My Project
SDL_gamecontroller.h
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2020 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 
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
40 extern "C" {
41 #endif
42 
58 struct _SDL_GameController;
59 typedef struct _SDL_GameController SDL_GameController;
60 
61 typedef 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 
73 typedef 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 
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 
98 
99 
134 extern DECLSPEC int SDLCALL SDL_GameControllerAddMappingsFromRW(SDL_RWops * rw, int freerw);
135 
141 #define SDL_GameControllerAddMappingsFromFile(file) SDL_GameControllerAddMappingsFromRW(SDL_RWFromFile(file, "rb"), 1)
142 
148 extern DECLSPEC int SDLCALL SDL_GameControllerAddMapping(const char* mappingString);
149 
155 extern DECLSPEC int SDLCALL SDL_GameControllerNumMappings(void);
156 
162 extern DECLSPEC char * SDLCALL SDL_GameControllerMappingForIndex(int mapping_index);
163 
169 extern DECLSPEC char * SDLCALL SDL_GameControllerMappingForGUID(SDL_JoystickGUID guid);
170 
176 extern DECLSPEC char * SDLCALL SDL_GameControllerMapping(SDL_GameController *gamecontroller);
177 
181 extern DECLSPEC SDL_bool SDLCALL SDL_IsGameController(int joystick_index);
182 
188 extern DECLSPEC const char *SDLCALL SDL_GameControllerNameForIndex(int joystick_index);
189 
194 extern DECLSPEC SDL_GameControllerType SDLCALL SDL_GameControllerTypeForIndex(int joystick_index);
195 
202 extern DECLSPEC char *SDLCALL SDL_GameControllerMappingForDeviceIndex(int joystick_index);
203 
213 extern DECLSPEC SDL_GameController *SDLCALL SDL_GameControllerOpen(int joystick_index);
214 
218 extern DECLSPEC SDL_GameController *SDLCALL SDL_GameControllerFromInstanceID(SDL_JoystickID joyid);
219 
223 extern DECLSPEC SDL_GameController *SDLCALL SDL_GameControllerFromPlayerIndex(int player_index);
224 
228 extern DECLSPEC const char *SDLCALL SDL_GameControllerName(SDL_GameController *gamecontroller);
229 
233 extern DECLSPEC SDL_GameControllerType SDLCALL SDL_GameControllerGetType(SDL_GameController *gamecontroller);
234 
240 extern DECLSPEC int SDLCALL SDL_GameControllerGetPlayerIndex(SDL_GameController *gamecontroller);
241 
245 extern DECLSPEC void SDLCALL SDL_GameControllerSetPlayerIndex(SDL_GameController *gamecontroller, int player_index);
246 
251 extern DECLSPEC Uint16 SDLCALL SDL_GameControllerGetVendor(SDL_GameController *gamecontroller);
252 
257 extern DECLSPEC Uint16 SDLCALL SDL_GameControllerGetProduct(SDL_GameController *gamecontroller);
258 
263 extern DECLSPEC Uint16 SDLCALL SDL_GameControllerGetProductVersion(SDL_GameController *gamecontroller);
264 
270 extern DECLSPEC const char * SDLCALL SDL_GameControllerGetSerial(SDL_GameController *gamecontroller);
271 
276 extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerGetAttached(SDL_GameController *gamecontroller);
277 
281 extern DECLSPEC SDL_Joystick *SDLCALL SDL_GameControllerGetJoystick(SDL_GameController *gamecontroller);
282 
292 extern DECLSPEC int SDLCALL SDL_GameControllerEventState(int state);
293 
300 extern DECLSPEC void SDLCALL SDL_GameControllerUpdate(void);
301 
302 
312 typedef enum
313 {
314  SDL_CONTROLLER_AXIS_INVALID = -1,
315  SDL_CONTROLLER_AXIS_LEFTX,
316  SDL_CONTROLLER_AXIS_LEFTY,
317  SDL_CONTROLLER_AXIS_RIGHTX,
318  SDL_CONTROLLER_AXIS_RIGHTY,
319  SDL_CONTROLLER_AXIS_TRIGGERLEFT,
320  SDL_CONTROLLER_AXIS_TRIGGERRIGHT,
321  SDL_CONTROLLER_AXIS_MAX
323 
327 extern DECLSPEC SDL_GameControllerAxis SDLCALL SDL_GameControllerGetAxisFromString(const char *pchString);
328 
332 extern DECLSPEC const char* SDLCALL SDL_GameControllerGetStringForAxis(SDL_GameControllerAxis axis);
333 
337 extern DECLSPEC SDL_GameControllerButtonBind SDLCALL
338 SDL_GameControllerGetBindForAxis(SDL_GameController *gamecontroller,
340 
344 extern DECLSPEC SDL_bool SDLCALL
345 SDL_GameControllerHasAxis(SDL_GameController *gamecontroller, SDL_GameControllerAxis axis);
346 
355 extern DECLSPEC Sint16 SDLCALL
356 SDL_GameControllerGetAxis(SDL_GameController *gamecontroller, SDL_GameControllerAxis axis);
357 
361 typedef enum
362 {
363  SDL_CONTROLLER_BUTTON_INVALID = -1,
364  SDL_CONTROLLER_BUTTON_A,
365  SDL_CONTROLLER_BUTTON_B,
366  SDL_CONTROLLER_BUTTON_X,
367  SDL_CONTROLLER_BUTTON_Y,
368  SDL_CONTROLLER_BUTTON_BACK,
369  SDL_CONTROLLER_BUTTON_GUIDE,
370  SDL_CONTROLLER_BUTTON_START,
371  SDL_CONTROLLER_BUTTON_LEFTSTICK,
372  SDL_CONTROLLER_BUTTON_RIGHTSTICK,
373  SDL_CONTROLLER_BUTTON_LEFTSHOULDER,
374  SDL_CONTROLLER_BUTTON_RIGHTSHOULDER,
375  SDL_CONTROLLER_BUTTON_DPAD_UP,
376  SDL_CONTROLLER_BUTTON_DPAD_DOWN,
377  SDL_CONTROLLER_BUTTON_DPAD_LEFT,
378  SDL_CONTROLLER_BUTTON_DPAD_RIGHT,
379  SDL_CONTROLLER_BUTTON_MISC1, /* Xbox Series X share button, PS5 microphone button, Nintendo Switch Pro capture button */
380  SDL_CONTROLLER_BUTTON_PADDLE1, /* Xbox Elite paddle P1 */
381  SDL_CONTROLLER_BUTTON_PADDLE2, /* Xbox Elite paddle P3 */
382  SDL_CONTROLLER_BUTTON_PADDLE3, /* Xbox Elite paddle P2 */
383  SDL_CONTROLLER_BUTTON_PADDLE4, /* Xbox Elite paddle P4 */
384  SDL_CONTROLLER_BUTTON_TOUCHPAD, /* PS4/PS5 touchpad button */
385  SDL_CONTROLLER_BUTTON_MAX
387 
391 extern DECLSPEC SDL_GameControllerButton SDLCALL SDL_GameControllerGetButtonFromString(const char *pchString);
392 
396 extern DECLSPEC const char* SDLCALL SDL_GameControllerGetStringForButton(SDL_GameControllerButton button);
397 
401 extern DECLSPEC SDL_GameControllerButtonBind SDLCALL
402 SDL_GameControllerGetBindForButton(SDL_GameController *gamecontroller,
403  SDL_GameControllerButton button);
404 
408 extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerHasButton(SDL_GameController *gamecontroller,
409  SDL_GameControllerButton button);
410 
416 extern DECLSPEC Uint8 SDLCALL SDL_GameControllerGetButton(SDL_GameController *gamecontroller,
417  SDL_GameControllerButton button);
418 
422 extern DECLSPEC int SDLCALL SDL_GameControllerGetNumTouchpads(SDL_GameController *gamecontroller);
423 
427 extern DECLSPEC int SDLCALL SDL_GameControllerGetNumTouchpadFingers(SDL_GameController *gamecontroller, int touchpad);
428 
432 extern DECLSPEC int SDLCALL SDL_GameControllerGetTouchpadFinger(SDL_GameController *gamecontroller, int touchpad, int finger, Uint8 *state, float *x, float *y, float *pressure);
433 
442 extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerHasSensor(SDL_GameController *gamecontroller, SDL_SensorType type);
443 
453 extern DECLSPEC int SDLCALL SDL_GameControllerSetSensorEnabled(SDL_GameController *gamecontroller, SDL_SensorType type, SDL_bool enabled);
454 
463 extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerIsSensorEnabled(SDL_GameController *gamecontroller, SDL_SensorType type);
464 
478 extern DECLSPEC int SDLCALL SDL_GameControllerGetSensorData(SDL_GameController *gamecontroller, SDL_SensorType type, float *data, int num_values);
479 
491 extern DECLSPEC int SDLCALL SDL_GameControllerRumble(SDL_GameController *gamecontroller, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
492 
504 extern DECLSPEC int SDLCALL SDL_GameControllerRumbleTriggers(SDL_GameController *gamecontroller, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms);
505 
513 extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerHasLED(SDL_GameController *gamecontroller);
514 
525 extern DECLSPEC int SDLCALL SDL_GameControllerSetLED(SDL_GameController *gamecontroller, Uint8 red, Uint8 green, Uint8 blue);
526 
530 extern DECLSPEC void SDLCALL SDL_GameControllerClose(SDL_GameController *gamecontroller);
531 
532 
533 /* Ends C function definitions when using C++ */
534 #ifdef __cplusplus
535 }
536 #endif
537 #include "close_code.h"
538 
539 #endif /* SDL_gamecontroller_h_ */
540 
541 /* vi: set ts=4 sw=4 expandtab: */
DECLSPEC int SDLCALL SDL_GameControllerAddMappingsFromRW(SDL_RWops *rw, int freerw)
DECLSPEC Sint16 SDLCALL SDL_GameControllerGetAxis(SDL_GameController *gamecontroller, SDL_GameControllerAxis axis)
DECLSPEC int SDLCALL SDL_GameControllerRumbleTriggers(SDL_GameController *gamecontroller, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms)
DECLSPEC SDL_bool SDLCALL SDL_GameControllerIsSensorEnabled(SDL_GameController *gamecontroller, SDL_SensorType type)
DECLSPEC char *SDLCALL SDL_GameControllerMappingForGUID(SDL_JoystickGUID guid)
DECLSPEC Uint16 SDLCALL SDL_GameControllerGetProductVersion(SDL_GameController *gamecontroller)
DECLSPEC SDL_bool SDLCALL SDL_IsGameController(int joystick_index)
DECLSPEC SDL_GameController *SDLCALL SDL_GameControllerFromInstanceID(SDL_JoystickID joyid)
DECLSPEC char *SDLCALL SDL_GameControllerMappingForDeviceIndex(int joystick_index)
DECLSPEC SDL_GameControllerAxis SDLCALL SDL_GameControllerGetAxisFromString(const char *pchString)
DECLSPEC int SDLCALL SDL_GameControllerEventState(int state)
DECLSPEC int SDLCALL SDL_GameControllerGetTouchpadFinger(SDL_GameController *gamecontroller, int touchpad, int finger, Uint8 *state, float *x, float *y, float *pressure)
DECLSPEC SDL_GameControllerButtonBind SDLCALL SDL_GameControllerGetBindForButton(SDL_GameController *gamecontroller, SDL_GameControllerButton button)
DECLSPEC int SDLCALL SDL_GameControllerGetNumTouchpads(SDL_GameController *gamecontroller)
DECLSPEC const char *SDLCALL SDL_GameControllerGetStringForButton(SDL_GameControllerButton button)
DECLSPEC int SDLCALL SDL_GameControllerSetLED(SDL_GameController *gamecontroller, Uint8 red, Uint8 green, Uint8 blue)
DECLSPEC int SDLCALL SDL_GameControllerAddMapping(const char *mappingString)
DECLSPEC const char *SDLCALL SDL_GameControllerGetStringForAxis(SDL_GameControllerAxis axis)
DECLSPEC char *SDLCALL SDL_GameControllerMapping(SDL_GameController *gamecontroller)
DECLSPEC SDL_bool SDLCALL SDL_GameControllerHasButton(SDL_GameController *gamecontroller, SDL_GameControllerButton button)
DECLSPEC int SDLCALL SDL_GameControllerGetNumTouchpadFingers(SDL_GameController *gamecontroller, int touchpad)
DECLSPEC const char *SDLCALL SDL_GameControllerGetSerial(SDL_GameController *gamecontroller)
DECLSPEC SDL_bool SDLCALL SDL_GameControllerHasAxis(SDL_GameController *gamecontroller, SDL_GameControllerAxis axis)
DECLSPEC void SDLCALL SDL_GameControllerSetPlayerIndex(SDL_GameController *gamecontroller, int player_index)
DECLSPEC SDL_GameControllerType SDLCALL SDL_GameControllerTypeForIndex(int joystick_index)
DECLSPEC Uint16 SDLCALL SDL_GameControllerGetProduct(SDL_GameController *gamecontroller)
DECLSPEC void SDLCALL SDL_GameControllerUpdate(void)
SDL_GameControllerAxis
Definition: SDL_gamecontroller.h:313
DECLSPEC void SDLCALL SDL_GameControllerClose(SDL_GameController *gamecontroller)
DECLSPEC int SDLCALL SDL_GameControllerGetPlayerIndex(SDL_GameController *gamecontroller)
SDL_GameControllerButton
Definition: SDL_gamecontroller.h:362
DECLSPEC const char *SDLCALL SDL_GameControllerNameForIndex(int joystick_index)
DECLSPEC SDL_GameControllerType SDLCALL SDL_GameControllerGetType(SDL_GameController *gamecontroller)
DECLSPEC Uint16 SDLCALL SDL_GameControllerGetVendor(SDL_GameController *gamecontroller)
struct SDL_GameControllerButtonBind SDL_GameControllerButtonBind
DECLSPEC int SDLCALL SDL_GameControllerNumMappings(void)
DECLSPEC int SDLCALL SDL_GameControllerGetSensorData(SDL_GameController *gamecontroller, SDL_SensorType type, float *data, int num_values)
DECLSPEC SDL_GameController *SDLCALL SDL_GameControllerFromPlayerIndex(int player_index)
DECLSPEC char *SDLCALL SDL_GameControllerMappingForIndex(int mapping_index)
DECLSPEC SDL_GameController *SDLCALL SDL_GameControllerOpen(int joystick_index)
DECLSPEC SDL_GameControllerButtonBind SDLCALL SDL_GameControllerGetBindForAxis(SDL_GameController *gamecontroller, SDL_GameControllerAxis axis)
DECLSPEC int SDLCALL SDL_GameControllerSetSensorEnabled(SDL_GameController *gamecontroller, SDL_SensorType type, SDL_bool enabled)
DECLSPEC const char *SDLCALL SDL_GameControllerName(SDL_GameController *gamecontroller)
DECLSPEC SDL_bool SDLCALL SDL_GameControllerGetAttached(SDL_GameController *gamecontroller)
DECLSPEC SDL_GameControllerButton SDLCALL SDL_GameControllerGetButtonFromString(const char *pchString)
DECLSPEC SDL_bool SDLCALL SDL_GameControllerHasLED(SDL_GameController *gamecontroller)
DECLSPEC SDL_Joystick *SDLCALL SDL_GameControllerGetJoystick(SDL_GameController *gamecontroller)
DECLSPEC int SDLCALL SDL_GameControllerRumble(SDL_GameController *gamecontroller, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
DECLSPEC SDL_bool SDLCALL SDL_GameControllerHasSensor(SDL_GameController *gamecontroller, SDL_SensorType type)
DECLSPEC Uint8 SDLCALL SDL_GameControllerGetButton(SDL_GameController *gamecontroller, SDL_GameControllerButton button)
Sint32 SDL_JoystickID
Definition: SDL_joystick.h:81
SDL_SensorType
Definition: SDL_sensor.h:70
Definition: SDL_gamecontroller.h:85
Definition: SDL_joystick.h:70
Definition: SDL_rwops.h:53