🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1074 lines
39 KiB

  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * \file SDL_gamecontroller.h
  20. *
  21. * Include file for SDL game controller event handling
  22. */
  23. #ifndef SDL_gamecontroller_h_
  24. #define SDL_gamecontroller_h_
  25. #include "SDL_stdinc.h"
  26. #include "SDL_error.h"
  27. #include "SDL_rwops.h"
  28. #include "SDL_sensor.h"
  29. #include "SDL_joystick.h"
  30. #include "begin_code.h"
  31. /* Set up for C function definitions, even when using C++ */
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. /**
  36. * \file SDL_gamecontroller.h
  37. *
  38. * In order to use these functions, SDL_Init() must have been called
  39. * with the ::SDL_INIT_GAMECONTROLLER flag. This causes SDL to scan the system
  40. * for game controllers, and load appropriate drivers.
  41. *
  42. * If you would like to receive controller updates while the application
  43. * is in the background, you should set the following hint before calling
  44. * SDL_Init(): SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS
  45. */
  46. /**
  47. * The gamecontroller structure used to identify an SDL game controller
  48. */
  49. struct _SDL_GameController;
  50. typedef struct _SDL_GameController SDL_GameController;
  51. typedef enum
  52. {
  53. SDL_CONTROLLER_TYPE_UNKNOWN = 0,
  54. SDL_CONTROLLER_TYPE_XBOX360,
  55. SDL_CONTROLLER_TYPE_XBOXONE,
  56. SDL_CONTROLLER_TYPE_PS3,
  57. SDL_CONTROLLER_TYPE_PS4,
  58. SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO,
  59. SDL_CONTROLLER_TYPE_VIRTUAL,
  60. SDL_CONTROLLER_TYPE_PS5,
  61. SDL_CONTROLLER_TYPE_AMAZON_LUNA,
  62. SDL_CONTROLLER_TYPE_GOOGLE_STADIA,
  63. SDL_CONTROLLER_TYPE_NVIDIA_SHIELD,
  64. SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_LEFT,
  65. SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT,
  66. SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_PAIR
  67. } SDL_GameControllerType;
  68. typedef enum
  69. {
  70. SDL_CONTROLLER_BINDTYPE_NONE = 0,
  71. SDL_CONTROLLER_BINDTYPE_BUTTON,
  72. SDL_CONTROLLER_BINDTYPE_AXIS,
  73. SDL_CONTROLLER_BINDTYPE_HAT
  74. } SDL_GameControllerBindType;
  75. /**
  76. * Get the SDL joystick layer binding for this controller button/axis mapping
  77. */
  78. typedef struct SDL_GameControllerButtonBind
  79. {
  80. SDL_GameControllerBindType bindType;
  81. union
  82. {
  83. int button;
  84. int axis;
  85. struct {
  86. int hat;
  87. int hat_mask;
  88. } hat;
  89. } value;
  90. } SDL_GameControllerButtonBind;
  91. /**
  92. * To count the number of game controllers in the system for the following:
  93. *
  94. * ```c
  95. * int nJoysticks = SDL_NumJoysticks();
  96. * int nGameControllers = 0;
  97. * for (int i = 0; i < nJoysticks; i++) {
  98. * if (SDL_IsGameController(i)) {
  99. * nGameControllers++;
  100. * }
  101. * }
  102. * ```
  103. *
  104. * Using the SDL_HINT_GAMECONTROLLERCONFIG hint or the SDL_GameControllerAddMapping() you can add support for controllers SDL is unaware of or cause an existing controller to have a different binding. The format is:
  105. * guid,name,mappings
  106. *
  107. * Where GUID is the string value from SDL_JoystickGetGUIDString(), name is the human readable string for the device and mappings are controller mappings to joystick ones.
  108. * Under Windows there is a reserved GUID of "xinput" that covers any XInput devices.
  109. * The mapping format for joystick is:
  110. * bX - a joystick button, index X
  111. * hX.Y - hat X with value Y
  112. * aX - axis X of the joystick
  113. * Buttons can be used as a controller axis and vice versa.
  114. *
  115. * This string shows an example of a valid mapping for a controller
  116. *
  117. * ```c
  118. * "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",
  119. * ```
  120. */
  121. /**
  122. * Load a set of Game Controller mappings from a seekable SDL data stream.
  123. *
  124. * You can call this function several times, if needed, to load different
  125. * database files.
  126. *
  127. * If a new mapping is loaded for an already known controller GUID, the later
  128. * version will overwrite the one currently loaded.
  129. *
  130. * Mappings not belonging to the current platform or with no platform field
  131. * specified will be ignored (i.e. mappings for Linux will be ignored in
  132. * Windows, etc).
  133. *
  134. * This function will load the text database entirely in memory before
  135. * processing it, so take this into consideration if you are in a memory
  136. * constrained environment.
  137. *
  138. * \param rw the data stream for the mappings to be added
  139. * \param freerw non-zero to close the stream after being read
  140. * \returns the number of mappings added or -1 on error; call SDL_GetError()
  141. * for more information.
  142. *
  143. * \since This function is available since SDL 2.0.2.
  144. *
  145. * \sa SDL_GameControllerAddMapping
  146. * \sa SDL_GameControllerAddMappingsFromFile
  147. * \sa SDL_GameControllerMappingForGUID
  148. */
  149. extern DECLSPEC int SDLCALL SDL_GameControllerAddMappingsFromRW(SDL_RWops * rw, int freerw);
  150. /**
  151. * Load a set of mappings from a file, filtered by the current SDL_GetPlatform()
  152. *
  153. * Convenience macro.
  154. */
  155. #define SDL_GameControllerAddMappingsFromFile(file) SDL_GameControllerAddMappingsFromRW(SDL_RWFromFile(file, "rb"), 1)
  156. /**
  157. * Add support for controllers that SDL is unaware of or to cause an existing
  158. * controller to have a different binding.
  159. *
  160. * The mapping string has the format "GUID,name,mapping", where GUID is the
  161. * string value from SDL_JoystickGetGUIDString(), name is the human readable
  162. * string for the device and mappings are controller mappings to joystick
  163. * ones. Under Windows there is a reserved GUID of "xinput" that covers all
  164. * XInput devices. The mapping format for joystick is: {| |bX |a joystick
  165. * button, index X |- |hX.Y |hat X with value Y |- |aX |axis X of the joystick
  166. * |} Buttons can be used as a controller axes and vice versa.
  167. *
  168. * This string shows an example of a valid mapping for a controller:
  169. *
  170. * ```c
  171. * "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"
  172. * ```
  173. *
  174. * \param mappingString the mapping string
  175. * \returns 1 if a new mapping is added, 0 if an existing mapping is updated,
  176. * -1 on error; call SDL_GetError() for more information.
  177. *
  178. * \since This function is available since SDL 2.0.0.
  179. *
  180. * \sa SDL_GameControllerMapping
  181. * \sa SDL_GameControllerMappingForGUID
  182. */
  183. extern DECLSPEC int SDLCALL SDL_GameControllerAddMapping(const char* mappingString);
  184. /**
  185. * Get the number of mappings installed.
  186. *
  187. * \returns the number of mappings.
  188. *
  189. * \since This function is available since SDL 2.0.6.
  190. */
  191. extern DECLSPEC int SDLCALL SDL_GameControllerNumMappings(void);
  192. /**
  193. * Get the mapping at a particular index.
  194. *
  195. * \returns the mapping string. Must be freed with SDL_free(). Returns NULL if
  196. * the index is out of range.
  197. *
  198. * \since This function is available since SDL 2.0.6.
  199. */
  200. extern DECLSPEC char * SDLCALL SDL_GameControllerMappingForIndex(int mapping_index);
  201. /**
  202. * Get the game controller mapping string for a given GUID.
  203. *
  204. * The returned string must be freed with SDL_free().
  205. *
  206. * \param guid a structure containing the GUID for which a mapping is desired
  207. * \returns a mapping string or NULL on error; call SDL_GetError() for more
  208. * information.
  209. *
  210. * \since This function is available since SDL 2.0.0.
  211. *
  212. * \sa SDL_JoystickGetDeviceGUID
  213. * \sa SDL_JoystickGetGUID
  214. */
  215. extern DECLSPEC char * SDLCALL SDL_GameControllerMappingForGUID(SDL_JoystickGUID guid);
  216. /**
  217. * Get the current mapping of a Game Controller.
  218. *
  219. * The returned string must be freed with SDL_free().
  220. *
  221. * Details about mappings are discussed with SDL_GameControllerAddMapping().
  222. *
  223. * \param gamecontroller the game controller you want to get the current
  224. * mapping for
  225. * \returns a string that has the controller's mapping or NULL if no mapping
  226. * is available; call SDL_GetError() for more information.
  227. *
  228. * \since This function is available since SDL 2.0.0.
  229. *
  230. * \sa SDL_GameControllerAddMapping
  231. * \sa SDL_GameControllerMappingForGUID
  232. */
  233. extern DECLSPEC char * SDLCALL SDL_GameControllerMapping(SDL_GameController *gamecontroller);
  234. /**
  235. * Check if the given joystick is supported by the game controller interface.
  236. *
  237. * `joystick_index` is the same as the `device_index` passed to
  238. * SDL_JoystickOpen().
  239. *
  240. * \param joystick_index the device_index of a device, up to
  241. * SDL_NumJoysticks()
  242. * \returns SDL_TRUE if the given joystick is supported by the game controller
  243. * interface, SDL_FALSE if it isn't or it's an invalid index.
  244. *
  245. * \since This function is available since SDL 2.0.0.
  246. *
  247. * \sa SDL_GameControllerNameForIndex
  248. * \sa SDL_GameControllerOpen
  249. */
  250. extern DECLSPEC SDL_bool SDLCALL SDL_IsGameController(int joystick_index);
  251. /**
  252. * Get the implementation dependent name for the game controller.
  253. *
  254. * This function can be called before any controllers are opened.
  255. *
  256. * `joystick_index` is the same as the `device_index` passed to
  257. * SDL_JoystickOpen().
  258. *
  259. * \param joystick_index the device_index of a device, from zero to
  260. * SDL_NumJoysticks()-1
  261. * \returns the implementation-dependent name for the game controller, or NULL
  262. * if there is no name or the index is invalid.
  263. *
  264. * \since This function is available since SDL 2.0.0.
  265. *
  266. * \sa SDL_GameControllerName
  267. * \sa SDL_GameControllerOpen
  268. * \sa SDL_IsGameController
  269. */
  270. extern DECLSPEC const char *SDLCALL SDL_GameControllerNameForIndex(int joystick_index);
  271. /**
  272. * Get the implementation dependent path for the game controller.
  273. *
  274. * This function can be called before any controllers are opened.
  275. *
  276. * `joystick_index` is the same as the `device_index` passed to
  277. * SDL_JoystickOpen().
  278. *
  279. * \param joystick_index the device_index of a device, from zero to
  280. * SDL_NumJoysticks()-1
  281. * \returns the implementation-dependent path for the game controller, or NULL
  282. * if there is no path or the index is invalid.
  283. *
  284. * \since This function is available since SDL 2.24.0.
  285. *
  286. * \sa SDL_GameControllerPath
  287. */
  288. extern DECLSPEC const char *SDLCALL SDL_GameControllerPathForIndex(int joystick_index);
  289. /**
  290. * Get the type of a game controller.
  291. *
  292. * This can be called before any controllers are opened.
  293. *
  294. * \param joystick_index the device_index of a device, from zero to
  295. * SDL_NumJoysticks()-1
  296. * \returns the controller type.
  297. *
  298. * \since This function is available since SDL 2.0.12.
  299. */
  300. extern DECLSPEC SDL_GameControllerType SDLCALL SDL_GameControllerTypeForIndex(int joystick_index);
  301. /**
  302. * Get the mapping of a game controller.
  303. *
  304. * This can be called before any controllers are opened.
  305. *
  306. * \param joystick_index the device_index of a device, from zero to
  307. * SDL_NumJoysticks()-1
  308. * \returns the mapping string. Must be freed with SDL_free(). Returns NULL if
  309. * no mapping is available.
  310. *
  311. * \since This function is available since SDL 2.0.9.
  312. */
  313. extern DECLSPEC char *SDLCALL SDL_GameControllerMappingForDeviceIndex(int joystick_index);
  314. /**
  315. * Open a game controller for use.
  316. *
  317. * `joystick_index` is the same as the `device_index` passed to
  318. * SDL_JoystickOpen().
  319. *
  320. * The index passed as an argument refers to the N'th game controller on the
  321. * system. This index is not the value which will identify this controller in
  322. * future controller events. The joystick's instance id (SDL_JoystickID) will
  323. * be used there instead.
  324. *
  325. * \param joystick_index the device_index of a device, up to
  326. * SDL_NumJoysticks()
  327. * \returns a gamecontroller identifier or NULL if an error occurred; call
  328. * SDL_GetError() for more information.
  329. *
  330. * \since This function is available since SDL 2.0.0.
  331. *
  332. * \sa SDL_GameControllerClose
  333. * \sa SDL_GameControllerNameForIndex
  334. * \sa SDL_IsGameController
  335. */
  336. extern DECLSPEC SDL_GameController *SDLCALL SDL_GameControllerOpen(int joystick_index);
  337. /**
  338. * Get the SDL_GameController associated with an instance id.
  339. *
  340. * \param joyid the instance id to get the SDL_GameController for
  341. * \returns an SDL_GameController on success or NULL on failure; call
  342. * SDL_GetError() for more information.
  343. *
  344. * \since This function is available since SDL 2.0.4.
  345. */
  346. extern DECLSPEC SDL_GameController *SDLCALL SDL_GameControllerFromInstanceID(SDL_JoystickID joyid);
  347. /**
  348. * Get the SDL_GameController associated with a player index.
  349. *
  350. * Please note that the player index is _not_ the device index, nor is it the
  351. * instance id!
  352. *
  353. * \param player_index the player index, which is not the device index or the
  354. * instance id!
  355. * \returns the SDL_GameController associated with a player index.
  356. *
  357. * \since This function is available since SDL 2.0.12.
  358. *
  359. * \sa SDL_GameControllerGetPlayerIndex
  360. * \sa SDL_GameControllerSetPlayerIndex
  361. */
  362. extern DECLSPEC SDL_GameController *SDLCALL SDL_GameControllerFromPlayerIndex(int player_index);
  363. /**
  364. * Get the implementation-dependent name for an opened game controller.
  365. *
  366. * This is the same name as returned by SDL_GameControllerNameForIndex(), but
  367. * it takes a controller identifier instead of the (unstable) device index.
  368. *
  369. * \param gamecontroller a game controller identifier previously returned by
  370. * SDL_GameControllerOpen()
  371. * \returns the implementation dependent name for the game controller, or NULL
  372. * if there is no name or the identifier passed is invalid.
  373. *
  374. * \since This function is available since SDL 2.0.0.
  375. *
  376. * \sa SDL_GameControllerNameForIndex
  377. * \sa SDL_GameControllerOpen
  378. */
  379. extern DECLSPEC const char *SDLCALL SDL_GameControllerName(SDL_GameController *gamecontroller);
  380. /**
  381. * Get the implementation-dependent path for an opened game controller.
  382. *
  383. * This is the same path as returned by SDL_GameControllerNameForIndex(), but
  384. * it takes a controller identifier instead of the (unstable) device index.
  385. *
  386. * \param gamecontroller a game controller identifier previously returned by
  387. * SDL_GameControllerOpen()
  388. * \returns the implementation dependent path for the game controller, or NULL
  389. * if there is no path or the identifier passed is invalid.
  390. *
  391. * \since This function is available since SDL 2.24.0.
  392. *
  393. * \sa SDL_GameControllerPathForIndex
  394. */
  395. extern DECLSPEC const char *SDLCALL SDL_GameControllerPath(SDL_GameController *gamecontroller);
  396. /**
  397. * Get the type of this currently opened controller
  398. *
  399. * This is the same name as returned by SDL_GameControllerTypeForIndex(), but
  400. * it takes a controller identifier instead of the (unstable) device index.
  401. *
  402. * \param gamecontroller the game controller object to query.
  403. * \returns the controller type.
  404. *
  405. * \since This function is available since SDL 2.0.12.
  406. */
  407. extern DECLSPEC SDL_GameControllerType SDLCALL SDL_GameControllerGetType(SDL_GameController *gamecontroller);
  408. /**
  409. * Get the player index of an opened game controller.
  410. *
  411. * For XInput controllers this returns the XInput user index.
  412. *
  413. * \param gamecontroller the game controller object to query.
  414. * \returns the player index for controller, or -1 if it's not available.
  415. *
  416. * \since This function is available since SDL 2.0.9.
  417. */
  418. extern DECLSPEC int SDLCALL SDL_GameControllerGetPlayerIndex(SDL_GameController *gamecontroller);
  419. /**
  420. * Set the player index of an opened game controller.
  421. *
  422. * \param gamecontroller the game controller object to adjust.
  423. * \param player_index Player index to assign to this controller, or -1 to
  424. * clear the player index and turn off player LEDs.
  425. *
  426. * \since This function is available since SDL 2.0.12.
  427. */
  428. extern DECLSPEC void SDLCALL SDL_GameControllerSetPlayerIndex(SDL_GameController *gamecontroller, int player_index);
  429. /**
  430. * Get the USB vendor ID of an opened controller, if available.
  431. *
  432. * If the vendor ID isn't available this function returns 0.
  433. *
  434. * \param gamecontroller the game controller object to query.
  435. * \return the USB vendor ID, or zero if unavailable.
  436. *
  437. * \since This function is available since SDL 2.0.6.
  438. */
  439. extern DECLSPEC Uint16 SDLCALL SDL_GameControllerGetVendor(SDL_GameController *gamecontroller);
  440. /**
  441. * Get the USB product ID of an opened controller, if available.
  442. *
  443. * If the product ID isn't available this function returns 0.
  444. *
  445. * \param gamecontroller the game controller object to query.
  446. * \return the USB product ID, or zero if unavailable.
  447. *
  448. * \since This function is available since SDL 2.0.6.
  449. */
  450. extern DECLSPEC Uint16 SDLCALL SDL_GameControllerGetProduct(SDL_GameController *gamecontroller);
  451. /**
  452. * Get the product version of an opened controller, if available.
  453. *
  454. * If the product version isn't available this function returns 0.
  455. *
  456. * \param gamecontroller the game controller object to query.
  457. * \return the USB product version, or zero if unavailable.
  458. *
  459. * \since This function is available since SDL 2.0.6.
  460. */
  461. extern DECLSPEC Uint16 SDLCALL SDL_GameControllerGetProductVersion(SDL_GameController *gamecontroller);
  462. /**
  463. * Get the firmware version of an opened controller, if available.
  464. *
  465. * If the firmware version isn't available this function returns 0.
  466. *
  467. * \param gamecontroller the game controller object to query.
  468. * \return the controller firmware version, or zero if unavailable.
  469. *
  470. * \since This function is available since SDL 2.24.0.
  471. */
  472. extern DECLSPEC Uint16 SDLCALL SDL_GameControllerGetFirmwareVersion(SDL_GameController *gamecontroller);
  473. /**
  474. * Get the serial number of an opened controller, if available.
  475. *
  476. * Returns the serial number of the controller, or NULL if it is not
  477. * available.
  478. *
  479. * \param gamecontroller the game controller object to query.
  480. * \return the serial number, or NULL if unavailable.
  481. *
  482. * \since This function is available since SDL 2.0.14.
  483. */
  484. extern DECLSPEC const char * SDLCALL SDL_GameControllerGetSerial(SDL_GameController *gamecontroller);
  485. /**
  486. * Check if a controller has been opened and is currently connected.
  487. *
  488. * \param gamecontroller a game controller identifier previously returned by
  489. * SDL_GameControllerOpen()
  490. * \returns SDL_TRUE if the controller has been opened and is currently
  491. * connected, or SDL_FALSE if not.
  492. *
  493. * \since This function is available since SDL 2.0.0.
  494. *
  495. * \sa SDL_GameControllerClose
  496. * \sa SDL_GameControllerOpen
  497. */
  498. extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerGetAttached(SDL_GameController *gamecontroller);
  499. /**
  500. * Get the Joystick ID from a Game Controller.
  501. *
  502. * This function will give you a SDL_Joystick object, which allows you to use
  503. * the SDL_Joystick functions with a SDL_GameController object. This would be
  504. * useful for getting a joystick's position at any given time, even if it
  505. * hasn't moved (moving it would produce an event, which would have the axis'
  506. * value).
  507. *
  508. * The pointer returned is owned by the SDL_GameController. You should not
  509. * call SDL_JoystickClose() on it, for example, since doing so will likely
  510. * cause SDL to crash.
  511. *
  512. * \param gamecontroller the game controller object that you want to get a
  513. * joystick from
  514. * \returns a SDL_Joystick object; call SDL_GetError() for more information.
  515. *
  516. * \since This function is available since SDL 2.0.0.
  517. */
  518. extern DECLSPEC SDL_Joystick *SDLCALL SDL_GameControllerGetJoystick(SDL_GameController *gamecontroller);
  519. /**
  520. * Query or change current state of Game Controller events.
  521. *
  522. * If controller events are disabled, you must call SDL_GameControllerUpdate()
  523. * yourself and check the state of the controller when you want controller
  524. * information.
  525. *
  526. * Any number can be passed to SDL_GameControllerEventState(), but only -1, 0,
  527. * and 1 will have any effect. Other numbers will just be returned.
  528. *
  529. * \param state can be one of `SDL_QUERY`, `SDL_IGNORE`, or `SDL_ENABLE`
  530. * \returns the same value passed to the function, with exception to -1
  531. * (SDL_QUERY), which will return the current state.
  532. *
  533. * \since This function is available since SDL 2.0.0.
  534. *
  535. * \sa SDL_JoystickEventState
  536. */
  537. extern DECLSPEC int SDLCALL SDL_GameControllerEventState(int state);
  538. /**
  539. * Manually pump game controller updates if not using the loop.
  540. *
  541. * This function is called automatically by the event loop if events are
  542. * enabled. Under such circumstances, it will not be necessary to call this
  543. * function.
  544. *
  545. * \since This function is available since SDL 2.0.0.
  546. */
  547. extern DECLSPEC void SDLCALL SDL_GameControllerUpdate(void);
  548. /**
  549. * The list of axes available from a controller
  550. *
  551. * Thumbstick axis values range from SDL_JOYSTICK_AXIS_MIN to SDL_JOYSTICK_AXIS_MAX,
  552. * and are centered within ~8000 of zero, though advanced UI will allow users to set
  553. * or autodetect the dead zone, which varies between controllers.
  554. *
  555. * Trigger axis values range from 0 to SDL_JOYSTICK_AXIS_MAX.
  556. */
  557. typedef enum
  558. {
  559. SDL_CONTROLLER_AXIS_INVALID = -1,
  560. SDL_CONTROLLER_AXIS_LEFTX,
  561. SDL_CONTROLLER_AXIS_LEFTY,
  562. SDL_CONTROLLER_AXIS_RIGHTX,
  563. SDL_CONTROLLER_AXIS_RIGHTY,
  564. SDL_CONTROLLER_AXIS_TRIGGERLEFT,
  565. SDL_CONTROLLER_AXIS_TRIGGERRIGHT,
  566. SDL_CONTROLLER_AXIS_MAX
  567. } SDL_GameControllerAxis;
  568. /**
  569. * Convert a string into SDL_GameControllerAxis enum.
  570. *
  571. * This function is called internally to translate SDL_GameController mapping
  572. * strings for the underlying joystick device into the consistent
  573. * SDL_GameController mapping. You do not normally need to call this function
  574. * unless you are parsing SDL_GameController mappings in your own code.
  575. *
  576. * Note specially that "righttrigger" and "lefttrigger" map to
  577. * `SDL_CONTROLLER_AXIS_TRIGGERRIGHT` and `SDL_CONTROLLER_AXIS_TRIGGERLEFT`,
  578. * respectively.
  579. *
  580. * \param str string representing a SDL_GameController axis
  581. * \returns the SDL_GameControllerAxis enum corresponding to the input string,
  582. * or `SDL_CONTROLLER_AXIS_INVALID` if no match was found.
  583. *
  584. * \since This function is available since SDL 2.0.0.
  585. *
  586. * \sa SDL_GameControllerGetStringForAxis
  587. */
  588. extern DECLSPEC SDL_GameControllerAxis SDLCALL SDL_GameControllerGetAxisFromString(const char *str);
  589. /**
  590. * Convert from an SDL_GameControllerAxis enum to a string.
  591. *
  592. * The caller should not SDL_free() the returned string.
  593. *
  594. * \param axis an enum value for a given SDL_GameControllerAxis
  595. * \returns a string for the given axis, or NULL if an invalid axis is
  596. * specified. The string returned is of the format used by
  597. * SDL_GameController mapping strings.
  598. *
  599. * \since This function is available since SDL 2.0.0.
  600. *
  601. * \sa SDL_GameControllerGetAxisFromString
  602. */
  603. extern DECLSPEC const char* SDLCALL SDL_GameControllerGetStringForAxis(SDL_GameControllerAxis axis);
  604. /**
  605. * Get the SDL joystick layer binding for a controller axis mapping.
  606. *
  607. * \param gamecontroller a game controller
  608. * \param axis an axis enum value (one of the SDL_GameControllerAxis values)
  609. * \returns a SDL_GameControllerButtonBind describing the bind. On failure
  610. * (like the given Controller axis doesn't exist on the device), its
  611. * `.bindType` will be `SDL_CONTROLLER_BINDTYPE_NONE`.
  612. *
  613. * \since This function is available since SDL 2.0.0.
  614. *
  615. * \sa SDL_GameControllerGetBindForButton
  616. */
  617. extern DECLSPEC SDL_GameControllerButtonBind SDLCALL
  618. SDL_GameControllerGetBindForAxis(SDL_GameController *gamecontroller,
  619. SDL_GameControllerAxis axis);
  620. /**
  621. * Query whether a game controller has a given axis.
  622. *
  623. * This merely reports whether the controller's mapping defined this axis, as
  624. * that is all the information SDL has about the physical device.
  625. *
  626. * \param gamecontroller a game controller
  627. * \param axis an axis enum value (an SDL_GameControllerAxis value)
  628. * \returns SDL_TRUE if the controller has this axis, SDL_FALSE otherwise.
  629. *
  630. * \since This function is available since SDL 2.0.14.
  631. */
  632. extern DECLSPEC SDL_bool SDLCALL
  633. SDL_GameControllerHasAxis(SDL_GameController *gamecontroller, SDL_GameControllerAxis axis);
  634. /**
  635. * Get the current state of an axis control on a game controller.
  636. *
  637. * The axis indices start at index 0.
  638. *
  639. * The state is a value ranging from -32768 to 32767. Triggers, however, range
  640. * from 0 to 32767 (they never return a negative value).
  641. *
  642. * \param gamecontroller a game controller
  643. * \param axis an axis index (one of the SDL_GameControllerAxis values)
  644. * \returns axis state (including 0) on success or 0 (also) on failure; call
  645. * SDL_GetError() for more information.
  646. *
  647. * \since This function is available since SDL 2.0.0.
  648. *
  649. * \sa SDL_GameControllerGetButton
  650. */
  651. extern DECLSPEC Sint16 SDLCALL
  652. SDL_GameControllerGetAxis(SDL_GameController *gamecontroller, SDL_GameControllerAxis axis);
  653. /**
  654. * The list of buttons available from a controller
  655. */
  656. typedef enum
  657. {
  658. SDL_CONTROLLER_BUTTON_INVALID = -1,
  659. SDL_CONTROLLER_BUTTON_A,
  660. SDL_CONTROLLER_BUTTON_B,
  661. SDL_CONTROLLER_BUTTON_X,
  662. SDL_CONTROLLER_BUTTON_Y,
  663. SDL_CONTROLLER_BUTTON_BACK,
  664. SDL_CONTROLLER_BUTTON_GUIDE,
  665. SDL_CONTROLLER_BUTTON_START,
  666. SDL_CONTROLLER_BUTTON_LEFTSTICK,
  667. SDL_CONTROLLER_BUTTON_RIGHTSTICK,
  668. SDL_CONTROLLER_BUTTON_LEFTSHOULDER,
  669. SDL_CONTROLLER_BUTTON_RIGHTSHOULDER,
  670. SDL_CONTROLLER_BUTTON_DPAD_UP,
  671. SDL_CONTROLLER_BUTTON_DPAD_DOWN,
  672. SDL_CONTROLLER_BUTTON_DPAD_LEFT,
  673. SDL_CONTROLLER_BUTTON_DPAD_RIGHT,
  674. SDL_CONTROLLER_BUTTON_MISC1, /* Xbox Series X share button, PS5 microphone button, Nintendo Switch Pro capture button, Amazon Luna microphone button */
  675. SDL_CONTROLLER_BUTTON_PADDLE1, /* Xbox Elite paddle P1 */
  676. SDL_CONTROLLER_BUTTON_PADDLE2, /* Xbox Elite paddle P3 */
  677. SDL_CONTROLLER_BUTTON_PADDLE3, /* Xbox Elite paddle P2 */
  678. SDL_CONTROLLER_BUTTON_PADDLE4, /* Xbox Elite paddle P4 */
  679. SDL_CONTROLLER_BUTTON_TOUCHPAD, /* PS4/PS5 touchpad button */
  680. SDL_CONTROLLER_BUTTON_MAX
  681. } SDL_GameControllerButton;
  682. /**
  683. * Convert a string into an SDL_GameControllerButton enum.
  684. *
  685. * This function is called internally to translate SDL_GameController mapping
  686. * strings for the underlying joystick device into the consistent
  687. * SDL_GameController mapping. You do not normally need to call this function
  688. * unless you are parsing SDL_GameController mappings in your own code.
  689. *
  690. * \param str string representing a SDL_GameController axis
  691. * \returns the SDL_GameControllerButton enum corresponding to the input
  692. * string, or `SDL_CONTROLLER_AXIS_INVALID` if no match was found.
  693. *
  694. * \since This function is available since SDL 2.0.0.
  695. */
  696. extern DECLSPEC SDL_GameControllerButton SDLCALL SDL_GameControllerGetButtonFromString(const char *str);
  697. /**
  698. * Convert from an SDL_GameControllerButton enum to a string.
  699. *
  700. * The caller should not SDL_free() the returned string.
  701. *
  702. * \param button an enum value for a given SDL_GameControllerButton
  703. * \returns a string for the given button, or NULL if an invalid button is
  704. * specified. The string returned is of the format used by
  705. * SDL_GameController mapping strings.
  706. *
  707. * \since This function is available since SDL 2.0.0.
  708. *
  709. * \sa SDL_GameControllerGetButtonFromString
  710. */
  711. extern DECLSPEC const char* SDLCALL SDL_GameControllerGetStringForButton(SDL_GameControllerButton button);
  712. /**
  713. * Get the SDL joystick layer binding for a controller button mapping.
  714. *
  715. * \param gamecontroller a game controller
  716. * \param button an button enum value (an SDL_GameControllerButton value)
  717. * \returns a SDL_GameControllerButtonBind describing the bind. On failure
  718. * (like the given Controller button doesn't exist on the device),
  719. * its `.bindType` will be `SDL_CONTROLLER_BINDTYPE_NONE`.
  720. *
  721. * \since This function is available since SDL 2.0.0.
  722. *
  723. * \sa SDL_GameControllerGetBindForAxis
  724. */
  725. extern DECLSPEC SDL_GameControllerButtonBind SDLCALL
  726. SDL_GameControllerGetBindForButton(SDL_GameController *gamecontroller,
  727. SDL_GameControllerButton button);
  728. /**
  729. * Query whether a game controller has a given button.
  730. *
  731. * This merely reports whether the controller's mapping defined this button,
  732. * as that is all the information SDL has about the physical device.
  733. *
  734. * \param gamecontroller a game controller
  735. * \param button a button enum value (an SDL_GameControllerButton value)
  736. * \returns SDL_TRUE if the controller has this button, SDL_FALSE otherwise.
  737. *
  738. * \since This function is available since SDL 2.0.14.
  739. */
  740. extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerHasButton(SDL_GameController *gamecontroller,
  741. SDL_GameControllerButton button);
  742. /**
  743. * Get the current state of a button on a game controller.
  744. *
  745. * \param gamecontroller a game controller
  746. * \param button a button index (one of the SDL_GameControllerButton values)
  747. * \returns 1 for pressed state or 0 for not pressed state or error; call
  748. * SDL_GetError() for more information.
  749. *
  750. * \since This function is available since SDL 2.0.0.
  751. *
  752. * \sa SDL_GameControllerGetAxis
  753. */
  754. extern DECLSPEC Uint8 SDLCALL SDL_GameControllerGetButton(SDL_GameController *gamecontroller,
  755. SDL_GameControllerButton button);
  756. /**
  757. * Get the number of touchpads on a game controller.
  758. *
  759. * \since This function is available since SDL 2.0.14.
  760. */
  761. extern DECLSPEC int SDLCALL SDL_GameControllerGetNumTouchpads(SDL_GameController *gamecontroller);
  762. /**
  763. * Get the number of supported simultaneous fingers on a touchpad on a game
  764. * controller.
  765. *
  766. * \since This function is available since SDL 2.0.14.
  767. */
  768. extern DECLSPEC int SDLCALL SDL_GameControllerGetNumTouchpadFingers(SDL_GameController *gamecontroller, int touchpad);
  769. /**
  770. * Get the current state of a finger on a touchpad on a game controller.
  771. *
  772. * \since This function is available since SDL 2.0.14.
  773. */
  774. extern DECLSPEC int SDLCALL SDL_GameControllerGetTouchpadFinger(SDL_GameController *gamecontroller, int touchpad, int finger, Uint8 *state, float *x, float *y, float *pressure);
  775. /**
  776. * Return whether a game controller has a particular sensor.
  777. *
  778. * \param gamecontroller The controller to query
  779. * \param type The type of sensor to query
  780. * \returns SDL_TRUE if the sensor exists, SDL_FALSE otherwise.
  781. *
  782. * \since This function is available since SDL 2.0.14.
  783. */
  784. extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerHasSensor(SDL_GameController *gamecontroller, SDL_SensorType type);
  785. /**
  786. * Set whether data reporting for a game controller sensor is enabled.
  787. *
  788. * \param gamecontroller The controller to update
  789. * \param type The type of sensor to enable/disable
  790. * \param enabled Whether data reporting should be enabled
  791. * \returns 0 or -1 if an error occurred.
  792. *
  793. * \since This function is available since SDL 2.0.14.
  794. */
  795. extern DECLSPEC int SDLCALL SDL_GameControllerSetSensorEnabled(SDL_GameController *gamecontroller, SDL_SensorType type, SDL_bool enabled);
  796. /**
  797. * Query whether sensor data reporting is enabled for a game controller.
  798. *
  799. * \param gamecontroller The controller to query
  800. * \param type The type of sensor to query
  801. * \returns SDL_TRUE if the sensor is enabled, SDL_FALSE otherwise.
  802. *
  803. * \since This function is available since SDL 2.0.14.
  804. */
  805. extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerIsSensorEnabled(SDL_GameController *gamecontroller, SDL_SensorType type);
  806. /**
  807. * Get the data rate (number of events per second) of a game controller
  808. * sensor.
  809. *
  810. * \param gamecontroller The controller to query
  811. * \param type The type of sensor to query
  812. * \return the data rate, or 0.0f if the data rate is not available.
  813. *
  814. * \since This function is available since SDL 2.0.16.
  815. */
  816. extern DECLSPEC float SDLCALL SDL_GameControllerGetSensorDataRate(SDL_GameController *gamecontroller, SDL_SensorType type);
  817. /**
  818. * Get the current state of a game controller sensor.
  819. *
  820. * The number of values and interpretation of the data is sensor dependent.
  821. * See SDL_sensor.h for the details for each type of sensor.
  822. *
  823. * \param gamecontroller The controller to query
  824. * \param type The type of sensor to query
  825. * \param data A pointer filled with the current sensor state
  826. * \param num_values The number of values to write to data
  827. * \return 0 or -1 if an error occurred.
  828. *
  829. * \since This function is available since SDL 2.0.14.
  830. */
  831. extern DECLSPEC int SDLCALL SDL_GameControllerGetSensorData(SDL_GameController *gamecontroller, SDL_SensorType type, float *data, int num_values);
  832. /**
  833. * Get the current state of a game controller sensor with the timestamp of the
  834. * last update.
  835. *
  836. * The number of values and interpretation of the data is sensor dependent.
  837. * See SDL_sensor.h for the details for each type of sensor.
  838. *
  839. * \param gamecontroller The controller to query
  840. * \param type The type of sensor to query
  841. * \param timestamp A pointer filled with the timestamp in microseconds of the
  842. * current sensor reading if available, or 0 if not
  843. * \param data A pointer filled with the current sensor state
  844. * \param num_values The number of values to write to data
  845. * \return 0 or -1 if an error occurred.
  846. *
  847. * \since This function is available since SDL 2.26.0.
  848. */
  849. extern DECLSPEC int SDLCALL SDL_GameControllerGetSensorDataWithTimestamp(SDL_GameController *gamecontroller, SDL_SensorType type, Uint64 *timestamp, float *data, int num_values);
  850. /**
  851. * Start a rumble effect on a game controller.
  852. *
  853. * Each call to this function cancels any previous rumble effect, and calling
  854. * it with 0 intensity stops any rumbling.
  855. *
  856. * \param gamecontroller The controller to vibrate
  857. * \param low_frequency_rumble The intensity of the low frequency (left)
  858. * rumble motor, from 0 to 0xFFFF
  859. * \param high_frequency_rumble The intensity of the high frequency (right)
  860. * rumble motor, from 0 to 0xFFFF
  861. * \param duration_ms The duration of the rumble effect, in milliseconds
  862. * \returns 0, or -1 if rumble isn't supported on this controller
  863. *
  864. * \since This function is available since SDL 2.0.9.
  865. *
  866. * \sa SDL_GameControllerHasRumble
  867. */
  868. extern DECLSPEC int SDLCALL SDL_GameControllerRumble(SDL_GameController *gamecontroller, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
  869. /**
  870. * Start a rumble effect in the game controller's triggers.
  871. *
  872. * Each call to this function cancels any previous trigger rumble effect, and
  873. * calling it with 0 intensity stops any rumbling.
  874. *
  875. * Note that this is rumbling of the _triggers_ and not the game controller as
  876. * a whole. This is currently only supported on Xbox One controllers. If you
  877. * want the (more common) whole-controller rumble, use
  878. * SDL_GameControllerRumble() instead.
  879. *
  880. * \param gamecontroller The controller to vibrate
  881. * \param left_rumble The intensity of the left trigger rumble motor, from 0
  882. * to 0xFFFF
  883. * \param right_rumble The intensity of the right trigger rumble motor, from 0
  884. * to 0xFFFF
  885. * \param duration_ms The duration of the rumble effect, in milliseconds
  886. * \returns 0, or -1 if trigger rumble isn't supported on this controller
  887. *
  888. * \since This function is available since SDL 2.0.14.
  889. *
  890. * \sa SDL_GameControllerHasRumbleTriggers
  891. */
  892. extern DECLSPEC int SDLCALL SDL_GameControllerRumbleTriggers(SDL_GameController *gamecontroller, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms);
  893. /**
  894. * Query whether a game controller has an LED.
  895. *
  896. * \param gamecontroller The controller to query
  897. * \returns SDL_TRUE, or SDL_FALSE if this controller does not have a
  898. * modifiable LED
  899. *
  900. * \since This function is available since SDL 2.0.14.
  901. */
  902. extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerHasLED(SDL_GameController *gamecontroller);
  903. /**
  904. * Query whether a game controller has rumble support.
  905. *
  906. * \param gamecontroller The controller to query
  907. * \returns SDL_TRUE, or SDL_FALSE if this controller does not have rumble
  908. * support
  909. *
  910. * \since This function is available since SDL 2.0.18.
  911. *
  912. * \sa SDL_GameControllerRumble
  913. */
  914. extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerHasRumble(SDL_GameController *gamecontroller);
  915. /**
  916. * Query whether a game controller has rumble support on triggers.
  917. *
  918. * \param gamecontroller The controller to query
  919. * \returns SDL_TRUE, or SDL_FALSE if this controller does not have trigger
  920. * rumble support
  921. *
  922. * \since This function is available since SDL 2.0.18.
  923. *
  924. * \sa SDL_GameControllerRumbleTriggers
  925. */
  926. extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerHasRumbleTriggers(SDL_GameController *gamecontroller);
  927. /**
  928. * Update a game controller's LED color.
  929. *
  930. * \param gamecontroller The controller to update
  931. * \param red The intensity of the red LED
  932. * \param green The intensity of the green LED
  933. * \param blue The intensity of the blue LED
  934. * \returns 0, or -1 if this controller does not have a modifiable LED
  935. *
  936. * \since This function is available since SDL 2.0.14.
  937. */
  938. extern DECLSPEC int SDLCALL SDL_GameControllerSetLED(SDL_GameController *gamecontroller, Uint8 red, Uint8 green, Uint8 blue);
  939. /**
  940. * Send a controller specific effect packet
  941. *
  942. * \param gamecontroller The controller to affect
  943. * \param data The data to send to the controller
  944. * \param size The size of the data to send to the controller
  945. * \returns 0, or -1 if this controller or driver doesn't support effect
  946. * packets
  947. *
  948. * \since This function is available since SDL 2.0.16.
  949. */
  950. extern DECLSPEC int SDLCALL SDL_GameControllerSendEffect(SDL_GameController *gamecontroller, const void *data, int size);
  951. /**
  952. * Close a game controller previously opened with SDL_GameControllerOpen().
  953. *
  954. * \param gamecontroller a game controller identifier previously returned by
  955. * SDL_GameControllerOpen()
  956. *
  957. * \since This function is available since SDL 2.0.0.
  958. *
  959. * \sa SDL_GameControllerOpen
  960. */
  961. extern DECLSPEC void SDLCALL SDL_GameControllerClose(SDL_GameController *gamecontroller);
  962. /**
  963. * Return the sfSymbolsName for a given button on a game controller on Apple
  964. * platforms.
  965. *
  966. * \param gamecontroller the controller to query
  967. * \param button a button on the game controller
  968. * \returns the sfSymbolsName or NULL if the name can't be found
  969. *
  970. * \since This function is available since SDL 2.0.18.
  971. *
  972. * \sa SDL_GameControllerGetAppleSFSymbolsNameForAxis
  973. */
  974. extern DECLSPEC const char* SDLCALL SDL_GameControllerGetAppleSFSymbolsNameForButton(SDL_GameController *gamecontroller, SDL_GameControllerButton button);
  975. /**
  976. * Return the sfSymbolsName for a given axis on a game controller on Apple
  977. * platforms.
  978. *
  979. * \param gamecontroller the controller to query
  980. * \param axis an axis on the game controller
  981. * \returns the sfSymbolsName or NULL if the name can't be found
  982. *
  983. * \since This function is available since SDL 2.0.18.
  984. *
  985. * \sa SDL_GameControllerGetAppleSFSymbolsNameForButton
  986. */
  987. extern DECLSPEC const char* SDLCALL SDL_GameControllerGetAppleSFSymbolsNameForAxis(SDL_GameController *gamecontroller, SDL_GameControllerAxis axis);
  988. /* Ends C function definitions when using C++ */
  989. #ifdef __cplusplus
  990. }
  991. #endif
  992. #include "close_code.h"
  993. #endif /* SDL_gamecontroller_h_ */
  994. /* vi: set ts=4 sw=4 expandtab: */