refactor: use InputManager for screens, DPI-aware InputManager

This commit is contained in:
Tropical
2026-03-09 23:41:56 -05:00
parent f0aa04a7ee
commit c4ce9b5377
3 changed files with 40 additions and 41 deletions

View File

@@ -61,13 +61,21 @@ static GLFWwindow *getWindow() {
// GLFW callbacks
// ---------------------------------------------------------------------------
static void onCursorPos(GLFWwindow * /*w*/, double x, double y) {
static void onCursorPos(GLFWwindow* w, double x, double y) {
float scaleX = 1;
float scaleY = 1;
glfwGetWindowContentScale(w, &scaleX, &scaleY);
x *= scaleX;
y *= scaleX;
if (s_cursorInitialized) {
s_mouseAccumX += (float)(x - s_lastCursorX);
s_mouseAccumY += (float)(y - s_lastCursorY);
} else {
s_cursorInitialized = true;
}
s_lastCursorX = x;
s_lastCursorY = y;
}
@@ -208,24 +216,25 @@ void C_4JInput::Tick(void) {
s_mouseAccumX = s_mouseAccumY = 0.0f;
// 6. Mouse buttons (only meaningful when locked in-game)
if (s_mouseLocked) {
s_mouseLeftCurrent = (glfwGetMouseButton(w, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS);
s_mouseRightCurrent = (glfwGetMouseButton(w, GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS);
} else {
// Not locked. Allow a left-click to re-lock (if not in a menu)
bool lclick = (glfwGetMouseButton(w, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS);
if (!menuNow && lclick) {
s_mouseLocked = true;
glfwSetInputMode(w, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
if (glfwRawMouseMotionSupported())
glfwSetInputMode(w, GLFW_RAW_MOUSE_MOTION, GLFW_TRUE);
s_mouseAccumX = s_mouseAccumY = 0.0f;
s_cursorInitialized = false;
}
s_mouseLeftCurrent = false;
s_mouseRightCurrent = false;
s_frameRelX = s_frameRelY = 0.0f;
}
s_mouseLeftCurrent = (glfwGetMouseButton(w, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS);
s_mouseRightCurrent = (glfwGetMouseButton(w, GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS);
// if (s_mouseLocked) {
// printf("locked\n");
// } else {
// // Not locked. Allow a left-click to re-lock (if not in a menu)
// bool lclick = (glfwGetMouseButton(w, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS);
// if (!menuNow && lclick) {
// s_mouseLocked = true;
// glfwSetInputMode(w, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
// if (glfwRawMouseMotionSupported())
// glfwSetInputMode(w, GLFW_RAW_MOUSE_MOTION, GLFW_TRUE);
// s_mouseAccumX = s_mouseAccumY = 0.0f;
// s_cursorInitialized = false;
// }
// s_mouseLeftCurrent = false;
// s_mouseRightCurrent = false;
// s_frameRelX = s_frameRelY = 0.0f;
// }
}
// ---------------------------------------------------------------------------