123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- #include "platform/CCPlatformMacros.h"
- #include "math/CCGeometry.h"
- NS_CC_BEGIN
- class Image;
- class SpriteFrame;
- /**
- * A class for paring Android .9 patch image.
- * For more about Android .9 patch image format, please refer to
- * http://developer.android.com/tools/help/draw9patch.html
- *
- * The class could parse a single .9 patch image and produce the capInsets
- * as well as a sprite atlas and store all the capInsets infos in a Texture2D.
- * Note:
- * - Currently only PixelFormat::RGBA8888 is supported.
- * - TexturePacker Trim mode is not supported at the moment.
- */
- class CC_DLL NinePatchImageParser
- {
- public:
-
- static bool isNinePatchImage(const std::string& filename);
-
- NinePatchImageParser();
-
- explicit NinePatchImageParser(Image* image);
-
- NinePatchImageParser(Image* image, const Rect& frameRect, bool rotated);
-
- void setSpriteFrameInfo(Image* image, const Rect& frameRect, bool rotated);
-
- virtual ~NinePatchImageParser();
-
- Rect parseCapInset()const;
- private:
- enum class Direction
- {
- HORIZONTAL,
- VERTICAL
- };
- int getPixelOriginOffset(Direction direction)const;
- Vec2 parseHorizontalMargin()const;
- Vec2 parseVerticalMargin()const;
- int getFrameWidth()const;
- int getFrameHeight()const;
- Image* _image;
- Rect _imageFrame;
- bool _isRotated;
- };
- NS_CC_END
|