Modify events methods

This commit is contained in:
CaiWenzhi 2013-09-17 20:34:26 +08:00
parent 9d07b2c1d2
commit 841408d1bc
2 changed files with 30 additions and 72 deletions

View File

@ -28,6 +28,7 @@
NS_CC_EXT_BEGIN NS_CC_EXT_BEGIN
UIScrollView::UIScrollView(): UIScrollView::UIScrollView():
_innerContainer(NULL),
_direction(SCROLLVIEW_DIR_VERTICAL), _direction(SCROLLVIEW_DIR_VERTICAL),
_moveDirection(SCROLLVIEW_MOVE_DIR_NONE), _moveDirection(SCROLLVIEW_MOVE_DIR_NONE),
_touchStartLocation(0.0f), _touchStartLocation(0.0f),
@ -48,15 +49,8 @@ _bePressed(false),
_slidTime(0.0f), _slidTime(0.0f),
_moveChildPoint(Point::ZERO), _moveChildPoint(Point::ZERO),
_childFocusCancelOffset(5.0f), _childFocusCancelOffset(5.0f),
_scrollToTopListener(NULL), _eventListener(NULL),
_scrollToTopSelector(NULL), _eventSelector(NULL)
_scrollToBottomListener(NULL),
_scrollToBottomSelector(NULL),
_scrollToLeftListener(NULL),
_scrollToLeftSelector(NULL),
_scrollToRightListener(NULL),
_scrollToRightSelector(NULL),
_innerContainer(NULL)
{ {
} }
@ -609,58 +603,40 @@ void UIScrollView::checkChildInfo(int handleState,UIWidget* sender,const Point &
void UIScrollView::scrollToTopEvent() void UIScrollView::scrollToTopEvent()
{ {
if (_scrollToTopListener && _scrollToTopSelector) if (_eventListener && _eventSelector)
{ {
(_scrollToTopListener->*_scrollToTopSelector)(this); (_eventListener->*_eventSelector)(this, SCROLLVIEW_EVENT_SCROLL_TO_TOP);
} }
} }
void UIScrollView::scrollToBottomEvent() void UIScrollView::scrollToBottomEvent()
{ {
if (_scrollToBottomListener && _scrollToBottomSelector) if (_eventListener && _eventSelector)
{ {
(_scrollToBottomListener->*_scrollToBottomSelector)(this); (_eventListener->*_eventSelector)(this, SCROLLVIEW_EVENT_SCROLL_TO_BOTTOM);
} }
} }
void UIScrollView::scrollToLeftEvent() void UIScrollView::scrollToLeftEvent()
{ {
if (_scrollToLeftListener && _scrollToLeftSelector) if (_eventListener && _eventSelector)
{ {
(_scrollToLeftListener->*_scrollToLeftSelector)(this); (_eventListener->*_eventSelector)(this, SCROLLVIEW_EVENT_SCROLL_TO_LEFT);
} }
} }
void UIScrollView::scrollToRightEvent() void UIScrollView::scrollToRightEvent()
{ {
if (_scrollToRightListener && _scrollToRightSelector) if (_eventListener && _eventSelector)
{ {
(_scrollToRightListener->*_scrollToRightSelector)(this); (_eventListener->*_eventSelector)(this, SCROLLVIEW_EVENT_SCROLL_TO_RIGHT);
} }
} }
void UIScrollView::addScrollToTopEvent(Object *target, SEL_ScrollToTopEvent selector) void UIScrollView::addEventListener(Object *target, SEL_ScrollViewEvent selector)
{ {
_scrollToTopListener = target; _eventListener = target;
_scrollToTopSelector = selector; _eventSelector = selector;
}
void UIScrollView::addScrollToBottomEvent(Object *target, SEL_ScrollToBottomEvent selector)
{
_scrollToBottomListener = target;
_scrollToBottomSelector = selector;
}
void UIScrollView::addScrollToLeftEvent(Object *target, SEL_ScrollToLeftEvent selector)
{
_scrollToLeftListener = target;
_scrollToLeftSelector = selector;
}
void UIScrollView::addScrollToRightEvent(Object *target, SEL_ScrollToRightEvent selector)
{
_scrollToRightListener = target;
_scrollToRightSelector = selector;
} }
void UIScrollView::setDirection(SCROLLVIEW_DIR dir) void UIScrollView::setDirection(SCROLLVIEW_DIR dir)

View File

@ -46,14 +46,16 @@ enum SCROLLVIEW_MOVE_DIR
SCROLLVIEW_MOVE_DIR_RIGHT, SCROLLVIEW_MOVE_DIR_RIGHT,
}; };
typedef void (Object::*SEL_ScrollToTopEvent)(Object*); typedef enum
typedef void (Object::*SEL_ScrollToBottomEvent)(Object*); {
typedef void (Object::*SEL_ScrollToLeftEvent)(Object*); SCROLLVIEW_EVENT_SCROLL_TO_TOP,
typedef void (Object::*SEL_ScrollToRightEvent)(Object*); SCROLLVIEW_EVENT_SCROLL_TO_BOTTOM,
#define coco_ScrollToTopSelector(_SELECTOR) (cocos2d::extension::SEL_ScrollToTopEvent)(&_SELECTOR) SCROLLVIEW_EVENT_SCROLL_TO_LEFT,
#define coco_ScrollToBottomSelector(_SELECTOR) (cocos2d::extension::SEL_ScrollToBottomEvent)(&_SELECTOR) SCROLLVIEW_EVENT_SCROLL_TO_RIGHT,
#define coco_ScrollToLeftSelector(_SELECTOR) (cocos2d::extension::SEL_ScrollToLeftEvent)(&_SELECTOR) }ScrollviewEventType;
#define coco_ScrollToRightSelector(_SELECTOR) (cocos2d::extension::SEL_ScrollToRightEvent)(&_SELECTOR)
typedef void (Object::*SEL_ScrollViewEvent)(Object*, ScrollviewEventType);
#define scrollvieweventselector(_SELECTOR) (SEL_ScrollViewEvent)(&_SELECTOR)
class UIScrollView : public Layout , public UIScrollInterface class UIScrollView : public Layout , public UIScrollInterface
@ -130,24 +132,9 @@ public:
const Size& getInnerContainerSize() const; const Size& getInnerContainerSize() const;
/** /**
* Add call back function called when scrollview scrolled to top. * Add call back function called scrollview event triggered
*/ */
void addScrollToTopEvent(Object* target, SEL_ScrollToTopEvent selector); void addEventListener(Object* target, SEL_ScrollViewEvent selector);
/**
* Add call back function called when scrollview scrolled to bottom.
*/
void addScrollToBottomEvent(Object* target, SEL_ScrollToBottomEvent selector);
/**
* Add call back function called when scrollview scrolled to left.
*/
void addScrollToLeftEvent(Object* target, SEL_ScrollToLeftEvent selector);
/**
* Add call back function called when scrollview scrolled to right.
*/
void addScrollToRightEvent(Object* target, SEL_ScrollToRightEvent selector);
//override "setLayoutExecutant" method of widget. //override "setLayoutExecutant" method of widget.
virtual void setLayoutExecutant(LayoutExecutant* exe); virtual void setLayoutExecutant(LayoutExecutant* exe);
@ -217,6 +204,8 @@ protected:
virtual void onSizeChanged(); virtual void onSizeChanged();
virtual void setClippingEnabled(bool able){Layout::setClippingEnabled(able);}; virtual void setClippingEnabled(bool able){Layout::setClippingEnabled(able);};
protected: protected:
Layout* _innerContainer;
SCROLLVIEW_DIR _direction; SCROLLVIEW_DIR _direction;
SCROLLVIEW_MOVE_DIR _moveDirection; SCROLLVIEW_MOVE_DIR _moveDirection;
float _touchStartLocation; float _touchStartLocation;
@ -242,16 +231,9 @@ protected:
Point _moveChildPoint; Point _moveChildPoint;
float _childFocusCancelOffset; float _childFocusCancelOffset;
Object* _scrollToTopListener; Object* _eventListener;
SEL_ScrollToTopEvent _scrollToTopSelector; SEL_ScrollViewEvent _eventSelector;
Object* _scrollToBottomListener;
SEL_ScrollToBottomEvent _scrollToBottomSelector;
Object* _scrollToLeftListener;
SEL_ScrollToLeftEvent _scrollToLeftSelector;
Object* _scrollToRightListener;
SEL_ScrollToRightEvent _scrollToRightSelector;
Layout* _innerContainer;
}; };
NS_CC_EXT_END NS_CC_EXT_END