Skip to content

Commit

Permalink
Event handler callback (#14)
Browse files Browse the repository at this point in the history
* added CMake support

* Added callback mechanism for forwarding event handling (e.g. for ImGui)
  • Loading branch information
psyinf authored Jun 5, 2024
1 parent b0ef6a4 commit d41a494
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion sdlpp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,10 @@ namespace sdl
inline SDL_Event* get() {
return &e;
}

void setCallback(const std::function<bool(SDL_Event)>& callback_)
{
callback = callback_;
}
bool poll()
{
if (SDL_PollEvent(&e))
Expand Down Expand Up @@ -563,8 +566,18 @@ namespace sdl
#undef EVENT
private:
SDL_Event e;
std::function<bool(SDL_Event)> callback;

void handleEvent()
{
if (callback)
{
if (callback(e))
{
//consider handled
return;
}
}
switch (e.type)
{
#define EVENT(x, y, z) \
Expand Down

0 comments on commit d41a494

Please sign in to comment.