From 23cd32ff45477cc35ef596bc29a3344d99a477b1 Mon Sep 17 00:00:00 2001 From: Moros Smith Date: Tue, 27 May 2025 17:05:07 -0400 Subject: [PATCH] replace cursorHidden checks with a new lockedMouseCursor check --- src/platforms/rcore_web.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/platforms/rcore_web.c b/src/platforms/rcore_web.c index bf5a6ba5a..1368af2fa 100644 --- a/src/platforms/rcore_web.c +++ b/src/platforms/rcore_web.c @@ -104,6 +104,9 @@ static const char cursorLUT[11][12] = { Vector2 lockedMousePos = { 0 }; +// an alternative might be to add CORE.Input.Mouse.cursorLocked to CoreData +static int lockedMouseCursor = 0; + //---------------------------------------------------------------------------------- // Module Internal Functions Declaration //---------------------------------------------------------------------------------- @@ -861,7 +864,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: isMouseLocked handled by EmscriptenPointerlockCallback() } // Disables cursor (lock cursor) @@ -873,7 +876,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: isMouseLocked handled by EmscriptenPointerlockCallback() } // Swap back buffer with front buffer (screen drawing) @@ -954,7 +957,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 (lockedMouseCursor) lockedMousePos = CORE.Input.Mouse.currentPosition; // NOTE: emscripten not implemented glfwSetCursorPos(platform.handle, CORE.Input.Mouse.currentPosition.x, CORE.Input.Mouse.currentPosition.y); @@ -1589,7 +1592,7 @@ static void MouseButtonCallback(GLFWwindow *window, int button, int action, int static void MouseCursorPosCallback(GLFWwindow *window, double x, double y) { // If the pointer is not locked, follow the position - if (!CORE.Input.Mouse.cursorHidden) + if (!lockedMouseCursor) { CORE.Input.Mouse.currentPosition.x = (float)x; CORE.Input.Mouse.currentPosition.y = (float)y; @@ -1623,7 +1626,7 @@ static void MouseCursorPosCallback(GLFWwindow *window, double x, double y) static EM_BOOL EmscriptenMouseMoveCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData) { // To emulate the GLFW_RAW_MOUSE_MOTION property. - if (CORE.Input.Mouse.cursorHidden) + if (lockedMouseCursor) { CORE.Input.Mouse.previousPosition.x = lockedMousePos.x - mouseEvent->movementX; CORE.Input.Mouse.previousPosition.y = lockedMousePos.y - mouseEvent->movementY; @@ -1720,9 +1723,9 @@ static EM_BOOL EmscriptenMouseCallback(int eventType, const EmscriptenMouseEvent // Register 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); + lockedMouseCursor = EM_ASM_INT( { if (document.pointerLockElement) return 1; }, 0); - if (CORE.Input.Mouse.cursorHidden) + if (lockedMouseCursor) { lockedMousePos = CORE.Input.Mouse.currentPosition; CORE.Input.Mouse.previousPosition = lockedMousePos;