From 9c3c693a2196682caf65444cdf351225770c5191 Mon Sep 17 00:00:00 2001 From: andyque Date: Wed, 5 Nov 2014 20:22:35 +0800 Subject: [PATCH 1/3] refactor Widget flip logic --- cocos/ui/UIButton.cpp | 29 ++------------ cocos/ui/UIButton.h | 3 -- cocos/ui/UICheckBox.cpp | 33 +++------------- cocos/ui/UICheckBox.h | 3 -- cocos/ui/UIImageView.cpp | 14 +------ cocos/ui/UIImageView.h | 3 -- cocos/ui/UIText.cpp | 24 ------------ cocos/ui/UIText.h | 2 - cocos/ui/UIWidget.cpp | 82 ++++++++++++++++++++++++++++++++++------ cocos/ui/UIWidget.h | 14 ++++++- 10 files changed, 92 insertions(+), 115 deletions(-) diff --git a/cocos/ui/UIButton.cpp b/cocos/ui/UIButton.cpp index b27d746735..81e637522e 100644 --- a/cocos/ui/UIButton.cpp +++ b/cocos/ui/UIButton.cpp @@ -236,8 +236,7 @@ void Button::loadTextureNormal(const std::string& normal,TextureResType texType) } _normalTextureSize = _buttonNormalRenderer->getContentSize(); - updateFlippedX(); - updateFlippedY(); + this->updateChildrenDisplayedRGBA(); if (_unifySize ) @@ -277,9 +276,7 @@ void Button::loadTexturePressed(const std::string& selected,TextureResType texTy } _pressedTextureSize = _buttonClickedRenderer->getContentSize(); - //TODO: mark as dirty - updateFlippedX(); - updateFlippedY(); + this->updateChildrenDisplayedRGBA(); _pressedTextureLoaded = true; @@ -308,8 +305,7 @@ void Button::loadTextureDisabled(const std::string& disabled,TextureResType texT } _disabledTextureSize = _buttonDisableRenderer->getContentSize(); - updateFlippedX(); - updateFlippedY(); + this->updateChildrenDisplayedRGBA(); _disabledTextureLoaded = true; @@ -539,25 +535,6 @@ void Button::onPressStateChangedToDisabled() _buttonNormalRenderer->setScale(_normalTextureScaleXInSize, _normalTextureScaleYInSize); _buttonClickedRenderer->setScale(_pressedTextureScaleXInSize, _pressedTextureScaleYInSize); } - -void Button::updateFlippedX() -{ - float flip = _flippedX ? -1.0f : 1.0f; - _titleRenderer->setScaleX(flip); - - _buttonNormalRenderer->setFlippedX(_flippedX); - _buttonClickedRenderer->setFlippedX(_flippedX); - _buttonDisableRenderer->setFlippedX(_flippedX); -} - -void Button::updateFlippedY() -{ - float flip = _flippedY ? -1.0f : 1.0f; - _titleRenderer->setScaleY(flip); - _buttonNormalRenderer->setFlippedY(_flippedY); - _buttonClickedRenderer->setFlippedY(_flippedY); - _buttonDisableRenderer->setFlippedY(_flippedY); -} void Button::updateTitleLocation() { diff --git a/cocos/ui/UIButton.h b/cocos/ui/UIButton.h index f5dc86a759..847f17dd1a 100644 --- a/cocos/ui/UIButton.h +++ b/cocos/ui/UIButton.h @@ -220,9 +220,6 @@ protected: virtual void onPressStateChangedToDisabled() override; virtual void onSizeChanged() override; - virtual void updateFlippedX() override; - virtual void updateFlippedY() override; - void normalTextureScaleChangedWithSize(); void pressedTextureScaleChangedWithSize(); void disabledTextureScaleChangedWithSize(); diff --git a/cocos/ui/UICheckBox.cpp b/cocos/ui/UICheckBox.cpp index 619ebbfa71..bc9431057b 100644 --- a/cocos/ui/UICheckBox.cpp +++ b/cocos/ui/UICheckBox.cpp @@ -182,8 +182,7 @@ void CheckBox::loadTextureBackGround(const std::string& backGround,TextureResTyp default: break; } - updateFlippedX(); - updateFlippedY(); + this->updateChildrenDisplayedRGBA(); updateContentSizeWithTextureSize(_backGroundBoxRenderer->getContentSize()); @@ -209,8 +208,7 @@ void CheckBox::loadTextureBackGroundSelected(const std::string& backGroundSelect default: break; } - updateFlippedX(); - updateFlippedY(); + this->updateChildrenDisplayedRGBA(); _backGroundSelectedBoxRendererAdaptDirty = true; @@ -235,8 +233,7 @@ void CheckBox::loadTextureFrontCross(const std::string& cross,TextureResType tex default: break; } - updateFlippedX(); - updateFlippedY(); + this->updateChildrenDisplayedRGBA(); _frontCrossRendererAdaptDirty = true; @@ -261,8 +258,7 @@ void CheckBox::loadTextureBackGroundDisabled(const std::string& backGroundDisabl default: break; } - updateFlippedX(); - updateFlippedY(); + this->updateChildrenDisplayedRGBA(); _backGroundBoxDisabledRendererAdaptDirty = true; @@ -287,8 +283,7 @@ void CheckBox::loadTextureFrontCrossDisabled(const std::string& frontCrossDisabl default: break; } - updateFlippedX(); - updateFlippedY(); + this->updateChildrenDisplayedRGBA(); _frontCrossDisabledRendererAdaptDirty = true; @@ -397,24 +392,6 @@ void CheckBox::addEventListener(const ccCheckBoxCallback& callback) _checkBoxEventCallback = callback; } -void CheckBox::updateFlippedX() -{ - _backGroundBoxRenderer->setFlippedX(_flippedX); - _backGroundSelectedBoxRenderer->setFlippedX(_flippedX); - _frontCrossRenderer->setFlippedX(_flippedX); - _backGroundBoxDisabledRenderer->setFlippedX(_flippedX); - _frontCrossDisabledRenderer->setFlippedX(_flippedX); -} - -void CheckBox::updateFlippedY() -{ - _backGroundBoxRenderer->setFlippedY(_flippedY); - _backGroundSelectedBoxRenderer->setFlippedY(_flippedY); - _frontCrossRenderer->setFlippedY(_flippedY); - _backGroundBoxDisabledRenderer->setFlippedY(_flippedY); - _frontCrossDisabledRenderer->setFlippedY(_flippedY); -} - void CheckBox::onSizeChanged() { Widget::onSizeChanged(); diff --git a/cocos/ui/UICheckBox.h b/cocos/ui/UICheckBox.h index 4b3db8edf2..ce1cb19e81 100644 --- a/cocos/ui/UICheckBox.h +++ b/cocos/ui/UICheckBox.h @@ -215,9 +215,6 @@ protected: virtual void releaseUpEvent(); virtual void onSizeChanged() override; - - virtual void updateFlippedX() override; - virtual void updateFlippedY() override; void backGroundTextureScaleChangedWithSize(); void backGroundSelectedTextureScaleChangedWithSize(); diff --git a/cocos/ui/UIImageView.cpp b/cocos/ui/UIImageView.cpp index 33b1e52dee..209878efe1 100644 --- a/cocos/ui/UIImageView.cpp +++ b/cocos/ui/UIImageView.cpp @@ -131,8 +131,7 @@ void ImageView::loadTexture(const std::string& fileName, TextureResType texType) } _imageTextureSize = _imageRenderer->getContentSize(); - updateFlippedX(); - updateFlippedY(); + this->updateChildrenDisplayedRGBA(); updateContentSizeWithTextureSize(_imageTextureSize); @@ -159,17 +158,6 @@ void ImageView::setTextureRect(const Rect &rect) } } -void ImageView::updateFlippedX() -{ - _imageRenderer->setFlippedX(_flippedX); -} - -void ImageView::updateFlippedY() -{ - _imageRenderer->setFlippedY(_flippedY); - -} - void ImageView::setScale9Enabled(bool able) { if (_scale9Enabled == able) diff --git a/cocos/ui/UIImageView.h b/cocos/ui/UIImageView.h index cdccdc7e03..0af88c85b5 100644 --- a/cocos/ui/UIImageView.h +++ b/cocos/ui/UIImageView.h @@ -119,9 +119,6 @@ CC_CONSTRUCTOR_ACCESS: protected: virtual void initRenderer() override; virtual void onSizeChanged() override; - - virtual void updateFlippedX() override; - virtual void updateFlippedY() override; virtual void adaptRenderers() override; diff --git a/cocos/ui/UIText.cpp b/cocos/ui/UIText.cpp index b6206a8dcc..460863db39 100644 --- a/cocos/ui/UIText.cpp +++ b/cocos/ui/UIText.cpp @@ -257,30 +257,6 @@ void Text::onPressStateChangedToDisabled() } -void Text::updateFlippedX() -{ - if (_flippedX) - { - _labelRenderer->setScaleX(-1.0f); - } - else - { - _labelRenderer->setScaleX(1.0f); - } -} - -void Text::updateFlippedY() -{ - if (_flippedY) - { - _labelRenderer->setScaleY(-1.0f); - } - else - { - _labelRenderer->setScaleY(1.0f); - } -} - void Text::onSizeChanged() { Widget::onSizeChanged(); diff --git a/cocos/ui/UIText.h b/cocos/ui/UIText.h index 58b7a0715f..c8e1291a34 100644 --- a/cocos/ui/UIText.h +++ b/cocos/ui/UIText.h @@ -197,8 +197,6 @@ protected: virtual void onPressStateChangedToDisabled() override; virtual void onSizeChanged() override; - virtual void updateFlippedX() override; - virtual void updateFlippedY() override; void labelScaleChangedWithSize(); virtual Widget* createCloneInstance() override; virtual void copySpecialProperties(Widget* model) override; diff --git a/cocos/ui/UIWidget.cpp b/cocos/ui/UIWidget.cpp index 1ef01292f9..a5e160da81 100644 --- a/cocos/ui/UIWidget.cpp +++ b/cocos/ui/UIWidget.cpp @@ -1135,17 +1135,77 @@ void Widget::copyProperties(Widget *widget) } } -void Widget::setFlippedX(bool flippedX) -{ - _flippedX = flippedX; - updateFlippedX(); -} - -void Widget::setFlippedY(bool flippedY) -{ - _flippedY = flippedY; - updateFlippedY(); -} + void Widget::setFlippedX(bool flippedX) + { + + float realScale = this->getScaleX(); + _flippedX = flippedX; + this->setScaleX(realScale); + } + + void Widget::setFlippedY(bool flippedY) + { + float realScale = this->getScaleY(); + _flippedY = flippedY; + this->setScaleY(realScale); + } + + + + void Widget::setScaleX(float scaleX) + { + if (_flippedX) { + scaleX = scaleX * -1; + } + Node::setScaleX(scaleX); + } + + void Widget::setScaleY(float scaleY) + { + if (_flippedY) { + scaleY = scaleY * -1; + } + Node::setScaleY(scaleY); + } + + void Widget::setScale(float scale) + { + this->setScaleX(scale); + this->setScaleY(scale); + this->setScaleZ(scale); + } + + void Widget::setScale(float scaleX, float scaleY) + { + this->setScaleX(scaleX); + this->setScaleY(scaleY); + } + + float Widget::getScaleX()const + { + float originalScale = Node::getScaleX(); + if (_flippedX) + { + originalScale = originalScale * -1.0; + } + return originalScale; + } + + float Widget::getScaleY()const + { + float originalScale = Node::getScaleY(); + if (_flippedY) + { + originalScale = originalScale * -1.0; + } + return originalScale; + } + + float Widget::getScale()const + { + CCASSERT(this->getScaleX() == this->getScaleY(), ""); + return this->getScaleX(); + } /*temp action*/ diff --git a/cocos/ui/UIWidget.h b/cocos/ui/UIWidget.h index 47556d4ab7..8d9e2f0a00 100644 --- a/cocos/ui/UIWidget.h +++ b/cocos/ui/UIWidget.h @@ -333,6 +333,17 @@ public: /** @deprecated Use setFlippedY() instead */ CC_DEPRECATED_ATTRIBUTE void setFlipY(bool flipY) { setFlippedY(flipY); }; + //override the setScale function of Node + virtual void setScaleX(float scaleX) override; + virtual void setScaleY(float scaleY) override; + virtual void setScale(float scale) override; + virtual void setScale(float scalex, float scaley) override; + using Node::setScaleZ; + virtual float getScaleX() const override; + virtual float getScaleY() const override; + virtual float getScale() const override; + using Node::getScaleZ; + /* * Checks a point if in parent's area. * @@ -663,8 +674,7 @@ protected: virtual void releaseUpEvent(); virtual void cancelUpEvent(); - virtual void updateFlippedX(){}; - virtual void updateFlippedY(){}; + virtual void adaptRenderers(){}; void updateChildrenDisplayedRGBA(); From 4bfa94b8c2f7049a107c7a95b70d779e19a34b0b Mon Sep 17 00:00:00 2001 From: andyque Date: Wed, 5 Nov 2014 20:50:13 +0800 Subject: [PATCH 2/3] add button flip test --- .../CocoStudioGUITest/CocosGUIScene.cpp | 2 +- .../UIButtonTest/UIButtonTest.cpp | 92 +++++++++++-------- .../UIButtonTest/UIButtonTest.h | 12 +++ .../CocoStudioGUITest/UISceneManager.cpp | 3 + .../UITest/CocoStudioGUITest/UISceneManager.h | 1 + 5 files changed, 69 insertions(+), 41 deletions(-) diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp index e4d73f8725..81be4f598c 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp @@ -91,7 +91,7 @@ g_guisTests[] = UISceneManager* sceneManager = UISceneManager::sharedUISceneManager(); sceneManager->setCurrentUISceneId(kUIButtonTest); sceneManager->setMinUISceneId(kUIButtonTest); - sceneManager->setMaxUISceneId(kUIButtonTitleEffectTest); + sceneManager->setMaxUISceneId(kUIButtonFlipTest); 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 6cab2ac2dd..4b55e4110a 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp @@ -470,14 +470,6 @@ bool UIButtonTestSwitchScale9::init() _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); _uiLayer->addChild(_displayValueLabel); - // Add the alert - Text* alert = Text::create("Button","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)); - - _uiLayer->addChild(alert); // Create the button Button* button = Button::create("cocosui/animationbuttonnormal.png", @@ -550,14 +542,6 @@ bool UIButtonTestZoomScale::init() _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 20)); _uiLayer->addChild(_displayValueLabel); - // Add the alert - Text* alert = Text::create("Button","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)); - - _uiLayer->addChild(alert); // Create the button Button* button = Button::create("cocosui/animationbuttonnormal.png", @@ -622,14 +606,6 @@ bool UIButtonTextOnly::init() _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 20)); _uiLayer->addChild(_displayValueLabel); - // Add the alert - Text* alert = Text::create("Button","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)); - - _uiLayer->addChild(alert); // Create the button auto button = Button::create(); @@ -673,14 +649,6 @@ bool UIButtonIgnoreContentSizeTest::init() _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 20)); _uiLayer->addChild(_displayValueLabel); - // Add the alert - Text* alert = Text::create("Button","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)); - - _uiLayer->addChild(alert); // Create the button auto button = Button::create("cocosui/animationbuttonnormal.png", @@ -741,14 +709,6 @@ bool UIButtonTitleEffectTest::init() _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 20)); _uiLayer->addChild(_displayValueLabel); - // Add the alert - Text* alert = Text::create("Button","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)); - - _uiLayer->addChild(alert); // Create the button auto button = Button::create("cocosui/animationbuttonnormal.png", @@ -779,5 +739,57 @@ bool UIButtonTitleEffectTest::init() } return false; } +// UIButtonFlipTest +UIButtonFlipTest::UIButtonFlipTest() +: _displayValueLabel(nullptr) +{ + +} +UIButtonFlipTest::~UIButtonFlipTest() +{ +} + +bool UIButtonFlipTest::init() +{ + if (UIScene::init()) + { + Size widgetSize = _widget->getContentSize(); + + // Add a label in which the button events will be displayed + _displayValueLabel = Text::create("Button X Flipped", "fonts/Marker Felt.ttf",20); + _displayValueLabel->setNormalizedPosition(Vec2(0.3, 0.7)); + _uiLayer->addChild(_displayValueLabel); + + + // Create the button + auto button = Button::create("cocosui/animationbuttonnormal.png", + "cocosui/animationbuttonpressed.png"); + button->setNormalizedPosition(Vec2(0.3f, 0.5f)); + button->setTitleText("PLAY GAME"); + button->setTitleFontName("fonts/Marker Felt.ttf"); + button->setZoomScale(0.3f); + button->setScale(2.0f); + button->setFlippedX(true); + button->setPressedActionEnabled(true); + + + _uiLayer->addChild(button); + + // Create the button + auto button2 = Button::create("cocosui/animationbuttonnormal.png", + "cocosui/animationbuttonpressed.png"); + button2->setNormalizedPosition(Vec2(0.8f, 0.5f)); + button2->setTitleText("PLAY GAME"); + button2->setFlippedY(true); + _uiLayer->addChild(button2); + + auto titleLabel = Text::create("Button Y flipped", "Arial", 20); + titleLabel->setNormalizedPosition(Vec2(0.8, 0.7)); + this->addChild(titleLabel); + + return true; + } + return false; +} diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.h index b8f7c0851e..a920a5e855 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.h @@ -153,4 +153,16 @@ protected: UI_SCENE_CREATE_FUNC(UIButtonTitleEffectTest) Text* _displayValueLabel; }; + +class UIButtonFlipTest : public UIScene +{ +public: + UIButtonFlipTest(); + ~UIButtonFlipTest(); + bool init(); + +protected: + UI_SCENE_CREATE_FUNC(UIButtonFlipTest) + Text* _displayValueLabel; +}; #endif /* defined(__TestCpp__UIButtonTest__) */ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp index 967e3f1a81..e2abb0af52 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp @@ -44,6 +44,7 @@ static const char* s_testArray[] = "UIButtonTextOnly", "UIButtonIgnoreContentSizeTest", "UIButtonTitleEffectTest", + "UIButtonFlipTest", #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) "UIEditBoxTest", @@ -218,6 +219,8 @@ Scene *UISceneManager::currentUIScene() return UIButtonIgnoreContentSizeTest::sceneWithTitle(s_testArray[_currentUISceneId]); case kUIButtonTitleEffectTest: return UIButtonTitleEffectTest::sceneWithTitle(s_testArray[_currentUISceneId]); + case kUIButtonFlipTest: + return UIButtonFlipTest::sceneWithTitle(s_testArray[_currentUISceneId]); case kUICheckBoxTest: return UICheckBoxTest::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 66ab43958f..a4d6dd4065 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.h @@ -41,6 +41,7 @@ enum kUIButtonTextOnly, kUIButtonIgnoreContentSizeTest, kUIButtonTitleEffectTest, + kUIButtonFlipTest, #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) kUIEditBoxTest, #endif From 8433127b45d4cf5319e56c9306847756bed09a94 Mon Sep 17 00:00:00 2001 From: andyque Date: Thu, 6 Nov 2014 09:23:58 +0800 Subject: [PATCH 3/3] 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,