2022-02-23 05:14:32 +00:00
|
|
|
|
namespace MoonWorks.Input
|
2021-01-19 07:29:07 +00:00
|
|
|
|
{
|
2022-03-07 18:54:52 +00:00
|
|
|
|
public struct ButtonState
|
2022-02-23 05:14:32 +00:00
|
|
|
|
{
|
2022-03-18 18:46:44 +00:00
|
|
|
|
public ButtonStatus ButtonStatus { get; }
|
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-07-12 23:09:23 +00:00
|
|
|
|
internal ButtonState(ButtonStatus buttonStatus)
|
2022-03-07 18:54:52 +00:00
|
|
|
|
{
|
|
|
|
|
ButtonStatus = buttonStatus;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal ButtonState Update(bool isPressed)
|
2022-02-23 05:14:32 +00:00
|
|
|
|
{
|
|
|
|
|
if (isPressed)
|
|
|
|
|
{
|
|
|
|
|
if (ButtonStatus == ButtonStatus.Pressed)
|
|
|
|
|
{
|
2022-03-07 18:54:52 +00:00
|
|
|
|
return new ButtonState(ButtonStatus.Held);
|
2022-02-23 05:14:32 +00:00
|
|
|
|
}
|
|
|
|
|
else if (ButtonStatus == ButtonStatus.Released)
|
|
|
|
|
{
|
2022-03-07 18:54:52 +00:00
|
|
|
|
return new ButtonState(ButtonStatus.Pressed);
|
|
|
|
|
}
|
|
|
|
|
else if (ButtonStatus == ButtonStatus.Held)
|
|
|
|
|
{
|
|
|
|
|
return new ButtonState(ButtonStatus.Held);
|
2022-02-23 05:14:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-07 18:54:52 +00:00
|
|
|
|
|
|
|
|
|
return new ButtonState(ButtonStatus.Released);
|
2022-02-23 05:14:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-01-19 07:29:07 +00:00
|
|
|
|
}
|