Add Lime mouse cursor support on SDL2
This commit is contained in:
@@ -132,6 +132,7 @@
|
||||
<file name="src/backend/sdl/SDLApplication.cpp" />
|
||||
<file name="src/backend/sdl/SDLWindow.cpp" />
|
||||
<file name="src/backend/sdl/SDLRenderer.cpp" />
|
||||
<file name="src/backend/sdl/SDLMouse.cpp" />
|
||||
|
||||
</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 <system/System.h>
|
||||
#include <ui/KeyEvent.h>
|
||||
#include <ui/Mouse.h>
|
||||
#include <ui/MouseCursor.h>
|
||||
#include <ui/MouseEvent.h>
|
||||
#include <ui/TouchEvent.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) {
|
||||
|
||||
#ifdef LIME_NEKO
|
||||
@@ -490,6 +516,9 @@ 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_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_neko_execute, 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