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 __UISCROLLVIEW_H__
|
|
|
|
#define __UISCROLLVIEW_H__
|
|
|
|
|
2013-10-16 16:48:39 +08:00
|
|
|
#include "gui//Layout.h"
|
|
|
|
#include "gui/UIScrollInterface.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
|
|
|
|
|
|
|
enum SCROLLVIEW_DIR
|
|
|
|
{
|
|
|
|
SCROLLVIEW_DIR_NONE,
|
|
|
|
SCROLLVIEW_DIR_VERTICAL,
|
|
|
|
SCROLLVIEW_DIR_HORIZONTAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum SCROLLVIEW_MOVE_DIR
|
|
|
|
{
|
|
|
|
SCROLLVIEW_MOVE_DIR_NONE,
|
|
|
|
SCROLLVIEW_MOVE_DIR_UP,
|
|
|
|
SCROLLVIEW_MOVE_DIR_DOWN,
|
|
|
|
SCROLLVIEW_MOVE_DIR_LEFT,
|
|
|
|
SCROLLVIEW_MOVE_DIR_RIGHT,
|
|
|
|
};
|
|
|
|
|
2013-09-17 20:34:26 +08:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
SCROLLVIEW_EVENT_SCROLL_TO_TOP,
|
|
|
|
SCROLLVIEW_EVENT_SCROLL_TO_BOTTOM,
|
|
|
|
SCROLLVIEW_EVENT_SCROLL_TO_LEFT,
|
|
|
|
SCROLLVIEW_EVENT_SCROLL_TO_RIGHT,
|
|
|
|
}ScrollviewEventType;
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
typedef void (cocos2d::Object::*SEL_ScrollViewEvent)(cocos2d::Object*, ScrollviewEventType);
|
2013-09-17 20:34:26 +08:00
|
|
|
#define scrollvieweventselector(_SELECTOR) (SEL_ScrollViewEvent)(&_SELECTOR)
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
class UIScrollView : public Layout , public UIScrollInterface
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Default constructor
|
|
|
|
*/
|
|
|
|
UIScrollView();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Default destructor
|
|
|
|
*/
|
|
|
|
virtual ~UIScrollView();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocates and initializes.
|
|
|
|
*/
|
|
|
|
static UIScrollView* create();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes scroll direction of scrollview.
|
|
|
|
*
|
|
|
|
* @see SCROLLVIEW_DIR SCROLLVIEW_DIR_VERTICAL means vertical scroll, SCROLLVIEW_DIR_HORIZONTAL means horizontal scroll
|
|
|
|
*
|
|
|
|
* @param SCROLLVIEW_DIR
|
|
|
|
*/
|
|
|
|
void setDirection(SCROLLVIEW_DIR dir);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets scroll direction of scrollview.
|
|
|
|
*
|
|
|
|
* @see SCROLLVIEW_DIR SCROLLVIEW_DIR_VERTICAL means vertical scroll, SCROLLVIEW_DIR_HORIZONTAL means horizontal scroll
|
|
|
|
*
|
|
|
|
* @return SCROLLVIEW_DIR
|
|
|
|
*/
|
|
|
|
SCROLLVIEW_DIR getDirection();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets inner container of scrollview.
|
|
|
|
*
|
|
|
|
* Inner container is the container of scrollview's children.
|
|
|
|
*
|
|
|
|
* @return inner container.
|
|
|
|
*/
|
|
|
|
Layout* getInnerContainer();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scroll inner container to bottom boundary of scrollview.
|
|
|
|
*/
|
|
|
|
void scrollToBottom();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scroll inner container to top boundary of scrollview.
|
|
|
|
*/
|
|
|
|
void scrollToTop();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes inner container size of scrollview.
|
|
|
|
*
|
|
|
|
* Inner container size must be larger than or equal scrollview's size.
|
|
|
|
*
|
|
|
|
* @param inner container size.
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
void setInnerContainerSize(const cocos2d::Size &size);
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets inner container size of scrollview.
|
|
|
|
*
|
|
|
|
* Inner container size must be larger than or equal scrollview's size.
|
|
|
|
*
|
|
|
|
* @return inner container size.
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
const cocos2d::Size& getInnerContainerSize() const;
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/**
|
2013-09-17 20:34:26 +08:00
|
|
|
* Add call back function called scrollview event triggered
|
2013-09-13 22:20:20 +08:00
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
void addEventListener(cocos2d::Object* target, SEL_ScrollViewEvent selector);
|
2013-09-23 19:16:20 +08:00
|
|
|
|
2013-09-13 22:20:20 +08:00
|
|
|
//override "addChild" method of widget.
|
|
|
|
virtual bool addChild(UIWidget* widget);
|
|
|
|
|
|
|
|
//override "removeAllChildrenAndCleanUp" method of widget.
|
|
|
|
virtual void removeAllChildren();
|
|
|
|
|
|
|
|
//override "removeChild" method of widget.
|
|
|
|
virtual bool removeChild(UIWidget* child);
|
|
|
|
|
|
|
|
//override "getChildren" method of widget.
|
2013-10-15 18:00:03 +08:00
|
|
|
virtual cocos2d::Array* getChildren();
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
//override "onTouchBegan" method of widget.
|
2013-10-15 18:00:03 +08:00
|
|
|
virtual bool onTouchBegan(const cocos2d::Point &touchPoint);
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
//override "onTouchMoved" method of widget.
|
2013-10-15 18:00:03 +08:00
|
|
|
virtual void onTouchMoved(const cocos2d::Point &touchPoint);
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
//override "onTouchEnded" method of widget.
|
2013-10-15 18:00:03 +08:00
|
|
|
virtual void onTouchEnded(const cocos2d::Point &touchPoint);
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
//override "onTouchCancelled" method of widget.
|
2013-10-15 18:00:03 +08:00
|
|
|
virtual void onTouchCancelled(const cocos2d::Point &touchPoint);
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
//override "onTouchLongClicked" method of widget.
|
2013-10-15 18:00:03 +08:00
|
|
|
virtual void onTouchLongClicked(const cocos2d::Point &touchPoint);
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
virtual void update(float dt);
|
2013-09-17 17:59:20 +08:00
|
|
|
|
2013-09-23 19:16:20 +08:00
|
|
|
/**
|
|
|
|
* Sets LayoutType.
|
|
|
|
*
|
|
|
|
* @see LayoutType
|
|
|
|
*
|
|
|
|
* @param LayoutType
|
|
|
|
*/
|
2013-09-23 21:26:44 +08:00
|
|
|
virtual void setLayoutType(LayoutType type);
|
2013-09-23 19:16:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets LayoutType.
|
|
|
|
*
|
|
|
|
* @see LayoutType
|
|
|
|
*
|
|
|
|
* @return LayoutType
|
|
|
|
*/
|
2013-09-23 21:26:44 +08:00
|
|
|
virtual LayoutType getLayoutType() const;
|
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 initRenderer();
|
|
|
|
void moveChildren(float offset);
|
|
|
|
void autoScrollChildren(float dt);
|
|
|
|
void startAutoScrollChildren(float v);
|
|
|
|
void stopAutoScrollChildren();
|
|
|
|
float getCurAutoScrollDistance(float time);
|
|
|
|
virtual bool scrollChildren(float touchOffset);
|
|
|
|
void startRecordSlidAction();
|
|
|
|
virtual void endRecordSlidAction();
|
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);
|
|
|
|
virtual void checkChildInfo(int handleState,UIWidget* sender,const cocos2d::Point &touchPoint);
|
2013-09-13 22:20:20 +08:00
|
|
|
void recordSlidTime(float dt);
|
|
|
|
//override "releaseResoures" method of widget.
|
|
|
|
virtual void releaseResoures();
|
|
|
|
|
|
|
|
void scrollToTopEvent();
|
|
|
|
void scrollToBottomEvent();
|
|
|
|
void scrollToLeftEvent();
|
|
|
|
void scrollToRightEvent();
|
|
|
|
void setMoveDirection(SCROLLVIEW_MOVE_DIR dir);
|
|
|
|
SCROLLVIEW_MOVE_DIR getMoveDirection();
|
|
|
|
virtual void onSizeChanged();
|
|
|
|
virtual void setClippingEnabled(bool able){Layout::setClippingEnabled(able);};
|
|
|
|
protected:
|
2013-09-17 20:34:26 +08:00
|
|
|
Layout* _innerContainer;
|
|
|
|
|
2013-09-16 20:54:13 +08:00
|
|
|
SCROLLVIEW_DIR _direction;
|
|
|
|
SCROLLVIEW_MOVE_DIR _moveDirection;
|
|
|
|
float _touchStartLocation;
|
|
|
|
float _touchEndLocation;
|
|
|
|
float _touchMoveStartLocation;
|
|
|
|
float _topBoundary;//test
|
|
|
|
float _bottomBoundary;//test
|
|
|
|
float _leftBoundary;
|
|
|
|
float _rightBoundary;
|
|
|
|
|
|
|
|
bool _topEnd;
|
|
|
|
bool _bottomEnd;
|
|
|
|
bool _leftEnd;
|
|
|
|
bool _rightEnd;
|
|
|
|
|
|
|
|
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:34:26 +08:00
|
|
|
SEL_ScrollViewEvent _eventSelector;
|
2013-09-16 20:54:13 +08:00
|
|
|
|
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(__CocoGUI__UIScrollView__) */
|