Merge pull request #386 from sepharoth213/master
Adding mouse functionality for locking/warping in native
This commit is contained in:
@@ -38,12 +38,27 @@ class FlashMouse {
|
||||
|
||||
}
|
||||
|
||||
public static function warpGlobal (x:Int,y:Int):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 {
|
||||
|
||||
@@ -71,5 +71,12 @@ class FlashWindow {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function warpMouse (x:Int, y:Int):Void {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -30,6 +30,11 @@ class HTML5Mouse {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static function setRelative (value:Bool):Int{
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
public static function show ():Void {
|
||||
@@ -47,11 +52,29 @@ class HTML5Mouse {
|
||||
}
|
||||
|
||||
|
||||
public static function warpGlobal (x:Int,y:Int):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 {
|
||||
|
||||
@@ -392,5 +392,11 @@ class HTML5Window {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function warpMouse (x:Int, y:Int):Void {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,7 +10,8 @@ class NativeMouse {
|
||||
|
||||
private static var __cursor:MouseCursor;
|
||||
private static var __hidden:Bool;
|
||||
|
||||
private static var __lock:Bool;
|
||||
|
||||
|
||||
public static function hide ():Void {
|
||||
|
||||
@@ -38,12 +39,38 @@ class NativeMouse {
|
||||
}
|
||||
|
||||
|
||||
public static function warpGlobal (x:Int,y:Int):Void {
|
||||
|
||||
lime_mouse_warp_global (x,y);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 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 {
|
||||
|
||||
@@ -96,6 +123,8 @@ 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_show = System.load ("lime", "lime_mouse_show", 0);
|
||||
|
||||
@@ -152,6 +152,17 @@ 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);
|
||||
@@ -163,6 +174,7 @@ 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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ package lime.ui;
|
||||
class Mouse {
|
||||
|
||||
|
||||
public static var lock (get, set):Bool;
|
||||
public static var cursor (get, set):MouseCursor;
|
||||
|
||||
|
||||
@@ -20,14 +21,31 @@ class Mouse {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static function warpGlobal(x:Int,y:Int):Void {
|
||||
|
||||
MouseBackend.warpGlobal(x,y);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 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 ();
|
||||
|
||||
@@ -129,6 +129,11 @@ class Window {
|
||||
backend.setIcon (image);
|
||||
|
||||
}
|
||||
|
||||
public function warpMouse(x:Int, y:Int){
|
||||
|
||||
backend.warpMouse(x,y);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@ 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 Show ();
|
||||
|
||||
@@ -28,6 +28,7 @@ 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;
|
||||
|
||||
@@ -516,6 +516,22 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
value lime_mouse_warp_global (value x, value y) {
|
||||
|
||||
Mouse::WarpGlobal (val_int(x),val_int(y));
|
||||
return alloc_null ();
|
||||
|
||||
}
|
||||
|
||||
|
||||
value lime_mouse_set_lock (value input_value) {
|
||||
|
||||
Mouse::SetLock (input_value);
|
||||
return alloc_null ();
|
||||
|
||||
}
|
||||
|
||||
|
||||
value lime_mouse_set_cursor (value cursor) {
|
||||
|
||||
Mouse::SetCursor ((MouseCursor)val_int (cursor));
|
||||
@@ -785,6 +801,15 @@ 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);
|
||||
@@ -817,6 +842,8 @@ namespace lime {
|
||||
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_mouse_hide, 0);
|
||||
DEFINE_PRIM (lime_mouse_set_cursor, 1);
|
||||
DEFINE_PRIM (lime_mouse_show, 0);
|
||||
@@ -846,6 +873,7 @@ 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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -17,6 +17,24 @@ 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 () {
|
||||
|
||||
@@ -200,6 +200,13 @@ 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);
|
||||
|
||||
@@ -27,6 +27,7 @@ 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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user