From c11ebaf7d1c9c4d80283639e6da412d94fbc2e1d Mon Sep 17 00:00:00 2001 From: Rankyn Bass Date: Sun, 21 Apr 2024 20:04:49 -0700 Subject: [PATCH] Use ImGuiHelpers to scale EVERYTHING --- src/XIVLauncher.Core/Components/Background.cs | 4 +- .../Components/Common/Button.cs | 2 +- .../Components/Common/Checkbox.cs | 2 +- .../Components/Common/Input.cs | 2 +- src/XIVLauncher.Core/Components/FtsPage.cs | 8 +-- .../Components/LoadingPage/LoadingPage.cs | 16 ++--- .../Components/MainPage/AccountSwitcher.cs | 4 +- .../Components/MainPage/ActionButtons.cs | 2 +- .../Components/MainPage/LoginFrame.cs | 14 ++--- .../Components/MainPage/MainPage.cs | 4 +- .../Components/MainPage/NewsFrame.cs | 8 +-- .../Components/OtpEntryPage.cs | 8 +-- .../Components/SettingsPage/SettingsPage.cs | 16 ++--- .../Components/SettingsPage/SettingsTab.cs | 2 +- .../SettingsPage/Tabs/SettingsTabAbout.cs | 4 +- .../SettingsPage/Tabs/SettingsTabWine.cs | 2 +- .../Components/SteamDeckPromptPage.cs | 2 +- .../Components/UpdateWarnPage.cs | 10 +-- src/XIVLauncher.Core/ImGuiHelpers.cs | 27 +++++++- src/XIVLauncher.Core/LauncherApp.cs | 8 +-- src/XIVLauncher.Core/Program.cs | 11 ++-- src/XIVLauncher.Core/Style/StyleModelV1.cs | 62 +++++++++---------- 22 files changed, 120 insertions(+), 98 deletions(-) diff --git a/src/XIVLauncher.Core/Components/Background.cs b/src/XIVLauncher.Core/Components/Background.cs index 0eed5b81..86b8b997 100644 --- a/src/XIVLauncher.Core/Components/Background.cs +++ b/src/XIVLauncher.Core/Components/Background.cs @@ -15,9 +15,9 @@ public Background() public override void Draw() { - ImGui.SetCursorPos(new Vector2(0, ImGuiHelpers.ViewportSize.Y - bgTexture.Height)); + ImGui.SetCursorPos(ImGuiHelpers.GetScaledVector2(new Vector2(0, ImGuiHelpers.ViewportSize.Y - bgTexture.Height))); - ImGui.Image(bgTexture.ImGuiHandle, new Vector2(bgTexture.Width, bgTexture.Height)); + ImGui.Image(bgTexture.ImGuiHandle, ImGuiHelpers.GetScaledVector2(new Vector2(bgTexture.Width, bgTexture.Height))); /* ImGui.SetCursorPos(new Vector2()); diff --git a/src/XIVLauncher.Core/Components/Common/Button.cs b/src/XIVLauncher.Core/Components/Common/Button.cs index f559d676..5b2b1f16 100644 --- a/src/XIVLauncher.Core/Components/Common/Button.cs +++ b/src/XIVLauncher.Core/Components/Common/Button.cs @@ -28,7 +28,7 @@ public Button(string label, bool isEnabled = true, Vector4? color = null, Vector public override void Draw() { - ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, new Vector2(16f, 16f)); + ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, ImGuiHelpers.GetScaledVector2(new Vector2(16f, 16f))); ImGui.PushStyleVar(ImGuiStyleVar.FrameRounding, 0); ImGui.PushStyleColor(ImGuiCol.Button, Color); ImGui.PushStyleColor(ImGuiCol.ButtonHovered, HoverColor); diff --git a/src/XIVLauncher.Core/Components/Common/Checkbox.cs b/src/XIVLauncher.Core/Components/Common/Checkbox.cs index cd171801..9028d896 100644 --- a/src/XIVLauncher.Core/Components/Common/Checkbox.cs +++ b/src/XIVLauncher.Core/Components/Common/Checkbox.cs @@ -29,7 +29,7 @@ public Checkbox(string label, bool value = false, bool isEnabled = true) public override void Draw() { - ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, new Vector2(0.5f, 0.5f)); + ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, ImGuiHelpers.GetScaledVector2(new Vector2(0.5f, 0.5f))); ImGui.PushStyleVar(ImGuiStyleVar.FrameRounding, 0); ImGui.PushStyleColor(ImGuiCol.FrameBg, ImGuiColors.BlueShade1); ImGui.PushStyleColor(ImGuiCol.FrameBgActive, ImGuiColors.BlueShade2); diff --git a/src/XIVLauncher.Core/Components/Common/Input.cs b/src/XIVLauncher.Core/Components/Common/Input.cs index 9ee1fb05..2bc3b2db 100644 --- a/src/XIVLauncher.Core/Components/Common/Input.cs +++ b/src/XIVLauncher.Core/Components/Common/Input.cs @@ -72,7 +72,7 @@ private void SteamOnOnGamepadTextInputDismissed(bool success) public override void Draw() { - ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, new Vector2(12f, 10f)); + ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, ImGuiHelpers.GetScaledVector2(new Vector2(12f, 10f))); ImGui.PushStyleVar(ImGuiStyleVar.FrameRounding, 0); ImGui.PushStyleColor(ImGuiCol.FrameBg, ImGuiColors.BlueShade1); ImGui.PushStyleColor(ImGuiCol.FrameBgActive, ImGuiColors.BlueShade2); diff --git a/src/XIVLauncher.Core/Components/FtsPage.cs b/src/XIVLauncher.Core/Components/FtsPage.cs index fbc6ad42..368385f1 100644 --- a/src/XIVLauncher.Core/Components/FtsPage.cs +++ b/src/XIVLauncher.Core/Components/FtsPage.cs @@ -64,9 +64,9 @@ public override void Draw() ImGui.PushStyleColor(ImGuiCol.ButtonHovered, Vector4.Zero); ImGui.PushStyleColor(ImGuiCol.ButtonActive, Vector4.Zero); - ImGui.SetCursorPos(new Vector2(316, 481)); + ImGui.SetCursorPos(ImGuiHelpers.GetScaledVector2(new Vector2(316, 481))); - if (ImGui.Button("###openGuideButton", new Vector2(649, 101))) + if (ImGui.Button("###openGuideButton", ImGuiHelpers.GetScaledVector2(new Vector2(649, 101)))) { if (!this.isSteamDeckAppIdError) { @@ -78,9 +78,9 @@ public override void Draw() } } - ImGui.SetCursorPos(new Vector2(316, 598)); + ImGui.SetCursorPos(ImGuiHelpers.GetScaledVector2(new Vector2(316, 598))); - if (ImGui.Button("###finishFtsButton", new Vector2(649, 101)) && !this.isSteamDeckAppIdError) + if (ImGui.Button("###finishFtsButton", ImGuiHelpers.GetScaledVector2(new Vector2(649, 101))) && !this.isSteamDeckAppIdError) { this.FinishFts(true); } diff --git a/src/XIVLauncher.Core/Components/LoadingPage/LoadingPage.cs b/src/XIVLauncher.Core/Components/LoadingPage/LoadingPage.cs index 3431bd00..4bdab083 100644 --- a/src/XIVLauncher.Core/Components/LoadingPage/LoadingPage.cs +++ b/src/XIVLauncher.Core/Components/LoadingPage/LoadingPage.cs @@ -8,7 +8,7 @@ namespace XIVLauncher.Core.Components.LoadingPage; public class LoadingPage : Page { - private const int SPINNER_RADIUS = 15; + private int SPINNER_RADIUS = ImGuiHelpers.GetScaledInt(15); public bool IsIndeterminate { get; set; } public bool CanCancel { get; set; } = true; @@ -32,7 +32,7 @@ public class LoadingPage : Page public LoadingPage(LauncherApp app) : base(app) { - this.spinner = new Spinner(SPINNER_RADIUS, 5, ImGui.GetColorU32(ImGuiCol.ButtonActive)); + this.spinner = new Spinner(SPINNER_RADIUS, ImGuiHelpers.GetScaledInt(5), ImGui.GetColorU32(ImGuiCol.ButtonActive)); this.cancelButton.Click += () => this.Cancelled?.Invoke(); this.disableAutoLoginButton.Click += () => @@ -51,20 +51,20 @@ public override void Draw() { var vp = ImGuiHelpers.ViewportSize; - ImGui.SetCursorPosY(vp.Y / 2 - 100); + ImGui.SetCursorPosY(vp.Y / 2 - ImGuiHelpers.GetScaled(100)); // center text in window ImGuiHelpers.CenteredText(Line1); if (!string.IsNullOrEmpty(Line2)) { - ImGui.Dummy(new Vector2(2)); + ImGui.Dummy(ImGuiHelpers.GetScaledVector2(new Vector2(2))); ImGuiHelpers.CenteredText(Line2); } if (!string.IsNullOrEmpty(Line3)) { - ImGui.Dummy(new Vector2(2)); + ImGui.Dummy(ImGuiHelpers.GetScaledVector2(new Vector2(2))); ImGuiHelpers.CenteredText(Line3); } @@ -72,7 +72,7 @@ public override void Draw() if (CanCancel || isDrawDisableAutoLogin) { - ImGui.Dummy(new Vector2(20)); + ImGui.Dummy(ImGuiHelpers.GetScaledVector2(new Vector2(20)));; } if (CanCancel) @@ -93,7 +93,7 @@ public override void Draw() ImGuiHelpers.CenteredText("Auto login disabled on next start!"); } - ImGui.Dummy(new Vector2(20)); + ImGui.Dummy(ImGuiHelpers.GetScaledVector2(new Vector2(20))); if (IsIndeterminate) { @@ -104,7 +104,7 @@ public override void Draw() { var width = vp.X / 3; ImGuiHelpers.CenterCursorFor((int)width); - ImGui.ProgressBar(Progress, new Vector2(width, 20), ProgressText); + ImGui.ProgressBar(Progress, new Vector2(width, ImGuiHelpers.GetScaled(20)), ProgressText); } Program.Invalidate(10); diff --git a/src/XIVLauncher.Core/Components/MainPage/AccountSwitcher.cs b/src/XIVLauncher.Core/Components/MainPage/AccountSwitcher.cs index c019bc92..8700a6a5 100644 --- a/src/XIVLauncher.Core/Components/MainPage/AccountSwitcher.cs +++ b/src/XIVLauncher.Core/Components/MainPage/AccountSwitcher.cs @@ -28,7 +28,7 @@ public void Open() public override void Draw() { - ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(5)); + ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, ImGuiHelpers.GetScaledVector2(new Vector2(5))); if (ImGui.BeginPopupContextItem(ACCOUNT_SWITCHER_POPUP_ID)) { @@ -49,7 +49,7 @@ public override void Draw() var textLength = ImGui.CalcTextSize(name).X; - if (ImGui.Button(name + $"###{account.Id}", new Vector2(textLength + 15, 40))) + if (ImGui.Button(name + $"###{account.Id}", new Vector2(textLength + ImGuiHelpers.GetScaled(15), ImGuiHelpers.GetScaled(40)))) { this.AccountChanged?.Invoke(this, account); } diff --git a/src/XIVLauncher.Core/Components/MainPage/ActionButtons.cs b/src/XIVLauncher.Core/Components/MainPage/ActionButtons.cs index 521cb3ee..db59dee1 100644 --- a/src/XIVLauncher.Core/Components/MainPage/ActionButtons.cs +++ b/src/XIVLauncher.Core/Components/MainPage/ActionButtons.cs @@ -12,7 +12,7 @@ public class ActionButtons : Component public override void Draw() { - var btnSize = new Vector2(80) * ImGuiHelpers.GlobalScale; + var btnSize = ImGuiHelpers.GetScaledVector2(new Vector2(80)); ImGui.PushFont(FontManager.IconFont); diff --git a/src/XIVLauncher.Core/Components/MainPage/LoginFrame.cs b/src/XIVLauncher.Core/Components/MainPage/LoginFrame.cs index 795b3868..1d306e4a 100644 --- a/src/XIVLauncher.Core/Components/MainPage/LoginFrame.cs +++ b/src/XIVLauncher.Core/Components/MainPage/LoginFrame.cs @@ -61,13 +61,13 @@ void TriggerLogin() this.OnLogin?.Invoke(LoginAction.Game); } - this.loginInput = new Input("Username", "Enter your Username", new Vector2(12f, 0f), 128) + this.loginInput = new Input("Username", "Enter your Username", ImGuiHelpers.GetScaledVector2(new Vector2(12f, 0f)), 128) { TakeKeyboardFocus = true }; this.loginInput.Enter += TriggerLogin; - this.passwordInput = new Input("Password", "Enter your password", new Vector2(12f, 0f), 128, flags: ImGuiInputTextFlags.Password | ImGuiInputTextFlags.NoUndoRedo); + this.passwordInput = new Input("Password", "Enter your password", ImGuiHelpers.GetScaledVector2(new Vector2(12f, 0f)), 128, flags: ImGuiInputTextFlags.Password | ImGuiInputTextFlags.NoUndoRedo); this.passwordInput.Enter += TriggerLogin; this.oneTimePasswordCheckbox = new Checkbox("Use one-time password"); @@ -83,14 +83,14 @@ void TriggerLogin() private Vector2 GetSize() { var vp = ImGuiHelpers.ViewportSize; - return new Vector2(-1, vp.Y - 128f); + return new Vector2(ImGuiHelpers.GetScaled(-1), vp.Y - ImGuiHelpers.GetScaled(128f)); } public override void Draw() { if (ImGui.BeginChild("###loginFrame", this.GetSize())) { - ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(32f, 32f)); + ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, ImGuiHelpers.GetScaledVector2(new Vector2(32f, 32f))); this.loginInput.Draw(); this.passwordInput.Draw(); @@ -98,7 +98,7 @@ public override void Draw() this.useSteamServiceCheckbox.Draw(); this.autoLoginCheckbox.Draw(); - ImGui.Dummy(new Vector2(10)); + ImGui.Dummy(ImGuiHelpers.GetScaledVector2(new Vector2(10))); this.loginButton.Draw(); @@ -159,12 +159,12 @@ public override void Draw() ImGui.TextWrapped("Take care! No secrets provider is installed or configured. Passwords can't be saved."); ImGui.PopStyleColor(); - ImGui.Dummy(new Vector2(15)); + ImGui.Dummy(ImGuiHelpers.GetScaledVector2(new Vector2(15))); } ImGui.PushFont(FontManager.IconFont); - var extraButtonSize = new Vector2(45) * ImGuiHelpers.GlobalScale; + var extraButtonSize = ImGuiHelpers.GetScaledVector2(new Vector2(45)); if (ImGui.Button(FontAwesomeIcon.CaretDown.ToIconString(), extraButtonSize)) { diff --git a/src/XIVLauncher.Core/Components/MainPage/MainPage.cs b/src/XIVLauncher.Core/Components/MainPage/MainPage.cs index 09289f54..f9c5ac87 100644 --- a/src/XIVLauncher.Core/Components/MainPage/MainPage.cs +++ b/src/XIVLauncher.Core/Components/MainPage/MainPage.cs @@ -49,7 +49,7 @@ public MainPage(LauncherApp app) this.actionButtons.OnSettingsButtonClicked += () => this.App.State = LauncherApp.LauncherState.Settings; this.actionButtons.OnStatusButtonClicked += () => AppUtil.OpenBrowser("https://is.xivup.com/"); - this.Padding = new Vector2(32f, 32f); + this.Padding = ImGuiHelpers.GetScaledVector2(new Vector2(32f, 32f)); var savedAccount = App.Accounts.CurrentAccount; @@ -75,7 +75,7 @@ public override void Draw() { base.Draw(); - ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(32f, 32f)); + ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, ImGuiHelpers.GetScaledVector2(new Vector2(32f, 32f))); this.newsFrame.Draw(); ImGui.SameLine(); diff --git a/src/XIVLauncher.Core/Components/MainPage/NewsFrame.cs b/src/XIVLauncher.Core/Components/MainPage/NewsFrame.cs index 49626e10..0e0fa6aa 100644 --- a/src/XIVLauncher.Core/Components/MainPage/NewsFrame.cs +++ b/src/XIVLauncher.Core/Components/MainPage/NewsFrame.cs @@ -72,15 +72,15 @@ public void ReloadNews() private Vector2 GetSize() { var vp = ImGuiHelpers.ViewportSize; - var calculatedSize = vp.X >= 1280 ? vp.X * 0.7f : vp.X * 0.5f; - return new Vector2(calculatedSize, vp.Y - 128f); + var calculatedSize = vp.X >= ImGuiHelpers.GetScaled(1280) ? vp.X * 0.7f : vp.X * 0.5f; + return new Vector2(calculatedSize, vp.Y - ImGuiHelpers.GetScaled(128f)); } public override void Draw() { if (ImGui.BeginChild("###newsFrame", this.GetSize())) { - ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(32f, 32f)); + ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, ImGuiHelpers.GetScaledVector2(new Vector2(32f, 32f))); if (this.newsLoaded) { @@ -90,7 +90,7 @@ public override void Draw() if (ImGui.IsItemClicked(ImGuiMouseButton.Left)) AppUtil.OpenBrowser(this.bannerList[this.currentBanner].Link.ToString()); - ImGui.Dummy(new Vector2(15)); + ImGui.Dummy(ImGuiHelpers.GetScaledVector2(new Vector2(15))); void ShowNewsEntry(News newsEntry) { diff --git a/src/XIVLauncher.Core/Components/OtpEntryPage.cs b/src/XIVLauncher.Core/Components/OtpEntryPage.cs index a5590286..213fc29a 100644 --- a/src/XIVLauncher.Core/Components/OtpEntryPage.cs +++ b/src/XIVLauncher.Core/Components/OtpEntryPage.cs @@ -82,7 +82,7 @@ public override void Draw() { ImGui.PushStyleVar(ImGuiStyleVar.ChildRounding, 7f); - var childSize = new Vector2(300, 200); + var childSize = ImGuiHelpers.GetScaledVector2(new Vector2(300, 200)); var vpSize = ImGuiHelpers.ViewportSize; ImGui.SetNextWindowPos(new Vector2(vpSize.X / 2 - childSize.X / 2, vpSize.Y / 2 - childSize.Y / 2), ImGuiCond.Always); @@ -90,12 +90,12 @@ public override void Draw() if (ImGui.BeginChild("###otp", childSize, true, ImGuiWindowFlags.AlwaysAutoResize)) { - ImGui.Dummy(new Vector2(40)); + ImGui.Dummy(ImGuiHelpers.GetScaledVector2(new Vector2(40))); // center text in window ImGuiHelpers.CenteredText("Please enter your OTP"); - const int INPUT_WIDTH = 150; + int INPUT_WIDTH = ImGuiHelpers.GetScaledInt(150); ImGui.SetNextItemWidth(INPUT_WIDTH); ImGuiHelpers.CenterCursorFor(INPUT_WIDTH); @@ -107,7 +107,7 @@ public override void Draw() var doEnter = ImGui.InputText("###otpInput", ref this.otp, 6, ImGuiInputTextFlags.CharsDecimal | ImGuiInputTextFlags.EnterReturnsTrue); - var buttonSize = new Vector2(INPUT_WIDTH / 2 - 4, 30); + var buttonSize = new Vector2(INPUT_WIDTH / 2 - ImGuiHelpers.GetScaled(4), ImGuiHelpers.GetScaled(30)); ImGuiHelpers.CenterCursorFor(INPUT_WIDTH); if (ImGui.Button("OK", buttonSize) || doEnter) diff --git a/src/XIVLauncher.Core/Components/SettingsPage/SettingsPage.cs b/src/XIVLauncher.Core/Components/SettingsPage/SettingsPage.cs index a5d48661..8e8a5ef7 100644 --- a/src/XIVLauncher.Core/Components/SettingsPage/SettingsPage.cs +++ b/src/XIVLauncher.Core/Components/SettingsPage/SettingsPage.cs @@ -85,7 +85,7 @@ public override void Draw() if (ImGui.BeginChild("SearchResults")) { ImGui.TextColored(ImGuiColors.DalamudGrey, settingsTab.Title); - ImGui.Dummy(new Vector2(5)); + ImGui.Dummy(ImGuiHelpers.GetScaledVector2(new Vector2(5))); foreach (SettingsEntry settingsTabEntry in eligible) { @@ -97,7 +97,7 @@ public override void Draw() ImGui.Separator(); - ImGui.Dummy(new Vector2(10)); + ImGui.Dummy(ImGuiHelpers.GetScaledVector2(new Vector2(10))); } ImGui.EndChild(); } @@ -110,11 +110,11 @@ public override void Draw() } } - ImGui.SetCursorPos(ImGuiHelpers.ViewportSize - new Vector2(60)); + ImGui.SetCursorPos(ImGuiHelpers.ViewportSize - ImGuiHelpers.GetScaledVector2(new Vector2(60))); if (ImGui.BeginChild("###settingsFinishButton")) { - ImGui.PushStyleVar(ImGuiStyleVar.FrameRounding, 100f); + ImGui.PushStyleVar(ImGuiStyleVar.FrameRounding, ImGuiHelpers.GetScaled(100f)); ImGui.PushFont(FontManager.IconFont); var invalid = this.tabs.Any(x => x.Entries.Any(y => y.IsVisible && !y.IsValid)); @@ -122,13 +122,13 @@ public override void Draw() { ImGui.BeginDisabled(); ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudRed); - ImGui.Button(FontAwesomeIcon.Ban.ToIconString(), new Vector2(40)); + ImGui.Button(FontAwesomeIcon.Ban.ToIconString(), ImGuiHelpers.GetScaledVector2(new Vector2(40))); ImGui.PopStyleColor(); ImGui.EndDisabled(); } else { - if (ImGui.Button(FontAwesomeIcon.Check.ToIconString(), new Vector2(40))) + if (ImGui.Button(FontAwesomeIcon.Check.ToIconString(), ImGuiHelpers.GetScaledVector2(new Vector2(40)))) { foreach (var settingsTab in this.tabs) { @@ -146,8 +146,8 @@ public override void Draw() ImGui.PopFont(); var vpSize = ImGuiHelpers.ViewportSize; - ImGui.SetCursorPos(new Vector2(vpSize.X - 260, 4)); - ImGui.SetNextItemWidth(250); + ImGui.SetCursorPos(new Vector2(vpSize.X - ImGuiHelpers.GetScaled(260), ImGuiHelpers.GetScaled(4))); + ImGui.SetNextItemWidth(ImGuiHelpers.GetScaled(250)); ImGui.InputTextWithHint("###searchInput", "Search for settings...", ref this.searchInput, 100); base.Draw(); diff --git a/src/XIVLauncher.Core/Components/SettingsPage/SettingsTab.cs b/src/XIVLauncher.Core/Components/SettingsPage/SettingsTab.cs index 5ec75444..a9efa317 100644 --- a/src/XIVLauncher.Core/Components/SettingsPage/SettingsTab.cs +++ b/src/XIVLauncher.Core/Components/SettingsPage/SettingsTab.cs @@ -19,7 +19,7 @@ public override void Draw() if (settingsEntry.IsVisible) settingsEntry.Draw(); - ImGui.Dummy(new Vector2(10) * ImGuiHelpers.GlobalScale); + ImGui.Dummy(ImGuiHelpers.GetScaledVector2(new Vector2(10))); } base.Draw(); diff --git a/src/XIVLauncher.Core/Components/SettingsPage/Tabs/SettingsTabAbout.cs b/src/XIVLauncher.Core/Components/SettingsPage/Tabs/SettingsTabAbout.cs index cd4350a9..9b6fc826 100644 --- a/src/XIVLauncher.Core/Components/SettingsPage/Tabs/SettingsTabAbout.cs +++ b/src/XIVLauncher.Core/Components/SettingsPage/Tabs/SettingsTabAbout.cs @@ -21,7 +21,7 @@ public SettingsTabAbout() public override void Draw() { - ImGui.Image(this.logoTexture.ImGuiHandle, new Vector2(256) * ImGuiHelpers.GlobalScale); + ImGui.Image(this.logoTexture.ImGuiHandle, ImGuiHelpers.GetScaledVector2(new Vector2(256))); ImGui.Text($"XIVLauncher Core v{AppUtil.GetAssemblyVersion()}({AppUtil.GetGitHash()})"); ImGui.Text("By goaaats"); @@ -29,7 +29,7 @@ public override void Draw() if (ImGui.IsItemClicked(ImGuiMouseButton.Left)) AppUtil.OpenBrowser("https://github.com/goaaats"); - ImGui.Dummy(new Vector2(20)); + ImGui.Dummy(ImGuiHelpers.GetScaledVector2(new Vector2(20))); if (ImGui.Button("Open Repository")) { diff --git a/src/XIVLauncher.Core/Components/SettingsPage/Tabs/SettingsTabWine.cs b/src/XIVLauncher.Core/Components/SettingsPage/Tabs/SettingsTabWine.cs index b9a95b1b..be86941e 100644 --- a/src/XIVLauncher.Core/Components/SettingsPage/Tabs/SettingsTabWine.cs +++ b/src/XIVLauncher.Core/Components/SettingsPage/Tabs/SettingsTabWine.cs @@ -75,7 +75,7 @@ public override void Draw() ImGui.BeginDisabled(); ImGui.Text("Compatibility tool isn't set up. Please start the game at least once."); - ImGui.Dummy(new Vector2(10)); + ImGui.Dummy(ImGuiHelpers.GetScaledVector2(new Vector2(10))); } if (ImGui.Button("Open prefix")) diff --git a/src/XIVLauncher.Core/Components/SteamDeckPromptPage.cs b/src/XIVLauncher.Core/Components/SteamDeckPromptPage.cs index 0dc299b6..f3b47ba2 100644 --- a/src/XIVLauncher.Core/Components/SteamDeckPromptPage.cs +++ b/src/XIVLauncher.Core/Components/SteamDeckPromptPage.cs @@ -18,7 +18,7 @@ public override void Draw() { ImGui.SetCursorPos(new Vector2(0)); - ImGui.Image(this.updateWarnTexture.ImGuiHandle, new Vector2(1280, 800)); + ImGui.Image(this.updateWarnTexture.ImGuiHandle, ImGuiHelpers.GetScaledVector2(new Vector2(1280, 800))); base.Draw(); } diff --git a/src/XIVLauncher.Core/Components/UpdateWarnPage.cs b/src/XIVLauncher.Core/Components/UpdateWarnPage.cs index 62303df8..68ba5590 100644 --- a/src/XIVLauncher.Core/Components/UpdateWarnPage.cs +++ b/src/XIVLauncher.Core/Components/UpdateWarnPage.cs @@ -18,22 +18,22 @@ public override void Draw() { ImGui.SetCursorPos(new Vector2(0)); - ImGui.Image(this.updateWarnTexture.ImGuiHandle, new Vector2(1280, 800)); + ImGui.Image(this.updateWarnTexture.ImGuiHandle, ImGuiHelpers.GetScaledVector2(new Vector2(1280, 800))); ImGui.PushStyleColor(ImGuiCol.Button, Vector4.Zero); ImGui.PushStyleColor(ImGuiCol.ButtonHovered, Vector4.Zero); ImGui.PushStyleColor(ImGuiCol.ButtonActive, Vector4.Zero); - ImGui.SetCursorPos(new Vector2(316, 481)); + ImGui.SetCursorPos(ImGuiHelpers.GetScaledVector2(new Vector2(316, 481))); - if (ImGui.Button("###openGuideButton", new Vector2(649, 101))) + if (ImGui.Button("###openGuideButton", ImGuiHelpers.GetScaledVector2(new Vector2(649, 101)))) { Environment.Exit(0); } - ImGui.SetCursorPos(new Vector2(316, 598)); + ImGui.SetCursorPos(ImGuiHelpers.GetScaledVector2(new Vector2(316, 598))); - if (ImGui.Button("###finishFtsButton", new Vector2(649, 101))) + if (ImGui.Button("###finishFtsButton", ImGuiHelpers.GetScaledVector2(new Vector2(649, 101)))) { App.FinishFromUpdateWarn(); } diff --git a/src/XIVLauncher.Core/ImGuiHelpers.cs b/src/XIVLauncher.Core/ImGuiHelpers.cs index a9c69400..174ca500 100644 --- a/src/XIVLauncher.Core/ImGuiHelpers.cs +++ b/src/XIVLauncher.Core/ImGuiHelpers.cs @@ -8,7 +8,32 @@ public static class ImGuiHelpers { public static Vector2 ViewportSize => ImGui.GetIO().DisplaySize; - public static float GlobalScale => ImGui.GetIO().FontGlobalScale; + public static float GlobalScale {get; set; } = 1.0f; + + public static float GetScaled(int size) + { + return GlobalScale * (float)size; + } + + public static float GetScaled(float size) + { + return GlobalScale * size; + } + + public static int GetScaledInt(int size) + { + return (int)(GlobalScale * (float)size); + } + + public static int GetScaledInt(float size) + { + return (int)(GlobalScale * size); + } + + public static Vector2 GetScaledVector2(Vector2 size) + { + return size * GlobalScale; + } public static void TextWrapped(string text) { diff --git a/src/XIVLauncher.Core/LauncherApp.cs b/src/XIVLauncher.Core/LauncherApp.cs index 31d98423..185c61a3 100644 --- a/src/XIVLauncher.Core/LauncherApp.cs +++ b/src/XIVLauncher.Core/LauncherApp.cs @@ -318,21 +318,21 @@ public override void Draw() private void DrawModal() { - ImGui.SetNextWindowSize(new Vector2(450, 300)); + ImGui.SetNextWindowSize(ImGuiHelpers.GetScaledVector2(new Vector2(450, 300))); if (ImGui.BeginPopupModal(this.modalTitle + "###xl_modal", ref this.isModalDrawing, ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoTitleBar)) { - if (ImGui.BeginChild("###xl_modal_scrolling", new Vector2(0, -ImGui.GetTextLineHeightWithSpacing() * 2))) + if (ImGui.BeginChild("###xl_modal_scrolling", ImGuiHelpers.GetScaledVector2(new Vector2(0, -ImGui.GetTextLineHeightWithSpacing() * 2)))) { ImGui.TextWrapped(this.modalText); } ImGui.EndChild(); - const float BUTTON_WIDTH = 120f; + float BUTTON_WIDTH = ImGuiHelpers.GetScaled(120f); ImGui.SetCursorPosX((ImGui.GetWindowWidth() - BUTTON_WIDTH) / 2); - if (ImGui.Button(modalButtonText, new Vector2(BUTTON_WIDTH, 40))) + if (ImGui.Button(modalButtonText, new Vector2(BUTTON_WIDTH, ImGuiHelpers.GetScaled(40)))) { modalButtonPressAction(); } diff --git a/src/XIVLauncher.Core/Program.cs b/src/XIVLauncher.Core/Program.cs index 821a26b6..ac47fbd5 100644 --- a/src/XIVLauncher.Core/Program.cs +++ b/src/XIVLauncher.Core/Program.cs @@ -262,16 +262,14 @@ private static void Main(string[] args) // Create window, GraphicsDevice, and all resources necessary for the demo. Sdl2Native.SDL_Init(SDLInitFlags.Video); - float dpiScale = 1f; - if (Environment.GetEnvironmentVariable("XDG_SESSION_TYPE") == "wayland" && SdlHelpers.GetCurrentVideoDriver() == "x11") { - dpiScale = SdlHelpers.GetDisplayDpiScale().Y; + ImGuiHelpers.GlobalScale = SdlHelpers.GetDisplayDpiScale().Y; } - var windowWidth = (int) Math.Round(1280 * dpiScale); - var windowHeight = (int) Math.Round(800 * dpiScale); + var windowWidth = ImGuiHelpers.GetScaledInt(1280); + var windowHeight = ImGuiHelpers.GetScaledInt(800); VeldridStartup.CreateWindowAndGraphicsDevice( new WindowCreateInfo(50, 50, windowWidth, windowHeight, WindowState.Normal, $"XIVLauncher {version}"), @@ -288,11 +286,10 @@ private static void Main(string[] args) cl = gd.ResourceFactory.CreateCommandList(); Log.Debug("Veldrid OK!"); - bindings = new ImGuiBindings(gd, gd.MainSwapchain.Framebuffer.OutputDescription, window.Width, window.Height, storage.GetFile("launcherUI.ini"), (Config.FontPxSize ?? 21.0f) * dpiScale); + bindings = new ImGuiBindings(gd, gd.MainSwapchain.Framebuffer.OutputDescription, window.Width, window.Height, storage.GetFile("launcherUI.ini"), ImGuiHelpers.GetScaled(Config.FontPxSize ?? 21.0f)); Log.Debug("ImGui OK!"); StyleModelV1.DalamudStandard.Apply(); - ImGui.GetIO().FontGlobalScale = Config.GlobalScale ?? 1.0f; var needUpdate = false; diff --git a/src/XIVLauncher.Core/Style/StyleModelV1.cs b/src/XIVLauncher.Core/Style/StyleModelV1.cs index 7f7f417b..df9faa7c 100644 --- a/src/XIVLauncher.Core/Style/StyleModelV1.cs +++ b/src/XIVLauncher.Core/Style/StyleModelV1.cs @@ -28,34 +28,34 @@ private StyleModelV1() Name = "Dalamud Standard", Alpha = 1, - WindowPadding = new Vector2(8, 8), - WindowRounding = 4, + WindowPadding = ImGuiHelpers.GetScaledVector2(new Vector2(8, 8)), + WindowRounding = ImGuiHelpers.GetScaled(4), WindowBorderSize = 0, WindowTitleAlign = new Vector2(0, 0.5f), WindowMenuButtonPosition = ImGuiDir.Right, ChildRounding = 0, - ChildBorderSize = 1, + ChildBorderSize = ImGuiHelpers.GetScaled(1), PopupRounding = 0, PopupBorderSize = 0, - FramePadding = new Vector2(4, 3), + FramePadding = ImGuiHelpers.GetScaledVector2(new Vector2(4, 3)), //FrameRounding = 4, FrameRounding = 0, FrameBorderSize = 0, - ItemSpacing = new Vector2(8, 4), - ItemInnerSpacing = new Vector2(4, 4), - CellPadding = new Vector2(4, 2), + ItemSpacing = ImGuiHelpers.GetScaledVector2(new Vector2(8, 4)), + ItemInnerSpacing = new Vector2(4, 4) * ImGuiHelpers.GlobalScale, + CellPadding = ImGuiHelpers.GetScaledVector2(new Vector2(4, 2)), TouchExtraPadding = new Vector2(0, 0), - IndentSpacing = 21, - ScrollbarSize = 16, - ScrollbarRounding = 9, - GrabMinSize = 13, - GrabRounding = 3, - LogSliderDeadzone = 4, - TabRounding = 1, + IndentSpacing = ImGuiHelpers.GetScaled(21), + ScrollbarSize = ImGuiHelpers.GetScaled(16), + ScrollbarRounding = ImGuiHelpers.GetScaled(9), + GrabMinSize = ImGuiHelpers.GetScaled(13), + GrabRounding = ImGuiHelpers.GetScaled(3), + LogSliderDeadzone = ImGuiHelpers.GetScaled(4), + TabRounding = ImGuiHelpers.GetScaled(1), TabBorderSize = 0, ButtonTextAlign = new Vector2(0.5f, 0.5f), SelectableTextAlign = new Vector2(0, 0), - DisplaySafeAreaPadding = new Vector2(3, 3), + DisplaySafeAreaPadding = ImGuiHelpers.GetScaledVector2(new Vector2(3, 3)), Colors = new Dictionary { @@ -125,33 +125,33 @@ private StyleModelV1() Name = "Dalamud Classic", Alpha = 1, - WindowPadding = new Vector2(8, 8), - WindowRounding = 4, + WindowPadding = ImGuiHelpers.GetScaledVector2(new Vector2(8, 8)), + WindowRounding = ImGuiHelpers.GetScaled(4), WindowBorderSize = 0, WindowTitleAlign = new Vector2(0, 0.5f), WindowMenuButtonPosition = ImGuiDir.Right, ChildRounding = 0, - ChildBorderSize = 1, + ChildBorderSize = ImGuiHelpers.GetScaled(1), PopupRounding = 0, PopupBorderSize = 0, - FramePadding = new Vector2(4, 3), - FrameRounding = 4, + FramePadding = ImGuiHelpers.GetScaledVector2(new Vector2(4, 3)), + FrameRounding = ImGuiHelpers.GetScaled(4), FrameBorderSize = 0, - ItemSpacing = new Vector2(8, 4), - ItemInnerSpacing = new Vector2(4, 4), - CellPadding = new Vector2(4, 2), + ItemSpacing = ImGuiHelpers.GetScaledVector2(new Vector2(8, 4)), + ItemInnerSpacing = ImGuiHelpers.GetScaledVector2(new Vector2(4, 4)), + CellPadding = ImGuiHelpers.GetScaledVector2(new Vector2(4, 2)), TouchExtraPadding = new Vector2(0, 0), - IndentSpacing = 21, - ScrollbarSize = 16, - ScrollbarRounding = 9, - GrabMinSize = 10, - GrabRounding = 3, - LogSliderDeadzone = 4, - TabRounding = 4, + IndentSpacing = ImGuiHelpers.GetScaled(21), + ScrollbarSize = ImGuiHelpers.GetScaled(16), + ScrollbarRounding = ImGuiHelpers.GetScaled(9), + GrabMinSize = ImGuiHelpers.GetScaled(10), + GrabRounding = ImGuiHelpers.GetScaled(3), + LogSliderDeadzone = ImGuiHelpers.GetScaled(4), + TabRounding = ImGuiHelpers.GetScaled(4), TabBorderSize = 0, ButtonTextAlign = new Vector2(0.5f, 0.5f), SelectableTextAlign = new Vector2(0, 0), - DisplaySafeAreaPadding = new Vector2(3, 3), + DisplaySafeAreaPadding = ImGuiHelpers.GetScaledVector2(new Vector2(3, 3)), Colors = new Dictionary {