feat: add IconFont to InterfaceManager and UiBuilder(based on FontAwesome 5) and a FontAwesomeIcon enum

This commit is contained in:
goat 2020-05-12 19:10:40 +02:00
parent eeab6a7135
commit dd711ed10c
4 changed files with 1457 additions and 6 deletions

View file

@ -16,6 +16,7 @@ namespace Dalamud.Interface
{AssetStoreUrl + "UIRes/serveropcode.json", "UIRes/serveropcode.json" },
{AssetStoreUrl + "UIRes/clientopcode.json", "UIRes/clientopcode.json" },
{AssetStoreUrl + "UIRes/NotoSansCJKjp-Medium.otf", "UIRes/NotoSansCJKjp-Medium.otf" },
{AssetStoreUrl + "UIRes/FontAwesome5FreeSolid.otf", "UIRes/FontAwesome5FreeSolid.otf" },
{AssetStoreUrl + "UIRes/logo.png", "UIRes/logo.png" },
{AssetStoreUrl + "UIRes/loc/dalamud/dalamud_de.json", "UIRes/loc/dalamud/dalamud_de.json" },
{AssetStoreUrl + "UIRes/loc/dalamud/dalamud_es.json", "UIRes/loc/dalamud/dalamud_es.json" },

File diff suppressed because it is too large Load diff

View file

@ -260,6 +260,9 @@ namespace Dalamud.Interface
return this.presentHook.Original(swapChain, syncInterval, presentFlags);
}
public static ImFontPtr DefaultFont { get; private set; }
public static ImFontPtr IconFont { get; private set; }
private unsafe void SetupFonts()
{
ImGui.GetIO().Fonts.Clear();
@ -269,27 +272,36 @@ namespace Dalamud.Interface
fontConfig.PixelSnapH = true;
var fontPathJp = Path.Combine(this.dalamud.StartInfo.WorkingDirectory, "UIRes", "NotoSansCJKjp-Medium.otf");
ImGui.GetIO().Fonts.AddFontFromFileTTF(fontPathJp, 17.0f, null, ImGui.GetIO().Fonts.GetGlyphRangesJapanese());
DefaultFont = ImGui.GetIO().Fonts.AddFontFromFileTTF(fontPathJp, 17.0f, null, ImGui.GetIO().Fonts.GetGlyphRangesJapanese());
var fontPathGame = Path.Combine(this.dalamud.StartInfo.WorkingDirectory, "UIRes", "gamesym.ttf");
Log.Verbose(fontPathGame);
var rangeHandle = GCHandle.Alloc(new ushort[]
var gameRangeHandle = GCHandle.Alloc(new ushort[]
{
0xE020,
0xE0DB,
0
}, GCHandleType.Pinned);
ImGui.GetIO().Fonts.AddFontFromFileTTF(fontPathGame, 17.0f, fontConfig, gameRangeHandle.AddrOfPinnedObject());
ImGui.GetIO().Fonts.AddFontFromFileTTF(fontPathGame, 17.0f, fontConfig, rangeHandle.AddrOfPinnedObject());
var fontPathIcon = Path.Combine(this.dalamud.StartInfo.WorkingDirectory, "UIRes", "FontAwesome5FreeSolid.otf");
OnBuildFonts?.Invoke();
var iconRangeHandle = GCHandle.Alloc(new ushort[]
{
0xE000,
0xF8FF,
0
}, GCHandleType.Pinned);
IconFont = ImGui.GetIO().Fonts.AddFontFromFileTTF(fontPathIcon, 17.0f, null, iconRangeHandle.AddrOfPinnedObject());
this.OnBuildFonts?.Invoke();
ImGui.GetIO().Fonts.Build();
fontConfig.Destroy();
rangeHandle.Free();
gameRangeHandle.Free();
iconRangeHandle.Free();
}
// This is intended to only be called as a handler attached to scene.OnNewRenderFrame

View file

@ -16,6 +16,15 @@ namespace Dalamud.Interface
public class UiBuilder : IDisposable {
private readonly string namespaceName;
/// <summary>
/// The default Dalamud font based on Noto Sans CJK Medium in 17pt - supporting all game languages and icons.
/// </summary>
public static ImFontPtr DefaultFont => InterfaceManager.DefaultFont;
/// <summary>
/// The default Dalamud icon font based on FontAwesome 5 Free solid in 20pt.
/// </summary>
public static ImFontPtr IconFont => InterfaceManager.IconFont;
/// <summary>
/// The delegate that gets called when Dalamud is ready to draw your windows or overlays.
/// When it is called, you can use static ImGui calls.