From 4e54ad77041de0417470e5a995af77eeccf9752a Mon Sep 17 00:00:00 2001 From: Bill Kendrick Date: Thu, 20 Apr 2023 23:31:28 -0700 Subject: [PATCH] Light: Support sizes --- docs/CHANGES.txt | 1 + magic/src/light.c | 45 ++++++++++++++++++++++++++++++++++----------- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/docs/CHANGES.txt b/docs/CHANGES.txt index 051d239c3..570a3f8b9 100644 --- a/docs/CHANGES.txt +++ b/docs/CHANGES.txt @@ -41,6 +41,7 @@ https://tuxpaint.org/ + Clone + Confetti + Googly Eyes + + Light + Metal Paint + Negative & Opposite + Pixels diff --git a/magic/src/light.c b/magic/src/light.c index 41b52d145..19330bf7d 100644 --- a/magic/src/light.c +++ b/magic/src/light.c @@ -23,7 +23,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA (See COPYING.txt) - Last updated: February 12, 2023 + Last updated: April 20, 2023 */ #include @@ -39,8 +39,12 @@ static Mix_Chunk *light1_snd, *light2_snd; static float light_h, light_s, light_v; +static int light_radius = 8; + +/* Function prototypes: */ + Uint32 light_api_version(void); -int light_init(magic_api * api); +int light_init(magic_api * api, Uint32 disabled_features); int light_get_tool_count(magic_api * api); SDL_Surface *light_get_icon(magic_api * api, int which); char *light_get_name(magic_api * api, int which); @@ -64,6 +68,9 @@ void light_switchin(magic_api * api, int which, int mode, void light_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas); int light_modes(magic_api * api, int which); +Uint8 light_accepted_sizes(magic_api * api, int which, int mode); +Uint8 light_default_size(magic_api * api, int which, int mode); +void light_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect); Uint32 light_api_version(void) @@ -73,7 +80,7 @@ Uint32 light_api_version(void) // No setup required: -int light_init(magic_api * api) +int light_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED) { char fname[1024]; @@ -142,17 +149,17 @@ static void do_light(void *ptr, int which ATTRIBUTE_UNUSED, float h, s, v, new_h, new_s, new_v; float adj; - for (yy = -8; yy < 8; yy++) + for (yy = -light_radius; yy < light_radius; yy++) { - for (xx = -8; xx < 8; xx++) + for (xx = -light_radius; xx < light_radius; xx++) { - if (api->in_circle(xx, yy, 8)) + if (api->in_circle(xx, yy, light_radius)) { pix = api->getpixel(canvas, x + xx, y + yy); SDL_GetRGB(pix, canvas->format, &r, &g, &b); - adj = (7.99 - sqrt(abs(xx * yy))) / 128.0; + adj = (((float) light_radius - 0.01) - sqrt(abs(xx * yy))) / (16.0 * (float) light_radius); api->rgbtohsv(r, g, b, &h, &s, &v); @@ -214,10 +221,10 @@ void light_drag(magic_api * api, int which, SDL_Surface * canvas, y = tmp; } - 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 - light_radius; + update_rect->y = oy - light_radius; + update_rect->w = (x + light_radius) - update_rect->x; + update_rect->h = (y + light_radius) - update_rect->y; api->playsound(light1_snd, (x * 255) / canvas->w, 255); } @@ -278,3 +285,19 @@ int light_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) { return (MODE_PAINT); } + + +Uint8 light_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED) +{ + return 4; +} + +Uint8 light_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED) +{ + return 2; +} + +void light_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) +{ + light_radius = size * 4; +}