indent smudge.c

This commit is contained in:
Bill Kendrick 2017-10-15 11:50:37 -07:00
parent e6a81956de
commit 6071c06c06

View file

@ -45,17 +45,13 @@ Uint32 smudge_api_version(void);
SDL_Surface *smudge_get_icon(magic_api * api, int which); SDL_Surface *smudge_get_icon(magic_api * api, int which);
char *smudge_get_name(magic_api * api, int which); char *smudge_get_name(magic_api * api, int which);
char *smudge_get_description(magic_api * api, int which, int mode); char *smudge_get_description(magic_api * api, int which, int mode);
static void do_smudge(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last, static void do_smudge(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
int x, int y);
void smudge_drag(magic_api * api, int which, SDL_Surface * canvas, void smudge_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
SDL_Rect * update_rect);
void smudge_click(magic_api * api, int which, int mode, void smudge_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
int x, int y, SDL_Rect * update_rect);
void smudge_release(magic_api * api, int which, void smudge_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last, SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
int x, int y, SDL_Rect * update_rect);
void smudge_shutdown(magic_api * api); void smudge_shutdown(magic_api * api);
void smudge_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b); void smudge_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int smudge_requires_colors(magic_api * api, int which); int smudge_requires_colors(magic_api * api, int which);
@ -69,14 +65,16 @@ int smudge_init(magic_api * api)
{ {
char fname[1024]; char fname[1024];
snprintf(fname, sizeof(fname), "%s/sounds/magic/smudge.wav", snprintf(fname, sizeof(fname), "%s/sounds/magic/smudge.wav", api->data_directory);
api->data_directory);
smudge_snd = Mix_LoadWAV(fname); smudge_snd = Mix_LoadWAV(fname);
return (1); return (1);
} }
Uint32 smudge_api_version(void) { return(TP_MAGIC_API_VERSION); } Uint32 smudge_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
// We have multiple tools: // We have multiple tools:
int smudge_get_tool_count(magic_api * api ATTRIBUTE_UNUSED) int smudge_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
@ -90,11 +88,9 @@ SDL_Surface * smudge_get_icon(magic_api * api, int which)
char fname[1024]; char fname[1024];
if (which == 0) if (which == 0)
snprintf(fname, sizeof(fname), "%s/images/magic/smudge.png", snprintf(fname, sizeof(fname), "%s/images/magic/smudge.png", api->data_directory);
api->data_directory);
else /* if (which == 1) */ else /* if (which == 1) */
snprintf(fname, sizeof(fname), "%s/images/magic/wetpaint.png", snprintf(fname, sizeof(fname), "%s/images/magic/wetpaint.png", api->data_directory);
api->data_directory);
return (IMG_Load(fname)); return (IMG_Load(fname));
} }
@ -119,8 +115,7 @@ char * smudge_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int m
// Do the effect: // Do the effect:
static void do_smudge(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last, static void do_smudge(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
int x, int y)
{ {
magic_api *api = (magic_api *) ptr; magic_api *api = (magic_api *) ptr;
static double state[32][32][3]; static double state[32][32][3];
@ -136,8 +131,7 @@ static void do_smudge(void * ptr, int which, SDL_Surface * canvas, SDL_Surface *
for (xx = -8; xx < 8; xx++) for (xx = -8; xx < 8; xx++)
if (api->in_circle(xx, yy, 8)) if (api->in_circle(xx, yy, 8))
{ {
SDL_GetRGB(api->getpixel(last, x + xx, y + yy), SDL_GetRGB(api->getpixel(last, x + xx, y + yy), last->format, &r, &g, &b);
last->format, &r, &g, &b);
//strength = (abs(xx * yy) / 8) + 6; //strength = (abs(xx * yy) / 8) + 6;
strength = (abs(xx * yy) / 8) + 1; strength = (abs(xx * yy) / 8) + 1;
api->putpixel(canvas, x + xx, y + yy, SDL_MapRGB(canvas->format, api->putpixel(canvas, x + xx, y + yy, SDL_MapRGB(canvas->format,
@ -151,39 +145,46 @@ static void do_smudge(void * ptr, int which, SDL_Surface * canvas, SDL_Surface *
{ {
int iy = i >> 5; int iy = i >> 5;
int ix = i & 0x1f; int ix = i & 0x1f;
// is it not on the circle of radius sqrt(120) at location 16,16? // is it not on the circle of radius sqrt(120) at location 16,16?
if ((ix - 16) * (ix - 16) + (iy - 16) * (iy - 16) > 120) if ((ix - 16) * (ix - 16) + (iy - 16) * (iy - 16) > 120)
continue; continue;
// it is on the circle, so grab it // it is on the circle, so grab it
SDL_GetRGB(api->getpixel(canvas, x + ix - 16, y + iy - 16), SDL_GetRGB(api->getpixel(canvas, x + ix - 16, y + iy - 16), last->format, &r, &g, &b);
last->format, &r, &g, &b); state[ix][iy][0] = rate * state[ix][iy][0] + (1.0 - rate) * api->sRGB_to_linear(r);
state[ix][iy][0] = state[ix][iy][1] = rate * state[ix][iy][1] + (1.0 - rate) * api->sRGB_to_linear(g);
rate * state[ix][iy][0] + (1.0 - rate) * api->sRGB_to_linear(r); state[ix][iy][2] = rate * state[ix][iy][2] + (1.0 - rate) * api->sRGB_to_linear(b);
state[ix][iy][1] =
rate * state[ix][iy][1] + (1.0 - rate) * api->sRGB_to_linear(g);
state[ix][iy][2] =
rate * state[ix][iy][2] + (1.0 - rate) * api->sRGB_to_linear(b);
// opacity 100% --> new data not blended w/ existing data // opacity 100% --> new data not blended w/ existing data
api->putpixel(canvas, x + ix - 16, y + iy - 16, api->putpixel(canvas, x + ix - 16, y + iy - 16,
SDL_MapRGB(canvas->format, api->linear_to_sRGB(state[ix][iy][0]), SDL_MapRGB(canvas->format, api->linear_to_sRGB(state[ix][iy][0]),
api->linear_to_sRGB(state[ix][iy][1]), api->linear_to_sRGB(state[ix][iy][1]), api->linear_to_sRGB(state[ix][iy][2])));
api->linear_to_sRGB(state[ix][iy][2])));
} }
} }
// Affect the canvas on drag: // Affect the canvas on drag:
void smudge_drag(magic_api * api, int which, SDL_Surface * canvas, void smudge_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
SDL_Rect * update_rect)
{ {
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_smudge); api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_smudge);
api->playsound(smudge_snd, (x * 255) / canvas->w, 255); api->playsound(smudge_snd, (x * 255) / canvas->w, 255);
if (ox > x) { int tmp = ox; ox = x; x = tmp; } if (ox > x)
if (oy > y) { int tmp = oy; oy = y; y = tmp; } {
int tmp = ox;
ox = x;
x = tmp;
}
if (oy > y)
{
int tmp = oy;
oy = y;
y = tmp;
}
update_rect->x = ox - 16; update_rect->x = ox - 16;
update_rect->y = oy - 16; update_rect->y = oy - 16;
@ -193,8 +194,7 @@ void smudge_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click: // Affect the canvas on click:
void smudge_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED, void smudge_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
int x, int y, SDL_Rect * update_rect)
{ {
smudge_drag(api, which, canvas, last, x, y, x, y, update_rect); smudge_drag(api, which, canvas, last, x, y, x, y, update_rect);
} }
@ -230,11 +230,13 @@ int smudge_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE
return 1; return 1;
} }
void smudge_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED) void smudge_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{ {
} }
void smudge_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED) void smudge_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{ {
} }