Browse Source

SlidingActor dispatching TOUCH_UP when current target could not be clicked

dmuratshin 9 years ago
parent
commit
ba6fd4050a
4 changed files with 29 additions and 6 deletions
  1. 9 5
      oxygine/src/Draggable.cpp
  2. 2 0
      oxygine/src/Draggable.h
  3. 16 1
      oxygine/src/SlidingActor.cpp
  4. 2 0
      oxygine/src/SlidingActor.h

+ 9 - 5
oxygine/src/Draggable.cpp

@@ -58,7 +58,8 @@ namespace oxygine
         _clientIsParent(false),
         _dragEnabled(true),
         _pressed(false),
-        _singleDrag(false)
+        _singleDrag(false),
+        _ignoreTouchUp(false)
     {
 
     }
@@ -164,11 +165,14 @@ namespace oxygine
             break;
             case TouchEvent::TOUCH_UP:
             {
-                _pressed = false;
-                _actor->_getStage()->removeEventListeners(this);
-                if (getTimeMS() - _startTm < 2)
+                if (!_ignoreTouchUp)
                 {
-                    _actor->setPosition(_clientPos);
+                    _pressed = false;
+                    _actor->_getStage()->removeEventListeners(this);
+                    if (getTimeMS() - _startTm < 2)
+                    {
+                        _actor->setPosition(_clientPos);
+                    }
                 }
             }
             break;

+ 2 - 0
oxygine/src/Draggable.h

@@ -31,6 +31,7 @@ namespace oxygine
         void setDragBounds(const RectF& bounds);
         /**sets destination drag client. Default value is Actor attached to DragHandler*/
         void setDragClient(Actor* actor);
+        void setIgnoreTouchUp(bool ignore) { _ignoreTouchUp = ignore; }
         void snapClient2Bounds();
 
     protected:
@@ -53,5 +54,6 @@ namespace oxygine
         bool _clientIsParent;
         bool _pressed;
         bool _dragEnabled;
+        bool _ignoreTouchUp;
     };
 }

+ 16 - 1
oxygine/src/SlidingActor.cpp

@@ -19,6 +19,7 @@ namespace oxygine
         _rad(_defaultTouchThreshold),
         _maxSpeed(250),
         _downTime(0),
+        _ignoreTouchUp(false),
         _lastTime(0), _current(0), _lastIterTime(0),
         _finger(0)
     {
@@ -237,7 +238,12 @@ namespace oxygine
 
             case TouchEvent::TOUCH_UP:
             {
-                if (_drag.getDragEnabled() && te->index == _finger)
+                if (_ignoreTouchUp)
+                {
+                    te->stopImmediatePropagation();
+                }
+
+                if (_drag.getDragEnabled() && te->index == _finger && _ignoreTouchUp == false)
                 {
                     _finger = 0;
                     _downTime = 0;
@@ -323,6 +329,15 @@ namespace oxygine
                             act = act->getParent();
                         }
 
+
+                        TouchEvent ev(TouchEvent::TOUCH_UP, true, Vector2(-100000, -100000));
+
+                        _ignoreTouchUp = true;
+                        _drag.setIgnoreTouchUp(true);
+                        _holded->dispatchEvent(&ev);
+                        _drag.setIgnoreTouchUp(false);
+                        _ignoreTouchUp = false;
+
                         _holded = 0;
                     }
                 }

+ 2 - 0
oxygine/src/SlidingActor.h

@@ -90,6 +90,8 @@ namespace oxygine
 
         timeMS _lastIterTime;
         pointer_index _finger;
+
+        bool _ignoreTouchUp;
     };
 }