Merge branch 'develop' of https://github.com/cocos2d/cocos2d-x into devRichText

This commit is contained in:
samuele3hu 2014-04-18 11:55:30 +08:00
commit 7e81f32016
44 changed files with 376 additions and 293 deletions

View File

@ -1109,6 +1109,10 @@ Widget* WidgetPropertiesReader0300::widgetFromJsonDictionary(const rapidjson::Va
} }
else else
{ {
if (!dynamic_cast<Layout*>(widget))
{
child->setPosition(Point(child->getPositionX() + widget->getSize().width / 2.0f, child->getPositionY() + widget->getSize().height / 2.0f));
}
widget->addChild(child); widget->addChild(child);
} }
} }

View File

@ -137,11 +137,6 @@
-- @param self -- @param self
-- @return Ref#Ref ret (return value: cc.Ref) -- @return Ref#Ref ret (return value: cc.Ref)
--------------------------------
-- @function [parent=#Button] setAnchorPoint
-- @param self
-- @param #point_table point
-------------------------------- --------------------------------
-- @function [parent=#Button] getVirtualRenderer -- @function [parent=#Button] getVirtualRenderer
-- @param self -- @param self
@ -153,7 +148,7 @@
-- @return string#string ret (return value: string) -- @return string#string ret (return value: string)
-------------------------------- --------------------------------
-- @function [parent=#Button] getContentSize -- @function [parent=#Button] getVirtualRendererSize
-- @param self -- @param self
-- @return size_table#size_table ret (return value: size_table) -- @return size_table#size_table ret (return value: size_table)

View File

@ -73,11 +73,6 @@
-- @param self -- @param self
-- @return Ref#Ref ret (return value: cc.Ref) -- @return Ref#Ref ret (return value: cc.Ref)
--------------------------------
-- @function [parent=#CheckBox] setAnchorPoint
-- @param self
-- @param #point_table point
-------------------------------- --------------------------------
-- @function [parent=#CheckBox] getVirtualRenderer -- @function [parent=#CheckBox] getVirtualRenderer
-- @param self -- @param self
@ -89,7 +84,7 @@
-- @return string#string ret (return value: string) -- @return string#string ret (return value: string)
-------------------------------- --------------------------------
-- @function [parent=#CheckBox] getContentSize -- @function [parent=#CheckBox] getVirtualRendererSize
-- @param self -- @param self
-- @return size_table#size_table ret (return value: size_table) -- @return size_table#size_table ret (return value: size_table)

View File

@ -50,11 +50,6 @@
-- @param self -- @param self
-- @return Ref#Ref ret (return value: cc.Ref) -- @return Ref#Ref ret (return value: cc.Ref)
--------------------------------
-- @function [parent=#ImageView] setAnchorPoint
-- @param self
-- @param #point_table point
-------------------------------- --------------------------------
-- @function [parent=#ImageView] getVirtualRenderer -- @function [parent=#ImageView] getVirtualRenderer
-- @param self -- @param self
@ -66,7 +61,7 @@
-- @return string#string ret (return value: string) -- @return string#string ret (return value: string)
-------------------------------- --------------------------------
-- @function [parent=#ImageView] getContentSize -- @function [parent=#ImageView] getVirtualRendererSize
-- @param self -- @param self
-- @return size_table#size_table ret (return value: size_table) -- @return size_table#size_table ret (return value: size_table)

View File

@ -137,12 +137,6 @@
-- @param self -- @param self
-- @return color3B_table#color3B_table ret (return value: color3B_table) -- @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 -- @function [parent=#Layout] setBackGroundImageScale9Enabled
-- @param self -- @param self

View File

@ -76,7 +76,7 @@
-- @return string#string ret (return value: string) -- @return string#string ret (return value: string)
-------------------------------- --------------------------------
-- @function [parent=#LoadingBar] getContentSize -- @function [parent=#LoadingBar] getVirtualRendererSize
-- @param self -- @param self
-- @return size_table#size_table ret (return value: size_table) -- @return size_table#size_table ret (return value: size_table)

View File

@ -19,10 +19,6 @@
-- @param self -- @param self
-- @param #ccui.RichElement richelement -- @param #ccui.RichElement richelement
--------------------------------
-- @function [parent=#RichText] formatText
-- @param self
-------------------------------- --------------------------------
-- @function [parent=#RichText] ignoreContentAdaptWithSize -- @function [parent=#RichText] ignoreContentAdaptWithSize
-- @param self -- @param self
@ -34,9 +30,8 @@
-- @param #float float -- @param #float float
-------------------------------- --------------------------------
-- @function [parent=#RichText] getContentSize -- @function [parent=#RichText] formatText
-- @param self -- @param self
-- @return size_table#size_table ret (return value: size_table)
-------------------------------- --------------------------------
-- overload function: removeElement(ccui.RichElement) -- overload function: removeElement(ccui.RichElement)
@ -57,6 +52,11 @@
-- @param self -- @param self
-- @return string#string ret (return value: string) -- @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 -- @function [parent=#RichText] RichText
-- @param self -- @param self

View File

@ -118,7 +118,7 @@
-- @return bool#bool ret (return value: bool) -- @return bool#bool ret (return value: bool)
-------------------------------- --------------------------------
-- @function [parent=#Slider] getContentSize -- @function [parent=#Slider] getVirtualRendererSize
-- @param self -- @param self
-- @return size_table#size_table ret (return value: size_table) -- @return size_table#size_table ret (return value: size_table)

View File

@ -95,11 +95,6 @@
-- @param self -- @param self
-- @return Ref#Ref ret (return value: cc.Ref) -- @return Ref#Ref ret (return value: cc.Ref)
--------------------------------
-- @function [parent=#Text] setAnchorPoint
-- @param self
-- @param #point_table point
-------------------------------- --------------------------------
-- @function [parent=#Text] getVirtualRenderer -- @function [parent=#Text] getVirtualRenderer
-- @param self -- @param self
@ -111,7 +106,7 @@
-- @return string#string ret (return value: string) -- @return string#string ret (return value: string)
-------------------------------- --------------------------------
-- @function [parent=#Text] getContentSize -- @function [parent=#Text] getVirtualRendererSize
-- @param self -- @param self
-- @return size_table#size_table ret (return value: size_table) -- @return size_table#size_table ret (return value: size_table)

View File

@ -17,6 +17,10 @@
-- @param self -- @param self
-- @return string#string ret (return value: string) -- @return string#string ret (return value: string)
--------------------------------
-- @function [parent=#TextAtlas] adaptRenderers
-- @param self
-------------------------------- --------------------------------
-- @function [parent=#TextAtlas] setStringValue -- @function [parent=#TextAtlas] setStringValue
-- @param self -- @param self
@ -41,11 +45,6 @@
-- @param self -- @param self
-- @return Ref#Ref ret (return value: cc.Ref) -- @return Ref#Ref ret (return value: cc.Ref)
--------------------------------
-- @function [parent=#TextAtlas] setAnchorPoint
-- @param self
-- @param #point_table point
-------------------------------- --------------------------------
-- @function [parent=#TextAtlas] getVirtualRenderer -- @function [parent=#TextAtlas] getVirtualRenderer
-- @param self -- @param self
@ -57,7 +56,7 @@
-- @return string#string ret (return value: string) -- @return string#string ret (return value: string)
-------------------------------- --------------------------------
-- @function [parent=#TextAtlas] getContentSize -- @function [parent=#TextAtlas] getVirtualRendererSize
-- @param self -- @param self
-- @return size_table#size_table ret (return value: size_table) -- @return size_table#size_table ret (return value: size_table)

View File

@ -34,11 +34,6 @@
-- @param self -- @param self
-- @return Ref#Ref ret (return value: cc.Ref) -- @return Ref#Ref ret (return value: cc.Ref)
--------------------------------
-- @function [parent=#TextBMFont] setAnchorPoint
-- @param self
-- @param #point_table point
-------------------------------- --------------------------------
-- @function [parent=#TextBMFont] getVirtualRenderer -- @function [parent=#TextBMFont] getVirtualRenderer
-- @param self -- @param self
@ -50,7 +45,7 @@
-- @return string#string ret (return value: string) -- @return string#string ret (return value: string)
-------------------------------- --------------------------------
-- @function [parent=#TextBMFont] getContentSize -- @function [parent=#TextBMFont] getVirtualRendererSize
-- @param self -- @param self
-- @return size_table#size_table ret (return value: size_table) -- @return size_table#size_table ret (return value: size_table)

View File

@ -184,11 +184,6 @@
-- @param self -- @param self
-- @return Ref#Ref ret (return value: cc.Ref) -- @return Ref#Ref ret (return value: cc.Ref)
--------------------------------
-- @function [parent=#TextField] setAnchorPoint
-- @param self
-- @param #point_table point
-------------------------------- --------------------------------
-- @function [parent=#TextField] getVirtualRenderer -- @function [parent=#TextField] getVirtualRenderer
-- @param self -- @param self
@ -205,7 +200,7 @@
-- @param #float float -- @param #float float
-------------------------------- --------------------------------
-- @function [parent=#TextField] getContentSize -- @function [parent=#TextField] getVirtualRendererSize
-- @param self -- @param self
-- @return size_table#size_table ret (return value: size_table) -- @return size_table#size_table ret (return value: size_table)

View File

@ -63,11 +63,6 @@
-- @param self -- @param self
-- @return float#float ret (return value: float) -- @return float#float ret (return value: float)
--------------------------------
-- @function [parent=#Widget] getActionTag
-- @param self
-- @return int#int ret (return value: int)
-------------------------------- --------------------------------
-- @function [parent=#Widget] getLayoutParameter -- @function [parent=#Widget] getLayoutParameter
-- @param self -- @param self
@ -100,15 +95,20 @@
-- @param self -- @param self
-- @return bool#bool ret (return value: bool) -- @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 -- @function [parent=#Widget] isTouchEnabled
-- @param self -- @param self
-- @return bool#bool ret (return value: bool) -- @return bool#bool ret (return value: bool)
-------------------------------- --------------------------------
-- @function [parent=#Widget] getContentSize -- @function [parent=#Widget] getActionTag
-- @param self -- @param self
-- @return size_table#size_table ret (return value: size_table) -- @return int#int ret (return value: int)
-------------------------------- --------------------------------
-- @function [parent=#Widget] getWorldPosition -- @function [parent=#Widget] getWorldPosition

View File

@ -1 +1 @@
a1f2ceee65fe7b4bdae2cd2c32ff84fa332a6b50 088e9951d4f001122370379060141d0e98b5a4d8

View File

@ -365,7 +365,6 @@ int register_all_cocos2dx_ui(lua_State* tolua_S);
#endif // __cocos2dx_ui_h__ #endif // __cocos2dx_ui_h__

View File

@ -63,7 +63,10 @@ _pressedTextureScaleXInSize(1.0f),
_pressedTextureScaleYInSize(1.0f), _pressedTextureScaleYInSize(1.0f),
_normalTextureLoaded(false), _normalTextureLoaded(false),
_pressedTextureLoaded(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(); _normalTextureSize = _buttonNormalRenderer->getContentSize();
normalTextureScaleChangedWithSize();
updateAnchorPoint();
updateFlippedX(); updateFlippedX();
updateFlippedY(); updateFlippedY();
updateRGBAToRenderer(_buttonNormalRenderer); updateRGBAToRenderer(_buttonNormalRenderer);
updateContentSizeWithTextureSize(_normalTextureSize);
_normalTextureLoaded = true; _normalTextureLoaded = true;
_normalTextureAdaptDirty = true;
} }
void Button::loadTexturePressed(const std::string& selected,TextureResType texType) 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(); _pressedTextureSize = _buttonClickedRenderer->getContentSize();
pressedTextureScaleChangedWithSize();
updateAnchorPoint();
updateFlippedX(); updateFlippedX();
updateFlippedY(); updateFlippedY();
updateRGBAToRenderer(_buttonDisableRenderer); updateRGBAToRenderer(_buttonDisableRenderer);
_pressedTextureLoaded = true; _pressedTextureLoaded = true;
_pressedTextureAdaptDirty = true;
} }
void Button::loadTextureDisabled(const std::string& disabled,TextureResType texType) 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(); _disabledTextureSize = _buttonDisableRenderer->getContentSize();
disabledTextureScaleChangedWithSize();
updateAnchorPoint();
updateFlippedX(); updateFlippedX();
updateFlippedY(); updateFlippedY();
updateRGBAToRenderer(_buttonDisableRenderer); updateRGBAToRenderer(_buttonDisableRenderer);
_disabledTextureLoaded = true; _disabledTextureLoaded = true;
_disabledTextureAdaptDirty = true;
} }
void Button::setCapInsets(const Rect &capInsets) void Button::setCapInsets(const Rect &capInsets)
@ -517,24 +518,40 @@ void Button::updateFlippedY()
} }
} }
void Button::setAnchorPoint(const Point &pt) void Button::updateTitleLocation()
{ {
Widget::setAnchorPoint(pt); _titleRenderer->setPosition(Point(_contentSize.width * 0.5f, _contentSize.height * 0.5f));
_buttonNormalRenderer->setAnchorPoint(pt);
_buttonClickedRenderer->setAnchorPoint(pt);
_buttonDisableRenderer->setAnchorPoint(pt);
_titleRenderer->setPosition(Point(_size.width*(0.5f-_anchorPoint.x), _size.height*(0.5f-_anchorPoint.y)));
} }
void Button::onSizeChanged() void Button::onSizeChanged()
{ {
Widget::onSizeChanged(); Widget::onSizeChanged();
normalTextureScaleChangedWithSize(); updateTitleLocation();
pressedTextureScaleChangedWithSize(); _normalTextureAdaptDirty = true;
disabledTextureScaleChangedWithSize(); _pressedTextureAdaptDirty = true;
_disabledTextureAdaptDirty = true;
} }
const Size& Button::getContentSize() const void Button::adaptRenderers()
{
if (_normalTextureAdaptDirty)
{
normalTextureScaleChangedWithSize();
_normalTextureAdaptDirty = false;
}
if (_pressedTextureAdaptDirty)
{
pressedTextureScaleChangedWithSize();
_pressedTextureAdaptDirty = false;
}
if (_disabledTextureAdaptDirty)
{
disabledTextureScaleChangedWithSize();
_disabledTextureAdaptDirty = false;
}
}
const Size& Button::getVirtualRendererSize() const
{ {
return _normalTextureSize; return _normalTextureSize;
} }
@ -567,7 +584,6 @@ void Button::normalTextureScaleChangedWithSize()
{ {
_buttonNormalRenderer->setScale(1.0f); _buttonNormalRenderer->setScale(1.0f);
_normalTextureScaleXInSize = _normalTextureScaleYInSize = 1.0f; _normalTextureScaleXInSize = _normalTextureScaleYInSize = 1.0f;
_size = _normalTextureSize;
} }
} }
else else
@ -593,6 +609,7 @@ void Button::normalTextureScaleChangedWithSize()
_normalTextureScaleYInSize = scaleY; _normalTextureScaleYInSize = scaleY;
} }
} }
_buttonNormalRenderer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f);
} }
void Button::pressedTextureScaleChangedWithSize() void Button::pressedTextureScaleChangedWithSize()
@ -628,6 +645,7 @@ void Button::pressedTextureScaleChangedWithSize()
_pressedTextureScaleYInSize = scaleY; _pressedTextureScaleYInSize = scaleY;
} }
} }
_buttonClickedRenderer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f);
} }
void Button::disabledTextureScaleChangedWithSize() void Button::disabledTextureScaleChangedWithSize()
@ -659,6 +677,7 @@ void Button::disabledTextureScaleChangedWithSize()
_buttonDisableRenderer->setScaleY(scaleY); _buttonDisableRenderer->setScaleY(scaleY);
} }
} }
_buttonDisableRenderer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f);
} }
void Button::setPressedActionEnabled(bool enabled) void Button::setPressedActionEnabled(bool enabled)

View File

@ -146,9 +146,6 @@ public:
const Rect& getCapInsetsDisabledRenderer(); const Rect& getCapInsetsDisabledRenderer();
//override "setAnchorPoint" of widget.
virtual void setAnchorPoint(const Point &pt) override;
/** /**
* Sets if button is using scale9 renderer. * Sets if button is using scale9 renderer.
* *
@ -168,8 +165,8 @@ public:
//override "ignoreContentAdaptWithSize" method of widget. //override "ignoreContentAdaptWithSize" method of widget.
virtual void ignoreContentAdaptWithSize(bool ignore) override; virtual void ignoreContentAdaptWithSize(bool ignore) override;
//override "getContentSize" method of widget. //override "getVirtualRendererSize" method of widget.
virtual const Size& getContentSize() const override; virtual const Size& getVirtualRendererSize() const override;
//override "getVirtualRenderer" method of widget. //override "getVirtualRenderer" method of widget.
virtual Node* getVirtualRenderer() override; virtual Node* getVirtualRenderer() override;
@ -212,6 +209,8 @@ protected:
void disabledTextureScaleChangedWithSize(); void disabledTextureScaleChangedWithSize();
virtual Widget* createCloneInstance() override; virtual Widget* createCloneInstance() override;
virtual void copySpecialProperties(Widget* model) override; virtual void copySpecialProperties(Widget* model) override;
virtual void adaptRenderers() override;
void updateTitleLocation();
protected: protected:
Node* _buttonNormalRenderer; Node* _buttonNormalRenderer;
Node* _buttonClickedRenderer; Node* _buttonClickedRenderer;
@ -240,6 +239,9 @@ protected:
bool _normalTextureLoaded; bool _normalTextureLoaded;
bool _pressedTextureLoaded; bool _pressedTextureLoaded;
bool _disabledTextureLoaded; bool _disabledTextureLoaded;
bool _normalTextureAdaptDirty;
bool _pressedTextureAdaptDirty;
bool _disabledTextureAdaptDirty;
}; };
} }

View File

@ -54,7 +54,12 @@ _backGroundFileName(""),
_backGroundSelectedFileName(""), _backGroundSelectedFileName(""),
_frontCrossFileName(""), _frontCrossFileName(""),
_backGroundDisabledFileName(""), _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: default:
break; break;
} }
backGroundTextureScaleChangedWithSize();
updateAnchorPoint();
updateFlippedX(); updateFlippedX();
updateFlippedY(); updateFlippedY();
updateRGBAToRenderer(_backGroundBoxRenderer); updateRGBAToRenderer(_backGroundBoxRenderer);
updateContentSizeWithTextureSize(_backGroundBoxRenderer->getContentSize());
_backGroundBoxRendererAdaptDirty = true;
} }
void CheckBox::loadTextureBackGroundSelected(const std::string& backGroundSelected,TextureResType texType) void CheckBox::loadTextureBackGroundSelected(const std::string& backGroundSelected,TextureResType texType)
@ -204,11 +209,10 @@ void CheckBox::loadTextureBackGroundSelected(const std::string& backGroundSelect
default: default:
break; break;
} }
backGroundSelectedTextureScaleChangedWithSize();
updateAnchorPoint();
updateFlippedX(); updateFlippedX();
updateFlippedY(); updateFlippedY();
updateRGBAToRenderer(_backGroundSelectedBoxRenderer); updateRGBAToRenderer(_backGroundSelectedBoxRenderer);
_backGroundSelectedBoxRendererAdaptDirty = true;
} }
void CheckBox::loadTextureFrontCross(const std::string& cross,TextureResType texType) void CheckBox::loadTextureFrontCross(const std::string& cross,TextureResType texType)
@ -230,11 +234,10 @@ void CheckBox::loadTextureFrontCross(const std::string& cross,TextureResType tex
default: default:
break; break;
} }
frontCrossTextureScaleChangedWithSize();
updateAnchorPoint();
updateFlippedX(); updateFlippedX();
updateFlippedY(); updateFlippedY();
updateRGBAToRenderer(_frontCrossRenderer); updateRGBAToRenderer(_frontCrossRenderer);
_frontCrossRendererAdaptDirty = true;
} }
void CheckBox::loadTextureBackGroundDisabled(const std::string& backGroundDisabled,TextureResType texType) void CheckBox::loadTextureBackGroundDisabled(const std::string& backGroundDisabled,TextureResType texType)
@ -256,11 +259,10 @@ void CheckBox::loadTextureBackGroundDisabled(const std::string& backGroundDisabl
default: default:
break; break;
} }
backGroundDisabledTextureScaleChangedWithSize();
updateAnchorPoint();
updateFlippedX(); updateFlippedX();
updateFlippedY(); updateFlippedY();
updateRGBAToRenderer(_backGroundBoxDisabledRenderer); updateRGBAToRenderer(_backGroundBoxDisabledRenderer);
_backGroundBoxDisabledRendererAdaptDirty = true;
} }
void CheckBox::loadTextureFrontCrossDisabled(const std::string& frontCrossDisabled,TextureResType texType) void CheckBox::loadTextureFrontCrossDisabled(const std::string& frontCrossDisabled,TextureResType texType)
@ -282,11 +284,10 @@ void CheckBox::loadTextureFrontCrossDisabled(const std::string& frontCrossDisabl
default: default:
break; break;
} }
frontCrossDisabledTextureScaleChangedWithSize();
updateAnchorPoint();
updateFlippedX(); updateFlippedX();
updateFlippedY(); updateFlippedY();
updateRGBAToRenderer(_frontCrossDisabledRenderer); updateRGBAToRenderer(_frontCrossDisabledRenderer);
_frontCrossDisabledRendererAdaptDirty = true;
} }
void CheckBox::onTouchEnded(Touch *touch, Event *unusedEvent) void CheckBox::onTouchEnded(Touch *touch, Event *unusedEvent)
@ -396,27 +397,46 @@ void CheckBox::updateFlippedY()
_frontCrossDisabledRenderer->setFlippedY(_flippedY); _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() void CheckBox::onSizeChanged()
{ {
Widget::onSizeChanged(); Widget::onSizeChanged();
backGroundTextureScaleChangedWithSize(); _backGroundBoxRendererAdaptDirty = true;
backGroundSelectedTextureScaleChangedWithSize(); _backGroundSelectedBoxRendererAdaptDirty = true;
frontCrossTextureScaleChangedWithSize(); _frontCrossRendererAdaptDirty = true;
backGroundDisabledTextureScaleChangedWithSize(); _backGroundBoxDisabledRendererAdaptDirty = true;
frontCrossDisabledTextureScaleChangedWithSize(); _frontCrossDisabledRendererAdaptDirty = true;
} }
const Size& CheckBox::getContentSize() const 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::getVirtualRendererSize() const
{ {
return _backGroundBoxRenderer->getContentSize(); return _backGroundBoxRenderer->getContentSize();
} }
@ -431,7 +451,6 @@ void CheckBox::backGroundTextureScaleChangedWithSize()
if (_ignoreSize) if (_ignoreSize)
{ {
_backGroundBoxRenderer->setScale(1.0f); _backGroundBoxRenderer->setScale(1.0f);
_size = _backGroundBoxRenderer->getContentSize();
} }
else else
{ {
@ -446,6 +465,7 @@ void CheckBox::backGroundTextureScaleChangedWithSize()
_backGroundBoxRenderer->setScaleX(scaleX); _backGroundBoxRenderer->setScaleX(scaleX);
_backGroundBoxRenderer->setScaleY(scaleY); _backGroundBoxRenderer->setScaleY(scaleY);
} }
_backGroundBoxRenderer->setPosition(Point(_contentSize.width / 2, _contentSize.height / 2));
} }
void CheckBox::backGroundSelectedTextureScaleChangedWithSize() void CheckBox::backGroundSelectedTextureScaleChangedWithSize()
@ -467,6 +487,7 @@ void CheckBox::backGroundSelectedTextureScaleChangedWithSize()
_backGroundSelectedBoxRenderer->setScaleX(scaleX); _backGroundSelectedBoxRenderer->setScaleX(scaleX);
_backGroundSelectedBoxRenderer->setScaleY(scaleY); _backGroundSelectedBoxRenderer->setScaleY(scaleY);
} }
_backGroundSelectedBoxRenderer->setPosition(Point(_contentSize.width / 2, _contentSize.height / 2));
} }
void CheckBox::frontCrossTextureScaleChangedWithSize() void CheckBox::frontCrossTextureScaleChangedWithSize()
@ -488,6 +509,7 @@ void CheckBox::frontCrossTextureScaleChangedWithSize()
_frontCrossRenderer->setScaleX(scaleX); _frontCrossRenderer->setScaleX(scaleX);
_frontCrossRenderer->setScaleY(scaleY); _frontCrossRenderer->setScaleY(scaleY);
} }
_frontCrossRenderer->setPosition(Point(_contentSize.width / 2, _contentSize.height / 2));
} }
void CheckBox::backGroundDisabledTextureScaleChangedWithSize() void CheckBox::backGroundDisabledTextureScaleChangedWithSize()
@ -509,6 +531,7 @@ void CheckBox::backGroundDisabledTextureScaleChangedWithSize()
_backGroundBoxDisabledRenderer->setScaleX(scaleX); _backGroundBoxDisabledRenderer->setScaleX(scaleX);
_backGroundBoxDisabledRenderer->setScaleY(scaleY); _backGroundBoxDisabledRenderer->setScaleY(scaleY);
} }
_backGroundBoxDisabledRenderer->setPosition(Point(_contentSize.width / 2, _contentSize.height / 2));
} }
void CheckBox::frontCrossDisabledTextureScaleChangedWithSize() void CheckBox::frontCrossDisabledTextureScaleChangedWithSize()
@ -530,6 +553,7 @@ void CheckBox::frontCrossDisabledTextureScaleChangedWithSize()
_frontCrossDisabledRenderer->setScaleX(scaleX); _frontCrossDisabledRenderer->setScaleX(scaleX);
_frontCrossDisabledRenderer->setScaleY(scaleY); _frontCrossDisabledRenderer->setScaleY(scaleY);
} }
_frontCrossDisabledRenderer->setPosition(Point(_contentSize.width / 2, _contentSize.height / 2));
} }
std::string CheckBox::getDescription() const std::string CheckBox::getDescription() const

View File

@ -164,8 +164,6 @@ public:
*/ */
bool getSelectedState(); 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. //add a call back function would called when checkbox is selected or unselected.
void addEventListenerCheckBox(Ref* target,SEL_SelectedStateEvent selector); void addEventListenerCheckBox(Ref* target,SEL_SelectedStateEvent selector);
@ -173,8 +171,8 @@ public:
//override "onTouchEnded" method of widget. //override "onTouchEnded" method of widget.
virtual void onTouchEnded(Touch *touch, Event *unusedEvent); virtual void onTouchEnded(Touch *touch, Event *unusedEvent);
//override "getContentSize" method of widget. //override "getVirtualRendererSize" method of widget.
virtual const Size& getContentSize() const override; virtual const Size& getVirtualRendererSize() const override;
//override "getVirtualRenderer" method of widget. //override "getVirtualRenderer" method of widget.
virtual Node* getVirtualRenderer() override; virtual Node* getVirtualRenderer() override;
@ -213,6 +211,7 @@ protected:
void frontCrossDisabledTextureScaleChangedWithSize(); void frontCrossDisabledTextureScaleChangedWithSize();
virtual Widget* createCloneInstance() override; virtual Widget* createCloneInstance() override;
virtual void copySpecialProperties(Widget* model) override; virtual void copySpecialProperties(Widget* model) override;
virtual void adaptRenderers() override;
protected: protected:
Sprite* _backGroundBoxRenderer; Sprite* _backGroundBoxRenderer;
Sprite* _backGroundSelectedBoxRenderer; Sprite* _backGroundSelectedBoxRenderer;
@ -235,6 +234,12 @@ protected:
std::string _frontCrossFileName; std::string _frontCrossFileName;
std::string _backGroundDisabledFileName; std::string _backGroundDisabledFileName;
std::string _frontCrossDisabledFileName; std::string _frontCrossDisabledFileName;
bool _backGroundBoxRendererAdaptDirty;
bool _backGroundSelectedBoxRendererAdaptDirty;
bool _frontCrossRendererAdaptDirty;
bool _backGroundBoxDisabledRendererAdaptDirty;
bool _frontCrossDisabledRendererAdaptDirty;
}; };
} }

View File

@ -44,7 +44,8 @@ _capInsets(Rect::ZERO),
_imageRenderer(nullptr), _imageRenderer(nullptr),
_textureFile(""), _textureFile(""),
_imageTexType(UI_TEX_TYPE_LOCAL), _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; break;
} }
_imageTextureSize = _imageRenderer->getContentSize(); _imageTextureSize = _imageRenderer->getContentSize();
imageTextureScaleChangedWithSize();
updateAnchorPoint();
updateFlippedX(); updateFlippedX();
updateFlippedY(); updateFlippedY();
updateRGBAToRenderer(_imageRenderer); updateRGBAToRenderer(_imageRenderer);
updateContentSizeWithTextureSize(_imageTextureSize);
_imageRendererAdaptDirty = true;
} }
void ImageView::setTextureRect(const Rect &rect) void ImageView::setTextureRect(const Rect &rect)
@ -258,19 +259,22 @@ const Rect& ImageView::getCapInsets()
return _capInsets; return _capInsets;
} }
void ImageView::setAnchorPoint(const Point &pt)
{
Widget::setAnchorPoint(pt);
_imageRenderer->setAnchorPoint(pt);
}
void ImageView::onSizeChanged() void ImageView::onSizeChanged()
{ {
Widget::onSizeChanged(); Widget::onSizeChanged();
imageTextureScaleChangedWithSize(); _imageRendererAdaptDirty = true;
} }
const Size& ImageView::getContentSize() const void ImageView::adaptRenderers()
{
if (_imageRendererAdaptDirty)
{
imageTextureScaleChangedWithSize();
_imageRendererAdaptDirty = false;
}
}
const Size& ImageView::getVirtualRendererSize() const
{ {
return _imageTextureSize; return _imageTextureSize;
} }
@ -287,7 +291,6 @@ void ImageView::imageTextureScaleChangedWithSize()
if (!_scale9Enabled) if (!_scale9Enabled)
{ {
_imageRenderer->setScale(1.0f); _imageRenderer->setScale(1.0f);
_size = _imageTextureSize;
} }
} }
else else
@ -310,6 +313,7 @@ void ImageView::imageTextureScaleChangedWithSize()
_imageRenderer->setScaleY(scaleY); _imageRenderer->setScaleY(scaleY);
} }
} }
_imageRenderer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f);
} }
std::string ImageView::getDescription() const std::string ImageView::getDescription() const

View File

@ -99,9 +99,6 @@ public:
const Rect& getCapInsets(); const Rect& getCapInsets();
//override "setAnchorPoint" method of widget.
virtual void setAnchorPoint(const Point &pt) override;
//override "ignoreContentAdaptWithSize" method of widget. //override "ignoreContentAdaptWithSize" method of widget.
virtual void ignoreContentAdaptWithSize(bool ignore) override; virtual void ignoreContentAdaptWithSize(bool ignore) override;
@ -110,7 +107,7 @@ public:
*/ */
virtual std::string getDescription() const override; virtual std::string getDescription() const override;
virtual const Size& getContentSize() const override; virtual const Size& getVirtualRendererSize() const override;
virtual Node* getVirtualRenderer() override; virtual Node* getVirtualRenderer() override;
CC_CONSTRUCTOR_ACCESS: CC_CONSTRUCTOR_ACCESS:
@ -129,6 +126,7 @@ protected:
void imageTextureScaleChangedWithSize(); void imageTextureScaleChangedWithSize();
virtual Widget* createCloneInstance() override; virtual Widget* createCloneInstance() override;
virtual void copySpecialProperties(Widget* model) override; virtual void copySpecialProperties(Widget* model) override;
virtual void adaptRenderers() override;
protected: protected:
bool _scale9Enabled; bool _scale9Enabled;
bool _prevIgnoreSize; bool _prevIgnoreSize;
@ -137,6 +135,7 @@ protected:
std::string _textureFile; std::string _textureFile;
TextureResType _imageTexType; TextureResType _imageTexType;
Size _imageTextureSize; Size _imageTextureSize;
bool _imageRendererAdaptDirty;
}; };
} }

View File

@ -701,23 +701,13 @@ bool Layout::isClippingEnabled()
return _clippingEnabled; 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) void Layout::visit(Renderer *renderer, const kmMat4 &parentTransform, bool parentTransformUpdated)
{ {
if (!_enabled) if (!_enabled)
{ {
return; return;
} }
adaptRenderers();
if (_clippingEnabled) if (_clippingEnabled)
{ {
switch (_clippingType) switch (_clippingType)
@ -1075,7 +1065,6 @@ const Rect& Layout::getClippingRect()
void Layout::onSizeChanged() void Layout::onSizeChanged()
{ {
Widget::onSizeChanged(); Widget::onSizeChanged();
setContentSize(_size);
setStencilClippingSize(_size); setStencilClippingSize(_size);
_doLayoutDirty = true; _doLayoutDirty = true;
_clippingRectDirty = true; _clippingRectDirty = true;

View File

@ -266,8 +266,6 @@ public:
virtual void onEnter() override; virtual void onEnter() override;
virtual void onExit() override; virtual void onExit() override;
virtual bool hitTest(const Point &pt);
CC_CONSTRUCTOR_ACCESS: CC_CONSTRUCTOR_ACCESS:
//override "init" method of widget. //override "init" method of widget.
virtual bool init() override; virtual bool init() override;

View File

@ -43,7 +43,8 @@ _barRendererTextureSize(Size::ZERO),
_scale9Enabled(false), _scale9Enabled(false),
_prevIgnoreSize(true), _prevIgnoreSize(true),
_capInsets(Rect::ZERO), _capInsets(Rect::ZERO),
_textureFile("") _textureFile(""),
_barRendererAdaptDirty(true)
{ {
} }
@ -175,7 +176,9 @@ int LoadingBar::getDirection()
} }
break; break;
} }
barRendererScaleChangedWithSize(); // barRendererScaleChangedWithSize();
updateContentSizeWithTextureSize(_barRendererTextureSize);
_barRendererAdaptDirty = true;
} }
void LoadingBar::setScale9Enabled(bool enabled) void LoadingBar::setScale9Enabled(bool enabled)
@ -265,7 +268,16 @@ int LoadingBar::getPercent()
void LoadingBar::onSizeChanged() void LoadingBar::onSizeChanged()
{ {
Widget::onSizeChanged(); Widget::onSizeChanged();
_barRendererAdaptDirty = true;
}
void LoadingBar::adaptRenderers()
{
if (_barRendererAdaptDirty)
{
barRendererScaleChangedWithSize(); barRendererScaleChangedWithSize();
_barRendererAdaptDirty = false;
}
} }
void LoadingBar::ignoreContentAdaptWithSize(bool ignore) 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; return _barRendererTextureSize;
} }
@ -295,7 +307,6 @@ void LoadingBar::barRendererScaleChangedWithSize()
{ {
_totalLength = _barRendererTextureSize.width; _totalLength = _barRendererTextureSize.width;
_barRenderer->setScale(1.0f); _barRenderer->setScale(1.0f);
_size = _barRendererTextureSize;
} }
} }
else else
@ -323,10 +334,10 @@ void LoadingBar::barRendererScaleChangedWithSize()
switch (_barType) switch (_barType)
{ {
case LoadingBarTypeLeft: case LoadingBarTypeLeft:
_barRenderer->setPosition(Point(-_totalLength * 0.5f, 0.0f)); _barRenderer->setPosition(Point(0.0f, _contentSize.height / 2.0f));
break; break;
case LoadingBarTypeRight: case LoadingBarTypeRight:
_barRenderer->setPosition(Point(_totalLength * 0.5f, 0.0f)); _barRenderer->setPosition(Point(_totalLength, _contentSize.height / 2.0f));
break; break;
default: default:
break; break;

View File

@ -128,8 +128,8 @@ public:
//override "ignoreContentAdaptWithSize" method of widget. //override "ignoreContentAdaptWithSize" method of widget.
virtual void ignoreContentAdaptWithSize(bool ignore) override; virtual void ignoreContentAdaptWithSize(bool ignore) override;
//override "getContentSize" method of widget. //override "getVirtualRendererSize" method of widget.
virtual const Size& getContentSize() const override; virtual const Size& getVirtualRendererSize() const override;
//override "getVirtualRenderer" method of widget. //override "getVirtualRenderer" method of widget.
virtual Node* getVirtualRenderer() override; virtual Node* getVirtualRenderer() override;
@ -148,6 +148,7 @@ protected:
void barRendererScaleChangedWithSize(); void barRendererScaleChangedWithSize();
virtual Widget* createCloneInstance() override; virtual Widget* createCloneInstance() override;
virtual void copySpecialProperties(Widget* model) override; virtual void copySpecialProperties(Widget* model) override;
virtual void adaptRenderers() override;
protected: protected:
LoadingBarType _barType; LoadingBarType _barType;
int _percent; int _percent;
@ -159,6 +160,7 @@ protected:
bool _prevIgnoreSize; bool _prevIgnoreSize;
Rect _capInsets; Rect _capInsets;
std::string _textureFile; std::string _textureFile;
bool _barRendererAdaptDirty;
}; };
} }

View File

@ -216,7 +216,6 @@ void RichText::formatText()
{ {
elementRenderer = Label::createWithSystemFont(elmtText->_text.c_str(), elmtText->_fontName, elmtText->_fontSize); elementRenderer = Label::createWithSystemFont(elmtText->_text.c_str(), elmtText->_fontName, elmtText->_fontSize);
} }
break; break;
} }
case RICH_IMAGE: case RICH_IMAGE:
@ -428,13 +427,15 @@ void RichText::formarRenderers()
if (_ignoreSize) if (_ignoreSize)
{ {
Size s = getContentSize(); Size s = getVirtualRendererSize();
_size = s; _size = s;
} }
else else
{ {
_size = _customSize; _size = _customSize;
} }
updateContentSizeWithTextureSize(_size);
_elementRenderersContainer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f);
} }
void RichText::pushToContainer(cocos2d::Node *renderer) void RichText::pushToContainer(cocos2d::Node *renderer)
@ -466,7 +467,7 @@ void RichText::setAnchorPoint(const Point &pt)
_elementRenderersContainer->setAnchorPoint(pt); _elementRenderersContainer->setAnchorPoint(pt);
} }
const Size& RichText::getContentSize() const const Size& RichText::getVirtualRendererSize() const
{ {
return _elementRenderersContainer->getContentSize(); return _elementRenderersContainer->getContentSize();
} }

View File

@ -105,7 +105,7 @@ public:
virtual void visit(cocos2d::Renderer *renderer, const kmMat4 &parentTransform, bool parentTransformUpdated) override; virtual void visit(cocos2d::Renderer *renderer, const kmMat4 &parentTransform, bool parentTransformUpdated) override;
void setVerticalSpace(float space); void setVerticalSpace(float space);
virtual void setAnchorPoint(const Point &pt); virtual void setAnchorPoint(const Point &pt);
virtual const Size& getContentSize() const; virtual const Size& getVirtualRendererSize() const override;
void formatText(); void formatText();
virtual void ignoreContentAdaptWithSize(bool ignore); virtual void ignoreContentAdaptWithSize(bool ignore);
virtual std::string getDescription() const override; virtual std::string getDescription() const override;

View File

@ -60,7 +60,9 @@ _barTexType(UI_TEX_TYPE_LOCAL),
_progressBarTexType(UI_TEX_TYPE_LOCAL), _progressBarTexType(UI_TEX_TYPE_LOCAL),
_ballNTexType(UI_TEX_TYPE_LOCAL), _ballNTexType(UI_TEX_TYPE_LOCAL),
_ballPTexType(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; break;
} }
updateRGBAToRenderer(_barRenderer); updateRGBAToRenderer(_barRenderer);
barRendererScaleChangedWithSize(); _barRendererAdaptDirty = true;
progressBarRendererScaleChangedWithSize(); _progressBarRendererDirty = true;
updateContentSizeWithTextureSize(_barRenderer->getContentSize());
} }
void Slider::loadProgressBarTexture(const std::string& fileName, TextureResType texType) void Slider::loadProgressBarTexture(const std::string& fileName, TextureResType texType)
@ -185,7 +188,7 @@ void Slider::loadProgressBarTexture(const std::string& fileName, TextureResType
updateRGBAToRenderer(_progressBarRenderer); updateRGBAToRenderer(_progressBarRenderer);
_progressBarRenderer->setAnchorPoint(Point(0.0f, 0.5f)); _progressBarRenderer->setAnchorPoint(Point(0.0f, 0.5f));
_progressBarTextureSize = _progressBarRenderer->getContentSize(); _progressBarTextureSize = _progressBarRenderer->getContentSize();
progressBarRendererScaleChangedWithSize(); _progressBarRendererDirty = true;
} }
void Slider::setScale9Enabled(bool able) void Slider::setScale9Enabled(bool able)
@ -364,7 +367,7 @@ void Slider::setPercent(int percent)
_percent = percent; _percent = percent;
float res = percent / 100.0f; float res = percent / 100.0f;
float dis = _barLength * res; float dis = _barLength * res;
_slidBallRenderer->setPosition(Point(-_barLength/2.0f + dis, 0.0f)); _slidBallRenderer->setPosition(Point(dis, _contentSize.height / 2.0f));
if (_scale9Enabled) if (_scale9Enabled)
{ {
static_cast<extension::Scale9Sprite*>(_progressBarRenderer)->setPreferredSize(Size(dis,_progressBarTextureSize.height)); static_cast<extension::Scale9Sprite*>(_progressBarRenderer)->setPreferredSize(Size(dis,_progressBarTextureSize.height));
@ -405,7 +408,6 @@ void Slider::onTouchMoved(Touch *touch, Event *unusedEvent)
{ {
_touchMovePos = touch->getLocation(); _touchMovePos = touch->getLocation();
Point nsp = convertToNodeSpace(_touchMovePos); Point nsp = convertToNodeSpace(_touchMovePos);
_slidBallRenderer->setPosition(Point(nsp.x,0));
setPercent(getPercentWithBallPos(nsp.x)); setPercent(getPercentWithBallPos(nsp.x));
percentChangedEvent(); percentChangedEvent();
} }
@ -422,7 +424,7 @@ void Slider::onTouchCancelled(Touch *touch, Event *unusedEvent)
float Slider::getPercentWithBallPos(float px) 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) void Slider::addEventListenerSlider(Ref *target, SEL_SlidPercentChangedEvent selector)
@ -447,11 +449,25 @@ int Slider::getPercent()
void Slider::onSizeChanged() void Slider::onSizeChanged()
{ {
Widget::onSizeChanged(); Widget::onSizeChanged();
barRendererScaleChangedWithSize(); _barRendererAdaptDirty = true;
progressBarRendererScaleChangedWithSize(); _progressBarRendererDirty = true;
} }
const Size& Slider::getContentSize() const void Slider::adaptRenderers()
{
if (_barRendererAdaptDirty)
{
barRendererScaleChangedWithSize();
_barRendererAdaptDirty = false;
}
if (_progressBarRendererDirty)
{
progressBarRendererScaleChangedWithSize();
_progressBarRendererDirty = false;
}
}
const Size& Slider::getVirtualRendererSize() const
{ {
return _barRenderer->getContentSize(); return _barRenderer->getContentSize();
} }
@ -467,7 +483,6 @@ void Slider::barRendererScaleChangedWithSize()
{ {
_barRenderer->setScale(1.0f); _barRenderer->setScale(1.0f);
_size = _barRenderer->getContentSize();
_barLength = _size.width; _barLength = _size.width;
} }
else else
@ -491,6 +506,7 @@ void Slider::barRendererScaleChangedWithSize()
_barRenderer->setScaleY(bscaleY); _barRenderer->setScaleY(bscaleY);
} }
} }
_barRenderer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f);
setPercent(_percent); setPercent(_percent);
} }
@ -528,7 +544,7 @@ void Slider::progressBarRendererScaleChangedWithSize()
_progressBarRenderer->setScaleY(pscaleY); _progressBarRenderer->setScaleY(pscaleY);
} }
} }
_progressBarRenderer->setPosition(Point(-_barLength * 0.5f, 0.0f)); _progressBarRenderer->setPosition(0.0f, _contentSize.height / 2.0f);
setPercent(_percent); setPercent(_percent);
} }

View File

@ -183,8 +183,8 @@ public:
virtual void onTouchEnded(Touch *touch, Event *unusedEvent) override; virtual void onTouchEnded(Touch *touch, Event *unusedEvent) override;
virtual void onTouchCancelled(Touch *touch, Event *unusedEvent) override; virtual void onTouchCancelled(Touch *touch, Event *unusedEvent) override;
//override "getContentSize" method of widget. //override "getVirtualRendererSize" method of widget.
virtual const Size& getContentSize() const override; virtual const Size& getVirtualRendererSize() const override;
//override "getVirtualRenderer" method of widget. //override "getVirtualRenderer" method of widget.
virtual Node* getVirtualRenderer() override; virtual Node* getVirtualRenderer() override;
@ -217,6 +217,7 @@ protected:
void progressBarRendererScaleChangedWithSize(); void progressBarRendererScaleChangedWithSize();
virtual Widget* createCloneInstance() override; virtual Widget* createCloneInstance() override;
virtual void copySpecialProperties(Widget* model) override; virtual void copySpecialProperties(Widget* model) override;
virtual void adaptRenderers() override;
protected: protected:
Node* _barRenderer; Node* _barRenderer;
Node* _progressBarRenderer; Node* _progressBarRenderer;
@ -248,6 +249,8 @@ protected:
TextureResType _ballNTexType; TextureResType _ballNTexType;
TextureResType _ballPTexType; TextureResType _ballPTexType;
TextureResType _ballDTexType; TextureResType _ballDTexType;
bool _barRendererAdaptDirty;
bool _progressBarRendererDirty;
}; };
} }

View File

@ -39,7 +39,8 @@ _normalScaleValueY(1.0f),
_fontName("Thonburi"), _fontName("Thonburi"),
_fontSize(10), _fontSize(10),
_onSelectedScaleOffset(0.5), _onSelectedScaleOffset(0.5),
_labelRenderer(nullptr) _labelRenderer(nullptr),
_labelRendererAdaptDirty(true)
{ {
} }
@ -104,7 +105,8 @@ void Text::initRenderer()
void Text::setText(const std::string& text) void Text::setText(const std::string& text)
{ {
_labelRenderer->setString(text); _labelRenderer->setString(text);
labelScaleChangedWithSize(); updateContentSizeWithTextureSize(_labelRenderer->getContentSize());
_labelRendererAdaptDirty = true;
} }
const std::string& Text::getStringValue() const std::string& Text::getStringValue()
@ -121,7 +123,8 @@ void Text::setFontSize(int size)
{ {
_fontSize = size; _fontSize = size;
_labelRenderer->setSystemFontSize(size); _labelRenderer->setSystemFontSize(size);
labelScaleChangedWithSize(); updateContentSizeWithTextureSize(_labelRenderer->getContentSize());
_labelRendererAdaptDirty = true;
} }
int Text::getFontSize() int Text::getFontSize()
@ -133,7 +136,8 @@ void Text::setFontName(const std::string& name)
{ {
_fontName = name; _fontName = name;
_labelRenderer->setSystemFontName(name); _labelRenderer->setSystemFontName(name);
labelScaleChangedWithSize(); updateContentSizeWithTextureSize(_labelRenderer->getContentSize());
_labelRendererAdaptDirty = true;
} }
const std::string& Text::getFontName() const std::string& Text::getFontName()
@ -144,7 +148,8 @@ const std::string& Text::getFontName()
void Text::setTextAreaSize(const Size &size) void Text::setTextAreaSize(const Size &size)
{ {
_labelRenderer->setDimensions(size.width,size.height); _labelRenderer->setDimensions(size.width,size.height);
labelScaleChangedWithSize(); updateContentSizeWithTextureSize(_labelRenderer->getContentSize());
_labelRendererAdaptDirty = true;
} }
const Size& Text::getTextAreaSize() const Size& Text::getTextAreaSize()
@ -155,7 +160,8 @@ const Size& Text::getTextAreaSize()
void Text::setTextHorizontalAlignment(TextHAlignment alignment) void Text::setTextHorizontalAlignment(TextHAlignment alignment)
{ {
_labelRenderer->setHorizontalAlignment(alignment); _labelRenderer->setHorizontalAlignment(alignment);
labelScaleChangedWithSize(); updateContentSizeWithTextureSize(_labelRenderer->getContentSize());
_labelRendererAdaptDirty = true;
} }
TextHAlignment Text::getTextHorizontalAlignment() TextHAlignment Text::getTextHorizontalAlignment()
@ -166,7 +172,8 @@ TextHAlignment Text::getTextHorizontalAlignment()
void Text::setTextVerticalAlignment(TextVAlignment alignment) void Text::setTextVerticalAlignment(TextVAlignment alignment)
{ {
_labelRenderer->setVerticalAlignment(alignment); _labelRenderer->setVerticalAlignment(alignment);
labelScaleChangedWithSize(); updateContentSizeWithTextureSize(_labelRenderer->getContentSize());
_labelRendererAdaptDirty = true;
} }
TextVAlignment Text::getTextVerticalAlignment() 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() void Text::onSizeChanged()
{ {
Widget::onSizeChanged(); Widget::onSizeChanged();
labelScaleChangedWithSize(); _labelRendererAdaptDirty = true;
} }
const Size& Text::getContentSize() const void Text::adaptRenderers()
{
if (_labelRendererAdaptDirty)
{
labelScaleChangedWithSize();
_labelRendererAdaptDirty = false;
}
}
const Size& Text::getVirtualRendererSize() const
{ {
return _labelRenderer->getContentSize(); return _labelRenderer->getContentSize();
} }
@ -261,7 +271,6 @@ void Text::labelScaleChangedWithSize()
{ {
_labelRenderer->setDimensions(0,0); _labelRenderer->setDimensions(0,0);
_labelRenderer->setScale(1.0f); _labelRenderer->setScale(1.0f);
_size = _labelRenderer->getContentSize();
_normalScaleValueX = _normalScaleValueY = 1.0f; _normalScaleValueX = _normalScaleValueY = 1.0f;
} }
else else
@ -280,7 +289,7 @@ void Text::labelScaleChangedWithSize()
_normalScaleValueX = scaleX; _normalScaleValueX = scaleX;
_normalScaleValueY = scaleY; _normalScaleValueY = scaleY;
} }
_labelRenderer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f);
} }
std::string Text::getDescription() const std::string Text::getDescription() const

View File

@ -116,11 +116,8 @@ public:
*/ */
bool isTouchScaleChangeEnabled(); bool isTouchScaleChangeEnabled();
//override "setAnchorPoint" method of widget. //override "getVirtualRendererSize" method of widget.
virtual void setAnchorPoint(const Point &pt) override; virtual const Size& getVirtualRendererSize() const override;
//override "getContentSize" method of widget.
virtual const Size& getContentSize() const override;
//override "getVirtualRenderer" method of widget. //override "getVirtualRenderer" method of widget.
virtual Node* getVirtualRenderer() override; virtual Node* getVirtualRenderer() override;
@ -162,6 +159,7 @@ protected:
void labelScaleChangedWithSize(); void labelScaleChangedWithSize();
virtual Widget* createCloneInstance() override; virtual Widget* createCloneInstance() override;
virtual void copySpecialProperties(Widget* model) override; virtual void copySpecialProperties(Widget* model) override;
virtual void adaptRenderers() override;
protected: protected:
bool _touchScaleChangeEnabled; bool _touchScaleChangeEnabled;
float _normalScaleValueX; float _normalScaleValueX;
@ -170,6 +168,7 @@ protected:
int _fontSize; int _fontSize;
float _onSelectedScaleOffset; float _onSelectedScaleOffset;
Label* _labelRenderer; Label* _labelRenderer;
bool _labelRendererAdaptDirty;
}; };
} }

View File

@ -38,7 +38,8 @@ _stringValue(""),
_charMapFileName(""), _charMapFileName(""),
_itemWidth(0), _itemWidth(0),
_itemHeight(0), _itemHeight(0),
_startCharMap("") _startCharMap(""),
_labelAtlasRendererAdaptDirty(true)
{ {
} }
@ -62,6 +63,7 @@ TextAtlas* TextAtlas::create()
void TextAtlas::initRenderer() void TextAtlas::initRenderer()
{ {
_labelAtlasRenderer = LabelAtlas::create(); _labelAtlasRenderer = LabelAtlas::create();
_labelAtlasRenderer->setAnchorPoint(Point::ANCHOR_MIDDLE);
addProtectedChild(_labelAtlasRenderer, LABELATLAS_RENDERER_Z, -1); addProtectedChild(_labelAtlasRenderer, LABELATLAS_RENDERER_Z, -1);
} }
@ -90,15 +92,18 @@ void TextAtlas::setProperty(const std::string& stringValue, const std::string& c
_itemHeight = itemHeight; _itemHeight = itemHeight;
_startCharMap = startCharMap; _startCharMap = startCharMap;
_labelAtlasRenderer->initWithString(stringValue, charMapFile, itemWidth, itemHeight, (int)(startCharMap[0])); _labelAtlasRenderer->initWithString(stringValue, charMapFile, itemWidth, itemHeight, (int)(startCharMap[0]));
updateAnchorPoint(); updateContentSizeWithTextureSize(_labelAtlasRenderer->getContentSize());
labelAtlasScaleChangedWithSize(); _labelAtlasRendererAdaptDirty = true;
CCLOG("cs w %f, h %f", _contentSize.width, _contentSize.height);
} }
void TextAtlas::setStringValue(const std::string& value) void TextAtlas::setStringValue(const std::string& value)
{ {
_stringValue = value; _stringValue = value;
_labelAtlasRenderer->setString(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 const std::string& TextAtlas::getStringValue() const
@ -106,19 +111,22 @@ const std::string& TextAtlas::getStringValue() const
return _labelAtlasRenderer->getString(); return _labelAtlasRenderer->getString();
} }
void TextAtlas::setAnchorPoint(const Point &pt)
{
Widget::setAnchorPoint(pt);
_labelAtlasRenderer->setAnchorPoint(Point(pt.x, pt.y));
}
void TextAtlas::onSizeChanged() void TextAtlas::onSizeChanged()
{ {
Widget::onSizeChanged(); Widget::onSizeChanged();
labelAtlasScaleChangedWithSize(); _labelAtlasRendererAdaptDirty = true;
} }
const Size& TextAtlas::getContentSize() const void TextAtlas::adaptRenderers()
{
if (_labelAtlasRendererAdaptDirty)
{
labelAtlasScaleChangedWithSize();
_labelAtlasRendererAdaptDirty = false;
}
}
const Size& TextAtlas::getVirtualRendererSize() const
{ {
return _labelAtlasRenderer->getContentSize(); return _labelAtlasRenderer->getContentSize();
} }
@ -133,7 +141,6 @@ void TextAtlas::labelAtlasScaleChangedWithSize()
if (_ignoreSize) if (_ignoreSize)
{ {
_labelAtlasRenderer->setScale(1.0f); _labelAtlasRenderer->setScale(1.0f);
_size = _labelAtlasRenderer->getContentSize();
} }
else else
{ {
@ -148,6 +155,7 @@ void TextAtlas::labelAtlasScaleChangedWithSize()
_labelAtlasRenderer->setScaleX(scaleX); _labelAtlasRenderer->setScaleX(scaleX);
_labelAtlasRenderer->setScaleY(scaleY); _labelAtlasRenderer->setScaleY(scaleY);
} }
_labelAtlasRenderer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f);
} }
std::string TextAtlas::getDescription() const std::string TextAtlas::getDescription() const

View File

@ -78,11 +78,8 @@ public:
//get string value for labelatlas. //get string value for labelatlas.
const std::string& getStringValue() const; const std::string& getStringValue() const;
//override "setAnchorPoint" method of widget. //override "getVirtualRendererSize" method of widget.
virtual void setAnchorPoint(const Point &pt) override; virtual const Size& getVirtualRendererSize() const override;
//override "getContentSize" method of widget.
virtual const Size& getContentSize() const override;
//override "getVirtualRenderer" method of widget. //override "getVirtualRenderer" method of widget.
virtual Node* getVirtualRenderer() override; virtual Node* getVirtualRenderer() override;
@ -92,6 +89,7 @@ public:
*/ */
virtual std::string getDescription() const override; virtual std::string getDescription() const override;
virtual void adaptRenderers() override;
protected: protected:
virtual void initRenderer() override; virtual void initRenderer() override;
virtual void onSizeChanged() override; virtual void onSizeChanged() override;
@ -108,6 +106,7 @@ protected:
int _itemWidth; int _itemWidth;
int _itemHeight; int _itemHeight;
std::string _startCharMap; std::string _startCharMap;
bool _labelAtlasRendererAdaptDirty;
}; };
} }

View File

@ -36,7 +36,8 @@ TextBMFont::TextBMFont():
_labelBMFontRenderer(nullptr), _labelBMFontRenderer(nullptr),
_fntFileHasInit(false), _fntFileHasInit(false),
_fntFileName(""), _fntFileName(""),
_stringValue("") _stringValue(""),
_labelBMFontRendererAdaptDirty(true)
{ {
} }
@ -85,8 +86,7 @@ void TextBMFont::setFntFile(const std::string& fileName)
} }
_fntFileName = fileName; _fntFileName = fileName;
_labelBMFontRenderer->setBMFontFilePath(fileName); _labelBMFontRenderer->setBMFontFilePath(fileName);
updateAnchorPoint(); updateRGBAToRenderer(_labelBMFontRenderer);
labelBMFontScaleChangedWithSize();
_fntFileHasInit = true; _fntFileHasInit = true;
setText(_stringValue); setText(_stringValue);
} }
@ -99,7 +99,8 @@ void TextBMFont::setText(const std::string& value)
return; return;
} }
_labelBMFontRenderer->setString(value); _labelBMFontRenderer->setString(value);
labelBMFontScaleChangedWithSize(); updateContentSizeWithTextureSize(_labelBMFontRenderer->getContentSize());
_labelBMFontRendererAdaptDirty = true;
} }
const std::string TextBMFont::getStringValue() const std::string TextBMFont::getStringValue()
@ -107,19 +108,22 @@ const std::string TextBMFont::getStringValue()
return _stringValue; return _stringValue;
} }
void TextBMFont::setAnchorPoint(const Point &pt)
{
Widget::setAnchorPoint(pt);
_labelBMFontRenderer->setAnchorPoint(pt);
}
void TextBMFont::onSizeChanged() void TextBMFont::onSizeChanged()
{ {
Widget::onSizeChanged(); Widget::onSizeChanged();
labelBMFontScaleChangedWithSize(); _labelBMFontRendererAdaptDirty = true;
} }
const Size& TextBMFont::getContentSize() const void TextBMFont::adaptRenderers()
{
if (_labelBMFontRendererAdaptDirty)
{
labelBMFontScaleChangedWithSize();
_labelBMFontRendererAdaptDirty = false;
}
}
const Size& TextBMFont::getVirtualRendererSize() const
{ {
return _labelBMFontRenderer->getContentSize(); return _labelBMFontRenderer->getContentSize();
} }
@ -134,7 +138,6 @@ void TextBMFont::labelBMFontScaleChangedWithSize()
if (_ignoreSize) if (_ignoreSize)
{ {
_labelBMFontRenderer->setScale(1.0f); _labelBMFontRenderer->setScale(1.0f);
_size = _labelBMFontRenderer->getContentSize();
} }
else else
{ {
@ -149,6 +152,7 @@ void TextBMFont::labelBMFontScaleChangedWithSize()
_labelBMFontRenderer->setScaleX(scaleX); _labelBMFontRenderer->setScaleX(scaleX);
_labelBMFontRenderer->setScaleY(scaleY); _labelBMFontRenderer->setScaleY(scaleY);
} }
_labelBMFontRenderer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f);
} }
std::string TextBMFont::getDescription() const std::string TextBMFont::getDescription() const

View File

@ -66,8 +66,7 @@ public:
/** get string value for labelbmfont*/ /** get string value for labelbmfont*/
const std::string getStringValue(); const std::string getStringValue();
virtual void setAnchorPoint(const Point &pt) override; virtual const Size& getVirtualRendererSize() const override;
virtual const Size& getContentSize() const override;
virtual Node* getVirtualRenderer() override; virtual Node* getVirtualRenderer() override;
/** /**
* Returns the "class name" of widget. * Returns the "class name" of widget.
@ -82,11 +81,13 @@ protected:
void labelBMFontScaleChangedWithSize(); void labelBMFontScaleChangedWithSize();
virtual Widget* createCloneInstance() override; virtual Widget* createCloneInstance() override;
virtual void copySpecialProperties(Widget* model) override; virtual void copySpecialProperties(Widget* model) override;
virtual void adaptRenderers() override;
protected: protected:
cocos2d::Label* _labelBMFontRenderer; cocos2d::Label* _labelBMFontRenderer;
bool _fntFileHasInit; bool _fntFileHasInit;
std::string _fntFileName; std::string _fntFileName;
std::string _stringValue; std::string _stringValue;
bool _labelBMFontRendererAdaptDirty;
}; };
} }

View File

@ -364,7 +364,8 @@ _touchHeight(0.0f),
_useTouchArea(false), _useTouchArea(false),
_textFieldEventListener(nullptr), _textFieldEventListener(nullptr),
_textFieldEventSelector(nullptr), _textFieldEventSelector(nullptr),
_passwordStyleText("") _passwordStyleText(""),
_textFieldRendererAdaptDirty(true)
{ {
} }
@ -514,14 +515,15 @@ void TextField::setText(const std::string& text)
{ {
_textFieldRenderer->setString(content); _textFieldRenderer->setString(content);
} }
_textFieldRendererAdaptDirty = true;
textfieldRendererScaleChangedWithSize(); updateContentSizeWithTextureSize(_textFieldRenderer->getContentSize());
} }
void TextField::setPlaceHolder(const std::string& value) void TextField::setPlaceHolder(const std::string& value)
{ {
_textFieldRenderer->setPlaceHolder(value); _textFieldRenderer->setPlaceHolder(value);
textfieldRendererScaleChangedWithSize(); _textFieldRendererAdaptDirty = true;
updateContentSizeWithTextureSize(_textFieldRenderer->getContentSize());
} }
const std::string& TextField::getPlaceHolder() const std::string& TextField::getPlaceHolder()
@ -532,7 +534,8 @@ const std::string& TextField::getPlaceHolder()
void TextField::setFontSize(int size) void TextField::setFontSize(int size)
{ {
_textFieldRenderer->setSystemFontSize(size); _textFieldRenderer->setSystemFontSize(size);
textfieldRendererScaleChangedWithSize(); _textFieldRendererAdaptDirty = true;
updateContentSizeWithTextureSize(_textFieldRenderer->getContentSize());
} }
int TextField::getFontSize() int TextField::getFontSize()
@ -543,7 +546,8 @@ int TextField::getFontSize()
void TextField::setFontName(const std::string& name) void TextField::setFontName(const std::string& name)
{ {
_textFieldRenderer->setSystemFontName(name); _textFieldRenderer->setSystemFontName(name);
textfieldRendererScaleChangedWithSize(); _textFieldRendererAdaptDirty = true;
updateContentSizeWithTextureSize(_textFieldRenderer->getContentSize());
} }
const std::string& TextField::getFontName() const std::string& TextField::getFontName()
@ -634,14 +638,16 @@ void TextField::update(float dt)
insertTextEvent(); insertTextEvent();
setInsertText(false); setInsertText(false);
textfieldRendererScaleChangedWithSize(); _textFieldRendererAdaptDirty = true;
updateContentSizeWithTextureSize(_textFieldRenderer->getContentSize());
} }
if (getDeleteBackward()) if (getDeleteBackward())
{ {
deleteBackwardEvent(); deleteBackwardEvent();
setDeleteBackward(false); setDeleteBackward(false);
textfieldRendererScaleChangedWithSize(); _textFieldRendererAdaptDirty = true;
updateContentSizeWithTextureSize(_textFieldRenderer->getContentSize());
} }
} }
@ -723,16 +729,19 @@ void TextField::addEventListenerTextField(Ref *target, SEL_TextFieldEvent seleco
_textFieldEventSelector = selecor; _textFieldEventSelector = selecor;
} }
void TextField::setAnchorPoint(const Point &pt)
{
Widget::setAnchorPoint(pt);
_textFieldRenderer->setAnchorPoint(pt);
}
void TextField::onSizeChanged() void TextField::onSizeChanged()
{ {
Widget::onSizeChanged(); Widget::onSizeChanged();
_textFieldRendererAdaptDirty = true;
}
void TextField::adaptRenderers()
{
if (_textFieldRendererAdaptDirty)
{
textfieldRendererScaleChangedWithSize(); textfieldRendererScaleChangedWithSize();
_textFieldRendererAdaptDirty = false;
}
} }
void TextField::textfieldRendererScaleChangedWithSize() void TextField::textfieldRendererScaleChangedWithSize()
@ -741,7 +750,6 @@ void TextField::textfieldRendererScaleChangedWithSize()
{ {
_textFieldRenderer->setDimensions(0,0); _textFieldRenderer->setDimensions(0,0);
_textFieldRenderer->setScale(1.0f); _textFieldRenderer->setScale(1.0f);
_size = getContentSize();
} }
else else
{ {
@ -757,9 +765,10 @@ void TextField::textfieldRendererScaleChangedWithSize()
_textFieldRenderer->setScaleX(scaleX); _textFieldRenderer->setScaleX(scaleX);
_textFieldRenderer->setScaleY(scaleY); _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(); return _textFieldRenderer->getContentSize();
} }

View File

@ -146,14 +146,12 @@ public:
void setDeleteBackward(bool deleteBackward); void setDeleteBackward(bool deleteBackward);
void addEventListenerTextField(Ref* target, SEL_TextFieldEvent selecor); void addEventListenerTextField(Ref* target, SEL_TextFieldEvent selecor);
virtual void setAnchorPoint(const Point &pt) override;
/** /**
* Returns the "class name" of widget. * Returns the "class name" of widget.
*/ */
virtual std::string getDescription() const override; virtual std::string getDescription() const override;
virtual const Size& getContentSize() const override; virtual const Size& getVirtualRendererSize() const override;
virtual Node* getVirtualRenderer() override; virtual Node* getVirtualRenderer() override;
void attachWithIME(); void attachWithIME();
virtual void onEnter() override; virtual void onEnter() override;
@ -178,6 +176,7 @@ protected:
void textfieldRendererScaleChangedWithSize(); void textfieldRendererScaleChangedWithSize();
virtual Widget* createCloneInstance() override; virtual Widget* createCloneInstance() override;
virtual void copySpecialProperties(Widget* model) override; virtual void copySpecialProperties(Widget* model) override;
virtual void adaptRenderers() override;
protected: protected:
UICCTextField* _textFieldRenderer; UICCTextField* _textFieldRenderer;
@ -189,6 +188,7 @@ protected:
SEL_TextFieldEvent _textFieldEventSelector; SEL_TextFieldEvent _textFieldEventSelector;
std::string _passwordStyleText; std::string _passwordStyleText;
bool _textFieldRendererAdaptDirty;
}; };
} }

View File

@ -112,6 +112,7 @@ void Widget::visit(Renderer *renderer, const kmMat4 &parentTransform, bool paren
{ {
if (_enabled) if (_enabled)
{ {
adaptRenderers();
ProtectedNode::visit(renderer, parentTransform, parentTransformUpdated); ProtectedNode::visit(renderer, parentTransform, parentTransformUpdated);
} }
} }
@ -177,7 +178,7 @@ void Widget::setSize(const Size &size)
_customSize = size; _customSize = size;
if (_ignoreSize) if (_ignoreSize)
{ {
_size = getContentSize(); _size = getVirtualRendererSize();
} }
else else
{ {
@ -228,7 +229,7 @@ void Widget::setSizePercent(const Point &percent)
} }
if (_ignoreSize) if (_ignoreSize)
{ {
_size = getContentSize(); _size = getVirtualRendererSize();
} }
else else
{ {
@ -261,7 +262,7 @@ void Widget::updateSizeAndPosition(const cocos2d::Size &parentSize)
{ {
if (_ignoreSize) if (_ignoreSize)
{ {
_size = getContentSize(); _size = getVirtualRendererSize();
} }
else else
{ {
@ -285,7 +286,7 @@ void Widget::updateSizeAndPosition(const cocos2d::Size &parentSize)
Size cSize = Size(parentSize.width * _sizePercent.x , parentSize.height * _sizePercent.y); Size cSize = Size(parentSize.width * _sizePercent.x , parentSize.height * _sizePercent.y);
if (_ignoreSize) if (_ignoreSize)
{ {
_size = getContentSize(); _size = getVirtualRendererSize();
} }
else else
{ {
@ -343,7 +344,7 @@ void Widget::ignoreContentAdaptWithSize(bool ignore)
_ignoreSize = ignore; _ignoreSize = ignore;
if (_ignoreSize) if (_ignoreSize)
{ {
Size s = getContentSize(); Size s = getVirtualRendererSize();
_size = s; _size = s;
} }
else else
@ -375,7 +376,7 @@ const Point& Widget::getSizePercent() const
Point Widget::getWorldPosition() Point Widget::getWorldPosition()
{ {
return convertToWorldSpace(Point::ZERO); return convertToWorldSpace(Point(_anchorPoint.x * _contentSize.width, _anchorPoint.y * _contentSize.height));
} }
Node* Widget::getVirtualRenderer() Node* Widget::getVirtualRenderer()
@ -385,6 +386,7 @@ Node* Widget::getVirtualRenderer()
void Widget::onSizeChanged() void Widget::onSizeChanged()
{ {
setContentSize(_size);
for (auto& child : getChildren()) for (auto& child : getChildren())
{ {
Widget* widgetChild = dynamic_cast<Widget*>(child); Widget* widgetChild = dynamic_cast<Widget*>(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) void Widget::setTouchEnabled(bool enable)
@ -617,8 +632,9 @@ void Widget::addTouchEventListener(Ref *target, SEL_TouchEvent selector)
bool Widget::hitTest(const Point &pt) bool Widget::hitTest(const Point &pt)
{ {
Point nsp = convertToNodeSpace(pt); Point nsp = convertToNodeSpace(pt);
Rect bb = Rect(-_size.width * _anchorPoint.x, -_size.height * _anchorPoint.y, _size.width, _size.height); Rect bb;
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) bb.size = _contentSize;
if (bb.containsPoint(nsp))
{ {
return true; return true;
} }
@ -712,11 +728,6 @@ void Widget::setPositionPercent(const Point &percent)
} }
} }
void Widget::updateAnchorPoint()
{
setAnchorPoint(getAnchorPoint());
}
const Point& Widget::getPositionPercent() const Point& Widget::getPositionPercent()
{ {
return _positionPercent; return _positionPercent;

View File

@ -501,12 +501,15 @@ public:
*/ */
virtual Node* getVirtualRenderer(); virtual Node* getVirtualRenderer();
/** // /**
* Gets the content size of widget. // * Gets the content size of widget.
* // *
* Content size is widget's texture size. // * Content size is widget's texture size.
*/ // */
virtual const Size& getContentSize() const; // virtual const Size& getContentSize() const;
virtual const Size& getVirtualRendererSize() const;
/** /**
* Returns the "class name" of widget. * Returns the "class name" of widget.
@ -549,7 +552,6 @@ protected:
void moveEvent(); void moveEvent();
void releaseUpEvent(); void releaseUpEvent();
void cancelUpEvent(); void cancelUpEvent();
void updateAnchorPoint();
virtual void updateTextureColor(){}; virtual void updateTextureColor(){};
virtual void updateTextureOpacity(){}; virtual void updateTextureOpacity(){};
virtual void updateTextureRGBA(){}; virtual void updateTextureRGBA(){};
@ -563,6 +565,8 @@ protected:
virtual void copySpecialProperties(Widget* model); virtual void copySpecialProperties(Widget* model);
virtual void copyClonedWidgetChildren(Widget* model); virtual void copyClonedWidgetChildren(Widget* model);
Widget* getWidgetParent(); Widget* getWidgetParent();
void updateContentSizeWithTextureSize(const Size& size);
virtual void adaptRenderers(){};
protected: protected:
bool _enabled; ///< Highest control of widget bool _enabled; ///< Highest control of widget
bool _bright; ///< is this widget bright bool _bright; ///< is this widget bright

View File

@ -109,7 +109,7 @@ bool UIButtonTest_Scale9::init()
// open scale9 render // open scale9 render
button->setScale9Enabled(true); button->setScale9Enabled(true);
button->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); 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)); button->addTouchEventListener(this, toucheventselector(UIButtonTest_Scale9::touchEvent));
_uiLayer->addChild(button); _uiLayer->addChild(button);

View File

@ -21,7 +21,7 @@ bool UIImageViewTest::init()
// Create the imageview // Create the imageview
ImageView* imageView = ImageView::create("cocosui/ccicon.png"); ImageView* imageView = ImageView::create("cocosui/ccicon.png");
imageView->setPosition(Point(widgetSize.width / 2.0f, imageView->setPosition(Point(widgetSize.width / 2.0f,
widgetSize.height / 2.0f + imageView->getSize().height / 4.0f)); widgetSize.height / 2.0f));
_uiLayer->addChild(imageView); _uiLayer->addChild(imageView);
@ -53,7 +53,7 @@ bool UIImageViewTest_Scale9::init()
imageView->setScale9Enabled(true); imageView->setScale9Enabled(true);
imageView->setSize(Size(300, 115)); imageView->setSize(Size(300, 115));
imageView->setPosition(Point(widgetSize.width / 2.0f, imageView->setPosition(Point(widgetSize.width / 2.0f,
widgetSize.height / 2.0f + imageView->getSize().height / 4.0f)); widgetSize.height / 2.0f));
_uiLayer->addChild(imageView); _uiLayer->addChild(imageView);

View File

@ -53,7 +53,7 @@ bool UILayoutTest::init()
Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
button_scale9->setScale9Enabled(true); 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->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f,
button_scale9->getSize().height / 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* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
button_scale9->setScale9Enabled(true); 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->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f,
button_scale9->getSize().height / 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* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
button_scale9->setScale9Enabled(true); 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->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f,
button_scale9->getSize().height / 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* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
button_scale9->setScale9Enabled(true); 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->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f,
button_scale9->getSize().height / 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* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
button_scale9->setScale9Enabled(true); 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->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f,
button_scale9->getSize().height / 2.0f)); button_scale9->getSize().height / 2.0f));
layout->addChild(button_scale9); 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* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
button_scale9->setScale9Enabled(true); 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); layout->addChild(button_scale9);
LinearLayoutParameter* lp3 = LinearLayoutParameter::create(); 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* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
button_scale9->setScale9Enabled(true); 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); layout->addChild(button_scale9);
LinearLayoutParameter* lp3 = LinearLayoutParameter::create(); LinearLayoutParameter* lp3 = LinearLayoutParameter::create();

View File

@ -193,7 +193,7 @@ bool UILoadingBarTest_Left_Scale9::init()
loadingBar->setTag(0); loadingBar->setTag(0);
loadingBar->setScale9Enabled(true); loadingBar->setScale9Enabled(true);
loadingBar->setCapInsets(Rect(0, 0, 0, 0)); 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, loadingBar->setPosition(Point(widgetSize.width / 2.0f,
widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f)); widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f));
@ -275,7 +275,7 @@ bool UILoadingBarTest_Right_Scale9::init()
loadingBar->setTag(0); loadingBar->setTag(0);
loadingBar->setScale9Enabled(true); loadingBar->setScale9Enabled(true);
loadingBar->setCapInsets(Rect(0, 0, 0, 0)); loadingBar->setCapInsets(Rect(0, 0, 0, 0));
loadingBar->setSize(Size(300, loadingBar->getContentSize().height)); loadingBar->setSize(Size(300, 13));
loadingBar->setDirection(LoadingBarTypeRight); loadingBar->setDirection(LoadingBarTypeRight);
loadingBar->setPosition(Point(widgetSize.width / 2.0f, loadingBar->setPosition(Point(widgetSize.width / 2.0f,

View File

@ -65,7 +65,7 @@ bool UIScrollViewTest_Vertical::init()
Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
button_scale9->setScale9Enabled(true); 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)); button_scale9->setPosition(Point(innerWidth / 2.0f, titleButton->getBottomInParent() - titleButton->getSize().height));
scrollView->addChild(button_scale9); scrollView->addChild(button_scale9);
@ -143,7 +143,7 @@ bool UIScrollViewTest_Horizontal::init()
Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
button_scale9->setScale9Enabled(true); 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, button_scale9->setPosition(Point(titleButton->getRightInParent() + titleButton->getSize().width / 2.0f,
titleButton->getBottomInParent() - titleButton->getSize().height / 2.0f)); titleButton->getBottomInParent() - titleButton->getSize().height / 2.0f));
scrollView->addChild(button_scale9); scrollView->addChild(button_scale9);