/// <summary> /// Loads the content of 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; // If the thickness is uniform, the ListBox only needs one rectangle // to define it. _rectangle = new XAMLiteRectangleNew(Game) { Width = Width, Height = Height, Fill = Background, Stroke = BorderBrush, StrokeThickness = _isBorderThicknessEqual ? BorderThickness.Left : 0, DrawOrder = DrawOrder }; _borderRectangles.Add(_rectangle); if (!_isBorderThicknessEqual) { SetBorders(); } foreach (var borderRectangle in _borderRectangles) { Children.Add(borderRectangle); } }
/// <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; }
/// <summary> /// Sets the borders on a menu. /// </summary> private void SetBorders() { var leftBorder = new XAMLiteRectangleNew(Game) { Fill = BorderBrush, Opacity = Opacity, Width = (int)BorderThickness.Left, Height = Height, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top, DrawOrder = DrawOrder }; _borderRectangles.Add(leftBorder); var rightBorder = new XAMLiteRectangleNew(Game) { Fill = BorderBrush, Opacity = Opacity, Width = (int)BorderThickness.Right, Height = Height, HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Top, DrawOrder = DrawOrder }; _borderRectangles.Add(rightBorder); var topBorder = new XAMLiteRectangleNew(Game) { Fill = BorderBrush, Opacity = Opacity, Width = Width - 2, Height = (int)BorderThickness.Top, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Top, DrawOrder = DrawOrder }; _borderRectangles.Add(topBorder); var bottomBorder = new XAMLiteRectangleNew(Game) { Fill = BorderBrush, Opacity = Opacity, Width = Width - 2, Height = (int)BorderThickness.Bottom, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Top, Margin = new Thickness(0, Height, 0, 0), DrawOrder = DrawOrder }; _borderRectangles.Add(bottomBorder); }
/// <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); }
/// <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); }
/// <summary> /// Sets the border colors of the textbox. /// </summary> private void SetBorders() { var nullbrush = false; // Set this to a defined default value. if (BorderBrush == null) { nullbrush = true; BorderThickness = new Thickness(1); } var leftBorder = new XAMLiteRectangleNew(Game) { Fill = nullbrush ? Brushes.Black : BorderBrush, Opacity = nullbrush ? 0.25f : Opacity, Width = (int)BorderThickness.Left, Height = Height, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top, DrawOrder = DrawOrder }; _borderRectangles.Add(leftBorder); var rightBorder = new XAMLiteRectangleNew(Game) { Fill = nullbrush ? Brushes.Black : BorderBrush, Opacity = nullbrush ? 0.25f : Opacity, Width = (int)BorderThickness.Right, Height = Height, HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Center, DrawOrder = DrawOrder }; _borderRectangles.Add(rightBorder); var topBorder = new XAMLiteRectangleNew(Game) { Fill = nullbrush ? Brushes.Black : BorderBrush, Opacity = nullbrush ? 0.5f : Opacity, Width = Width - 2, Height = (int)BorderThickness.Top, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Top, DrawOrder = DrawOrder }; _borderRectangles.Add(topBorder); var bottomBorder = new XAMLiteRectangleNew(Game) { Fill = nullbrush ? Brushes.Black : BorderBrush, Opacity = nullbrush ? 0.25f : Opacity, Width = Width - 2, Height = (int)BorderThickness.Bottom, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Bottom, DrawOrder = DrawOrder }; _borderRectangles.Add(bottomBorder); }
/// <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; }
/// <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); } }