issue #5176, refactor UICheckBox releaseUpEvent

This commit is contained in:
andyque 2014-05-26 14:44:28 +08:00
parent 40f2128acd
commit e866800044
9 changed files with 31 additions and 44 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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()
{

View File

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

View File

@ -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);
}
}

View File

@ -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(){};