Include button/id in mouse/touch events

This commit is contained in:
Joshua Granick
2014-06-17 18:30:42 -07:00
parent 806720647e
commit 0d0a9ea3b1
10 changed files with 51 additions and 32 deletions

View File

@@ -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 { }

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -49,6 +49,7 @@ class MouseEventManager extends EventManager<IMouseEventListener> {
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<IMouseEventListener> {
for (listener in listeners) {
listener.onMouseDown (x, y);
listener.onMouseDown (x, y, button);
}
@@ -64,7 +65,7 @@ class MouseEventManager extends EventManager<IMouseEventListener> {
for (listener in listeners) {
listener.onMouseUp (x, y);
listener.onMouseUp (x, y, button);
}
@@ -72,7 +73,7 @@ class MouseEventManager extends EventManager<IMouseEventListener> {
for (listener in listeners) {
listener.onMouseMove (x, y);
listener.onMouseMove (x, y, button);
}

View File

@@ -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);
}

View File

@@ -49,6 +49,7 @@ class TouchEventManager extends EventManager<ITouchEventListener> {
var x = eventInfo.x;
var y = eventInfo.y;
var id = eventInfo.id;
switch (eventInfo.type) {
@@ -56,7 +57,7 @@ class TouchEventManager extends EventManager<ITouchEventListener> {
for (listener in listeners) {
listener.onTouchStart (x, y);
listener.onTouchStart (x, y, id);
}
@@ -64,7 +65,7 @@ class TouchEventManager extends EventManager<ITouchEventListener> {
for (listener in listeners) {
listener.onTouchEnd (x, y);
listener.onTouchEnd (x, y, id);
}
@@ -72,7 +73,7 @@ class TouchEventManager extends EventManager<ITouchEventListener> {
for (listener in listeners) {
listener.onTouchMove (x, y);
listener.onTouchMove (x, y, id);
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -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));