1 2 // Copyright Michael D. Parker 2018. 3 // Distributed under the Boost Software License, Version 1.0. 4 // (See accompanying file LICENSE_1_0.txt or copy at 5 // http://www.boost.org/LICENSE_1_0.txt) 6 7 module bindbc.sdl.bind.sdlmouse; 8 9 import bindbc.sdl.config; 10 import bindbc.sdl.bind.sdlstdinc : SDL_bool; 11 import bindbc.sdl.bind.sdlsurface : SDL_Surface; 12 import bindbc.sdl.bind.sdlvideo : SDL_Window; 13 14 struct SDL_Cursor; 15 16 enum SDL_SystemCursor { 17 SDL_SYSTEM_CURSOR_ARROW, 18 SDL_SYSTEM_CURSOR_IBEAM, 19 SDL_SYSTEM_CURSOR_WAIT, 20 SDL_SYSTEM_CURSOR_CROSSHAIR, 21 SDL_SYSTEM_CURSOR_WAITARROW, 22 SDL_SYSTEM_CURSOR_SIZENWSE, 23 SDL_SYSTEM_CURSOR_SIZENESW, 24 SDL_SYSTEM_CURSOR_SIZEWE, 25 SDL_SYSTEM_CURSOR_SIZENS, 26 SDL_SYSTEM_CURSOR_SIZEALL, 27 SDL_SYSTEM_CURSOR_NO, 28 SDL_SYSTEM_CURSOR_HAND, 29 SDL_NUM_SYSTEM_CURSORS 30 } 31 32 alias SDL_SYSTEM_CURSOR_ARROW = SDL_SystemCursor.SDL_SYSTEM_CURSOR_ARROW; 33 alias SDL_SYSTEM_CURSOR_IBEAM = SDL_SystemCursor.SDL_SYSTEM_CURSOR_IBEAM; 34 alias SDL_SYSTEM_CURSOR_WAIT = SDL_SystemCursor.SDL_SYSTEM_CURSOR_WAIT; 35 alias SDL_SYSTEM_CURSOR_CROSSHAIR = SDL_SystemCursor.SDL_SYSTEM_CURSOR_CROSSHAIR; 36 alias SDL_SYSTEM_CURSOR_WAITARROW = SDL_SystemCursor.SDL_SYSTEM_CURSOR_WAITARROW; 37 alias SDL_SYSTEM_CURSOR_SIZENWSE = SDL_SystemCursor.SDL_SYSTEM_CURSOR_SIZENWSE; 38 alias SDL_SYSTEM_CURSOR_SIZENESW = SDL_SystemCursor.SDL_SYSTEM_CURSOR_SIZENESW; 39 alias SDL_SYSTEM_CURSOR_SIZEWE = SDL_SystemCursor.SDL_SYSTEM_CURSOR_SIZEWE; 40 alias SDL_SYSTEM_CURSOR_SIZENS = SDL_SystemCursor.SDL_SYSTEM_CURSOR_SIZENS; 41 alias SDL_SYSTEM_CURSOR_SIZEALL = SDL_SystemCursor.SDL_SYSTEM_CURSOR_SIZEALL; 42 alias SDL_SYSTEM_CURSOR_NO = SDL_SystemCursor.SDL_SYSTEM_CURSOR_NO; 43 alias SDL_SYSTEM_CURSOR_HAND = SDL_SystemCursor.SDL_SYSTEM_CURSOR_HAND; 44 alias SDL_NUM_SYSTEM_CURSORS = SDL_SystemCursor.SDL_NUM_SYSTEM_CURSORS; 45 46 enum SDL_BUTTON(ubyte x) = 1 << (x-1); 47 48 enum : ubyte { 49 SDL_BUTTON_LEFT = 1, 50 SDL_BUTTON_MIDDLE = 2, 51 SDL_BUTTON_RIGHT = 3, 52 SDL_BUTTON_X1 = 4, 53 SDL_BUTTON_X2 = 5, 54 SDL_BUTTON_LMASK = SDL_BUTTON!(SDL_BUTTON_LEFT), 55 SDL_BUTTON_MMASK = SDL_BUTTON!(SDL_BUTTON_MIDDLE), 56 SDL_BUTTON_RMASK = SDL_BUTTON!(SDL_BUTTON_RIGHT), 57 SDL_BUTTON_X1MASK = SDL_BUTTON!(SDL_BUTTON_X1), 58 SDL_BUTTON_X2MASK = SDL_BUTTON!(SDL_BUTTON_X2), 59 } 60 61 static if(sdlSupport >= SDLSupport.sdl204) { 62 enum SDL_MouseWheelDirection { 63 SDL_MOUSEWHEEL_NORMAL, 64 SDL_MOUSEWHEEL_FLIPPED, 65 } 66 } 67 68 version(BindSDL_Static) { 69 extern(C) @nogc nothrow { 70 SDL_Window* SDL_GetMouseFocus(); 71 uint SDL_GetMouseState(int*,int*); 72 uint SDL_GetRelativeMouseState(int*,int*); 73 void SDL_WarpMouseInWindow(SDL_Window*,int,int); 74 int SDL_SetRelativeMouseMode(SDL_bool); 75 SDL_bool SDL_GetRelativeMouseMode(); 76 SDL_Cursor* SDL_CreateCursor(const(ubyte)*,const(ubyte)*,int,int,int,int); 77 SDL_Cursor* SDL_CreateColorCursor(SDL_Surface*,int,int); 78 SDL_Cursor* SDL_CreateSystemCursor(SDL_SystemCursor); 79 void SDL_SetCursor(SDL_Cursor*); 80 SDL_Cursor* SDL_GetCursor(); 81 SDL_Cursor* SDL_GetDefaultCursor(); 82 void SDL_FreeCursor(SDL_Cursor*); 83 int SDL_ShowCursor(int); 84 85 static if(sdlSupport >= SDLSupport.sdl204) { 86 int SDL_CaptureMouse(SDL_bool); 87 uint SDL_GetGlobalMouseState(int*,int*); 88 void SDL_WarpMouseGlobal(int,int); 89 } 90 } 91 } 92 else { 93 extern(C) @nogc nothrow { 94 alias pSDL_GetMouseFocus = SDL_Window* function(); 95 alias pSDL_GetMouseState = uint function(int*,int*); 96 alias pSDL_GetRelativeMouseState = uint function(int*,int*); 97 alias pSDL_WarpMouseInWindow = void function(SDL_Window*,int,int); 98 alias pSDL_SetRelativeMouseMode = int function(SDL_bool); 99 alias pSDL_GetRelativeMouseMode = SDL_bool function(); 100 alias pSDL_CreateCursor = SDL_Cursor* function(const(ubyte)*,const(ubyte)*,int,int,int,int); 101 alias pSDL_CreateColorCursor = SDL_Cursor* function(SDL_Surface*,int,int); 102 alias pSDL_CreateSystemCursor = SDL_Cursor* function(SDL_SystemCursor); 103 alias pSDL_SetCursor = void function(SDL_Cursor*); 104 alias pSDL_GetCursor = SDL_Cursor* function(); 105 alias pSDL_GetDefaultCursor = SDL_Cursor* function(); 106 alias pSDL_FreeCursor = void function(SDL_Cursor*); 107 alias pSDL_ShowCursor = int function(int); 108 } 109 110 __gshared { 111 pSDL_GetMouseFocus SDL_GetMouseFocus; 112 pSDL_GetMouseState SDL_GetMouseState; 113 pSDL_GetRelativeMouseState SDL_GetRelativeMouseState; 114 pSDL_WarpMouseInWindow SDL_WarpMouseInWindow; 115 pSDL_SetRelativeMouseMode SDL_SetRelativeMouseMode; 116 pSDL_GetRelativeMouseMode SDL_GetRelativeMouseMode; 117 pSDL_CreateCursor SDL_CreateCursor; 118 pSDL_CreateColorCursor SDL_CreateColorCursor; 119 pSDL_CreateSystemCursor SDL_CreateSystemCursor; 120 pSDL_SetCursor SDL_SetCursor; 121 pSDL_GetCursor SDL_GetCursor; 122 pSDL_GetDefaultCursor SDL_GetDefaultCursor; 123 pSDL_FreeCursor SDL_FreeCursor; 124 pSDL_ShowCursor SDL_ShowCursor; 125 } 126 127 static if(sdlSupport >= SDLSupport.sdl204) { 128 extern(C) @nogc nothrow { 129 alias pSDL_CaptureMouse = int function(SDL_bool); 130 alias pSDL_GetGlobalMouseState = uint function(int*,int*); 131 alias pSDL_WarpMouseGlobal = void function(int,int); 132 } 133 134 __gshared { 135 pSDL_CaptureMouse SDL_CaptureMouse; 136 pSDL_GetGlobalMouseState SDL_GetGlobalMouseState; 137 pSDL_WarpMouseGlobal SDL_WarpMouseGlobal; 138 } 139 } 140 }