summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2021-03-18 16:55:55 (EDT)
committer P. J. McDermott <pj@pehjota.net>2021-03-18 16:55:55 (EDT)
commitfc8446c9c6cb702a56fb275a56706f80dba75d6f (patch)
treef6372be70f085e53bcdadaf086ee45feb7fdbfcd /src
parent778519f359332f7338d8ae7a6b20b394e8a092f9 (diff)
downloaddodge-balls-fc8446c9c6cb702a56fb275a56706f80dba75d6f.zip
dodge-balls-fc8446c9c6cb702a56fb275a56706f80dba75d6f.tar.gz
dodge-balls-fc8446c9c6cb702a56fb275a56706f80dba75d6f.tar.bz2
main-menu: Even more title text refactoring
Diffstat (limited to 'src')
-rw-r--r--src/main-menu.c25
1 files changed, 13 insertions, 12 deletions
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);
}