From f087754cccb3c2b8b4b820b683ef09483e73de82 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Sat, 20 Mar 2021 15:33:06 -0400 Subject: main-menu: Add second user data parameter --- (limited to 'src/main-menu.c') diff --git a/src/main-menu.c b/src/main-menu.c index f1f05c3..0fbb8c8 100644 --- a/src/main-menu.c +++ b/src/main-menu.c @@ -41,8 +41,9 @@ struct _db_main_menu_button { struct _db_main_menu_button *r; struct _db_main_menu_button *p; struct _db_main_menu_button *n; - int (*action)(void *); - void *user_data; + int (*action)(void *, void *); + void *user_data_1; + void *user_data_2; }; static SDL_Texture * @@ -73,17 +74,19 @@ _db_main_menu_text(TTF_Font *font, const char *text, SDL_Color *color, } static int -_db_main_menu_action_help(void *user_data __attribute__((__unused__))) +_db_main_menu_action_help(void *user_data_1, + void *user_data_2 __attribute__((__unused__))) { SDL_Window *window; - window = user_data; + window = user_data_1; return db_help(window); } static int -_db_main_menu_action_quit(void *user_data __attribute__((__unused__))) +_db_main_menu_action_quit(void *user_data_1 __attribute__((__unused__)), + void *user_data_2 __attribute__((__unused__))) { _db_main_menu_quit = 1; @@ -91,11 +94,11 @@ _db_main_menu_action_quit(void *user_data __attribute__((__unused__))) } static int -_db_main_menu_action_game(void *user_data) +_db_main_menu_action_game(void *user_data_1, void *user_data_2) { struct db_game *game; - game = user_data; + game = user_data_2; db_dbg("Loading game \"%s\"", db_game_get_name(game)); @@ -191,7 +194,8 @@ db_main_menu(SDL_Window *window) buttons[0]->rect.x = DB_WINDOW_W - DB_WINDOW_P - buttons[0]->rect.w; buttons[0]->rect.y = DB_WINDOW_P; buttons[0]->action = &_db_main_menu_action_help; - buttons[0]->user_data = window; + buttons[0]->user_data_1 = window; + buttons[0]->user_data_2 = NULL; /* Render quit button */ buttons[1] = malloc(sizeof(**buttons)); @@ -212,7 +216,8 @@ db_main_menu(SDL_Window *window) buttons[1]->rect.x = DB_WINDOW_W - DB_WINDOW_P - buttons[1]->rect.w; buttons[1]->rect.y = DB_WINDOW_P + DB_FONT_TEXT_SIZE + DB_MARGIN; buttons[1]->action = &_db_main_menu_action_quit; - buttons[1]->user_data = NULL; + buttons[1]->user_data_1 = NULL; + buttons[1]->user_data_2 = NULL; /* Render game buttons */ buttons[1]->n = buttons[0]; /* Quit button link (may change below) */ @@ -259,7 +264,8 @@ db_main_menu(SDL_Window *window) buttons[i + 2]->p = buttons[i + 1]; buttons[i + 1]->n = buttons[i + 2]; buttons[i + 2]->action = &_db_main_menu_action_game; - buttons[i + 2]->user_data = games[i]; + buttons[i + 2]->user_data_1 = games[i]; + buttons[i + 2]->user_data_2 = games[i]; } if (n > 0) { buttons[2]->u = NULL; @@ -341,7 +347,9 @@ db_main_menu(SDL_Window *window) case SDLK_RETURN: case SDLK_KP_ENTER: if (active->action(active-> - user_data) + user_data_1, + active-> + user_data_2) != 0) { _db_main_menu_quit = 2; @@ -372,7 +380,9 @@ db_main_menu(SDL_Window *window) if (db_pt_in_rect(event.button.x, event.button.y, &active->rect)) { - if (active->action(active->user_data) != + if (active->action(active->user_data_1, + active-> + user_data_2) != 0) { _db_main_menu_quit = 2; } -- cgit v0.9.1