diff --git a/src/XIVLauncher.Core/Components/Background.cs b/src/XIVLauncher.Core/Components/Background.cs index 0eed5b81..22f92f27 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.GetScaled(new Vector2(0, ImGuiHelpers.ViewportSize.Y - bgTexture.Height))); - ImGui.Image(bgTexture.ImGuiHandle, new Vector2(bgTexture.Width, bgTexture.Height)); + ImGui.Image(bgTexture.ImGuiHandle, ImGuiHelpers.GetScaled(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..fa7565ea 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.GetScaled(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..7493f355 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.GetScaled(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..32055804 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.GetScaled(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..94ba52f1 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.GetScaled(new Vector2(316, 481))); - if (ImGui.Button("###openGuideButton", new Vector2(649, 101))) + if (ImGui.Button("###openGuideButton", ImGuiHelpers.GetScaled(new Vector2(649, 101)))) { if (!this.isSteamDeckAppIdError) { @@ -78,9 +78,9 @@ public override void Draw() } } - ImGui.SetCursorPos(new Vector2(316, 598)); + ImGui.SetCursorPos(ImGuiHelpers.GetScaled(new Vector2(316, 598))); - if (ImGui.Button("###finishFtsButton", new Vector2(649, 101)) && !this.isSteamDeckAppIdError) + if (ImGui.Button("###finishFtsButton", ImGuiHelpers.GetScaled(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..dbada57f 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 = (int)ImGuiHelpers.GetScaled(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, (int)ImGuiHelpers.GetScaled(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.GetScaled(new Vector2(2))); ImGuiHelpers.CenteredText(Line2); } if (!string.IsNullOrEmpty(Line3)) { - ImGui.Dummy(new Vector2(2)); + ImGui.Dummy(ImGuiHelpers.GetScaled(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.GetScaled(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.GetScaled(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..36c81561 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.GetScaled(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..c9ed51a9 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.GetScaled(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..fb996cf1 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.GetScaled(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.GetScaled(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.GetScaled(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.GetScaled(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.GetScaled(new Vector2(15))); } ImGui.PushFont(FontManager.IconFont); - var extraButtonSize = new Vector2(45) * ImGuiHelpers.GlobalScale; + var extraButtonSize = ImGuiHelpers.GetScaled(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..56e66bc5 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.GetScaled(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.GetScaled(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..1b2deeed 100644 --- a/src/XIVLauncher.Core/Components/MainPage/NewsFrame.cs +++ b/src/XIVLauncher.Core/Components/MainPage/NewsFrame.cs @@ -72,25 +72,25 @@ 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.GetScaled(new Vector2(32f, 32f))); if (this.newsLoaded) { var banner = this.banners[this.currentBanner]; - ImGui.Image(banner.ImGuiHandle, banner.Size); + ImGui.Image(banner.ImGuiHandle, ImGuiHelpers.GetScaled(banner.Size)); if (ImGui.IsItemClicked(ImGuiMouseButton.Left)) AppUtil.OpenBrowser(this.bannerList[this.currentBanner].Link.ToString()); - ImGui.Dummy(new Vector2(15)); + ImGui.Dummy(ImGuiHelpers.GetScaled(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..0cc2fc8a 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.GetScaled(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.GetScaled(new Vector2(40))); // center text in window ImGuiHelpers.CenteredText("Please enter your OTP"); - const int INPUT_WIDTH = 150; + int INPUT_WIDTH = (int)ImGuiHelpers.GetScaled(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..70bfb393 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.GetScaled(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.GetScaled(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.GetScaled(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.GetScaled(new Vector2(40))); ImGui.PopStyleColor(); ImGui.EndDisabled(); } else { - if (ImGui.Button(FontAwesomeIcon.Check.ToIconString(), new Vector2(40))) + if (ImGui.Button(FontAwesomeIcon.Check.ToIconString(), ImGuiHelpers.GetScaled(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..70291fab 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.GetScaled(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..374fa559 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.GetScaled(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.GetScaled(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..8f3a2759 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.GetScaled(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..5522923f 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.GetScaled(new Vector2(1280, 800))); base.Draw(); } diff --git a/src/XIVLauncher.Core/Components/UpdateWarnPage.cs b/src/XIVLauncher.Core/Components/UpdateWarnPage.cs index 62303df8..6de7d526 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.GetScaled(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.GetScaled(new Vector2(316, 481))); - if (ImGui.Button("###openGuideButton", new Vector2(649, 101))) + if (ImGui.Button("###openGuideButton", ImGuiHelpers.GetScaled(new Vector2(649, 101)))) { Environment.Exit(0); } - ImGui.SetCursorPos(new Vector2(316, 598)); + ImGui.SetCursorPos(ImGuiHelpers.GetScaled(new Vector2(316, 598))); - if (ImGui.Button("###finishFtsButton", new Vector2(649, 101))) + if (ImGui.Button("###finishFtsButton", ImGuiHelpers.GetScaled(new Vector2(649, 101)))) { App.FinishFromUpdateWarn(); } diff --git a/src/XIVLauncher.Core/DesktopEnvironment/DesktopHelpers.cs b/src/XIVLauncher.Core/DesktopEnvironment/DesktopHelpers.cs new file mode 100644 index 00000000..9b26d53d --- /dev/null +++ b/src/XIVLauncher.Core/DesktopEnvironment/DesktopHelpers.cs @@ -0,0 +1,200 @@ +using System.Diagnostics; +using System.Text.Json; +using System.Text.RegularExpressions; + +using Serilog; + +namespace XIVLauncher.Core.DesktopEnvironment; + +public partial class DesktopHelpers +{ + [GeneratedRegex(@"^uint32\s+([0-9\.]+)$")] + private static partial Regex GSettingsRegex(); + + [GeneratedRegex(@"^Xft\.dpi:\s+([0-9]+)$")] + private static partial Regex XrdbRegex(); + + + public static float GetDesktopScaleFactor() + { + if (Environment.GetEnvironmentVariable("XDG_SESSION_TYPE") == "wayland" + && SdlHelpers.GetCurrentVideoDriver() == "x11") + { + return GetXWaylandScaleFactor(); + } + + return 1f; + } + + private static float GetXWaylandScaleFactor() + { + float? scaleFactor; + + if (Environment.GetEnvironmentVariable("XDG_SESSION_DESKTOP") == "KDE") + { + scaleFactor = GetKScreenDoctorScaleFactor(); + + if (scaleFactor != null) + { + return (float)scaleFactor; + } + } + + scaleFactor = GetGSettingsScaleFactor(); + + if (scaleFactor != null) + { + return (float)scaleFactor; + } + + scaleFactor = GetXrdbScaleFactor(); + + if (scaleFactor != null) + { + return (float)scaleFactor; + } + + // Fallback + return 1f; + } + + private static float? GetKScreenDoctorScaleFactor() + { + try + { + Log.Verbose("KDE detected - obtaining desktop scale from kscreen-doctor"); + + using var process = Process.Start(new ProcessStartInfo + { + FileName = "kscreen-doctor", + Arguments = "-j", + UseShellExecute = false, + RedirectStandardOutput = true, + }); + + if (process == null) + { + return null; + } + + var screenData = JsonSerializer.Deserialize(process.StandardOutput.BaseStream, + new JsonSerializerOptions(JsonSerializerDefaults.Web)); + + if (screenData != null) + { + foreach (var output in screenData.Outputs) + { + if (output.Pos.X == 0 && output.Pos.Y == 0) + { + // Primary monitor + Log.Verbose("Obtained scale from kscreen-doctor: {0}", output.Scale); + return output.Scale; + } + } + } + } + catch (Exception e) + { + Log.Error(e, "Cannot obtain desktop scale from kscreen-doctor - trying other methods"); + } + + return null; + } + + private static float? GetGSettingsScaleFactor() + { + try + { + Log.Verbose("Obtaining desktop scale from gsettings"); + + using var process = Process.Start(new ProcessStartInfo + { + FileName = "gsettings", + Arguments = "get org.gnome.desktop.interface scaling-factor", + UseShellExecute = false, + RedirectStandardOutput = true, + }); + + if (process == null) + { + return null; + } + + string? line; + + while ((line = process.StandardOutput.ReadLine()) != null) + { + var match = GSettingsRegex().Match(line); + + if (match != null && match.Success) + { + return float.Parse(match.Groups[1].Value); + } + } + } + catch (Exception e) + { + Log.Error(e, "Cannot obtain desktop scale from gsettings - trying other methods"); + } + + return null; + } + + private static float? GetXrdbScaleFactor() + { + try + { + Log.Verbose("Obtaining desktop scale from xrdb"); + + using var process = Process.Start(new ProcessStartInfo + { + FileName = "xrdb", + Arguments = "-query", + UseShellExecute = false, + RedirectStandardOutput = true, + }); + + if (process == null) + { + return null; + } + + string? line; + + while ((line = process.StandardOutput.ReadLine()) != null) + { + var match = XrdbRegex().Match(line); + + if (match != null && match.Success) + { + return int.Parse(match.Groups[1].Value) / 96f; + } + } + } + catch (Exception e) + { + Log.Error(e, "Cannot obtain desktop scale from gsettings - trying other methods"); + } + + return null; + } + + // JSON data classes + + private class KScreenDoctorData + { + public List Outputs { get; set; } = new(); + } + + private class KScreenDoctorOutput + { + public float Scale { get; set; } + public Point Pos { get; set; } + } + + private struct Point + { + public int X { get; set; } + public int Y { get; set; } + } +} diff --git a/src/XIVLauncher.Core/DesktopEnvironment/SdlHelpers.cs b/src/XIVLauncher.Core/DesktopEnvironment/SdlHelpers.cs new file mode 100644 index 00000000..14fff817 --- /dev/null +++ b/src/XIVLauncher.Core/DesktopEnvironment/SdlHelpers.cs @@ -0,0 +1,54 @@ +using System.Numerics; +using System.Runtime.InteropServices; +using System.Text; +using Serilog; +using Veldrid.Sdl2; + +namespace XIVLauncher.Core.DesktopEnvironment; + +internal static unsafe partial class SdlHelpers +{ + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate byte* SDL_GetCurrentVideoDriver_t(); + private static SDL_GetCurrentVideoDriver_t s_sdl_getCurrentVideoDriver = + Sdl2Native.LoadFunction("SDL_GetCurrentVideoDriver"); + private static byte* SDL_GetCurrentVideoDriver() => s_sdl_getCurrentVideoDriver(); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate int SDL_GetDisplayDPI_t(int displayIndex, float* ddpi, float* hdpi, float* vdpi); + private static SDL_GetDisplayDPI_t s_sdl_getDisplayDPI = + Sdl2Native.LoadFunction("SDL_GetDisplayDPI"); + private static int SDL_GetDisplayDPI(int displayIndex, float* ddpi, float* hdpi, float* vdpi) + => s_sdl_getDisplayDPI(displayIndex, ddpi, hdpi, vdpi); + + private static unsafe string GetString(byte* stringStart) + { + int characters = 0; + while (stringStart[characters] != 0) + { + characters++; + } + + return Encoding.UTF8.GetString(stringStart, characters); + } + + public static string GetCurrentVideoDriver() + { + return GetString(SDL_GetCurrentVideoDriver()); + } + + public static Vector2 GetDisplayDpiScale() + { + float ddpi, hdpi, vdpi; + + if (SDL_GetDisplayDPI(0, &ddpi, &hdpi, &vdpi) < 0) + { + Log.Warning("Cannot determine display DPI scale, defaulting to 1.0: {0}", + GetString(Sdl2Native.SDL_GetError())); + return new Vector2(1.0f, 1.0f); + } + + Log.Verbose("SDL reports {0}x{1} DPI", hdpi, vdpi); + return new Vector2(hdpi / 96, vdpi / 96); + } +} diff --git a/src/XIVLauncher.Core/ImGuiHelpers.cs b/src/XIVLauncher.Core/ImGuiHelpers.cs index a9c69400..891fb1f2 100644 --- a/src/XIVLauncher.Core/ImGuiHelpers.cs +++ b/src/XIVLauncher.Core/ImGuiHelpers.cs @@ -8,7 +8,22 @@ 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 Vector2 GetScaled(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..f64d065a 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.GetScaled(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.GetScaled(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 5aab280d..99015b02 100644 --- a/src/XIVLauncher.Core/Program.cs +++ b/src/XIVLauncher.Core/Program.cs @@ -4,8 +4,6 @@ using Config.Net; -using ImGuiNET; - using Serilog; using Veldrid; @@ -26,6 +24,7 @@ using XIVLauncher.Core.Components.LoadingPage; using XIVLauncher.Core.Configuration; using XIVLauncher.Core.Configuration.Parsers; +using XIVLauncher.Core.DesktopEnvironment; using XIVLauncher.Core.Style; namespace XIVLauncher.Core; @@ -260,8 +259,14 @@ private static void Main(string[] args) #endif // Create window, GraphicsDevice, and all resources necessary for the demo. + Sdl2Native.SDL_Init(SDLInitFlags.Video); + ImGuiHelpers.GlobalScale = DesktopHelpers.GetDesktopScaleFactor(); + + var windowWidth = (int)ImGuiHelpers.GetScaled(1280); + var windowHeight = (int)ImGuiHelpers.GetScaled(800); + VeldridStartup.CreateWindowAndGraphicsDevice( - new WindowCreateInfo(50, 50, 1280, 800, WindowState.Normal, $"XIVLauncher {version}"), + new WindowCreateInfo(50, 50, windowWidth, windowHeight, WindowState.Normal, $"XIVLauncher {version}"), new GraphicsDeviceOptions(false, null, true, ResourceBindingModel.Improved, true, true), out window, out gd); @@ -275,11 +280,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); + 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..32a48de2 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.GetScaled(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.GetScaled(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.GetScaled(new Vector2(8, 4)), + ItemInnerSpacing = ImGuiHelpers.GetScaled(new Vector2(4, 4)), + CellPadding = ImGuiHelpers.GetScaled(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.GetScaled(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.GetScaled(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.GetScaled(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.GetScaled(new Vector2(8, 4)), + ItemInnerSpacing = ImGuiHelpers.GetScaled(new Vector2(4, 4)), + CellPadding = ImGuiHelpers.GetScaled(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.GetScaled(new Vector2(3, 3)), Colors = new Dictionary {