From 1bdb46d3054d7384fc2c0165d805ec1f2f5bc827 Mon Sep 17 00:00:00 2001 From: Milo Turner Date: Tue, 25 Feb 2020 12:26:00 -0500 Subject: [PATCH] [sdl] stub: handle SDL events --- src/backend/sdl.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/backend/sdl.c b/src/backend/sdl.c index a9f6f7b..0f77e64 100644 --- a/src/backend/sdl.c +++ b/src/backend/sdl.c @@ -110,6 +110,7 @@ struct window_args_list { static void load_fonts(struct ax_backend* bac, struct font_list* fl); static void make_windows(struct ax_backend* bac, struct window_args_list* wl); +static void handle_events(void); static void render_windows(struct window_list* wl); void ax__backend_step(struct ax_backend* bac) @@ -168,11 +169,32 @@ void ax__backend_step(struct ax_backend* bac) load_fonts(bac, fonts); make_windows(bac, ax__reverse_list(windows)); render_windows(bac->windows); + handle_events(); rgn_cleanup(&tmp_rgn); // printf("ping. %zu message(s)\n", nmsg); } +/* ----------------------------------------------------------------------------- + * Event handling + * -------------------------------------------------------------------------- */ + +static void handle_events(void) +{ + SDL_Event ev; + while (SDL_PollEvent(&ev)) { + switch (ev.type) { + case SDL_QUIT: + printf("pls quit...\n"); + break; + + default: + printf("some event of type: %d\n", ev.type); + break; + } + } +} + /* ----------------------------------------------------------------------------- * Fonts * -------------------------------------------------------------------------- */ @@ -231,7 +253,7 @@ struct window_handle { SDL_Renderer* rnd; }; -static void cleanup_window_handle(struct window_handle*); +static void window_handle_cleanup(struct window_handle*); static int new_window_handle( struct rgn* rgn, @@ -242,7 +264,7 @@ static int new_window_handle( struct window_handle* wh = ralloc_typed(rgn, struct window_handle, 1); wh->win = NULL; wh->rnd = NULL; - rgn_pin(rgn, wh, (void*) cleanup_window_handle); + rgn_pin(rgn, wh, (void*) window_handle_cleanup); int rv; if ((rv = SDL_CreateWindowAndRenderer((int) args->width, @@ -259,7 +281,7 @@ static int new_window_handle( return 0; } -static void cleanup_window_handle(struct window_handle* wh) +static void window_handle_cleanup(struct window_handle* wh) { SDL_DestroyRenderer(wh->rnd); SDL_DestroyWindow(wh->win);