From 554c6145fc4a6a7056b407e6c5912e33cbcd7c25 Mon Sep 17 00:00:00 2001 From: Bill Kendrick Date: Mon, 8 Apr 2024 22:15:23 -0700 Subject: [PATCH] WIP Ability to ungroup Magic tools Put them in a big long list, without left/right pagination buttons, like pre-0.9.27 Tux Paint. Code is in place, but no way of activating it. For https://sourceforge.net/p/tuxpaint/feature-requests/229/ --- docs/CHANGES.txt | 8 +++- src/tuxpaint.c | 111 +++++++++++++++++++++++++++++++---------------- 2 files changed, 80 insertions(+), 39 deletions(-) diff --git a/docs/CHANGES.txt b/docs/CHANGES.txt index 14ec6a65f..88d73509c 100644 --- a/docs/CHANGES.txt +++ b/docs/CHANGES.txt @@ -6,7 +6,7 @@ Copyright (c) 2002-2024 Various contributors (see below, and AUTHORS.txt) https://tuxpaint.org/ -2024.March.28 (0.9.33) +2024.April.8 (0.9.33) * New Magic Tools: ---------------- * WIP Specular Reflection: Draws a slightly blurred, wavy, and @@ -48,6 +48,12 @@ https://tuxpaint.org/ (Management scripts based on those found in `tuxpaint-stamps`.) Bill Kendrick + * WIP New option, --ungroupmagictools, to ungroup Magic tools + (one big long list, rather than paginating; grouping was + added in Tux Paint 0.9.27) + Closes https://sourceforge.net/p/tuxpaint/feature-requests/229/ + Bill Kendrick + * Make screen refresh more snappy on macOS. Mark Kim diff --git a/src/tuxpaint.c b/src/tuxpaint.c index 899a25b86..19c50b8ee 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 - March 25, 2024 + June 14, 2002 - April 8, 2024 */ #include "platform.h" @@ -1427,6 +1427,7 @@ static int only_uppercase; static int disable_magic_controls; static int disable_magic_sizes; static int disable_shape_controls; +static int no_magic_groups = 0; static int shape_mode = SHAPEMODE_CENTER; static int stamp_rotation_ctrl = 0; @@ -4335,6 +4336,9 @@ static void mainloop(void) grp = magic_group; cur = cur_magic[grp]; + if (no_magic_groups) + which += 2; + if (which == 0 || which == 1) { int tries = 0; @@ -10042,11 +10046,15 @@ static void draw_magic(void) /* How many can we show? */ most = (buttons_tall * gd_toolopt.cols) - (gd_toolopt.cols * 2) - TOOLOFFSET - 2; + if (no_magic_groups) + most = most + gd_toolopt.cols; if (disable_magic_controls) most = most + gd_toolopt.cols; if (disable_magic_sizes) most = most + gd_toolopt.cols; + /* Draw scroll bars, if we need them */ + if (num_magics[magic_group] > most + TOOLOFFSET) { off_y = img_scroll_down->h; @@ -10083,6 +10091,8 @@ static void draw_magic(void) } + /* Draw the magic tool buttons */ + for (magic = magic_scroll[magic_group]; magic < magic_scroll[magic_group] + max; magic++) { i = magic - magic_scroll[magic_group]; @@ -10124,38 +10134,40 @@ static void draw_magic(void) /* Draw group pagination buttons: */ - /* Show prev button: */ + if (!no_magic_groups) + { + /* Show prev button: */ - button_color = img_black; - button_body = img_btn_nav; + button_color = img_black; + button_body = img_btn_nav; - dest.x = WINDOW_WIDTH - r_ttoolopt.w; - dest.y = r_ttoolopt.h + (((most + TOOLOFFSET) / 2) * button_h); + dest.x = WINDOW_WIDTH - r_ttoolopt.w; + dest.y = r_ttoolopt.h + (((most + TOOLOFFSET) / 2) * button_h); - SDL_BlitSurface(button_body, NULL, screen, &dest); + SDL_BlitSurface(button_body, NULL, screen, &dest); - dest.x = WINDOW_WIDTH - r_ttoolopt.w + (button_w - img_prev->w) / 2; - dest.y = (r_ttoolopt.h + (((most + TOOLOFFSET) / 2) * button_h) + (button_h - img_prev->h) / 2); + dest.x = WINDOW_WIDTH - r_ttoolopt.w + (button_w - img_prev->w) / 2; + dest.y = (r_ttoolopt.h + (((most + TOOLOFFSET) / 2) * button_h) + (button_h - img_prev->h) / 2); - SDL_BlitSurface(button_color, NULL, img_prev, NULL); - SDL_BlitSurface(img_prev, NULL, screen, &dest); + SDL_BlitSurface(button_color, NULL, img_prev, NULL); + SDL_BlitSurface(img_prev, NULL, screen, &dest); - /* Show next button: */ + /* Show next button: */ - button_color = img_black; - button_body = img_btn_nav; + button_color = img_black; + button_body = img_btn_nav; - dest.x = WINDOW_WIDTH - button_w; - dest.y = r_ttoolopt.h + (((most + TOOLOFFSET) / gd_toolopt.cols) * button_h); + dest.x = WINDOW_WIDTH - button_w; + dest.y = r_ttoolopt.h + (((most + TOOLOFFSET) / gd_toolopt.cols) * button_h); - SDL_BlitSurface(button_body, NULL, screen, &dest); + SDL_BlitSurface(button_body, NULL, screen, &dest); - dest.x = WINDOW_WIDTH - button_w + (button_w - img_next->w) / 2; - dest.y = (r_ttoolopt.h + (((most + TOOLOFFSET) / gd_toolopt.cols) * button_h) + (button_h - img_next->h) / 2); - - SDL_BlitSurface(button_color, NULL, img_next, NULL); - SDL_BlitSurface(img_next, NULL, screen, &dest); + dest.x = WINDOW_WIDTH - button_w + (button_w - img_next->w) / 2; + dest.y = (r_ttoolopt.h + (((most + TOOLOFFSET) / gd_toolopt.cols) * button_h) + (button_h - img_next->h) / 2); + SDL_BlitSurface(button_color, NULL, img_next, NULL); + SDL_BlitSurface(img_next, NULL, screen, &dest); + } /* Draw magic controls: */ @@ -10180,15 +10192,18 @@ static void draw_magic(void) button_color = img_btn_off; /* Unavailable */ dest.x = WINDOW_WIDTH - r_ttoolopt.w; - dest.y = r_ttoolopt.h + ((most / gd_toolopt.cols + (TOOLOFFSET + 2) / gd_toolopt.cols) * button_h); + // dest.y = r_ttoolopt.h + ((most / gd_toolopt.cols + (TOOLOFFSET + 2) / gd_toolopt.cols) * button_h); + dest.y = (button_h * buttons_tall + r_ttools.h) - button_h * (disable_magic_sizes ? 1 : 2); SDL_BlitSurface(button_color, NULL, screen, &dest); dest.x = WINDOW_WIDTH - r_ttoolopt.w + (button_w - img_magic_paint->w) / 2; - dest.y = - (r_ttoolopt.h + - ((most / gd_toolopt.cols + - (TOOLOFFSET + 2) / gd_toolopt.cols) * button_h) + (button_h - img_magic_paint->h) / 2); + //dest.y = + // (r_ttoolopt.h + + // ((most / gd_toolopt.cols + + // (TOOLOFFSET + 2) / gd_toolopt.cols) * button_h) + (button_h - img_magic_paint->h) / 2); + dest.y = (button_h * buttons_tall + r_ttools.h) - button_h * (disable_magic_sizes ? 1 : 2) + + ((button_h - img_magic_paint->h) / 2); SDL_BlitSurface(img_magic_paint, NULL, screen, &dest); @@ -10203,18 +10218,20 @@ static void draw_magic(void) button_color = img_btn_off; /* Unavailable */ dest.x = WINDOW_WIDTH - button_w; - dest.y = r_ttoolopt.h + ((most / gd_toolopt.cols + (TOOLOFFSET + 2) / gd_toolopt.cols) * button_h); + // dest.y = r_ttoolopt.h + ((most / gd_toolopt.cols + (TOOLOFFSET + 2) / gd_toolopt.cols) * button_h); + dest.y = (button_h * buttons_tall + r_ttools.h) - button_h * (disable_magic_sizes ? 1 : 2); SDL_BlitSurface(button_color, NULL, screen, &dest); dest.x = WINDOW_WIDTH - button_w + (button_w - img_magic_fullscreen->w) / 2; - dest.y = - (r_ttoolopt.h + - ((most / gd_toolopt.cols + - (TOOLOFFSET + 2) / gd_toolopt.cols) * button_h) + (button_h - img_magic_fullscreen->h) / 2); + //dest.y = + // (r_ttoolopt.h + + // ((most / gd_toolopt.cols + + // (TOOLOFFSET + 2) / gd_toolopt.cols) * button_h) + (button_h - img_magic_fullscreen->h) / 2); + dest.y = (button_h * buttons_tall + r_ttools.h) - button_h * (disable_magic_sizes ? 1 : 2) + + ((button_h - img_magic_fullscreen->h) / 2); SDL_BlitSurface(img_magic_fullscreen, NULL, screen, &dest); - } @@ -21781,12 +21798,17 @@ static void load_magic_plugins(void) } else { - int j, group, idx; + int j, group, idx, want_group, want_order; SDL_Surface *icon_tmp; for (i = 0; i < n; i++) { - group = magic_funcs[num_plugin_files].get_group(magic_api_struct, i); + want_group = magic_funcs[num_plugin_files].get_group(magic_api_struct, i); + if (!no_magic_groups) + group = want_group; + else + group = 0; + if (group < MAX_MAGIC_GROUPS) { idx = num_magics[group]; @@ -21796,7 +21818,11 @@ static void load_magic_plugins(void) magics[group][idx].handle_idx = num_plugin_files; magics[group][idx].group = group; magics[group][idx].name = magic_funcs[num_plugin_files].get_name(magic_api_struct, i); - magics[group][idx].order = magic_funcs[num_plugin_files].get_order(i); + want_order = magic_funcs[num_plugin_files].get_order(i); + if (!no_magic_groups) + magics[group][idx].order = want_order; + else + magics[group][idx].order = (want_group * 1000000) + want_order; magics[group][idx].avail_modes = magic_funcs[num_plugin_files].modes(magic_api_struct, i); @@ -21896,6 +21922,12 @@ static void load_magic_plugins(void) num_magics[group]++; num_magics_total++; + + if (num_magics[group] >= MAX_MAGICS_PER_GROUP) { + fprintf(stderr, "Error: exceeded maximum number of Magic tools (%d) in group %d!\n", + MAX_MAGICS_PER_GROUP, group); + num_magics[group]--; // FIXME: Do something better than just this! -bjk 2024.04.08 + } } else { @@ -32367,8 +32399,11 @@ int calc_magic_control_rows(void) { int r; - /* Start with group changing (left/right) buttons */ - r = 1; + r = 0; + + /* Add group changing (left/right) buttons */ + if (!no_magic_groups) + r++; /* Add magic controls (paint vs fullscreen) */ if (!disable_magic_controls)