Merge pull request #6685 from andyque/refactor5118

closed #5118, remove WidgetType and refactor LayoutType to Type
This commit is contained in:
minggo 2014-05-13 11:35:36 +08:00
commit ccb55448da
20 changed files with 130 additions and 117 deletions

View File

@ -218,6 +218,30 @@ Widget* GUIReader::widgetFromJsonFile(const char *fileName)
} }
void WidgetPropertiesReader::setAnchorPointForWidget(cocos2d::ui::Widget *widget, const rapidjson::Value &options)
{
bool isAnchorPointXExists = DICTOOL->checkObjectExist_json(options, "anchorPointX");
float anchorPointXInFile;
if (isAnchorPointXExists) {
anchorPointXInFile = DICTOOL->getFloatValue_json(options, "anchorPointX");
}else{
anchorPointXInFile = widget->getAnchorPoint().x;
}
bool isAnchorPointYExists = DICTOOL->checkObjectExist_json(options, "anchorPointY");
float anchorPointYInFile;
if (isAnchorPointYExists) {
anchorPointYInFile = DICTOOL->getFloatValue_json(options, "anchorPointY");
}
else{
anchorPointYInFile = widget->getAnchorPoint().y;
}
if (isAnchorPointXExists || isAnchorPointYExists) {
widget->setAnchorPoint(Vector2(anchorPointXInFile, anchorPointYInFile));
}
}
Widget* WidgetPropertiesReader0250::createWidget(const rapidjson::Value& data, const char* fullPath, const char* fileName) Widget* WidgetPropertiesReader0250::createWidget(const rapidjson::Value& data, const char* fullPath, const char* fileName)
{ {
@ -411,11 +435,9 @@ void WidgetPropertiesReader0250::setColorPropsForWidgetFromJsonDictionary(Widget
int colorG = cg ? DICTOOL->getIntValue_json(options, "colorG") : 255; int colorG = cg ? DICTOOL->getIntValue_json(options, "colorG") : 255;
int colorB = cb ? DICTOOL->getIntValue_json(options, "colorB") : 255; int colorB = cb ? DICTOOL->getIntValue_json(options, "colorB") : 255;
widget->setColor(Color3B(colorR, colorG, colorB)); widget->setColor(Color3B(colorR, colorG, colorB));
bool apx = DICTOOL->checkObjectExist_json(options, "anchorPointX");
float apxf = apx ? DICTOOL->getFloatValue_json(options, "anchorPointX") : ((widget->getWidgetType() == Widget::Type::ELEMENT) ? 0.5f : 0.0f); this->setAnchorPointForWidget(widget, options);
bool apy = DICTOOL->checkObjectExist_json(options, "anchorPointY");
float apyf = apy ? DICTOOL->getFloatValue_json(options, "anchorPointY") : ((widget->getWidgetType() == Widget::Type::ELEMENT) ? 0.5f : 0.0f);
widget->setAnchorPoint(Vector2(apxf, apyf));
bool flipX = DICTOOL->getBooleanValue_json(options, "flipX"); bool flipX = DICTOOL->getBooleanValue_json(options, "flipX");
bool flipY = DICTOOL->getBooleanValue_json(options, "flipY"); bool flipY = DICTOOL->getBooleanValue_json(options, "flipY");
widget->setFlippedX(flipX); widget->setFlippedX(flipX);
@ -1233,16 +1255,16 @@ void WidgetPropertiesReader0300::setColorPropsForWidgetFromJsonDictionary(Widget
int colorG = cg ? DICTOOL->getIntValue_json(options, "colorG") : 255; int colorG = cg ? DICTOOL->getIntValue_json(options, "colorG") : 255;
int colorB = cb ? DICTOOL->getIntValue_json(options, "colorB") : 255; int colorB = cb ? DICTOOL->getIntValue_json(options, "colorB") : 255;
widget->setColor(Color3B(colorR, colorG, colorB)); widget->setColor(Color3B(colorR, colorG, colorB));
bool apx = DICTOOL->checkObjectExist_json(options, "anchorPointX");
float apxf = apx ? DICTOOL->getFloatValue_json(options, "anchorPointX") : ((widget->getWidgetType() == Widget::Type::ELEMENT) ? 0.5f : 0.0f); this->setAnchorPointForWidget(widget, options);
bool apy = DICTOOL->checkObjectExist_json(options, "anchorPointY");
float apyf = apy ? DICTOOL->getFloatValue_json(options, "anchorPointY") : ((widget->getWidgetType() == Widget::Type::ELEMENT) ? 0.5f : 0.0f);
widget->setAnchorPoint(Vector2(apxf, apyf));
bool flipX = DICTOOL->getBooleanValue_json(options, "flipX"); bool flipX = DICTOOL->getBooleanValue_json(options, "flipX");
bool flipY = DICTOOL->getBooleanValue_json(options, "flipY"); bool flipY = DICTOOL->getBooleanValue_json(options, "flipY");
widget->setFlippedX(flipX); widget->setFlippedX(flipX);
widget->setFlippedY(flipY); widget->setFlippedY(flipY);
} }
void WidgetPropertiesReader0300::setPropsForButtonFromJsonDictionary(Widget*widget,const rapidjson::Value& options) void WidgetPropertiesReader0300::setPropsForButtonFromJsonDictionary(Widget*widget,const rapidjson::Value& options)
{ {
@ -1694,7 +1716,7 @@ void WidgetPropertiesReader0300::setPropsForLayoutFromJsonDictionary(Widget*widg
float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight"); float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight");
panel->setBackGroundImageCapInsets(Rect(cx, cy, cw, ch)); panel->setBackGroundImageCapInsets(Rect(cx, cy, cw, ch));
} }
panel->setLayoutType((Layout::LayoutType)DICTOOL->getIntValue_json(options, "layoutType")); panel->setLayoutType((Layout::Type)DICTOOL->getIntValue_json(options, "layoutType"));
setColorPropsForWidgetFromJsonDictionary(widget,options); setColorPropsForWidgetFromJsonDictionary(widget,options);
} }

View File

@ -91,6 +91,9 @@ public:
virtual void setPropsForAllCustomWidgetFromJsonDictionary(const std::string& classType, virtual void setPropsForAllCustomWidgetFromJsonDictionary(const std::string& classType,
cocos2d::ui::Widget* widget, cocos2d::ui::Widget* widget,
const rapidjson::Value& customOptions) = 0; const rapidjson::Value& customOptions) = 0;
protected:
void setAnchorPointForWidget(cocos2d::ui::Widget* widget, const rapidjson::Value&options);
protected: protected:
std::string m_strFilePath; std::string m_strFilePath;
}; };
@ -160,6 +163,8 @@ public:
virtual void setPropsForAllCustomWidgetFromJsonDictionary(const std::string& classType, virtual void setPropsForAllCustomWidgetFromJsonDictionary(const std::string& classType,
cocos2d::ui::Widget* widget, cocos2d::ui::Widget* widget,
const rapidjson::Value& customOptions); const rapidjson::Value& customOptions);
}; };

View File

@ -97,7 +97,7 @@ namespace cocostudio
float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight"); float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight");
panel->setBackGroundImageCapInsets(Rect(cx, cy, cw, ch)); panel->setBackGroundImageCapInsets(Rect(cx, cy, cw, ch));
} }
panel->setLayoutType((Layout::LayoutType)DICTOOL->getIntValue_json(options, "layoutType")); panel->setLayoutType((Layout::Type)DICTOOL->getIntValue_json(options, "layoutType"));
int bgimgcr = DICTOOL->getIntValue_json(options, "colorR"); int bgimgcr = DICTOOL->getIntValue_json(options, "colorR");
int bgimgcg = DICTOOL->getIntValue_json(options, "colorG"); int bgimgcg = DICTOOL->getIntValue_json(options, "colorG");

View File

@ -162,11 +162,9 @@ namespace cocostudio
int colorG = cg ? DICTOOL->getIntValue_json(options, "colorG") : 255; int colorG = cg ? DICTOOL->getIntValue_json(options, "colorG") : 255;
int colorB = cb ? DICTOOL->getIntValue_json(options, "colorB") : 255; int colorB = cb ? DICTOOL->getIntValue_json(options, "colorB") : 255;
widget->setColor(Color3B(colorR, colorG, colorB)); widget->setColor(Color3B(colorR, colorG, colorB));
bool apx = DICTOOL->checkObjectExist_json(options, "anchorPointX");
float apxf = apx ? DICTOOL->getFloatValue_json(options, "anchorPointX") : ((widget->getWidgetType() == Widget::Type::ELEMENT) ? 0.5f : 0.0f); this->setAnchorPointForWidget(widget, options);
bool apy = DICTOOL->checkObjectExist_json(options, "anchorPointY");
float apyf = apy ? DICTOOL->getFloatValue_json(options, "anchorPointY") : ((widget->getWidgetType() == Widget::Type::ELEMENT) ? 0.5f : 0.0f);
widget->setAnchorPoint(Vector2(apxf, apyf));
bool flipX = DICTOOL->getBooleanValue_json(options, "flipX"); bool flipX = DICTOOL->getBooleanValue_json(options, "flipX");
bool flipY = DICTOOL->getBooleanValue_json(options, "flipY"); bool flipY = DICTOOL->getBooleanValue_json(options, "flipY");
widget->setFlippedX(flipX); widget->setFlippedX(flipX);
@ -194,4 +192,31 @@ namespace cocostudio
} }
return imageFileName_tp; return imageFileName_tp;
} }
void WidgetReader::setAnchorPointForWidget(cocos2d::ui::Widget *widget, const rapidjson::Value &options)
{
bool isAnchorPointXExists = DICTOOL->checkObjectExist_json(options, "anchorPointX");
float anchorPointXInFile;
if (isAnchorPointXExists) {
anchorPointXInFile = DICTOOL->getFloatValue_json(options, "anchorPointX");
}else{
anchorPointXInFile = widget->getAnchorPoint().x;
}
bool isAnchorPointYExists = DICTOOL->checkObjectExist_json(options, "anchorPointY");
float anchorPointYInFile;
if (isAnchorPointYExists) {
anchorPointYInFile = DICTOOL->getFloatValue_json(options, "anchorPointY");
}
else{
anchorPointYInFile = widget->getAnchorPoint().y;
}
if (isAnchorPointXExists || isAnchorPointYExists) {
widget->setAnchorPoint(Vector2(anchorPointXInFile, anchorPointYInFile));
}
}
} }

View File

@ -53,6 +53,8 @@ namespace cocostudio
std::string getResourcePath(const rapidjson::Value& dict, std::string getResourcePath(const rapidjson::Value& dict,
const std::string& key, const std::string& key,
cocos2d::ui::Widget::TextureResType texType); cocos2d::ui::Widget::TextureResType texType);
void setAnchorPointForWidget(cocos2d::ui::Widget* widget, const rapidjson::Value&options);
}; };
} }

View File

@ -35,7 +35,7 @@
#define DECLARE_CLASS_GUI_INFO \ #define DECLARE_CLASS_GUI_INFO \
public: \ public: \
static cocostudio::ObjectFactory::TInfo Type; \ static cocostudio::ObjectFactory::TInfo __Type; \
static cocos2d::Ref* createInstance(void); \ static cocos2d::Ref* createInstance(void); \
#define IMPLEMENT_CLASS_GUI_INFO(className) \ #define IMPLEMENT_CLASS_GUI_INFO(className) \
@ -43,7 +43,7 @@
{ \ { \
return className::create(); \ return className::create(); \
} \ } \
cocostudio::ObjectFactory::TInfo className::Type(#className, &className::createInstance); \ cocostudio::ObjectFactory::TInfo className::__Type(#className, &className::createInstance); \
#define CREATE_CLASS_GUI_INFO(className) \ #define CREATE_CLASS_GUI_INFO(className) \
cocostudio::ObjectFactory::TInfo(#className, &className::createInstance) \ cocostudio::ObjectFactory::TInfo(#className, &className::createInstance) \
@ -55,7 +55,7 @@
#define DECLARE_CLASS_WIDGET_READER_INFO \ #define DECLARE_CLASS_WIDGET_READER_INFO \
public: \ public: \
static cocostudio::ObjectFactory::TInfo Type; \ static cocostudio::ObjectFactory::TInfo __Type; \
static cocos2d::Ref* createInstance(void); \ static cocos2d::Ref* createInstance(void); \
#define IMPLEMENT_CLASS_WIDGET_READER_INFO(className) \ #define IMPLEMENT_CLASS_WIDGET_READER_INFO(className) \
@ -63,7 +63,7 @@
{ \ { \
return className::getInstance(); \ return className::getInstance(); \
} \ } \
cocostudio::ObjectFactory::TInfo className::Type(#className, &className::createInstance); \ cocostudio::ObjectFactory::TInfo className::__Type(#className, &className::createInstance); \
#define CREATE_CLASS_WIDGET_READER_INFO(className) \ #define CREATE_CLASS_WIDGET_READER_INFO(className) \
cocostudio::ObjectFactory::TInfo(#className, &className::createInstance) \ cocostudio::ObjectFactory::TInfo(#className, &className::createInstance) \

View File

@ -37,17 +37,15 @@ CC_DEPRECATED_ATTRIBUTE const Widget::SizeType SIZE_ABSOLUTE = Widget::SizeType:
CC_DEPRECATED_ATTRIBUTE const Widget::SizeType SIZE_PERCENT = Widget::SizeType::PERCENT; CC_DEPRECATED_ATTRIBUTE const Widget::SizeType SIZE_PERCENT = Widget::SizeType::PERCENT;
CC_DEPRECATED_ATTRIBUTE const Widget::TextureResType UI_TEX_TYPE_LOCAL = Widget::TextureResType::LOCAL; CC_DEPRECATED_ATTRIBUTE const Widget::TextureResType UI_TEX_TYPE_LOCAL = Widget::TextureResType::LOCAL;
CC_DEPRECATED_ATTRIBUTE const Widget::TextureResType UI_TEX_TYPE_PLIST = Widget::TextureResType::PLIST; CC_DEPRECATED_ATTRIBUTE const Widget::TextureResType UI_TEX_TYPE_PLIST = Widget::TextureResType::PLIST;
CC_DEPRECATED_ATTRIBUTE const Widget::Type WidgetTypeWidget = Widget::Type::ELEMENT;
CC_DEPRECATED_ATTRIBUTE const Widget::Type WidgetTypeContainer = Widget::Type::CONTAINER;
CC_DEPRECATED_ATTRIBUTE const Widget::BrightStyle BRIGHT_NONE = Widget::BrightStyle::NONE; CC_DEPRECATED_ATTRIBUTE const Widget::BrightStyle BRIGHT_NONE = Widget::BrightStyle::NONE;
CC_DEPRECATED_ATTRIBUTE const Widget::BrightStyle BRIGHT_NORMAL = Widget::BrightStyle::NORMAL; CC_DEPRECATED_ATTRIBUTE const Widget::BrightStyle BRIGHT_NORMAL = Widget::BrightStyle::NORMAL;
CC_DEPRECATED_ATTRIBUTE const Widget::BrightStyle BRIGHT_HIGHLIGHT = Widget::BrightStyle::HIGHLIGHT; CC_DEPRECATED_ATTRIBUTE const Widget::BrightStyle BRIGHT_HIGHLIGHT = Widget::BrightStyle::HIGHLIGHT;
CC_DEPRECATED_ATTRIBUTE const Layout::ClippingType LAYOUT_CLIPPING_STENCIL = Layout::ClippingType::STENCIL; CC_DEPRECATED_ATTRIBUTE const Layout::ClippingType LAYOUT_CLIPPING_STENCIL = Layout::ClippingType::STENCIL;
CC_DEPRECATED_ATTRIBUTE const Layout::ClippingType LAYOUT_CLIPPING_SCISSOR = Layout::ClippingType::SCISSOR; CC_DEPRECATED_ATTRIBUTE const Layout::ClippingType LAYOUT_CLIPPING_SCISSOR = Layout::ClippingType::SCISSOR;
CC_DEPRECATED_ATTRIBUTE const Layout::LayoutType LAYOUT_ABSOLUTE = Layout::LayoutType::ABSOLUTE; CC_DEPRECATED_ATTRIBUTE const Layout::Type LAYOUT_ABSOLUTE = Layout::Type::ABSOLUTE;
CC_DEPRECATED_ATTRIBUTE const Layout::LayoutType LAYOUT_LINEAR_VERTICAL = Layout::LayoutType::VERTICAL; CC_DEPRECATED_ATTRIBUTE const Layout::Type LAYOUT_LINEAR_VERTICAL = Layout::Type::VERTICAL;
CC_DEPRECATED_ATTRIBUTE const Layout::LayoutType LAYOUT_LINEAR_HORIZONTAL = Layout::LayoutType::HORIZONTAL; CC_DEPRECATED_ATTRIBUTE const Layout::Type LAYOUT_LINEAR_HORIZONTAL = Layout::Type::HORIZONTAL;
CC_DEPRECATED_ATTRIBUTE const Layout::LayoutType LAYOUT_RELATIVE = Layout::LayoutType::VERTICAL; CC_DEPRECATED_ATTRIBUTE const Layout::Type LAYOUT_RELATIVE = Layout::Type::VERTICAL;
CC_DEPRECATED_ATTRIBUTE const Layout::BackGroundColorType LAYOUT_COLOR_NONE = Layout::BackGroundColorType::NONE; CC_DEPRECATED_ATTRIBUTE const Layout::BackGroundColorType LAYOUT_COLOR_NONE = Layout::BackGroundColorType::NONE;
CC_DEPRECATED_ATTRIBUTE const Layout::BackGroundColorType LAYOUT_COLOR_SOLID = Layout::BackGroundColorType::SOLID; CC_DEPRECATED_ATTRIBUTE const Layout::BackGroundColorType LAYOUT_COLOR_SOLID = Layout::BackGroundColorType::SOLID;
CC_DEPRECATED_ATTRIBUTE const Layout::BackGroundColorType LAYOUT_COLOR_GRADIENT CC_DEPRECATED_ATTRIBUTE const Layout::BackGroundColorType LAYOUT_COLOR_GRADIENT
@ -137,10 +135,9 @@ CC_DEPRECATED_ATTRIBUTE const ScrollView::Direction SCROLLVIEW_DIR_BOTH = Scrol
CC_DEPRECATED_ATTRIBUTE typedef Widget::TextureResType TextureResType; CC_DEPRECATED_ATTRIBUTE typedef Widget::TextureResType TextureResType;
CC_DEPRECATED_ATTRIBUTE typedef Widget::PositionType PositionType; CC_DEPRECATED_ATTRIBUTE typedef Widget::PositionType PositionType;
CC_DEPRECATED_ATTRIBUTE typedef Widget::SizeType SizeType; CC_DEPRECATED_ATTRIBUTE typedef Widget::SizeType SizeType;
CC_DEPRECATED_ATTRIBUTE typedef Widget::Type WidgetType;
CC_DEPRECATED_ATTRIBUTE typedef Widget::BrightStyle BrightStyle; CC_DEPRECATED_ATTRIBUTE typedef Widget::BrightStyle BrightStyle;
CC_DEPRECATED_ATTRIBUTE typedef Layout::ClippingType LayoutClippingType; CC_DEPRECATED_ATTRIBUTE typedef Layout::ClippingType LayoutClippingType;
CC_DEPRECATED_ATTRIBUTE typedef Layout::LayoutType LayoutType; CC_DEPRECATED_ATTRIBUTE typedef Layout::Type LayoutType;
CC_DEPRECATED_ATTRIBUTE typedef Layout::BackGroundColorType LayoutBackGroundColorType; CC_DEPRECATED_ATTRIBUTE typedef Layout::BackGroundColorType LayoutBackGroundColorType;
CC_DEPRECATED_ATTRIBUTE typedef LayoutParameter::Type LayoutParameterType; CC_DEPRECATED_ATTRIBUTE typedef LayoutParameter::Type LayoutParameterType;
CC_DEPRECATED_ATTRIBUTE typedef LinearLayoutParameter::LinearGravity LinearGravity; CC_DEPRECATED_ATTRIBUTE typedef LinearLayoutParameter::LinearGravity LinearGravity;

View File

@ -64,7 +64,7 @@ bool HBox::init()
{ {
if (Layout::init()) if (Layout::init())
{ {
setLayoutType(LayoutType::HORIZONTAL); setLayoutType(Layout::Type::HORIZONTAL);
return true; return true;
} }
return false; return false;

View File

@ -582,7 +582,7 @@ _gEndColor(Color3B::WHITE),
_alongVector(Vector2(0.0f, -1.0f)), _alongVector(Vector2(0.0f, -1.0f)),
_cOpacity(255), _cOpacity(255),
_backGroundImageTextureSize(Size::ZERO), _backGroundImageTextureSize(Size::ZERO),
_layoutType(LayoutType::ABSOLUTE), _layoutType(Type::ABSOLUTE),
_clippingType(ClippingType::STENCIL), _clippingType(ClippingType::STENCIL),
_clippingStencil(nullptr), _clippingStencil(nullptr),
_scissorRectDirty(false), _scissorRectDirty(false),
@ -608,8 +608,8 @@ _curLayoutExecutant(nullptr),
_passFocusToChild(true), _passFocusToChild(true),
_loopFocus(false) _loopFocus(false)
{ {
_widgetType = Widget::Type::CONTAINER;
onPassFocusToChild = CC_CALLBACK_2(Layout::findNearestChildWidgetIndex, this); onPassFocusToChild = CC_CALLBACK_2(Layout::findNearestChildWidgetIndex, this);
this->setAnchorPoint(Vector2::ZERO);
} }
Layout::~Layout() Layout::~Layout()
@ -1175,10 +1175,10 @@ void Layout::supplyTheLayoutParameterLackToChild(Widget *child)
} }
switch (_layoutType) switch (_layoutType)
{ {
case LayoutType::ABSOLUTE: case Type::ABSOLUTE:
break; break;
case LayoutType::HORIZONTAL: case Type::HORIZONTAL:
case LayoutType::VERTICAL: case Type::VERTICAL:
{ {
LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter(LayoutParameter::Type::LINEAR)); LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter(LayoutParameter::Type::LINEAR));
if (!layoutParameter) if (!layoutParameter)
@ -1187,7 +1187,7 @@ void Layout::supplyTheLayoutParameterLackToChild(Widget *child)
} }
break; break;
} }
case LayoutType::RELATIVE: case Type::RELATIVE:
{ {
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(child->getLayoutParameter(LayoutParameter::Type::RELATIVE)); RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(child->getLayoutParameter(LayoutParameter::Type::RELATIVE));
if (!layoutParameter) if (!layoutParameter)
@ -1424,7 +1424,7 @@ const Size& Layout::getBackGroundImageTextureSize() const
return _backGroundImageTextureSize; return _backGroundImageTextureSize;
} }
void Layout::setLayoutType(LayoutType type) void Layout::setLayoutType(Type type)
{ {
_layoutType = type; _layoutType = type;
CC_SAFE_RELEASE_NULL(_curLayoutExecutant); CC_SAFE_RELEASE_NULL(_curLayoutExecutant);
@ -1446,13 +1446,13 @@ LayoutExecutant* Layout::createCurrentLayoutExecutant()
LayoutExecutant* exe = nullptr; LayoutExecutant* exe = nullptr;
switch (_layoutType) switch (_layoutType)
{ {
case LayoutType::VERTICAL: case Type::VERTICAL:
exe = LinearVerticalLayoutExecutant::create(); exe = LinearVerticalLayoutExecutant::create();
break; break;
case LayoutType::HORIZONTAL: case Type::HORIZONTAL:
exe = LinearHorizontalLayoutExecutant::create(); exe = LinearHorizontalLayoutExecutant::create();
break; break;
case LayoutType::RELATIVE: case Type::RELATIVE:
exe = RelativeLayoutExecutant::create(); exe = RelativeLayoutExecutant::create();
break; break;
default: default:
@ -1461,7 +1461,7 @@ LayoutExecutant* Layout::createCurrentLayoutExecutant()
return exe; return exe;
} }
Layout::LayoutType Layout::getLayoutType() const Layout::Type Layout::getLayoutType() const
{ {
return _layoutType; return _layoutType;
} }
@ -1564,12 +1564,12 @@ Size Layout::getLayoutContentSize()const
} }
//substract extra size //substract extra size
LayoutType type = this->getLayoutType(); Type type = this->getLayoutType();
if (type == LayoutType::HORIZONTAL) if (type == Type::HORIZONTAL)
{ {
layoutSize = layoutSize - Size(0, layoutSize.height/widgetCount * (widgetCount-1)); layoutSize = layoutSize - Size(0, layoutSize.height/widgetCount * (widgetCount-1));
} }
if (type == LayoutType::VERTICAL) if (type == Type::VERTICAL)
{ {
layoutSize = layoutSize - Size(layoutSize.width/widgetCount * (widgetCount-1), 0); layoutSize = layoutSize - Size(layoutSize.width/widgetCount * (widgetCount-1), 0);
} }
@ -2186,7 +2186,7 @@ bool Layout::isLastWidgetInContainer(Widget* widget, FocusDirection direction)
auto container = parent->getChildren(); auto container = parent->getChildren();
ssize_t index = container.getIndex(widget); ssize_t index = container.getIndex(widget);
if (parent->getLayoutType() == LayoutType::HORIZONTAL) if (parent->getLayoutType() == Type::HORIZONTAL)
{ {
if (direction == FocusDirection::LEFT) { if (direction == FocusDirection::LEFT) {
if (index == 0) if (index == 0)
@ -2218,7 +2218,7 @@ bool Layout::isLastWidgetInContainer(Widget* widget, FocusDirection direction)
return isLastWidgetInContainer(parent, direction); return isLastWidgetInContainer(parent, direction);
} }
} }
else if(parent->getLayoutType() == LayoutType::VERTICAL) else if(parent->getLayoutType() == Type::VERTICAL)
{ {
if (direction == FocusDirection::UP) if (direction == FocusDirection::UP)
{ {
@ -2272,7 +2272,7 @@ bool Layout::isWidgetAncestorSupportLoopFocus(Widget* widget, FocusDirection di
if (parent->isLoopFocus()) if (parent->isLoopFocus())
{ {
auto layoutType = parent->getLayoutType(); auto layoutType = parent->getLayoutType();
if (layoutType == LayoutType::HORIZONTAL) if (layoutType == Type::HORIZONTAL)
{ {
if (direction == FocusDirection::LEFT || direction == FocusDirection::RIGHT) if (direction == FocusDirection::LEFT || direction == FocusDirection::RIGHT)
{ {
@ -2283,7 +2283,7 @@ bool Layout::isWidgetAncestorSupportLoopFocus(Widget* widget, FocusDirection di
return isWidgetAncestorSupportLoopFocus(parent, direction); return isWidgetAncestorSupportLoopFocus(parent, direction);
} }
} }
if (layoutType == LayoutType::VERTICAL) if (layoutType == Type::VERTICAL)
{ {
if (direction == FocusDirection::DOWN || direction == FocusDirection::UP) if (direction == FocusDirection::DOWN || direction == FocusDirection::UP)
{ {
@ -2334,7 +2334,7 @@ Widget* Layout::findNextFocusedWidget(FocusDirection direction, Widget* current)
} }
else if(current->isFocused() || !current->isFocusEnabled()) else if(current->isFocused() || !current->isFocusEnabled())
{ {
if (_layoutType == LayoutType::HORIZONTAL) if (_layoutType == Type::HORIZONTAL)
{ {
switch (direction) switch (direction)
{ {
@ -2371,7 +2371,7 @@ Widget* Layout::findNextFocusedWidget(FocusDirection direction, Widget* current)
break; break;
} }
} }
else if (_layoutType == LayoutType::VERTICAL) else if (_layoutType == Type::VERTICAL)
{ {
switch (direction) switch (direction)
{ {

View File

@ -43,13 +43,7 @@ class Layout : public Widget
DECLARE_CLASS_GUI_INFO DECLARE_CLASS_GUI_INFO
public: public:
enum class ClippingType enum class Type
{
STENCIL,
SCISSOR
};
enum class LayoutType
{ {
ABSOLUTE, ABSOLUTE,
VERTICAL, VERTICAL,
@ -57,12 +51,19 @@ public:
RELATIVE RELATIVE
}; };
enum class ClippingType
{
STENCIL,
SCISSOR
};
enum class BackGroundColorType enum class BackGroundColorType
{ {
NONE, NONE,
SOLID, SOLID,
GRADIENT GRADIENT
}; };
/** /**
* Default constructor * Default constructor
*/ */
@ -77,7 +78,7 @@ public:
* Allocates and initializes a layout. * Allocates and initializes a layout.
*/ */
static Layout* create(); static Layout* create();
//background //background
/** /**
* Sets a background image for layout * Sets a background image for layout
@ -201,23 +202,10 @@ public:
*/ */
virtual std::string getDescription() const override; virtual std::string getDescription() const override;
/**
* Sets LayoutType. virtual void setLayoutType(Type type);
*
* @see LayoutType
*
* @param LayoutType
*/
virtual void setLayoutType(LayoutType type);
/** virtual Type getLayoutType() const;
* Gets LayoutType.
*
* @see LayoutType
*
* @return LayoutType
*/
virtual LayoutType getLayoutType() const;
virtual void addChild(Node * child) override; virtual void addChild(Node * child) override;
/** /**
@ -460,7 +448,7 @@ protected:
Vector2 _alongVector; Vector2 _alongVector;
GLubyte _cOpacity; GLubyte _cOpacity;
Size _backGroundImageTextureSize; Size _backGroundImageTextureSize;
LayoutType _layoutType; Type _layoutType;
ClippingType _clippingType; ClippingType _clippingType;
DrawNode* _clippingStencil; DrawNode* _clippingStencil;
bool _scissorRectDirty; bool _scissorRectDirty;

View File

@ -70,7 +70,7 @@ const Margin MarginZero = Margin();
class LayoutParameter : public Ref class LayoutParameter : public Ref
{ {
public: public:
enum class Type : int enum class Type
{ {
NONE = 0, NONE = 0,
LINEAR, LINEAR,

View File

@ -69,7 +69,7 @@ bool ListView::init()
{ {
if (ScrollView::init()) if (ScrollView::init())
{ {
setLayoutType(LayoutType::VERTICAL); setLayoutType(Type::VERTICAL);
return true; return true;
} }
return false; return false;
@ -362,10 +362,10 @@ void ListView::setDirection(Direction dir)
switch (dir) switch (dir)
{ {
case Direction::VERTICAL: case Direction::VERTICAL:
setLayoutType(LayoutType::VERTICAL); setLayoutType(Type::VERTICAL);
break; break;
case Direction::HORIZONTAL: case Direction::HORIZONTAL:
setLayoutType(LayoutType::HORIZONTAL); setLayoutType(Type::HORIZONTAL);
break; break;
case Direction::BOTH: case Direction::BOTH:
return; return;

View File

@ -131,10 +131,7 @@ void PageView::addPage(Layout* page)
{ {
return; return;
} }
if (page->getWidgetType() != Widget::Type::CONTAINER)
{
return;
}
if (_pages.contains(page)) if (_pages.contains(page))
{ {
return; return;
@ -162,10 +159,7 @@ void PageView::insertPage(Layout* page, int idx)
{ {
return; return;
} }
if (page->getWidgetType() != Widget::Type::CONTAINER)
{
return;
}
if (_pages.contains(page)) if (_pages.contains(page))
{ {
return; return;

View File

@ -152,7 +152,7 @@ public:
* *
* @param LayoutType * @param LayoutType
*/ */
virtual void setLayoutType(LayoutType type) override{}; virtual void setLayoutType(Type type) override{};
/** /**
* Gets LayoutType. * Gets LayoutType.
@ -161,7 +161,7 @@ public:
* *
* @return LayoutType * @return LayoutType
*/ */
virtual LayoutType getLayoutType() const override{return LayoutType::ABSOLUTE;}; virtual Type getLayoutType() const override{return Type::ABSOLUTE;};
/** /**
* Returns the "class name" of widget. * Returns the "class name" of widget.

View File

@ -64,7 +64,7 @@ bool RelativeBox::init()
{ {
if (Layout::init()) if (Layout::init())
{ {
setLayoutType(LayoutType::RELATIVE); setLayoutType(Layout::Type::RELATIVE);
return true; return true;
} }
return false; return false;

View File

@ -1695,12 +1695,12 @@ Layout* ScrollView::getInnerContainer()
return _innerContainer; return _innerContainer;
} }
void ScrollView::setLayoutType(LayoutType type) void ScrollView::setLayoutType(Type type)
{ {
_innerContainer->setLayoutType(type); _innerContainer->setLayoutType(type);
} }
Layout::LayoutType ScrollView::getLayoutType() const Layout::Type ScrollView::getLayoutType() const
{ {
return _innerContainer->getLayoutType(); return _innerContainer->getLayoutType();
} }

View File

@ -322,7 +322,7 @@ public:
* *
* @param LayoutType * @param LayoutType
*/ */
virtual void setLayoutType(LayoutType type) override; virtual void setLayoutType(Type type) override;
/** /**
* Gets LayoutType. * Gets LayoutType.
@ -331,7 +331,7 @@ public:
* *
* @return LayoutType * @return LayoutType
*/ */
virtual LayoutType getLayoutType() const override; virtual Type getLayoutType() const override;
/** /**
* Returns the "class name" of widget. * Returns the "class name" of widget.

View File

@ -64,7 +64,7 @@ bool VBox::init()
{ {
if (Layout::init()) if (Layout::init())
{ {
setLayoutType(LayoutType::VERTICAL); setLayoutType(Layout::Type::VERTICAL);
return true; return true;
} }
return false; return false;

View File

@ -46,7 +46,6 @@ _touchEndPos(Vector2::ZERO),
_touchEventListener(nullptr), _touchEventListener(nullptr),
_touchEventSelector(nullptr), _touchEventSelector(nullptr),
_name("default"), _name("default"),
_widgetType(Type::ELEMENT),
_actionTag(0), _actionTag(0),
_size(Size::ZERO), _size(Size::ZERO),
_customSize(Size::ZERO), _customSize(Size::ZERO),
@ -68,6 +67,7 @@ _focusEnabled(true)
{ {
onFocusChanged = CC_CALLBACK_2(Widget::onFocusChange,this); onFocusChanged = CC_CALLBACK_2(Widget::onFocusChange,this);
onNextFocusedWidget = nullptr; onNextFocusedWidget = nullptr;
this->setAnchorPoint(Vector2(0.5f, 0.5f));
} }
Widget::~Widget() Widget::~Widget()
@ -834,10 +834,6 @@ const std::string& Widget::getName() const
return _name; return _name;
} }
Widget::Type Widget::getWidgetType() const
{
return _widgetType;
}
void Widget::setLayoutParameter(LayoutParameter *parameter) void Widget::setLayoutParameter(LayoutParameter *parameter)
{ {

View File

@ -94,12 +94,6 @@ public:
PLIST = 1 PLIST = 1
}; };
enum class Type
{
ELEMENT,
CONTAINER
};
enum class BrightStyle enum class BrightStyle
{ {
NONE = -1, NONE = -1,
@ -405,15 +399,6 @@ public:
*/ */
const std::string& getName() const; const std::string& getName() const;
/**
* Returns a type that is widget's type
*
* @see WidgetType
*
* @return A WidgetType
*/
Type getWidgetType() const;
/** /**
* Changes the size that is widget's size * Changes the size that is widget's size
* *
@ -679,8 +664,7 @@ protected:
ccWidgetTouchCallback _touchEventCallback; ccWidgetTouchCallback _touchEventCallback;
std::string _name; std::string _name;
Type _widgetType; int _actionTag;
int _actionTag;
Size _size; Size _size;
Size _customSize; Size _customSize;
bool _ignoreSize; bool _ignoreSize;