2018-11-30 02:41:06 +00:00
|
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
2019-03-24 00:04:43 +00:00
|
|
|
|
using RecrownedAthenaeum.Render;
|
2019-01-15 23:33:55 +00:00
|
|
|
|
using RecrownedAthenaeum.SpecialTypes;
|
2018-11-30 02:41:06 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
2018-12-04 13:45:09 +00:00
|
|
|
|
namespace RecrownedAthenaeum.UI.Modular.Modules
|
2018-11-30 02:41:06 +00:00
|
|
|
|
{
|
2019-01-14 06:34:35 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Represents a texture with more information.
|
|
|
|
|
/// </summary>
|
2018-12-14 06:42:51 +00:00
|
|
|
|
public class Image : UIModule, ISpecialDrawable
|
2018-11-30 02:41:06 +00:00
|
|
|
|
{
|
2019-01-14 06:34:35 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The rotation of the image.
|
|
|
|
|
/// </summary>
|
2018-11-30 02:41:06 +00:00
|
|
|
|
public float rotation = 0f;
|
|
|
|
|
|
2019-01-14 06:34:35 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The texture to be rendered.
|
|
|
|
|
/// </summary>
|
2019-03-02 05:10:53 +00:00
|
|
|
|
public Texture2D texture;
|
2019-01-14 06:34:35 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Scale of of the X axis.
|
|
|
|
|
/// </summary>
|
2019-04-09 04:58:27 +00:00
|
|
|
|
public float ScaleX { get { return (float)Width / texture.Width; } set { Width = (int)(texture.Width * value); } }
|
2018-11-30 02:41:06 +00:00
|
|
|
|
|
2019-01-14 06:34:35 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Scale of the Y axis.
|
|
|
|
|
/// </summary>
|
2019-04-09 04:58:27 +00:00
|
|
|
|
public float ScaleY { get { return (float)Height / texture.Height; } set { Height = (int)(texture.Height * value); } }
|
2018-11-30 02:41:06 +00:00
|
|
|
|
|
2019-01-14 06:34:35 +00:00
|
|
|
|
/// <summary>
|
2019-01-30 13:46:58 +00:00
|
|
|
|
/// Sets scale of X and Y.
|
2019-01-14 06:34:35 +00:00
|
|
|
|
/// </summary>
|
2019-01-30 13:46:58 +00:00
|
|
|
|
public float Scale { set { ScaleY = value; ScaleX = value; } }
|
2018-11-30 02:41:06 +00:00
|
|
|
|
|
2019-01-14 06:34:35 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Constructs an image given a texture.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="texture">Texture to use.</param>
|
2018-11-30 02:41:06 +00:00
|
|
|
|
public Image(Texture2D texture)
|
|
|
|
|
{
|
2019-03-02 05:10:53 +00:00
|
|
|
|
this.texture = texture ?? throw new ArgumentException("Image requires a texture.");
|
2019-04-09 04:58:27 +00:00
|
|
|
|
SetPositionAndDimensions(texture.Bounds);
|
2018-11-30 02:41:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 06:34:35 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Draws the image with default values.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="batch">The batch to use.</param>
|
2019-03-24 00:04:43 +00:00
|
|
|
|
public override void Draw(ConsistentSpriteBatch batch)
|
2018-11-30 02:41:06 +00:00
|
|
|
|
{
|
2019-04-09 04:58:27 +00:00
|
|
|
|
batch.Draw(texture, new Rectangle(X, Y, Width, Height), null, color, rotation, origin, SpriteEffects.None, 0f);
|
2018-11-30 02:41:06 +00:00
|
|
|
|
base.Draw(batch);
|
|
|
|
|
}
|
2018-12-14 06:42:51 +00:00
|
|
|
|
|
2019-01-14 06:34:35 +00:00
|
|
|
|
/// <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>
|
2019-03-24 00:04:43 +00:00
|
|
|
|
public void Draw(ConsistentSpriteBatch spriteBatch, Rectangle destination, Color color, float rotation = 0, Vector2 origin = default(Vector2))
|
2018-12-14 06:42:51 +00:00
|
|
|
|
{
|
|
|
|
|
this.color = color;
|
|
|
|
|
this.rotation = rotation;
|
2019-03-02 05:24:08 +00:00
|
|
|
|
this.origin = origin;
|
2019-04-09 04:58:27 +00:00
|
|
|
|
SetPositionAndDimensions(destination);
|
2018-12-14 06:42:51 +00:00
|
|
|
|
Draw(spriteBatch);
|
|
|
|
|
}
|
2019-04-09 04:58:27 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Center's the origin to the middle of the dimensions of the texture.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public override void CenterOrigin()
|
|
|
|
|
{
|
|
|
|
|
origin.X = texture.Bounds.Width / 2f;
|
|
|
|
|
origin.Y = texture.Bounds.Height / 2f;
|
|
|
|
|
}
|
2018-11-30 02:41:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|