mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
ImGuiLayer cleanup
This commit is contained in:
@@ -8,6 +8,7 @@ using internal ImGui;
|
|||||||
#if GE_GRAPHICS_DX11
|
#if GE_GRAPHICS_DX11
|
||||||
|
|
||||||
using GlitchyEngine.Platform.DX11;
|
using GlitchyEngine.Platform.DX11;
|
||||||
|
using GlitchyEngine.Renderer;
|
||||||
using internal GlitchyEngine.Platform.DX11;
|
using internal GlitchyEngine.Platform.DX11;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -16,6 +17,8 @@ namespace GlitchyEngine.ImGui
|
|||||||
{
|
{
|
||||||
public class ImGuiLayer : Layer
|
public class ImGuiLayer : Layer
|
||||||
{
|
{
|
||||||
|
ImGui.IO* _io;
|
||||||
|
|
||||||
public this() : base("ImGuiLayer") { }
|
public this() : base("ImGuiLayer") { }
|
||||||
|
|
||||||
public override void OnAttach()
|
public override void OnAttach()
|
||||||
@@ -29,10 +32,10 @@ namespace GlitchyEngine.ImGui
|
|||||||
ImGui.CreateContext();
|
ImGui.CreateContext();
|
||||||
ImGui.StyleColorsDark();
|
ImGui.StyleColorsDark();
|
||||||
|
|
||||||
ImGui.IO* io = ImGui.GetIO();
|
_io = ImGui.GetIO();
|
||||||
io.ConfigFlags |= .NavEnableKeyboard;
|
_io.ConfigFlags |= .NavEnableKeyboard;
|
||||||
io.ConfigFlags |= .DockingEnable;
|
_io.ConfigFlags |= .DockingEnable;
|
||||||
io.ConfigFlags |= .ViewportsEnable;
|
_io.ConfigFlags |= .ViewportsEnable;
|
||||||
|
|
||||||
// Todo: currently broken in ImGui
|
// Todo: currently broken in ImGui
|
||||||
//io.ConfigFlags |= .DpiEnableScaleFonts;
|
//io.ConfigFlags |= .DpiEnableScaleFonts;
|
||||||
@@ -40,15 +43,14 @@ namespace GlitchyEngine.ImGui
|
|||||||
|
|
||||||
// When viewports are enabled we tweak WindowRounding/WindowBg so platform windows can look identical to regular ones.
|
// When viewports are enabled we tweak WindowRounding/WindowBg so platform windows can look identical to regular ones.
|
||||||
ImGui.Style* style = ImGui.GetStyle();
|
ImGui.Style* style = ImGui.GetStyle();
|
||||||
if(io.ConfigFlags.HasFlag(.ViewportsEnable))
|
if(_io.ConfigFlags.HasFlag(.ViewportsEnable))
|
||||||
{
|
{
|
||||||
style.WindowRounding = 0.0f;
|
style.WindowRounding = 0.0f;
|
||||||
style.Colors[(int)ImGui.Col.WindowBg].w = 1.0f;
|
style.Colors[(int)ImGui.Col.WindowBg].w = 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if BF_PLATFORM_WINDOWS
|
#if BF_PLATFORM_WINDOWS
|
||||||
// Todo: temporary, needs to be platform independent
|
ImGuiImplWin32.Init(Application.Get().Window.NativeWindow);
|
||||||
ImGuiImplWin32.Init((void*)(uint)(Windows.HWnd)(int)Application.Get().Window.NativeWindow);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if GE_GRAPHICS_DX11
|
#if GE_GRAPHICS_DX11
|
||||||
@@ -59,149 +61,28 @@ namespace GlitchyEngine.ImGui
|
|||||||
public override void OnDetach()
|
public override void OnDetach()
|
||||||
{
|
{
|
||||||
Debug.Profiler.ProfileFunction!();
|
Debug.Profiler.ProfileFunction!();
|
||||||
|
|
||||||
|
#if GE_GRAPHICS_DX11
|
||||||
ImGuiImplDX11.Shutdown();
|
ImGuiImplDX11.Shutdown();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if BF_PLATFORM_WINDOWS
|
||||||
ImGuiImplWin32.Shutdown();
|
ImGuiImplWin32.Shutdown();
|
||||||
|
#endif
|
||||||
|
|
||||||
ImGui.DestroyContext();
|
ImGui.DestroyContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnEvent(Event event)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
EventDispatcher dispatcher = scope EventDispatcher(event);
|
|
||||||
|
|
||||||
dispatcher.Dispatch<WindowResizeEvent>(scope (e) =>
|
|
||||||
{
|
|
||||||
//ref ImGui.IO io = ref ImGui.GetIO();
|
|
||||||
//io.DisplaySize = .(e.Width, e.Height);
|
|
||||||
//io.DisplayFramebufferScale = .(1.0f, 1.0f);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
dispatcher.Dispatch<MouseMovedEvent>(scope (e) =>
|
|
||||||
{
|
|
||||||
ref ImGui.IO io = ref ImGui.GetIO();
|
|
||||||
io.MousePos = ImGui.Vec2(e.PositionX, e.PositionY);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
dispatcher.Dispatch<MouseButtonPressedEvent>(scope (e) =>
|
|
||||||
{
|
|
||||||
int button = 0;
|
|
||||||
switch(e.MouseButton)
|
|
||||||
{
|
|
||||||
case .LeftButton:
|
|
||||||
button = (uint)ImGui.MouseButton.Left;
|
|
||||||
case .RightButton:
|
|
||||||
button = (uint)ImGui.MouseButton.Right;
|
|
||||||
case .MiddleButton:
|
|
||||||
button = (uint)ImGui.MouseButton.Middle;
|
|
||||||
case .XButton1:
|
|
||||||
button = (uint)3;
|
|
||||||
case .XButton2:
|
|
||||||
button = (uint)4;
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
|
|
||||||
ref ImGui.IO io = ref ImGui.GetIO();
|
|
||||||
io.MouseDown[button] = true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
dispatcher.Dispatch<MouseButtonReleasedEvent>(scope (e) =>
|
|
||||||
{
|
|
||||||
int button = 0;
|
|
||||||
switch(e.MouseButton)
|
|
||||||
{
|
|
||||||
case .LeftButton:
|
|
||||||
button = (uint)ImGui.MouseButton.Left;
|
|
||||||
case .RightButton:
|
|
||||||
button = (uint)ImGui.MouseButton.Right;
|
|
||||||
case .MiddleButton:
|
|
||||||
button = (uint)ImGui.MouseButton.Middle;
|
|
||||||
case .XButton1:
|
|
||||||
button = (uint)3;
|
|
||||||
case .XButton2:
|
|
||||||
button = (uint)4;
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
|
|
||||||
ref ImGui.IO io = ref ImGui.GetIO();
|
|
||||||
io.MouseDown[button] = false;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
dispatcher.Dispatch<MouseScrolledEvent>(scope (e) =>
|
|
||||||
{
|
|
||||||
ref ImGui.IO io = ref ImGui.GetIO();
|
|
||||||
io.MouseWheel += e.YOffset;
|
|
||||||
io.MouseWheelH += e.XOffset; // Todo: horizontal mousewheel inverted?!
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
dispatcher.Dispatch<KeyPressedEvent>(scope (e) =>
|
|
||||||
{
|
|
||||||
if(e.KeyCode >= (.)256)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
ref ImGui.IO io = ref ImGui.GetIO();
|
|
||||||
io.KeysDown[(int32)e.KeyCode] = true;
|
|
||||||
|
|
||||||
io.KeyCtrl = io.KeysDown[(int32)Key.Control];
|
|
||||||
io.KeyShift = io.KeysDown[(int32)Key.Shift];
|
|
||||||
io.KeyAlt = io.KeysDown[(int32)Key.Alt];
|
|
||||||
io.KeySuper = io.KeysDown[(int32)Key.LeftSuper] || io.KeysDown[(int32)Key.RightSuper];
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
dispatcher.Dispatch<KeyReleasedEvent>(scope (e) =>
|
|
||||||
{
|
|
||||||
if(e.KeyCode >= (.)256)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
ref ImGui.IO io = ref ImGui.GetIO();
|
|
||||||
io.KeysDown[(int32)e.KeyCode] = false;
|
|
||||||
|
|
||||||
io.KeyCtrl = io.KeysDown[(int32)Key.Control];
|
|
||||||
io.KeyShift = io.KeysDown[(int32)Key.Shift];
|
|
||||||
io.KeyAlt = io.KeysDown[(int32)Key.Alt];
|
|
||||||
io.KeySuper = io.KeysDown[(int32)Key.LeftSuper] || io.KeysDown[(int32)Key.RightSuper];
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
dispatcher.Dispatch<KeyTypedEvent>(scope (e) =>
|
|
||||||
{
|
|
||||||
ref ImGui.IO io = ref ImGui.GetIO();
|
|
||||||
io.AddInputCharacterUTF16((uint16)e.Char);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Begin()
|
public void Begin()
|
||||||
{
|
{
|
||||||
Debug.Profiler.ProfileFunction!();
|
Debug.Profiler.ProfileFunction!();
|
||||||
|
|
||||||
// Todo:
|
|
||||||
//var v = DirectX.ImmediateContext;
|
|
||||||
//v.OutputMerger.SetRenderTargets(1, &DirectX.BackBufferTarget, null);
|
|
||||||
Application.Get().Window.Context.SetRenderTarget(null);
|
|
||||||
|
|
||||||
ImGuiImplDX11.NewFrame();
|
ImGuiImplDX11.NewFrame();
|
||||||
ImGuiImplWin32.NewFrame();
|
ImGuiImplWin32.NewFrame();
|
||||||
ImGui.NewFrame();
|
ImGui.NewFrame();
|
||||||
ImGuizmo.BeginFrame();
|
ImGuizmo.BeginFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool showDemo = true;
|
|
||||||
public void ImGuiRender()
|
public void ImGuiRender()
|
||||||
{
|
{
|
||||||
Debug.Profiler.ProfileFunction!();
|
Debug.Profiler.ProfileFunction!();
|
||||||
@@ -214,7 +95,6 @@ namespace GlitchyEngine.ImGui
|
|||||||
var event = scope ImGuiRenderEvent();
|
var event = scope ImGuiRenderEvent();
|
||||||
Application.Get().OnEvent(event);
|
Application.Get().OnEvent(event);
|
||||||
}
|
}
|
||||||
//ImGui.ShowDemoWindow(&showDemo);
|
|
||||||
|
|
||||||
End();
|
End();
|
||||||
}
|
}
|
||||||
@@ -223,20 +103,19 @@ namespace GlitchyEngine.ImGui
|
|||||||
{
|
{
|
||||||
Debug.Profiler.ProfileFunction!();
|
Debug.Profiler.ProfileFunction!();
|
||||||
|
|
||||||
ImGui.IO* io = ImGui.GetIO();
|
|
||||||
|
|
||||||
let window = Application.Get().Window;
|
|
||||||
io.DisplaySize = .(window.Width, window.Height);
|
|
||||||
|
|
||||||
ImGui.Render();
|
ImGui.Render();
|
||||||
|
|
||||||
|
RenderCommand.SetDepthStencilTarget(null);
|
||||||
|
RenderCommand.SetRenderTarget(null);
|
||||||
|
RenderCommand.BindRenderTargets();
|
||||||
|
|
||||||
#if GE_GRAPHICS_DX11
|
#if GE_GRAPHICS_DX11
|
||||||
ImGuiImplDX11.RenderDrawData(ImGui.GetDrawData());
|
ImGuiImplDX11.RenderDrawData(ImGui.GetDrawData());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ImGui.CleanupFrame();
|
ImGui.CleanupFrame();
|
||||||
|
|
||||||
if(io.ConfigFlags.HasFlag(.ViewportsEnable))
|
if(_io.ConfigFlags.HasFlag(.ViewportsEnable))
|
||||||
{
|
{
|
||||||
ImGui.UpdatePlatformWindows();
|
ImGui.UpdatePlatformWindows();
|
||||||
ImGui.RenderPlatformWindowsDefault();
|
ImGui.RenderPlatformWindowsDefault();
|
||||||
|
|||||||
Reference in New Issue
Block a user