feat(ui): AcDream.UI.ImGui backend — Hexa.NET.ImGui + Silk.NET input bridge
Second piece of Phase D.2a: the ImGui-specific backend that implements
AcDream.UI.Abstractions' IPanelRenderer / IPanelHost. No GameWindow
hookup yet — compiles standalone for clean review before integration.
Packages:
* Hexa.NET.ImGui 2.2.9 (auto-generated from cimgui 1.92.2b)
* Hexa.NET.ImGui.Backends 1.0.18 (consolidated — OpenGL3 is here)
* Silk.NET.Input 2.23.0 + Silk.NET.OpenGL 2.23.0 (matches AcDream.App)
Files:
ImGuiBootstrapper.cs
One-shot static Initialize(glslVersion) / Shutdown() pair. Creates
the ImGui context, applies dark style, enables NavEnableKeyboard,
and boots ImGuiImplOpenGL3. Re-init is a no-op.
SilkInputBridge.cs
Event-driven Silk.NET -> ImGui IO bridge. Subscribes on construction;
Dispose() unsubscribes. Covers:
- KeyDown/Up -> ImGui.AddKeyEvent with modifier latching
(Ctrl/Shift/Alt/Super routed via both ModXxx flags AND named
key events so both IsKeyPressed checks and ImGui shortcut
matching work)
- KeyChar -> AddInputCharacter for text fields
- MouseMove -> AddMousePosEvent
- MouseDown/Up -> AddMouseButtonEvent (L=0, R=1, M=2)
- Scroll -> AddMouseWheelEvent (both axes)
Silk.NET.Input.Key -> ImGuiKey map covers WASD, arrows, modifiers,
letters, digits, function keys. Unmapped keys silently ignored.
BeginFrame(displaySize, dt) sets IO.DisplaySize + IO.DeltaTime.
ImGuiPanelRenderer.cs
IPanelRenderer impl — one-line wrappers on ImGui.Begin/End,
TextUnformatted, SameLine, Separator, ProgressBar. The ONLY place
Hexa.NET.ImGui types appear outside bootstrap/input plumbing. Panels
still never import ImGui.
ImGuiPanelHost.cs
IPanelHost impl. Dictionary keyed by IPanel.Id for idempotent
Register. RenderAll iterates visible panels and calls their Render.
Does NOT call ImGui.NewFrame / ImGui.Render — ownership belongs to
the caller (GameWindow) so GL state is explicit. Diagnostic `Count`
property.
No behavior change yet; next commit wires this into GameWindow behind
ACDREAM_DEVTOOLS=1 and ships the first visible VitalsPanel.
This commit is contained in:
parent
fc03fa377b
commit
a7dbce3474
6 changed files with 361 additions and 0 deletions
62
src/AcDream.UI.ImGui/ImGuiBootstrapper.cs
Normal file
62
src/AcDream.UI.ImGui/ImGuiBootstrapper.cs
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
using Hexa.NET.ImGui;
|
||||
using Hexa.NET.ImGui.Backends.OpenGL3;
|
||||
|
||||
namespace AcDream.UI.ImGui;
|
||||
|
||||
/// <summary>
|
||||
/// One-shot ImGui setup / teardown for the devtools overlay. Called from
|
||||
/// <c>GameWindow</c> when <c>ACDREAM_DEVTOOLS=1</c>. Hides the cimgui
|
||||
/// context + OpenGL3 renderer-impl lifecycles behind two static methods
|
||||
/// so the calling code stays clean.
|
||||
///
|
||||
/// <para>
|
||||
/// Intentionally <b>not</b> an <c>IDisposable</c> singleton — the host
|
||||
/// window owns the one call to <see cref="Shutdown"/> at application
|
||||
/// exit. Re-initialisation mid-session is not supported.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public static class ImGuiBootstrapper
|
||||
{
|
||||
private static bool _initialized;
|
||||
|
||||
/// <summary>
|
||||
/// Create an ImGui context, apply the dark style + enable keyboard
|
||||
/// navigation, and bootstrap the OpenGL3 renderer backend. The GL
|
||||
/// context owned by Silk.NET must be current on the calling thread.
|
||||
/// </summary>
|
||||
/// <param name="glslVersion">
|
||||
/// GLSL version directive for the ImGui-internal shader.
|
||||
/// <c>"#version 330"</c> matches acdream's existing shaders and is
|
||||
/// the safest default for the OpenGL 4.3 core profile we ship.
|
||||
/// </param>
|
||||
public static void Initialize(string glslVersion = "#version 330")
|
||||
{
|
||||
if (_initialized) return;
|
||||
|
||||
Hexa.NET.ImGui.ImGui.CreateContext();
|
||||
Hexa.NET.ImGui.ImGui.StyleColorsDark();
|
||||
|
||||
var io = Hexa.NET.ImGui.ImGui.GetIO();
|
||||
io.ConfigFlags |= ImGuiConfigFlags.NavEnableKeyboard;
|
||||
// DO NOT enable NavEnableGamepad — we don't wire a gamepad backend.
|
||||
// DO NOT enable DockingEnable / ViewportsEnable — out of scope for D.2a.
|
||||
|
||||
ImGuiImplOpenGL3.Init(glslVersion);
|
||||
|
||||
_initialized = true;
|
||||
}
|
||||
|
||||
/// <summary>Tear down the OpenGL3 renderer + destroy the ImGui context.</summary>
|
||||
public static void Shutdown()
|
||||
{
|
||||
if (!_initialized) return;
|
||||
|
||||
ImGuiImplOpenGL3.Shutdown();
|
||||
Hexa.NET.ImGui.ImGui.DestroyContext();
|
||||
|
||||
_initialized = false;
|
||||
}
|
||||
|
||||
/// <summary>True after <see cref="Initialize"/> has run successfully.</summary>
|
||||
public static bool IsInitialized => _initialized;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue