CCControlExtension/CCControlButton

#ifndef __CCCONTROL_BUTTON_H__

#define __CCCONTROL_BUTTON_H__

#include "CCControl.h"

#include "CCInvocation.h"

#include "CCScale9Sprite.h"

NS_CC_EXT_BEGIN

/* Define the button margin for Left/Right edge */

#define CCControlButtonMarginLR 8 // px

/* Define the button margin for Top/Bottom edge */

#define CCControlButtonMarginTB 2 // px

/**

* @addtogroup GUI

* @{

* @addtogroup control_extension

* @{

*/

/** @class CCControlButton Button control for Cocos2D. */

class CCControlButton : public CCControl

{

public:

CCControlButton();

virtual ~CCControlButton();

virtual void needsLayout(void);

virtual void setEnabled(bool enabled);

virtual void setSelected(bool enabled);

virtual void setHighlighted(bool enabled);

protected:

// CCRGBAProtocol

//bool m_bIsOpacityModifyRGB;

/** The current title that is displayed on the button. */

CC_SYNTHESIZE_READONLY(CCString*, m_currentTitle, CurrentTitle);

/** The current color used to display the title. */

CC_SYNTHESIZE_READONLY_PASS_BY_REF(ccColor3B, m_currentTitleColor, CurrentTitleColor);

/** Adjust the background image. YES by default. If the property is set to NO, the

background will use the prefered size of the background image. */

bool doesAdjustBackgroundImage();

void setAdjustBackgroundImage(bool adjustBackgroundImage);

bool m_doesAdjustBackgroundImage;

/** The current title label. */

CC_SYNTHESIZE_RETAIN(CCNode*, m_titleLabel, TitleLabel);

/** The current background sprite. */

CC_SYNTHESIZE_RETAIN(CCScale9Sprite*, m_backgroundSprite, BackgroundSprite);

/** The prefered size of the button, if label is larger it will be expanded. */

CC_PROPERTY(CCSize, m_preferredSize, PreferredSize);

/** Adjust the button zooming on touchdown. Default value is YES. */

CC_PROPERTY(bool, m_zoomOnTouchDown, ZoomOnTouchDown);

CC_PROPERTY(CCPoint, m_labelAnchorPoint, LabelAnchorPoint);

/* Override setter to affect a background sprite too */

virtual GLubyte getOpacity(void);

virtual void setOpacity(GLubyte var);

virtual const ccColor3B& getColor(void);

virtual void setColor(const ccColor3B&);

/** Flag to know if the button is currently pushed.  */

protected:

bool m_isPushed;

bool m_bParentInited;

public:

bool isPushed() { return m_isPushed; }

// <CCControlState, CCString*>

CC_SYNTHESIZE_RETAIN(CCDictionary*, m_titleDispatchTable, TitleDispatchTable);

// <CCControlState, CCColor3bObject*>

CC_SYNTHESIZE_RETAIN(CCDictionary*, m_titleColorDispatchTable, TitleColorDispatchTable);

// <CCControlState, CCNode*>

CC_SYNTHESIZE_RETAIN(CCDictionary*, m_titleLabelDispatchTable, TitleLabelDispatchTable);

// <CCControlState, CCScale9Sprite*>

CC_SYNTHESIZE_RETAIN(CCDictionary*, m_backgroundSpriteDispatchTable, BackgroundSpriteDispatchTable);

/* Define the button margin for Top/Bottom edge */

CC_SYNTHESIZE_READONLY(int, m_marginV, VerticalMargin);

/* Define the button margin for Left/Right edge */

CC_SYNTHESIZE_READONLY(int, m_marginH, HorizontalOrigin);

//set the margins at once (so we only have to do one call of needsLayout)

virtual void setMargins(int marginH, int marginV);

public:

virtual bool init();

virtual bool initWithLabelAndBackgroundSprite(CCNode* label, CCScale9Sprite* backgroundSprite);

static CCControlButton* create(CCNode* label, CCScale9Sprite* backgroundSprite);

virtual bool initWithTitleAndFontNameAndFontSize(std::string title, const char * fontName, float fontSize);

static CCControlButton* create(std::string title, const char * fontName, float fontSize);

virtual bool initWithBackgroundSprite(CCScale9Sprite* sprite);

static CCControlButton* create(CCScale9Sprite* sprite);

//events

virtual bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent);

virtual void ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent);

virtual void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent);

virtual void ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent);

/**

* Returns the title used for a state.

*

* @param state The state that uses the title. Possible values are described in

* "CCControlState".

*

* @return The title for the specified state.

*/

virtual CCString* getTitleForState(CCControlState state);

/**

* Sets the title string to use for the specified state.

* If a property is not specified for a state, the default is to use

* the CCButtonStateNormal value.

*

* @param title The title string to use for the specified state.

* @param state The state that uses the specified title. The values are described

* in "CCControlState".

*/

virtual void setTitleForState(CCString* title, CCControlState state);

/**

* Returns the title color used for a state.

*

* @param state The state that uses the specified color. The values are described

* in "CCControlState".

*

* @return The color of the title for the specified state.

*/

virtual const ccColor3B getTitleColorForState(CCControlState state);

/**

* Sets the color of the title to use for the specified state.

*

* @param color The color of the title to use for the specified state.

* @param state The state that uses the specified color. The values are described

* in "CCControlState".

*/

virtual void setTitleColorForState(ccColor3B color, CCControlState state);

/**

* Returns the title label used for a state.

*

* @param state The state that uses the title label. Possible values are described

* in "CCControlState".

*/

virtual CCNode* getTitleLabelForState(CCControlState state);

/**

* Sets the title label to use for the specified state.

* If a property is not specified for a state, the default is to use

* the CCButtonStateNormal value.

*

* @param title The title label to use for the specified state.

* @param state The state that uses the specified title. The values are described

* in "CCControlState".

*/

virtual void setTitleLabelForState(CCNode* label, CCControlState state);

virtual void setTitleTTFForState(const char * fntFile, CCControlState state);

virtual const char * getTitleTTFForState(CCControlState state);

virtual void setTitleTTFSizeForState(float size, CCControlState state);

virtual float getTitleTTFSizeForState(CCControlState state);

/**

* Sets the font of the label, changes the label to a CCLabelBMFont if neccessary.

* @param fntFile The name of the font to change to

* @param state The state that uses the specified fntFile. The values are described

* in "CCControlState".

*/

virtual void setTitleBMFontForState(const char * fntFile, CCControlState state);

virtual const char * getTitleBMFontForState(CCControlState state);

/**

* Returns the background sprite used for a state.

*

* @param state The state that uses the background sprite. Possible values are

* described in "CCControlState".

*/

virtual CCScale9Sprite* getBackgroundSpriteForState(CCControlState state);

/**

* Sets the background sprite to use for the specified button state.

*

* @param sprite The background sprite to use for the specified state.

* @param state The state that uses the specified image. The values are described

* in "CCControlState".

*/

virtual void setBackgroundSpriteForState(CCScale9Sprite* sprite, CCControlState state);

/**

* Sets the background spriteFrame to use for the specified button state.

*

* @param spriteFrame The background spriteFrame to use for the specified state.

* @param state The state that uses the specified image. The values are described

* in "CCControlState".

*/

virtual void setBackgroundSpriteFrameForState(CCSpriteFrame * spriteFrame, CCControlState state);

static CCControlButton* create();

};

// end of GUI group

/// @}

/// @}

NS_CC_EXT_END

#endif

时间: 2024-10-19 16:01:33

CCControlExtension/CCControlButton的相关文章

【独立开发者er Cocos2d-x实战 013】Cocos2dx 网络编程实战之星座运势

本篇文章主要内容:jsoncpp的使用,Cocos2dx网络编程,聚合数据星座运势接口使用. 1.jsoncpp使用: jsoncpp的生成请参考博客:Jsoncpp使用详解以及链接问题解决 2.聚合数据星座运势接口使用: 我们先登上聚合数据官网,申请相关的数据后,就可以得到APPKEY等信息,调试如下: 3.Cocos2dx网络编程:源码下载请点击(源码中包括jsoncpp文件) #include "HelloWorldScene.h" #include "CocoStud

【独立开发人员er Cocos2d-x实战 013】Cocos2dx 网络编程实战之星座运势

学习cocos2d-x和cocos creator的圈子:cocos2d-x:436689827    cocos creator:124727696 本篇文章主要内容:jsoncpp的使用,Cocos2dx网络编程,聚合数据星座运势接口使用. 1.jsoncpp使用: jsoncpp的生成请參考博客:Jsoncpp使用具体解释以及链接问题解决 2.聚合数据星座运势接口使用: 我们先登上聚合数据官网.申请相关的数据后,就能够得到APPKEY等信息,调试例如以下: 3.Cocos2dx网络编程:源

cocos2d-x 之CCControlButton的使用方法

偶在今天想通过某一个按钮的按下松开实现针对于某一个动画的切换,之前使用的CCMenuItemImage,大概代码如下: CCMenuItemImage *pFightItem = CCMenuItemImage::create(        "Normal.png","Selected.png",this,        menu_selector(SecondScene::menuFightCallback)); pFightItem->setPositi

cocos2dx CCControlButton button大事

=================================.cpp文件 <pre name="code" class="cpp">bool HelloWorld::init() { if ( !CCLayer::init() ) { return false; } CCLabelTTF * label = CCLabelTTF::create("为选中文字", "MarkerFelt",25); CCCon

cocos2dx基础篇(13)——按钮控件CCControlButton

[引言] 按钮类CCControlButton继承于控件类CCControl. 控件类CCControl主要向子类提供了一系列的控件触发事件.当子控件触发相关的事件后,就会执行相关的控件事件回调函数.这与之前讲的CCMenu中的菜单按钮回调是类似的. 控件类CCControl主要有三个子类: (1)开关控件CCControlSwitch (2)滑块控件CCControlSlider (3)按钮控件CCControlButton 本节讲的是其子类其中之一:按钮类CCControlButton. [

【Cocos2dx】使用CCControlButton创建按钮、按钮点击事件,点击事件中的组件获取,setPosition的坐标问题

按钮不仅在游戏,在任何地方都是不可或缺却又是最基本的东西.在游戏引擎Cocos2dx中也不例外. 下面用一个例子说明Cocos2dx中如何使用按钮,同时,如果在Cocos2dx中获取层,也就是场景.舞台中的组件. 如下图,有一个按钮Clickme,被点击时候与不被点击的时间,其背景图片是不同的.其实就是资源文件夹Resource中早就被玩坏的两个图片,一张CloseNormal.png一张CloseSelected.png被拉伸后的惨状. Cocos2dx的资源文件夹在<[Cocos2dx]资源

12.解决CCScale9Sprite或者CCControlButton无法使用的问题。

问题: 使用CCScale9Sprite或者CCControlButton等控件的时候,会出现无法识别的情况. 解决方案: 1.include相应的头部,即#include "cocos-ext.h" 2.使用相应的命名空间,USING_NS_CC_EXT; 3.右击项目---->属性---->VC++目录---->包含目录---->添加extensions文件夹路径. 4.在属性面板展开C/C++的常规---->附加包含目录---->添加$(Sol

1cocos2dx扩展库UI控件,CCControlSlider,CCScale9Sprite(九妹图),CCControlSwitch,CCControlButton

 UI控件来自cocos2dx的扩展库,完善了UI方面的元素,使cocos2dx更加丰富多彩.使用扩展库需包含: #include "cocos-ext.h" USING_NS_CC_EXT; CCControlSlider CCControlSlider * slider = CCControlSlider::create("sliderTrack.png","sliderProgress.png","sliderThumb.pn

CCControlExtension/CCControl

#ifndef __CCCONTROL_H__ #define __CCCONTROL_H__ #include "CCInvocation.h" #include "CCControlUtils.h" #include "cocos2d.h" NS_CC_EXT_BEGIN class CCInvocation; /** ?* @addtogroup GUI ?* @{ ?* @addtogroup control_extension ?* @