aboutsummaryrefslogtreecommitdiff
path: root/source/game/input/MouseHelper.cs
diff options
context:
space:
mode:
authorhazel <hazel@hazelthats.me>2026-01-26 22:04:39 +0100
committerhazel <hazel@hazelthats.me>2026-01-26 22:04:39 +0100
commit567c422f8cd42eba2437f9a8c2522716a1649be7 (patch)
tree93c5b296f3b7c14b626d0aadf5cad37764c41c74 /source/game/input/MouseHelper.cs
downloadcelesteia-567c422f8cd42eba2437f9a8c2522716a1649be7.tar.gz
celesteia-567c422f8cd42eba2437f9a8c2522716a1649be7.tar.bz2
celesteia-567c422f8cd42eba2437f9a8c2522716a1649be7.zip
celesteia archive, last updated april 9th 2024
Signed-off-by: hazel <hazel@hazelthats.me>
Diffstat (limited to 'source/game/input/MouseHelper.cs')
-rw-r--r--source/game/input/MouseHelper.cs37
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