예제 #1
0
 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);
 }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
 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);
 }