From f3a472ab963a5ff04b738ccb90de1c151039c1b6 Mon Sep 17 00:00:00 2001 From: Glen Whitney Date: Sun, 19 Apr 2020 22:15:36 -0700 Subject: [PATCH] Modify GUI2 config files to scale font size with screen pixel pitch These changes to the data/gui subdirectories make it so that above a certain screen pixel dimensions (currently 1200x900), text font sizes will be scaled with the pixel pitch of the SDL video device. In addition, several dialogues (such as the unit recall window, for example) are allowed to take on larger pixel dimensions to accommodate the larger (in pixel size) fonts. --- data/gui/macros/_initial.cfg | 10 ++++++++++ data/gui/widget/label_default.cfg | 31 +++++++++++++++++++++++++++++++ data/gui/window/game_load.cfg | 2 +- data/gui/window/game_stats.cfg | 2 +- data/gui/window/unit_list.cfg | 2 +- data/gui/window/unit_recall.cfg | 2 +- data/schema/gui.cfg | 2 +- 7 files changed, 46 insertions(+), 5 deletions(-) diff --git a/data/gui/macros/_initial.cfg b/data/gui/macros/_initial.cfg index 589cfcd8acc..546ad68690e 100644 --- a/data/gui/macros/_initial.cfg +++ b/data/gui/macros/_initial.cfg @@ -248,6 +248,16 @@ y = "(floor((screen_height - window_height) / 2))" #enddef +#define GUI_WINDOW_PERC_FIXED_SIZE_CENTERED PERC_W PERC_H WIDTH HEIGHT + automatic_placement = false + + width = "(max(screen_width * {PERC_W} / 100, min(screen_width, {WIDTH})))" + height = "(max(screen_height * {PERC_H} / 100, min(screen_height, {HEIGHT})))" + + x = "(floor((screen_width - window_width) / 2))" + y = "(floor((screen_height - window_height) / 2))" +#enddef + #define GUI_CENTERED_IMAGE x = "(max(pos, 0) where pos = floor((width - image_width) / 2))" y = "(max(pos, 0) where pos = floor((height - image_height) / 2))" diff --git a/data/gui/widget/label_default.cfg b/data/gui/widget/label_default.cfg index 7996bf080b3..c3a3eac381e 100644 --- a/data/gui/widget/label_default.cfg +++ b/data/gui/widget/label_default.cfg @@ -80,6 +80,26 @@ [/resolution] #enddef +# The following is a more-or-less arbitrary resolution, larger than 1024x768 +# in both dimensions, at which to switch over from the traditional +# everything-is-fixed-size layout to one that scales proportionally to +# the screen_pitch_microns. + +#define _GUI_BIG_RES + window_width = 1200 + window_height = 900 +#enddef + +# The magic number 265 in the below formula is the pixel pitch in microns +# corresponding to 96 dpi, which the old layout seems to have been based on. +# The extra factor of 2/3 in the formula is a fudge factor based on the guess +# that the old fonts took up approximately 1.5 pixels per point size at 96 +# dpi. It came out looking pretty decent on my 90-micron monitor. + +#define _GUI_SCALE_RES SIZE + "(floor({SIZE} * 265 * 2 / (3 * screen_pitch_microns)))" +#enddef + #define _GUI_DEFINITION ID DESCRIPTION FONT_FAMILY FONT_SIZE FONT_STYLE FONT_COLOR [label_definition] id = {ID} @@ -94,6 +114,15 @@ ({GUI__FONT_COLOR_DISABLED__{FONT_COLOR} ALPHA=""}) } + {_GUI_RESOLUTION + ({_GUI_BIG_RES}) + ({FONT_FAMILY}) + ({_GUI_SCALE_RES {GUI_FONT_SIZE_{FONT_SIZE}}}) + ({FONT_STYLE}) + ({GUI__FONT_COLOR_ENABLED__{FONT_COLOR} ALPHA=""}) + ({GUI__FONT_COLOR_DISABLED__{FONT_COLOR} ALPHA=""}) + } + [/label_definition] #enddef @@ -108,5 +137,7 @@ {_GUI_DEFINITION "monospace" "fixed width scroll label" monospace DEFAULT () DEFAULT } +#undef _GUI_SCALE_RES SIZE +#undef _GUI_BIG_RES #undef _GUI_DEFINITION #undef _GUI_RESOLUTION diff --git a/data/gui/window/game_load.cfg b/data/gui/window/game_load.cfg index 1ab69c739f2..7b813c63f86 100644 --- a/data/gui/window/game_load.cfg +++ b/data/gui/window/game_load.cfg @@ -243,7 +243,7 @@ [resolution] definition = "default" - {GUI_WINDOW_FIXED_SIZE_CENTERED 850 800} + {GUI_WINDOW_PERC_FIXED_SIZE_CENTERED 80 95 850 800} [linked_group] id = "filename" diff --git a/data/gui/window/game_stats.cfg b/data/gui/window/game_stats.cfg index c50d3283883..a2c0929e064 100644 --- a/data/gui/window/game_stats.cfg +++ b/data/gui/window/game_stats.cfg @@ -594,7 +594,7 @@ Village" vertical_placement = "center" horizontal_placement = "center" - maximum_height = 750 + maximum_height = (max(750, screen_height*4/5)) [linked_group] id = "header" diff --git a/data/gui/window/unit_list.cfg b/data/gui/window/unit_list.cfg index 58ccf2b782b..7e4f11c4b52 100644 --- a/data/gui/window/unit_list.cfg +++ b/data/gui/window/unit_list.cfg @@ -303,7 +303,7 @@ vertical_placement = "center" horizontal_placement = "center" - maximum_height = 700 + maximum_height = (max(700, screen_height * 2 / 3)) [linked_group] id = "type" diff --git a/data/gui/window/unit_recall.cfg b/data/gui/window/unit_recall.cfg index 6fb10a1cdac..d91a50383ad 100644 --- a/data/gui/window/unit_recall.cfg +++ b/data/gui/window/unit_recall.cfg @@ -234,7 +234,7 @@ vertical_placement = "center" horizontal_placement = "center" - maximum_height = 750 + maximum_height = (max(750, screen_height * 3 / 5)) [linked_group] id = "image" diff --git a/data/schema/gui.cfg b/data/schema/gui.cfg index b2a7d1c24c5..97a19567fac 100644 --- a/data/schema/gui.cfg +++ b/data/schema/gui.cfg @@ -226,7 +226,7 @@ {DEFAULT_KEY "text_extra_height" unsigned 0} {DEFAULT_KEY "text_extra_width" unsigned 0} {DEFAULT_KEY "text_font_family" font_family "sans"} - {DEFAULT_KEY "text_font_size" unsigned 0} + {DEFAULT_KEY "text_font_size" f_unsigned 0} {DEFAULT_KEY "text_font_style" font_style ""} {DEFAULT_KEY "window_height" unsigned 0} {DEFAULT_KEY "window_width" unsigned 0}