using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Input; namespace MonoGame.Extended.Input; /// /// Represents mouse input. /// /// /// This si an extended version of the default class which offers /// internal tracking of both the previous and current state of mouse input. /// public static class MouseExtended { private static MouseState _currentMouseState; private static MouseState _previousMouseState; /// /// Gets the state of mouse input. /// /// /// A value that represents the state of mouse input. /// public static MouseStateExtended GetState() { return new MouseStateExtended(_currentMouseState, _previousMouseState); } /// /// Updates the . /// /// /// This internally will overwrite the source data for the previous state with the current state, then get the /// current state from the mouse input. This should only be called once per update cycle. Calling it more than /// once per update cycle can result in the cached previous state being overwritten with invalid data. /// public static void Update() { _previousMouseState = _currentMouseState; _currentMouseState = Mouse.GetState(); } /// /// Sets the position of the mouse cursor to the specified coordinates relative to the game window. /// /// The x-coordinate position. /// The y-coordinate position. public static void SetPosition(int x, int y) => Mouse.SetPosition(x, y); /// /// Sets the position of the mouse cursor to the specified coordinate relative to the game window. /// /// A value that represents the x- and y-coordinate positions. public static void SetPosition(Point point) => Mouse.SetPosition(point.X, point.Y); #if !FNA /// /// Sets the cursor of the mouse. /// /// The cursor to use. public static void SetCursor(MouseCursor cursor) => Mouse.SetCursor(cursor); #endif /// /// Gets or Sets the window handle of the mouse. /// public static IntPtr WindowHandle { get => Mouse.WindowHandle; set => Mouse.WindowHandle = value; } }