ImGuiNet
This commit is contained in:
+7
-54
@@ -2,16 +2,12 @@
|
||||
using System.Diagnostics;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
using Hexa.NET.ImGui;
|
||||
using Hexa.NET.ImGui.Utilities;
|
||||
using Hexa.NET.ImGuizmo;
|
||||
using Hexa.NET.ImPlot;
|
||||
using Hexa.NET.ImPlot3D;
|
||||
using ImGuiNET;
|
||||
using SDL3;
|
||||
|
||||
namespace SDL3_TestingSuite.SDL3;
|
||||
|
||||
public sealed unsafe class SDL3Window : IDisposable
|
||||
public sealed class SDL3Window : IDisposable
|
||||
{
|
||||
public readonly nint Window;
|
||||
public readonly nint Renderer;
|
||||
@@ -24,7 +20,7 @@ public sealed unsafe class SDL3Window : IDisposable
|
||||
private TimeSpan _time = TimeSpan.Zero;
|
||||
|
||||
private SDL.Rect _screenClipRect;
|
||||
private ImGuiContextPtr _imGuiContext;
|
||||
private nint _imGuiContext;
|
||||
|
||||
public bool Disposed => _disposed;
|
||||
private bool _disposed;
|
||||
@@ -45,56 +41,13 @@ public sealed unsafe class SDL3Window : IDisposable
|
||||
SDL.ShowWindow(Window);
|
||||
|
||||
// Create ImGui context
|
||||
var context = ImGui.CreateContext();
|
||||
ImPlot.CreateContext();
|
||||
ImPlot.SetImGuiContext(context);
|
||||
ImGuizmo.SetImGuiContext(context);
|
||||
// ImPlot3D.SetImGuiContext(context);
|
||||
// ImPlot3D.CreateContext();
|
||||
_imGuiContext = ImGui.CreateContext();
|
||||
|
||||
ImGuiIOPtr io = ImGui.GetIO();
|
||||
io.ConfigFlags |= ImGuiConfigFlags.NavEnableKeyboard | ImGuiConfigFlags.NavEnableGamepad | ImGuiConfigFlags.DockingEnable;
|
||||
// io.ConfigFlags |= ImGuiConfigFlags.ViewportsEnable;
|
||||
io.Fonts.Flags |= ImFontAtlasFlags.NoBakedLines;
|
||||
|
||||
io.Fonts.AddFontDefault();
|
||||
|
||||
try
|
||||
{
|
||||
string fontsPath = Path.Combine(AppContext.BaseDirectory, "Fonts");
|
||||
if (!Path.Exists(fontsPath)) Directory.CreateDirectory(fontsPath);
|
||||
|
||||
_watcher = new FileSystemWatcher(fontsPath);
|
||||
_watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.CreationTime;
|
||||
_watcher.Created += (a, b) =>
|
||||
{
|
||||
if (!File.Exists(b.FullPath)) return;
|
||||
|
||||
if (Path.GetExtension(b.FullPath) != ".ttf") return;
|
||||
|
||||
ImGui.GetIO().AddFont(b.FullPath);
|
||||
};
|
||||
_watcher.Deleted += (a, b) =>
|
||||
{
|
||||
if (Path.GetExtension(b.FullPath) != ".ttf") return;
|
||||
|
||||
ImGui.GetIO().RemoveFont(b.Name);
|
||||
};
|
||||
|
||||
_watcher.IncludeSubdirectories = false;
|
||||
_watcher.EnableRaisingEvents = true;
|
||||
|
||||
string[] fonts = Directory.GetFiles(fontsPath, "*.ttf", SearchOption.AllDirectories);
|
||||
foreach (string font in fonts)
|
||||
{
|
||||
io.AddFont(font);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
|
||||
// Init platform and renderer
|
||||
ImGuiSDL3Platform.Init(Window, Renderer);
|
||||
ImGuiSDL3Renderer.Init(Renderer);
|
||||
@@ -200,11 +153,11 @@ public sealed unsafe class SDL3Window : IDisposable
|
||||
RenderCallback = null;
|
||||
}
|
||||
|
||||
if (_imGuiContext.Handle != null)
|
||||
if (_imGuiContext != nint.Zero)
|
||||
{
|
||||
ImGui.SetCurrentContext(null);
|
||||
ImGui.SetCurrentContext(nint.Zero);
|
||||
ImGui.DestroyContext(_imGuiContext);
|
||||
_imGuiContext = null;
|
||||
_imGuiContext = nint.Zero;
|
||||
}
|
||||
|
||||
if (Renderer != nint.Zero)
|
||||
|
||||
Reference in New Issue
Block a user