indent emboss.c

This commit is contained in:
Bill Kendrick 2017-10-15 11:44:03 -07:00
parent 3d2cd7d327
commit 16a92fb71a

View file

@ -35,27 +35,24 @@
/* Our globals: */ /* Our globals: */
static Mix_Chunk * emboss_snd; static Mix_Chunk *emboss_snd;
// Prototypes // Prototypes
Uint32 emboss_api_version(void); Uint32 emboss_api_version(void);
int emboss_init(magic_api * api); int emboss_init(magic_api * api);
int emboss_get_tool_count(magic_api * api); int emboss_get_tool_count(magic_api * api);
SDL_Surface * emboss_get_icon(magic_api * api, int which); SDL_Surface *emboss_get_icon(magic_api * api, int which);
char * emboss_get_name(magic_api * api, int which); char *emboss_get_name(magic_api * api, int which);
char * emboss_get_description(magic_api * api, int which, int mode); char *emboss_get_description(magic_api * api, int which, int mode);
void emboss_drag(magic_api * api, int which, SDL_Surface * canvas, void emboss_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 emboss_click(magic_api * api, int which, int mode, void emboss_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 emboss_release(magic_api * api, int which, void emboss_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 emboss_shutdown(magic_api * api); void emboss_shutdown(magic_api * api);
void emboss_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b); void emboss_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
@ -65,7 +62,10 @@ void emboss_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas
int emboss_modes(magic_api * api, int which); int emboss_modes(magic_api * api, int which);
Uint32 emboss_api_version(void) { return(TP_MAGIC_API_VERSION); } Uint32 emboss_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
// No setup required: // No setup required:
@ -73,51 +73,47 @@ int emboss_init(magic_api * api)
{ {
char fname[1024]; char fname[1024];
snprintf(fname, sizeof(fname), "%s/sounds/magic/emboss.ogg", snprintf(fname, sizeof(fname), "%s/sounds/magic/emboss.ogg", api->data_directory);
api->data_directory);
emboss_snd = Mix_LoadWAV(fname); emboss_snd = Mix_LoadWAV(fname);
return(1); return (1);
} }
// We have multiple tools: // We have multiple tools:
int emboss_get_tool_count(magic_api * api ATTRIBUTE_UNUSED) int emboss_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{ {
return(1); return (1);
} }
// Load our icons: // Load our icons:
SDL_Surface * emboss_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED) SDL_Surface *emboss_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{ {
char fname[1024]; char fname[1024];
snprintf(fname, sizeof(fname), "%s/images/magic/emboss.png", snprintf(fname, sizeof(fname), "%s/images/magic/emboss.png", api->data_directory);
api->data_directory);
return(IMG_Load(fname)); return (IMG_Load(fname));
} }
// Return our names, localized: // Return our names, localized:
char * emboss_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) char *emboss_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{ {
return(strdup(gettext_noop("Emboss"))); return (strdup(gettext_noop("Emboss")));
} }
// Return our descriptions, localized: // Return our descriptions, localized:
char * emboss_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED) char *emboss_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{ {
return(strdup(gettext_noop("Click and drag the mouse to emboss the picture."))); return (strdup(gettext_noop("Click and drag the mouse to emboss the picture.")));
} }
// Do the effect: // Do the effect:
static void do_emboss(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last, static void do_emboss(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; int xx, yy;
Uint8 r1, g1, b1, Uint8 r1, g1, b1, r2, g2, b2;
r2, g2, b2;
int r, g, b; int r, g, b;
float h, s, v; float h, s, v;
int avg1, avg2; int avg1, avg2;
@ -139,8 +135,10 @@ static void do_emboss(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canv
api->rgbtohsv(r1, g1, b1, &h, &s, &v); api->rgbtohsv(r1, g1, b1, &h, &s, &v);
r = 128 + (((avg1 - avg2) * 3) / 2); r = 128 + (((avg1 - avg2) * 3) / 2);
if (r < 0) r = 0; if (r < 0)
if (r > 255) r = 255; r = 0;
if (r > 255)
r = 255;
g = b = r; g = b = r;
v = (r / 255.0); v = (r / 255.0);
@ -156,27 +154,36 @@ static void do_emboss(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canv
// Affect the canvas on drag: // Affect the canvas on drag:
void emboss_drag(magic_api * api, int which, SDL_Surface * canvas, void emboss_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_emboss); api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_emboss);
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;
update_rect->w = (x + 16) - update_rect->x; update_rect->w = (x + 16) - update_rect->x;
update_rect->h = (y + 16) - update_rect->h; update_rect->h = (y + 16) - update_rect->h;
api->playsound(emboss_snd, api->playsound(emboss_snd, (x * 255) / canvas->w, 255);
(x * 255) / canvas->w, 255);
} }
// Affect the canvas on click: // Affect the canvas on click:
void emboss_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED, void emboss_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)
{ {
emboss_drag(api, which, canvas, last, x, y, x, y, update_rect); emboss_drag(api, which, canvas, last, x, y, x, y, update_rect);
} }
@ -196,7 +203,8 @@ void emboss_shutdown(magic_api * api ATTRIBUTE_UNUSED)
} }
// Record the color from Tux Paint: // Record the color from Tux Paint:
void emboss_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED) void emboss_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED)
{ {
} }
@ -206,15 +214,17 @@ int emboss_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE
return 0; return 0;
} }
void emboss_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED) void emboss_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{ {
} }
void emboss_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED) void emboss_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{ {
} }
int emboss_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) int emboss_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{ {
return(MODE_PAINT); /* FIXME - Can also be turned into a full-image effect */ return (MODE_PAINT); /* FIXME - Can also be turned into a full-image effect */
} }