Skip to content

Commit d41a494

Browse files
authored
Event handler callback (#14)
* added CMake support * Added callback mechanism for forwarding event handling (e.g. for ImGui)
1 parent b0ef6a4 commit d41a494

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

sdlpp.hpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,10 @@ namespace sdl
490490
inline SDL_Event* get() {
491491
return &e;
492492
}
493-
493+
void setCallback(const std::function<bool(SDL_Event)>& callback_)
494+
{
495+
callback = callback_;
496+
}
494497
bool poll()
495498
{
496499
if (SDL_PollEvent(&e))
@@ -563,8 +566,18 @@ namespace sdl
563566
#undef EVENT
564567
private:
565568
SDL_Event e;
569+
std::function<bool(SDL_Event)> callback;
570+
566571
void handleEvent()
567572
{
573+
if (callback)
574+
{
575+
if (callback(e))
576+
{
577+
//consider handled
578+
return;
579+
}
580+
}
568581
switch (e.type)
569582
{
570583
#define EVENT(x, y, z) \

0 commit comments

Comments
 (0)