replace cursorHidden checks with a new lockedMouseCursor check
This commit is contained in:
parent
8d9c1cecb7
commit
23cd32ff45
1 changed files with 10 additions and 7 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue