Nerfed/Nerfed.Editor/Editor/EditorGui.cs
2024-07-25 22:58:07 +02:00

75 lines
1.9 KiB
C#

using ImGuiNET;
using Nerfed.Editor.Project;
using Nerfed.Runtime;
using Nerfed.Runtime.Graphics;
using Nerfed.Runtime.Gui;
namespace Nerfed.Editor
{
internal static class EditorGui
{
private static GuiController guiController;
internal static void Initialize()
{
// Create GuiController.
guiController = new GuiController(Engine.GraphicsDevice, Engine.MainWindow, Color.DimGray);
// Subscribe to GUI update.
// GuiController.OnGui call => UpdateDock;
// GuiController.OnGui call => UpdateEditorWindows;
// GuiController.OnGui call => ...;
guiController.OnGui += HandleOnGui;
}
internal static void Update()
{
// Update GuiController.
guiController.Update(Engine.Timestep.TotalSeconds);
}
internal static void Render()
{
// Reneder GuiController.
guiController.Render();
}
internal static void Quit()
{
guiController.Dispose();
}
private static void UpdateDock()
{
// Setup default dockspace for the main window.
uint id = ImGui.GetID("MainDockSpace");
ImGui.DockSpaceOverViewport(id, ImGui.GetMainViewport(), ImGuiDockNodeFlags.None);
}
private static void UpdateMainMenu()
{
if (ImGui.BeginMainMenuBar())
{
if (ImGui.BeginMenu("File"))
{
if (ImGui.MenuItem("Exit"))
{
Engine.Quit();
}
ImGui.EndMenu();
}
ImGui.EndMainMenuBar();
}
}
private static void HandleOnGui()
{
UpdateMainMenu();
UpdateDock();
ImGui.ShowDemoWindow();
EditorProjectGui.OnGui();
}
}
}