SDL_gamepad.h 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <[email protected]>
  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_gamepad.h
  20. *
  21. * Include file for SDL gamepad event handling
  22. */
  23. #ifndef SDL_gamepad_h_
  24. #define SDL_gamepad_h_
  25. #include <SDL3/SDL_stdinc.h>
  26. #include <SDL3/SDL_error.h>
  27. #include <SDL3/SDL_joystick.h>
  28. #include <SDL3/SDL_properties.h>
  29. #include <SDL3/SDL_rwops.h>
  30. #include <SDL3/SDL_sensor.h>
  31. #include <SDL3/SDL_begin_code.h>
  32. /* Set up for C function definitions, even when using C++ */
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /**
  37. * \file SDL_gamepad.h
  38. *
  39. * In order to use these functions, SDL_Init() must have been called
  40. * with the ::SDL_INIT_GAMEPAD flag. This causes SDL to scan the system
  41. * for gamepads, and load appropriate drivers.
  42. *
  43. * If you would like to receive gamepad updates while the application
  44. * is in the background, you should set the following hint before calling
  45. * SDL_Init(): SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS
  46. */
  47. /**
  48. * The structure used to identify an SDL gamepad
  49. */
  50. struct SDL_Gamepad;
  51. typedef struct SDL_Gamepad SDL_Gamepad;
  52. typedef enum
  53. {
  54. SDL_GAMEPAD_TYPE_UNKNOWN = 0,
  55. SDL_GAMEPAD_TYPE_STANDARD,
  56. SDL_GAMEPAD_TYPE_XBOX360,
  57. SDL_GAMEPAD_TYPE_XBOXONE,
  58. SDL_GAMEPAD_TYPE_PS3,
  59. SDL_GAMEPAD_TYPE_PS4,
  60. SDL_GAMEPAD_TYPE_PS5,
  61. SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_PRO,
  62. SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_LEFT,
  63. SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT,
  64. SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_PAIR,
  65. SDL_GAMEPAD_TYPE_MAX
  66. } SDL_GamepadType;
  67. /**
  68. * The list of buttons available on a gamepad
  69. *
  70. * For controllers that use a diamond pattern for the face buttons,
  71. * the south/east/west/north buttons below correspond to the locations
  72. * in the diamond pattern. For Xbox controllers, this would be A/B/X/Y,
  73. * for Nintendo Switch controllers, this would be B/A/Y/X, for
  74. * PlayStation controllers this would be Cross/Circle/Square/Triangle.
  75. *
  76. * For controllers that don't use a diamond pattern for the face buttons,
  77. * the south/east/west/north buttons indicate the buttons labeled A, B,
  78. * C, D, or 1, 2, 3, 4, or for controllers that aren't labeled, they are
  79. * the primary, secondary, etc. buttons.
  80. *
  81. * The activate action is often the south button and the cancel action
  82. * is often the east button, but in some regions this is reversed, so
  83. * your game should allow remapping actions based on user preferences.
  84. *
  85. * You can query the labels for the face buttons using SDL_GetGamepadButtonLabel()
  86. */
  87. typedef enum
  88. {
  89. SDL_GAMEPAD_BUTTON_INVALID = -1,
  90. SDL_GAMEPAD_BUTTON_SOUTH, /* Bottom face button (e.g. Xbox A button) */
  91. SDL_GAMEPAD_BUTTON_EAST, /* Right face button (e.g. Xbox B button) */
  92. SDL_GAMEPAD_BUTTON_WEST, /* Left face button (e.g. Xbox X button) */
  93. SDL_GAMEPAD_BUTTON_NORTH, /* Top face button (e.g. Xbox Y button) */
  94. SDL_GAMEPAD_BUTTON_BACK,
  95. SDL_GAMEPAD_BUTTON_GUIDE,
  96. SDL_GAMEPAD_BUTTON_START,
  97. SDL_GAMEPAD_BUTTON_LEFT_STICK,
  98. SDL_GAMEPAD_BUTTON_RIGHT_STICK,
  99. SDL_GAMEPAD_BUTTON_LEFT_SHOULDER,
  100. SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER,
  101. SDL_GAMEPAD_BUTTON_DPAD_UP,
  102. SDL_GAMEPAD_BUTTON_DPAD_DOWN,
  103. SDL_GAMEPAD_BUTTON_DPAD_LEFT,
  104. SDL_GAMEPAD_BUTTON_DPAD_RIGHT,
  105. SDL_GAMEPAD_BUTTON_MISC1, /* Additional button (e.g. Xbox Series X share button, PS5 microphone button, Nintendo Switch Pro capture button, Amazon Luna microphone button) */
  106. SDL_GAMEPAD_BUTTON_RIGHT_PADDLE1, /* Upper or primary paddle, under your right hand (e.g. Xbox Elite paddle P1) */
  107. SDL_GAMEPAD_BUTTON_LEFT_PADDLE1, /* Upper or primary paddle, under your left hand (e.g. Xbox Elite paddle P3) */
  108. SDL_GAMEPAD_BUTTON_RIGHT_PADDLE2, /* Lower or secondary paddle, under your right hand (e.g. Xbox Elite paddle P2) */
  109. SDL_GAMEPAD_BUTTON_LEFT_PADDLE2, /* Lower or secondary paddle, under your left hand (e.g. Xbox Elite paddle P4) */
  110. SDL_GAMEPAD_BUTTON_TOUCHPAD, /* PS4/PS5 touchpad button */
  111. SDL_GAMEPAD_BUTTON_MAX
  112. } SDL_GamepadButton;
  113. /**
  114. * The set of gamepad button labels
  115. *
  116. * This isn't a complete set, just the face buttons to make it easy to show button prompts.
  117. *
  118. * For a complete set, you should look at the button and gamepad type and have a set of symbols that work well with your art style.
  119. */
  120. typedef enum
  121. {
  122. SDL_GAMEPAD_BUTTON_LABEL_UNKNOWN,
  123. SDL_GAMEPAD_BUTTON_LABEL_A,
  124. SDL_GAMEPAD_BUTTON_LABEL_B,
  125. SDL_GAMEPAD_BUTTON_LABEL_X,
  126. SDL_GAMEPAD_BUTTON_LABEL_Y,
  127. SDL_GAMEPAD_BUTTON_LABEL_CROSS,
  128. SDL_GAMEPAD_BUTTON_LABEL_CIRCLE,
  129. SDL_GAMEPAD_BUTTON_LABEL_SQUARE,
  130. SDL_GAMEPAD_BUTTON_LABEL_TRIANGLE
  131. } SDL_GamepadButtonLabel;
  132. /**
  133. * The list of axes available on a gamepad
  134. *
  135. * Thumbstick axis values range from SDL_JOYSTICK_AXIS_MIN to SDL_JOYSTICK_AXIS_MAX,
  136. * and are centered within ~8000 of zero, though advanced UI will allow users to set
  137. * or autodetect the dead zone, which varies between gamepads.
  138. *
  139. * Trigger axis values range from 0 (released) to SDL_JOYSTICK_AXIS_MAX
  140. * (fully pressed) when reported by SDL_GetGamepadAxis(). Note that this is not the
  141. * same range that will be reported by the lower-level SDL_GetJoystickAxis().
  142. */
  143. typedef enum
  144. {
  145. SDL_GAMEPAD_AXIS_INVALID = -1,
  146. SDL_GAMEPAD_AXIS_LEFTX,
  147. SDL_GAMEPAD_AXIS_LEFTY,
  148. SDL_GAMEPAD_AXIS_RIGHTX,
  149. SDL_GAMEPAD_AXIS_RIGHTY,
  150. SDL_GAMEPAD_AXIS_LEFT_TRIGGER,
  151. SDL_GAMEPAD_AXIS_RIGHT_TRIGGER,
  152. SDL_GAMEPAD_AXIS_MAX
  153. } SDL_GamepadAxis;
  154. typedef enum
  155. {
  156. SDL_GAMEPAD_BINDTYPE_NONE = 0,
  157. SDL_GAMEPAD_BINDTYPE_BUTTON,
  158. SDL_GAMEPAD_BINDTYPE_AXIS,
  159. SDL_GAMEPAD_BINDTYPE_HAT
  160. } SDL_GamepadBindingType;
  161. typedef struct
  162. {
  163. SDL_GamepadBindingType inputType;
  164. union
  165. {
  166. int button;
  167. struct
  168. {
  169. int axis;
  170. int axis_min;
  171. int axis_max;
  172. } axis;
  173. struct
  174. {
  175. int hat;
  176. int hat_mask;
  177. } hat;
  178. } input;
  179. SDL_GamepadBindingType outputType;
  180. union
  181. {
  182. SDL_GamepadButton button;
  183. struct
  184. {
  185. SDL_GamepadAxis axis;
  186. int axis_min;
  187. int axis_max;
  188. } axis;
  189. } output;
  190. } SDL_GamepadBinding;
  191. /**
  192. * Add support for gamepads that SDL is unaware of or change the binding of an
  193. * existing gamepad.
  194. *
  195. * The mapping string has the format "GUID,name,mapping", where GUID is the
  196. * string value from SDL_GetJoystickGUIDString(), name is the human readable
  197. * string for the device and mappings are gamepad mappings to joystick ones.
  198. * Under Windows there is a reserved GUID of "xinput" that covers all XInput
  199. * devices. The mapping format for joystick is:
  200. *
  201. * - `bX`: a joystick button, index X
  202. * - `hX.Y`: hat X with value Y
  203. * - `aX`: axis X of the joystick
  204. *
  205. * Buttons can be used as a gamepad axes and vice versa.
  206. *
  207. * This string shows an example of a valid mapping for a gamepad:
  208. *
  209. * ```c
  210. * "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"
  211. * ```
  212. *
  213. * \param mapping the mapping string
  214. * \returns 1 if a new mapping is added, 0 if an existing mapping is updated,
  215. * -1 on error; call SDL_GetError() for more information.
  216. *
  217. * \since This function is available since SDL 3.0.0.
  218. *
  219. * \sa SDL_GetGamepadMapping
  220. * \sa SDL_GetGamepadMappingForGUID
  221. */
  222. extern DECLSPEC int SDLCALL SDL_AddGamepadMapping(const char *mapping);
  223. /**
  224. * Load a set of gamepad mappings from a seekable SDL data stream.
  225. *
  226. * You can call this function several times, if needed, to load different
  227. * database files.
  228. *
  229. * If a new mapping is loaded for an already known gamepad GUID, the later
  230. * version will overwrite the one currently loaded.
  231. *
  232. * Mappings not belonging to the current platform or with no platform field
  233. * specified will be ignored (i.e. mappings for Linux will be ignored in
  234. * Windows, etc).
  235. *
  236. * This function will load the text database entirely in memory before
  237. * processing it, so take this into consideration if you are in a memory
  238. * constrained environment.
  239. *
  240. * \param src the data stream for the mappings to be added
  241. * \param freesrc if SDL_TRUE, calls SDL_RWclose() on `src` before returning,
  242. * even in the case of an error
  243. * \returns the number of mappings added or -1 on error; call SDL_GetError()
  244. * for more information.
  245. *
  246. * \since This function is available since SDL 3.0.0.
  247. *
  248. * \sa SDL_AddGamepadMapping
  249. * \sa SDL_AddGamepadMappingsFromFile
  250. * \sa SDL_GetGamepadMappingForGUID
  251. */
  252. extern DECLSPEC int SDLCALL SDL_AddGamepadMappingsFromRW(SDL_RWops *src, SDL_bool freesrc);
  253. /**
  254. * Load a set of gamepad mappings from a file.
  255. *
  256. * You can call this function several times, if needed, to load different
  257. * database files.
  258. *
  259. * If a new mapping is loaded for an already known gamepad GUID, the later
  260. * version will overwrite the one currently loaded.
  261. *
  262. * Mappings not belonging to the current platform or with no platform field
  263. * specified will be ignored (i.e. mappings for Linux will be ignored in
  264. * Windows, etc).
  265. *
  266. * \param file the mappings file to load
  267. * \returns the number of mappings added or -1 on error; call SDL_GetError()
  268. * for more information.
  269. *
  270. * \since This function is available since SDL 3.0.0.
  271. *
  272. * \sa SDL_AddGamepadMapping
  273. * \sa SDL_AddGamepadMappingsFromRW
  274. * \sa SDL_GetGamepadMappingForGUID
  275. */
  276. extern DECLSPEC int SDLCALL SDL_AddGamepadMappingsFromFile(const char *file);
  277. /**
  278. * Reinitialize the SDL mapping database to its initial state.
  279. *
  280. * This will generate gamepad events as needed if device mappings change.
  281. *
  282. * \returns 0 on success or a negative error code on failure; call
  283. * SDL_GetError() for more information.
  284. *
  285. * \since This function is available since SDL 3.0.0.
  286. */
  287. extern DECLSPEC int SDLCALL SDL_ReloadGamepadMappings(void);
  288. /**
  289. * Get the mapping at a particular index.
  290. *
  291. * You must free the returned pointer with SDL_free() when you are done with
  292. * it, but you do _not_ free each string in the array.
  293. *
  294. * \param count a pointer filled in with the number of mappings returned, can
  295. * be NULL.
  296. * \returns an array of the mapping strings, NULL-terminated. Must be freed
  297. * with SDL_free(). Returns NULL on error.
  298. *
  299. * \since This function is available since SDL 3.0.0.
  300. */
  301. extern DECLSPEC char ** SDLCALL SDL_GetGamepadMappings(int *count);
  302. /**
  303. * Get the gamepad mapping string for a given GUID.
  304. *
  305. * The returned string must be freed with SDL_free().
  306. *
  307. * \param guid a structure containing the GUID for which a mapping is desired
  308. * \returns a mapping string or NULL on error; call SDL_GetError() for more
  309. * information.
  310. *
  311. * \since This function is available since SDL 3.0.0.
  312. *
  313. * \sa SDL_GetJoystickInstanceGUID
  314. * \sa SDL_GetJoystickGUID
  315. */
  316. extern DECLSPEC char * SDLCALL SDL_GetGamepadMappingForGUID(SDL_JoystickGUID guid);
  317. /**
  318. * Get the current mapping of a gamepad.
  319. *
  320. * The returned string must be freed with SDL_free().
  321. *
  322. * Details about mappings are discussed with SDL_AddGamepadMapping().
  323. *
  324. * \param gamepad the gamepad you want to get the current mapping for
  325. * \returns a string that has the gamepad's mapping or NULL if no mapping is
  326. * available; call SDL_GetError() for more information.
  327. *
  328. * \since This function is available since SDL 3.0.0.
  329. *
  330. * \sa SDL_AddGamepadMapping
  331. * \sa SDL_GetGamepadMappingForGUID
  332. * \sa SDL_SetGamepadMapping
  333. */
  334. extern DECLSPEC char * SDLCALL SDL_GetGamepadMapping(SDL_Gamepad *gamepad);
  335. /**
  336. * Set the current mapping of a joystick or gamepad.
  337. *
  338. * Details about mappings are discussed with SDL_AddGamepadMapping().
  339. *
  340. * \param instance_id the joystick instance ID
  341. * \param mapping the mapping to use for this device, or NULL to clear the
  342. * mapping
  343. * \returns 0 on success or a negative error code on failure; call
  344. * SDL_GetError() for more information.
  345. *
  346. * \since This function is available since SDL 3.0.0.
  347. *
  348. * \sa SDL_AddGamepadMapping
  349. * \sa SDL_GetGamepadMapping
  350. */
  351. extern DECLSPEC int SDLCALL SDL_SetGamepadMapping(SDL_JoystickID instance_id, const char *mapping);
  352. /**
  353. * Get a list of currently connected gamepads.
  354. *
  355. * \param count a pointer filled in with the number of gamepads returned
  356. * \returns a 0 terminated array of joystick instance IDs which should be
  357. * freed with SDL_free(), or NULL on error; call SDL_GetError() for
  358. * more details.
  359. *
  360. * \since This function is available since SDL 3.0.0.
  361. *
  362. * \sa SDL_OpenGamepad
  363. */
  364. extern DECLSPEC SDL_JoystickID *SDLCALL SDL_GetGamepads(int *count);
  365. /**
  366. * Check if the given joystick is supported by the gamepad interface.
  367. *
  368. * \param instance_id the joystick instance ID
  369. * \returns SDL_TRUE if the given joystick is supported by the gamepad
  370. * interface, SDL_FALSE if it isn't or it's an invalid index.
  371. *
  372. * \since This function is available since SDL 3.0.0.
  373. *
  374. * \sa SDL_OpenGamepad
  375. */
  376. extern DECLSPEC SDL_bool SDLCALL SDL_IsGamepad(SDL_JoystickID instance_id);
  377. /**
  378. * Get the implementation dependent name of a gamepad.
  379. *
  380. * This can be called before any gamepads are opened.
  381. *
  382. * \param instance_id the joystick instance ID
  383. * \returns the name of the selected gamepad. If no name can be found, this
  384. * function returns NULL; call SDL_GetError() for more information.
  385. *
  386. * \since This function is available since SDL 3.0.0.
  387. *
  388. * \sa SDL_GetGamepadName
  389. * \sa SDL_OpenGamepad
  390. */
  391. extern DECLSPEC const char *SDLCALL SDL_GetGamepadInstanceName(SDL_JoystickID instance_id);
  392. /**
  393. * Get the implementation dependent path of a gamepad.
  394. *
  395. * This can be called before any gamepads are opened.
  396. *
  397. * \param instance_id the joystick instance ID
  398. * \returns the path of the selected gamepad. If no path can be found, this
  399. * function returns NULL; call SDL_GetError() for more information.
  400. *
  401. * \since This function is available since SDL 3.0.0.
  402. *
  403. * \sa SDL_GetGamepadPath
  404. * \sa SDL_OpenGamepad
  405. */
  406. extern DECLSPEC const char *SDLCALL SDL_GetGamepadInstancePath(SDL_JoystickID instance_id);
  407. /**
  408. * Get the player index of a gamepad.
  409. *
  410. * This can be called before any gamepads are opened.
  411. *
  412. * \param instance_id the joystick instance ID
  413. * \returns the player index of a gamepad, or -1 if it's not available
  414. *
  415. * \since This function is available since SDL 3.0.0.
  416. *
  417. * \sa SDL_GetGamepadPlayerIndex
  418. * \sa SDL_OpenGamepad
  419. */
  420. extern DECLSPEC int SDLCALL SDL_GetGamepadInstancePlayerIndex(SDL_JoystickID instance_id);
  421. /**
  422. * Get the implementation-dependent GUID of a gamepad.
  423. *
  424. * This can be called before any gamepads are opened.
  425. *
  426. * \param instance_id the joystick instance ID
  427. * \returns the GUID of the selected gamepad. If called on an invalid index,
  428. * this function returns a zero GUID
  429. *
  430. * \since This function is available since SDL 3.0.0.
  431. *
  432. * \sa SDL_GetGamepadGUID
  433. * \sa SDL_GetGamepadGUIDString
  434. */
  435. extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_GetGamepadInstanceGUID(SDL_JoystickID instance_id);
  436. /**
  437. * Get the USB vendor ID of a gamepad, if available.
  438. *
  439. * This can be called before any gamepads are opened. If the vendor ID isn't
  440. * available this function returns 0.
  441. *
  442. * \param instance_id the joystick instance ID
  443. * \returns the USB vendor ID of the selected gamepad. If called on an invalid
  444. * index, this function returns zero
  445. *
  446. * \since This function is available since SDL 3.0.0.
  447. */
  448. extern DECLSPEC Uint16 SDLCALL SDL_GetGamepadInstanceVendor(SDL_JoystickID instance_id);
  449. /**
  450. * Get the USB product ID of a gamepad, if available.
  451. *
  452. * This can be called before any gamepads are opened. If the product ID isn't
  453. * available this function returns 0.
  454. *
  455. * \param instance_id the joystick instance ID
  456. * \returns the USB product ID of the selected gamepad. If called on an
  457. * invalid index, this function returns zero
  458. *
  459. * \since This function is available since SDL 3.0.0.
  460. */
  461. extern DECLSPEC Uint16 SDLCALL SDL_GetGamepadInstanceProduct(SDL_JoystickID instance_id);
  462. /**
  463. * Get the product version of a gamepad, if available.
  464. *
  465. * This can be called before any gamepads are opened. If the product version
  466. * isn't available this function returns 0.
  467. *
  468. * \param instance_id the joystick instance ID
  469. * \returns the product version of the selected gamepad. If called on an
  470. * invalid index, this function returns zero
  471. *
  472. * \since This function is available since SDL 3.0.0.
  473. */
  474. extern DECLSPEC Uint16 SDLCALL SDL_GetGamepadInstanceProductVersion(SDL_JoystickID instance_id);
  475. /**
  476. * Get the type of a gamepad.
  477. *
  478. * This can be called before any gamepads are opened.
  479. *
  480. * \param instance_id the joystick instance ID
  481. * \returns the gamepad type.
  482. *
  483. * \since This function is available since SDL 3.0.0.
  484. */
  485. extern DECLSPEC SDL_GamepadType SDLCALL SDL_GetGamepadInstanceType(SDL_JoystickID instance_id);
  486. /**
  487. * Get the type of a gamepad, ignoring any mapping override.
  488. *
  489. * This can be called before any gamepads are opened.
  490. *
  491. * \param instance_id the joystick instance ID
  492. * \returns the gamepad type.
  493. *
  494. * \since This function is available since SDL 3.0.0.
  495. */
  496. extern DECLSPEC SDL_GamepadType SDLCALL SDL_GetRealGamepadInstanceType(SDL_JoystickID instance_id);
  497. /**
  498. * Get the mapping of a gamepad.
  499. *
  500. * This can be called before any gamepads are opened.
  501. *
  502. * \param instance_id the joystick instance ID
  503. * \returns the mapping string. Must be freed with SDL_free(). Returns NULL if
  504. * no mapping is available.
  505. *
  506. * \since This function is available since SDL 3.0.0.
  507. */
  508. extern DECLSPEC char *SDLCALL SDL_GetGamepadInstanceMapping(SDL_JoystickID instance_id);
  509. /**
  510. * Open a gamepad for use.
  511. *
  512. * \param instance_id the joystick instance ID
  513. * \returns a gamepad identifier or NULL if an error occurred; call
  514. * SDL_GetError() for more information.
  515. *
  516. * \since This function is available since SDL 3.0.0.
  517. *
  518. * \sa SDL_CloseGamepad
  519. * \sa SDL_IsGamepad
  520. */
  521. extern DECLSPEC SDL_Gamepad *SDLCALL SDL_OpenGamepad(SDL_JoystickID instance_id);
  522. /**
  523. * Get the SDL_Gamepad associated with a joystick instance ID, if it has been
  524. * opened.
  525. *
  526. * \param instance_id the joystick instance ID of the gamepad
  527. * \returns an SDL_Gamepad on success or NULL on failure or if it hasn't been
  528. * opened yet; call SDL_GetError() for more information.
  529. *
  530. * \since This function is available since SDL 3.0.0.
  531. */
  532. extern DECLSPEC SDL_Gamepad *SDLCALL SDL_GetGamepadFromInstanceID(SDL_JoystickID instance_id);
  533. /**
  534. * Get the SDL_Gamepad associated with a player index.
  535. *
  536. * \param player_index the player index, which different from the instance ID
  537. * \returns the SDL_Gamepad associated with a player index.
  538. *
  539. * \since This function is available since SDL 3.0.0.
  540. *
  541. * \sa SDL_GetGamepadPlayerIndex
  542. * \sa SDL_SetGamepadPlayerIndex
  543. */
  544. extern DECLSPEC SDL_Gamepad *SDLCALL SDL_GetGamepadFromPlayerIndex(int player_index);
  545. /**
  546. * Get the properties associated with an opened gamepad.
  547. *
  548. * These properties are shared with the underlying joystick object.
  549. *
  550. * The following read-only properties are provided by SDL:
  551. *
  552. * - `SDL_PROP_GAMEPAD_CAP_MONO_LED_BOOLEAN`: true if this gamepad has an LED
  553. * that has adjustable brightness
  554. * - `SDL_PROP_GAMEPAD_CAP_RGB_LED_BOOLEAN`: true if this gamepad has an LED
  555. * that has adjustable color
  556. * - `SDL_PROP_GAMEPAD_CAP_PLAYER_LED_BOOLEAN`: true if this gamepad has a
  557. * player LED
  558. * - `SDL_PROP_GAMEPAD_CAP_RUMBLE_BOOLEAN`: true if this gamepad has
  559. * left/right rumble
  560. * - `SDL_PROP_GAMEPAD_CAP_TRIGGER_RUMBLE_BOOLEAN`: true if this gamepad has
  561. * simple trigger rumble
  562. *
  563. * \param gamepad a gamepad identifier previously returned by
  564. * SDL_OpenGamepad()
  565. * \returns a valid property ID on success or 0 on failure; call
  566. * SDL_GetError() for more information.
  567. *
  568. * \since This function is available since SDL 3.0.0.
  569. *
  570. * \sa SDL_GetProperty
  571. * \sa SDL_SetProperty
  572. */
  573. extern DECLSPEC SDL_PropertiesID SDLCALL SDL_GetGamepadProperties(SDL_Gamepad *gamepad);
  574. #define SDL_PROP_GAMEPAD_CAP_MONO_LED_BOOLEAN SDL_PROP_JOYSTICK_CAP_MONO_LED_BOOLEAN
  575. #define SDL_PROP_GAMEPAD_CAP_RGB_LED_BOOLEAN SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN
  576. #define SDL_PROP_GAMEPAD_CAP_PLAYER_LED_BOOLEAN SDL_PROP_JOYSTICK_CAP_PLAYER_LED_BOOLEAN
  577. #define SDL_PROP_GAMEPAD_CAP_RUMBLE_BOOLEAN SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN
  578. #define SDL_PROP_GAMEPAD_CAP_TRIGGER_RUMBLE_BOOLEAN SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN
  579. /**
  580. * Get the instance ID of an opened gamepad.
  581. *
  582. * \param gamepad a gamepad identifier previously returned by
  583. * SDL_OpenGamepad()
  584. * \returns the instance ID of the specified gamepad on success or 0 on
  585. * failure; call SDL_GetError() for more information.
  586. *
  587. * \since This function is available since SDL 3.0.0.
  588. *
  589. * \sa SDL_OpenGamepad
  590. */
  591. extern DECLSPEC SDL_JoystickID SDLCALL SDL_GetGamepadInstanceID(SDL_Gamepad *gamepad);
  592. /**
  593. * Get the implementation-dependent name for an opened gamepad.
  594. *
  595. * \param gamepad a gamepad identifier previously returned by
  596. * SDL_OpenGamepad()
  597. * \returns the implementation dependent name for the gamepad, or NULL if
  598. * there is no name or the identifier passed is invalid.
  599. *
  600. * \since This function is available since SDL 3.0.0.
  601. *
  602. * \sa SDL_GetGamepadInstanceName
  603. * \sa SDL_OpenGamepad
  604. */
  605. extern DECLSPEC const char *SDLCALL SDL_GetGamepadName(SDL_Gamepad *gamepad);
  606. /**
  607. * Get the implementation-dependent path for an opened gamepad.
  608. *
  609. * \param gamepad a gamepad identifier previously returned by
  610. * SDL_OpenGamepad()
  611. * \returns the implementation dependent path for the gamepad, or NULL if
  612. * there is no path or the identifier passed is invalid.
  613. *
  614. * \since This function is available since SDL 3.0.0.
  615. *
  616. * \sa SDL_GetGamepadInstancePath
  617. */
  618. extern DECLSPEC const char *SDLCALL SDL_GetGamepadPath(SDL_Gamepad *gamepad);
  619. /**
  620. * Get the type of an opened gamepad.
  621. *
  622. * \param gamepad the gamepad object to query.
  623. * \returns the gamepad type, or SDL_GAMEPAD_TYPE_UNKNOWN if it's not
  624. * available.
  625. *
  626. * \since This function is available since SDL 3.0.0.
  627. *
  628. * \sa SDL_GetGamepadInstanceType
  629. */
  630. extern DECLSPEC SDL_GamepadType SDLCALL SDL_GetGamepadType(SDL_Gamepad *gamepad);
  631. /**
  632. * Get the type of an opened gamepad, ignoring any mapping override.
  633. *
  634. * \param gamepad the gamepad object to query.
  635. * \returns the gamepad type, or SDL_GAMEPAD_TYPE_UNKNOWN if it's not
  636. * available.
  637. *
  638. * \since This function is available since SDL 3.0.0.
  639. *
  640. * \sa SDL_GetRealGamepadInstanceType
  641. */
  642. extern DECLSPEC SDL_GamepadType SDLCALL SDL_GetRealGamepadType(SDL_Gamepad *gamepad);
  643. /**
  644. * Get the player index of an opened gamepad.
  645. *
  646. * For XInput gamepads this returns the XInput user index.
  647. *
  648. * \param gamepad the gamepad object to query.
  649. * \returns the player index for gamepad, or -1 if it's not available.
  650. *
  651. * \since This function is available since SDL 3.0.0.
  652. */
  653. extern DECLSPEC int SDLCALL SDL_GetGamepadPlayerIndex(SDL_Gamepad *gamepad);
  654. /**
  655. * Set the player index of an opened gamepad.
  656. *
  657. * \param gamepad the gamepad object to adjust.
  658. * \param player_index Player index to assign to this gamepad, or -1 to clear
  659. * the player index and turn off player LEDs.
  660. * \returns 0 on success or a negative error code on failure; call
  661. * SDL_GetError() for more information.
  662. *
  663. * \since This function is available since SDL 3.0.0.
  664. */
  665. extern DECLSPEC int SDLCALL SDL_SetGamepadPlayerIndex(SDL_Gamepad *gamepad, int player_index);
  666. /**
  667. * Get the USB vendor ID of an opened gamepad, if available.
  668. *
  669. * If the vendor ID isn't available this function returns 0.
  670. *
  671. * \param gamepad the gamepad object to query.
  672. * \returns the USB vendor ID, or zero if unavailable.
  673. *
  674. * \since This function is available since SDL 3.0.0.
  675. */
  676. extern DECLSPEC Uint16 SDLCALL SDL_GetGamepadVendor(SDL_Gamepad *gamepad);
  677. /**
  678. * Get the USB product ID of an opened gamepad, if available.
  679. *
  680. * If the product ID isn't available this function returns 0.
  681. *
  682. * \param gamepad the gamepad object to query.
  683. * \returns the USB product ID, or zero if unavailable.
  684. *
  685. * \since This function is available since SDL 3.0.0.
  686. */
  687. extern DECLSPEC Uint16 SDLCALL SDL_GetGamepadProduct(SDL_Gamepad *gamepad);
  688. /**
  689. * Get the product version of an opened gamepad, if available.
  690. *
  691. * If the product version isn't available this function returns 0.
  692. *
  693. * \param gamepad the gamepad object to query.
  694. * \returns the USB product version, or zero if unavailable.
  695. *
  696. * \since This function is available since SDL 3.0.0.
  697. */
  698. extern DECLSPEC Uint16 SDLCALL SDL_GetGamepadProductVersion(SDL_Gamepad *gamepad);
  699. /**
  700. * Get the firmware version of an opened gamepad, if available.
  701. *
  702. * If the firmware version isn't available this function returns 0.
  703. *
  704. * \param gamepad the gamepad object to query.
  705. * \returns the gamepad firmware version, or zero if unavailable.
  706. *
  707. * \since This function is available since SDL 3.0.0.
  708. */
  709. extern DECLSPEC Uint16 SDLCALL SDL_GetGamepadFirmwareVersion(SDL_Gamepad *gamepad);
  710. /**
  711. * Get the serial number of an opened gamepad, if available.
  712. *
  713. * Returns the serial number of the gamepad, or NULL if it is not available.
  714. *
  715. * \param gamepad the gamepad object to query.
  716. * \returns the serial number, or NULL if unavailable.
  717. *
  718. * \since This function is available since SDL 3.0.0.
  719. */
  720. extern DECLSPEC const char * SDLCALL SDL_GetGamepadSerial(SDL_Gamepad *gamepad);
  721. /**
  722. * Get the Steam Input handle of an opened gamepad, if available.
  723. *
  724. * Returns an InputHandle_t for the gamepad that can be used with Steam Input
  725. * API: https://partner.steamgames.com/doc/api/ISteamInput
  726. *
  727. * \param gamepad the gamepad object to query.
  728. * \returns the gamepad handle, or 0 if unavailable.
  729. *
  730. * \since This function is available since SDL 3.0.0.
  731. */
  732. extern DECLSPEC Uint64 SDLCALL SDL_GetGamepadSteamHandle(SDL_Gamepad *gamepad);
  733. /**
  734. * Get the battery level of a gamepad, if available.
  735. *
  736. * \param gamepad a gamepad identifier previously returned by
  737. * SDL_OpenGamepad()
  738. * \returns the current battery level as SDL_JoystickPowerLevel on success or
  739. * `SDL_JOYSTICK_POWER_UNKNOWN` if it is unknown
  740. *
  741. * \since This function is available since SDL 3.0.0.
  742. */
  743. extern DECLSPEC SDL_JoystickPowerLevel SDLCALL SDL_GetGamepadPowerLevel(SDL_Gamepad *gamepad);
  744. /**
  745. * Check if a gamepad has been opened and is currently connected.
  746. *
  747. * \param gamepad a gamepad identifier previously returned by
  748. * SDL_OpenGamepad()
  749. * \returns SDL_TRUE if the gamepad has been opened and is currently
  750. * connected, or SDL_FALSE if not.
  751. *
  752. * \since This function is available since SDL 3.0.0.
  753. *
  754. * \sa SDL_CloseGamepad
  755. * \sa SDL_OpenGamepad
  756. */
  757. extern DECLSPEC SDL_bool SDLCALL SDL_GamepadConnected(SDL_Gamepad *gamepad);
  758. /**
  759. * Get the underlying joystick from a gamepad
  760. *
  761. * This function will give you a SDL_Joystick object, which allows you to use
  762. * the SDL_Joystick functions with a SDL_Gamepad object. This would be useful
  763. * for getting a joystick's position at any given time, even if it hasn't
  764. * moved (moving it would produce an event, which would have the axis' value).
  765. *
  766. * The pointer returned is owned by the SDL_Gamepad. You should not call
  767. * SDL_CloseJoystick() on it, for example, since doing so will likely cause
  768. * SDL to crash.
  769. *
  770. * \param gamepad the gamepad object that you want to get a joystick from
  771. * \returns an SDL_Joystick object; call SDL_GetError() for more information.
  772. *
  773. * \since This function is available since SDL 3.0.0.
  774. */
  775. extern DECLSPEC SDL_Joystick *SDLCALL SDL_GetGamepadJoystick(SDL_Gamepad *gamepad);
  776. /**
  777. * Set the state of gamepad event processing.
  778. *
  779. * If gamepad events are disabled, you must call SDL_UpdateGamepads() yourself
  780. * and check the state of the gamepad when you want gamepad information.
  781. *
  782. * \param enabled whether to process gamepad events or not
  783. *
  784. * \since This function is available since SDL 3.0.0.
  785. *
  786. * \sa SDL_GamepadEventsEnabled
  787. */
  788. extern DECLSPEC void SDLCALL SDL_SetGamepadEventsEnabled(SDL_bool enabled);
  789. /**
  790. * Query the state of gamepad event processing.
  791. *
  792. * If gamepad events are disabled, you must call SDL_UpdateGamepads() yourself
  793. * and check the state of the gamepad when you want gamepad information.
  794. *
  795. * \returns SDL_TRUE if gamepad events are being processed, SDL_FALSE
  796. * otherwise.
  797. *
  798. * \since This function is available since SDL 3.0.0.
  799. *
  800. * \sa SDL_SetGamepadEventsEnabled
  801. */
  802. extern DECLSPEC SDL_bool SDLCALL SDL_GamepadEventsEnabled(void);
  803. /**
  804. * Get the SDL joystick layer bindings for a gamepad
  805. *
  806. * \param gamepad a gamepad
  807. * \param count a pointer filled in with the number of bindings returned
  808. * \returns a NULL terminated array of pointers to bindings which should be
  809. * freed with SDL_free(), or NULL on error; call SDL_GetError() for
  810. * more details.
  811. *
  812. * \since This function is available since SDL 3.0.0.
  813. */
  814. extern DECLSPEC SDL_GamepadBinding **SDLCALL SDL_GetGamepadBindings(SDL_Gamepad *gamepad, int *count);
  815. /**
  816. * Manually pump gamepad updates if not using the loop.
  817. *
  818. * This function is called automatically by the event loop if events are
  819. * enabled. Under such circumstances, it will not be necessary to call this
  820. * function.
  821. *
  822. * \since This function is available since SDL 3.0.0.
  823. */
  824. extern DECLSPEC void SDLCALL SDL_UpdateGamepads(void);
  825. /**
  826. * Convert a string into SDL_GamepadType enum.
  827. *
  828. * This function is called internally to translate SDL_Gamepad mapping strings
  829. * for the underlying joystick device into the consistent SDL_Gamepad mapping.
  830. * You do not normally need to call this function unless you are parsing
  831. * SDL_Gamepad mappings in your own code.
  832. *
  833. * \param str string representing a SDL_GamepadType type
  834. * \returns the SDL_GamepadType enum corresponding to the input string, or
  835. * `SDL_GAMEPAD_TYPE_UNKNOWN` if no match was found.
  836. *
  837. * \since This function is available since SDL 3.0.0.
  838. *
  839. * \sa SDL_GetGamepadStringForType
  840. */
  841. extern DECLSPEC SDL_GamepadType SDLCALL SDL_GetGamepadTypeFromString(const char *str);
  842. /**
  843. * Convert from an SDL_GamepadType enum to a string.
  844. *
  845. * The caller should not SDL_free() the returned string.
  846. *
  847. * \param type an enum value for a given SDL_GamepadType
  848. * \returns a string for the given type, or NULL if an invalid type is
  849. * specified. The string returned is of the format used by
  850. * SDL_Gamepad mapping strings.
  851. *
  852. * \since This function is available since SDL 3.0.0.
  853. *
  854. * \sa SDL_GetGamepadTypeFromString
  855. */
  856. extern DECLSPEC const char *SDLCALL SDL_GetGamepadStringForType(SDL_GamepadType type);
  857. /**
  858. * Convert a string into SDL_GamepadAxis enum.
  859. *
  860. * This function is called internally to translate SDL_Gamepad mapping strings
  861. * for the underlying joystick device into the consistent SDL_Gamepad mapping.
  862. * You do not normally need to call this function unless you are parsing
  863. * SDL_Gamepad mappings in your own code.
  864. *
  865. * Note specially that "righttrigger" and "lefttrigger" map to
  866. * `SDL_GAMEPAD_AXIS_RIGHT_TRIGGER` and `SDL_GAMEPAD_AXIS_LEFT_TRIGGER`,
  867. * respectively.
  868. *
  869. * \param str string representing a SDL_Gamepad axis
  870. * \returns the SDL_GamepadAxis enum corresponding to the input string, or
  871. * `SDL_GAMEPAD_AXIS_INVALID` if no match was found.
  872. *
  873. * \since This function is available since SDL 3.0.0.
  874. *
  875. * \sa SDL_GetGamepadStringForAxis
  876. */
  877. extern DECLSPEC SDL_GamepadAxis SDLCALL SDL_GetGamepadAxisFromString(const char *str);
  878. /**
  879. * Convert from an SDL_GamepadAxis enum to a string.
  880. *
  881. * The caller should not SDL_free() the returned string.
  882. *
  883. * \param axis an enum value for a given SDL_GamepadAxis
  884. * \returns a string for the given axis, or NULL if an invalid axis is
  885. * specified. The string returned is of the format used by
  886. * SDL_Gamepad mapping strings.
  887. *
  888. * \since This function is available since SDL 3.0.0.
  889. *
  890. * \sa SDL_GetGamepadAxisFromString
  891. */
  892. extern DECLSPEC const char* SDLCALL SDL_GetGamepadStringForAxis(SDL_GamepadAxis axis);
  893. /**
  894. * Query whether a gamepad has a given axis.
  895. *
  896. * This merely reports whether the gamepad's mapping defined this axis, as
  897. * that is all the information SDL has about the physical device.
  898. *
  899. * \param gamepad a gamepad
  900. * \param axis an axis enum value (an SDL_GamepadAxis value)
  901. * \returns SDL_TRUE if the gamepad has this axis, SDL_FALSE otherwise.
  902. *
  903. * \since This function is available since SDL 3.0.0.
  904. */
  905. extern DECLSPEC SDL_bool SDLCALL SDL_GamepadHasAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis);
  906. /**
  907. * Get the current state of an axis control on a gamepad.
  908. *
  909. * The axis indices start at index 0.
  910. *
  911. * For thumbsticks, the state is a value ranging from -32768 (up/left) to
  912. * 32767 (down/right).
  913. *
  914. * Triggers range from 0 when released to 32767 when fully pressed, and never
  915. * return a negative value. Note that this differs from the value reported by
  916. * the lower-level SDL_GetJoystickAxis(), which normally uses the full range.
  917. *
  918. * \param gamepad a gamepad
  919. * \param axis an axis index (one of the SDL_GamepadAxis values)
  920. * \returns axis state (including 0) on success or 0 (also) on failure; call
  921. * SDL_GetError() for more information.
  922. *
  923. * \since This function is available since SDL 3.0.0.
  924. *
  925. * \sa SDL_GetGamepadButton
  926. */
  927. extern DECLSPEC Sint16 SDLCALL SDL_GetGamepadAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis);
  928. /**
  929. * Convert a string into an SDL_GamepadButton enum.
  930. *
  931. * This function is called internally to translate SDL_Gamepad mapping strings
  932. * for the underlying joystick device into the consistent SDL_Gamepad mapping.
  933. * You do not normally need to call this function unless you are parsing
  934. * SDL_Gamepad mappings in your own code.
  935. *
  936. * \param str string representing a SDL_Gamepad axis
  937. * \returns the SDL_GamepadButton enum corresponding to the input string, or
  938. * `SDL_GAMEPAD_BUTTON_INVALID` if no match was found.
  939. *
  940. * \since This function is available since SDL 3.0.0.
  941. */
  942. extern DECLSPEC SDL_GamepadButton SDLCALL SDL_GetGamepadButtonFromString(const char *str);
  943. /**
  944. * Convert from an SDL_GamepadButton enum to a string.
  945. *
  946. * The caller should not SDL_free() the returned string.
  947. *
  948. * \param button an enum value for a given SDL_GamepadButton
  949. * \returns a string for the given button, or NULL if an invalid button is
  950. * specified. The string returned is of the format used by
  951. * SDL_Gamepad mapping strings.
  952. *
  953. * \since This function is available since SDL 3.0.0.
  954. *
  955. * \sa SDL_GetGamepadButtonFromString
  956. */
  957. extern DECLSPEC const char* SDLCALL SDL_GetGamepadStringForButton(SDL_GamepadButton button);
  958. /**
  959. * Query whether a gamepad has a given button.
  960. *
  961. * This merely reports whether the gamepad's mapping defined this button, as
  962. * that is all the information SDL has about the physical device.
  963. *
  964. * \param gamepad a gamepad
  965. * \param button a button enum value (an SDL_GamepadButton value)
  966. * \returns SDL_TRUE if the gamepad has this button, SDL_FALSE otherwise.
  967. *
  968. * \since This function is available since SDL 3.0.0.
  969. */
  970. extern DECLSPEC SDL_bool SDLCALL SDL_GamepadHasButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
  971. /**
  972. * Get the current state of a button on a gamepad.
  973. *
  974. * \param gamepad a gamepad
  975. * \param button a button index (one of the SDL_GamepadButton values)
  976. * \returns 1 for pressed state or 0 for not pressed state or error; call
  977. * SDL_GetError() for more information.
  978. *
  979. * \since This function is available since SDL 3.0.0.
  980. *
  981. * \sa SDL_GetGamepadAxis
  982. */
  983. extern DECLSPEC Uint8 SDLCALL SDL_GetGamepadButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
  984. /**
  985. * Get the label of a button on a gamepad.
  986. *
  987. * \param type the type of gamepad to check
  988. * \param button a button index (one of the SDL_GamepadButton values)
  989. * \returns the SDL_GamepadButtonLabel enum corresponding to the button label
  990. *
  991. * \since This function is available since SDL 3.0.0.
  992. *
  993. * \sa SDL_GetGamepadButtonLabel
  994. */
  995. extern DECLSPEC SDL_GamepadButtonLabel SDLCALL SDL_GetGamepadButtonLabelForType(SDL_GamepadType type, SDL_GamepadButton button);
  996. /**
  997. * Get the label of a button on a gamepad.
  998. *
  999. * \param gamepad a gamepad
  1000. * \param button a button index (one of the SDL_GamepadButton values)
  1001. * \returns the SDL_GamepadButtonLabel enum corresponding to the button label
  1002. *
  1003. * \since This function is available since SDL 3.0.0.
  1004. *
  1005. * \sa SDL_GetGamepadButtonLabelForType
  1006. */
  1007. extern DECLSPEC SDL_GamepadButtonLabel SDLCALL SDL_GetGamepadButtonLabel(SDL_Gamepad *gamepad, SDL_GamepadButton button);
  1008. /**
  1009. * Get the number of touchpads on a gamepad.
  1010. *
  1011. * \param gamepad a gamepad
  1012. * \returns number of touchpads
  1013. *
  1014. * \since This function is available since SDL 3.0.0.
  1015. */
  1016. extern DECLSPEC int SDLCALL SDL_GetNumGamepadTouchpads(SDL_Gamepad *gamepad);
  1017. /**
  1018. * Get the number of supported simultaneous fingers on a touchpad on a game
  1019. * gamepad.
  1020. *
  1021. * \param gamepad a gamepad
  1022. * \param touchpad a touchpad
  1023. * \returns number of supported simultaneous fingers
  1024. *
  1025. * \since This function is available since SDL 3.0.0.
  1026. */
  1027. extern DECLSPEC int SDLCALL SDL_GetNumGamepadTouchpadFingers(SDL_Gamepad *gamepad, int touchpad);
  1028. /**
  1029. * Get the current state of a finger on a touchpad on a gamepad.
  1030. *
  1031. * \param gamepad a gamepad
  1032. * \param touchpad a touchpad
  1033. * \param finger a finger
  1034. * \param state filled with state
  1035. * \param x filled with x position
  1036. * \param y filled with y position
  1037. * \param pressure filled with pressure value
  1038. * \returns 0 on success or a negative error code on failure; call
  1039. * SDL_GetError() for more information.
  1040. *
  1041. * \since This function is available since SDL 3.0.0.
  1042. */
  1043. extern DECLSPEC int SDLCALL SDL_GetGamepadTouchpadFinger(SDL_Gamepad *gamepad, int touchpad, int finger, Uint8 *state, float *x, float *y, float *pressure);
  1044. /**
  1045. * Return whether a gamepad has a particular sensor.
  1046. *
  1047. * \param gamepad The gamepad to query
  1048. * \param type The type of sensor to query
  1049. * \returns SDL_TRUE if the sensor exists, SDL_FALSE otherwise.
  1050. *
  1051. * \since This function is available since SDL 3.0.0.
  1052. */
  1053. extern DECLSPEC SDL_bool SDLCALL SDL_GamepadHasSensor(SDL_Gamepad *gamepad, SDL_SensorType type);
  1054. /**
  1055. * Set whether data reporting for a gamepad sensor is enabled.
  1056. *
  1057. * \param gamepad The gamepad to update
  1058. * \param type The type of sensor to enable/disable
  1059. * \param enabled Whether data reporting should be enabled
  1060. * \returns 0 on success or a negative error code on failure; call
  1061. * SDL_GetError() for more information.
  1062. *
  1063. * \since This function is available since SDL 3.0.0.
  1064. */
  1065. extern DECLSPEC int SDLCALL SDL_SetGamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type, SDL_bool enabled);
  1066. /**
  1067. * Query whether sensor data reporting is enabled for a gamepad.
  1068. *
  1069. * \param gamepad The gamepad to query
  1070. * \param type The type of sensor to query
  1071. * \returns SDL_TRUE if the sensor is enabled, SDL_FALSE otherwise.
  1072. *
  1073. * \since This function is available since SDL 3.0.0.
  1074. */
  1075. extern DECLSPEC SDL_bool SDLCALL SDL_GamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type);
  1076. /**
  1077. * Get the data rate (number of events per second) of a gamepad sensor.
  1078. *
  1079. * \param gamepad The gamepad to query
  1080. * \param type The type of sensor to query
  1081. * \returns the data rate, or 0.0f if the data rate is not available.
  1082. *
  1083. * \since This function is available since SDL 3.0.0.
  1084. */
  1085. extern DECLSPEC float SDLCALL SDL_GetGamepadSensorDataRate(SDL_Gamepad *gamepad, SDL_SensorType type);
  1086. /**
  1087. * Get the current state of a gamepad sensor.
  1088. *
  1089. * The number of values and interpretation of the data is sensor dependent.
  1090. * See SDL_sensor.h for the details for each type of sensor.
  1091. *
  1092. * \param gamepad The gamepad to query
  1093. * \param type The type of sensor to query
  1094. * \param data A pointer filled with the current sensor state
  1095. * \param num_values The number of values to write to data
  1096. * \returns 0 on success or a negative error code on failure; call
  1097. * SDL_GetError() for more information.
  1098. *
  1099. * \since This function is available since SDL 3.0.0.
  1100. */
  1101. extern DECLSPEC int SDLCALL SDL_GetGamepadSensorData(SDL_Gamepad *gamepad, SDL_SensorType type, float *data, int num_values);
  1102. /**
  1103. * Start a rumble effect on a gamepad.
  1104. *
  1105. * Each call to this function cancels any previous rumble effect, and calling
  1106. * it with 0 intensity stops any rumbling.
  1107. *
  1108. * \param gamepad The gamepad to vibrate
  1109. * \param low_frequency_rumble The intensity of the low frequency (left)
  1110. * rumble motor, from 0 to 0xFFFF
  1111. * \param high_frequency_rumble The intensity of the high frequency (right)
  1112. * rumble motor, from 0 to 0xFFFF
  1113. * \param duration_ms The duration of the rumble effect, in milliseconds
  1114. * \returns 0, or -1 if rumble isn't supported on this gamepad
  1115. *
  1116. * \since This function is available since SDL 3.0.0.
  1117. */
  1118. extern DECLSPEC int SDLCALL SDL_RumbleGamepad(SDL_Gamepad *gamepad, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
  1119. /**
  1120. * Start a rumble effect in the gamepad's triggers.
  1121. *
  1122. * Each call to this function cancels any previous trigger rumble effect, and
  1123. * calling it with 0 intensity stops any rumbling.
  1124. *
  1125. * Note that this is rumbling of the _triggers_ and not the gamepad as a
  1126. * whole. This is currently only supported on Xbox One gamepads. If you want
  1127. * the (more common) whole-gamepad rumble, use SDL_RumbleGamepad() instead.
  1128. *
  1129. * \param gamepad The gamepad to vibrate
  1130. * \param left_rumble The intensity of the left trigger rumble motor, from 0
  1131. * to 0xFFFF
  1132. * \param right_rumble The intensity of the right trigger rumble motor, from 0
  1133. * to 0xFFFF
  1134. * \param duration_ms The duration of the rumble effect, in milliseconds
  1135. * \returns 0 on success or a negative error code on failure; call
  1136. * SDL_GetError() for more information.
  1137. *
  1138. * \since This function is available since SDL 3.0.0.
  1139. */
  1140. extern DECLSPEC int SDLCALL SDL_RumbleGamepadTriggers(SDL_Gamepad *gamepad, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms);
  1141. /**
  1142. * Update a gamepad's LED color.
  1143. *
  1144. * An example of a joystick LED is the light on the back of a PlayStation 4's
  1145. * DualShock 4 controller.
  1146. *
  1147. * For gamepads with a single color LED, the maximum of the RGB values will be
  1148. * used as the LED brightness.
  1149. *
  1150. * \param gamepad The gamepad to update
  1151. * \param red The intensity of the red LED
  1152. * \param green The intensity of the green LED
  1153. * \param blue The intensity of the blue LED
  1154. * \returns 0 on success or a negative error code on failure; call
  1155. * SDL_GetError() for more information.
  1156. *
  1157. * \since This function is available since SDL 3.0.0.
  1158. */
  1159. extern DECLSPEC int SDLCALL SDL_SetGamepadLED(SDL_Gamepad *gamepad, Uint8 red, Uint8 green, Uint8 blue);
  1160. /**
  1161. * Send a gamepad specific effect packet
  1162. *
  1163. * \param gamepad The gamepad to affect
  1164. * \param data The data to send to the gamepad
  1165. * \param size The size of the data to send to the gamepad
  1166. * \returns 0 on success or a negative error code on failure; call
  1167. * SDL_GetError() for more information.
  1168. *
  1169. * \since This function is available since SDL 3.0.0.
  1170. */
  1171. extern DECLSPEC int SDLCALL SDL_SendGamepadEffect(SDL_Gamepad *gamepad, const void *data, int size);
  1172. /**
  1173. * Close a gamepad previously opened with SDL_OpenGamepad().
  1174. *
  1175. * \param gamepad a gamepad identifier previously returned by
  1176. * SDL_OpenGamepad()
  1177. *
  1178. * \since This function is available since SDL 3.0.0.
  1179. *
  1180. * \sa SDL_OpenGamepad
  1181. */
  1182. extern DECLSPEC void SDLCALL SDL_CloseGamepad(SDL_Gamepad *gamepad);
  1183. /**
  1184. * Return the sfSymbolsName for a given button on a gamepad on Apple
  1185. * platforms.
  1186. *
  1187. * \param gamepad the gamepad to query
  1188. * \param button a button on the gamepad
  1189. * \returns the sfSymbolsName or NULL if the name can't be found
  1190. *
  1191. * \since This function is available since SDL 3.0.0.
  1192. *
  1193. * \sa SDL_GetGamepadAppleSFSymbolsNameForAxis
  1194. */
  1195. extern DECLSPEC const char* SDLCALL SDL_GetGamepadAppleSFSymbolsNameForButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
  1196. /**
  1197. * Return the sfSymbolsName for a given axis on a gamepad on Apple platforms.
  1198. *
  1199. * \param gamepad the gamepad to query
  1200. * \param axis an axis on the gamepad
  1201. * \returns the sfSymbolsName or NULL if the name can't be found
  1202. *
  1203. * \since This function is available since SDL 3.0.0.
  1204. *
  1205. * \sa SDL_GetGamepadAppleSFSymbolsNameForButton
  1206. */
  1207. extern DECLSPEC const char* SDLCALL SDL_GetGamepadAppleSFSymbolsNameForAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis);
  1208. /* Ends C function definitions when using C++ */
  1209. #ifdef __cplusplus
  1210. }
  1211. #endif
  1212. #include <SDL3/SDL_close_code.h>
  1213. #endif /* SDL_gamepad_h_ */