Monad Engine da02fba2
> Undercity Codex_
Loading...
Searching...
No Matches
Editor.h
Go to the documentation of this file.
1/**
2 * @file Editor.h
3 * @ingroup mnd_editor
4 * @brief In-game ImGui overlay: hierarchy, inspector, console, stats.
5 *
6 * The Engine creates one Editor and drives its three-phase frame from
7 * mnd::Engine::Run(): `BeginFrame()` after polling input, `Draw()` to
8 * lay out every panel, and `EndFrame()` after the scene render so the
9 * GUI composites on top.
10 *
11 * Toggle visibility at runtime, or register your own debug panels:
12 * @code
13 * engine.GetEditor().RegisterPanel("My Tool", [] {
14 * ImGui::Text("hello from a custom panel");
15 * });
16 * @endcode
17 */
18
19#pragma once
20
21#include <functional>
22#include <string>
23#include <vector>
24
25#include "Types.h"
26
27struct GLFWwindow;
28
29namespace mnd
30{
31
32class GameObject;
33
34/**
35 * @ingroup mnd_editor
36 * @brief ImGui-based in-game editor overlay.
37 *
38 * Owned by the Engine singleton and driven from Engine::Run(). Provides
39 * scene hierarchy, inspector, asset browser, render settings (including
40 * internal-resolution pixelation) and stats panels.
41 */
42class Editor
43{
44 public:
45 /// Custom-panel callback — render any ImGui widgets you like inside.
46 using PanelFn = std::function<void()>;
47
48 /// Initialise ImGui against the given GLFW window. Call once at startup.
49 bool Init(GLFWwindow *window);
50 /// Tear down ImGui state. Call before destroying the GL context.
51 void Shutdown();
52
53 void BeginFrame(); ///< Call after glfwPollEvents.
54 void Draw(); ///< Builds all panels (no GL state changes yet).
55 void EndFrame(); ///< Renders the ImGui draw data to the current framebuffer.
56
57 bool IsVisible() const { return m_visible; } ///< Editor overlay currently shown?
58
59 void ToggleVisible() { m_visible = !m_visible; } ///< Flip overlay visibility.
60
61 /// Tell game code whether ImGui is consuming the mouse this frame
62 /// (e.g. when hovering a panel) — skip your own click handling if so.
63 bool WantsCaptureMouse() const;
64 /// Same as WantsCaptureMouse() but for the keyboard.
65 bool WantsCaptureKeyboard() const;
66
67 /// Stats panel hook: report per-frame draw call count.
68 void NotifyDrawCount(int n) { m_lastDrawCount = n; }
69
70 /// Register a custom ImGui panel rendered alongside the built-ins.
71 void RegisterPanel(std::string name, PanelFn fn) { m_customPanels.emplace_back(std::move(name), std::move(fn)); }
72
73 private:
74 void DrawMenuBar();
75 void DrawHierarchy();
76 void DrawInspector();
77 void DrawConsole();
78 void DrawStats();
79 void DrawSettings(); ///< Tabbed left-column window holding the four bodies below.
80 void DrawRenderBody(); ///< Render tab content (no Begin/End).
81 void DrawEngineBody(); ///< Engine tab content.
82 void DrawPhysicsBody(); ///< Physics tab content.
83 void DrawPlayerBody(); ///< Player tab content.
84 void DrawObjectNode(GameObject *obj);
85
86 bool m_initialized = false;
87 bool m_visible = false; ///< Hidden at startup; F1 opens.
88 bool m_showHierarchy = true;
89 bool m_showInspector = true;
90 bool m_showConsole = true;
91 bool m_showRender = true;
92 bool m_showStats = true;
93 bool m_showEngine = true;
94 bool m_showPhysics = true;
95 bool m_showPlayer = true;
96 bool m_showDemo = false;
97 GameObject *m_selected = nullptr;
98 int m_lastDrawCount = 0;
99 f32 m_fpsSmoothed = 0.0F;
100
101 bool m_vsyncEnabled = false;
102 bool m_wireframe = false;
103 bool m_cursorLocked = true;
104
105 std::vector<std::pair<std::string, PanelFn>> m_customPanels;
106};
107
108} // namespace mnd
Engine-wide primitive type aliases and GLM math imports.
ImGui-based in-game editor overlay.
Definition Editor.h:43
void RegisterPanel(std::string name, PanelFn fn)
Register a custom ImGui panel rendered alongside the built-ins.
Definition Editor.h:71
std::function< void()> PanelFn
Custom-panel callback — render any ImGui widgets you like inside.
Definition Editor.h:46
void EndFrame()
Renders the ImGui draw data to the current framebuffer.
Definition Editor.cpp:241
void Shutdown()
Tear down ImGui state. Call before destroying the GL context.
Definition Editor.cpp:60
bool WantsCaptureKeyboard() const
Same as WantsCaptureMouse() but for the keyboard.
Definition Editor.cpp:256
void ToggleVisible()
Flip overlay visibility.
Definition Editor.h:59
bool IsVisible() const
Editor overlay currently shown?
Definition Editor.h:57
bool Init(GLFWwindow *window)
Initialise ImGui against the given GLFW window. Call once at startup.
Definition Editor.cpp:35
void BeginFrame()
Call after glfwPollEvents.
Definition Editor.cpp:72
void NotifyDrawCount(int n)
Stats panel hook: report per-frame draw call count.
Definition Editor.h:68
bool WantsCaptureMouse() const
Definition Editor.cpp:251
void Draw()
Builds all panels (no GL state changes yet).
Definition Editor.cpp:182
Node in the scene graph: a named transform that owns components and children.
Definition GameObject.h:91
float f32
32-bit IEEE float — the standard GL scalar type.
Definition Types.h:40