Beispiel #1
0
        public TextBounds DrawWrapped(GdxSpriteBatch spriteBatch, CharSequence str, float x, float y, float wrapWidth, HAlignment alignment)
        {
            _cache.Clear();
            TextBounds bounds = _cache.AddWrappedText(str, x, y, wrapWidth, alignment);

            _cache.Draw(spriteBatch);
            return(bounds);
        }
Beispiel #2
0
        public TextBounds DrawMultiLine(GdxSpriteBatch spriteBatch, CharSequence str, float x, float y, float alignmentWidth, HAlignment alignment)
        {
            _cache.Clear();
            TextBounds bounds = _cache.AddMultiLineText(str, x, y, alignmentWidth, alignment);

            _cache.Draw(spriteBatch);
            return(bounds);
        }
Beispiel #3
0
        public TextBounds Draw(GdxSpriteBatch spriteBatch, CharSequence str, float x, float y, int start, int end)
        {
            _cache.Clear();
            TextBounds bounds = _cache.AddText(str, x, y, start, end);

            _cache.Draw(spriteBatch);
            return(bounds);
        }
Beispiel #4
0
        public TextBounds Draw(GdxSpriteBatch spriteBatch, CharSequence str, float x, float y)
        {
            _cache.Clear();
            TextBounds bounds = _cache.AddText(str, x, y, 0, str.Length);

            _cache.Draw(spriteBatch);
            return(bounds);
        }
Beispiel #5
0
        public TextBounds AddText(CharSequence str, float x, float y, int start, int end)
        {
            Require(end - start);
            y += Font.Data.Ascent;

            return(Bounds = new TextBounds()
            {
                Width = AddToCache(str, x, y, start, end),
                Height = Font.Data.CapHeight,
            });
        }
Beispiel #6
0
        public TextBounds AddMultiLineText(CharSequence str, float x, float y, float alignmentWidth, HAlignment alignment)
        {
            BitmapFont font = Font;

            int length = str.Length;

            Require(length);

            y += Font.Data.Ascent;
            float down = font.Data.Down;

            float maxWidth = 0;
            float startY   = y;
            int   start    = 0;
            int   numLines = 0;

            while (start < length)
            {
                int   lineEnd   = BitmapFont.IndexOf(str, '\n', start);
                float xOffset   = 0;
                float lineWidth = 0;

                if (alignment != HAlignment.Left)
                {
                    lineWidth = font.GetBounds(str, start, lineEnd).Width;
                    xOffset   = alignmentWidth - lineWidth;

                    if (alignment == HAlignment.Center)
                    {
                        xOffset /= 2;
                    }
                }

                lineWidth = AddToCache(str, x + xOffset, y, start, lineEnd);
                maxWidth  = Math.Max(maxWidth, lineWidth);
                start     = lineEnd + 1;
                y        += down;
                numLines++;
            }

            return(Bounds = new TextBounds()
            {
                Width = maxWidth,
                Height = font.Data.CapHeight + (numLines - 1) * font.Data.LineHeight,
            });
        }
Beispiel #7
0
        public TextBounds AddWrappedText(CharSequence str, float x, float y, float wrapWidth, HAlignment alignment)
        {
            BitmapFont font = Font;

            int length = str.Length;

            Require(length);

            y += font.Data.Ascent;
            float down = font.Data.Down;

            if (wrapWidth <= 0)
            {
                wrapWidth = int.MaxValue;
            }
            float maxWidth = 0;
            int   start    = 0;
            int   numLines = 0;

            while (start < length)
            {
                int newLine = BitmapFont.IndexOf(str, '\n', start);
                while (start < newLine)
                {
                    if (!BitmapFont.IsWhitespace(str[start]))
                    {
                        break;
                    }
                    start++;
                }

                int lineEnd   = start + font.ComputeVisibleGlyphs(str, start, newLine, wrapWidth);
                int nextStart = lineEnd + 1;

                if (lineEnd < newLine)
                {
                    while (lineEnd > start)
                    {
                        if (BitmapFont.IsWhitespace(str[lineEnd]))
                        {
                            break;
                        }
                        lineEnd--;
                    }

                    if (lineEnd == start)
                    {
                        if (nextStart > start + 1)
                        {
                            nextStart--;
                        }
                        lineEnd = nextStart;
                    }
                    else
                    {
                        nextStart = lineEnd;
                        while (lineEnd > start)
                        {
                            if (!BitmapFont.IsWhitespace(str[lineEnd - 1]))
                            {
                                break;
                            }
                            lineEnd--;
                        }
                    }
                }

                if (lineEnd > start)
                {
                    float xOffset   = 0;
                    float lineWidth = 0;

                    if (alignment != HAlignment.Left)
                    {
                        lineWidth = font.GetBounds(str, start, lineEnd).Width;
                        xOffset   = wrapWidth - lineWidth;
                        if (alignment == HAlignment.Center)
                        {
                            xOffset /= 2;
                        }
                    }

                    lineWidth = AddToCache(str, x + xOffset, y, start, lineEnd);
                    maxWidth  = Math.Max(maxWidth, lineWidth);
                }

                start = nextStart;
                y    += down;
                numLines++;
            }

            return(Bounds = new TextBounds()
            {
                Width = maxWidth,
                Height = font.Data.CapHeight + (numLines - 1) * font.Data.LineHeight,
            });
        }