From 2b2f5aa940f02c15e675c362d9fbd273cf158c86 Mon Sep 17 00:00:00 2001 From: zv0n Date: Tue, 20 Oct 2020 11:43:22 +0200 Subject: [PATCH] SDLPP: Add function for retreiving events that works on all platforms --- sdlpp.cpp | 8 ++++++++ sdlpp.hpp | 1 + 2 files changed, 9 insertions(+) diff --git a/sdlpp.cpp b/sdlpp.cpp index a5fd500..428acb0 100644 --- a/sdlpp.cpp +++ b/sdlpp.cpp @@ -191,3 +191,11 @@ std::tuple< int, int, int, int > SDLPP::getColorsSDLColor( const SDL_Color &color ) { return { color.r, color.g, color.b, color.a }; } + +bool SDLPP::getSDLEvent( SDL_Event &e ) { + if( SDL_PeepEvents(&e, 1, SDL_PEEKEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT) == 1 ) { + SDL_PeepEvents(&e, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT); + return true; + } + return false; +} diff --git a/sdlpp.hpp b/sdlpp.hpp index 8b196b5..ebf7e07 100644 --- a/sdlpp.hpp +++ b/sdlpp.hpp @@ -35,6 +35,7 @@ std::tuple< int, int, int, int > getColorsHEX( const std::string &color ); SDL_Color getSDLColorHEX( const std::string &color ); std::tuple< int, int, int, int > getColorsSDLColor( const SDL_Color &color ); SDL_Color getSDLColorTuple( const std::tuple< int, int, int, int > &tuple ); +bool getSDLEvent( SDL_Event &e ); class Window { public: