现在的位置: 首页 > 综合 > 正文

cocos2d-X 节点(UIScrollView.h)API

2014年02月19日 ⁄ 综合 ⁄ 共 4903字 ⁄ 字号 评论关闭

本文来自http://blog.csdn.net/runaying ,引用必须注明出处!

cocos2d-X 节点(UIScrollView.h)API

温馨提醒:为了大家能更好学习,强烈推荐大家看看本人的这篇博客 Cocos2d-X权威指南笔记

滚动视图,包含了许多操作,例如滚动方向 ,顶部边界,滚动视图的容量等

/////cocos2d-x-3.0alpha0/extensions/CocoStudio/GUI/UIWidgets/ScrollWidget
// 滚动视图,包含了许多操作,例如滚动方向 ,顶部边界,滚动视图的容量等


#ifndef __UISCROLLVIEW_H__
#define __UISCROLLVIEW_H__

#include "../../Layouts/Layout.h"
#include "UIScrollInterface.h"

NS_CC_EXT_BEGIN

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,
};

typedef enum
{
    SCROLLVIEW_EVENT_SCROLL_TO_TOP,
    SCROLLVIEW_EVENT_SCROLL_TO_BOTTOM,
    SCROLLVIEW_EVENT_SCROLL_TO_LEFT,
    SCROLLVIEW_EVENT_SCROLL_TO_RIGHT,
}ScrollviewEventType;

typedef void (Object::*SEL_ScrollViewEvent)(Object*, ScrollviewEventType);
#define scrollvieweventselector(_SELECTOR) (SEL_ScrollViewEvent)(&_SELECTOR)


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.     //改变 scrollview 的滚动方向
     *
     * @see SCROLLVIEW_DIR      SCROLLVIEW_DIR_VERTICAL means vertical scroll, SCROLLVIEW_DIR_HORIZONTAL means horizontal scroll
     *
     * @param SCROLLVIEW_DIR
     */
    void setDirection(SCROLLVIEW_DIR dir);
    SCROLLVIEW_DIR getDirection();
    
    /**
     * Gets inner container of scrollview.          //获取 scrollview 的内部容器
     *
     * Inner container is the container of scrollview's children.
     *
     * @return inner container.
     */
    Layout* getInnerContainer();
    
    /**
     * Scroll inner container to bottom boundary of scrollview.  /// scrollview 内部容器的底部边界
     */
    void scrollToBottom();
    
    /**
     * Scroll inner container to top boundary of scrollview.       /// scrollview 内部容器的顶部边界
     */
    void scrollToTop();
    
    /**
     * Changes inner container size of scrollview.
     *
     *  内部容器容量必须大于或等于 scrollview‘s 的容量
     *
     * @param inner container size.
     */
    void setInnerContainerSize(const Size &size);
    
    /**
     * Gets inner container size of scrollview.  获取 scrollview 的内部内部容器容量
     * 内部容器容量必须大于或等于 scrollview‘s 的容量
     *
     *
     * @return inner container size.
     */
	const Size& getInnerContainerSize() const;
    
    /**
     * Add call back function called scrollview event triggered         添加一个回调函数 触发滚动事件
     */
    void addEventListener(Object* target, SEL_ScrollViewEvent selector);
    
    //override "setLayoutExecutant" method of widget.           覆盖 widget 的 setLayoutExecutant 方法
    virtual void setLayoutExecutant(LayoutExecutant* exe);
    
    //override "getLayoutExecutant" method of widget.
    virtual LayoutExecutant* getLayoutExecutant() const;
    
    //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.
    virtual Array* getChildren();
    
    //override "onTouchBegan" method of widget.
    virtual bool onTouchBegan(const Point &touchPoint);
    
    //override "onTouchMoved" method of widget.
    virtual void onTouchMoved(const Point &touchPoint);
    
    //override "onTouchEnded" method of widget.
    virtual void onTouchEnded(const Point &touchPoint);
    
    //override "onTouchCancelled" method of widget.
    virtual void onTouchCancelled(const Point &touchPoint);
    
    //override "onTouchLongClicked" method of widget.
    virtual void onTouchLongClicked(const Point &touchPoint);
    
    virtual void update(float dt);
    
    /**
     * Returns the "class name" of widget.           //返回 widget 的名字
     */
    virtual const char* getDescription() const;
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();
    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);
    virtual void checkChildInfo(int handleState,UIWidget* sender,const Point &touchPoint);
    void recordSlidTime(float dt);
    //override "releaseResoures" method of widget.                  //重写 widget 的releaseResoures 方法
    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:
    Layout* _innerContainer;
    
    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;
    Point _moveChildPoint;
    float _childFocusCancelOffset;
    
    Object* _eventListener;
    SEL_ScrollViewEvent _eventSelector;
    
};

NS_CC_EXT_END

#endif /* defined(__CocoGUI__UIScrollView__) */

抱歉!评论已关闭.