diff --git a/cocos/gui/UILayout.cpp b/cocos/gui/UILayout.cpp index 14bdff0831..7460c03723 100644 --- a/cocos/gui/UILayout.cpp +++ b/cocos/gui/UILayout.cpp @@ -81,7 +81,9 @@ _currentStencilPassDepthPass(GL_KEEP), _currentDepthWriteMask(GL_TRUE), _currentAlphaTestEnabled(GL_FALSE), _currentAlphaTestFunc(GL_ALWAYS), -_currentAlphaTestRef(1) +_currentAlphaTestRef(1), +_backGroundImageColor(Color3B::WHITE), +_backGroundImageOpacity(255) { _widgetType = WidgetTypeContainer; } @@ -628,20 +630,9 @@ void Layout::setBackGroundImage(const char* fileName,TextureResType texType) break; } } - if (_backGroundScale9Enabled) - { - extension::Scale9Sprite* bgiScale9 = static_cast(_backGroundImage); - bgiScale9->setColor(getColor()); - bgiScale9->setOpacity(getOpacity()); - } - else - { - Sprite* bgiScale9 = static_cast(_backGroundImage); - bgiScale9->setColor(getColor()); - bgiScale9->setOpacity(getOpacity()); - } _backGroundImageTextureSize = _backGroundImage->getContentSize(); _backGroundImage->setPosition(Point(_size.width/2.0f, _size.height/2.0f)); + updateBackGroundImageRGBA(); } void Layout::setBackGroundImageCapInsets(const Rect &capInsets) @@ -828,7 +819,7 @@ const Color3B& Layout::getBackGroundEndColor() return _gEndColor; } -void Layout::setBackGroundColorOpacity(int opacity) +void Layout::setBackGroundColorOpacity(GLubyte opacity) { _cOpacity = opacity; switch (_colorType) @@ -846,7 +837,7 @@ void Layout::setBackGroundColorOpacity(int opacity) } } -int Layout::getBackGroundColorOpacity() +GLubyte Layout::getBackGroundColorOpacity() { return _cOpacity; } @@ -865,6 +856,53 @@ const Point& Layout::getBackGroundColorVector() return _alongVector; } +void Layout::setBackGroundImageColor(const Color3B &color) +{ + _backGroundImageColor = color; + updateBackGroundImageColor(); +} + +void Layout::setBackGroundImageOpacity(GLubyte opacity) +{ + _backGroundImageOpacity = opacity; + updateBackGroundImageOpacity(); +} + +const Color3B& Layout::getBackGroundImageColor() +{ + return _backGroundImageColor; +} + +GLubyte Layout::getBackGroundImageOpacity() +{ + return _backGroundImageOpacity; +} + +void Layout::updateBackGroundImageColor() +{ + if (_backGroundImage) + { + _backGroundImage->setColor(_backGroundImageColor); + } +} + +void Layout::updateBackGroundImageOpacity() +{ + if (_backGroundImage) + { + _backGroundImage->setOpacity(_backGroundImageOpacity); + } +} + +void Layout::updateBackGroundImageRGBA() +{ + if (_backGroundImage) + { + _backGroundImage->setColor(_backGroundImageColor); + _backGroundImage->setOpacity(_backGroundImageOpacity); + } +} + const Size& Layout::getBackGroundImageTextureSize() const { return _backGroundImageTextureSize; diff --git a/cocos/gui/UILayout.h b/cocos/gui/UILayout.h index 272033493d..479e14bee1 100644 --- a/cocos/gui/UILayout.h +++ b/cocos/gui/UILayout.h @@ -141,9 +141,9 @@ public: * * @param opacity */ - void setBackGroundColorOpacity(int opacity); + void setBackGroundColorOpacity(GLubyte opacity); - int getBackGroundColorOpacity(); + GLubyte getBackGroundColorOpacity(); /** * Sets background color vector for layout, if color type is LAYOUT_COLOR_GRADIENT @@ -154,6 +154,14 @@ public: const Point& getBackGroundColorVector(); + void setBackGroundImageColor(const ccColor3B& color); + + void setBackGroundImageOpacity(GLubyte opacity); + + const ccColor3B& getBackGroundImageColor(); + + GLubyte getBackGroundImageOpacity(); + /** * Remove the background image of layout. */ @@ -286,6 +294,9 @@ protected: void onBeforeVisitScissor(); void onAfterVisitScissor(); + void updateBackGroundImageColor(); + void updateBackGroundImageOpacity(); + void updateBackGroundImageRGBA(); protected: bool _clippingEnabled; @@ -302,7 +313,7 @@ protected: Color3B _gStartColor; Color3B _gEndColor; Point _alongVector; - int _cOpacity; + GLubyte _cOpacity; Size _backGroundImageTextureSize; LayoutType _layoutType; LayoutClippingType _clippingType; @@ -329,8 +340,11 @@ protected: GLenum _currentAlphaTestFunc; GLclampf _currentAlphaTestRef; - GLint _mask_layer_le; + Color3B _backGroundImageColor; + GLubyte _backGroundImageOpacity; + + GLint _mask_layer_le; GroupCommand _groupCommand; CustomCommand _beforeVisitCmdStencil; CustomCommand _afterDrawStencilCmd; diff --git a/cocos/gui/UIListView.h b/cocos/gui/UIListView.h index a8d92c5794..58cf81ff46 100644 --- a/cocos/gui/UIListView.h +++ b/cocos/gui/UIListView.h @@ -172,7 +172,7 @@ public: virtual std::string getDescription() const override; void requestRefreshView(); - + void refreshView(); protected: virtual void addChild(Node* child) override{ScrollView::addChild(child);}; virtual void addChild(Node * child, int zOrder) override{ScrollView::addChild(child, zOrder);}; @@ -195,7 +195,6 @@ protected: virtual void copyClonedWidgetChildren(Widget* model) override; void selectedItemEvent(); virtual void interceptTouchEvent(int handleState,Widget* sender,const Point &touchPoint) override; - void refreshView(); protected: Widget* _model; diff --git a/cocos/gui/UIWidget.cpp b/cocos/gui/UIWidget.cpp index 403213c1fc..a1984c95d0 100644 --- a/cocos/gui/UIWidget.cpp +++ b/cocos/gui/UIWidget.cpp @@ -568,6 +568,11 @@ const Size& Widget::getSize() const { return _size; } + +const Size& Widget::getCustomSize() const +{ + return _customSize; +} const Point& Widget::getSizePercent() const { diff --git a/cocos/gui/UIWidget.h b/cocos/gui/UIWidget.h index 1a8597e5b7..38b19bcceb 100644 --- a/cocos/gui/UIWidget.h +++ b/cocos/gui/UIWidget.h @@ -547,6 +547,8 @@ public: * @return size */ const Size& getSize() const; + + const Size& getCustomSize() const; /** * Returns size percent of widget