From 7cbb74572180674b8a6f363335c28f02d7486bfb Mon Sep 17 00:00:00 2001 From: max Date: Fri, 5 Jul 2024 23:22:11 +0200 Subject: [PATCH] fix library and input --- Nerfed.Runtime/Gui/Controller.cs | 101 ++++++++++++------------------- libs/x64/cimgui.dll | 4 +- 2 files changed, 42 insertions(+), 63 deletions(-) diff --git a/Nerfed.Runtime/Gui/Controller.cs b/Nerfed.Runtime/Gui/Controller.cs index 6d4990d..b9a5b72 100644 --- a/Nerfed.Runtime/Gui/Controller.cs +++ b/Nerfed.Runtime/Gui/Controller.cs @@ -66,6 +66,7 @@ public Controller(GraphicsDevice graphicsDevice, Window mainWindow, Color clearC UniformBufferCount = 1, }; imGuiVertexShader = new Shader(graphicsDevice, Path.Combine(shaderContentPath, "imgui-vertex.spv"), "main", in vertexCreateInfo); + ShaderCreateInfo fragCreateInfo = new ShaderCreateInfo { ShaderStage = ShaderStage.Fragment, ShaderFormat = ShaderFormat.SPIRV, @@ -204,46 +205,46 @@ private void UpdateInput() io.MouseWheel = Mouse.GetWheel(); - //io.AddKeyEvent(ImGuiKey.A, Keyboard.IsKeyDown(Key.A)); - //io.AddKeyEvent(ImGuiKey.Z, Keyboard.IsKeyDown(Key.Z)); - //io.AddKeyEvent(ImGuiKey.Y, Keyboard.IsKeyDown(Key.Y)); - //io.AddKeyEvent(ImGuiKey.X, Keyboard.IsKeyDown(Key.X)); - //io.AddKeyEvent(ImGuiKey.C, Keyboard.IsKeyDown(Key.C)); - //io.AddKeyEvent(ImGuiKey.V, Keyboard.IsKeyDown(Key.V)); + io.AddKeyEvent(ImGuiKey.A, Keyboard.IsKeyDown(Key.A)); + io.AddKeyEvent(ImGuiKey.Z, Keyboard.IsKeyDown(Key.Z)); + io.AddKeyEvent(ImGuiKey.Y, Keyboard.IsKeyDown(Key.Y)); + io.AddKeyEvent(ImGuiKey.X, Keyboard.IsKeyDown(Key.X)); + io.AddKeyEvent(ImGuiKey.C, Keyboard.IsKeyDown(Key.C)); + io.AddKeyEvent(ImGuiKey.V, Keyboard.IsKeyDown(Key.V)); - //io.AddKeyEvent(ImGuiKey.Tab, Keyboard.IsKeyDown(Key.Tab)); - //io.AddKeyEvent(ImGuiKey.LeftArrow, Keyboard.IsKeyDown(Key.Left)); - //io.AddKeyEvent(ImGuiKey.RightArrow, Keyboard.IsKeyDown(Key.Right)); - //io.AddKeyEvent(ImGuiKey.UpArrow, Keyboard.IsKeyDown(Key.Up)); - //io.AddKeyEvent(ImGuiKey.DownArrow, Keyboard.IsKeyDown(Key.Down)); - //io.AddKeyEvent(ImGuiKey.Enter, Keyboard.IsKeyDown(Key.Enter)); - //io.AddKeyEvent(ImGuiKey.Escape, Keyboard.IsKeyDown(Key.Escape)); - //io.AddKeyEvent(ImGuiKey.Delete, Keyboard.IsKeyDown(Key.Delete)); - //io.AddKeyEvent(ImGuiKey.Backspace, Keyboard.IsKeyDown(Key.Backspace)); - //io.AddKeyEvent(ImGuiKey.Home, Keyboard.IsKeyDown(Key.Home)); - //io.AddKeyEvent(ImGuiKey.End, Keyboard.IsKeyDown(Key.End)); - //io.AddKeyEvent(ImGuiKey.PageDown, Keyboard.IsKeyDown(Key.PageDown)); - //io.AddKeyEvent(ImGuiKey.PageUp, Keyboard.IsKeyDown(Key.PageUp)); - //io.AddKeyEvent(ImGuiKey.Insert, Keyboard.IsKeyDown(Key.Insert)); + io.AddKeyEvent(ImGuiKey.Tab, Keyboard.IsKeyDown(Key.Tab)); + io.AddKeyEvent(ImGuiKey.LeftArrow, Keyboard.IsKeyDown(Key.Left)); + io.AddKeyEvent(ImGuiKey.RightArrow, Keyboard.IsKeyDown(Key.Right)); + io.AddKeyEvent(ImGuiKey.UpArrow, Keyboard.IsKeyDown(Key.Up)); + io.AddKeyEvent(ImGuiKey.DownArrow, Keyboard.IsKeyDown(Key.Down)); + io.AddKeyEvent(ImGuiKey.Enter, Keyboard.IsKeyDown(Key.Enter)); + io.AddKeyEvent(ImGuiKey.Escape, Keyboard.IsKeyDown(Key.Escape)); + io.AddKeyEvent(ImGuiKey.Delete, Keyboard.IsKeyDown(Key.Delete)); + io.AddKeyEvent(ImGuiKey.Backspace, Keyboard.IsKeyDown(Key.Backspace)); + io.AddKeyEvent(ImGuiKey.Home, Keyboard.IsKeyDown(Key.Home)); + io.AddKeyEvent(ImGuiKey.End, Keyboard.IsKeyDown(Key.End)); + io.AddKeyEvent(ImGuiKey.PageDown, Keyboard.IsKeyDown(Key.PageDown)); + io.AddKeyEvent(ImGuiKey.PageUp, Keyboard.IsKeyDown(Key.PageUp)); + io.AddKeyEvent(ImGuiKey.Insert, Keyboard.IsKeyDown(Key.Insert)); - //io.AddKeyEvent(ImGuiKey.ModCtrl, Keyboard.IsKeyDown(Key.LeftControl) || Keyboard.IsKeyDown(Key.RightControl)); - //io.AddKeyEvent(ImGuiKey.ModShift, Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift)); - //io.AddKeyEvent(ImGuiKey.ModAlt, Keyboard.IsKeyDown(Key.LeftAlt) || Keyboard.IsKeyDown(Key.RightAlt)); - //io.AddKeyEvent(ImGuiKey.ModSuper, Keyboard.IsKeyDown(Key.LeftSuper) || Keyboard.IsKeyDown(Key.RightSuper)); + io.AddKeyEvent(ImGuiKey.ModCtrl, Keyboard.IsKeyDown(Key.LeftControl) || Keyboard.IsKeyDown(Key.RightControl)); + io.AddKeyEvent(ImGuiKey.ModShift, Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift)); + io.AddKeyEvent(ImGuiKey.ModAlt, Keyboard.IsKeyDown(Key.LeftAlt) || Keyboard.IsKeyDown(Key.RightAlt)); + io.AddKeyEvent(ImGuiKey.ModSuper, Keyboard.IsKeyDown(Key.LeftSuper) || Keyboard.IsKeyDown(Key.RightSuper)); - //ReadOnlySpan input = Keyboard.GetTextInput(); - //if (!input.IsEmpty) - //{ - // foreach (char c in input) - // { - // if (c == '\t') - // { - // break; - // } + ReadOnlySpan input = Keyboard.GetTextInput(); + if (!input.IsEmpty) + { + foreach (char c in input) + { + if (c == '\t') + { + break; + } - // io.AddInputCharacter(c); - // } - //} + io.AddInputCharacter(c); + } + } } private unsafe void UpdateMonitors() @@ -505,32 +506,8 @@ private void CreateWindow(ImGuiViewportPtr vp) { WindowCreateInfo info = new WindowCreateInfo("Window Title", (uint)vp.Pos.X, (uint)vp.Pos.Y, ScreenMode.Windowed); - //SDL2.SDL.SDL_WindowFlags flags = graphicsDevice.WindowFlags; - //flags |= SDL2.SDL.SDL_WindowFlags.SDL_WINDOW_HIDDEN; - - //if ((vp.Flags & ImGuiViewportFlags.NoTaskBarIcon) != 0) - //{ - // flags |= SDL2.SDL.SDL_WindowFlags.SDL_WINDOW_SKIP_TASKBAR; - //} - - //if ((vp.Flags & ImGuiViewportFlags.NoDecoration) != 0) - //{ - // flags |= SDL2.SDL.SDL_WindowFlags.SDL_WINDOW_BORDERLESS; - // info.SystemResizable = false; - //} - //else - //{ - // flags |= SDL2.SDL.SDL_WindowFlags.SDL_WINDOW_RESIZABLE; - // info.SystemResizable = true; - //} - - //if ((vp.Flags & ImGuiViewportFlags.TopMost) != 0) - //{ - // flags |= SDL2.SDL.SDL_WindowFlags.SDL_WINDOW_ALWAYS_ON_TOP; - //} - Window window = new Window(graphicsDevice, info); - graphicsDevice.ClaimWindow(window, SwapchainComposition.SDR, PresentMode.Immediate); + graphicsDevice.ClaimWindow(window, SwapchainComposition.SDR, PresentMode.Immediate); // What PresentMode do we need? GCHandle handle = GCHandle.Alloc(window); vp.PlatformUserData = (IntPtr)handle; @@ -652,6 +629,8 @@ public void Dispose() foreach (KeyValuePair window in windows) { + if (window.Key == mainWindow) continue; + graphicsDevice.UnclaimWindow(window.Key); window.Key.Dispose(); window.Value.Free(); diff --git a/libs/x64/cimgui.dll b/libs/x64/cimgui.dll index 94c3de9..3f2319a 100644 --- a/libs/x64/cimgui.dll +++ b/libs/x64/cimgui.dll @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c1c7185401fdc2e008a4bf04ea6c667811f8f06b7fb3d33c18ef7ca983641e27 -size 1204224 +oid sha256:af446d0eeda59d2b36638fa4a6449491473724860f6e78b1f5cca65d228c8094 +size 1225216