From cdba8ffbbd7a9eccb825a666d8c6e61c23aa98d7 Mon Sep 17 00:00:00 2001 From: Bill Kendrick Date: Tue, 14 Jun 2022 00:14:02 -0700 Subject: [PATCH] Adding an auto option for button sizes Merge 333f4b05a49c4b106e19a4b9aeee53a1f2f03a0b sdl2.0->master (See https://sourceforge.net/p/tuxpaint/feature-requests/218/) --- src/tuxpaint.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/tuxpaint.c b/src/tuxpaint.c index 8643f2dde..e42fe858f 100644 --- a/src/tuxpaint.c +++ b/src/tuxpaint.c @@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA (See COPYING.txt) - June 14, 2002 - June 3, 2022 + June 14, 2002 - June 14, 2022 */ #include "platform.h" @@ -741,6 +741,7 @@ static SDL_Rect old_dest; static int button_w; /* was 48 */ static int button_h; /* was 48 */ +static int button_size_auto = 0; /* if the size of buttons should be autocalculated */ static float button_scale; /* scale factor to be applied to the size of buttons */ static int color_button_w; /* was 32 */ static int color_button_h; /* was 48 */ @@ -26072,12 +26073,17 @@ static void setup_config(char *argv[]) } if (tmpcfg.button_size) { - if (strtof(tmpcfg.button_size, NULL) < 24 || strtof(tmpcfg.button_size, NULL) > 192) + if (strstr(tmpcfg.button_size, "auto")) + button_size_auto = 1; + else { - fprintf(stderr, "Button size (now %s) must be between 24 and 192.\n", tmpcfg.button_size); - exit(1); + if (strtof(tmpcfg.button_size, NULL) < 24 || strtof(tmpcfg.button_size, NULL) > 192) + { + fprintf(stderr, "Button size (now %s) must be between 24 and 192.\n", tmpcfg.button_size); + exit(1); + } + button_scale = strtof(tmpcfg.button_size, NULL) / ORIGINAL_BUTTON_SIZE; } - button_scale = strtof(tmpcfg.button_size, NULL) / ORIGINAL_BUTTON_SIZE; } else button_scale = 1; @@ -27084,6 +27090,9 @@ static void setup(void) /* (Need to do this after native screen resolution is handled) */ + if (button_size_auto) /* Automatic size of buttons, see https://sourceforge.net/p/tuxpaint/feature-requests/218/ */ + button_scale = (float) min((48 * screen->w) / 800, (48 * screen->h) / 600) / ORIGINAL_BUTTON_SIZE; + setup_screen_layout(); set_color_picker_crosshair_size();