Skip to content

Commit

Permalink
Get rid of GetScaledInt, GetScaledVector2
Browse files Browse the repository at this point in the history
  • Loading branch information
rankynbass committed Apr 22, 2024
1 parent 933317a commit c13c4a8
Show file tree
Hide file tree
Showing 22 changed files with 62 additions and 72 deletions.
4 changes: 2 additions & 2 deletions src/XIVLauncher.Core/Components/Background.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public Background()

public override void Draw()
{
ImGui.SetCursorPos(ImGuiHelpers.GetScaledVector2(new Vector2(0, ImGuiHelpers.ViewportSize.Y - bgTexture.Height)));
ImGui.SetCursorPos(ImGuiHelpers.GetScaled(new Vector2(0, ImGuiHelpers.ViewportSize.Y - bgTexture.Height)));

ImGui.Image(bgTexture.ImGuiHandle, ImGuiHelpers.GetScaledVector2(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 @@ -27,7 +27,7 @@ public Button(string label, bool isEnabled = true, Vector4? color = null, Vector

public override void Draw()
{
ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, ImGuiHelpers.GetScaledVector2(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 @@ -28,7 +28,7 @@ public Checkbox(string label, bool value = false, bool isEnabled = true)

public override void Draw()
{
ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, ImGuiHelpers.GetScaledVector2(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 @@ -70,7 +70,7 @@ private void SteamOnOnGamepadTextInputDismissed(bool success)

public override void Draw()
{
ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, ImGuiHelpers.GetScaledVector2(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 @@ -63,9 +63,9 @@ public override void Draw()
ImGui.PushStyleColor(ImGuiCol.ButtonHovered, Vector4.Zero);
ImGui.PushStyleColor(ImGuiCol.ButtonActive, Vector4.Zero);

ImGui.SetCursorPos(ImGuiHelpers.GetScaledVector2(new Vector2(316, 481)));
ImGui.SetCursorPos(ImGuiHelpers.GetScaled(new Vector2(316, 481)));

if (ImGui.Button("###openGuideButton", ImGuiHelpers.GetScaledVector2(new Vector2(649, 101))))
if (ImGui.Button("###openGuideButton", ImGuiHelpers.GetScaled(new Vector2(649, 101))))
{
if (!this.isSteamDeckAppIdError)
{
Expand All @@ -77,9 +77,9 @@ public override void Draw()
}
}

ImGui.SetCursorPos(ImGuiHelpers.GetScaledVector2(new Vector2(316, 598)));
ImGui.SetCursorPos(ImGuiHelpers.GetScaled(new Vector2(316, 598)));

if (ImGui.Button("###finishFtsButton", ImGuiHelpers.GetScaledVector2(new Vector2(649, 101))) && !this.isSteamDeckAppIdError)
if (ImGui.Button("###finishFtsButton", ImGuiHelpers.GetScaled(new Vector2(649, 101))) && !this.isSteamDeckAppIdError)
{
this.FinishFts(true);
}
Expand Down
12 changes: 6 additions & 6 deletions src/XIVLauncher.Core/Components/LoadingPage/LoadingPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace XIVLauncher.Core.Components.LoadingPage;

public class LoadingPage : Page
{
private int SPINNER_RADIUS = ImGuiHelpers.GetScaledInt(15);
private int SPINNER_RADIUS = (int)ImGuiHelpers.GetScaled(15);

public bool IsIndeterminate { get; set; }
public bool CanCancel { get; set; } = true;
Expand All @@ -30,7 +30,7 @@ public class LoadingPage : Page
public LoadingPage(LauncherApp app)
: base(app)
{
this.spinner = new Spinner(SPINNER_RADIUS, ImGuiHelpers.GetScaledInt(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 @@ -56,21 +56,21 @@ public override void Draw()

if (!string.IsNullOrEmpty(Line2))
{
ImGui.Dummy(ImGuiHelpers.GetScaledVector2(new Vector2(2)));
ImGui.Dummy(ImGuiHelpers.GetScaled(new Vector2(2)));
ImGuiHelpers.CenteredText(Line2);
}

if (!string.IsNullOrEmpty(Line3))
{
ImGui.Dummy(ImGuiHelpers.GetScaledVector2(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(ImGuiHelpers.GetScaledVector2(new Vector2(20)));;
ImGui.Dummy(ImGuiHelpers.GetScaled(new Vector2(20)));;
}

if (CanCancel)
Expand All @@ -91,7 +91,7 @@ public override void Draw()
ImGuiHelpers.CenteredText("Auto login disabled on next start!");
}

ImGui.Dummy(ImGuiHelpers.GetScaledVector2(new Vector2(20)));
ImGui.Dummy(ImGuiHelpers.GetScaled(new Vector2(20)));

if (IsIndeterminate)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void Open()

public override void Draw()
{
ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, ImGuiHelpers.GetScaledVector2(new Vector2(5)));
ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, ImGuiHelpers.GetScaled(new Vector2(5)));

if (ImGui.BeginPopupContextItem(ACCOUNT_SWITCHER_POPUP_ID))
{
Expand Down
2 changes: 1 addition & 1 deletion src/XIVLauncher.Core/Components/MainPage/ActionButtons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ActionButtons : Component

public override void Draw()
{
var btnSize = ImGuiHelpers.GetScaledVector2(new Vector2(80));
var btnSize = ImGuiHelpers.GetScaled(new Vector2(80));

ImGui.PushFont(FontManager.IconFont);

Expand Down
12 changes: 6 additions & 6 deletions src/XIVLauncher.Core/Components/MainPage/LoginFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ void TriggerLogin()
this.OnLogin?.Invoke(LoginAction.Game);
}

this.loginInput = new Input("Username", "Enter your Username", ImGuiHelpers.GetScaledVector2(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", ImGuiHelpers.GetScaledVector2(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 @@ -88,15 +88,15 @@ public override void Draw()
{
if (ImGui.BeginChild("###loginFrame", this.GetSize()))
{
ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, ImGuiHelpers.GetScaledVector2(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(ImGuiHelpers.GetScaledVector2(new Vector2(10)));
ImGui.Dummy(ImGuiHelpers.GetScaled(new Vector2(10)));

this.loginButton.Draw();

Expand Down Expand Up @@ -157,12 +157,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(ImGuiHelpers.GetScaledVector2(new Vector2(15)));
ImGui.Dummy(ImGuiHelpers.GetScaled(new Vector2(15)));
}

ImGui.PushFont(FontManager.IconFont);

var extraButtonSize = ImGuiHelpers.GetScaledVector2(new Vector2(45));
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 @@ -45,7 +45,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 = ImGuiHelpers.GetScaledVector2(new Vector2(32f, 32f));
this.Padding = ImGuiHelpers.GetScaled(new Vector2(32f, 32f));

var savedAccount = App.Accounts.CurrentAccount;

Expand All @@ -71,7 +71,7 @@ public override void Draw()
{
base.Draw();

ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, ImGuiHelpers.GetScaledVector2(new Vector2(32f, 32f)));
ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, ImGuiHelpers.GetScaled(new Vector2(32f, 32f)));
this.newsFrame.Draw();

ImGui.SameLine();
Expand Down
4 changes: 2 additions & 2 deletions src/XIVLauncher.Core/Components/MainPage/NewsFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public override void Draw()
{
if (ImGui.BeginChild("###newsFrame", this.GetSize()))
{
ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, ImGuiHelpers.GetScaledVector2(new Vector2(32f, 32f)));
ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, ImGuiHelpers.GetScaled(new Vector2(32f, 32f)));

if (this.newsLoaded)
{
Expand All @@ -88,7 +88,7 @@ public override void Draw()
if (ImGui.IsItemClicked(ImGuiMouseButton.Left))
AppUtil.OpenBrowser(this.bannerList[this.currentBanner].Link.ToString());

ImGui.Dummy(ImGuiHelpers.GetScaledVector2(new Vector2(15)));
ImGui.Dummy(ImGuiHelpers.GetScaled(new Vector2(15)));

void ShowNewsEntry(News newsEntry)
{
Expand Down
6 changes: 3 additions & 3 deletions src/XIVLauncher.Core/Components/OtpEntryPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,20 @@ public override void Draw()
{
ImGui.PushStyleVar(ImGuiStyleVar.ChildRounding, 7f);

var childSize = ImGuiHelpers.GetScaledVector2(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(ImGuiHelpers.GetScaledVector2(new Vector2(40)));
ImGui.Dummy(ImGuiHelpers.GetScaled(new Vector2(40)));

// center text in window
ImGuiHelpers.CenteredText("Please enter your OTP");

int INPUT_WIDTH = ImGuiHelpers.GetScaledInt(150);
int INPUT_WIDTH = (int)ImGuiHelpers.GetScaled(150);
ImGui.SetNextItemWidth(INPUT_WIDTH);
ImGuiHelpers.CenterCursorFor(INPUT_WIDTH);

Expand Down
10 changes: 5 additions & 5 deletions src/XIVLauncher.Core/Components/SettingsPage/SettingsPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public override void Draw()
if (ImGui.BeginChild("SearchResults"))
{
ImGui.TextColored(ImGuiColors.DalamudGrey, settingsTab.Title);
ImGui.Dummy(ImGuiHelpers.GetScaledVector2(new Vector2(5)));
ImGui.Dummy(ImGuiHelpers.GetScaled(new Vector2(5)));

foreach (SettingsEntry settingsTabEntry in eligible)
{
Expand All @@ -95,7 +95,7 @@ public override void Draw()

ImGui.Separator();

ImGui.Dummy(ImGuiHelpers.GetScaledVector2(new Vector2(10)));
ImGui.Dummy(ImGuiHelpers.GetScaled(new Vector2(10)));
}
ImGui.EndChild();
}
Expand All @@ -108,7 +108,7 @@ public override void Draw()
}
}

ImGui.SetCursorPos(ImGuiHelpers.ViewportSize - ImGuiHelpers.GetScaledVector2(new Vector2(60)));
ImGui.SetCursorPos(ImGuiHelpers.ViewportSize - ImGuiHelpers.GetScaled(new Vector2(60)));

if (ImGui.BeginChild("###settingsFinishButton"))
{
Expand All @@ -120,13 +120,13 @@ public override void Draw()
{
ImGui.BeginDisabled();
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudRed);
ImGui.Button(FontAwesomeIcon.Ban.ToIconString(), ImGuiHelpers.GetScaledVector2(new Vector2(40)));
ImGui.Button(FontAwesomeIcon.Ban.ToIconString(), ImGuiHelpers.GetScaled(new Vector2(40)));
ImGui.PopStyleColor();
ImGui.EndDisabled();
}
else
{
if (ImGui.Button(FontAwesomeIcon.Check.ToIconString(), ImGuiHelpers.GetScaledVector2(new Vector2(40))))
if (ImGui.Button(FontAwesomeIcon.Check.ToIconString(), ImGuiHelpers.GetScaled(new Vector2(40))))
{
foreach (var settingsTab in this.tabs)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public override void Draw()
if (settingsEntry.IsVisible)
settingsEntry.Draw();

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

base.Draw();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ public SettingsTabAbout()

public override void Draw()
{
ImGui.Image(this.logoTexture.ImGuiHandle, ImGuiHelpers.GetScaledVector2(new Vector2(256)));
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(ImGuiHelpers.GetScaledVector2(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 @@ -73,7 +73,7 @@ public override void Draw()
ImGui.BeginDisabled();
ImGui.Text("Compatibility tool isn't set up. Please start the game at least once.");

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

if (ImGui.Button("Open prefix"))
Expand Down
2 changes: 1 addition & 1 deletion src/XIVLauncher.Core/Components/SteamDeckPromptPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public override void Draw()
{
ImGui.SetCursorPos(new Vector2(0));

ImGui.Image(this.updateWarnTexture.ImGuiHandle, ImGuiHelpers.GetScaledVector2(new Vector2(1280, 800)));
ImGui.Image(this.updateWarnTexture.ImGuiHandle, ImGuiHelpers.GetScaled(new Vector2(1280, 800)));

base.Draw();
}
Expand Down
10 changes: 5 additions & 5 deletions src/XIVLauncher.Core/Components/UpdateWarnPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ public override void Draw()
{
ImGui.SetCursorPos(new Vector2(0));

ImGui.Image(this.updateWarnTexture.ImGuiHandle, ImGuiHelpers.GetScaledVector2(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(ImGuiHelpers.GetScaledVector2(new Vector2(316, 481)));
ImGui.SetCursorPos(ImGuiHelpers.GetScaled(new Vector2(316, 481)));

if (ImGui.Button("###openGuideButton", ImGuiHelpers.GetScaledVector2(new Vector2(649, 101))))
if (ImGui.Button("###openGuideButton", ImGuiHelpers.GetScaled(new Vector2(649, 101))))
{
Environment.Exit(0);
}

ImGui.SetCursorPos(ImGuiHelpers.GetScaledVector2(new Vector2(316, 598)));
ImGui.SetCursorPos(ImGuiHelpers.GetScaled(new Vector2(316, 598)));

if (ImGui.Button("###finishFtsButton", ImGuiHelpers.GetScaledVector2(new Vector2(649, 101))))
if (ImGui.Button("###finishFtsButton", ImGuiHelpers.GetScaled(new Vector2(649, 101))))
{
App.FinishFromUpdateWarn();
}
Expand Down
12 changes: 1 addition & 11 deletions src/XIVLauncher.Core/ImGuiHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,7 @@ 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)
public static Vector2 GetScaled(Vector2 size)
{
return size * GlobalScale;
}
Expand Down
4 changes: 2 additions & 2 deletions src/XIVLauncher.Core/LauncherApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,11 @@ public override void Draw()

private void DrawModal()
{
ImGui.SetNextWindowSize(ImGuiHelpers.GetScaledVector2(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", ImGuiHelpers.GetScaledVector2(new Vector2(0, -ImGui.GetTextLineHeightWithSpacing() * 2))))
if (ImGui.BeginChild("###xl_modal_scrolling", ImGuiHelpers.GetScaled(new Vector2(0, -ImGui.GetTextLineHeightWithSpacing() * 2))))
{
ImGui.TextWrapped(this.modalText);
}
Expand Down
Loading

0 comments on commit c13c4a8

Please sign in to comment.