diff --git a/src/platforms/rcore_android.c b/src/platforms/rcore_android.c index 03cb9741c..bfbdd30b3 100644 --- a/src/platforms/rcore_android.c +++ b/src/platforms/rcore_android.c @@ -560,7 +560,7 @@ void EnableCursor(void) // Set cursor position in the middle SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2); - CORE.Input.Mouse.cursorHidden = false; + CORE.Input.Mouse.cursorLocked = false; } // Disables cursor (lock cursor) @@ -569,7 +569,7 @@ void DisableCursor(void) // Set cursor position in the middle SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2); - CORE.Input.Mouse.cursorHidden = true; + CORE.Input.Mouse.cursorLocked = true; } // Swap back buffer with front buffer (screen drawing) diff --git a/src/platforms/rcore_desktop_glfw.c b/src/platforms/rcore_desktop_glfw.c index c23b570d3..ca1ccebeb 100644 --- a/src/platforms/rcore_desktop_glfw.c +++ b/src/platforms/rcore_desktop_glfw.c @@ -1029,7 +1029,7 @@ void EnableCursor(void) if (glfwRawMouseMotionSupported()) glfwSetInputMode(platform.handle, GLFW_RAW_MOUSE_MOTION, GLFW_FALSE); - CORE.Input.Mouse.cursorHidden = false; + CORE.Input.Mouse.cursorLocked = false; } // Disables cursor (lock cursor) @@ -1045,7 +1045,7 @@ void DisableCursor(void) if (glfwRawMouseMotionSupported()) glfwSetInputMode(platform.handle, GLFW_RAW_MOUSE_MOTION, GLFW_TRUE); - CORE.Input.Mouse.cursorHidden = true; + CORE.Input.Mouse.cursorLocked = true; } // Swap back buffer with front buffer (screen drawing) diff --git a/src/platforms/rcore_desktop_sdl.c b/src/platforms/rcore_desktop_sdl.c index 5a62fa629..0dbe49436 100644 --- a/src/platforms/rcore_desktop_sdl.c +++ b/src/platforms/rcore_desktop_sdl.c @@ -1214,7 +1214,7 @@ void EnableCursor(void) #endif platform.cursorRelative = false; - CORE.Input.Mouse.cursorHidden = false; + CORE.Input.Mouse.cursorLocked = false; } // Disables cursor (lock cursor) @@ -1223,7 +1223,7 @@ void DisableCursor(void) SDL_SetRelativeMouseMode(SDL_TRUE); platform.cursorRelative = true; - CORE.Input.Mouse.cursorHidden = true; + CORE.Input.Mouse.cursorLocked = true; } // Swap back buffer with front buffer (screen drawing) diff --git a/src/platforms/rcore_drm.c b/src/platforms/rcore_drm.c index 930624fd2..2354bb3d2 100644 --- a/src/platforms/rcore_drm.c +++ b/src/platforms/rcore_drm.c @@ -556,7 +556,7 @@ void EnableCursor(void) SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2); platform.cursorRelative = false; - CORE.Input.Mouse.cursorHidden = false; + CORE.Input.Mouse.cursorLocked = false; } // Disables cursor (lock cursor) @@ -566,7 +566,7 @@ void DisableCursor(void) SetMousePosition(0, 0); platform.cursorRelative = true; - CORE.Input.Mouse.cursorHidden = true; + CORE.Input.Mouse.cursorLocked = true; } #if defined(SUPPORT_DRM_CACHE) @@ -2060,7 +2060,7 @@ static void PollMouseEvents(void) } // Screen confinement - if (!CORE.Input.Mouse.cursorHidden) + if (!CORE.Input.Mouse.cursorLocked) { if (CORE.Input.Mouse.currentPosition.x < 0) CORE.Input.Mouse.currentPosition.x = 0; if (CORE.Input.Mouse.currentPosition.x > CORE.Window.screen.width/CORE.Input.Mouse.scale.x) CORE.Input.Mouse.currentPosition.x = CORE.Window.screen.width/CORE.Input.Mouse.scale.x; diff --git a/src/platforms/rcore_web.c b/src/platforms/rcore_web.c index 9156f1599..93174b06d 100644 --- a/src/platforms/rcore_web.c +++ b/src/platforms/rcore_web.c @@ -102,8 +102,6 @@ static const char cursorLUT[11][12] = { "not-allowed" // 10 MOUSE_CURSOR_NOT_ALLOWED }; -Vector2 lockedMousePos = { 0 }; - //---------------------------------------------------------------------------------- // Module Internal Functions Declaration //---------------------------------------------------------------------------------- @@ -862,7 +860,7 @@ void EnableCursor(void) // Set cursor position in the middle SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2); - // NOTE: CORE.Input.Mouse.cursorHidden handled by EmscriptenPointerlockCallback() + // NOTE: CORE.Input.Mouse.cursorLocked handled by EmscriptenPointerlockCallback() } // Disables cursor (lock cursor) @@ -874,7 +872,7 @@ void DisableCursor(void) // Set cursor position in the middle SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2); - // NOTE: CORE.Input.Mouse.cursorHidden handled by EmscriptenPointerlockCallback() + // NOTE: CORE.Input.Mouse.cursorLocked handled by EmscriptenPointerlockCallback() } // Swap back buffer with front buffer (screen drawing) @@ -955,7 +953,7 @@ void SetMousePosition(int x, int y) CORE.Input.Mouse.currentPosition = (Vector2){ (float)x, (float)y }; CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.currentPosition; - if (CORE.Input.Mouse.cursorHidden) lockedMousePos = CORE.Input.Mouse.currentPosition; + if (CORE.Input.Mouse.cursorLocked) CORE.Input.Mouse.lockedPosition = CORE.Input.Mouse.currentPosition; // NOTE: emscripten not implemented glfwSetCursorPos(platform.handle, CORE.Input.Mouse.currentPosition.x, CORE.Input.Mouse.currentPosition.y); @@ -966,7 +964,7 @@ void SetMouseCursor(int cursor) { if (CORE.Input.Mouse.cursor != cursor) { - if (!CORE.Input.Mouse.cursorHidden) EM_ASM( { Module.canvas.style.cursor = UTF8ToString($0); }, cursorLUT[cursor]); + if (!CORE.Input.Mouse.cursorLocked) EM_ASM( { Module.canvas.style.cursor = UTF8ToString($0); }, cursorLUT[cursor]); CORE.Input.Mouse.cursor = cursor; } @@ -1573,7 +1571,7 @@ static void MouseButtonCallback(GLFWwindow *window, int button, int action, int static void MouseMoveCallback(GLFWwindow *window, double x, double y) { // If the pointer is not locked, follow the position - if (!CORE.Input.Mouse.cursorHidden) + if (!CORE.Input.Mouse.cursorLocked) { CORE.Input.Mouse.currentPosition.x = (float)x; CORE.Input.Mouse.currentPosition.y = (float)y; @@ -1641,11 +1639,11 @@ static EM_BOOL EmscriptenMouseCallback(int eventType, const EmscriptenMouseEvent // Emscripten: Called on mouse move events static EM_BOOL EmscriptenMouseMoveCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData) { - // To emulate the GLFW_RAW_MOUSE_MOTION property. - if (CORE.Input.Mouse.cursorHidden) + // To emulate the GLFW_RAW_MOUSE_MOTION property + if (CORE.Input.Mouse.cursorLocked) { - CORE.Input.Mouse.previousPosition.x = lockedMousePos.x - mouseEvent->movementX; - CORE.Input.Mouse.previousPosition.y = lockedMousePos.y - mouseEvent->movementY; + CORE.Input.Mouse.previousPosition.x = CORE.Input.Mouse.lockedPosition.x - mouseEvent->movementX; + CORE.Input.Mouse.previousPosition.y = CORE.Input.Mouse.lockedPosition.y - mouseEvent->movementY; } return 1; // The event was consumed by the callback handler @@ -1654,12 +1652,12 @@ static EM_BOOL EmscriptenMouseMoveCallback(int eventType, const EmscriptenMouseE // Emscripten: Called on pointer lock events static EM_BOOL EmscriptenPointerlockCallback(int eventType, const EmscriptenPointerlockChangeEvent *pointerlockChangeEvent, void *userData) { - CORE.Input.Mouse.cursorHidden = EM_ASM_INT( { if (document.pointerLockElement) return 1; }, 0); + CORE.Input.Mouse.cursorLocked = EM_ASM_INT( { if (document.pointerLockElement) return 1; }, 0); - if (CORE.Input.Mouse.cursorHidden) + if (CORE.Input.Mouse.cursorLocked) { - lockedMousePos = CORE.Input.Mouse.currentPosition; - CORE.Input.Mouse.previousPosition = lockedMousePos; + CORE.Input.Mouse.lockedPosition = CORE.Input.Mouse.currentPosition; + CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.lockedPosition; } return 1; // The event was consumed by the callback handler diff --git a/src/rcore.c b/src/rcore.c index 7eef877e2..b06422bbb 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -333,9 +333,11 @@ typedef struct CoreData { Vector2 scale; // Mouse scaling Vector2 currentPosition; // Mouse position on screen Vector2 previousPosition; // Previous mouse position + Vector2 lockedPosition; // Mouse position when locked int cursor; // Tracks current mouse cursor bool cursorHidden; // Track if cursor is hidden + bool cursorLocked; // Track if cursor is locked (disabled) bool cursorOnScreen; // Tracks if cursor is inside client area char currentButtonState[MAX_MOUSE_BUTTONS]; // Registers current mouse button state