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
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)

View File

@ -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