From b59beab61a3dd776f6630bde1b5117017f61f280 Mon Sep 17 00:00:00 2001 From: andyque Date: Thu, 3 Apr 2014 15:33:57 +0800 Subject: [PATCH] issue #4636, finish UISlider --- cocos/ui/UISlider.cpp | 36 ++++++------- cocos/ui/UISlider.h | 15 +++--- .../UISliderTest/UISliderTest.cpp | 51 ++----------------- 3 files changed, 31 insertions(+), 71 deletions(-) diff --git a/cocos/ui/UISlider.cpp b/cocos/ui/UISlider.cpp index 7d03f3d0f4..a50279cba2 100644 --- a/cocos/ui/UISlider.cpp +++ b/cocos/ui/UISlider.cpp @@ -111,9 +111,9 @@ void Slider::initRenderer() addProtectedChild(_slidBallRenderer, SLIDBALL_RENDERER_Z, -1); } -void Slider::loadBarTexture(const char* fileName, TextureResType texType) +void Slider::loadBarTexture(const std::string& fileName, TextureResType texType) { - if (!fileName || strcmp(fileName, "") == 0) + if (fileName.empty()) { return; } @@ -149,9 +149,9 @@ void Slider::loadBarTexture(const char* fileName, TextureResType texType) progressBarRendererScaleChangedWithSize(); } -void Slider::loadProgressBarTexture(const char *fileName, TextureResType texType) +void Slider::loadProgressBarTexture(const std::string& fileName, TextureResType texType) { - if (!fileName || strcmp(fileName, "") == 0) + if (fileName.empty()) { return; } @@ -210,8 +210,8 @@ void Slider::setScale9Enabled(bool able) _barRenderer = Sprite::create(); _progressBarRenderer = Sprite::create(); } - loadBarTexture(_textureFile.c_str(), _barTexType); - loadProgressBarTexture(_progressBarTextureFile.c_str(), _progressBarTexType); + loadBarTexture(_textureFile, _barTexType); + loadProgressBarTexture(_progressBarTextureFile, _progressBarTexType); addProtectedChild(_barRenderer, BASEBAR_RENDERER_Z, -1); addProtectedChild(_progressBarRenderer, PROGRESSBAR_RENDERER_Z, -1); if (_scale9Enabled) @@ -278,16 +278,16 @@ const Rect& Slider::getCapInsetsProgressBarRebderer() return _capInsetsProgressBarRenderer; } -void Slider::loadSlidBallTextures(const char* normal,const char* pressed,const char* disabled,TextureResType texType) + void Slider::loadSlidBallTextures(const std::string& normal,const std::string& pressed,const std::string& disabled,TextureResType texType) { loadSlidBallTextureNormal(normal, texType); loadSlidBallTexturePressed(pressed,texType); loadSlidBallTextureDisabled(disabled,texType); } -void Slider::loadSlidBallTextureNormal(const char* normal,TextureResType texType) +void Slider::loadSlidBallTextureNormal(const std::string& normal,TextureResType texType) { - if (!normal || strcmp(normal, "") == 0) + if (normal.empty()) { return; } @@ -307,9 +307,9 @@ void Slider::loadSlidBallTextureNormal(const char* normal,TextureResType texType updateRGBAToRenderer(_slidBallNormalRenderer); } -void Slider::loadSlidBallTexturePressed(const char* pressed,TextureResType texType) +void Slider::loadSlidBallTexturePressed(const std::string& pressed,TextureResType texType) { - if (!pressed || strcmp(pressed, "") == 0) + if (pressed.empty()) { return; } @@ -329,9 +329,9 @@ void Slider::loadSlidBallTexturePressed(const char* pressed,TextureResType texTy updateRGBAToRenderer(_slidBallPressedRenderer); } -void Slider::loadSlidBallTextureDisabled(const char* disabled,TextureResType texType) + void Slider::loadSlidBallTextureDisabled(const std::string& disabled,TextureResType texType) { - if (!disabled || strcmp(disabled, "") == 0) + if (disabled.empty()) { return; } @@ -596,11 +596,11 @@ void Slider::copySpecialProperties(Widget *widget) { _prevIgnoreSize = slider->_prevIgnoreSize; setScale9Enabled(slider->_scale9Enabled); - loadBarTexture(slider->_textureFile.c_str(), slider->_barTexType); - loadProgressBarTexture(slider->_progressBarTextureFile.c_str(), slider->_progressBarTexType); - loadSlidBallTextureNormal(slider->_slidBallNormalTextureFile.c_str(), slider->_ballNTexType); - loadSlidBallTexturePressed(slider->_slidBallPressedTextureFile.c_str(), slider->_ballPTexType); - loadSlidBallTextureDisabled(slider->_slidBallDisabledTextureFile.c_str(), slider->_ballDTexType); + loadBarTexture(slider->_textureFile, slider->_barTexType); + loadProgressBarTexture(slider->_progressBarTextureFile, slider->_progressBarTexType); + loadSlidBallTextureNormal(slider->_slidBallNormalTextureFile, slider->_ballNTexType); + loadSlidBallTexturePressed(slider->_slidBallPressedTextureFile, slider->_ballPTexType); + loadSlidBallTextureDisabled(slider->_slidBallDisabledTextureFile, slider->_ballDTexType); setPercent(slider->getPercent()); } } diff --git a/cocos/ui/UISlider.h b/cocos/ui/UISlider.h index de702eacef..3a109b3ac4 100644 --- a/cocos/ui/UISlider.h +++ b/cocos/ui/UISlider.h @@ -71,7 +71,7 @@ public: * * @param texType @see UI_TEX_TYPE_LOCAL */ - void loadBarTexture(const char* fileName,TextureResType texType = UI_TEX_TYPE_LOCAL); + void loadBarTexture(const std::string& fileName,TextureResType texType = UI_TEX_TYPE_LOCAL); /** * Sets if slider is using scale9 renderer. @@ -118,7 +118,10 @@ public: * * @param texType @see UI_TEX_TYPE_LOCAL */ - void loadSlidBallTextures(const char* normal,const char* pressed,const char* disabled,TextureResType texType = UI_TEX_TYPE_LOCAL); + void loadSlidBallTextures(const std::string& normal, + const std::string& pressed, + const std::string& disabled, + TextureResType texType = UI_TEX_TYPE_LOCAL); /** * Load normal state texture for slider ball. @@ -127,7 +130,7 @@ public: * * @param texType @see UI_TEX_TYPE_LOCAL */ - void loadSlidBallTextureNormal(const char* normal,TextureResType texType = UI_TEX_TYPE_LOCAL); + void loadSlidBallTextureNormal(const std::string& normal,TextureResType texType = UI_TEX_TYPE_LOCAL); /** * Load selected state texture for slider ball. @@ -136,7 +139,7 @@ public: * * @param texType @see UI_TEX_TYPE_LOCAL */ - void loadSlidBallTexturePressed(const char* pressed,TextureResType texType = UI_TEX_TYPE_LOCAL); + void loadSlidBallTexturePressed(const std::string& pressed,TextureResType texType = UI_TEX_TYPE_LOCAL); /** * Load dark state texture for slider ball. @@ -145,7 +148,7 @@ public: * * @param texType @see UI_TEX_TYPE_LOCAL */ - void loadSlidBallTextureDisabled(const char* disabled,TextureResType texType = UI_TEX_TYPE_LOCAL); + void loadSlidBallTextureDisabled(const std::string& disabled,TextureResType texType = UI_TEX_TYPE_LOCAL); /** * Load dark state texture for slider progress bar. @@ -154,7 +157,7 @@ public: * * @param texType @see UI_TEX_TYPE_LOCAL */ - void loadProgressBarTexture(const char* fileName, TextureResType texType = UI_TEX_TYPE_LOCAL); + void loadProgressBarTexture(const std::string& fileName, TextureResType texType = UI_TEX_TYPE_LOCAL); /** * Changes the progress direction of slider. diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UISliderTest/UISliderTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UISliderTest/UISliderTest.cpp index a87171c2c2..263cf5da0a 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UISliderTest/UISliderTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UISliderTest/UISliderTest.cpp @@ -22,26 +22,19 @@ bool UISliderTest::init() Size widgetSize = _widget->getSize(); // Add a label in which the slider alert will be displayed - _displayValueLabel = Text::create(); - _displayValueLabel->setText("Move the slider thumb"); - _displayValueLabel->setFontName("fonts/Marker Felt.ttf"); - _displayValueLabel->setFontSize(32); + _displayValueLabel = Text::create("Move the slider thumb","Move the slider thumb",32); _displayValueLabel->setAnchorPoint(Point(0.5f, -1)); _displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); _uiLayer->addChild(_displayValueLabel); // Add the alert - Text* alert = Text::create(); - alert->setText("Slider"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(30); + Text* alert = Text::create("Slider","fonts/Marker Felt.ttf",30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f)); _uiLayer->addChild(alert); // Create the slider Slider* slider = Slider::create(); - slider->setTouchEnabled(true); slider->loadBarTexture("cocosui/sliderTrack.png"); slider->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", ""); slider->loadProgressBarTexture("cocosui/sliderProgress.png"); @@ -49,19 +42,6 @@ bool UISliderTest::init() slider->addEventListenerSlider(this, sliderpercentchangedselector(UISliderTest::sliderEvent)); _uiLayer->addChild(slider); - /* - // Create the slider that set allow min progress and allow max progress - Slider* sliderAllow = Slider::create(); -// sliderAllow->setMinAllowPercent(20); -// sliderAllow->setMaxAllowPercent(80); - sliderAllow->setTouchEnabled(true); - sliderAllow->loadBarTexture("cocosui/sliderTrack.png"); - sliderAllow->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", ""); - sliderAllow->loadProgressBarTexture("cocosui/sliderProgress.png"); - sliderAllow->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - sliderAllow->getSize().height * 2.0f)); - sliderAllow->addEventListenerSlider(this, sliderpercentchangedselector(UISliderTest::sliderEvent)); - _uiLayer->addChild(sliderAllow); - */ return true; } @@ -97,26 +77,19 @@ bool UISliderTest_Scale9::init() Size widgetSize = _widget->getSize(); // Add a label in which the slider alert will be displayed - _displayValueLabel = Text::create(); - _displayValueLabel->setText("Move the slider thumb"); - _displayValueLabel->setFontName("fonts/Marker Felt.ttf"); - _displayValueLabel->setFontSize(32); + _displayValueLabel = Text::create("Move the slider thumb","fonts/Marker Felt.ttf",32); _displayValueLabel->setAnchorPoint(Point(0.5f, -1)); _displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); _uiLayer->addChild(_displayValueLabel); // Add the alert - Text *alert = Text::create(); - alert->setText("Slider scale9 render"); - alert->setFontName("fonts/Marker Felt.ttf"); - alert->setFontSize(30); + Text *alert = Text::create("Slider scale9 render","fonts/Marker Felt.ttf",30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f)); _uiLayer->addChild(alert); // Create the slider Slider* slider = Slider::create(); - slider->setTouchEnabled(true); slider->loadBarTexture("cocosui/sliderTrack2.png"); slider->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", ""); slider->loadProgressBarTexture("cocosui/slider_bar_active_9patch.png"); @@ -127,22 +100,6 @@ bool UISliderTest_Scale9::init() slider->addEventListenerSlider(this, sliderpercentchangedselector(UISliderTest_Scale9::sliderEvent)); _uiLayer->addChild(slider); - /* - // Create the slider that set allow min progress and allow max progress - Slider* sliderAllow = Slider::create(); -// sliderAllow->setMinAllowPercent(20); -// sliderAllow->setMaxAllowPercent(80); - sliderAllow->setTouchEnabled(true); - sliderAllow->loadBarTexture("cocosui/sliderTrack2.png"); - sliderAllow->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", ""); - sliderAllow->loadProgressBarTexture("cocosui/slider_bar_active_9patch.png"); - sliderAllow->setScale9Enabled(true); - sliderAllow->setCapInsets(Rect(0, 0, 0, 0)); - sliderAllow->setSize(Size(250.0f, 10.0f / Director::getInstance()->getContentScaleFactor())); - sliderAllow->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - slider->getSize().height * 3.0f)); - sliderAllow->addEventListenerSlider(this, sliderpercentchangedselector(UISliderTest_Scale9::sliderEvent)); - _uiLayer->addChild(sliderAllow); - */ return true; }