From 2911b35a50664f187971daa09324c80d836d9c18 Mon Sep 17 00:00:00 2001 From: Bill Kendrick Date: Thu, 12 Sep 2019 23:04:13 -0700 Subject: [PATCH] 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. --- Makefile | 23 +- {magic/icons => data/images/tools}/fill.png | Bin {magic => data}/sounds/fill.wav | Bin docs/CHANGES.txt | 6 + docs/en/README.txt | 12 +- docs/en/html/README.html | 13 +- docs/html/images/tool_fill.png | Bin 0 -> 3049 bytes magic/magic-docs/src/magic-docs.php | 6 +- magic/src/fill.c | 268 -------------------- src/fill.c | 160 ++++++++++++ src/fill.h | 37 +++ src/manpage/tuxpaint.1 | 13 +- src/sounds.h | 8 +- src/tools.h | 16 +- src/tuxpaint.c | 37 ++- 15 files changed, 295 insertions(+), 304 deletions(-) rename {magic/icons => data/images/tools}/fill.png (100%) rename {magic => data}/sounds/fill.wav (100%) create mode 100644 docs/html/images/tool_fill.png delete mode 100644 magic/src/fill.c create mode 100644 src/fill.c create mode 100644 src/fill.h diff --git a/Makefile b/Makefile index 2a6449e04..75c3300d8 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,10 @@ # Tux Paint - A simple drawing program for children. -# Copyright (c) 2002-2018 +# Copyright (c) 2002-2019 # Various contributors (see AUTHORS.txt) # http://www.tuxpaint.org/ -# June 14, 2002 - December 18, 2018 +# June 14, 2002 - September 12, 2019 # The version number, for release: @@ -481,7 +481,7 @@ install: install-bin install-data install-man install-doc \ @echo @echo "--------------------------------------------------------------" @echo - @if [ "x$(OS)" == "xosx" ]; then \ + @if [ "x$(OS)" = "xosx" ]; then \ echo "All done! Now you can double click $(BUNDLE) to run the"; \ echo "program!!! TuxPaint.dmg has also been created for"; \ echo "distribution."; \ @@ -876,7 +876,7 @@ install-dlls: @cp `which libstdc++-6.dll` $(BIN_PREFIX) @cp `which libfribidi-0.dll` $(BIN_PREFIX) @cp `which libpthread-2.dll` $(BIN_PREFIX) - @if [ "x$(BDIST_WIN9X)" == "x" ]; then \ + @if [ "x$(BDIST_WIN9X)" = "x" ]; then \ cp `which libxml2-2.dll` $(BIN_PREFIX); \ cp `which libcairo-2.dll` $(BIN_PREFIX); \ cp `which libfontconfig-1.dll` $(BIN_PREFIX); \ @@ -898,7 +898,7 @@ install-dlls: cp `which bz2-1.dll` $(BIN_PREFIX); \ fi @strip -s $(BIN_PREFIX)/*.dll - @if [ "x$(BDIST_WIN9X)" == "x" ]; then \ + @if [ "x$(BDIST_WIN9X)" = "x" ]; then \ echo; \ echo "...Installing Configuration Files..."; \ cp -R win32/etc/ $(BIN_PREFIX); \ @@ -1021,7 +1021,7 @@ TuxPaint.dmg: # Build the program! tuxpaint: obj/tuxpaint.o obj/i18n.o obj/im.o obj/cursor.o obj/pixels.o \ - obj/rgblinear.o obj/playsound.o obj/fonts.o obj/parse.o \ + obj/rgblinear.o obj/playsound.o obj/fonts.o obj/parse.o obj/fill.o \ obj/progressbar.o obj/dirwalk.o obj/get_fname.o obj/onscreen_keyboard.o \ $(ARCH_LIBS) @echo @@ -1037,7 +1037,7 @@ tuxpaint: obj/tuxpaint.o obj/i18n.o obj/im.o obj/cursor.o obj/pixels.o \ obj/tuxpaint.o: src/tuxpaint.c \ src/i18n.h src/im.h src/cursor.h src/pixels.h \ - src/rgblinear.h src/playsound.h src/fonts.h \ + src/rgblinear.h src/playsound.h src/fonts.h src/fill.h \ src/progressbar.h src/dirwalk.h src/get_fname.h \ src/compiler.h src/debug.h \ src/tools.h src/titles.h src/colors.h src/shapes.h \ @@ -1136,6 +1136,13 @@ obj/playsound.o: src/playsound.c src/playsound.h \ @$(CC) $(CFLAGS) $(DEBUG_FLAGS) $(SDL_CFLAGS) $(DEFS) \ -c src/playsound.c -o obj/playsound.o +obj/fill.o: src/fill.c src/fill.h \ + src/rgblinear.h src/playsound.h src/pixels.h + @echo + @echo "...Compiling flood fill tool..." + @$(CC) $(CFLAGS) $(DEBUG_FLAGS) $(SDL_CFLAGS) $(DEFS) \ + -c src/fill.c -o obj/fill.o + obj/progressbar.o: src/progressbar.c src/progressbar.h \ src/compiler.h src/debug.h @echo @@ -1226,7 +1233,7 @@ PLUGIN_LIBS:=$($(OS)_PLUGIN_LIBS) #MAGIC_CFLAGS:=-g3 -O2 -fvisibility=hidden -fno-common -W -Wstrict-prototypes -Wmissing-prototypes -Wall $(MAGIC_SDL_CPPFLAGS) -Isrc/ MAGIC_CFLAGS:=-g3 -O2 -fno-common -W -Wstrict-prototypes -Wmissing-prototypes -Wall $(MAGIC_SDL_CPPFLAGS) -Isrc/ $(ARCH_CFLAGS) -SHARED_FLAGS:=-shared -fpic +SHARED_FLAGS:=-shared -fpic -lm MAGIC_C:=$(wildcard magic/src/*.c) MAGIC_SO:=$(patsubst magic/src/%.c,magic/%.$(SO_TYPE),$(MAGIC_C)) diff --git a/magic/icons/fill.png b/data/images/tools/fill.png similarity index 100% rename from magic/icons/fill.png rename to data/images/tools/fill.png diff --git a/magic/sounds/fill.wav b/data/sounds/fill.wav similarity index 100% rename from magic/sounds/fill.wav rename to data/sounds/fill.wav diff --git a/docs/CHANGES.txt b/docs/CHANGES.txt index 0e5bcd52b..bf18dc769 100644 --- a/docs/CHANGES.txt +++ b/docs/CHANGES.txt @@ -9,6 +9,12 @@ http://www.tuxpaint.org/ $Id$ 2019.Sep.12 (0.9.24) + * New tools + --------- + * Fill + Not actually a new tool, but promoted from a "Magic" tool + to a full-fledge tool in the "Tools" bar. + * Ports & Building ---------------- * Updates to build on Haiku. diff --git a/docs/en/README.txt b/docs/en/README.txt index e87dff5d1..28b30d1f3 100644 --- a/docs/en/README.txt +++ b/docs/en/README.txt @@ -6,7 +6,7 @@ Copyright 2002-2019 by various contributors; see AUTHORS.txt http://www.tuxpaint.org/ - June 14, 2002 - April 3, 2019 + June 14, 2002 - September 12, 2019 ---------------------------------------------------------------------- @@ -375,6 +375,16 @@ Available Tools left [Alt] * Thai — right [Alt] + ---------------------------------------------------------------------- + + Fill + + The 'Fill' tool 'flood-fills' a contiguous area of your + drawing with a solid color of your choice. + + Note: Prior to Tux Paint 0.9.24, this was a "Magic" tool + (see below). + ---------------------------------------------------------------------- Magic (Special Effects) diff --git a/docs/en/html/README.html b/docs/en/html/README.html index 049cd4c96..5ac5e6efc 100644 --- a/docs/en/html/README.html +++ b/docs/en/html/README.html @@ -22,7 +22,7 @@ version

June 14, 2002 - - April 3, 2019

+ September 12, 2019

@@ -507,6 +507,17 @@ version
+
Fill
+
+ + +

The 'Fill' tool 'flood-fills' a contiguous area of your drawing + with a solid color of your choice.

+ +

Note: Prior to Tux Paint 0.9.24, this was a "Magic" tool (see below).

+ +
+
Magic (Special Effects)
diff --git a/docs/html/images/tool_fill.png b/docs/html/images/tool_fill.png new file mode 100644 index 0000000000000000000000000000000000000000..5507f67af2f273005e9c9627ac0d800211c3f08f GIT binary patch literal 3049 zcmVs)f)@}5H0^P_po%^&+0-}8R>;~jmK#Y02;7wXngy0Xs2>-&2PnRKGZo;ego zJP)8h9XwWT1h$R<=bY6i0w);y4^QpM=L;J)Uh?Iye=iJzBS%JFBc>?gb5>MR+o zKOH>Q3CJ)HK7TYtQ|iukWgI_<{BXfyjBzs=Ka4Kecrg+E*&R zEkHwm9Z%`WI4bLEKa3FO39BpK_9m~{002@-Ykk9Y@7a9$RRF-u!O7mC^)eu&FrRbk z%}^2mEkHqN4v$Wyz4KkJ9~!jiW@Gxir*H7!L?QA?MbcaTYi{Iu(S*brg!o3&WESKK_?<^2Oys zKIZ^}WvD&-{Nptj*Qzsbeft%SM*a6s?7r;_-?`+ncLBiFmkpeI{>I~Dqs>O0h3nNB z5fKq0(vF+UbpgQI^EST!`faNQ&P@?{L3DJy3ILX*_rC4ymCMQ+0EWkAT5}>GLTDHf zFa?$H6h)ENPFJBPmoH{>U3cE`)r&5@+}`^5tzW5}c1Al7dw$!f&4gjF z=kZ_v?zfKs010)&8G5CH;Oi!sFyHR{!+%U9$J z-OLOEVc|Qm6z$1OWsAwNh+^iLG-1 zK&=_*rWeNU46*lUtsF)CPH-lW(|>)>34T0}=JNsI(#`Lz*JdmRvbabgS;9~$ zWu>%rOB5naPELr(jW>TPj3A0sNQRKDTLq!f#;}brL{za}`pFr6@u~Kmjm@HH+AE z7)QIKTt|O;`$v@4Q5bfhN%3W}*;T98)T=W{n6i@kFDWZqs#>BQ5s?}lei;B9SGy4h zPNae)+aa)sMgSYvR(!41Lag+xtA}^~7!gx? z9LIU`xfhkfr-lyMbTu-3h+q}Y}%o<*4l9v^;K4{Sz9O+Em@B|aDNc^&mMl& z4^5*PR_k81+N{-@o)<)+Awr#TRnw0UFzHMsKP7e?x~euKOCHoX7+O zKm=ICFa(kD0#k4J)oOEQrrxM~z8@~>D^MZl+HFvpN^ZIROGwmgGyvePU5_}fYX|yU z3#0`F;>}k&sl`ypxw<=_fjI2ZUcdJGfBMkYf7S}E@3Wi&b`p+S;F9fNYhD28&S!LQ zF^lOAnh*)oCmDnwZk`Io020X(Om_c;i9v5MOXZ$iLSMYA7X$%d0FLz*7C3R)ykX$E zy@T^s+KXXf5f)(k&X^n~VurBXlhfty98r9@NRMJMu~sjH*~=@uZ_|bsp5LD~@B7u0 zH{bf1)0Zwc0sz1Q9hF%;NlQ3@S@RNMxjUyFP34|k-8X<>&pYWeY*&>Q-!1mP@U0(Q z@xBk*mYc~8oO>Psun2(VpuMsHpyW55qui5oG!X!t(N~=Nm{mFvZdSYifYOfRW^56G zcV9TLZ||T8K-yI?F*S^DEVUT$%?Zpn&lFY&a5dcNF ztWp5`^~2F>X{9((4~0cq&=Z?4;y-@d=Qm$*H2`SGiQ_p9>^YSVXMk3k6?<+Jk)@TQ zqZOpzhgL4@eP!slJv7B#5k#;f#8PaE`(X+e_t7pio?5`k1PW?>OwS-Gs&-i?oQ z{gq9ii1&svuVV^8M}h%Zu+k9_tzoU8EXBDGM1&!p%<$^|Qu_HkIm7})hIj8h3R-7#8OPDeX3vvugN&3fQ<1L$ZA0u(Z|v^P`f&deRHlOg+zV;XsH rTzQ@6=u={dn3b$!Dj+V*iJAWg@^aP+9^G@j00000NkvXXu0mjf9_Y6C literal 0 HcmV?d00001 diff --git a/magic/magic-docs/src/magic-docs.php b/magic/magic-docs/src/magic-docs.php index ef3d98765..00c9a7991 100644 --- a/magic/magic-docs/src/magic-docs.php +++ b/magic/magic-docs/src/magic-docs.php @@ -5,7 +5,7 @@ individual HTML files for each of them, and an index.html that links to them all. */ /* Bill Kendrick */ -/* Oct. 8, 2009 - August 30, 2018 */ +/* Oct. 8, 2009 - September 12, 2019 */ /* Authors of the Magic tools: */ @@ -114,10 +114,6 @@ $tools = array( 'author'=>$AUTHOR_KENDRICK, 'see'=>array('Edges', 'Silhouette')), - array('name'=>'Fill', - 'desc'=>'This floods the picture with a color. It lets you quickly fill parts of the picture, as if it were a coloring book.', - 'author'=>$AUTHOR_KENDRICK), - array('name'=>'Fisheye', 'desc'=>'Warp parts of your picture like it\'s being seen through a fisheye lens.', 'author'=>$AUTHOR_ADAMR), diff --git a/magic/src/fill.c b/magic/src/fill.c deleted file mode 100644 index 75f4fda12..000000000 --- a/magic/src/fill.c +++ /dev/null @@ -1,268 +0,0 @@ -/* - fill.c - - Fill Magic Tool Plugin - Tux Paint - A simple drawing program for children. - - Copyright (c) 2002-2008 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: July 8, 2008 - $Id$ -*/ - -#include -#include -#include "tp_magic_api.h" -#include "SDL_image.h" - - -/* Our globals: */ - -static Mix_Chunk *fill_snd; -static Uint8 fill_r, fill_g, fill_b; - -/* Local function prototypes: */ - -static int colors_close(magic_api * api, SDL_Surface * canvas, Uint32 c1, Uint32 c2); -static void do_flood_fill(magic_api * api, SDL_Surface * canvas, int x, int y, Uint32 cur_colr, Uint32 old_colr); -int fill_modes(magic_api * api, int which); -void fill_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas); -void fill_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas); -int fill_requires_colors(magic_api * api, int which); -void fill_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b); -void fill_shutdown(magic_api * api); -void fill_release(magic_api * api, int which, - SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect); -void fill_click(magic_api * api, int which, int mode, - SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect); -void fill_drag(magic_api * api, int which, SDL_Surface * canvas, - SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect); -char *fill_get_description(magic_api * api, int which, int mode); -char *fill_get_name(magic_api * api, int which); -int fill_get_tool_count(magic_api * api); -SDL_Surface *fill_get_icon(magic_api * api, int which); -Uint32 fill_api_version(void); -int fill_init(magic_api * api); - - -// No setup required: -int fill_init(magic_api * api) -{ - char fname[1024]; - - snprintf(fname, sizeof(fname), "%s/sounds/magic/fill.wav", api->data_directory); - fill_snd = Mix_LoadWAV(fname); - - return (1); -} - -Uint32 fill_api_version(void) -{ - return (TP_MAGIC_API_VERSION); -} - -// We have multiple tools: -int fill_get_tool_count(magic_api * api ATTRIBUTE_UNUSED) -{ - return (1); -} - -// Load our icons: -SDL_Surface *fill_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED) -{ - char fname[1024]; - - snprintf(fname, sizeof(fname), "%s/images/magic/fill.png", api->data_directory); - - return (IMG_Load(fname)); -} - -// Return our names, localized: -char *fill_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) -{ - return (strdup(gettext_noop("Fill"))); -} - -// Return our descriptions, localized: -char *fill_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED) -{ - return (strdup(gettext_noop("Click in the picture to fill that area with color."))); -} - - -// Affect the canvas on drag: -void fill_drag(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, - SDL_Surface * last ATTRIBUTE_UNUSED, int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, - int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED) -{ -} - -// Affect the canvas on click: -void fill_click(magic_api * api, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, - SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, - int x, int y, SDL_Rect * update_rect) -{ - do_flood_fill(api, canvas, x, y, SDL_MapRGB(canvas->format, fill_r, fill_g, fill_b), api->getpixel(canvas, x, y)); - - update_rect->x = 0; - update_rect->y = 0; - update_rect->w = canvas->w; - update_rect->h = canvas->h; -} - -void fill_release(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, - SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, - int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED) -{ -} - -void fill_shutdown(magic_api * api ATTRIBUTE_UNUSED) -{ - Mix_FreeChunk(fill_snd); -} - -// Record the color from Tux Paint: -void fill_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b) -{ - fill_r = r; - fill_g = g; - fill_b = b; -} - -// Use colors: -int fill_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) -{ - return 1; -} - - -static int colors_close(magic_api * api, 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 = api->sRGB_to_linear(r1) - api->sRGB_to_linear(r2); - r *= r; - g = api->sRGB_to_linear(g1) - api->sRGB_to_linear(g2); - g *= g; - b = api->sRGB_to_linear(b1) - api->sRGB_to_linear(b2); - b *= b; - - // easy to confuse: - // dark grey, brown, purple - // light grey, tan - // red, orange - return r + g + b < 0.04; - } -} - - -static void do_flood_fill(magic_api * api, SDL_Surface * canvas, int x, int y, Uint32 cur_colr, Uint32 old_colr) -{ - int fillL, fillR, i, in_line; - static unsigned char prog_anim; - - - if (cur_colr == old_colr || colors_close(api, canvas, cur_colr, old_colr)) - return; - - - fillL = x; - fillR = x; - - prog_anim++; - if ((prog_anim % 4) == 0) - { - api->update_progress_bar(); - api->playsound(fill_snd, (x * 255) / canvas->w, 255); - } - - - /* Find left side, filling along the way */ - - in_line = 1; - - while (in_line) - { - api->putpixel(canvas, fillL, y, cur_colr); - fillL--; - - in_line = (fillL < 0) ? 0 : colors_close(api, canvas, api->getpixel(canvas, fillL, y), old_colr); - } - - fillL++; - - /* Find right side, filling along the way */ - - in_line = 1; - while (in_line) - { - api->putpixel(canvas, fillR, y, cur_colr); - fillR++; - - in_line = (fillR >= canvas->w) ? 0 : colors_close(api, canvas, api->getpixel(canvas, fillR, y), old_colr); - } - - fillR--; - - - /* Search top and bottom */ - - for (i = fillL; i <= fillR; i++) - { - if (y > 0 && colors_close(api, canvas, api->getpixel(canvas, i, y - 1), old_colr)) - do_flood_fill(api, canvas, i, y - 1, cur_colr, old_colr); - - if (y < canvas->h && colors_close(api, canvas, api->getpixel(canvas, i, y + 1), old_colr)) - do_flood_fill(api, canvas, i, y + 1, cur_colr, old_colr); - } -} - -void fill_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, - SDL_Surface * canvas ATTRIBUTE_UNUSED) -{ -} - -void fill_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, - SDL_Surface * canvas ATTRIBUTE_UNUSED) -{ -} - -int fill_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) -{ - return (MODE_PAINT); -} diff --git a/src/fill.c b/src/fill.c new file mode 100644 index 000000000..2fce7d215 --- /dev/null +++ b/src/fill.c @@ -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 +#include +#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); + } +} + diff --git a/src/fill.h b/src/fill.h new file mode 100644 index 000000000..2e37a09aa --- /dev/null +++ b/src/fill.h @@ -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); + diff --git a/src/manpage/tuxpaint.1 b/src/manpage/tuxpaint.1 index 6c1df5f09..0c4a2535a 100644 --- a/src/manpage/tuxpaint.1 +++ b/src/manpage/tuxpaint.1 @@ -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 diff --git a/src/sounds.h b/src/sounds.h index ed850f74c..bdbde6e2c 100644 --- a/src/sounds.h +++ b/src/sounds.h @@ -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 diff --git a/src/tools.h b/src/tools.h index 0336e27fc..99d55c1cd 100644 --- a/src/tools.h +++ b/src/tools.h @@ -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", diff --git a/src/tuxpaint.c b/src/tuxpaint.c index 2435b4884..7976db2f6 100644 --- a/src/tuxpaint.c +++ b/src/tuxpaint.c @@ -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)