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.sdljoystick; 8 9 import bindbc.sdl.config; 10 import bindbc.sdl.bind.sdlstdinc : SDL_bool; 11 12 struct SDL_Joystick; 13 14 struct SDL_JoystickGUID { 15 ubyte[16] data; 16 } 17 18 alias SDL_JoystickID = int; 19 20 enum : ubyte { 21 SDL_HAT_CENTERED = 0x00, 22 SDL_HAT_UP = 0x01, 23 SDL_HAT_RIGHT = 0x02, 24 SDL_HAT_DOWN = 0x04, 25 SDL_HAT_LEFT = 0x08, 26 SDL_HAT_RIGHTUP = (SDL_HAT_RIGHT|SDL_HAT_UP), 27 SDL_HAT_RIGHTDOWN = (SDL_HAT_RIGHT|SDL_HAT_DOWN), 28 SDL_HAT_LEFTUP = (SDL_HAT_LEFT|SDL_HAT_UP), 29 SDL_HAT_LEFTDOWN = (SDL_HAT_LEFT|SDL_HAT_DOWN), 30 } 31 32 static if(sdlSupport >= SDLSupport.sdl204) { 33 enum SDL_JoystickPowerLevel { 34 SDL_JOYSTICK_POWER_UNKNOWN = -1, 35 SDL_JOYSTICK_POWER_EMPTY, 36 SDL_JOYSTICK_POWER_LOW, 37 SDL_JOYSTICK_POWER_MEDIUM, 38 SDL_JOYSTICK_POWER_FULL, 39 SDL_JOYSTICK_POWER_WIRED, 40 SDL_JOYSTICK_POWER_MAX 41 } 42 mixin(expandEnum!SDL_JoystickPowerLevel); 43 } 44 45 static if(sdlSupport >= SDLSupport.sdl206) { 46 enum SDL_JoystickType { 47 SDL_JOYSTICK_TYPE_UNKNOWN, 48 SDL_JOYSTICK_TYPE_GAMECONTROLLER, 49 SDL_JOYSTICK_TYPE_WHEEL, 50 SDL_JOYSTICK_TYPE_ARCADE_STICK, 51 SDL_JOYSTICK_TYPE_FLIGHT_STICK, 52 SDL_JOYSTICK_TYPE_DANCE_PAD, 53 SDL_JOYSTICK_TYPE_GUITAR, 54 SDL_JOYSTICK_TYPE_DRUM_KIT, 55 SDL_JOYSTICK_TYPE_ARCADE_PAD, 56 SDL_JOYSTICK_TYPE_THROTTLE, 57 } 58 mixin(expandEnum!SDL_JoystickType); 59 60 enum { 61 SDL_JOYSTICK_AXIS_MAX = 32767, 62 SDL_JOYSTICK_AXIS_MIN = -32768, 63 } 64 } 65 66 version(BindSDL_Static) { 67 extern(C) @nogc nothrow { 68 int SDL_NumJoysticks(); 69 const(char)* SDL_JoystickNameForIndex(int); 70 SDL_JoystickGUID SDL_JoystickGetDeviceGUID(int); 71 SDL_Joystick* SDL_JoystickOpen(int); 72 const(char)* SDL_JoystickName(SDL_Joystick*); 73 SDL_JoystickGUID SDL_JoystickGetGUID(SDL_Joystick*); 74 char* SDL_JoystickGetGUIDString(SDL_JoystickGUID); 75 SDL_JoystickGUID SDL_JoystickGetGUIDFromString(const(char)*); 76 SDL_bool SDL_JoystickGetAttached(SDL_Joystick*); 77 SDL_JoystickID SDL_JoystickInstanceID(SDL_Joystick*); 78 int SDL_JoystickNumAxes(SDL_Joystick*); 79 int SDL_JoystickNumBalls(SDL_Joystick*); 80 int SDL_JoystickNumHats(SDL_Joystick*); 81 int SDL_JoystickNumButtons(SDL_Joystick*); 82 void SDL_JoystickUpdate(); 83 int SDL_JoystickEventState(int); 84 short SDL_JoystickGetAxis(SDL_Joystick*,int); 85 ubyte SDL_JoystickGetHat(SDL_Joystick*,int); 86 int SDL_JoystickGetBall(SDL_Joystick*,int,int*,int*); 87 ubyte SDL_JoystickGetButton(SDL_Joystick*,int); 88 void SDL_JoystickClose(SDL_Joystick*); 89 90 static if(sdlSupport >= SDLSupport.sdl204) { 91 SDL_JoystickPowerLevel SDL_JoystickCurrentPowerLevel(SDL_Joystick*); 92 SDL_Joystick* SDL_JoystickFromInstanceID(SDL_JoystickID); 93 } 94 static if(sdlSupport >= SDLSupport.sdl206) { 95 SDL_bool SDL_JoystickGetAxisInitialState(SDL_Joystick*,int,short*); 96 SDL_JoystickType SDL_JoystickGetDeviceInstanceID(int); 97 ushort SDL_JoystickGetDeviceProduct(int); 98 ushort SDL_JoystickGetDeviceProductVersion(int); 99 SDL_JoystickType SDL_JoystickGetDeviceType(int); 100 ushort SDL_JoystickGetDeviceVendor(int); 101 ushort SDL_JoystickGetProduct(SDL_Joystick*); 102 ushort SDL_JoystickGetProductVersion(SDL_Joystick*); 103 SDL_JoystickType SDL_JoystickGetType(SDL_Joystick*); 104 ushort SDL_JoystickGetVendor(SDL_Joystick*); 105 } 106 static if(sdlSupport >= SDLSupport.sdl207) { 107 void SDL_LockJoysticks(); 108 void SDL_UnlockJoysticks(); 109 } 110 static if(sdlSupport >= SDLSupport.sdl209) { 111 int SDL_JoystickRumble(SDL_Joystick*,ushort,ushort,uint); 112 } 113 static if(sdlSupport >= SDLSupport.sdl2010) { 114 int SDL_JoystickGetDevicePlayerIndex(int); 115 int SDL_JoystickGetPlayerIndex(SDL_Joystick*); 116 } 117 } 118 } 119 else { 120 extern(C) @nogc nothrow { 121 alias pSDL_NumJoysticks = int function(); 122 alias pSDL_JoystickNameForIndex = const(char)* function(int); 123 alias pSDL_JoystickGetDeviceGUID = SDL_JoystickGUID function(int); 124 alias pSDL_JoystickOpen = SDL_Joystick* function(int); 125 alias pSDL_JoystickName = const(char)* function(SDL_Joystick*); 126 alias pSDL_JoystickGetGUID = SDL_JoystickGUID function(SDL_Joystick*); 127 alias pSDL_JoystickGetGUIDString = char* function(SDL_JoystickGUID); 128 alias pSDL_JoystickGetGUIDFromString = SDL_JoystickGUID function(const(char)*); 129 alias pSDL_JoystickGetAttached = SDL_bool function(SDL_Joystick*); 130 alias pSDL_JoystickInstanceID = SDL_JoystickID function(SDL_Joystick*); 131 alias pSDL_JoystickNumAxes = int function(SDL_Joystick*); 132 alias pSDL_JoystickNumBalls = int function(SDL_Joystick*); 133 alias pSDL_JoystickNumHats = int function(SDL_Joystick*); 134 alias pSDL_JoystickNumButtons = int function(SDL_Joystick*); 135 alias pSDL_JoystickUpdate = void function(); 136 alias pSDL_JoystickEventState = int function(int); 137 alias pSDL_JoystickGetAxis = short function(SDL_Joystick*,int); 138 alias pSDL_JoystickGetHat = ubyte function(SDL_Joystick*,int); 139 alias pSDL_JoystickGetBall = int function(SDL_Joystick*,int,int*,int*); 140 alias pSDL_JoystickGetButton = ubyte function(SDL_Joystick*,int); 141 alias pSDL_JoystickClose = void function(SDL_Joystick*); 142 } 143 __gshared { 144 pSDL_NumJoysticks SDL_NumJoysticks; 145 pSDL_JoystickNameForIndex SDL_JoystickNameForIndex; 146 pSDL_JoystickGetDeviceGUID SDL_JoystickGetDeviceGUID; 147 pSDL_JoystickOpen SDL_JoystickOpen; 148 pSDL_JoystickName SDL_JoystickName; 149 pSDL_JoystickGetGUID SDL_JoystickGetGUID; 150 pSDL_JoystickGetGUIDString SDL_JoystickGetGUIDString; 151 pSDL_JoystickGetGUIDFromString SDL_JoystickGetGUIDFromString; 152 pSDL_JoystickGetAttached SDL_JoystickGetAttached; 153 pSDL_JoystickInstanceID SDL_JoystickInstanceID; 154 pSDL_JoystickNumAxes SDL_JoystickNumAxes; 155 pSDL_JoystickNumBalls SDL_JoystickNumBalls; 156 pSDL_JoystickNumHats SDL_JoystickNumHats; 157 pSDL_JoystickNumButtons SDL_JoystickNumButtons; 158 pSDL_JoystickUpdate SDL_JoystickUpdate; 159 pSDL_JoystickEventState SDL_JoystickEventState; 160 pSDL_JoystickGetAxis SDL_JoystickGetAxis; 161 pSDL_JoystickGetHat SDL_JoystickGetHat; 162 pSDL_JoystickGetBall SDL_JoystickGetBall; 163 pSDL_JoystickGetButton SDL_JoystickGetButton; 164 pSDL_JoystickClose SDL_JoystickClose; 165 } 166 static if(sdlSupport >= SDLSupport.sdl204) { 167 extern(C) @nogc nothrow { 168 alias pSDL_JoystickCurrentPowerLevel = SDL_JoystickPowerLevel function(SDL_Joystick*); 169 alias pSDL_JoystickFromInstanceID = SDL_Joystick* function(SDL_JoystickID); 170 } 171 __gshared { 172 pSDL_JoystickCurrentPowerLevel SDL_JoystickCurrentPowerLevel; 173 pSDL_JoystickFromInstanceID SDL_JoystickFromInstanceID; 174 } 175 } 176 static if(sdlSupport >= SDLSupport.sdl206) { 177 extern(C) @nogc nothrow { 178 alias pSDL_JoystickGetAxisInitialState = SDL_bool function(SDL_Joystick*,int,short*); 179 alias pSDL_JoystickGetDeviceInstanceID = SDL_JoystickType function(int); 180 alias pSDL_JoystickGetDeviceProduct = ushort function(int); 181 alias pSDL_JoystickGetDeviceProductVersion = ushort function(int); 182 alias pSDL_JoystickGetDeviceType = SDL_JoystickType function(int); 183 alias pSDL_JoystickGetDeviceVendor = ushort function(int); 184 alias pSDL_JoystickGetProduct = ushort function(SDL_Joystick*); 185 alias pSDL_JoystickGetProductVersion = ushort function(SDL_Joystick*); 186 alias pSDL_JoystickGetType = SDL_JoystickType function(SDL_Joystick*); 187 alias pSDL_JoystickGetVendor = ushort function(SDL_Joystick*); 188 } 189 __gshared { 190 pSDL_JoystickGetAxisInitialState SDL_JoystickGetAxisInitialState; 191 pSDL_JoystickGetDeviceInstanceID SDL_JoystickGetDeviceInstanceID; 192 pSDL_JoystickGetDeviceProduct SDL_JoystickGetDeviceProduct; 193 pSDL_JoystickGetDeviceProductVersion SDL_JoystickGetDeviceProductVersion; 194 pSDL_JoystickGetDeviceType SDL_JoystickGetDeviceType; 195 pSDL_JoystickGetDeviceVendor SDL_JoystickGetDeviceVendor; 196 pSDL_JoystickGetProduct SDL_JoystickGetProduct; 197 pSDL_JoystickGetProductVersion SDL_JoystickGetProductVersion; 198 pSDL_JoystickGetType SDL_JoystickGetType; 199 pSDL_JoystickGetVendor SDL_JoystickGetVendor; 200 } 201 } 202 static if(sdlSupport >= SDLSupport.sdl207) { 203 extern(C) @nogc nothrow { 204 alias pSDL_LockJoysticks = void function(); 205 alias pSDL_UnlockJoysticks = void function(); 206 } 207 __gshared { 208 pSDL_LockJoysticks SDL_LockJoysticks; 209 pSDL_UnlockJoysticks SDL_UnlockJoysticks; 210 } 211 } 212 static if(sdlSupport >= SDLSupport.sdl209) { 213 extern(C) @nogc nothrow { 214 alias pSDL_JoystickRumble = int function(SDL_Joystick*,ushort,ushort,uint); 215 } 216 __gshared { 217 pSDL_JoystickRumble SDL_JoystickRumble; 218 } 219 } 220 221 static if(sdlSupport >= SDLSupport.sdl2010) { 222 extern(C) @nogc nothrow { 223 alias pSDL_JoystickGetDevicePlayerIndex = int function(int); 224 alias pSDL_JoystickGetPlayerIndex = int function(SDL_Joystick*); 225 } 226 __gshared { 227 pSDL_JoystickGetDevicePlayerIndex SDL_JoystickGetDevicePlayerIndex; 228 pSDL_JoystickGetPlayerIndex SDL_JoystickGetPlayerIndex; 229 } 230 } 231 }