From f6c74f897e55452611f62b08bb1473f9395f62f6 Mon Sep 17 00:00:00 2001 From: Bill Kendrick Date: Sat, 4 Sep 2021 23:28:33 -0700 Subject: [PATCH] "Halftone" can now affect the entire image at once --- docs/CHANGES.txt | 7 +++++-- magic/src/halftone.c | 30 +++++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/docs/CHANGES.txt b/docs/CHANGES.txt index 6ea3b6fb1..84338fce1 100644 --- a/docs/CHANGES.txt +++ b/docs/CHANGES.txt @@ -22,8 +22,8 @@ $Id$ of Cyan, Magenta, Yellow, and Black, based on the average color of the area of the picture being replaced, to give a "newsprint" effect. - * WIP - Need to make it run against entire image - * WIP - It seems to have the "Zoom" tool's icon!?! + + * "Halftone" can now affect the entire image at once. * Documentation updates --------------------- @@ -65,6 +65,9 @@ $Id$ * "Zoom" magic tool icon had weird artifacting. Mended. + * WIP - "Halftone" magic tool had the "Zoom" tool's icon. + + 2021.June.28 (0.9.26) * New Features ------------ diff --git a/magic/src/halftone.c b/magic/src/halftone.c index baaf55a6c..bee550b6f 100644 --- a/magic/src/halftone.c +++ b/magic/src/halftone.c @@ -139,7 +139,7 @@ int halftone_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBU int halftone_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) { - return MODE_PAINT; + return (MODE_PAINT | MODE_FULLSCREEN); } void halftone_shutdown(magic_api * api ATTRIBUTE_UNUSED) @@ -156,10 +156,30 @@ void halftone_shutdown(magic_api * api ATTRIBUTE_UNUSED) SDL_FreeSurface(square); } -void halftone_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED, +void halftone_click(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect) { - halftone_drag(api, which, canvas, snapshot, x, y, x, y, update_rect); + int full_x, full_y; + + if (mode == MODE_PAINT) + { + halftone_drag(api, which, canvas, snapshot, x, y, x, y, update_rect); + } + else + { + for (full_y = 0; full_y < canvas->h; full_y += GRID_SIZE) + { + for (full_x = 0; full_x < canvas->w; full_x += GRID_SIZE) + { + halftone_line_callback(api, which, canvas, snapshot, full_x, full_y); + } + } + api->playsound(snd_effect[which], 128, 255); + update_rect->x = 0; + update_rect->y = 0; + update_rect->w = canvas->w; + update_rect->h = canvas->h; + } } void halftone_drag(magic_api * api, int which, SDL_Surface * canvas, @@ -291,8 +311,8 @@ void halftone_line_callback(void *ptr, int which ATTRIBUTE_UNUSED, ox = xxx + deg_cos(chan_angles[channel]) * OFFSET_RADIUS; oy = yyy + deg_sin(chan_angles[channel]) * OFFSET_RADIUS; - sqx = (GRID_SIZE / 2) + ox; - sqy = (GRID_SIZE / 2) + oy; + sqx = ((GRID_SIZE / 2) + ox) % GRID_SIZE; + sqy = ((GRID_SIZE / 2) + oy) % GRID_SIZE; /* Use intensity of the CMKY channel in question to decide how big of a circle to paint */