From b765eba46a42275059eac6cb0e4372c3908fdd0a Mon Sep 17 00:00:00 2001 From: Pavel fljot Date: Thu, 5 May 2011 19:14:49 +0300 Subject: [PATCH] Added GestureTrackingEvent (GESTURE_TRACKING_BEGIN, GESTURE_TRACKING_END), made Gesture extend EventDispatcher (and IGesture extend IEventDispatcher) --- src/org/gestouch/core/GesturesManager.as | 2 +- src/org/gestouch/core/IGesture.as | 3 +- .../gestouch/events/GestureTrackingEvent.as | 32 +++++++++++++++++++ src/org/gestouch/gestures/Gesture.as | 26 +++++++++++++-- 4 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 src/org/gestouch/events/GestureTrackingEvent.as diff --git a/src/org/gestouch/core/GesturesManager.as b/src/org/gestouch/core/GesturesManager.as index e199480..4af5972 100644 --- a/src/org/gestouch/core/GesturesManager.as +++ b/src/org/gestouch/core/GesturesManager.as @@ -85,7 +85,7 @@ package org.gestouch.core _stage.addEventListener(MouseEvent.MOUSE_DOWN, stage_mouseDownHandler); _stage.addEventListener(TouchEvent.TOUCH_BEGIN, stage_touchBeginHandler); _stage.addEventListener(TouchEvent.TOUCH_MOVE, stage_touchMoveHandler); - _stage.addEventListener(TouchEvent.TOUCH_END, stage_touchEndHandler); + _stage.addEventListener(TouchEvent.TOUCH_END, stage_touchEndHandler, true); } diff --git a/src/org/gestouch/core/IGesture.as b/src/org/gestouch/core/IGesture.as index 6ba69a4..ed4e84b 100644 --- a/src/org/gestouch/core/IGesture.as +++ b/src/org/gestouch/core/IGesture.as @@ -1,12 +1,13 @@ package org.gestouch.core { + import flash.events.IEventDispatcher; import flash.display.InteractiveObject; import flash.events.TouchEvent; /** * @author Pavel fljot */ - public interface IGesture + public interface IGesture extends IEventDispatcher { function get target():InteractiveObject; function get trackingPoints():Vector.; diff --git a/src/org/gestouch/events/GestureTrackingEvent.as b/src/org/gestouch/events/GestureTrackingEvent.as new file mode 100644 index 0000000..a8b43ff --- /dev/null +++ b/src/org/gestouch/events/GestureTrackingEvent.as @@ -0,0 +1,32 @@ +package org.gestouch.events +{ + import flash.events.Event; + + + /** + * @author Pavel fljot + */ + public class GestureTrackingEvent extends Event + { + public static const GESTURE_TRACKING_BEGIN:String = "gestureTrackingBegin"; + public static const GESTURE_TRACKING_END:String = "gestureTrackingEnd"; + + + public function GestureTrackingEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false) + { + super(type, bubbles, cancelable); + } + + + override public function clone():Event + { + return new GestureTrackingEvent(type, bubbles, cancelable); + } + + + override public function toString():String + { + return formatToString("GestureTrackingEvent", "type", "bubbles", "cancelable", "eventPhase"); + } + } +} \ No newline at end of file diff --git a/src/org/gestouch/gestures/Gesture.as b/src/org/gestouch/gestures/Gesture.as index 66e6cfc..5099a5b 100644 --- a/src/org/gestouch/gestures/Gesture.as +++ b/src/org/gestouch/gestures/Gesture.as @@ -1,5 +1,7 @@ package org.gestouch.gestures { + import org.gestouch.events.GestureTrackingEvent; + import flash.events.EventDispatcher; import flash.errors.IllegalOperationError; import flash.display.InteractiveObject; import flash.events.GestureEvent; @@ -11,15 +13,17 @@ package org.gestouch.gestures import org.gestouch.core.IGesture; import org.gestouch.core.TouchPoint; import org.gestouch.core.gestouch_internal; - - + + + [Event(name="gestureTrackingBegin", type="org.gestouch.events.GestureTrackingEvent")] + [Event(name="gestureTrackingEnd", type="org.gestouch.events.GestureTrackingEvent")] /** * Base class for all gestures. Gesture is essentially a detector that tracks touch points * in order detect specific gesture motion and form gesture event on target. * * @author Pavel fljot */ - public class Gesture implements IGesture + public class Gesture extends EventDispatcher implements IGesture { /** * Threshold for screen distance they must move to count as valid input @@ -448,6 +452,14 @@ _propertyNames.push("timeThreshold", "moveThreshold"); { _adjustCentralPoint(); } + + if (_trackingPointsCount == minTouchPointsCount) + { + if (hasEventListener(GestureTrackingEvent.GESTURE_TRACKING_BEGIN)) + { + dispatchEvent(new GestureTrackingEvent(GestureTrackingEvent.GESTURE_TRACKING_BEGIN)); + } + } } @@ -467,6 +479,14 @@ _propertyNames.push("timeThreshold", "moveThreshold"); _trackingPointsCount--; _adjustCentralPoint(); + + if (_trackingPointsCount == minTouchPointsCount + 1) + { + if (hasEventListener(GestureTrackingEvent.GESTURE_TRACKING_END)) + { + dispatchEvent(new GestureTrackingEvent(GestureTrackingEvent.GESTURE_TRACKING_END)); + } + } }