WIP Lightning Magic tool

UI, icon, sfx working; not actually rendering the bolt yet.
This commit is contained in:
Bill Kendrick 2021-09-26 22:50:41 -07:00
parent e6a15fbe5c
commit 2bd9b74dd6
5 changed files with 252 additions and 80 deletions

View file

@ -6,11 +6,7 @@ Copyright (c) 2002-2021
Various contributors (see below, and CHANGES.txt) Various contributors (see below, and CHANGES.txt)
http://www.tuxpaint.org/ http://www.tuxpaint.org/
June 17, 2002 - September 26, 2021
June 17, 2002 - September 17, 2021
$Id$
* Design and Coding: * Design and Coding:
@ -390,97 +386,102 @@ $Id$
http://commons.wikimedia.org/wiki/Image:FD_pip_socandecho_call.ogg http://commons.wikimedia.org/wiki/Image:FD_pip_socandecho_call.ogg
Dual licensed CC-BY-SA and GFDL. Dual licensed CC-BY-SA and GFDL.
* Color Shift sound (alien.ogg) * Color Shift sound (alien.ogg)
Caroline Ford <caroline.ford.work@googlemail.com> 2008 based on Caroline Ford <caroline.ford.work@googlemail.com> 2008 based on
Sound translation of Saturn radio transmissions from Cassini. Sound translation of Saturn radio transmissions from Cassini.
http://commons.wikimedia.org/wiki/Image:Saturn_sound.ogg http://commons.wikimedia.org/wiki/Image:Saturn_sound.ogg
Public domain. Public domain.
* String tools sound (string.ogg) * String tools sound (string.ogg)
Caroline Ford <caroline.ford.work@googlemail.com> 2009 cropped from Caroline Ford <caroline.ford.work@googlemail.com> 2009 cropped from
http://soundbible.com/170-Elves-Laughing-High-Pitch.html http://soundbible.com/170-Elves-Laughing-High-Pitch.html
Elves Laughing High Pitch by Mike Koenig Elves Laughing High Pitch by Mike Koenig
Creative Commons attribution licence 3.0 Creative Commons attribution licence 3.0
* Real rainbow sound (realrainbow.org) * Real rainbow sound (realrainbow.org)
Caroline Ford <caroline.ford.work@googlemail.com> 2009 cropped from Caroline Ford <caroline.ford.work@googlemail.com> 2009 cropped from
http://soundbible.com/474-Magic-Wand-Noise.html http://soundbible.com/474-Magic-Wand-Noise.html
Magic Wand Noise Sounds by Mike Koenig Magic Wand Noise Sounds by Mike Koenig
Creative Commons attribution licence 3.0 Creative Commons attribution licence 3.0
* Fisheye sound (fisheye.ogg) * Fisheye sound (fisheye.ogg)
Caroline Ford <caroline.ford.work@googlemail.com> 2009 cropped from Caroline Ford <caroline.ford.work@googlemail.com> 2009 cropped from
http://http://soundbible.com/146-UFO-Exit.html http://http://soundbible.com/146-UFO-Exit.html
UFO Exit by Stephan UFO Exit by Stephan
Public domain. Public domain.
* Distortion sound (distortion.ogg) * Distortion sound (distortion.ogg)
Caroline Ford <caroline.ford.work@googlemail.com> 2009 cropped from Caroline Ford <caroline.ford.work@googlemail.com> 2009 cropped from
http://soundbible.com/366-Alien-Creatures.html http://soundbible.com/366-Alien-Creatures.html
Alien Creatures by Mike Koenig Alien Creatures by Mike Koenig
Creative Commons attribution licence 3.0 Creative Commons attribution licence 3.0
* Rain sound (rain.ogg) * Rain sound (rain.ogg)
Caroline Ford <caroline.ford.work@googlemail.com> 2009 cropped from Caroline Ford <caroline.ford.work@googlemail.com> 2009 cropped from
http://soundbible.com/431-Pouring-Rain-On-Cement.html http://soundbible.com/431-Pouring-Rain-On-Cement.html
Pouring rain on cement by Mike Koenig Pouring rain on cement by Mike Koenig
Creative Commons attribution licence 3.0 Creative Commons attribution licence 3.0
* Confetti sound (confetti.ogg) * Confetti sound (confetti.ogg)
http://soundbible.com/419-Tiny-Button-Push.html http://soundbible.com/419-Tiny-Button-Push.html
Tiny button push sound by Mike Koenig Tiny button push sound by Mike Koenig
Creative Commons attribution licence 3.0 Creative Commons attribution licence 3.0
* Silhouette sound (silhouette.ogg) * Silhouette sound (silhouette.ogg)
http://soundbible.com/417-Right-Channel-Scramble.html http://soundbible.com/417-Right-Channel-Scramble.html
Right channel scramble by Mike Koenig Right channel scramble by Mike Koenig
Creative Commons attribution licence 3.0 Creative Commons attribution licence 3.0
* Calligraphy sound (calligraphy.ogg) * Calligraphy sound (calligraphy.ogg)
http://soundbible.com/214-Tearing-Paper.html http://soundbible.com/214-Tearing-Paper.html
Tearing Paper by Mike Koenig Tearing Paper by Mike Koenig
Creative Commons attribution licence 3.0 Creative Commons attribution licence 3.0
* Fold sound (fold.ogg) * Fold sound (fold.ogg)
http://soundbible.com/341-Ping-Pong-Game.html http://soundbible.com/341-Ping-Pong-Game.html
Ping pong game by Aldor cropped by Caroline Ford Ping pong game by Aldor cropped by Caroline Ford
Public domain. Public domain.
* Picasso sound (picasso.ogg) * Picasso sound (picasso.ogg)
http://soundbible.com/171-Alien-Brain-Scanner.html http://soundbible.com/171-Alien-Brain-Scanner.html
Cropped from Alien Brain Scanner by Mike Koenig Cropped from Alien Brain Scanner by Mike Koenig
Creative Commons Attribution 3.0 Creative Commons Attribution 3.0
* Mosaic sound (mosaic.ogg) * Mosaic sound (mosaic.ogg)
http://soundbible.com/171-Alien-Brain-Scanner.html http://soundbible.com/171-Alien-Brain-Scanner.html
Cropped from Alien Brain Scanner by Mike Koenig Cropped from Alien Brain Scanner by Mike Koenig
Altered in audacity by Caroline Ford Altered in audacity by Caroline Ford
Creative Commons Attribution 3.0 Creative Commons Attribution 3.0
* toothpaste sound (toothpaste.ogg) * toothpaste sound (toothpaste.ogg)
Based on squishy 2 by Mike Koenig Based on squishy 2 by Mike Koenig
Reversed and pitch shifted in audacity by C Ford Reversed and pitch shifted in audacity by C Ford
http://soundbible.com/512-Squishy-2.html http://soundbible.com/512-Squishy-2.html
Creative Commons Attribution 3.0 Creative Commons Attribution 3.0
* tv sound (tv.ogg) * tv sound (tv.ogg)
One second of white noise generated by audacity One second of white noise generated by audacity
Uploaded by C Ford. Uploaded by C Ford.
PD PD
* string2.ogg and string3.ogg * string2.ogg and string3.ogg
Made messing around in audacity by C Ford. Made messing around in audacity by C Ford.
PD PD
* snowball.ogg * snowball.ogg
Cropped by C Ford from original by Mike Koenig Cropped by C Ford from original by Mike Koenig
http://soundbible.com/632-Snow-Ball-Throw-And-Splat.html http://soundbible.com/632-Snow-Ball-Throw-And-Splat.html
Creative Commons Attribution 3.0 Creative Commons Attribution 3.0
* snowflake.ogg * snowflake.ogg
Cropped by C Ford from original by Mike Koenig Cropped by C Ford from original by Mike Koenig
http://soundbible.com/633-Snowing.html http://soundbible.com/633-Snowing.html
Creative Commons Attribution 3.0 Creative Commons Attribution 3.0
* lightning.ogg
Jonathan Hunt, CC BY-SA 4.0 <https://creativecommons.org/licenses/by-sa/4.0>
via Wikimedia Commons
https://commons.wikimedia.org/wiki/File:Thunder_Claps.ogg
* Translations * Translations

View file

@ -11,6 +11,9 @@ $Id$
2021.September.26 (0.9.27) 2021.September.26 (0.9.27)
* New Magic Tools: * 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 * "Opposite" -- Change parts of the picture to their complementary
colors. (Similar to "Negative", but instead of inverting the colors. (Similar to "Negative", but instead of inverting the
Red, Green, and Blue components, it rotates the Hue 180 degrees Red, Green, and Blue components, it rotates the Hue 180 degrees

BIN
magic/icons/lightning.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
magic/sounds/lightning.ogg Normal file

Binary file not shown.

168
magic/src/lightning.c Normal file
View file

@ -0,0 +1,168 @@
/* lightning.c
Draws a lightning strike between the click
and drag+release positions.
Last modified: 2021.09.26
*/
#include <stdio.h>
#include <string.h>
#include <libintl.h>
#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)
{
}