VisuTwin Canvas
C++ 3D Engine — Metal Backend
Loading...
Searching...
No Matches
imguiOverlay.h
Go to the documentation of this file.
1//
2// ImGui overlay for VisuTwin Canvas — digital twin HUD rendering.
3//
4// Provides GPU-accelerated UI overlays rendered on top of the 3D scene:
5// - Floating data panels, sensor readouts, charts (via ImPlot)
6// - 3D-anchored labels projected to screen space
7// - Digital twin dark glassmorphism theme
8//
9// Integration point: hook into Engine's "postrender" event so the overlay
10// renders after all 3D passes but before the frame is presented.
11//
12//
13#pragma once
14
15#include <functional>
16#include <string>
17#include <vector>
18
19#include "core/math/color.h"
20#include "core/math/matrix4.h"
21#include "core/math/vector3.h"
22
23union SDL_Event;
24struct SDL_Window;
25
26namespace visutwin::canvas
27{
29
30 // ── 3D-anchored label descriptor ─────────────────────────────────────
31
32 struct Label3D
33 {
35 std::string text;
36 Color color = Color(0.94f, 0.96f, 0.98f, 0.95f); // slate-100
37 float fontSize = 0.0f; // 0 = default
38 };
39
40 // ── ImGui overlay lifecycle manager ──────────────────────────────────
41
43 {
44 public:
45 ImGuiOverlay() = default;
47
48 // Non-copyable, movable
49 ImGuiOverlay(const ImGuiOverlay&) = delete;
51 ImGuiOverlay(ImGuiOverlay&&) noexcept;
52 ImGuiOverlay& operator=(ImGuiOverlay&&) noexcept;
53
56 void init(MetalGraphicsDevice* device, SDL_Window* window);
57
61 bool processEvent(const SDL_Event& event);
62
64 bool wantCaptureMouse() const;
65
67 bool wantCaptureKeyboard() const;
68
70 void beginFrame();
71
74 void endFrame();
75
78 void renderToGPU();
79
81 void shutdown();
82
84 bool isInitialized() const { return _initialized; }
85
86 // ── 3D-anchored label helpers ────────────────────────────────────
87
89 void setViewProjection(const Matrix4& vp) { _viewProjection = vp; }
90
92 void setWindowSize(int width, int height) { _windowW = width; _windowH = height; }
93
97 void label3D(const Vector3& worldPos, const char* text,
98 const Color& color = Color(0.94f, 0.96f, 0.98f, 0.95f));
99
101 void panelLabel3D(const Vector3& worldPos, const char* title, const char* body,
102 const Color& panelColor = Color(0.06f, 0.09f, 0.16f, 0.88f));
103
104 // ── Theme ────────────────────────────────────────────────────────
105
107 static void applyDigitalTwinTheme();
108
109 private:
112 bool worldToScreen(const Vector3& worldPos, float& screenX, float& screenY) const;
113
114 MetalGraphicsDevice* _device = nullptr;
115 SDL_Window* _window = nullptr;
116 bool _initialized = false;
117
118 // View-projection for 3D label projection
119 Matrix4 _viewProjection;
120 int _windowW = 1280;
121 int _windowH = 900;
122 };
123
124} // namespace visutwin::canvas
void setViewProjection(const Matrix4 &vp)
Set the current frame's view-projection matrix (needed for worldToScreen).
ImGuiOverlay & operator=(const ImGuiOverlay &)=delete
bool isInitialized() const
Whether the overlay has been initialized.
bool wantCaptureKeyboard() const
True if ImGui wants exclusive keyboard input (an ImGui text field is active).
bool processEvent(const SDL_Event &event)
void label3D(const Vector3 &worldPos, const char *text, const Color &color=Color(0.94f, 0.96f, 0.98f, 0.95f))
void shutdown()
Shut down ImGui and release all resources.
void panelLabel3D(const Vector3 &worldPos, const char *title, const char *body, const Color &panelColor=Color(0.06f, 0.09f, 0.16f, 0.88f))
Render a text label with a background panel anchored to a 3D world position.
bool wantCaptureMouse() const
True if ImGui wants exclusive mouse input (cursor is over an ImGui window).
static void applyDigitalTwinTheme()
Apply the digital twin dark glassmorphism theme.
void beginFrame()
Begin a new ImGui frame. Call once per frame before building any UI.
void init(MetalGraphicsDevice *device, SDL_Window *window)
void setWindowSize(int width, int height)
Set the current window dimensions (needed for NDC→screen conversion).
ImGuiOverlay(const ImGuiOverlay &)=delete
RGBA color with floating-point components in [0, 1].
Definition color.h:18
4x4 column-major transformation matrix with SIMD acceleration.
Definition matrix4.h:31
3D vector for positions, directions, and normals with multi-backend SIMD acceleration.
Definition vector3.h:29