mirror of https://github.com/axmolengine/axmol.git
Merge pull request #961 from icewind/gles20
fixed #1289: CCControlButton update. Added zoomOnTouchDown property and setPreferredSize.
This commit is contained in:
commit
1b4de48e86
|
@ -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;
|
float scaleValue = (getIsHighlighted() && getIsEnabled() && !getIsSelected()) ? 1.1f : 1.0f;
|
||||||
CCAction *zoomAction =CCScaleTo::actionWithDuration(0.05f, scaleValue);
|
CCAction *zoomAction =CCScaleTo::actionWithDuration(0.05f, scaleValue);
|
||||||
zoomAction->setTag(kZoomActionTag);
|
zoomAction->setTag(kZoomActionTag);
|
||||||
runAction(zoomAction);
|
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;
|
||||||
|
|
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue