From 3b55336cb690ec04bb9b93901d4181c327bd27c8 Mon Sep 17 00:00:00 2001 From: Bill Kendrick Date: Sat, 22 Apr 2023 11:31:41 -0700 Subject: [PATCH] Distortion: Support sizes --- docs/CHANGES.txt | 1 + magic/src/distortion.c | 39 ++++++++++++++++++++++++++++++--------- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/docs/CHANGES.txt b/docs/CHANGES.txt index 4239a7d64..331e2dff4 100644 --- a/docs/CHANGES.txt +++ b/docs/CHANGES.txt @@ -41,6 +41,7 @@ https://tuxpaint.org/ + Cartoon + Clone + Confetti + + Distortion + Emboss + Foam + Googly Eyes diff --git a/magic/src/distortion.c b/magic/src/distortion.c index b3e120b09..f3a098776 100644 --- a/magic/src/distortion.c +++ b/magic/src/distortion.c @@ -43,6 +43,7 @@ /* Sound effects: */ static Mix_Chunk *snd_effect; +static int distortion_radius = 8; /* Our local function prototypes: */ @@ -54,7 +55,7 @@ static Mix_Chunk *snd_effect; // that are declared _before_ them. 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); SDL_Surface *distortion_get_icon(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 * 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: */ /* ---------------- */ @@ -98,7 +103,7 @@ Uint32 distortion_api_version(void) // Initialization -int distortion_init(magic_api * api) +int distortion_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED) { 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->y = oy - 8; - update_rect->w = (x + 8) - update_rect->x; - update_rect->h = (y + 8) - update_rect->y; + update_rect->x = ox - distortion_radius; + update_rect->y = oy - distortion_radius; + update_rect->w = (x + distortion_radius) - update_rect->x; + update_rect->h = (y + distortion_radius) - update_rect->y; 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 // 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->getpixel(snapshot, x + xx / 2, y + yy)); @@ -297,3 +302,19 @@ int distortion_modes(magic_api * api ATTRIBUTE_UNUSED, { 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; +}