diff --git a/data/brushes/rotating_dash.dat b/data/brushes/rotating_dash.dat new file mode 100644 index 000000000..e8180d852 --- /dev/null +++ b/data/brushes/rotating_dash.dat @@ -0,0 +1,2 @@ +rotate +spacing=10 diff --git a/data/brushes/rotating_dash.png b/data/brushes/rotating_dash.png new file mode 100644 index 000000000..9457fee79 Binary files /dev/null and b/data/brushes/rotating_dash.png differ diff --git a/docs/CHANGES.txt b/docs/CHANGES.txt index ee8aef2f8..7158de445 100644 --- a/docs/CHANGES.txt +++ b/docs/CHANGES.txt @@ -8,7 +8,7 @@ http://www.tuxpaint.org/ $Id$ -2021.November.8 (0.9.27) +2021.November.15 (0.9.27) * New Magic Tools: ---------------- * "Lightning" - Draws a bolt of lightning striking between @@ -66,6 +66,8 @@ $Id$ arrow which can rotate at any angle, using the new "rotational" brush feature. + * Added "rotating dash" brush. + * Small icons appear on brush selection buttons denoting when the brush is animated and/or directional. (Closes https://sourceforge.net/p/tuxpaint/bugs/183/) @@ -192,6 +194,11 @@ $Id$ (e.g., when returning from the "Open" dialog). (Closes https://sourceforge.net/p/tuxpaint/feature-requests/186/) + * Attempt to void crashing (by blowing up the stack) when doing + a flood-fill of a complicated shape on a large canvas + (e.g., `tuxpaint --3000x2000` with `starters/mosaic.svg`). + (h/t Yang for reporting, and Pere for confirming) + * Ports & Building ---------------- * Fix compilation error on Linux with HOST environment variable set. diff --git a/src/fill.c b/src/fill.c index 25749a44b..33ce80f0a 100644 --- a/src/fill.c +++ b/src/fill.c @@ -27,7 +27,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA (See COPYING.txt) - Last updated: October 24, 2021 + Last updated: November 15, 2021 $Id$ */ @@ -64,7 +64,7 @@ double colors_close(SDL_Surface * canvas, Uint32 c1, Uint32 c2); Uint32 blend(SDL_Surface * canvas, Uint32 draw_colr, Uint32 old_colr, double pct); -void simulate_flood_fill_outside_check(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer, SDL_Surface * last, SDL_Surface * canvas, int x, int y, Uint32 cur_colr, Uint32 old_colr, int * x1, int * y1, int * x2, int * y2, Uint8 * touched, int y_outside); +void simulate_flood_fill_outside_check(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer, SDL_Surface * last, SDL_Surface * canvas, int x, int y, Uint32 cur_colr, Uint32 old_colr, int * x1, int * y1, int * x2, int * y2, Uint8 * touched, int y_outside, Uint32 cnt); void draw_brush_fill_single(SDL_Surface * canvas, int x, int y, Uint32 draw_color, Uint8 * touched); @@ -133,10 +133,10 @@ Uint32 blend(SDL_Surface * canvas, Uint32 draw_colr, Uint32 old_colr, double pct } void simulate_flood_fill(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer, SDL_Surface * last, SDL_Surface * canvas, int x, int y, Uint32 cur_colr, Uint32 old_colr, int * x1, int * y1, int * x2, int * y2, Uint8 * touched) { - simulate_flood_fill_outside_check(screen, texture, renderer, last, canvas, x, y, cur_colr, old_colr, x1, y1, x2, y2, touched, 0); + simulate_flood_fill_outside_check(screen, texture, renderer, last, canvas, x, y, cur_colr, old_colr, x1, y1, x2, y2, touched, 0, 0); } -void simulate_flood_fill_outside_check(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer, SDL_Surface * last, SDL_Surface * canvas, int x, int y, Uint32 cur_colr, Uint32 old_colr, int * x1, int * y1, int * x2, int * y2, Uint8 * touched, int y_outside) +void simulate_flood_fill_outside_check(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer, SDL_Surface * last, SDL_Surface * canvas, int x, int y, Uint32 cur_colr, Uint32 old_colr, int * x1, int * y1, int * x2, int * y2, Uint8 * touched, int y_outside, Uint32 cnt) { int fillL, fillR, narrowFillL, narrowFillR, i, outside; double in_line, closeness; @@ -144,6 +144,10 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen, SDL_Texture * textu Uint32 px_colr; Uint8 touch_byt; + /* Don't blow up the stack! */ + /* FIXME: Would be better to do this a more reliable way */ + if (cnt >= 20000) + return; /* "Same" color? No need to fill */ if (!would_flood_fill(canvas, cur_colr, old_colr)) @@ -313,7 +317,7 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen, SDL_Texture * textu ) ) { - simulate_flood_fill_outside_check(screen, texture, renderer, last, canvas, i, y - 1, cur_colr, old_colr, x1, y1, x2, y2, touched, y_outside + 1); + simulate_flood_fill_outside_check(screen, texture, renderer, last, canvas, i, y - 1, cur_colr, old_colr, x1, y1, x2, y2, touched, y_outside + 1, cnt + 1); } px_colr = getpixels[last->format->BytesPerPixel] (last, i, y + 1); @@ -325,7 +329,7 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen, SDL_Texture * textu ) ) { - simulate_flood_fill_outside_check(screen, texture, renderer, last, canvas, i, y + 1, cur_colr, old_colr, x1, y1, x2, y2, touched, y_outside + 1); + simulate_flood_fill_outside_check(screen, texture, renderer, last, canvas, i, y + 1, cur_colr, old_colr, x1, y1, x2, y2, touched, y_outside + 1, cnt + 1); } } } diff --git a/src/tuxpaint.c b/src/tuxpaint.c index a3a78a4e9..218f787c6 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 - November 8, 2021 + June 14, 2002 - November 15, 2021 */ #include "platform.h" @@ -2071,7 +2071,7 @@ SDL_Joystick *joystick; static void mainloop(void); static void brush_draw(int x1, int y1, int x2, int y2, int update); -static void blit_brush(int x, int y, int direction, int rotation, int * w, int * h); +static void blit_brush(int x, int y, int direction, double rotation, int * w, int * h); static void stamp_draw(int x, int y); static void rec_undo_buffer(void); @@ -6307,10 +6307,11 @@ static void draw_blinking_cursor(void) */ static void brush_draw(int x1, int y1, int x2, int y2, int update) { - int dx, dy, y, frame_w, w, h; + int dx, dy, y, frame_w, w, h, sz; int orig_x1, orig_y1, orig_x2, orig_y2, tmp; - int direction, r; + int direction; float m, b; + double r; orig_x1 = x1; orig_y1 = y1; @@ -6331,22 +6332,22 @@ static void brush_draw(int x1, int y1, int x2, int y2, int update) direction = BRUSH_DIRECTION_NONE; - r = 0; + r = -1.0; if (brushes_directional[cur_brush] || brushes_rotate[cur_brush]) { r = brush_rotation(x1, y1, x2, y2); if (brushes_directional[cur_brush]) { - r = r + 22; - if (r < 0) - r = r + 360; + r = r + 22.0; + if (r < 0.0) + r = r + 360.0; if (x1 != x2 || y1 != y2) - direction = (r / 45); + direction = (r / 45.0); } else { - r = 270 - r; + r = 270.0 - r; } } @@ -6414,19 +6415,25 @@ static void brush_draw(int x1, int y1, int x2, int y2, int update) if (update) { - update_canvas(orig_x1 - (w >> 1), orig_y1 - (h >> 1), orig_x2 + (w >> 1), orig_y2 + (h >> 1)); + sz = max(w,h); + update_canvas(orig_x1 - sz, orig_y1 - sz, orig_x2 + sz, orig_y2 + sz); } } /** - * Reset the brush counter, such that the next - * attempt to draw something is guaranteed to - * do so, regardless of the brushe's spacing. + * Reset the brush counter, such that the next attempt to draw something + * is either (a) guaranteed to do so, regardless of the brush's spacing + * (for non-rotational brushes), or (b) requires the user to have moved + * far enough to get a good idea of the angle they're drawing + * (for rotational brushes). */ void reset_brush_counter(void) { - brush_counter = 999; + if (img_cur_brush_rotate) + brush_counter = 0; + else + brush_counter = 999; } @@ -6442,7 +6449,7 @@ void reset_brush_counter(void) * @param direction BRUSH_DIRECTION_... being drawn (for compass direction brushes) * @param rotation angle being drawn (for brushes which may rotate at any angle (0-360 degrees)) */ -static void blit_brush(int x, int y, int direction, int rotation, int * w, int * h) +static void blit_brush(int x, int y, int direction, double rotation, int * w, int * h) { SDL_Rect src, dest; @@ -6515,7 +6522,7 @@ static void blit_brush(int x, int y, int direction, int rotation, int * w, int * src.w = img_cur_brush_w; src.h = img_cur_brush_h; - if (img_cur_brush_rotate) + if (img_cur_brush_rotate && rotation != -1.0 /* only if we're moving */) { SDL_Surface * rotated_brush;