Add SetMouseCursorImage() and ClearMouseCursorImage() for GLFW platform
This commit is contained in:
parent
a6d5a7ffbc
commit
7b4d4989d1
|
|
@ -111,6 +111,7 @@
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
typedef struct {
|
typedef struct {
|
||||||
GLFWwindow *handle; // GLFW window handle (graphic device)
|
GLFWwindow *handle; // GLFW window handle (graphic device)
|
||||||
|
GLFWcursor *customCursor; // GLFW custom cursor handle
|
||||||
} PlatformData;
|
} PlatformData;
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
@ -1238,6 +1239,8 @@ void SetMousePosition(int x, int y)
|
||||||
// Set mouse cursor
|
// Set mouse cursor
|
||||||
void SetMouseCursor(int cursor)
|
void SetMouseCursor(int cursor)
|
||||||
{
|
{
|
||||||
|
ClearMouseCursorImage();
|
||||||
|
|
||||||
CORE.Input.Mouse.cursor = cursor;
|
CORE.Input.Mouse.cursor = cursor;
|
||||||
if (cursor == MOUSE_CURSOR_DEFAULT) glfwSetCursor(platform.handle, NULL);
|
if (cursor == MOUSE_CURSOR_DEFAULT) glfwSetCursor(platform.handle, NULL);
|
||||||
else
|
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
|
// Get physical key name
|
||||||
const char *GetKeyName(int key)
|
const char *GetKeyName(int key)
|
||||||
{
|
{
|
||||||
|
|
@ -1870,6 +1905,12 @@ int InitPlatform(void)
|
||||||
// Close platform
|
// Close platform
|
||||||
void ClosePlatform(void)
|
void ClosePlatform(void)
|
||||||
{
|
{
|
||||||
|
if (platform.customCursor != NULL)
|
||||||
|
{
|
||||||
|
glfwDestroyCursor(platform.customCursor);
|
||||||
|
platform.customCursor = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
glfwDestroyWindow(platform.handle);
|
glfwDestroyWindow(platform.handle);
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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 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 Vector2 GetMouseWheelMoveV(void); // Get mouse wheel movement for both X and Y
|
||||||
RLAPI void SetMouseCursor(int cursor); // Set mouse cursor
|
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
|
// Input-related functions: touch
|
||||||
RLAPI int GetTouchX(void); // Get touch position X for touch point 0 (relative to screen size)
|
RLAPI int GetTouchX(void); // Get touch position X for touch point 0 (relative to screen size)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user