author | Sam Lantinga <slouken@libsdl.org> |
Tue, 29 Nov 2011 02:15:39 -0500 | |
changeset 6096 | 71a57385664f |
parent 6095 | 32d8fad8d7ad |
child 6097 | 4ea2b4d4937a |
permissions | -rw-r--r-- |
0 | 1 |
/* |
5535
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
2 |
Simple DirectMedia Layer |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
3 |
Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org> |
0 | 4 |
|
5535
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
5 |
This software is provided 'as-is', without any express or implied |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
6 |
warranty. In no event will the authors be held liable for any damages |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
7 |
arising from the use of this software. |
0 | 8 |
|
5535
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
9 |
Permission is granted to anyone to use this software for any purpose, |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
10 |
including commercial applications, and to alter it and redistribute it |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
11 |
freely, subject to the following restrictions: |
0 | 12 |
|
5535
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
13 |
1. The origin of this software must not be misrepresented; you must not |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
14 |
claim that you wrote the original software. If you use this software |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
15 |
in a product, an acknowledgment in the product documentation would be |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
16 |
appreciated but is not required. |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
17 |
2. Altered source versions must be plainly marked as such, and must not be |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
18 |
misrepresented as being the original software. |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
19 |
3. This notice may not be removed or altered from any source distribution. |
0 | 20 |
*/ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
21 |
#include "SDL_config.h" |
0 | 22 |
|
23 |
/* This is the joystick API for Simple DirectMedia Layer */ |
|
24 |
||
25 |
#include "SDL_events.h" |
|
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
26 |
#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
|
27 |
#include "SDL_joystick_c.h" |
5861 | 28 |
#include "SDL_assert.h" |
29 |
||
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
30 |
#if !SDL_EVENTS_DISABLED |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
31 |
#include "../events/SDL_events_c.h" |
0 | 32 |
#endif |
33 |
||
34 |
Uint8 SDL_numjoysticks = 0; |
|
35 |
SDL_Joystick **SDL_joysticks = NULL; |
|
36 |
||
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
37 |
int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
38 |
SDL_JoystickInit(void) |
0 | 39 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
40 |
int arraylen; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
41 |
int status; |
0 | 42 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
43 |
SDL_numjoysticks = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
44 |
status = SDL_SYS_JoystickInit(); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
45 |
if (status >= 0) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
46 |
arraylen = (status + 1) * sizeof(*SDL_joysticks); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
47 |
SDL_joysticks = (SDL_Joystick **) SDL_malloc(arraylen); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
48 |
if (SDL_joysticks == NULL) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
49 |
SDL_numjoysticks = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
50 |
} else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
51 |
SDL_memset(SDL_joysticks, 0, arraylen); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
52 |
SDL_numjoysticks = status; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
53 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
54 |
status = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
55 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
56 |
return (status); |
0 | 57 |
} |
58 |
||
59 |
/* |
|
60 |
* Count the number of joysticks attached to the system |
|
61 |
*/ |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
62 |
int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
63 |
SDL_NumJoysticks(void) |
0 | 64 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
65 |
return SDL_numjoysticks; |
0 | 66 |
} |
67 |
||
68 |
/* |
|
69 |
* Get the implementation dependent name of a joystick |
|
70 |
*/ |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
71 |
const char * |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
72 |
SDL_JoystickName(int device_index) |
0 | 73 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
74 |
if ((device_index < 0) || (device_index >= SDL_numjoysticks)) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
75 |
SDL_SetError("There are %d joysticks available", SDL_numjoysticks); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
76 |
return (NULL); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
77 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
78 |
return (SDL_SYS_JoystickName(device_index)); |
0 | 79 |
} |
80 |
||
81 |
/* |
|
82 |
* Open a joystick for use - the index passed as an argument refers to |
|
83 |
* the N'th joystick on the system. This index is the value which will |
|
84 |
* identify this joystick in future joystick events. |
|
85 |
* |
|
86 |
* This function returns a joystick identifier, or NULL if an error occurred. |
|
87 |
*/ |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
88 |
SDL_Joystick * |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
89 |
SDL_JoystickOpen(int device_index) |
0 | 90 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
91 |
int i; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
92 |
SDL_Joystick *joystick; |
0 | 93 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
94 |
if ((device_index < 0) || (device_index >= SDL_numjoysticks)) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
95 |
SDL_SetError("There are %d joysticks available", SDL_numjoysticks); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
96 |
return (NULL); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
97 |
} |
0 | 98 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
99 |
/* If the joystick is already open, return it */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
100 |
for (i = 0; SDL_joysticks[i]; ++i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
101 |
if (device_index == SDL_joysticks[i]->index) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
102 |
joystick = SDL_joysticks[i]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
103 |
++joystick->ref_count; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
104 |
return (joystick); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
105 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
106 |
} |
0 | 107 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
108 |
/* Create and initialize the joystick */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
109 |
joystick = (SDL_Joystick *) SDL_malloc((sizeof *joystick)); |
3608
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
110 |
if (joystick == NULL) { |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
111 |
SDL_OutOfMemory(); |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
112 |
return NULL; |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
113 |
} |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
114 |
|
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
115 |
SDL_memset(joystick, 0, (sizeof *joystick)); |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
116 |
joystick->index = device_index; |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
117 |
if (SDL_SYS_JoystickOpen(joystick) < 0) { |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
118 |
SDL_free(joystick); |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
119 |
return NULL; |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
120 |
} |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
121 |
if (joystick->naxes > 0) { |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
122 |
joystick->axes = (Sint16 *) SDL_malloc |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
123 |
(joystick->naxes * sizeof(Sint16)); |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
124 |
} |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
125 |
if (joystick->nhats > 0) { |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
126 |
joystick->hats = (Uint8 *) SDL_malloc |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
127 |
(joystick->nhats * sizeof(Uint8)); |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
128 |
} |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
129 |
if (joystick->nballs > 0) { |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
130 |
joystick->balls = (struct balldelta *) SDL_malloc |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
131 |
(joystick->nballs * sizeof(*joystick->balls)); |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
132 |
} |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
133 |
if (joystick->nbuttons > 0) { |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
134 |
joystick->buttons = (Uint8 *) SDL_malloc |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
135 |
(joystick->nbuttons * sizeof(Uint8)); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
136 |
} |
3608
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
137 |
if (((joystick->naxes > 0) && !joystick->axes) |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
138 |
|| ((joystick->nhats > 0) && !joystick->hats) |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
139 |
|| ((joystick->nballs > 0) && !joystick->balls) |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
140 |
|| ((joystick->nbuttons > 0) && !joystick->buttons)) { |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
141 |
SDL_OutOfMemory(); |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
142 |
SDL_JoystickClose(joystick); |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
143 |
return NULL; |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
144 |
} |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
145 |
if (joystick->axes) { |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
146 |
SDL_memset(joystick->axes, 0, joystick->naxes * sizeof(Sint16)); |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
147 |
} |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
148 |
if (joystick->hats) { |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
149 |
SDL_memset(joystick->hats, 0, joystick->nhats * sizeof(Uint8)); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
150 |
} |
3608
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
151 |
if (joystick->balls) { |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
152 |
SDL_memset(joystick->balls, 0, |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
153 |
joystick->nballs * sizeof(*joystick->balls)); |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
154 |
} |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
155 |
if (joystick->buttons) { |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
156 |
SDL_memset(joystick->buttons, 0, joystick->nbuttons * sizeof(Uint8)); |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
157 |
} |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
158 |
|
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
159 |
/* Add joystick to list */ |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
160 |
++joystick->ref_count; |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
161 |
for (i = 0; SDL_joysticks[i]; ++i) |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
162 |
/* Skip to next joystick */ ; |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
163 |
SDL_joysticks[i] = joystick; |
a5a37f850d83
Merged r3787:3788 from branches/SDL-1.2: better failures for joystick opening.
Ryan C. Gordon <icculus@icculus.org>
parents:
3369
diff
changeset
|
164 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
165 |
return (joystick); |
0 | 166 |
} |
167 |
||
168 |
/* |
|
169 |
* Returns 1 if the joystick has been opened, or 0 if it has not. |
|
170 |
*/ |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
171 |
int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
172 |
SDL_JoystickOpened(int device_index) |
0 | 173 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
174 |
int i, opened; |
0 | 175 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
176 |
opened = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
177 |
for (i = 0; SDL_joysticks[i]; ++i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
178 |
if (SDL_joysticks[i]->index == (Uint8) device_index) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
179 |
opened = 1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
180 |
break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
181 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
182 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
183 |
return (opened); |
0 | 184 |
} |
185 |
||
2713
0906692aa6a4
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
186 |
|
0906692aa6a4
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
187 |
/* |
0906692aa6a4
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
188 |
* Checks to make sure the joystick is valid. |
0906692aa6a4
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
189 |
*/ |
0906692aa6a4
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
190 |
int |
0906692aa6a4
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
191 |
SDL_PrivateJoystickValid(SDL_Joystick ** joystick) |
0 | 192 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
193 |
int valid; |
0 | 194 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
195 |
if (*joystick == NULL) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
196 |
SDL_SetError("Joystick hasn't been opened yet"); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
197 |
valid = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
198 |
} else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
199 |
valid = 1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
200 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
201 |
return valid; |
0 | 202 |
} |
203 |
||
204 |
/* |
|
205 |
* Get the device index of an opened joystick. |
|
206 |
*/ |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
207 |
int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
208 |
SDL_JoystickIndex(SDL_Joystick * joystick) |
0 | 209 |
{ |
2713
0906692aa6a4
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
210 |
if (!SDL_PrivateJoystickValid(&joystick)) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
211 |
return (-1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
212 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
213 |
return (joystick->index); |
0 | 214 |
} |
215 |
||
216 |
/* |
|
217 |
* Get the number of multi-dimensional axis controls on a joystick |
|
218 |
*/ |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
219 |
int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
220 |
SDL_JoystickNumAxes(SDL_Joystick * joystick) |
0 | 221 |
{ |
2713
0906692aa6a4
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
222 |
if (!SDL_PrivateJoystickValid(&joystick)) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
223 |
return (-1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
224 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
225 |
return (joystick->naxes); |
0 | 226 |
} |
227 |
||
228 |
/* |
|
229 |
* Get the number of hats on a joystick |
|
230 |
*/ |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
231 |
int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
232 |
SDL_JoystickNumHats(SDL_Joystick * joystick) |
0 | 233 |
{ |
2713
0906692aa6a4
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
234 |
if (!SDL_PrivateJoystickValid(&joystick)) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
235 |
return (-1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
236 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
237 |
return (joystick->nhats); |
0 | 238 |
} |
239 |
||
240 |
/* |
|
241 |
* Get the number of trackballs on a joystick |
|
242 |
*/ |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
243 |
int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
244 |
SDL_JoystickNumBalls(SDL_Joystick * joystick) |
0 | 245 |
{ |
2713
0906692aa6a4
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
246 |
if (!SDL_PrivateJoystickValid(&joystick)) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
247 |
return (-1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
248 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
249 |
return (joystick->nballs); |
0 | 250 |
} |
251 |
||
252 |
/* |
|
253 |
* Get the number of buttons on a joystick |
|
254 |
*/ |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
255 |
int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
256 |
SDL_JoystickNumButtons(SDL_Joystick * joystick) |
0 | 257 |
{ |
2713
0906692aa6a4
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
258 |
if (!SDL_PrivateJoystickValid(&joystick)) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
259 |
return (-1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
260 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
261 |
return (joystick->nbuttons); |
0 | 262 |
} |
263 |
||
264 |
/* |
|
265 |
* Get the current state of an axis control on a joystick |
|
266 |
*/ |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
267 |
Sint16 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
268 |
SDL_JoystickGetAxis(SDL_Joystick * joystick, int axis) |
0 | 269 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
270 |
Sint16 state; |
0 | 271 |
|
2713
0906692aa6a4
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
272 |
if (!SDL_PrivateJoystickValid(&joystick)) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
273 |
return (0); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
274 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
275 |
if (axis < joystick->naxes) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
276 |
state = joystick->axes[axis]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
277 |
} else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
278 |
SDL_SetError("Joystick only has %d axes", joystick->naxes); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
279 |
state = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
280 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
281 |
return (state); |
0 | 282 |
} |
283 |
||
284 |
/* |
|
285 |
* Get the current state of a hat on a joystick |
|
286 |
*/ |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
287 |
Uint8 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
288 |
SDL_JoystickGetHat(SDL_Joystick * joystick, int hat) |
0 | 289 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
290 |
Uint8 state; |
0 | 291 |
|
2713
0906692aa6a4
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
292 |
if (!SDL_PrivateJoystickValid(&joystick)) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
293 |
return (0); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
294 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
295 |
if (hat < joystick->nhats) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
296 |
state = joystick->hats[hat]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
297 |
} else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
298 |
SDL_SetError("Joystick only has %d hats", joystick->nhats); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
299 |
state = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
300 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
301 |
return (state); |
0 | 302 |
} |
303 |
||
304 |
/* |
|
305 |
* Get the ball axis change since the last poll |
|
306 |
*/ |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
307 |
int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
308 |
SDL_JoystickGetBall(SDL_Joystick * joystick, int ball, int *dx, int *dy) |
0 | 309 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
310 |
int retval; |
0 | 311 |
|
2713
0906692aa6a4
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
312 |
if (!SDL_PrivateJoystickValid(&joystick)) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
313 |
return (-1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
314 |
} |
0 | 315 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
316 |
retval = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
317 |
if (ball < joystick->nballs) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
318 |
if (dx) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
319 |
*dx = joystick->balls[ball].dx; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
320 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
321 |
if (dy) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
322 |
*dy = joystick->balls[ball].dy; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
323 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
324 |
joystick->balls[ball].dx = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
325 |
joystick->balls[ball].dy = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
326 |
} else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
327 |
SDL_SetError("Joystick only has %d balls", joystick->nballs); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
328 |
retval = -1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
329 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
330 |
return (retval); |
0 | 331 |
} |
332 |
||
333 |
/* |
|
334 |
* Get the current state of a button on a joystick |
|
335 |
*/ |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
336 |
Uint8 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
337 |
SDL_JoystickGetButton(SDL_Joystick * joystick, int button) |
0 | 338 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
339 |
Uint8 state; |
0 | 340 |
|
2713
0906692aa6a4
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
341 |
if (!SDL_PrivateJoystickValid(&joystick)) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
342 |
return (0); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
343 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
344 |
if (button < joystick->nbuttons) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
345 |
state = joystick->buttons[button]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
346 |
} else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
347 |
SDL_SetError("Joystick only has %d buttons", joystick->nbuttons); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
348 |
state = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
349 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
350 |
return (state); |
0 | 351 |
} |
352 |
||
353 |
/* |
|
354 |
* Close a joystick previously opened with SDL_JoystickOpen() |
|
355 |
*/ |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
356 |
void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
357 |
SDL_JoystickClose(SDL_Joystick * joystick) |
0 | 358 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
359 |
int i; |
0 | 360 |
|
2713
0906692aa6a4
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
361 |
if (!SDL_PrivateJoystickValid(&joystick)) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
362 |
return; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
363 |
} |
0 | 364 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
365 |
/* First decrement ref count */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
366 |
if (--joystick->ref_count > 0) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
367 |
return; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
368 |
} |
0 | 369 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
370 |
SDL_SYS_JoystickClose(joystick); |
0 | 371 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
372 |
/* Remove joystick from list */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
373 |
for (i = 0; SDL_joysticks[i]; ++i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
374 |
if (joystick == SDL_joysticks[i]) { |
3369
71bb88152e3f
Debian patch: 218_joystick_memmove.diff
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
375 |
SDL_memmove(&SDL_joysticks[i], &SDL_joysticks[i + 1], |
71bb88152e3f
Debian patch: 218_joystick_memmove.diff
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
376 |
(SDL_numjoysticks - i) * sizeof(joystick)); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
377 |
break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
378 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
379 |
} |
0 | 380 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
381 |
/* Free the data associated with this joystick */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
382 |
if (joystick->axes) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
383 |
SDL_free(joystick->axes); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
384 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
385 |
if (joystick->hats) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
386 |
SDL_free(joystick->hats); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
387 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
388 |
if (joystick->balls) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
389 |
SDL_free(joystick->balls); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
390 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
391 |
if (joystick->buttons) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
392 |
SDL_free(joystick->buttons); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
393 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
394 |
SDL_free(joystick); |
0 | 395 |
} |
396 |
||
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
397 |
void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
398 |
SDL_JoystickQuit(void) |
0 | 399 |
{ |
5856
173d28fd4be4
Clean up any opened joysticks during SDL_JoystickQuit().
Ryan C. Gordon <icculus@icculus.org>
parents:
5535
diff
changeset
|
400 |
const int numsticks = SDL_numjoysticks; |
173d28fd4be4
Clean up any opened joysticks during SDL_JoystickQuit().
Ryan C. Gordon <icculus@icculus.org>
parents:
5535
diff
changeset
|
401 |
int i; |
173d28fd4be4
Clean up any opened joysticks during SDL_JoystickQuit().
Ryan C. Gordon <icculus@icculus.org>
parents:
5535
diff
changeset
|
402 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
403 |
/* Stop the event polling */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
404 |
SDL_numjoysticks = 0; |
0 | 405 |
|
5856
173d28fd4be4
Clean up any opened joysticks during SDL_JoystickQuit().
Ryan C. Gordon <icculus@icculus.org>
parents:
5535
diff
changeset
|
406 |
for (i = 0; i < numsticks; i++) { |
6096
71a57385664f
Closing the joystick removes it from the list.
Sam Lantinga <slouken@libsdl.org>
parents:
6095
diff
changeset
|
407 |
SDL_Joystick *stick = SDL_joysticks[0]; |
5856
173d28fd4be4
Clean up any opened joysticks during SDL_JoystickQuit().
Ryan C. Gordon <icculus@icculus.org>
parents:
5535
diff
changeset
|
408 |
if (stick && (stick->ref_count >= 1)) { |
173d28fd4be4
Clean up any opened joysticks during SDL_JoystickQuit().
Ryan C. Gordon <icculus@icculus.org>
parents:
5535
diff
changeset
|
409 |
stick->ref_count = 1; |
173d28fd4be4
Clean up any opened joysticks during SDL_JoystickQuit().
Ryan C. Gordon <icculus@icculus.org>
parents:
5535
diff
changeset
|
410 |
SDL_JoystickClose(stick); |
173d28fd4be4
Clean up any opened joysticks during SDL_JoystickQuit().
Ryan C. Gordon <icculus@icculus.org>
parents:
5535
diff
changeset
|
411 |
} |
173d28fd4be4
Clean up any opened joysticks during SDL_JoystickQuit().
Ryan C. Gordon <icculus@icculus.org>
parents:
5535
diff
changeset
|
412 |
} |
173d28fd4be4
Clean up any opened joysticks during SDL_JoystickQuit().
Ryan C. Gordon <icculus@icculus.org>
parents:
5535
diff
changeset
|
413 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
414 |
/* Quit the joystick setup */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
415 |
SDL_SYS_JoystickQuit(); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
416 |
if (SDL_joysticks) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
417 |
SDL_free(SDL_joysticks); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
418 |
SDL_joysticks = NULL; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
419 |
} |
0 | 420 |
} |
421 |
||
422 |
||
423 |
/* These are global for SDL_sysjoystick.c and SDL_events.c */ |
|
424 |
||
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
425 |
int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
426 |
SDL_PrivateJoystickAxis(SDL_Joystick * joystick, Uint8 axis, Sint16 value) |
0 | 427 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
428 |
int posted; |
0 | 429 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
430 |
/* Update internal joystick state */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
431 |
joystick->axes[axis] = value; |
0 | 432 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
433 |
/* Post the event, if desired */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
434 |
posted = 0; |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
435 |
#if !SDL_EVENTS_DISABLED |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
436 |
if (SDL_GetEventState(SDL_JOYAXISMOTION) == SDL_ENABLE) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
437 |
SDL_Event event; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
438 |
event.type = SDL_JOYAXISMOTION; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
439 |
event.jaxis.which = joystick->index; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
440 |
event.jaxis.axis = axis; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
441 |
event.jaxis.value = value; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
442 |
if ((SDL_EventOK == NULL) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
443 |
|| (*SDL_EventOK) (SDL_EventOKParam, &event)) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
444 |
posted = 1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
445 |
SDL_PushEvent(&event); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
446 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
447 |
} |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
448 |
#endif /* !SDL_EVENTS_DISABLED */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
449 |
return (posted); |
0 | 450 |
} |
451 |
||
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
452 |
int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
453 |
SDL_PrivateJoystickHat(SDL_Joystick * joystick, Uint8 hat, Uint8 value) |
0 | 454 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
455 |
int posted; |
0 | 456 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
457 |
/* Update internal joystick state */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
458 |
joystick->hats[hat] = value; |
0 | 459 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
460 |
/* Post the event, if desired */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
461 |
posted = 0; |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
462 |
#if !SDL_EVENTS_DISABLED |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
463 |
if (SDL_GetEventState(SDL_JOYHATMOTION) == SDL_ENABLE) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
464 |
SDL_Event event; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
465 |
event.jhat.type = SDL_JOYHATMOTION; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
466 |
event.jhat.which = joystick->index; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
467 |
event.jhat.hat = hat; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
468 |
event.jhat.value = value; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
469 |
if ((SDL_EventOK == NULL) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
470 |
|| (*SDL_EventOK) (SDL_EventOKParam, &event)) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
471 |
posted = 1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
472 |
SDL_PushEvent(&event); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
473 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
474 |
} |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
475 |
#endif /* !SDL_EVENTS_DISABLED */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
476 |
return (posted); |
0 | 477 |
} |
478 |
||
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
479 |
int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
480 |
SDL_PrivateJoystickBall(SDL_Joystick * joystick, Uint8 ball, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
481 |
Sint16 xrel, Sint16 yrel) |
0 | 482 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
483 |
int posted; |
0 | 484 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
485 |
/* Update internal mouse state */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
486 |
joystick->balls[ball].dx += xrel; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
487 |
joystick->balls[ball].dy += yrel; |
0 | 488 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
489 |
/* Post the event, if desired */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
490 |
posted = 0; |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
491 |
#if !SDL_EVENTS_DISABLED |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
492 |
if (SDL_GetEventState(SDL_JOYBALLMOTION) == SDL_ENABLE) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
493 |
SDL_Event event; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
494 |
event.jball.type = SDL_JOYBALLMOTION; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
495 |
event.jball.which = joystick->index; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
496 |
event.jball.ball = ball; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
497 |
event.jball.xrel = xrel; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
498 |
event.jball.yrel = yrel; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
499 |
if ((SDL_EventOK == NULL) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
500 |
|| (*SDL_EventOK) (SDL_EventOKParam, &event)) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
501 |
posted = 1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
502 |
SDL_PushEvent(&event); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
503 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
504 |
} |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
505 |
#endif /* !SDL_EVENTS_DISABLED */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
506 |
return (posted); |
0 | 507 |
} |
508 |
||
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
509 |
int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
510 |
SDL_PrivateJoystickButton(SDL_Joystick * joystick, Uint8 button, Uint8 state) |
0 | 511 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
512 |
int posted; |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
513 |
#if !SDL_EVENTS_DISABLED |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
514 |
SDL_Event event; |
0 | 515 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
516 |
switch (state) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
517 |
case SDL_PRESSED: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
518 |
event.type = SDL_JOYBUTTONDOWN; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
519 |
break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
520 |
case SDL_RELEASED: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
521 |
event.type = SDL_JOYBUTTONUP; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
522 |
break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
523 |
default: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
524 |
/* Invalid state -- bail */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
525 |
return (0); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
526 |
} |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
527 |
#endif /* !SDL_EVENTS_DISABLED */ |
0 | 528 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
529 |
/* Update internal joystick state */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
530 |
joystick->buttons[button] = state; |
0 | 531 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
532 |
/* Post the event, if desired */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
533 |
posted = 0; |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
534 |
#if !SDL_EVENTS_DISABLED |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
535 |
if (SDL_GetEventState(event.type) == SDL_ENABLE) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
536 |
event.jbutton.which = joystick->index; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
537 |
event.jbutton.button = button; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
538 |
event.jbutton.state = state; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
539 |
if ((SDL_EventOK == NULL) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
540 |
|| (*SDL_EventOK) (SDL_EventOKParam, &event)) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
541 |
posted = 1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
542 |
SDL_PushEvent(&event); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
543 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
544 |
} |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
545 |
#endif /* !SDL_EVENTS_DISABLED */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
546 |
return (posted); |
0 | 547 |
} |
548 |
||
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
549 |
void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
550 |
SDL_JoystickUpdate(void) |
0 | 551 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
552 |
int i; |
0 | 553 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
554 |
for (i = 0; SDL_joysticks[i]; ++i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
555 |
SDL_SYS_JoystickUpdate(SDL_joysticks[i]); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
556 |
} |
0 | 557 |
} |
558 |
||
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
559 |
int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
560 |
SDL_JoystickEventState(int state) |
0 | 561 |
{ |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
562 |
#if SDL_EVENTS_DISABLED |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
563 |
return SDL_IGNORE; |
0 | 564 |
#else |
4429
faa9fc8e7f67
General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
565 |
const Uint32 event_list[] = { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
566 |
SDL_JOYAXISMOTION, SDL_JOYBALLMOTION, SDL_JOYHATMOTION, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
567 |
SDL_JOYBUTTONDOWN, SDL_JOYBUTTONUP, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
568 |
}; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
569 |
unsigned int i; |
0 | 570 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
571 |
switch (state) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
572 |
case SDL_QUERY: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
573 |
state = SDL_IGNORE; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
574 |
for (i = 0; i < SDL_arraysize(event_list); ++i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
575 |
state = SDL_EventState(event_list[i], SDL_QUERY); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
576 |
if (state == SDL_ENABLE) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
577 |
break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
578 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
579 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
580 |
break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
581 |
default: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
582 |
for (i = 0; i < SDL_arraysize(event_list); ++i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
583 |
SDL_EventState(event_list[i], state); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
584 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
585 |
break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
586 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
587 |
return (state); |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
588 |
#endif /* SDL_EVENTS_DISABLED */ |
0 | 589 |
} |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
590 |
|
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1612
diff
changeset
|
591 |
/* vi: set ts=4 sw=4 expandtab: */ |