2013-09-13 22:20:20 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013 cocos2d-x.org
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __UILISTVIEW_H__
|
|
|
|
#define __UILISTVIEW_H__
|
|
|
|
|
|
|
|
/* gui mark */
|
2013-10-16 16:48:39 +08:00
|
|
|
#include "gui/Layout.h"
|
2013-09-13 22:20:20 +08:00
|
|
|
/**/
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
namespace gui {
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* list view direction
|
|
|
|
*/
|
|
|
|
typedef enum LISTVIEW_DIR
|
|
|
|
{
|
|
|
|
LISTVIEW_DIR_NONE,
|
|
|
|
LISTVIEW_DIR_VERTICAL,
|
|
|
|
LISTVIEW_DIR_HORIZONTAL
|
|
|
|
}ListViewDirection;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* list view scroll direction
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
|
2013-09-17 20:13:23 +08:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
LISTVIEW_EVENT_INIT_CHILD,
|
|
|
|
LISTVIEW_EVENT_UPDATE_CHILD,
|
|
|
|
}ListViewEventType;
|
|
|
|
|
2013-09-13 22:20:20 +08:00
|
|
|
/**
|
|
|
|
* list view event
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
typedef void (cocos2d::Object::*SEL_ListViewEvent)(cocos2d::Object*, ListViewEventType);
|
2013-09-17 20:13:23 +08:00
|
|
|
#define listvieweventselector(_SELECTOR)(SEL_ListViewEvent)(&_SELECTOR)
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
class UIListView : public Layout
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
UIListView();
|
|
|
|
virtual ~UIListView();
|
|
|
|
static UIListView* create();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* add widget child override
|
|
|
|
*/
|
|
|
|
virtual bool addChild(UIWidget* widget);
|
|
|
|
/**
|
|
|
|
* remove all widget children override
|
|
|
|
*/
|
|
|
|
virtual void removeAllChildren();
|
|
|
|
/**
|
|
|
|
* remove widget child override
|
|
|
|
*/
|
|
|
|
virtual bool removeChild(UIWidget* child);
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
virtual bool onTouchBegan(const cocos2d::Point &touchPoint);
|
|
|
|
virtual void onTouchMoved(const cocos2d::Point &touchPoint);
|
|
|
|
virtual void onTouchEnded(const cocos2d::Point &touchPoint);
|
|
|
|
virtual void onTouchCancelled(const cocos2d::Point &touchPoint);
|
|
|
|
virtual void onTouchLongClicked(const cocos2d::Point &touchPoint);
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* set and get direction
|
|
|
|
*/
|
|
|
|
void setDirection(ListViewDirection dir);
|
|
|
|
ListViewDirection getDirection();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* initialze data length
|
|
|
|
* and create children with parameter length
|
|
|
|
*/
|
|
|
|
void initChildWithDataLength(int length);
|
|
|
|
/**
|
|
|
|
* get data length
|
|
|
|
*/
|
|
|
|
int getDataLength();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* update child function whetn trigger update child event
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* get update 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
|
|
|
|
*/
|
|
|
|
/**
|
2013-09-17 20:13:23 +08:00
|
|
|
* add event
|
2013-09-13 22:20:20 +08:00
|
|
|
*/
|
2013-09-17 20:13:23 +08:00
|
|
|
void addEventListenter(cocos2d::Object* target, SEL_ListViewEvent selector);
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/* gui mark */
|
|
|
|
/**
|
|
|
|
* get and set degree range for checking move or not with scrolling
|
|
|
|
*/
|
|
|
|
/**/
|
|
|
|
virtual void update(float dt);
|
|
|
|
|
2013-09-23 19:16:20 +08:00
|
|
|
virtual void doLayout(){};
|
|
|
|
|
2013-09-17 17:59:20 +08:00
|
|
|
/**
|
|
|
|
* Returns the "class name" of widget.
|
|
|
|
*/
|
|
|
|
virtual const char* getDescription() const;
|
2013-09-13 22:20:20 +08:00
|
|
|
protected:
|
|
|
|
virtual bool init();
|
|
|
|
|
|
|
|
virtual void onSizeChanged();
|
|
|
|
|
|
|
|
void setMoveDirection(ListViewMoveDirection dir);
|
|
|
|
ListViewMoveDirection getMoveDirection();
|
|
|
|
|
|
|
|
virtual void resetProperty();
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
virtual void handlePressLogic(const cocos2d::Point &touchPoint);
|
|
|
|
virtual void handleMoveLogic(const cocos2d::Point &touchPoint);
|
|
|
|
virtual void handleReleaseLogic(const cocos2d::Point &touchPoint);
|
|
|
|
virtual void interceptTouchEvent(int handleState,UIWidget* sender,const cocos2d::Point &touchPoint);
|
2013-09-13 22:20:20 +08:00
|
|
|
/* gui mark */
|
|
|
|
// virtual bool isInScrollDegreeRange(UIWidget* widget);
|
|
|
|
/**/
|
2013-10-15 18:00:03 +08:00
|
|
|
virtual void checkChildInfo(int handleState,UIWidget* sender,const cocos2d::Point &touchPoint);
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
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:
|
2013-09-16 20:54:13 +08:00
|
|
|
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;
|
2013-10-15 18:00:03 +08:00
|
|
|
cocos2d::Point _moveChildPoint;
|
2013-09-16 20:54:13 +08:00
|
|
|
float _childFocusCancelOffset;
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
cocos2d::Object* _eventListener;
|
2013-09-17 20:13:23 +08:00
|
|
|
SEL_ListViewEvent _eventSelector;
|
2013-09-16 20:54:13 +08:00
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
cocos2d::Array* _childPool;
|
|
|
|
cocos2d::Array* _updatePool;
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
int _dataLength;
|
|
|
|
int _begin;
|
|
|
|
int _end;
|
|
|
|
UIWidget* _updateChild;
|
|
|
|
int _updateDataIndex;
|
|
|
|
bool _updateSuccess;
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
cocos2d::Array* _overTopArray;
|
|
|
|
cocos2d::Array* _overBottomArray;
|
|
|
|
cocos2d::Array* _overLeftArray;
|
|
|
|
cocos2d::Array* _overRightArray;
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
float _disBoundaryToChild_0;
|
|
|
|
float _disBetweenChild;
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/* gui mark */
|
2013-09-16 20:54:13 +08:00
|
|
|
float _scrollDegreeRange;
|
2013-09-13 22:20:20 +08:00
|
|
|
/**/
|
|
|
|
};
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
}
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
#endif /* defined(__Test__UIListView__) */
|