Engines/FlatRedBallXNA/FlatRedBall/Graphics/Text.cs
/// <summary>
/// Sets the Scale and Spacing such that the Text is drawn pixel-perfect at the given Z position.
/// This method obeys the Layer's overridden field of view if it uses one.
/// </summary>
/// <param name="layer"></param>
Sets the Scale and Spacing such that the Text is drawn pixel-perfect at the given Z position.
This method obeys the Layer's overridden field of view if it uses one.
Sets the Scale and Spacing such that the Text is drawn pixel - perfect at the given Z position . This method obeys the Layer ' s overridden field of view if it uses one .
public void SetPixelPerfectScale(Layer layer)
        {
            if (mFont == null)
            {
                throw new NullReferenceException("The Text object must have a non-null font to be scaled");
            }
            if (layer != null && layer.LayerCameraSettings != null)
            {
                LayerCameraSettings lcs = layer.LayerCameraSettings;
                if (layer.CameraBelongingTo == null)
                {
                    Scale = .5f * mFont.LineHeightInPixels /
                        SpriteManager.Camera.PixelsPerUnitAt(ref this.Position, lcs.FieldOfView, lcs.Orthogonal, lcs.OrthogonalHeight);
                }
                else
                {
                    Scale = .5f * mFont.LineHeightInPixels /
                        layer.CameraBelongingTo.PixelsPerUnitAt(ref this.Position, lcs.FieldOfView, lcs.Orthogonal, lcs.OrthogonalHeight);
                }
            }
            else if (layer != null && layer.CameraBelongingTo != null)
            {
                Scale = .5f * mFont.LineHeightInPixels / layer.CameraBelongingTo.PixelsPerUnitAt(ref this.Position);
            }
            else
            {
                var camera = Camera.Main;
                bool destinationRectangleHasArea = camera.DestinationRectangle.Width != 0 && camera.DestinationRectangle.Height != 0;
                if(destinationRectangleHasArea)
                {
                    var pixelsPerUnit = camera.PixelsPerUnitAt(ref this.Position);
                    Scale = .5f * mFont.LineHeightInPixels / pixelsPerUnit;
                }
            }
            Spacing = Scale;
            if (AdjustPositionForPixelPerfectDrawing)
            {
                NewLineDistance = (float)System.Math.Round(Scale * 1.5f);
            }
            else
            {
                NewLineDistance = Scale * 1.5f;
            }
        }
public void SetPixelPerfectScale ( Layer layer ) { if ( mFont == null ) { throw new NullReferenceException ( " " ) ; } if ( layer != null && layer . LayerCameraSettings != null ) { LayerCameraSettings lcs = layer . LayerCameraSettings ; if ( layer . CameraBelongingTo == null ) { Scale = .5f * mFont . LineHeightInPixels / SpriteManager . Camera . PixelsPerUnitAt ( ref this . Position , lcs . FieldOfView , lcs . Orthogonal , lcs . OrthogonalHeight ) ; } else { Scale = .5f * mFont . LineHeightInPixels / layer . CameraBelongingTo . PixelsPerUnitAt ( ref this . Position , lcs . FieldOfView , lcs . Orthogonal , lcs . OrthogonalHeight ) ; } } else if ( layer != null && layer . CameraBelongingTo != null ) { Scale = .5f * mFont . LineHeightInPixels / layer . CameraBelongingTo . PixelsPerUnitAt ( ref this . Position ) ; } else { var camera = Camera . Main ; bool destinationRectangleHasArea = camera . DestinationRectangle . Width != 0 && camera . DestinationRectangle . Height != 0 ; if ( destinationRectangleHasArea ) { var pixelsPerUnit = camera . PixelsPerUnitAt ( ref this . Position ) ; Scale = .5f * mFont . LineHeightInPixels / pixelsPerUnit ; } } Spacing = Scale ; if ( AdjustPositionForPixelPerfectDrawing ) { NewLineDistance = ( float ) System . Math . Round ( Scale * 1.5f ) ; } else { NewLineDistance = Scale * 1.5f ; } }
Sets the Scale and Spacing such that the Text is drawn pixel-perfect at the given Z position.
Sets the Scale and Spacing such that the Text is drawn pixel - perfect at the given Z position .
// Any camera can be used here since the fieldOfView is being overridden:
layer
Layer
None