Пример #1
0
        /// <summary>
        /// Loads all of the content for the control.
        /// </summary>
        protected override void LoadContent()
        {
            base.LoadContent();

            // determines whether all borders are of uniform size.
            _isBorderThicknessEqual = BorderThickness.Left == BorderThickness.Right &&
                                      BorderThickness.Right == BorderThickness.Top &&
                                      BorderThickness.Top == BorderThickness.Bottom;
            _background = new XAMLiteRectangleNew(Game)
            {
                Width           = Width,
                Height          = Height,
                Fill            = Background,
                Stroke          = BorderBrush,
                StrokeThickness = _isBorderThicknessEqual ? BorderThickness.Left : 0,
                DrawOrder       = DrawOrder
            };
            _borderRectangles.Add(_background);

            if (!_isBorderThicknessEqual)
            {
                SetBorders();
            }

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

            var m = Margin;

            _gradientTop = new XAMLiteImageNew(Game, GradientTextureBuilder.CreateGradientTexture(Game, 5, Height, Background == Brushes.DarkGray ? 180 : UpperGradientBrightness))
            {
                Width               = Width,
                Height              = Height,
                Margin              = new Thickness(m.Left + BorderThickness.Left, m.Top + BorderThickness.Top, m.Right, m.Bottom),
                Background          = Brushes.White,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Center,
                RenderTransform     = RenderTransform.FlipVertical
            };
            Children.Add(_gradientTop);

            _gradientBottom = new XAMLiteImageNew(Game, GradientTextureBuilder.CreateGradientTexture(Game, 5, Height, Background == Brushes.DarkGray ? 165 : LowerGradientBrightness))
            {
                Width               = Width - (int)BorderThickness.Left - (int)BorderThickness.Right,
                Height              = Height - (int)BorderThickness.Top - (int)BorderThickness.Bottom,
                Margin              = new Thickness(m.Left + BorderThickness.Left, m.Top + BorderThickness.Top, m.Right, m.Bottom),
                Background          = Brushes.Black,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Center
            };
            Children.Add(_gradientBottom);
        }
Пример #2
0
        /// <summary>
        /// Loads the content for the control.
        /// </summary>
        protected override void LoadContent()
        {
            base.LoadContent();

            var leftSideBar = new XAMLiteImageNew(Game)
            {
                SourceName = "Icons/slider-bar-left"
            };

            Children.Add(leftSideBar);

            var rightSideBar = new XAMLiteImageNew(Game)
            {
                SourceName      = "Icons/slider-bar-left",
                RenderTransform = RenderTransform.FlipHorizontal
            };

            Children.Add(rightSideBar);

            var centerBar = new XAMLiteImageNew(Game)
            {
                SourceName          = "Icons/slider-bar-center",
                Width               = Width - 4,
                Margin              = new Thickness(2, 0, 0, 0),
                HorizontalAlignment = HorizontalAlignment.Stretch
            };

            Children.Add(centerBar);

            var b = Game.Content.Load <Texture2D>("Icons/slider-button-normal");

            _range         = Maximum - Minimum;
            _slideAdjuster = _range / (Width - b.Width);

            if (Minimum < Maximum)
            {
                _initialSliderValue = (Value - Minimum) / _slideAdjuster;
            }
            else
            {
                _initialSliderValue = (-(Minimum - (Value - Maximum)) / _slideAdjuster) - b.Width;
            }

            button = new XAMLiteButtonNew(Game)
            {
                SourceName         = "Icons/slider-button-normal",
                RolloverSourceName = "Icons/slider-button-hover",
                ClickSourceName    = "Icons/slider-button-down",
                Margin             = new Thickness(_initialSliderValue, 0, 0, 0)
            };
            button.MouseDown += ButtonOnMouseDown;
            Children.Add(button);
        }
Пример #3
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);
        }
Пример #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 for the control.
        /// </summary>
        protected override void LoadContent()
        {
            base.LoadContent();

            _defaultText = Text;

            _textBox = new XAMLiteTextBoxNew(Game)
            {
                IsReadOnly          = true,
                Text                = _defaultText == string.Empty ? "Add default text" : _defaultText,
                Width               = Width,
                IsCursorOveride     = true,
                Height              = 28,
                FontFamily          = FontFamily,
                Foreground          = Foreground,
                Background          = Background,
                BorderBrush         = BorderBrush,
                BorderThickness     = BorderThickness,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top,
                Padding             = new Thickness(7, 0, 7, 0),
                DrawOrder           = DrawOrder
            };
            Children.Add(_textBox);

            _textBoxHover = new XAMLiteImageNew(Game, GradientTextureBuilder.CreateGradientTexture(Game, 5, _textBox.Height - (int)_textBox.BorderThickness.Top - (int)_textBox.BorderThickness.Bottom, 85))
            {
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top,
                Width      = _textBox.Width - (int)_textBox.BorderThickness.Left - (int)_textBox.BorderThickness.Right,
                Height     = _textBox.Height - (int)_textBox.BorderThickness.Top - (int)_textBox.BorderThickness.Bottom,
                Margin     = new Thickness(_textBox.BorderThickness.Left, _textBox.BorderThickness.Top, 0, 0),
                Background = SelectedBackground,
                Visibility = Visibility.Hidden,
                DrawOrder  = DrawOrder + 1
            };
            Children.Add(_textBoxHover);

            _button = new XAMLiteImageNew(Game)
            {
                SourceName          = "Icons/combobox-arrow",
                Width               = 15,
                Height              = 8,
                HorizontalAlignment = HorizontalAlignment.Right,
                VerticalAlignment   = VerticalAlignment.Top,
                Margin              = new Thickness(0, 10, 5, 0),
                Background          = BorderBrush,
                DrawOrder           = DrawOrder + 1
            };
            Children.Add(_button);

            _buttonOver = new XAMLiteImageNew(Game)
            {
                SourceName          = "Icons/combobox-arrow-hover",
                Width               = 15,
                Height              = 8,
                HorizontalAlignment = HorizontalAlignment.Right,
                VerticalAlignment   = VerticalAlignment.Top,
                Margin              = new Thickness(0, 10, 5, 0),
                Background          = SelectedBackground,
                DrawOrder           = DrawOrder + 1
            };
            Children.Add(_buttonOver);
        }
Пример #6
0
        /// <summary>
        /// Loads the hover edges of the control.
        /// </summary>
        private void LoadHighlightEdges()
        {
            var texture  = Game.Content.Load <Texture2D>("Icons/menu-highlight-top");
            var isBright = ColorHelper.Brightness(HoverBrush) > 0.75f;
            var top      = new XAMLiteImageNew(Game, texture)
            {
                Width               = Width - 4,
                Background          = HoverBrush == Brushes.Transparent ? Brushes.DarkGray : !isBright ? HoverBrush : Brushes.DarkGray,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Top,
                Visibility          = Visibility.Hidden
            };

            _highlightEdgesHover.Add(top);

            var bottom = new XAMLiteImageNew(Game, texture)
            {
                Width               = Width - 4,
                RenderTransform     = RenderTransform.FlipVertical,
                Background          = HoverBrush == Brushes.Transparent ? Brushes.DarkGray : !isBright ? HoverBrush : Brushes.DarkGray,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Bottom,
                Visibility          = Visibility.Hidden
            };

            _highlightEdgesHover.Add(bottom);

            texture = Game.Content.Load <Texture2D>("Icons/menu-highlight-side");

            var left = new XAMLiteImageNew(Game, texture)
            {
                Background          = HoverBrush == Brushes.Transparent ? Brushes.DarkGray : !isBright ? HoverBrush : Brushes.DarkGray,
                Height              = Height - 4,
                Margin              = Parent is XAMLiteMenuNew ? new Thickness() : new Thickness(5, 0, 0, 0),
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Center,
                Visibility          = Visibility.Hidden
            };

            _highlightEdgesHover.Add(left);

            var right = new XAMLiteImageNew(Game, texture)
            {
                RenderTransform     = RenderTransform.FlipHorizontal,
                Height              = Height - 4,
                Background          = HoverBrush == Brushes.Transparent ? Brushes.DarkGray : !isBright ? HoverBrush : Brushes.DarkGray,
                Margin              = Parent is XAMLiteMenuNew ? new Thickness() : new Thickness(0, 0, 5, 0),
                HorizontalAlignment = HorizontalAlignment.Right,
                VerticalAlignment   = VerticalAlignment.Center,
                Visibility          = Visibility.Hidden
            };

            _highlightEdgesHover.Add(right);

            texture = Game.Content.Load <Texture2D>("Icons/menu-highlight-corner");
            var tlCorner = new XAMLiteImageNew(Game, texture)
            {
                Background          = HoverBrush == Brushes.Transparent ? Brushes.DarkGray : !isBright ? HoverBrush : Brushes.DarkGray,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top,
                Margin     = Parent is XAMLiteMenuNew ? new Thickness(1, 1, 0, 0) : new Thickness(6, 1, 0, 0),
                Visibility = Visibility.Hidden
            };

            _highlightEdgesHover.Add(tlCorner);

            var trCorner = new XAMLiteImageNew(Game, texture)
            {
                Background          = HoverBrush == Brushes.Transparent ? Brushes.DarkGray : !isBright ? HoverBrush : Brushes.DarkGray,
                HorizontalAlignment = HorizontalAlignment.Right,
                VerticalAlignment   = VerticalAlignment.Top,
                Margin     = Parent is XAMLiteMenuNew ? new Thickness(0, 1, 1, 0) : new Thickness(0, 1, 6, 0),
                Visibility = Visibility.Hidden
            };

            _highlightEdgesHover.Add(trCorner);

            var blCorner = new XAMLiteImageNew(Game, texture)
            {
                Background          = HoverBrush == Brushes.Transparent ? Brushes.DarkGray : !isBright ? HoverBrush : Brushes.DarkGray,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Bottom,
                Margin     = Parent is XAMLiteMenuNew ? new Thickness(1, 0, 0, 1) : new Thickness(6, 0, 0, 1),
                Visibility = Visibility.Hidden
            };

            _highlightEdgesHover.Add(blCorner);

            var brCorner = new XAMLiteImageNew(Game, texture)
            {
                Background          = HoverBrush == Brushes.Transparent ? Brushes.DarkGray : !isBright ? HoverBrush : Brushes.DarkGray,
                HorizontalAlignment = HorizontalAlignment.Right,
                VerticalAlignment   = VerticalAlignment.Bottom,
                Margin     = Parent is XAMLiteMenuNew ? new Thickness(0, 0, 1, 1) : new Thickness(0, 0, 6, 1),
                Visibility = Visibility.Hidden
            };

            _highlightEdgesHover.Add(brCorner);

            foreach (var image in _highlightEdgesHover)
            {
                Children.Add(image);
            }
        }
Пример #7
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);
        }
Пример #8
0
        /// <summary>
        /// Loads the content for the control.
        /// </summary>
        protected override void LoadContent()
        {
            base.LoadContent();

            var ch = Child as XAMLiteTextBlockNew;
            var bt = 0;

            if (ch != null)
            {
                bt = ch.StrokeThickness;
            }

            switch (Orientation)
            {
            case Orientation.Vertical:
                Width  = 21;
                Height = Child != null && Height == 0 ? Child.Height - (bt * 2) : 100;
                break;

            case Orientation.Horizontal:
                Width  = Child != null && Width == 0 ? Child.Width - (bt * 2) : 100;
                Height = 21;
                break;
            }

            // If there is a child linked to the Scroll Bar, set up a grid that imitates the
            // child's location so that the scroll bar will be positioned within its child's
            // boundaries. Also, modify the padding of the child to accommodate the space
            // that the scroll bar needs.
            if (ch != null)
            {
                DrawOrder = Child.DrawOrder + 1;
                var m = Child.Margin;
                _grid = new XAMLiteGridNew(Game)
                {
                    Width  = Child.Width,
                    Height = Child.Height,
                    Margin = new Thickness(m.Left, m.Top, m.Right + bt, m.Bottom),
                    HorizontalAlignment = Child.HorizontalAlignment,
                    VerticalAlignment   = Child.VerticalAlignment,
                };
                Game.Components.Add(_grid);
                _grid.Children.Add(this);

                ModifyChildPadding(ch);
            }

            var backDrop = new XAMLiteImageNew(Game)
            {
                SourceName = "Icons/ScrollBackDrop",
                Height     = Height - (bt * 2),
                Width      = Width,
                DrawOrder  = DrawOrder
            };

            Children.Add(backDrop);

            var t = Game.Content.Load <Texture2D>("Icons/ArrowButton");

            var upArrowNormalButton = new XAMLiteImageNew(Game, t)
            {
                RenderTransform     = Orientation == Orientation.Vertical ? RenderTransform.Normal : RenderTransform.RotateCounterClockwise90,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top,
                DrawOrder           = DrawOrder
            };

            var downArrowNormalButton = new XAMLiteImageNew(Game)
            {
                SourceName          = "Icons/ArrowButton",
                RenderTransform     = Orientation == Orientation.Vertical ? RenderTransform.FlipVertical : RenderTransform.RotateClockwise90,
                HorizontalAlignment = HorizontalAlignment.Right,
                VerticalAlignment   = VerticalAlignment.Bottom,
                DrawOrder           = DrawOrder
            };

            var c = Child as XAMLiteTextBlockNew;

            if (c == null)
            {
                return;
            }

            c.MouseDown += ChildOnMouseDown;
            // if the text height is less than the height of the block, do not load
            // scroll bar nor set the event handlers.

            if (Child is XAMLiteRichTextBlock)
            {
                var rtb = Child as XAMLiteRichTextBlock;
                _childTextHeight = rtb.MeasureTextHeight();
            }
            else
            {
                _childTextHeight = c.MeasureText().Y;
            }

            if (_childTextHeight <= Child.Height)
            {
                Children.Add(upArrowNormalButton);
                Children.Add(downArrowNormalButton);

                return;
            }

            _upArrow = new XAMLiteGridNew(Game)
            {
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top,
                Width     = t.Width,
                Height    = t.Height,
                DrawOrder = DrawOrder
            };
            Children.Add(_upArrow);

            _upArrow.Children.Add(upArrowNormalButton);

            var upArrowHoverButton = new XAMLiteImageNew(Game)
            {
                SourceName          = "Icons/ArrowButtonHover",
                RenderTransform     = Orientation == Orientation.Vertical ? RenderTransform.Normal : RenderTransform.RotateCounterClockwise90,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top,
                Visibility          = Visibility.Hidden,
                DrawOrder           = DrawOrder
            };

            _upArrow.Children.Add(upArrowHoverButton);

            _upArrowButtonMouseDown = new XAMLiteImageNew(Game)
            {
                SourceName          = "Icons/ArrowButtonMouseDown",
                RenderTransform     = Orientation == Orientation.Vertical ? RenderTransform.Normal : RenderTransform.RotateCounterClockwise90,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top,
                Visibility          = Visibility.Hidden,
                DrawOrder           = DrawOrder
            };
            _upArrow.Children.Add(_upArrowButtonMouseDown);

            _downArrow = new XAMLiteGridNew(Game)
            {
                HorizontalAlignment = HorizontalAlignment.Right,
                VerticalAlignment   = VerticalAlignment.Bottom,
                Width     = t.Width,
                Height    = t.Height,
                Margin    = new Thickness(0, 0, 0, bt),
                DrawOrder = DrawOrder
            };
            Children.Add(_downArrow);

            _downArrow.Children.Add(downArrowNormalButton);

            var downArrowHoverButton = new XAMLiteImageNew(Game)
            {
                SourceName          = "Icons/ArrowButtonHover",
                RenderTransform     = Orientation == Orientation.Vertical ? RenderTransform.FlipVertical : RenderTransform.RotateClockwise90,
                HorizontalAlignment = HorizontalAlignment.Right,
                VerticalAlignment   = VerticalAlignment.Bottom,
                Visibility          = Visibility.Hidden,
                DrawOrder           = DrawOrder
            };

            _downArrow.Children.Add(downArrowHoverButton);

            _downArrowButtonMouseDown = new XAMLiteImageNew(Game)
            {
                SourceName          = "Icons/ArrowButtonMouseDown",
                RenderTransform     = Orientation == Orientation.Vertical ? RenderTransform.FlipVertical : RenderTransform.RotateClockwise90,
                HorizontalAlignment = HorizontalAlignment.Right,
                VerticalAlignment   = VerticalAlignment.Bottom,
                Visibility          = Visibility.Hidden,
                DrawOrder           = DrawOrder
            };
            _downArrow.Children.Add(_downArrowButtonMouseDown);

            // load the event handlers for the arrow buttons.
            _upArrow.MouseEnter += UpArrowOnMouseEnter;
            _upArrow.MouseLeave += UpArrowOnMouseLeave;
            _upArrow.MouseDown  += UpArrowOnMouseDown;

            _downArrow.MouseEnter += DownArrowOnMouseEnter;
            _downArrow.MouseLeave += DownArrowOnMouseLeave;
            _downArrow.MouseDown  += DownArrowOnMouseDown;

            _scrollBarNormal    = new List <XAMLiteImageNew>();
            _scrollBarHover     = new List <XAMLiteImageNew>();
            _scrollBarMouseDown = new List <XAMLiteImageNew>();

            // percent of the text height versus the child height.
            var childToTextRatio = Child.Height / _childTextHeight;

            // the difference between the text height and the height of its
            // container.
            var textHeightToChildHeightDifference = _childTextHeight - Child.Height;

            // the maximum scroll bar height
            _maxScrollBarHeight = Height - (t.Height * 2);

            // the minimum scroll bar height.
            _minScrollBarHeight = 10;

            var scrollHeight = 0;

            if (textHeightToChildHeightDifference + _minScrollBarHeight < _maxScrollBarHeight)
            {
                scrollHeight = (int)(_maxScrollBarHeight - textHeightToChildHeightDifference);
            }
            else
            {
                _isLargeTextBlock = true;
                var difference = textHeightToChildHeightDifference + _minScrollBarHeight + 1 - _maxScrollBarHeight;
                _scrollValueAdjuster = difference / textHeightToChildHeightDifference;
                scrollHeight         = (int)_minScrollBarHeight;
                _textValueAdjuster   = (_childTextHeight - Height) / (_maxScrollBarHeight - scrollHeight);
            }

            // TODO: this is not truly set up yet.  Focus is currently on vertical scrolling.
            var scrollWidth = Orientation == Orientation.Vertical ? Width : (int)((Width - (t.Width * 2)) * childToTextRatio);

            SetInitialScrollValues(new Vector2(scrollWidth, scrollHeight));

            _scrollBar = new XAMLiteGridNew(Game)
            {
                Width  = scrollWidth,
                Height = scrollHeight,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top,
                Margin    = Orientation == Orientation.Vertical ? new Thickness(0, t.Height, 0, 0) : new Thickness(t.Width, 0, 0, 0),
                DrawOrder = DrawOrder
            };
            Children.Add(_scrollBar);
            _scrollBar.MouseEnter += ScrollBarOnMouseEnter;
            _scrollBar.MouseLeave += ScrollBarOnMouseLeave;
            _scrollBar.MouseDown  += ScrollBarOnMouseDown;

            var tTop    = Game.Content.Load <Texture2D>("Icons/ScrollButtonTopNoHover");
            var tBottom = Game.Content.Load <Texture2D>("Icons/ScrollButtonBottomNoHover");

            var scrollBarTopNoHover = new XAMLiteImageNew(Game, tTop)
            {
                RenderTransform     = Orientation == Orientation.Vertical ? RenderTransform.Normal : RenderTransform.RotateCounterClockwise90,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top,
                DrawOrder           = DrawOrder
            };

            _scrollBar.Children.Add(scrollBarTopNoHover);
            _scrollBarNormal.Add(scrollBarTopNoHover);

            var scrollBarTopHover = new XAMLiteImageNew(Game)
            {
                SourceName          = "Icons/ScrollButtonTopHover",
                RenderTransform     = Orientation == Orientation.Vertical ? RenderTransform.Normal : RenderTransform.RotateCounterClockwise90,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top,
                Visibility          = Visibility.Hidden,
                DrawOrder           = DrawOrder
            };

            _scrollBar.Children.Add(scrollBarTopHover);
            _scrollBarHover.Add(scrollBarTopHover);

            var scrollBarTopMouseDown = new XAMLiteImageNew(Game)
            {
                SourceName          = "Icons/ScrollButtonTopMouseDown",
                RenderTransform     = Orientation == Orientation.Vertical ? RenderTransform.Normal : RenderTransform.RotateCounterClockwise90,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top,
                Visibility          = Visibility.Hidden,
                DrawOrder           = DrawOrder
            };

            _scrollBar.Children.Add(scrollBarTopMouseDown);
            _scrollBarMouseDown.Add(scrollBarTopMouseDown);

            var scrollBarBodyNoHover = new XAMLiteImageNew(Game)
            {
                SourceName          = "Icons/ScrollButtonBodyNoHover",
                Width               = Orientation == Orientation.Vertical ? _scrollBar.Width : _scrollBar.Width - tTop.Width - tBottom.Width,
                Height              = Orientation == Orientation.Vertical ? _scrollBar.Height - tTop.Height - tBottom.Height : _scrollBar.Height,
                RenderTransform     = Orientation == Orientation.Vertical ? RenderTransform.Normal : RenderTransform.RotateCounterClockwise90,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Center,
                DrawOrder           = DrawOrder
            };

            _scrollBar.Children.Add(scrollBarBodyNoHover);
            _scrollBarNormal.Add(scrollBarBodyNoHover);

            var scrollBarBodyHover = new XAMLiteImageNew(Game)
            {
                SourceName          = "Icons/ScrollButtonBodyHover",
                Width               = Orientation == Orientation.Vertical ? _scrollBar.Width : _scrollBar.Width - tTop.Width - tBottom.Width,
                Height              = Orientation == Orientation.Vertical ? _scrollBar.Height - tTop.Height - tBottom.Height : _scrollBar.Height,
                RenderTransform     = Orientation == Orientation.Vertical ? RenderTransform.Normal : RenderTransform.RotateCounterClockwise90,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Center,
                Visibility          = Visibility.Hidden,
                DrawOrder           = DrawOrder
            };

            _scrollBar.Children.Add(scrollBarBodyHover);
            _scrollBarHover.Add(scrollBarBodyHover);

            var scrollBarBodyMouseDown = new XAMLiteImageNew(Game)
            {
                SourceName          = "Icons/ScrollButtonBodyMouseDown",
                Width               = Orientation == Orientation.Vertical ? _scrollBar.Width : _scrollBar.Width - tTop.Width - tBottom.Width,
                Height              = Orientation == Orientation.Vertical ? _scrollBar.Height - tTop.Height - tBottom.Height : _scrollBar.Height,
                RenderTransform     = Orientation == Orientation.Vertical ? RenderTransform.Normal : RenderTransform.RotateCounterClockwise90,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Center,
                Visibility          = Visibility.Hidden,
                DrawOrder           = DrawOrder
            };

            _scrollBar.Children.Add(scrollBarBodyMouseDown);
            _scrollBarMouseDown.Add(scrollBarBodyMouseDown);

            var scrollBarBottomNoHover = new XAMLiteImageNew(Game)
            {
                SourceName          = "Icons/ScrollButtonBottomNoHover",
                RenderTransform     = Orientation == Orientation.Vertical ? RenderTransform.Normal : RenderTransform.RotateClockwise90,
                HorizontalAlignment = HorizontalAlignment.Right,
                VerticalAlignment   = VerticalAlignment.Bottom,
                DrawOrder           = DrawOrder
            };

            _scrollBar.Children.Add(scrollBarBottomNoHover);
            _scrollBarNormal.Add(scrollBarBottomNoHover);

            var scrollBarBottomHover = new XAMLiteImageNew(Game)
            {
                SourceName          = "Icons/ScrollButtonBottomHover",
                RenderTransform     = Orientation == Orientation.Vertical ? RenderTransform.Normal : RenderTransform.RotateClockwise90,
                HorizontalAlignment = HorizontalAlignment.Right,
                VerticalAlignment   = VerticalAlignment.Bottom,
                Visibility          = Visibility.Hidden,
                DrawOrder           = DrawOrder
            };

            _scrollBar.Children.Add(scrollBarBottomHover);
            _scrollBarHover.Add(scrollBarBottomHover);

            var scrollBarBottomMouseDown = new XAMLiteImageNew(Game)
            {
                SourceName          = "Icons/ScrollButtonBottomMouseDown",
                RenderTransform     = Orientation == Orientation.Vertical ? RenderTransform.Normal : RenderTransform.RotateClockwise90,
                HorizontalAlignment = HorizontalAlignment.Right,
                VerticalAlignment   = VerticalAlignment.Bottom,
                Visibility          = Visibility.Hidden,
                DrawOrder           = DrawOrder
            };

            _scrollBar.Children.Add(scrollBarBottomMouseDown);
            _scrollBarMouseDown.Add(scrollBarBottomMouseDown);
        }
Пример #9
0
        /// <summary>
        /// Load default content for the button when none provided.
        /// </summary>
        private void LoadDefaultContent()
        {
            if (Background == null)
            {
                Background = Brushes.CornflowerBlue;
            }

            _mainButton = new XAMLiteImageNew(Game, GradientTextureBuilder.CreateGradientTexture(Game, 3, Height - (4), 0))
            {
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Center,
                Width      = Width - (_defaultEdgeTexture.Width * 2),
                Height     = Height - (4),
                Background = Background,
                DrawOrder  = DrawOrder
            };
            _defaultImages.Add(_mainButton);

            var defaultRolloverButton = new XAMLiteImageNew(Game, GradientTextureBuilder.CreateGradientTexture(Game, 3, Height - (4), 75))
            {
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Center,
                Width      = _isDefaultTextures ? Width - (_defaultEdgeTexture.Width * 2) : Width,
                Height     = Height - (4),
                Visibility = Visibility.Hidden,
                Background = Background,
                DrawOrder  = DrawOrder
            };

            _defaultRolloverImages.Add(defaultRolloverButton);

            _clickedButton = new XAMLiteImageNew(Game, GradientTextureBuilder.CreateGradientTexture(Game, 3, Height - (4), -75))
            {
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Center,
                Width      = Width - (_defaultEdgeTexture.Width * 2),
                Height     = Height - (4),
                Visibility = Visibility.Hidden,
                Background = Background,
                DrawOrder  = DrawOrder
            };
            _defaultClickImages.Add(_clickedButton);

            var defaultLeftEdge = new XAMLiteImageNew(Game, _defaultEdgeTexture)
            {
                IsEdge              = true,
                VerticalAlignment   = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Right,
                Height              = Height - 4,
                Margin              = new Thickness(0, 0, Width - _defaultEdgeTexture.Width, 0),
                Background          = Background,
                DrawOrder           = DrawOrder
            };

            _defaultImages.Add(defaultLeftEdge);

            var defaultRolloverLeftEdge = new XAMLiteImageNew(Game)
            {
                SourceName          = _defaultRolloverSourceNameEdge,
                IsEdge              = true,
                VerticalAlignment   = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Right,
                Height              = Height - 4,
                Margin              = new Thickness(0, 0, Width - _defaultEdgeTexture.Width, 0),
                Visibility          = Visibility.Hidden,
                Background          = Background,
                DrawOrder           = DrawOrder
            };

            _defaultRolloverImages.Add(defaultRolloverLeftEdge);

            var defaultClickLeftEdge = new XAMLiteImageNew(Game)
            {
                SourceName          = _defaultClickedSourceNameEdge,
                IsEdge              = true,
                VerticalAlignment   = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Right,
                Height              = Height - 4,
                Margin              = new Thickness(0, 0, Width - _defaultEdgeTexture.Width, 0),
                Visibility          = Visibility.Hidden,
                Background          = Background,
                DrawOrder           = DrawOrder
            };

            _defaultClickImages.Add(defaultClickLeftEdge);

            var defaultRightEdge = new XAMLiteImageNew(Game, _defaultEdgeTexture)
            {
                IsEdge              = true,
                RenderTransform     = RenderTransform.FlipHorizontal,
                VerticalAlignment   = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Left,
                Height              = Height - 4,
                Margin              = new Thickness(Width - _defaultEdgeTexture.Width, 0, 0, 0),
                Background          = Background,
                DrawOrder           = DrawOrder
            };

            _defaultImages.Add(defaultRightEdge);

            var defaultRolloverRightEdge = new XAMLiteImageNew(Game)
            {
                SourceName          = _defaultRolloverSourceNameEdge,
                IsEdge              = true,
                RenderTransform     = RenderTransform.FlipHorizontal,
                VerticalAlignment   = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Left,
                Height              = Height - 4,
                Margin              = new Thickness(Width - _defaultEdgeTexture.Width, 0, 0, 0),
                Visibility          = Visibility.Hidden,
                Background          = Background,
                DrawOrder           = DrawOrder
            };

            _defaultRolloverImages.Add(defaultRolloverRightEdge);

            var defaultClickRightEdge = new XAMLiteImageNew(Game)
            {
                SourceName          = _defaultClickedSourceNameEdge,
                IsEdge              = true,
                RenderTransform     = RenderTransform.FlipHorizontal,
                VerticalAlignment   = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Left,
                Height              = Height - 4,
                Margin              = new Thickness(Width - _defaultEdgeTexture.Width, 0, 0, 0),
                Visibility          = Visibility.Hidden,
                Background          = Background,
                DrawOrder           = DrawOrder
            };

            _defaultClickImages.Add(defaultClickRightEdge);

            var defaultTopEdge = new XAMLiteImageNew(Game)
            {
                SourceName          = _defaultSourceNameTopEdge,
                IsEdge              = true,
                IsTopEdge           = true,
                VerticalAlignment   = VerticalAlignment.Bottom,
                HorizontalAlignment = HorizontalAlignment.Center,
                Width      = Width - 4,
                Margin     = new Thickness(0, 0, 0, Height - 4),
                Background = Background,
                DrawOrder  = DrawOrder
            };

            _defaultImages.Add(defaultTopEdge);

            var defaultRolloverTopEdge = new XAMLiteImageNew(Game)
            {
                SourceName          = _defaultRolloverSourceNameTopEdge,
                IsEdge              = true,
                IsTopEdge           = true,
                VerticalAlignment   = VerticalAlignment.Bottom,
                HorizontalAlignment = HorizontalAlignment.Center,
                Width      = Width - 4,
                Margin     = new Thickness(0, 0, 0, Height - 4),
                Visibility = Visibility.Hidden,
                Background = Background,
                DrawOrder  = DrawOrder
            };

            _defaultRolloverImages.Add(defaultRolloverTopEdge);

            var defaultClickTopEdge = new XAMLiteImageNew(Game)
            {
                SourceName          = _defaultClickSourceNameTopEdge,
                IsEdge              = true,
                IsTopEdge           = true,
                VerticalAlignment   = VerticalAlignment.Bottom,
                HorizontalAlignment = HorizontalAlignment.Center,
                Width      = Width - 4,
                Margin     = new Thickness(0, 0, 0, Height - 4),
                Visibility = Visibility.Hidden,
                Background = Background,
                DrawOrder  = DrawOrder
            };

            _defaultClickImages.Add(defaultClickTopEdge);

            var defaultBottomEdge = new XAMLiteImageNew(Game)
            {
                SourceName          = _defaultSourceNameBottomEdge,
                IsEdge              = true,
                VerticalAlignment   = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Center,
                Width      = Width - 4,
                Margin     = new Thickness(0, Height - 4, 0, 0),
                Background = Background,
                DrawOrder  = DrawOrder
            };

            _defaultImages.Add(defaultBottomEdge);

            var defaultRolloverBottomEdge = new XAMLiteImageNew(Game)
            {
                SourceName          = _defaultRolloverSourceNameBottomEdge,
                IsEdge              = true,
                VerticalAlignment   = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Center,
                Width      = Width - 4,
                Margin     = new Thickness(0, Height - 4, 0, 0),
                Visibility = Visibility.Hidden,
                Background = Background,
                DrawOrder  = DrawOrder
            };

            _defaultRolloverImages.Add(defaultRolloverBottomEdge);

            var defaultClickBottomEdge = new XAMLiteImageNew(Game)
            {
                SourceName          = _defaultClickSourceNameBottomEdge,
                IsEdge              = true,
                VerticalAlignment   = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Center,
                Width      = Width - 4,
                Margin     = new Thickness(0, Height - 4, 0, 0),
                Visibility = Visibility.Hidden,
                Background = Background,
                DrawOrder  = DrawOrder
            };

            _defaultClickImages.Add(defaultClickBottomEdge);

            foreach (var image in _defaultImages)
            {
                Children.Add(image);
            }

            foreach (var image in _defaultRolloverImages)
            {
                Children.Add(image);
            }

            foreach (var image in _defaultClickImages)
            {
                Children.Add(image);
            }
        }
Пример #10
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;
        }