| 642 | |
| 643 | |
| 644 | void Window::cursorLock() { |
| 645 | if (!settings::allowCursorLock) |
| 646 | return; |
| 647 | if (internal->cursorLocked) |
| 648 | return; |
| 649 | |
| 650 | // GLFW_CURSOR_DISABLED is buggy. |
| 651 | // https://github.com/glfw/glfw/issues/2523 |
| 652 | // So instead, hide the cursor, move cursor to center of window, and reset mouse position every frame in cursorPosCallback(). |
| 653 | glfwGetCursorPos(win, &internal->cursorLockedPosX, &internal->cursorLockedPosY); |
| 654 | internal->cursorLocked = true; |
| 655 | glfwSetInputMode(win, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); |
| 656 | |
| 657 | int width, height; |
| 658 | glfwGetWindowSize(win, &width, &height); |
| 659 | glfwSetCursorPos(win, width / 2, height / 2); |
| 660 | } |
| 661 | |
| 662 | |
| 663 | void Window::cursorUnlock() { |
no outgoing calls
no test coverage detected