/// <summary> /// Constructs a new ImGuiController. /// </summary> public ImGuiController(GraphicsDevice gd, OutputDescription outputDescription, WindowBase window) { #if DEBUG using Profiler fullProfiler = new Profiler(GetType()); #endif mainWindow = window; Sdl2Window sdlWindow = window.SdlWindow; windowWidth = sdlWindow.Width; windowHeight = sdlWindow.Height; ImPlot.CreateContext(); ImNodes.Initialize(); IntPtr imguiCtx = ImGui.CreateContext(); ImGui.SetCurrentContext(imguiCtx); ImPlot.SetImGuiContext(imguiCtx); ImNodes.SetImGuiContext(imguiCtx); ImGuizmo.SetImGuiContext(imguiCtx); ImGui.StyleColorsDark(); CreateDeviceResources(gd, outputDescription); SetupImGuiIo(sdlWindow); SetImGuiKeyMappings(); SetPerFrameImGuiData(1f / 60); }
/// <summary> /// Constructs a new ImGuiController. /// </summary> public unsafe ImGuiController(GraphicsDevice gd, Sdl2Window window, OutputDescription outputDescription, int width, int height) { _gd = gd; _window = window; _windowWidth = width; _windowHeight = height; //Create ImGui Context var context = ImGui.CreateContext(); ImGui.SetCurrentContext(context); //Create ImPlot Context ImPlot.SetImGuiContext(context); ImPlot.CreateContext(); //Create ImNodes Context imnodes.SetImGuiContext(context); imnodes.Initialize(); //Create ImGuizmo Context ImGuizmo.SetImGuiContext(context); ImGuiIOPtr io = ImGui.GetIO(); io.ConfigFlags |= ImGuiConfigFlags.DockingEnable; io.ConfigFlags |= ImGuiConfigFlags.ViewportsEnable; io.ConfigFlags |= ImGuiConfigFlags.NavEnableKeyboard; io.ConfigFlags |= ImGuiConfigFlags.NavEnableGamepad; ImGuiPlatformIOPtr platformIo = ImGui.GetPlatformIO(); ImGuiViewportPtr mainViewport = platformIo.Viewports[0]; mainViewport.PlatformHandle = window.Handle; _mainViewportWindow = new VeldridImGuiWindow(gd, mainViewport, _window); _createWindow = CreateWindow; _destroyWindow = DestroyWindow; _getWindowPos = GetWindowPos; _showWindow = ShowWindow; _setWindowPos = SetWindowPos; _setWindowSize = SetWindowSize; _getWindowSize = GetWindowSize; _setWindowFocus = SetWindowFocus; _getWindowFocus = GetWindowFocus; _getWindowMinimized = GetWindowMinimized; _setWindowTitle = SetWindowTitle; platformIo.Platform_CreateWindow = Marshal.GetFunctionPointerForDelegate(_createWindow); platformIo.Platform_DestroyWindow = Marshal.GetFunctionPointerForDelegate(_destroyWindow); platformIo.Platform_ShowWindow = Marshal.GetFunctionPointerForDelegate(_showWindow); platformIo.Platform_SetWindowPos = Marshal.GetFunctionPointerForDelegate(_setWindowPos); platformIo.Platform_SetWindowSize = Marshal.GetFunctionPointerForDelegate(_setWindowSize); platformIo.Platform_SetWindowFocus = Marshal.GetFunctionPointerForDelegate(_setWindowFocus); platformIo.Platform_GetWindowFocus = Marshal.GetFunctionPointerForDelegate(_getWindowFocus); platformIo.Platform_GetWindowMinimized = Marshal.GetFunctionPointerForDelegate(_getWindowMinimized); platformIo.Platform_SetWindowTitle = Marshal.GetFunctionPointerForDelegate(_setWindowTitle); ImGuiNative.ImGuiPlatformIO_Set_Platform_GetWindowPos(platformIo.NativePtr, Marshal.GetFunctionPointerForDelegate(_getWindowPos)); ImGuiNative.ImGuiPlatformIO_Set_Platform_GetWindowSize(platformIo.NativePtr, Marshal.GetFunctionPointerForDelegate(_getWindowSize)); unsafe { io.NativePtr->BackendPlatformName = (byte *)new FixedAsciiString("Veldrid.SDL2 Backend").DataPtr; } io.BackendFlags |= ImGuiBackendFlags.HasMouseCursors; io.BackendFlags |= ImGuiBackendFlags.HasSetMousePos; io.BackendFlags |= ImGuiBackendFlags.PlatformHasViewports; io.BackendFlags |= ImGuiBackendFlags.RendererHasViewports; io.Fonts.AddFontDefault(); CreateDeviceResources(gd, outputDescription); SetKeyMappings(); SetPerFrameImGuiData(1f / 60f); UpdateMonitors(); ImGui.NewFrame(); _frameBegun = true; }