Mercurial > sdl-ios-xcode
comparison src/joystick/SDL_joystick.c @ 1668:4da1ee79c9af SDL-1.3
more tweaking indent options
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 29 May 2006 04:04:35 +0000 |
parents | 782fd950bd46 |
children | 5daa04d862f1 |
comparison
equal
deleted
inserted
replaced
1667:1fddae038bc8 | 1668:4da1ee79c9af |
---|---|
39 Uint8 SDL_numjoysticks = 0; | 39 Uint8 SDL_numjoysticks = 0; |
40 SDL_Joystick **SDL_joysticks = NULL; | 40 SDL_Joystick **SDL_joysticks = NULL; |
41 static SDL_Joystick *default_joystick = NULL; | 41 static SDL_Joystick *default_joystick = NULL; |
42 | 42 |
43 int | 43 int |
44 SDL_JoystickInit (void) | 44 SDL_JoystickInit(void) |
45 { | 45 { |
46 int arraylen; | 46 int arraylen; |
47 int status; | 47 int status; |
48 | 48 |
49 SDL_numjoysticks = 0; | 49 SDL_numjoysticks = 0; |
50 status = SDL_SYS_JoystickInit (); | 50 status = SDL_SYS_JoystickInit(); |
51 if (status >= 0) { | 51 if (status >= 0) { |
52 arraylen = (status + 1) * sizeof (*SDL_joysticks); | 52 arraylen = (status + 1) * sizeof(*SDL_joysticks); |
53 SDL_joysticks = (SDL_Joystick **) SDL_malloc (arraylen); | 53 SDL_joysticks = (SDL_Joystick **) SDL_malloc(arraylen); |
54 if (SDL_joysticks == NULL) { | 54 if (SDL_joysticks == NULL) { |
55 SDL_numjoysticks = 0; | 55 SDL_numjoysticks = 0; |
56 } else { | 56 } else { |
57 SDL_memset (SDL_joysticks, 0, arraylen); | 57 SDL_memset(SDL_joysticks, 0, arraylen); |
58 SDL_numjoysticks = status; | 58 SDL_numjoysticks = status; |
59 } | 59 } |
60 status = 0; | 60 status = 0; |
61 } | 61 } |
62 default_joystick = NULL; | 62 default_joystick = NULL; |
65 | 65 |
66 /* | 66 /* |
67 * Count the number of joysticks attached to the system | 67 * Count the number of joysticks attached to the system |
68 */ | 68 */ |
69 int | 69 int |
70 SDL_NumJoysticks (void) | 70 SDL_NumJoysticks(void) |
71 { | 71 { |
72 return SDL_numjoysticks; | 72 return SDL_numjoysticks; |
73 } | 73 } |
74 | 74 |
75 /* | 75 /* |
76 * Get the implementation dependent name of a joystick | 76 * Get the implementation dependent name of a joystick |
77 */ | 77 */ |
78 const char * | 78 const char * |
79 SDL_JoystickName (int device_index) | 79 SDL_JoystickName(int device_index) |
80 { | 80 { |
81 if ((device_index < 0) || (device_index >= SDL_numjoysticks)) { | 81 if ((device_index < 0) || (device_index >= SDL_numjoysticks)) { |
82 SDL_SetError ("There are %d joysticks available", SDL_numjoysticks); | 82 SDL_SetError("There are %d joysticks available", SDL_numjoysticks); |
83 return (NULL); | 83 return (NULL); |
84 } | 84 } |
85 return (SDL_SYS_JoystickName (device_index)); | 85 return (SDL_SYS_JoystickName(device_index)); |
86 } | 86 } |
87 | 87 |
88 /* | 88 /* |
89 * Open a joystick for use - the index passed as an argument refers to | 89 * Open a joystick for use - the index passed as an argument refers to |
90 * the N'th joystick on the system. This index is the value which will | 90 * the N'th joystick on the system. This index is the value which will |
91 * identify this joystick in future joystick events. | 91 * identify this joystick in future joystick events. |
92 * | 92 * |
93 * This function returns a joystick identifier, or NULL if an error occurred. | 93 * This function returns a joystick identifier, or NULL if an error occurred. |
94 */ | 94 */ |
95 SDL_Joystick * | 95 SDL_Joystick * |
96 SDL_JoystickOpen (int device_index) | 96 SDL_JoystickOpen(int device_index) |
97 { | 97 { |
98 int i; | 98 int i; |
99 SDL_Joystick *joystick; | 99 SDL_Joystick *joystick; |
100 | 100 |
101 if ((device_index < 0) || (device_index >= SDL_numjoysticks)) { | 101 if ((device_index < 0) || (device_index >= SDL_numjoysticks)) { |
102 SDL_SetError ("There are %d joysticks available", SDL_numjoysticks); | 102 SDL_SetError("There are %d joysticks available", SDL_numjoysticks); |
103 return (NULL); | 103 return (NULL); |
104 } | 104 } |
105 | 105 |
106 /* If the joystick is already open, return it */ | 106 /* If the joystick is already open, return it */ |
107 for (i = 0; SDL_joysticks[i]; ++i) { | 107 for (i = 0; SDL_joysticks[i]; ++i) { |
111 return (joystick); | 111 return (joystick); |
112 } | 112 } |
113 } | 113 } |
114 | 114 |
115 /* Create and initialize the joystick */ | 115 /* Create and initialize the joystick */ |
116 joystick = (SDL_Joystick *) SDL_malloc ((sizeof *joystick)); | 116 joystick = (SDL_Joystick *) SDL_malloc((sizeof *joystick)); |
117 if (joystick != NULL) { | 117 if (joystick != NULL) { |
118 SDL_memset (joystick, 0, (sizeof *joystick)); | 118 SDL_memset(joystick, 0, (sizeof *joystick)); |
119 joystick->index = device_index; | 119 joystick->index = device_index; |
120 if (SDL_SYS_JoystickOpen (joystick) < 0) { | 120 if (SDL_SYS_JoystickOpen(joystick) < 0) { |
121 SDL_free (joystick); | 121 SDL_free(joystick); |
122 joystick = NULL; | 122 joystick = NULL; |
123 } else { | 123 } else { |
124 if (joystick->naxes > 0) { | 124 if (joystick->naxes > 0) { |
125 joystick->axes = (Sint16 *) SDL_malloc | 125 joystick->axes = (Sint16 *) SDL_malloc |
126 (joystick->naxes * sizeof (Sint16)); | 126 (joystick->naxes * sizeof(Sint16)); |
127 } | 127 } |
128 if (joystick->nhats > 0) { | 128 if (joystick->nhats > 0) { |
129 joystick->hats = (Uint8 *) SDL_malloc | 129 joystick->hats = (Uint8 *) SDL_malloc |
130 (joystick->nhats * sizeof (Uint8)); | 130 (joystick->nhats * sizeof(Uint8)); |
131 } | 131 } |
132 if (joystick->nballs > 0) { | 132 if (joystick->nballs > 0) { |
133 joystick->balls = (struct balldelta *) SDL_malloc | 133 joystick->balls = (struct balldelta *) SDL_malloc |
134 (joystick->nballs * sizeof (*joystick->balls)); | 134 (joystick->nballs * sizeof(*joystick->balls)); |
135 } | 135 } |
136 if (joystick->nbuttons > 0) { | 136 if (joystick->nbuttons > 0) { |
137 joystick->buttons = (Uint8 *) SDL_malloc | 137 joystick->buttons = (Uint8 *) SDL_malloc |
138 (joystick->nbuttons * sizeof (Uint8)); | 138 (joystick->nbuttons * sizeof(Uint8)); |
139 } | 139 } |
140 if (((joystick->naxes > 0) && !joystick->axes) | 140 if (((joystick->naxes > 0) && !joystick->axes) |
141 || ((joystick->nhats > 0) && !joystick->hats) | 141 || ((joystick->nhats > 0) && !joystick->hats) |
142 || ((joystick->nballs > 0) && !joystick->balls) | 142 || ((joystick->nballs > 0) && !joystick->balls) |
143 || ((joystick->nbuttons > 0) && !joystick->buttons)) { | 143 || ((joystick->nbuttons > 0) && !joystick->buttons)) { |
144 SDL_OutOfMemory (); | 144 SDL_OutOfMemory(); |
145 SDL_JoystickClose (joystick); | 145 SDL_JoystickClose(joystick); |
146 joystick = NULL; | 146 joystick = NULL; |
147 } | 147 } |
148 if (joystick->axes) { | 148 if (joystick->axes) { |
149 SDL_memset (joystick->axes, 0, | 149 SDL_memset(joystick->axes, 0, |
150 joystick->naxes * sizeof (Sint16)); | 150 joystick->naxes * sizeof(Sint16)); |
151 } | 151 } |
152 if (joystick->hats) { | 152 if (joystick->hats) { |
153 SDL_memset (joystick->hats, 0, | 153 SDL_memset(joystick->hats, 0, |
154 joystick->nhats * sizeof (Uint8)); | 154 joystick->nhats * sizeof(Uint8)); |
155 } | 155 } |
156 if (joystick->balls) { | 156 if (joystick->balls) { |
157 SDL_memset (joystick->balls, 0, | 157 SDL_memset(joystick->balls, 0, |
158 joystick->nballs * sizeof (*joystick->balls)); | 158 joystick->nballs * sizeof(*joystick->balls)); |
159 } | 159 } |
160 if (joystick->buttons) { | 160 if (joystick->buttons) { |
161 SDL_memset (joystick->buttons, 0, | 161 SDL_memset(joystick->buttons, 0, |
162 joystick->nbuttons * sizeof (Uint8)); | 162 joystick->nbuttons * sizeof(Uint8)); |
163 } | 163 } |
164 } | 164 } |
165 } | 165 } |
166 if (joystick) { | 166 if (joystick) { |
167 /* Add joystick to list */ | 167 /* Add joystick to list */ |
168 ++joystick->ref_count; | 168 ++joystick->ref_count; |
169 SDL_Lock_EventThread (); | 169 SDL_Lock_EventThread(); |
170 for (i = 0; SDL_joysticks[i]; ++i) | 170 for (i = 0; SDL_joysticks[i]; ++i) |
171 /* Skip to next joystick */ ; | 171 /* Skip to next joystick */ ; |
172 SDL_joysticks[i] = joystick; | 172 SDL_joysticks[i] = joystick; |
173 SDL_Unlock_EventThread (); | 173 SDL_Unlock_EventThread(); |
174 } | 174 } |
175 return (joystick); | 175 return (joystick); |
176 } | 176 } |
177 | 177 |
178 /* | 178 /* |
179 * Returns 1 if the joystick has been opened, or 0 if it has not. | 179 * Returns 1 if the joystick has been opened, or 0 if it has not. |
180 */ | 180 */ |
181 int | 181 int |
182 SDL_JoystickOpened (int device_index) | 182 SDL_JoystickOpened(int device_index) |
183 { | 183 { |
184 int i, opened; | 184 int i, opened; |
185 | 185 |
186 opened = 0; | 186 opened = 0; |
187 for (i = 0; SDL_joysticks[i]; ++i) { | 187 for (i = 0; SDL_joysticks[i]; ++i) { |
192 } | 192 } |
193 return (opened); | 193 return (opened); |
194 } | 194 } |
195 | 195 |
196 static int | 196 static int |
197 ValidJoystick (SDL_Joystick ** joystick) | 197 ValidJoystick(SDL_Joystick ** joystick) |
198 { | 198 { |
199 int valid; | 199 int valid; |
200 | 200 |
201 if (*joystick == NULL) { | 201 if (*joystick == NULL) { |
202 *joystick = default_joystick; | 202 *joystick = default_joystick; |
203 } | 203 } |
204 if (*joystick == NULL) { | 204 if (*joystick == NULL) { |
205 SDL_SetError ("Joystick hasn't been opened yet"); | 205 SDL_SetError("Joystick hasn't been opened yet"); |
206 valid = 0; | 206 valid = 0; |
207 } else { | 207 } else { |
208 valid = 1; | 208 valid = 1; |
209 } | 209 } |
210 return valid; | 210 return valid; |
212 | 212 |
213 /* | 213 /* |
214 * Get the device index of an opened joystick. | 214 * Get the device index of an opened joystick. |
215 */ | 215 */ |
216 int | 216 int |
217 SDL_JoystickIndex (SDL_Joystick * joystick) | 217 SDL_JoystickIndex(SDL_Joystick * joystick) |
218 { | 218 { |
219 if (!ValidJoystick (&joystick)) { | 219 if (!ValidJoystick(&joystick)) { |
220 return (-1); | 220 return (-1); |
221 } | 221 } |
222 return (joystick->index); | 222 return (joystick->index); |
223 } | 223 } |
224 | 224 |
225 /* | 225 /* |
226 * Get the number of multi-dimensional axis controls on a joystick | 226 * Get the number of multi-dimensional axis controls on a joystick |
227 */ | 227 */ |
228 int | 228 int |
229 SDL_JoystickNumAxes (SDL_Joystick * joystick) | 229 SDL_JoystickNumAxes(SDL_Joystick * joystick) |
230 { | 230 { |
231 if (!ValidJoystick (&joystick)) { | 231 if (!ValidJoystick(&joystick)) { |
232 return (-1); | 232 return (-1); |
233 } | 233 } |
234 return (joystick->naxes); | 234 return (joystick->naxes); |
235 } | 235 } |
236 | 236 |
237 /* | 237 /* |
238 * Get the number of hats on a joystick | 238 * Get the number of hats on a joystick |
239 */ | 239 */ |
240 int | 240 int |
241 SDL_JoystickNumHats (SDL_Joystick * joystick) | 241 SDL_JoystickNumHats(SDL_Joystick * joystick) |
242 { | 242 { |
243 if (!ValidJoystick (&joystick)) { | 243 if (!ValidJoystick(&joystick)) { |
244 return (-1); | 244 return (-1); |
245 } | 245 } |
246 return (joystick->nhats); | 246 return (joystick->nhats); |
247 } | 247 } |
248 | 248 |
249 /* | 249 /* |
250 * Get the number of trackballs on a joystick | 250 * Get the number of trackballs on a joystick |
251 */ | 251 */ |
252 int | 252 int |
253 SDL_JoystickNumBalls (SDL_Joystick * joystick) | 253 SDL_JoystickNumBalls(SDL_Joystick * joystick) |
254 { | 254 { |
255 if (!ValidJoystick (&joystick)) { | 255 if (!ValidJoystick(&joystick)) { |
256 return (-1); | 256 return (-1); |
257 } | 257 } |
258 return (joystick->nballs); | 258 return (joystick->nballs); |
259 } | 259 } |
260 | 260 |
261 /* | 261 /* |
262 * Get the number of buttons on a joystick | 262 * Get the number of buttons on a joystick |
263 */ | 263 */ |
264 int | 264 int |
265 SDL_JoystickNumButtons (SDL_Joystick * joystick) | 265 SDL_JoystickNumButtons(SDL_Joystick * joystick) |
266 { | 266 { |
267 if (!ValidJoystick (&joystick)) { | 267 if (!ValidJoystick(&joystick)) { |
268 return (-1); | 268 return (-1); |
269 } | 269 } |
270 return (joystick->nbuttons); | 270 return (joystick->nbuttons); |
271 } | 271 } |
272 | 272 |
273 /* | 273 /* |
274 * Get the current state of an axis control on a joystick | 274 * Get the current state of an axis control on a joystick |
275 */ | 275 */ |
276 Sint16 | 276 Sint16 |
277 SDL_JoystickGetAxis (SDL_Joystick * joystick, int axis) | 277 SDL_JoystickGetAxis(SDL_Joystick * joystick, int axis) |
278 { | 278 { |
279 Sint16 state; | 279 Sint16 state; |
280 | 280 |
281 if (!ValidJoystick (&joystick)) { | 281 if (!ValidJoystick(&joystick)) { |
282 return (0); | 282 return (0); |
283 } | 283 } |
284 if (axis < joystick->naxes) { | 284 if (axis < joystick->naxes) { |
285 state = joystick->axes[axis]; | 285 state = joystick->axes[axis]; |
286 } else { | 286 } else { |
287 SDL_SetError ("Joystick only has %d axes", joystick->naxes); | 287 SDL_SetError("Joystick only has %d axes", joystick->naxes); |
288 state = 0; | 288 state = 0; |
289 } | 289 } |
290 return (state); | 290 return (state); |
291 } | 291 } |
292 | 292 |
293 /* | 293 /* |
294 * Get the current state of a hat on a joystick | 294 * Get the current state of a hat on a joystick |
295 */ | 295 */ |
296 Uint8 | 296 Uint8 |
297 SDL_JoystickGetHat (SDL_Joystick * joystick, int hat) | 297 SDL_JoystickGetHat(SDL_Joystick * joystick, int hat) |
298 { | 298 { |
299 Uint8 state; | 299 Uint8 state; |
300 | 300 |
301 if (!ValidJoystick (&joystick)) { | 301 if (!ValidJoystick(&joystick)) { |
302 return (0); | 302 return (0); |
303 } | 303 } |
304 if (hat < joystick->nhats) { | 304 if (hat < joystick->nhats) { |
305 state = joystick->hats[hat]; | 305 state = joystick->hats[hat]; |
306 } else { | 306 } else { |
307 SDL_SetError ("Joystick only has %d hats", joystick->nhats); | 307 SDL_SetError("Joystick only has %d hats", joystick->nhats); |
308 state = 0; | 308 state = 0; |
309 } | 309 } |
310 return (state); | 310 return (state); |
311 } | 311 } |
312 | 312 |
313 /* | 313 /* |
314 * Get the ball axis change since the last poll | 314 * Get the ball axis change since the last poll |
315 */ | 315 */ |
316 int | 316 int |
317 SDL_JoystickGetBall (SDL_Joystick * joystick, int ball, int *dx, int *dy) | 317 SDL_JoystickGetBall(SDL_Joystick * joystick, int ball, int *dx, int *dy) |
318 { | 318 { |
319 int retval; | 319 int retval; |
320 | 320 |
321 if (!ValidJoystick (&joystick)) { | 321 if (!ValidJoystick(&joystick)) { |
322 return (-1); | 322 return (-1); |
323 } | 323 } |
324 | 324 |
325 retval = 0; | 325 retval = 0; |
326 if (ball < joystick->nballs) { | 326 if (ball < joystick->nballs) { |
331 *dy = joystick->balls[ball].dy; | 331 *dy = joystick->balls[ball].dy; |
332 } | 332 } |
333 joystick->balls[ball].dx = 0; | 333 joystick->balls[ball].dx = 0; |
334 joystick->balls[ball].dy = 0; | 334 joystick->balls[ball].dy = 0; |
335 } else { | 335 } else { |
336 SDL_SetError ("Joystick only has %d balls", joystick->nballs); | 336 SDL_SetError("Joystick only has %d balls", joystick->nballs); |
337 retval = -1; | 337 retval = -1; |
338 } | 338 } |
339 return (retval); | 339 return (retval); |
340 } | 340 } |
341 | 341 |
342 /* | 342 /* |
343 * Get the current state of a button on a joystick | 343 * Get the current state of a button on a joystick |
344 */ | 344 */ |
345 Uint8 | 345 Uint8 |
346 SDL_JoystickGetButton (SDL_Joystick * joystick, int button) | 346 SDL_JoystickGetButton(SDL_Joystick * joystick, int button) |
347 { | 347 { |
348 Uint8 state; | 348 Uint8 state; |
349 | 349 |
350 if (!ValidJoystick (&joystick)) { | 350 if (!ValidJoystick(&joystick)) { |
351 return (0); | 351 return (0); |
352 } | 352 } |
353 if (button < joystick->nbuttons) { | 353 if (button < joystick->nbuttons) { |
354 state = joystick->buttons[button]; | 354 state = joystick->buttons[button]; |
355 } else { | 355 } else { |
356 SDL_SetError ("Joystick only has %d buttons", joystick->nbuttons); | 356 SDL_SetError("Joystick only has %d buttons", joystick->nbuttons); |
357 state = 0; | 357 state = 0; |
358 } | 358 } |
359 return (state); | 359 return (state); |
360 } | 360 } |
361 | 361 |
362 /* | 362 /* |
363 * Close a joystick previously opened with SDL_JoystickOpen() | 363 * Close a joystick previously opened with SDL_JoystickOpen() |
364 */ | 364 */ |
365 void | 365 void |
366 SDL_JoystickClose (SDL_Joystick * joystick) | 366 SDL_JoystickClose(SDL_Joystick * joystick) |
367 { | 367 { |
368 int i; | 368 int i; |
369 | 369 |
370 if (!ValidJoystick (&joystick)) { | 370 if (!ValidJoystick(&joystick)) { |
371 return; | 371 return; |
372 } | 372 } |
373 | 373 |
374 /* First decrement ref count */ | 374 /* First decrement ref count */ |
375 if (--joystick->ref_count > 0) { | 375 if (--joystick->ref_count > 0) { |
376 return; | 376 return; |
377 } | 377 } |
378 | 378 |
379 /* Lock the event queue - prevent joystick polling */ | 379 /* Lock the event queue - prevent joystick polling */ |
380 SDL_Lock_EventThread (); | 380 SDL_Lock_EventThread(); |
381 | 381 |
382 if (joystick == default_joystick) { | 382 if (joystick == default_joystick) { |
383 default_joystick = NULL; | 383 default_joystick = NULL; |
384 } | 384 } |
385 SDL_SYS_JoystickClose (joystick); | 385 SDL_SYS_JoystickClose(joystick); |
386 | 386 |
387 /* Remove joystick from list */ | 387 /* Remove joystick from list */ |
388 for (i = 0; SDL_joysticks[i]; ++i) { | 388 for (i = 0; SDL_joysticks[i]; ++i) { |
389 if (joystick == SDL_joysticks[i]) { | 389 if (joystick == SDL_joysticks[i]) { |
390 SDL_memcpy (&SDL_joysticks[i], &SDL_joysticks[i + 1], | 390 SDL_memcpy(&SDL_joysticks[i], &SDL_joysticks[i + 1], |
391 (SDL_numjoysticks - i) * sizeof (joystick)); | 391 (SDL_numjoysticks - i) * sizeof(joystick)); |
392 break; | 392 break; |
393 } | 393 } |
394 } | 394 } |
395 | 395 |
396 /* Let the event thread keep running */ | 396 /* Let the event thread keep running */ |
397 SDL_Unlock_EventThread (); | 397 SDL_Unlock_EventThread(); |
398 | 398 |
399 /* Free the data associated with this joystick */ | 399 /* Free the data associated with this joystick */ |
400 if (joystick->axes) { | 400 if (joystick->axes) { |
401 SDL_free (joystick->axes); | 401 SDL_free(joystick->axes); |
402 } | 402 } |
403 if (joystick->hats) { | 403 if (joystick->hats) { |
404 SDL_free (joystick->hats); | 404 SDL_free(joystick->hats); |
405 } | 405 } |
406 if (joystick->balls) { | 406 if (joystick->balls) { |
407 SDL_free (joystick->balls); | 407 SDL_free(joystick->balls); |
408 } | 408 } |
409 if (joystick->buttons) { | 409 if (joystick->buttons) { |
410 SDL_free (joystick->buttons); | 410 SDL_free(joystick->buttons); |
411 } | 411 } |
412 SDL_free (joystick); | 412 SDL_free(joystick); |
413 } | 413 } |
414 | 414 |
415 void | 415 void |
416 SDL_JoystickQuit (void) | 416 SDL_JoystickQuit(void) |
417 { | 417 { |
418 /* Stop the event polling */ | 418 /* Stop the event polling */ |
419 SDL_Lock_EventThread (); | 419 SDL_Lock_EventThread(); |
420 SDL_numjoysticks = 0; | 420 SDL_numjoysticks = 0; |
421 SDL_Unlock_EventThread (); | 421 SDL_Unlock_EventThread(); |
422 | 422 |
423 /* Quit the joystick setup */ | 423 /* Quit the joystick setup */ |
424 SDL_SYS_JoystickQuit (); | 424 SDL_SYS_JoystickQuit(); |
425 if (SDL_joysticks) { | 425 if (SDL_joysticks) { |
426 SDL_free (SDL_joysticks); | 426 SDL_free(SDL_joysticks); |
427 SDL_joysticks = NULL; | 427 SDL_joysticks = NULL; |
428 } | 428 } |
429 } | 429 } |
430 | 430 |
431 | 431 |
432 /* These are global for SDL_sysjoystick.c and SDL_events.c */ | 432 /* These are global for SDL_sysjoystick.c and SDL_events.c */ |
433 | 433 |
434 int | 434 int |
435 SDL_PrivateJoystickAxis (SDL_Joystick * joystick, Uint8 axis, Sint16 value) | 435 SDL_PrivateJoystickAxis(SDL_Joystick * joystick, Uint8 axis, Sint16 value) |
436 { | 436 { |
437 int posted; | 437 int posted; |
438 | 438 |
439 /* Update internal joystick state */ | 439 /* Update internal joystick state */ |
440 joystick->axes[axis] = value; | 440 joystick->axes[axis] = value; |
448 event.jaxis.which = joystick->index; | 448 event.jaxis.which = joystick->index; |
449 event.jaxis.axis = axis; | 449 event.jaxis.axis = axis; |
450 event.jaxis.value = value; | 450 event.jaxis.value = value; |
451 if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) { | 451 if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) { |
452 posted = 1; | 452 posted = 1; |
453 SDL_PushEvent (&event); | 453 SDL_PushEvent(&event); |
454 } | 454 } |
455 } | 455 } |
456 #endif /* !SDL_EVENTS_DISABLED */ | 456 #endif /* !SDL_EVENTS_DISABLED */ |
457 return (posted); | 457 return (posted); |
458 } | 458 } |
459 | 459 |
460 int | 460 int |
461 SDL_PrivateJoystickHat (SDL_Joystick * joystick, Uint8 hat, Uint8 value) | 461 SDL_PrivateJoystickHat(SDL_Joystick * joystick, Uint8 hat, Uint8 value) |
462 { | 462 { |
463 int posted; | 463 int posted; |
464 | 464 |
465 /* Update internal joystick state */ | 465 /* Update internal joystick state */ |
466 joystick->hats[hat] = value; | 466 joystick->hats[hat] = value; |
474 event.jhat.which = joystick->index; | 474 event.jhat.which = joystick->index; |
475 event.jhat.hat = hat; | 475 event.jhat.hat = hat; |
476 event.jhat.value = value; | 476 event.jhat.value = value; |
477 if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) { | 477 if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) { |
478 posted = 1; | 478 posted = 1; |
479 SDL_PushEvent (&event); | 479 SDL_PushEvent(&event); |
480 } | 480 } |
481 } | 481 } |
482 #endif /* !SDL_EVENTS_DISABLED */ | 482 #endif /* !SDL_EVENTS_DISABLED */ |
483 return (posted); | 483 return (posted); |
484 } | 484 } |
485 | 485 |
486 int | 486 int |
487 SDL_PrivateJoystickBall (SDL_Joystick * joystick, Uint8 ball, | 487 SDL_PrivateJoystickBall(SDL_Joystick * joystick, Uint8 ball, |
488 Sint16 xrel, Sint16 yrel) | 488 Sint16 xrel, Sint16 yrel) |
489 { | 489 { |
490 int posted; | 490 int posted; |
491 | 491 |
492 /* Update internal mouse state */ | 492 /* Update internal mouse state */ |
493 joystick->balls[ball].dx += xrel; | 493 joystick->balls[ball].dx += xrel; |
503 event.jball.ball = ball; | 503 event.jball.ball = ball; |
504 event.jball.xrel = xrel; | 504 event.jball.xrel = xrel; |
505 event.jball.yrel = yrel; | 505 event.jball.yrel = yrel; |
506 if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) { | 506 if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) { |
507 posted = 1; | 507 posted = 1; |
508 SDL_PushEvent (&event); | 508 SDL_PushEvent(&event); |
509 } | 509 } |
510 } | 510 } |
511 #endif /* !SDL_EVENTS_DISABLED */ | 511 #endif /* !SDL_EVENTS_DISABLED */ |
512 return (posted); | 512 return (posted); |
513 } | 513 } |
514 | 514 |
515 int | 515 int |
516 SDL_PrivateJoystickButton (SDL_Joystick * joystick, Uint8 button, Uint8 state) | 516 SDL_PrivateJoystickButton(SDL_Joystick * joystick, Uint8 button, Uint8 state) |
517 { | 517 { |
518 int posted; | 518 int posted; |
519 #if !SDL_EVENTS_DISABLED | 519 #if !SDL_EVENTS_DISABLED |
520 SDL_Event event; | 520 SDL_Event event; |
521 | 521 |
542 event.jbutton.which = joystick->index; | 542 event.jbutton.which = joystick->index; |
543 event.jbutton.button = button; | 543 event.jbutton.button = button; |
544 event.jbutton.state = state; | 544 event.jbutton.state = state; |
545 if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) { | 545 if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) { |
546 posted = 1; | 546 posted = 1; |
547 SDL_PushEvent (&event); | 547 SDL_PushEvent(&event); |
548 } | 548 } |
549 } | 549 } |
550 #endif /* !SDL_EVENTS_DISABLED */ | 550 #endif /* !SDL_EVENTS_DISABLED */ |
551 return (posted); | 551 return (posted); |
552 } | 552 } |
553 | 553 |
554 void | 554 void |
555 SDL_JoystickUpdate (void) | 555 SDL_JoystickUpdate(void) |
556 { | 556 { |
557 int i; | 557 int i; |
558 | 558 |
559 for (i = 0; SDL_joysticks[i]; ++i) { | 559 for (i = 0; SDL_joysticks[i]; ++i) { |
560 SDL_SYS_JoystickUpdate (SDL_joysticks[i]); | 560 SDL_SYS_JoystickUpdate(SDL_joysticks[i]); |
561 } | 561 } |
562 } | 562 } |
563 | 563 |
564 int | 564 int |
565 SDL_JoystickEventState (int state) | 565 SDL_JoystickEventState(int state) |
566 { | 566 { |
567 #if SDL_EVENTS_DISABLED | 567 #if SDL_EVENTS_DISABLED |
568 return SDL_IGNORE; | 568 return SDL_IGNORE; |
569 #else | 569 #else |
570 const Uint8 event_list[] = { | 570 const Uint8 event_list[] = { |
574 unsigned int i; | 574 unsigned int i; |
575 | 575 |
576 switch (state) { | 576 switch (state) { |
577 case SDL_QUERY: | 577 case SDL_QUERY: |
578 state = SDL_IGNORE; | 578 state = SDL_IGNORE; |
579 for (i = 0; i < SDL_arraysize (event_list); ++i) { | 579 for (i = 0; i < SDL_arraysize(event_list); ++i) { |
580 state = SDL_EventState (event_list[i], SDL_QUERY); | 580 state = SDL_EventState(event_list[i], SDL_QUERY); |
581 if (state == SDL_ENABLE) { | 581 if (state == SDL_ENABLE) { |
582 break; | 582 break; |
583 } | 583 } |
584 } | 584 } |
585 break; | 585 break; |
586 default: | 586 default: |
587 for (i = 0; i < SDL_arraysize (event_list); ++i) { | 587 for (i = 0; i < SDL_arraysize(event_list); ++i) { |
588 SDL_EventState (event_list[i], state); | 588 SDL_EventState(event_list[i], state); |
589 } | 589 } |
590 break; | 590 break; |
591 } | 591 } |
592 return (state); | 592 return (state); |
593 #endif /* SDL_EVENTS_DISABLED */ | 593 #endif /* SDL_EVENTS_DISABLED */ |