From a5362a0924f89f89bb6df9c1b5a41f51db34bcbc Mon Sep 17 00:00:00 2001 From: Skirmis Date: Wed, 21 Oct 2026 19:02:28 +0200 Subject: [PATCH] Fix ClickGUI mouse offset on HiDPI/Retina displays 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 #134 Co-Authored-By: Claude Opus 5.5 --- src/main/java/net/aoba/gui/GuiManager.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/aoba/gui/GuiManager.java b/src/main/java/net/aoba/gui/GuiManager.java index 597003c9..7586b283 100644 --- a/src/main/java/net/aoba/gui/GuiManager.java +++ b/src/main/java/net/aoba/gui/GuiManager.java @@ -459,10 +459,16 @@ public void onRender(Render2DEvent event) { Matrix3x2fStack matrixStack = drawContext.pose(); matrixStack.pushMatrix(); - int guiScale = MC.getWindow().calculateScale(MC.options.guiScale().get(), MC.isEnforceUnicode()); - matrixStack.scale(1.0f / guiScale, 1.0f / guiScale); - com.mojang.blaze3d.platform.Window window = MC.getWindow(); + + // The UI is laid out in window (screen) coordinates, which is the same space GLFW + // reports the mouse in. On HiDPI displays (e.g. macOS Retina) the framebuffer is + // larger than the window, so scale from screen coordinates to framebuffer pixels + // before dividing out the GUI scale. Otherwise rendering and mouse input disagree. + int guiScale = window.getGuiScale(); + float pixelRatio = window.getScreenWidth() > 0 ? (float) window.getWidth() / window.getScreenWidth() : 1.0f; + float uiScale = pixelRatio / guiScale; + matrixStack.scale(uiScale, uiScale); // Render ClickGUI and Topbar if (clickGuiOpen) { renderer.drawBox(0, 0, window.getScreenWidth(), window.getScreenHeight(),