SDL_gamepad.h 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * # CategoryGamepad
  20. *
  21. * SDL provides a low-level joystick API, which just treats joysticks as an
  22. * arbitrary pile of buttons, axes, and hat switches. If you're planning to
  23. * write your own control configuration screen, this can give you a lot of
  24. * flexibility, but that's a lot of work, and most things that we consider
  25. * "joysticks" now are actually console-style gamepads. So SDL provides the
  26. * gamepad API on top of the lower-level joystick functionality.
  27. *
  28. * The difference betweena joystick and a gamepad is that a gamepad tells you
  29. * _where_ a button or axis is on the device. You don't speak to gamepads in
  30. * terms of arbitrary numbers like "button 3" or "axis 2" but in standard
  31. * locations: the d-pad, the shoulder buttons, triggers, A/B/X/Y (or
  32. * X/O/Square/Triangle, if you will).
  33. *
  34. * One turns a joystick into a gamepad by providing a magic configuration
  35. * string, which tells SDL the details of a specific device: when you see this
  36. * specific hardware, if button 2 gets pressed, this is actually D-Pad Up,
  37. * etc.
  38. *
  39. * SDL has many popular controllers configured out of the box, and users can
  40. * add their own controller details through an environment variable if it's
  41. * otherwise unknown to SDL.
  42. *
  43. * In order to use these functions, SDL_Init() must have been called with the
  44. * SDL_INIT_GAMEPAD flag. This causes SDL to scan the system for gamepads, and
  45. * load appropriate drivers.
  46. *
  47. * If you would like to receive gamepad updates while the application is in
  48. * the background, you should set the following hint before calling
  49. * SDL_Init(): SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS
  50. */
  51. #ifndef SDL_gamepad_h_
  52. #define SDL_gamepad_h_
  53. #include <SDL3/SDL_stdinc.h>
  54. #include <SDL3/SDL_error.h>
  55. #include <SDL3/SDL_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. * The returned pointer follows the SDL_GetStringRule.
  367. *
  368. * \param count a pointer filled in with the number of mappings returned, can
  369. * be NULL.
  370. * \returns an array of the mapping strings, NULL-terminated. Returns NULL on
  371. * error.
  372. *
  373. * \since This function is available since SDL 3.0.0.
  374. */
  375. extern SDL_DECLSPEC const char * const * SDLCALL SDL_GetGamepadMappings(int *count);
  376. /**
  377. * Get the gamepad mapping string for a given GUID.
  378. *
  379. * The returned string follows the SDL_GetStringRule.
  380. *
  381. * \param guid a structure containing the GUID for which a mapping is desired.
  382. * \returns a mapping string or NULL on error; call SDL_GetError() for more
  383. * information.
  384. *
  385. * \since This function is available since SDL 3.0.0.
  386. *
  387. * \sa SDL_GetJoystickGUIDForID
  388. * \sa SDL_GetJoystickGUID
  389. */
  390. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadMappingForGUID(SDL_JoystickGUID guid);
  391. /**
  392. * Get the current mapping of a gamepad.
  393. *
  394. * The returned string follows the SDL_GetStringRule.
  395. *
  396. * Details about mappings are discussed with SDL_AddGamepadMapping().
  397. *
  398. * \param gamepad the gamepad you want to get the current mapping for.
  399. * \returns a string that has the gamepad's mapping or NULL if no mapping is
  400. * available; call SDL_GetError() for more information.
  401. *
  402. * \since This function is available since SDL 3.0.0.
  403. *
  404. * \sa SDL_AddGamepadMapping
  405. * \sa SDL_GetGamepadMappingForID
  406. * \sa SDL_GetGamepadMappingForGUID
  407. * \sa SDL_SetGamepadMapping
  408. */
  409. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadMapping(SDL_Gamepad *gamepad);
  410. /**
  411. * Set the current mapping of a joystick or gamepad.
  412. *
  413. * Details about mappings are discussed with SDL_AddGamepadMapping().
  414. *
  415. * \param instance_id the joystick instance ID.
  416. * \param mapping the mapping to use for this device, or NULL to clear the
  417. * mapping.
  418. * \returns 0 on success or a negative error code on failure; call
  419. * SDL_GetError() for more information.
  420. *
  421. * \since This function is available since SDL 3.0.0.
  422. *
  423. * \sa SDL_AddGamepadMapping
  424. * \sa SDL_GetGamepadMapping
  425. */
  426. extern SDL_DECLSPEC int SDLCALL SDL_SetGamepadMapping(SDL_JoystickID instance_id, const char *mapping);
  427. /**
  428. * Return whether a gamepad is currently connected.
  429. *
  430. * \returns SDL_TRUE if a gamepad is connected, SDL_FALSE otherwise.
  431. *
  432. * \since This function is available since SDL 3.0.0.
  433. *
  434. * \sa SDL_GetGamepads
  435. */
  436. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasGamepad(void);
  437. /**
  438. * Get a list of currently connected gamepads.
  439. *
  440. * \param count a pointer filled in with the number of gamepads returned.
  441. * \returns a 0 terminated array of joystick instance IDs which should be
  442. * freed with SDL_free(), or NULL on error; call SDL_GetError() for
  443. * more details.
  444. *
  445. * \since This function is available since SDL 3.0.0.
  446. *
  447. * \sa SDL_HasGamepad
  448. * \sa SDL_OpenGamepad
  449. */
  450. extern SDL_DECLSPEC SDL_JoystickID *SDLCALL SDL_GetGamepads(int *count);
  451. /**
  452. * Check if the given joystick is supported by the gamepad interface.
  453. *
  454. * \param instance_id the joystick instance ID.
  455. * \returns SDL_TRUE if the given joystick is supported by the gamepad
  456. * interface, SDL_FALSE if it isn't or it's an invalid index.
  457. *
  458. * \since This function is available since SDL 3.0.0.
  459. *
  460. * \sa SDL_GetJoysticks
  461. * \sa SDL_OpenGamepad
  462. */
  463. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_IsGamepad(SDL_JoystickID instance_id);
  464. /**
  465. * Get the implementation dependent name of a gamepad.
  466. *
  467. * This can be called before any gamepads are opened.
  468. *
  469. * The returned string follows the SDL_GetStringRule.
  470. *
  471. * \param instance_id the joystick instance ID.
  472. * \returns the name of the selected gamepad. If no name can be found, this
  473. * function returns NULL; call SDL_GetError() for more information.
  474. *
  475. * \since This function is available since SDL 3.0.0.
  476. *
  477. * \sa SDL_GetGamepadName
  478. * \sa SDL_GetGamepads
  479. */
  480. extern SDL_DECLSPEC const char *SDLCALL SDL_GetGamepadNameForID(SDL_JoystickID instance_id);
  481. /**
  482. * Get the implementation dependent path of a gamepad.
  483. *
  484. * This can be called before any gamepads are opened.
  485. *
  486. * The returned string follows the SDL_GetStringRule.
  487. *
  488. * \param instance_id the joystick instance ID.
  489. * \returns the path of the selected gamepad. If no path can be found, this
  490. * function returns NULL; call SDL_GetError() for more information.
  491. *
  492. * \since This function is available since SDL 3.0.0.
  493. *
  494. * \sa SDL_GetGamepadPath
  495. * \sa SDL_GetGamepads
  496. */
  497. extern SDL_DECLSPEC const char *SDLCALL SDL_GetGamepadPathForID(SDL_JoystickID instance_id);
  498. /**
  499. * Get the player index of a gamepad.
  500. *
  501. * This can be called before any gamepads are opened.
  502. *
  503. * \param instance_id the joystick instance ID.
  504. * \returns the player index of a gamepad, or -1 if it's not available.
  505. *
  506. * \since This function is available since SDL 3.0.0.
  507. *
  508. * \sa SDL_GetGamepadPlayerIndex
  509. * \sa SDL_GetGamepads
  510. */
  511. extern SDL_DECLSPEC int SDLCALL SDL_GetGamepadPlayerIndexForID(SDL_JoystickID instance_id);
  512. /**
  513. * Get the implementation-dependent GUID of a gamepad.
  514. *
  515. * This can be called before any gamepads are opened.
  516. *
  517. * \param instance_id the joystick instance ID.
  518. * \returns the GUID of the selected gamepad. If called on an invalid index,
  519. * this function returns a zero GUID.
  520. *
  521. * \since This function is available since SDL 3.0.0.
  522. *
  523. * \sa SDL_GetGamepadGUID
  524. * \sa SDL_GetGamepadGUIDString
  525. * \sa SDL_GetGamepads
  526. */
  527. extern SDL_DECLSPEC SDL_JoystickGUID SDLCALL SDL_GetGamepadGUIDForID(SDL_JoystickID instance_id);
  528. /**
  529. * Get the USB vendor ID of a gamepad, if available.
  530. *
  531. * This can be called before any gamepads are opened. If the vendor ID isn't
  532. * available this function returns 0.
  533. *
  534. * \param instance_id the joystick instance ID.
  535. * \returns the USB vendor ID of the selected gamepad. If called on an invalid
  536. * index, this function returns zero.
  537. *
  538. * \since This function is available since SDL 3.0.0.
  539. *
  540. * \sa SDL_GetGamepadVendor
  541. * \sa SDL_GetGamepads
  542. */
  543. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadVendorForID(SDL_JoystickID instance_id);
  544. /**
  545. * Get the USB product ID of a gamepad, if available.
  546. *
  547. * This can be called before any gamepads are opened. If the product ID isn't
  548. * available this function returns 0.
  549. *
  550. * \param instance_id the joystick instance ID.
  551. * \returns the USB product ID of the selected gamepad. If called on an
  552. * invalid index, this function returns zero.
  553. *
  554. * \since This function is available since SDL 3.0.0.
  555. *
  556. * \sa SDL_GetGamepadProduct
  557. * \sa SDL_GetGamepads
  558. */
  559. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadProductForID(SDL_JoystickID instance_id);
  560. /**
  561. * Get the product version of a gamepad, if available.
  562. *
  563. * This can be called before any gamepads are opened. If the product version
  564. * isn't available this function returns 0.
  565. *
  566. * \param instance_id the joystick instance ID.
  567. * \returns the product version of the selected gamepad. If called on an
  568. * invalid index, this function returns zero.
  569. *
  570. * \since This function is available since SDL 3.0.0.
  571. *
  572. * \sa SDL_GetGamepadProductVersion
  573. * \sa SDL_GetGamepads
  574. */
  575. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadProductVersionForID(SDL_JoystickID instance_id);
  576. /**
  577. * Get the type of a gamepad.
  578. *
  579. * This can be called before any gamepads are opened.
  580. *
  581. * \param instance_id the joystick instance ID.
  582. * \returns the gamepad type.
  583. *
  584. * \since This function is available since SDL 3.0.0.
  585. *
  586. * \sa SDL_GetGamepadType
  587. * \sa SDL_GetGamepads
  588. * \sa SDL_GetRealGamepadTypeForID
  589. */
  590. extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetGamepadTypeForID(SDL_JoystickID instance_id);
  591. /**
  592. * Get the type of a gamepad, ignoring any mapping override.
  593. *
  594. * This can be called before any gamepads are opened.
  595. *
  596. * \param instance_id the joystick instance ID.
  597. * \returns the gamepad type.
  598. *
  599. * \since This function is available since SDL 3.0.0.
  600. *
  601. * \sa SDL_GetGamepadTypeForID
  602. * \sa SDL_GetGamepads
  603. * \sa SDL_GetRealGamepadType
  604. */
  605. extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetRealGamepadTypeForID(SDL_JoystickID instance_id);
  606. /**
  607. * Get the mapping of a gamepad.
  608. *
  609. * This can be called before any gamepads are opened.
  610. *
  611. * The returned string follows the SDL_GetStringRule.
  612. *
  613. * \param instance_id the joystick instance ID.
  614. * \returns the mapping string. Returns NULL if 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 const char *SDLCALL SDL_GetGamepadMappingForID(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_GetGamepadFromID(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. extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetGamepadProperties(SDL_Gamepad *gamepad);
  684. #define SDL_PROP_GAMEPAD_CAP_MONO_LED_BOOLEAN SDL_PROP_JOYSTICK_CAP_MONO_LED_BOOLEAN
  685. #define SDL_PROP_GAMEPAD_CAP_RGB_LED_BOOLEAN SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN
  686. #define SDL_PROP_GAMEPAD_CAP_PLAYER_LED_BOOLEAN SDL_PROP_JOYSTICK_CAP_PLAYER_LED_BOOLEAN
  687. #define SDL_PROP_GAMEPAD_CAP_RUMBLE_BOOLEAN SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN
  688. #define SDL_PROP_GAMEPAD_CAP_TRIGGER_RUMBLE_BOOLEAN SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN
  689. /**
  690. * Get the instance ID of an opened gamepad.
  691. *
  692. * \param gamepad a gamepad identifier previously returned by
  693. * SDL_OpenGamepad().
  694. * \returns the instance ID of the specified gamepad on success or 0 on
  695. * failure; call SDL_GetError() for more information.
  696. *
  697. * \since This function is available since SDL 3.0.0.
  698. */
  699. extern SDL_DECLSPEC SDL_JoystickID SDLCALL SDL_GetGamepadID(SDL_Gamepad *gamepad);
  700. /**
  701. * Get the implementation-dependent name for an opened gamepad.
  702. *
  703. * The returned string follows the SDL_GetStringRule.
  704. *
  705. * \param gamepad a gamepad identifier previously returned by
  706. * SDL_OpenGamepad().
  707. * \returns the implementation dependent name for the gamepad, or NULL if
  708. * there is no name or the identifier passed is invalid.
  709. *
  710. * \since This function is available since SDL 3.0.0.
  711. *
  712. * \sa SDL_GetGamepadNameForID
  713. */
  714. extern SDL_DECLSPEC const char *SDLCALL SDL_GetGamepadName(SDL_Gamepad *gamepad);
  715. /**
  716. * Get the implementation-dependent path for an opened gamepad.
  717. *
  718. * The returned string follows the SDL_GetStringRule.
  719. *
  720. * \param gamepad a gamepad identifier previously returned by
  721. * SDL_OpenGamepad().
  722. * \returns the implementation dependent path for the gamepad, or NULL if
  723. * there is no path or the identifier passed is invalid.
  724. *
  725. * \since This function is available since SDL 3.0.0.
  726. *
  727. * \sa SDL_GetGamepadPathForID
  728. */
  729. extern SDL_DECLSPEC const char *SDLCALL SDL_GetGamepadPath(SDL_Gamepad *gamepad);
  730. /**
  731. * Get the type of an opened gamepad.
  732. *
  733. * \param gamepad the gamepad object to query.
  734. * \returns the gamepad type, or SDL_GAMEPAD_TYPE_UNKNOWN if it's not
  735. * available.
  736. *
  737. * \since This function is available since SDL 3.0.0.
  738. *
  739. * \sa SDL_GetGamepadTypeForID
  740. */
  741. extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetGamepadType(SDL_Gamepad *gamepad);
  742. /**
  743. * Get the type of an opened gamepad, ignoring any mapping override.
  744. *
  745. * \param gamepad the gamepad object to query.
  746. * \returns the gamepad type, or SDL_GAMEPAD_TYPE_UNKNOWN if it's not
  747. * available.
  748. *
  749. * \since This function is available since SDL 3.0.0.
  750. *
  751. * \sa SDL_GetRealGamepadTypeForID
  752. */
  753. extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetRealGamepadType(SDL_Gamepad *gamepad);
  754. /**
  755. * Get the player index of an opened gamepad.
  756. *
  757. * For XInput gamepads this returns the XInput user index.
  758. *
  759. * \param gamepad the gamepad object to query.
  760. * \returns the player index for gamepad, or -1 if it's not available.
  761. *
  762. * \since This function is available since SDL 3.0.0.
  763. *
  764. * \sa SDL_SetGamepadPlayerIndex
  765. */
  766. extern SDL_DECLSPEC int SDLCALL SDL_GetGamepadPlayerIndex(SDL_Gamepad *gamepad);
  767. /**
  768. * Set the player index of an opened gamepad.
  769. *
  770. * \param gamepad the gamepad object to adjust.
  771. * \param player_index player index to assign to this gamepad, or -1 to clear
  772. * the player index and turn off player LEDs.
  773. * \returns 0 on success or a negative error code on failure; call
  774. * SDL_GetError() for more information.
  775. *
  776. * \since This function is available since SDL 3.0.0.
  777. *
  778. * \sa SDL_GetGamepadPlayerIndex
  779. */
  780. extern SDL_DECLSPEC int SDLCALL SDL_SetGamepadPlayerIndex(SDL_Gamepad *gamepad, int player_index);
  781. /**
  782. * Get the USB vendor ID of an opened gamepad, if available.
  783. *
  784. * If the vendor ID isn't available this function returns 0.
  785. *
  786. * \param gamepad the gamepad object to query.
  787. * \returns the USB vendor ID, or zero if unavailable.
  788. *
  789. * \since This function is available since SDL 3.0.0.
  790. *
  791. * \sa SDL_GetGamepadVendorForID
  792. */
  793. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadVendor(SDL_Gamepad *gamepad);
  794. /**
  795. * Get the USB product ID of an opened gamepad, if available.
  796. *
  797. * If the product ID isn't available this function returns 0.
  798. *
  799. * \param gamepad the gamepad object to query.
  800. * \returns the USB product ID, or zero if unavailable.
  801. *
  802. * \since This function is available since SDL 3.0.0.
  803. *
  804. * \sa SDL_GetGamepadProductForID
  805. */
  806. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadProduct(SDL_Gamepad *gamepad);
  807. /**
  808. * Get the product version of an opened gamepad, if available.
  809. *
  810. * If the product version isn't available this function returns 0.
  811. *
  812. * \param gamepad the gamepad object to query.
  813. * \returns the USB product version, or zero if unavailable.
  814. *
  815. * \since This function is available since SDL 3.0.0.
  816. *
  817. * \sa SDL_GetGamepadProductVersionForID
  818. */
  819. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadProductVersion(SDL_Gamepad *gamepad);
  820. /**
  821. * Get the firmware version of an opened gamepad, if available.
  822. *
  823. * If the firmware version isn't available this function returns 0.
  824. *
  825. * \param gamepad the gamepad object to query.
  826. * \returns the gamepad firmware version, or zero if unavailable.
  827. *
  828. * \since This function is available since SDL 3.0.0.
  829. */
  830. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadFirmwareVersion(SDL_Gamepad *gamepad);
  831. /**
  832. * Get the serial number of an opened gamepad, if available.
  833. *
  834. * Returns the serial number of the gamepad, or NULL if it is not available.
  835. *
  836. * The returned string follows the SDL_GetStringRule.
  837. *
  838. * \param gamepad the gamepad object to query.
  839. * \returns the serial number, or NULL if unavailable.
  840. *
  841. * \since This function is available since SDL 3.0.0.
  842. */
  843. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadSerial(SDL_Gamepad *gamepad);
  844. /**
  845. * Get the Steam Input handle of an opened gamepad, if available.
  846. *
  847. * Returns an InputHandle_t for the gamepad that can be used with Steam Input
  848. * API: https://partner.steamgames.com/doc/api/ISteamInput
  849. *
  850. * \param gamepad the gamepad object to query.
  851. * \returns the gamepad handle, or 0 if unavailable.
  852. *
  853. * \since This function is available since SDL 3.0.0.
  854. */
  855. extern SDL_DECLSPEC Uint64 SDLCALL SDL_GetGamepadSteamHandle(SDL_Gamepad *gamepad);
  856. /**
  857. * Get the connection state of a gamepad.
  858. *
  859. * \param gamepad the gamepad object to query.
  860. * \returns the connection state on success or
  861. * `SDL_JOYSTICK_CONNECTION_INVALID` on failure; call SDL_GetError()
  862. * for more information.
  863. *
  864. * \since This function is available since SDL 3.0.0.
  865. */
  866. extern SDL_DECLSPEC SDL_JoystickConnectionState SDLCALL SDL_GetGamepadConnectionState(SDL_Gamepad *gamepad);
  867. /**
  868. * Get the battery state of a gamepad.
  869. *
  870. * You should never take a battery status as absolute truth. Batteries
  871. * (especially failing batteries) are delicate hardware, and the values
  872. * reported here are best estimates based on what that hardware reports. It's
  873. * not uncommon for older batteries to lose stored power much faster than it
  874. * reports, or completely drain when reporting it has 20 percent left, etc.
  875. *
  876. * \param gamepad the gamepad object to query.
  877. * \param percent a pointer filled in with the percentage of battery life
  878. * left, between 0 and 100, or NULL to ignore. This will be
  879. * filled in with -1 we can't determine a value or there is no
  880. * battery.
  881. * \returns the current battery state.
  882. *
  883. * \since This function is available since SDL 3.0.0.
  884. */
  885. extern SDL_DECLSPEC SDL_PowerState SDLCALL SDL_GetGamepadPowerInfo(SDL_Gamepad *gamepad, int *percent);
  886. /**
  887. * Check if a gamepad has been opened and is currently connected.
  888. *
  889. * \param gamepad a gamepad identifier previously returned by
  890. * SDL_OpenGamepad().
  891. * \returns SDL_TRUE if the gamepad has been opened and is currently
  892. * connected, or SDL_FALSE if not.
  893. *
  894. * \since This function is available since SDL 3.0.0.
  895. */
  896. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadConnected(SDL_Gamepad *gamepad);
  897. /**
  898. * Get the underlying joystick from a gamepad.
  899. *
  900. * This function will give you a SDL_Joystick object, which allows you to use
  901. * the SDL_Joystick functions with a SDL_Gamepad object. This would be useful
  902. * for getting a joystick's position at any given time, even if it hasn't
  903. * moved (moving it would produce an event, which would have the axis' value).
  904. *
  905. * The pointer returned is owned by the SDL_Gamepad. You should not call
  906. * SDL_CloseJoystick() on it, for example, since doing so will likely cause
  907. * SDL to crash.
  908. *
  909. * \param gamepad the gamepad object that you want to get a joystick from.
  910. * \returns an SDL_Joystick object; call SDL_GetError() for more information.
  911. *
  912. * \since This function is available since SDL 3.0.0.
  913. */
  914. extern SDL_DECLSPEC SDL_Joystick *SDLCALL SDL_GetGamepadJoystick(SDL_Gamepad *gamepad);
  915. /**
  916. * Set the state of gamepad event processing.
  917. *
  918. * If gamepad events are disabled, you must call SDL_UpdateGamepads() yourself
  919. * and check the state of the gamepad when you want gamepad information.
  920. *
  921. * \param enabled whether to process gamepad events or not.
  922. *
  923. * \since This function is available since SDL 3.0.0.
  924. *
  925. * \sa SDL_GamepadEventsEnabled
  926. * \sa SDL_UpdateGamepads
  927. */
  928. extern SDL_DECLSPEC void SDLCALL SDL_SetGamepadEventsEnabled(SDL_bool enabled);
  929. /**
  930. * Query the state of gamepad event processing.
  931. *
  932. * If gamepad events are disabled, you must call SDL_UpdateGamepads() yourself
  933. * and check the state of the gamepad when you want gamepad information.
  934. *
  935. * \returns SDL_TRUE if gamepad events are being processed, SDL_FALSE
  936. * otherwise.
  937. *
  938. * \since This function is available since SDL 3.0.0.
  939. *
  940. * \sa SDL_SetGamepadEventsEnabled
  941. */
  942. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadEventsEnabled(void);
  943. /**
  944. * Get the SDL joystick layer bindings for a gamepad.
  945. *
  946. * \param gamepad a gamepad.
  947. * \param count a pointer filled in with the number of bindings returned.
  948. * \returns a NULL terminated array of pointers to bindings which should be
  949. * freed with SDL_free(), or NULL on error; call SDL_GetError() for
  950. * more details.
  951. *
  952. * \since This function is available since SDL 3.0.0.
  953. */
  954. extern SDL_DECLSPEC SDL_GamepadBinding **SDLCALL SDL_GetGamepadBindings(SDL_Gamepad *gamepad, int *count);
  955. /**
  956. * Manually pump gamepad updates if not using the loop.
  957. *
  958. * This function is called automatically by the event loop if events are
  959. * enabled. Under such circumstances, it will not be necessary to call this
  960. * function.
  961. *
  962. * \since This function is available since SDL 3.0.0.
  963. */
  964. extern SDL_DECLSPEC void SDLCALL SDL_UpdateGamepads(void);
  965. /**
  966. * Convert a string into SDL_GamepadType enum.
  967. *
  968. * This function is called internally to translate SDL_Gamepad mapping strings
  969. * for the underlying joystick device into the consistent SDL_Gamepad mapping.
  970. * You do not normally need to call this function unless you are parsing
  971. * SDL_Gamepad mappings in your own code.
  972. *
  973. * \param str string representing a SDL_GamepadType type.
  974. * \returns the SDL_GamepadType enum corresponding to the input string, or
  975. * `SDL_GAMEPAD_TYPE_UNKNOWN` if no match was found.
  976. *
  977. * \since This function is available since SDL 3.0.0.
  978. *
  979. * \sa SDL_GetGamepadStringForType
  980. */
  981. extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetGamepadTypeFromString(const char *str);
  982. /**
  983. * Convert from an SDL_GamepadType enum to a string.
  984. *
  985. * The returned string follows the SDL_GetStringRule.
  986. *
  987. * \param type an enum value for a given SDL_GamepadType.
  988. * \returns a string for the given type, or NULL if an invalid type is
  989. * specified. The string returned is of the format used by
  990. * SDL_Gamepad mapping strings.
  991. *
  992. * \since This function is available since SDL 3.0.0.
  993. *
  994. * \sa SDL_GetGamepadTypeFromString
  995. */
  996. extern SDL_DECLSPEC const char *SDLCALL SDL_GetGamepadStringForType(SDL_GamepadType type);
  997. /**
  998. * Convert a string into SDL_GamepadAxis enum.
  999. *
  1000. * This function is called internally to translate SDL_Gamepad mapping strings
  1001. * for the underlying joystick device into the consistent SDL_Gamepad mapping.
  1002. * You do not normally need to call this function unless you are parsing
  1003. * SDL_Gamepad mappings in your own code.
  1004. *
  1005. * Note specially that "righttrigger" and "lefttrigger" map to
  1006. * `SDL_GAMEPAD_AXIS_RIGHT_TRIGGER` and `SDL_GAMEPAD_AXIS_LEFT_TRIGGER`,
  1007. * respectively.
  1008. *
  1009. * \param str string representing a SDL_Gamepad axis.
  1010. * \returns the SDL_GamepadAxis enum corresponding to the input string, or
  1011. * `SDL_GAMEPAD_AXIS_INVALID` if no match was found.
  1012. *
  1013. * \since This function is available since SDL 3.0.0.
  1014. *
  1015. * \sa SDL_GetGamepadStringForAxis
  1016. */
  1017. extern SDL_DECLSPEC SDL_GamepadAxis SDLCALL SDL_GetGamepadAxisFromString(const char *str);
  1018. /**
  1019. * Convert from an SDL_GamepadAxis enum to a string.
  1020. *
  1021. * The returned string follows the SDL_GetStringRule.
  1022. *
  1023. * \param axis an enum value for a given SDL_GamepadAxis.
  1024. * \returns a string for the given axis, or NULL if an invalid axis is
  1025. * specified. The string returned is of the format used by
  1026. * SDL_Gamepad mapping strings.
  1027. *
  1028. * \since This function is available since SDL 3.0.0.
  1029. *
  1030. * \sa SDL_GetGamepadAxisFromString
  1031. */
  1032. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadStringForAxis(SDL_GamepadAxis axis);
  1033. /**
  1034. * Query whether a gamepad has a given axis.
  1035. *
  1036. * This merely reports whether the gamepad's mapping defined this axis, as
  1037. * that is all the information SDL has about the physical device.
  1038. *
  1039. * \param gamepad a gamepad.
  1040. * \param axis an axis enum value (an SDL_GamepadAxis value).
  1041. * \returns SDL_TRUE if the gamepad has this axis, SDL_FALSE otherwise.
  1042. *
  1043. * \since This function is available since SDL 3.0.0.
  1044. *
  1045. * \sa SDL_GamepadHasButton
  1046. * \sa SDL_GetGamepadAxis
  1047. */
  1048. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadHasAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis);
  1049. /**
  1050. * Get the current state of an axis control on a gamepad.
  1051. *
  1052. * The axis indices start at index 0.
  1053. *
  1054. * For thumbsticks, the state is a value ranging from -32768 (up/left) to
  1055. * 32767 (down/right).
  1056. *
  1057. * Triggers range from 0 when released to 32767 when fully pressed, and never
  1058. * return a negative value. Note that this differs from the value reported by
  1059. * the lower-level SDL_GetJoystickAxis(), which normally uses the full range.
  1060. *
  1061. * \param gamepad a gamepad.
  1062. * \param axis an axis index (one of the SDL_GamepadAxis values).
  1063. * \returns axis state (including 0) on success or 0 (also) on failure; call
  1064. * SDL_GetError() for more information.
  1065. *
  1066. * \since This function is available since SDL 3.0.0.
  1067. *
  1068. * \sa SDL_GamepadHasAxis
  1069. * \sa SDL_GetGamepadButton
  1070. */
  1071. extern SDL_DECLSPEC Sint16 SDLCALL SDL_GetGamepadAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis);
  1072. /**
  1073. * Convert a string into an SDL_GamepadButton enum.
  1074. *
  1075. * This function is called internally to translate SDL_Gamepad mapping strings
  1076. * for the underlying joystick device into the consistent SDL_Gamepad mapping.
  1077. * You do not normally need to call this function unless you are parsing
  1078. * SDL_Gamepad mappings in your own code.
  1079. *
  1080. * \param str string representing a SDL_Gamepad axis.
  1081. * \returns the SDL_GamepadButton enum corresponding to the input string, or
  1082. * `SDL_GAMEPAD_BUTTON_INVALID` if no match was found.
  1083. *
  1084. * \since This function is available since SDL 3.0.0.
  1085. *
  1086. * \sa SDL_GetGamepadStringForButton
  1087. */
  1088. extern SDL_DECLSPEC SDL_GamepadButton SDLCALL SDL_GetGamepadButtonFromString(const char *str);
  1089. /**
  1090. * Convert from an SDL_GamepadButton enum to a string.
  1091. *
  1092. * The returned string follows the SDL_GetStringRule.
  1093. *
  1094. * \param button an enum value for a given SDL_GamepadButton.
  1095. * \returns a string for the given button, or NULL if an invalid button is
  1096. * specified. The string returned is of the format used by
  1097. * SDL_Gamepad mapping strings.
  1098. *
  1099. * \since This function is available since SDL 3.0.0.
  1100. *
  1101. * \sa SDL_GetGamepadButtonFromString
  1102. */
  1103. extern SDL_DECLSPEC const char* SDLCALL SDL_GetGamepadStringForButton(SDL_GamepadButton button);
  1104. /**
  1105. * Query whether a gamepad has a given button.
  1106. *
  1107. * This merely reports whether the gamepad's mapping defined this button, as
  1108. * that is all the information SDL has about the physical device.
  1109. *
  1110. * \param gamepad a gamepad.
  1111. * \param button a button enum value (an SDL_GamepadButton value).
  1112. * \returns SDL_TRUE if the gamepad has this button, SDL_FALSE otherwise.
  1113. *
  1114. * \since This function is available since SDL 3.0.0.
  1115. *
  1116. * \sa SDL_GamepadHasAxis
  1117. */
  1118. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadHasButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
  1119. /**
  1120. * Get the current state of a button on a gamepad.
  1121. *
  1122. * \param gamepad a gamepad.
  1123. * \param button a button index (one of the SDL_GamepadButton values).
  1124. * \returns 1 for pressed state or 0 for not pressed state or error; call
  1125. * SDL_GetError() for more information.
  1126. *
  1127. * \since This function is available since SDL 3.0.0.
  1128. *
  1129. * \sa SDL_GamepadHasButton
  1130. * \sa SDL_GetGamepadAxis
  1131. */
  1132. extern SDL_DECLSPEC Uint8 SDLCALL SDL_GetGamepadButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
  1133. /**
  1134. * Get the label of a button on a gamepad.
  1135. *
  1136. * \param type the type of gamepad to check.
  1137. * \param button a button index (one of the SDL_GamepadButton values).
  1138. * \returns the SDL_GamepadButtonLabel enum corresponding to the button label.
  1139. *
  1140. * \since This function is available since SDL 3.0.0.
  1141. *
  1142. * \sa SDL_GetGamepadButtonLabel
  1143. */
  1144. extern SDL_DECLSPEC SDL_GamepadButtonLabel SDLCALL SDL_GetGamepadButtonLabelForType(SDL_GamepadType type, SDL_GamepadButton button);
  1145. /**
  1146. * Get the label of a button on a gamepad.
  1147. *
  1148. * \param gamepad a gamepad.
  1149. * \param button a button index (one of the SDL_GamepadButton values).
  1150. * \returns the SDL_GamepadButtonLabel enum corresponding to the button label.
  1151. *
  1152. * \since This function is available since SDL 3.0.0.
  1153. *
  1154. * \sa SDL_GetGamepadButtonLabelForType
  1155. */
  1156. extern SDL_DECLSPEC SDL_GamepadButtonLabel SDLCALL SDL_GetGamepadButtonLabel(SDL_Gamepad *gamepad, SDL_GamepadButton button);
  1157. /**
  1158. * Get the number of touchpads on a gamepad.
  1159. *
  1160. * \param gamepad a gamepad.
  1161. * \returns number of touchpads.
  1162. *
  1163. * \since This function is available since SDL 3.0.0.
  1164. *
  1165. * \sa SDL_GetNumGamepadTouchpadFingers
  1166. */
  1167. extern SDL_DECLSPEC int SDLCALL SDL_GetNumGamepadTouchpads(SDL_Gamepad *gamepad);
  1168. /**
  1169. * Get the number of supported simultaneous fingers on a touchpad on a game
  1170. * gamepad.
  1171. *
  1172. * \param gamepad a gamepad.
  1173. * \param touchpad a touchpad.
  1174. * \returns number of supported simultaneous fingers.
  1175. *
  1176. * \since This function is available since SDL 3.0.0.
  1177. *
  1178. * \sa SDL_GetGamepadTouchpadFinger
  1179. * \sa SDL_GetNumGamepadTouchpads
  1180. */
  1181. extern SDL_DECLSPEC int SDLCALL SDL_GetNumGamepadTouchpadFingers(SDL_Gamepad *gamepad, int touchpad);
  1182. /**
  1183. * Get the current state of a finger on a touchpad on a gamepad.
  1184. *
  1185. * \param gamepad a gamepad.
  1186. * \param touchpad a touchpad.
  1187. * \param finger a finger.
  1188. * \param state filled with state.
  1189. * \param x filled with x position, normalized 0 to 1, with the origin in the
  1190. * upper left.
  1191. * \param y filled with y position, normalized 0 to 1, with the origin in the
  1192. * upper left.
  1193. * \param pressure filled with pressure value.
  1194. * \returns 0 on success or a negative error code on failure; call
  1195. * SDL_GetError() for more information.
  1196. *
  1197. * \since This function is available since SDL 3.0.0.
  1198. *
  1199. * \sa SDL_GetNumGamepadTouchpadFingers
  1200. */
  1201. extern SDL_DECLSPEC int SDLCALL SDL_GetGamepadTouchpadFinger(SDL_Gamepad *gamepad, int touchpad, int finger, Uint8 *state, float *x, float *y, float *pressure);
  1202. /**
  1203. * Return whether a gamepad has a particular sensor.
  1204. *
  1205. * \param gamepad the gamepad to query.
  1206. * \param type the type of sensor to query.
  1207. * \returns SDL_TRUE if the sensor exists, SDL_FALSE otherwise.
  1208. *
  1209. * \since This function is available since SDL 3.0.0.
  1210. *
  1211. * \sa SDL_GetGamepadSensorData
  1212. * \sa SDL_GetGamepadSensorDataRate
  1213. * \sa SDL_SetGamepadSensorEnabled
  1214. */
  1215. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadHasSensor(SDL_Gamepad *gamepad, SDL_SensorType type);
  1216. /**
  1217. * Set whether data reporting for a gamepad sensor is enabled.
  1218. *
  1219. * \param gamepad the gamepad to update.
  1220. * \param type the type of sensor to enable/disable.
  1221. * \param enabled whether data reporting should be enabled.
  1222. * \returns 0 on success or a negative error code on failure; call
  1223. * SDL_GetError() for more information.
  1224. *
  1225. * \since This function is available since SDL 3.0.0.
  1226. *
  1227. * \sa SDL_GamepadHasSensor
  1228. * \sa SDL_GamepadSensorEnabled
  1229. */
  1230. extern SDL_DECLSPEC int SDLCALL SDL_SetGamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type, SDL_bool enabled);
  1231. /**
  1232. * Query whether sensor data reporting is enabled for a gamepad.
  1233. *
  1234. * \param gamepad the gamepad to query.
  1235. * \param type the type of sensor to query.
  1236. * \returns SDL_TRUE if the sensor is enabled, SDL_FALSE otherwise.
  1237. *
  1238. * \since This function is available since SDL 3.0.0.
  1239. *
  1240. * \sa SDL_SetGamepadSensorEnabled
  1241. */
  1242. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type);
  1243. /**
  1244. * Get the data rate (number of events per second) of a gamepad sensor.
  1245. *
  1246. * \param gamepad the gamepad to query.
  1247. * \param type the type of sensor to query.
  1248. * \returns the data rate, or 0.0f if the data rate is not available.
  1249. *
  1250. * \since This function is available since SDL 3.0.0.
  1251. */
  1252. extern SDL_DECLSPEC float SDLCALL SDL_GetGamepadSensorDataRate(SDL_Gamepad *gamepad, SDL_SensorType type);
  1253. /**
  1254. * Get the current state of a gamepad sensor.
  1255. *
  1256. * The number of values and interpretation of the data is sensor dependent.
  1257. * See SDL_sensor.h for the details for each type of sensor.
  1258. *
  1259. * \param gamepad the gamepad to query.
  1260. * \param type the type of sensor to query.
  1261. * \param data a pointer filled with the current sensor state.
  1262. * \param num_values the number of values to write to data.
  1263. * \returns 0 on success or a negative error code on failure; call
  1264. * SDL_GetError() for more information.
  1265. *
  1266. * \since This function is available since SDL 3.0.0.
  1267. */
  1268. extern SDL_DECLSPEC int SDLCALL SDL_GetGamepadSensorData(SDL_Gamepad *gamepad, SDL_SensorType type, float *data, int num_values);
  1269. /**
  1270. * Start a rumble effect on a gamepad.
  1271. *
  1272. * Each call to this function cancels any previous rumble effect, and calling
  1273. * it with 0 intensity stops any rumbling.
  1274. *
  1275. * This function requires you to process SDL events or call
  1276. * SDL_UpdateJoysticks() to update rumble state.
  1277. *
  1278. * \param gamepad the gamepad to vibrate.
  1279. * \param low_frequency_rumble the intensity of the low frequency (left)
  1280. * rumble motor, from 0 to 0xFFFF.
  1281. * \param high_frequency_rumble the intensity of the high frequency (right)
  1282. * rumble motor, from 0 to 0xFFFF.
  1283. * \param duration_ms the duration of the rumble effect, in milliseconds.
  1284. * \returns 0, or -1 if rumble isn't supported on this gamepad.
  1285. *
  1286. * \since This function is available since SDL 3.0.0.
  1287. */
  1288. extern SDL_DECLSPEC int SDLCALL SDL_RumbleGamepad(SDL_Gamepad *gamepad, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
  1289. /**
  1290. * Start a rumble effect in the gamepad's triggers.
  1291. *
  1292. * Each call to this function cancels any previous trigger rumble effect, and
  1293. * calling it with 0 intensity stops any rumbling.
  1294. *
  1295. * Note that this is rumbling of the _triggers_ and not the gamepad as a
  1296. * whole. This is currently only supported on Xbox One gamepads. If you want
  1297. * the (more common) whole-gamepad rumble, use SDL_RumbleGamepad() instead.
  1298. *
  1299. * This function requires you to process SDL events or call
  1300. * SDL_UpdateJoysticks() to update rumble state.
  1301. *
  1302. * \param gamepad the gamepad to vibrate.
  1303. * \param left_rumble the intensity of the left trigger rumble motor, from 0
  1304. * to 0xFFFF.
  1305. * \param right_rumble the intensity of the right trigger rumble motor, from 0
  1306. * to 0xFFFF.
  1307. * \param duration_ms the duration of the rumble effect, in milliseconds.
  1308. * \returns 0 on success or a negative error code on failure; call
  1309. * SDL_GetError() for more information.
  1310. *
  1311. * \since This function is available since SDL 3.0.0.
  1312. *
  1313. * \sa SDL_RumbleGamepad
  1314. */
  1315. extern SDL_DECLSPEC int SDLCALL SDL_RumbleGamepadTriggers(SDL_Gamepad *gamepad, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms);
  1316. /**
  1317. * Update a gamepad's LED color.
  1318. *
  1319. * An example of a joystick LED is the light on the back of a PlayStation 4's
  1320. * DualShock 4 controller.
  1321. *
  1322. * For gamepads with a single color LED, the maximum of the RGB values will be
  1323. * used as the LED brightness.
  1324. *
  1325. * \param gamepad the gamepad to update.
  1326. * \param red the intensity of the red LED.
  1327. * \param green the intensity of the green LED.
  1328. * \param blue the intensity of the blue LED.
  1329. * \returns 0 on success or a negative error code on failure; call
  1330. * SDL_GetError() for more information.
  1331. *
  1332. * \since This function is available since SDL 3.0.0.
  1333. */
  1334. extern SDL_DECLSPEC int SDLCALL SDL_SetGamepadLED(SDL_Gamepad *gamepad, Uint8 red, Uint8 green, Uint8 blue);
  1335. /**
  1336. * Send a gamepad specific effect packet.
  1337. *
  1338. * \param gamepad the gamepad to affect.
  1339. * \param data the data to send to the gamepad.
  1340. * \param size the size of the data to send to the gamepad.
  1341. * \returns 0 on success or a negative error code on failure; call
  1342. * SDL_GetError() for more information.
  1343. *
  1344. * \since This function is available since SDL 3.0.0.
  1345. */
  1346. extern SDL_DECLSPEC int SDLCALL SDL_SendGamepadEffect(SDL_Gamepad *gamepad, const void *data, int size);
  1347. /**
  1348. * Close a gamepad previously opened with SDL_OpenGamepad().
  1349. *
  1350. * \param gamepad a gamepad identifier previously returned by
  1351. * SDL_OpenGamepad().
  1352. *
  1353. * \since This function is available since SDL 3.0.0.
  1354. *
  1355. * \sa SDL_OpenGamepad
  1356. */
  1357. extern SDL_DECLSPEC void SDLCALL SDL_CloseGamepad(SDL_Gamepad *gamepad);
  1358. /**
  1359. * Return the sfSymbolsName for a given button on a gamepad on Apple
  1360. * platforms.
  1361. *
  1362. * The returned string follows the SDL_GetStringRule.
  1363. *
  1364. * \param gamepad the gamepad to query.
  1365. * \param button a button on the gamepad.
  1366. * \returns the sfSymbolsName or NULL if the name can't be found.
  1367. *
  1368. * \since This function is available since SDL 3.0.0.
  1369. *
  1370. * \sa SDL_GetGamepadAppleSFSymbolsNameForAxis
  1371. */
  1372. extern SDL_DECLSPEC const char* SDLCALL SDL_GetGamepadAppleSFSymbolsNameForButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
  1373. /**
  1374. * Return the sfSymbolsName for a given axis on a gamepad on Apple platforms.
  1375. *
  1376. * The returned string follows the SDL_GetStringRule.
  1377. *
  1378. * \param gamepad the gamepad to query.
  1379. * \param axis an axis on the gamepad.
  1380. * \returns the sfSymbolsName or NULL if the name can't be found.
  1381. *
  1382. * \since This function is available since SDL 3.0.0.
  1383. *
  1384. * \sa SDL_GetGamepadAppleSFSymbolsNameForButton
  1385. */
  1386. extern SDL_DECLSPEC const char* SDLCALL SDL_GetGamepadAppleSFSymbolsNameForAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis);
  1387. /* Ends C function definitions when using C++ */
  1388. #ifdef __cplusplus
  1389. }
  1390. #endif
  1391. #include <SDL3/SDL_close_code.h>
  1392. #endif /* SDL_gamepad_h_ */