-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameFont.cs
46 lines (38 loc) · 1.3 KB
/
GameFont.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using Dalamud.Interface.GameFonts;
using Dalamud.Interface.ManagedFontAtlas;
using Heliosphere.Util;
namespace Heliosphere;
internal class GameFont : IDisposable {
private Plugin Plugin { get; }
private readonly Dictionary<(uint, bool), IFontHandle> _fonts = new();
internal GameFont(Plugin plugin) {
this.Plugin = plugin;
}
public void Dispose() {
foreach (var handle in this._fonts.Values) {
handle.Dispose();
}
}
internal IFontHandle? this[uint size, bool italic] {
get {
IFontHandle handle;
if (this._fonts.ContainsKey((size, italic))) {
handle = this._fonts[(size, italic)];
} else {
handle = this.Plugin.Interface.UiBuilder.FontAtlas.NewGameFontHandle(new GameFontStyle(GameFontFamily.Axis, size) {
Italic = italic,
});
this._fonts[(size, italic)] = handle;
}
return handle.Available ? handle : null;
}
}
internal IFontHandle? this[uint size] => this[size, false];
internal OnDispose? WithFont(uint size, bool italic = false) {
var font = this[size, italic];
font?.Push();
return font == null
? null
: new OnDispose(font.Pop);
}
}