示例#1
0
        static void Main(string[] args)
        {
            var dispose = new DisposeGroup();

            // Initialize window and imgui
            var view = dispose.Add(new RenderView());
            var gd   = view.GraphicsDevice;

            var cl = gd.ResourceFactory.CreateCommandList();

            var imGui = new ImGuiView(gd, view.Window, gd.MainSwapchain.Framebuffer.OutputDescription, view.Width, view.Height);

            ImGui.GetIO().ConfigWindowsMoveFromTitleBarOnly = true;

            //Create ImGui Windows
            var menu     = new UIMenu("Hello World!", new IUIComponent[] { new UIMenuItem("Test 1"), new UIMenuItem("Test 2", "CTRL+Z") });
            var mainmenu = new UIMainMenuBar(new IUIComponent[] { menu });

            var uiwindow = new UIWindow("Abstracted ImGui!", new IUIComponent[] { new UIText("Test Text"), new UICheckbox("Test Checkbox", false) });

            var pattern         = new MIDIPattern();
            var projectConnect  = new ProjectConnect();
            var pianoRollWindow = UIUtils.CreatePianoRollWindow(projectConnect, pattern, gd, imGui);

            // Initialize imgui UI
            var uihost = dispose.Add(new UIHost(new IUIComponent[] { mainmenu, uiwindow, pianoRollWindow }));

            Stopwatch frameTimer = new Stopwatch();

            frameTimer.Start();

            var hotkeys = new HotkeyHandler <GlobalHotkey>();

            // Main application loop
            while (view.Exists)
            {
                if (!view.Exists)
                {
                    break;
                }
                imGui.Update((float)frameTimer.Elapsed.TotalSeconds, view.Width, view.Height);
                frameTimer.Reset();
                frameTimer.Start();

                cl.Begin();

                // Compute UI elements, render canvases
                ImGui.DockSpaceOverViewport();
                uihost.Render(cl);
                ImGui.ShowDemoWindow();
                hotkeys.Update(true);
                if (hotkeys.CurrentHotkey == GlobalHotkey.Undo)
                {
                    projectConnect.Undo();
                }
                if (hotkeys.CurrentHotkey == GlobalHotkey.Redo)
                {
                    projectConnect.Redo();
                }
                Console.WriteLine(hotkeys.CurrentHotkey);

                ImGui.Text(ImGui.GetIO().Framerate.ToString());

                imGui.UpdateViewIO(view);

                cl.SetFramebuffer(gd.MainSwapchain.Framebuffer);
                cl.ClearColorTarget(0, new RgbaFloat(clearColor.X, clearColor.Y, clearColor.Z, 1f));
                imGui.Render(gd, cl);
                cl.End();
                gd.SubmitCommands(cl);
                gd.SwapBuffers(gd.MainSwapchain);
                imGui.SwapExtraWindows(gd);
            }

            dispose.Dispose();
        }
示例#2
0
        private void InitializeUi()
        {
            //Create ImGui Windows
            var mainmenu = new UIMainMenuBar(new IUIComponent[]
            {
                new UIMenu("File", new IUIComponent[]
                {
                    new UIMenuItem("Open Scene", "CTRL+O"),
                    new UIMenuItem("Open Project", "CTRL+SHIFT+O"),
                    new UIMenuItem("New Scene", "CTRL+N"),
                    new UIMenuItem("New Project", "CTRL+SHIFT+N"),

                    new UIMenuItem("Exit", "ALT+F4", () => view.Close())
                }),
                new UIMenu("Edit", new IUIComponent[]
                {
                    new UIMenuItem("Open Scene", "CTRL+O"),
                    new UIMenuItem("Open Project", "CTRL+SHIFT+O"),
                    new UIMenuItem("New Scene", "CTRL+N"),
                    new UIMenuItem("New Project", "CTRL+SHIFT+N"),

                    new UIMenuItem("Exit", "ALT+F4", () => view.Close())
                }),

                new UIMenu("Windows", new IUIComponent[]
                {
                    new UIMenuItem("Scene", action: () => uihost.Children.Add(new UIWindow("Scene", new IUIComponent[] {  })))
                })
            });

            var sceneWindow = new UIWindow("Scene", new IUIComponent[]
            {
            });
            var gameWindow = new UIWindow("Game", new IUIComponent[]
            {
                new UIMenuBar(new IUIComponent[] { new UIMenu("Status", new IUIComponent[] { new UIMenuItem($"FPS: {ImGui.GetIO().Framerate}") }), }),
            });
            var hierarchyWindow = new UIWindow("Hierarchy", new IUIComponent[]
            {
            });
            var inspectorWindow = new UIWindow("Inspector", new IUIComponent[]
            {
            });
            var projectWindow = new UIWindow("Project", new IUIComponent[]
            {
            });
            var consoleWindow = new UIWindow("Console", new IUIComponent[]
            {
            });

            var pattern = new MIDIPattern();

            projectConnect = new ProjectConnect();
            var pianoRollWindow = UIUtils.CreatePianoRollWindow(projectConnect, pattern, gd, imGui);

            // Initialize imgui UI
            uihost = disposer.Add(new UIHost(new IUIComponent[]
            {
                mainmenu,
                sceneWindow,
                gameWindow,
                hierarchyWindow,
                inspectorWindow,
                projectWindow,
                consoleWindow,
                //pianoRollWindow,
            }));


            frameTimer = new Stopwatch();
            frameTimer.Start();

            hotkeys = new HotkeyHandler <GlobalHotkey>();
        }