Make sure Fill uses undo (but also intelligently)
"Fill", as a new main-toolbar tool, was not recording snapshots of the image for the "Undo" tool. Mended. However, also updated the tool so that it doesn't _bother_ recording into the undo buffer if the fill action is a no-op (e.g., clicking the same spot a second time, or otherwise attempting to fill an area with a color that's identical to what's already on the canvas).
This commit is contained in:
parent
8f9ea4cb69
commit
a54dd570b4
4 changed files with 42 additions and 17 deletions
|
|
@ -13,7 +13,10 @@ $Id$
|
||||||
---------
|
---------
|
||||||
* Fill
|
* Fill
|
||||||
Not actually a new tool, but promoted from a "Magic" tool
|
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
|
* Ports & Building
|
||||||
----------------
|
----------------
|
||||||
|
|
|
||||||
12
src/fill.c
12
src/fill.c
|
|
@ -27,7 +27,7 @@
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
(See COPYING.txt)
|
(See COPYING.txt)
|
||||||
|
|
||||||
Last updated: September 12, 2019
|
Last updated: September 14, 2019
|
||||||
$Id$
|
$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)
|
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;
|
int fillL, fillR, i, in_line;
|
||||||
|
|
|
||||||
|
|
@ -27,11 +27,12 @@
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
(See COPYING.txt)
|
(See COPYING.txt)
|
||||||
|
|
||||||
Last updated: September 12, 2019
|
Last updated: September 14, 2019
|
||||||
$Id$
|
$Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "SDL.h"
|
#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);
|
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);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4384,24 +4384,35 @@ static void mainloop(void)
|
||||||
if (mouseaccessibility)
|
if (mouseaccessibility)
|
||||||
emulate_button_pressed = !emulate_button_pressed;
|
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 */
|
/* Fill */
|
||||||
x1 = x2 = old_x;
|
|
||||||
y1 = y2 = old_y;
|
|
||||||
|
|
||||||
do_flood_fill(canvas, old_x, old_y,
|
draw_color = SDL_MapRGB(canvas->format,
|
||||||
SDL_MapRGB(canvas->format,
|
color_hexes[cur_color][0],
|
||||||
color_hexes[cur_color][0],
|
color_hexes[cur_color][1],
|
||||||
color_hexes[cur_color][1],
|
color_hexes[cur_color][2]);
|
||||||
color_hexes[cur_color][2]),
|
canv_color = getpixels[canvas->format->BytesPerPixel] (canvas, old_x, old_y);
|
||||||
getpixels[canvas->format->BytesPerPixel] (canvas, old_x, old_y),
|
|
||||||
&x1, &y1, &x2, &y2);
|
|
||||||
|
|
||||||
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)
|
else if (cur_tool == TOOL_TEXT || cur_tool == TOOL_LABEL)
|
||||||
{
|
{
|
||||||
/* Text and Label Tools! */
|
/* Text and Label Tools! */
|
||||||
|
|
@ -18778,7 +18789,7 @@ static int do_new_dialog(void)
|
||||||
|| strcasestr(f->d_name, ".bmp") != NULL
|
|| strcasestr(f->d_name, ".bmp") != NULL
|
||||||
/* Support for KPX (Kid Pix templates; just a JPEG with resource fork header): */
|
/* Support for KPX (Kid Pix templates; just a JPEG with resource fork header): */
|
||||||
|| strcasestr(f->d_name, ".kpx") != NULL
|
|| strcasestr(f->d_name, ".kpx") != NULL
|
||||||
|| strcasestr(f->d_name, ".jpg") != NULL
|
|| strcasestr(f->d_name, ".jpg") != NULL
|
||||||
#ifndef NOSVG
|
#ifndef NOSVG
|
||||||
|| strcasestr(f->d_name, ".svg") != NULL
|
|| strcasestr(f->d_name, ".svg") != NULL
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue