#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

 * @{

 */

/** Number of kinds of control event. */

#define kControlEventTotalNumber 9

/** Kinds of possible events for the control objects. */

enum 

{

    CCControlEventTouchDown           = 1 << 0,    // A touch-down event in the control.

    CCControlEventTouchDragInside     = 1 << 1,    // An event where a finger is dragged inside the bounds of the control.

    CCControlEventTouchDragOutside    = 1 << 2,    // An event where a finger is dragged just outside the bounds of the control. 

    CCControlEventTouchDragEnter      = 1 << 3,    // An event where a finger is dragged into the bounds of the control.

    CCControlEventTouchDragExit       = 1 << 4,    // An event where a finger is dragged from within a control to outside its bounds.

    CCControlEventTouchUpInside       = 1 << 5,    // A touch-up event in the control where the finger is inside the bounds of the control. 

    CCControlEventTouchUpOutside      = 1 << 6,    // A touch-up event in the control where the finger is outside the bounds of the control.

    CCControlEventTouchCancel         = 1 << 7,    // A system event canceling the current touches for the control.

    CCControlEventValueChanged        = 1 << 8      // A touch dragging or otherwise manipulating a control, causing it to emit a series of different
values.

};

typedef unsigned int CCControlEvent;

/** The possible state for a control.  */

enum 

{

    CCControlStateNormal       = 1 << 0, // The normal, or default state of a control°™that is, enabled but neither selected nor highlighted.

    CCControlStateHighlighted  = 1 << 1, // Highlighted state of a control. A control enters this state when a touch down, drag inside or drag enter
is performed. You can retrieve and set this value through the highlighted property.

    CCControlStateDisabled     = 1 << 2, // Disabled state of a control. This state indicates that the control is currently disabled. You can retrieve
and set this value through the enabled property.

    CCControlStateSelected     = 1 << 3  // Selected state of a control. This state indicates that the control is currently selected. You can retrieve
and set this value through the selected property.

};

typedef unsigned int CCControlState;

/*

 * @class

 * CCControl is inspired by the UIControl API class from the UIKit library of 

 * CocoaTouch. It provides a base class for control CCSprites such as CCButton 

 * or CCSlider that convey user intent to the application.

 *

 * The goal of CCControl is to define an interface and base implementation for 

 * preparing action messages and initially dispatching them to their targets when

 * certain events occur.

 *

 * To use the CCControl you have to subclass it.

 */

class CCControl : public CCLayerRGBA

{

    //CCRGBAProtocol

    bool m_bIsOpacityModifyRGB;

    

    /** The current control state constant. */

    CC_SYNTHESIZE_READONLY(CCControlState, m_eState, State);

    /** True if all of the controls parents are visible */

protected:

    bool m_hasVisibleParents;

public:

    /** Tells whether the control is enabled. */

    virtual void setEnabled(bool bEnabled);

    virtual bool isEnabled();

    /** A Boolean value that determines the control selected state. */

    virtual void setSelected(bool bSelected);

    virtual bool isSelected();

    /** A Boolean value that determines whether the control is highlighted. */

    virtual void setHighlighted(bool bHighlighted);

    virtual bool isHighlighted();

    bool hasVisibleParents();

    /**

     * Updates the control layout using its current internal state.

     */

    virtual void needsLayout();

    

    virtual bool isOpacityModifyRGB();

    virtual void setOpacityModifyRGB(bool bOpacityModifyRGB);

protected:

    bool m_bEnabled;

    bool m_bSelected;

    bool m_bHighlighted;

    /** 

     * Table of connection between the CCControlEvents and their associated

     * target-actions pairs. For each CCButtonEvents a list of NSInvocation

     * (which contains the target-action pair) is linked.

     */

    CCDictionary* m_pDispatchTable;

public:

    CCControl();

    virtual bool init(void);

    virtual ~CCControl();

    virtual void onEnter();

    virtual void onExit();

    virtual void registerWithTouchDispatcher();

    /**

 * Sends action messages for the given control events.

 *

 * @param controlEvents A bitmask whose set flags specify the control events for

 * which action messages are sent. See "CCControlEvent" for bitmask constants.

 */

    virtual void sendActionsForControlEvents(CCControlEvent controlEvents);

    /**

    * Adds a target and action for a particular event (or events) to an internal

    * dispatch table.

    * The action message may optionnaly include the sender and the event as 

    * parameters, in that order.

    * When you call this method, target is not retained.

    *

    * @param target The target object that is, the object to which the action 

    * message is sent. It cannot be nil. The target is not retained.

    * @param action A selector identifying an action message. It cannot be NULL.

    * @param controlEvents A bitmask specifying the control events for which the 

    * action message is sent. See "CCControlEvent" for bitmask constants.

    */

    virtual void addTargetWithActionForControlEvents(CCObject* target, SEL_CCControlHandler action, CCControlEvent controlEvents);

    /**

    * Removes a target and action for a particular event (or events) from an 

    * internal dispatch table.

    *

    * @param target The target objectóthat is, the object to which the action 

    * message is sent. Pass nil to remove all targets paired with action and the

    * specified control events.

    * @param action A selector identifying an action message. Pass NULL to remove

    * all action messages paired with target.

    * @param controlEvents A bitmask specifying the control events associated with

    * target and action. See "CCControlEvent" for bitmask constants.

    */

    virtual void removeTargetWithActionForControlEvents(CCObject* target, SEL_CCControlHandler action, CCControlEvent controlEvents);

    /**

    * Returns a point corresponding to the touh location converted into the 

    * control space coordinates.

    * @param touch A CCTouch object that represents a touch.

    */

    virtual CCPoint getTouchLocation(CCTouch* touch);

    

    /**

    * Returns a boolean value that indicates whether a touch is inside the bounds

    * of the receiver. The given touch must be relative to the world.

    *

    * @param touch A CCTouch object that represents a touch.

    *

    * @return YES whether a touch is inside the receiver°Øs rect.

    */

    virtual bool isTouchInside(CCTouch * touch);

protected:

    /**

     * Returns an CCInvocation object able to construct messages using a given 

     * target-action pair. (The invocation may optionnaly include the sender and

     * the event as parameters, in that order)

     *

     * @param target The target object.

     * @param action A selector identifying an action message.

     * @param controlEvent A control events for which the action message is sent.

     * See "CCControlEvent" for constants.

     *

     * @return an CCInvocation object able to construct messages using a given 

     * target-action pair.

     */

    CCInvocation* invocationWithTargetAndActionForControlEvent(CCObject* target, SEL_CCControlHandler action, CCControlEvent controlEvent);

    /**

    * Returns the CCInvocation list for the given control event. If the list does

    * not exist, it'll create an empty array before returning it.

    *

    * @param controlEvent A control events for which the action message is sent.

    * See "CCControlEvent" for constants.

    *

    * @return the CCInvocation list for the given control event.

    */

    //<CCInvocation*>

    CCArray* dispatchListforControlEvent(CCControlEvent controlEvent);

    /**

     * Adds a target and action for a particular event to an internal dispatch 

     * table.

     * The action message may optionnaly include the sender and the event as 

     * parameters, in that order.

     * When you call this method, target is not retained.

     *

     * @param target The target object°™that is, the object to which the action 

     * message is sent. It cannot be nil. The target is not retained.

     * @param action A selector identifying an action message. It cannot be NULL.

     * @param controlEvent A control event for which the action message is sent.

     * See "CCControlEvent" for constants.

     */

    void addTargetWithActionForControlEvent(CCObject* target, SEL_CCControlHandler action, CCControlEvent controlEvent);

    

    /**

     * Removes a target and action for a particular event from an internal dispatch

     * table.

     *

     * @param target The target object°™that is, the object to which the action 

     * message is sent. Pass nil to remove all targets paired with action and the

     * specified control events.

     * @param action A selector identifying an action message. Pass NULL to remove

     * all action messages paired with target.

     * @param controlEvent A control event for which the action message is sent.

     * See "CCControlEvent" for constants.

     */

    void removeTargetWithActionForControlEvent(CCObject* target, SEL_CCControlHandler action, CCControlEvent controlEvent);

    static CCControl* create();

public:

    void addHandleOfControlEvent(int nFunID,CCControlEvent controlEvent);

    void removeHandleOfControlEvent(CCControlEvent controlEvent);

private:

    int  getHandleOfControlEvent(CCControlEvent controlEvent);

private:

    std::map<int,int> m_mapHandleOfControlEvent;

};

// end of GUI group

/// @}

/// @}

NS_CC_EXT_END

#endif

最新文章

  1. EF DbContext 并发执行时可能出现的问题
  2. python 实现文件下载
  3. mybatis 3.x 缓存Cache的使用
  4. Oracle数据库DOC命令导入导出(2014-3-10记)
  5. Socket 入门
  6. 客户端js判断文件类型和文件大小即限制上传大小
  7. UVA-Matrix Chain Multiplication(栈)
  8. Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value: &amp;#39;L
  9. python使用smtplib库和smtp.qq.com邮件服务器发送邮件(转)
  10. 谈一谈Java8的函数式编程(二) --Java8中的流
  11. .Net mvc 上传多文件
  12. Navicat Premium 12 破解(MySQL、MariaDB、MongoDB、SQL Server、SQLite)
  13. kvm企业级虚拟化环境部署
  14. 2018.10.14 loj#6011. 「网络流 24 题」运输问题(费用流)
  15. [洛谷P2783]有机化学之神偶尔会做作弊
  16. IEC62304开发过程框架
  17. python学习笔记(八)python操作Excel
  18. UVA+POJ中大数实现的题目,持续更新(JAVA实现)
  19. neo4j使用笔记
  20. 关于k Line Chart (k线图)

热门文章

  1. js弹出遮层
  2. Vs2015+opencv2.4.10出现msvcp120d.dll丢失 opencv2410.props
  3. System.Web.HttpException: 请求在此上下文中不可用
  4. Hadoop源码学习笔记(4) ——Socket到RPC调用
  5. 一、spark单机安装
  6. Ubuntu 16.04安装Oracle 11gR2入门教程图文详解
  7. MySQL数据导出为Excel, json,sql等格式
  8. SQL导出到Excel 存储过程
  9. [SD2015]序列统计——solution
  10. 简易搭建git仓库、关联远程和本地仓库方法。克隆仓库方法。同一台电脑上创建两个git ssh key方法。