コード例 #1
0
        public override void Draw(SpriteBatch spritebatch)
        {
            base.Draw(spritebatch);

            NoImageDropdownUp.Draw(spritebatch);
            ImageDropdownDown.Draw(spritebatch);
        }
コード例 #2
0
        public void Draw(SpriteBatch spriteBatch)
        {
            var sourceRect = CursorSprites.DropdownButton;

            var position = new Vector2(
                x: _categoryDropdown.bounds.X + _categoryDropdown.bounds.Width - 5,
                y: _categoryDropdown.bounds.Y + 10
                );

            spriteBatch.Draw(Game1.mouseCursors, position, sourceRect, Color.White, 0, Vector2.Zero, Game1.pixelZoom,
                             SpriteEffects.None, 1f);

            if (_categoryDropdown.IsExpanded)
            {
                spriteBatch.Draw(Game1.mouseCursors,
                                 new Vector2(position.X + 2 * Game1.pixelZoom, position.Y + 3 * Game1.pixelZoom),
                                 new Rectangle(sourceRect.X + 2, sourceRect.Y + 3, 5, 6), Color.White, 0, Vector2.Zero,
                                 Game1.pixelZoom, SpriteEffects.FlipVertically, 1f);
            }

            _categoryDropdown.Draw(spriteBatch);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: frederikja163/sfml-ui
        static void Main(string[] args)
        {
            RenderWindow window = new RenderWindow(new VideoMode(1280, 720), "Checkbox", Styles.Titlebar | Styles.Close);

            window.SetFramerateLimit(60);
            window.SetVerticalSyncEnabled(true);
            window.Closed += (_, __) => window.Close();

            Checkbox checkbox = new Checkbox(window, new Vector2f(150, 150));

            checkbox.Width          = 310;
            checkbox.Height         = 310;
            checkbox.CrossThickness = 20f;

            Button button = new Button(window, checkbox.Position + new Vector2f(checkbox.Width + 5, 0), new Vector2f(100, 100));

            button.ButtonPressed += () =>
            {
                button.CenterColor = new Color((byte)new Random().Next(255), (byte)new Random().Next(255),
                                               (byte)new Random().Next(255));
            };
            button.CenterColor = Color.Blue;

            Button button2 = new Button(window, button.Position + new Vector2f(0, button.Height + 5), button.Size);

            button2.CenterColor = Color.Green;

            Button button3 = new Button(window, button2.Position + new Vector2f(0, button2.Height + 5), button2.Size);


            TextInput textInput = new TextInput(window, button.Position + new Vector2f(button.Width + 5, 0), 500, 100, new Font("Arial.ttf"));

            Slider slider = new Slider(window, textInput.Position + new Vector2f(0, textInput.Height + 5), 500, 100, 0, 100);

            Dropdown dropdown = new Dropdown(window, checkbox.Position + new Vector2f(0, checkbox.Height + 5), new Font("Arial.ttf"), 59,
                                             "Lorem Ipsum",
                                             "Lorem Larum",
                                             "Lorem Lurum",
                                             "Lorem Durum"
                                             );

            TextBox textBox = new TextBox(window, slider.Position + new Vector2f(0, slider.Height + 5), textInput.Width, textInput.Height, new Font("Arial.ttf"), (uint)Math.Round(textInput.Height * 0.75));

            textBox.Output("DURUM");
            textBox.TextColor = Color.Black;

            Graphic graphic = new Graphic(window, "background.png", textBox.Position + new Vector2f(0, textBox.Height + 5), new Vector2f(0, 0), new Vector2f(textBox.Width, textBox.Height));

            button2.ButtonPressed += () =>
            {
                graphic.StartFlashing((long)(1 + 10 * slider.Value));
            };

            button3.ButtonPressed += () =>
            {
                graphic.StopFlashing();
            };

            RadioButton radioButton = new RadioButton(window, textInput.Position + new Vector2f(textInput.Width + 25, 0), 50, new Vector2f(0, 157), 3);

            while (window.IsOpen)
            {
                window.DispatchEvents();

                window.Clear();

                checkbox.Draw();
                button.Draw();
                textInput.Draw();
                slider.Draw();
                textInput.SetText(slider.Value.ToString());
                dropdown.Draw();
                textBox.Draw();
                graphic.Draw();
                button2.Draw();
                button3.Draw();
                radioButton.Draw();

                window.Display();
            }
        }
コード例 #4
0
        static void Main(string[] args)
        {
            RenderWindow Window = new RenderWindow(new VideoMode(1024, 768), "Graphic test", Styles.Titlebar | Styles.Close);

            Window.Closed += OnClose;
            SfmlUI.Graphic background = new SfmlUI.Graphic(Window, "background.png", new Vector2f(20, 20));
            SfmlUI.Graphic element    = new SfmlUI.Graphic(Window, "background.png", new Vector2f(820, 100), new Vector2f(100, 100), new Vector2f(100, 100));
            element.StartFlashing(300);
            SfmlUI.Graphic scaledElement = new SfmlUI.Graphic(Window, "background.png", new Vector2f(870, 250), new Vector2f(100, 200), new Vector2f(100, 100), 2f);
            scaledElement.Origin.Horizontal.Center();
            SfmlUI.Graphic element2 = new SfmlUI.Graphic(Window, "background.png", new Vector2f(870, 600), new Vector2f(500, 100), new Vector2f(100, 100));
            element2.Origin.Horizontal.Center();
            element2.Origin.Vertical.Center();
            element2.Fade(0.7f);
            SfmlUI.Graphic element3 = new SfmlUI.Graphic(Window, "background.png", new Vector2f(400, 600), new Vector2f(100, 200), new Vector2f(100, 100));
            element3.Color(255, 0, 0);
            SfmlUI.Graphic element4 = new SfmlUI.Graphic(Window, "background.png", new Vector2f(570, 600), new Vector2f(100, 200), new Vector2f(100, 100));
            element4.Rotate(45f);

            Window.KeyReleased += OnKeyReleased;

            Checkbox checkbox = new Checkbox(Window, new Vector2f(770, 470));

            checkbox.Width           = 50;
            checkbox.Height          = 50;
            checkbox.CrossThickness  = 5f;
            checkbox.CrossColor      = Color.Green;
            checkbox.FillColor       = Color.Black;
            checkbox.BorderEnabled   = true;
            checkbox.BorderColor     = Color.White;
            checkbox.BorderThickness = 5;
            checkbox.IsChecked       = true;

            var radioButton  = new RadioButton(Window, new Vector2f(950, 500), 14, new Vector2f(0, 40), 5, 3);
            var radioButton2 = new RadioButton(Window, new Vector2f(720, 550), 14, new Vector2f(0, 40), 5);

            Dropdown dropdown = new Dropdown(Window, new Vector2f(50, 550), new Font("ArialNova.ttf"), 30,
                                             "No Blink",
                                             "Fast",
                                             "Medium",
                                             "Slow"
                                             );
            Dropdown dropdown2 = new Dropdown(Window, new Vector2f(250, 550), new Font("ArialNova.ttf"), 30,
                                              "Red",
                                              "Green",
                                              "Blue",
                                              "Yellow",
                                              "Purple",
                                              "Cyan"
                                              );

            Window.MouseButtonReleased += OnMouseButtonReleased;

            int _lastRadio  = -2;
            int _lastRadio2 = -2;

            while (Window.IsOpen)
            {
                Window.DispatchEvents();

                Window.Clear();
                background.Draw();
                element.Draw();
                scaledElement.Draw();
                scaledElement.IsVisible = checkbox.IsChecked;
                checkbox.Draw();

                radioButton.Draw();
                if (radioButton._selected != _lastRadio)
                {
                    _lastRadio = radioButton._selected;
                    switch (_lastRadio)
                    {
                    case 0:
                        element2.StopFlashing();
                        break;

                    case 1:
                        element2.StartFlashing(1000);
                        break;

                    case 2:
                        element2.StartFlashing(600);
                        break;

                    case 3:
                        element2.StartFlashing(300);
                        break;

                    case 4:
                        element2.StartFlashing(100);
                        break;
                    }
                }
                radioButton2.Draw();
                if (radioButton2._selected != _lastRadio2)
                {
                    _lastRadio2 = radioButton2._selected;
                    switch (_lastRadio2)
                    {
                    case 0:
                        element4.Rotate(0);
                        break;

                    case 1:
                        element4.Rotate(45);
                        break;

                    case 2:
                        element4.Rotate(90);
                        break;

                    case 3:
                        element4.Rotation(30);
                        break;

                    case 4:
                        element4.Rotation(360);
                        break;
                    }
                }

                element2.Draw();
                element3.Draw();
                element4.Draw();
                dropdown.Draw();
                dropdown2.Draw();

                Window.Display();
            }

            void OnMouseButtonReleased(object sender, MouseButtonEventArgs e)
            {
                if (dropdown.ChosenItem == "No Blink")
                {
                    background.StopFlashing();
                }
                if (dropdown.ChosenItem == "Fast")
                {
                    background.StartFlashing(100);
                }
                if (dropdown.ChosenItem == "Medium")
                {
                    background.StartFlashing(300);
                }
                if (dropdown.ChosenItem == "Slow")
                {
                    background.StartFlashing(600);
                }
                if (dropdown2.ChosenItem == "Red")
                {
                    element3.Color(255, 0, 0);
                }
                if (dropdown2.ChosenItem == "Green")
                {
                    element3.Color(0, 255, 0);
                }
                if (dropdown2.ChosenItem == "Blue")
                {
                    element3.Color(0, 0, 255);
                }
                if (dropdown2.ChosenItem == "Yellow")
                {
                    element3.Color(255, 255, 0);
                }
                if (dropdown2.ChosenItem == "Purple")
                {
                    element3.Color(255, 0, 255);
                }
                if (dropdown2.ChosenItem == "Cyan")
                {
                    element3.Color(0, 255, 255);
                }
            }

            void OnKeyReleased(object sender, KeyEventArgs e)
            {
                if (e.Code == Keyboard.Key.H)
                {
                    Console.WriteLine("element Height: " + element.Height);
                }
                if (e.Code == Keyboard.Key.W)
                {
                    Console.WriteLine("scaledElement Width: " + scaledElement.Width);
                }
                if (e.Code == Keyboard.Key.B)
                {
                    element.StartFlashing(300);
                    Console.WriteLine("element Blikning");
                }
                if (e.Code == Keyboard.Key.F)
                {
                    element.StartFlashing(100);
                    Console.WriteLine("element Blikning fast");
                }
                if (e.Code == Keyboard.Key.S)
                {
                    element.StartFlashing(600);
                    Console.WriteLine("element Blining slowly");
                }
                if (e.Code == Keyboard.Key.N)
                {
                    element.StopFlashing();
                    Console.WriteLine("element Not Blinking");
                }
                if (e.Code == Keyboard.Key.I)
                {
                    background.IsVisible = false;
                    Console.WriteLine("background Invisible");
                }
                if (e.Code == Keyboard.Key.V)
                {
                    background.IsVisible = true;
                    Console.WriteLine("background Visible");
                }
                if (e.Code == Keyboard.Key.Escape)
                {
                    Window.Close();
                }
            }
        }
コード例 #5
0
        static void Main(string[] args)
        {
            RenderWindow   Window     = new RenderWindow(VideoMode.DesktopMode, "Dropdown Sandbox", Styles.Titlebar | Styles.Close);
            RectangleShape Background = new RectangleShape(new Vector2f(Window.Size.X, Window.Size.Y));

            Background.Position  = new Vector2f(0, 0);
            Background.FillColor = new Color(122, 122, 122, 255);
            Window.Closed       += OnClose;

            // dropdown 1
            Dropdown dropdown = new Dropdown(Window, new Vector2f(200, 150), new Font("ArialNova.ttf"), 30,
                                             "Lorem Ipsum",
                                             "Electric boogaloo",
                                             "James",
                                             "Brown fox",
                                             "Doc",
                                             "Docile",
                                             "Pizza",
                                             "Hut Hut",
                                             "Last item"
                                             );

            dropdown.OutlineColor     = Color.Cyan;
            dropdown.OutlineThickness = 50;
            dropdown.TextColor        = Color.Blue;
            dropdown.HighlightColor   = Color.Cyan;
            dropdown.BackgroundColor  = Color.Yellow;
            dropdown.FontSize         = 200;

            // Button
            Button button = new Button(Window, new Vector2f(200, 200), new Vector2f(100, 20));

            button.CenterColor    = Color.Black;
            button.OuterColor     = Color.Red;
            button.ButtonPressed += buttonPress;

            void buttonPress()
            {
                dropdown.AddItem("last time i was here i was just a kid");
            }

            // Checkbox
            Checkbox checkbox = new Checkbox(Window, new Vector2f(1000, 500));

            checkbox.FillColor  = Color.Yellow;
            checkbox.CrossColor = Color.Magenta;

            // RadioButton
            RadioButton radiobutton = new RadioButton(Window, new Vector2f(500, 700), 10f, new Vector2f(0, 50f), 3);

            // Slider
            Slider slider = new Slider(Window, new Vector2f(1080, 500), 200f, 50f, 0f, 100f);

            // Text input
            TextInput textinput = new TextInput(Window, new Vector2f(900, 80), 900f, 50f, new Font("ArialNova.ttf"));


            while (Window.IsOpen)
            {
                Window.DispatchEvents();

                Window.Clear();
                Window.Draw(Background);

                dropdown.Draw();
                button.Draw();
                checkbox.Draw();
                radiobutton.Draw();
                slider.Draw();
                textinput.Draw();

                Window.Display();
            }
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: frederikja163/sfml-ui
        static void Main(string[] args)
        {
            _window = new RenderWindow(new VideoMode(1000, 1000), "RadioButton");

            //RadioButton(RenderWindow = _window, startingPosition, globalRadius, lineSpacing, radioAmount)
            RadioButton radioButton = new RadioButton(_window, new Vector2f(100, 100), 30, new Vector2f(0, 100), 5);

            //TextBox(_window, position, ?, font, fontSize
            TextBox text1 = new TextBox(_window, new Vector2f(190, 115), 200f, 200f, new Font("Arial.ttf"), 30);

            text1.BackgroundColor = new Color(0, 0, 0, 0);
            text1.OutlineColor    = new Color(0, 0, 160);
            text1.TextColor       = Color.White;
            text1.Output("Radio button 1");

            TextBox text2 = new TextBox(_window, new Vector2f(190, 215), 200f, 200f, new Font("Arial.ttf"), 30);

            text2.BackgroundColor = new Color(0, 0, 0, 0);
            text2.OutlineColor    = new Color(0, 0, 160);
            text2.TextColor       = Color.White;
            text2.Output("Radio button 2");

            TextBox text3 = new TextBox(_window, new Vector2f(190, 315), 200f, 200f, new Font("Arial.ttf"), 30);

            text3.BackgroundColor = new Color(0, 0, 0, 0);
            text3.OutlineColor    = new Color(0, 0, 160);
            text3.TextColor       = Color.White;
            text3.Output("Radio button 3");

            TextBox text4 = new TextBox(_window, new Vector2f(190, 415), 200f, 200f, new Font("Arial.ttf"), 30);

            text4.BackgroundColor = new Color(0, 0, 0, 0);
            text4.OutlineColor    = new Color(0, 0, 160);
            text4.TextColor       = Color.White;
            text4.Output("Radio button 4");

            TextBox text5 = new TextBox(_window, new Vector2f(190, 515), 200f, 200f, new Font("Arial.ttf"), 30);

            text5.BackgroundColor = new Color(0, 0, 0, 0);
            text5.OutlineColor    = new Color(0, 0, 160);
            text5.TextColor       = Color.White;
            text5.Output("Radio button 5");

            TextBox text6 = new TextBox(_window, new Vector2f(100, 615), 200f, 200f, new Font("Arial.ttf"), 30);

            text6.BackgroundColor = new Color(0, 0, 0, 0);
            text6.OutlineColor    = new Color(0, 0, 160);
            text6.TextColor       = Color.White;

            //Slider(_window, position, length, height, min-value, max-value)
            Slider slider = new Slider(_window, new Vector2f(500, 100), 400f, 50f, 0f, 100f);

            TextBox text7 = new TextBox(_window, new Vector2f(600, 50), 200f, 200f, new Font("Arial.ttf"), 30);

            text7.BackgroundColor = new Color(0, 0, 0, 0);
            text7.OutlineColor    = new Color(0, 0, 160);
            text7.TextColor       = Color.White;

            //Button(_window, position, size)
            Button button = new Button(_window, new Vector2f(500, 200), new Vector2f(200, 200));

            button.Shape = Button.Shapes.Elipse;

            button.ButtonPressed  += buttonPressed;
            button.ButtonReleased += buttonReleased;

            Text8 = new TextBox(_window, new Vector2f(730, 275), 200f, 200f, new Font("Arial.ttf"), 30);
            Text8.BackgroundColor = new Color(0, 0, 0, 0);
            Text8.OutlineColor    = new Color(0, 0, 160);
            Text8.TextColor       = Color.White;
            Text8.Output("Not pressed");

            //Checkbox(_window, position)
            Checkbox checkbox = new Checkbox(_window, new Vector2f(500, 450));

            checkbox.Width          = 50;
            checkbox.Height         = 50;
            checkbox.CrossThickness = 5f;
            checkbox.FillColor      = new Color(255, 255, 255);
            checkbox.CrossColor     = new Color(100, 100, 100);

            TextBox text9 = new TextBox(_window, new Vector2f(575, 455), 200f, 200f, new Font("Arial.ttf"), 30);

            text9.BackgroundColor = new Color(0, 0, 0, 0);
            text9.OutlineColor    = new Color(0, 0, 160);
            text9.TextColor       = Color.White;

            //Dropdown(_window, position, font, fontSize)
            Dropdown dropdown = new Dropdown(_window, new Vector2f(100, 700), new Font("Arial.ttf"), 30,
                                             "Lorem Ipsum",
                                             "Electric boogaloo",
                                             "James",
                                             "Brown fox",
                                             "Doc",
                                             "Docile",
                                             "Pizza"
                                             );

            dropdown.OutlineColor     = new Color(100, 100, 100);
            dropdown.OutlineThickness = 50;
            dropdown.TextColor        = new Color(255, 255, 255);
            dropdown.HighlightColor   = new Color(255, 0, 0);;
            dropdown.BackgroundColor  = new Color(100, 100, 100);

            TextBox text10 = new TextBox(_window, new Vector2f(100, 775), 200f, 200f, new Font("Arial.ttf"), 30);

            text10.BackgroundColor = new Color(0, 0, 0, 0);
            text10.OutlineColor    = new Color(0, 0, 160);
            text10.TextColor       = Color.White;

            //TextInput(_window, position, width, height, font)
            TextInput textInput = new TextInput(_window, new Vector2f(500, 550), 400f, 50f, new Font("Arial.ttf"));

            textInput.OutlineColor = new Color(100, 100, 100);
            textInput.TextColor    = new Color(0, 0, 0);

            TextBox text11 = new TextBox(_window, new Vector2f(500, 625), 200f, 200f, new Font("Arial.ttf"), 30);

            text11.BackgroundColor = new Color(0, 0, 0, 0);
            text11.OutlineColor    = new Color(0, 0, 160);
            text11.TextColor       = Color.White;

            //Graphic(_window, "name.filetype", position)
            Graphic graphic = new Graphic(_window, "image.jpg", new Vector2f(500, 700));

            _window.Closed += WindowClosed;

            _window.SetFramerateLimit(60);
            _window.SetVerticalSyncEnabled(true);

            while (_window.IsOpen)
            {
                _window.DispatchEvents();
                _window.Clear();

                radioButton.Draw();
                text1.Draw();
                text2.Draw();
                text3.Draw();
                text4.Draw();
                text5.Draw();
                if (radioButton._selected == -1)
                {
                    text6.Output("Selected button: none");
                }
                else
                {
                    text6.Output("Selected button: " + (radioButton._selected + 1));
                }
                text6.Draw();

                slider.Draw();
                text7.Output(slider.Value.ToString());
                text7.Draw();

                button.Draw();
                Text8.Draw();

                checkbox.Draw();
                if (checkbox.IsChecked == true)
                {
                    text9.Output("Checked");
                }
                else
                {
                    text9.Output("Unchecked");
                }
                text9.Draw();

                text10.Output("Selected: " + dropdown.ChosenItem);
                text10.Draw();
                dropdown.Draw();

                textInput.Draw();
                text11.Output("Input: " + textInput.Text);
                text11.Draw();

                graphic.Draw();

                _window.Display();
            }
        }