Beispiel #1
0
        public SelectDemoScreen(GuiSkin skin, IDictionary <string, DemoBase> demos, Action <string> loadDemo, Action exitGameAction)
            : base(skin)
        {
            _demos    = demos;
            _loadDemo = loadDemo;
            //var button = Skin.Create<GuiButton>("white-button", c =>
            //{
            //    c.Position = new Vector2(670, 430);
            //    c.Size = new Size2(120, 42);
            //    c.Text = "Next Demo";
            //});
            //var canvas = new GuiCanvas
            //{
            //    Controls = { button }
            //};

            //Controls.Add(canvas);
            //button.Clicked += (sender, args) => onNextDemo();

            var dialog = Skin.Create <GuiDialog>("dialog");
            var grid   = new GuiUniformGrid {
                Columns = 3
            };

            foreach (var demo in _demos.Values.OrderBy(i => i.Name))
            {
                var button = Skin.Create <GuiButton>("white-button", c =>
                {
                    c.Text     = demo.Name;
                    c.Margin   = new Thickness(4);
                    c.Clicked += (sender, args) => LoadDemo(demo);
                });
                grid.Controls.Add(button);
            }

            // Close button
            var atlas             = skin.TextureAtlases[0];
            var closeButtonRegion = atlas?.GetRegion("buttonRound_close");

            if (closeButtonRegion != null)
            {
                var closeButton = Skin.Create <GuiButton>("white-button", c =>
                {
                    c.IconRegion = closeButtonRegion;
                    c.Margin     = new Thickness(4);
                    c.Clicked   += (sender, args) => exitGameAction();
                });
                grid.Controls.Add(closeButton);
            }

            dialog.Controls.Add(grid);
            Controls.Add(dialog);
            //DialogDemo();
        }
        public GuiLayoutScreen(GuiSkin skin, GraphicsDevice graphicsDevice)
            : base(skin)
        {
            _texture = new Texture2D(graphicsDevice, 1, 1);
            _texture.SetData(new[] { new Color(Color.Black, 0.5f) });

            var backgroundRegion = new TextureRegion2D(_texture);

            var uniformGrid = new GuiUniformGrid(skin)
            {
                Text     = "Uniform Grid",
                Controls =
                {
                    new GuiCanvas(skin)
                    {
                        Text     = "Canvas",
                        Controls =
                        {
                            Skin.Create <GuiButton>("white-button", c =>{ c.Text                                                  = "Reasonably long text"; c.Position = new Vector2(0,       0); }),
                            Skin.Create <GuiButton>("white-button", c =>{ c.Text                                                  = "Child 2"; c.Position              = new Vector2(50,     50); }),
                            Skin.Create <GuiButton>("white-button", c =>{ c.Text                                                  = "Child 3"; c.Position              = new Vector2(100,   100); }),
                        }
                    },
                    new GuiStackPanel(skin)
                    {
                        Text        = "Stack Panel (Vertical)",
                        Orientation = GuiOrientation.Vertical,
                        Controls    =
                        {
                            Skin.Create <GuiButton>("white-button", c =>{ c.Text                                                  = "Child 1"; c.HorizontalAlignment   = HorizontalAlignment.Centre; }),
                            Skin.Create <GuiButton>("white-button", c =>{ c.Text                                                  = "Child 2"; c.HorizontalAlignment   = HorizontalAlignment.Right;  }),
                            Skin.Create <GuiButton>("white-button", c =>{ c.Text                                                  = "Child 3"; c.HorizontalAlignment   = HorizontalAlignment.Left;   }),
                            Skin.Create <GuiButton>("white-button", c =>{ c.Text                                                  = "Child 4"; }),
                        }
                    },
                    new GuiStackPanel(skin)
                    {
                        Text        = "Stack Panel (Horizontal)",
                        Orientation = GuiOrientation.Horizontal,
                        Controls    =
                        {
                            Skin.Create <GuiButton>("white-button", c =>{ c.Text                                                  = "Child 1"; c.Width                 =80; c.VerticalAlignment = VerticalAlignment.Centre; }),
                            Skin.Create <GuiButton>("white-button", c =>{ c.Text                                                  = "Child 2"; c.Width                 =80; c.VerticalAlignment = VerticalAlignment.Top;    }),
                            Skin.Create <GuiButton>("white-button", c =>{ c.Text                                                  = "Child 3"; c.Width                 =80; c.VerticalAlignment = VerticalAlignment.Bottom; }),
                            Skin.Create <GuiButton>("white-button", c =>{ c.Text                                                  = "Child 3"; c.Width                 =          80; }),
                        }
                    },
                    new GuiListBox(skin)
                    {
                        Name = "DisplayModesListBox"
                    }
                }
            };

            //var stackPanel = ;
            //stackPanel.PerformLayout();

            Controls.Add(uniformGrid);

            var listBox = FindControl <GuiListBox>("DisplayModesListBox");

            listBox.Items.AddRange(GraphicsAdapter.DefaultAdapter.SupportedDisplayModes.Select(i => $"{i.Width}x{i.Height}"));
        }