From 103816ca03fba3ff396e35ce9ccdfcca56c99476 Mon Sep 17 00:00:00 2001 From: jupahe64 Date: Mon, 6 Nov 2023 22:03:28 +0100 Subject: [PATCH] expose onConfigureIO in CreateWindow and add proper font setup to MainWindow --- Fushigi/ui/MainWindow.cs | 27 ++++++++++++++++++++++++++- Fushigi/windowing/WindowManager.cs | 9 ++------- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/Fushigi/ui/MainWindow.cs b/Fushigi/ui/MainWindow.cs index 613cf4c1..0808781d 100644 --- a/Fushigi/ui/MainWindow.cs +++ b/Fushigi/ui/MainWindow.cs @@ -6,15 +6,40 @@ using Fushigi.param; using Fushigi.ui.widgets; using ImGuiNET; +using System.Runtime.CompilerServices; +using System.Numerics; namespace Fushigi.ui { public class MainWindow { + private ImFontPtr mDefaultFont; + public MainWindow() { - WindowManager.CreateWindow(out mWindow); + WindowManager.CreateWindow(out mWindow, + onConfigureIO: () => { + unsafe + { + var io = ImGui.GetIO(); + + var nativeConfig = ImGuiNative.ImFontConfig_ImFontConfig(); + //Add a higher horizontal/vertical sample rate for global scaling. + nativeConfig->OversampleH = 8; + nativeConfig->OversampleV = 8; + nativeConfig->RasterizerMultiply = 1f; + nativeConfig->GlyphOffset = new Vector2(0); + + { + mDefaultFont = io.Fonts.AddFontFromFileTTF( + Path.Combine("res", "Font.ttf"), + 16, nativeConfig); + + //other fonts go here and follow the same schema + } + } + }); mWindow.Load += () => WindowManager.RegisterRenderDelegate(mWindow, Render); mWindow.Closing += Close; mWindow.Run(); diff --git a/Fushigi/windowing/WindowManager.cs b/Fushigi/windowing/WindowManager.cs index b5942d32..59a06e6d 100644 --- a/Fushigi/windowing/WindowManager.cs +++ b/Fushigi/windowing/WindowManager.cs @@ -24,7 +24,7 @@ private record struct WindowResources(ImGuiController ImguiController, IInputCon private static readonly List s_pendingInits = []; private static readonly List<(IWindow window, WindowResources res)> s_windows = []; - public static void CreateWindow(out IWindow window, Vector2D? initialWindowSize = null) + public static void CreateWindow(out IWindow window, Vector2D? initialWindowSize = null, Action? onConfigureIO = null) { var options = WindowOptions.Default; options.API = new GraphicsAPI( @@ -52,13 +52,8 @@ public static void CreateWindow(out IWindow window, Vector2D? initialWindow if (_window.Native!.Win32.HasValue) WindowsDarkmodeUtil.SetDarkmodeAware(_window.Native.Win32.Value.Hwnd); - - ImGuiFontConfig? imGuiFontConfig = new ImGuiFontConfig( - Path.Combine("res", "Font.ttf"), - 16); - var input = _window.CreateInput(); - var imguiController = new ImGuiController(s_gl, _window, input, imGuiFontConfig); + var imguiController = new ImGuiController(s_gl, _window, input, onConfigureIO); //update _window.Update += ds => imguiController.Update((float)ds);