diff options
author | P. J. McDermott <pj@pehjota.net> | 2021-08-07 13:27:35 (EDT) |
---|---|---|
committer | P. J. McDermott <pj@pehjota.net> | 2021-08-07 13:44:18 (EDT) |
commit | 9d9d9fb9eab0213cd305f53a887628a2aca2c365 (patch) | |
tree | da6b8eadab80b51c20f6cb348ab949297b87330e | |
parent | b94641a84956bd45398980aad48ead89d0fcc275 (diff) | |
download | mazefight-9d9d9fb9eab0213cd305f53a887628a2aca2c365.zip mazefight-9d9d9fb9eab0213cd305f53a887628a2aca2c365.tar.gz mazefight-9d9d9fb9eab0213cd305f53a887628a2aca2c365.tar.bz2 |
menu: Improve quit handling; free strings earlier
-rw-r--r-- | src/menu.c | 28 |
1 files changed, 14 insertions, 14 deletions
@@ -38,7 +38,6 @@ struct _mf_menu { int size; int fow; int reveal; - int quit; }; static int @@ -82,13 +81,9 @@ _mf_menu_reveal(void *user_data, int state) } static int -_mf_menu_quit(void *user_data) +_mf_menu_quit(void *user_data __attribute__((__unused__))) { - struct _mf_menu *menu = (struct _mf_menu *) user_data; - - menu->quit = SDL_TRUE; - - return 0; + return 1; } static int @@ -166,7 +161,7 @@ _mf_menu_form(SDL_Renderer *renderer, TTF_Font *text_font, mftk_grid_new(1, 2, 0, MF_SPLASH_BTN_M, mftk_button_new(text_font, "Quit", text_color, &butn_color, MF_SPLASH_BTN_P, - &_mf_menu_quit, menu, renderer), + &_mf_menu_quit, NULL, renderer), MFTK_GRID_HALIGN_L|MFTK_GRID_VALIGN_T, mftk_button_new(text_font, "Play", text_color, &butn_color, MF_SPLASH_BTN_P, @@ -176,6 +171,8 @@ _mf_menu_form(SDL_Renderer *renderer, TTF_Font *text_font, MFTK_GRID_HALIGN_L|MFTK_GRID_VALIGN_T ); + free(seed_buf); + return grid; } @@ -209,7 +206,6 @@ mf_menu(SDL_Renderer *renderer) menu.size = 15; menu.fow = SDL_TRUE; menu.reveal = SDL_FALSE; - menu.quit = SDL_FALSE; font_path = mf_strcat(mf_get_fonts_dir(), "/FifteenTwenty-Regular.ttf"); title_font = TTF_OpenFont(font_path, MF_SPLASH_TITLE_FONT_S); @@ -226,6 +222,8 @@ mf_menu(SDL_Renderer *renderer) TTF_GetError()); goto err; } + free(font_path); + font_path = NULL; form_color.r = MF_COLOR_FORM_R, form_color.g = MF_COLOR_FORM_G; form_color.b = MF_COLOR_FORM_B, form_color.a = MF_COLOR_FORM_A; @@ -247,8 +245,6 @@ mf_menu(SDL_Renderer *renderer) TTF_CloseFont(title_font); title_font = NULL; - free(font_path); - font_path = NULL; SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND); @@ -266,9 +262,13 @@ mf_menu(SDL_Renderer *renderer) default: break; } - mftk_window_event(win, &event); - if (menu.quit) { - goto quit; + switch (mftk_window_event(win, &event)) { + case 0: + break; + case 1: + goto quit; + default: + goto err; } SDL_SetRenderDrawColor(renderer, MF_COLOR_BACK_R, MF_COLOR_BACK_G, |