diff --git a/src/Input/ButtonState.cs b/src/Input/ButtonState.cs index e9ba555..444e916 100644 --- a/src/Input/ButtonState.cs +++ b/src/Input/ButtonState.cs @@ -8,6 +8,8 @@ public bool IsHeld => ButtonStatus == ButtonStatus.Held; public bool IsDown => ButtonStatus == ButtonStatus.Pressed || ButtonStatus == ButtonStatus.Held; public bool IsReleased => ButtonStatus == ButtonStatus.Released; + public bool IsIdle => ButtonStatus == ButtonStatus.Idle; + public bool IsUp => ButtonStatus == ButtonStatus.Idle || ButtonStatus == ButtonStatus.Released; public ButtonState(ButtonStatus buttonStatus) { @@ -18,26 +20,34 @@ { if (isPressed) { - if (ButtonStatus == ButtonStatus.Pressed) - { - return new ButtonState(ButtonStatus.Held); - } - else if (ButtonStatus == ButtonStatus.Released) + if (IsUp) { return new ButtonState(ButtonStatus.Pressed); } - else if (ButtonStatus == ButtonStatus.Held) + else { return new ButtonState(ButtonStatus.Held); } } - - return new ButtonState(ButtonStatus.Released); + else + { + if (IsDown) + { + return new ButtonState(ButtonStatus.Released); + } + else + { + return new ButtonState(ButtonStatus.Idle); + } + } } + /// + /// Combines two button states. Useful for alt controls or input buffering. + /// public static ButtonState operator |(ButtonState a, ButtonState b) { - if (a.ButtonStatus == ButtonStatus.Released) + if (a.ButtonStatus == ButtonStatus.Idle || a.ButtonStatus == ButtonStatus.Released) { return b; } diff --git a/src/Input/ButtonStatus.cs b/src/Input/ButtonStatus.cs index 6f341d7..0f8930f 100644 --- a/src/Input/ButtonStatus.cs +++ b/src/Input/ButtonStatus.cs @@ -3,15 +3,19 @@ public enum ButtonStatus { /// - /// Indicates that the input is not pressed. + /// Indicates that the button was not pressed last frame and is still not pressed. + /// + Idle, + /// + /// Indicates that the button was released this frame. /// Released, /// - /// Indicates that the input was pressed this frame. + /// Indicates that the button was pressed this frame. /// Pressed, /// - /// Indicates that the input has been held for multiple frames. + /// Indicates that the button has been held for multiple frames. /// Held } diff --git a/src/Input/Keyboard.cs b/src/Input/Keyboard.cs index ac66018..0ce091f 100644 --- a/src/Input/Keyboard.cs +++ b/src/Input/Keyboard.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Runtime.InteropServices; using SDL2; namespace MoonWorks.Input