add mySDL_GetAllEvents and mySDL_PushEvents
This commit is contained in:
+33
-14
@@ -508,6 +508,26 @@ bool SDL_GetEvent(SDL_Event &event, int mask)
|
|||||||
default: RageException::Throw("SDL_PeepEvents returned unexpected error: %s", SDL_GetError());
|
default: RageException::Throw("SDL_PeepEvents returned unexpected error: %s", SDL_GetError());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#include "RageLog.h"
|
||||||
|
/* Reads all currently queued SDL events, clearing them from the queue. */
|
||||||
|
void mySDL_GetAllEvents(vector<SDL_Event> &events)
|
||||||
|
{
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
SDL_Event ev;
|
||||||
|
if(SDL_PollEvent(&ev) <= 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
events.push_back(ev);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Pushes the given events onto the SDL event queue. */
|
||||||
|
void mySDL_PushEvents(vector<SDL_Event> &events)
|
||||||
|
{
|
||||||
|
for(unsigned i = 0; i < events.size(); ++i)
|
||||||
|
LOG->Trace("push ev %i: %i", events[i].type, SDL_PushEvent(&events[i]));
|
||||||
|
}
|
||||||
|
|
||||||
/* For some bizarre reason, SDL_EventState flushes all events. This is a pain, so
|
/* For some bizarre reason, SDL_EventState flushes all events. This is a pain, so
|
||||||
* avoid it. */
|
* avoid it. */
|
||||||
@@ -517,24 +537,23 @@ Uint8 mySDL_EventState(Uint8 type, int state)
|
|||||||
return SDL_EventState(type, state);
|
return SDL_EventState(type, state);
|
||||||
|
|
||||||
vector<SDL_Event> events;
|
vector<SDL_Event> events;
|
||||||
while(1)
|
mySDL_GetAllEvents(events);
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/* Set the event mask. */
|
||||||
Uint8 ret = SDL_EventState(type, state);
|
Uint8 ret = SDL_EventState(type, state);
|
||||||
|
|
||||||
|
/* Don't readding events that we just turned off; they'll just sit around
|
||||||
|
* in the buffer. */
|
||||||
|
for(unsigned i = 0; i < events.size(); )
|
||||||
|
{
|
||||||
|
if(state == SDL_IGNORE && events[i].type == type)
|
||||||
|
events.erase(events.begin()+i);
|
||||||
|
else
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
/* Put them back. */
|
/* Put them back. */
|
||||||
for(unsigned i = 0; i < events.size(); ++i)
|
mySDL_PushEvents(events);
|
||||||
SDL_PushEvent(&events[i]);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,9 @@ bool SDL_GetEvent(SDL_Event &event, int mask);
|
|||||||
/* Change the event state without dropping extra events. */
|
/* Change the event state without dropping extra events. */
|
||||||
Uint8 mySDL_EventState(Uint8 type, int state);
|
Uint8 mySDL_EventState(Uint8 type, int state);
|
||||||
|
|
||||||
|
void mySDL_GetAllEvents(vector<SDL_Event> &events);
|
||||||
|
void mySDL_PushEvents(vector<SDL_Event> &events);
|
||||||
|
|
||||||
/* The surface contains no transparent pixels and/or never uses its color
|
/* The surface contains no transparent pixels and/or never uses its color
|
||||||
* key, so it doesn't need any alpha bits at all. */
|
* key, so it doesn't need any alpha bits at all. */
|
||||||
#define TRAIT_NO_TRANSPARENCY 0x0001 /* 0alpha */
|
#define TRAIT_NO_TRANSPARENCY 0x0001 /* 0alpha */
|
||||||
|
|||||||
Reference in New Issue
Block a user