public static void DrawTextAligned(String fontName, String text, SpriteBatch spriteBatch, Point location, TextVerticalAlignment verticalAlignment, TextHorizantialAlignment horizantialAlignment, Color color) { Fonts.DrawTextAligned(fontName, text, spriteBatch, new Vector2((float)location.X, (float)location.Y), verticalAlignment, horizantialAlignment, color); }
public static void DrawTextAligned(String fontName, String text, SpriteBatch spriteBatch, Vector2 location, TextVerticalAlignment verticalAlignment, TextHorizantialAlignment horizantialAlignment, Color color) { SpriteFont spriteFont = Fonts.GetFont(fontName); Vector2 textSize = spriteFont.MeasureString(text); Vector2 alignedLocation = new Vector2(); // Calculate Horizantial Aligned Location switch (horizantialAlignment) { case TextHorizantialAlignment.Left: alignedLocation.X = location.X; break; case TextHorizantialAlignment.Center: alignedLocation.X = location.X - (textSize.X / 2.0f); break; case TextHorizantialAlignment.Right: alignedLocation.X = location.X - textSize.X; break; } // Calculate Vertical Aligned Location switch (verticalAlignment) { case TextVerticalAlignment.Top: alignedLocation.Y = location.Y; break; case TextVerticalAlignment.Middle: alignedLocation.Y = location.Y - (textSize.Y / 2.0f); break; case TextVerticalAlignment.Bottom: alignedLocation.Y = location.Y - textSize.Y; break; } spriteBatch.DrawString(spriteFont, text, alignedLocation, color); }
public static void DrawTextAligned(String fontName, String text, SpriteBatch spriteBatch, Vector2 location, TextVerticalAlignment verticalAlignment, TextHorizantialAlignment horizantialAlignment, Color color) { SpriteFont spriteFont = Fonts.GetFont(fontName); Vector2 textSize = spriteFont.MeasureString(text); Vector2 alignedLocation = new Vector2(); // Calculate Horizantial Aligned Location switch (horizantialAlignment) { case TextHorizantialAlignment.Left: alignedLocation.X = location.X; break; case TextHorizantialAlignment.Center: alignedLocation.X = location.X - (textSize.X / 2.0f); break; case TextHorizantialAlignment.Right: alignedLocation.X = location.X - textSize.X; break; } // Calculate Vertical Aligned Location switch (verticalAlignment) { case TextVerticalAlignment.Top: alignedLocation.Y = location.Y; break; case TextVerticalAlignment.Middle: alignedLocation.Y = location.Y - (textSize.Y / 2.0f); break; case TextVerticalAlignment.Bottom: alignedLocation.Y = location.Y - textSize.Y; break; } spriteBatch.DrawString(spriteFont, text, alignedLocation, color); }
public static void DrawTextAligned(String fontName, String text, SpriteBatch spriteBatch, Point location, TextVerticalAlignment verticalAlignment, TextHorizantialAlignment horizantialAlignment, Color color) { Fonts.DrawTextAligned(fontName, text, spriteBatch, new Vector2((float)location.X, (float)location.Y), verticalAlignment, horizantialAlignment, color); }