Repository navigation
Fix ClickGUI mouse offset on HiDPI/Retina displays - #161
Merged
Merged
Conversation
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>
Owner
|
Thanks! I will have a look tomorrow during the day. |
Owner
|
Looks good. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.onRenderscaled the pose by1 / 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 becauseenableScissorgoes through the same pose. The change also useswindow.getGuiScale()to match the projection inRenderer2D.The mouse events are unchanged on purpose, because
MacroRecorder/MacroPlayerreplay the raw cursor coordinates.On standard displays the pixel ratio is 1, so nothing changes there.
Notes
Testing
./gradlew buildpasses (JDK 25)🤖 Generated with Claude Code