Add SDL 2.0 compatibility.
Replaced events::discard with SDL_FlushEvent for SDL 2.0 and added SDL_FlushEvent emulation for SDL 1.2.
This commit is contained in:
parent
42b54cc9a9
commit
032ce3a27f
3 changed files with 43 additions and 28 deletions
|
@ -454,31 +454,6 @@ void raise_help_string_event(int mousex, int mousey)
|
|||
}
|
||||
}
|
||||
|
||||
int discard(Uint32 event_mask)
|
||||
{
|
||||
int discard_count = 0;
|
||||
SDL_Event temp_event;
|
||||
std::vector< SDL_Event > keepers;
|
||||
SDL_Delay(10);
|
||||
while(SDL_PollEvent(&temp_event) > 0) {
|
||||
if((SDL_EVENTMASK(temp_event.type) & event_mask) == 0) {
|
||||
keepers.push_back( temp_event );
|
||||
} else {
|
||||
++discard_count;
|
||||
}
|
||||
}
|
||||
|
||||
//FIXME: there is a chance new events are added before kept events are replaced
|
||||
for (unsigned int i=0; i < keepers.size(); ++i)
|
||||
{
|
||||
if(SDL_PushEvent(&keepers[i]) != 0) {
|
||||
ERR_GEN << "failed to return an event to the queue.";
|
||||
}
|
||||
}
|
||||
|
||||
return discard_count;
|
||||
}
|
||||
|
||||
int pump_info::ticks(unsigned *refresh_counter, unsigned refresh_rate) {
|
||||
if(!ticks_ && !(refresh_counter && ++*refresh_counter % refresh_rate)) {
|
||||
ticks_ = ::SDL_GetTicks();
|
||||
|
@ -516,6 +491,26 @@ bool is_input(const SDL_Event& event)
|
|||
return SDL_EVENTMASK(event.type) & INPUT_MASK;
|
||||
}
|
||||
|
||||
static void discard(Uint32 event_mask)
|
||||
{
|
||||
SDL_Event temp_event;
|
||||
std::vector< SDL_Event > keepers;
|
||||
SDL_Delay(10);
|
||||
while(SDL_PollEvent(&temp_event) > 0) {
|
||||
if((SDL_EVENTMASK(temp_event.type) & event_mask) == 0) {
|
||||
keepers.push_back( temp_event );
|
||||
}
|
||||
}
|
||||
|
||||
//FIXME: there is a chance new events are added before kept events are replaced
|
||||
for (unsigned int i=0; i < keepers.size(); ++i)
|
||||
{
|
||||
if(SDL_PushEvent(&keepers[i]) != 0) {
|
||||
ERR_GEN << "failed to return an event to the queue.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void discard_input()
|
||||
{
|
||||
discard(INPUT_MASK);
|
||||
|
@ -524,3 +519,12 @@ void discard_input()
|
|||
#endif
|
||||
|
||||
} //end events namespace
|
||||
|
||||
#if !SDL_VERSION_ATLEAST(2,0,0)
|
||||
|
||||
void SDL_FlushEvent(Uint32 type)
|
||||
{
|
||||
events::discard(SDL_EVENTMASK(type));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -106,8 +106,6 @@ public:
|
|||
virtual void process(pump_info& info) = 0;
|
||||
};
|
||||
|
||||
int discard(Uint32 event_mask);
|
||||
|
||||
void raise_process_event();
|
||||
void raise_draw_event();
|
||||
void raise_volatile_draw_event();
|
||||
|
@ -129,4 +127,17 @@ void discard_input();
|
|||
|
||||
typedef std::vector<events::handler*> handler_vector;
|
||||
|
||||
#if ! SDL_VERSION_ATLEAST(2,0,0)
|
||||
|
||||
/**
|
||||
* Removes events from the queue.
|
||||
*
|
||||
* This emulates the function available in SDL 2.0.
|
||||
*
|
||||
* @param type The type of event to flush.
|
||||
*/
|
||||
void SDL_FlushEvent(Uint32 type);
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -62,7 +62,7 @@ bool tdialog::show(CVideo& video, const unsigned auto_close_time)
|
|||
* to avoid that problem, filter all pending DOUBLE_CLICK_EVENT events after
|
||||
* the window is closed.
|
||||
*/
|
||||
events::discard(SDL_EVENTMASK(DOUBLE_CLICK_EVENT));
|
||||
SDL_FlushEvent(DOUBLE_CLICK_EVENT);
|
||||
|
||||
finalize_fields(*window, (retval_ == twindow::OK || always_save_fields_));
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue