indent xor.c

This commit is contained in:
Bill Kendrick 2017-10-15 11:51:27 -07:00
parent 5a88d476c8
commit 4ab8280bbe

View file

@ -44,16 +44,13 @@ char * xor_get_name(magic_api * api, int which);
char *xor_get_description(magic_api * api, int which, int mode); char *xor_get_description(magic_api * api, int which, int mode);
void xor_drag(magic_api * api, int which, SDL_Surface * canvas, void xor_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 xor_click(magic_api * api, int which, int mode, void xor_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 xor_release(magic_api * api, int which, void xor_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 xor_shutdown(magic_api * api); void xor_shutdown(magic_api * api);
void xor_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b); void xor_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
@ -62,14 +59,16 @@ void xor_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void xor_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas); void xor_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int xor_modes(magic_api * api, int which); int xor_modes(magic_api * api, int which);
Uint32 xor_api_version(void) { return(TP_MAGIC_API_VERSION); } Uint32 xor_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
int xor_init(magic_api * api) int xor_init(magic_api * api)
{ {
char fname[1024]; char fname[1024];
snprintf(fname, sizeof(fname), "%s/sounds/magic/xor.ogg", snprintf(fname, sizeof(fname), "%s/sounds/magic/xor.ogg", api->data_directory);
api->data_directory);
xor_snd = Mix_LoadWAV(fname); xor_snd = Mix_LoadWAV(fname);
return (1); return (1);
@ -84,8 +83,7 @@ SDL_Surface * xor_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{ {
char fname[1024]; char fname[1024];
snprintf(fname, sizeof(fname), "%s/images/magic/xor.png", snprintf(fname, sizeof(fname), "%s/images/magic/xor.png", api->data_directory);
api->data_directory);
return (IMG_Load(fname)); return (IMG_Load(fname));
} }
@ -113,12 +111,15 @@ static void do_xor(void * ptr, int which ATTRIBUTE_UNUSED,
SDL_GetRGB(api->getpixel(canvas, x, y), canvas->format, &r, &g, &b); SDL_GetRGB(api->getpixel(canvas, x, y), canvas->format, &r, &g, &b);
api->rgbtohsv(r, g, b, &hue, &sat, &val); api->rgbtohsv(r, g, b, &hue, &sat, &val);
if (sat == 0) xor = (2*(int)hue+(x^y))%360; if (sat == 0)
else xor = ((int)hue+(x^y))%360; xor = (2 * (int)hue + (x ^ y)) % 360;
else
xor = ((int)hue + (x ^ y)) % 360;
api->hsvtorgb(xor, 1, 1, &r, &g, &b); api->hsvtorgb(xor, 1, 1, &r, &g, &b);
pixel = SDL_MapRGB(canvas->format, r, g, b); pixel = SDL_MapRGB(canvas->format, r, g, b);
api->putpixel(canvas, x, y, pixel); api->putpixel(canvas, x, y, pixel);
} }
static void do_xor_circle(void *ptr, int which ATTRIBUTE_UNUSED, static void do_xor_circle(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y) SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
{ {
@ -131,20 +132,32 @@ static void do_xor_circle(void * ptr, int which ATTRIBUTE_UNUSED,
{ {
if (api->in_circle(xx, yy, 16)) if (api->in_circle(xx, yy, 16))
{ {
if (!api->touched(xx+x,yy+y)) do_xor(api,which,canvas,last,x + xx,y + yy); if (!api->touched(xx + x, yy + y))
do_xor(api, which, canvas, last, x + xx, y + yy);
} }
} }
} }
} }
void xor_drag(magic_api * api, int which, SDL_Surface * canvas, void xor_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last ATTRIBUTE_UNUSED, int ox, int oy, int x, int y, SDL_Surface * last ATTRIBUTE_UNUSED, 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_xor_circle); api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_xor_circle);
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;
@ -155,8 +168,7 @@ void xor_drag(magic_api * api, int which, SDL_Surface * canvas,
} }
void xor_click(magic_api * api, int which, int mode, void xor_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y, SDL_Rect * update_rect)
int x, int y, SDL_Rect * update_rect)
{ {
if (mode == MODE_PAINT) if (mode == MODE_PAINT)
xor_drag(api, which, canvas, last, x, y, x, y, update_rect); xor_drag(api, which, canvas, last, x, y, x, y, update_rect);
@ -188,7 +200,8 @@ void xor_shutdown(magic_api * api ATTRIBUTE_UNUSED)
Mix_FreeChunk(xor_snd); Mix_FreeChunk(xor_snd);
} }
void xor_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED) void xor_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED)
{ {
} }
@ -197,11 +210,13 @@ int xor_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UN
return 0; return 0;
} }
void xor_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED) void xor_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{ {
} }
void xor_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED) void xor_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{ {
} }