SDL_gamepad.h 47 KB

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