Image control.
Inheritance: Control
 /// <summary>
 /// Initializes a new instance of the <see cref="ImageControlRenderer" /> class.
 /// </summary>
 /// <param name="layerType">Type of the layer.</param>
 public ImageControlRenderer(Type layerType)
     : base("ImageRenderer" + instances++, layerType)
 {
     this.Transform2D = null;
     this.Image = null;
     this.scale = Vector2.Zero;
     this.position = Vector2.Zero;
     this.origin = Vector2.Zero;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ImageControlRenderer" /> class.
 /// </summary>
 /// <param name="layerType">Type of the layer.</param>
 public ImageControlRenderer(Type layerType)
     : base("ImageRenderer" + instances++, layerType)
 {
     this.Transform2D = null;
     this.Image       = null;
     this.scale       = Vector2.Zero;
     this.position    = Vector2.Zero;
     this.origin      = Vector2.Zero;
 }
示例#3
0
        /// <summary>
        /// Handles the EntityInitialized event of the entity control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        private void Entity_EntityInitialized(object sender, EventArgs e)
        {
            if (!this.sizeDefineByUser)
            {
                ImageControl ic    = this.entity.FindChild("ImageControlEntity").FindComponent <ImageControl>();
                PanelControl panel = this.entity.FindComponent <PanelControl>();

                panel.Width  = ic.Width;
                panel.Height = ic.Height;
            }
        }
示例#4
0
        /// <summary>
        /// Handles the EntityInitialized event of the entity control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        private void Entity_EntityInitialized(object sender, EventArgs e)
        {
            Entity imageEntity = this.entity.FindChild("ImageEntity");

            if (imageEntity != null && !this.sizeDefineByUser && !this.backgroundIsColor)
            {
                ImageControl ic    = imageEntity.FindComponent <ImageControl>();
                PanelControl panel = this.entity.FindComponent <PanelControl>();

                panel.Width  = ic.Width;
                panel.Height = ic.Height;
            }
        }
示例#5
0
        /// <summary>
        /// Resolves the dependencies needed for this instance to work.
        /// </summary>
        protected override void ResolveDependencies()
        {
            base.ResolveDependencies();

            this.textControl      = Owner.FindChild("TextEntity").FindComponent <TextControl>();
            this.textBeforeCursor = this.textControl.Text;

            Entity cursorEntity = Owner.FindChild("CursorEntity");

            this.cursorTransform = cursorEntity.FindComponent <Transform2D>();
            this.cursorAnimation = cursorEntity.FindComponent <AnimationUI>();

            this.imageControl        = Owner.FindChild("ImageEntity").FindComponent <ImageControl>();
            this.imageControl.Width  = this.Panel.Width;
            this.imageControl.Height = this.Panel.Height;
        }
示例#6
0
        /// <summary>
        /// Resolves the dependencies needed for this instance to work.
        /// </summary>
        protected override void ResolveDependencies()
        {
            base.ResolveDependencies();

            Entity bulletEntity = Owner.FindChild("BulletEntity");

            this.bulletTransform    = bulletEntity.FindComponent <Transform2D>();
            this.bulletImage        = bulletEntity.FindComponent <ImageControl>();
            this.bulletImage.Width  = DefaultSliderWeight;
            this.bulletImage.Height = DefaultSliderWeight;

            Entity foregroundEntity = Owner.FindChild("ForegroundEntity");

            this.foregroundImage     = foregroundEntity.FindComponent <ImageControl>();
            this.foregroundTransform = foregroundEntity.FindComponent <Transform2D>();

            this.backgroundImage = Owner.FindChild("BackgroundEntity").FindComponent <ImageControl>();

            Entity textEntity = Owner.FindChild("TextEntity");

            this.textControl   = textEntity.FindComponent <TextControl>();
            this.textTransform = textEntity.FindComponent <Transform2D>();

            this.animation = textEntity.FindComponent <AnimationUI>();

            // Default parameters
            this.UpdateOrientation();

            // Initialization value
            switch (this.orientation)
            {
            case Orientation.Vertical:
                float result = this.maximunOffset * (this.value - this.minimum) / this.difference;
                this.bulletTransform.Y          = -result;
                this.foregroundTransform.YScale = result;
                break;

            case Orientation.Horizontal:
                this.bulletTransform.X          = this.maximunOffset * (this.value - this.minimum) / this.difference;
                this.foregroundTransform.XScale = this.bulletTransform.X;
                break;
            }
        }
示例#7
0
        /// <summary>
        /// Resolves the dependencies needed for this instance to work.
        /// </summary>
        protected override void ResolveDependencies()
        {
            base.ResolveDependencies();

            Entity foregroundEntity = Owner.FindChild("ForegroundEntity");

            this.foregroundImage     = foregroundEntity.FindComponent <ImageControl>();
            this.foregroundTransform = foregroundEntity.FindComponent <Transform2D>();

            this.foregroundImage.Height     = this.Panel.Height;
            this.foregroundImage.Width      = 1;
            this.foregroundTransform.XScale = this.Panel.Width * (this.value - this.minimum) / this.difference;

            this.backgroundImage = Owner.FindChild("BackgroundEntity").FindComponent <ImageControl>();

            this.backgroundImage.Width  = this.Panel.Width;
            this.backgroundImage.Height = this.Panel.Height;

            this.animation = foregroundEntity.FindComponent <AnimationUI>();
        }
示例#8
0
        /// <summary>
        /// Modifies the background image with the new asset path.
        /// </summary>
        /// <param name="imagePath">Path to the background image</param>
        private void ChangeBackgroundImage(string imagePath)
        {
            Entity       imageEntity     = this.entity.FindChild("ImageEntity");
            ImageControl newImageControl = new ImageControl(imagePath)
            {
                Stretch = Stretch.Fill,
            };

            if (imageEntity != null)
            {
                Transform2D transform = imageEntity.FindComponent <Transform2D>();
                RectangleF  rectangle = transform.Rectangle;

                rectangle.Offset(-rectangle.Width * transform.Origin.X, -rectangle.Height * transform.Origin.Y);

                // If imageEntity exist
                imageEntity.RemoveComponent <ImageControl>();
                imageEntity.AddComponent(newImageControl);
                imageEntity.RefreshDependencies();

                newImageControl.Arrange(rectangle);
            }
            else
            {
                // If imageEntity doesn't exist
                this.entity.AddChild(new Entity("ImageEntity")
                                     .AddComponent(new Transform2D()
                {
                    DrawOrder = 0.5f
                })
                                     .AddComponent(newImageControl)
                                     .AddComponent(new ImageControlRenderer()));

                this.entity.RefreshDependencies();
            }
        }
示例#9
0
        /// <summary>
        /// Resolves the dependencies needed for this instance to work.
        /// </summary>
        protected override void ResolveDependencies()
        {
            base.ResolveDependencies();

            this.textControl = Owner.FindChild("TextEntity").FindComponent<TextControl>();
            this.textBeforeCursor = this.textControl.Text;

            Entity cursorEntity = Owner.FindChild("CursorEntity");
            this.cursorTransform = cursorEntity.FindComponent<Transform2D>();
            this.cursorAnimation = cursorEntity.FindComponent<AnimationUI>();

            this.imageControl = Owner.FindChild("ImageEntity").FindComponent<ImageControl>();
            this.imageControl.Width = this.Panel.Width;
            this.imageControl.Height = this.Panel.Height;
        }
示例#10
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;
        }
示例#11
0
        /// <summary>
        /// Modifies the background image with the new asset path.
        /// </summary>
        /// <param name="imagePath">Path to the background image</param>
        private void ChangeBackgroundImage(string imagePath)
        {
            Entity imageEntity = this.entity.FindChild("ImageEntity");
            ImageControl newImageControl = new ImageControl(imagePath)
            {
                Stretch = Stretch.Fill,
            };

            if (imageEntity != null)
            {
                Transform2D transform = imageEntity.FindComponent<Transform2D>();
                RectangleF rectangle = transform.Rectangle;

                rectangle.Offset(-rectangle.Width * transform.Origin.X, -rectangle.Height * transform.Origin.Y);

                // If imageEntity exist
                imageEntity.RemoveComponent<ImageControl>();
                imageEntity.AddComponent(newImageControl);
                imageEntity.RefreshDependencies();

                newImageControl.Arrange(rectangle);
            }
            else
            {
                // If imageEntity doesn't exist
                this.entity.AddChild(new Entity("ImageEntity")
                    .AddComponent(new Transform2D()
                    {
                        DrawOrder = 0.5f
                    })
                    .AddComponent(newImageControl)
                    .AddComponent(new ImageControlRenderer()));

                this.entity.RefreshDependencies();
            }
        }
示例#12
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;
        }
        /// <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;
        }
示例#14
0
        protected override void ResolveDependencies()
        {
            base.ResolveDependencies();

            this.textControl = Owner.FindChild("TextEntity").FindComponent<TextControl>();

            this.imageControl = Owner.FindChild("ImageEntity").FindComponent<ImageControl>();
            this.imageControl.Width = this.Panel.Width;
            this.imageControl.Height = this.Panel.Height;
        }
        /// <summary>
        /// Resolves the dependencies needed for this instance to work.
        /// </summary>
        protected override void ResolveDependencies()
        {
            base.ResolveDependencies();

            Entity foregroundEntity = Owner.FindChild("ForegroundEntity");
            this.foregroundImage = foregroundEntity.FindComponent<ImageControl>();
            this.foregroundTransform = foregroundEntity.FindComponent<Transform2D>();

            this.foregroundImage.Height = this.Panel.Height;
            this.foregroundImage.Width = 1;
            this.foregroundTransform.XScale = this.Panel.Width * (this.value - this.minimum) / this.difference;

            this.backgroundImage = Owner.FindChild("BackgroundEntity").FindComponent<ImageControl>();

            this.backgroundImage.Width = this.Panel.Width;
            this.backgroundImage.Height = this.Panel.Height;

            this.animation = foregroundEntity.FindComponent<AnimationUI>();
        }
示例#16
0
        /// <summary>
        /// Resolves the dependencies needed for this instance to work.
        /// </summary>
        protected override void ResolveDependencies()
        {
            base.ResolveDependencies();

            Entity bulletEntity = Owner.FindChild("BulletEntity");
            this.bulletTransform = bulletEntity.FindComponent<Transform2D>();
            this.bulletImage = bulletEntity.FindComponent<ImageControl>();
            this.bulletImage.Width = DefaultSliderWeight;
            this.bulletImage.Height = DefaultSliderWeight;

            Entity foregroundEntity = Owner.FindChild("ForegroundEntity");
            this.foregroundImage = foregroundEntity.FindComponent<ImageControl>();
            this.foregroundTransform = foregroundEntity.FindComponent<Transform2D>();

            this.backgroundImage = Owner.FindChild("BackgroundEntity").FindComponent<ImageControl>();

            Entity textEntity = Owner.FindChild("TextEntity");
            this.textControl = textEntity.FindComponent<TextControl>();
            this.textTransform = textEntity.FindComponent<Transform2D>();

            this.animation = textEntity.FindComponent<AnimationUI>();

            // Default parameters
            this.UpdateOrientation();

            // Initialization value
            switch (this.orientation)
            {
                case Orientation.Vertical:
                    float result = this.maximunOffset * (this.value - this.minimum) / this.difference;
                    this.bulletTransform.Y = -result;
                    this.foregroundTransform.YScale = result;
                    break;
                case Orientation.Horizontal:
                    this.bulletTransform.X = this.maximunOffset * (this.value - this.minimum) / this.difference;
                    this.foregroundTransform.XScale = this.bulletTransform.X;
                    break;
            }
        }