Skip to content

Commit 37a87e1

Browse files
committed
Fix DPI relative scaling
1 parent dc95f7d commit 37a87e1

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/main/kotlin/com/lambda/gui/DearImGui.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ object DearImGui : Loadable {
7575
}
7676

7777
fun render() {
78-
val scale = (ClickGuiLayout.scaleSetting / 100.0).toFloat()
78+
val userPercent = ClickGuiLayout.scaleSetting / 100.0
79+
val dpi = ClickGuiLayout.deviceScaleMultiplier()
80+
val base = ClickGuiLayout.BASE_SCALE_MULTI * dpi
81+
val fontScaleSetting = ClickGuiLayout.fontScale
82+
val scale = (base * userPercent * fontScaleSetting).toFloat()
7983

8084
if (lastScale == 0f) {
8185
targetScale = scale

src/main/kotlin/com/lambda/gui/components/ClickGuiLayout.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,18 @@ object ClickGuiLayout : Loadable, Configurable(GuiConfig) {
8181
LongDelay("Long Delay", "Show tooltip after a longer delay (~0.40s), and only after the mouse has been still briefly on the item.", ImGuiHoveredFlags.DelayNormal)
8282
}
8383

84-
const val RELATION = 0.02604
85-
const val BASE_SCALE = 130
86-
val width = mc.window.monitor!!.currentVideoMode!!.width
84+
const val BASE_SCALE = 100
85+
const val BASE_SCALE_MULTI = 1.8
8786

88-
// don't worry, I'm a professional
89-
// linear interpolation :3
90-
val defaultScale = (RELATION * width + BASE_SCALE).toInt()
87+
fun deviceScaleMultiplier() = try {
88+
val monitorWidth = mc.window.monitor!!.currentVideoMode!!.width.toDouble()
89+
(monitorWidth / 1920.0).coerceIn(0.5, 4.0)
90+
} catch (_: Throwable) {
91+
1.0
92+
}
9193

9294
// General
93-
internal val scaleSetting by setting("Scale", defaultScale, 50..300, 1, unit = "%").group(Group.General)
95+
internal val scaleSetting by setting("Scale", BASE_SCALE, 50..300, 1, unit = "%").group(Group.General)
9496
val alpha by setting("Alpha", 1.0f, 0.0f..1.0f, 0.01f).group(Group.General)
9597
val disabledAlpha by setting("Disabled Alpha", 0.6f, 0.0f..1.0f, 0.01f).group(Group.General)
9698
val tooltipType by setting("Tooltip Type", TooltipType.Stationary, description = "When to show the tooltip.").group(Group.General)

0 commit comments

Comments
 (0)