From fc8446c9c6cb702a56fb275a56706f80dba75d6f Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Thu, 18 Mar 2021 16:55:55 -0400 Subject: main-menu: Even more title text refactoring --- (limited to 'src') diff --git a/src/main-menu.c b/src/main-menu.c index 07a1302..7ac9157 100644 --- a/src/main-menu.c +++ b/src/main-menu.c @@ -27,19 +27,12 @@ #include "util.h" static SDL_Texture * -_db_main_menu_title(const char *font_path, SDL_Color *color, +_db_main_menu_title(TTF_Font *font, SDL_Color *color, SDL_Renderer *renderer, SDL_Rect *rect) { - TTF_Font *font; SDL_Surface *surface; SDL_Texture *texture; - font = TTF_OpenFont(font_path, 48); - if (font == NULL) { - db_err("Failed to open font (%s)", TTF_GetError()); - return NULL; - } - surface = TTF_RenderText_Blended(font, "Dodge Balls", *color); if (surface == NULL) { db_err("Failed to create surface (%s)", TTF_GetError()); @@ -56,7 +49,6 @@ _db_main_menu_title(const char *font_path, SDL_Color *color, rect->h = surface->h; SDL_FreeSurface(surface); - TTF_CloseFont(font); return texture; } @@ -69,6 +61,7 @@ db_main_menu(void) SDL_Renderer *renderer; SDL_Color text_color; SDL_Rect dest_rect; + TTF_Font *font; SDL_Texture *texture_title; struct db_game **games; int n; @@ -89,10 +82,18 @@ db_main_menu(void) text_color.a = 0xFF; /* Render title text */ - texture_title = _db_main_menu_title(font_path, &text_color, renderer, + font = TTF_OpenFont(font_path, 48); + if (font == NULL) { + db_err("Failed to open font (%s)", TTF_GetError()); + free(font_path); + return; + } + texture_title = _db_main_menu_title(font, &text_color, renderer, &dest_rect); if (texture_title == NULL) { - goto out; + free(font_path); + TTF_CloseFont(font); + return; } dest_rect.x = 16; dest_rect.y = 16; @@ -114,6 +115,6 @@ db_main_menu(void) SDL_RenderPresent(renderer); SDL_Delay(1000); - out: free(font_path); + TTF_CloseFont(font); } -- cgit v0.9.1