indent glasstile.c

This commit is contained in:
Bill Kendrick 2017-10-15 11:45:55 -07:00
parent 8a7edd82bf
commit 9fd870b985

View file

@ -36,26 +36,22 @@
/* Our globals: */ /* Our globals: */
static Mix_Chunk * glasstile_snd; static Mix_Chunk *glasstile_snd;
// Prototypes // Prototypes
Uint32 glasstile_api_version(void); Uint32 glasstile_api_version(void);
int glasstile_init(magic_api * api); int glasstile_init(magic_api * api);
int glasstile_get_tool_count(magic_api * api); int glasstile_get_tool_count(magic_api * api);
SDL_Surface * glasstile_get_icon(magic_api * api, int which); SDL_Surface *glasstile_get_icon(magic_api * api, int which);
char * glasstile_get_name(magic_api * api, int which); char *glasstile_get_name(magic_api * api, int which);
char * glasstile_get_description(magic_api * api, int which, int mode); char *glasstile_get_description(magic_api * api, int which, int mode);
static void do_glasstile(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last, static void do_glasstile(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
int x, int y);
void glasstile_drag(magic_api * api, int which, SDL_Surface * canvas, void glasstile_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 glasstile_click(magic_api * api, int which, int mode, void glasstile_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 glasstile_release(magic_api * api, int which, void glasstile_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 glasstile_shutdown(magic_api * api); void glasstile_shutdown(magic_api * api);
void glasstile_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b); void glasstile_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int glasstile_requires_colors(magic_api * api, int which); int glasstile_requires_colors(magic_api * api, int which);
@ -63,9 +59,12 @@ void glasstile_switchin(magic_api * api, int which, int mode, SDL_Surface * canv
void glasstile_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas); void glasstile_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int glasstile_modes(magic_api * api, int which); int glasstile_modes(magic_api * api, int which);
Uint32 glasstile_api_version(void) { return(TP_MAGIC_API_VERSION); } Uint32 glasstile_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
static int * * glasstile_hit; static int **glasstile_hit;
static int glasstile_hit_xsize; static int glasstile_hit_xsize;
static int glasstile_hit_ysize; static int glasstile_hit_ysize;
@ -74,60 +73,53 @@ int glasstile_init(magic_api * api)
{ {
char fname[1024]; char fname[1024];
snprintf(fname, sizeof(fname), "%s/sounds/magic/glasstile.ogg", snprintf(fname, sizeof(fname), "%s/sounds/magic/glasstile.ogg", api->data_directory);
api->data_directory);
glasstile_snd = Mix_LoadWAV(fname); glasstile_snd = Mix_LoadWAV(fname);
glasstile_hit = NULL; glasstile_hit = NULL;
glasstile_hit_ysize = 0; glasstile_hit_ysize = 0;
return(1); return (1);
} }
// We have multiple tools: // We have multiple tools:
int glasstile_get_tool_count(magic_api * api ATTRIBUTE_UNUSED) int glasstile_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{ {
return(1); return (1);
} }
// Load our icons: // Load our icons:
SDL_Surface * glasstile_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED) SDL_Surface *glasstile_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{ {
char fname[1024]; char fname[1024];
snprintf(fname, sizeof(fname), "%s/images/magic/glasstile.png", snprintf(fname, sizeof(fname), "%s/images/magic/glasstile.png", api->data_directory);
api->data_directory);
return(IMG_Load(fname)); return (IMG_Load(fname));
} }
// Return our names, localized: // Return our names, localized:
char * glasstile_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) char *glasstile_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{ {
return(strdup(gettext_noop("Glass Tile"))); return (strdup(gettext_noop("Glass Tile")));
} }
// Return our descriptions, localized: // Return our descriptions, localized:
char * glasstile_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode) char *glasstile_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode)
{ {
if (mode == MODE_PAINT) if (mode == MODE_PAINT)
return(strdup(gettext_noop("Click and drag the mouse to put glass tile over your picture."))); return (strdup(gettext_noop("Click and drag the mouse to put glass tile over your picture.")));
else else
return(strdup(gettext_noop("Click to cover your entire picture in glass tiles."))); return (strdup(gettext_noop("Click to cover your entire picture in glass tiles.")));
} }
// Do the effect: // Do the effect:
static void do_glasstile(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last, static void do_glasstile(void *ptr, int which ATTRIBUTE_UNUSED, 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;
int xx, yy, xl, xr, yt, yb; int xx, yy, xl, xr, yt, yb;
Uint8 r1, g1, b1, Uint8 r1, g1, b1, r2, g2, b2, r3, g3, b3, r4, g4, b4, r, g, b;
r2, g2, b2,
r3, g3, b3,
r4, g4, b4,
r, g, b;
Uint32 rgb; Uint32 rgb;
@ -157,14 +149,10 @@ static void do_glasstile(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * c
{ {
for (xx = -GT_SIZE; xx < GT_SIZE; xx = xx + 2) for (xx = -GT_SIZE; xx < GT_SIZE; xx = xx + 2)
{ {
SDL_GetRGB(api->getpixel(last, x + xx, y + yy), last->format, SDL_GetRGB(api->getpixel(last, x + xx, y + yy), last->format, &r1, &g1, &b1);
&r1, &g1, &b1); SDL_GetRGB(api->getpixel(last, x + xx + 1, y + yy), last->format, &r2, &g2, &b2);
SDL_GetRGB(api->getpixel(last, x + xx + 1, y + yy), last->format, SDL_GetRGB(api->getpixel(last, x + xx, y + yy + 1), last->format, &r3, &g3, &b3);
&r2, &g2, &b2); SDL_GetRGB(api->getpixel(last, x + xx + 1, y + yy + 1), last->format, &r4, &g4, &b4);
SDL_GetRGB(api->getpixel(last, x + xx, y + yy + 1), last->format,
&r3, &g3, &b3);
SDL_GetRGB(api->getpixel(last, x + xx + 1, y + yy + 1), last->format,
&r4, &g4, &b4);
r = (r1 + r2 + r3 + r4) >> 2; r = (r1 + r2 + r3 + r4) >> 2;
g = (g1 + g2 + g3 + g4) >> 2; g = (g1 + g2 + g3 + g4) >> 2;
@ -176,7 +164,7 @@ static void do_glasstile(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * c
g = min(255, g + 64); g = min(255, g + 64);
b = min(255, b + 64); b = min(255, b + 64);
} }
else if (xx >= GT_SIZE - 3|| yy >= GT_SIZE - 3) else if (xx >= GT_SIZE - 3 || yy >= GT_SIZE - 3)
{ {
r = max(0, r - 64); r = max(0, r - 64);
g = max(0, g - 64); g = max(0, g - 64);
@ -210,10 +198,9 @@ static void do_glasstile(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * c
// Affect the canvas on drag: // Affect the canvas on drag:
void glasstile_drag(magic_api * api, int which, SDL_Surface * canvas, void glasstile_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_glasstile); api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_glasstile);
update_rect->x = 0; update_rect->x = 0;
update_rect->y = 0; update_rect->y = 0;
@ -246,8 +233,7 @@ void glasstile_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click: // Affect the canvas on click:
void glasstile_click(magic_api * api, int which, int mode, void glasstile_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)
{ {
int xx, yy; int xx, yy;
@ -256,10 +242,10 @@ void glasstile_click(magic_api * api, int which, int mode,
glasstile_hit_ysize = (canvas->h / GT_SIZE) + 1; glasstile_hit_ysize = (canvas->h / GT_SIZE) + 1;
glasstile_hit_xsize = (canvas->w / GT_SIZE) + 1; glasstile_hit_xsize = (canvas->w / GT_SIZE) + 1;
glasstile_hit = (int * *) malloc(sizeof(int *) * glasstile_hit_ysize); glasstile_hit = (int * *)malloc(sizeof(int *) * glasstile_hit_ysize);
for (yy = 0; yy < glasstile_hit_ysize; yy++) for (yy = 0; yy < glasstile_hit_ysize; yy++)
glasstile_hit[yy] = (int *) malloc(sizeof(int) * glasstile_hit_xsize); glasstile_hit[yy] = (int *)malloc(sizeof(int) * glasstile_hit_xsize);
} }
for (yy = 0; yy < glasstile_hit_ysize; yy++) for (yy = 0; yy < glasstile_hit_ysize; yy++)
@ -310,7 +296,8 @@ void glasstile_shutdown(magic_api * api ATTRIBUTE_UNUSED)
} }
// Record the color from Tux Paint: // Record the color from Tux Paint:
void glasstile_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED) void glasstile_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED)
{ {
} }
@ -320,15 +307,17 @@ int glasstile_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIB
return 0; return 0;
} }
void glasstile_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED) void glasstile_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{ {
} }
void glasstile_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED) void glasstile_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{ {
} }
int glasstile_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) int glasstile_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{ {
return(MODE_PAINT | MODE_FULLSCREEN); return (MODE_PAINT | MODE_FULLSCREEN);
} }