Elevate "Fill" from Magic Tool to real Tool

Replace the somewhat-recently-added "nothing" item in the tool bar
with the "Fill" tool, which has been converted back from a Magic tool
to a regular tool.

Also, change bash "==" to sh "=" in "if [ ... ]" tests in Makefile.

Also, link to math library (via "-lm") to make sure "max()" is available to
magic tools.

Also, add missing mention of "--newcolorslast" and "--newcolorsfirst" to manpage.
This commit is contained in:
Bill Kendrick 2019-09-12 23:04:13 -07:00
parent d79173eae4
commit 2911b35a50
15 changed files with 295 additions and 304 deletions

160
src/fill.c Normal file
View file

@ -0,0 +1,160 @@
/*
fill.c
Fill tool
Tux Paint - A simple drawing program for children.
Copyright (c) 2002-2019 by Bill Kendrick and others; see AUTHORS.txt
bill@newbreedsoftware.com
http://www.tuxpaint.org/
Flood fill code based on Wikipedia example:
http://www.wikipedia.org/wiki/Flood_fill/C_example
by Damian Yerrick - http://www.wikipedia.org/wiki/Damian_Yerrick
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
Last updated: September 12, 2019
$Id$
*/
#include <stdio.h>
#include <string.h>
#include "fill.h"
#include "rgblinear.h"
#include "playsound.h"
#include "pixels.h"
/* Local function prototypes: */
int colors_close(SDL_Surface * canvas, Uint32 c1, Uint32 c2);
int colors_close(SDL_Surface * canvas, Uint32 c1, Uint32 c2)
{
Uint8 r1, g1, b1, r2, g2, b2;
if (c1 == c2)
{
/* Get it over with quick, if possible! */
return 1;
}
else
{
double r, g, b;
SDL_GetRGB(c1, canvas->format, &r1, &g1, &b1);
SDL_GetRGB(c2, canvas->format, &r2, &g2, &b2);
// use distance in linear RGB space
r = sRGB_to_linear_table[r1] - sRGB_to_linear_table[r2];
r *= r;
g = sRGB_to_linear_table[g1] - sRGB_to_linear_table[g2];
g *= g;
b = sRGB_to_linear_table[b1] - sRGB_to_linear_table[b2];
b *= b;
// easy to confuse:
// dark grey, brown, purple
// light grey, tan
// red, orange
return r + g + b < 0.04;
}
}
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;
static unsigned char prog_anim;
if (cur_colr == old_colr || colors_close(canvas, cur_colr, old_colr))
return;
if (y < *y1)
{
*y1 = y;
}
if (y > *y2)
{
*y2 = y;
}
fillL = x;
fillR = x;
prog_anim++;
if ((prog_anim % 4) == 0)
{
/* FIXME: api->update_progress_bar(); */
playsound(canvas, 1, SND_FILL, 1, x, SNDDIST_NEAR);
}
/* Find left side, filling along the way */
in_line = 1;
while (in_line)
{
putpixels[canvas->format->BytesPerPixel] (canvas, fillL, y, cur_colr);
fillL--;
in_line = (fillL < 0) ? 0 : colors_close(canvas, getpixels[canvas->format->BytesPerPixel] (canvas, fillL, y), old_colr);
}
if (fillL < *x1)
{
*x1 = fillL;
}
fillL++;
/* Find right side, filling along the way */
in_line = 1;
while (in_line)
{
putpixels[canvas->format->BytesPerPixel] (canvas, fillR, y, cur_colr);
fillR++;
in_line = (fillR >= canvas->w) ? 0 : colors_close(canvas, getpixels[canvas->format->BytesPerPixel] (canvas, fillR, y), old_colr);
}
if (fillR > *x2)
{
*x2 = fillR;
}
fillR--;
/* Search top and bottom */
for (i = fillL; i <= fillR; i++)
{
if (y > 0 && colors_close(canvas, getpixels[canvas->format->BytesPerPixel] (canvas, i, y - 1), old_colr))
do_flood_fill(canvas, i, y - 1, cur_colr, old_colr, x1, y1, x2, y2);
if (y < canvas->h && colors_close(canvas, getpixels[canvas->format->BytesPerPixel] (canvas, i, y + 1), old_colr))
do_flood_fill(canvas, i, y + 1, cur_colr, old_colr, x1, y1, x2, y2);
}
}

37
src/fill.h Normal file
View file

@ -0,0 +1,37 @@
/*
fill.h
Fill tool
Tux Paint - A simple drawing program for children.
Copyright (c) 2002-2019 by Bill Kendrick and others; see AUTHORS.txt
bill@newbreedsoftware.com
http://www.tuxpaint.org/
Flood fill code based on Wikipedia example:
http://www.wikipedia.org/wiki/Flood_fill/C_example
by Damian Yerrick - http://www.wikipedia.org/wiki/Damian_Yerrick
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
Last updated: September 12, 2019
$Id$
*/
#include "SDL.h"
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);

View file

@ -1,5 +1,5 @@
.\" tuxpaint.1 - 2018.09.24
.TH TUXPAINT 1 "24 September 2018" "0.9.23c" "Tux Paint"
.\" tuxpaint.1 - 2019.09.12
.TH TUXPAINT 1 "12 September 2019" "0.9.24" "Tux Paint"
.SH NAME
tuxpaint -- "Tux Paint", a drawing program for young children.
@ -61,6 +61,8 @@ tuxpaint -- "Tux Paint", a drawing program for young children.
.br
[\-\-nolabel]
.br
[\-\-newcolorslast]
.br
[\-\-mirrorstamps]
.br
[\-\-mouse-accessibility]
@ -187,6 +189,8 @@ tuxpaint -- "Tux Paint", a drawing program for young children.
.br
[\-\-label]
.br
[\-\-newcolorsfirst]
.br
[\-\-dontmirrorstamps]
.br
[\-\-stampsize=default]
@ -408,6 +412,11 @@ controllable.)
Disable or enable (default) the \fILabel\fP tool, which lets you create
text which can be altered or moved later.
.TP 8
.B \-\-newcolorslast \-\-newcolorsfirst
List solid (blank) colors at the end, or beginning (default) of the
options displayed when using the \fINew\fP tool to start a new picture.
.TP 8
.B \-\-mirrorstamps \-\-dontmirrorstamps
With \fImirrorstamps\fP set, stamps which can be mirrored will appear

View file

@ -4,7 +4,7 @@
For Tux Paint
List of sound effects.
Copyright (c) 2002-2007 by Bill Kendrick and others
Copyright (c) 2002-2019 by Bill Kendrick and others
bill@newbreedsoftware.com
http://www.tuxpaint.org/
@ -23,7 +23,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
June 15, 2002 - July 5, 2007
June 15, 2002 - September 12, 2019
$Id$
*/
@ -67,6 +67,7 @@ enum
SND_TUXOK, /* "Ok" */
SND_THICK,
SND_THIN,
SND_FILL,
NUM_SOUNDS
};
@ -107,7 +108,8 @@ static const char *sound_fnames[NUM_SOUNDS] = {
DATA_PREFIX "sounds/youcannot.wav",
DATA_PREFIX "sounds/tuxok.wav",
DATA_PREFIX "sounds/thick.wav",
DATA_PREFIX "sounds/thin.wav"
DATA_PREFIX "sounds/thin.wav",
DATA_PREFIX "sounds/fill.wav"
};
#endif

View file

@ -19,11 +19,11 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
Copyright (c) 2002-2009 by Bill Kendrick
Copyright (c) 2002-2019 by Bill Kendrick
bill@newbreedsoftware.com
http://www.tuxpaint.org/
June 14, 2002 - October 9, 2009
June 14, 2002 - September 12, 2019
$Id$
*/
@ -41,7 +41,7 @@ enum
TOOL_SHAPES,
TOOL_TEXT,
TOOL_LABEL,
TOOL_NA,
TOOL_FILL,
TOOL_MAGIC,
TOOL_UNDO,
TOOL_REDO,
@ -76,8 +76,8 @@ const char *const tool_names[NUM_TOOLS] = {
// Label tool
gettext_noop("Label"),
// Reserved...
" ",
// Fill tool
gettext_noop("Fill"),
// "Magic" effects tools (blur, flip image, etc.)
gettext_noop("Magic"),
@ -132,8 +132,8 @@ const char *const tool_tips[NUM_TOOLS] = {
gettext_noop
("Choose a style of text. Click on your drawing and you can start typing. Press [Enter] or [Tab] to complete the text. By using the selector button and clicking an existing label, you can move it, edit it and change its text style."),
// Reserved...
" ",
// Fill tool instructions
gettext_noop("Click in the picture to fill that area with color."),
// Magic tool instruction
gettext_noop("Pick a magical effect to use on your drawing!"),
@ -185,7 +185,7 @@ const char *const tool_img_fnames[NUM_TOOLS] = {
DATA_PREFIX "images/tools/shapes.png",
DATA_PREFIX "images/tools/text.png",
DATA_PREFIX "images/tools/label.png",
DATA_PREFIX "images/ui/dead40x40.png",
DATA_PREFIX "images/tools/fill.png",
DATA_PREFIX "images/tools/magic.png",
DATA_PREFIX "images/tools/undo.png",
DATA_PREFIX "images/tools/redo.png",

View file

@ -503,6 +503,8 @@ static void mtw(wchar_t * wtok, char *tok)
#include "tip_tux.h"
#include "great.h"
#include "fill.h"
#include "im.h"
@ -3065,6 +3067,12 @@ static void mainloop(void)
draw_brushes();
draw_colors(COLORSEL_ENABLE);
}
else if (cur_tool == TOOL_FILL)
{
keybd_flag = 0;
draw_none();
draw_colors(COLORSEL_ENABLE);
}
else if (cur_tool == TOOL_SHAPES)
{
keybd_flag = 0;
@ -4376,6 +4384,24 @@ static void mainloop(void)
if (mouseaccessibility)
emulate_button_pressed = !emulate_button_pressed;
}
else if (cur_tool == TOOL_FILL)
{
int x1, y1, x2, y2;
/* 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);
update_canvas(x1, y1, x2, y2);
}
else if (cur_tool == TOOL_TEXT || cur_tool == TOOL_LABEL)
{
/* Text and Label Tools! */
@ -4549,7 +4575,8 @@ static void mainloop(void)
if (cur_tool == TOOL_BRUSH || cur_tool == TOOL_STAMP ||
cur_tool == TOOL_SHAPES || cur_tool == TOOL_LINES ||
cur_tool == TOOL_MAGIC || cur_tool == TOOL_TEXT || cur_tool == TOOL_ERASER || cur_tool == TOOL_LABEL)
cur_tool == TOOL_MAGIC || cur_tool == TOOL_TEXT ||
cur_tool == TOOL_ERASER || cur_tool == TOOL_LABEL)
{
/* Left tools scroll */
@ -5151,7 +5178,7 @@ static void mainloop(void)
do_setcursor(cursor_brush);
else if (cur_tool == TOOL_STAMP)
do_setcursor(cursor_tiny);
else if (cur_tool == TOOL_LINES)
else if (cur_tool == TOOL_LINES || cur_tool == TOOL_FILL)
do_setcursor(cursor_crosshair);
else if (cur_tool == TOOL_SHAPES)
{
@ -5182,7 +5209,6 @@ static void mainloop(void)
do_setcursor(cursor_arrow);
}
}
else if (cur_tool == TOOL_MAGIC)
do_setcursor(cursor_wand);
else if (cur_tool == TOOL_ERASER)
@ -10110,11 +10136,6 @@ static void reset_avail_tools(void)
tool_avail[TOOL_LABEL] = 0;
/* TBD... */
tool_avail[TOOL_NA] = 0;
/* Disable save? */
if (disable_save)