diff --git a/docs/AUTHORS.txt b/docs/AUTHORS.txt index f5fe4b435..e3a660645 100644 --- a/docs/AUTHORS.txt +++ b/docs/AUTHORS.txt @@ -6,11 +6,7 @@ Copyright (c) 2002-2021 Various contributors (see below, and CHANGES.txt) http://www.tuxpaint.org/ - -June 17, 2002 - September 17, 2021 - -$Id$ - +June 17, 2002 - September 26, 2021 * Design and Coding: @@ -390,97 +386,102 @@ $Id$ http://commons.wikimedia.org/wiki/Image:FD_pip_socandecho_call.ogg Dual licensed CC-BY-SA and GFDL. - * Color Shift sound (alien.ogg) - Caroline Ford 2008 based on - Sound translation of Saturn radio transmissions from Cassini. - http://commons.wikimedia.org/wiki/Image:Saturn_sound.ogg - Public domain. + * Color Shift sound (alien.ogg) + Caroline Ford 2008 based on + Sound translation of Saturn radio transmissions from Cassini. + http://commons.wikimedia.org/wiki/Image:Saturn_sound.ogg + Public domain. - * String tools sound (string.ogg) - Caroline Ford 2009 cropped from - http://soundbible.com/170-Elves-Laughing-High-Pitch.html - Elves Laughing High Pitch by Mike Koenig - Creative Commons attribution licence 3.0 + * String tools sound (string.ogg) + Caroline Ford 2009 cropped from + http://soundbible.com/170-Elves-Laughing-High-Pitch.html + Elves Laughing High Pitch by Mike Koenig + Creative Commons attribution licence 3.0 - * Real rainbow sound (realrainbow.org) - Caroline Ford 2009 cropped from - http://soundbible.com/474-Magic-Wand-Noise.html - Magic Wand Noise Sounds by Mike Koenig - Creative Commons attribution licence 3.0 + * Real rainbow sound (realrainbow.org) + Caroline Ford 2009 cropped from + http://soundbible.com/474-Magic-Wand-Noise.html + Magic Wand Noise Sounds by Mike Koenig + Creative Commons attribution licence 3.0 - * Fisheye sound (fisheye.ogg) - Caroline Ford 2009 cropped from - http://http://soundbible.com/146-UFO-Exit.html - UFO Exit by Stephan - Public domain. + * Fisheye sound (fisheye.ogg) + Caroline Ford 2009 cropped from + http://http://soundbible.com/146-UFO-Exit.html + UFO Exit by Stephan + Public domain. - * Distortion sound (distortion.ogg) - Caroline Ford 2009 cropped from - http://soundbible.com/366-Alien-Creatures.html - Alien Creatures by Mike Koenig - Creative Commons attribution licence 3.0 + * Distortion sound (distortion.ogg) + Caroline Ford 2009 cropped from + http://soundbible.com/366-Alien-Creatures.html + Alien Creatures by Mike Koenig + Creative Commons attribution licence 3.0 - * Rain sound (rain.ogg) - Caroline Ford 2009 cropped from - http://soundbible.com/431-Pouring-Rain-On-Cement.html - Pouring rain on cement by Mike Koenig - Creative Commons attribution licence 3.0 + * Rain sound (rain.ogg) + Caroline Ford 2009 cropped from + http://soundbible.com/431-Pouring-Rain-On-Cement.html + Pouring rain on cement by Mike Koenig + Creative Commons attribution licence 3.0 - * Confetti sound (confetti.ogg) - http://soundbible.com/419-Tiny-Button-Push.html - Tiny button push sound by Mike Koenig - Creative Commons attribution licence 3.0 + * Confetti sound (confetti.ogg) + http://soundbible.com/419-Tiny-Button-Push.html + Tiny button push sound by Mike Koenig + Creative Commons attribution licence 3.0 - * Silhouette sound (silhouette.ogg) - http://soundbible.com/417-Right-Channel-Scramble.html - Right channel scramble by Mike Koenig - Creative Commons attribution licence 3.0 + * Silhouette sound (silhouette.ogg) + http://soundbible.com/417-Right-Channel-Scramble.html + Right channel scramble by Mike Koenig + Creative Commons attribution licence 3.0 - * Calligraphy sound (calligraphy.ogg) - http://soundbible.com/214-Tearing-Paper.html - Tearing Paper by Mike Koenig - Creative Commons attribution licence 3.0 + * Calligraphy sound (calligraphy.ogg) + http://soundbible.com/214-Tearing-Paper.html + Tearing Paper by Mike Koenig + Creative Commons attribution licence 3.0 - * Fold sound (fold.ogg) - http://soundbible.com/341-Ping-Pong-Game.html - Ping pong game by Aldor cropped by Caroline Ford - Public domain. + * Fold sound (fold.ogg) + http://soundbible.com/341-Ping-Pong-Game.html + Ping pong game by Aldor cropped by Caroline Ford + Public domain. - * Picasso sound (picasso.ogg) - http://soundbible.com/171-Alien-Brain-Scanner.html - Cropped from Alien Brain Scanner by Mike Koenig - Creative Commons Attribution 3.0 + * Picasso sound (picasso.ogg) + http://soundbible.com/171-Alien-Brain-Scanner.html + Cropped from Alien Brain Scanner by Mike Koenig + Creative Commons Attribution 3.0 - * Mosaic sound (mosaic.ogg) - http://soundbible.com/171-Alien-Brain-Scanner.html - Cropped from Alien Brain Scanner by Mike Koenig - Altered in audacity by Caroline Ford - Creative Commons Attribution 3.0 + * Mosaic sound (mosaic.ogg) + http://soundbible.com/171-Alien-Brain-Scanner.html + Cropped from Alien Brain Scanner by Mike Koenig + Altered in audacity by Caroline Ford + Creative Commons Attribution 3.0 - * toothpaste sound (toothpaste.ogg) - Based on squishy 2 by Mike Koenig - Reversed and pitch shifted in audacity by C Ford - http://soundbible.com/512-Squishy-2.html - Creative Commons Attribution 3.0 + * toothpaste sound (toothpaste.ogg) + Based on squishy 2 by Mike Koenig + Reversed and pitch shifted in audacity by C Ford + http://soundbible.com/512-Squishy-2.html + Creative Commons Attribution 3.0 - * tv sound (tv.ogg) - One second of white noise generated by audacity - Uploaded by C Ford. - PD + * tv sound (tv.ogg) + One second of white noise generated by audacity + Uploaded by C Ford. + PD - * string2.ogg and string3.ogg - Made messing around in audacity by C Ford. - PD + * string2.ogg and string3.ogg + Made messing around in audacity by C Ford. + PD - * snowball.ogg - Cropped by C Ford from original by Mike Koenig - http://soundbible.com/632-Snow-Ball-Throw-And-Splat.html - Creative Commons Attribution 3.0 + * snowball.ogg + Cropped by C Ford from original by Mike Koenig + http://soundbible.com/632-Snow-Ball-Throw-And-Splat.html + Creative Commons Attribution 3.0 - * snowflake.ogg - Cropped by C Ford from original by Mike Koenig - http://soundbible.com/633-Snowing.html - Creative Commons Attribution 3.0 + * snowflake.ogg + Cropped by C Ford from original by Mike Koenig + http://soundbible.com/633-Snowing.html + Creative Commons Attribution 3.0 + + * lightning.ogg + Jonathan Hunt, CC BY-SA 4.0 + via Wikimedia Commons + https://commons.wikimedia.org/wiki/File:Thunder_Claps.ogg * Translations diff --git a/docs/CHANGES.txt b/docs/CHANGES.txt index 1d4197a4f..7b7a7aaf2 100644 --- a/docs/CHANGES.txt +++ b/docs/CHANGES.txt @@ -11,6 +11,9 @@ $Id$ 2021.September.26 (0.9.27) * New Magic Tools: ---------------- + * WIP "Lightning" - Draws a bolt of lightning striking between + the start and end positions of a line. + * "Opposite" -- Change parts of the picture to their complementary colors. (Similar to "Negative", but instead of inverting the Red, Green, and Blue components, it rotates the Hue 180 degrees diff --git a/magic/icons/lightning.png b/magic/icons/lightning.png new file mode 100644 index 000000000..ce563675e Binary files /dev/null and b/magic/icons/lightning.png differ diff --git a/magic/sounds/lightning.ogg b/magic/sounds/lightning.ogg new file mode 100644 index 000000000..db63c5ef9 Binary files /dev/null and b/magic/sounds/lightning.ogg differ diff --git a/magic/src/lightning.c b/magic/src/lightning.c new file mode 100644 index 000000000..c60b22a33 --- /dev/null +++ b/magic/src/lightning.c @@ -0,0 +1,168 @@ +/* lightning.c + + Draws a lightning strike between the click + and drag+release positions. + + Last modified: 2021.09.26 +*/ + +#include +#include +#include + +#include "tp_magic_api.h" +#include "SDL_image.h" +#include "SDL_mixer.h" + +Mix_Chunk *snd_effect; +Uint8 lightning_r, lightning_g, lightning_b; +int sx, sy; + + +void lightning_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 lightning_line_callback_drag(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y); +void lightning_line_callback_release(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y); + + +Uint32 lightning_api_version(void) +{ + return (TP_MAGIC_API_VERSION); +} + +int lightning_init(magic_api * api) +{ + char fname[1024]; + + snprintf(fname, sizeof(fname), "%s/sounds/magic/lightning.ogg", api->data_directory); + snd_effect = Mix_LoadWAV(fname); + + return (1); +} + +int lightning_get_tool_count(magic_api * api) +{ + return (1); +} + + +SDL_Surface *lightning_get_icon(magic_api * api, int which) +{ + char fname[1024]; + + snprintf(fname, sizeof(fname), "%s/images/magic/lightning.png", api->data_directory); + + return (IMG_Load(fname)); +} + +char *lightning_get_name(magic_api * api, int which) +{ + return strdup(gettext("Lightning")); +} + +int lightning_get_group(magic_api * api, int which) +{ + return MAGIC_TYPE_ARTISTIC; +} + +char *lightning_get_description(magic_api * api, int which, int mode) +{ + return strdup(gettext("Click, drag, and release to a lightning bolt between two points.")); +} + +int lightning_requires_colors(magic_api * api, int which) +{ + return 1; +} + +int lightning_modes(magic_api * api, int which) +{ + return MODE_PAINT; +} + +void lightning_shutdown(magic_api * api) +{ + if (snd_effect != NULL) + Mix_FreeChunk(snd_effect); +} + + +void +lightning_click(magic_api * api, int which, int mode, + SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect) +{ + sx = x; + sy = y; + lightning_drag(api, which, canvas, snapshot, x, y, x, y, update_rect); +} + + +void +lightning_drag(magic_api * api, int which, SDL_Surface * canvas, + SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect) +{ + /* FIXME: This could be made more efficient + (only blit and update between (sx,sy) and (x,y), though + it should also cover the area extending to (ox,oy), + to avoid leaving trails */ + update_rect->x = 0; + update_rect->y = 0; + update_rect->w = canvas->w; + update_rect->h = canvas->h; + + SDL_BlitSurface(snapshot, update_rect, canvas, update_rect); + + api->line((void *)api, which, canvas, snapshot, sx, sy, x, y, 1, lightning_line_callback_drag); +} + + +void +lightning_release(magic_api * api, int which, + SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect) +{ + /* FIXME: This could be made more efficient + (only blit and update between (sx,sy) and (x,y), though + it should also cover the area extending to (ox,oy), + to avoid leaving trails */ + update_rect->x = 0; + update_rect->y = 0; + update_rect->w = canvas->w; + update_rect->h = canvas->h; + + SDL_BlitSurface(snapshot, update_rect, canvas, update_rect); + + api->line((void *)api, which, canvas, snapshot, sx, sy, x, y, 1, lightning_line_callback_release); + api->stopsound(); + api->playsound(snd_effect, (x * 255) / canvas->w, 255); +} + +void lightning_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b) +{ + lightning_r = r; + lightning_g = g; + lightning_b = b; +} + + +void lightning_line_callback_drag(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y) +{ + magic_api *api = (magic_api *) ptr; + + api->xorpixel(canvas, x, y); +} + +void lightning_line_callback_release(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y) +{ + magic_api *api = (magic_api *) ptr; + + // FIXME + api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, lightning_r, lightning_g, lightning_b)); +} + +void lightning_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas) +{ +} + +void lightning_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas) +{ +}