diff --git a/cocos/ui/UICheckBox.cpp b/cocos/ui/UICheckBox.cpp index a92537a58c..75fd2edc1c 100644 --- a/cocos/ui/UICheckBox.cpp +++ b/cocos/ui/UICheckBox.cpp @@ -288,30 +288,23 @@ void CheckBox::loadTextureFrontCrossDisabled(const std::string& frontCrossDisabl _frontCrossDisabledRendererAdaptDirty = true; } -void CheckBox::onTouchEnded(Touch *touch, Event *unusedEvent) + +void CheckBox::releaseUpEvent() { - _touchEndPos = touch->getLocation(); - if (_highlight) - { - releaseUpEvent(); - if (_isSelected){ - setSelectedState(false); - unSelectedEvent(); - } - else - { - setSelectedState(true); - selectedEvent(); - } + Widget::releaseUpEvent(); + + if (_isSelected){ + setSelectedState(false); + unSelectedEvent(); } - setHighlighted(false); - Widget* widgetParent = getWidgetParent(); - if (widgetParent) + else { - widgetParent->passTouchEventToParent(TouchEventType::ENDED,this,_touchEndPos); + setSelectedState(true); + selectedEvent(); } } + void CheckBox::onPressStateChangedToNormal() { _backGroundBoxRenderer->setVisible(true); diff --git a/cocos/ui/UICheckBox.h b/cocos/ui/UICheckBox.h index bcfb68e628..2e35ed7798 100644 --- a/cocos/ui/UICheckBox.h +++ b/cocos/ui/UICheckBox.h @@ -176,8 +176,6 @@ public: CC_DEPRECATED_ATTRIBUTE void addEventListenerCheckBox(Ref* target,SEL_SelectedStateEvent selector); void addEventListener(const ccCheckBoxCallback& callback); - //override "onTouchEnded" method of widget. - virtual void onTouchEnded(Touch *touch, Event *unusedEvent); //override "getVirtualRendererSize" method of widget. virtual const Size& getVirtualRendererSize() const override; @@ -204,8 +202,12 @@ protected: virtual void onPressStateChangedToNormal() override; virtual void onPressStateChangedToPressed() override; virtual void onPressStateChangedToDisabled() override; + void selectedEvent(); void unSelectedEvent(); + + virtual void releaseUpEvent(); + virtual void onSizeChanged() override; virtual void updateTextureColor() override; virtual void updateTextureOpacity() override; diff --git a/cocos/ui/UIPageView.cpp b/cocos/ui/UIPageView.cpp index a447a8d968..e3e4517092 100644 --- a/cocos/ui/UIPageView.cpp +++ b/cocos/ui/UIPageView.cpp @@ -344,7 +344,7 @@ void PageView::onTouchMoved(Touch *touch, Event *unusedEvent) Widget* widgetParent = getWidgetParent(); if (widgetParent) { - widgetParent->passTouchEventToParent(TouchEventType::MOVED,this,_touchMovePos); + widgetParent->interceptTouchEvent(TouchEventType::MOVED,this,_touchMovePos); } moveEvent(); } @@ -497,10 +497,6 @@ void PageView::handleReleaseLogic(const Vec2 &touchPoint) } } -void PageView::passTouchEventToParent(TouchEventType event,Widget* sender, const Vec2 &touchPoint) -{ - interceptTouchEvent(event, sender, touchPoint); -} void PageView::interceptTouchEvent(TouchEventType event, Widget *sender, const Vec2 &touchPoint) { diff --git a/cocos/ui/UIPageView.h b/cocos/ui/UIPageView.h index 437c24a8c7..af3ba46f25 100644 --- a/cocos/ui/UIPageView.h +++ b/cocos/ui/UIPageView.h @@ -194,8 +194,6 @@ protected: virtual void handleReleaseLogic(const Vec2 &touchPoint) ; virtual void interceptTouchEvent(TouchEventType event, Widget* sender, const Vec2 &touchPoint) ; - //overrided functions - virtual void passTouchEventToParent(TouchEventType event,Widget* sender,const Vec2 &point) override; virtual void onSizeChanged() override; virtual Widget* createCloneInstance() override; diff --git a/cocos/ui/UIScrollInterface.h b/cocos/ui/UIScrollInterface.h index 84f26f3164..a1cbdf484d 100644 --- a/cocos/ui/UIScrollInterface.h +++ b/cocos/ui/UIScrollInterface.h @@ -40,7 +40,6 @@ protected: virtual void handlePressLogic(const Vec2 &touchPoint) = 0; virtual void handleMoveLogic(const Vec2 &touchPoint) = 0; virtual void handleReleaseLogic(const Vec2 &touchPoint) = 0; - virtual void interceptTouchEvent(Widget::TouchEventType event, Widget* sender, const Vec2 &touchPoint) = 0; }; } diff --git a/cocos/ui/UIScrollView.cpp b/cocos/ui/UIScrollView.cpp index 35422f7b81..e24cc2575b 100644 --- a/cocos/ui/UIScrollView.cpp +++ b/cocos/ui/UIScrollView.cpp @@ -1596,10 +1596,6 @@ void ScrollView::interceptTouchEvent(Widget::TouchEventType event, Widget *sende } } -void ScrollView::passTouchEventToParent(cocos2d::ui::Widget::TouchEventType event, cocos2d::ui::Widget *sender, const cocos2d::Vec2 &point) -{ - interceptTouchEvent(event, sender, point); -} void ScrollView::scrollToTopEvent() { diff --git a/cocos/ui/UIScrollView.h b/cocos/ui/UIScrollView.h index 20a3d05e35..8bfae7f546 100644 --- a/cocos/ui/UIScrollView.h +++ b/cocos/ui/UIScrollView.h @@ -334,7 +334,6 @@ protected: virtual void onSizeChanged() override; virtual void doLayout() override; - virtual void passTouchEventToParent(TouchEventType event,Widget* sender,const Vec2 &point) override; virtual Widget* createCloneInstance() override; virtual void copySpecialProperties(Widget* model) override; diff --git a/cocos/ui/UIWidget.cpp b/cocos/ui/UIWidget.cpp index 2082fd4e16..27ecfe332b 100644 --- a/cocos/ui/UIWidget.cpp +++ b/cocos/ui/UIWidget.cpp @@ -587,7 +587,7 @@ bool Widget::onTouchBegan(Touch *touch, Event *unusedEvent) Widget* widgetParent = getWidgetParent(); if (widgetParent) { - widgetParent->passTouchEventToParent(TouchEventType::BEGAN, this, _touchStartPos); + widgetParent->interceptTouchEvent(TouchEventType::BEGAN, this, _touchStartPos); } pushDownEvent(); return true; @@ -600,7 +600,7 @@ void Widget::onTouchMoved(Touch *touch, Event *unusedEvent) Widget* widgetParent = getWidgetParent(); if (widgetParent) { - widgetParent->passTouchEventToParent(TouchEventType::MOVED, this, _touchMovePos); + widgetParent->interceptTouchEvent(TouchEventType::MOVED, this, _touchMovePos); } moveEvent(); } @@ -608,14 +608,14 @@ void Widget::onTouchMoved(Touch *touch, Event *unusedEvent) void Widget::onTouchEnded(Touch *touch, Event *unusedEvent) { _touchEndPos = touch->getLocation(); - bool highlight = _highlight; - setHighlighted(false); + Widget* widgetParent = getWidgetParent(); if (widgetParent) { - widgetParent->passTouchEventToParent(TouchEventType::ENDED, this, _touchEndPos); + widgetParent->interceptTouchEvent(TouchEventType::ENDED, this, _touchEndPos); } - if (highlight) + + if (_highlight) { releaseUpEvent(); } @@ -623,6 +623,9 @@ void Widget::onTouchEnded(Touch *touch, Event *unusedEvent) { cancelUpEvent(); } + + setHighlighted(false); + } void Widget::onTouchCancelled(Touch *touch, Event *unusedEvent) @@ -747,12 +750,12 @@ bool Widget::clippingParentAreaContainPoint(const Vec2 &pt) return true; } -void Widget::passTouchEventToParent(cocos2d::ui::Widget::TouchEventType event, cocos2d::ui::Widget *sender, const cocos2d::Vec2 &point) +void Widget::interceptTouchEvent(cocos2d::ui::Widget::TouchEventType event, cocos2d::ui::Widget *sender, const cocos2d::Vec2 &point) { Widget* widgetParent = getWidgetParent(); if (widgetParent) { - widgetParent->passTouchEventToParent(event,sender,point); + widgetParent->interceptTouchEvent(event,sender,point); } } diff --git a/cocos/ui/UIWidget.h b/cocos/ui/UIWidget.h index 2425295785..e1be34aa7f 100644 --- a/cocos/ui/UIWidget.h +++ b/cocos/ui/UIWidget.h @@ -460,7 +460,7 @@ public: * @param parent * @param point */ - virtual void passTouchEventToParent(TouchEventType event,Widget* sender,const Vec2 &point); + virtual void interceptTouchEvent(TouchEventType event,Widget* sender,const Vec2 &point); virtual bool onTouchBegan(Touch *touch, Event *unusedEvent); virtual void onTouchMoved(Touch *touch, Event *unusedEvent); @@ -623,8 +623,9 @@ protected: virtual void onPressStateChangedToDisabled(); void pushDownEvent(); void moveEvent(); - void releaseUpEvent(); - void cancelUpEvent(); + + virtual void releaseUpEvent(); + virtual void cancelUpEvent(); virtual void updateTextureColor(){}; virtual void updateTextureOpacity(){};