SDL_gamepad.h 48 KB

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