From 96f86ed5e2472571760388c6658c42c6237b699a Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 25 May 2003 23:49:40 +0000 Subject: [PATCH] Add mySDL_EventState to work around bizarre SDL event behavior --- stepmania/src/SDL_utils.cpp | 29 +++++++++++++++++++++++++++++ stepmania/src/SDL_utils.h | 3 +++ 2 files changed, 32 insertions(+) diff --git a/stepmania/src/SDL_utils.cpp b/stepmania/src/SDL_utils.cpp index d1c5dc60ac..bc61f83c8d 100644 --- a/stepmania/src/SDL_utils.cpp +++ b/stepmania/src/SDL_utils.cpp @@ -509,6 +509,35 @@ bool SDL_GetEvent(SDL_Event &event, int mask) } } +/* For some bizarre reason, SDL_EventState flushes all events. This is a pain, so + * avoid it. */ +Uint8 mySDL_EventState(Uint8 type, int state) +{ + if(state == SDL_QUERY) + return SDL_EventState(type, state); + + vector events; + while(1) + { + SDL_Event ev; + if(SDL_PollEvent(&ev) <= 0) + break; + + /* Don't bother readding it if we're turning this event type off. */ + if(state == SDL_IGNORE && ev.type == type) + continue; + + events.push_back(ev); + } + + Uint8 ret = SDL_EventState(type, state); + + /* Put them back. */ + for(unsigned i = 0; i < events.size(); ++i) + SDL_PushEvent(&events[i]); + + return ret; +} #include "SDL_image.h" // for setting icon #include "SDL_rotozoom.h" // for setting icon diff --git a/stepmania/src/SDL_utils.h b/stepmania/src/SDL_utils.h index e3396b18de..556d2e02b3 100644 --- a/stepmania/src/SDL_utils.h +++ b/stepmania/src/SDL_utils.h @@ -35,6 +35,9 @@ void FixHiddenAlpha(SDL_Surface *img); /* Check for an event; return true if one was waiting. */ bool SDL_GetEvent(SDL_Event &event, int mask); +/* Change the event state without dropping extra events. */ +Uint8 mySDL_EventState(Uint8 type, int state); + /* The surface contains no transparent pixels and/or never uses its color * key, so it doesn't need any alpha bits at all. */ #define TRAIT_NO_TRANSPARENCY 0x0001 /* 0alpha */