gui events

fix scroll input
handle gui side, move and closed events
This commit is contained in:
max
2024-07-06 01:29:12 +02:00
parent 7cbb745721
commit 1eb899b240
5 changed files with 73 additions and 32 deletions

View File

@ -113,7 +113,7 @@ internal class Controller : IDisposable
mainViewport.PlatformHandle = mainWindow.Handle;
GCHandle handle = GCHandle.Alloc(mainWindow);
mainViewport.PlatformUserData = (IntPtr)handle;
windows.Add(mainWindow, handle);
AddWindow(mainWindow, mainViewport, handle);
unsafe
{
@ -504,7 +504,11 @@ internal class Controller : IDisposable
#region Window
private void CreateWindow(ImGuiViewportPtr vp)
{
WindowCreateInfo info = new WindowCreateInfo("Window Title", (uint)vp.Pos.X, (uint)vp.Pos.Y, ScreenMode.Windowed);
// TODO: Handle all flags.
ScreenMode screenMode = vp.Flags.HasFlag(ImGuiViewportFlags.NoDecoration) ? ScreenMode.WindowedBorderless : ScreenMode.Windowed;
bool systemResizable = !vp.Flags.HasFlag(ImGuiViewportFlags.NoDecoration);
WindowCreateInfo info = new WindowCreateInfo("Window Title", (uint)vp.Pos.X, (uint)vp.Pos.Y, screenMode, systemResizable, false);
Window window = new Window(graphicsDevice, info);
graphicsDevice.ClaimWindow(window, SwapchainComposition.SDR, PresentMode.Immediate); // What PresentMode do we need?
@ -512,7 +516,7 @@ internal class Controller : IDisposable
GCHandle handle = GCHandle.Alloc(window);
vp.PlatformUserData = (IntPtr)handle;
windows.Add(window, handle);
AddWindow(window, vp, handle);
}
private void DestroyWindow(ImGuiViewportPtr vp)
@ -528,8 +532,38 @@ internal class Controller : IDisposable
windows.Remove(window);
}
graphicsDevice.Wait();
//graphicsDevice.Wait();
window.Dispose();
vp.PlatformUserData = IntPtr.Zero;
}
private void AddWindow(Window window, ImGuiViewportPtr vp, GCHandle handle)
{
window.OnResizedEvent += ((win, w, h) => {
vp.PlatformRequestResize = true;
});
window.OnMovedEvent += ((win, x, y) =>
{
vp.PlatformRequestMove = true;
});
window.OnCloseEvent += (win) =>
{
ImGuiPlatformIOPtr platformIO = ImGui.GetPlatformIO();
for (int i = 0; i < platformIO.Viewports.Capacity; i++)
{
ImGuiViewportPtr vp = platformIO.Viewports[i];
if(win == (Window)GCHandle.FromIntPtr(vp.PlatformUserData).Target)
{
DestroyWindow(vp);
}
}
};
windows.Add(window, handle);
}
private void ShowWindow(ImGuiViewportPtr vp)