diff --git a/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id b/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id index 47e338de5b..aff667703a 100644 --- a/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -2abd573d3cb41c16925cbdf14bd55be5f97d88a4 \ No newline at end of file +a87ed79f8ef68972cf8791008b9d79f2a5ed84f1 \ No newline at end of file diff --git a/extensions/Android.mk b/extensions/Android.mk index cbd8d39ebd..4289775bc8 100644 --- a/extensions/Android.mk +++ b/extensions/Android.mk @@ -63,7 +63,6 @@ CocoStudio/Components/CCInputDelegate.cpp \ CocoStudio/GUI/BaseClasses/UIRootWidget.cpp \ CocoStudio/GUI/BaseClasses/UIWidget.cpp \ CocoStudio/GUI/Layouts/Layout.cpp \ -CocoStudio/GUI/Layouts/LayoutExecutant.cpp \ CocoStudio/GUI/Layouts/LayoutParameter.cpp \ CocoStudio/GUI/Layouts/UILayoutDefine.cpp \ CocoStudio/GUI/System/CocosGUI.cpp \ diff --git a/extensions/CocoStudio/GUI/Layouts/Layout.cpp b/extensions/CocoStudio/GUI/Layouts/Layout.cpp index a32aaf6cb6..3492de9486 100644 --- a/extensions/CocoStudio/GUI/Layouts/Layout.cpp +++ b/extensions/CocoStudio/GUI/Layouts/Layout.cpp @@ -24,6 +24,7 @@ #include "Layout.h" #include "../System/UILayer.h" +#include "../System/UIHelper.h" #include "../../../GUI/CCControlExtension/CCScale9Sprite.h" NS_CC_EXT_BEGIN @@ -32,7 +33,6 @@ NS_CC_EXT_BEGIN Layout::Layout(): _clippingEnabled(false), -_layoutExecutant(NULL), _backGroundScale9Enabled(false), _backGroundImage(NULL), _backGroundImageFileName(""), @@ -46,14 +46,14 @@ _gStartColor(Color3B::WHITE), _gEndColor(Color3B::WHITE), _alongVector(Point(0.0f, -1.0f)), _cOpacity(255), -_backGroundImageTextureSize(Size::ZERO) +_backGroundImageTextureSize(Size::ZERO), +_layoutType(LAYOUT_ABSOLUTE) { _widgetType = WidgetTypeContainer; } Layout::~Layout() { - CC_SAFE_RELEASE_NULL(_layoutExecutant); } Layout* Layout::create() @@ -90,22 +90,6 @@ bool Layout::init() return true; } -void Layout::setLayoutExecutant(LayoutExecutant *exe) -{ - if (_layoutExecutant) - { - CC_SAFE_RELEASE_NULL(_layoutExecutant); - } - _layoutExecutant = exe; - _layoutExecutant->setLayout(this); - CC_SAFE_RETAIN(_layoutExecutant); -} - -LayoutExecutant* Layout::getLayoutExecutant() const -{ - return _layoutExecutant; -} - void Layout::initRenderer() { _renderer = RectClippingNode::create(); @@ -136,10 +120,7 @@ void Layout::setClippingEnabled(bool able) void Layout::onSizeChanged() { DYNAMIC_CAST_CLIPPINGLAYER->setClippingSize(_size); - if (_layoutExecutant) - { - _layoutExecutant->doLayout(); - } + doLayout(); if (_backGroundImage) { _backGroundImage->setPosition(Point(_size.width/2.0f, _size.height/2.0f)); @@ -425,6 +406,283 @@ const Size& Layout::getContentSize() const return _renderer->getContentSize(); } +void Layout::setLayoutType(LayoutType type) +{ + _layoutType = type; +} + +LayoutType Layout::getLayoutType() const +{ + return _layoutType; +} + +void Layout::doLayout() +{ + switch (_layoutType) + { + case LAYOUT_ABSOLUTE: + break; + case LAYOUT_LINEAR_VERTICAL: + { + ccArray* layoutChildrenArray = getChildren()->data; + int length = layoutChildrenArray->num; + Size layoutSize = getSize(); + float topBoundary = layoutSize.height; + for (int i=0; i(layoutChildrenArray->arr[i]); + LinearLayoutParameter* layoutParameter = dynamic_cast(child->getLayoutParameter()); + + if (layoutParameter) + { + WidgetType childType = child->getWidgetType(); + UILinearGravity childGravity = layoutParameter->getGravity(); + Point ap = child->getAnchorPoint(); + Size cs = child->getSize(); + float finalPosX = childType == WidgetTypeWidget ? ap.x * cs.width : 0.0f; + float finalPosY = childType == WidgetTypeWidget ? topBoundary - ((1.0f-ap.y) * cs.height) : topBoundary - cs.height; + switch (childGravity) + { + case LINEAR_GRAVITY_NONE: + case LINEAR_GRAVITY_LEFT: + break; + case LINEAR_GRAVITY_RIGHT: + finalPosX = childType == WidgetTypeWidget ? layoutSize.width - ((1.0f - ap.x) * cs.width) : layoutSize.width - cs.width; + break; + case LINEAR_GRAVITY_CENTER_HORIZONTAL: + finalPosX = childType == WidgetTypeWidget ? layoutSize.width / 2.0f - cs.width * (0.5f-ap.x) : (layoutSize.width - cs.width) * 0.5f; + break; + default: + break; + } + UIMargin mg = layoutParameter->getMargin(); + finalPosX += mg.left; + finalPosY -= mg.top; + child->setPosition(Point(finalPosX, finalPosY)); + topBoundary = child->getBottomInParent() - mg.bottom; + } + } + break; + } + case LAYOUT_LINEAR_HORIZONTAL: + { + ccArray* layoutChildrenArray = getChildren()->data; + int length = layoutChildrenArray->num; + Size layoutSize = getSize(); + float leftBoundary = 0.0f; + for (int i=0; i(layoutChildrenArray->arr[i]); + LinearLayoutParameter* layoutParameter = dynamic_cast(child->getLayoutParameter()); + + if (layoutParameter) + { + WidgetType childType = child->getWidgetType(); + UILinearGravity childGravity = layoutParameter->getGravity(); + Point ap = child->getAnchorPoint(); + Size cs = child->getSize(); + float finalPosX = childType == WidgetTypeWidget ? leftBoundary + (ap.x * cs.width) : leftBoundary; + float finalPosY = childType == WidgetTypeWidget ? layoutSize.height - (1.0f - ap.y) * cs.height : layoutSize.height - cs.height; + switch (childGravity) + { + case LINEAR_GRAVITY_NONE: + case LINEAR_GRAVITY_TOP: + break; + case LINEAR_GRAVITY_BOTTOM: + finalPosY = childType == WidgetTypeWidget ? ap.y * cs.height : 0.0f; + break; + case LINEAR_GRAVITY_CENTER_VERTICAL: + finalPosY = childType == WidgetTypeWidget ? layoutSize.height/2.0f - cs.height * (0.5f - ap.y) : (layoutSize.height - cs.height) * 0.5f; + break; + default: + break; + } + UIMargin mg = layoutParameter->getMargin(); + finalPosX += mg.left; + finalPosY -= mg.top; + child->setPosition(Point(finalPosX, finalPosY)); + leftBoundary = child->getRightInParent() + mg.right; + } + } + break; + } + case LAYOUT_RELATIVE: + { + ccArray* layoutChildrenArray = getChildren()->data; + int length = layoutChildrenArray->num; + Size layoutSize = getSize(); + for (int i=0; i(layoutChildrenArray->arr[i]); + WidgetType childType = child->getWidgetType(); + Point ap = child->getAnchorPoint(); + Size cs = child->getSize(); + RelativeLayoutParameter* layoutParameter = dynamic_cast(child->getLayoutParameter()); + if (layoutParameter) + { + float finalPosX = childType == WidgetTypeWidget ? ap.x * cs.width : 0.0f; + float finalPosY = childType == WidgetTypeWidget ? layoutSize.height - ((1.0f - ap.y) * cs.height) : layoutSize.height - cs.height; + UIRelativeAlign align = layoutParameter->getAlign(); + const char* relativeName = layoutParameter->getRelativeToWidgetName(); + UIWidget* relativeWidget = NULL; + if (relativeName && strcmp(relativeName, "")) + { + relativeWidget = CCUIHELPER->seekWidgetByRelativeName(this, relativeName); + } + switch (align) + { + case RELATIVE_ALIGN_NONE: + break; + case RELATIVE_ALIGN_PARENT_LEFT: + break; + case RELATIVE_ALIGN_PARENT_TOP: + break; + case RELATIVE_ALIGN_PARENT_RIGHT: + finalPosX = childType == WidgetTypeWidget ? layoutSize.width - ((1.0f - ap.x) * cs.width) : layoutSize.width - cs.width; + break; + case RELATIVE_ALIGN_PARENT_BOTTOM: + finalPosY = childType == WidgetTypeWidget ? ap.y * cs.height : 0.0f; + break; + case RELATIVE_CENTER_IN_PARENT: + finalPosX = childType == WidgetTypeWidget ? layoutSize.width * 0.5f - cs.width * (0.5f - ap.x) : (layoutSize.width - cs.width) * 0.5f; + finalPosY = childType == WidgetTypeWidget ? layoutSize.height * 0.5f - cs.height * (0.5f - ap.y) : (layoutSize.height - cs.height) * 0.5f; + break; + case RELATIVE_CENTER_HORIZONTAL: + finalPosX = childType == WidgetTypeWidget ? layoutSize.width * 0.5f - cs.width * (0.5f - ap.x) : (layoutSize.width - cs.width) * 0.5f; + break; + case RELATIVE_CENTER_VERTICAL: + finalPosY = childType == WidgetTypeWidget ? layoutSize.height * 0.5f - cs.height * (0.5f - ap.y) : (layoutSize.height - cs.height) * 0.5f; + break; + case RELATIVE_LOCATION_LEFT_OF_TOPALIGN: + if (relativeWidget) + { + float locationTop = relativeWidget->getTopInParent(); + float locationRight = relativeWidget->getLeftInParent(); + finalPosY = childType == WidgetTypeWidget ? locationTop - ap.y * cs.height : locationTop - cs.height; + finalPosX = childType == WidgetTypeWidget ? locationRight - (1.0f - ap.x) * cs.width : locationRight - cs.width; + } + break; + case RELATIVE_LOCATION_LEFT_OF_CENTER: + break; + case RELATIVE_LOCATION_LEFT_OF_BOTTOMALIGN: + if (relativeWidget) + { + float locationRight = relativeWidget->getLeftInParent(); + float locationBottom = relativeWidget->getBottomInParent(); + finalPosY = childType == WidgetTypeWidget ? locationBottom + ap.y * cs.height : locationBottom; + finalPosX = childType == WidgetTypeWidget ? locationRight - (1.0f - ap.x) * cs.width : locationRight - cs.width; + } + break; + case RELATIVE_LOCATION_RIGHT_OF_TOPALIGN: + if (relativeWidget) + { + float locationTop = relativeWidget->getTopInParent(); + float locationLeft = relativeWidget->getRightInParent(); + finalPosY = childType == WidgetTypeWidget ? locationTop - ap.y * cs.height : locationTop - cs.height; + finalPosX = childType == WidgetTypeWidget ? locationLeft + ap.x * cs.width : locationLeft; + } + break; + case RELATIVE_LOCATION_RIGHT_OF_CENTER: + break; + case RELATIVE_LOCATION_RIGHT_OF_BOTTOMALIGN: + if (relativeWidget) + { + float locationLeft = relativeWidget->getRightInParent(); + float locationBottom = relativeWidget->getBottomInParent(); + finalPosY = childType == WidgetTypeWidget ? locationBottom + ap.y * cs.height : locationBottom; + finalPosX = childType == WidgetTypeWidget ? locationLeft + ap.x * cs.width : locationLeft; + } + break; + case RELATIVE_LOCATION_ABOVE_LEFTALIGN: + if (relativeWidget) + { + float locationBottom = relativeWidget->getTopInParent(); + float locationLeft = relativeWidget->getLeftInParent(); + finalPosY = childType == WidgetTypeWidget ? locationBottom + ap.y * cs.height : locationBottom; + finalPosX = childType == WidgetTypeWidget ? locationLeft + ap.x * cs.width : locationLeft; + } + break; + case RELATIVE_LOCATION_ABOVE_CENTER: + break; + case RELATIVE_LOCATION_ABOVE_RIGHTALIGN: + if (relativeWidget) + { + float locationBottom = relativeWidget->getTopInParent(); + float locationRight = relativeWidget->getRightInParent(); + finalPosY = childType == WidgetTypeWidget ? locationBottom + ap.y * cs.height : locationBottom; + finalPosX = childType == WidgetTypeWidget ? locationRight - (1.0f - ap.x) * cs.width : locationRight - cs.width; + } + break; + case RELATIVE_LOCATION_BELOW_LEFTALIGN: + if (relativeWidget) + { + float locationTop = relativeWidget->getBottomInParent(); + float locationLeft = relativeWidget->getLeftInParent(); + finalPosY = childType == WidgetTypeWidget ? locationTop - (1.0f - ap.y) * cs.height : locationTop - cs.height; + finalPosX = childType == WidgetTypeWidget ? locationLeft + ap.x * cs.width : locationLeft; + } + break; + case RELATIVE_LOCATION_BELOW_CENTER: + break; + case RELATIVE_LOCATION_BELOW_RIGHTALIGN: + if (relativeWidget) + { + float locationTop = relativeWidget->getBottomInParent(); + float locationRight = relativeWidget->getRightInParent(); + finalPosY = childType == WidgetTypeWidget ? locationTop - (1.0f - ap.y) * cs.height : locationTop - cs.height; + finalPosX = childType == WidgetTypeWidget ? locationRight - (1.0f - ap.x) * cs.width : locationRight - cs.width; + } + break; + default: + break; + } + UIMargin relativeWidgetMargin; + UIMargin mg; + if (relativeWidget) + { + relativeWidgetMargin = relativeWidget->getLayoutParameter()->getMargin(); + mg = child->getLayoutParameter()->getMargin(); + } + //handle margin + switch (align) + { + case RELATIVE_LOCATION_ABOVE_LEFTALIGN: + case RELATIVE_LOCATION_ABOVE_RIGHTALIGN: + case RELATIVE_LOCATION_ABOVE_CENTER: + finalPosY += relativeWidgetMargin.top; + finalPosY += mg.bottom; + break; + case RELATIVE_LOCATION_BELOW_LEFTALIGN: + case RELATIVE_LOCATION_BELOW_RIGHTALIGN: + case RELATIVE_LOCATION_BELOW_CENTER: + finalPosY -= relativeWidgetMargin.bottom; + finalPosY -= mg.top; + break; + case RELATIVE_LOCATION_LEFT_OF_TOPALIGN: + case RELATIVE_LOCATION_LEFT_OF_BOTTOMALIGN: + case RELATIVE_LOCATION_LEFT_OF_CENTER: + finalPosX -= relativeWidgetMargin.left; + finalPosX -= mg.right; + break; + case RELATIVE_LOCATION_RIGHT_OF_TOPALIGN: + case RELATIVE_LOCATION_RIGHT_OF_BOTTOMALIGN: + case RELATIVE_LOCATION_RIGHT_OF_CENTER: + finalPosX += relativeWidgetMargin.right; + finalPosX += mg.left; + break; + default: + break; + } + child->setPosition(Point(finalPosX, finalPosY)); + } + } + break; + } + default: + break; + } +} + const char* Layout::getDescription() const { return "Layout"; diff --git a/extensions/CocoStudio/GUI/Layouts/Layout.h b/extensions/CocoStudio/GUI/Layouts/Layout.h index 9afa9f539c..bf8719a06d 100644 --- a/extensions/CocoStudio/GUI/Layouts/Layout.h +++ b/extensions/CocoStudio/GUI/Layouts/Layout.h @@ -26,7 +26,6 @@ #define __LAYOUT_H__ #include "../BaseClasses/UIWidget.h" -#include "LayoutExecutant.h" NS_CC_EXT_BEGIN @@ -37,6 +36,14 @@ typedef enum LAYOUT_COLOR_GRADIENT }LayoutBackGroundColorType; +typedef enum +{ + LAYOUT_ABSOLUTE, + LAYOUT_LINEAR_VERTICAL, + LAYOUT_LINEAR_HORIZONTAL, + LAYOUT_RELATIVE +}LayoutType; + class Layout : public UIWidget { public: @@ -55,24 +62,6 @@ public: */ static Layout* create(); - /** - * Sets a LayoutExecutant for doing layout. - * - * @see LayoutExecutant - * - * @param LayoutExecutant pointer. - */ - virtual void setLayoutExecutant(LayoutExecutant* exe); - - /** - * Gets the LayoutExecutant of Layout - * - * @see LayoutExecutant - * - * @return LayoutExecutant pointer. - */ - virtual LayoutExecutant* getLayoutExecutant() const; - //override "hitTest" method of widget. virtual bool hitTest(const Point &pt); @@ -178,6 +167,26 @@ public: * Content size is widget's texture size. */ virtual const Size& getContentSize() const; + + /** + * Sets LayoutType. + * + * @see LayoutType + * + * @param LayoutType + */ + virtual void setLayoutType(LayoutType type); + + /** + * Gets LayoutType. + * + * @see LayoutType + * + * @return LayoutType + */ + virtual LayoutType getLayoutType() const; + + virtual void doLayout(); /** * Returns the "class name" of widget. @@ -197,7 +206,6 @@ protected: void addBackGroundImage(); protected: bool _clippingEnabled; - LayoutExecutant* _layoutExecutant; //background bool _backGroundScale9Enabled; @@ -214,6 +222,7 @@ protected: Point _alongVector; int _cOpacity; Size _backGroundImageTextureSize; + LayoutType _layoutType; }; class RectClippingNode : public ClippingNode diff --git a/extensions/CocoStudio/GUI/Layouts/LayoutExecutant.cpp b/extensions/CocoStudio/GUI/Layouts/LayoutExecutant.cpp deleted file mode 100644 index fa049ae69b..0000000000 --- a/extensions/CocoStudio/GUI/Layouts/LayoutExecutant.cpp +++ /dev/null @@ -1,342 +0,0 @@ -/**************************************************************************** - Copyright (c) 2013 cocos2d-x.org - - 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 "LayoutExecutant.h" -#include "Layout.h" -#include "../System/UIHelper.h" - -NS_CC_EXT_BEGIN - -void LayoutExecutant::setLayout(Layout *layout) -{ - _layout = layout; -} - -Layout* LayoutExecutant::getLayout() const -{ - return _layout; -} - -LinearVerticalLayoutExecutant* LinearVerticalLayoutExecutant::create() -{ - LinearVerticalLayoutExecutant* executant = new LinearVerticalLayoutExecutant(); - if (executant) - { - executant->autorelease(); - return executant; - } - CC_SAFE_DELETE(executant); - return NULL; -} - -LinearHorizontalLayoutExecutant* LinearHorizontalLayoutExecutant::create() -{ - LinearHorizontalLayoutExecutant* executant = new LinearHorizontalLayoutExecutant(); - if (executant) - { - executant->autorelease(); - return executant; - } - CC_SAFE_DELETE(executant); - return NULL; -} - -RelativeLayoutExecutant* RelativeLayoutExecutant::create() -{ - RelativeLayoutExecutant* executant = new RelativeLayoutExecutant(); - if (executant) - { - executant->autorelease(); - return executant; - } - CC_SAFE_DELETE(executant); - return NULL; -} - -void LinearVerticalLayoutExecutant::doLayout() -{ - if (_layout) - { - ccArray* layoutChildrenArray = _layout->getChildren()->data; - int length = layoutChildrenArray->num; - Size layoutSize = _layout->getSize(); - float topBoundary = layoutSize.height; - for (int i=0; i(layoutChildrenArray->arr[i]); - LinearLayoutParameter* layoutParameter = dynamic_cast(child->getLayoutParameter()); - - if (layoutParameter) - { - WidgetType childType = child->getWidgetType(); - UILinearGravity childGravity = layoutParameter->getGravity(); - Point ap = child->getAnchorPoint(); - Size cs = child->getSize(); - float finalPosX = childType == WidgetTypeWidget ? ap.x * cs.width : 0.0f; - float finalPosY = childType == WidgetTypeWidget ? topBoundary - ((1.0f-ap.y) * cs.height) : topBoundary - cs.height; - switch (childGravity) - { - case LINEAR_GRAVITY_NONE: - case LINEAR_GRAVITY_LEFT: - break; - case LINEAR_GRAVITY_RIGHT: - finalPosX = childType == WidgetTypeWidget ? layoutSize.width - ((1.0f - ap.x) * cs.width) : layoutSize.width - cs.width; - break; - case LINEAR_GRAVITY_CENTER_HORIZONTAL: - finalPosX = childType == WidgetTypeWidget ? layoutSize.width / 2.0f - cs.width * (0.5f-ap.x) : (layoutSize.width - cs.width) * 0.5f; - break; - default: - break; - } - UIMargin mg = layoutParameter->getMargin(); - finalPosX += mg.left; - finalPosY -= mg.top; - child->setPosition(Point(finalPosX, finalPosY)); - topBoundary = child->getBottomInParent() - mg.bottom; - } - } - } -} - -void LinearHorizontalLayoutExecutant::doLayout() -{ - if (_layout) - { - ccArray* layoutChildrenArray = _layout->getChildren()->data; - int length = layoutChildrenArray->num; - Size layoutSize = _layout->getSize(); - float leftBoundary = 0.0f; - for (int i=0; i(layoutChildrenArray->arr[i]); - LinearLayoutParameter* layoutParameter = dynamic_cast(child->getLayoutParameter()); - - if (layoutParameter) - { - WidgetType childType = child->getWidgetType(); - UILinearGravity childGravity = layoutParameter->getGravity(); - Point ap = child->getAnchorPoint(); - Size cs = child->getSize(); - float finalPosX = childType == WidgetTypeWidget ? leftBoundary + (ap.x * cs.width) : leftBoundary; - float finalPosY = childType == WidgetTypeWidget ? layoutSize.height - (1.0f - ap.y) * cs.height : layoutSize.height - cs.height; - switch (childGravity) - { - case LINEAR_GRAVITY_NONE: - case LINEAR_GRAVITY_TOP: - break; - case LINEAR_GRAVITY_BOTTOM: - finalPosY = childType == WidgetTypeWidget ? ap.y * cs.height : 0.0f; - break; - case LINEAR_GRAVITY_CENTER_VERTICAL: - finalPosY = childType == WidgetTypeWidget ? layoutSize.height/2.0f - cs.height * (0.5f - ap.y) : (layoutSize.height - cs.height) * 0.5f; - break; - default: - break; - } - UIMargin mg = layoutParameter->getMargin(); - finalPosX += mg.left; - finalPosY -= mg.top; - child->setPosition(Point(finalPosX, finalPosY)); - leftBoundary = child->getRightInParent() + mg.right; - } - } - } -} - -void RelativeLayoutExecutant::doLayout() -{ - if (_layout) - { - ccArray* layoutChildrenArray = _layout->getChildren()->data; - int length = layoutChildrenArray->num; - Size layoutSize = _layout->getSize(); - for (int i=0; i(layoutChildrenArray->arr[i]); - WidgetType childType = child->getWidgetType(); - Point ap = child->getAnchorPoint(); - Size cs = child->getSize(); - RelativeLayoutParameter* layoutParameter = dynamic_cast(child->getLayoutParameter()); - if (layoutParameter) - { - float finalPosX = childType == WidgetTypeWidget ? ap.x * cs.width : 0.0f; - float finalPosY = childType == WidgetTypeWidget ? layoutSize.height - ((1.0f - ap.y) * cs.height) : layoutSize.height - cs.height; - UIRelativeAlign align = layoutParameter->getAlign(); - const char* relativeName = layoutParameter->getRelativeToWidgetName(); - UIWidget* relativeWidget = NULL; - if (relativeName && strcmp(relativeName, "")) - { - relativeWidget = CCUIHELPER->seekWidgetByRelativeName(_layout, relativeName); - } - switch (align) - { - case RELATIVE_ALIGN_NONE: - break; - case RELATIVE_ALIGN_PARENT_LEFT: - break; - case RELATIVE_ALIGN_PARENT_TOP: - break; - case RELATIVE_ALIGN_PARENT_RIGHT: - finalPosX = childType == WidgetTypeWidget ? layoutSize.width - ((1.0f - ap.x) * cs.width) : layoutSize.width - cs.width; - break; - case RELATIVE_ALIGN_PARENT_BOTTOM: - finalPosY = childType == WidgetTypeWidget ? ap.y * cs.height : 0.0f; - break; - case RELATIVE_CENTER_IN_PARENT: - finalPosX = childType == WidgetTypeWidget ? layoutSize.width * 0.5f - cs.width * (0.5f - ap.x) : (layoutSize.width - cs.width) * 0.5f; - finalPosY = childType == WidgetTypeWidget ? layoutSize.height * 0.5f - cs.height * (0.5f - ap.y) : (layoutSize.height - cs.height) * 0.5f; - break; - case RELATIVE_CENTER_HORIZONTAL: - finalPosX = childType == WidgetTypeWidget ? layoutSize.width * 0.5f - cs.width * (0.5f - ap.x) : (layoutSize.width - cs.width) * 0.5f; - break; - case RELATIVE_CENTER_VERTICAL: - finalPosY = childType == WidgetTypeWidget ? layoutSize.height * 0.5f - cs.height * (0.5f - ap.y) : (layoutSize.height - cs.height) * 0.5f; - break; - case RELATIVE_LOCATION_LEFT_OF_TOPALIGN: - if (relativeWidget) - { - float locationTop = relativeWidget->getTopInParent(); - float locationRight = relativeWidget->getLeftInParent(); - finalPosY = childType == WidgetTypeWidget ? locationTop - ap.y * cs.height : locationTop - cs.height; - finalPosX = childType == WidgetTypeWidget ? locationRight - (1.0f - ap.x) * cs.width : locationRight - cs.width; - } - break; - case RELATIVE_LOCATION_LEFT_OF_CENTER: - break; - case RELATIVE_LOCATION_LEFT_OF_BOTTOMALIGN: - if (relativeWidget) - { - float locationRight = relativeWidget->getLeftInParent(); - float locationBottom = relativeWidget->getBottomInParent(); - finalPosY = childType == WidgetTypeWidget ? locationBottom + ap.y * cs.height : locationBottom; - finalPosX = childType == WidgetTypeWidget ? locationRight - (1.0f - ap.x) * cs.width : locationRight - cs.width; - } - break; - case RELATIVE_LOCATION_RIGHT_OF_TOPALIGN: - if (relativeWidget) - { - float locationTop = relativeWidget->getTopInParent(); - float locationLeft = relativeWidget->getRightInParent(); - finalPosY = childType == WidgetTypeWidget ? locationTop - ap.y * cs.height : locationTop - cs.height; - finalPosX = childType == WidgetTypeWidget ? locationLeft + ap.x * cs.width : locationLeft; - } - break; - case RELATIVE_LOCATION_RIGHT_OF_CENTER: - break; - case RELATIVE_LOCATION_RIGHT_OF_BOTTOMALIGN: - if (relativeWidget) - { - float locationLeft = relativeWidget->getRightInParent(); - float locationBottom = relativeWidget->getBottomInParent(); - finalPosY = childType == WidgetTypeWidget ? locationBottom + ap.y * cs.height : locationBottom; - finalPosX = childType == WidgetTypeWidget ? locationLeft + ap.x * cs.width : locationLeft; - } - break; - case RELATIVE_LOCATION_ABOVE_LEFTALIGN: - if (relativeWidget) - { - float locationBottom = relativeWidget->getTopInParent(); - float locationLeft = relativeWidget->getLeftInParent(); - finalPosY = childType == WidgetTypeWidget ? locationBottom + ap.y * cs.height : locationBottom; - finalPosX = childType == WidgetTypeWidget ? locationLeft + ap.x * cs.width : locationLeft; - } - break; - case RELATIVE_LOCATION_ABOVE_CENTER: - break; - case RELATIVE_LOCATION_ABOVE_RIGHTALIGN: - if (relativeWidget) - { - float locationBottom = relativeWidget->getTopInParent(); - float locationRight = relativeWidget->getRightInParent(); - finalPosY = childType == WidgetTypeWidget ? locationBottom + ap.y * cs.height : locationBottom; - finalPosX = childType == WidgetTypeWidget ? locationRight - (1.0f - ap.x) * cs.width : locationRight - cs.width; - } - break; - case RELATIVE_LOCATION_BELOW_LEFTALIGN: - if (relativeWidget) - { - float locationTop = relativeWidget->getBottomInParent(); - float locationLeft = relativeWidget->getLeftInParent(); - finalPosY = childType == WidgetTypeWidget ? locationTop - (1.0f - ap.y) * cs.height : locationTop - cs.height; - finalPosX = childType == WidgetTypeWidget ? locationLeft + ap.x * cs.width : locationLeft; - } - break; - case RELATIVE_LOCATION_BELOW_CENTER: - break; - case RELATIVE_LOCATION_BELOW_RIGHTALIGN: - if (relativeWidget) - { - float locationTop = relativeWidget->getBottomInParent(); - float locationRight = relativeWidget->getRightInParent(); - finalPosY = childType == WidgetTypeWidget ? locationTop - (1.0f - ap.y) * cs.height : locationTop - cs.height; - finalPosX = childType == WidgetTypeWidget ? locationRight - (1.0f - ap.x) * cs.width : locationRight - cs.width; - } - break; - default: - break; - } - UIMargin relativeWidgetMargin; - UIMargin mg; - if (relativeWidget) - { - relativeWidgetMargin = relativeWidget->getLayoutParameter()->getMargin(); - mg = child->getLayoutParameter()->getMargin(); - } - //handle margin - switch (align) - { - case RELATIVE_LOCATION_ABOVE_LEFTALIGN: - case RELATIVE_LOCATION_ABOVE_RIGHTALIGN: - case RELATIVE_LOCATION_ABOVE_CENTER: - finalPosY += relativeWidgetMargin.top; - finalPosY += mg.bottom; - break; - case RELATIVE_LOCATION_BELOW_LEFTALIGN: - case RELATIVE_LOCATION_BELOW_RIGHTALIGN: - case RELATIVE_LOCATION_BELOW_CENTER: - finalPosY -= relativeWidgetMargin.bottom; - finalPosY -= mg.top; - break; - case RELATIVE_LOCATION_LEFT_OF_TOPALIGN: - case RELATIVE_LOCATION_LEFT_OF_BOTTOMALIGN: - case RELATIVE_LOCATION_LEFT_OF_CENTER: - finalPosX -= relativeWidgetMargin.left; - finalPosX -= mg.right; - break; - case RELATIVE_LOCATION_RIGHT_OF_TOPALIGN: - case RELATIVE_LOCATION_RIGHT_OF_BOTTOMALIGN: - case RELATIVE_LOCATION_RIGHT_OF_CENTER: - finalPosX += relativeWidgetMargin.right; - finalPosX += mg.left; - break; - default: - break; - } - child->setPosition(Point(finalPosX, finalPosY)); - } - } - } -} - -NS_CC_EXT_END \ No newline at end of file diff --git a/extensions/CocoStudio/GUI/Layouts/LayoutExecutant.h b/extensions/CocoStudio/GUI/Layouts/LayoutExecutant.h deleted file mode 100644 index 4bc3519d1c..0000000000 --- a/extensions/CocoStudio/GUI/Layouts/LayoutExecutant.h +++ /dev/null @@ -1,158 +0,0 @@ -/**************************************************************************** - Copyright (c) 2013 cocos2d-x.org - - 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. - ****************************************************************************/ - -#ifndef __LAYOUTEXECUTANT_H__ -#define __LAYOUTEXECUTANT_H__ - -#include "LayoutParameter.h" - -NS_CC_EXT_BEGIN - -typedef enum -{ - LAYOUT_DEFAULT, - LAYOUT_LINEAR_VERTICAL, - LAYOUT_LINEAR_HORIZONTAL, - LAYOUT_RELATIVE -}LayoutType; - -class Layout; - -class LayoutExecutant : public Object -{ -public: - /** - * Default constructor - */ - LayoutExecutant() : _layout(NULL){_layoutType = LAYOUT_DEFAULT;}; - - /** - * Default destructor - */ - virtual ~LayoutExecutant(){_layout = NULL;}; - - /** - * To do layout. Need to be overrided. - */ - virtual void doLayout()=0; - - /** - * Gets LayoutType. - * - * @see LayoutType - * - * @return LayoutType - */ - LayoutType getLayoutType(){return _layoutType;}; - - /** - * Binding a Layout to LayoutExecutant. - * - * @param Layout - */ - void setLayout(Layout* layout); - - /** - * Gets the Layout of LayoutExecutant. - * - * @return Layout - */ - Layout* getLayout() const; -protected: - LayoutType _layoutType; - Layout* _layout; -}; - -class LinearVerticalLayoutExecutant : public LayoutExecutant -{ -public: - /** - * Default constructor - */ - LinearVerticalLayoutExecutant(){_layoutType = LAYOUT_LINEAR_VERTICAL;}; - - /** - * Default destructor - */ - virtual ~LinearVerticalLayoutExecutant(){}; - - /** - * Allocates and initializes. - * @return A initialized LayoutExecutant which is marked as "autorelease". - */ - static LinearVerticalLayoutExecutant* create(); - - //To do layout. - virtual void doLayout(); -}; - -class LinearHorizontalLayoutExecutant : public LayoutExecutant -{ -public: - /** - * Default constructor - */ - LinearHorizontalLayoutExecutant(){_layoutType = LAYOUT_LINEAR_HORIZONTAL;}; - - /** - * Default destructor - */ - virtual ~LinearHorizontalLayoutExecutant(){}; - - /** - * Allocates and initializes. - * @return A initialized LayoutExecutant which is marked as "autorelease". - */ - static LinearHorizontalLayoutExecutant* create(); - - //To do layout. - virtual void doLayout(); -}; - -class RelativeLayoutExecutant : public LayoutExecutant -{ -public: - /** - * Default constructor - */ - RelativeLayoutExecutant(){_layoutType = LAYOUT_RELATIVE;}; - - /** - * Default destructor - */ - virtual ~RelativeLayoutExecutant(){}; - - /** - * Allocates and initializes. - * @return A initialized LayoutExecutant which is marked as "autorelease". - */ - static RelativeLayoutExecutant* create(); - - //To do layout. - virtual void doLayout(); -}; - -NS_CC_EXT_END - -#endif /* defined(__LayoutExecutant__) */ diff --git a/extensions/CocoStudio/GUI/Layouts/LayoutParameter.cpp b/extensions/CocoStudio/GUI/Layouts/LayoutParameter.cpp index 5c1c6699ee..b7456e5074 100644 --- a/extensions/CocoStudio/GUI/Layouts/LayoutParameter.cpp +++ b/extensions/CocoStudio/GUI/Layouts/LayoutParameter.cpp @@ -51,11 +51,7 @@ void LayoutParameter::setMargin(const UIMargin &margin) Layout* containerParent = dynamic_cast(parent); if (containerParent) { - LayoutExecutant* exe = containerParent->getLayoutExecutant(); - if (exe) - { - exe->doLayout(); - } + containerParent->doLayout(); } } } @@ -95,10 +91,9 @@ void LinearLayoutParameter::setGravity(UILinearGravity gravity) Layout* containerParent = dynamic_cast(parent); if (containerParent) { - LayoutExecutant* exe = containerParent->getLayoutExecutant(); - if (exe && (exe->getLayoutType() == LAYOUT_LINEAR_HORIZONTAL || exe->getLayoutType() == LAYOUT_LINEAR_VERTICAL)) + if ((containerParent->getLayoutType() == LAYOUT_LINEAR_HORIZONTAL || containerParent->getLayoutType() == LAYOUT_LINEAR_VERTICAL)) { - exe->doLayout(); + containerParent->doLayout(); } } } @@ -134,10 +129,9 @@ void RelativeLayoutParameter::setAlign(UIRelativeAlign align) Layout* containerParent = dynamic_cast(parent); if (containerParent) { - LayoutExecutant* exe = containerParent->getLayoutExecutant(); - if (exe && (exe->getLayoutType() == LAYOUT_RELATIVE)) + if ((containerParent->getLayoutType() == LAYOUT_RELATIVE)) { - exe->doLayout(); + containerParent->doLayout(); } } } @@ -161,10 +155,9 @@ void RelativeLayoutParameter::setRelativeToWidgetName(const char *name) Layout* containerParent = dynamic_cast(parent); if (containerParent) { - LayoutExecutant* exe = containerParent->getLayoutExecutant(); - if (exe && (exe->getLayoutType() == LAYOUT_RELATIVE)) + if ((containerParent->getLayoutType() == LAYOUT_RELATIVE)) { - exe->doLayout(); + containerParent->doLayout(); } } } @@ -188,10 +181,9 @@ void RelativeLayoutParameter::setRelativeName(const char* name) Layout* containerParent = dynamic_cast(parent); if (containerParent) { - LayoutExecutant* exe = containerParent->getLayoutExecutant(); - if (exe && (exe->getLayoutType() == LAYOUT_RELATIVE)) + if ((containerParent->getLayoutType() == LAYOUT_RELATIVE)) { - exe->doLayout(); + containerParent->doLayout(); } } } diff --git a/extensions/CocoStudio/GUI/System/CocosGUI.h b/extensions/CocoStudio/GUI/System/CocosGUI.h index 37651a694b..ca080ea059 100644 --- a/extensions/CocoStudio/GUI/System/CocosGUI.h +++ b/extensions/CocoStudio/GUI/System/CocosGUI.h @@ -45,7 +45,6 @@ #include "UIHelper.h" #include "../../Reader/CCSGUIReader.h" #include "UILayer.h" -#include "../Layouts/LayoutExecutant.h" NS_CC_EXT_BEGIN const char* CocosGUIVersion(); diff --git a/extensions/CocoStudio/GUI/UIWidgets/ScrollWidget/UIDragPanel.cpp b/extensions/CocoStudio/GUI/UIWidgets/ScrollWidget/UIDragPanel.cpp index 2d4818354b..e21d59e1b8 100644 --- a/extensions/CocoStudio/GUI/UIWidgets/ScrollWidget/UIDragPanel.cpp +++ b/extensions/CocoStudio/GUI/UIWidgets/ScrollWidget/UIDragPanel.cpp @@ -1244,6 +1244,21 @@ Layout* UIDragPanel::getInnerContainer() return _innerContainer; } +void UIDragPanel::setLayoutType(LayoutType type) +{ + _innerContainer->setLayoutType(type); +} + +LayoutType UIDragPanel::getLayoutType() const +{ + return _innerContainer->getLayoutType(); +} + +void UIDragPanel::doLayout() +{ + _innerContainer->doLayout(); +} + const char* UIDragPanel::getDescription() const { return "DragPanel"; diff --git a/extensions/CocoStudio/GUI/UIWidgets/ScrollWidget/UIDragPanel.h b/extensions/CocoStudio/GUI/UIWidgets/ScrollWidget/UIDragPanel.h index c7d0ccbc21..dc05b53d21 100644 --- a/extensions/CocoStudio/GUI/UIWidgets/ScrollWidget/UIDragPanel.h +++ b/extensions/CocoStudio/GUI/UIWidgets/ScrollWidget/UIDragPanel.h @@ -191,6 +191,26 @@ public: */ Layout* getInnerContainer(); + /** + * Sets LayoutType. + * + * @see LayoutType + * + * @param LayoutType + */ + virtual void setLayoutType(LayoutType type); + + /** + * Gets LayoutType. + * + * @see LayoutType + * + * @return LayoutType + */ + virtual LayoutType getLayoutType() const; + + virtual void doLayout(); + /** * Returns the "class name" of widget. */ diff --git a/extensions/CocoStudio/GUI/UIWidgets/ScrollWidget/UIListView.h b/extensions/CocoStudio/GUI/UIWidgets/ScrollWidget/UIListView.h index 658dd4482c..2bbbae212c 100644 --- a/extensions/CocoStudio/GUI/UIWidgets/ScrollWidget/UIListView.h +++ b/extensions/CocoStudio/GUI/UIWidgets/ScrollWidget/UIListView.h @@ -139,6 +139,8 @@ public: /**/ virtual void update(float dt); + virtual void doLayout(){}; + /** * Returns the "class name" of widget. */ diff --git a/extensions/CocoStudio/GUI/UIWidgets/ScrollWidget/UIPageView.h b/extensions/CocoStudio/GUI/UIWidgets/ScrollWidget/UIPageView.h index 974f35019b..6644ce5cd0 100644 --- a/extensions/CocoStudio/GUI/UIWidgets/ScrollWidget/UIPageView.h +++ b/extensions/CocoStudio/GUI/UIWidgets/ScrollWidget/UIPageView.h @@ -138,6 +138,8 @@ public: //override "update" method of widget. virtual void update(float dt); + + virtual void doLayout(){}; /** * Returns the "class name" of widget. diff --git a/extensions/CocoStudio/GUI/UIWidgets/ScrollWidget/UIScrollView.cpp b/extensions/CocoStudio/GUI/UIWidgets/ScrollWidget/UIScrollView.cpp index 1a64d69778..4575c6b832 100644 --- a/extensions/CocoStudio/GUI/UIWidgets/ScrollWidget/UIScrollView.cpp +++ b/extensions/CocoStudio/GUI/UIWidgets/ScrollWidget/UIScrollView.cpp @@ -664,14 +664,19 @@ Layout* UIScrollView::getInnerContainer() return _innerContainer; } -void UIScrollView::setLayoutExecutant(LayoutExecutant *exe) +void UIScrollView::setLayoutType(LayoutType type) { - _innerContainer->setLayoutExecutant(exe); + _innerContainer->setLayoutType(type); } -LayoutExecutant* UIScrollView::getLayoutExecutant() const +LayoutType UIScrollView::getLayoutType() const { - return _innerContainer->getLayoutExecutant(); + return _innerContainer->getLayoutType(); +} + +void UIScrollView::doLayout() +{ + _innerContainer->doLayout(); } const char* UIScrollView::getDescription() const diff --git a/extensions/CocoStudio/GUI/UIWidgets/ScrollWidget/UIScrollView.h b/extensions/CocoStudio/GUI/UIWidgets/ScrollWidget/UIScrollView.h index f2ef9157ee..ecf56cadd7 100644 --- a/extensions/CocoStudio/GUI/UIWidgets/ScrollWidget/UIScrollView.h +++ b/extensions/CocoStudio/GUI/UIWidgets/ScrollWidget/UIScrollView.h @@ -135,13 +135,7 @@ public: * Add call back function called scrollview event triggered */ void addEventListener(Object* target, SEL_ScrollViewEvent selector); - - //override "setLayoutExecutant" method of widget. - virtual void setLayoutExecutant(LayoutExecutant* exe); - - //override "getLayoutExecutant" method of widget. - virtual LayoutExecutant* getLayoutExecutant() const; - + //override "addChild" method of widget. virtual bool addChild(UIWidget* widget); @@ -171,6 +165,26 @@ public: virtual void update(float dt); + /** + * Sets LayoutType. + * + * @see LayoutType + * + * @param LayoutType + */ + virtual void setLayoutType(LayoutType type); + + /** + * Gets LayoutType. + * + * @see LayoutType + * + * @return LayoutType + */ + virtual LayoutType getLayoutType() const; + + virtual void doLayout(); + /** * Returns the "class name" of widget. */ diff --git a/extensions/proj.emscripten/Makefile b/extensions/proj.emscripten/Makefile index 5811dbca76..e2ded4d8c0 100644 --- a/extensions/proj.emscripten/Makefile +++ b/extensions/proj.emscripten/Makefile @@ -86,7 +86,6 @@ SOURCES = ../CCBReader/CCBFileLoader.cpp \ ../CocoStudio/GUI/BaseClasses/UIRootWidget.cpp \ ../CocoStudio/GUI/BaseClasses/UIWidget.cpp \ ../CocoStudio/GUI/Layouts/Layout.cpp \ -../CocoStudio/GUI/Layouts/LayoutExecutant.cpp \ ../CocoStudio/GUI/Layouts/LayoutParameter.cpp \ ../CocoStudio/GUI/Layouts/UILayoutDefine.cpp \ ../CocoStudio/GUI/System/CocosGUI.cpp \ diff --git a/extensions/proj.linux/Makefile b/extensions/proj.linux/Makefile index d491fc23ab..a932d20016 100644 --- a/extensions/proj.linux/Makefile +++ b/extensions/proj.linux/Makefile @@ -84,7 +84,6 @@ SOURCES = ../CCBReader/CCBFileLoader.cpp \ ../CocoStudio/GUI/BaseClasses/UIRootWidget.cpp \ ../CocoStudio/GUI/BaseClasses/UIWidget.cpp \ ../CocoStudio/GUI/Layouts/Layout.cpp \ -../CocoStudio/GUI/Layouts/LayoutExecutant.cpp \ ../CocoStudio/GUI/Layouts/LayoutParameter.cpp \ ../CocoStudio/GUI/Layouts/UILayoutDefine.cpp \ ../CocoStudio/GUI/System/CocosGUI.cpp \ diff --git a/extensions/proj.nacl/Makefile b/extensions/proj.nacl/Makefile index 48cd332a41..2b713969f3 100644 --- a/extensions/proj.nacl/Makefile +++ b/extensions/proj.nacl/Makefile @@ -71,7 +71,6 @@ EXTENSIONS_SOURCES = ../CCBReader/CCBFileLoader.cpp \ ../CocoStudio/GUI/BaseClasses/UIRootWidget.cpp \ ../CocoStudio/GUI/BaseClasses/UIWidget.cpp \ ../CocoStudio/GUI/Layouts/Layout.cpp \ -../CocoStudio/GUI/Layouts/LayoutExecutant.cpp \ ../CocoStudio/GUI/Layouts/LayoutParameter.cpp \ ../CocoStudio/GUI/Layouts/UILayoutDefine.cpp \ ../CocoStudio/GUI/System/CocosGUI.cpp \ diff --git a/extensions/proj.win32/libExtensions.vcxproj b/extensions/proj.win32/libExtensions.vcxproj index bc6aba8c20..b221f7dfd1 100644 --- a/extensions/proj.win32/libExtensions.vcxproj +++ b/extensions/proj.win32/libExtensions.vcxproj @@ -149,7 +149,6 @@ - @@ -284,7 +283,6 @@ - diff --git a/extensions/proj.win32/libExtensions.vcxproj.filters b/extensions/proj.win32/libExtensions.vcxproj.filters index 7740b98e00..e6d6f2354c 100644 --- a/extensions/proj.win32/libExtensions.vcxproj.filters +++ b/extensions/proj.win32/libExtensions.vcxproj.filters @@ -436,9 +436,6 @@ CocoStudio\GUI\Layouts - - CocoStudio\GUI\Layouts - CocoStudio\GUI\Layouts @@ -950,9 +947,6 @@ CocoStudio\GUI\Layouts - - CocoStudio\GUI\Layouts - CocoStudio\GUI\Layouts diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioGUITest/UIPanelTest/UIPanelTest.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioGUITest/UIPanelTest/UIPanelTest.cpp index d3c3e7e2f3..49674298bc 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioGUITest/UIPanelTest/UIPanelTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioGUITest/UIPanelTest/UIPanelTest.cpp @@ -362,6 +362,7 @@ bool UIPanelTest_Layout_Linear_Vertical::init() // Create the layout Layout* layout = Layout::create(); + layout->setLayoutType(LAYOUT_LINEAR_VERTICAL); layout->setSize(Size(280, 150)); Size backgroundSize = background->getSize(); layout->setPosition(Point((widgetSize.width - backgroundSize.width) / 2 + @@ -407,9 +408,7 @@ bool UIPanelTest_Layout_Linear_Vertical::init() lp3->setMargin(UIMargin(0, 10, 0, 10)); - LinearVerticalLayoutExecutant* exe = LinearVerticalLayoutExecutant::create(); - layout->setLayoutExecutant(exe); - exe->doLayout(); + layout->doLayout(); return true; } @@ -446,6 +445,7 @@ bool UIPanelTest_Layout_Linear_Horizontal::init() // Create the layout Layout* layout = Layout::create(); + layout->setLayoutType(LAYOUT_LINEAR_HORIZONTAL); layout->setClippingEnabled(true); layout->setSize(Size(280, 150)); Size backgroundSize = background->getSize(); @@ -491,9 +491,7 @@ bool UIPanelTest_Layout_Linear_Horizontal::init() lp3->setMargin(UIMargin(0, 10, 0, 10)); - LinearHorizontalLayoutExecutant* exe = LinearHorizontalLayoutExecutant::create(); - layout->setLayoutExecutant(exe); - exe->doLayout(); + layout->doLayout(); return true; } @@ -530,6 +528,7 @@ bool UIPanelTest_Layout_Relative::init() // Create the layout Layout* layout = Layout::create(); + layout->setLayoutType(LAYOUT_RELATIVE); layout->setSize(Size(280, 150)); layout->setBackGroundColorType(LAYOUT_COLOR_SOLID); layout->setBackGroundColor(Color3B::GREEN); @@ -574,9 +573,7 @@ bool UIPanelTest_Layout_Relative::init() rp3->setAlign(RELATIVE_ALIGN_PARENT_RIGHT); - RelativeLayoutExecutant* exe = RelativeLayoutExecutant::create(); - layout->setLayoutExecutant(exe); - exe->doLayout(); + layout->doLayout(); return true; }