From b6b40402db89b407365e70a0f0562a52b1667def Mon Sep 17 00:00:00 2001 From: BoredGuy Date: Sun, 8 Feb 2026 09:39:24 +0300 Subject: Back on track fully --- MonoGameLibrary/Graphics/TextureRegion.cs | 75 +++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 MonoGameLibrary/Graphics/TextureRegion.cs (limited to 'MonoGameLibrary/Graphics/TextureRegion.cs') 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; + +/// +/// Represents a rectangular region within a texture +/// +public class TextureRegion +{ + /// + /// Gets or Sets the source texture this texture region is part of + /// + public Texture2D Texture { get; set; } + + /// + /// Gets or Sets the source rectangle boundary of this texture region within the source texture + /// + public Rectangle SourceRectangle { get; set; } + + /// + /// Gets the width, in pixels, of this texture region + /// + public int Width => SourceRectangle.Width; + + /// + /// Gets the height, in pixels, of this texture region/ + /// + public int Height => SourceRectangle.Height; + + /// + /// Creates a new texture region. + /// + 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 -- cgit v1.2.3