#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

CCControlExtension/CCControl的更多相关文章

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

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

  2. GUI之CCControlExtension

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

  3. CCControlExtension/CCControlButton

    #ifndef __CCCONTROL_BUTTON_H__ #define __CCCONTROL_BUTTON_H__ #include "CCControl.h" #incl ...

  4. CCControlExtension/CCControlPotentiometer

    #ifndef __CCCONTROLPOTENTIOMETER_H__ #define __CCCONTROLPOTENTIOMETER_H__ #include "CCControl.h ...

  5. cocos2d-x CCControl控件

    感谢点评与关注.欢迎转载与分享.勤奋努力,持之以恒! CCControlSlider 滑动条 void HelloWorld::myInit10() { CCSize size = CCDirecto ...

  6. 第一次看CCControl

    Control中有九种可能的事件,定义在.h文件中,另外还定义四种状态,用来表示控件高亮等. 在初始化控件的时候: bool Control::init() { if (Layer::init()) ...

  7. CocoStudio UI 编辑器的使用

    详细教程:http://www.cocoachina.com/bbs/read.php?tid=161567 Table of Contents 1 游戏中的 UI 1.1 基于 Cocos2d-x ...

  8. cocos2d-x3.2 使用开关控制按钮 ControlSwitch

    ContolSwitch 控件起到了一个开关的作用类似于现实生活中的开关,直接上代码: .h文件 // // SwitchBtnScene.h // LSWGameIOS // // Created ...

  9. cocos2dx中常见的类及类继承关系

    场景:CCScene,继承自CCNode,几乎完全等于CCNode类 CCNode继承自CCObject,CCObject是真正意义上的父类,CCObject又继承自CCCopying类,CCCopy ...

随机推荐

  1. BTREE索引和HASH索引的区别

    从本质上理解,BTREE是一种有序树,而hash是无序的.所以最关键的区别在于: 1,BTREE可以用来做范围查询,比如大于,小于,而HASH索引仅在"=","IN&qu ...

  2. JavaScript数组的三种定义方法

    数组的定义: <script type="text/javascript"> // <!--声明数组--> // 1.先声明数组长度,后进行赋值 var a ...

  3. 16、IO (Properties、序列化流、打印流、CommonsIO)

    Properties集合的特点 * A: Properties集合的特点 * a: Properties类介绍 * Properties 类表示了一个持久的属性集.Properties 可保存在流中或 ...

  4. sql server web管理软件

    Sql server目前虽然没有mysql用户量大,但是微软的产品在易用性方面还是很不错的,有些政务类的项目还是用 Sql server数据库的, 目前有一款Sql server的web管理工具Tre ...

  5. 使用TreeDMS进行MySQL数据库的Web页面远程管理

    在互联网应用蓬勃发展的时代背景下,各种各样的网络平台,网络应用,移动应用层出不穷,那么这些应用及平台都需要使用到数据库.如何高效的对数据进行日常维护.管理.监控成为迫切需要解决的问题. 基于web的方 ...

  6. MySQL B+树索引和哈希索引的区别(转 JD二面)

    导读 在MySQL里常用的索引数据结构有B+树索引和哈希索引两种,我们来看下这两种索引数据结构的区别及其不同的应用建议. 二者区别 备注:先说下,在MySQL文档里,实际上是把B+树索引写成了BTRE ...

  7. python中字典,没键加键,有键操作其键对应的值,的思想

    cars = ['鲁A32444', '鲁B12333', '京B8989M', '黑C49678', '黑C46555', '沪B25041', '黑C34567'] locations = {'沪 ...

  8. WinAPI: WinExec - 运行外部程序

    原文:http://www.cnblogs.com/del/archive/2008/02/13/1067871.html //声明 WinExec(   lpCmdLine: LPCSTR; {文件 ...

  9. eclipse调试 10个技巧

    先提三点 不要使用System.out.println作为调试工具 启用所有组件的详细的日志记录级别 使用一个日志分析器来阅读日志 1.条件断点 想象一下我们平时如何添加断点,通常的做法是双击行号的左 ...

  10. 中专生自学Android到找到工作的前前后后

    我是一名中专生,在学校里读的是计算机专业,但是由于学校不好大部分同学都不爱学习来这里几乎大部分都是在混日子的,虽然我中考的成绩不差,但是因为家里穷考虑到以后没钱读大学我毅然来到这里,虽然是中专,但是我 ...