mirror of https://github.com/axmolengine/axmol.git
issue #5176, refactor passTouchEventToParent method of UIWidget
This commit is contained in:
parent
4d82d8d26b
commit
c8d9ab8122
|
@ -308,7 +308,7 @@ void CheckBox::onTouchEnded(Touch *touch, Event *unusedEvent)
|
|||
Widget* widgetParent = getWidgetParent();
|
||||
if (widgetParent)
|
||||
{
|
||||
widgetParent->checkChildInfo(2,this,_touchEndPos);
|
||||
widgetParent->passTouchEventToParent(TouchEventType::ENDED,this,_touchEndPos);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -735,6 +735,7 @@ void Layout::visit(Renderer *renderer, const Mat4 &parentTransform, bool parentT
|
|||
void Layout::sortAllChildren()
|
||||
{
|
||||
Widget::sortAllChildren();
|
||||
doLayout();
|
||||
}
|
||||
|
||||
void Layout::stencilClippingVisit(Renderer *renderer, const Mat4 &parentTransform, bool parentTransformUpdated)
|
||||
|
|
|
@ -414,11 +414,11 @@ void ListView::addEventListener(const ccListViewCallback& callback)
|
|||
_eventCallback = callback;
|
||||
}
|
||||
|
||||
void ListView::selectedItemEvent(int state)
|
||||
void ListView::selectedItemEvent(TouchEventType event)
|
||||
{
|
||||
switch (state)
|
||||
switch (event)
|
||||
{
|
||||
case 0:
|
||||
case TouchEventType::BEGAN:
|
||||
{
|
||||
if (_listViewEventListener && _listViewEventSelector)
|
||||
{
|
||||
|
@ -444,10 +444,10 @@ void ListView::selectedItemEvent(int state)
|
|||
|
||||
}
|
||||
|
||||
void ListView::interceptTouchEvent(int handleState, Widget *sender, const Vec2 &touchPoint)
|
||||
void ListView::interceptTouchEvent(TouchEventType event, Widget *sender, const Vec2 &touchPoint)
|
||||
{
|
||||
ScrollView::interceptTouchEvent(handleState, sender, touchPoint);
|
||||
if (handleState != 1)
|
||||
ScrollView::interceptTouchEvent(event, sender, touchPoint);
|
||||
if (event != TouchEventType::MOVED)
|
||||
{
|
||||
Widget* parent = sender;
|
||||
while (parent)
|
||||
|
@ -459,7 +459,7 @@ void ListView::interceptTouchEvent(int handleState, Widget *sender, const Vec2 &
|
|||
}
|
||||
parent = dynamic_cast<Widget*>(parent->getParent());
|
||||
}
|
||||
selectedItemEvent(handleState);
|
||||
selectedItemEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -204,8 +204,8 @@ protected:
|
|||
virtual Widget* createCloneInstance() override;
|
||||
virtual void copySpecialProperties(Widget* model) override;
|
||||
virtual void copyClonedWidgetChildren(Widget* model) override;
|
||||
void selectedItemEvent(int state);
|
||||
virtual void interceptTouchEvent(int handleState,Widget* sender,const Vec2 &touchPoint) override;
|
||||
void selectedItemEvent(TouchEventType event);
|
||||
virtual void interceptTouchEvent(Widget::TouchEventType event,Widget* sender,const Vec2 &touchPoint) override;
|
||||
protected:
|
||||
|
||||
Widget* _model;
|
||||
|
|
|
@ -344,7 +344,7 @@ void PageView::onTouchMoved(Touch *touch, Event *unusedEvent)
|
|||
Widget* widgetParent = getWidgetParent();
|
||||
if (widgetParent)
|
||||
{
|
||||
widgetParent->checkChildInfo(1,this,_touchMovePos);
|
||||
widgetParent->passTouchEventToParent(TouchEventType::MOVED,this,_touchMovePos);
|
||||
}
|
||||
moveEvent();
|
||||
}
|
||||
|
@ -495,19 +495,19 @@ void PageView::handleReleaseLogic(const Vec2 &touchPoint)
|
|||
}
|
||||
}
|
||||
|
||||
void PageView::checkChildInfo(int handleState,Widget* sender, const Vec2 &touchPoint)
|
||||
void PageView::passTouchEventToParent(TouchEventType event,Widget* sender, const Vec2 &touchPoint)
|
||||
{
|
||||
interceptTouchEvent(handleState, sender, touchPoint);
|
||||
interceptTouchEvent(event, sender, touchPoint);
|
||||
}
|
||||
|
||||
void PageView::interceptTouchEvent(int handleState, Widget *sender, const Vec2 &touchPoint)
|
||||
void PageView::interceptTouchEvent(TouchEventType event, Widget *sender, const Vec2 &touchPoint)
|
||||
{
|
||||
switch (handleState)
|
||||
switch (event)
|
||||
{
|
||||
case 0:
|
||||
case TouchEventType::BEGAN:
|
||||
handlePressLogic(touchPoint);
|
||||
break;
|
||||
case 1:
|
||||
case TouchEventType::MOVED:
|
||||
{
|
||||
float offset = 0;
|
||||
offset = fabs(sender->getTouchStartPos().x - touchPoint.x);
|
||||
|
@ -518,11 +518,8 @@ void PageView::interceptTouchEvent(int handleState, Widget *sender, const Vec2 &
|
|||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
handleReleaseLogic(touchPoint);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
case TouchEventType::CANCELED:
|
||||
case TouchEventType::ENDED:
|
||||
handleReleaseLogic(touchPoint);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -192,10 +192,11 @@ protected:
|
|||
virtual void handlePressLogic(const Vec2 &touchPoint);
|
||||
virtual void handleMoveLogic(const Vec2 &touchPoint) ;
|
||||
virtual void handleReleaseLogic(const Vec2 &touchPoint) ;
|
||||
virtual void interceptTouchEvent(int handleState, Widget* sender, const Vec2 &touchPoint) ;
|
||||
virtual void interceptTouchEvent(TouchEventType event, Widget* sender, const Vec2 &touchPoint) ;
|
||||
|
||||
//overrided functions
|
||||
virtual void checkChildInfo(int handleState, Widget* sender, const Vec2 &touchPoint) override;
|
||||
virtual void passTouchEventToParent(TouchEventType event,Widget* sender,const Vec2 &point) override;
|
||||
|
||||
virtual void onSizeChanged() override;
|
||||
virtual Widget* createCloneInstance() override;
|
||||
virtual void copySpecialProperties(Widget* model) override;
|
||||
|
|
|
@ -40,7 +40,7 @@ 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(int handleState, Widget* sender, const Vec2 &touchPoint) = 0;
|
||||
virtual void interceptTouchEvent(Widget::TouchEventType event, Widget* sender, const Vec2 &touchPoint) = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -1515,15 +1515,15 @@ void ScrollView::recordSlidTime(float dt)
|
|||
}
|
||||
}
|
||||
|
||||
void ScrollView::interceptTouchEvent(int handleState, Widget *sender, const Vec2 &touchPoint)
|
||||
void ScrollView::interceptTouchEvent(Widget::TouchEventType event, Widget *sender, const Vec2 &touchPoint)
|
||||
{
|
||||
switch (handleState)
|
||||
switch (event)
|
||||
{
|
||||
case 0:
|
||||
case TouchEventType::BEGAN:
|
||||
handlePressLogic(touchPoint);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
case TouchEventType::MOVED:
|
||||
{
|
||||
float offset = (sender->getTouchStartPos() - touchPoint).getLength();
|
||||
if (offset > _childFocusCancelOffset)
|
||||
|
@ -1534,19 +1534,17 @@ void ScrollView::interceptTouchEvent(int handleState, Widget *sender, const Vec2
|
|||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
case TouchEventType::CANCELED:
|
||||
case TouchEventType::ENDED:
|
||||
handleReleaseLogic(touchPoint);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
handleReleaseLogic(touchPoint);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ScrollView::checkChildInfo(int handleState,Widget* sender,const Vec2 &touchPoint)
|
||||
void ScrollView::passTouchEventToParent(cocos2d::ui::Widget::TouchEventType event, cocos2d::ui::Widget *sender, const cocos2d::Vec2 &point)
|
||||
{
|
||||
interceptTouchEvent(handleState, sender, touchPoint);
|
||||
interceptTouchEvent(event, sender, point);
|
||||
}
|
||||
|
||||
void ScrollView::scrollToTopEvent()
|
||||
|
|
|
@ -320,6 +320,16 @@ CC_CONSTRUCTOR_ACCESS:
|
|||
|
||||
protected:
|
||||
virtual void initRenderer() override;
|
||||
|
||||
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;
|
||||
virtual void copyClonedWidgetChildren(Widget* model) override;
|
||||
|
||||
|
||||
void moveChildren(float offsetX, float offsetY);
|
||||
void autoScrollChildren(float dt);
|
||||
void bounceChildren(float dt);
|
||||
|
@ -336,27 +346,28 @@ protected:
|
|||
bool bounceScrollChildren(float touchOffsetX, float touchOffsetY);
|
||||
void startRecordSlidAction();
|
||||
virtual void endRecordSlidAction();
|
||||
|
||||
//ScrollViewProtocol
|
||||
virtual void handlePressLogic(const Vec2 &touchPoint) override;
|
||||
virtual void handleMoveLogic(const Vec2 &touchPoint) override;
|
||||
virtual void handleReleaseLogic(const Vec2 &touchPoint) override;
|
||||
virtual void interceptTouchEvent(int handleState,Widget* sender,const Vec2 &touchPoint) override;
|
||||
virtual void checkChildInfo(int handleState,Widget* sender,const Vec2 &touchPoint) override;
|
||||
virtual void interceptTouchEvent(Widget::TouchEventType event,Widget* sender,const Vec2 &touchPoint) override;
|
||||
|
||||
void recordSlidTime(float dt);
|
||||
|
||||
void scrollToTopEvent();
|
||||
void scrollToBottomEvent();
|
||||
void scrollToLeftEvent();
|
||||
void scrollToRightEvent();
|
||||
void scrollingEvent();
|
||||
|
||||
void bounceTopEvent();
|
||||
void bounceBottomEvent();
|
||||
void bounceLeftEvent();
|
||||
void bounceRightEvent();
|
||||
virtual void onSizeChanged() override;
|
||||
virtual Widget* createCloneInstance() override;
|
||||
virtual void copySpecialProperties(Widget* model) override;
|
||||
virtual void copyClonedWidgetChildren(Widget* model) override;
|
||||
virtual void setClippingEnabled(bool able) override{Layout::setClippingEnabled(able);};
|
||||
virtual void doLayout() override;
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
Layout* _innerContainer;
|
||||
|
||||
|
|
|
@ -586,7 +586,7 @@ bool Widget::onTouchBegan(Touch *touch, Event *unusedEvent)
|
|||
Widget* widgetParent = getWidgetParent();
|
||||
if (widgetParent)
|
||||
{
|
||||
widgetParent->checkChildInfo(0,this,_touchStartPos);
|
||||
widgetParent->passTouchEventToParent(TouchEventType::BEGAN, this, _touchStartPos);
|
||||
}
|
||||
pushDownEvent();
|
||||
return true;
|
||||
|
@ -599,7 +599,7 @@ void Widget::onTouchMoved(Touch *touch, Event *unusedEvent)
|
|||
Widget* widgetParent = getWidgetParent();
|
||||
if (widgetParent)
|
||||
{
|
||||
widgetParent->checkChildInfo(1,this,_touchMovePos);
|
||||
widgetParent->passTouchEventToParent(TouchEventType::MOVED, this, _touchMovePos);
|
||||
}
|
||||
moveEvent();
|
||||
}
|
||||
|
@ -612,7 +612,7 @@ void Widget::onTouchEnded(Touch *touch, Event *unusedEvent)
|
|||
Widget* widgetParent = getWidgetParent();
|
||||
if (widgetParent)
|
||||
{
|
||||
widgetParent->checkChildInfo(2,this,_touchEndPos);
|
||||
widgetParent->passTouchEventToParent(TouchEventType::ENDED, this, _touchEndPos);
|
||||
}
|
||||
if (highlight)
|
||||
{
|
||||
|
@ -746,13 +746,14 @@ bool Widget::clippingParentAreaContainPoint(const Vec2 &pt)
|
|||
return true;
|
||||
}
|
||||
|
||||
void Widget::checkChildInfo(int handleState, Widget *sender, const Vec2 &touchPoint)
|
||||
void Widget::passTouchEventToParent(cocos2d::ui::Widget::TouchEventType event, cocos2d::ui::Widget *sender, const cocos2d::Vec2 &point)
|
||||
{
|
||||
Widget* widgetParent = getWidgetParent();
|
||||
if (widgetParent)
|
||||
{
|
||||
widgetParent->checkChildInfo(handleState,sender,touchPoint);
|
||||
widgetParent->passTouchEventToParent(event,sender,point);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Widget::setPosition(const Vec2 &pos)
|
||||
|
|
|
@ -353,11 +353,6 @@ public:
|
|||
*/
|
||||
bool clippingParentAreaContainPoint(const Vec2 &pt);
|
||||
|
||||
/*
|
||||
* Sends the touch event to widget's parent
|
||||
*/
|
||||
virtual void checkChildInfo(int handleState,Widget* sender,const Vec2 &touchPoint);
|
||||
|
||||
/*
|
||||
* Gets the touch began point of widget when widget is selected.
|
||||
*
|
||||
|
@ -453,6 +448,14 @@ public:
|
|||
* @return true if the point is in widget's space, flase otherwise.
|
||||
*/
|
||||
virtual bool hitTest(const Vec2 &pt);
|
||||
|
||||
/*
|
||||
* Sends the touch event to widget's parent
|
||||
* @param event the touch event type, it could be BEGAN/MOVED/CANCELED/ENDED
|
||||
* @param parent
|
||||
* @param point
|
||||
*/
|
||||
virtual void passTouchEventToParent(TouchEventType event,Widget* sender,const Vec2 &point);
|
||||
|
||||
virtual bool onTouchBegan(Touch *touch, Event *unusedEvent);
|
||||
virtual void onTouchMoved(Touch *touch, Event *unusedEvent);
|
||||
|
@ -615,21 +618,27 @@ protected:
|
|||
void moveEvent();
|
||||
void releaseUpEvent();
|
||||
void cancelUpEvent();
|
||||
|
||||
virtual void updateTextureColor(){};
|
||||
virtual void updateTextureOpacity(){};
|
||||
virtual void updateTextureRGBA(){};
|
||||
virtual void updateFlippedX(){};
|
||||
virtual void updateFlippedY(){};
|
||||
virtual void adaptRenderers(){};
|
||||
|
||||
|
||||
void updateColorToRenderer(Node* renderer);
|
||||
void updateOpacityToRenderer(Node* renderer);
|
||||
void updateRGBAToRenderer(Node* renderer);
|
||||
|
||||
void copyProperties(Widget* model);
|
||||
virtual Widget* createCloneInstance();
|
||||
virtual void copySpecialProperties(Widget* model);
|
||||
virtual void copyClonedWidgetChildren(Widget* model);
|
||||
|
||||
Widget* getWidgetParent();
|
||||
void updateContentSizeWithTextureSize(const Size& size);
|
||||
virtual void adaptRenderers(){};
|
||||
|
||||
bool isAncestorsEnabled();
|
||||
Widget* getAncensterWidget(Node* node);
|
||||
bool isAncestorsVisible(Node* node);
|
||||
|
|
Loading…
Reference in New Issue