🛠️🐜 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.

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