summaryrefslogtreecommitdiff
path: root/MonoGameLibrary/Graphics/TextureRegion.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MonoGameLibrary/Graphics/TextureRegion.cs')
-rw-r--r--MonoGameLibrary/Graphics/TextureRegion.cs75
1 files changed, 75 insertions, 0 deletions
diff --git a/MonoGameLibrary/Graphics/TextureRegion.cs b/MonoGameLibrary/Graphics/TextureRegion.cs
new file mode 100644
index 0000000..f03097c
--- /dev/null
+++ b/MonoGameLibrary/Graphics/TextureRegion.cs
@@ -0,0 +1,75 @@
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+
+namespace MonoGameLibrary.Graphics;
+
+///<summary>
+/// Represents a rectangular region within a texture
+///</summary>
+public class TextureRegion
+{
+ /// <summary>
+ /// Gets or Sets the source texture this texture region is part of
+ /// </summary>
+ public Texture2D Texture { get; set; }
+
+ /// <summary>
+ /// Gets or Sets the source rectangle boundary of this texture region within the source texture
+ /// </summary>
+ public Rectangle SourceRectangle { get; set; }
+
+ /// <summary>
+ /// Gets the width, in pixels, of this texture region
+ /// </summary>
+ public int Width => SourceRectangle.Width;
+
+ /// <summary>
+ /// Gets the height, in pixels, of this texture region/
+ /// </summary>
+ public int Height => SourceRectangle.Height;
+
+ /// <summary>
+ /// Creates a new texture region.
+ /// </summary>
+ public TextureRegion() { }
+
+ public TextureRegion(Texture2D texture, int x, int y, int width, int height)
+ {
+ Texture = texture;
+ SourceRectangle = new Rectangle(x, y, width, height);
+ }
+
+ public void Draw(SpriteBatch spriteBatch, Vector2 position, Color color)
+ {
+ Draw(spriteBatch, position, color, 0.0f, Vector2.Zero, Vector2.One, SpriteEffects.None, 0.0f);
+ }
+
+ public void Draw(SpriteBatch spriteBatch, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth)
+ {
+ Draw(
+ spriteBatch,
+ position,
+ color,
+ rotation,
+ origin,
+ new Vector2(scale, scale),
+ effects,
+ layerDepth
+ );
+ }
+
+ public void Draw(SpriteBatch spriteBatch, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth)
+ {
+ spriteBatch.Draw(
+ Texture,
+ position,
+ SourceRectangle,
+ color,
+ rotation,
+ origin,
+ scale,
+ effects,
+ layerDepth
+ );
+ }
+} \ No newline at end of file