diff --git a/GlitchyEngine/src/Application.bf b/GlitchyEngine/src/Application.bf index 549e8cc..999a33a 100644 --- a/GlitchyEngine/src/Application.bf +++ b/GlitchyEngine/src/Application.bf @@ -33,7 +33,7 @@ namespace GlitchyEngine _window.EventCallback = new => OnEvent; _imGuiLayer = new ImGuiLayer(); - PushLayer(_imGuiLayer); + PushOverlay(_imGuiLayer); } public void OnEvent(Event e) diff --git a/GlitchyEngine/src/ImGui/ImGuiLayer.bf b/GlitchyEngine/src/ImGui/ImGuiLayer.bf index 22d6e05..84f0ec7 100644 --- a/GlitchyEngine/src/ImGui/ImGuiLayer.bf +++ b/GlitchyEngine/src/ImGui/ImGuiLayer.bf @@ -13,6 +13,7 @@ namespace GlitchyEngine.ImGui public override void OnAttach() { + ImGuiImplWin32.EnableDpiAwareness(); Log.EngineLogger.Trace("Initializing ImGui..."); ImGui.CHECKVERSION(); @@ -24,8 +25,12 @@ namespace GlitchyEngine.ImGui io.ConfigFlags |= .DockingEnable; io.ConfigFlags |= .ViewportsEnable; - ref ImGui.Style style = ref ImGui.GetStyle(); + // Todo: currently broken in ImGui + //io.ConfigFlags |= .DpiEnableScaleFonts; + //io.ConfigFlags |= .DpiEnableScaleViewports; + // When viewports are enabled we tweak WindowRounding/WindowBg so platform windows can look identical to regular ones. + ref ImGui.Style style = ref ImGui.GetStyle(); if(io.ConfigFlags.HasFlag(.ViewportsEnable)) { style.WindowRounding = 0.0f; @@ -36,8 +41,8 @@ namespace GlitchyEngine.ImGui #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); + ImGuiImplDX11.Init(Platform.DX11.DirectX.Device, Platform.DX11.DirectX.ImmediateContext); #endif } diff --git a/GlitchyEngine/src/LayerStack.bf b/GlitchyEngine/src/LayerStack.bf index 1190201..5750eb5 100644 --- a/GlitchyEngine/src/LayerStack.bf +++ b/GlitchyEngine/src/LayerStack.bf @@ -4,7 +4,16 @@ namespace GlitchyEngine { public class LayerStack { - private List _layers = new List() ~ DeleteContainerAndItems!(_); + private List _layers = new List() ~ delete _; + + public ~this() + { + for(let layer in _layers) + { + layer.OnDetach(); + delete layer; + } + } /* * Marks the index of the last layer. diff --git a/GlitchyEngine/src/Platform/Windows/WindowsWindow.bf b/GlitchyEngine/src/Platform/Windows/WindowsWindow.bf index d255631..eec664c 100644 --- a/GlitchyEngine/src/Platform/Windows/WindowsWindow.bf +++ b/GlitchyEngine/src/Platform/Windows/WindowsWindow.bf @@ -16,6 +16,8 @@ namespace GlitchyEngine /// The windows specific Window implementation public extension Window { + const String WindowClassName = "GlitchyEngineWindow"; + private Windows.HInstance _instanceHandle; private Windows.HWnd _windowHandle; @@ -152,6 +154,14 @@ namespace GlitchyEngine Init(desc); } + + [LinkName("UnregisterClassW")] + static extern Windows.IntBool UnregisterClass(char16* className, Windows.HInstance hInstance); + + public ~this() + { + UnregisterClass(WindowClassName.ToScopedNativeWChar!(), _instanceHandle); + } private void Init(WindowDescription desc) { @@ -171,7 +181,7 @@ namespace GlitchyEngine _windowClass.Cursor = LoadCursorW(0, IDC_ARROW); _windowClass.BackgroundBrush = (HBRUSH)SystemColor.WindowFrame; - _windowClass.ClassName = "GlitchyEngineWindow".ToScopedNativeWChar!(); + _windowClass.ClassName = WindowClassName.ToScopedNativeWChar!(); if (RegisterClassExW(ref _windowClass) == 0) { diff --git a/Sandbox/src/SandboxApp.bf b/Sandbox/src/SandboxApp.bf index 1e5d7e7..ad63efb 100644 --- a/Sandbox/src/SandboxApp.bf +++ b/Sandbox/src/SandboxApp.bf @@ -42,7 +42,6 @@ namespace Sandbox public this() { PushLayer(new ExampleLayer()); - PushOverlay(new ImGuiLayer()); } [Export, LinkName("CreateApplication")]