EditorGui setup

This commit is contained in:
max 2024-07-12 19:09:59 +02:00
parent b003ffbaec
commit 60b85960ff
3 changed files with 56 additions and 7 deletions

View File

@ -1,30 +1,71 @@
namespace Nerfed.Editor.Editor
using ImGuiNET;
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();
}
}
}

View File

@ -18,21 +18,25 @@ private static void HandleOnInitialize()
{
// Open project.
// Setip EditorGui.
EditorGui.Initialize();
}
private static void HandleOnUpdate()
{
// Editor Update.
EditorGui.Update();
// Try Catch UserCode Update.
}
private static void HandleOnRender()
{
// Editor GUI Render.
EditorGui.Render();
}
private static void HandleOnQuit()
{
EditorGui.Quit();
}
}

View File

@ -9,7 +9,7 @@
namespace Nerfed.Runtime.Gui;
internal class GuiController : IDisposable
public class GuiController : IDisposable
{
public event Action OnGui;
@ -144,9 +144,13 @@ public GuiController(GraphicsDevice graphicsDevice, Window mainWindow, Color cle
io.BackendFlags |= ImGuiBackendFlags.HasSetMousePos;
io.BackendFlags |= ImGuiBackendFlags.PlatformHasViewports;
io.BackendFlags |= ImGuiBackendFlags.RendererHasViewports;
UpdatePerFrameImGuiData(1.0 / 60.0);
ImGui.NewFrame();
frameBegun = true;
}
public void Update(float deltaTime)
public void Update(double deltaTime)
{
if (frameBegun)
{
@ -167,12 +171,12 @@ public void Update(float deltaTime)
ImGui.EndFrame();
}
private void UpdatePerFrameImGuiData(float deltaSeconds)
private void UpdatePerFrameImGuiData(double deltaSeconds)
{
ImGuiIOPtr io = ImGui.GetIO();
io.DisplaySize = new Vector2(mainWindow.Width, mainWindow.Height);
io.DisplayFramebufferScale = new Vector2(1, 1);
io.DeltaTime = deltaSeconds; // DeltaTime is in seconds.
io.DeltaTime = (float)deltaSeconds; // DeltaTime is in seconds.
}
private void UpdateInput()