Home | History | Annotate | Download | only in joystick

Lines Matching defs:joystick

24 /* This is the joystick API for Simple DirectMedia Layer */
75 * Get the implementation dependent name of a joystick
88 * Open a joystick for use - the index passed as an argument refers to
89 * the N'th joystick on the system. This index is the value which will
90 * identify this joystick in future joystick events.
92 * This function returns a joystick identifier, or NULL if an error occurred.
97 SDL_Joystick *joystick;
105 /* If the joystick is already open, return it */
108 joystick = SDL_joysticks[i];
109 ++joystick->ref_count;
110 return(joystick);
114 /* Create and initialize the joystick */
115 joystick = (SDL_Joystick *)SDL_malloc((sizeof *joystick));
116 if ( !joystick ) {
121 SDL_memset(joystick, 0, (sizeof *joystick));
122 joystick->index = device_index;
123 if ( SDL_SYS_JoystickOpen(joystick) < 0 ) {
124 SDL_free(joystick);
128 if ( joystick->naxes > 0 ) {
129 joystick->axes = (Sint16 *)SDL_malloc
130 (joystick->naxes*sizeof(Sint16));
132 if ( joystick->nhats > 0 ) {
133 joystick->hats = (Uint8 *)SDL_malloc
134 (joystick->nhats*sizeof(Uint8));
136 if ( joystick->nballs > 0 ) {
137 joystick->balls = (struct balldelta *)SDL_malloc
138 (joystick->nballs*sizeof(*joystick->balls));
140 if ( joystick->nbuttons > 0 ) {
141 joystick->buttons = (Uint8 *)SDL_malloc
142 (joystick->nbuttons*sizeof(Uint8));
144 if ( ((joystick->naxes > 0) && !joystick->axes)
145 || ((joystick->nhats > 0) && !joystick->hats)
146 || ((joystick->nballs > 0) && !joystick->balls)
147 || ((joystick->nbuttons > 0) && !joystick->buttons)) {
149 SDL_JoystickClose(joystick);
153 if ( joystick->axes ) {
154 SDL_memset(joystick->axes, 0,
155 joystick->naxes*sizeof(Sint16));
157 if ( joystick->hats ) {
158 SDL_memset(joystick->hats, 0,
159 joystick->nhats*sizeof(Uint8));
161 if ( joystick->balls ) {
162 SDL_memset(joystick->balls, 0,
163 joystick->nballs*sizeof(*joystick->balls));
165 if ( joystick->buttons ) {
166 SDL_memset(joystick->buttons, 0,
167 joystick->nbuttons*sizeof(Uint8));
170 /* Add joystick to list */
171 ++joystick->ref_count;
174 /* Skip to next joystick */ ;
175 SDL_joysticks[i] = joystick;
178 return(joystick);
182 * Returns 1 if the joystick has been opened, or 0 if it has not.
198 static int ValidJoystick(SDL_Joystick **joystick)
202 if ( *joystick == NULL ) {
203 SDL_SetError("Joystick hasn't been opened yet");
212 * Get the device index of an opened joystick.
214 int SDL_JoystickIndex(SDL_Joystick *joystick)
216 if ( ! ValidJoystick(&joystick) ) {
219 return(joystick->index);
223 * Get the number of multi-dimensional axis controls on a joystick
225 int SDL_JoystickNumAxes(SDL_Joystick *joystick)
227 if ( ! ValidJoystick(&joystick) ) {
230 return(joystick->naxes);
234 * Get the number of hats on a joystick
236 int SDL_JoystickNumHats(SDL_Joystick *joystick)
238 if ( ! ValidJoystick(&joystick) ) {
241 return(joystick->nhats);
245 * Get the number of trackballs on a joystick
247 int SDL_JoystickNumBalls(SDL_Joystick *joystick)
249 if ( ! ValidJoystick(&joystick) ) {
252 return(joystick->nballs);
256 * Get the number of buttons on a joystick
258 int SDL_JoystickNumButtons(SDL_Joystick *joystick)
260 if ( ! ValidJoystick(&joystick) ) {
263 return(joystick->nbuttons);
267 * Get the current state of an axis control on a joystick
269 Sint16 SDL_JoystickGetAxis(SDL_Joystick *joystick, int axis)
273 if ( ! ValidJoystick(&joystick) ) {
276 if ( axis < joystick->naxes ) {
277 state = joystick->axes[axis];
279 SDL_SetError("Joystick only has %d axes", joystick->naxes);
286 * Get the current state of a hat on a joystick
288 Uint8 SDL_JoystickGetHat(SDL_Joystick *joystick, int hat)
292 if ( ! ValidJoystick(&joystick) ) {
295 if ( hat < joystick->nhats ) {
296 state = joystick->hats[hat];
298 SDL_SetError("Joystick only has %d hats", joystick->nhats);
307 int SDL_JoystickGetBall(SDL_Joystick *joystick, int ball, int *dx, int *dy)
311 if ( ! ValidJoystick(&joystick) ) {
316 if ( ball < joystick->nballs ) {
318 *dx = joystick->balls[ball].dx;
321 *dy = joystick->balls[ball].dy;
323 joystick->balls[ball].dx = 0;
324 joystick->balls[ball].dy = 0;
326 SDL_SetError("Joystick only has %d balls", joystick->nballs);
333 * Get the current state of a button on a joystick
335 Uint8 SDL_JoystickGetButton(SDL_Joystick *joystick, int button)
339 if ( ! ValidJoystick(&joystick) ) {
342 if ( button < joystick->nbuttons ) {
343 state = joystick->buttons[button];
345 SDL_SetError("Joystick only has %d buttons",joystick->nbuttons);
352 * Close a joystick previously opened with SDL_JoystickOpen()
354 void SDL_JoystickClose(SDL_Joystick *joystick)
358 if ( ! ValidJoystick(&joystick) ) {
363 if ( --joystick->ref_count > 0 ) {
367 /* Lock the event queue - prevent joystick polling */
370 SDL_SYS_JoystickClose(joystick);
372 /* Remove joystick from list */
374 if ( joystick == SDL_joysticks[i] ) {
376 (SDL_allocatedjoysticks-i)*sizeof(joystick));
384 /* Free the data associated with this joystick */
385 if ( joystick->axes ) {
386 SDL_free(joystick->axes);
388 if ( joystick->hats ) {
389 SDL_free(joystick->hats);
391 if ( joystick->balls ) {
392 SDL_free(joystick->balls);
394 if ( joystick->buttons ) {
395 SDL_free(joystick->buttons);
397 SDL_free(joystick);
420 /* Quit the joystick setup */
432 int SDL_PrivateJoystickAxis(SDL_Joystick *joystick, Uint8 axis, Sint16 value)
437 if (axis >= joystick->naxes) {
441 /* Update internal joystick state */
442 joystick->axes[axis] = value;
450 event.jaxis.which = joystick->index;
462 int SDL_PrivateJoystickHat(SDL_Joystick *joystick, Uint8 hat, Uint8 value)
467 if (hat >= joystick->nhats) {
471 /* Update internal joystick state */
472 joystick->hats[hat] = value;
480 event.jhat.which = joystick->index;
492 int SDL_PrivateJoystickBall(SDL_Joystick *joystick, Uint8 ball,
498 if (ball >= joystick->nballs) {
503 joystick->balls[ball].dx += xrel;
504 joystick->balls[ball].dy += yrel;
512 event.jball.which = joystick->index;
525 int SDL_PrivateJoystickButton(SDL_Joystick *joystick, Uint8 button, Uint8 state)
545 if (button >= joystick->nbuttons) {
549 /* Update internal joystick state */
550 joystick->buttons[button] = state;
556 event.jbutton.which = joystick->index;