diff --git a/docs/CHANGES.txt b/docs/CHANGES.txt index 23ca81f08..b54407ede 100644 --- a/docs/CHANGES.txt +++ b/docs/CHANGES.txt @@ -13,7 +13,10 @@ $Id$ --------- * Fill Not actually a new tool, but promoted from a "Magic" tool - to a full-fledge tool in the "Tools" bar. + to a full-fledge tool in the "Tools" bar. However, also + avoids filling "Undo" buffer with snapshots of the drawing, + if the fill does nothing (e.g., if you click the same spot + a second time). * Ports & Building ---------------- diff --git a/src/fill.c b/src/fill.c index 2fce7d215..f33f0516b 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: September 12, 2019 + Last updated: September 14, 2019 $Id$ */ @@ -78,6 +78,16 @@ int colors_close(SDL_Surface * canvas, Uint32 c1, Uint32 c2) } +int would_flood_fill(SDL_Surface * canvas, int x, int y, Uint32 cur_colr, Uint32 old_colr) +{ + if (cur_colr == old_colr || colors_close(canvas, cur_colr, old_colr)) + { + return 0; + } else { + return 1; + } +} + void do_flood_fill(SDL_Surface * canvas, int x, int y, Uint32 cur_colr, Uint32 old_colr, int * x1, int * y1, int * x2, int * y2) { int fillL, fillR, i, in_line; diff --git a/src/fill.h b/src/fill.h index 2e37a09aa..9677bc459 100644 --- a/src/fill.h +++ b/src/fill.h @@ -27,11 +27,12 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA (See COPYING.txt) - Last updated: September 12, 2019 + Last updated: September 14, 2019 $Id$ */ #include "SDL.h" +int would_flood_fill(SDL_Surface * canvas, int x, int y, Uint32 cur_colr, Uint32 old_colr); void do_flood_fill(SDL_Surface * canvas, int x, int y, Uint32 cur_colr, Uint32 old_colr, int * x1, int * y1, int * x2, int * y2); diff --git a/src/tuxpaint.c b/src/tuxpaint.c index 8b9724dc1..1f2021e4d 100644 --- a/src/tuxpaint.c +++ b/src/tuxpaint.c @@ -4384,24 +4384,35 @@ static void mainloop(void) if (mouseaccessibility) emulate_button_pressed = !emulate_button_pressed; } - else if (cur_tool == TOOL_FILL) + else if (cur_tool == TOOL_FILL) { - int x1, y1, x2, y2; + Uint32 draw_color, canv_color; /* Fill */ - x1 = x2 = old_x; - y1 = y2 = old_y; - do_flood_fill(canvas, old_x, old_y, - SDL_MapRGB(canvas->format, - color_hexes[cur_color][0], - color_hexes[cur_color][1], - color_hexes[cur_color][2]), - getpixels[canvas->format->BytesPerPixel] (canvas, old_x, old_y), - &x1, &y1, &x2, &y2); + draw_color = SDL_MapRGB(canvas->format, + color_hexes[cur_color][0], + color_hexes[cur_color][1], + color_hexes[cur_color][2]); + canv_color = getpixels[canvas->format->BytesPerPixel] (canvas, old_x, old_y); - update_canvas(x1, y1, x2, y2); - } + if (would_flood_fill(canvas, old_x, old_y, draw_color, canv_color)) + { + /* We only bother recording an undo buffer + (which may kill our redos) if we're about + to actually change the picture */ + int x1, y1, x2, y2; + + rec_undo_buffer(); + + x1 = x2 = old_x; + y1 = y2 = old_y; + + do_flood_fill(canvas, old_x, old_y, draw_color, canv_color, &x1, &y1, &x2, &y2); + + update_canvas(x1, y1, x2, y2); + } + } else if (cur_tool == TOOL_TEXT || cur_tool == TOOL_LABEL) { /* Text and Label Tools! */ @@ -18778,7 +18789,7 @@ static int do_new_dialog(void) || strcasestr(f->d_name, ".bmp") != NULL /* Support for KPX (Kid Pix templates; just a JPEG with resource fork header): */ || strcasestr(f->d_name, ".kpx") != NULL - || strcasestr(f->d_name, ".jpg") != NULL + || strcasestr(f->d_name, ".jpg") != NULL #ifndef NOSVG || strcasestr(f->d_name, ".svg") != NULL #endif