author | Sam Lantinga <slouken@libsdl.org> |
Fri, 25 Jan 2013 14:25:19 -0800 | |
changeset 6823 | e9d312d26979 |
parent 6738 | b408d5a406a3 |
child 6841 | 90bba8d8e42a |
permissions | -rw-r--r-- |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
2 |
Simple DirectMedia Layer |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
3 |
Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org> |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
4 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
5 |
This software is provided 'as-is', without any express or implied |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
6 |
warranty. In no event will the authors be held liable for any damages |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
7 |
arising from the use of this software. |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
8 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
9 |
Permission is granted to anyone to use this software for any purpose, |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
10 |
including commercial applications, and to alter it and redistribute it |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
11 |
freely, subject to the following restrictions: |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
12 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
13 |
1. The origin of this software must not be misrepresented; you must not |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
14 |
claim that you wrote the original software. If you use this software |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
15 |
in a product, an acknowledgment in the product documentation would be |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
16 |
appreciated but is not required. |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
17 |
2. Altered source versions must be plainly marked as such, and must not be |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
18 |
misrepresented as being the original software. |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
19 |
3. This notice may not be removed or altered from any source distribution. |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 |
#include "SDL_config.h" |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
23 |
/* This is the game controller API for Simple DirectMedia Layer */ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
24 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
25 |
#include "SDL_events.h" |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
26 |
#include "SDL_assert.h" |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
27 |
#include "SDL_sysjoystick.h" |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
28 |
#include "SDL_hints.h" |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
29 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
30 |
#if !SDL_EVENTS_DISABLED |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
31 |
#include "../events/SDL_events_c.h" |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
32 |
#endif |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
33 |
#define ABS(_x) ((_x) < 0 ? -(_x) : (_x)) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
34 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
35 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
36 |
/* a list of currently opened game controllers */ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
37 |
static SDL_GameController *SDL_gamecontrollers = NULL; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
38 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
39 |
/* keep track of the hat and mask value that transforms this hat movement into a button press */ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
40 |
struct _SDL_HatAsButton |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
41 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
42 |
int hat; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
43 |
Uint8 mask; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
44 |
}; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
46 |
#define k_nMaxReverseEntries 20 |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
47 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
48 |
/* our in memory mapping db between joystick objects and controller mappings*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
49 |
struct _SDL_ControllerMapping |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
50 |
{ |
6738 | 51 |
SDL_JoystickGUID guid; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
52 |
const char *name; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
53 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
54 |
// mapping of axis/button id to controller version |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
55 |
int axes[SDL_CONTROLLER_AXIS_MAX]; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
56 |
int buttons[SDL_CONTROLLER_BUTTON_MAX]; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
57 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
58 |
int axesasbutton[SDL_CONTROLLER_BUTTON_MAX]; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
59 |
struct _SDL_HatAsButton hatasbutton[SDL_CONTROLLER_BUTTON_MAX]; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
60 |
int buttonasaxis[SDL_CONTROLLER_AXIS_MAX]; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
61 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
62 |
// reverse mapping, joystick indices to buttons |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
63 |
SDL_CONTROLLER_AXIS raxes[k_nMaxReverseEntries]; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
64 |
SDL_CONTROLLER_BUTTON rbuttons[k_nMaxReverseEntries]; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
65 |
SDL_CONTROLLER_BUTTON raxesasbutton[k_nMaxReverseEntries]; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
66 |
struct _SDL_HatAsButton rhatasbutton[k_nMaxReverseEntries]; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
67 |
SDL_CONTROLLER_AXIS rbuttonasaxis[k_nMaxReverseEntries]; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
68 |
}; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
69 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
70 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
71 |
/* our hard coded list of mapping support */ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
72 |
typedef struct _ControllerMapping_t |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
73 |
{ |
6738 | 74 |
SDL_JoystickGUID guid; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
75 |
char *name; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
76 |
const char *mapping; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
77 |
struct _ControllerMapping_t *next; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
78 |
} ControllerMapping_t; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
79 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
80 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
81 |
/* default mappings we support */ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
82 |
const char *s_ControllerMappings [] = |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
83 |
{ |
6701
91160c9b35da
The XInput code is only available in the DirectInput joystick driver.
Sam Lantinga <slouken@libsdl.org>
parents:
6690
diff
changeset
|
84 |
#ifdef SDL_JOYSTICK_DINPUT |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
85 |
"xinput,X360 Controller,a:b10,b:b11,y:b13,x:b12,start:b4,guide:b14,back:b5,dpup:b0,dpleft:b2,dpdown:b1,dpright:b3,leftshoulder:b8,rightshoulder:b9,leftstick:b6,rightstick:b7,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5", |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
86 |
"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", |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
87 |
"88880803000000000000504944564944,PS3,a:b2,b:b1,x:b0,y:b3,start:b11,back:b8,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.4,dpdown:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:b6,righttrigger:b7,guide:b12", |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
88 |
"25090500000000000000504944564944,PS3 DualShock,a:b2,b:b1,x:b0,y:b3,start:b8,guide:,back:b9,leftstick:b10,rightstick:b11,leftshoulder:b6,rightshoulder:b7,dpup:h0.1,dpleft:h0.4,dpdown:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b4,righttrigger:b5", |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
89 |
#elif defined(__MACOSX__) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
90 |
"5e040000000000008e02000000000000,X360 Controller,a:b0,b:b1,y:b3,x:b2,start:b8,guide:b10,back:b9,dpup:b11,dpleft:b13,dpdown:b12,dpright:b14,leftshoulder:b4,rightshoulder:b5,leftstick:b6,rightstick:b7,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5", |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
91 |
"4c050000000000006802000000000000,PS3 Controller,a:b14,b:b13,x:b12,y:b15,start:b3,guide:b16,back:b0,leftstick:b1,rightstick:b2,leftshoulder:b10,rightshoulder:b11,dpup:b4,dpleft:b6,dpdown:b7,dpright:b5,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b8,righttrigger:b9", |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
92 |
#elif defined(__LINUX__) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
93 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
94 |
#endif |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
95 |
NULL |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
96 |
}; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
97 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
98 |
static ControllerMapping_t *s_pSupportedControllers = NULL; |
6708 | 99 |
#ifdef SDL_JOYSTICK_DINPUT |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
100 |
static ControllerMapping_t *s_pXInputMapping = NULL; |
6708 | 101 |
#endif |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
102 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
103 |
/* The SDL game controller structure */ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
104 |
struct _SDL_GameController |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
105 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
106 |
SDL_Joystick *joystick; /* underlying joystick device */ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
107 |
int ref_count; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
108 |
struct _SDL_ControllerMapping mapping; /* the mapping object for this controller */ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
109 |
struct _SDL_GameController *next; /* pointer to next game controller we have allocated */ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
110 |
}; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
111 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
112 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
113 |
int SDL_PrivateGameControllerAxis(SDL_GameController * gamecontroller, SDL_CONTROLLER_AXIS axis, Sint16 value); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
114 |
int SDL_PrivateGameControllerButton(SDL_GameController * gamecontroller, SDL_CONTROLLER_BUTTON button, Uint8 state); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
115 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
116 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
117 |
* Event filter to fire controller events from joystick ones |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
118 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
119 |
int SDL_GameControllerEventWatcher(void *userdata, SDL_Event * event) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
120 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
121 |
switch( event->type ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
122 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
123 |
case SDL_JOYAXISMOTION: |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
124 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
125 |
SDL_GameController *controllerlist = SDL_gamecontrollers; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
126 |
while ( controllerlist ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
127 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
128 |
if ( controllerlist->joystick->instance_id == event->jaxis.which ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
129 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
130 |
if ( controllerlist->mapping.raxes[event->jaxis.axis] >= 0 ) // simple axis to axis, send it through |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
131 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
132 |
SDL_PrivateGameControllerAxis( controllerlist, controllerlist->mapping.raxes[event->jaxis.axis], event->jaxis.value ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
133 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
134 |
else if ( controllerlist->mapping.raxesasbutton[event->jaxis.axis] >= 0 ) // simlate an axis as a button |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
135 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
136 |
SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.raxesasbutton[event->jaxis.axis], ABS(event->jaxis.value) > 32768/2 ? 1 : 0 ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
137 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
138 |
break; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
139 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
140 |
controllerlist = controllerlist->next; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
141 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
142 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
143 |
break; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
144 |
case SDL_JOYBUTTONDOWN: |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
145 |
case SDL_JOYBUTTONUP: |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
146 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
147 |
SDL_GameController *controllerlist = SDL_gamecontrollers; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
148 |
while ( controllerlist ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
149 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
150 |
if ( controllerlist->joystick->instance_id == event->jbutton.which ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
151 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
152 |
if ( controllerlist->mapping.rbuttons[event->jbutton.button] >= 0 ) // simple button as button |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
153 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
154 |
SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rbuttons[event->jbutton.button], event->jbutton.state ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
155 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
156 |
else if ( controllerlist->mapping.rbuttonasaxis[event->jbutton.button] >= 0 ) // an button pretending to be an axis |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
157 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
158 |
SDL_PrivateGameControllerAxis( controllerlist, controllerlist->mapping.rbuttonasaxis[event->jbutton.button], event->jbutton.state > 0 ? 32768 : 0 ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
159 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
160 |
break; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
161 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
162 |
controllerlist = controllerlist->next; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
163 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
164 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
165 |
break; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
166 |
case SDL_JOYHATMOTION: |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
167 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
168 |
if ( event->jhat.hat == 0 ) // BUGBUG - multiple hat support?? |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
169 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
170 |
SDL_GameController *controllerlist = SDL_gamecontrollers; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
171 |
while ( controllerlist ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
172 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
173 |
if ( controllerlist->joystick->instance_id == event->jhat.which ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
174 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
175 |
static Uint8 bHatsDown = 0; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
176 |
if ( event->jhat.value == 0 ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
177 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
178 |
if ( bHatsDown & SDL_HAT_DOWN ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
179 |
SDL_PrivateGameControllerButton( controllerlist, SDL_CONTROLLER_BUTTON_DPAD_DOWN, 0 ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
180 |
if ( bHatsDown & SDL_HAT_UP ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
181 |
SDL_PrivateGameControllerButton( controllerlist, SDL_CONTROLLER_BUTTON_DPAD_UP, 0 ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
182 |
if ( bHatsDown & SDL_HAT_LEFT ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
183 |
SDL_PrivateGameControllerButton( controllerlist, SDL_CONTROLLER_BUTTON_DPAD_LEFT, 0 ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
184 |
if ( bHatsDown & SDL_HAT_RIGHT ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
185 |
SDL_PrivateGameControllerButton( controllerlist, SDL_CONTROLLER_BUTTON_DPAD_RIGHT, 0 ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
186 |
bHatsDown = 0; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
187 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
188 |
else if ( controllerlist->mapping.rhatasbutton[event->jhat.value].hat >= 0 ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
189 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
190 |
bHatsDown |= event->jhat.value; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
191 |
SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rhatasbutton[event->jhat.value].hat, (event->jhat.value & controllerlist->mapping.rhatasbutton[event->jhat.value].mask) > 0 ? 1 : 0 ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
192 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
193 |
break; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
194 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
195 |
controllerlist = controllerlist->next; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
196 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
197 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
198 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
199 |
break; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
200 |
case SDL_JOYDEVICEADDED: |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
201 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
202 |
if ( SDL_IsGameController(event->jdevice.which ) ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
203 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
204 |
SDL_Event deviceevent; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
205 |
deviceevent.type = SDL_CONTROLLERDEVICEADDED; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
206 |
deviceevent.cdevice.which = event->jdevice.which; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
207 |
SDL_PushEvent(&deviceevent); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
208 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
209 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
210 |
break; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
211 |
case SDL_JOYDEVICEREMOVED: |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
212 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
213 |
SDL_GameController *controllerlist = SDL_gamecontrollers; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
214 |
while ( controllerlist ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
215 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
216 |
if ( controllerlist->joystick->instance_id == event->jdevice.which ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
217 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
218 |
SDL_Event deviceevent; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
219 |
deviceevent.type = SDL_CONTROLLERDEVICEREMOVED; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
220 |
deviceevent.cdevice.which = event->jdevice.which; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
221 |
SDL_PushEvent(&deviceevent); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
222 |
break; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
223 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
224 |
controllerlist = controllerlist->next; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
225 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
226 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
227 |
break; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
228 |
default: |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
229 |
break; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
230 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
231 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
232 |
return 1; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
233 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
234 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
235 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
236 |
* Helper function to determine pre-caclulated offset to certain joystick mappings |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
237 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
238 |
ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
239 |
{ |
6701
91160c9b35da
The XInput code is only available in the DirectInput joystick driver.
Sam Lantinga <slouken@libsdl.org>
parents:
6690
diff
changeset
|
240 |
#ifdef SDL_JOYSTICK_DINPUT |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
241 |
if ( SDL_SYS_IsXInputDeviceIndex(device_index) && s_pXInputMapping ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
242 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
243 |
return s_pXInputMapping; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
244 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
245 |
#endif |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
246 |
return NULL; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
247 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
248 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
249 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
250 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
251 |
* convert a string to its enum equivalent |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
252 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
253 |
SDL_CONTROLLER_AXIS SDL_GameControllerGetAxisFromString( const char *pchString ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
254 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
255 |
if ( !pchString || !pchString[0] ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
256 |
return SDL_CONTROLLER_AXIS_INVALID; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
257 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
258 |
if ( !SDL_strcasecmp( pchString, "leftx" ) ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
259 |
return SDL_CONTROLLER_AXIS_LEFTX; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
260 |
else if ( !SDL_strcasecmp( pchString, "lefty" ) ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
261 |
return SDL_CONTROLLER_AXIS_LEFTY; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
262 |
else if ( !SDL_strcasecmp( pchString, "rightx" ) ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
263 |
return SDL_CONTROLLER_AXIS_RIGHTX; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
264 |
else if ( !SDL_strcasecmp( pchString, "righty" ) ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
265 |
return SDL_CONTROLLER_AXIS_RIGHTY; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
266 |
else if ( !SDL_strcasecmp( pchString, "lefttrigger" ) ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
267 |
return SDL_CONTROLLER_AXIS_TRIGGERLEFT; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
268 |
else if ( !SDL_strcasecmp( pchString, "righttrigger" ) ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
269 |
return SDL_CONTROLLER_AXIS_TRIGGERRIGHT; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
270 |
else |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
271 |
return SDL_CONTROLLER_AXIS_INVALID; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
272 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
273 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
274 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
275 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
276 |
* convert a string to its enum equivalent |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
277 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
278 |
SDL_CONTROLLER_BUTTON SDL_GameControllerGetButtonFromString( const char *pchString ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
279 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
280 |
if ( !pchString || !pchString[0] ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
281 |
return SDL_CONTROLLER_BUTTON_INVALID; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
282 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
283 |
if ( !SDL_strcasecmp( pchString, "a" ) ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
284 |
return SDL_CONTROLLER_BUTTON_A; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
285 |
else if ( !SDL_strcasecmp( pchString, "b" ) ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
286 |
return SDL_CONTROLLER_BUTTON_B; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
287 |
else if ( !SDL_strcasecmp( pchString, "x" ) ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
288 |
return SDL_CONTROLLER_BUTTON_X; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
289 |
else if ( !SDL_strcasecmp( pchString, "y" ) ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
290 |
return SDL_CONTROLLER_BUTTON_Y; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
291 |
else if ( !SDL_strcasecmp( pchString, "start" ) ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
292 |
return SDL_CONTROLLER_BUTTON_START; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
293 |
else if ( !SDL_strcasecmp( pchString, "guide" ) ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
294 |
return SDL_CONTROLLER_BUTTON_GUIDE; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
295 |
else if ( !SDL_strcasecmp( pchString, "back" ) ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
296 |
return SDL_CONTROLLER_BUTTON_BACK; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
297 |
else if ( !SDL_strcasecmp( pchString, "dpup" ) ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
298 |
return SDL_CONTROLLER_BUTTON_DPAD_UP; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
299 |
else if ( !SDL_strcasecmp( pchString, "dpdown" ) ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
300 |
return SDL_CONTROLLER_BUTTON_DPAD_DOWN; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
301 |
else if ( !SDL_strcasecmp( pchString, "dpleft" ) ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
302 |
return SDL_CONTROLLER_BUTTON_DPAD_LEFT; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
303 |
else if ( !SDL_strcasecmp( pchString, "dpright" ) ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
304 |
return SDL_CONTROLLER_BUTTON_DPAD_RIGHT; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
305 |
else if ( !SDL_strcasecmp( pchString, "leftshoulder" ) ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
306 |
return SDL_CONTROLLER_BUTTON_LEFTSHOULDER; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
307 |
else if ( !SDL_strcasecmp( pchString, "rightshoulder" ) ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
308 |
return SDL_CONTROLLER_BUTTON_RIGHTSHOULDER; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
309 |
else if ( !SDL_strcasecmp( pchString, "leftstick" ) ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
310 |
return SDL_CONTROLLER_BUTTON_LEFTSTICK; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
311 |
else if ( !SDL_strcasecmp( pchString, "rightstick" ) ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
312 |
return SDL_CONTROLLER_BUTTON_RIGHTSTICK; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
313 |
else |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
314 |
return SDL_CONTROLLER_BUTTON_INVALID; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
315 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
316 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
317 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
318 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
319 |
* given a controller button name and a joystick name update our mapping structure with it |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
320 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
321 |
void SDL_PrivateGameControllerParseButton( const char *szGameButton, const char *szJoystickButton, struct _SDL_ControllerMapping *pMapping ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
322 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
323 |
int iSDLButton = 0; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
324 |
SDL_CONTROLLER_BUTTON button; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
325 |
SDL_CONTROLLER_AXIS axis; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
326 |
button = SDL_GameControllerGetButtonFromString( szGameButton ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
327 |
axis = SDL_GameControllerGetAxisFromString( szGameButton ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
328 |
iSDLButton = SDL_atoi( &szJoystickButton[1] ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
329 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
330 |
if ( iSDLButton >= k_nMaxReverseEntries ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
331 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
332 |
SDL_SetError("Button index too large: %d", iSDLButton ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
333 |
return; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
334 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
335 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
336 |
if ( szJoystickButton[0] == 'a' ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
337 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
338 |
if ( axis != SDL_CONTROLLER_AXIS_INVALID ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
339 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
340 |
pMapping->axes[ axis ] = iSDLButton; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
341 |
pMapping->raxes[ iSDLButton ] = axis; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
342 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
343 |
else if ( button != SDL_CONTROLLER_BUTTON_INVALID ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
344 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
345 |
pMapping->buttonasaxis[ button ] = iSDLButton; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
346 |
pMapping->rbuttonasaxis[ iSDLButton ] = button; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
347 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
348 |
else |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
349 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
350 |
SDL_assert( !"How did we get here?" ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
351 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
352 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
353 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
354 |
else if ( szJoystickButton[0] == 'b' ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
355 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
356 |
if ( button != SDL_CONTROLLER_BUTTON_INVALID ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
357 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
358 |
pMapping->buttons[ button ] = iSDLButton; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
359 |
pMapping->rbuttons[ iSDLButton ] = button; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
360 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
361 |
else if ( axis != SDL_CONTROLLER_AXIS_INVALID ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
362 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
363 |
pMapping->buttonasaxis[ axis ] = iSDLButton; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
364 |
pMapping->rbuttonasaxis[ iSDLButton ] = axis; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
365 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
366 |
else |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
367 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
368 |
SDL_assert( !"How did we get here?" ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
369 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
370 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
371 |
else if ( szJoystickButton[0] == 'h' ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
372 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
373 |
int hat = SDL_atoi( &szJoystickButton[1] ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
374 |
int mask = SDL_atoi( &szJoystickButton[3] ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
375 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
376 |
if ( button != SDL_CONTROLLER_BUTTON_INVALID ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
377 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
378 |
pMapping->hatasbutton[ button ].hat = hat; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
379 |
pMapping->hatasbutton[ button ].mask = mask; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
380 |
pMapping->rhatasbutton[ mask ].hat = button; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
381 |
pMapping->rhatasbutton[ mask ].mask = mask; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
382 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
383 |
else if ( axis != SDL_CONTROLLER_AXIS_INVALID ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
384 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
385 |
SDL_assert( !"Support hat as axis" ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
386 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
387 |
else |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
388 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
389 |
SDL_assert( !"How did we get here?" ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
390 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
391 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
392 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
393 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
394 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
395 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
396 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
397 |
* given a controller mapping string update our mapping object |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
398 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
399 |
static void |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
400 |
SDL_PrivateGameControllerParseControllerConfigString( struct _SDL_ControllerMapping *pMapping, const char *pchString ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
401 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
402 |
char szGameButton[20]; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
403 |
char szJoystickButton[20]; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
404 |
SDL_bool bGameButton = SDL_TRUE; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
405 |
int i = 0; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
406 |
const char *pchPos = pchString; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
407 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
408 |
SDL_memset( szGameButton, 0x0, sizeof(szGameButton) ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
409 |
SDL_memset( szJoystickButton, 0x0, sizeof(szJoystickButton) ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
410 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
411 |
while ( pchPos && *pchPos ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
412 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
413 |
if ( *pchPos == ':' ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
414 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
415 |
i = 0; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
416 |
bGameButton = SDL_FALSE; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
417 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
418 |
else if ( *pchPos == ' ' ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
419 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
420 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
421 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
422 |
else if ( *pchPos == ',' ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
423 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
424 |
i = 0; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
425 |
bGameButton = SDL_TRUE; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
426 |
SDL_PrivateGameControllerParseButton( szGameButton, szJoystickButton, pMapping ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
427 |
SDL_memset( szGameButton, 0x0, sizeof(szGameButton) ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
428 |
SDL_memset( szJoystickButton, 0x0, sizeof(szJoystickButton) ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
429 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
430 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
431 |
else if ( bGameButton ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
432 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
433 |
if ( i >= sizeof(szGameButton)) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
434 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
435 |
SDL_SetError( "Button name too large: %s", szGameButton ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
436 |
return; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
437 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
438 |
szGameButton[i] = *pchPos; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
439 |
i++; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
440 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
441 |
else |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
442 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
443 |
if ( i >= sizeof(szJoystickButton)) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
444 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
445 |
SDL_SetError( "Joystick button name too large: %s", szJoystickButton ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
446 |
return; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
447 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
448 |
szJoystickButton[i] = *pchPos; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
449 |
i++; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
450 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
451 |
pchPos++; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
452 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
453 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
454 |
SDL_PrivateGameControllerParseButton( szGameButton, szJoystickButton, pMapping ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
455 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
456 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
457 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
458 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
459 |
* Make a new button mapping struct |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
460 |
*/ |
6738 | 461 |
void SDL_PrivateLoadButtonMapping( struct _SDL_ControllerMapping *pMapping, SDL_JoystickGUID guid, const char *pchName, const char *pchMapping ) |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
462 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
463 |
int j; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
464 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
465 |
pMapping->guid = guid; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
466 |
pMapping->name = pchName; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
467 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
468 |
// set all the button mappings to non defaults |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
469 |
for ( j = 0; j < SDL_CONTROLLER_AXIS_MAX; j++ ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
470 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
471 |
pMapping->axes[j] = -1; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
472 |
pMapping->buttonasaxis[j] = -1; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
473 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
474 |
for ( j = 0; j < SDL_CONTROLLER_BUTTON_MAX; j++ ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
475 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
476 |
pMapping->buttons[j] = -1; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
477 |
pMapping->axesasbutton[j] = -1; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
478 |
pMapping->hatasbutton[j].hat = -1; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
479 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
480 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
481 |
for ( j = 0; j < k_nMaxReverseEntries; j++ ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
482 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
483 |
pMapping->raxes[j] = SDL_CONTROLLER_AXIS_INVALID; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
484 |
pMapping->rbuttons[j] = SDL_CONTROLLER_BUTTON_INVALID; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
485 |
pMapping->raxesasbutton[j] = SDL_CONTROLLER_BUTTON_INVALID; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
486 |
pMapping->rhatasbutton[j].hat = -1; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
487 |
pMapping->rbuttonasaxis[j] = SDL_CONTROLLER_AXIS_INVALID; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
488 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
489 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
490 |
SDL_PrivateGameControllerParseControllerConfigString( pMapping, pchMapping ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
491 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
492 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
493 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
494 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
495 |
* grab the guid string from a mapping string |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
496 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
497 |
char *SDL_PrivateGetControllerGUIDFromMappingString( const char *pMapping ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
498 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
499 |
const char *pFirstComma = SDL_strchr( pMapping, ',' ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
500 |
if ( pFirstComma ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
501 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
502 |
char *pchGUID = SDL_malloc( pFirstComma - pMapping + 1 ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
503 |
if ( !pchGUID ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
504 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
505 |
SDL_OutOfMemory(); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
506 |
return NULL; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
507 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
508 |
SDL_memcpy( pchGUID, pMapping, pFirstComma - pMapping ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
509 |
pchGUID[ pFirstComma - pMapping ] = 0; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
510 |
return pchGUID; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
511 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
512 |
return NULL; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
513 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
514 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
515 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
516 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
517 |
* grab the name string from a mapping string |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
518 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
519 |
char *SDL_PrivateGetControllerNameFromMappingString( const char *pMapping ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
520 |
{ |
6823
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
521 |
const char *pFirstComma, *pSecondComma; |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
522 |
char *pchName; |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
523 |
|
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
524 |
pFirstComma = SDL_strchr( pMapping, ',' ); |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
525 |
if ( !pFirstComma ) |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
526 |
return NULL; |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
527 |
|
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
528 |
pSecondComma = SDL_strchr( pFirstComma + 1, ',' ); |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
529 |
if ( !pSecondComma ) |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
530 |
return NULL; |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
531 |
|
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
532 |
pchName = SDL_malloc( pSecondComma - pFirstComma ); |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
533 |
if ( !pchName ) |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
534 |
{ |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
535 |
SDL_OutOfMemory(); |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
536 |
return NULL; |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
537 |
} |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
538 |
SDL_memcpy( pchName, pFirstComma + 1, pSecondComma - pFirstComma ); |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
539 |
pchName[ pSecondComma - pFirstComma - 1 ] = 0; |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
540 |
return pchName; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
541 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
542 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
543 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
544 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
545 |
* grab the button mapping string from a mapping string |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
546 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
547 |
const char *SDL_PrivateGetControllerMappingFromMappingString( const char *pMapping ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
548 |
{ |
6823
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
549 |
const char *pFirstComma, *pSecondComma; |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
550 |
|
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
551 |
pFirstComma = SDL_strchr( pMapping, ',' ); |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
552 |
if ( !pFirstComma ) |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
553 |
return NULL; |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
554 |
|
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
555 |
pSecondComma = SDL_strchr( pFirstComma + 1, ',' ); |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
556 |
if ( !pSecondComma ) |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
557 |
return NULL; |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
558 |
|
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
559 |
return pSecondComma + 1; /* mapping is everything after the 3rd comma, no need to malloc it */ |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
560 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
561 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
562 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
563 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
564 |
* Initialize the game controller system, mostly load our DB of controller config mappings |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
565 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
566 |
int |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
567 |
SDL_GameControllerInit(void) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
568 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
569 |
int i = 0; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
570 |
const char *pMappingString = NULL; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
571 |
s_pSupportedControllers = NULL; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
572 |
pMappingString = s_ControllerMappings[i]; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
573 |
while ( pMappingString ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
574 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
575 |
ControllerMapping_t *pControllerMapping; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
576 |
char *pchGUID; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
577 |
char *pchName; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
578 |
const char *pchMapping; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
579 |
pControllerMapping = SDL_malloc( sizeof(*pControllerMapping) ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
580 |
if ( !pControllerMapping ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
581 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
582 |
SDL_OutOfMemory(); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
583 |
return -1; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
584 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
585 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
586 |
pchGUID = SDL_PrivateGetControllerGUIDFromMappingString( pMappingString ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
587 |
pchName = SDL_PrivateGetControllerNameFromMappingString( pMappingString ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
588 |
pchMapping = SDL_PrivateGetControllerMappingFromMappingString( pMappingString ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
589 |
if ( pchGUID && pchName ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
590 |
{ |
6701
91160c9b35da
The XInput code is only available in the DirectInput joystick driver.
Sam Lantinga <slouken@libsdl.org>
parents:
6690
diff
changeset
|
591 |
#ifdef SDL_JOYSTICK_DINPUT |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
592 |
if ( !SDL_strcasecmp( pchGUID, "xinput" ) ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
593 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
594 |
s_pXInputMapping = pControllerMapping; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
595 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
596 |
#endif |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
597 |
pControllerMapping->guid = SDL_JoystickGetGUIDFromString( pchGUID ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
598 |
pControllerMapping->name = pchName; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
599 |
pControllerMapping->mapping = pchMapping; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
600 |
pControllerMapping->next = s_pSupportedControllers; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
601 |
s_pSupportedControllers = pControllerMapping; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
602 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
603 |
SDL_free( pchGUID ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
604 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
605 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
606 |
i++; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
607 |
pMappingString = s_ControllerMappings[i]; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
608 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
609 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
610 |
// load in any user supplied config |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
611 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
612 |
const char *hint = SDL_GetHint(SDL_HINT_GAMECONTROLLERCONFIG); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
613 |
if ( hint && hint[0] ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
614 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
615 |
int nchHints = SDL_strlen( hint ); |
6823
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
616 |
char *pUserMappings = SDL_malloc( nchHints + 1 ); /* FIXME: memory leak, but we can't free it in this function because pchMapping below points into this memory */ |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
617 |
SDL_memcpy( pUserMappings, hint, nchHints + 1 ); |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
618 |
while ( pUserMappings ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
619 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
620 |
char *pchGUID; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
621 |
char *pchName; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
622 |
const char *pchMapping; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
623 |
char *pchNewLine = NULL; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
624 |
ControllerMapping_t *pControllerMapping; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
625 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
626 |
pchNewLine = SDL_strchr( pUserMappings, '\n' ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
627 |
if ( pchNewLine ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
628 |
*pchNewLine = '\0'; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
629 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
630 |
pControllerMapping = SDL_malloc( sizeof(*pControllerMapping) ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
631 |
if ( !pControllerMapping ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
632 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
633 |
SDL_OutOfMemory(); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
634 |
return -1; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
635 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
636 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
637 |
pchGUID = SDL_PrivateGetControllerGUIDFromMappingString( pUserMappings ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
638 |
pchName = SDL_PrivateGetControllerNameFromMappingString( pUserMappings ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
639 |
pchMapping = SDL_PrivateGetControllerMappingFromMappingString( pUserMappings ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
640 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
641 |
if ( pchGUID && pchName ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
642 |
{ |
6701
91160c9b35da
The XInput code is only available in the DirectInput joystick driver.
Sam Lantinga <slouken@libsdl.org>
parents:
6690
diff
changeset
|
643 |
#ifdef SDL_JOYSTICK_DINPUT |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
644 |
if ( !SDL_strcasecmp( pchGUID, "xinput" ) ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
645 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
646 |
s_pXInputMapping = pControllerMapping; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
647 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
648 |
#endif |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
649 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
650 |
pControllerMapping->guid = SDL_JoystickGetGUIDFromString( pchGUID ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
651 |
pControllerMapping->name = pchName; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
652 |
pControllerMapping->mapping = pchMapping; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
653 |
pControllerMapping->next = s_pSupportedControllers; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
654 |
s_pSupportedControllers = pControllerMapping; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
655 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
656 |
SDL_free( pchGUID ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
657 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
658 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
659 |
if ( pchNewLine ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
660 |
pUserMappings = pchNewLine + 1; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
661 |
else |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
662 |
pUserMappings = NULL; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
663 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
664 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
665 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
666 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
667 |
/* watch for joy events and fire controller ones if needed */ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
668 |
SDL_AddEventWatch( SDL_GameControllerEventWatcher, NULL ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
669 |
return (0); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
670 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
671 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
672 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
673 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
674 |
* Get the implementation dependent name of a controller |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
675 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
676 |
const char * |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
677 |
SDL_GameControllerNameForIndex(int device_index) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
678 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
679 |
ControllerMapping_t *pSupportedController = SDL_PrivateGetControllerMapping(device_index); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
680 |
if ( pSupportedController ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
681 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
682 |
return pSupportedController->name; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
683 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
684 |
else |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
685 |
{ |
6738 | 686 |
SDL_JoystickGUID jGUID = SDL_JoystickGetDeviceGUID( device_index ); |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
687 |
pSupportedController = s_pSupportedControllers; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
688 |
while ( pSupportedController ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
689 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
690 |
if ( !SDL_memcmp( &jGUID, &pSupportedController->guid, sizeof(jGUID) ) ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
691 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
692 |
return pSupportedController->name; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
693 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
694 |
pSupportedController = pSupportedController->next; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
695 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
696 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
697 |
return NULL; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
698 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
699 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
700 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
701 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
702 |
* Return 1 if the joystick at this device index is a supported controller |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
703 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
704 |
int SDL_IsGameController(int device_index) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
705 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
706 |
ControllerMapping_t *pSupportedController = SDL_PrivateGetControllerMapping(device_index); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
707 |
if ( pSupportedController ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
708 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
709 |
return 1; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
710 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
711 |
else |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
712 |
{ |
6738 | 713 |
SDL_JoystickGUID jGUID = SDL_JoystickGetDeviceGUID( device_index ); |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
714 |
pSupportedController = s_pSupportedControllers; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
715 |
// debug code to help get the guid string for a new joystick |
6738 | 716 |
/* char szGUID[33]; |
717 |
SDL_JoystickGetGUIDString( jGUID, szGUID, sizeof(szGUID) ); |
|
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
718 |
printf( "%s\n", pchGUID ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
719 |
SDL_free( pchGUID );*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
720 |
while ( pSupportedController ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
721 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
722 |
if ( !SDL_memcmp( &jGUID, &pSupportedController->guid, sizeof(jGUID) ) ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
723 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
724 |
return 1; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
725 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
726 |
pSupportedController = pSupportedController->next; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
727 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
728 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
729 |
return 0; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
730 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
731 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
732 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
733 |
* Open a controller for use - the index passed as an argument refers to |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
734 |
* the N'th controller on the system. This index is the value which will |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
735 |
* identify this controller in future controller events. |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
736 |
* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
737 |
* This function returns a controller identifier, or NULL if an error occurred. |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
738 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
739 |
SDL_GameController * |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
740 |
SDL_GameControllerOpen(int device_index) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
741 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
742 |
SDL_GameController *gamecontroller; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
743 |
SDL_GameController *gamecontrollerlist; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
744 |
ControllerMapping_t *pSupportedController = NULL; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
745 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
746 |
if ((device_index < 0) || (device_index >= SDL_NumJoysticks())) { |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
747 |
SDL_SetError("There are %d joysticks available", SDL_NumJoysticks()); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
748 |
return (NULL); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
749 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
750 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
751 |
gamecontrollerlist = SDL_gamecontrollers; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
752 |
// If the controller is already open, return it |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
753 |
while ( gamecontrollerlist ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
754 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
755 |
if ( SDL_SYS_GetInstanceIdOfDeviceIndex(device_index) == gamecontrollerlist->joystick->instance_id ) { |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
756 |
gamecontroller = gamecontrollerlist; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
757 |
++gamecontroller->ref_count; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
758 |
return (gamecontroller); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
759 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
760 |
gamecontrollerlist = gamecontrollerlist->next; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
761 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
762 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
763 |
// Create and initialize the joystick |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
764 |
gamecontroller = (SDL_GameController *) SDL_malloc((sizeof *gamecontroller)); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
765 |
if (gamecontroller == NULL) { |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
766 |
SDL_OutOfMemory(); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
767 |
return NULL; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
768 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
769 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
770 |
pSupportedController = SDL_PrivateGetControllerMapping(device_index); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
771 |
if ( !pSupportedController ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
772 |
{ |
6738 | 773 |
SDL_JoystickGUID jGUID; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
774 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
775 |
jGUID = SDL_JoystickGetDeviceGUID( device_index ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
776 |
pSupportedController = s_pSupportedControllers; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
777 |
while ( pSupportedController ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
778 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
779 |
if ( !SDL_memcmp( &jGUID, &pSupportedController->guid, sizeof(jGUID) ) ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
780 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
781 |
break; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
782 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
783 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
784 |
pSupportedController = pSupportedController->next; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
785 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
786 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
787 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
788 |
if ( !pSupportedController ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
789 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
790 |
SDL_SetError("Couldn't find mapping for device (%d)", device_index ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
791 |
return (NULL); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
792 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
793 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
794 |
SDL_memset(gamecontroller, 0, (sizeof *gamecontroller)); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
795 |
gamecontroller->joystick = SDL_JoystickOpen(device_index); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
796 |
if ( !gamecontroller->joystick ) { |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
797 |
SDL_free(gamecontroller); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
798 |
return NULL; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
799 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
800 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
801 |
SDL_PrivateLoadButtonMapping( &gamecontroller->mapping, pSupportedController->guid, pSupportedController->name, pSupportedController->mapping ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
802 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
803 |
// Add joystick to list |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
804 |
++gamecontroller->ref_count; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
805 |
// Link the joystick in the list |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
806 |
gamecontroller->next = SDL_gamecontrollers; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
807 |
SDL_gamecontrollers = gamecontroller; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
808 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
809 |
SDL_SYS_JoystickUpdate( gamecontroller->joystick ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
810 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
811 |
return (gamecontroller); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
812 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
813 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
814 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
815 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
816 |
* Get the current state of an axis control on a controller |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
817 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
818 |
Sint16 |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
819 |
SDL_GameControllerGetAxis(SDL_GameController * gamecontroller, SDL_CONTROLLER_AXIS axis) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
820 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
821 |
if ( !gamecontroller ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
822 |
return 0; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
823 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
824 |
if (gamecontroller->mapping.axes[axis] >= 0 ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
825 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
826 |
return ( SDL_JoystickGetAxis( gamecontroller->joystick, gamecontroller->mapping.axes[axis]) ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
827 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
828 |
else if (gamecontroller->mapping.buttonasaxis[axis] >= 0 ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
829 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
830 |
Uint8 value; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
831 |
value = SDL_JoystickGetButton( gamecontroller->joystick, gamecontroller->mapping.buttonasaxis[axis] ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
832 |
if ( value > 0 ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
833 |
return 32767; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
834 |
return 0; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
835 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
836 |
return 0; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
837 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
838 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
839 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
840 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
841 |
* Get the current state of a button on a controller |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
842 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
843 |
Uint8 |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
844 |
SDL_GameControllerGetButton(SDL_GameController * gamecontroller, SDL_CONTROLLER_BUTTON button) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
845 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
846 |
if ( !gamecontroller ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
847 |
return 0; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
848 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
849 |
if ( gamecontroller->mapping.buttons[button] >= 0 ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
850 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
851 |
return ( SDL_JoystickGetButton( gamecontroller->joystick, gamecontroller->mapping.buttons[button] ) ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
852 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
853 |
else if ( gamecontroller->mapping.axesasbutton[button] >= 0 ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
854 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
855 |
Sint16 value; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
856 |
value = SDL_JoystickGetAxis( gamecontroller->joystick, gamecontroller->mapping.axesasbutton[button] ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
857 |
if ( ABS(value) > 32768/2 ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
858 |
return 1; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
859 |
return 0; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
860 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
861 |
else if ( gamecontroller->mapping.hatasbutton[button].hat >= 0 ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
862 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
863 |
Uint8 value; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
864 |
value = SDL_JoystickGetHat( gamecontroller->joystick, gamecontroller->mapping.hatasbutton[button].hat ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
865 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
866 |
if ( value & gamecontroller->mapping.hatasbutton[button].mask ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
867 |
return 1; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
868 |
return 0; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
869 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
870 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
871 |
return 0; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
872 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
873 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
874 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
875 |
* Return if the joystick in question is currently attached to the system, |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
876 |
* \return 0 if not plugged in, 1 if still present. |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
877 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
878 |
int |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
879 |
SDL_GameControllerGetAttached( SDL_GameController * gamecontroller ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
880 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
881 |
if ( !gamecontroller ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
882 |
return 0; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
883 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
884 |
return SDL_JoystickGetAttached(gamecontroller->joystick); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
885 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
886 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
887 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
888 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
889 |
* Get the number of multi-dimensional axis controls on a joystick |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
890 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
891 |
const char * |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
892 |
SDL_GameControllerName(SDL_GameController * gamecontroller) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
893 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
894 |
if ( !gamecontroller ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
895 |
return NULL; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
896 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
897 |
return (gamecontroller->mapping.name); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
898 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
899 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
900 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
901 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
902 |
* Get the joystick for this controller |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
903 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
904 |
SDL_Joystick *SDL_GameControllerGetJoystick(SDL_GameController * gamecontroller) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
905 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
906 |
if ( !gamecontroller ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
907 |
return NULL; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
908 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
909 |
return gamecontroller->joystick; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
910 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
911 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
912 |
/** |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
913 |
* get the sdl joystick layer binding for this controller axi mapping |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
914 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
915 |
SDL_GameControllerButtonBind SDL_GameControllerGetBindForAxis( SDL_GameController * gamecontroller, SDL_CONTROLLER_AXIS axis ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
916 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
917 |
SDL_GameControllerButtonBind bind; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
918 |
SDL_memset( &bind, 0x0, sizeof(bind) ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
919 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
920 |
if ( !gamecontroller || axis == SDL_CONTROLLER_AXIS_INVALID ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
921 |
return bind; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
922 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
923 |
if (gamecontroller->mapping.axes[axis] >= 0 ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
924 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
925 |
bind.m_eBindType = SDL_CONTROLLER_BINDTYPE_AXIS; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
926 |
bind.button = gamecontroller->mapping.axes[axis]; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
927 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
928 |
else if (gamecontroller->mapping.buttonasaxis[axis] >= 0 ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
929 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
930 |
bind.m_eBindType = SDL_CONTROLLER_BINDTYPE_BUTTON; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
931 |
bind.button = gamecontroller->mapping.buttonasaxis[axis]; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
932 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
933 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
934 |
return bind; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
935 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
936 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
937 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
938 |
/** |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
939 |
* get the sdl joystick layer binding for this controller button mapping |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
940 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
941 |
SDL_GameControllerButtonBind SDL_GameControllerGetBindForButton( SDL_GameController * gamecontroller, SDL_CONTROLLER_BUTTON button ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
942 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
943 |
SDL_GameControllerButtonBind bind; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
944 |
SDL_memset( &bind, 0x0, sizeof(bind) ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
945 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
946 |
if ( !gamecontroller || button == SDL_CONTROLLER_BUTTON_INVALID ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
947 |
return bind; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
948 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
949 |
if ( gamecontroller->mapping.buttons[button] >= 0 ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
950 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
951 |
bind.m_eBindType = SDL_CONTROLLER_BINDTYPE_BUTTON; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
952 |
bind.button = gamecontroller->mapping.buttons[button]; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
953 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
954 |
else if ( gamecontroller->mapping.axesasbutton[button] >= 0 ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
955 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
956 |
bind.m_eBindType = SDL_CONTROLLER_BINDTYPE_AXIS; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
957 |
bind.axis = gamecontroller->mapping.axesasbutton[button]; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
958 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
959 |
else if ( gamecontroller->mapping.hatasbutton[button].hat >= 0 ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
960 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
961 |
bind.m_eBindType = SDL_CONTROLLER_BINDTYPE_HAT; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
962 |
bind.hat.hat = gamecontroller->mapping.hatasbutton[button].hat; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
963 |
bind.hat.hat_mask = gamecontroller->mapping.hatasbutton[button].mask; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
964 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
965 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
966 |
return bind; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
967 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
968 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
969 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
970 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
971 |
* Close a joystick previously opened with SDL_JoystickOpen() |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
972 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
973 |
void |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
974 |
SDL_GameControllerClose(SDL_GameController * gamecontroller) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
975 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
976 |
SDL_GameController *gamecontrollerlist, *gamecontrollerlistprev; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
977 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
978 |
if ( !gamecontroller ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
979 |
return; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
980 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
981 |
// First decrement ref count |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
982 |
if (--gamecontroller->ref_count > 0) { |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
983 |
return; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
984 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
985 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
986 |
SDL_JoystickClose( gamecontroller->joystick ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
987 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
988 |
gamecontrollerlist = SDL_gamecontrollers; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
989 |
gamecontrollerlistprev = NULL; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
990 |
while ( gamecontrollerlist ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
991 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
992 |
if (gamecontroller == gamecontrollerlist) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
993 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
994 |
if ( gamecontrollerlistprev ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
995 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
996 |
// unlink this entry |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
997 |
gamecontrollerlistprev->next = gamecontrollerlist->next; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
998 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
999 |
else |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1000 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1001 |
SDL_gamecontrollers = gamecontroller->next; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1002 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1003 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1004 |
break; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1005 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1006 |
gamecontrollerlistprev = gamecontrollerlist; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1007 |
gamecontrollerlist = gamecontrollerlist->next; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1008 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1009 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1010 |
SDL_free(gamecontroller); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1011 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1012 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1013 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1014 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1015 |
* Quit the controller subsystem |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1016 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1017 |
void |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1018 |
SDL_GameControllerQuit(void) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1019 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1020 |
ControllerMapping_t *pControllerMap; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1021 |
while ( SDL_gamecontrollers ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1022 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1023 |
SDL_gamecontrollers->ref_count = 1; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1024 |
SDL_GameControllerClose(SDL_gamecontrollers); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1025 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1026 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1027 |
pControllerMap = s_pSupportedControllers; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1028 |
while ( s_pSupportedControllers ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1029 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1030 |
pControllerMap = s_pSupportedControllers; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1031 |
s_pSupportedControllers = s_pSupportedControllers->next; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1032 |
SDL_free( pControllerMap->name ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1033 |
SDL_free( pControllerMap ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1034 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1035 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1036 |
SDL_DelEventWatch( SDL_GameControllerEventWatcher, NULL ); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1037 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1038 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1039 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1040 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1041 |
* Event filter to transform joystick events into appropriate game controller ones |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1042 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1043 |
int |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1044 |
SDL_PrivateGameControllerAxis(SDL_GameController * gamecontroller, SDL_CONTROLLER_AXIS axis, Sint16 value) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1045 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1046 |
int posted; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1047 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1048 |
/* translate the event, if desired */ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1049 |
posted = 0; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1050 |
#if !SDL_EVENTS_DISABLED |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1051 |
if (SDL_GetEventState(SDL_CONTROLLERAXISMOTION) == SDL_ENABLE) { |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1052 |
SDL_Event event; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1053 |
event.type = SDL_CONTROLLERAXISMOTION; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1054 |
event.caxis.which = gamecontroller->joystick->instance_id; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1055 |
event.caxis.axis = axis; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1056 |
event.caxis.value = value; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1057 |
posted = SDL_PushEvent(&event) == 1; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1058 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1059 |
#endif /* !SDL_EVENTS_DISABLED */ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1060 |
return (posted); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1061 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1062 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1063 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1064 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1065 |
* Event filter to transform joystick events into appropriate game controller ones |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1066 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1067 |
int |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1068 |
SDL_PrivateGameControllerButton(SDL_GameController * gamecontroller, SDL_CONTROLLER_BUTTON button, Uint8 state) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1069 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1070 |
int posted; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1071 |
#if !SDL_EVENTS_DISABLED |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1072 |
SDL_Event event; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1073 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1074 |
switch (state) { |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1075 |
case SDL_PRESSED: |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1076 |
event.type = SDL_CONTROLLERBUTTONDOWN; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1077 |
break; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1078 |
case SDL_RELEASED: |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1079 |
event.type = SDL_CONTROLLERBUTTONUP; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1080 |
break; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1081 |
default: |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1082 |
/* Invalid state -- bail */ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1083 |
return (0); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1084 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1085 |
#endif /* !SDL_EVENTS_DISABLED */ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1086 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1087 |
/* translate the event, if desired */ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1088 |
posted = 0; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1089 |
#if !SDL_EVENTS_DISABLED |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1090 |
if (SDL_GetEventState(event.type) == SDL_ENABLE) { |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1091 |
event.cbutton.which = gamecontroller->joystick->instance_id; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1092 |
event.cbutton.button = button; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1093 |
event.cbutton.state = state; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1094 |
posted = SDL_PushEvent(&event) == 1; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1095 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1096 |
#endif /* !SDL_EVENTS_DISABLED */ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1097 |
return (posted); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1098 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1099 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1100 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1101 |
* Turn off controller events |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1102 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1103 |
int |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1104 |
SDL_GameControllerEventState(int state) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1105 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1106 |
#if SDL_EVENTS_DISABLED |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1107 |
return SDL_IGNORE; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|