From 3f4db26a2bc59147447b0c038ce7963c2c7ab2ba Mon Sep 17 00:00:00 2001 From: CaiWenzhi Date: Fri, 10 Jan 2014 16:02:23 +0800 Subject: [PATCH 01/13] Fixed bugs --- cocos/gui/UIButton.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cocos/gui/UIButton.cpp b/cocos/gui/UIButton.cpp index 5a6a2dc54f..82ed33dfec 100644 --- a/cocos/gui/UIButton.cpp +++ b/cocos/gui/UIButton.cpp @@ -366,8 +366,7 @@ void Button::onPressStateChangedToNormal() else { _buttonNormalRenderer->stopAllActions(); - Action *zoomAction = ScaleTo::create(0.05f, _normalTextureScaleXInSize, _normalTextureScaleYInSize); - _buttonNormalRenderer->runAction(zoomAction); + _buttonNormalRenderer->setScale(_normalTextureScaleXInSize, _normalTextureScaleYInSize); } } @@ -393,8 +392,7 @@ void Button::onPressStateChangedToPressed() _buttonClickedRenderer->setVisible(true); _buttonDisableRenderer->setVisible(false); _buttonNormalRenderer->stopAllActions(); - Action *zoomAction = ScaleTo::create(0.05f, _pressedTextureScaleXInSize + 0.1f, _pressedTextureScaleYInSize + 0.1f); - _buttonNormalRenderer->runAction(zoomAction); + _buttonNormalRenderer->setScale(_normalTextureScaleXInSize + 0.1f, _normalTextureScaleYInSize + 0.1f); } } From 4e2d6143afbff47eb2d7fad7023e4b6544273b1a Mon Sep 17 00:00:00 2001 From: CaiWenzhi Date: Fri, 10 Jan 2014 17:02:16 +0800 Subject: [PATCH 02/13] Fixed bug of reader --- .../cocostudio/CCSGUIReader.cpp | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/cocos/editor-support/cocostudio/CCSGUIReader.cpp b/cocos/editor-support/cocostudio/CCSGUIReader.cpp index 349bba5dfe..016ddeafb8 100644 --- a/cocos/editor-support/cocostudio/CCSGUIReader.cpp +++ b/cocos/editor-support/cocostudio/CCSGUIReader.cpp @@ -558,12 +558,16 @@ void WidgetPropertiesReader0250::setPropsForLabelFromJsonDictionary(Widget*widge { label->setFontName(DICTOOL->getStringValue_json(options, "fontName")); } - bool aw = DICTOOL->checkObjectExist_json(options, "areaWidth"); - bool ah = DICTOOL->checkObjectExist_json(options, "areaHeight"); - if (aw && ah) + bool handleDimensions = DICTOOL->getBooleanValue_json(options, "handleDimensions"); + if (handleDimensions) { - Size size = Size(DICTOOL->getFloatValue_json(options, "areaWidth"),DICTOOL->getFloatValue_json(options,"areaHeight")); - label->setTextAreaSize(size); + bool aw = DICTOOL->checkObjectExist_json(options, "areaWidth"); + bool ah = DICTOOL->checkObjectExist_json(options, "areaHeight"); + if (aw && ah) + { + Size size = Size(DICTOOL->getFloatValue_json(options, "areaWidth"),DICTOOL->getFloatValue_json(options,"areaHeight")); + label->setTextAreaSize(size); + } } bool ha = DICTOOL->checkObjectExist_json(options, "hAlignment"); if (ha) @@ -1449,12 +1453,16 @@ void WidgetPropertiesReader0300::setPropsForLabelFromJsonDictionary(Widget*widge { label->setFontName(DICTOOL->getStringValue_json(options, "fontName")); } - bool aw = DICTOOL->checkObjectExist_json(options, "areaWidth"); - bool ah = DICTOOL->checkObjectExist_json(options, "areaHeight"); - if (aw && ah) + bool handleDimensions = DICTOOL->getBooleanValue_json(options, "handleDimensions"); + if (handleDimensions) { - Size size = Size(DICTOOL->getFloatValue_json(options, "areaWidth"),DICTOOL->getFloatValue_json(options,"areaHeight")); - label->setTextAreaSize(size); + bool aw = DICTOOL->checkObjectExist_json(options, "areaWidth"); + bool ah = DICTOOL->checkObjectExist_json(options, "areaHeight"); + if (aw && ah) + { + Size size = Size(DICTOOL->getFloatValue_json(options, "areaWidth"),DICTOOL->getFloatValue_json(options,"areaHeight")); + label->setTextAreaSize(size); + } } bool ha = DICTOOL->checkObjectExist_json(options, "hAlignment"); if (ha) From fdfa84ce20c04dac3f75b359a66a587ff53511ca Mon Sep 17 00:00:00 2001 From: CaiWenzhi Date: Tue, 14 Jan 2014 14:37:31 +0800 Subject: [PATCH 03/13] Fixed bugs. --- .../cocostudio/CCSGUIReader.cpp | 28 +++++++------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/cocos/editor-support/cocostudio/CCSGUIReader.cpp b/cocos/editor-support/cocostudio/CCSGUIReader.cpp index 016ddeafb8..349bba5dfe 100644 --- a/cocos/editor-support/cocostudio/CCSGUIReader.cpp +++ b/cocos/editor-support/cocostudio/CCSGUIReader.cpp @@ -558,16 +558,12 @@ void WidgetPropertiesReader0250::setPropsForLabelFromJsonDictionary(Widget*widge { label->setFontName(DICTOOL->getStringValue_json(options, "fontName")); } - bool handleDimensions = DICTOOL->getBooleanValue_json(options, "handleDimensions"); - if (handleDimensions) + bool aw = DICTOOL->checkObjectExist_json(options, "areaWidth"); + bool ah = DICTOOL->checkObjectExist_json(options, "areaHeight"); + if (aw && ah) { - bool aw = DICTOOL->checkObjectExist_json(options, "areaWidth"); - bool ah = DICTOOL->checkObjectExist_json(options, "areaHeight"); - if (aw && ah) - { - Size size = Size(DICTOOL->getFloatValue_json(options, "areaWidth"),DICTOOL->getFloatValue_json(options,"areaHeight")); - label->setTextAreaSize(size); - } + Size size = Size(DICTOOL->getFloatValue_json(options, "areaWidth"),DICTOOL->getFloatValue_json(options,"areaHeight")); + label->setTextAreaSize(size); } bool ha = DICTOOL->checkObjectExist_json(options, "hAlignment"); if (ha) @@ -1453,16 +1449,12 @@ void WidgetPropertiesReader0300::setPropsForLabelFromJsonDictionary(Widget*widge { label->setFontName(DICTOOL->getStringValue_json(options, "fontName")); } - bool handleDimensions = DICTOOL->getBooleanValue_json(options, "handleDimensions"); - if (handleDimensions) + bool aw = DICTOOL->checkObjectExist_json(options, "areaWidth"); + bool ah = DICTOOL->checkObjectExist_json(options, "areaHeight"); + if (aw && ah) { - bool aw = DICTOOL->checkObjectExist_json(options, "areaWidth"); - bool ah = DICTOOL->checkObjectExist_json(options, "areaHeight"); - if (aw && ah) - { - Size size = Size(DICTOOL->getFloatValue_json(options, "areaWidth"),DICTOOL->getFloatValue_json(options,"areaHeight")); - label->setTextAreaSize(size); - } + Size size = Size(DICTOOL->getFloatValue_json(options, "areaWidth"),DICTOOL->getFloatValue_json(options,"areaHeight")); + label->setTextAreaSize(size); } bool ha = DICTOOL->checkObjectExist_json(options, "hAlignment"); if (ha) From fdf5a4c0b530242be7a29259bc376a010afbb236 Mon Sep 17 00:00:00 2001 From: CaiWenzhi Date: Wed, 15 Jan 2014 20:06:49 +0800 Subject: [PATCH 04/13] Fixed bug of reader. --- cocos/editor-support/cocostudio/CCSGUIReader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos/editor-support/cocostudio/CCSGUIReader.cpp b/cocos/editor-support/cocostudio/CCSGUIReader.cpp index 349bba5dfe..ac3dc907ab 100644 --- a/cocos/editor-support/cocostudio/CCSGUIReader.cpp +++ b/cocos/editor-support/cocostudio/CCSGUIReader.cpp @@ -474,7 +474,7 @@ void WidgetPropertiesReader0250::setPropsForCheckBoxFromJsonDictionary(Widget*wi { checkBox->loadTextures(backGroundFileName_tp, backGroundSelectedFileName_tp, frontCrossFileName_tp,backGroundDisabledFileName_tp,frontCrossDisabledFileName_tp); } - + checkBox->setSelectedState(DICTOOL->getBooleanValue_json(options, "selectedState")); setColorPropsForWidgetFromJsonDictionary(widget,options); } @@ -1364,7 +1364,7 @@ void WidgetPropertiesReader0300::setPropsForCheckBoxFromJsonDictionary(Widget*wi default: break; } - + checkBox->setSelectedState(DICTOOL->getBooleanValue_json(options, "selectedState")); setColorPropsForWidgetFromJsonDictionary(widget,options); } From bea46fa2908335f58b4f803fb849626d88795e7a Mon Sep 17 00:00:00 2001 From: CaiWenzhi Date: Fri, 17 Jan 2014 13:10:04 +0800 Subject: [PATCH 05/13] Add clone method to LayoutParameter --- cocos/gui/UILayoutParameter.cpp | 93 +++++++++++++++++++++++++-------- cocos/gui/UILayoutParameter.h | 53 +++++++++++-------- cocos/gui/UILoadingBar.cpp | 1 + cocos/gui/UIWidget.cpp | 5 ++ 4 files changed, 108 insertions(+), 44 deletions(-) diff --git a/cocos/gui/UILayoutParameter.cpp b/cocos/gui/UILayoutParameter.cpp index d0a98f4d0d..bbde56f9e3 100644 --- a/cocos/gui/UILayoutParameter.cpp +++ b/cocos/gui/UILayoutParameter.cpp @@ -1,26 +1,26 @@ /**************************************************************************** -Copyright (c) 2013-2014 Chukong Technologies Inc. - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ + Copyright (c) 2013-2014 Chukong Technologies Inc. + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ #include "gui/UILayoutParameter.h" #include "gui/UILayout.h" @@ -56,6 +56,23 @@ LayoutParameterType LayoutParameter::getLayoutType() const { return _layoutParameterType; } + +LayoutParameter* LayoutParameter::clone() +{ + LayoutParameter* clonedParameter = createCloneInstance(); + clonedParameter->copyProperties(this); + return clonedParameter; +} + +LayoutParameter* LayoutParameter::createCloneInstance() +{ + return LayoutParameter::create(); +} + +void LayoutParameter::copyProperties(LayoutParameter *model) +{ + _margin = model->_margin; +} LinearLayoutParameter* LinearLayoutParameter::create() { @@ -78,6 +95,21 @@ LinearGravity LinearLayoutParameter::getGravity() const { return _linearGravity; } + +LayoutParameter* LinearLayoutParameter::createCloneInstance() +{ + return LinearLayoutParameter::create(); +} + +void LinearLayoutParameter::copyProperties(LayoutParameter *model) +{ + LayoutParameter::copyProperties(model); + LinearLayoutParameter* parameter = dynamic_cast(model); + if (parameter) + { + setGravity(parameter->_linearGravity); + } +} RelativeLayoutParameter* RelativeLayoutParameter::create() { @@ -120,6 +152,23 @@ const char* RelativeLayoutParameter::getRelativeName() const { return _relativeLayoutName.c_str(); } + +LayoutParameter* RelativeLayoutParameter::createCloneInstance() +{ + return RelativeLayoutParameter::create(); +} + +void RelativeLayoutParameter::copyProperties(LayoutParameter *model) +{ + LayoutParameter::copyProperties(model); + RelativeLayoutParameter* parameter = dynamic_cast(model); + if (parameter) + { + setAlign(parameter->_relativeAlign); + setRelativeName(parameter->_relativeLayoutName.c_str()); + setRelativeToWidgetName(parameter->_relativeWidgetName.c_str()); + } +} } diff --git a/cocos/gui/UILayoutParameter.h b/cocos/gui/UILayoutParameter.h index 9065a16176..e3ad428243 100644 --- a/cocos/gui/UILayoutParameter.h +++ b/cocos/gui/UILayoutParameter.h @@ -1,26 +1,26 @@ /**************************************************************************** -Copyright (c) 2013-2014 Chukong Technologies Inc. - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ + Copyright (c) 2013-2014 Chukong Technologies Inc. + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ #ifndef __LAYOUTPARMETER_H__ #define __LAYOUTPARMETER_H__ @@ -86,6 +86,10 @@ public: * @return LayoutParameterType */ LayoutParameterType getLayoutType() const; + + LayoutParameter* clone(); + virtual LayoutParameter* createCloneInstance(); + virtual void copyProperties(LayoutParameter* model); protected: Margin _margin; LayoutParameterType _layoutParameterType; @@ -130,6 +134,8 @@ public: * @return LinearGravity */ LinearGravity getGravity() const; + virtual LayoutParameter* createCloneInstance(); + virtual void copyProperties(LayoutParameter* model); protected: LinearGravity _linearGravity; }; @@ -202,6 +208,9 @@ public: * @return name */ const char* getRelativeName() const; + + virtual LayoutParameter* createCloneInstance(); + virtual void copyProperties(LayoutParameter* model); protected: RelativeAlign _relativeAlign; std::string _relativeWidgetName; diff --git a/cocos/gui/UILoadingBar.cpp b/cocos/gui/UILoadingBar.cpp index b561c3fd7c..15ade85aef 100644 --- a/cocos/gui/UILoadingBar.cpp +++ b/cocos/gui/UILoadingBar.cpp @@ -334,6 +334,7 @@ void LoadingBar::copySpecialProperties(Widget *widget) loadTexture(loadingBar->_textureFile.c_str(), loadingBar->_renderBarTexType); setCapInsets(loadingBar->_capInsets); setPercent(loadingBar->_percent); + setDirection(loadingBar->_barType); } } diff --git a/cocos/gui/UIWidget.cpp b/cocos/gui/UIWidget.cpp index e28f4d8db0..c475a1c409 100644 --- a/cocos/gui/UIWidget.cpp +++ b/cocos/gui/UIWidget.cpp @@ -1065,6 +1065,11 @@ void Widget::copyProperties(Widget *widget) setOpacity(widget->getOpacity()); setCascadeOpacityEnabled(widget->isCascadeOpacityEnabled()); setCascadeColorEnabled(widget->isCascadeColorEnabled()); + Map& layoutParameterDic = widget->_layoutParameterDictionary; + for (auto iter = layoutParameterDic.begin(); iter != layoutParameterDic.end(); ++iter) + { + setLayoutParameter(iter->second->clone()); + } onSizeChanged(); } From f33064a2fcd2d38f7b882c227fafab2337ea5a8d Mon Sep 17 00:00:00 2001 From: CaiWenzhi Date: Fri, 17 Jan 2014 15:22:59 +0800 Subject: [PATCH 06/13] Fixed bug of label --- cocos/gui/UIText.cpp | 18 +++++------------- cocos/gui/UIText.h | 1 - 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/cocos/gui/UIText.cpp b/cocos/gui/UIText.cpp index 1899d7439a..13b014fe66 100644 --- a/cocos/gui/UIText.cpp +++ b/cocos/gui/UIText.cpp @@ -127,14 +127,11 @@ void Text::setTextVerticalAlignment(TextVAlignment alignment) void Text::setTouchScaleChangeEnabled(bool enable) { _touchScaleChangeEnabled = enable; - _normalScaleValueX = getScaleX(); - _normalScaleValueY = getScaleY(); } void Text::setScale(float fScale) { Widget::setScale(fScale); - _normalScaleValueX = _normalScaleValueY = fScale; } void Text::setScaleX(float fScaleX) @@ -158,7 +155,7 @@ void Text::onPressStateChangedToNormal() { return; } - clickScale(_normalScaleValueX, _normalScaleValueY); + _labelRenderer->setScale(_normalScaleValueX, _normalScaleValueY); } void Text::onPressStateChangedToPressed() @@ -167,9 +164,7 @@ void Text::onPressStateChangedToPressed() { return; } - _normalScaleValueX = getScaleX(); - _normalScaleValueY = getScaleY(); - clickScale(_normalScaleValueX + _onSelectedScaleOffset, _normalScaleValueY + _onSelectedScaleOffset); + _labelRenderer->setScale(_normalScaleValueX + _onSelectedScaleOffset, _normalScaleValueY + _onSelectedScaleOffset); } void Text::onPressStateChangedToDisabled() @@ -177,12 +172,6 @@ void Text::onPressStateChangedToDisabled() } -void Text::clickScale(float scaleX, float scaleY) -{ - setScaleX(scaleX); - setScaleY(scaleY); -} - void Text::setFlipX(bool flipX) { _labelRenderer->setFlippedX(flipX); @@ -231,6 +220,7 @@ void Text::labelScaleChangedWithSize() { _labelRenderer->setScale(1.0f); _size = _labelRenderer->getContentSize(); + _normalScaleValueX = _normalScaleValueY = 1.0f; } else { @@ -244,6 +234,8 @@ void Text::labelScaleChangedWithSize() float scaleY = _size.height / textureSize.height; _labelRenderer->setScaleX(scaleX); _labelRenderer->setScaleY(scaleY); + _normalScaleValueX = scaleX; + _normalScaleValueY = scaleY; } } diff --git a/cocos/gui/UIText.h b/cocos/gui/UIText.h index e41b01d321..44d558151a 100644 --- a/cocos/gui/UIText.h +++ b/cocos/gui/UIText.h @@ -166,7 +166,6 @@ protected: virtual void onPressStateChangedToPressed() override; virtual void onPressStateChangedToDisabled() override; virtual void onSizeChanged() override; - void clickScale(float scaleX, float scaleY); void labelScaleChangedWithSize(); virtual Widget* createCloneInstance() override; virtual void copySpecialProperties(Widget* model) override; From f10e1ee04cb3900665e42beb9b44172d724665c6 Mon Sep 17 00:00:00 2001 From: CaiWenzhi Date: Mon, 20 Jan 2014 13:38:13 +0800 Subject: [PATCH 07/13] optimize scissor clipping --- cocos/gui/UILayout.cpp | 130 ++++++++++++++++++++++------------------- cocos/gui/UILayout.h | 1 + 2 files changed, 70 insertions(+), 61 deletions(-) diff --git a/cocos/gui/UILayout.cpp b/cocos/gui/UILayout.cpp index 8a64ad7ed4..697c89a243 100644 --- a/cocos/gui/UILayout.cpp +++ b/cocos/gui/UILayout.cpp @@ -67,6 +67,7 @@ _scissorRectDirty(false), _clippingRect(Rect::ZERO), _clippingParent(nullptr), _doLayoutDirty(true), +_clippingRectDirty(true), _currentStencilEnabled(GL_FALSE), _currentStencilWriteMask(~0), _currentStencilFunc(GL_ALWAYS), @@ -95,6 +96,8 @@ void Layout::onEnter() { _clippingStencil->onEnter(); } + _doLayoutDirty = true; + _clippingRectDirty = true; } void Layout::onExit() @@ -421,79 +424,83 @@ void Layout::setStencilClippingSize(const Size &size) const Rect& Layout::getClippingRect() { - Point worldPos = convertToWorldSpace(Point::ZERO); - AffineTransform t = getNodeToWorldAffineTransform(); - float scissorWidth = _size.width*t.a; - float scissorHeight = _size.height*t.d; - Rect parentClippingRect; - Layout* parent = this; - bool firstClippingParentFounded = false; - while (parent) + if (_clippingRectDirty) { - parent = dynamic_cast(parent->getParent()); - if(parent) + Point worldPos = convertToWorldSpace(Point::ZERO); + AffineTransform t = getNodeToWorldAffineTransform(); + float scissorWidth = _size.width*t.a; + float scissorHeight = _size.height*t.d; + Rect parentClippingRect; + Layout* parent = this; + bool firstClippingParentFounded = false; + while (parent) { - if (parent->isClippingEnabled()) + parent = dynamic_cast(parent->getParent()); + if(parent) { - if (!firstClippingParentFounded) + if (parent->isClippingEnabled()) { - _clippingParent = parent; - firstClippingParentFounded = true; - break; + if (!firstClippingParentFounded) + { + _clippingParent = parent; + firstClippingParentFounded = true; + break; + } } } } - } - - if (_clippingParent) - { - parentClippingRect = _clippingParent->getClippingRect(); - float finalX = worldPos.x - (scissorWidth * _anchorPoint.x); - float finalY = worldPos.y - (scissorHeight * _anchorPoint.y); - float finalWidth = scissorWidth; - float finalHeight = scissorHeight; - float leftOffset = worldPos.x - parentClippingRect.origin.x; - if (leftOffset < 0.0f) + if (_clippingParent) { - finalX = parentClippingRect.origin.x; - finalWidth += leftOffset; + parentClippingRect = _clippingParent->getClippingRect(); + float finalX = worldPos.x - (scissorWidth * _anchorPoint.x); + float finalY = worldPos.y - (scissorHeight * _anchorPoint.y); + float finalWidth = scissorWidth; + float finalHeight = scissorHeight; + + float leftOffset = worldPos.x - parentClippingRect.origin.x; + if (leftOffset < 0.0f) + { + finalX = parentClippingRect.origin.x; + finalWidth += leftOffset; + } + float rightOffset = (worldPos.x + scissorWidth) - (parentClippingRect.origin.x + parentClippingRect.size.width); + if (rightOffset > 0.0f) + { + finalWidth -= rightOffset; + } + float topOffset = (worldPos.y + scissorHeight) - (parentClippingRect.origin.y + parentClippingRect.size.height); + if (topOffset > 0.0f) + { + finalHeight -= topOffset; + } + float bottomOffset = worldPos.y - parentClippingRect.origin.y; + if (bottomOffset < 0.0f) + { + finalY = parentClippingRect.origin.x; + finalHeight += bottomOffset; + } + if (finalWidth < 0.0f) + { + finalWidth = 0.0f; + } + if (finalHeight < 0.0f) + { + finalHeight = 0.0f; + } + _clippingRect.origin.x = finalX; + _clippingRect.origin.y = finalY; + _clippingRect.size.width = finalWidth; + _clippingRect.size.height = finalHeight; } - float rightOffset = (worldPos.x + scissorWidth) - (parentClippingRect.origin.x + parentClippingRect.size.width); - if (rightOffset > 0.0f) + else { - finalWidth -= rightOffset; + _clippingRect.origin.x = worldPos.x - (scissorWidth * _anchorPoint.x); + _clippingRect.origin.y = worldPos.y - (scissorHeight * _anchorPoint.y); + _clippingRect.size.width = scissorWidth; + _clippingRect.size.height = scissorHeight; } - float topOffset = (worldPos.y + scissorHeight) - (parentClippingRect.origin.y + parentClippingRect.size.height); - if (topOffset > 0.0f) - { - finalHeight -= topOffset; - } - float bottomOffset = worldPos.y - parentClippingRect.origin.y; - if (bottomOffset < 0.0f) - { - finalY = parentClippingRect.origin.x; - finalHeight += bottomOffset; - } - if (finalWidth < 0.0f) - { - finalWidth = 0.0f; - } - if (finalHeight < 0.0f) - { - finalHeight = 0.0f; - } - _clippingRect.origin.x = finalX; - _clippingRect.origin.y = finalY; - _clippingRect.size.width = finalWidth; - _clippingRect.size.height = finalHeight; - } - else - { - _clippingRect.origin.x = worldPos.x - (scissorWidth * _anchorPoint.x); - _clippingRect.origin.y = worldPos.y - (scissorHeight * _anchorPoint.y); - _clippingRect.size.width = scissorWidth; - _clippingRect.size.height = scissorHeight; + _clippingRectDirty = false; } return _clippingRect; } @@ -504,6 +511,7 @@ void Layout::onSizeChanged() setContentSize(_size); setStencilClippingSize(_size); _doLayoutDirty = true; + _clippingRectDirty = true; if (_backGroundImage) { _backGroundImage->setPosition(Point(_size.width/2.0f, _size.height/2.0f)); diff --git a/cocos/gui/UILayout.h b/cocos/gui/UILayout.h index 327707d7c8..13f7ac1e36 100644 --- a/cocos/gui/UILayout.h +++ b/cocos/gui/UILayout.h @@ -273,6 +273,7 @@ protected: Rect _clippingRect; Layout* _clippingParent; bool _doLayoutDirty; + bool _clippingRectDirty; //clipping From 223857398d4bd16de4087a9b5181f2bd239998bf Mon Sep 17 00:00:00 2001 From: CaiWenzhi Date: Mon, 20 Jan 2014 13:44:44 +0800 Subject: [PATCH 08/13] Add "override" --- cocos/gui/UILayoutParameter.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cocos/gui/UILayoutParameter.h b/cocos/gui/UILayoutParameter.h index e3ad428243..3e439e4a1a 100644 --- a/cocos/gui/UILayoutParameter.h +++ b/cocos/gui/UILayoutParameter.h @@ -134,8 +134,8 @@ public: * @return LinearGravity */ LinearGravity getGravity() const; - virtual LayoutParameter* createCloneInstance(); - virtual void copyProperties(LayoutParameter* model); + virtual LayoutParameter* createCloneInstance() override; + virtual void copyProperties(LayoutParameter* model) override; protected: LinearGravity _linearGravity; }; @@ -209,8 +209,8 @@ public: */ const char* getRelativeName() const; - virtual LayoutParameter* createCloneInstance(); - virtual void copyProperties(LayoutParameter* model); + virtual LayoutParameter* createCloneInstance() override; + virtual void copyProperties(LayoutParameter* model) override; protected: RelativeAlign _relativeAlign; std::string _relativeWidgetName; From 0837b73dda351ca55daabcc762647af5c37d0bce Mon Sep 17 00:00:00 2001 From: Dhilan007 Date: Fri, 28 Feb 2014 17:34:24 +0800 Subject: [PATCH 09/13] fixed incorrect effect of Gaussian Blur. --- tests/Classes/ShaderTest/ShaderTest.cpp | 77 ++++++++++++++++++------- 1 file changed, 56 insertions(+), 21 deletions(-) diff --git a/tests/Classes/ShaderTest/ShaderTest.cpp b/tests/Classes/ShaderTest/ShaderTest.cpp index 0377617ae5..07d5e086fa 100644 --- a/tests/Classes/ShaderTest/ShaderTest.cpp +++ b/tests/Classes/ShaderTest/ShaderTest.cpp @@ -438,14 +438,21 @@ public: static SpriteBlur* create(const char *pszFileName); - Point blur_; - GLfloat sub_[4]; - - GLuint blurLocation; - GLuint subLocation; protected: void onDraw(); private: + int _blurRadius; + Point _pixelSize; + + int _samplingRadius; + //gaussian = cons * exp( (dx*dx + dy*dy) * scale); + float _scale; + float _cons; + float _weightSum; + + GLuint pixelSizeLocation; + GLuint coefficientLocation; + CustomCommand _customCommand; }; @@ -470,6 +477,7 @@ SpriteBlur* SpriteBlur::create(const char *pszFileName) bool SpriteBlur::initWithTexture(Texture2D* texture, const Rect& rect) { + _blurRadius = 0; if( Sprite::initWithTexture(texture, rect) ) { #if CC_ENABLE_CACHE_TEXTURE_DATA @@ -483,11 +491,10 @@ bool SpriteBlur::initWithTexture(Texture2D* texture, const Rect& rect) auto s = getTexture()->getContentSizeInPixels(); - blur_ = Point(1/s.width, 1/s.height); - sub_[0] = sub_[1] = sub_[2] = sub_[3] = 0; - + _pixelSize = Point(1/s.width, 1/s.height); + _samplingRadius = 0; this->initProgram(); - + return true; } @@ -497,7 +504,7 @@ bool SpriteBlur::initWithTexture(Texture2D* texture, const Rect& rect) void SpriteBlur::initProgram() { GLchar * fragSource = (GLchar*) String::createWithContentsOfFile( - FileUtils::getInstance()->fullPathForFilename("Shaders/example_Blur.fsh").c_str())->getCString(); + FileUtils::getInstance()->fullPathForFilename("Shaders/example_Blur.fsh").c_str())->getCString(); auto pProgram = new GLProgram(); pProgram->initWithVertexShaderByteArray(ccPositionTextureColor_vert, fragSource); setShaderProgram(pProgram); @@ -519,9 +526,9 @@ void SpriteBlur::initProgram() CHECK_GL_ERROR_DEBUG(); - subLocation = glGetUniformLocation( getShaderProgram()->getProgram(), "substract"); - blurLocation = glGetUniformLocation( getShaderProgram()->getProgram(), "blurSize"); - + pixelSizeLocation = glGetUniformLocation( getShaderProgram()->getProgram(), "onePixelSize"); + coefficientLocation = glGetUniformLocation( getShaderProgram()->getProgram(), "gaussianCoefficient"); + CHECK_GL_ERROR_DEBUG(); } @@ -540,8 +547,8 @@ void SpriteBlur::onDraw() getShaderProgram()->use(); getShaderProgram()->setUniformsForBuiltins(); - getShaderProgram()->setUniformLocationWith2f(blurLocation, blur_.x, blur_.y); - getShaderProgram()->setUniformLocationWith4fv(subLocation, sub_, 1); + getShaderProgram()->setUniformLocationWith2f(pixelSizeLocation, _pixelSize.x, _pixelSize.y); + getShaderProgram()->setUniformLocationWith4f(coefficientLocation, _samplingRadius, _scale,_cons,_weightSum); GL::bindTexture2D( getTexture()->getName()); @@ -571,10 +578,37 @@ void SpriteBlur::onDraw() void SpriteBlur::setBlurSize(float f) { - auto s = getTexture()->getContentSizeInPixels(); + if(_blurRadius == (int)f) + return; + _blurRadius = (int)f; - blur_ = Point(1/s.width, 1/s.height); - blur_ = blur_ * f; + _samplingRadius = _blurRadius; + if (_samplingRadius > 10) + { + _samplingRadius = 10; + } + if (_blurRadius > 0) + { + float sigma = _blurRadius / 2.0f; + _scale = -0.5f / (sigma * sigma); + _cons = -1.0f * _scale / 3.141592f; + _weightSum = -_cons; + + float weight; + int squareX; + for(int dx = 0; dx <= _samplingRadius; ++dx) + { + squareX = dx * dx; + weight = _cons * exp(squareX * _scale); + _weightSum += 2.0 * weight; + for (int dy = 1; dy <= _samplingRadius; ++dy) + { + weight = _cons * exp((squareX + dy * dy) * _scale); + _weightSum += 4.0 * weight; + } + } + } + log("_blurRadius:%d",_blurRadius); } // ShaderBlur @@ -597,16 +631,17 @@ std::string ShaderBlur::subtitle() const ControlSlider* ShaderBlur::createSliderCtl() { auto screenSize = Director::getInstance()->getWinSize(); - + ControlSlider *slider = ControlSlider::create("extensions/sliderTrack.png","extensions/sliderProgress.png" ,"extensions/sliderThumb.png"); slider->setAnchorPoint(Point(0.5f, 1.0f)); slider->setMinimumValue(0.0f); // Sets the min value of range - slider->setMaximumValue(3.0f); // Sets the max value of range - slider->setValue(1.0f); + slider->setMaximumValue(25.0f); // Sets the max value of range + slider->setPosition(Point(screenSize.width / 2.0f, screenSize.height / 3.0f)); // When the value of the slider will change, the given selector will be call slider->addTargetWithActionForControlEvents(this, cccontrol_selector(ShaderBlur::sliderAction), Control::EventType::VALUE_CHANGED); + slider->setValue(2.0f); return slider; From 4f90676e923a5ad69fcdbad9e3e2eaf77a9ae2d9 Mon Sep 17 00:00:00 2001 From: cai wenzhi Date: Sat, 1 Mar 2014 22:34:25 +0800 Subject: [PATCH 10/13] Add method for editor --- cocos/gui/UIButton.cpp | 20 +++++++++++++ cocos/gui/UIButton.h | 8 ++++++ cocos/gui/UIImageView.cpp | 10 +++++++ cocos/gui/UIImageView.h | 4 +++ cocos/gui/UILayout.cpp | 57 ++++++++++++++++++++++++++++++++++++++ cocos/gui/UILayout.h | 36 ++++++++++++++++++++++++ cocos/gui/UIListView.cpp | 5 ++++ cocos/gui/UIListView.h | 2 ++ cocos/gui/UILoadingBar.cpp | 10 +++++++ cocos/gui/UILoadingBar.h | 4 +++ cocos/gui/UIScrollView.cpp | 40 ++++++++++++++++++++++++++ cocos/gui/UIScrollView.h | 16 +++++++++++ cocos/gui/UISlider.cpp | 15 ++++++++++ cocos/gui/UISlider.h | 6 ++++ cocos/gui/UIText.cpp | 25 +++++++++++++++++ cocos/gui/UIText.h | 15 +++++++++- cocos/gui/UITextField.cpp | 25 +++++++++++++++++ cocos/gui/UITextField.h | 5 ++++ 18 files changed, 302 insertions(+), 1 deletion(-) diff --git a/cocos/gui/UIButton.cpp b/cocos/gui/UIButton.cpp index 82ed33dfec..3d08a6f2e3 100644 --- a/cocos/gui/UIButton.cpp +++ b/cocos/gui/UIButton.cpp @@ -152,6 +152,11 @@ void Button::setScale9Enabled(bool able) setCapInsetsDisabledRenderer(_capInsetsDisabled); setBright(_bright); } + +bool Button::isScale9Enabled() +{ + return _scale9Enabled; +} void Button::ignoreContentAdaptWithSize(bool ignore) { @@ -326,6 +331,11 @@ void Button::setCapInsetsNormalRenderer(const Rect &capInsets) } static_cast(_buttonNormalRenderer)->setCapInsets(capInsets); } + +const Rect& Button::getCapInsetsNormalRenderer() +{ + return _capInsetsNormal; +} void Button::setCapInsetsPressedRenderer(const Rect &capInsets) { @@ -336,6 +346,11 @@ void Button::setCapInsetsPressedRenderer(const Rect &capInsets) } static_cast(_buttonClickedRenderer)->setCapInsets(capInsets); } + +const Rect& Button::getCapInsetsPressedRenderer() +{ + return _capInsetsPressed; +} void Button::setCapInsetsDisabledRenderer(const Rect &capInsets) { @@ -346,6 +361,11 @@ void Button::setCapInsetsDisabledRenderer(const Rect &capInsets) } static_cast(_buttonDisableRenderer)->setCapInsets(capInsets); } + +const Rect& Button::getCapInsetsDisabledRenderer() +{ + return _capInsetsDisabled; +} void Button::onPressStateChangedToNormal() { diff --git a/cocos/gui/UIButton.h b/cocos/gui/UIButton.h index c2f7bf30a4..71f624d975 100644 --- a/cocos/gui/UIButton.h +++ b/cocos/gui/UIButton.h @@ -107,6 +107,8 @@ public: */ void setCapInsetsNormalRenderer(const Rect &capInsets); + const Rect& getCapInsetsNormalRenderer(); + /** * Sets capinsets for button, if button is using scale9 renderer. * @@ -114,6 +116,8 @@ public: */ void setCapInsetsPressedRenderer(const Rect &capInsets); + const Rect& getCapInsetsPressedRenderer(); + /** * Sets capinsets for button, if button is using scale9 renderer. * @@ -121,6 +125,8 @@ public: */ void setCapInsetsDisabledRenderer(const Rect &capInsets); + const Rect& getCapInsetsDisabledRenderer(); + //override "setAnchorPoint" of widget. virtual void setAnchorPoint(const Point &pt) override; @@ -131,6 +137,8 @@ public: */ virtual void setScale9Enabled(bool able); + bool isScale9Enabled(); + //override "setFlipX" of widget. virtual void setFlipX(bool flipX) override; diff --git a/cocos/gui/UIImageView.cpp b/cocos/gui/UIImageView.cpp index a77dee73e0..86be041024 100644 --- a/cocos/gui/UIImageView.cpp +++ b/cocos/gui/UIImageView.cpp @@ -206,6 +206,11 @@ void ImageView::setScale9Enabled(bool able) } setCapInsets(_capInsets); } + +bool ImageView::isScale9Enabled() +{ + return _scale9Enabled; +} void ImageView::ignoreContentAdaptWithSize(bool ignore) { @@ -226,6 +231,11 @@ void ImageView::setCapInsets(const Rect &capInsets) STATIC_CAST_SCALE9SPRITE->setCapInsets(capInsets); } +const Rect& ImageView::getCapInsets() +{ + return _capInsets; +} + void ImageView::setAnchorPoint(const Point &pt) { Widget::setAnchorPoint(pt); diff --git a/cocos/gui/UIImageView.h b/cocos/gui/UIImageView.h index df373a67a9..017dab5572 100644 --- a/cocos/gui/UIImageView.h +++ b/cocos/gui/UIImageView.h @@ -75,6 +75,8 @@ public: */ void setScale9Enabled(bool able); + bool isScale9Enabled(); + /** * Sets capinsets for imageview, if imageview is using scale9 renderer. * @@ -82,6 +84,8 @@ public: */ void setCapInsets(const Rect &capInsets); + const Rect& getCapInsets(); + //override "setFlipX" method of widget. virtual void setFlipX(bool flipX) override; diff --git a/cocos/gui/UILayout.cpp b/cocos/gui/UILayout.cpp index e72d105f30..82d01821e4 100644 --- a/cocos/gui/UILayout.cpp +++ b/cocos/gui/UILayout.cpp @@ -153,6 +153,23 @@ void Layout::addChild(Node *child, int zOrder, int tag) Widget::addChild(child, zOrder, tag); _doLayoutDirty = true; } + +void Layout::removeChild(Node *child, bool cleanup) +{ + Widget::removeChild(child, cleanup); + _doLayoutDirty = true; +} + +void Layout::removeAllChildren() +{ + Widget::removeAllChildren(); +} + +void Layout::removeAllChildrenWithCleanup(bool cleanup) +{ + Widget::removeAllChildrenWithCleanup(cleanup); + _doLayoutDirty = true; +} bool Layout::isClippingEnabled() { @@ -408,6 +425,11 @@ void Layout::setClippingType(LayoutClippingType type) setClippingEnabled(clippingEnabled); } +LayoutClippingType Layout::getClippingType() +{ + return _clippingType; +} + void Layout::setStencilClippingSize(const Size &size) { if (_clippingEnabled && _clippingType == LAYOUT_CLIPPING_STENCIL) @@ -620,6 +642,11 @@ void Layout::setBackGroundImageCapInsets(const Rect &capInsets) static_cast(_backGroundImage)->setCapInsets(capInsets); } } + +const Rect& Layout::getBackGroundImageCapInsets() +{ + return _backGroundImageCapInsets; +} void Layout::supplyTheLayoutParameterLackToChild(Widget *child) { @@ -747,6 +774,11 @@ void Layout::setBackGroundColorType(LayoutBackGroundColorType type) break; } } + +LayoutBackGroundColorType Layout::getBackGroundColorType() +{ + return _colorType; +} void Layout::setBackGroundColor(const Color3B &color) { @@ -756,6 +788,11 @@ void Layout::setBackGroundColor(const Color3B &color) _colorRender->setColor(color); } } + +const Color3B& Layout::getBackGroundColor() +{ + return _cColor; +} void Layout::setBackGroundColor(const Color3B &startColor, const Color3B &endColor) { @@ -770,6 +807,16 @@ void Layout::setBackGroundColor(const Color3B &startColor, const Color3B &endCol _gradientRender->setEndColor(endColor); } } + +const Color3B& Layout::getBackGroundStartColor() +{ + return _gStartColor; +} + +const Color3B& Layout::getBackGroundEndColor() +{ + return _gEndColor; +} void Layout::setBackGroundColorOpacity(int opacity) { @@ -788,6 +835,11 @@ void Layout::setBackGroundColorOpacity(int opacity) break; } } + +int Layout::getBackGroundColorOpacity() +{ + return _cOpacity; +} void Layout::setBackGroundColorVector(const Point &vector) { @@ -797,6 +849,11 @@ void Layout::setBackGroundColorVector(const Point &vector) _gradientRender->setVector(vector); } } + +const Point& Layout::getBackGroundColorVector() +{ + return _alongVector; +} const Size& Layout::getBackGroundImageTextureSize() const { diff --git a/cocos/gui/UILayout.h b/cocos/gui/UILayout.h index 13f7ac1e36..8d876d86e1 100644 --- a/cocos/gui/UILayout.h +++ b/cocos/gui/UILayout.h @@ -91,6 +91,8 @@ public: */ void setBackGroundImageCapInsets(const Rect& capInsets); + const Rect& getBackGroundImageCapInsets(); + /** * Sets Color Type for layout. * @@ -98,6 +100,8 @@ public: */ void setBackGroundColorType(LayoutBackGroundColorType type); + LayoutBackGroundColorType getBackGroundColorType(); + /** * Sets background iamge use scale9 renderer. * @@ -105,6 +109,8 @@ public: */ void setBackGroundImageScale9Enabled(bool enabled); + bool isBackGroundImageScale9Enabled(); + /** * Sets background color for layout, if color type is LAYOUT_COLOR_SOLID * @@ -112,6 +118,8 @@ public: */ void setBackGroundColor(const Color3B &color); + const Color3B& getBackGroundColor(); + /** * Sets background color for layout, if color type is LAYOUT_COLOR_GRADIENT * @@ -121,6 +129,10 @@ public: */ void setBackGroundColor(const Color3B &startColor, const Color3B &endColor); + const Color3B& getBackGroundStartColor(); + + const Color3B& getBackGroundEndColor(); + /** * Sets background opacity layout. * @@ -128,6 +140,8 @@ public: */ void setBackGroundColorOpacity(int opacity); + int getBackGroundColorOpacity(); + /** * Sets background color vector for layout, if color type is LAYOUT_COLOR_GRADIENT * @@ -135,6 +149,8 @@ public: */ void setBackGroundColorVector(const Point &vector); + const Point& getBackGroundColorVector(); + /** * Remove the background image of layout. */ @@ -158,6 +174,8 @@ public: void setClippingType(LayoutClippingType type); + LayoutClippingType getClippingType(); + /** * Gets if layout is clipping enabled. * @@ -209,6 +227,24 @@ public: */ virtual void addChild(Node* child, int zOrder, int tag) override; + virtual void removeChild(Node* child, bool cleanup = true) override; + + /** + * Removes all children from the container with a cleanup. + * + * @see `removeAllChildrenWithCleanup(bool)` + */ + virtual void removeAllChildren() override; + /** + * Removes all children from the container, and do a cleanup to all running actions depending on the cleanup parameter. + * + * @param cleanup true if all running actions on all children nodes should be cleanup, false oterwise. + * @js removeAllChildren + * @lua removeAllChildren + */ + virtual void removeAllChildrenWithCleanup(bool cleanup) override; + + virtual void visit(); virtual void sortAllChildren() override; diff --git a/cocos/gui/UIListView.cpp b/cocos/gui/UIListView.cpp index 8c732f6e70..a447f46bbe 100644 --- a/cocos/gui/UIListView.cpp +++ b/cocos/gui/UIListView.cpp @@ -347,6 +347,11 @@ void ListView::setItemsMargin(float margin) _itemsMargin = margin; _refreshViewDirty = true; } + +float ListView::getItemsMargin() +{ + return _itemsMargin; +} void ListView::setDirection(SCROLLVIEW_DIR dir) { diff --git a/cocos/gui/UIListView.h b/cocos/gui/UIListView.h index 2a6b2df848..3458b5fd48 100644 --- a/cocos/gui/UIListView.h +++ b/cocos/gui/UIListView.h @@ -150,6 +150,8 @@ public: */ void setItemsMargin(float margin); + float getItemsMargin(); + virtual void sortAllChildren() override; ssize_t getCurSelectedIndex() const; diff --git a/cocos/gui/UILoadingBar.cpp b/cocos/gui/UILoadingBar.cpp index 15ade85aef..542b3fa016 100644 --- a/cocos/gui/UILoadingBar.cpp +++ b/cocos/gui/UILoadingBar.cpp @@ -196,6 +196,11 @@ void LoadingBar::setScale9Enabled(bool enabled) setCapInsets(_capInsets); } +bool LoadingBar::isScale9Enabled() +{ + return _scale9Enabled; +} + void LoadingBar::setCapInsets(const Rect &capInsets) { _capInsets = capInsets; @@ -206,6 +211,11 @@ void LoadingBar::setCapInsets(const Rect &capInsets) static_cast(_barRenderer)->setCapInsets(capInsets); } +const Rect& LoadingBar::getCapInsets() +{ + return _capInsets; +} + void LoadingBar::setPercent(int percent) { if ( percent < 0 || percent > 100) diff --git a/cocos/gui/UILoadingBar.h b/cocos/gui/UILoadingBar.h index b0305951d5..d8b69aa83a 100644 --- a/cocos/gui/UILoadingBar.h +++ b/cocos/gui/UILoadingBar.h @@ -106,6 +106,8 @@ public: */ void setScale9Enabled(bool enabled); + bool isScale9Enabled(); + /** * Sets capinsets for loadingbar, if loadingbar is using scale9 renderer. * @@ -113,6 +115,8 @@ public: */ void setCapInsets(const Rect &capInsets); + const Rect& getCapInsets(); + //override "ignoreContentAdaptWithSize" method of widget. virtual void ignoreContentAdaptWithSize(bool ignore) override; diff --git a/cocos/gui/UIScrollView.cpp b/cocos/gui/UIScrollView.cpp index 8bb23aae8d..553491d408 100644 --- a/cocos/gui/UIScrollView.cpp +++ b/cocos/gui/UIScrollView.cpp @@ -273,6 +273,46 @@ Widget* ScrollView::getChildByName(const char *name) { return _innerContainer->getChildByName(name); } + +void ScrollView::addNode(Node* node) +{ + Layout::addNode(node); +} + +void ScrollView::addNode(Node * node, int zOrder) +{ + Layout::addNode(node, zOrder); +} + +void ScrollView::addNode(Node* node, int zOrder, int tag) +{ + _innerContainer->addNode(node, zOrder, tag); +} + +Node* ScrollView::getNodeByTag(int tag) +{ + return _innerContainer->getNodeByTag(tag); +} + +Vector& ScrollView::getNodes() +{ + return _innerContainer->getNodes(); +} + +void ScrollView::removeNode(Node* node) +{ + _innerContainer->removeNode(node); +} + +void ScrollView::removeNodeByTag(int tag) +{ + _innerContainer->removeNodeByTag(tag); +} + +void ScrollView::removeAllNodes() +{ + _innerContainer->removeAllNodes(); +} void ScrollView::moveChildren(float offsetX, float offsetY) { diff --git a/cocos/gui/UIScrollView.h b/cocos/gui/UIScrollView.h index 0b196cef55..6cb3a554fc 100644 --- a/cocos/gui/UIScrollView.h +++ b/cocos/gui/UIScrollView.h @@ -274,6 +274,22 @@ public: virtual Widget* getChildByName(const char* name) override; + virtual void addNode(Node* node) override; + + virtual void addNode(Node * node, int zOrder) override; + + virtual void addNode(Node* node, int zOrder, int tag) override; + + virtual Node * getNodeByTag(int tag) override; + + virtual Vector& getNodes() override; + + virtual void removeNode(Node* node) override; + + virtual void removeNodeByTag(int tag) override; + + virtual void removeAllNodes() override; + virtual bool onTouchBegan(Touch *touch, Event *unusedEvent) override; virtual void onTouchMoved(Touch *touch, Event *unusedEvent) override; virtual void onTouchEnded(Touch *touch, Event *unusedEvent) override; diff --git a/cocos/gui/UISlider.cpp b/cocos/gui/UISlider.cpp index d138def5a3..e5557b6cbf 100644 --- a/cocos/gui/UISlider.cpp +++ b/cocos/gui/UISlider.cpp @@ -216,6 +216,11 @@ void Slider::setScale9Enabled(bool able) setCapInsetsBarRenderer(_capInsetsBarRenderer); setCapInsetProgressBarRebderer(_capInsetsProgressBarRenderer); } + +bool Slider::isScale9Enabled() +{ + return _scale9Enabled; +} void Slider::ignoreContentAdaptWithSize(bool ignore) { @@ -241,6 +246,11 @@ void Slider::setCapInsetsBarRenderer(const Rect &capInsets) } static_cast(_barRenderer)->setCapInsets(capInsets); } + +const Rect& Slider::getCapInsetsBarRenderer() +{ + return _capInsetsBarRenderer; +} void Slider::setCapInsetProgressBarRebderer(const Rect &capInsets) { @@ -251,6 +261,11 @@ void Slider::setCapInsetProgressBarRebderer(const Rect &capInsets) } static_cast(_progressBarRenderer)->setCapInsets(capInsets); } + +const Rect& Slider::getCapInsetsProgressBarRebderer() +{ + return _capInsetsProgressBarRenderer; +} void Slider::loadSlidBallTextures(const char* normal,const char* pressed,const char* disabled,TextureResType texType) { diff --git a/cocos/gui/UISlider.h b/cocos/gui/UISlider.h index bc952ede15..9f2f175200 100644 --- a/cocos/gui/UISlider.h +++ b/cocos/gui/UISlider.h @@ -77,6 +77,8 @@ public: */ void setScale9Enabled(bool able); + bool isScale9Enabled(); + /** * Sets capinsets for slider, if slider is using scale9 renderer. * @@ -91,6 +93,8 @@ public: */ void setCapInsetsBarRenderer(const Rect &capInsets); + const Rect& getCapInsetsBarRenderer(); + /** * Sets capinsets for slider, if slider is using scale9 renderer. * @@ -98,6 +102,8 @@ public: */ void setCapInsetProgressBarRebderer(const Rect &capInsets); + const Rect& getCapInsetsProgressBarRebderer(); + /** * Load textures for slider ball. * diff --git a/cocos/gui/UIText.cpp b/cocos/gui/UIText.cpp index 13b014fe66..274b28b140 100644 --- a/cocos/gui/UIText.cpp +++ b/cocos/gui/UIText.cpp @@ -98,6 +98,11 @@ void Text::setFontSize(int size) _labelRenderer->setFontSize(size); labelScaleChangedWithSize(); } + +int Text::getFontSize() +{ + return _fontSize; +} void Text::setFontName(const std::string& name) { @@ -105,24 +110,44 @@ void Text::setFontName(const std::string& name) _labelRenderer->setFontName(name); labelScaleChangedWithSize(); } + +const std::string& Text::getFontName() +{ + return _fontName; +} void Text::setTextAreaSize(const Size &size) { _labelRenderer->setDimensions(size); labelScaleChangedWithSize(); } + +const Size& Text::getTextAreaSize() +{ + return _labelRenderer->getDimensions(); +} void Text::setTextHorizontalAlignment(TextHAlignment alignment) { _labelRenderer->setHorizontalAlignment(alignment); labelScaleChangedWithSize(); } + +TextHAlignment Text::getTextHorizontalAlignment() +{ + return _labelRenderer->getHorizontalAlignment(); +} void Text::setTextVerticalAlignment(TextVAlignment alignment) { _labelRenderer->setVerticalAlignment(alignment); labelScaleChangedWithSize(); } + +TextVAlignment Text::getTextVerticalAlignment() +{ + return _labelRenderer->getVerticalAlignment(); +} void Text::setTouchScaleChangeEnabled(bool enable) { diff --git a/cocos/gui/UIText.h b/cocos/gui/UIText.h index 44d558151a..03dc895727 100644 --- a/cocos/gui/UIText.h +++ b/cocos/gui/UIText.h @@ -81,6 +81,8 @@ public: */ void setFontSize(int size); + int getFontSize(); + /** * Sets the font name of label. * @@ -88,6 +90,8 @@ public: */ void setFontName(const std::string& name); + const std::string& getFontName(); + /** * Sets the touch scale enabled of label. * @@ -157,8 +161,17 @@ public: virtual std::string getDescription() const override; void setTextAreaSize(const Size &size); + + const Size& getTextAreaSize(); + void setTextHorizontalAlignment(TextHAlignment alignment); - void setTextVerticalAlignment(TextVAlignment alignment); + + TextHAlignment getTextHorizontalAlignment(); + + void setTextVerticalAlignment(TextVAlignment alignment); + + TextVAlignment getTextVerticalAlignment(); + protected: virtual bool init() override; virtual void initRenderer() override; diff --git a/cocos/gui/UITextField.cpp b/cocos/gui/UITextField.cpp index c463293006..23fffb831e 100644 --- a/cocos/gui/UITextField.cpp +++ b/cocos/gui/UITextField.cpp @@ -319,6 +319,11 @@ void TextField::setTouchSize(const Size &size) _touchWidth = size.width; _touchHeight = size.height; } + +Size TextField::getTouchSize() +{ + return Size(_touchWidth, _touchHeight); +} void TextField::setText(const std::string& text) { @@ -345,18 +350,33 @@ void TextField::setPlaceHolder(const std::string& value) _textFieldRenderer->setPlaceHolder(value); textfieldRendererScaleChangedWithSize(); } + +const std::string& TextField::getPlaceHolder() +{ + return _textFieldRenderer->getPlaceHolder(); +} void TextField::setFontSize(int size) { _textFieldRenderer->setFontSize(size); textfieldRendererScaleChangedWithSize(); } + +int TextField::getFontSize() +{ + return _textFieldRenderer->getFontSize(); +} void TextField::setFontName(const std::string& name) { _textFieldRenderer->setFontName(name); textfieldRendererScaleChangedWithSize(); } + +const std::string& TextField::getFontName() +{ + return _textFieldRenderer->getFontName(); +} void TextField::didNotSelectSelf() { @@ -414,6 +434,11 @@ void TextField::setPasswordStyleText(const char *styleText) _passwordStyleText = styleText; } + +const char* TextField::getPasswordStyleText() +{ + return _passwordStyleText.c_str(); +} void TextField::update(float dt) { diff --git a/cocos/gui/UITextField.h b/cocos/gui/UITextField.h index 1f01103592..1fc3d2cc0b 100644 --- a/cocos/gui/UITextField.h +++ b/cocos/gui/UITextField.h @@ -108,10 +108,14 @@ public: virtual ~TextField(); static TextField* create(); void setTouchSize(const Size &size); + Size getTouchSize(); void setText(const std::string& text); void setPlaceHolder(const std::string& value); + const std::string& getPlaceHolder(); void setFontSize(int size); + int getFontSize(); void setFontName(const std::string& name); + const std::string& getFontName(); virtual void didNotSelectSelf(); const std::string& getStringValue(); virtual bool onTouchBegan(Touch *touch, Event *unusedEvent) override; @@ -122,6 +126,7 @@ public: void setPasswordEnabled(bool enable); bool isPasswordEnabled(); void setPasswordStyleText(const char* styleText); + const char* getPasswordStyleText(); virtual void update(float dt) override; bool getAttachWithIME(); void setAttachWithIME(bool attach); From f3949e078b4a08807ee449f09d100d8a6d05f193 Mon Sep 17 00:00:00 2001 From: James Chen Date: Sun, 2 Mar 2014 15:54:36 +0800 Subject: [PATCH 11/13] [EventDispatcher] Adds 'pauseEventListenersForTarget', 'resumeEventListenersForTarget' and 'removeEventListenersForTarget'. --- cocos/2d/CCEventDispatcher.cpp | 51 ++++++-- cocos/2d/CCEventDispatcher.h | 40 ++++-- cocos/2d/CCNode.cpp | 8 +- .../NewEventDispatcherTest.cpp | 123 ++++++++++++++---- .../NewEventDispatcherTest.h | 13 ++ 5 files changed, 185 insertions(+), 50 deletions(-) diff --git a/cocos/2d/CCEventDispatcher.cpp b/cocos/2d/CCEventDispatcher.cpp index ccdb174725..10776fbe20 100644 --- a/cocos/2d/CCEventDispatcher.cpp +++ b/cocos/2d/CCEventDispatcher.cpp @@ -267,9 +267,9 @@ void EventDispatcher::visitTarget(Node* node, bool isRootNode) } } -void EventDispatcher::pauseTarget(Node* node) +void EventDispatcher::pauseEventListenersForTarget(Node* target, bool recursive/* = false */) { - auto listenerIter = _nodeListenersMap.find(node); + auto listenerIter = _nodeListenersMap.find(target); if (listenerIter != _nodeListenersMap.end()) { auto listeners = listenerIter->second; @@ -278,11 +278,20 @@ void EventDispatcher::pauseTarget(Node* node) l->setPaused(true); } } + + if (recursive) + { + const auto& children = target->getChildren(); + for (const auto& child : children) + { + pauseEventListenersForTarget(child, true); + } + } } -void EventDispatcher::resumeTarget(Node* node) +void EventDispatcher::resumeEventListenersForTarget(Node* target, bool recursive/* = false */) { - auto listenerIter = _nodeListenersMap.find(node); + auto listenerIter = _nodeListenersMap.find(target); if (listenerIter != _nodeListenersMap.end()) { auto listeners = listenerIter->second; @@ -291,12 +300,21 @@ void EventDispatcher::resumeTarget(Node* node) l->setPaused(false); } } - setDirtyForNode(node); + setDirtyForNode(target); + + if (recursive) + { + const auto& children = target->getChildren(); + for (const auto& child : children) + { + resumeEventListenersForTarget(child, true); + } + } } -void EventDispatcher::cleanTarget(Node* node) +void EventDispatcher::removeEventListenersForTarget(Node* target, bool recursive/* = false */) { - auto listenerIter = _nodeListenersMap.find(node); + auto listenerIter = _nodeListenersMap.find(target); if (listenerIter != _nodeListenersMap.end()) { auto listeners = listenerIter->second; @@ -306,6 +324,15 @@ void EventDispatcher::cleanTarget(Node* node) removeEventListener(l); } } + + if (recursive) + { + const auto& children = target->getChildren(); + for (const auto& child : children) + { + removeEventListenersForTarget(child, true); + } + } } void EventDispatcher::associateNodeAndEventListener(Node* node, EventListener* listener) @@ -389,7 +416,7 @@ void EventDispatcher::forceAddEventListener(EventListener* listener) if (node->isRunning()) { - resumeTarget(node); + resumeEventListenersForTarget(node); } } else @@ -430,7 +457,7 @@ void EventDispatcher::addEventListenerWithFixedPriority(EventListener* listener, addEventListener(listener); } -EventListenerCustom* EventDispatcher::addCustomEventListener(const std::string &eventName, std::function callback) +EventListenerCustom* EventDispatcher::addCustomEventListener(const std::string &eventName, const std::function& callback) { EventListenerCustom *listener = EventListenerCustom::create(eventName, callback); addEventListenerWithFixedPriority(listener, 1); @@ -443,7 +470,7 @@ void EventDispatcher::removeEventListener(EventListener* listener) return; bool isFound = false; - + auto removeListenerInVector = [&](std::vector* listeners){ if (listeners == nullptr) return; @@ -553,7 +580,7 @@ void EventDispatcher::setPriority(EventListener* listener, int fixedPriority) } } -void EventDispatcher::dispatchEventToListeners(EventListenerVector* listeners, std::function onEvent) +void EventDispatcher::dispatchEventToListeners(EventListenerVector* listeners, const std::function& onEvent) { bool shouldStopPropagation = false; auto fixedPriorityListeners = listeners->getFixedPriorityListeners(); @@ -1121,7 +1148,7 @@ void EventDispatcher::removeEventListenersForListenerID(const EventListener::Lis } } -void EventDispatcher::removeEventListeners(EventListener::Type listenerType) +void EventDispatcher::removeEventListenersForType(EventListener::Type listenerType) { if (listenerType == EventListener::Type::TOUCH_ONE_BY_ONE) { diff --git a/cocos/2d/CCEventDispatcher.h b/cocos/2d/CCEventDispatcher.h index 9e9077159d..1178cb8444 100644 --- a/cocos/2d/CCEventDispatcher.h +++ b/cocos/2d/CCEventDispatcher.h @@ -56,6 +56,8 @@ dispatched. class EventDispatcher : public Ref { public: + // Adds event listener + /** Adds a event listener for a specified event with the priority of scene graph. * @param listener The listener of a specified event. * @param node The priority of the listener is based on the draw order of this node. @@ -76,22 +78,41 @@ public: It will use a fixed priority of 1. @return the generated event. Needed in order to remove the event from the dispather */ - EventListenerCustom* addCustomEventListener(const std::string &eventName, std::function callback); + EventListenerCustom* addCustomEventListener(const std::string &eventName, const std::function& callback); + ///////////////////////////////////////////// + + // Removes event listener + /** Remove a listener * @param listener The specified event listener which needs to be removed. */ void removeEventListener(EventListener* listener); /** Removes all listeners with the same event listener type */ - void removeEventListeners(EventListener::Type listenerType); + void removeEventListenersForType(EventListener::Type listenerType); + /** Removes all listeners which are associated with the specified target. */ + void removeEventListenersForTarget(Node* target, bool recursive = false); + /** Removes all custom listeners with the same event name */ void removeCustomEventListeners(const std::string& customEventName); /** Removes all listeners */ void removeAllEventListeners(); + ///////////////////////////////////////////// + + // Pauses / Resumes event listener + + /** Pauses all listeners which are associated the specified target. */ + void pauseEventListenersForTarget(Node* target, bool recursive = false); + + /** Resumes all listeners which are associated the specified target. */ + void resumeEventListenersForTarget(Node* target, bool recursive = false); + + ///////////////////////////////////////////// + /** Sets listener's priority with fixed value. */ void setPriority(EventListener* listener, int fixedPriority); @@ -101,6 +122,8 @@ public: /** Checks whether dispatching events is enabled */ bool isEnabled() const; + ///////////////////////////////////////////// + /** Dispatches the event * Also removes all EventListeners marked for deletion from the * event dispatcher list. @@ -110,6 +133,8 @@ public: /** Dispatches a Custom Event with a event name an optional user data */ void dispatchCustomEvent(const std::string &eventName, void *optionalUserData = nullptr); + ///////////////////////////////////////////// + /** Constructor of EventDispatcher */ EventDispatcher(); /** Destructor of EventDispatcher */ @@ -121,15 +146,6 @@ protected: /** Sets the dirty flag for a node. */ void setDirtyForNode(Node* node); - /** Notifys event dispatcher that the node has been paused. */ - void pauseTarget(Node* node); - - /** Notifys event dispatcher that the node has been resumed. */ - void resumeTarget(Node* node); - - /** Notifys event dispatcher that the node has been deleted. */ - void cleanTarget(Node* node); - /** * The vector to store event listeners with scene graph based priority and fixed priority. */ @@ -202,7 +218,7 @@ protected: void dissociateNodeAndEventListener(Node* node, EventListener* listener); /** Dispatches event to listeners with a specified listener type */ - void dispatchEventToListeners(EventListenerVector* listeners, std::function onEvent); + void dispatchEventToListeners(EventListenerVector* listeners, const std::function& onEvent); /// Priority dirty flag enum class DirtyFlag diff --git a/cocos/2d/CCNode.cpp b/cocos/2d/CCNode.cpp index 49472cf822..9bf31270c1 100644 --- a/cocos/2d/CCNode.cpp +++ b/cocos/2d/CCNode.cpp @@ -156,7 +156,7 @@ Node::~Node() CC_SAFE_RELEASE(_actionManager); CC_SAFE_RELEASE(_scheduler); - _eventDispatcher->cleanTarget(this); + _eventDispatcher->removeEventListenersForTarget(this); CC_SAFE_RELEASE(_eventDispatcher); // attributes @@ -1050,7 +1050,7 @@ void Node::setEventDispatcher(EventDispatcher* dispatcher) { if (dispatcher != _eventDispatcher) { - _eventDispatcher->cleanTarget(this); + _eventDispatcher->removeEventListenersForTarget(this); CC_SAFE_RETAIN(dispatcher); CC_SAFE_RELEASE(_eventDispatcher); _eventDispatcher = dispatcher; @@ -1198,14 +1198,14 @@ void Node::resume() { _scheduler->resumeTarget(this); _actionManager->resumeTarget(this); - _eventDispatcher->resumeTarget(this); + _eventDispatcher->resumeEventListenersForTarget(this); } void Node::pause() { _scheduler->pauseTarget(this); _actionManager->pauseTarget(this); - _eventDispatcher->pauseTarget(this); + _eventDispatcher->pauseEventListenersForTarget(this); } void Node::resumeSchedulerAndActions() diff --git a/tests/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp b/tests/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp index 2464d7b40f..7b4ff93a6c 100644 --- a/tests/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp +++ b/tests/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp @@ -24,6 +24,7 @@ std::function createFunctions[] = CL(DirectorEventTest), CL(GlobalZTouchTest), CL(StopPropagationTest), + CL(PauseResumeTargetTest), CL(Issue4129), CL(Issue4160) }; @@ -187,7 +188,7 @@ void TouchableSpriteTest::onEnter() auto senderItem = static_cast(sender); senderItem->setString("Only Next item could be clicked"); - _eventDispatcher->removeEventListeners(EventListener::Type::TOUCH_ONE_BY_ONE); + _eventDispatcher->removeEventListenersForType(EventListener::Type::TOUCH_ONE_BY_ONE); auto nextItem = MenuItemFont::create("Next", [=](Ref* sender){ nextCallback(nullptr); @@ -223,21 +224,32 @@ std::string TouchableSpriteTest::subtitle() const // FixedPriorityChangedTest -class TouchableSpriteWithFixedPriority : public Sprite +class TouchableSprite : public Sprite { public: + static TouchableSprite* create(int priority = 0) + { + auto ret = new TouchableSprite(priority); + if (ret && ret->init()) + { + ret->autorelease(); + } + else + { + CC_SAFE_DELETE(ret); + } + return ret; + } - CREATE_FUNC(TouchableSpriteWithFixedPriority); - - TouchableSpriteWithFixedPriority() +protected: + TouchableSprite(int priority) : _listener(nullptr) - , _fixedPriority(0) + , _fixedPriority(priority) , _removeListenerOnTouchEnded(false) { } - void setPriority(int fixedPriority) { _fixedPriority = fixedPriority; }; - +public: void onEnter() override { Sprite::onEnter(); @@ -268,7 +280,14 @@ public: } }; - _eventDispatcher->addEventListenerWithFixedPriority(listener, _fixedPriority); + if (_fixedPriority != 0) + { + _eventDispatcher->addEventListenerWithFixedPriority(listener, _fixedPriority); + } + else + { + _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); + } _listener = listener; } @@ -295,21 +314,18 @@ void FixedPriorityTest::onEnter() Point origin = Director::getInstance()->getVisibleOrigin(); Size size = Director::getInstance()->getVisibleSize(); - auto sprite1 = TouchableSpriteWithFixedPriority::create(); + auto sprite1 = TouchableSprite::create(30); sprite1->setTexture("Images/CyanSquare.png"); - sprite1->setPriority(30); sprite1->setPosition(origin+Point(size.width/2, size.height/2) + Point(-80, 40)); addChild(sprite1, 10); - auto sprite2 = TouchableSpriteWithFixedPriority::create(); + auto sprite2 = TouchableSprite::create(20); sprite2->setTexture("Images/MagentaSquare.png"); - sprite2->setPriority(20); sprite2->setPosition(origin+Point(size.width/2, size.height/2)); addChild(sprite2, 20); - auto sprite3 = TouchableSpriteWithFixedPriority::create(); + auto sprite3 = TouchableSprite::create(10); sprite3->setTexture("Images/YellowSquare.png"); - sprite3->setPriority(10); sprite3->setPosition(Point(0, 0)); sprite2->addChild(sprite3, 1); @@ -701,7 +717,7 @@ void RemoveListenerAfterAddingTest::onEnter() }; _eventDispatcher->addEventListenerWithFixedPriority(listener, -1); - _eventDispatcher->removeEventListeners(EventListener::Type::TOUCH_ONE_BY_ONE); + _eventDispatcher->removeEventListenersForType(EventListener::Type::TOUCH_ONE_BY_ONE); addNextButton(); }); @@ -1087,6 +1103,72 @@ std::string StopPropagationTest::subtitle() const return "Shouldn't crash and only blue block could be clicked"; } +// PauseResumeTargetTest +PauseResumeTargetTest::PauseResumeTargetTest() +{ + Point origin = Director::getInstance()->getVisibleOrigin(); + Size size = Director::getInstance()->getVisibleSize(); + + auto sprite1 = TouchableSprite::create(); + sprite1->setTexture("Images/CyanSquare.png"); + sprite1->setPosition(origin+Point(size.width/2, size.height/2) + Point(-80, 40)); + addChild(sprite1, -10); + + auto sprite2 = TouchableSprite::create(); + sprite2->setTexture("Images/MagentaSquare.png"); + sprite2->setPosition(origin+Point(size.width/2, size.height/2)); + addChild(sprite2, -20); + + auto sprite3 = TouchableSprite::create(); + sprite3->setTexture("Images/YellowSquare.png"); + sprite3->setPosition(Point(0, 0)); + sprite2->addChild(sprite3, -1); + + auto popup = MenuItemFont::create("Popup", [this](Ref* sender){ + + _eventDispatcher->pauseEventListenersForTarget(this, true); + + auto colorLayer = LayerColor::create(Color4B(0, 0, 255, 100)); + this->addChild(colorLayer, 99999); + + auto closeItem = MenuItemFont::create("close", [this, colorLayer](Ref* sender){ + colorLayer->removeFromParent(); + _eventDispatcher->resumeEventListenersForTarget(this, true); + }); + + closeItem->setPosition(VisibleRect::center()); + + auto closeMenu = Menu::create(closeItem, NULL); + closeMenu->setAnchorPoint(Point::ANCHOR_BOTTOM_LEFT); + closeMenu->setPosition(Point::ZERO); + + colorLayer->addChild(closeMenu); + }); + + popup->setAnchorPoint(Point::ANCHOR_MIDDLE_RIGHT); + popup->setPosition(VisibleRect::right()); + + auto menu = Menu::create(popup, nullptr); + menu->setAnchorPoint(Point::ANCHOR_BOTTOM_LEFT); + menu->setPosition(Point::ZERO); + + addChild(menu); +} + +PauseResumeTargetTest::~PauseResumeTargetTest() +{ +} + +std::string PauseResumeTargetTest::title() const +{ + return "PauseResumeTargetTest"; +} + +std::string PauseResumeTargetTest::subtitle() const +{ + return ""; +} + // Issue4129 Issue4129::Issue4129() : _bugFixed(false) @@ -1157,22 +1239,19 @@ Issue4160::Issue4160() Point origin = Director::getInstance()->getVisibleOrigin(); Size size = Director::getInstance()->getVisibleSize(); - auto sprite1 = TouchableSpriteWithFixedPriority::create(); + auto sprite1 = TouchableSprite::create(-30); sprite1->setTexture("Images/CyanSquare.png"); - sprite1->setPriority(-30); sprite1->setPosition(origin+Point(size.width/2, size.height/2) + Point(-80, 40)); addChild(sprite1, -10); - auto sprite2 = TouchableSpriteWithFixedPriority::create(); + auto sprite2 = TouchableSprite::create(-20); sprite2->setTexture("Images/MagentaSquare.png"); - sprite2->setPriority(-20); sprite2->removeListenerOnTouchEnded(true); sprite2->setPosition(origin+Point(size.width/2, size.height/2)); addChild(sprite2, -20); - auto sprite3 = TouchableSpriteWithFixedPriority::create(); + auto sprite3 = TouchableSprite::create(-10); sprite3->setTexture("Images/YellowSquare.png"); - sprite3->setPriority(-10); sprite3->setPosition(Point(0, 0)); sprite2->addChild(sprite3, -1); } diff --git a/tests/Classes/NewEventDispatcherTest/NewEventDispatcherTest.h b/tests/Classes/NewEventDispatcherTest/NewEventDispatcherTest.h index 4392998358..e35035b4c6 100644 --- a/tests/Classes/NewEventDispatcherTest/NewEventDispatcherTest.h +++ b/tests/Classes/NewEventDispatcherTest/NewEventDispatcherTest.h @@ -165,6 +165,19 @@ protected: bool isPointInTopHalfAreaOfScreen(Point pt); }; +class PauseResumeTargetTest : public EventDispatcherTestDemo +{ +public: + CREATE_FUNC(PauseResumeTargetTest); + PauseResumeTargetTest(); + virtual ~PauseResumeTargetTest(); + + virtual std::string title() const override; + virtual std::string subtitle() const override; + +private: +}; + class Issue4129 : public EventDispatcherTestDemo { public: From a6e4a5e5aa504db70076d394320c2ee87b6eb976 Mon Sep 17 00:00:00 2001 From: cai wenzhi Date: Sun, 2 Mar 2014 22:41:47 +0800 Subject: [PATCH 12/13] Adjust layout --- cocos/gui/UILayout.cpp | 78 ------------------------------------------ 1 file changed, 78 deletions(-) diff --git a/cocos/gui/UILayout.cpp b/cocos/gui/UILayout.cpp index 1b2c071197..af0d2c8464 100644 --- a/cocos/gui/UILayout.cpp +++ b/cocos/gui/UILayout.cpp @@ -1257,128 +1257,50 @@ void Layout::doLayout() case RELATIVE_LOCATION_ABOVE_LEFTALIGN: finalPosY += mg.bottom; - if (relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_TOP_CENTER_HORIZONTAL - && relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_TOP_LEFT - && relativeWidgetLP->getAlign() != RELATIVE_ALIGN_NONE - && relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_TOP_RIGHT) - { - finalPosY += relativeWidgetMargin.top; - } finalPosX += mg.left; break; case RELATIVE_LOCATION_ABOVE_RIGHTALIGN: finalPosY += mg.bottom; - if (relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_TOP_CENTER_HORIZONTAL - && relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_TOP_LEFT - && relativeWidgetLP->getAlign() != RELATIVE_ALIGN_NONE - && relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_TOP_RIGHT) - { - finalPosY += relativeWidgetMargin.top; - } finalPosX -= mg.right; break; case RELATIVE_LOCATION_ABOVE_CENTER: finalPosY += mg.bottom; - if (relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_TOP_CENTER_HORIZONTAL - && relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_TOP_LEFT - && relativeWidgetLP->getAlign() != RELATIVE_ALIGN_NONE - && relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_TOP_RIGHT) - { - finalPosY += relativeWidgetMargin.top; - } break; case RELATIVE_LOCATION_LEFT_OF_TOPALIGN: finalPosX -= mg.right; - if (relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_TOP_LEFT - && relativeWidgetLP->getAlign() != RELATIVE_ALIGN_NONE - && relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_LEFT_BOTTOM - && relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_LEFT_CENTER_VERTICAL) - { - finalPosX -= relativeWidgetMargin.left; - } finalPosY -= mg.top; break; case RELATIVE_LOCATION_LEFT_OF_BOTTOMALIGN: finalPosX -= mg.right; - if (relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_TOP_LEFT - && relativeWidgetLP->getAlign() != RELATIVE_ALIGN_NONE - && relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_LEFT_BOTTOM - && relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_LEFT_CENTER_VERTICAL) - { - finalPosX -= relativeWidgetMargin.left; - } finalPosY += mg.bottom; break; case RELATIVE_LOCATION_LEFT_OF_CENTER: finalPosX -= mg.right; - if (relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_TOP_LEFT - && relativeWidgetLP->getAlign() != RELATIVE_ALIGN_NONE - && relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_LEFT_BOTTOM - && relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_LEFT_CENTER_VERTICAL) - { - finalPosX -= relativeWidgetMargin.left; - } break; case RELATIVE_LOCATION_RIGHT_OF_TOPALIGN: finalPosX += mg.left; - if (relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_TOP_RIGHT - && relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_RIGHT_BOTTOM - && relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_RIGHT_CENTER_VERTICAL) - { - finalPosX += relativeWidgetMargin.right; - } finalPosY -= mg.top; break; case RELATIVE_LOCATION_RIGHT_OF_BOTTOMALIGN: finalPosX += mg.left; - if (relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_TOP_RIGHT - && relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_RIGHT_BOTTOM - && relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_RIGHT_CENTER_VERTICAL) - { - finalPosX += relativeWidgetMargin.right; - } finalPosY += mg.bottom; break; case RELATIVE_LOCATION_RIGHT_OF_CENTER: finalPosX += mg.left; - if (relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_TOP_RIGHT - && relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_RIGHT_BOTTOM - && relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_RIGHT_CENTER_VERTICAL) - { - finalPosX += relativeWidgetMargin.right; - } break; case RELATIVE_LOCATION_BELOW_LEFTALIGN: finalPosY -= mg.top; - if (relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_LEFT_BOTTOM - && relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_RIGHT_BOTTOM - && relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_BOTTOM_CENTER_HORIZONTAL) - { - finalPosY -= relativeWidgetMargin.bottom; - } finalPosX += mg.left; break; case RELATIVE_LOCATION_BELOW_RIGHTALIGN: finalPosY -= mg.top; - if (relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_LEFT_BOTTOM - && relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_RIGHT_BOTTOM - && relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_BOTTOM_CENTER_HORIZONTAL) - { - finalPosY -= relativeWidgetMargin.bottom; - } finalPosX -= mg.right; break; case RELATIVE_LOCATION_BELOW_CENTER: finalPosY -= mg.top; - if (relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_LEFT_BOTTOM - && relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_RIGHT_BOTTOM - && relativeWidgetLP->getAlign() != RELATIVE_ALIGN_PARENT_BOTTOM_CENTER_HORIZONTAL) - { - finalPosY -= relativeWidgetMargin.bottom; - } break; default: break; From f2e9ae97e20e623359aa89f8d6eae46ad58a39ef Mon Sep 17 00:00:00 2001 From: qiaofeng00oo Date: Mon, 3 Mar 2014 17:47:55 +0800 Subject: [PATCH 13/13] modify autotest.py in tools/jenkins-scripts --- tools/jenkins-scripts/autotest.py | 75 +++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100755 tools/jenkins-scripts/autotest.py diff --git a/tools/jenkins-scripts/autotest.py b/tools/jenkins-scripts/autotest.py new file mode 100755 index 0000000000..a5ac0df1a2 --- /dev/null +++ b/tools/jenkins-scripts/autotest.py @@ -0,0 +1,75 @@ +import os +import sys +import subprocess +import socket +import time + +HOST = 'localhost' +PORT = 5678 + +def autotest(): + soc = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) + soc.connect((HOST, PORT)) + time.sleep(3) + print 'autotest run:' + soc.send('autotest run\r\n') + + while True: + buf = soc.recv(64) + print buf + + print 'test end and close socket.' + soc.close() + +#----------------autotest build and run----------------# +sleep_time = 1.5 +def cleanProj(): + infoClean = os.system('xcodebuild -project ./build/cocos2d_tests.xcodeproj -target Test\ cpp\ Mac clean') + print 'infoClean: ', infoClean + if infoClean != 0: + print 'clean **CLEAN FAILED**' + time.sleep(sleep_time) +def buildProj(): + infoBuild = os.system('xcodebuild -project ./build/cocos2d_tests.xcodeproj -target Test\ cpp\ Mac') + print 'infoBuild: ', infoBuild + if infoBuild != 0: + print 'build **BUILD FAILED**' + time.sleep(sleep_time) + return infoBuild +def openProj(): + cmd = 'open ./build/build/Debug/Test\ cpp\ Mac.app' + print 'cmd: ', cmd + infoOpen = os.system(cmd) + print 'infoOpen: ', infoOpen + if infoOpen != 0: + print 'open **OPEN FAILED**' + time.sleep(sleep_time) +def buildAndRun(): + # cleanProj() + if buildProj() != 0: + cleanProj() + buildProj() + openProj() + time.sleep(sleep_time) +#----------------autotest build and run end----------------# + +def main(): + try: + buildAndRun() + except Exception, e: + print 'BUILD FAILED!' + else: + autotest() + + +# -------------- main -------------- +if __name__ == '__main__': + sys_ret = 0 + try: + sys_ret = main() + except: + traceback.print_exc() + sys_ret = 1 + finally: + sys.exit(sys_ret) +