SDL_gamecontroller.h 31 KB

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