mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Fixed ImGui and added docking and viewport support
This commit is contained in:
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
FileVersion = 1
|
FileVersion = 1
|
||||||
Projects = {Sandbox = {Path = "Sandbox"}, GlitchyEngine = {Path = "GlitchyEngine"}, GlitchLog = {Path = "GlitchLog"}, DirectX = {Path = "GlitchyEngine/vendor/directx/DirectX"}, imgui-beef = {Path = "GlitchyEngine/vendor/imgui-beef/imgui-beef"}, imgui-impl-win32 = {Path = "GlitchyEngine/vendor/imgui-beef/imgui-impl-win32"}, imgui-impl-dx11 = {Path = "GlitchyEngine/vendor/imgui-beef/imgui-impl-dx11"}}
|
Projects = {Sandbox = {Path = "Sandbox"}, GlitchyEngine = {Path = "GlitchyEngine"}, GlitchLog = {Path = "GlitchLog"}, DirectX = {Path = "GlitchyEngine/vendor/directx/DirectX"}, ImGui = {Path = "GlitchyEngine/vendor/imgui-beef/ImGui"}, ImGuiImplWin32 = {Path = "GlitchyEngine/vendor/imgui-beef/ImGuiImplWin32"}, ImGuiImplDx11 = {Path = "GlitchyEngine/vendor/imgui-beef/ImGuiImplDX11"}}
|
||||||
|
|
||||||
[Workspace]
|
[Workspace]
|
||||||
StartupProject = "Sandbox"
|
StartupProject = "Sandbox"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
FileVersion = 1
|
FileVersion = 1
|
||||||
Dependencies = {GlitchLog = "*", corlib = "*", DirectX = "*", imgui-beef = "*", imgui-impl-win32 = "*", imgui-impl-dx11 = "*"}
|
Dependencies = {GlitchLog = "*", corlib = "*", DirectX = "*", ImGui = "*", ImGuiImplDx11 = "*", ImGuiImplWin32 = "*"}
|
||||||
|
|
||||||
[Project]
|
[Project]
|
||||||
Name = "GlitchyEngine"
|
Name = "GlitchyEngine"
|
||||||
@@ -8,6 +8,7 @@ Name = "GlitchyEngine"
|
|||||||
PreprocessorMacros = ["DEBUG", "GE_WINDOWS"]
|
PreprocessorMacros = ["DEBUG", "GE_WINDOWS"]
|
||||||
|
|
||||||
[Configs.Debug.Win64]
|
[Configs.Debug.Win64]
|
||||||
|
CLibType = "DynamicDebug"
|
||||||
PreprocessorMacros = ["DEBUG", "GE_WINDOWS"]
|
PreprocessorMacros = ["DEBUG", "GE_WINDOWS"]
|
||||||
|
|
||||||
[Configs.Release.Win32]
|
[Configs.Release.Win32]
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using System;
|
|||||||
using GlitchyEngine.Events;
|
using GlitchyEngine.Events;
|
||||||
using GlitchyEngine.Platform.Windows;
|
using GlitchyEngine.Platform.Windows;
|
||||||
using GlitchyEngine.Platform.DX11;
|
using GlitchyEngine.Platform.DX11;
|
||||||
|
using GlitchyEngine.ImGui;
|
||||||
|
|
||||||
namespace GlitchyEngine
|
namespace GlitchyEngine
|
||||||
{
|
{
|
||||||
@@ -14,6 +15,8 @@ namespace GlitchyEngine
|
|||||||
|
|
||||||
private LayerStack _layerStack = new LayerStack() ~ delete _;
|
private LayerStack _layerStack = new LayerStack() ~ delete _;
|
||||||
|
|
||||||
|
private ImGuiLayer _imGuiLayer;
|
||||||
|
|
||||||
private GameTime _gameTime = new GameTime(true) ~ delete _;
|
private GameTime _gameTime = new GameTime(true) ~ delete _;
|
||||||
|
|
||||||
public bool IsRunning => _running;
|
public bool IsRunning => _running;
|
||||||
@@ -29,6 +32,9 @@ namespace GlitchyEngine
|
|||||||
|
|
||||||
_window = GlitchyEngine.Window.CreateWindow(WindowDescription());
|
_window = GlitchyEngine.Window.CreateWindow(WindowDescription());
|
||||||
_window.EventCallback = new => OnEvent;
|
_window.EventCallback = new => OnEvent;
|
||||||
|
|
||||||
|
_imGuiLayer = new ImGuiLayer();
|
||||||
|
PushLayer(_imGuiLayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnEvent(Event e)
|
public void OnEvent(Event e)
|
||||||
@@ -59,6 +65,8 @@ namespace GlitchyEngine
|
|||||||
|
|
||||||
_window.Update();
|
_window.Update();
|
||||||
|
|
||||||
|
_imGuiLayer.ImGuiRender();
|
||||||
|
|
||||||
DirectX.Present();
|
DirectX.Present();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using imgui_beef;
|
using ImGui;
|
||||||
using GlitchyEngine.Events;
|
using GlitchyEngine.Events;
|
||||||
|
|
||||||
// Temporary
|
// Temporary
|
||||||
@@ -20,39 +20,32 @@ namespace GlitchyEngine.ImGui
|
|||||||
ImGui.StyleColorsDark();
|
ImGui.StyleColorsDark();
|
||||||
|
|
||||||
ref ImGui.IO io = ref ImGui.GetIO();
|
ref ImGui.IO io = ref ImGui.GetIO();
|
||||||
io.BackendFlags |= .HasMouseCursors | .HasSetMousePos;
|
io.ConfigFlags |= .NavEnableKeyboard;
|
||||||
|
io.ConfigFlags |= .DockingEnable;
|
||||||
|
io.ConfigFlags |= .ViewportsEnable;
|
||||||
|
|
||||||
// Todo: Temporary, needs own keymap
|
ref ImGui.Style style = ref ImGui.GetStyle();
|
||||||
// Keyboard mapping. ImGui will use those indices to peek into the io.KeysDown[] array that we will update during the application lifetime.
|
|
||||||
io.KeyMap[(int32)ImGui.Key.Tab] = (int32)Key.Tab;
|
|
||||||
io.KeyMap[(int32)ImGui.Key.LeftArrow] = (int32)Key.Left;
|
|
||||||
io.KeyMap[(int32)ImGui.Key.RightArrow] = (int32)Key.Right;
|
|
||||||
io.KeyMap[(int32)ImGui.Key.UpArrow] = (int32)Key.Up;
|
|
||||||
io.KeyMap[(int32)ImGui.Key.DownArrow] = (int32)Key.Down;
|
|
||||||
io.KeyMap[(int32)ImGui.Key.PageUp] = (int32)Key.Prior;
|
|
||||||
io.KeyMap[(int32)ImGui.Key.PageDown] = (int32)Key.Next;
|
|
||||||
io.KeyMap[(int32)ImGui.Key.Home] = (int32)Key.Home;
|
|
||||||
io.KeyMap[(int32)ImGui.Key.End] = (int32)Key.End;
|
|
||||||
io.KeyMap[(int32)ImGui.Key.Insert] = (int32)Key.Insert;
|
|
||||||
io.KeyMap[(int32)ImGui.Key.Delete] = (int32)Key.Delete;
|
|
||||||
io.KeyMap[(int32)ImGui.Key.Backspace] = (int32)Key.Backspace;
|
|
||||||
io.KeyMap[(int32)ImGui.Key.Space] = (int32)Key.Space;
|
|
||||||
io.KeyMap[(int32)ImGui.Key.Enter] = (int32)Key.Return;
|
|
||||||
io.KeyMap[(int32)ImGui.Key.Escape] = (int32)Key.Escape;
|
|
||||||
io.KeyMap[(int32)ImGui.Key.KeyPadEnter] = (int32)Key.Return;
|
|
||||||
io.KeyMap[(int32)ImGui.Key.A] = (int32)(int32)Key.A;
|
|
||||||
io.KeyMap[(int32)ImGui.Key.C] = (int32)(int32)Key.C;
|
|
||||||
io.KeyMap[(int32)ImGui.Key.V] = (int32)(int32)Key.V;
|
|
||||||
io.KeyMap[(int32)ImGui.Key.X] = (int32)(int32)Key.X;
|
|
||||||
io.KeyMap[(int32)ImGui.Key.Y] = (int32)(int32)Key.Y;
|
|
||||||
io.KeyMap[(int32)ImGui.Key.Z] = (int32)(int32)Key.Z;
|
|
||||||
|
|
||||||
// Todo: temporary, needs to be platform independant
|
if(io.ConfigFlags.HasFlag(.ViewportsEnable))
|
||||||
ImGuiImplDx11.Init(Platform.DX11.DirectX.Device, Platform.DX11.DirectX.ImmediateContext);
|
{
|
||||||
|
style.WindowRounding = 0.0f;
|
||||||
|
style.Colors[(int)ImGui.Col.WindowBg].w = 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
//ImGui.Dock
|
||||||
|
|
||||||
|
#if GE_WINDOWS
|
||||||
|
// Todo: temporary, needs to be platform independent
|
||||||
|
ImGuiImplDX11.Init(Platform.DX11.DirectX.Device, Platform.DX11.DirectX.ImmediateContext);
|
||||||
|
ImGuiImplWin32.Init((Windows.HWnd)(int)Application.Get().Window.NativeWindow);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnDetach()
|
public override void OnDetach()
|
||||||
{
|
{
|
||||||
|
ImGuiImplDX11.Shutdown();
|
||||||
|
ImGuiImplWin32.Shutdown();
|
||||||
|
ImGui.DestroyContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnEvent(Event event)
|
public override void OnEvent(Event event)
|
||||||
@@ -61,9 +54,9 @@ namespace GlitchyEngine.ImGui
|
|||||||
|
|
||||||
dispatcher.Dispatch<WindowResizeEvent>(scope (e) =>
|
dispatcher.Dispatch<WindowResizeEvent>(scope (e) =>
|
||||||
{
|
{
|
||||||
ref ImGui.IO io = ref ImGui.GetIO();
|
//ref ImGui.IO io = ref ImGui.GetIO();
|
||||||
io.DisplaySize = .(e.Width, e.Height);
|
//io.DisplaySize = .(e.Width, e.Height);
|
||||||
io.DisplayFramebufferScale = .(1.0f, 1.0f);
|
//io.DisplayFramebufferScale = .(1.0f, 1.0f);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
@@ -150,32 +143,50 @@ namespace GlitchyEngine.ImGui
|
|||||||
dispatcher.Dispatch<KeyTypedEvent>(scope (e) =>
|
dispatcher.Dispatch<KeyTypedEvent>(scope (e) =>
|
||||||
{
|
{
|
||||||
ref ImGui.IO io = ref ImGui.GetIO();
|
ref ImGui.IO io = ref ImGui.GetIO();
|
||||||
io.AddInputCharacterUTF16((int16)e.Char);
|
io.AddInputCharacterUTF16((uint16)e.Char);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool showDemo = true;
|
public void Begin()
|
||||||
public override void Update(GameTime gameTime)
|
|
||||||
{
|
{
|
||||||
var v = DirectX.ImmediateContext;
|
var v = DirectX.ImmediateContext;
|
||||||
|
|
||||||
v.OutputMerger.SetRenderTargets(1, &DirectX.BackBufferTarget, null);
|
v.OutputMerger.SetRenderTargets(1, &DirectX.BackBufferTarget, null);
|
||||||
|
|
||||||
|
ImGuiImplDX11.NewFrame();
|
||||||
|
ImGuiImplWin32.NewFrame();
|
||||||
|
ImGui.NewFrame();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool showDemo = true;
|
||||||
|
public void ImGuiRender()
|
||||||
|
{
|
||||||
|
Begin();
|
||||||
|
|
||||||
|
var event = scope ImGuiRenderEvent();
|
||||||
|
Application.Get().OnEvent(event);
|
||||||
|
|
||||||
|
ImGui.ShowDemoWindow(&showDemo);
|
||||||
|
|
||||||
|
End();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void End()
|
||||||
|
{
|
||||||
ref ImGui.IO io = ref ImGui.GetIO();
|
ref ImGui.IO io = ref ImGui.GetIO();
|
||||||
|
|
||||||
let window = Application.Get().Window;
|
let window = Application.Get().Window;
|
||||||
io.DisplaySize = .(window.Width, window.Height);
|
io.DisplaySize = .(window.Width, window.Height);
|
||||||
io.DeltaTime = (float)gameTime.FrameTime.TotalSeconds;
|
|
||||||
|
|
||||||
ImGuiImplDx11.NewFrame();
|
|
||||||
ImGui.NewFrame();
|
|
||||||
|
|
||||||
ImGui.ShowDemoWindow(&showDemo);
|
|
||||||
|
|
||||||
ImGui.Render();
|
ImGui.Render();
|
||||||
ImGuiImplDx11.RenderDrawData(ImGui.GetDrawData());
|
ImGuiImplDX11.RenderDrawData(ref ImGui.GetDrawData());
|
||||||
|
|
||||||
|
if(io.ConfigFlags.HasFlag(.ViewportsEnable))
|
||||||
|
{
|
||||||
|
ImGui.UpdatePlatformWindows();
|
||||||
|
ImGui.RenderPlatformWindowsDefault();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
using GlitchyEngine.Events;
|
||||||
|
|
||||||
|
namespace GlitchyEngine.Events
|
||||||
|
{
|
||||||
|
extension EventType
|
||||||
|
{
|
||||||
|
case ImGuiRender;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace GlitchyEngine.ImGui
|
||||||
|
{
|
||||||
|
public class ImGuiRenderEvent : Event, IEvent
|
||||||
|
{
|
||||||
|
public override EventType EventType => .ImGuiRender;
|
||||||
|
|
||||||
|
public override EventCategory Category => .Application;
|
||||||
|
|
||||||
|
public override System.StringView Name => "ImGuiRender";
|
||||||
|
|
||||||
|
public static EventType StaticType => .ImGuiRender;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -59,11 +59,19 @@ namespace GlitchyEngine.Platform.DX11
|
|||||||
Log.EngineLogger.Trace("D3D11 Device and Context created (Feature level: {})", deviceLevel);
|
Log.EngineLogger.Trace("D3D11 Device and Context created (Feature level: {})", deviceLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint32 _width, _height;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the swapchain.
|
* Initializes the swapchain.
|
||||||
*/
|
*/
|
||||||
public static void UpdateSwapchain(uint32 width, uint32 height)
|
public static void UpdateSwapchain(uint32 width, uint32 height)
|
||||||
{
|
{
|
||||||
|
if(_width == width && _height == height)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_width = width;
|
||||||
|
_height = height;
|
||||||
|
|
||||||
Log.EngineLogger.Trace("Updating swap chain ({}, {})", width, height);
|
Log.EngineLogger.Trace("Updating swap chain ({}, {})", width, height);
|
||||||
|
|
||||||
uint32 backBufferCount = 2;
|
uint32 backBufferCount = 2;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ using GlitchLog;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using GlitchyEngine.Platform.Windows;
|
using GlitchyEngine.Platform.Windows;
|
||||||
|
|
||||||
using imgui_beef;
|
//using imgui_beef;
|
||||||
|
|
||||||
namespace GlitchyEngine
|
namespace GlitchyEngine
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,3 +5,6 @@ Dependencies = {GlitchyEngine = "*", corlib = "*"}
|
|||||||
Name = "Sandbox"
|
Name = "Sandbox"
|
||||||
TargetType = "BeefGUIApplication"
|
TargetType = "BeefGUIApplication"
|
||||||
StartupObject = "GlitchyEngine.Program"
|
StartupObject = "GlitchyEngine.Program"
|
||||||
|
|
||||||
|
[Configs.Debug.Win64]
|
||||||
|
CLibType = "DynamicDebug"
|
||||||
|
|||||||
@@ -21,6 +21,19 @@ namespace Sandbox
|
|||||||
public override void OnEvent(Event event)
|
public override void OnEvent(Event event)
|
||||||
{
|
{
|
||||||
Log.ClientLogger.Trace("{}", event);
|
Log.ClientLogger.Trace("{}", event);
|
||||||
|
|
||||||
|
EventDispatcher dispatcher = scope EventDispatcher(event);
|
||||||
|
|
||||||
|
dispatcher.Dispatch<ImGuiRenderEvent>(scope (e) => OnImGuiRender(e));
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool OnImGuiRender(ImGuiRenderEvent e)
|
||||||
|
{
|
||||||
|
ImGui.ImGui.Begin("Test");
|
||||||
|
|
||||||
|
ImGui.ImGui.End();
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user