Esempio n. 1
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);
        }
Esempio n. 2
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;
        }