From fe3358803802374b5fb1fbfb03cc1dc0c42bf987 Mon Sep 17 00:00:00 2001 From: andyque Date: Thu, 3 Apr 2014 11:14:35 +0800 Subject: [PATCH] issue #4636. finish UILayout --- cocos/ui/UILayout.cpp | 8 +- cocos/ui/UILayout.h | 2 +- .../UILayoutTest/UILayoutTest.cpp | 334 +++++------------- 3 files changed, 98 insertions(+), 246 deletions(-) diff --git a/cocos/ui/UILayout.cpp b/cocos/ui/UILayout.cpp index 9808553d62..27ce84dfa4 100644 --- a/cocos/ui/UILayout.cpp +++ b/cocos/ui/UILayout.cpp @@ -1111,7 +1111,7 @@ void Layout::setBackGroundImageScale9Enabled(bool able) _backGroundImage = nullptr; _backGroundScale9Enabled = able; addBackGroundImage(); - setBackGroundImage(_backGroundImageFileName.c_str(),_bgImageTexType); + setBackGroundImage(_backGroundImageFileName,_bgImageTexType); setBackGroundImageCapInsets(_backGroundImageCapInsets); } @@ -1120,9 +1120,9 @@ bool Layout::isBackGroundImageScale9Enabled() return _backGroundScale9Enabled; } -void Layout::setBackGroundImage(const char* fileName,TextureResType texType) +void Layout::setBackGroundImage(const std::string& fileName,TextureResType texType) { - if (!fileName || strcmp(fileName, "") == 0) + if (fileName.empty()) { return; } @@ -1519,7 +1519,7 @@ void Layout::copySpecialProperties(Widget *widget) if (layout) { setBackGroundImageScale9Enabled(layout->_backGroundScale9Enabled); - setBackGroundImage(layout->_backGroundImageFileName.c_str(),layout->_bgImageTexType); + setBackGroundImage(layout->_backGroundImageFileName,layout->_bgImageTexType); setBackGroundImageCapInsets(layout->_backGroundImageCapInsets); setBackGroundColorType(layout->_colorType); setBackGroundColor(layout->_cColor); diff --git a/cocos/ui/UILayout.h b/cocos/ui/UILayout.h index 3155332793..8d56d44610 100644 --- a/cocos/ui/UILayout.h +++ b/cocos/ui/UILayout.h @@ -86,7 +86,7 @@ public: * * @param texType @see TextureResType. UI_TEX_TYPE_LOCAL means local file, UI_TEX_TYPE_PLIST means sprite frame. */ - void setBackGroundImage(const char* fileName,TextureResType texType = UI_TEX_TYPE_LOCAL); + void setBackGroundImage(const std::string& fileName,TextureResType texType = UI_TEX_TYPE_LOCAL); /** * Sets a background image capinsets for layout, if the background image is a scale9 render. diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp index aa3b617afc..89d7347866 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp @@ -20,12 +20,11 @@ bool UILayoutTest::init() Size widgetSize = _widget->getSize(); // Add the alert - Text* alert = Text::create(); - alert->setText("Layout"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(30); + Text* alert = Text::create("Layout", "fonts/Marker Felt.ttf", 30 ); alert->setColor(Color3B(159, 168, 176)); - alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075f)); + alert->setPosition(Point(widgetSize.width / 2.0f, + widgetSize.height / 2.0f - alert->getSize().height * 3.075f)); + _uiLayer->addChild(alert); Layout* root = static_cast(_uiLayer->getChildByTag(81)) ; @@ -42,25 +41,22 @@ bool UILayoutTest::init() (backgroundSize.height - layout->getSize().height) / 2.0f)); _uiLayer->addChild(layout); - Button* button = Button::create(); - button->setTouchEnabled(true); - button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); - button->setPosition(Point(button->getSize().width / 2.0f, layout->getSize().height - button->getSize().height / 2.0f)); + Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); + button->setPosition(Point(button->getSize().width / 2.0f, + layout->getSize().height - button->getSize().height / 2.0f)); layout->addChild(button); - Button* titleButton = Button::create(); - titleButton->setTouchEnabled(true); - titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", ""); + Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png"); titleButton->setTitleText("Title Button"); titleButton->setPosition(Point(layout->getSize().width / 2.0f, layout->getSize().height / 2.0f)); layout->addChild(titleButton); - Button* button_scale9 = Button::create(); - button_scale9->setTouchEnabled(true); - button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); + Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height)); - button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f, button_scale9->getSize().height / 2.0f)); + button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f, + button_scale9->getSize().height / 2.0f)); + layout->addChild(button_scale9); return true; @@ -86,12 +82,11 @@ bool UILayoutTest_Color::init() Size widgetSize = _widget->getSize(); // Add the alert - Text* alert = Text::create(); - alert->setText("Layout color render"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(30); + Text* alert = Text::create("Layout color render", "fonts/Marker Felt.ttf", 30); alert->setColor(Color3B(159, 168, 176)); - alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075f)); + alert->setPosition(Point(widgetSize.width / 2.0f, + widgetSize.height / 2.0f - alert->getSize().height * 3.075f)); + _uiLayer->addChild(alert); Layout* root = static_cast(_uiLayer->getChildByTag(81)); @@ -110,25 +105,23 @@ bool UILayoutTest_Color::init() (backgroundSize.height - layout->getSize().height) / 2.0f)); _uiLayer->addChild(layout); - Button* button = Button::create(); - button->setTouchEnabled(true); - button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); - button->setPosition(Point(button->getSize().width / 2.0f, layout->getSize().height - button->getSize().height / 2.0f)); + Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); + button->setPosition(Point(button->getSize().width / 2.0f, + layout->getSize().height - button->getSize().height / 2.0f)); + layout->addChild(button); - Button* titleButton = Button::create(); - titleButton->setTouchEnabled(true); - titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", ""); + Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png"); titleButton->setTitleText("Title Button"); titleButton->setPosition(Point(layout->getSize().width / 2.0f, layout->getSize().height / 2.0f)); layout->addChild(titleButton); - Button* button_scale9 = Button::create(); - button_scale9->setTouchEnabled(true); - button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); + Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height)); - button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f, button_scale9->getSize().height / 2.0f)); + button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f, + button_scale9->getSize().height / 2.0f)); + layout->addChild(button_scale9); return true; @@ -153,12 +146,11 @@ bool UILayoutTest_Gradient::init() Size widgetSize = _widget->getSize(); // Add the alert - Text* alert = Text::create(); - alert->setText("Layout gradient render"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(30); + Text* alert = Text::create("Layout gradient render", "fonts/Marker Felt.ttf", 30); alert->setColor(Color3B(159, 168, 176)); - alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075f)); + alert->setPosition(Point(widgetSize.width / 2.0f, + widgetSize.height / 2.0f - alert->getSize().height * 3.075f)); + _uiLayer->addChild(alert); Layout* root = static_cast(_uiLayer->getChildByTag(81)); @@ -177,25 +169,23 @@ bool UILayoutTest_Gradient::init() (backgroundSize.height - layout->getSize().height) / 2.0f)); _uiLayer->addChild(layout); - Button* button = Button::create(); - button->setTouchEnabled(true); - button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); - button->setPosition(Point(button->getSize().width / 2.0f, layout->getSize().height - button->getSize().height / 2.0f)); + Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); + button->setPosition(Point(button->getSize().width / 2.0f, + layout->getSize().height - button->getSize().height / 2.0f)); + layout->addChild(button); - Button* titleButton = Button::create(); - titleButton->setTouchEnabled(true); - titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", ""); + Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png"); titleButton->setTitleText("Title Button"); titleButton->setPosition(Point(layout->getSize().width / 2.0f, layout->getSize().height / 2.0f)); layout->addChild(titleButton); - Button* button_scale9 = Button::create(); - button_scale9->setTouchEnabled(true); - button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); + Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height)); - button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f, button_scale9->getSize().height / 2.0f)); + button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f, + button_scale9->getSize().height / 2.0f)); + layout->addChild(button_scale9); return true; @@ -220,10 +210,7 @@ bool UILayoutTest_BackGroundImage::init() Size widgetSize = _widget->getSize(); // Add the alert - Text* alert = Text::create(); - alert->setText("Layout background image"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(20); + Text* alert = Text::create("Layout background image", "fonts/Marker Felt.ttf", 20); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 4.5f)); _uiLayer->addChild(alert); @@ -244,25 +231,22 @@ bool UILayoutTest_BackGroundImage::init() (backgroundSize.height - layout->getSize().height) / 2.0f)); _uiLayer->addChild(layout); - Button* button = Button::create(); - button->setTouchEnabled(true); - button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); - button->setPosition(Point(button->getSize().width / 2.0f, layout->getSize().height - button->getSize().height / 2.0f)); + Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); + button->setPosition(Point(button->getSize().width / 2.0f, + layout->getSize().height - button->getSize().height / 2.0f)); layout->addChild(button); - Button* titleButton = Button::create(); - titleButton->setTouchEnabled(true); - titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", ""); + Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png"); titleButton->setTitleText("Title Button"); titleButton->setPosition(Point(layout->getSize().width / 2.0f, layout->getSize().height / 2.0f)); layout->addChild(titleButton); - Button* button_scale9 = Button::create(); - button_scale9->setTouchEnabled(true); - button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); + Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height)); - button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f, button_scale9->getSize().height / 2.0f)); + button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f, + button_scale9->getSize().height / 2.0f)); + layout->addChild(button_scale9); return true; @@ -287,10 +271,7 @@ bool UILayoutTest_BackGroundImage_Scale9::init() Size widgetSize = _widget->getSize(); // Add the alert - Text* alert = Text::create(); - alert->setText("Layout background image scale9"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(20); + Text* alert = Text::create("Layout background image scale9", "fonts/Marker Felt.ttf", 20); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 4.5f)); _uiLayer->addChild(alert); @@ -311,26 +292,23 @@ bool UILayoutTest_BackGroundImage_Scale9::init() (backgroundSize.height - layout->getSize().height) / 2.0f)); _uiLayer->addChild(layout); - Button* button = Button::create(); - button->setTouchEnabled(true); - button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); - button->setPosition(Point(button->getSize().width / 2.0f, layout->getSize().height - button->getSize().height / 2.0f)); + Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); + button->setPosition(Point(button->getSize().width / 2.0f, + layout->getSize().height - button->getSize().height / 2.0f)); + layout->addChild(button); - Button* titleButton = Button::create(); - titleButton->setTouchEnabled(true); - titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", ""); + Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png"); titleButton->setTitleText("Title Button"); titleButton->setPosition(Point(layout->getSize().width / 2.0f, layout->getSize().height / 2.0f)); layout->addChild(titleButton); - Button* button_scale9 = Button::create(); - button_scale9->setTouchEnabled(true); - button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); + Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height)); - button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f, button_scale9->getSize().height / 2.0f)); - layout->addChild(button_scale9); + button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f, + button_scale9->getSize().height / 2.0f)); + layout->addChild(button_scale9); return true; } @@ -354,12 +332,11 @@ bool UILayoutTest_Layout_Linear_Vertical::init() Size widgetSize = _widget->getSize(); // Add the alert - Text* alert = Text::create(); - alert->setText("Layout Linear Vertical"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(20); + Text* alert = Text::create("Layout Linear Vertical", "fonts/Marker Felt.ttf", 20); alert->setColor(Color3B(159, 168, 176)); - alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 4.5f)); + alert->setPosition(Point(widgetSize.width / 2.0f, + widgetSize.height / 2.0f - alert->getSize().height * 4.5f)); + _uiLayer->addChild(alert); Layout* root = static_cast(_uiLayer->getChildByTag(81)); @@ -378,9 +355,7 @@ bool UILayoutTest_Layout_Linear_Vertical::init() _uiLayer->addChild(layout); - Button* button = Button::create(); - button->setTouchEnabled(true); - button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); + Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); layout->addChild(button); LinearLayoutParameter* lp1 = LinearLayoutParameter::create(); @@ -389,9 +364,7 @@ bool UILayoutTest_Layout_Linear_Vertical::init() lp1->setMargin(Margin(0.0f, 5.0f, 0.0f, 10.0f)); - Button* titleButton = Button::create(); - titleButton->setTouchEnabled(true); - titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", ""); + Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png"); titleButton->setTitleText("Title Button"); layout->addChild(titleButton); @@ -401,9 +374,7 @@ bool UILayoutTest_Layout_Linear_Vertical::init() lp2->setMargin(Margin(0.0f, 10.0f, 0.0f, 10.0f)); - Button* button_scale9 = Button::create(); - button_scale9->setTouchEnabled(true); - button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); + Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height)); layout->addChild(button_scale9); @@ -414,8 +385,6 @@ bool UILayoutTest_Layout_Linear_Vertical::init() lp3->setMargin(Margin(0.0f, 10.0f, 0.0f, 10.0f)); -// layout->doLayout(); - return true; } @@ -439,10 +408,7 @@ bool UILayoutTest_Layout_Linear_Horizontal::init() Size widgetSize = _widget->getSize(); // Add the alert - Text* alert = Text::create(); - alert->setText("Layout Linear Horizontal"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(20); + Text* alert = Text::create("Layout Linear Horizontal", "fonts/Marker Felt.ttf", 20); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 4.5f)); _uiLayer->addChild(alert); @@ -463,9 +429,7 @@ bool UILayoutTest_Layout_Linear_Horizontal::init() (backgroundSize.height - layout->getSize().height) / 2.0f)); _uiLayer->addChild(layout); - Button* button = Button::create(); - button->setTouchEnabled(true); - button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); + Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); layout->addChild(button); LinearLayoutParameter* lp1 = LinearLayoutParameter::create(); @@ -474,9 +438,7 @@ bool UILayoutTest_Layout_Linear_Horizontal::init() lp1->setMargin(Margin(0.0f, 10.0f, 0.0f, 10.0f)); - Button* titleButton = Button::create(); - titleButton->setTouchEnabled(true); - titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", ""); + Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png"); titleButton->setTitleText("Title Button"); layout->addChild(titleButton); @@ -486,9 +448,7 @@ bool UILayoutTest_Layout_Linear_Horizontal::init() lp2->setMargin(Margin(0.0f, 10.0f, 0.0f, 10.0f)); - Button* button_scale9 = Button::create(); - button_scale9->setTouchEnabled(true); - button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); + Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height)); layout->addChild(button_scale9); @@ -499,8 +459,6 @@ bool UILayoutTest_Layout_Linear_Horizontal::init() lp3->setMargin(Margin(0.0f, 10.0f, 0.0f, 10.0f)); -// layout->doLayout(); - return true; } @@ -524,10 +482,7 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init() Size widgetSize = _widget->getSize(); // Add the alert - Text* alert = Text::create(); - alert->setText("Layout Relative Align Parent"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(20); + Text* alert = Text::create("Layout Relative Align Parent", "fonts/Marker Felt.ttf", 20); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 4.5f)); _uiLayer->addChild(alert); @@ -550,9 +505,8 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init() _uiLayer->addChild(layout); // top left - Button* button_TopLeft = Button::create(); - button_TopLeft->setTouchEnabled(true); - button_TopLeft->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); + Button* button_TopLeft = Button::create("cocosui/animationbuttonnormal.png", + "cocosui/animationbuttonpressed.png"); layout->addChild(button_TopLeft); RelativeLayoutParameter* rp_TopLeft = RelativeLayoutParameter::create(); @@ -561,9 +515,8 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init() // top center horizontal - Button* button_TopCenter = Button::create(); - button_TopCenter->setTouchEnabled(true); - button_TopCenter->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); + Button* button_TopCenter = Button::create("cocosui/animationbuttonnormal.png", + "cocosui/animationbuttonpressed.png"); layout->addChild(button_TopCenter); RelativeLayoutParameter* rp_TopCenter = RelativeLayoutParameter::create(); @@ -572,9 +525,8 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init() // top right - Button* button_TopRight = Button::create(); - button_TopRight->setTouchEnabled(true); - button_TopRight->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); + Button* button_TopRight = Button::create("cocosui/animationbuttonnormal.png", + "cocosui/animationbuttonpressed.png"); layout->addChild(button_TopRight); RelativeLayoutParameter* rp_TopRight = RelativeLayoutParameter::create(); @@ -583,9 +535,8 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init() // left center - Button* button_LeftCenter = Button::create(); - button_LeftCenter->setTouchEnabled(true); - button_LeftCenter->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); + Button* button_LeftCenter = Button::create("cocosui/animationbuttonnormal.png", + "cocosui/animationbuttonpressed.png"); layout->addChild(button_LeftCenter); RelativeLayoutParameter* rp_LeftCenter = RelativeLayoutParameter::create(); @@ -594,9 +545,8 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init() // center - Button* buttonCenter = Button::create(); - buttonCenter->setTouchEnabled(true); - buttonCenter->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); + Button* buttonCenter = Button::create("cocosui/animationbuttonnormal.png", + "cocosui/animationbuttonpressed.png"); layout->addChild(buttonCenter); RelativeLayoutParameter* rpCenter = RelativeLayoutParameter::create(); @@ -605,9 +555,8 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init() // right center - Button* button_RightCenter = Button::create(); - button_RightCenter->setTouchEnabled(true); - button_RightCenter->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); + Button* button_RightCenter = Button::create("cocosui/animationbuttonnormal.png", + "cocosui/animationbuttonpressed.png"); layout->addChild(button_RightCenter); RelativeLayoutParameter* rp_RightCenter = RelativeLayoutParameter::create(); @@ -616,9 +565,8 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init() // left bottom - Button* button_LeftBottom = Button::create(); - button_LeftBottom->setTouchEnabled(true); - button_LeftBottom->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); + Button* button_LeftBottom = Button::create("cocosui/animationbuttonnormal.png", + "cocosui/animationbuttonpressed.png"); layout->addChild(button_LeftBottom); RelativeLayoutParameter* rp_LeftBottom = RelativeLayoutParameter::create(); @@ -627,9 +575,8 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init() // bottom center - Button* button_BottomCenter = Button::create(); - button_BottomCenter->setTouchEnabled(true); - button_BottomCenter->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); + Button* button_BottomCenter = Button::create("cocosui/animationbuttonnormal.png", + "cocosui/animationbuttonpressed.png"); layout->addChild(button_BottomCenter); RelativeLayoutParameter* rp_BottomCenter = RelativeLayoutParameter::create(); @@ -638,9 +585,8 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init() // right bottom - Button* button_RightBottom = Button::create(); - button_RightBottom->setTouchEnabled(true); - button_RightBottom->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); + Button* button_RightBottom = Button::create("cocosui/animationbuttonnormal.png", + "cocosui/animationbuttonpressed.png"); layout->addChild(button_RightBottom); RelativeLayoutParameter* rp_RightBottom = RelativeLayoutParameter::create(); @@ -648,8 +594,6 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init() button_RightBottom->setLayoutParameter(rp_RightBottom); -// layout->doLayout(); - return true; } @@ -673,10 +617,7 @@ bool UILayoutTest_Layout_Relative_Location::init() Size widgetSize = _widget->getSize(); // Add the alert - Text* alert = Text::create(); - alert->setText("Layout Relative Location"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(20); + Text* alert = Text::create("Layout Relative Location", "fonts/Marker Felt.ttf", 20); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 4.5f)); _uiLayer->addChild(alert); @@ -697,8 +638,7 @@ bool UILayoutTest_Layout_Relative_Location::init() _uiLayer->addChild(layout); // center - ImageView* imageView_Center = ImageView::create(); - imageView_Center->loadTexture("cocosui/scrollviewbg.png"); + ImageView* imageView_Center = ImageView::create("cocosui/scrollviewbg.png"); layout->addChild(imageView_Center); RelativeLayoutParameter* rp_Center = RelativeLayoutParameter::create(); @@ -708,8 +648,7 @@ bool UILayoutTest_Layout_Relative_Location::init() // above center - ImageView* imageView_AboveCenter = ImageView::create(); - imageView_AboveCenter->loadTexture("cocosui/switch-mask.png"); + ImageView* imageView_AboveCenter = ImageView::create("cocosui/switch-mask.png"); layout->addChild(imageView_AboveCenter); RelativeLayoutParameter* rp_AboveCenter = RelativeLayoutParameter::create(); @@ -719,8 +658,7 @@ bool UILayoutTest_Layout_Relative_Location::init() // below center - ImageView* imageView_BelowCenter = ImageView::create(); - imageView_BelowCenter->loadTexture("cocosui/switch-mask.png"); + ImageView* imageView_BelowCenter = ImageView::create("cocosui/switch-mask.png"); layout->addChild(imageView_BelowCenter); RelativeLayoutParameter* rp_BelowCenter = RelativeLayoutParameter::create(); @@ -730,8 +668,7 @@ bool UILayoutTest_Layout_Relative_Location::init() // left center - ImageView* imageView_LeftCenter = ImageView::create(); - imageView_LeftCenter->loadTexture("cocosui/switch-mask.png"); + ImageView* imageView_LeftCenter = ImageView::create("cocosui/switch-mask.png"); layout->addChild(imageView_LeftCenter); RelativeLayoutParameter* rp_LeftCenter = RelativeLayoutParameter::create(); @@ -742,8 +679,7 @@ bool UILayoutTest_Layout_Relative_Location::init() // right center - ImageView* imageView_RightCenter = ImageView::create(); - imageView_RightCenter->loadTexture("cocosui/switch-mask.png"); + ImageView* imageView_RightCenter = ImageView::create("cocosui/switch-mask.png"); layout->addChild(imageView_RightCenter); RelativeLayoutParameter* rp_RightCenter = RelativeLayoutParameter::create(); @@ -752,93 +688,9 @@ bool UILayoutTest_Layout_Relative_Location::init() imageView_RightCenter->setLayoutParameter(rp_RightCenter); -// layout->doLayout(); - return true; } return false; } -// UILayoutTest_Layout_Grid -/* -UILayoutTest_Layout_Grid::UILayoutTest_Layout_Grid() -{ -} - -UILayoutTest_Layout_Grid::~UILayoutTest_Layout_Grid() -{ -} - -bool UILayoutTest_Layout_Grid::init() -{ - if (UIScene::init()) - { - Size widgetSize = _widget->getSize(); - - // Add the alert - Text* alert = Text::create(); - alert->setText("Layout Grid"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(20); - alert->setColor(Color3B(159, 168, 176)); - alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 4.5f)); - _uiLayer->addChild(alert); - - Layout* root = static_cast(_uiLayer->getChildByTag(81)); - - Layout* background = dynamic_cast(root->getChildByName("background_Panel")); - - // Create the layout - Layout* layout = Layout::create(); - layout->setLayoutType(LAYOUT_GRID_MODE_COLUMN); - layout->setSize(Size(280, 150)); - Size backgroundSize = background->getSize(); - layout->setPosition(Point((widgetSize.width - backgroundSize.width) / 2.0f + - (backgroundSize.width - layout->getSize().width) / 2.0f, - (widgetSize.height - backgroundSize.height) / 2.0f + - (backgroundSize.height - layout->getSize().height) / 2.0f)); - _uiLayer->addChild(layout); - - - // create items - for (int i = 0; i < 14; ++i) - { - Button* button = Button::create(); - button->setName("TextButton"); - button->setTouchEnabled(true); - button->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); - button->setScale9Enabled(true); - AffineTransform transform = AffineTransformMakeIdentity(); - transform = AffineTransformScale(transform, 3.0f, 1.3f); - button->setSize(SizeApplyAffineTransform(button->getContentSize(), transform)); - button->setTitleText(CCString::createWithFormat("grid_%d", i)->getCString()); - - Layout* item = Layout::create(); - item->setTouchEnabled(true); - item->setSize(button->getSize()); - button->setPosition(Point(item->getSize().width / 2.0f, item->getSize().height / 2.0f)); - item->addChild(button); - - GridLayoutParameter* gp = GridLayoutParameter::create(); - item->setLayoutParameter(gp); - gp->setMargin(Margin(0.0f, 0.0f, 0.0f, 0.0f)); - - layout->addChild(item); - } - - // set grid view row and column - Widget* item = static_cast(layout->getChildren().at(0)); - int rowCount = layout->getSize().height / item->getSize().height; - int columnCount = layout->getSize().width / item->getSize().width; - layout->setGridLayoutRowAndColumnCount(rowCount, columnCount); - -// layout->doLayout(); - - return true; - } - - return false; -} - */ -