Exemplo n.º 1
0
 /// <summary>
 /// Updates the cursor position.
 /// </summary>
 private void UpdateTextAndCursor()
 {
     if (!(this is XAMLitePasswordBox))
     {
         TextCursor.Padding = new Thickness(
             _initialPadding + _textLabel.MeasureString().X + Spacing, Padding.Top, 0, 0);
     }
 }
Exemplo n.º 2
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;
        }
Exemplo n.º 3
0
 /// <summary>
 /// Word wraps the text when TextWrapping = Wrap.
 /// </summary>
 protected virtual void UpdateForTextWrapping()
 {
     // When applicable, wrap the text and create the label.
     if (TextWrapping == TextWrapping.Wrap)
     {
         Text = WordWrapper.Wrap(Text, Width, (int)TextLabel.MeasureString().X, TextLabel.Padding);
     }
 }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
            }
        }
Exemplo n.º 6
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            // If the text is the initial text, hide the mask.
            if (Text == InitialText && _passwordMask.Visibility == Visibility.Visible)
            {
                _passwordMask.Visibility = Visibility.Hidden;
            }
            else if (Text != _previousText && Text.Length < _previousText.Length)
            {
                // If password character have been deleted.
                // set the previous text to the new text.
                _previousText = Text;
                // update the mask and cursor positions.
                UpdateMask(Text.Length);
                _passwordMask.Visibility = Visibility.Visible;

                UpdateCursor(_passwordMask.MeasureString().X);
            }
            else if (Text != _previousText && Text != string.Empty && Text != InitialText)
            {
                // if password characters have increased...
                // mask all of the text with filled characters, except the most
                // recently pressed key.
                UpdateMask(Text.Length - 1);
                _passwordMask.Visibility = Visibility.Visible;

                var pos = _passwordMask.MeasureString().X + Spacing;

                // make the most recently pressed key visible.
                _currentCharacter.Visibility = Visibility.Visible;
                _currentCharacter.Content    = Text == string.Empty
                                                ? ""
                                                : Text[Text.Length - 1].ToString(CultureInfo.InvariantCulture);
                // update the exposed character position.
                _currentCharacter.Margin = new Thickness(pos, 0, 0, 0);

                // update the cursor position.
                UpdateCursor(pos + _currentCharacter.MeasureString().X);

                // set the timer for when to replace the exposed character with the mask.
                _maskCharacter = TimeSpan.FromMilliseconds(800);

                // set the previous text to the new text.
                _previousText = Text;
            }
            else
            {
                // if the most recently pressed key is exposed, the timer will count down.
                if (_currentCharacter.Visibility == Visibility.Visible)
                {
                    _maskCharacter -= gameTime.ElapsedGameTime;

                    // When the timer reaches zero
                    if (_maskCharacter <= TimeSpan.Zero)
                    {
                        // hide the character and mask it.
                        _currentCharacter.Visibility = Visibility.Hidden;

                        // Update the mask and cursor positions.
                        UpdateMask(Text.Length);
                        _passwordMask.Visibility = Visibility.Visible;
                        UpdateCursor(_passwordMask.MeasureString().X);
                    }
                }
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 8
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;
        }
Exemplo n.º 9
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;
        }