SDL_gamepad.h 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493
  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. * \threadsafety It is safe to call this function from any thread.
  285. *
  286. * \since This function is available since SDL 3.0.0.
  287. *
  288. * \sa SDL_GetGamepadMapping
  289. * \sa SDL_GetGamepadMappingForGUID
  290. */
  291. extern SDL_DECLSPEC int SDLCALL SDL_AddGamepadMapping(const char *mapping);
  292. /**
  293. * Load a set of gamepad mappings from an SDL_IOStream.
  294. *
  295. * You can call this function several times, if needed, to load different
  296. * database files.
  297. *
  298. * If a new mapping is loaded for an already known gamepad GUID, the later
  299. * version will overwrite the one currently loaded.
  300. *
  301. * Mappings not belonging to the current platform or with no platform field
  302. * specified will be ignored (i.e. mappings for Linux will be ignored in
  303. * Windows, etc).
  304. *
  305. * This function will load the text database entirely in memory before
  306. * processing it, so take this into consideration if you are in a memory
  307. * constrained environment.
  308. *
  309. * \param src the data stream for the mappings to be added
  310. * \param closeio if SDL_TRUE, calls SDL_CloseIO() on `src` before returning,
  311. * even in the case of an error
  312. * \returns the number of mappings added or -1 on error; call SDL_GetError()
  313. * for more information.
  314. *
  315. * \threadsafety It is safe to call this function from any thread.
  316. *
  317. * \since This function is available since SDL 3.0.0.
  318. *
  319. * \sa SDL_AddGamepadMapping
  320. * \sa SDL_AddGamepadMappingsFromFile
  321. * \sa SDL_GetGamepadMapping
  322. * \sa SDL_GetGamepadMappingForGUID
  323. */
  324. extern SDL_DECLSPEC int SDLCALL SDL_AddGamepadMappingsFromIO(SDL_IOStream *src, SDL_bool closeio);
  325. /**
  326. * Load a set of gamepad mappings from a file.
  327. *
  328. * You can call this function several times, if needed, to load different
  329. * database files.
  330. *
  331. * If a new mapping is loaded for an already known gamepad GUID, the later
  332. * version will overwrite the one currently loaded.
  333. *
  334. * Mappings not belonging to the current platform or with no platform field
  335. * specified will be ignored (i.e. mappings for Linux will be ignored in
  336. * Windows, etc).
  337. *
  338. * \param file the mappings file to load
  339. * \returns the number of mappings added or -1 on error; call SDL_GetError()
  340. * for more information.
  341. *
  342. * \threadsafety It is safe to call this function from any thread.
  343. *
  344. * \since This function is available since SDL 3.0.0.
  345. *
  346. * \sa SDL_AddGamepadMapping
  347. * \sa SDL_AddGamepadMappingsFromIO
  348. * \sa SDL_GetGamepadMapping
  349. * \sa SDL_GetGamepadMappingForGUID
  350. */
  351. extern SDL_DECLSPEC int SDLCALL SDL_AddGamepadMappingsFromFile(const char *file);
  352. /**
  353. * Reinitialize the SDL mapping database to its initial state.
  354. *
  355. * This will generate gamepad events as needed if device mappings change.
  356. *
  357. * \returns 0 on success or a negative error code on failure; call
  358. * SDL_GetError() for more information.
  359. *
  360. * \since This function is available since SDL 3.0.0.
  361. */
  362. extern SDL_DECLSPEC int SDLCALL SDL_ReloadGamepadMappings(void);
  363. /**
  364. * Get the current gamepad mappings.
  365. *
  366. * You must free the returned pointer with SDL_free() when you are done with
  367. * it, but you do _not_ free each string in the array.
  368. *
  369. * \param count a pointer filled in with the number of mappings returned, can
  370. * be NULL.
  371. * \returns an array of the mapping strings, NULL-terminated. Must be freed
  372. * with SDL_free(). Returns NULL on error.
  373. *
  374. * \since This function is available since SDL 3.0.0.
  375. */
  376. extern SDL_DECLSPEC char ** SDLCALL SDL_GetGamepadMappings(int *count);
  377. /**
  378. * Get the gamepad mapping string for a given GUID.
  379. *
  380. * The returned string must be freed with SDL_free().
  381. *
  382. * \param guid a structure containing the GUID for which a mapping is desired
  383. * \returns a mapping string or NULL on error; call SDL_GetError() for more
  384. * information.
  385. *
  386. * \since This function is available since SDL 3.0.0.
  387. *
  388. * \sa SDL_GetJoystickInstanceGUID
  389. * \sa SDL_GetJoystickGUID
  390. */
  391. extern SDL_DECLSPEC char * SDLCALL SDL_GetGamepadMappingForGUID(SDL_JoystickGUID guid);
  392. /**
  393. * Get the current mapping of a gamepad.
  394. *
  395. * The returned string must be freed with SDL_free().
  396. *
  397. * Details about mappings are discussed with SDL_AddGamepadMapping().
  398. *
  399. * \param gamepad the gamepad you want to get the current mapping for
  400. * \returns a string that has the gamepad's mapping or NULL if no mapping is
  401. * available; call SDL_GetError() for more information.
  402. *
  403. * \since This function is available since SDL 3.0.0.
  404. *
  405. * \sa SDL_AddGamepadMapping
  406. * \sa SDL_GetGamepadInstanceMapping
  407. * \sa SDL_GetGamepadMappingForGUID
  408. * \sa SDL_SetGamepadMapping
  409. */
  410. extern SDL_DECLSPEC char * SDLCALL SDL_GetGamepadMapping(SDL_Gamepad *gamepad);
  411. /**
  412. * Set the current mapping of a joystick or gamepad.
  413. *
  414. * Details about mappings are discussed with SDL_AddGamepadMapping().
  415. *
  416. * \param instance_id the joystick instance ID
  417. * \param mapping the mapping to use for this device, or NULL to clear the
  418. * mapping
  419. * \returns 0 on success or a negative error code on failure; call
  420. * SDL_GetError() for more information.
  421. *
  422. * \since This function is available since SDL 3.0.0.
  423. *
  424. * \sa SDL_AddGamepadMapping
  425. * \sa SDL_GetGamepadMapping
  426. */
  427. extern SDL_DECLSPEC int SDLCALL SDL_SetGamepadMapping(SDL_JoystickID instance_id, const char *mapping);
  428. /**
  429. * Return whether a gamepad is currently connected.
  430. *
  431. * \returns SDL_TRUE if a gamepad is connected, SDL_FALSE otherwise.
  432. *
  433. * \since This function is available since SDL 3.0.0.
  434. *
  435. * \sa SDL_GetGamepads
  436. */
  437. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasGamepad(void);
  438. /**
  439. * Get a list of currently connected gamepads.
  440. *
  441. * \param count a pointer filled in with the number of gamepads returned
  442. * \returns a 0 terminated array of joystick instance IDs which should be
  443. * freed with SDL_free(), or NULL on error; call SDL_GetError() for
  444. * more details.
  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 SDL_TRUE if the given joystick is supported by the gamepad
  457. * interface, SDL_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 SDL_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. * The returned string follows the SDL_GetStringRule.
  471. *
  472. * \param instance_id the joystick instance ID
  473. * \returns the name of the selected gamepad. If no name can be found, this
  474. * function returns NULL; call SDL_GetError() for more information.
  475. *
  476. * \since This function is available since SDL 3.0.0.
  477. *
  478. * \sa SDL_GetGamepadName
  479. * \sa SDL_GetGamepads
  480. */
  481. extern SDL_DECLSPEC const char *SDLCALL SDL_GetGamepadInstanceName(SDL_JoystickID instance_id);
  482. /**
  483. * Get the implementation dependent path of a gamepad.
  484. *
  485. * This can be called before any gamepads are opened.
  486. *
  487. * The returned string follows the SDL_GetStringRule.
  488. *
  489. * \param instance_id the joystick instance ID
  490. * \returns the path of the selected gamepad. If no path can be found, this
  491. * function returns NULL; call SDL_GetError() for more information.
  492. *
  493. * \since This function is available since SDL 3.0.0.
  494. *
  495. * \sa SDL_GetGamepadPath
  496. * \sa SDL_GetGamepads
  497. */
  498. extern SDL_DECLSPEC const char *SDLCALL SDL_GetGamepadInstancePath(SDL_JoystickID instance_id);
  499. /**
  500. * Get the player index of a gamepad.
  501. *
  502. * This can be called before any gamepads are opened.
  503. *
  504. * \param instance_id the joystick instance ID
  505. * \returns the player index of a gamepad, or -1 if it's not available
  506. *
  507. * \since This function is available since SDL 3.0.0.
  508. *
  509. * \sa SDL_GetGamepadPlayerIndex
  510. * \sa SDL_GetGamepads
  511. */
  512. extern SDL_DECLSPEC int SDLCALL SDL_GetGamepadInstancePlayerIndex(SDL_JoystickID instance_id);
  513. /**
  514. * Get the implementation-dependent GUID of a gamepad.
  515. *
  516. * This can be called before any gamepads are opened.
  517. *
  518. * \param instance_id the joystick instance ID
  519. * \returns the GUID of the selected gamepad. If called on an invalid index,
  520. * this function returns a zero GUID
  521. *
  522. * \since This function is available since SDL 3.0.0.
  523. *
  524. * \sa SDL_GetGamepadGUID
  525. * \sa SDL_GetGamepadGUIDString
  526. * \sa SDL_GetGamepads
  527. */
  528. extern SDL_DECLSPEC SDL_JoystickGUID SDLCALL SDL_GetGamepadInstanceGUID(SDL_JoystickID instance_id);
  529. /**
  530. * Get the USB vendor ID of a gamepad, if available.
  531. *
  532. * This can be called before any gamepads are opened. If the vendor ID isn't
  533. * available this function returns 0.
  534. *
  535. * \param instance_id the joystick instance ID
  536. * \returns the USB vendor ID of the selected gamepad. If called on an invalid
  537. * index, this function returns zero
  538. *
  539. * \since This function is available since SDL 3.0.0.
  540. *
  541. * \sa SDL_GetGamepadVendor
  542. * \sa SDL_GetGamepads
  543. */
  544. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadInstanceVendor(SDL_JoystickID instance_id);
  545. /**
  546. * Get the USB product ID of a gamepad, if available.
  547. *
  548. * This can be called before any gamepads are opened. If the product ID isn't
  549. * available this function returns 0.
  550. *
  551. * \param instance_id the joystick instance ID
  552. * \returns the USB product ID of the selected gamepad. If called on an
  553. * invalid index, this function returns zero
  554. *
  555. * \since This function is available since SDL 3.0.0.
  556. *
  557. * \sa SDL_GetGamepadProduct
  558. * \sa SDL_GetGamepads
  559. */
  560. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadInstanceProduct(SDL_JoystickID instance_id);
  561. /**
  562. * Get the product version of a gamepad, if available.
  563. *
  564. * This can be called before any gamepads are opened. If the product version
  565. * isn't available this function returns 0.
  566. *
  567. * \param instance_id the joystick instance ID
  568. * \returns the product version of the selected gamepad. If called on an
  569. * invalid index, this function returns zero
  570. *
  571. * \since This function is available since SDL 3.0.0.
  572. *
  573. * \sa SDL_GetGamepadProductVersion
  574. * \sa SDL_GetGamepads
  575. */
  576. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadInstanceProductVersion(SDL_JoystickID instance_id);
  577. /**
  578. * Get the type of a gamepad.
  579. *
  580. * This can be called before any gamepads are opened.
  581. *
  582. * \param instance_id the joystick instance ID
  583. * \returns the gamepad type.
  584. *
  585. * \since This function is available since SDL 3.0.0.
  586. *
  587. * \sa SDL_GetGamepadType
  588. * \sa SDL_GetGamepads
  589. * \sa SDL_GetRealGamepadInstanceType
  590. */
  591. extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetGamepadInstanceType(SDL_JoystickID instance_id);
  592. /**
  593. * Get the type of a gamepad, ignoring any mapping override.
  594. *
  595. * This can be called before any gamepads are opened.
  596. *
  597. * \param instance_id the joystick instance ID
  598. * \returns the gamepad type.
  599. *
  600. * \since This function is available since SDL 3.0.0.
  601. *
  602. * \sa SDL_GetGamepadInstanceType
  603. * \sa SDL_GetGamepads
  604. * \sa SDL_GetRealGamepadType
  605. */
  606. extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetRealGamepadInstanceType(SDL_JoystickID instance_id);
  607. /**
  608. * Get the mapping of a gamepad.
  609. *
  610. * This can be called before any gamepads are opened.
  611. *
  612. * \param instance_id the joystick instance ID
  613. * \returns the mapping string. Must be freed with SDL_free(). Returns NULL if
  614. * no mapping is available.
  615. *
  616. * \since This function is available since SDL 3.0.0.
  617. *
  618. * \sa SDL_GetGamepads
  619. * \sa SDL_GetGamepadMapping
  620. */
  621. extern SDL_DECLSPEC char *SDLCALL SDL_GetGamepadInstanceMapping(SDL_JoystickID instance_id);
  622. /**
  623. * Open a gamepad for use.
  624. *
  625. * \param instance_id the joystick instance ID
  626. * \returns a gamepad identifier or NULL if an error occurred; call
  627. * SDL_GetError() for more information.
  628. *
  629. * \since This function is available since SDL 3.0.0.
  630. *
  631. * \sa SDL_CloseGamepad
  632. * \sa SDL_IsGamepad
  633. */
  634. extern SDL_DECLSPEC SDL_Gamepad *SDLCALL SDL_OpenGamepad(SDL_JoystickID instance_id);
  635. /**
  636. * Get the SDL_Gamepad associated with a joystick instance ID, if it has been
  637. * opened.
  638. *
  639. * \param instance_id the joystick instance ID of the gamepad
  640. * \returns an SDL_Gamepad on success or NULL on failure or if it hasn't been
  641. * opened yet; call SDL_GetError() for more information.
  642. *
  643. * \since This function is available since SDL 3.0.0.
  644. */
  645. extern SDL_DECLSPEC SDL_Gamepad *SDLCALL SDL_GetGamepadFromInstanceID(SDL_JoystickID instance_id);
  646. /**
  647. * Get the SDL_Gamepad associated with a player index.
  648. *
  649. * \param player_index the player index, which different from the instance ID
  650. * \returns the SDL_Gamepad associated with a player index.
  651. *
  652. * \since This function is available since SDL 3.0.0.
  653. *
  654. * \sa SDL_GetGamepadPlayerIndex
  655. * \sa SDL_SetGamepadPlayerIndex
  656. */
  657. extern SDL_DECLSPEC SDL_Gamepad *SDLCALL SDL_GetGamepadFromPlayerIndex(int player_index);
  658. /**
  659. * Get the properties associated with an opened gamepad.
  660. *
  661. * These properties are shared with the underlying joystick object.
  662. *
  663. * The following read-only properties are provided by SDL:
  664. *
  665. * - `SDL_PROP_GAMEPAD_CAP_MONO_LED_BOOLEAN`: true if this gamepad has an LED
  666. * that has adjustable brightness
  667. * - `SDL_PROP_GAMEPAD_CAP_RGB_LED_BOOLEAN`: true if this gamepad has an LED
  668. * that has adjustable color
  669. * - `SDL_PROP_GAMEPAD_CAP_PLAYER_LED_BOOLEAN`: true if this gamepad has a
  670. * player LED
  671. * - `SDL_PROP_GAMEPAD_CAP_RUMBLE_BOOLEAN`: true if this gamepad has
  672. * left/right rumble
  673. * - `SDL_PROP_GAMEPAD_CAP_TRIGGER_RUMBLE_BOOLEAN`: true if this gamepad has
  674. * simple trigger rumble
  675. *
  676. * \param gamepad a gamepad identifier previously returned by
  677. * SDL_OpenGamepad()
  678. * \returns a valid property ID on success or 0 on failure; call
  679. * SDL_GetError() for more information.
  680. *
  681. * \since This function is available since SDL 3.0.0.
  682. *
  683. * \sa SDL_GetProperty
  684. * \sa SDL_SetProperty
  685. */
  686. extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetGamepadProperties(SDL_Gamepad *gamepad);
  687. #define SDL_PROP_GAMEPAD_CAP_MONO_LED_BOOLEAN SDL_PROP_JOYSTICK_CAP_MONO_LED_BOOLEAN
  688. #define SDL_PROP_GAMEPAD_CAP_RGB_LED_BOOLEAN SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN
  689. #define SDL_PROP_GAMEPAD_CAP_PLAYER_LED_BOOLEAN SDL_PROP_JOYSTICK_CAP_PLAYER_LED_BOOLEAN
  690. #define SDL_PROP_GAMEPAD_CAP_RUMBLE_BOOLEAN SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN
  691. #define SDL_PROP_GAMEPAD_CAP_TRIGGER_RUMBLE_BOOLEAN SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN
  692. /**
  693. * Get the instance ID of an opened gamepad.
  694. *
  695. * \param gamepad a gamepad identifier previously returned by
  696. * SDL_OpenGamepad()
  697. * \returns the instance ID of the specified gamepad on success or 0 on
  698. * failure; call SDL_GetError() for more information.
  699. *
  700. * \since This function is available since SDL 3.0.0.
  701. */
  702. extern SDL_DECLSPEC SDL_JoystickID SDLCALL SDL_GetGamepadInstanceID(SDL_Gamepad *gamepad);
  703. /**
  704. * Get the implementation-dependent name for an opened gamepad.
  705. *
  706. * The returned string follows the SDL_GetStringRule.
  707. *
  708. * \param gamepad a gamepad identifier previously returned by
  709. * SDL_OpenGamepad()
  710. * \returns the implementation dependent name for the gamepad, or NULL if
  711. * there is no name or the identifier passed is invalid.
  712. *
  713. * \since This function is available since SDL 3.0.0.
  714. *
  715. * \sa SDL_GetGamepadInstanceName
  716. */
  717. extern SDL_DECLSPEC const char *SDLCALL SDL_GetGamepadName(SDL_Gamepad *gamepad);
  718. /**
  719. * Get the implementation-dependent path for an opened gamepad.
  720. *
  721. * The returned string follows the SDL_GetStringRule.
  722. *
  723. * \param gamepad a gamepad identifier previously returned by
  724. * SDL_OpenGamepad()
  725. * \returns the implementation dependent path for the gamepad, or NULL if
  726. * there is no path or the identifier passed is invalid.
  727. *
  728. * \since This function is available since SDL 3.0.0.
  729. *
  730. * \sa SDL_GetGamepadInstancePath
  731. */
  732. extern SDL_DECLSPEC const char *SDLCALL SDL_GetGamepadPath(SDL_Gamepad *gamepad);
  733. /**
  734. * Get the type of an opened gamepad.
  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_GetGamepadInstanceType
  743. */
  744. extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetGamepadType(SDL_Gamepad *gamepad);
  745. /**
  746. * Get the type of an opened gamepad, ignoring any mapping override.
  747. *
  748. * \param gamepad the gamepad object to query.
  749. * \returns the gamepad type, or SDL_GAMEPAD_TYPE_UNKNOWN if it's not
  750. * available.
  751. *
  752. * \since This function is available since SDL 3.0.0.
  753. *
  754. * \sa SDL_GetRealGamepadInstanceType
  755. */
  756. extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetRealGamepadType(SDL_Gamepad *gamepad);
  757. /**
  758. * Get the player index of an opened gamepad.
  759. *
  760. * For XInput gamepads this returns the XInput user index.
  761. *
  762. * \param gamepad the gamepad object to query.
  763. * \returns the player index for gamepad, or -1 if it's not available.
  764. *
  765. * \since This function is available since SDL 3.0.0.
  766. *
  767. * \sa SDL_SetGamepadPlayerIndex
  768. */
  769. extern SDL_DECLSPEC int SDLCALL SDL_GetGamepadPlayerIndex(SDL_Gamepad *gamepad);
  770. /**
  771. * Set the player index of an opened gamepad.
  772. *
  773. * \param gamepad the gamepad object to adjust.
  774. * \param player_index Player index to assign to this gamepad, or -1 to clear
  775. * the player index and turn off player LEDs.
  776. * \returns 0 on success or a negative error code on failure; call
  777. * SDL_GetError() for more information.
  778. *
  779. * \since This function is available since SDL 3.0.0.
  780. *
  781. * \sa SDL_GetGamepadPlayerIndex
  782. */
  783. extern SDL_DECLSPEC int SDLCALL SDL_SetGamepadPlayerIndex(SDL_Gamepad *gamepad, int player_index);
  784. /**
  785. * Get the USB vendor ID of an opened gamepad, if available.
  786. *
  787. * If the vendor ID isn't available this function returns 0.
  788. *
  789. * \param gamepad the gamepad object to query.
  790. * \returns the USB vendor ID, or zero if unavailable.
  791. *
  792. * \since This function is available since SDL 3.0.0.
  793. *
  794. * \sa SDL_GetGamepadInstanceVendor
  795. */
  796. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadVendor(SDL_Gamepad *gamepad);
  797. /**
  798. * Get the USB product ID of an opened gamepad, if available.
  799. *
  800. * If the product ID isn't available this function returns 0.
  801. *
  802. * \param gamepad the gamepad object to query.
  803. * \returns the USB product ID, or zero if unavailable.
  804. *
  805. * \since This function is available since SDL 3.0.0.
  806. *
  807. * \sa SDL_GetGamepadInstanceProduct
  808. */
  809. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadProduct(SDL_Gamepad *gamepad);
  810. /**
  811. * Get the product version of an opened gamepad, if available.
  812. *
  813. * If the product version isn't available this function returns 0.
  814. *
  815. * \param gamepad the gamepad object to query.
  816. * \returns the USB product version, or zero if unavailable.
  817. *
  818. * \since This function is available since SDL 3.0.0.
  819. *
  820. * \sa SDL_GetGamepadInstanceProductVersion
  821. */
  822. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadProductVersion(SDL_Gamepad *gamepad);
  823. /**
  824. * Get the firmware version of an opened gamepad, if available.
  825. *
  826. * If the firmware version isn't available this function returns 0.
  827. *
  828. * \param gamepad the gamepad object to query.
  829. * \returns the gamepad firmware version, or zero if unavailable.
  830. *
  831. * \since This function is available since SDL 3.0.0.
  832. */
  833. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadFirmwareVersion(SDL_Gamepad *gamepad);
  834. /**
  835. * Get the serial number of an opened gamepad, if available.
  836. *
  837. * Returns the serial number of the gamepad, or NULL if it is not available.
  838. *
  839. * The returned string follows the SDL_GetStringRule.
  840. *
  841. * \param gamepad the gamepad object to query.
  842. * \returns the serial number, or NULL if unavailable.
  843. *
  844. * \since This function is available since SDL 3.0.0.
  845. */
  846. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadSerial(SDL_Gamepad *gamepad);
  847. /**
  848. * Get the Steam Input handle of an opened gamepad, if available.
  849. *
  850. * Returns an InputHandle_t for the gamepad that can be used with Steam Input
  851. * API: https://partner.steamgames.com/doc/api/ISteamInput
  852. *
  853. * \param gamepad the gamepad object to query.
  854. * \returns the gamepad handle, or 0 if unavailable.
  855. *
  856. * \since This function is available since SDL 3.0.0.
  857. */
  858. extern SDL_DECLSPEC Uint64 SDLCALL SDL_GetGamepadSteamHandle(SDL_Gamepad *gamepad);
  859. /**
  860. * Get the connection state of a gamepad.
  861. *
  862. * \param gamepad the gamepad object to query.
  863. * \returns the connection state on success or
  864. * `SDL_JOYSTICK_CONNECTION_INVALID` on failure; call SDL_GetError()
  865. * for more information.
  866. *
  867. * \since This function is available since SDL 3.0.0.
  868. */
  869. extern SDL_DECLSPEC SDL_JoystickConnectionState SDLCALL SDL_GetGamepadConnectionState(SDL_Gamepad *gamepad);
  870. /**
  871. * Get the battery state of a gamepad.
  872. *
  873. * You should never take a battery status as absolute truth. Batteries
  874. * (especially failing batteries) are delicate hardware, and the values
  875. * reported here are best estimates based on what that hardware reports. It's
  876. * not uncommon for older batteries to lose stored power much faster than it
  877. * reports, or completely drain when reporting it has 20 percent left, etc.
  878. *
  879. * \param gamepad the gamepad object to query.
  880. * \param percent a pointer filled in with the percentage of battery life
  881. * left, between 0 and 100, or NULL to ignore. This will be
  882. * filled in with -1 we can't determine a value or there is no
  883. * battery.
  884. * \returns the current battery state.
  885. *
  886. * \since This function is available since SDL 3.0.0.
  887. */
  888. extern SDL_DECLSPEC SDL_PowerState SDLCALL SDL_GetGamepadPowerInfo(SDL_Gamepad *gamepad, int *percent);
  889. /**
  890. * Check if a gamepad has been opened and is currently connected.
  891. *
  892. * \param gamepad a gamepad identifier previously returned by
  893. * SDL_OpenGamepad()
  894. * \returns SDL_TRUE if the gamepad has been opened and is currently
  895. * connected, or SDL_FALSE if not.
  896. *
  897. * \since This function is available since SDL 3.0.0.
  898. */
  899. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadConnected(SDL_Gamepad *gamepad);
  900. /**
  901. * Get the underlying joystick from a gamepad.
  902. *
  903. * This function will give you a SDL_Joystick object, which allows you to use
  904. * the SDL_Joystick functions with a SDL_Gamepad object. This would be useful
  905. * for getting a joystick's position at any given time, even if it hasn't
  906. * moved (moving it would produce an event, which would have the axis' value).
  907. *
  908. * The pointer returned is owned by the SDL_Gamepad. You should not call
  909. * SDL_CloseJoystick() on it, for example, since doing so will likely cause
  910. * SDL to crash.
  911. *
  912. * \param gamepad the gamepad object that you want to get a joystick from
  913. * \returns an SDL_Joystick object; call SDL_GetError() for more information.
  914. *
  915. * \since This function is available since SDL 3.0.0.
  916. */
  917. extern SDL_DECLSPEC SDL_Joystick *SDLCALL SDL_GetGamepadJoystick(SDL_Gamepad *gamepad);
  918. /**
  919. * Set the state of gamepad event processing.
  920. *
  921. * If gamepad events are disabled, you must call SDL_UpdateGamepads() yourself
  922. * and check the state of the gamepad when you want gamepad information.
  923. *
  924. * \param enabled whether to process gamepad events or not
  925. *
  926. * \since This function is available since SDL 3.0.0.
  927. *
  928. * \sa SDL_GamepadEventsEnabled
  929. * \sa SDL_UpdateGamepads
  930. */
  931. extern SDL_DECLSPEC void SDLCALL SDL_SetGamepadEventsEnabled(SDL_bool enabled);
  932. /**
  933. * Query the state of gamepad event processing.
  934. *
  935. * If gamepad events are disabled, you must call SDL_UpdateGamepads() yourself
  936. * and check the state of the gamepad when you want gamepad information.
  937. *
  938. * \returns SDL_TRUE if gamepad events are being processed, SDL_FALSE
  939. * otherwise.
  940. *
  941. * \since This function is available since SDL 3.0.0.
  942. *
  943. * \sa SDL_SetGamepadEventsEnabled
  944. */
  945. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadEventsEnabled(void);
  946. /**
  947. * Get the SDL joystick layer bindings for a gamepad.
  948. *
  949. * \param gamepad a gamepad
  950. * \param count a pointer filled in with the number of bindings returned
  951. * \returns a NULL terminated array of pointers to bindings which should be
  952. * freed with SDL_free(), or NULL on error; call SDL_GetError() for
  953. * more details.
  954. *
  955. * \since This function is available since SDL 3.0.0.
  956. */
  957. extern SDL_DECLSPEC SDL_GamepadBinding **SDLCALL SDL_GetGamepadBindings(SDL_Gamepad *gamepad, int *count);
  958. /**
  959. * Manually pump gamepad updates if not using the loop.
  960. *
  961. * This function is called automatically by the event loop if events are
  962. * enabled. Under such circumstances, it will not be necessary to call this
  963. * function.
  964. *
  965. * \since This function is available since SDL 3.0.0.
  966. */
  967. extern SDL_DECLSPEC void SDLCALL SDL_UpdateGamepads(void);
  968. /**
  969. * Convert a string into SDL_GamepadType enum.
  970. *
  971. * This function is called internally to translate SDL_Gamepad mapping strings
  972. * for the underlying joystick device into the consistent SDL_Gamepad mapping.
  973. * You do not normally need to call this function unless you are parsing
  974. * SDL_Gamepad mappings in your own code.
  975. *
  976. * \param str string representing a SDL_GamepadType type
  977. * \returns the SDL_GamepadType enum corresponding to the input string, or
  978. * `SDL_GAMEPAD_TYPE_UNKNOWN` if no match was found.
  979. *
  980. * \since This function is available since SDL 3.0.0.
  981. *
  982. * \sa SDL_GetGamepadStringForType
  983. */
  984. extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetGamepadTypeFromString(const char *str);
  985. /**
  986. * Convert from an SDL_GamepadType enum to a string.
  987. *
  988. * The returned string follows the SDL_GetStringRule.
  989. *
  990. * \param type an enum value for a given SDL_GamepadType
  991. * \returns a string for the given type, or NULL if an invalid type is
  992. * specified. The string returned is of the format used by
  993. * SDL_Gamepad mapping strings.
  994. *
  995. * \since This function is available since SDL 3.0.0.
  996. *
  997. * \sa SDL_GetGamepadTypeFromString
  998. */
  999. extern SDL_DECLSPEC const char *SDLCALL SDL_GetGamepadStringForType(SDL_GamepadType type);
  1000. /**
  1001. * Convert a string into SDL_GamepadAxis enum.
  1002. *
  1003. * This function is called internally to translate SDL_Gamepad mapping strings
  1004. * for the underlying joystick device into the consistent SDL_Gamepad mapping.
  1005. * You do not normally need to call this function unless you are parsing
  1006. * SDL_Gamepad mappings in your own code.
  1007. *
  1008. * Note specially that "righttrigger" and "lefttrigger" map to
  1009. * `SDL_GAMEPAD_AXIS_RIGHT_TRIGGER` and `SDL_GAMEPAD_AXIS_LEFT_TRIGGER`,
  1010. * respectively.
  1011. *
  1012. * \param str string representing a SDL_Gamepad axis
  1013. * \returns the SDL_GamepadAxis enum corresponding to the input string, or
  1014. * `SDL_GAMEPAD_AXIS_INVALID` if no match was found.
  1015. *
  1016. * \since This function is available since SDL 3.0.0.
  1017. *
  1018. * \sa SDL_GetGamepadStringForAxis
  1019. */
  1020. extern SDL_DECLSPEC SDL_GamepadAxis SDLCALL SDL_GetGamepadAxisFromString(const char *str);
  1021. /**
  1022. * Convert from an SDL_GamepadAxis enum to a string.
  1023. *
  1024. * The returned string follows the SDL_GetStringRule.
  1025. *
  1026. * \param axis an enum value for a given SDL_GamepadAxis
  1027. * \returns a string for the given axis, or NULL if an invalid axis is
  1028. * specified. The string returned is of the format used by
  1029. * SDL_Gamepad mapping strings.
  1030. *
  1031. * \since This function is available since SDL 3.0.0.
  1032. *
  1033. * \sa SDL_GetGamepadAxisFromString
  1034. */
  1035. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadStringForAxis(SDL_GamepadAxis axis);
  1036. /**
  1037. * Query whether a gamepad has a given axis.
  1038. *
  1039. * This merely reports whether the gamepad's mapping defined this axis, as
  1040. * that is all the information SDL has about the physical device.
  1041. *
  1042. * \param gamepad a gamepad
  1043. * \param axis an axis enum value (an SDL_GamepadAxis value)
  1044. * \returns SDL_TRUE if the gamepad has this axis, SDL_FALSE otherwise.
  1045. *
  1046. * \since This function is available since SDL 3.0.0.
  1047. *
  1048. * \sa SDL_GamepadHasButton
  1049. * \sa SDL_GetGamepadAxis
  1050. */
  1051. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadHasAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis);
  1052. /**
  1053. * Get the current state of an axis control on a gamepad.
  1054. *
  1055. * The axis indices start at index 0.
  1056. *
  1057. * For thumbsticks, the state is a value ranging from -32768 (up/left) to
  1058. * 32767 (down/right).
  1059. *
  1060. * Triggers range from 0 when released to 32767 when fully pressed, and never
  1061. * return a negative value. Note that this differs from the value reported by
  1062. * the lower-level SDL_GetJoystickAxis(), which normally uses the full range.
  1063. *
  1064. * \param gamepad a gamepad
  1065. * \param axis an axis index (one of the SDL_GamepadAxis values)
  1066. * \returns axis state (including 0) on success or 0 (also) on failure; call
  1067. * SDL_GetError() for more information.
  1068. *
  1069. * \since This function is available since SDL 3.0.0.
  1070. *
  1071. * \sa SDL_GamepadHasAxis
  1072. * \sa SDL_GetGamepadButton
  1073. */
  1074. extern SDL_DECLSPEC Sint16 SDLCALL SDL_GetGamepadAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis);
  1075. /**
  1076. * Convert a string into an SDL_GamepadButton enum.
  1077. *
  1078. * This function is called internally to translate SDL_Gamepad mapping strings
  1079. * for the underlying joystick device into the consistent SDL_Gamepad mapping.
  1080. * You do not normally need to call this function unless you are parsing
  1081. * SDL_Gamepad mappings in your own code.
  1082. *
  1083. * \param str string representing a SDL_Gamepad axis
  1084. * \returns the SDL_GamepadButton enum corresponding to the input string, or
  1085. * `SDL_GAMEPAD_BUTTON_INVALID` if no match was found.
  1086. *
  1087. * \since This function is available since SDL 3.0.0.
  1088. *
  1089. * \sa SDL_GetGamepadStringForButton
  1090. */
  1091. extern SDL_DECLSPEC SDL_GamepadButton SDLCALL SDL_GetGamepadButtonFromString(const char *str);
  1092. /**
  1093. * Convert from an SDL_GamepadButton enum to a string.
  1094. *
  1095. * The returned string follows the SDL_GetStringRule.
  1096. *
  1097. * \param button an enum value for a given SDL_GamepadButton
  1098. * \returns a string for the given button, or NULL if an invalid button is
  1099. * specified. The string returned is of the format used by
  1100. * SDL_Gamepad mapping strings.
  1101. *
  1102. * \since This function is available since SDL 3.0.0.
  1103. *
  1104. * \sa SDL_GetGamepadButtonFromString
  1105. */
  1106. extern SDL_DECLSPEC const char* SDLCALL SDL_GetGamepadStringForButton(SDL_GamepadButton button);
  1107. /**
  1108. * Query whether a gamepad has a given button.
  1109. *
  1110. * This merely reports whether the gamepad's mapping defined this button, as
  1111. * that is all the information SDL has about the physical device.
  1112. *
  1113. * \param gamepad a gamepad
  1114. * \param button a button enum value (an SDL_GamepadButton value)
  1115. * \returns SDL_TRUE if the gamepad has this button, SDL_FALSE otherwise.
  1116. *
  1117. * \since This function is available since SDL 3.0.0.
  1118. *
  1119. * \sa SDL_GamepadHasAxis
  1120. */
  1121. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadHasButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
  1122. /**
  1123. * Get the current state of a button on a gamepad.
  1124. *
  1125. * \param gamepad a gamepad
  1126. * \param button a button index (one of the SDL_GamepadButton values)
  1127. * \returns 1 for pressed state or 0 for not pressed state or error; call
  1128. * SDL_GetError() for more information.
  1129. *
  1130. * \since This function is available since SDL 3.0.0.
  1131. *
  1132. * \sa SDL_GamepadHasButton
  1133. * \sa SDL_GetGamepadAxis
  1134. */
  1135. extern SDL_DECLSPEC Uint8 SDLCALL SDL_GetGamepadButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
  1136. /**
  1137. * Get the label of a button on a gamepad.
  1138. *
  1139. * \param type the type of gamepad to check
  1140. * \param button a button index (one of the SDL_GamepadButton values)
  1141. * \returns the SDL_GamepadButtonLabel enum corresponding to the button label
  1142. *
  1143. * \since This function is available since SDL 3.0.0.
  1144. *
  1145. * \sa SDL_GetGamepadButtonLabel
  1146. */
  1147. extern SDL_DECLSPEC SDL_GamepadButtonLabel SDLCALL SDL_GetGamepadButtonLabelForType(SDL_GamepadType type, SDL_GamepadButton button);
  1148. /**
  1149. * Get the label of a button on a gamepad.
  1150. *
  1151. * \param gamepad a gamepad
  1152. * \param button a button index (one of the SDL_GamepadButton values)
  1153. * \returns the SDL_GamepadButtonLabel enum corresponding to the button label
  1154. *
  1155. * \since This function is available since SDL 3.0.0.
  1156. *
  1157. * \sa SDL_GetGamepadButtonLabelForType
  1158. */
  1159. extern SDL_DECLSPEC SDL_GamepadButtonLabel SDLCALL SDL_GetGamepadButtonLabel(SDL_Gamepad *gamepad, SDL_GamepadButton button);
  1160. /**
  1161. * Get the number of touchpads on a gamepad.
  1162. *
  1163. * \param gamepad a gamepad
  1164. * \returns number of touchpads
  1165. *
  1166. * \since This function is available since SDL 3.0.0.
  1167. *
  1168. * \sa SDL_GetNumGamepadTouchpadFingers
  1169. */
  1170. extern SDL_DECLSPEC int SDLCALL SDL_GetNumGamepadTouchpads(SDL_Gamepad *gamepad);
  1171. /**
  1172. * Get the number of supported simultaneous fingers on a touchpad on a game
  1173. * gamepad.
  1174. *
  1175. * \param gamepad a gamepad
  1176. * \param touchpad a touchpad
  1177. * \returns number of supported simultaneous fingers
  1178. *
  1179. * \since This function is available since SDL 3.0.0.
  1180. *
  1181. * \sa SDL_GetGamepadTouchpadFinger
  1182. * \sa SDL_GetNumGamepadTouchpads
  1183. */
  1184. extern SDL_DECLSPEC int SDLCALL SDL_GetNumGamepadTouchpadFingers(SDL_Gamepad *gamepad, int touchpad);
  1185. /**
  1186. * Get the current state of a finger on a touchpad on a gamepad.
  1187. *
  1188. * \param gamepad a gamepad
  1189. * \param touchpad a touchpad
  1190. * \param finger a finger
  1191. * \param state filled with state
  1192. * \param x filled with x position, normalized 0 to 1, with the origin in the
  1193. * upper left
  1194. * \param y filled with y position, normalized 0 to 1, with the origin in the
  1195. * upper left
  1196. * \param pressure filled with pressure value
  1197. * \returns 0 on success or a negative error code on failure; call
  1198. * SDL_GetError() for more information.
  1199. *
  1200. * \since This function is available since SDL 3.0.0.
  1201. *
  1202. * \sa SDL_GetNumGamepadTouchpadFingers
  1203. */
  1204. extern SDL_DECLSPEC int SDLCALL SDL_GetGamepadTouchpadFinger(SDL_Gamepad *gamepad, int touchpad, int finger, Uint8 *state, float *x, float *y, float *pressure);
  1205. /**
  1206. * Return whether a gamepad has a particular sensor.
  1207. *
  1208. * \param gamepad The gamepad to query
  1209. * \param type The type of sensor to query
  1210. * \returns SDL_TRUE if the sensor exists, SDL_FALSE otherwise.
  1211. *
  1212. * \since This function is available since SDL 3.0.0.
  1213. *
  1214. * \sa SDL_GetGamepadSensorData
  1215. * \sa SDL_GetGamepadSensorDataRate
  1216. * \sa SDL_SetGamepadSensorEnabled
  1217. */
  1218. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadHasSensor(SDL_Gamepad *gamepad, SDL_SensorType type);
  1219. /**
  1220. * Set whether data reporting for a gamepad sensor is enabled.
  1221. *
  1222. * \param gamepad The gamepad to update
  1223. * \param type The type of sensor to enable/disable
  1224. * \param enabled Whether data reporting should be enabled
  1225. * \returns 0 on success or a negative error code on failure; call
  1226. * SDL_GetError() for more information.
  1227. *
  1228. * \since This function is available since SDL 3.0.0.
  1229. *
  1230. * \sa SDL_GamepadHasSensor
  1231. * \sa SDL_GamepadSensorEnabled
  1232. */
  1233. extern SDL_DECLSPEC int SDLCALL SDL_SetGamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type, SDL_bool enabled);
  1234. /**
  1235. * Query whether sensor data reporting is enabled for a gamepad.
  1236. *
  1237. * \param gamepad The gamepad to query
  1238. * \param type The type of sensor to query
  1239. * \returns SDL_TRUE if the sensor is enabled, SDL_FALSE otherwise.
  1240. *
  1241. * \since This function is available since SDL 3.0.0.
  1242. *
  1243. * \sa SDL_SetGamepadSensorEnabled
  1244. */
  1245. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type);
  1246. /**
  1247. * Get the data rate (number of events per second) of a gamepad sensor.
  1248. *
  1249. * \param gamepad The gamepad to query
  1250. * \param type The type of sensor to query
  1251. * \returns the data rate, or 0.0f if the data rate is not available.
  1252. *
  1253. * \since This function is available since SDL 3.0.0.
  1254. */
  1255. extern SDL_DECLSPEC float SDLCALL SDL_GetGamepadSensorDataRate(SDL_Gamepad *gamepad, SDL_SensorType type);
  1256. /**
  1257. * Get the current state of a gamepad sensor.
  1258. *
  1259. * The number of values and interpretation of the data is sensor dependent.
  1260. * See SDL_sensor.h for the details for each type of sensor.
  1261. *
  1262. * \param gamepad The gamepad to query
  1263. * \param type The type of sensor to query
  1264. * \param data A pointer filled with the current sensor state
  1265. * \param num_values The number of values to write to data
  1266. * \returns 0 on success or a negative error code on failure; call
  1267. * SDL_GetError() for more information.
  1268. *
  1269. * \since This function is available since SDL 3.0.0.
  1270. */
  1271. extern SDL_DECLSPEC int SDLCALL SDL_GetGamepadSensorData(SDL_Gamepad *gamepad, SDL_SensorType type, float *data, int num_values);
  1272. /**
  1273. * Start a rumble effect on a gamepad.
  1274. *
  1275. * Each call to this function cancels any previous rumble effect, and calling
  1276. * it with 0 intensity stops any rumbling.
  1277. *
  1278. * This function requires you to process SDL events or call
  1279. * SDL_UpdateJoysticks() to update rumble state.
  1280. *
  1281. * \param gamepad The gamepad to vibrate
  1282. * \param low_frequency_rumble The intensity of the low frequency (left)
  1283. * rumble motor, from 0 to 0xFFFF
  1284. * \param high_frequency_rumble The intensity of the high frequency (right)
  1285. * rumble motor, from 0 to 0xFFFF
  1286. * \param duration_ms The duration of the rumble effect, in milliseconds
  1287. * \returns 0, or -1 if rumble isn't supported on this gamepad
  1288. *
  1289. * \since This function is available since SDL 3.0.0.
  1290. */
  1291. extern SDL_DECLSPEC int SDLCALL SDL_RumbleGamepad(SDL_Gamepad *gamepad, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
  1292. /**
  1293. * Start a rumble effect in the gamepad's triggers.
  1294. *
  1295. * Each call to this function cancels any previous trigger rumble effect, and
  1296. * calling it with 0 intensity stops any rumbling.
  1297. *
  1298. * Note that this is rumbling of the _triggers_ and not the gamepad as a
  1299. * whole. This is currently only supported on Xbox One gamepads. If you want
  1300. * the (more common) whole-gamepad rumble, use SDL_RumbleGamepad() instead.
  1301. *
  1302. * This function requires you to process SDL events or call
  1303. * SDL_UpdateJoysticks() to update rumble state.
  1304. *
  1305. * \param gamepad The gamepad to vibrate
  1306. * \param left_rumble The intensity of the left trigger rumble motor, from 0
  1307. * to 0xFFFF
  1308. * \param right_rumble The intensity of the right trigger rumble motor, from 0
  1309. * to 0xFFFF
  1310. * \param duration_ms The duration of the rumble effect, in milliseconds
  1311. * \returns 0 on success or a negative error code on failure; call
  1312. * SDL_GetError() for more information.
  1313. *
  1314. * \since This function is available since SDL 3.0.0.
  1315. *
  1316. * \sa SDL_RumbleGamepad
  1317. */
  1318. extern SDL_DECLSPEC int SDLCALL SDL_RumbleGamepadTriggers(SDL_Gamepad *gamepad, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms);
  1319. /**
  1320. * Update a gamepad's LED color.
  1321. *
  1322. * An example of a joystick LED is the light on the back of a PlayStation 4's
  1323. * DualShock 4 controller.
  1324. *
  1325. * For gamepads with a single color LED, the maximum of the RGB values will be
  1326. * used as the LED brightness.
  1327. *
  1328. * \param gamepad The gamepad to update
  1329. * \param red The intensity of the red LED
  1330. * \param green The intensity of the green LED
  1331. * \param blue The intensity of the blue LED
  1332. * \returns 0 on success or a negative error code on failure; call
  1333. * SDL_GetError() for more information.
  1334. *
  1335. * \since This function is available since SDL 3.0.0.
  1336. */
  1337. extern SDL_DECLSPEC int SDLCALL SDL_SetGamepadLED(SDL_Gamepad *gamepad, Uint8 red, Uint8 green, Uint8 blue);
  1338. /**
  1339. * Send a gamepad specific effect packet.
  1340. *
  1341. * \param gamepad The gamepad to affect
  1342. * \param data The data to send to the gamepad
  1343. * \param size The size of the data to send to the gamepad
  1344. * \returns 0 on success or a negative error code on failure; call
  1345. * SDL_GetError() for more information.
  1346. *
  1347. * \since This function is available since SDL 3.0.0.
  1348. */
  1349. extern SDL_DECLSPEC int SDLCALL SDL_SendGamepadEffect(SDL_Gamepad *gamepad, const void *data, int size);
  1350. /**
  1351. * Close a gamepad previously opened with SDL_OpenGamepad().
  1352. *
  1353. * \param gamepad a gamepad identifier previously returned by
  1354. * SDL_OpenGamepad()
  1355. *
  1356. * \since This function is available since SDL 3.0.0.
  1357. *
  1358. * \sa SDL_OpenGamepad
  1359. */
  1360. extern SDL_DECLSPEC void SDLCALL SDL_CloseGamepad(SDL_Gamepad *gamepad);
  1361. /**
  1362. * Return the sfSymbolsName for a given button on a gamepad on Apple
  1363. * platforms.
  1364. *
  1365. * The returned string follows the SDL_GetStringRule.
  1366. *
  1367. * \param gamepad the gamepad to query
  1368. * \param button a button on the gamepad
  1369. * \returns the sfSymbolsName or NULL if the name can't be found
  1370. *
  1371. * \since This function is available since SDL 3.0.0.
  1372. *
  1373. * \sa SDL_GetGamepadAppleSFSymbolsNameForAxis
  1374. */
  1375. extern SDL_DECLSPEC const char* SDLCALL SDL_GetGamepadAppleSFSymbolsNameForButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
  1376. /**
  1377. * Return the sfSymbolsName for a given axis on a gamepad on Apple platforms.
  1378. *
  1379. * The returned string follows the SDL_GetStringRule.
  1380. *
  1381. * \param gamepad the gamepad to query
  1382. * \param axis an axis on the gamepad
  1383. * \returns the sfSymbolsName or NULL if the name can't be found
  1384. *
  1385. * \since This function is available since SDL 3.0.0.
  1386. *
  1387. * \sa SDL_GetGamepadAppleSFSymbolsNameForButton
  1388. */
  1389. extern SDL_DECLSPEC const char* SDLCALL SDL_GetGamepadAppleSFSymbolsNameForAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis);
  1390. /* Ends C function definitions when using C++ */
  1391. #ifdef __cplusplus
  1392. }
  1393. #endif
  1394. #include <SDL3/SDL_close_code.h>
  1395. #endif /* SDL_gamepad_h_ */