mirror of
https://github.com/scratchfoundation/Gestouch.git
synced 2024-11-23 15:57:54 -05:00
Added GestureTrackingEvent (GESTURE_TRACKING_BEGIN, GESTURE_TRACKING_END),
made Gesture extend EventDispatcher (and IGesture extend IEventDispatcher)
This commit is contained in:
parent
ad8b5a2ecd
commit
b765eba46a
4 changed files with 58 additions and 5 deletions
|
@ -85,7 +85,7 @@ package org.gestouch.core
|
||||||
_stage.addEventListener(MouseEvent.MOUSE_DOWN, stage_mouseDownHandler);
|
_stage.addEventListener(MouseEvent.MOUSE_DOWN, stage_mouseDownHandler);
|
||||||
_stage.addEventListener(TouchEvent.TOUCH_BEGIN, stage_touchBeginHandler);
|
_stage.addEventListener(TouchEvent.TOUCH_BEGIN, stage_touchBeginHandler);
|
||||||
_stage.addEventListener(TouchEvent.TOUCH_MOVE, stage_touchMoveHandler);
|
_stage.addEventListener(TouchEvent.TOUCH_MOVE, stage_touchMoveHandler);
|
||||||
_stage.addEventListener(TouchEvent.TOUCH_END, stage_touchEndHandler);
|
_stage.addEventListener(TouchEvent.TOUCH_END, stage_touchEndHandler, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
package org.gestouch.core
|
package org.gestouch.core
|
||||||
{
|
{
|
||||||
|
import flash.events.IEventDispatcher;
|
||||||
import flash.display.InteractiveObject;
|
import flash.display.InteractiveObject;
|
||||||
import flash.events.TouchEvent;
|
import flash.events.TouchEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Pavel fljot
|
* @author Pavel fljot
|
||||||
*/
|
*/
|
||||||
public interface IGesture
|
public interface IGesture extends IEventDispatcher
|
||||||
{
|
{
|
||||||
function get target():InteractiveObject;
|
function get target():InteractiveObject;
|
||||||
function get trackingPoints():Vector.<TouchPoint>;
|
function get trackingPoints():Vector.<TouchPoint>;
|
||||||
|
|
32
src/org/gestouch/events/GestureTrackingEvent.as
Normal file
32
src/org/gestouch/events/GestureTrackingEvent.as
Normal file
|
@ -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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,7 @@
|
||||||
package org.gestouch.gestures
|
package org.gestouch.gestures
|
||||||
{
|
{
|
||||||
|
import org.gestouch.events.GestureTrackingEvent;
|
||||||
|
import flash.events.EventDispatcher;
|
||||||
import flash.errors.IllegalOperationError;
|
import flash.errors.IllegalOperationError;
|
||||||
import flash.display.InteractiveObject;
|
import flash.display.InteractiveObject;
|
||||||
import flash.events.GestureEvent;
|
import flash.events.GestureEvent;
|
||||||
|
@ -13,13 +15,15 @@ package org.gestouch.gestures
|
||||||
import org.gestouch.core.gestouch_internal;
|
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
|
* 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.
|
* in order detect specific gesture motion and form gesture event on target.
|
||||||
*
|
*
|
||||||
* @author Pavel fljot
|
* @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
|
* Threshold for screen distance they must move to count as valid input
|
||||||
|
@ -448,6 +452,14 @@ _propertyNames.push("timeThreshold", "moveThreshold");
|
||||||
{
|
{
|
||||||
_adjustCentralPoint();
|
_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--;
|
_trackingPointsCount--;
|
||||||
|
|
||||||
_adjustCentralPoint();
|
_adjustCentralPoint();
|
||||||
|
|
||||||
|
if (_trackingPointsCount == minTouchPointsCount + 1)
|
||||||
|
{
|
||||||
|
if (hasEventListener(GestureTrackingEvent.GESTURE_TRACKING_END))
|
||||||
|
{
|
||||||
|
dispatchEvent(new GestureTrackingEvent(GestureTrackingEvent.GESTURE_TRACKING_END));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue