Permalink
Browse files

For v0.4.1

  • Loading branch information...
2 parents 4d35bbc + 9291b34 commit 836151a196518dbb57eeafa0116ccd7c14f20f12 @fljot committed Aug 27, 2012
@@ -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}]});
@@ -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}]});
@@ -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>
Oops, something went wrong.

0 comments on commit 836151a

Please sign in to comment.