From 585ccf2c71ea635ef407bb58cad5b3360f94019e Mon Sep 17 00:00:00 2001 From: andyque Date: Fri, 20 Jun 2014 10:40:16 +0800 Subject: [PATCH] issue #5161, replace all _size to _contentSize --- cocos/ui/UIButton.cpp | 24 ++++----- cocos/ui/UICheckBox.cpp | 20 ++++---- cocos/ui/UIImageView.cpp | 8 +-- cocos/ui/UILayout.cpp | 34 ++++++------ cocos/ui/UIListView.cpp | 4 +- cocos/ui/UILoadingBar.cpp | 8 +-- cocos/ui/UIRichText.cpp | 8 +-- cocos/ui/UIScrollView.cpp | 105 +++++++++++++++++++++----------------- cocos/ui/UISlider.cpp | 20 ++++---- cocos/ui/UIText.cpp | 6 +-- cocos/ui/UITextAtlas.cpp | 4 +- cocos/ui/UITextBMFont.cpp | 4 +- cocos/ui/UITextField.cpp | 6 +-- cocos/ui/UIWidget.cpp | 39 +++++++------- cocos/ui/UIWidget.h | 3 +- 15 files changed, 150 insertions(+), 143 deletions(-) diff --git a/cocos/ui/UIButton.cpp b/cocos/ui/UIButton.cpp index f8366ccad2..4f1d36bd2e 100644 --- a/cocos/ui/UIButton.cpp +++ b/cocos/ui/UIButton.cpp @@ -56,9 +56,9 @@ _capInsetsDisabled(Rect::ZERO), _normalTexType(TextureResType::LOCAL), _pressedTexType(TextureResType::LOCAL), _disabledTexType(TextureResType::LOCAL), -_normalTextureSize(_size), -_pressedTextureSize(_size), -_disabledTextureSize(_size), +_normalTextureSize(_contentSize), +_pressedTextureSize(_contentSize), +_disabledTextureSize(_contentSize), _pressedActionEnabled(false), _titleColor(Color3B::WHITE), _normalTextureScaleXInSize(1.0f), @@ -615,7 +615,7 @@ void Button::normalTextureScaleChangedWithSize() { if (_scale9Enabled) { - static_cast(_buttonNormalRenderer)->setPreferredSize(_size); + static_cast(_buttonNormalRenderer)->setPreferredSize(_contentSize); _normalTextureScaleXInSize = _normalTextureScaleYInSize = 1.0f; } else @@ -626,8 +626,8 @@ void Button::normalTextureScaleChangedWithSize() _buttonNormalRenderer->setScale(1.0f); return; } - float scaleX = _size.width / textureSize.width; - float scaleY = _size.height / textureSize.height; + float scaleX = _contentSize.width / textureSize.width; + float scaleY = _contentSize.height / textureSize.height; _buttonNormalRenderer->setScaleX(scaleX); _buttonNormalRenderer->setScaleY(scaleY); _normalTextureScaleXInSize = scaleX; @@ -651,7 +651,7 @@ void Button::pressedTextureScaleChangedWithSize() { if (_scale9Enabled) { - static_cast(_buttonClickedRenderer)->setPreferredSize(_size); + static_cast(_buttonClickedRenderer)->setPreferredSize(_contentSize); _pressedTextureScaleXInSize = _pressedTextureScaleYInSize = 1.0f; } else @@ -662,8 +662,8 @@ void Button::pressedTextureScaleChangedWithSize() _buttonClickedRenderer->setScale(1.0f); return; } - float scaleX = _size.width / _pressedTextureSize.width; - float scaleY = _size.height / _pressedTextureSize.height; + float scaleX = _contentSize.width / _pressedTextureSize.width; + float scaleY = _contentSize.height / _pressedTextureSize.height; _buttonClickedRenderer->setScaleX(scaleX); _buttonClickedRenderer->setScaleY(scaleY); _pressedTextureScaleXInSize = scaleX; @@ -686,7 +686,7 @@ void Button::disabledTextureScaleChangedWithSize() { if (_scale9Enabled) { - static_cast(_buttonDisableRenderer)->setPreferredSize(_size); + static_cast(_buttonDisableRenderer)->setPreferredSize(_contentSize); } else { @@ -696,8 +696,8 @@ void Button::disabledTextureScaleChangedWithSize() _buttonDisableRenderer->setScale(1.0f); return; } - float scaleX = _size.width / _disabledTextureSize.width; - float scaleY = _size.height / _disabledTextureSize.height; + float scaleX = _contentSize.width / _disabledTextureSize.width; + float scaleY = _contentSize.height / _disabledTextureSize.height; _buttonDisableRenderer->setScaleX(scaleX); _buttonDisableRenderer->setScaleY(scaleY); } diff --git a/cocos/ui/UICheckBox.cpp b/cocos/ui/UICheckBox.cpp index 5440da5a3a..d5a3b762d0 100644 --- a/cocos/ui/UICheckBox.cpp +++ b/cocos/ui/UICheckBox.cpp @@ -473,8 +473,8 @@ void CheckBox::backGroundTextureScaleChangedWithSize() _backGroundBoxRenderer->setScale(1.0f); return; } - float scaleX = _size.width / textureSize.width; - float scaleY = _size.height / textureSize.height; + float scaleX = _contentSize.width / textureSize.width; + float scaleY = _contentSize.height / textureSize.height; _backGroundBoxRenderer->setScaleX(scaleX); _backGroundBoxRenderer->setScaleY(scaleY); } @@ -495,8 +495,8 @@ void CheckBox::backGroundSelectedTextureScaleChangedWithSize() _backGroundSelectedBoxRenderer->setScale(1.0f); return; } - float scaleX = _size.width / textureSize.width; - float scaleY = _size.height / textureSize.height; + float scaleX = _contentSize.width / textureSize.width; + float scaleY = _contentSize.height / textureSize.height; _backGroundSelectedBoxRenderer->setScaleX(scaleX); _backGroundSelectedBoxRenderer->setScaleY(scaleY); } @@ -517,8 +517,8 @@ void CheckBox::frontCrossTextureScaleChangedWithSize() _frontCrossRenderer->setScale(1.0f); return; } - float scaleX = _size.width / textureSize.width; - float scaleY = _size.height / textureSize.height; + float scaleX = _contentSize.width / textureSize.width; + float scaleY = _contentSize.height / textureSize.height; _frontCrossRenderer->setScaleX(scaleX); _frontCrossRenderer->setScaleY(scaleY); } @@ -539,8 +539,8 @@ void CheckBox::backGroundDisabledTextureScaleChangedWithSize() _backGroundBoxDisabledRenderer->setScale(1.0f); return; } - float scaleX = _size.width / textureSize.width; - float scaleY = _size.height / textureSize.height; + float scaleX = _contentSize.width / textureSize.width; + float scaleY = _contentSize.height / textureSize.height; _backGroundBoxDisabledRenderer->setScaleX(scaleX); _backGroundBoxDisabledRenderer->setScaleY(scaleY); } @@ -561,8 +561,8 @@ void CheckBox::frontCrossDisabledTextureScaleChangedWithSize() _frontCrossDisabledRenderer->setScale(1.0f); return; } - float scaleX = _size.width / textureSize.width; - float scaleY = _size.height / textureSize.height; + float scaleX = _contentSize.width / textureSize.width; + float scaleY = _contentSize.height / textureSize.height; _frontCrossDisabledRenderer->setScaleX(scaleX); _frontCrossDisabledRenderer->setScaleY(scaleY); } diff --git a/cocos/ui/UIImageView.cpp b/cocos/ui/UIImageView.cpp index 95034eeef5..cfc5d76d62 100644 --- a/cocos/ui/UIImageView.cpp +++ b/cocos/ui/UIImageView.cpp @@ -45,7 +45,7 @@ _capInsets(Rect::ZERO), _imageRenderer(nullptr), _textureFile(""), _imageTexType(TextureResType::LOCAL), -_imageTextureSize(_size), +_imageTextureSize(_contentSize), _imageRendererAdaptDirty(true) { @@ -300,7 +300,7 @@ void ImageView::imageTextureScaleChangedWithSize() { if (_scale9Enabled) { - static_cast(_imageRenderer)->setPreferredSize(_size); + static_cast(_imageRenderer)->setPreferredSize(_contentSize); } else { @@ -310,8 +310,8 @@ void ImageView::imageTextureScaleChangedWithSize() _imageRenderer->setScale(1.0f); return; } - float scaleX = _size.width / textureSize.width; - float scaleY = _size.height / textureSize.height; + float scaleX = _contentSize.width / textureSize.width; + float scaleY = _contentSize.height / textureSize.height; _imageRenderer->setScaleX(scaleX); _imageRenderer->setScaleY(scaleY); } diff --git a/cocos/ui/UILayout.cpp b/cocos/ui/UILayout.cpp index a42599b915..092ef3a61c 100644 --- a/cocos/ui/UILayout.cpp +++ b/cocos/ui/UILayout.cpp @@ -429,7 +429,7 @@ void Layout::setClippingEnabled(bool able) _clippingStencil->onEnter(); } _clippingStencil->retain(); - setStencilClippingSize(_size); + setStencilClippingSize(_contentSize); } else { @@ -469,9 +469,9 @@ void Layout::setStencilClippingSize(const Size &size) { Vec2 rect[4]; rect[0] = Vec2::ZERO; - rect[1] = Vec2(_size.width, 0); - rect[2] = Vec2(_size.width, _size.height); - rect[3] = Vec2(0, _size.height); + rect[1] = Vec2(_contentSize.width, 0); + rect[2] = Vec2(_contentSize.width, _contentSize.height); + rect[3] = Vec2(0, _contentSize.height); Color4F green(0, 1, 0, 1); _clippingStencil->clear(); _clippingStencil->drawPolygon(rect, 4, green, 0, green); @@ -484,8 +484,8 @@ const Rect& Layout::getClippingRect() { Vec2 worldPos = convertToWorldSpace(Vec2::ZERO); AffineTransform t = getNodeToWorldAffineTransform(); - float scissorWidth = _size.width*t.a; - float scissorHeight = _size.height*t.d; + float scissorWidth = _contentSize.width*t.a; + float scissorHeight = _contentSize.height*t.d; Rect parentClippingRect; Layout* parent = this; @@ -560,24 +560,24 @@ const Rect& Layout::getClippingRect() void Layout::onSizeChanged() { Widget::onSizeChanged(); - setStencilClippingSize(_size); + setStencilClippingSize(_contentSize); _doLayoutDirty = true; _clippingRectDirty = true; if (_backGroundImage) { - _backGroundImage->setPosition(Vec2(_size.width/2.0f, _size.height/2.0f)); + _backGroundImage->setPosition(Vec2(_contentSize.width/2.0f, _contentSize.height/2.0f)); if (_backGroundScale9Enabled && _backGroundImage) { - static_cast(_backGroundImage)->setPreferredSize(_size); + static_cast(_backGroundImage)->setPreferredSize(_contentSize); } } if (_colorRender) { - _colorRender->setContentSize(_size); + _colorRender->setContentSize(_contentSize); } if (_gradientRender) { - _gradientRender->setContentSize(_size); + _gradientRender->setContentSize(_contentSize); } } @@ -626,7 +626,7 @@ void Layout::setBackGroundImage(const std::string& fileName,TextureResType texTy default: break; } - bgiScale9->setPreferredSize(_size); + bgiScale9->setPreferredSize(_contentSize); } else { @@ -643,7 +643,7 @@ void Layout::setBackGroundImage(const std::string& fileName,TextureResType texTy } } _backGroundImageTextureSize = _backGroundImage->getContentSize(); - _backGroundImage->setPosition(Vec2(_size.width/2.0f, _size.height/2.0f)); + _backGroundImage->setPosition(Vec2(_contentSize.width/2.0f, _contentSize.height/2.0f)); updateBackGroundImageRGBA(); } @@ -701,14 +701,14 @@ void Layout::addBackGroundImage() { _backGroundImage = extension::Scale9Sprite::create(); addProtectedChild(_backGroundImage, BACKGROUNDIMAGE_Z, -1); - static_cast(_backGroundImage)->setPreferredSize(_size); + static_cast(_backGroundImage)->setPreferredSize(_contentSize); } else { _backGroundImage = Sprite::create(); addProtectedChild(_backGroundImage, BACKGROUNDIMAGE_Z, -1); } - _backGroundImage->setPosition(Vec2(_size.width/2.0f, _size.height/2.0f)); + _backGroundImage->setPosition(Vec2(_contentSize.width/2.0f, _contentSize.height/2.0f)); } void Layout::removeBackGroundImage() @@ -767,14 +767,14 @@ void Layout::setBackGroundColorType(BackGroundColorType type) break; case BackGroundColorType::SOLID: _colorRender = LayerColor::create(); - _colorRender->setContentSize(_size); + _colorRender->setContentSize(_contentSize); _colorRender->setOpacity(_cOpacity); _colorRender->setColor(_cColor); addProtectedChild(_colorRender, BCAKGROUNDCOLORRENDERER_Z, -1); break; case BackGroundColorType::GRADIENT: _gradientRender = LayerGradient::create(); - _gradientRender->setContentSize(_size); + _gradientRender->setContentSize(_contentSize); _gradientRender->setOpacity(_cOpacity); _gradientRender->setStartColor(_gStartColor); _gradientRender->setEndColor(_gEndColor); diff --git a/cocos/ui/UIListView.cpp b/cocos/ui/UIListView.cpp index 16d9e29280..0d6a5b4cb2 100644 --- a/cocos/ui/UIListView.cpp +++ b/cocos/ui/UIListView.cpp @@ -98,7 +98,7 @@ void ListView::updateInnerContainerSize() { totalHeight += item->getSize().height; } - float finalWidth = _size.width; + float finalWidth = _contentSize.width; float finalHeight = totalHeight; setInnerContainerSize(Size(finalWidth, finalHeight)); break; @@ -112,7 +112,7 @@ void ListView::updateInnerContainerSize() totalWidth += item->getSize().width; } float finalWidth = totalWidth; - float finalHeight = _size.height; + float finalHeight = _contentSize.height; setInnerContainerSize(Size(finalWidth, finalHeight)); break; } diff --git a/cocos/ui/UILoadingBar.cpp b/cocos/ui/UILoadingBar.cpp index 5dccc11c5b..6cc2f658f0 100644 --- a/cocos/ui/UILoadingBar.cpp +++ b/cocos/ui/UILoadingBar.cpp @@ -317,7 +317,7 @@ void LoadingBar::barRendererScaleChangedWithSize() } else { - _totalLength = _size.width; + _totalLength = _contentSize.width; if (_scale9Enabled) { setScale9Scale(); @@ -331,8 +331,8 @@ void LoadingBar::barRendererScaleChangedWithSize() _barRenderer->setScale(1.0f); return; } - float scaleX = _size.width / textureSize.width; - float scaleY = _size.height / textureSize.height; + float scaleX = _contentSize.width / textureSize.width; + float scaleY = _contentSize.height / textureSize.height; _barRenderer->setScaleX(scaleX); _barRenderer->setScaleY(scaleY); } @@ -353,7 +353,7 @@ void LoadingBar::barRendererScaleChangedWithSize() void LoadingBar::setScale9Scale() { float width = (float)(_percent) / 100.0f * _totalLength; - static_cast(_barRenderer)->setPreferredSize(Size(width, _size.height)); + static_cast(_barRenderer)->setPreferredSize(Size(width, _contentSize.height)); } std::string LoadingBar::getDescription() const diff --git a/cocos/ui/UIRichText.cpp b/cocos/ui/UIRichText.cpp index 49546be2e8..03e59cb301 100644 --- a/cocos/ui/UIRichText.cpp +++ b/cocos/ui/UIRichText.cpp @@ -414,7 +414,7 @@ void RichText::formarRenderers() nextPosX += l->getContentSize().width; } } - _elementRenderersContainer->setContentSize(_size); + _elementRenderersContainer->setContentSize(_contentSize); delete [] maxHeights; } @@ -430,13 +430,13 @@ void RichText::formarRenderers() if (_ignoreSize) { Size s = getVirtualRendererSize(); - _size = s; + _contentSize = s; } else { - _size = _customSize; + _contentSize = _customSize; } - updateContentSizeWithTextureSize(_size); + updateContentSizeWithTextureSize(_contentSize); _elementRenderersContainer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f); } diff --git a/cocos/ui/UIScrollView.cpp b/cocos/ui/UIScrollView.cpp index 8ed6d8231f..5977deb432 100644 --- a/cocos/ui/UIScrollView.cpp +++ b/cocos/ui/UIScrollView.cpp @@ -128,29 +128,29 @@ void ScrollView::initRenderer() void ScrollView::onSizeChanged() { Layout::onSizeChanged(); - _topBoundary = _size.height; - _rightBoundary = _size.width; - float bounceBoundaryParameterX = _size.width / 3.0f; - float bounceBoundaryParameterY = _size.height / 3.0f; - _bounceTopBoundary = _size.height - bounceBoundaryParameterY; + _topBoundary = _contentSize.height; + _rightBoundary = _contentSize.width; + float bounceBoundaryParameterX = _contentSize.width / 3.0f; + float bounceBoundaryParameterY = _contentSize.height / 3.0f; + _bounceTopBoundary = _contentSize.height - bounceBoundaryParameterY; _bounceBottomBoundary = bounceBoundaryParameterY; _bounceLeftBoundary = bounceBoundaryParameterX; - _bounceRightBoundary = _size.width - bounceBoundaryParameterX; + _bounceRightBoundary = _contentSize.width - bounceBoundaryParameterX; Size innerSize = _innerContainer->getSize(); float orginInnerSizeWidth = innerSize.width; float orginInnerSizeHeight = innerSize.height; - float innerSizeWidth = MAX(orginInnerSizeWidth, _size.width); - float innerSizeHeight = MAX(orginInnerSizeHeight, _size.height); + float innerSizeWidth = MAX(orginInnerSizeWidth, _contentSize.width); + float innerSizeHeight = MAX(orginInnerSizeHeight, _contentSize.height); _innerContainer->setSize(Size(innerSizeWidth, innerSizeHeight)); - _innerContainer->setPosition(Vec2(0, _size.height - _innerContainer->getSize().height)); + _innerContainer->setPosition(Vec2(0, _contentSize.height - _innerContainer->getSize().height)); } void ScrollView::setInnerContainerSize(const Size &size) { - float innerSizeWidth = _size.width; - float innerSizeHeight = _size.height; + float innerSizeWidth = _contentSize.width; + float innerSizeHeight = _contentSize.height; Size originalInnerSize = _innerContainer->getSize(); - if (size.width < _size.width) + if (size.width < _contentSize.width) { CCLOG("Inner width <= scrollview width, it will be force sized!"); } @@ -158,7 +158,7 @@ void ScrollView::setInnerContainerSize(const Size &size) { innerSizeWidth = size.width; } - if (size.height < _size.height) + if (size.height < _contentSize.height) { CCLOG("Inner height <= scrollview height, it will be force sized!"); } @@ -179,7 +179,7 @@ void ScrollView::setInnerContainerSize(const Size &size) } case Direction::HORIZONTAL: { - if (_innerContainer->getRightBoundary() <= _size.width) + if (_innerContainer->getRightBoundary() <= _contentSize.width) { Size newInnerSize = _innerContainer->getSize(); float offset = originalInnerSize.width - newInnerSize.width; @@ -192,7 +192,7 @@ void ScrollView::setInnerContainerSize(const Size &size) Size newInnerSize = _innerContainer->getSize(); float offsetY = originalInnerSize.height - newInnerSize.height; float offsetX = 0.0f; - if (_innerContainer->getRightBoundary() <= _size.width) + if (_innerContainer->getRightBoundary() <= _contentSize.width) { offsetX = originalInnerSize.width - newInnerSize.width; } @@ -204,19 +204,23 @@ void ScrollView::setInnerContainerSize(const Size &size) } if (_innerContainer->getLeftBoundary() > 0.0f) { - _innerContainer->setPosition(Vec2(_innerContainer->getAnchorPoint().x * _innerContainer->getSize().width, _innerContainer->getPosition().y)); + _innerContainer->setPosition(Vec2(_innerContainer->getAnchorPoint().x * _innerContainer->getSize().width, + _innerContainer->getPosition().y)); } - if (_innerContainer->getRightBoundary() < _size.width) + if (_innerContainer->getRightBoundary() < _contentSize.width) { - _innerContainer->setPosition(Vec2(_size.width - ((1.0f - _innerContainer->getAnchorPoint().x) * _innerContainer->getSize().width), _innerContainer->getPosition().y)); + _innerContainer->setPosition(Vec2(_contentSize.width - ((1.0f - _innerContainer->getAnchorPoint().x) * _innerContainer->getSize().width), + _innerContainer->getPosition().y)); } if (_innerContainer->getPosition().y > 0.0f) { - _innerContainer->setPosition(Vec2(_innerContainer->getPosition().x, _innerContainer->getAnchorPoint().y * _innerContainer->getSize().height)); + _innerContainer->setPosition(Vec2(_innerContainer->getPosition().x, + _innerContainer->getAnchorPoint().y * _innerContainer->getSize().height)); } - if (_innerContainer->getTopBoundary() < _size.height) + if (_innerContainer->getTopBoundary() < _contentSize.height) { - _innerContainer->setPosition(Vec2(_innerContainer->getPosition().x, _size.height - (1.0f - _innerContainer->getAnchorPoint().y) * _innerContainer->getSize().height)); + _innerContainer->setPosition(Vec2(_innerContainer->getPosition().x, + _contentSize.height - (1.0f - _innerContainer->getAnchorPoint().y) * _innerContainer->getSize().height)); } } @@ -359,14 +363,14 @@ bool ScrollView::checkNeedBounce() { if (_topBounceNeeded && _leftBounceNeeded) { - Vec2 scrollVector = Vec2(0.0f, _size.height) - Vec2(_innerContainer->getLeftBoundary(), _innerContainer->getTopBoundary()); + Vec2 scrollVector = Vec2(0.0f, _contentSize.height) - Vec2(_innerContainer->getLeftBoundary(), _innerContainer->getTopBoundary()); float orSpeed = scrollVector.getLength()/(0.2f); _bounceDir = scrollVector.getNormalized(); startBounceChildren(orSpeed); } else if (_topBounceNeeded && _rightBounceNeeded) { - Vec2 scrollVector = Vec2(_size.width, _size.height) - Vec2(_innerContainer->getRightBoundary(), _innerContainer->getTopBoundary()); + Vec2 scrollVector = Vec2(_contentSize.width, _contentSize.height) - Vec2(_innerContainer->getRightBoundary(), _innerContainer->getTopBoundary()); float orSpeed = scrollVector.getLength()/(0.2f); _bounceDir = scrollVector.getNormalized(); startBounceChildren(orSpeed); @@ -380,14 +384,14 @@ bool ScrollView::checkNeedBounce() } else if (_bottomBounceNeeded && _rightBounceNeeded) { - Vec2 scrollVector = Vec2(_size.width, 0.0f) - Vec2(_innerContainer->getRightBoundary(), _innerContainer->getBottomBoundary()); + Vec2 scrollVector = Vec2(_contentSize.width, 0.0f) - Vec2(_innerContainer->getRightBoundary(), _innerContainer->getBottomBoundary()); float orSpeed = scrollVector.getLength()/(0.2f); _bounceDir = scrollVector.getNormalized(); startBounceChildren(orSpeed); } else if (_topBounceNeeded) { - Vec2 scrollVector = Vec2(0.0f, _size.height) - Vec2(0.0f, _innerContainer->getTopBoundary()); + Vec2 scrollVector = Vec2(0.0f, _contentSize.height) - Vec2(0.0f, _innerContainer->getTopBoundary()); float orSpeed = scrollVector.getLength()/(0.2f); _bounceDir = scrollVector.getNormalized(); startBounceChildren(orSpeed); @@ -408,7 +412,7 @@ bool ScrollView::checkNeedBounce() } else if (_rightBounceNeeded) { - Vec2 scrollVector = Vec2(_size.width, 0.0f) - Vec2(_innerContainer->getRightBoundary(), 0.0f); + Vec2 scrollVector = Vec2(_contentSize.width, 0.0f) - Vec2(_innerContainer->getRightBoundary(), 0.0f); float orSpeed = scrollVector.getLength()/(0.2f); _bounceDir = scrollVector.getNormalized(); startBounceChildren(orSpeed); @@ -518,23 +522,23 @@ void ScrollView::jumpToDestination(const Vec2 &des) case Direction::VERTICAL: if (des.y <= 0) { - finalOffsetY = MAX(des.y, _size.height - _innerContainer->getSize().height); + finalOffsetY = MAX(des.y, _contentSize.height - _innerContainer->getSize().height); } break; case Direction::HORIZONTAL: if (des.x <= 0) { - finalOffsetX = MAX(des.x, _size.width - _innerContainer->getSize().width); + finalOffsetX = MAX(des.x, _contentSize.width - _innerContainer->getSize().width); } break; case Direction::BOTH: if (des.y <= 0) { - finalOffsetY = MAX(des.y, _size.height - _innerContainer->getSize().height); + finalOffsetY = MAX(des.y, _contentSize.height - _innerContainer->getSize().height); } if (des.x <= 0) { - finalOffsetX = MAX(des.x, _size.width - _innerContainer->getSize().width); + finalOffsetX = MAX(des.x, _contentSize.width - _innerContainer->getSize().width); } break; default: @@ -1217,7 +1221,8 @@ void ScrollView::scrollToBottom(float time, bool attenuated) void ScrollView::scrollToTop(float time, bool attenuated) { - startAutoScrollChildrenWithDestination(Vec2(_innerContainer->getPosition().x, _size.height - _innerContainer->getSize().height), time, attenuated); + startAutoScrollChildrenWithDestination(Vec2(_innerContainer->getPosition().x, + _contentSize.height - _innerContainer->getSize().height), time, attenuated); } void ScrollView::scrollToLeft(float time, bool attenuated) @@ -1227,7 +1232,8 @@ void ScrollView::scrollToLeft(float time, bool attenuated) void ScrollView::scrollToRight(float time, bool attenuated) { - startAutoScrollChildrenWithDestination(Vec2(_size.width - _innerContainer->getSize().width, _innerContainer->getPosition().y), time, attenuated); + startAutoScrollChildrenWithDestination(Vec2(_contentSize.width - _innerContainer->getSize().width, + _innerContainer->getPosition().y), time, attenuated); } void ScrollView::scrollToTopLeft(float time, bool attenuated) @@ -1237,7 +1243,7 @@ void ScrollView::scrollToTopLeft(float time, bool attenuated) CCLOG("Scroll diretion is not both!"); return; } - startAutoScrollChildrenWithDestination(Vec2(0.0f, _size.height - _innerContainer->getSize().height), time, attenuated); + startAutoScrollChildrenWithDestination(Vec2(0.0f, _contentSize.height - _innerContainer->getSize().height), time, attenuated); } void ScrollView::scrollToTopRight(float time, bool attenuated) @@ -1247,7 +1253,8 @@ void ScrollView::scrollToTopRight(float time, bool attenuated) CCLOG("Scroll diretion is not both!"); return; } - startAutoScrollChildrenWithDestination(Vec2(_size.width - _innerContainer->getSize().width, _size.height - _innerContainer->getSize().height), time, attenuated); + startAutoScrollChildrenWithDestination(Vec2(_contentSize.width - _innerContainer->getSize().width, + _contentSize.height - _innerContainer->getSize().height), time, attenuated); } void ScrollView::scrollToBottomLeft(float time, bool attenuated) @@ -1267,19 +1274,19 @@ void ScrollView::scrollToBottomRight(float time, bool attenuated) CCLOG("Scroll diretion is not both!"); return; } - startAutoScrollChildrenWithDestination(Vec2(_size.width - _innerContainer->getSize().width, 0.0f), time, attenuated); + startAutoScrollChildrenWithDestination(Vec2(_contentSize.width - _innerContainer->getSize().width, 0.0f), time, attenuated); } void ScrollView::scrollToPercentVertical(float percent, float time, bool attenuated) { - float minY = _size.height - _innerContainer->getSize().height; + float minY = _contentSize.height - _innerContainer->getSize().height; float h = - minY; startAutoScrollChildrenWithDestination(Vec2(_innerContainer->getPosition().x, minY + percent * h / 100.0f), time, attenuated); } void ScrollView::scrollToPercentHorizontal(float percent, float time, bool attenuated) { - float w = _innerContainer->getSize().width - _size.width; + float w = _innerContainer->getSize().width - _contentSize.width; startAutoScrollChildrenWithDestination(Vec2(-(percent * w / 100.0f), _innerContainer->getPosition().y), time, attenuated); } @@ -1289,9 +1296,9 @@ void ScrollView::scrollToPercentBothDirection(const Vec2& percent, float time, b { return; } - float minY = _size.height - _innerContainer->getSize().height; + float minY = _contentSize.height - _innerContainer->getSize().height; float h = - minY; - float w = _innerContainer->getSize().width - _size.width; + float w = _innerContainer->getSize().width - _contentSize.width; startAutoScrollChildrenWithDestination(Vec2(-(percent.x * w / 100.0f), minY + percent.y * h / 100.0f), time, attenuated); } @@ -1302,7 +1309,8 @@ void ScrollView::jumpToBottom() void ScrollView::jumpToTop() { - jumpToDestination(Vec2(_innerContainer->getPosition().x, _size.height - _innerContainer->getSize().height)); + jumpToDestination(Vec2(_innerContainer->getPosition().x, + _contentSize.height - _innerContainer->getSize().height)); } void ScrollView::jumpToLeft() @@ -1312,7 +1320,7 @@ void ScrollView::jumpToLeft() void ScrollView::jumpToRight() { - jumpToDestination(Vec2(_size.width - _innerContainer->getSize().width, _innerContainer->getPosition().y)); + jumpToDestination(Vec2(_contentSize.width - _innerContainer->getSize().width, _innerContainer->getPosition().y)); } void ScrollView::jumpToTopLeft() @@ -1322,7 +1330,7 @@ void ScrollView::jumpToTopLeft() CCLOG("Scroll diretion is not both!"); return; } - jumpToDestination(Vec2(0.0f, _size.height - _innerContainer->getSize().height)); + jumpToDestination(Vec2(0.0f, _contentSize.height - _innerContainer->getSize().height)); } void ScrollView::jumpToTopRight() @@ -1332,7 +1340,8 @@ void ScrollView::jumpToTopRight() CCLOG("Scroll diretion is not both!"); return; } - jumpToDestination(Vec2(_size.width - _innerContainer->getSize().width, _size.height - _innerContainer->getSize().height)); + jumpToDestination(Vec2(_contentSize.width - _innerContainer->getSize().width, + _contentSize.height - _innerContainer->getSize().height)); } void ScrollView::jumpToBottomLeft() @@ -1352,19 +1361,19 @@ void ScrollView::jumpToBottomRight() CCLOG("Scroll diretion is not both!"); return; } - jumpToDestination(Vec2(_size.width - _innerContainer->getSize().width, 0.0f)); + jumpToDestination(Vec2(_contentSize.width - _innerContainer->getSize().width, 0.0f)); } void ScrollView::jumpToPercentVertical(float percent) { - float minY = _size.height - _innerContainer->getSize().height; + float minY = _contentSize.height - _innerContainer->getSize().height; float h = - minY; jumpToDestination(Vec2(_innerContainer->getPosition().x, minY + percent * h / 100.0f)); } void ScrollView::jumpToPercentHorizontal(float percent) { - float w = _innerContainer->getSize().width - _size.width; + float w = _innerContainer->getSize().width - _contentSize.width; jumpToDestination(Vec2(-(percent * w / 100.0f), _innerContainer->getPosition().y)); } @@ -1374,9 +1383,9 @@ void ScrollView::jumpToPercentBothDirection(const Vec2& percent) { return; } - float minY = _size.height - _innerContainer->getSize().height; + float minY = _contentSize.height - _innerContainer->getSize().height; float h = - minY; - float w = _innerContainer->getSize().width - _size.width; + float w = _innerContainer->getSize().width - _contentSize.width; jumpToDestination(Vec2(-(percent.x * w / 100.0f), minY + percent.y * h / 100.0f)); } diff --git a/cocos/ui/UISlider.cpp b/cocos/ui/UISlider.cpp index 7a2e9f441b..65886298a7 100644 --- a/cocos/ui/UISlider.cpp +++ b/cocos/ui/UISlider.cpp @@ -500,14 +500,14 @@ void Slider::barRendererScaleChangedWithSize() { _barRenderer->setScale(1.0f); - _barLength = _size.width; + _barLength = _contentSize.width; } else { - _barLength = _size.width; + _barLength = _contentSize.width; if (_scale9Enabled) { - static_cast(_barRenderer)->setPreferredSize(_size); + static_cast(_barRenderer)->setPreferredSize(_contentSize); } else { @@ -517,8 +517,8 @@ void Slider::barRendererScaleChangedWithSize() _barRenderer->setScale(1.0f); return; } - float bscaleX = _size.width / btextureSize.width; - float bscaleY = _size.height / btextureSize.height; + float bscaleX = _contentSize.width / btextureSize.width; + float bscaleY = _contentSize.height / btextureSize.height; _barRenderer->setScaleX(bscaleX); _barRenderer->setScaleY(bscaleY); } @@ -534,8 +534,8 @@ void Slider::progressBarRendererScaleChangedWithSize() if (!_scale9Enabled) { Size ptextureSize = _progressBarTextureSize; - float pscaleX = _size.width / ptextureSize.width; - float pscaleY = _size.height / ptextureSize.height; + float pscaleX = _contentSize.width / ptextureSize.width; + float pscaleY = _contentSize.height / ptextureSize.height; _progressBarRenderer->setScaleX(pscaleX); _progressBarRenderer->setScaleY(pscaleY); } @@ -544,7 +544,7 @@ void Slider::progressBarRendererScaleChangedWithSize() { if (_scale9Enabled) { - static_cast(_progressBarRenderer)->setPreferredSize(_size); + static_cast(_progressBarRenderer)->setPreferredSize(_contentSize); _progressBarTextureSize = _progressBarRenderer->getContentSize(); } else @@ -555,8 +555,8 @@ void Slider::progressBarRendererScaleChangedWithSize() _progressBarRenderer->setScale(1.0f); return; } - float pscaleX = _size.width / ptextureSize.width; - float pscaleY = _size.height / ptextureSize.height; + float pscaleX = _contentSize.width / ptextureSize.width; + float pscaleY = _contentSize.height / ptextureSize.height; _progressBarRenderer->setScaleX(pscaleX); _progressBarRenderer->setScaleY(pscaleY); } diff --git a/cocos/ui/UIText.cpp b/cocos/ui/UIText.cpp index 0ce8d0f57a..d8be8244ac 100644 --- a/cocos/ui/UIText.cpp +++ b/cocos/ui/UIText.cpp @@ -302,15 +302,15 @@ void Text::labelScaleChangedWithSize() } else { - _labelRenderer->setDimensions(_size.width,_size.height); + _labelRenderer->setDimensions(_contentSize.width,_contentSize.height); Size textureSize = _labelRenderer->getContentSize(); if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) { _labelRenderer->setScale(1.0f); return; } - float scaleX = _size.width / textureSize.width; - float scaleY = _size.height / textureSize.height; + float scaleX = _contentSize.width / textureSize.width; + float scaleY = _contentSize.height / textureSize.height; _labelRenderer->setScaleX(scaleX); _labelRenderer->setScaleY(scaleY); _normalScaleValueX = scaleX; diff --git a/cocos/ui/UITextAtlas.cpp b/cocos/ui/UITextAtlas.cpp index e7bac16081..6419e7b11a 100644 --- a/cocos/ui/UITextAtlas.cpp +++ b/cocos/ui/UITextAtlas.cpp @@ -159,8 +159,8 @@ void TextAtlas::labelAtlasScaleChangedWithSize() _labelAtlasRenderer->setScale(1.0f); return; } - float scaleX = _size.width / textureSize.width; - float scaleY = _size.height / textureSize.height; + float scaleX = _contentSize.width / textureSize.width; + float scaleY = _contentSize.height / textureSize.height; _labelAtlasRenderer->setScaleX(scaleX); _labelAtlasRenderer->setScaleY(scaleY); } diff --git a/cocos/ui/UITextBMFont.cpp b/cocos/ui/UITextBMFont.cpp index 4e4c7f34a7..52187ecda1 100644 --- a/cocos/ui/UITextBMFont.cpp +++ b/cocos/ui/UITextBMFont.cpp @@ -155,8 +155,8 @@ void TextBMFont::labelBMFontScaleChangedWithSize() _labelBMFontRenderer->setScale(1.0f); return; } - float scaleX = _size.width / textureSize.width; - float scaleY = _size.height / textureSize.height; + float scaleX = _contentSize.width / textureSize.width; + float scaleY = _contentSize.height / textureSize.height; _labelBMFontRenderer->setScaleX(scaleX); _labelBMFontRenderer->setScaleY(scaleY); } diff --git a/cocos/ui/UITextField.cpp b/cocos/ui/UITextField.cpp index 7159fa0f6b..1cbbd901c0 100644 --- a/cocos/ui/UITextField.cpp +++ b/cocos/ui/UITextField.cpp @@ -783,15 +783,15 @@ void TextField::textfieldRendererScaleChangedWithSize() } else { - _textFieldRenderer->setDimensions(_size.width,_size.height); + _textFieldRenderer->setDimensions(_contentSize.width, _contentSize.height); Size textureSize = getContentSize(); if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) { _textFieldRenderer->setScale(1.0f); return; } - float scaleX = _size.width / textureSize.width; - float scaleY = _size.height / textureSize.height; + float scaleX = _contentSize.width / textureSize.width; + float scaleY = _contentSize.height / textureSize.height; _textFieldRenderer->setScaleX(scaleX); _textFieldRenderer->setScaleY(scaleY); } diff --git a/cocos/ui/UIWidget.cpp b/cocos/ui/UIWidget.cpp index 5a18f10f74..068b6221b5 100644 --- a/cocos/ui/UIWidget.cpp +++ b/cocos/ui/UIWidget.cpp @@ -145,7 +145,6 @@ _touchEndPosition(Vec2::ZERO), _touchEventListener(nullptr), _touchEventSelector(nullptr), _actionTag(0), -_size(Size::ZERO), _customSize(Size::ZERO), _ignoreSize(false), _affectByClipping(false), @@ -258,11 +257,11 @@ void Widget::setSize(const Size &size) _customSize = size; if (_ignoreSize) { - _size = getVirtualRendererSize(); + _contentSize = getVirtualRendererSize(); } else { - _size = size; + _contentSize = size; } if (_running) { @@ -309,11 +308,11 @@ void Widget::setSizePercent(const Vec2 &percent) } if (_ignoreSize) { - _size = getVirtualRendererSize(); + _contentSize = getVirtualRendererSize(); } else { - _size = cSize; + _contentSize = cSize; } _customSize = cSize; onSizeChanged(); @@ -342,11 +341,11 @@ void Widget::updateSizeAndPosition(const cocos2d::Size &parentSize) { if (_ignoreSize) { - _size = getVirtualRendererSize(); + _contentSize = getVirtualRendererSize(); } else { - _size = _customSize; + _contentSize = _customSize; } float spx = 0.0f; float spy = 0.0f; @@ -366,11 +365,11 @@ void Widget::updateSizeAndPosition(const cocos2d::Size &parentSize) Size cSize = Size(parentSize.width * _sizePercent.x , parentSize.height * _sizePercent.y); if (_ignoreSize) { - _size = getVirtualRendererSize(); + _contentSize = getVirtualRendererSize(); } else { - _size = cSize; + _contentSize = cSize; } _customSize = cSize; break; @@ -425,11 +424,11 @@ void Widget::ignoreContentAdaptWithSize(bool ignore) if (_ignoreSize) { Size s = getVirtualRendererSize(); - _size = s; + _contentSize = s; } else { - _size = _customSize; + _contentSize = _customSize; } onSizeChanged(); } @@ -441,7 +440,7 @@ bool Widget::isIgnoreContentAdaptWithSize() const const Size& Widget::getSize() const { - return _size; + return _contentSize; } const Size& Widget::getCustomSize() const @@ -466,7 +465,7 @@ Node* Widget::getVirtualRenderer() void Widget::onSizeChanged() { - setContentSize(_size); + setContentSize(_contentSize); for (auto& child : getChildren()) { Widget* widgetChild = dynamic_cast(child); @@ -486,11 +485,11 @@ void Widget::updateContentSizeWithTextureSize(const cocos2d::Size &size) { if (_ignoreSize) { - _size = size; + _contentSize = size; } else { - _size = _customSize; + _contentSize = _customSize; } onSizeChanged(); } @@ -911,22 +910,22 @@ bool Widget::isEnabled() const float Widget::getLeftBoundary() const { - return getPosition().x - getAnchorPoint().x * _size.width; + return getPosition().x - getAnchorPoint().x * _contentSize.width; } float Widget::getBottomBoundary() const { - return getPosition().y - getAnchorPoint().y * _size.height; + return getPosition().y - getAnchorPoint().y * _contentSize.height; } float Widget::getRightBoundary() const { - return getLeftBoundary() + _size.width; + return getLeftBoundary() + _contentSize.width; } float Widget::getTopBoundary() const { - return getBottomBoundary() + _size.height; + return getBottomBoundary() + _contentSize.height; } const Vec2& Widget::getTouchBeganPosition()const @@ -1012,7 +1011,7 @@ void Widget::copyProperties(Widget *widget) setName(widget->getName()); setActionTag(widget->getActionTag()); _ignoreSize = widget->_ignoreSize; - _size = widget->_size; + _contentSize = widget->_contentSize; _customSize = widget->_customSize; _sizeType = widget->getSizeType(); _sizePercent = widget->_sizePercent; diff --git a/cocos/ui/UIWidget.h b/cocos/ui/UIWidget.h index 4d201720b0..c059f19a5e 100644 --- a/cocos/ui/UIWidget.h +++ b/cocos/ui/UIWidget.h @@ -407,7 +407,7 @@ public: const Size& getCustomSize() const; - virtual const Size& getLayoutSize() {return _size;}; + virtual const Size& getLayoutSize() {return _contentSize;}; /** * Returns size percent of widget @@ -659,7 +659,6 @@ protected: //use int _actionTag; - Size _size; Size _customSize; Vec2 _sizePercent;