diff --git a/docs/AUTHORS.txt b/docs/AUTHORS.txt index 941c853ac..45a4c67de 100644 --- a/docs/AUTHORS.txt +++ b/docs/AUTHORS.txt @@ -7,7 +7,7 @@ Various contributors (see below, and CHANGES.txt) http://www.tuxpaint.org/ -June 17, 2002 - February 10, 2021 +June 17, 2002 - February 15, 2021 $Id$ @@ -358,6 +358,11 @@ $Id$ * Cartoon * "cartoon6.wav" from http://www.grsites.com/ + * Checkerboard + * Horse gallop from + https://bigsoundbank.com/detail-0611-horse-gallop.html + Creative Commons CC0 1.0 Universal + * Clone * https://commons.wikimedia.org/wiki/File:Sheep_bleating.ogg Public domain diff --git a/docs/CHANGES.txt b/docs/CHANGES.txt index 792c6bfe6..939735ff4 100644 --- a/docs/CHANGES.txt +++ b/docs/CHANGES.txt @@ -8,7 +8,7 @@ http://www.tuxpaint.org/ $Id$ -2021.February.10 (0.9.26) +2021.February.15 (0.9.26) * New Features ------------ * [WIP] Larger UI buttons @@ -21,12 +21,16 @@ $Id$ * New Magic Tools: ---------------- - * Pixels - Draws large squares, for classic computer 'pixel art' style drawings. + * Checkerboard + Cover the entire canvas with a checkboard pattern using the + current color. Drag to change the size of the squares. * Clone Clones (copies, via painting) part of a drawing to another position. + * Pixels + Draws large squares, for classic computer 'pixel art' style drawings. + * Documentation updates --------------------- * Documentation is now maintained in a separate source repository, diff --git a/magic/icons/checkerboard.png b/magic/icons/checkerboard.png new file mode 100644 index 000000000..711588474 Binary files /dev/null and b/magic/icons/checkerboard.png differ diff --git a/magic/magic-docs/en/checkerboard.txt b/magic/magic-docs/en/checkerboard.txt new file mode 100644 index 000000000..16ec5518c --- /dev/null +++ b/magic/magic-docs/en/checkerboard.txt @@ -0,0 +1,6 @@ + Tux Paint "Magic" Tool: Checkerboard + + By Bill Kendrick + + This covers the entire canvas with a checkboard pattern using the current + color. Drag to change the size of the squares. diff --git a/magic/magic-docs/en/html/checkerboard.html b/magic/magic-docs/en/html/checkerboard.html new file mode 100644 index 000000000..c50146ba9 --- /dev/null +++ b/magic/magic-docs/en/html/checkerboard.html @@ -0,0 +1,9 @@ + +Tux Paint "Magic" Tool: Checkerboard + + + +

Tux Paint "Magic" Tool: Checkerboard

+

By Bill Kendrick <bill@newbreedsoftware.com>

+

This covers the entire canvas with a checkboard pattern using the current color. Drag to change the size of the squares.

+ \ No newline at end of file diff --git a/magic/magic-docs/en/html/index.html b/magic/magic-docs/en/html/index.html index 08ea33072..ed77bc230 100644 --- a/magic/magic-docs/en/html/index.html +++ b/magic/magic-docs/en/html/index.html @@ -11,6 +11,7 @@
  • Calligraphy
  • Cartoon
  • Chalk
  • +
  • Checkerboard
  • Clone
  • Color and White
  • Color Shift
  • diff --git a/magic/magic-docs/en/index.txt b/magic/magic-docs/en/index.txt index 0d017e19c..667124e6b 100644 --- a/magic/magic-docs/en/index.txt +++ b/magic/magic-docs/en/index.txt @@ -7,6 +7,7 @@ * Calligraphy * Cartoon * Chalk + * Checkerboard * Clone * Color and White * Color Shift diff --git a/magic/magic-docs/src/magic-docs.php b/magic/magic-docs/src/magic-docs.php index ec6b237f3..2904c7b98 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 - January 10, 2020 */ +/* Oct. 8, 2009 - February 15, 2020 */ /* Authors of the Magic tools: */ @@ -80,6 +80,10 @@ $tools = array( 'desc'=>'This makes parts of the picture (where you move the mouse) look like a chalk drawing.', 'author'=>$AUTHOR_KENDRICK), + array('name'=>'Checkerboard', + 'desc'=>'This covers the entire canvas with a checkboard pattern using the current color. Drag to change the size of the squares.', + 'author'=>$AUTHOR_KENDRICK), + array('name'=>'Clone', 'desc'=>'Clone (copy, via painting) part of the picture. Click ones to choose the source, then click and drag to clone it elsewhere in the drawing. Once you release, click to choose another source and start again.', 'author'=>$AUTHOR_KENDRICK), diff --git a/magic/sounds/checkerboard.ogg b/magic/sounds/checkerboard.ogg new file mode 100644 index 000000000..587dccf6f Binary files /dev/null and b/magic/sounds/checkerboard.ogg differ diff --git a/magic/src/blind.c b/magic/src/blind.c index 1cf01857a..9ca509699 100644 --- a/magic/src/blind.c +++ b/magic/src/blind.c @@ -1,13 +1,12 @@ /* blind.c -// + BLIND Magic Tools Plugin Tux Paint - A simple drawing program for children. By Pere Pujal Carabantes - Copyright (c) 2002-2009 by Bill Kendrick and others; see AUTHORS.txt - bill@newbreedsoftware.com + Copyright (c) 2009-2021 http://www.tuxpaint.org/ This program is free software; you can redistribute it and/or modify @@ -275,20 +274,20 @@ void blind_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED, { if (x < y) - blind_side = 1; /* left */ + blind_side = BLIND_SIDE_LEFT; else if (canvas->w - x < y) - blind_side = 3; /* right */ + blind_side = BLIND_SIDE_RIGHT; else - blind_side = 0; /* top */ + blind_side = BLIND_SIDE_TOP; } else { if (x < canvas->h - y) - blind_side = 1; /* left */ + blind_side = BLIND_SIDE_LEFT; else if (canvas->w - x < canvas->h - y) - blind_side = 3; /* right */ + blind_side = BLIND_SIDE_RIGHT; else - blind_side = 2; /* bottom */ + blind_side = BLIND_SIDE_BOTTOM; } blind_drag(api, which, canvas, last, x, y, x, y, update_rect); diff --git a/magic/src/checkerboard.c b/magic/src/checkerboard.c new file mode 100644 index 000000000..692fbae4d --- /dev/null +++ b/magic/src/checkerboard.c @@ -0,0 +1,245 @@ +/* + checkeroard.c + + "Checkerboard" Magic Tools Plugin + Tux Paint - A simple drawing program for children. + + By Bill Kendrick + Based on `blind.c` by Pere Pujal Carabantes + + Copyright (c) 2021 + http://www.tuxpaint.org/ + + 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) +*/ + +#include "tp_magic_api.h" +#include "SDL_image.h" +#include "SDL_mixer.h" + +static Uint8 checkerboard_r, checkerboard_g, checkerboard_b; +int checkerboard_start_x, checkerboard_start_y; + +Mix_Chunk *checkerboard_snd; + +// Prototypes +Uint32 checkerboard_api_version(void); +void checkerboard_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b); +int checkerboard_init(magic_api * api); +int checkerboard_get_tool_count(magic_api * api); +SDL_Surface *checkerboard_get_icon(magic_api * api, int which); +char *checkerboard_get_name(magic_api * api, int which); +char *checkerboard_get_description(magic_api * api, int which, int mode); +int checkerboard_requires_colors(magic_api * api, int which); +void checkerboard_release(magic_api * api, int which, + SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect); +void checkerboard_shutdown(magic_api * api); +void checkerboard_paint_checkerboard(void *ptr_to_api, int which_tool, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y); +void checkerboard_drag(magic_api * api, int which, SDL_Surface * canvas, + SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect); +void checkerboard_click(magic_api * api, int which, int mode, + SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect); +void checkerboard_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas); +void checkerboard_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas); +int checkerboard_modes(magic_api * api, int which); + +// Housekeeping functions + +Uint32 checkerboard_api_version(void) +{ + return (TP_MAGIC_API_VERSION); +} + +void checkerboard_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b) //get the colors from API and store it in structure +{ + checkerboard_r = r; + checkerboard_g = g; + checkerboard_b = b; +} + +int checkerboard_init(magic_api * api) +{ + char fname[1024]; + + snprintf(fname, sizeof(fname), "%s/sounds/magic/checkerboard.ogg", api->data_directory); + checkerboard_snd = Mix_LoadWAV(fname); + + return (1); +} + +int checkerboard_get_tool_count(magic_api * api ATTRIBUTE_UNUSED) +{ + return 1; +} + +SDL_Surface *checkerboard_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED) +{ + char fname[1024]; + + snprintf(fname, sizeof(fname), "%s/images/magic/checkerboard.png", api->data_directory); + + return (IMG_Load(fname)); +} + +char *checkerboard_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) +{ + return strdup(gettext_noop("Checkerboard")); +} + +char *checkerboard_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED) +{ + return + strdup(gettext_noop + ("Click and drag to fill the canvas with a checkerboard pattern.")); +} + +int checkerboard_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) +{ + return 1; +} + +void checkerboard_release(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, + SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * snapshot ATTRIBUTE_UNUSED, + int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED) +{ +} + +void checkerboard_shutdown(magic_api * api ATTRIBUTE_UNUSED) +{ + Mix_FreeChunk(checkerboard_snd); +} + +// Interactivity functions + +void checkerboard_drag(magic_api * api, int which, SDL_Surface * canvas, + SDL_Surface * snapshot, + int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, + int x, int y, SDL_Rect * update_rect) +{ + int sz, xx, yy; + Uint8 draw_start, draw_row, draw_cell; + Uint32 colr; + SDL_Rect dest; + + SDL_BlitSurface(snapshot, NULL, canvas, NULL); + + sz = max(10, max(abs(x - checkerboard_start_x), abs(y - checkerboard_start_y))); + + colr = SDL_MapRGB(canvas->format, checkerboard_r, checkerboard_g, checkerboard_b); + + draw_start = 1; + if (x < checkerboard_start_x) + draw_start = !draw_start; + if (y < checkerboard_start_y) + draw_start = !draw_start; + + /* From the mouse Y position down... */ + draw_row = draw_start; + for (yy = checkerboard_start_y; yy <= canvas->h; yy += sz) { + /* From the mouse X position right... */ + draw_cell = draw_row; + for (xx = checkerboard_start_x; xx <= canvas->w; xx += sz) { + if (draw_cell) { + dest.x = xx; + dest.y = yy; + dest.w = sz; + dest.h = sz; + SDL_FillRect(canvas, &dest, colr); + } + draw_cell = !draw_cell; + } + + /* From the mouse X position left... */ + draw_cell = !draw_row; + for (xx = checkerboard_start_x - sz; xx > -sz; xx -= sz) { + if (draw_cell) { + dest.x = xx; + dest.y = yy; + dest.w = sz; + dest.h = sz; + SDL_FillRect(canvas, &dest, colr); + } + draw_cell = !draw_cell; + } + + draw_row = !draw_row; + } + + /* From the mouse Y position up... */ + draw_row = !draw_start; + for (yy = checkerboard_start_y - sz; yy > -sz; yy -= sz) { + /* From the mouse X position right... */ + draw_cell = draw_row; + for (xx = checkerboard_start_x; xx <= canvas->w; xx += sz) { + if (draw_cell) { + dest.x = xx; + dest.y = yy; + dest.w = sz; + dest.h = sz; + SDL_FillRect(canvas, &dest, colr); + } + draw_cell = !draw_cell; + } + + /* From the mouse X position left... */ + draw_cell = !draw_row; + for (xx = checkerboard_start_x - sz; xx > -sz; xx -= sz) { + if (draw_cell) { + dest.x = xx; + dest.y = yy; + dest.w = sz; + dest.h = sz; + SDL_FillRect(canvas, &dest, colr); + } + draw_cell = !draw_cell; + } + + draw_row = !draw_row; + } + + /* Always applies to the whole screen! */ + update_rect->x = 0; + update_rect->y = 0; + update_rect->w = canvas->w; + update_rect->h = canvas->h; + + api->playsound(checkerboard_snd, 128, 255); +} + +void checkerboard_click(magic_api * api, int which, int mode, + SDL_Surface * canvas, SDL_Surface * last, + int x, int y, + SDL_Rect * update_rect) +{ + checkerboard_start_x = x; + checkerboard_start_y = y; + checkerboard_drag(api, which, canvas, last, x, y, x, y, update_rect); +} + +void checkerboard_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, + SDL_Surface * canvas ATTRIBUTE_UNUSED) +{ +} + +void checkerboard_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, + SDL_Surface * canvas ATTRIBUTE_UNUSED) +{ +} + +int checkerboard_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) +{ + return (MODE_PAINT); +}