rhythmbullet/RhythmBullet/Utilities/UI/Modular/Modules/Image.cs

64 lines
1.5 KiB
C#
Raw Normal View History

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using RhythmBullet.UI.Modular;
2018-11-13 01:54:33 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RhythmBullet.Utilities.UI.Modular.Modules
2018-11-13 01:54:33 +00:00
{
class Image : UIModule
{
public float rotation = 0f;
public Texture2D Texture { get; set; }
public float ScaleX
{
get
{
return (float)bounds.Width / Texture.Width;
}
set
{
bounds.Width = (int)(Texture.Width * value);
}
}
public float ScaleY
{
get
{
return (float)bounds.Height / Texture.Height;
}
set
{
bounds.Height = (int)(Texture.Height * value);
}
}
public float Scale
{
set
{
bounds.Height = (int)(Texture.Height * value);
bounds.Width = (int)(Texture.Width * value);
}
}
2018-11-13 01:54:33 +00:00
public Image(Texture2D texture)
{
Texture = texture ?? throw new ArgumentException("Image requires a texture.");
bounds = texture.Bounds;
2018-11-13 01:54:33 +00:00
}
public override void Draw(SpriteBatch batch)
{
batch.Draw(Texture, bounds, null, color, rotation, origin, SpriteEffects.None, 0f);
2018-11-13 01:54:33 +00:00
base.Draw(batch);
}
}
}