Merge pull request #6991 from andyque/fixUIFrameColorAndOpacity

fix UI frame cascade color and opacity
This commit is contained in:
minggo 2014-06-09 09:42:47 +08:00
commit ccff80df2f
21 changed files with 89 additions and 262 deletions

View File

@ -260,7 +260,10 @@ void Button::loadTextureNormal(const std::string& normal,TextureResType texType)
_normalTextureSize = _buttonNormalRenderer->getContentSize();
updateFlippedX();
updateFlippedY();
updateRGBAToRenderer(_buttonNormalRenderer);
_buttonNormalRenderer->setColor(this->getColor());
_buttonNormalRenderer->setOpacity(this->getOpacity());
updateContentSizeWithTextureSize(_normalTextureSize);
_normalTextureLoaded = true;
_normalTextureAdaptDirty = true;
@ -308,7 +311,10 @@ void Button::loadTexturePressed(const std::string& selected,TextureResType texTy
_pressedTextureSize = _buttonClickedRenderer->getContentSize();
updateFlippedX();
updateFlippedY();
updateRGBAToRenderer(_buttonDisableRenderer);
_buttonDisableRenderer->setColor(this->getColor());
_buttonDisableRenderer->setOpacity(this->getOpacity());
_pressedTextureLoaded = true;
_pressedTextureAdaptDirty = true;
}
@ -355,7 +361,9 @@ void Button::loadTextureDisabled(const std::string& disabled,TextureResType texT
_disabledTextureSize = _buttonDisableRenderer->getContentSize();
updateFlippedX();
updateFlippedY();
updateRGBAToRenderer(_buttonDisableRenderer);
_buttonDisableRenderer->setColor(this->getColor());
_buttonDisableRenderer->setOpacity(this->getOpacity());
_disabledTextureLoaded = true;
_disabledTextureAdaptDirty = true;
}
@ -432,7 +440,7 @@ void Button::onPressStateChangedToNormal()
{
if (_scale9Enabled)
{
updateTextureRGBA();
updateTexturesRGBA();
}
else
{
@ -441,6 +449,17 @@ void Button::onPressStateChangedToNormal()
}
}
}
void Button::updateTexturesRGBA()
{
_buttonNormalRenderer->setColor(this->getColor());
_buttonClickedRenderer->setColor(this->getColor());
_buttonDisableRenderer->setColor(this->getColor());
_buttonNormalRenderer->setOpacity(this->getOpacity());
_buttonClickedRenderer->setOpacity(this->getOpacity());
_buttonDisableRenderer->setOpacity(this->getOpacity());
}
void Button::onPressStateChangedToPressed()
{
@ -732,27 +751,6 @@ std::string Button::getDescription() const
{
return "Button";
}
void Button::updateTextureColor()
{
updateColorToRenderer(_buttonNormalRenderer);
updateColorToRenderer(_buttonClickedRenderer);
updateColorToRenderer(_buttonDisableRenderer);
}
void Button::updateTextureOpacity()
{
updateOpacityToRenderer(_buttonNormalRenderer);
updateOpacityToRenderer(_buttonClickedRenderer);
updateOpacityToRenderer(_buttonDisableRenderer);
}
void Button::updateTextureRGBA()
{
updateRGBAToRenderer(_buttonNormalRenderer);
updateRGBAToRenderer(_buttonClickedRenderer);
updateRGBAToRenderer(_buttonDisableRenderer);
}
Widget* Button::createCloneInstance()
{

View File

@ -201,18 +201,22 @@ protected:
virtual void onPressStateChangedToPressed() override;
virtual void onPressStateChangedToDisabled() override;
virtual void onSizeChanged() override;
virtual void updateTextureColor() override;
virtual void updateTextureOpacity() override;
virtual void updateTextureRGBA() override;
virtual void updateFlippedX() override;
virtual void updateFlippedY() override;
void updateTexturesRGBA();
void normalTextureScaleChangedWithSize();
void pressedTextureScaleChangedWithSize();
void disabledTextureScaleChangedWithSize();
virtual Widget* createCloneInstance() override;
virtual void copySpecialProperties(Widget* model) override;
virtual void adaptRenderers() override;
void updateTitleLocation();
virtual Widget* createCloneInstance() override;
virtual void copySpecialProperties(Widget* model) override;
protected:
Node* _buttonNormalRenderer;
Node* _buttonClickedRenderer;

View File

@ -184,7 +184,9 @@ void CheckBox::loadTextureBackGround(const std::string& backGround,TextureResTyp
}
updateFlippedX();
updateFlippedY();
updateRGBAToRenderer(_backGroundBoxRenderer);
_backGroundBoxRenderer->setColor(this->getColor());
_backGroundBoxRenderer->setOpacity(this->getOpacity());
updateContentSizeWithTextureSize(_backGroundBoxRenderer->getContentSize());
_backGroundBoxRendererAdaptDirty = true;
}
@ -210,7 +212,8 @@ void CheckBox::loadTextureBackGroundSelected(const std::string& backGroundSelect
}
updateFlippedX();
updateFlippedY();
updateRGBAToRenderer(_backGroundSelectedBoxRenderer);
_backGroundSelectedBoxRenderer->setColor(this->getColor());
_backGroundSelectedBoxRenderer->setOpacity(this->getOpacity());
_backGroundSelectedBoxRendererAdaptDirty = true;
}
@ -235,7 +238,8 @@ void CheckBox::loadTextureFrontCross(const std::string& cross,TextureResType tex
}
updateFlippedX();
updateFlippedY();
updateRGBAToRenderer(_frontCrossRenderer);
_frontCrossRenderer->setColor(this->getColor());
_frontCrossRenderer->setOpacity(this->getOpacity());
_frontCrossRendererAdaptDirty = true;
}
@ -260,7 +264,9 @@ void CheckBox::loadTextureBackGroundDisabled(const std::string& backGroundDisabl
}
updateFlippedX();
updateFlippedY();
updateRGBAToRenderer(_backGroundBoxDisabledRenderer);
_backGroundBoxDisabledRenderer->setColor(this->getColor());
_backGroundBoxDisabledRenderer->setOpacity(this->getOpacity());
_backGroundBoxDisabledRendererAdaptDirty = true;
}
@ -285,7 +291,9 @@ void CheckBox::loadTextureFrontCrossDisabled(const std::string& frontCrossDisabl
}
updateFlippedX();
updateFlippedY();
updateRGBAToRenderer(_frontCrossDisabledRenderer);
_frontCrossDisabledRenderer->setColor(this->getColor());
_frontCrossDisabledRenderer->setOpacity(this->getOpacity());
_frontCrossDisabledRendererAdaptDirty = true;
}
@ -565,33 +573,6 @@ std::string CheckBox::getDescription() const
{
return "CheckBox";
}
void CheckBox::updateTextureColor()
{
updateColorToRenderer(_backGroundBoxRenderer);
updateColorToRenderer(_backGroundSelectedBoxRenderer);
updateColorToRenderer(_frontCrossRenderer);
updateColorToRenderer(_backGroundBoxDisabledRenderer);
updateColorToRenderer(_frontCrossDisabledRenderer);
}
void CheckBox::updateTextureOpacity()
{
updateOpacityToRenderer(_backGroundBoxRenderer);
updateOpacityToRenderer(_backGroundSelectedBoxRenderer);
updateOpacityToRenderer(_frontCrossRenderer);
updateOpacityToRenderer(_backGroundBoxDisabledRenderer);
updateOpacityToRenderer(_frontCrossDisabledRenderer);
}
void CheckBox::updateTextureRGBA()
{
updateRGBAToRenderer(_backGroundBoxRenderer);
updateRGBAToRenderer(_backGroundSelectedBoxRenderer);
updateRGBAToRenderer(_frontCrossRenderer);
updateRGBAToRenderer(_backGroundBoxDisabledRenderer);
updateRGBAToRenderer(_frontCrossDisabledRenderer);
}
Widget* CheckBox::createCloneInstance()
{

View File

@ -211,16 +211,16 @@ protected:
virtual void releaseUpEvent();
virtual void onSizeChanged() override;
virtual void updateTextureColor() override;
virtual void updateTextureOpacity() override;
virtual void updateTextureRGBA() override;
virtual void updateFlippedX() override;
virtual void updateFlippedY() override;
void backGroundTextureScaleChangedWithSize();
void backGroundSelectedTextureScaleChangedWithSize();
void frontCrossTextureScaleChangedWithSize();
void backGroundDisabledTextureScaleChangedWithSize();
void frontCrossDisabledTextureScaleChangedWithSize();
virtual Widget* createCloneInstance() override;
virtual void copySpecialProperties(Widget* model) override;
virtual void adaptRenderers() override;

View File

@ -154,7 +154,9 @@ void ImageView::loadTexture(const std::string& fileName, TextureResType texType)
_imageTextureSize = _imageRenderer->getContentSize();
updateFlippedX();
updateFlippedY();
updateRGBAToRenderer(_imageRenderer);
_imageRenderer->setColor(this->getColor());
_imageRenderer->setOpacity(this->getOpacity());
updateContentSizeWithTextureSize(_imageTextureSize);
_imageRendererAdaptDirty = true;
}
@ -321,21 +323,6 @@ std::string ImageView::getDescription() const
{
return "ImageView";
}
void ImageView::updateTextureColor()
{
updateColorToRenderer(_imageRenderer);
}
void ImageView::updateTextureOpacity()
{
updateOpacityToRenderer(_imageRenderer);
}
void ImageView::updateTextureRGBA()
{
updateRGBAToRenderer(_imageRenderer);
}
Widget* ImageView::createCloneInstance()
{

View File

@ -118,15 +118,15 @@ CC_CONSTRUCTOR_ACCESS:
protected:
virtual void initRenderer() override;
virtual void onSizeChanged() override;
virtual void updateTextureColor() override;
virtual void updateTextureOpacity() override;
virtual void updateTextureRGBA() override;
virtual void updateFlippedX() override;
virtual void updateFlippedY() override;
virtual void adaptRenderers() override;
void imageTextureScaleChangedWithSize();
virtual Widget* createCloneInstance() override;
virtual void copySpecialProperties(Widget* model) override;
virtual void adaptRenderers() override;
protected:
bool _scale9Enabled;
bool _prevIgnoreSize;

View File

@ -123,7 +123,7 @@ LoadingBar::Direction LoadingBar::getDirection()const
}
void LoadingBar::loadTexture(const std::string& texture,TextureResType texType)
void LoadingBar::loadTexture(const std::string& texture,TextureResType texType)
{
if (texture.empty())
{
@ -160,7 +160,9 @@ LoadingBar::Direction LoadingBar::getDirection()const
default:
break;
}
updateRGBAToRenderer(_barRenderer);
_barRenderer->setColor(this->getColor());
_barRenderer->setOpacity(this->getOpacity());
_barRendererTextureSize = _barRenderer->getContentSize();
switch (_direction)
@ -358,21 +360,6 @@ std::string LoadingBar::getDescription() const
{
return "LoadingBar";
}
void LoadingBar::updateTextureColor()
{
updateColorToRenderer(_barRenderer);
}
void LoadingBar::updateTextureOpacity()
{
updateOpacityToRenderer(_barRenderer);
}
void LoadingBar::updateTextureRGBA()
{
updateRGBAToRenderer(_barRenderer);
}
Widget* LoadingBar::createCloneInstance()
{

View File

@ -141,14 +141,14 @@ public:
protected:
virtual void initRenderer() override;
virtual void onSizeChanged() override;
virtual void updateTextureColor() override;
virtual void updateTextureOpacity() override;
virtual void updateTextureRGBA() override;
void setScale9Scale();
void barRendererScaleChangedWithSize();
virtual void adaptRenderers() override;
virtual Widget* createCloneInstance() override;
virtual void copySpecialProperties(Widget* model) override;
virtual void adaptRenderers() override;
protected:
Direction _direction;
float _percent;

View File

@ -147,7 +147,9 @@ void Slider::loadBarTexture(const std::string& fileName, TextureResType texType)
default:
break;
}
updateRGBAToRenderer(_barRenderer);
_barRenderer->setColor(this->getColor());
_barRenderer->setOpacity(this->getOpacity());
_barRendererAdaptDirty = true;
_progressBarRendererDirty = true;
updateContentSizeWithTextureSize(_barRenderer->getContentSize());
@ -186,7 +188,10 @@ void Slider::loadProgressBarTexture(const std::string& fileName, TextureResType
default:
break;
}
updateRGBAToRenderer(_progressBarRenderer);
_progressBarRenderer->setColor(this->getColor());
_progressBarRenderer->setOpacity(this->getOpacity());
_progressBarRenderer->setAnchorPoint(Vec2(0.0f, 0.5f));
_progressBarTextureSize = _progressBarRenderer->getContentSize();
_progressBarRendererDirty = true;
@ -308,7 +313,8 @@ void Slider::loadSlidBallTextureNormal(const std::string& normal,TextureResType
default:
break;
}
updateRGBAToRenderer(_slidBallNormalRenderer);
_slidBallNormalRenderer->setColor(this->getColor());
_slidBallNormalRenderer->setOpacity(this->getOpacity());
}
void Slider::loadSlidBallTexturePressed(const std::string& pressed,TextureResType texType)
@ -330,7 +336,8 @@ void Slider::loadSlidBallTexturePressed(const std::string& pressed,TextureResTyp
default:
break;
}
updateRGBAToRenderer(_slidBallPressedRenderer);
_slidBallPressedRenderer->setColor(this->getColor());
_slidBallPressedRenderer->setOpacity(this->getOpacity());
}
void Slider::loadSlidBallTextureDisabled(const std::string& disabled,TextureResType texType)
@ -352,7 +359,8 @@ void Slider::loadSlidBallTexturePressed(const std::string& pressed,TextureResTyp
default:
break;
}
updateRGBAToRenderer(_slidBallDisabledRenderer);
_slidBallDisabledRenderer->setColor(this->getColor());
_slidBallDisabledRenderer->setOpacity(this->getOpacity());
}
void Slider::setPercent(int percent)
@ -582,33 +590,6 @@ std::string Slider::getDescription() const
{
return "Slider";
}
void Slider::updateTextureColor()
{
updateColorToRenderer(_barRenderer);
updateColorToRenderer(_progressBarRenderer);
updateColorToRenderer(_slidBallNormalRenderer);
updateColorToRenderer(_slidBallPressedRenderer);
updateColorToRenderer(_slidBallDisabledRenderer);
}
void Slider::updateTextureOpacity()
{
updateOpacityToRenderer(_barRenderer);
updateOpacityToRenderer(_progressBarRenderer);
updateOpacityToRenderer(_slidBallNormalRenderer);
updateOpacityToRenderer(_slidBallPressedRenderer);
updateOpacityToRenderer(_slidBallDisabledRenderer);
}
void Slider::updateTextureRGBA()
{
updateRGBAToRenderer(_barRenderer);
updateRGBAToRenderer(_progressBarRenderer);
updateRGBAToRenderer(_slidBallNormalRenderer);
updateRGBAToRenderer(_slidBallPressedRenderer);
updateRGBAToRenderer(_slidBallDisabledRenderer);
}
Widget* Slider::createCloneInstance()
{

View File

@ -218,9 +218,7 @@ protected:
virtual void onPressStateChangedToPressed() override;
virtual void onPressStateChangedToDisabled() override;
virtual void onSizeChanged() override;
virtual void updateTextureColor() override;
virtual void updateTextureOpacity() override;
virtual void updateTextureRGBA() override;
void barRendererScaleChangedWithSize();
void progressBarRendererScaleChangedWithSize();
virtual Widget* createCloneInstance() override;

View File

@ -324,20 +324,6 @@ std::string Text::getDescription() const
return "Label";
}
void Text::updateTextureColor()
{
updateColorToRenderer(_labelRenderer);
}
void Text::updateTextureOpacity()
{
updateOpacityToRenderer(_labelRenderer);
}
void Text::updateTextureRGBA()
{
updateRGBAToRenderer(_labelRenderer);
}
Widget* Text::createCloneInstance()
{

View File

@ -172,9 +172,7 @@ protected:
virtual void onPressStateChangedToPressed() override;
virtual void onPressStateChangedToDisabled() override;
virtual void onSizeChanged() override;
virtual void updateTextureColor() override;
virtual void updateTextureOpacity() override;
virtual void updateTextureRGBA() override;
virtual void updateFlippedX() override;
virtual void updateFlippedY() override;
void labelScaleChangedWithSize();

View File

@ -171,21 +171,6 @@ std::string TextAtlas::getDescription() const
{
return "TextAtlas";
}
void TextAtlas::updateTextureColor()
{
updateColorToRenderer(_labelAtlasRenderer);
}
void TextAtlas::updateTextureOpacity()
{
updateOpacityToRenderer(_labelAtlasRenderer);
}
void TextAtlas::updateTextureRGBA()
{
updateRGBAToRenderer(_labelAtlasRenderer);
}
Widget* TextAtlas::createCloneInstance()
{

View File

@ -106,9 +106,7 @@ public:
protected:
virtual void initRenderer() override;
virtual void onSizeChanged() override;
virtual void updateTextureColor() override;
virtual void updateTextureOpacity() override;
virtual void updateTextureRGBA() override;
void labelAtlasScaleChangedWithSize();
virtual Widget* createCloneInstance() override;
virtual void copySpecialProperties(Widget* model) override;

View File

@ -87,7 +87,9 @@ void TextBMFont::setFntFile(const std::string& fileName)
}
_fntFileName = fileName;
_labelBMFontRenderer->setBMFontFilePath(fileName);
updateRGBAToRenderer(_labelBMFontRenderer);
_labelBMFontRenderer->setColor(this->getColor());
_labelBMFontRenderer->setOpacity(this->getOpacity());
_fntFileHasInit = true;
setString(_stringValue);
}
@ -165,21 +167,6 @@ std::string TextBMFont::getDescription() const
{
return "TextBMFont";
}
void TextBMFont::updateTextureColor()
{
updateColorToRenderer(_labelBMFontRenderer);
}
void TextBMFont::updateTextureOpacity()
{
updateOpacityToRenderer(_labelBMFontRenderer);
}
void TextBMFont::updateTextureRGBA()
{
updateRGBAToRenderer(_labelBMFontRenderer);
}
Widget* TextBMFont::createCloneInstance()
{

View File

@ -89,9 +89,7 @@ public:
protected:
virtual void initRenderer() override;
virtual void onSizeChanged() override;
virtual void updateTextureColor() override;
virtual void updateTextureOpacity() override;
virtual void updateTextureRGBA() override;
void labelBMFontScaleChangedWithSize();
virtual Widget* createCloneInstance() override;
virtual void copySpecialProperties(Widget* model) override;

View File

@ -799,21 +799,6 @@ std::string TextField::getDescription() const
{
return "TextField";
}
void TextField::updateTextureColor()
{
updateColorToRenderer(_textFieldRenderer);
}
void TextField::updateTextureOpacity()
{
updateOpacityToRenderer(_textFieldRenderer);
}
void TextField::updateTextureRGBA()
{
updateRGBAToRenderer(_textFieldRenderer);
}
void TextField::attachWithIME()
{

View File

@ -197,9 +197,7 @@ protected:
void insertTextEvent();
void deleteBackwardEvent();
virtual void onSizeChanged() override;
virtual void updateTextureColor() override;
virtual void updateTextureOpacity() override;
virtual void updateTextureRGBA() override;
void textfieldRendererScaleChangedWithSize();
virtual Widget* createCloneInstance() override;

View File

@ -157,8 +157,6 @@ _positionPercent(Vec2::ZERO),
_reorderWidgetChildDirty(true),
_hitted(false),
_touchListener(nullptr),
_color(Color3B::WHITE),
_opacity(255),
_flippedX(false),
_flippedY(false),
_focused(false),
@ -212,6 +210,8 @@ bool Widget::init()
setBright(true);
ignoreContentAdaptWithSize(true);
setAnchorPoint(Vec2(0.5f, 0.5f));
this->setCascadeColorEnabled(true);
this->setCascadeOpacityEnabled(true);
return true;
}
return false;
@ -1075,18 +1075,6 @@ void Widget::copyProperties(Widget *widget)
onSizeChanged();
}
void Widget::setColor(const Color3B& color)
{
_color = color;
updateTextureColor();
}
void Widget::setOpacity(GLubyte opacity)
{
_opacity = opacity;
updateTextureOpacity();
}
void Widget::setFlippedX(bool flippedX)
{
_flippedX = flippedX;
@ -1099,21 +1087,6 @@ void Widget::setFlippedY(bool flippedY)
updateFlippedY();
}
void Widget::updateColorToRenderer(Node* renderer)
{
renderer->setColor(_color);
}
void Widget::updateOpacityToRenderer(Node* renderer)
{
renderer->setOpacity(_opacity);
}
void Widget::updateRGBAToRenderer(Node* renderer)
{
renderer->setColor(_color);
renderer->setOpacity(_opacity);
}
/*temp action*/
void Widget::setActionTag(int tag)

View File

@ -334,14 +334,6 @@ public:
* @return true if the widget is flipped vertically, flase otherwise.
*/
virtual bool isFlippedY()const{return _flippedY;};
virtual void setColor(const Color3B& color) override;
virtual void setOpacity(GLubyte opacity) override;
const Color3B& getColor() const override {return _color;};
GLubyte getOpacity() const override {return _opacity;};
/** @deprecated Use isFlippedX() instead */
CC_DEPRECATED_ATTRIBUTE bool isFlipX() { return isFlippedX(); };
@ -649,18 +641,10 @@ protected:
virtual void releaseUpEvent();
virtual void cancelUpEvent();
virtual void updateTextureColor(){};
virtual void updateTextureOpacity(){};
virtual void updateTextureRGBA(){};
virtual void updateFlippedX(){};
virtual void updateFlippedY(){};
virtual void adaptRenderers(){};
void updateColorToRenderer(Node* renderer);
void updateOpacityToRenderer(Node* renderer);
void updateRGBAToRenderer(Node* renderer);
void copyProperties(Widget* model);
virtual Widget* createCloneInstance();
@ -720,8 +704,6 @@ protected:
bool _reorderWidgetChildDirty;
bool _hitted;
EventListenerTouchOneByOne* _touchListener;
Color3B _color;
GLubyte _opacity;
bool _flippedX;
bool _flippedY;
//use map to enble switch back and forth for user layout parameters

View File

@ -98,7 +98,8 @@ bool Scale9Sprite::initWithBatchNode(SpriteBatchNode* batchnode, const Rect& rec
{
this->updateWithBatchNode(batchnode, rect, rotated, capInsets);
}
this->setCascadeColorEnabled(true);
this->setCascadeOpacityEnabled(true);
this->setAnchorPoint(Vec2(0.5f, 0.5f));
this->_positionsAreDirty = true;