From 841408d1bc255444c372c924763bc27c34bb1de2 Mon Sep 17 00:00:00 2001 From: CaiWenzhi Date: Tue, 17 Sep 2013 20:34:26 +0800 Subject: [PATCH] Modify events methods --- .../UIWidgets/ScrollWidget/UIScrollView.cpp | 52 +++++-------------- .../GUI/UIWidgets/ScrollWidget/UIScrollView.h | 50 ++++++------------ 2 files changed, 30 insertions(+), 72 deletions(-) diff --git a/extensions/CocoStudio/GUI/UIWidgets/ScrollWidget/UIScrollView.cpp b/extensions/CocoStudio/GUI/UIWidgets/ScrollWidget/UIScrollView.cpp index 0881f5f98a..1a64d69778 100644 --- a/extensions/CocoStudio/GUI/UIWidgets/ScrollWidget/UIScrollView.cpp +++ b/extensions/CocoStudio/GUI/UIWidgets/ScrollWidget/UIScrollView.cpp @@ -28,6 +28,7 @@ NS_CC_EXT_BEGIN UIScrollView::UIScrollView(): +_innerContainer(NULL), _direction(SCROLLVIEW_DIR_VERTICAL), _moveDirection(SCROLLVIEW_MOVE_DIR_NONE), _touchStartLocation(0.0f), @@ -48,15 +49,8 @@ _bePressed(false), _slidTime(0.0f), _moveChildPoint(Point::ZERO), _childFocusCancelOffset(5.0f), -_scrollToTopListener(NULL), -_scrollToTopSelector(NULL), -_scrollToBottomListener(NULL), -_scrollToBottomSelector(NULL), -_scrollToLeftListener(NULL), -_scrollToLeftSelector(NULL), -_scrollToRightListener(NULL), -_scrollToRightSelector(NULL), -_innerContainer(NULL) +_eventListener(NULL), +_eventSelector(NULL) { } @@ -609,58 +603,40 @@ void UIScrollView::checkChildInfo(int handleState,UIWidget* sender,const Point & void UIScrollView::scrollToTopEvent() { - if (_scrollToTopListener && _scrollToTopSelector) + if (_eventListener && _eventSelector) { - (_scrollToTopListener->*_scrollToTopSelector)(this); + (_eventListener->*_eventSelector)(this, SCROLLVIEW_EVENT_SCROLL_TO_TOP); } } void UIScrollView::scrollToBottomEvent() { - if (_scrollToBottomListener && _scrollToBottomSelector) + if (_eventListener && _eventSelector) { - (_scrollToBottomListener->*_scrollToBottomSelector)(this); + (_eventListener->*_eventSelector)(this, SCROLLVIEW_EVENT_SCROLL_TO_BOTTOM); } } void UIScrollView::scrollToLeftEvent() { - if (_scrollToLeftListener && _scrollToLeftSelector) + if (_eventListener && _eventSelector) { - (_scrollToLeftListener->*_scrollToLeftSelector)(this); + (_eventListener->*_eventSelector)(this, SCROLLVIEW_EVENT_SCROLL_TO_LEFT); } } 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; - _scrollToTopSelector = 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; + _eventListener = target; + _eventSelector = selector; } void UIScrollView::setDirection(SCROLLVIEW_DIR dir) diff --git a/extensions/CocoStudio/GUI/UIWidgets/ScrollWidget/UIScrollView.h b/extensions/CocoStudio/GUI/UIWidgets/ScrollWidget/UIScrollView.h index 67d1995c08..f2ef9157ee 100644 --- a/extensions/CocoStudio/GUI/UIWidgets/ScrollWidget/UIScrollView.h +++ b/extensions/CocoStudio/GUI/UIWidgets/ScrollWidget/UIScrollView.h @@ -46,14 +46,16 @@ enum SCROLLVIEW_MOVE_DIR SCROLLVIEW_MOVE_DIR_RIGHT, }; -typedef void (Object::*SEL_ScrollToTopEvent)(Object*); -typedef void (Object::*SEL_ScrollToBottomEvent)(Object*); -typedef void (Object::*SEL_ScrollToLeftEvent)(Object*); -typedef void (Object::*SEL_ScrollToRightEvent)(Object*); -#define coco_ScrollToTopSelector(_SELECTOR) (cocos2d::extension::SEL_ScrollToTopEvent)(&_SELECTOR) -#define coco_ScrollToBottomSelector(_SELECTOR) (cocos2d::extension::SEL_ScrollToBottomEvent)(&_SELECTOR) -#define coco_ScrollToLeftSelector(_SELECTOR) (cocos2d::extension::SEL_ScrollToLeftEvent)(&_SELECTOR) -#define coco_ScrollToRightSelector(_SELECTOR) (cocos2d::extension::SEL_ScrollToRightEvent)(&_SELECTOR) +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 @@ -130,24 +132,9 @@ public: 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); - - /** - * 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); + void addEventListener(Object* target, SEL_ScrollViewEvent selector); //override "setLayoutExecutant" method of widget. virtual void setLayoutExecutant(LayoutExecutant* exe); @@ -217,6 +204,8 @@ protected: virtual void onSizeChanged(); virtual void setClippingEnabled(bool able){Layout::setClippingEnabled(able);}; protected: + Layout* _innerContainer; + SCROLLVIEW_DIR _direction; SCROLLVIEW_MOVE_DIR _moveDirection; float _touchStartLocation; @@ -242,16 +231,9 @@ protected: Point _moveChildPoint; float _childFocusCancelOffset; - Object* _scrollToTopListener; - SEL_ScrollToTopEvent _scrollToTopSelector; - Object* _scrollToBottomListener; - SEL_ScrollToBottomEvent _scrollToBottomSelector; - Object* _scrollToLeftListener; - SEL_ScrollToLeftEvent _scrollToLeftSelector; - Object* _scrollToRightListener; - SEL_ScrollToRightEvent _scrollToRightSelector; + Object* _eventListener; + SEL_ScrollViewEvent _eventSelector; - Layout* _innerContainer; }; NS_CC_EXT_END