comparison src/joystick/SDL_joystick.c @ 4429:faa9fc8e7f67

General improvements for user custom event registration * Switched event type to enum (int32) * Switched polling by mask to polling by type range * Added SDL_RegisterEvents() to allow dynamic user event registration * Spread events out to allow inserting new related events without breaking binary compatibility * Added padding to event structures so they're the same size regardless of 32-bit compiler structure packing settings * Split SDL_HasEvent() to SDL_HasEvent() for a single event and SDL_HasEvents() for a range of events * Added SDL_GetEventState() as a shortcut for SDL_EventState(X, SDL_QUERY) * Added SDL_FlushEvent() and SDL_FlushEvents() to clear events from the event queue
author Sam Lantinga <slouken@libsdl.org>
date Thu, 25 Mar 2010 01:08:26 -0700
parents f7b03b6838cb
children dc0dfdd58f27
comparison
equal deleted inserted replaced
4428:68dfd6df47da 4429:faa9fc8e7f67
443 joystick->axes[axis] = value; 443 joystick->axes[axis] = value;
444 444
445 /* Post the event, if desired */ 445 /* Post the event, if desired */
446 posted = 0; 446 posted = 0;
447 #if !SDL_EVENTS_DISABLED 447 #if !SDL_EVENTS_DISABLED
448 if (SDL_ProcessEvents[SDL_JOYAXISMOTION] == SDL_ENABLE) { 448 if (SDL_GetEventState(SDL_JOYAXISMOTION) == SDL_ENABLE) {
449 SDL_Event event; 449 SDL_Event event;
450 event.type = SDL_JOYAXISMOTION; 450 event.type = SDL_JOYAXISMOTION;
451 event.jaxis.which = joystick->index; 451 event.jaxis.which = joystick->index;
452 event.jaxis.axis = axis; 452 event.jaxis.axis = axis;
453 event.jaxis.value = value; 453 event.jaxis.value = value;
470 joystick->hats[hat] = value; 470 joystick->hats[hat] = value;
471 471
472 /* Post the event, if desired */ 472 /* Post the event, if desired */
473 posted = 0; 473 posted = 0;
474 #if !SDL_EVENTS_DISABLED 474 #if !SDL_EVENTS_DISABLED
475 if (SDL_ProcessEvents[SDL_JOYHATMOTION] == SDL_ENABLE) { 475 if (SDL_GetEventState(SDL_JOYHATMOTION) == SDL_ENABLE) {
476 SDL_Event event; 476 SDL_Event event;
477 event.jhat.type = SDL_JOYHATMOTION; 477 event.jhat.type = SDL_JOYHATMOTION;
478 event.jhat.which = joystick->index; 478 event.jhat.which = joystick->index;
479 event.jhat.hat = hat; 479 event.jhat.hat = hat;
480 event.jhat.value = value; 480 event.jhat.value = value;
499 joystick->balls[ball].dy += yrel; 499 joystick->balls[ball].dy += yrel;
500 500
501 /* Post the event, if desired */ 501 /* Post the event, if desired */
502 posted = 0; 502 posted = 0;
503 #if !SDL_EVENTS_DISABLED 503 #if !SDL_EVENTS_DISABLED
504 if (SDL_ProcessEvents[SDL_JOYBALLMOTION] == SDL_ENABLE) { 504 if (SDL_GetEventState(SDL_JOYBALLMOTION) == SDL_ENABLE) {
505 SDL_Event event; 505 SDL_Event event;
506 event.jball.type = SDL_JOYBALLMOTION; 506 event.jball.type = SDL_JOYBALLMOTION;
507 event.jball.which = joystick->index; 507 event.jball.which = joystick->index;
508 event.jball.ball = ball; 508 event.jball.ball = ball;
509 event.jball.xrel = xrel; 509 event.jball.xrel = xrel;
542 joystick->buttons[button] = state; 542 joystick->buttons[button] = state;
543 543
544 /* Post the event, if desired */ 544 /* Post the event, if desired */
545 posted = 0; 545 posted = 0;
546 #if !SDL_EVENTS_DISABLED 546 #if !SDL_EVENTS_DISABLED
547 if (SDL_ProcessEvents[event.type] == SDL_ENABLE) { 547 if (SDL_GetEventState(event.type) == SDL_ENABLE) {
548 event.jbutton.which = joystick->index; 548 event.jbutton.which = joystick->index;
549 event.jbutton.button = button; 549 event.jbutton.button = button;
550 event.jbutton.state = state; 550 event.jbutton.state = state;
551 if ((SDL_EventOK == NULL) 551 if ((SDL_EventOK == NULL)
552 || (*SDL_EventOK) (SDL_EventOKParam, &event)) { 552 || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
572 SDL_JoystickEventState(int state) 572 SDL_JoystickEventState(int state)
573 { 573 {
574 #if SDL_EVENTS_DISABLED 574 #if SDL_EVENTS_DISABLED
575 return SDL_IGNORE; 575 return SDL_IGNORE;
576 #else 576 #else
577 const Uint8 event_list[] = { 577 const Uint32 event_list[] = {
578 SDL_JOYAXISMOTION, SDL_JOYBALLMOTION, SDL_JOYHATMOTION, 578 SDL_JOYAXISMOTION, SDL_JOYBALLMOTION, SDL_JOYHATMOTION,
579 SDL_JOYBUTTONDOWN, SDL_JOYBUTTONUP, 579 SDL_JOYBUTTONDOWN, SDL_JOYBUTTONUP,
580 }; 580 };
581 unsigned int i; 581 unsigned int i;
582 582