本文来自http://blog.csdn.net/runaying ,引用必须注明出处!
cocos2d-X 节点(UIListView.h)API
温馨提醒:为了大家能更好学习,强烈推荐大家看看本人的这篇博客 Cocos2d-X权威指南笔记
这是一个列表视图,它 定义了 view列表方向、 view列表滚动方向、view列表事件类型,提供了一些常用方法
/////cocos2d-x-3.0alpha0/extensions/CocoStudio/GUI/UIWidgets/ScrollWidget //这是一个列表视图,它 定义了 view 列表方向、 view 列表滚动方向、view 列表事件类型 ,提供了一些常用方法 #ifndef __UILISTVIEW_H__ #define __UILISTVIEW_H__ /* gui mark */ #include "../../Layouts/Layout.h" /**/ NS_CC_EXT_BEGIN /** * list view direction //view 列表方向 */ typedef enum LISTVIEW_DIR { LISTVIEW_DIR_NONE, LISTVIEW_DIR_VERTICAL, LISTVIEW_DIR_HORIZONTAL }ListViewDirection; /** * list view scroll direction // view 列表滚动方向 */ typedef enum LISTVIEW_MOVE_DIR { LISTVIEW_MOVE_DIR_NONE, LISTVIEW_MOVE_DIR_UP, LISTVIEW_MOVE_DIR_DOWN, LISTVIEW_MOVE_DIR_LEFT, LISTVIEW_MOVE_DIR_RIGHT, }ListViewMoveDirection; //view 列表事件类型 typedef enum { LISTVIEW_EVENT_INIT_CHILD, LISTVIEW_EVENT_UPDATE_CHILD, }ListViewEventType; /** * list view event view 列表事件 */ typedef void (Object::*SEL_ListViewEvent)(Object*, ListViewEventType); #define listvieweventselector(_SELECTOR)(SEL_ListViewEvent)(&_SELECTOR) class UIListView : public Layout { public: UIListView(); virtual ~UIListView(); static UIListView* create(); /** * add widget child override //添加 Widget child 重写 */ virtual bool addChild(UIWidget* widget); /** * remove all widget children override // 移除所有 widget chld 重写 */ virtual void removeAllChildren(); /** * remove widget child override // 移除 widget chld 重写 */ virtual bool removeChild(UIWidget* child); 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); /** * set and get direction //设置方向 */ void setDirection(ListViewDirection dir); ListViewDirection getDirection(); /** * initialze data length * and create children with parameter length //使用 length 参数创建 children */ void initChildWithDataLength(int length); /** * get data length //获取数据长度 */ int getDataLength(); /** * update child function whetn trigger update child event //触发更新 child 事件后更新 child 函数 */ /** * get update widget child //获取 widget child更新 */ UIWidget* getUpdateChild(); /** * get update data index //设置更新数据索引 */ int getUpdateDataIndex(); /** * get and set update success or not //获取/设置是否更新成功 */ bool getUpdateSuccess(); void setUpdateSuccess(bool sucess); /** * add event call-back function //添加回调函数事件 */ /** * add event */ void addEventListenter(cocos2d::Object* target, SEL_ListViewEvent selector); /* gui mark */ /** * get and set degree range for checking move or not with scrolling //设置范围(度)来检查移动、滑动 */ /**/ virtual void update(float dt); /** * Returns the "class name" of widget. //返回 widget 的名字 */ virtual const char* getDescription() const; protected: virtual bool init(); virtual void onSizeChanged(); void setMoveDirection(ListViewMoveDirection dir); ListViewMoveDirection getMoveDirection(); virtual void resetProperty(); 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 */ //标志 // virtual bool isInScrollDegreeRange(UIWidget* widget); /**/ virtual void checkChildInfo(int handleState,UIWidget* sender,const Point &touchPoint); void moveChildren(float offset); virtual bool scrollChildren(float touchOffset); void autoScrollChildren(float dt); float getCurAutoScrollDistance(float time); void startAutoScrollChildren(float v); void stopAutoScrollChildren(); void recordSlidTime(float dt); void startRecordSlidAction(); virtual void endRecordSlidAction(); UIWidget* getCheckPositionChild(); UIWidget* getChildFromUpdatePool(); void pushChildToPool(); void getAndCallback(); void setUpdateChild(UIWidget* child); void setUpdateDataIndex(int index); void clearCollectOverArray(); void collectOverTopChild(); void collectOverBottomChild(); void collectOverLeftChild(); void collectOverRightChild(); void setLoopPosition(); void updateChild(); void initChildEvent(); void updateChildEvent(); virtual void setClippingEnabled(bool able){Layout::setClippingEnabled(able);}; protected: ListViewDirection _direction; ListViewMoveDirection _moveDirection; float _touchStartLocation; float _touchEndLocation; float _touchMoveStartLocation; float _topBoundary;//test float _bottomBoundary;//test float _leftBoundary; float _rightBoundary; bool _autoScroll; float _autoScrollOriginalSpeed; float _autoScrollAcceleration; bool _bePressed; float _slidTime; Point _moveChildPoint; float _childFocusCancelOffset; Object* _eventListener; SEL_ListViewEvent _eventSelector; Array* _childPool; Array* _updatePool; int _dataLength; int _begin; int _end; UIWidget* _updateChild; int _updateDataIndex; bool _updateSuccess; Array* _overTopArray; Array* _overBottomArray; Array* _overLeftArray; Array* _overRightArray; float _disBoundaryToChild_0; float _disBetweenChild; /* gui mark */ //标志 float _scrollDegreeRange; /**/ }; NS_CC_EXT_END #endif /* defined(__Test__UIListView__) */