Mercurial > sdl-ios-xcode
comparison src/joystick/SDL_joystick.c @ 1361:19418e4422cb
New configure-based build system. Still work in progress, but much improved
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 16 Feb 2006 10:11:48 +0000 |
parents | c71e05b4dc2e |
children | c0a74f199ecf |
comparison
equal
deleted
inserted
replaced
1360:70a9cfb4cf1b | 1361:19418e4422cb |
---|---|
21 */ | 21 */ |
22 | 22 |
23 /* This is the joystick API for Simple DirectMedia Layer */ | 23 /* This is the joystick API for Simple DirectMedia Layer */ |
24 | 24 |
25 #include "SDL_events.h" | 25 #include "SDL_events.h" |
26 #ifndef DISABLE_EVENTS | 26 #include "SDL_sysjoystick.h" |
27 #include "SDL_events_c.h" | 27 #include "SDL_joystick_c.h" |
28 #if !SDL_EVENTS_DISABLED | |
29 #include "../events/SDL_events_c.h" | |
28 #endif | 30 #endif |
29 #include "SDL_joystick_c.h" | |
30 #include "SDL_sysjoystick.h" | |
31 | 31 |
32 /* This is used for Quake III Arena */ | 32 /* This is used for Quake III Arena */ |
33 #ifdef DISABLE_EVENTS | 33 #if SDL_EVENTS_DISABLED |
34 #define SDL_Lock_EventThread() | 34 #define SDL_Lock_EventThread() |
35 #define SDL_Unlock_EventThread() | 35 #define SDL_Unlock_EventThread() |
36 #endif | 36 #endif |
37 | 37 |
38 Uint8 SDL_numjoysticks = 0; | 38 Uint8 SDL_numjoysticks = 0; |
422 /* Update internal joystick state */ | 422 /* Update internal joystick state */ |
423 joystick->axes[axis] = value; | 423 joystick->axes[axis] = value; |
424 | 424 |
425 /* Post the event, if desired */ | 425 /* Post the event, if desired */ |
426 posted = 0; | 426 posted = 0; |
427 #ifndef DISABLE_EVENTS | 427 #if !SDL_EVENTS_DISABLED |
428 if ( SDL_ProcessEvents[SDL_JOYAXISMOTION] == SDL_ENABLE ) { | 428 if ( SDL_ProcessEvents[SDL_JOYAXISMOTION] == SDL_ENABLE ) { |
429 SDL_Event event; | 429 SDL_Event event; |
430 event.type = SDL_JOYAXISMOTION; | 430 event.type = SDL_JOYAXISMOTION; |
431 event.jaxis.which = joystick->index; | 431 event.jaxis.which = joystick->index; |
432 event.jaxis.axis = axis; | 432 event.jaxis.axis = axis; |
434 if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) { | 434 if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) { |
435 posted = 1; | 435 posted = 1; |
436 SDL_PushEvent(&event); | 436 SDL_PushEvent(&event); |
437 } | 437 } |
438 } | 438 } |
439 #endif /* !DISABLE_EVENTS */ | 439 #endif /* !SDL_EVENTS_DISABLED */ |
440 return(posted); | 440 return(posted); |
441 } | 441 } |
442 | 442 |
443 int SDL_PrivateJoystickHat(SDL_Joystick *joystick, Uint8 hat, Uint8 value) | 443 int SDL_PrivateJoystickHat(SDL_Joystick *joystick, Uint8 hat, Uint8 value) |
444 { | 444 { |
447 /* Update internal joystick state */ | 447 /* Update internal joystick state */ |
448 joystick->hats[hat] = value; | 448 joystick->hats[hat] = value; |
449 | 449 |
450 /* Post the event, if desired */ | 450 /* Post the event, if desired */ |
451 posted = 0; | 451 posted = 0; |
452 #ifndef DISABLE_EVENTS | 452 #if !SDL_EVENTS_DISABLED |
453 if ( SDL_ProcessEvents[SDL_JOYHATMOTION] == SDL_ENABLE ) { | 453 if ( SDL_ProcessEvents[SDL_JOYHATMOTION] == SDL_ENABLE ) { |
454 SDL_Event event; | 454 SDL_Event event; |
455 event.jhat.type = SDL_JOYHATMOTION; | 455 event.jhat.type = SDL_JOYHATMOTION; |
456 event.jhat.which = joystick->index; | 456 event.jhat.which = joystick->index; |
457 event.jhat.hat = hat; | 457 event.jhat.hat = hat; |
459 if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) { | 459 if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) { |
460 posted = 1; | 460 posted = 1; |
461 SDL_PushEvent(&event); | 461 SDL_PushEvent(&event); |
462 } | 462 } |
463 } | 463 } |
464 #endif /* !DISABLE_EVENTS */ | 464 #endif /* !SDL_EVENTS_DISABLED */ |
465 return(posted); | 465 return(posted); |
466 } | 466 } |
467 | 467 |
468 int SDL_PrivateJoystickBall(SDL_Joystick *joystick, Uint8 ball, | 468 int SDL_PrivateJoystickBall(SDL_Joystick *joystick, Uint8 ball, |
469 Sint16 xrel, Sint16 yrel) | 469 Sint16 xrel, Sint16 yrel) |
474 joystick->balls[ball].dx += xrel; | 474 joystick->balls[ball].dx += xrel; |
475 joystick->balls[ball].dy += yrel; | 475 joystick->balls[ball].dy += yrel; |
476 | 476 |
477 /* Post the event, if desired */ | 477 /* Post the event, if desired */ |
478 posted = 0; | 478 posted = 0; |
479 #ifndef DISABLE_EVENTS | 479 #if !SDL_EVENTS_DISABLED |
480 if ( SDL_ProcessEvents[SDL_JOYBALLMOTION] == SDL_ENABLE ) { | 480 if ( SDL_ProcessEvents[SDL_JOYBALLMOTION] == SDL_ENABLE ) { |
481 SDL_Event event; | 481 SDL_Event event; |
482 event.jball.type = SDL_JOYBALLMOTION; | 482 event.jball.type = SDL_JOYBALLMOTION; |
483 event.jball.which = joystick->index; | 483 event.jball.which = joystick->index; |
484 event.jball.ball = ball; | 484 event.jball.ball = ball; |
487 if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) { | 487 if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) { |
488 posted = 1; | 488 posted = 1; |
489 SDL_PushEvent(&event); | 489 SDL_PushEvent(&event); |
490 } | 490 } |
491 } | 491 } |
492 #endif /* !DISABLE_EVENTS */ | 492 #endif /* !SDL_EVENTS_DISABLED */ |
493 return(posted); | 493 return(posted); |
494 } | 494 } |
495 | 495 |
496 int SDL_PrivateJoystickButton(SDL_Joystick *joystick, Uint8 button, Uint8 state) | 496 int SDL_PrivateJoystickButton(SDL_Joystick *joystick, Uint8 button, Uint8 state) |
497 { | 497 { |
498 int posted; | 498 int posted; |
499 #ifndef DISABLE_EVENTS | 499 #if !SDL_EVENTS_DISABLED |
500 SDL_Event event; | 500 SDL_Event event; |
501 | 501 |
502 switch ( state ) { | 502 switch ( state ) { |
503 case SDL_PRESSED: | 503 case SDL_PRESSED: |
504 event.type = SDL_JOYBUTTONDOWN; | 504 event.type = SDL_JOYBUTTONDOWN; |
508 break; | 508 break; |
509 default: | 509 default: |
510 /* Invalid state -- bail */ | 510 /* Invalid state -- bail */ |
511 return(0); | 511 return(0); |
512 } | 512 } |
513 #endif /* !DISABLE_EVENTS */ | 513 #endif /* !SDL_EVENTS_DISABLED */ |
514 | 514 |
515 /* Update internal joystick state */ | 515 /* Update internal joystick state */ |
516 joystick->buttons[button] = state; | 516 joystick->buttons[button] = state; |
517 | 517 |
518 /* Post the event, if desired */ | 518 /* Post the event, if desired */ |
519 posted = 0; | 519 posted = 0; |
520 #ifndef DISABLE_EVENTS | 520 #if !SDL_EVENTS_DISABLED |
521 if ( SDL_ProcessEvents[event.type] == SDL_ENABLE ) { | 521 if ( SDL_ProcessEvents[event.type] == SDL_ENABLE ) { |
522 event.jbutton.which = joystick->index; | 522 event.jbutton.which = joystick->index; |
523 event.jbutton.button = button; | 523 event.jbutton.button = button; |
524 event.jbutton.state = state; | 524 event.jbutton.state = state; |
525 if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) { | 525 if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) { |
526 posted = 1; | 526 posted = 1; |
527 SDL_PushEvent(&event); | 527 SDL_PushEvent(&event); |
528 } | 528 } |
529 } | 529 } |
530 #endif /* !DISABLE_EVENTS */ | 530 #endif /* !SDL_EVENTS_DISABLED */ |
531 return(posted); | 531 return(posted); |
532 } | 532 } |
533 | 533 |
534 void SDL_JoystickUpdate(void) | 534 void SDL_JoystickUpdate(void) |
535 { | 535 { |
540 } | 540 } |
541 } | 541 } |
542 | 542 |
543 int SDL_JoystickEventState(int state) | 543 int SDL_JoystickEventState(int state) |
544 { | 544 { |
545 #ifdef DISABLE_EVENTS | 545 #if SDL_EVENTS_DISABLED |
546 return SDL_IGNORE; | 546 return SDL_IGNORE; |
547 #else | 547 #else |
548 const Uint8 event_list[] = { | 548 const Uint8 event_list[] = { |
549 SDL_JOYAXISMOTION, SDL_JOYBALLMOTION, SDL_JOYHATMOTION, | 549 SDL_JOYAXISMOTION, SDL_JOYBALLMOTION, SDL_JOYHATMOTION, |
550 SDL_JOYBUTTONDOWN, SDL_JOYBUTTONUP, | 550 SDL_JOYBUTTONDOWN, SDL_JOYBUTTONUP, |
566 SDL_EventState(event_list[i], state); | 566 SDL_EventState(event_list[i], state); |
567 } | 567 } |
568 break; | 568 break; |
569 } | 569 } |
570 return(state); | 570 return(state); |
571 #endif /* DISABLE_EVENTS */ | 571 #endif /* SDL_EVENTS_DISABLED */ |
572 } | 572 } |