From 323598c4f2a0be5aa936948f7de6368e9132e667 Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Sat, 27 May 2023 02:12:06 +0530 Subject: [PATCH] fix dpi scaling for scrollbars --- src/Settings.hx | 1 + src/gui/GuiControl.hx | 2 ++ src/gui/GuiScrollCtrl.hx | 2 +- src/gui/GuiTextListCtrl.hx | 31 ++++++++++++++++++------------- src/gui/HelpCreditsGui.hx | 1 + 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/Settings.hx b/src/Settings.hx index e6b10032..2da00feb 100644 --- a/src/Settings.hx +++ b/src/Settings.hx @@ -424,6 +424,7 @@ class Settings { #if js Window.getInstance().propagateKeyEvents = true; #end + // @:privateAccess Window.getInstance().window.center(); Window.getInstance().addResizeEvent(() -> { var wnd = Window.getInstance(); diff --git a/src/gui/GuiControl.hx b/src/gui/GuiControl.hx index 344681f3..bdc07ab2 100644 --- a/src/gui/GuiControl.hx +++ b/src/gui/GuiControl.hx @@ -263,6 +263,8 @@ class GuiControl { var uiScaleFactor = Settings.uiScale; var offset = this.position.clone(); + offset.x *= uiScaleFactor; + offset.y *= uiScaleFactor; if (this.parent != null) { parentRect = this.parent.getRenderRectangle(); diff --git a/src/gui/GuiScrollCtrl.hx b/src/gui/GuiScrollCtrl.hx index e8db4a6d..3b615992 100644 --- a/src/gui/GuiScrollCtrl.hx +++ b/src/gui/GuiScrollCtrl.hx @@ -189,7 +189,7 @@ class GuiScrollCtrl extends GuiControl { } for (i in 0...this._flow.numChildren) { var ch = this._flow.getChildAt(i); - ch.y -= cast actualDelta * this.maxScrollY / renderRect.extent.y; + ch.y -= cast(actualDelta * this.maxScrollY * Settings.uiScale * Settings.uiScale / renderRect.extent.y); } } } diff --git a/src/gui/GuiTextListCtrl.hx b/src/gui/GuiTextListCtrl.hx index a6ff4ac1..42cd4dd9 100644 --- a/src/gui/GuiTextListCtrl.hx +++ b/src/gui/GuiTextListCtrl.hx @@ -80,7 +80,7 @@ class GuiTextListCtrl extends GuiControl { for (i in 0...textObjs.length) { var text = textObjs[i]; text.setPosition(Math.floor((!scrollable ? renderRect.position.x : 0) + 5), - Math.floor((!scrollable ? renderRect.position.y : 0) + (i * (text.font.size + 4) + 5 + textYOffset * Settings.uiScale - this.scroll))); + Math.floor((!scrollable ? renderRect.position.y : 0) + (i * (text.font.size + 4) + 5 + textYOffset - this.scroll) * Settings.uiScale)); if (_prevSelected == i) { text.textColor = selectedColor; @@ -140,7 +140,8 @@ class GuiTextListCtrl extends GuiControl { } text.setPosition(Math.floor((!scrollable ? renderRect.position.x : 0) + 5), - Math.floor((!scrollable ? renderRect.position.y : 0) + (i * (text.font.size + 4) + 5 + textYOffset * Settings.uiScale - this.scroll))); + Math.floor((!scrollable ? renderRect.position.y : 0) + + (i * (text.font.size + 4 * Settings.uiScale) + (5 + textYOffset) * Settings.uiScale - this.scroll))); if (_prevSelected == i) { text.textColor = selectedColor; @@ -152,7 +153,7 @@ class GuiTextListCtrl extends GuiControl { } public function calculateFullHeight() { - return (this.texts.length * (font.size + 4)); + return (this.texts.length * (font.size + 4 * Settings.uiScale)); } public override function dispose() { @@ -184,7 +185,7 @@ class GuiTextListCtrl extends GuiControl { var renderRect = this.getRenderRectangle(); var yStart = renderRect.position.y; var dy = mousePos.y - yStart; - var hoverIndex = Math.floor(dy / (font.size + 4)); + var hoverIndex = Math.floor(dy / (font.size + 4 * Settings.uiScale)); if (hoverIndex >= this.texts.length) { hoverIndex = -1; } @@ -216,7 +217,7 @@ class GuiTextListCtrl extends GuiControl { var renderRect = this.getRenderRectangle(); var yStart = renderRect.position.y; var dy = mousePos.y - yStart; - var selectedIndex = Math.floor((dy + this.scroll) / (font.size + 4)); + var selectedIndex = Math.floor((dy + this.scroll) / (font.size + 4 * Settings.uiScale)); if (selectedIndex >= this.texts.length) { selectedIndex = -1; } @@ -238,25 +239,29 @@ class GuiTextListCtrl extends GuiControl { var off = this.getOffsetFromParent(); // Check if we are between the top and bottom, render normally in that case - var topY = 2 + (_prevSelected * (font.size + 4)) + g.y; - var bottomY = 2 + (_prevSelected * (font.size + 4)) + g.y + font.size + 4; + var topY = 2 * Settings.uiScale + (_prevSelected * (font.size + 4 * Settings.uiScale)) + g.y; + var bottomY = 2 * Settings.uiScale + (_prevSelected * (font.size + 4 * Settings.uiScale)) + g.y + font.size + 4 * Settings.uiScale; var topRectY = off.y; var bottomRectY = off.y + renderRect.extent.y; if (topY >= topRectY && bottomY <= bottomRectY) - g.drawRect(0, 5 + (_prevSelected * (font.size + 4)) - 3, renderRect.extent.x, font.size + 4); + g.drawRect(0, 5 * Settings.uiScale + + (_prevSelected * (font.size + 4 * Settings.uiScale)) + - 3 * Settings.uiScale, renderRect.extent.x, + font.size + + 4 * Settings.uiScale); // We need to do math the draw the partially visible top selected if (topY <= topRectY && bottomY >= topRectY) { - g.drawRect(0, this.scroll, renderRect.extent.x, topY + font.size + 4 - off.y); + g.drawRect(0, this.scroll, renderRect.extent.x, topY + font.size + 4 * Settings.uiScale - off.y); } // Same for the bottom if (topY <= bottomRectY && bottomY >= bottomRectY) { g.drawRect(0, this.scroll + renderRect.extent.y - font.size - - 4 - + (topY + font.size + 4 - bottomRectY), renderRect.extent.x, - off.y + - 4 * Settings.uiScale + + (topY + font.size + 4 * Settings.uiScale - bottomRectY), + renderRect.extent.x, off.y + renderRect.extent.y - (topY)); } @@ -274,7 +279,7 @@ class GuiTextListCtrl extends GuiControl { var hittestrect = this.getHitTestRect(false); for (i in 0...textObjs.length) { var text = textObjs[i]; - text.y = Math.floor((i * (text.font.size + 4) + 5 + textYOffset * Settings.uiScale - scrollY)); + text.y = Math.floor((i * (text.font.size + 4 * Settings.uiScale) + (5 + textYOffset) * Settings.uiScale - scrollY)); g.y = -scrollY; } redrawSelectionRect(hittestrect); diff --git a/src/gui/HelpCreditsGui.hx b/src/gui/HelpCreditsGui.hx index e9db3bc9..309a83a9 100644 --- a/src/gui/HelpCreditsGui.hx +++ b/src/gui/HelpCreditsGui.hx @@ -75,6 +75,7 @@ class HelpCreditsGui extends GuiImage { manualPageList = new GuiTextListCtrl(arial14, pageheadings); manualPageList.position = new Vector(0, 0); manualPageList.extent = new Vector(176, 352); + manualPageList.scrollable = true; scrollCtrl1.addChild(manualPageList); var scrollCtrl2 = new GuiScrollCtrl(ResourceLoader.getResource("data/ui/common/philscroll.png", ResourceLoader.getImage, this.imageResources)