indent blocks_chalk_drip.c
This commit is contained in:
parent
5b76d99ae6
commit
5ada032452
1 changed files with 150 additions and 148 deletions
|
|
@ -35,7 +35,8 @@
|
||||||
|
|
||||||
/* What tools we contain: */
|
/* What tools we contain: */
|
||||||
|
|
||||||
enum {
|
enum
|
||||||
|
{
|
||||||
TOOL_BLOCKS,
|
TOOL_BLOCKS,
|
||||||
TOOL_CHALK,
|
TOOL_CHALK,
|
||||||
TOOL_DRIP,
|
TOOL_DRIP,
|
||||||
|
|
@ -45,7 +46,7 @@ enum {
|
||||||
|
|
||||||
/* Our globals: */
|
/* Our globals: */
|
||||||
|
|
||||||
static Mix_Chunk * snd_effect[NUM_TOOLS];
|
static Mix_Chunk *snd_effect[NUM_TOOLS];
|
||||||
|
|
||||||
|
|
||||||
/* Our function prototypes: */
|
/* Our function prototypes: */
|
||||||
|
|
@ -53,21 +54,16 @@ static Mix_Chunk * snd_effect[NUM_TOOLS];
|
||||||
int blocks_chalk_drip_init(magic_api * api);
|
int blocks_chalk_drip_init(magic_api * api);
|
||||||
Uint32 blocks_chalk_drip_api_version(void);
|
Uint32 blocks_chalk_drip_api_version(void);
|
||||||
int blocks_chalk_drip_get_tool_count(magic_api * api);
|
int blocks_chalk_drip_get_tool_count(magic_api * api);
|
||||||
SDL_Surface * blocks_chalk_drip_get_icon(magic_api * api, int which);
|
SDL_Surface *blocks_chalk_drip_get_icon(magic_api * api, int which);
|
||||||
char * blocks_chalk_drip_get_name(magic_api * api, int which);
|
char *blocks_chalk_drip_get_name(magic_api * api, int which);
|
||||||
char * blocks_chalk_drip_get_description(magic_api * api, int which, int mode);
|
char *blocks_chalk_drip_get_description(magic_api * api, int which, int mode);
|
||||||
static void blocks_chalk_drip_linecb(void * ptr, int which,
|
static void blocks_chalk_drip_linecb(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||||
SDL_Surface * canvas, SDL_Surface * last,
|
|
||||||
int x, int y);
|
|
||||||
void blocks_chalk_drip_drag(magic_api * api, int which, SDL_Surface * canvas,
|
void blocks_chalk_drip_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 blocks_chalk_drip_click(magic_api * api, int which, int mode,
|
void blocks_chalk_drip_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 blocks_chalk_drip_release(magic_api * api, int which,
|
void blocks_chalk_drip_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 blocks_chalk_drip_shutdown(magic_api * api);
|
void blocks_chalk_drip_shutdown(magic_api * api);
|
||||||
void blocks_chalk_drip_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
void blocks_chalk_drip_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||||
int blocks_chalk_drip_requires_colors(magic_api * api, int which);
|
int blocks_chalk_drip_requires_colors(magic_api * api, int which);
|
||||||
|
|
@ -81,90 +77,82 @@ int blocks_chalk_drip_init(magic_api * api)
|
||||||
{
|
{
|
||||||
char fname[1024];
|
char fname[1024];
|
||||||
|
|
||||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/blocks.wav",
|
snprintf(fname, sizeof(fname), "%s/sounds/magic/blocks.wav", api->data_directory);
|
||||||
api->data_directory);
|
|
||||||
snd_effect[0] = Mix_LoadWAV(fname);
|
snd_effect[0] = Mix_LoadWAV(fname);
|
||||||
|
|
||||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/chalk.wav",
|
snprintf(fname, sizeof(fname), "%s/sounds/magic/chalk.wav", api->data_directory);
|
||||||
api->data_directory);
|
|
||||||
snd_effect[1] = Mix_LoadWAV(fname);
|
snd_effect[1] = Mix_LoadWAV(fname);
|
||||||
|
|
||||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/drip.wav",
|
snprintf(fname, sizeof(fname), "%s/sounds/magic/drip.wav", api->data_directory);
|
||||||
api->data_directory);
|
|
||||||
snd_effect[2] = Mix_LoadWAV(fname);
|
snd_effect[2] = Mix_LoadWAV(fname);
|
||||||
|
|
||||||
return(1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint32 blocks_chalk_drip_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
Uint32 blocks_chalk_drip_api_version(void)
|
||||||
|
{
|
||||||
|
return (TP_MAGIC_API_VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// We have multiple tools:
|
// We have multiple tools:
|
||||||
int blocks_chalk_drip_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
int blocks_chalk_drip_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
return(NUM_TOOLS);
|
return (NUM_TOOLS);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load our icons:
|
// Load our icons:
|
||||||
SDL_Surface * blocks_chalk_drip_get_icon(magic_api * api, int which)
|
SDL_Surface *blocks_chalk_drip_get_icon(magic_api * api, int which)
|
||||||
{
|
{
|
||||||
char fname[1024];
|
char fname[1024];
|
||||||
|
|
||||||
if (which == TOOL_BLOCKS)
|
if (which == TOOL_BLOCKS)
|
||||||
{
|
{
|
||||||
snprintf(fname, sizeof(fname), "%s/images/magic/blocks.png",
|
snprintf(fname, sizeof(fname), "%s/images/magic/blocks.png", api->data_directory);
|
||||||
api->data_directory);
|
|
||||||
}
|
}
|
||||||
else if (which == TOOL_CHALK)
|
else if (which == TOOL_CHALK)
|
||||||
{
|
{
|
||||||
snprintf(fname, sizeof(fname), "%s/images/magic/chalk.png",
|
snprintf(fname, sizeof(fname), "%s/images/magic/chalk.png", api->data_directory);
|
||||||
api->data_directory);
|
|
||||||
}
|
}
|
||||||
else if (which == TOOL_DRIP)
|
else if (which == TOOL_DRIP)
|
||||||
{
|
{
|
||||||
snprintf(fname, sizeof(fname), "%s/images/magic/drip.png",
|
snprintf(fname, sizeof(fname), "%s/images/magic/drip.png", api->data_directory);
|
||||||
api->data_directory);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return(IMG_Load(fname));
|
return (IMG_Load(fname));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return our names, localized:
|
// Return our names, localized:
|
||||||
char * blocks_chalk_drip_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
|
char *blocks_chalk_drip_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
|
||||||
{
|
{
|
||||||
if (which == TOOL_BLOCKS)
|
if (which == TOOL_BLOCKS)
|
||||||
return(strdup(gettext_noop("Blocks")));
|
return (strdup(gettext_noop("Blocks")));
|
||||||
else if (which == TOOL_CHALK)
|
else if (which == TOOL_CHALK)
|
||||||
return(strdup(gettext_noop("Chalk")));
|
return (strdup(gettext_noop("Chalk")));
|
||||||
else if (which == TOOL_DRIP)
|
else if (which == TOOL_DRIP)
|
||||||
return(strdup(gettext_noop("Drip")));
|
return (strdup(gettext_noop("Drip")));
|
||||||
|
|
||||||
return(NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return our descriptions, localized:
|
// Return our descriptions, localized:
|
||||||
char * blocks_chalk_drip_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
|
char *blocks_chalk_drip_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
if (which == TOOL_BLOCKS)
|
if (which == TOOL_BLOCKS)
|
||||||
return(strdup(gettext_noop(
|
return (strdup(gettext_noop("Click and drag the mouse around to make the picture blocky.")));
|
||||||
"Click and drag the mouse around to make the picture blocky.")));
|
|
||||||
else if (which == TOOL_CHALK)
|
else if (which == TOOL_CHALK)
|
||||||
return(strdup(gettext_noop(
|
return (strdup(gettext_noop("Click and drag the mouse around to turn the picture into a chalk drawing.")));
|
||||||
"Click and drag the mouse around to turn the picture into a chalk drawing.")));
|
|
||||||
else if (which == TOOL_DRIP)
|
else if (which == TOOL_DRIP)
|
||||||
return(strdup(gettext_noop(
|
return (strdup(gettext_noop("Click and drag the mouse around to make the picture drip.")));
|
||||||
"Click and drag the mouse around to make the picture drip.")));
|
|
||||||
|
|
||||||
return(NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do the effect:
|
// Do the effect:
|
||||||
|
|
||||||
static void blocks_chalk_drip_linecb(void * ptr, int which,
|
static void blocks_chalk_drip_linecb(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
|
||||||
SDL_Surface * canvas, SDL_Surface * last,
|
|
||||||
int x, int y)
|
|
||||||
{
|
{
|
||||||
magic_api * api = (magic_api *) ptr;
|
magic_api *api = (magic_api *) ptr;
|
||||||
int xx, yy;
|
int xx, yy;
|
||||||
int h;
|
int h;
|
||||||
SDL_Rect src, dest;
|
SDL_Rect src, dest;
|
||||||
|
|
@ -188,9 +176,11 @@ static void blocks_chalk_drip_linecb(void * ptr, int which,
|
||||||
Uint32 p_or = 0;
|
Uint32 p_or = 0;
|
||||||
Uint32 p_and = ~0;
|
Uint32 p_and = ~0;
|
||||||
unsigned i = 16;
|
unsigned i = 16;
|
||||||
|
|
||||||
while (i--)
|
while (i--)
|
||||||
{
|
{
|
||||||
Uint32 p_tmp;
|
Uint32 p_tmp;
|
||||||
|
|
||||||
p_tmp = api->getpixel(last, xx + (i >> 2), yy + (i & 3));
|
p_tmp = api->getpixel(last, xx + (i >> 2), yy + (i & 3));
|
||||||
p_or |= p_tmp;
|
p_or |= p_tmp;
|
||||||
p_and &= p_tmp;
|
p_and &= p_tmp;
|
||||||
|
|
@ -205,6 +195,7 @@ static void blocks_chalk_drip_linecb(void * ptr, int which,
|
||||||
double r_sum = 0.0;
|
double r_sum = 0.0;
|
||||||
double g_sum = 0.0;
|
double g_sum = 0.0;
|
||||||
double b_sum = 0.0;
|
double b_sum = 0.0;
|
||||||
|
|
||||||
i = 16;
|
i = 16;
|
||||||
while (i--)
|
while (i--)
|
||||||
{
|
{
|
||||||
|
|
@ -242,8 +233,7 @@ static void blocks_chalk_drip_linecb(void * ptr, int which,
|
||||||
dest.w = (rand() % 4) + 2;
|
dest.w = (rand() % 4) + 2;
|
||||||
dest.h = (rand() % 4) + 2;
|
dest.h = (rand() % 4) + 2;
|
||||||
|
|
||||||
colr = api->getpixel(last, clamp(0, xx, canvas->w - 1),
|
colr = api->getpixel(last, clamp(0, xx, canvas->w - 1), clamp(0, yy, canvas->h - 1));
|
||||||
clamp(0, yy, canvas->h - 1));
|
|
||||||
SDL_FillRect(canvas, &dest, colr);
|
SDL_FillRect(canvas, &dest, colr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -272,13 +262,24 @@ static void blocks_chalk_drip_linecb(void * ptr, int which,
|
||||||
|
|
||||||
// Affect the canvas on drag:
|
// Affect the canvas on drag:
|
||||||
void blocks_chalk_drip_drag(magic_api * api, int which, SDL_Surface * canvas,
|
void blocks_chalk_drip_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, blocks_chalk_drip_linecb);
|
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, blocks_chalk_drip_linecb);
|
||||||
|
|
||||||
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;
|
||||||
|
|
@ -290,8 +291,7 @@ void blocks_chalk_drip_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||||
|
|
||||||
// Affect the canvas on click:
|
// Affect the canvas on click:
|
||||||
void blocks_chalk_drip_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
|
void blocks_chalk_drip_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)
|
|
||||||
{
|
{
|
||||||
blocks_chalk_drip_drag(api, which, canvas, last, x, y, x, y, update_rect);
|
blocks_chalk_drip_drag(api, which, canvas, last, x, y, x, y, update_rect);
|
||||||
}
|
}
|
||||||
|
|
@ -325,15 +325,17 @@ int blocks_chalk_drip_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int whic
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void blocks_chalk_drip_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
void blocks_chalk_drip_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||||
|
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void blocks_chalk_drip_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
void blocks_chalk_drip_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
|
||||||
|
int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int blocks_chalk_drip_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
int blocks_chalk_drip_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
return(MODE_PAINT); /* FIXME - Blocks and Chalk, at least, can also be turned into a full-image effect */
|
return (MODE_PAINT); /* FIXME - Blocks and Chalk, at least, can also be turned into a full-image effect */
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue