1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-04 22:49:08 +01:00
MLEM/MLEM.Ui/Elements/Image.cs

28 lines
958 B
C#
Raw Normal View History

2019-08-09 22:23:16 +02:00
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MLEM.Extensions;
using MLEM.Textures;
namespace MLEM.Ui.Elements {
public class Image : Element {
public Color Color = Color.White;
2019-08-14 22:06:06 +02:00
public TextureRegion Texture;
2019-08-09 22:23:16 +02:00
private readonly bool scaleToImage;
public Image(Anchor anchor, Vector2 size, TextureRegion texture, bool scaleToImage = false) : base(anchor, size) {
2019-08-14 22:06:06 +02:00
this.Texture = texture;
2019-08-09 22:23:16 +02:00
this.scaleToImage = scaleToImage;
}
protected override Point CalcActualSize(Rectangle parentArea) {
2019-08-14 22:06:06 +02:00
return this.scaleToImage ? this.Texture.Size : base.CalcActualSize(parentArea);
2019-08-09 22:23:16 +02:00
}
public override void Draw(GameTime time, SpriteBatch batch, float alpha, Point offset) {
2019-08-14 22:06:06 +02:00
batch.Draw(this.Texture, this.DisplayArea.OffsetCopy(offset), this.Color * alpha);
base.Draw(time, batch, alpha, offset);
2019-08-09 22:23:16 +02:00
}
}
}