Mercurial > sdl-ios-xcode
annotate src/joystick/macos/SDL_sysjoystick.c @ 1716:6ab5e712e642 SDL-1.3
The screen/shadow surface flags are no longer needed
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 26 Jun 2006 20:32:54 +0000 |
parents | 4da1ee79c9af |
children |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 9 |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
22 #include "SDL_config.h" |
0 | 23 |
1635
92947e3a18db
Make sure code is only compiled if the appropriate subsystem is enabled
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
24 #ifdef SDL_JOYSTICK_MACOS |
92947e3a18db
Make sure code is only compiled if the appropriate subsystem is enabled
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
25 |
0 | 26 /* SDL stuff -- "SDL_sysjoystick.c" |
27 MacOS joystick functions by Frederick Reitberger | |
28 | |
29 The code that follows is meant for SDL. Use at your own risk. | |
30 */ | |
31 | |
32 #include <InputSprocket.h> | |
33 | |
34 #include "SDL_joystick.h" | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
35 #include "../SDL_sysjoystick.h" |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
36 #include "../SDL_joystick_c.h" |
0 | 37 |
38 | |
39 /* The max number of joysticks we will detect */ | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
40 #define MAX_JOYSTICKS 16 |
0 | 41 /* Limit ourselves to 32 elements per device */ |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
42 #define kMaxReferences 32 |
0 | 43 |
44 #define ISpSymmetricAxisToFloat(axis) ((((float) axis) - kISpAxisMiddle) / (kISpAxisMaximum-kISpAxisMiddle)) | |
45 #define ISpAsymmetricAxisToFloat(axis) (((float) axis) / (kISpAxisMaximum)) | |
46 | |
47 | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
48 static ISpDeviceReference SYS_Joysticks[MAX_JOYSTICKS]; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
49 static ISpElementListReference SYS_Elements[MAX_JOYSTICKS]; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
50 static ISpDeviceDefinition SYS_DevDef[MAX_JOYSTICKS]; |
0 | 51 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
52 struct joystick_hwdata |
0 | 53 { |
54 char name[64]; | |
55 /* Uint8 id;*/ | |
56 ISpElementReference refs[kMaxReferences]; | |
57 /* gonna need some sort of mapping info */ | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
58 }; |
0 | 59 |
60 | |
61 /* Function to scan the system for joysticks. | |
62 * Joystick 0 should be the system default joystick. | |
63 * This function should return the number of available joysticks, or -1 | |
64 * on an unrecoverable fatal error. | |
65 */ | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
66 int |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
67 SDL_SYS_JoystickInit(void) |
0 | 68 { |
69 static ISpDeviceClass classes[4] = { | |
70 kISpDeviceClass_Joystick, | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
71 #if kISpDeviceClass_Gamepad |
0 | 72 kISpDeviceClass_Gamepad, |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
73 #endif |
0 | 74 kISpDeviceClass_Wheel, |
75 0 | |
76 }; | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
77 OSErr err; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
78 int i; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
79 UInt32 count, numJoysticks; |
0 | 80 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
81 if ((Ptr) 0 == (Ptr) ISpStartup) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
82 SDL_SetError("InputSprocket not installed"); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
83 return -1; // InputSprocket not installed |
0 | 84 } |
85 | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
86 if ((Ptr) 0 == (Ptr) ISpGetVersion) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
87 SDL_SetError("InputSprocket not version 1.1 or newer"); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
88 return -1; // old version of ISp (not at least 1.1) |
0 | 89 } |
90 | |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
91 ISpStartup(); |
0 | 92 |
93 /* Get all the joysticks */ | |
94 numJoysticks = 0; | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
95 for (i = 0; classes[i]; ++i) { |
0 | 96 count = 0; |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
97 err = ISpDevices_ExtractByClass(classes[i], |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
98 MAX_JOYSTICKS - numJoysticks, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
99 &count, &SYS_Joysticks[numJoysticks]); |
0 | 100 numJoysticks += count; |
101 } | |
102 | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
103 for (i = 0; i < numJoysticks; i++) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
104 ISpDevice_GetDefinition(SYS_Joysticks[i], |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
105 sizeof(ISpDeviceDefinition), &SYS_DevDef[i]); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
106 |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
107 err = ISpElementList_New(0, NULL, &SYS_Elements[i], 0); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
108 |
0 | 109 if (err) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
110 SDL_OutOfMemory(); |
0 | 111 return -1; |
112 } | |
113 | |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
114 ISpDevice_GetElementList(SYS_Joysticks[i], &SYS_Elements[i]); |
0 | 115 } |
116 | |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
117 ISpDevices_Deactivate(numJoysticks, SYS_Joysticks); |
0 | 118 |
119 return numJoysticks; | |
120 } | |
121 | |
122 /* Function to get the device-dependent name of a joystick */ | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
123 const char * |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
124 SDL_SYS_JoystickName(int index) |
0 | 125 { |
126 static char name[64]; | |
127 int len; | |
128 | |
129 /* convert pascal string to c-string */ | |
130 len = SYS_DevDef[index].deviceName[0]; | |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
131 if (len >= sizeof(name)) { |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
132 len = (sizeof(name) - 1); |
0 | 133 } |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
134 SDL_memcpy(name, &SYS_DevDef[index].deviceName[1], len); |
0 | 135 name[len] = '\0'; |
136 | |
137 return name; | |
138 } | |
139 | |
140 /* Function to open a joystick for use. | |
141 The joystick to open is specified by the index field of the joystick. | |
142 This should fill the nbuttons and naxes fields of the joystick structure. | |
143 It returns 0, or -1 if there is an error. | |
144 */ | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
145 int |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
146 SDL_SYS_JoystickOpen(SDL_Joystick * joystick) |
0 | 147 { |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
148 int index; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
149 UInt32 count, gotCount, count2; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
150 long numAxis, numButtons, numHats, numBalls; |
0 | 151 |
152 count = kMaxReferences; | |
153 count2 = 0; | |
154 numAxis = numButtons = numHats = numBalls = 0; | |
155 | |
156 index = joystick->index; | |
157 | |
158 /* allocate memory for system specific hardware data */ | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
159 joystick->hwdata = |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
160 (struct joystick_hwdata *) SDL_malloc(sizeof(*joystick->hwdata)); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
161 if (joystick->hwdata == NULL) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
162 SDL_OutOfMemory(); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
163 return (-1); |
0 | 164 } |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
165 SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata)); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
166 SDL_strlcpy(joystick->hwdata->name, SDL_SYS_JoystickName(index), |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
167 SDL_arraysize(joystick->hwdata->name)); |
0 | 168 joystick->name = joystick->hwdata->name; |
169 | |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
170 ISpElementList_ExtractByKind(SYS_Elements[index], |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
171 kISpElementKind_Axis, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
172 count, &gotCount, joystick->hwdata->refs); |
0 | 173 |
174 numAxis = gotCount; | |
175 count -= gotCount; | |
176 count2 += gotCount; | |
177 | |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
178 ISpElementList_ExtractByKind(SYS_Elements[index], |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
179 kISpElementKind_DPad, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
180 count, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
181 &gotCount, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
182 &(joystick->hwdata->refs[count2])); |
0 | 183 |
184 numHats = gotCount; | |
185 count -= gotCount; | |
186 count2 += gotCount; | |
187 | |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
188 ISpElementList_ExtractByKind(SYS_Elements[index], |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
189 kISpElementKind_Button, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
190 count, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
191 &gotCount, |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
192 &(joystick->hwdata->refs[count2])); |
0 | 193 |
194 numButtons = gotCount; | |
195 count -= gotCount; | |
196 count2 += gotCount; | |
197 | |
198 joystick->naxes = numAxis; | |
199 joystick->nhats = numHats; | |
200 joystick->nballs = numBalls; | |
201 joystick->nbuttons = numButtons; | |
202 | |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
203 ISpDevices_Activate(1, &SYS_Joysticks[index]); |
0 | 204 |
205 return 0; | |
206 } | |
207 | |
208 /* Function to update the state of a joystick - called as a device poll. | |
209 * This function shouldn't update the joystick structure directly, | |
210 * but instead should call SDL_PrivateJoystick*() to deliver events | |
211 * and update joystick device state. | |
212 */ | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
213 void |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
214 SDL_SYS_JoystickUpdate(SDL_Joystick * joystick) |
0 | 215 { |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
216 int i, j; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
217 ISpAxisData a; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
218 ISpDPadData b; |
0 | 219 //ISpDeltaData c; |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
220 ISpButtonData d; |
0 | 221 |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
222 for (i = 0, j = 0; i < joystick->naxes; i++, j++) { |
0 | 223 Sint16 value; |
224 | |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
225 ISpElement_GetSimpleState(joystick->hwdata->refs[j], &a); |
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
226 value = (ISpSymmetricAxisToFloat(a) * 32767.0); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
227 if (value != joystick->axes[i]) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
228 SDL_PrivateJoystickAxis(joystick, i, value); |
0 | 229 } |
230 } | |
231 | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
232 for (i = 0; i < joystick->nhats; i++, j++) { |
0 | 233 Uint8 pos; |
234 | |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
235 ISpElement_GetSimpleState(joystick->hwdata->refs[j], &b); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
236 switch (b) { |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
237 case kISpPadIdle: |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
238 pos = SDL_HAT_CENTERED; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
239 break; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
240 case kISpPadLeft: |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
241 pos = SDL_HAT_LEFT; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
242 break; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
243 case kISpPadUpLeft: |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
244 pos = SDL_HAT_LEFTUP; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
245 break; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
246 case kISpPadUp: |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
247 pos = SDL_HAT_UP; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
248 break; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
249 case kISpPadUpRight: |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
250 pos = SDL_HAT_RIGHTUP; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
251 break; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
252 case kISpPadRight: |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
253 pos = SDL_HAT_RIGHT; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
254 break; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
255 case kISpPadDownRight: |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
256 pos = SDL_HAT_RIGHTDOWN; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
257 break; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
258 case kISpPadDown: |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
259 pos = SDL_HAT_DOWN; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
260 break; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
261 case kISpPadDownLeft: |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
262 pos = SDL_HAT_LEFTDOWN; |
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
263 break; |
0 | 264 } |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
265 if (pos != joystick->hats[i]) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
266 SDL_PrivateJoystickHat(joystick, i, pos); |
0 | 267 } |
268 } | |
269 | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
270 for (i = 0; i < joystick->nballs; i++, j++) { |
0 | 271 /* ignore balls right now */ |
272 } | |
273 | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
274 for (i = 0; i < joystick->nbuttons; i++, j++) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
275 ISpElement_GetSimpleState(joystick->hwdata->refs[j], &d); |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
276 if (d != joystick->buttons[i]) { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
277 SDL_PrivateJoystickButton(joystick, i, d); |
0 | 278 } |
279 } | |
280 } | |
281 | |
282 /* Function to close a joystick after use */ | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
283 void |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
284 SDL_SYS_JoystickClose(SDL_Joystick * joystick) |
0 | 285 { |
286 int index; | |
287 | |
288 index = joystick->index; | |
289 | |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
290 ISpDevices_Deactivate(1, &SYS_Joysticks[index]); |
0 | 291 } |
292 | |
293 /* Function to perform any system-specific joystick related cleanup */ | |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
294 void |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
295 SDL_SYS_JoystickQuit(void) |
0 | 296 { |
1668
4da1ee79c9af
more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents:
1662
diff
changeset
|
297 ISpShutdown(); |
0 | 298 } |
299 | |
1635
92947e3a18db
Make sure code is only compiled if the appropriate subsystem is enabled
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
300 #endif /* SDL_JOYSTICK_MACOS */ |
1662
782fd950bd46
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
301 /* vi: set ts=4 sw=4 expandtab: */ |