123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- #region File Description
- //-----------------------------------------------------------------------------
- // ScaledSpriteBatch.cs
- //
- // Microsoft XNA Community Game Platform
- // Copyright (C) Microsoft Corporation. All rights reserved.
- //-----------------------------------------------------------------------------
- #endregion
- #region Using Statements
- using System;
- using System.Collections.Generic;
- using System.Text;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework;
- #endregion
- namespace HoneycombRush
- {
- /// <summary>
- /// Represents a spritebatch where all drawing operations are scaled by a specific non-uniform factor. If a draw
- /// operation specifies a specific scale factor, it will be multiplied by the default one.
- /// </summary>
- public class ScaledSpriteBatch : SpriteBatch
- {
- #region Properties
- /// <summary>
- /// Determines the scale factor for all drawing operations
- /// </summary>
- public Vector2 ScaleVector { get; set; }
- #endregion
- #region Initialization
- public ScaledSpriteBatch(GraphicsDevice graphicsDevice, Vector2 initialScale) : base(graphicsDevice)
- {
- ScaleVector = initialScale;
- }
- #endregion
- #region Draw overrides
- /// <summary>
- /// Adds a sprite to a batch of sprites for rendering using the specified texture,
- /// position and color. Reference page contains links to related code samples.
- /// </summary>
- /// <param name="texture">A texture.</param>
- /// <param name="position">The location (in screen coordinates) to draw the sprite.</param>
- /// <param name="color">The color to tint a sprite. Use Color.White for full color with no tinting.</param>
- /// <remarks>The drawing operation will be scaled according to the <see cref="ScaleVector"/>
- /// property.</remarks>
- public new void Draw(Texture2D texture, Vector2 position, Color color)
- {
- base.Draw(texture, position, null, color, 0, Vector2.Zero, ScaleVector, SpriteEffects.None, 0);
- }
- /// <summary>
- /// Adds a sprite to a batch of sprites for rendering using the specified texture,
- /// position, source rectangle, and color.
- /// </summary>
- /// <param name="texture">A texture.</param>
- /// <param name="position">The location (in screen coordinates) to draw the sprite.</param>
- /// <param name="sourceRectangle">A rectangle that specifies (in texels) the source texels from a texture.
- /// Use null to draw the entire texture.</param>
- /// <param name="color">The color to tint a sprite. Use Color.White for full color with no tinting.</param>
- /// <remarks>The drawing operation will be scaled according to the <see cref="ScaleVector"/>
- /// property.</remarks>
- public new void Draw(Texture2D texture, Vector2 position, Rectangle? sourceRectangle, Color color)
- {
- base.Draw(texture, position, sourceRectangle, color, 0, Vector2.Zero, ScaleVector, SpriteEffects.None, 0);
- }
- /// <summary>
- /// Adds a sprite to a batch of sprites for rendering using the specified texture,
- /// position, source rectangle, color, rotation, origin, scale, effects, and
- /// layer. Reference page contains links to related code samples.
- /// </summary>
- /// <param name="texture">A texture.</param>
- /// <param name="position">The location (in screen coordinates) to draw the sprite.</param>
- /// <param name="sourceRectangle">A rectangle that specifies (in texels) the source texels from a texture.
- /// Use null to draw the entire texture.</param>
- /// <param name="color">The color to tint a sprite. Use Color.White for full color with no tinting.</param>
- /// <param name="rotation">Specifies the angle (in radians) to rotate the sprite about its center.</param>
- /// <param name="origin">The sprite origin; the default is (0,0) which represents the
- /// upper-left corner.</param>
- /// <param name="scale">Scale factor.</param>
- /// <param name="effects">Effects to apply.</param>
- /// <param name="layerDepth">The depth of a layer. By default, 0 represents the front layer and 1 represents
- /// a back layer. Use SpriteSortMode if you want sprites to be sorted during drawing.</param>
- /// <remarks>The drawing operation will be scaled according to the <see cref="ScaleVector"/>
- /// property.</remarks>
- public new void Draw(Texture2D texture, Vector2 position, Rectangle? sourceRectangle, Color color,
- float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth)
- {
- base.Draw(texture, position, sourceRectangle, color, rotation, origin, scale * ScaleVector, effects,
- layerDepth);
- }
- /// <summary>
- /// Adds a sprite to a batch of sprites for rendering using the specified texture,
- /// position, source rectangle, color, rotation, origin, scale, effects and layer.
- /// Reference page contains links to related code samples.
- /// </summary>
- /// <param name="texture">A texture.</param>
- /// <param name="position">The location (in screen coordinates) to draw the sprite.</param>
- /// <param name="sourceRectangle">A rectangle that specifies (in texels) the source texels from a texture.
- /// Use null to draw the entire texture.</param>
- /// <param name="color">The color to tint a sprite. Use Color.White for full color with no tinting.</param>
- /// <param name="rotation">Specifies the angle (in radians) to rotate the sprite about its center.</param>
- /// <param name="origin">The sprite origin; the default is (0,0) which represents the
- /// upper-left corner.</param>
- /// <param name="scale">Scale factor.</param>
- /// <param name="effects">Effects to apply.</param>
- /// <param name="layerDepth">The depth of a layer. By default, 0 represents the front layer and 1 represents
- /// a back layer. Use SpriteSortMode if you want sprites to be sorted during drawing.</param>
- /// <remarks>The drawing operation will be scaled according to the <see cref="ScaleVector"/>
- /// property.</remarks>
- public new void Draw(Texture2D texture, Vector2 position, Rectangle? sourceRectangle, Color color,
- float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth)
- {
- base.Draw(texture, position, sourceRectangle, color, rotation, origin, scale * ScaleVector, effects,
- layerDepth);
- }
- /// <summary>
- /// Adds a string to a batch of sprites for rendering using the specified font,
- /// text, position, and color.
- /// </summary>
- /// <param name="spriteFont">A font for diplaying text</param>
- /// <param name="text">A text string.</param>
- /// <param name="position">The location (in screen coordinates) to draw the sprite.</param>
- /// <param name="color">The color to tint a sprite. Use Color.White for full color with no tinting.</param>
- /// <remarks>The drawing operation will be scaled according to the <see cref="ScaleVector"/>
- /// property.</remarks>
- public new void DrawString(SpriteFont spriteFont, string text, Vector2 position, Color color)
- {
- base.DrawString(spriteFont, text, position, color, 0, Vector2.Zero, ScaleVector, SpriteEffects.None, 0);
- }
- /// <summary>
- /// Adds a string to a batch of sprites for rendering using the specified font,
- /// text, position, and color.
- /// </summary>
- /// <param name="spriteFont">A font for diplaying text.</param>
- /// <param name="text">A text string.</param>
- /// <param name="position">The location (in screen coordinates) to draw the sprite.</param>
- /// <param name="color">The color to tint a sprite. Use Color.White for full color with no tinting.</param>
- /// <remarks>The drawing operation will be scaled according to the <see cref="ScaleVector"/>
- /// property.</remarks>
- public new void DrawString(SpriteFont spriteFont, StringBuilder text, Vector2 position, Color color)
- {
- base.DrawString(spriteFont, text, position, color, 0, Vector2.Zero, ScaleVector, SpriteEffects.None, 0);
- }
- /// <summary>
- /// Adds a string to a batch of sprites for rendering using the specified font,
- /// text, position, color, rotation, origin, scale, effects and layer.
- /// </summary>
- /// <param name="spriteFont">A font for diplaying text.</param>
- /// <param name="text">A text string.</param>
- /// <param name="position">The location (in screen coordinates) to draw the sprite.</param>
- /// <param name="color">The color to tint a sprite. Use Color.White for full color with no tinting.</param>
- /// <param name="rotation">Specifies the angle (in radians) to rotate the sprite about its center.</param>
- /// <param name="origin">The sprite origin; the default is (0,0) which represents the
- /// upper-left corner.</param>
- /// <param name="scale">Scale factor.</param>
- /// <param name="effects">Effects to apply.</param>
- /// <param name="layerDepth">The depth of a layer. By default, 0 represents the front layer and 1 represents
- /// a back layer. Use SpriteSortMode if you want sprites to be sorted during drawing.</param>
- /// <remarks>The drawing operation will be scaled according to the <see cref="ScaleVector"/>
- /// property.</remarks>
- public new void DrawString(SpriteFont spriteFont, string text, Vector2 position, Color color, float rotation,
- Vector2 origin, float scale, SpriteEffects effects, float layerDepth)
- {
- base.DrawString(spriteFont, text, position, color, rotation, origin, scale * ScaleVector, effects,
- layerDepth);
- }
- /// <summary>
- /// Adds a string to a batch of sprites for rendering using the specified font,
- /// text, position, color, rotation, origin, scale, effects and layer.
- /// </summary>
- /// <param name="spriteFont">A font for diplaying text.</param>
- /// <param name="text">A text string.</param>
- /// <param name="position">The location (in screen coordinates) to draw the sprite.</param>
- /// <param name="color">The color to tint a sprite. Use Color.White for full color with no tinting.</param>
- /// <param name="rotation">Specifies the angle (in radians) to rotate the sprite about its center.</param>
- /// <param name="origin">The sprite origin; the default is (0,0) which represents the upper-left
- /// corner.</param>
- /// <param name="scale">Scale factor.</param>
- /// <param name="effects">Effects to apply.</param>
- /// <param name="layerDepth">The depth of a layer. By default, 0 represents the front layer and 1 represents
- /// a back layer. Use SpriteSortMode if you want sprites to be sorted during drawing.</param>
- /// <remarks>The drawing operation will be scaled according to the <see cref="ScaleVector"/>
- /// property.</remarks>
- public new void DrawString(SpriteFont spriteFont, string text, Vector2 position, Color color, float rotation,
- Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth)
- {
- DrawString(spriteFont, text, position, color, rotation, origin, scale * ScaleVector, effects, layerDepth);
- }
- /// <summary>
- /// Adds a string to a batch of sprites for rendering using the specified font,
- /// text, position, color, rotation, origin, scale, effects and layer.
- /// </summary>
- /// <param name="spriteFont">A font for diplaying text.</param>
- /// <param name="text">Text string.</param>
- /// <param name="position">The location (in screen coordinates) to draw the sprite.</param>
- /// <param name="color">The color to tint a sprite. Use Color.White for full color with no tinting.</param>
- /// <param name="rotation">Specifies the angle (in radians) to rotate the sprite about its center.</param>
- /// <param name="origin">The sprite origin; the default is (0,0) which represents the upper-left
- /// corner.</param>
- /// <param name="scale">Scale factor.</param>
- /// <param name="effects">Effects to apply.</param>
- /// <param name="layerDepth">The depth of a layer. By default, 0 represents the front layer and 1 represents
- /// a back layer. Use SpriteSortMode if you want sprites to be sorted during drawing.</param>
- /// <remarks>The drawing operation will be scaled according to the <see cref="ScaleVector"/>
- /// property.</remarks>
- public new void DrawString(SpriteFont spriteFont, StringBuilder text, Vector2 position, Color color,
- float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth)
- {
- base.DrawString(spriteFont, text, position, color, rotation, origin, scale * ScaleVector, effects,
- layerDepth);
- }
- /// <summary>
- /// Adds a string to a batch of sprites for rendering using the specified font,
- /// text, position, color, rotation, origin, scale, effects and layer.
- /// </summary>
- /// <param name="spriteFont">A font for diplaying text.</param>
- /// <param name="text">Text string.</param>
- /// <param name="position">The location (in screen coordinates) to draw the sprite.</param>
- /// <param name="color">The color to tint a sprite. Use Color.White for full color with no tinting.</param>
- /// <param name="rotation">Specifies the angle (in radians) to rotate the sprite about its center.</param>
- /// <param name="origin">The sprite origin; the default is (0,0) which represents the upper-left
- /// corner.</param>
- /// <param name="scale">Scale factor.</param>
- /// <param name="effects">Effects to apply.</param>
- /// <param name="layerDepth">The depth of a layer. By default, 0 represents the front layer and 1 represents
- /// a back layer. Use SpriteSortMode if you want sprites to be sorted during drawing.</param>
- /// <remarks>The drawing operation will be scaled according to the <see cref="ScaleVector"/>
- /// property.</remarks>
- public new void DrawString(SpriteFont spriteFont, StringBuilder text, Vector2 position, Color color,
- float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth)
- {
- base.DrawString(spriteFont, text, position, color, rotation, origin, scale * ScaleVector,
- effects, layerDepth);
- }
- #endregion
- }
- }
|