Exemplo n.º 1
0
 protected virtual void DrawForeground(IGuiContext context, IGuiRenderer renderer, float deltaSeconds, TextInfo textInfo)
 {
     if (!string.IsNullOrWhiteSpace(textInfo.Text))
     {
         renderer.DrawText(textInfo.Font, textInfo.Text, textInfo.Position + TextOffset, textInfo.Color, textInfo.ClippingRectangle);
     }
 }
Exemplo n.º 2
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);
            }
        }
Exemplo 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);
                //}
            }
        }
Exemplo n.º 4
0
        public override void Draw(IGuiContext context, IGuiRenderer renderer, float deltaSeconds)
        {
            base.Draw(context, renderer, deltaSeconds);

            var text     = Math.Round(Value, DecimalPlaces).ToString() + Suffix;
            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);
            }
        }
        /// <summary>
        /// Draws colored text line
        /// </summary>
        /// <param name="context">gui context</param>
        /// <param name="renderer">gui renderer</param>
        /// <param name="line">scroll line to draw</param>
        /// <param name="lineIndex">current line index</param>
        private void DrawColoredText(IGuiContext context, IGuiRenderer renderer, string line, int lineIndex)
        {
            string remainingLine = line;

            var currentDrawPos = new Vector2(this.ContentRectangle.X, this.ContentRectangle.Y + (lineIndex * 16.0f));

            Color currentColor = this.TextColor;

            while (remainingLine.Any())
            {
                int colorModifierPos = remainingLine.IndexOf(ColorModifierChar);

                string linePart = colorModifierPos == -1
                    ? remainingLine
                    : remainingLine.Substring(0, colorModifierPos);

                if (linePart.Any())
                {
                    renderer.DrawText(
                        context.DefaultFont,
                        linePart,
                        currentDrawPos,
                        currentColor);

                    currentDrawPos.X += (linePart.Length - 1) * 16.0f;
                }

                if (colorModifierPos != -1)
                {
                    Debug.Assert(
                        colorModifierPos + 1 < remainingLine.Length,
                        "after the ~ the color character must follow");

                    char colorChar  = char.ToLowerInvariant(remainingLine[colorModifierPos + 1]);
                    int  colorIndex = colorChar >= '0' && colorChar <= '9' ? colorChar - '0' : colorChar - 'a' + 10;

                    Debug.Assert(
                        colorIndex < ColorByIndex.Count,
                        "invalid color modifier character");

                    if (colorIndex < ColorByIndex.Count)
                    {
                        currentColor = ColorByIndex[colorIndex];
                    }
                }

                int charsToSkip = linePart.Length + (colorModifierPos != -1 ? 2 : 0);
                remainingLine = remainingLine.Substring(charsToSkip);
            }
        }
        protected void DrawItemList(IGuiContext context, IGuiRenderer renderer)
        {
            var listRectangle = GetListAreaRectangle(context);

            for (var i = FirstIndex; i < Items.Count; i++)
            {
                var item          = Items[i];
                var itemRectangle = GetItemRectangle(context, i - FirstIndex, listRectangle);
                var itemTextInfo  = GetItemTextInfo(context, itemRectangle, item);
                var textColor     = i == SelectedIndex ? SelectedTextColor : itemTextInfo.Color;

                if (SelectedIndex == i)
                {
                    renderer.FillRectangle(itemRectangle, SelectedItemColor, listRectangle);
                }

                renderer.DrawText(itemTextInfo.Font, itemTextInfo.Text, itemTextInfo.Position + TextOffset, textColor, itemTextInfo.ClippingRectangle);
            }
        }
        /// <summary>
        /// Draws all text lines
        /// </summary>
        /// <param name="context">gui context</param>
        /// <param name="renderer">gui renderer</param>
        /// <param name="scrollLines">all scroll lines to draw</param>
        private void DrawTextLines(IGuiContext context, IGuiRenderer renderer, IEnumerable <string> scrollLines)
        {
            int lineIndex = 0;

            foreach (string line in scrollLines)
            {
                Color currentColor = this.TextColor;

                if (!line.Contains(ColorModifierChar))
                {
                    renderer.DrawText(
                        context.DefaultFont,
                        line,
                        new Vector2(this.ContentRectangle.X, this.ContentRectangle.Y + (lineIndex * 16.0f)),
                        currentColor);
                }
                else
                {
                    this.DrawColoredText(context, renderer, line, lineIndex);
                }

                lineIndex++;
            }
        }