예제 #1
0
 /// <summary>
 /// Extension method for SpriteBatch that draws a string without allocating
 /// any memory. This function avoids garbage collections that are normally caused
 /// by creating strings
 /// </summary>
 /// <param name="spriteBatch">The SpriteBatch instance whose DrawString method will be invoked.</param>
 /// <param name="text">The text to draw.</param>
 public static void DrawString(
     this SpriteBatch spriteBatch,
     XenString text
     )
 {
     DrawString(spriteBatch, null, text, Matrix.Identity);
 }
예제 #2
0
 /// <summary>
 /// Extension method for SpriteBatch that draws a string without allocating
 /// any memory. This function avoids garbage collections that are normally caused
 /// by creating strings
 /// </summary>
 /// <param name="spriteBatch">The SpriteBatch instance whose DrawString method will be invoked.</param>
 /// <param name="spriteFont">The SpriteFont to draw the text with.</param>
 /// <param name="text">The text to draw.</param>
 public static void DrawString(
     this SpriteBatch spriteBatch,
     SpriteFont spriteFont,
     XenString text
     )
 {
     DrawString(spriteBatch, spriteFont, text, Matrix.Identity);
 }
예제 #3
0
 /// <summary>
 /// Extension method for SpriteBatch that draws a string without allocating
 /// any memory. This function avoids garbage collections that are normally caused
 /// by creating strings
 /// </summary>
 /// <param name="spriteBatch">The SpriteBatch instance whose DrawString method will be invoked.</param>
 /// <param name="spriteFont">The SpriteFont to draw the text with.</param>
 /// <param name="text">The text to draw.</param>
 /// <param name="position">The screen position specifying where to draw the text.</param>
 /// <param name="color">The color of the text drawn.</param>
 /// <remarks>The parameters override the parameters defined inside the XenString class</remarks>
 public static void DrawString(
     this SpriteBatch spriteBatch,
     SpriteFont spriteFont,
     XenString text,
     Vector2 position,
     Color color
     )
 {
     DrawString(spriteBatch, spriteFont, text, position, color, 0.0f, Vector2.Zero, Vector2.One, SpriteEffects.None, 0.0f);
 }
예제 #4
0
 /// <summary>
 /// Extension method for SpriteBatch that draws a string without allocating
 /// any memory. This function avoids garbage collections that are normally caused
 /// by creating strings
 /// </summary>
 /// <param name="spriteBatch">The SpriteBatch instance whose DrawString method will be invoked.</param>
 /// <param name="spriteFont">The SpriteFont to draw the text with.</param>
 /// <param name="text">The text to draw.</param>
 /// <param name="position">The screen position specifying where to draw the text.</param>
 /// <param name="color">The color of the text drawn.</param>
 /// <param name="rotation">The rotation angle of the text.</param>
 /// <param name="origin">The origin of the text image</param>
 /// <param name="scale">The scale factor of the text.</param>
 /// <param name="effects">The sprite effects applied to the text.</param>
 /// <param name="layerDepth">The layer depth of the text.</param>
 /// <remarks>The parameters override the parameters defined inside the XenString class</remarks>
 public static void DrawString(
     this SpriteBatch spriteBatch,
     SpriteFont spriteFont,
     XenString text,
     Vector2 position,
     Color color,
     float rotation,
     Vector2 origin,
     float scale,
     SpriteEffects effects,
     float layerDepth
     )
 {
     DrawString(spriteBatch, spriteFont, text, position, color, rotation, origin, Vector2.One * scale, effects, layerDepth);
 }
예제 #5
0
        /// <summary>
        /// Extension method for SpriteBatch that draws a string without allocating
        /// any memory. This function avoids garbage collections that are normally caused
        /// by creating strings
        /// </summary>
        /// <param name="spriteBatch">The SpriteBatch instance whose DrawString method will be invoked.</param>
        /// <param name="spriteFont">The SpriteFont to draw the text with.</param>
        /// <param name="text">The text to draw.</param>
        /// <param name="position">The screen position specifying where to draw the text.</param>
        /// <param name="color">The color of the text drawn.</param>
        /// <param name="rotation">The rotation angle of the text.</param>
        /// <param name="origin">The origin of the text image</param>
        /// <param name="scale">The scale factor of the text.</param>
        /// <param name="effects">The sprite effects applied to the text.</param>
        /// <param name="layerDepth">The layer depth of the text.</param>
        /// <returns>The next position on the line to draw text.</returns>
        /// <remarks>The parameters override the parameters defined inside the XenString class</remarks>
        public static void DrawString(
            this SpriteBatch spriteBatch,
            SpriteFont spriteFont,
            XenString text,
            Vector2 position,
            Color color,
            float rotation,
            Vector2 origin,
            Vector2 scale,
            SpriteEffects effects,
            float layerDepth
            )
        {
            SpriteFont font = (spriteFont != null ? spriteFont : text.SpriteFont);

            if (font == null)
            {
                throw new ArgumentNullException("spriteFont");
            }

            Vector2 nextPosition = position;

            switch (text._type)
            {
            case XenString.XenStringType.String:
                spriteBatch.DrawString(
                    font,
                    text.Text,
                    position,
                    color,
                    rotation,
                    origin,
                    scale,
                    effects,
                    layerDepth);
                nextPosition += font.MeasureString(text.Text) * Vector2.Transform(Vector2.UnitX, Matrix.CreateRotationZ(rotation));
                break;

            case XenString.XenStringType.Integer:
                nextPosition = spriteBatch.DrawInteger(
                    font,
                    text.ValueInt,
                    position + Vector2.Transform(text.RenderingExtent.ReferenceTopLeft, text.Transform.TranslateFrom),
                    color);
                break;

            case XenString.XenStringType.Float:
                nextPosition = spriteBatch.DrawDecimal(
                    font,
                    text.ValueFloat,
                    text.FloatDecimalPlaces,
                    position + Vector2.Transform(text.RenderingExtent.ReferenceTopLeft, text.Transform.TranslateFrom),
                    color);
                break;
            }
            if (text._nextString != null)
            {
                spriteBatch.DrawString(
                    spriteFont,
                    text._nextString,
                    nextPosition,
                    color,
                    rotation,
                    origin,
                    scale,
                    effects,
                    layerDepth);
            }
            if (text.IsTemporary)
            {
                text.Release();
            }
        }
예제 #6
0
        /// <summary>
        /// Extension method for SpriteBatch that draws a string without allocating
        /// any memory. This function avoids garbage collections that are normally caused
        /// by creating strings
        /// </summary>
        /// <param name="spriteBatch">The SpriteBatch instance whose DrawString method will be invoked.</param>
        /// <param name="spriteFont">The SpriteFont to draw the text with.</param>
        /// <param name="text">The text to draw.</param>
        /// <param name="transformFromWorldToCamera">The matrix transformation to bring the world to camera-space.</param>
        public static void DrawString(
            this SpriteBatch spriteBatch,
            SpriteFont spriteFont,
            XenString text,
            Matrix transformFromWorldToCamera
            )
        {
            SpriteFont font = (spriteFont != null ? spriteFont : text.SpriteFont);

            if (font == null)
            {
                throw new ArgumentNullException("spriteFont");
            }

            Matrix  transformFromTextToWorld = text.RenderingExtent.TranslateFrom;
            Matrix  fromTextToCamera         = transformFromTextToWorld * transformFromWorldToCamera;
            Vector2 position = Vector2.Transform(text.RenderingExtent.ReferenceTopLeft, fromTextToCamera);

            Vector3    scale, translate;
            Quaternion rotate;

            fromTextToCamera.Decompose(out scale, out rotate, out translate);
            fromTextToCamera.Translation = Vector3.Zero;

            float angle = XenMath.GetAngleFloat(Vector2.Transform(Vector2.UnitX, fromTextToCamera));

            Vector2 nextPosition = position;

            switch (text._type)
            {
            case XenString.XenStringType.String:
                spriteBatch.DrawString(
                    font,
                    text.Text,
                    position,
                    text.ModulationColorWithOpacity,
                    angle,
                    Vector2.Zero,
                    new Vector2(scale.X, scale.Y),
                    text.SpriteEffects,
                    text.LayerDepth);
                nextPosition += font.MeasureString(text.Text) * Vector2.Transform(Vector2.UnitX, Matrix.CreateRotationZ(angle));
                break;

            case XenString.XenStringType.Integer:
                nextPosition = spriteBatch.DrawInteger(
                    font,
                    text.ValueInt,
                    position,
                    text.ModulationColorWithOpacity,
                    angle,
                    Vector2.Zero,
                    new Vector2(scale.X, scale.Y),
                    text.SpriteEffects,
                    text.LayerDepth);
                break;

            case XenString.XenStringType.Float:
                nextPosition = spriteBatch.DrawDecimal(
                    font,
                    text.ValueFloat,
                    text.FloatDecimalPlaces,
                    position,
                    text.ModulationColorWithOpacity,
                    angle,
                    Vector2.Zero,
                    new Vector2(scale.X, scale.Y),
                    text.SpriteEffects,
                    text.LayerDepth);
                break;
            }
            if (text._nextString != null)
            {
                spriteBatch.DrawString(
                    spriteFont,
                    text._nextString,
                    nextPosition,
                    text.ModulationColorWithOpacity,
                    angle,
                    Vector2.Zero,
                    new Vector2(scale.X, scale.Y),
                    text.SpriteEffects, text.LayerDepth);
            }
            if (text.IsTemporary)
            {
                text.Release();
            }
        }