From fdbf84a11867d81b3f406d5b4ba5be80752185ed Mon Sep 17 00:00:00 2001 From: andyque Date: Mon, 26 Jan 2015 13:49:54 +0800 Subject: [PATCH 1/4] add uploading switch scale9 tests --- cocos/ui/UILoadingBar.cpp | 12 ++- cocos/ui/UILoadingBar.h | 1 + .../CocoStudioGUITest/CocosGUIScene.cpp | 2 +- .../UILoadingBarTest/UILoadingBarTest.cpp | 83 +++++++++++++++++++ .../UILoadingBarTest/UILoadingBarTest.h | 16 +++- .../CocoStudioGUITest/UISceneManager.cpp | 3 + .../UITest/CocoStudioGUITest/UISceneManager.h | 1 + 7 files changed, 113 insertions(+), 5 deletions(-) diff --git a/cocos/ui/UILoadingBar.cpp b/cocos/ui/UILoadingBar.cpp index 917a07e3ed..c0a2aab2cd 100644 --- a/cocos/ui/UILoadingBar.cpp +++ b/cocos/ui/UILoadingBar.cpp @@ -216,7 +216,7 @@ void LoadingBar::setScale9Enabled(bool enabled) ignoreContentAdaptWithSize(_prevIgnoreSize); } setCapInsets(_capInsets); - setPercent(_percent); + this->setPercent(_percent); _barRendererAdaptDirty = true; } @@ -255,18 +255,24 @@ void LoadingBar::setPercent(float percent) return; } _percent = percent; + if (_totalLength <= 0) { return; } - float res = _percent / 100.0f; + this->updateProgressBar(); +} + +void LoadingBar::updateProgressBar() +{ if (_scale9Enabled) { setScale9Scale(); } else { + float res = _percent / 100.0f; Sprite* spriteRenderer = _barRenderer->getSprite(); Rect rect = spriteRenderer->getTextureRect(); rect.size.width = _barRendererTextureSize.width * res; @@ -334,7 +340,7 @@ void LoadingBar::barRendererScaleChangedWithSize() _totalLength = _contentSize.width; if (_scale9Enabled) { - setScale9Scale(); + this->setScale9Scale(); _barRenderer->setScale(1.0f); } else diff --git a/cocos/ui/UILoadingBar.h b/cocos/ui/UILoadingBar.h index 058ce793ac..3a961c0f29 100644 --- a/cocos/ui/UILoadingBar.h +++ b/cocos/ui/UILoadingBar.h @@ -148,6 +148,7 @@ protected: virtual void onSizeChanged() override; void setScale9Scale(); + void updateProgressBar(); void barRendererScaleChangedWithSize(); virtual void adaptRenderers() override; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp index 0a63ebbf5f..b5489b4451 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp @@ -139,7 +139,7 @@ g_guisTests[] = UISceneManager* sceneManager = UISceneManager::sharedUISceneManager(); sceneManager->setCurrentUISceneId(kUILoadingBarTest_Left); sceneManager->setMinUISceneId(kUILoadingBarTest_Left); - sceneManager->setMaxUISceneId(kUILoadingBarTest_Right_Scale9); + sceneManager->setMaxUISceneId(kUILoadingBarReloadTexture); Scene* scene = sceneManager->currentUIScene(); Director::getInstance()->replaceScene(scene); } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp index 94e1062365..6da67c0a0e 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp @@ -396,4 +396,87 @@ bool UILoadingBarTest_Scale9_State_Change::init() return true; } return false; +} + + +// UILoadingBarReloadTexture + +UILoadingBarReloadTexture::UILoadingBarReloadTexture() +: _count(0) +{ + +} + +UILoadingBarReloadTexture::~UILoadingBarReloadTexture() +{ + +} + +bool UILoadingBarReloadTexture::init() +{ + if (UIScene::init()) + { + Size widgetSize = _widget->getContentSize(); + + // Add the alert + Text *alert = Text::create("LoadingBar right scale9 render", "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 * 2.7f)); + _uiLayer->addChild(alert); + + LoadingBar* loadingBar = LoadingBar::create("cocosui/slider_bar_active_9patch.png"); + loadingBar->setTag(0); + loadingBar->ignoreContentAdaptWithSize(false); + loadingBar->setScale9Enabled(true); + loadingBar->setCapInsets(Rect(0, 0, 0, 0)); + loadingBar->setContentSize(Size(300, 13)); + loadingBar->setName("texture0"); + loadingBar->setDirection(LoadingBar::Direction::RIGHT); + + loadingBar->setPosition(Vec2(widgetSize.width / 2.0f, + widgetSize.height / 2.0f + loadingBar->getContentSize().height / 4.0f)); + + _uiLayer->addChild(loadingBar); + + auto buttonScale9 = Button::create(); + buttonScale9->setTitleText("ToggleScale9"); + buttonScale9->addClickEventListener([=](Ref*){ + loadingBar->setScale9Enabled(!loadingBar->isScale9Enabled()); + }); + buttonScale9->setPosition(loadingBar->getPosition() + Vec2(-50,50)); + _uiLayer->addChild(buttonScale9); + + auto buttonChangeTexture = Button::create(); + buttonChangeTexture->setTitleText("ChangeTexture"); + buttonChangeTexture->addClickEventListener([=](Ref*){ + auto name = loadingBar->getName(); + if (name == "texture0") + { + loadingBar->loadTexture("cocosui/slider_bar_active_9patch2.png"); + loadingBar->setName("texture1"); + } + else + { + loadingBar->loadTexture("cocosui/slider_bar_active_9patch.png"); + loadingBar->setName("texture0"); + } + }); + buttonChangeTexture->setPosition(loadingBar->getPosition() + Vec2(50,50)); + _uiLayer->addChild(buttonChangeTexture); + + this->scheduleUpdate(); + return true; + } + return false; +} + +void UILoadingBarReloadTexture::update(float delta) +{ + _count++; + if (_count > 100) + { + _count = 0; + } + LoadingBar* loadingBar = static_cast(_uiLayer->getChildByTag(0)); + loadingBar->setPercent(_count); } \ No newline at end of file diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.h index c6c8a4d56a..79428689b4 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.h @@ -104,7 +104,21 @@ public: protected: UI_SCENE_CREATE_FUNC(UILoadingBarTest_Scale9_State_Change) - int _count; + int _count; +}; + +class UILoadingBarReloadTexture : public UIScene +{ +public: + UILoadingBarReloadTexture(); + ~UILoadingBarReloadTexture(); + void update(float dt); + bool init(); + +protected: + UI_SCENE_CREATE_FUNC(UILoadingBarReloadTexture); + int _count; + }; #endif /* defined(__TestCpp__UILoadingBarTest__) */ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp index 5de0885b90..90439e937a 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp @@ -71,6 +71,7 @@ static const char* s_testArray[] = "UILoadingBarTest_Scale9_State_Change", "UILoadingBarTest_Left_Scale9", "UILoadingBarTest_Right_Scale9", + "UILoadingBarReloadTexture", "UITextAtlasTest", "UITextTest", @@ -284,6 +285,8 @@ Scene *UISceneManager::currentUIScene() case kUILoadingBarTest_Right_Scale9: return UILoadingBarTest_Right_Scale9::sceneWithTitle(s_testArray[_currentUISceneId]); + case kUILoadingBarReloadTexture: + return UILoadingBarReloadTexture::sceneWithTitle(s_testArray[_currentUISceneId]); case kUITextAtlasTest: return UITextAtlasTest::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 f0613a2680..52df15c65d 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.h @@ -66,6 +66,7 @@ enum kUILoadingBarTest_Scale9_State_Change, kUILoadingBarTest_Left_Scale9, kUILoadingBarTest_Right_Scale9, + kUILoadingBarReloadTexture, kUITextAtlasTest, kUITextTest, kUITextTest_LineWrap, From 0e67cfcbff1d8a05ceb5886c1b94b692d0b1bcee Mon Sep 17 00:00:00 2001 From: andyque Date: Mon, 26 Jan 2015 14:39:44 +0800 Subject: [PATCH 2/4] improve loading Bar Test --- cocos/ui/UILoadingBar.cpp | 4 +++- .../UILoadingBarTest/UILoadingBarTest.cpp | 10 ++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/cocos/ui/UILoadingBar.cpp b/cocos/ui/UILoadingBar.cpp index c0a2aab2cd..7910dc6899 100644 --- a/cocos/ui/UILoadingBar.cpp +++ b/cocos/ui/UILoadingBar.cpp @@ -193,6 +193,8 @@ void LoadingBar::loadTexture(const std::string& texture,TextureResType texType) barRendererScaleChangedWithSize(); updateContentSizeWithTextureSize(_barRendererTextureSize); + + this->updateProgressBar(); _barRendererAdaptDirty = true; } @@ -216,7 +218,7 @@ void LoadingBar::setScale9Enabled(bool enabled) ignoreContentAdaptWithSize(_prevIgnoreSize); } setCapInsets(_capInsets); - this->setPercent(_percent); + this->updateProgressBar(); _barRendererAdaptDirty = true; } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp index 6da67c0a0e..62b422ac43 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp @@ -427,18 +427,19 @@ bool UILoadingBarReloadTexture::init() LoadingBar* loadingBar = LoadingBar::create("cocosui/slider_bar_active_9patch.png"); loadingBar->setTag(0); loadingBar->ignoreContentAdaptWithSize(false); - loadingBar->setScale9Enabled(true); +// loadingBar->setScale9Enabled(true); loadingBar->setCapInsets(Rect(0, 0, 0, 0)); loadingBar->setContentSize(Size(300, 13)); loadingBar->setName("texture0"); loadingBar->setDirection(LoadingBar::Direction::RIGHT); - + loadingBar->setPercent(70); loadingBar->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + loadingBar->getContentSize().height / 4.0f)); _uiLayer->addChild(loadingBar); - auto buttonScale9 = Button::create(); + auto buttonScale9 = Button::create("cocosui/animationbuttonnormal.png", + "cocosui/animationbuttonpressed.png"); buttonScale9->setTitleText("ToggleScale9"); buttonScale9->addClickEventListener([=](Ref*){ loadingBar->setScale9Enabled(!loadingBar->isScale9Enabled()); @@ -446,7 +447,8 @@ bool UILoadingBarReloadTexture::init() buttonScale9->setPosition(loadingBar->getPosition() + Vec2(-50,50)); _uiLayer->addChild(buttonScale9); - auto buttonChangeTexture = Button::create(); + auto buttonChangeTexture = Button::create("cocosui/animationbuttonnormal.png", + "cocosui/animationbuttonpressed.png"); buttonChangeTexture->setTitleText("ChangeTexture"); buttonChangeTexture->addClickEventListener([=](Ref*){ auto name = loadingBar->getName(); From 12cf9da486dc9f07a0781d1dbd930e3d43c40cd3 Mon Sep 17 00:00:00 2001 From: andyque Date: Mon, 26 Jan 2015 14:46:45 +0800 Subject: [PATCH 3/4] improve loadingbar test --- .../CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp index 62b422ac43..fcf8ed7580 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp @@ -419,9 +419,10 @@ bool UILoadingBarReloadTexture::init() Size widgetSize = _widget->getContentSize(); // Add the alert - Text *alert = Text::create("LoadingBar right scale9 render", "fonts/Marker Felt.ttf", 20); + Text *alert = Text::create("Click button to Toggle Scale9 and switch Texture.", "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 * 2.7f)); + alert->setPosition(Vec2(widgetSize.width / 2.0f, + widgetSize.height / 2.0f - alert->getContentSize().height * 2.7f)); _uiLayer->addChild(alert); LoadingBar* loadingBar = LoadingBar::create("cocosui/slider_bar_active_9patch.png"); From 691e1925ca440297fbdd00b168de9cbe5424920b Mon Sep 17 00:00:00 2001 From: andyque Date: Mon, 26 Jan 2015 15:05:41 +0800 Subject: [PATCH 4/4] udpate test resource submodule --- tests/cpp-tests/Resources/ccs-res | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cpp-tests/Resources/ccs-res b/tests/cpp-tests/Resources/ccs-res index 615f52a6c5..ce5606d4e5 160000 --- a/tests/cpp-tests/Resources/ccs-res +++ b/tests/cpp-tests/Resources/ccs-res @@ -1 +1 @@ -Subproject commit 615f52a6c5fc1f60c6f01832d110c78a65be3a11 +Subproject commit ce5606d4e520d2671a678b0ba3d5a0b84fdb5ab9