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 } 114 } 115 else { 116 extern(C) @nogc nothrow { 117 alias pSDL_NumJoysticks = int function(); 118 alias pSDL_JoystickNameForIndex = const(char)* function(int); 119 alias pSDL_JoystickGetDeviceGUID = SDL_JoystickGUID function(int); 120 alias pSDL_JoystickOpen = SDL_Joystick* function(int); 121 alias pSDL_JoystickName = const(char)* function(SDL_Joystick*); 122 alias pSDL_JoystickGetGUID = SDL_JoystickGUID function(SDL_Joystick*); 123 alias pSDL_JoystickGetGUIDString = char* function(SDL_JoystickGUID); 124 alias pSDL_JoystickGetGUIDFromString = SDL_JoystickGUID function(const(char)*); 125 alias pSDL_JoystickGetAttached = SDL_bool function(SDL_Joystick*); 126 alias pSDL_JoystickInstanceID = SDL_JoystickID function(SDL_Joystick*); 127 alias pSDL_JoystickNumAxes = int function(SDL_Joystick*); 128 alias pSDL_JoystickNumBalls = int function(SDL_Joystick*); 129 alias pSDL_JoystickNumHats = int function(SDL_Joystick*); 130 alias pSDL_JoystickNumButtons = int function(SDL_Joystick*); 131 alias pSDL_JoystickUpdate = void function(); 132 alias pSDL_JoystickEventState = int function(int); 133 alias pSDL_JoystickGetAxis = short function(SDL_Joystick*,int); 134 alias pSDL_JoystickGetHat = ubyte function(SDL_Joystick*,int); 135 alias pSDL_JoystickGetBall = int function(SDL_Joystick*,int,int*,int*); 136 alias pSDL_JoystickGetButton = ubyte function(SDL_Joystick*,int); 137 alias pSDL_JoystickClose = void function(SDL_Joystick*); 138 } 139 140 __gshared { 141 pSDL_NumJoysticks SDL_NumJoysticks; 142 pSDL_JoystickNameForIndex SDL_JoystickNameForIndex; 143 pSDL_JoystickGetDeviceGUID SDL_JoystickGetDeviceGUID; 144 pSDL_JoystickOpen SDL_JoystickOpen; 145 pSDL_JoystickName SDL_JoystickName; 146 pSDL_JoystickGetGUID SDL_JoystickGetGUID; 147 pSDL_JoystickGetGUIDString SDL_JoystickGetGUIDString; 148 pSDL_JoystickGetGUIDFromString SDL_JoystickGetGUIDFromString; 149 pSDL_JoystickGetAttached SDL_JoystickGetAttached; 150 pSDL_JoystickInstanceID SDL_JoystickInstanceID; 151 pSDL_JoystickNumAxes SDL_JoystickNumAxes; 152 pSDL_JoystickNumBalls SDL_JoystickNumBalls; 153 pSDL_JoystickNumHats SDL_JoystickNumHats; 154 pSDL_JoystickNumButtons SDL_JoystickNumButtons; 155 pSDL_JoystickUpdate SDL_JoystickUpdate; 156 pSDL_JoystickEventState SDL_JoystickEventState; 157 pSDL_JoystickGetAxis SDL_JoystickGetAxis; 158 pSDL_JoystickGetHat SDL_JoystickGetHat; 159 pSDL_JoystickGetBall SDL_JoystickGetBall; 160 pSDL_JoystickGetButton SDL_JoystickGetButton; 161 pSDL_JoystickClose SDL_JoystickClose; 162 } 163 164 static if(sdlSupport >= SDLSupport.sdl204) { 165 extern(C) @nogc nothrow { 166 alias pSDL_JoystickCurrentPowerLevel = SDL_JoystickPowerLevel function(SDL_Joystick*); 167 alias pSDL_JoystickFromInstanceID = SDL_Joystick* function(SDL_JoystickID); 168 } 169 170 __gshared { 171 pSDL_JoystickCurrentPowerLevel SDL_JoystickCurrentPowerLevel; 172 pSDL_JoystickFromInstanceID SDL_JoystickFromInstanceID; 173 } 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 190 __gshared { 191 pSDL_JoystickGetAxisInitialState SDL_JoystickGetAxisInitialState; 192 pSDL_JoystickGetDeviceInstanceID SDL_JoystickGetDeviceInstanceID; 193 pSDL_JoystickGetDeviceProduct SDL_JoystickGetDeviceProduct; 194 pSDL_JoystickGetDeviceProductVersion SDL_JoystickGetDeviceProductVersion; 195 pSDL_JoystickGetDeviceType SDL_JoystickGetDeviceType; 196 pSDL_JoystickGetDeviceVendor SDL_JoystickGetDeviceVendor; 197 pSDL_JoystickGetProduct SDL_JoystickGetProduct; 198 pSDL_JoystickGetProductVersion SDL_JoystickGetProductVersion; 199 pSDL_JoystickGetType SDL_JoystickGetType; 200 pSDL_JoystickGetVendor SDL_JoystickGetVendor; 201 } 202 } 203 204 static if(sdlSupport >= SDLSupport.sdl207) { 205 extern(C) @nogc nothrow { 206 alias pSDL_LockJoysticks = void function(); 207 alias pSDL_UnlockJoysticks = void function(); 208 } 209 210 __gshared { 211 pSDL_LockJoysticks SDL_LockJoysticks; 212 pSDL_UnlockJoysticks SDL_UnlockJoysticks; 213 } 214 } 215 216 static if(sdlSupport >= SDLSupport.sdl207) { 217 extern(C) @nogc nothrow { 218 alias pSDL_JoystickRumble = int function(SDL_Joystick*,ushort,ushort,uint); 219 } 220 221 __gshared { 222 pSDL_JoystickRumble SDL_JoystickRumble; 223 } 224 } 225 }