public void Render(SpriteBatch spriteBatch, string value, Rectangle renderArea, TextHorizontal h = TextHorizontal.LeftAligned, TextVertical v = TextVertical.TopAligned) { var location = new Vector2(renderArea.X, renderArea.Y); var size = SpriteFont.MeasureString(value); switch (h) { case TextHorizontal.CenterAligned: location.X += (renderArea.Width - size.X) / 1.9f; break; case TextHorizontal.RightAligned: location.X += renderArea.Width - size.X; break; } switch (v) { case TextVertical.CenterAligned: location.Y += (renderArea.Height - size.Y) / 1.9f; break; case TextVertical.BottomAligned: location.Y += renderArea.Height - size.Y; break; } spriteBatch.DrawString(SpriteFont, value, location, Color); }
public void Render(SBX spriteBatch, string value, Rectangle renderArea, TextHorizontal h = TextHorizontal.LeftAligned, TextVertical v = TextVertical.TopAligned, Color?color = null) { if (value == null) { return; } if (color == null) { color = Color; } Vector2 location = new Vector2(renderArea.X, renderArea.Y); Vector2 size = SpriteFont.MeasureString(value); switch (h) { case TextHorizontal.CenterAligned: location.X += (renderArea.Width - size.X) / 1.9f; break; case TextHorizontal.RightAligned: location.X += renderArea.Width - size.X; break; } switch (v) { case TextVertical.CenterAligned: location.Y += (renderArea.Height - size.Y) / 1.9f; break; case TextVertical.BottomAligned: location.Y += renderArea.Height - size.Y; break; } spriteBatch.GUIDrawString(SpriteFont, value, location, color); }