diff --git a/src/platforms/rcore_desktop_glfw.c b/src/platforms/rcore_desktop_glfw.c index 1975a7bfe..ab1d93a4e 100644 --- a/src/platforms/rcore_desktop_glfw.c +++ b/src/platforms/rcore_desktop_glfw.c @@ -111,6 +111,7 @@ //---------------------------------------------------------------------------------- typedef struct { GLFWwindow *handle; // GLFW window handle (graphic device) + GLFWcursor *customCursor; // GLFW custom cursor handle } PlatformData; //---------------------------------------------------------------------------------- @@ -1238,6 +1239,8 @@ void SetMousePosition(int x, int y) // Set mouse cursor void SetMouseCursor(int cursor) { + ClearMouseCursorImage(); + CORE.Input.Mouse.cursor = cursor; if (cursor == MOUSE_CURSOR_DEFAULT) glfwSetCursor(platform.handle, NULL); else @@ -1247,6 +1250,38 @@ void SetMouseCursor(int cursor) } } +// Set mouse cursor to custom image +void SetMouseCursorImage(Image image, int hotX, int hotY) +{ + // Ensure image is RGBA format + Image copy = ImageCopy(image); + ImageFormat(©, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8); + + GLFWimage glfwImage = { copy.width, copy.height, (unsigned char *)copy.data }; + + if (platform.customCursor != NULL) + { + glfwDestroyCursor(platform.customCursor); + platform.customCursor = NULL; + } + + platform.customCursor = glfwCreateCursor(&glfwImage, hotX, hotY); + glfwSetCursor(platform.handle, platform.customCursor); + + UnloadImage(copy); +} + +// Restore default mouse cursor +void ClearMouseCursorImage(void) +{ + if (platform.customCursor != NULL) + { + glfwSetCursor(platform.handle, NULL); + glfwDestroyCursor(platform.customCursor); + platform.customCursor = NULL; + } +} + // Get physical key name const char *GetKeyName(int key) { @@ -1870,6 +1905,12 @@ int InitPlatform(void) // Close platform void ClosePlatform(void) { + if (platform.customCursor != NULL) + { + glfwDestroyCursor(platform.customCursor); + platform.customCursor = NULL; + } + glfwDestroyWindow(platform.handle); glfwTerminate(); diff --git a/src/raylib.h b/src/raylib.h index a1391de19..1be2020c5 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1232,6 +1232,8 @@ RLAPI void SetMouseScale(float scaleX, float scaleY); // Set mouse scali RLAPI float GetMouseWheelMove(void); // Get mouse wheel movement for X or Y, whichever is larger RLAPI Vector2 GetMouseWheelMoveV(void); // Get mouse wheel movement for both X and Y RLAPI void SetMouseCursor(int cursor); // Set mouse cursor +RLAPI void SetMouseCursorImage(Image image, int hotX, int hotY); // Set mouse cursor to custom image +RLAPI void ClearMouseCursorImage(void); // Restore default mouse cursor // Input-related functions: touch RLAPI int GetTouchX(void); // Get touch position X for touch point 0 (relative to screen size)