MoonWorks/src/Input/VirtualButton.cs

48 lines
1.1 KiB
C#
Raw Normal View History

2022-03-18 18:46:44 +00:00
namespace MoonWorks.Input
{
/// <summary>
/// VirtualButtons map inputs to binary inputs, like a trigger threshold or joystick axis threshold.
/// </summary>
2022-07-12 23:09:23 +00:00
public abstract class VirtualButton
2022-03-18 18:46:44 +00:00
{
2022-07-12 23:09:23 +00:00
public ButtonState State { get; protected set; }
2022-03-18 18:46:44 +00:00
/// <summary>
2022-11-28 08:48:48 +00:00
/// True if the button was pressed this exact frame.
/// </summary>
2022-11-28 08:48:48 +00:00
public bool IsPressed => State.IsPressed;
/// <summary>
/// True if the button has been continuously held for more than one frame.
/// </summary>
2022-03-18 18:46:44 +00:00
public bool IsHeld => State.IsHeld;
/// <summary>
2022-11-28 08:48:48 +00:00
/// True if the button is pressed or held.
/// </summary>
2022-11-28 08:48:48 +00:00
public bool IsDown => State.IsDown;
/// <summary>
2022-11-28 08:48:48 +00:00
/// True if the button was released this frame.
/// </summary>
2022-03-18 18:46:44 +00:00
public bool IsReleased => State.IsReleased;
2022-11-28 08:48:48 +00:00
/// <summary>
/// True if the button was not pressed the previous or current frame.
/// </summary>
public bool IsIdle => State.IsIdle;
/// <summary>
/// True if the button is idle or released.
/// </summary>
public bool IsUp => State.IsUp;
2022-07-12 23:09:23 +00:00
internal virtual void Update()
2022-03-18 18:46:44 +00:00
{
2022-07-12 23:09:23 +00:00
State = State.Update(CheckPressed());
2022-03-18 18:46:44 +00:00
}
2022-07-12 23:09:23 +00:00
internal abstract bool CheckPressed();
2022-03-18 18:46:44 +00:00
}
}