From 98f943b8710263e2c81aa39955f9c90bfed540cf Mon Sep 17 00:00:00 2001 From: Pavel fljot Date: Mon, 3 Sep 2012 16:34:36 +0300 Subject: [PATCH] Get rid of IDLE gesture state --- src/org/gestouch/core/GestureState.as | 10 +++--- src/org/gestouch/events/GestureEvent.as | 1 - src/org/gestouch/gestures/Gesture.as | 45 ++++++++++++++----------- 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/org/gestouch/core/GestureState.as b/src/org/gestouch/core/GestureState.as index 5821fad..43a0b70 100644 --- a/src/org/gestouch/core/GestureState.as +++ b/src/org/gestouch/core/GestureState.as @@ -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; } diff --git a/src/org/gestouch/events/GestureEvent.as b/src/org/gestouch/events/GestureEvent.as index b8a4e72..1c271f2 100644 --- a/src/org/gestouch/events/GestureEvent.as +++ b/src/org/gestouch/events/GestureEvent.as @@ -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"; diff --git a/src/org/gestouch/gestures/Gesture.as b/src/org/gestouch/gestures/Gesture.as index 5eab1f2..a5e6968 100644 --- a/src/org/gestouch/gestures/Gesture.as +++ b/src/org/gestouch/gestures/Gesture.as @@ -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); }