public TextControl(VisualStyle defaultStyle) : base(defaultStyle) { TextStyle = new TextStyle(); }
public void DrawText(string text, IRectangle destinationRectangle, TextStyle style) { var textPosition = AlignText(text, ToRectangle(destinationRectangle), style); _fontRenderer.DrawText(_spriteBatch, textPosition.X, textPosition.Y, text, style.Colour); }
private Point AlignText(string text, Rectangle destinationRectangle, TextStyle style) { int x = 0, y = 0; var size = _fontRenderer.MeasureText(text); var centre = destinationRectangle.Center; var lineHeight = _fontRenderer.FontFile.Common.LineHeight; switch(style.HorizontalAlignment) { case HorizontalAlignment.Centre: x = centre.X - size.Width / 2; break; case HorizontalAlignment.Stretch: case HorizontalAlignment.Left: x = destinationRectangle.X; break; case HorizontalAlignment.Right: x = destinationRectangle.Right - size.Width; break; } switch(style.VerticalAlignment) { case VerticalAlignment.Centre: y = centre.Y - lineHeight / 2; break; case VerticalAlignment.Stretch: case VerticalAlignment.Top: y = destinationRectangle.Y; break; case VerticalAlignment.Bottom: y = destinationRectangle.Bottom - size.Height; break; } return new Point(x, y); }