Get rid of IDLE gesture state

This commit is contained in:
Pavel fljot 2012-09-03 16:34:36 +03:00
parent 3081c80355
commit 98f943b871
3 changed files with 29 additions and 27 deletions

View file

@ -9,7 +9,6 @@ package org.gestouch.core
*/ */
final public class GestureState final public class GestureState
{ {
public static const IDLE:GestureState = new GestureState("IDLE");
public static const POSSIBLE:GestureState = new GestureState("POSSIBLE"); public static const POSSIBLE:GestureState = new GestureState("POSSIBLE");
public static const RECOGNIZED:GestureState = new GestureState("RECOGNIZED", true); public static const RECOGNIZED:GestureState = new GestureState("RECOGNIZED", true);
public static const BEGAN:GestureState = new GestureState("BEGAN"); public static const BEGAN:GestureState = new GestureState("BEGAN");
@ -46,14 +45,13 @@ package org.gestouch.core
private static function _initClass():void private static function _initClass():void
{ {
IDLE.setValidNextStates(POSSIBLE);
POSSIBLE.setValidNextStates(RECOGNIZED, BEGAN, FAILED); POSSIBLE.setValidNextStates(RECOGNIZED, BEGAN, FAILED);
RECOGNIZED.setValidNextStates(IDLE); RECOGNIZED.setValidNextStates(POSSIBLE);
BEGAN.setValidNextStates(CHANGED, ENDED, CANCELLED); BEGAN.setValidNextStates(CHANGED, ENDED, CANCELLED);
CHANGED.setValidNextStates(CHANGED, ENDED, CANCELLED); CHANGED.setValidNextStates(CHANGED, ENDED, CANCELLED);
ENDED.setValidNextStates(IDLE); ENDED.setValidNextStates(POSSIBLE);
FAILED.setValidNextStates(IDLE); FAILED.setValidNextStates(POSSIBLE);
CANCELLED.setValidNextStates(IDLE); CANCELLED.setValidNextStates(POSSIBLE);
allStatesInitialized = true; allStatesInitialized = true;
} }

View file

@ -10,7 +10,6 @@ package org.gestouch.events
*/ */
public class GestureEvent extends Event public class GestureEvent extends Event
{ {
public static const GESTURE_IDLE:String = "gestureIdle";
public static const GESTURE_POSSIBLE:String = "gesturePossible"; public static const GESTURE_POSSIBLE:String = "gesturePossible";
public static const GESTURE_RECOGNIZED:String = "gestureRecognized"; public static const GESTURE_RECOGNIZED:String = "gestureRecognized";
public static const GESTURE_BEGAN:String = "gestureBegan"; public static const GESTURE_BEGAN:String = "gestureBegan";

View file

@ -23,13 +23,6 @@ package org.gestouch.gestures
* @see #state * @see #state
*/ */
[Event(name="gestureStateChange", type="org.gestouch.events.GestureEvent")] [Event(name="gestureStateChange", type="org.gestouch.events.GestureEvent")]
/**
* Dispatched when the state of the gesture changes to GestureState.IDLE.
*
* @eventType org.gestouch.events.GestureEvent
* @see #state
*/
[Event(name="gestureIdle", type="org.gestouch.events.GestureEvent")]
/** /**
* Dispatched when the state of the gesture changes to GestureState.POSSIBLE. * Dispatched when the state of the gesture changes to GestureState.POSSIBLE.
* *
@ -185,13 +178,20 @@ package org.gestouch.gestures
} }
protected var _state:GestureState = GestureState.IDLE; protected var _state:GestureState = GestureState.POSSIBLE;
public function get state():GestureState public function get state():GestureState
{ {
return _state; return _state;
} }
protected var _idle:Boolean = true;
gestouch_internal function get idle():Boolean
{
return _idle;
}
protected var _touchesCount:uint = 0; protected var _touchesCount:uint = 0;
/** /**
* Amount of currently tracked touch points. * Amount of currently tracked touch points.
@ -286,15 +286,16 @@ package org.gestouch.gestures
*/ */
public function reset():void public function reset():void
{ {
var state:GestureState = this.state;//caching getter if (idle)
return;// Do nothing as we are idle and there is nothing to reset
if (state == GestureState.IDLE) const state:GestureState = this.state;//caching getter
return;// Do nothing as we're in IDLE and nothing to reset
_location.x = 0; _location.x = 0;
_location.y = 0; _location.y = 0;
_touchesMap = {}; _touchesMap = {};
_touchesCount = 0; _touchesCount = 0;
_idle = true;
for (var key:* in _gesturesToFail) for (var key:* in _gesturesToFail)
{ {
@ -320,7 +321,7 @@ package org.gestouch.gestures
// state == GestureState.ENDED || // state == GestureState.ENDED ||
// state == GestureState.FAILED || // state == GestureState.FAILED ||
// state == GestureState.CANCELLED) // state == GestureState.CANCELLED)
setState(GestureState.IDLE); setState(GestureState.POSSIBLE);
} }
} }
@ -434,7 +435,7 @@ package org.gestouch.gestures
{ {
setState(GestureState.FAILED); setState(GestureState.FAILED);
} }
else if (state != GestureState.IDLE) else
{ {
ignoreTouch(touch); ignoreTouch(touch);
} }
@ -503,6 +504,12 @@ package org.gestouch.gestures
_state + " to state " + newState + "."); _state + " to state " + newState + ".");
} }
if (newState != GestureState.POSSIBLE)
{
// in case instantly switch state in touchBeganHandler()
_idle = false;
}
if (newState == GestureState.BEGAN || newState == GestureState.RECOGNIZED) if (newState == GestureState.BEGAN || newState == GestureState.RECOGNIZED)
{ {
@ -514,7 +521,7 @@ package org.gestouch.gestures
for (key in _gesturesToFail) for (key in _gesturesToFail)
{ {
gestureToFail = key as Gesture; gestureToFail = key as Gesture;
if (gestureToFail.state != GestureState.IDLE && if (!gestureToFail.idle &&
gestureToFail.state != GestureState.POSSIBLE && gestureToFail.state != GestureState.POSSIBLE &&
gestureToFail.state != GestureState.FAILED) gestureToFail.state != GestureState.FAILED)
{ {
@ -637,9 +644,9 @@ package org.gestouch.gestures
onTouchBegin(touch); onTouchBegin(touch);
if (_touchesCount == 1 && state == GestureState.IDLE) if (_touchesCount == 1 && state == GestureState.POSSIBLE)
{ {
setState(GestureState.POSSIBLE); _idle = false;
} }
} }
@ -701,11 +708,9 @@ package org.gestouch.gestures
// at this point all gestures-to-fail are either in IDLE or in FAILED states // at this point all gestures-to-fail are either in IDLE or in FAILED states
setState(_pendingRecognizedState); setState(_pendingRecognizedState);
} }
else if (event.newState != GestureState.IDLE && event.newState != GestureState.POSSIBLE) else if (event.newState != GestureState.POSSIBLE)
{ {
// NB: _other_ gesture may switch to IDLE state if it was in FAILED when //TODO: need to re-think this over
// _this_ gesture initially attempted to switch to one of recognized state.
// ...and that's OK (we ignore that)
setState(GestureState.FAILED); setState(GestureState.FAILED);
} }