From aaa7d7f6b08ecfcc3797683ddad892031f3de8d4 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Thu, 18 Mar 2021 15:28:20 -0400 Subject: main-menu: Render title text --- (limited to 'src/main-menu.c') diff --git a/src/main-menu.c b/src/main-menu.c index f3e46bf..01af44e 100644 --- a/src/main-menu.c +++ b/src/main-menu.c @@ -24,6 +24,7 @@ #include "main-menu.h" #include "main.h" #include "output.h" +#include "util.h" void db_main_menu(void) @@ -33,6 +34,11 @@ 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; @@ -44,6 +50,38 @@ db_main_menu(void) renderer = db_get_renderer(); texture = db_get_texture(); + /* Render background */ + SDL_SetRenderDrawColor(renderer, 0x7F, 0x7F, 0x7F, 0xFF); + 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); + /* Find games */ n = db_games_find(games_dir, &games); if (n > 0) { @@ -56,8 +94,9 @@ db_main_menu(void) free(games); } - SDL_SetRenderDrawColor(renderer, 0x7F, 0x7F, 0x7F, 0xFF); - SDL_RenderClear(renderer); SDL_RenderPresent(renderer); SDL_Delay(1000); + + SDL_DestroyTexture(text_texture); + SDL_FreeSurface(text_surface); } -- cgit v0.9.1