REVIEWED: SetMouseCursor() #3416

This commit is contained in:
Ray 2023-10-14 22:45:56 +02:00
parent b79e381092
commit 37e3ffcaac

View file

@ -659,8 +659,11 @@ void SetMousePosition(int x, int y)
// Set mouse cursor // Set mouse cursor
void SetMouseCursor(int cursor) void SetMouseCursor(int cursor)
{ {
if (CORE.Input.Mouse.cursor != cursor)
{
const char *cursorName = NULL;
CORE.Input.Mouse.cursor = cursor; CORE.Input.Mouse.cursor = cursor;
const char *cursorName;
switch (cursor) switch (cursor)
{ {
case MOUSE_CURSOR_IBEAM: cursorName = "text"; break; case MOUSE_CURSOR_IBEAM: cursorName = "text"; break;
@ -672,16 +675,10 @@ void SetMouseCursor(int cursor)
case MOUSE_CURSOR_RESIZE_NESW: cursorName = "nesw-resize"; break; case MOUSE_CURSOR_RESIZE_NESW: cursorName = "nesw-resize"; break;
case MOUSE_CURSOR_RESIZE_ALL: cursorName = "move"; break; case MOUSE_CURSOR_RESIZE_ALL: cursorName = "move"; break;
case MOUSE_CURSOR_NOT_ALLOWED: cursorName = "not-allowed"; break; case MOUSE_CURSOR_NOT_ALLOWED: cursorName = "not-allowed"; break;
case MOUSE_CURSOR_ARROW: // WARNING: It does not seem t be a specific cursor for arrow
case MOUSE_CURSOR_ARROW: // can't find a name specifically for arrow cursor case MOUSE_CURSOR_DEFAULT: cursorName = "default"; break;
case MOUSE_CURSOR_DEFAULT:
{
cursorName = "default";
} break;
default: default:
{ {
TRACELOG(LOG_WARNING, "Cursor value out of bound (%d). Setting to default", cursor);
cursorName = "default"; cursorName = "default";
CORE.Input.Mouse.cursor = MOUSE_CURSOR_DEFAULT; CORE.Input.Mouse.cursor = MOUSE_CURSOR_DEFAULT;
} break; } break;
@ -691,6 +688,7 @@ void SetMouseCursor(int cursor)
// The canvas is coded to the Id "canvas" on init // The canvas is coded to the Id "canvas" on init
EM_ASM({document.getElementById("canvas").style.cursor = UTF8ToString($0);}, cursorName); EM_ASM({document.getElementById("canvas").style.cursor = UTF8ToString($0);}, cursorName);
} }
}
// Register all input events // Register all input events
void PollInputEvents(void) void PollInputEvents(void)