From 8ae9e62be3f219a3d2429d54035fabb866c6a8bd Mon Sep 17 00:00:00 2001 From: Tropical <42101043+tropicaaal@users.noreply.github.com> Date: Tue, 10 Mar 2026 21:14:19 -0500 Subject: [PATCH] feat: reimplement absolute mouse input on SDL --- 4J.Input/4J_Input.cpp | 12 +++++++++++- 4J.Input/4J_Input.h | 4 ++-- Minecraft.Client/UI/Screen.cpp | 2 -- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/4J.Input/4J_Input.cpp b/4J.Input/4J_Input.cpp index 2ed4de5e4..f79180bf3 100644 --- a/4J.Input/4J_Input.cpp +++ b/4J.Input/4J_Input.cpp @@ -21,6 +21,7 @@ static bool s_prevMenuDisplayed = false; static bool s_snapTaken = false; static float s_accumRelX = 0, s_accumRelY = 0; static float s_snapRelX = 0, s_snapRelY = 0; +static int s_mouseX = 0, s_mouseY = 0; static int s_scrollTicksForButtonPressed = 0; static int s_scrollTicksForGetValue = 0; @@ -143,7 +144,7 @@ void C_4JInput::Tick() { if (sc > 0 && sc < KEY_COUNT) s_keysCurrent[sc] = state[sc] != 0; } - Uint32 btns = SDL_GetMouseState(NULL, NULL); + Uint32 btns = SDL_GetMouseState(&s_mouseX, &s_mouseY); s_mouseLeftCurrent = (btns & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0; s_mouseRightCurrent = (btns & SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0; @@ -300,6 +301,15 @@ float C_4JInput::GetJoypadStick_RY(int, bool) { unsigned char C_4JInput::GetJoypadLTrigger(int, bool) { return s_mouseRightCurrent ? 255 : 0; } unsigned char C_4JInput::GetJoypadRTrigger(int, bool) { return s_mouseLeftCurrent ? 255 : 0; } + +int C_4JInput::GetMouseX() { + return s_mouseX; +} +int C_4JInput::GetMouseY() { + return s_mouseY; +} + + // We detect if a Menu is visible on the player's screen to the mouse being stuck. void C_4JInput::SetMenuDisplayed(int iPad, bool bVal) { if (iPad >= 0 && iPad < 4) s_menuDisplayed[iPad] = bVal; diff --git a/4J.Input/4J_Input.h b/4J.Input/4J_Input.h index 6fbe0006c..565fa08c4 100644 --- a/4J.Input/4J_Input.h +++ b/4J.Input/4J_Input.h @@ -134,8 +134,8 @@ public: //bool InputDetected(DWORD dwUserIndex,WCHAR *pwchInput); - float GetMouseX(); - float GetMouseY(); + int GetMouseX(); + int GetMouseY(); }; // Singleton diff --git a/Minecraft.Client/UI/Screen.cpp b/Minecraft.Client/UI/Screen.cpp index f66e14953..b9162e89f 100644 --- a/Minecraft.Client/UI/Screen.cpp +++ b/Minecraft.Client/UI/Screen.cpp @@ -121,8 +121,6 @@ void Screen::updateEvents() bool leftState = InputManager.ButtonDown(0, MINECRAFT_ACTION_ACTION); bool rightState = InputManager.ButtonDown(0, MINECRAFT_ACTION_USE); - printf("%d, %d\n", leftState, rightState); - if (leftState && !prevLeftState) { mouseClicked(xMouse, yMouse, 0); }