refactor: OnBuildFonts -> BuildFonts

This commit is contained in:
goat 2021-08-24 15:00:55 +02:00
parent 33cbad9f16
commit 8256e5431a
No known key found for this signature in database
GPG key ID: F18F057873895461
2 changed files with 29 additions and 23 deletions

View file

@ -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
/// </summary>
public event RawDX11Scene.BuildUIDelegate Draw;
/// <summary>
/// Gets or sets an action that is executed when fonts are rebuilt.
/// </summary>
public event Action BuildFonts;
/// <summary>
/// Gets the default ImGui font.
/// </summary>
@ -151,11 +156,6 @@ namespace Dalamud.Interface.Internal
/// </summary>
public static ImFontPtr MonoFont { get; private set; }
/// <summary>
/// Gets or sets an action that is exexuted when fonts are rebuilt.
/// </summary>
public Action OnBuildFonts { get; set; }
/// <summary>
/// Gets or sets the pointer to ImGui.IO(), when it was last used.
/// </summary>
@ -164,7 +164,7 @@ namespace Dalamud.Interface.Internal
/// <summary>
/// Gets the D3D11 device instance.
/// </summary>
public Device Device => this.scene.Device;
public Device? Device => this.scene?.Device;
/// <summary>
/// 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++)

View file

@ -35,7 +35,9 @@ namespace Dalamud.Interface
this.stopwatch = new Stopwatch();
this.namespaceName = namespaceName;
Service<InterfaceManager>.Get().Draw += this.OnDraw;
var interfaceManager = Service<InterfaceManager>.Get();
interfaceManager.Draw += this.OnDraw;
interfaceManager.BuildFonts += this.OnBuildFonts;
}
/// <summary>
@ -49,6 +51,15 @@ namespace Dalamud.Interface
/// </summary>
public event EventHandler OpenConfigUi;
/// <summary>
/// Gets or sets an action that is called any time ImGui fonts need to be rebuilt.<br/>
/// Any ImFontPtr objects that you store <strong>can be invalidated</strong> when fonts are rebuilt
/// (at any time), so you should both reload your custom fonts and restore those
/// pointers inside this handler.<br/>
/// <strong>PLEASE remove this handler inside Dispose, or when you no longer need your fonts!</strong>
/// </summary>
public event Action BuildFonts;
/// <summary>
/// Gets the default Dalamud font based on Noto Sans CJK Medium in 17pt - supporting all game languages and icons.
/// </summary>
@ -103,19 +114,6 @@ namespace Dalamud.Interface
set => Service<InterfaceManager>.Get().OverrideGameCursor = value;
}
/// <summary>
/// Gets or sets an action that is called any time ImGui fonts need to be rebuilt.<br/>
/// Any ImFontPtr objects that you store <strong>can be invalidated</strong> when fonts are rebuilt
/// (at any time), so you should both reload your custom fonts and restore those
/// pointers inside this handler.<br/>
/// <strong>PLEASE remove this handler inside Dispose, or when you no longer need your fonts!</strong>
/// </summary>
public Action OnBuildFonts
{
get => Service<InterfaceManager>.Get().OnBuildFonts;
set => Service<InterfaceManager>.Get().OnBuildFonts = value;
}
/// <summary>
/// Gets or sets a value indicating whether statistics about UI draw time should be collected.
/// </summary>
@ -218,7 +216,10 @@ namespace Dalamud.Interface
/// </summary>
public void Dispose()
{
Service<InterfaceManager>.Get().Draw -= this.OnDraw;
var interfaceManager = Service<InterfaceManager>.Get();
interfaceManager.Draw -= this.OnDraw;
interfaceManager.BuildFonts -= this.BuildFonts;
}
/// <summary>
@ -286,5 +287,10 @@ namespace Dalamud.Interface
ImGui.PopID();
}
private void OnBuildFonts()
{
this.BuildFonts.Invoke();
}
}
}