MoonWorks/src/Input/ButtonState.cs

32 lines
745 B
C#
Raw Normal View History

2022-02-23 05:14:32 +00:00
namespace MoonWorks.Input
2021-01-19 07:29:07 +00:00
{
2022-02-23 05:14:32 +00:00
public class ButtonState
{
private ButtonStatus ButtonStatus { get; set; }
2021-01-22 22:41:34 +00:00
2022-02-23 05:14:32 +00:00
public bool IsPressed => ButtonStatus == ButtonStatus.Pressed;
public bool IsHeld => ButtonStatus == ButtonStatus.Held;
public bool IsDown => ButtonStatus == ButtonStatus.Pressed || ButtonStatus == ButtonStatus.Held;
public bool IsReleased => ButtonStatus == ButtonStatus.Released;
2021-01-22 22:41:34 +00:00
2022-02-23 05:14:32 +00:00
internal void Update(bool isPressed)
{
if (isPressed)
{
if (ButtonStatus == ButtonStatus.Pressed)
{
ButtonStatus = ButtonStatus.Held;
}
else if (ButtonStatus == ButtonStatus.Released)
{
ButtonStatus = ButtonStatus.Pressed;
}
}
else
{
ButtonStatus = ButtonStatus.Released;
}
}
}
2021-01-19 07:29:07 +00:00
}