From 4688958ade94245cb87696368f535823f29b02c2 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 28 Jun 2023 06:56:32 +0300 Subject: [PATCH 16/16] sdl2: Add commandline parameter -- --Font SIZE See osdn #48305 Signed-off-by: Marko Lindqvist --- client/gui-sdl2/gui_main.c | 19 +++++++++++++++++++ client/gui-sdl2/gui_main.h | 3 +++ client/gui-sdl2/gui_string.c | 2 +- client/gui-sdl2/themes.c | 2 +- client/gui-sdl2/themespec.c | 2 +- doc/man/freeciv-client.6.in | 3 ++- 6 files changed, 27 insertions(+), 4 deletions(-) diff --git a/client/gui-sdl2/gui_main.c b/client/gui-sdl2/gui_main.c index d383ddbf60..f84596ad50 100644 --- a/client/gui-sdl2/gui_main.c +++ b/client/gui-sdl2/gui_main.c @@ -114,6 +114,8 @@ int *client_font_sizes[FONT_COUNT] = { &city_productions_font_size /* FONT_REQTREE_TEXT; not used yet */ }; +static unsigned font_size_parameter = 0; + /* ================================ Private ============================ */ static int net_socket = -1; static bool autoconnect = FALSE; @@ -167,6 +169,8 @@ static void print_usage(void) /* Add client-specific usage information here */ fc_fprintf(stderr, _(" -f, --fullscreen\tStart Client in Fullscreen mode\n")); + fc_fprintf(stderr, + _(" -F, --Font SIZE\tUse SIZE as the base font size\n")); fc_fprintf(stderr, _(" -s, --swrenderer\tUse SW renderer\n")); fc_fprintf(stderr, _(" -t, --theme THEME\tUse GUI theme THEME\n")); @@ -190,6 +194,12 @@ static void parse_options(int argc, char **argv) gui_options.gui_sdl2_fullscreen = TRUE; } else if (is_option("--swrenderer", argv[i])) { sdl2_client_flags |= CF_SWRENDERER; + } else if ((option = get_option_malloc("--Font", argv, &i, argc, FALSE))) { + if (!str_to_uint(option, &font_size_parameter)) { + fc_fprintf(stderr, _("Invalid font size %s"), option); + exit(EXIT_FAILURE); + } + free(option); } else if ((option = get_option_malloc("--theme", argv, &i, argc, FALSE))) { sz_strlcpy(gui_options.gui_sdl2_default_theme_name, option); free(option); @@ -1270,6 +1280,15 @@ void gui_update_font(const char *font_name, const char *font_value) #undef CHECK_FONT } +/**********************************************************************//** + Return default font size, from any source. +**************************************************************************/ +unsigned default_font_size(struct theme *act_theme) +{ + return font_size_parameter > 0 ? font_size_parameter : + theme_default_font_size(act_theme); +} + /**********************************************************************//** Update font sizes based on theme. **************************************************************************/ diff --git a/client/gui-sdl2/gui_main.h b/client/gui-sdl2/gui_main.h index ecf8e4e49b..dcc25b5fd9 100644 --- a/client/gui-sdl2/gui_main.h +++ b/client/gui-sdl2/gui_main.h @@ -32,6 +32,8 @@ /* client/include */ #include "gui_main_g.h" +struct theme; + /* Enable this to adjust sizes for 320x240 resolution */ /* #define SMALL_SCREEN */ @@ -124,6 +126,7 @@ Uint16 gui_event_loop(void *data, void (*loop_action)(void *data), Uint16 (*mouse_motion_handler)(SDL_MouseMotionEvent *motion_event, void *data)); +unsigned default_font_size(struct theme *act_theme); void update_font_from_theme(int theme_font_size); /* Shrink sizes for 320x240 screen */ diff --git a/client/gui-sdl2/gui_string.c b/client/gui-sdl2/gui_string.c index 5bc0dd0c48..1d8d0d90c5 100644 --- a/client/gui-sdl2/gui_string.c +++ b/client/gui-sdl2/gui_string.c @@ -60,7 +60,7 @@ static TTF_Font *load_font(Uint16 ptsize); static SDL_Surface *create_utf8_surf(utf8_str *pstr); static SDL_Surface *create_utf8_multi_surf(utf8_str *pstr); -#define ptsize_default() adj_font(theme_default_font_size(active_theme)) +#define ptsize_default() adj_font(default_font_size(active_theme)) /**********************************************************************//** Adjust font sizes for small screen. diff --git a/client/gui-sdl2/themes.c b/client/gui-sdl2/themes.c index 05aad7ce60..68ca680ca8 100644 --- a/client/gui-sdl2/themes.c +++ b/client/gui-sdl2/themes.c @@ -57,7 +57,7 @@ void gui_load_theme(const char *directory, const char *theme_name) themespec_try_read(buf); theme_load_sprites(active_theme); - update_font_from_theme(theme_default_font_size(active_theme)); + update_font_from_theme(default_font_size(active_theme)); } /*************************************************************************//** diff --git a/client/gui-sdl2/themespec.c b/client/gui-sdl2/themespec.c index 397fb43c60..303203d8ae 100644 --- a/client/gui-sdl2/themespec.c +++ b/client/gui-sdl2/themespec.c @@ -172,7 +172,7 @@ const char *theme_font_filename(const struct theme *t) } /************************************************************************//** - Return the default font size. + Return theme's default font size. ****************************************************************************/ int theme_default_font_size(const struct theme *t) { diff --git a/doc/man/freeciv-client.6.in b/doc/man/freeciv-client.6.in index c87b096fc6..d493e5e008 100644 --- a/doc/man/freeciv-client.6.in +++ b/doc/man/freeciv-client.6.in @@ -9,7 +9,7 @@ .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the .\" GNU General Public License for more details. .\" -.TH FREECIV 6 "November 2nd 2016" +.TH FREECIV 6 "June 28th 2023" .SH NAME freeciv-gtk3, freeciv-gtk3.22, freeciv-gtk4, freeciv-sdl2, freeciv-qt \ \- The clients for the Freeciv game @@ -59,6 +59,7 @@ documentation. It also accepts .B freeciv-sdl2 accepts the following parameters following \fB\-\-\fP: .B [ \-f|\-\-fullscreen ] \ +[ \-F|\-\-Font \fsize\fP ] \ [ \-h|\-\-help ] \ [ \-s|\-\-swrenderer ] \ [ \-t|\-\-theme \fIstring\fP ] -- 2.40.1