summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2021-03-19 18:36:14 (EDT)
committer P. J. McDermott <pj@pehjota.net>2021-03-19 18:36:14 (EDT)
commit8e15eccb7de2d93268672fb6c6631a76c410d580 (patch)
tree77372fb8bd1cc70ca71d3ca19c56d9e0b17d167c
parent5321cad3318c93653522fc03f1d9a1995b39e53b (diff)
downloaddodge-balls-8e15eccb7de2d93268672fb6c6631a76c410d580.zip
dodge-balls-8e15eccb7de2d93268672fb6c6631a76c410d580.tar.gz
dodge-balls-8e15eccb7de2d93268672fb6c6631a76c410d580.tar.bz2
main-menu, help: Take window pointer parameter
-rw-r--r--src/help.c8
-rw-r--r--src/help.h4
-rw-r--r--src/main-menu.c16
-rw-r--r--src/main-menu.h4
-rw-r--r--src/main.c14
-rw-r--r--src/main.h4
6 files changed, 25 insertions, 25 deletions
diff --git a/src/help.c b/src/help.c
index 3e3d365..3195615 100644
--- a/src/help.c
+++ b/src/help.c
@@ -88,7 +88,7 @@ _db_help_triangle(SDL_Renderer *renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a,
}
int
-db_help(void)
+db_help(SDL_Window *window)
{
char *font_path;
SDL_Renderer *renderer;
@@ -106,7 +106,11 @@ db_help(void)
font_path = db_strcat(db_get_fonts_dir(), "/UbuntuTitling-Bold.ttf");
- renderer = db_get_renderer();
+ renderer = SDL_GetRenderer(window);
+ if (renderer == NULL) {
+ db_err("Failed to get renderer (%s)", SDL_GetError());
+ return -1;
+ }
font = TTF_OpenFont(font_path, DB_FONT_TEXT_SIZE);
if (font == NULL) {
diff --git a/src/help.h b/src/help.h
index 8f3acc0..03b4fa6 100644
--- a/src/help.h
+++ b/src/help.h
@@ -20,6 +20,8 @@
#ifndef DB_HELP_H_
#define DB_HELP_H_
-int db_help(void);
+#include <SDL.h>
+
+int db_help(SDL_Window *window);
#endif /* DB_HELP_H_ */
diff --git a/src/main-menu.c b/src/main-menu.c
index 0bd135d..74f8bff 100644
--- a/src/main-menu.c
+++ b/src/main-menu.c
@@ -75,7 +75,11 @@ _db_main_menu_text(TTF_Font *font, const char *text, SDL_Color *color,
static int
_db_main_menu_action_help(void *user_data __attribute__((__unused__)))
{
- return db_help();
+ SDL_Window *window;
+
+ window = user_data;
+
+ return db_help(window);
}
static int
@@ -99,7 +103,7 @@ _db_main_menu_action_game(void *user_data)
}
int
-db_main_menu(void)
+db_main_menu(SDL_Window *window)
{
const char *games_dir;
char *font_path;
@@ -120,7 +124,11 @@ db_main_menu(void)
games_dir = db_get_games_dir();
font_path = db_strcat(db_get_fonts_dir(), "/UbuntuTitling-Bold.ttf");
- renderer = db_get_renderer();
+ renderer = SDL_GetRenderer(window);
+ if (renderer == NULL) {
+ db_err("Failed to get renderer (%s)", SDL_GetError());
+ return -1;
+ }
text_color.r = DB_COLOR_FORE_R;
text_color.g = DB_COLOR_FORE_G;
@@ -183,7 +191,7 @@ db_main_menu(void)
buttons[0]->rect.x = DB_WINDOW_W - DB_WINDOW_P - buttons[0]->rect.w;
buttons[0]->rect.y = DB_WINDOW_P;
buttons[0]->action = &_db_main_menu_action_help;
- buttons[0]->user_data = NULL;
+ buttons[0]->user_data = window;
/* Render quit button */
buttons[1] = malloc(sizeof(**buttons));
diff --git a/src/main-menu.h b/src/main-menu.h
index 7dffbd9..5e9f6e8 100644
--- a/src/main-menu.h
+++ b/src/main-menu.h
@@ -20,6 +20,8 @@
#ifndef DB_MAIN_MENU_H_
#define DB_MAIN_MENU_H_
-int db_main_menu(void);
+#include <SDL.h>
+
+int db_main_menu(SDL_Window *window);
#endif /* DB_MAIN_MENU_H_ */
diff --git a/src/main.c b/src/main.c
index abd0f44..fc634d6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -108,18 +108,6 @@ db_get_fonts_dir(void)
return _db_fonts_dir;
}
-SDL_Window *
-db_get_window(void)
-{
- return _db_window;
-}
-
-SDL_Renderer *
-db_get_renderer(void)
-{
- return _db_renderer;
-}
-
int
main(int argc, char *argv[])
{
@@ -131,7 +119,7 @@ main(int argc, char *argv[])
return EXIT_FAILURE;
}
- db_main_menu();
+ db_main_menu(_db_window);
/* Quit SDL libraries */
_db_quit();
diff --git a/src/main.h b/src/main.h
index f3c52cc..c6ce604 100644
--- a/src/main.h
+++ b/src/main.h
@@ -20,11 +20,7 @@
#ifndef DB_MAIN_H_
#define DB_MAIN_H_
-#include <SDL.h>
-
const char *db_get_games_dir(void) __attribute__((__pure__));
const char *db_get_fonts_dir(void) __attribute__((__pure__));
-SDL_Window *db_get_window(void) __attribute__((__pure__));
-SDL_Renderer *db_get_renderer(void) __attribute__((__pure__));
#endif /* DB_MAIN_H_ */