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