From b87e932b9ff2093ee9bc7351f9d36ba5ebbbc0f3 Mon Sep 17 00:00:00 2001 From: icewind Date: Thu, 7 Jun 2012 13:20:30 +0400 Subject: [PATCH] Override setOpacity to affect a background sprites Calling button->setOpacity was affecting only to label. Now opacity value applies also to a background sprites --- .../CCControlExtension/CCControlButton.cpp | 27 +++++++++++++++++++ .../CCControlExtension/CCControlButton.h | 5 ++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/cocos2dx/extensions/CCControlExtension/CCControlButton.cpp b/cocos2dx/extensions/CCControlExtension/CCControlButton.cpp index 24c00f96ed..12f767f1a9 100644 --- a/cocos2dx/extensions/CCControlExtension/CCControlButton.cpp +++ b/cocos2dx/extensions/CCControlExtension/CCControlButton.cpp @@ -496,6 +496,33 @@ void CCControlButton::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent) } } +void CCControlButton::setOpacity(GLubyte opacity) +{ + m_cOpacity = opacity; + + CCObject* child; + CCArray* children=getChildren(); + CCARRAY_FOREACH(children, child) + { + CCRGBAProtocol* pNode = dynamic_cast(child); + if (pNode) + { + pNode->setOpacity(opacity); + } + } + CCDictElement * item = NULL; + CCDICT_FOREACH(m_backgroundSpriteDispatchTable, item) + { + CCScale9Sprite* sprite = (CCScale9Sprite*)item->getObject(); + sprite->setOpacity(opacity); + } +} + +GLubyte CCControlButton::getOpacity() +{ + return m_cOpacity; +} + void CCControlButton::ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent) { m_nState = CCControlStateNormal; diff --git a/cocos2dx/extensions/CCControlExtension/CCControlButton.h b/cocos2dx/extensions/CCControlExtension/CCControlButton.h index 75abd743d0..8f993d6fe6 100644 --- a/cocos2dx/extensions/CCControlExtension/CCControlButton.h +++ b/cocos2dx/extensions/CCControlExtension/CCControlButton.h @@ -70,6 +70,9 @@ protected: //CC_PROPERTY(CCScale9Sprite*, m_backgroundSprite, BackgroundSprite); CCScale9Sprite* m_backgroundSprite; + /* Override setter to affect a background sprite too */ + CC_PROPERTY(GLubyte, m_cOpacity, Opacity); + /** Flag to know if the button is currently pushed. */ CC_SYNTHESIZE_READONLY(bool, pushed, IsPushed); // @@ -105,8 +108,6 @@ public: virtual void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent); virtual void ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent); - - /** * Returns the title used for a state. *