indent toothpaste.c

This commit is contained in:
Bill Kendrick 2017-10-15 11:51:10 -07:00
parent 5871ef9b3a
commit cf3173690d

View file

@ -48,7 +48,8 @@ static Uint8 toothpaste_r, toothpaste_g, toothpaste_b;
static const int toothpaste_RADIUS = 10; static const int toothpaste_RADIUS = 10;
double *toothpaste_weights = NULL; double *toothpaste_weights = NULL;
enum { enum
{
TOOL_toothpaste, TOOL_toothpaste,
toothpaste_NUM_TOOLS toothpaste_NUM_TOOLS
}; };
@ -58,12 +59,15 @@ static Mix_Chunk * toothpaste_snd_effect[toothpaste_NUM_TOOLS];
const char *toothpaste_snd_filenames[toothpaste_NUM_TOOLS] = { const char *toothpaste_snd_filenames[toothpaste_NUM_TOOLS] = {
"toothpaste.ogg", "toothpaste.ogg",
}; };
const char *toothpaste_icon_filenames[toothpaste_NUM_TOOLS] = { const char *toothpaste_icon_filenames[toothpaste_NUM_TOOLS] = {
"toothpaste.png", "toothpaste.png",
}; };
const char *toothpaste_names[toothpaste_NUM_TOOLS] = { const char *toothpaste_names[toothpaste_NUM_TOOLS] = {
gettext_noop("Toothpaste"), gettext_noop("Toothpaste"),
}; };
const char *toothpaste_descs[toothpaste_NUM_TOOLS] = { const char *toothpaste_descs[toothpaste_NUM_TOOLS] = {
gettext_noop("Click and drag to squirt toothpaste onto your picture."), gettext_noop("Click and drag to squirt toothpaste onto your picture."),
}; };
@ -75,17 +79,13 @@ int toothpaste_get_tool_count(magic_api * api);
SDL_Surface *toothpaste_get_icon(magic_api * api, int which); SDL_Surface *toothpaste_get_icon(magic_api * api, int which);
char *toothpaste_get_name(magic_api * api, int which); char *toothpaste_get_name(magic_api * api, int which);
char *toothpaste_get_description(magic_api * api, int which, int mode); char *toothpaste_get_description(magic_api * api, int which, int mode);
static void do_toothpaste(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last, static void do_toothpaste(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
int x, int y);
void toothpaste_drag(magic_api * api, int which, SDL_Surface * canvas, void toothpaste_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 toothpaste_click(magic_api * api, int which, int mode, void toothpaste_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 toothpaste_release(magic_api * api, int which, void toothpaste_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 toothpaste_shutdown(magic_api * api); void toothpaste_shutdown(magic_api * api);
void toothpaste_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b); void toothpaste_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int toothpaste_requires_colors(magic_api * api, int which); int toothpaste_requires_colors(magic_api * api, int which);
@ -93,16 +93,22 @@ void toothpaste_switchin(magic_api * api, int which, int mode, SDL_Surface * can
void toothpaste_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas); void toothpaste_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int toothpaste_modes(magic_api * api, int which); int toothpaste_modes(magic_api * api, int which);
Uint32 toothpaste_api_version(void) { return(TP_MAGIC_API_VERSION); } Uint32 toothpaste_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
int toothpaste_init(magic_api * api){ int toothpaste_init(magic_api * api)
{
int i; int i;
char fname[1024]; char fname[1024];
int k, j; int k, j;
//Load sounds //Load sounds
for (i = 0; i < toothpaste_NUM_TOOLS; i++){ for (i = 0; i < toothpaste_NUM_TOOLS; i++)
{
snprintf(fname, sizeof(fname), "%s/sounds/magic/%s", api->data_directory, toothpaste_snd_filenames[i]); snprintf(fname, sizeof(fname), "%s/sounds/magic/%s", api->data_directory, toothpaste_snd_filenames[i]);
toothpaste_snd_effect[i] = Mix_LoadWAV(fname); toothpaste_snd_effect[i] = Mix_LoadWAV(fname);
} }
@ -110,14 +116,19 @@ int toothpaste_init(magic_api * api){
//Set up weights //Set up weights
pi = acos(0.0) * 2; pi = acos(0.0) * 2;
toothpaste_weights = (double *)malloc(toothpaste_RADIUS * 2 * toothpaste_RADIUS * 2 * sizeof(double)); toothpaste_weights = (double *)malloc(toothpaste_RADIUS * 2 * toothpaste_RADIUS * 2 * sizeof(double));
if (toothpaste_weights == NULL){ if (toothpaste_weights == NULL)
{
return (0); return (0);
} }
for (k = - toothpaste_RADIUS; k < + toothpaste_RADIUS; k++){ for (k = -toothpaste_RADIUS; k < +toothpaste_RADIUS; k++)
for (j = - toothpaste_RADIUS; j < + toothpaste_RADIUS; j++){ {
if (api->in_circle(j , k, toothpaste_RADIUS)){ for (j = -toothpaste_RADIUS; j < +toothpaste_RADIUS; j++)
toothpaste_weights[(k+toothpaste_RADIUS)*((toothpaste_RADIUS*2) -1)+(j+toothpaste_RADIUS)] = ((fabs(atan2((double)(j),(double)(k))))/pi); {
if (api->in_circle(j, k, toothpaste_RADIUS))
{
toothpaste_weights[(k + toothpaste_RADIUS) * ((toothpaste_RADIUS * 2) - 1) + (j + toothpaste_RADIUS)] =
((fabs(atan2((double)(j), (double)(k)))) / pi);
} }
} }
} }
@ -125,43 +136,55 @@ int toothpaste_init(magic_api * api){
return (1); return (1);
} }
int toothpaste_get_tool_count(magic_api * api ATTRIBUTE_UNUSED){ int toothpaste_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return (toothpaste_NUM_TOOLS); return (toothpaste_NUM_TOOLS);
} }
// Load our icons: // Load our icons:
SDL_Surface * toothpaste_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED){ SDL_Surface *toothpaste_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024]; char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, toothpaste_icon_filenames[which]); snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, toothpaste_icon_filenames[which]);
return (IMG_Load(fname)); return (IMG_Load(fname));
} }
// Return our names, localized: // Return our names, localized:
char * toothpaste_get_name(magic_api * api ATTRIBUTE_UNUSED, int which){ char *toothpaste_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
{
return (strdup(gettext_noop(toothpaste_names[which]))); return (strdup(gettext_noop(toothpaste_names[which])));
} }
// Return our descriptions, localized: // Return our descriptions, localized:
char * toothpaste_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED){ char *toothpaste_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
{
return (strdup(gettext_noop(toothpaste_descs[which]))); return (strdup(gettext_noop(toothpaste_descs[which])));
} }
// Do the effect: // Do the effect:
static void do_toothpaste(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y){ static void do_toothpaste(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
{
magic_api *api = (magic_api *) ptr; magic_api *api = (magic_api *) ptr;
int xx, yy; int xx, yy;
// double colr; // double colr;
float h, s, v; float h, s, v;
Uint8 r, g, b; Uint8 r, g, b;
for (yy = y - toothpaste_RADIUS; yy < y + toothpaste_RADIUS; yy++){ for (yy = y - toothpaste_RADIUS; yy < y + toothpaste_RADIUS; yy++)
for (xx = x - toothpaste_RADIUS; xx < x + toothpaste_RADIUS; xx++){ {
if (api->in_circle(xx - x, yy - y, toothpaste_RADIUS) && for (xx = x - toothpaste_RADIUS; xx < x + toothpaste_RADIUS; xx++)
!api->touched(xx, yy)){ {
if (api->in_circle(xx - x, yy - y, toothpaste_RADIUS) && !api->touched(xx, yy))
{
api->rgbtohsv(toothpaste_r, toothpaste_g, toothpaste_b, &h, &s, &v); api->rgbtohsv(toothpaste_r, toothpaste_g, toothpaste_b, &h, &s, &v);
api->hsvtorgb(h, s, toothpaste_weights[(yy-y+toothpaste_RADIUS)*((toothpaste_RADIUS*2) -1)+(xx-x+toothpaste_RADIUS)], &r, &g, &b); api->hsvtorgb(h, s,
toothpaste_weights[(yy - y + toothpaste_RADIUS) * ((toothpaste_RADIUS * 2) - 1) +
(xx - x + toothpaste_RADIUS)], &r, &g, &b);
api->putpixel(canvas, xx, yy, SDL_MapRGB(canvas->format, r, g, b)); api->putpixel(canvas, xx, yy, SDL_MapRGB(canvas->format, r, g, b));
} }
@ -172,8 +195,8 @@ static void do_toothpaste(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface *
// Affect the canvas on drag: // Affect the canvas on drag:
void toothpaste_drag(magic_api * api, int which, SDL_Surface * canvas, void toothpaste_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_toothpaste); api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_toothpaste);
@ -188,8 +211,8 @@ void toothpaste_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click: // Affect the canvas on click:
void toothpaste_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED, void toothpaste_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){ {
toothpaste_drag(api, which, canvas, last, x, y, x, y, update_rect); toothpaste_drag(api, which, canvas, last, x, y, x, y, update_rect);
} }
@ -206,12 +229,16 @@ void toothpaste_shutdown(magic_api * api ATTRIBUTE_UNUSED)
{ {
//Clean up sounds //Clean up sounds
int i; int i;
for(i=0; i<toothpaste_NUM_TOOLS; i++){
if(toothpaste_snd_effect[i] != NULL){ for (i = 0; i < toothpaste_NUM_TOOLS; i++)
{
if (toothpaste_snd_effect[i] != NULL)
{
Mix_FreeChunk(toothpaste_snd_effect[i]); Mix_FreeChunk(toothpaste_snd_effect[i]);
} }
} }
if (toothpaste_weights != NULL){ if (toothpaste_weights != NULL)
{
free(toothpaste_weights); free(toothpaste_weights);
toothpaste_weights = NULL; toothpaste_weights = NULL;
} }
@ -232,11 +259,13 @@ int toothpaste_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRI
} }
void toothpaste_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED) void toothpaste_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{ {
} }
void toothpaste_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED) void toothpaste_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{ {
} }
@ -244,5 +273,3 @@ int toothpaste_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSE
{ {
return (MODE_PAINT); return (MODE_PAINT);
} }