Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update for API changes (0.4.1)

  • Loading branch information...
commit 9291b34433ceeda36281baf12c27eb16dc162279 1 parent ae0e7f1
@fljot authored
View
69 src/org/gestouch/examples/starling/ConflictGesturesExample.as
@@ -1,21 +1,19 @@
package org.gestouch.examples.starling
{
- import com.greensock.easing.Linear;
- import com.greensock.TweenLite;
import starling.core.Starling;
import starling.display.DisplayObject;
import starling.display.Image;
import starling.display.Sprite;
import starling.textures.Texture;
+ import com.greensock.TweenLite;
import com.greensock.TweenMax;
+ import com.greensock.easing.Linear;
import org.gestouch.core.GestureState;
import org.gestouch.core.IGestureDelegate;
import org.gestouch.core.Touch;
- import org.gestouch.events.LongPressGestureEvent;
- import org.gestouch.events.TapGestureEvent;
- import org.gestouch.events.TransformGestureEvent;
+ import org.gestouch.events.GestureEvent;
import org.gestouch.gestures.Gesture;
import org.gestouch.gestures.LongPressGesture;
import org.gestouch.gestures.TapGesture;
@@ -59,7 +57,7 @@ package org.gestouch.examples.starling
addChild(container);
var freeTransform:TransformGesture = new TransformGesture(stage);
- freeTransform.addEventListener(TransformGestureEvent.GESTURE_TRANSFORM, onTransform, false, 0, true);
+ freeTransform.addEventListener(GestureEvent.GESTURE_STATE_CHANGE, onTransform, false, 0, true);
freeTransform.delegate = this;
var image:Image;
@@ -78,13 +76,15 @@ package org.gestouch.examples.starling
// native stage still acts as the parent of everything
var longPress:LongPressGesture = new LongPressGesture(Starling.current.nativeStage);
- longPress.addEventListener(LongPressGestureEvent.GESTURE_LONG_PRESS, onLongPress);
+ longPress.addEventListener(GestureEvent.GESTURE_STATE_CHANGE, onLongPress);
}
- private function onLongPress(event:LongPressGestureEvent):void
+ private function onLongPress(event:GestureEvent):void
{
- if (event.gestureState != GestureState.BEGAN)
+ const gesture:LongPressGesture = event.target as LongPressGesture;
+
+ if (event.newState != GestureState.BEGAN)
return;
const circle:Shape = new Shape();
@@ -93,8 +93,9 @@ package org.gestouch.examples.starling
g.drawCircle(0, 0, 100);
g.endFill();
Starling.current.nativeStage.addChild(circle);
- circle.x = event.stageX;
- circle.y = event.stageY;
+ const location:Point = gesture.location;
+ circle.x = location.x;
+ circle.y = location.y;
TweenLite.to(circle, 0.5, {
alpha: 0,
scaleX: 0,
@@ -112,68 +113,66 @@ package org.gestouch.examples.starling
image.width = image.height = Math.min(stage.stageWidth, stage.stageHeight) / 3;
var tap:TapGesture = new TapGesture(image);
- tap.addEventListener(TapGestureEvent.GESTURE_TAP, onTap, false, 0, true);
+ tap.addEventListener(GestureEvent.GESTURE_RECOGNIZED, onTap, false, 0, true);
var freeTransform:TransformGesture = new TransformGesture(image);
- freeTransform.addEventListener(TransformGestureEvent.GESTURE_TRANSFORM, onTransform, false, 0, true);
+ freeTransform.addEventListener(GestureEvent.GESTURE_STATE_CHANGE, onTransform, false, 0, true);
freeTransform.delegate = this;
return image;
}
- private function onTransform(event:TransformGestureEvent):void
+ private function onTransform(event:GestureEvent):void
{
- var target:DisplayObject = (event.target as Gesture).target as DisplayObject;
+ const gesture:TransformGesture = event.target as TransformGesture;
+ var target:DisplayObject = gesture.target as DisplayObject;
+ var offsetX:Number = gesture.offsetX;
+ var offsetY:Number = gesture.offsetY;
+
if (target == stage)
{
target = container;
- if (event.gestureState == GestureState.BEGAN)
+ if (event.newState == GestureState.BEGAN)
{
containerIsTransforming = true;
}
- else if (event.gestureState == GestureState.ENDED || event.gestureState == GestureState.CANCELLED)
+ else if (event.newState == GestureState.ENDED || event.newState == GestureState.CANCELLED)
{
containerIsTransforming = false;
}
}
else
{
- if (event.gestureState == GestureState.BEGAN)
+ if (event.newState == GestureState.BEGAN)
{
innerActiveTransformGesturesCounter++;
}
- else if (event.gestureState == GestureState.ENDED || event.gestureState == GestureState.CANCELLED)
+ else if (event.newState == GestureState.ENDED || event.newState == GestureState.CANCELLED)
{
innerActiveTransformGesturesCounter--;
}
// Recalculate offsets in case some parent is transformed
- if (event.offsetX != 0 || event.offsetY != 0)
- {
- var offset:Point = target.parent.globalToLocal(new Point(event.offsetX, event.offsetY)).subtract(target.parent.globalToLocal(GestureUtils.GLOBAL_ZERO));
- event.offsetX = offset.x;
- event.offsetY = offset.y;
- }
+ var offset:Point = target.parent.globalToLocal(new Point(offsetX, offsetY)).subtract(target.parent.globalToLocal(GestureUtils.GLOBAL_ZERO));
+ offsetX = offset.x;
+ offsetY = offset.y;
}
// Panning
- target.x += event.offsetX;
- target.y += event.offsetY;
+ target.x += offsetX;
+ target.y += offsetY;
- if (event.scaleX != 1 || event.rotation != 0)
+ if (gesture.scale != 1 || gesture.rotation != 0)
{
var m:Matrix = target.getTransformationMatrix(target.parent);
// Scale and rotation.
- // NB! event.localX and event.stageX actually represent previous
- // location of the centroid (middle point between two fingers so you
- // can easely perform these transformations without any additional transformations.
- var transformPoint:Point = m.transformPoint(new Point(event.localX, event.localY));
+ var transformPoint:Point = m.transformPoint(target.globalToLocal(gesture.location));
m.translate(-transformPoint.x, -transformPoint.y);
- m.rotate(event.rotation);
- m.scale(event.scaleX, event.scaleY);
+ m.rotate(gesture.rotation);
+ m.scale(gesture.scale, gesture.scale);
m.translate(transformPoint.x, transformPoint.y);
target.x = m.tx;
@@ -184,7 +183,7 @@ package org.gestouch.examples.starling
}
- private function onTap(event:TapGestureEvent):void
+ private function onTap(event:GestureEvent):void
{
trace("tap");
TweenMax.to((event.target as Gesture).target, 0.5, {bezierThrough:[{alpha:0.1}, {alpha:1}]});
View
8 src/org/gestouch/examples/starling/TransformedViewportExample.as
@@ -1,12 +1,12 @@
package org.gestouch.examples.starling
{
- import starling.textures.Texture;
import starling.core.Starling;
import starling.display.Image;
+ import starling.textures.Texture;
import com.greensock.TweenMax;
- import org.gestouch.events.TapGestureEvent;
+ import org.gestouch.events.GestureEvent;
import org.gestouch.gestures.Gesture;
import org.gestouch.gestures.TapGesture;
@@ -50,11 +50,11 @@ package org.gestouch.examples.starling
addChild(image);
var tap:TapGesture = new TapGesture(image);
- tap.addEventListener(TapGestureEvent.GESTURE_TAP, onTap, false, 0, true);
+ tap.addEventListener(GestureEvent.GESTURE_RECOGNIZED, onTap, false, 0, true);
}
- private function onTap(event:TapGestureEvent):void
+ private function onTap(event:GestureEvent):void
{
trace("tap");
TweenMax.to((event.target as Gesture).target, 0.5, {bezierThrough:[{alpha:0.1}, {alpha:1}]});
View
73 src/org/gestouch/examples/views/ConflictGesturesView.mxml
@@ -11,11 +11,8 @@
<fx:Script>
<![CDATA[
- import org.gestouch.core.GestureState;
import org.gestouch.core.Touch;
- import org.gestouch.events.PanGestureEvent;
- import org.gestouch.events.RotateGestureEvent;
- import org.gestouch.events.ZoomGestureEvent;
+ import org.gestouch.events.GestureEvent;
import org.gestouch.gestures.Gesture;
import org.gestouch.gestures.PanGesture;
import org.gestouch.gestures.RotateGesture;
@@ -25,6 +22,7 @@
import mx.core.UIComponent;
+
private var gestures:Vector.<Gesture> = new Vector.<Gesture>();
@@ -65,12 +63,9 @@
override protected function onViewDeactivate():void
{
super.onViewDeactivate();
-
+
for each (var gesture:Gesture in gestures)
{
- gesture.removeEventListener(PanGestureEvent.GESTURE_PAN, onPan);
- gesture.removeEventListener(ZoomGestureEvent.GESTURE_ZOOM, onZoom);
- gesture.removeEventListener(RotateGestureEvent.GESTURE_ROTATE, onRotate);
gesture.dispose();
}
@@ -83,17 +78,20 @@
var pan:PanGesture = new PanGesture(target);
pan.maxNumTouchesRequired = 2;
pan.delegate = this;
- pan.addEventListener(PanGestureEvent.GESTURE_PAN, onPan);
+ pan.addEventListener(org.gestouch.events.GestureEvent.GESTURE_BEGAN, onPan);
+ pan.addEventListener(org.gestouch.events.GestureEvent.GESTURE_CHANGED, onPan);
gestures.push(pan);
var zoom:ZoomGesture = new ZoomGesture(target);
- zoom.addEventListener(ZoomGestureEvent.GESTURE_ZOOM, onZoom);
+ zoom.addEventListener(org.gestouch.events.GestureEvent.GESTURE_BEGAN, onZoom);
+ zoom.addEventListener(org.gestouch.events.GestureEvent.GESTURE_CHANGED, onZoom);
zoom.delegate = this;
gestures.push(zoom);
var rotate:RotateGesture = new RotateGesture(target);
rotate.delegate = this;
- rotate.addEventListener(RotateGestureEvent.GESTURE_ROTATE, onRotate);
+ rotate.addEventListener(org.gestouch.events.GestureEvent.GESTURE_BEGAN, onRotate);
+ rotate.addEventListener(org.gestouch.events.GestureEvent.GESTURE_CHANGED, onRotate);
gestures.push(rotate);
if (target is Image)
@@ -104,49 +102,40 @@
}
- private function onPan(event:PanGestureEvent):void
+ private function onPan(event:org.gestouch.events.GestureEvent):void
{
- var gesture:PanGesture = event.target as PanGesture;
- var target:UIComponent = gesture.target as UIComponent;
+ const gesture:PanGesture = event.target as PanGesture;
+ const target:UIComponent = gesture.target as UIComponent;
- if (event.gestureState == GestureState.BEGAN || event.gestureState == GestureState.CHANGED)
- {
- target.move(target.x + event.offsetX, target.y + event.offsetY);
- }
+ target.move(target.x + gesture.offsetX, target.y + gesture.offsetY);
}
- private function onZoom(event:ZoomGestureEvent):void
+ private function onZoom(event:org.gestouch.events.GestureEvent):void
{
- var gesture:ZoomGesture = event.target as ZoomGesture;
- var target:UIComponent = gesture.target as UIComponent;
+ const gesture:ZoomGesture = event.target as ZoomGesture;
+ const target:UIComponent = gesture.target as UIComponent;
- if (event.scaleX != 1 || event.scaleY != 1)
- {
- var matrix:Matrix = target.transform.matrix;
- var transformPoint:Point = matrix.transformPoint(target.globalToLocal(gesture.location));
- matrix.translate(-transformPoint.x, -transformPoint.y);
- matrix.scale(event.scaleX, event.scaleY);
- matrix.translate(transformPoint.x, transformPoint.y);
- target.transform.matrix = matrix;
- }
+ var matrix:Matrix = target.transform.matrix;
+ var transformPoint:Point = matrix.transformPoint(target.globalToLocal(gesture.location));
+ matrix.translate(-transformPoint.x, -transformPoint.y);
+ matrix.scale(gesture.scaleX, gesture.scaleY);
+ matrix.translate(transformPoint.x, transformPoint.y);
+ target.transform.matrix = matrix;
}
- private function onRotate(event:RotateGestureEvent):void
+ private function onRotate(event:org.gestouch.events.GestureEvent):void
{
- var gesture:RotateGesture = event.target as RotateGesture;
- var target:UIComponent = gesture.target as UIComponent;
+ const gesture:RotateGesture = event.target as RotateGesture;
+ const target:UIComponent = gesture.target as UIComponent;
- if (event.rotation != 0)
- {
- var matrix:Matrix = target.transform.matrix;
- var transformPoint:Point = matrix.transformPoint(target.globalToLocal(gesture.location));
- matrix.translate(-transformPoint.x, -transformPoint.y);
- matrix.rotate(event.rotation);
- matrix.translate(transformPoint.x, transformPoint.y);
- target.transform.matrix = matrix;
- }
+ var matrix:Matrix = target.transform.matrix;
+ var transformPoint:Point = matrix.transformPoint(target.globalToLocal(gesture.location));
+ matrix.translate(-transformPoint.x, -transformPoint.y);
+ matrix.rotate(gesture.rotation);
+ matrix.translate(transformPoint.x, transformPoint.y);
+ target.transform.matrix = matrix;
}
]]>
</fx:Script>
View
25 src/org/gestouch/examples/views/DependentSwipingGesturesView.mxml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<views:ExampleViewBase xmlns:fx="http://ns.adobe.com/mxml/2009"
- xmlns:s="library://ns.adobe.com/flex/spark"
+ xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:views="org.gestouch.examples.views.*"
xmlns:controls="org.gestouch.examples.controls.*"
@@ -11,9 +11,9 @@
<fx:Script>
<![CDATA[
import com.greensock.TweenMax;
+
import org.gestouch.core.Touch;
- import org.gestouch.events.PanGestureEvent;
- import org.gestouch.events.SwipeGestureEvent;
+ import org.gestouch.events.GestureEvent;
import org.gestouch.gestures.Gesture;
import org.gestouch.gestures.PanGesture;
import org.gestouch.gestures.SwipeGesture;
@@ -56,7 +56,7 @@
//----------------------------------
-
+
override protected function init():void
{
super.init();
@@ -72,7 +72,7 @@
fillBitmapData.draw(bmd, new Matrix(10, 0, 0, 10));
}
-
+
override protected function onResize(width:Number, height:Number):void
{
super.onResize(width, height);
@@ -87,11 +87,12 @@
super.onViewActivate();
pan = new PanGesture(this);
- pan.addEventListener(PanGestureEvent.GESTURE_PAN, onPan);
+ pan.addEventListener(org.gestouch.events.GestureEvent.GESTURE_BEGAN, onPan);
+ pan.addEventListener(org.gestouch.events.GestureEvent.GESTURE_CHANGED, onPan);
pan.slop = 0;
swipe = new SwipeGesture(this);
- swipe.addEventListener(SwipeGestureEvent.GESTURE_SWIPE, onSwipe);
+ swipe.addEventListener(org.gestouch.events.GestureEvent.GESTURE_RECOGNIZED, onSwipe);
swipe.direction = SwipeGestureDirection.RIGHT;
swipe.delegate = this;
@@ -105,13 +106,11 @@
if (pan)
{
- pan.removeEventListener(PanGestureEvent.GESTURE_PAN, onPan);
pan.dispose();
pan = null;
}
if (swipe)
{
- swipe.removeEventListener(SwipeGestureEvent.GESTURE_SWIPE, onSwipe);
swipe.dispose();
swipe = null;
}
@@ -128,15 +127,15 @@
}
- private function onPan(event:PanGestureEvent):void
+ private function onPan(event:org.gestouch.events.GestureEvent):void
{
- trace("pan", event.gestureState);
- fillOffsetMatrix.translate(event.offsetX, event.offsetY);
+ trace("pan");
+ fillOffsetMatrix.translate(pan.offsetX, pan.offsetY);
updateFill();
}
- private function onSwipe(event:SwipeGestureEvent):void
+ private function onSwipe(event:org.gestouch.events.GestureEvent):void
{
trace("swipe");
TweenMax.to(menu, 1, {bezierThrough:[{scaleX:2}, {scaleX:1}]});
View
10 src/org/gestouch/examples/views/DependentTapGesturesView.mxml
@@ -11,7 +11,7 @@
<![CDATA[
import com.greensock.TweenMax;
- import org.gestouch.events.TapGestureEvent;
+ import org.gestouch.events.GestureEvent;
import org.gestouch.gestures.TapGesture;
@@ -24,10 +24,10 @@
super.onViewActivate();
singleTapGesture = new TapGesture(button);
- singleTapGesture.addEventListener(TapGestureEvent.GESTURE_TAP, onGesture);
+ singleTapGesture.addEventListener(org.gestouch.events.GestureEvent.GESTURE_RECOGNIZED, onGesture);
doubleTapGesture = new TapGesture(button);
- doubleTapGesture.addEventListener(TapGestureEvent.GESTURE_TAP, onGesture);
+ doubleTapGesture.addEventListener(org.gestouch.events.GestureEvent.GESTURE_RECOGNIZED, onGesture);
// probably you want to set a bit smaller value for maxTapDelay
// so double tap will fail a bit more quickly. default is 400ms
doubleTapGesture.maxTapDelay = 300;
@@ -43,20 +43,18 @@
if (singleTapGesture)
{
- singleTapGesture.removeEventListener(TapGestureEvent.GESTURE_TAP, onGesture);
singleTapGesture.dispose();
singleTapGesture = null;
}
if (doubleTapGesture)
{
- doubleTapGesture.removeEventListener(TapGestureEvent.GESTURE_TAP, onGesture);
doubleTapGesture.dispose();
doubleTapGesture = null;
}
}
- private function onGesture(event:TapGestureEvent):void
+ private function onGesture(event:org.gestouch.events.GestureEvent):void
{
var tapGesture:TapGesture = event.target as TapGesture;
if (tapGesture == singleTapGesture)
View
14 src/org/gestouch/examples/views/LongPressGestureAdvancedView.mxml
@@ -14,8 +14,10 @@
import com.greensock.plugins.TweenPlugin;
import org.gestouch.core.GestureState;
- import org.gestouch.events.LongPressGestureEvent;
+ import org.gestouch.events.GestureEvent;
+ import org.gestouch.gestures.Gesture;
import org.gestouch.gestures.LongPressGesture;
+
private var longPressGesture:LongPressGesture;
@@ -37,7 +39,7 @@
super.onViewActivate();
longPressGesture = new LongPressGesture(image);
- longPressGesture.addEventListener(LongPressGestureEvent.GESTURE_LONG_PRESS, onGesture);
+ longPressGesture.addEventListener(org.gestouch.events.GestureEvent.GESTURE_STATE_CHANGE, onGesture);
}
@@ -47,18 +49,18 @@
if (longPressGesture)
{
- longPressGesture.removeEventListener(LongPressGestureEvent.GESTURE_LONG_PRESS, onGesture);
longPressGesture.dispose();
longPressGesture = null;
}
}
- private function onGesture(event:LongPressGestureEvent):void
+ private function onGesture(event:org.gestouch.events.GestureEvent):void
{
- var loc:Point = globalToLocal(longPressGesture.location);
+ const gesture:Gesture = event.target as Gesture;
+ var loc:Point = globalToLocal(gesture.location);
- switch (event.gestureState)
+ switch (event.newState)
{
case GestureState.BEGAN:
initialTransform = image.transform.matrix;
View
24 src/org/gestouch/examples/views/LongPressGestureView.mxml
@@ -13,9 +13,9 @@
import com.greensock.plugins.GlowFilterPlugin;
import com.greensock.plugins.TweenPlugin;
- import org.gestouch.core.GestureState;
- import org.gestouch.events.LongPressGestureEvent;
+ import org.gestouch.events.GestureEvent;
import org.gestouch.gestures.LongPressGesture;
+
private var longPressGesture:LongPressGesture;
@@ -25,7 +25,7 @@
{
super.init();
- TweenPlugin.activate([GlowFilterPlugin]);
+ TweenPlugin.activate([GlowFilterPlugin]);
}
@@ -34,7 +34,7 @@
super.onViewActivate();
longPressGesture = new LongPressGesture(button);
- longPressGesture.addEventListener(LongPressGestureEvent.GESTURE_LONG_PRESS, onGesture);
+ longPressGesture.addEventListener(org.gestouch.events.GestureEvent.GESTURE_BEGAN, onGesture);
slopSlider.value = longPressGesture.slop;
touchesSlider.value = longPressGesture.numTouchesRequired;
@@ -48,22 +48,18 @@
if (longPressGesture)
{
- longPressGesture.removeEventListener(LongPressGestureEvent.GESTURE_LONG_PRESS, onGesture);
- longPressGesture.dispose();
+ longPressGesture.dispose();// all event listeners automatically removed
longPressGesture = null;
}
}
- private function onGesture(event:LongPressGestureEvent):void
+ private function onGesture(event:org.gestouch.events.GestureEvent):void
{
- if (event.gestureState == GestureState.BEGAN)
- {
- TweenMax.fromTo(button, 1,
- {glowFilter: {color: 0xCCCCCC * Math.random(), blurX: 64, blurY: 64, strength: 3, alpha: 1, quality: 1}},
- {glowFilter: {alpha: 0, remove: true}}
- );
- }
+ TweenMax.fromTo(button, 1,
+ {glowFilter: {color: 0xCCCCCC * Math.random(), blurX: 64, blurY: 64, strength: 3, alpha: 1, quality: 1}},
+ {glowFilter: {alpha: 0, remove: true}}
+ );
}
View
22 src/org/gestouch/examples/views/PanGestureView.mxml
@@ -9,26 +9,21 @@
<fx:Script>
<![CDATA[
- import org.gestouch.events.PanGestureEvent;
+ import org.gestouch.events.GestureEvent;
import org.gestouch.gestures.PanGesture;
private var pan:PanGesture;
- override protected function init():void
- {
- super.init();
- }
-
-
override protected function onViewActivate():void
{
super.onViewActivate();
pan = new PanGesture(image);
pan.maxNumTouchesRequired = 2;
- pan.addEventListener(PanGestureEvent.GESTURE_PAN, onPan);
+ pan.addEventListener(org.gestouch.events.GestureEvent.GESTURE_BEGAN, onPan);
+ pan.addEventListener(org.gestouch.events.GestureEvent.GESTURE_CHANGED, onPan);
slopSlider.value = pan.slop;
minNumTouchesSlider.value = pan.minNumTouchesRequired;
@@ -42,19 +37,16 @@
if (pan)
{
- pan.removeEventListener(PanGestureEvent.GESTURE_PAN, onPan);
- pan.dispose();
+ pan.dispose();// all event listeners automatically removed
pan = null;
}
}
- private function onPan(event:PanGestureEvent):void
+ private function onPan(event:org.gestouch.events.GestureEvent):void
{
- if (event.offsetX != 0 || event.offsetY != 0)
- {
- image.move(image.x + event.offsetX, image.y + event.offsetY);
- }
+ const gesture:PanGesture = event.target as PanGesture;
+ image.move(image.x + gesture.offsetX, image.y + gesture.offsetY);
}
View
38 src/org/gestouch/examples/views/RotateGestureView.mxml
@@ -11,22 +11,11 @@
<fx:Script>
<![CDATA[
- import com.greensock.plugins.GlowFilterPlugin;
- import com.greensock.plugins.TweenPlugin;
-
- import org.gestouch.events.RotateGestureEvent;
+ import org.gestouch.events.GestureEvent;
import org.gestouch.gestures.RotateGesture;
private var rotate:RotateGesture;
-
-
- override protected function init():void
- {
- super.init();
-
- TweenPlugin.activate([GlowFilterPlugin]);
- }
override protected function onViewActivate():void
@@ -34,7 +23,8 @@
super.onViewActivate();
rotate = new RotateGesture(image);
- rotate.addEventListener(RotateGestureEvent.GESTURE_ROTATE, onGesture);
+ rotate.addEventListener(org.gestouch.events.GestureEvent.GESTURE_BEGAN, onGesture);
+ rotate.addEventListener(org.gestouch.events.GestureEvent.GESTURE_CHANGED, onGesture);
}
@@ -44,26 +34,22 @@
if (rotate)
{
- rotate.removeEventListener(RotateGestureEvent.GESTURE_ROTATE, onGesture);
- rotate.dispose();
+ rotate.dispose();// all event listeners automatically removed
rotate = null;
}
}
- private function onGesture(event:RotateGestureEvent):void
+ private function onGesture(event:org.gestouch.events.GestureEvent):void
{
- var loc:Point = globalToLocal(rotate.location);
+ const gesture:RotateGesture = event.target as RotateGesture;
- if (event.rotation != 0)
- {
- var matrix:Matrix = image.transform.matrix;
- var transformPoint:Point = matrix.transformPoint(new Point(event.localX, event.localY));
- matrix.translate(-transformPoint.x, -transformPoint.y);
- matrix.rotate(event.rotation);
- matrix.translate(transformPoint.x, transformPoint.y);
- image.transform.matrix = matrix;
- }
+ var matrix:Matrix = image.transform.matrix;
+ var transformPoint:Point = matrix.transformPoint(image.globalToLocal(rotate.location));
+ matrix.translate(-transformPoint.x, -transformPoint.y);
+ matrix.rotate(gesture.rotation);
+ matrix.translate(transformPoint.x, transformPoint.y);
+ image.transform.matrix = matrix;
}
View
35 src/org/gestouch/examples/views/SwipeGestureView.mxml
@@ -9,15 +9,14 @@
<fx:Script>
<![CDATA[
- import org.gestouch.gestures.SwipeGestureDirection;
- import org.gestouch.core.GestureState;
- import org.gestouch.events.GestureStateEvent;
import com.greensock.TweenMax;
import com.greensock.easing.Sine;
- import org.gestouch.events.SwipeGestureEvent;
+ import org.gestouch.events.GestureEvent;
import org.gestouch.examples.controls.ArrowShape;
import org.gestouch.gestures.SwipeGesture;
+ import org.gestouch.gestures.SwipeGestureDirection;
+
private var arrow:ArrowShape;
@@ -41,8 +40,8 @@
super.onViewActivate();
swipe = new SwipeGesture(this);
- swipe.addEventListener(SwipeGestureEvent.GESTURE_SWIPE, onGesture);
- swipe.addEventListener(GestureStateEvent.STATE_CHANGE, onGestureStateChange);
+ swipe.addEventListener(org.gestouch.events.GestureEvent.GESTURE_RECOGNIZED, onGesture);
+ swipe.addEventListener(org.gestouch.events.GestureEvent.GESTURE_FAILED, onGestureStateChange);
minDistanceSlider.value = swipe.minOffset;
touchesSlider.value = swipe.numTouchesRequired;
@@ -61,8 +60,7 @@
if (swipe)
{
- swipe.removeEventListener(SwipeGestureEvent.GESTURE_SWIPE, onGesture);
- swipe.dispose();
+ swipe.dispose();// all event listeners automatically removed
swipe = null;
}
@@ -70,13 +68,15 @@
}
- private function onGesture(event:SwipeGestureEvent):void
+ private function onGesture(event:org.gestouch.events.GestureEvent):void
{
- arrow.scaleX = (event.offsetX < 0 && event.offsetY == 0 ? -1 : 1) * Math.abs(arrow.scaleX);
+ const gesture:SwipeGesture = event.target as SwipeGesture;
+
+ arrow.scaleX = (gesture.offsetX < 0 && gesture.offsetY == 0 ? -1 : 1) * Math.abs(arrow.scaleX);
var angle:int = 0;//event.offsetX == 0 ? (event.offsetY > 0 ? 90 : -90) : Math.atan(event.offsetY / event.offsetX) * 180 / Math.PI;
- if (event.offsetY != 0)
+ if (gesture.offsetY != 0)
{
- angle = event.offsetY > 0 ? 90 : -90;
+ angle = gesture.offsetY > 0 ? 90 : -90;
}
arrow.rotation = angle;
TweenMax.fromTo(arrow, 2, {alpha: 1}, {alpha: 0, ease: Sine.easeIn});
@@ -85,17 +85,14 @@
private function onNativeGesture(event:TransformGestureEvent):void
{
- onGesture(new SwipeGestureEvent(SwipeGestureEvent.GESTURE_SWIPE, false, false, GestureState.RECOGNIZED,
- event.stageX, event.stageY, event.localX, event.localY, event.offsetX, event.offsetY));
+// onGesture(new SwipeGestureEvent(SwipeGestureEvent.GESTURE_SWIPE, false, false, GestureState.RECOGNIZED,
+// event.stageX, event.stageY, event.localX, event.localY, event.offsetX, event.offsetY));
}
- private function onGestureStateChange(event:GestureStateEvent):void
+ private function onGestureStateChange(event:org.gestouch.events.GestureEvent):void
{
- if (event.newState == GestureState.FAILED)
- {
- TweenMax.fromTo(failedGraphic, 1, {alpha: 1}, {alpha: 0, ease: Sine.easeIn});
- }
+ TweenMax.fromTo(failedGraphic, 1, {alpha: 1}, {alpha: 0, ease: Sine.easeIn});
}
View
24 src/org/gestouch/examples/views/TapGestureUsageView.mxml
@@ -10,23 +10,13 @@
<fx:Script>
<![CDATA[
import com.greensock.TweenMax;
- import com.greensock.plugins.GlowFilterPlugin;
- import com.greensock.plugins.TweenPlugin;
- import org.gestouch.events.TapGestureEvent;
+ import org.gestouch.events.GestureEvent;
import org.gestouch.gestures.TapGesture;
private var doubleTapGesture:TapGesture;
private var twoFingerTapGesture:TapGesture;
-
-
- override protected function init():void
- {
- super.init();
-
- TweenPlugin.activate([GlowFilterPlugin]);
- }
override protected function onViewActivate():void
@@ -35,11 +25,11 @@
doubleTapGesture = new TapGesture(button);
doubleTapGesture.numTapsRequired = 2;
- doubleTapGesture.addEventListener(TapGestureEvent.GESTURE_TAP, onGesture);
+ doubleTapGesture.addEventListener(org.gestouch.events.GestureEvent.GESTURE_RECOGNIZED, onGesture);
twoFingerTapGesture = new TapGesture(button);
twoFingerTapGesture.numTouchesRequired = 2;
- twoFingerTapGesture.addEventListener(TapGestureEvent.GESTURE_TAP, onGesture);
+ twoFingerTapGesture.addEventListener(org.gestouch.events.GestureEvent.GESTURE_RECOGNIZED, onGesture);
}
@@ -49,20 +39,18 @@
if (doubleTapGesture)
{
- doubleTapGesture.removeEventListener(TapGestureEvent.GESTURE_TAP, onGesture);
- doubleTapGesture.dispose();
+ doubleTapGesture.dispose();// all event listeners automatically removed
doubleTapGesture = null;
}
if (twoFingerTapGesture)
{
- twoFingerTapGesture.removeEventListener(TapGestureEvent.GESTURE_TAP, onGesture);
- twoFingerTapGesture.dispose();
+ twoFingerTapGesture.dispose();// all event listeners automatically removed
twoFingerTapGesture = null;
}
}
- private function onGesture(event:TapGestureEvent):void
+ private function onGesture(event:org.gestouch.events.GestureEvent):void
{
var gesture:TapGesture = event.target as TapGesture;
var scale:Number;
View
21 src/org/gestouch/examples/views/TapGestureView.mxml
@@ -21,6 +21,20 @@
TweenPlugin.activate([GlowFilterPlugin]);
}
+
+
+ override protected function onViewDeactivate():void
+ {
+ super.onViewDeactivate();
+
+ if (tap)
+ {
+ tap.removeAllEventListeners();
+ // Do not dispose it because view can be activated again.
+ // Removing all event listeners is enough for it to be GC-ed
+ // as soon as this view is GC-ed.
+ }
+ }
]]>
</fx:Script>
@@ -65,12 +79,15 @@
numTapsRequired="@{tapsSlider.value}"
numTouchesRequired="@{touchesSlider.value}"
>
- <gestures:gestureTap><![CDATA[
+ <gestures:gestureStateChange>
+ trace("gesture state changed from " + event.oldState + " to " + event.newState);
+ </gestures:gestureStateChange>
+ <gestures:gestureRecognized><![CDATA[
TweenMax.fromTo(button, 1,
{glowFilter: {color: 0xCCCCCC * Math.random(), blurX: 64, blurY: 64, strength: 3, alpha: 1, quality: 1}},
{glowFilter: {alpha: 0, remove: true}}
);
- ]]></gestures:gestureTap>
+ ]]></gestures:gestureRecognized>
</gestures:TapGesture>
</fx:Declarations>
View
41 src/org/gestouch/examples/views/TransformGestureView.mxml
@@ -11,8 +11,7 @@
<fx:Script>
<![CDATA[
- import org.gestouch.core.GestureState;
- import org.gestouch.events.TransformGestureEvent;
+ import org.gestouch.events.GestureEvent;
import org.gestouch.gestures.TransformGesture;
@@ -24,7 +23,8 @@
super.onViewActivate();
transformGesture = new TransformGesture(image);
- transformGesture.addEventListener(org.gestouch.events.TransformGestureEvent.GESTURE_TRANSFORM, onGesture);
+ transformGesture.addEventListener(org.gestouch.events.GestureEvent.GESTURE_BEGAN, onGesture);
+ transformGesture.addEventListener(org.gestouch.events.GestureEvent.GESTURE_CHANGED, onGesture);
}
@@ -34,34 +34,29 @@
if (transformGesture)
{
- transformGesture.removeEventListener(org.gestouch.events.TransformGestureEvent.GESTURE_TRANSFORM, onGesture);
transformGesture.dispose();
transformGesture = null;
}
}
- private function onGesture(event:org.gestouch.events.TransformGestureEvent):void
+ private function onGesture(event:org.gestouch.events.GestureEvent):void
{
- if (event.gestureState == GestureState.BEGAN || event.gestureState == GestureState.CHANGED)
+ const gesture:TransformGesture = event.target as TransformGesture;
+ var matrix:Matrix = image.transform.matrix;
+
+ // Panning
+ matrix.translate(gesture.offsetX, gesture.offsetY);
+ image.transform.matrix = matrix;
+
+ if (gesture.scale != 1 || gesture.rotation != 0)
{
- var matrix:Matrix = image.transform.matrix;
-
- // Panning
- matrix.translate(event.offsetX, event.offsetY);
-
- if (event.scaleX != 1 || event.rotation != 0)
- {
- // Scale and rotation.
- // NB! event.localX and event.stageX actually represent previous
- // location of the centroid (middle point between two fingers so you
- // can easely perform these transformations without any additional transformations.
- var transformPoint:Point = matrix.transformPoint(new Point(event.localX, event.localY));
- matrix.translate(-transformPoint.x, -transformPoint.y);
- matrix.rotate(event.rotation);
- matrix.scale(event.scaleX, event.scaleY);
- matrix.translate(transformPoint.x, transformPoint.y);
- }
+ // Scale and rotation.
+ var transformPoint:Point = matrix.transformPoint(image.globalToLocal(gesture.location));
+ matrix.translate(-transformPoint.x, -transformPoint.y);
+ matrix.rotate(gesture.rotation);
+ matrix.scale(gesture.scale, gesture.scale);
+ matrix.translate(transformPoint.x, transformPoint.y);
image.transform.matrix = matrix;
}
View
27 src/org/gestouch/examples/views/ZoomGestureView.mxml
@@ -11,7 +11,7 @@
<fx:Script>
<![CDATA[
- import org.gestouch.events.ZoomGestureEvent;
+ import org.gestouch.events.GestureEvent;
import org.gestouch.gestures.ZoomGesture;
@@ -23,7 +23,8 @@
super.onViewActivate();
zoom = new ZoomGesture(image);
- zoom.addEventListener(ZoomGestureEvent.GESTURE_ZOOM, onGesture);
+ zoom.addEventListener(org.gestouch.events.GestureEvent.GESTURE_BEGAN, onGesture);
+ zoom.addEventListener(org.gestouch.events.GestureEvent.GESTURE_CHANGED, onGesture);
}
@@ -33,26 +34,22 @@
if (zoom)
{
- zoom.removeEventListener(ZoomGestureEvent.GESTURE_ZOOM, onGesture);
- zoom.dispose();
+ zoom.dispose();// all event listeners automatically removed
zoom = null;
}
}
- private function onGesture(event:ZoomGestureEvent):void
+ private function onGesture(event:org.gestouch.events.GestureEvent):void
{
-// var loc:Point = globalToLocal(zoom.location);
+ const gesture:ZoomGesture = event.target as ZoomGesture;
- if (event.scaleX != 1 || event.scaleY)
- {
- var matrix:Matrix = image.transform.matrix;
- var transformPoint:Point = matrix.transformPoint(new Point(event.localX, event.localY));
- matrix.translate(-transformPoint.x, -transformPoint.y);
- matrix.scale(event.scaleX, event.scaleY);
- matrix.translate(transformPoint.x, transformPoint.y);
- image.transform.matrix = matrix;
- }
+ var matrix:Matrix = image.transform.matrix;
+ var transformPoint:Point = matrix.transformPoint(image.globalToLocal(zoom.location));
+ matrix.translate(-transformPoint.x, -transformPoint.y);
+ matrix.scale(gesture.scaleX, gesture.scaleY);
+ matrix.translate(transformPoint.x, transformPoint.y);
+ image.transform.matrix = matrix;
}
Please sign in to comment.
Something went wrong with that request. Please try again.