indent kalidescope.c

This commit is contained in:
Bill Kendrick 2017-10-15 11:47:20 -07:00
parent 3bfbc3e741
commit e146c3df38

View file

@ -35,12 +35,13 @@
/* Our globals: */ /* Our globals: */
static Mix_Chunk * kalidescope_snd; static Mix_Chunk *kalidescope_snd;
static Uint8 kalidescope_r, kalidescope_g, kalidescope_b; static Uint8 kalidescope_r, kalidescope_g, kalidescope_b;
static int square_size = 128; static int square_size = 128;
enum { enum
{
KAL_UD, KAL_UD,
KAL_LR, KAL_LR,
KAL_BOTH, KAL_BOTH,
@ -49,7 +50,7 @@ enum {
KAL_COUNT KAL_COUNT
}; };
char * kal_icon_names[KAL_COUNT] = { char *kal_icon_names[KAL_COUNT] = {
"symmetric_updown.png", "symmetric_updown.png",
"symmetric_leftright.png", "symmetric_leftright.png",
"kalidescope.png", "kalidescope.png",
@ -62,20 +63,16 @@ char * kal_icon_names[KAL_COUNT] = {
Uint32 kalidescope_api_version(void); Uint32 kalidescope_api_version(void);
int kalidescope_init(magic_api * api); int kalidescope_init(magic_api * api);
int kalidescope_get_tool_count(magic_api * api); int kalidescope_get_tool_count(magic_api * api);
SDL_Surface * kalidescope_get_icon(magic_api * api, int which); SDL_Surface *kalidescope_get_icon(magic_api * api, int which);
char * kalidescope_get_name(magic_api * api, int which); char *kalidescope_get_name(magic_api * api, int which);
char * kalidescope_get_description(magic_api * api, int which, int mode); char *kalidescope_get_description(magic_api * api, int which, int mode);
static void do_kalidescope(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last, static void do_kalidescope(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
int x, int y);
void kalidescope_drag(magic_api * api, int which, SDL_Surface * canvas, void kalidescope_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 kalidescope_click(magic_api * api, int which, int mode, void kalidescope_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 kalidescope_release(magic_api * api, int which, void kalidescope_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 kalidescope_shutdown(magic_api * api); void kalidescope_shutdown(magic_api * api);
int kalidescope_requires_colors(magic_api * api, int which); int kalidescope_requires_colors(magic_api * api, int which);
void kalidescope_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b); void kalidescope_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
@ -83,82 +80,102 @@ void kalidescope_switchin(magic_api * api, int which, int mode, SDL_Surface * ca
void kalidescope_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas); void kalidescope_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int kalidescope_modes(magic_api * api, int which); int kalidescope_modes(magic_api * api, int which);
Uint32 kalidescope_api_version(void) { return(TP_MAGIC_API_VERSION); } Uint32 kalidescope_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
// No setup required: // No setup required:
int kalidescope_init(magic_api * api) int kalidescope_init(magic_api * api)
{ {
char fname[1024]; char fname[1024];
snprintf(fname, sizeof(fname), "%s/sounds/magic/kaleidoscope.ogg", snprintf(fname, sizeof(fname), "%s/sounds/magic/kaleidoscope.ogg", api->data_directory);
api->data_directory);
kalidescope_snd = Mix_LoadWAV(fname); kalidescope_snd = Mix_LoadWAV(fname);
return(1); return (1);
} }
int kalidescope_get_tool_count(magic_api * api ATTRIBUTE_UNUSED) int kalidescope_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{ {
return(KAL_COUNT); return (KAL_COUNT);
} }
// Load our icons: // Load our icons:
SDL_Surface * kalidescope_get_icon(magic_api * api, int which) SDL_Surface *kalidescope_get_icon(magic_api * api, int which)
{ {
char fname[1024]; char fname[1024];
snprintf(fname, sizeof(fname), "%s/images/magic/%s", snprintf(fname, sizeof(fname), "%s/images/magic/%s", api->data_directory, kal_icon_names[which]);
api->data_directory, kal_icon_names[which]);
return(IMG_Load(fname)); return (IMG_Load(fname));
} }
// Return our names, localized: // Return our names, localized:
char * kalidescope_get_name(magic_api * api ATTRIBUTE_UNUSED, int which) char *kalidescope_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
{ {
if (which == KAL_LR) { if (which == KAL_LR)
return(strdup(gettext_noop("Symmetric Left/Right"))); {
} else if (which == KAL_UD) { return (strdup(gettext_noop("Symmetric Left/Right")));
return(strdup(gettext_noop("Symmetric Up/Down"))); }
} else if (which == KAL_PATTERN) { else if (which == KAL_UD)
return(strdup(gettext_noop("Pattern"))); {
} else if (which == KAL_TILES) { return (strdup(gettext_noop("Symmetric Up/Down")));
return(strdup(gettext_noop("Tiles"))); }
} else { /* KAL_BOTH */ else if (which == KAL_PATTERN)
return(strdup(gettext_noop("Kaleidoscope"))); {
return (strdup(gettext_noop("Pattern")));
}
else if (which == KAL_TILES)
{
return (strdup(gettext_noop("Tiles")));
}
else
{ /* KAL_BOTH */
return (strdup(gettext_noop("Kaleidoscope")));
} }
} }
// Return our descriptions, localized: // Return our descriptions, localized:
char * kalidescope_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED) char *kalidescope_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
{ {
if (which == KAL_LR) { if (which == KAL_LR)
return(strdup(gettext_noop("Click and drag the mouse to draw with two brushes that are symmetric across the left and right of your picture."))); {
} else if (which == KAL_UD) { return (strdup
return(strdup(gettext_noop("Click and drag the mouse to draw with two brushes that are symmetric across the top and bottom of your picture."))); (gettext_noop
} else if (which == KAL_PATTERN) { ("Click and drag the mouse to draw with two brushes that are symmetric across the left and right of your picture.")));
return(strdup(gettext_noop("Click and drag the mouse to draw a pattern across the picture."))); }
} else if (which == KAL_TILES) { else if (which == KAL_UD)
return(strdup(gettext_noop("Click and drag the mouse to draw a pattern that is symmetric across the picture."))); {
} else { /* KAL_BOTH */ return (strdup
return(strdup(gettext_noop("Click and drag the mouse to draw with symmetric brushes (a kaleidoscope)."))); (gettext_noop
("Click and drag the mouse to draw with two brushes that are symmetric across the top and bottom of your picture.")));
}
else if (which == KAL_PATTERN)
{
return (strdup(gettext_noop("Click and drag the mouse to draw a pattern across the picture.")));
}
else if (which == KAL_TILES)
{
return (strdup(gettext_noop("Click and drag the mouse to draw a pattern that is symmetric across the picture.")));
}
else
{ /* KAL_BOTH */
return (strdup(gettext_noop("Click and drag the mouse to draw with symmetric brushes (a kaleidoscope).")));
} }
} }
// Do the effect: // Do the effect:
static void do_kalidescope(void * ptr, int which, SDL_Surface * canvas, static void do_kalidescope(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y) 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;
int i, j; int i, j;
Uint32 colr; Uint32 colr;
colr = SDL_MapRGB(canvas->format, colr = SDL_MapRGB(canvas->format, kalidescope_r, kalidescope_g, kalidescope_b);
kalidescope_r,
kalidescope_g,
kalidescope_b);
for (yy = -8; yy < 8; yy++) for (yy = -8; yy < 8; yy++)
{ {
@ -168,19 +185,24 @@ static void do_kalidescope(void * ptr, int which, SDL_Surface * canvas,
{ {
api->putpixel(canvas, x + xx, y + yy, colr); api->putpixel(canvas, x + xx, y + yy, colr);
if (which == KAL_LR || which == KAL_BOTH) { if (which == KAL_LR || which == KAL_BOTH)
{
api->putpixel(canvas, canvas->w - 1 - x + xx, y + yy, colr); api->putpixel(canvas, canvas->w - 1 - x + xx, y + yy, colr);
if (which == KAL_BOTH) { if (which == KAL_BOTH)
{
api->putpixel(canvas, canvas->w - 1 - x + xx, canvas->h - 1 - y + yy, colr); api->putpixel(canvas, canvas->w - 1 - x + xx, canvas->h - 1 - y + yy, colr);
} }
} }
if (which == KAL_UD || which == KAL_BOTH) { if (which == KAL_UD || which == KAL_BOTH)
{
api->putpixel(canvas, x + xx, canvas->h - 1 - y + yy, colr); api->putpixel(canvas, x + xx, canvas->h - 1 - y + yy, colr);
} }
if (which == KAL_PATTERN || which == KAL_TILES) { if (which == KAL_PATTERN || which == KAL_TILES)
{
for (i = 0; i <= canvas->w; i += square_size) for (i = 0; i <= canvas->w; i += square_size)
for (j = 0; j <= canvas->h; j += square_size){ for (j = 0; j <= canvas->h; j += square_size)
{
api->putpixel(canvas, i + xx + x % square_size, j + yy + y % square_size, colr); api->putpixel(canvas, i + xx + x % square_size, j + yy + y % square_size, colr);
if (which == KAL_TILES) if (which == KAL_TILES)
api->putpixel(canvas, i + yy + y % square_size, j + xx + x % square_size, colr); api->putpixel(canvas, i + yy + y % square_size, j + xx + x % square_size, colr);
@ -193,10 +215,9 @@ static void do_kalidescope(void * ptr, int which, SDL_Surface * canvas,
// Affect the canvas on drag: // Affect the canvas on drag:
void kalidescope_drag(magic_api * api, int which, SDL_Surface * canvas, void kalidescope_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_kalidescope); api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_kalidescope);
update_rect->x = 0; update_rect->x = 0;
update_rect->y = 0; update_rect->y = 0;
@ -208,8 +229,7 @@ void kalidescope_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click: // Affect the canvas on click:
void kalidescope_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED, void kalidescope_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)
{ {
kalidescope_drag(api, which, canvas, last, x, y, x, y, update_rect); kalidescope_drag(api, which, canvas, last, x, y, x, y, update_rect);
} }
@ -217,8 +237,7 @@ void kalidescope_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
// Affect the canvas on release: // Affect the canvas on release:
void kalidescope_release(magic_api * api, int which ATTRIBUTE_UNUSED, void kalidescope_release(magic_api * api, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{ {
api->stopsound(); api->stopsound();
} }
@ -256,5 +275,5 @@ void kalidescope_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE
int kalidescope_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) int kalidescope_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{ {
return(MODE_PAINT); return (MODE_PAINT);
} }