From 0d0a9ea3b108e512a7e99ee72a98bac376a5e766 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Tue, 17 Jun 2014 18:30:42 -0700 Subject: [PATCH] Include button/id in mouse/touch events --- lime/app/Application.hx | 12 ++++++------ lime/ui/IMouseEventListener.hx | 6 +++--- lime/ui/ITouchEventListener.hx | 6 +++--- lime/ui/MouseEventInfo.hx | 17 +++++++++++++---- lime/ui/MouseEventManager.hx | 7 ++++--- lime/ui/TouchEventInfo.hx | 7 +++---- lime/ui/TouchEventManager.hx | 7 ++++--- project/include/ui/MouseEvent.h | 11 ++++++++++- project/src/backend/sdl/SDLApplication.cpp | 2 +- project/src/ui/MouseEvent.cpp | 8 ++++---- 10 files changed, 51 insertions(+), 32 deletions(-) diff --git a/lime/app/Application.hx b/lime/app/Application.hx index 354ed47ee..fe0fe6ea4 100644 --- a/lime/app/Application.hx +++ b/lime/app/Application.hx @@ -81,12 +81,12 @@ class Application implements IKeyEventListener implements IMouseEventListener im public function onKeyDown (keyCode:Int, modifier:Int):Void {} public function onKeyUp (keyCode:Int, modifier:Int):Void {} - public function onMouseDown (x:Float, y:Float):Void {} - public function onMouseMove (x:Float, y:Float):Void {} - public function onMouseUp (x:Float, y:Float):Void {} - public function onTouchEnd (x:Float, y:Float):Void {} - public function onTouchMove (x:Float, y:Float):Void {} - public function onTouchStart (x:Float, y:Float):Void {} + public function onMouseDown (x:Float, y:Float, button:Int):Void {} + public function onMouseMove (x:Float, y:Float, button:Int):Void {} + public function onMouseUp (x:Float, y:Float, button:Int):Void {} + public function onTouchEnd (x:Float, y:Float, id:Int):Void {} + public function onTouchMove (x:Float, y:Float, id:Int):Void {} + public function onTouchStart (x:Float, y:Float, id:Int):Void {} public function onWindowActivate ():Void {} public function onWindowDeactivate ():Void { } diff --git a/lime/ui/IMouseEventListener.hx b/lime/ui/IMouseEventListener.hx index a93ba14a4..b2bf78521 100644 --- a/lime/ui/IMouseEventListener.hx +++ b/lime/ui/IMouseEventListener.hx @@ -4,9 +4,9 @@ package lime.ui; interface IMouseEventListener { - function onMouseDown (x:Float, y:Float):Void; - function onMouseMove (x:Float, y:Float):Void; - function onMouseUp (x:Float, y:Float):Void; + function onMouseDown (x:Float, y:Float, button:Int):Void; + function onMouseMove (x:Float, y:Float, button:Int):Void; + function onMouseUp (x:Float, y:Float, button:Int):Void; } \ No newline at end of file diff --git a/lime/ui/ITouchEventListener.hx b/lime/ui/ITouchEventListener.hx index 5c7b6fffd..dc220739c 100644 --- a/lime/ui/ITouchEventListener.hx +++ b/lime/ui/ITouchEventListener.hx @@ -4,9 +4,9 @@ package lime.ui; interface ITouchEventListener { - function onTouchEnd (x:Float, y:Float):Void; - function onTouchMove (x:Float, y:Float):Void; - function onTouchStart (x:Float, y:Float):Void; + function onTouchEnd (x:Float, y:Float, id:Int):Void; + function onTouchMove (x:Float, y:Float, id:Int):Void; + function onTouchStart (x:Float, y:Float, id:Int):Void; } \ No newline at end of file diff --git a/lime/ui/MouseEventInfo.hx b/lime/ui/MouseEventInfo.hx index 79366941f..3fd699085 100644 --- a/lime/ui/MouseEventInfo.hx +++ b/lime/ui/MouseEventInfo.hx @@ -4,26 +4,26 @@ package lime.ui; class MouseEventInfo { - public var id:Int; + public var button:MouseEventButton; public var type:MouseEventType; public var x:Float; public var y:Float; - public function new (type:MouseEventType = null, id:Int = 0, x:Float = 0, y:Float = 0) { + public function new (type:MouseEventType = null, x:Float = 0, y:Float = 0, button:MouseEventButton = null) { - this.id = id; this.type = type; this.x = x; this.y = y; + this.button = button; } public function clone ():MouseEventInfo { - return new MouseEventInfo (type, id, x, y); + return new MouseEventInfo (type, x, y, button); } @@ -31,6 +31,15 @@ class MouseEventInfo { } +@:enum abstract MouseEventButton(Int) { + + var MOUSE_BUTTON_LEFT = 0; + var MOUSE_BUTTON_MIDDLE = 1; + var MOUSE_BUTTON_RIGHT = 2; + +} + + @:enum abstract MouseEventType(Int) { var MOUSE_DOWN = 0; diff --git a/lime/ui/MouseEventManager.hx b/lime/ui/MouseEventManager.hx index 466681f15..4d33c6d3f 100644 --- a/lime/ui/MouseEventManager.hx +++ b/lime/ui/MouseEventManager.hx @@ -49,6 +49,7 @@ class MouseEventManager extends EventManager { var x = eventInfo.x; var y = eventInfo.y; + var button:Int = cast eventInfo.button; switch (eventInfo.type) { @@ -56,7 +57,7 @@ class MouseEventManager extends EventManager { for (listener in listeners) { - listener.onMouseDown (x, y); + listener.onMouseDown (x, y, button); } @@ -64,7 +65,7 @@ class MouseEventManager extends EventManager { for (listener in listeners) { - listener.onMouseUp (x, y); + listener.onMouseUp (x, y, button); } @@ -72,7 +73,7 @@ class MouseEventManager extends EventManager { for (listener in listeners) { - listener.onMouseMove (x, y); + listener.onMouseMove (x, y, button); } diff --git a/lime/ui/TouchEventInfo.hx b/lime/ui/TouchEventInfo.hx index ba1335c21..096a84bc2 100644 --- a/lime/ui/TouchEventInfo.hx +++ b/lime/ui/TouchEventInfo.hx @@ -10,20 +10,19 @@ class TouchEventInfo { public var y:Float; - - public function new (type:TouchEventType = null, id:Int = 0, x:Float = 0, y:Float = 0) { + public function new (type:TouchEventType = null, x:Float = 0, y:Float = 0, id:Int = 0) { this.type = type; - this.id = id; this.x = x; this.y = y; + this.id = id; } public function clone ():TouchEventInfo { - return new TouchEventInfo (type, id, x, y); + return new TouchEventInfo (type, x, y, id); } diff --git a/lime/ui/TouchEventManager.hx b/lime/ui/TouchEventManager.hx index 693048c0c..19baa0a1e 100644 --- a/lime/ui/TouchEventManager.hx +++ b/lime/ui/TouchEventManager.hx @@ -49,6 +49,7 @@ class TouchEventManager extends EventManager { var x = eventInfo.x; var y = eventInfo.y; + var id = eventInfo.id; switch (eventInfo.type) { @@ -56,7 +57,7 @@ class TouchEventManager extends EventManager { for (listener in listeners) { - listener.onTouchStart (x, y); + listener.onTouchStart (x, y, id); } @@ -64,7 +65,7 @@ class TouchEventManager extends EventManager { for (listener in listeners) { - listener.onTouchEnd (x, y); + listener.onTouchEnd (x, y, id); } @@ -72,7 +73,7 @@ class TouchEventManager extends EventManager { for (listener in listeners) { - listener.onTouchMove (x, y); + listener.onTouchMove (x, y, id); } diff --git a/project/include/ui/MouseEvent.h b/project/include/ui/MouseEvent.h index 0d419b703..1c2bf190d 100644 --- a/project/include/ui/MouseEvent.h +++ b/project/include/ui/MouseEvent.h @@ -8,6 +8,15 @@ namespace lime { + enum MouseEventButton { + + MOUSE_BUTTON_LEFT, + MOUSE_BUTTON_MIDDLE, + MOUSE_BUTTON_RIGHT + + }; + + enum MouseEventType { MOUSE_DOWN, @@ -29,7 +38,7 @@ namespace lime { static void Dispatch (MouseEvent* event); - int id; + int button; MouseEventType type; double x; double y; diff --git a/project/src/backend/sdl/SDLApplication.cpp b/project/src/backend/sdl/SDLApplication.cpp index 419960a84..935cf19ed 100644 --- a/project/src/backend/sdl/SDLApplication.cpp +++ b/project/src/backend/sdl/SDLApplication.cpp @@ -225,7 +225,7 @@ namespace lime { } - mouseEvent.id = event->button.button - 1; + mouseEvent.button = event->button.button - 1; mouseEvent.x = event->button.x; mouseEvent.y = event->button.y; diff --git a/project/src/ui/MouseEvent.cpp b/project/src/ui/MouseEvent.cpp index 222a632c8..6394d1a6f 100644 --- a/project/src/ui/MouseEvent.cpp +++ b/project/src/ui/MouseEvent.cpp @@ -8,7 +8,7 @@ namespace lime { AutoGCRoot* MouseEvent::callback = 0; AutoGCRoot* MouseEvent::eventObject = 0; - static int id_id; + static int id_button; static int id_type; static int id_x; static int id_y; @@ -17,7 +17,7 @@ namespace lime { MouseEvent::MouseEvent () { - id = 0; + button = MOUSE_BUTTON_LEFT; type = MOUSE_DOWN; x = 0.0; y = 0.0; @@ -31,7 +31,7 @@ namespace lime { if (!init) { - id_id = val_id ("id"); + id_button = val_id ("button"); id_type = val_id ("type"); id_x = val_id ("x"); id_y = val_id ("y"); @@ -41,7 +41,7 @@ namespace lime { value object = (MouseEvent::eventObject ? MouseEvent::eventObject->get () : alloc_empty_object ()); - alloc_field (object, id_id, alloc_int (event->id)); + alloc_field (object, id_button, alloc_int (event->button)); alloc_field (object, id_type, alloc_int (event->type)); alloc_field (object, id_x, alloc_float (event->x)); alloc_field (object, id_y, alloc_float (event->y));