Ejemplo n.º 1
0
        public override void Draw(IGuiContext context, IGuiRenderer renderer, float deltaSeconds)
        {
            base.Draw(context, renderer, deltaSeconds);

            if (IsOpen)
            {
                var dropDownRectangle = GetListAreaRectangle(context);

                if (DropDownRegion != null)
                {
                    renderer.DrawRegion(DropDownRegion, dropDownRectangle, DropDownColor);
                }
                else
                {
                    renderer.FillRectangle(dropDownRectangle, DropDownColor);
                    renderer.DrawRectangle(dropDownRectangle, BorderColor);
                }

                DrawItemList(context, renderer);
            }

            var selectedTextInfo = GetItemTextInfo(context, ContentRectangle, SelectedItem);

            if (!string.IsNullOrWhiteSpace(selectedTextInfo.Text))
            {
                renderer.DrawText(selectedTextInfo.Font, selectedTextInfo.Text, selectedTextInfo.Position + TextOffset, selectedTextInfo.Color, selectedTextInfo.ClippingRectangle);
            }
        }
Ejemplo n.º 2
0
        protected override void DrawText(IGuiRenderer renderer, float deltaSeconds, TextInfo textInfo)
        {
            var caretRectangle = textInfo.Font.GetStringRectangle(Text.Substring(0, SelectionStart), textInfo.Position);

            // TODO: Finish the caret position stuff when it's outside the clipping rectangle
            if (caretRectangle.Right > ClippingRectangle.Right)
            {
                var textOffset = caretRectangle.Right - ClippingRectangle.Right;
                textInfo.Position.X -= textOffset;
            }

            caretRectangle.X     = caretRectangle.Right < ClippingRectangle.Right ? caretRectangle.Right : ClippingRectangle.Right;
            caretRectangle.Width = 1;

            base.DrawText(renderer, deltaSeconds, textInfo);

            if (IsFocused)
            {
                if (_isCaretVisible)
                {
                    renderer.DrawRectangle(caretRectangle, TextColor);
                }

                _nextCaretBlink -= deltaSeconds;

                if (_nextCaretBlink <= 0)
                {
                    _isCaretVisible = !_isCaretVisible;
                    _nextCaretBlink = _caretBlinkRate;
                }
            }
        }
Ejemplo n.º 3
0
        //private bool _startSelectionBox = false;
        //private Stack<int> _selectionIndexes = new Stack<int>();

        public override void Draw(IGuiContext context, IGuiRenderer renderer, float deltaSeconds)
        {
            base.Draw(context, renderer, deltaSeconds);

            var text     = PasswordCharacter.HasValue ? new string(PasswordCharacter.Value, Text.Length) : Text;
            var textInfo = GetTextInfo(context, text, ContentRectangle, HorizontalTextAlignment, VerticalTextAlignment);

            if (!string.IsNullOrWhiteSpace(textInfo.Text))
            {
                renderer.DrawText(textInfo.Font, textInfo.Text, textInfo.Position + TextOffset, textInfo.Color,
                                  textInfo.ClippingRectangle);
            }

            if (IsFocused)
            {
                var caretRectangle = GetCaretRectangle(textInfo, SelectionStart);

                if (_isCaretVisible)
                {
                    renderer.DrawRectangle(caretRectangle, TextColor);
                }

                _nextCaretBlink -= deltaSeconds;

                if (_nextCaretBlink <= 0)
                {
                    _isCaretVisible = !_isCaretVisible;
                    _nextCaretBlink = _caretBlinkRate;
                }

                //if (_selectionIndexes.Count > 1)
                //{
                //    var start = 0;
                //    var end = 0;
                //    var point = Point2.Zero;
                //    if (_selectionIndexes.Last() > _selectionIndexes.Peek())
                //    {
                //        start = _selectionIndexes.Peek();
                //        end = _selectionIndexes.Last();
                //        point = caretRectangle.Position;
                //    }
                //    else
                //    {
                //        start = _selectionIndexes.Last();
                //        end = _selectionIndexes.Peek();
                //        point = GetCaretRectangle(textInfo, start).Position;
                //    }
                //    var selectionRectangle = textInfo.Font.GetStringRectangle(textInfo.Text.Substring(start, end - start), point);

                //    renderer.FillRectangle((Rectangle)selectionRectangle, Color.Black * 0.25f);
                //}
            }
        }
Ejemplo n.º 4
0
        protected override void DrawForeground(IGuiContext context, IGuiRenderer renderer, float deltaSeconds, TextInfo textInfo)
        {
            if (PasswordCharacter.HasValue)
            {
                textInfo = GetTextInfo(context, new string(PasswordCharacter.Value, textInfo.Text.Length), BoundingRectangle, HorizontalAlignment.Centre, VerticalAlignment.Centre);
            }

            base.DrawForeground(context, renderer, deltaSeconds, textInfo);

            if (IsFocused)
            {
                var caretRectangle = GetCaretRectangle(textInfo, SelectionStart);

                if (_isCaretVisible)
                {
                    renderer.DrawRectangle((Rectangle)caretRectangle, TextColor);
                }

                _nextCaretBlink -= deltaSeconds;

                if (_nextCaretBlink <= 0)
                {
                    _isCaretVisible = !_isCaretVisible;
                    _nextCaretBlink = _caretBlinkRate;
                }

                if (_selectionIndexes.Count > 1)
                {
                    var start = 0;
                    var end   = 0;
                    var point = Point2.Zero;
                    if (_selectionIndexes.Last() > _selectionIndexes.Peek())
                    {
                        start = _selectionIndexes.Peek();
                        end   = _selectionIndexes.Last();
                        point = caretRectangle.Position;
                    }
                    else
                    {
                        start = _selectionIndexes.Last();
                        end   = _selectionIndexes.Peek();
                        point = GetCaretRectangle(textInfo, start).Position;
                    }
                    var selectionRectangle = textInfo.Font.GetStringRectangle(textInfo.Text.Substring(start, end - start), point);

                    renderer.FillRectangle((Rectangle)selectionRectangle, Color.Black * 0.25f);
                }
            }
        }
Ejemplo n.º 5
0
        protected override void DrawForeground(IGuiContext context, IGuiRenderer renderer, float deltaSeconds, TextInfo textInfo)
        {
            if (PasswordCharacter.HasValue)
            {
                textInfo = GetTextInfo(context, new string(PasswordCharacter.Value, textInfo.Text.Length), BoundingRectangle, HorizontalAlignment.Centre, VerticalAlignment.Centre);
            }

            var caretRectangle = textInfo.Font.GetStringRectangle(textInfo.Text.Substring(0, SelectionStart), textInfo.Position);

            // TODO: Finish the caret position stuff when it's outside the clipping rectangle
            if (caretRectangle.Right > ClippingRectangle.Right)
            {
                textInfo.Position.X -= caretRectangle.Right - ClippingRectangle.Right;
            }

            caretRectangle.X     = caretRectangle.Right < ClippingRectangle.Right ? caretRectangle.Right : ClippingRectangle.Right;
            caretRectangle.Width = 1;

            if (caretRectangle.Left < ClippingRectangle.Left)
            {
                textInfo.Position.X += ClippingRectangle.Left - caretRectangle.Left;
                caretRectangle.X     = ClippingRectangle.Left;
            }

            base.DrawForeground(context, renderer, deltaSeconds, textInfo);

            if (IsFocused)
            {
                if (_isCaretVisible)
                {
                    renderer.DrawRectangle((Rectangle)caretRectangle, TextColor);
                }

                _nextCaretBlink -= deltaSeconds;

                if (_nextCaretBlink <= 0)
                {
                    _isCaretVisible = !_isCaretVisible;
                    _nextCaretBlink = _caretBlinkRate;
                }
            }
        }
Ejemplo n.º 6
0
 public override void Draw(IGuiContext context, IGuiRenderer renderer, float deltaSeconds)
 {
     renderer.DrawRectangle(BoundingRectangle, Color.Green);
 }