From 8e9a51d478c2f61ec938844fcd6f09181de13676 Mon Sep 17 00:00:00 2001 From: Bill Kendrick Date: Wed, 10 May 2023 23:20:05 -0700 Subject: [PATCH] Define & use NUM_ERASER_SIZES ...everywhere "NUM_ERASERS / 2" was being used --- docs/CHANGES.txt | 2 +- src/tuxpaint.c | 31 ++++++++++++++++--------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/docs/CHANGES.txt b/docs/CHANGES.txt index 57de180e8..9e3a4c424 100644 --- a/docs/CHANGES.txt +++ b/docs/CHANGES.txt @@ -6,7 +6,7 @@ Copyright (c) 2002-2023 Various contributors (see below, and AUTHORS.txt) https://tuxpaint.org/ -2023.May.9 (0.9.30) +2023.May.10 (0.9.30) * Improvements to Stamp tool: --------------------------- * Avoid playing English descriptive sound for a stamp diff --git a/src/tuxpaint.c b/src/tuxpaint.c index 264c4fa39..d7e26f2c6 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 - May 9, 2023 + June 14, 2002 - May 10, 2023 */ #include "platform.h" @@ -1969,8 +1969,10 @@ static int brush_counter, brush_frame; #define NUM_ERASERS 16 /* How many sizes of erasers (from ERASER_MIN to _MAX as squares, then again - from ERASER_MIN to _MAX as circles; best if a - multiple of 4, since selector is 2 buttons across) */ + from ERASER_MIN to _MAX as circles; + must be a multiple of 2; + best if a multiple of 4, since selector is 2 buttons across) */ +#define NUM_ERASER_SIZES (NUM_ERASERS / 2) #define ERASER_MIN 5 /* Smaller than 5 will not render as a circle! */ #define ERASER_MAX 128 @@ -6582,7 +6584,7 @@ static void mainloop(void) eraser_draw(old_x, old_y, new_x, new_y); sz = calc_eraser_size(cur_eraser); - if (cur_eraser >= NUM_ERASERS / 2) + if (cur_eraser >= NUM_ERASER_SIZES) { /* Circle eraser */ circle_xor(new_x, new_y, sz / 2); @@ -6651,16 +6653,16 @@ static void mainloop(void) } else { - if (cur_eraser < NUM_ERASERS / 2) + if (cur_eraser < NUM_ERASER_SIZES) { w = (ERASER_MIN + - (((NUM_ERASERS / 2) - cur_eraser - 1) * ((ERASER_MAX - ERASER_MIN) / ((NUM_ERASERS / 2) - 1)))); + ((NUM_ERASER_SIZES - cur_eraser - 1) * ((ERASER_MAX - ERASER_MIN) / (NUM_ERASER_SIZES - 1)))); } else { w = (ERASER_MIN + - (((NUM_ERASERS / 2) - (cur_eraser - NUM_ERASERS / 2) - 1) * - ((ERASER_MAX - ERASER_MIN) / ((NUM_ERASERS / 2) - 1)))); + ((NUM_ERASER_SIZES - (cur_eraser - NUM_ERASERS / 2) - 1) * + ((ERASER_MAX - ERASER_MIN) / (NUM_ERASER_SIZES - 1)))); } h = w; @@ -11232,7 +11234,7 @@ static void draw_erasers(void) { /* Square */ - sz = (2 + (((NUM_ERASERS / 2) - 1 - i) * (38 / ((NUM_ERASERS / 2) - 1)))) * button_scale; + sz = (2 + ((NUM_ERASER_SIZES - 1 - i) * (38 / (NUM_ERASER_SIZES - 1)))) * button_scale; x = ((i % 2) * button_w) + WINDOW_WIDTH - r_ttoolopt.w + 24 * button_scale - sz / 2; y = ((j / 2) * button_h) + r_ttoolopt.h + 24 * button_scale - sz / 2 + off_y; @@ -11269,7 +11271,7 @@ static void draw_erasers(void) { /* Circle */ - sz = (2 + (((NUM_ERASERS / 2) - 1 - (i - NUM_ERASERS / 2)) * (38 / ((NUM_ERASERS / 2) - 1)))) * button_scale; + sz = (2 + ((NUM_ERASER_SIZES - 1 - (i - NUM_ERASERS / 2)) * (38 / (NUM_ERASER_SIZES - 1)))) * button_scale; x = ((i % 2) * button_w) + WINDOW_WIDTH - r_ttoolopt.w + 24 * button_scale - sz / 2; y = ((j / 2) * button_h) + 40 * button_scale + 24 * button_scale - sz / 2 + off_y; @@ -12193,11 +12195,10 @@ static void circle_xor(int x, int y, int sz) static int calc_eraser_size(int which_eraser) { -#define NUM_SIZES (NUM_ERASERS / 2) - if (which_eraser >= NUM_SIZES) - which_eraser -= NUM_SIZES; + if (which_eraser >= NUM_ERASER_SIZES) + which_eraser -= NUM_ERASER_SIZES; - return (((NUM_SIZES - 1 - which_eraser) * ((ERASER_MAX - ERASER_MIN) / (NUM_SIZES - 1))) + ERASER_MIN); + return (((NUM_ERASER_SIZES - 1 - which_eraser) * ((ERASER_MAX - ERASER_MIN) / (NUM_ERASER_SIZES - 1))) + ERASER_MIN); } /** @@ -12212,7 +12213,7 @@ static void do_eraser(int x, int y, int update) sz = calc_eraser_size(cur_eraser); - if (cur_eraser < NUM_SIZES) + if (cur_eraser < NUM_ERASER_SIZES) { /* Square eraser: */