diff --git a/Dalamud/Interface/GameFonts/GameFontHandle.cs b/Dalamud/Interface/GameFonts/GameFontHandle.cs index 77461aa0a..d11414517 100644 --- a/Dalamud/Interface/GameFonts/GameFontHandle.cs +++ b/Dalamud/Interface/GameFonts/GameFontHandle.cs @@ -2,6 +2,7 @@ using System.Numerics; using Dalamud.Interface.ManagedFontAtlas; using Dalamud.Interface.ManagedFontAtlas.Internals; +using Dalamud.Utility; using ImGuiNET; @@ -10,6 +11,7 @@ namespace Dalamud.Interface.GameFonts; /// /// ABI-compatible wrapper for . /// +[Api10ToDo(Api10ToDoAttribute.DeleteCompatBehavior)] public sealed class GameFontHandle : IFontHandle { private readonly IFontHandle.IInternal fontHandle; @@ -53,8 +55,14 @@ public sealed class GameFontHandle : IFontHandle /// public void Dispose() => this.fontHandle.Dispose(); - /// + /// + /// Pushes the font. + /// + /// An that can be used to pop the font on dispose. public IDisposable Push() => this.fontHandle.Push(); + + /// + IFontHandle.FontPopper IFontHandle.Push() => this.fontHandle.Push(); /// /// Creates a new .
diff --git a/Dalamud/Interface/ManagedFontAtlas/IFontHandle.cs b/Dalamud/Interface/ManagedFontAtlas/IFontHandle.cs index 854594663..47f384c11 100644 --- a/Dalamud/Interface/ManagedFontAtlas/IFontHandle.cs +++ b/Dalamud/Interface/ManagedFontAtlas/IFontHandle.cs @@ -1,4 +1,6 @@ -using ImGuiNET; +using Dalamud.Utility; + +using ImGuiNET; namespace Dalamud.Interface.ManagedFontAtlas; @@ -38,5 +40,39 @@ public interface IFontHandle : IDisposable /// You may not access the font once you dispose this object. ///
/// A disposable object that will call (1) on dispose. - IDisposable Push(); + /// If called outside of the main thread. + FontPopper Push(); + + /// + /// The wrapper for popping fonts. + /// + public struct FontPopper : IDisposable + { + private int count; + + /// + /// Initializes a new instance of the struct. + /// + /// The font to push. + /// Whether to push. + internal FontPopper(ImFontPtr fontPtr, bool push) + { + if (!push) + return; + + ThreadSafety.AssertMainThread(); + + this.count = 1; + ImGui.PushFont(fontPtr); + } + + /// + public void Dispose() + { + ThreadSafety.AssertMainThread(); + + while (this.count-- > 0) + ImGui.PopFont(); + } + } } diff --git a/Dalamud/Interface/ManagedFontAtlas/Internals/DelegateFontHandle.cs b/Dalamud/Interface/ManagedFontAtlas/Internals/DelegateFontHandle.cs index 99067a9de..bde349736 100644 --- a/Dalamud/Interface/ManagedFontAtlas/Internals/DelegateFontHandle.cs +++ b/Dalamud/Interface/ManagedFontAtlas/Internals/DelegateFontHandle.cs @@ -2,7 +2,6 @@ using System.Linq; using Dalamud.Interface.Utility; -using Dalamud.Interface.Utility.Raii; using Dalamud.Logging.Internal; using Dalamud.Utility; @@ -53,7 +52,7 @@ internal class DelegateFontHandle : IFontHandle.IInternal } /// - public IDisposable Push() => ImRaii.PushFont(this.ImFont, this.Available); + public IFontHandle.FontPopper Push() => new(this.ImFont, this.Available); /// /// Manager for s. diff --git a/Dalamud/Interface/ManagedFontAtlas/Internals/GamePrebakedFontHandle.cs b/Dalamud/Interface/ManagedFontAtlas/Internals/GamePrebakedFontHandle.cs index 2686259bc..feda47a8a 100644 --- a/Dalamud/Interface/ManagedFontAtlas/Internals/GamePrebakedFontHandle.cs +++ b/Dalamud/Interface/ManagedFontAtlas/Internals/GamePrebakedFontHandle.cs @@ -9,7 +9,6 @@ using Dalamud.Game.Text; using Dalamud.Interface.GameFonts; using Dalamud.Interface.Internal; using Dalamud.Interface.Utility; -using Dalamud.Interface.Utility.Raii; using Dalamud.Utility; using ImGuiNET; @@ -117,7 +116,7 @@ internal class GamePrebakedFontHandle : IFontHandle.IInternal } /// - public IDisposable Push() => ImRaii.PushFont(this.ImFont, this.Available); + public IFontHandle.FontPopper Push() => new(this.ImFont, this.Available); /// /// Manager for s.