axmol/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp

935 lines
39 KiB
C++
Raw Normal View History

2013-12-23 15:35:35 +08:00
#include "UILayoutTest.h"
2015-04-09 12:23:47 +08:00
USING_NS_CC;
using namespace cocos2d::ui;
UILayoutTests::UILayoutTests()
{
ADD_TEST_CASE(UILayoutTest);
ADD_TEST_CASE(UILayoutTest_Color);
ADD_TEST_CASE(UILayoutTest_Gradient);
ADD_TEST_CASE(UILayoutTest_BackGroundImage);
ADD_TEST_CASE(UILayoutTest_BackGroundImage_Scale9);
ADD_TEST_CASE(UILayoutTest_Layout_Linear_Vertical);
ADD_TEST_CASE(UILayoutTest_Layout_Linear_Horizontal);
ADD_TEST_CASE(UILayoutTest_Layout_Relative_Align_Parent);
ADD_TEST_CASE(UILayoutTest_Layout_Relative_Location);
ADD_TEST_CASE(UILayoutTest_Layout_Scaled_Widget);
ADD_TEST_CASE(UILayoutComponentTest);
ADD_TEST_CASE(UILayoutComponent_Berth_Test);
ADD_TEST_CASE(UILayoutComponent_Berth_Stretch_Test);
}
2013-12-23 15:35:35 +08:00
// UILayoutTest
UILayoutTest::UILayoutTest()
{
}
UILayoutTest::~UILayoutTest()
{
}
bool UILayoutTest::init()
{
if (UIScene::init())
{
2014-06-20 11:18:53 +08:00
Size widgetSize = _widget->getContentSize();
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
// Add the alert
2014-12-22 15:15:40 +08:00
Text* alert = Text::create("Layout", "fonts/Marker Felt.ttf", 30 );
2013-12-23 15:35:35 +08:00
alert->setColor(Color3B(159, 168, 176));
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
alert->setPosition(Vec2(widgetSize.width / 2.0f,
2014-12-22 15:15:40 +08:00
widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
2013-12-23 15:35:35 +08:00
_uiLayer->addChild(alert);
2014-12-22 15:15:40 +08:00
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81)) ;
2013-12-23 15:35:35 +08:00
Layout* background = static_cast<Layout*>(root->getChildByName("background_Panel"));
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
// Create the layout
Layout* layout = Layout::create();
layout->setContentSize(Size(280, 150));
2014-06-20 11:18:53 +08:00
Size backgroundSize = background->getContentSize();
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
layout->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
2014-12-22 15:15:40 +08:00
(backgroundSize.width - layout->getContentSize().width) / 2.0f,
(widgetSize.height - backgroundSize.height) / 2.0f +
(backgroundSize.height - layout->getContentSize().height) / 2.0f));
2013-12-23 15:35:35 +08:00
_uiLayer->addChild(layout);
2014-12-22 15:15:40 +08:00
2014-04-03 11:14:35 +08:00
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
2014-06-20 11:18:53 +08:00
button->setPosition(Vec2(button->getContentSize().width / 2.0f,
2014-12-22 15:15:40 +08:00
layout->getContentSize().height - button->getContentSize().height / 2.0f));
2013-12-23 15:35:35 +08:00
layout->addChild(button);
2014-12-22 15:15:40 +08:00
2014-04-03 11:14:35 +08:00
Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png");
2013-12-23 15:35:35 +08:00
titleButton->setTitleText("Title Button");
2014-06-20 11:18:53 +08:00
titleButton->setPosition(Vec2(layout->getContentSize().width / 2.0f, layout->getContentSize().height / 2.0f));
2013-12-23 15:35:35 +08:00
layout->addChild(titleButton);
2014-12-22 15:15:40 +08:00
2014-04-03 11:14:35 +08:00
Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
2013-12-23 15:35:35 +08:00
button_scale9->setScale9Enabled(true);
button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height));
2014-06-20 11:18:53 +08:00
button_scale9->setPosition(Vec2(layout->getContentSize().width - button_scale9->getContentSize().width / 2.0f,
2014-12-22 15:15:40 +08:00
button_scale9->getContentSize().height / 2.0f));
2013-12-23 15:35:35 +08:00
layout->addChild(button_scale9);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
return true;
}
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
return false;
}
// UILayoutTest_Color
UILayoutTest_Color::UILayoutTest_Color()
{
}
UILayoutTest_Color::~UILayoutTest_Color()
{
}
bool UILayoutTest_Color::init()
{
if (UIScene::init())
{
2014-06-20 11:18:53 +08:00
Size widgetSize = _widget->getContentSize();
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
// Add the alert
2014-04-03 11:14:35 +08:00
Text* alert = Text::create("Layout color render", "fonts/Marker Felt.ttf", 30);
2013-12-23 15:35:35 +08:00
alert->setColor(Color3B(159, 168, 176));
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
alert->setPosition(Vec2(widgetSize.width / 2.0f,
2014-12-22 15:15:40 +08:00
widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
2013-12-23 15:35:35 +08:00
_uiLayer->addChild(alert);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
Layout* background = static_cast<Layout*>(root->getChildByName("background_Panel"));
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
// Create the layout with color render
Layout* layout = Layout::create();
layout->setBackGroundColorType(Layout::BackGroundColorType::SOLID);
2013-12-23 15:35:35 +08:00
layout->setBackGroundColor(Color3B(128, 128, 128));
layout->setContentSize(Size(280, 150));
2013-12-23 15:35:35 +08:00
Size backgroundSize = background->getContentSize();
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
layout->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
2014-12-22 15:15:40 +08:00
(backgroundSize.width - layout->getContentSize().width) / 2.0f,
(widgetSize.height - backgroundSize.height) / 2.0f +
(backgroundSize.height - layout->getContentSize().height) / 2.0f));
2013-12-23 15:35:35 +08:00
_uiLayer->addChild(layout);
2014-12-22 15:15:40 +08:00
2014-04-03 11:14:35 +08:00
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
2014-06-20 11:18:53 +08:00
button->setPosition(Vec2(button->getContentSize().width / 2.0f,
2014-12-22 15:15:40 +08:00
layout->getContentSize().height - button->getContentSize().height / 2.0f));
2013-12-23 15:35:35 +08:00
layout->addChild(button);
2014-12-22 15:15:40 +08:00
2014-04-03 11:14:35 +08:00
Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png");
2013-12-23 15:35:35 +08:00
titleButton->setTitleText("Title Button");
2014-06-20 11:18:53 +08:00
titleButton->setPosition(Vec2(layout->getContentSize().width / 2.0f, layout->getContentSize().height / 2.0f));
2013-12-23 15:35:35 +08:00
layout->addChild(titleButton);
2014-12-22 15:15:40 +08:00
2014-04-03 11:14:35 +08:00
Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
2013-12-23 15:35:35 +08:00
button_scale9->setScale9Enabled(true);
button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height));
2014-06-20 11:18:53 +08:00
button_scale9->setPosition(Vec2(layout->getContentSize().width - button_scale9->getContentSize().width / 2.0f,
2014-12-22 15:15:40 +08:00
button_scale9->getContentSize().height / 2.0f));
layout->addChild(button_scale9);
2013-12-23 15:35:35 +08:00
return true;
}
return false;
}
// UILayoutTest_Gradient
UILayoutTest_Gradient::UILayoutTest_Gradient()
2014-12-22 15:15:40 +08:00
{
2013-12-23 15:35:35 +08:00
}
UILayoutTest_Gradient::~UILayoutTest_Gradient()
{
}
bool UILayoutTest_Gradient::init()
{
if (UIScene::init())
{
2014-06-20 11:18:53 +08:00
Size widgetSize = _widget->getContentSize();
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
// Add the alert
2014-04-03 11:14:35 +08:00
Text* alert = Text::create("Layout gradient render", "fonts/Marker Felt.ttf", 30);
2013-12-23 15:35:35 +08:00
alert->setColor(Color3B(159, 168, 176));
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
alert->setPosition(Vec2(widgetSize.width / 2.0f,
2014-12-22 15:15:40 +08:00
widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
2013-12-23 15:35:35 +08:00
_uiLayer->addChild(alert);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
Layout* background = static_cast<Layout*>(root->getChildByName("background_Panel"));
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
// Create the layout with gradient render
Layout* layout = Layout::create();
layout->setBackGroundColorType(Layout::BackGroundColorType::GRADIENT);
2013-12-23 15:35:35 +08:00
layout->setBackGroundColor(Color3B(64, 64, 64), Color3B(192, 192, 192));
layout->setContentSize(Size(280, 150));
2013-12-23 15:35:35 +08:00
Size backgroundSize = background->getContentSize();
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
layout->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
2014-12-22 15:15:40 +08:00
(backgroundSize.width - layout->getContentSize().width) / 2.0f,
(widgetSize.height - backgroundSize.height) / 2.0f +
(backgroundSize.height - layout->getContentSize().height) / 2.0f));
2013-12-23 15:35:35 +08:00
_uiLayer->addChild(layout);
2014-12-22 15:15:40 +08:00
2014-04-03 11:14:35 +08:00
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
2014-06-20 11:18:53 +08:00
button->setPosition(Vec2(button->getContentSize().width / 2.0f,
2014-12-22 15:15:40 +08:00
layout->getContentSize().height - button->getContentSize().height / 2.0f));
2013-12-23 15:35:35 +08:00
layout->addChild(button);
2014-12-22 15:15:40 +08:00
2014-04-03 11:14:35 +08:00
Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png");
2013-12-23 15:35:35 +08:00
titleButton->setTitleText("Title Button");
2014-06-20 11:18:53 +08:00
titleButton->setPosition(Vec2(layout->getContentSize().width / 2.0f, layout->getContentSize().height / 2.0f));
2013-12-23 15:35:35 +08:00
layout->addChild(titleButton);
2014-12-22 15:15:40 +08:00
2014-04-03 11:14:35 +08:00
Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
2013-12-23 15:35:35 +08:00
button_scale9->setScale9Enabled(true);
button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height));
2014-06-20 11:18:53 +08:00
button_scale9->setPosition(Vec2(layout->getContentSize().width - button_scale9->getContentSize().width / 2.0f,
2014-12-22 15:15:40 +08:00
button_scale9->getContentSize().height / 2.0f));
layout->addChild(button_scale9);
2013-12-23 15:35:35 +08:00
return true;
}
return false;
}
// UILayoutTest_BackGroundImage
UILayoutTest_BackGroundImage::UILayoutTest_BackGroundImage()
{
}
UILayoutTest_BackGroundImage::~UILayoutTest_BackGroundImage()
{
}
bool UILayoutTest_BackGroundImage::init()
{
if (UIScene::init())
{
2014-06-20 11:18:53 +08:00
Size widgetSize = _widget->getContentSize();
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
// Add the alert
2014-04-03 11:14:35 +08:00
Text* alert = Text::create("Layout background image", "fonts/Marker Felt.ttf", 20);
2013-12-23 15:35:35 +08:00
alert->setColor(Color3B(159, 168, 176));
2014-06-20 11:18:53 +08:00
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 4.5f));
2013-12-23 15:35:35 +08:00
_uiLayer->addChild(alert);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
Layout* background = dynamic_cast<Layout*>(root->getChildByName("background_Panel"));
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
// Create the layout with background image
Layout* layout = Layout::create();
layout->setClippingEnabled(true);
2014-03-11 17:13:54 +08:00
layout->setBackGroundImage("cocosui/Hello.png");
layout->setContentSize(Size(280, 150));
2013-12-23 15:35:35 +08:00
Size backgroundSize = background->getContentSize();
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
layout->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
2014-12-22 15:15:40 +08:00
(backgroundSize.width - layout->getContentSize().width) / 2.0f,
(widgetSize.height - backgroundSize.height) / 2.0f +
(backgroundSize.height - layout->getContentSize().height) / 2.0f));
2013-12-23 15:35:35 +08:00
_uiLayer->addChild(layout);
2014-12-22 15:15:40 +08:00
2014-04-03 11:14:35 +08:00
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
2014-06-20 11:18:53 +08:00
button->setPosition(Vec2(button->getContentSize().width / 2.0f,
2014-12-22 15:15:40 +08:00
layout->getContentSize().height - button->getContentSize().height / 2.0f));
2013-12-23 15:35:35 +08:00
layout->addChild(button);
2014-12-22 15:15:40 +08:00
2014-04-03 11:14:35 +08:00
Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png");
2013-12-23 15:35:35 +08:00
titleButton->setTitleText("Title Button");
2014-06-20 11:18:53 +08:00
titleButton->setPosition(Vec2(layout->getContentSize().width / 2.0f, layout->getContentSize().height / 2.0f));
2013-12-23 15:35:35 +08:00
layout->addChild(titleButton);
2014-12-22 15:15:40 +08:00
2014-04-03 11:14:35 +08:00
Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
2013-12-23 15:35:35 +08:00
button_scale9->setScale9Enabled(true);
button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height));
2014-06-20 11:18:53 +08:00
button_scale9->setPosition(Vec2(layout->getContentSize().width - button_scale9->getContentSize().width / 2.0f,
2014-12-22 15:15:40 +08:00
button_scale9->getContentSize().height / 2.0f));
layout->addChild(button_scale9);
2015-11-30 16:17:13 +08:00
_layout = layout;
TTFConfig ttfConfig("fonts/arial.ttf", 15);
auto label1 = Label::createWithTTF(ttfConfig, "Print Resources");
2015-12-01 11:07:02 +08:00
auto item1 = MenuItemLabel::create(label1, CC_CALLBACK_1(UILayoutTest_BackGroundImage::printWidgetResources, this));
2015-11-30 16:17:13 +08:00
item1->setPosition(Vec2(VisibleRect::left().x + 60, VisibleRect::bottom().y + item1->getContentSize().height * 3));
auto pMenu1 = Menu::create(item1, nullptr);
pMenu1->setPosition(Vec2(0, 0));
this->addChild(pMenu1, 10);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
return true;
}
return false;
}
2015-12-01 11:07:02 +08:00
void UILayoutTest_BackGroundImage::printWidgetResources(cocos2d::Ref* sender)
2015-11-30 16:17:13 +08:00
{
cocos2d::ResourceData textureFile = _layout->getRenderFile();
2015-11-30 16:17:13 +08:00
CCLOG("textureFile Name : %s, Type: %d", textureFile.file.c_str(), textureFile.type);
}
2013-12-23 15:35:35 +08:00
// UILayoutTest_BackGroundImage_Scale9
UILayoutTest_BackGroundImage_Scale9::UILayoutTest_BackGroundImage_Scale9()
{
}
UILayoutTest_BackGroundImage_Scale9::~UILayoutTest_BackGroundImage_Scale9()
{
}
bool UILayoutTest_BackGroundImage_Scale9::init()
{
if (UIScene::init())
{
2014-06-20 11:18:53 +08:00
Size widgetSize = _widget->getContentSize();
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
// Add the alert
2014-04-03 11:14:35 +08:00
Text* alert = Text::create("Layout background image scale9", "fonts/Marker Felt.ttf", 20);
2013-12-23 15:35:35 +08:00
alert->setColor(Color3B(159, 168, 176));
2014-06-20 11:18:53 +08:00
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 4.5f));
2013-12-23 15:35:35 +08:00
_uiLayer->addChild(alert);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
Layout* background = dynamic_cast<Layout*>(root->getChildByName("background_Panel"));
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
// Create the layout with background image
Layout* layout = Layout::create();
layout->setBackGroundImageScale9Enabled(true);
2014-03-11 17:13:54 +08:00
layout->setBackGroundImage("cocosui/green_edit.png");
layout->setContentSize(Size(280, 150));
2013-12-23 15:35:35 +08:00
Size backgroundSize = background->getContentSize();
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
layout->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
2014-12-22 15:15:40 +08:00
(backgroundSize.width - layout->getContentSize().width) / 2.0f,
(widgetSize.height - backgroundSize.height) / 2.0f +
(backgroundSize.height - layout->getContentSize().height) / 2.0f));
2013-12-23 15:35:35 +08:00
_uiLayer->addChild(layout);
2014-12-22 15:15:40 +08:00
2014-04-03 11:14:35 +08:00
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
2014-06-20 11:18:53 +08:00
button->setPosition(Vec2(button->getContentSize().width / 2.0f,
2014-12-22 15:15:40 +08:00
layout->getContentSize().height - button->getContentSize().height / 2.0f));
2013-12-23 15:35:35 +08:00
layout->addChild(button);
2014-12-22 15:15:40 +08:00
2014-04-03 11:14:35 +08:00
Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png");
2013-12-23 15:35:35 +08:00
titleButton->setTitleText("Title Button");
2014-06-20 11:18:53 +08:00
titleButton->setPosition(Vec2(layout->getContentSize().width / 2.0f, layout->getContentSize().height / 2.0f));
2013-12-23 15:35:35 +08:00
layout->addChild(titleButton);
2014-12-22 15:15:40 +08:00
2014-04-03 11:14:35 +08:00
Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
2013-12-23 15:35:35 +08:00
button_scale9->setScale9Enabled(true);
button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height));
2014-06-20 11:18:53 +08:00
button_scale9->setPosition(Vec2(layout->getContentSize().width - button_scale9->getContentSize().width / 2.0f,
2014-12-22 15:15:40 +08:00
button_scale9->getContentSize().height / 2.0f));
2014-04-03 11:14:35 +08:00
layout->addChild(button_scale9);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
return true;
}
return false;
}
// UILayoutTest_Layout_Linear_Vertical
UILayoutTest_Layout_Linear_Vertical::UILayoutTest_Layout_Linear_Vertical()
{
}
UILayoutTest_Layout_Linear_Vertical::~UILayoutTest_Layout_Linear_Vertical()
{
}
bool UILayoutTest_Layout_Linear_Vertical::init()
{
if (UIScene::init())
{
2014-06-20 11:18:53 +08:00
Size widgetSize = _widget->getContentSize();
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
// Add the alert
2014-04-03 11:14:35 +08:00
Text* alert = Text::create("Layout Linear Vertical", "fonts/Marker Felt.ttf", 20);
2013-12-23 15:35:35 +08:00
alert->setColor(Color3B(159, 168, 176));
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
alert->setPosition(Vec2(widgetSize.width / 2.0f,
2014-12-22 15:15:40 +08:00
widgetSize.height / 2.0f - alert->getContentSize().height * 4.5f));
2013-12-23 15:35:35 +08:00
_uiLayer->addChild(alert);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
Layout* background = static_cast<Layout*>(root->getChildByName("background_Panel"));
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
// Create the layout
Layout* layout = Layout::create();
2015-07-15 12:04:48 +08:00
layout->setLayoutType(Layout::Type::VERTICAL);
layout->setContentSize(Size(280, 150));
2014-06-20 11:18:53 +08:00
Size backgroundSize = background->getContentSize();
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
layout->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
2014-12-22 15:15:40 +08:00
(backgroundSize.width - layout->getContentSize().width) / 2.0f,
(widgetSize.height - backgroundSize.height) / 2.0f +
(backgroundSize.height - layout->getContentSize().height) / 2.0f));
2013-12-23 15:35:35 +08:00
_uiLayer->addChild(layout);
2014-12-22 15:15:40 +08:00
2014-04-03 11:14:35 +08:00
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
2013-12-23 15:35:35 +08:00
layout->addChild(button);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
LinearLayoutParameter* lp1 = LinearLayoutParameter::create();
button->setLayoutParameter(lp1);
2014-05-09 17:54:25 +08:00
lp1->setGravity(LinearLayoutParameter::LinearGravity::CENTER_HORIZONTAL);
2013-12-23 15:35:35 +08:00
lp1->setMargin(Margin(0.0f, 5.0f, 0.0f, 10.0f));
2014-12-22 15:15:40 +08:00
2014-04-03 11:14:35 +08:00
Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png");
2013-12-23 15:35:35 +08:00
titleButton->setTitleText("Title Button");
layout->addChild(titleButton);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
LinearLayoutParameter* lp2 = LinearLayoutParameter::create();
titleButton->setLayoutParameter(lp2);
2014-05-09 17:54:25 +08:00
lp2->setGravity(LinearLayoutParameter::LinearGravity::CENTER_HORIZONTAL);
2013-12-23 15:35:35 +08:00
lp2->setMargin(Margin(0.0f, 10.0f, 0.0f, 10.0f));
2014-12-22 15:15:40 +08:00
2014-04-03 11:14:35 +08:00
Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
2013-12-23 15:35:35 +08:00
button_scale9->setScale9Enabled(true);
button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height));
2013-12-23 15:35:35 +08:00
layout->addChild(button_scale9);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
LinearLayoutParameter* lp3 = LinearLayoutParameter::create();
button_scale9->setLayoutParameter(lp3);
2014-05-09 17:54:25 +08:00
lp3->setGravity(LinearLayoutParameter::LinearGravity::CENTER_HORIZONTAL);
2013-12-23 15:35:35 +08:00
lp3->setMargin(Margin(0.0f, 10.0f, 0.0f, 10.0f));
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
return true;
}
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
return false;
}
// UILayoutTest_Layout_Linear_Horizontal
UILayoutTest_Layout_Linear_Horizontal::UILayoutTest_Layout_Linear_Horizontal()
{
}
UILayoutTest_Layout_Linear_Horizontal::~UILayoutTest_Layout_Linear_Horizontal()
{
}
bool UILayoutTest_Layout_Linear_Horizontal::init()
{
if (UIScene::init())
{
2014-06-20 11:18:53 +08:00
Size widgetSize = _widget->getContentSize();
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
// Add the alert
2014-04-03 11:14:35 +08:00
Text* alert = Text::create("Layout Linear Horizontal", "fonts/Marker Felt.ttf", 20);
2013-12-23 15:35:35 +08:00
alert->setColor(Color3B(159, 168, 176));
2014-06-20 11:18:53 +08:00
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 4.5f));
2013-12-23 15:35:35 +08:00
_uiLayer->addChild(alert);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
Layout* background = dynamic_cast<Layout*>(root->getChildByName("background_Panel"));
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
// Create the layout
Layout* layout = Layout::create();
2015-07-15 12:04:48 +08:00
layout->setLayoutType(Layout::Type::HORIZONTAL);
2013-12-23 15:35:35 +08:00
layout->setClippingEnabled(true);
layout->setContentSize(Size(280, 150));
2014-06-20 11:18:53 +08:00
Size backgroundSize = background->getContentSize();
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
layout->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
2014-12-22 15:15:40 +08:00
(backgroundSize.width - layout->getContentSize().width) / 2.0f,
(widgetSize.height - backgroundSize.height) / 2.0f +
(backgroundSize.height - layout->getContentSize().height) / 2.0f));
2013-12-23 15:35:35 +08:00
_uiLayer->addChild(layout);
2014-12-22 15:15:40 +08:00
2014-04-03 11:14:35 +08:00
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
2013-12-23 15:35:35 +08:00
layout->addChild(button);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
LinearLayoutParameter* lp1 = LinearLayoutParameter::create();
button->setLayoutParameter(lp1);
2014-05-09 17:54:25 +08:00
lp1->setGravity(LinearLayoutParameter::LinearGravity::CENTER_VERTICAL);
2013-12-23 15:35:35 +08:00
lp1->setMargin(Margin(0.0f, 10.0f, 0.0f, 10.0f));
2014-12-22 15:15:40 +08:00
2014-04-03 11:14:35 +08:00
Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png");
2013-12-23 15:35:35 +08:00
titleButton->setTitleText("Title Button");
layout->addChild(titleButton);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
LinearLayoutParameter* lp2 = LinearLayoutParameter::create();
titleButton->setLayoutParameter(lp2);
2014-05-09 17:54:25 +08:00
lp2->setGravity(LinearLayoutParameter::LinearGravity::CENTER_VERTICAL);
2013-12-23 15:35:35 +08:00
lp2->setMargin(Margin(0.0f, 10.0f, 0.0f, 10.0f));
2014-12-22 15:15:40 +08:00
2014-04-03 11:14:35 +08:00
Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
2013-12-23 15:35:35 +08:00
button_scale9->setScale9Enabled(true);
button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height));
2013-12-23 15:35:35 +08:00
layout->addChild(button_scale9);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
LinearLayoutParameter* lp3 = LinearLayoutParameter::create();
button_scale9->setLayoutParameter(lp3);
2014-05-09 17:54:25 +08:00
lp3->setGravity(LinearLayoutParameter::LinearGravity::CENTER_VERTICAL);
2013-12-23 15:35:35 +08:00
lp3->setMargin(Margin(0.0f, 10.0f, 0.0f, 10.0f));
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
return true;
}
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
return false;
}
// UILayoutTest_Layout_Relative_Align_Parent
UILayoutTest_Layout_Relative_Align_Parent::UILayoutTest_Layout_Relative_Align_Parent()
{
}
UILayoutTest_Layout_Relative_Align_Parent::~UILayoutTest_Layout_Relative_Align_Parent()
{
}
bool UILayoutTest_Layout_Relative_Align_Parent::init()
{
if (UIScene::init())
{
2014-06-20 11:18:53 +08:00
Size widgetSize = _widget->getContentSize();
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
// Add the alert
2014-04-03 11:14:35 +08:00
Text* alert = Text::create("Layout Relative Align Parent", "fonts/Marker Felt.ttf", 20);
2013-12-23 15:35:35 +08:00
alert->setColor(Color3B(159, 168, 176));
2014-06-20 11:18:53 +08:00
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 4.5f));
2013-12-23 15:35:35 +08:00
_uiLayer->addChild(alert);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
Layout* background = dynamic_cast<Layout*>(root->getChildByName("background_Panel"));
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
// Create the layout
Layout* layout = Layout::create();
2015-07-15 12:04:48 +08:00
layout->setLayoutType(Layout::Type::RELATIVE);
layout->setContentSize(Size(280, 150));
layout->setBackGroundColorType(Layout::BackGroundColorType::SOLID);
2013-12-23 15:35:35 +08:00
layout->setBackGroundColor(Color3B::GREEN);
2014-06-20 11:18:53 +08:00
Size backgroundSize = background->getContentSize();
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
layout->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
2014-12-22 15:15:40 +08:00
(backgroundSize.width - layout->getContentSize().width) / 2.0f,
(widgetSize.height - backgroundSize.height) / 2.0f +
(backgroundSize.height - layout->getContentSize().height) / 2.0f));
2013-12-23 15:35:35 +08:00
_uiLayer->addChild(layout);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
// top left
2014-04-03 11:14:35 +08:00
Button* button_TopLeft = Button::create("cocosui/animationbuttonnormal.png",
2014-12-22 15:15:40 +08:00
"cocosui/animationbuttonpressed.png");
2013-12-23 15:35:35 +08:00
layout->addChild(button_TopLeft);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
RelativeLayoutParameter* rp_TopLeft = RelativeLayoutParameter::create();
rp_TopLeft->setAlign(RelativeLayoutParameter::RelativeAlign::PARENT_TOP_LEFT);
2013-12-23 15:35:35 +08:00
button_TopLeft->setLayoutParameter(rp_TopLeft);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
// top center horizontal
2014-04-03 11:14:35 +08:00
Button* button_TopCenter = Button::create("cocosui/animationbuttonnormal.png",
2014-12-22 15:15:40 +08:00
"cocosui/animationbuttonpressed.png");
2013-12-23 15:35:35 +08:00
layout->addChild(button_TopCenter);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
RelativeLayoutParameter* rp_TopCenter = RelativeLayoutParameter::create();
rp_TopCenter->setAlign(RelativeLayoutParameter::RelativeAlign::PARENT_TOP_CENTER_HORIZONTAL);
2013-12-23 15:35:35 +08:00
button_TopCenter->setLayoutParameter(rp_TopCenter);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
// top right
2014-04-03 11:14:35 +08:00
Button* button_TopRight = Button::create("cocosui/animationbuttonnormal.png",
2014-12-22 15:15:40 +08:00
"cocosui/animationbuttonpressed.png");
2013-12-23 15:35:35 +08:00
layout->addChild(button_TopRight);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
RelativeLayoutParameter* rp_TopRight = RelativeLayoutParameter::create();
rp_TopRight->setAlign(RelativeLayoutParameter::RelativeAlign::PARENT_TOP_RIGHT);
2013-12-23 15:35:35 +08:00
button_TopRight->setLayoutParameter(rp_TopRight);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
// left center
2014-04-03 11:14:35 +08:00
Button* button_LeftCenter = Button::create("cocosui/animationbuttonnormal.png",
2014-12-22 15:15:40 +08:00
"cocosui/animationbuttonpressed.png");
2013-12-23 15:35:35 +08:00
layout->addChild(button_LeftCenter);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
RelativeLayoutParameter* rp_LeftCenter = RelativeLayoutParameter::create();
rp_LeftCenter->setAlign(RelativeLayoutParameter::RelativeAlign::PARENT_LEFT_CENTER_VERTICAL);
2013-12-23 15:35:35 +08:00
button_LeftCenter->setLayoutParameter(rp_LeftCenter);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
// center
2014-04-03 11:14:35 +08:00
Button* buttonCenter = Button::create("cocosui/animationbuttonnormal.png",
2014-12-22 15:15:40 +08:00
"cocosui/animationbuttonpressed.png");
2013-12-23 15:35:35 +08:00
layout->addChild(buttonCenter);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
RelativeLayoutParameter* rpCenter = RelativeLayoutParameter::create();
rpCenter->setAlign(RelativeLayoutParameter::RelativeAlign::CENTER_IN_PARENT);
2013-12-23 15:35:35 +08:00
buttonCenter->setLayoutParameter(rpCenter);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
// right center
2014-04-03 11:14:35 +08:00
Button* button_RightCenter = Button::create("cocosui/animationbuttonnormal.png",
2014-12-22 15:15:40 +08:00
"cocosui/animationbuttonpressed.png");
2013-12-23 15:35:35 +08:00
layout->addChild(button_RightCenter);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
RelativeLayoutParameter* rp_RightCenter = RelativeLayoutParameter::create();
rp_RightCenter->setAlign(RelativeLayoutParameter::RelativeAlign::PARENT_RIGHT_CENTER_VERTICAL);
2013-12-23 15:35:35 +08:00
button_RightCenter->setLayoutParameter(rp_RightCenter);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
// left bottom
2014-04-03 11:14:35 +08:00
Button* button_LeftBottom = Button::create("cocosui/animationbuttonnormal.png",
2014-12-22 15:15:40 +08:00
"cocosui/animationbuttonpressed.png");
2013-12-23 15:35:35 +08:00
layout->addChild(button_LeftBottom);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
RelativeLayoutParameter* rp_LeftBottom = RelativeLayoutParameter::create();
rp_LeftBottom->setAlign(RelativeLayoutParameter::RelativeAlign::PARENT_LEFT_BOTTOM);
2013-12-23 15:35:35 +08:00
button_LeftBottom->setLayoutParameter(rp_LeftBottom);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
// bottom center
2014-04-03 11:14:35 +08:00
Button* button_BottomCenter = Button::create("cocosui/animationbuttonnormal.png",
2014-12-22 15:15:40 +08:00
"cocosui/animationbuttonpressed.png");
2013-12-23 15:35:35 +08:00
layout->addChild(button_BottomCenter);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
RelativeLayoutParameter* rp_BottomCenter = RelativeLayoutParameter::create();
rp_BottomCenter->setAlign(RelativeLayoutParameter::RelativeAlign::PARENT_BOTTOM_CENTER_HORIZONTAL);
2013-12-23 15:35:35 +08:00
button_BottomCenter->setLayoutParameter(rp_BottomCenter);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
// right bottom
2014-04-03 11:14:35 +08:00
Button* button_RightBottom = Button::create("cocosui/animationbuttonnormal.png",
2014-12-22 15:15:40 +08:00
"cocosui/animationbuttonpressed.png");
2013-12-23 15:35:35 +08:00
layout->addChild(button_RightBottom);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
RelativeLayoutParameter* rp_RightBottom = RelativeLayoutParameter::create();
rp_RightBottom->setAlign(RelativeLayoutParameter::RelativeAlign::PARENT_RIGHT_BOTTOM);
2013-12-23 15:35:35 +08:00
button_RightBottom->setLayoutParameter(rp_RightBottom);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
return true;
}
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
return false;
}
// UILayoutTest_Layout_Relative_Location
UILayoutTest_Layout_Relative_Location::UILayoutTest_Layout_Relative_Location()
{
}
UILayoutTest_Layout_Relative_Location::~UILayoutTest_Layout_Relative_Location()
{
}
bool UILayoutTest_Layout_Relative_Location::init()
{
if (UIScene::init())
{
2014-06-20 11:18:53 +08:00
Size widgetSize = _widget->getContentSize();
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
// Add the alert
2014-04-03 11:14:35 +08:00
Text* alert = Text::create("Layout Relative Location", "fonts/Marker Felt.ttf", 20);
2013-12-23 15:35:35 +08:00
alert->setColor(Color3B(159, 168, 176));
2014-06-20 11:18:53 +08:00
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 4.5f));
2013-12-23 15:35:35 +08:00
_uiLayer->addChild(alert);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
Layout* background = dynamic_cast<Layout*>(root->getChildByName("background_Panel"));
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
// Create the layout
Layout* layout = Layout::create();
2015-07-15 12:04:48 +08:00
layout->setLayoutType(Layout::Type::RELATIVE);
layout->setContentSize(Size(280, 150));
2014-06-20 11:18:53 +08:00
Size backgroundSize = background->getContentSize();
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
layout->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
2014-12-22 15:15:40 +08:00
(backgroundSize.width - layout->getContentSize().width) / 2.0f,
(widgetSize.height - backgroundSize.height) / 2.0f +
(backgroundSize.height - layout->getContentSize().height) / 2.0f));
2013-12-23 15:35:35 +08:00
_uiLayer->addChild(layout);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
// center
2014-04-03 11:14:35 +08:00
ImageView* imageView_Center = ImageView::create("cocosui/scrollviewbg.png");
2013-12-23 15:35:35 +08:00
layout->addChild(imageView_Center);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
RelativeLayoutParameter* rp_Center = RelativeLayoutParameter::create();
rp_Center->setRelativeName("rp_Center");
rp_Center->setAlign(RelativeLayoutParameter::RelativeAlign::CENTER_IN_PARENT);
2013-12-23 15:35:35 +08:00
imageView_Center->setLayoutParameter(rp_Center);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
// above center
2014-04-03 11:14:35 +08:00
ImageView* imageView_AboveCenter = ImageView::create("cocosui/switch-mask.png");
2013-12-23 15:35:35 +08:00
layout->addChild(imageView_AboveCenter);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
RelativeLayoutParameter* rp_AboveCenter = RelativeLayoutParameter::create();
rp_AboveCenter->setRelativeToWidgetName("rp_Center");
rp_AboveCenter->setAlign(RelativeLayoutParameter::RelativeAlign::LOCATION_ABOVE_CENTER);
2013-12-23 15:35:35 +08:00
imageView_AboveCenter->setLayoutParameter(rp_AboveCenter);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
// below center
2014-04-03 11:14:35 +08:00
ImageView* imageView_BelowCenter = ImageView::create("cocosui/switch-mask.png");
2013-12-23 15:35:35 +08:00
layout->addChild(imageView_BelowCenter);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
RelativeLayoutParameter* rp_BelowCenter = RelativeLayoutParameter::create();
rp_BelowCenter->setRelativeToWidgetName("rp_Center");
rp_BelowCenter->setAlign(RelativeLayoutParameter::RelativeAlign::LOCATION_BELOW_CENTER);
2013-12-23 15:35:35 +08:00
imageView_BelowCenter->setLayoutParameter(rp_BelowCenter);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
// left center
2014-04-03 11:14:35 +08:00
ImageView* imageView_LeftCenter = ImageView::create("cocosui/switch-mask.png");
2013-12-23 15:35:35 +08:00
layout->addChild(imageView_LeftCenter);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
RelativeLayoutParameter* rp_LeftCenter = RelativeLayoutParameter::create();
rp_LeftCenter->setRelativeToWidgetName("rp_Center");
rp_LeftCenter->setAlign(RelativeLayoutParameter::RelativeAlign::LOCATION_LEFT_OF_CENTER);
2013-12-23 15:35:35 +08:00
imageView_LeftCenter->setLayoutParameter(rp_LeftCenter);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
// right center
2014-04-03 11:14:35 +08:00
ImageView* imageView_RightCenter = ImageView::create("cocosui/switch-mask.png");
2013-12-23 15:35:35 +08:00
layout->addChild(imageView_RightCenter);
2014-12-22 15:15:40 +08:00
2013-12-23 15:35:35 +08:00
RelativeLayoutParameter* rp_RightCenter = RelativeLayoutParameter::create();
rp_RightCenter->setRelativeToWidgetName("rp_Center");
rp_RightCenter->setAlign(RelativeLayoutParameter::RelativeAlign::LOCATION_RIGHT_OF_CENTER);
2013-12-23 15:35:35 +08:00
imageView_RightCenter->setLayoutParameter(rp_RightCenter);
2014-12-22 15:15:40 +08:00
2014-12-22 14:51:50 +08:00
return true;
}
2014-12-22 15:15:40 +08:00
2014-12-22 14:51:50 +08:00
return false;
}
// UILayoutTest_Layout_Relative_Location
UILayoutTest_Layout_Scaled_Widget::UILayoutTest_Layout_Scaled_Widget()
{
}
UILayoutTest_Layout_Scaled_Widget::~UILayoutTest_Layout_Scaled_Widget()
{
}
bool UILayoutTest_Layout_Scaled_Widget::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getContentSize();
// Add the alert
Text* alert = Text::create("Layout Scaled Widget", "fonts/Marker Felt.ttf", 20);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 4.5f));
_uiLayer->addChild(alert);
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
Layout* background = dynamic_cast<Layout*>(root->getChildByName("background_Panel"));
// Create the layout
Layout* layout = Layout::create();
layout->setLayoutType(Layout::Type::HORIZONTAL);
layout->setContentSize(Size(280, 150));
Size backgroundSize = background->getContentSize();
layout->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
(backgroundSize.width - layout->getContentSize().width) / 2.0f,
(widgetSize.height - backgroundSize.height) / 2.0f +
(backgroundSize.height - layout->getContentSize().height) / 2.0f));
_uiLayer->addChild(layout);
ImageView* imageView_Center1 = ImageView::create("cocosui/scrollviewbg.png");
imageView_Center1->setScale(0.5);
layout->addChild(imageView_Center1);
ImageView* imageView_Center2 = ImageView::create("cocosui/scrollviewbg.png");
imageView_Center2->setScale(1.2);
layout->addChild(imageView_Center2);
ImageView* imageView_Center3 = ImageView::create("cocosui/scrollviewbg.png");
imageView_Center3->setScale(0.8);
layout->addChild(imageView_Center3);
return true;
}
return false;
}
2014-12-22 14:51:50 +08:00
bool UILayoutComponentTest::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getContentSize();
_baseLayer = LayerColor::create();
_baseLayer->setColor(Color3B(50, 100, 0));
_baseLayer->setOpacity(100);
_baseLayer->setContentSize(Size(200, 200));
_uiLayer->addChild(_baseLayer);
Button* button = Button::create("cocosui/animationbuttonnormal.png");
CCLOG("content size should be greater than 0: width = %f, height = %f", button->getContentSize().width,
button->getContentSize().height);
button->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
button->addTouchEventListener(CC_CALLBACK_2(UILayoutComponentTest::touchEvent, this));
button->setZoomScale(0.4f);
button->setPressedActionEnabled(true);
_uiLayer->addChild(button);
return true;
}
return false;
}
void UILayoutComponentTest::touchEvent(Ref *pSender, Widget::TouchEventType type)
{
switch (type)
{
case Widget::TouchEventType::BEGAN:
break;
case Widget::TouchEventType::MOVED:
break;
case Widget::TouchEventType::ENDED:
{
Size widgetSize = _widget->getContentSize();
Size layerSize = _baseLayer->getContentSize();
if (layerSize.width == widgetSize.width && layerSize.height == widgetSize.height)
_baseLayer->setContentSize(Size(200, 200));
else
_baseLayer->setContentSize(widgetSize);
Helper::doLayout(_baseLayer);
2014-12-22 14:51:50 +08:00
}
break;
case Widget::TouchEventType::CANCELED:
break;
default:
break;
}
}
bool UILayoutComponent_Berth_Test::init()
{
if (UILayoutComponentTest::init())
{
Sprite* leftTopSprite = Sprite::create("cocosui/CloseSelected.png");
2014-12-25 15:02:22 +08:00
LayoutComponent* leftTop = LayoutComponent::bindLayoutComponent(leftTopSprite);
2014-12-24 10:56:01 +08:00
leftTop->setHorizontalEdge(LayoutComponent::HorizontalEdge::Left);
leftTop->setVerticalEdge(LayoutComponent::VerticalEdge::Top);
2014-12-22 14:51:50 +08:00
_baseLayer->addChild(leftTopSprite);
Sprite* leftBottomSprite = Sprite::create("cocosui/CloseSelected.png");
2014-12-25 15:02:22 +08:00
LayoutComponent* leftBottom = LayoutComponent::bindLayoutComponent(leftBottomSprite);
2014-12-24 10:56:01 +08:00
leftBottom->setHorizontalEdge(LayoutComponent::HorizontalEdge::Left);
leftBottom->setVerticalEdge(LayoutComponent::VerticalEdge::Bottom);
2014-12-22 14:51:50 +08:00
_baseLayer->addChild(leftBottomSprite);
Sprite* rightTopSprite = Sprite::create("cocosui/CloseSelected.png");
2014-12-25 15:02:22 +08:00
LayoutComponent* rightTop = LayoutComponent::bindLayoutComponent(rightTopSprite);
2014-12-24 10:56:01 +08:00
rightTop->setHorizontalEdge(LayoutComponent::HorizontalEdge::Right);
rightTop->setVerticalEdge(LayoutComponent::VerticalEdge::Top);
2014-12-22 14:51:50 +08:00
_baseLayer->addChild(rightTopSprite);
Sprite* rightBottomSprite = Sprite::create("cocosui/CloseSelected.png");
2014-12-25 15:02:22 +08:00
LayoutComponent* rightBottom = LayoutComponent::bindLayoutComponent(rightBottomSprite);
2014-12-24 10:56:01 +08:00
rightBottom->setHorizontalEdge(LayoutComponent::HorizontalEdge::Right);
rightBottom->setVerticalEdge(LayoutComponent::VerticalEdge::Bottom);
2014-12-22 14:51:50 +08:00
_baseLayer->addChild(rightBottomSprite);
ui::Helper::doLayout(_baseLayer);
return true;
}
return false;
}
bool UILayoutComponent_Berth_Stretch_Test::init()
{
if (UILayoutComponentTest::init())
{
ImageView* leftTopSprite = ImageView::create("cocosui/CloseSelected.png");
leftTopSprite->ignoreContentAdaptWithSize(false);
2014-12-25 15:02:22 +08:00
LayoutComponent* leftTop = LayoutComponent::bindLayoutComponent(leftTopSprite);
2014-12-24 10:56:01 +08:00
leftTop->setHorizontalEdge(LayoutComponent::HorizontalEdge::Left);
leftTop->setVerticalEdge(LayoutComponent::VerticalEdge::Top);
2014-12-22 14:51:50 +08:00
leftTop->setStretchWidthEnabled(true);
leftTop->setStretchHeightEnabled(true);
_baseLayer->addChild(leftTopSprite);
leftTop->setSize(leftTopSprite->getContentSize());
leftTop->setLeftMargin(0);
leftTop->setTopMargin(0);
ImageView* leftBottomSprite = ImageView::create("cocosui/CloseSelected.png");
leftBottomSprite->ignoreContentAdaptWithSize(false);
2014-12-25 15:02:22 +08:00
LayoutComponent* leftBottom = LayoutComponent::bindLayoutComponent(leftBottomSprite);
2014-12-24 10:56:01 +08:00
leftBottom->setHorizontalEdge(LayoutComponent::HorizontalEdge::Left);
leftBottom->setVerticalEdge(LayoutComponent::VerticalEdge::Bottom);
2014-12-22 14:51:50 +08:00
leftBottom->setStretchWidthEnabled(true);
leftBottom->setStretchHeightEnabled(true);
_baseLayer->addChild(leftBottomSprite);
leftBottom->setSize(leftBottomSprite->getContentSize());
leftBottom->setLeftMargin(0);
2014-12-24 10:56:01 +08:00
leftBottom->setBottomMargin(0);
2014-12-22 14:51:50 +08:00
ImageView* rightTopSprite = ImageView::create("cocosui/CloseSelected.png");
rightTopSprite->ignoreContentAdaptWithSize(false);
2014-12-25 15:02:22 +08:00
LayoutComponent* rightTop = LayoutComponent::bindLayoutComponent(rightTopSprite);
2014-12-24 10:56:01 +08:00
rightTop->setHorizontalEdge(LayoutComponent::HorizontalEdge::Right);
rightTop->setVerticalEdge(LayoutComponent::VerticalEdge::Top);
2014-12-22 14:51:50 +08:00
rightTop->setStretchWidthEnabled(true);
rightTop->setStretchHeightEnabled(true);
_baseLayer->addChild(rightTopSprite);
rightTop->setSize(rightTopSprite->getContentSize());
rightTop->setTopMargin(0);
rightTop->setRightMargin(0);
ImageView* rightBottomSprite = ImageView::create("cocosui/CloseSelected.png");
rightBottomSprite->ignoreContentAdaptWithSize(false);
2014-12-25 15:02:22 +08:00
LayoutComponent* rightBottom = LayoutComponent::bindLayoutComponent(rightBottomSprite);
2014-12-24 10:56:01 +08:00
rightBottom->setHorizontalEdge(LayoutComponent::HorizontalEdge::Right);
rightBottom->setVerticalEdge(LayoutComponent::VerticalEdge::Bottom);
2014-12-22 14:51:50 +08:00
rightBottom->setStretchWidthEnabled(true);
rightBottom->setStretchHeightEnabled(true);
_baseLayer->addChild(rightBottomSprite);
rightBottom->setSize(rightBottomSprite->getContentSize());
2014-12-24 10:56:01 +08:00
rightBottom->setBottomMargin(0);
2014-12-22 14:51:50 +08:00
rightBottom->setRightMargin(0);
ui::Helper::doLayout(_baseLayer);
2013-12-23 15:35:35 +08:00
return true;
}
return false;
}