MCPcopy Create free account
hub / github.com/VCVRack/Rack / cursorPosCallback

Function cursorPosCallback

src/window/Window.cpp:167–199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

165
166
167static 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
202static void cursorEnterCallback(GLFWwindow* win, int entered) {

Callers 1

stepMethod · 0.85

Calls 5

contextSetFunction · 0.85
VecClass · 0.85
mouseMoveFunction · 0.85
roundMethod · 0.80
handleHoverMethod · 0.80

Tested by

no test coverage detected