From 92d78efce0b76ee6bfe10f190476735c671ab4f5 Mon Sep 17 00:00:00 2001 From: XiaoFeng Date: Fri, 10 Jul 2015 17:00:16 +0800 Subject: [PATCH] Fix percentage setting won't effect when UISlider's background resource set to null --- .../WidgetReader/SliderReader/SliderReader.cpp | 4 ++-- cocos/ui/UISlider.cpp | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.cpp index 4ca33378ce..18db60f410 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.cpp @@ -466,7 +466,7 @@ namespace cocostudio auto options = (SliderOptions*)sliderOptions; int percent = options->percent(); - slider->setPercent(percent); + //slider->setPercent(percent); bool imageFileExist = false; std::string imageErrorFilePath = ""; @@ -798,7 +798,7 @@ namespace cocostudio auto widgetReader = WidgetReader::getInstance(); widgetReader->setPropsWithFlatBuffers(node, (Table*)options->widgetOptions()); - + slider->setPercent(percent); } Node* SliderReader::createNodeWithFlatBuffers(const flatbuffers::Table *sliderOptions) diff --git a/cocos/ui/UISlider.cpp b/cocos/ui/UISlider.cpp index 427e0a1157..5e1a8894b8 100644 --- a/cocos/ui/UISlider.cpp +++ b/cocos/ui/UISlider.cpp @@ -553,12 +553,14 @@ void Slider::barRendererScaleChangedWithSize() if (btextureSize.width <= 0.0f || btextureSize.height <= 0.0f) { _barRenderer->setScale(1.0f); - return; } - float bscaleX = _contentSize.width / btextureSize.width; - float bscaleY = _contentSize.height / btextureSize.height; - _barRenderer->setScaleX(bscaleX); - _barRenderer->setScaleY(bscaleY); + else + { + float bscaleX = _contentSize.width / btextureSize.width; + float bscaleY = _contentSize.height / btextureSize.height; + _barRenderer->setScaleX(bscaleX); + _barRenderer->setScaleY(bscaleY); + } } } _barRenderer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f);