mirror of
https://github.com/scratchfoundation/Gestouch.git
synced 2025-02-16 23:40:14 -05:00
Moved some IGesturesManager methods under gestouch_internal namespace
This commit is contained in:
parent
3ba8a3df86
commit
0532f4bfbb
3 changed files with 114 additions and 117 deletions
|
@ -76,108 +76,6 @@ package org.gestouch.core
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function addGesture(gesture:Gesture):void
|
||||
{
|
||||
if (!gesture)
|
||||
{
|
||||
throw new ArgumentError("Argument 'gesture' must be not null.");
|
||||
}
|
||||
if (_gestures.indexOf(gesture) > -1)
|
||||
{
|
||||
throw new Error("This gesture is already registered.. something wrong.");
|
||||
}
|
||||
|
||||
var targetGestures:Vector.<Gesture> = _gesturesForTargetMap[gesture.target] as Vector.<Gesture>;
|
||||
if (!targetGestures)
|
||||
{
|
||||
targetGestures = _gesturesForTargetMap[gesture.target] = new Vector.<Gesture>();
|
||||
}
|
||||
targetGestures.push(gesture);
|
||||
|
||||
_gestures.push(gesture);
|
||||
|
||||
if (GesturesManager.initDefaultInputAdapter)
|
||||
{
|
||||
if (!_stage && gesture.target.stage)
|
||||
{
|
||||
installStage(gesture.target.stage);
|
||||
}
|
||||
else
|
||||
{
|
||||
gesture.target.addEventListener(Event.ADDED_TO_STAGE, gestureTarget_addedToStageHandler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function removeGesture(gesture:Gesture):void
|
||||
{
|
||||
if (!gesture)
|
||||
{
|
||||
throw new ArgumentError("Argument 'gesture' must be not null.");
|
||||
}
|
||||
|
||||
|
||||
var target:InteractiveObject = gesture.target;
|
||||
var targetGestures:Vector.<Gesture> = _gesturesForTargetMap[target] as Vector.<Gesture>;
|
||||
targetGestures.splice(targetGestures.indexOf(gesture), 1);
|
||||
|
||||
if (targetGestures.length == 0)
|
||||
{
|
||||
delete _gesturesForTargetMap[target];
|
||||
target.removeEventListener(Event.ADDED_TO_STAGE, gestureTarget_addedToStageHandler);
|
||||
}
|
||||
|
||||
var index:int = _gestures.indexOf(gesture);
|
||||
if (index > -1)
|
||||
{
|
||||
_gestures.splice(index, 1);
|
||||
}
|
||||
|
||||
//TODO: decide about gesture state and _dirtyGestures
|
||||
}
|
||||
|
||||
|
||||
public function scheduleGestureStateReset(gesture:Gesture):void
|
||||
{
|
||||
if (!_dirtyGesturesMap[gesture])
|
||||
{
|
||||
_dirtyGestures.push(gesture);
|
||||
_dirtyGesturesLength++;
|
||||
_frameTickerShape.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function onGestureRecognized(gesture:Gesture):void
|
||||
{
|
||||
for each (var otherGesture:Gesture in _gestures)
|
||||
{
|
||||
// conditions for otherGesture "own properties"
|
||||
if (otherGesture != gesture &&
|
||||
otherGesture.enabled &&
|
||||
otherGesture.state == GestureState.POSSIBLE)
|
||||
{
|
||||
// conditions for otherGesture target
|
||||
if (otherGesture.target == gesture.target ||
|
||||
(gesture.target is DisplayObjectContainer && (gesture.target as DisplayObjectContainer).contains(otherGesture.target)) ||
|
||||
(otherGesture.target is DisplayObjectContainer && (otherGesture.target as DisplayObjectContainer).contains(gesture.target))
|
||||
)
|
||||
{
|
||||
// conditions for gestures relations
|
||||
if (gesture.canPreventGesture(otherGesture) &&
|
||||
otherGesture.canBePreventedByGesture(gesture) &&
|
||||
(!gesture.delegate || !gesture.delegate.gesturesShouldRecognizeSimultaneously(gesture, otherGesture)) &&
|
||||
(!otherGesture.delegate || !otherGesture.delegate.gesturesShouldRecognizeSimultaneously(otherGesture, gesture)))
|
||||
{
|
||||
otherGesture.gestouch_internal::setState_internal(GestureState.FAILED);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function addInputAdapter(inputAdapter:IInputAdapter):void
|
||||
|
@ -248,6 +146,108 @@ package org.gestouch.core
|
|||
}
|
||||
|
||||
|
||||
gestouch_internal function addGesture(gesture:Gesture):void
|
||||
{
|
||||
if (!gesture)
|
||||
{
|
||||
throw new ArgumentError("Argument 'gesture' must be not null.");
|
||||
}
|
||||
if (_gestures.indexOf(gesture) > -1)
|
||||
{
|
||||
throw new Error("This gesture is already registered.. something wrong.");
|
||||
}
|
||||
|
||||
var targetGestures:Vector.<Gesture> = _gesturesForTargetMap[gesture.target] as Vector.<Gesture>;
|
||||
if (!targetGestures)
|
||||
{
|
||||
targetGestures = _gesturesForTargetMap[gesture.target] = new Vector.<Gesture>();
|
||||
}
|
||||
targetGestures.push(gesture);
|
||||
|
||||
_gestures.push(gesture);
|
||||
|
||||
if (GesturesManager.initDefaultInputAdapter)
|
||||
{
|
||||
if (!_stage && gesture.target.stage)
|
||||
{
|
||||
installStage(gesture.target.stage);
|
||||
}
|
||||
else
|
||||
{
|
||||
gesture.target.addEventListener(Event.ADDED_TO_STAGE, gestureTarget_addedToStageHandler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
gestouch_internal function removeGesture(gesture:Gesture):void
|
||||
{
|
||||
if (!gesture)
|
||||
{
|
||||
throw new ArgumentError("Argument 'gesture' must be not null.");
|
||||
}
|
||||
|
||||
|
||||
var target:InteractiveObject = gesture.target;
|
||||
var targetGestures:Vector.<Gesture> = _gesturesForTargetMap[target] as Vector.<Gesture>;
|
||||
targetGestures.splice(targetGestures.indexOf(gesture), 1);
|
||||
|
||||
if (targetGestures.length == 0)
|
||||
{
|
||||
delete _gesturesForTargetMap[target];
|
||||
target.removeEventListener(Event.ADDED_TO_STAGE, gestureTarget_addedToStageHandler);
|
||||
}
|
||||
|
||||
var index:int = _gestures.indexOf(gesture);
|
||||
if (index > -1)
|
||||
{
|
||||
_gestures.splice(index, 1);
|
||||
}
|
||||
|
||||
//TODO: decide about gesture state and _dirtyGestures
|
||||
}
|
||||
|
||||
|
||||
gestouch_internal function scheduleGestureStateReset(gesture:Gesture):void
|
||||
{
|
||||
if (!_dirtyGesturesMap[gesture])
|
||||
{
|
||||
_dirtyGestures.push(gesture);
|
||||
_dirtyGesturesLength++;
|
||||
_frameTickerShape.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
gestouch_internal function onGestureRecognized(gesture:Gesture):void
|
||||
{
|
||||
for each (var otherGesture:Gesture in _gestures)
|
||||
{
|
||||
// conditions for otherGesture "own properties"
|
||||
if (otherGesture != gesture &&
|
||||
otherGesture.enabled &&
|
||||
otherGesture.state == GestureState.POSSIBLE)
|
||||
{
|
||||
// conditions for otherGesture target
|
||||
if (otherGesture.target == gesture.target ||
|
||||
(gesture.target is DisplayObjectContainer && (gesture.target as DisplayObjectContainer).contains(otherGesture.target)) ||
|
||||
(otherGesture.target is DisplayObjectContainer && (otherGesture.target as DisplayObjectContainer).contains(gesture.target))
|
||||
)
|
||||
{
|
||||
// conditions for gestures relations
|
||||
if (gesture.canPreventGesture(otherGesture) &&
|
||||
otherGesture.canBePreventedByGesture(gesture) &&
|
||||
(!gesture.delegate || !gesture.delegate.gesturesShouldRecognizeSimultaneously(gesture, otherGesture)) &&
|
||||
(!otherGesture.delegate || !otherGesture.delegate.gesturesShouldRecognizeSimultaneously(otherGesture, gesture)))
|
||||
{
|
||||
otherGesture.gestouch_internal::setState_internal(GestureState.FAILED);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
gestouch_internal function onTouchBegin(touch:Touch):void
|
||||
{
|
||||
if (_dirtyGesturesLength > 0)
|
||||
|
|
|
@ -1,20 +1,17 @@
|
|||
package org.gestouch.core
|
||||
{
|
||||
import org.gestouch.gestures.Gesture;
|
||||
/**
|
||||
* @author Pavel fljot
|
||||
* The class that implements this interface must also
|
||||
* implement next methods under gestouch_internal namespace:
|
||||
*
|
||||
* function addGesture(gesture:Gesture):void;
|
||||
* function removeGesture(gesture:Gesture):void;
|
||||
* function scheduleGestureStateReset(gesture:Gesture):void;
|
||||
* function onGestureRecognized(gesture:Gesture):void;
|
||||
*/
|
||||
public interface IGesturesManager
|
||||
{
|
||||
function addInputAdapter(inputAdapter:IInputAdapter):void;
|
||||
function removeInputAdapter(inputAdapter:IInputAdapter):void;
|
||||
|
||||
function addGesture(gesture:Gesture):void;
|
||||
|
||||
function removeGesture(gesture:Gesture):void;
|
||||
|
||||
function scheduleGestureStateReset(gesture:Gesture):void;
|
||||
|
||||
function onGestureRecognized(gesture:Gesture):void;
|
||||
}
|
||||
}
|
|
@ -248,8 +248,8 @@ package org.gestouch.gestures
|
|||
protected function installTarget(target:InteractiveObject):void
|
||||
{
|
||||
if (target)
|
||||
{
|
||||
_gesturesManager.addGesture(this);
|
||||
{
|
||||
_gesturesManager.gestouch_internal::addGesture(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -265,7 +265,7 @@ package org.gestouch.gestures
|
|||
{
|
||||
if (target)
|
||||
{
|
||||
_gesturesManager.removeGesture(this);
|
||||
_gesturesManager.gestouch_internal::removeGesture(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -337,7 +337,7 @@ package org.gestouch.gestures
|
|||
|
||||
if (((GestureState.CANCELLED | GestureState.RECOGNIZED | GestureState.ENDED | GestureState.FAILED) & _state) > 0)
|
||||
{
|
||||
_gesturesManager.scheduleGestureStateReset(this);
|
||||
_gesturesManager.gestouch_internal::scheduleGestureStateReset(this);
|
||||
}
|
||||
|
||||
//TODO: what if RTE happens in event handlers?
|
||||
|
@ -349,7 +349,7 @@ package org.gestouch.gestures
|
|||
|
||||
if (_state == GestureState.BEGAN || _state == GestureState.RECOGNIZED)
|
||||
{
|
||||
_gesturesManager.onGestureRecognized(this);
|
||||
_gesturesManager.gestouch_internal::onGestureRecognized(this);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
Loading…
Reference in a new issue