| 165 | |
| 166 | |
| 167 | static void cursorPosCallback(GLFWwindow* win, double xpos, double ypos) { |
| 168 | contextSet((Context*) glfwGetWindowUserPointer(win)); |
| 169 | Window* window = APP->window; |
| 170 | |
| 171 | int width, height; |
| 172 | glfwGetWindowSize(win, &width, &height); |
| 173 | float ratio = window->pixelRatio / window->windowRatio; |
| 174 | |
| 175 | math::Vec mousePos; |
| 176 | math::Vec mouseDelta; |
| 177 | |
| 178 | if (window->internal->cursorLocked) { |
| 179 | mousePos = (math::Vec(window->internal->cursorLockedPosX, window->internal->cursorLockedPosY) / ratio).round(); |
| 180 | mouseDelta = math::Vec(xpos - width / 2, ypos - height / 2) / ratio; |
| 181 | |
| 182 | // Reset cursor to center of screen |
| 183 | glfwSetCursorPos(win, width / 2, height / 2); |
| 184 | } |
| 185 | else { |
| 186 | mousePos = (math::Vec(xpos, ypos) / ratio).round(); |
| 187 | mouseDelta = mousePos - window->internal->lastMousePos; |
| 188 | |
| 189 | window->internal->lastMousePos = mousePos; |
| 190 | } |
| 191 | |
| 192 | APP->event->handleHover(mousePos, mouseDelta); |
| 193 | |
| 194 | if (!window->internal->cursorLocked) { |
| 195 | // Keyboard/mouse MIDI driver |
| 196 | math::Vec scaledPos(xpos / width, ypos / height); |
| 197 | keyboard::mouseMove(scaledPos); |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | |
| 202 | static void cursorEnterCallback(GLFWwindow* win, int entered) { |
no test coverage detected