mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-06-02 01:47:41 +00:00
hint for which system cursor to use as default
Co-Authored-By: Sam Lantinga <slouken@libsdl.org>
This commit is contained in:
parent
3c13bae64f
commit
d55e6dfc5e
10 changed files with 54 additions and 34 deletions
|
@ -2401,6 +2401,17 @@ extern "C" {
|
||||||
*/
|
*/
|
||||||
#define SDL_HINT_MOUSE_DOUBLE_CLICK_TIME "SDL_MOUSE_DOUBLE_CLICK_TIME"
|
#define SDL_HINT_MOUSE_DOUBLE_CLICK_TIME "SDL_MOUSE_DOUBLE_CLICK_TIME"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A variable setting which system cursor to use as the default cursor.
|
||||||
|
* This should be an integer corresponding to the SDL_SystemCursor enum.
|
||||||
|
* The default value is zero (SDL_SYSTEM_CURSOR_DEFAULT).
|
||||||
|
*
|
||||||
|
* This hint needs to be set before SDL_Init().
|
||||||
|
*
|
||||||
|
* \since This hint is available since SDL 3.1.3.
|
||||||
|
*/
|
||||||
|
#define SDL_HINT_MOUSE_DEFAULT_SYSTEM_CURSOR "SDL_MOUSE_DEFAULT_SYSTEM_CURSOR"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A variable controlling whether warping a hidden mouse cursor will activate
|
* A variable controlling whether warping a hidden mouse cursor will activate
|
||||||
* relative mouse mode.
|
* relative mouse mode.
|
||||||
|
|
|
@ -440,6 +440,19 @@ void SDL_SetDefaultCursor(SDL_Cursor *cursor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDL_SystemCursor SDL_GetDefaultSystemCursor(void)
|
||||||
|
{
|
||||||
|
SDL_SystemCursor id = SDL_SYSTEM_CURSOR_DEFAULT;
|
||||||
|
const char *value = SDL_GetHint(SDL_HINT_MOUSE_DEFAULT_SYSTEM_CURSOR);
|
||||||
|
if (value) {
|
||||||
|
int index = SDL_atoi(value);
|
||||||
|
if (0 <= index && index < (int)SDL_SYSTEM_CURSOR_COUNT) {
|
||||||
|
id = (SDL_SystemCursor)index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
SDL_Mouse *SDL_GetMouse(void)
|
SDL_Mouse *SDL_GetMouse(void)
|
||||||
{
|
{
|
||||||
return &SDL_mouse;
|
return &SDL_mouse;
|
||||||
|
|
|
@ -158,6 +158,9 @@ extern SDL_Mouse *SDL_GetMouse(void);
|
||||||
// Set the default mouse cursor
|
// Set the default mouse cursor
|
||||||
extern void SDL_SetDefaultCursor(SDL_Cursor *cursor);
|
extern void SDL_SetDefaultCursor(SDL_Cursor *cursor);
|
||||||
|
|
||||||
|
// Get the preferred default system cursor
|
||||||
|
extern SDL_SystemCursor SDL_GetDefaultSystemCursor(void);
|
||||||
|
|
||||||
// Set the mouse focus window
|
// Set the mouse focus window
|
||||||
extern void SDL_SetMouseFocus(SDL_Window *window);
|
extern void SDL_SetMouseFocus(SDL_Window *window);
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,8 @@ static SDL_Cursor *Android_WrapCursor(int custom_cursor, int system_cursor)
|
||||||
|
|
||||||
static SDL_Cursor *Android_CreateDefaultCursor(void)
|
static SDL_Cursor *Android_CreateDefaultCursor(void)
|
||||||
{
|
{
|
||||||
return Android_WrapCursor(0, SDL_SYSTEM_CURSOR_DEFAULT);
|
SDL_SystemCursor id = SDL_GetDefaultSystemCursor();
|
||||||
|
return Android_WrapCursor(0, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SDL_Cursor *Android_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y)
|
static SDL_Cursor *Android_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y)
|
||||||
|
|
|
@ -63,25 +63,6 @@
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
static SDL_Cursor *Cocoa_CreateDefaultCursor(void)
|
|
||||||
{
|
|
||||||
@autoreleasepool {
|
|
||||||
NSCursor *nscursor;
|
|
||||||
SDL_Cursor *cursor = NULL;
|
|
||||||
|
|
||||||
nscursor = [NSCursor arrowCursor];
|
|
||||||
|
|
||||||
if (nscursor) {
|
|
||||||
cursor = SDL_calloc(1, sizeof(*cursor));
|
|
||||||
if (cursor) {
|
|
||||||
cursor->internal = (void *)CFBridgingRetain(nscursor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return cursor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static SDL_Cursor *Cocoa_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y)
|
static SDL_Cursor *Cocoa_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y)
|
||||||
{
|
{
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
|
@ -229,6 +210,12 @@ static SDL_Cursor *Cocoa_CreateSystemCursor(SDL_SystemCursor id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static SDL_Cursor *Cocoa_CreateDefaultCursor(void)
|
||||||
|
{
|
||||||
|
SDL_SystemCursor id = SDL_GetDefaultSystemCursor();
|
||||||
|
return Cocoa_CreateSystemCursor(id);
|
||||||
|
}
|
||||||
|
|
||||||
static void Cocoa_FreeCursor(SDL_Cursor *cursor)
|
static void Cocoa_FreeCursor(SDL_Cursor *cursor)
|
||||||
{
|
{
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
|
|
|
@ -62,7 +62,9 @@ static SDL_Cursor *Emscripten_CreateCursorFromString(const char *cursor_str, boo
|
||||||
|
|
||||||
static SDL_Cursor *Emscripten_CreateDefaultCursor(void)
|
static SDL_Cursor *Emscripten_CreateDefaultCursor(void)
|
||||||
{
|
{
|
||||||
return Emscripten_CreateCursorFromString("default", false);
|
SDL_SystemCursor id = SDL_GetDefaultSystemCursor();
|
||||||
|
const char *cursor_name = SDL_GetCSSCursorName(id, NULL);
|
||||||
|
return Emscripten_CreateCursorFromString(cursor_name, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
EM_JS_DEPS(sdlmouse, "$stringToUTF8,$UTF8ToString");
|
EM_JS_DEPS(sdlmouse, "$stringToUTF8,$UTF8ToString");
|
||||||
|
|
|
@ -180,7 +180,8 @@ static SDL_Cursor * HAIKU_CreateSystemCursor(SDL_SystemCursor id)
|
||||||
|
|
||||||
static SDL_Cursor * HAIKU_CreateDefaultCursor()
|
static SDL_Cursor * HAIKU_CreateDefaultCursor()
|
||||||
{
|
{
|
||||||
return HAIKU_CreateSystemCursor(SDL_SYSTEM_CURSOR_DEFAULT);
|
SDL_SystemCursor id = SDL_GetDefaultSystemCursor();
|
||||||
|
return HAIKU_CreateSystemCursor(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void HAIKU_FreeCursor(SDL_Cursor * cursor)
|
static void HAIKU_FreeCursor(SDL_Cursor * cursor)
|
||||||
|
|
|
@ -592,7 +592,8 @@ static SDL_Cursor *Wayland_CreateSystemCursor(SDL_SystemCursor id)
|
||||||
|
|
||||||
static SDL_Cursor *Wayland_CreateDefaultCursor(void)
|
static SDL_Cursor *Wayland_CreateDefaultCursor(void)
|
||||||
{
|
{
|
||||||
return Wayland_CreateSystemCursor(SDL_SYSTEM_CURSOR_DEFAULT);
|
SDL_SystemCursor id = SDL_GetDefaultSystemCursor();
|
||||||
|
return Wayland_CreateSystemCursor(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Wayland_FreeCursorData(SDL_CursorData *d)
|
static void Wayland_FreeCursorData(SDL_CursorData *d)
|
||||||
|
|
|
@ -84,11 +84,6 @@ static SDL_Cursor *WIN_CreateCursorAndData(HCURSOR hcursor)
|
||||||
return cursor;
|
return cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SDL_Cursor *WIN_CreateDefaultCursor(void)
|
|
||||||
{
|
|
||||||
return WIN_CreateCursorAndData(LoadCursor(NULL, IDC_ARROW));
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool IsMonochromeSurface(SDL_Surface *surface)
|
static bool IsMonochromeSurface(SDL_Surface *surface)
|
||||||
{
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
|
@ -342,6 +337,12 @@ static SDL_Cursor *WIN_CreateSystemCursor(SDL_SystemCursor id)
|
||||||
return WIN_CreateCursorAndData(LoadCursor(NULL, name));
|
return WIN_CreateCursorAndData(LoadCursor(NULL, name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static SDL_Cursor *WIN_CreateDefaultCursor(void)
|
||||||
|
{
|
||||||
|
SDL_SystemCursor id = SDL_GetDefaultSystemCursor();
|
||||||
|
return WIN_CreateSystemCursor(id);
|
||||||
|
}
|
||||||
|
|
||||||
static void WIN_FreeCursor(SDL_Cursor *cursor)
|
static void WIN_FreeCursor(SDL_Cursor *cursor)
|
||||||
{
|
{
|
||||||
SDL_CursorData *data = cursor->internal;
|
SDL_CursorData *data = cursor->internal;
|
||||||
|
|
|
@ -89,12 +89,6 @@ static SDL_Cursor *X11_CreateCursorAndData(Cursor x11_cursor)
|
||||||
return cursor;
|
return cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SDL_Cursor *X11_CreateDefaultCursor(void)
|
|
||||||
{
|
|
||||||
// None is used to indicate the default cursor
|
|
||||||
return X11_CreateCursorAndData(None);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef SDL_VIDEO_DRIVER_X11_XCURSOR
|
#ifdef SDL_VIDEO_DRIVER_X11_XCURSOR
|
||||||
static Cursor X11_CreateXCursorCursor(SDL_Surface *surface, int hot_x, int hot_y)
|
static Cursor X11_CreateXCursorCursor(SDL_Surface *surface, int hot_x, int hot_y)
|
||||||
{
|
{
|
||||||
|
@ -279,6 +273,12 @@ static SDL_Cursor *X11_CreateSystemCursor(SDL_SystemCursor id)
|
||||||
return cursor;
|
return cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static SDL_Cursor *X11_CreateDefaultCursor(void)
|
||||||
|
{
|
||||||
|
SDL_SystemCursor id = SDL_GetDefaultSystemCursor();
|
||||||
|
return X11_CreateSystemCursor(id);
|
||||||
|
}
|
||||||
|
|
||||||
static void X11_FreeCursor(SDL_Cursor *cursor)
|
static void X11_FreeCursor(SDL_Cursor *cursor)
|
||||||
{
|
{
|
||||||
Cursor x11_cursor = cursor->internal->cursor;
|
Cursor x11_cursor = cursor->internal->cursor;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue