Skip to content

Fix ClickGUI mouse offset on HiDPI/Retina displays - #161

Merged
Cocolots merged 1 commit into
Cocolots:masterfrom
SkirmisLTU:fix/gui-hidpi-mouse-offset
Oct 24, 2026
Merged

Cocolots merged 1 commit into
Cocolots:masterfrom
SkirmisLTU:fix/gui-hidpi-mouse-offset

Conversation

@SkirmisLTU

Copy link
Copy Markdown
Contributor

Fixes #134

Problem

On HiDPI displays such as macOS Retina, the ClickGUI is the wrong size and clicks land away from the cursor, so modules can't be toggled. Switching to Exclusive fullscreen hides the problem.

Cause

GuiManager.onRender scaled the pose by 1 / guiScale, so the GUI was drawn in framebuffer pixels. Layout (getScreenWidth()/getScreenHeight()), hit-testing and the tooltip all use window (screen) coordinates, which is the space GLFW reports the cursor in (MouseHandler.xpos/ypos). On a standard display the two spaces are the same. On Retina the framebuffer is 2× the window, so rendering and input disagree by that factor. Exclusive fullscreen works around it because the framebuffer and window sizes match there.

Fix

Before dividing out the GUI scale, multiply the pose scale by the framebuffer-to-window pixel ratio (getWidth() / getScreenWidth()). Rendering, layout and mouse input now all use window coordinates, and the GUI keeps the same physical size as on non-HiDPI screens. Scissor clipping still lines up because enableScissor goes through the same pose. The change also uses window.getGuiScale() to match the projection in Renderer2D.

The mouse events are unchanged on purpose, because MacroRecorder/MacroPlayer replay the raw cursor coordinates.

On standard displays the pixel ratio is 1, so nothing changes there.

Notes

  • HUD positions that were saved on a Retina display were stored in framebuffer pixels, so they may appear in different places once and need dragging back.

Testing

  • ./gradlew build passes (JDK 25)
  • In-game on macOS Retina, windowed: overlay covers the window, clicks/hover/drag/sliders line up with the cursor

🤖 Generated with Claude Code

The ClickGUI was rendered in framebuffer pixels but laid out and
hit-tested in window (screen) coordinates, which is the space GLFW
reports the cursor in. On HiDPI displays such as macOS Retina the
framebuffer is larger than the window, so the GUI was drawn at the
wrong size and clicks landed away from the cursor.

Scale the GUI pose by the framebuffer/window pixel ratio before
dividing out the GUI scale so rendering, layout and mouse input all
share window coordinates. Also use window.getGuiScale() to match the
projection used by Renderer2D.

Fixes Cocolots#134

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Cocolots

Copy link
Copy Markdown
Owner

Thanks! I will have a look tomorrow during the day.

@Cocolots
Cocolots merged commit 0eb84da into Cocolots:master Oct 24, 2026
3 checks passed
@Cocolots

Copy link
Copy Markdown
Owner

Looks good. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GUI not working

2 participants