Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ToggleSwitch" /> class.
        /// </summary>
        /// <param name="name">The name.</param>
        public ToggleSwitch(string name)
        {
            this.entity = new Entity(name)
                          .AddComponent(new Transform2D())
                          .AddComponent(new RectangleCollider())
                          .AddComponent(new TouchGestures(false))
                          .AddComponent(new GridControl(100, 42))
                          .AddComponent(new GridRenderer())
                          .AddComponent(new ToggleSwitchBehavior());

            GridControl gridPanel = this.entity.FindComponent <GridControl>();

            gridPanel.RowDefinitions.Add(new RowDefinition()
            {
                Height = new GridLength(1, GridUnitType.Proportional)
            });
            gridPanel.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(1, GridUnitType.Auto)
            });
            gridPanel.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(1, GridUnitType.Proportional)
            });

            // Text
            Entity textEntity = new Entity("TextEntity")
                                .AddComponent(new Transform2D()
            {
                DrawOrder = 0.4f
            })
                                .AddComponent(new TextControl()
            {
                Text   = "Off",
                Margin = DefaultTextMargin
            })
                                .AddComponent(new TextControlRenderer());

            TextControl text = textEntity.FindComponent <TextControl>();

            text.SetValue(GridControl.RowProperty, 0);
            text.SetValue(GridControl.ColumnProperty, 0);

            this.entity.AddChild(textEntity);

            // Background
            Entity backgroundEntity = new Entity("BackgroundEntity")
                                      .AddComponent(new Transform2D()
            {
                DrawOrder = 0.5f
            })
                                      .AddComponent(new ImageControl(Color.Blue, DefaultWidth, DefaultHeight)
            {
                Margin = DefaultSliderMargin
            })
                                      .AddComponent(new ImageControlRenderer());

            ImageControl background = backgroundEntity.FindComponent <ImageControl>();

            background.SetValue(GridControl.RowProperty, 0);
            background.SetValue(GridControl.ColumnProperty, 1);

            this.entity.AddChild(backgroundEntity);

            // Foreground
            Entity foregroundEntity = new Entity("ForegroundEntity")
                                      .AddComponent(new Transform2D()
            {
                DrawOrder = 0.45f
            })
                                      .AddComponent(new AnimationUI())
                                      .AddComponent(new ImageControl(Color.LightBlue, 1, DefaultHeight)
            {
                Margin = DefaultSliderMargin
            })
                                      .AddComponent(new ImageControlRenderer());

            ImageControl foreground = foregroundEntity.FindComponent <ImageControl>();

            foreground.SetValue(GridControl.RowProperty, 0);
            foreground.SetValue(GridControl.ColumnProperty, 1);

            this.entity.AddChild(foregroundEntity);

            // Bullet
            Entity bulletEntity = new Entity("BulletEntity")
                                  .AddComponent(new Transform2D()
            {
                DrawOrder = 0.4f
            })
                                  .AddComponent(new AnimationUI())
                                  .AddComponent(new ImageControl(Color.White, DefaultHeight, DefaultHeight)
            {
                Margin = DefaultSliderMargin
            })
                                  .AddComponent(new ImageControlRenderer());

            ImageControl bullet = bulletEntity.FindComponent <ImageControl>();

            bullet.SetValue(GridControl.RowProperty, 0);
            bullet.SetValue(GridControl.ColumnProperty, 1);

            this.entity.AddChild(bulletEntity);

            // Event
            this.entity.FindComponent <ToggleSwitchBehavior>().Toggled += this.ToggleSwitch_Toggled;
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RadioButton" /> class.
        /// </summary>
        /// <param name="name">The name.</param>
        public RadioButton(string name)
        {
            this.entity = new Entity(name)
                          .AddComponent(new Transform2D())
                          .AddComponent(new RectangleCollider())
                          .AddComponent(new TouchGestures(false))
                          .AddComponent(new RadioButtonBehavior())
                          .AddComponent(new GridControl(170, 42))
                          .AddComponent(new GridRenderer());

            GridControl gridPanel = this.entity.FindComponent <GridControl>();

            gridPanel.RowDefinitions.Add(new RowDefinition()
            {
                Height = new GridLength(1, GridUnitType.Proportional)
            });
            gridPanel.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(1, GridUnitType.Auto)
            });
            gridPanel.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(1, GridUnitType.Proportional)
            });

            // Image Unchecked
            Entity imageUnCheckedEntity = new Entity("ImageUncheckedEntity")
                                          .AddComponent(new Transform2D()
            {
                DrawOrder = 0.5f
            })
                                          .AddComponent(new ImageControl(Color.White, DefaultUncheckedImage, DefaultUncheckedImage)
            {
                Margin = DefaultMargin,
                HorizontalAlignment = HorizontalAlignment.Center
            })
                                          .AddComponent(new ImageControlRenderer());

            ImageControl imageUnchecked = imageUnCheckedEntity.FindComponent <ImageControl>();

            imageUnchecked.SetValue(GridControl.RowProperty, 0);
            imageUnchecked.SetValue(GridControl.ColumnProperty, 0);

            this.entity.AddChild(imageUnCheckedEntity);

            // Image Checked
            Entity imageCheckedEntity = new Entity("ImageCheckedEntity")
                                        .AddComponent(new Transform2D()
            {
                DrawOrder = 0.45f,
                Opacity   = 0
            })
                                        .AddComponent(new AnimationUI())
                                        .AddComponent(new ImageControl(Color.Black, DefaultCheckedImage, DefaultCheckedImage)
            {
                Margin = DefaultCheckedImageMargin,
                HorizontalAlignment = HorizontalAlignment.Center
            })
                                        .AddComponent(new ImageControlRenderer());

            ImageControl imageChecked = imageCheckedEntity.FindComponent <ImageControl>();

            imageChecked.SetValue(GridControl.RowProperty, 0);
            imageChecked.SetValue(GridControl.ColumnProperty, 0);

            this.entity.AddChild(imageCheckedEntity);

            // Text
            Entity textEntity = new Entity("TextEntity")
                                .AddComponent(new Transform2D()
            {
                DrawOrder = 0.4f
            })
                                .AddComponent(new TextControl()
            {
                Text   = "RadioButton",
                Margin = DefaultMargin
            })
                                .AddComponent(new TextControlRenderer());

            TextControl textControl = textEntity.FindComponent <TextControl>();

            textControl.SetValue(GridControl.RowProperty, 0);
            textControl.SetValue(GridControl.ColumnProperty, 1);

            this.entity.AddChild(textEntity);

            // Cached
            this.radioButtonBehavior = this.entity.FindComponent <RadioButtonBehavior>();

            // Events
            this.radioButtonBehavior.CheckedChanged -= this.RadioButtonBehavior_CheckedChanged;
            this.radioButtonBehavior.CheckedChanged += this.RadioButtonBehavior_CheckedChanged;
        }