From 8433127b45d4cf5319e56c9306847756bed09a94 Mon Sep 17 00:00:00 2001 From: andyque Date: Thu, 6 Nov 2014 09:23:58 +0800 Subject: [PATCH] finish tests --- .../CocoStudioGUITest/CocosGUIScene.cpp | 2 +- .../UIButtonTest/UIButtonTest.cpp | 6 ++- .../UIImageViewTest/UIImageViewTest.cpp | 52 +++++++++++++++++++ .../UIImageViewTest/UIImageViewTest.h | 9 ++++ .../CocoStudioGUITest/UISceneManager.cpp | 4 ++ .../UITest/CocoStudioGUITest/UISceneManager.h | 2 + 6 files changed, 72 insertions(+), 3 deletions(-) diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp index 81be4f598c..2383be754a 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp @@ -127,7 +127,7 @@ g_guisTests[] = UISceneManager* sceneManager = UISceneManager::sharedUISceneManager(); sceneManager->setCurrentUISceneId(kUIImageViewTest); sceneManager->setMinUISceneId(kUIImageViewTest); - sceneManager->setMaxUISceneId(kUIImageViewTest_ContentSize); + sceneManager->setMaxUISceneId(kUIImageViewFlipTest); Scene* scene = sceneManager->currentUIScene(); Director::getInstance()->replaceScene(scene); } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp index 4b55e4110a..a74cb121a3 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp @@ -290,7 +290,7 @@ bool UIButtonTest_Title::init() _uiLayer->addChild(_displayValueLabel); // Add the alert - Text* alert = Text::create("Button with title", "fonts/Marker Felt.ttf", 30); + Text* alert = Text::create("Button with title, title should be flipped!", "fonts/Marker Felt.ttf", 30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 1.75f)); @@ -305,7 +305,9 @@ bool UIButtonTest_Title::init() CCASSERT(button->getTitleColor() == Color3B::YELLOW, "Button setTitleColotr & getTitleColor not match!"); button->addTouchEventListener(CC_CALLBACK_2(UIButtonTest_Title::touchEvent, this)); _uiLayer->addChild(button); - + button->setFlippedX(true); + auto label = button->getTitleRenderer(); + label->setScale(4.0); button->runAction(RepeatForever::create(Sequence::create(ScaleTo::create(1.0f, 1.2f), ScaleTo::create(1.0f, 1.0f),nullptr))); diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp index 01978a4e86..3228d57abf 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp @@ -129,3 +129,55 @@ bool UIImageViewTest_ContentSize::init() } return false; } + + +// UIImageViewFlipTest + +bool UIImageViewFlipTest::init() +{ + if (UIScene::init()) + { + SpriteFrameCache::getInstance()->addSpriteFramesWithFile("Images/blocks9ss.plist"); + Size widgetSize = _widget->getContentSize(); + + Text* alert = Text::create("ImageView flip test", "fonts/Marker Felt.ttf", 26); + alert->setColor(Color3B(159, 168, 176)); + alert->setPosition(Vec2(widgetSize.width / 2.0f, + widgetSize.height / 2.0f - alert->getContentSize().height * 2.125f)); + + _uiLayer->addChild(alert); + + // Create the imageview + ImageView* imageView = ImageView::create("blocks9r.png", Widget::TextureResType::PLIST); + imageView->setScale9Enabled(true); + imageView->setContentSize(Size(250, 115)); + imageView->setFlippedX(true); + imageView->setScale(0.5); + imageView->ignoreContentAdaptWithSize(false); + imageView->setPosition(Vec2(widgetSize.width / 2.0f, + widgetSize.height / 2.0f)); + + _uiLayer->addChild(imageView); + + auto toggleButton = Button::create(); + toggleButton->setTitleText("Toggle FlipX"); + toggleButton->setPosition(imageView->getPosition() + Vec2(-50, - imageView->getContentSize().height/2 - 20)); + this->addChild(toggleButton); + toggleButton->addClickEventListener([=](Ref*){ + imageView->setFlippedX(!imageView->isFlippedX()); + }); + + auto toggleScale9 = Button::create(); + toggleScale9->setTitleText("Toggle Scale9"); + toggleScale9->setPosition(imageView->getPosition() + Vec2(+50, - imageView->getContentSize().height/2- 20)); + this->addChild(toggleScale9); + toggleScale9->addClickEventListener([=](Ref*){ + imageView->setScale9Enabled(!imageView->isScale9Enabled()); + //after switching scale9, you must call setContentSize to keep the size not change + imageView->setContentSize(Size(250, 115)); + }); + + return true; + } + return false; +} diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.h index a70668751c..6ed85b932f 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.h @@ -54,4 +54,13 @@ protected: UI_SCENE_CREATE_FUNC(UIImageViewTest_ContentSize) }; +class UIImageViewFlipTest : public UIScene +{ +public: + bool init(); + +protected: + UI_SCENE_CREATE_FUNC(UIImageViewFlipTest) +}; + #endif /* defined(__TestCpp__UIImageViewTest__) */ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp index e2abb0af52..f92edc7d10 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp @@ -56,6 +56,7 @@ static const char* s_testArray[] = "UIImageViewTest", "UIImageViewTest_Scale9", "UIImageViewTest_ContentSize", + "UIImageViewFlipTest", "UILoadingBarTest_Left", "UILoadingBarTest_Right", @@ -237,6 +238,9 @@ Scene *UISceneManager::currentUIScene() return UIImageViewTest_Scale9::sceneWithTitle(s_testArray[_currentUISceneId]); case kUIImageViewTest_ContentSize: return UIImageViewTest_ContentSize::sceneWithTitle(s_testArray[_currentUISceneId]); + case kUIImageViewFlipTest: + return UIImageViewFlipTest::sceneWithTitle(s_testArray[_currentUISceneId]); + case kUILoadingBarTest_Left: return UILoadingBarTest_Left::sceneWithTitle(s_testArray[_currentUISceneId]); diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.h index a4d6dd4065..da319d9e98 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.h @@ -51,6 +51,8 @@ enum kUIImageViewTest, kUIImageViewTest_Scale9, kUIImageViewTest_ContentSize, + kUIImageViewFlipTest, + kUILoadingBarTest_Left, kUILoadingBarTest_Right, kUILoadingBarTest_Left_Scale9,