indent ripples.c
This commit is contained in:
parent
247be68e46
commit
fea1b424ba
1 changed files with 53 additions and 56 deletions
|
|
@ -37,28 +37,23 @@
|
||||||
|
|
||||||
/* Our globals: */
|
/* Our globals: */
|
||||||
|
|
||||||
static Mix_Chunk * ripples_snd;
|
static Mix_Chunk *ripples_snd;
|
||||||
|
|
||||||
static int ripples_z, ripples_brite;
|
static int ripples_z, ripples_brite;
|
||||||
|
|
||||||
Uint32 ripples_api_version(void);
|
Uint32 ripples_api_version(void);
|
||||||
int ripples_init(magic_api * api);
|
int ripples_init(magic_api * api);
|
||||||
int ripples_get_tool_count(magic_api * api);
|
int ripples_get_tool_count(magic_api * api);
|
||||||
SDL_Surface * ripples_get_icon(magic_api * api, int which);
|
SDL_Surface *ripples_get_icon(magic_api * api, int which);
|
||||||
char * ripples_get_name(magic_api * api, int which);
|
char *ripples_get_name(magic_api * api, int which);
|
||||||
char * ripples_get_description(magic_api * api, int which, int mode);
|
char *ripples_get_description(magic_api * api, int which, int mode);
|
||||||
void ripples_drag(magic_api * api, int which, SDL_Surface * canvas,
|
void ripples_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);
|
static void ripples_linecb(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||||
static void ripples_linecb(void * ptr, int which,
|
|
||||||
SDL_Surface * canvas, SDL_Surface * last,
|
|
||||||
int x, int y);
|
|
||||||
void ripples_click(magic_api * api, int which, int mode,
|
void ripples_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 ripples_release(magic_api * api, int which,
|
void ripples_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 ripples_shutdown(magic_api * api);
|
void ripples_shutdown(magic_api * api);
|
||||||
void ripples_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
void ripples_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||||
int ripples_requires_colors(magic_api * api, int which);
|
int ripples_requires_colors(magic_api * api, int which);
|
||||||
|
|
@ -66,7 +61,10 @@ void ripples_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas
|
||||||
void ripples_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
void ripples_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||||
int ripples_modes(magic_api * api, int which);
|
int ripples_modes(magic_api * api, int which);
|
||||||
|
|
||||||
Uint32 ripples_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
Uint32 ripples_api_version(void)
|
||||||
|
{
|
||||||
|
return (TP_MAGIC_API_VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
#define deg_cos(x) cos((x) * M_PI / 180.0)
|
#define deg_cos(x) cos((x) * M_PI / 180.0)
|
||||||
#define deg_sin(x) sin((x) * M_PI / 180.0)
|
#define deg_sin(x) sin((x) * M_PI / 180.0)
|
||||||
|
|
@ -76,54 +74,51 @@ int ripples_init(magic_api * api)
|
||||||
{
|
{
|
||||||
char fname[1024];
|
char fname[1024];
|
||||||
|
|
||||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/ripples.ogg",
|
snprintf(fname, sizeof(fname), "%s/sounds/magic/ripples.ogg", api->data_directory);
|
||||||
api->data_directory);
|
|
||||||
ripples_snd = Mix_LoadWAV(fname);
|
ripples_snd = Mix_LoadWAV(fname);
|
||||||
|
|
||||||
return(1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We have multiple tools:
|
// We have multiple tools:
|
||||||
int ripples_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
int ripples_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
return(1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load our icons:
|
// Load our icons:
|
||||||
SDL_Surface * ripples_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
SDL_Surface *ripples_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
char fname[1024];
|
char fname[1024];
|
||||||
|
|
||||||
snprintf(fname, sizeof(fname), "%s/images/magic/ripples.png",
|
snprintf(fname, sizeof(fname), "%s/images/magic/ripples.png", api->data_directory);
|
||||||
api->data_directory);
|
|
||||||
|
|
||||||
return(IMG_Load(fname));
|
return (IMG_Load(fname));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return our names, localized:
|
// Return our names, localized:
|
||||||
char * ripples_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
char *ripples_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
return(strdup(gettext_noop("Ripples")));
|
return (strdup(gettext_noop("Ripples")));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return our descriptions, localized:
|
// Return our descriptions, localized:
|
||||||
char * ripples_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
char *ripples_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
return(strdup(gettext_noop("Click to make ripples appear over your picture.")));
|
return (strdup(gettext_noop("Click to make ripples appear over your picture.")));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Affect the canvas on drag:
|
// Affect the canvas on drag:
|
||||||
void ripples_drag(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
|
void ripples_drag(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
|
||||||
SDL_Surface * last ATTRIBUTE_UNUSED, int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED,
|
SDL_Surface * last ATTRIBUTE_UNUSED, int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED,
|
||||||
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ripples_linecb(void * ptr, int which ATTRIBUTE_UNUSED,
|
static void ripples_linecb(void *ptr, int which ATTRIBUTE_UNUSED,
|
||||||
SDL_Surface * canvas, SDL_Surface * last,
|
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;
|
||||||
Uint8 r, g, b;
|
Uint8 r, g, b;
|
||||||
Uint32 pix;
|
Uint32 pix;
|
||||||
|
|
||||||
|
|
@ -139,8 +134,7 @@ static void ripples_linecb(void * ptr, int which ATTRIBUTE_UNUSED,
|
||||||
|
|
||||||
// Affect the canvas on click:
|
// Affect the canvas on click:
|
||||||
void ripples_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
|
void ripples_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)
|
|
||||||
{
|
{
|
||||||
float radius;
|
float radius;
|
||||||
float fli;
|
float fli;
|
||||||
|
|
@ -149,25 +143,25 @@ void ripples_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
|
||||||
radius = 100;
|
radius = 100;
|
||||||
|
|
||||||
for (fli = 0; fli < radius; fli = fli + .25)
|
for (fli = 0; fli < radius; fli = fli + .25)
|
||||||
{
|
|
||||||
ripples_z = (10 * deg_sin(((50 * 50) / (fli + 4)) * 10));
|
|
||||||
|
|
||||||
ox = fli * deg_cos(0) + x;
|
|
||||||
oy = -fli * deg_sin(0) + y;
|
|
||||||
|
|
||||||
for (d = 0; d <= 360 + (360 / (fli + 1)); d = d + 360 / (fli + 1))
|
|
||||||
{
|
{
|
||||||
nx = fli * deg_cos(d) + x;
|
ripples_z = (10 * deg_sin(((50 * 50) / (fli + 4)) * 10));
|
||||||
ny = -fli * deg_sin(d) + y;
|
|
||||||
|
|
||||||
ripples_brite = (ripples_z * 20 * deg_sin(d + 45)) / ((fli / 4) + 1);
|
|
||||||
|
|
||||||
api->line((void *) api, which, canvas, last, ox, oy, nx, ny, 1, ripples_linecb);
|
ox = fli * deg_cos(0) + x;
|
||||||
|
oy = -fli * deg_sin(0) + y;
|
||||||
ox = nx;
|
|
||||||
oy = ny;
|
for (d = 0; d <= 360 + (360 / (fli + 1)); d = d + 360 / (fli + 1))
|
||||||
|
{
|
||||||
|
nx = fli * deg_cos(d) + x;
|
||||||
|
ny = -fli * deg_sin(d) + y;
|
||||||
|
|
||||||
|
ripples_brite = (ripples_z * 20 * deg_sin(d + 45)) / ((fli / 4) + 1);
|
||||||
|
|
||||||
|
api->line((void *)api, which, canvas, last, ox, oy, nx, ny, 1, ripples_linecb);
|
||||||
|
|
||||||
|
ox = nx;
|
||||||
|
oy = ny;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
update_rect->x = x - 100;
|
update_rect->x = x - 100;
|
||||||
update_rect->y = y - 100;
|
update_rect->y = y - 100;
|
||||||
|
|
@ -179,8 +173,8 @@ void ripples_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
|
||||||
|
|
||||||
// Affect the canvas on release:
|
// Affect the canvas on release:
|
||||||
void ripples_release(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
|
void ripples_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)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -192,7 +186,8 @@ void ripples_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Record the color from Tux Paint:
|
// Record the color from Tux Paint:
|
||||||
void ripples_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
|
void ripples_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
|
||||||
|
Uint8 b ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -202,15 +197,17 @@ int ripples_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUT
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ripples_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
void ripples_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||||
|
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void ripples_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
void ripples_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||||
|
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int ripples_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
int ripples_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
return(MODE_ONECLICK);
|
return (MODE_ONECLICK);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue