mirror of
https://github.com/scratchfoundation/Gestouch.git
synced 2024-11-26 17:26:09 -05:00
Get rid of IDLE gesture state
This commit is contained in:
parent
3081c80355
commit
98f943b871
3 changed files with 29 additions and 27 deletions
|
@ -9,7 +9,6 @@ package org.gestouch.core
|
|||
*/
|
||||
final public class GestureState
|
||||
{
|
||||
public static const IDLE:GestureState = new GestureState("IDLE");
|
||||
public static const POSSIBLE:GestureState = new GestureState("POSSIBLE");
|
||||
public static const RECOGNIZED:GestureState = new GestureState("RECOGNIZED", true);
|
||||
public static const BEGAN:GestureState = new GestureState("BEGAN");
|
||||
|
@ -46,14 +45,13 @@ package org.gestouch.core
|
|||
|
||||
private static function _initClass():void
|
||||
{
|
||||
IDLE.setValidNextStates(POSSIBLE);
|
||||
POSSIBLE.setValidNextStates(RECOGNIZED, BEGAN, FAILED);
|
||||
RECOGNIZED.setValidNextStates(IDLE);
|
||||
RECOGNIZED.setValidNextStates(POSSIBLE);
|
||||
BEGAN.setValidNextStates(CHANGED, ENDED, CANCELLED);
|
||||
CHANGED.setValidNextStates(CHANGED, ENDED, CANCELLED);
|
||||
ENDED.setValidNextStates(IDLE);
|
||||
FAILED.setValidNextStates(IDLE);
|
||||
CANCELLED.setValidNextStates(IDLE);
|
||||
ENDED.setValidNextStates(POSSIBLE);
|
||||
FAILED.setValidNextStates(POSSIBLE);
|
||||
CANCELLED.setValidNextStates(POSSIBLE);
|
||||
|
||||
allStatesInitialized = true;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ package org.gestouch.events
|
|||
*/
|
||||
public class GestureEvent extends Event
|
||||
{
|
||||
public static const GESTURE_IDLE:String = "gestureIdle";
|
||||
public static const GESTURE_POSSIBLE:String = "gesturePossible";
|
||||
public static const GESTURE_RECOGNIZED:String = "gestureRecognized";
|
||||
public static const GESTURE_BEGAN:String = "gestureBegan";
|
||||
|
|
|
@ -23,13 +23,6 @@ package org.gestouch.gestures
|
|||
* @see #state
|
||||
*/
|
||||
[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.
|
||||
*
|
||||
|
@ -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
|
||||
{
|
||||
return _state;
|
||||
}
|
||||
|
||||
|
||||
protected var _idle:Boolean = true;
|
||||
gestouch_internal function get idle():Boolean
|
||||
{
|
||||
return _idle;
|
||||
}
|
||||
|
||||
|
||||
protected var _touchesCount:uint = 0;
|
||||
/**
|
||||
* Amount of currently tracked touch points.
|
||||
|
@ -286,15 +286,16 @@ package org.gestouch.gestures
|
|||
*/
|
||||
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)
|
||||
return;// Do nothing as we're in IDLE and nothing to reset
|
||||
const state:GestureState = this.state;//caching getter
|
||||
|
||||
_location.x = 0;
|
||||
_location.y = 0;
|
||||
_touchesMap = {};
|
||||
_touchesCount = 0;
|
||||
_idle = true;
|
||||
|
||||
for (var key:* in _gesturesToFail)
|
||||
{
|
||||
|
@ -320,7 +321,7 @@ package org.gestouch.gestures
|
|||
// state == GestureState.ENDED ||
|
||||
// state == GestureState.FAILED ||
|
||||
// state == GestureState.CANCELLED)
|
||||
setState(GestureState.IDLE);
|
||||
setState(GestureState.POSSIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -434,7 +435,7 @@ package org.gestouch.gestures
|
|||
{
|
||||
setState(GestureState.FAILED);
|
||||
}
|
||||
else if (state != GestureState.IDLE)
|
||||
else
|
||||
{
|
||||
ignoreTouch(touch);
|
||||
}
|
||||
|
@ -503,6 +504,12 @@ package org.gestouch.gestures
|
|||
_state + " to state " + newState + ".");
|
||||
}
|
||||
|
||||
if (newState != GestureState.POSSIBLE)
|
||||
{
|
||||
// in case instantly switch state in touchBeganHandler()
|
||||
_idle = false;
|
||||
}
|
||||
|
||||
|
||||
if (newState == GestureState.BEGAN || newState == GestureState.RECOGNIZED)
|
||||
{
|
||||
|
@ -514,7 +521,7 @@ package org.gestouch.gestures
|
|||
for (key in _gesturesToFail)
|
||||
{
|
||||
gestureToFail = key as Gesture;
|
||||
if (gestureToFail.state != GestureState.IDLE &&
|
||||
if (!gestureToFail.idle &&
|
||||
gestureToFail.state != GestureState.POSSIBLE &&
|
||||
gestureToFail.state != GestureState.FAILED)
|
||||
{
|
||||
|
@ -637,9 +644,9 @@ package org.gestouch.gestures
|
|||
|
||||
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
|
||||
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
|
||||
// _this_ gesture initially attempted to switch to one of recognized state.
|
||||
// ...and that's OK (we ignore that)
|
||||
//TODO: need to re-think this over
|
||||
|
||||
setState(GestureState.FAILED);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue