diff --git a/cocos/editor-support/cocostudio/CCSGUIReader.cpp b/cocos/editor-support/cocostudio/CCSGUIReader.cpp index 710297c001..cc0de45460 100644 --- a/cocos/editor-support/cocostudio/CCSGUIReader.cpp +++ b/cocos/editor-support/cocostudio/CCSGUIReader.cpp @@ -1109,6 +1109,10 @@ Widget* WidgetPropertiesReader0300::widgetFromJsonDictionary(const rapidjson::Va } else { + if (!dynamic_cast(widget)) + { + child->setPosition(Point(child->getPositionX() + widget->getSize().width / 2.0f, child->getPositionY() + widget->getSize().height / 2.0f)); + } widget->addChild(child); } } diff --git a/cocos/scripting/lua-bindings/auto/api/Button.lua b/cocos/scripting/lua-bindings/auto/api/Button.lua index 203ab720b4..f4b9700b56 100644 --- a/cocos/scripting/lua-bindings/auto/api/Button.lua +++ b/cocos/scripting/lua-bindings/auto/api/Button.lua @@ -137,11 +137,6 @@ -- @param self -- @return Ref#Ref ret (return value: cc.Ref) --------------------------------- --- @function [parent=#Button] setAnchorPoint --- @param self --- @param #point_table point - -------------------------------- -- @function [parent=#Button] getVirtualRenderer -- @param self @@ -153,7 +148,7 @@ -- @return string#string ret (return value: string) -------------------------------- --- @function [parent=#Button] getContentSize +-- @function [parent=#Button] getVirtualRendererSize -- @param self -- @return size_table#size_table ret (return value: size_table) diff --git a/cocos/scripting/lua-bindings/auto/api/CheckBox.lua b/cocos/scripting/lua-bindings/auto/api/CheckBox.lua index c2a9ed2d91..4784f88235 100644 --- a/cocos/scripting/lua-bindings/auto/api/CheckBox.lua +++ b/cocos/scripting/lua-bindings/auto/api/CheckBox.lua @@ -73,11 +73,6 @@ -- @param self -- @return Ref#Ref ret (return value: cc.Ref) --------------------------------- --- @function [parent=#CheckBox] setAnchorPoint --- @param self --- @param #point_table point - -------------------------------- -- @function [parent=#CheckBox] getVirtualRenderer -- @param self @@ -89,7 +84,7 @@ -- @return string#string ret (return value: string) -------------------------------- --- @function [parent=#CheckBox] getContentSize +-- @function [parent=#CheckBox] getVirtualRendererSize -- @param self -- @return size_table#size_table ret (return value: size_table) diff --git a/cocos/scripting/lua-bindings/auto/api/ImageView.lua b/cocos/scripting/lua-bindings/auto/api/ImageView.lua index d841c5b850..43e733e104 100644 --- a/cocos/scripting/lua-bindings/auto/api/ImageView.lua +++ b/cocos/scripting/lua-bindings/auto/api/ImageView.lua @@ -50,11 +50,6 @@ -- @param self -- @return Ref#Ref ret (return value: cc.Ref) --------------------------------- --- @function [parent=#ImageView] setAnchorPoint --- @param self --- @param #point_table point - -------------------------------- -- @function [parent=#ImageView] getVirtualRenderer -- @param self @@ -66,7 +61,7 @@ -- @return string#string ret (return value: string) -------------------------------- --- @function [parent=#ImageView] getContentSize +-- @function [parent=#ImageView] getVirtualRendererSize -- @param self -- @return size_table#size_table ret (return value: size_table) diff --git a/cocos/scripting/lua-bindings/auto/api/Layout.lua b/cocos/scripting/lua-bindings/auto/api/Layout.lua index bcfe778653..8a5ef2c0e1 100644 --- a/cocos/scripting/lua-bindings/auto/api/Layout.lua +++ b/cocos/scripting/lua-bindings/auto/api/Layout.lua @@ -137,12 +137,6 @@ -- @param self -- @return color3B_table#color3B_table ret (return value: color3B_table) --------------------------------- --- @function [parent=#Layout] hitTest --- @param self --- @param #point_table point --- @return bool#bool ret (return value: bool) - -------------------------------- -- @function [parent=#Layout] setBackGroundImageScale9Enabled -- @param self diff --git a/cocos/scripting/lua-bindings/auto/api/LoadingBar.lua b/cocos/scripting/lua-bindings/auto/api/LoadingBar.lua index a4fc57235c..89637ee4f3 100644 --- a/cocos/scripting/lua-bindings/auto/api/LoadingBar.lua +++ b/cocos/scripting/lua-bindings/auto/api/LoadingBar.lua @@ -76,7 +76,7 @@ -- @return string#string ret (return value: string) -------------------------------- --- @function [parent=#LoadingBar] getContentSize +-- @function [parent=#LoadingBar] getVirtualRendererSize -- @param self -- @return size_table#size_table ret (return value: size_table) diff --git a/cocos/scripting/lua-bindings/auto/api/RichText.lua b/cocos/scripting/lua-bindings/auto/api/RichText.lua index b14dcddf9e..cd2dedd8c8 100644 --- a/cocos/scripting/lua-bindings/auto/api/RichText.lua +++ b/cocos/scripting/lua-bindings/auto/api/RichText.lua @@ -19,10 +19,6 @@ -- @param self -- @param #ccui.RichElement richelement --------------------------------- --- @function [parent=#RichText] formatText --- @param self - -------------------------------- -- @function [parent=#RichText] ignoreContentAdaptWithSize -- @param self @@ -34,9 +30,8 @@ -- @param #float float -------------------------------- --- @function [parent=#RichText] getContentSize +-- @function [parent=#RichText] formatText -- @param self --- @return size_table#size_table ret (return value: size_table) -------------------------------- -- overload function: removeElement(ccui.RichElement) @@ -57,6 +52,11 @@ -- @param self -- @return string#string ret (return value: string) +-------------------------------- +-- @function [parent=#RichText] getVirtualRendererSize +-- @param self +-- @return size_table#size_table ret (return value: size_table) + -------------------------------- -- @function [parent=#RichText] RichText -- @param self diff --git a/cocos/scripting/lua-bindings/auto/api/Slider.lua b/cocos/scripting/lua-bindings/auto/api/Slider.lua index e3a6e6b2ad..41b439b77e 100644 --- a/cocos/scripting/lua-bindings/auto/api/Slider.lua +++ b/cocos/scripting/lua-bindings/auto/api/Slider.lua @@ -118,7 +118,7 @@ -- @return bool#bool ret (return value: bool) -------------------------------- --- @function [parent=#Slider] getContentSize +-- @function [parent=#Slider] getVirtualRendererSize -- @param self -- @return size_table#size_table ret (return value: size_table) diff --git a/cocos/scripting/lua-bindings/auto/api/Text.lua b/cocos/scripting/lua-bindings/auto/api/Text.lua index ff84275e98..6e326cc7a7 100644 --- a/cocos/scripting/lua-bindings/auto/api/Text.lua +++ b/cocos/scripting/lua-bindings/auto/api/Text.lua @@ -95,11 +95,6 @@ -- @param self -- @return Ref#Ref ret (return value: cc.Ref) --------------------------------- --- @function [parent=#Text] setAnchorPoint --- @param self --- @param #point_table point - -------------------------------- -- @function [parent=#Text] getVirtualRenderer -- @param self @@ -111,7 +106,7 @@ -- @return string#string ret (return value: string) -------------------------------- --- @function [parent=#Text] getContentSize +-- @function [parent=#Text] getVirtualRendererSize -- @param self -- @return size_table#size_table ret (return value: size_table) diff --git a/cocos/scripting/lua-bindings/auto/api/TextAtlas.lua b/cocos/scripting/lua-bindings/auto/api/TextAtlas.lua index 1fe2b105f7..b1cba77fdf 100644 --- a/cocos/scripting/lua-bindings/auto/api/TextAtlas.lua +++ b/cocos/scripting/lua-bindings/auto/api/TextAtlas.lua @@ -17,6 +17,10 @@ -- @param self -- @return string#string ret (return value: string) +-------------------------------- +-- @function [parent=#TextAtlas] adaptRenderers +-- @param self + -------------------------------- -- @function [parent=#TextAtlas] setStringValue -- @param self @@ -41,11 +45,6 @@ -- @param self -- @return Ref#Ref ret (return value: cc.Ref) --------------------------------- --- @function [parent=#TextAtlas] setAnchorPoint --- @param self --- @param #point_table point - -------------------------------- -- @function [parent=#TextAtlas] getVirtualRenderer -- @param self @@ -57,7 +56,7 @@ -- @return string#string ret (return value: string) -------------------------------- --- @function [parent=#TextAtlas] getContentSize +-- @function [parent=#TextAtlas] getVirtualRendererSize -- @param self -- @return size_table#size_table ret (return value: size_table) diff --git a/cocos/scripting/lua-bindings/auto/api/TextBMFont.lua b/cocos/scripting/lua-bindings/auto/api/TextBMFont.lua index 961683e0ce..c0fe477b96 100644 --- a/cocos/scripting/lua-bindings/auto/api/TextBMFont.lua +++ b/cocos/scripting/lua-bindings/auto/api/TextBMFont.lua @@ -34,11 +34,6 @@ -- @param self -- @return Ref#Ref ret (return value: cc.Ref) --------------------------------- --- @function [parent=#TextBMFont] setAnchorPoint --- @param self --- @param #point_table point - -------------------------------- -- @function [parent=#TextBMFont] getVirtualRenderer -- @param self @@ -50,7 +45,7 @@ -- @return string#string ret (return value: string) -------------------------------- --- @function [parent=#TextBMFont] getContentSize +-- @function [parent=#TextBMFont] getVirtualRendererSize -- @param self -- @return size_table#size_table ret (return value: size_table) diff --git a/cocos/scripting/lua-bindings/auto/api/TextField.lua b/cocos/scripting/lua-bindings/auto/api/TextField.lua index 1e318ed19a..8b1c571dbf 100644 --- a/cocos/scripting/lua-bindings/auto/api/TextField.lua +++ b/cocos/scripting/lua-bindings/auto/api/TextField.lua @@ -184,11 +184,6 @@ -- @param self -- @return Ref#Ref ret (return value: cc.Ref) --------------------------------- --- @function [parent=#TextField] setAnchorPoint --- @param self --- @param #point_table point - -------------------------------- -- @function [parent=#TextField] getVirtualRenderer -- @param self @@ -205,7 +200,7 @@ -- @param #float float -------------------------------- --- @function [parent=#TextField] getContentSize +-- @function [parent=#TextField] getVirtualRendererSize -- @param self -- @return size_table#size_table ret (return value: size_table) diff --git a/cocos/scripting/lua-bindings/auto/api/Widget.lua b/cocos/scripting/lua-bindings/auto/api/Widget.lua index 1f97832c9f..3ec34ffdc8 100644 --- a/cocos/scripting/lua-bindings/auto/api/Widget.lua +++ b/cocos/scripting/lua-bindings/auto/api/Widget.lua @@ -63,11 +63,6 @@ -- @param self -- @return float#float ret (return value: float) --------------------------------- --- @function [parent=#Widget] getActionTag --- @param self --- @return int#int ret (return value: int) - -------------------------------- -- @function [parent=#Widget] getLayoutParameter -- @param self @@ -100,15 +95,20 @@ -- @param self -- @return bool#bool ret (return value: bool) +-------------------------------- +-- @function [parent=#Widget] getVirtualRendererSize +-- @param self +-- @return size_table#size_table ret (return value: size_table) + -------------------------------- -- @function [parent=#Widget] isTouchEnabled -- @param self -- @return bool#bool ret (return value: bool) -------------------------------- --- @function [parent=#Widget] getContentSize +-- @function [parent=#Widget] getActionTag -- @param self --- @return size_table#size_table ret (return value: size_table) +-- @return int#int ret (return value: int) -------------------------------- -- @function [parent=#Widget] getWorldPosition diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp.REMOVED.git-id b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp.REMOVED.git-id index db0a19197c..f10963bde4 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp.REMOVED.git-id +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp.REMOVED.git-id @@ -1 +1 @@ -a1f2ceee65fe7b4bdae2cd2c32ff84fa332a6b50 \ No newline at end of file +088e9951d4f001122370379060141d0e98b5a4d8 \ No newline at end of file diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.hpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.hpp index 75d07761f8..fa8c906dcd 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.hpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.hpp @@ -365,7 +365,6 @@ int register_all_cocos2dx_ui(lua_State* tolua_S); - #endif // __cocos2dx_ui_h__ diff --git a/cocos/ui/UIButton.cpp b/cocos/ui/UIButton.cpp index cff34e84ec..75ba0e9256 100644 --- a/cocos/ui/UIButton.cpp +++ b/cocos/ui/UIButton.cpp @@ -63,7 +63,10 @@ _pressedTextureScaleXInSize(1.0f), _pressedTextureScaleYInSize(1.0f), _normalTextureLoaded(false), _pressedTextureLoaded(false), -_disabledTextureLoaded(false) +_disabledTextureLoaded(false), +_normalTextureAdaptDirty(true), +_pressedTextureAdaptDirty(true), +_disabledTextureAdaptDirty(true) { } @@ -253,12 +256,12 @@ void Button::loadTextureNormal(const std::string& normal,TextureResType texType) } } _normalTextureSize = _buttonNormalRenderer->getContentSize(); - normalTextureScaleChangedWithSize(); - updateAnchorPoint(); updateFlippedX(); updateFlippedY(); updateRGBAToRenderer(_buttonNormalRenderer); + updateContentSizeWithTextureSize(_normalTextureSize); _normalTextureLoaded = true; + _normalTextureAdaptDirty = true; } void Button::loadTexturePressed(const std::string& selected,TextureResType texType) @@ -301,12 +304,11 @@ void Button::loadTexturePressed(const std::string& selected,TextureResType texTy } } _pressedTextureSize = _buttonClickedRenderer->getContentSize(); - pressedTextureScaleChangedWithSize(); - updateAnchorPoint(); updateFlippedX(); updateFlippedY(); updateRGBAToRenderer(_buttonDisableRenderer); _pressedTextureLoaded = true; + _pressedTextureAdaptDirty = true; } void Button::loadTextureDisabled(const std::string& disabled,TextureResType texType) @@ -349,12 +351,11 @@ void Button::loadTextureDisabled(const std::string& disabled,TextureResType texT } } _disabledTextureSize = _buttonDisableRenderer->getContentSize(); - disabledTextureScaleChangedWithSize(); - updateAnchorPoint(); updateFlippedX(); updateFlippedY(); updateRGBAToRenderer(_buttonDisableRenderer); _disabledTextureLoaded = true; + _disabledTextureAdaptDirty = true; } void Button::setCapInsets(const Rect &capInsets) @@ -516,25 +517,41 @@ void Button::updateFlippedY() static_cast(_buttonDisableRenderer)->setFlippedY(_flippedY); } } - -void Button::setAnchorPoint(const Point &pt) + +void Button::updateTitleLocation() { - Widget::setAnchorPoint(pt); - _buttonNormalRenderer->setAnchorPoint(pt); - _buttonClickedRenderer->setAnchorPoint(pt); - _buttonDisableRenderer->setAnchorPoint(pt); - _titleRenderer->setPosition(Point(_size.width*(0.5f-_anchorPoint.x), _size.height*(0.5f-_anchorPoint.y))); + _titleRenderer->setPosition(Point(_contentSize.width * 0.5f, _contentSize.height * 0.5f)); } void Button::onSizeChanged() { Widget::onSizeChanged(); - normalTextureScaleChangedWithSize(); - pressedTextureScaleChangedWithSize(); - disabledTextureScaleChangedWithSize(); + updateTitleLocation(); + _normalTextureAdaptDirty = true; + _pressedTextureAdaptDirty = true; + _disabledTextureAdaptDirty = true; +} + +void Button::adaptRenderers() +{ + if (_normalTextureAdaptDirty) + { + normalTextureScaleChangedWithSize(); + _normalTextureAdaptDirty = false; + } + if (_pressedTextureAdaptDirty) + { + pressedTextureScaleChangedWithSize(); + _pressedTextureAdaptDirty = false; + } + if (_disabledTextureAdaptDirty) + { + disabledTextureScaleChangedWithSize(); + _disabledTextureAdaptDirty = false; + } } -const Size& Button::getContentSize() const +const Size& Button::getVirtualRendererSize() const { return _normalTextureSize; } @@ -567,7 +584,6 @@ void Button::normalTextureScaleChangedWithSize() { _buttonNormalRenderer->setScale(1.0f); _normalTextureScaleXInSize = _normalTextureScaleYInSize = 1.0f; - _size = _normalTextureSize; } } else @@ -593,6 +609,7 @@ void Button::normalTextureScaleChangedWithSize() _normalTextureScaleYInSize = scaleY; } } + _buttonNormalRenderer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f); } void Button::pressedTextureScaleChangedWithSize() @@ -628,6 +645,7 @@ void Button::pressedTextureScaleChangedWithSize() _pressedTextureScaleYInSize = scaleY; } } + _buttonClickedRenderer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f); } void Button::disabledTextureScaleChangedWithSize() @@ -659,6 +677,7 @@ void Button::disabledTextureScaleChangedWithSize() _buttonDisableRenderer->setScaleY(scaleY); } } + _buttonDisableRenderer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f); } void Button::setPressedActionEnabled(bool enabled) diff --git a/cocos/ui/UIButton.h b/cocos/ui/UIButton.h index 42d9c1d22d..a67cfdd064 100644 --- a/cocos/ui/UIButton.h +++ b/cocos/ui/UIButton.h @@ -146,9 +146,6 @@ public: const Rect& getCapInsetsDisabledRenderer(); - //override "setAnchorPoint" of widget. - virtual void setAnchorPoint(const Point &pt) override; - /** * Sets if button is using scale9 renderer. * @@ -168,8 +165,8 @@ public: //override "ignoreContentAdaptWithSize" method of widget. virtual void ignoreContentAdaptWithSize(bool ignore) override; - //override "getContentSize" method of widget. - virtual const Size& getContentSize() const override; + //override "getVirtualRendererSize" method of widget. + virtual const Size& getVirtualRendererSize() const override; //override "getVirtualRenderer" method of widget. virtual Node* getVirtualRenderer() override; @@ -212,6 +209,8 @@ protected: void disabledTextureScaleChangedWithSize(); virtual Widget* createCloneInstance() override; virtual void copySpecialProperties(Widget* model) override; + virtual void adaptRenderers() override; + void updateTitleLocation(); protected: Node* _buttonNormalRenderer; Node* _buttonClickedRenderer; @@ -240,6 +239,9 @@ protected: bool _normalTextureLoaded; bool _pressedTextureLoaded; bool _disabledTextureLoaded; + bool _normalTextureAdaptDirty; + bool _pressedTextureAdaptDirty; + bool _disabledTextureAdaptDirty; }; } diff --git a/cocos/ui/UICheckBox.cpp b/cocos/ui/UICheckBox.cpp index 1393d7fdb3..2da91ba8c1 100644 --- a/cocos/ui/UICheckBox.cpp +++ b/cocos/ui/UICheckBox.cpp @@ -54,7 +54,12 @@ _backGroundFileName(""), _backGroundSelectedFileName(""), _frontCrossFileName(""), _backGroundDisabledFileName(""), -_frontCrossDisabledFileName("") +_frontCrossDisabledFileName(""), +_backGroundBoxRendererAdaptDirty(true), +_backGroundSelectedBoxRendererAdaptDirty(true), +_frontCrossRendererAdaptDirty(true), +_backGroundBoxDisabledRendererAdaptDirty(true), +_frontCrossDisabledRendererAdaptDirty(true) { } @@ -178,11 +183,11 @@ void CheckBox::loadTextureBackGround(const std::string& backGround,TextureResTyp default: break; } - backGroundTextureScaleChangedWithSize(); - updateAnchorPoint(); updateFlippedX(); updateFlippedY(); updateRGBAToRenderer(_backGroundBoxRenderer); + updateContentSizeWithTextureSize(_backGroundBoxRenderer->getContentSize()); + _backGroundBoxRendererAdaptDirty = true; } void CheckBox::loadTextureBackGroundSelected(const std::string& backGroundSelected,TextureResType texType) @@ -204,11 +209,10 @@ void CheckBox::loadTextureBackGroundSelected(const std::string& backGroundSelect default: break; } - backGroundSelectedTextureScaleChangedWithSize(); - updateAnchorPoint(); updateFlippedX(); updateFlippedY(); updateRGBAToRenderer(_backGroundSelectedBoxRenderer); + _backGroundSelectedBoxRendererAdaptDirty = true; } void CheckBox::loadTextureFrontCross(const std::string& cross,TextureResType texType) @@ -230,11 +234,10 @@ void CheckBox::loadTextureFrontCross(const std::string& cross,TextureResType tex default: break; } - frontCrossTextureScaleChangedWithSize(); - updateAnchorPoint(); updateFlippedX(); updateFlippedY(); updateRGBAToRenderer(_frontCrossRenderer); + _frontCrossRendererAdaptDirty = true; } void CheckBox::loadTextureBackGroundDisabled(const std::string& backGroundDisabled,TextureResType texType) @@ -256,11 +259,10 @@ void CheckBox::loadTextureBackGroundDisabled(const std::string& backGroundDisabl default: break; } - backGroundDisabledTextureScaleChangedWithSize(); - updateAnchorPoint(); updateFlippedX(); updateFlippedY(); updateRGBAToRenderer(_backGroundBoxDisabledRenderer); + _backGroundBoxDisabledRendererAdaptDirty = true; } void CheckBox::loadTextureFrontCrossDisabled(const std::string& frontCrossDisabled,TextureResType texType) @@ -282,11 +284,10 @@ void CheckBox::loadTextureFrontCrossDisabled(const std::string& frontCrossDisabl default: break; } - frontCrossDisabledTextureScaleChangedWithSize(); - updateAnchorPoint(); updateFlippedX(); updateFlippedY(); updateRGBAToRenderer(_frontCrossDisabledRenderer); + _frontCrossDisabledRendererAdaptDirty = true; } void CheckBox::onTouchEnded(Touch *touch, Event *unusedEvent) @@ -396,27 +397,46 @@ void CheckBox::updateFlippedY() _frontCrossDisabledRenderer->setFlippedY(_flippedY); } -void CheckBox::setAnchorPoint(const Point &pt) -{ - Widget::setAnchorPoint(pt); - _backGroundBoxRenderer->setAnchorPoint(pt); - _backGroundSelectedBoxRenderer->setAnchorPoint(pt); - _backGroundBoxDisabledRenderer->setAnchorPoint(pt); - _frontCrossRenderer->setAnchorPoint(pt); - _frontCrossDisabledRenderer->setAnchorPoint(pt); -} - void CheckBox::onSizeChanged() { Widget::onSizeChanged(); - backGroundTextureScaleChangedWithSize(); - backGroundSelectedTextureScaleChangedWithSize(); - frontCrossTextureScaleChangedWithSize(); - backGroundDisabledTextureScaleChangedWithSize(); - frontCrossDisabledTextureScaleChangedWithSize(); + _backGroundBoxRendererAdaptDirty = true; + _backGroundSelectedBoxRendererAdaptDirty = true; + _frontCrossRendererAdaptDirty = true; + _backGroundBoxDisabledRendererAdaptDirty = true; + _frontCrossDisabledRendererAdaptDirty = true; +} + +void CheckBox::adaptRenderers() +{ + if (_backGroundBoxRendererAdaptDirty) + { + backGroundTextureScaleChangedWithSize(); + _backGroundBoxRendererAdaptDirty = false; + } + if (_backGroundSelectedBoxRendererAdaptDirty) + { + backGroundSelectedTextureScaleChangedWithSize(); + _backGroundSelectedBoxRendererAdaptDirty = false; + } + if (_frontCrossRendererAdaptDirty) + { + frontCrossTextureScaleChangedWithSize(); + _frontCrossRendererAdaptDirty = false; + } + if (_backGroundBoxDisabledRendererAdaptDirty) + { + backGroundDisabledTextureScaleChangedWithSize(); + _backGroundBoxDisabledRendererAdaptDirty = false; + } + if (_frontCrossDisabledRendererAdaptDirty) + { + frontCrossDisabledTextureScaleChangedWithSize(); + _frontCrossDisabledRendererAdaptDirty = false; + } } -const Size& CheckBox::getContentSize() const +const Size& CheckBox::getVirtualRendererSize() const { return _backGroundBoxRenderer->getContentSize(); } @@ -431,7 +451,6 @@ void CheckBox::backGroundTextureScaleChangedWithSize() if (_ignoreSize) { _backGroundBoxRenderer->setScale(1.0f); - _size = _backGroundBoxRenderer->getContentSize(); } else { @@ -446,6 +465,7 @@ void CheckBox::backGroundTextureScaleChangedWithSize() _backGroundBoxRenderer->setScaleX(scaleX); _backGroundBoxRenderer->setScaleY(scaleY); } + _backGroundBoxRenderer->setPosition(Point(_contentSize.width / 2, _contentSize.height / 2)); } void CheckBox::backGroundSelectedTextureScaleChangedWithSize() @@ -467,6 +487,7 @@ void CheckBox::backGroundSelectedTextureScaleChangedWithSize() _backGroundSelectedBoxRenderer->setScaleX(scaleX); _backGroundSelectedBoxRenderer->setScaleY(scaleY); } + _backGroundSelectedBoxRenderer->setPosition(Point(_contentSize.width / 2, _contentSize.height / 2)); } void CheckBox::frontCrossTextureScaleChangedWithSize() @@ -488,6 +509,7 @@ void CheckBox::frontCrossTextureScaleChangedWithSize() _frontCrossRenderer->setScaleX(scaleX); _frontCrossRenderer->setScaleY(scaleY); } + _frontCrossRenderer->setPosition(Point(_contentSize.width / 2, _contentSize.height / 2)); } void CheckBox::backGroundDisabledTextureScaleChangedWithSize() @@ -509,6 +531,7 @@ void CheckBox::backGroundDisabledTextureScaleChangedWithSize() _backGroundBoxDisabledRenderer->setScaleX(scaleX); _backGroundBoxDisabledRenderer->setScaleY(scaleY); } + _backGroundBoxDisabledRenderer->setPosition(Point(_contentSize.width / 2, _contentSize.height / 2)); } void CheckBox::frontCrossDisabledTextureScaleChangedWithSize() @@ -530,6 +553,7 @@ void CheckBox::frontCrossDisabledTextureScaleChangedWithSize() _frontCrossDisabledRenderer->setScaleX(scaleX); _frontCrossDisabledRenderer->setScaleY(scaleY); } + _frontCrossDisabledRenderer->setPosition(Point(_contentSize.width / 2, _contentSize.height / 2)); } std::string CheckBox::getDescription() const diff --git a/cocos/ui/UICheckBox.h b/cocos/ui/UICheckBox.h index ab704a547c..6b00c407c5 100644 --- a/cocos/ui/UICheckBox.h +++ b/cocos/ui/UICheckBox.h @@ -164,8 +164,6 @@ public: */ bool getSelectedState(); - //override "setAnchorPoint" method of widget. - virtual void setAnchorPoint(const Point &pt) override; //add a call back function would called when checkbox is selected or unselected. void addEventListenerCheckBox(Ref* target,SEL_SelectedStateEvent selector); @@ -173,8 +171,8 @@ public: //override "onTouchEnded" method of widget. virtual void onTouchEnded(Touch *touch, Event *unusedEvent); - //override "getContentSize" method of widget. - virtual const Size& getContentSize() const override; + //override "getVirtualRendererSize" method of widget. + virtual const Size& getVirtualRendererSize() const override; //override "getVirtualRenderer" method of widget. virtual Node* getVirtualRenderer() override; @@ -213,6 +211,7 @@ protected: void frontCrossDisabledTextureScaleChangedWithSize(); virtual Widget* createCloneInstance() override; virtual void copySpecialProperties(Widget* model) override; + virtual void adaptRenderers() override; protected: Sprite* _backGroundBoxRenderer; Sprite* _backGroundSelectedBoxRenderer; @@ -235,6 +234,12 @@ protected: std::string _frontCrossFileName; std::string _backGroundDisabledFileName; std::string _frontCrossDisabledFileName; + + bool _backGroundBoxRendererAdaptDirty; + bool _backGroundSelectedBoxRendererAdaptDirty; + bool _frontCrossRendererAdaptDirty; + bool _backGroundBoxDisabledRendererAdaptDirty; + bool _frontCrossDisabledRendererAdaptDirty; }; } diff --git a/cocos/ui/UIImageView.cpp b/cocos/ui/UIImageView.cpp index 691a33bd97..eb25b4b4fd 100644 --- a/cocos/ui/UIImageView.cpp +++ b/cocos/ui/UIImageView.cpp @@ -44,7 +44,8 @@ _capInsets(Rect::ZERO), _imageRenderer(nullptr), _textureFile(""), _imageTexType(UI_TEX_TYPE_LOCAL), -_imageTextureSize(_size) +_imageTextureSize(_size), +_imageRendererAdaptDirty(true) { } @@ -150,11 +151,11 @@ void ImageView::loadTexture(const std::string& fileName, TextureResType texType) break; } _imageTextureSize = _imageRenderer->getContentSize(); - imageTextureScaleChangedWithSize(); - updateAnchorPoint(); updateFlippedX(); updateFlippedY(); updateRGBAToRenderer(_imageRenderer); + updateContentSizeWithTextureSize(_imageTextureSize); + _imageRendererAdaptDirty = true; } void ImageView::setTextureRect(const Rect &rect) @@ -257,20 +258,23 @@ const Rect& ImageView::getCapInsets() { return _capInsets; } - -void ImageView::setAnchorPoint(const Point &pt) -{ - Widget::setAnchorPoint(pt); - _imageRenderer->setAnchorPoint(pt); -} void ImageView::onSizeChanged() { Widget::onSizeChanged(); - imageTextureScaleChangedWithSize(); + _imageRendererAdaptDirty = true; +} + +void ImageView::adaptRenderers() +{ + if (_imageRendererAdaptDirty) + { + imageTextureScaleChangedWithSize(); + _imageRendererAdaptDirty = false; + } } -const Size& ImageView::getContentSize() const +const Size& ImageView::getVirtualRendererSize() const { return _imageTextureSize; } @@ -287,7 +291,6 @@ void ImageView::imageTextureScaleChangedWithSize() if (!_scale9Enabled) { _imageRenderer->setScale(1.0f); - _size = _imageTextureSize; } } else @@ -310,6 +313,7 @@ void ImageView::imageTextureScaleChangedWithSize() _imageRenderer->setScaleY(scaleY); } } + _imageRenderer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f); } std::string ImageView::getDescription() const diff --git a/cocos/ui/UIImageView.h b/cocos/ui/UIImageView.h index 97e1051e6e..8b88b8e09b 100644 --- a/cocos/ui/UIImageView.h +++ b/cocos/ui/UIImageView.h @@ -99,9 +99,6 @@ public: const Rect& getCapInsets(); - //override "setAnchorPoint" method of widget. - virtual void setAnchorPoint(const Point &pt) override; - //override "ignoreContentAdaptWithSize" method of widget. virtual void ignoreContentAdaptWithSize(bool ignore) override; @@ -110,7 +107,7 @@ public: */ virtual std::string getDescription() const override; - virtual const Size& getContentSize() const override; + virtual const Size& getVirtualRendererSize() const override; virtual Node* getVirtualRenderer() override; CC_CONSTRUCTOR_ACCESS: @@ -129,6 +126,7 @@ protected: void imageTextureScaleChangedWithSize(); virtual Widget* createCloneInstance() override; virtual void copySpecialProperties(Widget* model) override; + virtual void adaptRenderers() override; protected: bool _scale9Enabled; bool _prevIgnoreSize; @@ -137,6 +135,7 @@ protected: std::string _textureFile; TextureResType _imageTexType; Size _imageTextureSize; + bool _imageRendererAdaptDirty; }; } diff --git a/cocos/ui/UILayout.cpp b/cocos/ui/UILayout.cpp index 9e4886e369..f57359a3b3 100644 --- a/cocos/ui/UILayout.cpp +++ b/cocos/ui/UILayout.cpp @@ -700,24 +700,14 @@ bool Layout::isClippingEnabled() { return _clippingEnabled; } - -bool Layout::hitTest(const Point &pt) -{ - Point nsp = convertToNodeSpace(pt); - Rect bb = Rect(0.0f, 0.0f, _size.width, _size.height); - if (nsp.x >= bb.origin.x && nsp.x <= bb.origin.x + bb.size.width && nsp.y >= bb.origin.y && nsp.y <= bb.origin.y + bb.size.height) - { - return true; - } - return false; -} - + void Layout::visit(Renderer *renderer, const kmMat4 &parentTransform, bool parentTransformUpdated) { if (!_enabled) { return; } + adaptRenderers(); if (_clippingEnabled) { switch (_clippingType) @@ -1075,7 +1065,6 @@ const Rect& Layout::getClippingRect() void Layout::onSizeChanged() { Widget::onSizeChanged(); - setContentSize(_size); setStencilClippingSize(_size); _doLayoutDirty = true; _clippingRectDirty = true; diff --git a/cocos/ui/UILayout.h b/cocos/ui/UILayout.h index 8d56d44610..ffec780a70 100644 --- a/cocos/ui/UILayout.h +++ b/cocos/ui/UILayout.h @@ -265,9 +265,7 @@ public: virtual void onEnter() override; virtual void onExit() override; - - virtual bool hitTest(const Point &pt); - + CC_CONSTRUCTOR_ACCESS: //override "init" method of widget. virtual bool init() override; diff --git a/cocos/ui/UILoadingBar.cpp b/cocos/ui/UILoadingBar.cpp index c6b5191bd0..dae641c1ac 100644 --- a/cocos/ui/UILoadingBar.cpp +++ b/cocos/ui/UILoadingBar.cpp @@ -43,7 +43,8 @@ _barRendererTextureSize(Size::ZERO), _scale9Enabled(false), _prevIgnoreSize(true), _capInsets(Rect::ZERO), -_textureFile("") +_textureFile(""), +_barRendererAdaptDirty(true) { } @@ -175,7 +176,9 @@ int LoadingBar::getDirection() } break; } - barRendererScaleChangedWithSize(); +// barRendererScaleChangedWithSize(); + updateContentSizeWithTextureSize(_barRendererTextureSize); + _barRendererAdaptDirty = true; } void LoadingBar::setScale9Enabled(bool enabled) @@ -265,7 +268,16 @@ int LoadingBar::getPercent() void LoadingBar::onSizeChanged() { Widget::onSizeChanged(); - barRendererScaleChangedWithSize(); + _barRendererAdaptDirty = true; +} + +void LoadingBar::adaptRenderers() +{ + if (_barRendererAdaptDirty) + { + barRendererScaleChangedWithSize(); + _barRendererAdaptDirty = false; + } } void LoadingBar::ignoreContentAdaptWithSize(bool ignore) @@ -277,7 +289,7 @@ void LoadingBar::ignoreContentAdaptWithSize(bool ignore) } } -const Size& LoadingBar::getContentSize() const +const Size& LoadingBar::getVirtualRendererSize() const { return _barRendererTextureSize; } @@ -295,7 +307,6 @@ void LoadingBar::barRendererScaleChangedWithSize() { _totalLength = _barRendererTextureSize.width; _barRenderer->setScale(1.0f); - _size = _barRendererTextureSize; } } else @@ -323,10 +334,10 @@ void LoadingBar::barRendererScaleChangedWithSize() switch (_barType) { case LoadingBarTypeLeft: - _barRenderer->setPosition(Point(-_totalLength * 0.5f, 0.0f)); + _barRenderer->setPosition(Point(0.0f, _contentSize.height / 2.0f)); break; case LoadingBarTypeRight: - _barRenderer->setPosition(Point(_totalLength * 0.5f, 0.0f)); + _barRenderer->setPosition(Point(_totalLength, _contentSize.height / 2.0f)); break; default: break; diff --git a/cocos/ui/UILoadingBar.h b/cocos/ui/UILoadingBar.h index 65e9a3e8de..f00de91acf 100644 --- a/cocos/ui/UILoadingBar.h +++ b/cocos/ui/UILoadingBar.h @@ -128,8 +128,8 @@ public: //override "ignoreContentAdaptWithSize" method of widget. virtual void ignoreContentAdaptWithSize(bool ignore) override; - //override "getContentSize" method of widget. - virtual const Size& getContentSize() const override; + //override "getVirtualRendererSize" method of widget. + virtual const Size& getVirtualRendererSize() const override; //override "getVirtualRenderer" method of widget. virtual Node* getVirtualRenderer() override; @@ -148,6 +148,7 @@ protected: void barRendererScaleChangedWithSize(); virtual Widget* createCloneInstance() override; virtual void copySpecialProperties(Widget* model) override; + virtual void adaptRenderers() override; protected: LoadingBarType _barType; int _percent; @@ -159,6 +160,7 @@ protected: bool _prevIgnoreSize; Rect _capInsets; std::string _textureFile; + bool _barRendererAdaptDirty; }; } diff --git a/cocos/ui/UIRichText.cpp b/cocos/ui/UIRichText.cpp index a3dc6a0245..33180f3b42 100644 --- a/cocos/ui/UIRichText.cpp +++ b/cocos/ui/UIRichText.cpp @@ -211,12 +211,11 @@ void RichText::formatText() if (FileUtils::getInstance()->isFileExist(elmtText->_fontName)) { elementRenderer = Label::createWithTTF(elmtText->_text.c_str(), elmtText->_fontName, elmtText->_fontSize); - } + } else { elementRenderer = Label::createWithSystemFont(elmtText->_text.c_str(), elmtText->_fontName, elmtText->_fontSize); } - break; } case RICH_IMAGE: @@ -428,13 +427,15 @@ void RichText::formarRenderers() if (_ignoreSize) { - Size s = getContentSize(); + Size s = getVirtualRendererSize(); _size = s; } else { _size = _customSize; } + updateContentSizeWithTextureSize(_size); + _elementRenderersContainer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f); } void RichText::pushToContainer(cocos2d::Node *renderer) @@ -466,7 +467,7 @@ void RichText::setAnchorPoint(const Point &pt) _elementRenderersContainer->setAnchorPoint(pt); } -const Size& RichText::getContentSize() const +const Size& RichText::getVirtualRendererSize() const { return _elementRenderersContainer->getContentSize(); } diff --git a/cocos/ui/UIRichText.h b/cocos/ui/UIRichText.h index d5e0f176b2..6bf9fddf63 100644 --- a/cocos/ui/UIRichText.h +++ b/cocos/ui/UIRichText.h @@ -105,7 +105,7 @@ public: virtual void visit(cocos2d::Renderer *renderer, const kmMat4 &parentTransform, bool parentTransformUpdated) override; void setVerticalSpace(float space); virtual void setAnchorPoint(const Point &pt); - virtual const Size& getContentSize() const; + virtual const Size& getVirtualRendererSize() const override; void formatText(); virtual void ignoreContentAdaptWithSize(bool ignore); virtual std::string getDescription() const override; diff --git a/cocos/ui/UISlider.cpp b/cocos/ui/UISlider.cpp index 20449b7083..e6b190bc44 100644 --- a/cocos/ui/UISlider.cpp +++ b/cocos/ui/UISlider.cpp @@ -60,7 +60,9 @@ _barTexType(UI_TEX_TYPE_LOCAL), _progressBarTexType(UI_TEX_TYPE_LOCAL), _ballNTexType(UI_TEX_TYPE_LOCAL), _ballPTexType(UI_TEX_TYPE_LOCAL), -_ballDTexType(UI_TEX_TYPE_LOCAL) +_ballDTexType(UI_TEX_TYPE_LOCAL), +_barRendererAdaptDirty(true), +_progressBarRendererDirty(true) { } @@ -145,8 +147,9 @@ void Slider::loadBarTexture(const std::string& fileName, TextureResType texType) break; } updateRGBAToRenderer(_barRenderer); - barRendererScaleChangedWithSize(); - progressBarRendererScaleChangedWithSize(); + _barRendererAdaptDirty = true; + _progressBarRendererDirty = true; + updateContentSizeWithTextureSize(_barRenderer->getContentSize()); } void Slider::loadProgressBarTexture(const std::string& fileName, TextureResType texType) @@ -185,7 +188,7 @@ void Slider::loadProgressBarTexture(const std::string& fileName, TextureResType updateRGBAToRenderer(_progressBarRenderer); _progressBarRenderer->setAnchorPoint(Point(0.0f, 0.5f)); _progressBarTextureSize = _progressBarRenderer->getContentSize(); - progressBarRendererScaleChangedWithSize(); + _progressBarRendererDirty = true; } void Slider::setScale9Enabled(bool able) @@ -364,7 +367,7 @@ void Slider::setPercent(int percent) _percent = percent; float res = percent / 100.0f; float dis = _barLength * res; - _slidBallRenderer->setPosition(Point(-_barLength/2.0f + dis, 0.0f)); + _slidBallRenderer->setPosition(Point(dis, _contentSize.height / 2.0f)); if (_scale9Enabled) { static_cast(_progressBarRenderer)->setPreferredSize(Size(dis,_progressBarTextureSize.height)); @@ -405,7 +408,6 @@ void Slider::onTouchMoved(Touch *touch, Event *unusedEvent) { _touchMovePos = touch->getLocation(); Point nsp = convertToNodeSpace(_touchMovePos); - _slidBallRenderer->setPosition(Point(nsp.x,0)); setPercent(getPercentWithBallPos(nsp.x)); percentChangedEvent(); } @@ -422,7 +424,7 @@ void Slider::onTouchCancelled(Touch *touch, Event *unusedEvent) float Slider::getPercentWithBallPos(float px) { - return (((px-(-_barLength/2.0f))/_barLength)*100.0f); + return ((px/_barLength)*100.0f); } void Slider::addEventListenerSlider(Ref *target, SEL_SlidPercentChangedEvent selector) @@ -447,11 +449,25 @@ int Slider::getPercent() void Slider::onSizeChanged() { Widget::onSizeChanged(); - barRendererScaleChangedWithSize(); - progressBarRendererScaleChangedWithSize(); + _barRendererAdaptDirty = true; + _progressBarRendererDirty = true; +} + +void Slider::adaptRenderers() +{ + if (_barRendererAdaptDirty) + { + barRendererScaleChangedWithSize(); + _barRendererAdaptDirty = false; + } + if (_progressBarRendererDirty) + { + progressBarRendererScaleChangedWithSize(); + _progressBarRendererDirty = false; + } } -const Size& Slider::getContentSize() const +const Size& Slider::getVirtualRendererSize() const { return _barRenderer->getContentSize(); } @@ -467,7 +483,6 @@ void Slider::barRendererScaleChangedWithSize() { _barRenderer->setScale(1.0f); - _size = _barRenderer->getContentSize(); _barLength = _size.width; } else @@ -491,6 +506,7 @@ void Slider::barRendererScaleChangedWithSize() _barRenderer->setScaleY(bscaleY); } } + _barRenderer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f); setPercent(_percent); } @@ -528,7 +544,7 @@ void Slider::progressBarRendererScaleChangedWithSize() _progressBarRenderer->setScaleY(pscaleY); } } - _progressBarRenderer->setPosition(Point(-_barLength * 0.5f, 0.0f)); + _progressBarRenderer->setPosition(0.0f, _contentSize.height / 2.0f); setPercent(_percent); } diff --git a/cocos/ui/UISlider.h b/cocos/ui/UISlider.h index 3a109b3ac4..aa21cccc4b 100644 --- a/cocos/ui/UISlider.h +++ b/cocos/ui/UISlider.h @@ -183,8 +183,8 @@ public: virtual void onTouchEnded(Touch *touch, Event *unusedEvent) override; virtual void onTouchCancelled(Touch *touch, Event *unusedEvent) override; - //override "getContentSize" method of widget. - virtual const Size& getContentSize() const override; + //override "getVirtualRendererSize" method of widget. + virtual const Size& getVirtualRendererSize() const override; //override "getVirtualRenderer" method of widget. virtual Node* getVirtualRenderer() override; @@ -217,6 +217,7 @@ protected: void progressBarRendererScaleChangedWithSize(); virtual Widget* createCloneInstance() override; virtual void copySpecialProperties(Widget* model) override; + virtual void adaptRenderers() override; protected: Node* _barRenderer; Node* _progressBarRenderer; @@ -248,6 +249,8 @@ protected: TextureResType _ballNTexType; TextureResType _ballPTexType; TextureResType _ballDTexType; + bool _barRendererAdaptDirty; + bool _progressBarRendererDirty; }; } diff --git a/cocos/ui/UIText.cpp b/cocos/ui/UIText.cpp index d1e3d711b2..a0fc15131a 100644 --- a/cocos/ui/UIText.cpp +++ b/cocos/ui/UIText.cpp @@ -39,7 +39,8 @@ _normalScaleValueY(1.0f), _fontName("Thonburi"), _fontSize(10), _onSelectedScaleOffset(0.5), -_labelRenderer(nullptr) +_labelRenderer(nullptr), +_labelRendererAdaptDirty(true) { } @@ -104,7 +105,8 @@ void Text::initRenderer() void Text::setText(const std::string& text) { _labelRenderer->setString(text); - labelScaleChangedWithSize(); + updateContentSizeWithTextureSize(_labelRenderer->getContentSize()); + _labelRendererAdaptDirty = true; } const std::string& Text::getStringValue() @@ -121,7 +123,8 @@ void Text::setFontSize(int size) { _fontSize = size; _labelRenderer->setSystemFontSize(size); - labelScaleChangedWithSize(); + updateContentSizeWithTextureSize(_labelRenderer->getContentSize()); + _labelRendererAdaptDirty = true; } int Text::getFontSize() @@ -133,7 +136,8 @@ void Text::setFontName(const std::string& name) { _fontName = name; _labelRenderer->setSystemFontName(name); - labelScaleChangedWithSize(); + updateContentSizeWithTextureSize(_labelRenderer->getContentSize()); + _labelRendererAdaptDirty = true; } const std::string& Text::getFontName() @@ -144,7 +148,8 @@ const std::string& Text::getFontName() void Text::setTextAreaSize(const Size &size) { _labelRenderer->setDimensions(size.width,size.height); - labelScaleChangedWithSize(); + updateContentSizeWithTextureSize(_labelRenderer->getContentSize()); + _labelRendererAdaptDirty = true; } const Size& Text::getTextAreaSize() @@ -155,7 +160,8 @@ const Size& Text::getTextAreaSize() void Text::setTextHorizontalAlignment(TextHAlignment alignment) { _labelRenderer->setHorizontalAlignment(alignment); - labelScaleChangedWithSize(); + updateContentSizeWithTextureSize(_labelRenderer->getContentSize()); + _labelRendererAdaptDirty = true; } TextHAlignment Text::getTextHorizontalAlignment() @@ -166,7 +172,8 @@ TextHAlignment Text::getTextHorizontalAlignment() void Text::setTextVerticalAlignment(TextVAlignment alignment) { _labelRenderer->setVerticalAlignment(alignment); - labelScaleChangedWithSize(); + updateContentSizeWithTextureSize(_labelRenderer->getContentSize()); + _labelRendererAdaptDirty = true; } TextVAlignment Text::getTextVerticalAlignment() @@ -233,19 +240,22 @@ void Text::updateFlippedY() } } -void Text::setAnchorPoint(const Point &pt) -{ - Widget::setAnchorPoint(pt); - _labelRenderer->setAnchorPoint(pt); -} - void Text::onSizeChanged() { Widget::onSizeChanged(); - labelScaleChangedWithSize(); + _labelRendererAdaptDirty = true; +} + +void Text::adaptRenderers() +{ + if (_labelRendererAdaptDirty) + { + labelScaleChangedWithSize(); + _labelRendererAdaptDirty = false; + } } -const Size& Text::getContentSize() const +const Size& Text::getVirtualRendererSize() const { return _labelRenderer->getContentSize(); } @@ -261,7 +271,6 @@ void Text::labelScaleChangedWithSize() { _labelRenderer->setDimensions(0,0); _labelRenderer->setScale(1.0f); - _size = _labelRenderer->getContentSize(); _normalScaleValueX = _normalScaleValueY = 1.0f; } else @@ -280,7 +289,7 @@ void Text::labelScaleChangedWithSize() _normalScaleValueX = scaleX; _normalScaleValueY = scaleY; } - + _labelRenderer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f); } std::string Text::getDescription() const diff --git a/cocos/ui/UIText.h b/cocos/ui/UIText.h index 4113397787..65d1d04ed9 100644 --- a/cocos/ui/UIText.h +++ b/cocos/ui/UIText.h @@ -116,11 +116,8 @@ public: */ bool isTouchScaleChangeEnabled(); - //override "setAnchorPoint" method of widget. - virtual void setAnchorPoint(const Point &pt) override; - - //override "getContentSize" method of widget. - virtual const Size& getContentSize() const override; + //override "getVirtualRendererSize" method of widget. + virtual const Size& getVirtualRendererSize() const override; //override "getVirtualRenderer" method of widget. virtual Node* getVirtualRenderer() override; @@ -162,6 +159,7 @@ protected: void labelScaleChangedWithSize(); virtual Widget* createCloneInstance() override; virtual void copySpecialProperties(Widget* model) override; + virtual void adaptRenderers() override; protected: bool _touchScaleChangeEnabled; float _normalScaleValueX; @@ -170,6 +168,7 @@ protected: int _fontSize; float _onSelectedScaleOffset; Label* _labelRenderer; + bool _labelRendererAdaptDirty; }; } diff --git a/cocos/ui/UITextAtlas.cpp b/cocos/ui/UITextAtlas.cpp index f0cbc01421..0beb9c67b9 100644 --- a/cocos/ui/UITextAtlas.cpp +++ b/cocos/ui/UITextAtlas.cpp @@ -38,7 +38,8 @@ _stringValue(""), _charMapFileName(""), _itemWidth(0), _itemHeight(0), -_startCharMap("") +_startCharMap(""), +_labelAtlasRendererAdaptDirty(true) { } @@ -62,6 +63,7 @@ TextAtlas* TextAtlas::create() void TextAtlas::initRenderer() { _labelAtlasRenderer = LabelAtlas::create(); + _labelAtlasRenderer->setAnchorPoint(Point::ANCHOR_MIDDLE); addProtectedChild(_labelAtlasRenderer, LABELATLAS_RENDERER_Z, -1); } @@ -90,15 +92,18 @@ void TextAtlas::setProperty(const std::string& stringValue, const std::string& c _itemHeight = itemHeight; _startCharMap = startCharMap; _labelAtlasRenderer->initWithString(stringValue, charMapFile, itemWidth, itemHeight, (int)(startCharMap[0])); - updateAnchorPoint(); - labelAtlasScaleChangedWithSize(); + updateContentSizeWithTextureSize(_labelAtlasRenderer->getContentSize()); + _labelAtlasRendererAdaptDirty = true; + CCLOG("cs w %f, h %f", _contentSize.width, _contentSize.height); } void TextAtlas::setStringValue(const std::string& value) { _stringValue = value; _labelAtlasRenderer->setString(value); - labelAtlasScaleChangedWithSize(); + updateContentSizeWithTextureSize(_labelAtlasRenderer->getContentSize()); + _labelAtlasRendererAdaptDirty = true; + CCLOG("cssss w %f, h %f", _contentSize.width, _contentSize.height); } const std::string& TextAtlas::getStringValue() const @@ -106,19 +111,22 @@ const std::string& TextAtlas::getStringValue() const return _labelAtlasRenderer->getString(); } -void TextAtlas::setAnchorPoint(const Point &pt) -{ - Widget::setAnchorPoint(pt); - _labelAtlasRenderer->setAnchorPoint(Point(pt.x, pt.y)); -} - void TextAtlas::onSizeChanged() { Widget::onSizeChanged(); - labelAtlasScaleChangedWithSize(); + _labelAtlasRendererAdaptDirty = true; +} + +void TextAtlas::adaptRenderers() +{ + if (_labelAtlasRendererAdaptDirty) + { + labelAtlasScaleChangedWithSize(); + _labelAtlasRendererAdaptDirty = false; + } } -const Size& TextAtlas::getContentSize() const +const Size& TextAtlas::getVirtualRendererSize() const { return _labelAtlasRenderer->getContentSize(); } @@ -133,7 +141,6 @@ void TextAtlas::labelAtlasScaleChangedWithSize() if (_ignoreSize) { _labelAtlasRenderer->setScale(1.0f); - _size = _labelAtlasRenderer->getContentSize(); } else { @@ -148,6 +155,7 @@ void TextAtlas::labelAtlasScaleChangedWithSize() _labelAtlasRenderer->setScaleX(scaleX); _labelAtlasRenderer->setScaleY(scaleY); } + _labelAtlasRenderer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f); } std::string TextAtlas::getDescription() const diff --git a/cocos/ui/UITextAtlas.h b/cocos/ui/UITextAtlas.h index 501473f7cd..2a79e84803 100644 --- a/cocos/ui/UITextAtlas.h +++ b/cocos/ui/UITextAtlas.h @@ -78,11 +78,8 @@ public: //get string value for labelatlas. const std::string& getStringValue() const; - //override "setAnchorPoint" method of widget. - virtual void setAnchorPoint(const Point &pt) override; - - //override "getContentSize" method of widget. - virtual const Size& getContentSize() const override; + //override "getVirtualRendererSize" method of widget. + virtual const Size& getVirtualRendererSize() const override; //override "getVirtualRenderer" method of widget. virtual Node* getVirtualRenderer() override; @@ -92,6 +89,7 @@ public: */ virtual std::string getDescription() const override; + virtual void adaptRenderers() override; protected: virtual void initRenderer() override; virtual void onSizeChanged() override; @@ -108,6 +106,7 @@ protected: int _itemWidth; int _itemHeight; std::string _startCharMap; + bool _labelAtlasRendererAdaptDirty; }; } diff --git a/cocos/ui/UITextBMFont.cpp b/cocos/ui/UITextBMFont.cpp index 85b893fa9f..78648b464f 100644 --- a/cocos/ui/UITextBMFont.cpp +++ b/cocos/ui/UITextBMFont.cpp @@ -36,7 +36,8 @@ TextBMFont::TextBMFont(): _labelBMFontRenderer(nullptr), _fntFileHasInit(false), _fntFileName(""), -_stringValue("") +_stringValue(""), +_labelBMFontRendererAdaptDirty(true) { } @@ -85,8 +86,7 @@ void TextBMFont::setFntFile(const std::string& fileName) } _fntFileName = fileName; _labelBMFontRenderer->setBMFontFilePath(fileName); - updateAnchorPoint(); - labelBMFontScaleChangedWithSize(); + updateRGBAToRenderer(_labelBMFontRenderer); _fntFileHasInit = true; setText(_stringValue); } @@ -99,7 +99,8 @@ void TextBMFont::setText(const std::string& value) return; } _labelBMFontRenderer->setString(value); - labelBMFontScaleChangedWithSize(); + updateContentSizeWithTextureSize(_labelBMFontRenderer->getContentSize()); + _labelBMFontRendererAdaptDirty = true; } const std::string TextBMFont::getStringValue() @@ -107,19 +108,22 @@ const std::string TextBMFont::getStringValue() return _stringValue; } -void TextBMFont::setAnchorPoint(const Point &pt) -{ - Widget::setAnchorPoint(pt); - _labelBMFontRenderer->setAnchorPoint(pt); -} - void TextBMFont::onSizeChanged() { Widget::onSizeChanged(); - labelBMFontScaleChangedWithSize(); + _labelBMFontRendererAdaptDirty = true; +} + +void TextBMFont::adaptRenderers() +{ + if (_labelBMFontRendererAdaptDirty) + { + labelBMFontScaleChangedWithSize(); + _labelBMFontRendererAdaptDirty = false; + } } -const Size& TextBMFont::getContentSize() const +const Size& TextBMFont::getVirtualRendererSize() const { return _labelBMFontRenderer->getContentSize(); } @@ -134,7 +138,6 @@ void TextBMFont::labelBMFontScaleChangedWithSize() if (_ignoreSize) { _labelBMFontRenderer->setScale(1.0f); - _size = _labelBMFontRenderer->getContentSize(); } else { @@ -149,6 +152,7 @@ void TextBMFont::labelBMFontScaleChangedWithSize() _labelBMFontRenderer->setScaleX(scaleX); _labelBMFontRenderer->setScaleY(scaleY); } + _labelBMFontRenderer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f); } std::string TextBMFont::getDescription() const diff --git a/cocos/ui/UITextBMFont.h b/cocos/ui/UITextBMFont.h index e41cbea7fc..aa82126516 100644 --- a/cocos/ui/UITextBMFont.h +++ b/cocos/ui/UITextBMFont.h @@ -66,8 +66,7 @@ public: /** get string value for labelbmfont*/ const std::string getStringValue(); - virtual void setAnchorPoint(const Point &pt) override; - virtual const Size& getContentSize() const override; + virtual const Size& getVirtualRendererSize() const override; virtual Node* getVirtualRenderer() override; /** * Returns the "class name" of widget. @@ -82,11 +81,13 @@ protected: void labelBMFontScaleChangedWithSize(); virtual Widget* createCloneInstance() override; virtual void copySpecialProperties(Widget* model) override; + virtual void adaptRenderers() override; protected: cocos2d::Label* _labelBMFontRenderer; bool _fntFileHasInit; std::string _fntFileName; std::string _stringValue; + bool _labelBMFontRendererAdaptDirty; }; } diff --git a/cocos/ui/UITextField.cpp b/cocos/ui/UITextField.cpp index b96ef54dae..5a1914595e 100644 --- a/cocos/ui/UITextField.cpp +++ b/cocos/ui/UITextField.cpp @@ -364,7 +364,8 @@ _touchHeight(0.0f), _useTouchArea(false), _textFieldEventListener(nullptr), _textFieldEventSelector(nullptr), -_passwordStyleText("") +_passwordStyleText(""), +_textFieldRendererAdaptDirty(true) { } @@ -514,14 +515,15 @@ void TextField::setText(const std::string& text) { _textFieldRenderer->setString(content); } - - textfieldRendererScaleChangedWithSize(); + _textFieldRendererAdaptDirty = true; + updateContentSizeWithTextureSize(_textFieldRenderer->getContentSize()); } void TextField::setPlaceHolder(const std::string& value) { _textFieldRenderer->setPlaceHolder(value); - textfieldRendererScaleChangedWithSize(); + _textFieldRendererAdaptDirty = true; + updateContentSizeWithTextureSize(_textFieldRenderer->getContentSize()); } const std::string& TextField::getPlaceHolder() @@ -532,7 +534,8 @@ const std::string& TextField::getPlaceHolder() void TextField::setFontSize(int size) { _textFieldRenderer->setSystemFontSize(size); - textfieldRendererScaleChangedWithSize(); + _textFieldRendererAdaptDirty = true; + updateContentSizeWithTextureSize(_textFieldRenderer->getContentSize()); } int TextField::getFontSize() @@ -543,7 +546,8 @@ int TextField::getFontSize() void TextField::setFontName(const std::string& name) { _textFieldRenderer->setSystemFontName(name); - textfieldRendererScaleChangedWithSize(); + _textFieldRendererAdaptDirty = true; + updateContentSizeWithTextureSize(_textFieldRenderer->getContentSize()); } const std::string& TextField::getFontName() @@ -634,14 +638,16 @@ void TextField::update(float dt) insertTextEvent(); setInsertText(false); - textfieldRendererScaleChangedWithSize(); + _textFieldRendererAdaptDirty = true; + updateContentSizeWithTextureSize(_textFieldRenderer->getContentSize()); } if (getDeleteBackward()) { deleteBackwardEvent(); setDeleteBackward(false); - textfieldRendererScaleChangedWithSize(); + _textFieldRendererAdaptDirty = true; + updateContentSizeWithTextureSize(_textFieldRenderer->getContentSize()); } } @@ -723,16 +729,19 @@ void TextField::addEventListenerTextField(Ref *target, SEL_TextFieldEvent seleco _textFieldEventSelector = selecor; } -void TextField::setAnchorPoint(const Point &pt) -{ - Widget::setAnchorPoint(pt); - _textFieldRenderer->setAnchorPoint(pt); -} - void TextField::onSizeChanged() { Widget::onSizeChanged(); - textfieldRendererScaleChangedWithSize(); + _textFieldRendererAdaptDirty = true; +} + +void TextField::adaptRenderers() +{ + if (_textFieldRendererAdaptDirty) + { + textfieldRendererScaleChangedWithSize(); + _textFieldRendererAdaptDirty = false; + } } void TextField::textfieldRendererScaleChangedWithSize() @@ -741,7 +750,6 @@ void TextField::textfieldRendererScaleChangedWithSize() { _textFieldRenderer->setDimensions(0,0); _textFieldRenderer->setScale(1.0f); - _size = getContentSize(); } else { @@ -757,9 +765,10 @@ void TextField::textfieldRendererScaleChangedWithSize() _textFieldRenderer->setScaleX(scaleX); _textFieldRenderer->setScaleY(scaleY); } + _textFieldRenderer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f); } -const Size& TextField::getContentSize() const +const Size& TextField::getVirtualRendererSize() const { return _textFieldRenderer->getContentSize(); } diff --git a/cocos/ui/UITextField.h b/cocos/ui/UITextField.h index 73e728cb8b..56733e06cd 100644 --- a/cocos/ui/UITextField.h +++ b/cocos/ui/UITextField.h @@ -145,15 +145,13 @@ public: bool getDeleteBackward(); void setDeleteBackward(bool deleteBackward); void addEventListenerTextField(Ref* target, SEL_TextFieldEvent selecor); - - virtual void setAnchorPoint(const Point &pt) override; /** * Returns the "class name" of widget. */ virtual std::string getDescription() const override; - virtual const Size& getContentSize() const override; + virtual const Size& getVirtualRendererSize() const override; virtual Node* getVirtualRenderer() override; void attachWithIME(); virtual void onEnter() override; @@ -178,6 +176,7 @@ protected: void textfieldRendererScaleChangedWithSize(); virtual Widget* createCloneInstance() override; virtual void copySpecialProperties(Widget* model) override; + virtual void adaptRenderers() override; protected: UICCTextField* _textFieldRenderer; @@ -189,6 +188,7 @@ protected: SEL_TextFieldEvent _textFieldEventSelector; std::string _passwordStyleText; + bool _textFieldRendererAdaptDirty; }; } diff --git a/cocos/ui/UIWidget.cpp b/cocos/ui/UIWidget.cpp index d35c7b38a2..ff9e5edf6d 100644 --- a/cocos/ui/UIWidget.cpp +++ b/cocos/ui/UIWidget.cpp @@ -112,6 +112,7 @@ void Widget::visit(Renderer *renderer, const kmMat4 &parentTransform, bool paren { if (_enabled) { + adaptRenderers(); ProtectedNode::visit(renderer, parentTransform, parentTransformUpdated); } } @@ -177,7 +178,7 @@ void Widget::setSize(const Size &size) _customSize = size; if (_ignoreSize) { - _size = getContentSize(); + _size = getVirtualRendererSize(); } else { @@ -228,7 +229,7 @@ void Widget::setSizePercent(const Point &percent) } if (_ignoreSize) { - _size = getContentSize(); + _size = getVirtualRendererSize(); } else { @@ -261,7 +262,7 @@ void Widget::updateSizeAndPosition(const cocos2d::Size &parentSize) { if (_ignoreSize) { - _size = getContentSize(); + _size = getVirtualRendererSize(); } else { @@ -285,7 +286,7 @@ void Widget::updateSizeAndPosition(const cocos2d::Size &parentSize) Size cSize = Size(parentSize.width * _sizePercent.x , parentSize.height * _sizePercent.y); if (_ignoreSize) { - _size = getContentSize(); + _size = getVirtualRendererSize(); } else { @@ -343,7 +344,7 @@ void Widget::ignoreContentAdaptWithSize(bool ignore) _ignoreSize = ignore; if (_ignoreSize) { - Size s = getContentSize(); + Size s = getVirtualRendererSize(); _size = s; } else @@ -375,7 +376,7 @@ const Point& Widget::getSizePercent() const Point Widget::getWorldPosition() { - return convertToWorldSpace(Point::ZERO); + return convertToWorldSpace(Point(_anchorPoint.x * _contentSize.width, _anchorPoint.y * _contentSize.height)); } Node* Widget::getVirtualRenderer() @@ -385,6 +386,7 @@ Node* Widget::getVirtualRenderer() void Widget::onSizeChanged() { + setContentSize(_size); for (auto& child : getChildren()) { Widget* widgetChild = dynamic_cast(child); @@ -395,9 +397,22 @@ void Widget::onSizeChanged() } } -const Size& Widget::getContentSize() const +const Size& Widget::getVirtualRendererSize() const { - return _size; + return _contentSize; +} + +void Widget::updateContentSizeWithTextureSize(const cocos2d::Size &size) +{ + if (_ignoreSize) + { + _size = size; + } + else + { + _size = _customSize; + } + onSizeChanged(); } void Widget::setTouchEnabled(bool enable) @@ -617,8 +632,9 @@ void Widget::addTouchEventListener(Ref *target, SEL_TouchEvent selector) bool Widget::hitTest(const Point &pt) { Point nsp = convertToNodeSpace(pt); - Rect bb = Rect(-_size.width * _anchorPoint.x, -_size.height * _anchorPoint.y, _size.width, _size.height); - if (nsp.x >= bb.origin.x && nsp.x <= bb.origin.x + bb.size.width && nsp.y >= bb.origin.y && nsp.y <= bb.origin.y + bb.size.height) + Rect bb; + bb.size = _contentSize; + if (bb.containsPoint(nsp)) { return true; } @@ -712,11 +728,6 @@ void Widget::setPositionPercent(const Point &percent) } } -void Widget::updateAnchorPoint() -{ - setAnchorPoint(getAnchorPoint()); -} - const Point& Widget::getPositionPercent() { return _positionPercent; diff --git a/cocos/ui/UIWidget.h b/cocos/ui/UIWidget.h index 0f2aa4d40c..c26eb0020d 100644 --- a/cocos/ui/UIWidget.h +++ b/cocos/ui/UIWidget.h @@ -501,12 +501,15 @@ public: */ virtual Node* getVirtualRenderer(); - /** - * Gets the content size of widget. - * - * Content size is widget's texture size. - */ - virtual const Size& getContentSize() const; +// /** +// * Gets the content size of widget. +// * +// * Content size is widget's texture size. +// */ +// virtual const Size& getContentSize() const; + virtual const Size& getVirtualRendererSize() const; + + /** * Returns the "class name" of widget. @@ -549,7 +552,6 @@ protected: void moveEvent(); void releaseUpEvent(); void cancelUpEvent(); - void updateAnchorPoint(); virtual void updateTextureColor(){}; virtual void updateTextureOpacity(){}; virtual void updateTextureRGBA(){}; @@ -563,6 +565,8 @@ protected: virtual void copySpecialProperties(Widget* model); virtual void copyClonedWidgetChildren(Widget* model); Widget* getWidgetParent(); + void updateContentSizeWithTextureSize(const Size& size); + virtual void adaptRenderers(){}; protected: bool _enabled; ///< Highest control of widget bool _bright; ///< is this widget bright diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp index 725a96ce9f..0539c64528 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp @@ -40,7 +40,7 @@ bool UIButtonTest::init() "cocosui/animationbuttonpressed.png"); button->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); button->addTouchEventListener(this, toucheventselector(UIButtonTest::touchEvent)); - _uiLayer->addChild(button); + _uiLayer->addChild(button); return true; } @@ -109,7 +109,7 @@ bool UIButtonTest_Scale9::init() // open scale9 render button->setScale9Enabled(true); button->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); - button->setSize(Size(150, button->getContentSize().height * 1.5f)); + button->setSize(Size(150, 70)); button->addTouchEventListener(this, toucheventselector(UIButtonTest_Scale9::touchEvent)); _uiLayer->addChild(button); diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp index 9445db0c9a..885ef2bfff 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp @@ -21,7 +21,7 @@ bool UIImageViewTest::init() // Create the imageview ImageView* imageView = ImageView::create("cocosui/ccicon.png"); imageView->setPosition(Point(widgetSize.width / 2.0f, - widgetSize.height / 2.0f + imageView->getSize().height / 4.0f)); + widgetSize.height / 2.0f)); _uiLayer->addChild(imageView); @@ -53,7 +53,7 @@ bool UIImageViewTest_Scale9::init() imageView->setScale9Enabled(true); imageView->setSize(Size(300, 115)); imageView->setPosition(Point(widgetSize.width / 2.0f, - widgetSize.height / 2.0f + imageView->getSize().height / 4.0f)); + widgetSize.height / 2.0f)); _uiLayer->addChild(imageView); diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp index 89d7347866..efab080cb6 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp @@ -53,7 +53,7 @@ bool UILayoutTest::init() Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); - button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height)); + button_scale9->setSize(Size(100.0f, button_scale9->getVirtualRendererSize().height)); button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f, button_scale9->getSize().height / 2.0f)); @@ -118,7 +118,7 @@ bool UILayoutTest_Color::init() Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); - button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height)); + button_scale9->setSize(Size(100.0f, button_scale9->getVirtualRendererSize().height)); button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f, button_scale9->getSize().height / 2.0f)); @@ -182,7 +182,7 @@ bool UILayoutTest_Gradient::init() Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); - button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height)); + button_scale9->setSize(Size(100.0f, button_scale9->getVirtualRendererSize().height)); button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f, button_scale9->getSize().height / 2.0f)); @@ -243,7 +243,7 @@ bool UILayoutTest_BackGroundImage::init() Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); - button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height)); + button_scale9->setSize(Size(100.0f, button_scale9->getVirtualRendererSize().height)); button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f, button_scale9->getSize().height / 2.0f)); @@ -305,7 +305,7 @@ bool UILayoutTest_BackGroundImage_Scale9::init() Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); - button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height)); + button_scale9->setSize(Size(100.0f, button_scale9->getVirtualRendererSize().height)); button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f, button_scale9->getSize().height / 2.0f)); layout->addChild(button_scale9); @@ -376,7 +376,7 @@ bool UILayoutTest_Layout_Linear_Vertical::init() Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); - button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height)); + button_scale9->setSize(Size(100.0f, button_scale9->getVirtualRendererSize().height)); layout->addChild(button_scale9); LinearLayoutParameter* lp3 = LinearLayoutParameter::create(); @@ -450,7 +450,7 @@ bool UILayoutTest_Layout_Linear_Horizontal::init() Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); - button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height)); + button_scale9->setSize(Size(100.0f, button_scale9->getVirtualRendererSize().height)); layout->addChild(button_scale9); LinearLayoutParameter* lp3 = LinearLayoutParameter::create(); diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp index b728db0634..892b4a4b3c 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp @@ -193,7 +193,7 @@ bool UILoadingBarTest_Left_Scale9::init() loadingBar->setTag(0); loadingBar->setScale9Enabled(true); loadingBar->setCapInsets(Rect(0, 0, 0, 0)); - loadingBar->setSize(Size(300, loadingBar->getContentSize().height)); + loadingBar->setSize(Size(300, 13)); loadingBar->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f)); @@ -275,7 +275,7 @@ bool UILoadingBarTest_Right_Scale9::init() loadingBar->setTag(0); loadingBar->setScale9Enabled(true); loadingBar->setCapInsets(Rect(0, 0, 0, 0)); - loadingBar->setSize(Size(300, loadingBar->getContentSize().height)); + loadingBar->setSize(Size(300, 13)); loadingBar->setDirection(LoadingBarTypeRight); loadingBar->setPosition(Point(widgetSize.width / 2.0f, diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp index 40fe24d6d3..3daf1fbc37 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp @@ -65,7 +65,7 @@ bool UIScrollViewTest_Vertical::init() Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); - button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height)); + button_scale9->setSize(Size(100.0f, button_scale9->getVirtualRendererSize().height)); button_scale9->setPosition(Point(innerWidth / 2.0f, titleButton->getBottomInParent() - titleButton->getSize().height)); scrollView->addChild(button_scale9); @@ -143,7 +143,7 @@ bool UIScrollViewTest_Horizontal::init() Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); - button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height)); + button_scale9->setSize(Size(100.0f, button_scale9->getVirtualRendererSize().height)); button_scale9->setPosition(Point(titleButton->getRightInParent() + titleButton->getSize().width / 2.0f, titleButton->getBottomInParent() - titleButton->getSize().height / 2.0f)); scrollView->addChild(button_scale9);