예제 #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 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);
        }
예제 #3
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);
        }
예제 #4
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);
            }
        }