using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using RhythmBullet.UI.Modular; using RhythmBullet.Utilities.DataTypes; using RhythmBullet.Utilities.Input; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace RhythmBullet.Utilities.UI.Modular.Modules.Interactive { public delegate bool Clicked(); public class Button : UIModule { private NinePatch background; public event Clicked Listeners; public Button(NinePatch background = null) { this.background = background; } public override void Draw(SpriteBatch batch) { background?.Draw(batch, bounds); base.Draw(batch); } public sealed override bool MouseStateChanged(MouseState state) { if (InputUtilities.MouseWithinBoundries(bounds)) { if (InputUtilities.MouseClicked()) { OnClick(); } Highlighted = true; } else { Highlighted = false; } return base.MouseStateChanged(state); } public sealed override bool KeyboardStateChanged(KeyboardState state) { return base.KeyboardStateChanged(state); } protected void OnClick() { Listeners?.Invoke(); } public bool Highlighted { get; private set; } } }