mirror of
https://github.com/libSDL2pp/libSDL2pp.git
synced 2025-08-04 03:15:59 -04:00
Added EventWait code (definitions/logic)
This commit is contained in:
parent
648754505f
commit
c641f5602b
@ -21,7 +21,33 @@
|
|||||||
|
|
||||||
#include <SDL2pp/EventWait.hh>
|
#include <SDL2pp/EventWait.hh>
|
||||||
|
|
||||||
|
#include <SDL2pp/Exception.hh>
|
||||||
|
|
||||||
namespace SDL2pp {
|
namespace SDL2pp {
|
||||||
namespace Event {
|
namespace Event {
|
||||||
|
SDL_Event WaitEvent() {
|
||||||
|
SDL_Event result;
|
||||||
|
if (SDL_WaitEvent(&result) == 0) {
|
||||||
|
throw Exception("SDL_WaitEvent");
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
Optional<SDL_Event> WaitEvent(int timeout) {
|
||||||
|
SDL_Event result;
|
||||||
|
SDL_ClearError(); // Necessary to ensure SDL_WaitEventTimeout
|
||||||
|
// returned with no errors
|
||||||
|
if (SDL_WaitEventTimeout(&result, timeout) == 0) {
|
||||||
|
auto error = SDL_GetError();
|
||||||
|
// Check if the error message is empty
|
||||||
|
if (*error == 0) {
|
||||||
|
return Optional<SDL_Event>();
|
||||||
|
} else {
|
||||||
|
throw Exception("SDL_WaitEventTimeout");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,13 @@
|
|||||||
|
|
||||||
#include <SDL_events.h>
|
#include <SDL_events.h>
|
||||||
|
|
||||||
|
#include <SDL2pp/Optional.hh>
|
||||||
|
|
||||||
namespace SDL2pp {
|
namespace SDL2pp {
|
||||||
namespace Event {
|
namespace Event {
|
||||||
|
SDL_Event WaitEvent();
|
||||||
|
|
||||||
|
Optional<SDL_Event> WaitEvent(int timeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user