mirror of
https://github.com/scratchfoundation/Gestouch.git
synced 2025-02-16 23:40:14 -05:00
Moved IDisplayListAdapter creating and retrieving logic to Gestouch class
This commit is contained in:
parent
32e9ff979c
commit
cdd90d7479
4 changed files with 70 additions and 44 deletions
|
@ -44,7 +44,33 @@ package org.gestouch.core
|
|||
{
|
||||
const targetAsDOC:DisplayObjectContainer = this.target as DisplayObjectContainer;
|
||||
const objectAsDO:DisplayObject = object as DisplayObject;
|
||||
return (targetAsDOC && objectAsDO && targetAsDOC.contains(objectAsDO));
|
||||
if (objectAsDO)
|
||||
{
|
||||
return (targetAsDOC && targetAsDOC.contains(objectAsDO));
|
||||
}
|
||||
/**
|
||||
* There might be case when we use some old "software" 3D library for instace,
|
||||
* which viewport is added to classic Display List. So native stage, root and some other
|
||||
* sprites will actually be parents of 3D objects. To ensure all gestures (both for
|
||||
* native and 3D objects) work correctly with each other contains() method should be
|
||||
* a bit more sophisticated.
|
||||
* But as all 3D engines (at least it looks like that) are moving towards Stage3D layer
|
||||
* this task doesn't seem significant anymore. So I leave this implementation as
|
||||
* comments in case someone will actually need it.
|
||||
* Just uncomment this and it should work.
|
||||
|
||||
// else: more complex case.
|
||||
// object is not of the same type as this.target (flash.display::DisplayObject)
|
||||
// it might we some 3D library object in it's viewport (which itself is in DisplayList).
|
||||
// So we perform more general check:
|
||||
const adapter:IDisplayListAdapter = Gestouch.gestouch_internal::getDisplayListAdapter(object);
|
||||
if (adapter)
|
||||
{
|
||||
return adapter.getHierarchy(object).indexOf(this.target) > -1;
|
||||
}
|
||||
*/
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
package org.gestouch.core
|
||||
{
|
||||
import flash.utils.getQualifiedClassName;
|
||||
import flash.display.DisplayObject;
|
||||
import flash.utils.Dictionary;
|
||||
|
||||
|
||||
/**
|
||||
* @author Pavel fljot
|
||||
*/
|
||||
public class Gestouch
|
||||
{
|
||||
final public class Gestouch
|
||||
{
|
||||
private static const _displayListAdaptersMap:Dictionary = new Dictionary();
|
||||
|
||||
{
|
||||
initClass();
|
||||
}
|
||||
|
@ -56,7 +60,12 @@ package org.gestouch.core
|
|||
|
||||
public static function addDisplayListAdapter(targetClass:Class, adapter:IDisplayListAdapter):void
|
||||
{
|
||||
gesturesManager.gestouch_internal::addDisplayListAdapter(targetClass, adapter);
|
||||
if (!targetClass || !adapter)
|
||||
{
|
||||
throw new Error("Argument error: both arguments required.");
|
||||
}
|
||||
|
||||
_displayListAdaptersMap[targetClass] = adapter;
|
||||
}
|
||||
|
||||
|
||||
|
@ -77,6 +86,32 @@ package org.gestouch.core
|
|||
// return touchesManager.getTouches(target);
|
||||
// }
|
||||
|
||||
gestouch_internal static function createGestureTargetAdapter(target:Object):IDisplayListAdapter
|
||||
{
|
||||
const adapter:IDisplayListAdapter = Gestouch.gestouch_internal::getDisplayListAdapter(target);
|
||||
if (adapter)
|
||||
{
|
||||
return new (adapter.reflect())(target);
|
||||
}
|
||||
|
||||
throw new Error("Cannot create adapter for target " + target + " of type " + getQualifiedClassName(target) + ".");
|
||||
}
|
||||
|
||||
|
||||
gestouch_internal static function getDisplayListAdapter(object:Object):IDisplayListAdapter
|
||||
{
|
||||
for (var key:Object in _displayListAdaptersMap)
|
||||
{
|
||||
var targetClass:Class = key as Class;
|
||||
if (object is targetClass)
|
||||
{
|
||||
return _displayListAdaptersMap[key] as IDisplayListAdapter;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private static function initClass():void
|
||||
{
|
||||
|
|
|
@ -16,7 +16,6 @@ package org.gestouch.core
|
|||
*/
|
||||
public class GesturesManager
|
||||
{
|
||||
protected const _displayListAdaptersMap:Dictionary = new Dictionary();
|
||||
protected const _frameTickerShape:Shape = new Shape();
|
||||
protected var _inputAdapters:Vector.<IInputAdapter> = new Vector.<IInputAdapter>();
|
||||
protected var _gesturesMap:Dictionary = new Dictionary(true);
|
||||
|
@ -31,23 +30,13 @@ package org.gestouch.core
|
|||
|
||||
|
||||
public function GesturesManager()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
gestouch_internal function addDisplayListAdapter(targetClass:Class, adapter:IDisplayListAdapter):void
|
||||
{
|
||||
if (!targetClass || !adapter)
|
||||
{
|
||||
throw new Error("Argument error: both arguments required.");
|
||||
}
|
||||
|
||||
_displayListAdaptersMap[targetClass] = adapter;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
// Private methods
|
||||
|
@ -75,22 +64,6 @@ package org.gestouch.core
|
|||
}
|
||||
|
||||
|
||||
gestouch_internal function createGestureTargetAdapter(target:Object):IDisplayListAdapter
|
||||
{
|
||||
for (var key:Object in _displayListAdaptersMap)
|
||||
{
|
||||
var targetClass:Class = key as Class;
|
||||
if (target is targetClass)
|
||||
{
|
||||
var adapter:IDisplayListAdapter = _displayListAdaptersMap[key] as IDisplayListAdapter;
|
||||
return new (adapter.reflect())(target);
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error("Cannot create adapter for target " + target + " of type " + getQualifiedClassName(target) + ".");
|
||||
}
|
||||
|
||||
|
||||
gestouch_internal function addGesture(gesture:Gesture):void
|
||||
{
|
||||
if (!gesture)
|
||||
|
@ -227,19 +200,11 @@ package org.gestouch.core
|
|||
}
|
||||
|
||||
var target:Object = touch.target;
|
||||
var hierarchy:Vector.<Object>;
|
||||
for (var key:Object in _displayListAdaptersMap)
|
||||
{
|
||||
var targetClass:Class = key as Class;
|
||||
if (target is targetClass)
|
||||
{
|
||||
hierarchy = (_displayListAdaptersMap[key] as IDisplayListAdapter).getHierarchy(target);
|
||||
break;
|
||||
}
|
||||
}
|
||||
const displayListAdapter:IDisplayListAdapter = Gestouch.gestouch_internal::getDisplayListAdapter(target);
|
||||
const hierarchy:Vector.<Object> = displayListAdapter.getHierarchy(target);
|
||||
if (!hierarchy)
|
||||
{
|
||||
throw new Error("Display list adapter not found for target of type '" + targetClass + "'.");
|
||||
throw new Error("Display list adapter not found for target of type '" + getQualifiedClassName(target) + "'.");
|
||||
}
|
||||
const hierarchyLength:uint = hierarchy.length;
|
||||
if (hierarchyLength == 0)
|
||||
|
|
|
@ -101,7 +101,7 @@ package org.gestouch.gestures
|
|||
return;
|
||||
|
||||
uninstallTarget(target);
|
||||
_targetAdapter = value ? _gesturesManager.gestouch_internal::createGestureTargetAdapter(value) : null;
|
||||
_targetAdapter = value ? Gestouch.gestouch_internal::createGestureTargetAdapter(value) : null;
|
||||
installTarget(value);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue