SDL_gamepad.h 51 KB

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