Engines/FlatRedBallXNA/FlatRedBall/Graphics/Text.cs
/// <summary>
/// Sets the Scale and Spacing such that the Text is drawn pixel-perfect at its given Z position.
/// </summary>
/// <param name="camera">Reference to the camera to use when calculating the Scale and Spacing.</param>
Sets the Scale and Spacing such that the Text is drawn pixel-perfect at its given Z position.
Sets the Scale and Spacing such that the Text is drawn pixel - perfect at its given Z position .
public void SetPixelPerfectScale(Camera camera)
        {
            int lineHeight = 0;
            if (this.SpriteFont != null)
            {
                lineHeight = SpriteFont.LineSpacing;
            }
            else
            {
                if (mFont != null)
                {
                    lineHeight = mFont.LineHeightInPixels;
                }
                else
                {
                    return;
                }
            }
            var pixelsPerUnit = camera.PixelsPerUnitAt(ref this.Position);
#if DEBUG
            if(pixelsPerUnit == 0 || float.IsPositiveInfinity(pixelsPerUnit) || float.IsNegativeInfinity(pixelsPerUnit))
            {
                throw new Exception(
                    $"Could not set pixel perfect scale because of invalid pixelsPerUnit:{pixelsPerUnit}. camera position:{camera.Position}, text position:{this.Position}");
            }
#endif
            Scale = .5f *
                mFont.LineHeightInPixels / pixelsPerUnit;
            Spacing = Scale;
            if (AdjustPositionForPixelPerfectDrawing)
            {
                if (camera.Orthogonal)
                {
                    NewLineDistance = (float)System.Math.Round(Scale * 1.5f);
                }
                else
                {
                    NewLineDistance = (float)Scale * 1.5f;
                }
            }
            else
            {
                NewLineDistance = Scale * 1.5f;
            }
            UpdateDisplayedText();
            UpdateDimensions();
        }
public void SetPixelPerfectScale ( Camera camera ) { int lineHeight = 0 ; if ( this . SpriteFont != null ) { lineHeight = SpriteFont . LineSpacing ; } else { if ( mFont != null ) { lineHeight = mFont . LineHeightInPixels ; } else { return ; } } var pixelsPerUnit = camera . PixelsPerUnitAt ( ref this . Position ) ; if DEBUG if ( pixelsPerUnit == 0 || float . IsPositiveInfinity ( pixelsPerUnit ) || float . IsNegativeInfinity ( pixelsPerUnit ) ) { throw new Exception ( $" Could not set pixel perfect scale because of invalid pixelsPerUnit: { pixelsPerUnit } . camera position: { camera . Position } , text position: { this . Position } " ) ; } endif Scale = .5f * mFont . LineHeightInPixels / pixelsPerUnit ; Spacing = Scale ; if ( AdjustPositionForPixelPerfectDrawing ) { if ( camera . Orthogonal ) { NewLineDistance = ( float ) System . Math . Round ( Scale * 1.5f ) ; } else { NewLineDistance = ( float ) Scale * 1.5f ; } } else { NewLineDistance = Scale * 1.5f ; } UpdateDisplayedText ( ) ; UpdateDimensions ( ) ; }
Sets the Scale and Spacing such that the Text is drawn pixel-perfect at its given Z position.
Sets the Scale and Spacing such that the Text is drawn pixel - perfect at its given Z position .
// If we are using a 3D camera, then the line height might be something like // 1.4.  We don't want to round it if not ortho
camera
Camera
Reference to the camera to use when calculating the Scale and Spacing.
Reference to the camera to use when calculating the Scale and Spacing .