Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix HiDPI scaling on XWayland (#88) #152

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/XIVLauncher.Core/Components/Background.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/XIVLauncher.Core/Components/Common/Button.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/XIVLauncher.Core/Components/Common/Checkbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/XIVLauncher.Core/Components/Common/Input.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/XIVLauncher.Core/Components/FtsPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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);
}
Expand Down
16 changes: 8 additions & 8 deletions src/XIVLauncher.Core/Components/LoadingPage/LoadingPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 += () =>
Expand All @@ -51,28 +51,28 @@ 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);
}

var isDrawDisableAutoLogin = CanDisableAutoLogin && (App.Settings.IsAutologin ?? false);

if (CanCancel || isDrawDisableAutoLogin)
{
ImGui.Dummy(new Vector2(20));
ImGui.Dummy(ImGuiHelpers.GetScaled(new Vector2(20)));;
}

if (CanCancel)
Expand All @@ -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)
{
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/XIVLauncher.Core/Components/MainPage/AccountSwitcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
14 changes: 7 additions & 7 deletions src/XIVLauncher.Core/Components/MainPage/LoginFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -83,22 +83,22 @@ 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();

this.oneTimePasswordCheckbox.Draw();
this.useSteamServiceCheckbox.Draw();
this.autoLoginCheckbox.Draw();

ImGui.Dummy(new Vector2(10));
ImGui.Dummy(ImGuiHelpers.GetScaled(new Vector2(10)));

this.loginButton.Draw();

Expand Down Expand Up @@ -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))
{
Expand Down
4 changes: 2 additions & 2 deletions src/XIVLauncher.Core/Components/MainPage/MainPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
Expand Down
10 changes: 5 additions & 5 deletions src/XIVLauncher.Core/Components/MainPage/NewsFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
8 changes: 4 additions & 4 deletions src/XIVLauncher.Core/Components/OtpEntryPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,20 @@ 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);
ImGui.SetNextWindowBgAlpha(0.4f);

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);

Expand All @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions src/XIVLauncher.Core/Components/SettingsPage/SettingsPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -97,7 +97,7 @@ public override void Draw()

ImGui.Separator();

ImGui.Dummy(new Vector2(10));
ImGui.Dummy(ImGuiHelpers.GetScaled(new Vector2(10)));
}
ImGui.EndChild();
}
Expand All @@ -110,25 +110,25 @@ 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));
if (invalid)
{
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)
{
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ 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");

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"))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
Loading