chore: some imraii conversion

This commit is contained in:
goat 2023-03-26 00:38:34 +01:00
parent 14ce85627d
commit 1ce98a2350
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
8 changed files with 115 additions and 109 deletions

View file

@ -5,6 +5,7 @@ using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using Dalamud.Game.ClientState.Keys;
using Dalamud.Interface.Raii;
using ImGuiNET;
using ImGuiScene;
@ -161,9 +162,10 @@ public static class ImGuiHelpers
/// <param name="text">The text to write.</param>
public static void SafeTextColoredWrapped(Vector4 color, string text)
{
ImGui.PushStyleColor(ImGuiCol.Text, color);
using (ImRaii.PushColor(ImGuiCol.Text, color))
{
ImGui.TextWrapped(text.Replace("%", "%%"));
ImGui.PopStyleColor();
}
}
/// <summary>

View file

@ -20,6 +20,7 @@ using Dalamud.Interface.Internal.Windows.PluginInstaller;
using Dalamud.Interface.Internal.Windows.SelfTest;
using Dalamud.Interface.Internal.Windows.Settings;
using Dalamud.Interface.Internal.Windows.StyleEditor;
using Dalamud.Interface.Raii;
using Dalamud.Interface.Style;
using Dalamud.Interface.Windowing;
using Dalamud.Logging;
@ -522,7 +523,8 @@ internal class DalamudInterface : IDisposable, IServiceType
private void DrawCreditsDarkeningAnimation()
{
ImGui.PushStyleVar(ImGuiStyleVar.WindowRounding, 0f);
using var style = ImRaii.PushStyle(ImGuiStyleVar.WindowRounding, 0f);
ImGui.SetNextWindowPos(new Vector2(0, 0));
ImGui.SetNextWindowSize(ImGuiHelpers.MainViewport.Size);
ImGuiHelpers.ForceNextWindowMainViewport();
@ -536,8 +538,6 @@ internal class DalamudInterface : IDisposable, IServiceType
ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoFocusOnAppearing | ImGuiWindowFlags.NoBringToFrontOnFocus |
ImGuiWindowFlags.NoNav);
ImGui.End();
ImGui.PopStyleVar();
}
private void DrawHiddenDevMenuOpener()
@ -546,18 +546,17 @@ internal class DalamudInterface : IDisposable, IServiceType
if (!this.isImGuiDrawDevMenu && !condition.Any())
{
ImGui.PushStyleColor(ImGuiCol.Button, Vector4.Zero);
ImGui.PushStyleColor(ImGuiCol.ButtonActive, Vector4.Zero);
ImGui.PushStyleColor(ImGuiCol.ButtonHovered, Vector4.Zero);
ImGui.PushStyleColor(ImGuiCol.TextSelectedBg, new Vector4(0, 0, 0, 1));
ImGui.PushStyleColor(ImGuiCol.Border, new Vector4(0, 0, 0, 1));
ImGui.PushStyleColor(ImGuiCol.BorderShadow, new Vector4(0, 0, 0, 1));
ImGui.PushStyleColor(ImGuiCol.WindowBg, new Vector4(0, 0, 0, 1));
using var color = ImRaii.PushColor(ImGuiCol.Button, Vector4.Zero);
color.Push(ImGuiCol.ButtonActive, Vector4.Zero);
color.Push(ImGuiCol.ButtonHovered, Vector4.Zero);
color.Push(ImGuiCol.TextSelectedBg, new Vector4(0, 0, 0, 1));
color.Push(ImGuiCol.Border, new Vector4(0, 0, 0, 1));
color.Push(ImGuiCol.BorderShadow, new Vector4(0, 0, 0, 1));
color.Push(ImGuiCol.WindowBg, new Vector4(0, 0, 0, 1));
ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, Vector2.Zero);
ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, Vector2.Zero);
ImGui.PushStyleVar(ImGuiStyleVar.WindowBorderSize, 0);
ImGui.PushStyleVar(ImGuiStyleVar.FrameBorderSize, 0);
using var style = ImRaii.PushStyle(ImGuiStyleVar.WindowPadding, Vector2.Zero);
style.Push(ImGuiStyleVar.WindowBorderSize, 0);
style.Push(ImGuiStyleVar.FrameBorderSize, 0);
var windowPos = ImGui.GetMainViewport().Pos + new Vector2(20);
ImGui.SetNextWindowPos(windowPos, ImGuiCond.Always);
@ -589,9 +588,6 @@ internal class DalamudInterface : IDisposable, IServiceType
ImGui.End();
}
ImGui.PopStyleVar(4);
ImGui.PopStyleColor(7);
}
}

View file

@ -5,6 +5,7 @@ using CheapLoc;
using Dalamud.Configuration.Internal;
using Dalamud.Interface.Colors;
using Dalamud.Interface.Internal.Windows.Settings.Tabs;
using Dalamud.Interface.Raii;
using Dalamud.Interface.Windowing;
using Dalamud.Plugin.Internal;
using Dalamud.Utility;
@ -159,12 +160,11 @@ internal class SettingsWindow : Window
if (ImGui.BeginChild("###settingsFinishButton"))
{
ImGui.PushStyleVar(ImGuiStyleVar.FrameRounding, 100f);
ImGui.PushFont(InterfaceManager.IconFont);
using var disabled = ImRaii.Disabled(this.tabs.Any(x => x.Entries.Any(y => !y.IsValid)));
var invalid = this.tabs.Any(x => x.Entries.Any(y => !y.IsValid));
if (invalid)
ImGui.BeginDisabled();
using (ImRaii.PushStyle(ImGuiStyleVar.FrameRounding, 100f))
{
using var font = ImRaii.PushFont(InterfaceManager.IconFont);
if (ImGui.Button(FontAwesomeIcon.Save.ToIconString(), new Vector2(40)))
{
@ -173,9 +173,7 @@ internal class SettingsWindow : Window
if (!ImGui.IsKeyDown(ImGuiKey.ModShift))
this.IsOpen = false;
}
ImGui.PopStyleVar();
ImGui.PopFont();
}
if (ImGui.IsItemHovered())
{
@ -183,9 +181,6 @@ internal class SettingsWindow : Window
? Loc.Localize("DalamudSettingsSaveAndExit", "Save changes and close")
: Loc.Localize("DalamudSettingsSaveAndExit", "Save changes"));
}
if (invalid)
ImGui.EndDisabled();
}
ImGui.EndChild();

View file

@ -8,6 +8,7 @@ using System.Numerics;
using CheapLoc;
using Dalamud.Game.Gui;
using Dalamud.Interface.GameFonts;
using Dalamud.Interface.Raii;
using Dalamud.Plugin.Internal;
using Dalamud.Utility;
using FFXIVClientStructs.FFXIV.Client.Game.UI;
@ -243,8 +244,8 @@ Contribute at: https://github.com/goatcorp/Dalamud
this.resetNow = false;
}
ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, Vector2.Zero);
using (ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, Vector2.Zero))
{
ImGuiHelpers.ScaledDummy(0, windowSize.Y + 20f);
ImGui.Text(string.Empty);
@ -280,8 +281,7 @@ Contribute at: https://github.com/goatcorp/Dalamud
}
ImGuiHelpers.ScaledDummy(0, windowSize.Y + 50f);
ImGui.PopStyleVar();
}
if (this.creditsThrottler.Elapsed.TotalMilliseconds > (1000.0f / CreditFps))
{

View file

@ -10,6 +10,7 @@ using Dalamud.Configuration;
using Dalamud.Configuration.Internal;
using Dalamud.Interface.Colors;
using Dalamud.Interface.Components;
using Dalamud.Interface.Raii;
using Dalamud.Plugin.Internal;
using ImGuiNET;
@ -57,10 +58,11 @@ public class DevPluginsSettingsEntry : SettingsEntry
ImGui.Text(this.Name);
if (this.devPluginLocationsChanged)
{
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.HealerGreen);
using (ImRaii.PushColor(ImGuiCol.Text, ImGuiColors.HealerGreen))
{
ImGui.SameLine();
ImGui.Text(Loc.Localize("DalamudSettingsChanged", "(Changed)"));
ImGui.PopStyleColor();
}
}
ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.DalamudGrey, Loc.Localize("DalamudSettingsDevPluginLocationsHint", "Add additional dev plugin load locations.\nThese can be either the directory or DLL path."));

View file

@ -7,6 +7,7 @@ using System.Linq;
using Dalamud.Configuration.Internal;
using Dalamud.Interface.Colors;
using Dalamud.Interface.Raii;
using Dalamud.Utility;
using ImGuiNET;
@ -121,9 +122,11 @@ internal sealed class SettingsEntry<T> : SettingsEntry
}
}
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudGrey);
using (ImRaii.PushColor(ImGuiCol.Text, ImGuiColors.DalamudGrey))
{
ImGuiHelpers.SafeTextWrapped(this.Description);
ImGui.PopStyleColor();
}
if (this.CheckValidity != null)
{
@ -132,11 +135,13 @@ internal sealed class SettingsEntry<T> : SettingsEntry
if (!this.IsValid)
{
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudRed);
using (ImRaii.PushColor(ImGuiCol.Text, ImGuiColors.DalamudRed))
{
ImGui.Text(validityMsg);
ImGui.PopStyleColor();
}
}
}
else
{
this.IsValid = true;
@ -146,11 +151,13 @@ internal sealed class SettingsEntry<T> : SettingsEntry
if (warningMessage != null)
{
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudRed);
using (ImRaii.PushColor(ImGuiCol.Text, ImGuiColors.DalamudRed))
{
ImGui.Text(warningMessage);
ImGui.PopStyleColor();
}
}
}
public override void Load()
{

View file

@ -10,6 +10,7 @@ using Dalamud.Configuration;
using Dalamud.Configuration.Internal;
using Dalamud.Interface.Colors;
using Dalamud.Interface.Components;
using Dalamud.Interface.Raii;
using Dalamud.Plugin.Internal;
using ImGuiNET;
@ -53,10 +54,11 @@ public class ThirdRepoSettingsEntry : SettingsEntry
ImGui.Text(Loc.Localize("DalamudSettingsCustomRepo", "Custom Plugin Repositories"));
if (this.thirdRepoListChanged)
{
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.HealerGreen);
using (ImRaii.PushColor(ImGuiCol.Text, ImGuiColors.HealerGreen))
{
ImGui.SameLine();
ImGui.Text(Loc.Localize("DalamudSettingsChanged", "(Changed)"));
ImGui.PopStyleColor();
}
}
ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.DalamudGrey, Loc.Localize("DalamudSettingCustomRepoHint", "Add custom plugin repositories."));

View file

@ -9,6 +9,7 @@ using Dalamud.Game;
using Dalamud.Game.ClientState;
using Dalamud.Game.Gui;
using Dalamud.Interface.Animation.EasingFunctions;
using Dalamud.Interface.Raii;
using Dalamud.Interface.Windowing;
using ImGuiNET;
using ImGuiScene;
@ -169,8 +170,8 @@ internal class TitleScreenMenuWindow : Window, IDisposable
this.fadeOutEasing.Update();
ImGui.PushStyleVar(ImGuiStyleVar.Alpha, (float)this.fadeOutEasing.Value);
using (ImRaii.PushStyle(ImGuiStyleVar.Alpha, (float)this.fadeOutEasing.Value))
{
for (var i = 0; i < tsm.Entries.Count; i++)
{
var entry = tsm.Entries[i];
@ -183,8 +184,7 @@ internal class TitleScreenMenuWindow : Window, IDisposable
cursor.Y = finalPos;
ImGui.SetCursorPos(cursor);
}
ImGui.PopStyleVar();
}
var isHover = ImGui.IsWindowHovered(ImGuiHoveredFlags.RootAndChildWindows |
ImGuiHoveredFlags.AllowWhenBlockedByActiveItem);
@ -254,9 +254,11 @@ internal class TitleScreenMenuWindow : Window, IDisposable
var initialCursor = ImGui.GetCursorPos();
ImGui.PushStyleVar(ImGuiStyleVar.Alpha, (float)shadeEasing.Value);
using (ImRaii.PushStyle(ImGuiStyleVar.Alpha, (float)shadeEasing.Value))
{
ImGui.Image(this.shadeTexture.ImGuiHandle, new Vector2(this.shadeTexture.Width * scale, this.shadeTexture.Height * scale));
ImGui.PopStyleVar();
}
var isHover = ImGui.IsItemHovered();
if (isHover && (!shadeEasing.IsRunning || (shadeEasing.IsDone && shadeEasing.IsInverse)) && !inhibitFadeout)
@ -331,14 +333,14 @@ internal class TitleScreenMenuWindow : Window, IDisposable
}
// Drop shadow
ImGui.PushStyleColor(ImGuiCol.Text, 0xFF000000);
using (ImRaii.PushColor(ImGuiCol.Text, 0xFF000000))
{
for (int i = 0, i_ = (int)Math.Ceiling(1 * scale); i < i_; i++)
{
ImGui.SetCursorPos(new Vector2(cursor.X, cursor.Y + i));
ImGui.Text(entry.Name);
}
ImGui.PopStyleColor();
}
ImGui.SetCursorPos(cursor);
ImGui.Text(entry.Name);