Esempio n. 1
0
        public static void ShowWindow(ref bool windowOpened)
        {
            if (!GUI.Begin(WindowName, ref windowOpened))
            {
                GUI.End();
                return;
            }

            // Basic info
            GUIContext g = GetCurrentContext();

            Text("Hello ImGui {0}##Metrics.Version", GetVersion());
            Text("Application average {0:F3} ms/frame ({1:F1} FPS)##Metrics.FPS", 1000.0f / g.fps, g.fps);
            Text("{0} vertices, {1} indices ({2} triangles)##Metrics.VI",
                 VertexNumber, IndexNumber, IndexNumber / 3);
            Text("{0} active windows ({0} visible)##Metrics.Window", ActiveWindows, RenderWindows);
            Separator("separator0");

            //Windows
            var windowManager = g.WindowManager;

            NodeWindows(windowManager.Windows.ToArray(), "Windows");

            GUI.End();
        }
Esempio n. 2
0
        public void FlexibleSpace()
        {
            Application.IsRunningInUnitTest = true;
            Application.Init();

            bool open = true;
            var  form = new MainForm();

            Application.Run(form, () =>
            {
                GUI.Begin("Test", ref open, Point.Zero, new Size(300, 300));

                GUILayout.BeginHorizontal("h0");
                {
                    GUILayout.Button("0", GUILayout.Width(20));
                    GUILayout.FlexibleSpace("space0", 1);
                    GUILayout.Button("1", GUILayout.Width(20));
                    GUILayout.FlexibleSpace("space1", 2);
                    GUILayout.Button("2", GUILayout.Width(20));
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal("h2");
                {
                    GUILayout.Button("0", GUILayout.Width(20));
                    GUILayout.FlexibleSpace("space0", 2);
                    GUILayout.Button("1", GUILayout.Width(20));
                    GUILayout.FlexibleSpace("space1", 1);
                    GUILayout.Button("2", GUILayout.Width(20));
                }
                GUILayout.EndHorizontal();
                GUI.End();
            });
        }
Esempio n. 3
0
        public void WindowOverflowByManyButtons()
        {
            Application.IsRunningInUnitTest = true;
            Application.Init();

            var  form = new MainForm(new Rect(320, 180, 800, 600));
            bool open = true;

            Application.Run(form, () =>
            {
                GUI.Begin("test window", ref open, new Point(100, 100), new Size(100, 100));
                GUILayout.Button("Button 0");
                GUILayout.Button("Button 1");
                GUILayout.Button("Button 2");
                GUILayout.Button("Button 3");
                GUILayout.Button("Button 4");
                GUILayout.Button("Button 5");
                GUILayout.Button("Button 6");
                GUILayout.Button("Button 7");
                GUILayout.Button("Button 8");
                GUILayout.Button("Button 9");
                GUILayout.Button("Button 10");
                GUILayout.Button("Button 11");
                GUILayout.Button("Button 12");
                GUILayout.Button("Button 13");
                GUILayout.Button("Button 14");
                GUILayout.Button("Button 15");
                GUILayout.Button("Button 16");
                GUILayout.Button("Button 17");
                GUILayout.Button("Button 18");
                GUILayout.Button("Button 19");
                GUI.End();
            });
        }
Esempio n. 4
0
 private static void OnGUI()
 {
     demo.OnGUI();
     GUI.Begin("Combobox demo", new Point(10, 10), new Size(400, 400));
     GUI.ComboBox(new Rect(10, 10, 200, 20), text);
     GUI.End();
 }
Esempio n. 5
0
    public void OnGUI()
    {
        deltaTime = watch.ElapsedMilliseconds - startTime;
        startTime = watch.ElapsedMilliseconds;

        // 1. Show a simple window
        // Tip: if we don't call GUI.Begin()/GUI.End() the widgets appears in a window automatically called "Debug"
        {
            GUILayout.Label("Hello, world!");
            f          = GUILayout.Slider("float", f, 0, 1);
            clearColor = GUILayout.ColorField("clear color", clearColor);
            if (GUILayout.Button("Show Demo Window"))
            {
                showDemoWindow = !showDemoWindow;
            }
            if (GUILayout.Button("Show Another Window"))
            {
                showAnotherWindow = !showAnotherWindow;
            }
            if (GUILayout.Button("Show Metrics Window"))
            {
                showMetricsWindow = !showMetricsWindow;
            }
            //var fps = Form.current.uiContext.fps;
            //GUILayout.Label(string.Format("Application average {0:F3} ms/frame ({1:F1} FPS)", 1000.0f / fps, fps));//FIXME Showing text that keeps updating is slow.
        }

        // 2. Show another simple window, this time using an explicit Begin/End pair
        if (showAnotherWindow)
        {
            GUI.Begin("Another Window", ref showAnotherWindow, (80, 340), (400, 150));
            GUILayout.Text("Hello, ImGui {0}", 123);

            if (GUILayout.Button("OK"))
            {
                // do stuff
            }

            text  = GUILayout.TextBox("string", 256, text);
            value = GUILayout.Slider("float", value, 0, 1);
            GUI.End();
        }

        // 3. Show the ImGui demo window. Most of the sample code is in demoUI.ShowTestWindow()
        if (showDemoWindow)
        {
            ShowTestWindow(ref showDemoWindow);
        }

        if (showMetricsWindow)
        {
            ImGui.Development.Metrics.ShowWindow(ref showMetricsWindow);
        }

        Form.current.BackgroundColor = clearColor;
    }
Esempio n. 6
0
        public void CreateAWindow()
        {
            Application.IsRunningInUnitTest = true;
            Application.Init();

            var  form = new MainForm(new Rect(320, 180, 800, 600));
            bool open = true;

            Application.Run(form, () =>
            {
                GUI.Begin("test window", ref open, new Point(100, 100), new Size(100, 100));
                GUI.End();
            });
        }
Esempio n. 7
0
        protected override void OnGUI()
        {
            GUI.Begin("TextPad", ref open, (10, 10), (800, 600));
            GUILayout.Label("Only *.txt file smaller than 1KB are supported.");
            if (!fileOpened)
            {
                filePath = GUILayout.InputText("Path", filePath);
            }
            else
            {
                GUILayout.PushFontColor(Color.TextDisabled);
                GUILayout.InputText("Path", filePath);
                GUILayout.PopStyleVar();
            }

            GUILayout.BeginHorizontal("CommandButtons");
            bool requestOpen  = GUILayout.Button("Open");
            bool requestSave  = GUILayout.Button("Save");
            bool requestClose = GUILayout.Button("Close");

            GUILayout.EndHorizontal();

            if (requestOpen)
            {
                if (filePath.EndsWith(".txt") && System.IO.File.Exists(filePath))
                {
                    if (new System.IO.FileInfo(filePath).Length < 10000)
                    {
                        fileContent = System.IO.File.ReadAllText(filePath);
                    }
                    fileOpened = true;
                }
            }
            if (requestSave && fileOpened)
            {
                System.IO.File.WriteAllText(filePath, fileContent);
            }
            if (requestClose && fileOpened)
            {
                filePath    = "";
                fileContent = "";
                fileOpened  = false;
            }

            GUILayout.PushHStretchFactor(1);
            fileContent = GUILayout.TextBox("file content textbox", new Size(400, 400), fileContent);
            GUILayout.PopStyleVar();

            GUI.End();
        }
Esempio n. 8
0
            public void TheWindowShouldBeDrawn()
            {
                Application.Init();

                var  form = new MainForm();
                bool open = true;

                form.OnGUIAction = () =>
                {
                    GUI.Begin("test window", ref open);
                    GUI.End();
                };

                Application.Run(form);
            }
Esempio n. 9
0
        /// <summary>
        /// Draws the Kyoob game.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            // draw the world (handles clearing)
            _renderer.Draw(gameTime);

            // draw our GUI items
            GUI.Begin();
            GUI.DrawText(10, 10, "{0} FPS", _frameCounter.FPS);
#if DEBUG
            GUI.DrawText(10, 24, "Eye Position: {0}", Player.Instance.EyePosition);
            GUI.DrawText(10, 38, "World Seed: {0}", Terrain.Instance.Seed);
#endif
            GUI.End();

            base.Draw(gameTime);
        }
Esempio n. 10
0
            public void TheWindowShouldBeDrawn()
            {
                Application.IsRunningInUnitTest = true;
                Application.Init();

                var  form = new MainForm(new Rect(320, 180, 800, 600));
                bool open = true;

                form.OnGUIAction = () =>
                {
                    GUI.Begin("test window", ref open, new Point(100, 100), new Size(100, 100));
                    GUI.End();
                };

                Application.Run(form);
            }
Esempio n. 11
0
        public override void OnPaint()
        {
            currentNodeIndex = 0;
            isDirty          = EngineUtility.TransformHierarchyDirty;
            if (isDirty)
            {
                ResetNodes();
                isDirty = false;
            }

            GUI.Begin("Hierarchy");
            GUI.PushStyleVar(GUIStyleVar.ItemSpacing, new Vector2(3.0f, 3.0f));
            foreach (HierarchyNode node in nodes)
            {
                node.OnPaint();
            }
            GUI.PopStyleVar();
            GUI.End();
        }
Esempio n. 12
0
        public void WindowOverflowByListBox()
        {
            Application.IsRunningInUnitTest = true;
            Application.Init();

            var  form = new MainForm(new Rect(320, 180, 800, 600));
            bool open = true;

            string[] listBoxItems       = { "Apple", "Banana", "Cherry", "Kiwi", "Mango", "Orange", "Pineapple", "Strawberry", "Watermelon" };
            int      currentListBoxItem = 0;

            Application.Run(form, () =>
            {
                GUI.Begin("test window", ref open, new Point(100, 100), new Size(200, 100));
                GUILayout.Button("Button 0");
                currentListBoxItem = GUILayout.ListBox("listbox\n(single select)", listBoxItems, currentListBoxItem);
                GUILayout.Button("Button 1");
                GUI.End();
            });
        }
Esempio n. 13
0
        protected override void Draw(GameTime gameTime)
        {
            m_spriteBatch.Begin();
            GraphicsDevice.Clear(Color.Black);

            double fps = Math.Round(1000.0 / gameTime.ElapsedGameTime.TotalMilliseconds);

            m_spriteBatch.DrawString($"FPS: {fps}", Vector2.Zero);

            GUI.Begin();
            if (GUI.Button("Click me!", 50, 50))
            {
                Console.WriteLine("Button was clicked :O");
            }
            GUI.End();

            Mrag.Render();
            m_spriteBatch.End();

            base.Draw(gameTime);
        }
Esempio n. 14
0
        public void FixedSpace()
        {
            Application.IsRunningInUnitTest = true;
            Application.Init();

            bool open = true;
            var  form = new MainForm();

            Application.Run(form, () =>
            {
                GUI.Begin("Test", ref open, Point.Zero, new Size(100, 300));

                GUILayout.Button("button0");
                GUILayout.Space("space0", 10);
                GUILayout.Button("button1");
                GUILayout.Button("button2");
                GUILayout.Space("space1", 30);
                GUILayout.Button("button3");

                GUI.End();
            });
        }
Esempio n. 15
0
        public void LayoutSeparator()
        {
            Application.IsRunningInUnitTest = true;
            Application.Init();

            bool open = true;
            var  form = new MainForm();

            Application.Run(form, () =>
            {
                GUI.Begin("Test", ref open, Point.Zero, new Size(300, 300));
                GUILayout.Button("Button 0");
                GUILayout.Button("Button 1");
                GUILayout.Separator("separator1");
                GUILayout.Button("Button 2");
                GUILayout.Button("Button 3");
                GUILayout.Button("Button 4");
                GUILayout.Separator("separator2");
                GUILayout.Button("Button 5");
                GUI.End();
            });
        }
Esempio n. 16
0
        public override void OnPaint()
        {
            GUI.Begin("View",
                      GUIWindowFlags.NoScrollbar
                      | GUIWindowFlags.NoCollapse
                      | GUIWindowFlags.NoResize
                      //| ImGuiWindowFlags.NoMove
                      | GUIWindowFlags.NoScrollWithMouse
                      | GUIWindowFlags.NoTitleBar);

            //ImGui.SetWindowSize(size);
            //ImGui.SetWindowPos(pos);

            ViewPos  = GUI.GetWindowPos();
            ViewSize = new Vector2(GUI.GetWindowWidth() - 12, GUI.GetWindowHeight() - 16);

            // Magical numbers to fix the viewport scaling.
            ViewBounds = new Rectangle((int)ViewPos.X + 7, (int)ViewPos.Y + 7, (int)ViewSize.X, (int)ViewSize.Y);
            Screen.EditorViewBounds = ViewBounds;

            GUI.Image(boundTexture, ViewSize, Vector2.Zero, Vector2.One);
            GUI.End();
        }
Esempio n. 17
0
        public override void OnGUI()
        {
            GUI.Begin();
            GUI.Label(new Rectangle(0, Height * 1 / 4, 100, 100), "variant- play radius=" + variant);
            GUI.Label(new Rectangle(0, Height / 2, 100, 100), "debug  =" + debug);
            GUI.Label(new Rectangle(Width / 2 - 64, 16, 128, 16), "CURRENT PLAYER-" + gameState.CurrentPlayerId);
            GUI.Label(new Rectangle(Width / 2 - 64, 48, 128, 16), "PLAYER" + huPlayer.PlayerId + "_SCORE:" + huPlayer.Score);
            //GUI.Label(new Rectangle(Width / 2 - 64, 48, 128, 16), "PLAYER" + testAIPlayer.PlayerId + "_SCORE:" + testAIPlayer.Score);
            GUI.Label(new Rectangle(Width / 2 - 64, 64, 128, 16), "PLAYER" + aiPlayer.PlayerId + "SCORE:" + aiPlayer.Score);

            if (gameState.CurrentPlayerId == 1)
            {
                GUI.Label(new Rectangle(Width - 64, 64, 128, 16), "PLAYER " + huPlayer.PlayerId, Color.Black, currentColor);
                //GUI.Label(new Rectangle(Width - 64, 64, 128, 16), "PLAYER " + testAIPlayer.PlayerId, Color.Black, currentColor);

                GUI.Label(new Rectangle(Width - 64, Height - 64, 128, 16), "PLAYER " + aiPlayer.PlayerId, Color.Black, Color.White);
            }
            else
            {
                GUI.Label(new Rectangle(Width - 64, 64, 128, 16), "PLAYER " + huPlayer.PlayerId, Color.Black, Color.White);
                //GUI.Label(new Rectangle(Width - 64, 64, 128, 16), "PLAYER " + testAIPlayer.PlayerId, Color.Black, Color.White);

                GUI.Label(new Rectangle(Width - 64, Height - 64, 128, 16), "PLAYER " + aiPlayer.PlayerId, Color.Black, currentColor);
            }

            GUI.Label(new Rectangle(Width - 200, Height / 2, 200, 128),
                      "W:increase playing hexes per side\n"
                      + "S:decrease playing hexes per side\n"
                      + "U:undo 1 turn\n"
                      + "Y:undo player turn\n"
                      + "R:reset new round\n"
                      + "Space:next AI turn"
                      , Color.Black, Color.Salmon);

            GUI.End();
        }
Esempio n. 18
0
    public void OnGUI()
    {
        // 1. Show a simple window
        // Tip: if we don't call GUI.Begin()/GUI.End() the widgets appears in a window automatically called "Debug"
        {
            GUILayout.Label("Hello, world!");
            f          = GUILayout.Slider("float", f, 0, 1);
            clearColor = GUILayout.ColorField("clear color", clearColor);
            if (GUILayout.Button("Show Demo Window"))
            {
                showDemoWindow = !showDemoWindow;
            }
            if (GUILayout.Button("Show Another Window"))
            {
                showAnotherWindow = !showAnotherWindow;
            }
            //var fps = Form.current.uiContext.fps;
            //GUILayout.Label(string.Format("Application average {0:F3} ms/frame ({1:F1} FPS)", 1000.0f / fps, fps));//FIXME Showing text that keeps updating is slow.
        }

        // 2. Show another simple window, this time using an explicit Begin/End pair
        if (showAnotherWindow)
        {
            GUI.Begin("Another Window", ref showAnotherWindow, (70, 450), (400, 100));
            GUILayout.Label("Hello");
            GUI.End();
        }

        // 3. Show the ImGui demo window. Most of the sample code is in demoUI.ShowTestWindow()
        if (showDemoWindow)
        {
            ShowTestWindow(ref showDemoWindow);
        }

        Form.current.BackgroundColor = clearColor;
    }
Esempio n. 19
0
        public void OnGUI()
        {
            GUI.Begin("Simple Calculator", ref open, (10, 10), (240, 270));

            if (Current != ButtonType.Idle)
            {
                Last = Current;
            }
            Current = ButtonType.Idle;

            const int o = -20;

            GUI.Label(new Rect(14, 22 + o, new Size(190, 20)), calc.Expression + "##Expression"); //ExpressionLabel
            GUI.Label(new Rect(14, 42 + o, new Size(190, 24)), calc.Result + "##Result");         //ResultLabel

            var backspace = GUI.Button(new Rect(14, 68 + o, new Size(34, 27)), "←");              //backspaceButton

            if (backspace)
            {
                Current = ButtonType.Backspace;
            }
            var clearInput = GUI.Button(new Rect(53, 68 + o, new Size(34, 27)), "CE");//CEButton

            if (clearInput)
            {
                Current = ButtonType.ClearInput;
            }
            var clear = GUI.Button(new Rect(92, 68 + o, new Size(34, 27)), "C");//CButton

            if (clear)
            {
                Current = ButtonType.Clear;
            }
            var plusMinus = GUI.Button(new Rect(131, 68 + o, new Size(34, 27)), "±");//SignButton

            if (plusMinus)
            {
                Current = ButtonType.PlusMinus;
            }
            var sqrt = GUI.Button(new Rect(170, 68 + o, new Size(34, 27)), "√");//SqrtButton

            if (sqrt)
            {
                Current = ButtonType.Sqrt;
            }

            bool[] number = new bool[10];

            number[7] = GUI.Button(new Rect(14, 100 + o, new Size(34, 27)), "7");//_7Button
            if (number[7])
            {
                Current = ButtonType.Number7;
            }
            number[8] = GUI.Button(new Rect(53, 100 + o, new Size(34, 27)), "8");//_8Button
            if (number[8])
            {
                Current = ButtonType.Number8;
            }
            number[9] = GUI.Button(new Rect(92, 100 + o, new Size(34, 27)), "9");//_9Button
            if (number[9])
            {
                Current = ButtonType.Number9;
            }
            var divide = GUI.Button(new Rect(131, 100 + o, new Size(34, 27)), "/");//DivideButton

            if (divide)
            {
                Current = ButtonType.Divide;
            }
            var percent = GUI.Button(new Rect(170, 100 + o, new Size(34, 27)), "%");//PercentButton

            if (percent)
            {
                Current = ButtonType.Percent;
            }

            number[4] = GUI.Button(new Rect(14, 132 + o, new Size(34, 27)), "4");//_4Button
            if (number[4])
            {
                Current = ButtonType.Number4;
            }
            number[5] = GUI.Button(new Rect(53, 132 + o, new Size(34, 27)), "5");//_5Button
            if (number[5])
            {
                Current = ButtonType.Number5;
            }
            number[6] = GUI.Button(new Rect(92, 132 + o, new Size(34, 27)), "6");//_6Button
            if (number[6])
            {
                Current = ButtonType.Number6;
            }
            var multiply = GUI.Button(new Rect(131, 132 + o, new Size(34, 27)), "*");//MultiplyButton

            if (multiply)
            {
                Current = ButtonType.Multiply;
            }
            var inverse = GUI.Button(new Rect(170, 132 + o, new Size(34, 27)), "1/x");//InverseButton

            if (inverse)
            {
                Current = ButtonType.Inverse;
            }

            number[1] = GUI.Button(new Rect(14, 164 + o, new Size(34, 27)), "1");//_1Button
            if (number[1])
            {
                Current = ButtonType.Number1;
            }
            number[2] = GUI.Button(new Rect(53, 164 + o, new Size(34, 27)), "2");//_2Button
            if (number[2])
            {
                Current = ButtonType.Number2;
            }
            number[3] = GUI.Button(new Rect(92, 164 + o, new Size(34, 27)), "3");//_3Button
            if (number[3])
            {
                Current = ButtonType.Number3;
            }
            var minus = GUI.Button(new Rect(131, 164 + o, new Size(34, 27)), "-");//MinusButton

            if (minus)
            {
                Current = ButtonType.Minus;
            }

            number[0] = GUI.Button(new Rect(14, 196 + o, new Size(73, 27)), "0");//_0Button
            if (number[0])
            {
                Current = ButtonType.Number0;
            }
            var dot = GUI.Button(new Rect(92, 196 + o, new Size(34, 27)), ".");//PointButton

            if (dot)
            {
                Current = ButtonType.Dot;
            }
            var plus = GUI.Button(new Rect(131, 196 + o, new Size(34, 27)), "+");//_plusButton

            if (plus)
            {
                Current = ButtonType.Plus;
            }

            var equal = GUI.Button(new Rect(170, 164 + o, new Size(34, 59)), "=");//_EqualButton

            if (equal)
            {
                Current = ButtonType.Equal;
            }

            GUI.End();

            if (Current == ButtonType.Idle)
            {
                return;
            }

            if (Current == ButtonType.ClearInput)
            {
                calc.ClearInput();
                calc.ShowingResult = false;
                return;
            }

            if (Current == ButtonType.Clear)
            {
                calc.Clear();
                calc.EnteringOperand0 = true;
                calc.EnteringOperator = false;
                calc.EnteringOperand1 = false;

                calc.ShowingResult = false;
                return;
            }

            if (Current == ButtonType.Backspace)
            {
                calc.Backspace();
                return;
            }

            if (Current.IsNumber())
            {
                if (calc.ShowingResult)
                {
                    calc.Clear();
                }
                if (calc.EnteringOperand0)
                {
                    if (calc.Operand0 == "0")
                    {
                        calc.Operand0 = ((int)Current).ToString();
                    }
                    else
                    {
                        calc.Operand0 += (int)Current;
                    }
                }
                else if (calc.EnteringOperand1)
                {
                    if (calc.Operand1 == "0")
                    {
                        calc.Operand1 = ((int)Current).ToString();
                    }
                    else
                    {
                        calc.Operand1 += (int)Current;
                    }
                }

                calc.ShowingResult = false;
            }

            if (Last.IsNumber() && Current.IsUnaryOperator())
            {
                calc.Op = (OpType)Current;
                calc.DoCalc();
                calc.EnteringOperand0 = true;
                calc.EnteringOperator = false;
                calc.EnteringOperand1 = false;

                calc.ShowingResult = true;
            }

            if (Last.IsNumber() && Current.IsBinaryOperator())
            {
                calc.Op = (OpType)Current;
                calc.EnteringOperand0 = false;
                calc.EnteringOperator = true;
                calc.EnteringOperand1 = true;

                calc.ShowingResult = false;
            }

            if (!calc.ShowingResult && Current.IsBinaryOperator())
            {
                calc.Op = (OpType)Current;
                calc.EnteringOperand0 = false;
                calc.EnteringOperator = true;
                calc.EnteringOperand1 = true;

                calc.ShowingResult = false;
            }

            if (Last.IsBinaryOperator() && Current.IsNumber())
            {
                calc.EnteringOperand0 = false;
                calc.EnteringOperator = false;
                calc.EnteringOperand1 = true;

                calc.ShowingResult = false;
            }

            if (calc.EnteringOperand1 && Current == ButtonType.Equal)
            {
                calc.DoCalc();
                calc.EnteringOperand0 = false;
                calc.EnteringOperator = false;
                calc.EnteringOperand1 = false;

                calc.ShowingResult = true;
            }

            if (Last == ButtonType.Equal && Current.IsNumber())
            {
                calc.Clear();
                calc.EnteringOperand0 = true;
                calc.EnteringOperator = false;
                calc.EnteringOperand1 = false;
                calc.ShowingResult    = false;
                calc.Operand0         = ((int)Current).ToString();
            }
        }
Esempio n. 20
0
    private void ShowTestWindow(ref bool open)
    {
        WindowFlags window_flags = WindowFlags.None;

        if (no_titlebar)
        {
            window_flags |= WindowFlags.NoTitleBar;
        }
        if (no_resize)
        {
            window_flags |= WindowFlags.NoResize;
        }
        if (no_move)
        {
            window_flags |= WindowFlags.NoMove;
        }
        if (no_scrollbar)
        {
            window_flags |= WindowFlags.NoScrollbar;
        }
        if (no_collapse)
        {
            window_flags |= WindowFlags.NoCollapse;
        }

        if (!GUI.Begin("ImGui Demo", ref open, (650, 20), (550, 680), bg_alpha, window_flags))
        {
            // Early out if the window is collapsed, as an optimization.
            GUI.End();
            return;
        }
        GUILayout.Label("ImGui says hello.");
        GUILayout.Space("Space~1", 5);
        if (GUILayout.CollapsingHeader("Help", ref helpOn))
        {
            ShowUserGuide();
        }

        if (GUILayout.CollapsingHeader("Window options", ref windowsOptionsOn))
        {
            GUILayout.PushID("_WindowOptions");
            no_titlebar  = GUILayout.Toggle("no titlebar", no_titlebar);
            no_border    = GUILayout.Toggle("no border", no_border);
            no_resize    = GUILayout.Toggle("no resize", no_resize);
            no_move      = GUILayout.Toggle("no move", no_move);
            no_scrollbar = GUILayout.Toggle("no scrollbar", no_scrollbar);
            bg_alpha     = GUILayout.Slider("background alpha", bg_alpha, 0.0, 1.0);
            if (GUILayout.TreeNode("Style", ref styleEditorOpen))
            {
                ShowStyleEditor();
                GUILayout.TreePop();
            }
            if (GUILayout.TreeNode("Logging", ref loggingOpen))
            {
                GUILayout.Text("TODO");
                GUILayout.TreePop();
            }
            //TODO logging
            GUILayout.PopID();
        }

        if (GUILayout.CollapsingHeader("Widgets", ref widgetsOn))
        {
            GUILayout.PushID("_Widgets");
            if (GUILayout.TreeNode("Trees", ref open1))
            {
                if (GUILayout.TreeNode("Basic trees", ref open2))
                {
                    for (int i = 0; i < openChild.Length; i++)
                    {
                        if (GUILayout.TreeNode(string.Format("Child {0}", i), ref openChild[i]))
                        {
                            GUILayout.BeginHorizontal("HGroup");
                            GUILayout.Label("blah blah");
                            if (GUILayout.Button("print"))
                            {
                                System.Console.WriteLine(@"Child {0} pressed", i);
                            }
                            GUILayout.EndHorizontal();
                            GUILayout.TreePop();
                        }
                    }
                    GUILayout.TreePop();
                }
                GUILayout.TreePop();
            }

            if (GUILayout.TreeNode("Collapsing Headers", ref open4))
            {
                if (GUILayout.CollapsingHeader("Header", ref open5))
                {
                    closable_group = GUILayout.Toggle("Enable extra group", closable_group);
                    for (int i = 0; i < 5; i++)
                    {
                        GUILayout.Label("Some content {0}", i);
                    }
                }
                if (GUILayout.CollapsingHeader("Header with a close button", ref closable_group))
                {
                    for (int i = 0; i < 5; i++)
                    {
                        GUILayout.Label("More content {0}", i);
                    }
                }
                GUILayout.TreePop();
            }

            if (GUILayout.TreeNode("Bullets", ref open6))
            {
                GUILayout.BulletText("Bullet point 1");
                GUILayout.BulletText("Bullet point 2\nOn multiple lines");
                GUILayout.PushStyle(StylePropertyName.CellSpacingHorizontal, 0);//remove horizontal cell spacing of following groups.
                GUILayout.BeginHorizontal("HGroup~1"); GUILayout.Bullet("_Bullet"); GUILayout.Text("Bullet point 3 (two calls)"); GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal("HGroup~2"); GUILayout.Bullet("_Bullet"); GUILayout.Button("Button"); GUILayout.EndHorizontal();
                GUILayout.PopStyle();
                GUILayout.TreePop();
            }

            if (GUILayout.TreeNode("Colored Text", ref open7))
            {
                // Using shortcut. You can use GUILayout.PushFontColor() for more flexibility.
                GUILayout.Label(new Color(1.0f, 0.0f, 1.0f, 1.0f), "Pink");
                GUILayout.Label(new Color(1.0f, 1.0f, 0.0f, 1.0f), "Yellow");
                GUILayout.LabelDisabled("Disabled");
                GUILayout.TreePop();
            }

            if (GUILayout.TreeNode("Word Wrapping", ref open8))
            {
                //TODO
                GUILayout.Label("TODO");
                GUILayout.TreePop();
            }

            if (GUILayout.TreeNode("Non-ASCII Text", ref open9))
            {
                //TODO wrapped Label
                GUILayout.Label("Hiragana: カククケコ (kakikukeko)");
                GUILayout.Label("Kanjis: 日本語 (nihongo)");
                buf = GUILayout.InputText("Unicode input", buf);
                GUILayout.TreePop();
            }

            if (GUILayout.TreeNode("Images", ref open10))
            {
                GUILayout.Image("images/trees.jpg");
                GUILayout.Text("Some textured buttons:");
                GUILayout.BeginHorizontal("HGroup~1");
                for (int i = 0; i < 8; i++)
                {
                    GUILayout.PushID(i);
                    if (GUILayout.ImageButton("images/trees.jpg", new Size(32, 32),
                                              new Vector(32.0f * i, 0)))
                    {
                        pressed_count += 1;
                    }
                    GUILayout.PopID();
                }
                GUILayout.EndHorizontal();
                GUILayout.Label("Pressed {0} times.", pressed_count);
                GUILayout.TreePop();
            }

            if (GUILayout.TreeNode("Selectables", ref open11))
            {
                if (GUILayout.TreeNode("Basic", ref basicSelectableOpen))
                {
                    selected[0] = GUILayout.Selectable("1. I am selectable", selected[0]);
                    selected[1] = GUILayout.Selectable("2. I am selectable", selected[1]);
                    GUILayout.Text("3. I am not selectable");
                    selected[2] = GUILayout.Selectable("4. I am selectable", selected[2]);
                    GUILayout.TreePop();
                }
                GUILayout.Label("more TODO");
                GUILayout.TreePop();
            }

            if (GUILayout.TreeNode("Filtered Text Input", ref open12))
            {
                defaultText     = GUILayout.InputText("default", defaultText);
                decimalText     = GUILayout.InputText("decimal", decimalText, InputTextFlags.CharsDecimal);
                hexadecimalText = GUILayout.InputText("hexadecimal", hexadecimalText, InputTextFlags.CharsHexadecimal | InputTextFlags.CharsUppercase);
                uppercaseText   = GUILayout.InputText("uppercase", uppercaseText, InputTextFlags.CharsUppercase);
                noBlankText     = GUILayout.InputText("no blank", noBlankText, InputTextFlags.CharsNoBlank);
                customText      = GUILayout.InputText("\"imgui\" letters", customText, 0, (c) => "imguiIMGUI".IndexOf(c) >= 0);
                GUILayout.Text("Password input");
                password = GUILayout.InputText("password", password, InputTextFlags.Password | InputTextFlags.CharsNoBlank);
                password = GUILayout.InputText("password (clear)", password, InputTextFlags.CharsNoBlank);
                GUILayout.TreePop();
            }

            if (GUILayout.TreeNode("Multi-line Text Input", ref open13))
            {
                GUILayout.PushPadding((0, 0, 0, 0));
                read_only = GUILayout.CheckBox("Read-only", read_only);
                GUILayout.PopStyle(4);
                GUILayout.PushStyle(StylePropertyName.HorizontalStretchFactor, 1);
                if (read_only)
                {
                    GUILayout.InputTextMultiline("Text Box", new Size(120, 200), multiLineText);
                }
                else
                {
                    multiLineText = GUILayout.InputTextMultiline("Text Box", new Size(120, 200), multiLineText);
                }
                GUILayout.PopStyle();
                GUILayout.TreePop();
            }

            using (GUILayout.HScope("HGroup~button_show_text"))
            {
                if (GUILayout.Button("Button"))
                {
                    System.Console.WriteLine("Clicked");
                    a ^= true;
                }
                if (a)
                {
                    GUILayout.Label("Thanks for clicking me!");
                }
            }

            check = GUILayout.CheckBox("checkbox", check);

            GUILayout.BeginHorizontal("HGroup~radios");
            {
                GUILayout.RadioButton("Radio 0", ref active_id, 0);
                GUILayout.RadioButton("Radio 1", ref active_id, 1);
                GUILayout.RadioButton("Radio 2", ref active_id, 2);
            }
            GUILayout.EndHorizontal();

            // Color buttons, demonstrate using PushID() to add unique identifier in the ID stack, and changing style.
            GUILayout.BeginHorizontal("HGroup~click buttons");
            {
                for (int i = 0; i < 7; i++)
                {
                    GUILayout.PushID(i);
                    GUILayout.PushStyle(StylePropertyName.BackgroundColor, Color.HSV(i / 7.0f, 0.6f, 0.6f), GUIState.Normal);
                    GUILayout.PushStyle(StylePropertyName.BackgroundColor, Color.HSV(i / 7.0f, 0.7f, 0.7f), GUIState.Hover);
                    GUILayout.PushStyle(StylePropertyName.BackgroundColor, Color.HSV(i / 7.0f, 0.8f, 0.8f), GUIState.Active);
                    GUILayout.Button("Click");
                    GUILayout.PopStyle(3);
                    GUILayout.PopID();
                }
            }
            GUILayout.EndHorizontal();

            //TODO tooltip
            //GUILayout.BeginHorizontal("HGroup~tooltips");
            //GUILayout.Text("Hover over me");
            //if (GUI.IsItemHovered())
            //    GUI.SetTooltip("I am a tooltip");

            //if (GUI.IsItemHovered())
            //{
            //    GUILayout.BeginTooltip();
            //    //...
            //    GUILayout.EndTooltip();
            //}
            //GUILayout.EndHorizontal();

            GUILayout.Separator("Separator~1");

            GUILayout.LabelText("label", "Value");

            //TODO combo

            str0 = GUILayout.InputText("input text", str0);
            i0   = GUILayout.InputInt("input int", i0);
            f0   = GUILayout.InputFloat("input float", f0);
            col1 = GUILayout.ColorField("color 1", col1);//TODO no alpha color field
            col2 = GUILayout.ColorField("color 2", col2);
            currentListBoxItem = GUILayout.ListBox <string>("listbox\n(single select)", listBoxItems, currentListBoxItem);

            if (GUILayout.TreeNode("Sliders", ref open14))
            {
                GUILayout.Label("Horizontal Slider");
                sliderValue = GUILayout.Slider("slider", sliderValue, 0.0, 1.0);
                GUILayout.Label("Vertical Slder");
                vSliderValue = GUILayout.VSlider("vslider", vSliderValue, 0.0, 1.0);
                GUILayout.TreePop();
            }

            GUILayout.PopID();
        }

        if (GUILayout.CollapsingHeader("Graphs widgets", ref graphicsWidgetsOn))
        {
            GUILayout.PushID("_GraphsWidgets");
            animate = GUILayout.CheckBox("Animate", animate);
            GUILayout.PushStyle(StylePropertyName.HorizontalStretchFactor, 1);//+1
            if (animate)
            {
                progress += progress_dir * 0.4f * deltaTime / 1000.0;
                if (progress >= +1.1f)
                {
                    progress = +1.1f; progress_dir *= -1.0f;
                }
                if (progress <= -0.1f)
                {
                    progress = -0.1f; progress_dir *= -1.0f;
                }
            }
            double progress_saturated = (progress < 0.0) ? 0.0 : (progress > 1.0f) ? 1.0 : progress;

            var percentText = string.Format("{0}%", (int)(progress_saturated * 100));
            GUILayout.BeginHorizontal("HGroup~1");
            GUILayout.BeginVertical("ProgressBars");
            GUILayout.ProgressBar("ProgressBar %", progress, (400, 20), percentText);

            const int total        = 1753;
            var       progressText = string.Format("{0}/{1}", (int)(progress_saturated * total), total);
            GUILayout.ProgressBar("ProgressBar /", progress, (400, 20), progressText);
            GUILayout.EndVertical();
            GUILayout.PushFixedWidth(100); //+2
            GUILayout.Text("Progress");
            GUILayout.PopStyle(2);         //-2
            GUILayout.EndHorizontal();

            GUILayout.PopStyle();//-1
            GUILayout.PopID();
        }

        if (GUILayout.CollapsingHeader("Layout", ref layoutOn))
        {
            GUILayout.PushID("_Layout");

            if (GUILayout.TreeNode("Child regions", ref childRegionsOpen))
            {
                GUILayout.Text("Without border");
                bool goto_line = GUILayout.Button("Goto");
                GUILayout.PushFixedWidth(100);//+2
                var newLine = GUILayout.InputInt("##Line", line);
                if (newLine != line)
                {
                    goto_line = true;
                }
                GUILayout.PopStyle(2);//-2

                using (GUILayout.HScope("HGroup~1"))
                {
                    if (GUILayout.BeginChild("Sub1", GUILayout.Height(300).ExpandWidth(true)))
                    {
                        for (int i = 0; i < 50; i++)
                        {
                            GUILayout.Text("{0,4}: scrollable region", i);
                            if (goto_line && line == i)
                            {
                                //SetScrollHere();//TODO
                            }
                        }
                        if (goto_line && line >= 10)
                        {
                            //SetScrollHere();//TODO
                        }
                        GUILayout.EndChild();
                    }

                    if (GUILayout.BeginChild("Sub2", GUILayout.Height(300).ExpandWidth(true)))
                    {
                        GUILayout.Text("With border");
                        for (int i = 0; i < 50; i++)
                        {
                            GUILayout.Button(string.Format("0x{0:X8}", i * 5731));
                        }
                        GUILayout.EndChild();
                    }
                }
                GUILayout.TreePop();
            }

            if (GUILayout.TreeNode("Stack layout", ref stackLayoutOpen))
            {
                GUILayout.Label("Three buttons of default size.");
                GUILayout.BeginHorizontal("H~~~1");
                {
                    GUILayout.Button("1~");
                    GUILayout.Button("2~~");
                    GUILayout.Button("3~~~");
                }
                GUILayout.EndHorizontal();
                GUILayout.Label("Three fixed-width (100 pixels) buttons.");
                GUILayout.BeginHorizontal("H~~~2");
                {
                    GUILayout.PushFixedWidth(100);
                    GUILayout.Button("1");
                    GUILayout.Button("2");
                    GUILayout.Button("3");
                    GUILayout.PopStyle(2);
                }
                GUILayout.EndHorizontal();
                GUILayout.Label("Three stretched sized buttons with 1/2/3 stretch factor.");
                GUILayout.BeginHorizontal("H~~~3");
                {
                    GUILayout.PushStyle(StylePropertyName.HorizontalStretchFactor, 1);
                    GUILayout.Button("1");
                    GUILayout.PopStyle();
                    GUILayout.PushStyle(StylePropertyName.HorizontalStretchFactor, 2);
                    GUILayout.Button("2");
                    GUILayout.PopStyle();
                    GUILayout.PushStyle(StylePropertyName.HorizontalStretchFactor, 3);
                    GUILayout.Button("3");
                    GUILayout.PopStyle();
                }
                GUILayout.EndHorizontal();
                GUILayout.TreePop();
            }

            if (GUILayout.TreeNode("Layout scopes", ref layoutScopesOpen))
            {
                /*
                 * H(V)Scope is a wrapper of BeginHorizontal(Vertical)/EndHorizontal(Vertical) API.
                 * It employs IDisposable so we don't need to call EndHorizontal(Vertical),
                 * because it is called automatically when H(V)Scope goes out of scope.
                 */
                using (GUILayout.HScope("HorizontalScope~", GUILayout.ExpandWidth(false)))
                {
                    GUILayout.Button("H1");
                    using (GUILayout.VScope("VerticalScope~", GUILayout.ExpandWidth(false)))
                    {
                        GUILayout.Button("V1");
                        GUILayout.Button("V2");
                    }
                    GUILayout.Button("H2");
                    GUILayout.Button("H3");
                }
                GUILayout.TreePop();
            }

            GUILayout.PopID();
        }

        if (GUILayout.CollapsingHeader("Style & Skin", ref skinOn))
        {
            GUILayout.PushID("_Skin");

            GUILayout.Button("MyButton1", this.smallRed);
            GUILayout.Button("MyButton2", new LayoutOptions().FontColor(Color.Blue).FontSize(40));

            GUILayout.PushBorder((10, 20, 30, 40));
            GUILayout.PushPadding((40, 30, 20, 10));
            GUILayout.PushStyle(StylePropertyName.BorderTopColor, Color.Red);
            GUILayout.PushStyle(StylePropertyName.BorderRightColor, Color.Green);
            GUILayout.PushStyle(StylePropertyName.BorderBottomColor, Color.Blue);
            GUILayout.PushStyle(StylePropertyName.BorderLeftColor, Color.Yellow);
            GUILayout.Button("Box Model", GUILayout.Width(161).Height(100));
            GUILayout.PopStyle(4 + 4 + 4);

            if (GUILayout.TreeNode("Default", ref defaultSkinOpen))
            {
                using (GUILayout.HScope("HorizontalScope~", GUILayout.ExpandWidth(false)))
                {
                    GUILayout.Button("Button 1");
                    GUILayout.Button("Button 2");
                    GUILayout.Button("Button 3");
                }
                GUILayout.TreePop();
            }

            if (GUILayout.TreeNode("dear imgui", ref dearImGuiSkinOpen))
            {
                GUI.SetSkin(dearImGuiSkinRules);
                using (GUILayout.HScope("HorizontalScope~", GUILayout.ExpandWidth(false)))
                {
                    GUILayout.Button("Button 1");
                    GUILayout.Button("Button 2");
                    GUILayout.Button("Button 3");
                }
                GUILayout.TreePop();
            }

            GUI.SetDefaultSkin();

            if (GUILayout.TreeNode("Windows 10", ref win10SkinOpen))
            {
                GUI.SetSkin(win10SkinRules);
                using (GUILayout.HScope("HorizontalScope~", GUILayout.ExpandWidth(false)))
                {
                    GUILayout.Button("Button 1");
                    GUILayout.Button("Button 2");
                    GUILayout.Button("Button 3");
                }
                GUILayout.TreePop();
            }

            GUI.SetDefaultSkin();

            GUILayout.PopID();
        }

        if (GUILayout.CollapsingHeader("Header", ref headerOn))
        {
            GUILayout.Button("Button A");
            GUILayout.Button("Button B");
            GUILayout.Button("Button C");
        }
        GUI.End();
    }
Esempio n. 21
0
        public static void ShowWindow(ref bool windowOpened)
        {
            if (!GUI.Begin(WindowName, ref windowOpened))
            {
                GUI.End();
                return;
            }

            // Basic info
            GUIContext g = GetCurrentContext();

            Text("Hello ImGui {0}##Metrics.Version", GetVersion());
            Text("Application average {0:F3} ms/frame ({1:F1} FPS)##Metrics.FPS", 1000.0f / g.fps, g.fps);
            Text("{0} vertices, {1} indices ({2} triangles)##Metrics.VI",
                 VertexNumber, IndexNumber, IndexNumber / 3);
            Text("{0} active windows ({0} visible)##Metrics.Window", ActiveWindows, RenderWindows);
            Separator("separator0");

            //Windows
            var windowManager = g.WindowManager;

            NodeWindows(windowManager.Windows.ToArray(), "Windows");

            //Internal state
            if (TreeNode("Internal state"))
            {
                var w = g.WindowManager;
                Text("HoveredWindow: '{0}'",
                     w.HoveredWindow != null ? w.HoveredWindow.Name : "null");
                Text("HoveredRootWindow: '{0}'",
                     w.HoveredRootWindow != null ? w.HoveredRootWindow.Name : "null");
                // Data is "in-flight" so depending on when the Metrics window is called we may see
                // current frame information or not
                Text("HoveredId: {0:X8}/{1:X8}, AllowOverlap: {2}",
                     g.HoverId, g.HoveredIdPreviousFrame, g.HoverIdAllowOverlap);
                Text("ActiveId: {0:X8}/{1:X8}, AllowOverlap: {2}",
                     g.ActiveId, g.ActiveIdPreviousFrame, g.ActiveIdAllowOverlap);
                Text("ActiveIdWindow: '{0}'",
                     w.ActiveIdWindow != null ? w.ActiveIdWindow.Name : "null");
                Text("MovingWindow: '{0}'", w.MovingWindow != null ? w.MovingWindow.Name : "null");
                TreePop();
            }

            if (TreeNode("Tools"))
            {
                // The Item Picker tool is super useful to visually select an item and break into the call-stack of where it was submitted.
                if (Button("Item Picker.."))
                {
                    lastPickedItemId = 0;
                    g.DebugStartItemPicker();
                }

                if (g.DebugItemPickerBreakID != 0)
                {
                    lastPickedItemId = g.DebugItemPickerBreakID;
                }

                if (lastPickedItemId != 0)
                {
                    //get picked node
                    Node pickedNode = null;
                    var  w          = g.WindowManager.Windows;
                    foreach (var window in w)
                    {
                        var node = window.RenderTree.GetNodeById(lastPickedItemId);
                        if (node != null)
                        {
                            pickedNode = node;
                            break;
                        }
                    }

                    DoBoxModel(pickedNode);
                }
                else if (g.HoveredIdPreviousFrame != 0)
                {
                    //get picking node
                    Node pickingNode = null;
                    var  w           = g.WindowManager.Windows;
                    foreach (var window in w)
                    {
                        var node = window.RenderTree.GetNodeById(g.HoveredIdPreviousFrame);
                        if (node != null)
                        {
                            pickingNode = node;
                            break;
                        }
                    }
                    DoBoxModel(pickingNode);
                }

                TreePop();
            }

            GUI.End();
        }
Esempio n. 22
0
 public override void OnPaint()
 {
     GUI.Begin("Properties");
     View?.OnPaint();
     GUI.End();
 }