public static void DrawTextMagnified(
            this Renderer renderer,
            BasicFont font,
            int x, int y,
            TextAlignH alignH, TextAlignV alignV,
            MagnificationFactors magnificationFactors,
            string messageText)
        {
            var textDimensions = font.GetStringDimensions(magnificationFactors, messageText);

            if (alignH == TextAlignH.CentreAlign)
            {
                x -= textDimensions.Width / 2;
            }
            else if (alignH == TextAlignH.RightAlign)
            {
                x -= textDimensions.Width;
            }

            if (alignV == TextAlignV.MiddleAlign)
            {
                y -= textDimensions.Height / 2;
            }
            else if (alignV == TextAlignV.BottomAlign)
            {
                y -= textDimensions.Height;
            }

            font.Draw(renderer, new Point {
                x = x, y = y
            }, magnificationFactors, messageText);
        }
Ejemplo n.º 2
0
 public override Dimensions GetStringDimensions(MagnificationFactors magnificationFactors, string messageText)
 {
     return(new Dimensions
     {
         Width = messageText.Length * CharWidth * magnificationFactors.HorizontalMagnification,
         Height = FontTexture.Dimensions.Height * magnificationFactors.VerticalMagnification
     });
 }
Ejemplo n.º 3
0
        public override void Draw(Renderer renderer, Point topLeft, MagnificationFactors magnificationFactors, string messageText)
        {
            int x = topLeft.x;
            int y = topLeft.y;
            int w = CharWidth;
            int h = FontTexture.Dimensions.Height;

            int magx = magnificationFactors.HorizontalMagnification;
            int magy = magnificationFactors.VerticalMagnification;

            var destw = w * magx;
            var desth = h * magy;

            foreach (char c in messageText)
            {
                int n = -1;
                if (c >= '0' && c <= '9')
                {
                    n = ((int)c) - 48;
                }
                else if (c >= 'A' && c <= 'Z')
                {
                    n = ((int)c) - 55;
                }

                if (n != -1)
                {
                    var sourceRect = new Rectangle {
                        Left = n * CharWidth, Top = 0, Width = w, Height = h
                    };
                    var destRect = new Rectangle {
                        Left = x, Top = y, Width = destw, Height = desth
                    };
                    renderer.DrawStretchedTexturePortion(FontTexture, sourceRect, destRect);
                }

                x += destw;
            }
        }
 /// <summary>
 /// Draws the given string in the font, at the given position, using the given renderer.
 /// </summary>
 public abstract void Draw(Renderer renderer, Point topLeft, MagnificationFactors magnificationFactors, string messageText);
 /// <summary>
 /// Obtains the dimensions, in pixels, of the extents box of the given string when written in this font.
 /// </summary>
 public abstract Dimensions GetStringDimensions(MagnificationFactors magnificationFactors, string messageText);