src/events/SDL_events.c
branchSDL-1.3
changeset 1722 5daa04d862f1
parent 1668 4da1ee79c9af
child 1724 6c63fc2bd986
     1.1 --- a/src/events/SDL_events.c	Fri Jun 30 05:50:35 2006 +0000
     1.2 +++ b/src/events/SDL_events.c	Fri Jun 30 08:18:44 2006 +0000
     1.3 @@ -34,6 +34,7 @@
     1.4  
     1.5  /* Public data -- the event filter */
     1.6  SDL_EventFilter SDL_EventOK = NULL;
     1.7 +void *SDL_EventOKParam;
     1.8  Uint8 SDL_ProcessEvents[SDL_NUMEVENTS];
     1.9  static Uint32 SDL_eventstate = 0;
    1.10  
    1.11 @@ -434,21 +435,43 @@
    1.12  }
    1.13  
    1.14  void
    1.15 -SDL_SetEventFilter(SDL_EventFilter filter)
    1.16 +SDL_SetEventFilter(SDL_EventFilter filter, void *userdata)
    1.17  {
    1.18      SDL_Event bitbucket;
    1.19  
    1.20      /* Set filter and discard pending events */
    1.21      SDL_EventOK = filter;
    1.22 +    SDL_EventOKParam = userdata;
    1.23      while (SDL_PollEvent(&bitbucket) > 0);
    1.24  }
    1.25  
    1.26  SDL_EventFilter
    1.27 -SDL_GetEventFilter(void)
    1.28 +SDL_GetEventFilter(void **userdata)
    1.29  {
    1.30 +    if (userdata) {
    1.31 +        *userdata = SDL_EventOKParam;
    1.32 +    }
    1.33      return (SDL_EventOK);
    1.34  }
    1.35  
    1.36 +void
    1.37 +SDL_FilterEvents(SDL_EventFilter filter, void *userdata)
    1.38 +{
    1.39 +    if (SDL_mutexP(SDL_EventQ.lock) == 0) {
    1.40 +        int spot;
    1.41 +
    1.42 +        spot = SDL_EventQ.head;
    1.43 +        while (spot != SDL_EventQ.tail) {
    1.44 +            if (filter(userdata, &SDL_EventQ.event[spot])) {
    1.45 +                spot = (spot + 1) % MAXEVENTS;
    1.46 +            } else {
    1.47 +                spot = SDL_CutEvent(spot);
    1.48 +            }
    1.49 +        }
    1.50 +    }
    1.51 +    SDL_mutexV(SDL_EventQ.lock);
    1.52 +}
    1.53 +
    1.54  Uint8
    1.55  SDL_EventState(Uint8 type, int state)
    1.56  {
    1.57 @@ -507,7 +530,8 @@
    1.58          SDL_memset(&event, 0, sizeof(event));
    1.59          event.type = SDL_SYSWMEVENT;
    1.60          event.syswm.msg = message;
    1.61 -        if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) {
    1.62 +        if ((SDL_EventOK == NULL)
    1.63 +            || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
    1.64              posted = 1;
    1.65              SDL_PushEvent(&event);
    1.66          }