MonoGameUi.Label.OnDrawContent C# (CSharp) Method

OnDrawContent() protected method

protected OnDrawContent ( SpriteBatch batch, Rectangle area, GameTime gameTime, float alpha ) : void
batch Microsoft.Xna.Framework.Graphics.SpriteBatch
area Microsoft.Xna.Framework.Rectangle
gameTime Microsoft.Xna.Framework.GameTime
alpha float
return void
        protected override void OnDrawContent(SpriteBatch batch, Rectangle area, GameTime gameTime, float alpha)
        {
            // Rahmenbedingungen fürs Rendern checken
            if (Font == null) return;

            Vector2 offset = new Vector2(area.X, area.Y);

            if (WordWrap)
            {
                int totalHeight = 0;
                foreach (var line in lines)
                {
                    Vector2 lineSize = Font.MeasureString(line);
                    totalHeight += (int)lineSize.Y;
                }

                switch (VerticalTextAlignment)
                {
                    case VerticalAlignment.Top:
                        break;
                    case VerticalAlignment.Bottom:
                        offset.Y = area.Y + area.Height - totalHeight;
                        break;
                    case VerticalAlignment.Center:
                        offset.Y = area.Y + (area.Height - totalHeight) / 2;
                        break;
                }

                foreach (var line in lines)
                {
                    Vector2 lineSize = Font.MeasureString(line);
                    switch (HorizontalTextAlignment)
                    {
                        case HorizontalAlignment.Left:
                            offset.X = area.X;
                            break;
                        case HorizontalAlignment.Center:
                            offset.X = area.X + (area.Width - lineSize.X) / 2;
                            break;
                        case HorizontalAlignment.Right:
                            offset.X = area.X + area.Width - lineSize.X;
                            break;
                    }

                    batch.DrawString(Font, line, offset, TextColor * alpha);

                    offset.Y += (int)lineSize.Y;
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(Text))
                    batch.DrawString(Font, Text, offset, TextColor * alpha);
            }
        }