indent alien.c

This commit is contained in:
Bill Kendrick 2017-10-15 11:37:22 -07:00
parent 14af5f0114
commit d62e1ec901

View file

@ -43,48 +43,50 @@
#define gettext_noop(String) String #define gettext_noop(String) String
#endif #endif
static const double alien_ANGLE[] = {0,0,0}; static const double alien_ANGLE[] = { 0, 0, 0 };
static const double alien_FREQUENCY[] = {1,1,1}; static const double alien_FREQUENCY[] = { 1, 1, 1 };
static const int alien_RADIUS = 16; static const int alien_RADIUS = 16;
enum { enum
TOOL_alien, {
alien_NUM_TOOLS TOOL_alien,
alien_NUM_TOOLS
}; };
static Mix_Chunk * alien_snd_effect[alien_NUM_TOOLS]; static Mix_Chunk *alien_snd_effect[alien_NUM_TOOLS];
const char * alien_snd_filenames[alien_NUM_TOOLS] = { const char *alien_snd_filenames[alien_NUM_TOOLS] = {
"alien.ogg", "alien.ogg",
}; };
const char * alien_icon_filenames[alien_NUM_TOOLS] = {
const char *alien_icon_filenames[alien_NUM_TOOLS] = {
"alien.png", "alien.png",
}; };
const char * alien_names[alien_NUM_TOOLS] = {
const char *alien_names[alien_NUM_TOOLS] = {
gettext_noop("Color Shift"), gettext_noop("Color Shift"),
}; };
const char * alien_descs[alien_NUM_TOOLS][2] = {
const char *alien_descs[alien_NUM_TOOLS][2] = {
{gettext_noop("Click and drag the mouse to change the colors in parts of your picture."), {gettext_noop("Click and drag the mouse to change the colors in parts of your picture."),
gettext_noop("Click to change the colors in your entire picture."),}, gettext_noop("Click to change the colors in your entire picture."),},
}; };
// Prototypes // Prototypes
Uint32 alien_api_version(void); Uint32 alien_api_version(void);
int alien_init(magic_api * api); int alien_init(magic_api * api);
int alien_get_tool_count(magic_api * api); int alien_get_tool_count(magic_api * api);
SDL_Surface * alien_get_icon(magic_api * api, int which); SDL_Surface *alien_get_icon(magic_api * api, int which);
char * alien_get_name(magic_api * api, int which); char *alien_get_name(magic_api * api, int which);
char * alien_get_description(magic_api * api, int which, int mode); char *alien_get_description(magic_api * api, int which, int mode);
void alien_drag(magic_api * api, int which, SDL_Surface * canvas, void alien_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); Mix_Chunk *magic_loadsound(char *file);
Mix_Chunk * magic_loadsound(char* file);
void alien_click(magic_api * api, int which, int mode, void alien_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 alien_release(magic_api * api, int which, void alien_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 alien_shutdown(magic_api * api); void alien_shutdown(magic_api * api);
void alien_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b); void alien_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int alien_requires_colors(magic_api * api, int which); int alien_requires_colors(magic_api * api, int which);
@ -93,109 +95,134 @@ void alien_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
int alien_modes(magic_api * api, int which); int alien_modes(magic_api * api, int which);
Uint32 alien_api_version(void) { return(TP_MAGIC_API_VERSION); } Uint32 alien_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
//Load sounds //Load sounds
int alien_init(magic_api * api){ int alien_init(magic_api * api)
{
int i; int i;
char fname[1024]; char fname[1024];
srand(time(0)); srand(time(0));
for (i = 0; i < alien_NUM_TOOLS; i++){ for (i = 0; i < alien_NUM_TOOLS; i++)
snprintf(fname, sizeof(fname), "%s/sounds/magic/%s", api->data_directory, alien_snd_filenames[i]); {
alien_snd_effect[i] = Mix_LoadWAV(fname); snprintf(fname, sizeof(fname), "%s/sounds/magic/%s", api->data_directory, alien_snd_filenames[i]);
} alien_snd_effect[i] = Mix_LoadWAV(fname);
return(1); }
return (1);
} }
int alien_get_tool_count(magic_api * api ATTRIBUTE_UNUSED){ int alien_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
return(alien_NUM_TOOLS); {
return (alien_NUM_TOOLS);
} }
// Load our icons: // Load our icons:
SDL_Surface * alien_get_icon(magic_api * api, int which){ SDL_Surface *alien_get_icon(magic_api * api, int which)
{
char fname[1024]; char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, alien_icon_filenames[which]); snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, alien_icon_filenames[which]);
return(IMG_Load(fname)); return (IMG_Load(fname));
} }
// Return our names, localized: // Return our names, localized:
char * alien_get_name(magic_api * api ATTRIBUTE_UNUSED, int which){ char *alien_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
return(strdup(gettext_noop(alien_names[which]))); {
return (strdup(gettext_noop(alien_names[which])));
} }
// Return our descriptions, localized: // Return our descriptions, localized:
char * alien_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode){ char *alien_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode)
return(strdup(gettext_noop(alien_descs[which][mode-1]))); {
return (strdup(gettext_noop(alien_descs[which][mode - 1])));
} }
//Do the effect for one pixel //Do the effect for one pixel
static void do_alien_pixel(void * ptr, int which ATTRIBUTE_UNUSED, static void do_alien_pixel(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
int x, int y){ {
magic_api * api = (magic_api *) ptr; magic_api *api = (magic_api *) ptr;
Uint8 temp[3]; Uint8 temp[3];
double temp2[3]; double temp2[3];
int k; int k;
SDL_GetRGB(api->getpixel(canvas,x, y), canvas->format, &temp[0], &temp[1], &temp[2]); SDL_GetRGB(api->getpixel(canvas, x, y), canvas->format, &temp[0], &temp[1], &temp[2]);
for (k =0;k<3;k++){ for (k = 0; k < 3; k++)
{
//EP temp2[k] = clamp(0,127.5 * (1.0 + sin (((temp[k] / 127.5 - 1.0) * alien_FREQUENCY[k] + alien_ANGLE[k] / 180.0) * M_PI)),255); //EP temp2[k] = clamp(0,127.5 * (1.0 + sin (((temp[k] / 127.5 - 1.0) * alien_FREQUENCY[k] + alien_ANGLE[k] / 180.0) * M_PI)),255);
temp2[k] = clamp(0.0, temp2[k] = clamp(0.0,
127.5 * ( 127.5 * (1.0 +
1.0 + sin (((temp[k] / 127.5 - 1.0) * alien_FREQUENCY[k] + alien_ANGLE[k] / 180.0) * M_PI) sin(((temp[k] / 127.5 - 1.0) * alien_FREQUENCY[k] + alien_ANGLE[k] / 180.0) * M_PI)),
), 255.0);
255.0); }
} api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, temp2[0], temp2[1], temp2[2]));
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, temp2[0], temp2[1], temp2[2]));
} }
// Do the effect for the full image // Do the effect for the full image
static void do_alien_full(void * ptr,SDL_Surface * canvas, SDL_Surface * last, int which){ static void do_alien_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int which)
{
magic_api * api = (magic_api *) ptr; magic_api *api = (magic_api *) ptr;
int x,y; int x, y;
for (y = 0; y < last->h; y++){ for (y = 0; y < last->h; y++)
for (x=0; x < last->w; x++){ {
do_alien_pixel(ptr, which, canvas, last, x, y); for (x = 0; x < last->w; x++)
} {
} do_alien_pixel(ptr, which, canvas, last, x, y);
}
}
} }
//do the effect for the brush //do the effect for the brush
static void do_alien_brush(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y){ static void do_alien_brush(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
int xx, yy; int xx, yy;
magic_api * api = (magic_api *) ptr; magic_api *api = (magic_api *) ptr;
for (yy = y - alien_RADIUS; yy < y + alien_RADIUS; yy++) for (yy = y - alien_RADIUS; yy < y + alien_RADIUS; yy++)
{
for (xx = x - alien_RADIUS; xx < x + alien_RADIUS; xx++)
{ {
if (api->in_circle(xx - x, yy - y, alien_RADIUS) && for (xx = x - alien_RADIUS; xx < x + alien_RADIUS; xx++)
!api->touched(xx, yy)) {
{ if (api->in_circle(xx - x, yy - y, alien_RADIUS) && !api->touched(xx, yy))
do_alien_pixel(api, which, canvas, last, xx, yy); {
} do_alien_pixel(api, which, canvas, last, xx, yy);
}
}
} }
}
} }
// Affect the canvas on drag: // Affect the canvas on drag:
void alien_drag(magic_api * api, int which, SDL_Surface * canvas, void alien_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_alien_brush); api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_alien_brush);
api->playsound(alien_snd_effect[which], (x * 255) / canvas->w, 255); api->playsound(alien_snd_effect[which], (x * 255) / canvas->w, 255);
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 - alien_RADIUS; update_rect->x = ox - alien_RADIUS;
update_rect->y = oy - alien_RADIUS; update_rect->y = oy - alien_RADIUS;
@ -205,53 +232,60 @@ void alien_drag(magic_api * api, int which, SDL_Surface * canvas,
int use_sound = 1; int use_sound = 1;
Mix_Chunk * magic_loadsound(char* file){ Mix_Chunk *magic_loadsound(char *file)
Mix_Chunk * temp; {
Mix_Chunk *temp;
if (!use_sound){ if (!use_sound)
return (Mix_Chunk*)-1; {
} return (Mix_Chunk *) - 1;
}
temp = Mix_LoadWAV(file); temp = Mix_LoadWAV(file);
return temp; return temp;
} }
// Affect the canvas on click: // Affect the canvas on click:
void alien_click(magic_api * api, int which, int mode, void alien_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){ {
if (mode == MODE_PAINT) if (mode == MODE_PAINT)
alien_drag(api, which, canvas, last, x, y, x, y, update_rect); alien_drag(api, which, canvas, last, x, y, x, y, update_rect);
else{ else
update_rect->x = 0; {
update_rect->y = 0; update_rect->x = 0;
update_rect->w = canvas->w; update_rect->y = 0;
update_rect->h = canvas->h; update_rect->w = canvas->w;
do_alien_full(api, canvas, last, which); update_rect->h = canvas->h;
api->playsound(alien_snd_effect[which], 128, 255); do_alien_full(api, canvas, last, which);
} api->playsound(alien_snd_effect[which], 128, 255);
}
} }
// Affect the canvas on release: // Affect the canvas on release:
void alien_release(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, void alien_release(magic_api * api ATTRIBUTE_UNUSED, 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, SDL_Rect * update_rect ATTRIBUTE_UNUSED) int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{ {
} }
// No setup happened: // No setup happened:
void alien_shutdown(magic_api * api ATTRIBUTE_UNUSED) void alien_shutdown(magic_api * api ATTRIBUTE_UNUSED)
{ {
//Clean up sounds //Clean up sounds
int i; int i;
for(i=0; i<alien_NUM_TOOLS; i++){
if(alien_snd_effect[i] != NULL){ for (i = 0; i < alien_NUM_TOOLS; i++)
Mix_FreeChunk(alien_snd_effect[i]); {
} if (alien_snd_effect[i] != NULL)
} {
Mix_FreeChunk(alien_snd_effect[i]);
}
}
} }
// Record the color from Tux Paint: // Record the color from Tux Paint:
void alien_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED) void alien_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED)
{ {
} }
@ -261,16 +295,17 @@ int alien_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_
return 0; return 0;
} }
void alien_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED) void alien_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{ {
} }
void alien_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED) void alien_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{ {
} }
int alien_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) int alien_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{ {
return(MODE_FULLSCREEN|MODE_PAINT); return (MODE_FULLSCREEN | MODE_PAINT);
} }