mirror of
https://github.com/scratchfoundation/Gestouch.git
synced 2024-11-27 01:35:40 -05:00
Update "requireGestureToFail" API implementation
This commit is contained in:
parent
60d9cb6744
commit
2d52729f7c
1 changed files with 25 additions and 15 deletions
|
@ -299,6 +299,11 @@ package org.gestouch.gestures
|
||||||
public function requireGestureToFail(gesture:Gesture):void
|
public function requireGestureToFail(gesture:Gesture):void
|
||||||
{
|
{
|
||||||
//TODO
|
//TODO
|
||||||
|
if (!gesture)
|
||||||
|
{
|
||||||
|
throw new ArgumentError();
|
||||||
|
}
|
||||||
|
|
||||||
_gesturesToFail[gesture] = true;
|
_gesturesToFail[gesture] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -406,14 +411,16 @@ package org.gestouch.gestures
|
||||||
if (newState == GestureState.BEGAN || newState == GestureState.RECOGNIZED)
|
if (newState == GestureState.BEGAN || newState == GestureState.RECOGNIZED)
|
||||||
{
|
{
|
||||||
var gestureToFail:Gesture;
|
var gestureToFail:Gesture;
|
||||||
|
var key:*;
|
||||||
// first we check if other required-to-fail gestures recognized
|
// first we check if other required-to-fail gestures recognized
|
||||||
// TODO: is this really necessary? using "requireGestureToFail" API assume that
|
// TODO: is this really necessary? using "requireGestureToFail" API assume that
|
||||||
// required-to-fail gesture always recognizes AFTER this one.
|
// required-to-fail gesture always recognizes AFTER this one.
|
||||||
for (var key:* in _gesturesToFail)
|
for (key in _gesturesToFail)
|
||||||
{
|
{
|
||||||
gestureToFail = key as Gesture;
|
gestureToFail = key as Gesture;
|
||||||
if (gestureToFail.state != GestureState.IDLE && gestureToFail.state != GestureState.POSSIBLE
|
if (gestureToFail.state != GestureState.IDLE &&
|
||||||
&& gestureToFail.state != GestureState.FAILED)
|
gestureToFail.state != GestureState.POSSIBLE &&
|
||||||
|
gestureToFail.state != GestureState.FAILED)
|
||||||
{
|
{
|
||||||
// Looks like other gesture won't fail,
|
// Looks like other gesture won't fail,
|
||||||
// which means the required condition will not happen, so we must fail
|
// which means the required condition will not happen, so we must fail
|
||||||
|
@ -421,7 +428,7 @@ package org.gestouch.gestures
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// then we check of other required-to-fail gestures are actually tracked (not IDLE)
|
// then we check if other required-to-fail gestures are actually tracked (not IDLE)
|
||||||
// and not still not recognized (e.g. POSSIBLE state)
|
// and not still not recognized (e.g. POSSIBLE state)
|
||||||
for (key in _gesturesToFail)
|
for (key in _gesturesToFail)
|
||||||
{
|
{
|
||||||
|
@ -430,6 +437,13 @@ package org.gestouch.gestures
|
||||||
{
|
{
|
||||||
// Other gesture might fail soon, so we postpone state change
|
// Other gesture might fail soon, so we postpone state change
|
||||||
_pendingRecognizedState = newState;
|
_pendingRecognizedState = newState;
|
||||||
|
|
||||||
|
for (key in _gesturesToFail)
|
||||||
|
{
|
||||||
|
gestureToFail = key as Gesture;
|
||||||
|
gestureToFail.addEventListener(GestureStateEvent.STATE_CHANGE, gestureToFail_stateChangeHandler, false, 0, true);
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// else if gesture is in IDLE state it means it doesn't track anything,
|
// else if gesture is in IDLE state it means it doesn't track anything,
|
||||||
|
@ -528,12 +542,6 @@ package org.gestouch.gestures
|
||||||
|
|
||||||
if (_touchesCount == 1 && state == GestureState.IDLE)
|
if (_touchesCount == 1 && state == GestureState.IDLE)
|
||||||
{
|
{
|
||||||
for (var key:* in _gesturesToFail)
|
|
||||||
{
|
|
||||||
var gestureToFail:Gesture = key as Gesture;
|
|
||||||
gestureToFail.addEventListener(GestureStateEvent.STATE_CHANGE, gestureToFail_stateChangeHandler, false, 0, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
setState(GestureState.POSSIBLE);
|
setState(GestureState.POSSIBLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -557,10 +565,7 @@ package org.gestouch.gestures
|
||||||
|
|
||||||
protected function gestureToFail_stateChangeHandler(event:GestureStateEvent):void
|
protected function gestureToFail_stateChangeHandler(event:GestureStateEvent):void
|
||||||
{
|
{
|
||||||
if (state != GestureState.POSSIBLE)
|
if (!_pendingRecognizedState || state != GestureState.POSSIBLE)
|
||||||
return;//just in case..FIXME?
|
|
||||||
|
|
||||||
if (!_pendingRecognizedState)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (event.newState == GestureState.FAILED)
|
if (event.newState == GestureState.FAILED)
|
||||||
|
@ -575,13 +580,18 @@ package org.gestouch.gestures
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// at this point all gestures-to-fail are either in IDLE or in FAILED states
|
||||||
if (setState(_pendingRecognizedState))
|
if (setState(_pendingRecognizedState))
|
||||||
{
|
{
|
||||||
onDelayedRecognize();
|
onDelayedRecognize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (event.newState != GestureState.POSSIBLE)
|
else if (event.newState != GestureState.IDLE && 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)
|
||||||
|
|
||||||
setState(GestureState.FAILED);
|
setState(GestureState.FAILED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue