using RecrownedAthenaeum.Graphics.Render; using RecrownedAthenaeum.Types; using OpenTK; using OpenTK.Graphics; using System; namespace RecrownedAthenaeum.Graphics.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)Width / texture.Width; } set { Width = (int)(texture.Width * value); } } /// /// Scale of the Y axis. /// public float ScaleY { get { return (float)Height / texture.Height; } set { 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."); SetPositionAndDimensions(texture.Bounds); } /// /// Draws the image with default values. /// /// The batch to use. public override void Draw(ConsistentSpriteBatch batch) { batch.Draw(texture, new Rectangle(X, Y, Width, Height), 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(ConsistentSpriteBatch spriteBatch, Rectangle destination, Color4 color, float rotation = 0, Vector2 origin = default(Vector2)) { this.color = color; this.rotation = rotation; this.origin = origin; SetPositionAndDimensions(destination); Draw(spriteBatch); } /// /// Center's the origin to the middle of the dimensions of the texture. /// public override void CenterOrigin() { origin.X = texture.Bounds.Width / 2f; origin.Y = texture.Bounds.Height / 2f; } } }