Browse Source

Fix resetting cursor pos in cursorPosCallback() for non-integer pixelRatios.

tags/v2.6.5
Andrew Belt 3 months ago
parent
commit
ad78992e79
1 changed files with 7 additions and 5 deletions
  1. +7
    -5
      src/window/Window.cpp

+ 7
- 5
src/window/Window.cpp View File

@@ -103,6 +103,8 @@ struct Window::Internal {
double lastFrameDuration = NAN; double lastFrameDuration = NAN;


math::Vec lastMousePos; math::Vec lastMousePos;
double lockedCursorPosX = 0.0;
double lockedCursorPosY = 0.0;


std::map<std::string, std::shared_ptr<Font>> fontCache; std::map<std::string, std::shared_ptr<Font>> fontCache;
std::map<std::string, std::shared_ptr<Image>> imageCache; std::map<std::string, std::shared_ptr<Image>> imageCache;
@@ -167,13 +169,12 @@ static void cursorPosCallback(GLFWwindow* win, double xpos, double ypos) {
math::Vec mouseDelta = mousePos.minus(APP->window->internal->lastMousePos); math::Vec mouseDelta = mousePos.minus(APP->window->internal->lastMousePos);


if (glfwGetInputMode(win, GLFW_CURSOR) == GLFW_CURSOR_HIDDEN) { if (glfwGetInputMode(win, GLFW_CURSOR) == GLFW_CURSOR_HIDDEN) {
math::Vec lastMousePos = APP->window->internal->lastMousePos;
glfwSetCursorPos(win, lastMousePos.x, lastMousePos.y);
}
else {
APP->window->internal->lastMousePos = mousePos;
glfwSetCursorPos(win, APP->window->internal->lockedCursorPosX, APP->window->internal->lockedCursorPosY);
mousePos = math::Vec(APP->window->internal->lockedCursorPosX, APP->window->internal->lockedCursorPosY).div(APP->window->pixelRatio / APP->window->windowRatio).round();
} }


APP->window->internal->lastMousePos = mousePos;

APP->event->handleHover(mousePos, mouseDelta); APP->event->handleHover(mousePos, mouseDelta);


// Keyboard/mouse MIDI driver // Keyboard/mouse MIDI driver
@@ -633,6 +634,7 @@ void Window::cursorLock() {
// GLFW_CURSOR_DISABLED is buggy. // GLFW_CURSOR_DISABLED is buggy.
// https://github.com/glfw/glfw/issues/2523 // https://github.com/glfw/glfw/issues/2523
// So hide the cursor instead and reset mouse position in cursorPosCallback(). // So hide the cursor instead and reset mouse position in cursorPosCallback().
glfwGetCursorPos(win, &internal->lockedCursorPosX, &internal->lockedCursorPosY);
glfwSetInputMode(win, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); glfwSetInputMode(win, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
} }




Loading…
Cancel
Save