2019-08-09 22:04:26 +02:00
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
using MLEM.Extensions;
|
|
|
|
using MLEM.Textures;
|
|
|
|
|
|
|
|
namespace MLEM.Ui.Elements {
|
|
|
|
public class Button : Element {
|
|
|
|
|
|
|
|
public NinePatch Texture;
|
|
|
|
public NinePatch HoveredTexture;
|
|
|
|
public Color HoveredColor;
|
|
|
|
public AutoScaledText Text;
|
|
|
|
|
2019-08-09 22:23:16 +02:00
|
|
|
public Button(Anchor anchor, Vector2 size, NinePatch texture, string text = null, Color? hoveredColor = null, NinePatch hoveredTexture = null) : base(anchor, size) {
|
2019-08-09 22:04:26 +02:00
|
|
|
this.Texture = texture;
|
|
|
|
this.HoveredTexture = hoveredTexture;
|
2019-08-09 22:23:16 +02:00
|
|
|
this.HoveredColor = hoveredColor ?? Color.LightGray;
|
2019-08-09 22:04:26 +02:00
|
|
|
|
|
|
|
if (text != null) {
|
|
|
|
this.Text = new AutoScaledText(Anchor.Center, Vector2.One, text, true) {
|
|
|
|
IgnoresMouse = true
|
|
|
|
};
|
|
|
|
this.AddChild(this.Text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Draw(GameTime time, SpriteBatch batch, Color color) {
|
|
|
|
var tex = this.Texture;
|
|
|
|
if (this.IsMouseOver) {
|
|
|
|
if (this.HoveredTexture != null)
|
|
|
|
tex = this.HoveredTexture;
|
|
|
|
color = this.HoveredColor.CopyAlpha(color);
|
|
|
|
}
|
|
|
|
batch.Draw(tex, this.DisplayArea, color);
|
|
|
|
base.Draw(time, batch, color);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|