axmol/cocos/editor-support/cocosbuilder/CCScale9SpriteLoader.cpp

108 lines
5.0 KiB
C++

/****************************************************************************
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "editor-support/cocosbuilder/CCScale9SpriteLoader.h"
using namespace cocos2d;
using namespace cocos2d::extension;
#define PROPERTY_CONTENTSIZE "contentSize"
#define PROPERTY_SPRITEFRAME "spriteFrame"
#define PROPERTY_COLOR "color"
#define PROPERTY_OPACITY "opacity"
#define PROPERTY_BLENDFUNC "blendFunc"
// TODO: Should be "preferredSize". This is a typo in cocos2d-iphone, cocos2d-x and CocosBuilder!
#define PROPERTY_PREFEREDSIZE "preferedSize"
#define PROPERTY_INSETLEFT "insetLeft"
#define PROPERTY_INSETTOP "insetTop"
#define PROPERTY_INSETRIGHT "insetRight"
#define PROPERTY_INSETBOTTOM "insetBottom"
namespace cocosbuilder {
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;
}
void Scale9SpriteLoader::onHandlePropTypeSpriteFrame(Node * pNode, Node * pParent, const char * pPropertyName, SpriteFrame * pSpriteFrame, CCBReader * ccbReader) {
if(strcmp(pPropertyName, PROPERTY_SPRITEFRAME) == 0) {
static_cast<cocos2d::ui::Scale9Sprite*>(pNode)->setSpriteFrame(pSpriteFrame);
} else {
NodeLoader::onHandlePropTypeSpriteFrame(pNode, pParent, pPropertyName, pSpriteFrame, ccbReader);
}
}
void Scale9SpriteLoader::onHandlePropTypeColor3(Node * pNode, Node * pParent, const char * pPropertyName, Color3B pColor3B, CCBReader * ccbReader) {
if(strcmp(pPropertyName, PROPERTY_COLOR) == 0) {
((cocos2d::ui::Scale9Sprite *)pNode)->setColor(pColor3B);
} else {
NodeLoader::onHandlePropTypeColor3(pNode, pParent, pPropertyName, pColor3B, ccbReader);
}
}
void Scale9SpriteLoader::onHandlePropTypeByte(Node * pNode, Node * pParent, const char * pPropertyName, unsigned char pByte, CCBReader * ccbReader) {
if(strcmp(pPropertyName, PROPERTY_OPACITY) == 0) {
((cocos2d::ui::Scale9Sprite *)pNode)->setOpacity(pByte);
} else {
NodeLoader::onHandlePropTypeByte(pNode, pParent, pPropertyName, pByte, ccbReader);
}
}
void Scale9SpriteLoader::onHandlePropTypeBlendFunc(Node * pNode, Node * pParent, const char * pPropertyName, BlendFunc pBlendFunc, CCBReader * ccbReader) {
if(strcmp(pPropertyName, PROPERTY_BLENDFUNC) == 0) {
// TODO Not exported by CocosBuilder yet!
// ((Scale9Sprite *)pNode)->setBlendFunc(pBlendFunc);
} else {
NodeLoader::onHandlePropTypeBlendFunc(pNode, pParent, pPropertyName, pBlendFunc, ccbReader);
}
}
void Scale9SpriteLoader::onHandlePropTypeSize(Node * pNode, Node * pParent, const char * pPropertyName, Size pSize, CCBReader * ccbReader) {
if(strcmp(pPropertyName, PROPERTY_CONTENTSIZE) == 0) {
//((Scale9Sprite *)pNode)->setContentSize(pSize);
} else if(strcmp(pPropertyName, PROPERTY_PREFEREDSIZE) == 0) {
((cocos2d::ui::Scale9Sprite *)pNode)->setPreferredSize(pSize);
} else {
NodeLoader::onHandlePropTypeSize(pNode, pParent, pPropertyName, pSize, ccbReader);
}
}
void Scale9SpriteLoader::onHandlePropTypeFloat(Node * pNode, Node * pParent, const char * pPropertyName, float pFloat, CCBReader * ccbReader) {
if(strcmp(pPropertyName, PROPERTY_INSETLEFT) == 0) {
((cocos2d::ui::Scale9Sprite *)pNode)->setInsetLeft(pFloat);
} else if(strcmp(pPropertyName, PROPERTY_INSETTOP) == 0) {
((cocos2d::ui::Scale9Sprite *)pNode)->setInsetTop(pFloat);
} else if(strcmp(pPropertyName, PROPERTY_INSETRIGHT) == 0) {
((cocos2d::ui::Scale9Sprite *)pNode)->setInsetRight(pFloat);
} else if(strcmp(pPropertyName, PROPERTY_INSETBOTTOM) == 0) {
((cocos2d::ui::Scale9Sprite *)pNode)->setInsetBottom(pFloat);
} else {
NodeLoader::onHandlePropTypeFloat(pNode, pParent, pPropertyName, pFloat, ccbReader);
}
}
}