SDL_gamepad.h 51 KB

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