summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2021-08-04 19:20:42 (EDT)
committer P. J. McDermott <pj@pehjota.net>2021-08-04 19:29:42 (EDT)
commitf22a8bc2913ff5e927846cd2b2129789bb613398 (patch)
tree5065e5efa1a62a84e6cb11832e4367143ec40a6d /src
parent8cdfd577b4f7d70acddde353b600559010ea6d39 (diff)
downloadmazefight-f22a8bc2913ff5e927846cd2b2129789bb613398.zip
mazefight-f22a8bc2913ff5e927846cd2b2129789bb613398.tar.gz
mazefight-f22a8bc2913ff5e927846cd2b2129789bb613398.tar.bz2
splash: Use mftk
Diffstat (limited to 'src')
-rw-r--r--src/splash.c112
1 files changed, 43 insertions, 69 deletions
diff --git a/src/splash.c b/src/splash.c
index a12a8a0..b7d9185 100644
--- a/src/splash.c
+++ b/src/splash.c
@@ -25,81 +25,59 @@
#include "dirs.h"
#include "maze.h"
#include "splash.h"
+#include "tk.h"
#include "util.h"
-#include "widget.h"
int
mf_splash(SDL_Renderer *renderer)
{
- char *font_path;
- SDL_Color text_color;
- TTF_Font *font;
- SDL_Rect title_rect;
- SDL_Texture *title_texture;
- SDL_Color butn_color;
- SDL_Rect play_btn_rect;
- SDL_Texture *play_btn_texture;
- SDL_Rect form_rect;
- struct mf_maze *maze;
- SDL_Color maze_color;
- SDL_Event event;
+ char *font_path = NULL;
+ TTF_Font *title_font = NULL;
+ TTF_Font *text_font = NULL;
+ SDL_Color text_color;
+ SDL_Color butn_color;
+ struct mftk_widget *grid;
+ struct mf_maze *maze = NULL;
+ SDL_Color maze_color;
+ SDL_Event event;
font_path = mf_strcat(mf_get_fonts_dir(), "/FifteenTwenty-Regular.ttf");
-
- text_color.r = MF_COLOR_FORE_R;
- text_color.g = MF_COLOR_FORE_G;
- text_color.b = MF_COLOR_FORE_B;
- text_color.a = MF_COLOR_FORE_A;
- butn_color.r = MF_COLOR_BUTN_R;
- butn_color.g = MF_COLOR_BUTN_G;
- butn_color.b = MF_COLOR_BUTN_B;
- butn_color.a = MF_COLOR_BUTN_A;
-
- /* Render title text */
- font = TTF_OpenFont(font_path, MF_SPLASH_TITLE_FONT_S);
- if (font == NULL) {
+ title_font = TTF_OpenFont(font_path, MF_SPLASH_TITLE_FONT_S);
+ if (title_font == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"Couldn't open font: %s",
TTF_GetError());
- free(font_path);
- return -1;
- }
- title_texture = mf_widget_text(font, "Maze Fight", &text_color,
- renderer, &title_rect);
- if (title_texture == NULL) {
goto err;
}
- TTF_CloseFont(font);
- font = NULL;
- title_rect.x = (MF_WINDOW_W - title_rect.w) / 2;
- title_rect.y += MF_SPLASH_WINDOW_P + MF_SPLASH_FORM_P;
-
- font = TTF_OpenFont(font_path, MF_SPLASH_TEXT_FONT_S);
- if (font == NULL) {
+ text_font = TTF_OpenFont(font_path, MF_SPLASH_TEXT_FONT_S);
+ if (text_font == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"Couldn't open font: %s",
TTF_GetError());
- free(font_path);
- return -1;
+ goto err;
}
- /* TODO: Widgets */
-
- /* Render play button */
- play_btn_texture = mf_widget_button(font, "Play", &text_color,
- &butn_color, 2, renderer, &play_btn_rect);
- play_btn_rect.x = (MF_WINDOW_W - play_btn_rect.w) / 2;
- play_btn_rect.y += title_rect.y + title_rect.h + MF_SPLASH_TITLE_M;
-
- TTF_CloseFont(font);
- font = NULL;
+ text_color.r = MF_COLOR_FORE_R;
+ text_color.g = MF_COLOR_FORE_G;
+ text_color.b = MF_COLOR_FORE_B;
+ text_color.a = MF_COLOR_FORE_A;
+ butn_color.r = MF_COLOR_BUTN_R;
+ butn_color.g = MF_COLOR_BUTN_G;
+ butn_color.b = MF_COLOR_BUTN_B;
+ butn_color.a = MF_COLOR_BUTN_A;
- /* TODO: Size to widgets and center in window */
- form_rect.x = MF_SPLASH_WINDOW_P;
- form_rect.y = MF_SPLASH_WINDOW_P;
- form_rect.w = MF_WINDOW_W - MF_SPLASH_WINDOW_P*2;
- form_rect.h = MF_WINDOW_H - MF_SPLASH_WINDOW_P*2;
+ grid = mftk_grid_new(2, 1, MF_SPLASH_TITLE_M, 0,
+ mftk_label_new(title_font, "Maze Fight", &text_color,
+ renderer),
+ mftk_button_new(text_font, "Play", &text_color,
+ &butn_color, 2, NULL, NULL, renderer));
+ /* TODO: Widgets */
+ mftk_widget_layout(grid);
+ TTF_CloseFont(title_font);
+ title_font = NULL;
+ TTF_CloseFont(text_font);
+ text_font = NULL;
free(font_path);
font_path = NULL;
@@ -130,19 +108,13 @@ mf_splash(SDL_Renderer *renderer)
SDL_RenderClear(renderer);
mf_maze_render(maze, renderer, &maze_color,
MF_SPLASH_MAZE_CELL_W);
- SDL_SetRenderDrawColor(renderer,
- MF_COLOR_FORM_R, MF_COLOR_FORM_G,
- MF_COLOR_FORM_B, MF_COLOR_FORM_A);
- SDL_RenderFillRect(renderer, &form_rect);
- SDL_RenderCopy(renderer, title_texture, NULL, &title_rect);
- SDL_RenderCopy(renderer, play_btn_texture, NULL,&play_btn_rect);
+ mftk_widget_render(grid, renderer,
+ MF_SPLASH_WINDOW_P, MF_SPLASH_WINDOW_P);
SDL_RenderPresent(renderer);
}
quit:
- SDL_DestroyTexture(title_texture);
- title_texture = NULL;
-
+ mftk_widget_destroy(&grid);
mf_maze_destroy(&maze);
return 0;
@@ -151,11 +123,13 @@ mf_splash(SDL_Renderer *renderer)
if (font_path != NULL) {
free(font_path);
}
- if (font != NULL) {
- TTF_CloseFont(font);
+ if (title_font != NULL) {
+ TTF_CloseFont(title_font);
}
- if (title_texture != NULL) {
- SDL_DestroyTexture(title_texture);
+ if (text_font != NULL) {
+ TTF_CloseFont(text_font);
}
+ mftk_widget_destroy(&grid);
+ mf_maze_destroy(&maze);
return -1;
}