mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-06-24 13:50:04 +02:00
40 lines
1.3 KiB
C#
40 lines
1.3 KiB
C#
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using MLEM.Extensions;
|
|
using MLEM.Textures;
|
|
|
|
namespace MLEM.Ui.Elements {
|
|
public class Button : Element {
|
|
|
|
public static NinePatch DefaultTexture;
|
|
public static NinePatch DefaultHoveredTexture;
|
|
public static Color DefaultHoveredColor = Color.LightGray;
|
|
|
|
public NinePatch Texture = DefaultTexture;
|
|
public NinePatch HoveredTexture = DefaultHoveredTexture;
|
|
public Color HoveredColor = DefaultHoveredColor;
|
|
public AutoScaledText Text;
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
public override void Draw(GameTime time, SpriteBatch batch, float alpha) {
|
|
var tex = this.Texture;
|
|
var color = Color.White * alpha;
|
|
if (this.IsMouseOver) {
|
|
if (this.HoveredTexture != null)
|
|
tex = this.HoveredTexture;
|
|
color = this.HoveredColor * alpha;
|
|
}
|
|
batch.Draw(tex, this.DisplayArea, color);
|
|
base.Draw(time, batch, alpha);
|
|
}
|
|
|
|
}
|
|
} |