The CheckBoxBehavior class.
Inheritance: FocusBehavior
Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CheckBox" /> class.
        /// </summary>
        /// <param name="name">The name.</param>
        public CheckBox(string name)
        {
            this.entity = new Entity(name)
                          .AddComponent(new Transform2D())
                          .AddComponent(new RectangleCollider2D())
                          .AddComponent(new TouchGestures(false))
                          .AddComponent(new CheckBoxBehavior())
                          .AddComponent(new GridControl(150, 42))
                          .AddComponent(new GridRenderer());

            this.gridPanel = this.entity.FindComponent <GridControl>();
            this.gridPanel.RowDefinitions.Add(new RowDefinition()
            {
                Height = new GridLength(1, GridUnitType.Proportional)
            });
            this.gridPanel.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(1, GridUnitType.Auto)
            });
            this.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());

            this.imageUnchecked = imageUnCheckedEntity.FindComponent <ImageControl>();
            this.imageUnchecked.SetValue(GridControl.RowProperty, 0);
            this.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());

            this.imageChecked = imageCheckedEntity.FindComponent <ImageControl>();
            this.imageChecked.SetValue(GridControl.RowProperty, 0);
            this.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   = "CheckBox",
                Margin = DefaultMargin
            })
                                .AddComponent(new TextControlRenderer());

            this.textControl = textEntity.FindComponent <TextControl>();
            this.textControl.SetValue(GridControl.RowProperty, 0);
            this.textControl.SetValue(GridControl.ColumnProperty, 1);
            this.textControl.OnWidthChanged += this.TextControl_OnWidthChanged;

            this.entity.AddChild(textEntity);

            // Cached
            this.checkBoxBehavior = this.entity.FindComponent <CheckBoxBehavior>();

            // Events
            this.checkBoxBehavior.CheckedChanged -= this.CheckBox_CheckedChanged;
            this.checkBoxBehavior.CheckedChanged += this.CheckBox_CheckedChanged;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CheckBox" /> class.
        /// </summary>
        /// <param name="name">The name.</param>
        public CheckBox(string name)
        {
            this.entity = new Entity(name)
                           .AddComponent(new Transform2D())
                           .AddComponent(new RectangleCollider2D())
                           .AddComponent(new TouchGestures(false))
                           .AddComponent(new CheckBoxBehavior())
                           .AddComponent(new GridControl(150, 42))
                           .AddComponent(new GridRenderer());

            this.gridPanel = this.entity.FindComponent<GridControl>();
            this.gridPanel.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Proportional) });
            this.gridPanel.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto) });
            this.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());

            this.imageUnchecked = imageUnCheckedEntity.FindComponent<ImageControl>();
            this.imageUnchecked.SetValue(GridControl.RowProperty, 0);
            this.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());

            this.imageChecked = imageCheckedEntity.FindComponent<ImageControl>();
            this.imageChecked.SetValue(GridControl.RowProperty, 0);
            this.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 = "CheckBox",
                                        Margin = DefaultMargin
                                    })
                                    .AddComponent(new TextControlRenderer());

            this.textControl = textEntity.FindComponent<TextControl>();
            this.textControl.SetValue(GridControl.RowProperty, 0);
            this.textControl.SetValue(GridControl.ColumnProperty, 1);
            this.textControl.OnWidthChanged += this.TextControl_OnWidthChanged;

            this.entity.AddChild(textEntity);

            // Cached
            this.checkBoxBehavior = this.entity.FindComponent<CheckBoxBehavior>();

            // Events
            this.checkBoxBehavior.CheckedChanged -= this.CheckBox_CheckedChanged;
            this.checkBoxBehavior.CheckedChanged += this.CheckBox_CheckedChanged;
        }