| 1 | package SDL2::gamecontroller 0.01 { | ||
| 2 | use SDL2::Utils; | ||
| 3 | use experimental 'signatures'; | ||
| 4 | # | ||
| 5 | use SDL2::stdinc; | ||
| 6 | use SDL2::error; | ||
| 7 | use SDL2::rwops; | ||
| 8 | use SDL2::sensor; | ||
| 9 | use SDL2::joystick; | ||
| 10 | # | ||
| 11 | package SDL2::GameController { | ||
| 12 | use SDL2::Utils; | ||
| 13 | our $TYPE = has(); | ||
| 14 | }; | ||
| 15 | enum SDL_GameControllerType => [ | ||
| 16 | [ SDL_CONTROLLER_TYPE_UNKNOWN => 0 ], qw[SDL_CONTROLLER_TYPE_XBOX360 | ||
| 17 | SDL_CONTROLLER_TYPE_XBOXONE | ||
| 18 | SDL_CONTROLLER_TYPE_PS3 | ||
| 19 | SDL_CONTROLLER_TYPE_PS4 | ||
| 20 | SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO | ||
| 21 | SDL_CONTROLLER_TYPE_VIRTUAL | ||
| 22 | SDL_CONTROLLER_TYPE_PS5] | ||
| 23 | ], | ||
| 24 | SDL_GameControllerBindType => [ | ||
| 25 | [ SDL_CONTROLLER_BINDTYPE_NONE => 0 ], qw[SDL_CONTROLLER_BINDTYPE_BUTTON | ||
| 26 | SDL_CONTROLLER_BINDTYPE_AXIS | ||
| 27 | SDL_CONTROLLER_BINDTYPE_HAT] | ||
| 28 | ], | ||
| 29 | SDL_GameControllerAxis => [ | ||
| 30 | [ SDL_CONTROLLER_AXIS_INVALID => -1 ], qw[ SDL_CONTROLLER_AXIS_LEFTX | ||
| 31 | SDL_CONTROLLER_AXIS_LEFTY | ||
| 32 | SDL_CONTROLLER_AXIS_RIGHTX | ||
| 33 | SDL_CONTROLLER_AXIS_RIGHTY | ||
| 34 | SDL_CONTROLLER_AXIS_TRIGGERLEFT | ||
| 35 | SDL_CONTROLLER_AXIS_TRIGGERRIGHT | ||
| 36 | SDL_CONTROLLER_AXIS_MAX] | ||
| 37 | ], | ||
| 38 | SDL_GameControllerButton => [ | ||
| 39 | [ SDL_CONTROLLER_BUTTON_INVALID => -1 ], qw[ SDL_CONTROLLER_BUTTON_A | ||
| 40 | SDL_CONTROLLER_BUTTON_B | ||
| 41 | SDL_CONTROLLER_BUTTON_X | ||
| 42 | SDL_CONTROLLER_BUTTON_Y | ||
| 43 | SDL_CONTROLLER_BUTTON_BACK | ||
| 44 | SDL_CONTROLLER_BUTTON_GUIDE | ||
| 45 | SDL_CONTROLLER_BUTTON_START | ||
| 46 | SDL_CONTROLLER_BUTTON_LEFTSTICK | ||
| 47 | SDL_CONTROLLER_BUTTON_RIGHTSTICK | ||
| 48 | SDL_CONTROLLER_BUTTON_LEFTSHOULDER | ||
| 49 | SDL_CONTROLLER_BUTTON_RIGHTSHOULDER | ||
| 50 | SDL_CONTROLLER_BUTTON_DPAD_UP | ||
| 51 | SDL_CONTROLLER_BUTTON_DPAD_DOWN | ||
| 52 | SDL_CONTROLLER_BUTTON_DPAD_LEFT | ||
| 53 | SDL_CONTROLLER_BUTTON_DPAD_RIGHT | ||
| 54 | SDL_CONTROLLER_BUTTON_MISC1 | ||
| 55 | SDL_CONTROLLER_BUTTON_PADDLE1 | ||
| 56 | SDL_CONTROLLER_BUTTON_PADDLE2 | ||
| 57 | SDL_CONTROLLER_BUTTON_PADDLE3 | ||
| 58 | SDL_CONTROLLER_BUTTON_PADDLE4 | ||
| 59 | SDL_CONTROLLER_BUTTON_TOUCHPAD | ||
| 60 | SDL_CONTROLLER_BUTTON_MAX] | ||
| 61 | ]; | ||
| 62 | |||
| 63 | package SDL2::GameControllerButtonBind { | ||
| 64 | use SDL2::Utils; | ||
| 65 | |||
| 66 | package SDL2::GameControllerButtonBind_Hat { | ||
| 67 | use SDL2::Utils; | ||
| 68 | our $TYPE = has | ||
| 69 | hat => 'int', | ||
| 70 | hat_mask => 'int'; | ||
| 71 | }; | ||
| 72 | |||
| 73 | package SDL2::GameControllerButtonBind_Value { | ||
| 74 | use SDL2::Utils; | ||
| 75 | is 'Union'; | ||
| 76 | our $TYPE = has | ||
| 77 | button => 'int', | ||
| 78 | axis => 'int', | ||
| 79 | hat => 'SDL_GameControllerButtonBind_Hat'; # GameControllerButtonBind_Hat | ||
| 80 | }; | ||
| 81 | our $TYPE = has | ||
| 82 | bindType => 'SDL_GameControllerBindType', | ||
| 83 | value => 'SDL_GameControllerButtonBind_Value'; | ||
| 84 | }; | ||
| 85 | attach gamecontroller => { | ||
| 86 | SDL_GameControllerAddMappingsFromRW => [ [ 'SDL_RWops', 'int', ], 'int' ], | ||
| 87 | SDL_GameControllerAddMapping => [ ['string'], 'int' ], | ||
| 88 | SDL_GameControllerNumMappings => [ [], 'int' ], | ||
| 89 | SDL_GameControllerMappingForIndex => [ ['int'], 'string' ], | ||
| 90 | SDL_GameControllerMappingForGUID => [ ['SDL_JoystickGUID'], 'string' ], | ||
| 91 | SDL_GameControllerMapping => [ ['SDL_GameController'], 'string' ], | ||
| 92 | SDL_IsGameController => [ ['int'], 'SDL_bool' ], | ||
| 93 | SDL_GameControllerNameForIndex => [ ['int'], 'string' ], | ||
| 94 | SDL_GameControllerTypeForIndex => [ ['int'], 'SDL_GameControllerType' ], | ||
| 95 | SDL_GameControllerMappingForDeviceIndex => [ ['int'], 'string' ], | ||
| 96 | SDL_GameControllerOpen => [ ['int'], 'SDL_GameController' ], | ||
| 97 | SDL_GameControllerFromInstanceID => [ ['SDL_JoystickID'], 'SDL_GameController' ], | ||
| 98 | SDL_GameControllerFromPlayerIndex => [ ['int'], 'SDL_GameController' ], | ||
| 99 | SDL_GameControllerName => [ ['SDL_GameController'], 'string' ], | ||
| 100 | SDL_GameControllerGetType => [ ['SDL_GameController'], 'SDL_GameControllerType' ], | ||
| 101 | SDL_GameControllerGetPlayerIndex => [ ['SDL_GameController'], 'int' ], | ||
| 102 | SDL_GameControllerSetPlayerIndex => [ [ 'SDL_GameController', 'int' ] ], | ||
| 103 | SDL_GameControllerGetVendor => [ ['SDL_GameController'], 'uint16' ], | ||
| 104 | SDL_GameControllerGetProduct => [ ['SDL_GameController'], 'uint16' ], | ||
| 105 | SDL_GameControllerGetProductVersion => [ ['SDL_GameController'], 'uint16' ], | ||
| 106 | SDL_GameControllerGetSerial => [ ['SDL_GameController'], 'string' ], | ||
| 107 | SDL_GameControllerGetAttached => [ ['SDL_GameController'], 'SDL_bool' ], | ||
| 108 | SDL_GameControllerGetJoystick => [ ['SDL_GameController'], 'SDL_Joystick' ], | ||
| 109 | SDL_GameControllerEventState => [ ['int'], 'int' ], | ||
| 110 | SDL_GameControllerUpdate => [ [] ], | ||
| 111 | # | ||
| 112 | SDL_GameControllerGetAxisFromString => [ ['string'], 'SDL_GameControllerAxis' ], | ||
| 113 | SDL_GameControllerGetStringForAxis => [ ['SDL_GameControllerAxis'], 'string' ], | ||
| 114 | SDL_GameControllerGetBindForAxis => | ||
| 115 | [ [ 'SDL_GameController', 'SDL_GameControllerAxis' ], 'SDL_GameControllerButtonBind' ], | ||
| 116 | SDL_GameControllerHasAxis => | ||
| 117 | [ [ 'SDL_GameController', 'SDL_GameControllerAxis' ], 'SDL_bool' ], | ||
| 118 | SDL_GameControllerGetAxis => | ||
| 119 | [ [ 'SDL_GameController', 'SDL_GameControllerAxis' ], 'sint16' ], | ||
| 120 | # | ||
| 121 | SDL_GameControllerGetButtonFromString => [ ['string'], 'SDL_GameControllerButton' ], | ||
| 122 | SDL_GameControllerGetStringForButton => [ ['SDL_GameControllerButton'], 'string' ], | ||
| 123 | SDL_GameControllerGetBindForButton => [ | ||
| 124 | [ 'SDL_GameController', 'SDL_GameControllerButton' ], 'SDL_GameControllerButtonBind' | ||
| 125 | ], | ||
| 126 | SDL_GameControllerHasButton => | ||
| 127 | [ [ 'SDL_GameController', 'SDL_GameControllerButton' ], 'SDL_bool' ], | ||
| 128 | SDL_GameControllerGetButton => | ||
| 129 | [ [ 'SDL_GameController', 'SDL_GameControllerButton' ], 'uint8' ], | ||
| 130 | SDL_GameControllerGetNumTouchpads => [ ['SDL_GameController'], 'int' ], | ||
| 131 | SDL_GameControllerGetNumTouchpadFingers => [ [ 'SDL_GameController', 'int' ], 'int' ], | ||
| 132 | SDL_GameControllerGetTouchpadFinger => [ | ||
| 133 | [ 'SDL_GameController', 'int', 'int', 'uint8*', 'uint8*', 'uint8*', 'float*' ], 'int' | ||
| 134 | ], | ||
| 135 | SDL_GameControllerHasSensor => [ [ 'SDL_GameController', 'SDL_SensorType' ], 'SDL_bool' ], | ||
| 136 | SDL_GameControllerSetSensorEnabled => | ||
| 137 | [ [ 'SDL_GameController', 'SDL_SensorType', 'SDL_bool' ], 'int' ], | ||
| 138 | SDL_GameControllerIsSensorEnabled => | ||
| 139 | [ [ 'SDL_GameController', 'SDL_SensorType' ], 'SDL_bool' ], | ||
| 140 | SDL_GameControllerGetSensorData => | ||
| 141 | [ [ 'SDL_GameController', 'SDL_SensorType', 'float*', 'int' ], 'int' ], | ||
| 142 | SDL_GameControllerRumble => | ||
| 143 | [ [ 'SDL_GameController', 'uint16', 'uint16', 'uint16' ], 'int' ], | ||
| 144 | SDL_GameControllerRumbleTriggers => | ||
| 145 | [ [ 'SDL_GameController', 'uint16', 'uint16', 'uint32' ], 'int' ], | ||
| 146 | SDL_GameControllerHasLED => [ ['SDL_GameController'], 'SDL_bool' ], | ||
| 147 | SDL_GameControllerSetLED => [ [ 'SDL_GameController', 'uint8', 'uint8', 'uint8' ], 'int' ], | ||
| 148 | SDL_GameControllerClose => [ ['SDL_GameController'] ], | ||
| 149 | }; | ||
| 150 | define gamecontroller => [ | ||
| 151 | [ SDL_GameControllerAddMappingsFromFile => sub ($file) { | ||
| 152 | SDL2::FFI::SDL_GameControllerAddMappingsFromRW( | ||
| 153 | SDL2::FFI::SDL_RWFromFile( $file, 'rb' ), 1 ); | ||
| 154 | } | ||
| 155 | ] | ||
| 156 | ]; | ||
| 157 | |||
| 158 | =encoding utf-8 | ||
| 159 | |||
| 160 | =head1 NAME | ||
| 161 | |||
| 162 | SDL2::gamecontroller - SDL Game Controller Event Handling | ||
| 163 | |||
| 164 | =head1 SYNOPSIS | ||
| 165 | |||
| 166 | use SDL2 qw[:gamecontroller]; | ||
| 167 | |||
| 168 | =head1 DESCRIPTION | ||
| 169 | |||
| 170 | In order to use these functions, C<SDL_Init( ... )> must have been called with | ||
| 171 | the C<SDL_INIT_GAMECONTROLLER> flag. This causes SDL to scan the system for | ||
| 172 | game controllers, and load appropriate drivers. | ||
| 173 | |||
| 174 | If you would like to receive controller updates while the application is in the | ||
| 175 | background, you should set the following hint before calling C<SDL_Init( ... | ||
| 176 | )>: C<SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS>. | ||
| 177 | |||
| 178 | =head1 Functions | ||
| 179 | |||
| 180 | These may be imported by name or with the C<:gamecontroller> tag. | ||
| 181 | |||
| 182 | =head2 C<SDL_GameControllerAddMappingsFromRW( ... )> | ||
| 183 | |||
| 184 | Load a set of Game Controller mappings from a seekable SDL data stream. | ||
| 185 | |||
| 186 | You can call this function several times, if needed, to load different database | ||
| 187 | files. | ||
| 188 | |||
| 189 | If a new mapping is loaded for an already known controller GUID, the later | ||
| 190 | version will overwrite the one currently loaded. | ||
| 191 | |||
| 192 | Mappings not belonging to the current platform or with no platform field | ||
| 193 | specified will be ignored (i.e. mappings for Linux will be ignored in Windows, | ||
| 194 | etc). | ||
| 195 | |||
| 196 | This function will load the text database entirely in memory before processing | ||
| 197 | it, so take this into consideration if you are in a memory constrained | ||
| 198 | environment. | ||
| 199 | |||
| 200 | Expected parameters include: | ||
| 201 | |||
| 202 | =over | ||
| 203 | |||
| 204 | =item C<rw> - the data stream for the mappings to be added | ||
| 205 | |||
| 206 | =item C<freerw> - non-zero to close the stream after being read | ||
| 207 | |||
| 208 | =back | ||
| 209 | |||
| 210 | Returns the number of mappings added or C<-1> on error; call C<SDL_GetError( )> | ||
| 211 | for more information. | ||
| 212 | |||
| 213 | =head2 C<SDL_GameControllerAddMappingsFromRW( ... )> | ||
| 214 | |||
| 215 | Load a set of mappings from a file, filtered by the current C<SDL_GetPlatform( | ||
| 216 | )>. | ||
| 217 | |||
| 218 | SDL_GameControllerAddMappingsFromFile( 'gamecontrollerdb.txt' ); | ||
| 219 | |||
| 220 | Expected parameters include: | ||
| 221 | |||
| 222 | =over | ||
| 223 | |||
| 224 | =item C<file> - the name of the database you want to load | ||
| 225 | |||
| 226 | =back | ||
| 227 | |||
| 228 | Returns the number of mappings added or C<-1> on error; call C<SDL_GetError( )> | ||
| 229 | for more information. | ||
| 230 | |||
| 231 | =head2 C<SDL_GameControllerAddMapping( ... )> | ||
| 232 | |||
| 233 | Add support for controllers that SDL is unaware of or to cause an existing | ||
| 234 | controller to have a different binding. | ||
| 235 | |||
| 236 | The mapping string has the format "GUID,name,mapping", where GUID is the string | ||
| 237 | value from C<SDL_JoystickGetGUIDString( ... )>, name is the human readable | ||
| 238 | string for the device and mappings are controller mappings to joystick ones. | ||
| 239 | Under Windows there is a reserved GUID of "xinput" that covers all XInput | ||
| 240 | devices. The mapping format for joystick is: | ||
| 241 | |||
| 242 | {| |bX |a joystickbutton, index X |- |hX.Y |hat X with value Y |- |aX |axis X of the joystick|} | ||
| 243 | |||
| 244 | Buttons can be used as a controller axes and vice versa. | ||
| 245 | |||
| 246 | This string shows an example of a valid mapping for a controller: | ||
| 247 | |||
| 248 | 341a3608000000000000504944564944,Afterglow PS3 Controller,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b8,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7 | ||
| 249 | |||
| 250 | Expected parameters include: | ||
| 251 | |||
| 252 | =over | ||
| 253 | |||
| 254 | =item C<mappingString> - the mapping string | ||
| 255 | |||
| 256 | =back | ||
| 257 | |||
| 258 | Returns C<1> if a new mapping is added, C<0> if an existing mapping is updated, | ||
| 259 | C<-1> on error; call C<SDL_GetError( )> for more information. | ||
| 260 | |||
| 261 | =head2 C<SDL_GameControllerNumMappings( )> | ||
| 262 | |||
| 263 | Get the number of mappings installed. | ||
| 264 | |||
| 265 | Returns the number of mappings. | ||
| 266 | |||
| 267 | =head2 C<SDL_GameControllerMappingForIndex( ... )> | ||
| 268 | |||
| 269 | Get the mapping at a particular index. | ||
| 270 | |||
| 271 | Returns the mapping string. Must be freed with C<SDL_free( ... )>. Returns | ||
| 272 | C<undef> if the index is out of range. | ||
| 273 | |||
| 274 | =head2 C<SDL_GameControllerMappingForGUID( ... )> | ||
| 275 | |||
| 276 | Get the game controller mapping string for a given GUID. | ||
| 277 | |||
| 278 | The returned string must be freed with C<SDL_free( ... )>. | ||
| 279 | |||
| 280 | Expected parameters include: | ||
| 281 | |||
| 282 | =over | ||
| 283 | |||
| 284 | =item C<guid> - a structure containing the GUID for which a mapping is desired | ||
| 285 | |||
| 286 | =back | ||
| 287 | |||
| 288 | Returns a mapping string or NULL on error; call C<SDL_GetError( )> for more | ||
| 289 | information. | ||
| 290 | |||
| 291 | =head2 C<SDL_GameControllerMapping( ... )> | ||
| 292 | |||
| 293 | Get the current mapping of a Game Controller. | ||
| 294 | |||
| 295 | The returned string must be freed with C<SDL_free( ... )>. | ||
| 296 | |||
| 297 | Details about mappings are discussed with L<< C<SDL_GameControllerAddMapping( | ||
| 298 | ... )>|/C<SDL_GameControllerAddMapping( ... )> >>. | ||
| 299 | |||
| 300 | Expected parameters include: | ||
| 301 | |||
| 302 | =over | ||
| 303 | |||
| 304 | =item C<gamecontroller> - the game controller you want to get the current mapping for | ||
| 305 | |||
| 306 | =back | ||
| 307 | |||
| 308 | Returns a string that has the controller's mapping or C<undef> if no mapping is | ||
| 309 | available; call C<SDL_GetError( )> for more information. | ||
| 310 | |||
| 311 | =head2 C<SDL_IsGameController( ... )> | ||
| 312 | |||
| 313 | Check if the given joystick is supported by the game controller interface. | ||
| 314 | |||
| 315 | C<joystick_index> is the same as the C<device_index> passed to L<< | ||
| 316 | C<SDL_JoystickOpen( ... )>|SDL2::joystick/C<SDL_JoystickOpen( ... )> >>. | ||
| 317 | |||
| 318 | Expected parameters include: | ||
| 319 | |||
| 320 | =over | ||
| 321 | |||
| 322 | =item C<joystick_index> - the C<device_index> of a device, up to L<< C<SDL_NumJoysticks( )>|SDL2::joystick/C<SDL_NumJoysticks( )> >> | ||
| 323 | |||
| 324 | =back | ||
| 325 | |||
| 326 | Returns C<SDL_TRUE> if the given joystick is supported by the game controller | ||
| 327 | interface, C<SDL_FALSE> if it isn't or it's an invalid index. | ||
| 328 | |||
| 329 | =head2 C<SDL_GameControllerNameForIndex( ... )> | ||
| 330 | |||
| 331 | Get the implementation dependent name for the game controller. | ||
| 332 | |||
| 333 | This function can be called before any controllers are opened. | ||
| 334 | |||
| 335 | C<joystick_index> is the same as the C<device_index> passed to L<< | ||
| 336 | C<SDL_JoystickOpen( ... )>|SDL2::joystick/C<SDL_JoystickOpen( ... )> >>. | ||
| 337 | |||
| 338 | Expected parameters include: | ||
| 339 | |||
| 340 | =over | ||
| 341 | |||
| 342 | =item C<joystick_index> - the device_index of a device, from zero to C<SDL_NumJoysticks( ) - 1> | ||
| 343 | |||
| 344 | =back | ||
| 345 | |||
| 346 | Returns the implementation-dependent name for the game controller, or C<undef> | ||
| 347 | if there is no name or the index is invalid. | ||
| 348 | |||
| 349 | =head2 C<SDL_GameControllerTypeForIndex( ... )> | ||
| 350 | |||
| 351 | Get the type of a game controller. | ||
| 352 | |||
| 353 | This can be called before any controllers are opened. | ||
| 354 | |||
| 355 | Expected parameters include: | ||
| 356 | |||
| 357 | =over | ||
| 358 | |||
| 359 | =item C<joystick_index> - the device_index of a device, from zero to C<SDL_NumJoysticks( ) - 1> | ||
| 360 | |||
| 361 | =back | ||
| 362 | |||
| 363 | Returns the controller type. | ||
| 364 | |||
| 365 | =head2 C<SDL_GameControllerMappingForDeviceIndex( ... )> | ||
| 366 | |||
| 367 | Get the mapping of a game controller. | ||
| 368 | |||
| 369 | This can be called before any controllers are opened. | ||
| 370 | |||
| 371 | Expected parameters include: | ||
| 372 | |||
| 373 | =over | ||
| 374 | |||
| 375 | =item C<joystick_index> - the device_index of a device, from zero to C<SDL_NumJoysticks( ) - 1> | ||
| 376 | |||
| 377 | =back | ||
| 378 | |||
| 379 | Returns the mapping string. Must be freed with C<SDL_free( ... )>. Returns | ||
| 380 | C<undef> if no mapping is available. | ||
| 381 | |||
| 382 | =head2 C<SDL_GameControllerOpen( ... )> | ||
| 383 | |||
| 384 | Open a game controller for use. | ||
| 385 | |||
| 386 | C<joystick_index> is the same as the C<device_index> passed to L<< | ||
| 387 | C<SDL_JoystickOpen( ... )>|SDL2::joystick/C<SDL_JoystickOpen( ... )> >>. | ||
| 388 | |||
| 389 | The index passed as an argument refers to the N'th game controller on the | ||
| 390 | system. This index is not the value which will identify this controller in | ||
| 391 | future controller events. The joystick's instance id (C<SDL_JoystickID>) will | ||
| 392 | be used there instead. | ||
| 393 | |||
| 394 | Expected parameters include; | ||
| 395 | |||
| 396 | =over | ||
| 397 | |||
| 398 | =item C<joystick_index> - the device_index of a device, up to L<< C<SDL_NumJoysticks( )>|SDL2::joystick/C<SDL_NumJoysticks( )> >> | ||
| 399 | |||
| 400 | =back | ||
| 401 | |||
| 402 | Returns a gamecontroller identifier or C<undef> if an error occurred; call | ||
| 403 | C<SDL_GetError( )> for more information. | ||
| 404 | |||
| 405 | =head2 C<SDL_GameControllerFromInstanceID( ... )> | ||
| 406 | |||
| 407 | Get the SDL_GameController associated with an instance id. | ||
| 408 | |||
| 409 | Expected parameters include: | ||
| 410 | |||
| 411 | =over | ||
| 412 | |||
| 413 | =item C<joyid> - the instance id to get the C<SDL2::GameController> for | ||
| 414 | |||
| 415 | =back | ||
| 416 | |||
| 417 | Returns an L<SDL2::GameController> on success or C<undef> on failure; call | ||
| 418 | C<SDL_GetError( )> for more information. | ||
| 419 | |||
| 420 | =head2 C<SDL_GameControllerFromPlayerIndex( ... )> | ||
| 421 | |||
| 422 | Get the L<SDL2::GameController> associated with a player index. | ||
| 423 | |||
| 424 | Please note that the player index is _not_ the device index, nor is it the | ||
| 425 | instance id! | ||
| 426 | |||
| 427 | Expected parameters include: | ||
| 428 | |||
| 429 | =over | ||
| 430 | |||
| 431 | =item C<player_index> - the player index (which is not the device index or the instance id) | ||
| 432 | |||
| 433 | =back | ||
| 434 | |||
| 435 | Returns the L<SDL2::GameController> associated with a player index. | ||
| 436 | |||
| 437 | =head2 C<SDL_GameControllerName( ... )> | ||
| 438 | |||
| 439 | Get the implementation-dependent name for an opened game controller. | ||
| 440 | |||
| 441 | This is the same name as returned by SDL_GameControllerNameForIndex(), but it | ||
| 442 | takes a controller identifier instead of the (unstable) device index. | ||
| 443 | |||
| 444 | Expected parameters include: | ||
| 445 | |||
| 446 | =over | ||
| 447 | |||
| 448 | =item C<gamecontroller> a game controller identifier previously returned by L<< C<SDL_GameControllerOpen( ... )>|/C<SDL_GameControllerOpen( ... )> >> | ||
| 449 | |||
| 450 | =back | ||
| 451 | |||
| 452 | Returns the implementation dependent name for the game controller, or C<undef> | ||
| 453 | if there is no name or the identifier passed is invalid. | ||
| 454 | |||
| 455 | =head2 C<SDL_GameControllerGetType( ... )> | ||
| 456 | |||
| 457 | Get the type of this currently opened controller | ||
| 458 | |||
| 459 | This is the same name as returned by L<< C<SDL_GameControllerTypeForIndex( ... | ||
| 460 | )>|/C<SDL_GameControllerTypeForIndex( ... )> >>, but it takes a controller | ||
| 461 | identifier instead of the (unstable) device index. | ||
| 462 | |||
| 463 | Expected parameters include: | ||
| 464 | |||
| 465 | =over | ||
| 466 | |||
| 467 | =item C<gamecontroller> - the game controller object to query | ||
| 468 | |||
| 469 | =back | ||
| 470 | |||
| 471 | Returns the controller type. | ||
| 472 | |||
| 473 | =head2 C<SDL_GameControllerGetPlayerIndex( ... )> | ||
| 474 | |||
| 475 | Get the player index of an opened game controller. | ||
| 476 | |||
| 477 | For XInput controllers this returns the XInput user index. | ||
| 478 | |||
| 479 | Expected parameters include: | ||
| 480 | |||
| 481 | =over | ||
| 482 | |||
| 483 | =item C<gamecontroller> - the game controller object to query | ||
| 484 | |||
| 485 | =back | ||
| 486 | |||
| 487 | Returns player index for controller, or C<-1> if it's not available. | ||
| 488 | |||
| 489 | =head2 C<SDL_GameControllerSetPlayerIndex( ... )> | ||
| 490 | |||
| 491 | Set the player index of an opened game controller. | ||
| 492 | |||
| 493 | Expected parameters include: | ||
| 494 | |||
| 495 | =over | ||
| 496 | |||
| 497 | =item C<gamecontroller> - the game controller object to adjust | ||
| 498 | |||
| 499 | =item C<player_index> - player index to assign to this controller | ||
| 500 | |||
| 501 | =back | ||
| 502 | |||
| 503 | =head2 C<SDL_GameControllerGetVendor( ... )> | ||
| 504 | |||
| 505 | Get the USB vendor ID of an opened controller, if available. | ||
| 506 | |||
| 507 | If the vendor ID isn't available this function returns 0. | ||
| 508 | |||
| 509 | Expected parameters include: | ||
| 510 | |||
| 511 | =over | ||
| 512 | |||
| 513 | =item C<gamecontroller> - the game controller object to query | ||
| 514 | |||
| 515 | =back | ||
| 516 | |||
| 517 | Return USB vendor ID, or zero if unavailable. | ||
| 518 | |||
| 519 | =head2 C<SDL_GameControllerGetProduct( ... )> | ||
| 520 | |||
| 521 | Get the USB product ID of an opened controller, if available. | ||
| 522 | |||
| 523 | If the product ID isn't available this function returns 0. | ||
| 524 | |||
| 525 | Expected parameters include: | ||
| 526 | |||
| 527 | =over | ||
| 528 | |||
| 529 | =item C<gamecontroller> - the game controller object to query | ||
| 530 | |||
| 531 | =back | ||
| 532 | |||
| 533 | Return USB product ID, or zero if unavailable. | ||
| 534 | |||
| 535 | =head2 C<SDL_GameControllerGetProductVersion( ... )> | ||
| 536 | |||
| 537 | Get the product version of an opened controller, if available. | ||
| 538 | |||
| 539 | If the product version isn't available this function returns 0. | ||
| 540 | |||
| 541 | Expected parameters include: | ||
| 542 | |||
| 543 | =over | ||
| 544 | |||
| 545 | =item C<gamecontroller> - the game controller object to query | ||
| 546 | |||
| 547 | =back | ||
| 548 | |||
| 549 | Return USB product version, or zero if unavailable. | ||
| 550 | |||
| 551 | =head2 C<SDL_GameControllerGetSerial( ... )> | ||
| 552 | |||
| 553 | Get the serial number of an opened controller, if available. | ||
| 554 | |||
| 555 | Returns the serial number of the controller, or C<undef> if it is not | ||
| 556 | available. | ||
| 557 | |||
| 558 | Expected parameters include: | ||
| 559 | |||
| 560 | =over | ||
| 561 | |||
| 562 | =item C<gamecontroller> - the game controller object to query | ||
| 563 | |||
| 564 | =back | ||
| 565 | |||
| 566 | Returns a serial number, or C<undef> if unavailable. | ||
| 567 | |||
| 568 | =head2 C<SDL_GameControllerGetAttached( ... )> | ||
| 569 | |||
| 570 | Check if a controller has been opened and is currently connected. | ||
| 571 | |||
| 572 | Expected parameters include: | ||
| 573 | |||
| 574 | =over | ||
| 575 | |||
| 576 | =item C<gamecontroller> - a game controller identifier previously returned by L<< C<SDL_GameControllerOpen( ... )>|/C<SDL_GameControllerOpen( ... )> >> | ||
| 577 | |||
| 578 | =back | ||
| 579 | |||
| 580 | Returns C<SDL_TRUE> if the controller has been opened and is currently | ||
| 581 | connected, or C<SDL_FALSE> if not. | ||
| 582 | |||
| 583 | |||
| 584 | |||
| 585 | =head2 C<SDL_GameControllerGetJoystick( ... )> | ||
| 586 | |||
| 587 | Get the Joystick ID from a Game Controller. | ||
| 588 | |||
| 589 | This function will give you a L<SDL2::Joystick> object, which allows you to use | ||
| 590 | the L<SDL2::Joystick> functions with a L<SDL2::GameController> object. This | ||
| 591 | would be useful for getting a joystick's position at any given time, even if it | ||
| 592 | hasn't moved (moving it would produce an event, which would have the axis' | ||
| 593 | value). | ||
| 594 | |||
| 595 | The pointer returned is owned by the L<SDL2::GameController>. You should not | ||
| 596 | call L<< C<SDL_JoystickClose( ... )>|SDL2::joystick/C<SDL_JoystickClose( ... )> | ||
| 597 | >> on it, for example, since doing so will likely cause SDL to crash. | ||
| 598 | |||
| 599 | Expected parameters include: | ||
| 600 | |||
| 601 | =over | ||
| 602 | |||
| 603 | =item C<gamecontroller> - the game controller object that you want to get a joystick from | ||
| 604 | |||
| 605 | =back | ||
| 606 | |||
| 607 | Returns a L<SDL2::Joystick> object; call C<SDL_GetError( )> for more | ||
| 608 | information. | ||
| 609 | |||
| 610 | =head2 C<SDL_GameControllerEventState( ... )> | ||
| 611 | |||
| 612 | Query or change current state of Game Controller events. | ||
| 613 | |||
| 614 | If controller events are disabled, you must call L<< | ||
| 615 | C<SDL_GameControllerUpdate( )>|/C<SDL_GameControllerUpdate( )> >> yourself and | ||
| 616 | check the state of the controller when you want controller information. | ||
| 617 | |||
| 618 | Any number can be passed to C<SDL_GameControllerEventState( ... )>, but only | ||
| 619 | C<-1>, C<0>, and C<1> will have any effect. Other numbers will just be | ||
| 620 | returned. | ||
| 621 | |||
| 622 | =over | ||
| 623 | |||
| 624 | =item C<state> - can be one of C<SDL_QUERY>, C<SDL_IGNORE>, or C<SDL_ENABLE> | ||
| 625 | |||
| 626 | =back | ||
| 627 | |||
| 628 | Returns the same value passed to the function, with exception to C<-1> | ||
| 629 | (C<SDL_QUERY>), which will return the current state. | ||
| 630 | |||
| 631 | =head2 C<SDL_GameControllerUpdate( )> | ||
| 632 | |||
| 633 | Manually pump game controller updates if not using the loop. | ||
| 634 | |||
| 635 | This function is called automatically by the event loop if events are enabled. | ||
| 636 | Under such circumstances, it will not be necessary to call this function. | ||
| 637 | |||
| 638 | =head2 C<SDL_GameControllerGetAxisFromString( ... )> | ||
| 639 | |||
| 640 | Convert a string into L<< C<SDL_GameControllerAxis>|/C<SDL_GameControllerAxis> | ||
| 641 | >> enum. | ||
| 642 | |||
| 643 | This function is called internally to translate L<SDL2::GameController> mapping | ||
| 644 | strings for the underlying joystick device into the consistent | ||
| 645 | L<SDL2::GameController> mapping. You do not normally need to call this function | ||
| 646 | unless you are parsing L<SDL2::GameController> mappings in your own code. | ||
| 647 | |||
| 648 | Expected parameters include: | ||
| 649 | |||
| 650 | =over | ||
| 651 | |||
| 652 | =item C<str> - string representing a L<SDL2::GameController> axis | ||
| 653 | |||
| 654 | =back | ||
| 655 | |||
| 656 | Returns the L<< C<SDL_GameControllerAxis>|/C<SDL_GameControllerAxis> >> enum | ||
| 657 | corresponding to the input string, or C<SDL_CONTROLLER_AXIS_INVALID> if no | ||
| 658 | match was found. | ||
| 659 | |||
| 660 | =head2 C<SDL_GameControllerGetStringForAxis( ... )> | ||
| 661 | |||
| 662 | Convert from an SDL_GameControllerAxis enum to a string. | ||
| 663 | |||
| 664 | The caller should not C<SDL_free( ... )> the returned string. | ||
| 665 | |||
| 666 | Expected parameters include: | ||
| 667 | |||
| 668 | =over | ||
| 669 | |||
| 670 | =item C<axis> - an enum value for a given L<< C<SDL_GameControllerAxis>|/C<SDL_GameControllerAxis> >> | ||
| 671 | |||
| 672 | =back | ||
| 673 | |||
| 674 | Returns a string for the given axis, or C<undef> if an invalid axis is | ||
| 675 | specified. The string returned is of the format used by L<SDL2::GameController> | ||
| 676 | mapping strings. | ||
| 677 | |||
| 678 | =head2 C<SDL_GameControllerGetBindForAxis( ... )> | ||
| 679 | |||
| 680 | Get the SDL joystick layer binding for a controller axis mapping. | ||
| 681 | |||
| 682 | Expected parameters include: | ||
| 683 | |||
| 684 | =over | ||
| 685 | |||
| 686 | =item C<gamecontroller> - a game controller | ||
| 687 | |||
| 688 | =item C<axis> - an axis enum value (one of the L<< C<SDL_GameControllerAxis>|/C<SDL_GameControllerAxis> >> values) | ||
| 689 | |||
| 690 | =back | ||
| 691 | |||
| 692 | Returns a L<SDL2::GameControllerButtonBind> describing the bind. On failure | ||
| 693 | (like the given Controller axis doesn't exist on the device), its C<bindType> | ||
| 694 | will be C<SDL_CONTROLLER_BINDTYPE_NONE>. | ||
| 695 | |||
| 696 | =head2 C<SDL_GameControllerHasAxis( ... )> | ||
| 697 | |||
| 698 | Query whether a game controller has a given axis. | ||
| 699 | |||
| 700 | This merely reports whether the controller's mapping defined this axis, as that | ||
| 701 | is all the information SDL has about the physical device. | ||
| 702 | |||
| 703 | Expected parameters include: | ||
| 704 | |||
| 705 | =over | ||
| 706 | |||
| 707 | =item C<gamecontroller> - a game controller | ||
| 708 | |||
| 709 | =item C<axis> - an axis enum value (an L<< C<SDL_GameControllerAxis>|/C<SDL_GameControllerAxis> >> value) | ||
| 710 | |||
| 711 | =back | ||
| 712 | |||
| 713 | Returns C<SDL_TRUE> if the controller has this axis, C<SDL_FALSE> otherwise. | ||
| 714 | |||
| 715 | =head2 C<SDL_GameControllerGetAxis( ... )> | ||
| 716 | |||
| 717 | Get the current state of an axis control on a game controller. | ||
| 718 | |||
| 719 | The axis indices start at index C<0>. | ||
| 720 | |||
| 721 | The state is a value ranging from C<-32768> to C<32767>. Triggers, however, | ||
| 722 | range from C<0> to C<32767> (they never return a negative value). | ||
| 723 | |||
| 724 | Expected parameters include: | ||
| 725 | |||
| 726 | =over | ||
| 727 | |||
| 728 | =item C<gamecontroller> - a game controller | ||
| 729 | |||
| 730 | =item C<axis> - an axis index (one of the L<< C<SDL_GameControllerAxis>|/C<SDL_GameControllerAxis> >> values) | ||
| 731 | |||
| 732 | =back | ||
| 733 | |||
| 734 | Returns axis state (including C<0>) on success or C<0> (also) on failure; call | ||
| 735 | C<SDL_GetError( )> for more information. | ||
| 736 | |||
| 737 | =head2 C<SDL_GameControllerGetButtonFromString( ... )> | ||
| 738 | |||
| 739 | Convert a string into an C<SDL_GameControllerButton> enum. | ||
| 740 | |||
| 741 | This function is called internally to translate L<SDL2::GameController> mapping | ||
| 742 | strings for the underlying joystick device into the consistent | ||
| 743 | L<SDL2::GameController> mapping. You do not normally need to call this function | ||
| 744 | unless you are parsing L<SDL2::GameController> mappings in your own code. | ||
| 745 | |||
| 746 | Expected parameters include: | ||
| 747 | |||
| 748 | =over | ||
| 749 | |||
| 750 | =item C<str> - string representing a L<SDL2::GameController> axis | ||
| 751 | |||
| 752 | =back | ||
| 753 | |||
| 754 | Returns the C<SDL_GameControllerButton> enum corresponding to the input string, | ||
| 755 | or C<SDL_CONTROLLER_AXIS_INVALID> if no match was found. | ||
| 756 | |||
| 757 | =head2 C<SDL_GameControllerGetStringForButton( ... )> | ||
| 758 | |||
| 759 | Convert from an C<SDL_GameControllerButton> enum to a string. | ||
| 760 | |||
| 761 | The caller should not C<SDL_free( )> the returned string. | ||
| 762 | |||
| 763 | Expected parameters include: | ||
| 764 | |||
| 765 | =over | ||
| 766 | |||
| 767 | =item C<button> - an enum value for a given L<SDL2::GameControllerButton> | ||
| 768 | |||
| 769 | =back | ||
| 770 | |||
| 771 | Returns a string for the given button, or C<undef> if an invalid axis is | ||
| 772 | specified. The string returned is of the format used by L<SDL2::GameController> | ||
| 773 | mapping strings. | ||
| 774 | |||
| 775 | =head2 C<SDL_GameControllerGetBindForButton( ... )> | ||
| 776 | |||
| 777 | Get the SDL joystick layer binding for a controller button mapping. | ||
| 778 | |||
| 779 | Expected parameters includes: | ||
| 780 | |||
| 781 | =over | ||
| 782 | |||
| 783 | =item C<gamecontroller> - a game controller | ||
| 784 | |||
| 785 | =item C<button> - an button enum value (an C<SDL_GameControllerButton> value) | ||
| 786 | |||
| 787 | =back | ||
| 788 | |||
| 789 | Returns a C<SDL_GameControllerButtonBind> describing the bind. On failure (like | ||
| 790 | the given Controller button doesn't exist on the device), its C<bindType> will | ||
| 791 | be C<SDL_CONTROLLER_BINDTYPE_NONE>. | ||
| 792 | |||
| 793 | =head2 C<SDL_GameControllerHasButton( ... )> | ||
| 794 | |||
| 795 | Query whether a game controller has a given button. | ||
| 796 | |||
| 797 | This merely reports whether the controller's mapping defined this button, as | ||
| 798 | that is all the information SDL has about the physical device. | ||
| 799 | |||
| 800 | Expected parameters include: | ||
| 801 | |||
| 802 | =over | ||
| 803 | |||
| 804 | =item C<gamecontroller> - a game controller | ||
| 805 | |||
| 806 | =item C<button> - a button enum value (an C<SDL_GameControllerButton> value) | ||
| 807 | |||
| 808 | =back | ||
| 809 | |||
| 810 | Returns C<SDL_TRUE> if the controller has this button, C<SDL_FALSE> otherwise. | ||
| 811 | |||
| 812 | =head2 C<SDL_GameControllerGetButton( ... )> | ||
| 813 | |||
| 814 | Get the current state of a button on a game controller. | ||
| 815 | |||
| 816 | Expected parameters include: | ||
| 817 | |||
| 818 | =over | ||
| 819 | |||
| 820 | =item C<gamecontroller> - a game controller | ||
| 821 | |||
| 822 | =item C<button> - a button index (one of the SDL_GameControllerButton values) | ||
| 823 | |||
| 824 | =back | ||
| 825 | |||
| 826 | Returns C<1> for pressed state or C<0> for not pressed state or error; call | ||
| 827 | C<SDL_GetError( )> for more information. | ||
| 828 | |||
| 829 | =head2 C<SDL_GameControllerGetNumTouchpads( ... )> | ||
| 830 | |||
| 831 | Get the number of touchpads on a game controller. | ||
| 832 | |||
| 833 | Expected parameters include: | ||
| 834 | |||
| 835 | =over | ||
| 836 | |||
| 837 | =item C<gamecontroller> - a game controller | ||
| 838 | |||
| 839 | =back | ||
| 840 | |||
| 841 | Returns the number of touchpads. | ||
| 842 | |||
| 843 | |||
| 844 | =head2 C<SDL_GameControllerGetNumTouchpadFingers( ... )> | ||
| 845 | |||
| 846 | Get the number of supported simultaneous fingers on a touchpad on a game | ||
| 847 | controller. | ||
| 848 | |||
| 849 | Expected parameters include: | ||
| 850 | |||
| 851 | =over | ||
| 852 | |||
| 853 | =item C<gamecontroller> - a game controller | ||
| 854 | |||
| 855 | =item C<touchpad> - index of the touchpad to query | ||
| 856 | |||
| 857 | =back | ||
| 858 | |||
| 859 | Returns the number of supported simultaneous fingers. | ||
| 860 | |||
| 861 | =head2 C<SDL_GameControllerGetTouchpadFinger( ... )> | ||
| 862 | |||
| 863 | Get the current state of a finger on a touchpad on a game controller. | ||
| 864 | |||
| 865 | Expected parameters include: | ||
| 866 | |||
| 867 | =over | ||
| 868 | |||
| 869 | =item C<gamecontroller> - a game controller | ||
| 870 | |||
| 871 | =item C<touchpad> - touchpad index to query | ||
| 872 | |||
| 873 | =item C<finger> - finger index to query | ||
| 874 | |||
| 875 | =item C<state> - pointer | ||
| 876 | |||
| 877 | =item C<x> - pointer | ||
| 878 | |||
| 879 | =item C<y> - pointer | ||
| 880 | |||
| 881 | =item C<pressure> - pointer | ||
| 882 | |||
| 883 | =back | ||
| 884 | |||
| 885 | Returns C<0> if the given finger is defined on the given touchpad on the given | ||
| 886 | controller, C<-1> otherwise. | ||
| 887 | |||
| 888 | =head2 C<SDL_GameControllerHasSensor( ... )> | ||
| 889 | |||
| 890 | Return whether a game controller has a particular sensor. | ||
| 891 | |||
| 892 | Expected parameters include: | ||
| 893 | |||
| 894 | =over | ||
| 895 | |||
| 896 | =item C<gamecontroller> - the controller to query | ||
| 897 | |||
| 898 | =item C<type> - the type of sensor to query | ||
| 899 | |||
| 900 | =back | ||
| 901 | |||
| 902 | Returns C<SDL_TRUE> if the sensor exists, C<SDL_FALSE> otherwise. | ||
| 903 | |||
| 904 | =head2 C<SDL_GameControllerSetSensorEnabled( ... )> | ||
| 905 | |||
| 906 | Set whether data reporting for a game controller sensor is enabled. | ||
| 907 | |||
| 908 | Expected parameters include: | ||
| 909 | |||
| 910 | =over | ||
| 911 | |||
| 912 | =item C<gamecontroller> - the controller to update | ||
| 913 | |||
| 914 | =item C<type> - the type of sensor to enable/disable | ||
| 915 | |||
| 916 | =item C<enabled> - whether data reporting should be enabled | ||
| 917 | |||
| 918 | =back | ||
| 919 | |||
| 920 | Returns C<0> or C<-1> if an error occurred. | ||
| 921 | |||
| 922 | =head2 C<SDL_GameControllerIsSensorEnabled( ... )> | ||
| 923 | |||
| 924 | Query whether sensor data reporting is enabled for a game controller. | ||
| 925 | |||
| 926 | Expected parameters include: | ||
| 927 | |||
| 928 | =over | ||
| 929 | |||
| 930 | =item C<gamecontroller> - the controller to query | ||
| 931 | |||
| 932 | =item C<type> - the type of sensor to query | ||
| 933 | |||
| 934 | =back | ||
| 935 | |||
| 936 | Returns C<SDL_TRUE> if the sensor is enabled, C<SDL_FALSE> otherwise. | ||
| 937 | |||
| 938 | =head2 C<SDL_GameControllerGetSensorData( ... )> | ||
| 939 | |||
| 940 | Get the current state of a game controller sensor. | ||
| 941 | |||
| 942 | The number of values and interpretation of the data is sensor dependent. See | ||
| 943 | C<SDL_sensor.h> for the details for each type of sensor. | ||
| 944 | |||
| 945 | Expected parameters include; | ||
| 946 | |||
| 947 | =over | ||
| 948 | |||
| 949 | =item C<gamecontroller> - the controller to query | ||
| 950 | |||
| 951 | =item C<type> - the type of sensor to query | ||
| 952 | |||
| 953 | =item C<data> - a pointer filled with the current sensor state | ||
| 954 | |||
| 955 | =item C<num_values> - the number of values to write to data | ||
| 956 | |||
| 957 | =back | ||
| 958 | |||
| 959 | Return C<0> or C<-1> if an error occurred. | ||
| 960 | |||
| 961 | =head2 C<SDL_GameControllerRumble( ... )> | ||
| 962 | |||
| 963 | Start a rumble effect on a game controller. | ||
| 964 | |||
| 965 | Each call to this function cancels any previous rumble effect, and calling it | ||
| 966 | with 0 intensity stops any rumbling. | ||
| 967 | |||
| 968 | Expected parameters include: | ||
| 969 | |||
| 970 | =over | ||
| 971 | |||
| 972 | =item C<gamecontroller> - the controller to vibrate | ||
| 973 | |||
| 974 | =item C<low_frequency_rumble> - the intensity of the low frequency (left) rumble motor, from C<0> to C<0xFFFF> | ||
| 975 | |||
| 976 | =item C<high_frequency_rumble> - the intensity of the high frequency (right) rumble motor, from C<0> to C<0xFFFF> | ||
| 977 | |||
| 978 | =item C<duration_ms> - the duration of the rumble effect, in milliseconds | ||
| 979 | |||
| 980 | =back | ||
| 981 | |||
| 982 | Returns C<0>, or C<-1> if rumble isn't supported on this controller | ||
| 983 | |||
| 984 | =head2 C<SDL_GameControllerRumbleTriggers( ... )> | ||
| 985 | |||
| 986 | Start a rumble effect in the game controller's triggers. | ||
| 987 | |||
| 988 | Each call to this function cancels any previous trigger rumble effect, and | ||
| 989 | calling it with 0 intensity stops any rumbling. | ||
| 990 | |||
| 991 | Note that this is rumbling of the _triggers_ and not the game controller as a | ||
| 992 | whole. The first controller to offer this feature was the PlayStation 5's | ||
| 993 | DualShock 5. | ||
| 994 | |||
| 995 | Expected parameters include: | ||
| 996 | |||
| 997 | =over | ||
| 998 | |||
| 999 | =item C<gamecontroller> - the controller to vibrate | ||
| 1000 | |||
| 1001 | =item C<left_rumble> - the intensity of the left trigger rumble motor, from C<0> to C<0xFFFF> | ||
| 1002 | |||
| 1003 | =item C<right_rumble> - the intensity of the right trigger rumble motor, from C<0> to C<0xFFFF> | ||
| 1004 | |||
| 1005 | =item C<duration_ms> - the duration of the rumble effect, in milliseconds | ||
| 1006 | |||
| 1007 | =back | ||
| 1008 | |||
| 1009 | Returns C<0>, or C<-1> if trigger rumble isn't supported on this controller. | ||
| 1010 | |||
| 1011 | =head2 C<SDL_GameControllerHasLED( ... )> | ||
| 1012 | |||
| 1013 | Query whether a game controller has an LED. | ||
| 1014 | |||
| 1015 | Expected parameters include: | ||
| 1016 | |||
| 1017 | =over | ||
| 1018 | |||
| 1019 | =item C<gamecontroller> - the controller to query | ||
| 1020 | |||
| 1021 | =back | ||
| 1022 | |||
| 1023 | Returns C<SDL_TRUE>, or C<SDL_FALSE> if this controller does not have a | ||
| 1024 | modifiable LED. | ||
| 1025 | |||
| 1026 | =head2 C<SDL_GameControllerSetLED( ... )> | ||
| 1027 | |||
| 1028 | Update a game controller's LED color. | ||
| 1029 | |||
| 1030 | Expected parameters include: | ||
| 1031 | |||
| 1032 | =over | ||
| 1033 | |||
| 1034 | =item C<gamecontroller> - the controller to update | ||
| 1035 | |||
| 1036 | =item C<red> - the intensity of the red LED | ||
| 1037 | |||
| 1038 | =item C<green> - the intensity of the green LED | ||
| 1039 | |||
| 1040 | =item C<blue> - the intensity of the blue LED | ||
| 1041 | |||
| 1042 | =back | ||
| 1043 | |||
| 1044 | Returns C<0>, or C<-1> if this controller does not have a modifiable LED | ||
| 1045 | |||
| 1046 | =head2 C<SDL_GameControllerClose( ... )> | ||
| 1047 | |||
| 1048 | Close a game controller previously opened with L<< C<SDL_GameControllerOpen( | ||
| 1049 | ... )>|/C<SDL_GameControllerOpen( ... )> >>. | ||
| 1050 | |||
| 1051 | Expected parameters include: | ||
| 1052 | |||
| 1053 | =over | ||
| 1054 | |||
| 1055 | =item C<gamecontroller> - a game controller identifier previously returned by L<< C<SDL_GameControllerOpen( ... )>|/C<SDL_GameControllerOpen( ... )> >> | ||
| 1056 | |||
| 1057 | =back | ||
| 1058 | |||
| 1059 | =head1 Defined Values and Enumerations | ||
| 1060 | |||
| 1061 | These may be imported by name or with the given tag. | ||
| 1062 | |||
| 1063 | =head2 C<SDL_GameControllerType> | ||
| 1064 | |||
| 1065 | =over | ||
| 1066 | |||
| 1067 | =item C<SDL_CONTROLLER_TYPE_UNKNOWN> | ||
| 1068 | |||
| 1069 | =item C<SDL_CONTROLLER_TYPE_XBOX360> | ||
| 1070 | |||
| 1071 | =item C<SDL_CONTROLLER_TYPE_XBOXONE> | ||
| 1072 | |||
| 1073 | =item C<SDL_CONTROLLER_TYPE_PS3> | ||
| 1074 | |||
| 1075 | =item C<SDL_CONTROLLER_TYPE_PS4> | ||
| 1076 | |||
| 1077 | =item C<SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO> | ||
| 1078 | |||
| 1079 | =item C<SDL_CONTROLLER_TYPE_VIRTUAL> | ||
| 1080 | |||
| 1081 | =item C<SDL_CONTROLLER_TYPE_PS5> | ||
| 1082 | |||
| 1083 | =back | ||
| 1084 | |||
| 1085 | =head2 C<SDL_GameControllerBindType> | ||
| 1086 | |||
| 1087 | =over | ||
| 1088 | |||
| 1089 | =item C<SDL_CONTROLLER_BINDTYPE_NONE> | ||
| 1090 | |||
| 1091 | =item C<SDL_CONTROLLER_BINDTYPE_BUTTON> | ||
| 1092 | |||
| 1093 | =item C<SDL_CONTROLLER_BINDTYPE_AXIS> | ||
| 1094 | |||
| 1095 | =item C<SDL_CONTROLLER_BINDTYPE_HAT> | ||
| 1096 | |||
| 1097 | =back | ||
| 1098 | |||
| 1099 | =head2 C<SDL_GameControllerAxis> | ||
| 1100 | |||
| 1101 | The list of axes available from a controller | ||
| 1102 | |||
| 1103 | Thumbstick axis values range from C<SDL_JOYSTICK_AXIS_MIN> to | ||
| 1104 | C<SDL_JOYSTICK_AXIS_MAX>, and are centered within ~8000 of zero, though | ||
| 1105 | advanced UI will allow users to set or autodetect the dead zone, which varies | ||
| 1106 | between controllers. | ||
| 1107 | |||
| 1108 | Trigger axis values range from C<0> to C<SDL_JOYSTICK_AXIS_MAX>. | ||
| 1109 | |||
| 1110 | =over | ||
| 1111 | |||
| 1112 | =item C<SDL_CONTROLLER_AXIS_INVALID> | ||
| 1113 | |||
| 1114 | =item C<SDL_CONTROLLER_AXIS_LEFTX> | ||
| 1115 | |||
| 1116 | =item C<SDL_CONTROLLER_AXIS_LEFTY> | ||
| 1117 | |||
| 1118 | =item C<SDL_CONTROLLER_AXIS_RIGHTX> | ||
| 1119 | |||
| 1120 | =item C<SDL_CONTROLLER_AXIS_RIGHTY> | ||
| 1121 | |||
| 1122 | =item C<SDL_CONTROLLER_AXIS_TRIGGERLEFT> | ||
| 1123 | |||
| 1124 | =item C<SDL_CONTROLLER_AXIS_TRIGGERRIGHT> | ||
| 1125 | |||
| 1126 | =item C<SDL_CONTROLLER_AXIS_MAX> | ||
| 1127 | |||
| 1128 | =back | ||
| 1129 | |||
| 1130 | =head2 C<SDL_GameControllerButton> | ||
| 1131 | |||
| 1132 | The list of buttons available from a controller. | ||
| 1133 | |||
| 1134 | =over | ||
| 1135 | |||
| 1136 | =item C<SDL_CONTROLLER_BUTTON_INVALID> | ||
| 1137 | |||
| 1138 | =item C<SDL_CONTROLLER_BUTTON_A> | ||
| 1139 | |||
| 1140 | =item C<SDL_CONTROLLER_BUTTON_B> | ||
| 1141 | |||
| 1142 | =item C<SDL_CONTROLLER_BUTTON_X> | ||
| 1143 | |||
| 1144 | =item C<SDL_CONTROLLER_BUTTON_Y> | ||
| 1145 | |||
| 1146 | =item C<SDL_CONTROLLER_BUTTON_BACK> | ||
| 1147 | |||
| 1148 | =item C<SDL_CONTROLLER_BUTTON_GUIDE> | ||
| 1149 | |||
| 1150 | =item C<SDL_CONTROLLER_BUTTON_START> | ||
| 1151 | |||
| 1152 | =item C<SDL_CONTROLLER_BUTTON_LEFTSTICK> | ||
| 1153 | |||
| 1154 | =item C<SDL_CONTROLLER_BUTTON_RIGHTSTICK> | ||
| 1155 | |||
| 1156 | =item C<SDL_CONTROLLER_BUTTON_LEFTSHOULDER> | ||
| 1157 | |||
| 1158 | =item C<SDL_CONTROLLER_BUTTON_RIGHTSHOULDER> | ||
| 1159 | |||
| 1160 | =item C<SDL_CONTROLLER_BUTTON_DPAD_UP> | ||
| 1161 | |||
| 1162 | =item C<SDL_CONTROLLER_BUTTON_DPAD_DOWN> | ||
| 1163 | |||
| 1164 | =item C<SDL_CONTROLLER_BUTTON_DPAD_LEFT> | ||
| 1165 | |||
| 1166 | =item C<SDL_CONTROLLER_BUTTON_DPAD_RIGHT> | ||
| 1167 | |||
| 1168 | =item C<SDL_CONTROLLER_BUTTON_MISC1> - Xbox Series X share button, PS5 microphone button, Nintendo Switch Pro capture button | ||
| 1169 | |||
| 1170 | =item C<SDL_CONTROLLER_BUTTON_PADDLE1> - Xbox Elite paddle P1 | ||
| 1171 | |||
| 1172 | =item C<SDL_CONTROLLER_BUTTON_PADDLE2> - Xbox Elite paddle P3 | ||
| 1173 | |||
| 1174 | =item C<SDL_CONTROLLER_BUTTON_PADDLE3> - Xbox Elite paddle P2 | ||
| 1175 | |||
| 1176 | =item C<SDL_CONTROLLER_BUTTON_PADDLE4> - Xbox Elite paddle P4 | ||
| 1177 | |||
| 1178 | =item C<SDL_CONTROLLER_BUTTON_TOUCHPAD> - PS4/PS5 touchpad button | ||
| 1179 | |||
| 1180 | =item C<SDL_CONTROLLER_BUTTON_MAX> | ||
| 1181 | |||
| 1182 | =back | ||
| 1183 | |||
| 1184 | =head2 Notes | ||
| 1185 | |||
| 1186 | To count the number of game controllers in the system for the following: | ||
| 1187 | |||
| 1188 | my $nJoysticks = SDL_NumJoysticks(); | ||
| 1189 | my $nGameControllers = 0; | ||
| 1190 | for my $i (0 .. $nJoysticks) { | ||
| 1191 | $nGameControllers++ if SDL_IsGameController($i); | ||
| 1192 | } | ||
| 1193 | |||
| 1194 | Using the C<SDL_HINT_GAMECONTROLLERCONFIG> hint or the L<< | ||
| 1195 | C<SDL_GameControllerAddMapping( ... )>|/C<SDL_GameControllerAddMapping( ... )> | ||
| 1196 | >> you can add support for controllers SDL is unaware of or cause an existing | ||
| 1197 | controller to have a different binding. The format is: C<guid,name,mappings>, | ||
| 1198 | |||
| 1199 | Where GUID is the string value from C<SDL_JoystickGetGUIDString( ... )>, name | ||
| 1200 | is the human readable string for the device and mappings are controller | ||
| 1201 | mappings to joystick ones. Under Windows there is a reserved GUID of "xinput" | ||
| 1202 | that covers any XInput devices. The mapping format for joystick is: | ||
| 1203 | |||
| 1204 | =over | ||
| 1205 | |||
| 1206 | =item C<bX> - a joystick button, index X | ||
| 1207 | |||
| 1208 | =item C<hX.Y> - hat X with value Y | ||
| 1209 | |||
| 1210 | =item C<aX> - axis X of the joystick | ||
| 1211 | |||
| 1212 | =back | ||
| 1213 | |||
| 1214 | Buttons can be used as a controller axis and vice versa. | ||
| 1215 | |||
| 1216 | This string shows an example of a valid mapping for a controller | ||
| 1217 | |||
| 1218 | 03000000341a00003608000000000000,PS3 Controller,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b8,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7 | ||
| 1219 | |||
| 1220 | =head1 LICENSE | ||
| 1221 | |||
| 1222 | Copyright (C) Sanko Robinson. | ||
| 1223 | |||
| 1224 | This library is free software; you can redistribute it and/or modify it under | ||
| 1225 | the terms found in the Artistic License 2. Other copyrights, terms, and | ||
| 1226 | conditions may apply to data transmitted through this module. | ||
| 1227 | |||
| 1228 | =head1 AUTHOR | ||
| 1229 | |||
| 1230 | Sanko Robinson E<lt>sanko@cpan.orgE<gt> | ||
| 1231 | |||
| 1232 | =begin stopwords | ||
| 1233 | |||
| 1234 | xinput versa N'th touchpads autodetect | ||
| 1235 | |||
| 1236 | =end stopwords | ||
| 1237 | |||
| 1238 | =cut | ||
| 1239 | |||
| 1240 | }; | ||
| 1241 | 1; |