summaryrefslogtreecommitdiffstats
path: root/src/main-menu.c
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2021-03-18 16:46:34 (EDT)
committer P. J. McDermott <pj@pehjota.net>2021-03-18 16:48:06 (EDT)
commit778519f359332f7338d8ae7a6b20b394e8a092f9 (patch)
tree76163caf68a16297212db1a776592b2d426c0c4b /src/main-menu.c
parent24468c113cb7a3fd2ed6089793e25015ea7c7c39 (diff)
downloaddodge-balls-778519f359332f7338d8ae7a6b20b394e8a092f9.zip
dodge-balls-778519f359332f7338d8ae7a6b20b394e8a092f9.tar.gz
dodge-balls-778519f359332f7338d8ae7a6b20b394e8a092f9.tar.bz2
main-menu: More title text refactoring
Diffstat (limited to 'src/main-menu.c')
-rw-r--r--src/main-menu.c56
1 files changed, 33 insertions, 23 deletions
diff --git a/src/main-menu.c b/src/main-menu.c
index 58f0a5d..07a1302 100644
--- a/src/main-menu.c
+++ b/src/main-menu.c
@@ -26,46 +26,39 @@
#include "output.h"
#include "util.h"
-static void
-_db_main_menu_title(const char *font_path, SDL_Renderer *renderer)
+static SDL_Texture *
+_db_main_menu_title(const char *font_path, SDL_Color *color,
+ SDL_Renderer *renderer, SDL_Rect *rect)
{
- SDL_Color color;
- TTF_Font *font;
- SDL_Surface *surface;
- SDL_Texture *texture;
- SDL_Rect rect;
-
- color.r = 0x00;
- color.g = 0x00;
- color.b = 0xFF;
- color.a = 0xFF;
+ 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;
+ return NULL;
}
- surface = TTF_RenderText_Blended(font, "Dodge Balls", color);
+ surface = TTF_RenderText_Blended(font, "Dodge Balls", *color);
if (surface == NULL) {
db_err("Failed to create surface (%s)", TTF_GetError());
- return;
+ return NULL;
}
texture = SDL_CreateTextureFromSurface(renderer, surface);
if (texture == NULL) {
db_err("Failed to create texture (%s)", SDL_GetError());
- return;
+ return NULL;
}
- rect.x = 16;
- rect.y = 16;
- rect.w = surface->w;
- rect.h = surface->h;
- SDL_RenderCopy(renderer, texture, NULL, &rect);
+ rect->w = surface->w;
+ rect->h = surface->h;
- SDL_DestroyTexture(texture);
SDL_FreeSurface(surface);
+ TTF_CloseFont(font);
+
+ return texture;
}
void
@@ -74,6 +67,9 @@ db_main_menu(void)
const char *games_dir;
char *font_path;
SDL_Renderer *renderer;
+ SDL_Color text_color;
+ SDL_Rect dest_rect;
+ SDL_Texture *texture_title;
struct db_game **games;
int n;
int i;
@@ -87,8 +83,21 @@ db_main_menu(void)
SDL_SetRenderDrawColor(renderer, 0x7F, 0x7F, 0x7F, 0xFF);
SDL_RenderClear(renderer);
+ text_color.r = 0x00;
+ text_color.g = 0x00;
+ text_color.b = 0xFF;
+ text_color.a = 0xFF;
+
/* Render title text */
- _db_main_menu_title(font_path, renderer);
+ texture_title = _db_main_menu_title(font_path, &text_color, renderer,
+ &dest_rect);
+ if (texture_title == NULL) {
+ goto out;
+ }
+ dest_rect.x = 16;
+ dest_rect.y = 16;
+ SDL_RenderCopy(renderer, texture_title, NULL, &dest_rect);
+ SDL_DestroyTexture(texture_title);
/* Find games */
n = db_games_find(games_dir, &games);
@@ -105,5 +114,6 @@ db_main_menu(void)
SDL_RenderPresent(renderer);
SDL_Delay(1000);
+ out:
free(font_path);
}