comparison src/events/SDL_events.c @ 1722:5daa04d862f1 SDL-1.3

Added a userdata parameter for event filters. Added a function to filter the existing queued events. Added explicit support for relative mouse mode to the API.
author Sam Lantinga <slouken@libsdl.org>
date Fri, 30 Jun 2006 08:18:44 +0000
parents 4da1ee79c9af
children 6c63fc2bd986
comparison
equal deleted inserted replaced
1721:1cc762cafff8 1722:5daa04d862f1
32 #include "../joystick/SDL_joystick_c.h" 32 #include "../joystick/SDL_joystick_c.h"
33 #endif 33 #endif
34 34
35 /* Public data -- the event filter */ 35 /* Public data -- the event filter */
36 SDL_EventFilter SDL_EventOK = NULL; 36 SDL_EventFilter SDL_EventOK = NULL;
37 void *SDL_EventOKParam;
37 Uint8 SDL_ProcessEvents[SDL_NUMEVENTS]; 38 Uint8 SDL_ProcessEvents[SDL_NUMEVENTS];
38 static Uint32 SDL_eventstate = 0; 39 static Uint32 SDL_eventstate = 0;
39 40
40 /* Private data -- event queue */ 41 /* Private data -- event queue */
41 #define MAXEVENTS 128 42 #define MAXEVENTS 128
432 return -1; 433 return -1;
433 return 0; 434 return 0;
434 } 435 }
435 436
436 void 437 void
437 SDL_SetEventFilter(SDL_EventFilter filter) 438 SDL_SetEventFilter(SDL_EventFilter filter, void *userdata)
438 { 439 {
439 SDL_Event bitbucket; 440 SDL_Event bitbucket;
440 441
441 /* Set filter and discard pending events */ 442 /* Set filter and discard pending events */
442 SDL_EventOK = filter; 443 SDL_EventOK = filter;
444 SDL_EventOKParam = userdata;
443 while (SDL_PollEvent(&bitbucket) > 0); 445 while (SDL_PollEvent(&bitbucket) > 0);
444 } 446 }
445 447
446 SDL_EventFilter 448 SDL_EventFilter
447 SDL_GetEventFilter(void) 449 SDL_GetEventFilter(void **userdata)
448 { 450 {
451 if (userdata) {
452 *userdata = SDL_EventOKParam;
453 }
449 return (SDL_EventOK); 454 return (SDL_EventOK);
455 }
456
457 void
458 SDL_FilterEvents(SDL_EventFilter filter, void *userdata)
459 {
460 if (SDL_mutexP(SDL_EventQ.lock) == 0) {
461 int spot;
462
463 spot = SDL_EventQ.head;
464 while (spot != SDL_EventQ.tail) {
465 if (filter(userdata, &SDL_EventQ.event[spot])) {
466 spot = (spot + 1) % MAXEVENTS;
467 } else {
468 spot = SDL_CutEvent(spot);
469 }
470 }
471 }
472 SDL_mutexV(SDL_EventQ.lock);
450 } 473 }
451 474
452 Uint8 475 Uint8
453 SDL_EventState(Uint8 type, int state) 476 SDL_EventState(Uint8 type, int state)
454 { 477 {
505 if (SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE) { 528 if (SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE) {
506 SDL_Event event; 529 SDL_Event event;
507 SDL_memset(&event, 0, sizeof(event)); 530 SDL_memset(&event, 0, sizeof(event));
508 event.type = SDL_SYSWMEVENT; 531 event.type = SDL_SYSWMEVENT;
509 event.syswm.msg = message; 532 event.syswm.msg = message;
510 if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) { 533 if ((SDL_EventOK == NULL)
534 || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
511 posted = 1; 535 posted = 1;
512 SDL_PushEvent(&event); 536 SDL_PushEvent(&event);
513 } 537 }
514 } 538 }
515 /* Update internal event state */ 539 /* Update internal event state */