2019-08-09 22:04:26 +02:00
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
using MLEM.Extensions;
|
|
|
|
using MLEM.Textures;
|
2019-08-10 21:37:10 +02:00
|
|
|
using MLEM.Ui.Style;
|
2019-08-09 22:04:26 +02:00
|
|
|
|
|
|
|
namespace MLEM.Ui.Elements {
|
|
|
|
public class Button : Element {
|
|
|
|
|
2019-08-10 21:37:10 +02:00
|
|
|
public NinePatch Texture;
|
|
|
|
public NinePatch HoveredTexture;
|
|
|
|
public Color HoveredColor;
|
2019-08-09 22:04:26 +02:00
|
|
|
public AutoScaledText Text;
|
|
|
|
|
2019-08-10 18:41:56 +02:00
|
|
|
public Button(Anchor anchor, Vector2 size, string text = null) : base(anchor, size) {
|
2019-08-09 22:04:26 +02:00
|
|
|
if (text != null) {
|
2019-08-10 13:28:58 +02:00
|
|
|
this.Text = new AutoScaledText(Anchor.Center, Vector2.One, text) {
|
2019-08-09 22:04:26 +02:00
|
|
|
IgnoresMouse = true
|
|
|
|
};
|
|
|
|
this.AddChild(this.Text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-10 13:42:18 +02:00
|
|
|
public override void Draw(GameTime time, SpriteBatch batch, float alpha) {
|
2019-08-09 22:04:26 +02:00
|
|
|
var tex = this.Texture;
|
2019-08-10 13:42:18 +02:00
|
|
|
var color = Color.White * alpha;
|
2019-08-09 22:04:26 +02:00
|
|
|
if (this.IsMouseOver) {
|
|
|
|
if (this.HoveredTexture != null)
|
|
|
|
tex = this.HoveredTexture;
|
2019-08-10 13:42:18 +02:00
|
|
|
color = this.HoveredColor * alpha;
|
2019-08-09 22:04:26 +02:00
|
|
|
}
|
2019-08-11 21:38:03 +02:00
|
|
|
batch.Draw(tex, this.DisplayArea, color, this.Scale);
|
2019-08-10 13:42:18 +02:00
|
|
|
base.Draw(time, batch, alpha);
|
2019-08-09 22:04:26 +02:00
|
|
|
}
|
|
|
|
|
2019-08-10 21:37:10 +02:00
|
|
|
protected override void InitStyle(UiStyle style) {
|
|
|
|
base.InitStyle(style);
|
|
|
|
this.Texture = style.ButtonTexture;
|
|
|
|
this.HoveredTexture = style.ButtonHoveredTexture;
|
|
|
|
this.HoveredColor = style.ButtonHoveredColor;
|
|
|
|
}
|
|
|
|
|
2019-08-09 22:04:26 +02:00
|
|
|
}
|
|
|
|
}
|