#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

CCControlExtension/CCControlButton的更多相关文章

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

    学习cocos2d-x和cocos creator的圈子:cocos2d-x:436689827    cocos creator:124727696 本篇文章主要内容:jsoncpp的使用,Coco ...

  2. Cocos2d-x-html5之HelloWorld深入分析与调试

    Cocos2d-x-html5之HelloWorld深入分析与调试 另:本章所用Cocos2d-x版本为: Cocos2d-html5-v2.1.1 http://cn.cocos2d-x.org/d ...

  3. GUI之CCControlExtension

    Introduction CCControl is inspired by the UIControl API class from the UIKit library of CocoaTouch. ...

  4. cocos2dx CCControlButton button大事

    =================================.cpp文件 <pre name="code" class="cpp">bool ...

  5. 1cocos2dx扩展UI控制,CCControlSlider,CCScale9Sprite(九妹图。),CCControlSwitch,CCControlButton

     UI控件来自cocos2dx的扩展库.完好了UI方面的元素,使cocos2dx更加丰富多彩.使用扩展库需包括: #include "cocos-ext.h" USING_NS ...

  6. 【转】CCScale9Sprite和CCControlButton

    转自:http://blog.csdn.net/nat_myron/article/details/12975145 在2dx下用到了android下的.9.png图片,下面是原图   查了一下2dx ...

  7. CCControlSwitch 、CCControlSlider、CCControlButton

    /* *bool hasMoved(); 这里获取的不是开关是否正在被用户拨动,而是开关最终的状态是由用户手动拨动开关进行的, *还是用户点击开关进行的状态更改 */ CCControlSwitch* ...

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

    问题: 使用CCScale9Sprite或者CCControlButton等控件的时候,会出现无法识别的情况. 解决方式: 1.include对应的头部,即#include "cocos-e ...

  9. cocos2dx基础篇(10) 按钮控件CCControlButton

    [3.x] (1)去掉 “CC” (2)对象类 CCObject 改为 Ref (3)按钮事件回调依旧为 cccontrol_selector ,没有使用 CC_CALLBACK_2 (4)按钮状态  ...

随机推荐

  1. Ubuntu 16.04 apt-get搭建LAMP环境

    本文重点介绍在Ubuntu中使用apt-get安装LAMP(Ubuntu 16.04,Apache2.4.18,mysql5.7.12,php7.0.4)环境,所以不再介绍如何安装Ubuntu. 安装 ...

  2. Team Service 编译项目并生成项目

    第一步:生成GitHub帐号连接 在Service中选择Github 在弹出的GitHub连接中点击授权,即会弹出另一个窗口,输入Github的用户名及口令,即可授权. 第二步:创建Build定义 解 ...

  3. <<持续交付>>终点的精彩

    1,向敏捷转变的过程是一个很容易出乱子的过程, 尤其对项目的领导力来说.在实施敏捷的过程中,会突然释放出一些有用的信息,将原来隐蔽起来的真相推倒聚光灯下. 2,假如执行者忽略了技术实践(比如测试驱动开 ...

  4. thinkphp之自动完成

    1.自动完成 自动完成是ThinkPHP提供用来完成数据自动处理和过滤的方法,使用create方法创建数据对象的时候会自动完成数据处理.  因此,在ThinkPHP使用create方法来创建数据对象是 ...

  5. 141. Linked List Cycle【Easy】【判断链表是否存在环】

    Given a linked list, determine if it has a cycle in it. To represent a cycle in the given linked lis ...

  6. webstorm中.vue报错

    1.webstorm中es6语法报错,解决方法: 打开 Settings => Languages & Frameworks => Javascript把 Javascript L ...

  7. 图灵杯 E 简单的RMQ(UVA 11235)(RMQ)

    E: 简单的RMQ 时间限制: 2 Sec  内存限制: 64 MB提交: 934  解决: 165[提交][状态][讨论版] 题目描述 给定一个数组,其中的元素满足非递减顺序.任意给定一个区间[i, ...

  8. mysql无法输入中文排错

    题记:以前都是使用可视化界面创建数据库,进行操作的,但是今天使用cmd窗口进行操作发现出错了. 以前记得自己使用cmd也是可以正确操作的,但是这次却出错了,在网上找了很多解决的办法,最后还是靠自己慢慢 ...

  9. [Nescafé41]异化多肽(多项式求逆元)

    2015年的题,应该是将形式幂级数引入国内的元老级题目. 大意:给定一个大小为m的正整数序列和n,问有多少种选法可以凑成n,每个数可以选多次,种类不同算不同方案.$n,m,C \leqslant 10 ...

  10. 洛谷 P3943 星空

    题目背景 命运偷走如果只留下结果, 时间偷走初衷只留下了苦衷. 你来过,然后你走后,只留下星空. 题目描述 逃不掉的那一天还是来了,小 F 看着夜空发呆. 天上空荡荡的,没有一颗星星——大概是因为天上 ...