Skip to content

Commit

Permalink
starling initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
fljot committed Mar 15, 2012
1 parent 340a246 commit 17baeee
Show file tree
Hide file tree
Showing 32 changed files with 1,164 additions and 49 deletions.
1 change: 1 addition & 0 deletions .settings/com.powerflasher.fdt.classpath
Expand Up @@ -19,4 +19,5 @@
<AS3Classpath generateProblems="false" sdkBased="false" type="lib" useAsSharedCode="false">libs/MonsterDebuggerMobile.swc</AS3Classpath>
<AS3Classpath generateProblems="false" inclusion="complete" sdkBased="false" type="project" useAsSharedCode="false">Gestouch</AS3Classpath>
<AS3Classpath generateProblems="false" sdkBased="true" type="lib" useAsSharedCode="false">frameworks/libs/mx/mx.swc</AS3Classpath>
<AS3Classpath generateProblems="false" sdkBased="false" type="lib" useAsSharedCode="false">libs/starling.swc</AS3Classpath>
</AS3Classpath>
6 changes: 3 additions & 3 deletions .settings/com.powerflasher.fdt.core.prefs
@@ -1,4 +1,4 @@
#Mon Apr 25 18:42:57 EEST 2011
#Thu Mar 08 20:28:06 EET 2012
com.powerflasher.fdt.core.CompatiblePlayers=AIR_Debug_Launcher
com.powerflasher.fdt.core.CompilerArguments=-load-config\="{flexSDK}/frameworks/airmobile-config.xml"\n-target-player\={playerVersion}\n-library-path+\="{flexSDK}/frameworks/locale/en_US"
com.powerflasher.fdt.core.DefaultOutputFolder=bin
Expand All @@ -8,8 +8,8 @@ com.powerflasher.fdt.core.PassClasspath=true
com.powerflasher.fdt.core.PassMainclass=true
com.powerflasher.fdt.core.PassRsls=false
com.powerflasher.fdt.core.PassSwcs=true
com.powerflasher.fdt.core.PlayerVersion=10.2
com.powerflasher.fdt.core.PlayerVersion=11.1
com.powerflasher.fdt.core.ProjectTypeHint=Flex 4.5 Mobile
com.powerflasher.fdt.core.Runtime=AIR
com.powerflasher.fdt.core.SdkName=Flex 4.5
com.powerflasher.fdt.core.SdkName=Flex 4.6
eclipse.preferences.version=1
Binary file added back-button.psd
Binary file not shown.
4 changes: 2 additions & 2 deletions build.template.properties
@@ -1,7 +1,7 @@
# IMPORTANT Change to your local system paths before using ANT

# Flex SDK related properties
FLEX_HOME = path-to-flex-4.5-SDK#/Users/fljot/Development/SDKs/flex_sdk_4.5
FLEX_HOME = path-to-flex-4.6-SDK(AIR 3.2)#/Users/fljot/Development/SDKs/flex_sdk_4.6
flexSDK.dir = ${FLEX_HOME}
flexSDK.adl = ${flexSDK.dir}/bin/adl
flexSDK.adt = ${flexSDK.dir}/lib/adt.jar
Expand Down Expand Up @@ -29,7 +29,7 @@ binrelease.dir = ${basedir}/bin
# Input
project.examplesPackage.dir = org/gestouch/examples
project.targetPlayerVersion = 10.2
project.baseCompilerArguments = -default-size=800,600 --target-player=${project.targetPlayerVersion} -static-link-runtime-shared-libraries=true
project.baseCompilerArguments = -default-size=800,600 --target-player=${project.targetPlayerVersion} -static-link-runtime-shared-libraries=true -swf-version=15
project.mobileCompilerArguments = -preloader=spark.preloaders.SplashScreen -theme="${flexSDK.dir}/frameworks/themes/Mobile/mobile.swc"
project.debugCompilerArguments = -define=CONFIG::Debug,true -define+=CONFIG::Release,false -verbose-stacktraces=true
project.releaseCompilerArguments = -define=CONFIG::Debug,false -define+=CONFIG::Release,true
Expand Down
4 changes: 2 additions & 2 deletions build/air/descriptor-template-app.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<application xmlns="http://ns.adobe.com/air/application/3.0">
<application xmlns="http://ns.adobe.com/air/application/3.2">

<!-- Adobe AIR Application Descriptor File Template.
Expand Down Expand Up @@ -101,7 +101,7 @@

<!-- The render mode for the app (either auto, cpu, or gpu). Optional. Mobile only. Default auto -->

<!-- <renderMode></renderMode> -->
<renderMode>direct</renderMode>

<!-- Whether or not to pan when a soft keyboard is raised or lowered (either "pan" or "none"). Optional. Defaults "pan." -->
<!-- <softKeyboardBehavior></softKeyboardBehavior> -->
Expand Down
9 changes: 4 additions & 5 deletions build/android/descriptor-template-apk.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<application xmlns="http://ns.adobe.com/air/application/2.6">
<application xmlns="http://ns.adobe.com/air/application/3.2">

<!-- Adobe AIR Application Descriptor File Template.
Expand Down Expand Up @@ -88,20 +88,19 @@
<!-- <maxSize></maxSize> -->

<!-- The initial aspect ratio of the app when launched (either "portrait" or "landscape"). Optional. Mobile only. Default is the natural orientation of the device -->

<!-- <aspectRatio></aspectRatio> -->

<!-- Whether the app will begin auto-orienting on launch. Optional. Mobile only. Default false -->

<autoOrients>true</autoOrients>

<!-- Whether the app launches in full screen. Optional. Mobile only. Default false -->

<fullScreen>true</fullScreen>

<!-- The render mode for the app (either auto, cpu, or gpu). Optional. Mobile only. Default auto -->
<renderMode>direct</renderMode>

<!-- <renderMode></renderMode> -->
<!-- Whether the default direct mode rendering context allocates storage for depth and stencil buffers. Optional. Default false. -->
<depthAndStencil>false</depthAndStencil>

<!-- Whether or not to pan when a soft keyboard is raised or lowered (either "pan" or "none"). Optional. Defaults "pan." -->
<!-- <softKeyboardBehavior></softKeyboardBehavior> -->
Expand Down
9 changes: 4 additions & 5 deletions build/iOS/descriptor-template-ipa.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<application xmlns="http://ns.adobe.com/air/application/2.6">
<application xmlns="http://ns.adobe.com/air/application/3.2">

<!-- Adobe AIR Application Descriptor File Template.
Expand Down Expand Up @@ -88,20 +88,19 @@
<!-- <maxSize></maxSize> -->

<!-- The initial aspect ratio of the app when launched (either "portrait" or "landscape"). Optional. Mobile only. Default is the natural orientation of the device -->

<!-- <aspectRatio></aspectRatio> -->

<!-- Whether the app will begin auto-orienting on launch. Optional. Mobile only. Default false -->

<autoOrients>true</autoOrients>

<!-- Whether the app launches in full screen. Optional. Mobile only. Default false -->

<fullScreen>true</fullScreen>

<!-- The render mode for the app (either auto, cpu, or gpu). Optional. Mobile only. Default auto -->
<renderMode>direct</renderMode>

<!-- <renderMode></renderMode> -->
<!-- Whether the default direct mode rendering context allocates storage for depth and stencil buffers. Optional. Default false. -->
<depthAndStencil>false</depthAndStencil>

<!-- Whether or not to pan when a soft keyboard is raised or lowered (either "pan" or "none"). Optional. Defaults "pan." -->
<!-- <softKeyboardBehavior></softKeyboardBehavior> -->
Expand Down
Binary file added libs/starling.swc
Binary file not shown.
Binary file added src/assets/images/back-button.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion src/org/gestouch/examples/model/ExamplesModel.as
@@ -1,12 +1,13 @@
package org.gestouch.examples.model
{
import org.gestouch.examples.views.DependentSwipingGesturesView;
import org.gestouch.examples.views.ConflictGesturesView;
import org.gestouch.examples.views.DependentSwipingGesturesView;
import org.gestouch.examples.views.DependentTapGesturesView;
import org.gestouch.examples.views.LongPressGestureAdvancedView;
import org.gestouch.examples.views.LongPressGestureView;
import org.gestouch.examples.views.PanGestureView;
import org.gestouch.examples.views.RotateGestureView;
import org.gestouch.examples.views.StarlingConflictGesturesView;
import org.gestouch.examples.views.SwipeGestureView;
import org.gestouch.examples.views.TapGestureUsageView;
import org.gestouch.examples.views.TapGestureView;
Expand Down Expand Up @@ -35,6 +36,7 @@ package org.gestouch.examples.model
,{label: "Conflicts Resolution Example", viewClass: ConflictGesturesView}
,{label: "Dependent Tap Gestures Example", viewClass: DependentTapGesturesView}
,{label: "Dependent Swiping Gestures Example", viewClass: DependentSwipingGesturesView}
,{label: "Starling: Conflicts Example", viewClass: StarlingConflictGesturesView}
]
);

Expand Down
193 changes: 193 additions & 0 deletions src/org/gestouch/examples/starling/ConflictGesturesExample.as
@@ -0,0 +1,193 @@
package org.gestouch.examples.starling
{
import com.greensock.TweenMax;
import flash.geom.Matrix;
import flash.geom.Point;
import org.gestouch.core.GestureState;
import org.gestouch.core.IGestureDelegate;
import org.gestouch.core.Touch;
import org.gestouch.events.TapGestureEvent;
import org.gestouch.events.TransformGestureEvent;
import org.gestouch.extensions.starling.StarlingDisplayObjectAdapter;
import org.gestouch.gestures.Gesture;
import org.gestouch.gestures.TapGesture;
import org.gestouch.gestures.TransformGesture;
import org.gestouch.utils.GestureUtils;
import starling.display.DisplayObject;
import starling.display.Image;
import starling.display.Sprite;
import starling.textures.Texture;




/**
* @author Pavel fljot
*/
public class ConflictGesturesExample extends StarlingExampleBase implements IGestureDelegate
{
[Embed(source="/assets/images/YellowSquare.png")]
private static const yellowAsset:Class;
[Embed(source="/assets/images/CyanSquare.png")]
private static const cyanAsset:Class;
[Embed(source="/assets/images/MagentaSquare.png")]
private static const magentaAsset:Class;

private var container:Sprite;
private var containerIsTransforming:Boolean;
private var innerActiveTransformGesturesCounter:uint;


public function ConflictGesturesExample()
{
super();
}


override protected function init():void
{
super.init();

container = new Sprite();
addChild(container);

var freeTransform:TransformGesture = new TransformGesture(new StarlingDisplayObjectAdapter(stage));
freeTransform.addEventListener(TransformGestureEvent.GESTURE_TRANSFORM, onTransform, false, 0, true);
freeTransform.delegate = this;

var image:Image;
image = addImage(Texture.fromBitmap(new yellowAsset()));
image.x = stage.stageWidth - 3 * image.width >> 1;
image.y = stage.stageHeight - 3 * image.height >> 1;
container.addChild(image);
image = addImage(Texture.fromBitmap(new cyanAsset()));
image.x = stage.stageWidth - image.width >> 1;
image.y = stage.stageHeight - image.height >> 1;
container.addChild(image);
image = addImage(Texture.fromBitmap(new magentaAsset()));
image.x = stage.stageWidth + image.width >> 1;
image.y = stage.stageHeight + image.height >> 1;
container.addChild(image);
}


private function addImage(texture:Texture):Image
{
var image:Image = new Image(texture);
image.width = image.height = Math.min(stage.stageWidth, stage.stageHeight) / 3;

var tap:TapGesture = new TapGesture(new StarlingDisplayObjectAdapter(image));
tap.addEventListener(TapGestureEvent.GESTURE_TAP, onTap, false, 0, true);

var freeTransform:TransformGesture = new TransformGesture(new StarlingDisplayObjectAdapter(image));
freeTransform.addEventListener(TransformGestureEvent.GESTURE_TRANSFORM, onTransform, false, 0, true);
freeTransform.delegate = this;

return image;
}


private function onTransform(event:TransformGestureEvent):void
{
var target:DisplayObject = (event.target as Gesture).target as DisplayObject;
if (target == stage)
{
target = container;

if (event.gestureState == GestureState.BEGAN)
{
containerIsTransforming = true;
}
else if (event.gestureState == GestureState.ENDED || event.gestureState == GestureState.CANCELLED)
{
containerIsTransforming = false;
}
}
else
{
if (event.gestureState == GestureState.BEGAN)
{
innerActiveTransformGesturesCounter++;
}
else if (event.gestureState == GestureState.ENDED || event.gestureState == 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;
}
}

// Panning
target.x += event.offsetX;
target.y += event.offsetY;

if (event.scaleX != 1 || event.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));
m.translate(-transformPoint.x, -transformPoint.y);
m.rotate(event.rotation * GestureUtils.DEGREES_TO_RADIANS);
m.scale(event.scaleX, event.scaleY);
m.translate(transformPoint.x, transformPoint.y);

target.x = m.tx;
target.y = m.ty;
target.rotation = Math.atan2(m.b, m.a);
target.scaleX = target.scaleY = Math.sqrt(m.a*m.a + m.b*m.b);
}
}


private function onTap(event:TapGestureEvent):void
{
trace("tap");
TweenMax.to((event.target as Gesture).target, 0.5, {bezierThrough:[{alpha:0.1}, {alpha:1}]});
}


public function gestureShouldReceiveTouch(gesture:Gesture, touch:Touch):Boolean
{
if (containerIsTransforming && gesture is TransformGesture && container.contains(gesture.target as DisplayObject))
{
// Let the inner transform gestures don't even receive touch
// if container's transform gesture is in progress
return false;
}

if (gesture is TransformGesture && gesture.target == stage && innerActiveTransformGesturesCounter > 0)
{
// One or more inner squares are currently transforming.
// To prevent strange offsets we ignore this touch for our stage transform gesture
return false;
}

// Default behavior
return true;
}


public function gestureShouldBegin(gesture:Gesture):Boolean
{
// Default behavior
return true;
}


public function gesturesShouldRecognizeSimultaneously(gesture:Gesture, otherGesture:Gesture):Boolean
{
// Default behavior
return false;
}
}
}
53 changes: 53 additions & 0 deletions src/org/gestouch/examples/starling/StarlingExample.as
@@ -0,0 +1,53 @@
package org.gestouch.examples.starling
{
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.geom.Rectangle;
import org.gestouch.core.GesturesManager;
import org.gestouch.core.IGesturesManager;
import org.gestouch.extensions.starling.StarlingDisplayListAdapter;
import org.gestouch.extensions.starling.StarlingInputAdapter;
import starling.core.Starling;
import starling.display.DisplayObject;
import starling.events.ResizeEvent;



[SWF(backgroundColor="#FFFFFF", frameRate="60", width="640", height="480")]
/**
* @author Pavel fljot
*/
public class StarlingExample extends Sprite
{
private var starling:Starling;


public function StarlingExample()
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;

Starling.multitouchEnabled = true; // useful on mobile devices
Starling.handleLostContext = true; // deactivate on mobile devices (to save memory)

starling = new Starling(StarlingRoot, stage);
starling.enableErrorChecking = false;
starling.stage.addEventListener(ResizeEvent.RESIZE, starling_resizeHandler);
starling.start();

var gesturesManager:IGesturesManager = GesturesManager.getInstance();
gesturesManager.addDisplayListAdapter(starling.display.DisplayObject, new StarlingDisplayListAdapter());
gesturesManager.addInputAdapter(new StarlingInputAdapter(starling));
}


private function starling_resizeHandler(event:ResizeEvent):void
{
var rect:Rectangle = new Rectangle(0, 0, event.width, event.height);
starling.viewPort = rect;
starling.stage.stageWidth = rect.width;
starling.stage.stageHeight = rect.height;
}
}
}

0 comments on commit 17baeee

Please sign in to comment.