SDL_gamecontroller.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2021 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. * \sa SDL_GameControllerMapping
  175. * \sa SDL_GameControllerMappingForGUID
  176. */
  177. extern DECLSPEC int SDLCALL SDL_GameControllerAddMapping(const char* mappingString);
  178. /**
  179. * Get the number of mappings installed.
  180. *
  181. * \returns the number of mappings.
  182. */
  183. extern DECLSPEC int SDLCALL SDL_GameControllerNumMappings(void);
  184. /**
  185. * Get the mapping at a particular index.
  186. *
  187. * \returns the mapping string. Must be freed with SDL_free(). Returns NULL if
  188. * the index is out of range.
  189. */
  190. extern DECLSPEC char * SDLCALL SDL_GameControllerMappingForIndex(int mapping_index);
  191. /**
  192. * Get the game controller mapping string for a given GUID.
  193. *
  194. * The returned string must be freed with SDL_free().
  195. *
  196. * \param guid a structure containing the GUID for which a mapping is desired
  197. * \returns a mapping string or NULL on error; call SDL_GetError() for more
  198. * information.
  199. *
  200. * \sa SDL_JoystickGetDeviceGUID
  201. * \sa SDL_JoystickGetGUID
  202. */
  203. extern DECLSPEC char * SDLCALL SDL_GameControllerMappingForGUID(SDL_JoystickGUID guid);
  204. /**
  205. * Get the current mapping of a Game Controller.
  206. *
  207. * The returned string must be freed with SDL_free().
  208. *
  209. * Details about mappings are discussed with SDL_GameControllerAddMapping().
  210. *
  211. * \param gamecontroller the game controller you want to get the current
  212. * mapping for
  213. * \returns a string that has the controller's mapping or NULL if no mapping
  214. * is available; call SDL_GetError() for more information.
  215. *
  216. * \since This function is available since SDL 2.0.0.
  217. *
  218. * \sa SDL_GameControllerAddMapping
  219. * \sa SDL_GameControllerMappingForGUID
  220. */
  221. extern DECLSPEC char * SDLCALL SDL_GameControllerMapping(SDL_GameController *gamecontroller);
  222. /**
  223. * Check if the given joystick is supported by the game controller interface.
  224. *
  225. * `joystick_index` is the same as the `device_index` passed to
  226. * SDL_JoystickOpen().
  227. *
  228. * \param joystick_index the device_index of a device, up to
  229. * SDL_NumJoysticks()
  230. * \returns SDL_TRUE if the given joystick is supported by the game controller
  231. * interface, SDL_FALSE if it isn't or it's an invalid index.
  232. *
  233. * \since This function is available since SDL 2.0.0.
  234. *
  235. * \sa SDL_GameControllerNameForIndex
  236. * \sa SDL_GameControllerOpen
  237. */
  238. extern DECLSPEC SDL_bool SDLCALL SDL_IsGameController(int joystick_index);
  239. /**
  240. * Get the implementation dependent name for the game controller.
  241. *
  242. * This function can be called before any controllers are opened.
  243. *
  244. * `joystick_index` is the same as the `device_index` passed to
  245. * SDL_JoystickOpen().
  246. *
  247. * \param joystick_index the device_index of a device, from zero to
  248. * SDL_NumJoysticks()-1
  249. * \returns the implementation-dependent name for the game controller, or NULL
  250. * if there is no name or the index is invalid.
  251. *
  252. * \since This function is available since SDL 2.0.0.
  253. *
  254. * \sa SDL_GameControllerName
  255. * \sa SDL_GameControllerOpen
  256. * \sa SDL_IsGameController
  257. */
  258. extern DECLSPEC const char *SDLCALL SDL_GameControllerNameForIndex(int joystick_index);
  259. /**
  260. * Get the type of a game controller.
  261. *
  262. * This can be called before any controllers are opened.
  263. *
  264. * \param joystick_index the device_index of a device, from zero to
  265. * SDL_NumJoysticks()-1
  266. * \returns the controller type.
  267. */
  268. extern DECLSPEC SDL_GameControllerType SDLCALL SDL_GameControllerTypeForIndex(int joystick_index);
  269. /**
  270. * Get the mapping of a game controller.
  271. *
  272. * This can be called before any controllers are opened.
  273. *
  274. * \param joystick_index the device_index of a device, from zero to
  275. * SDL_NumJoysticks()-1
  276. * \returns the mapping string. Must be freed with SDL_free(). Returns NULL if
  277. * no mapping is available.
  278. */
  279. extern DECLSPEC char *SDLCALL SDL_GameControllerMappingForDeviceIndex(int joystick_index);
  280. /**
  281. * Open a game controller for use.
  282. *
  283. * `joystick_index` is the same as the `device_index` passed to
  284. * SDL_JoystickOpen().
  285. *
  286. * The index passed as an argument refers to the N'th game controller on the
  287. * system. This index is not the value which will identify this controller in
  288. * future controller events. The joystick's instance id (SDL_JoystickID) will
  289. * be used there instead.
  290. *
  291. * \param joystick_index the device_index of a device, up to
  292. * SDL_NumJoysticks()
  293. * \returns a gamecontroller identifier or NULL if an error occurred; call
  294. * SDL_GetError() for more information.
  295. *
  296. * \since This function is available since SDL 2.0.0.
  297. *
  298. * \sa SDL_GameControllerClose
  299. * \sa SDL_GameControllerNameForIndex
  300. * \sa SDL_IsGameController
  301. */
  302. extern DECLSPEC SDL_GameController *SDLCALL SDL_GameControllerOpen(int joystick_index);
  303. /**
  304. * Get the SDL_GameController associated with an instance id.
  305. *
  306. * \param joyid the instance id to get the SDL_GameController for
  307. * \returns an SDL_GameController on success or NULL on failure; call
  308. * SDL_GetError() for more information.
  309. *
  310. * \since This function is available since SDL 2.0.4.
  311. */
  312. extern DECLSPEC SDL_GameController *SDLCALL SDL_GameControllerFromInstanceID(SDL_JoystickID joyid);
  313. /**
  314. * Get the SDL_GameController associated with a player index.
  315. *
  316. * Please note that the player index is _not_ the device index, nor is it the
  317. * instance id!
  318. *
  319. * \param player_index the player index, which is not the device index or the
  320. * instance id!
  321. * \returns the SDL_GameController associated with a player index.
  322. *
  323. * \sa SDL_GameControllerGetPlayerIndex
  324. * \sa SDL_GameControllerSetPlayerIndex
  325. */
  326. extern DECLSPEC SDL_GameController *SDLCALL SDL_GameControllerFromPlayerIndex(int player_index);
  327. /**
  328. * Get the implementation-dependent name for an opened game controller.
  329. *
  330. * This is the same name as returned by SDL_GameControllerNameForIndex(), but
  331. * it takes a controller identifier instead of the (unstable) device index.
  332. *
  333. * \param gamecontroller a game controller identifier previously returned by
  334. * SDL_GameControllerOpen()
  335. * \returns the implementation dependent name for the game controller, or NULL
  336. * if there is no name or the identifier passed is invalid.
  337. *
  338. * \since This function is available since SDL 2.0.0.
  339. *
  340. * \sa SDL_GameControllerNameForIndex
  341. * \sa SDL_GameControllerOpen
  342. */
  343. extern DECLSPEC const char *SDLCALL SDL_GameControllerName(SDL_GameController *gamecontroller);
  344. /**
  345. * Get the type of this currently opened controller
  346. *
  347. * This is the same name as returned by SDL_GameControllerTypeForIndex(), but
  348. * it takes a controller identifier instead of the (unstable) device index.
  349. *
  350. * \param gamecontroller the game controller object to query.
  351. * \returns the controller type.
  352. */
  353. extern DECLSPEC SDL_GameControllerType SDLCALL SDL_GameControllerGetType(SDL_GameController *gamecontroller);
  354. /**
  355. * Get the player index of an opened game controller.
  356. *
  357. * For XInput controllers this returns the XInput user index.
  358. *
  359. * \param gamecontroller the game controller object to query.
  360. * \returns the player index for controller, or -1 if it's not available.
  361. */
  362. extern DECLSPEC int SDLCALL SDL_GameControllerGetPlayerIndex(SDL_GameController *gamecontroller);
  363. /**
  364. * Set the player index of an opened game controller.
  365. *
  366. * \param gamecontroller the game controller object to adjust.
  367. * \param player_index Player index to assign to this controller.
  368. */
  369. extern DECLSPEC void SDLCALL SDL_GameControllerSetPlayerIndex(SDL_GameController *gamecontroller, int player_index);
  370. /**
  371. * Get the USB vendor ID of an opened controller, if available.
  372. *
  373. * If the vendor ID isn't available this function returns 0.
  374. *
  375. * \param gamecontroller the game controller object to query.
  376. * \return the USB vendor ID, or zero if unavailable.
  377. */
  378. extern DECLSPEC Uint16 SDLCALL SDL_GameControllerGetVendor(SDL_GameController *gamecontroller);
  379. /**
  380. * Get the USB product ID of an opened controller, if available.
  381. *
  382. * If the product ID isn't available this function returns 0.
  383. *
  384. * \param gamecontroller the game controller object to query.
  385. * \return the USB product ID, or zero if unavailable.
  386. */
  387. extern DECLSPEC Uint16 SDLCALL SDL_GameControllerGetProduct(SDL_GameController *gamecontroller);
  388. /**
  389. * Get the product version of an opened controller, if available.
  390. *
  391. * If the product version isn't available this function returns 0.
  392. *
  393. * \param gamecontroller the game controller object to query.
  394. * \return the USB product version, or zero if unavailable.
  395. */
  396. extern DECLSPEC Uint16 SDLCALL SDL_GameControllerGetProductVersion(SDL_GameController *gamecontroller);
  397. /**
  398. * Get the serial number of an opened controller, if available.
  399. *
  400. * Returns the serial number of the controller, or NULL if it is not
  401. * available.
  402. *
  403. * \param gamecontroller the game controller object to query.
  404. * \return the serial number, or NULL if unavailable.
  405. */
  406. extern DECLSPEC const char * SDLCALL SDL_GameControllerGetSerial(SDL_GameController *gamecontroller);
  407. /**
  408. * Check if a controller has been opened and is currently connected.
  409. *
  410. * \param gamecontroller a game controller identifier previously returned by
  411. * SDL_GameControllerOpen()
  412. * \returns SDL_TRUE if the controller has been opened and is currently
  413. * connected, or SDL_FALSE if not.
  414. *
  415. * \sa SDL_GameControllerClose
  416. * \sa SDL_GameControllerOpen
  417. */
  418. extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerGetAttached(SDL_GameController *gamecontroller);
  419. /**
  420. * Get the Joystick ID from a Game Controller.
  421. *
  422. * This function will give you a SDL_Joystick object, which allows you to use
  423. * the SDL_Joystick functions with a SDL_GameController object. This would be
  424. * useful for getting a joystick's position at any given time, even if it
  425. * hasn't moved (moving it would produce an event, which would have the axis'
  426. * value).
  427. *
  428. * The pointer returned is owned by the SDL_GameController. You should not
  429. * call SDL_JoystickClose() on it, for example, since doing so will likely
  430. * cause SDL to crash.
  431. *
  432. * \param gamecontroller the game controller object that you want to get a
  433. * joystick from
  434. * \returns a SDL_Joystick object; call SDL_GetError() for more information.
  435. */
  436. extern DECLSPEC SDL_Joystick *SDLCALL SDL_GameControllerGetJoystick(SDL_GameController *gamecontroller);
  437. /**
  438. * Query or change current state of Game Controller events.
  439. *
  440. * If controller events are disabled, you must call SDL_GameControllerUpdate()
  441. * yourself and check the state of the controller when you want controller
  442. * information.
  443. *
  444. * Any number can be passed to SDL_GameControllerEventState(), but only -1, 0,
  445. * and 1 will have any effect. Other numbers will just be returned.
  446. *
  447. * \param state can be one of `SDL_QUERY`, `SDL_IGNORE`, or `SDL_ENABLE`
  448. * \returns the same value passed to the function, with exception to -1
  449. * (SDL_QUERY), which will return the current state.
  450. *
  451. * \since This function is available since SDL 2.0.0.
  452. *
  453. * \sa SDL_JoystickEventState
  454. */
  455. extern DECLSPEC int SDLCALL SDL_GameControllerEventState(int state);
  456. /**
  457. * Manually pump game controller updates if not using the loop.
  458. *
  459. * This function is called automatically by the event loop if events are
  460. * enabled. Under such circumstances, it will not be necessary to call this
  461. * function.
  462. */
  463. extern DECLSPEC void SDLCALL SDL_GameControllerUpdate(void);
  464. /**
  465. * The list of axes available from a controller
  466. *
  467. * Thumbstick axis values range from SDL_JOYSTICK_AXIS_MIN to SDL_JOYSTICK_AXIS_MAX,
  468. * and are centered within ~8000 of zero, though advanced UI will allow users to set
  469. * or autodetect the dead zone, which varies between controllers.
  470. *
  471. * Trigger axis values range from 0 to SDL_JOYSTICK_AXIS_MAX.
  472. */
  473. typedef enum
  474. {
  475. SDL_CONTROLLER_AXIS_INVALID = -1,
  476. SDL_CONTROLLER_AXIS_LEFTX,
  477. SDL_CONTROLLER_AXIS_LEFTY,
  478. SDL_CONTROLLER_AXIS_RIGHTX,
  479. SDL_CONTROLLER_AXIS_RIGHTY,
  480. SDL_CONTROLLER_AXIS_TRIGGERLEFT,
  481. SDL_CONTROLLER_AXIS_TRIGGERRIGHT,
  482. SDL_CONTROLLER_AXIS_MAX
  483. } SDL_GameControllerAxis;
  484. /**
  485. * Convert a string into SDL_GameControllerAxis enum.
  486. *
  487. * This function is called internally to translate SDL_GameController mapping
  488. * strings for the underlying joystick device into the consistent
  489. * SDL_GameController mapping. You do not normally need to call this function
  490. * unless you are parsing SDL_GameController mappings in your own code.
  491. *
  492. * Note specially that "righttrigger" and "lefttrigger" map to
  493. * `SDL_CONTROLLER_AXIS_TRIGGERRIGHT` and `SDL_CONTROLLER_AXIS_TRIGGERLEFT`,
  494. * respectively.
  495. *
  496. * \param str string representing a SDL_GameController axis
  497. * \returns the SDL_GameControllerAxis enum corresponding to the input string,
  498. * or `SDL_CONTROLLER_AXIS_INVALID` if no match was found.
  499. *
  500. * \sa SDL_GameControllerGetStringForAxis
  501. */
  502. extern DECLSPEC SDL_GameControllerAxis SDLCALL SDL_GameControllerGetAxisFromString(const char *str);
  503. /**
  504. * Convert from an SDL_GameControllerAxis enum to a string.
  505. *
  506. * The caller should not SDL_free() the returned string.
  507. *
  508. * \param axis an enum value for a given SDL_GameControllerAxis
  509. * \returns a string for the given axis, or NULL if an invalid axis is
  510. * specified. The string returned is of the format used by
  511. * SDL_GameController mapping strings.
  512. *
  513. * \sa SDL_GameControllerGetAxisFromString
  514. */
  515. extern DECLSPEC const char* SDLCALL SDL_GameControllerGetStringForAxis(SDL_GameControllerAxis axis);
  516. /**
  517. * Get the SDL joystick layer binding for a controller axis mapping.
  518. *
  519. * \param gamecontroller a game controller
  520. * \param axis an axis enum value (one of the SDL_GameControllerAxis values)
  521. * \returns a SDL_GameControllerButtonBind describing the bind. On failure
  522. * (like the given Controller axis doesn't exist on the device), its
  523. * `.bindType` will be `SDL_CONTROLLER_BINDTYPE_NONE`.
  524. *
  525. * \since This function is available since SDL 2.0.0.
  526. *
  527. * \sa SDL_GameControllerGetBindForButton
  528. */
  529. extern DECLSPEC SDL_GameControllerButtonBind SDLCALL
  530. SDL_GameControllerGetBindForAxis(SDL_GameController *gamecontroller,
  531. SDL_GameControllerAxis axis);
  532. /**
  533. * Query whether a game controller has a given axis.
  534. *
  535. * This merely reports whether the controller's mapping defined this axis, as
  536. * that is all the information SDL has about the physical device.
  537. *
  538. * \param gamecontroller a game controller
  539. * \param axis an axis enum value (an SDL_GameControllerAxis value)
  540. * \returns SDL_TRUE if the controller has this axis, SDL_FALSE otherwise.
  541. */
  542. extern DECLSPEC SDL_bool SDLCALL
  543. SDL_GameControllerHasAxis(SDL_GameController *gamecontroller, SDL_GameControllerAxis axis);
  544. /**
  545. * Get the current state of an axis control on a game controller.
  546. *
  547. * The axis indices start at index 0.
  548. *
  549. * The state is a value ranging from -32768 to 32767. Triggers, however, range
  550. * from 0 to 32767 (they never return a negative value).
  551. *
  552. * \param gamecontroller a game controller
  553. * \param axis an axis index (one of the SDL_GameControllerAxis values)
  554. * \returns axis state (including 0) on success or 0 (also) on failure; call
  555. * SDL_GetError() for more information.
  556. *
  557. * \since This function is available since SDL 2.0.0.
  558. *
  559. * \sa SDL_GameControllerGetButton
  560. */
  561. extern DECLSPEC Sint16 SDLCALL
  562. SDL_GameControllerGetAxis(SDL_GameController *gamecontroller, SDL_GameControllerAxis axis);
  563. /**
  564. * The list of buttons available from a controller
  565. */
  566. typedef enum
  567. {
  568. SDL_CONTROLLER_BUTTON_INVALID = -1,
  569. SDL_CONTROLLER_BUTTON_A,
  570. SDL_CONTROLLER_BUTTON_B,
  571. SDL_CONTROLLER_BUTTON_X,
  572. SDL_CONTROLLER_BUTTON_Y,
  573. SDL_CONTROLLER_BUTTON_BACK,
  574. SDL_CONTROLLER_BUTTON_GUIDE,
  575. SDL_CONTROLLER_BUTTON_START,
  576. SDL_CONTROLLER_BUTTON_LEFTSTICK,
  577. SDL_CONTROLLER_BUTTON_RIGHTSTICK,
  578. SDL_CONTROLLER_BUTTON_LEFTSHOULDER,
  579. SDL_CONTROLLER_BUTTON_RIGHTSHOULDER,
  580. SDL_CONTROLLER_BUTTON_DPAD_UP,
  581. SDL_CONTROLLER_BUTTON_DPAD_DOWN,
  582. SDL_CONTROLLER_BUTTON_DPAD_LEFT,
  583. SDL_CONTROLLER_BUTTON_DPAD_RIGHT,
  584. SDL_CONTROLLER_BUTTON_MISC1, /* Xbox Series X share button, PS5 microphone button, Nintendo Switch Pro capture button, Amazon Luna microphone button */
  585. SDL_CONTROLLER_BUTTON_PADDLE1, /* Xbox Elite paddle P1 */
  586. SDL_CONTROLLER_BUTTON_PADDLE2, /* Xbox Elite paddle P3 */
  587. SDL_CONTROLLER_BUTTON_PADDLE3, /* Xbox Elite paddle P2 */
  588. SDL_CONTROLLER_BUTTON_PADDLE4, /* Xbox Elite paddle P4 */
  589. SDL_CONTROLLER_BUTTON_TOUCHPAD, /* PS4/PS5 touchpad button */
  590. SDL_CONTROLLER_BUTTON_MAX
  591. } SDL_GameControllerButton;
  592. /**
  593. * Convert a string into an SDL_GameControllerButton enum.
  594. *
  595. * This function is called internally to translate SDL_GameController mapping
  596. * strings for the underlying joystick device into the consistent
  597. * SDL_GameController mapping. You do not normally need to call this function
  598. * unless you are parsing SDL_GameController mappings in your own code.
  599. *
  600. * \param str string representing a SDL_GameController axis
  601. * \returns the SDL_GameControllerButton enum corresponding to the input
  602. * string, or `SDL_CONTROLLER_AXIS_INVALID` if no match was found.
  603. */
  604. extern DECLSPEC SDL_GameControllerButton SDLCALL SDL_GameControllerGetButtonFromString(const char *str);
  605. /**
  606. * Convert from an SDL_GameControllerButton enum to a string.
  607. *
  608. * The caller should not SDL_free() the returned string.
  609. *
  610. * \param button an enum value for a given SDL_GameControllerButton
  611. * \returns a string for the given button, or NULL if an invalid axis is
  612. * specified. The string returned is of the format used by
  613. * SDL_GameController mapping strings.
  614. *
  615. * \since This function is available since SDL 2.0.0.
  616. *
  617. * \sa SDL_GameControllerGetButtonFromString
  618. */
  619. extern DECLSPEC const char* SDLCALL SDL_GameControllerGetStringForButton(SDL_GameControllerButton button);
  620. /**
  621. * Get the SDL joystick layer binding for a controller button mapping.
  622. *
  623. * \param gamecontroller a game controller
  624. * \param button an button enum value (an SDL_GameControllerButton value)
  625. * \returns a SDL_GameControllerButtonBind describing the bind. On failure
  626. * (like the given Controller button doesn't exist on the device),
  627. * its `.bindType` will be `SDL_CONTROLLER_BINDTYPE_NONE`.
  628. *
  629. * \since This function is available since SDL 2.0.0.
  630. *
  631. * \sa SDL_GameControllerGetBindForAxis
  632. */
  633. extern DECLSPEC SDL_GameControllerButtonBind SDLCALL
  634. SDL_GameControllerGetBindForButton(SDL_GameController *gamecontroller,
  635. SDL_GameControllerButton button);
  636. /**
  637. * Query whether a game controller has a given button.
  638. *
  639. * This merely reports whether the controller's mapping defined this button,
  640. * as that is all the information SDL has about the physical device.
  641. *
  642. * \param gamecontroller a game controller
  643. * \param button a button enum value (an SDL_GameControllerButton value)
  644. * \returns SDL_TRUE if the controller has this button, SDL_FALSE otherwise.
  645. */
  646. extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerHasButton(SDL_GameController *gamecontroller,
  647. SDL_GameControllerButton button);
  648. /**
  649. * Get the current state of a button on a game controller.
  650. *
  651. * \param gamecontroller a game controller
  652. * \param button a button index (one of the SDL_GameControllerButton values)
  653. * \returns 1 for pressed state or 0 for not pressed state or error; call
  654. * SDL_GetError() for more information.
  655. *
  656. * \since This function is available since SDL 2.0.0.
  657. *
  658. * \sa SDL_GameControllerGetAxis
  659. */
  660. extern DECLSPEC Uint8 SDLCALL SDL_GameControllerGetButton(SDL_GameController *gamecontroller,
  661. SDL_GameControllerButton button);
  662. /**
  663. * Get the number of touchpads on a game controller.
  664. */
  665. extern DECLSPEC int SDLCALL SDL_GameControllerGetNumTouchpads(SDL_GameController *gamecontroller);
  666. /**
  667. * Get the number of supported simultaneous fingers on a touchpad on a game
  668. * controller.
  669. */
  670. extern DECLSPEC int SDLCALL SDL_GameControllerGetNumTouchpadFingers(SDL_GameController *gamecontroller, int touchpad);
  671. /**
  672. * Get the current state of a finger on a touchpad on a game controller.
  673. */
  674. extern DECLSPEC int SDLCALL SDL_GameControllerGetTouchpadFinger(SDL_GameController *gamecontroller, int touchpad, int finger, Uint8 *state, float *x, float *y, float *pressure);
  675. /**
  676. * Return whether a game controller has a particular sensor.
  677. *
  678. * \param gamecontroller The controller to query
  679. * \param type The type of sensor to query
  680. * \returns SDL_TRUE if the sensor exists, SDL_FALSE otherwise.
  681. */
  682. extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerHasSensor(SDL_GameController *gamecontroller, SDL_SensorType type);
  683. /**
  684. * Set whether data reporting for a game controller sensor is enabled.
  685. *
  686. * \param gamecontroller The controller to update
  687. * \param type The type of sensor to enable/disable
  688. * \param enabled Whether data reporting should be enabled
  689. * \returns 0 or -1 if an error occurred.
  690. */
  691. extern DECLSPEC int SDLCALL SDL_GameControllerSetSensorEnabled(SDL_GameController *gamecontroller, SDL_SensorType type, SDL_bool enabled);
  692. /**
  693. * Query whether sensor data reporting is enabled for a game controller.
  694. *
  695. * \param gamecontroller The controller to query
  696. * \param type The type of sensor to query
  697. * \returns SDL_TRUE if the sensor is enabled, SDL_FALSE otherwise.
  698. */
  699. extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerIsSensorEnabled(SDL_GameController *gamecontroller, SDL_SensorType type);
  700. /**
  701. * Get the data rate (number of events per second) of a game controller
  702. * sensor.
  703. *
  704. * \param gamecontroller The controller to query
  705. * \param type The type of sensor to query
  706. * \return the data rate, or 0.0f if the data rate is not available.
  707. */
  708. extern DECLSPEC float SDLCALL SDL_GameControllerGetSensorDataRate(SDL_GameController *gamecontroller, SDL_SensorType type);
  709. /**
  710. * Get the current state of a game controller sensor.
  711. *
  712. * The number of values and interpretation of the data is sensor dependent.
  713. * See SDL_sensor.h for the details for each type of sensor.
  714. *
  715. * \param gamecontroller The controller to query
  716. * \param type The type of sensor to query
  717. * \param data A pointer filled with the current sensor state
  718. * \param num_values The number of values to write to data
  719. * \return 0 or -1 if an error occurred.
  720. */
  721. extern DECLSPEC int SDLCALL SDL_GameControllerGetSensorData(SDL_GameController *gamecontroller, SDL_SensorType type, float *data, int num_values);
  722. /**
  723. * Start a rumble effect on a game controller.
  724. *
  725. * Each call to this function cancels any previous rumble effect, and calling
  726. * it with 0 intensity stops any rumbling.
  727. *
  728. * \param gamecontroller The controller to vibrate
  729. * \param low_frequency_rumble The intensity of the low frequency (left)
  730. * rumble motor, from 0 to 0xFFFF
  731. * \param high_frequency_rumble The intensity of the high frequency (right)
  732. * rumble motor, from 0 to 0xFFFF
  733. * \param duration_ms The duration of the rumble effect, in milliseconds
  734. * \returns 0, or -1 if rumble isn't supported on this controller
  735. */
  736. extern DECLSPEC int SDLCALL SDL_GameControllerRumble(SDL_GameController *gamecontroller, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
  737. /**
  738. * Start a rumble effect in the game controller's triggers.
  739. *
  740. * Each call to this function cancels any previous trigger rumble effect, and
  741. * calling it with 0 intensity stops any rumbling.
  742. *
  743. * Note that this is rumbling of the _triggers_ and not the game controller as
  744. * a whole. The first controller to offer this feature was the PlayStation 5's
  745. * DualShock 5.
  746. *
  747. * \param gamecontroller The controller to vibrate
  748. * \param left_rumble The intensity of the left trigger rumble motor, from 0
  749. * to 0xFFFF
  750. * \param right_rumble The intensity of the right trigger rumble motor, from 0
  751. * to 0xFFFF
  752. * \param duration_ms The duration of the rumble effect, in milliseconds
  753. * \returns 0, or -1 if trigger rumble isn't supported on this controller
  754. */
  755. extern DECLSPEC int SDLCALL SDL_GameControllerRumbleTriggers(SDL_GameController *gamecontroller, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms);
  756. /**
  757. * Query whether a game controller has an LED.
  758. *
  759. * \param gamecontroller The controller to query
  760. * \returns SDL_TRUE, or SDL_FALSE if this controller does not have a
  761. * modifiable LED
  762. */
  763. extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerHasLED(SDL_GameController *gamecontroller);
  764. /**
  765. * Update a game controller's LED color.
  766. *
  767. * \param gamecontroller The controller to update
  768. * \param red The intensity of the red LED
  769. * \param green The intensity of the green LED
  770. * \param blue The intensity of the blue LED
  771. * \returns 0, or -1 if this controller does not have a modifiable LED
  772. */
  773. extern DECLSPEC int SDLCALL SDL_GameControllerSetLED(SDL_GameController *gamecontroller, Uint8 red, Uint8 green, Uint8 blue);
  774. /**
  775. * Send a controller specific effect packet
  776. *
  777. * \param gamecontroller The controller to affect
  778. * \param data The data to send to the controller
  779. * \param size The size of the data to send to the controller
  780. * \returns 0, or -1 if this controller or driver doesn't support effect
  781. * packets
  782. */
  783. extern DECLSPEC int SDLCALL SDL_GameControllerSendEffect(SDL_GameController *gamecontroller, const void *data, int size);
  784. /**
  785. * Close a game controller previously opened with SDL_GameControllerOpen().
  786. *
  787. * \param gamecontroller a game controller identifier previously returned by
  788. * SDL_GameControllerOpen()
  789. *
  790. * \sa SDL_GameControllerOpen
  791. */
  792. extern DECLSPEC void SDLCALL SDL_GameControllerClose(SDL_GameController *gamecontroller);
  793. /* Ends C function definitions when using C++ */
  794. #ifdef __cplusplus
  795. }
  796. #endif
  797. #include "close_code.h"
  798. #endif /* SDL_gamecontroller_h_ */
  799. /* vi: set ts=4 sw=4 expandtab: */