Distortion: Support sizes

This commit is contained in:
Bill Kendrick 2023-04-22 11:31:41 -07:00
parent 225aec9984
commit 3b55336cb6
2 changed files with 31 additions and 9 deletions

View file

@ -41,6 +41,7 @@ https://tuxpaint.org/
+ Cartoon + Cartoon
+ Clone + Clone
+ Confetti + Confetti
+ Distortion
+ Emboss + Emboss
+ Foam + Foam
+ Googly Eyes + Googly Eyes

View file

@ -43,6 +43,7 @@
/* Sound effects: */ /* Sound effects: */
static Mix_Chunk *snd_effect; static Mix_Chunk *snd_effect;
static int distortion_radius = 8;
/* Our local function prototypes: */ /* Our local function prototypes: */
@ -54,7 +55,7 @@ static Mix_Chunk *snd_effect;
// that are declared _before_ them. // that are declared _before_ them.
Uint32 distortion_api_version(void); Uint32 distortion_api_version(void);
int distortion_init(magic_api * api); int distortion_init(magic_api * api, Uint32 disabled_features);
int distortion_get_tool_count(magic_api * api); int distortion_get_tool_count(magic_api * api);
SDL_Surface *distortion_get_icon(magic_api * api, int which); SDL_Surface *distortion_get_icon(magic_api * api, int which);
char *distortion_get_name(magic_api * api, int which); char *distortion_get_name(magic_api * api, int which);
@ -86,6 +87,10 @@ static void distortion_line_callback(void *ptr, int which,
SDL_Surface * canvas, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y); SDL_Surface * snapshot, int x, int y);
Uint8 distortion_accepted_sizes(magic_api * api, int which, int mode);
Uint8 distortion_default_size(magic_api * api, int which, int mode);
void distortion_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
/* Setup Functions: */ /* Setup Functions: */
/* ---------------- */ /* ---------------- */
@ -98,7 +103,7 @@ Uint32 distortion_api_version(void)
// Initialization // Initialization
int distortion_init(magic_api * api) int distortion_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{ {
char fname[1024]; char fname[1024];
@ -222,10 +227,10 @@ void distortion_drag(magic_api * api, int which, SDL_Surface * canvas,
} }
update_rect->x = ox - 8; update_rect->x = ox - distortion_radius;
update_rect->y = oy - 8; update_rect->y = oy - distortion_radius;
update_rect->w = (x + 8) - update_rect->x; update_rect->w = (x + distortion_radius) - update_rect->x;
update_rect->h = (y + 8) - update_rect->y; update_rect->h = (y + distortion_radius) - update_rect->y;
api->playsound(snd_effect, (x * 255) / canvas->w, // pan api->playsound(snd_effect, (x * 255) / canvas->w, // pan
@ -265,11 +270,11 @@ static void distortion_line_callback(void *ptr, int which ATTRIBUTE_UNUSED,
// is being used right now. We compare the 'which' argument that // is being used right now. We compare the 'which' argument that
// Tux Paint sends to us with the values we enumerated above. // Tux Paint sends to us with the values we enumerated above.
for (yy = -8; yy < 8; yy++) for (yy = -distortion_radius; yy < distortion_radius; yy++)
{ {
for (xx = -8; xx < 8; xx++) for (xx = -distortion_radius; xx < distortion_radius; xx++)
{ {
if (api->in_circle(xx, yy, 8)) if (api->in_circle(xx, yy, distortion_radius))
{ {
api->putpixel(canvas, x + xx, y + yy, api->putpixel(canvas, x + xx, y + yy,
api->getpixel(snapshot, x + xx / 2, y + yy)); api->getpixel(snapshot, x + xx / 2, y + yy));
@ -297,3 +302,19 @@ int distortion_modes(magic_api * api ATTRIBUTE_UNUSED,
{ {
return (MODE_PAINT); return (MODE_PAINT);
} }
Uint8 distortion_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return 8;
}
Uint8 distortion_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return 2;
}
void distortion_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
distortion_radius = size * 4;
}