1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
22/**
23 * \file SDL_gamecontroller.h
24 *
25 * Include file for SDL game controller event handling
26 */
27
28#ifndef SDL_gamecontroller_h_
29#define SDL_gamecontroller_h_
30
31#include "SDL_stdinc.h"
32#include "SDL_error.h"
33#include "SDL_rwops.h"
34#include "SDL_sensor.h"
35#include "SDL_joystick.h"
36
37#include "begin_code.h"
38/* Set up for C function definitions, even when using C++ */
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43/**
44 * \file SDL_gamecontroller.h
45 *
46 * In order to use these functions, SDL_Init() must have been called
47 * with the ::SDL_INIT_GAMECONTROLLER flag. This causes SDL to scan the system
48 * for game controllers, and load appropriate drivers.
49 *
50 * If you would like to receive controller updates while the application
51 * is in the background, you should set the following hint before calling
52 * SDL_Init(): SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS
53 */
54
55/**
56 * The gamecontroller structure used to identify an SDL game controller
57 */
58struct _SDL_GameController;
59typedef struct _SDL_GameController SDL_GameController;
60
61typedef enum
62{
63 SDL_CONTROLLER_TYPE_UNKNOWN = 0,
64 SDL_CONTROLLER_TYPE_XBOX360,
65 SDL_CONTROLLER_TYPE_XBOXONE,
66 SDL_CONTROLLER_TYPE_PS3,
67 SDL_CONTROLLER_TYPE_PS4,
68 SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO,
69 SDL_CONTROLLER_TYPE_VIRTUAL,
70 SDL_CONTROLLER_TYPE_PS5
71} SDL_GameControllerType;
72
73typedef enum
74{
75 SDL_CONTROLLER_BINDTYPE_NONE = 0,
76 SDL_CONTROLLER_BINDTYPE_BUTTON,
77 SDL_CONTROLLER_BINDTYPE_AXIS,
78 SDL_CONTROLLER_BINDTYPE_HAT
79} SDL_GameControllerBindType;
80
81/**
82 * Get the SDL joystick layer binding for this controller button/axis mapping
83 */
84typedef struct SDL_GameControllerButtonBind
85{
86 SDL_GameControllerBindType bindType;
87 union
88 {
89 int button;
90 int axis;
91 struct {
92 int hat;
93 int hat_mask;
94 } hat;
95 } value;
96
97} SDL_GameControllerButtonBind;
98
99
100/**
101 * To count the number of game controllers in the system for the following:
102 * int nJoysticks = SDL_NumJoysticks();
103 * int nGameControllers = 0;
104 * for (int i = 0; i < nJoysticks; i++) {
105 * if (SDL_IsGameController(i)) {
106 * nGameControllers++;
107 * }
108 * }
109 *
110 * Using the SDL_HINT_GAMECONTROLLERCONFIG hint or the SDL_GameControllerAddMapping() you can add support for controllers SDL is unaware of or cause an existing controller to have a different binding. The format is:
111 * guid,name,mappings
112 *
113 * Where GUID is the string value from SDL_JoystickGetGUIDString(), name is the human readable string for the device and mappings are controller mappings to joystick ones.
114 * Under Windows there is a reserved GUID of "xinput" that covers any XInput devices.
115 * The mapping format for joystick is:
116 * bX - a joystick button, index X
117 * hX.Y - hat X with value Y
118 * aX - axis X of the joystick
119 * Buttons can be used as a controller axis and vice versa.
120 *
121 * This string shows an example of a valid mapping for a controller
122 * "03000000341a00003608000000000000,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",
123 *
124 */
125
126/**
127 * Load a set of Game Controller mappings from a seekable SDL data stream.
128 *
129 * You can call this function several times, if needed, to load different
130 * database files.
131 *
132 * If a new mapping is loaded for an already known controller GUID, the later
133 * version will overwrite the one currently loaded.
134 *
135 * Mappings not belonging to the current platform or with no platform field
136 * specified will be ignored (i.e. mappings for Linux will be ignored in
137 * Windows, etc).
138 *
139 * This function will load the text database entirely in memory before
140 * processing it, so take this into consideration if you are in a memory
141 * constrained environment.
142 *
143 * \param rw the data stream for the mappings to be added
144 * \param freerw non-zero to close the stream after being read
145 * \returns the number of mappings added or -1 on error; call SDL_GetError()
146 * for more information.
147 *
148 * \since This function is available since SDL 2.0.2.
149 *
150 * \sa SDL_GameControllerAddMapping
151 * \sa SDL_GameControllerAddMappingsFromFile
152 * \sa SDL_GameControllerMappingForGUID
153 */
154extern DECLSPEC int SDLCALL SDL_GameControllerAddMappingsFromRW(SDL_RWops * rw, int freerw);
155
156/**
157 * Load a set of mappings from a file, filtered by the current SDL_GetPlatform()
158 *
159 * Convenience macro.
160 */
161#define SDL_GameControllerAddMappingsFromFile(file) SDL_GameControllerAddMappingsFromRW(SDL_RWFromFile(file, "rb"), 1)
162
163/**
164 * Add support for controllers that SDL is unaware of or
165 * to cause an existing controller to have a different binding.
166 *
167 * The mapping string has the format "GUID,name,mapping", where GUID is the
168 * string value from SDL_JoystickGetGUIDString(), name is the human readable
169 * string for the device and mappings are controller mappings to joystick
170 * ones. Under Windows there is a reserved GUID of "xinput" that covers all
171 * XInput devices. The mapping format for joystick is: {| |bX |a joystick
172 * button, index X |- |hX.Y |hat X with value Y |- |aX |axis X of the joystick
173 * |} Buttons can be used as a controller axes and vice versa.
174 *
175 * This string shows an example of a valid mapping for a controller:
176 *
177 * ```
178 * "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"
179 * ```
180 *
181 * \param mappingString the mapping string
182 * \returns 1 if a new mapping is added, 0 if an existing mapping is updated,
183 * -1 on error; call SDL_GetError() for more information.
184 *
185 * \sa SDL_GameControllerMapping
186 * \sa SDL_GameControllerMappingForGUID
187 */
188extern DECLSPEC int SDLCALL SDL_GameControllerAddMapping(const char* mappingString);
189
190/**
191 * Get the number of mappings installed.
192 *
193 * \returns the number of mappings.
194 */
195extern DECLSPEC int SDLCALL SDL_GameControllerNumMappings(void);
196
197/**
198 * Get the mapping at a particular index.
199 *
200 * \returns the mapping string. Must be freed with SDL_free().
201 * Returns NULL if the index is out of range.
202 */
203extern DECLSPEC char * SDLCALL SDL_GameControllerMappingForIndex(int mapping_index);
204
205/**
206 * Get the game controller mapping string for a given GUID.
207 *
208 * The returned string must be freed with SDL_free().
209 *
210 * \param guid a structure containing the GUID for which a mapping is desired
211 * \returns a mapping string or NULL on error; call SDL_GetError() for more
212 * information.
213 *
214 * \sa SDL_JoystickGetDeviceGUID
215 * \sa SDL_JoystickGetGUID
216 */
217extern DECLSPEC char * SDLCALL SDL_GameControllerMappingForGUID(SDL_JoystickGUID guid);
218
219/**
220 * Get the current mapping of a Game Controller.
221 *
222 * The returned string must be freed with SDL_free().
223 *
224 * Details about mappings are discussed with SDL_GameControllerAddMapping().
225 *
226 * \param gamecontroller the game controller you want to get the current
227 * mapping for
228 * \returns a string that has the controller's mapping or NULL if no mapping
229 * is available; call SDL_GetError() for more information.
230 *
231 * \since This function is available since SDL 2.0.0.
232 *
233 * \sa SDL_GameControllerAddMapping
234 * \sa SDL_GameControllerMappingForGUID
235 */
236extern DECLSPEC char * SDLCALL SDL_GameControllerMapping(SDL_GameController *gamecontroller);
237
238/**
239 * Check if the given joystick is supported by the game controller interface.
240 *
241 * `joystick_index` is the same as the `device_index` passed to
242 * SDL_JoystickOpen().
243 *
244 * \param joystick_index the device_index of a device, up to
245 * SDL_NumJoysticks()
246 * \returns SDL_TRUE if the given joystick is supported by the game controller
247 * interface, SDL_FALSE if it isn't or it's an invalid index.
248 *
249 * \since This function is available since SDL 2.0.0.
250 *
251 * \sa SDL_GameControllerNameForIndex
252 * \sa SDL_GameControllerOpen
253 */
254extern DECLSPEC SDL_bool SDLCALL SDL_IsGameController(int joystick_index);
255
256/**
257 * Get the implementation dependent name for the game
258 * controller.
259 *
260 * This function can be called before any controllers are opened.
261 *
262 * `joystick_index` is the same as the `device_index` passed to
263 * SDL_JoystickOpen().
264 *
265 * \param joystick_index the device_index of a device, from zero to
266 * SDL_NumJoysticks()-1
267 * \returns the implementation-dependent name for the game controller, or NULL
268 * if there is no name or the index is invalid.
269 *
270 * \since This function is available since SDL 2.0.0.
271 *
272 * \sa SDL_GameControllerName
273 * \sa SDL_GameControllerOpen
274 * \sa SDL_IsGameController
275 */
276extern DECLSPEC const char *SDLCALL SDL_GameControllerNameForIndex(int joystick_index);
277
278/**
279 * Get the type of a game controller.
280 *
281 * This can be called before any controllers are opened.
282 *
283 * \param joystick_index the device_index of a device, from zero to
284 * SDL_NumJoysticks()-1
285 * \returns the controller type.
286 */
287extern DECLSPEC SDL_GameControllerType SDLCALL SDL_GameControllerTypeForIndex(int joystick_index);
288
289/**
290 * Get the mapping of a game controller.
291 *
292 * This can be called before any controllers are opened.
293 *
294 * \param joystick_index the device_index of a device, from zero to
295 * SDL_NumJoysticks()-1
296 * \returns the mapping string. Must be freed with SDL_free(). Returns NULL
297 * if no mapping is available.
298 */
299extern DECLSPEC char *SDLCALL SDL_GameControllerMappingForDeviceIndex(int joystick_index);
300
301/**
302 * Open a game controller for use.
303 *
304 * `joystick_index` is the same as the `device_index` passed to
305 * SDL_JoystickOpen().
306 *
307 * The index passed as an argument refers to the N'th game controller on the
308 * system. This index is not the value which will identify this controller in
309 * future controller events. The joystick's instance id (SDL_JoystickID) will
310 * be used there instead.
311 *
312 * \param joystick_index the device_index of a device, up to
313 * SDL_NumJoysticks()
314 * \returns a gamecontroller identifier or NULL if an error occurred; call
315 * SDL_GetError() for more information.
316 *
317 * \since This function is available since SDL 2.0.0.
318 *
319 * \sa SDL_GameControllerClose
320 * \sa SDL_GameControllerNameForIndex
321 * \sa SDL_IsGameController
322 */
323extern DECLSPEC SDL_GameController *SDLCALL SDL_GameControllerOpen(int joystick_index);
324
325/**
326 * Get the SDL_GameController associated with an instance id.
327 *
328 * \param joyid the instance id to get the SDL_GameController for
329 * \returns an SDL_GameController on success or NULL on failure; call
330 * SDL_GetError() for more information.
331 *
332 * \since This function is available since SDL 2.0.4.
333 */
334extern DECLSPEC SDL_GameController *SDLCALL SDL_GameControllerFromInstanceID(SDL_JoystickID joyid);
335
336/**
337 * Get the SDL_GameController associated with a player index.
338 *
339 * Please note that the player index is _not_ the device index, nor is it
340 * the instance id!
341 *
342 * \param player_index the player index, which is not the device index or
343 * the instance id!
344 * \returns the SDL_GameController associated with a player index.
345 *
346 * \sa SDL_GameControllerGetPlayerIndex
347 * \sa SDL_GameControllerSetPlayerIndex
348 */
349extern DECLSPEC SDL_GameController *SDLCALL SDL_GameControllerFromPlayerIndex(int player_index);
350
351/**
352 * Get the implementation-dependent name for an opened game controller.
353 *
354 * This is the same name as returned by SDL_GameControllerNameForIndex(), but
355 * it takes a controller identifier instead of the (unstable) device index.
356 *
357 * \param gamecontroller a game controller identifier previously returned by
358 * SDL_GameControllerOpen()
359 * \returns the implementation dependent name for the game controller, or NULL
360 * if there is no name or the identifier passed is invalid.
361 *
362 * \since This function is available since SDL 2.0.0.
363 *
364 * \sa SDL_GameControllerNameForIndex
365 * \sa SDL_GameControllerOpen
366 */
367extern DECLSPEC const char *SDLCALL SDL_GameControllerName(SDL_GameController *gamecontroller);
368
369/**
370 * Get the type of this currently opened controller
371 *
372 * This is the same name as returned by SDL_GameControllerTypeForIndex(), but
373 * it takes a controller identifier instead of the (unstable) device index.
374 *
375 * \param gamecontroller the game controller object to query.
376 * \returns the controller type.
377 */
378extern DECLSPEC SDL_GameControllerType SDLCALL SDL_GameControllerGetType(SDL_GameController *gamecontroller);
379
380/**
381 * Get the player index of an opened game controller.
382 *
383 * For XInput controllers this returns the XInput user index.
384 *
385 * \param gamecontroller the game controller object to query.
386 * \returns player index for controller, or -1 if it's not available.
387 */
388extern DECLSPEC int SDLCALL SDL_GameControllerGetPlayerIndex(SDL_GameController *gamecontroller);
389
390/**
391 * Set the player index of an opened game controller.
392 *
393 * \param gamecontroller the game controller object to adjust.
394 * \param player_index Player index to assign to this controller.
395 */
396extern DECLSPEC void SDLCALL SDL_GameControllerSetPlayerIndex(SDL_GameController *gamecontroller, int player_index);
397
398/**
399 * Get the USB vendor ID of an opened controller, if available.
400 *
401 * If the vendor ID isn't available this function returns 0.
402 *
403 * \param gamecontroller the game controller object to query.
404 * \return USB vendor ID, or zero if unavailable.
405 */
406extern DECLSPEC Uint16 SDLCALL SDL_GameControllerGetVendor(SDL_GameController *gamecontroller);
407
408/**
409 * Get the USB product ID of an opened controller, if available.
410 *
411 * If the product ID isn't available this function returns 0.
412 *
413 * \param gamecontroller the game controller object to query.
414 * \return USB product ID, or zero if unavailable.
415 */
416extern DECLSPEC Uint16 SDLCALL SDL_GameControllerGetProduct(SDL_GameController *gamecontroller);
417
418/**
419 * Get the product version of an opened controller, if available.
420 *
421 * If the product version isn't available this function returns 0.
422 *
423 * \param gamecontroller the game controller object to query.
424 * \return USB product version, or zero if unavailable.
425 */
426extern DECLSPEC Uint16 SDLCALL SDL_GameControllerGetProductVersion(SDL_GameController *gamecontroller);
427
428/**
429 * Get the serial number of an opened controller, if available.
430 *
431 * Returns the serial number of the controller, or NULL if it is not available.
432 *
433 * \param gamecontroller the game controller object to query.
434 * \return Serial number, or NULL if unavailable.
435 */
436extern DECLSPEC const char * SDLCALL SDL_GameControllerGetSerial(SDL_GameController *gamecontroller);
437
438/**
439 * Check if a controller has been opened and is currently connected.
440 *
441 * \param gamecontroller a game controller identifier previously returned by
442 * SDL_GameControllerOpen()
443 * \returns SDL_TRUE if the controller has been opened and is currently
444 * connected, or SDL_FALSE if not.
445 *
446 * \sa SDL_GameControllerClose
447 * \sa SDL_GameControllerOpen
448 */
449extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerGetAttached(SDL_GameController *gamecontroller);
450
451/**
452 * Get the Joystick ID from a Game Controller.
453 *
454 * This function will give you a SDL_Joystick object, which allows you to use
455 * the SDL_Joystick functions with a SDL_GameController object. This would be
456 * useful for getting a joystick's position at any given time, even if it
457 * hasn't moved (moving it would produce an event, which would have the axis'
458 * value).
459 *
460 * The pointer returned is owned by the SDL_GameController. You should not
461 * call SDL_JoystickClose() on it, for example, since doing so will likely
462 * cause SDL to crash.
463 *
464 * \param gamecontroller the game controller object that you want to get a
465 * joystick from
466 * \returns a SDL_Joystick object; call SDL_GetError() for more information.
467 */
468extern DECLSPEC SDL_Joystick *SDLCALL SDL_GameControllerGetJoystick(SDL_GameController *gamecontroller);
469
470/**
471 * Query or change current state of Game Controller events.
472 *
473 * If controller events are disabled, you must call SDL_GameControllerUpdate()
474 * yourself and check the state of the controller when you want controller
475 * information.
476 *
477 * Any number can be passed to SDL_GameControllerEventState(), but only -1, 0,
478 * and 1 will have any effect. Other numbers will just be returned.
479 *
480 * \param state can be one of `SDL_QUERY`, `SDL_IGNORE`, or `SDL_ENABLE`
481 * \returns the same value passed to the function, with exception to -1
482 * (SDL_QUERY), which will return the current state.
483 *
484 * \since This function is available since SDL 2.0.0.
485 *
486 * \sa SDL_JoystickEventState
487 */
488extern DECLSPEC int SDLCALL SDL_GameControllerEventState(int state);
489
490/**
491 * Manually pump game controller updates if not using the loop.
492 *
493 * This function is called automatically by the event loop if events are
494 * enabled. Under such circumstances, it will not be necessary to call this
495 * function.
496 */
497extern DECLSPEC void SDLCALL SDL_GameControllerUpdate(void);
498
499
500/**
501 * The list of axes available from a controller
502 *
503 * Thumbstick axis values range from SDL_JOYSTICK_AXIS_MIN to SDL_JOYSTICK_AXIS_MAX,
504 * and are centered within ~8000 of zero, though advanced UI will allow users to set
505 * or autodetect the dead zone, which varies between controllers.
506 *
507 * Trigger axis values range from 0 to SDL_JOYSTICK_AXIS_MAX.
508 */
509typedef enum
510{
511 SDL_CONTROLLER_AXIS_INVALID = -1,
512 SDL_CONTROLLER_AXIS_LEFTX,
513 SDL_CONTROLLER_AXIS_LEFTY,
514 SDL_CONTROLLER_AXIS_RIGHTX,
515 SDL_CONTROLLER_AXIS_RIGHTY,
516 SDL_CONTROLLER_AXIS_TRIGGERLEFT,
517 SDL_CONTROLLER_AXIS_TRIGGERRIGHT,
518 SDL_CONTROLLER_AXIS_MAX
519} SDL_GameControllerAxis;
520
521/**
522 * Convert a string into SDL_GameControllerAxis enum.
523 *
524 * This function is called internally to translate SDL_GameController mapping
525 * strings for the underlying joystick device into the consistent
526 * SDL_GameController mapping. You do not normally need to call this function
527 * unless you are parsing SDL_GameController mappings in your own code.
528 *
529 * \param str string representing a SDL_GameController axis
530 * \returns the SDL_GameControllerAxis enum corresponding to the input string,
531 * or `SDL_CONTROLLER_AXIS_INVALID` if no match was found.
532 *
533 * \sa SDL_GameControllerGetStringForAxis
534 */
535extern DECLSPEC SDL_GameControllerAxis SDLCALL SDL_GameControllerGetAxisFromString(const char *str);
536
537/**
538 * Convert from an SDL_GameControllerAxis enum to a string.
539 *
540 * The caller should not SDL_free() the returned string.
541 *
542 * \param axis an enum value for a given SDL_GameControllerAxis
543 * \returns a string for the given axis, or NULL if an invalid axis is
544 * specified. The string returned is of the format used by
545 * SDL_GameController mapping strings.
546 *
547 * \sa SDL_GameControllerGetAxisFromString
548 */
549extern DECLSPEC const char* SDLCALL SDL_GameControllerGetStringForAxis(SDL_GameControllerAxis axis);
550
551/**
552 * Get the SDL joystick layer binding for a controller axis mapping.
553 *
554 * \param gamecontroller a game controller
555 * \param axis an axis enum value (one of the SDL_GameControllerAxis values)
556 * \returns a SDL_GameControllerButtonBind describing the bind. On
557 * failure (like the given Controller axis doesn't exist on the
558 * device), its `.bindType` will be `SDL_CONTROLLER_BINDTYPE_NONE`.
559 *
560 * \since This function is available since SDL 2.0.0.
561 *
562 * \sa SDL_GameControllerGetBindForButton
563 */
564extern DECLSPEC SDL_GameControllerButtonBind SDLCALL
565SDL_GameControllerGetBindForAxis(SDL_GameController *gamecontroller,
566 SDL_GameControllerAxis axis);
567
568/**
569 * Query whether a game controller has a given axis.
570 *
571 * This merely reports whether the controller's mapping defined this axis, as
572 * that is all the information SDL has about the physical device.
573 *
574 * \param gamecontroller a game controller
575 * \param axis an axis enum value (an SDL_GameControllerAxis value)
576 * \returns SDL_TRUE if the controller has this axis, SDL_FALSE otherwise.
577 */
578extern DECLSPEC SDL_bool SDLCALL
579SDL_GameControllerHasAxis(SDL_GameController *gamecontroller, SDL_GameControllerAxis axis);
580
581/**
582 * Get the current state of an axis control on a game controller.
583 *
584 * The axis indices start at index 0.
585 *
586 * The state is a value ranging from -32768 to 32767. Triggers, however, range
587 * from 0 to 32767 (they never return a negative value).
588 *
589 * \param gamecontroller a game controller
590 * \param axis an axis index (one of the SDL_GameControllerAxis values)
591 * \returns axis state (including 0) on success or 0 (also) on failure; call
592 * SDL_GetError() for more information.
593 *
594 * \since This function is available since SDL 2.0.0.
595 *
596 * \sa SDL_GameControllerGetButton
597 */
598extern DECLSPEC Sint16 SDLCALL
599SDL_GameControllerGetAxis(SDL_GameController *gamecontroller, SDL_GameControllerAxis axis);
600
601/**
602 * The list of buttons available from a controller
603 */
604typedef enum
605{
606 SDL_CONTROLLER_BUTTON_INVALID = -1,
607 SDL_CONTROLLER_BUTTON_A,
608 SDL_CONTROLLER_BUTTON_B,
609 SDL_CONTROLLER_BUTTON_X,
610 SDL_CONTROLLER_BUTTON_Y,
611 SDL_CONTROLLER_BUTTON_BACK,
612 SDL_CONTROLLER_BUTTON_GUIDE,
613 SDL_CONTROLLER_BUTTON_START,
614 SDL_CONTROLLER_BUTTON_LEFTSTICK,
615 SDL_CONTROLLER_BUTTON_RIGHTSTICK,
616 SDL_CONTROLLER_BUTTON_LEFTSHOULDER,
617 SDL_CONTROLLER_BUTTON_RIGHTSHOULDER,
618 SDL_CONTROLLER_BUTTON_DPAD_UP,
619 SDL_CONTROLLER_BUTTON_DPAD_DOWN,
620 SDL_CONTROLLER_BUTTON_DPAD_LEFT,
621 SDL_CONTROLLER_BUTTON_DPAD_RIGHT,
622 SDL_CONTROLLER_BUTTON_MISC1, /* Xbox Series X share button, PS5 microphone button, Nintendo Switch Pro capture button */
623 SDL_CONTROLLER_BUTTON_PADDLE1, /* Xbox Elite paddle P1 */
624 SDL_CONTROLLER_BUTTON_PADDLE2, /* Xbox Elite paddle P3 */
625 SDL_CONTROLLER_BUTTON_PADDLE3, /* Xbox Elite paddle P2 */
626 SDL_CONTROLLER_BUTTON_PADDLE4, /* Xbox Elite paddle P4 */
627 SDL_CONTROLLER_BUTTON_TOUCHPAD, /* PS4/PS5 touchpad button */
628 SDL_CONTROLLER_BUTTON_MAX
629} SDL_GameControllerButton;
630
631/**
632 * Convert a string into an SDL_GameControllerButton enum.
633 *
634 * This function is called internally to translate SDL_GameController mapping
635 * strings for the underlying joystick device into the consistent
636 * SDL_GameController mapping. You do not normally need to call this function
637 * unless you are parsing SDL_GameController mappings in your own code.
638 *
639 * \param str string representing a SDL_GameController axis
640 * \returns the SDL_GameControllerButton enum corresponding to the input
641 * string, or `SDL_CONTROLLER_AXIS_INVALID` if no match was found.
642 *
643 */
644extern DECLSPEC SDL_GameControllerButton SDLCALL SDL_GameControllerGetButtonFromString(const char *str);
645
646/**
647 * Convert from an SDL_GameControllerButton enum to a string.
648 *
649 * The caller should not SDL_free() the returned string.
650 *
651 * \param button an enum value for a given SDL_GameControllerButton
652 * \returns a string for the given button, or NULL if an invalid axis is
653 * specified. The string returned is of the format used by
654 * SDL_GameController mapping strings.
655 *
656 * \since This function is available since SDL 2.0.0.
657 *
658 * \sa SDL_GameControllerGetButtonFromString
659 */
660extern DECLSPEC const char* SDLCALL SDL_GameControllerGetStringForButton(SDL_GameControllerButton button);
661
662/**
663 * Get the SDL joystick layer binding for a controller button mapping.
664 *
665 * \param gamecontroller a game controller
666 * \param button an button enum value (an SDL_GameControllerButton value)
667 * \returns a SDL_GameControllerButtonBind describing the bind. On
668 * failure (like the given Controller button doesn't exist on the
669 * device), its `.bindType` will be `SDL_CONTROLLER_BINDTYPE_NONE`.
670 *
671 * \since This function is available since SDL 2.0.0.
672 *
673 * \sa SDL_GameControllerGetBindForAxis
674 */
675extern DECLSPEC SDL_GameControllerButtonBind SDLCALL
676SDL_GameControllerGetBindForButton(SDL_GameController *gamecontroller,
677 SDL_GameControllerButton button);
678
679/**
680 * Query whether a game controller has a given button.
681 *
682 * This merely reports whether the controller's mapping defined this button,
683 * as that is all the information SDL has about the physical device.
684 *
685 * \param gamecontroller a game controller
686 * \param button a button enum value (an SDL_GameControllerButton value)
687 * \returns SDL_TRUE if the controller has this button, SDL_FALSE otherwise.
688 */
689extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerHasButton(SDL_GameController *gamecontroller,
690 SDL_GameControllerButton button);
691
692/**
693 * Get the current state of a button on a game controller.
694 *
695 * \param gamecontroller a game controller
696 * \param button a button index (one of the SDL_GameControllerButton values)
697 * \returns 1 for pressed state or 0 for not pressed state or error; call
698 * SDL_GetError() for more information.
699 *
700 * \since This function is available since SDL 2.0.0.
701 *
702 * \sa SDL_GameControllerGetAxis
703 */
704extern DECLSPEC Uint8 SDLCALL SDL_GameControllerGetButton(SDL_GameController *gamecontroller,
705 SDL_GameControllerButton button);
706
707/**
708 * Get the number of touchpads on a game controller.
709 */
710extern DECLSPEC int SDLCALL SDL_GameControllerGetNumTouchpads(SDL_GameController *gamecontroller);
711
712/**
713 * Get the number of supported simultaneous fingers on a touchpad on a game controller.
714 */
715extern DECLSPEC int SDLCALL SDL_GameControllerGetNumTouchpadFingers(SDL_GameController *gamecontroller, int touchpad);
716
717/**
718 * Get the current state of a finger on a touchpad on a game controller.
719 */
720extern DECLSPEC int SDLCALL SDL_GameControllerGetTouchpadFinger(SDL_GameController *gamecontroller, int touchpad, int finger, Uint8 *state, float *x, float *y, float *pressure);
721
722/**
723 * Return whether a game controller has a particular sensor.
724 *
725 * \param gamecontroller The controller to query
726 * \param type The type of sensor to query
727 *
728 * \returns SDL_TRUE if the sensor exists, SDL_FALSE otherwise.
729 */
730extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerHasSensor(SDL_GameController *gamecontroller, SDL_SensorType type);
731
732/**
733 * Set whether data reporting for a game controller sensor is enabled.
734 *
735 * \param gamecontroller The controller to update
736 * \param type The type of sensor to enable/disable
737 * \param enabled Whether data reporting should be enabled
738 *
739 * \returns 0 or -1 if an error occurred.
740 */
741extern DECLSPEC int SDLCALL SDL_GameControllerSetSensorEnabled(SDL_GameController *gamecontroller, SDL_SensorType type, SDL_bool enabled);
742
743/**
744 * Query whether sensor data reporting is enabled for a game controller.
745 *
746 * \param gamecontroller The controller to query
747 * \param type The type of sensor to query
748 *
749 * \returns SDL_TRUE if the sensor is enabled, SDL_FALSE otherwise.
750 */
751extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerIsSensorEnabled(SDL_GameController *gamecontroller, SDL_SensorType type);
752
753/**
754 * Get the current state of a game controller sensor.
755 *
756 * The number of values and interpretation of the data is sensor dependent.
757 * See SDL_sensor.h for the details for each type of sensor.
758 *
759 * \param gamecontroller The controller to query
760 * \param type The type of sensor to query
761 * \param data A pointer filled with the current sensor state
762 * \param num_values The number of values to write to data
763 * \return 0 or -1 if an error occurred.
764 */
765extern DECLSPEC int SDLCALL SDL_GameControllerGetSensorData(SDL_GameController *gamecontroller, SDL_SensorType type, float *data, int num_values);
766
767/**
768 * Start a rumble effect on a game controller.
769 *
770 * Each call to this function cancels any previous rumble effect, and calling
771 * it with 0 intensity stops any rumbling.
772 *
773 * \param gamecontroller The controller to vibrate
774 * \param low_frequency_rumble The intensity of the low frequency (left)
775 * rumble motor, from 0 to 0xFFFF
776 * \param high_frequency_rumble The intensity of the high frequency (right)
777 * rumble motor, from 0 to 0xFFFF
778 * \param duration_ms The duration of the rumble effect, in milliseconds
779 * \returns 0, or -1 if rumble isn't supported on this controller
780 */
781extern DECLSPEC int SDLCALL SDL_GameControllerRumble(SDL_GameController *gamecontroller, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
782
783/**
784 * Start a rumble effect in the game controller's triggers.
785 *
786 * Each call to this function cancels any previous trigger rumble effect, and
787 * calling it with 0 intensity stops any rumbling.
788 *
789 * Note that this is rumbling of the _triggers_ and not the game controller as
790 * a whole. The first controller to offer this feature was the PlayStation 5's
791 * DualShock 5.
792 *
793 * \param gamecontroller The controller to vibrate
794 * \param left_rumble The intensity of the left trigger rumble motor, from 0
795 * to 0xFFFF
796 * \param right_rumble The intensity of the right trigger rumble motor, from 0 to 0xFFFF
797 * \param duration_ms The duration of the rumble effect, in milliseconds
798 *
799 * \returns 0, or -1 if trigger rumble isn't supported on this controller
800 */
801extern DECLSPEC int SDLCALL SDL_GameControllerRumbleTriggers(SDL_GameController *gamecontroller, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms);
802
803/**
804 * Query whether a game controller has an LED.
805 *
806 * \param gamecontroller The controller to query
807 * \returns SDL_TRUE, or SDL_FALSE if this controller does not have a
808 * modifiable LED
809 */
810extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerHasLED(SDL_GameController *gamecontroller);
811
812/**
813 * Update a game controller's LED color.
814 *
815 * \param gamecontroller The controller to update
816 * \param red The intensity of the red LED
817 * \param green The intensity of the green LED
818 * \param blue The intensity of the blue LED
819 * \returns 0, or -1 if this controller does not have a modifiable LED
820 */
821extern DECLSPEC int SDLCALL SDL_GameControllerSetLED(SDL_GameController *gamecontroller, Uint8 red, Uint8 green, Uint8 blue);
822
823/**
824 * Close a game controller previously opened with SDL_GameControllerOpen().
825 *
826 * \param gamecontroller a game controller identifier previously returned by
827 * SDL_GameControllerOpen()
828 *
829 * \sa SDL_GameControllerOpen
830 */
831extern DECLSPEC void SDLCALL SDL_GameControllerClose(SDL_GameController *gamecontroller);
832
833/* Ends C function definitions when using C++ */
834#ifdef __cplusplus
835}
836#endif
837#include "close_code.h"
838
839#endif /* SDL_gamecontroller_h_ */
840
841/* vi: set ts=4 sw=4 expandtab: */
842