diff options
Diffstat (limited to 'source/game/input/MouseHelper.cs')
| -rw-r--r-- | source/game/input/MouseHelper.cs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/source/game/input/MouseHelper.cs b/source/game/input/MouseHelper.cs new file mode 100644 index 0000000..3000c6e --- /dev/null +++ b/source/game/input/MouseHelper.cs @@ -0,0 +1,37 @@ +using Celesteia.Game.Input.Definitions; +using Microsoft.Xna.Framework; +using MonoGame.Extended.Input; + +namespace Celesteia.Game.Input { + public static class MouseHelper { + private static MouseStateExtended _prev; + private static MouseStateExtended _curr; + + public static int ScrollDelta => _curr.ScrollWheelValue - _prev.ScrollWheelValue; + + // Get the position of the mouse pointer on the SCREEN, not the VIEWPORT. + public static Point Position => _curr.Position; + + public static void Update() { + _prev = _curr; + _curr = MouseExtended.GetState(); + } + + // Was true, now true. + public static bool Held(MouseButton button) => _prev.IsButtonDown(button) && _curr.IsButtonDown(button); + // Is true. + public static bool IsDown(MouseButton button) => _curr.IsButtonDown(button); + // Was false, now true. + public static bool Pressed(MouseButton button) => !_prev.IsButtonDown(button) && _curr.IsButtonDown(button); + // Was true, now false. + public static bool Released(MouseButton button) => _prev.IsButtonDown(button) && !_curr.IsButtonDown(button); + + public static bool Poll(MouseButton button, InputPollType type) => type switch { + InputPollType.Held => Held(button), + InputPollType.IsDown => IsDown(button), + InputPollType.Pressed => Pressed(button), + InputPollType.Released => Released(button), + _ => false + }; + } +}
\ No newline at end of file |
