Make the Touch events more robust
This commit is contained in:
@@ -16,6 +16,7 @@ import lime.graphics.Renderer;
|
|||||||
import lime.ui.Keyboard;
|
import lime.ui.Keyboard;
|
||||||
import lime.ui.KeyCode;
|
import lime.ui.KeyCode;
|
||||||
import lime.ui.KeyModifier;
|
import lime.ui.KeyModifier;
|
||||||
|
import lime.ui.Touch;
|
||||||
import lime.ui.Window;
|
import lime.ui.Window;
|
||||||
|
|
||||||
@:access(lime.app.Application)
|
@:access(lime.app.Application)
|
||||||
@@ -26,8 +27,10 @@ class FlashApplication {
|
|||||||
|
|
||||||
|
|
||||||
private var cacheTime:Int;
|
private var cacheTime:Int;
|
||||||
|
private var currentTouches = new Map<Int, Touch> ();
|
||||||
private var mouseLeft:Bool;
|
private var mouseLeft:Bool;
|
||||||
private var parent:Application;
|
private var parent:Application;
|
||||||
|
private var unusedTouchesPool = new List<Touch> ();
|
||||||
|
|
||||||
|
|
||||||
public function new (parent:Application):Void {
|
public function new (parent:Application):Void {
|
||||||
@@ -160,9 +163,9 @@ class FlashApplication {
|
|||||||
Lib.current.stage.addEventListener (Event.RESIZE, handleWindowEvent);
|
Lib.current.stage.addEventListener (Event.RESIZE, handleWindowEvent);
|
||||||
|
|
||||||
cacheTime = Lib.getTimer ();
|
cacheTime = Lib.getTimer ();
|
||||||
handleUpdateEvent (null);
|
handleApplicationEvent (null);
|
||||||
|
|
||||||
Lib.current.stage.addEventListener (Event.ENTER_FRAME, handleUpdateEvent);
|
Lib.current.stage.addEventListener (Event.ENTER_FRAME, handleApplicationEvent);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@@ -176,6 +179,24 @@ class FlashApplication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private function handleApplicationEvent (event:Event):Void {
|
||||||
|
|
||||||
|
var currentTime = Lib.getTimer ();
|
||||||
|
var deltaTime = currentTime - cacheTime;
|
||||||
|
cacheTime = currentTime;
|
||||||
|
|
||||||
|
parent.onUpdate.dispatch (deltaTime);
|
||||||
|
|
||||||
|
if (parent.renderer != null) {
|
||||||
|
|
||||||
|
parent.renderer.onRender.dispatch ();
|
||||||
|
parent.renderer.flip ();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private function handleKeyEvent (event:KeyboardEvent):Void {
|
private function handleKeyEvent (event:KeyboardEvent):Void {
|
||||||
|
|
||||||
var keyCode = convertKeyCode (event.keyCode);
|
var keyCode = convertKeyCode (event.keyCode);
|
||||||
@@ -250,7 +271,6 @@ class FlashApplication {
|
|||||||
|
|
||||||
if (parent.window != null) {
|
if (parent.window != null) {
|
||||||
|
|
||||||
var id = 0;
|
|
||||||
var x = event.stageX;
|
var x = event.stageX;
|
||||||
var y = event.stageY;
|
var y = event.stageY;
|
||||||
|
|
||||||
@@ -258,18 +278,87 @@ class FlashApplication {
|
|||||||
|
|
||||||
case TouchEvent.TOUCH_BEGIN:
|
case TouchEvent.TOUCH_BEGIN:
|
||||||
|
|
||||||
parent.window.onTouchStart.dispatch (x / parent.window.width, y / parent.window.height, id);
|
var touch = unusedTouchesPool.pop ();
|
||||||
parent.window.onMouseDown.dispatch (x, y, 0);
|
|
||||||
|
|
||||||
case TouchEvent.TOUCH_MOVE:
|
|
||||||
|
|
||||||
parent.window.onTouchMove.dispatch (x / parent.window.width, y / parent.window.height, id);
|
if (touch == null) {
|
||||||
parent.window.onMouseMove.dispatch (x, y);
|
|
||||||
|
touch = new Touch (x / parent.window.width, y / parent.window.height, event.touchPointID, 0, 0, event.pressure, 0);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
touch.x = x / parent.window.width;
|
||||||
|
touch.y = y / parent.window.height;
|
||||||
|
touch.id = event.touchPointID;
|
||||||
|
touch.dx = 0;
|
||||||
|
touch.dy = 0;
|
||||||
|
touch.pressure = event.pressure;
|
||||||
|
touch.device = 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
currentTouches.set (event.touchPointID, touch);
|
||||||
|
|
||||||
|
Touch.onStart.dispatch (touch);
|
||||||
|
|
||||||
|
if (event.isPrimaryTouchPoint) {
|
||||||
|
|
||||||
|
parent.window.onMouseDown.dispatch (x, y, 0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
case TouchEvent.TOUCH_END:
|
case TouchEvent.TOUCH_END:
|
||||||
|
|
||||||
parent.window.onTouchEnd.dispatch (x / parent.window.width, y / parent.window.height, id);
|
var touch = currentTouches.get (event.touchPointID);
|
||||||
parent.window.onMouseUp.dispatch (x, y, 0);
|
|
||||||
|
if (touch != null) {
|
||||||
|
|
||||||
|
var cacheX = touch.x;
|
||||||
|
var cacheY = touch.y;
|
||||||
|
|
||||||
|
touch.x = x / parent.window.width;
|
||||||
|
touch.y = y / parent.window.height;
|
||||||
|
touch.dx = touch.x - cacheX;
|
||||||
|
touch.dy = touch.y - cacheY;
|
||||||
|
touch.pressure = event.pressure;
|
||||||
|
|
||||||
|
Touch.onEnd.dispatch (touch);
|
||||||
|
|
||||||
|
currentTouches.remove (event.touchPointID);
|
||||||
|
unusedTouchesPool.add (touch);
|
||||||
|
|
||||||
|
if (event.isPrimaryTouchPoint) {
|
||||||
|
|
||||||
|
parent.window.onMouseUp.dispatch (x, y, 0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
case TouchEvent.TOUCH_MOVE:
|
||||||
|
|
||||||
|
var touch = currentTouches.get (event.touchPointID);
|
||||||
|
|
||||||
|
if (touch != null) {
|
||||||
|
|
||||||
|
var cacheX = touch.x;
|
||||||
|
var cacheY = touch.y;
|
||||||
|
|
||||||
|
touch.x = x / parent.window.width;
|
||||||
|
touch.y = y / parent.window.height;
|
||||||
|
touch.dx = touch.x - cacheX;
|
||||||
|
touch.dy = touch.y - cacheY;
|
||||||
|
touch.pressure = event.pressure;
|
||||||
|
|
||||||
|
Touch.onMove.dispatch (touch);
|
||||||
|
|
||||||
|
if (event.isPrimaryTouchPoint) {
|
||||||
|
|
||||||
|
parent.window.onMouseMove.dispatch (x, y);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -278,24 +367,6 @@ class FlashApplication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private function handleUpdateEvent (event:Event):Void {
|
|
||||||
|
|
||||||
var currentTime = Lib.getTimer ();
|
|
||||||
var deltaTime = currentTime - cacheTime;
|
|
||||||
cacheTime = currentTime;
|
|
||||||
|
|
||||||
parent.onUpdate.dispatch (deltaTime);
|
|
||||||
|
|
||||||
if (parent.renderer != null) {
|
|
||||||
|
|
||||||
parent.renderer.onRender.dispatch ();
|
|
||||||
parent.renderer.flip ();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private function handleWindowEvent (event:Event):Void {
|
private function handleWindowEvent (event:Event):Void {
|
||||||
|
|
||||||
if (parent.window != null) {
|
if (parent.window != null) {
|
||||||
|
|||||||
@@ -167,7 +167,7 @@ class HTML5Application {
|
|||||||
|
|
||||||
lastUpdate = Date.now ().getTime ();
|
lastUpdate = Date.now ().getTime ();
|
||||||
|
|
||||||
handleUpdateEvent ();
|
handleApplicationEvent ();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@@ -193,38 +193,7 @@ class HTML5Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private function handleKeyEvent (event:KeyboardEvent):Void {
|
private function handleApplicationEvent (?__):Void {
|
||||||
|
|
||||||
if (parent.window != null) {
|
|
||||||
|
|
||||||
// space and arrow keys
|
|
||||||
|
|
||||||
// switch (event.keyCode) {
|
|
||||||
|
|
||||||
// case 32, 37, 38, 39, 40: event.preventDefault ();
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
var keyCode = cast convertKeyCode (event.keyCode != null ? event.keyCode : event.which);
|
|
||||||
var modifier = (event.shiftKey ? (KeyModifier.SHIFT) : 0) | (event.ctrlKey ? (KeyModifier.CTRL) : 0) | (event.altKey ? (KeyModifier.ALT) : 0) | (event.metaKey ? (KeyModifier.META) : 0);
|
|
||||||
|
|
||||||
if (event.type == "keydown") {
|
|
||||||
|
|
||||||
Keyboard.onKeyDown.dispatch (keyCode, modifier);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
Keyboard.onKeyUp.dispatch (keyCode, modifier);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private function handleUpdateEvent (?__):Void {
|
|
||||||
|
|
||||||
currentUpdate = Date.now ().getTime ();
|
currentUpdate = Date.now ().getTime ();
|
||||||
|
|
||||||
@@ -271,7 +240,38 @@ class HTML5Application {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Browser.window.requestAnimationFrame (cast handleUpdateEvent);
|
Browser.window.requestAnimationFrame (cast handleApplicationEvent);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private function handleKeyEvent (event:KeyboardEvent):Void {
|
||||||
|
|
||||||
|
if (parent.window != null) {
|
||||||
|
|
||||||
|
// space and arrow keys
|
||||||
|
|
||||||
|
// switch (event.keyCode) {
|
||||||
|
|
||||||
|
// case 32, 37, 38, 39, 40: event.preventDefault ();
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
var keyCode = cast convertKeyCode (event.keyCode != null ? event.keyCode : event.which);
|
||||||
|
var modifier = (event.shiftKey ? (KeyModifier.SHIFT) : 0) | (event.ctrlKey ? (KeyModifier.CTRL) : 0) | (event.altKey ? (KeyModifier.ALT) : 0) | (event.metaKey ? (KeyModifier.META) : 0);
|
||||||
|
|
||||||
|
if (event.type == "keydown") {
|
||||||
|
|
||||||
|
Keyboard.onKeyDown.dispatch (keyCode, modifier);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
Keyboard.onKeyUp.dispatch (keyCode, modifier);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import lime.app.Application;
|
|||||||
import lime.graphics.Image;
|
import lime.graphics.Image;
|
||||||
import lime.system.Display;
|
import lime.system.Display;
|
||||||
import lime.system.System;
|
import lime.system.System;
|
||||||
|
import lime.ui.Touch;
|
||||||
import lime.ui.Window;
|
import lime.ui.Window;
|
||||||
|
|
||||||
#if (haxe_ver < 3.2)
|
#if (haxe_ver < 3.2)
|
||||||
@@ -43,10 +44,12 @@ class HTML5Window {
|
|||||||
public var stats:Dynamic;
|
public var stats:Dynamic;
|
||||||
#end
|
#end
|
||||||
|
|
||||||
|
private var currentTouches = new Map<Int, Touch> ();
|
||||||
private var enableTextEvents:Bool;
|
private var enableTextEvents:Bool;
|
||||||
private var parent:Window;
|
private var parent:Window;
|
||||||
private var setHeight:Int;
|
private var setHeight:Int;
|
||||||
private var setWidth:Int;
|
private var setWidth:Int;
|
||||||
|
private var unusedTouchesPool = new List<Touch> ();
|
||||||
|
|
||||||
|
|
||||||
public function new (parent:Window) {
|
public function new (parent:Window) {
|
||||||
@@ -366,60 +369,131 @@ class HTML5Window {
|
|||||||
|
|
||||||
event.preventDefault ();
|
event.preventDefault ();
|
||||||
|
|
||||||
var touch = event.changedTouches[0];
|
var rect = null;
|
||||||
var id = touch.identifier;
|
|
||||||
var x = 0.0;
|
|
||||||
var y = 0.0;
|
|
||||||
|
|
||||||
if (element != null) {
|
if (element != null) {
|
||||||
|
|
||||||
if (canvas != null) {
|
if (canvas != null) {
|
||||||
|
|
||||||
var rect = canvas.getBoundingClientRect ();
|
rect = canvas.getBoundingClientRect ();
|
||||||
x = (touch.clientX - rect.left) * (parent.width / rect.width);
|
|
||||||
y = (touch.clientY - rect.top) * (parent.height / rect.height);
|
|
||||||
|
|
||||||
} else if (div != null) {
|
} else if (div != null) {
|
||||||
|
|
||||||
var rect = div.getBoundingClientRect ();
|
rect = div.getBoundingClientRect ();
|
||||||
//eventInfo.x = (event.clientX - rect.left) * (window.div.style.width / rect.width);
|
|
||||||
x = (touch.clientX - rect.left);
|
|
||||||
//eventInfo.y = (event.clientY - rect.top) * (window.div.style.height / rect.height);
|
|
||||||
y = (touch.clientY - rect.top);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
var rect = element.getBoundingClientRect ();
|
rect = element.getBoundingClientRect ();
|
||||||
x = (touch.clientX - rect.left) * (parent.width / rect.width);
|
|
||||||
y = (touch.clientY - rect.top) * (parent.height / rect.height);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
x = touch.clientX;
|
|
||||||
y = touch.clientY;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (event.type) {
|
for (data in event.changedTouches) {
|
||||||
|
|
||||||
case "touchstart":
|
var x = 0.0;
|
||||||
|
var y = 0.0;
|
||||||
|
|
||||||
|
if (rect != null) {
|
||||||
|
|
||||||
parent.onTouchStart.dispatch (x / setWidth, y / setHeight, id);
|
x = (data.clientX - rect.left) * (parent.width / rect.width);
|
||||||
parent.onMouseDown.dispatch (x, y, 0);
|
y = (data.clientY - rect.top) * (parent.height / rect.height);
|
||||||
|
|
||||||
case "touchmove":
|
|
||||||
|
|
||||||
parent.onTouchMove.dispatch (x / setWidth, y / setHeight, id);
|
} else {
|
||||||
parent.onMouseMove.dispatch (x, y);
|
|
||||||
|
|
||||||
case "touchend":
|
|
||||||
|
|
||||||
parent.onTouchEnd.dispatch (x / setWidth, y / setHeight, id);
|
x = data.clientX;
|
||||||
parent.onMouseUp.dispatch (x, y, 0);
|
y = data.clientY;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
switch (event.type) {
|
||||||
|
|
||||||
|
case "touchstart":
|
||||||
|
|
||||||
|
var touch = unusedTouchesPool.pop ();
|
||||||
|
|
||||||
|
if (touch == null) {
|
||||||
|
|
||||||
|
touch = new Touch (x / setWidth, y / setHeight, data.identifier, 0, 0, data.force, parent.id);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
touch.x = x / setWidth;
|
||||||
|
touch.y = y / setHeight;
|
||||||
|
touch.id = data.identifier;
|
||||||
|
touch.dx = 0;
|
||||||
|
touch.dy = 0;
|
||||||
|
touch.pressure = data.force;
|
||||||
|
touch.device = parent.id;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
currentTouches.set (data.identifier, touch);
|
||||||
|
|
||||||
|
Touch.onStart.dispatch (touch);
|
||||||
|
|
||||||
|
if (data == event.touches[0]) {
|
||||||
|
|
||||||
|
parent.onMouseDown.dispatch (x, y, 0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
case "touchend":
|
||||||
|
|
||||||
|
var touch = currentTouches.get (data.identifier);
|
||||||
|
|
||||||
|
if (touch != null) {
|
||||||
|
|
||||||
|
var cacheX = touch.x;
|
||||||
|
var cacheY = touch.y;
|
||||||
|
|
||||||
|
touch.x = x / setWidth;
|
||||||
|
touch.y = y / setHeight;
|
||||||
|
touch.dx = touch.x - cacheX;
|
||||||
|
touch.dy = touch.y - cacheY;
|
||||||
|
touch.pressure = data.force;
|
||||||
|
|
||||||
|
Touch.onEnd.dispatch (touch);
|
||||||
|
|
||||||
|
currentTouches.remove (data.identifier);
|
||||||
|
unusedTouchesPool.add (touch);
|
||||||
|
|
||||||
|
if (data == event.touches[0]) {
|
||||||
|
|
||||||
|
parent.onMouseUp.dispatch (x, y, 0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
case "touchmove":
|
||||||
|
|
||||||
|
var touch = currentTouches.get (data.identifier);
|
||||||
|
|
||||||
|
if (touch != null) {
|
||||||
|
|
||||||
|
var cacheX = touch.x;
|
||||||
|
var cacheY = touch.y;
|
||||||
|
|
||||||
|
touch.x = x / setWidth;
|
||||||
|
touch.y = y / setHeight;
|
||||||
|
touch.dx = touch.x - cacheX;
|
||||||
|
touch.dy = touch.y - cacheY;
|
||||||
|
touch.pressure = data.force;
|
||||||
|
|
||||||
|
Touch.onMove.dispatch (touch);
|
||||||
|
|
||||||
|
if (data == event.touches[0]) {
|
||||||
|
|
||||||
|
parent.onMouseMove.dispatch (x, y);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import lime.system.DisplayMode;
|
|||||||
import lime.system.System;
|
import lime.system.System;
|
||||||
import lime.ui.Gamepad;
|
import lime.ui.Gamepad;
|
||||||
import lime.ui.Keyboard;
|
import lime.ui.Keyboard;
|
||||||
|
import lime.ui.Touch;
|
||||||
import lime.ui.Window;
|
import lime.ui.Window;
|
||||||
|
|
||||||
@:access(haxe.Timer)
|
@:access(haxe.Timer)
|
||||||
@@ -29,12 +30,14 @@ class NativeApplication {
|
|||||||
|
|
||||||
|
|
||||||
private var applicationEventInfo = new ApplicationEventInfo (UPDATE);
|
private var applicationEventInfo = new ApplicationEventInfo (UPDATE);
|
||||||
|
private var currentTouches = new Map<Int, Touch> ();
|
||||||
private var gamepadEventInfo = new GamepadEventInfo ();
|
private var gamepadEventInfo = new GamepadEventInfo ();
|
||||||
private var keyEventInfo = new KeyEventInfo ();
|
private var keyEventInfo = new KeyEventInfo ();
|
||||||
private var mouseEventInfo = new MouseEventInfo ();
|
private var mouseEventInfo = new MouseEventInfo ();
|
||||||
private var renderEventInfo = new RenderEventInfo (RENDER);
|
private var renderEventInfo = new RenderEventInfo (RENDER);
|
||||||
private var textEventInfo = new TextEventInfo ();
|
private var textEventInfo = new TextEventInfo ();
|
||||||
private var touchEventInfo = new TouchEventInfo ();
|
private var touchEventInfo = new TouchEventInfo ();
|
||||||
|
private var unusedTouchesPool = new List<Touch> ();
|
||||||
private var windowEventInfo = new WindowEventInfo ();
|
private var windowEventInfo = new WindowEventInfo ();
|
||||||
|
|
||||||
public var handle:Dynamic;
|
public var handle:Dynamic;
|
||||||
@@ -314,28 +317,68 @@ class NativeApplication {
|
|||||||
|
|
||||||
private function handleTouchEvent ():Void {
|
private function handleTouchEvent ():Void {
|
||||||
|
|
||||||
//var window = parent.windows.get (touchEventInfo.windowID);
|
switch (touchEventInfo.type) {
|
||||||
var window = parent.window;
|
|
||||||
|
|
||||||
if (window != null) {
|
|
||||||
|
|
||||||
switch (touchEventInfo.type) {
|
case TOUCH_START:
|
||||||
|
|
||||||
case TOUCH_START:
|
var touch = unusedTouchesPool.pop ();
|
||||||
|
|
||||||
|
if (touch == null) {
|
||||||
|
|
||||||
window.onTouchStart.dispatch (touchEventInfo.x, touchEventInfo.y, touchEventInfo.id);
|
touch = new Touch (touchEventInfo.x, touchEventInfo.x, touchEventInfo.id, touchEventInfo.dx, touchEventInfo.dy, touchEventInfo.pressure, touchEventInfo.device);
|
||||||
|
|
||||||
case TOUCH_END:
|
|
||||||
|
|
||||||
window.onTouchEnd.dispatch (touchEventInfo.x, touchEventInfo.y, touchEventInfo.id);
|
} else {
|
||||||
|
|
||||||
case TOUCH_MOVE:
|
|
||||||
|
|
||||||
window.onTouchMove.dispatch (touchEventInfo.x, touchEventInfo.y, touchEventInfo.id);
|
touch.x = touchEventInfo.x;
|
||||||
|
touch.y = touchEventInfo.y;
|
||||||
|
touch.id = touchEventInfo.id;
|
||||||
|
touch.dx = touchEventInfo.dx;
|
||||||
|
touch.dy = touchEventInfo.dy;
|
||||||
|
touch.pressure = touchEventInfo.pressure;
|
||||||
|
touch.device = touchEventInfo.device;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
currentTouches.set (touch.id, touch);
|
||||||
|
|
||||||
}
|
Touch.onStart.dispatch (touch);
|
||||||
|
|
||||||
|
case TOUCH_END:
|
||||||
|
|
||||||
|
var touch = currentTouches.get (touchEventInfo.id);
|
||||||
|
|
||||||
|
if (touch != null) {
|
||||||
|
|
||||||
|
touch.x = touchEventInfo.x;
|
||||||
|
touch.y = touchEventInfo.y;
|
||||||
|
touch.dx = touchEventInfo.dx;
|
||||||
|
touch.dy = touchEventInfo.dy;
|
||||||
|
touch.pressure = touchEventInfo.pressure;
|
||||||
|
|
||||||
|
Touch.onEnd.dispatch (touch);
|
||||||
|
|
||||||
|
currentTouches.remove (touchEventInfo.id);
|
||||||
|
unusedTouchesPool.add (touch);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
case TOUCH_MOVE:
|
||||||
|
|
||||||
|
var touch = currentTouches.get (touchEventInfo.id);
|
||||||
|
|
||||||
|
if (touch != null) {
|
||||||
|
|
||||||
|
touch.x = touchEventInfo.x;
|
||||||
|
touch.y = touchEventInfo.y;
|
||||||
|
touch.dx = touchEventInfo.dx;
|
||||||
|
touch.dy = touchEventInfo.dy;
|
||||||
|
touch.pressure = touchEventInfo.pressure;
|
||||||
|
|
||||||
|
Touch.onMove.dispatch (touch);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -716,27 +759,33 @@ private class TextEventInfo {
|
|||||||
private class TouchEventInfo {
|
private class TouchEventInfo {
|
||||||
|
|
||||||
|
|
||||||
|
public var device:Int;
|
||||||
|
public var dx:Float;
|
||||||
|
public var dy:Float;
|
||||||
public var id:Int;
|
public var id:Int;
|
||||||
|
public var pressure:Float;
|
||||||
public var type:TouchEventType;
|
public var type:TouchEventType;
|
||||||
public var windowID:Int;
|
|
||||||
public var x:Float;
|
public var x:Float;
|
||||||
public var y:Float;
|
public var y:Float;
|
||||||
|
|
||||||
|
|
||||||
public function new (type:TouchEventType = null, windowID:Int = 0, x:Float = 0, y:Float = 0, id:Int = 0) {
|
public function new (type:TouchEventType = null, x:Float = 0, y:Float = 0, id:Int = 0, dx:Float = 0, dy:Float = 0, pressure:Float = 0, device:Int = 0) {
|
||||||
|
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.windowID = windowID;
|
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
this.dx = dx;
|
||||||
|
this.dy = dy;
|
||||||
|
this.pressure = pressure;
|
||||||
|
this.device = device;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function clone ():TouchEventInfo {
|
public function clone ():TouchEventInfo {
|
||||||
|
|
||||||
return new TouchEventInfo (type, windowID, x, y, id);
|
return new TouchEventInfo (type, x, y, id, dx, dy, pressure, device);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import lime.ui.GamepadButton;
|
|||||||
import lime.ui.Keyboard;
|
import lime.ui.Keyboard;
|
||||||
import lime.ui.KeyCode;
|
import lime.ui.KeyCode;
|
||||||
import lime.ui.KeyModifier;
|
import lime.ui.KeyModifier;
|
||||||
|
import lime.ui.Touch;
|
||||||
import lime.ui.Window;
|
import lime.ui.Window;
|
||||||
|
|
||||||
|
|
||||||
@@ -63,6 +64,9 @@ class Application extends Module {
|
|||||||
Gamepad.onConnect.add (onGamepadConnect);
|
Gamepad.onConnect.add (onGamepadConnect);
|
||||||
Keyboard.onKeyDown.add (onKeyDown);
|
Keyboard.onKeyDown.add (onKeyDown);
|
||||||
Keyboard.onKeyUp.add (onKeyUp);
|
Keyboard.onKeyUp.add (onKeyUp);
|
||||||
|
Touch.onStart.add (onTouchStart);
|
||||||
|
Touch.onMove.add (onTouchMove);
|
||||||
|
Touch.onEnd.add (onTouchEnd);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,9 +143,6 @@ class Application extends Module {
|
|||||||
window.onRestore.add (onWindowRestore.bind (window));
|
window.onRestore.add (onWindowRestore.bind (window));
|
||||||
window.onTextEdit.add (onTextEdit.bind (window));
|
window.onTextEdit.add (onTextEdit.bind (window));
|
||||||
window.onTextInput.add (onTextInput.bind (window));
|
window.onTextInput.add (onTextInput.bind (window));
|
||||||
window.onTouchStart.add (onTouchStart.bind (window));
|
|
||||||
window.onTouchMove.add (onTouchMove.bind (window));
|
|
||||||
window.onTouchEnd.add (onTouchEnd.bind (window));
|
|
||||||
|
|
||||||
window.create (this);
|
window.create (this);
|
||||||
windows.set (window.id, window);
|
windows.set (window.id, window);
|
||||||
@@ -410,33 +411,33 @@ class Application extends Module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public override function onTouchEnd (window:Window, x:Float, y:Float, id:Int):Void {
|
public override function onTouchEnd (touch:Touch):Void {
|
||||||
|
|
||||||
for (module in modules) {
|
for (module in modules) {
|
||||||
|
|
||||||
module.onTouchEnd (window, x, y, id);
|
module.onTouchEnd (touch);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public override function onTouchMove (window:Window, x:Float, y:Float, id:Int):Void {
|
public override function onTouchMove (touch:Touch):Void {
|
||||||
|
|
||||||
for (module in modules) {
|
for (module in modules) {
|
||||||
|
|
||||||
module.onTouchMove (window, x, y, id);
|
module.onTouchMove (touch);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public override function onTouchStart (window:Window, x:Float, y:Float, id:Int):Void {
|
public override function onTouchStart (touch:Touch):Void {
|
||||||
|
|
||||||
for (module in modules) {
|
for (module in modules) {
|
||||||
|
|
||||||
module.onTouchStart (window, x, y, id);
|
module.onTouchStart (touch);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import lime.ui.GamepadAxis;
|
|||||||
import lime.ui.GamepadButton;
|
import lime.ui.GamepadButton;
|
||||||
import lime.ui.KeyCode;
|
import lime.ui.KeyCode;
|
||||||
import lime.ui.KeyModifier;
|
import lime.ui.KeyModifier;
|
||||||
|
import lime.ui.Touch;
|
||||||
import lime.ui.Window;
|
import lime.ui.Window;
|
||||||
|
|
||||||
|
|
||||||
@@ -180,32 +181,23 @@ interface IModule {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a touch end event is fired
|
* Called when a touch end event is fired
|
||||||
* @param window The window dispatching the event
|
* @param touch The current touch object
|
||||||
* @param x The current x coordinate of the touch point
|
|
||||||
* @param y The current y coordinate of the touch point
|
|
||||||
* @param id The ID of the touch point
|
|
||||||
*/
|
*/
|
||||||
public function onTouchEnd (window:Window, x:Float, y:Float, id:Int):Void;
|
public function onTouchEnd (touch:Touch):Void;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a touch move event is fired
|
* Called when a touch move event is fired
|
||||||
* @param window The window dispatching the event
|
* @param touch The current touch object
|
||||||
* @param x The current x coordinate of the touch point
|
|
||||||
* @param y The current y coordinate of the touch point
|
|
||||||
* @param id The ID of the touch point
|
|
||||||
*/
|
*/
|
||||||
public function onTouchMove (window:Window, x:Float, y:Float, id:Int):Void;
|
public function onTouchMove (touch:Touch):Void;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a touch start event is fired
|
* Called when a touch start event is fired
|
||||||
* @param window The window dispatching the event
|
* @param touch The current touch object
|
||||||
* @param x The current x coordinate of the touch point
|
|
||||||
* @param y The current y coordinate of the touch point
|
|
||||||
* @param id The ID of the touch point
|
|
||||||
*/
|
*/
|
||||||
public function onTouchStart (window:Window, x:Float, y:Float, id:Int):Void;
|
public function onTouchStart (touch:Touch):Void;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import lime.ui.GamepadAxis;
|
|||||||
import lime.ui.GamepadButton;
|
import lime.ui.GamepadButton;
|
||||||
import lime.ui.KeyCode;
|
import lime.ui.KeyCode;
|
||||||
import lime.ui.KeyModifier;
|
import lime.ui.KeyModifier;
|
||||||
|
import lime.ui.Touch;
|
||||||
import lime.ui.Window;
|
import lime.ui.Window;
|
||||||
|
|
||||||
|
|
||||||
@@ -193,32 +194,23 @@ class Module implements IModule {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a touch end event is fired
|
* Called when a touch end event is fired
|
||||||
* @param window The window dispatching the event
|
* @param touch The current touch object
|
||||||
* @param x The current x coordinate of the touch point
|
|
||||||
* @param y The current y coordinate of the touch point
|
|
||||||
* @param id The ID of the touch point
|
|
||||||
*/
|
*/
|
||||||
public function onTouchEnd (window:Window, x:Float, y:Float, id:Int):Void { }
|
public function onTouchEnd (touch:Touch):Void { }
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a touch move event is fired
|
* Called when a touch move event is fired
|
||||||
* @param window The window dispatching the event
|
* @param touch The current touch object
|
||||||
* @param x The current x coordinate of the touch point
|
|
||||||
* @param y The current y coordinate of the touch point
|
|
||||||
* @param id The ID of the touch point
|
|
||||||
*/
|
*/
|
||||||
public function onTouchMove (window:Window, x:Float, y:Float, id:Int):Void { }
|
public function onTouchMove (touch:Touch):Void { }
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a touch start event is fired
|
* Called when a touch start event is fired
|
||||||
* @param window The window dispatching the event
|
* @param touch The current touch object
|
||||||
* @param x The current x coordinate of the touch point
|
|
||||||
* @param y The current y coordinate of the touch point
|
|
||||||
* @param id The ID of the touch point
|
|
||||||
*/
|
*/
|
||||||
public function onTouchStart (window:Window, x:Float, y:Float, id:Int):Void { }
|
public function onTouchStart (touch:Touch):Void { }
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
36
lime/ui/Touch.hx
Normal file
36
lime/ui/Touch.hx
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
package lime.ui;
|
||||||
|
|
||||||
|
|
||||||
|
import lime.app.Event;
|
||||||
|
|
||||||
|
|
||||||
|
class Touch {
|
||||||
|
|
||||||
|
|
||||||
|
public static var onEnd = new Event<Touch->Void> ();
|
||||||
|
public static var onMove = new Event<Touch->Void> ();
|
||||||
|
public static var onStart = new Event<Touch->Void> ();
|
||||||
|
|
||||||
|
public var device:Int;
|
||||||
|
public var dx:Float;
|
||||||
|
public var dy:Float;
|
||||||
|
public var id:Int;
|
||||||
|
public var pressure:Float;
|
||||||
|
public var x:Float;
|
||||||
|
public var y:Float;
|
||||||
|
|
||||||
|
|
||||||
|
public function new (x:Float, y:Float, id:Int, dx:Float, dy:Float, pressure:Float, device:Int) {
|
||||||
|
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.id = id;
|
||||||
|
this.dx = dx;
|
||||||
|
this.dy = dy;
|
||||||
|
this.pressure = pressure;
|
||||||
|
this.device = device;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -40,9 +40,6 @@ class Window {
|
|||||||
public var onRestore = new Event<Void->Void> ();
|
public var onRestore = new Event<Void->Void> ();
|
||||||
public var onTextEdit = new Event<String->Int->Int->Void> ();
|
public var onTextEdit = new Event<String->Int->Int->Void> ();
|
||||||
public var onTextInput = new Event<String->Void> ();
|
public var onTextInput = new Event<String->Void> ();
|
||||||
public var onTouchEnd = new Event<Float->Float->Int->Void> ();
|
|
||||||
public var onTouchMove = new Event<Float->Float->Int->Void> ();
|
|
||||||
public var onTouchStart = new Event<Float->Float->Int->Void> ();
|
|
||||||
public var title (get, set):String;
|
public var title (get, set):String;
|
||||||
public var width (get, set):Int;
|
public var width (get, set):Int;
|
||||||
public var x (get, set):Int;
|
public var x (get, set):Int;
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <hx/CFFI.h>
|
#include <hx/CFFI.h>
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
|
|
||||||
namespace lime {
|
namespace lime {
|
||||||
@@ -29,11 +28,14 @@ namespace lime {
|
|||||||
|
|
||||||
static void Dispatch (TouchEvent* event);
|
static void Dispatch (TouchEvent* event);
|
||||||
|
|
||||||
|
int device;
|
||||||
|
float dx;
|
||||||
|
float dy;
|
||||||
int id;
|
int id;
|
||||||
|
float pressure;
|
||||||
TouchEventType type;
|
TouchEventType type;
|
||||||
uint32_t windowID;
|
float x;
|
||||||
double x;
|
float y;
|
||||||
double y;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -429,30 +429,28 @@ namespace lime {
|
|||||||
case SDL_FINGERMOTION:
|
case SDL_FINGERMOTION:
|
||||||
|
|
||||||
touchEvent.type = TOUCH_MOVE;
|
touchEvent.type = TOUCH_MOVE;
|
||||||
touchEvent.x = event->tfinger.x;
|
|
||||||
touchEvent.y = event->tfinger.y;
|
|
||||||
touchEvent.id = event->tfinger.fingerId;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_FINGERDOWN:
|
case SDL_FINGERDOWN:
|
||||||
|
|
||||||
touchEvent.type = TOUCH_START;
|
touchEvent.type = TOUCH_START;
|
||||||
touchEvent.x = event->tfinger.x;
|
|
||||||
touchEvent.y = event->tfinger.y;
|
|
||||||
touchEvent.id = event->tfinger.fingerId;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_FINGERUP:
|
case SDL_FINGERUP:
|
||||||
|
|
||||||
touchEvent.type = TOUCH_END;
|
touchEvent.type = TOUCH_END;
|
||||||
touchEvent.x = event->tfinger.x;
|
|
||||||
touchEvent.y = event->tfinger.y;
|
|
||||||
touchEvent.id = event->tfinger.fingerId;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//touchEvent.windowID = event->tfinger.windowID;
|
touchEvent.x = event->tfinger.x;
|
||||||
|
touchEvent.y = event->tfinger.y;
|
||||||
|
touchEvent.id = event->tfinger.fingerId;
|
||||||
|
touchEvent.dx = event->tfinger.dx;
|
||||||
|
touchEvent.dy = event->tfinger.dy;
|
||||||
|
touchEvent.pressure = event->tfinger.pressure;
|
||||||
|
touchEvent.device = event->tfinger.touchId;
|
||||||
|
|
||||||
TouchEvent::Dispatch (&touchEvent);
|
TouchEvent::Dispatch (&touchEvent);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,9 +8,12 @@ namespace lime {
|
|||||||
AutoGCRoot* TouchEvent::callback = 0;
|
AutoGCRoot* TouchEvent::callback = 0;
|
||||||
AutoGCRoot* TouchEvent::eventObject = 0;
|
AutoGCRoot* TouchEvent::eventObject = 0;
|
||||||
|
|
||||||
|
static int id_device;
|
||||||
|
static int id_dx;
|
||||||
|
static int id_dy;
|
||||||
static int id_id;
|
static int id_id;
|
||||||
|
static int id_pressure;
|
||||||
static int id_type;
|
static int id_type;
|
||||||
static int id_windowID;
|
|
||||||
static int id_x;
|
static int id_x;
|
||||||
static int id_y;
|
static int id_y;
|
||||||
static bool init = false;
|
static bool init = false;
|
||||||
@@ -18,11 +21,14 @@ namespace lime {
|
|||||||
|
|
||||||
TouchEvent::TouchEvent () {
|
TouchEvent::TouchEvent () {
|
||||||
|
|
||||||
id = 0;
|
|
||||||
type = TOUCH_START;
|
type = TOUCH_START;
|
||||||
windowID = 0;
|
|
||||||
x = 0;
|
x = 0;
|
||||||
y = 0;
|
y = 0;
|
||||||
|
id = 0;
|
||||||
|
dx = 0;
|
||||||
|
dy = 0;
|
||||||
|
pressure = 0;
|
||||||
|
device = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,9 +39,12 @@ namespace lime {
|
|||||||
|
|
||||||
if (!init) {
|
if (!init) {
|
||||||
|
|
||||||
|
id_device = val_id ("device");
|
||||||
|
id_dx = val_id ("dx");
|
||||||
|
id_dy = val_id ("dy");
|
||||||
id_id = val_id ("id");
|
id_id = val_id ("id");
|
||||||
|
id_pressure = val_id ("pressure");
|
||||||
id_type = val_id ("type");
|
id_type = val_id ("type");
|
||||||
id_windowID = val_id ("windowID");
|
|
||||||
id_x = val_id ("x");
|
id_x = val_id ("x");
|
||||||
id_y = val_id ("y");
|
id_y = val_id ("y");
|
||||||
init = true;
|
init = true;
|
||||||
@@ -44,9 +53,12 @@ namespace lime {
|
|||||||
|
|
||||||
value object = (TouchEvent::eventObject ? TouchEvent::eventObject->get () : alloc_empty_object ());
|
value object = (TouchEvent::eventObject ? TouchEvent::eventObject->get () : alloc_empty_object ());
|
||||||
|
|
||||||
|
alloc_field (object, id_device, alloc_int (event->device));
|
||||||
|
alloc_field (object, id_dx, alloc_float (event->dx));
|
||||||
|
alloc_field (object, id_dy, alloc_float (event->dy));
|
||||||
alloc_field (object, id_id, alloc_int (event->id));
|
alloc_field (object, id_id, alloc_int (event->id));
|
||||||
|
alloc_field (object, id_pressure, alloc_float (event->pressure));
|
||||||
alloc_field (object, id_type, alloc_int (event->type));
|
alloc_field (object, id_type, alloc_int (event->type));
|
||||||
alloc_field (object, id_windowID, alloc_int (event->windowID));
|
|
||||||
alloc_field (object, id_x, alloc_float (event->x));
|
alloc_field (object, id_x, alloc_float (event->x));
|
||||||
alloc_field (object, id_y, alloc_float (event->y));
|
alloc_field (object, id_y, alloc_float (event->y));
|
||||||
|
|
||||||
@@ -57,4 +69,4 @@ namespace lime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user