using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using RecrownedAthenaeum.SpecialTypes; using System; namespace RecrownedAthenaeum.UI.Modular.Modules { /// /// Represents a texture with more information. /// public class Image : UIModule, ISpecialDrawable { /// /// The rotation of the image. /// public float rotation = 0f; /// /// The texture to be rendered. /// public Texture2D texture; /// /// Scale of of the X axis. /// public float ScaleX { get { return (float)situation.Width / texture.Width; } set { situation.Width = (int)(texture.Width * value); } } /// /// Scale of the Y axis. /// public float ScaleY { get { return (float)situation.Height / texture.Height; } set { situation.Height = (int)(texture.Height * value); } } /// /// Sets scale of X and Y. /// public float Scale { set { ScaleY = value; ScaleX = value; } } /// /// Constructs an image given a texture. /// /// Texture to use. public Image(Texture2D texture) { this.texture = texture ?? throw new ArgumentException("Image requires a texture."); situation = texture.Bounds; } /// /// Draws the image with default values. /// /// The batch to use. public override void Draw(SpriteBatch batch) { batch.Draw(texture, situation, null, color, rotation, origin, SpriteEffects.None, 0f); base.Draw(batch); } /// /// Draws the image with more options. /// /// Batch used. /// Where to draw texture to. /// The color tint to use. /// Rotation of image. /// Origin for the rotation. public void Draw(SpriteBatch spriteBatch, Rectangle destination, Color color, float rotation = 0, Vector2 origin = default(Vector2)) { this.color = color; this.rotation = rotation; this.origin = origin; situation = destination; Draw(spriteBatch); } } }