Explorar o código

Add pointer input to tracking system

Jean-David Moisan %!s(int64=4) %!d(string=hai) anos
pai
achega
f54c910aa1
Modificáronse 2 ficheiros con 18 adicións e 3 borrados
  1. 5 3
      Source/MouseCondition.cs
  2. 13 0
      Source/Track/MouseCondition.cs

+ 5 - 3
Source/MouseCondition.cs

@@ -57,14 +57,16 @@ namespace Apos.Input {
         /// <returns>Returns the difference between last frame and this frame's scroll wheel value.</returns>
         public static int ScrollDelta => InputHelper.NewMouse.ScrollWheelValue - InputHelper.OldMouse.ScrollWheelValue;
 
+        /// <returns>Returns true when the mouse pointer is moved.</returns>
+        public static bool PointerMoved() => PointerDelta != Point.Zero;
+        ///<returns>Returns the difference between the last frame and this frame's mouse pointer position.</returns>
+        public static Point PointerDelta => InputHelper.NewMouse.Position - InputHelper.OldMouse.Position;
+
         /// <returns>Returns true when the mouse is within the game window and active.</returns>
         public static bool IsMouseValid => InputHelper.IsActive &&
                 0 <= InputHelper.NewMouse.X && InputHelper.NewMouse.X <= InputHelper.WindowWidth &&
                 0 <= InputHelper.NewMouse.Y && InputHelper.NewMouse.Y <= InputHelper.WindowHeight;
 
-        ///<returns>Returns the difference between the last frame and this frame's mouse pointer position</returns>
-        public static Point PointerDelta => InputHelper.NewMouse.Position - InputHelper.OldMouse.Position;
-
         /// <summary>
         /// The button that will be checked.
         /// </summary>

+ 13 - 0
Source/Track/MouseCondition.cs

@@ -1,4 +1,5 @@
 using System.Collections.Generic;
+using Microsoft.Xna.Framework;
 
 namespace Apos.Input.Track {
     /// <summary>
@@ -82,6 +83,18 @@ namespace Apos.Input.Track {
         /// <returns>Returns the difference between last frame and this frame's scroll wheel value.</returns>
         public static int ScrollDelta => Apos.Input.MouseCondition.ScrollDelta;
 
+        /// <returns>Returns true when the mouse pointer is moved.</returns>
+        public static bool PointerMoved(bool canConsume = true) {
+            if (IsUnique(MouseSensor.Pointer) && Apos.Input.MouseCondition.PointerMoved()) {
+                if (canConsume)
+                    Consume(MouseSensor.Pointer);
+                return true;
+            }
+            return false;
+        }
+        ///<returns>Returns the difference between the last frame and this frame's mouse pointer position.</returns>
+        public static Point PointerDelta => Apos.Input.MouseCondition.PointerDelta;
+
         /// <summary>Mark the mouse button as used for this frame.</summary>
         public static void Consume(MouseButton button) {
             ButtonTracker[button] = InputHelper.CurrentFrame;