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 static if(staticBinding) { 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 static if(sdlSupport >= SDLSupport.sdl2012) { 118 SDL_Joystick* SDL_JoystickFromPlayerIndex(int); 119 void SDL_JoystickSetPlayerIndex(SDL_Joystick*,int); 120 } 121 } 122 } 123 else { 124 extern(C) @nogc nothrow { 125 alias pSDL_NumJoysticks = int function(); 126 alias pSDL_JoystickNameForIndex = const(char)* function(int); 127 alias pSDL_JoystickGetDeviceGUID = SDL_JoystickGUID function(int); 128 alias pSDL_JoystickOpen = SDL_Joystick* function(int); 129 alias pSDL_JoystickName = const(char)* function(SDL_Joystick*); 130 alias pSDL_JoystickGetGUID = SDL_JoystickGUID function(SDL_Joystick*); 131 alias pSDL_JoystickGetGUIDString = char* function(SDL_JoystickGUID); 132 alias pSDL_JoystickGetGUIDFromString = SDL_JoystickGUID function(const(char)*); 133 alias pSDL_JoystickGetAttached = SDL_bool function(SDL_Joystick*); 134 alias pSDL_JoystickInstanceID = SDL_JoystickID function(SDL_Joystick*); 135 alias pSDL_JoystickNumAxes = int function(SDL_Joystick*); 136 alias pSDL_JoystickNumBalls = int function(SDL_Joystick*); 137 alias pSDL_JoystickNumHats = int function(SDL_Joystick*); 138 alias pSDL_JoystickNumButtons = int function(SDL_Joystick*); 139 alias pSDL_JoystickUpdate = void function(); 140 alias pSDL_JoystickEventState = int function(int); 141 alias pSDL_JoystickGetAxis = short function(SDL_Joystick*,int); 142 alias pSDL_JoystickGetHat = ubyte function(SDL_Joystick*,int); 143 alias pSDL_JoystickGetBall = int function(SDL_Joystick*,int,int*,int*); 144 alias pSDL_JoystickGetButton = ubyte function(SDL_Joystick*,int); 145 alias pSDL_JoystickClose = void function(SDL_Joystick*); 146 } 147 __gshared { 148 pSDL_NumJoysticks SDL_NumJoysticks; 149 pSDL_JoystickNameForIndex SDL_JoystickNameForIndex; 150 pSDL_JoystickGetDeviceGUID SDL_JoystickGetDeviceGUID; 151 pSDL_JoystickOpen SDL_JoystickOpen; 152 pSDL_JoystickName SDL_JoystickName; 153 pSDL_JoystickGetGUID SDL_JoystickGetGUID; 154 pSDL_JoystickGetGUIDString SDL_JoystickGetGUIDString; 155 pSDL_JoystickGetGUIDFromString SDL_JoystickGetGUIDFromString; 156 pSDL_JoystickGetAttached SDL_JoystickGetAttached; 157 pSDL_JoystickInstanceID SDL_JoystickInstanceID; 158 pSDL_JoystickNumAxes SDL_JoystickNumAxes; 159 pSDL_JoystickNumBalls SDL_JoystickNumBalls; 160 pSDL_JoystickNumHats SDL_JoystickNumHats; 161 pSDL_JoystickNumButtons SDL_JoystickNumButtons; 162 pSDL_JoystickUpdate SDL_JoystickUpdate; 163 pSDL_JoystickEventState SDL_JoystickEventState; 164 pSDL_JoystickGetAxis SDL_JoystickGetAxis; 165 pSDL_JoystickGetHat SDL_JoystickGetHat; 166 pSDL_JoystickGetBall SDL_JoystickGetBall; 167 pSDL_JoystickGetButton SDL_JoystickGetButton; 168 pSDL_JoystickClose SDL_JoystickClose; 169 } 170 static if(sdlSupport >= SDLSupport.sdl204) { 171 extern(C) @nogc nothrow { 172 alias pSDL_JoystickCurrentPowerLevel = SDL_JoystickPowerLevel function(SDL_Joystick*); 173 alias pSDL_JoystickFromInstanceID = SDL_Joystick* function(SDL_JoystickID); 174 } 175 __gshared { 176 pSDL_JoystickCurrentPowerLevel SDL_JoystickCurrentPowerLevel; 177 pSDL_JoystickFromInstanceID SDL_JoystickFromInstanceID; 178 } 179 } 180 static if(sdlSupport >= SDLSupport.sdl206) { 181 extern(C) @nogc nothrow { 182 alias pSDL_JoystickGetAxisInitialState = SDL_bool function(SDL_Joystick*,int,short*); 183 alias pSDL_JoystickGetDeviceInstanceID = SDL_JoystickType function(int); 184 alias pSDL_JoystickGetDeviceProduct = ushort function(int); 185 alias pSDL_JoystickGetDeviceProductVersion = ushort function(int); 186 alias pSDL_JoystickGetDeviceType = SDL_JoystickType function(int); 187 alias pSDL_JoystickGetDeviceVendor = ushort function(int); 188 alias pSDL_JoystickGetProduct = ushort function(SDL_Joystick*); 189 alias pSDL_JoystickGetProductVersion = ushort function(SDL_Joystick*); 190 alias pSDL_JoystickGetType = SDL_JoystickType function(SDL_Joystick*); 191 alias pSDL_JoystickGetVendor = ushort function(SDL_Joystick*); 192 } 193 __gshared { 194 pSDL_JoystickGetAxisInitialState SDL_JoystickGetAxisInitialState; 195 pSDL_JoystickGetDeviceInstanceID SDL_JoystickGetDeviceInstanceID; 196 pSDL_JoystickGetDeviceProduct SDL_JoystickGetDeviceProduct; 197 pSDL_JoystickGetDeviceProductVersion SDL_JoystickGetDeviceProductVersion; 198 pSDL_JoystickGetDeviceType SDL_JoystickGetDeviceType; 199 pSDL_JoystickGetDeviceVendor SDL_JoystickGetDeviceVendor; 200 pSDL_JoystickGetProduct SDL_JoystickGetProduct; 201 pSDL_JoystickGetProductVersion SDL_JoystickGetProductVersion; 202 pSDL_JoystickGetType SDL_JoystickGetType; 203 pSDL_JoystickGetVendor SDL_JoystickGetVendor; 204 } 205 } 206 static if(sdlSupport >= SDLSupport.sdl207) { 207 extern(C) @nogc nothrow { 208 alias pSDL_LockJoysticks = void function(); 209 alias pSDL_UnlockJoysticks = void function(); 210 } 211 __gshared { 212 pSDL_LockJoysticks SDL_LockJoysticks; 213 pSDL_UnlockJoysticks SDL_UnlockJoysticks; 214 } 215 } 216 static if(sdlSupport >= SDLSupport.sdl209) { 217 extern(C) @nogc nothrow { 218 alias pSDL_JoystickRumble = int function(SDL_Joystick*,ushort,ushort,uint); 219 } 220 __gshared { 221 pSDL_JoystickRumble SDL_JoystickRumble; 222 } 223 } 224 static if(sdlSupport >= SDLSupport.sdl2010) { 225 extern(C) @nogc nothrow { 226 alias pSDL_JoystickGetDevicePlayerIndex = int function(int); 227 alias pSDL_JoystickGetPlayerIndex = int function(SDL_Joystick*); 228 } 229 __gshared { 230 pSDL_JoystickGetDevicePlayerIndex SDL_JoystickGetDevicePlayerIndex; 231 pSDL_JoystickGetPlayerIndex SDL_JoystickGetPlayerIndex; 232 } 233 } 234 static if(sdlSupport >= SDLSupport.sdl2012) { 235 extern(C) @nogc nothrow { 236 alias pSDL_JoystickFromPlayerIndex = SDL_Joystick* function(int); 237 alias pSDL_JoystickSetPlayerIndex = void function(SDL_Joystick*,int); 238 } 239 __gshared { 240 pSDL_JoystickFromPlayerIndex SDL_JoystickFromPlayerIndex; 241 pSDL_JoystickSetPlayerIndex SDL_JoystickSetPlayerIndex; 242 } 243 } 244 }