WaveEngine.Components.Toolkit.TextComponent.AddLine C# (CSharp) Method

AddLine() private method

Updates the vertex buffer of the text
private AddLine ( string text, System.Vector2 initOffset, System.Color color ) : void
text string The text position
initOffset System.Vector2 The line offset
color System.Color The text color
return void
        private void AddLine(string text, Vector2 initOffset, Color color)
        {
            var spriteFont = this.SpriteFont;
            var textSize = spriteFont.MeasureString(text);
            Vector2 accumulatedPosition = Vector2.Zero;
            bool flag = true;

            accumulatedPosition.Y = textSize.Y - spriteFont.LineSpacing; // * scale.Y;

            for (int i = 0; i < text.Length; i++)
            {
                char character = text[i];

                int indexForCharacter = spriteFont.GetIndexForCharacter(character);
                Vector3 kerning = spriteFont.Kerning[indexForCharacter];

                if (flag)
                {
                    kerning.X = Math.Max(kerning.X, 0f);
                }
                else
                {
                    accumulatedPosition.X += spriteFont.Spacing;
                }

                accumulatedPosition.X += kerning.X;
                Rectangle glyphRectangle = spriteFont.Glyphs[indexForCharacter];
                Rectangle cropRectangle = spriteFont.Cropping[indexForCharacter];

                cropRectangle.Y = -glyphRectangle.Height - cropRectangle.Y;

                Vector2 position = accumulatedPosition;
                position.X += cropRectangle.X;
                position.Y += cropRectangle.Y;

                position += initOffset + this.TextOffset;

                this.AddGlyph(character, position, glyphRectangle);
                flag = false;
                accumulatedPosition.X += kerning.Y + kerning.Z;
            }
        }