2016-03-20 21:53:44 +08:00
|
|
|
#include "editor-support/cocosbuilder/CCScale9SpriteLoader.h"
|
2012-05-31 07:52:02 +08:00
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
using namespace cocos2d;
|
|
|
|
using namespace cocos2d::extension;
|
2012-05-31 07:52:02 +08:00
|
|
|
|
|
|
|
#define PROPERTY_CONTENTSIZE "contentSize"
|
2012-06-01 03:38:00 +08:00
|
|
|
#define PROPERTY_SPRITEFRAME "spriteFrame"
|
2012-05-31 07:52:02 +08:00
|
|
|
#define PROPERTY_COLOR "color"
|
|
|
|
#define PROPERTY_OPACITY "opacity"
|
|
|
|
#define PROPERTY_BLENDFUNC "blendFunc"
|
2014-08-30 03:54:24 +08:00
|
|
|
// TODO: Should be "preferredSize". This is a typo in cocos2d-iphone, cocos2d-x and CocosBuilder!
|
|
|
|
#define PROPERTY_PREFEREDSIZE "preferedSize"
|
2012-06-01 03:38:00 +08:00
|
|
|
#define PROPERTY_INSETLEFT "insetLeft"
|
|
|
|
#define PROPERTY_INSETTOP "insetTop"
|
|
|
|
#define PROPERTY_INSETRIGHT "insetRight"
|
|
|
|
#define PROPERTY_INSETBOTTOM "insetBottom"
|
2012-05-31 07:52:02 +08:00
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
namespace cocosbuilder {
|
2012-07-19 17:22:36 +08:00
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
ui::Scale9Sprite* Scale9SpriteLoader::createNode(cocos2d::Node* /*pParent*/, cocosbuilder::CCBReader* /*ccbReader*/) {
|
|
|
|
cocos2d::ui::Scale9Sprite* pNode = cocos2d::ui::Scale9Sprite::create();
|
|
|
|
pNode->setAnchorPoint(cocos2d::Vec2::ZERO);
|
|
|
|
return pNode;
|
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void Scale9SpriteLoader::onHandlePropTypeSpriteFrame(Node * pNode, Node * pParent, const char * pPropertyName, SpriteFrame * pSpriteFrame, CCBReader * ccbReader) {
|
2012-11-26 21:51:05 +08:00
|
|
|
if(strcmp(pPropertyName, PROPERTY_SPRITEFRAME) == 0) {
|
2016-11-24 09:59:00 +08:00
|
|
|
static_cast<cocos2d::ui::Scale9Sprite*>(pNode)->setSpriteFrame(pSpriteFrame);
|
2012-05-31 07:52:02 +08:00
|
|
|
} else {
|
2013-07-27 21:44:49 +08:00
|
|
|
NodeLoader::onHandlePropTypeSpriteFrame(pNode, pParent, pPropertyName, pSpriteFrame, ccbReader);
|
2012-05-31 07:52:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void Scale9SpriteLoader::onHandlePropTypeColor3(Node * pNode, Node * pParent, const char * pPropertyName, Color3B pColor3B, CCBReader * ccbReader) {
|
2012-11-26 21:51:05 +08:00
|
|
|
if(strcmp(pPropertyName, PROPERTY_COLOR) == 0) {
|
2014-09-01 17:06:22 +08:00
|
|
|
((cocos2d::ui::Scale9Sprite *)pNode)->setColor(pColor3B);
|
2012-05-31 07:52:02 +08:00
|
|
|
} else {
|
2013-07-27 21:44:49 +08:00
|
|
|
NodeLoader::onHandlePropTypeColor3(pNode, pParent, pPropertyName, pColor3B, ccbReader);
|
2012-05-31 07:52:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void Scale9SpriteLoader::onHandlePropTypeByte(Node * pNode, Node * pParent, const char * pPropertyName, unsigned char pByte, CCBReader * ccbReader) {
|
2012-11-26 21:51:05 +08:00
|
|
|
if(strcmp(pPropertyName, PROPERTY_OPACITY) == 0) {
|
2014-09-01 17:06:22 +08:00
|
|
|
((cocos2d::ui::Scale9Sprite *)pNode)->setOpacity(pByte);
|
2012-05-31 07:52:02 +08:00
|
|
|
} else {
|
2013-07-27 21:44:49 +08:00
|
|
|
NodeLoader::onHandlePropTypeByte(pNode, pParent, pPropertyName, pByte, ccbReader);
|
2012-05-31 07:52:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void Scale9SpriteLoader::onHandlePropTypeBlendFunc(Node * pNode, Node * pParent, const char * pPropertyName, BlendFunc pBlendFunc, CCBReader * ccbReader) {
|
2012-11-26 21:51:05 +08:00
|
|
|
if(strcmp(pPropertyName, PROPERTY_BLENDFUNC) == 0) {
|
2012-05-31 07:52:02 +08:00
|
|
|
// TODO Not exported by CocosBuilder yet!
|
2013-06-20 14:15:53 +08:00
|
|
|
// ((Scale9Sprite *)pNode)->setBlendFunc(pBlendFunc);
|
2012-05-31 07:52:02 +08:00
|
|
|
} else {
|
2013-07-27 21:44:49 +08:00
|
|
|
NodeLoader::onHandlePropTypeBlendFunc(pNode, pParent, pPropertyName, pBlendFunc, ccbReader);
|
2012-05-31 07:52:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void Scale9SpriteLoader::onHandlePropTypeSize(Node * pNode, Node * pParent, const char * pPropertyName, Size pSize, CCBReader * ccbReader) {
|
2012-11-26 21:51:05 +08:00
|
|
|
if(strcmp(pPropertyName, PROPERTY_CONTENTSIZE) == 0) {
|
2013-06-20 14:15:53 +08:00
|
|
|
//((Scale9Sprite *)pNode)->setContentSize(pSize);
|
2012-11-26 21:51:05 +08:00
|
|
|
} else if(strcmp(pPropertyName, PROPERTY_PREFEREDSIZE) == 0) {
|
2014-09-01 17:06:22 +08:00
|
|
|
((cocos2d::ui::Scale9Sprite *)pNode)->setPreferredSize(pSize);
|
2012-05-31 07:52:02 +08:00
|
|
|
} else {
|
2013-07-27 21:44:49 +08:00
|
|
|
NodeLoader::onHandlePropTypeSize(pNode, pParent, pPropertyName, pSize, ccbReader);
|
2012-05-31 07:52:02 +08:00
|
|
|
}
|
2012-06-01 03:38:00 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void Scale9SpriteLoader::onHandlePropTypeFloat(Node * pNode, Node * pParent, const char * pPropertyName, float pFloat, CCBReader * ccbReader) {
|
2012-11-26 21:51:05 +08:00
|
|
|
if(strcmp(pPropertyName, PROPERTY_INSETLEFT) == 0) {
|
2014-09-01 17:06:22 +08:00
|
|
|
((cocos2d::ui::Scale9Sprite *)pNode)->setInsetLeft(pFloat);
|
2012-11-26 21:51:05 +08:00
|
|
|
} else if(strcmp(pPropertyName, PROPERTY_INSETTOP) == 0) {
|
2014-09-01 17:06:22 +08:00
|
|
|
((cocos2d::ui::Scale9Sprite *)pNode)->setInsetTop(pFloat);
|
2012-11-26 21:51:05 +08:00
|
|
|
} else if(strcmp(pPropertyName, PROPERTY_INSETRIGHT) == 0) {
|
2014-09-01 17:06:22 +08:00
|
|
|
((cocos2d::ui::Scale9Sprite *)pNode)->setInsetRight(pFloat);
|
2012-11-26 21:51:05 +08:00
|
|
|
} else if(strcmp(pPropertyName, PROPERTY_INSETBOTTOM) == 0) {
|
2014-09-01 17:06:22 +08:00
|
|
|
((cocos2d::ui::Scale9Sprite *)pNode)->setInsetBottom(pFloat);
|
2012-06-01 03:38:00 +08:00
|
|
|
} else {
|
2013-07-27 21:44:49 +08:00
|
|
|
NodeLoader::onHandlePropTypeFloat(pNode, pParent, pPropertyName, pFloat, ccbReader);
|
2012-06-01 03:38:00 +08:00
|
|
|
}
|
2012-07-19 17:22:36 +08:00
|
|
|
}
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
}
|