From 8256e5431a316054406ecd75dccc3ff61078dcd2 Mon Sep 17 00:00:00 2001 From: goat <16760685+goaaats@users.noreply.github.com> Date: Tue, 24 Aug 2021 15:00:55 +0200 Subject: [PATCH] refactor: OnBuildFonts -> BuildFonts --- .../Interface/Internal/InterfaceManager.cs | 16 ++++----- Dalamud/Interface/UiBuilder.cs | 36 +++++++++++-------- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/Dalamud/Interface/Internal/InterfaceManager.cs b/Dalamud/Interface/Internal/InterfaceManager.cs index b5493605e..82d48f44a 100644 --- a/Dalamud/Interface/Internal/InterfaceManager.cs +++ b/Dalamud/Interface/Internal/InterfaceManager.cs @@ -48,7 +48,7 @@ namespace Dalamud.Interface.Internal private readonly ManualResetEvent fontBuildSignal; private readonly ISwapChainAddressResolver address; - private RawDX11Scene scene; + private RawDX11Scene? scene; // can't access imgui IO before first present call private bool lastWantCapture = false; @@ -136,6 +136,11 @@ namespace Dalamud.Interface.Internal /// public event RawDX11Scene.BuildUIDelegate Draw; + /// + /// Gets or sets an action that is executed when fonts are rebuilt. + /// + public event Action BuildFonts; + /// /// Gets the default ImGui font. /// @@ -151,11 +156,6 @@ namespace Dalamud.Interface.Internal /// public static ImFontPtr MonoFont { get; private set; } - /// - /// Gets or sets an action that is exexuted when fonts are rebuilt. - /// - public Action OnBuildFonts { get; set; } - /// /// Gets or sets the pointer to ImGui.IO(), when it was last used. /// @@ -164,7 +164,7 @@ namespace Dalamud.Interface.Internal /// /// Gets the D3D11 device instance. /// - public Device Device => this.scene.Device; + public Device? Device => this.scene?.Device; /// /// Gets the address handle to the main process window. @@ -494,7 +494,7 @@ namespace Dalamud.Interface.Internal MonoFont = ImGui.GetIO().Fonts.AddFontFromFileTTF(fontPathMono, 16.0f); Log.Verbose("[FONT] Invoke OnBuildFonts"); - this.OnBuildFonts?.Invoke(); + this.BuildFonts?.Invoke(); Log.Verbose("[FONT] OnBuildFonts OK!"); for (var i = 0; i < ImGui.GetIO().Fonts.Fonts.Size; i++) diff --git a/Dalamud/Interface/UiBuilder.cs b/Dalamud/Interface/UiBuilder.cs index 7de2dbae9..c6e9daede 100644 --- a/Dalamud/Interface/UiBuilder.cs +++ b/Dalamud/Interface/UiBuilder.cs @@ -35,7 +35,9 @@ namespace Dalamud.Interface this.stopwatch = new Stopwatch(); this.namespaceName = namespaceName; - Service.Get().Draw += this.OnDraw; + var interfaceManager = Service.Get(); + interfaceManager.Draw += this.OnDraw; + interfaceManager.BuildFonts += this.OnBuildFonts; } /// @@ -49,6 +51,15 @@ namespace Dalamud.Interface /// public event EventHandler OpenConfigUi; + /// + /// Gets or sets an action that is called any time ImGui fonts need to be rebuilt.
+ /// Any ImFontPtr objects that you store can be invalidated when fonts are rebuilt + /// (at any time), so you should both reload your custom fonts and restore those + /// pointers inside this handler.
+ /// PLEASE remove this handler inside Dispose, or when you no longer need your fonts! + ///
+ public event Action BuildFonts; + /// /// Gets the default Dalamud font based on Noto Sans CJK Medium in 17pt - supporting all game languages and icons. /// @@ -103,19 +114,6 @@ namespace Dalamud.Interface set => Service.Get().OverrideGameCursor = value; } - /// - /// Gets or sets an action that is called any time ImGui fonts need to be rebuilt.
- /// Any ImFontPtr objects that you store can be invalidated when fonts are rebuilt - /// (at any time), so you should both reload your custom fonts and restore those - /// pointers inside this handler.
- /// PLEASE remove this handler inside Dispose, or when you no longer need your fonts! - ///
- public Action OnBuildFonts - { - get => Service.Get().OnBuildFonts; - set => Service.Get().OnBuildFonts = value; - } - /// /// Gets or sets a value indicating whether statistics about UI draw time should be collected. /// @@ -218,7 +216,10 @@ namespace Dalamud.Interface ///
public void Dispose() { - Service.Get().Draw -= this.OnDraw; + var interfaceManager = Service.Get(); + + interfaceManager.Draw -= this.OnDraw; + interfaceManager.BuildFonts -= this.BuildFonts; } /// @@ -286,5 +287,10 @@ namespace Dalamud.Interface ImGui.PopID(); } + + private void OnBuildFonts() + { + this.BuildFonts.Invoke(); + } } }