Merge pull request #961 from icewind/gles20

fixed #1289: CCControlButton update. Added zoomOnTouchDown property and setPreferredSize.
This commit is contained in:
James Chen 2012-06-03 19:55:39 -07:00
commit 1b4de48e86
2 changed files with 52 additions and 5 deletions

View File

@ -70,6 +70,9 @@ bool CCControlButton::initWithLabelAndBackgroundSprite(CCNode* node, CCScale9Spr
// Adjust the background image by default // Adjust the background image by default
m_adjustBackgroundImage=true; m_adjustBackgroundImage=true;
// Zooming button by default
m_zoomOnTouchDown = true;
// Set the default anchor point // Set the default anchor point
setIsRelativeAnchorPoint(true); setIsRelativeAnchorPoint(true);
setAnchorPoint(ccp(0.5f, 0.5f)); setAnchorPoint(ccp(0.5f, 0.5f));
@ -185,12 +188,51 @@ void CCControlButton::setIsHighlighted(bool enabled)
stopAction(action); stopAction(action);
} }
needsLayout(); needsLayout();
if( m_zoomOnTouchDown )
float scaleValue = (getIsHighlighted() && getIsEnabled() && !getIsSelected()) ? 1.1f : 1.0f; {
CCAction *zoomAction =CCScaleTo::actionWithDuration(0.05f, scaleValue); float scaleValue = (getIsHighlighted() && getIsEnabled() && !getIsSelected()) ? 1.1f : 1.0f;
zoomAction->setTag(kZoomActionTag); CCAction *zoomAction =CCScaleTo::actionWithDuration(0.05f, scaleValue);
runAction(zoomAction); zoomAction->setTag(kZoomActionTag);
runAction(zoomAction);
}
} }
void CCControlButton::setZoomOnTouchDown(bool zoomOnTouchDown)
{
m_zoomOnTouchDown = zoomOnTouchDown;
}
bool CCControlButton::getZoomOnTouchDown()
{
return m_zoomOnTouchDown;
}
void CCControlButton::setPreferredSize(CCSize size)
{
if(size.width == 0 && size.height == 0)
{
m_adjustBackgroundImage = true;
}
else
{
m_adjustBackgroundImage = false;
CCDictElement * item = NULL;
CCDICT_FOREACH(m_backgroundSpriteDispatchTable, item)
{
CCScale9Sprite* sprite = (CCScale9Sprite*)item->getObject();
sprite->setPreferredSize(size);
}
m_preferredSize = size;
}
needsLayout();
}
CCSize CCControlButton::getPreferredSize()
{
return m_preferredSize;
}
void CCControlButton::setAdjustBackgroundImage(bool adjustBackgroundImage) void CCControlButton::setAdjustBackgroundImage(bool adjustBackgroundImage)
{ {
m_adjustBackgroundImage=adjustBackgroundImage; m_adjustBackgroundImage=adjustBackgroundImage;

View File

@ -53,6 +53,11 @@ protected:
background will use the prefered size of the background image. */ background will use the prefered size of the background image. */
CC_PROPERTY(bool, m_adjustBackgroundImage, AdjustBackgroundImage); CC_PROPERTY(bool, m_adjustBackgroundImage, AdjustBackgroundImage);
/** Adjust the button zooming on touchdown. Default value is YES. */
CC_PROPERTY(bool, m_zoomOnTouchDown, ZoomOnTouchDown);
/** The prefered size of the button, if label is larger it will be expanded. */
CC_PROPERTY(CCSize, m_preferredSize, PreferredSize);
/** The current title that is displayed on the button. */ /** The current title that is displayed on the button. */
CC_SYNTHESIZE_READONLY(CCString*, m_currentTitle, CurrentTitle); CC_SYNTHESIZE_READONLY(CCString*, m_currentTitle, CurrentTitle);