Skip to content

Commit 595d6ab

Browse files
committed
v0.4.1
2 parents b445a5c + 3081c80 commit 595d6ab

26 files changed

Lines changed: 375 additions & 717 deletions

README.textile

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,33 +31,43 @@ Features:
3131

3232

3333

34-
h3. Current state of the project
34+
h3. Getting Started
3535

36-
v0.3 introduces "new architecture". I'm planning to develop everything in develop branch and merge to master only release versions. Release versions suppose to be pretty stable. As much as I test them on the examples project.
37-
Current plan is to fix possible bugs in v0.3.#, and I really want to introduce Stage3D support in v0.4. So watch both branches.
38-
And I hope people to become giving some real feedback at least.
36+
All gestures dispatch (if you listen) GestureEvent with the next types:
37+
GestureEvent.GESTURE_STATE_CHANGE
38+
GestureEvent.GESTURE_IDLE
39+
GestureEvent.GESTURE_POSSIBLE
40+
GestureEvent.GESTURE_FAILED
3941

42+
Discrete gestures also dispatch:
43+
GestureEvent.GESTURE_RECOGNIZED
4044

45+
Continuous gestures also dispatch:
46+
GestureEvent.GESTURE_BEGAN
47+
GestureEvent.GESTURE_CHANGED
48+
GestureEvent.GESTURE_ENDED
4149

42-
h3. Getting Started
50+
If you use a good IDE (such as Intellij IDEA, FDT, FlashDevelop, Flash Builder) you should see these events in autocompletion.
4351

44-
Like so:
52+
Quick start:
4553
<pre><code>var doubleTap:TapGesture = new TapGesture(myButton);
4654
doubleTap.numTapsRequired = 2;
47-
doubleTap.addEventListener(TapGestureEvent.GESTURE_TAP, onDoubleTap);
55+
doubleTap.addEventListener(GestureEvent.GESTURE_RECOGNIZED, onDoubleTap);
4856
...
49-
private function onDoubleTap(event:TapGestureEvent):void
57+
private function onDoubleTap(event:GestureEvent):void
5058
{
5159
// handle double tap!
5260
}
5361
</code></pre>
5462
or
5563
<pre><code>var freeTransform:TransformGesture = new TransformGesture(myImage);
56-
freeTransform.addEventListener(TransformGestureEvent.GESTURE_TRANSFORM, onFreeTransform);
64+
freeTransform.addEventListener(GestureEvent.GESTURE_BEGAN, onFreeTransform);
65+
freeTransform.addEventListener(GestureEvent.GESTURE_CHANGED, onFreeTransform);
5766
...
58-
private function onFreeTransform(event:TransformGestureEvent):void
67+
private function onFreeTransform(event:GestureEvent):void
5968
{
6069
// move, rotate, scale — all at once for better performance!
70+
trace(freeTransform.offsetX, freeTransform.offsetY, freeTransform.rotation, freeTransform.scale);
6171
}
6272
</code></pre>
6373

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,46 @@
11
package org.gestouch.core
22
{
3+
import flash.utils.Dictionary;
34
import flash.errors.IllegalOperationError;
45

56

67
/**
78
* @author Pavel fljot
89
*/
9-
public class GestureState
10+
final public class GestureState
1011
{
11-
public static const IDLE:GestureState = new GestureState(1 << 0, "IDLE");
12-
public static const POSSIBLE:GestureState = new GestureState(1 << 1, "POSSIBLE");
13-
public static const RECOGNIZED:GestureState = new GestureState(1 << 2, "RECOGNIZED");
14-
public static const BEGAN:GestureState = new GestureState(1 << 3, "BEGAN");
15-
public static const CHANGED:GestureState = new GestureState(1 << 4, "CHANGED");
16-
public static const ENDED:GestureState = new GestureState(1 << 5, "ENDED");
17-
public static const CANCELLED:GestureState = new GestureState(1 << 6, "CANCELLED");
18-
public static const FAILED:GestureState = new GestureState(1 << 7, "FAILED");
19-
20-
private static const endStatesBitMask:uint =
21-
GestureState.CANCELLED.toUint() |
22-
GestureState.RECOGNIZED.toUint() |
23-
GestureState.ENDED.toUint() |
24-
GestureState.FAILED.toUint();
12+
public static const IDLE:GestureState = new GestureState("IDLE");
13+
public static const POSSIBLE:GestureState = new GestureState("POSSIBLE");
14+
public static const RECOGNIZED:GestureState = new GestureState("RECOGNIZED", true);
15+
public static const BEGAN:GestureState = new GestureState("BEGAN");
16+
public static const CHANGED:GestureState = new GestureState("CHANGED");
17+
public static const ENDED:GestureState = new GestureState("ENDED", true);
18+
public static const CANCELLED:GestureState = new GestureState("CANCELLED", true);
19+
public static const FAILED:GestureState = new GestureState("FAILED", true);
2520

2621
private static var allStatesInitialized:Boolean;
2722

2823

29-
private var value:uint;
3024
private var name:String;
31-
private var validTransitionsBitMask:uint;
25+
private var eventType:String;
26+
private var validTransitionStateMap:Dictionary = new Dictionary();
3227

3328
{
3429
_initClass();
3530
}
3631

3732

38-
public function GestureState(value:uint, name:String)
33+
public function GestureState(name:String, isEndState:Boolean = false)
3934
{
4035
if (allStatesInitialized)
4136
{
4237
throw new IllegalOperationError("You cannot create gesture states." +
4338
"Use predefined constats like GestureState.RECOGNIZED");
4439
}
4540

46-
this.value = value;
47-
this.name = name;
41+
this.name = "GestureState." + name;
42+
this.eventType = "gesture" + name.charAt(0).toUpperCase() + name.substr(1).toLowerCase();
43+
this._isEndState = isEndState;
4844
}
4945

5046

@@ -65,36 +61,35 @@ package org.gestouch.core
6561

6662
public function toString():String
6763
{
68-
return "GestureState." + name;
69-
}
70-
71-
72-
public function toUint():uint
73-
{
74-
return value;
64+
return name;
7565
}
7666

7767

7868
private function setValidNextStates(...states):void
7969
{
80-
var mask:uint;
8170
for each (var state:GestureState in states)
8271
{
83-
mask = mask | state.value;
72+
validTransitionStateMap[state] = true;
8473
}
85-
validTransitionsBitMask = mask;
74+
}
75+
76+
77+
gestouch_internal function toEventType():String
78+
{
79+
return eventType;
8680
}
8781

8882

8983
gestouch_internal function canTransitionTo(state:GestureState):Boolean
9084
{
91-
return (validTransitionsBitMask & state.value) > 0;
85+
return (state in validTransitionStateMap);
9286
}
9387

9488

89+
private var _isEndState:Boolean = false;
9590
gestouch_internal function get isEndState():Boolean
9691
{
97-
return (endStatesBitMask & value) > 0;
92+
return _isEndState;
9893
}
9994
}
10095
}
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
package org.gestouch.core
22
{
3-
import flash.geom.Point;
43
/**
54
* @author Pavel fljot
65
*/
76
public interface IGestureTargetAdapter
87
{
98
function get target():Object;
109

11-
function globalToLocal(point:Point):Point;
12-
1310
function contains(object:Object):Boolean;
1411
}
1512
}

src/org/gestouch/events/GestureEvent.as

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,40 @@ package org.gestouch.events
1010
*/
1111
public class GestureEvent extends Event
1212
{
13-
public var gestureState:GestureState;
14-
public var stageX:Number;
15-
public var stageY:Number;
16-
public var localX:Number;
17-
public var localY:Number;
13+
public static const GESTURE_IDLE:String = "gestureIdle";
14+
public static const GESTURE_POSSIBLE:String = "gesturePossible";
15+
public static const GESTURE_RECOGNIZED:String = "gestureRecognized";
16+
public static const GESTURE_BEGAN:String = "gestureBegan";
17+
public static const GESTURE_CHANGED:String = "gestureChanged";
18+
public static const GESTURE_ENDED:String = "gestureEnded";
19+
public static const GESTURE_CANCELLED:String = "gestureCancelled";
20+
public static const GESTURE_FAILED:String = "gestureFailed";
1821

22+
public static const GESTURE_STATE_CHANGE:String = "gestureStateChange";
1923

20-
public function GestureEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false,
21-
gestureState:GestureState = null,
22-
stageX:Number = 0, stageY:Number = 0,
23-
localX:Number = 0, localY:Number = 0)
24+
25+
public var newState:GestureState;
26+
public var oldState:GestureState;
27+
28+
29+
public function GestureEvent(type:String, newState:GestureState, oldState:GestureState)
2430
{
25-
super(type, bubbles, cancelable);
31+
super(type, false, false);
2632

27-
this.gestureState = gestureState;
28-
this.stageX = stageX;
29-
this.stageY = stageY;
30-
this.localX = localX;
31-
this.localY = localY;
33+
this.newState = newState;
34+
this.oldState = oldState;
3235
}
3336

3437

3538
override public function clone():Event
3639
{
37-
return new GestureEvent(type, bubbles, cancelable, gestureState, stageX, stageY, localX, localY);
40+
return new GestureEvent(type, newState, oldState);
3841
}
3942

4043

4144
override public function toString():String
4245
{
43-
return formatToString("org.gestouch.events.GestureEvent", "bubbles", "cancelable",
44-
"gestureState", "stageX", "stageY", "localX", "localY");
46+
return formatToString("GestureEvent", "type", "oldState", "newState");
4547
}
4648
}
47-
}
49+
}

src/org/gestouch/events/GestureStateEvent.as

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/org/gestouch/events/LongPressGestureEvent.as

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/org/gestouch/events/PanGestureEvent.as

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)