Cleanup, using Mouse.warp and Mouse.lock, window.onMouseMoveRelative, removing 'button' value from mouse move event

This commit is contained in:
Joshua Granick
2015-03-26 02:10:08 -07:00
parent 3ea7830673
commit 6d8c9458fe
24 changed files with 233 additions and 204 deletions

View File

@@ -178,8 +178,8 @@ class FlashApplication {
var button = switch (event.type) {
case "middleMouseDown", "middleMouseMove", "middleMouseUp": 1;
case "rightMouseDown", "rightMouseMove", "rightMouseUp": 2;
case "middleMouseDown", "middleMouseUp": 1;
case "rightMouseDown", "rightMouseUp": 2;
default: 0;
}
@@ -190,9 +190,9 @@ class FlashApplication {
parent.window.onMouseDown.dispatch (event.stageX, event.stageY, button);
case "mouseMove", "middleMouseMove", "rightMouseMove":
case "mouseMove":
parent.window.onMouseMove.dispatch (event.stageX, event.stageY, button);
parent.window.onMouseMove.dispatch (event.stageX, event.stageY);
case "mouseUp", "middleMouseUp", "rightMouseUp":

View File

@@ -4,6 +4,7 @@ package lime._backend.flash;
import flash.ui.Mouse;
import flash.ui.MouseCursor in FlashMouseCursor;
import lime.ui.MouseCursor;
import lime.ui.Window;
class FlashMouse {
@@ -38,29 +39,21 @@ class FlashMouse {
}
public static function warpGlobal (x:Int,y:Int):Void {
public static function warp (x:Int, y:Int, window:Window):Void {
}
// Get & Set Methods
public static function get_lock ():Bool {
return false;
}
public static function set_lock (value:Bool):Bool {
return value;
}
public static function get_cursor ():MouseCursor {
if (__cursor == null) return DEFAULT;
@@ -103,4 +96,18 @@ class FlashMouse {
}
public static function get_lock ():Bool {
return false;
}
public static function set_lock (value:Bool):Bool {
return value;
}
}

View File

@@ -72,11 +72,4 @@ class FlashWindow {
}
public function warpMouse (x:Int, y:Int):Void {
}
}

View File

@@ -3,6 +3,7 @@ package lime._backend.html5;
import lime.app.Application;
import lime.ui.MouseCursor;
import lime.ui.Window;
@:access(lime.app.Application)
@:access(lime.ui.Window)
@@ -31,11 +32,6 @@ class HTML5Mouse {
}
public static function setRelative (value:Bool):Int{
return -1;
}
public static function show ():Void {
@@ -52,31 +48,20 @@ class HTML5Mouse {
}
public static function warpGlobal (x:Int,y:Int):Void {
public static function warp (x:Int, y:Int, window:Window):Void {
}
// Get & Set Methods
public static function get_lock ():Bool {
return false;
}
public static function set_lock (value:Bool):Bool {
return value;
}
public static function get_cursor ():MouseCursor {
if (__cursor == null) return DEFAULT;
@@ -123,4 +108,18 @@ class HTML5Mouse {
}
public static function get_lock ():Bool {
return false;
}
public static function set_lock (value:Bool):Bool {
return value;
}
}

View File

@@ -216,7 +216,7 @@ class HTML5Window {
case "mousemove":
parent.onMouseMove.dispatch (x, y, event.button);
parent.onMouseMove.dispatch (x, y);
default:
@@ -393,10 +393,4 @@ class HTML5Window {
}
public function warpMouse (x:Int, y:Int):Void {
}
}

View File

@@ -185,7 +185,8 @@ class NativeApplication {
case MOUSE_MOVE:
parent.window.onMouseMove.dispatch (mouseEventInfo.x, mouseEventInfo.y, mouseEventInfo.button);
parent.window.onMouseMove.dispatch (mouseEventInfo.x, mouseEventInfo.y);
parent.window.onMouseMoveRelative.dispatch (mouseEventInfo.movementX, mouseEventInfo.movementY);
case MOUSE_WHEEL:
@@ -376,7 +377,6 @@ class NativeApplication {
private static var lime_application_init = System.load ("lime", "lime_application_init", 1);
private static var lime_application_update = System.load ("lime", "lime_application_update", 1);
private static var lime_application_quit = System.load ("lime", "lime_application_quit", 1);
private static var lime_application_get_ticks = System.load ("lime", "lime_application_get_ticks", 0);
private static var lime_gamepad_event_manager_register = System.load ("lime", "lime_gamepad_event_manager_register", 2);
private static var lime_key_event_manager_register = System.load ("lime", "lime_key_event_manager_register", 2);
private static var lime_mouse_event_manager_register = System.load ("lime", "lime_mouse_event_manager_register", 2);
@@ -470,25 +470,29 @@ private class MouseEventInfo {
public var button:Int;
public var movementX:Float;
public var movementY:Float;
public var type:MouseEventType;
public var x:Float;
public var y:Float;
public function new (type:MouseEventType = null, x:Float = 0, y:Float = 0, button:Int = 0) {
public function new (type:MouseEventType = null, x:Float = 0, y:Float = 0, button:Int = 0, movementX:Float = 0, movementY:Float = 0) {
this.type = type;
this.x = x;
this.y = y;
this.button = button;
this.movementX = movementX;
this.movementY = movementY;
}
public function clone ():MouseEventInfo {
return new MouseEventInfo (type, x, y, button);
return new MouseEventInfo (type, x, y, button, movementX, movementY);
}

View File

@@ -3,6 +3,9 @@ package lime._backend.native;
import lime.system.System;
import lime.ui.MouseCursor;
import lime.ui.Window;
@:access(lime.ui.Window)
class NativeMouse {
@@ -39,39 +42,20 @@ class NativeMouse {
}
public static function warpGlobal (x:Int,y:Int):Void {
public static function warp (x:Int, y:Int, window:Window):Void {
lime_mouse_warp_global (x,y);
lime_mouse_warp (x, y, window == null ? null : window.backend.handle);
}
// Get & Set Methods
public static function get_lock ():Bool {
return __lock;
}
public static function set_lock (value:Bool):Bool {
if (__lock != value) {
lime_mouse_set_lock (value);
__lock = value;
}
return __lock;
}
public static function get_cursor ():MouseCursor {
if (__cursor == null) return DEFAULT;
@@ -116,6 +100,29 @@ class NativeMouse {
}
public static function get_lock ():Bool {
return __lock;
}
public static function set_lock (value:Bool):Bool {
if (__lock != value) {
lime_mouse_set_lock (value);
__hidden = value;
__lock = value;
}
return __lock;
}
// Native Methods
@@ -123,11 +130,11 @@ class NativeMouse {
private static var lime_mouse_warp_global = System.load ("lime", "lime_mouse_warp_global", 2);
private static var lime_mouse_set_lock = System.load ("lime", "lime_mouse_set_lock", 1);
private static var lime_mouse_hide = System.load ("lime", "lime_mouse_hide", 0);
private static var lime_mouse_set_cursor = System.load ("lime", "lime_mouse_set_cursor", 1);
private static var lime_mouse_set_lock = System.load ("lime", "lime_mouse_set_lock", 1);
private static var lime_mouse_show = System.load ("lime", "lime_mouse_show", 0);
private static var lime_mouse_warp = System.load ("lime", "lime_mouse_warp", 3);
}

View File

@@ -152,17 +152,6 @@ class NativeWindow {
}
public function warpMouse (x:Int, y:Int):Void {
if (handle != null) {
lime_window_warp_mouse (handle, x, y);
}
}
private static var lime_window_close = System.load ("lime", "lime_window_close", 1);
private static var lime_window_create = System.load ("lime", "lime_window_create", 5);
private static var lime_window_get_height = System.load ("lime", "lime_window_get_height", 1);
@@ -174,7 +163,6 @@ class NativeWindow {
private static var lime_window_set_fullscreen = System.load ("lime", "lime_window_set_fullscreen", 2);
private static var lime_window_set_icon = System.load ("lime", "lime_window_set_icon", 2);
private static var lime_window_set_minimized = System.load ("lime", "lime_window_set_minimized", 2);
private static var lime_window_warp_mouse = System.load ("lime", "lime_window_warp_mouse", 3);
}

View File

@@ -110,6 +110,7 @@ class Application extends Module {
window.onKeyUp.add (onKeyUp);
window.onMouseDown.add (onMouseDown);
window.onMouseMove.add (onMouseMove);
window.onMouseMoveRelative.add (onMouseMoveRelative);
window.onMouseUp.add (onMouseUp);
window.onMouseWheel.add (onMouseWheel);
window.onTouchStart.add (onTouchStart);
@@ -260,11 +261,22 @@ class Application extends Module {
}
public override function onMouseMove (x:Float, y:Float, button:Int):Void {
public override function onMouseMove (x:Float, y:Float):Void {
for (module in modules) {
module.onMouseMove (x, y, button);
module.onMouseMove (x, y);
}
}
public override function onMouseMoveRelative (x:Float, y:Float):Void {
for (module in modules) {
module.onMouseMoveRelative (x, y);
}

View File

@@ -89,9 +89,16 @@ interface IModule {
* Called when a mouse move event is fired
* @param x The current x coordinate of the mouse
* @param y The current y coordinate of the mouse
* @param button The ID of the mouse button that was pressed
*/
public function onMouseMove (x:Float, y:Float, button:Int):Void;
public function onMouseMove (x:Float, y:Float):Void;
/**
* Called when a mouse move relative event is fired
* @param x The x movement of the mouse
* @param y The y movement of the mouse
*/
public function onMouseMoveRelative (x:Float, y:Float):Void;
/**

View File

@@ -64,9 +64,16 @@ class Module implements IModule {
* Called when a mouse move event is fired
* @param x The current x coordinate of the mouse
* @param y The current y coordinate of the mouse
* @param button The ID of the mouse button that was pressed
*/
public function onMouseMove (x:Float, y:Float, button:Int):Void { }
public function onMouseMove (x:Float, y:Float):Void { }
/**
* Called when a mouse move relative event is fired
* @param x The x movement of the mouse
* @param y The y movement of the mouse
*/
public function onMouseMoveRelative (x:Float, y:Float):Void { }
/**

View File

@@ -4,8 +4,8 @@ package lime.ui;
class Mouse {
public static var lock (get, set):Bool;
public static var cursor (get, set):MouseCursor;
public static var lock (get, set):Bool;
public static function hide ():Void {
@@ -21,31 +21,21 @@ class Mouse {
}
public static function warpGlobal(x:Int,y:Int):Void {
MouseBackend.warpGlobal(x,y);
public static function warp (x:Int, y:Int, window:Window = null):Void {
MouseBackend.warp (x, y, window);
}
// Get & Set Methods
private static function get_lock ():Bool {
return MouseBackend.get_lock ();
}
private static function set_lock (value:Bool):Bool {
return MouseBackend.set_lock (value);
}
private static function get_cursor ():MouseCursor {
return MouseBackend.get_cursor ();
@@ -60,6 +50,20 @@ class Mouse {
}
private static function get_lock ():Bool {
return MouseBackend.get_lock ();
}
private static function set_lock (value:Bool):Bool {
return MouseBackend.set_lock (value);
}
}

View File

@@ -24,7 +24,8 @@ class Window {
public var onKeyDown = new Event<KeyCode->KeyModifier->Void> ();
public var onKeyUp = new Event<KeyCode->KeyModifier->Void> ();
public var onMouseDown = new Event<Float->Float->Int->Void> ();
public var onMouseMove = new Event<Float->Float->Int->Void> ();
public var onMouseMove = new Event<Float->Float->Void> ();
public var onMouseMoveRelative = new Event<Float->Float->Void> ();
public var onMouseUp = new Event<Float->Float->Int->Void> ();
public var onMouseWheel = new Event<Float->Float->Void> ();
public var onTouchEnd = new Event<Float->Float->Int->Void> ();
@@ -130,11 +131,6 @@ class Window {
}
public function warpMouse(x:Int, y:Int){
backend.warpMouse(x,y);
}

View File

@@ -13,8 +13,6 @@ namespace lime {
public:
static double GetTicks ();
static AutoGCRoot* callback;
virtual int Exec () = 0;

View File

@@ -3,6 +3,7 @@
#include <ui/MouseCursor.h>
#include <ui/Window.h>
namespace lime {
@@ -14,11 +15,11 @@ namespace lime {
static MouseCursor currentCursor;
static void WarpGlobal (int x, int y);
static void SetLock (bool value);
static void Hide ();
static void SetCursor (MouseCursor cursor);
static void SetLock (bool lock);
static void Show ();
static void Warp (int x, int y, Window* window);
};

View File

@@ -30,6 +30,8 @@ namespace lime {
static void Dispatch (MouseEvent* event);
int button;
double movementX;
double movementY;
MouseEventType type;
double x;
double y;

View File

@@ -28,7 +28,6 @@ namespace lime {
virtual bool SetFullscreen (bool fullscreen) = 0;
virtual void SetIcon (ImageBuffer *imageBuffer) = 0;
virtual bool SetMinimized (bool minimized) = 0;
virtual void WarpMouse (int x, int y) = 0;
Application* currentApplication;
int flags;

View File

@@ -63,13 +63,6 @@ namespace lime {
}
value lime_application_get_ticks (value application) {
return alloc_float (Application::GetTicks ());
}
value lime_application_quit (value application) {
Application* app = (Application*)(intptr_t)val_float (application);
@@ -516,17 +509,25 @@ namespace lime {
}
value lime_mouse_warp_global (value x, value y) {
value lime_mouse_warp (value x, value y, value window) {
Mouse::WarpGlobal (val_int(x),val_int(y));
Window* windowRef = 0;
if (!val_is_null (window)) {
windowRef = (Window*)(intptr_t)val_float (window);
}
Mouse::Warp (val_int (x), val_int (y), windowRef);
return alloc_null ();
}
value lime_mouse_set_lock (value input_value) {
value lime_mouse_set_lock (value lock) {
Mouse::SetLock (input_value);
Mouse::SetLock (val_bool (lock));
return alloc_null ();
}
@@ -801,19 +802,9 @@ namespace lime {
}
value lime_window_warp_mouse (value window, value x, value y) {
Window* targetWindow = (Window*)(intptr_t)val_float (window);
targetWindow->WarpMouse (val_int (x), val_int (y));
return alloc_null ();
}
DEFINE_PRIM (lime_application_create, 1);
DEFINE_PRIM (lime_application_exec, 1);
DEFINE_PRIM (lime_application_init, 1);
DEFINE_PRIM (lime_application_get_ticks, 0);
DEFINE_PRIM (lime_application_quit, 1);
DEFINE_PRIM (lime_application_update, 1);
DEFINE_PRIM (lime_audio_load, 1);
@@ -840,14 +831,14 @@ namespace lime {
DEFINE_PRIM (lime_image_load, 1);
DEFINE_PRIM (lime_jni_getenv, 0);
DEFINE_PRIM (lime_key_event_manager_register, 2);
DEFINE_PRIM (lime_lzma_encode, 1);
DEFINE_PRIM (lime_lzma_decode, 1);
DEFINE_PRIM (lime_mouse_warp_global, 2);
DEFINE_PRIM (lime_mouse_set_lock, 1);
DEFINE_PRIM (lime_lzma_encode, 1);
DEFINE_PRIM (lime_mouse_event_manager_register, 2);
DEFINE_PRIM (lime_mouse_hide, 0);
DEFINE_PRIM (lime_mouse_set_cursor, 1);
DEFINE_PRIM (lime_mouse_set_lock, 1);
DEFINE_PRIM (lime_mouse_show, 0);
DEFINE_PRIM (lime_mouse_event_manager_register, 2);
DEFINE_PRIM (lime_mouse_warp, 3);
DEFINE_PRIM (lime_neko_execute, 1);
DEFINE_PRIM (lime_renderer_create, 1);
DEFINE_PRIM (lime_renderer_flip, 1);
@@ -873,7 +864,6 @@ namespace lime {
DEFINE_PRIM (lime_window_set_fullscreen, 2);
DEFINE_PRIM (lime_window_set_icon, 2);
DEFINE_PRIM (lime_window_set_minimized, 2);
DEFINE_PRIM (lime_window_warp_mouse, 3);
}

View File

@@ -294,23 +294,37 @@ namespace lime {
switch (event->type) {
case SDL_MOUSEMOTION: mouseEvent.type = MOUSE_MOVE; break;
case SDL_MOUSEBUTTONDOWN: mouseEvent.type = MOUSE_DOWN; break;
case SDL_MOUSEBUTTONUP: mouseEvent.type = MOUSE_UP; break;
case SDL_MOUSEWHEEL: mouseEvent.type = MOUSE_WHEEL; break;
case SDL_MOUSEMOTION:
}
mouseEvent.type = MOUSE_MOVE;
mouseEvent.x = event->motion.x;
mouseEvent.y = event->motion.y;
mouseEvent.movementX = event->motion.xrel;
mouseEvent.movementY = event->motion.yrel;
break;
if (event->type != SDL_MOUSEWHEEL) {
case SDL_MOUSEBUTTONDOWN:
mouseEvent.type = MOUSE_DOWN;
mouseEvent.button = event->button.button - 1;
mouseEvent.x = event->button.x;
mouseEvent.y = event->button.y;
break;
} else {
case SDL_MOUSEBUTTONUP:
mouseEvent.type = MOUSE_UP;
mouseEvent.button = event->button.button - 1;
mouseEvent.x = event->button.x;
mouseEvent.y = event->button.y;
break;
case SDL_MOUSEWHEEL:
mouseEvent.type = MOUSE_WHEEL;
mouseEvent.x = event->wheel.x;
mouseEvent.y = event->wheel.y;
break;
}
@@ -494,13 +508,6 @@ namespace lime {
}
double Application::GetTicks () {
return SDL_GetTicks ();
}
Application* CreateApplication () {
return new SDLApplication ();

View File

@@ -1,4 +1,5 @@
#include "SDLMouse.h"
#include "SDLWindow.h"
namespace lime {
@@ -18,24 +19,6 @@ namespace lime {
SDL_Cursor* SDLMouse::waitCursor = 0;
SDL_Cursor* SDLMouse::waitArrowCursor = 0;
void Mouse::WarpGlobal(int x, int y){
SDL_WarpMouseGlobal(x,y);
}
void Mouse::SetLock (bool value) {
if(value)
{
SDL_SetRelativeMouseMode(SDL_TRUE);
}
else
{
SDL_SetRelativeMouseMode(SDL_FALSE);
}
}
void Mouse::Hide () {
@@ -180,6 +163,21 @@ namespace lime {
}
void Mouse::SetLock (bool lock) {
if (lock) {
SDL_SetRelativeMouseMode (SDL_TRUE);
} else {
SDL_SetRelativeMouseMode (SDL_FALSE);
}
}
void Mouse::Show () {
SDL_ShowCursor (SDL_ENABLE);
@@ -187,4 +185,19 @@ namespace lime {
}
void Mouse::Warp (int x, int y, Window* window){
if (window) {
SDL_WarpMouseInWindow (((SDLWindow*)window)->sdlWindow, x, y);
} else {
SDL_WarpMouseGlobal (x, y);
}
}
}

View File

@@ -5,6 +5,7 @@
#include <SDL.h>
#include <ui/Mouse.h>
#include <ui/MouseCursor.h>
#include <ui/Window.h>
namespace lime {

View File

@@ -200,13 +200,6 @@ namespace lime {
}
void SDLWindow::WarpMouse (int x, int y) {
SDL_WarpMouseInWindow (sdlWindow,x,y);
}
Window* CreateWindow (Application* application, int width, int height, int flags, const char* title) {
return new SDLWindow (application, width, height, flags, title);

View File

@@ -27,7 +27,6 @@ namespace lime {
virtual bool SetFullscreen (bool fullscreen);
virtual void SetIcon (ImageBuffer *imageBuffer);
virtual bool SetMinimized (bool minimized);
virtual void WarpMouse (int x, int y);
SDL_Window* sdlWindow;

View File

@@ -9,6 +9,8 @@ namespace lime {
AutoGCRoot* MouseEvent::eventObject = 0;
static int id_button;
static int id_movementX;
static int id_movementY;
static int id_type;
static int id_x;
static int id_y;
@@ -21,6 +23,8 @@ namespace lime {
type = MOUSE_DOWN;
x = 0.0;
y = 0.0;
movementX = 0.0;
movementY = 0.0;
}
@@ -32,6 +36,8 @@ namespace lime {
if (!init) {
id_button = val_id ("button");
id_movementX = val_id ("movementX");
id_movementY = val_id ("movementY");
id_type = val_id ("type");
id_x = val_id ("x");
id_y = val_id ("y");
@@ -47,6 +53,8 @@ namespace lime {
}
alloc_field (object, id_movementX, alloc_float (event->movementX));
alloc_field (object, id_movementY, alloc_float (event->movementY));
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));