Skip to content

Commit 95e4494

Browse files
committed
ADDED: cursorLocked variable and review required code #4940 #4955
1 parent c4414fa commit 95e4494

File tree

6 files changed

+24
-24
lines changed

6 files changed

+24
-24
lines changed

src/platforms/rcore_android.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ void EnableCursor(void)
560560
// Set cursor position in the middle
561561
SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2);
562562

563-
CORE.Input.Mouse.cursorHidden = false;
563+
CORE.Input.Mouse.cursorLocked = false;
564564
}
565565

566566
// Disables cursor (lock cursor)
@@ -569,7 +569,7 @@ void DisableCursor(void)
569569
// Set cursor position in the middle
570570
SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2);
571571

572-
CORE.Input.Mouse.cursorHidden = true;
572+
CORE.Input.Mouse.cursorLocked = true;
573573
}
574574

575575
// Swap back buffer with front buffer (screen drawing)

src/platforms/rcore_desktop_glfw.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ void EnableCursor(void)
10291029

10301030
if (glfwRawMouseMotionSupported()) glfwSetInputMode(platform.handle, GLFW_RAW_MOUSE_MOTION, GLFW_FALSE);
10311031

1032-
CORE.Input.Mouse.cursorHidden = false;
1032+
CORE.Input.Mouse.cursorLocked = false;
10331033
}
10341034

10351035
// Disables cursor (lock cursor)
@@ -1045,7 +1045,7 @@ void DisableCursor(void)
10451045

10461046
if (glfwRawMouseMotionSupported()) glfwSetInputMode(platform.handle, GLFW_RAW_MOUSE_MOTION, GLFW_TRUE);
10471047

1048-
CORE.Input.Mouse.cursorHidden = true;
1048+
CORE.Input.Mouse.cursorLocked = true;
10491049
}
10501050

10511051
// Swap back buffer with front buffer (screen drawing)

src/platforms/rcore_desktop_sdl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,7 @@ void EnableCursor(void)
12141214
#endif
12151215

12161216
platform.cursorRelative = false;
1217-
CORE.Input.Mouse.cursorHidden = false;
1217+
CORE.Input.Mouse.cursorLocked = false;
12181218
}
12191219

12201220
// Disables cursor (lock cursor)
@@ -1223,7 +1223,7 @@ void DisableCursor(void)
12231223
SDL_SetRelativeMouseMode(SDL_TRUE);
12241224

12251225
platform.cursorRelative = true;
1226-
CORE.Input.Mouse.cursorHidden = true;
1226+
CORE.Input.Mouse.cursorLocked = true;
12271227
}
12281228

12291229
// Swap back buffer with front buffer (screen drawing)

src/platforms/rcore_drm.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ void EnableCursor(void)
556556
SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2);
557557

558558
platform.cursorRelative = false;
559-
CORE.Input.Mouse.cursorHidden = false;
559+
CORE.Input.Mouse.cursorLocked = false;
560560
}
561561

562562
// Disables cursor (lock cursor)
@@ -566,7 +566,7 @@ void DisableCursor(void)
566566
SetMousePosition(0, 0);
567567

568568
platform.cursorRelative = true;
569-
CORE.Input.Mouse.cursorHidden = true;
569+
CORE.Input.Mouse.cursorLocked = true;
570570
}
571571

572572
#if defined(SUPPORT_DRM_CACHE)
@@ -2060,7 +2060,7 @@ static void PollMouseEvents(void)
20602060
}
20612061

20622062
// Screen confinement
2063-
if (!CORE.Input.Mouse.cursorHidden)
2063+
if (!CORE.Input.Mouse.cursorLocked)
20642064
{
20652065
if (CORE.Input.Mouse.currentPosition.x < 0) CORE.Input.Mouse.currentPosition.x = 0;
20662066
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;

src/platforms/rcore_web.c

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ static const char cursorLUT[11][12] = {
102102
"not-allowed" // 10 MOUSE_CURSOR_NOT_ALLOWED
103103
};
104104

105-
Vector2 lockedMousePos = { 0 };
106-
107105
//----------------------------------------------------------------------------------
108106
// Module Internal Functions Declaration
109107
//----------------------------------------------------------------------------------
@@ -862,7 +860,7 @@ void EnableCursor(void)
862860
// Set cursor position in the middle
863861
SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2);
864862

865-
// NOTE: CORE.Input.Mouse.cursorHidden handled by EmscriptenPointerlockCallback()
863+
// NOTE: CORE.Input.Mouse.cursorLocked handled by EmscriptenPointerlockCallback()
866864
}
867865

868866
// Disables cursor (lock cursor)
@@ -874,7 +872,7 @@ void DisableCursor(void)
874872
// Set cursor position in the middle
875873
SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2);
876874

877-
// NOTE: CORE.Input.Mouse.cursorHidden handled by EmscriptenPointerlockCallback()
875+
// NOTE: CORE.Input.Mouse.cursorLocked handled by EmscriptenPointerlockCallback()
878876
}
879877

880878
// Swap back buffer with front buffer (screen drawing)
@@ -955,7 +953,7 @@ void SetMousePosition(int x, int y)
955953
CORE.Input.Mouse.currentPosition = (Vector2){ (float)x, (float)y };
956954
CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.currentPosition;
957955

958-
if (CORE.Input.Mouse.cursorHidden) lockedMousePos = CORE.Input.Mouse.currentPosition;
956+
if (CORE.Input.Mouse.cursorLocked) CORE.Input.Mouse.lockedPosition = CORE.Input.Mouse.currentPosition;
959957

960958
// NOTE: emscripten not implemented
961959
glfwSetCursorPos(platform.handle, CORE.Input.Mouse.currentPosition.x, CORE.Input.Mouse.currentPosition.y);
@@ -966,7 +964,7 @@ void SetMouseCursor(int cursor)
966964
{
967965
if (CORE.Input.Mouse.cursor != cursor)
968966
{
969-
if (!CORE.Input.Mouse.cursorHidden) EM_ASM( { Module.canvas.style.cursor = UTF8ToString($0); }, cursorLUT[cursor]);
967+
if (!CORE.Input.Mouse.cursorLocked) EM_ASM( { Module.canvas.style.cursor = UTF8ToString($0); }, cursorLUT[cursor]);
970968

971969
CORE.Input.Mouse.cursor = cursor;
972970
}
@@ -1573,7 +1571,7 @@ static void MouseButtonCallback(GLFWwindow *window, int button, int action, int
15731571
static void MouseMoveCallback(GLFWwindow *window, double x, double y)
15741572
{
15751573
// If the pointer is not locked, follow the position
1576-
if (!CORE.Input.Mouse.cursorHidden)
1574+
if (!CORE.Input.Mouse.cursorLocked)
15771575
{
15781576
CORE.Input.Mouse.currentPosition.x = (float)x;
15791577
CORE.Input.Mouse.currentPosition.y = (float)y;
@@ -1641,11 +1639,11 @@ static EM_BOOL EmscriptenMouseCallback(int eventType, const EmscriptenMouseEvent
16411639
// Emscripten: Called on mouse move events
16421640
static EM_BOOL EmscriptenMouseMoveCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
16431641
{
1644-
// To emulate the GLFW_RAW_MOUSE_MOTION property.
1645-
if (CORE.Input.Mouse.cursorHidden)
1642+
// To emulate the GLFW_RAW_MOUSE_MOTION property
1643+
if (CORE.Input.Mouse.cursorLocked)
16461644
{
1647-
CORE.Input.Mouse.previousPosition.x = lockedMousePos.x - mouseEvent->movementX;
1648-
CORE.Input.Mouse.previousPosition.y = lockedMousePos.y - mouseEvent->movementY;
1645+
CORE.Input.Mouse.previousPosition.x = CORE.Input.Mouse.lockedPosition.x - mouseEvent->movementX;
1646+
CORE.Input.Mouse.previousPosition.y = CORE.Input.Mouse.lockedPosition.y - mouseEvent->movementY;
16491647
}
16501648

16511649
return 1; // The event was consumed by the callback handler
@@ -1654,12 +1652,12 @@ static EM_BOOL EmscriptenMouseMoveCallback(int eventType, const EmscriptenMouseE
16541652
// Emscripten: Called on pointer lock events
16551653
static EM_BOOL EmscriptenPointerlockCallback(int eventType, const EmscriptenPointerlockChangeEvent *pointerlockChangeEvent, void *userData)
16561654
{
1657-
CORE.Input.Mouse.cursorHidden = EM_ASM_INT( { if (document.pointerLockElement) return 1; }, 0);
1655+
CORE.Input.Mouse.cursorLocked = EM_ASM_INT( { if (document.pointerLockElement) return 1; }, 0);
16581656

1659-
if (CORE.Input.Mouse.cursorHidden)
1657+
if (CORE.Input.Mouse.cursorLocked)
16601658
{
1661-
lockedMousePos = CORE.Input.Mouse.currentPosition;
1662-
CORE.Input.Mouse.previousPosition = lockedMousePos;
1659+
CORE.Input.Mouse.lockedPosition = CORE.Input.Mouse.currentPosition;
1660+
CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.lockedPosition;
16631661
}
16641662

16651663
return 1; // The event was consumed by the callback handler

src/rcore.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,11 @@ typedef struct CoreData {
333333
Vector2 scale; // Mouse scaling
334334
Vector2 currentPosition; // Mouse position on screen
335335
Vector2 previousPosition; // Previous mouse position
336+
Vector2 lockedPosition; // Mouse position when locked
336337

337338
int cursor; // Tracks current mouse cursor
338339
bool cursorHidden; // Track if cursor is hidden
340+
bool cursorLocked; // Track if cursor is locked (disabled)
339341
bool cursorOnScreen; // Tracks if cursor is inside client area
340342

341343
char currentButtonState[MAX_MOUSE_BUTTONS]; // Registers current mouse button state

0 commit comments

Comments
 (0)