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/Button.cs

44 lines
1.4 KiB
C#
Raw Normal View History

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;
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;
public AutoScaledText Text;
2019-08-10 18:41:56 +02:00
public Button(Anchor anchor, Vector2 size, string text = null) : base(anchor, size) {
if (text != null) {
this.Text = new AutoScaledText(Anchor.Center, Vector2.One, text) {
IgnoresMouse = true
};
this.AddChild(this.Text);
}
}
2019-08-10 13:42:18 +02:00
public override void Draw(GameTime time, SpriteBatch batch, float alpha) {
var tex = this.Texture;
2019-08-10 13:42:18 +02:00
var color = Color.White * alpha;
if (this.IsMouseOver) {
if (this.HoveredTexture != null)
tex = this.HoveredTexture;
2019-08-10 13:42:18 +02:00
color = this.HoveredColor * alpha;
}
batch.Draw(tex, this.DisplayArea, color, this.Scale);
2019-08-10 13:42:18 +02:00
base.Draw(time, batch, alpha);
}
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;
}
}
}