Make event managers always static
This commit is contained in:
@@ -101,12 +101,9 @@ class Application {
|
||||
handle = lime_application_create (null);
|
||||
#end
|
||||
|
||||
new KeyEventManager ();
|
||||
new MouseEventManager ();
|
||||
//new RenderEventManager ();
|
||||
new TouchEventManager ();
|
||||
//new UpdateEventManager ();
|
||||
//new WindowEventManager ();
|
||||
KeyEventManager.create ();
|
||||
MouseEventManager.create ();
|
||||
TouchEventManager.create ();
|
||||
|
||||
KeyEventManager.onKeyDown.add (onKeyDown);
|
||||
KeyEventManager.onKeyUp.add (onKeyUp);
|
||||
|
||||
@@ -11,48 +11,41 @@ import flash.Lib;
|
||||
#end
|
||||
|
||||
|
||||
@:allow(lime.ui.Window)
|
||||
class KeyEventManager {
|
||||
|
||||
|
||||
public static var onKeyDown = new Event<Int->Int->Void> ();
|
||||
public static var onKeyUp = new Event<Int->Int->Void> ();
|
||||
|
||||
private static var instance:KeyEventManager;
|
||||
private var eventInfo:KeyEventInfo;
|
||||
private static var eventInfo:KeyEventInfo;
|
||||
|
||||
|
||||
public function new () {
|
||||
public static function create ():Void {
|
||||
|
||||
instance = this;
|
||||
eventInfo = new KeyEventInfo ();
|
||||
|
||||
#if (cpp || neko)
|
||||
lime_key_event_manager_register (dispatch, eventInfo);
|
||||
#if js
|
||||
|
||||
Browser.window.addEventListener ("keydown", handleEvent, false);
|
||||
Browser.window.addEventListener ("keyup", handleEvent, false);
|
||||
|
||||
#elseif flash
|
||||
|
||||
Lib.current.stage.addEventListener (flash.events.KeyboardEvent.KEY_DOWN, handleEvent);
|
||||
Lib.current.stage.addEventListener (flash.events.KeyboardEvent.KEY_UP, handleEvent);
|
||||
|
||||
#elseif (cpp || neko)
|
||||
|
||||
lime_key_event_manager_register (handleEvent, eventInfo);
|
||||
|
||||
#end
|
||||
|
||||
}
|
||||
|
||||
|
||||
private function dispatch ():Void {
|
||||
private static function handleEvent (#if js event:js.html.KeyboardEvent #elseif flash event:flash.events.KeyboardEvent #end):Void {
|
||||
|
||||
switch (eventInfo.type) {
|
||||
|
||||
case KEY_DOWN:
|
||||
|
||||
onKeyDown.dispatch (eventInfo.keyCode, eventInfo.modifier);
|
||||
|
||||
case KEY_UP:
|
||||
|
||||
onKeyUp.dispatch (eventInfo.keyCode, eventInfo.modifier);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#if js
|
||||
private function handleDOMEvent (event:js.html.KeyboardEvent):Void {
|
||||
#if js
|
||||
|
||||
//keyEvent.code = event.code;
|
||||
eventInfo.keyCode = (event.keyCode != null ? event.keyCode : event.which);
|
||||
@@ -67,14 +60,8 @@ class KeyEventManager {
|
||||
//keyEvent.metaKey = event.metaKey;
|
||||
|
||||
eventInfo.type = (event.type == "keydown" ? KEY_DOWN : KEY_UP);
|
||||
dispatch ();
|
||||
|
||||
}
|
||||
#end
|
||||
|
||||
|
||||
#if flash
|
||||
private function handleFlashEvent (event:flash.events.KeyboardEvent):Void {
|
||||
#elseif flash
|
||||
|
||||
eventInfo.keyCode = event.keyCode;
|
||||
//keyEvent.key = event.charCode;
|
||||
@@ -85,23 +72,18 @@ class KeyEventManager {
|
||||
//keyEvent.metaKey = event.commandKey;
|
||||
|
||||
eventInfo.type = (event.type == flash.events.KeyboardEvent.KEY_DOWN ? KEY_DOWN : KEY_UP);
|
||||
dispatch ();
|
||||
|
||||
}
|
||||
#end
|
||||
|
||||
|
||||
private static function registerWindow (_):Void {
|
||||
#end
|
||||
|
||||
if (instance != null) {
|
||||
switch (eventInfo.type) {
|
||||
|
||||
#if js
|
||||
Browser.window.addEventListener ("keydown", instance.handleDOMEvent, false);
|
||||
Browser.window.addEventListener ("keyup", instance.handleDOMEvent, false);
|
||||
#elseif flash
|
||||
Lib.current.stage.addEventListener (flash.events.KeyboardEvent.KEY_DOWN, instance.handleFlashEvent);
|
||||
Lib.current.stage.addEventListener (flash.events.KeyboardEvent.KEY_UP, instance.handleFlashEvent);
|
||||
#end
|
||||
case KEY_DOWN:
|
||||
|
||||
onKeyDown.dispatch (eventInfo.keyCode, eventInfo.modifier);
|
||||
|
||||
case KEY_UP:
|
||||
|
||||
onKeyUp.dispatch (eventInfo.keyCode, eventInfo.modifier);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -19,47 +19,24 @@ class MouseEventManager {
|
||||
public static var onMouseMove = new Event<Float->Float->Int->Void> ();
|
||||
public static var onMouseUp = new Event<Float->Float->Int->Void> ();
|
||||
|
||||
private static var instance:MouseEventManager;
|
||||
private var eventInfo:MouseEventInfo;
|
||||
private static var created:Bool;
|
||||
private static var eventInfo:MouseEventInfo;
|
||||
|
||||
|
||||
public function new () {
|
||||
public static function create ():Void {
|
||||
|
||||
instance = this;
|
||||
eventInfo = new MouseEventInfo ();
|
||||
|
||||
#if (cpp || neko)
|
||||
lime_mouse_event_manager_register (dispatch, eventInfo);
|
||||
lime_mouse_event_manager_register (handleEvent, eventInfo);
|
||||
#end
|
||||
|
||||
}
|
||||
|
||||
|
||||
private function dispatch ():Void {
|
||||
private static function handleEvent (#if js event:js.html.MouseEvent #elseif flash event:flash.events.MouseEvent #end):Void {
|
||||
|
||||
switch (eventInfo.type) {
|
||||
|
||||
case MOUSE_DOWN:
|
||||
|
||||
onMouseDown.dispatch (eventInfo.x, eventInfo.y, cast eventInfo.button);
|
||||
|
||||
case MOUSE_UP:
|
||||
|
||||
onMouseUp.dispatch (eventInfo.x, eventInfo.y, cast eventInfo.button);
|
||||
|
||||
case MOUSE_MOVE:
|
||||
|
||||
onMouseMove.dispatch (eventInfo.x, eventInfo.y, cast eventInfo.button);
|
||||
|
||||
default:
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#if js
|
||||
private function handleDOMEvent (event:js.html.MouseEvent):Void {
|
||||
#if js
|
||||
|
||||
/*
|
||||
var rect;
|
||||
@@ -96,14 +73,7 @@ class MouseEventManager {
|
||||
|
||||
}
|
||||
|
||||
dispatch ();
|
||||
|
||||
}
|
||||
#end
|
||||
|
||||
|
||||
#if flash
|
||||
private function handleFlashEvent (event:flash.events.MouseEvent):Void {
|
||||
#elseif flash
|
||||
|
||||
eventInfo.x = event.stageX;
|
||||
eventInfo.y = event.stageY;
|
||||
@@ -116,37 +86,54 @@ class MouseEventManager {
|
||||
|
||||
}
|
||||
|
||||
dispatch ();
|
||||
#end
|
||||
|
||||
switch (eventInfo.type) {
|
||||
|
||||
case MOUSE_DOWN:
|
||||
|
||||
onMouseDown.dispatch (eventInfo.x, eventInfo.y, cast eventInfo.button);
|
||||
|
||||
case MOUSE_UP:
|
||||
|
||||
onMouseUp.dispatch (eventInfo.x, eventInfo.y, cast eventInfo.button);
|
||||
|
||||
case MOUSE_MOVE:
|
||||
|
||||
onMouseMove.dispatch (eventInfo.x, eventInfo.y, cast eventInfo.button);
|
||||
|
||||
default:
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
#end
|
||||
|
||||
|
||||
private static function registerWindow (window:Window):Void {
|
||||
|
||||
if (instance != null) {
|
||||
|
||||
#if js
|
||||
window.element.addEventListener ("mousedown", instance.handleDOMEvent, true);
|
||||
window.element.addEventListener ("mousemove", instance.handleDOMEvent, true);
|
||||
window.element.addEventListener ("mouseup", instance.handleDOMEvent, true);
|
||||
//window.element.addEventListener ("mousewheel", handleDOMEvent, true);
|
||||
|
||||
// Disable image drag on Firefox
|
||||
/*Browser.document.addEventListener ("dragstart", function (e) {
|
||||
if (e.target.nodeName.toLowerCase() == "img") {
|
||||
e.preventDefault();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}, false);*/
|
||||
#elseif flash
|
||||
Lib.current.stage.addEventListener (flash.events.MouseEvent.MOUSE_DOWN, instance.handleFlashEvent);
|
||||
Lib.current.stage.addEventListener (flash.events.MouseEvent.MOUSE_MOVE, instance.handleFlashEvent);
|
||||
Lib.current.stage.addEventListener (flash.events.MouseEvent.MOUSE_UP, instance.handleFlashEvent);
|
||||
#end
|
||||
|
||||
}
|
||||
#if js
|
||||
|
||||
window.element.addEventListener ("mousedown", handleEvent, true);
|
||||
window.element.addEventListener ("mousemove", handleEvent, true);
|
||||
window.element.addEventListener ("mouseup", handleEvent, true);
|
||||
//window.element.addEventListener ("mousewheel", handleDOMEvent, true);
|
||||
|
||||
// Disable image drag on Firefox
|
||||
/*Browser.document.addEventListener ("dragstart", function (e) {
|
||||
if (e.target.nodeName.toLowerCase() == "img") {
|
||||
e.preventDefault();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}, false);*/
|
||||
|
||||
#elseif flash
|
||||
|
||||
Lib.current.stage.addEventListener (flash.events.MouseEvent.MOUSE_DOWN, handleEvent);
|
||||
Lib.current.stage.addEventListener (flash.events.MouseEvent.MOUSE_MOVE, handleEvent);
|
||||
Lib.current.stage.addEventListener (flash.events.MouseEvent.MOUSE_UP, handleEvent);
|
||||
|
||||
#end
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -11,53 +11,30 @@ import flash.Lib;
|
||||
#end
|
||||
|
||||
|
||||
@:allow(lime.ui.Window)
|
||||
class TouchEventManager {
|
||||
@:allow(lime.ui.Window) class TouchEventManager {
|
||||
|
||||
|
||||
public static var onTouchEnd = new Event<Float->Float->Int->Void> ();
|
||||
public static var onTouchMove = new Event<Float->Float->Int->Void> ();
|
||||
public static var onTouchStart = new Event<Float->Float->Int->Void> ();
|
||||
|
||||
private static var instance:TouchEventManager;
|
||||
private var eventInfo:TouchEventInfo;
|
||||
private static var eventInfo:TouchEventInfo;
|
||||
|
||||
|
||||
public function new () {
|
||||
public static function create ():Void {
|
||||
|
||||
instance = this;
|
||||
eventInfo = new TouchEventInfo ();
|
||||
|
||||
#if (cpp || neko)
|
||||
lime_touch_event_manager_register (dispatch, eventInfo);
|
||||
lime_touch_event_manager_register (handleEvent, eventInfo);
|
||||
#end
|
||||
|
||||
}
|
||||
|
||||
|
||||
private function dispatch ():Void {
|
||||
private static function handleEvent (#if js event:js.html.TouchEvent #elseif flash event:flash.events.TouchEvent #end):Void {
|
||||
|
||||
switch (eventInfo.type) {
|
||||
|
||||
case TOUCH_START:
|
||||
|
||||
onTouchStart.dispatch (eventInfo.x, eventInfo.y, eventInfo.id);
|
||||
|
||||
case TOUCH_END:
|
||||
|
||||
onTouchEnd.dispatch (eventInfo.x, eventInfo.y, eventInfo.id);
|
||||
|
||||
case TOUCH_MOVE:
|
||||
|
||||
onTouchMove.dispatch (eventInfo.x, eventInfo.y, eventInfo.id);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#if js
|
||||
private function handleDOMEvent (event:js.html.TouchEvent):Void {
|
||||
#if js
|
||||
|
||||
event.preventDefault ();
|
||||
|
||||
@@ -76,8 +53,6 @@ class TouchEventManager {
|
||||
|
||||
}
|
||||
|
||||
dispatch ();
|
||||
|
||||
/*
|
||||
event.preventDefault ();
|
||||
|
||||
@@ -126,12 +101,7 @@ class TouchEventManager {
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
#end
|
||||
|
||||
|
||||
#if flash
|
||||
private function handleFlashEvent (event:flash.events.TouchEvent):Void {
|
||||
#elseif flash
|
||||
|
||||
//touchEvent.id = event.touchPointID;
|
||||
eventInfo.x = event.stageX;
|
||||
@@ -145,28 +115,43 @@ class TouchEventManager {
|
||||
|
||||
}
|
||||
|
||||
dispatch ();
|
||||
#end
|
||||
|
||||
switch (eventInfo.type) {
|
||||
|
||||
case TOUCH_START:
|
||||
|
||||
onTouchStart.dispatch (eventInfo.x, eventInfo.y, eventInfo.id);
|
||||
|
||||
case TOUCH_END:
|
||||
|
||||
onTouchEnd.dispatch (eventInfo.x, eventInfo.y, eventInfo.id);
|
||||
|
||||
case TOUCH_MOVE:
|
||||
|
||||
onTouchMove.dispatch (eventInfo.x, eventInfo.y, eventInfo.id);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
#end
|
||||
|
||||
|
||||
private static function registerWindow (window:Window):Void {
|
||||
|
||||
if (instance != null) {
|
||||
|
||||
#if js
|
||||
window.element.addEventListener ("touchstart", instance.handleDOMEvent, true);
|
||||
window.element.addEventListener ("touchmove", instance.handleDOMEvent, true);
|
||||
window.element.addEventListener ("touchend", instance.handleDOMEvent, true);
|
||||
#elseif flash
|
||||
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
|
||||
Lib.current.stage.addEventListener (flash.events.TouchEvent.TOUCH_BEGIN, instance.handleFlashEvent);
|
||||
Lib.current.stage.addEventListener (flash.events.TouchEvent.TOUCH_MOVE, instance.handleFlashEvent);
|
||||
Lib.current.stage.addEventListener (flash.events.TouchEvent.TOUCH_END, instance.handleFlashEvent);
|
||||
#end
|
||||
|
||||
}
|
||||
#if js
|
||||
|
||||
window.element.addEventListener ("touchstart", handleEvent, true);
|
||||
window.element.addEventListener ("touchmove", handleEvent, true);
|
||||
window.element.addEventListener ("touchend", handleEvent, true);
|
||||
|
||||
#elseif flash
|
||||
|
||||
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
|
||||
Lib.current.stage.addEventListener (flash.events.TouchEvent.TOUCH_BEGIN, handleEvent);
|
||||
Lib.current.stage.addEventListener (flash.events.TouchEvent.TOUCH_MOVE, handleEvent);
|
||||
Lib.current.stage.addEventListener (flash.events.TouchEvent.TOUCH_END, handleEvent);
|
||||
|
||||
#end
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -184,7 +184,6 @@ class Window {
|
||||
handle = lime_window_create (application.handle, flags);
|
||||
#end
|
||||
|
||||
KeyEventManager.registerWindow (this);
|
||||
MouseEventManager.registerWindow (this);
|
||||
TouchEventManager.registerWindow (this);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user