Skip to content

Instantly share code, notes, and snippets.

@startling
Created May 20, 2012 05:54
Show Gist options
  • Save startling/2753590 to your computer and use it in GitHub Desktop.
Save startling/2753590 to your computer and use it in GitHub Desktop.
#include <sdl.h>
void event_loop(void (*on_keydown)(char), void (*on_loop)()) {
/* Given a function pointer to call on each new keypress, catch keypresses
* and pass them to it.
*
* TODO: a callback on quit. */
SDL_Event event;
int cont = 1;
while (cont) {
while (SDL_PollEvent(&event)) {
switch(event.type){
case SDL_KEYDOWN:
(*on_keydown)(event.key.keysym.sym);
break;
case SDL_QUIT:
cont = 0;
puts("Quitting.");
break;
}
}
(*on_loop)();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment