summaryrefslogtreecommitdiffstats
path: root/src/main-menu.c
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2021-03-18 16:27:03 (EDT)
committer P. J. McDermott <pj@pehjota.net>2021-03-18 16:27:03 (EDT)
commita100ac901dd85a2f7152e5c8376f6ca1cdb0d56c (patch)
treec699b688666aa6356e7fe9c66563156ce3cf517b /src/main-menu.c
parentaaa7d7f6b08ecfcc3797683ddad892031f3de8d4 (diff)
downloaddodge-balls-a100ac901dd85a2f7152e5c8376f6ca1cdb0d56c.zip
dodge-balls-a100ac901dd85a2f7152e5c8376f6ca1cdb0d56c.tar.gz
dodge-balls-a100ac901dd85a2f7152e5c8376f6ca1cdb0d56c.tar.bz2
main-menu: Factor title text rendering into new fn
Diffstat (limited to 'src/main-menu.c')
-rw-r--r--src/main-menu.c78
1 files changed, 44 insertions, 34 deletions
diff --git a/src/main-menu.c b/src/main-menu.c
index 01af44e..6dae575 100644
--- a/src/main-menu.c
+++ b/src/main-menu.c
@@ -26,6 +26,49 @@
#include "output.h"
#include "util.h"
+static void
+_db_main_menu_title(const char *fonts_dir, SDL_Renderer *renderer)
+{
+ 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;
+
+ font = TTF_OpenFont(
+ db_strcat(fonts_dir, "/UbuntuTitling-Bold.ttf"), 48);
+ if (font == NULL) {
+ db_err("Failed to open font (%s)", TTF_GetError());
+ return;
+ }
+
+ surface = TTF_RenderText_Blended(font, "Dodge Balls", color);
+ if (surface == NULL) {
+ db_err("Failed to create surface (%s)", TTF_GetError());
+ return;
+ }
+
+ texture = SDL_CreateTextureFromSurface(renderer, surface);
+ if (texture == NULL) {
+ db_err("Failed to create texture (%s)", SDL_GetError());
+ return;
+ }
+
+ rect.x = 16;
+ rect.y = 16;
+ rect.w = surface->w;
+ rect.h = surface->h;
+ SDL_RenderCopy(renderer, texture, NULL, &rect);
+
+ SDL_DestroyTexture(texture);
+ SDL_FreeSurface(surface);
+}
+
void
db_main_menu(void)
{
@@ -34,11 +77,6 @@ db_main_menu(void)
SDL_Window *window;
SDL_Renderer *renderer;
SDL_Texture *texture;
- SDL_Color text_color;
- TTF_Font *font;
- SDL_Surface *text_surface;
- SDL_Texture *text_texture;
- SDL_Rect dest_rect;
struct db_game **games;
int n;
int i;
@@ -55,32 +93,7 @@ db_main_menu(void)
SDL_RenderClear(renderer);
/* Render title text */
- text_color.r = 0x00;
- text_color.g = 0x00;
- text_color.b = 0xFF;
- text_color.a = 0xFF;
- font = TTF_OpenFont(
- db_strcat(fonts_dir, "/UbuntuTitling-Bold.ttf"), 48);
- if (font == NULL) {
- db_err("Failed to open font (%s)", TTF_GetError());
- return;
- }
- text_surface = TTF_RenderText_Blended(font, "Dodge Balls",
- text_color);
- if (text_surface == NULL) {
- db_err("Failed to create surface (%s)", TTF_GetError());
- return;
- }
- text_texture = SDL_CreateTextureFromSurface(renderer, text_surface);
- if (text_texture == NULL) {
- db_err("Failed to create texture (%s)", SDL_GetError());
- return;
- }
- dest_rect.x = 16;
- dest_rect.y = 16;
- dest_rect.w = text_surface->w;
- dest_rect.h = text_surface->h;
- SDL_RenderCopy(renderer, text_texture, NULL, &dest_rect);
+ _db_main_menu_title(fonts_dir, renderer);
/* Find games */
n = db_games_find(games_dir, &games);
@@ -96,7 +109,4 @@ db_main_menu(void)
SDL_RenderPresent(renderer);
SDL_Delay(1000);
-
- SDL_DestroyTexture(text_texture);
- SDL_FreeSurface(text_surface);
}