예제 #1
0
        /// <summary>
        /// Loads the content of the control.
        /// </summary>
        protected override void LoadContent()
        {
            base.LoadContent();

            _listBoxContent = new XAMLiteLabelNew(Game)
            {
                Content             = Content,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top,
                FontFamily          = FontFamily,
                Spacing             = Spacing,
                Padding             = Padding,
                Foreground          = Foreground,
                Opacity             = IsEnabled ? 1f : 0.65f,
                DrawOrder           = Parent.DrawOrder
            };
            Game.Components.Add(_listBoxContent);

            var w = _listBoxContent.MeasureString().X + Padding.Left + Padding.Right;
            var h = _listBoxContent.MeasureString().Y + Padding.Top + Padding.Bottom;

            if (w > Width)
            {
                Width = (int)w;
            }

            if (h > Height)
            {
                Height = (int)h;
            }

            var width = _listBoxContent.Width + (int)Padding.Left + (int)Padding.Right;

            if (Parent.Width < width)
            {
                var parent = (XAMLiteListBox)Parent;
                parent.UpdateWidth(width);
            }

            Game.Components.Remove(_listBoxContent);

            BackgroundPanel = new XAMLiteRectangleNew(Game)
            {
                Width  = Width,
                Height = Height,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top,
                Margin    = new Thickness(BorderThickness.Left, 0, BorderThickness.Top, BorderThickness.Bottom),
                Opacity   = 0.45f,
                DrawOrder = Parent.DrawOrder
            };
            Children.Add(BackgroundPanel);

            Children.Add(_listBoxContent);

            _parent = (XAMLiteListBox)Parent;
        }
예제 #2
0
        /// <summary>
        /// Loads the content for the control.
        /// </summary>
        protected override void LoadContent()
        {
            base.LoadContent();

            var checkBoxAsset = Game.Content.Load <Texture2D>(RadioButtonSourceName);

            _label = new XAMLiteLabelNew(Game)
            {
                Content           = Content,
                FontFamily        = FontFamily,
                Foreground        = Foreground,
                Spacing           = Spacing,
                Margin            = new Thickness(checkBoxAsset.Width + Padding.Left, 0, 0, 0),
                VerticalAlignment = VerticalAlignment.Center,
                Padding           = Padding,
                DrawOrder         = DrawOrder
            };
            Game.Components.Add(_label);

            // determine width and height
            Width  = (int)(_label.MeasureString().X + checkBoxAsset.Width + Padding.Left + Padding.Right + _label.Margin.Left);
            Height = (int)(_label.MeasureString().Y + Padding.Top + Padding.Bottom);

            Game.Components.Remove(_label);
            Children.Add(_label);

            _uncheckedBox = new XAMLiteImageNew(Game, checkBoxAsset)
            {
                VerticalAlignment   = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Left,
                Visibility          = !IsChecked ? Visibility.Visible : Visibility.Hidden
            };
            Children.Add(_uncheckedBox);

            _checkedBox = new XAMLiteImageNew(Game)
            {
                SourceName          = RadioButtonSelectedSourceName,
                VerticalAlignment   = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Left,
                Visibility          = IsChecked ? Visibility.Visible : Visibility.Hidden
            };
            Children.Add(_checkedBox);

            RadioButtonList.Add(this);
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        protected override void LoadContent()
        {
            base.LoadContent();

            _previousText = Text;

            _passwordMask = new XAMLiteLabelNew(Game)
            {
                FontFamily        = new FontFamily("Webdings08"),
                VerticalAlignment = VerticalAlignment.Center,
                Padding           = new Thickness(BorderThickness.Left > 1 ? Padding.Left + BorderThickness.Left : Padding.Left,
                                                  BorderThickness.Top > 1 ? Padding.Top + BorderThickness.Top : Padding.Top, 0, 0),
                HorizontalAlignment = TextAlignment == TextAlignment.Left ||
                                      TextAlignment == TextAlignment.Justify ?
                                      HorizontalAlignment.Left : TextAlignment == TextAlignment.Center ?
                                      HorizontalAlignment.Center : HorizontalAlignment.Right,
                Spacing = Spacing
            };
            Children.Add(_passwordMask);

            _currentCharacter = new XAMLiteLabelNew(Game)
            {
                FontFamily        = FontFamily,
                Spacing           = Spacing,
                Content           = " ",
                VerticalAlignment = VerticalAlignment.Center,
                Padding           = new Thickness(BorderThickness.Left > 1 ? Padding.Left + BorderThickness.Left : Padding.Left,
                                                  BorderThickness.Top > 1 ? Padding.Top + BorderThickness.Top : Padding.Top, 0, 0),
                HorizontalAlignment = TextAlignment == TextAlignment.Left ||
                                      TextAlignment == TextAlignment.Justify ?
                                      HorizontalAlignment.Left : TextAlignment == TextAlignment.Center ?
                                      HorizontalAlignment.Center : HorizontalAlignment.Right,
                Visibility = Visibility.Hidden
            };
            Children.Add(_currentCharacter);

            _previousText = Text;
        }
예제 #4
0
        /// <summary>
        ///
        /// </summary>
        protected override void LoadContent()
        {
            base.LoadContent();

            Debug.Assert((SourceName != null), "Must set CheckBoxSourceName property. This is the image file path, minus the file extension.");
            _texture = Game.Content.Load <Texture2D>(SourceName);

            Debug.Assert((CheckedSourceName != null), "Must set CheckBoxSelectedSourceName property. This is the image file path, minus the file extension.");

            _label = new XAMLiteLabelNew(Game)
            {
                Content           = Content,
                FontFamily        = FontFamily,
                Foreground        = Foreground,
                Spacing           = Spacing,
                Margin            = new Thickness(_texture.Width + Padding.Left, 0, 0, 0),
                VerticalAlignment = VerticalAlignment.Center,
                DrawOrder         = DrawOrder
            };
            Game.Components.Add(_label);

            // determine width and height
            Width  = (int)(_label.MeasureString().X + _texture.Width + Padding.Left + Padding.Right + _label.Margin.Left);
            Height = (int)(_label.MeasureString().Y + Padding.Top + Padding.Bottom);

            Game.Components.Remove(_label);
            Children.Add(_label);

            _uncheckedButton = new XAMLiteImageNew(Game)
            {
                SourceName          = SourceName,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Center,
                Visibility          = !IsChecked ? Visibility.Visible : Visibility.Hidden
            };
            Children.Add(_uncheckedButton);

            if (HoverSourceName != null)
            {
                _uncheckedHoverButton = new XAMLiteImageNew(Game)
                {
                    SourceName          = HoverSourceName,
                    HorizontalAlignment = HorizontalAlignment.Left,
                    VerticalAlignment   = VerticalAlignment.Center,
                    Visibility          = Visibility.Hidden
                };
                Children.Add(_uncheckedHoverButton);
            }

            _checkedButton = new XAMLiteImageNew(Game)
            {
                SourceName          = CheckedSourceName,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Center,
                Visibility          = IsChecked ? Visibility.Visible : Visibility.Hidden
            };
            Children.Add(_checkedButton);

            if (HoverCheckedSourceName != null)
            {
                _checkedHoverButton = new XAMLiteImageNew(Game)
                {
                    SourceName          = HoverCheckedSourceName,
                    HorizontalAlignment = HorizontalAlignment.Left,
                    VerticalAlignment   = VerticalAlignment.Center,
                    Visibility          = Visibility.Hidden
                };
                Children.Add(_checkedHoverButton);
            }
        }
예제 #5
0
        /// <summary>
        /// Loads the content of the control.
        /// </summary>
        protected override void LoadContent()
        {
            base.LoadContent();

            if (HasItems)
            {
                _dropShadow = new XAMLiteRectangleNew(Game)
                {
                    Width      = Width,
                    Height     = Height,
                    Fill       = Brushes.Black,
                    Visibility = Visibility.Hidden,
                    Opacity    = 0.15f
                };
                Children.Add(_dropShadow);

                _backdrop = new XAMLiteRectangleNew(Game)
                {
                    Width           = Width,
                    Height          = Height,
                    Fill            = ItemsBackground,
                    Stroke          = Brushes.Black,
                    StrokeThickness = 1,
                    Visibility      = Visibility.Hidden
                };
                Children.Add(_backdrop);
            }

            _label = new XAMLiteLabelNew(Game)
            {
                Content             = Header,
                Foreground          = Foreground == Brushes.Transparent ? Brushes.Black : Foreground,
                FontFamily          = FontFamily,
                Spacing             = Spacing,
                Padding             = Padding,
                HorizontalAlignment = HorizontalAlignment.Left,
                Opacity             = IsEnabled ? 1f : 0.55f
            };
            Game.Components.Add(_label);

            var w = _label.MeasureString().X + Padding.Left + Padding.Right;
            var h = _label.MeasureString().Y + Padding.Top + Padding.Bottom;

            if (w > Width)
            {
                Width = (int)w;
            }

            if (h > Height)
            {
                Height = (int)h;
            }

            Game.Components.Remove(_label);

            // Max BorderBrush size in WPF is 1.
            if (BorderBrush != Brushes.Transparent)
            {
                BorderThickness = new Thickness(1);
            }

            var topMargin = 0;

            //var gradientLevel = 1;
            if (Parent is XAMLiteMenuNew)
            {
                var m = Margin;
                topMargin = (Parent.Height - Height) / 2;
                Margin    = new Thickness(m.Left, topMargin, m.Right, m.Bottom);
                //gradientLevel = (Parent as XAMLiteMenuNew).UpperGradientBrightness;
            }

            if (HoverBrush != Brushes.Transparent)
            {
                var isBright = ColorHelper.Brightness(HoverBrush) > (IsMenuHead ? ColorHelper.Brightness(Parent.Background) : ColorHelper.Brightness(ItemsBackground));

                _highlightedBackground = new XAMLiteImageNew(Game, GradientTextureBuilder.CreateGradientTexture(Game, 5, Height, !isBright ? 55 : 100))
                {
                    RenderTransform     = isBright ? RenderTransform.FlipVertical : RenderTransform.Normal,
                    Background          = HoverBrush,
                    Width               = Width,
                    Height              = Height - 2,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center,
                    Opacity             = 0.45f,
                    DrawOrder           = Parent.DrawOrder,
                    Visibility          = Visibility.Hidden
                };
                Children.Add(_highlightedBackground);
            }

            LoadHighlightEdges();

            if (HasItems && !IsMenuHead)
            {
                _arrow = new XAMLiteImageNew(Game)
                {
                    SourceName          = "Icons/menu-item-arrow",
                    Background          = _label.Foreground,
                    HorizontalAlignment = HorizontalAlignment.Right,
                    VerticalAlignment   = VerticalAlignment.Center,
                    Margin      = new Thickness(0, 0, 15, 0),
                    IsColorized = true
                };
                Children.Add(_arrow);
            }

            if (IsCheckable)
            {
                _checkmark = new XAMLiteImageNew(Game)
                {
                    SourceName          = "Icons/checkmark",
                    Background          = _label.Foreground,
                    HorizontalAlignment = HorizontalAlignment.Left,
                    VerticalAlignment   = VerticalAlignment.Center,
                    Margin      = new Thickness(12, 0, 0, 0),
                    Visibility  = IsChecked ? Visibility.Visible : Visibility.Hidden,
                    IsColorized = true
                };
                Children.Add(_checkmark);
            }

            Children.Add(_label);
        }
예제 #6
0
        /// <summary>
        /// Loads the text box content.
        /// </summary>
        protected override void LoadContent()
        {
            base.LoadContent();

            InitialText     = Text;
            _initialPadding = Padding.Left;

            _textLabel = new XAMLiteLabelNew(Game)
            {
                Content             = Text,
                HorizontalAlignment = TextAlignment == TextAlignment.Left ||
                                      TextAlignment == TextAlignment.Justify ?
                                      HorizontalAlignment.Left : TextAlignment == TextAlignment.Center ?
                                      HorizontalAlignment.Center : HorizontalAlignment.Right,
                VerticalAlignment = VerticalAlignment.Center,
                FontFamily        = FontFamily,
                Spacing           = Spacing,
                Foreground        = Foreground,
                Padding           = new Thickness(BorderThickness.Left > 1 ? Padding.Left + BorderThickness.Left : Padding.Left,
                                                  BorderThickness.Top > 1 ? Padding.Top + BorderThickness.Top : Padding.Top, 0, 0),
                DrawOrder = DrawOrder + 2
            };

            // the developer did not set a specific Width and therefore, the
            // control needs to be quickly added to get a measurement.  Then
            // it is removed and added to the grid.
            if (_textLabel.Width == 0)
            {
                Game.Components.Add(_textLabel);
            }

            // get the width and height of the text label to make sure the
            // control will be large enough to contain it.
            if (Width < (int)_textLabel.MeasureString().X + (int)_textLabel.Padding.Left + (int)_textLabel.Padding.Right)
            {
                var pl = 0;

                if (_textLabel.Padding.Right == 0)
                {
                    pl = _textLabel.Padding.Left > 0 ? (int)_textLabel.Padding.Left : 5;
                }

                Width = (int)_textLabel.MeasureString().X + (int)_textLabel.Padding.Left + (int)_textLabel.Padding.Right + pl;
            }

            if (Height < (int)_textLabel.MeasureString().Y + (int)_textLabel.Padding.Top + (int)_textLabel.Padding.Bottom)
            {
                Height = (int)_textLabel.MeasureString().Y + (int)_textLabel.Padding.Top + (int)_textLabel.Padding.Bottom;
            }

            // If it was added as a component already, then remove it so it can
            // be added to the grid.
            if (Game.Components.Contains(_textLabel))
            {
                Game.Components.Remove(_textLabel);
            }

            fill = new XAMLiteRectangleNew(Game)
            {
                Fill   = Background,
                Width  = Width,
                Height = Height,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top,
                DrawOrder           = DrawOrder
            };

            Children.Add(fill);

            Children.Add(_textLabel);

            if (!IsReadOnly)
            {
                TextCursor = new XAMLiteLabelNew(Game)
                {
                    Content             = TextBoxCursor,
                    HorizontalAlignment = _textLabel.HorizontalAlignment,
                    VerticalAlignment   = _textLabel.VerticalAlignment,
                    FontFamily          = FontFamily,
                    Spacing             = Spacing,
                    Foreground          = Foreground,
                    Padding             = _textLabel.Padding,
                    Visibility          = Visibility.Hidden,
                    DrawOrder           = DrawOrder
                };
                Children.Add(TextCursor);
            }

            if (BorderBrush == null)
            {
                SetBorders();
            }

            // Create the borders of the control, if they are set.
            if (BorderThickness.Left > 0)
            {
                if (BorderThickness.Left == BorderThickness.Right &&
                    BorderThickness.Right == BorderThickness.Top &&
                    BorderThickness.Top == BorderThickness.Bottom)
                {
                    var border = new XAMLiteRectangleNew(Game)
                    {
                        Stroke          = BorderBrush,
                        StrokeThickness = BorderThickness.Left,
                        DrawOrder       = DrawOrder
                    };
                    _borderRectangles.Add(border);
                }
                else
                {
                    SetBorders();
                }

                foreach (var borderRectangle in _borderRectangles)
                {
                    Children.Add(borderRectangle);
                }
            }

            Background = Brushes.Transparent;
        }
예제 #7
0
        /// <summary>
        /// Loads the content for the control.
        /// </summary>
        protected override void LoadContent()
        {
            base.LoadContent();

            _originalText = Text;

            TextLabel = new XAMLiteLabelNew(Game)
            {
                Content             = Text,
                HorizontalAlignment = TextAlignment == TextAlignment.Left ||
                                      TextAlignment == TextAlignment.Justify ?
                                      HorizontalAlignment.Left : TextAlignment == TextAlignment.Center ?
                                      HorizontalAlignment.Center : HorizontalAlignment.Right,
                VerticalAlignment = VerticalAlignment.Top,
                FontFamily        = FontFamily,
                Spacing           = Spacing,
                Foreground        = Foreground,
                Padding           = Padding,
                Width             = Width,
                DrawOrder         = DrawOrder
            };

            if (Text != string.Empty || TextLabel.Width == 0)
            {
                // Add to the game so that it has a measureable size.
                Game.Components.Add(TextLabel);
                UpdateForTextWrapping();
            }
            else
            {
                Console.WriteLine(Text != string.Empty || TextLabel.Width == 0);
            }

            if (Game.Components.Contains(TextLabel))
            {
                Game.Components.Remove(TextLabel);
            }

            // Place a background for the text.
            if (Background != Brushes.Transparent)
            {
                Back = new XAMLiteRectangleNew(Game)
                {
                    Fill   = Background,
                    Width  = Width,
                    Height = Height,
                    HorizontalAlignment = HorizontalAlignment,
                    VerticalAlignment   = VerticalAlignment,
                    DrawOrder           = DrawOrder
                };
                Children.Add(Back);
            }

            // Add the text over the background
            Children.Add(TextLabel);

            // Add borders around the edge of the text.
            if (Background != Brushes.Transparent && StrokeThickness > 0)
            {
                var top = new XAMLiteRectangleNew(Game)
                {
                    Fill   = Brushes.Black,
                    Width  = Width,
                    Height = 1,
                    HorizontalAlignment = HorizontalAlignment.Left,
                    VerticalAlignment   = VerticalAlignment.Top,
                    DrawOrder           = TextLabel.DrawOrder + 1
                };
                Children.Add(top);

                var left = new XAMLiteRectangleNew(Game)
                {
                    Fill   = Brushes.Black,
                    Width  = 1,
                    Height = Height,
                    HorizontalAlignment = HorizontalAlignment.Left,
                    VerticalAlignment   = VerticalAlignment.Top,
                    DrawOrder           = TextLabel.DrawOrder + 1
                };
                Children.Add(left);

                var right = new XAMLiteRectangleNew(Game)
                {
                    Fill   = Brushes.Black,
                    Width  = 1,
                    Height = Height,
                    HorizontalAlignment = HorizontalAlignment.Right,
                    VerticalAlignment   = VerticalAlignment.Top,
                    DrawOrder           = TextLabel.DrawOrder + 1
                };
                Children.Add(right);

                var bottom = new XAMLiteRectangleNew(Game)
                {
                    Fill   = Brushes.Black,
                    Width  = Width,
                    Height = 1,
                    HorizontalAlignment = HorizontalAlignment.Left,
                    VerticalAlignment   = VerticalAlignment.Bottom,
                    DrawOrder           = TextLabel.DrawOrder + 1
                };
                Children.Add(bottom);
            }
        }
예제 #8
0
        /// <summary>
        /// Loads the content for the Rich Text Block.
        /// </summary>
        protected override void LoadContent()
        {
            BuildTextBlocks();

            base.LoadContent();

            Margin = _storedMargin;

            foreach (var info in _richTextInfo)
            {
                var label = new XAMLiteLabelNew(Game);
                label.Content    = info.Text;
                label.Foreground = Foreground;
                label.FontFamily = info.Font;
                label.Spacing    = Spacing;
                label.Padding    = Padding;
                label.Width      = Width;
                label.DrawOrder  = DrawOrder;
                _labels.Add(label);
            }

            var h     = 0;
            int count = 0;

            foreach (var label in _labels)
            {
                Game.Components.Add(label);
                var append = false;
                var w      = (int)label.MeasureString().X;
                if (count > 0)
                {
                    var s = _labels[count - 1].Content.ToString();
                    if (s.LastIndexOf("\n") != s.Length - 1)
                    {
                        append = true;
                    }
                }

                if (w > Width)
                {
                    label.Content = WordWrapper.Wrap(label.Content.ToString(), Width - 20, w, label.Padding);
                }

                if (append)
                {
                    var text = label.Content.ToString();
                    label.Content = "";

                    while (label.MeasureString().X < _labels[count - 1].MeasureString().X)
                    {
                        label.Content = " " + label.Content;
                    }

                    label.Content += text;
                }

                var m = label.Margin;
                label.Margin = new Thickness(m.Left, m.Top + h, m.Right, m.Bottom);

                h += (label.Content.ToString().LastIndexOf("\n") != label.Content.ToString().Length - 1) ? 0 : (int)label.MeasureHeight();

                Game.Components.Remove(label);
                Children.Add(label);
                count++;
            }

            TextLabel.Foreground = Brushes.Transparent;
        }
예제 #9
0
        /// <summary>
        /// Loads the button content.
        /// </summary>
        protected override void LoadContent()
        {
            base.LoadContent();

            if (SourceName == null)
            {
                LoadDefaultTexturePaths();
            }

            if (Content != null)
            {
                label = new XAMLiteLabelNew(Game)
                {
                    Content             = Content,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center,
                    FontFamily          = FontFamily,
                    Spacing             = Spacing,
                    Foreground          = Foreground,
                    Padding             = Padding,
                    //Visibility = Visibility.Hidden,
                    DrawOrder = DrawOrder
                };

                Game.Components.Add(label);

                Width  = label.Width;
                Height = label.Height;

                Game.Components.Remove(label);
            }

            _texture = Game.Content.Load <Texture2D>(SourceName);

            if (Width == 0)
            {
                Width = _texture.Width;
            }

            if (Height == 0)
            {
                Height = _texture.Height;
            }

            // get a reference to the edge texture and get basic edge width
            if (_isDefaultTextures)
            {
                _defaultEdgeTexture = Game.Content.Load <Texture2D>(_defaultSourceNameEdge);
                Width += _defaultEdgeTexture.Width * 2;
            }

            // load the default XAMLiteObjects if none set by the developer.
            if (_isDefaultTextures)
            {
                LoadDefaultContent();
            }
            else
            {
                if (RolloverSourceName != null)
                {
                    _mainButtonWithRollover = new XAMLiteImageWithRolloverNew(Game, _texture)
                    {
                        Name = "Rollover Image",
                        RolloverSourceName  = RolloverSourceName,
                        HorizontalAlignment = HorizontalAlignment.Center,
                        Width      = Width,
                        Height     = Height,
                        Background = Background,
                        DrawOrder  = DrawOrder
                    };
                    Children.Add(_mainButtonWithRollover);
                }
                else
                {
                    _mainButton = new XAMLiteImageNew(Game, _texture)
                    {
                        HorizontalAlignment = HorizontalAlignment.Center,
                        Width      = Width,
                        Height     = Height,
                        Background = Background,
                        DrawOrder  = DrawOrder
                    };
                    Children.Add(_mainButton);
                }

                if (ClickSourceName != null)
                {
                    _clickedButton = new XAMLiteImageNew(Game)
                    {
                        SourceName          = ClickSourceName,
                        HorizontalAlignment = HorizontalAlignment.Center,
                        Width      = Width,
                        Height     = Height,
                        Visibility = Visibility.Hidden,
                        Background = Background,
                        DrawOrder  = DrawOrder
                    };
                    Children.Add(_clickedButton);
                }
            }

            if (Content != null)
            {
                Children.Add(label);
            }

            // Set to transparent so that only the button textures get
            // Colorized.
            Background = Brushes.Transparent;

            MouseDown  += OnMouseDown;
            MouseEnter += OnMouseEnter;
            MouseLeave += OnMouseLeave;
        }