Compare commits
10 commits
Author | SHA1 | Date | |
---|---|---|---|
|
319c6a2602 | ||
|
16c24d5e29 | ||
|
8c815c4e14 | ||
|
c7278faa7d | ||
|
e696ed6e98 | ||
|
6fd8baacbf | ||
|
e2831d9dbd | ||
|
89e3acf473 | ||
|
55294a9bf0 | ||
|
e33887befa |
8 changed files with 68 additions and 27 deletions
src/org/gestouch
|
@ -45,14 +45,14 @@ package org.gestouch.core
|
||||||
*/
|
*/
|
||||||
public static function get touchesManager():TouchesManager
|
public static function get touchesManager():TouchesManager
|
||||||
{
|
{
|
||||||
return _touchesManager ||= new TouchesManager(gesturesManager);
|
return _touchesManager ? _touchesManager : _touchesManager = new TouchesManager(gesturesManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static var _gesturesManager:GesturesManager;
|
private static var _gesturesManager:GesturesManager;
|
||||||
public static function get gesturesManager():GesturesManager
|
public static function get gesturesManager():GesturesManager
|
||||||
{
|
{
|
||||||
return _gesturesManager ||= new GesturesManager();
|
return _gesturesManager ? _gesturesManager : _gesturesManager = new GesturesManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -106,6 +106,12 @@ package org.gestouch.core
|
||||||
|
|
||||||
gestouch_internal static function getDisplayListAdapter(object:Object):IDisplayListAdapter
|
gestouch_internal static function getDisplayListAdapter(object:Object):IDisplayListAdapter
|
||||||
{
|
{
|
||||||
|
// Try to find use the object's final class
|
||||||
|
var dla:IDisplayListAdapter = _displayListAdaptersMap[object.constructor as Class];
|
||||||
|
if (dla) {
|
||||||
|
return dla;
|
||||||
|
}
|
||||||
|
|
||||||
for (var key:Object in _displayListAdaptersMap)
|
for (var key:Object in _displayListAdaptersMap)
|
||||||
{
|
{
|
||||||
var targetClass:Class = key as Class;
|
var targetClass:Class = key as Class;
|
||||||
|
|
|
@ -48,7 +48,7 @@ package org.gestouch.core
|
||||||
{
|
{
|
||||||
_stage = stage;
|
_stage = stage;
|
||||||
|
|
||||||
Gestouch.inputAdapter ||= new NativeInputAdapter(stage);
|
if (!Gestouch.inputAdapter) Gestouch.inputAdapter = new NativeInputAdapter(stage);
|
||||||
Gestouch.addTouchHitTester(new NativeTouchHitTester(stage));
|
Gestouch.addTouchHitTester(new NativeTouchHitTester(stage));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,7 +217,7 @@ package org.gestouch.core
|
||||||
{
|
{
|
||||||
throw new Error("Display list adapter not found for target of type '" + getQualifiedClassName(target) + "'.");
|
throw new Error("Display list adapter not found for target of type '" + getQualifiedClassName(target) + "'.");
|
||||||
}
|
}
|
||||||
const hierarchy:Vector.<Object> = displayListAdapter.getHierarchy(target);
|
const hierarchy:Vector.<Object> = displayListAdapter.getHierarchy(target, touch);
|
||||||
const hierarchyLength:uint = hierarchy.length;
|
const hierarchyLength:uint = hierarchy.length;
|
||||||
if (hierarchyLength == 0)
|
if (hierarchyLength == 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package org.gestouch.core
|
package org.gestouch.core
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @author Pavel fljot
|
* @author Pavel fljot
|
||||||
*/
|
*/
|
||||||
public interface IDisplayListAdapter extends IGestureTargetAdapter
|
public interface IDisplayListAdapter extends IGestureTargetAdapter
|
||||||
{
|
{
|
||||||
function getHierarchy(target:Object):Vector.<Object>;
|
function getHierarchy(target:Object, touch:Touch):Vector.<Object>;
|
||||||
|
|
||||||
function reflect():Class;
|
function reflect():Class;
|
||||||
}
|
}
|
||||||
|
|
|
@ -176,7 +176,37 @@ package org.gestouch.core
|
||||||
const touch:Touch = _touchesMap[touchID] as Touch;
|
const touch:Touch = _touchesMap[touchID] as Touch;
|
||||||
if (!touch)
|
if (!touch)
|
||||||
return;// touch with specified ID isn't registered
|
return;// touch with specified ID isn't registered
|
||||||
|
|
||||||
|
var target:Object;
|
||||||
|
var altTarget:Object;
|
||||||
|
var location:Point = new Point(x, y);
|
||||||
|
for each (var hitTester:ITouchHitTester in _hitTesters)
|
||||||
|
{
|
||||||
|
target = hitTester.hitTest(location);
|
||||||
|
if (target)
|
||||||
|
{
|
||||||
|
if ((target is Stage))
|
||||||
|
{
|
||||||
|
// NB! Target is flash.display::Stage is a special case. If it is true, we want
|
||||||
|
// to give a try to a lower-priority (Stage3D) hit-testers.
|
||||||
|
altTarget = target;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// We found a target.
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!target && !altTarget)
|
||||||
|
{
|
||||||
|
throw new Error("Not touch target found (hit test)." +
|
||||||
|
"Something is wrong, at least flash.display::Stage should be found." +
|
||||||
|
"See Gestouch#addTouchHitTester() and Gestouch#inputAdapter.");
|
||||||
|
}
|
||||||
|
|
||||||
|
touch.target = target || altTarget;
|
||||||
touch.updateLocation(x, y, getTimer());
|
touch.updateLocation(x, y, getTimer());
|
||||||
|
|
||||||
delete _touchesMap[touchID];
|
delete _touchesMap[touchID];
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
package org.gestouch.extensions.native
|
package org.gestouch.extensions.native
|
||||||
{
|
{
|
||||||
import flash.display.DisplayObject;
|
import flash.display.DisplayObject;
|
||||||
import flash.display.DisplayObjectContainer;
|
import flash.display.DisplayObjectContainer;
|
||||||
import flash.display.Stage;
|
import flash.display.Stage;
|
||||||
import flash.geom.Point;
|
import flash.utils.Dictionary;
|
||||||
import flash.utils.Dictionary;
|
|
||||||
import org.gestouch.core.IDisplayListAdapter;
|
|
||||||
|
|
||||||
|
import org.gestouch.core.IDisplayListAdapter;
|
||||||
|
import org.gestouch.core.Touch;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Pavel fljot
|
* @author Pavel fljot
|
||||||
*/
|
*/
|
||||||
final public class NativeDisplayListAdapter implements IDisplayListAdapter
|
final public class NativeDisplayListAdapter implements IDisplayListAdapter
|
||||||
|
@ -74,11 +74,11 @@ package org.gestouch.extensions.native
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getHierarchy(genericTarget:Object):Vector.<Object>
|
public function getHierarchy(genericObj:Object, touch:Touch):Vector.<Object>
|
||||||
{
|
{
|
||||||
var list:Vector.<Object> = new Vector.<Object>();
|
var list:Vector.<Object> = new Vector.<Object>();
|
||||||
var i:uint = 0;
|
var i:uint = 0;
|
||||||
var target:DisplayObject = genericTarget as DisplayObject;
|
var target:DisplayObject = genericObj as DisplayObject;
|
||||||
while (target)
|
while (target)
|
||||||
{
|
{
|
||||||
list[i] = target;
|
list[i] = target;
|
||||||
|
|
|
@ -1,14 +1,11 @@
|
||||||
package org.gestouch.extensions.starling
|
package org.gestouch.extensions.starling
|
||||||
{
|
{
|
||||||
import starling.display.DisplayObject;
|
import flash.utils.Dictionary;
|
||||||
import starling.display.DisplayObjectContainer;
|
|
||||||
|
|
||||||
import org.gestouch.core.IDisplayListAdapter;
|
import org.gestouch.core.IDisplayListAdapter;
|
||||||
|
import org.gestouch.core.Touch;
|
||||||
|
|
||||||
import flash.utils.Dictionary;
|
/**
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Pavel fljot
|
* @author Pavel fljot
|
||||||
*/
|
*/
|
||||||
final public class StarlingDisplayListAdapter implements IDisplayListAdapter
|
final public class StarlingDisplayListAdapter implements IDisplayListAdapter
|
||||||
|
@ -44,11 +41,11 @@ package org.gestouch.extensions.starling
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getHierarchy(genericTarget:Object):Vector.<Object>
|
public function getHierarchy(target:Object, touch:Touch):Vector.<Object>
|
||||||
{
|
{
|
||||||
var list:Vector.<Object> = new Vector.<Object>();
|
var list:Vector.<Object> = new Vector.<Object>();
|
||||||
var i:uint = 0;
|
var i:uint = 0;
|
||||||
var target:DisplayObject = genericTarget as DisplayObject;
|
var target:DisplayObject = target as DisplayObject;
|
||||||
while (target)
|
while (target)
|
||||||
{
|
{
|
||||||
list[i] = target;
|
list[i] = target;
|
||||||
|
|
|
@ -51,7 +51,7 @@ package org.gestouch.gestures
|
||||||
* (not an accidental offset on touch),
|
* (not an accidental offset on touch),
|
||||||
* based on 20 pixels on a 252ppi device.
|
* based on 20 pixels on a 252ppi device.
|
||||||
*/
|
*/
|
||||||
public static var DEFAULT_SLOP:uint = Math.round(20 / 252 * flash.system.Capabilities.screenDPI);
|
public static var DEFAULT_SLOP:uint = Math.round(10 / 252 * flash.system.Capabilities.screenDPI);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If a gesture should receive a touch.
|
* If a gesture should receive a touch.
|
||||||
|
|
|
@ -28,6 +28,7 @@ package org.gestouch.gestures
|
||||||
protected var _numTouchesRequiredReached:Boolean;
|
protected var _numTouchesRequiredReached:Boolean;
|
||||||
protected var _tapCounter:uint = 0;
|
protected var _tapCounter:uint = 0;
|
||||||
protected var _touchBeginLocations:Vector.<Point> = new Vector.<Point>();
|
protected var _touchBeginLocations:Vector.<Point> = new Vector.<Point>();
|
||||||
|
protected var firstTouchTarget:Object;
|
||||||
|
|
||||||
|
|
||||||
public function TapGesture(target:Object = null)
|
public function TapGesture(target:Object = null)
|
||||||
|
@ -102,6 +103,7 @@ package org.gestouch.gestures
|
||||||
_timer.reset();
|
_timer.reset();
|
||||||
_timer.delay = maxTapDuration;
|
_timer.delay = maxTapDuration;
|
||||||
_timer.start();
|
_timer.start();
|
||||||
|
firstTouchTarget = touch.target;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numTapsRequired > 1)
|
if (numTapsRequired > 1)
|
||||||
|
@ -155,17 +157,23 @@ package org.gestouch.gestures
|
||||||
if (!_numTouchesRequiredReached)
|
if (!_numTouchesRequiredReached)
|
||||||
{
|
{
|
||||||
setState(GestureState.FAILED);
|
setState(GestureState.FAILED);
|
||||||
|
firstTouchTarget = null;
|
||||||
}
|
}
|
||||||
else if (touchesCount == 0)
|
else if (touchesCount == 0)
|
||||||
{
|
{
|
||||||
// reset flag for the next "full press" cycle
|
// reset flag for the next "full press" cycle
|
||||||
_numTouchesRequiredReached = false;
|
_numTouchesRequiredReached = false;
|
||||||
|
|
||||||
_tapCounter++;
|
_tapCounter++;
|
||||||
_timer.reset();
|
_timer.reset();
|
||||||
|
|
||||||
if (_tapCounter == numTapsRequired)
|
if (_tapCounter == numTapsRequired)
|
||||||
{
|
{
|
||||||
|
if (numTouchesRequired == 1 && firstTouchTarget && touch.target != firstTouchTarget) {
|
||||||
|
firstTouchTarget = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setState(GestureState.RECOGNIZED);
|
setState(GestureState.RECOGNIZED);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Reference in a new issue