Exemplo n.º 1
0
        /// <summary>
        /// Renders the ImGui draw list data.
        /// This method requires a <see cref="GraphicsDevice"/> because it may create new DeviceBuffers if the size of vertex
        /// or index data has increased beyond the capacity of the existing buffers.
        /// A <see cref="CommandList"/> is needed to submit drawing and resource update commands.
        /// </summary>
        public void Render(GraphicsDevice gd, CommandList cl)
        {
            if (_frameBegun)
            {
                _frameBegun = false;
                ImGui.Render();
                RenderImDrawData(ImGui.GetDrawData(), gd, cl);

                // Update and Render additional Platform Windows
                if ((ImGui.GetIO().ConfigFlags & ImGuiConfigFlags.ViewportsEnable) != 0)
                {
                    ImGui.UpdatePlatformWindows();
                    ImGuiPlatformIOPtr platformIO = ImGui.GetPlatformIO();
                    for (int i = 1; i < platformIO.Viewports.Size; i++)
                    {
                        ImGuiViewportPtr   vp     = platformIO.Viewports[i];
                        VeldridImGuiWindow?window = (VeldridImGuiWindow?)GCHandle.FromIntPtr(vp.PlatformUserData).Target;
                        if (window == null)
                        {
                            throw new NullReferenceException();
                        }
                        if (window.Swapchain != null)
                        {
                            cl.SetFramebuffer(window.Swapchain.Framebuffer);
                            RenderImDrawData(vp.DrawData, gd, cl);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private unsafe void PlatformCreateWindow(ImGuiViewportPtr viewport)
        {
#if DEBUG
            using Profiler fullProfiler = new Profiler(GetType());
#endif
            SDL_WindowFlags sdlFlags = (Sdl2Native.SDL_GetWindowFlags(mainWindow.SdlWindow.SdlWindowHandle) & SDL_WindowFlags.AllowHighDpi)
                                       | SDL_WindowFlags.Hidden;
            sdlFlags |= ((viewport.Flags & ImGuiViewportFlags.NoDecoration) != 0) ? SDL_WindowFlags.Borderless : SDL_WindowFlags.Resizable;

            if (graphicsDevice.BackendType == GraphicsBackend.OpenGL || graphicsDevice.BackendType == GraphicsBackend.OpenGLES)
            {
                sdlFlags |= SDL_WindowFlags.OpenGL;
            }
            if ((viewport.Flags & ImGuiViewportFlags.TopMost) != 0)
            {
                sdlFlags |= SDL_WindowFlags.AlwaysOnTop;
            }
            //Seems to work
            if ((viewport.Flags & ImGuiViewportFlags.NoTaskBarIcon) != 0)
            {
                sdlFlags |= SDL_WindowFlags.SkipTaskbar;
            }

            Sdl2Window sdlWindow = new Sdl2Window("Viewport", (int)viewport.Pos.X, (int)viewport.Pos.Y,
                                                  (int)viewport.Size.X, (int)viewport.Size.Y, sdlFlags, false);

            sdlWindow.Resized += () => viewport.PlatformRequestResize = true;
            sdlWindow.Moved   += (_) => viewport.PlatformRequestMove = true;
            sdlWindow.Closed  += () => viewport.PlatformRequestClose = true;

            WindowBase newWindow = WindowBase.CreateSubWindow(graphicsDevice, sdlWindow, mainWindow.GetType());

            viewport.PlatformUserData = (IntPtr)newWindow.GcHandle;
            viewport.PlatformHandle   = newWindow.SdlWindow.Handle;
        }
Exemplo n.º 3
0
        private void PlatformSetWindowPosition(ImGuiViewportPtr viewport, Vector2 pos)
        {
            WindowBase window = (WindowBase)GCHandle.FromIntPtr(viewport.PlatformUserData).Target;

            window.SdlWindow.X = (int)pos.X;
            window.SdlWindow.Y = (int)pos.Y;
        }
Exemplo n.º 4
0
        public static void BeginGlobalDocking()
        {
            ImGuiViewportPtr viewport = ImGui.GetMainViewport();

            ImGui.SetNextWindowPos(viewport.Pos);
            ImGui.SetNextWindowSize(viewport.Size);
            ImGui.SetNextWindowViewport(viewport.ID);
            ImGui.SetNextWindowBgAlpha(0.0f);

            ImGuiWindowFlags windowFlags = ImGuiWindowFlags.NoDocking | ImGuiWindowFlags.MenuBar;

            windowFlags |= ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoCollapse;
            windowFlags |= ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoMove;
            windowFlags |= ImGuiWindowFlags.NoBringToFrontOnFocus | ImGuiWindowFlags.NoNavFocus;

            ImGui.PushStyleVar(ImGuiStyleVar.WindowRounding, 0.0f);
            ImGui.PushStyleVar(ImGuiStyleVar.WindowBorderSize, 0.0f);
            ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, System.Numerics.Vector2.Zero);
            ImGui.Begin("imgui-docking", windowFlags);
            ImGui.PopStyleVar(3);

            uint dockspaceID = ImGui.GetID("default-dockspace");
            ImGuiDockNodeFlags dockspaceFlags = ImGuiDockNodeFlags.PassthruCentralNode;

            ImGui.DockSpace(dockspaceID, System.Numerics.Vector2.Zero, dockspaceFlags);
        }
Exemplo n.º 5
0
        private byte GetWindowMinimized(ImGuiViewportPtr vp)
        {
            VeldridImGuiWindow window = (VeldridImGuiWindow)GCHandle.FromIntPtr(vp.PlatformUserData).Target;
            SDL_WindowFlags    flags  = Sdl2Native.SDL_GetWindowFlags(window.Window.SdlWindowHandle);

            return((flags & SDL_WindowFlags.Minimized) != 0 ? (byte)1 : (byte)0);
        }
Exemplo n.º 6
0
        private unsafe void GetWindowSize(ImGuiViewportPtr vp, Vector2 *outSize)
        {
            VeldridImGuiWindow window = (VeldridImGuiWindow)GCHandle.FromIntPtr(vp.PlatformUserData).Target;
            Rectangle          bounds = window.Window.Bounds;

            *outSize = new Vector2(bounds.Width, bounds.Height);
        }
Exemplo n.º 7
0
        public static void ImGui_ImplGlfw_SetWindowTitle(ImGuiViewportPtr viewport, char *title)
        {
            string titleString = Marshal.PtrToStringAnsi(new IntPtr(title));
            var    window      = GetWindow(viewport);

            GLFW.SetWindowTitle(window, titleString);
        }
Exemplo n.º 8
0
        public static void ImGui_ImplGlfw_SwapBuffers(ImGuiViewportPtr viewport, void *_)
        {
            var window = GetWindow(viewport);

            GLFW.MakeContextCurrent(window);
            GLFW.SwapBuffers(window);
        }
Exemplo n.º 9
0
        public static void ImGui_ImplGlfw_SetWindowSize(ImGuiViewportPtr viewport, Vector2 size)
        {
            var data = GetViewportData(viewport);

            data.IgnoreWindowSizeEventFrame = ImGui.GetFrameCount();
            GLFW.SetWindowSize((Window *)data.Window, (int)size.X, (int)size.Y);
        }
Exemplo n.º 10
0
        public static Vector2 ImGui_ImplGlfw_GetWindowSize(ImGuiViewportPtr viewport)
        {
            var window = GetWindow(viewport);

            GLFW.GetWindowSize(window, out int w, out int h);
            return(new Vector2(w, h));
        }
Exemplo n.º 11
0
        public static void ImGui_ImplGlfw_GetWindowPos(out Vector2 position, ImGuiViewportPtr viewport)
        {
            var window = GetWindow(viewport);

            GLFW.GetWindowPos(window, out int x, out int y);
            position = new Vector2(x, y);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Renders the ImGui draw list data.
        /// This method requires a <see cref="GraphicsDevice"/> because it may create new DeviceBuffers if the size of vertex
        /// or index data has increased beyond the capacity of the existing buffers.
        /// A <see cref="CommandList"/> is needed to submit drawing and resource update commands.
        /// </summary>
        public void Render(GraphicsDevice gd, CommandList cl)
        {
#if DEBUG
            using Profiler fullProfiler = new Profiler(GetType());
#endif
            if (frameBegun)
            {
                frameBegun = false;
                ImGui.Render();
                if (!mainWindow.Minimized)
                {
                    RenderImDrawData(ImGui.GetDrawData(), gd, cl);
                }

                // Update and Render additional Platform Windows
                if ((ImGui.GetIO().ConfigFlags & ImGuiConfigFlags.ViewportsEnable) != 0)
                {
                    ImGui.UpdatePlatformWindows();
                    ImGuiPlatformIOPtr platformIO = ImGui.GetPlatformIO();
                    for (int i = 1; i < platformIO.Viewports.Size; i++)
                    {
                        ImGuiViewportPtr vp = platformIO.Viewports[i];
                        if ((vp.Flags & ImGuiViewportFlags.Minimized) == 0)
                        {
                            WindowBase window = (WindowBase)GCHandle.FromIntPtr(vp.PlatformUserData).Target;
                            cl.SetFramebuffer(window.Swapchain.Framebuffer);
                            RenderImDrawData(vp.DrawData, gd, cl);
                        }
                    }
                }
            }
        }
Exemplo n.º 13
0
        void DrawHeader()
        {
            ImGuiIOPtr       io               = ImGui.GetIO();
            ImGuiViewportPtr viewport         = ImGui.GetMainViewport();
            Vector2          work_area_pos    = viewport.GetWorkPos();
            Vector2          work_area_size   = viewport.GetWorkSize();
            Vector2          window_pos       = work_area_pos;
            Vector2          window_pos_pivot = Vector2.Zero;

            ImGui.SetNextWindowPos(window_pos, ImGuiCond.Always, window_pos_pivot);
            work_area_size.Y = 40;
            ImGui.SetNextWindowSize(work_area_size);
            ImGui.SetNextWindowViewport(viewport.ID);

            ImGuiWindowFlags windowFlags = ImGuiWindowFlags.NoDecoration | ImGuiWindowFlags.NoDocking | ImGuiWindowFlags.NoSavedSettings | ImGuiWindowFlags.NoFocusOnAppearing | ImGuiWindowFlags.NoNav | ImGuiWindowFlags.NoMove;
            bool             open        = true;

            if (ImGui.Begin("HeaderBar", ref open, windowFlags))
            {
                ImGui.BeginChild("header");

                ImGui.Text("Left 1"); ImGui.SameLine();
                ImGui.Text("Left 2"); ImGui.SameLine();

                ImGui.EndChild();
                ImGui.End();
            }
        }
Exemplo n.º 14
0
        private void SetWindowPos(ImGuiViewportPtr vp, Vector2 pos)
        {
            VeldridImGuiWindow window = (VeldridImGuiWindow)GCHandle.FromIntPtr(vp.PlatformUserData).Target;

            window.Window.X = (int)pos.X;
            window.Window.Y = (int)pos.Y;
        }
Exemplo n.º 15
0
        public static void ImGui_ImplGlfw_CreateWindow(ImGuiViewportPtr viewport)
        {
            // ImGuiViewportDataGlfw* data = CreateViewportData();
            // viewport->PlatformUserData = data;
            // GLFW 3.2 unfortunately always set focus on glfwCreateWindow() if GLFW_VISIBLE is set, regardless of GLFW_FOCUSED
            // With GLFW 3.3, the hint GLFW_FOCUS_ON_SHOW fixes this problem

            GLFW.WindowHint(WindowHintBool.Visible, true);
            GLFW.WindowHint(WindowHintBool.Focused, true);
            GLFW.WindowHint(WindowHintBool.FocusOnShow, true);
            GLFW.WindowHint(WindowHintBool.Decorated, !viewport.Flags.HasFlag(ImGuiViewportFlags.NoDecoration));
            GLFW.WindowHint(WindowHintBool.Floating, viewport.Flags.HasFlag(ImGuiViewportFlags.TopMost));

            Window *share_window = (Window *)GetMainWindowHandle().ToPointer();

            var window = GLFW.CreateWindow((int)viewport.Size.X, (int)viewport.Size.Y, "No Title Yet", null, share_window);

            // data->Window = window;
            // data->WindowOwned = true;
            viewport.PlatformHandle = new IntPtr(window);

            GLFW.SetWindowPos(window, (int)viewport.Pos.X, (int)viewport.Pos.Y);

            // GLFW.SetMouseButtonCallback(data->Window, ImGui_ImplGlfw_MouseButtonCallback);
            // GLFW.SetScrollCallback(data->Window, ImGui_ImplGlfw_ScrollCallback);
            // GLFW.SetKeyCallback(data->Window, ImGui_ImplGlfw_KeyCallback);
            // GLFW.SetCharCallback(data->Window, ImGui_ImplGlfw_CharCallback);
            GLFW.SetWindowCloseCallback(window, ImGui_ImplGlfw_WindowCloseCallback);
            GLFW.SetWindowPosCallback(window, ImGui_ImplGlfw_WindowPosCallback);
            GLFW.SetWindowSizeCallback(window, ImGui_ImplGlfw_WindowSizeCallback);

            GLFW.MakeContextCurrent(window);
            GLFW.SwapInterval(0);
        }
Exemplo n.º 16
0
        public override void BuildUI(ImGuiRenderer renderer)
        {
            ImGuiViewportPtr viewport = ImGui.GetMainViewport();

            ImGui.SetNextWindowPos(viewport.Pos);
            ImGui.SetNextWindowSize(viewport.Size);
            ImGui.SetNextWindowViewport(viewport.ID);
            ImGui.SetNextWindowBgAlpha(0.0f);

            ImGuiWindowFlags window_flags = ImGuiWindowFlags.MenuBar | ImGuiWindowFlags.NoDocking;

            window_flags |= ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoMove;
            window_flags |= ImGuiWindowFlags.NoBringToFrontOnFocus | ImGuiWindowFlags.NoNavFocus;

            ImGui.PushStyleVar(ImGuiStyleVar.WindowRounding, 0.0f);
            ImGui.PushStyleVar(ImGuiStyleVar.WindowBorderSize, 0.0f);
            ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(0.0f, 0.0f));
            ImGui.Begin("DockSpace Demo", ref p_open, window_flags);
            ImGui.PopStyleVar(3);

            var dockspace_id = ImGui.GetID("RootDockspace");
            ImGuiDockNodeFlags dockspace_flags = ImGuiDockNodeFlags.PassthruCentralNode;

            ImGui.DockSpace(dockspace_id, new Vector2(0.0f, 0.0f), dockspace_flags);
            ImGui.End();
        }
Exemplo n.º 17
0
 public VeldridImGuiWindow(GraphicsDevice gd, ImGuiViewportPtr vp, Sdl2Window window)
 {
     _gcHandle           = GCHandle.Alloc(this);
     _gd                 = gd;
     _vp                 = vp;
     _window             = window;
     vp.PlatformUserData = (IntPtr)_gcHandle;
 }
Exemplo n.º 18
0
        private void PlatformGetWindowPosition(Vector2 pos, ImGuiViewportPtr viewport)
        {
            WindowBase window = (WindowBase)GCHandle.FromIntPtr(viewport.PlatformUserData).Target;
            Rectangle  bounds = window.SdlWindow.Bounds;

            pos.X = bounds.X;
            pos.Y = bounds.Y;
        }
        private static Vector2 SetExceptionScreenPositionAndSize()
        {
            ImGuiViewportPtr mainViewport  = ImGui.GetMainViewport();
            Vector2          textInputSize = new Vector2(mainViewport.Size.X * 0.8f, mainViewport.Size.Y * 0.8f);

            ImGui.SetNextWindowPos(new Vector2(mainViewport.Pos.X + mainViewport.Size.X * 0.5f, mainViewport.Pos.Y + mainViewport.Size.Y * 0.5f), ImGuiCond.Always, new Vector2(0.5f, 0.5f));
            return(textInputSize);
        }
Exemplo n.º 20
0
        private void PlatformGetWindowSize(Vector2 size, ImGuiViewportPtr viewport)
        {
            //Seems to work
            WindowBase window = (WindowBase)GCHandle.FromIntPtr(viewport.PlatformUserData).Target;
            Rectangle  bounds = window.SdlWindow.Bounds;

            size.X = bounds.Width;
            size.Y = bounds.Height;
        }
Exemplo n.º 21
0
        private unsafe void GetWindowPos(ImGuiViewportPtr vp, Vector2 *outPos)
        {
            VeldridImGuiWindow?window = (VeldridImGuiWindow?)GCHandle.FromIntPtr(vp.PlatformUserData).Target;

            if (window == null)
            {
                throw new NullReferenceException();
            }
            *outPos = new Vector2(window.Window.Bounds.X, window.Window.Bounds.Y);
        }
Exemplo n.º 22
0
        private void DestroyWindow(ImGuiViewportPtr vp)
        {
            if (vp.PlatformUserData != IntPtr.Zero)
            {
                VeldridImGuiWindow window = (VeldridImGuiWindow)GCHandle.FromIntPtr(vp.PlatformUserData).Target;
                window.Dispose();

                vp.PlatformUserData = IntPtr.Zero;
            }
        }
Exemplo n.º 23
0
        private void SetWindowSize(ImGuiViewportPtr vp, Vector2 size)
        {
            VeldridImGuiWindow?window = (VeldridImGuiWindow?)GCHandle.FromIntPtr(vp.PlatformUserData).Target;

            if (window == null)
            {
                throw new NullReferenceException();
            }
            Sdl2Native.SDL_SetWindowSize(window.Window.SdlWindowHandle, (int)size.X, (int)size.Y);
        }
Exemplo n.º 24
0
        private void ShowWindow(ImGuiViewportPtr vp)
        {
            VeldridImGuiWindow?window = (VeldridImGuiWindow?)GCHandle.FromIntPtr(vp.PlatformUserData).Target;

            if (window == null)
            {
                throw new NullReferenceException();
            }
            Sdl2Native.SDL_ShowWindow(window.Window.SdlWindowHandle);
        }
Exemplo n.º 25
0
        public void SwapExtraWindows(GraphicsDevice gd)
        {
            ImGuiPlatformIOPtr platformIO = ImGui.GetPlatformIO();

            for (int i = 1; i < platformIO.Viewports.Size; i++)
            {
                ImGuiViewportPtr   vp     = platformIO.Viewports[i];
                VeldridImGuiWindow window = (VeldridImGuiWindow)GCHandle.FromIntPtr(vp.PlatformUserData).Target;
                gd.SwapBuffers(window.Swapchain);
            }
        }
Exemplo n.º 26
0
        // Viewport functions
        public void CreateWindow(ImGuiViewportPtr viewport)
        {
            ImGuiViewportDataDx11 data = new ImGuiViewportDataDx11();

            // PlatformHandleRaw should always be a HWND, whereas PlatformHandle might be a higher-level handle (e.g. GLFWWindow*, SDL_Window*).
            // Some backend will leave PlatformHandleRaw NULL, in which case we assume PlatformHandle will contain the HWND.
            IntPtr hWnd = viewport.PlatformHandleRaw;

            if (hWnd == IntPtr.Zero)
            {
                hWnd = viewport.PlatformHandle;
            }

            // Create swapchain
            SwapChainDescription desc = new SwapChainDescription
            {
                ModeDescription = new ModeDescription
                {
                    Width  = 0,
                    Height = 0,
                    Format = Format.R8G8B8A8_UNorm,
                },
                SampleDescription = new SampleDescription
                {
                    Count   = 1,
                    Quality = 0
                },
                Usage        = Usage.RenderTargetOutput,
                BufferCount  = 1,
                OutputHandle = hWnd,
                IsWindowed   = true,
                SwapEffect   = SwapEffect.Discard,
                Flags        = SwapChainFlags.None
            };

            // Create a swapchain using the existing game hardware (I think)
            using (var dxgi = _device.QueryInterface <SharpDX.DXGI.Device>())
                using (var adapter = dxgi.Adapter)
                    using (var factory = adapter.GetParent <Factory>())
                    {
                        data.SwapChain = new SwapChain(factory, _device, desc).NativePointer;
                    }

            // Create the render target view
            using (var backbuffer = new SwapChain(data.SwapChain).GetBackBuffer <Texture2D>(0))
                data.View = new RenderTargetView(_device, backbuffer).NativePointer;

            // Save data in renderer data
            IntPtr dataPtr = IntPtr.Zero;

            dataPtr = Marshal.AllocHGlobal(Marshal.SizeOf(data));
            Marshal.StructureToPtr(data, dataPtr, false);
            viewport.RendererUserData = dataPtr;
        }
Exemplo n.º 27
0
        private void SetWindowFocus(ImGuiViewportPtr vp)
        {
            if (p_sdl_RaiseWindow == null)
            {
                p_sdl_RaiseWindow = Sdl2Native.LoadFunction <SDL_RaiseWindow_t>("SDL_RaiseWindow");
            }

            VeldridImGuiWindow window = (VeldridImGuiWindow)GCHandle.FromIntPtr(vp.PlatformUserData).Target;

            p_sdl_RaiseWindow(window.Window.SdlWindowHandle);
        }
Exemplo n.º 28
0
        private void SetWindowPos(ImGuiViewportPtr vp, Vector2 pos)
        {
            VeldridImGuiWindow?window = (VeldridImGuiWindow?)GCHandle.FromIntPtr(vp.PlatformUserData).Target;

            if (window == null)
            {
                throw new NullReferenceException();
            }
            window.Window.X = (int)pos.X;
            window.Window.Y = (int)pos.Y;
        }
Exemplo n.º 29
0
        private unsafe void SetWindowTitle(ImGuiViewportPtr vp, IntPtr title)
        {
            VeldridImGuiWindow window = (VeldridImGuiWindow)GCHandle.FromIntPtr(vp.PlatformUserData).Target;
            byte *titlePtr            = (byte *)title;
            int   count = 0;

            while (titlePtr[count] != 0)
            {
                titlePtr += 1;
            }
            window.Window.Title = System.Text.Encoding.ASCII.GetString(titlePtr, count);
        }
Exemplo n.º 30
0
        private byte GetWindowMinimized(ImGuiViewportPtr vp)
        {
            VeldridImGuiWindow?window = (VeldridImGuiWindow?)GCHandle.FromIntPtr(vp.PlatformUserData).Target;

            if (window == null)
            {
                throw new NullReferenceException();
            }
            SDL_WindowFlags flags = Sdl2Native.SDL_GetWindowFlags(window.Window.SdlWindowHandle);

            return((flags & SDL_WindowFlags.Minimized) != 0 ? (byte)1 : (byte)0);
        }