diff --git a/DotSDL/Interop/Core/Mouse.cs b/DotSDL/Interop/Core/Mouse.cs new file mode 100644 index 0000000..fec1cd5 --- /dev/null +++ b/DotSDL/Interop/Core/Mouse.cs @@ -0,0 +1,193 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; + +namespace DotSDL.Interop.Core { + /// + /// Contains the necessary constants and function imports from SDL_mouse.h. + /// + internal static class Mouse { + /// + /// Specifies valid mouse cursor states. + /// + [SuppressMessage("ReSharper", "InconsistentNaming")] + internal enum SystemCursor : uint { + /// The standard mouse pointer. + Arrow, + + /// The I-beam cursor, usually used for text boxes. + IBeam, + + /// The wait cursor, usually represented by an hourglass. + Wait, + + /// The crosshair cursor. + Crosshair, + + /// The wait/arrow cursor, usually represented by an arrow with + /// an hourglass next to it. + WaitArrow, + + /// Double arrow pointing northwest and southeast. + SizeNwSe, + + /// Double arrow pointing northeast and southwest. + SizeNeSw, + + /// Double arrow pointing west and east. + SizeWE, + + /// Double arrow pointing north and south. + SizeNS, + + /// Four pointed arrow pointing north, south, east, and west. + SizeAll, + + /// Slashed circle. + No, + + /// Hand pointer, usually used for hyperlinks. + Hand + } + + /// + /// Defines the valid scroll wheel directions for the system. + /// + internal enum MouseWheelDirection : uint { + /// The scroll direction is normal (up increments, down decrements). + Normal, + + /// The scroll direction is inverted/natural (up decrements, down increments). + Inverted + } + + /// + /// Capture the mouse in order to track input outside an SDL window. Capturing allows + /// mouse events to be obtained globally instead of just within the main window. Unlike + /// relative mode, no change is made to the cursor and it is not constrained to the window. + /// This function may deny mouse input to other windows--both in this application and + /// others on the system--so it should be used sparingly and in small bursts. For example, + /// this can be used to track the mouse while the user is dragging something, until the + /// item is dropped by the user releasing the mouse button. + /// While captured, mouse events report coordinates relative to the current + /// (foreground) window, but those coordinates may be outside of the bounds of the window, + /// including negative values. If the window loses focus while capturing, the capture + /// will be disabled automatically. + /// + /// true to capture the mouse, otherwise false (default). + /// 0 on success, or -1 if mouse capture is not supported. + /// While capturing is enabled, the current window will have the + /// flag set. + [DllImport(Meta.CoreLib, EntryPoint = "SDL_CaptureMouse", CallingConvention = CallingConvention.Cdecl)] + internal static extern int CaptureMouse(bool enabled); + + /// + /// Creates a color cursor from an SDL2 surface. + /// + /// The surface representing the cursor's appearance.' + /// The X coordinate of this cursor's hotspot. + /// The Y coordinate of this cursor's hotspot. + /// The created cursor. + [DllImport(Meta.CoreLib, EntryPoint = "SDL_CreateColorCursor", CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr CreateColorCursor(IntPtr surface, int hotX, int hotY); + + /// + /// Creates a system cursor. + /// + /// A designating what kind of cursor + /// to create. + /// The created cursor. + [DllImport(Meta.CoreLib, EntryPoint = "SDL_CreateSystemCursor", CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr CreateSystemCursor(SystemCursor id); + + /// + /// Frees a cursor created with or similar functions. + /// + /// The cursor to free. + [DllImport(Meta.CoreLib, EntryPoint = "SDL_FreeCursor", CallingConvention = CallingConvention.Cdecl)] + internal static extern void FreeCursor(IntPtr cursor); + + /// + /// Returns the default cursor. + /// + /// The default cursor. + [DllImport(Meta.CoreLib, EntryPoint = "SDL_GetDefaultCursor", CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr GetDefaultCursor(); + + /// + /// Gets the location of the mouse pointer relative to the window. + /// + /// The current X coordinate, relative to the window. + /// The current Y coordinate, relative to the window. + /// The current button state as a bitmask. + [DllImport(Meta.CoreLib, EntryPoint = "SDL_GetMouseState", CallingConvention = CallingConvention.Cdecl)] + internal static extern uint GetMouseState(ref int x, ref int y); + + /// + /// Gets the location of the mouse pointer relative to the top-left of the desktop. + /// + /// The current X coordinate, relative to the desktop. + /// The current Y coordinate, relative to the desktop. + /// The current button state as a bitmask. + [DllImport(Meta.CoreLib, EntryPoint = "SDL_GetGlobalMouseState", CallingConvention = CallingConvention.Cdecl)] + internal static extern uint GetGlobalMouseState(ref int x, ref int y); + + /// + /// Queries whether relative mouse mode is enabled. + /// + /// true if relative mouse mode is enabled, otherwise false. + [DllImport(Meta.CoreLib, EntryPoint = "SDL_GetRelativeMouseMode", CallingConvention = CallingConvention.Cdecl)] + internal static extern bool GetRelativeMouseMode(); + + /// + /// Gets the location of the mouse pointer relative to the last time this function + /// was called. + /// + /// The current X coordinate, relative to last invocation. + /// The current Y coordinate, relative to last invocation. + /// The current button state as a bitmask. + [DllImport(Meta.CoreLib, EntryPoint = "SDL_GetRelativeMouseState", CallingConvention = CallingConvention.Cdecl)] + internal static extern uint GetRelativeMouseState(ref int x, ref int y); + + /// + /// Set relative mouse mode. While the mouse is in relative mode, the cursor is hidden and + /// the driver will try to report continuous motion in the current window. Only relative + /// motion events will be delivered and the mouse position will not change. + /// + /// true to enable relative mode, or false to use + /// absolute mode (default). + /// 0 on success, or -1 if relative mode is not supported. + /// This function will flush any pending mosue motion. + [DllImport(Meta.CoreLib, EntryPoint = "SDL_SetRelativeMouseMode", CallingConvention = CallingConvention.Cdecl)] + internal static extern int SetRelativeMouseMode(bool enabled); + + /// + /// Toggle whether or not the cursor is shown. + /// + /// 1 to show the cursor, 0 to hide it, -1 to query the current state. + /// 1 if the cursor is shown, or 0 if the cursor is hidden. + [DllImport(Meta.CoreLib, EntryPoint = "SDL_ShowCursor", CallingConvention = CallingConvention.Cdecl)] + internal static extern int ShowCursor(int toggle); + + /// + /// Moves the mouse to the given position within the window. + /// + /// The window to move the mouse into, or for + /// the current mouse focus. + /// The X coordinate within the window. + /// The Y coordinate within the window. + /// This function generates a mouse motion event. + [DllImport(Meta.CoreLib, EntryPoint = "SDL_WarpMouseInWindow", CallingConvention = CallingConvention.Cdecl)] + internal static extern void WarpMouseInWindow(IntPtr window, int x, int y); + + /// + /// Moves the mouse to the given position in global screen space. + /// + /// The X coordinate. + /// The Y coordinate. + /// 0 on success, -1 on error (usually: unsupported by a platform). + /// This function generates a mouse motion event. + [DllImport(Meta.CoreLib, EntryPoint = "SDL_WarpMouseGlobal", CallingConvention = CallingConvention.Cdecl)] + internal static extern int WarpMouseGlobal(int x, int y); + } +}