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

@@ -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;
mouseEvent.button = event->button.button - 1;
mouseEvent.x = event->button.x;
mouseEvent.y = event->button.y;
case SDL_MOUSEBUTTONUP:
mouseEvent.type = MOUSE_UP;
mouseEvent.button = event->button.button - 1;
mouseEvent.x = event->button.x;
mouseEvent.y = event->button.y;
break;
} else {
mouseEvent.x = event->wheel.x;
mouseEvent.y = event->wheel.y;
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 {
@@ -17,24 +18,6 @@ namespace lime {
SDL_Cursor* SDLMouse::textCursor = 0;
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));