[SDL] Help with SDL_Event

Christian Walther cwalther at gmx.ch
Sun Aug 6 00:11:32 PDT 2006


Phantom Lord wrote:
> Hi, i'm working on a function that lets me check if the SDL_Event.type 
> argument passed, is equal to the one that is in the class.
> Just dont know how to make something like this:
> 
> checkEvent(SDL_Event.type EventType);
> 
> Because i dont want to create another SDL_Event and set its type to 
> SDL_QUIT, for example, and then check, if this is possible.

 From SDL_Events.h:

/* Event enumerations */
typedef enum {
     SDL_NOEVENT = 0,                    /* Unused (do not remove) */
     ...
     SDL_EVENT_RESERVED7,                /* Reserved for future use.. */
     /* Events SDL_USEREVENT through SDL_MAXEVENTS-1 are for your use */
     SDL_USEREVENT = 24,
     /* This last event is only for bounding internal arrays
        It is the number of bits in the event mask datatype -- Uint32
     */
     SDL_NUMEVENTS = 32
} SDL_EventType;

So, use something like

#define MYEVENT1 SDL_USEREVENT
#define MYEVENT2 (SDL_USEREVENT+1)

and if you still need your check function, it would look something like

SDL_bool isInternalEventType(SDL_EventType type) {
	return (type >= 0 && type < SDL_USEREVENT);
}

As mentioned on this list recently, this still doesn't protect you from 
stepping on someone else's user events, though, if you happen to use a 
library that defines some user events itself.

  -Christian





More information about the SDL mailing list