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 __UIPAGEVIEW_H__
|
|
|
|
#define __UIPAGEVIEW_H__
|
|
|
|
|
2013-11-06 16:04:06 +08:00
|
|
|
#include "gui/UILayout.h"
|
2013-10-16 16:48:39 +08:00
|
|
|
#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
|
|
|
|
2013-09-17 20:13:23 +08:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
PAGEVIEW_EVENT_TURNING,
|
|
|
|
}PageViewEventType;
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
typedef void (cocos2d::Object::*SEL_PageViewEvent)(cocos2d::Object*, PageViewEventType);
|
2013-09-17 20:13:23 +08:00
|
|
|
#define pagevieweventselector(_SELECTOR)(SEL_PageViewEvent)(&_SELECTOR)
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
PAGEVIEW_TOUCHLEFT,
|
|
|
|
PAGEVIEW_TOUCHRIGHT
|
|
|
|
}PVTouchDir;
|
|
|
|
|
2013-11-06 16:04:06 +08:00
|
|
|
class UIPageView : public UILayout , public UIScrollInterface
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Default constructor
|
|
|
|
*/
|
|
|
|
UIPageView();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Default destructor
|
|
|
|
*/
|
|
|
|
virtual ~UIPageView();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocates and initializes.
|
|
|
|
*/
|
|
|
|
static UIPageView* create();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a widget to a page of pageview.
|
|
|
|
*
|
|
|
|
* @param widget widget to be added to pageview.
|
|
|
|
*
|
|
|
|
* @param pageIdx index of page.
|
|
|
|
*
|
|
|
|
* @param forceCreate if force create and there is no page exsit, pageview would create a default page for adding widget.
|
|
|
|
*/
|
|
|
|
void addWidgetToPage(UIWidget* widget, int pageIdx, bool forceCreate);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Push back a page to pageview.
|
|
|
|
*
|
|
|
|
* @param page page to be added to pageview.
|
|
|
|
*/
|
2013-11-06 16:04:06 +08:00
|
|
|
void addPage(UILayout* page);
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Inert a page to pageview.
|
|
|
|
*
|
|
|
|
* @param page page to be added to pageview.
|
|
|
|
*/
|
2013-11-06 16:04:06 +08:00
|
|
|
void insertPage(UILayout* page, int idx);
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a page of pageview.
|
|
|
|
*
|
|
|
|
* @param page page which will be removed.
|
|
|
|
*/
|
2013-11-06 16:04:06 +08:00
|
|
|
void removePage(UILayout* page);
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a page at index of pageview.
|
|
|
|
*
|
|
|
|
* @param index index of page.
|
|
|
|
*/
|
|
|
|
void removePageAtIndex(int index);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* scroll pageview to index.
|
|
|
|
*
|
|
|
|
* @param idx index of page.
|
|
|
|
*/
|
|
|
|
void scrollToPage(int idx);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets current page index.
|
|
|
|
*
|
|
|
|
* @return current page index.
|
|
|
|
*/
|
|
|
|
int getCurPageIndex() const;
|
|
|
|
|
2013-11-06 16:04:06 +08:00
|
|
|
cocos2d::Array* getPages();
|
|
|
|
|
2013-09-17 20:13:23 +08:00
|
|
|
// event
|
2013-11-08 18:43:06 +08:00
|
|
|
void addEventListenerPageView(cocos2d::Object *target, SEL_PageViewEvent selector);
|
2013-11-06 16:04:06 +08:00
|
|
|
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
//override "removeChild" method of widget.
|
|
|
|
virtual bool removeChild(UIWidget* widget);
|
|
|
|
|
|
|
|
//override "removeAllChildrenAndCleanUp" method of widget.
|
|
|
|
virtual void removeAllChildren();
|
|
|
|
|
|
|
|
//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 "update" method of widget.
|
|
|
|
virtual void update(float dt);
|
2013-09-23 19:16:20 +08:00
|
|
|
|
|
|
|
virtual void doLayout(){};
|
2013-11-06 16:04:06 +08:00
|
|
|
|
2013-09-17 17:59:20 +08:00
|
|
|
/**
|
|
|
|
* Returns the "class name" of widget.
|
|
|
|
*/
|
|
|
|
virtual const char* getDescription() const;
|
2013-11-06 16:04:06 +08:00
|
|
|
|
2013-09-13 22:20:20 +08:00
|
|
|
protected:
|
|
|
|
virtual bool addChild(UIWidget* widget);
|
|
|
|
virtual bool init();
|
2013-11-06 16:04:06 +08:00
|
|
|
UILayout* createPage();
|
2013-09-13 22:20:20 +08:00
|
|
|
float getPositionXByIndex(int idx);
|
|
|
|
void updateBoundaryPages();
|
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
|
|
|
virtual bool scrollPages(float touchOffset);
|
|
|
|
void movePages(float offset);
|
|
|
|
void pageTurningEvent();
|
|
|
|
void updateChildrenSize();
|
|
|
|
void updateChildrenPosition();
|
|
|
|
virtual void onSizeChanged();
|
2013-11-06 16:04:06 +08:00
|
|
|
virtual UIWidget* createCloneInstance();
|
|
|
|
virtual void copySpecialProperties(UIWidget* model);
|
|
|
|
virtual void copyClonedWidgetChildren(UIWidget* model);
|
|
|
|
virtual void setClippingEnabled(bool able){UILayout::setClippingEnabled(able);};
|
2013-09-13 22:20:20 +08:00
|
|
|
protected:
|
2013-09-16 20:54:13 +08:00
|
|
|
int _curPageIdx;
|
2013-10-15 18:00:03 +08:00
|
|
|
cocos2d::Array* _pages;
|
2013-09-16 20:54:13 +08:00
|
|
|
PVTouchDir _touchMoveDir;
|
|
|
|
float _touchStartLocation;
|
|
|
|
float _touchMoveStartLocation;
|
2013-10-15 18:00:03 +08:00
|
|
|
cocos2d::Point _movePagePoint;
|
2013-09-16 20:54:13 +08:00
|
|
|
UIWidget* _leftChild;
|
|
|
|
UIWidget* _rightChild;
|
|
|
|
float _leftBoundary;
|
|
|
|
float _rightBoundary;
|
|
|
|
bool _isAutoScrolling;
|
|
|
|
float _autoScrollDistance;
|
|
|
|
float _autoScrollSpeed;
|
|
|
|
int _autoScrollDir;
|
|
|
|
float _childFocusCancelOffset;
|
2013-11-08 18:43:06 +08:00
|
|
|
cocos2d::Object* _pageViewEventListener;
|
|
|
|
SEL_PageViewEvent _pageViewEventSelector;
|
2013-11-06 16:04:06 +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(__UIPageView__) */
|