Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
  • 6 commits
  • 16 files changed
  • 0 commit comments
  • 1 contributor
Commits on Jan 29, 2014
@vizanto vizanto Update JS target: Haxe 3.0 compatibility. f21bab1
Commits on Feb 05, 2014
@vizanto vizanto Improve Hammer.js externs
- Fix argument error in untyped js.
- Map to proper event class and typedefs
974d3e4
@vizanto vizanto GestureEvents backed by Hammer.js b85094b
@vizanto vizanto Small JS target fixes. Wrap unimplemented: Asset. a204a06
@vizanto vizanto Only position using CSSMatrix, to fix transition
 issues on some Android browsers.

- Webkit only (for now)
3d424b0
@vizanto vizanto Reduce reflows by hiding from DOM,
 instead of removing an element immediately.
b19e37d
View
159 libs/hammer/Hammer.hx
@@ -1,117 +1,130 @@
import js.html.Event;
import js.html.Element;
+@:fakeEnum(String)
+extern enum HammerDirection
+{
+ up;
+ down;
+ left;
+ right;
+}
+
+
extern class Hammer {
- public function on(gesture:String, callback:HammerEvent->Void):Element;
+ public function on(gesture:String, callback:GestureEvent->Void):Element;
static public inline function time(element:Element, ?options : HammerOptions):Hammer {
- return untyped __js__("Hammer(element, options)");
+ var e = element;
+ var o = options;
+ return untyped __js__("Hammer(e, o)");
}
- public function off(gesture:String, callback:HammerEvent->Void):Element;
+ public function off(gesture:String, callback:GestureEvent->Void):Element;
public function enable(toggle:Bool):Element;
public function trigger(gesture:String, eventData:Event):Element;
}
typedef HammerOptions = {
- var drag: Bool;
- var drag_block_horizontal: Bool;
- var drag_block_vertical: Bool;
- var drag_lock_to_axis: Bool;
- var drag_max_touches: Int;
- var drag_min_distance: Int;
- var hold: Bool;
- var hold_threshold: Int;
- var hold_timeout: Int;
- var prevent_default: Bool;
- var prevent_mouseevents: Bool;
- var release: Bool;
- var show_touches: Bool;
- var stop_browser_behavior: {
- userSelect: String,
- touchAction: String,
- touchCallout: String,
- contentZooming: String,
- userDrag: String,
- tapHighlightColor: String
- };
- var swipe: Bool;
- var swipe_max_touches: Int;
- var swipe_velocity: Float;
- var tap: Bool;
- var tap_always: Bool;
- var tap_max_distance: Int;
- var tap_max_touchtime: Int;
- var doubletap_distance: Int;
- var doubletap_interval: Int;
- var touch: Bool;
- var transform: Bool;
- var transform_always_block: Bool;
- var transform_min_rotation: Int;
- var transform_min_scale: Float;
+ ?drag: Bool,
+ ?drag_block_horizontal: Bool,
+ ?drag_block_vertical: Bool,
+ ?drag_lock_to_axis: Bool,
+ ?drag_max_touches: Int,
+ ?drag_min_distance: Int,
+ ?hold: Bool,
+ ?hold_threshold: Int,
+ ?hold_timeout: Int,
+ ?prevent_default: Bool,
+ ?prevent_mouseevents: Bool,
+ ?release: Bool,
+ ?show_touches: Bool,
+ ?stop_browser_behavior: {
+ ?userSelect: String,
+ ?touchAction: String,
+ ?touchCallout: String,
+ ?contentZooming: String,
+ ?userDrag: String,
+ ?tapHighlightColor: String
+ },
+ ?swipe: Bool,
+ ?swipe_max_touches: Int,
+ ?swipe_velocity: Float,
+ ?tap: Bool,
+ ?tap_always: Bool,
+ ?tap_max_distance: Int,
+ ?tap_max_touchtime: Int,
+ ?doubletap_distance: Int,
+ ?doubletap_interval: Int,
+ ?touch: Bool,
+ ?transform: Bool,
+ ?transform_always_block: Bool,
+ ?transform_min_rotation: Int,
+ ?transform_min_scale: Float,
}
typedef HammerTouch = {
identifier:Int,
pageX:Int,
pageY:Int,
- target:String
+ target:Element
}
typedef Center = {
pageX: Int,
pageY: Int
}
-typedef StartEvent = {
- var center: Center;
- var eventType: String;
+typedef HammerEvent = {
+ /** center position of the touches. contains pageX and pageY */
+ var center: Center;
+ /** matches Hammer.EVENT_START|MOVE|END */
+ var eventType: String;
+ /** kind of pointer that was used. matches Hammer.POINTER_MOUSE|TOUCH */
var pointerType: String;
- var srcEvent: Event;
- var target: String;
- var timestamp: Int;
- var touches: Array<HammerTouch>;
+ /** the source event, like TouchStart or MouseDown * */
+ var srcEvent: Event;
+ /** A reference to the target to which the event was originally dispatched. */
+ var target(default,null) : js.html.EventTarget;
+ /** The time that the event was created. */
+ var timeStamp(default,null) : Int;
+ /** touches (fingers; mouse) on the screen */
+ var touches: Array<HammerTouch>;
function preventDefault():Void;
function stopDetect():Void;
function stopPropagation():Void;
}
-typedef HammerEvent = {
- /** time the event occurred */
- var timestamp: Int;
- /** target element */
- var target: String;
- /** touches (fingers; mouse) on the screen */
- var touches: Array<HammerTouch>;
- /** kind of pointer that was used. matches Hammer.POINTER_MOUSE|TOUCH */
- var pointerType: String;
- /** center position of the touches. contains pageX and pageY */
- var center: Center;
+extern class GestureEvent extends Event
+{
+ var gesture: HammerGesture;
+}
+
+typedef HammerGesture = {>HammerEvent,
/** the total time of the touches in the screen */
var deltaTime: Int;
/** the delta on x axis we haved moved */
- var deltaX: Int;
+ var deltaX: Float;
/** the delta on y axis we haved moved */
- var deltaY: Int;
+ var deltaY: Float;
/** the velocity on the x */
- var velocityX: Int;
+ var velocityX: Float;
/** the velocity on y */
- var velocityY: Int;
+ var velocityY: Float;
/** the angle we are moving */
- var angle: Int;
- /** the direction we are moving. matches Hammer.DIRECTION_UP|DOWN|LEFT|RIGHT */
- var direction: String;
+ var angle: Float;
+ /** the direction we are moving */
+ var direction: HammerDirection;
/** the distance we haved moved */
- var distance: Int;
+ var distance: Float;
/** scaling of the touches, needs 2 touches */
- var scale: Int;
+ var scale: Float;
/** rotation of the touches, needs 2 touches * */
- var rotation: Int;
- /** matches Hammer.EVENT_START|MOVE|END */
- var eventType: String;
- /** the source event, like TouchStart or MouseDown * */
- var srcEvent: Event;
+ var rotation: Float;
/** contains the same properties as above,
but from the first touch. this is used to calculate
distances, deltaTime, scaling etc */
- var startEvent: StartEvent;
-}
+ var startEvent: HammerEvent;
+
+ var interimAngle: Float;
+ var interimDirection: HammerDirection;
+}
View
9 prime-core/src/prime/js/net/URLLoader.hx
@@ -3,6 +3,7 @@ package prime.js.net;
import prime.core.events.LoaderEvents;
import prime.net.ICommunicator;
import prime.net.CommunicationType;
+ import prime.net.RequestMethod;
import prime.bindable.Bindable;
import prime.types.URI;
import haxe.io.BytesData;
@@ -133,6 +134,12 @@ class URLLoader implements ICommunicator
request = null;
}
+ public function requestBinary (uri:URI, method:RequestMethod) return switch (method) {
+ case get: binaryGET (uri);
+ case post: sendBinary(uri);
+ default: throw "unsupported: " + method;
+ }
+
public function binaryGET(uri:URI)
{
this.type = CommunicationType.loading;
@@ -146,7 +153,7 @@ class URLLoader implements ICommunicator
this.isStarted = true;
}
- public function binaryPOST(uri:URI, mimetype:String = "application/octet-stream")
+ public function sendBinary(uri:URI, mimetype:String = "application/octet-stream")
{
this.type = CommunicationType.sending;
View
3 prime-core/src/prime/net/URLLoader.hx
@@ -27,7 +27,6 @@
* Ruben Weijers <ruben @ prime.vc>
*/
package prime.net;
-#if (flash9 || nme)
typedef URLLoader =
#if (flash9 || nme) prime.avm2.net.URLLoader;
@@ -36,5 +35,3 @@ typedef URLLoader =
#elseif js prime.js .net.URLLoader;
#elseif neko prime.neko.net.URLLoader;
#else #error; #end
-
-#end
View
27 prime-display/src/prime/js/display/Button.hx
@@ -0,0 +1,27 @@
+package prime.js.display;
+
+/**
+ * @since January 26, 2012
+ * @author Stanislav Sopov
+ */
+class Button extends DOMElem
+{
+ public var icon(default, null):Image;
+ public var iconURI(default, set_iconURI):String;
+
+ public function new() {
+ super("div");
+ className = "button";
+ }
+
+ private function set_iconURI(v:String):String {
+ iconURI = v;
+ if (icon == null) {
+ icon = new Image();
+ children.add(icon);
+ }
+ icon.src = v;
+ icon.load();
+ return v;
+ }
+}
View
25 prime-display/src/prime/js/display/DOMElem.hx
@@ -16,25 +16,21 @@ class DOMElem
public var id (default, set_id):String;
public var matrix (default, null):Dynamic;//WebKitCSSMatrix;
public var parent :DOMElem;
- public var scale (default, set_scale):Float;
- public var style (get_style, null):Style;
+ public var scale (default, set_scale):Float = 1;
+ public var style (get_style, null):js.html.CSSStyleDeclaration;
public var type (default, null):String;
public var visible (default, set_visible):Bool;
public var width (default, set_width):Int;
- public var x (default, set_x):Int;
- public var y (default, set_y):Int;
+ public var x (default, set_x):Int = 0;
+ public var y (default, set_y):Int = 0;
public function new(type:String)
{
- elem = Lib.document.createElement(type);
+ elem = js.Browser.document.createElement(type);
children = new DisplayList(this);
-#if onlinetouch
- matrix = nl.onlinetouch.viewer.view.managers.js.Transform.getMatrix(elem); //<-- WTF Stan?!@%
-#end
- (untyped this).x = 0;
- (untyped this).y = 0;
- (untyped this).scale = 1;
+ var style = js.Browser.window.getComputedStyle(elem, null);
+ this.matrix = untyped __js__("new WebKitCSSMatrix(style.webkitTransform)");
}
private function set_width(v:Int):Int
@@ -101,7 +97,7 @@ class DOMElem
return id;
}
- inline private function get_style():Style
+ inline private function get_style()
{
return elem.style;
}
@@ -125,14 +121,11 @@ class DOMElem
inline private function applyTransforms()
{
- //elem.style.webkitTransform = "translate3d(" + x + "px," + y + "px,0) scale3d(" + scale + "," + scale + ",1)";
- elem.style.webkitTransform = "translate(" + x + "px," + y + "px) scale(" + scale + ")";
- /* var m = matrix;
+ var m = matrix;
m.a = m.d = scale;
m.e = x;
m.f = y;
elem.style.webkitTransform = m;
- */
}
}
#end
View
9 prime-display/src/prime/js/display/DisplayList.hx
@@ -19,16 +19,21 @@ class DisplayList
{
if (object.elem.parentNode != target.elem)
{
- target.elem.appendChild(object.elem);
+ if (object.elem.parentNode != null) object.elem.parentNode.removeChild(object.elem);
+ object.style.display = "block";
object.parent = target;
+ target.elem.appendChild(object.elem);
}
}
public #if !noinline inline #end function remove(object:DOMElem)
{
if (object.elem.parentNode == target.elem)
{
- target.elem.removeChild(object.elem);
+ // --- Reduce reflows by hiding from DOM, instead of removing an element immediately:
+ //target.elem.removeChild(object.elem);
+ // ---
+ object.style.display = "none";
object.parent = null;
}
}
View
17 prime-display/src/prime/js/display/Image.hx
@@ -1,6 +1,5 @@
package prime.js.display;
#if js
- import js.Dom;
import prime.signals.Signal1;
import prime.js.events.DisplayEvents;
import prime.js.events.DisplaySignal;
@@ -16,8 +15,6 @@ class Image extends DOMElem {
public var events (default, null):DisplayEvents;
public var isDisplayed (default, null):Bool;
public var loaded (default, null):Signal1<Image>;
- override public var width (default, set_width):Int;
- override public var height (default, set_height):Int;
public function new() {
super("img");
@@ -28,8 +25,8 @@ class Image extends DOMElem {
private function initEvents() {
events = new DisplayEvents(elem);
- events.insertedIntoDoc.bind(this, onInsertedIntoDoc);
- events.removedFromDoc.bind(this, onRemovedFromDoc);
+ events.addedToStage.bind(this, onInsertedIntoDoc);
+ events.removedFromStage.bind(this, onRemovedFromDoc);
loaded = new Signal1();
untyped elem.addEventListener("load", onLoad, false);
@@ -61,17 +58,17 @@ class Image extends DOMElem {
return src;
}
- private function onInsertedIntoDoc(event:DisplayEvent) {
+ private function onInsertedIntoDoc() {
isDisplayed = true;
load();
}
- private function onRemovedFromDoc(event:DisplayEvent) {
+ private function onRemovedFromDoc() {
isDisplayed = false;
elem.src = "";
}
- private function onLoad(event:Event) {
+ private function onLoad(event) {
loaded.send(this);
}
@@ -80,5 +77,9 @@ class Image extends DOMElem {
elem.src = src;
}
}
+
+ inline public function unload() {
+ elem.src = "";
+ }
}
#end
View
8 prime-display/src/prime/js/display/Link.hx
@@ -1,6 +1,5 @@
package prime.js.display;
#if js
-import js.Dom;
import js.Lib;
import prime.js.events.TouchEvents;
import prime.js.events.TouchSignal;
@@ -31,13 +30,12 @@ class Link extends DOMElem
private function set_href(v:String):String
{
- href = v;
- elem.href = href;
+ elem.href = v;
elem.target = "_blank";
- return href;
+ return href = v;
}
- private function applyAction(e:TouchEvent)
+ private function applyAction(e)
{
action();
}
View
1 prime-display/src/prime/js/display/Sprite.hx
@@ -1,6 +1,5 @@
package prime.js.display;
#if js
-import js.Dom;
import js.Lib;
/**
View
14 prime-display/src/prime/js/display/Video.hx
@@ -1,6 +1,5 @@
package prime.js.display;
#if js
-import js.Dom;
import js.Lib;
/**
@@ -26,8 +25,6 @@ class Video extends DOMElem
public var src (default, set_src):String;
public var preload (default, set_preload):String;
- override public var width (default, set_width):Int;
- override public var height (default, set_height):Int;
public function new() {
super("video");
@@ -77,5 +74,16 @@ class Video extends DOMElem
//elem.load();
//elem.play();
}
+
+ public function load() {
+ //if (src != null && elem.src != src) {
+ elem.src = src;
+ //}
+ }
+
+ public function unload() {
+ elem.pause();
+ elem.src = "";
+ }
}
#end
View
4 prime-display/src/prime/types/Asset.hx
@@ -26,6 +26,7 @@
* Authors:
* Ruben Weijers <ruben @ onlinetouch.nl>
*/
+#if !js
package prime.types;
import prime.core.geom.Matrix2D;
import prime.net.ICommunicator;
@@ -680,4 +681,5 @@ enum AssetStates {
enum AssetType {
bitmapData;
displayObject;
-}
+}
+#end
View
1 prime-layout/munit_test/TestMain.hx
@@ -7,7 +7,6 @@ import massive.munit.TestRunner;
#if js
import js.Lib;
-import js.Dom;
#end
#if (haxe_208 && !haxe_209)
View
4 prime-signals/src/prime/gui/events/TouchEvents.hx
@@ -32,8 +32,6 @@ package prime.gui.events;
import prime.core.traits.IClonable;
import prime.gui.events.KeyModState;
-#if (flash9 || nme)
-
typedef TouchEvents =
#if (flash9 || nme) Dynamic; //TODO
#elseif flash prime.avm1.events.TouchEvents;
@@ -42,8 +40,6 @@ typedef TouchEvents =
// #elseif neko prime.neko.events.TouchEvents;
#else #error; #end
-#end
-
typedef TouchHandler = TouchState -> Void;
typedef TouchSignal = prime.signals.Signal1<TouchState>;
View
9 prime-signals/src/prime/js/events/DOMSignal0.hx
@@ -27,21 +27,16 @@ class DOMSignal0 extends Signal0 implements IWireWatcher<Void->Void>
if (n.next() == null) // First wire connected
{
- untyped eventDispatcher.addEventListener(event, dispatch, false);
+ untyped eventDispatcher.addEventListener(event, send, false);
}
}
public function wireDisabled (wire:Wire<Void->Void>):Void
{
if (n == null) // No more wires connected
{
- untyped eventDispatcher.removeEventListener(event, dispatch, false);
+ untyped eventDispatcher.removeEventListener(event, send, false);
}
}
-
- private function dispatch(e:Event)
- {
- Assert.abstractMethod();
- }
}
#end
View
120 prime-signals/src/prime/js/events/GestureEvents.hx
@@ -1,43 +1,111 @@
package prime.js.events;
#if js
+ import Hammer;
+ import prime.signals.Wire;
import prime.signals.Signals;
+ import prime.signals.Signal1;
+ import prime.signals.IWireWatcher;
import prime.gui.events.UserEventTarget;
-/**
- * @author Stanislav Sopov
- * @author Ruben Weijers
- * @since May 3, 2011
+typedef GestureEvent = Hammer.GestureEvent;
+
+/**
+ * Signal0<-->hammer.js Event Proxy implementation
+ *
+ * @author Danny Wilson
+ * @creation-date jun 15, 2010
*/
-class GestureEvents extends Signals
+class GestureSignal extends Signal1<GestureEvent> implements IWireWatcher<Void->Void>
{
- private var eventDispatcher : UserEventTarget;
-
- public var start (get_start, null) : GestureSignal;
- public var change (get_change,null) : GestureSignal;
- public var end (get_end, null) : GestureSignal;
-
-
- public function new(eventDispatcher:Dynamic)
+ var hammer : Hammer;
+ var event : String;
+
+ public function new (d:Hammer, e:String)
{
super();
- this.eventDispatcher = eventDispatcher;
+ this.hammer = d;
+ this.event = e;
+ }
+
+ public function wireEnabled (wire:Wire<Void -> Void>) : Void {
+ Assert.isNotNull(n);
+ if (n.next() == null) // First wire connected
+ hammer.on(event, send);
+ }
+
+ public function wireDisabled (wire:Wire<Void -> Void>) : Void {
+ if (n == null) // No more wires connected
+ hammer.off(event, send);
}
+}
-
- override public function dispose ()
+
+/**
+ * @author Danny Wilson
+ * @since Jan 29, 2014
+ */
+class GestureEvents extends Signals
+{
+ var hold (get, null) : GestureSignal;
+ var tap (get, null) : GestureSignal;
+ var doubletap (get, null) : GestureSignal;
+ var drag (get, null) : GestureSignal;
+ var dragstart (get, null) : GestureSignal;
+ var dragend (get, null) : GestureSignal;
+ var dragup (get, null) : GestureSignal;
+ var dragdown (get, null) : GestureSignal;
+ var dragleft (get, null) : GestureSignal;
+ var dragright (get, null) : GestureSignal;
+ var swipe (get, null) : GestureSignal;
+ var swipeup (get, null) : GestureSignal;
+ var swipedown (get, null) : GestureSignal;
+ var swipeleft (get, null) : GestureSignal;
+ var swiperight (get, null) : GestureSignal;
+ var transform (get, null) : GestureSignal;
+ var transformstart (get, null) : GestureSignal;
+ var transformend (get, null) : GestureSignal;
+ var rotate (get, null) : GestureSignal;
+ var pinch (get, null) : GestureSignal;
+ var pinchin (get, null) : GestureSignal;
+ var pinchout (get, null) : GestureSignal;
+ /** (gesture detection starts) */
+ var touch (get, null) : GestureSignal;
+ /** (gesture detection ends) */
+ var release (get, null) : GestureSignal;
+
+ private var eventDispatcher : Hammer;
+
+
+ public function new (target : UserEventTarget)
{
- super.dispose();
- eventDispatcher = null;
+ super();
+ this.eventDispatcher = Hammer.time(target, {transform_always_block: true});
}
-
- private inline function get_start () { if (start == null) { createStart(); } return start; }
- private inline function get_change () { if (change == null) { createChange(); } return change; }
- private inline function get_end () { if (end == null) { createEnd(); } return end; }
-
- private inline function createStart () { start = new GestureSignal(eventDispatcher, "gesturestart"); }
- private inline function createChange() { change = new GestureSignal(eventDispatcher, "gesturechange"); }
- private inline function createEnd () { end = new GestureSignal(eventDispatcher, "gestureend"); }
+ private function get_hold (){ if (hold == null) hold = new GestureSignal(eventDispatcher, "hold"); return hold; }
+ private function get_tap (){ if (tap == null) tap = new GestureSignal(eventDispatcher, "tap"); return tap; }
+ private function get_doubletap (){ if (doubletap == null) doubletap = new GestureSignal(eventDispatcher, "doubletap"); return doubletap; }
+ private function get_drag (){ if (drag == null) drag = new GestureSignal(eventDispatcher, "drag"); return drag; }
+ private function get_dragstart (){ if (dragstart == null) dragstart = new GestureSignal(eventDispatcher, "dragstart"); return dragstart; }
+ private function get_dragend (){ if (dragend == null) dragend = new GestureSignal(eventDispatcher, "dragend"); return dragend; }
+ private function get_dragup (){ if (dragup == null) dragup = new GestureSignal(eventDispatcher, "dragup"); return dragup; }
+ private function get_dragdown (){ if (dragdown == null) dragdown = new GestureSignal(eventDispatcher, "dragdown"); return dragdown; }
+ private function get_dragleft (){ if (dragleft == null) dragleft = new GestureSignal(eventDispatcher, "dragleft"); return dragleft; }
+ private function get_dragright (){ if (dragright == null) dragright = new GestureSignal(eventDispatcher, "dragright"); return dragright; }
+ private function get_swipe (){ if (swipe == null) swipe = new GestureSignal(eventDispatcher, "swipe"); return swipe; }
+ private function get_swipeup (){ if (swipeup == null) swipeup = new GestureSignal(eventDispatcher, "swipeup"); return swipeup; }
+ private function get_swipedown (){ if (swipedown == null) swipedown = new GestureSignal(eventDispatcher, "swipedown"); return swipedown; }
+ private function get_swipeleft (){ if (swipeleft == null) swipeleft = new GestureSignal(eventDispatcher, "swipeleft"); return swipeleft; }
+ private function get_swiperight (){ if (swiperight == null) swiperight = new GestureSignal(eventDispatcher, "swiperight"); return swiperight; }
+ private function get_transform (){ if (transform == null) transform = new GestureSignal(eventDispatcher, "transform"); return transform; }
+ private function get_transformstart (){ if (transformstart == null) transformstart = new GestureSignal(eventDispatcher, "transformstart"); return transformstart; }
+ private function get_transformend (){ if (transformend == null) transformend = new GestureSignal(eventDispatcher, "transformend"); return transformend; }
+ private function get_rotate (){ if (rotate == null) rotate = new GestureSignal(eventDispatcher, "rotate"); return rotate; }
+ private function get_pinch (){ if (pinch == null) pinch = new GestureSignal(eventDispatcher, "pinch"); return pinch; }
+ private function get_pinchin (){ if (pinchin == null) pinchin = new GestureSignal(eventDispatcher, "pinchin"); return pinchin; }
+ private function get_pinchout (){ if (pinchout == null) pinchout = new GestureSignal(eventDispatcher, "pinchout"); return pinchout; }
+ private function get_touch (){ if (touch == null) touch = new GestureSignal(eventDispatcher, "touch"); return touch; }
+ private function get_release (){ if (release == null) release = new GestureSignal(eventDispatcher, "release"); return release; }
}
#end
View
2 prime-signals/src/prime/js/events/TouchSignal.hx
@@ -25,15 +25,13 @@ class TouchSignal extends DOMSignal1<TouchState>
-//import js.Dom;
/**
* @author Stanislav Sopov
* @since march 2, 2011
*/
/*class TouchSignal extends DOMSignal1<Type>
import prime.js.events.DOMSignal1;
-import js.Dom;
typedef TouchEvent =
{

No commit comments for this range

Something went wrong with that request. Please try again.