From 07215f11845fdca57ac24eab235753b2c8cec7c3 Mon Sep 17 00:00:00 2001 From: Victor Buldakov Date: Mon, 4 Nov 2013 17:17:01 +0400 Subject: [PATCH] Add scale ratio to button touchdown --- extensions/GUI/CCControlExtension/CCControlButton.cpp | 6 +++--- extensions/GUI/CCControlExtension/CCControlButton.h | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/extensions/GUI/CCControlExtension/CCControlButton.cpp b/extensions/GUI/CCControlExtension/CCControlButton.cpp index 247634a72c..b0878b8933 100644 --- a/extensions/GUI/CCControlExtension/CCControlButton.cpp +++ b/extensions/GUI/CCControlExtension/CCControlButton.cpp @@ -50,6 +50,7 @@ ControlButton::ControlButton() , _titleLabel(NULL) , _backgroundSprite(NULL) , _zoomOnTouchDown(false) +, _scaleRatio(1.0) , _titleDispatchTable(NULL) , _titleColorDispatchTable(NULL) , _titleLabelDispatchTable(NULL) @@ -98,8 +99,6 @@ bool ControlButton::initWithLabelAndBackgroundSprite(Node* node, Scale9Sprite* b setTouchEnabled(true); _isPushed = false; - _zoomOnTouchDown = true; - _currentTitle=NULL; // Adjust the background image by default @@ -107,6 +106,7 @@ bool ControlButton::initWithLabelAndBackgroundSprite(Node* node, Scale9Sprite* b setPreferredSize(Size::ZERO); // Zooming button by default _zoomOnTouchDown = true; + _scaleRatio = 1.1f; // Set the default anchor point ignoreAnchorPointForPosition(false); @@ -221,7 +221,7 @@ void ControlButton::setHighlighted(bool enabled) needsLayout(); if( _zoomOnTouchDown ) { - float scaleValue = (isHighlighted() && isEnabled() && !isSelected()) ? 1.1f : 1.0f; + float scaleValue = (isHighlighted() && isEnabled() && !isSelected()) ? _scaleRatio : 1.0f; Action *zoomAction = ScaleTo::create(0.05f, scaleValue); zoomAction->setTag(kZoomActionTag); runAction(zoomAction); diff --git a/extensions/GUI/CCControlExtension/CCControlButton.h b/extensions/GUI/CCControlExtension/CCControlButton.h index 5a30c64f4c..61bc24f76e 100644 --- a/extensions/GUI/CCControlExtension/CCControlButton.h +++ b/extensions/GUI/CCControlExtension/CCControlButton.h @@ -230,6 +230,8 @@ protected: /** Adjust the button zooming on touchdown. Default value is YES. */ CC_PROPERTY(bool, _zoomOnTouchDown, ZoomOnTouchDown); + /** Scale ratio button on touchdown. Default value 1.1f */ + CC_SYNTHESIZE(float, _scaleRatio, ScaleRatio); CC_PROPERTY(Point, _labelAnchorPoint, LabelAnchorPoint);