mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-02-20 23:07:43 +01:00
Merge pull request #1619 from Soreepeong/feature/ifontatlas-lockable-fonts
Make `IFontHandle` lockable, and add font change event
This commit is contained in:
commit
e20daed848
18 changed files with 893 additions and 146 deletions
|
|
@ -1,7 +1,9 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Dalamud.Interface.GameFonts;
|
||||
using Dalamud.Interface.ManagedFontAtlas;
|
||||
|
|
@ -11,6 +13,8 @@ using Dalamud.Utility;
|
|||
|
||||
using ImGuiNET;
|
||||
|
||||
using Serilog;
|
||||
|
||||
namespace Dalamud.Interface.Internal.Windows.Data.Widgets;
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -103,6 +107,10 @@ internal class GamePrebakedFontsTestWidget : IDataWindowWidget, IDisposable
|
|||
minCapacity: 1024);
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
if (ImGui.Button("Test Lock"))
|
||||
Task.Run(this.TestLock);
|
||||
|
||||
fixed (byte* labelPtr = "Test Input"u8)
|
||||
{
|
||||
if (ImGuiNative.igInputTextMultiline(
|
||||
|
|
@ -155,6 +163,7 @@ internal class GamePrebakedFontsTestWidget : IDataWindowWidget, IDisposable
|
|||
.ToArray());
|
||||
|
||||
var offsetX = ImGui.CalcTextSize("99.9pt").X + (ImGui.GetStyle().FramePadding.X * 2);
|
||||
var counter = 0;
|
||||
foreach (var (family, items) in this.fontHandles)
|
||||
{
|
||||
if (!ImGui.CollapsingHeader($"{family} Family"))
|
||||
|
|
@ -180,10 +189,21 @@ internal class GamePrebakedFontsTestWidget : IDataWindowWidget, IDisposable
|
|||
{
|
||||
if (!this.useGlobalScale)
|
||||
ImGuiNative.igSetWindowFontScale(1 / ImGuiHelpers.GlobalScale);
|
||||
using var pushPop = handle.Value.Push();
|
||||
ImGuiNative.igTextUnformatted(
|
||||
this.testStringBuffer.Data,
|
||||
this.testStringBuffer.Data + this.testStringBuffer.Length);
|
||||
if (counter++ % 2 == 0)
|
||||
{
|
||||
using var pushPop = handle.Value.Push();
|
||||
ImGuiNative.igTextUnformatted(
|
||||
this.testStringBuffer.Data,
|
||||
this.testStringBuffer.Data + this.testStringBuffer.Length);
|
||||
}
|
||||
else
|
||||
{
|
||||
handle.Value.Push();
|
||||
ImGuiNative.igTextUnformatted(
|
||||
this.testStringBuffer.Data,
|
||||
this.testStringBuffer.Data + this.testStringBuffer.Length);
|
||||
handle.Value.Pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
|
|
@ -210,4 +230,49 @@ internal class GamePrebakedFontsTestWidget : IDataWindowWidget, IDisposable
|
|||
this.privateAtlas?.Dispose();
|
||||
this.privateAtlas = null;
|
||||
}
|
||||
|
||||
private async void TestLock()
|
||||
{
|
||||
if (this.fontHandles is not { } fontHandlesCopy)
|
||||
return;
|
||||
|
||||
Log.Information($"{nameof(GamePrebakedFontsTestWidget)}: {nameof(this.TestLock)} waiting for build");
|
||||
|
||||
await using var garbage = new DisposeSafety.ScopedFinalizer();
|
||||
var fonts = new List<ImFontPtr>();
|
||||
IFontHandle[] handles;
|
||||
try
|
||||
{
|
||||
handles = fontHandlesCopy.Values.SelectMany(x => x).Select(x => x.Handle.Value).ToArray();
|
||||
foreach (var handle in handles)
|
||||
{
|
||||
await handle.WaitAsync();
|
||||
var locked = handle.Lock();
|
||||
garbage.Add(locked);
|
||||
fonts.Add(locked);
|
||||
}
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
Log.Information($"{nameof(GamePrebakedFontsTestWidget)}: {nameof(this.TestLock)} cancelled");
|
||||
return;
|
||||
}
|
||||
|
||||
Log.Information($"{nameof(GamePrebakedFontsTestWidget)}: {nameof(this.TestLock)} waiting in lock");
|
||||
await Task.Delay(5000);
|
||||
|
||||
foreach (var (font, handle) in fonts.Zip(handles))
|
||||
TestSingle(font, handle);
|
||||
|
||||
return;
|
||||
|
||||
unsafe void TestSingle(ImFontPtr fontPtr, IFontHandle handle)
|
||||
{
|
||||
var dim = default(Vector2);
|
||||
var test = "Test string"u8;
|
||||
fixed (byte* pTest = test)
|
||||
ImGuiNative.ImFont_CalcTextSizeA(&dim, fontPtr, fontPtr.FontSize, float.MaxValue, 0, pTest, null, null);
|
||||
Log.Information($"{nameof(GamePrebakedFontsTestWidget)}: {handle} => {dim}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ internal class SettingsWindow : Window
|
|||
var fontAtlasFactory = Service<FontAtlasFactory>.Get();
|
||||
|
||||
var rebuildFont = fontAtlasFactory.UseAxis != configuration.UseAxisFontsFromGame;
|
||||
rebuildFont |= !Equals(ImGui.GetIO().FontGlobalScale, configuration.GlobalUiScale);
|
||||
|
||||
ImGui.GetIO().FontGlobalScale = configuration.GlobalUiScale;
|
||||
fontAtlasFactory.UseAxisOverride = null;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue