From 567c422f8cd42eba2437f9a8c2522716a1649be7 Mon Sep 17 00:00:00 2001 From: hazel Date: Mon, 26 Jan 2026 22:04:39 +0100 Subject: celesteia archive, last updated april 9th 2024 Signed-off-by: hazel --- source/game/input/MouseHelper.cs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 source/game/input/MouseHelper.cs (limited to 'source/game/input/MouseHelper.cs') 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 -- cgit v1.2.3