From 967ca52d7a1ec98b6b233b63ceeadfe6c2db5e25 Mon Sep 17 00:00:00 2001
From: P. J. McDermott <pj@pehjota.net>
Date: Thu, 05 Aug 2021 15:00:52 -0400
Subject: splash: Split title into separate grid

---
diff --git a/src/splash.c b/src/splash.c
index 93dbc3d..e7ba5b1 100644
--- a/src/splash.c
+++ b/src/splash.c
@@ -82,17 +82,68 @@ _mf_splash_play(void *user_data)
 	return 0;
 }
 
+static struct mftk_widget *
+_mf_splash_form(SDL_Renderer *renderer, const char *font_path,
+		SDL_Color *text_color)
+{
+	TTF_Font           *text_font   = NULL;
+	SDL_Color           butn_color;
+	SDL_Color           chkb_color;
+	SDL_Color           chkm_color;
+	struct mftk_widget *grid;
+
+	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());
+		return NULL;
+	}
+
+	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;
+	chkb_color.r = MF_COLOR_CHKB_R, chkb_color.g = MF_COLOR_CHKB_G;
+	chkb_color.b = MF_COLOR_CHKB_B, chkb_color.a = MF_COLOR_CHKB_A;
+	chkm_color.r = MF_COLOR_CHKM_R, chkm_color.g = MF_COLOR_CHKM_G;
+	chkm_color.b = MF_COLOR_CHKM_B, chkm_color.a = MF_COLOR_CHKM_A;
+
+	grid = mftk_grid_new(4, 1, MF_SPLASH_ROW_M, 0,
+			mftk_radio_new(MF_SPLASH_CHK_BTN_W, MF_SPLASH_CHK_BTN_P,
+				&chkb_color, &chkm_color, MF_SPLASH_CHK_LBL_P,
+				MF_SPLASH_CHK_ITM_P, text_font, text_color,
+				_mf_splash_size, NULL, renderer, 0, 3, "15x15",
+				"20x20", "30x30"),
+			mftk_check_new(MF_SPLASH_CHK_BTN_W, MF_SPLASH_CHK_BTN_P,
+				&chkb_color, &chkm_color, SDL_TRUE,
+				MF_SPLASH_CHK_LBL_P, text_font, "Fog of war",
+				text_color, _mf_splash_fow, NULL, renderer),
+			mftk_check_new(MF_SPLASH_CHK_BTN_W, MF_SPLASH_CHK_BTN_P,
+				&chkb_color, &chkm_color, SDL_FALSE,
+				MF_SPLASH_CHK_LBL_P, text_font, "Reveal maze",
+				text_color, _mf_splash_reveal, NULL, renderer),
+			mftk_grid_new(1, 2, 0, MF_SPLASH_BTN_M,
+				mftk_button_new(text_font, "Quit", text_color,
+					&butn_color, MF_SPLASH_BTN_P,
+					&_mf_splash_quit, NULL, renderer),
+				mftk_button_new(text_font, "Play", text_color,
+					&butn_color, MF_SPLASH_BTN_P,
+					&_mf_splash_play, NULL, renderer)
+				)
+			);
+
+	TTF_CloseFont(text_font);
+	text_font = NULL;
+
+	return grid;
+}
+
 int
 mf_splash(SDL_Renderer *renderer)
 {
 	char               *font_path   = NULL;
 	TTF_Font           *title_font  = NULL;
-	TTF_Font           *text_font   = NULL;
 	SDL_Color           form_color;
 	SDL_Color           text_color;
-	SDL_Color           butn_color;
-	SDL_Color           chkb_color;
-	SDL_Color           chkm_color;
 	struct mftk_widget *box;
 	struct mf_maze     *maze        = NULL;
 	SDL_Color           maze_color;
@@ -106,61 +157,18 @@ mf_splash(SDL_Renderer *renderer)
 				TTF_GetError());
 		goto err;
 	}
-	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());
-		goto err;
-	}
 
 	form_color.r = MF_COLOR_FORM_R, form_color.g = MF_COLOR_FORM_G;
 	form_color.b = MF_COLOR_FORM_B, form_color.a = MF_COLOR_FORM_A;
 	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;
-	chkb_color.r = MF_COLOR_CHKB_R, chkb_color.g = MF_COLOR_CHKB_G;
-	chkb_color.b = MF_COLOR_CHKB_B, chkb_color.a = MF_COLOR_CHKB_A;
-	chkm_color.r = MF_COLOR_CHKM_R, chkm_color.g = MF_COLOR_CHKM_G;
-	chkm_color.b = MF_COLOR_CHKM_B, chkm_color.a = MF_COLOR_CHKM_A;
 
 	box = mftk_box_new(MF_WINDOW_W, MF_WINDOW_H, 0, 0, MF_SPLASH_FORM_P,
-			&form_color,
-			mftk_grid_new(5, 1, MF_SPLASH_TITLE_M, 0,
+			&form_color, mftk_grid_new(2, 1, MF_SPLASH_TITLE_M, 0,
 				mftk_label_new(title_font, "Maze Fight",
 					&text_color, renderer),
-				mftk_radio_new(MF_SPLASH_CHK_BTN_W,
-					MF_SPLASH_CHK_BTN_P, &chkb_color,
-					&chkm_color, MF_SPLASH_CHK_LBL_P,
-					MF_SPLASH_CHK_ITM_P, text_font,
-					&text_color, _mf_splash_size, NULL,
-					renderer, 0, 3, "15x15", "20x20",
-					"30x30"),
-				mftk_check_new(MF_SPLASH_CHK_BTN_W,
-					MF_SPLASH_CHK_BTN_P, &chkb_color,
-					&chkm_color, SDL_TRUE,
-					MF_SPLASH_CHK_LBL_P, text_font,
-					"Fog of war", &text_color,
-					_mf_splash_fow, NULL, renderer),
-				mftk_check_new(MF_SPLASH_CHK_BTN_W,
-					MF_SPLASH_CHK_BTN_P, &chkb_color,
-					&chkm_color, SDL_FALSE,
-					MF_SPLASH_CHK_LBL_P, text_font,
-					"Reveal maze", &text_color,
-					_mf_splash_reveal, NULL, renderer),
-				mftk_grid_new(1, 2, 0, MF_SPLASH_BTN_M,
-					mftk_button_new(text_font, "Quit",
-						&text_color, &butn_color,
-						MF_SPLASH_BTN_P,
-						&_mf_splash_quit, NULL,
-						renderer),
-					mftk_button_new(text_font, "Play",
-						&text_color, &butn_color,
-						MF_SPLASH_BTN_P,
-						&_mf_splash_play, NULL,
-						renderer)
-					)
+				_mf_splash_form(renderer, font_path,
+					&text_color)
 				)
 			);
 	/* TODO: Widgets */
@@ -168,8 +176,6 @@ mf_splash(SDL_Renderer *renderer)
 
 	TTF_CloseFont(title_font);
 	title_font = NULL;
-	TTF_CloseFont(text_font);
-	text_font = NULL;
 	free(font_path);
 	font_path = NULL;
 
@@ -218,9 +224,6 @@ mf_splash(SDL_Renderer *renderer)
 	if (title_font != NULL) {
 		TTF_CloseFont(title_font);
 	}
-	if (text_font != NULL) {
-		TTF_CloseFont(text_font);
-	}
 	mftk_widget_destroy(&box);
 	mf_maze_destroy(&maze);
 	return -1;
--
cgit v0.9.1