Smudge & Wet Paint: Support sizes
This commit is contained in:
parent
17b23e19d0
commit
7ab630c914
2 changed files with 47 additions and 21 deletions
|
|
@ -63,6 +63,7 @@ https://tuxpaint.org/
|
|||
+ Rosette, Picasso
|
||||
+ Saturate, Desaturate
|
||||
+ Sharpen, Edges, Silhouette
|
||||
+ Smudge, Wet Paint
|
||||
+ Tint, Color & White
|
||||
+ Toothpaste
|
||||
+ TV
|
||||
|
|
|
|||
|
|
@ -25,7 +25,9 @@
|
|||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
(See COPYING.txt)
|
||||
|
||||
Last updated: February 12, 2023
|
||||
Last updated: April 23, 2023
|
||||
|
||||
FIXME: "Wet Paint" doesn't smudge enough -bjk 2023.04.23
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
|
@ -38,8 +40,9 @@
|
|||
|
||||
static Mix_Chunk *smudge_snd;
|
||||
static Uint8 smudge_r, smudge_g, smudge_b;
|
||||
static int smudge_radius = 16;
|
||||
|
||||
int smudge_init(magic_api * api);
|
||||
int smudge_init(magic_api * api, Uint32 disabled_features);
|
||||
Uint32 smudge_api_version(void);
|
||||
SDL_Surface *smudge_get_icon(magic_api * api, int which);
|
||||
char *smudge_get_name(magic_api * api, int which);
|
||||
|
|
@ -64,9 +67,12 @@ void smudge_switchout(magic_api * api, int which, int mode,
|
|||
SDL_Surface * canvas);
|
||||
int smudge_modes(magic_api * api, int which);
|
||||
int smudge_get_tool_count(magic_api * api);
|
||||
Uint8 smudge_accepted_sizes(magic_api * api, int which, int mode);
|
||||
Uint8 smudge_default_size(magic_api * api, int which, int mode);
|
||||
void smudge_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
|
||||
|
||||
// No setup required:
|
||||
int smudge_init(magic_api * api)
|
||||
|
||||
int smudge_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
|
|
@ -141,8 +147,8 @@ static void do_smudge(void *ptr, int which, SDL_Surface * canvas,
|
|||
SDL_Surface * last, int x, int y)
|
||||
{
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
static double state[32][32][3];
|
||||
unsigned i = 32 * 32;
|
||||
static double state[256][256][3];
|
||||
unsigned i = (smudge_radius * 2) * (smudge_radius * 2);
|
||||
double rate = api->button_down()? 0.5 : 0.0;
|
||||
Uint8 r, g, b;
|
||||
int xx, yy, strength;
|
||||
|
|
@ -150,14 +156,13 @@ static void do_smudge(void *ptr, int which, SDL_Surface * canvas,
|
|||
if (which == 1)
|
||||
{
|
||||
/* Wet paint */
|
||||
for (yy = -8; yy < 8; yy++)
|
||||
for (xx = -8; xx < 8; xx++)
|
||||
if (api->in_circle(xx, yy, 8))
|
||||
for (yy = -(smudge_radius / 2); yy < (smudge_radius / 2); yy++)
|
||||
for (xx = -(smudge_radius / 2); xx < (smudge_radius / 2); xx++)
|
||||
if (api->in_circle(xx, yy, (smudge_radius / 2)))
|
||||
{
|
||||
SDL_GetRGB(api->getpixel(last, x + xx, y + yy), last->format, &r,
|
||||
&g, &b);
|
||||
//strength = (abs(xx * yy) / 8) + 6;
|
||||
strength = (abs(xx * yy) / 8) + 1;
|
||||
strength = (abs(xx * yy) / (smudge_radius / 2)) + 1;
|
||||
api->putpixel(canvas, x + xx, y + yy, SDL_MapRGB(canvas->format,
|
||||
(smudge_r +
|
||||
r * strength) /
|
||||
|
|
@ -173,15 +178,18 @@ static void do_smudge(void *ptr, int which, SDL_Surface * canvas,
|
|||
|
||||
while (i--)
|
||||
{
|
||||
int iy = i >> 5;
|
||||
int ix = i & 0x1f;
|
||||
int iy = i / (smudge_radius * 2);
|
||||
int ix = i % (smudge_radius * 2);
|
||||
int radius_check;
|
||||
|
||||
// is it not on the circle of radius sqrt(120) at location 16,16?
|
||||
if ((ix - 16) * (ix - 16) + (iy - 16) * (iy - 16) > 120)
|
||||
radius_check = (smudge_radius * 75) / 10; /* For 16 radius, we'll use 120 */
|
||||
|
||||
// is it not on the circle of radius sqrt(radius_check) at location (smudge_radius,smudge_radius)?
|
||||
if ((ix - smudge_radius) * (ix - smudge_radius) + (iy - smudge_radius) * (iy - smudge_radius) > radius_check)
|
||||
continue;
|
||||
// it is on the circle, so grab it
|
||||
|
||||
SDL_GetRGB(api->getpixel(canvas, x + ix - 16, y + iy - 16), last->format,
|
||||
SDL_GetRGB(api->getpixel(canvas, x + ix - smudge_radius, y + iy - smudge_radius), last->format,
|
||||
&r, &g, &b);
|
||||
state[ix][iy][0] =
|
||||
rate * state[ix][iy][0] + (1.0 - rate) * api->sRGB_to_linear(r);
|
||||
|
|
@ -191,7 +199,7 @@ static void do_smudge(void *ptr, int which, SDL_Surface * canvas,
|
|||
rate * state[ix][iy][2] + (1.0 - rate) * api->sRGB_to_linear(b);
|
||||
|
||||
// opacity 100% --> new data not blended w/ existing data
|
||||
api->putpixel(canvas, x + ix - 16, y + iy - 16,
|
||||
api->putpixel(canvas, x + ix - smudge_radius, y + iy - smudge_radius,
|
||||
SDL_MapRGB(canvas->format,
|
||||
api->linear_to_sRGB(state[ix][iy][0]),
|
||||
api->linear_to_sRGB(state[ix][iy][1]),
|
||||
|
|
@ -223,10 +231,10 @@ void smudge_drag(magic_api * api, int which, SDL_Surface * canvas,
|
|||
y = tmp;
|
||||
}
|
||||
|
||||
update_rect->x = ox - 16;
|
||||
update_rect->y = oy - 16;
|
||||
update_rect->w = (x + 16) - update_rect->x;
|
||||
update_rect->h = (y + 16) - update_rect->y;
|
||||
update_rect->x = ox - smudge_radius;
|
||||
update_rect->y = oy - smudge_radius;
|
||||
update_rect->w = (x + smudge_radius) - update_rect->x;
|
||||
update_rect->h = (y + smudge_radius) - update_rect->y;
|
||||
}
|
||||
|
||||
// Affect the canvas on click:
|
||||
|
|
@ -289,3 +297,20 @@ int smudge_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
|||
{
|
||||
return (MODE_PAINT);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Uint8 smudge_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
|
||||
Uint8 smudge_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
void smudge_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)
|
||||
{
|
||||
smudge_radius = size * 4;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue