Add Lime mouse cursor support on SDL2
This commit is contained in:
@@ -2,6 +2,7 @@ package lime.ui;
|
|||||||
|
|
||||||
|
|
||||||
import lime.app.Application;
|
import lime.app.Application;
|
||||||
|
import lime.system.System;
|
||||||
|
|
||||||
@:access(lime.app.Application)
|
@:access(lime.app.Application)
|
||||||
|
|
||||||
@@ -28,6 +29,10 @@ class Mouse {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#elseif (cpp || neko || nodejs)
|
||||||
|
|
||||||
|
lime_mouse_hide ();
|
||||||
|
|
||||||
#end
|
#end
|
||||||
|
|
||||||
__hidden = true;
|
__hidden = true;
|
||||||
@@ -47,6 +52,10 @@ class Mouse {
|
|||||||
__cursor = null;
|
__cursor = null;
|
||||||
cursor = cacheValue;
|
cursor = cacheValue;
|
||||||
|
|
||||||
|
#elseif (cpp || neko || nodejs)
|
||||||
|
|
||||||
|
lime_mouse_show ();
|
||||||
|
|
||||||
#end
|
#end
|
||||||
|
|
||||||
__hidden = false;
|
__hidden = false;
|
||||||
@@ -91,6 +100,18 @@ class Mouse {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#elseif (cpp || neko || nodejs)
|
||||||
|
|
||||||
|
var type = switch (value) {
|
||||||
|
|
||||||
|
case POINTER: MouseCursorType.POINTER;
|
||||||
|
case TEXT: MouseCursorType.TEXT;
|
||||||
|
default: MouseCursorType.DEFAULT;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
lime_mouse_set_cursor (type);
|
||||||
|
|
||||||
#end
|
#end
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -104,4 +125,20 @@ class Mouse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if (cpp || neko || nodejs)
|
||||||
|
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);
|
||||||
|
#end
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@:enum private abstract MouseCursorType(Int) {
|
||||||
|
|
||||||
|
var DEFAULT = 0;
|
||||||
|
var POINTER = 1;
|
||||||
|
var TEXT = 2;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -132,6 +132,7 @@
|
|||||||
<file name="src/backend/sdl/SDLApplication.cpp" />
|
<file name="src/backend/sdl/SDLApplication.cpp" />
|
||||||
<file name="src/backend/sdl/SDLWindow.cpp" />
|
<file name="src/backend/sdl/SDLWindow.cpp" />
|
||||||
<file name="src/backend/sdl/SDLRenderer.cpp" />
|
<file name="src/backend/sdl/SDLRenderer.cpp" />
|
||||||
|
<file name="src/backend/sdl/SDLMouse.cpp" />
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
27
project/include/ui/Mouse.h
Normal file
27
project/include/ui/Mouse.h
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#ifndef LIME_UI_MOUSE_H
|
||||||
|
#define LIME_UI_MOUSE_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <ui/MouseCursor.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace lime {
|
||||||
|
|
||||||
|
|
||||||
|
class Mouse {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
static MouseCursor currentCursor;
|
||||||
|
|
||||||
|
static void Hide ();
|
||||||
|
static void SetCursor (MouseCursor cursor);
|
||||||
|
static void Show ();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
21
project/include/ui/MouseCursor.h
Normal file
21
project/include/ui/MouseCursor.h
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#ifndef LIME_UI_MOUSE_CURSOR_H
|
||||||
|
#define LIME_UI_MOUSE_CURSOR_H
|
||||||
|
|
||||||
|
|
||||||
|
namespace lime {
|
||||||
|
|
||||||
|
|
||||||
|
enum MouseCursor {
|
||||||
|
|
||||||
|
DEFAULT,
|
||||||
|
POINTER,
|
||||||
|
TEXT,
|
||||||
|
CUSTOM
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -24,6 +24,8 @@
|
|||||||
#include <graphics/RenderEvent.h>
|
#include <graphics/RenderEvent.h>
|
||||||
#include <system/System.h>
|
#include <system/System.h>
|
||||||
#include <ui/KeyEvent.h>
|
#include <ui/KeyEvent.h>
|
||||||
|
#include <ui/Mouse.h>
|
||||||
|
#include <ui/MouseCursor.h>
|
||||||
#include <ui/MouseEvent.h>
|
#include <ui/MouseEvent.h>
|
||||||
#include <ui/TouchEvent.h>
|
#include <ui/TouchEvent.h>
|
||||||
#include <ui/Window.h>
|
#include <ui/Window.h>
|
||||||
@@ -329,6 +331,30 @@ namespace lime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
value lime_mouse_hide () {
|
||||||
|
|
||||||
|
Mouse::Hide ();
|
||||||
|
return alloc_null ();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
value lime_mouse_set_cursor (value cursor) {
|
||||||
|
|
||||||
|
Mouse::SetCursor ((MouseCursor)val_int (cursor));
|
||||||
|
return alloc_null ();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
value lime_mouse_show () {
|
||||||
|
|
||||||
|
Mouse::Show ();
|
||||||
|
return alloc_null ();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
value lime_neko_execute (value module) {
|
value lime_neko_execute (value module) {
|
||||||
|
|
||||||
#ifdef LIME_NEKO
|
#ifdef LIME_NEKO
|
||||||
@@ -490,6 +516,9 @@ namespace lime {
|
|||||||
DEFINE_PRIM (lime_key_event_manager_register, 2);
|
DEFINE_PRIM (lime_key_event_manager_register, 2);
|
||||||
DEFINE_PRIM (lime_lzma_encode, 1);
|
DEFINE_PRIM (lime_lzma_encode, 1);
|
||||||
DEFINE_PRIM (lime_lzma_decode, 1);
|
DEFINE_PRIM (lime_lzma_decode, 1);
|
||||||
|
DEFINE_PRIM (lime_mouse_hide, 0);
|
||||||
|
DEFINE_PRIM (lime_mouse_set_cursor, 1);
|
||||||
|
DEFINE_PRIM (lime_mouse_show, 0);
|
||||||
DEFINE_PRIM (lime_mouse_event_manager_register, 2);
|
DEFINE_PRIM (lime_mouse_event_manager_register, 2);
|
||||||
DEFINE_PRIM (lime_neko_execute, 1);
|
DEFINE_PRIM (lime_neko_execute, 1);
|
||||||
DEFINE_PRIM (lime_renderer_create, 1);
|
DEFINE_PRIM (lime_renderer_create, 1);
|
||||||
|
|||||||
77
project/src/backend/sdl/SDLMouse.cpp
Normal file
77
project/src/backend/sdl/SDLMouse.cpp
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
#include "SDLMouse.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace lime {
|
||||||
|
|
||||||
|
|
||||||
|
MouseCursor Mouse::currentCursor = DEFAULT;
|
||||||
|
SDL_Cursor* SDLMouse::defaultCursor = 0;
|
||||||
|
SDL_Cursor* SDLMouse::pointerCursor = 0;
|
||||||
|
SDL_Cursor* SDLMouse::textCursor = 0;
|
||||||
|
|
||||||
|
|
||||||
|
void Mouse::Hide () {
|
||||||
|
|
||||||
|
SDL_ShowCursor (SDL_DISABLE);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Mouse::SetCursor (MouseCursor cursor) {
|
||||||
|
|
||||||
|
if (cursor != Mouse::currentCursor) {
|
||||||
|
|
||||||
|
switch (cursor) {
|
||||||
|
|
||||||
|
case POINTER:
|
||||||
|
|
||||||
|
if (!SDLMouse::pointerCursor) {
|
||||||
|
|
||||||
|
SDLMouse::pointerCursor = SDL_CreateSystemCursor (SDL_SYSTEM_CURSOR_HAND);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_SetCursor (SDLMouse::pointerCursor);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TEXT:
|
||||||
|
|
||||||
|
if (!SDLMouse::textCursor) {
|
||||||
|
|
||||||
|
SDLMouse::textCursor = SDL_CreateSystemCursor (SDL_SYSTEM_CURSOR_IBEAM);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_SetCursor (SDLMouse::textCursor);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
|
||||||
|
if (!SDLMouse::defaultCursor) {
|
||||||
|
|
||||||
|
SDLMouse::defaultCursor = SDL_CreateSystemCursor (SDL_SYSTEM_CURSOR_ARROW);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_SetCursor (SDLMouse::defaultCursor);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Mouse::currentCursor = cursor;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Mouse::Show () {
|
||||||
|
|
||||||
|
SDL_ShowCursor (SDL_ENABLE);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
27
project/src/backend/sdl/SDLMouse.h
Normal file
27
project/src/backend/sdl/SDLMouse.h
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#ifndef LIME_SDL_MOUSE_H
|
||||||
|
#define LIME_SDL_MOUSE_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <SDL.h>
|
||||||
|
#include <ui/Mouse.h>
|
||||||
|
#include <ui/MouseCursor.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace lime {
|
||||||
|
|
||||||
|
|
||||||
|
class SDLMouse {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
static SDL_Cursor* defaultCursor;
|
||||||
|
static SDL_Cursor* pointerCursor;
|
||||||
|
static SDL_Cursor* textCursor;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user