Root/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | #region License /* FNA - XNA4 Reimplementation for Desktop Platforms * Copyright 2009-2016 Ethan Lee and the MonoGame Team * * Released under the Microsoft Public License. * See LICENSE for details. */ #endregion #region Using Statements using System; #endregion namespace Microsoft.Xna.Framework.Input { /// <summary> /// Allows reading position and button click information from mouse. /// </summary> public static class Mouse { #region Public Properties public static IntPtr WindowHandle { get ; set ; } #endregion #region Internal Variables internal static int INTERNAL_WindowWidth = GraphicsDeviceManager.DefaultBackBufferWidth; internal static int INTERNAL_WindowHeight = GraphicsDeviceManager.DefaultBackBufferHeight; internal static int INTERNAL_BackBufferWidth = GraphicsDeviceManager.DefaultBackBufferWidth; internal static int INTERNAL_BackBufferHeight = GraphicsDeviceManager.DefaultBackBufferHeight; internal static int INTERNAL_MouseWheel = 0; // FIXME: Remove when global mouse state is accessible! -flibit internal static bool INTERNAL_IsWarped = false ; internal static int INTERNAL_warpX = 0; internal static int INTERNAL_warpY = 0; #endregion #region Public Interface /// <summary> /// Gets mouse state information that includes position and button /// presses for the provided window /// </summary> /// <returns>Current state of the mouse.</returns> public static MouseState GetState() { int x, y; ButtonState left, middle, right, x1, x2; FNAPlatform.GetMouseState( out x, out y, out left, out middle, out right, out x1, out x2 ); // If we warped the mouse, we've already done this in SetPosition. if (INTERNAL_IsWarped) { x = INTERNAL_warpX; y = INTERNAL_warpY; } else { // Scale the mouse coordinates for the faux-backbuffer x = ( int ) (( double ) x * INTERNAL_BackBufferWidth / INTERNAL_WindowWidth); y = ( int ) (( double ) y * INTERNAL_BackBufferHeight / INTERNAL_WindowHeight); } return new MouseState( x, y, INTERNAL_MouseWheel, left, middle, right, x1, x2 ); } /// <summary> /// Sets mouse cursor's relative position to game-window. /// </summary> /// <param name="x">Relative horizontal position of the cursor.</param> /// <param name="y">Relative vertical position of the cursor.</param> public static void SetPosition( int x, int y) { // The state should appear to be what they _think_ they're setting first. INTERNAL_warpX = x; INTERNAL_warpY = y; // Scale the mouse coordinates for the faux-backbuffer x = ( int ) (( double ) x * INTERNAL_WindowWidth / INTERNAL_BackBufferWidth); y = ( int ) (( double ) y * INTERNAL_WindowHeight / INTERNAL_BackBufferHeight); FNAPlatform.SetMousePosition(WindowHandle, x, y); INTERNAL_IsWarped = true ; } #endregion } } |