2018-11-30 02:41:06 +00:00
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
|
using Microsoft.Xna.Framework.Input;
|
2018-12-04 13:45:09 +00:00
|
|
|
|
using RecrownedAthenaeum.UI.Modular;
|
|
|
|
|
using RecrownedAthenaeum.DataTypes;
|
|
|
|
|
using RecrownedAthenaeum.Input;
|
2018-11-30 02:41:06 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2018-12-04 13:45:09 +00:00
|
|
|
|
namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
|
2018-11-30 02:41:06 +00:00
|
|
|
|
{
|
|
|
|
|
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; }
|
|
|
|
|
}
|
|
|
|
|
}
|