SDL_gamepad.h 48 KB

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