本文来自http://blog.csdn.net/runaying ,引用必须注明出处!
cocos2d-X 节点(UIDragPanel.h)API
温馨提醒:为了大家能更好学习,强烈推荐大家看看本人的这篇博客 Cocos2d-X权威指南笔记
这个类和玩家有关,其中定义了 dragpanel事件、拖动面板移动类型、 dragpanel事件类型 、dragpanel反弹方向、dragpanel停泊方向以及事件监听
///cocos2d-x-3.0alpha0/extensions/CocoStudio/GUI/UIWidgets/ScrollWidget
// 这个类和玩家有关,其中定义了 dragpanel事件、拖动面板移动类型、 dragpanel 事件类型 、dragpanel反弹方向 、dragpanel停泊方向 以及事件监听
#ifndef __UIDRAGPANEL_H__
#define __UIDRAGPANEL_H__
#include "../../Layouts/Layout.h"
#include "UIScrollInterface.h"
NS_CC_EXT_BEGIN
/**
* drag panel move type //拖动面板移动类型
*/
enum DRAGPANEL_MOVE_TYPE
{
DRAGPANEL_MOVE_TYPE_NONE,
DRAGPANEL_MOVE_TYPE_AUTOMOVE,
DRAGPANEL_MOVE_TYPE_BOUNCE,
};
/**
* dragpanel berth direction //dragpanel停泊方向
*/
enum DRAGPANEL_BERTH_DIR
{
DRAGPANEL_BERTH_DIR_NONE,
DRAGPANEL_BERTH_DIR_LEFTBOTTOM,
DRAGPANEL_BERTH_DIR_LFETTOP,
DRAGPANEL_BERTH_DIR_RIGHTBOTTOM,
DRAGPANEL_BERTH_DIR_RIGHTTOP,
DRAGPANEL_BERTH_DIR_LEFT,
DRAGPANEL_BERTH_DIR_TOP,
DRAGPANEL_BERTH_DIR_RIGHT,
DRAGPANEL_BERTH_DIR_BOTTOM,
};
/**
* dragpanel bounce direction //dragpanel反弹方向
*/
enum DRAGPANEL_BOUNCE_DIR
{
DRAGPANEL_BOUNCE_DIR_NONE,
DRAGPANEL_BOUNCE_DIR_LEFTBOTTOM,
DRAGPANEL_BOUNCE_DIR_LEFTTOP,
DRAGPANEL_BOUNCE_DIR_RIGHTBOTTOM,
DRAGPANEL_BOUNCE_DIR_RIGHTTOP,
DRAGPANEL_BOUNCE_DIR_LEFT,
DRAGPANEL_BOUNCE_DIR_TOP,
DRAGPANEL_BOUNCE_DIR_RIGHT,
DRAGPANEL_BOUNCE_DIR_BOTTOM,
};
//dragpanel 事件类型
typedef enum
{
DRAGPANEL_EVENT_BERTH_LEFTBOTTOM,
DRAGPANEL_EVENT_BERTH_LFETTOP,
DRAGPANEL_EVENT_BERTH_RIGHTBOTTOM,
DRAGPANEL_EVENT_BERTH_RIGHTTOP,
DRAGPANEL_EVENT_BERTH_LEFT,
DRAGPANEL_EVENT_BERTH_TOP,
DRAGPANEL_EVENT_BERTH_RIGHT,
DRAGPANEL_EVENT_BERTH_BOTTOM,
DRAGPANEL_EVENT_BOUNCE_LEFTBOTTOM,
DRAGPANEL_EVENT_BOUNCE_LEFTTOP,
DRAGPANEL_EVENT_BOUNCE_RIGHTBOTTOM,
DRAGPANEL_EVENT_BOUNCE_RIGHTTOP,
DRAGPANEL_EVENT_BOUNCE_LEFT,
DRAGPANEL_EVENT_BOUNCE_TOP,
DRAGPANEL_EVENT_BOUNCE_RIGHT,
DRAGPANEL_EVENT_BOUNCE_BOTTOM,
}DragPanelEventType;
/**
* dragpanel event dragpanel事件
*/
typedef void (Object::*SEL_DragPanelEvent)(Object*, DragPanelEventType);
#define dragpaneleventselector(_SELECTOR)(SEL_DragPanelEvent)(&_SELECTOR)
class UIDragPanel : public Layout, public UIScrollInterface
{
public:
UIDragPanel();
virtual ~UIDragPanel();
static UIDragPanel* create();
virtual bool onTouchBegan(const Point &touchPoint);
virtual void onTouchMoved(const Point &touchPoint);
virtual void onTouchEnded(const Point &touchPoint);
virtual void onTouchCancelled(const Point &touchPoint);
virtual void onTouchLongClicked(const Point &touchPoint);
virtual void update(float dt);
/**
* add widget child override //添加 Widget child 重写
*/
virtual bool addChild(UIWidget* widget);
/**
* remove widget child override // 移除 widget chld 重写
*/
virtual bool removeChild(UIWidget* child);
/**
* remove all widget children override //移除所有的 widget chld 重写
*/
virtual void removeAllChildren();
/**
* get widget children of inner container //内部容器获取 widget children
*/
virtual Array* getChildren();
/* gui mark */ //gui 标记
/**
* get and set inner container size //获取/设置 内部容器尺寸
*/
const Size& getInnerContainerSize() const;
void setInnerContainerSize(const Size &size);
/**
* get and set inner container position 获取/设置 内部容器位置
*/
const Point& getInnerContainerPosition() const;
void setInnerContainerPosition(const Point& point, bool animated);
/**
* set inner container offset //设置内部容器偏移
*/
void setInnerContainerOffset(const Point& offset, bool animated);
/**/
// auto move //自动移动
/**
* set auto move duration //设置自动移动的持续时间
*/
void setAutoMoveDuration(float duration);
/**
* set auto move ease rate //设置自动移动的速率
*/
void setAutoMoveEaseRate(float rate);
// berth //停泊
/**
* get berth or not //获取是否停泊
*/
bool isBerth();
/**
* event //添加事件监听
*/
void addEventListener(Object* target, SEL_DragPanelEvent selector);
/**
* get and set bounce enable //获取是否启用了反弹
*/
bool isBounceEnable();
void setBounceEnable(bool bounce);
/**
* set bounce duration //获取反弹持续时间
*/
void setBounceDuratoin(float duration);
/**
* set bounce ease rate //设置反弹速率
*/
void setBounceEaseRate(float rate);
/**
* Gets inner container of dragpanel. //获取dragpanel的内部容器。
*
* Inner container is the container of dragpanel's children. //内部容器是 dragpanel's children 的容器
*
* @return inner container.
*/
Layout* getInnerContainer();
/**
* Returns the "class name" of widget. //返回 widget 的名字
*/
virtual const char* getDescription() const;
protected:
virtual bool init();
virtual void initRenderer();
virtual void releaseResoures();
virtual void handlePressLogic(const Point &touchPoint);
virtual void handleMoveLogic(const Point &touchPoint);
virtual void handleReleaseLogic(const Point &touchPoint);
virtual void interceptTouchEvent(int handleState,UIWidget* sender, const Point &touchPoint);
/* gui mark */ // gui 标志
// virtual bool isInScrollDegreeRange(UIWidget* widget);
/**/
virtual void checkChildInfo(int handleState, UIWidget *sender, const Point &touchPoint);
// void updateWidthAndHeight();
void recordSlidTime(float dt);
/* gui mark */
void setInnerContainerOffset(const Point& offset);
/**/
// check if dragpanel rect contain inner rect //检查 dragpanel rect 是否包含 内部 rect
bool checkContainInnerRect();
// move
void moveWithDelta(const Point& delta);
// auto move
void autoMove();
void autoMoveOver();
void startAutoMove();
void stopAutoMove();
// berth
// check if move to boundary with update //检查是否移动到了边界位置
bool checkToBoundaryWithDeltaPosition(const Point& delta);
// calculate to boundary delta // 计算出边界增量
Point calculateToBoundaryDeltaPosition(const Point& paramDelta);
// check berth //检查停泊
bool checkBerth();
// berth event // 停泊事件
void berthEvent();
void berthToLeftEvent();
void berthToRightEvent();
void berthToTopEvent();
void berthToBottomEvent();
void berthToLeftBottomEvent();
void berthToLeftTopEvent();
void berthToRightBottomEvent();
void berthToRightTopEvent();
// bounce //反弹
bool checkNeedBounce();
void startBounce();
void stopBounce();
void bounceToCorner();
void bounceOver();
// bounce event //反弹事件
void bounceToLeftBottomEvent();
void bounceToRightBottomEvent();
void bounceToLeftTopEvent();
void bounceToRightTopEvent();
void bounceToLeftEvent();
void bounceToTopEvent();
void bounceToRightEvent();
void bounceToBottomEvent();
void actionWithDuration(float duration);
bool actionIsDone();
void actionStartWithWidget(UIWidget* widget);
void actionStep(float dt);
void actionUpdate(float dt);
void actionStop();
void actionDone();
void moveByWithDuration(float duration, const Point& deltaPosition);
void moveByInit();
void moveByUpdate(float t);
void moveToWithDuration(float duration, const Point& position);
void moveToInit();
void moveToUpdate(float t);
virtual void onSizeChanged();
/*compatible*/ //兼容
/**
* These methods will be removed //这些方法将被删除
*/
virtual void setClippingEnable(bool is){setClippingEnabled(is);};
/************/
virtual void setClippingEnabled(bool able){Layout::setClippingEnabled(able);};
protected:
Layout* _innerContainer;
/*
DRAGPANEL_DIR m_eDirection;
DRAGPANEL_MOVE_DIR m_eMoveDirection;
*/
bool _touchPressed;
bool _touchMoved;
bool _touchReleased;
bool _touchCanceld; // check touch out of drag panel boundary //检查触摸有没有超出拖动面板的边界
Point _touchStartNodeSpace;
Point _touchStartWorldSpace;
Point _touchEndWorldSpace;
float _slidTime;
// move type //移动类型
DRAGPANEL_MOVE_TYPE _moveType;
// auto move 自动移动
float _autoMoveDuration;
float _autoMoveEaseRate;
// event //事件监听
Object* _eventLister;
SEL_DragPanelEvent _eventSelector;
// berth //停泊
DRAGPANEL_BERTH_DIR _berthDirection;
// bounce 反弹
bool _bounceEnable;
DRAGPANEL_BOUNCE_DIR _bounceDirection;
float _bounceDuration;
float _bounceEaseRate;
float _runningAction;
int _actionType;
UIWidget* _actionWidget;
float _duration;
float _elapsed;
bool _firstTick;
Point _positionDelta;
Point _startPosition;
Point _previousPosition;
Point _endPosition;
};
NS_CC_EXT_END
#endif /* defined(__TestCpp__UIDragPanel__) */