[core] Added desktop cursor getter and setter functions

This commit is contained in:
Chance Snow 2020-10-07 15:01:44 -05:00
parent 7ef114d1da
commit 4ece005269
3 changed files with 76 additions and 0 deletions

View File

@ -148,6 +148,8 @@ RLAPI void SetMousePosition(int x, int y); // Set mouse posit
RLAPI void SetMouseOffset(int offsetX, int offsetY); // Set mouse offset
RLAPI void SetMouseScale(float scaleX, float scaleY); // Set mouse scaling
RLAPI int GetMouseWheelMove(void); // Returns mouse wheel movement Y
RLAPI MouseCursor GetMouseCursor(void); // Returns mouse cursor
RLAPI void SetMouseCursor(MouseCursor cursor); // Set mouse cursor
// Input-related functions: touch
RLAPI int GetTouchX(void); // Returns touch position X for touch point 0 (relative to screen size)

View File

@ -400,6 +400,8 @@ typedef struct CoreData {
Vector2 offset; // Mouse offset
Vector2 scale; // Mouse scaling
MouseCursor cursor; // Tracks current mouse cursor
void* standardCursors[10]; // Opaque pointers to GLFW cursors
bool cursorHidden; // Track if cursor is hidden
bool cursorOnScreen; // Tracks if cursor is inside client area
#if defined(PLATFORM_WEB)
@ -615,8 +617,29 @@ void InitWindow(int width, int height, const char *title)
// Initialize required global values different than 0
CORE.Input.Keyboard.exitKey = KEY_ESCAPE;
CORE.Input.Mouse.scale = (Vector2){ 1.0f, 1.0f };
CORE.Input.Mouse.cursor = MOUSE_CURSOR_ARROW;
CORE.Input.Gamepad.lastButtonPressed = -1;
#if defined(PLATFORM_DESKTOP)
// Initialize GLFW's standard cursors
const int shapes[] = {
MOUSE_CURSOR_ARROW,
MOUSE_CURSOR_IBEAM,
MOUSE_CURSOR_CROSSHAIR,
MOUSE_CURSOR_POINTING_HAND,
MOUSE_CURSOR_RESIZE_EW,
MOUSE_CURSOR_RESIZE_NS,
MOUSE_CURSOR_RESIZE_NWSE,
MOUSE_CURSOR_RESIZE_NESW,
MOUSE_CURSOR_RESIZE_ALL,
MOUSE_CURSOR_NOT_ALLOWED
};
for (int i = 0; i < sizeof(CORE.Input.Mouse.standardCursors) / sizeof(CORE.Input.Mouse.standardCursors[0]); i += 1)
{
CORE.Input.Mouse.standardCursors[i] = glfwCreateStandardCursor(shapes[i]);
}
#endif
#if defined(PLATFORM_ANDROID)
CORE.Window.screen.width = width;
CORE.Window.screen.height = height;
@ -751,6 +774,11 @@ void CloseWindow(void)
rlglClose(); // De-init rlgl
#if defined(PLATFORM_DESKTOP)
for (int i = 0; i < sizeof(CORE.Input.Mouse.standardCursors) / sizeof(CORE.Input.Mouse.standardCursors[0]); i += 1)
glfwDestroyCursor(CORE.Input.Mouse.standardCursors[i]);
#endif
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
glfwDestroyWindow(CORE.Window.handle);
glfwTerminate();
@ -2647,6 +2675,29 @@ int GetMouseWheelMove(void)
#endif
}
// Returns mouse cursor
MouseCursor GetMouseCursor(void)
{
return CORE.Input.Mouse.cursor;
}
// Set mouse cursor
// NOTE: This is a no-op on platforms other than PLATFORM_DESKTOP
void SetMouseCursor(MouseCursor cursor)
{
#if defined(PLATFORM_DESKTOP)
CORE.Input.Mouse.cursor = cursor;
if (cursor == MOUSE_CURSOR_DEFAULT)
{
glfwSetCursor(CORE.Window.handle, NULL);
}
else
{
glfwSetCursor(CORE.Window.handle, CORE.Input.Mouse.standardCursors[cursor]);
}
#endif
}
// Returns touch position X for touch point 0 (relative to screen size)
int GetTouchX(void)
{

View File

@ -620,6 +620,27 @@ typedef enum {
MOUSE_MIDDLE_BUTTON = 2
} MouseButton;
// Mouse cursor types
typedef enum {
MOUSE_CURSOR_DEFAULT = 0,
MOUSE_CURSOR_ARROW = 0x00036001,
MOUSE_CURSOR_IBEAM = 0x00036002,
MOUSE_CURSOR_CROSSHAIR = 0x00036003,
MOUSE_CURSOR_POINTING_HAND = 0x00036004,
// The horizontal resize/move arrow shape.
MOUSE_CURSOR_RESIZE_EW = 0x00036005,
// The vertical resize/move arrow shape.
MOUSE_CURSOR_RESIZE_NS = 0x00036006,
// The top-left to bottom-right diagonal resize/move arrow shape.
MOUSE_CURSOR_RESIZE_NWSE = 0x00036007,
// The top-right to bottom-left diagonal resize/move arrow shape.
MOUSE_CURSOR_RESIZE_NESW = 0x00036008,
// The omni-directional resize/move cursor shape.
MOUSE_CURSOR_RESIZE_ALL = 0x00036009,
// The operation-not-allowed shape.
MOUSE_CURSOR_NOT_ALLOWED = 0x0003600A,
} MouseCursor;
// Gamepad number
typedef enum {
GAMEPAD_PLAYER1 = 0,
@ -1019,6 +1040,8 @@ RLAPI void SetMousePosition(int x, int y); // Set mouse posit
RLAPI void SetMouseOffset(int offsetX, int offsetY); // Set mouse offset
RLAPI void SetMouseScale(float scaleX, float scaleY); // Set mouse scaling
RLAPI int GetMouseWheelMove(void); // Returns mouse wheel movement Y
RLAPI MouseCursor GetMouseCursor(void); // Returns mouse cursor
RLAPI void SetMouseCursor(MouseCursor cursor); // Set mouse cursor
// Input-related functions: touch
RLAPI int GetTouchX(void); // Returns touch position X for touch point 0 (relative to screen size)