Adding "indent.sh" to re-indent code; ran it!!!

This commit is contained in:
Bill Kendrick 2023-04-23 23:26:00 -07:00
parent 16336cc854
commit 18f9cad6fe
98 changed files with 5798 additions and 9001 deletions

View file

@ -106,6 +106,12 @@ https://tuxpaint.org/
* Don't try to load a blank-named template during slideshow playback.
Bill Kendrick <bill@newbreedsoftware.com>
* Ports & Building:
-----------------
* Created "src/indent.sh", to run 'indent' against source files.
Ran it during 0.9.30 development.
Bill Kendrick <bill@newbreedsoftware.com>
* Localization Updates:
---------------------
* Chinese (Simplified) translation

View file

@ -26,15 +26,11 @@
// #define DEBUG_ANGLE
Mix_Chunk *snd_effect = NULL;
SDL_Surface * rivulet_img_brush_add = NULL,
* rivulet_img_brush_alpha = NULL,
* rivulet_img_brush_sub = NULL,
* rivulet_img_angles = NULL;
SDL_Surface * rivulet_snapshot = NULL;
SDL_Surface *rivulet_img_brush_add = NULL,
*rivulet_img_brush_alpha = NULL, *rivulet_img_brush_sub = NULL, *rivulet_img_angles = NULL;
SDL_Surface *rivulet_snapshot = NULL;
int riv_x, riv_y;
Uint8 * riv_radii = NULL,
* riv_alpha = NULL,
* riv_angles = NULL;
Uint8 *riv_radii = NULL, *riv_alpha = NULL, *riv_angles = NULL;
Uint32 rivulet_api_version(void);
int rivulet_init(magic_api * api);
@ -47,22 +43,16 @@ int rivulet_requires_colors(magic_api * api, int which);
int rivulet_modes(magic_api * api, int which);
void rivulet_shutdown(magic_api * api);
void rivulet_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * snapshot, int x,
int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
void rivulet_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
void rivulet_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
void rivulet_line_callback_drag(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y);
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void rivulet_line_callback_drag(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
void rivulet_release(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect);
void rivulet_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void rivulet_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
void rivulet_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void rivulet_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
void zero_riv_arrays(SDL_Surface * canvas);
@ -82,8 +72,7 @@ int rivulet_init(magic_api * api)
/* Load our images */
snprintf(fname, sizeof(fname), "%simages/magic/rivulet-brush-add.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/rivulet-brush-add.png", api->data_directory);
rivulet_img_brush_add = IMG_Load(fname);
if (rivulet_img_brush_add == NULL)
{
@ -91,8 +80,7 @@ int rivulet_init(magic_api * api)
return 0;
}
snprintf(fname, sizeof(fname), "%simages/magic/rivulet-brush-alpha.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/rivulet-brush-alpha.png", api->data_directory);
rivulet_img_brush_alpha = IMG_Load(fname);
if (rivulet_img_brush_alpha == NULL)
{
@ -100,8 +88,7 @@ int rivulet_init(magic_api * api)
return 0;
}
snprintf(fname, sizeof(fname), "%simages/magic/rivulet-brush-sub.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/rivulet-brush-sub.png", api->data_directory);
rivulet_img_brush_sub = IMG_Load(fname);
if (rivulet_img_brush_sub == NULL)
{
@ -109,8 +96,7 @@ int rivulet_init(magic_api * api)
return 0;
}
snprintf(fname, sizeof(fname), "%simages/magic/rivulet-angles.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/rivulet-angles.png", api->data_directory);
rivulet_img_angles = IMG_Load(fname);
if (rivulet_img_angles == NULL)
{
@ -131,39 +117,32 @@ SDL_Surface *rivulet_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/rivulet.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/rivulet.png", api->data_directory);
return (IMG_Load(fname));
}
char *rivulet_get_name(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
char *rivulet_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return strdup(gettext("Rivulet"));
}
int rivulet_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int rivulet_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_DISTORTS;
}
char *rivulet_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED)
char *rivulet_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return(gettext("Click and drag downward to add water rivulets to your drawing"));
return (gettext("Click and drag downward to add water rivulets to your drawing"));
}
int rivulet_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int rivulet_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 0;
}
int rivulet_modes(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int rivulet_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MODE_PAINT;
}
@ -198,8 +177,7 @@ void rivulet_shutdown(magic_api * api ATTRIBUTE_UNUSED)
void
rivulet_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
{
riv_x = x;
riv_y = y - 1;
@ -208,10 +186,10 @@ rivulet_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
return;
if (snd_effect != NULL)
{
api->stopsound();
api->playsound(snd_effect, (x * 255) / canvas->w, 255);
}
{
api->stopsound();
api->playsound(snd_effect, (x * 255) / canvas->w, 255);
}
rivulet_drag(api, which, canvas, snapshot, x, y, x, y, update_rect);
}
@ -219,8 +197,8 @@ rivulet_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
void
rivulet_drag(magic_api * api ATTRIBUTE_UNUSED, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox ATTRIBUTE_UNUSED,
int oy ATTRIBUTE_UNUSED, int x, int y, SDL_Rect * update_rect)
SDL_Surface * snapshot, int ox ATTRIBUTE_UNUSED,
int oy ATTRIBUTE_UNUSED, int x, int y, SDL_Rect * update_rect)
{
int old_riv_x, old_riv_y;
@ -243,8 +221,7 @@ rivulet_drag(magic_api * api ATTRIBUTE_UNUSED, int which, SDL_Surface * canvas,
riv_x = x;
riv_y = y;
api->line((void *) api, which, canvas, snapshot, old_riv_x, old_riv_y, riv_x, riv_y, 1,
rivulet_line_callback_drag);
api->line((void *)api, which, canvas, snapshot, old_riv_x, old_riv_y, riv_x, riv_y, 1, rivulet_line_callback_drag);
/* FIXME */
update_rect->x = 0;
@ -254,11 +231,8 @@ rivulet_drag(magic_api * api ATTRIBUTE_UNUSED, int which, SDL_Surface * canvas,
}
void
rivulet_release(magic_api * api, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED,
int x, int y, /* ignored and reused in a for-loop */
SDL_Rect * update_rect)
void rivulet_release(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y, /* ignored and reused in a for-loop */
SDL_Rect * update_rect)
{
int src_x, src_y, idx;
double radius, angle_deg, angle_rad;
@ -294,12 +268,13 @@ rivulet_release(magic_api * api, int which ATTRIBUTE_UNUSED,
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, v, 64, 64));
#else
radius = ((double) riv_radii[idx]);
radius = ((double)riv_radii[idx]);
alpha = riv_alpha[idx] / 2;
if (radius != 0.0) {
if (radius != 0.0)
{
/* Angle is stored as 0-255 (so 256 would be 360 degrees) */
angle_deg = ((((double) riv_angles[idx]) / 256.0) * 360.0);
angle_deg = ((((double)riv_angles[idx]) / 256.0) * 360.0);
angle_rad = (angle_deg * M_PI) / 180.0;
@ -343,11 +318,9 @@ void rivulet_set_color(magic_api * api, int which, SDL_Surface * canvas,
void rivulet_line_callback_drag(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas,
SDL_Surface * snapshot ATTRIBUTE_UNUSED,
int x, int y)
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
{
magic_api * api;
magic_api *api;
SDL_Rect dest;
int w, h, half_w, half_h, idx;
int src_x, src_y, dest_x, dest_y;
@ -374,19 +347,23 @@ void rivulet_line_callback_drag(void *ptr, int which ATTRIBUTE_UNUSED,
/* Adjust the displacement maps */
for (src_y = 0; src_y <= h; src_y++) {
for (src_y = 0; src_y <= h; src_y++)
{
dest_y = (y - half_h) + src_y;
if (dest_y >= 0 && dest_y < canvas->h) {
for (src_x = 0; src_x < w; src_x++) {
if (dest_y >= 0 && dest_y < canvas->h)
{
for (src_x = 0; src_x < w; src_x++)
{
dest_x = (x - half_w) + src_x;
if (dest_x >= 0 && dest_x < canvas->w) {
if (dest_x >= 0 && dest_x < canvas->w)
{
idx = (dest_y * canvas->w) + dest_x;
/* Add alpha */
pix = api->getpixel(rivulet_img_brush_alpha, src_x, src_y);
SDL_GetRGB(pix, rivulet_img_brush_alpha->format, &intensity, &tmp, &tmp);
alpha = ((int) riv_alpha[idx] + (int) (intensity));
alpha = ((int)riv_alpha[idx] + (int)(intensity));
if (alpha > 255)
alpha = 255;
riv_alpha[idx] = (Uint8) alpha;
@ -394,17 +371,17 @@ void rivulet_line_callback_drag(void *ptr, int which ATTRIBUTE_UNUSED,
/* Apply radius brush to radius displacement map */
if (alpha > 0)
{
pix = api->getpixel(rivulet_img_brush_add, src_x, src_y);
SDL_GetRGB(pix, rivulet_img_brush_add->format, &intensity, &tmp, &tmp);
{
pix = api->getpixel(rivulet_img_brush_add, src_x, src_y);
SDL_GetRGB(pix, rivulet_img_brush_add->format, &intensity, &tmp, &tmp);
radius = ((int) riv_radii[idx] + (int) intensity - 128);
if (radius < 0)
radius = 0;
if (radius > 255)
radius = 255;
riv_radii[idx] = radius;
}
radius = ((int)riv_radii[idx] + (int)intensity - 128);
if (radius < 0)
radius = 0;
if (radius > 255)
radius = 255;
riv_radii[idx] = radius;
}
/* Apply angle brush to angle displacement map */
@ -419,58 +396,54 @@ void rivulet_line_callback_drag(void *ptr, int which ATTRIBUTE_UNUSED,
}
void rivulet_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas)
{
if (riv_radii == NULL)
{
riv_radii = (Uint8 *) malloc(sizeof(Uint8) * canvas->w * canvas->h);
if (riv_radii == NULL)
{
riv_radii = (Uint8 *) malloc(sizeof(Uint8) * canvas->w * canvas->h);
if (riv_radii == NULL)
{
fprintf(stderr, "rivulet: Cannot malloc() riv_radii!\n");
return;
}
riv_alpha = (Uint8 *) malloc(sizeof(Uint8) * canvas->w * canvas->h);
if (riv_alpha == NULL)
{
free(riv_radii);
riv_radii = NULL;
fprintf(stderr, "rivulet: Cannot malloc() riv_alpha!\n");
return;
}
riv_angles = (Uint8 *) malloc(sizeof(Uint8) * canvas->w * canvas->h);
if (riv_angles == NULL)
{
free(riv_radii);
riv_radii = NULL;
free(riv_alpha);
riv_alpha = NULL;
fprintf(stderr, "rivulet: Cannot malloc() riv_angles!\n");
return;
}
fprintf(stderr, "rivulet: Cannot malloc() riv_radii!\n");
return;
}
riv_alpha = (Uint8 *) malloc(sizeof(Uint8) * canvas->w * canvas->h);
if (riv_alpha == NULL)
{
free(riv_radii);
riv_radii = NULL;
fprintf(stderr, "rivulet: Cannot malloc() riv_alpha!\n");
return;
}
riv_angles = (Uint8 *) malloc(sizeof(Uint8) * canvas->w * canvas->h);
if (riv_angles == NULL)
{
free(riv_radii);
riv_radii = NULL;
free(riv_alpha);
riv_alpha = NULL;
fprintf(stderr, "rivulet: Cannot malloc() riv_angles!\n");
return;
}
}
zero_riv_arrays(canvas);
if (rivulet_snapshot == NULL)
rivulet_snapshot = SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h,
canvas->format->BitsPerPixel, canvas->format->Rmask,
canvas->format->Gmask, canvas->format->Bmask,
canvas->format->Amask);
canvas->format->BitsPerPixel, canvas->format->Rmask,
canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
if (rivulet_snapshot != NULL)
SDL_BlitSurface(canvas, NULL, rivulet_snapshot, NULL);
}
void rivulet_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
zero_riv_arrays(canvas);
}

View file

@ -72,8 +72,7 @@ const int alien_groups[alien_NUM_TOOLS] = {
};
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."),},
};
@ -86,12 +85,10 @@ char *alien_get_name(magic_api * api, int which);
int alien_get_group(magic_api * api, int which);
char *alien_get_description(magic_api * api, int which, int mode);
void alien_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
Mix_Chunk *magic_loadsound(char *file);
void alien_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void alien_release(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void alien_shutdown(magic_api * api);
@ -101,12 +98,9 @@ int alien_requires_colors(magic_api * api, int which);
Uint8 alien_accepted_sizes(magic_api * api, int which, int mode);
Uint8 alien_default_size(magic_api * api, int which, int mode);
void alien_set_size(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
Uint8 size, SDL_Rect * update_rect);
void alien_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void alien_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void alien_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void alien_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int alien_modes(magic_api * api, int which);
@ -125,8 +119,7 @@ int alien_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
for (i = 0; i < alien_NUM_TOOLS; i++)
{
snprintf(fname, sizeof(fname), "%ssounds/magic/%s", api->data_directory,
alien_snd_filenames[i]);
snprintf(fname, sizeof(fname), "%ssounds/magic/%s", api->data_directory, alien_snd_filenames[i]);
alien_snd_effect[i] = Mix_LoadWAV(fname);
}
return (1);
@ -142,8 +135,7 @@ SDL_Surface *alien_get_icon(magic_api * api, int which)
{
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));
}
@ -159,16 +151,14 @@ int alien_get_group(magic_api * api ATTRIBUTE_UNUSED, int which)
}
// 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])));
}
//Do the effect for one pixel
static void do_alien_pixel(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)
{
magic_api *api = (magic_api *) ptr;
@ -176,25 +166,21 @@ static void do_alien_pixel(void *ptr, int which ATTRIBUTE_UNUSED,
double temp2[3];
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++)
{
//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,
127.5 * (1.0 +
sin(((temp[k] / 127.5 -
1.0) * alien_FREQUENCY[k] +
alien_ANGLE[k] / 180.0) * M_PI)), 255.0);
1.0) * alien_FREQUENCY[k] + alien_ANGLE[k] / 180.0) * M_PI)), 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
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)
{
int x, y;
@ -208,8 +194,7 @@ static void do_alien_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last,
}
//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;
magic_api *api = (magic_api *) ptr;
@ -218,8 +203,7 @@ static void do_alien_brush(void *ptr, int which, SDL_Surface * canvas,
{
for (xx = x - alien_RADIUS; xx < x + alien_RADIUS; xx++)
{
if (api->in_circle(xx - x, yy - y, alien_RADIUS)
&& !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);
}
@ -229,12 +213,10 @@ static void do_alien_brush(void *ptr, int which, SDL_Surface * canvas,
// Affect the canvas on drag:
void alien_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * last, int ox, int oy, int x, int y, 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);
@ -275,8 +257,7 @@ Mix_Chunk *magic_loadsound(char *file)
// Affect the canvas on click:
void alien_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
if (mode == MODE_PAINT)
alien_drag(api, which, canvas, last, x, y, x, y, update_rect);
@ -296,8 +277,7 @@ void alien_release(magic_api * api ATTRIBUTE_UNUSED,
int which 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)
{
}
@ -317,14 +297,15 @@ void alien_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void alien_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void alien_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
// Use colors:
int alien_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int alien_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 0;
}
@ -340,20 +321,19 @@ Uint8 alien_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_U
}
void alien_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 size, SDL_Rect * update_rect ATTRIBUTE_UNUSED) {
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 size, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
alien_RADIUS = size * 4;
}
void alien_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas 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 which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}

View file

@ -65,24 +65,20 @@ int blind_get_group(magic_api * api, int which);
char *blind_get_description(magic_api * api, int which, int mode);
int blind_requires_colors(magic_api * api, int which);
void blind_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
void blind_shutdown(magic_api * api);
void blind_paint_blind(void *ptr_to_api, int which_tool, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y);
void blind_paint_blind(void *ptr_to_api, int which_tool, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
void blind_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void blind_click(magic_api * api, int which, int mode, SDL_Surface * canvas,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void blind_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void blind_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void blind_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void blind_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int blind_modes(magic_api * api, int which);
Uint8 blind_accepted_sizes(magic_api * api, int which, int mode);
Uint8 blind_default_size(magic_api * api, int which, int mode);
void blind_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void blind_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
// Housekeeping functions
@ -91,8 +87,9 @@ Uint32 blind_api_version(void)
return (TP_MAGIC_API_VERSION);
}
void blind_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void blind_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g,
Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
//get the colors from API and store it in structure
blind_r = r;
@ -104,8 +101,7 @@ int blind_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%ssounds/magic/blind.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/blind.ogg", api->data_directory);
blind_snd = Mix_LoadWAV(fname);
return (1);
@ -120,35 +116,29 @@ SDL_Surface *blind_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/blind.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/blind.png", api->data_directory);
return (IMG_Load(fname));
}
char *blind_get_name(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
char *blind_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return strdup(gettext_noop("Blind"));
}
int blind_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int blind_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_PICTURE_DECORATIONS;
}
char *blind_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED)
char *blind_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return
strdup(gettext_noop
("Click towards the edge of your picture to pull window blinds over it. Move perpendicularly to open or close the blinds."));
}
int blind_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int blind_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 1;
}
@ -157,8 +147,7 @@ void blind_release(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * snapshot 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)
{
}
@ -170,15 +159,13 @@ void blind_shutdown(magic_api * api ATTRIBUTE_UNUSED)
// Interactivity functions
void blind_paint_blind(void *ptr_to_api, int which_tool ATTRIBUTE_UNUSED,
SDL_Surface * canvas,
SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
{
magic_api *api = (magic_api *) ptr_to_api;
api->putpixel(canvas, x, y,
SDL_MapRGB(canvas->format, (blind_r + blind_light) / 2,
(blind_g + blind_light) / 2,
(blind_b + blind_light) / 2));
(blind_g + blind_light) / 2, (blind_b + blind_light) / 2));
}
/* void blind_do_blind(void * ptr_to_api, int which_tool,
@ -192,8 +179,7 @@ void blind_paint_blind(void *ptr_to_api, int which_tool ATTRIBUTE_UNUSED,
*/
void blind_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
int opaque;
@ -209,14 +195,12 @@ void blind_drag(magic_api * api, int which, SDL_Surface * canvas,
blind_light = 255;
for (j = i; j > i - opaque / 2; j--)
{
api->line(api, which, canvas, snapshot, 0, j, canvas->w, j, 1,
blind_paint_blind);
api->line(api, which, canvas, snapshot, 0, j, canvas->w, j, 1, blind_paint_blind);
blind_light -= 20;
}
for (j = i - opaque / 2; j > i - opaque; j--)
{
api->line(api, which, canvas, snapshot, 0, j, canvas->w, j, 1,
blind_paint_blind);
api->line(api, which, canvas, snapshot, 0, j, canvas->w, j, 1, blind_paint_blind);
blind_light += 20;
}
}
@ -234,14 +218,12 @@ void blind_drag(magic_api * api, int which, SDL_Surface * canvas,
blind_light = 255;
for (j = i; j < i + opaque / 2; j++)
{
api->line(api, which, canvas, snapshot, 0, j, canvas->w, j, 1,
blind_paint_blind);
api->line(api, which, canvas, snapshot, 0, j, canvas->w, j, 1, blind_paint_blind);
blind_light -= 20;
}
for (j = i + opaque / 2; j < i + opaque; j++)
{
api->line(api, which, canvas, snapshot, 0, j, canvas->w, j, 1,
blind_paint_blind);
api->line(api, which, canvas, snapshot, 0, j, canvas->w, j, 1, blind_paint_blind);
blind_light += 20;
}
}
@ -260,14 +242,12 @@ void blind_drag(magic_api * api, int which, SDL_Surface * canvas,
blind_light = 255;
for (j = i; j < i + opaque / 2; j++)
{
api->line(api, which, canvas, snapshot, j, 0, j, canvas->h, 1,
blind_paint_blind);
api->line(api, which, canvas, snapshot, j, 0, j, canvas->h, 1, blind_paint_blind);
blind_light -= 20;
}
for (j = i + opaque / 2; j < i + opaque; j++)
{
api->line(api, which, canvas, snapshot, j, 0, j, canvas->h, 1,
blind_paint_blind);
api->line(api, which, canvas, snapshot, j, 0, j, canvas->h, 1, blind_paint_blind);
blind_light += 20;
}
}
@ -286,14 +266,12 @@ void blind_drag(magic_api * api, int which, SDL_Surface * canvas,
blind_light = 255;
for (j = i; j > i - opaque / 2; j--)
{
api->line(api, which, canvas, snapshot, j, 0, j, canvas->h, 1,
blind_paint_blind);
api->line(api, which, canvas, snapshot, j, 0, j, canvas->h, 1, blind_paint_blind);
blind_light -= 20;
}
for (j = i - opaque / 2; j > i - opaque; j--)
{
api->line(api, which, canvas, snapshot, j, 0, j, canvas->h, 1,
blind_paint_blind);
api->line(api, which, canvas, snapshot, j, 0, j, canvas->h, 1, blind_paint_blind);
blind_light += 20;
}
}
@ -308,8 +286,7 @@ void blind_drag(magic_api * api, int which, SDL_Surface * canvas,
}
void blind_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
if (y < canvas->h / 2)
@ -335,15 +312,13 @@ void blind_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
}
void blind_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void blind_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
@ -363,6 +338,8 @@ Uint8 blind_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_U
return 0;
}
void blind_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void blind_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}

View file

@ -59,30 +59,24 @@ SDL_Surface *blocks_etc_get_icon(magic_api * api, int which);
char *blocks_etc_get_name(magic_api * api, int which);
int blocks_etc_get_group(magic_api * api, int which);
char *blocks_etc_get_description(magic_api * api, int which, int mode);
static void blocks_etc_linecb(void *ptr, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y);
static void blocks_etc_linecb(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
void blocks_etc_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void blocks_etc_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x,
int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void blocks_etc_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void blocks_etc_shutdown(magic_api * api);
void blocks_etc_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
int blocks_etc_requires_colors(magic_api * api, int which);
void blocks_etc_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void blocks_etc_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void blocks_etc_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void blocks_etc_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int blocks_etc_modes(magic_api * api, int which);
Uint8 blocks_etc_accepted_sizes(magic_api * api, int which, int mode);
Uint8 blocks_etc_default_size(magic_api * api, int which, int mode);
void blocks_etc_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void blocks_etc_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
@ -90,16 +84,13 @@ int blocks_etc_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%ssounds/magic/blocks.wav",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/blocks.wav", api->data_directory);
snd_effect[0] = Mix_LoadWAV(fname);
snprintf(fname, sizeof(fname), "%ssounds/magic/chalk.wav",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/chalk.wav", api->data_directory);
snd_effect[1] = Mix_LoadWAV(fname);
snprintf(fname, sizeof(fname), "%ssounds/magic/drip.wav",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/drip.wav", api->data_directory);
snd_effect[2] = Mix_LoadWAV(fname);
return (1);
@ -124,18 +115,15 @@ SDL_Surface *blocks_etc_get_icon(magic_api * api, int which)
if (which == TOOL_BLOCKS)
{
snprintf(fname, sizeof(fname), "%simages/magic/blocks.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/blocks.png", api->data_directory);
}
else if (which == TOOL_CHALK)
{
snprintf(fname, sizeof(fname), "%simages/magic/chalk.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/chalk.png", api->data_directory);
}
else if (which == TOOL_DRIP)
{
snprintf(fname, sizeof(fname), "%simages/magic/drip.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/drip.png", api->data_directory);
}
return (IMG_Load(fname));
@ -155,52 +143,41 @@ char *blocks_etc_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
}
// Return our group (all the same):
int blocks_etc_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int blocks_etc_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_DISTORTS;
}
// Return our descriptions, localized:
char *blocks_etc_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which, int mode)
char *blocks_etc_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode)
{
if (which == TOOL_BLOCKS)
{
if (mode == MODE_PAINT)
{
return (strdup
(gettext_noop
("Click and drag the mouse around to make the picture blocky.")));
return (strdup(gettext_noop("Click and drag the mouse around to make the picture blocky.")));
}
else
{
return (strdup
(gettext_noop("Click to make the entire picture blocky.")));
return (strdup(gettext_noop("Click to make the entire picture blocky.")));
}
}
else if (which == TOOL_CHALK)
{
if (mode == MODE_PAINT)
{
return (strdup
(gettext_noop
("Click and drag the mouse around to turn the picture into a chalk drawing.")));
return (strdup(gettext_noop("Click and drag the mouse around to turn the picture into a chalk drawing.")));
}
else
{
return (strdup
(gettext_noop
("Click to turn the entire picture into a chalk drawing.")));
return (strdup(gettext_noop("Click to turn the entire picture into a chalk drawing.")));
}
}
else if (which == TOOL_DRIP)
{
if (mode == MODE_PAINT)
{
return (strdup
(gettext_noop
("Click and drag the mouse around to make the picture drip.")));
return (strdup(gettext_noop("Click and drag the mouse around to make the picture drip.")));
}
else
{
@ -213,9 +190,7 @@ char *blocks_etc_get_description(magic_api * api ATTRIBUTE_UNUSED,
// Do the effect:
static void blocks_etc_linecb(void *ptr, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y)
static void blocks_etc_linecb(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
magic_api *api = (magic_api *) ptr;
int xx, yy;
@ -233,11 +208,9 @@ static void blocks_etc_linecb(void *ptr, int which,
if (!api->touched(x, y))
{
for (yy = y - (EFFECT_REZ * 2); yy < y + (EFFECT_REZ * 2);
yy = yy + EFFECT_REZ)
for (yy = y - (EFFECT_REZ * 2); yy < y + (EFFECT_REZ * 2); yy = yy + EFFECT_REZ)
{
for (xx = x - (EFFECT_REZ * 2); xx < x + (EFFECT_REZ * 2);
xx = xx + EFFECT_REZ)
for (xx = x - (EFFECT_REZ * 2); xx < x + (EFFECT_REZ * 2); xx = xx + EFFECT_REZ)
{
Uint32 pix[(EFFECT_REZ * EFFECT_REZ)];
Uint32 p_or = 0;
@ -271,12 +244,9 @@ static void blocks_etc_linecb(void *ptr, int which,
g_sum += api->sRGB_to_linear(g);
b_sum += api->sRGB_to_linear(b);
}
r =
api->linear_to_sRGB(r_sum / (float) (EFFECT_REZ * EFFECT_REZ));
g =
api->linear_to_sRGB(g_sum / (float) (EFFECT_REZ * EFFECT_REZ));
b =
api->linear_to_sRGB(b_sum / (float) (EFFECT_REZ * EFFECT_REZ));
r = api->linear_to_sRGB(r_sum / (float)(EFFECT_REZ * EFFECT_REZ));
g = api->linear_to_sRGB(g_sum / (float)(EFFECT_REZ * EFFECT_REZ));
b = api->linear_to_sRGB(b_sum / (float)(EFFECT_REZ * EFFECT_REZ));
}
/* Draw block: */
@ -293,20 +263,16 @@ static void blocks_etc_linecb(void *ptr, int which,
}
else if (which == TOOL_CHALK)
{
for (yy = y - (EFFECT_REZ * 2); yy <= y + (EFFECT_REZ * 2);
yy = yy + EFFECT_REZ)
for (yy = y - (EFFECT_REZ * 2); yy <= y + (EFFECT_REZ * 2); yy = yy + EFFECT_REZ)
{
for (xx = x - (EFFECT_REZ * 2); xx <= x + (EFFECT_REZ * 2);
xx = xx + EFFECT_REZ)
for (xx = x - (EFFECT_REZ * 2); xx <= x + (EFFECT_REZ * 2); xx = xx + EFFECT_REZ)
{
dest.x = xx + ((rand() % (EFFECT_REZ + 1)) - (EFFECT_REZ / 2));
dest.y = yy + ((rand() % (EFFECT_REZ + 1)) - (EFFECT_REZ / 2));
dest.w = (rand() % EFFECT_REZ) + (EFFECT_REZ / 2);
dest.h = (rand() % EFFECT_REZ) + (EFFECT_REZ / 2);
colr =
api->getpixel(last, clamp(0, xx, canvas->w - 1),
clamp(0, yy, canvas->h - 1));
colr = api->getpixel(last, clamp(0, xx, canvas->w - 1), clamp(0, yy, canvas->h - 1));
SDL_FillRect(canvas, &dest, colr);
}
}
@ -335,11 +301,9 @@ static void blocks_etc_linecb(void *ptr, int which,
// Affect the canvas on drag:
void blocks_etc_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1,
blocks_etc_linecb);
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, blocks_etc_linecb);
if (ox > x)
{
@ -366,8 +330,7 @@ void blocks_etc_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void blocks_etc_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x,
int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
if (mode == MODE_PAINT)
{
@ -393,6 +356,7 @@ void blocks_etc_click(magic_api * api, int which, int mode,
{
/* Drip (works from bottom-to-top) */
int p = (canvas->h - 1) % 10;
for (y = canvas->h - 1; y >= 0; y -= EFFECT_REZ)
{
if ((y + p) % 10 == 0)
@ -416,11 +380,10 @@ void blocks_etc_click(magic_api * api, int which, int mode,
// Affect the canvas on release:
void blocks_etc_release(magic_api * api ATTRIBUTE_UNUSED,
int which 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 which 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)
{
}
@ -435,29 +398,26 @@ void blocks_etc_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void blocks_etc_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void blocks_etc_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
// Use colors:
int blocks_etc_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int blocks_etc_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 0;
}
void blocks_etc_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void blocks_etc_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
@ -480,7 +440,9 @@ Uint8 blocks_etc_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIB
return 2;
}
void blocks_etc_set_size(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void blocks_etc_set_size(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
if (which == TOOL_BLOCKS)
EFFECT_REZ = size * 4;

View file

@ -37,8 +37,8 @@ float sample_weights[NUM_SAMPLE_WEIGHTS] = {
0.0449, 0.0627, 0.0752, 0.0842, 0.0904, 0.0940, 0.0952, 0.0940, 0.0904, 0.0842, 0.0752, 0.0627, 0.0449
};
Mix_Chunk * snd_effects = NULL;
Uint8 * bloom_mask = NULL;
Mix_Chunk *snd_effects = NULL;
Uint8 *bloom_mask = NULL;
int bloom_scale;
Uint32 bloom_api_version(void);
@ -52,30 +52,23 @@ int bloom_requires_colors(magic_api * api, int which);
int bloom_modes(magic_api * api, int which);
void bloom_shutdown(magic_api * api);
void bloom_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * snapshot, int x,
int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
void bloom_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
void bloom_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
void bloom_line_callback_drag(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y);
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void bloom_line_callback_drag(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
void bloom_release(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect);
void bloom_apply_effect(magic_api * api,
SDL_Surface * canvas,
SDL_Surface * snapshot);
void bloom_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void bloom_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
void bloom_apply_effect(magic_api * api, SDL_Surface * canvas, SDL_Surface * snapshot);
void bloom_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void bloom_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
float luminance(float r, float g, float b);
float change_luminance(float c_in, float l_in, float l_out);
Uint8 bloom_accepted_sizes(magic_api * api, int which, int mode);
Uint8 bloom_default_size(magic_api * api, int which, int mode);
void bloom_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void bloom_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
Uint32 bloom_api_version(void)
@ -87,8 +80,7 @@ int bloom_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%ssounds/magic/bloom.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/bloom.ogg", api->data_directory);
snd_effects = Mix_LoadWAV(fname);
bloom_scale = sqrt(2 * (BLOOM_PAINT_RADIUS * BLOOM_PAINT_RADIUS));
@ -105,54 +97,53 @@ SDL_Surface *bloom_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/bloom.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/bloom.png", api->data_directory);
return (IMG_Load(fname));
}
char *bloom_get_name(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
char *bloom_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return strdup(gettext("Bloom"));
}
int bloom_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED ATTRIBUTE_UNUSED)
int bloom_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_COLOR_FILTERS;
}
char *bloom_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode)
char *bloom_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode)
{
if (mode == MODE_PAINT) {
if (mode == MODE_PAINT)
{
return strdup(gettext("Click and drag to apply a glowing \"bloom\" effect to parts of your image."));
} else {
}
else
{
return strdup(gettext("Click to apply a glowing \"bloom\" effect to your entire image."));
}
}
int bloom_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int bloom_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 0; /* TODO: Maybe some day? */
return 0; /* TODO: Maybe some day? */
}
int bloom_modes(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED ATTRIBUTE_UNUSED)
int bloom_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED ATTRIBUTE_UNUSED)
{
return (MODE_PAINT | MODE_FULLSCREEN);
}
void bloom_shutdown(magic_api * api ATTRIBUTE_UNUSED)
{
if (snd_effects != NULL) {
if (snd_effects != NULL)
{
Mix_FreeChunk(snd_effects);
snd_effects = NULL;
}
if (bloom_mask != NULL) {
if (bloom_mask != NULL)
{
free(bloom_mask);
bloom_mask = NULL;
}
@ -160,8 +151,7 @@ void bloom_shutdown(magic_api * api ATTRIBUTE_UNUSED)
void
bloom_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
{
if (bloom_mask == NULL)
return;
@ -169,11 +159,15 @@ bloom_click(magic_api * api, int which, int mode,
if (snd_effects != NULL)
api->stopsound();
if (mode == MODE_PAINT) {
if (mode == MODE_PAINT)
{
memset(bloom_mask, 0, (canvas->w * canvas->h));
bloom_drag(api, which, canvas, snapshot, x, y, x, y, update_rect);
} else {
if (snd_effects != NULL) {
}
else
{
if (snd_effects != NULL)
{
api->playsound(snd_effects, (x * 255) / canvas->w, 255);
}
@ -190,12 +184,12 @@ bloom_click(magic_api * api, int which, int mode,
void
bloom_drag(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect)
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
if (bloom_mask == NULL)
return;
api->line((void *) api, which, canvas, snapshot, ox, oy, x, y, 1 /* FIXME: Consider fewer iterations? */,
api->line((void *)api, which, canvas, snapshot, ox, oy, x, y, 1 /* FIXME: Consider fewer iterations? */ ,
bloom_line_callback_drag);
/* FIXME: Would be good to only update the area around the line (ox,oy)->(x,y) (+/- the maxium radius of the effect) */
@ -207,10 +201,9 @@ bloom_drag(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Sur
void bloom_release(magic_api * api, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas,
SDL_Surface * snapshot,
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED,
SDL_Rect * update_rect) {
SDL_Surface * canvas,
SDL_Surface * snapshot, int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect)
{
if (bloom_mask == NULL)
return;
@ -225,9 +218,8 @@ void bloom_release(magic_api * api, int which ATTRIBUTE_UNUSED,
update_rect->h = canvas->h;
}
void bloom_apply_effect(magic_api * api,
SDL_Surface * canvas,
SDL_Surface * snapshot) {
void bloom_apply_effect(magic_api * api, SDL_Surface * canvas, SDL_Surface * snapshot)
{
int sample, offset, offset_flip, x, y, xx, yy;
Uint8 r, g, b;
float rf, gf, bf, mask_weight, lum;
@ -236,19 +228,24 @@ void bloom_apply_effect(magic_api * api,
SDL_BlitSurface(snapshot, NULL, canvas, NULL);
for (y = 0; y < canvas->h; y++) {
if (y % 10 == 0) {
for (y = 0; y < canvas->h; y++)
{
if (y % 10 == 0)
{
api->update_progress_bar();
}
for (x = 0; x < canvas->w; x++) {
if (bloom_mask[y * canvas->w + x] > 0) {
for (x = 0; x < canvas->w; x++)
{
if (bloom_mask[y * canvas->w + x] > 0)
{
sums[0] = 0.0;
sums[1] = 0.0;
sums[2] = 0.0;
/* (Pull from snapshot) */
for (sample = 0; sample < NUM_SAMPLE_WEIGHTS; sample++) {
for (sample = 0; sample < NUM_SAMPLE_WEIGHTS; sample++)
{
/* Horizontal samples */
color = api->getpixel(snapshot, x - ((NUM_SAMPLE_WEIGHTS - 1) / 2) + sample, y);
SDL_GetRGB(color, snapshot->format, &r, &g, &b);
@ -265,29 +262,34 @@ void bloom_apply_effect(magic_api * api,
}
/* (Blend an "X" shape, additively, onto target canvas) */
for (offset = -BLOOM_SPIKE_LENGTH; offset <= BLOOM_SPIKE_LENGTH; offset++) {
for (offset_flip = -1; offset <= 1; offset += 2) {
for (offset = -BLOOM_SPIKE_LENGTH; offset <= BLOOM_SPIKE_LENGTH; offset++)
{
for (offset_flip = -1; offset <= 1; offset += 2)
{
xx = x + offset;
yy = y + (offset * offset_flip);
if (xx >= 0 && xx < canvas->w && yy >= 0 && yy < canvas->h) {
if (xx >= 0 && xx < canvas->w && yy >= 0 && yy < canvas->h)
{
color = api->getpixel(snapshot, xx, yy);
SDL_GetRGB(color, snapshot->format, &r, &g, &b);
mask_weight = (float) (bloom_mask[(yy) * canvas->w + xx] / 255.0);
mask_weight = (float)(bloom_mask[(yy) * canvas->w + xx] / 255.0);
mask_weight *= BLOOM_WEIGHT_CONST;
mask_weight *= ((BLOOM_SPIKE_LENGTH + 1) - (abs(offset)) / BLOOM_SPIKE_LENGTH);
rf = (((float) r) + (sums[0] * mask_weight)) / 255.0;
gf = (((float) g) + (sums[1] * mask_weight)) / 255.0;
bf = (((float) b) + (sums[2] * mask_weight)) / 255.0;
rf = (((float)r) + (sums[0] * mask_weight)) / 255.0;
gf = (((float)g) + (sums[1] * mask_weight)) / 255.0;
bf = (((float)b) + (sums[2] * mask_weight)) / 255.0;
/* Reinhard Tonemap (Luminence) */
lum = luminance(rf, gf, bf);
if (lum > 0.0) {
if (lum > 0.0)
{
float numerator = lum * (1.0f + lum);
float l_new = numerator / (1.0f + lum);
rf = change_luminance(rf, lum, l_new);
gf = change_luminance(gf, lum, l_new);
bf = change_luminance(bf, lum, l_new);
@ -316,19 +318,17 @@ void bloom_apply_effect(magic_api * api,
void bloom_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
/* TODO: Maybe some day? */
}
void bloom_line_callback_drag(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas,
SDL_Surface * snapshot ATTRIBUTE_UNUSED,
int x, int y)
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
{
int xrad, yrad, xx, yy, chg, n;
magic_api *api = (magic_api *) ptr;
@ -336,18 +336,24 @@ void bloom_line_callback_drag(void *ptr, int which ATTRIBUTE_UNUSED,
if (snd_effects != NULL)
api->playsound(snd_effects, (x * 255) / canvas->w, 255);
for (yrad = -BLOOM_PAINT_RADIUS; yrad < BLOOM_PAINT_RADIUS; yrad++) {
for (yrad = -BLOOM_PAINT_RADIUS; yrad < BLOOM_PAINT_RADIUS; yrad++)
{
yy = y + yrad;
if (yy >= 0 && yy < canvas->h) {
for (xrad = -BLOOM_PAINT_RADIUS; xrad < BLOOM_PAINT_RADIUS; xrad++) {
if (yy >= 0 && yy < canvas->h)
{
for (xrad = -BLOOM_PAINT_RADIUS; xrad < BLOOM_PAINT_RADIUS; xrad++)
{
xx = x + xrad;
if (xx >= 0 && xx < canvas->w) {
if (api->in_circle(xrad, yrad, BLOOM_PAINT_RADIUS)) {
if (xx >= 0 && xx < canvas->w)
{
if (api->in_circle(xrad, yrad, BLOOM_PAINT_RADIUS))
{
/* Add to the bloom mask */
n = (int) bloom_mask[yy * canvas->w + xx];
n = (int)bloom_mask[yy * canvas->w + xx];
chg = sqrt(bloom_scale - sqrt((xrad * xrad) + (yrad * yrad)));
n += chg;
if (n > 255) {
if (n > 255)
{
n = 255;
}
bloom_mask[yy * canvas->w + xx] = (Uint8) n;
@ -363,29 +369,29 @@ void bloom_line_callback_drag(void *ptr, int which ATTRIBUTE_UNUSED,
void bloom_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED ATTRIBUTE_UNUSED, int mode,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED ATTRIBUTE_UNUSED, int mode, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
if (bloom_mask == NULL)
bloom_mask = (Uint8 *) malloc(sizeof(Uint8) * canvas-> w * canvas->h);
bloom_mask = (Uint8 *) malloc(sizeof(Uint8) * canvas->w * canvas->h);
if (mode == MODE_FULLSCREEN)
bloom_set_size(api, which, mode, NULL, NULL, bloom_default_size(api, which, mode), NULL);
}
void bloom_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
float luminance(float r, float g, float b) {
float luminance(float r, float g, float b)
{
return (r * 0.2126) + (g * 0.7152) + (b * 0.0722);
}
float change_luminance(float c_in, float l_in, float l_out) {
return c_in * (l_out / l_in);
float change_luminance(float c_in, float l_in, float l_out)
{
return c_in * (l_out / l_in);
}
@ -402,7 +408,9 @@ Uint8 bloom_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_U
return 2;
}
void bloom_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void bloom_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
BLOOM_PAINT_RADIUS = size * 12;
BLOOM_SPIKE_LENGTH = sqrt(BLOOM_PAINT_RADIUS + 1);

View file

@ -46,8 +46,7 @@ char *blur_get_name(magic_api * api, int which);
int blur_get_group(magic_api * api, int which);
char *blur_get_description(magic_api * api, int which, int mode);
void blur_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void blur_click(magic_api * api, int which, int mode, SDL_Surface * canvas,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void blur_release(magic_api * api, int which, SDL_Surface * canvas,
@ -60,10 +59,8 @@ void blur_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas,
int blur_requires_colors(magic_api * api, int which);
Uint8 blur_accepted_sizes(magic_api * api, int which, int mode);
Uint8 blur_default_size(magic_api * api, int which, int mode);
void blur_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void blur_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void blur_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void blur_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int blur_modes(magic_api * api, int which);
enum
@ -110,8 +107,7 @@ int blur_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
for (i = 0; i < blur_NUM_TOOLS; i++)
{
snprintf(fname, sizeof(fname), "%ssounds/magic/%s", api->data_directory,
blur_snd_filenames[i]);
snprintf(fname, sizeof(fname), "%ssounds/magic/%s", api->data_directory, blur_snd_filenames[i]);
blur_snd_effect[i] = Mix_LoadWAV(fname);
}
return (1);
@ -127,8 +123,7 @@ SDL_Surface *blur_get_icon(magic_api * api, int which)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory,
blur_icon_filenames[which]);
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, blur_icon_filenames[which]);
return (IMG_Load(fname));
}
@ -145,16 +140,13 @@ int blur_get_group(magic_api * api ATTRIBUTE_UNUSED, int which)
}
// Return our descriptions, localized:
char *blur_get_description(magic_api * api ATTRIBUTE_UNUSED, int which,
int mode)
char *blur_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode)
{
return (strdup(gettext_noop(blur_descs[which][mode - 1])));
}
//Do the effect for one pixel
static void do_blur_pixel(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, int x,
int y)
static void do_blur_pixel(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
magic_api *api = (magic_api *) ptr;
int i, j, k;
@ -179,8 +171,7 @@ static void do_blur_pixel(void *ptr, int which ATTRIBUTE_UNUSED,
for (j = -2; j < 3; j++)
{
//Add the pixels around the current one wieghted
SDL_GetRGB(api->getpixel(last, x + i, y + j), last->format, &temp[0],
&temp[1], &temp[2]);
SDL_GetRGB(api->getpixel(last, x + i, y + j), last->format, &temp[0], &temp[1], &temp[2]);
for (k = 0; k < 3; k++)
{
blurValue[k] += temp[k] * weight[i + 2][j + 2];
@ -191,14 +182,11 @@ static void do_blur_pixel(void *ptr, int which ATTRIBUTE_UNUSED,
{
blurValue[k] /= 273;
}
api->putpixel(canvas, x, y,
SDL_MapRGB(canvas->format, blurValue[0], blurValue[1],
blurValue[2]));
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, blurValue[0], blurValue[1], blurValue[2]));
}
// Do the effect for the full image
static void do_blur_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last,
int which)
static void do_blur_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int which)
{
magic_api *api = (magic_api *) ptr;
int x, y;
@ -218,8 +206,7 @@ static void do_blur_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last,
}
//do the effect for the brush
static void do_blur_brush(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y)
static void do_blur_brush(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
int xx, yy;
magic_api *api = (magic_api *) ptr;
@ -228,8 +215,7 @@ static void do_blur_brush(void *ptr, int which, SDL_Surface * canvas,
{
for (xx = x - blur_RADIUS; xx < x + blur_RADIUS; xx++)
{
if (api->in_circle(xx - x, yy - y, blur_RADIUS)
&& !api->touched(xx, yy))
if (api->in_circle(xx - x, yy - y, blur_RADIUS) && !api->touched(xx, yy))
{
do_blur_pixel(api, which, canvas, last, xx, yy);
}
@ -239,12 +225,10 @@ static void do_blur_brush(void *ptr, int which, SDL_Surface * canvas,
// Affect the canvas on drag:
void blur_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1,
do_blur_brush);
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_blur_brush);
api->playsound(blur_snd_effect[which], (x * 255) / canvas->w, 255);
@ -271,8 +255,7 @@ void blur_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void blur_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
if (mode == MODE_PAINT)
blur_drag(api, which, canvas, last, x, y, x, y, update_rect);
@ -292,8 +275,7 @@ void blur_release(magic_api * api ATTRIBUTE_UNUSED,
int which 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 y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
@ -314,45 +296,46 @@ void blur_shutdown(magic_api * api ATTRIBUTE_UNUSED)
// Record the color from Tux Paint:
void blur_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
// Record the size from Tux Paint:
void blur_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 sz, SDL_Rect * update_rect ATTRIBUTE_UNUSED) {
Uint8 sz, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
blur_RADIUS = sz * 4;
}
// Use colors:
int blur_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int blur_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 0;
}
Uint8 blur_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode) {
Uint8 blur_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode)
{
if (mode == MODE_PAINT)
return 8;
else
return 0;
}
Uint8 blur_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED) {
Uint8 blur_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return 4;
}
void blur_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void blur_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}

View file

@ -55,8 +55,7 @@ static int brick_size = TOOL_LARGEBRICKS;
/* Local function prototype: */
static void do_brick(magic_api * api, SDL_Surface * canvas, int x, int y,
int w, int h);
static void do_brick(magic_api * api, SDL_Surface * canvas, int x, int y, int w, int h);
int bricks_init(magic_api * api, Uint32 disabled_features);
Uint32 bricks_api_version(void);
int bricks_get_tool_count(magic_api * api);
@ -65,8 +64,7 @@ char *bricks_get_name(magic_api * api, int which);
int bricks_get_group(magic_api * api, int which);
char *bricks_get_description(magic_api * api, int which, int mode);
void bricks_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void bricks_click(magic_api * api, int which, int mode, SDL_Surface * canvas,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void bricks_release(magic_api * api, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect); //An empty function. Is there a purpose to this? Ask moderator.
@ -74,22 +72,20 @@ void bricks_shutdown(magic_api * api);
void bricks_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
int bricks_requires_colors(magic_api * api, int which);
void bricks_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void bricks_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void bricks_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void bricks_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int bricks_modes(magic_api * api, int which);
Uint8 bricks_accepted_sizes(magic_api * api, int which, int mode);
Uint8 bricks_default_size(magic_api * api, int which, int mode);
void bricks_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void bricks_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
// No setup required:
int bricks_init(magic_api * api, Uint32 disabled_features)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%ssounds/magic/brick.wav",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/brick.wav", api->data_directory);
brick_snd = Mix_LoadWAV(fname);
if (disabled_features & MAGIC_FEATURE_SIZE)
@ -121,21 +117,18 @@ SDL_Surface *bricks_get_icon(magic_api * api, int which)
if (which == TOOL_LARGEBRICKS)
{
snprintf(fname, sizeof(fname), "%simages/magic/largebrick.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/largebrick.png", api->data_directory);
}
else if (which == TOOL_SMALLBRICKS)
{
snprintf(fname, sizeof(fname), "%simages/magic/smallbrick.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/smallbrick.png", api->data_directory);
}
return (IMG_Load(fname));
}
// Return our names, localized:
char *bricks_get_name(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
char *bricks_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
/* Both are named "Bricks", at the moment: */
@ -143,22 +136,23 @@ char *bricks_get_name(magic_api * api ATTRIBUTE_UNUSED,
}
// Return our group (both the same):
int bricks_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int bricks_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_PAINTING;
}
// Return our descriptions, localized:
char *bricks_get_description(magic_api * api ATTRIBUTE_UNUSED, int which,
int mode ATTRIBUTE_UNUSED)
char *bricks_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
{
if (brick_two_tools) {
if (brick_two_tools)
{
if (which == TOOL_LARGEBRICKS)
return (strdup(gettext_noop("Click and drag to draw large bricks.")));
else if (which == TOOL_SMALLBRICKS)
return (strdup(gettext_noop("Click and drag to draw small bricks.")));
} else {
}
else
{
return (strdup(gettext_noop("Click and drag to draw bricks.")));
}
@ -167,8 +161,7 @@ char *bricks_get_description(magic_api * api ATTRIBUTE_UNUSED, int which,
// Do the effect:
static void do_bricks(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
static void do_bricks(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
{
magic_api *api = (magic_api *) ptr;
@ -215,8 +208,7 @@ static void do_bricks(void *ptr, int which, SDL_Surface * canvas,
mybrick = map + brick_x + 1 + (brick_y + 1) * x_count;
if ((unsigned) x < (unsigned) canvas->w
&& (unsigned) y < (unsigned) canvas->h && !*mybrick)
if ((unsigned)x < (unsigned)canvas->w && (unsigned)y < (unsigned)canvas->h && !*mybrick)
{
int my_x = brick_x * nominal_width;
int my_w = specified_width;
@ -237,8 +229,7 @@ static void do_bricks(void *ptr, int which, SDL_Surface * canvas,
my_x -= nominal_width;
my_w = specified_length;
}
do_brick(api, canvas, my_x, brick_y * nominal_height, my_w,
specified_height);
do_brick(api, canvas, my_x, brick_y * nominal_height, my_w, specified_height);
// FIXME:
@ -258,10 +249,9 @@ static void do_bricks(void *ptr, int which, SDL_Surface * canvas,
// Affect the canvas on drag:
void bricks_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_bricks);
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_bricks);
if (ox > x)
{
@ -290,8 +280,7 @@ void bricks_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void bricks_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
bricks_drag(api, which, canvas, last, x, y, x, y, update_rect);
}
@ -300,8 +289,7 @@ void bricks_release(magic_api * api ATTRIBUTE_UNUSED,
int which 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)
{
}
@ -313,8 +301,9 @@ void bricks_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void bricks_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void bricks_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g,
Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
bricks_r = r;
bricks_g = g;
@ -322,29 +311,21 @@ void bricks_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUS
}
// Use colors:
int bricks_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int bricks_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 1;
}
static void do_brick(magic_api * api, SDL_Surface * canvas, int x, int y,
int w, int h)
static void do_brick(magic_api * api, SDL_Surface * canvas, int x, int y, int w, int h)
{
SDL_Rect dest;
// brick color: 127,76,73
double ran_r = rand() / (double) RAND_MAX;
double ran_g = rand() / (double) RAND_MAX;
double base_r =
api->sRGB_to_linear(bricks_r) * 1.5 + api->sRGB_to_linear(127) * 5.0 +
ran_r;
double base_g =
api->sRGB_to_linear(bricks_g) * 1.5 + api->sRGB_to_linear(76) * 5.0 +
ran_g;
double base_b =
api->sRGB_to_linear(bricks_b) * 1.5 + api->sRGB_to_linear(73) * 5.0 +
(ran_r + ran_g * 2.0) / 3.0;
double ran_r = rand() / (double)RAND_MAX;
double ran_g = rand() / (double)RAND_MAX;
double base_r = api->sRGB_to_linear(bricks_r) * 1.5 + api->sRGB_to_linear(127) * 5.0 + ran_r;
double base_g = api->sRGB_to_linear(bricks_g) * 1.5 + api->sRGB_to_linear(76) * 5.0 + ran_g;
double base_b = api->sRGB_to_linear(bricks_b) * 1.5 + api->sRGB_to_linear(73) * 5.0 + (ran_r + ran_g * 2.0) / 3.0;
Uint8 r = api->linear_to_sRGB(base_r / 7.5);
Uint8 g = api->linear_to_sRGB(base_g / 7.5);
@ -365,14 +346,12 @@ static void do_brick(magic_api * api, SDL_Surface * canvas, int x, int y,
}
void bricks_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void bricks_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
@ -392,10 +371,16 @@ Uint8 bricks_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_
return 2;
}
void bricks_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size, SDL_Rect * update_rect ATTRIBUTE_UNUSED) {
if (size == 1) {
void bricks_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
if (size == 1)
{
brick_size = TOOL_SMALLBRICKS;
} else { // 2
}
else
{ // 2
brick_size = TOOL_LARGEBRICKS;
}
}

View file

@ -49,8 +49,7 @@ static SDL_Surface *calligraphy_brush, *calligraphy_colored_brush;
/* Local Function Prototypes */
static Point2D calligraphy_PointOnCubicBezier(Point2D * cp, float t);
static void calligraphy_ComputeBezier(Point2D * cp, int numberOfPoints,
Point2D * curve);
static void calligraphy_ComputeBezier(Point2D * cp, int numberOfPoints, Point2D * curve);
static float calligraphy_dist(float x1, float y1, float x2, float y2);
int calligraphy_init(magic_api * api, Uint32 disabled_features);
Uint32 calligraphy_api_version(void);
@ -60,26 +59,22 @@ char *calligraphy_get_name(magic_api * api, int which);
int calligraphy_get_group(magic_api * api, int which);
char *calligraphy_get_description(magic_api * api, int which, int mode);
void calligraphy_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void calligraphy_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void calligraphy_release(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void calligraphy_shutdown(magic_api * api);
void calligraphy_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
int calligraphy_requires_colors(magic_api * api, int which);
void calligraphy_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void calligraphy_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void calligraphy_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void calligraphy_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int calligraphy_modes(magic_api * api, int which);
Uint8 calligraphy_accepted_sizes(magic_api * api, int which, int mode);
Uint8 calligraphy_default_size(magic_api * api, int which, int mode);
void calligraphy_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void calligraphy_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
@ -87,13 +82,11 @@ int calligraphy_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%ssounds/magic/calligraphy.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/calligraphy.ogg", api->data_directory);
calligraphy_snd = Mix_LoadWAV(fname);
snprintf(fname, sizeof(fname), "%simages/magic/calligraphy_brush.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/calligraphy_brush.png", api->data_directory);
calligraphy_brush = IMG_Load(fname);
calligraphy_colored_brush = NULL;
@ -127,40 +120,33 @@ SDL_Surface *calligraphy_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/calligraphy.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/calligraphy.png", api->data_directory);
return (IMG_Load(fname));
}
// Return our name, localized:
char *calligraphy_get_name(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
char *calligraphy_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (strdup(gettext_noop("Calligraphy")));
}
// Return our group
int calligraphy_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int calligraphy_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_PAINTING;
}
// Return our description, localized:
char *calligraphy_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return (strdup
(gettext_noop
("Click and drag the mouse around to draw in calligraphy.")));
return (strdup(gettext_noop("Click and drag the mouse around to draw in calligraphy.")));
}
void calligraphy_drag(magic_api * api, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas,
SDL_Surface * last ATTRIBUTE_UNUSED, int ox, int oy,
int x, int y, SDL_Rect * update_rect)
SDL_Surface * last ATTRIBUTE_UNUSED, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
Point2D *curve;
int i, n_points, thick, new_thick;
@ -200,9 +186,7 @@ void calligraphy_drag(magic_api * api, int which ATTRIBUTE_UNUSED,
calligraphy_control_points[2].x,
calligraphy_control_points[2].y) +
calligraphy_dist(calligraphy_control_points[2].x,
calligraphy_control_points[2].y,
calligraphy_control_points[3].x,
calligraphy_control_points[3].y);
calligraphy_control_points[2].y, calligraphy_control_points[3].x, calligraphy_control_points[3].y);
if (n_points == 0)
return; // No-op; not any points to plot
@ -216,8 +200,7 @@ void calligraphy_drag(magic_api * api, int which ATTRIBUTE_UNUSED,
for (i = 0; i < n_points - 1; i++)
{
thick =
((new_thick * i) + (calligraphy_old_thick * (n_points - i))) / n_points;
thick = ((new_thick * i) + (calligraphy_old_thick * (n_points - i))) / n_points;
/* The new way, using an antialiased brush bitmap */
@ -286,8 +269,7 @@ void calligraphy_drag(magic_api * api, int which ATTRIBUTE_UNUSED,
void calligraphy_click(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
calligraphy_old_thick = 8;
calligraphy_last_time = 0;
@ -307,8 +289,7 @@ void calligraphy_release(magic_api * api ATTRIBUTE_UNUSED,
int which 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)
{
}
@ -325,7 +306,8 @@ void calligraphy_shutdown(magic_api * api ATTRIBUTE_UNUSED)
// We don't use colors
void calligraphy_set_color(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
int x, y;
Uint8 a;
@ -341,9 +323,7 @@ void calligraphy_set_color(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surf
if (calligraphy_colored_brush != NULL)
SDL_FreeSurface(calligraphy_colored_brush);
amask =
~(calligraphy_brush->format->Rmask | calligraphy_brush->format->
Gmask | calligraphy_brush->format->Bmask);
amask = ~(calligraphy_brush->format->Rmask | calligraphy_brush->format->Gmask | calligraphy_brush->format->Bmask);
calligraphy_colored_brush =
SDL_CreateRGBSurface(SDL_SWSURFACE,
@ -351,8 +331,7 @@ void calligraphy_set_color(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surf
calligraphy_brush->h,
calligraphy_brush->format->BitsPerPixel,
calligraphy_brush->format->Rmask,
calligraphy_brush->format->Gmask,
calligraphy_brush->format->Bmask, amask);
calligraphy_brush->format->Gmask, calligraphy_brush->format->Bmask, amask);
if (calligraphy_colored_brush == NULL)
return; // FIXME: Error!
@ -365,13 +344,10 @@ void calligraphy_set_color(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surf
{
for (x = 0; x < calligraphy_brush->w; x++)
{
SDL_GetRGBA(api->getpixel(calligraphy_brush, x, y),
calligraphy_brush->format, &r, &g, &b, &a);
SDL_GetRGBA(api->getpixel(calligraphy_brush, x, y), calligraphy_brush->format, &r, &g, &b, &a);
api->putpixel(calligraphy_colored_brush, x, y,
SDL_MapRGBA(calligraphy_colored_brush->format,
calligraphy_r, calligraphy_g, calligraphy_b,
a));
SDL_MapRGBA(calligraphy_colored_brush->format, calligraphy_r, calligraphy_g, calligraphy_b, a));
}
}
@ -380,8 +356,7 @@ void calligraphy_set_color(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surf
}
// We don't use colors
int calligraphy_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int calligraphy_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 1;
}
@ -436,8 +411,7 @@ static Point2D calligraphy_PointOnCubicBezier(Point2D * cp, float t)
<sizeof(Point2D) numberOfPoints>
*/
static void calligraphy_ComputeBezier(Point2D * cp, int numberOfPoints,
Point2D * curve)
static void calligraphy_ComputeBezier(Point2D * cp, int numberOfPoints, Point2D * curve)
{
float dt;
int i;
@ -458,27 +432,23 @@ static float calligraphy_dist(float x1, float y1, float x2, float y2)
}
void calligraphy_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void calligraphy_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int calligraphy_modes(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int calligraphy_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (MODE_PAINT);
}
Uint8 calligraphy_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
Uint8 calligraphy_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED)
{
return 0;
}
@ -488,6 +458,8 @@ Uint8 calligraphy_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRI
return 0;
}
void calligraphy_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void calligraphy_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}

View file

@ -51,31 +51,26 @@ SDL_Surface *cartoon_get_icon(magic_api * api, int which);
char *cartoon_get_name(magic_api * api, int which);
int cartoon_get_group(magic_api * api, int which);
char *cartoon_get_description(magic_api * api, int which, int mode);
void cartoon_apply_colors(magic_api * api, SDL_Surface * surf, int xx,
int yy);
void cartoon_apply_colors(magic_api * api, SDL_Surface * surf, int xx, int yy);
void cartoon_apply_outline(magic_api * api, int xx, int yy);
static void do_cartoon(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y);
static void do_cartoon(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
void cartoon_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void cartoon_click(magic_api * api, int which, int mode, SDL_Surface * canvas,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void cartoon_release(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void cartoon_shutdown(magic_api * api);
void cartoon_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
int cartoon_requires_colors(magic_api * api, int which);
void cartoon_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void cartoon_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void cartoon_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void cartoon_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int cartoon_modes(magic_api * api, int which);
Uint8 cartoon_accepted_sizes(magic_api * api, int which, int mode);
Uint8 cartoon_default_size(magic_api * api, int which, int mode);
void cartoon_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void cartoon_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
// No setup required:
@ -83,8 +78,7 @@ int cartoon_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%ssounds/magic/cartoon.wav",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/cartoon.wav", api->data_directory);
cartoon_snd = Mix_LoadWAV(fname);
return (1);
@ -106,41 +100,33 @@ SDL_Surface *cartoon_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/cartoon.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/cartoon.png", api->data_directory);
return (IMG_Load(fname));
}
// Return our names, localized:
char *cartoon_get_name(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
char *cartoon_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (strdup(gettext_noop("Cartoon")));
}
// Return our groups
int cartoon_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int cartoon_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_COLOR_FILTERS;
}
// Return our descriptions, localized:
char *cartoon_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode)
char *cartoon_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode)
{
if (mode == MODE_PAINT)
{
return (strdup
(gettext_noop
("Click and drag the mouse around to turn the picture into a cartoon.")));
return (strdup(gettext_noop("Click and drag the mouse around to turn the picture into a cartoon.")));
}
else
{
return (strdup
(gettext_noop
("Click to turn the entire picture into a cartoon.")));
return (strdup(gettext_noop("Click to turn the entire picture into a cartoon.")));
}
}
@ -168,8 +154,7 @@ void cartoon_apply_colors(magic_api * api, SDL_Surface * surf, int xx, int yy)
sat = floor(sat * 4) / 4;
api->hsvtorgb(hue, sat, val, &r, &g, &b);
api->putpixel(result_surf, xx, yy,
SDL_MapRGB(result_surf->format, r, g, b));
api->putpixel(result_surf, xx, yy, SDL_MapRGB(result_surf->format, r, g, b));
}
@ -178,34 +163,26 @@ void cartoon_apply_outline(magic_api * api, int xx, int yy)
Uint8 r, g, b;
Uint8 r1, g1, b1, r2, g2, b2;
SDL_GetRGB(api->getpixel(result_surf, xx, yy), result_surf->format, &r, &g,
&b);
SDL_GetRGB(api->getpixel(result_surf, xx + 1, yy), result_surf->format, &r1,
&g1, &b1);
SDL_GetRGB(api->getpixel(result_surf, xx + 1, yy + 1), result_surf->format,
&r2, &g2, &b2);
SDL_GetRGB(api->getpixel(result_surf, xx, yy), result_surf->format, &r, &g, &b);
SDL_GetRGB(api->getpixel(result_surf, xx + 1, yy), result_surf->format, &r1, &g1, &b1);
SDL_GetRGB(api->getpixel(result_surf, xx + 1, yy + 1), result_surf->format, &r2, &g2, &b2);
if (abs(((r + g + b) / 3) - (r1 + g1 + b1) / 3) > OUTLINE_THRESH
|| abs(((r + g + b) / 3) - (r2 + g2 + b2) / 3) >
OUTLINE_THRESH || abs(r - r1) > OUTLINE_THRESH
|| abs(g - g1) > OUTLINE_THRESH
|| abs(b - b1) > OUTLINE_THRESH
|| abs(r - r2) > OUTLINE_THRESH || abs(g - g2) > OUTLINE_THRESH
|| abs(b - b2) > OUTLINE_THRESH)
|| abs(r - r2) > OUTLINE_THRESH || abs(g - g2) > OUTLINE_THRESH || abs(b - b2) > OUTLINE_THRESH)
{
api->putpixel(result_surf, xx - 1, yy,
SDL_MapRGB(result_surf->format, 0, 0, 0));
api->putpixel(result_surf, xx, yy - 1,
SDL_MapRGB(result_surf->format, 0, 0, 0));
api->putpixel(result_surf, xx - 1, yy - 1,
SDL_MapRGB(result_surf->format, 0, 0, 0));
api->putpixel(result_surf, xx - 1, yy, SDL_MapRGB(result_surf->format, 0, 0, 0));
api->putpixel(result_surf, xx, yy - 1, SDL_MapRGB(result_surf->format, 0, 0, 0));
api->putpixel(result_surf, xx - 1, yy - 1, SDL_MapRGB(result_surf->format, 0, 0, 0));
}
}
static void do_cartoon(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)
{
magic_api *api = (magic_api *) ptr;
int xx, yy;
@ -224,8 +201,7 @@ static void do_cartoon(void *ptr, int which ATTRIBUTE_UNUSED,
// Affect the canvas on drag:
void cartoon_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
if (ox > x)
{
@ -242,7 +218,7 @@ void cartoon_drag(magic_api * api, int which, SDL_Surface * canvas,
y = tmp;
}
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_cartoon);
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_cartoon);
update_rect->x = ox - cartoon_radius;
update_rect->y = oy - cartoon_radius;
@ -254,8 +230,7 @@ void cartoon_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void cartoon_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
for (y = 0; y < canvas->h; y++)
{
@ -303,8 +278,7 @@ void cartoon_release(magic_api * api ATTRIBUTE_UNUSED,
int which 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)
{
}
@ -316,46 +290,41 @@ void cartoon_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void cartoon_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void cartoon_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
// Use colors:
int cartoon_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int cartoon_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 0;
}
void cartoon_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas)
{
Uint32 amask;
amask =
~(canvas->format->Rmask | canvas->format->Gmask | canvas->format->Bmask);
amask = ~(canvas->format->Rmask | canvas->format->Gmask | canvas->format->Bmask);
result_surf = SDL_CreateRGBSurface(SDL_SWSURFACE,
canvas->w,
canvas->h,
canvas->format->BitsPerPixel,
canvas->format->Rmask,
canvas->format->Gmask,
canvas->format->Bmask, amask);
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, amask);
}
void cartoon_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
if (result_surf != NULL)
SDL_FreeSurface(result_surf);
}
int cartoon_modes(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int cartoon_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (MODE_PAINT | MODE_FULLSCREEN);
}
@ -374,7 +343,9 @@ Uint8 cartoon_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE
return 4;
}
void cartoon_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void cartoon_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
cartoon_radius = size * 4;
}

View file

@ -49,26 +49,24 @@ int checkerboard_get_group(magic_api * api, int which);
char *checkerboard_get_description(magic_api * api, int which, int mode);
int checkerboard_requires_colors(magic_api * api, int which);
void checkerboard_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, int x,
int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
void checkerboard_shutdown(magic_api * api);
void checkerboard_paint_checkerboard(void *ptr_to_api, int which_tool,
SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y);
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
void checkerboard_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void checkerboard_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x,
int y, SDL_Rect * update_rect);
void checkerboard_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void checkerboard_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void checkerboard_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void checkerboard_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int checkerboard_modes(magic_api * api, int which);
Uint8 checkerboard_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED);
Uint8 checkerboard_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED);
void checkerboard_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED);
Uint8 checkerboard_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED);
Uint8 checkerboard_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED);
void checkerboard_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED);
// Housekeeping functions
@ -77,8 +75,9 @@ Uint32 checkerboard_api_version(void)
return (TP_MAGIC_API_VERSION);
}
void checkerboard_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void checkerboard_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r,
Uint8 g, Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
//get the colors from API and store it in structure
checkerboard_r = r;
@ -90,8 +89,7 @@ int checkerboard_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED
{
char fname[1024];
snprintf(fname, sizeof(fname), "%ssounds/magic/checkerboard.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/checkerboard.ogg", api->data_directory);
checkerboard_snd = Mix_LoadWAV(fname);
return (1);
@ -102,40 +100,32 @@ int checkerboard_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
return 1;
}
SDL_Surface *checkerboard_get_icon(magic_api * api,
int which ATTRIBUTE_UNUSED)
SDL_Surface *checkerboard_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/checkerboard.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/checkerboard.png", api->data_directory);
return (IMG_Load(fname));
}
char *checkerboard_get_name(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
char *checkerboard_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return strdup(gettext_noop("Checkerboard"));
}
int checkerboard_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int checkerboard_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_PICTURE_DECORATIONS;
}
char *checkerboard_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return
strdup(gettext_noop
("Click and drag to fill the canvas with a checkerboard pattern."));
return strdup(gettext_noop("Click and drag to fill the canvas with a checkerboard pattern."));
}
int checkerboard_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int checkerboard_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 1;
}
@ -144,8 +134,7 @@ void checkerboard_release(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * snapshot 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)
{
}
@ -158,8 +147,7 @@ void checkerboard_shutdown(magic_api * api ATTRIBUTE_UNUSED)
void checkerboard_drag(magic_api * api, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * snapshot,
int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED,
int x, int y, SDL_Rect * update_rect)
int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, int x, int y, SDL_Rect * update_rect)
{
int sz, xx, yy;
Uint8 draw_start, draw_row, draw_cell;
@ -168,13 +156,9 @@ void checkerboard_drag(magic_api * api, int which ATTRIBUTE_UNUSED,
SDL_BlitSurface(snapshot, NULL, canvas, NULL);
sz =
max(10,
max(abs(x - checkerboard_start_x), abs(y - checkerboard_start_y)));
sz = max(10, max(abs(x - checkerboard_start_x), abs(y - checkerboard_start_y)));
colr =
SDL_MapRGB(canvas->format, checkerboard_r, checkerboard_g,
checkerboard_b);
colr = SDL_MapRGB(canvas->format, checkerboard_r, checkerboard_g, checkerboard_b);
draw_start = 1;
if (x < checkerboard_start_x)
@ -267,8 +251,7 @@ void checkerboard_drag(magic_api * api, int which ATTRIBUTE_UNUSED,
void checkerboard_click(magic_api * api, int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas,
SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
checkerboard_start_x = x;
checkerboard_start_y = y;
@ -276,26 +259,23 @@ void checkerboard_click(magic_api * api, int which ATTRIBUTE_UNUSED,
}
void checkerboard_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void checkerboard_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int checkerboard_modes(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int checkerboard_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (MODE_PAINT);
}
Uint8 checkerboard_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
Uint8 checkerboard_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED)
{
return 0;
}
@ -305,6 +285,8 @@ Uint8 checkerboard_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTR
return 0;
}
void checkerboard_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void checkerboard_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}

View file

@ -73,11 +73,9 @@ char *clone_get_name(magic_api * api, int which);
int clone_get_group(magic_api * api, int which);
char *clone_get_description(magic_api * api, int which, int mode);
void clone_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void clone_doit(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect, int crosshairs);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect, int crosshairs);
void clone_click(magic_api * api, int which, int mode, SDL_Surface * canvas,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void clone_release(magic_api * api, int which, SDL_Surface * canvas,
@ -86,29 +84,25 @@ void clone_shutdown(magic_api * api);
void clone_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
int clone_requires_colors(magic_api * api, int which);
void clone_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void clone_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void clone_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void clone_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int clone_modes(magic_api * api, int which);
void clone_crosshairs(magic_api * api, SDL_Surface * canvas, int x, int y);
void done_cloning(magic_api * api, SDL_Surface * canvas,
SDL_Rect * update_rect);
void done_cloning(magic_api * api, SDL_Surface * canvas, SDL_Rect * update_rect);
Uint8 clone_accepted_sizes(magic_api * api, int which, int mode);
Uint8 clone_default_size(magic_api * api, int which, int mode);
void clone_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void clone_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
// No setup required:
int clone_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%ssounds/magic/clone_start.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/clone_start.ogg", api->data_directory);
clone_start_snd = Mix_LoadWAV(fname);
snprintf(fname, sizeof(fname), "%ssounds/magic/clone.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/clone.ogg", api->data_directory);
clone_snd = Mix_LoadWAV(fname);
clone_state = CLONE_READY_TO_START;
@ -133,30 +127,25 @@ SDL_Surface *clone_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/clone.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/clone.png", api->data_directory);
return (IMG_Load(fname));
}
// Return our names, localized:
char *clone_get_name(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
char *clone_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (strdup(gettext_noop("Clone")));
}
// Return our groups:
int clone_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int clone_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_DISTORTS;
}
// Return our descriptions, localized:
char *clone_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED)
char *clone_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return (strdup
(gettext_noop
@ -167,8 +156,7 @@ char *clone_get_description(magic_api * api ATTRIBUTE_UNUSED,
// Do the effect:
static void do_clone(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, int x, int y)
static void do_clone(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
magic_api *api = (magic_api *) ptr;
int yy, dx;
@ -206,8 +194,7 @@ static void do_clone(void *ptr, int which ATTRIBUTE_UNUSED,
// Affect the canvas on drag:
void clone_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last ATTRIBUTE_UNUSED, int ox, int oy, int x,
int y, SDL_Rect * update_rect)
SDL_Surface * last ATTRIBUTE_UNUSED, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
/* Step 3 - Actively cloning (moving the mouse) */
@ -221,8 +208,7 @@ void clone_drag(magic_api * api, int which, SDL_Surface * canvas,
}
void clone_doit(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect, int crosshairs)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect, int crosshairs)
{
if (clone_state != CLONE_CLONING)
return;
@ -230,7 +216,7 @@ void clone_doit(magic_api * api, int which, SDL_Surface * canvas,
clone_drag_start_x = ox;
clone_drag_start_y = oy;
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_clone);
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_clone);
/* Move source position relative to mouse motion */
clone_src_x += (x - ox);
@ -275,8 +261,7 @@ void clone_doit(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void clone_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
if (clone_state == CLONE_READY_TO_START)
{
@ -306,8 +291,7 @@ void clone_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
void clone_release(magic_api * api, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED,
SDL_Rect * update_rect)
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect)
{
if (clone_state == CLONE_STARTING)
{
@ -321,8 +305,7 @@ void clone_release(magic_api * api, int which ATTRIBUTE_UNUSED,
}
}
void done_cloning(magic_api * api, SDL_Surface * canvas,
SDL_Rect * update_rect)
void done_cloning(magic_api * api, SDL_Surface * canvas, SDL_Rect * update_rect)
{
/* Done cloning! */
@ -361,32 +344,30 @@ void clone_shutdown(magic_api * api ATTRIBUTE_UNUSED)
Mix_FreeChunk(clone_start_snd);
}
void clone_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void clone_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
int clone_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int clone_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 0;
}
void clone_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
clone_last =
SDL_CreateRGBSurface(0, canvas->w, canvas->h,
canvas->format->BitsPerPixel, canvas->format->Rmask,
canvas->format->Gmask, canvas->format->Bmask,
canvas->format->Amask);
canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
clone_state = CLONE_READY_TO_START;
}
void clone_switchout(magic_api * api, int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas)
void clone_switchout(magic_api * api, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas)
{
SDL_Rect update_rect; /* Needed to satisfy done_cloning() :-( */
@ -402,15 +383,19 @@ int clone_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
}
Uint8 clone_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED) {
Uint8 clone_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return 8;
}
Uint8 clone_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED) {
Uint8 clone_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return 2;
}
void clone_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void clone_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
clone_radius = size * 8;
}

View file

@ -15,33 +15,35 @@
#include "SDL_image.h"
#include "SDL_mixer.h"
enum {
enum
{
COLORSEP_TOOL_3DGLASSES,
COLORSEP_TOOL_COLORSEP,
COLORSEP_TOOL_DOUBLEVISION,
NUM_TOOLS
};
static char * colorsep_snd_filenames[NUM_TOOLS] = {
static char *colorsep_snd_filenames[NUM_TOOLS] = {
"3dglasses.ogg",
"colorsep.ogg",
"doublevision.ogg",
};
static char * colorsep_icon_filenames[NUM_TOOLS] = {
static char *colorsep_icon_filenames[NUM_TOOLS] = {
"3dglasses.png",
"colorsep.png",
"doublevision.png"
};
char * colorsep_names[NUM_TOOLS] = {
char *colorsep_names[NUM_TOOLS] = {
gettext_noop("3D Glasses"),
gettext_noop("Color Sep."),
gettext_noop("Double Vision"),
};
char * colorsep_descrs[NUM_TOOLS] = {
gettext_noop("Click and drag left and right to separate your picture's red and cyan, to make anaglyphs you can view with 3D glasses!"),
char *colorsep_descrs[NUM_TOOLS] = {
gettext_noop
("Click and drag left and right to separate your picture's red and cyan, to make anaglyphs you can view with 3D glasses!"),
gettext_noop("Click and drag to separate your picture's colors."),
gettext_noop("Click and drag to simulate double vision."),
};
@ -61,25 +63,22 @@ int colorsep_requires_colors(magic_api * api, int which);
int colorsep_modes(magic_api * api, int which);
void colorsep_shutdown(magic_api * api);
void colorsep_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * snapshot, int x,
int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
void colorsep_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
void colorsep_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void colorsep_apply(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int offset_x, int offset_y, int preview);
void colorsep_release(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect);
void colorsep_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void colorsep_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
void colorsep_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void colorsep_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
Uint8 colorsep_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED);
Uint8 colorsep_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED);
void colorsep_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED);
void colorsep_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED);
Uint32 colorsep_api_version(void)
@ -92,9 +91,9 @@ int colorsep_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
int i;
char fname[1024];
for (i = 0; i < NUM_TOOLS; i++) {
snprintf(fname, sizeof(fname), "%ssounds/magic/%s",
api->data_directory, colorsep_snd_filenames[i]);
for (i = 0; i < NUM_TOOLS; i++)
{
snprintf(fname, sizeof(fname), "%ssounds/magic/%s", api->data_directory, colorsep_snd_filenames[i]);
snd_effects[i] = Mix_LoadWAV(fname);
}
@ -111,32 +110,27 @@ SDL_Surface *colorsep_get_icon(magic_api * api, int which)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/%s",
api->data_directory, colorsep_icon_filenames[which]);
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, colorsep_icon_filenames[which]);
return (IMG_Load(fname));
}
char *colorsep_get_name(magic_api * api ATTRIBUTE_UNUSED,
int which)
char *colorsep_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
{
return strdup(gettext(colorsep_names[which]));
}
int colorsep_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int colorsep_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_COLOR_FILTERS;
}
char *colorsep_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which, int mode ATTRIBUTE_UNUSED)
char *colorsep_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
{
return strdup(gettext(colorsep_descrs[which]));
}
int colorsep_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int colorsep_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
if (which == COLORSEP_TOOL_COLORSEP)
return 1;
@ -144,8 +138,7 @@ int colorsep_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
return 0;
}
int colorsep_modes(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int colorsep_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MODE_PAINT;
}
@ -154,7 +147,8 @@ void colorsep_shutdown(magic_api * api ATTRIBUTE_UNUSED)
{
int i;
for (i = 0; i < NUM_TOOLS; i++) {
for (i = 0; i < NUM_TOOLS; i++)
{
if (snd_effects[i] != NULL)
Mix_FreeChunk(snd_effects[i]);
}
@ -162,8 +156,7 @@ void colorsep_shutdown(magic_api * api ATTRIBUTE_UNUSED)
void
colorsep_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
{
api->stopsound();
@ -183,9 +176,12 @@ colorsep_drag(magic_api * api, int which, SDL_Surface * canvas,
int offset_x, offset_y;
offset_x = colorsep_click_x - x;
if (which == COLORSEP_TOOL_3DGLASSES) {
if (which == COLORSEP_TOOL_3DGLASSES)
{
offset_y = 0;
} else {
}
else
{
offset_y = colorsep_click_y - y;
}
@ -206,41 +202,54 @@ void colorsep_apply(magic_api * api, int which, SDL_Surface * canvas,
Uint8 r1, g1, b1, r2, g2, b2, r, g, b;
SDL_Rect dest;
if (preview) {
if (preview)
{
step = 3;
} else {
}
else
{
step = 1;
}
for (yy = 0; yy < canvas->h; yy = yy + step) {
for (xx = 0; xx < canvas->w; xx = xx + step) {
for (yy = 0; yy < canvas->h; yy = yy + step)
{
for (xx = 0; xx < canvas->w; xx = xx + step)
{
SDL_GetRGB(api->getpixel(snapshot, xx + offset_x / 2, yy + offset_y / 2), snapshot->format, &r1, &g1, &b1);
SDL_GetRGB(api->getpixel(snapshot, xx - offset_x / 2, yy - offset_y / 2), snapshot->format, &r2, &g2, &b2);
if (which == COLORSEP_TOOL_3DGLASSES) {
if (which == COLORSEP_TOOL_3DGLASSES)
{
/* Split red aparet from green & blue (cyan) */
r = r1;
g = g2;
b = b2;
} else if (which == COLORSEP_TOOL_COLORSEP) {
r = (Uint8) ((float) r1 * colorsep_r_pct) + ((float) r2 * (1.0 - colorsep_r_pct));
g = (Uint8) ((float) g1 * colorsep_g_pct) + ((float) g2 * (1.0 - colorsep_g_pct));
b = (Uint8) ((float) b1 * colorsep_b_pct) + ((float) b2 * (1.0 - colorsep_b_pct));
} else { /* which == COLORSEP_TOOL_DOUBLEVISION */
}
else if (which == COLORSEP_TOOL_COLORSEP)
{
r = (Uint8) ((float)r1 * colorsep_r_pct) + ((float)r2 * (1.0 - colorsep_r_pct));
g = (Uint8) ((float)g1 * colorsep_g_pct) + ((float)g2 * (1.0 - colorsep_g_pct));
b = (Uint8) ((float)b1 * colorsep_b_pct) + ((float)b2 * (1.0 - colorsep_b_pct));
}
else
{ /* which == COLORSEP_TOOL_DOUBLEVISION */
/* 50/50 for all colors */
r = (Uint8) ((float) r1 * 0.5) + ((float) r2 * 0.5);
g = (Uint8) ((float) g1 * 0.5) + ((float) g2 * 0.5);
b = (Uint8) ((float) b1 * 0.5) + ((float) b2 * 0.5);
r = (Uint8) ((float)r1 * 0.5) + ((float)r2 * 0.5);
g = (Uint8) ((float)g1 * 0.5) + ((float)g2 * 0.5);
b = (Uint8) ((float)b1 * 0.5) + ((float)b2 * 0.5);
}
if (preview) {
if (preview)
{
dest.x = xx;
dest.y = yy;
dest.w = step;
dest.h = step;
SDL_FillRect(canvas, &dest, SDL_MapRGB(canvas->format, r, g, b));
} else {
}
else
{
api->putpixel(canvas, xx, yy, SDL_MapRGB(canvas->format, r, g, b));
}
}
@ -249,17 +258,17 @@ void colorsep_apply(magic_api * api, int which, SDL_Surface * canvas,
void colorsep_release(magic_api * api, int which,
SDL_Surface * canvas,
SDL_Surface * snapshot,
int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
{
int offset_x, offset_y;
offset_x = colorsep_click_x - x;
if (which == COLORSEP_TOOL_3DGLASSES) {
if (which == COLORSEP_TOOL_3DGLASSES)
{
offset_y = 0;
} else {
}
else
{
offset_y = colorsep_click_y - y;
}
colorsep_apply(api, which, canvas, snapshot, offset_x, offset_y, 0);
@ -272,16 +281,16 @@ void colorsep_release(magic_api * api, int which,
void colorsep_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 r, Uint8 g, Uint8 b,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
colorsep_r_pct = (float) r / 255.0;
colorsep_g_pct = (float) g / 255.0;
colorsep_b_pct = (float) b / 255.0;
colorsep_r_pct = (float)r / 255.0;
colorsep_g_pct = (float)g / 255.0;
colorsep_b_pct = (float)b / 255.0;
if (colorsep_r_pct == colorsep_g_pct && colorsep_r_pct == colorsep_b_pct) {
if (colorsep_r_pct == colorsep_g_pct && colorsep_r_pct == colorsep_b_pct)
{
colorsep_r_pct = 1.0;
colorsep_g_pct = 0.0;
colorsep_b_pct = 0.0;
@ -290,15 +299,12 @@ void colorsep_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UN
void colorsep_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void colorsep_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
@ -313,6 +319,8 @@ Uint8 colorsep_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUT
}
void colorsep_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void colorsep_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}

View file

@ -8,7 +8,8 @@
#include "SDL_image.h"
#include "SDL_mixer.h"
static int CONFETTI_BRUSH_SIZE = 8; //radius of each confetti circle
static int CONFETTI_BRUSH_SIZE = 8; //radius of each confetti circle
#define CONFETTI_QUANTITY 3 //how many circles will be created every click?
#ifdef __ANDROID__
@ -36,37 +37,34 @@ int confetti_get_group(magic_api * api, int which);
char *confetti_get_description(magic_api * api, int which, int mode);
int confetti_requires_colors(magic_api * api, int which);
void confetti_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, int x,
int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
void confetti_shutdown(magic_api * api);
inline char confetti_get_greater(const char what1, const char what2);
inline char confetti_get_lesser(const char what1, const char what2);
Uint32 confetti_get_new_color(void *ptr, SDL_Surface * canvas);
void confetti_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
void confetti_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void confetti_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void confetti_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void confetti_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int confetti_modes(magic_api * api, int which);
// Housekeeping functions
void confetti_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
Uint8 confetti_accepted_sizes(magic_api * api, int which, int mode);
Uint8 confetti_default_size(magic_api * api, int which, int mode);
void confetti_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void confetti_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
Uint32 confetti_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
void confetti_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void confetti_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g,
Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
//get the colors from API and store it in structure
confetti_colors.r = r;
@ -78,8 +76,7 @@ int confetti_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%ssounds/magic/confetti.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/confetti.ogg", api->data_directory);
confetti_snd = Mix_LoadWAV(fname);
return (1);
@ -94,33 +91,27 @@ SDL_Surface *confetti_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/confetti.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/confetti.png", api->data_directory);
return (IMG_Load(fname));
}
char *confetti_get_name(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
char *confetti_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return strdup(gettext_noop("Confetti"));
}
int confetti_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int confetti_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_PAINTING;
}
char *confetti_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED)
char *confetti_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return strdup(gettext_noop("Click to throw confetti!"));
}
int confetti_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int confetti_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 1;
}
@ -129,8 +120,7 @@ void confetti_release(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * snapshot 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)
{
}
@ -183,27 +173,23 @@ Uint32 confetti_get_new_color(void *ptr, SDL_Surface * canvas) //this function
static void confetti_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)
{
magic_api *api = (magic_api *) ptr;
int xx, yy;
Uint32 color = confetti_get_new_color(api, canvas);
for (yy = y - CONFETTI_BRUSH_SIZE / 2; yy < y + CONFETTI_BRUSH_SIZE / 2;
yy++)
for (yy = y - CONFETTI_BRUSH_SIZE / 2; yy < y + CONFETTI_BRUSH_SIZE / 2; yy++)
for (xx = x - CONFETTI_BRUSH_SIZE / 2; xx < x + CONFETTI_BRUSH_SIZE / 2;
xx++)
for (xx = x - CONFETTI_BRUSH_SIZE / 2; xx < x + CONFETTI_BRUSH_SIZE / 2; xx++)
if (api->in_circle(xx - x, yy - y, CONFETTI_BRUSH_SIZE / 2))
api->putpixel(canvas, xx, yy, color);
}
void confetti_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
unsigned char i;
char min_x = 0, max_x = 0, min_y = 0, max_y = 0;
@ -212,8 +198,8 @@ void confetti_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
for (i = 0; i < CONFETTI_QUANTITY; i++)
{
srand((dx + dy) / 2 + time(0)); //to get a unique seed even if dx and dy aren't defined
dx = (rand() % CONFETTI_BRUSH_SIZE * 12) - (CONFETTI_BRUSH_SIZE * 6); //generate a value between <-50; +50>
dy = (rand() % CONFETTI_BRUSH_SIZE * 12) - (CONFETTI_BRUSH_SIZE * 6); //to spread confetti around the cursor position
dx = (rand() % CONFETTI_BRUSH_SIZE * 12) - (CONFETTI_BRUSH_SIZE * 6); //generate a value between <-50; +50>
dy = (rand() % CONFETTI_BRUSH_SIZE * 12) - (CONFETTI_BRUSH_SIZE * 6); //to spread confetti around the cursor position
if (!i)
{
@ -227,7 +213,7 @@ void confetti_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
min_y = confetti_get_lesser(min_y, dy);
max_y = confetti_get_greater(max_y, dy);
}
confetti_circle((void *) api, which, canvas, last, x + dx, y + dy);
confetti_circle((void *)api, which, canvas, last, x + dx, y + dy);
}
update_rect->x = x + min_x - CONFETTI_BRUSH_SIZE / 2;
@ -239,8 +225,7 @@ void confetti_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
}
void confetti_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
int temp;
@ -261,19 +246,16 @@ void confetti_drag(magic_api * api, int which, SDL_Surface * canvas,
}
void confetti_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void confetti_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int confetti_modes(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int confetti_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (MODE_PAINT);
}
@ -289,7 +271,9 @@ Uint8 confetti_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUT
return 2;
}
void confetti_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void confetti_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
CONFETTI_BRUSH_SIZE = size * 4;
}

View file

@ -65,31 +65,25 @@ int distortion_requires_colors(magic_api * api, int which);
void distortion_shutdown(magic_api * api);
void distortion_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * snapshot, int x,
int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
void distortion_release(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
void distortion_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
void distortion_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void distortion_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void distortion_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void distortion_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int distortion_modes(magic_api * api, int which);
void distortion_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
static void distortion_line_callback(void *ptr, int which,
SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y);
static void distortion_line_callback(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
Uint8 distortion_accepted_sizes(magic_api * api, int which, int mode);
Uint8 distortion_default_size(magic_api * api, int which, int mode);
void distortion_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void distortion_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
/* Setup Functions: */
@ -107,8 +101,7 @@ int distortion_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%ssounds/magic/distortion.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/distortion.ogg", api->data_directory);
// Try to load the file!
@ -132,8 +125,7 @@ SDL_Surface *distortion_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/distortion.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/distortion.png", api->data_directory);
// Try to load the image, and return the results to Tux Paint:
@ -144,8 +136,7 @@ SDL_Surface *distortion_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
// Report our "Magic" tool names
char *distortion_get_name(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
char *distortion_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (strdup(gettext_noop("Distortion")));
}
@ -153,8 +144,7 @@ char *distortion_get_name(magic_api * api ATTRIBUTE_UNUSED,
// Report our "Magic" tool groups
int distortion_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int distortion_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_DISTORTS;
}
@ -163,18 +153,14 @@ int distortion_get_group(magic_api * api ATTRIBUTE_UNUSED,
// Report our "Magic" tool descriptions
char *distortion_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return (strdup
(gettext_noop
("Click and drag the mouse to cause distortion in your picture.")));
return (strdup(gettext_noop("Click and drag the mouse to cause distortion in your picture.")));
}
// Report whether we accept colors
int distortion_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int distortion_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 0;
}
@ -194,8 +180,7 @@ void distortion_shutdown(magic_api * api ATTRIBUTE_UNUSED)
// Affect the canvas on click:
void distortion_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * snapshot, int x,
int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
{
distortion_drag(api, which, canvas, snapshot, x, y, x, y, update_rect);
}
@ -204,11 +189,9 @@ void distortion_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
// Affect the canvas on drag:
void distortion_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *) api, which, canvas, snapshot, ox, oy, x, y, 1,
distortion_line_callback);
api->line((void *)api, which, canvas, snapshot, ox, oy, x, y, 1, distortion_line_callback);
if (ox > x)
@ -244,14 +227,15 @@ void distortion_release(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * snapshot 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)
{
}
void distortion_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void distortion_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
@ -259,8 +243,7 @@ void distortion_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_
// Our "callback" function
static void distortion_line_callback(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y)
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y)
{
magic_api *api = (magic_api *) ptr;
int xx, yy;
@ -276,29 +259,23 @@ static void distortion_line_callback(void *ptr, int which ATTRIBUTE_UNUSED,
{
if (api->in_circle(xx, yy, distortion_radius))
{
api->putpixel(canvas, x + xx, y + yy,
api->getpixel(snapshot, x + xx / 2, y + yy));
api->putpixel(canvas, x + xx, y + yy, api->getpixel(snapshot, x + xx / 2, y + yy));
}
}
}
}
void distortion_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void distortion_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int distortion_modes(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int distortion_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (MODE_PAINT);
}
@ -314,7 +291,9 @@ Uint8 distortion_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIB
return 2;
}
void distortion_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void distortion_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
distortion_radius = size * 4;
}

View file

@ -47,29 +47,25 @@ int emboss_get_group(magic_api * api, int which);
char *emboss_get_description(magic_api * api, int which, int mode);
void emboss_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void emboss_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void emboss_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void emboss_shutdown(magic_api * api);
void emboss_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
int emboss_requires_colors(magic_api * api, int which);
void emboss_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void emboss_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void emboss_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void emboss_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int emboss_modes(magic_api * api, int which);
Uint8 emboss_accepted_sizes(magic_api * api, int which, int mode);
Uint8 emboss_default_size(magic_api * api, int which, int mode);
void emboss_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void emboss_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
Uint32 emboss_api_version(void)
@ -83,8 +79,7 @@ int emboss_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%ssounds/magic/emboss.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/emboss.ogg", api->data_directory);
emboss_snd = Mix_LoadWAV(fname);
return (1);
@ -101,34 +96,28 @@ SDL_Surface *emboss_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/emboss.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/emboss.png", api->data_directory);
return (IMG_Load(fname));
}
// 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 our groups:
int emboss_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int emboss_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_DISTORTS;
}
// Return our descriptions, localized:
char *emboss_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode)
char *emboss_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode)
{
if (mode == MODE_PAINT)
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.")));
else
return (strdup(gettext_noop("Click to emboss the entire picture.")));
}
@ -136,8 +125,7 @@ char *emboss_get_description(magic_api * api ATTRIBUTE_UNUSED,
// Do the effect (single pixel; used by do_emboss() (painted circle)
// and emboss_click() when in fullscreen mode):
static void emboss_pixel(void *ptr, SDL_Surface * last, int x, int y,
SDL_Surface * canvas)
static void emboss_pixel(void *ptr, SDL_Surface * last, int x, int y, SDL_Surface * canvas)
{
magic_api *api = (magic_api *) ptr;
Uint8 r1, g1, b1, r2, g2, b2;
@ -168,8 +156,7 @@ static void emboss_pixel(void *ptr, SDL_Surface * last, int x, int y,
// Do the effect (a circle around a touch point):
static void do_emboss(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, int x, int y)
static void do_emboss(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
magic_api *api = (magic_api *) ptr;
int xx, yy;
@ -191,10 +178,9 @@ static void do_emboss(void *ptr, int which ATTRIBUTE_UNUSED,
// Affect the canvas on drag:
void emboss_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * last, int ox, int oy, int x, int y, 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)
{
@ -221,8 +207,7 @@ void emboss_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void emboss_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
if (mode == MODE_PAINT)
{
@ -255,8 +240,7 @@ void emboss_release(magic_api * api ATTRIBUTE_UNUSED,
int which 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)
{
}
@ -268,27 +252,26 @@ void emboss_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void emboss_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void emboss_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
// Use colors:
int emboss_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int emboss_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 0;
}
void emboss_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas 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 which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
@ -311,7 +294,9 @@ Uint8 emboss_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_
return 4;
}
void emboss_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void emboss_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
emboss_radius = size * 4;
}

View file

@ -43,7 +43,7 @@ enum
NUM_TOOLS
};
char * tool_names[NUM_TOOLS] = {
char *tool_names[NUM_TOOLS] = {
gettext_noop("Lighten"),
gettext_noop("Darken"),
gettext_noop("Desaturate"),
@ -52,34 +52,31 @@ char * tool_names[NUM_TOOLS] = {
gettext_noop("Keep Color"),
};
char * tool_descriptions[NUM_TOOLS][2] = {
char *tool_descriptions[NUM_TOOLS][2] = {
{
gettext_noop("Click and drag the mouse to lighten parts of your picture."),
gettext_noop("Click to lighten your entire picture.")
},
gettext_noop("Click to lighten your entire picture.")},
{
gettext_noop("Click and drag the mouse to darken parts of your picture."),
gettext_noop("Click to darken your entire picture.")
},
gettext_noop("Click to darken your entire picture.")},
{
gettext_noop("Click and drag the mouse to desaturate parts of your picture."),
gettext_noop("Click to desaturate your entire picture.")
},
gettext_noop("Click to desaturate your entire picture.")},
{
gettext_noop("Click and drag the mouse to saturate parts of your picture."),
gettext_noop("Click to saturate your entire picture.")
},
gettext_noop("Click to saturate your entire picture.")},
{
gettext_noop("Click and drag the mouse to entirely desaturate parts of your picture that match the chosen color."),
gettext_noop("Click to entirely desaturate the parts of your picture that match the chosen color."),
},
},
{
gettext_noop("Click and drag the mouse to entirely desaturate parts of your picture that don't match the chosen color."),
gettext_noop
("Click and drag the mouse to entirely desaturate parts of your picture that don't match the chosen color."),
gettext_noop("Click to entirely desaturate the parts of your picture that don't match the chosen color."),
},
},
};
char * sfx_filenames[NUM_TOOLS] = {
char *sfx_filenames[NUM_TOOLS] = {
"fade.wav",
"darken.wav",
"desaturate.ogg",
@ -88,7 +85,7 @@ char * sfx_filenames[NUM_TOOLS] = {
"keep_color.ogg",
};
char * icon_filenames[NUM_TOOLS] = {
char *icon_filenames[NUM_TOOLS] = {
"fade.png",
"darken.png",
"desaturate.png",
@ -117,31 +114,25 @@ SDL_Surface *fade_darken_get_icon(magic_api * api, int which);
int fade_darken_get_group(magic_api * api, int which);
char *fade_darken_get_name(magic_api * api, int which);
char *fade_darken_get_description(magic_api * api, int which, int mode);
static void do_fade_darken(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y);
static void do_fade_darken_paint(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y);
static void do_fade_darken(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
static void do_fade_darken_paint(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
void fade_darken_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void fade_darken_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void fade_darken_release(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void fade_darken_shutdown(magic_api * api);
void fade_darken_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
int fade_darken_requires_colors(magic_api * api, int which);
void fade_darken_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void fade_darken_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void fade_darken_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void fade_darken_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int fade_darken_modes(magic_api * api, int which);
Uint8 fade_darken_accepted_sizes(magic_api * api, int which, int mode);
Uint8 fade_darken_default_size(magic_api * api, int which, int mode);
void fade_darken_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void fade_darken_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
int fade_darken_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
@ -149,9 +140,9 @@ int fade_darken_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
int i;
char fname[1024];
for (i = 0; i < NUM_TOOLS; i++) {
snprintf(fname, sizeof(fname), "%ssounds/magic/%s",
api->data_directory, sfx_filenames[i]);
for (i = 0; i < NUM_TOOLS; i++)
{
snprintf(fname, sizeof(fname), "%ssounds/magic/%s", api->data_directory, sfx_filenames[i]);
snd_effects[i] = Mix_LoadWAV(fname);
}
@ -174,8 +165,7 @@ SDL_Surface *fade_darken_get_icon(magic_api * api, int which)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/%s",
api->data_directory, icon_filenames[which]);
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, icon_filenames[which]);
return (IMG_Load(fname));
}
@ -187,21 +177,18 @@ char *fade_darken_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
}
// Return our group (all the same):
int fade_darken_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int fade_darken_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_COLOR_FILTERS;
}
// Return our description, localized:
char *fade_darken_get_description(magic_api * api ATTRIBUTE_UNUSED, int which,
int mode)
char *fade_darken_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode)
{
return strdup(gettext(tool_descriptions[which][mode - 1]));
}
static void do_fade_darken(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y)
static void do_fade_darken(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
Uint8 r, g, b;
magic_api *api = (magic_api *) ptr;
@ -226,25 +213,36 @@ static void do_fade_darken(void *ptr, int which, SDL_Surface * canvas,
api->rgbtohsv(r, g, b, &h, &s, &v);
if (which == TOOL_DESATURATE) {
if (which == TOOL_DESATURATE)
{
s = (s * SAT_DESAT_RATIO_NUM) / SAT_DESAT_RATIO_DENOM;
} else if (which == TOOL_SATURATE) {
if (s > 0.1) { /* don't saturate things w/o undefined color! */
}
else if (which == TOOL_SATURATE)
{
if (s > 0.1)
{ /* don't saturate things w/o undefined color! */
s = (s * SAT_DESAT_RATIO_DENOM) / SAT_DESAT_RATIO_NUM;
if (s > 1.0) {
if (s > 1.0)
{
s = 1.0;
}
}
} else if (which == TOOL_REMOVE) {
}
else if (which == TOOL_REMOVE)
{
if (fabs(h - chosen_h) <= KEEP_REMOVE_HUE_THRESH
/* && fabs(s - chosen_s) <= KEEP_REMOVE_VALUE_THRESH */
) {
/* && fabs(s - chosen_s) <= KEEP_REMOVE_VALUE_THRESH */
)
{
s = 0.0;
}
} else if (which == TOOL_KEEP) {
}
else if (which == TOOL_KEEP)
{
if (fabs(h - chosen_h) > KEEP_REMOVE_HUE_THRESH
/* || fabs(s - chosen_s) > KEEP_REMOVE_VALUE_THRESH */
) {
/* || fabs(s - chosen_s) > KEEP_REMOVE_VALUE_THRESH */
)
{
s = 0.0;
}
}
@ -257,8 +255,7 @@ static void do_fade_darken(void *ptr, int which, SDL_Surface * canvas,
// Callback that does the fade_darken color effect on a circle centered around x,y
static void do_fade_darken_paint(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y)
static void do_fade_darken_paint(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
int xx, yy;
magic_api *api = (magic_api *) ptr;
@ -277,14 +274,12 @@ static void do_fade_darken_paint(void *ptr, int which, SDL_Surface * canvas,
// Ask Tux Paint to call our 'do_fade_darken_paint()' callback over a line
void fade_darken_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
SDL_LockSurface(last);
SDL_LockSurface(canvas);
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1,
do_fade_darken_paint);
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_fade_darken_paint);
SDL_UnlockSurface(canvas);
SDL_UnlockSurface(last);
@ -315,8 +310,7 @@ void fade_darken_drag(magic_api * api, int which, SDL_Surface * canvas,
// Ask Tux Paint to call our 'do_fade_darken_paint()' callback at a single point,
// or 'do_fade_darken()' on the entire image
void fade_darken_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
if (mode == MODE_PAINT)
fade_darken_drag(api, which, canvas, last, x, y, x, y, update_rect);
@ -342,8 +336,7 @@ void fade_darken_release(magic_api * api ATTRIBUTE_UNUSED,
int which 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)
{
}
@ -358,7 +351,8 @@ void fade_darken_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
void fade_darken_set_color(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
float tmp;
@ -366,8 +360,7 @@ void fade_darken_set_color(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surf
}
// We don't use colors
int fade_darken_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int fade_darken_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
if (which == TOOL_REMOVE || which == TOOL_KEEP)
return 1;
@ -376,27 +369,23 @@ int fade_darken_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
}
void fade_darken_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void fade_darken_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int fade_darken_modes(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int fade_darken_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (MODE_PAINT | MODE_FULLSCREEN);
}
Uint8 fade_darken_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
Uint8 fade_darken_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED)
{
if (mode == MODE_PAINT)
return 8;
@ -409,7 +398,9 @@ Uint8 fade_darken_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRI
return 4;
}
void fade_darken_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void fade_darken_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
fade_darken_radius = size * 4;
}

View file

@ -49,39 +49,36 @@ int fisheye_get_group(magic_api * api, int which);
char *fisheye_get_description(magic_api * api, int which, int mode);
int fisheye_requires_colors(magic_api * api, int which);
void fisheye_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, int x,
int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
void fisheye_shutdown(magic_api * api);
void fisheye_draw(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y);
void fisheye_draw(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
void fisheye_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void fisheye_click(magic_api * api, int which, int mode, SDL_Surface * canvas,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void fisheye_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void fisheye_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void fisheye_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void fisheye_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int fisheye_modes(magic_api * api, int which);
Uint8 fisheye_accepted_sizes(magic_api * api, int which, int mode);
Uint8 fisheye_default_size(magic_api * api, int which, int mode);
void fisheye_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void fisheye_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
// Housekeeping functions
void fisheye_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
Uint32 fisheye_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
void fisheye_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void fisheye_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
@ -89,8 +86,7 @@ int fisheye_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%ssounds/magic/fisheye.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/fisheye.ogg", api->data_directory);
fisheye_snd = Mix_LoadWAV(fname);
return (1);
@ -105,35 +101,27 @@ SDL_Surface *fisheye_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/fisheye.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/fisheye.png", api->data_directory);
return (IMG_Load(fname));
}
char *fisheye_get_name(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
char *fisheye_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return strdup(gettext_noop("Fisheye"));
}
int fisheye_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int fisheye_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_DISTORTS;
}
char *fisheye_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED)
char *fisheye_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return
strdup(gettext_noop
("Click on part of your picture to create a fisheye effect."));
return strdup(gettext_noop("Click on part of your picture to create a fisheye effect."));
}
int fisheye_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int fisheye_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 0;
}
@ -142,8 +130,7 @@ void fisheye_release(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * snapshot 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)
{
}
@ -172,13 +159,11 @@ void fisheye_draw(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
oryg =
SDL_CreateRGBSurface(SDL_SWSURFACE, fisheye_radius, fisheye_radius, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask,
canvas->format->Bmask, canvas->format->Amask);
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
output =
SDL_CreateRGBSurface(SDL_SWSURFACE, fisheye_radius, fisheye_radius, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask,
canvas->format->Bmask, canvas->format->Amask);
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
rect.x = x - (fisheye_radius / 2);
rect.y = y - (fisheye_radius / 2);
@ -191,8 +176,7 @@ void fisheye_draw(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
{
temp_src =
SDL_CreateRGBSurface(SDL_SWSURFACE, 1, fisheye_radius, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask,
canvas->format->Bmask, canvas->format->Amask);
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
//let's take a smooth bar of scaled bitmap and copy it to temp
//left side first
@ -205,10 +189,9 @@ void fisheye_draw(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
temp_dest =
SDL_CreateRGBSurface(SDL_SWSURFACE, 1, fisheye_radius + 2 * i,
canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask,
canvas->format->Bmask, canvas->format->Amask);
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
temp_dest = api->scale(temp_src, 1, fisheye_radius + 2 * i, 0); //temp_dest stores scaled temp_src
temp_dest = api->scale(temp_src, 1, fisheye_radius + 2 * i, 0); //temp_dest stores scaled temp_src
temp_rect.x = 0;
temp_rect.y = i;
@ -223,7 +206,7 @@ void fisheye_draw(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
SDL_BlitSurface(oryg, &rect, temp_src, NULL); //this bar is copied to temp_src //OK
temp_dest = api->scale(temp_src, 1, fisheye_radius + 2 * i, 0); //temp_dest stores scaled temp_src
temp_dest = api->scale(temp_src, 1, fisheye_radius + 2 * i, 0); //temp_dest stores scaled temp_src
SDL_BlitSurface(temp_dest, &temp_rect, output, &rect); //let's copy it to output
}
@ -233,14 +216,12 @@ void fisheye_draw(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
{
temp_src =
SDL_CreateRGBSurface(SDL_SWSURFACE, fisheye_radius, 1, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask,
canvas->format->Bmask, canvas->format->Amask);
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
temp_dest =
SDL_CreateRGBSurface(SDL_SWSURFACE, fisheye_radius + 2 * i, 1,
canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask,
canvas->format->Bmask, canvas->format->Amask);
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
//upper side first
rect.x = 0;
@ -274,9 +255,12 @@ void fisheye_draw(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
//let's blit an area surrounded by a circle
for (yy = y - (fisheye_radius / 2); yy < y + (fisheye_radius / 2); yy++) {
for (xx = x - (fisheye_radius / 2); xx < x + (fisheye_radius / 2); xx++) {
if (api->in_circle(xx - x, yy - y, (fisheye_radius / 2))) {
for (yy = y - (fisheye_radius / 2); yy < y + (fisheye_radius / 2); yy++)
{
for (xx = x - (fisheye_radius / 2); xx < x + (fisheye_radius / 2); xx++)
{
if (api->in_circle(xx - x, yy - y, (fisheye_radius / 2)))
{
api->putpixel(canvas, xx, yy,
api->getpixel(output, xx + (fisheye_radius / 2) - x, yy + (fisheye_radius / 2) - y));
}
@ -294,8 +278,7 @@ void fisheye_draw(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
}
void fisheye_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line(api, which, canvas, snapshot, ox, oy, x, y, 1, fisheye_draw);
@ -306,30 +289,26 @@ void fisheye_drag(magic_api * api, int which, SDL_Surface * canvas,
}
void fisheye_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
last_x = -fisheye_radius; /* A value that will be beyond any clicked position */
last_x = -fisheye_radius; /* A value that will be beyond any clicked position */
last_y = -fisheye_radius;
fisheye_drag(api, which, canvas, last, x, y, x, y, update_rect);
}
void fisheye_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void fisheye_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int fisheye_modes(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int fisheye_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (MODE_PAINT);
}
@ -337,15 +316,17 @@ int fisheye_modes(magic_api * api ATTRIBUTE_UNUSED,
Uint8 fisheye_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return 5; // FIXME
return 5; // FIXME
}
Uint8 fisheye_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return 2; // FIXME
return 2; // FIXME
}
void fisheye_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void fisheye_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
fisheye_radius = size * 40;
}

View file

@ -59,8 +59,7 @@ static int flower_min_x, flower_max_x, flower_bottom_x, flower_bottom_y;
static int flower_side_first;
static int flower_side_decided;
static SDL_Surface *flower_base_full = NULL, *flower_leaf_full = NULL, *flower_petals_full = NULL;
static SDL_Surface *flower_base = NULL, *flower_leaf = NULL, *flower_petals = NULL,
*flower_petals_colorized = NULL;
static SDL_Surface *flower_base = NULL, *flower_leaf = NULL, *flower_petals = NULL, *flower_petals_colorized = NULL;
/* Local function prototypes: */
@ -70,11 +69,9 @@ typedef struct
} Point2D;
static void flower_drawbase(magic_api * api, SDL_Surface * canvas);
static void flower_drawflower(magic_api * api, SDL_Surface * canvas, int x,
int y);
static void flower_drawflower(magic_api * api, SDL_Surface * canvas, int x, int y);
static Point2D flower_PointOnCubicBezier(Point2D * cp, float t);
static void flower_ComputeBezier(Point2D * cp, int numberOfPoints,
Point2D * curve);
static void flower_ComputeBezier(Point2D * cp, int numberOfPoints, Point2D * curve);
Uint32 flower_api_version(void);
int flower_init(magic_api * api, Uint32 disabled_features);
int flower_get_tool_count(magic_api * api);
@ -82,37 +79,31 @@ SDL_Surface *flower_get_icon(magic_api * api, int which);
char *flower_get_name(magic_api * api, int which);
int flower_get_group(magic_api * api, int which);
char *flower_get_description(magic_api * api, int which, int mode);
static void flower_predrag(magic_api * api, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y);
static void flower_predrag(magic_api * api, SDL_Surface * canvas, SDL_Surface * last, int ox, int oy, int x, int y);
void flower_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void flower_click(magic_api * api, int which, int mode, SDL_Surface * canvas,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void flower_release(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
static void flower_drawflower(magic_api * api, SDL_Surface * canvas, int x,
int y);
static void flower_drawflower(magic_api * api, SDL_Surface * canvas, int x, int y);
static void flower_drawbase(magic_api * api, SDL_Surface * canvas);
static void flower_drawstalk(magic_api * api, SDL_Surface * canvas,
int top_x, int top_y, int minx, int maxx,
int bottom_x, int bottom_y, int final);
int top_x, int top_y, int minx, int maxx, int bottom_x, int bottom_y, int final);
void flower_shutdown(magic_api * api);
void flower_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
int flower_requires_colors(magic_api * api, int which);
static Point2D flower_PointOnCubicBezier(Point2D * cp, float t);
static void flower_ComputeBezier(Point2D * cp, int numberOfPoints,
Point2D * curve);
static void flower_ComputeBezier(Point2D * cp, int numberOfPoints, Point2D * curve);
static void flower_colorize_petals(magic_api * api);
void flower_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void flower_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void flower_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void flower_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int flower_modes(magic_api * api, int which);
Uint8 flower_accepted_sizes(magic_api * api, int which, int mode);
Uint8 flower_default_size(magic_api * api, int which, int mode);
void flower_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void flower_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
@ -126,58 +117,59 @@ Uint32 flower_api_version(void)
int flower_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{
char fname[1024];
SDL_Surface * tmp_surf;
SDL_Surface *tmp_surf;
int h;
snprintf(fname, sizeof(fname), "%ssounds/magic/flower_click.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/flower_click.ogg", api->data_directory);
flower_click_snd = Mix_LoadWAV(fname);
snprintf(fname, sizeof(fname), "%ssounds/magic/flower_release.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/flower_release.ogg", api->data_directory);
flower_release_snd = Mix_LoadWAV(fname);
snprintf(fname, sizeof(fname), "%simages/magic/flower_base.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/flower_base.png", api->data_directory);
tmp_surf = IMG_Load(fname);
if (tmp_surf == NULL) {
if (tmp_surf == NULL)
{
fprintf(stderr, "Cannot load %s", fname);
return(0);
return (0);
}
h = tmp_surf->h * MAX_WIDTH / tmp_surf->w;
flower_base_full = api->scale(tmp_surf, MAX_WIDTH, h, 1);
if (flower_base_full == NULL) {
if (flower_base_full == NULL)
{
fprintf(stderr, "Cannot scale %s", fname);
return(0);
return (0);
}
snprintf(fname, sizeof(fname), "%simages/magic/flower_leaf.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/flower_leaf.png", api->data_directory);
tmp_surf = IMG_Load(fname);
if (tmp_surf == NULL) {
if (tmp_surf == NULL)
{
fprintf(stderr, "Cannot load %s", fname);
return(0);
return (0);
}
/* N.B.: Leaf is 1/2 as wide as base & petals */
h = tmp_surf->h * (MAX_WIDTH / 2) / tmp_surf->w;
flower_leaf_full = api->scale(tmp_surf, MAX_WIDTH / 2, h, 1);
if (flower_leaf_full == NULL) {
if (flower_leaf_full == NULL)
{
fprintf(stderr, "Cannot scale %s", fname);
return(0);
return (0);
}
snprintf(fname, sizeof(fname), "%simages/magic/flower_petals.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/flower_petals.png", api->data_directory);
tmp_surf = IMG_Load(fname);
if (tmp_surf == NULL) {
if (tmp_surf == NULL)
{
fprintf(stderr, "Cannot load %s", fname);
return(0);
return (0);
}
h = tmp_surf->h * MAX_WIDTH / tmp_surf->w;
flower_petals_full = api->scale(tmp_surf, MAX_WIDTH, h, 1);
if (flower_petals_full == NULL) {
if (flower_petals_full == NULL)
{
fprintf(stderr, "Cannot scale %s", fname);
return(0);
return (0);
}
flower_cur_size = DEFAULT_SIZE;
@ -197,41 +189,33 @@ SDL_Surface *flower_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/flower.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/flower.png", api->data_directory);
return (IMG_Load(fname));
}
// Return our names, localized:
char *flower_get_name(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
char *flower_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (strdup(gettext_noop("Flower")));
}
// Return our groups:
int flower_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int flower_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_ARTISTIC;
}
// Return our descriptions, localized:
char *flower_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED)
char *flower_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return (strdup
(gettext_noop
("Click and drag to draw a flower stalk. Let go to finish the flower.")));
return (strdup(gettext_noop("Click and drag to draw a flower stalk. Let go to finish the flower.")));
}
// Affect the canvas on drag:
static void flower_predrag(magic_api * api ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED,
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)
{
if (x < flower_min_x)
flower_min_x = x;
@ -265,8 +249,7 @@ static void flower_predrag(magic_api * api ATTRIBUTE_UNUSED,
}
void flower_drag(magic_api * api, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, int ox, int oy,
int x, int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
flower_predrag(api, canvas, last, ox, oy, x, y);
@ -279,8 +262,7 @@ void flower_drag(magic_api * api, int which ATTRIBUTE_UNUSED,
/* Draw the base and the stalk (low-quality) for now: */
flower_drawstalk(api, canvas,
x, y, flower_min_x, flower_max_x, flower_bottom_x,
flower_bottom_y, !(api->button_down()));
x, y, flower_min_x, flower_max_x, flower_bottom_x, flower_bottom_y, !(api->button_down()));
flower_drawbase(api, canvas);
@ -292,8 +274,7 @@ void flower_drag(magic_api * api, int which ATTRIBUTE_UNUSED,
// Affect the canvas on click:
void flower_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
flower_min_x = x;
flower_max_x = x;
@ -310,8 +291,7 @@ void flower_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
// Affect the canvas on release:
void flower_release(magic_api * api, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
/* Don't let flower be too low compared to base: */
@ -331,8 +311,7 @@ void flower_release(magic_api * api, int which ATTRIBUTE_UNUSED,
/* Draw high-quality stalk, and flower: */
flower_drawstalk(api, canvas, x, y, flower_min_x, flower_max_x,
flower_bottom_x, flower_bottom_y, 1);
flower_drawstalk(api, canvas, x, y, flower_min_x, flower_max_x, flower_bottom_x, flower_bottom_y, 1);
flower_drawflower(api, canvas, x, y);
@ -348,12 +327,11 @@ void flower_release(magic_api * api, int which ATTRIBUTE_UNUSED,
}
static void flower_drawflower(magic_api * api ATTRIBUTE_UNUSED,
SDL_Surface * canvas, int x, int y)
static void flower_drawflower(magic_api * api ATTRIBUTE_UNUSED, SDL_Surface * canvas, int x, int y)
{
SDL_Rect dest;
if (flower_petals_colorized == NULL) // Abort!
if (flower_petals_colorized == NULL) // Abort!
return;
dest.x = x - (flower_petals_colorized->w / 2);
@ -362,12 +340,11 @@ static void flower_drawflower(magic_api * api ATTRIBUTE_UNUSED,
SDL_BlitSurface(flower_petals_colorized, NULL, canvas, &dest);
}
static void flower_drawbase(magic_api * api ATTRIBUTE_UNUSED,
SDL_Surface * canvas)
static void flower_drawbase(magic_api * api ATTRIBUTE_UNUSED, SDL_Surface * canvas)
{
SDL_Rect dest;
if (flower_base == NULL) // Abort!
if (flower_base == NULL) // Abort!
return;
dest.x = flower_bottom_x - (flower_base->w / 2);
@ -378,8 +355,7 @@ static void flower_drawbase(magic_api * api ATTRIBUTE_UNUSED,
static void flower_drawstalk(magic_api * api ATTRIBUTE_UNUSED,
SDL_Surface * canvas, int top_x, int top_y,
int minx, int maxx, int bottom_x, int bottom_y,
int final)
int minx, int maxx, int bottom_x, int bottom_y, int final)
{
Point2D control_points[4];
Point2D *curve;
@ -389,7 +365,7 @@ static void flower_drawstalk(magic_api * api ATTRIBUTE_UNUSED,
int xx, yy, side;
if (flower_leaf == NULL) // Abort!
if (flower_leaf == NULL) // Abort!
return;
/* Compute a nice bezier curve for the stalk, based on the
@ -585,7 +561,8 @@ void flower_shutdown(magic_api * api ATTRIBUTE_UNUSED)
// Record the color from Tux Paint:
void flower_set_color(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
flower_r = r;
flower_g = g;
@ -595,8 +572,7 @@ void flower_set_color(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface *
}
// Use colors:
int flower_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int flower_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 1;
}
@ -651,8 +627,7 @@ static Point2D flower_PointOnCubicBezier(Point2D * cp, float t)
<sizeof(Point2D) numberOfPoints>
*/
static void flower_ComputeBezier(Point2D * cp, int numberOfPoints,
Point2D * curve)
static void flower_ComputeBezier(Point2D * cp, int numberOfPoints, Point2D * curve)
{
float dt;
int i;
@ -673,14 +648,12 @@ static void flower_colorize_petals(magic_api * api)
if (flower_petals_colorized != NULL)
SDL_FreeSurface(flower_petals_colorized);
if (flower_petals == NULL) // Abort!
if (flower_petals == NULL) // Abort!
return;
/* Create a surface to render into: */
amask =
~(flower_petals->format->Rmask | flower_petals->format->
Gmask | flower_petals->format->Bmask);
amask = ~(flower_petals->format->Rmask | flower_petals->format->Gmask | flower_petals->format->Bmask);
flower_petals_colorized =
SDL_CreateRGBSurface(SDL_SWSURFACE,
@ -688,8 +661,7 @@ static void flower_colorize_petals(magic_api * api)
flower_petals->h,
flower_petals->format->BitsPerPixel,
flower_petals->format->Rmask,
flower_petals->format->Gmask,
flower_petals->format->Bmask, amask);
flower_petals->format->Gmask, flower_petals->format->Bmask, amask);
/* Render the new petals: */
@ -700,19 +672,14 @@ static void flower_colorize_petals(magic_api * api)
{
for (x = 0; x < flower_petals->w; x++)
{
SDL_GetRGBA(api->getpixel(flower_petals, x, y), flower_petals->format,
&r, &g, &b, &a);
SDL_GetRGBA(api->getpixel(flower_petals, x, y), flower_petals->format, &r, &g, &b, &a);
api->putpixel(flower_petals_colorized, x, y,
SDL_MapRGBA(flower_petals_colorized->format, flower_r,
flower_g, flower_b, a));
SDL_MapRGBA(flower_petals_colorized->format, flower_r, flower_g, flower_b, a));
if (api->in_circle
((x - flower_petals->w / 2), (y - flower_petals->h / 2), (flower_petals->w / 4)))
if (api->in_circle((x - flower_petals->w / 2), (y - flower_petals->h / 2), (flower_petals->w / 4)))
{
api->putpixel(flower_petals_colorized, x, y,
SDL_MapRGBA(flower_petals_colorized->format, 0xFF, 0xFF,
0x00, a));
api->putpixel(flower_petals_colorized, x, y, SDL_MapRGBA(flower_petals_colorized->format, 0xFF, 0xFF, 0x00, a));
}
}
}
@ -722,14 +689,12 @@ static void flower_colorize_petals(magic_api * api)
}
void flower_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void flower_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
@ -748,7 +713,9 @@ Uint8 flower_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_
return DEFAULT_SIZE;
}
void flower_set_size(magic_api * api, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void flower_set_size(magic_api * api, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
int scale, width, height;

View file

@ -45,23 +45,17 @@ Uint32 foam_api_version(void);
int foam_init(magic_api * api, Uint32 disabled_features);
char *foam_get_description(magic_api * api, int which, int mode);
void foam_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
void foam_release_worker(SDL_Surface * canvas, SDL_Surface* last, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void foam_release_worker(SDL_Surface * canvas, SDL_Surface * last, SDL_Rect * update_rect);
void foam_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void foam_click(magic_api * api, int which, int mode, SDL_Surface * canvas,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
SDL_Surface *foam_get_icon(magic_api * api, int which);
char *foam_get_name(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED);
int foam_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED);
void foam_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void foam_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
char *foam_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED);
int foam_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED);
void foam_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void foam_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
void foam_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
void foam_shutdown(magic_api * api);
@ -70,7 +64,8 @@ int foam_modes(magic_api * api, int which);
int foam_requires_colors(magic_api * api, int which);
Uint8 foam_accepted_sizes(magic_api * api, int which, int mode);
Uint8 foam_default_size(magic_api * api, int which, int mode);
void foam_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void foam_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
#define FOAM_PROP 8
#define FOAM_RADIUS 3
@ -87,26 +82,16 @@ int foam_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
char fname[1024];
SDL_Surface *foam_data;
snprintf(fname, sizeof(fname), "%ssounds/magic/foam.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/foam.ogg", api->data_directory);
foam_snd = Mix_LoadWAV(fname);
snprintf(fname, sizeof(fname), "%simages/magic/foam_data.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/foam_data.png", api->data_directory);
foam_data = IMG_Load(fname);
foam_7 =
api->scale(foam_data, ((api->canvas_w / FOAM_PROP) * 4) / 4,
((api->canvas_h / FOAM_PROP) * 4) / 4, 1);
foam_5 =
api->scale(foam_data, ((api->canvas_w / FOAM_PROP) * 3) / 4,
((api->canvas_h / FOAM_PROP) * 3) / 4, 1);
foam_3 =
api->scale(foam_data, ((api->canvas_w / FOAM_PROP) * 2) / 4,
((api->canvas_h / FOAM_PROP) * 2) / 4, 1);
foam_1 =
api->scale(foam_data, ((api->canvas_w / FOAM_PROP) * 1) / 4,
((api->canvas_h / FOAM_PROP) * 1) / 4, 1);
foam_7 = api->scale(foam_data, ((api->canvas_w / FOAM_PROP) * 4) / 4, ((api->canvas_h / FOAM_PROP) * 4) / 4, 1);
foam_5 = api->scale(foam_data, ((api->canvas_w / FOAM_PROP) * 3) / 4, ((api->canvas_h / FOAM_PROP) * 3) / 4, 1);
foam_3 = api->scale(foam_data, ((api->canvas_w / FOAM_PROP) * 2) / 4, ((api->canvas_h / FOAM_PROP) * 2) / 4, 1);
foam_1 = api->scale(foam_data, ((api->canvas_w / FOAM_PROP) * 1) / 4, ((api->canvas_h / FOAM_PROP) * 1) / 4, 1);
SDL_FreeSurface(foam_data);
@ -124,41 +109,33 @@ SDL_Surface *foam_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/foam.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/foam.png", api->data_directory);
return (IMG_Load(fname));
}
// Return our names, localized:
char *foam_get_name(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
char *foam_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (strdup(gettext_noop("Foam")));
}
// Return our groups
int foam_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int foam_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_PAINTING;
}
// Return our descriptions, localized:
char *foam_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED)
char *foam_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 cover an area with foamy bubbles.")));
return (strdup(gettext_noop("Click and drag the mouse to cover an area with foamy bubbles.")));
}
// Do the effect:
static void do_foam(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
{
magic_api *api = (magic_api *) ptr;
int xx, yy, nx, ny;
@ -185,10 +162,9 @@ static void do_foam(void *ptr, int which ATTRIBUTE_UNUSED,
// Affect the canvas on drag:
void foam_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_foam);
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_foam);
foam_release_worker(canvas, last, update_rect);
// foam_release(api, which, canvas, last, x, y, update_rect);
@ -220,8 +196,7 @@ void foam_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void foam_click(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas,
SDL_Surface * last, int x ATTRIBUTE_UNUSED,
int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect)
SDL_Surface * last, int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect)
{
int i;
@ -230,8 +205,8 @@ void foam_click(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
foam_mask_w = canvas->w / FOAM_PROP;
foam_mask_h = canvas->h / FOAM_PROP;
foam_mask = (int *) malloc(sizeof(int) * (foam_mask_w * foam_mask_h));
foam_mask_tmp = (int *) malloc(sizeof(int) * (foam_mask_w * foam_mask_h));
foam_mask = (int *)malloc(sizeof(int) * (foam_mask_w * foam_mask_h));
foam_mask_tmp = (int *)malloc(sizeof(int) * (foam_mask_w * foam_mask_h));
}
for (i = 0; i < foam_mask_w * foam_mask_h; i++)
@ -265,14 +240,13 @@ static int foam_mask_test(int r, int x, int y)
// Affect the canvas on release:
void foam_release(magic_api * api ATTRIBUTE_UNUSED ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
SDL_Surface * last, int x ATTRIBUTE_UNUSED,
int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect)
SDL_Surface * last, int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect)
{
api->stopsound();
foam_release_worker(canvas, last, update_rect);
}
void foam_release_worker(SDL_Surface * canvas, SDL_Surface* last, SDL_Rect * update_rect)
void foam_release_worker(SDL_Surface * canvas, SDL_Surface * last, SDL_Rect * update_rect)
{
int xx, yy;
int changes, max_iters;
@ -282,8 +256,7 @@ void foam_release_worker(SDL_Surface * canvas, SDL_Surface* last, SDL_Rect * upd
SDL_BlitSurface(last, NULL, canvas, NULL);
memcpy(foam_mask_tmp, foam_mask,
(sizeof(int) * (foam_mask_w * foam_mask_h)));
memcpy(foam_mask_tmp, foam_mask, (sizeof(int) * (foam_mask_w * foam_mask_h)));
max_iters = 2;
@ -441,8 +414,7 @@ void foam_release_worker(SDL_Surface * canvas, SDL_Surface* last, SDL_Rect * upd
}
}
memcpy(foam_mask, foam_mask_tmp,
(sizeof(int) * (foam_mask_w * foam_mask_h)));
memcpy(foam_mask, foam_mask_tmp, (sizeof(int) * (foam_mask_w * foam_mask_h)));
update_rect->x = 0;
@ -472,7 +444,8 @@ void foam_shutdown(magic_api * api ATTRIBUTE_UNUSED)
// Record the color from Tux Paint:
void foam_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
foam_r = r;
foam_g = g;
@ -480,21 +453,18 @@ void foam_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED
}
// Use colors:
int foam_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int foam_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 0; /* FIXME: Would be nice to tint the bubbles */
}
void foam_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void foam_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
@ -514,6 +484,8 @@ Uint8 foam_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UN
return 0;
}
void foam_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void foam_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}

View file

@ -30,21 +30,15 @@ SDL_Surface *fold_surface_src, *fold_surface_dst;
void fold_draw(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect);
static void fold_erase(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y);
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
static void fold_erase(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
void translate_coords(SDL_Surface * canvas, int angle);
SDL_Surface *rotate(magic_api * api, SDL_Surface * canvas, int angle);
void fold_draw(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect);
static void fold_print_line(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y);
static void fold_print_dark_line(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y);
void translate_xy(SDL_Surface * canvas, int x, int y, int *a, int *b,
int rotation);
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
static void fold_print_line(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
static void fold_print_dark_line(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
void translate_xy(SDL_Surface * canvas, int x, int y, int *a, int *b, int rotation);
Uint32 fold_api_version(void);
void fold_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
@ -56,30 +50,25 @@ int fold_get_group(magic_api * api, int which);
char *fold_get_description(magic_api * api, int which, int mode);
int fold_requires_colors(magic_api * api, int which);
void fold_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
void fold_shutdown(magic_api * api);
void fold_click(magic_api * ptr, int which, int mode,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
void fold_preview(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
int fold_modes(magic_api * api, int which);
// Housekeeping functions
void fold_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
void fold_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void fold_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
inline Uint8 fold_what_corner(int x, int y, SDL_Surface * canvas);
void fold_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void fold_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
Uint8 fold_accepted_sizes(magic_api * api, int which, int mode);
Uint8 fold_default_size(magic_api * api, int which, int mode);
void fold_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void fold_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
Uint32 fold_api_version(void)
{
@ -87,7 +76,8 @@ Uint32 fold_api_version(void)
}
void fold_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
//get the colors from API and store it in structure
fold_r = r;
@ -99,8 +89,7 @@ int fold_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%ssounds/magic/fold.wav",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/fold.wav", api->data_directory);
fold_snd = Mix_LoadWAV(fname);
return (1);
@ -111,48 +100,37 @@ int fold_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
return 1;
}
SDL_Surface *fold_get_icon(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
SDL_Surface *fold_get_icon(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/fold.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/fold.png", api->data_directory);
return (IMG_Load(fname));
}
char *fold_get_name(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
char *fold_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (gettext_noop("Fold"));
}
int fold_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int fold_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_PICTURE_WARPS;
}
char *fold_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED)
char *fold_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return
strdup(gettext_noop
("Choose a background color and click to turn the corner of the page over."));
return strdup(gettext_noop("Choose a background color and click to turn the corner of the page over."));
}
int fold_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int fold_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 1;
} //selected color will be a "backpage" color
static void fold_shadow(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * temp, int x,
int y)
static void fold_shadow(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * temp, int x, int y)
{
magic_api *api = (magic_api *) ptr;
Uint8 r, g, b, a;
@ -162,14 +140,11 @@ static void fold_shadow(void *ptr, int which ATTRIBUTE_UNUSED,
max(r - 160 + fold_shadow_value * 4,
0),
max(g - 160 + fold_shadow_value * 4,
0),
max(b - 160 + fold_shadow_value * 4,
0), a));
0), max(b - 160 + fold_shadow_value * 4, 0), a));
}
void fold_draw(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
float right_step_x, right_step_y, left_step_x, left_step_y;
float dist_x, dist_y;
@ -180,17 +155,16 @@ void fold_draw(magic_api * api, int which,
temp =
SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h,
canvas->format->BitsPerPixel, canvas->format->Rmask,
canvas->format->Gmask, canvas->format->Bmask,
canvas->format->Amask);
canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
SDL_BlitSurface(canvas, 0, temp, 0);
right_step_x = (float) (x - left_arm_x) / (float) (left_arm_x - fold_ox);
right_step_y = (float) (y - left_arm_y) / (float) (left_arm_x - fold_ox);
left_step_x = (float) (x - right_arm_x) / (float) (right_arm_y - fold_oy);
left_step_y = (float) (y - right_arm_y) / (float) (right_arm_y - fold_oy);
right_step_x = (float)(x - left_arm_x) / (float)(left_arm_x - fold_ox);
right_step_y = (float)(y - left_arm_y) / (float)(left_arm_x - fold_ox);
left_step_x = (float)(x - right_arm_x) / (float)(right_arm_y - fold_oy);
left_step_y = (float)(y - right_arm_y) / (float)(right_arm_y - fold_oy);
left_y = (float) right_arm_y / left_arm_x * (left_arm_x - canvas->w);
right_x = (float) left_arm_x / right_arm_y * (right_arm_y - canvas->h);
left_y = (float)right_arm_y / left_arm_x * (left_arm_x - canvas->w);
right_x = (float)left_arm_x / right_arm_y * (right_arm_y - canvas->h);
for (w = 0; w < canvas->w; w += 0.5)
{
@ -198,8 +172,7 @@ void fold_draw(magic_api * api, int which,
{
dist_x = right_step_x * w + left_step_x * h;
dist_y = right_step_y * w + left_step_y * h;
api->putpixel(canvas, x - dist_x, y - dist_y,
api->getpixel(temp, w, h));
api->putpixel(canvas, x - dist_x, y - dist_y, api->getpixel(temp, w, h));
}
}
@ -208,71 +181,58 @@ void fold_draw(magic_api * api, int which,
if (left_arm_x > canvas->w)
{
for (h = 0; h <= right_arm_y; h++)
api->line((void *) api, which, canvas, snapshot, canvas->w, left_y - h,
-1, right_arm_y - h, 1, fold_erase);
api->line((void *)api, which, canvas, snapshot, canvas->w, left_y - h, -1, right_arm_y - h, 1, fold_erase);
}
else if (right_arm_y > canvas->h)
{
for (w = 0; w <= left_arm_x; w++)
api->line((void *) api, which, canvas, snapshot, left_arm_x - w, 0,
right_x - w, canvas->h + 1, 1, fold_erase);
api->line((void *)api, which, canvas, snapshot, left_arm_x - w, 0, right_x - w, canvas->h + 1, 1, fold_erase);
}
else
for (w = 0; w <= min(left_arm_x, right_arm_y); w++) // The -1 values are because api->line
api->line((void *) api, which, canvas, snapshot, left_arm_x - w, 0, -1,
right_arm_y - w, 1, fold_erase);
api->line((void *)api, which, canvas, snapshot, left_arm_x - w, 0, -1, right_arm_y - w, 1, fold_erase);
SDL_BlitSurface(canvas, 0, temp, 0);
// Shadows
if (left_arm_x > canvas->w)
{
for (fold_shadow_value = 0; fold_shadow_value < 40;
fold_shadow_value += 1)
api->line((void *) api, which, canvas, temp, canvas->w,
left_y - fold_shadow_value, 0,
right_arm_y - fold_shadow_value, 1, fold_shadow);
for (fold_shadow_value = 0; fold_shadow_value < 40; fold_shadow_value += 1)
api->line((void *)api, which, canvas, temp, canvas->w,
left_y - fold_shadow_value, 0, right_arm_y - fold_shadow_value, 1, fold_shadow);
}
else if (right_arm_y > canvas->h)
{
for (fold_shadow_value = 0; fold_shadow_value < 40;
fold_shadow_value += 1)
api->line((void *) api, which, canvas, temp,
left_arm_x - fold_shadow_value, 0,
right_x - fold_shadow_value, canvas->h, 1, fold_shadow);
for (fold_shadow_value = 0; fold_shadow_value < 40; fold_shadow_value += 1)
api->line((void *)api, which, canvas, temp,
left_arm_x - fold_shadow_value, 0, right_x - fold_shadow_value, canvas->h, 1, fold_shadow);
}
else
for (fold_shadow_value = 0; fold_shadow_value < 40;
fold_shadow_value += 1)
api->line((void *) api, which, canvas, temp,
left_arm_x - fold_shadow_value, 0, 0,
right_arm_y - fold_shadow_value, 1, fold_shadow);
for (fold_shadow_value = 0; fold_shadow_value < 40; fold_shadow_value += 1)
api->line((void *)api, which, canvas, temp,
left_arm_x - fold_shadow_value, 0, 0, right_arm_y - fold_shadow_value, 1, fold_shadow);
SDL_BlitSurface(canvas, 0, temp, 0);
for (fold_shadow_value = 0; fold_shadow_value < 40; fold_shadow_value += 1)
{
if (fold_shadow_value * left_step_x > x
|| fold_shadow_value * right_step_y > y)
if (fold_shadow_value * left_step_x > x || fold_shadow_value * right_step_y > y)
break;
dist_x = fold_shadow_value * (right_step_x + left_step_x);
dist_y = fold_shadow_value * (right_step_y + left_step_y);
api->line((void *) api, which, canvas, temp,
api->line((void *)api, which, canvas, temp,
left_arm_x + fold_shadow_value * right_step_x,
fold_shadow_value * right_step_y,
fold_shadow_value * left_step_x,
right_arm_y + fold_shadow_value * left_step_y, 1, fold_shadow);
fold_shadow_value * left_step_x, right_arm_y + fold_shadow_value * left_step_y, 1, fold_shadow);
}
api->line((void *) api, which, canvas, snapshot, x, y, right_arm_x,
right_arm_y, 1, fold_print_line);
api->line((void *) api, which, canvas, snapshot, x, y, left_arm_x,
left_arm_y, 1, fold_print_line);
api->line((void *) api, which, canvas, snapshot, left_arm_x, left_arm_y,
api->line((void *)api, which, canvas, snapshot, x, y, right_arm_x, right_arm_y, 1, fold_print_line);
api->line((void *)api, which, canvas, snapshot, x, y, left_arm_x, left_arm_y, 1, fold_print_line);
api->line((void *)api, which, canvas, snapshot, left_arm_x, left_arm_y,
right_arm_x, right_arm_y, 1, fold_print_dark_line);
}
@ -287,14 +247,12 @@ SDL_Surface *rotate(magic_api * api, SDL_Surface * canvas, int angle)
temp =
SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h,
canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask,
canvas->format->Bmask, canvas->format->Amask);
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
else
temp =
SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->h, canvas->w,
canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask,
canvas->format->Bmask, canvas->format->Amask);
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
switch (angle)
{
@ -361,8 +319,7 @@ void translate_coords(SDL_Surface * canvas, int angle)
}
}
void translate_xy(SDL_Surface * canvas, int x, int y, int *a, int *b,
int rotation)
void translate_xy(SDL_Surface * canvas, int x, int y, int *a, int *b, int rotation)
{
switch (rotation)
{
@ -382,8 +339,7 @@ void translate_xy(SDL_Surface * canvas, int x, int y, int *a, int *b,
}
void fold_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
{
int a, b;
SDL_Surface *temp, *temp2;
@ -467,8 +423,7 @@ inline Uint8 fold_what_corner(int x, int y, SDL_Surface * canvas)
static void fold_print_line(void *ptr, int which ATTRIBUTE_UNUSED,
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;
@ -476,9 +431,7 @@ static void fold_print_line(void *ptr, int which ATTRIBUTE_UNUSED,
}
static void fold_print_dark_line(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)
{
magic_api *api = (magic_api *) ptr;
@ -486,18 +439,15 @@ static void fold_print_dark_line(void *ptr, int which ATTRIBUTE_UNUSED,
}
static void fold_erase(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)
{
magic_api *api = (magic_api *) ptr;
api->putpixel(canvas, x, y,
SDL_MapRGB(canvas->format, fold_r, fold_g, fold_b));
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, fold_r, fold_g, fold_b));
}
void fold_click(magic_api * ptr, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
{
magic_api *api = (magic_api *) ptr;
@ -527,8 +477,7 @@ void fold_click(magic_api * ptr, int which, int mode ATTRIBUTE_UNUSED,
void fold_preview(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox ATTRIBUTE_UNUSED,
int oy ATTRIBUTE_UNUSED, int x, int y,
SDL_Rect * update_rect)
int oy ATTRIBUTE_UNUSED, int x, int y, SDL_Rect * update_rect)
{
int middle_point_x;
int middle_point_y;
@ -543,67 +492,49 @@ void fold_preview(magic_api * api, int which, SDL_Surface * canvas,
switch (corner)
{
case 1: //Right Upper
right_arm_x =
fold_ox - (fold_ox - middle_point_x) -
middle_point_y * middle_point_y / (fold_ox - middle_point_x);
right_arm_x = fold_ox - (fold_ox - middle_point_x) - middle_point_y * middle_point_y / (fold_ox - middle_point_x);
right_arm_y = fold_oy;
left_arm_x = fold_ox;
left_arm_y =
fold_oy - (fold_oy - middle_point_y) - (fold_ox -
middle_point_x) * (fold_ox -
middle_point_x)
/ (fold_oy - middle_point_y);
middle_point_x) * (fold_ox - middle_point_x) / (fold_oy - middle_point_y);
break;
case 2: //LU
right_arm_x = fold_ox;
right_arm_y =
middle_point_y + middle_point_x * middle_point_x / middle_point_y;
right_arm_y = middle_point_y + middle_point_x * middle_point_x / middle_point_y;
left_arm_x =
middle_point_x + middle_point_y * middle_point_y / middle_point_x;
left_arm_x = middle_point_x + middle_point_y * middle_point_y / middle_point_x;
left_arm_y = fold_oy;
break;
case 3: //LL
right_arm_x =
middle_point_x + (fold_oy - middle_point_y) * (fold_oy -
middle_point_y) /
middle_point_x;
right_arm_x = middle_point_x + (fold_oy - middle_point_y) * (fold_oy - middle_point_y) / middle_point_x;
right_arm_y = fold_oy;
left_arm_x = fold_ox;
left_arm_y =
fold_oy - (fold_oy - middle_point_y) - (fold_ox -
middle_point_x) * (fold_ox -
middle_point_x)
/ (fold_oy - middle_point_y);
middle_point_x) * (fold_ox - middle_point_x) / (fold_oy - middle_point_y);
break;
case 4: //RL
right_arm_x = fold_ox;
right_arm_y =
fold_oy - (fold_oy - middle_point_y) - (fold_ox -
middle_point_x) * (fold_ox -
middle_point_x)
/ (fold_oy - middle_point_y);
middle_point_x) * (fold_ox - middle_point_x) / (fold_oy - middle_point_y);
left_arm_x =
fold_ox - (fold_ox - middle_point_x) - (fold_oy -
middle_point_y) * (fold_oy -
middle_point_y)
/ (fold_ox - middle_point_x);
middle_point_y) * (fold_oy - middle_point_y) / (fold_ox - middle_point_x);
left_arm_y = fold_oy;
break;
}
api->line((void *) api, which, canvas, snapshot, x, y, right_arm_x,
right_arm_y, 1, fold_print_line);
api->line((void *) api, which, canvas, snapshot, x, y, left_arm_x,
left_arm_y, 1, fold_print_line);
api->line((void *) api, which, canvas, snapshot, left_arm_x, left_arm_y,
right_arm_x, right_arm_y, 1, fold_print_line);
api->line((void *)api, which, canvas, snapshot, x, y, right_arm_x, right_arm_y, 1, fold_print_line);
api->line((void *)api, which, canvas, snapshot, x, y, left_arm_x, left_arm_y, 1, fold_print_line);
api->line((void *)api, which, canvas, snapshot, left_arm_x, left_arm_y, right_arm_x, right_arm_y, 1, fold_print_line);
update_rect->x = update_rect->y = 0;
update_rect->w = canvas->w;
@ -611,8 +542,7 @@ void fold_preview(magic_api * api, int which, SDL_Surface * canvas,
}
void fold_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
// Avoid division by zero when calculating the preview
x = clamp(2, x, canvas->w - 2);
@ -621,14 +551,12 @@ void fold_drag(magic_api * api, int which, SDL_Surface * canvas,
}
void fold_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void fold_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
@ -648,6 +576,8 @@ Uint8 fold_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UN
return 0;
}
void fold_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void fold_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}

View file

@ -49,8 +49,7 @@ static unsigned int fretwork_update_rectangle_width; //the width of the updat
static unsigned int fretwork_update_rectangle_height; //the height of the update_rectangle
static SDL_Rect modification_rect;
static SDL_Surface *canvas_backup;
static SDL_Surface *fretwork_one_back, *fretwork_three_back,
*fretwork_four_back, *fretwork_corner_back;
static SDL_Surface *fretwork_one_back, *fretwork_three_back, *fretwork_four_back, *fretwork_corner_back;
// Housekeeping functions
@ -59,8 +58,7 @@ Uint32 fretwork_api_version(void);
int fretwork_modes(magic_api * api, int which);
void fretwork_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
static void fretwork_colorize(magic_api * api, SDL_Surface * dest,
SDL_Surface * src);
static void fretwork_colorize(magic_api * api, SDL_Surface * dest, SDL_Surface * src);
int fretwork_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED);
int fretwork_get_tool_count(magic_api * api);
SDL_Surface *fretwork_get_icon(magic_api * api, int which);
@ -69,32 +67,26 @@ int fretwork_get_group(magic_api * api, int which);
char *fretwork_get_description(magic_api * api, int which, int mode);
int fretwork_requires_colors(magic_api * api, int which);
void fretwork_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, int x,
int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
void fretwork_shutdown(magic_api * api);
void fretwork_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * snapshot);
void fretwork_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * snapshot);
void fretwork_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * snapshot);
void fretwork_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * snapshot);
#define POINT_TYPE typeof(((SDL_Rect *)NULL)->x)
inline void fretwork_extract_coords_from_segment(unsigned int segment,
POINT_TYPE * x,
POINT_TYPE * y);
inline void fretwork_extract_coords_from_segment(unsigned int segment, POINT_TYPE * x, POINT_TYPE * y);
void fretwork_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * snapshot, int x,
int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
void fretwork_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
static void fretwork_draw_wrapper(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y);
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
static void fretwork_draw_wrapper(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
inline unsigned int fretwork_get_segment(int x, int y);
Uint8 fretwork_accepted_sizes(magic_api * api, int which, int mode);
Uint8 fretwork_default_size(magic_api * api, int which, int mode);
void fretwork_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void fretwork_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
SDL_Surface *fretwork_one, *fretwork_three, *fretwork_four, *fretwork_corner;
@ -104,14 +96,14 @@ Uint32 fretwork_api_version(void)
return (TP_MAGIC_API_VERSION);
}
int fretwork_modes(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int fretwork_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (MODE_PAINT | MODE_FULLSCREEN);
}
void fretwork_set_color(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
fretwork_r = r;
fretwork_g = g;
@ -123,8 +115,7 @@ void fretwork_set_color(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface
}
/* Adapted from flower.c */
static void fretwork_colorize(magic_api * api, SDL_Surface * dest,
SDL_Surface * src)
static void fretwork_colorize(magic_api * api, SDL_Surface * dest, SDL_Surface * src)
{
int x, y;
Uint8 r, g, b, a;
@ -138,9 +129,7 @@ static void fretwork_colorize(magic_api * api, SDL_Surface * dest,
{
SDL_GetRGBA(api->getpixel(src, x, y), src->format, &r, &g, &b, &a);
api->putpixel(dest, x, y,
SDL_MapRGBA(dest->format, fretwork_r, fretwork_g,
fretwork_b, a));
api->putpixel(dest, x, y, SDL_MapRGBA(dest->format, fretwork_r, fretwork_g, fretwork_b, a));
}
}
@ -154,19 +143,15 @@ int fretwork_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
char fname[1024];
Uint8 i; //is always < 4, so Uint8 seems to be a good idea
fretwork_images = (char **) malloc(sizeof(char *) * 4);
fretwork_images = (char **)malloc(sizeof(char *) * 4);
for (i = 0; i < 4; i++)
fretwork_images[i] = (char *) malloc(sizeof(char) * 1024);
fretwork_images[i] = (char *)malloc(sizeof(char) * 1024);
snprintf(fretwork_images[0], 1024 * sizeof(char),
"%simages/magic/fretwork_one.png", api->data_directory);
snprintf(fretwork_images[1], 1024 * sizeof(char),
"%simages/magic/fretwork_three.png", api->data_directory);
snprintf(fretwork_images[2], 1024 * sizeof(char),
"%simages/magic/fretwork_four.png", api->data_directory);
snprintf(fretwork_images[3], 1024 * sizeof(char),
"%simages/magic/fretwork_corner.png", api->data_directory);
snprintf(fretwork_images[0], 1024 * sizeof(char), "%simages/magic/fretwork_one.png", api->data_directory);
snprintf(fretwork_images[1], 1024 * sizeof(char), "%simages/magic/fretwork_three.png", api->data_directory);
snprintf(fretwork_images[2], 1024 * sizeof(char), "%simages/magic/fretwork_four.png", api->data_directory);
snprintf(fretwork_images[3], 1024 * sizeof(char), "%simages/magic/fretwork_corner.png", api->data_directory);
fretwork_one = IMG_Load(fretwork_images[0]);
fretwork_three = IMG_Load(fretwork_images[1]);
@ -180,8 +165,7 @@ int fretwork_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
img_w = fretwork_one->w;
img_h = fretwork_one->h;
snprintf(fname, sizeof(fname), "%ssounds/magic/fretwork.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/fretwork.ogg", api->data_directory);
fretwork_snd = Mix_LoadWAV(fname);
return (1);
@ -196,38 +180,30 @@ SDL_Surface *fretwork_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/fretwork.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/fretwork.png", api->data_directory);
return (IMG_Load(fname));
}
int fretwork_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int fretwork_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_PAINTING;
}
char *fretwork_get_name(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
char *fretwork_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return strdup(gettext_noop("Fretwork"));
}
char *fretwork_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode)
char *fretwork_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode)
{
if (mode == MODE_PAINT)
return
strdup(gettext_noop("Click and drag to draw repetitive patterns."));
return strdup(gettext_noop("Click and drag to draw repetitive patterns."));
else
return
strdup(gettext_noop
("Click to surround your picture with repetitive patterns."));
return strdup(gettext_noop("Click to surround your picture with repetitive patterns."));
}
int fretwork_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int fretwork_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 1;
}
@ -236,8 +212,7 @@ void fretwork_release(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * snapshot 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)
{
}
@ -266,16 +241,14 @@ void fretwork_shutdown(magic_api * api ATTRIBUTE_UNUSED)
void fretwork_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas,
SDL_Surface * snapshot ATTRIBUTE_UNUSED)
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED)
{
//we've to compute the quantity of segments in each direction
canvas_backup =
SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h,
canvas->format->BitsPerPixel, canvas->format->Rmask,
canvas->format->Gmask, canvas->format->Bmask,
canvas->format->Amask);
canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
SDL_BlitSurface(canvas, NULL, canvas_backup, NULL);
fretwork_segments_x = fretwork_math_ceil(canvas->w, img_w);
@ -287,8 +260,7 @@ void fretwork_switchin(magic_api * api ATTRIBUTE_UNUSED,
void fretwork_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * snapshot ATTRIBUTE_UNUSED)
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * snapshot ATTRIBUTE_UNUSED)
{
free(fretwork_status_of_segments);
fretwork_status_of_segments = NULL;
@ -301,7 +273,7 @@ inline int fretwork_math_ceil(int x, int y)
{
int temp;
temp = (int) x / y;
temp = (int)x / y;
if (x % y)
return temp + 1;
else
@ -320,12 +292,10 @@ inline unsigned int fretwork_get_segment(int x, int y)
return (yy - 1) * fretwork_segments_x + xx;
}
inline void fretwork_extract_coords_from_segment(unsigned int segment,
POINT_TYPE * x,
POINT_TYPE * y)
inline void fretwork_extract_coords_from_segment(unsigned int segment, POINT_TYPE * x, POINT_TYPE * y)
{
*x = ((segment % fretwork_segments_x) - 1) * img_w; //useful to set update_rect as small as possible
*y = (int) (segment / fretwork_segments_x) * img_h;
*y = (int)(segment / fretwork_segments_x) * img_h;
}
/* static void fretwork_flip(void * ptr, SDL_Surface * dest, SDL_Surface * src) */
@ -339,20 +309,17 @@ inline void fretwork_extract_coords_from_segment(unsigned int segment,
/* api->putpixel(dest, x, y, api->getpixel(src, x, src->h-y)); */
/* } */
static void fretwork_flip_flop(void *ptr, SDL_Surface * dest,
SDL_Surface * src)
static void fretwork_flip_flop(void *ptr, SDL_Surface * dest, SDL_Surface * src)
{
magic_api *api = (magic_api *) ptr;
POINT_TYPE x, y;
for (x = 0; x < dest->w; x++)
for (y = 0; y < dest->h; y++)
api->putpixel(dest, dest->w - 1 - x, dest->h - 1 - y,
api->getpixel(src, x, y));
api->putpixel(dest, dest->w - 1 - x, dest->h - 1 - y, api->getpixel(src, x, y));
}
static void fretwork_rotate(void *ptr, SDL_Surface * dest, SDL_Surface * src,
_Bool direction)
static void fretwork_rotate(void *ptr, SDL_Surface * dest, SDL_Surface * src, _Bool direction)
//src and dest must have same size
{
magic_api *api = (magic_api *) ptr;
@ -375,8 +342,7 @@ static void fretwork_rotate(void *ptr, SDL_Surface * dest, SDL_Surface * src,
void fretwork_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * snapshot, int x,
int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
{
int left_x, right_x, top_y, bottom_y;
@ -388,29 +354,26 @@ void fretwork_click(magic_api * api, int which, int mode,
}
else
{
if (fretwork_full_runs <=
min(fretwork_segments_x, fretwork_segments_y) / 2)
if (fretwork_full_runs <= min(fretwork_segments_x, fretwork_segments_y) / 2)
{
left_x = img_w * fretwork_full_runs;
right_x = img_w * fretwork_segments_x - img_w * fretwork_full_runs;
top_y = img_h * fretwork_full_runs;
bottom_y =
img_h * fretwork_segments_y - img_h * (fretwork_full_runs - 1);
bottom_y = img_h * fretwork_segments_y - img_h * (fretwork_full_runs - 1);
//left line
api->line((void *) api, which, canvas, snapshot, left_x, top_y, left_x,
api->line((void *)api, which, canvas, snapshot, left_x, top_y, left_x,
bottom_y, img_w / 2, fretwork_draw_wrapper);
//top line
api->line((void *) api, which, canvas, snapshot, left_x, top_y, right_x,
top_y, img_w / 2, fretwork_draw_wrapper);
api->line((void *)api, which, canvas, snapshot, left_x, top_y, right_x, top_y, img_w / 2, fretwork_draw_wrapper);
//bottom line
api->line((void *) api, which, canvas, snapshot, left_x, bottom_y,
api->line((void *)api, which, canvas, snapshot, left_x, bottom_y,
right_x, bottom_y, img_w / 2, fretwork_draw_wrapper);
//right line
api->line((void *) api, which, canvas, snapshot, right_x, top_y,
api->line((void *)api, which, canvas, snapshot, right_x, top_y,
right_x, bottom_y, img_w / 2, fretwork_draw_wrapper);
fretwork_full_runs += 1;
@ -427,8 +390,7 @@ static Uint8 fretwork_select_image(Uint16 segment)
int take_up, take_down;
int val_up, val_down, val_left, val_right;
int from_top = 0, from_bottom = 0, from_left = 0, from_right = 0;
int from_top_right = 0, from_top_left = 0, from_bottom_right =
0, from_bottom_left = 0;
int from_top_right = 0, from_top_left = 0, from_bottom_right = 0, from_bottom_left = 0;
int TOP = 0, BOTTOM = 0, LEFT = 0, RIGHT = 0;
//Checking from were we come...
@ -445,26 +407,22 @@ static Uint8 fretwork_select_image(Uint16 segment)
// Very very few cases will reach this, segments are joining by the corner
// We need to add a new segment to join by side, adding clockwise
else if (segment ==
fretwork_segment_modified_last + fretwork_segments_x + 1)
else if (segment == fretwork_segment_modified_last + fretwork_segments_x + 1)
{
from_top_left = 1;
fretwork_segment_to_add = segment - fretwork_segments_x;
}
else if (segment ==
fretwork_segment_modified_last + fretwork_segments_x - 1)
else if (segment == fretwork_segment_modified_last + fretwork_segments_x - 1)
{
from_top_right = 1;
fretwork_segment_to_add = segment + 1;
}
else if (segment ==
fretwork_segment_modified_last - fretwork_segments_x - 1)
else if (segment == fretwork_segment_modified_last - fretwork_segments_x - 1)
{
from_bottom_right = 1;
fretwork_segment_to_add = segment + fretwork_segments_x;
}
else if (segment ==
fretwork_segment_modified_last - fretwork_segments_x + 1)
else if (segment == fretwork_segment_modified_last - fretwork_segments_x + 1)
{
from_bottom_left = 1;
fretwork_segment_to_add = segment - 1;
@ -478,7 +436,7 @@ static Uint8 fretwork_select_image(Uint16 segment)
val_up = fretwork_status_of_segments[take_up];
take_down = segment + fretwork_segments_x;
if (take_down > (signed) (fretwork_segments_x * fretwork_segments_y))
if (take_down > (signed)(fretwork_segments_x * fretwork_segments_y))
val_down = SEG_NONE;
else
val_down = fretwork_status_of_segments[take_down];
@ -536,8 +494,7 @@ static Uint8 fretwork_select_image(Uint16 segment)
static void fretwork_draw(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas,
SDL_Surface * last ATTRIBUTE_UNUSED, int x,
int y ATTRIBUTE_UNUSED, unsigned int segment)
SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y ATTRIBUTE_UNUSED, unsigned int segment)
{
magic_api *api = (magic_api *) ptr;
SDL_Surface *result, *temp;
@ -547,8 +504,7 @@ static void fretwork_draw(void *ptr, int which ATTRIBUTE_UNUSED,
use_temp = 0;
if ((segment < 1) | (segment > fretwork_segments_x * fretwork_segments_y))
return;
fretwork_extract_coords_from_segment(segment, &modification_rect.x,
&modification_rect.y);
fretwork_extract_coords_from_segment(segment, &modification_rect.x, &modification_rect.y);
modification_rect.h = img_w;
modification_rect.w = img_h;
@ -563,17 +519,13 @@ static void fretwork_draw(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_CreateRGBSurface(SDL_SWSURFACE, img_w, img_h,
fretwork_one->format->BitsPerPixel,
fretwork_one->format->Rmask,
fretwork_one->format->Gmask,
fretwork_one->format->Bmask,
fretwork_one->format->Amask);
fretwork_one->format->Gmask, fretwork_one->format->Bmask, fretwork_one->format->Amask);
temp =
SDL_CreateRGBSurface(SDL_SWSURFACE, img_w, img_h,
fretwork_one->format->BitsPerPixel,
fretwork_one->format->Rmask,
fretwork_one->format->Gmask,
fretwork_one->format->Bmask,
fretwork_one->format->Amask);
fretwork_one->format->Gmask, fretwork_one->format->Bmask, fretwork_one->format->Amask);
SDL_BlitSurface(canvas_backup, &modification_rect, result, NULL);
@ -645,32 +597,25 @@ static void fretwork_draw(void *ptr, int which ATTRIBUTE_UNUSED,
}
static void fretwork_draw_wrapper(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y)
static void fretwork_draw_wrapper(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
fretwork_segment_modified = fretwork_get_segment(x, y);
fretwork_draw((void *) ptr, which, canvas, last, x, y,
fretwork_segment_modified);
fretwork_draw((void *)ptr, which, canvas, last, x, y, fretwork_segment_modified);
if (fretwork_segment_modified_last > 0)
{
fretwork_draw((void *) ptr, which, canvas, last, x, y,
fretwork_segment_modified_last);
fretwork_extract_coords_from_segment(fretwork_segment_start_rectangle,
&modification_rect.x,
&modification_rect.y);
fretwork_draw((void *)ptr, which, canvas, last, x, y, fretwork_segment_modified_last);
fretwork_extract_coords_from_segment(fretwork_segment_start_rectangle, &modification_rect.x, &modification_rect.y);
modification_rect.w = fretwork_update_rectangle_width * img_w;
modification_rect.h = fretwork_update_rectangle_height * img_h;
}
if (fretwork_segment_to_add > 0)
{
fretwork_draw((void *) ptr, which, canvas, last, x, y,
fretwork_segment_to_add);
fretwork_draw((void *) ptr, which, canvas, last, x, y,
fretwork_segment_modified_last);
fretwork_draw((void *)ptr, which, canvas, last, x, y, fretwork_segment_to_add);
fretwork_draw((void *)ptr, which, canvas, last, x, y, fretwork_segment_modified_last);
fretwork_segment_to_add = 0;
}
@ -678,17 +623,14 @@ static void fretwork_draw_wrapper(void *ptr, int which, SDL_Surface * canvas,
}
void fretwork_drag(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, int ox,
int oy, int x, int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
int start_x, end_x, start_y, end_y, segment_start, segment_end, w, h;
if ((x < canvas->w) && (y < canvas->h) && (ox < canvas->w)
&& (oy < canvas->h) && ((signed) x > 0) && ((signed) y > 0)
&& ((signed) ox > 0) && ((signed) oy > 0))
&& (oy < canvas->h) && ((signed)x > 0) && ((signed)y > 0) && ((signed)ox > 0) && ((signed)oy > 0))
{
api->line((void *) api, which, canvas, snapshot, ox, oy, x, y, img_w / 2,
fretwork_draw_wrapper);
api->line((void *)api, which, canvas, snapshot, ox, oy, x, y, img_w / 2, fretwork_draw_wrapper);
// This should be improved, maybe passed to fretwork_draw()
start_x = min(ox, x);
end_x = max(ox, x);
@ -698,9 +640,9 @@ void fretwork_drag(magic_api * api, int which,
segment_end = fretwork_get_segment(end_x + img_w, end_y + img_h);
x = ((segment_start % fretwork_segments_x) - 1) * img_w;
y = (int) (segment_start / fretwork_segments_x) * img_h;
y = (int)(segment_start / fretwork_segments_x) * img_h;
w = ((segment_end % fretwork_segments_x) - 1) * img_w - x + img_w;
h = (int) (segment_end / fretwork_segments_x) * img_h - y + img_h;
h = (int)(segment_end / fretwork_segments_x) * img_h - y + img_h;
update_rect->x = x;
update_rect->y = y;
@ -719,6 +661,8 @@ Uint8 fretwork_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUT
return 0;
}
void fretwork_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void fretwork_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}

View file

@ -48,29 +48,24 @@ SDL_Surface *glasstile_get_icon(magic_api * api, int which);
char *glasstile_get_name(magic_api * api, int which);
int glasstile_get_group(magic_api * api, int which);
char *glasstile_get_description(magic_api * api, int which, int mode);
static void do_glasstile(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y);
static void do_glasstile(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
void glasstile_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void glasstile_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void glasstile_release(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void glasstile_shutdown(magic_api * api);
void glasstile_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
int glasstile_requires_colors(magic_api * api, int which);
void glasstile_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void glasstile_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void glasstile_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void glasstile_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int glasstile_modes(magic_api * api, int which);
Uint8 glasstile_accepted_sizes(magic_api * api, int which, int mode);
Uint8 glasstile_default_size(magic_api * api, int which, int mode);
void glasstile_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void glasstile_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
Uint32 glasstile_api_version(void)
@ -87,8 +82,7 @@ int glasstile_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%ssounds/magic/glasstile.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/glasstile.ogg", api->data_directory);
glasstile_snd = Mix_LoadWAV(fname);
glasstile_hit = NULL;
@ -108,45 +102,35 @@ SDL_Surface *glasstile_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/glasstile.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/glasstile.png", api->data_directory);
return (IMG_Load(fname));
}
// Return our names, localized:
char *glasstile_get_name(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
char *glasstile_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (strdup(gettext_noop("Glass Tile")));
}
// Return our groups
int glasstile_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int glasstile_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_DISTORTS;
}
// Return our descriptions, localized:
char *glasstile_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode)
char *glasstile_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode)
{
if (mode == MODE_PAINT)
return (strdup
(gettext_noop
("Click and drag the mouse to put glass tile over your picture.")));
return (strdup(gettext_noop("Click and drag the mouse to put glass tile over your picture.")));
else
return (strdup
(gettext_noop
("Click to cover your entire picture in glass tiles.")));
return (strdup(gettext_noop("Click to cover your entire picture in glass tiles.")));
}
// Do the effect:
static void do_glasstile(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, int x,
int y)
static void do_glasstile(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
magic_api *api = (magic_api *) ptr;
int xx, yy, xl, xr, yt, yb;
@ -180,14 +164,10 @@ static void do_glasstile(void *ptr, int which ATTRIBUTE_UNUSED,
{
for (xx = -GT_SIZE; xx < GT_SIZE; xx = xx + 2)
{
SDL_GetRGB(api->getpixel(last, x + xx, y + yy), last->format, &r1, &g1,
&b1);
SDL_GetRGB(api->getpixel(last, x + xx + 1, y + yy), last->format, &r2,
&g2, &b2);
SDL_GetRGB(api->getpixel(last, x + xx, y + yy + 1), last->format, &r3,
&g3, &b3);
SDL_GetRGB(api->getpixel(last, x + xx + 1, y + yy + 1), last->format,
&r4, &g4, &b4);
SDL_GetRGB(api->getpixel(last, x + xx, y + yy), last->format, &r1, &g1, &b1);
SDL_GetRGB(api->getpixel(last, x + xx + 1, y + yy), last->format, &r2, &g2, &b2);
SDL_GetRGB(api->getpixel(last, x + xx, y + yy + 1), last->format, &r3, &g3, &b3);
SDL_GetRGB(api->getpixel(last, x + xx + 1, y + yy + 1), last->format, &r4, &g4, &b4);
r = (r1 + r2 + r3 + r4) >> 2;
g = (g1 + g2 + g3 + g4) >> 2;
@ -233,10 +213,9 @@ static void do_glasstile(void *ptr, int which ATTRIBUTE_UNUSED,
// Affect the canvas on drag:
void glasstile_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_glasstile);
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_glasstile);
update_rect->x = 0;
update_rect->y = 0;
@ -269,8 +248,7 @@ void glasstile_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void glasstile_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
int xx, yy;
@ -279,10 +257,10 @@ void glasstile_click(magic_api * api, int which, int mode,
glasstile_hit_ysize = (canvas->h / GT_SIZE) + 1;
glasstile_hit_xsize = (canvas->w / GT_SIZE) + 1;
glasstile_hit = (int * *) malloc(sizeof(int *) * glasstile_hit_ysize);
glasstile_hit = (int * *)malloc(sizeof(int *) * glasstile_hit_ysize);
for (yy = 0; yy < glasstile_hit_ysize; yy++)
glasstile_hit[yy] = (int *) malloc(sizeof(int) * glasstile_hit_xsize);
glasstile_hit[yy] = (int *)malloc(sizeof(int) * glasstile_hit_xsize);
}
for (yy = 0; yy < glasstile_hit_ysize; yy++)
@ -311,8 +289,7 @@ void glasstile_release(magic_api * api ATTRIBUTE_UNUSED,
int which 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)
{
}
@ -336,33 +313,30 @@ void glasstile_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void glasstile_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void glasstile_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
// Use colors:
int glasstile_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int glasstile_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 0;
}
void glasstile_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void glasstile_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int glasstile_modes(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int glasstile_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (MODE_PAINT | MODE_FULLSCREEN);
}
@ -379,6 +353,8 @@ Uint8 glasstile_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBU
return 0;
}
void glasstile_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void glasstile_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}

View file

@ -19,12 +19,14 @@
#define NUM_SIZES 2
int sizes[NUM_SIZES] = { 100, 50 };
char * googlyeyes_descr[NUM_SIZES] = {
char *googlyeyes_descr[NUM_SIZES] = {
gettext_noop("Click to place a large googly eye, then drag and release to make it look that direction."),
gettext_noop("Click to place a small googly eye, then drag and release to make it look that direction."),
};
char * img_filenames[NUM_SIZES] = {
"googlyeyes.png", // Also used with magic sizes
char *img_filenames[NUM_SIZES] = {
"googlyeyes.png", // Also used with magic sizes
"googlyeyes-sm.png"
};
@ -34,9 +36,9 @@ int googlyeyes_limited = 0;
int googlyeyes_sizes;
int googlyeyes_size;
Mix_Chunk *snd_effect = NULL;
SDL_Surface * * googlyeyes_img_bkgd = NULL;
SDL_Surface * * googlyeyes_img_pupil = NULL;
SDL_Surface * * googlyeyes_img_reflection = NULL;
SDL_Surface **googlyeyes_img_bkgd = NULL;
SDL_Surface **googlyeyes_img_pupil = NULL;
SDL_Surface **googlyeyes_img_reflection = NULL;
int eye_x, eye_y;
Uint32 googlyeyes_api_version(void);
@ -48,27 +50,22 @@ int googlyeyes_get_group(magic_api * api, int which);
char *googlyeyes_get_description(magic_api * api, int which, int mode);
int googlyeyes_requires_colors(magic_api * api, int which);
int googlyeyes_modes(magic_api * api, int which);
Uint8 googlyeyes_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED);
Uint8 googlyeyes_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED);
Uint8 googlyeyes_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED);
void googlyeyes_shutdown(magic_api * api);
void googlyeyes_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * snapshot, int x,
int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
void googlyeyes_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
void googlyeyes_set_size(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
Uint8 sz, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, Uint8 sz, SDL_Rect * update_rect);
void googlyeyes_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void googlyeyes_release(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect);
void googlyeyes_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void googlyeyes_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
void googlyeyes_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void googlyeyes_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
Uint32 googlyeyes_api_version(void)
@ -84,30 +81,32 @@ int googlyeyes_init(magic_api * api, Uint32 disabled_features)
googlyeyes_limited = (disabled_features & MAGIC_FEATURE_SIZE);
/* Load sound effect */
snprintf(fname, sizeof(fname), "%ssounds/magic/googlyeyes.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/googlyeyes.ogg", api->data_directory);
snd_effect = Mix_LoadWAV(fname);
/* Init the images */
if (googlyeyes_limited) {
if (googlyeyes_limited)
{
googlyeyes_sizes = NUM_SIZES;
} else {
}
else
{
googlyeyes_sizes = NUM_SCALEABLE_SIZES;
}
googlyeyes_img_bkgd = (SDL_Surface * *) malloc(sizeof(SDL_Surface *) * googlyeyes_sizes);
googlyeyes_img_pupil = (SDL_Surface * *) malloc(sizeof(SDL_Surface *) * googlyeyes_sizes);
googlyeyes_img_reflection = (SDL_Surface * *) malloc(sizeof(SDL_Surface *) * googlyeyes_sizes);
googlyeyes_img_bkgd = (SDL_Surface * *)malloc(sizeof(SDL_Surface *) * googlyeyes_sizes);
googlyeyes_img_pupil = (SDL_Surface * *)malloc(sizeof(SDL_Surface *) * googlyeyes_sizes);
googlyeyes_img_reflection = (SDL_Surface * *)malloc(sizeof(SDL_Surface *) * googlyeyes_sizes);
for (i = 0; i < googlyeyes_sizes; i++) {
for (i = 0; i < googlyeyes_sizes; i++)
{
googlyeyes_img_bkgd[i] = NULL;
googlyeyes_img_pupil[i] = NULL;
googlyeyes_img_reflection[i] = NULL;
}
/* Load the base images (100% scale) */
snprintf(fname, sizeof(fname), "%simages/magic/googly-eyes-bkgd.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/googly-eyes-bkgd.png", api->data_directory);
googlyeyes_img_bkgd[0] = IMG_Load(fname);
if (googlyeyes_img_bkgd[0] == NULL)
{
@ -115,8 +114,7 @@ int googlyeyes_init(magic_api * api, Uint32 disabled_features)
return 0;
}
snprintf(fname, sizeof(fname), "%simages/magic/googly-eyes-pupil.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/googly-eyes-pupil.png", api->data_directory);
googlyeyes_img_pupil[0] = IMG_Load(fname);
if (googlyeyes_img_pupil[0] == NULL)
{
@ -124,8 +122,7 @@ int googlyeyes_init(magic_api * api, Uint32 disabled_features)
return 0;
}
snprintf(fname, sizeof(fname), "%simages/magic/googly-eyes-reflection.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/googly-eyes-reflection.png", api->data_directory);
googlyeyes_img_reflection[0] = IMG_Load(fname);
if (googlyeyes_img_reflection[0] == NULL)
{
@ -134,43 +131,47 @@ int googlyeyes_init(magic_api * api, Uint32 disabled_features)
}
/* Create the scaled versions */
for (i = 1; i < googlyeyes_sizes; i++) {
for (i = 1; i < googlyeyes_sizes; i++)
{
int size;
if (googlyeyes_limited) {
if (googlyeyes_limited)
{
size = sizes[i];
} else {
}
else
{
size = (100 * (googlyeyes_sizes - i)) / googlyeyes_sizes;
}
googlyeyes_img_bkgd[i] = api->scale(googlyeyes_img_bkgd[0],
(googlyeyes_img_bkgd[0]->w * size) / 100,
(googlyeyes_img_bkgd[0]->h * size) / 100,
1);
(googlyeyes_img_bkgd[0]->h * size) / 100, 1);
if (googlyeyes_img_bkgd[i] == NULL) {
if (googlyeyes_img_bkgd[i] == NULL)
{
fprintf(stderr, "Cannot scale bkgd to %d%%", size);
return(1);
return (1);
}
googlyeyes_img_pupil[i] = api->scale(googlyeyes_img_pupil[0],
(googlyeyes_img_pupil[0]->w * size) / 100,
(googlyeyes_img_pupil[0]->h * size) / 100,
1);
(googlyeyes_img_pupil[0]->w * size) / 100,
(googlyeyes_img_pupil[0]->h * size) / 100, 1);
if (googlyeyes_img_pupil[i] == NULL) {
if (googlyeyes_img_pupil[i] == NULL)
{
fprintf(stderr, "Cannot scale pupil to %d%%", size);
return(1);
return (1);
}
googlyeyes_img_reflection[i] = api->scale(googlyeyes_img_reflection[0],
(googlyeyes_img_reflection[0]->w * size) / 100,
(googlyeyes_img_reflection[0]->h * size) / 100,
1);
(googlyeyes_img_reflection[0]->w * size) / 100,
(googlyeyes_img_reflection[0]->h * size) / 100, 1);
if (googlyeyes_img_reflection[i] == NULL) {
if (googlyeyes_img_reflection[i] == NULL)
{
fprintf(stderr, "Cannot scale reflection to %d%%", size);
return(1);
return (1);
}
}
@ -179,9 +180,12 @@ int googlyeyes_init(magic_api * api, Uint32 disabled_features)
int googlyeyes_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
if (googlyeyes_limited) {
if (googlyeyes_limited)
{
return (NUM_SIZES);
} else {
}
else
{
return 1;
}
}
@ -191,52 +195,52 @@ SDL_Surface *googlyeyes_get_icon(magic_api * api, int which)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/%s",
api->data_directory, img_filenames[which]);
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, img_filenames[which]);
return (IMG_Load(fname));
}
char *googlyeyes_get_name(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
char *googlyeyes_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return strdup(gettext("Googly Eyes"));
}
int googlyeyes_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int googlyeyes_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_ARTISTIC;
}
char *googlyeyes_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
if (googlyeyes_limited) {
if (googlyeyes_limited)
{
return strdup(gettext(googlyeyes_descr[which]));
} else {
}
else
{
return strdup(gettext_noop("Click to place a googly eye, then drag and release to make it look that direction."));
}
}
int googlyeyes_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int googlyeyes_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 0;
}
int googlyeyes_modes(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int googlyeyes_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MODE_PAINT;
}
Uint8 googlyeyes_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
if (googlyeyes_limited) {
if (googlyeyes_limited)
{
return 1;
} else {
}
else
{
return NUM_SCALEABLE_SIZES;
}
}
@ -253,7 +257,8 @@ void googlyeyes_shutdown(magic_api * api ATTRIBUTE_UNUSED)
if (snd_effect != NULL)
Mix_FreeChunk(snd_effect);
for (i = 0; i < googlyeyes_sizes; i++) {
for (i = 0; i < googlyeyes_sizes; i++)
{
if (googlyeyes_img_bkgd[i] != NULL)
SDL_FreeSurface(googlyeyes_img_bkgd[i]);
@ -272,17 +277,19 @@ void googlyeyes_shutdown(magic_api * api ATTRIBUTE_UNUSED)
void
googlyeyes_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
{
int img;
eye_x = x;
eye_y = y;
if (googlyeyes_limited) {
if (googlyeyes_limited)
{
img = which;
} else {
}
else
{
img = googlyeyes_size - 1;
}
@ -300,16 +307,19 @@ googlyeyes_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
void
googlyeyes_drag(magic_api * api ATTRIBUTE_UNUSED, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox ATTRIBUTE_UNUSED,
int oy ATTRIBUTE_UNUSED, int x, int y, SDL_Rect * update_rect)
SDL_Surface * snapshot, int ox ATTRIBUTE_UNUSED,
int oy ATTRIBUTE_UNUSED, int x, int y, SDL_Rect * update_rect)
{
SDL_Rect dest;
int max_radius;
int img;
if (googlyeyes_limited) {
if (googlyeyes_limited)
{
img = which;
} else {
}
else
{
img = googlyeyes_size - 1;
}
@ -327,7 +337,8 @@ googlyeyes_drag(magic_api * api ATTRIBUTE_UNUSED, int which, SDL_Surface * canva
/* 2. Draw the pupil */
max_radius = ((googlyeyes_img_bkgd[img]->w - googlyeyes_img_pupil[img]->w) / 2);
if (sqrt(((x - eye_x) * (x - eye_x)) + ((y - eye_y) * (y - eye_y))) > max_radius) {
if (sqrt(((x - eye_x) * (x - eye_x)) + ((y - eye_y) * (y - eye_y))) > max_radius)
{
/* If drag position would place pupil outside the circular bounds
* of the background, put it on the edge, "looking towards" (pointing at)
* the mouse. */
@ -335,8 +346,8 @@ googlyeyes_drag(magic_api * api ATTRIBUTE_UNUSED, int which, SDL_Surface * canva
* https://github.com/freedesktop/xorg-xeyes/blob/master/Eyes.c) */
double dx, dy, angle;
dx = (double) (x - eye_x);
dy = (double) (y - eye_y);
dx = (double)(x - eye_x);
dy = (double)(y - eye_y);
angle = atan2(dy, dx);
x = eye_x + (cos(angle) * max_radius);
@ -360,15 +371,16 @@ googlyeyes_drag(magic_api * api ATTRIBUTE_UNUSED, int which, SDL_Surface * canva
void
googlyeyes_release(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * snapshot ATTRIBUTE_UNUSED,
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * snapshot ATTRIBUTE_UNUSED,
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
void googlyeyes_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void googlyeyes_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
@ -381,14 +393,11 @@ void googlyeyes_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_U
}
void googlyeyes_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void googlyeyes_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}

View file

@ -49,8 +49,7 @@ char *grass_get_name(magic_api * api, int which);
int grass_get_group(magic_api * api, int which);
char *grass_get_description(magic_api * api, int which, int mode);
void grass_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void grass_click(magic_api * api, int which, int mode, SDL_Surface * canvas,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void grass_release(magic_api * api, int which, SDL_Surface * canvas,
@ -59,29 +58,25 @@ void grass_shutdown(magic_api * api);
void grass_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
int grass_requires_colors(magic_api * api, int which);
static void do_grass(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y);
static void do_grass(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
static int log2int(int x);
void grass_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void grass_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void grass_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void grass_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int grass_modes(magic_api * api, int which);
Uint8 grass_accepted_sizes(magic_api * api, int which, int mode);
Uint8 grass_default_size(magic_api * api, int which, int mode);
void grass_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void grass_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
// No setup required:
int grass_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%ssounds/magic/grass.wav",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/grass.wav", api->data_directory);
grass_snd = Mix_LoadWAV(fname);
snprintf(fname, sizeof(fname), "%simages/magic/grass_data.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/grass_data.png", api->data_directory);
img_grass = IMG_Load(fname);
return (1);
@ -105,43 +100,35 @@ SDL_Surface *grass_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/grass.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/grass.png", api->data_directory);
return (IMG_Load(fname));
}
// Return our names, localized:
char *grass_get_name(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
char *grass_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (strdup(gettext_noop("Grass")));
}
// Return our groups:
int grass_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int grass_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_PAINTING;
}
// Return our descriptions, localized:
char *grass_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED)
char *grass_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return (strdup
(gettext_noop
("Click and drag to draw grass. Dont forget the dirt!")));
return (strdup(gettext_noop("Click and drag to draw grass. Dont forget the dirt!")));
}
// Affect the canvas on drag:
void grass_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *) api, which, canvas, last, ox, oy, x, y, 4, do_grass);
api->line((void *)api, which, canvas, last, ox, oy, x, y, 4, do_grass);
if (ox > x)
{
@ -168,8 +155,7 @@ void grass_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void grass_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
grass_drag(api, which, canvas, last, x, y, x, y, update_rect);
}
@ -178,8 +164,7 @@ void grass_release(magic_api * api ATTRIBUTE_UNUSED,
int which 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)
{
}
@ -191,8 +176,9 @@ void grass_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void grass_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void grass_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g,
Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
grass_r = r;
grass_g = g;
@ -200,15 +186,13 @@ void grass_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSE
}
// Use colors:
int grass_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int grass_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 1;
}
static void do_grass(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)
{
magic_api *api = (magic_api *) ptr;
int xx, yy;
@ -221,12 +205,10 @@ static void do_grass(void *ptr, int which ATTRIBUTE_UNUSED,
if (!api->button_down())
bucket = 0;
bucket += (3.5 + (rand() / (double) RAND_MAX)) * 7.0;
bucket += (3.5 + (rand() / (double)RAND_MAX)) * 7.0;
while (bucket >= 0)
{
int rank =
log2int(((double) y / canvas->h) *
(0.99 + (rand() / (double) RAND_MAX)) * 64);
int rank = log2int(((double)y / canvas->h) * (0.99 + (rand() / (double)RAND_MAX)) * 64);
int ah = 1 << rank;
bucket -= ah;
@ -236,12 +218,10 @@ static void do_grass(void *ptr, int which ATTRIBUTE_UNUSED,
src.h = ah;
dest.x = x - 32;
dest.y = y - 30 + (int) ((rand() / (double) RAND_MAX) * 30);
dest.y = y - 30 + (int)((rand() / (double)RAND_MAX) * 30);
tmp_red =
api->sRGB_to_linear(grass_r) * 2.0 + (rand() / (double) RAND_MAX);
tmp_green =
api->sRGB_to_linear(grass_g) * 2.0 + (rand() / (double) RAND_MAX);
tmp_red = api->sRGB_to_linear(grass_r) * 2.0 + (rand() / (double)RAND_MAX);
tmp_green = api->sRGB_to_linear(grass_g) * 2.0 + (rand() / (double)RAND_MAX);
tmp_blue = api->sRGB_to_linear(grass_b) * 2.0 + api->sRGB_to_linear(17);
for (yy = 0; yy < ah; yy++)
@ -250,8 +230,7 @@ static void do_grass(void *ptr, int which ATTRIBUTE_UNUSED,
{
double rd, gd, bd;
SDL_GetRGBA(api->getpixel(img_grass, xx + src.x, yy + src.y),
img_grass->format, &r, &g, &b, &a);
SDL_GetRGBA(api->getpixel(img_grass, xx + src.x, yy + src.y), img_grass->format, &r, &g, &b, &a);
rd = api->sRGB_to_linear(r) * 8.0 + tmp_red;
rd = rd * (a / 255.0) / 11.0;
@ -260,21 +239,13 @@ static void do_grass(void *ptr, int which ATTRIBUTE_UNUSED,
bd = api->sRGB_to_linear(b) * 8.0 + tmp_blue;
bd = bd * (a / 255.0) / 11.0;
SDL_GetRGB(api->getpixel(canvas, xx + dest.x, yy + dest.y),
canvas->format, &r, &g, &b);
SDL_GetRGB(api->getpixel(canvas, xx + dest.x, yy + dest.y), canvas->format, &r, &g, &b);
r =
api->linear_to_sRGB(api->sRGB_to_linear(r) * (1.0 - a / 255.0) +
rd);
g =
api->linear_to_sRGB(api->sRGB_to_linear(g) * (1.0 - a / 255.0) +
gd);
b =
api->linear_to_sRGB(api->sRGB_to_linear(b) * (1.0 - a / 255.0) +
bd);
r = api->linear_to_sRGB(api->sRGB_to_linear(r) * (1.0 - a / 255.0) + rd);
g = api->linear_to_sRGB(api->sRGB_to_linear(g) * (1.0 - a / 255.0) + gd);
b = api->linear_to_sRGB(api->sRGB_to_linear(b) * (1.0 - a / 255.0) + bd);
api->putpixel(canvas, xx + dest.x, yy + dest.y,
SDL_MapRGB(canvas->format, r, g, b));
api->putpixel(canvas, xx + dest.x, yy + dest.y, SDL_MapRGB(canvas->format, r, g, b));
}
}
}
@ -297,14 +268,12 @@ static int log2int(int x)
}
void grass_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void grass_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
@ -325,6 +294,8 @@ Uint8 grass_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_U
return 0;
}
void grass_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void grass_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}

View file

@ -59,10 +59,8 @@ static SDL_Surface *canvas_backup, *square;
/* Function Prototypes: */
void halftone_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
void halftone_line_callback(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y);
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void halftone_line_callback(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
Uint32 halftone_api_version(void);
int halftone_init(magic_api * api, Uint32 disabled_features);
int halftone_get_tool_count(magic_api * api);
@ -74,21 +72,18 @@ int halftone_requires_colors(magic_api * api, int which);
int halftone_modes(magic_api * api, int which);
void halftone_shutdown(magic_api * api);
void halftone_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * snapshot, int x,
int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
void halftone_release(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
void halftone_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
void halftone_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void halftone_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void halftone_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void halftone_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
void halftone_rgb2cmyk(Uint8 r, Uint8 g, Uint8 b, float cmyk[]);
Uint8 halftone_accepted_sizes(magic_api * api, int which, int mode);
Uint8 halftone_default_size(magic_api * api, int which, int mode);
void halftone_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void halftone_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
@ -107,8 +102,7 @@ int halftone_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
for (i = 0; i < NUM_TOOLS; i++)
{
snprintf(fname, sizeof(fname), "%ssounds/magic/%s", api->data_directory,
snd_filenames[i]);
snprintf(fname, sizeof(fname), "%ssounds/magic/%s", api->data_directory, snd_filenames[i]);
snd_effect[i] = Mix_LoadWAV(fname);
}
@ -126,8 +120,7 @@ SDL_Surface *halftone_get_icon(magic_api * api, int which)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory,
icon_filenames[which]);
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, icon_filenames[which]);
return (IMG_Load(fname));
}
@ -148,8 +141,7 @@ int halftone_get_group(magic_api * api ATTRIBUTE_UNUSED, int which)
return groups[which];
}
char *halftone_get_description(magic_api * api ATTRIBUTE_UNUSED, int which,
int mode)
char *halftone_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode)
{
const char *our_desc_english;
const char *our_desc_localized;
@ -160,14 +152,12 @@ char *halftone_get_description(magic_api * api ATTRIBUTE_UNUSED, int which,
return (strdup(our_desc_localized));
}
int halftone_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int halftone_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 0;
}
int halftone_modes(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int halftone_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (MODE_PAINT | MODE_FULLSCREEN);
}
@ -189,8 +179,7 @@ void halftone_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
void halftone_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * snapshot, int x,
int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
{
int full_x, full_y;
@ -216,11 +205,9 @@ void halftone_click(magic_api * api, int which, int mode,
}
void halftone_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *) api, which, canvas, snapshot, ox, oy, x, y, 4,
halftone_line_callback);
api->line((void *)api, which, canvas, snapshot, ox, oy, x, y, 4, halftone_line_callback);
if (ox > x)
{
@ -278,21 +265,20 @@ void halftone_release(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * snapshot 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)
{
}
void halftone_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void halftone_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
void halftone_line_callback(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas,
SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x,
int y)
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
{
Uint8 r, g, b, or, og, ob;
Uint32 total_r, total_g, total_b;
@ -323,8 +309,7 @@ void halftone_line_callback(void *ptr, int which ATTRIBUTE_UNUSED,
{
for (yyy = -(GRID_SIZE / 2); yyy < (GRID_SIZE / 2); yyy++)
{
SDL_GetRGB(api->getpixel(canvas_backup, x + xxx, y + yyy),
canvas_backup->format, &r, &g, &b);
SDL_GetRGB(api->getpixel(canvas_backup, x + xxx, y + yyy), canvas_backup->format, &r, &g, &b);
total_r += r;
total_g += g;
total_b += b;
@ -367,12 +352,10 @@ void halftone_line_callback(void *ptr, int which ATTRIBUTE_UNUSED,
/* Additively blend with whatever we have in the
'square' buffer (which starts as white)
(since the target is RGB, we use `min()`) */
SDL_GetRGB(api->getpixel(square, sqx, sqy), square->format, &or,
&og, &ob);
SDL_GetRGB(api->getpixel(square, sqx, sqy), square->format, &or, &og, &ob);
pixel =
SDL_MapRGB(square->format, min((Uint8) (r * 2.0), or),
min((Uint8) (g * 2.0), og), min((Uint8) (b * 2.0),
ob));
min((Uint8) (g * 2.0), og), min((Uint8) (b * 2.0), ob));
api->putpixel(square, sqx, sqy, pixel);
}
}
@ -388,16 +371,14 @@ void halftone_line_callback(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_BlitSurface(square, NULL, canvas, &dest);
}
void halftone_switchin(magic_api * api, int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas)
void halftone_switchin(magic_api * api, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas)
{
if (canvas_backup == NULL)
{
canvas_backup =
SDL_CreateRGBSurface(SDL_SWSURFACE, api->canvas_w, api->canvas_h,
canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask,
canvas->format->Bmask, canvas->format->Amask);
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
}
if (square == NULL)
@ -405,16 +386,14 @@ void halftone_switchin(magic_api * api, int which ATTRIBUTE_UNUSED,
square =
SDL_CreateRGBSurface(SDL_SWSURFACE, GRID_SIZE, GRID_SIZE,
canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask,
canvas->format->Bmask, canvas->format->Amask);
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
}
SDL_BlitSurface(canvas, NULL, canvas_backup, NULL);
}
void halftone_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
@ -436,9 +415,9 @@ void halftone_rgb2cmyk(Uint8 r, Uint8 g, Uint8 b, float cmyk[])
}
else
{
c = 1.0 - (((float) r) / 255.0);
m = 1.0 - (((float) g) / 255.0);
y = 1.0 - (((float) b) / 255.0);
c = 1.0 - (((float)r) / 255.0);
m = 1.0 - (((float)g) / 255.0);
y = 1.0 - (((float)b) / 255.0);
mincmy = min(c, min(m, y));
c = (c - mincmy) / (1.0 - mincmy);
@ -456,14 +435,16 @@ void halftone_rgb2cmyk(Uint8 r, Uint8 g, Uint8 b, float cmyk[])
Uint8 halftone_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return 0; // No size support at this time
return 0; // No size support at this time
}
Uint8 halftone_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return 0; // No size support at this time
return 0; // No size support at this time
}
void halftone_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void halftone_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}

View file

@ -16,32 +16,33 @@
#include "SDL_image.h"
#include "SDL_mixer.h"
enum {
enum
{
KAL_LENS_4,
KAL_LENS_6,
KAL_LENS_8,
NUM_TOOLS
};
static char * kaleidox_snd_fnames[NUM_TOOLS] = {
static char *kaleidox_snd_fnames[NUM_TOOLS] = {
"kaleido-4.ogg",
"kaleido-6.ogg",
"kaleido-8.ogg",
};
static char * kaleidox_icon_fnames[NUM_TOOLS] = {
static char *kaleidox_icon_fnames[NUM_TOOLS] = {
"kaleido-4.png",
"kaleido-6.png",
"kaleido-8.png",
};
char * kaleidox_names[NUM_TOOLS] = {
char *kaleidox_names[NUM_TOOLS] = {
gettext_noop("Kaleido-4"),
gettext_noop("Kaleido-6"),
gettext_noop("Kaleido-8"),
};
char * kaleidox_descrs[NUM_TOOLS] = {
char *kaleidox_descrs[NUM_TOOLS] = {
gettext_noop("Click and drag around your picture to look through it with a kaleidoscope!"),
gettext_noop("Click and drag around your picture to look through it with a kaleidoscope!"),
gettext_noop("Click and drag around your picture to look through it with a kaleidoscope!"),
@ -60,26 +61,21 @@ int kaleidox_requires_colors(magic_api * api, int which);
int kaleidox_modes(magic_api * api, int which);
void kaleidox_shutdown(magic_api * api);
void kaleidox_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * snapshot, int x,
int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
void kaleidox_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
void kaleidox_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
void kaleidox_render(magic_api *, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y, int preview);
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void kaleidox_render(magic_api *, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, int preview);
void kaleidox_release(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect);
void kaleidox_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void kaleidox_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
void kaleidox_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void kaleidox_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int mirror(int n, int max, int flip);
Uint8 kaleidox_accepted_sizes(magic_api * api, int which, int mode);
Uint8 kaleidox_default_size(magic_api * api, int which, int mode);
void kaleidox_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void kaleidox_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
Uint32 kaleidox_api_version(void)
@ -92,9 +88,9 @@ int kaleidox_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
int i;
char fname[1024];
for (i = 0; i < NUM_TOOLS; i++) {
snprintf(fname, sizeof(fname), "%ssounds/magic/%s",
api->data_directory, kaleidox_snd_fnames[i]);
for (i = 0; i < NUM_TOOLS; i++)
{
snprintf(fname, sizeof(fname), "%ssounds/magic/%s", api->data_directory, kaleidox_snd_fnames[i]);
snd_effects[i] = Mix_LoadWAV(fname);
}
@ -111,38 +107,32 @@ SDL_Surface *kaleidox_get_icon(magic_api * api, int which)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/%s",
api->data_directory, kaleidox_icon_fnames[which]);
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, kaleidox_icon_fnames[which]);
return (IMG_Load(fname));
}
char *kaleidox_get_name(magic_api * api ATTRIBUTE_UNUSED,
int which)
char *kaleidox_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
{
return strdup(gettext(kaleidox_names[which]));
}
int kaleidox_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int kaleidox_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_PICTURE_WARPS;
}
char *kaleidox_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which, int mode ATTRIBUTE_UNUSED)
char *kaleidox_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
{
return strdup(gettext(kaleidox_descrs[which]));
}
int kaleidox_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int kaleidox_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 0;
}
int kaleidox_modes(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int kaleidox_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MODE_PAINT_WITH_PREVIEW;
}
@ -151,7 +141,8 @@ void kaleidox_shutdown(magic_api * api ATTRIBUTE_UNUSED)
{
int i;
for (i = 0; i < NUM_TOOLS; i++) {
for (i = 0; i < NUM_TOOLS; i++)
{
if (snd_effects[i] != NULL)
Mix_FreeChunk(snd_effects[i]);
}
@ -159,8 +150,7 @@ void kaleidox_shutdown(magic_api * api ATTRIBUTE_UNUSED)
void
kaleidox_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
{
api->stopsound();
@ -170,23 +160,28 @@ kaleidox_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
#define linear(start, end, dist, full) (start + (((end - start) * dist) / full))
#define length(x1, y1, x2, y2) sqrt(pow((x2 - x1), 2) + pow((y2 - y1), 2))
int mirror(int n, int max, int flip) {
int mirror(int n, int max, int flip)
{
int adjusted;
if (flip)
n = max - n;
do {
do
{
adjusted = 0;
if (n < 0) {
if (n < 0)
{
n = -n;
adjusted = 1;
}
if (n >= max) {
if (n >= max)
{
n = (max - 1) - (n - max);
adjusted = 1;
}
} while (adjusted);
}
while (adjusted);
return n;
}
@ -196,7 +191,8 @@ kaleidox_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED,
int x, int y, SDL_Rect * update_rect)
{
if (snd_effects[which] != NULL) {
if (snd_effects[which] != NULL)
{
api->playsound(snd_effects[which], 128, 255);
}
@ -209,7 +205,7 @@ kaleidox_drag(magic_api * api, int which, SDL_Surface * canvas,
}
void kaleidox_render(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y, int preview)
SDL_Surface * snapshot, int x, int y, int preview)
{
int off_x, off_y, sides, max_radius;
float angle, angle_offset;
@ -221,15 +217,22 @@ void kaleidox_render(magic_api * api, int which, SDL_Surface * canvas,
off_x = (canvas->w / 2) - x * 2;
off_y = (canvas->h / 2) - y * 2;
max_radius = max(canvas->w, canvas->h); /* FIXME: Better calculation should be used! */
max_radius = max(canvas->w, canvas->h); /* FIXME: Better calculation should be used! */
if (which == KAL_LENS_4) {
if (which == KAL_LENS_4)
{
sides = 4;
} else if (which == KAL_LENS_6) {
}
else if (which == KAL_LENS_6)
{
sides = 6;
} else if (which == KAL_LENS_8) {
}
else if (which == KAL_LENS_8)
{
sides = 8;
} else {
}
else
{
return;
}
@ -237,12 +240,14 @@ void kaleidox_render(magic_api * api, int which, SDL_Surface * canvas,
angle_offset = angle / 2;
/* Go around each side */
for (s = 0; s < sides; s++) {
a1 = (angle * (float) s) + angle_offset;
a2 = (angle * (float) (s + 1)) + angle_offset;
for (s = 0; s < sides; s++)
{
a1 = (angle * (float)s) + angle_offset;
a2 = (angle * (float)(s + 1)) + angle_offset;
/* From the center outward... */
for (r = 0; r < max_radius; r = r + (preview ? 4 : 1)) {
for (r = 0; r < max_radius; r = r + (preview ? 4 : 1))
{
dx = (canvas->w / 2) + cos(a1) * r;
dy = (canvas->h / 2) - sin(a1) * r;
@ -252,13 +257,15 @@ void kaleidox_render(magic_api * api, int which, SDL_Surface * canvas,
len = length(dx, dy, dx2, dy2);
/* Scan rows of the source, and draw along each triangle */
if (len != 0) {
xxm = ((len > 0 ? 1 : -1 ) * (preview ? 4 : 1));
if (len != 0)
{
xxm = ((len > 0 ? 1 : -1) * (preview ? 4 : 1));
push = (canvas->w - abs(len)) / 2;
xx = 0;
done = 0;
do {
do
{
src_x = (canvas->w / 2) + off_x + xx + push;
src_x = mirror(src_x, canvas->w, (s % 2));
@ -268,20 +275,25 @@ void kaleidox_render(magic_api * api, int which, SDL_Surface * canvas,
colr = api->getpixel(snapshot, src_x, src_y);
dest.x = linear(dx, dx2, xx, len);
dest.y = linear(dy, dy2, xx, len);
if (preview) {
if (preview)
{
dest.w = 6;
dest.h = 6;
} else {
}
else
{
dest.w = 2;
dest.h = 2;
}
SDL_FillRect(canvas, &dest, colr);
xx = xx + xxm;
if ((xxm > 0 && xx > len) || (xxm < 0 && xx < len)) {
if ((xxm > 0 && xx > len) || (xxm < 0 && xx < len))
{
done = 1;
}
} while (!done);
}
while (!done);
}
}
}
@ -289,10 +301,7 @@ void kaleidox_render(magic_api * api, int which, SDL_Surface * canvas,
void kaleidox_release(magic_api * api, int which,
SDL_Surface * canvas,
SDL_Surface * snapshot,
int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
{
kaleidox_render(api, which, canvas, snapshot, x, y, 0);
@ -306,24 +315,21 @@ void kaleidox_release(magic_api * api, int which,
void kaleidox_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
void kaleidox_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void kaleidox_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
@ -340,6 +346,8 @@ Uint8 kaleidox_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUT
return 0;
}
void kaleidox_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void kaleidox_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}

View file

@ -70,17 +70,13 @@ SDL_Surface *kalidescope_get_icon(magic_api * api, int which);
char *kalidescope_get_name(magic_api * api, int which);
int kalidescope_get_group(magic_api * api, int which);
char *kalidescope_get_description(magic_api * api, int which, int mode);
static void do_kalidescope(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y);
static void do_kalidescope(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
void kalidescope_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void kalidescope_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void kalidescope_release(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void kalidescope_shutdown(magic_api * api);
int kalidescope_requires_colors(magic_api * api, int which);
Uint8 kalidescope_accepted_sizes(magic_api * api, int which, int mode);
@ -88,12 +84,9 @@ Uint8 kalidescope_default_size(magic_api * api, int which, int mode);
void kalidescope_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
void kalidescope_set_size(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
Uint8 sz, SDL_Rect * update_rect);
void kalidescope_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void kalidescope_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
SDL_Surface * canvas, SDL_Surface * last, Uint8 sz, SDL_Rect * update_rect);
void kalidescope_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void kalidescope_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int kalidescope_modes(magic_api * api, int which);
Uint32 kalidescope_api_version(void)
@ -105,8 +98,7 @@ int kalidescope_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%ssounds/magic/kaleidoscope.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/kaleidoscope.ogg", api->data_directory);
kalidescope_snd = Mix_LoadWAV(fname);
return (1);
@ -122,8 +114,7 @@ SDL_Surface *kalidescope_get_icon(magic_api * api, int which)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory,
kal_icon_names[which]);
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, kal_icon_names[which]);
return (IMG_Load(fname));
}
@ -154,16 +145,14 @@ char *kalidescope_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
}
// Return our group (all the same):
int kalidescope_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int kalidescope_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_PATTERN_PAINTING;
}
// Return our descriptions, localized:
char *kalidescope_get_description(magic_api * api ATTRIBUTE_UNUSED, int which,
int mode ATTRIBUTE_UNUSED)
char *kalidescope_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
{
if (which == KAL_LR)
{
@ -179,21 +168,15 @@ char *kalidescope_get_description(magic_api * api ATTRIBUTE_UNUSED, int which,
}
else if (which == KAL_PATTERN)
{
return (strdup
(gettext_noop
("Click and drag the mouse to draw a pattern across the picture.")));
return (strdup(gettext_noop("Click and drag the mouse to draw a pattern across the picture.")));
}
else if (which == KAL_TILES)
{
return (strdup
(gettext_noop
("Click and drag the mouse to draw a pattern that is symmetric across the picture.")));
return (strdup(gettext_noop("Click and drag the mouse to draw a pattern that is symmetric across the picture.")));
}
else
{ /* KAL_BOTH */
return (strdup
(gettext_noop
("Click and drag the mouse to draw with symmetric brushes (a kaleidoscope).")));
return (strdup(gettext_noop("Click and drag the mouse to draw with symmetric brushes (a kaleidoscope).")));
}
}
@ -207,8 +190,7 @@ static void do_kalidescope(void *ptr, int which, SDL_Surface * canvas,
int i, j;
Uint32 colr;
colr =
SDL_MapRGB(canvas->format, kalidescope_r, kalidescope_g, kalidescope_b);
colr = SDL_MapRGB(canvas->format, kalidescope_r, kalidescope_g, kalidescope_b);
for (yy = -kalidescope_sz; yy < kalidescope_sz; yy++)
{
@ -224,8 +206,7 @@ static void do_kalidescope(void *ptr, int which, SDL_Surface * canvas,
if (which == KAL_BOTH)
{
api->putpixel(canvas, canvas->w - 1 - x + xx,
canvas->h - 1 - y + yy, colr);
api->putpixel(canvas, canvas->w - 1 - x + xx, canvas->h - 1 - y + yy, colr);
}
}
if (which == KAL_UD || which == KAL_BOTH)
@ -237,11 +218,9 @@ static void do_kalidescope(void *ptr, int which, SDL_Surface * canvas,
for (i = 0; i <= canvas->w; i += square_size)
for (j = 0; j <= canvas->h; j += square_size)
{
api->putpixel(canvas, i + xx + x % square_size,
j + yy + y % square_size, colr);
api->putpixel(canvas, i + xx + x % square_size, j + yy + y % square_size, colr);
if (which == KAL_TILES)
api->putpixel(canvas, i + yy + y % square_size,
j + xx + x % square_size, colr);
api->putpixel(canvas, i + yy + y % square_size, j + xx + x % square_size, colr);
}
}
}
@ -251,11 +230,9 @@ static void do_kalidescope(void *ptr, int which, SDL_Surface * canvas,
// Affect the canvas on drag:
void kalidescope_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1,
do_kalidescope);
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_kalidescope);
update_rect->x = 0;
update_rect->y = 0;
@ -267,8 +244,7 @@ void kalidescope_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void kalidescope_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
kalidescope_drag(api, which, canvas, last, x, y, x, y, update_rect);
}
@ -277,8 +253,7 @@ void kalidescope_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
void kalidescope_release(magic_api * api, int which 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)
{
api->stopsound();
}
@ -291,15 +266,15 @@ void kalidescope_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Use colors:
int kalidescope_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int kalidescope_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 1;
}
// Record the color from Tux Paint:
void kalidescope_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void kalidescope_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g,
Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
kalidescope_r = r;
kalidescope_g = g;
@ -313,8 +288,7 @@ Uint8 kalidescope_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED,
return KAL_MAX_SIZE;
}
Uint8 kalidescope_default_size(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
Uint8 kalidescope_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return KAL_DEF_SIZE;
}
@ -329,21 +303,16 @@ void kalidescope_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_
void kalidescope_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void kalidescope_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int kalidescope_modes(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int kalidescope_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (MODE_PAINT);
}

View file

@ -50,11 +50,9 @@ SDL_Surface *light_get_icon(magic_api * api, int which);
char *light_get_name(magic_api * api, int which);
int light_get_group(magic_api * api, int which);
char *light_get_description(magic_api * api, int which, int mode);
static void do_light(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y);
static void do_light(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
void light_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void light_click(magic_api * api, int which, int mode, SDL_Surface * canvas,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void light_release(magic_api * api, int which, SDL_Surface * canvas,
@ -63,14 +61,13 @@ void light_shutdown(magic_api * api);
void light_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
int light_requires_colors(magic_api * api, int which);
void light_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void light_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void light_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void light_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int light_modes(magic_api * api, int which);
Uint8 light_accepted_sizes(magic_api * api, int which, int mode);
Uint8 light_default_size(magic_api * api, int which, int mode);
void light_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void light_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
Uint32 light_api_version(void)
@ -84,12 +81,10 @@ int light_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%ssounds/magic/light1.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/light1.ogg", api->data_directory);
light1_snd = Mix_LoadWAV(fname);
snprintf(fname, sizeof(fname), "%ssounds/magic/light2.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/light2.ogg", api->data_directory);
light2_snd = Mix_LoadWAV(fname);
return (1);
@ -106,41 +101,33 @@ SDL_Surface *light_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/light.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/light.png", api->data_directory);
return (IMG_Load(fname));
}
// Return our names, localized:
char *light_get_name(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
char *light_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (strdup(gettext_noop("Light")));
}
// Return our groups:
int light_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int light_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_PAINTING;
}
// Return our descriptions, localized:
char *light_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED)
char *light_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return (strdup
(gettext_noop
("Click and drag to draw a beam of light on your picture.")));
return (strdup(gettext_noop("Click and drag to draw a beam of light on your picture.")));
}
// Do the effect:
static void do_light(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)
{
magic_api *api = (magic_api *) ptr;
int xx, yy;
@ -159,11 +146,11 @@ static void do_light(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_GetRGB(pix, canvas->format, &r, &g, &b);
adj = (((float) light_radius - 0.01) - sqrt(abs(xx * yy))) / (16.0 * (float) light_radius);
adj = (((float)light_radius - 0.01) - sqrt(abs(xx * yy))) / (16.0 * (float)light_radius);
api->rgbtohsv(r, g, b, &h, &s, &v);
v = min((float) 1.0, v + adj);
v = min((float)1.0, v + adj);
if (light_h == -1 && h == -1)
{
@ -192,8 +179,7 @@ static void do_light(void *ptr, int which ATTRIBUTE_UNUSED,
api->hsvtorgb(new_h, new_s, new_v, &r, &g, &b);
api->putpixel(canvas, x + xx, y + yy,
SDL_MapRGB(canvas->format, r, g, b));
api->putpixel(canvas, x + xx, y + yy, SDL_MapRGB(canvas->format, r, g, b));
}
}
}
@ -201,10 +187,9 @@ static void do_light(void *ptr, int which ATTRIBUTE_UNUSED,
// Affect the canvas on drag:
void light_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_light);
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_light);
if (ox > x)
{
@ -231,8 +216,7 @@ void light_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void light_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
light_drag(api, which, canvas, last, x, y, x, y, update_rect);
}
@ -240,8 +224,7 @@ void light_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
// Affect the canvas on release:
void light_release(magic_api * api, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
int x, int y ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
int x, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
api->playsound(light2_snd, (x * 255) / canvas->w, 255);
}
@ -257,27 +240,25 @@ void light_shutdown(magic_api * api ATTRIBUTE_UNUSED)
// Record the color from Tux Paint:
void light_set_color(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
api->rgbtohsv(r, g, b, &light_h, &light_s, &light_v);
}
// Use colors:
int light_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int light_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 1;
}
void light_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void light_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
@ -297,7 +278,9 @@ Uint8 light_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_U
return 2;
}
void light_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void light_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
light_radius = size * 4;
}

View file

@ -31,28 +31,22 @@ int lightning_requires_colors(magic_api * api, int which);
int lightning_modes(magic_api * api, int which);
void lightning_shutdown(magic_api * api);
void lightning_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * snapshot, int x,
int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
void lightning_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
void lightning_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
void lightning_line_callback_drag(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y);
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void lightning_line_callback_drag(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
void lightning_draw_bolt(void *ptr, SDL_Surface * canvas,
SDL_Surface * snapshot, float sx, float sy,
float angle, float len, int thickness);
SDL_Surface * snapshot, float sx, float sy, float angle, float len, int thickness);
void lightning_release(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect);
void lightning_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void lightning_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
void lightning_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void lightning_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
Uint8 lightning_accepted_sizes(magic_api * api, int which, int mode);
Uint8 lightning_default_size(magic_api * api, int which, int mode);
void lightning_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void lightning_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
Uint32 lightning_api_version(void)
@ -64,8 +58,7 @@ int lightning_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%ssounds/magic/lightning.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/lightning.ogg", api->data_directory);
snd_effect = Mix_LoadWAV(fname);
return (1);
@ -81,41 +74,32 @@ SDL_Surface *lightning_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/lightning.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/lightning.png", api->data_directory);
return (IMG_Load(fname));
}
char *lightning_get_name(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
char *lightning_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return strdup(gettext("Lightning"));
}
int lightning_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int lightning_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_ARTISTIC;
}
char *lightning_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED)
char *lightning_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return
strdup(gettext
("Click, drag, and release to draw a lightning bolt between two points."));
return strdup(gettext("Click, drag, and release to draw a lightning bolt between two points."));
}
int lightning_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int lightning_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 1;
}
int lightning_modes(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int lightning_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MODE_PAINT;
}
@ -129,8 +113,7 @@ void lightning_shutdown(magic_api * api ATTRIBUTE_UNUSED)
void
lightning_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
{
sx = x;
sy = y;
@ -154,15 +137,13 @@ lightning_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_BlitSurface(snapshot, update_rect, canvas, update_rect);
api->line((void *) api, which, canvas, snapshot, sx, sy, x, y, 1,
lightning_line_callback_drag);
api->line((void *)api, which, canvas, snapshot, sx, sy, x, y, 1, lightning_line_callback_drag);
}
void
lightning_release(magic_api * api, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
{
float a, b, len, angle;
int thickness;
@ -194,8 +175,7 @@ lightning_release(magic_api * api, int which ATTRIBUTE_UNUSED,
#ifdef DEBUG
printf
("(%d,%d)->(%d,%d) => a = %.2f, b = %.2f, c (len) = %.2f; angle = %.2f degrees\n",
sx, sy, x, y, a, b, len, angle);
("(%d,%d)->(%d,%d) => a = %.2f, b = %.2f, c (len) = %.2f; angle = %.2f degrees\n", sx, sy, x, y, a, b, len, angle);
fflush(stdout);
#endif
@ -203,13 +183,11 @@ lightning_release(magic_api * api, int which ATTRIBUTE_UNUSED,
if (thickness < 4)
thickness = 4;
lightning_draw_bolt((void *) api, canvas, snapshot, (float) sx, (float) sy,
angle, len, thickness);
lightning_draw_bolt((void *)api, canvas, snapshot, (float)sx, (float)sy, angle, len, thickness);
}
void lightning_draw_bolt(void *ptr, SDL_Surface * canvas,
SDL_Surface * snapshot, float sx, float sy,
float angle, float len, int thickness)
SDL_Surface * snapshot, float sx, float sy, float angle, float len, int thickness)
{
magic_api *api = (magic_api *) ptr;
float i;
@ -232,7 +210,7 @@ void lightning_draw_bolt(void *ptr, SDL_Surface * canvas,
x = x + cos(angle * M_PI / 180.0);
y = y + sin(angle * M_PI / 180.0);
angle = angle + ((float) (rand() % 15) - 7.5);
angle = angle + ((float)(rand() % 15) - 7.5);
if (angle < orig_angle - 10.0)
angle = orig_angle - 10.0;
else if (angle > orig_angle + 10.0)
@ -249,8 +227,7 @@ void lightning_draw_bolt(void *ptr, SDL_Surface * canvas,
light_h = lightning_h;
light_s = lightning_s;
SDL_GetRGB(api->getpixel(canvas, x + xx, y + yy), canvas->format,
&r, &g, &b);
SDL_GetRGB(api->getpixel(canvas, x + xx, y + yy), canvas->format, &r, &g, &b);
api->rgbtohsv(r, g, b, &h, &s, &v);
adj = 1.0 - (sqrt((xx * xx) + (yy * yy)) / t);
@ -275,46 +252,41 @@ void lightning_draw_bolt(void *ptr, SDL_Surface * canvas,
api->hsvtorgb(new_h, new_s, new_v, &r, &g, &b);
api->putpixel(canvas, x + xx, y + yy,
SDL_MapRGB(canvas->format, r, g, b));
api->putpixel(canvas, x + xx, y + yy, SDL_MapRGB(canvas->format, r, g, b));
}
}
}
if (((rand() % 50) == 0 || (int) i == (int) (len / 2)) && thickness > 1
&& len >= 4)
if (((rand() % 50) == 0 || (int)i == (int)(len / 2)) && thickness > 1 && len >= 4)
{
float new_angle;
if ((rand() % 10) == 0)
{
new_angle = angle + ((float) (rand() % 180) - 90.0);
new_angle = angle + ((float)(rand() % 180) - 90.0);
}
else
{
new_angle = angle + ((float) (rand() % 90) - 45.0);
new_angle = angle + ((float)(rand() % 90) - 45.0);
}
lightning_draw_bolt((void *) api, canvas, snapshot, x, y,
new_angle,
((len / 8) + (rand() % (int) (len / 4))),
thickness - 1);
lightning_draw_bolt((void *)api, canvas, snapshot, x, y,
new_angle, ((len / 8) + (rand() % (int)(len / 4))), thickness - 1);
}
}
}
void lightning_set_color(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
api->rgbtohsv(r, g, b, &lightning_h, &lightning_s, &lightning_v);
}
void lightning_line_callback_drag(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas,
SDL_Surface * snapshot ATTRIBUTE_UNUSED,
int x, int y)
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
{
magic_api *api = (magic_api *) ptr;
@ -322,15 +294,12 @@ void lightning_line_callback_drag(void *ptr, int which ATTRIBUTE_UNUSED,
}
void lightning_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void lightning_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
@ -344,6 +313,8 @@ Uint8 lightning_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBU
return 0;
}
void lightning_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void lightning_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}

View file

@ -28,15 +28,16 @@
int xm[4] = { 0, 0, -1, 1 };
int ym[4] = { -1, 1, 0, 0 };
typedef struct {
typedef struct
{
int x, y;
} maze_start_t;
Mix_Chunk *snd_effect = NULL;
Uint8 * maze_mask = NULL, * new_maze_mask = NULL, * maze_array = NULL;
Uint32 * maze_color;
maze_start_t * maze_starts;
SDL_Surface * maze_snapshot = NULL;
Uint8 *maze_mask = NULL, *new_maze_mask = NULL, *maze_array = NULL;
Uint32 *maze_color;
maze_start_t *maze_starts;
SDL_Surface *maze_snapshot = NULL;
Uint8 maze_r, maze_g, maze_b;
int maze_start_x, maze_start_y;
int num_maze_starts = 0, maze_starts_size = 0;
@ -52,23 +53,17 @@ int maze_requires_colors(magic_api * api, int which);
int maze_modes(magic_api * api, int which);
void maze_shutdown(magic_api * api);
void maze_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * snapshot, int x,
int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
void maze_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
void maze_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
void maze_line_callback_drag(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y);
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void maze_line_callback_drag(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
void maze_release(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
void maze_render(magic_api * api, SDL_Surface * canvas);
void maze_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void maze_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void maze_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void maze_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
void zero_maze_arrays(SDL_Surface * canvas);
void draw_hall(SDL_Surface * canvas, int x, int y);
void maze_add_start(void);
@ -76,7 +71,8 @@ int check_arrays(void);
void maze_collapse_contiguous(SDL_Surface * canvas);
Uint8 maze_accepted_sizes(magic_api * api, int which, int mode);
Uint8 maze_default_size(magic_api * api, int which, int mode);
void maze_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void maze_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
Uint32 maze_api_version(void)
@ -88,8 +84,7 @@ int maze_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%ssounds/magic/maze.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/maze.ogg", api->data_directory);
snd_effect = Mix_LoadWAV(fname);
return (1);
@ -105,42 +100,35 @@ SDL_Surface *maze_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/maze.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/maze.png", api->data_directory);
return (IMG_Load(fname));
}
char *maze_get_name(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
char *maze_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return strdup(gettext("Maze"));
}
int maze_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int maze_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_PAINTING;
}
char *maze_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode)
char *maze_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode)
{
if (mode == MODE_PAINT)
return(gettext("Click and drag to paint a maze on your picture."));
return (gettext("Click and drag to paint a maze on your picture."));
else
return(gettext("Click to turn your entire picture into a maze."));
return (gettext("Click to turn your entire picture into a maze."));
}
int maze_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int maze_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 1;
}
int maze_modes(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int maze_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MODE_PAINT | MODE_FULLSCREEN;
}
@ -164,18 +152,19 @@ void maze_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
/* FIXME */
int check_arrays(void) {
int check_arrays(void)
{
if (maze_array == NULL || maze_mask == NULL || new_maze_mask == NULL ||
maze_color == NULL || maze_snapshot == NULL || maze_starts == NULL) {
return(0);
maze_color == NULL || maze_snapshot == NULL || maze_starts == NULL)
{
return (0);
}
return(1);
return (1);
}
void
maze_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
{
if (!check_arrays())
return;
@ -186,9 +175,12 @@ maze_click(magic_api * api, int which, int mode,
maze_start_x = floor(x / MAZE_BLOCK_SIZE) * MAZE_BLOCK_SIZE + (MAZE_BLOCK_SIZE / 2);
maze_start_y = floor(y / MAZE_BLOCK_SIZE) * MAZE_BLOCK_SIZE + (MAZE_BLOCK_SIZE / 2);
if (mode == MODE_PAINT) {
if (mode == MODE_PAINT)
{
maze_drag(api, which, canvas, snapshot, x, y, x, y, update_rect);
} else {
}
else
{
Uint32 color;
maze_add_start();
@ -216,14 +208,13 @@ maze_click(magic_api * api, int which, int mode,
void
maze_drag(magic_api * api ATTRIBUTE_UNUSED, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox ATTRIBUTE_UNUSED,
int oy ATTRIBUTE_UNUSED, int x, int y, SDL_Rect * update_rect)
SDL_Surface * snapshot, int ox ATTRIBUTE_UNUSED,
int oy ATTRIBUTE_UNUSED, int x, int y, SDL_Rect * update_rect)
{
if (!check_arrays())
return;
api->line((void *) api, which, canvas, snapshot, ox, oy, x, y, 1,
maze_line_callback_drag);
api->line((void *)api, which, canvas, snapshot, ox, oy, x, y, 1, maze_line_callback_drag);
update_rect->x = 0;
update_rect->y = 0;
@ -234,8 +225,8 @@ maze_drag(magic_api * api ATTRIBUTE_UNUSED, int which, SDL_Surface * canvas,
void maze_release(magic_api * api, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED,
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED,
SDL_Rect * update_rect) {
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect)
{
if (snd_effect != NULL)
api->stopsound();
@ -266,27 +257,34 @@ void maze_render(magic_api * api, SDL_Surface * canvas)
/* Reset everything we've drawn [back to] wall: */
memset(maze_array, MAZE_HALL, (canvas->w * canvas->h));
for (y = 0; y < canvas->h; y++) {
for (x = 0; x < canvas->w; x++) {
if (maze_mask[y * canvas->w + x]) {
for (y = 0; y < canvas->h; y++)
{
for (x = 0; x < canvas->w; x++)
{
if (maze_mask[y * canvas->w + x])
{
maze_array[y * canvas->w + x] = MAZE_WALL;
}
}
}
/* Render a maze! */
for (s = 0; s < num_maze_starts; s++) {
for (s = 0; s < num_maze_starts; s++)
{
x = maze_starts[s].x;
y = maze_starts[s].y;
/* Render from here, ONLY if it's still non-contiguous to anything: */
if (maze_mask[y * canvas->w + x] == s + 1) {
if (maze_mask[y * canvas->w + x] == s + 1)
{
maze_array[y * canvas->w + x] = MAZE_START;
state = STATE_PICKDIR;
iter = 0;
do {
if (state == STATE_PICKDIR) {
do
{
if (state == STATE_PICKDIR)
{
dir = (rand() % 4);
old_dir = dir;
}
@ -296,7 +294,8 @@ void maze_render(magic_api * api, SDL_Surface * canvas)
nx = x + (xm[dir] * MAZE_BLOCK_SIZE * 2);
ny = y + (ym[dir] * MAZE_BLOCK_SIZE * 2);
if (nx >= 0 && nx < canvas->w && ny >= 0 && ny < canvas->h && maze_array[ny * canvas->w + nx] == MAZE_WALL) {
if (nx >= 0 && nx < canvas->w && ny >= 0 && ny < canvas->h && maze_array[ny * canvas->w + nx] == MAZE_WALL)
{
draw_hall(canvas, nx, ny);
maze_array[ny * canvas->w + nx] = dir + 1;
@ -310,18 +309,21 @@ void maze_render(magic_api * api, SDL_Surface * canvas)
state = STATE_PICKDIR;
}
if (state == STATE_DONE) {
if (state == STATE_DONE)
{
dir = (dir + 1) % 4;
if (dir != old_dir)
state = STATE_KEEPGOING;
}
if (state == STATE_DONE) {
if (state == STATE_DONE)
{
dir = maze_array[y * canvas->w + x];
draw_hall(canvas, x, y);
if (dir != MAZE_START) {
if (dir != MAZE_START)
{
x = x - (xm[dir - 1] * MAZE_BLOCK_SIZE * 2);
y = y - (ym[dir - 1] * MAZE_BLOCK_SIZE * 2);
@ -335,11 +337,16 @@ void maze_render(magic_api * api, SDL_Surface * canvas)
}
/* Draw the maze onto the canvas */
for (y = 0; y < canvas->h; y++) {
for (x = 0; x < canvas->w; x++) {
if (maze_array[y * canvas->w + x] == MAZE_WALL) {
for (y = 0; y < canvas->h; y++)
{
for (x = 0; x < canvas->w; x++)
{
if (maze_array[y * canvas->w + x] == MAZE_WALL)
{
api->putpixel(canvas, x, y, maze_color[y * canvas->w + x]);
} else {
}
else
{
api->putpixel(canvas, x, y, api->getpixel(maze_snapshot, x, y));
}
}
@ -348,7 +355,8 @@ void maze_render(magic_api * api, SDL_Surface * canvas)
void maze_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
maze_r = r;
maze_g = g;
@ -357,9 +365,7 @@ void maze_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED
void maze_line_callback_drag(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas,
SDL_Surface * snapshot ATTRIBUTE_UNUSED,
int x, int y)
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
{
magic_api *api = (magic_api *) ptr;
int xx, yy, idx;
@ -373,12 +379,17 @@ void maze_line_callback_drag(void *ptr, int which ATTRIBUTE_UNUSED,
x = floor(x / (MAZE_BLOCK_SIZE * 3)) * (MAZE_BLOCK_SIZE * 3);
y = floor(y / (MAZE_BLOCK_SIZE * 3)) * (MAZE_BLOCK_SIZE * 3);
for (yy = -MAZE_PAINT_RADIUS; yy < MAZE_PAINT_RADIUS; yy++) {
if (y + yy > 0 && y + yy < canvas->h) {
for (xx = -MAZE_PAINT_RADIUS; xx < MAZE_PAINT_RADIUS; xx++) {
if (x + xx > 0 && x + xx < canvas->w) {
for (yy = -MAZE_PAINT_RADIUS; yy < MAZE_PAINT_RADIUS; yy++)
{
if (y + yy > 0 && y + yy < canvas->h)
{
for (xx = -MAZE_PAINT_RADIUS; xx < MAZE_PAINT_RADIUS; xx++)
{
if (x + xx > 0 && x + xx < canvas->w)
{
idx = (y + yy) * canvas->w + (x + xx);
if (maze_mask[idx] == 0) {
if (maze_mask[idx] == 0)
{
maze_mask[idx] = num_maze_starts + 1;
}
maze_color[idx] = color;
@ -390,80 +401,77 @@ void maze_line_callback_drag(void *ptr, int which ATTRIBUTE_UNUSED,
}
void maze_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas)
{
if (maze_array == NULL)
{
maze_array = (Uint8 *) malloc(sizeof(Uint8) * canvas->w * canvas->h);
if (maze_array == NULL)
{
maze_array = (Uint8 *) malloc(sizeof(Uint8) * canvas->w * canvas->h);
if (maze_array == NULL)
{
fprintf(stderr, "maze: Cannot malloc() maze_array!\n");
return;
}
fprintf(stderr, "maze: Cannot malloc() maze_array!\n");
return;
}
}
if (maze_mask == NULL)
{
maze_mask = (Uint8 *) malloc(sizeof(Uint8) * canvas->w * canvas->h);
if (maze_mask == NULL)
{
maze_mask = (Uint8 *) malloc(sizeof(Uint8) * canvas->w * canvas->h);
if (maze_mask == NULL)
{
fprintf(stderr, "maze: Cannot malloc() maze_mask!\n");
return;
}
fprintf(stderr, "maze: Cannot malloc() maze_mask!\n");
return;
}
}
if (new_maze_mask == NULL)
{
new_maze_mask = (Uint8 *) malloc(sizeof(Uint8) * canvas->w * canvas->h);
if (new_maze_mask == NULL)
{
new_maze_mask = (Uint8 *) malloc(sizeof(Uint8) * canvas->w * canvas->h);
if (new_maze_mask == NULL)
{
fprintf(stderr, "new_maze: Cannot malloc() maze_mask!\n");
return;
}
fprintf(stderr, "new_maze: Cannot malloc() maze_mask!\n");
return;
}
}
if (maze_color == NULL)
{
maze_color = (Uint32 *) malloc(sizeof(Uint32) * canvas->w * canvas->h);
if (maze_color == NULL)
{
maze_color = (Uint32 *) malloc(sizeof(Uint32) * canvas->w * canvas->h);
if (maze_color == NULL)
{
fprintf(stderr, "maze: Cannot malloc() maze_color!\n");
return;
}
fprintf(stderr, "maze: Cannot malloc() maze_color!\n");
return;
}
}
if (maze_starts == NULL)
{
int w, h;
w = ceil(canvas->w / MAZE_BLOCK_SIZE);
h = ceil(canvas->h / MAZE_BLOCK_SIZE);
maze_starts_size = (w * h);
{
int w, h;
maze_starts = (maze_start_t *) malloc(sizeof(maze_start_t) * maze_starts_size);
if (maze_starts == NULL)
{
fprintf(stderr, "maze: Cannot malloc() maze_starts!\n");
return;
}
w = ceil(canvas->w / MAZE_BLOCK_SIZE);
h = ceil(canvas->h / MAZE_BLOCK_SIZE);
maze_starts_size = (w * h);
maze_starts = (maze_start_t *) malloc(sizeof(maze_start_t) * maze_starts_size);
if (maze_starts == NULL)
{
fprintf(stderr, "maze: Cannot malloc() maze_starts!\n");
return;
}
}
zero_maze_arrays(canvas);
if (maze_snapshot == NULL)
maze_snapshot = SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h,
canvas->format->BitsPerPixel, canvas->format->Rmask,
canvas->format->Gmask, canvas->format->Bmask,
canvas->format->Amask);
canvas->format->BitsPerPixel, canvas->format->Rmask,
canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
if (maze_snapshot != NULL)
SDL_BlitSurface(canvas, NULL, maze_snapshot, NULL);
}
void maze_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
zero_maze_arrays(canvas);
}
@ -485,13 +493,18 @@ void zero_maze_arrays(SDL_Surface * canvas)
memset(maze_color, 0, (sizeof(Uint32) * (canvas->w * canvas->h)));
}
void draw_hall(SDL_Surface * canvas, int x, int y) {
void draw_hall(SDL_Surface * canvas, int x, int y)
{
int xx, yy;
for (yy = -MAZE_BLOCK_SIZE / 2; yy < MAZE_BLOCK_SIZE / 2; yy++) {
if (y + yy >= 0 && y + yy < canvas->h) {
for (xx = -MAZE_BLOCK_SIZE / 2; xx < MAZE_BLOCK_SIZE / 2; xx++) {
if (x + xx >= 0 && x + xx < canvas->w) {
for (yy = -MAZE_BLOCK_SIZE / 2; yy < MAZE_BLOCK_SIZE / 2; yy++)
{
if (y + yy >= 0 && y + yy < canvas->h)
{
for (xx = -MAZE_BLOCK_SIZE / 2; xx < MAZE_BLOCK_SIZE / 2; xx++)
{
if (x + xx >= 0 && x + xx < canvas->w)
{
maze_array[(y + yy) * canvas->w + (x + xx)] = MAZE_HALL;
}
}
@ -499,42 +512,59 @@ void draw_hall(SDL_Surface * canvas, int x, int y) {
}
}
void maze_add_start(void) {
void maze_add_start(void)
{
maze_starts[num_maze_starts].x = maze_start_x;
maze_starts[num_maze_starts].y = maze_start_y;
num_maze_starts++;
}
void maze_collapse_contiguous(SDL_Surface * canvas) {
void maze_collapse_contiguous(SDL_Surface * canvas)
{
int i, x, y, touching, idx;
for (i = num_maze_starts; i > 0; i--) {
for (i = num_maze_starts; i > 0; i--)
{
touching = -1;
for (y = 1; y < canvas->h - 1 && touching == -1; y++) {
for (x = 1; x < canvas->w - 1 && touching == -1; x++) {
for (y = 1; y < canvas->h - 1 && touching == -1; y++)
{
for (x = 1; x < canvas->w - 1 && touching == -1; x++)
{
idx = (y * canvas->w + x);
if (maze_mask[idx] == i + 1) {
if (maze_mask[idx - 1] != 0 && maze_mask[idx - 1] != i + 1) {
if (maze_mask[idx] == i + 1)
{
if (maze_mask[idx - 1] != 0 && maze_mask[idx - 1] != i + 1)
{
touching = maze_mask[idx - 1];
} else if (maze_mask[idx + 1] != 0 && maze_mask[idx + 1] != i + 1) {
}
else if (maze_mask[idx + 1] != 0 && maze_mask[idx + 1] != i + 1)
{
touching = maze_mask[idx + 1];
} else if (maze_mask[idx - canvas->w] != 0 && maze_mask[idx - canvas->w] != i + 1) {
}
else if (maze_mask[idx - canvas->w] != 0 && maze_mask[idx - canvas->w] != i + 1)
{
touching = maze_mask[idx - canvas->w];
} else if (maze_mask[idx + canvas->w] != 0 && maze_mask[idx + canvas->w] != i + 1) {
}
else if (maze_mask[idx + canvas->w] != 0 && maze_mask[idx + canvas->w] != i + 1)
{
touching = maze_mask[idx + canvas->w];
}
}
}
}
if (touching != -1) {
if (touching != -1)
{
/* Touching someone else; turn all of our area
into that area */
for (y = 1; y < canvas->h; y++) {
for (x = 1; x < canvas->w; x++) {
for (y = 1; y < canvas->h; y++)
{
for (x = 1; x < canvas->w; x++)
{
idx = (y * canvas->w + x);
if (maze_mask[idx] == i + 1) {
if (maze_mask[idx] == i + 1)
{
maze_mask[idx] = touching;
}
}
@ -553,6 +583,8 @@ Uint8 maze_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UN
return 0;
}
void maze_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void maze_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}

View file

@ -45,29 +45,24 @@ SDL_Surface *metalpaint_get_icon(magic_api * api, int which);
char *metalpaint_get_name(magic_api * api, int which);
int metalpaint_get_group(magic_api * api, int which);
char *metalpaint_get_description(magic_api * api, int which, int mode);
static void do_metalpaint(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y);
static void do_metalpaint(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
void metalpaint_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void metalpaint_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void metalpaint_release(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void metalpaint_shutdown(magic_api * api);
void metalpaint_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
int metalpaint_requires_colors(magic_api * api, int which);
void metalpaint_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void metalpaint_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void metalpaint_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void metalpaint_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int metalpaint_modes(magic_api * api, int which);
Uint8 metalpaint_accepted_sizes(magic_api * api, int which, int mode);
Uint8 metalpaint_default_size(magic_api * api, int which, int mode);
void metalpaint_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void metalpaint_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
Uint32 metalpaint_api_version(void)
@ -81,8 +76,7 @@ int metalpaint_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%ssounds/magic/metalpaint.wav",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/metalpaint.wav", api->data_directory);
metalpaint_snd = Mix_LoadWAV(fname);
return (1);
@ -99,34 +93,28 @@ SDL_Surface *metalpaint_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/metalpaint.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/metalpaint.png", api->data_directory);
return (IMG_Load(fname));
}
// Return our names, localized:
char *metalpaint_get_name(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
char *metalpaint_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (strdup(gettext_noop("Metal Paint")));
}
// Return our groups:
int metalpaint_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int metalpaint_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_PAINTING;
}
// Return our descriptions, localized:
char *metalpaint_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return (strdup
(gettext_noop
("Click and drag the mouse to paint with a metallic color.")));
return (strdup(gettext_noop("Click and drag the mouse to paint with a metallic color.")));
}
#define METALPAINT_CYCLE 32
@ -143,8 +131,7 @@ static int metalpaint_gradient[METALPAINT_CYCLE] = {
// Do the effect:
static void do_metalpaint(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)
{
magic_api *api = (magic_api *) ptr;
int xx, yy;
@ -161,19 +148,16 @@ static void do_metalpaint(void *ptr, int which ATTRIBUTE_UNUSED,
g = (metalpaint_g * n) / 255;
b = (metalpaint_b * n) / 255;
api->putpixel(canvas, x + xx, y + yy,
SDL_MapRGB(canvas->format, r, g, b));
api->putpixel(canvas, x + xx, y + yy, SDL_MapRGB(canvas->format, r, g, b));
}
}
}
// Affect the canvas on drag:
void metalpaint_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1,
do_metalpaint);
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_metalpaint);
if (ox > x)
{
@ -200,8 +184,7 @@ void metalpaint_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void metalpaint_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
metalpaint_drag(api, which, canvas, last, x, y, x, y, update_rect);
}
@ -211,8 +194,7 @@ void metalpaint_release(magic_api * api ATTRIBUTE_UNUSED,
int which 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)
{
}
@ -224,8 +206,9 @@ void metalpaint_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void metalpaint_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void metalpaint_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g,
Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
metalpaint_r = min(255, r + 64);
metalpaint_g = min(255, g + 64);
@ -233,28 +216,22 @@ void metalpaint_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_
}
// Use colors:
int metalpaint_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int metalpaint_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 1;
}
void metalpaint_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void metalpaint_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int metalpaint_modes(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int metalpaint_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (MODE_PAINT);
}
@ -270,7 +247,9 @@ Uint8 metalpaint_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIB
return 2;
}
void metalpaint_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void metalpaint_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
metalpaint_size = size * 4;
}

View file

@ -51,12 +51,9 @@ SDL_Surface *mirror_flip_get_icon(magic_api *, int);
char *mirror_flip_get_name(magic_api *, int);
int mirror_flip_get_group(magic_api *, int);
char *mirror_flip_get_description(magic_api *, int, int);
void mirror_flip_drag(magic_api *, int, SDL_Surface *, SDL_Surface *, int,
int, int, int, SDL_Rect *);
void mirror_flip_release(magic_api *, int, SDL_Surface *, SDL_Surface *, int,
int, int, int, SDL_Rect *);
void mirror_flip_click(magic_api *, int, int, SDL_Surface *, SDL_Surface *,
int, int, SDL_Rect *);
void mirror_flip_drag(magic_api *, int, SDL_Surface *, SDL_Surface *, int, int, int, int, SDL_Rect *);
void mirror_flip_release(magic_api *, int, SDL_Surface *, SDL_Surface *, int, int, int, int, SDL_Rect *);
void mirror_flip_click(magic_api *, int, int, SDL_Surface *, SDL_Surface *, int, int, SDL_Rect *);
void mirror_flip_shutdown(magic_api *);
void mirror_flip_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
@ -66,19 +63,18 @@ void mirror_flip_switchout(magic_api *, int, int, SDL_Surface *);
int mirror_flip_modes(magic_api *, int);
Uint8 mirror_flip_accepted_sizes(magic_api * api, int which, int mode);
Uint8 mirror_flip_default_size(magic_api * api, int which, int mode);
void mirror_flip_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void mirror_flip_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
// No setup required:
int mirror_flip_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%ssounds/magic/mirror.wav",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/mirror.wav", api->data_directory);
snd_effects[TOOL_MIRROR] = Mix_LoadWAV(fname);
snprintf(fname, sizeof(fname), "%ssounds/magic/flip.wav",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/flip.wav", api->data_directory);
snd_effects[TOOL_FLIP] = Mix_LoadWAV(fname);
return (1);
@ -102,13 +98,11 @@ SDL_Surface *mirror_flip_get_icon(magic_api * api, int which)
if (which == TOOL_MIRROR)
{
snprintf(fname, sizeof(fname), "%simages/magic/mirror.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/mirror.png", api->data_directory);
}
else if (which == TOOL_FLIP)
{
snprintf(fname, sizeof(fname), "%simages/magic/flip.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/flip.png", api->data_directory);
}
return (IMG_Load(fname));
@ -126,15 +120,13 @@ char *mirror_flip_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
}
// Return our group (the same):
int mirror_flip_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int mirror_flip_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_PICTURE_WARPS;
}
// Return our descriptions, localized:
char *mirror_flip_get_description(magic_api * api ATTRIBUTE_UNUSED, int which,
int mode ATTRIBUTE_UNUSED)
char *mirror_flip_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
{
if (which == TOOL_MIRROR)
return (strdup(gettext_noop("Click to make a mirror image.")));
@ -150,8 +142,7 @@ void mirror_flip_drag(magic_api * api 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_Rect * update_rect ATTRIBUTE_UNUSED)
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
// No-op
}
@ -161,8 +152,7 @@ void mirror_flip_release(magic_api * api 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_Rect * update_rect ATTRIBUTE_UNUSED)
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
// No-op
}
@ -170,8 +160,7 @@ void mirror_flip_release(magic_api * api ATTRIBUTE_UNUSED,
// Affect the canvas on click:
void mirror_flip_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last,
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED,
SDL_Rect * update_rect)
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect)
{
int xx, yy;
SDL_Rect src, dest;
@ -229,40 +218,37 @@ void mirror_flip_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// We don't use colors:
void mirror_flip_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void mirror_flip_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
// We don't use colors:
int mirror_flip_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int mirror_flip_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 0;
}
void mirror_flip_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void mirror_flip_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int mirror_flip_modes(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int mirror_flip_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (MODE_FULLSCREEN);
}
Uint8 mirror_flip_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
Uint8 mirror_flip_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED)
{
return 0;
}
@ -272,6 +258,8 @@ Uint8 mirror_flip_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRI
return 0;
}
void mirror_flip_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void mirror_flip_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}

View file

@ -44,12 +44,9 @@
#define gettext_noop(String) String
#endif
static void mosaic_noise_pixel(void *ptr, SDL_Surface * canvas,
int noise_AMOUNT, int x, int y);
static void mosaic_blur_pixel(void *ptr, SDL_Surface * canvas,
SDL_Surface * last, int x, int y);
static void mosaic_sharpen_pixel(void *ptr, SDL_Surface * canvas,
SDL_Surface * last, int x, int y);
static void mosaic_noise_pixel(void *ptr, SDL_Surface * canvas, int noise_AMOUNT, int x, int y);
static void mosaic_blur_pixel(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
static void mosaic_sharpen_pixel(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
static void reset_mosaic_blured(SDL_Surface * canvas);
/* Prototypes */
@ -61,12 +58,9 @@ char *mosaic_get_name(magic_api *, int);
int mosaic_get_group(magic_api *, int);
char *mosaic_get_description(magic_api *, int, int);
void mosaic_paint(void *, int, SDL_Surface *, SDL_Surface *, int, int);
void mosaic_drag(magic_api *, int, SDL_Surface *, SDL_Surface *, int, int,
int, int, SDL_Rect *);
void mosaic_click(magic_api *, int, int, SDL_Surface *, SDL_Surface *, int,
int, SDL_Rect *);
void mosaic_release(magic_api *, int, SDL_Surface *, SDL_Surface *, int, int,
SDL_Rect *);
void mosaic_drag(magic_api *, int, SDL_Surface *, SDL_Surface *, int, int, int, int, SDL_Rect *);
void mosaic_click(magic_api *, int, int, SDL_Surface *, SDL_Surface *, int, int, SDL_Rect *);
void mosaic_release(magic_api *, int, SDL_Surface *, SDL_Surface *, int, int, SDL_Rect *);
void mosaic_shutdown(magic_api *);
void mosaic_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
@ -76,7 +70,8 @@ void mosaic_switchout(magic_api *, int, int, SDL_Surface *);
int mosaic_modes(magic_api *, int);
Uint8 mosaic_accepted_sizes(magic_api * api, int which, int mode);
Uint8 mosaic_default_size(magic_api * api, int which, int mode);
void mosaic_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void mosaic_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
static const int mosaic_AMOUNT = 300;
@ -112,8 +107,7 @@ const int mosaic_groups[mosaic_NUM_TOOLS] = {
};
const char *mosaic_descs[mosaic_NUM_TOOLS][2] = {
{gettext_noop
("Click and drag the mouse to add a mosaic effect to parts of your picture."),
{gettext_noop("Click and drag the mouse to add a mosaic effect to parts of your picture."),
gettext_noop("Click to add a mosaic effect to your entire picture."),},
};
@ -131,8 +125,7 @@ int mosaic_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
for (i = 0; i < mosaic_NUM_TOOLS; i++)
{
snprintf(fname, sizeof(fname), "%ssounds/magic/%s", api->data_directory,
mosaic_snd_filenames[i]);
snprintf(fname, sizeof(fname), "%ssounds/magic/%s", api->data_directory, mosaic_snd_filenames[i]);
mosaic_snd_effect[i] = Mix_LoadWAV(fname);
}
@ -149,8 +142,7 @@ SDL_Surface *mosaic_get_icon(magic_api * api, int which)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory,
mosaic_icon_filenames[which]);
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, mosaic_icon_filenames[which]);
return (IMG_Load(fname));
}
@ -167,8 +159,7 @@ int mosaic_get_group(magic_api * api ATTRIBUTE_UNUSED, int which)
}
// Return our descriptions, localized:
char *mosaic_get_description(magic_api * api ATTRIBUTE_UNUSED, int which,
int mode)
char *mosaic_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode)
{
return (strdup(gettext_noop(mosaic_descs[which][mode - 1])));
}
@ -181,21 +172,18 @@ static int mosaic_grey(Uint8 r1, Uint8 g1, Uint8 b1)
// Do the effect for the full image
static void do_mosaic_full(void *ptr, SDL_Surface * canvas,
SDL_Surface * last ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
SDL_Surface * last ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
magic_api *api = (magic_api *) ptr;
int x, y;
Uint32 amask =
~(canvas->format->Rmask | canvas->format->Gmask | canvas->format->Bmask);
Uint32 amask = ~(canvas->format->Rmask | canvas->format->Gmask | canvas->format->Bmask);
SDL_Surface *mosaic_temp = SDL_CreateRGBSurface(SDL_SWSURFACE,
canvas->w,
canvas->h,
canvas->format->
BitsPerPixel,
canvas->format->BitsPerPixel,
canvas->format->Rmask,
canvas->format->Gmask,
canvas->format->Bmask,
@ -229,21 +217,17 @@ static void do_mosaic_full(void *ptr, SDL_Surface * canvas,
/* Paint the brush, noise is yet done at switchin,
blurs 2 pixels around the brush in order to get sharpen well done.*/
void mosaic_paint(void *ptr_to_api, 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)
{
int i, j, pix_row_pos;
magic_api *api = (magic_api *) ptr_to_api;
for (j = max(0, y - mosaic_RADIUS - 2);
j < min(canvas->h, y + mosaic_RADIUS + 2); j++)
for (j = max(0, y - mosaic_RADIUS - 2); j < min(canvas->h, y + mosaic_RADIUS + 2); j++)
{
pix_row_pos = j * canvas->w;
for (i = max(0, x - mosaic_RADIUS - 2);
i < min(canvas->w, x + mosaic_RADIUS + 2); i++)
if (!mosaic_blured[pix_row_pos + i]
&& api->in_circle(i - x, j - y, mosaic_RADIUS + 2))
for (i = max(0, x - mosaic_RADIUS - 2); i < min(canvas->w, x + mosaic_RADIUS + 2); i++)
if (!mosaic_blured[pix_row_pos + i] && api->in_circle(i - x, j - y, mosaic_RADIUS + 2))
{
mosaic_blur_pixel(api, canvas_blur, canvas_noise, i, j);
mosaic_blured[pix_row_pos + i] = 1; /* Track what are yet blured */
@ -262,8 +246,7 @@ void mosaic_paint(void *ptr_to_api, int which ATTRIBUTE_UNUSED,
// Affect the canvas on drag:
void mosaic_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line(api, which, canvas, last, ox, oy, x, y, 1, mosaic_paint);
@ -277,8 +260,7 @@ void mosaic_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void mosaic_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
if (mode == MODE_FULLSCREEN)
@ -302,8 +284,7 @@ void mosaic_release(magic_api * api ATTRIBUTE_UNUSED,
int which 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)
{
}
@ -323,21 +304,21 @@ void mosaic_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void mosaic_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void mosaic_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
// Use colors:
int mosaic_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int mosaic_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 0;
}
//Add noise to a pixel
static void mosaic_noise_pixel(void *ptr, SDL_Surface * canvas,
int noise_AMOUNT, int x, int y)
static void mosaic_noise_pixel(void *ptr, SDL_Surface * canvas, int noise_AMOUNT, int x, int y)
{
magic_api *api = (magic_api *) ptr;
@ -345,21 +326,16 @@ static void mosaic_noise_pixel(void *ptr, SDL_Surface * canvas,
double temp2[3];
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++)
{
temp2[k] =
clamp(0.0, (int) temp[k] - (rand() % noise_AMOUNT) + noise_AMOUNT / 2.0,
255.0);
temp2[k] = clamp(0.0, (int)temp[k] - (rand() % noise_AMOUNT) + noise_AMOUNT / 2.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]));
}
//Blur a pixel
static void mosaic_blur_pixel(void *ptr, SDL_Surface * canvas,
SDL_Surface * last, int x, int y)
static void mosaic_blur_pixel(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
magic_api *api = (magic_api *) ptr;
int i, j, k;
@ -384,8 +360,7 @@ static void mosaic_blur_pixel(void *ptr, SDL_Surface * canvas,
for (j = -2; j < 3; j++)
{
//Add the pixels around the current one wieghted
SDL_GetRGB(api->getpixel(last, x + i, y + j), last->format, &temp[0],
&temp[1], &temp[2]);
SDL_GetRGB(api->getpixel(last, x + i, y + j), last->format, &temp[0], &temp[1], &temp[2]);
for (k = 0; k < 3; k++)
{
blurValue[k] += temp[k] * weight[i + 2][j + 2];
@ -396,14 +371,11 @@ static void mosaic_blur_pixel(void *ptr, SDL_Surface * canvas,
{
blurValue[k] /= 273;
}
api->putpixel(canvas, x, y,
SDL_MapRGB(canvas->format, blurValue[0], blurValue[1],
blurValue[2]));
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, blurValue[0], blurValue[1], blurValue[2]));
}
//Sharpen a pixel
static void mosaic_sharpen_pixel(void *ptr, SDL_Surface * canvas,
SDL_Surface * last, int x, int y)
static void mosaic_sharpen_pixel(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
magic_api *api = (magic_api *) ptr;
@ -431,8 +403,7 @@ static void mosaic_sharpen_pixel(void *ptr, SDL_Surface * canvas,
for (j = -1; j < 2; j++)
{
//No need to check if inside canvas, getpixel does it for us.
SDL_GetRGB(api->getpixel(last, x + i, y + j), last->format, &r1, &g1,
&b1);
SDL_GetRGB(api->getpixel(last, x + i, y + j), last->format, &r1, &g1, &b1);
grey = mosaic_grey(r1, g1, b1);
sobel_1 += grey * sobel_weights_1[i + 1][j + 1];
sobel_2 += grey * sobel_weights_2[i + 1][j + 1];
@ -451,8 +422,7 @@ static void mosaic_sharpen_pixel(void *ptr, SDL_Surface * canvas,
}
void mosaic_switchin(magic_api * api, int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas)
void mosaic_switchin(magic_api * api, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas)
{
int y, x;
Uint32 amask;
@ -464,16 +434,13 @@ void mosaic_switchin(magic_api * api, int which ATTRIBUTE_UNUSED,
exit(1);
}
amask =
~(canvas->format->Rmask | canvas->format->Gmask | canvas->format->Bmask);
amask = ~(canvas->format->Rmask | canvas->format->Gmask | canvas->format->Bmask);
canvas_noise = SDL_CreateRGBSurface(SDL_SWSURFACE,
canvas->w,
canvas->h,
canvas->format->BitsPerPixel,
canvas->format->Rmask,
canvas->format->Gmask,
canvas->format->Bmask, amask);
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, amask);
SDL_BlitSurface(canvas, NULL, canvas_noise, NULL);
@ -489,23 +456,18 @@ void mosaic_switchin(magic_api * api, int which ATTRIBUTE_UNUSED,
canvas->w,
canvas->h,
canvas->format->BitsPerPixel,
canvas->format->Rmask,
canvas->format->Gmask,
canvas->format->Bmask, amask);
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, amask);
canvas_sharp = SDL_CreateRGBSurface(SDL_SWSURFACE,
canvas->w,
canvas->h,
canvas->format->BitsPerPixel,
canvas->format->Rmask,
canvas->format->Gmask,
canvas->format->Bmask, amask);
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, amask);
reset_mosaic_blured(canvas);
}
void mosaic_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
SDL_FreeSurface(canvas_noise);
SDL_FreeSurface(canvas_blur);
@ -542,8 +504,9 @@ Uint8 mosaic_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_
return 4;
}
void mosaic_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void mosaic_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
mosaic_RADIUS = size * 4;
}

View file

@ -48,20 +48,14 @@
#define gettext_noop(String) String
#endif
static void mosaic_shaped_sharpen_pixel(void *ptr, SDL_Surface * canvas,
SDL_Surface * last, int x, int y);
static void mosaic_shaped_sharpen_pixel(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
static void reset_counter(SDL_Surface * canvas, Uint8 * counter);
static void fill_square(magic_api * api, SDL_Surface * canvas, int x, int y,
int size, Uint32 color);
static void fill_square(magic_api * api, SDL_Surface * canvas, int x, int y, int size, Uint32 color);
static void deform(magic_api * api, SDL_Surface * srfc);
static void do_mosaic_shaped_full(void *ptr, SDL_Surface * canvas,
SDL_Surface * last, int which,
SDL_Rect * update_rect);
static void mosaic_shaped_fill(void *ptr_to_api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y);
static void mosaic_shaped_paint(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y);
SDL_Surface * last, int which, SDL_Rect * update_rect);
static void mosaic_shaped_fill(void *ptr_to_api, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
static void mosaic_shaped_paint(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
Uint32 mosaic_shaped_api_version(void);
int mosaic_shaped_init(magic_api * api, Uint32 disabled_features);
@ -73,16 +67,13 @@ int mosaic_shaped_get_group(magic_api * api, int which);
char *mosaic_shaped_get_description(magic_api * api, int which, int mode);
void mosaic_shaped_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void mosaic_shaped_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x,
int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void mosaic_shaped_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last, int x,
int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void mosaic_shaped_shutdown(magic_api * api);
@ -91,28 +82,25 @@ void mosaic_shaped_set_color(magic_api * api, int which, SDL_Surface * canvas,
int mosaic_shaped_requires_colors(magic_api * api, int which);
void mosaic_shaped_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void mosaic_shaped_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void mosaic_shaped_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void mosaic_shaped_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int mosaic_shaped_modes(magic_api * api, int which);
int scan_fill(magic_api * api, SDL_Surface * canvas, SDL_Surface * srfc,
int x, int y, int fill_edge, int fill_tile, int size,
Uint32 color);
int x, int y, int fill_edge, int fill_tile, int size, Uint32 color);
Uint8 mosaic_shaped_accepted_sizes(magic_api * api, int which, int mode);
Uint8 mosaic_shaped_default_size(magic_api * api, int which, int mode);
void mosaic_shaped_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void mosaic_shaped_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
Uint8 *mosaic_shaped_counted;
Uint8 *mosaic_shaped_done;
Uint8 mosaic_shaped_r, mosaic_shaped_g, mosaic_shaped_b;
int mosaic_shaped_average_r, mosaic_shaped_average_g, mosaic_shaped_average_b,
mosaic_shaped_average_count;
int mosaic_shaped_average_r, mosaic_shaped_average_g, mosaic_shaped_average_b, mosaic_shaped_average_count;
Uint32 pixel_average, black, white;
enum
@ -155,20 +143,17 @@ const char *mosaic_shaped_names[mosaic_shaped_NUM_TOOLS] = {
const char *mosaic_shaped_descs[mosaic_shaped_NUM_TOOLS][2] = {
{
gettext_noop
("Click and drag the mouse to add a square mosaic to parts of your picture."),
gettext_noop("Click and drag the mouse to add a square mosaic to parts of your picture."),
gettext_noop("Click to add a square mosaic to your entire picture."),
},
{
gettext_noop
("Click and drag the mouse to add a hexagonal mosaic to parts of your picture."),
gettext_noop("Click and drag the mouse to add a hexagonal mosaic to parts of your picture."),
gettext_noop("Click to add a hexagonal mosaic to your entire picture."),
},
{
gettext_noop
("Click and drag the mouse to add an irregular mosaic to parts of your picture."),
gettext_noop("Click and drag the mouse to add an irregular mosaic to parts of your picture."),
gettext_noop("Click to add an irregular mosaic to your entire picture."),
},
};
@ -188,8 +173,7 @@ int mosaic_shaped_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSE
for (i = 0; i < mosaic_shaped_NUM_TOOLS; i++)
{
snprintf(fname, sizeof(fname), "%ssounds/magic/%s", api->data_directory,
mosaic_shaped_snd_filenames[i]);
snprintf(fname, sizeof(fname), "%ssounds/magic/%s", api->data_directory, mosaic_shaped_snd_filenames[i]);
mosaic_shaped_snd_effect[i] = Mix_LoadWAV(fname);
}
@ -206,8 +190,7 @@ SDL_Surface *mosaic_shaped_get_icon(magic_api * api, int which)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory,
mosaic_shaped_icon_filenames[which]);
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, mosaic_shaped_icon_filenames[which]);
return (IMG_Load(fname));
}
@ -218,15 +201,13 @@ char *mosaic_shaped_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
}
// Return our groups (all the same!)
int mosaic_shaped_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int mosaic_shaped_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_DISTORTS;
}
// Return our descriptions, localized:
char *mosaic_shaped_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which, int mode)
char *mosaic_shaped_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode)
{
return (strdup(gettext_noop(mosaic_shaped_descs[which][mode - 1])));
}
@ -240,16 +221,13 @@ static int mosaic_shaped_grey(Uint8 r1, Uint8 g1, Uint8 b1)
// Do the effect for the full image
static void do_mosaic_shaped_full(void *ptr, SDL_Surface * canvas,
SDL_Surface * last ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
int i, j, size;
Uint32 mosaic_shaped_color;
magic_api *api = (magic_api *) ptr;
mosaic_shaped_color =
SDL_MapRGBA(canvas->format, mosaic_shaped_r, mosaic_shaped_g,
mosaic_shaped_b, 0);
mosaic_shaped_color = SDL_MapRGBA(canvas->format, mosaic_shaped_r, mosaic_shaped_g, mosaic_shaped_b, 0);
for (i = 3; i < canvas->w - 3; i += 2)
{
@ -266,8 +244,7 @@ static void do_mosaic_shaped_full(void *ptr, SDL_Surface * canvas,
mosaic_shaped_average_g = 0;
mosaic_shaped_average_b = 0;
mosaic_shaped_average_count = 0;
scan_fill(api, canvas, canvas_shaped, i, j, 1, 0, 1,
mosaic_shaped_color);
scan_fill(api, canvas, canvas_shaped, i, j, 1, 0, 1, mosaic_shaped_color);
if (mosaic_shaped_average_count > 0)
{
@ -278,11 +255,8 @@ static void do_mosaic_shaped_full(void *ptr, SDL_Surface * canvas,
mosaic_shaped_average_r /
mosaic_shaped_average_count,
mosaic_shaped_average_g /
mosaic_shaped_average_count,
mosaic_shaped_average_b /
mosaic_shaped_average_count);
scan_fill(api, canvas, canvas_shaped, i, j, 0, 1, size,
pixel_average);
mosaic_shaped_average_count, mosaic_shaped_average_b / mosaic_shaped_average_count);
scan_fill(api, canvas, canvas_shaped, i, j, 0, 1, size, pixel_average);
}
}
}
@ -291,9 +265,7 @@ static void do_mosaic_shaped_full(void *ptr, SDL_Surface * canvas,
/* Fills a tesera */
static void mosaic_shaped_fill(void *ptr_to_api, 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)
{
Uint32 mosaic_shaped_color;
int size;
@ -301,9 +273,7 @@ static void mosaic_shaped_fill(void *ptr_to_api, int which ATTRIBUTE_UNUSED,
x = clamp(0, x, canvas->w - 1);
y = clamp(0, y, canvas->h - 1);
mosaic_shaped_color =
SDL_MapRGBA(canvas->format, mosaic_shaped_r, mosaic_shaped_g,
mosaic_shaped_b, 0);
mosaic_shaped_color = SDL_MapRGBA(canvas->format, mosaic_shaped_r, mosaic_shaped_g, mosaic_shaped_b, 0);
mosaic_shaped_average_r = 0;
mosaic_shaped_average_g = 0;
mosaic_shaped_average_b = 0;
@ -331,8 +301,7 @@ static void mosaic_shaped_fill(void *ptr_to_api, int which ATTRIBUTE_UNUSED,
// Affect the canvas on drag:
void mosaic_shaped_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line(api, which, canvas, last, ox, oy, x, y, 1, mosaic_shaped_fill);
update_rect->x = min(ox, x) - mosaic_shaped_pattern->w;
@ -344,8 +313,7 @@ void mosaic_shaped_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void mosaic_shaped_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x,
int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
if (mode == MODE_FULLSCREEN)
{
@ -367,8 +335,7 @@ void mosaic_shaped_release(magic_api * api ATTRIBUTE_UNUSED,
int which 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)
{
}
@ -388,8 +355,9 @@ void mosaic_shaped_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void mosaic_shaped_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void mosaic_shaped_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r,
Uint8 g, Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
mosaic_shaped_r = r;
mosaic_shaped_g = g;
@ -397,16 +365,14 @@ void mosaic_shaped_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBU
}
// Use colors:
int mosaic_shaped_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int mosaic_shaped_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 1;
}
//Sharpen a pixel
static void mosaic_shaped_sharpen_pixel(void *ptr,
SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last, int x, int y)
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last, int x, int y)
{
magic_api *api = (magic_api *) ptr;
Uint8 r1, g1, b1;
@ -432,8 +398,7 @@ static void mosaic_shaped_sharpen_pixel(void *ptr,
for (j = -1; j < 2; j++)
{
//No need to check if inside canvas, getpixel does it for us.
SDL_GetRGB(api->getpixel(last, x + i, y + j), last->format, &r1, &g1,
&b1);
SDL_GetRGB(api->getpixel(last, x + i, y + j), last->format, &r1, &g1, &b1);
grey = mosaic_shaped_grey(r1, g1, b1);
sobel_1 += grey * sobel_weights_1[i + 1][j + 1];
sobel_2 += grey * sobel_weights_2[i + 1][j + 1];
@ -445,15 +410,13 @@ static void mosaic_shaped_sharpen_pixel(void *ptr,
if (temp > 25)
{
api->putpixel(canvas_shaped, x, y,
SDL_MapRGBA(canvas_shaped->format, 0, 0, 0, 0));
api->putpixel(canvas_shaped, x, y, SDL_MapRGBA(canvas_shaped->format, 0, 0, 0, 0));
}
}
void mosaic_shaped_switchin(magic_api * api, int which,
int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas)
void mosaic_shaped_switchin(magic_api * api, int which, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas)
{
int y, x;
int i, j;
@ -461,8 +424,7 @@ void mosaic_shaped_switchin(magic_api * api, int which,
SDL_Surface *surf_aux, *tmp, *tmp2;
Uint32 amask;
mosaic_shaped_counted =
(Uint8 *) malloc(sizeof(Uint8) * (canvas->w * canvas->h));
mosaic_shaped_counted = (Uint8 *) malloc(sizeof(Uint8) * (canvas->w * canvas->h));
if (mosaic_shaped_counted == NULL)
{
@ -470,8 +432,7 @@ void mosaic_shaped_switchin(magic_api * api, int which,
exit(1);
}
mosaic_shaped_done =
(Uint8 *) malloc(sizeof(Uint8) * (canvas->w * canvas->h));
mosaic_shaped_done = (Uint8 *) malloc(sizeof(Uint8) * (canvas->w * canvas->h));
if (mosaic_shaped_done == NULL)
{
@ -479,15 +440,13 @@ void mosaic_shaped_switchin(magic_api * api, int which,
exit(1);
}
amask =
~(canvas->format->Rmask | canvas->format->Gmask | canvas->format->Bmask);
amask = ~(canvas->format->Rmask | canvas->format->Gmask | canvas->format->Bmask);
tmp = SDL_CreateRGBSurface(SDL_SWSURFACE,
canvas->w,
canvas->h,
canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask,
canvas->format->Bmask, amask);
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, amask);
canvas_shaped = SDL_ConvertSurfaceFormat(tmp, SDL_PIXELFORMAT_RGB888, 0);
SDL_FreeSurface(tmp);
@ -495,8 +454,7 @@ void mosaic_shaped_switchin(magic_api * api, int which,
canvas->w + 10,
canvas->h + 10,
canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask,
canvas->format->Bmask, amask);
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, amask);
surf_aux = SDL_ConvertSurfaceFormat(tmp2, SDL_PIXELFORMAT_RGB888, 0);
SDL_FreeSurface(tmp2);
@ -509,58 +467,41 @@ void mosaic_shaped_switchin(magic_api * api, int which,
16,
canvas->format->BitsPerPixel,
canvas->format->Rmask,
canvas->format->Gmask,
canvas->format->Bmask,
amask);
canvas->format->Gmask, canvas->format->Bmask, amask);
SDL_FillRect(mosaic_shaped_pattern, NULL,
SDL_MapRGBA(mosaic_shaped_pattern->format, 255, 255, 255,
SDL_ALPHA_OPAQUE));
SDL_MapRGBA(mosaic_shaped_pattern->format, 255, 255, 255, SDL_ALPHA_OPAQUE));
/* Shape */
for (i = 0; i < mosaic_shaped_pattern->w; i++)
{
api->putpixel(mosaic_shaped_pattern, 0, i,
SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0,
SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, 0, i, SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, mosaic_shaped_pattern->w - 1, i,
SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0,
SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, i, 0,
SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0,
SDL_ALPHA_OPAQUE));
SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, i, 0, SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, i, mosaic_shaped_pattern->w - 1,
SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0,
SDL_ALPHA_OPAQUE));
SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0, SDL_ALPHA_OPAQUE));
}
/* Shadow */
for (i = 1; i < mosaic_shaped_pattern->w - 1; i++)
{
api->putpixel(mosaic_shaped_pattern, 1, i,
SDL_MapRGBA(mosaic_shaped_pattern->format, 128, 128, 128,
SDL_ALPHA_OPAQUE));
SDL_MapRGBA(mosaic_shaped_pattern->format, 128, 128, 128, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, mosaic_shaped_pattern->w - 2, i,
SDL_MapRGBA(mosaic_shaped_pattern->format, 128, 128, 128,
SDL_ALPHA_OPAQUE));
SDL_MapRGBA(mosaic_shaped_pattern->format, 128, 128, 128, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, i, 1,
SDL_MapRGBA(mosaic_shaped_pattern->format, 128, 128, 128,
SDL_ALPHA_OPAQUE));
SDL_MapRGBA(mosaic_shaped_pattern->format, 128, 128, 128, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, i, mosaic_shaped_pattern->w - 2,
SDL_MapRGBA(mosaic_shaped_pattern->format, 128, 128, 128,
SDL_ALPHA_OPAQUE));
SDL_MapRGBA(mosaic_shaped_pattern->format, 128, 128, 128, SDL_ALPHA_OPAQUE));
}
api->putpixel(mosaic_shaped_pattern, 2, 2,
SDL_MapRGBA(mosaic_shaped_pattern->format, 152, 152, 152,
SDL_ALPHA_OPAQUE));
SDL_MapRGBA(mosaic_shaped_pattern->format, 152, 152, 152, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, 2, mosaic_shaped_pattern->h - 3,
SDL_MapRGBA(mosaic_shaped_pattern->format, 152, 152, 152,
SDL_ALPHA_OPAQUE));
SDL_MapRGBA(mosaic_shaped_pattern->format, 152, 152, 152, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, mosaic_shaped_pattern->w - 3, 2,
SDL_MapRGBA(mosaic_shaped_pattern->format, 152, 152, 152,
SDL_ALPHA_OPAQUE));
SDL_MapRGBA(mosaic_shaped_pattern->format, 152, 152, 152, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, mosaic_shaped_pattern->w - 3,
mosaic_shaped_pattern->h - 3,
SDL_MapRGBA(mosaic_shaped_pattern->format, 152, 152, 152,
SDL_ALPHA_OPAQUE));
SDL_MapRGBA(mosaic_shaped_pattern->format, 152, 152, 152, SDL_ALPHA_OPAQUE));
}
else if (which == TOOL_IRREGULAR)
{
@ -569,68 +510,38 @@ void mosaic_shaped_switchin(magic_api * api, int which,
64,
canvas->format->BitsPerPixel,
canvas->format->Rmask,
canvas->format->Gmask,
canvas->format->Bmask,
amask);
canvas->format->Gmask, canvas->format->Bmask, amask);
SDL_FillRect(mosaic_shaped_pattern, NULL,
SDL_MapRGBA(mosaic_shaped_pattern->format, 255, 255, 255,
SDL_ALPHA_OPAQUE));
SDL_MapRGBA(mosaic_shaped_pattern->format, 255, 255, 255, SDL_ALPHA_OPAQUE));
/* Start/end of lines taken from the original mosaic_shaped_irregular_pattern.png */
api->line(api, which, mosaic_shaped_pattern, NULL, 0, 8, 36, 23, 1,
mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 0, 43, 36, 23, 1,
mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 0, 26, 28, 53, 1,
mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 0, 54, 10, 63, 1,
mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 55, 0, 36, 23, 1,
mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 63, 43, 28, 53, 1,
mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 24, 63, 28, 53, 1,
mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 24, 0, 27, 19, 1,
mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 63, 8, 50, 6, 1,
mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 10, 0, 4, 10, 1,
mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 10, 0, 25, 7, 1,
mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 41, 0, 26, 12, 1,
mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 41, 63, 28, 53, 1,
mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 41, 63, 56, 58, 1,
mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 63, 53, 55, 45, 1,
mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 55, 63, 59, 49, 1,
mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 10, 63, 20, 45, 1,
mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 63, 26, 40, 18, 1,
mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 4, 30, 14, 14, 1,
mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 18, 33, 21, 17, 1,
mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 23, 48, 29, 27, 1,
mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 37, 50, 36, 23, 1,
mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 44, 13, 37, 3, 1,
mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 59, 24, 55, 7, 1,
mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 49, 47, 54, 23, 1,
mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 36, 35, 51, 37, 1,
mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 61, 44, 52, 31, 1,
mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 0, 8, 36, 23, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 0, 43, 36, 23, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 0, 26, 28, 53, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 0, 54, 10, 63, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 55, 0, 36, 23, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 63, 43, 28, 53, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 24, 63, 28, 53, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 24, 0, 27, 19, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 63, 8, 50, 6, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 10, 0, 4, 10, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 10, 0, 25, 7, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 41, 0, 26, 12, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 41, 63, 28, 53, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 41, 63, 56, 58, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 63, 53, 55, 45, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 55, 63, 59, 49, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 10, 63, 20, 45, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 63, 26, 40, 18, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 4, 30, 14, 14, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 18, 33, 21, 17, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 23, 48, 29, 27, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 37, 50, 36, 23, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 44, 13, 37, 3, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 59, 24, 55, 7, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 49, 47, 54, 23, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 36, 35, 51, 37, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 61, 44, 52, 31, 1, mosaic_shaped_paint);
}
else if (which == TOOL_HEX)
@ -640,45 +551,24 @@ void mosaic_shaped_switchin(magic_api * api, int which,
28,
canvas->format->BitsPerPixel,
canvas->format->Rmask,
canvas->format->Gmask,
canvas->format->Bmask,
amask);
canvas->format->Gmask, canvas->format->Bmask, amask);
SDL_FillRect(mosaic_shaped_pattern, NULL,
SDL_MapRGBA(mosaic_shaped_pattern->format, 255, 255, 255,
SDL_ALPHA_OPAQUE));
SDL_MapRGBA(mosaic_shaped_pattern->format, 255, 255, 255, SDL_ALPHA_OPAQUE));
api->line(api, which, mosaic_shaped_pattern, NULL, 0, 16, 8, 0, 1,
mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 8, 0, 26, 0, 1,
mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 26, 0, 32, 14, 1,
mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 32, 14, 26, 27, 1,
mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 32, 14, 47, 14, 1,
mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 0, 13, 8, 27, 1,
mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 0, 16, 8, 0, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 8, 0, 26, 0, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 26, 0, 32, 14, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 32, 14, 26, 27, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 32, 14, 47, 14, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 0, 13, 8, 27, 1, mosaic_shaped_paint);
//make pattern more accurate
api->putpixel(mosaic_shaped_pattern, 9, 27,
SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0,
SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, 9, 26,
SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0,
SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, 26, 27,
SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0,
SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, 26, 26,
SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0,
SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, 26, 25,
SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0,
SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, 25, 27,
SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0,
SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, 9, 27, SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, 9, 26, SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, 26, 27, SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, 26, 26, SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, 26, 25, SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, 25, 27, SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0, SDL_ALPHA_OPAQUE));
}
@ -728,9 +618,7 @@ void mosaic_shaped_switchin(magic_api * api, int which,
canvas->w,
canvas->h,
canvas->format->BitsPerPixel,
canvas->format->Rmask,
canvas->format->Gmask,
canvas->format->Bmask, amask);
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, amask);
SDL_BlitSurface(canvas, NULL, canvas_back, NULL);
if (which != TOOL_SQUARE) /* The pattern for square is small enouth to not need an additional shape */
@ -748,8 +636,7 @@ void mosaic_shaped_switchin(magic_api * api, int which,
void mosaic_shaped_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
SDL_FreeSurface(canvas_shaped);
SDL_FreeSurface(canvas_back);
@ -757,8 +644,7 @@ void mosaic_shaped_switchout(magic_api * api ATTRIBUTE_UNUSED,
free(mosaic_shaped_counted);
}
int mosaic_shaped_modes(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int mosaic_shaped_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (MODE_PAINT | MODE_FULLSCREEN);
}
@ -778,8 +664,7 @@ void reset_counter(SDL_Surface * canvas, Uint8 * counter)
int scan_fill_count;
int scan_fill(magic_api * api, SDL_Surface * canvas, SDL_Surface * srfc,
int x, int y, int fill_edge, int fill_tile, int size,
Uint32 color)
int x, int y, int fill_edge, int fill_tile, int size, Uint32 color)
{
int leftx, rightx;
Uint8 r, g, b, a;
@ -829,8 +714,7 @@ int scan_fill(magic_api * api, SDL_Surface * canvas, SDL_Surface * srfc,
}
else
{
SDL_GetRGBA(api->getpixel(canvas_back, x, y), canvas_back->format, &r, &g,
&b, &a);
SDL_GetRGBA(api->getpixel(canvas_back, x, y), canvas_back->format, &r, &g, &b, &a);
mosaic_shaped_average_r += r;
mosaic_shaped_average_g += g;
mosaic_shaped_average_b += b;
@ -839,17 +723,13 @@ int scan_fill(magic_api * api, SDL_Surface * canvas, SDL_Surface * srfc,
}
/* Search right */
while (scan_fill
(api, canvas, srfc, rightx, y, fill_edge, fill_tile, size, color)
&& (rightx < canvas->w))
while (scan_fill(api, canvas, srfc, rightx, y, fill_edge, fill_tile, size, color) && (rightx < canvas->w))
{
rightx++;
}
/* Search left */
while (scan_fill
(api, canvas, srfc, leftx, y, fill_edge, fill_tile, size, color)
&& (leftx >= 0))
while (scan_fill(api, canvas, srfc, leftx, y, fill_edge, fill_tile, size, color) && (leftx >= 0))
{
leftx--;
}
@ -859,14 +739,12 @@ int scan_fill(magic_api * api, SDL_Surface * canvas, SDL_Surface * srfc,
{
if (y > 0)
{
scan_fill(api, canvas, srfc, i, y - 1, fill_edge, fill_tile, size,
color);
scan_fill(api, canvas, srfc, i, y - 1, fill_edge, fill_tile, size, color);
}
if (y + 1 < canvas->w)
{
scan_fill(api, canvas, srfc, i, y + 1, fill_edge, fill_tile, size,
color);
scan_fill(api, canvas, srfc, i, y + 1, fill_edge, fill_tile, size, color);
}
}
@ -875,8 +753,7 @@ int scan_fill(magic_api * api, SDL_Surface * canvas, SDL_Surface * srfc,
}
void fill_square(magic_api * api, SDL_Surface * canvas, int x, int y,
int size, Uint32 color)
void fill_square(magic_api * api, SDL_Surface * canvas, int x, int y, int size, Uint32 color)
{
int i, j;
@ -894,23 +771,19 @@ void deform(magic_api * api, SDL_Surface * srfc)
for (j = 0; j < srfc->h; j++)
for (i = 0; i < srfc->w; i++)
{
api->putpixel(srfc, i, j,
api->getpixel(srfc, i + sin(j * M_PI / 90) * 10 + 10, j));
api->putpixel(srfc, i, j, api->getpixel(srfc, i + sin(j * M_PI / 90) * 10 + 10, j));
}
for (i = 0; i < srfc->w; i++)
for (j = 0; j < srfc->h; j++)
{
api->putpixel(srfc, i, j,
api->getpixel(srfc, i, j + sin(i * M_PI / 90) * 10 + 10));
api->putpixel(srfc, i, j, api->getpixel(srfc, i, j + sin(i * M_PI / 90) * 10 + 10));
}
}
/* Paints a 2 pixel square with black and shadows around 3 more pixels */
static void mosaic_shaped_paint(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)
{
magic_api *api = (magic_api *) ptr;
int radius, shadow;
@ -957,8 +830,7 @@ static void mosaic_shaped_paint(void *ptr, int which ATTRIBUTE_UNUSED,
if (b > 10)
b -= 9;
api->putpixel(canvas, ii, jj,
SDL_MapRGBA(canvas->format, r, g, b, SDL_ALPHA_OPAQUE));
api->putpixel(canvas, ii, jj, SDL_MapRGBA(canvas->format, r, g, b, SDL_ALPHA_OPAQUE));
}
@ -966,16 +838,20 @@ static void mosaic_shaped_paint(void *ptr, int which ATTRIBUTE_UNUSED,
}
Uint8 mosaic_shaped_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
Uint8 mosaic_shaped_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED)
{
return 0;
}
Uint8 mosaic_shaped_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
Uint8 mosaic_shaped_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED)
{
return 0;
}
void mosaic_shaped_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void mosaic_shaped_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}

View file

@ -42,30 +42,25 @@ SDL_Surface *negative_get_icon(magic_api * api, int which);
char *negative_get_name(magic_api * api, int which);
int negative_get_group(magic_api * api, int which);
char *negative_get_description(magic_api * api, int which, int mode);
static void do_negative(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y);
static void do_negative(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
void negative_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void negative_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void negative_release(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void negative_shutdown(magic_api * api);
void negative_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
int negative_requires_colors(magic_api * api, int which);
void negative_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void negative_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void negative_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void negative_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int negative_modes(magic_api * api, int which);
Uint8 negative_accepted_sizes(magic_api * api, int which, int mode);
Uint8 negative_default_size(magic_api * api, int which, int mode);
void negative_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void negative_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
enum
{
@ -86,14 +81,11 @@ const char *negative_names[negative_NUM_TOOLS] = {
const char *negative_descs[negative_NUM_TOOLS][2] = {
{
gettext_noop
("Click and drag the mouse around to make your painting negative."),
gettext_noop("Click and drag the mouse around to make your painting negative."),
gettext_noop("Click to turn your painting into its negative.")},
{
gettext_noop
("Click and drag the mouse around to change colors to their opposites -- their complementary colors."),
gettext_noop
("Click to turn all colors in your painting into their opposites -- their complementary colors.")},
gettext_noop("Click and drag the mouse around to change colors to their opposites -- their complementary colors."),
gettext_noop("Click to turn all colors in your painting into their opposites -- their complementary colors.")},
};
@ -101,8 +93,7 @@ int negative_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%ssounds/magic/negative.wav",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/negative.wav", api->data_directory);
negative_snd = Mix_LoadWAV(fname);
@ -124,8 +115,7 @@ SDL_Surface *negative_get_icon(magic_api * api, int which)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory,
negative_icon_filenames[which]);
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, negative_icon_filenames[which]);
return (IMG_Load(fname));
}
@ -136,15 +126,13 @@ char *negative_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
}
// Return our group (both the same):
int negative_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int negative_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_COLOR_FILTERS;
}
// Return our description, localized:
char *negative_get_description(magic_api * api ATTRIBUTE_UNUSED, int which,
int mode)
char *negative_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode)
{
int mode_idx;
@ -164,8 +152,7 @@ char *negative_get_description(magic_api * api ATTRIBUTE_UNUSED, int which,
return (strdup(gettext_noop(negative_descs[which][mode_idx])));
}
static void negative_calc(void *ptr, int which, Uint8 r, Uint8 g, Uint8 b,
Uint8 * new_r, Uint8 * new_g, Uint8 * new_b)
static void negative_calc(void *ptr, int which, Uint8 r, Uint8 g, Uint8 b, Uint8 * new_r, Uint8 * new_g, Uint8 * new_b)
{
float h, s, v, new_h;
magic_api *api = (magic_api *) ptr;
@ -189,8 +176,7 @@ static void negative_calc(void *ptr, int which, Uint8 r, Uint8 g, Uint8 b,
}
// Callback that does the negative color effect on a circle centered around x,y
static void do_negative(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y)
static void do_negative(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
int xx, yy;
Uint8 r, g, b, new_r, new_g, new_b;
@ -204,8 +190,7 @@ static void do_negative(void *ptr, int which, SDL_Surface * canvas,
{
SDL_GetRGB(api->getpixel(last, xx, yy), last->format, &r, &g, &b);
negative_calc(api, which, r, g, b, &new_r, &new_g, &new_b);
api->putpixel(canvas, xx, yy,
SDL_MapRGB(canvas->format, new_r, new_g, new_b));
api->putpixel(canvas, xx, yy, SDL_MapRGB(canvas->format, new_r, new_g, new_b));
}
}
}
@ -213,13 +198,12 @@ static void do_negative(void *ptr, int which, SDL_Surface * canvas,
// Ask Tux Paint to call our 'do_negative()' callback over a line
void negative_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
SDL_LockSurface(last);
SDL_LockSurface(canvas);
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_negative);
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_negative);
if (ox > x)
{
@ -250,8 +234,7 @@ void negative_drag(magic_api * api, int which, SDL_Surface * canvas,
// Ask Tux Paint to call our 'do_negative()' callback at a single point
void negative_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
if (mode == MODE_PAINT)
negative_drag(api, which, canvas, last, x, y, x, y, update_rect);
@ -266,8 +249,7 @@ void negative_click(magic_api * api, int which, int mode,
{
SDL_GetRGB(api->getpixel(last, xx, yy), last->format, &r, &g, &b);
negative_calc(api, which, r, g, b, &new_r, &new_g, &new_b);
api->putpixel(canvas, xx, yy,
SDL_MapRGB(canvas->format, new_r, new_g, new_b));
api->putpixel(canvas, xx, yy, SDL_MapRGB(canvas->format, new_r, new_g, new_b));
}
}
@ -285,8 +267,7 @@ void negative_release(magic_api * api ATTRIBUTE_UNUSED,
int which 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)
{
}
@ -298,38 +279,37 @@ void negative_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// We don't use colors
void negative_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void negative_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
// We don't use colors
int negative_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int negative_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 0;
}
void negative_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void negative_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int negative_modes(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int negative_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (MODE_PAINT | MODE_FULLSCREEN);
}
Uint8 negative_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode) {
Uint8 negative_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode)
{
if (mode == MODE_PAINT)
return 8;
else
@ -341,7 +321,9 @@ Uint8 negative_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUT
return 4;
}
void negative_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void negative_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
negative_radius = size * 4;
}

View file

@ -70,8 +70,7 @@ const int noise_groups[noise_NUM_TOOLS] = {
};
const char *noise_descs[noise_NUM_TOOLS][2] = {
{gettext_noop
("Click and drag the mouse to add noise to parts of your picture."),
{gettext_noop("Click and drag the mouse to add noise to parts of your picture."),
gettext_noop("Click to add noise to your entire picture."),},
};
@ -81,15 +80,11 @@ SDL_Surface *noise_get_icon(magic_api * api, int which);
char *noise_get_name(magic_api * api, int which);
int noise_get_group(magic_api * api, int which);
char *noise_get_description(magic_api * api, int which, int mode);
static void do_noise_pixel(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y);
static void do_noise_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last,
int which);
static void do_noise_brush(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y);
static void do_noise_pixel(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
static void do_noise_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int which);
static void do_noise_brush(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
void noise_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void noise_click(magic_api * api, int which, int mode, SDL_Surface * canvas,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void noise_release(magic_api * api, int which, SDL_Surface * canvas,
@ -98,15 +93,14 @@ void noise_shutdown(magic_api * api);
void noise_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
int noise_requires_colors(magic_api * api, int which);
void noise_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void noise_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void noise_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void noise_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int noise_modes(magic_api * api, int which);
int noise_get_tool_count(magic_api * api ATTRIBUTE_UNUSED);
Uint8 noise_accepted_sizes(magic_api * api, int which, int mode);
Uint8 noise_default_size(magic_api * api, int which, int mode);
void noise_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void noise_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
Uint32 noise_api_version(void)
@ -124,8 +118,7 @@ int noise_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
for (i = 0; i < noise_NUM_TOOLS; i++)
{
snprintf(fname, sizeof(fname), "%ssounds/magic/%s", api->data_directory,
noise_snd_filenames[i]);
snprintf(fname, sizeof(fname), "%ssounds/magic/%s", api->data_directory, noise_snd_filenames[i]);
noise_snd_effect[i] = Mix_LoadWAV(fname);
}
return (1);
@ -141,8 +134,7 @@ SDL_Surface *noise_get_icon(magic_api * api, int which)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory,
noise_icon_filenames[which]);
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, noise_icon_filenames[which]);
return (IMG_Load(fname));
}
@ -159,16 +151,14 @@ int noise_get_group(magic_api * api ATTRIBUTE_UNUSED, int which)
}
// Return our descriptions, localized:
char *noise_get_description(magic_api * api ATTRIBUTE_UNUSED, int which,
int mode)
char *noise_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode)
{
return (strdup(gettext_noop(noise_descs[which][mode - 1])));
}
//Do the effect for one pixel
static void do_noise_pixel(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)
{
magic_api *api = (magic_api *) ptr;
@ -176,22 +166,17 @@ static void do_noise_pixel(void *ptr, int which ATTRIBUTE_UNUSED,
double temp2[3];
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++)
{
temp2[k] =
clamp(0.0, (int) temp[k] - (rand() % noise_AMOUNT) + noise_AMOUNT / 2.0,
255.0);
temp2[k] = clamp(0.0, (int)temp[k] - (rand() % noise_AMOUNT) + noise_AMOUNT / 2.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
static void do_noise_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last,
int which)
static void do_noise_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int which)
{
int x, y;
@ -205,8 +190,7 @@ static void do_noise_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last,
}
//do the effect for the brush
static void do_noise_brush(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y)
static void do_noise_brush(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
int xx, yy;
magic_api *api = (magic_api *) ptr;
@ -215,8 +199,7 @@ static void do_noise_brush(void *ptr, int which, SDL_Surface * canvas,
{
for (xx = x - noise_RADIUS; xx < x + noise_RADIUS; xx++)
{
if (api->in_circle(xx - x, yy - y, noise_RADIUS)
&& !api->touched(xx, yy))
if (api->in_circle(xx - x, yy - y, noise_RADIUS) && !api->touched(xx, yy))
{
do_noise_pixel(api, which, canvas, last, xx, yy);
}
@ -226,12 +209,10 @@ static void do_noise_brush(void *ptr, int which, SDL_Surface * canvas,
// Affect the canvas on drag:
void noise_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1,
do_noise_brush);
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_noise_brush);
api->playsound(noise_snd_effect[which], (x * 255) / canvas->w, 255);
@ -258,8 +239,7 @@ void noise_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void noise_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
if (mode == MODE_PAINT)
noise_drag(api, which, canvas, last, x, y, x, y, update_rect);
@ -279,8 +259,7 @@ void noise_release(magic_api * api ATTRIBUTE_UNUSED,
int which 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)
{
}
@ -300,27 +279,26 @@ void noise_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void noise_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void noise_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
// Use colors:
int noise_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int noise_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 0;
}
void noise_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void noise_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
@ -343,7 +321,9 @@ Uint8 noise_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_U
return 4;
}
void noise_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void noise_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
noise_RADIUS = size * 4;
}

View file

@ -51,8 +51,7 @@
static void perspective_preview(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect,
float step);
int x, int y, SDL_Rect * update_rect, float step);
Uint32 perspective_api_version(void);
int perspective_init(magic_api * api, Uint32 disabled_features);
int perspective_get_tool_count(magic_api * api);
@ -63,16 +62,13 @@ int perspective_get_group(magic_api * api, int which);
char *perspective_get_description(magic_api * api, int which, int mode);
void perspective_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void perspective_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void perspective_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last, int x,
int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void perspective_shutdown(magic_api * api);
@ -81,24 +77,21 @@ void perspective_set_color(magic_api * api, int which, SDL_Surface * canvas,
int perspective_requires_colors(magic_api * api, int which);
void perspective_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void perspective_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void perspective_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void perspective_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int perspective_modes(magic_api * api, int which);
int scan_fill(magic_api * api, SDL_Surface * canvas, SDL_Surface * srfc,
int x, int y, int fill_edge, int fill_tile, int size,
Uint32 color);
int x, int y, int fill_edge, int fill_tile, int size, Uint32 color);
void perspective_line(void *ptr_to_api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y);
void perspective_line(void *ptr_to_api, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
Uint8 perspective_accepted_sizes(magic_api * api, int which, int mode);
Uint8 perspective_default_size(magic_api * api, int which, int mode);
void perspective_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void perspective_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
@ -115,8 +108,7 @@ int click_x, click_y;
int latest_x, latest_y;
int new_w, new_h, old_h, sound_h;
int perspective_average_r, perspective_average_g, perspective_average_b,
perspective_average_count;
int perspective_average_r, perspective_average_g, perspective_average_b, perspective_average_count;
Uint32 pixel_average, black, white;
int otop_left_x, otop_left_y, otop_right_x, otop_right_y;
@ -178,19 +170,15 @@ const char *perspective_names[perspective_NUM_TOOLS] = {
};
const char *perspective_descs[perspective_NUM_TOOLS] = {
gettext_noop
("Click on the corners and drag where you want to stretch the picture."),
gettext_noop("Click on the corners and drag where you want to stretch the picture."),
gettext_noop("Click to turn your picture into 2-by-2 panels."),
gettext_noop
("Click and drag up to zoom in the picture. Drag down to zoom out and tile the picture."),
gettext_noop("Click and drag up to zoom in the picture. Drag down to zoom out and tile the picture."),
gettext_noop
("Click and drag up to zoom in or drag down to zoom out the picture."),
gettext_noop("Click and drag up to zoom in or drag down to zoom out the picture."),
gettext_noop
("Click and drag up to rush in or drag down to rush out the picture."),
gettext_noop("Click and drag up to rush in or drag down to rush out the picture."),
};
Uint32 perspective_api_version(void)
@ -206,8 +194,7 @@ int perspective_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
for (i = 0; i <= perspective_NUM_TOOLS; i++)
{
snprintf(fname, sizeof(fname), "%ssounds/magic/%s", api->data_directory,
perspective_snd_filenames[i]);
snprintf(fname, sizeof(fname), "%ssounds/magic/%s", api->data_directory, perspective_snd_filenames[i]);
perspective_snd_effect[i] = Mix_LoadWAV(fname);
}
return (1);
@ -223,8 +210,7 @@ SDL_Surface *perspective_get_icon(magic_api * api, int which)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory,
perspective_icon_filenames[which]);
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, perspective_icon_filenames[which]);
return (IMG_Load(fname));
}
@ -235,15 +221,13 @@ char *perspective_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
}
// Return our group (the same):
int perspective_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int perspective_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_PICTURE_WARPS;
}
// Return our descriptions, localized:
char *perspective_get_description(magic_api * api ATTRIBUTE_UNUSED, int which,
int mode ATTRIBUTE_UNUSED)
char *perspective_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
{
return (strdup(gettext_noop(perspective_descs[which])));
}
@ -252,8 +236,7 @@ char *perspective_get_description(magic_api * api ATTRIBUTE_UNUSED, int which,
// Affect the canvas on drag:
void perspective_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox ATTRIBUTE_UNUSED,
int oy ATTRIBUTE_UNUSED, int x, int y,
SDL_Rect * update_rect)
int oy ATTRIBUTE_UNUSED, int x, int y, SDL_Rect * update_rect)
{
if (canvas_back == NULL)
return;
@ -302,8 +285,7 @@ void perspective_drag(magic_api * api, int which, SDL_Surface * canvas,
/* Draw a square and the current shape relative to it as a visual reference */
/* square */
api->line(api, which, canvas, last, otop_left_x, otop_left_y,
otop_right_x, otop_right_y, 1, perspective_line);
api->line(api, which, canvas, last, otop_left_x, otop_left_y, otop_right_x, otop_right_y, 1, perspective_line);
api->line(api, which, canvas, last, otop_left_x, otop_left_y,
obottom_left_x, obottom_left_y, 1, perspective_line);
api->line(api, which, canvas, last, obottom_left_x, obottom_left_y,
@ -312,10 +294,8 @@ void perspective_drag(magic_api * api, int which, SDL_Surface * canvas,
otop_right_x, otop_right_y, 1, perspective_line);
/* shape */
api->line(api, which, canvas, last, top_left_x, top_left_y, top_right_x,
top_right_y, 1, perspective_line);
api->line(api, which, canvas, last, top_left_x, top_left_y,
bottom_left_x, bottom_left_y, 1, perspective_line);
api->line(api, which, canvas, last, top_left_x, top_left_y, top_right_x, top_right_y, 1, perspective_line);
api->line(api, which, canvas, last, top_left_x, top_left_y, bottom_left_x, bottom_left_y, 1, perspective_line);
api->line(api, which, canvas, last, bottom_left_x, bottom_left_y,
bottom_right_x, bottom_right_y, 1, perspective_line);
api->line(api, which, canvas, last, bottom_right_x, bottom_right_y,
@ -324,8 +304,7 @@ void perspective_drag(magic_api * api, int which, SDL_Surface * canvas,
api->playsound(perspective_snd_effect[which], (x * 255) / canvas->w,
255);
api->playsound(perspective_snd_effect[which], (x * 255) / canvas->w, 255);
}
break;
case TOOL_ZOOM:
@ -340,9 +319,7 @@ void perspective_drag(magic_api * api, int which, SDL_Surface * canvas,
update_rect->w = canvas->w;
update_rect->h = canvas->h;
SDL_FillRect(canvas, update_rect,
SDL_MapRGB(canvas->format, perspective_r, perspective_g,
perspective_b));
SDL_FillRect(canvas, update_rect, SDL_MapRGB(canvas->format, perspective_r, perspective_g, perspective_b));
}
new_h = max(1, old_h + click_y - y);
@ -381,8 +358,7 @@ void perspective_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void perspective_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
click_x = x;
click_y = y;
@ -482,8 +458,7 @@ void perspective_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
// Affect the canvas on release:
void perspective_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last, int x,
int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
if (canvas_back == NULL)
return;
@ -496,9 +471,7 @@ void perspective_release(magic_api * api, int which,
update_rect->h = canvas->h;
if (which == TOOL_ZOOM || which == TOOL_PERSPECTIVE)
SDL_FillRect(canvas, update_rect,
SDL_MapRGB(canvas->format, perspective_r, perspective_g,
perspective_b));
SDL_FillRect(canvas, update_rect, SDL_MapRGB(canvas->format, perspective_r, perspective_g, perspective_b));
if (which == TOOL_PERSPECTIVE)
{
@ -508,7 +481,7 @@ void perspective_release(magic_api * api, int which,
{
int h1, h2, w, h, hh, dx1, dy1;
SDL_Surface *scaled_surf;
SDL_Surface * aux1;
SDL_Surface *aux1;
if (new_h == canvas->h || new_h == 0)
{
@ -536,9 +509,10 @@ void perspective_release(magic_api * api, int which,
aux1 = api->scale(last, last->w, last->h, 0);
for (h = 0; h < h2 - h1; h++)
{
if (h % 10 == 0)
{
if (h % 10 == 0) {
api->update_progress_bar();
api->update_progress_bar();
}
hh = h2 - h;
w = canvas->w * hh / canvas->h;
@ -546,67 +520,68 @@ void perspective_release(magic_api * api, int which,
dx1 = (canvas->w - scaled_surf->w) / 2;
dy1 = (canvas->h - scaled_surf->h) / 2;
SDL_Rect rrr;
rrr.x = dx1;
rrr.y = dy1;
rrr.w = dx1 + scaled_surf->w;
rrr.h = dy1 + scaled_surf->h;
SDL_SetSurfaceBlendMode( scaled_surf, SDL_BLENDMODE_BLEND);
SDL_SetSurfaceAlphaMod(scaled_surf,24);
SDL_SetSurfaceBlendMode(scaled_surf, SDL_BLENDMODE_BLEND);
SDL_SetSurfaceAlphaMod(scaled_surf, 24);
SDL_BlitSurface(scaled_surf, NULL, aux1, &rrr);
SDL_FreeSurface(scaled_surf);
}
}
SDL_BlitSurface(aux1, NULL, canvas, NULL);
SDL_FreeSurface(aux1);
/*
for (h = 0; h < (h2 - h1); h++)
{
if ((h / 2) % 10 == 0)
api->update_progress_bar();
for (h = 0; h < (h2 - h1); h++)
{
if ((h / 2) % 10 == 0)
api->update_progress_bar();
// if (new_h < canvas->h)
hh = h2 - h;
// else
// hh = new_h + h;
// if (new_h < canvas->h)
hh = h2 - h;
// else
// hh = new_h + h;
w = canvas->w * hh / canvas->h;
scaled_surf = api->scale(last, w, hh, 0);
w = canvas->w * hh / canvas->h;
scaled_surf = api->scale(last, w, hh, 0);
dx1 = (canvas->w - scaled_surf->w) / 2;
dy1 = (canvas->h - scaled_surf->h) / 2;
dx1 = (canvas->w - scaled_surf->w) / 2;
dy1 = (canvas->h - scaled_surf->h) / 2;
for (y = 0; y < scaled_surf->h; y++)
{
if (dy1 + y >= 0 && dy1 + y < canvas->h)
{
for (x = 0; x < scaled_surf->w; x++)
{
if (dx1 + x >= 0 && dx1 + x < canvas->w)
{
SDL_GetRGB(api->getpixel(scaled_surf, x, y),
scaled_surf->format, &r1, &g1, &b1);
SDL_GetRGB(api->getpixel(canvas, dx1 + x, dy1 + y),
canvas->format, &r2, &g2, &b2);
pct = (float) ((float) h / ((float) h2 - (float) h1));
// if (new_h > canvas->h)
// pct = 1.0 - pct;
r =
api->linear_to_sRGB((api->sRGB_to_linear(r1) * (1.0 - pct)) +
(api->sRGB_to_linear(r2) * (pct)));
g =
api->linear_to_sRGB((api->sRGB_to_linear(g1) * (1.0 - pct)) +
(api->sRGB_to_linear(g2) * (pct)));
b =
api->linear_to_sRGB((api->sRGB_to_linear(b1) * (1.0 - pct)) +
(api->sRGB_to_linear(b2) * (pct)));
for (y = 0; y < scaled_surf->h; y++)
{
if (dy1 + y >= 0 && dy1 + y < canvas->h)
{
for (x = 0; x < scaled_surf->w; x++)
{
if (dx1 + x >= 0 && dx1 + x < canvas->w)
{
SDL_GetRGB(api->getpixel(scaled_surf, x, y),
scaled_surf->format, &r1, &g1, &b1);
SDL_GetRGB(api->getpixel(canvas, dx1 + x, dy1 + y),
canvas->format, &r2, &g2, &b2);
pct = (float) ((float) h / ((float) h2 - (float) h1));
// if (new_h > canvas->h)
// pct = 1.0 - pct;
r =
api->linear_to_sRGB((api->sRGB_to_linear(r1) * (1.0 - pct)) +
(api->sRGB_to_linear(r2) * (pct)));
g =
api->linear_to_sRGB((api->sRGB_to_linear(g1) * (1.0 - pct)) +
(api->sRGB_to_linear(g2) * (pct)));
b =
api->linear_to_sRGB((api->sRGB_to_linear(b1) * (1.0 - pct)) +
(api->sRGB_to_linear(b2) * (pct)));
api->putpixel(canvas, dx1 + x, dy1 + y,
SDL_MapRGB(canvas->format, r, g, b));
}
}
}
}
}*/
api->putpixel(canvas, dx1 + x, dy1 + y,
SDL_MapRGB(canvas->format, r, g, b));
}
}
}
}
} */
update_rect->x = 0;
update_rect->y = 0;
@ -623,9 +598,7 @@ void perspective_release(magic_api * api, int which,
update_rect->h = canvas->h;
if (which == TOOL_ZOOM)
SDL_FillRect(canvas, update_rect,
SDL_MapRGB(canvas->format, perspective_r, perspective_g,
perspective_b));
SDL_FillRect(canvas, update_rect, SDL_MapRGB(canvas->format, perspective_r, perspective_g, perspective_b));
if (new_h < canvas->h)
@ -670,9 +643,7 @@ void perspective_release(magic_api * api, int which,
aux_w,
aux_h,
canvas->format->BitsPerPixel,
canvas->format->Rmask,
canvas->format->Gmask,
canvas->format->Bmask, 0);
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, 0);
SDL_BlitSurface(canvas_back, update_rect, aux_surf, NULL);
scaled_surf = api->scale(aux_surf, canvas->w, canvas->h, 0);
@ -691,8 +662,7 @@ void perspective_release(magic_api * api, int which,
void perspective_preview(magic_api * api, int which,
SDL_Surface * canvas,
SDL_Surface * last ATTRIBUTE_UNUSED,
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED,
SDL_Rect * update_rect, float step)
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect, float step)
{
float i, j;
float ax, ay, bx, by, dx, dy;
@ -708,47 +678,42 @@ void perspective_preview(magic_api * api, int which,
update_rect->h = canvas->h;
if (which == TOOL_ZOOM)
SDL_FillRect(canvas, update_rect,
SDL_MapRGB(canvas->format, perspective_r, perspective_g,
perspective_b));
SDL_FillRect(canvas, update_rect, SDL_MapRGB(canvas->format, perspective_r, perspective_g, perspective_b));
else if (which == TOOL_TILEZOOM || which == TOOL_RUSH)
SDL_FillRect(canvas, update_rect,
SDL_MapRGB(canvas->format, 128, 128, 128));
SDL_FillRect(canvas, update_rect, SDL_MapRGB(canvas->format, 128, 128, 128));
ox_distance = otop_right_x - otop_left_x;
oy_distance = obottom_left_y - otop_left_y;
top_advc_x = (float) (top_right_x - top_left_x) / ox_distance;
top_advc_y = (float) (top_right_y - top_left_y) / ox_distance;
top_advc_x = (float)(top_right_x - top_left_x) / ox_distance;
top_advc_y = (float)(top_right_y - top_left_y) / ox_distance;
left_advc_x = (float) (bottom_left_x - top_left_x) / oy_distance;
left_advc_y = (float) (bottom_left_y - top_left_y) / oy_distance;
left_advc_x = (float)(bottom_left_x - top_left_x) / oy_distance;
left_advc_y = (float)(bottom_left_y - top_left_y) / oy_distance;
right_advc_x = (float) (bottom_right_x - top_right_x) / oy_distance;
right_advc_y = (float) (bottom_right_y - top_right_y) / oy_distance;
right_advc_x = (float)(bottom_right_x - top_right_x) / oy_distance;
right_advc_y = (float)(bottom_right_y - top_right_y) / oy_distance;
bottom_advc_x = (float) (bottom_right_x - bottom_left_x) / ox_distance;
bottom_advc_y = (float) (bottom_right_y - bottom_left_y) / ox_distance;
bottom_advc_x = (float)(bottom_right_x - bottom_left_x) / ox_distance;
bottom_advc_y = (float)(bottom_right_y - bottom_left_y) / ox_distance;
center_ofset_x = (otop_left_x - top_left_x) * 2;
center_ofset_y = (otop_left_y - top_left_y) * 2;
for (i = 0; i < canvas->w; i += step)
{
ax = (float) top_advc_x *i;
ay = (float) top_advc_y *i;
bx = (float) bottom_advc_x *i + (bottom_left_x - top_left_x) * 2;
by = (float) bottom_advc_y *i + (bottom_left_y - top_left_y) * 2;
ax = (float)top_advc_x *i;
ay = (float)top_advc_y *i;
bx = (float)bottom_advc_x *i + (bottom_left_x - top_left_x) * 2;
by = (float)bottom_advc_y *i + (bottom_left_y - top_left_y) * 2;
for (j = 0; j < canvas->h; j += step)
{
dx = (float) (bx - ax) / canvas->h * j;
dy = (float) (by - ay) / canvas->h * j;
dx = (float)(bx - ax) / canvas->h * j;
dy = (float)(by - ay) / canvas->h * j;
api->putpixel(canvas, ax + dx - center_ofset_x,
ay + dy - center_ofset_y, api->getpixel(canvas_back, i,
j));
api->putpixel(canvas, ax + dx - center_ofset_x, ay + dy - center_ofset_y, api->getpixel(canvas_back, i, j));
}
}
@ -800,7 +765,8 @@ void perspective_shutdown(magic_api * api ATTRIBUTE_UNUSED)
void perspective_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect)
{
if (r != perspective_r || g != perspective_g || b != perspective_b) {
if (r != perspective_r || g != perspective_g || b != perspective_b)
{
perspective_r = r;
perspective_g = g;
perspective_b = b;
@ -818,8 +784,7 @@ int perspective_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which)
}
void perspective_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas)
{
Uint32 amask;
@ -829,29 +794,26 @@ void perspective_switchin(magic_api * api ATTRIBUTE_UNUSED,
top_left_x = otop_left_x = bottom_left_x = obottom_left_x = canvas->w / 4;
top_left_y = otop_left_y = top_right_y = otop_right_y = canvas->h / 4;
top_right_x = otop_right_x = bottom_right_x = obottom_right_x =
canvas->w - otop_left_x;
top_right_x = otop_right_x = bottom_right_x = obottom_right_x = canvas->w - otop_left_x;
bottom_left_y = obottom_left_y = bottom_right_y = obottom_right_y =
canvas->h - otop_left_y;
bottom_left_y = obottom_left_y = bottom_right_y = obottom_right_y = canvas->h - otop_left_y;
black = SDL_MapRGBA(canvas->format, 0, 0, 0, 0);
white = SDL_MapRGBA(canvas->format, 255, 255, 255, 0);
amask =
~(canvas->format->Rmask | canvas->format->Gmask | canvas->format->Bmask);
amask = ~(canvas->format->Rmask | canvas->format->Gmask | canvas->format->Bmask);
if (canvas_back == NULL) {
if (canvas_back == NULL)
{
canvas_back = SDL_CreateRGBSurface(SDL_SWSURFACE,
canvas->w,
canvas->h,
canvas->format->BitsPerPixel,
canvas->format->Rmask,
canvas->format->Gmask,
canvas->format->Bmask, amask);
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, amask);
}
if (canvas_back == NULL) {
if (canvas_back == NULL)
{
fprintf(stderr, "perspective cannot create background canvas!\n");
return;
}
@ -860,11 +822,10 @@ void perspective_switchin(magic_api * api ATTRIBUTE_UNUSED,
}
void perspective_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
if (canvas_back != NULL) {
if (canvas_back != NULL)
{
SDL_FreeSurface(canvas_back);
canvas_back = NULL;
}
@ -883,8 +844,7 @@ int perspective_modes(magic_api * api ATTRIBUTE_UNUSED, int which)
}
void perspective_line(void *ptr_to_api, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas,
SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
{
magic_api *api = (magic_api *) ptr_to_api;
@ -898,7 +858,8 @@ void perspective_line(void *ptr_to_api, int which ATTRIBUTE_UNUSED,
}
Uint8 perspective_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
Uint8 perspective_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED)
{
return 0;
}
@ -908,6 +869,8 @@ Uint8 perspective_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRI
return 0;
}
void perspective_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void perspective_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}

View file

@ -58,8 +58,7 @@ char *pixels_get_name(magic_api * api, int which);
int pixels_get_group(magic_api * api, int which);
char *pixels_get_description(magic_api * api, int which, int mode);
void pixels_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void pixels_click(magic_api * api, int which, int mode, SDL_Surface * canvas,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void pixels_release(magic_api * api, int which, SDL_Surface * canvas,
@ -68,14 +67,13 @@ void pixels_shutdown(magic_api * api);
void pixels_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
int pixels_requires_colors(magic_api * api, int which);
void pixels_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void pixels_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void pixels_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void pixels_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int pixels_modes(magic_api * api, int which);
Uint8 pixels_accepted_sizes(magic_api * api, int which, int mode);
Uint8 pixels_default_size(magic_api * api, int which, int mode);
void pixels_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void pixels_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
// No setup required:
@ -83,8 +81,7 @@ int pixels_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%ssounds/magic/pixels.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/pixels.ogg", api->data_directory);
pixel_snd = Mix_LoadWAV(fname);
return (1);
@ -106,30 +103,25 @@ SDL_Surface *pixels_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/pixels.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/pixels.png", api->data_directory);
return (IMG_Load(fname));
}
// Return our names, localized:
char *pixels_get_name(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
char *pixels_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (strdup(gettext_noop("Pixels")));
}
// Return our group (both the same):
int pixels_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int pixels_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_PAINTING;
}
// Return our descriptions, localized:
char *pixels_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED)
char *pixels_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return (strdup(gettext_noop("Click and drag to draw large pixels.")));
@ -139,8 +131,7 @@ char *pixels_get_description(magic_api * api ATTRIBUTE_UNUSED,
// Do the effect:
static void do_pixels(void *ptr ATTRIBUTE_UNUSED, 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)
{
SDL_Rect dest;
@ -149,16 +140,14 @@ static void do_pixels(void *ptr ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
dest.w = pixel_size;
dest.h = pixel_size;
SDL_FillRect(canvas, &dest,
SDL_MapRGB(canvas->format, pixels_r, pixels_g, pixels_b));
SDL_FillRect(canvas, &dest, SDL_MapRGB(canvas->format, pixels_r, pixels_g, pixels_b));
}
// Affect the canvas on drag:
void pixels_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_pixels);
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_pixels);
if (ox > x)
{
@ -190,8 +179,7 @@ void pixels_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void pixels_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
pixels_drag(api, which, canvas, last, x, y, x, y, update_rect);
}
@ -199,8 +187,7 @@ void pixels_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
void pixels_release(magic_api * api, int which 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)
{
api->stopsound();
}
@ -213,8 +200,9 @@ void pixels_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void pixels_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void pixels_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g,
Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
pixels_r = r;
pixels_g = g;
@ -222,21 +210,18 @@ void pixels_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUS
}
// Use colors:
int pixels_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int pixels_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 1;
}
void pixels_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void pixels_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
@ -256,7 +241,9 @@ Uint8 pixels_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_
return 1;
}
void pixels_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void pixels_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
int canv_area_scale;

View file

@ -57,30 +57,25 @@ char *puzzle_get_name(magic_api * api, int which);
int puzzle_get_group(magic_api * api, int which);
char *puzzle_get_description(magic_api * api, int which, int mode);
void puzzle_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void puzzle_shutdown(magic_api * api);
void puzzle_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
int puzzle_requires_colors(magic_api * api, int which);
void puzzle_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void puzzle_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void puzzle_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void puzzle_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int puzzle_modes(magic_api * api, int which);
static void puzzle_draw(void *ptr, int which_tool, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y);
static void puzzle_draw(void *ptr, int which_tool, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
void puzzle_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void puzzle_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
int gcd(int a, int b);
Uint8 puzzle_accepted_sizes(magic_api * api, int which, int mode);
Uint8 puzzle_default_size(magic_api * api, int which, int mode);
void puzzle_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void puzzle_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
Uint32 puzzle_api_version(void)
{
@ -91,8 +86,7 @@ int puzzle_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%ssounds/magic/puzzle.wav",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/puzzle.wav", api->data_directory);
puzzle_snd = Mix_LoadWAV(fname);
return 1;
@ -107,32 +101,26 @@ SDL_Surface *puzzle_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/puzzle.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/puzzle.png", api->data_directory);
return (IMG_Load(fname));
}
char *puzzle_get_name(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
char *puzzle_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (strdup(gettext_noop("Puzzle")));
}
int puzzle_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int puzzle_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_DISTORTS;
}
char *puzzle_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode)
char *puzzle_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode)
{
if (mode == MODE_PAINT)
return
strdup(gettext_noop
("Click the part of your picture where would you like a puzzle."));
return strdup(gettext_noop("Click the part of your picture where would you like a puzzle."));
return strdup(gettext_noop("Click to make a puzzle in fullscreen mode."));
}
@ -140,8 +128,7 @@ void puzzle_release(magic_api * api ATTRIBUTE_UNUSED,
int which 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)
{
}
@ -151,13 +138,14 @@ void puzzle_shutdown(magic_api * api ATTRIBUTE_UNUSED)
Mix_FreeChunk(puzzle_snd);
}
void puzzle_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void puzzle_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
int puzzle_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int puzzle_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 0;
}
@ -170,22 +158,19 @@ int gcd(int a, int b) //greatest common divisor
}
void puzzle_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas)
{
puzzle_gcd = RATIO * gcd(canvas->w, canvas->h);
rects_w = (unsigned int) canvas->w / puzzle_gcd;
rects_h = (unsigned int) canvas->h / puzzle_gcd;
rects_w = (unsigned int)canvas->w / puzzle_gcd;
rects_h = (unsigned int)canvas->h / puzzle_gcd;
canvas_backup =
SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h,
canvas->format->BitsPerPixel, canvas->format->Rmask,
canvas->format->Gmask, canvas->format->Bmask,
canvas->format->Amask);
canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
}
void puzzle_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
SDL_FreeSurface(canvas_backup);
canvas_backup = NULL;
@ -197,8 +182,7 @@ int puzzle_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
}
static void puzzle_draw(void *ptr, int which_tool ATTRIBUTE_UNUSED,
SDL_Surface * canvas,
SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
{
@ -258,20 +242,14 @@ static void puzzle_draw(void *ptr, int which_tool ATTRIBUTE_UNUSED,
void puzzle_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox ATTRIBUTE_UNUSED,
int oy ATTRIBUTE_UNUSED, int x, int y,
SDL_Rect * update_rect)
int oy ATTRIBUTE_UNUSED, int x, int y, SDL_Rect * update_rect)
{
puzzle_draw(api, which, canvas, last, x - puzzle_gcd / 2,
y - puzzle_gcd / 2);
puzzle_draw(api, which, canvas, last, x - puzzle_gcd / 2, y - puzzle_gcd / 2);
puzzle_draw(api, which, canvas, last, x - 1.5 * puzzle_gcd / 2,
y - puzzle_gcd / 2);
puzzle_draw(api, which, canvas, last, x + 0.5 * puzzle_gcd,
y - puzzle_gcd / 2);
puzzle_draw(api, which, canvas, last, x - puzzle_gcd / 2,
y - 1.5 * puzzle_gcd);
puzzle_draw(api, which, canvas, last, x - puzzle_gcd / 2,
y + 0.5 * puzzle_gcd);
puzzle_draw(api, which, canvas, last, x - 1.5 * puzzle_gcd / 2, y - puzzle_gcd / 2);
puzzle_draw(api, which, canvas, last, x + 0.5 * puzzle_gcd, y - puzzle_gcd / 2);
puzzle_draw(api, which, canvas, last, x - puzzle_gcd / 2, y - 1.5 * puzzle_gcd);
puzzle_draw(api, which, canvas, last, x - puzzle_gcd / 2, y + 0.5 * puzzle_gcd);
update_rect->x = 0;
update_rect->y = 0;
@ -280,8 +258,7 @@ void puzzle_drag(magic_api * api, int which, SDL_Surface * canvas,
}
void puzzle_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
puzzle_drag(api, which, canvas, last, x, y, x, y, update_rect);
}
@ -297,9 +274,9 @@ Uint8 puzzle_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_
return 4;
}
void puzzle_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void puzzle_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 size, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
RATIO = size + 1;
puzzle_switchin(api, which, mode, canvas);
}

View file

@ -60,37 +60,30 @@ int rails_get_group(magic_api * api, int which);
char *rails_get_description(magic_api * api, int which, int mode);
int rails_requires_colors(magic_api * api, int which);
void rails_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
void rails_shutdown(magic_api * api);
void rails_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void rails_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void rails_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void rails_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
inline unsigned int rails_get_segment(int x, int y);
#define POINT_TYPE typeof(((SDL_Rect *)NULL)->x)
inline void rails_extract_coords_from_segment(unsigned int segment,
POINT_TYPE * x, POINT_TYPE * y);
inline void rails_extract_coords_from_segment(unsigned int segment, POINT_TYPE * x, POINT_TYPE * y);
static void rails_flip(void *ptr, SDL_Surface * dest, SDL_Surface * src);
static void rails_flip_flop(void *ptr, SDL_Surface * dest, SDL_Surface * src);
static void rails_rotate(void *ptr, SDL_Surface * dest, SDL_Surface * src,
unsigned int direction);
static void rails_rotate(void *ptr, SDL_Surface * dest, SDL_Surface * src, unsigned int direction);
void rails_click(magic_api * api, int which, int mode, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
static Uint8 rails_select_image(Uint16 segment);
static void rails_draw(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y,
unsigned int segment);
SDL_Surface * last, int x, int y, unsigned int segment);
static void rails_draw_wrapper(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y);
static void rails_draw_wrapper(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
void rails_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
Uint8 rails_accepted_sizes(magic_api * api, int which, int mode);
Uint8 rails_default_size(magic_api * api, int which, int mode);
void rails_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void rails_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
Uint32 rails_api_version(void)
{
@ -102,8 +95,10 @@ int rails_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
return (MODE_PAINT);
}
void rails_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void rails_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
@ -112,19 +107,15 @@ int rails_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
char fname[1024];
Uint8 i; //is always < 3, so Uint8 seems to be a good idea
rails_images = (char **) malloc(sizeof(char *) * 4);
rails_images = (char **)malloc(sizeof(char *) * 4);
for (i = 0; i < 4; i++)
rails_images[i] = (char *) malloc(sizeof(char) * 1024);
rails_images[i] = (char *)malloc(sizeof(char) * 1024);
snprintf(rails_images[0], 1024 * sizeof(char),
"%simages/magic/rails_one.png", api->data_directory);
snprintf(rails_images[1], 1024 * sizeof(char),
"%simages/magic/rails_three.png", api->data_directory);
snprintf(rails_images[2], 1024 * sizeof(char),
"%simages/magic/rails_four.png", api->data_directory);
snprintf(rails_images[3], 1024 * sizeof(char),
"%simages/magic/rails_corner.png", api->data_directory);
snprintf(rails_images[0], 1024 * sizeof(char), "%simages/magic/rails_one.png", api->data_directory);
snprintf(rails_images[1], 1024 * sizeof(char), "%simages/magic/rails_three.png", api->data_directory);
snprintf(rails_images[2], 1024 * sizeof(char), "%simages/magic/rails_four.png", api->data_directory);
snprintf(rails_images[3], 1024 * sizeof(char), "%simages/magic/rails_corner.png", api->data_directory);
rails_one = IMG_Load(rails_images[0]);
rails_three = IMG_Load(rails_images[1]);
@ -134,8 +125,7 @@ int rails_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
img_w = rails_one->w;
img_h = rails_one->h;
snprintf(fname, sizeof(fname), "%ssounds/magic/rails.wav",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/rails.wav", api->data_directory);
rails_snd = Mix_LoadWAV(fname);
return (1);
@ -150,35 +140,27 @@ SDL_Surface *rails_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/rails.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/rails.png", api->data_directory);
return (IMG_Load(fname));
}
char *rails_get_name(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
char *rails_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return strdup(gettext_noop("Rails"));
}
int rails_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int rails_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_PAINTING;
}
char *rails_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED)
char *rails_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return
strdup(gettext_noop
("Click and drag to draw train track rails on your picture."));
return strdup(gettext_noop("Click and drag to draw train track rails on your picture."));
}
int rails_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int rails_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 0;
}
@ -187,8 +169,7 @@ void rails_release(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * snapshot 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)
{
}
@ -212,28 +193,24 @@ void rails_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
void rails_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas)
{
//we've to compute the quantity of segments in each direction
canvas_backup =
SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h,
canvas->format->BitsPerPixel, canvas->format->Rmask,
canvas->format->Gmask, canvas->format->Bmask,
canvas->format->Amask);
canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
SDL_BlitSurface(canvas, NULL, canvas_backup, NULL);
rails_segments_x = rails_math_ceil(canvas->w, img_w);
rails_segments_y = rails_math_ceil(canvas->h, img_h);
//status_of_segments[0] will not be used, we write in rails_status_of_segments[1 to segments_x*segments_y]
rails_status_of_segments =
(Uint8 *) calloc(rails_segments_x * rails_segments_y + 1, sizeof(Uint8));
rails_status_of_segments = (Uint8 *) calloc(rails_segments_x * rails_segments_y + 1, sizeof(Uint8));
}
void rails_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
if (rails_status_of_segments != NULL)
{
@ -248,7 +225,7 @@ inline int rails_math_ceil(int x, int y)
{
int temp;
temp = (int) x / y;
temp = (int)x / y;
if (x % y)
return temp + 1;
@ -269,11 +246,10 @@ inline unsigned int rails_get_segment(int x, int y)
}
inline void rails_extract_coords_from_segment(unsigned int segment,
POINT_TYPE * x, POINT_TYPE * y)
inline void rails_extract_coords_from_segment(unsigned int segment, POINT_TYPE * x, POINT_TYPE * y)
{ //extracts the coords of the beginning and the segment
*x = ((segment % rails_segments_x) - 1) * img_w; //useful to set update_rect as small as possible
*y = (int) (segment / rails_segments_x) * img_h;
*y = (int)(segment / rails_segments_x) * img_h;
}
static void rails_flip(void *ptr, SDL_Surface * dest, SDL_Surface * src)
@ -296,8 +272,7 @@ static void rails_flip_flop(void *ptr, SDL_Surface * dest, SDL_Surface * src)
api->putpixel(dest, x, y, api->getpixel(src, y, x));
}
static void rails_rotate(void *ptr, SDL_Surface * dest, SDL_Surface * src,
unsigned int direction)
static void rails_rotate(void *ptr, SDL_Surface * dest, SDL_Surface * src, unsigned int direction)
//src and dest must have same size
{
magic_api *api = (magic_api *) ptr;
@ -319,8 +294,7 @@ static void rails_rotate(void *ptr, SDL_Surface * dest, SDL_Surface * src,
}
void rails_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
{
rails_segment_modified_last = 0;
rails_drag(api, which, canvas, snapshot, x, y, x, y, update_rect);
@ -331,8 +305,7 @@ static Uint8 rails_select_image(Uint16 segment)
int take_up, take_down;
int val_up, val_down, val_left, val_right;
int from_top = 0, from_bottom = 0, from_left = 0, from_right = 0;
int from_top_right = 0, from_top_left = 0, from_bottom_right =
0, from_bottom_left = 0;
int from_top_right = 0, from_top_left = 0, from_bottom_right = 0, from_bottom_left = 0;
int TOP = 0, BOTTOM = 0, LEFT = 0, RIGHT = 0;
//Checking from were we come...
@ -387,7 +360,7 @@ static Uint8 rails_select_image(Uint16 segment)
val_up = rails_status_of_segments[take_up];
take_down = segment + rails_segments_x;
if (take_down > (signed) (rails_segments_x * rails_segments_y))
if (take_down > (signed)(rails_segments_x * rails_segments_y))
val_down = SEG_NONE;
else
val_down = rails_status_of_segments[take_down];
@ -446,8 +419,7 @@ static Uint8 rails_select_image(Uint16 segment)
static void rails_draw(void *ptr, int which ATTRIBUTE_UNUSED,
ATTRIBUTE_UNUSED SDL_Surface * canvas,
SDL_Surface * last ATTRIBUTE_UNUSED, int x,
int y ATTRIBUTE_UNUSED, unsigned int segment)
SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y ATTRIBUTE_UNUSED, unsigned int segment)
{
magic_api *api = (magic_api *) ptr;
SDL_Surface *result, *temp;
@ -458,8 +430,7 @@ static void rails_draw(void *ptr, int which ATTRIBUTE_UNUSED,
if (segment > rails_segments_x * rails_segments_y)
return;
//modification_rect.x and modification_rect.y are set by function
rails_extract_coords_from_segment(segment, &modification_rect.x,
&modification_rect.y);
rails_extract_coords_from_segment(segment, &modification_rect.x, &modification_rect.y);
modification_rect.h = img_w;
modification_rect.w = img_h;
@ -553,8 +524,7 @@ static void rails_draw(void *ptr, int which ATTRIBUTE_UNUSED,
api->playsound(rails_snd, (x * 255) / canvas->w, 255);
}
static void rails_draw_wrapper(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y)
static void rails_draw_wrapper(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
rails_segment_modified = rails_get_segment(x, y);
@ -563,18 +533,15 @@ static void rails_draw_wrapper(void *ptr, int which, SDL_Surface * canvas,
return;
if (rails_segment_modified > 0)
{
rails_draw((void *) ptr, which, canvas, last, x, y,
rails_segment_modified);
rails_draw((void *)ptr, which, canvas, last, x, y, rails_segment_modified);
}
if (rails_segment_modified_last > 0)
rails_draw((void *) ptr, which, canvas, last, x, y,
rails_segment_modified_last);
rails_draw((void *)ptr, which, canvas, last, x, y, rails_segment_modified_last);
if (rails_segment_to_add > 0)
{
rails_draw((void *) ptr, which, canvas, last, x, y, rails_segment_to_add);
rails_draw((void *) ptr, which, canvas, last, x, y,
rails_segment_modified_last);
rails_draw((void *)ptr, which, canvas, last, x, y, rails_segment_to_add);
rails_draw((void *)ptr, which, canvas, last, x, y, rails_segment_modified_last);
rails_segment_to_add = 0;
}
if (rails_segment_modified > 0)
@ -582,18 +549,15 @@ static void rails_draw_wrapper(void *ptr, int which, SDL_Surface * canvas,
}
void rails_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
int start_x, end_x, start_y, end_y, segment_start, segment_end, w, h;
// avoiding to write out of the canvas
if ((x < canvas->w) && (y < canvas->h) && (ox < canvas->w)
&& (oy < canvas->h) && ((signed) x > 0) && ((signed) y > 0)
&& ((signed) ox > 0) && ((signed) oy > 0))
&& (oy < canvas->h) && ((signed)x > 0) && ((signed)y > 0) && ((signed)ox > 0) && ((signed)oy > 0))
{
api->line((void *) api, which, canvas, snapshot, ox, oy, x, y, img_w / 2,
rails_draw_wrapper);
api->line((void *)api, which, canvas, snapshot, ox, oy, x, y, img_w / 2, rails_draw_wrapper);
start_x = min(ox, x);
end_x = max(ox, x);
@ -604,9 +568,9 @@ void rails_drag(magic_api * api, int which, SDL_Surface * canvas,
segment_end = rails_get_segment(end_x + img_w, end_y + img_h);
x = ((segment_start % rails_segments_x) - 1) * img_w;
y = (int) (segment_start / rails_segments_x) * img_h;
y = (int)(segment_start / rails_segments_x) * img_h;
w = ((segment_end % rails_segments_x) - 1) * img_w - x + img_w;
h = (int) (segment_end / rails_segments_x) * img_h - y + img_h;
h = (int)(segment_end / rails_segments_x) * img_h - y + img_h;
update_rect->x = x;
update_rect->y = y;
@ -627,6 +591,8 @@ Uint8 rails_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_U
return 0;
}
void rails_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void rails_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}

View file

@ -42,8 +42,7 @@
#define gettext_noop(String) String
#endif
void rain_click(magic_api *, int, int, SDL_Surface *, SDL_Surface *, int, int,
SDL_Rect *);
void rain_click(magic_api *, int, int, SDL_Surface *, SDL_Surface *, int, int, SDL_Rect *);
static int rain_SIZE = 30;
static int rain_AMOUNT = 200;
@ -84,13 +83,10 @@ SDL_Surface *rain_get_icon(magic_api * api, int which);
char *rain_get_name(magic_api * api, int which);
int rain_get_group(magic_api * api, int which);
char *rain_get_description(magic_api * api, int which, int mode);
static void do_rain_drop(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y);
static void rain_linecb(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y);
static void do_rain_drop(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
static void rain_linecb(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
void rain_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void rain_click(magic_api * api, int which, int mode, SDL_Surface * canvas,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void rain_release(magic_api * api, int which, SDL_Surface * canvas,
@ -99,14 +95,13 @@ void rain_shutdown(magic_api * api);
void rain_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
int rain_requires_colors(magic_api * api, int which);
void rain_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void rain_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void rain_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void rain_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int rain_modes(magic_api * api, int which);
Uint8 rain_accepted_sizes(magic_api * api, int which, int mode);
Uint8 rain_default_size(magic_api * api, int which, int mode);
void rain_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void rain_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
Uint32 rain_api_version(void)
@ -117,7 +112,7 @@ Uint32 rain_api_version(void)
//Checks if a a pixel is inside a raindrop shape centered on the origin
static int rain_inRainShape(double x, double y, double r)
{
if (sqrt(x * x + y * y) < (r * pow(cos(atan2(x, y)), (float) (rain_SIZE / 3.0))))
if (sqrt(x * x + y * y) < (r * pow(cos(atan2(x, y)), (float)(rain_SIZE / 3.0))))
{
return 1;
}
@ -133,8 +128,7 @@ int rain_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
//Load sounds
for (i = 0; i < rain_NUM_TOOLS; i++)
{
snprintf(fname, sizeof(fname), "%ssounds/magic/%s", api->data_directory,
rain_snd_filenames[i]);
snprintf(fname, sizeof(fname), "%ssounds/magic/%s", api->data_directory, rain_snd_filenames[i]);
rain_snd_effect[i] = Mix_LoadWAV(fname);
}
@ -151,8 +145,7 @@ SDL_Surface *rain_get_icon(magic_api * api, int which)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory,
rain_icon_filenames[which]);
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, rain_icon_filenames[which]);
return (IMG_Load(fname));
}
@ -169,16 +162,14 @@ int rain_get_group(magic_api * api ATTRIBUTE_UNUSED, int which)
}
// Return our descriptions, localized:
char *rain_get_description(magic_api * api ATTRIBUTE_UNUSED, int which,
int mode)
char *rain_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode)
{
return (strdup(gettext_noop(rain_descs[which][mode - 1])));
}
// Do the effect:
static void do_rain_drop(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)
{
magic_api *api = (magic_api *) ptr;
@ -195,17 +186,14 @@ static void do_rain_drop(void *ptr, int which ATTRIBUTE_UNUSED,
//api->hsvtorgb(h, s, rain_weights[(yy-y)*((rain_SIZE*2) -1)+(xx-x)], &r, &g, &b);
SDL_GetRGB(api->getpixel(canvas, xx, yy), canvas->format, &r, &g, &b);
api->putpixel(canvas, xx, yy,
SDL_MapRGB(canvas->format, clamp(0, r - 50, 255),
clamp(0, g - 50, 255), clamp(0, b + 200,
255)));
SDL_MapRGB(canvas->format, clamp(0, r - 50, 255), clamp(0, g - 50, 255), clamp(0, b + 200, 255)));
}
}
}
}
static void rain_linecb(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y)
static void rain_linecb(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
magic_api *api = (magic_api *) ptr;
SDL_Rect rect;
@ -213,17 +201,15 @@ static void rain_linecb(void *ptr, int which, SDL_Surface * canvas,
if (rand() % 10 == 0)
{
rain_click(api, which, MODE_PAINT, canvas, last,
x + (rand() % rain_SIZE * 2) - rain_SIZE,
y + (rand() % rain_SIZE * 2) - rain_SIZE, &rect);
x + (rand() % rain_SIZE * 2) - rain_SIZE, y + (rand() % rain_SIZE * 2) - rain_SIZE, &rect);
}
}
// Affect the canvas on drag:
void rain_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, rain_linecb);
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, rain_linecb);
if (ox > x)
{
@ -248,8 +234,7 @@ void rain_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void rain_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
if (mode == MODE_PAINT)
@ -270,8 +255,7 @@ void rain_click(magic_api * api, int which, int mode,
for (i = 0; i < rain_AMOUNT; i++)
{
do_rain_drop(api, which, canvas, last, rand() % canvas->w,
rand() % canvas->h);
do_rain_drop(api, which, canvas, last, rand() % canvas->w, rand() % canvas->h);
}
update_rect->x = 0;
@ -288,8 +272,7 @@ void rain_release(magic_api * api ATTRIBUTE_UNUSED,
int which 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 y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
@ -310,27 +293,25 @@ void rain_shutdown(magic_api * api ATTRIBUTE_UNUSED)
// Record the color from Tux Paint:
void rain_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
// Use colors:
int rain_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int rain_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 0;
}
void rain_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void rain_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
@ -351,7 +332,9 @@ Uint8 rain_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UN
return 2;
}
void rain_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void rain_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
rain_SIZE = size * 15;
rain_AMOUNT = 400 / size;

View file

@ -77,34 +77,29 @@ SDL_Surface *rainbow_get_icon(magic_api * api, int which);
char *rainbow_get_name(magic_api * api, int which);
int rainbow_get_group(magic_api * api, int which);
char *rainbow_get_description(magic_api * api, int which, int mode);
static void rainbow_linecb(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y);
static void rainbow_linecb(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
void rainbow_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void rainbow_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void rainbow_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void rainbow_shutdown(magic_api * api);
void rainbow_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
int rainbow_requires_colors(magic_api * api, int which);
void rainbow_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void rainbow_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void rainbow_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void rainbow_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int rainbow_modes(magic_api * api, int which);
Uint8 rainbow_accepted_sizes(magic_api * api, int which, int mode);
Uint8 rainbow_default_size(magic_api * api, int which, int mode);
void rainbow_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void rainbow_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
Uint32 rainbow_api_version(void)
@ -121,8 +116,7 @@ int rainbow_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
rainbow_color = 0;
rainbow_mix = 0;
snprintf(fname, sizeof(fname), "%ssounds/magic/rainbow.wav",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/rainbow.wav", api->data_directory);
rainbow_snd = Mix_LoadWAV(fname);
return (1);
@ -139,15 +133,13 @@ SDL_Surface *rainbow_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/rainbow.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/rainbow.png", api->data_directory);
return (IMG_Load(fname));
}
// Return our names, localized:
char *rainbow_get_name(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
char *rainbow_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
if (which == 0)
{
@ -160,16 +152,13 @@ char *rainbow_get_name(magic_api * api ATTRIBUTE_UNUSED,
}
// Return our group:
int rainbow_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int rainbow_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_PAINTING;
}
// Return our descriptions, localized:
char *rainbow_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED)
char *rainbow_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return (strdup(gettext_noop("You can draw in rainbow colors!")));
}
@ -177,8 +166,7 @@ char *rainbow_get_description(magic_api * api ATTRIBUTE_UNUSED,
// Do the effect:
static void rainbow_linecb(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)
{
magic_api *api = (magic_api *) ptr;
int xx, yy;
@ -197,8 +185,7 @@ static void rainbow_linecb(void *ptr, int which ATTRIBUTE_UNUSED,
// Affect the canvas on drag:
void rainbow_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
Uint8 r1, g1, b1, r2, g2, b2;
int rc_tmp;
@ -232,11 +219,9 @@ void rainbow_drag(magic_api * api, int which, SDL_Surface * canvas,
(r2 * rainbow_mix)) / MIX_MAX,
((g1 * (MIX_MAX - rainbow_mix)) +
(g2 * rainbow_mix)) / MIX_MAX,
((b1 * (MIX_MAX - rainbow_mix)) +
(b2 * rainbow_mix)) / MIX_MAX);
((b1 * (MIX_MAX - rainbow_mix)) + (b2 * rainbow_mix)) / MIX_MAX);
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1,
rainbow_linecb);
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, rainbow_linecb);
if (ox > x)
{
@ -263,8 +248,7 @@ void rainbow_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void rainbow_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
rainbow_drag(api, which, canvas, last, x, y, x, y, update_rect);
}
@ -273,8 +257,7 @@ void rainbow_release(magic_api * api ATTRIBUTE_UNUSED,
int which 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)
{
}
@ -286,32 +269,30 @@ void rainbow_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void rainbow_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void rainbow_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
// Use colors:
int rainbow_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int rainbow_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 0;
}
void rainbow_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void rainbow_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int rainbow_modes(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int rainbow_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (MODE_PAINT);
}
@ -327,7 +308,9 @@ Uint8 rainbow_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE
return 4;
}
void rainbow_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void rainbow_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
rainbow_radius = size * 4;
}

View file

@ -25,15 +25,12 @@ Mix_Chunk *realrainbow_snd;
int realrainbow_x1, realrainbow_y1, realrainbow_x2, realrainbow_y2;
SDL_Rect realrainbow_rect;
SDL_Surface *realrainbow_colors[2];
Uint8 realrainbow_blendr, realrainbow_blendg, realrainbow_blendb,
realrainbow_blenda;
Uint8 realrainbow_blendr, realrainbow_blendg, realrainbow_blendb, realrainbow_blenda;
void realrainbow_arc(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int x1, int y1, int x2, int y2,
int fulldraw, SDL_Rect * update_rect);
static void realrainbow_linecb(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y);
SDL_Surface * last, int x1, int y1, int x2, int y2, int fulldraw, SDL_Rect * update_rect);
static void realrainbow_linecb(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
Uint32 realrainbow_api_version(void);
int realrainbow_init(magic_api * api, Uint32 disabled_features);
int realrainbow_get_tool_count(magic_api * api);
@ -47,21 +44,17 @@ void realrainbow_shutdown(magic_api * api);
void realrainbow_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
void realrainbow_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void realrainbow_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void realrainbow_release(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
void realrainbow_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void realrainbow_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void realrainbow_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void realrainbow_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
Uint8 realrainbow_accepted_sizes(magic_api * api, int which, int mode);
Uint8 realrainbow_default_size(magic_api * api, int which, int mode);
void realrainbow_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void realrainbow_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
Uint32 realrainbow_api_version(void)
@ -73,21 +66,17 @@ int realrainbow_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/realrainbow-colors.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/realrainbow-colors.png", api->data_directory);
realrainbow_colors[0] = IMG_Load(fname);
if (realrainbow_colors[0] == NULL)
return (0);
snprintf(fname, sizeof(fname),
"%simages/magic/realrainbow-roygbiv-colors.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/realrainbow-roygbiv-colors.png", api->data_directory);
realrainbow_colors[1] = IMG_Load(fname);
if (realrainbow_colors[1] == NULL)
return (0);
snprintf(fname, sizeof(fname), "%ssounds/magic/realrainbow.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/realrainbow.ogg", api->data_directory);
realrainbow_snd = Mix_LoadWAV(fname);
return (1);
@ -103,11 +92,9 @@ SDL_Surface *realrainbow_get_icon(magic_api * api, int which)
char fname[1024];
if (which == 0)
snprintf(fname, sizeof(fname), "%simages/magic/realrainbow.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/realrainbow.png", api->data_directory);
else
snprintf(fname, sizeof(fname), "%simages/magic/realrainbow-roygbiv.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/realrainbow-roygbiv.png", api->data_directory);
return (IMG_Load(fname));
}
@ -120,29 +107,25 @@ char *realrainbow_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
return (strdup(gettext_noop("ROYGBIV Rainbow")));
}
int realrainbow_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int realrainbow_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_ARTISTIC;
}
char *realrainbow_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return (strdup
(gettext_noop
("Click where you want your rainbow to start, drag to where you want it to end, and then let go to draw a rainbow.")));
}
int realrainbow_modes(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int realrainbow_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (MODE_PAINT_WITH_PREVIEW);
}
int realrainbow_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int realrainbow_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (0);
}
@ -157,16 +140,17 @@ void realrainbow_shutdown(magic_api * api ATTRIBUTE_UNUSED)
Mix_FreeChunk(realrainbow_snd);
}
void realrainbow_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void realrainbow_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
void realrainbow_click(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
realrainbow_x1 = x;
realrainbow_y1 = y;
@ -179,8 +163,7 @@ void realrainbow_click(magic_api * api ATTRIBUTE_UNUSED,
void realrainbow_drag(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, int x,
int y, SDL_Rect * update_rect)
int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, int x, int y, SDL_Rect * update_rect)
{
int rx1, ry1, rx2, ry2;
SDL_Rect rect;
@ -217,8 +200,7 @@ void realrainbow_drag(magic_api * api, int which,
}
void realrainbow_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last, int x,
int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
int rx1, ry1, rx2, ry2;
SDL_Rect rect;
@ -257,23 +239,18 @@ void realrainbow_release(magic_api * api, int which,
}
void realrainbow_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void realrainbow_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void realrainbow_arc(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int x1, int y1, int x2, int y2,
int fulldraw, SDL_Rect * update_rect)
SDL_Surface * last, int x1, int y1, int x2, int y2, int fulldraw, SDL_Rect * update_rect)
{
int lowx, lowy, hix, hiy, xm, ym, xc, yc, r, a1, atan2_a, atan2_b;
int a, oa, ox, oy, nx, ny, step, thick, rr, done;
@ -320,7 +297,7 @@ void realrainbow_arc(magic_api * api, int which, SDL_Surface * canvas,
if (hix == lowx)
return;
slope = (float) (hiy - lowy) / (float) (hix - lowx);
slope = (float)(hiy - lowy) / (float)(hix - lowx);
yc = lowy;
xc = slope * (ym - yc) + xm;
@ -364,20 +341,16 @@ void realrainbow_arc(magic_api * api, int which, SDL_Surface * canvas,
nx = (rr * cos(a * M_PI / 180.0)) + xc;
ny = (rr * sin(a * M_PI / 180.0)) + yc;
colorindex =
realrainbow_colors[which]->h - 1 -
(((rr - r + (thick / 2)) * realrainbow_colors[which]->h) / thick);
colorindex = realrainbow_colors[which]->h - 1 - (((rr - r + (thick / 2)) * realrainbow_colors[which]->h) / thick);
SDL_GetRGBA(api->getpixel(realrainbow_colors[which], 0, colorindex),
realrainbow_colors[which]->format, &realrainbow_blendr,
&realrainbow_blendg, &realrainbow_blendb,
&realrainbow_blenda);
&realrainbow_blendg, &realrainbow_blendb, &realrainbow_blenda);
if (!fulldraw)
realrainbow_blenda = 255;
api->line((void *) api, 0, canvas, last, ox, oy, nx, ny, 1,
realrainbow_linecb);
api->line((void *)api, 0, canvas, last, ox, oy, nx, ny, 1, realrainbow_linecb);
}
oa = a;
@ -396,8 +369,7 @@ void realrainbow_arc(magic_api * api, int which, SDL_Surface * canvas,
}
static void realrainbow_linecb(void *ptr, int which ATTRIBUTE_UNUSED,
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;
Uint8 origr, origg, origb;
@ -405,21 +377,16 @@ static void realrainbow_linecb(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_GetRGB(api->getpixel(last, x, y), last->format, &origr, &origg, &origb);
newr =
((realrainbow_blendr * realrainbow_blenda) / 255) +
((origr * (255 - realrainbow_blenda)) / 255);
newg =
((realrainbow_blendg * realrainbow_blenda) / 255) +
((origg * (255 - realrainbow_blenda)) / 255);
newb =
((realrainbow_blendb * realrainbow_blenda) / 255) +
((origb * (255 - realrainbow_blenda)) / 255);
newr = ((realrainbow_blendr * realrainbow_blenda) / 255) + ((origr * (255 - realrainbow_blenda)) / 255);
newg = ((realrainbow_blendg * realrainbow_blenda) / 255) + ((origg * (255 - realrainbow_blenda)) / 255);
newb = ((realrainbow_blendb * realrainbow_blenda) / 255) + ((origb * (255 - realrainbow_blenda)) / 255);
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, newr, newg, newb));
}
Uint8 realrainbow_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
Uint8 realrainbow_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED)
{
return 0;
}
@ -429,6 +396,8 @@ Uint8 realrainbow_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRI
return 0;
}
void realrainbow_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void realrainbow_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}

View file

@ -59,28 +59,24 @@ char *reflection_get_name(magic_api * api, int which);
int reflection_get_group(magic_api * api, int which);
char *reflection_get_description(magic_api * api, int which, int mode);
void reflection_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void do_reflection(magic_api * api, SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect, int show_origin);
void reflection_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void reflection_release(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void reflection_shutdown(magic_api * api);
void reflection_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
int reflection_requires_colors(magic_api * api, int which);
void reflection_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void reflection_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void reflection_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void reflection_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int reflection_modes(magic_api * api, int which);
Uint8 reflection_accepted_sizes(magic_api * api, int which, int mode);
Uint8 reflection_default_size(magic_api * api, int which, int mode);
void reflection_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void reflection_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
@ -88,8 +84,7 @@ int reflection_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%ssounds/magic/reflection.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/reflection.ogg", api->data_directory);
reflection_snd = Mix_LoadWAV(fname);
return (1);
@ -114,38 +109,31 @@ SDL_Surface *reflection_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
return (IMG_Load(fname));
}
char *reflection_get_name(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
char *reflection_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (strdup(gettext_noop("Reflection")));
}
int reflection_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int reflection_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_PICTURE_WARPS;
}
char *reflection_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return (strdup
(gettext_noop
("Click and drag the mouse around to add a reflection to your picture.")));
return (strdup(gettext_noop("Click and drag the mouse around to add a reflection to your picture.")));
}
void reflection_drag(magic_api * api, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last,
int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, int x,
int y, SDL_Rect * update_rect)
int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, int x, int y, SDL_Rect * update_rect)
{
do_reflection(api, canvas, last, x, y, update_rect, 1);
}
void do_reflection(magic_api * api, SDL_Surface * canvas,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect,
int show_origin)
SDL_Surface * last, int x, int y, SDL_Rect * update_rect, int show_origin)
{
float scale;
int xx, yy;
@ -200,7 +188,7 @@ void do_reflection(magic_api * api, SDL_Surface * canvas,
/* Starting from `reflection_y1` and moving down,
we'll copy from `reflection_y1` and moving up */
scale = (float) reflection_y1 / (float) y;
scale = (float)reflection_y1 / (float)y;
for (yy = reflection_y1; yy < canvas->h; yy++)
{
@ -232,7 +220,7 @@ void do_reflection(magic_api * api, SDL_Surface * canvas,
/* Starting from `reflection_y1` and moving up,
we'll copy from `reflection_y1` and moving down */
scale = ((float) reflection_y1 / (float) y);
scale = ((float)reflection_y1 / (float)y);
for (yy = reflection_y1; yy >= 0; yy--)
{
@ -264,7 +252,7 @@ void do_reflection(magic_api * api, SDL_Surface * canvas,
/* Starting from `reflection_x1` and moving right,
we'll copy from `reflection_x1` and moving left */
scale = (float) reflection_x1 / (float) x;
scale = (float)reflection_x1 / (float)x;
for (xx = reflection_x1; xx < canvas->w; xx++)
{
@ -296,7 +284,7 @@ void do_reflection(magic_api * api, SDL_Surface * canvas,
/* Starting from `reflection_x1` and left up,
we'll copy from `reflection_x1` and right down */
scale = (float) reflection_x1 / (float) x;
scale = (float)reflection_x1 / (float)x;
for (xx = reflection_x1; xx >= 0; xx--)
{
@ -336,24 +324,20 @@ void do_reflection(magic_api * api, SDL_Surface * canvas,
}
else
{
for (yy = reflection_y1 - REFLECTION_XOR_SIZE;
yy < reflection_y1 + REFLECTION_XOR_SIZE; yy++)
for (yy = reflection_y1 - REFLECTION_XOR_SIZE; yy < reflection_y1 + REFLECTION_XOR_SIZE; yy++)
{
if (show_origin)
api->xorpixel(canvas, reflection_x1, yy);
else
api->putpixel(canvas, reflection_x1, yy,
api->getpixel(last, reflection_x1, yy));
api->putpixel(canvas, reflection_x1, yy, api->getpixel(last, reflection_x1, yy));
}
for (xx = reflection_x1 - REFLECTION_XOR_SIZE;
xx < reflection_x1 + REFLECTION_XOR_SIZE; xx++)
for (xx = reflection_x1 - REFLECTION_XOR_SIZE; xx < reflection_x1 + REFLECTION_XOR_SIZE; xx++)
{
if (show_origin)
api->xorpixel(canvas, xx, reflection_y1);
else
api->putpixel(canvas, xx, reflection_y1,
api->getpixel(last, xx, reflection_y1));
api->putpixel(canvas, xx, reflection_y1, api->getpixel(last, xx, reflection_y1));
}
update_rect->x -= REFLECTION_XOR_SIZE;
@ -362,13 +346,11 @@ void do_reflection(magic_api * api, SDL_Surface * canvas,
update_rect->h += (REFLECTION_XOR_SIZE * 2);
}
api->playsound(reflection_snd, (x * 255) / canvas->w,
(y * 255) / canvas->h);
api->playsound(reflection_snd, (x * 255) / canvas->w, (y * 255) / canvas->h);
}
void reflection_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
if (x <= 0)
x = 1;
@ -388,8 +370,7 @@ void reflection_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
}
void reflection_release(magic_api * api, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
do_reflection(api, canvas, last, x, y, update_rect, 0);
}
@ -400,34 +381,31 @@ void reflection_shutdown(magic_api * api ATTRIBUTE_UNUSED)
Mix_FreeChunk(reflection_snd);
}
void reflection_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void reflection_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
int reflection_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int reflection_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 0;
}
void reflection_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas)
{
reflection_x1 = canvas->w / 2;
reflection_y1 = canvas->h / 2;
}
void reflection_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int reflection_modes(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int reflection_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MODE_PAINT;
}
@ -443,6 +421,8 @@ Uint8 reflection_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIB
return 0;
}
void reflection_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void reflection_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}

View file

@ -49,27 +49,23 @@ char *ripples_get_name(magic_api * api, int which);
int ripples_get_group(magic_api * api, int which);
char *ripples_get_description(magic_api * api, int which, int mode);
void ripples_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
static void ripples_linecb(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
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, SDL_Surface * canvas,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void ripples_release(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void ripples_shutdown(magic_api * api);
void ripples_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
int ripples_requires_colors(magic_api * api, int which);
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_switchin(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);
Uint8 ripples_accepted_sizes(magic_api * api, int which, int mode);
Uint8 ripples_default_size(magic_api * api, int which, int mode);
void ripples_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void ripples_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
Uint32 ripples_api_version(void)
@ -85,8 +81,7 @@ int ripples_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%ssounds/magic/ripples.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/ripples.ogg", api->data_directory);
ripples_snd = Mix_LoadWAV(fname);
return (1);
@ -103,33 +98,27 @@ SDL_Surface *ripples_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/ripples.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/ripples.png", api->data_directory);
return (IMG_Load(fname));
}
// 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 our groups:
int ripples_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int ripples_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_DISTORTS;
}
// 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:
@ -138,14 +127,12 @@ void ripples_drag(magic_api * api 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_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,
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;
Uint8 r, g, b;
@ -163,8 +150,7 @@ static void ripples_linecb(void *ptr, int which ATTRIBUTE_UNUSED,
// Affect the canvas on click:
void ripples_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
float fli;
int ox, oy, nx, ny, d;
@ -183,18 +169,17 @@ void ripples_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
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);
api->line((void *)api, which, canvas, last, ox, oy, nx, ny, 1, ripples_linecb);
ox = nx;
oy = ny;
}
}
update_rect->x = x - (int) ripples_radius;
update_rect->y = y - (int) ripples_radius;
update_rect->w = ((int) ripples_radius) * 2;
update_rect->h = ((int) ripples_radius) * 2;
update_rect->x = x - (int)ripples_radius;
update_rect->y = y - (int)ripples_radius;
update_rect->w = ((int)ripples_radius) * 2;
update_rect->h = ((int)ripples_radius) * 2;
api->playsound(ripples_snd, (x * 255) / api->canvas_w, 255);
}
@ -204,8 +189,7 @@ void ripples_release(magic_api * api ATTRIBUTE_UNUSED,
int which 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)
{
}
@ -217,38 +201,37 @@ void ripples_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void ripples_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void ripples_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
// Use colors:
int ripples_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int ripples_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 0;
}
void ripples_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas 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 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);
}
Uint8 ripples_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED) {
Uint8 ripples_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return 10;
}
@ -257,7 +240,9 @@ Uint8 ripples_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE
return 5;
}
void ripples_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void ripples_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
ripples_radius = ((float) size) * 20.0;
ripples_radius = ((float)size) * 20.0;
}

View file

@ -36,7 +36,7 @@
#include "SDL_mixer.h"
#include <math.h> //for sin, cos, ...
static int ROSETTE_R = 8; //circle's diameter
static int ROSETTE_R = 8; //circle's diameter
static int xmid, ymid;
@ -62,28 +62,22 @@ int rosette_get_group(magic_api * api, int which);
char *rosette_get_description(magic_api * api, int which, int mode);
int rosette_requires_colors(magic_api * api, int which);
void rosette_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, int x,
int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
void rosette_shutdown(magic_api * api);
void rosette_draw(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y);
void rosette_draw(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
void rosette_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void rosette_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
void rosette_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void rosette_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void rosette_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void rosette_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int rosette_modes(magic_api * api, int which);
void rosette_circle(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y);
void rosette_circle(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
Uint8 rosette_accepted_sizes(magic_api * api, int which, int mode);
Uint8 rosette_default_size(magic_api * api, int which, int mode);
void rosette_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void rosette_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
Uint32 rosette_api_version(void)
@ -91,8 +85,9 @@ Uint32 rosette_api_version(void)
return (TP_MAGIC_API_VERSION);
}
void rosette_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void rosette_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g,
Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
//get the colors from API and store it in structure
rosette_colors.r = r;
@ -104,8 +99,7 @@ int rosette_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%ssounds/magic/picasso.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/picasso.ogg", api->data_directory);
rosette_snd = Mix_LoadWAV(fname);
return (1);
@ -121,11 +115,9 @@ SDL_Surface *rosette_get_icon(magic_api * api, int which)
char fname[1024];
if (!which)
snprintf(fname, sizeof(fname), "%simages/magic/rosette.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/rosette.png", api->data_directory);
else
snprintf(fname, sizeof(fname), "%simages/magic/picasso.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/picasso.png", api->data_directory);
return (IMG_Load(fname));
}
@ -138,14 +130,12 @@ char *rosette_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
return strdup(gettext_noop("Picasso"));
}
int rosette_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int rosette_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_PATTERN_PAINTING;
}
char *rosette_get_description(magic_api * api ATTRIBUTE_UNUSED, int which,
int mode ATTRIBUTE_UNUSED)
char *rosette_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
{
if (!which)
return strdup(gettext_noop("Click and start drawing your rosette.")); //just k'scope with 3 bits?
@ -153,8 +143,7 @@ char *rosette_get_description(magic_api * api ATTRIBUTE_UNUSED, int which,
return strdup(gettext_noop("You can draw just like Picasso!")); //what is this actually doing?
}
int rosette_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int rosette_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 1;
}
@ -163,8 +152,7 @@ void rosette_release(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * snapshot 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)
{
}
@ -176,8 +164,7 @@ void rosette_shutdown(magic_api * api ATTRIBUTE_UNUSED)
// Interactivity functions
void rosette_circle(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas,
SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
{
magic_api *api = (magic_api *) ptr;
@ -186,14 +173,11 @@ void rosette_circle(void *ptr, int which ATTRIBUTE_UNUSED,
for (yy = y - ROSETTE_R; yy < y + ROSETTE_R; yy++)
for (xx = x - ROSETTE_R; xx < x + ROSETTE_R; xx++)
if (api->in_circle(xx - x, yy - y, ROSETTE_R / 2))
api->putpixel(canvas, xx, yy,
SDL_MapRGB(canvas->format, rosette_colors.r,
rosette_colors.g, rosette_colors.b));
api->putpixel(canvas, xx, yy, SDL_MapRGB(canvas->format, rosette_colors.r, rosette_colors.g, rosette_colors.b));
}
void rosette_draw(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y)
void rosette_draw(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y)
{
magic_api *api = (magic_api *) ptr;
@ -201,18 +185,18 @@ void rosette_draw(void *ptr, int which, SDL_Surface * canvas,
double xx, yy; //distance to the center of the image
int x1, y1, x2, y2;
xx = (double) (xmid - x);
yy = (double) (y - ymid);
xx = (double)(xmid - x);
yy = (double)(y - ymid);
if (which == 0)
{
angle = 2 * M_PI / 3; //an angle between brushes
x1 = (int) (xx * cos(angle) - yy * sin(angle));
y1 = (int) (xx * sin(angle) + yy * cos(angle));
x1 = (int)(xx * cos(angle) - yy * sin(angle));
y1 = (int)(xx * sin(angle) + yy * cos(angle));
x2 = (int) (xx * cos(2 * angle) - yy * sin(2 * angle));
y2 = (int) (xx * sin(2 * angle) + yy * cos(2 * angle));
x2 = (int)(xx * cos(2 * angle) - yy * sin(2 * angle));
y2 = (int)(xx * sin(2 * angle) + yy * cos(2 * angle));
}
else
{
@ -230,11 +214,11 @@ void rosette_draw(void *ptr, int which, SDL_Surface * canvas,
if ((y == ymid) && (xx < 0))
angle = M_PI;
x1 = (int) (xx * cos(2 * angle) - yy * sin(2 * angle));
y1 = (int) (xx * sin(2 * angle) - yy * cos(angle));
x1 = (int)(xx * cos(2 * angle) - yy * sin(2 * angle));
y1 = (int)(xx * sin(2 * angle) - yy * cos(angle));
x2 = (int) (xx * cos(2 * angle) - yy * sin(2 * angle));
y2 = (int) (xx * sin(2 * angle) + yy * cos(2 * angle));
x2 = (int)(xx * cos(2 * angle) - yy * sin(2 * angle));
y2 = (int)(xx * sin(2 * angle) + yy * cos(2 * angle));
}
rosette_circle(api, which, canvas, snapshot, x, y);
@ -243,11 +227,9 @@ void rosette_draw(void *ptr, int which, SDL_Surface * canvas,
}
void rosette_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *) api, which, canvas, snapshot, ox, oy, x, y, 1,
rosette_draw);
api->line((void *)api, which, canvas, snapshot, ox, oy, x, y, 1, rosette_draw);
api->playsound(rosette_snd, (x * 255) / canvas->w, 255);
update_rect->x = update_rect->y = 0;
@ -256,29 +238,25 @@ void rosette_drag(magic_api * api, int which, SDL_Surface * canvas,
}
void rosette_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
rosette_drag(api, which, canvas, last, x, y, x, y, update_rect);
}
void rosette_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
xmid = canvas->w / 2;
ymid = canvas->h / 2;
}
void rosette_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int rosette_modes(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int rosette_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (MODE_PAINT);
}
@ -294,7 +272,9 @@ Uint8 rosette_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE
return 1;
}
void rosette_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void rosette_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
ROSETTE_R = (size + 2) * 2;
}

View file

@ -78,15 +78,12 @@ const char *sharpen_names[sharpen_NUM_TOOLS] = {
};
const char *sharpen_descs[sharpen_NUM_TOOLS][2] = {
{gettext_noop
("Click and drag the mouse to trace edges in parts of your picture."),
{gettext_noop("Click and drag the mouse to trace edges in parts of your picture."),
gettext_noop("Click to trace edges in your entire picture."),},
{gettext_noop("Click and drag the mouse to sharpen parts of your picture."),
gettext_noop("Click to sharpen the entire picture."),},
{gettext_noop
("Click and drag the mouse to create a black and white silhouette."),
gettext_noop
("Click to create a black and white silhouette of your entire picture.")},
{gettext_noop("Click and drag the mouse to create a black and white silhouette."),
gettext_noop("Click to create a black and white silhouette of your entire picture.")},
};
Uint32 sharpen_api_version(void);
@ -97,34 +94,28 @@ char *sharpen_get_name(magic_api * api, int which);
int sharpen_get_group(magic_api * api, int which);
char *sharpen_get_description(magic_api * api, int which, int mode);
static int sharpen_grey(Uint8 r1, Uint8 g1, Uint8 b1);
static void do_sharpen_pixel(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y);
static void do_sharpen_full(void *ptr, SDL_Surface * canvas,
SDL_Surface * last, int which);
static void do_sharpen_brush(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y);
static void do_sharpen_pixel(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
static void do_sharpen_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int which);
static void do_sharpen_brush(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
void sharpen_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void sharpen_click(magic_api * api, int which, int mode, SDL_Surface * canvas,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void sharpen_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void sharpen_shutdown(magic_api * api);
void sharpen_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
int sharpen_requires_colors(magic_api * api, int which);
void sharpen_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void sharpen_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void sharpen_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void sharpen_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int sharpen_modes(magic_api * api, int which);
Uint8 sharpen_accepted_sizes(magic_api * api, int which, int mode);
Uint8 sharpen_default_size(magic_api * api, int which, int mode);
void sharpen_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void sharpen_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
@ -143,8 +134,7 @@ int sharpen_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
for (i = 0; i < sharpen_NUM_TOOLS; i++)
{
snprintf(fname, sizeof(fname), "%ssounds/magic/%s", api->data_directory,
sharpen_snd_filenames[i]);
snprintf(fname, sizeof(fname), "%ssounds/magic/%s", api->data_directory, sharpen_snd_filenames[i]);
sharpen_snd_effect[i] = Mix_LoadWAV(fname);
}
@ -162,8 +152,7 @@ SDL_Surface *sharpen_get_icon(magic_api * api, int which)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory,
sharpen_icon_filenames[which]);
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, sharpen_icon_filenames[which]);
return (IMG_Load(fname));
}
@ -174,15 +163,13 @@ char *sharpen_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
}
// Return our group (all the same):
int sharpen_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int sharpen_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_DISTORTS;
}
// Return our descriptions, localized:
char *sharpen_get_description(magic_api * api ATTRIBUTE_UNUSED, int which,
int mode)
char *sharpen_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode)
{
return (strdup(gettext_noop(sharpen_descs[which][mode - 1])));
}
@ -194,8 +181,7 @@ static int sharpen_grey(Uint8 r1, Uint8 g1, Uint8 b1)
}
// Do the effect:
static void do_sharpen_pixel(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y)
static void do_sharpen_pixel(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
magic_api *api = (magic_api *) ptr;
@ -222,8 +208,7 @@ static void do_sharpen_pixel(void *ptr, int which, SDL_Surface * canvas,
for (j = -1; j < 2; j++)
{
//No need to check if inside canvas, getpixel does it for us.
SDL_GetRGB(api->getpixel(last, x + i, y + j), last->format, &r1, &g1,
&b1);
SDL_GetRGB(api->getpixel(last, x + i, y + j), last->format, &r1, &g1, &b1);
grey = sharpen_grey(r1, g1, b1);
sobel_1 += grey * sobel_weights_1[i + 1][j + 1];
sobel_2 += grey * sobel_weights_2[i + 1][j + 1];
@ -253,14 +238,12 @@ static void do_sharpen_pixel(void *ptr, int which, SDL_Surface * canvas,
api->putpixel(canvas, x, y,
SDL_MapRGB(canvas->format,
clamp(0.0, r1 + SHARPEN * temp, 255.0),
clamp(0.0, g1 + SHARPEN * temp, 255.0),
clamp(0.0, b1 + SHARPEN * temp, 255.0)));
clamp(0.0, g1 + SHARPEN * temp, 255.0), clamp(0.0, b1 + SHARPEN * temp, 255.0)));
}
}
// Do the effect for the full image
static void do_sharpen_full(void *ptr, SDL_Surface * canvas,
SDL_Surface * last, int which)
static void do_sharpen_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int which)
{
magic_api *api = (magic_api *) ptr;
@ -281,8 +264,7 @@ static void do_sharpen_full(void *ptr, SDL_Surface * canvas,
}
//do the effect for the brush
static void do_sharpen_brush(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y)
static void do_sharpen_brush(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
int xx, yy;
magic_api *api = (magic_api *) ptr;
@ -291,8 +273,7 @@ static void do_sharpen_brush(void *ptr, int which, SDL_Surface * canvas,
{
for (xx = x - sharpen_RADIUS; xx < x + sharpen_RADIUS; xx++)
{
if (api->in_circle(xx - x, yy - y, sharpen_RADIUS)
&& !api->touched(xx, yy))
if (api->in_circle(xx - x, yy - y, sharpen_RADIUS) && !api->touched(xx, yy))
{
do_sharpen_pixel(api, which, canvas, last, xx, yy);
}
@ -302,12 +283,10 @@ static void do_sharpen_brush(void *ptr, int which, SDL_Surface * canvas,
// Affect the canvas on drag:
void sharpen_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1,
do_sharpen_brush);
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_sharpen_brush);
api->playsound(sharpen_snd_effect[which], (x * 255) / canvas->w, 255);
@ -334,8 +313,7 @@ void sharpen_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void sharpen_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
if (mode == MODE_PAINT)
sharpen_drag(api, which, canvas, last, x, y, x, y, update_rect);
@ -355,8 +333,7 @@ void sharpen_release(magic_api * api ATTRIBUTE_UNUSED,
int which 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)
{
}
@ -376,32 +353,30 @@ void sharpen_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void sharpen_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void sharpen_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
// Use colors:
int sharpen_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int sharpen_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 0;
}
void sharpen_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void sharpen_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int sharpen_modes(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int sharpen_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (MODE_FULLSCREEN | MODE_PAINT);
}
@ -421,7 +396,9 @@ Uint8 sharpen_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE
return 4;
}
void sharpen_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void sharpen_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
sharpen_RADIUS = size * 4;
}

View file

@ -43,8 +43,7 @@ static Mix_Chunk *shift_snd;
/* Local function prototypes: */
static void shift_doit(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect, int crosshairs);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect, int crosshairs);
Uint32 shift_api_version(void);
int shift_init(magic_api * api, Uint32 disabled_features);
int shift_get_tool_count(magic_api * api);
@ -53,8 +52,7 @@ char *shift_get_name(magic_api * api, int which);
int shift_get_group(magic_api * api, int which);
char *shift_get_description(magic_api * api, int which, int mode);
void shift_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void shift_click(magic_api * api, int which, int mode, SDL_Surface * canvas,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void shift_release(magic_api * api, int which, SDL_Surface * canvas,
@ -64,15 +62,14 @@ void shift_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
int shift_requires_colors(magic_api * api, int which);
void shift_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void shift_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void shift_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void shift_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int shift_modes(magic_api * api, int which);
Uint8 shift_accepted_sizes(magic_api * api, int which, int mode);
Uint8 shift_default_size(magic_api * api, int which, int mode);
void shift_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void shift_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
@ -87,8 +84,7 @@ int shift_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%ssounds/magic/shift.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/shift.ogg", api->data_directory);
shift_snd = Mix_LoadWAV(fname);
return (1);
@ -101,46 +97,37 @@ int shift_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
}
// Load our icons:
SDL_Surface *shift_get_icon(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
SDL_Surface *shift_get_icon(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/shift.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/shift.png", api->data_directory);
return (IMG_Load(fname));
}
// Return our names, localized:
char *shift_get_name(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
char *shift_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (strdup(gettext_noop("Shift")));
}
// Return our group
int shift_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int shift_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_PICTURE_WARPS;
}
// Return our descriptions, localized:
char *shift_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED)
char *shift_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return (strdup
(gettext_noop
("Click and drag to shift your picture around on the canvas.")));
return (strdup(gettext_noop("Click and drag to shift your picture around on the canvas.")));
}
// Affect the canvas on drag:
void shift_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
if (ox == x && oy == y)
return; /* No-op */
@ -151,8 +138,7 @@ void shift_drag(magic_api * api, int which, SDL_Surface * canvas,
static void shift_doit(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
SDL_Surface * last, int ox ATTRIBUTE_UNUSED,
int oy ATTRIBUTE_UNUSED, int x, int y,
SDL_Rect * update_rect, int crosshairs)
int oy ATTRIBUTE_UNUSED, int x, int y, SDL_Rect * update_rect, int crosshairs)
{
SDL_Rect dest;
int dx, dy;
@ -313,8 +299,7 @@ static void shift_doit(magic_api * api ATTRIBUTE_UNUSED,
// Affect the canvas on click:
void shift_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
shift_x = x;
shift_y = y;
@ -324,8 +309,7 @@ void shift_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
// Affect the canvas on release:
void shift_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
shift_doit(api, which, canvas, last, x, y, x, y, update_rect, 0);
api->stopsound();
@ -340,27 +324,26 @@ void shift_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void shift_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void shift_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
// Use colors:
int shift_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int shift_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 0;
}
void shift_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void shift_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
@ -380,6 +363,8 @@ Uint8 shift_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_U
return 0;
}
void shift_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void shift_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}

View file

@ -48,11 +48,9 @@ SDL_Surface *smudge_get_icon(magic_api * api, int which);
char *smudge_get_name(magic_api * api, int which);
int smudge_get_group(magic_api * api, int which);
char *smudge_get_description(magic_api * api, int which, int mode);
static void do_smudge(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y);
static void do_smudge(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
void smudge_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void smudge_click(magic_api * api, int which, int mode, SDL_Surface * canvas,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void smudge_release(magic_api * api, int which, SDL_Surface * canvas,
@ -61,23 +59,21 @@ void smudge_shutdown(magic_api * api);
void smudge_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
int smudge_requires_colors(magic_api * api, int which);
void smudge_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void smudge_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void smudge_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void smudge_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int smudge_modes(magic_api * api, int which);
int smudge_get_tool_count(magic_api * api);
Uint8 smudge_accepted_sizes(magic_api * api, int which, int mode);
Uint8 smudge_default_size(magic_api * api, int which, int mode);
void smudge_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void smudge_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
int smudge_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%ssounds/magic/smudge.wav",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/smudge.wav", api->data_directory);
smudge_snd = Mix_LoadWAV(fname);
return (1);
@ -100,11 +96,9 @@ SDL_Surface *smudge_get_icon(magic_api * api, int which)
char fname[1024];
if (which == 0)
snprintf(fname, sizeof(fname), "%simages/magic/smudge.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/smudge.png", api->data_directory);
else /* if (which == 1) */
snprintf(fname, sizeof(fname), "%simages/magic/wetpaint.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/wetpaint.png", api->data_directory);
return (IMG_Load(fname));
}
@ -128,23 +122,17 @@ int smudge_get_group(magic_api * api ATTRIBUTE_UNUSED, int which)
}
// Return our descriptions, localized:
char *smudge_get_description(magic_api * api ATTRIBUTE_UNUSED, int which,
int mode ATTRIBUTE_UNUSED)
char *smudge_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
{
if (which == 0)
return (strdup
(gettext_noop
("Click and drag the mouse around to smudge the picture.")));
return (strdup(gettext_noop("Click and drag the mouse around to smudge the picture.")));
else /* if (which == 1) */
return (strdup
(gettext_noop
("Click and drag the mouse around to draw with wet, smudgy paint.")));
return (strdup(gettext_noop("Click and drag the mouse around to draw with wet, smudgy paint.")));
}
// Do the effect:
static void do_smudge(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y)
static void do_smudge(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
magic_api *api = (magic_api *) ptr;
static double state[256][256][3];
@ -160,8 +148,7 @@ static void do_smudge(void *ptr, int which, SDL_Surface * canvas,
for (xx = -(smudge_radius / 2); xx < (smudge_radius / 2); xx++)
if (api->in_circle(xx, yy, (smudge_radius / 2)))
{
SDL_GetRGB(api->getpixel(last, x + xx, y + yy), last->format, &r,
&g, &b);
SDL_GetRGB(api->getpixel(last, x + xx, y + yy), last->format, &r, &g, &b);
strength = (abs(xx * yy) / (smudge_radius / 2)) + 1;
api->putpixel(canvas, x + xx, y + yy, SDL_MapRGB(canvas->format,
(smudge_r +
@ -169,10 +156,7 @@ static void do_smudge(void *ptr, int which, SDL_Surface * canvas,
(strength + 1),
(smudge_g +
g * strength) /
(strength + 1),
(smudge_b +
b * strength) /
(strength + 1)));
(strength + 1), (smudge_b + b * strength) / (strength + 1)));
}
}
@ -182,37 +166,31 @@ static void do_smudge(void *ptr, int which, SDL_Surface * canvas,
int ix = i % (smudge_radius * 2);
int radius_check;
radius_check = (smudge_radius * 75) / 10; /* For 16 radius, we'll use 120 */
radius_check = (smudge_radius * 75) / 10; /* For 16 radius, we'll use 120 */
// is it not on the circle of radius sqrt(radius_check) at location (smudge_radius,smudge_radius)?
if ((ix - smudge_radius) * (ix - smudge_radius) + (iy - smudge_radius) * (iy - smudge_radius) > radius_check)
continue;
// it is on the circle, so grab it
SDL_GetRGB(api->getpixel(canvas, x + ix - smudge_radius, y + iy - smudge_radius), last->format,
&r, &g, &b);
state[ix][iy][0] =
rate * state[ix][iy][0] + (1.0 - rate) * api->sRGB_to_linear(r);
state[ix][iy][1] =
rate * state[ix][iy][1] + (1.0 - rate) * api->sRGB_to_linear(g);
state[ix][iy][2] =
rate * state[ix][iy][2] + (1.0 - rate) * api->sRGB_to_linear(b);
SDL_GetRGB(api->getpixel(canvas, x + ix - smudge_radius, y + iy - smudge_radius), last->format, &r, &g, &b);
state[ix][iy][0] = rate * state[ix][iy][0] + (1.0 - rate) * api->sRGB_to_linear(r);
state[ix][iy][1] = rate * state[ix][iy][1] + (1.0 - rate) * api->sRGB_to_linear(g);
state[ix][iy][2] = rate * state[ix][iy][2] + (1.0 - rate) * api->sRGB_to_linear(b);
// opacity 100% --> new data not blended w/ existing data
api->putpixel(canvas, x + ix - smudge_radius, y + iy - smudge_radius,
SDL_MapRGB(canvas->format,
api->linear_to_sRGB(state[ix][iy][0]),
api->linear_to_sRGB(state[ix][iy][1]),
api->linear_to_sRGB(state[ix][iy][2])));
api->linear_to_sRGB(state[ix][iy][1]), api->linear_to_sRGB(state[ix][iy][2])));
}
}
// Affect the canvas on drag:
void smudge_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_smudge);
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_smudge);
api->playsound(smudge_snd, (x * 255) / canvas->w, 255);
@ -239,8 +217,7 @@ void smudge_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void smudge_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
smudge_drag(api, which, canvas, last, x, y, x, y, update_rect);
}
@ -250,8 +227,7 @@ void smudge_release(magic_api * api ATTRIBUTE_UNUSED,
int which 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)
{
}
@ -263,8 +239,9 @@ void smudge_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void smudge_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void smudge_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g,
Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
smudge_r = r;
smudge_g = g;
@ -272,8 +249,7 @@ void smudge_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUS
}
// Use colors:
int smudge_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int smudge_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
if (which == 0)
return 0;
@ -282,14 +258,12 @@ int smudge_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
}
void smudge_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void smudge_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
@ -310,7 +284,9 @@ Uint8 smudge_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_
return 4;
}
void smudge_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void smudge_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
smudge_radius = size * 4;
}

View file

@ -89,29 +89,25 @@ SDL_Surface *snow_get_icon(magic_api * api, int which);
char *snow_get_name(magic_api * api, int which);
int snow_get_group(magic_api * api, int which);
char *snow_get_description(magic_api * api, int which);
static void do_snow(void *ptr, SDL_Surface * canvas, SDL_Surface * last,
int which, int snowAmount);
static void do_snow(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int which, int snowAmount);
void snow_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void snow_click(magic_api * api, int which, int mode, SDL_Surface * canvas,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void snow_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void snow_shutdown(magic_api * api);
void snow_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
int snow_requires_colors(magic_api * api, int which);
void snow_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void snow_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void snow_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void snow_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int snow_modes(magic_api * api, int which);
Uint8 snow_accepted_sizes(magic_api * api, int which, int mode);
Uint8 snow_default_size(magic_api * api, int which, int mode);
void snow_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void snow_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
Uint32 snow_api_version(void)
@ -128,16 +124,14 @@ int snow_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
srand(time(0));
snprintf(fname, sizeof(fname), "%simages/magic/Snow_flake4.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/Snow_flake4.png", api->data_directory);
snow_flake1 = IMG_Load(fname);
if (snow_flake1 == NULL)
{
return (0);
}
snprintf(fname, sizeof(fname), "%simages/magic/Snow_flake5.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/Snow_flake5.png", api->data_directory);
snow_flake2 = IMG_Load(fname);
if (snow_flake2 == NULL)
{
@ -146,8 +140,7 @@ int snow_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
for (i = 0; i < snow_NUM_TOOLS; i++)
{
snprintf(fname, sizeof(fname), "%ssounds/magic/%s", api->data_directory,
snow_snd_filenames[i]);
snprintf(fname, sizeof(fname), "%ssounds/magic/%s", api->data_directory, snow_snd_filenames[i]);
snow_snd_effect[i] = Mix_LoadWAV(fname);
}
return (1);
@ -163,8 +156,7 @@ SDL_Surface *snow_get_icon(magic_api * api, int which)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory,
snow_icon_filenames[which]);
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, snow_icon_filenames[which]);
return (IMG_Load(fname));
}
@ -174,8 +166,7 @@ char *snow_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
return (strdup(gettext_noop(snow_names[which])));
}
int snow_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int snow_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_PICTURE_DECORATIONS; /* Because we affect the whole image, and not just around the mouse */
}
@ -187,8 +178,7 @@ char *snow_get_description(magic_api * api ATTRIBUTE_UNUSED, int which)
}
// Do the effect:
static void do_snow(void *ptr, SDL_Surface * canvas, SDL_Surface * last,
int which, int snowAmount)
static void do_snow(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int which, int snowAmount)
{
magic_api *api = (magic_api *) ptr;
@ -208,10 +198,8 @@ static void do_snow(void *ptr, SDL_Surface * canvas, SDL_Surface * last,
{
if (api->in_circle(x, y, snow_RADIUS))
{
SDL_GetRGB(api->getpixel(last, centre_x + x, centre_y + y),
last->format, &r, &g, &b);
api->putpixel(canvas, centre_x + x, centre_y + y,
SDL_MapRGB(canvas->format, 255, 255, 255));
SDL_GetRGB(api->getpixel(last, centre_x + x, centre_y + y), last->format, &r, &g, &b);
api->putpixel(canvas, centre_x + x, centre_y + y, SDL_MapRGB(canvas->format, 255, 255, 255));
}
}
}
@ -237,8 +225,7 @@ void snow_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_Rect * update_rect ATTRIBUTE_UNUSED)
int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
// No-op
}
@ -246,8 +233,7 @@ void snow_drag(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
// Affect the canvas on click:
void snow_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last,
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED,
SDL_Rect * update_rect)
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect)
{
update_rect->x = 0;
update_rect->y = 0;
@ -263,8 +249,7 @@ void snow_release(magic_api * api ATTRIBUTE_UNUSED,
int which 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 y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
@ -293,26 +278,24 @@ void snow_shutdown(magic_api * api ATTRIBUTE_UNUSED)
// Record the color from Tux Paint:
void snow_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
// Use colors:
int snow_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int snow_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 0;
}
void snow_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void snow_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
@ -333,6 +316,8 @@ Uint8 snow_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UN
return 0;
}
void snow_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void snow_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}

View file

@ -60,25 +60,21 @@ int stretch_get_group(magic_api * api, int which);
char *stretch_get_description(magic_api * api, int which, int mode);
int stretch_requires_colors(magic_api * api, int which);
void stretch_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, int x,
int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
void stretch_shutdown(magic_api * api);
void stretch_paint_stretch(void *ptr_to_api, int which_tool,
SDL_Surface * canvas, SDL_Surface * snapshot,
int x, int y);
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
void stretch_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void stretch_click(magic_api * api, int which, int mode, SDL_Surface * canvas,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void stretch_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void stretch_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void stretch_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void stretch_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int stretch_modes(magic_api * api, int which);
Uint8 stretch_accepted_sizes(magic_api * api, int which, int mode);
Uint8 stretch_default_size(magic_api * api, int which, int mode);
void stretch_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void stretch_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
// Housekeeping functions
Uint32 stretch_api_version(void)
@ -86,8 +82,10 @@ Uint32 stretch_api_version(void)
return (TP_MAGIC_API_VERSION);
}
void stretch_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void stretch_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
@ -95,8 +93,7 @@ int stretch_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%ssounds/magic/stretch.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/stretch.ogg", api->data_directory);
stretch_snd = Mix_LoadWAV(fname);
return (1);
@ -111,35 +108,27 @@ SDL_Surface *stretch_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/stretch.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/stretch.png", api->data_directory);
return (IMG_Load(fname));
}
char *stretch_get_name(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
char *stretch_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return strdup(gettext_noop("Stretch"));
}
int stretch_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int stretch_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_PICTURE_WARPS;
}
char *stretch_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED)
char *stretch_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return
strdup(gettext_noop
("Click and drag to stretch part of your picture vertically or horizontally."));
return strdup(gettext_noop("Click and drag to stretch part of your picture vertically or horizontally."));
}
int stretch_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int stretch_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 0;
}
@ -148,8 +137,7 @@ void stretch_release(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * snapshot 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)
{
}
@ -162,8 +150,7 @@ void stretch_shutdown(magic_api * api ATTRIBUTE_UNUSED)
void stretch_drag(magic_api * api, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * snapshot,
int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, int x,
int y, SDL_Rect * update_rect)
int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, int x, int y, SDL_Rect * update_rect)
{
SDL_Rect src, dest;
float xx, yy;
@ -177,9 +164,8 @@ void stretch_drag(magic_api * api, int which ATTRIBUTE_UNUSED,
{
if (y != stretch_start_y)
{
divisor1 = (float) y / (float) stretch_start_y;
divisor2 =
(float) (canvas->h - y) / (float) (canvas->h - stretch_start_y);
divisor1 = (float)y / (float)stretch_start_y;
divisor2 = (float)(canvas->h - y) / (float)(canvas->h - stretch_start_y);
for (yy = 0; yy < y; yy++)
{
@ -220,9 +206,8 @@ void stretch_drag(magic_api * api, int which ATTRIBUTE_UNUSED,
{
if (x != stretch_start_x)
{
divisor1 = (float) x / (float) stretch_start_x;
divisor2 =
(float) (canvas->w - x) / (float) (canvas->w - stretch_start_x);
divisor1 = (float)x / (float)stretch_start_x;
divisor2 = (float)(canvas->w - x) / (float)(canvas->w - stretch_start_x);
for (xx = 0; xx < x; xx++)
{
@ -267,8 +252,7 @@ void stretch_drag(magic_api * api, int which ATTRIBUTE_UNUSED,
}
void stretch_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
if (y < canvas->h / 2)
{
@ -296,21 +280,18 @@ void stretch_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
}
void stretch_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void stretch_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int stretch_modes(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int stretch_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (MODE_PAINT);
}
@ -326,6 +307,8 @@ Uint8 stretch_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE
return 0;
}
void stretch_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void stretch_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}

View file

@ -10,8 +10,7 @@
unsigned int img_w, img_h;
static Uint8 string_r, string_g, string_b;
static int string_ox, string_oy;
static int string_vertex_x, string_vertex_y, string_vertex_done,
string_vertex_distance;
static int string_vertex_x, string_vertex_y, string_vertex_done, string_vertex_distance;
static SDL_Surface *canvas_backup;
enum string_tools
{
@ -25,24 +24,18 @@ Mix_Chunk *string_snd[STRING_NUMTOOLS];
// Custom function declarations
void string_callback(void *ptr, int which_tool, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y);
void string_callback_xor(void *ptr, int which_tool, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y);
void string_callback(void *ptr, int which_tool, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
void string_callback_xor(void *ptr, int which_tool, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
void string_draw_triangle(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x,
int y, SDL_Rect * update_rect);
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void string_draw_angle(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void string_draw_triangle_preview(magic_api * api, int which,
SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void string_draw_angle_preview(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot,
int ox, int oy, int x, int y,
SDL_Rect * update_rect);
int ox, int oy, int x, int y, SDL_Rect * update_rect);
void scale_xcoord(int *xcoord);
void scale_ycoord(int *ycoord);
void scale_coords(int *ox, int *oy, int *x, int *y);
@ -56,8 +49,7 @@ void compute_middle(int start_point, int end_point, int vertex, int *middle);
// Prototypes for required functions
void string_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
Uint32 string_api_version(void);
@ -71,20 +63,18 @@ int string_get_group(magic_api * api, int which);
char *string_get_description(magic_api * api, int which, int mode);
int string_requires_colors(magic_api * api, int which);
void string_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, int x,
int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
int string_init(magic_api * api, Uint32 disabled_features);
void string_shutdown(magic_api * api);
void string_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * snapshot);
void string_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * snapshot);
void string_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * snapshot);
void string_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * snapshot);
void string_click(magic_api * api, int which, int mode, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
Uint8 string_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED);
Uint8 string_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED);
void string_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED);
void string_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED);
// Required functions
@ -101,8 +91,9 @@ int string_modes(magic_api * api ATTRIBUTE_UNUSED, int which)
return (MODE_PAINT_WITH_PREVIEW);
}
void string_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void string_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g,
Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
string_r = r;
string_g = g;
@ -123,17 +114,13 @@ SDL_Surface *string_get_icon(magic_api * api, int which)
switch (which)
{
case STRING_TOOL_FULL_BY_OFFSET:
snprintf(fname, sizeof(fname),
"%simages/magic/string_art_full_by_offset.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/string_art_full_by_offset.png", api->data_directory);
break;
case STRING_TOOL_TRIANGLE:
snprintf(fname, sizeof(fname), "%simages/magic/string_art_triangles.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/string_art_triangles.png", api->data_directory);
break;
case STRING_TOOL_ANGLE:
snprintf(fname, sizeof(fname), "%simages/magic/string_art_angles.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/string_art_angles.png", api->data_directory);
break;
}
@ -141,8 +128,7 @@ SDL_Surface *string_get_icon(magic_api * api, int which)
}
char *string_get_name(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
char *string_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
switch (which)
{
@ -157,14 +143,12 @@ char *string_get_name(magic_api * api ATTRIBUTE_UNUSED,
}
}
int string_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int string_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_ARTISTIC;
}
char *string_get_description(magic_api * api ATTRIBUTE_UNUSED, int which,
int mode ATTRIBUTE_UNUSED)
char *string_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
{
switch (which)
{
@ -174,30 +158,25 @@ char *string_get_description(magic_api * api ATTRIBUTE_UNUSED, int which,
("Click and drag to draw string art. Drag top-bottom to draw less or more lines, left or right to make a bigger hole."));
break;
case STRING_TOOL_TRIANGLE:
return
strdup(gettext_noop
("Click and drag to draw arrows made of string art."));
return strdup(gettext_noop("Click and drag to draw arrows made of string art."));
break;
default:
return strdup(gettext_noop("Draw string art arrows with free angles."));
}
}
int string_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int string_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 1;
}
void string_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, int x,
int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
{
int dx, dy;
if (which == STRING_TOOL_TRIANGLE)
string_draw_triangle((void *) api, which, canvas, snapshot, string_ox,
string_oy, x, y, update_rect);
string_draw_triangle((void *)api, which, canvas, snapshot, string_ox, string_oy, x, y, update_rect);
if (which == STRING_TOOL_ANGLE)
{
if (!string_vertex_done) // maybe we face small children, draw square angles aligned to the drag
@ -207,8 +186,7 @@ void string_release(magic_api * api, int which,
y = y + dx;
x = x - dy;
}
string_draw_angle((void *) api, which, canvas, snapshot, string_ox,
string_oy, x, y, update_rect);
string_draw_angle((void *)api, which, canvas, snapshot, string_ox, string_oy, x, y, update_rect);
}
}
@ -216,16 +194,13 @@ int string_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%ssounds/magic/string.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/string.ogg", api->data_directory);
string_snd[STRING_TOOL_FULL_BY_OFFSET] = Mix_LoadWAV(fname);
snprintf(fname, sizeof(fname), "%ssounds/magic/string2.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/string2.ogg", api->data_directory);
string_snd[STRING_TOOL_TRIANGLE] = Mix_LoadWAV(fname);
snprintf(fname, sizeof(fname), "%ssounds/magic/string3.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/string3.ogg", api->data_directory);
string_snd[STRING_TOOL_ANGLE] = Mix_LoadWAV(fname);
return (1);
@ -248,20 +223,17 @@ void string_shutdown(magic_api * api ATTRIBUTE_UNUSED)
void string_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas,
SDL_Surface * snapshot ATTRIBUTE_UNUSED)
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED)
{
canvas_backup =
SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h,
canvas->format->BitsPerPixel, canvas->format->Rmask,
canvas->format->Gmask, canvas->format->Bmask,
canvas->format->Amask);
canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
}
void string_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * snapshot ATTRIBUTE_UNUSED)
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * snapshot ATTRIBUTE_UNUSED)
{
SDL_FreeSurface(canvas_backup);
canvas_backup = NULL;
@ -271,19 +243,15 @@ void string_switchout(magic_api * api ATTRIBUTE_UNUSED,
void string_callback(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas,
SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
{
magic_api *api = (magic_api *) ptr;
api->putpixel(canvas, x, y,
SDL_MapRGBA(canvas->format, string_r, string_g, string_b,
255));
api->putpixel(canvas, x, y, SDL_MapRGBA(canvas->format, string_r, string_g, string_b, 255));
}
void string_callback_xor(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas,
SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
{
magic_api *api = (magic_api *) ptr;
@ -292,8 +260,7 @@ void string_callback_xor(void *ptr, int which ATTRIBUTE_UNUSED,
void string_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
{
SDL_BlitSurface(canvas, NULL, canvas_backup, NULL);
@ -306,9 +273,7 @@ void string_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
static void string_draw_full_by_offset(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas,
SDL_Surface *
snapshot ATTRIBUTE_UNUSED, int x,
int y, SDL_Rect * update_rect)
SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y, SDL_Rect * update_rect)
{
magic_api *api = (magic_api *) ptr;
int u;
@ -318,16 +283,16 @@ static void string_draw_full_by_offset(void *ptr, int which ATTRIBUTE_UNUSED,
// int n=y/5;
int **a;
float step_w, step_h, aux;
int side = (int) (y / 3);
int side = (int)(y / 3);
SDL_BlitSurface(snapshot, 0, canvas, 0);
if (side < 3)
side = 3;
o = (int) (side * 4 * x / canvas->w);
step_w = canvas->w / (float) side;
step_h = canvas->h / (float) side;
o = (int)(side * 4 * x / canvas->w);
step_w = canvas->w / (float)side;
step_h = canvas->h / (float)side;
a = malloc(sizeof(int *) * side * 4 * 2);
@ -337,22 +302,22 @@ static void string_draw_full_by_offset(void *ptr, int which ATTRIBUTE_UNUSED,
if (i < side)
{
a[i][0] = 0;
aux = step_h * (float) i;
a[i][1] = (int) aux;
aux = step_h * (float)i;
a[i][1] = (int)aux;
}
else if (i < (side * 2))
{
a[i][0] = (int) ((float) (i % side) * step_w);
a[i][0] = (int)((float)(i % side) * step_w);
a[i][1] = canvas->h;
}
else if (i < (int) (side * 3))
else if (i < (int)(side * 3))
{
a[i][0] = canvas->w;
a[i][1] = (int) (canvas->h - (float) ((i % side) * step_h));
a[i][1] = (int)(canvas->h - (float)((i % side) * step_h));
}
else if (i < (int) (side * 4))
else if (i < (int)(side * 4))
{
a[i][0] = (int) (canvas->w - ((float) ((i % side) * step_w)));
a[i][0] = (int)(canvas->w - ((float)((i % side) * step_w)));
a[i][1] = 0;
}
}
@ -361,8 +326,7 @@ static void string_draw_full_by_offset(void *ptr, int which ATTRIBUTE_UNUSED,
for (i = 0; i < side * 4; i++)
{
u = (i + o) % (side * 4);
api->line((void *) api, which, canvas, snapshot, a[i][0], a[i][1],
a[u][0], a[u][1], 1, string_callback);
api->line((void *)api, which, canvas, snapshot, a[i][0], a[i][1], a[u][0], a[u][1], 1, string_callback);
}
for (i = 0; i < side * 4; i++)
@ -403,18 +367,13 @@ void scale_coords(int *ox, int *oy, int *x, int *y)
void compute_middle(int start_point, int end_point, int vertex, int *middle)
{
*middle =
min(start_point,
end_point) + (max(start_point, end_point) - min(start_point,
end_point)) / 2;
*middle =
min(*middle, vertex) + (max(*middle, vertex) - min(*middle, vertex)) / 2;
*middle = min(start_point, end_point) + (max(start_point, end_point) - min(start_point, end_point)) / 2;
*middle = min(*middle, vertex) + (max(*middle, vertex) - min(*middle, vertex)) / 2;
}
void string_draw_triangle_preview(magic_api * api, int which,
SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy,
int x, int y, SDL_Rect * update_rect)
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
int middle_x, middle_y;
@ -429,21 +388,15 @@ void string_draw_triangle_preview(magic_api * api, int which,
compute_middle(x, string_ox, string_ox, &middle_x);
compute_middle(y, string_oy, string_oy, &middle_y);
api->line((void *) api, which, canvas, snapshot, string_ox, string_oy,
string_ox, y, 1, string_callback_xor);
api->line((void *) api, which, canvas, snapshot, string_ox, string_oy, x,
string_oy, 1, string_callback_xor);
api->line((void *) api, which, canvas, snapshot, middle_x, middle_y, x,
string_oy, 1, string_callback_xor);
api->line((void *) api, which, canvas, snapshot, string_ox, y, middle_x,
middle_y, 1, string_callback_xor);
api->line((void *)api, which, canvas, snapshot, string_ox, string_oy, string_ox, y, 1, string_callback_xor);
api->line((void *)api, which, canvas, snapshot, string_ox, string_oy, x, string_oy, 1, string_callback_xor);
api->line((void *)api, which, canvas, snapshot, middle_x, middle_y, x, string_oy, 1, string_callback_xor);
api->line((void *)api, which, canvas, snapshot, string_ox, y, middle_x, middle_y, 1, string_callback_xor);
}
void string_draw_angle_preview(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot,
int ox ATTRIBUTE_UNUSED,
int oy ATTRIBUTE_UNUSED, int x, int y,
SDL_Rect * update_rect)
int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, int x, int y, SDL_Rect * update_rect)
{
int middle_x, middle_y;
int dx, dy;
@ -454,7 +407,7 @@ void string_draw_angle_preview(magic_api * api, int which,
update_rect->h = canvas->h;
SDL_BlitSurface(canvas_backup, update_rect, canvas, update_rect);
api->line((void *) api, which, canvas, snapshot, string_ox, string_oy,
api->line((void *)api, which, canvas, snapshot, string_ox, string_oy,
string_vertex_x, string_vertex_y, 1, string_callback_xor);
if (!string_vertex_done)
{
@ -469,22 +422,17 @@ void string_draw_angle_preview(magic_api * api, int which,
compute_middle(string_ox, x, string_vertex_x, &middle_x);
compute_middle(string_oy, y, string_vertex_y, &middle_y);
api->line((void *) api, which, canvas, snapshot, string_vertex_x,
string_vertex_y, x, y, 1, string_callback_xor);
api->line((void *) api, which, canvas, snapshot, string_ox, string_oy,
middle_x, middle_y, 1, string_callback_xor);
api->line((void *) api, which, canvas, snapshot, x, y, middle_x, middle_y,
1, string_callback_xor);
api->line((void *)api, which, canvas, snapshot, string_vertex_x, string_vertex_y, x, y, 1, string_callback_xor);
api->line((void *)api, which, canvas, snapshot, string_ox, string_oy, middle_x, middle_y, 1, string_callback_xor);
api->line((void *)api, which, canvas, snapshot, x, y, middle_x, middle_y, 1, string_callback_xor);
}
void string_draw_angle(magic_api * api, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas,
SDL_Surface * snapshot ATTRIBUTE_UNUSED,
int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED,
int x, int y, SDL_Rect * update_rect)
int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, int x, int y, SDL_Rect * update_rect)
{
float first_arm_step_x, first_arm_step_y, second_arm_step_x,
second_arm_step_y;
float first_arm_step_x, first_arm_step_y, second_arm_step_x, second_arm_step_y;
int i;
int max_wh, steps;
int max_separation = 10;
@ -498,29 +446,26 @@ void string_draw_angle(magic_api * api, int which ATTRIBUTE_UNUSED,
max_wh =
max(max(max(string_ox, string_vertex_x), x) -
min(min(string_vertex_x, x), string_ox),
max(max(string_oy, string_vertex_y), y) - min(min(string_vertex_y, y),
string_oy));
max(max(string_oy, string_vertex_y), y) - min(min(string_vertex_y, y), string_oy));
steps = max_wh / max_separation;
first_arm_step_x = (float) (string_ox - string_vertex_x) / (float) steps;
first_arm_step_y = (float) (string_oy - string_vertex_y) / (float) steps;
second_arm_step_x = (float) (string_vertex_x - x) / (float) steps;
second_arm_step_y = (float) (string_vertex_y - y) / (float) steps;
first_arm_step_x = (float)(string_ox - string_vertex_x) / (float)steps;
first_arm_step_y = (float)(string_oy - string_vertex_y) / (float)steps;
second_arm_step_x = (float)(string_vertex_x - x) / (float)steps;
second_arm_step_y = (float)(string_vertex_y - y) / (float)steps;
for (i = 0; i <= steps; i++)
{
api->line((void *) api, 0, canvas, snapshot,
api->line((void *)api, 0, canvas, snapshot,
string_ox - first_arm_step_x * i,
string_oy - first_arm_step_y * i,
string_vertex_x - second_arm_step_x * i,
string_vertex_y - second_arm_step_y * i, 1, string_callback);
string_vertex_x - second_arm_step_x * i, string_vertex_y - second_arm_step_y * i, 1, string_callback);
}
}
void string_draw_triangle(magic_api * api, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * snapshot,
int ox, int oy, int x, int y,
SDL_Rect * update_rect)
int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
SDL_BlitSurface(canvas_backup, 0, canvas, 0);
scale_coords(&ox, &oy, &x, &y);
@ -531,8 +476,7 @@ void string_draw_triangle(magic_api * api, int which ATTRIBUTE_UNUSED,
string_oy = y;
y = string_vertex_y;
string_draw_angle((void *) api, which, canvas, snapshot, string_ox,
string_oy, x, y, update_rect);
string_draw_angle((void *)api, which, canvas, snapshot, string_ox, string_oy, x, y, update_rect);
}
void string_draw_wrapper(magic_api * api, int which,
@ -540,14 +484,11 @@ void string_draw_wrapper(magic_api * api, int which,
int oy, int x, int y, SDL_Rect * update_rect)
{
if (which == STRING_TOOL_FULL_BY_OFFSET)
string_draw_full_by_offset((void *) api, which, canvas, snapshot, x, y,
update_rect);
string_draw_full_by_offset((void *)api, which, canvas, snapshot, x, y, update_rect);
else if (which == STRING_TOOL_TRIANGLE)
string_draw_triangle_preview((void *) api, which, canvas, snapshot, ox,
oy, x, y, update_rect);
string_draw_triangle_preview((void *)api, which, canvas, snapshot, ox, oy, x, y, update_rect);
else if (which == STRING_TOOL_ANGLE)
string_draw_angle_preview((void *) api, which, canvas, snapshot, ox, oy,
x, y, update_rect);
string_draw_angle_preview((void *)api, which, canvas, snapshot, ox, oy, x, y, update_rect);
}
void string_set_vertex(int x, int y)
@ -569,16 +510,13 @@ void string_set_vertex(int x, int y)
}
void string_drag(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, int ox, int oy,
int x, int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
if ((x < canvas->w) && (y < canvas->h) && (ox < canvas->w)
&& (oy < canvas->h) && ((signed) x > 0) && ((signed) y > 0)
&& ((signed) ox > 0) && ((signed) oy > 0))
&& (oy < canvas->h) && ((signed)x > 0) && ((signed)y > 0) && ((signed)ox > 0) && ((signed)oy > 0))
{
string_set_vertex(x, y);
string_draw_wrapper((void *) api, which, canvas, snapshot, ox, oy, x, y,
update_rect);
string_draw_wrapper((void *)api, which, canvas, snapshot, ox, oy, x, y, update_rect);
api->playsound(string_snd[which], (x * 255) / canvas->w, 255);
}
@ -596,6 +534,8 @@ Uint8 string_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_
return 0;
}
void string_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void string_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}

View file

@ -19,41 +19,39 @@
#include "SDL_image.h"
#include "SDL_mixer.h"
enum {
enum
{
SWIRL_TOOL_CIRCLES,
SWIRL_TOOL_RAYS,
SWIRL_TOOL_FUR,
NUM_SWIRL_TOOLS
};
char * swirl_names[NUM_SWIRL_TOOLS] = {
char *swirl_names[NUM_SWIRL_TOOLS] = {
gettext_noop("Circles"),
gettext_noop("Rays"),
gettext_noop("Fur")
};
char * swirl_descriptions[NUM_SWIRL_TOOLS][2] = {
char *swirl_descriptions[NUM_SWIRL_TOOLS][2] = {
{
gettext_noop("Click and drag to transform parts of your picture to circular brushstrokes."),
gettext_noop("Click to turn your entire picture into circular brushstrokes.")
},
gettext_noop("Click to turn your entire picture into circular brushstrokes.")},
{
gettext_noop("Click and drag to transform parts of your picture to brushstroke rays."),
gettext_noop("Click to turn your entire picture into brushstroke rays.")
},
gettext_noop("Click to turn your entire picture into brushstroke rays.")},
{
gettext_noop("Click and drag to add fur to your picture."),
""
},
""},
};
char * swirl_icon_filenames[NUM_SWIRL_TOOLS] = {
char *swirl_icon_filenames[NUM_SWIRL_TOOLS] = {
"swirls_circles.png",
"swirls_rays.png",
"swirls_fur.png"
};
char * swirl_sfx_filenames[NUM_SWIRL_TOOLS] = {
char *swirl_sfx_filenames[NUM_SWIRL_TOOLS] = {
"swirls_circles.ogg",
"swirls_rays.ogg",
"swirls_fur.ogg"
@ -78,7 +76,7 @@ int SWIRLS_STROKE_LENGTH[NUM_SWIRL_TOOLS] = {
};
Mix_Chunk *snd_effects[NUM_SWIRL_TOOLS];
SDL_Surface * swirls_snapshot = NULL;
SDL_Surface *swirls_snapshot = NULL;
int swirls_start_x, swirls_start_y;
Uint32 swirl_stroke_color;
Uint8 swirl_fur_color_r, swirl_fur_color_g, swirl_fur_color_b;
@ -94,31 +92,24 @@ int swirls_requires_colors(magic_api * api, int which);
int swirls_modes(magic_api * api, int which);
void swirls_shutdown(magic_api * api);
void swirls_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * snapshot, int x,
int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
void swirls_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
void swirls_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
void swirls_line_callback_drag(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y);
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void swirls_line_callback_drag(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
void swirls_draw_stroke(magic_api * api, int which, SDL_Surface * canvas, int x, int y);
void swirls_line_callback_draw_stroke(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas,
SDL_Surface * snapshot ATTRIBUTE_UNUSED,
int x, int y);
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y);
void swirls_release(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect);
void swirls_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void swirls_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
void swirls_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void swirls_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
double get_angle(int x, int y, int target_x, int target_y);
Uint8 swirls_accepted_sizes(magic_api * api, int which, int mode);
Uint8 swirls_default_size(magic_api * api, int which, int mode);
void swirls_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void swirls_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
Uint32 swirls_api_version(void)
@ -131,9 +122,9 @@ int swirls_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
int i;
char fname[1024];
for (i = 0; i < NUM_SWIRL_TOOLS; i++) {
snprintf(fname, sizeof(fname), "%ssounds/magic/%s",
api->data_directory, swirl_sfx_filenames[i]);
for (i = 0; i < NUM_SWIRL_TOOLS; i++)
{
snprintf(fname, sizeof(fname), "%ssounds/magic/%s", api->data_directory, swirl_sfx_filenames[i]);
snd_effects[i] = Mix_LoadWAV(fname);
}
@ -150,50 +141,53 @@ SDL_Surface *swirls_get_icon(magic_api * api, int which)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/%s",
api->data_directory, swirl_icon_filenames[which]);
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, swirl_icon_filenames[which]);
return (IMG_Load(fname));
}
char *swirls_get_name(magic_api * api ATTRIBUTE_UNUSED,
int which)
char *swirls_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
{
return strdup(gettext(swirl_names[which]));
}
int swirls_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int swirls_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
if (which == SWIRL_TOOL_FUR) {
if (which == SWIRL_TOOL_FUR)
{
return MAGIC_TYPE_PAINTING;
} else {
}
else
{
return MAGIC_TYPE_DISTORTS;
}
}
char *swirls_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which, int mode)
char *swirls_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode)
{
return strdup(gettext(swirl_descriptions[which][mode - 1]));
}
int swirls_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which)
int swirls_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which)
{
if (which == SWIRL_TOOL_FUR) {
if (which == SWIRL_TOOL_FUR)
{
return 1;
} else {
}
else
{
return 0;
}
}
int swirls_modes(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int swirls_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
if (which == SWIRL_TOOL_FUR) {
if (which == SWIRL_TOOL_FUR)
{
return MODE_PAINT;
} else {
}
else
{
return (MODE_PAINT | MODE_FULLSCREEN);
}
}
@ -202,7 +196,8 @@ void swirls_shutdown(magic_api * api ATTRIBUTE_UNUSED)
{
int i;
for (i = 0; i < NUM_SWIRL_TOOLS; i++) {
for (i = 0; i < NUM_SWIRL_TOOLS; i++)
{
if (snd_effects[i] != NULL)
Mix_FreeChunk(snd_effects[i]);
}
@ -210,8 +205,7 @@ void swirls_shutdown(magic_api * api ATTRIBUTE_UNUSED)
void
swirls_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
{
if (snd_effects[which] != NULL)
api->stopsound();
@ -219,16 +213,23 @@ swirls_click(magic_api * api, int which, int mode,
swirls_start_x = x;
swirls_start_y = y;
if (mode == MODE_PAINT) {
if (mode == MODE_PAINT)
{
swirls_drag(api, which, canvas, snapshot, x, y, x, y, update_rect);
} else {
if (snd_effects[which] != NULL) {
}
else
{
if (snd_effects[which] != NULL)
{
api->playsound(snd_effects[which], (x * 255) / canvas->w, 255);
}
for (x = 0; x < canvas->w; x++) {
for (y = 0; y < canvas->h; y++) {
if (rand() % 100 == 0) {
for (x = 0; x < canvas->w; x++)
{
for (y = 0; y < canvas->h; y++)
{
if (rand() % 100 == 0)
{
swirls_draw_stroke(api, which, canvas, x, y);
}
}
@ -244,14 +245,15 @@ swirls_click(magic_api * api, int which, int mode,
void
swirls_drag(magic_api * api ATTRIBUTE_UNUSED, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect)
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
if (which == SWIRL_TOOL_FUR) {
if (which == SWIRL_TOOL_FUR)
{
swirls_start_x = x;
swirls_start_y = y;
}
api->line((void *) api, which, canvas, snapshot, ox, oy, x, y, 1 /* FIXME: Consider fewer iterations? */,
api->line((void *)api, which, canvas, snapshot, ox, oy, x, y, 1 /* FIXME: Consider fewer iterations? */ ,
swirls_line_callback_drag);
/* FIXME: Would be good to only update the area around the line (ox,oy)->(x,y) (+/- the maxium radius of the effect) */
@ -263,10 +265,10 @@ swirls_drag(magic_api * api ATTRIBUTE_UNUSED, int which, SDL_Surface * canvas,
void swirls_release(magic_api * api, int which,
SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * snapshot ATTRIBUTE_UNUSED,
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED) {
SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * snapshot ATTRIBUTE_UNUSED,
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
if (snd_effects[which] != NULL && which != SWIRL_TOOL_FUR)
api->stopsound();
}
@ -275,8 +277,7 @@ void swirls_release(magic_api * api, int which,
void swirls_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 r, Uint8 g, Uint8 b,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
swirl_fur_color_r = r;
swirl_fur_color_g = g;
@ -285,9 +286,7 @@ void swirls_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUS
void swirls_line_callback_drag(void *ptr, int which,
SDL_Surface * canvas,
SDL_Surface * snapshot ATTRIBUTE_UNUSED,
int x, int y)
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
{
int i, ang_deg, radius, nx, ny;
double ang_rad;
@ -296,19 +295,21 @@ void swirls_line_callback_drag(void *ptr, int which,
if (snd_effects[which] != NULL)
api->playsound(snd_effects[which], (x * 255) / canvas->w, 255);
for (i = 0; i < SWIRLS_NUM_STROKES_PER_DRAG_LINE[which]; i++) {
for (i = 0; i < SWIRLS_NUM_STROKES_PER_DRAG_LINE[which]; i++)
{
ang_deg = (rand() % 360);
ang_rad = (ang_deg * M_PI) / 180.0;
radius = (rand() % (SWIRLS_DRAG_LINE_STROKE_RADIUS[which] * 2)) - SWIRLS_DRAG_LINE_STROKE_RADIUS[which];
nx = x + (int) (cos(ang_rad) * radius);
ny = y + (int) (sin(ang_rad) * radius);
nx = x + (int)(cos(ang_rad) * radius);
ny = y + (int)(sin(ang_rad) * radius);
swirls_draw_stroke(api, which, canvas, nx, ny);
}
}
void swirls_draw_stroke(magic_api * api, int which, SDL_Surface * canvas, int x, int y) {
void swirls_draw_stroke(magic_api * api, int which, SDL_Surface * canvas, int x, int y)
{
int x1, y1, x2, y2, len;
double a;
Uint8 r, g, b;
@ -317,66 +318,85 @@ void swirls_draw_stroke(magic_api * api, int which, SDL_Surface * canvas, int x,
len = SWIRLS_STROKE_LENGTH[which];
a = get_angle(x, y, swirls_start_x, swirls_start_y);
if (which == SWIRL_TOOL_CIRCLES) {
if (which == SWIRL_TOOL_CIRCLES)
{
a = a + (M_PI / 2.0);
}
x1 = x - cos(a) * len;
y1 = y - sin(a) * len;
x2 = x + cos(a) * len;
y2 = y + sin(a) * len;
if (which == SWIRL_TOOL_FUR) {
if (which == SWIRL_TOOL_FUR)
{
r = swirl_fur_color_r;
g = swirl_fur_color_g;
b = swirl_fur_color_b;
} else {
}
else
{
swirl_stroke_color = api->getpixel(swirls_snapshot, x, y);
SDL_GetRGB(swirl_stroke_color, canvas->format, &r, &g, &b);
}
api->rgbtohsv(r, g, b, &h, &s, &v);
h = h + (((rand() % 7) - 3) / 10.0);
if (s > 0.00) {
if (s > 0.00)
{
s = s + (((rand() % 3) - 1) / 10.0);
}
v = v + (((rand() % 3) - 1) / 10.0);
if (h < 0.0) {
h = h - 360.0;
} else if (h >= 360.0) {
if (h < 0.0)
{
h = h - 360.0;
}
if (s < 0.0) {
else if (h >= 360.0)
{
h = h - 360.0;
}
if (s < 0.0)
{
s = 0.0;
} else if (s > 1.0) {
}
else if (s > 1.0)
{
s = 1.0;
}
if (v < 0.0) {
if (v < 0.0)
{
v = 0.0;
} else if (v > 1.0) {
}
else if (v > 1.0)
{
v = 1.0;
}
api->hsvtorgb(h, s, v, &r, &g, &b);
swirl_stroke_color = SDL_MapRGB(canvas->format, r, g, b);
api->line((void *) api, which, canvas, NULL /* N/A */,
api->line((void *)api, which, canvas, NULL /* N/A */ ,
x1, y1, x2, y2, 1, swirls_line_callback_draw_stroke);
}
void swirls_line_callback_draw_stroke(void *ptr, int which,
SDL_Surface * canvas,
SDL_Surface * snapshot ATTRIBUTE_UNUSED,
int x, int y) {
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
{
magic_api *api = (magic_api *) ptr;
if (which == SWIRL_TOOL_FUR) {
if (which == SWIRL_TOOL_FUR)
{
api->putpixel(canvas, x, y, swirl_stroke_color);
} else {
}
else
{
int xx, yy;
for (yy = -1; yy <= 1; yy++) {
for (xx = -1; xx <= 1; xx++) {
for (yy = -1; yy <= 1; yy++)
{
for (xx = -1; xx <= 1; xx++)
{
api->putpixel(canvas, x + xx, y + yy, swirl_stroke_color);
}
}
@ -385,28 +405,25 @@ void swirls_line_callback_draw_stroke(void *ptr, int which,
void swirls_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas)
{
if (swirls_snapshot == NULL)
swirls_snapshot = SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h,
canvas->format->BitsPerPixel, canvas->format->Rmask,
canvas->format->Gmask, canvas->format->Bmask,
canvas->format->Amask);
canvas->format->BitsPerPixel, canvas->format->Rmask,
canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
if (swirls_snapshot != NULL)
SDL_BlitSurface(canvas, NULL, swirls_snapshot, NULL);
}
void swirls_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
double get_angle(int x, int y, int target_x, int target_y) {
return atan2((double) (y - target_y), (double) (x - target_x));
double get_angle(int x, int y, int target_x, int target_y)
{
return atan2((double)(y - target_y), (double)(x - target_x));
}
@ -423,6 +440,8 @@ Uint8 swirls_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_
return 0;
}
void swirls_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void swirls_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}

View file

@ -75,13 +75,10 @@ const char *tint_names[tint_NUM_TOOLS] = {
};
const char *tint_descs[tint_NUM_TOOLS][2] = {
{gettext_noop
("Click and drag the mouse around to change the color of parts of your picture."),
{gettext_noop("Click and drag the mouse around to change the color of parts of your picture."),
gettext_noop("Click to change the color of your entire picture."),},
{gettext_noop
("Click and drag the mouse around to turn parts of your picture into white and a color you choose."),
gettext_noop
("Click to turn your entire picture into white and a color you choose.")}
{gettext_noop("Click and drag the mouse around to turn parts of your picture into white and a color you choose."),
gettext_noop("Click to turn your entire picture into white and a color you choose.")}
};
int tint_init(magic_api * api, Uint32 disabled_features);
@ -92,15 +89,11 @@ char *tint_get_name(magic_api * api, int which);
int tint_get_group(magic_api * api, int which);
char *tint_get_description(magic_api * api, int which, int mode);
static int tint_grey(Uint8 r1, Uint8 g1, Uint8 b1);
static void do_tint_pixel(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y);
static void do_tint_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last,
int which);
static void do_tint_brush(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y);
static void do_tint_pixel(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
static void do_tint_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int which);
static void do_tint_brush(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
void tint_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void tint_click(magic_api * api, int which, int mode, SDL_Surface * canvas,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void tint_release(magic_api * api, int which, SDL_Surface * canvas,
@ -109,14 +102,13 @@ void tint_shutdown(magic_api * api);
void tint_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
int tint_requires_colors(magic_api * api, int which);
void tint_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void tint_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void tint_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void tint_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int tint_modes(magic_api * api, int which);
Uint8 tint_accepted_sizes(magic_api * api, int which, int mode);
Uint8 tint_default_size(magic_api * api, int which, int mode);
void tint_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void tint_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
Uint32 tint_api_version(void)
@ -126,13 +118,13 @@ Uint32 tint_api_version(void)
//Load sounds
int tint_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{int i;
{
int i;
char fname[1024];
for (i = 0; i < tint_NUM_TOOLS; i++)
{
snprintf(fname, sizeof(fname), "%ssounds/magic/%s", api->data_directory,
tint_snd_filenames[i]);
snprintf(fname, sizeof(fname), "%ssounds/magic/%s", api->data_directory, tint_snd_filenames[i]);
tint_snd_effect[i] = Mix_LoadWAV(fname);
}
return (1);
@ -148,8 +140,7 @@ SDL_Surface *tint_get_icon(magic_api * api, int which)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory,
tint_icon_filenames[which]);
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, tint_icon_filenames[which]);
return (IMG_Load(fname));
}
@ -160,15 +151,13 @@ char *tint_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
}
// Return our group (both the same):
int tint_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int tint_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_COLOR_FILTERS;
}
// Return our descriptions, localized:
char *tint_get_description(magic_api * api ATTRIBUTE_UNUSED, int which,
int mode)
char *tint_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode)
{
return (strdup(gettext_noop(tint_descs[which][mode - 1])));
}
@ -179,8 +168,7 @@ static int tint_grey(Uint8 r1, Uint8 g1, Uint8 b1)
return 0.3 * r1 + .59 * g1 + 0.11 * b1;
}
static void do_tint_pixel(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y)
static void do_tint_pixel(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
magic_api *api = (magic_api *) ptr;
@ -204,21 +192,18 @@ static void do_tint_pixel(void *ptr, int which, SDL_Surface * canvas,
if (greyValue < thresholdValue)
{
api->putpixel(canvas, x, y,
SDL_MapRGB(canvas->format, tint_r, tint_g, tint_b));
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, tint_r, tint_g, tint_b));
}
else
{
api->putpixel(canvas, x, y,
SDL_MapRGB(canvas->format, 255, 255, 255));
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, 255, 255, 255));
}
}
}
}
// Do the effect:
static void do_tint_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last,
int which)
static void do_tint_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int which)
{
int x, y;
@ -231,8 +216,7 @@ static void do_tint_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last,
}
}
static void do_tint_brush(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y)
static void do_tint_brush(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
int xx, yy;
magic_api *api = (magic_api *) ptr;
@ -241,8 +225,7 @@ static void do_tint_brush(void *ptr, int which, SDL_Surface * canvas,
{
for (xx = x - tint_RADIUS; xx < x + tint_RADIUS; xx++)
{
if (api->in_circle(xx - x, yy - y, tint_RADIUS)
&& !api->touched(xx, yy))
if (api->in_circle(xx - x, yy - y, tint_RADIUS) && !api->touched(xx, yy))
{
do_tint_pixel(api, which, canvas, last, xx, yy);
}
@ -252,12 +235,10 @@ static void do_tint_brush(void *ptr, int which, SDL_Surface * canvas,
// Affect the canvas on drag:
void tint_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1,
do_tint_brush);
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_tint_brush);
api->playsound(tint_snd_effect[which], (x * 255) / canvas->w, 255);
@ -284,8 +265,7 @@ void tint_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void tint_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
if (mode == MODE_PAINT)
tint_drag(api, which, canvas, last, x, y, x, y, update_rect);
@ -305,8 +285,7 @@ void tint_release(magic_api * api ATTRIBUTE_UNUSED,
int which 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 y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
@ -327,7 +306,8 @@ void tint_shutdown(magic_api * api ATTRIBUTE_UNUSED)
// Record the color from Tux Paint:
void tint_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
tint_r = r;
tint_g = g;
@ -335,14 +315,12 @@ void tint_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED
}
// Use colors:
int tint_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int tint_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 1;
}
void tint_switchin(magic_api * api, int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas)
void tint_switchin(magic_api * api, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas)
{
int x, y;
@ -370,8 +348,7 @@ void tint_switchin(magic_api * api, int which ATTRIBUTE_UNUSED,
}
void tint_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
@ -394,8 +371,9 @@ Uint8 tint_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UN
return 4;
}
void tint_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void tint_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
tint_RADIUS = size * 4;
}

View file

@ -83,30 +83,25 @@ SDL_Surface *toothpaste_get_icon(magic_api * api, int which);
char *toothpaste_get_name(magic_api * api, int which);
int toothpaste_get_group(magic_api * api, int which);
char *toothpaste_get_description(magic_api * api, int which, int mode);
static void do_toothpaste(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y);
static void do_toothpaste(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
void toothpaste_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void toothpaste_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void toothpaste_release(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void toothpaste_shutdown(magic_api * api);
void toothpaste_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
int toothpaste_requires_colors(magic_api * api, int which);
void toothpaste_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void toothpaste_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void toothpaste_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void toothpaste_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int toothpaste_modes(magic_api * api, int which);
int toothpaste_setup_weights(magic_api * api);
Uint8 toothpaste_accepted_sizes(magic_api * api, int which, int mode);
Uint8 toothpaste_default_size(magic_api * api, int which, int mode);
void toothpaste_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void toothpaste_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
Uint32 toothpaste_api_version(void)
@ -123,8 +118,7 @@ int toothpaste_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
//Load sounds
for (i = 0; i < toothpaste_NUM_TOOLS; i++)
{
snprintf(fname, sizeof(fname), "%ssounds/magic/%s", api->data_directory,
toothpaste_snd_filenames[i]);
snprintf(fname, sizeof(fname), "%ssounds/magic/%s", api->data_directory, toothpaste_snd_filenames[i]);
toothpaste_snd_effect[i] = Mix_LoadWAV(fname);
}
@ -137,13 +131,12 @@ int toothpaste_setup_weights(magic_api * api)
//Set up weights
pi = acos(0.0) * 2;
if (toothpaste_weights != NULL) {
if (toothpaste_weights != NULL)
{
free(toothpaste_weights);
}
toothpaste_weights =
(double *) malloc(toothpaste_RADIUS * 2 * toothpaste_RADIUS * 2 *
sizeof(double));
toothpaste_weights = (double *)malloc(toothpaste_RADIUS * 2 * toothpaste_RADIUS * 2 * sizeof(double));
if (toothpaste_weights == NULL)
{
return (0);
@ -159,7 +152,7 @@ int toothpaste_setup_weights(magic_api * api)
toothpaste_RADIUS) * ((toothpaste_RADIUS * 2) -
1) + (j +
toothpaste_RADIUS)] =
((fabs(atan2((double) (j), (double) (k)))) / pi);
((fabs(atan2((double)(j), (double)(k)))) / pi);
}
}
}
@ -177,8 +170,7 @@ SDL_Surface *toothpaste_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory,
toothpaste_icon_filenames[which]);
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, toothpaste_icon_filenames[which]);
return (IMG_Load(fname));
}
@ -195,16 +187,14 @@ int toothpaste_get_group(magic_api * api ATTRIBUTE_UNUSED, int which)
}
// Return our descriptions, localized:
char *toothpaste_get_description(magic_api * api ATTRIBUTE_UNUSED, int which,
int mode ATTRIBUTE_UNUSED)
char *toothpaste_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
{
return (strdup(gettext_noop(toothpaste_descs[which])));
}
// Do the effect:
static void do_toothpaste(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)
{
magic_api *api = (magic_api *) ptr;
int xx, yy;
@ -220,18 +210,14 @@ static void do_toothpaste(void *ptr, int which ATTRIBUTE_UNUSED,
{
for (xx = x - toothpaste_RADIUS; xx < x + toothpaste_RADIUS; xx++)
{
if (api->in_circle(xx - x, yy - y, toothpaste_RADIUS)
&& !api->touched(xx, yy))
if (api->in_circle(xx - x, yy - y, toothpaste_RADIUS) && !api->touched(xx, yy))
{
api->rgbtohsv(toothpaste_r, toothpaste_g, toothpaste_b, &h, &s, &v);
api->hsvtorgb(h, s,
toothpaste_weights[(yy - y +
toothpaste_RADIUS) *
((toothpaste_RADIUS * 2) - 1) + (xx -
x +
toothpaste_RADIUS)],
&r, &g, &b);
((toothpaste_RADIUS * 2) - 1) + (xx - x + toothpaste_RADIUS)], &r, &g, &b);
api->putpixel(canvas, xx, yy, SDL_MapRGB(canvas->format, r, g, b));
}
@ -242,12 +228,10 @@ static void do_toothpaste(void *ptr, int which ATTRIBUTE_UNUSED,
// Affect the canvas on drag:
void toothpaste_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1,
do_toothpaste);
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_toothpaste);
api->playsound(toothpaste_snd_effect[which], (x * 255) / canvas->w, 255);
@ -260,8 +244,7 @@ void toothpaste_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void toothpaste_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
toothpaste_drag(api, which, canvas, last, x, y, x, y, update_rect);
@ -272,8 +255,7 @@ void toothpaste_release(magic_api * api ATTRIBUTE_UNUSED,
int which 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)
{
}
@ -298,8 +280,9 @@ void toothpaste_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void toothpaste_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void toothpaste_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g,
Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
toothpaste_r = r;
toothpaste_g = g;
@ -307,29 +290,23 @@ void toothpaste_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_
}
// Use colors:
int toothpaste_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int toothpaste_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 1;
}
void toothpaste_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void toothpaste_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int toothpaste_modes(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int toothpaste_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (MODE_PAINT);
}
@ -345,7 +322,9 @@ Uint8 toothpaste_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIB
return 2;
}
void toothpaste_set_size(magic_api * api, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void toothpaste_set_size(magic_api * api, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
toothpaste_RADIUS = size * 5;
toothpaste_setup_weights(api);

View file

@ -63,18 +63,14 @@ typedef struct
float x, y;
} Point2D;
static void tornado_predrag(magic_api * api, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y);
static void tornado_predrag(magic_api * api, SDL_Surface * canvas, SDL_Surface * last, int ox, int oy, int x, int y);
static void tornado_drawbase(magic_api * api, SDL_Surface * canvas);
static void tornado_drawstalk(magic_api * api, SDL_Surface * canvas,
SDL_Surface * last, int top_x, int top_y,
int minx, int maxx, int bottom_x, int bottom_y,
int final);
static void tornado_drawtornado(magic_api * api, SDL_Surface * canvas, int x,
int y);
int minx, int maxx, int bottom_x, int bottom_y, int final);
static void tornado_drawtornado(magic_api * api, SDL_Surface * canvas, int x, int y);
static Point2D tornado_PointOnCubicBezier(Point2D * cp, float t);
static void tornado_ComputeBezier(Point2D * cp, int numberOfPoints,
Point2D * curve);
static void tornado_ComputeBezier(Point2D * cp, int numberOfPoints, Point2D * curve);
static void tornado_colorize_cloud(magic_api * api);
static Uint32 tornado_mess(Uint32 pixel, SDL_Surface * canvas);
Uint32 tornado_api_version(void);
@ -85,26 +81,23 @@ char *tornado_get_name(magic_api * api, int which);
int tornado_get_group(magic_api * api, int which);
char *tornado_get_description(magic_api * api, int which, int mode);
void tornado_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void tornado_click(magic_api * api, int which, int mode, SDL_Surface * canvas,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void tornado_release(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void tornado_shutdown(magic_api * api);
void tornado_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
int tornado_requires_colors(magic_api * api, int which);
void tornado_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void tornado_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void tornado_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void tornado_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int tornado_modes(magic_api * api, int which);
Uint8 tornado_accepted_sizes(magic_api * api, int which, int mode);
Uint8 tornado_default_size(magic_api * api, int which, int mode);
void tornado_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void tornado_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
@ -125,16 +118,13 @@ int tornado_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
tornado_click_snd = Mix_LoadWAV(fname);
*/
snprintf(fname, sizeof(fname), "%ssounds/magic/tornado_release.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/tornado_release.ogg", api->data_directory);
tornado_release_snd = Mix_LoadWAV(fname);
snprintf(fname, sizeof(fname), "%simages/magic/tornado_base.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/tornado_base.png", api->data_directory);
tornado_base = IMG_Load(fname);
snprintf(fname, sizeof(fname), "%simages/magic/tornado_cloud.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/tornado_cloud.png", api->data_directory);
tornado_cloud = IMG_Load(fname);
return (1);
@ -151,41 +141,33 @@ SDL_Surface *tornado_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/tornado.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/tornado.png", api->data_directory);
return (IMG_Load(fname));
}
// Return our names, localized:
char *tornado_get_name(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
char *tornado_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (strdup(gettext_noop("Tornado")));
}
// Return our groups:
int tornado_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int tornado_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_ARTISTIC;
}
// Return our descriptions, localized:
char *tornado_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED)
char *tornado_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return (strdup
(gettext_noop
("Click and drag to draw a tornado funnel on your picture.")));
return (strdup(gettext_noop("Click and drag to draw a tornado funnel on your picture.")));
}
// Affect the canvas on drag:
static void tornado_predrag(magic_api * api ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED,
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)
{
if (x < tornado_min_x)
tornado_min_x = x;
@ -219,8 +201,7 @@ static void tornado_predrag(magic_api * api ATTRIBUTE_UNUSED,
}
void tornado_drag(magic_api * api, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, int ox, int oy,
int x, int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
tornado_predrag(api, canvas, last, ox, oy, x, y);
@ -233,8 +214,7 @@ void tornado_drag(magic_api * api, int which ATTRIBUTE_UNUSED,
/* Draw the base and the stalk (low-quality) for now: */
tornado_drawstalk(api, canvas, last,
x, y, tornado_min_x, tornado_max_x, tornado_bottom_x,
tornado_bottom_y, !(api->button_down()));
x, y, tornado_min_x, tornado_max_x, tornado_bottom_x, tornado_bottom_y, !(api->button_down()));
tornado_drawbase(api, canvas);
@ -246,8 +226,7 @@ void tornado_drag(magic_api * api, int which ATTRIBUTE_UNUSED,
// Affect the canvas on click:
void tornado_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
tornado_min_x = x;
tornado_max_x = x;
@ -266,8 +245,7 @@ void tornado_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
// Affect the canvas on release:
void tornado_release(magic_api * api, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
/* Don't let tornado be too low compared to base: */
@ -287,8 +265,7 @@ void tornado_release(magic_api * api, int which ATTRIBUTE_UNUSED,
/* Draw high-quality stalk, and tornado: */
tornado_drawstalk(api, canvas, last, x, y, tornado_min_x, tornado_max_x,
tornado_bottom_x, tornado_bottom_y, 1);
tornado_drawstalk(api, canvas, last, x, y, tornado_min_x, tornado_max_x, tornado_bottom_x, tornado_bottom_y, 1);
tornado_drawtornado(api, canvas, x, y);
@ -304,8 +281,7 @@ void tornado_release(magic_api * api, int which ATTRIBUTE_UNUSED,
}
static void tornado_drawtornado(magic_api * api, SDL_Surface * canvas, int x,
int y)
static void tornado_drawtornado(magic_api * api, SDL_Surface * canvas, int x, int y)
{
SDL_Surface *aux_surf;
SDL_Rect dest;
@ -318,8 +294,7 @@ static void tornado_drawtornado(magic_api * api, SDL_Surface * canvas, int x,
SDL_FreeSurface(aux_surf);
}
static void tornado_drawbase(magic_api * api ATTRIBUTE_UNUSED,
SDL_Surface * canvas)
static void tornado_drawbase(magic_api * api ATTRIBUTE_UNUSED, SDL_Surface * canvas)
{
SDL_Rect dest;
@ -332,19 +307,17 @@ static void tornado_drawbase(magic_api * api ATTRIBUTE_UNUSED,
static Uint32 tornado_mess(Uint32 pixel, SDL_Surface * canvas)
{
Uint8 r, g, b, a;
float f = (float) rand() * 255 / RAND_MAX;
float f = (float)rand() * 255 / RAND_MAX;
SDL_GetRGBA(pixel, canvas->format, &r, &g, &b, &a);
return (SDL_MapRGBA(canvas->format,
(tornado_r + r + (Uint8) f * 2) / 4,
(tornado_g + g + (Uint8) f * 2) / 4,
(tornado_b + b + (Uint8) f * 2) / 4, a));
(tornado_g + g + (Uint8) f * 2) / 4, (tornado_b + b + (Uint8) f * 2) / 4, a));
}
static void tornado_drawstalk(magic_api * api, SDL_Surface * canvas,
SDL_Surface * last, int top_x, int top_y,
int minx, int maxx, int bottom_x, int bottom_y,
int final)
int minx, int maxx, int bottom_x, int bottom_y, int final)
{
Point2D control_points[4];
Point2D *curve;
@ -426,34 +399,23 @@ static void tornado_drawstalk(magic_api * api, SDL_Surface * canvas,
/* The body of the tornado: 3x 1y rotation + some random particles */
for (p = dest.x; p < dest.x + dest.w; p++)
{
if ((float) rand() * 100 / RAND_MAX > 10)
if ((float)rand() * 100 / RAND_MAX > 10)
{
api->putpixel(canvas, p, dest.y,
api->getpixel(last,
dest.x + (p - dest.x + rotation) % dest.w,
dest.y));
api->putpixel(canvas, p, dest.y, api->getpixel(last, dest.x + (p - dest.x + rotation) % dest.w, dest.y));
}
else
{
api->putpixel(canvas, p, dest.y,
tornado_mess(api->getpixel(last,
dest.x + (p - dest.x +
rotation) % dest.w,
dest.y), canvas));
tornado_mess(api->getpixel(last, dest.x + (p - dest.x + rotation) % dest.w, dest.y), canvas));
}
}
/* Some random particles flying around the tornado */
for (p = dest.x - dest.w * 20 / 100;
p < dest.x + dest.w + dest.w * 20 / 100; p++)
for (p = dest.x - dest.w * 20 / 100; p < dest.x + dest.w + dest.w * 20 / 100; p++)
{
if ((float) rand() * 100 / RAND_MAX < 5
&& ((p < dest.x) || (p > dest.w)))
if ((float)rand() * 100 / RAND_MAX < 5 && ((p < dest.x) || (p > dest.w)))
api->putpixel(canvas, p, dest.y,
tornado_mess(api->getpixel(last,
dest.x + (p - dest.x +
rotation) % dest.w,
dest.y), canvas));
tornado_mess(api->getpixel(last, dest.x + (p - dest.x + rotation) % dest.w, dest.y), canvas));
}
}
@ -480,7 +442,8 @@ void tornado_shutdown(magic_api * api ATTRIBUTE_UNUSED)
// Record the color from Tux Paint:
void tornado_set_color(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
tornado_r = r;
tornado_g = g;
@ -490,8 +453,7 @@ void tornado_set_color(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface
}
// Use colors:
int tornado_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int tornado_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 1;
}
@ -546,8 +508,7 @@ static Point2D tornado_PointOnCubicBezier(Point2D * cp, float t)
<sizeof(Point2D) numberOfPoints>
*/
static void tornado_ComputeBezier(Point2D * cp, int numberOfPoints,
Point2D * curve)
static void tornado_ComputeBezier(Point2D * cp, int numberOfPoints, Point2D * curve)
{
float dt;
int i;
@ -570,9 +531,7 @@ static void tornado_colorize_cloud(magic_api * api)
/* Create a surface to render into: */
amask =
~(tornado_cloud->format->Rmask | tornado_cloud->format->
Gmask | tornado_cloud->format->Bmask);
amask = ~(tornado_cloud->format->Rmask | tornado_cloud->format->Gmask | tornado_cloud->format->Bmask);
tornado_cloud_colorized =
SDL_CreateRGBSurface(SDL_SWSURFACE,
@ -580,8 +539,7 @@ static void tornado_colorize_cloud(magic_api * api)
tornado_cloud->h,
tornado_cloud->format->BitsPerPixel,
tornado_cloud->format->Rmask,
tornado_cloud->format->Gmask,
tornado_cloud->format->Bmask, amask);
tornado_cloud->format->Gmask, tornado_cloud->format->Bmask, amask);
/* Render the new cloud: */
@ -592,14 +550,11 @@ static void tornado_colorize_cloud(magic_api * api)
{
for (x = 0; x < tornado_cloud->w; x++)
{
SDL_GetRGBA(api->getpixel(tornado_cloud, x, y), tornado_cloud->format,
&r, &g, &b, &a);
SDL_GetRGBA(api->getpixel(tornado_cloud, x, y), tornado_cloud->format, &r, &g, &b, &a);
api->putpixel(tornado_cloud_colorized, x, y,
SDL_MapRGBA(tornado_cloud_colorized->format,
(tornado_r + r * 2) / 3,
(tornado_g + g * 2) / 3,
(tornado_b + b * 2) / 3, a));
(tornado_r + r * 2) / 3, (tornado_g + g * 2) / 3, (tornado_b + b * 2) / 3, a));
}
}
@ -608,20 +563,17 @@ static void tornado_colorize_cloud(magic_api * api)
}
void tornado_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void tornado_switchout(magic_api * api, int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
api->stopsound();
}
int tornado_modes(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int tornado_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (MODE_PAINT_WITH_PREVIEW);
}
@ -637,6 +589,8 @@ Uint8 tornado_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE
return 0;
}
void tornado_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void tornado_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}

View file

@ -36,7 +36,8 @@
static int tv_radius = 16;
enum {
enum
{
TV_TOOL_TV_CLASSIC,
TV_TOOL_TV_BRIGHT,
NUM_TV_TOOLS
@ -55,16 +56,12 @@ int tv_get_group(magic_api * api, int which);
char *tv_get_description(magic_api * api, int which, int mode);
int tv_requires_colors(magic_api * api, int which);
void tv_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
void tv_shutdown(magic_api * api);
void tv_paint_tv(void *ptr_to_api, int which_tool, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y);
void tv_do_tv(void *ptr_to_api, int which_tool, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y);
void tv_paint_tv(void *ptr_to_api, int which_tool, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
void tv_do_tv(void *ptr_to_api, int which_tool, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
void tv_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void tv_click(magic_api * api, int which, int mode, SDL_Surface * canvas,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void tv_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
@ -72,7 +69,8 @@ void tv_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int tv_modes(magic_api * api, int which);
Uint8 tv_accepted_sizes(magic_api * api, int which, int mode);
Uint8 tv_default_size(magic_api * api, int which, int mode);
void tv_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void tv_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
// Housekeeping functions
@ -83,7 +81,8 @@ Uint32 tv_api_version(void)
}
void tv_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
//get the colors from API and store it in structure
}
@ -92,8 +91,7 @@ int tv_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%ssounds/magic/tv.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/tv.ogg", api->data_directory);
tv_snd = Mix_LoadWAV(fname);
return (1);
@ -108,8 +106,7 @@ SDL_Surface *tv_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/tv.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/tv.png", api->data_directory);
return (IMG_Load(fname));
}
@ -127,21 +124,15 @@ int tv_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
return MAGIC_TYPE_DISTORTS;
}
char *tv_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode)
char *tv_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode)
{
if (mode == MODE_PAINT)
return
strdup(gettext_noop
("Click and drag to make parts of your picture look like they are on television."));
return strdup(gettext_noop("Click and drag to make parts of your picture look like they are on television."));
else
return
strdup(gettext_noop
("Click to make your picture look like it's on television."));
return strdup(gettext_noop("Click to make your picture look like it's on television."));
}
int tv_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int tv_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 0;
}
@ -149,8 +140,7 @@ int tv_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
void tv_release(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * snapshot 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)
{
}
@ -162,8 +152,7 @@ void tv_shutdown(magic_api * api ATTRIBUTE_UNUSED)
// Interactivity functions
void tv_do_tv(void *ptr_to_api, int which_tool,
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED,
int x, int y)
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
{
magic_api *api = (magic_api *) ptr_to_api;
int r, g, b, i;
@ -178,11 +167,14 @@ void tv_do_tv(void *ptr_to_api, int which_tool,
the original "TV" effect as a stylistic way to darken parts of their
picture, so we offer two tools (brighter, and classic).
-bjk 2023.04.22 */
if (which_tool == TV_TOOL_TV_BRIGHT) {
if (which_tool == TV_TOOL_TV_BRIGHT)
{
r = r8 * 2;
g = g8 * 2;
b = b8 * 2;
} else {
}
else
{
r = r8;
g = g8;
b = b8;
@ -220,8 +212,7 @@ void tv_do_tv(void *ptr_to_api, int which_tool,
}
void tv_paint_tv(void *ptr_to_api, int which_tool,
SDL_Surface * canvas,
SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
{
int i, j;
magic_api *api = (magic_api *) ptr_to_api;
@ -241,8 +232,7 @@ void tv_paint_tv(void *ptr_to_api, int which_tool,
}
void tv_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line(api, which, canvas, snapshot, ox, oy, x, y, 1, tv_paint_tv);
@ -254,8 +244,7 @@ void tv_drag(magic_api * api, int which, SDL_Surface * canvas,
}
void tv_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
if (mode == MODE_FULLSCREEN)
{
@ -279,15 +268,13 @@ void tv_click(magic_api * api, int which, int mode,
}
void tv_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void tv_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
@ -311,7 +298,9 @@ Uint8 tv_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUS
return 4;
}
void tv_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void tv_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
tv_radius = size * 4;
}

View file

@ -48,8 +48,7 @@ char *waves_get_name(magic_api * api, int which);
int waves_get_group(magic_api * api, int which);
char *waves_get_description(magic_api * api, int which, int mode);
void waves_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void waves_click(magic_api * api, int which, int mode, SDL_Surface * canvas,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void waves_release(magic_api * api, int which, SDL_Surface * canvas,
@ -58,14 +57,13 @@ void waves_shutdown(magic_api * api);
void waves_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
int waves_requires_colors(magic_api * api, int which);
void waves_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void waves_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void waves_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void waves_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int waves_modes(magic_api * api, int which);
Uint8 waves_accepted_sizes(magic_api * api, int which, int mode);
Uint8 waves_default_size(magic_api * api, int which, int mode);
void waves_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void waves_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
Uint32 waves_api_version(void)
{
@ -78,12 +76,10 @@ int waves_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%ssounds/magic/waves.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/waves.ogg", api->data_directory);
waves_snd[0] = Mix_LoadWAV(fname);
snprintf(fname, sizeof(fname), "%ssounds/magic/wavelet.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/wavelet.ogg", api->data_directory);
waves_snd[1] = Mix_LoadWAV(fname);
@ -102,18 +98,15 @@ SDL_Surface *waves_get_icon(magic_api * api, int which)
char fname[1024];
if (!which)
snprintf(fname, sizeof(fname), "%simages/magic/waves.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/waves.png", api->data_directory);
else
snprintf(fname, sizeof(fname), "%simages/magic/wavelet.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/wavelet.png", api->data_directory);
return (IMG_Load(fname));
}
// Return our group (both the same):
int waves_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int waves_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_PICTURE_WARPS;
}
@ -128,8 +121,7 @@ char *waves_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
}
// Return our descriptions, localized:
char *waves_get_description(magic_api * api ATTRIBUTE_UNUSED, int which,
int mode ATTRIBUTE_UNUSED)
char *waves_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
{
if (!which)
return (strdup
@ -143,8 +135,7 @@ char *waves_get_description(magic_api * api ATTRIBUTE_UNUSED, int which,
void waves_drag(magic_api * api ATTRIBUTE_UNUSED, int which,
SDL_Surface * canvas, SDL_Surface * last,
int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, int x,
int y, SDL_Rect * update_rect)
int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, int x, int y, SDL_Rect * update_rect)
{
int xx, yy;
SDL_Rect src, dest;
@ -202,8 +193,7 @@ void waves_drag(magic_api * api ATTRIBUTE_UNUSED, int which,
// Affect the canvas on click:
void waves_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
waves_drag(api, which, canvas, last, x, y, x, y, update_rect);
api->playsound(waves_snd[which], 128, 255);
@ -214,8 +204,7 @@ void waves_release(magic_api * api ATTRIBUTE_UNUSED,
int which 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)
{
}
@ -229,27 +218,26 @@ void waves_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void waves_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void waves_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
// Use colors:
int waves_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int waves_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 0;
}
void waves_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void waves_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
@ -269,6 +257,8 @@ Uint8 waves_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_U
return 0;
}
void waves_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void waves_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}

View file

@ -44,28 +44,25 @@ int xor_get_group(magic_api * api, int which);
char *xor_get_description(magic_api * api, int which, int mode);
void xor_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void xor_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void xor_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void xor_shutdown(magic_api * api);
void xor_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
int xor_requires_colors(magic_api * api, int which);
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);
Uint8 xor_accepted_sizes(magic_api * api, int which, int mode);
Uint8 xor_default_size(magic_api * api, int which, int mode);
void xor_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
void xor_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect);
Uint32 xor_api_version(void)
@ -77,8 +74,7 @@ int xor_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%ssounds/magic/xor.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/xor.ogg", api->data_directory);
xor_snd = Mix_LoadWAV(fname);
return (1);
@ -93,38 +89,31 @@ SDL_Surface *xor_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/xor.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/xor.png", api->data_directory);
return (IMG_Load(fname));
}
char *xor_get_name(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
char *xor_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (strdup(gettext_noop("Xor Colors")));
}
int xor_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int xor_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_COLOR_FILTERS;
}
char *xor_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode)
char *xor_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode)
{
if (mode == MODE_PAINT)
return (strdup(gettext_noop("Click and drag to draw a XOR effect")));
else
return (strdup
(gettext_noop
("Click to draw a XOR effect on the whole picture")));
return (strdup(gettext_noop("Click to draw a XOR effect on the whole picture")));
}
static void do_xor(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)
{
magic_api *api = (magic_api *) ptr;
Uint8 r, g, b, xor;
@ -134,17 +123,16 @@ static void do_xor(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_GetRGB(api->getpixel(canvas, x, y), canvas->format, &r, &g, &b);
api->rgbtohsv(r, g, b, &hue, &sat, &val);
if (sat == 0)
xor = (2 * (int) hue + (x ^ y)) % 360;
xor = (2 * (int)hue + (x ^ y)) % 360;
else
xor = ((int) hue + (x ^ y)) % 360;
xor = ((int)hue + (x ^ y)) % 360;
api->hsvtorgb(xor, 1, 1, &r, &g, &b);
pixel = SDL_MapRGB(canvas->format, r, g, b);
api->putpixel(canvas, x, y, pixel);
}
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)
{
magic_api *api = (magic_api *) ptr;
int xx, yy;
@ -163,11 +151,9 @@ static void do_xor_circle(void *ptr, int which ATTRIBUTE_UNUSED,
}
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_Rect * update_rect)
SDL_Surface * last ATTRIBUTE_UNUSED, int ox, int oy, int x, int y, 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)
{
@ -193,8 +179,7 @@ void xor_drag(magic_api * api, int which, SDL_Surface * canvas,
}
void xor_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
int x, int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y, SDL_Rect * update_rect)
{
if (mode == MODE_PAINT)
xor_drag(api, which, canvas, last, x, y, x, y, update_rect);
@ -217,8 +202,7 @@ void xor_click(magic_api * api, int which, int mode,
void xor_release(magic_api * api ATTRIBUTE_UNUSED, int which 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 y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
@ -229,25 +213,23 @@ void xor_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
void xor_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
int xor_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int xor_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 0;
}
void xor_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas 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)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
@ -270,7 +252,9 @@ Uint8 xor_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNU
return 4;
}
void xor_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void xor_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
xor_radius = size * 4;
}

View file

@ -32,15 +32,15 @@ char *get_nativelibdir()
return nativelibdir;
}
void load_assets_dir(char *dirname, tp_ftw_str ** ffilenames,
unsigned *num_file_names)
void load_assets_dir(char *dirname, tp_ftw_str ** ffilenames, unsigned *num_file_names)
{
AAssetDir *assetDir = AAssetManager_openDir(asset_manager, dirname);
const char *filename = (const char *) NULL;
const char *filename = (const char *)NULL;
tp_ftw_str *filenames = NULL;
unsigned max_file_names = 0;
int fulllen = 0;
*num_file_names = 0;
@ -67,12 +67,7 @@ void load_assets_dir(char *dirname, tp_ftw_str ** ffilenames,
*ffilenames = filenames;
}
JNIEXPORT jboolean Java_org_tuxpaint_tuxpaintActivity_managertojni(JNIEnv *
env,
jclass
clazz,
jobject
mgr)
JNIEXPORT jboolean Java_org_tuxpaint_tuxpaintActivity_managertojni(JNIEnv * env, jclass clazz, jobject mgr)
{
asset_manager = AAssetManager_fromJava(env, mgr);
@ -82,14 +77,10 @@ JNIEXPORT jboolean Java_org_tuxpaint_tuxpaintActivity_managertojni(JNIEnv *
return 1;
}
JNIEXPORT void Java_org_tuxpaint_tuxpaintActivity_setnativelibdir(JNIEnv *
env,
jclass
clazz,
jstring
path)
JNIEXPORT void Java_org_tuxpaint_tuxpaintActivity_setnativelibdir(JNIEnv * env, jclass clazz, jstring path)
{
const char *cpath = (*env)->GetStringUTFChars(env, path, NULL);
nativelibdir = strdup(cpath);
(*env)->ReleaseStringUTFChars(env, path, cpath);
}
@ -102,8 +93,7 @@ void load_brushes_from_assets(SDL_Surface * screen, SDL_Texture * texture,
SDL_Renderer * renderer,
const char *restrict const dir,
unsigned dirlen, tp_ftw_str * files,
unsigned count,
const char *restrict const locale))
unsigned count, const char *restrict const locale))
{
unsigned num_file_names = 0;
char *dir = "data/brushes";
@ -127,10 +117,10 @@ void load_from_assets(SDL_Surface * screen, SDL_Texture * texture,
SDL_Renderer * renderer,
const char *restrict const dir,
unsigned dirlen, tp_ftw_str * files,
unsigned count,
const char *restrict const locale))
unsigned count, const char *restrict const locale))
{
unsigned num_file_names = 0;
// char * dir = "data/stamps/cartoon/tux";
char buf[TP_FTW_PATHSIZE];
unsigned dirlen = strlen(dirname);
@ -140,6 +130,5 @@ void load_from_assets(SDL_Surface * screen, SDL_Texture * texture,
tp_ftw_str *filenames = NULL;
load_assets_dir(dirname, &filenames, &num_file_names);
fn(screen, texture, renderer, dirname, dirlen, filenames, num_file_names,
NULL);
fn(screen, texture, renderer, dirname, dirlen, filenames, num_file_names, NULL);
}

View file

@ -38,8 +38,7 @@ void load_brushes_from_assets(SDL_Surface * screen, SDL_Texture * texture,
SDL_Renderer * renderer,
const char *restrict const dir,
unsigned dirlen, tp_ftw_str * files,
unsigned count,
const char *restrict const locale));
unsigned count, const char *restrict const locale));
void load_from_assets(SDL_Surface * screen, SDL_Texture * texture,
SDL_Renderer * renderer, const char *dirname,
@ -47,24 +46,12 @@ void load_from_assets(SDL_Surface * screen, SDL_Texture * texture,
SDL_Renderer * renderer,
const char *restrict const dir,
unsigned dirlen, tp_ftw_str * files,
unsigned count,
const char *restrict const locale));
unsigned count, const char *restrict const locale));
void load_assets_dir(char *dirname, tp_ftw_str ** ffilenames,
unsigned *num_file_names);
void load_assets_dir(char *dirname, tp_ftw_str ** ffilenames, unsigned *num_file_names);
JNIEXPORT jboolean Java_org_tuxpaint_tuxpaintActivity_managertojni(JNIEnv *
env,
jclass
clazz,
jobject
mgr);
JNIEXPORT jboolean Java_org_tuxpaint_tuxpaintActivity_managertojni(JNIEnv * env, jclass clazz, jobject mgr);
JNIEXPORT void Java_org_tuxpaint_tuxpaintActivity_setnativelibdir(JNIEnv *
env,
jclass
clazz,
jstring
path);
JNIEXPORT void Java_org_tuxpaint_tuxpaintActivity_setnativelibdir(JNIEnv * env, jclass clazz, jstring path);
#endif

View file

@ -33,6 +33,7 @@
size_t mbstowcs(wchar_t *__restrict pwcs, const char *__restrict s, size_t n)
{
int length = strnlen(s, n);
// w is the index of pwcs, s is the index of s
int w = 0, c = 0;
@ -41,9 +42,10 @@ size_t mbstowcs(wchar_t *__restrict pwcs, const char *__restrict s, size_t n)
pwcs[w] = '\0';
char first = s[c];
int len = 0;
if ((first & 0x80) == 0)
{
pwcs[w] = (wchar_t) s[c];
pwcs[w] = (wchar_t)s[c];
len = 1;
}
else if ((first & 0xe0) == 0xc0)

View file

@ -34,17 +34,14 @@
int IsPrinterAvailable(void)
{
JNIEnv *mEnv = Android_JNI_GetEnv();
jclass mPrintHelperClass =
(*mEnv)->FindClass(mEnv, "androidx/print/PrintHelper");
jclass mPrintHelperClass = (*mEnv)->FindClass(mEnv, "androidx/print/PrintHelper");
if (mPrintHelperClass == NULL)
return 0;
jmethodID mSupportMethod =
(*mEnv)->GetStaticMethodID(mEnv, mPrintHelperClass, "systemSupportsPrint",
"()Z");
jboolean support =
(*mEnv)->CallStaticBooleanMethod(mEnv, mPrintHelperClass, mSupportMethod);
jmethodID mSupportMethod = (*mEnv)->GetStaticMethodID(mEnv, mPrintHelperClass, "systemSupportsPrint",
"()Z");
jboolean support = (*mEnv)->CallStaticBooleanMethod(mEnv, mPrintHelperClass, mSupportMethod);
return support ? 1 : 0;
}
@ -56,49 +53,41 @@ const char *SurfacePrint(SDL_Surface * surface)
{
JNIEnv *mEnv = Android_JNI_GetEnv();
jclass mBitmapClass = (*mEnv)->FindClass(mEnv, "android/graphics/Bitmap");
jmethodID mCreateMethod =
(*mEnv)->GetStaticMethodID(mEnv, mBitmapClass, "createBitmap",
"([IIILandroid/graphics/Bitmap$Config;)Landroid/graphics/Bitmap;");
jintArray mSurfaceArray =
(*mEnv)->NewIntArray(mEnv, surface->w * surface->h);
(*mEnv)->SetIntArrayRegion(mEnv, mSurfaceArray, 0, surface->w * surface->h,
surface->pixels);
jclass mConfigClass =
(*mEnv)->FindClass(mEnv, "android/graphics/Bitmap$Config");
jfieldID mConfigField =
(*mEnv)->GetStaticFieldID(mEnv, mConfigClass, "ARGB_8888",
"Landroid/graphics/Bitmap$Config;");
jobject mConfig =
(*mEnv)->GetStaticObjectField(mEnv, mConfigClass, mConfigField);
jobject mBitMap =
(*mEnv)->CallStaticObjectMethod(mEnv, mBitmapClass, mCreateMethod,
mSurfaceArray, surface->w, surface->h,
mConfig);
jmethodID mCreateMethod = (*mEnv)->GetStaticMethodID(mEnv, mBitmapClass, "createBitmap",
"([IIILandroid/graphics/Bitmap$Config;)Landroid/graphics/Bitmap;");
jintArray mSurfaceArray = (*mEnv)->NewIntArray(mEnv, surface->w * surface->h);
(*mEnv)->SetIntArrayRegion(mEnv, mSurfaceArray, 0, surface->w * surface->h, surface->pixels);
jclass mConfigClass = (*mEnv)->FindClass(mEnv, "android/graphics/Bitmap$Config");
jfieldID mConfigField = (*mEnv)->GetStaticFieldID(mEnv, mConfigClass, "ARGB_8888",
"Landroid/graphics/Bitmap$Config;");
jobject mConfig = (*mEnv)->GetStaticObjectField(mEnv, mConfigClass, mConfigField);
jobject mBitMap = (*mEnv)->CallStaticObjectMethod(mEnv, mBitmapClass, mCreateMethod,
mSurfaceArray, surface->w, surface->h,
mConfig);
jobject mContext = (jobject) SDL_AndroidGetActivity();
jclass mPrintClass = (*mEnv)->FindClass(mEnv, "androidx/print/PrintHelper");
// sometimes android v4 support library may be not ready
if (mPrintClass == NULL)
return "There is no androidX support library.";
jmethodID mInitMethod = (*mEnv)->GetMethodID(mEnv, mPrintClass, "<init>",
"(Landroid/content/Context;)V");
jobject mPrint =
(*mEnv)->NewObject(mEnv, mPrintClass, mInitMethod, mContext);
jmethodID mPrintMethod =
(*mEnv)->GetMethodID(mEnv, mPrintClass, "printBitmap",
"(Ljava/lang/String;Landroid/graphics/Bitmap;)V");
jobject mPrint = (*mEnv)->NewObject(mEnv, mPrintClass, mInitMethod, mContext);
jmethodID mPrintMethod = (*mEnv)->GetMethodID(mEnv, mPrintClass, "printBitmap",
"(Ljava/lang/String;Landroid/graphics/Bitmap;)V");
/* Thanks to n.collins for the explaination on the int signature
on https://stackoverflow.com/questions/13468041/android-how-to-call-java-method-from-jni-with-int-and-int-parameters --Pere */
jmethodID msetScaleMode =
(*mEnv)->GetMethodID(mEnv, mPrintClass, "setScaleMode", "(I)V");
jfieldID mScaleModeField =
(*mEnv)->GetStaticFieldID(mEnv, mPrintClass, "SCALE_MODE_FIT", "I");
jint mScaleModeInt =
(*mEnv)->GetStaticIntField(mEnv, mPrintClass, mScaleModeField);
jmethodID msetScaleMode = (*mEnv)->GetMethodID(mEnv, mPrintClass, "setScaleMode", "(I)V");
jfieldID mScaleModeField = (*mEnv)->GetStaticFieldID(mEnv, mPrintClass, "SCALE_MODE_FIT", "I");
jint mScaleModeInt = (*mEnv)->GetStaticIntField(mEnv, mPrintClass, mScaleModeField);
(*mEnv)->CallVoidMethod(mEnv, mPrint, msetScaleMode, mScaleModeInt);
jstring mString = (*mEnv)->NewStringUTF(mEnv, "TuxPaint");
(*mEnv)->CallVoidMethod(mEnv, mPrint, mPrintMethod, mString, mBitMap);
// clean up

View file

@ -34,8 +34,7 @@
SDL_Cursor *cursor_hand, *cursor_arrow, *cursor_watch,
*cursor_up, *cursor_down, *cursor_tiny, *cursor_crosshair,
*cursor_brush, *cursor_wand, *cursor_insertion, *cursor_rotate,
*cursor_pipette;
*cursor_brush, *cursor_wand, *cursor_insertion, *cursor_rotate, *cursor_pipette;
#ifdef NOKIA_770
int hide_cursor = 1;

View file

@ -70,8 +70,7 @@
extern SDL_Cursor *cursor_hand, *cursor_arrow, *cursor_watch,
*cursor_up, *cursor_down, *cursor_tiny, *cursor_crosshair,
*cursor_brush, *cursor_wand, *cursor_insertion, *cursor_rotate,
*cursor_pipette;
*cursor_brush, *cursor_wand, *cursor_insertion, *cursor_rotate, *cursor_pipette;
extern int no_fancy_cursors, hide_cursor;

View file

@ -82,8 +82,7 @@ extern char *strcasestr(const char *haystack, const char *needle);
void loadfont_callback(SDL_Surface * screen, SDL_Texture * texture,
SDL_Renderer * renderer,
const char *restrict const dir, unsigned dirlen,
tp_ftw_str * files, unsigned i,
const char *restrict const locale)
tp_ftw_str * files, unsigned i, const char *restrict const locale)
{
dirlen = dirlen;
@ -153,10 +152,8 @@ void loadfont_callback(SDL_Surface * screen, SDL_Texture * texture,
}
if (font)
{
const char *restrict const family =
TuxPaint_Font_FontFaceFamilyName(font);
const char *restrict const style =
TuxPaint_Font_FontFaceStyleName(font);
const char *restrict const family = TuxPaint_Font_FontFaceFamilyName(font);
const char *restrict const style = TuxPaint_Font_FontFaceStyleName(font);
#ifdef DEBUG
@ -165,22 +162,19 @@ void loadfont_callback(SDL_Surface * screen, SDL_Texture * texture,
int numfaces = TTF_FontFaces(font->ttf_font);
if (numfaces != 1)
printf("%s:%d - Found %d faces in %s, %s, %s\n", __FILE__,
__LINE__, numfaces, files[i].str, family, style);
printf("%s:%d - Found %d faces in %s, %s, %s\n", __FILE__, __LINE__, numfaces, files[i].str, family, style);
printf("%s:%d - success: tpf: 0x%x tpf->ttf_font: 0x%x\n", __FILE__, __LINE__, (unsigned int) (intptr_t) font, (unsigned int) (intptr_t) font->ttf_font); //EP added (intptr_t) to avoid warning on x64
printf("%s:%d - success: tpf: 0x%x tpf->ttf_font: 0x%x\n", __FILE__, __LINE__, (unsigned int)(intptr_t) font, (unsigned int)(intptr_t) font->ttf_font); //EP added (intptr_t) to avoid warning on x64
}
#ifndef NO_SDLPANGO
else
printf("%s:%d - success: tpf: 0x%x tpf->pango_context: 0x%x\n",
__FILE__, __LINE__, (unsigned int) (intptr_t) font,
(unsigned int) (intptr_t) font->pango_context);
__FILE__, __LINE__, (unsigned int)(intptr_t) font, (unsigned int)(intptr_t) font->pango_context);
#endif
#endif
// These fonts crash Tux Paint via a library bug.
int blacklisted = !strcmp("Zapfino", family)
|| !strcmp("Elvish Ring NFI", family);
int blacklisted = !strcmp("Zapfino", family) || !strcmp("Elvish Ring NFI", family);
// First, the blacklist. We list font families that can crash Tux Paint
// via bugs in the SDL_ttf library. We also test fonts to be sure that
@ -201,8 +195,7 @@ void loadfont_callback(SDL_Surface * screen, SDL_Texture * texture,
// impossible for a user to type ASCII letters.
//
// Most translators should use scoring instead.
if (!charset_works(font, gettext("qx"))
|| !charset_works(font, gettext("QX")))
if (!charset_works(font, gettext("qx")) || !charset_works(font, gettext("QX")))
blacklisted = 1;
if (!blacklisted)
@ -210,12 +203,9 @@ void loadfont_callback(SDL_Surface * screen, SDL_Texture * texture,
if (num_font_styles == num_font_styles_max)
{
num_font_styles_max = num_font_styles_max * 5 / 4 + 30;
user_font_styles =
realloc(user_font_styles,
num_font_styles_max * sizeof *user_font_styles);
user_font_styles = realloc(user_font_styles, num_font_styles_max * sizeof *user_font_styles);
}
user_font_styles[num_font_styles] =
malloc(sizeof *user_font_styles[num_font_styles]);
user_font_styles[num_font_styles] = malloc(sizeof *user_font_styles[num_font_styles]);
user_font_styles[num_font_styles]->directory = strdup(dir);
user_font_styles[num_font_styles]->filename = files[i].str; // steal it (mark NULL below)
user_font_styles[num_font_styles]->family = strdup(family);
@ -230,52 +220,46 @@ void loadfont_callback(SDL_Surface * screen, SDL_Texture * texture,
// Translators should do whatever is needed to put crummy fonts last.
user_font_styles[num_font_styles]->score +=
charset_works(
font, /* distinct uppercase and lowercase (e.g., 'o' vs. 'O') */ gettext("oO")
charset_works(font, /* distinct uppercase and lowercase (e.g., 'o' vs. 'O') */ gettext("oO")
);
// common punctuation (e.g., '?', '!', '.', ',', etc.)
user_font_styles[num_font_styles]->score +=
charset_works(
font, /* common punctuation (e.g., '?', '!', '.', ',', etc.) */ gettext(",.?!")
charset_works(font, /* common punctuation (e.g., '?', '!', '.', ',', etc.) */ gettext(",.?!")
);
user_font_styles[num_font_styles]->score +=
charset_works(
font, /* uncommon punctuation (e.g., '@', '#', '*', etc.) */ gettext("`\%_@$~#{<(^&*")
charset_works(font, /* uncommon punctuation (e.g., '@', '#', '*', etc.) */ gettext("`\%_@$~#{<(^&*")
);
user_font_styles[num_font_styles]->score +=
charset_works(
font, /* digits (e.g., '0', '1' and '7') */ gettext("017")
charset_works(font, /* digits (e.g., '0', '1' and '7') */ gettext("017")
);
user_font_styles[num_font_styles]->score +=
charset_works(
font, /* distinct circle-like characters (e.g., 'O' (capital oh) vs. '0' (zero)) */ gettext("O0")
charset_works(font, /* distinct circle-like characters (e.g., 'O' (capital oh) vs. '0' (zero)) */
gettext("O0")
);
user_font_styles[num_font_styles]->score +=
charset_works(
font, /* distinct line-like characters (e.g., 'l' (lowercase elle) vs. '1' (one) vs. 'I' (capital aye)) */ gettext("1Il|")
);
charset_works(font,
/* distinct line-like characters (e.g., 'l' (lowercase elle) vs. '1' (one) vs. 'I' (capital aye)) */
gettext("1Il|")
);
// Translation spares
user_font_styles[num_font_styles]->score +=
// If neccessary, translate any of following strings using at least
// two locale specific characters required to render your language.
// Then, the scores for those fonts having such characters will increase.
//
// You can use two different weight for scoring, 1 or 9, according
// to the importance.
// If neccessary, translate any of following strings using at least
// two locale specific characters required to render your language.
// Then, the scores for those fonts having such characters will increase.
//
// You can use two different weight for scoring, 1 or 9, according
// to the importance.
charset_works(font, gettext("<1>spare-1a"));
user_font_styles[num_font_styles]->score +=
charset_works(font, gettext("<1>spare-1b"));
user_font_styles[num_font_styles]->score +=
charset_works(font, gettext("<9>spare-9a")) * 9;
user_font_styles[num_font_styles]->score +=
charset_works(font, gettext("<9>spare-9b")) * 9;
user_font_styles[num_font_styles]->score += charset_works(font, gettext("<1>spare-1b"));
user_font_styles[num_font_styles]->score += charset_works(font, gettext("<9>spare-9a")) * 9;
user_font_styles[num_font_styles]->score += charset_works(font, gettext("<9>spare-9b")) * 9;
// this really should be dynamic, avoiding the need for a special build
#ifdef OLPC_XO
@ -292,8 +276,7 @@ void loadfont_callback(SDL_Surface * screen, SDL_Texture * texture,
else
{
#ifdef DEBUG
fprintf(stderr, "Font is too defective: %s, %s, %s\n", files[i].str,
family, style);
fprintf(stderr, "Font is too defective: %s, %s, %s\n", files[i].str, family, style);
#endif
}
TuxPaint_Font_CloseFont(font);
@ -349,9 +332,7 @@ void tp_ftw(SDL_Surface * screen, SDL_Texture * texture,
dir, unsigned dirlen,
tp_ftw_str * files,
unsigned count,
const char *restrict const
locale),
const char *restrict const locale)
const char *restrict const locale), const char *restrict const locale)
{
DIR *d;
unsigned num_file_names = 0;
@ -362,6 +343,7 @@ void tp_ftw(SDL_Surface * screen, SDL_Texture * texture,
tp_ftw_str *dir_names = NULL;
int d_namlen;
int add_rsrc;
#ifdef __ANDROID__
unsigned dlen;
#endif
@ -532,12 +514,10 @@ void tp_ftw(SDL_Surface * screen, SDL_Texture * texture,
#else
#ifdef __ANDROID__
if (dlen != dirlen) /* First case only happens in Android files coming from assets */
fn(screen, texture, renderer, di, dlen, file_names, num_file_names,
locale);
fn(screen, texture, renderer, di, dlen, file_names, num_file_names, locale);
else
#endif
fn(screen, texture, renderer, dir, dirlen, file_names, num_file_names,
locale);
fn(screen, texture, renderer, dir, dirlen, file_names, num_file_names, locale);
#endif
}
@ -546,10 +526,8 @@ void tp_ftw(SDL_Surface * screen, SDL_Texture * texture,
qsort(dir_names, num_dir_names, sizeof *dir_names, compare_ftw_str);
while (num_dir_names--)
{
memcpy(dir + dirlen, dir_names[num_dir_names].str,
dir_names[num_dir_names].len + 1);
tp_ftw(screen, texture, renderer, dir,
dirlen + dir_names[num_dir_names].len, rsrc, fn, locale);
memcpy(dir + dirlen, dir_names[num_dir_names].str, dir_names[num_dir_names].len + 1);
tp_ftw(screen, texture, renderer, dir, dirlen + dir_names[num_dir_names].len, rsrc, fn, locale);
free(dir_names[num_dir_names].str);
}
free(dir_names);

View file

@ -49,8 +49,7 @@ typedef struct tp_ftw_str
void loadfont_callback(SDL_Surface * screen, SDL_Texture * texture,
SDL_Renderer * renderer,
const char *restrict const dir, unsigned dirlen,
tp_ftw_str * files, unsigned i,
const char *restrict const locale);
tp_ftw_str * files, unsigned i, const char *restrict const locale);
int compare_ftw_str(const void *v1, const void *v2);
void tp_ftw(SDL_Surface * screen, SDL_Texture * texture,
SDL_Renderer * renderer, char *restrict const dir,
@ -62,7 +61,6 @@ void tp_ftw(SDL_Surface * screen, SDL_Texture * texture,
tp_ftw_str * files,
unsigned count,
const char *restrict const
locale),
const char *restrict const locale);
locale), const char *restrict const locale);
#endif

View file

@ -82,7 +82,7 @@ sdf_point sdf_pt_empty = { 9999, 9999 };
typedef struct sdf_grid_s
{
sdf_point * * grid;
sdf_point **grid;
int w, h;
} sdf_grid;
@ -96,14 +96,10 @@ int global_extent_x1, global_extent_y1, global_extent_x2, global_extent_y2;
int global_prog_anim;
double colors_close(SDL_Surface * canvas, Uint32 c1, Uint32 c2);
Uint32 blend(SDL_Surface * canvas, Uint32 draw_colr, Uint32 old_colr,
double pct);
Uint32 blend(SDL_Surface * canvas, Uint32 draw_colr, Uint32 old_colr, double pct);
void simulate_flood_fill_outside_check(SDL_Surface * screen,
SDL_Texture * texture,
SDL_Renderer * renderer, int x, int y,
int y_outside);
void draw_brush_fill_single(SDL_Surface * canvas, int x, int y,
Uint32 draw_color, Uint8 * touched);
SDL_Texture * texture, SDL_Renderer * renderer, int x, int y, int y_outside);
void draw_brush_fill_single(SDL_Surface * canvas, int x, int y, Uint32 draw_color, Uint8 * touched);
void init_queue(void);
void add_to_queue(int x, int y, int y_outside);
@ -140,9 +136,8 @@ void add_to_queue(int x, int y, int y_outside)
if (queue_end + 1 > queue_size)
{
queue_t *tmp;
tmp =
(queue_t *) realloc(queue,
sizeof(queue_t) * (queue_size + QUEUE_SIZE_CHUNK));
tmp = (queue_t *) realloc(queue, sizeof(queue_t) * (queue_size + QUEUE_SIZE_CHUNK));
if (tmp == NULL)
{
fprintf(stderr, "Fill queue cannot be realloc()'d\n");
@ -256,25 +251,22 @@ int would_flood_fill(SDL_Surface * canvas, Uint32 cur_colr, Uint32 old_colr)
void do_flood_fill(SDL_Surface * screen, SDL_Texture * texture,
SDL_Renderer * renderer, SDL_Surface * last,
SDL_Surface * canvas, int x, int y, Uint32 cur_colr,
Uint32 old_colr, int *x1, int *y1, int *x2, int *y2,
Uint8 * touched)
Uint32 old_colr, int *x1, int *y1, int *x2, int *y2, Uint8 * touched)
{
simulate_flood_fill(screen, texture, renderer, last, canvas, x, y, cur_colr,
old_colr, x1, y1, x2, y2, touched);
simulate_flood_fill(screen, texture, renderer, last, canvas, x, y, cur_colr, old_colr, x1, y1, x2, y2, touched);
}
Uint32 blend(SDL_Surface * canvas, Uint32 draw_colr, Uint32 old_colr,
double pct)
Uint32 blend(SDL_Surface * canvas, Uint32 draw_colr, Uint32 old_colr, double pct)
{
Uint8 old_r, old_g, old_b, draw_r, draw_g, draw_b, new_r, new_g, new_b;
SDL_GetRGB(draw_colr, canvas->format, &draw_r, &draw_g, &draw_b);
SDL_GetRGB(old_colr, canvas->format, &old_r, &old_g, &old_b);
new_r = (Uint8) (((float) old_r) * (1.00 - pct) + ((float) draw_r * pct));
new_g = (Uint8) (((float) old_g) * (1.00 - pct) + ((float) draw_g * pct));
new_b = (Uint8) (((float) old_b) * (1.00 - pct) + ((float) draw_b * pct));
new_r = (Uint8) (((float)old_r) * (1.00 - pct) + ((float)draw_r * pct));
new_g = (Uint8) (((float)old_g) * (1.00 - pct) + ((float)draw_g * pct));
new_b = (Uint8) (((float)old_b) * (1.00 - pct) + ((float)draw_b * pct));
return SDL_MapRGB(canvas->format, draw_r, draw_g, draw_b);
return SDL_MapRGB(canvas->format, new_r, new_g, new_b);
@ -308,8 +300,7 @@ void simulate_flood_fill(SDL_Surface * screen, SDL_Texture * texture,
/* Do the work (possibly queuing more, as we go) */
while (remove_from_queue(&x, &y, &y_outside))
{
simulate_flood_fill_outside_check(screen, texture, renderer, x, y,
y_outside);
simulate_flood_fill_outside_check(screen, texture, renderer, x, y, y_outside);
}
cleanup_queue();
@ -320,9 +311,7 @@ void simulate_flood_fill(SDL_Surface * screen, SDL_Texture * texture,
}
void simulate_flood_fill_outside_check(SDL_Surface * screen,
SDL_Texture * texture,
SDL_Renderer * renderer, int x, int y,
int y_outside)
SDL_Texture * texture, SDL_Renderer * renderer, int x, int y, int y_outside)
{
int fillL, fillR, narrowFillL, narrowFillR, i, outside, just_queued;
double in_line, closeness;
@ -374,9 +363,7 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen,
/* Find left side, filling along the way */
px_colr =
getpixels[global_last->format->BytesPerPixel] (global_last,
fillL /* - 1 */ , y);
px_colr = getpixels[global_last->format->BytesPerPixel] (global_last, fillL /* - 1 */ , y);
in_line = colors_close(global_canvas, px_colr, global_old_colr);
outside = 0;
while (in_line < COLOR_MATCH_WIDE && outside < WIDE_MATCH_THRESHOLD)
@ -399,17 +386,12 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen,
global_touched[(y * global_canvas->w) + fillL] = touch_byt;
}
px_colr =
getpixels[global_last->format->BytesPerPixel] (global_last, fillL, y);
px_colr = getpixels[global_last->format->BytesPerPixel] (global_last, fillL, y);
putpixels[global_canvas->format->BytesPerPixel] (global_canvas, fillL, y,
blend(global_canvas,
global_cur_colr,
px_colr,
(1.0 - in_line)));
blend(global_canvas, global_cur_colr, px_colr, (1.0 - in_line)));
fillL--;
px_colr =
getpixels[global_last->format->BytesPerPixel] (global_last, fillL, y);
px_colr = getpixels[global_last->format->BytesPerPixel] (global_last, fillL, y);
if (fillL >= 0)
{
@ -432,13 +414,9 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen,
global_touched[(y * global_canvas->w) + fillL] = touch_byt;
}
px_colr =
getpixels[global_last->format->BytesPerPixel] (global_last, fillL, y);
px_colr = getpixels[global_last->format->BytesPerPixel] (global_last, fillL, y);
putpixels[global_canvas->format->BytesPerPixel] (global_canvas, fillL, y,
blend(global_canvas,
global_cur_colr,
px_colr,
(1.0 - in_line)));
blend(global_canvas, global_cur_colr, px_colr, (1.0 - in_line)));
}
@ -452,8 +430,7 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen,
/* Find right side, filling along the way */
px_colr =
getpixels[global_last->format->BytesPerPixel] (global_last, fillR + 1, y);
px_colr = getpixels[global_last->format->BytesPerPixel] (global_last, fillR + 1, y);
in_line = colors_close(global_canvas, px_colr, global_old_colr);
outside = 0;
while (in_line < COLOR_MATCH_WIDE && outside < WIDE_MATCH_THRESHOLD)
@ -476,17 +453,12 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen,
global_touched[(y * global_canvas->w) + fillR] = touch_byt;
}
px_colr =
getpixels[global_last->format->BytesPerPixel] (global_last, fillR, y);
px_colr = getpixels[global_last->format->BytesPerPixel] (global_last, fillR, y);
putpixels[global_canvas->format->BytesPerPixel] (global_canvas, fillR, y,
blend(global_canvas,
global_cur_colr,
px_colr,
(1.0 - in_line)));
blend(global_canvas, global_cur_colr, px_colr, (1.0 - in_line)));
fillR++;
px_colr =
getpixels[global_last->format->BytesPerPixel] (global_last, fillR, y);
px_colr = getpixels[global_last->format->BytesPerPixel] (global_last, fillR, y);
if (fillR < global_canvas->w)
{
@ -509,13 +481,9 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen,
global_touched[(y * global_canvas->w) + fillR] = touch_byt;
}
px_colr =
getpixels[global_last->format->BytesPerPixel] (global_last, fillR, y);
px_colr = getpixels[global_last->format->BytesPerPixel] (global_last, fillR, y);
putpixels[global_canvas->format->BytesPerPixel] (global_canvas, fillR, y,
blend(global_canvas,
global_cur_colr,
px_colr,
(1.0 - in_line)));
blend(global_canvas, global_cur_colr, px_colr, (1.0 - in_line)));
}
if (fillR > global_extent_x2)
@ -533,15 +501,11 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen,
{
for (i = narrowFillL; i <= narrowFillR; i++)
{
px_colr =
getpixels[global_last->format->BytesPerPixel] (global_last, i, y - 1);
px_colr = getpixels[global_last->format->BytesPerPixel] (global_last, i, y - 1);
closeness = colors_close(global_canvas, px_colr, global_old_colr);
if (closeness < COLOR_MATCH_NARROW ||
(closeness < COLOR_MATCH_WIDE && y_outside < WIDE_MATCH_THRESHOLD))
if (closeness < COLOR_MATCH_NARROW || (closeness < COLOR_MATCH_WIDE && y_outside < WIDE_MATCH_THRESHOLD))
{
if (!just_queued
&& (global_touched == NULL
|| !global_touched[((y - 1) * global_canvas->w) + i]))
if (!just_queued && (global_touched == NULL || !global_touched[((y - 1) * global_canvas->w) + i]))
{
add_to_queue(i, y - 1, y_outside + 1);
just_queued = 1;
@ -566,15 +530,11 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen,
{
for (i = narrowFillL; i <= narrowFillR; i++)
{
px_colr =
getpixels[global_last->format->BytesPerPixel] (global_last, i, y + 1);
px_colr = getpixels[global_last->format->BytesPerPixel] (global_last, i, y + 1);
closeness = colors_close(global_canvas, px_colr, global_old_colr);
if (closeness < COLOR_MATCH_NARROW ||
(closeness < COLOR_MATCH_WIDE && y_outside < WIDE_MATCH_THRESHOLD))
if (closeness < COLOR_MATCH_NARROW || (closeness < COLOR_MATCH_WIDE && y_outside < WIDE_MATCH_THRESHOLD))
{
if (!just_queued
&& (global_touched == NULL
|| !global_touched[((y + 1) * global_canvas->w) + i]))
if (!just_queued && (global_touched == NULL || !global_touched[((y + 1) * global_canvas->w) + i]))
{
add_to_queue(i, y + 1, y_outside + 1);
just_queued = 1;
@ -595,8 +555,7 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen,
void draw_linear_gradient(SDL_Surface * canvas, SDL_Surface * last,
int x_left, int y_top, int x_right, int y_bottom,
int x1, int y1, int x2, int y2, Uint32 draw_color,
Uint8 * touched)
int x1, int y1, int x2, int y2, Uint32 draw_color, Uint8 * touched)
{
Uint32 old_colr, new_colr;
int xx, yy;
@ -643,17 +602,11 @@ void draw_linear_gradient(SDL_Surface * canvas, SDL_Surface * last,
}
/* Apply fuzziness at any antialiased edges we detected */
ratio = (ratio * ((float) touched[yy * canvas->w + xx] / 255.0));
ratio = (ratio * ((float)touched[yy * canvas->w + xx] / 255.0));
new_r =
(Uint8) (((float) old_r) * ratio +
((float) draw_r * (1.0 - ratio)));
new_g =
(Uint8) (((float) old_g) * ratio +
((float) draw_g * (1.0 - ratio)));
new_b =
(Uint8) (((float) old_b) * ratio +
((float) draw_b * (1.0 - ratio)));
new_r = (Uint8) (((float)old_r) * ratio + ((float)draw_r * (1.0 - ratio)));
new_g = (Uint8) (((float)old_g) * ratio + ((float)draw_g * (1.0 - ratio)));
new_b = (Uint8) (((float)old_b) * ratio + ((float)draw_b * (1.0 - ratio)));
new_colr = SDL_MapRGB(canvas->format, new_r, new_g, new_b);
putpixels[canvas->format->BytesPerPixel] (canvas, xx, yy, new_colr);
@ -662,8 +615,7 @@ void draw_linear_gradient(SDL_Surface * canvas, SDL_Surface * last,
}
}
void draw_brush_fill_single(SDL_Surface * canvas, int x, int y,
Uint32 draw_color, Uint8 * touched)
void draw_brush_fill_single(SDL_Surface * canvas, int x, int y, Uint32 draw_color, Uint8 * touched)
{
int xx, yy;
int pix;
@ -675,13 +627,12 @@ void draw_brush_fill_single(SDL_Surface * canvas, int x, int y,
pix = ((y + yy) * canvas->w) + (x + xx);
if (pix >= 0 && pix < canvas->w * canvas->h)
{
if ((xx * xx) + (yy * yy) < (16 * 16) && touched[pix])
{
if ((xx * xx) + (yy * yy) < (16 * 16) && touched[pix])
{
putpixels[canvas->format->BytesPerPixel] (canvas, x + xx, y + yy,
draw_color);
}
putpixels[canvas->format->BytesPerPixel] (canvas, x + xx, y + yy, draw_color);
}
}
}
}
}
@ -690,8 +641,7 @@ void draw_brush_fill(SDL_Surface * canvas,
int x_left ATTRIBUTE_UNUSED, int y_top ATTRIBUTE_UNUSED,
int x_right ATTRIBUTE_UNUSED,
int y_bottom ATTRIBUTE_UNUSED, int x1, int y1, int x2,
int y2, Uint32 draw_color, Uint8 * touched, int *up_x1,
int *up_y1, int *up_x2, int *up_y2)
int y2, Uint32 draw_color, Uint8 * touched, int *up_x1, int *up_y1, int *up_x2, int *up_y2)
{
int dx, dy;
int y;
@ -709,7 +659,7 @@ void draw_brush_fill(SDL_Surface * canvas,
if (dx != 0)
{
m = ((float) dy) / ((float) dx);
m = ((float)dy) / ((float)dx);
b = y1 - m * x1;
if (x2 >= x1)
@ -770,8 +720,7 @@ void draw_brush_fill(SDL_Surface * canvas,
}
void draw_radial_gradient(SDL_Surface * canvas, int x_left, int y_top,
int x_right, int y_bottom, int x, int y,
Uint32 draw_color, Uint8 * touched)
int x_right, int y_bottom, int x, int y, Uint32 draw_color, Uint8 * touched)
{
Uint32 old_colr, new_colr;
int xx, yy;
@ -800,40 +749,33 @@ void draw_radial_gradient(SDL_Surface * canvas, int x_left, int y_top,
pix = (yy * canvas->w) + xx;
if (pix >= 0 && pix < canvas->w * canvas->h)
{
if (touched[pix])
{
if (touched[pix])
/* Determine the distance from the click point */
xd = fabs((float)(xx - x));
yd = fabs((float)(yy - y));
dist = sqrt(xd * xd + yd * yd);
if (dist < rad)
{
/* Determine the distance from the click point */
xd = fabs((float) (xx - x));
yd = fabs((float) (yy - y));
dist = sqrt(xd * xd + yd * yd);
if (dist < rad)
{
ratio = (dist / rad);
ratio = (dist / rad);
/* Get the old color, and blend it (with a distance-based ratio) with the target color */
old_colr =
getpixels[canvas->format->BytesPerPixel] (canvas, xx, yy);
SDL_GetRGB(old_colr, canvas->format, &old_r, &old_g, &old_b);
/* Get the old color, and blend it (with a distance-based ratio) with the target color */
old_colr = getpixels[canvas->format->BytesPerPixel] (canvas, xx, yy);
SDL_GetRGB(old_colr, canvas->format, &old_r, &old_g, &old_b);
/* Apply fuzziness at any antialiased edges we detected */
ratio = (ratio * ((float) touched[pix] / 255.0));
/* Apply fuzziness at any antialiased edges we detected */
ratio = (ratio * ((float)touched[pix] / 255.0));
new_r =
(Uint8) (((float) old_r) * ratio +
((float) draw_r * (1.00 - ratio)));
new_g =
(Uint8) (((float) old_g) * ratio +
((float) draw_g * (1.00 - ratio)));
new_b =
(Uint8) (((float) old_b) * ratio +
((float) draw_b * (1.00 - ratio)));
new_r = (Uint8) (((float)old_r) * ratio + ((float)draw_r * (1.00 - ratio)));
new_g = (Uint8) (((float)old_g) * ratio + ((float)draw_g * (1.00 - ratio)));
new_b = (Uint8) (((float)old_b) * ratio + ((float)draw_b * (1.00 - ratio)));
new_colr = SDL_MapRGB(canvas->format, new_r, new_g, new_b);
putpixels[canvas->format->BytesPerPixel] (canvas, xx, yy, new_colr);
}
new_colr = SDL_MapRGB(canvas->format, new_r, new_g, new_b);
putpixels[canvas->format->BytesPerPixel] (canvas, xx, yy, new_colr);
}
}
}
}
}
}
@ -845,9 +787,12 @@ void draw_radial_gradient(SDL_Surface * canvas, int x_left, int y_top,
void sdf_pt_get(sdf_grid * g, int x, int y, sdf_point * p)
{
if (x >= 0 && x < g->w && y >= 0 && y < g->h) {
if (x >= 0 && x < g->w && y >= 0 && y < g->h)
{
memcpy(p, &(g->grid[y][x]), sizeof(sdf_point));
} else {
}
else
{
memcpy(p, &(sdf_pt_empty), sizeof(sdf_point));
}
}
@ -870,37 +815,44 @@ void sdf_compare(sdf_grid * g, sdf_point * p, int x, int y, int offsetx, int off
other.dx += offsetx;
other.dy += offsety;
if (sdf_distsq(other) < sdf_distsq(*p)) {
if (sdf_distsq(other) < sdf_distsq(*p))
{
p->dx = other.dx;
p->dy = other.dy;
}
}
int malloc_sdf_grid(sdf_grid * g, int w, int h) {
int malloc_sdf_grid(sdf_grid * g, int w, int h)
{
int i, abort;
g->w = w;
g->h = h;
g->grid = (sdf_point * *) malloc(h * sizeof(sdf_point *));
if (g->grid == NULL) {
g->grid = (sdf_point * *)malloc(h * sizeof(sdf_point *));
if (g->grid == NULL)
{
fprintf(stderr, "malloc_sdf_grid() cannot malloc() g->grid!\n");
free(g);
return 0;
}
for (i = 0; i < h; i++) {
for (i = 0; i < h; i++)
{
g->grid[i] = NULL;
}
abort = 0;
for (i = 0; i < h && !abort; i++) {
for (i = 0; i < h && !abort; i++)
{
g->grid[i] = (sdf_point *) malloc(w * sizeof(sdf_point));
if (g->grid[i] == NULL) {
if (g->grid[i] == NULL)
{
abort = 1;
}
}
if (abort) {
if (abort)
{
fprintf(stderr, "malloc_sdf_grid() cannot malloc() g->grid[]!\n");
free_sdf_grid(g);
return 0;
@ -909,11 +861,14 @@ int malloc_sdf_grid(sdf_grid * g, int w, int h) {
return 1;
}
void free_sdf_grid(sdf_grid * g) {
void free_sdf_grid(sdf_grid * g)
{
int i;
for (i = 0; i < g->h; i++) {
if (g->grid[i] != NULL) {
for (i = 0; i < g->h; i++)
{
if (g->grid[i] != NULL)
{
free(g->grid[i]);
}
}
@ -921,15 +876,21 @@ void free_sdf_grid(sdf_grid * g) {
}
void sdf_fill_bitmask_to_sdf_grids(Uint8 * bitmask, int w, int h, sdf_grid * g1, sdf_grid * g2) {
void sdf_fill_bitmask_to_sdf_grids(Uint8 * bitmask, int w, int h, sdf_grid * g1, sdf_grid * g2)
{
int x, y;
for (y = 0; y < h; y++) {
for (x = 0; x < w; x++) {
if (bitmask[y * w + x]) {
for (y = 0; y < h; y++)
{
for (x = 0; x < w; x++)
{
if (bitmask[y * w + x])
{
sdf_pt_put(g1, x, y, sdf_pt_inside);
sdf_pt_put(g2, x, y, sdf_pt_empty);
} else {
}
else
{
sdf_pt_put(g1, x, y, sdf_pt_empty);
sdf_pt_put(g2, x, y, sdf_pt_inside);
}
@ -938,40 +899,47 @@ void sdf_fill_bitmask_to_sdf_grids(Uint8 * bitmask, int w, int h, sdf_grid * g1,
}
void sdf_generate(sdf_grid * g) {
void sdf_generate(sdf_grid * g)
{
int x, y;
sdf_point p;
/* Pass 0 */
for (y = 0; y < g->h; y++) {
for (x = 0; x < g->w; x++) {
for (y = 0; y < g->h; y++)
{
for (x = 0; x < g->w; x++)
{
sdf_pt_get(g, x, y, &p);
sdf_compare(g, &p, x, y, -1, 0);
sdf_compare(g, &p, x, y, 0, -1);
sdf_compare(g, &p, x, y, -1, 0);
sdf_compare(g, &p, x, y, 0, -1);
sdf_compare(g, &p, x, y, -1, -1);
sdf_compare(g, &p, x, y, 1, -1);
sdf_compare(g, &p, x, y, 1, -1);
sdf_pt_put(g, x, y, p);
}
for (x = g->w - 1; x >= 0; x--) {
for (x = g->w - 1; x >= 0; x--)
{
sdf_pt_get(g, x, y, &p);
sdf_compare(g, &p, x, y, 1, 0);
sdf_compare(g, &p, x, y, 1, 0);
sdf_pt_put(g, x, y, p);
}
}
/* Pass 1 */
for (y = g->h - 1; y >= 0; y--) {
for (x = g->w - 1; x >= 0; x--) {
for (y = g->h - 1; y >= 0; y--)
{
for (x = g->w - 1; x >= 0; x--)
{
sdf_pt_get(g, x, y, &p);
sdf_compare(g, &p, x, y, 1, 0);
sdf_compare(g, &p, x, y, 0, 1);
sdf_compare(g, &p, x, y, 1, 0);
sdf_compare(g, &p, x, y, 0, 1);
sdf_compare(g, &p, x, y, -1, 1);
sdf_compare(g, &p, x, y, 1, 1);
sdf_compare(g, &p, x, y, 1, 1);
sdf_pt_put(g, x, y, p);
}
for (x = 0; x < g->w; x++) {
for (x = 0; x < g->w; x++)
{
sdf_pt_get(g, x, y, &p);
sdf_compare(g, &p, x, y, -1, 0);
sdf_pt_put(g, x, y, p);
@ -989,21 +957,24 @@ void draw_shaped_gradient(SDL_Surface * canvas, Uint32 draw_color, Uint8 * touch
int pix_idx;
float ratio;
Uint8 draw_r, draw_g, draw_b, old_r, old_g, old_b, new_r, new_g, new_b;
Uint8 * bitmask;
Uint8 *bitmask;
sdf_grid g1, g2;
/* Create space for bitmask (based on `touched`) and SDF output
large enough for the area being filled */
bitmask = (Uint8 *) malloc(sizeof(Uint8) * canvas->w * canvas->h);
if (bitmask == NULL) {
if (bitmask == NULL)
{
return;
}
if (!malloc_sdf_grid(&g1, canvas->w, canvas->h)) {
if (!malloc_sdf_grid(&g1, canvas->w, canvas->h))
{
free(bitmask);
return;
}
if (!malloc_sdf_grid(&g2, canvas->w, canvas->h)) {
if (!malloc_sdf_grid(&g2, canvas->w, canvas->h))
{
free(bitmask);
free_sdf_grid(&g1);
return;
@ -1011,8 +982,10 @@ void draw_shaped_gradient(SDL_Surface * canvas, Uint32 draw_color, Uint8 * touch
/* Convert the `touched` values into a bitmask to feed into the SDF routines */
for (yy = 0; yy < canvas->h; yy++) {
for (xx = 0; xx < canvas->w; xx++) {
for (yy = 0; yy < canvas->h; yy++)
{
for (xx = 0; xx < canvas->w; xx++)
{
/* Converting 0-255 to 0/1 */
bitmask[yy * canvas->w + xx] = (touched[(yy * canvas->w) + xx] >= 128);
}
@ -1036,49 +1009,42 @@ void draw_shaped_gradient(SDL_Surface * canvas, Uint32 draw_color, Uint8 * touch
pix_idx = (yy * canvas->w) + xx;
if (pix_idx >= 0 && pix_idx < canvas->w * canvas->h)
{
if (touched[pix_idx])
{
if (touched[pix_idx])
{
sdf_point p;
double dist1, dist2, dist;
sdf_point p;
double dist1, dist2, dist;
sdf_pt_get(&g1, xx, yy, &p);
dist1 = sqrt(sdf_distsq(p));
sdf_pt_get(&g1, xx, yy, &p);
dist1 = sqrt(sdf_distsq(p));
sdf_pt_get(&g2, xx, yy, &p);
dist2 = sqrt(sdf_distsq(p));
sdf_pt_get(&g2, xx, yy, &p);
dist2 = sqrt(sdf_distsq(p));
dist = dist1 - dist2;
dist = dist1 - dist2;
/* Determine the distance from the click point */
ratio = ((float) ((dist * 10) + 255)) / 255.0; // Magic numbers :-( -bjk 2023.02.25
if (ratio < 0.0)
ratio = 0.0;
else if (ratio > 1.0)
ratio = 1.0;
/* Determine the distance from the click point */
ratio = ((float)((dist * 10) + 255)) / 255.0; // Magic numbers :-( -bjk 2023.02.25
if (ratio < 0.0)
ratio = 0.0;
else if (ratio > 1.0)
ratio = 1.0;
/* Get the old color, and blend it (with a distance-based ratio) with the target color */
old_colr =
getpixels[canvas->format->BytesPerPixel] (canvas, xx, yy);
SDL_GetRGB(old_colr, canvas->format, &old_r, &old_g, &old_b);
/* Get the old color, and blend it (with a distance-based ratio) with the target color */
old_colr = getpixels[canvas->format->BytesPerPixel] (canvas, xx, yy);
SDL_GetRGB(old_colr, canvas->format, &old_r, &old_g, &old_b);
/* Apply fuzziness at any antialiased edges we detected */
ratio = (ratio * ((float) touched[pix_idx] / 255.0));
/* Apply fuzziness at any antialiased edges we detected */
ratio = (ratio * ((float)touched[pix_idx] / 255.0));
new_r =
(Uint8) (((float) old_r) * ratio +
((float) draw_r * (1.00 - ratio)));
new_g =
(Uint8) (((float) old_g) * ratio +
((float) draw_g * (1.00 - ratio)));
new_b =
(Uint8) (((float) old_b) * ratio +
((float) draw_b * (1.00 - ratio)));
new_r = (Uint8) (((float)old_r) * ratio + ((float)draw_r * (1.00 - ratio)));
new_g = (Uint8) (((float)old_g) * ratio + ((float)draw_g * (1.00 - ratio)));
new_b = (Uint8) (((float)old_b) * ratio + ((float)draw_b * (1.00 - ratio)));
new_colr = SDL_MapRGB(canvas->format, new_r, new_g, new_b);
putpixels[canvas->format->BytesPerPixel] (canvas, xx, yy, new_colr);
}
new_colr = SDL_MapRGB(canvas->format, new_r, new_g, new_b);
putpixels[canvas->format->BytesPerPixel] (canvas, xx, yy, new_colr);
}
}
}
}

View file

@ -40,24 +40,19 @@ int would_flood_fill(SDL_Surface * canvas, Uint32 cur_colr, Uint32 old_colr);
void do_flood_fill(SDL_Surface * screen, SDL_Texture * texture,
SDL_Renderer * renderer, SDL_Surface * last,
SDL_Surface * canvas, int x, int y, Uint32 cur_colr,
Uint32 old_colr, int *x1, int *y1, int *x2, int *y2,
Uint8 * touched);
Uint32 old_colr, int *x1, int *y1, int *x2, int *y2, Uint8 * touched);
void simulate_flood_fill(SDL_Surface * screen, SDL_Texture * texture,
SDL_Renderer * renderer, SDL_Surface * last,
SDL_Surface * canvas, int x, int y, Uint32 cur_colr,
Uint32 old_colr, int *x1, int *y1, int *x2, int *y2,
Uint8 * touched);
Uint32 old_colr, int *x1, int *y1, int *x2, int *y2, Uint8 * touched);
void draw_linear_gradient(SDL_Surface * canvas, SDL_Surface * last,
int x_left, int y_top, int x_right, int y_bottom,
int x1, int y1, int x2, int y2, Uint32 draw_color,
Uint8 * touched);
int x1, int y1, int x2, int y2, Uint32 draw_color, Uint8 * touched);
void draw_radial_gradient(SDL_Surface * canvas, int x_left, int y_top,
int x_right, int y_bottom, int x, int y,
Uint32 draw_color, Uint8 * touched);
int x_right, int y_bottom, int x, int y, Uint32 draw_color, Uint8 * touched);
void draw_shaped_gradient(SDL_Surface * canvas, Uint32 draw_color, Uint8 * touched);
void draw_brush_fill(SDL_Surface * canvas, int x_left, int y_top, int x_right,
int y_bottom, int x1, int y1, int x2, int y2,
Uint32 draw_color, Uint8 * touched, int *up_x1,
int *up_y1, int *up_x2, int *up_y2);
Uint32 draw_color, Uint8 * touched, int *up_x1, int *up_y1, int *up_x2, int *up_y2);
#endif

View file

@ -59,12 +59,9 @@ const char *const fill_names[NUM_FILLS] = {
const char *const fill_tips[NUM_FILLS] = {
gettext_noop("Click to fill an area with a solid color."),
gettext_noop("Click and drag to fill an area by hand, using a brush."),
gettext_noop
("Click and drag to fill an area with a linear gradient (from the chosen color to transparent)."),
gettext_noop
("Click to fill an area with a radial gradient (from the chosen color to transparent)."),
gettext_noop
("Click to fill an area with a shaped gradient (from the chosen color to transparent).")
gettext_noop("Click and drag to fill an area with a linear gradient (from the chosen color to transparent)."),
gettext_noop("Click to fill an area with a radial gradient (from the chosen color to transparent)."),
gettext_noop("Click to fill an area with a shaped gradient (from the chosen color to transparent).")
};
const char *const fill_img_fnames[NUM_FILLS] = {

View file

@ -142,6 +142,7 @@ int all_locale_fonts;
volatile long font_thread_done;
volatile long font_thread_aborted;
volatile long waiting_for_fonts;
#ifdef FORKED_FONTS
static int font_scanner_pid;
#endif
@ -180,8 +181,7 @@ TuxPaint_Font *load_locale_font(TuxPaint_Font * fallback, int size)
{
char str[128];
snprintf(str, sizeof(str), "%sfonts/locale/%s.ttf", DATA_PREFIX,
lang_prefix);
snprintf(str, sizeof(str), "%sfonts/locale/%s.ttf", DATA_PREFIX, lang_prefix);
ret = TuxPaint_Font_OpenFont("", str, size);
@ -214,16 +214,14 @@ TuxPaint_Font *load_locale_font(TuxPaint_Font * fallback, int size)
void TuxPaint_Font_CloseFont(TuxPaint_Font * tpf)
{
#ifdef DEBUG
printf("%s:%d - TuxPaint_Font_CloseFont step 1 (%p)\n", __FILE__, __LINE__,
tpf);
printf("%s:%d - TuxPaint_Font_CloseFont step 1 (%p)\n", __FILE__, __LINE__, tpf);
#endif
if (!tpf)
return;
#ifndef NO_SDLPANGO
#ifdef DEBUG
printf("%s:%d - TuxPaint_Font_CloseFont step 2 (%p, %d)\n", __FILE__,
__LINE__, tpf->pango_context, tpf->typ);
printf("%s:%d - TuxPaint_Font_CloseFont step 2 (%p, %d)\n", __FILE__, __LINE__, tpf->pango_context, tpf->typ);
#endif
if (tpf->typ == FONT_TYPE_PANGO)
if (tpf->pango_context)
@ -236,8 +234,7 @@ void TuxPaint_Font_CloseFont(TuxPaint_Font * tpf)
#endif
#ifdef DEBUG
printf("%s:%d - TuxPaint_Font_CloseFont step 3 (%p, %d)\n", __FILE__,
__LINE__, tpf->ttf_font, tpf->typ);
printf("%s:%d - TuxPaint_Font_CloseFont step 3 (%p, %d)\n", __FILE__, __LINE__, tpf->ttf_font, tpf->typ);
fflush(stdout);
#endif
if (tpf->typ == FONT_TYPE_TTF)
@ -256,8 +253,7 @@ void TuxPaint_Font_CloseFont(TuxPaint_Font * tpf)
free(tpf);
}
TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc,
const char *ttffilename, int size)
TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc, const char *ttffilename, int size)
{
TTF_Font *ttf_font;
TuxPaint_Font *tpf = NULL;
@ -269,8 +265,7 @@ TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc,
#endif
#ifdef DEBUG
printf("%s:%d - OpenFont(pango:\"%s\", ttf:\"%s\")\n", __FILE__, __LINE__,
pangodesc, ttffilename);
printf("%s:%d - OpenFont(pango:\"%s\", ttf:\"%s\")\n", __FILE__, __LINE__, pangodesc, ttffilename);
#endif
#ifndef NO_SDLPANGO
@ -282,16 +277,15 @@ TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc,
tpf->desc = strdup(desc);
#ifdef DEBUG
printf("%s:%d - Creating Pango context: \"%s\"\n", __FILE__, __LINE__,
desc);
printf("%s:%d - Creating Pango context: \"%s\"\n", __FILE__, __LINE__, desc);
#endif
#ifdef __APPLE__
/*
* SDLPango_CreateContext_GivenFontDesc() defaults to ASCII character set
* (at least on the macOS) unless the CHARSET environment varaible is set.
* May also want to set on non-macOS platforms, also.
*/
* SDLPango_CreateContext_GivenFontDesc() defaults to ASCII character set
* (at least on the macOS) unless the CHARSET environment varaible is set.
* May also want to set on non-macOS platforms, also.
*/
mysetenv("CHARSET", "UTF-8");
#endif
@ -325,8 +319,7 @@ TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc,
if (ttffilename != NULL && ttffilename[0] != '\0')
{
#ifdef DEBUG
printf("%s:%d - Considering loading TTF \"%s\"\n", __FILE__, __LINE__,
ttffilename);
printf("%s:%d - Considering loading TTF \"%s\"\n", __FILE__, __LINE__, ttffilename);
fflush(stdout);
#endif
@ -336,8 +329,7 @@ TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc,
if (!strcmp(ttffilename, problemFonts[i++]))
{
#ifdef DEBUG
fprintf(stderr, "Notice: Skipping problematic font: \"%s\"\n",
ttffilename);
fprintf(stderr, "Notice: Skipping problematic font: \"%s\"\n", ttffilename);
#endif
return NULL; /* bail on known problematic fonts that cause TTF_OpenFont to crash */
}
@ -349,9 +341,7 @@ TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc,
if (strstr(ttffilename, problemFontExtensions[i++]))
{
#ifdef DEBUG
fprintf(stderr,
"Notice: Skipping font with problematic extension: \"%s\"\n",
ttffilename);
fprintf(stderr, "Notice: Skipping font with problematic extension: \"%s\"\n", ttffilename);
#endif
return NULL; /* bail on known problematic font types that cause TTF_OpenFont to crash */
}
@ -361,13 +351,12 @@ TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc,
if (ttf_font == NULL)
{
fprintf(stderr, "Cannot open TTF font '%s' (size %d)\n", ttffilename,
size);
fprintf(stderr, "Cannot open TTF font '%s' (size %d)\n", ttffilename, size);
return NULL;
}
familyname = TTF_FontFaceFamilyName(ttf_font); /* N.B.: I don't believe we're supposed to free() this... -bjk 2021.10.26 */
(void) familyname; // avoid compiler complaints if NO_SDLPANGO is set, or ALWAYS_LOAD_FONT_WITH_PANGO is not set, and DEBUG is not set
(void)familyname; // avoid compiler complaints if NO_SDLPANGO is set, or ALWAYS_LOAD_FONT_WITH_PANGO is not set, and DEBUG is not set
#ifdef DEBUG
printf("%s:%d - Loaded %s (\"%s\")\n", __FILE__, __LINE__, ttffilename,
@ -406,8 +395,7 @@ TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc,
tpf->desc = strdup(ttffilename);
#ifdef DEBUG
printf("%s:%d - Succeeded loading %s via SDL_ttf\n", __FILE__, __LINE__,
ttffilename);
printf("%s:%d - Succeeded loading %s via SDL_ttf\n", __FILE__, __LINE__, ttffilename);
#endif
tpf->height = TTF_FontHeight(tpf->ttf_font);
@ -614,9 +602,7 @@ static void groupfonts_range(style_info ** base, int count)
if (num_font_families == num_font_families_max)
{
num_font_families_max = num_font_families_max * 5 / 4 + 30;
user_font_families =
realloc(user_font_families,
num_font_families_max * sizeof *user_font_families);
user_font_families = realloc(user_font_families, num_font_families_max * sizeof *user_font_families);
}
fi = calloc(1, sizeof *fi);
@ -633,8 +619,7 @@ static void groupfonts_range(style_info ** base, int count)
{
#if 0
// THREADED_FONTS
printf("too many boldness levels, discarding: %s, %s\n",
base[i]->family, base[i]->style);
printf("too many boldness levels, discarding: %s, %s\n", base[i]->family, base[i]->style);
#endif
continue;
}
@ -644,11 +629,9 @@ static void groupfonts_range(style_info ** base, int count)
{
#if 0
// THREADED_FONTS
printf("duplicates, discarding: %s, %s\n", base[i]->family,
base[i]->style);
printf("duplicates, discarding: %s, %s\n", base[i]->family, base[i]->style);
printf("b %d, spot %d\n", b, spot);
printf("occupancy %p %p %p %p\n", fi->filename[0], fi->filename[1],
fi->filename[2], fi->filename[3]);
printf("occupancy %p %p %p %p\n", fi->filename[0], fi->filename[1], fi->filename[2], fi->filename[3]);
#endif
continue;
}
@ -872,8 +855,7 @@ static void parse_font_style(style_info * si)
si->boldness = 1;
// we'll count both TrueType and OpenType
si->truetype = !!strcasestr(si->filename, ".ttf")
|| !!strcasestr(si->filename, ".otf");
si->truetype = !!strcasestr(si->filename, ".ttf") || !!strcasestr(si->filename, ".otf");
}
@ -911,8 +893,7 @@ static void groupfonts(void)
while (i--)
parse_font_style(user_font_styles[i]);
qsort(user_font_styles, num_font_styles, sizeof user_font_styles[0],
compar_fontgroup);
qsort(user_font_styles, num_font_styles, sizeof user_font_styles[0], compar_fontgroup);
//printf("groupfonts() qsort(user_font_styles...)\n");
//fflush(stdout);
@ -945,8 +926,7 @@ static void groupfonts(void)
free(user_font_styles);
user_font_styles = NULL; // just to catch bugs
qsort(user_font_families, num_font_families, sizeof user_font_families[0],
compar_fontkiller);
qsort(user_font_families, num_font_families, sizeof user_font_families[0], compar_fontkiller);
low = 0;
for (;;)
{
@ -958,15 +938,13 @@ static void groupfonts(void)
{
if (++high >= num_font_families)
break;
if (strcmp
(user_font_families[low]->family, user_font_families[high]->family))
if (strcmp(user_font_families[low]->family, user_font_families[high]->family))
break;
}
dupe_markdown_range(user_font_families + low, high - low);
low = high;
}
qsort(user_font_families, num_font_families, sizeof user_font_families[0],
compar_fontscore);
qsort(user_font_families, num_font_families, sizeof user_font_families[0], compar_fontscore);
//printf("groupfonts() qsort(user_font_families 2...)\n");
//fflush(stdout);
if (num_font_families > 0 && user_font_families[0]->score < 0)
@ -975,8 +953,7 @@ static void groupfonts(void)
// THREADED_FONTS
printf("Trim starting with %d families\n", num_font_families);
#endif
while (num_font_families > 1
&& user_font_families[num_font_families - 1]->score < 0)
while (num_font_families > 1 && user_font_families[num_font_families - 1]->score < 0)
{
i = --num_font_families;
free(user_font_families[i]->directory);
@ -1002,9 +979,7 @@ static void groupfonts(void)
static void loadfonts_locale_filter(SDL_Surface * screen,
SDL_Texture * texture,
SDL_Renderer * renderer,
const char *const dir,
const char *restrict const locale)
SDL_Renderer * renderer, const char *const dir, const char *restrict const locale)
{
char buf[TP_FTW_PATHSIZE];
unsigned dirlen = strlen(dir);
@ -1012,27 +987,23 @@ static void loadfonts_locale_filter(SDL_Surface * screen,
DEBUG_PRINTF("Loading fonts from [%s]\n", dir);
memcpy(buf, dir, dirlen);
tp_ftw(screen, texture, renderer, buf, dirlen, 1, loadfont_callback,
locale);
tp_ftw(screen, texture, renderer, buf, dirlen, 1, loadfont_callback, locale);
}
static void loadfonts(SDL_Surface * screen, SDL_Texture * texture,
SDL_Renderer * renderer, const char *const dir)
static void loadfonts(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer, const char *const dir)
{
loadfonts_locale_filter(screen, texture, renderer, dir, NULL);
}
/* static */ int load_user_fonts(SDL_Surface * screen, SDL_Texture * texture,
SDL_Renderer * renderer, void *vp,
const char *restrict const locale)
SDL_Renderer * renderer, void *vp, const char *restrict const locale)
{
char *homedirdir;
(void) vp; // junk passed by threading library
(void)vp; // junk passed by threading library
loadfonts_locale_filter(screen, texture, renderer, DATA_PREFIX "fonts",
locale);
loadfonts_locale_filter(screen, texture, renderer, DATA_PREFIX "fonts", locale);
if (!no_system_fonts)
{
@ -1049,21 +1020,13 @@ static void loadfonts(SDL_Surface * screen, SDL_Texture * texture,
char buffer[B_PATH_NAME_LENGTH + B_FILE_NAME_LENGTH];
status_t result;
result =
find_directory(B_SYSTEM_FONTS_DIRECTORY, volume, false, buffer,
sizeof(buffer));
result = find_directory(B_SYSTEM_FONTS_DIRECTORY, volume, false, buffer, sizeof(buffer));
loadfonts(screen, texture, renderer, buffer);
result =
find_directory(B_SYSTEM_NONPACKAGED_FONTS_DIRECTORY, volume, false,
buffer, sizeof(buffer));
result = find_directory(B_SYSTEM_NONPACKAGED_FONTS_DIRECTORY, volume, false, buffer, sizeof(buffer));
loadfonts(screen, texture, renderer, buffer);
result =
find_directory(B_USER_FONTS_DIRECTORY, volume, false, buffer,
sizeof(buffer));
result = find_directory(B_USER_FONTS_DIRECTORY, volume, false, buffer, sizeof(buffer));
loadfonts(screen, texture, renderer, buffer);
result =
find_directory(B_USER_NONPACKAGED_FONTS_DIRECTORY, volume, false,
buffer, sizeof(buffer));
result = find_directory(B_USER_NONPACKAGED_FONTS_DIRECTORY, volume, false, buffer, sizeof(buffer));
loadfonts(screen, texture, renderer, buffer);
#elif defined(__APPLE__)
loadfonts(screen, texture, renderer, "/System/Library/Fonts");
@ -1102,8 +1065,7 @@ static void loadfonts(SDL_Surface * screen, SDL_Texture * texture,
#endif
#ifdef __APPLE__
homedirdir =
malloc(snprintf(NULL, 0, "%s/fonts", apple_globalPreferencesPath()) + 1);
homedirdir = malloc(snprintf(NULL, 0, "%s/fonts", apple_globalPreferencesPath()) + 1);
if (homedirdir)
{
sprintf(homedirdir, "%s/fonts", apple_globalPreferencesPath());
@ -1113,8 +1075,7 @@ static void loadfonts(SDL_Surface * screen, SDL_Texture * texture,
#endif
#ifdef DEBUG
printf("%s:%d - Grouping %d fonts...\n", __FILE__, __LINE__,
num_font_styles);
printf("%s:%d - Grouping %d fonts...\n", __FILE__, __LINE__, num_font_styles);
fflush(stdout);
#endif
@ -1135,8 +1096,7 @@ static void loadfonts(SDL_Surface * screen, SDL_Texture * texture,
#ifdef FORKED_FONTS
void run_font_scanner(SDL_Surface * screen, SDL_Texture * texture,
SDL_Renderer * renderer,
const char *restrict const locale)
SDL_Renderer * renderer, const char *restrict const locale)
{
int sv[2];
int size, i;
@ -1202,8 +1162,7 @@ void run_font_scanner(SDL_Surface * screen, SDL_Texture * texture,
buf = malloc(size);
walk = buf;
#ifdef DEBUG
printf("%s:%d - Sending %u bytes with %u families.\n", __FILE__, __LINE__,
size, num_font_families);
printf("%s:%d - Sending %u bytes with %u families.\n", __FILE__, __LINE__, size, num_font_families);
#endif
*walk++ = num_font_families & 0xffu;
*walk++ = num_font_families >> 8u;
@ -1272,8 +1231,7 @@ void run_font_scanner(SDL_Surface * screen, SDL_Texture * texture,
}
void receive_some_font_info(SDL_Surface * screen, SDL_Texture * texture,
SDL_Renderer * renderer)
void receive_some_font_info(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer)
{
char *buf = NULL;
unsigned buf_size = 0;
@ -1298,7 +1256,7 @@ void receive_some_font_info(SDL_Surface * screen, SDL_Texture * texture,
rc = read(font_socket_fd, buf + buf_fill, buf_size - buf_fill);
#ifdef DEBUG
printf("%s:%d - read: fd=%d buf_fill=%u buf_size=%u rc=%ld\n", __FILE__,
__LINE__, font_socket_fd, buf_fill, buf_size, (long int) rc);
__LINE__, font_socket_fd, buf_fill, buf_size, (long int)rc);
#endif
if (rc == -1)
@ -1339,11 +1297,10 @@ void receive_some_font_info(SDL_Surface * screen, SDL_Texture * texture,
show_progress_bar_(screen, texture, renderer);
walk = buf;
num_font_families = *(unsigned char *) walk++;
num_font_families += *(unsigned char *) walk++ << 8u;
num_font_families = *(unsigned char *)walk++;
num_font_families += *(unsigned char *)walk++ << 8u;
#ifdef DEBUG
printf("%s:%d - Got %u bytes with %u families.\n", __FILE__, __LINE__,
buf_fill, num_font_families);
printf("%s:%d - Got %u bytes with %u families.\n", __FILE__, __LINE__, buf_fill, num_font_families);
#endif
user_font_families = malloc(num_font_families * sizeof *user_font_families);
@ -1409,8 +1366,7 @@ TuxPaint_Font *getfonthandle(int desire)
if (fi == NULL)
{
#ifdef DEBUG
printf("%s:%d - getfonthandle(%d) points to a NULL family\n", __FILE__,
__LINE__, desire);
printf("%s:%d - getfonthandle(%d) points to a NULL family\n", __FILE__, __LINE__, desire);
fflush(stdout);
#endif
return NULL;
@ -1419,8 +1375,7 @@ TuxPaint_Font *getfonthandle(int desire)
if (fi->filename != NULL)
{
#ifdef DEBUG
printf("%s:%d - Setting 'name' to fi->filename[%d (0x%x)]\n", __FILE__,
__LINE__, (int) text_state, (int) text_state);
printf("%s:%d - Setting 'name' to fi->filename[%d (0x%x)]\n", __FILE__, __LINE__, (int)text_state, (int)text_state);
fflush(stdout);
#endif
@ -1444,8 +1399,7 @@ TuxPaint_Font *getfonthandle(int desire)
if (fi->handle)
{
#ifdef DEBUG
printf("%s:%d - fi->handle was set (0x%x)\n", __FILE__, __LINE__,
(int) (intptr_t) fi->handle);
printf("%s:%d - fi->handle was set (0x%x)\n", __FILE__, __LINE__, (int)(intptr_t) fi->handle);
fflush(stdout);
#endif
@ -1511,8 +1465,7 @@ TuxPaint_Font *getfonthandle(int desire)
strcpy(description, "");
}
fi->handle =
TuxPaint_Font_OpenFont(description, pathname, text_sizes[text_size]);
fi->handle = TuxPaint_Font_OpenFont(description, pathname, text_sizes[text_size]);
// if the font doesn't load, we die -- it did load OK before though
if (fi->handle == NULL)
@ -1536,8 +1489,7 @@ TuxPaint_Font *getfonthandle(int desire)
}
#ifdef DEBUG
printf("%s:%d - calling TTF_SetFontStyle(0x%x)\n", __FILE__, __LINE__,
missing);
printf("%s:%d - calling TTF_SetFontStyle(0x%x)\n", __FILE__, __LINE__, missing);
fflush(stdout);
#endif
@ -1557,8 +1509,7 @@ TuxPaint_Font *getfonthandle(int desire)
static int was_bad_font;
// see if two font surfaces are the same
static int do_surfcmp(const SDL_Surface * const *const v1,
const SDL_Surface * const *const v2)
static int do_surfcmp(const SDL_Surface * const *const v1, const SDL_Surface * const *const v2)
{
const SDL_Surface *const s1 = *v1;
const SDL_Surface *const s2 = *v2;
@ -1572,8 +1523,7 @@ static int do_surfcmp(const SDL_Surface * const *const v1,
fprintf(stderr, "s1==s2?\n");
return 0;
}
if (!s1 || !s2 || !s1->w || !s2->w || !s1->h || !s2->h || !s1->format
|| !s2->format)
if (!s1 || !s2 || !s1->w || !s2->w || !s1->h || !s2->h || !s1->format || !s2->format)
{
/* One or the other or both SDL_Surfaces were invalid!? */
was_bad_font = 1;
@ -1596,11 +1546,12 @@ static int do_surfcmp(const SDL_Surface * const *const v1,
/* Otherwise, compare the pixels in the surfaces
(using `memcmp()`) */
{
const char *const c1 = (char *const) s1->pixels;
const char *const c2 = (char *const) s2->pixels;
const char *const c1 = (char *const)s1->pixels;
const char *const c2 = (char *const)s2->pixels;
width = s1->format->BytesPerPixel * s1->w;
if (width == s1->pitch) {
if (width == s1->pitch)
{
/* Same width, just compare scanline */
return memcmp(c1, c2, width * s1->h);
}
@ -1625,7 +1576,8 @@ static int surfcmp(const void *s1, const void *s2)
{
int diff = do_surfcmp(s1, s2);
if (!diff) {
if (!diff)
{
#ifdef DEBUG
printf("surfcmp found two identical renders!\n");
#endif
@ -1708,8 +1660,7 @@ int TuxPaint_Font_FontHeight(TuxPaint_Font * tpf)
if (tpf == NULL)
{
#ifdef DEBUG
printf("%s:%d - TuxPaint_Font_FontHeight() received NULL\n", __FILE__,
__LINE__);
printf("%s:%d - TuxPaint_Font_FontHeight() received NULL\n", __FILE__, __LINE__);
fflush(stdout);
#endif
return (1);
@ -1723,8 +1674,7 @@ const char *TuxPaint_Font_FontFaceFamilyName(TuxPaint_Font * tpf)
if (tpf == NULL)
{
#ifdef DEBUG
printf("%s:%d - TuxPaint_Font_FontFaceFamilyName() received NULL\n",
__FILE__, __LINE__);
printf("%s:%d - TuxPaint_Font_FontFaceFamilyName() received NULL\n", __FILE__, __LINE__);
fflush(stdout);
#endif
return ("");
@ -1733,7 +1683,7 @@ const char *TuxPaint_Font_FontFaceFamilyName(TuxPaint_Font * tpf)
#ifndef NO_SDLPANGO
if (tpf->typ == FONT_TYPE_PANGO)
{
(void) (tpf);
(void)(tpf);
/* FIXME */
return ("");
@ -1744,8 +1694,7 @@ const char *TuxPaint_Font_FontFaceFamilyName(TuxPaint_Font * tpf)
return (TTF_FontFaceFamilyName(tpf->ttf_font));
#ifdef DEBUG
printf("%s:%d - TuxPaint_Font_FontFaceFamilyName() is confused\n", __FILE__,
__LINE__);
printf("%s:%d - TuxPaint_Font_FontFaceFamilyName() is confused\n", __FILE__, __LINE__);
#endif
return ("");
@ -1756,8 +1705,7 @@ const char *TuxPaint_Font_FontFaceStyleName(TuxPaint_Font * tpf)
if (tpf == NULL)
{
#ifdef DEBUG
printf("%s:%d - TuxPaint_Font_FontFaceStyleName() received NULL\n",
__FILE__, __LINE__);
printf("%s:%d - TuxPaint_Font_FontFaceStyleName() received NULL\n", __FILE__, __LINE__);
fflush(stdout);
#endif
return ("");
@ -1766,7 +1714,7 @@ const char *TuxPaint_Font_FontFaceStyleName(TuxPaint_Font * tpf)
#ifndef NO_SDLPANGO
if (tpf->typ == FONT_TYPE_PANGO)
{
(void) (tpf);
(void)(tpf);
/* FIXME */
return ("");
@ -1777,8 +1725,7 @@ const char *TuxPaint_Font_FontFaceStyleName(TuxPaint_Font * tpf)
return (TTF_FontFaceStyleName(tpf->ttf_font));
#ifdef DEBUG
printf("%s:%d - TuxPaint_Font_FontFaceStyleName() is confused\n", __FILE__,
__LINE__);
printf("%s:%d - TuxPaint_Font_FontFaceStyleName() is confused\n", __FILE__, __LINE__);
#endif
return ("");
@ -1787,8 +1734,7 @@ const char *TuxPaint_Font_FontFaceStyleName(TuxPaint_Font * tpf)
#ifndef NO_SDLPANGO
void sdl_color_to_pango_color(SDL_Color sdl_color,
SDLPango_Matrix * pango_color)
void sdl_color_to_pango_color(SDL_Color sdl_color, SDLPango_Matrix * pango_color)
{
Uint8 pc[4][4];

View file

@ -121,10 +121,8 @@ int TuxPaint_Font_FontHeight(TuxPaint_Font * tpf);
#ifdef FORKED_FONTS
void reliable_write(int fd, const void *buf, size_t count);
void run_font_scanner(SDL_Surface * screen, SDL_Texture * texture,
SDL_Renderer * renderer,
const char *restrict const locale);
void receive_some_font_info(SDL_Surface * screen, SDL_Texture * texture,
SDL_Renderer * renderer);
SDL_Renderer * renderer, const char *restrict const locale);
void receive_some_font_info(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer);
#endif
//////////////////////////////////////////////////////////////////////
@ -192,8 +190,7 @@ TuxPaint_Font *getfonthandle(int desire);
int charset_works(TuxPaint_Font * font, const char *s);
TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc,
const char *ttffilename, int size);
TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc, const char *ttffilename, int size);
void TuxPaint_Font_CloseFont(TuxPaint_Font * tpf);
const char *TuxPaint_Font_FontFaceFamilyName(TuxPaint_Font * tpf);
const char *TuxPaint_Font_FontFaceStyleName(TuxPaint_Font * tpf);
@ -201,12 +198,10 @@ const char *TuxPaint_Font_FontFaceStyleName(TuxPaint_Font * tpf);
#ifdef NO_SDLPANGO
TuxPaint_Font *load_locale_font(TuxPaint_Font * fallback, int size);
#else
void sdl_color_to_pango_color(SDL_Color sdl_color,
SDLPango_Matrix * pango_color);
void sdl_color_to_pango_color(SDL_Color sdl_color, SDLPango_Matrix * pango_color);
#endif
int load_user_fonts(SDL_Surface * screen, SDL_Texture * texture,
SDL_Renderer * renderer, void *vp,
const char *restrict const locale);
SDL_Renderer * renderer, void *vp, const char *restrict const locale);
#endif

View file

@ -88,6 +88,7 @@ const char *exportdir;
char *get_fname(const char *const name, int kind)
{
char f[512];
// const char *restrict const dir;
const char *dir;

View file

@ -44,6 +44,7 @@ typedef struct Node Node;
static Node *new_node(uint16_t key, int degree)
{
Node *node = calloc(1, sizeof(*node) + degree * sizeof(Node *));
if (node)
node->key = key;
return node;
@ -52,6 +53,7 @@ static Node *new_node(uint16_t key, int degree)
static Node *new_trie(int degree, int *nkeys)
{
Node *root = new_node(0, degree);
/* Create nodes for single pixels. */
for (*nkeys = 0; *nkeys < degree; (*nkeys)++)
root->children[*nkeys] = new_node(*nkeys, degree);
@ -75,12 +77,12 @@ static void put_loop(ge_GIF * gif, uint16_t loop);
#define OR_ABORT if (res == -1) { fprintf(stderr, "Cannot write to GIF\n"); return(NULL); }
#define OR_ABORT2 if (res == -1) { fprintf(stderr, "Cannot write to GIF\n"); return; }
ge_GIF *ge_new_gif(const char *fname, uint16_t width, uint16_t height,
uint8_t * palette, int depth, int loop)
ge_GIF *ge_new_gif(const char *fname, uint16_t width, uint16_t height, uint8_t * palette, int depth, int loop)
{
int i, r, g, b, v;
ssize_t res;
ge_GIF *gif = calloc(1, sizeof(*gif) + 2 * width * height);
if (!gif)
goto no_gif;
gif->w = width;
@ -225,8 +227,7 @@ static void end_key(ge_GIF * gif)
gif->offset = gif->partial = 0;
}
static void
put_image(ge_GIF * gif, uint16_t w, uint16_t h, uint16_t x, uint16_t y)
static void put_image(ge_GIF * gif, uint16_t w, uint16_t h, uint16_t x, uint16_t y)
{
int nkeys, key_size, i, j;
Node *node, *child, *root;
@ -255,6 +256,7 @@ put_image(ge_GIF * gif, uint16_t w, uint16_t h, uint16_t x, uint16_t y)
for (j = x; j < x + w; j++)
{
uint8_t pixel = gif->frame[i * gif->w + j] & (degree - 1);
child = node->children[pixel];
if (child)
{
@ -286,11 +288,11 @@ put_image(ge_GIF * gif, uint16_t w, uint16_t h, uint16_t x, uint16_t y)
del_trie(root, degree);
}
static int
get_bbox(ge_GIF * gif, uint16_t * w, uint16_t * h, uint16_t * x, uint16_t * y)
static int get_bbox(ge_GIF * gif, uint16_t * w, uint16_t * h, uint16_t * x, uint16_t * y)
{
int i, j, k;
int left, right, top, bottom;
left = gif->w;
right = 0;
top = gif->h;

View file

@ -15,8 +15,7 @@ typedef struct ge_GIF
uint8_t buffer[0xFF];
} ge_GIF;
ge_GIF *ge_new_gif(const char *fname, uint16_t width, uint16_t height,
uint8_t * palette, int depth, int loop);
ge_GIF *ge_new_gif(const char *fname, uint16_t width, uint16_t height, uint8_t * palette, int depth, int loop);
void ge_add_frame(ge_GIF * gif, uint16_t delay);
void ge_close_gif(ge_GIF * gif);

View file

@ -64,16 +64,12 @@ static char *android_locale()
static char android_locale_buf[32];
JNIEnv *mEnv = Android_JNI_GetEnv();
jclass mLocaleClass = (*mEnv)->FindClass(mEnv, "java/util/Locale");
jmethodID mGetDefaultMethod =
(*mEnv)->GetStaticMethodID(mEnv, mLocaleClass, "getDefault",
"()Ljava/util/Locale;");
jobject mLocaleObject =
(*mEnv)->CallStaticObjectMethod(mEnv, mLocaleClass, mGetDefaultMethod);
jmethodID mToStringMethod =
(*mEnv)->GetMethodID(mEnv, mLocaleClass, "toString",
"()Ljava/lang/String;");
jstring mLocaleString =
(*mEnv)->CallObjectMethod(mEnv, mLocaleObject, mToStringMethod);
jmethodID mGetDefaultMethod = (*mEnv)->GetStaticMethodID(mEnv, mLocaleClass, "getDefault",
"()Ljava/util/Locale;");
jobject mLocaleObject = (*mEnv)->CallStaticObjectMethod(mEnv, mLocaleClass, mGetDefaultMethod);
jmethodID mToStringMethod = (*mEnv)->GetMethodID(mEnv, mLocaleClass, "toString",
"()Ljava/lang/String;");
jstring mLocaleString = (*mEnv)->CallObjectMethod(mEnv, mLocaleObject, mToStringMethod);
const char *locale = (*mEnv)->GetStringUTFChars(mEnv, mLocaleString, 0);
strcpy(android_locale_buf, locale);
@ -494,9 +490,7 @@ static void show_lang_usage(int exitcode)
const char *const prg = "tuxpaint";
/* FIXME: All this should REALLY be array-based!!! */
fprintf(f,
"\n" "Usage: %s [--lang LANGUAGE]\n" "\n"
"LANGUAGE may be one of:\n"
fprintf(f, "\n" "Usage: %s [--lang LANGUAGE]\n" "\n" "LANGUAGE may be one of:\n"
/* C */ " english american-english\n"
/* ach */ " acholi acoli\n"
/* af */ " afrikaans\n"
@ -774,8 +768,7 @@ static void show_locale_usage(FILE * f, const char *const prg)
" wa_BE (Walloon)\n"
" wo_SN (Wolof)\n"
" cy_GB (Welsh Cymraeg)\n"
" xh_ZA (Xhosa)\n" " zam (Zapoteco-Miahuatlan)\n"
" zu_ZA (Zulu)\n" "\n", prg);
" xh_ZA (Xhosa)\n" " zam (Zapoteco-Miahuatlan)\n" " zu_ZA (Zulu)\n" "\n", prg);
}
/**
@ -819,13 +812,12 @@ static void ctype_utf8(void)
#ifndef _WIN32
/* FIXME: should this iterate over more locales?
A zapotec speaker may have es_MX.UTF-8 available but not have en_US.UTF-8 for example */
const char *names[] =
{ "en_US.UTF8", "en_US.UTF-8", "UTF8", "UTF-8", "C.UTF-8" };
const char *names[] = { "en_US.UTF8", "en_US.UTF-8", "UTF8", "UTF-8", "C.UTF-8" };
int i = sizeof(names) / sizeof(names[0]);
for (;;)
{
if (iswprint((wchar_t) 0xf7)) // division symbol -- which is in Latin-1 :-/
if (iswprint((wchar_t)0xf7)) // division symbol -- which is in Latin-1 :-/
return;
if (--i < 0)
break;
@ -844,8 +836,7 @@ static void ctype_utf8(void)
*/
static const char *language_to_locale(const char *langstr)
{
int i =
sizeof language_to_locale_array / sizeof language_to_locale_array[0];
int i = sizeof language_to_locale_array / sizeof language_to_locale_array[0];
while (i--)
{
@ -871,8 +862,7 @@ static const char *language_to_locale(const char *langstr)
*/
static const char *locale_to_closest_locale(const char *inlocale)
{
const int numlocale =
sizeof(language_to_locale_array) / sizeof(language_to_locale_array[0]);
const int numlocale = sizeof(language_to_locale_array) / sizeof(language_to_locale_array[0]);
const char *outlocale = NULL;
int outlocale_score = 0;
int i = 0;
@ -883,8 +873,7 @@ static const char *locale_to_closest_locale(const char *inlocale)
{
const char *candidate = language_to_locale_array[i].locale;
for (j = 0; j < (int) strlen(inlocale) && j < (int) strlen(candidate);
j++)
for (j = 0; j < (int)strlen(inlocale) && j < (int)strlen(candidate); j++)
{
if (inlocale[j] != candidate[j])
break;
@ -964,8 +953,7 @@ static void set_langint_from_locale_string(const char *restrict loc)
for (i = 0; i < NUM_LANGS && found == 0; i++)
{
// Case-insensitive (both "pt_BR" and "pt_br" work, etc.)
if (len_baseloc == strlen(lang_prefixes[i])
&& !strncasecmp(straux, lang_prefixes[i], len_baseloc))
if (len_baseloc == strlen(lang_prefixes[i]) && !strncasecmp(straux, lang_prefixes[i], len_baseloc))
{
langint = i;
found = 1;
@ -980,8 +968,7 @@ static void set_langint_from_locale_string(const char *restrict loc)
for (i = 0; i < NUM_LANGS && found == 0; i++)
{
// Case-insensitive (both "pt_BR" and "pt_br" work, etc.)
if (len_baseloc == strlen(lang_prefixes[i])
&& !strncasecmp(straux, lang_prefixes[i], len_baseloc))
if (len_baseloc == strlen(lang_prefixes[i]) && !strncasecmp(straux, lang_prefixes[i], len_baseloc))
{
langint = i;
found = 1;
@ -1001,8 +988,7 @@ static void set_langint_from_locale_string(const char *restrict loc)
for (i = 0; i < NUM_LANGS && found == 0; i++)
{
// Case-insensitive (both "pt_BR" and "pt_br" work, etc.)
if (len_baseloc == strlen(lang_prefixes[i]) &&
!strncasecmp(straux, lang_prefixes[i], strlen(lang_prefixes[i])))
if (len_baseloc == strlen(lang_prefixes[i]) && !strncasecmp(straux, lang_prefixes[i], strlen(lang_prefixes[i])))
{
langint = i;
found = 1;
@ -1018,8 +1004,7 @@ static void set_langint_from_locale_string(const char *restrict loc)
for (i = 0; i < NUM_LANGS && found == 0; i++)
{
// Case-insensitive (both "pt_BR" and "pt_br" work, etc.)
if (len_baseloc == strlen(lang_prefixes[i])
&& !strncasecmp(baseloc, lang_prefixes[i], strlen(lang_prefixes[i])))
if (len_baseloc == strlen(lang_prefixes[i]) && !strncasecmp(baseloc, lang_prefixes[i], strlen(lang_prefixes[i])))
{
langint = i;
found = 1;
@ -1099,8 +1084,7 @@ void mysetenv(const char *name, const char *value)
* @return The Y-nudge value for font rendering in the language.
*/
static int set_current_language(const char *restrict loc,
int *ptr_num_wished_langs)
static int set_current_language(const char *restrict loc, int *ptr_num_wished_langs)
{
int i;
int j = 0;
@ -1137,8 +1121,7 @@ static int set_current_language(const char *restrict loc,
env = getenv("LC_MESSAGES");
if (env != NULL && env[0] != '\0')
{
DEBUG_PRINTF("Language via LC_MESSAGES: %s\n",
getenv("LC_MESSAGES"));
DEBUG_PRINTF("Language via LC_MESSAGES: %s\n", getenv("LC_MESSAGES"));
mysetenv("LANGUAGE", getenv("LC_MESSAGES"));
}
else
@ -1182,6 +1165,7 @@ static int set_current_language(const char *restrict loc,
// -- 2022/02/02: Shin-ichi TOYAMA & Pere Pujal i Carabantes
char curdir[256];
char f[512];
getcwd(curdir, sizeof(curdir));
snprintf(f, sizeof(f), "%s%s", curdir, "\\locale");
#ifdef DEBUG
@ -1255,12 +1239,9 @@ static int set_current_language(const char *restrict loc,
set_langint_from_locale_string(env_language_lang);
wished_langs[j].langint = langint;
wished_langs[j].lang_prefix = lang_prefixes[langint];
wished_langs[j].need_own_font =
search_int_array(langint, lang_use_own_font);
wished_langs[j].need_right_to_left =
search_int_array(langint, lang_use_right_to_left);
wished_langs[j].need_right_to_left_word =
search_int_array(langint, lang_use_right_to_left_word);
wished_langs[j].need_own_font = search_int_array(langint, lang_use_own_font);
wished_langs[j].need_right_to_left = search_int_array(langint, lang_use_right_to_left);
wished_langs[j].need_right_to_left_word = search_int_array(langint, lang_use_right_to_left_word);
for (i = 0; lang_y_nudge[i][0] != -1; i++)
{
// printf("lang_y_nudge[%d][0] = %d\n", i, lang_y_nudge[i][0]);
@ -1294,15 +1275,13 @@ static int set_current_language(const char *restrict loc,
#ifdef DEBUG
fprintf(stderr, "DEBUG: Language is %s (%d) %s/%s\n",
lang_prefix, langint, need_right_to_left ? "(RTL)" : "",
need_right_to_left_word ? "(RTL words)" : "");
lang_prefix, langint, need_right_to_left ? "(RTL)" : "", need_right_to_left_word ? "(RTL words)" : "");
fflush(stderr);
#endif
free(oldloc);
DEBUG_PRINTF("lang_prefixes[%d] is \"%s\"\n", get_current_language(),
lang_prefixes[get_current_language()]);
DEBUG_PRINTF("lang_prefixes[%d] is \"%s\"\n", get_current_language(), lang_prefixes[get_current_language()]);
*ptr_num_wished_langs = num_wished_langs;
@ -1321,8 +1300,7 @@ static int set_current_language(const char *restrict loc,
* @param int * a place to return the number of languages we want to use, when scanning stamp descriptions
* @return Y-nudge
*/
int setup_i18n(const char *restrict lang, const char *restrict locale,
int *num_wished_langs)
int setup_i18n(const char *restrict lang, const char *restrict locale, int *num_wished_langs)
{
DEBUG_PRINTF("lang %p, locale %p\n", lang, locale);
DEBUG_PRINTF("lang \"%s\", locale \"%s\"\n", lang, locale);
@ -1364,6 +1342,7 @@ int setup_i18n(const char *restrict lang, const char *restrict locale,
int smash_i18n(void)
{
int tmp;
return set_current_language("C", &tmp);
}
#endif

View file

@ -206,9 +206,8 @@ extern w_langs wished_langs[255];
/* Function prototypes: */
int get_current_language(void);
int setup_i18n(const char *restrict lang, const char *restrict locale,
int *ptr_num_wished_languages) MUST_CHECK;
void mysetenv(const char *name, const char *value);
int setup_i18n(const char *restrict lang, const char *restrict locale, int *ptr_num_wished_languages) MUST_CHECK;
void mysetenv(const char *name, const char *value);
#ifdef NO_SDLPANGO
int smash_i18n(void) MUST_CHECK;

View file

@ -258,7 +258,7 @@ static void wcs_lshift(wchar_t *s, size_t count)
*/
static void wcs_pull(wchar_t *s, size_t count)
{
int peg = (int) wcslen(s) - (int) count;
int peg = (int)wcslen(s) - (int)count;
if (peg < 0)
peg = 0;
@ -311,7 +311,7 @@ static void sm_free(STATE_MACHINE * sm)
{
int i = 0;
for (i = 0; i < (int) sm->next_maxsize; i++)
for (i = 0; i < (int)sm->next_maxsize; i++)
{
STATE_MACHINE *next_state = sm->next[i].state;
@ -358,8 +358,7 @@ static STATE_MACHINE *sm_search_shallow(STATE_MACHINE * sm, char key)
SM_WITH_KEY smk = { key, NULL };
SM_WITH_KEY *smk_found;
smk_found =
bsearch(&smk, sm->next, sm->next_size, sizeof(SM_WITH_KEY), swk_compare);
smk_found = bsearch(&smk, sm->next, sm->next_size, sizeof(SM_WITH_KEY), swk_compare);
if (!smk_found)
return NULL;
@ -381,10 +380,9 @@ static STATE_MACHINE *sm_search_shallow(STATE_MACHINE * sm, char key)
* @return Found unicode character sequence output of the last state.
*/
static const wchar_t *sm_search(STATE_MACHINE * start, wchar_t *key,
int *matched, STATE_MACHINE ** penult,
STATE_MACHINE ** end)
int *matched, STATE_MACHINE ** penult, STATE_MACHINE ** end)
{
STATE_MACHINE *sm = sm_search_shallow(start, (char) *key);
STATE_MACHINE *sm = sm_search_shallow(start, (char)*key);
const wchar_t *unicode;
/* No match - stop recursion */
@ -418,8 +416,7 @@ static void sm_sort_shallow(STATE_MACHINE * sm)
/**
* Add a single sequence-to-unicode path to the state machine.
*/
static int sm_add(STATE_MACHINE * sm, char *seq, const wchar_t *unicode,
char flag)
static int sm_add(STATE_MACHINE * sm, char *seq, const wchar_t *unicode, char flag)
{
STATE_MACHINE *sm_found = sm_search_shallow(sm, seq[0]);
@ -432,10 +429,10 @@ static int sm_add(STATE_MACHINE * sm, char *seq, const wchar_t *unicode,
fprintf(stderr, "Unicode sequence ");
for (i = 0; i < wcslen(sm->output); i++)
fprintf(stderr, "%04X ", (int) sm->output[i]);
fprintf(stderr, "%04X ", (int)sm->output[i]);
fprintf(stderr, " already defined, overriding with ");
for (i = 0; i < wcslen(unicode); i++)
fprintf(stderr, "%04X ", (int) unicode[i]);
fprintf(stderr, "%04X ", (int)unicode[i]);
fprintf(stderr, "\n");
}
wcscpy(sm->output, unicode);
@ -446,7 +443,7 @@ static int sm_add(STATE_MACHINE * sm, char *seq, const wchar_t *unicode,
/* The key doesn't exist yet */
if (!sm_found)
{
int index = (int) sm->next_size;
int index = (int)sm->next_size;
SM_WITH_KEY *next = &sm->next[index];
/* Add the key */
@ -516,8 +513,7 @@ static int charmap_init(CHARMAP * cm)
*
* @return 0 if no error, 1 if error.
*/
static int charmap_add(CHARMAP * cm, int section, char *seq,
const wchar_t *unicode, char *flag)
static int charmap_add(CHARMAP * cm, int section, char *seq, const wchar_t *unicode, char *flag)
{
if (section >= MAX_SECTIONS)
{
@ -528,7 +524,7 @@ static int charmap_add(CHARMAP * cm, int section, char *seq,
/* For now, we only utilize one-character flags */
if (strlen(flag) > 1)
{
fprintf(stderr, "%04X: Multi-character flag, truncated.\n", (int) (intptr_t) unicode); //EP added (intptr_t) to avoid warning on x64
fprintf(stderr, "%04X: Multi-character flag, truncated.\n", (int)(intptr_t) unicode); //EP added (intptr_t) to avoid warning on x64
}
return sm_add(&cm->sections[section], seq, unicode, flag[0]);
@ -635,7 +631,7 @@ static int charmap_load(CHARMAP * cm, const char *path)
fwprintf(stderr, L"Unable to add sequence '%ls', unicode ", buf);
for (i = 0; i < wcslen(unicode); i++)
fwprintf(stderr, L"%04X ", (int) unicode[i]);
fwprintf(stderr, L"%04X ", (int)unicode[i]);
fwprintf(stderr, L"in section %d\n", section);
#endif
#endif
@ -679,15 +675,13 @@ static const wchar_t *charmap_search(CHARMAP * cm, wchar_t *s)
/* Determine the starting state based on the charmap's active section */
section = cm->section;
if (!IN_RANGE(0, section, (int) ARRAYLEN(cm->sections)))
if (!IN_RANGE(0, section, (int)ARRAYLEN(cm->sections)))
section = 0;
start = &cm->sections[section];
cm->match_state = NULL;
cm->match_state_prev = NULL;
unicode =
sm_search(start, s, &cm->match_count, &cm->match_state_prev,
&cm->match_state);
unicode = sm_search(start, s, &cm->match_count, &cm->match_state_prev, &cm->match_state);
/**
* Determine whether the match is final. A match is considered to be final
@ -701,7 +695,7 @@ static const wchar_t *charmap_search(CHARMAP * cm, wchar_t *s)
* final state we possibly can.
*/
cm->match_is_final = 0;
if (cm->match_count < (int) wcslen(s))
if (cm->match_count < (int)wcslen(s))
{
cm->match_is_final = 1;
}
@ -713,7 +707,7 @@ static const wchar_t *charmap_search(CHARMAP * cm, wchar_t *s)
cm->match_is_final = 1;
cm->match_stats |= MATCH_STAT_NOMOSTATES;
}
if (cm->match_count == (int) wcslen(s))
if (cm->match_count == (int)wcslen(s))
{
cm->match_stats |= MATCH_STAT_NOMOBUF;
}
@ -830,8 +824,7 @@ int im_read(IM_DATA * im, SDL_Event event)
redraw = im_event_c(im, event);
#ifdef IM_DEBUG
wprintf(L"* [%8ls] [%8ls] %2d %2d (%2d)\n", im->s, im->buf, wcslen(im->s),
wcslen(im->buf), im->redraw);
wprintf(L"* [%8ls] [%8ls] %2d %2d (%2d)\n", im->s, im->buf, wcslen(im->s), wcslen(im->buf), im->redraw);
#endif
return redraw;
@ -983,8 +976,7 @@ static int im_event_zh_tw(IM_DATA * im, SDL_Event event)
if (charmap_load(&cm, lang_file))
{
fprintf(stderr, "Unable to load %s, defaulting to im_event_c\n",
lang_file);
fprintf(stderr, "Unable to load %s, defaulting to im_event_c\n", lang_file);
im->lang = LANG_DEFAULT;
return im_event_c(im, event);
}
@ -1001,7 +993,7 @@ static int im_event_zh_tw(IM_DATA * im, SDL_Event event)
/* Discard redraw characters, so they can be redrawn */
if ((int) wcslen(im->s) < im->redraw)
if ((int)wcslen(im->s) < im->redraw)
im->redraw = wcslen(im->s);
wcs_lshift(im->s, (wcslen(im->s) - im->redraw));
@ -1055,8 +1047,7 @@ static int im_event_zh_tw(IM_DATA * im, SDL_Event event)
/* Actual character processing */
default:
if (event.type == SDL_TEXTINPUT || ks.sym == SDLK_BACKSPACE
|| ks.sym == SDLK_RETURN || ks.sym == SDLK_TAB)
if (event.type == SDL_TEXTINPUT || ks.sym == SDLK_BACKSPACE || ks.sym == SDLK_RETURN || ks.sym == SDLK_TAB)
{
/* English mode */
if (cm.section == SEC_ENGLISH)
@ -1081,8 +1072,7 @@ static int im_event_zh_tw(IM_DATA * im, SDL_Event event)
const wchar_t *us = charmap_search(&cm, im->buf);
#ifdef IM_DEBUG
wprintf(L" [%8ls] [%8ls] %2d %2d\n", im->s, im->buf, wcslen(im->s),
wcslen(im->buf));
wprintf(L" [%8ls] [%8ls] %2d %2d\n", im->s, im->buf, wcslen(im->s), wcslen(im->buf));
#endif
/* Match was found? */
@ -1122,7 +1112,7 @@ static int im_event_zh_tw(IM_DATA * im, SDL_Event event)
cm.match_is_final = 0;
}
/* If the matched characters didn't consume all, it's own state */
else if ((size_t) cm.match_count != wcslen(im->buf))
else if ((size_t)cm.match_count != wcslen(im->buf))
{
#ifdef IM_DEBUG
wprintf(L" 2b (%2d)\n", cm.match_count);
@ -1209,8 +1199,7 @@ static int im_event_th(IM_DATA * im, SDL_Event event)
if (charmap_load(&cm, lang_file))
{
fprintf(stderr, "Unable to load %s, defaulting to im_event_c\n",
lang_file);
fprintf(stderr, "Unable to load %s, defaulting to im_event_c\n", lang_file);
im->lang = LANG_DEFAULT;
return im_event_c(im, event);
}
@ -1227,7 +1216,7 @@ static int im_event_th(IM_DATA * im, SDL_Event event)
/* Discard redraw characters, so they can be redrawn */
if ((int) wcslen(im->s) < im->redraw)
if ((int)wcslen(im->s) < im->redraw)
im->redraw = wcslen(im->s);
wcs_lshift(im->s, (wcslen(im->s) - im->redraw));
@ -1304,8 +1293,7 @@ static int im_event_th(IM_DATA * im, SDL_Event event)
const wchar_t *us = charmap_search(&cm, im->buf);
#ifdef IM_DEBUG
wprintf(L" [%8ls] [%8ls] %2d %2d\n", im->s, im->buf, wcslen(im->s),
wcslen(im->buf));
wprintf(L" [%8ls] [%8ls] %2d %2d\n", im->s, im->buf, wcslen(im->s), wcslen(im->buf));
#endif
/* Match was found? */
@ -1345,7 +1333,7 @@ static int im_event_th(IM_DATA * im, SDL_Event event)
cm.match_is_final = 0;
}
/* If the matched characters didn't consume all, it's own state */
else if ((size_t) cm.match_count != wcslen(im->buf))
else if ((size_t)cm.match_count != wcslen(im->buf))
{
#ifdef IM_DEBUG
wprintf(L" 2b (%2d)\n", cm.match_count);
@ -1431,8 +1419,7 @@ static int im_event_ja(IM_DATA * im, SDL_Event event)
if (charmap_load(&cm, lang_file))
{
fprintf(stderr, "Unable to load %s, defaulting to im_event_c\n",
lang_file);
fprintf(stderr, "Unable to load %s, defaulting to im_event_c\n", lang_file);
im->lang = LANG_DEFAULT;
return im_event_c(im, event);
}
@ -1449,7 +1436,7 @@ static int im_event_ja(IM_DATA * im, SDL_Event event)
/* Discard redraw characters, so they can be redrawn */
if ((int) wcslen(im->s) < im->redraw)
if ((int)wcslen(im->s) < im->redraw)
im->redraw = wcslen(im->s);
wcs_lshift(im->s, (wcslen(im->s) - im->redraw));
@ -1506,8 +1493,7 @@ static int im_event_ja(IM_DATA * im, SDL_Event event)
/* Actual character processing */
default:
if (event.type == SDL_TEXTINPUT || ks.sym == SDLK_BACKSPACE
|| ks.sym == SDLK_RETURN || ks.sym == SDLK_TAB)
if (event.type == SDL_TEXTINPUT || ks.sym == SDLK_BACKSPACE || ks.sym == SDLK_RETURN || ks.sym == SDLK_TAB)
{
/* English mode */
if (cm.section == SEC_ENGLISH)
@ -1532,8 +1518,7 @@ static int im_event_ja(IM_DATA * im, SDL_Event event)
const wchar_t *us = charmap_search(&cm, im->buf);
#ifdef IM_DEBUG
wprintf(L" [%8ls] [%8ls] %2d %2d\n", im->s, im->buf, wcslen(im->s),
wcslen(im->buf));
wprintf(L" [%8ls] [%8ls] %2d %2d\n", im->s, im->buf, wcslen(im->s), wcslen(im->buf));
#endif
/* Match was found? */
@ -1573,7 +1558,7 @@ static int im_event_ja(IM_DATA * im, SDL_Event event)
cm.match_is_final = 0;
}
/* If the matched characters didn't consume all, it's own state */
else if ((size_t) cm.match_count != wcslen(im->buf))
else if ((size_t)cm.match_count != wcslen(im->buf))
{
#ifdef IM_DEBUG
wprintf(L" 2b (%2d)\n", cm.match_count);
@ -1628,15 +1613,14 @@ static int im_event_ko_isvowel(CHARMAP * cm, wchar_t c)
/* Determine the starting state based on the charmap's active section */
section = cm->section;
if (!IN_RANGE(0, section, (int) ARRAYLEN(cm->sections)))
if (!IN_RANGE(0, section, (int)ARRAYLEN(cm->sections)))
section = 0;
start = &cm->sections[section];
next = sm_search_shallow(start, (char) c);
next = sm_search_shallow(start, (char)c);
unicode = next ? next->output : NULL;
return (unicode && wcslen(unicode) == 1 && 0x314F <= unicode[0]
&& unicode[0] <= 0x3163);
return (unicode && wcslen(unicode) == 1 && 0x314F <= unicode[0] && unicode[0] <= 0x3163);
}
@ -1685,8 +1669,7 @@ static int im_event_ko(IM_DATA * im, SDL_Event event)
if (charmap_load(&cm, lang_file))
{
fprintf(stderr, "Unable to load %s, defaulting to im_event_c\n",
lang_file);
fprintf(stderr, "Unable to load %s, defaulting to im_event_c\n", lang_file);
im->lang = LANG_DEFAULT;
return im_event_c(im, event);
}
@ -1703,7 +1686,7 @@ static int im_event_ko(IM_DATA * im, SDL_Event event)
/* Discard redraw characters, so they can be redrawn */
if ((int) wcslen(im->s) < im->redraw)
if ((int)wcslen(im->s) < im->redraw)
im->redraw = wcslen(im->s);
wcs_lshift(im->s, (wcslen(im->s) - im->redraw));
@ -1758,8 +1741,7 @@ static int im_event_ko(IM_DATA * im, SDL_Event event)
/* Actual character processing */
default:
if (event.type == SDL_TEXTINPUT || ks.sym == SDLK_BACKSPACE
|| ks.sym == SDLK_RETURN || ks.sym == SDLK_TAB)
if (event.type == SDL_TEXTINPUT || ks.sym == SDLK_BACKSPACE || ks.sym == SDLK_RETURN || ks.sym == SDLK_TAB)
{
/* English mode */
if (cm.section == SEC_ENGLISH)
@ -1783,8 +1765,7 @@ static int im_event_ko(IM_DATA * im, SDL_Event event)
const wchar_t *us = charmap_search(&cm, bp);
#ifdef IM_DEBUG
wprintf(L" [%8ls] [%8ls] %2d %2d\n", im->s, im->buf, wcslen(im->s),
wcslen(im->buf));
wprintf(L" [%8ls] [%8ls] %2d %2d\n", im->s, im->buf, wcslen(im->s), wcslen(im->buf));
#endif
/* Match was found? */
@ -1876,7 +1857,7 @@ static int im_event_ko(IM_DATA * im, SDL_Event event)
cm.match_is_final = 0;
}
/* If the matched characters didn't consume all, it's own state */
else if ((size_t) cm.match_count != wcslen(bp))
else if ((size_t)cm.match_count != wcslen(bp))
{
#ifdef IM_DEBUG
wprintf(L" 2b (%2d)\n", cm.match_count);

16
src/indent.sh Executable file
View file

@ -0,0 +1,16 @@
#!/bin/bash
# Indent Tux Paint source files
echo "Indenting src/*.c"
find . -name "*.c" -exec indent -nbfda -npcs -npsl -bli0 --no-tabs {} \;
echo "Indenting src/*.h"
find . -name "*.h" -exec indent -nbfda -npcs -npsl -bli0 --no-tabs {} \;
echo "Indenting magic/src/*.c"
find ../magic/src/ -name "*.c" -exec indent -nbfda -npcs -npsl -bli0 --no-tabs {} \;
echo "Indenting magic/src/*.h"
find ../magic/src/ -name "*.h" -exec indent -nbfda -npcs -npsl -bli0 --no-tabs {} \;

View file

@ -61,8 +61,7 @@ static void draw_keyboard(on_screen_keyboard * keyboard);
static osk_key *find_key(on_screen_keyboard * keyboard, int x, int y);
static void set_key(osk_key * orig, osk_key * dest, int firsttime);
static void load_keysymdefs(osk_layout * layout, char *keysymdefs_name);
static struct osk_layout *load_layout(on_screen_keyboard * keyboard,
char *layout_name);
static struct osk_layout *load_layout(on_screen_keyboard * keyboard, char *layout_name);
#ifdef DEBUG_OSK_COMPOSEMAP
static void print_composemap(osk_composenode * composemap, char *sp);
@ -91,9 +90,7 @@ struct osk_keyboard *osk_create(char *layout_name, SDL_Surface * canvas,
SDL_Surface * BLANK_oskdel,
SDL_Surface * BLANK_osktab,
SDL_Surface * BLANK_oskenter,
SDL_Surface * BLANK_oskcapslock,
SDL_Surface * BLANK_oskshift,
int disable_change)
SDL_Surface * BLANK_oskcapslock, SDL_Surface * BLANK_oskshift, int disable_change)
{
SDL_Surface *surface;
SDL_Surface *button_up, *button_down;
@ -113,8 +110,7 @@ struct osk_keyboard *osk_create(char *layout_name, SDL_Surface * canvas,
layout = load_layout(keyboard, layout_name);
if (!layout)
{
fprintf(stderr, "Error trying to load the required layout %s\n",
layout_name);
fprintf(stderr, "Error trying to load the required layout %s\n", layout_name);
layout = load_layout(keyboard, strdup("default.layout"));
if (!layout)
{
@ -142,17 +138,15 @@ struct osk_keyboard *osk_create(char *layout_name, SDL_Surface * canvas,
#ifdef OSK_DEBUG
printf
("%d x %d layout of %d x %d buttons won't fit within %d x %d pixel area...\n",
layout->width, layout->height, BLANK_button_up->w, BLANK_button_up->h,
layout_avail_width, layout_avail_height);
layout->width, layout->height, BLANK_button_up->w, BLANK_button_up->h, layout_avail_width, layout_avail_height);
#endif
max_w = (float) layout_avail_width / (float) layout->width;
max_h = (float) layout_avail_height / (float) layout->height;
max_w = (float)layout_avail_width / (float)layout->width;
max_h = (float)layout_avail_height / (float)layout->height;
#ifdef OSK_DEBUG
printf("...want (%d / %d) x (%d x %d) = %.2f x %.2f buttons...\n",
layout_avail_width, layout->width,
layout_avail_height, layout->height, max_w, max_h);
layout_avail_width, layout->width, layout_avail_height, layout->height, max_w, max_h);
#endif
if (max_w > max_h)
@ -160,8 +154,8 @@ struct osk_keyboard *osk_create(char *layout_name, SDL_Surface * canvas,
if (max_h > max_w)
max_h = max_w;
scale_w = (float) max_w / (float) BLANK_button_up->w;
scale_h = (float) max_h / (float) BLANK_button_up->h;
scale_w = (float)max_w / (float)BLANK_button_up->w;
scale_h = (float)max_h / (float)BLANK_button_up->h;
#ifdef OSK_DEBUG
printf("...so scaling by w=%.2f & h=%.2f\n", scale_w, scale_h);
@ -196,8 +190,7 @@ struct osk_keyboard *osk_create(char *layout_name, SDL_Surface * canvas,
layout->width * button_up->w,
layout->height * button_up->h,
canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask,
canvas->format->Bmask, 0);
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, 0);
if (!surface)
{
fprintf(stderr, "Error creating the onscreen keyboard surface\n");
@ -251,8 +244,7 @@ struct osk_keyboard *osk_create(char *layout_name, SDL_Surface * canvas,
SDL_FillRect(surface, NULL,
SDL_MapRGB(surface->format, keyboard->layout->bgcolor.r,
keyboard->layout->bgcolor.g,
keyboard->layout->bgcolor.b));
keyboard->layout->bgcolor.g, keyboard->layout->bgcolor.b));
keybd_prepare(keyboard);
@ -260,8 +252,7 @@ struct osk_keyboard *osk_create(char *layout_name, SDL_Surface * canvas,
return keyboard;
}
static struct osk_layout *load_layout(on_screen_keyboard * keyboard,
char *layout_name)
static struct osk_layout *load_layout(on_screen_keyboard * keyboard, char *layout_name)
{
FILE *fi;
int hlayout_loaded;
@ -303,8 +294,7 @@ static struct osk_layout *load_layout(on_screen_keyboard * keyboard,
fi = fopen(filename, "r");
if (fi == NULL)
{
fprintf(stderr, "Can't open either %s nor %s\n", layout_name,
filename);
fprintf(stderr, "Can't open either %s nor %s\n", layout_name, filename);
/* Fallback to default */
snprintf(filename, 255, "%sosk/default.layout", DATA_PREFIX);
fi = fopen(filename, "r");
@ -424,8 +414,7 @@ void load_hlayout(osk_layout * layout, char *hlayout_name)
fi = fopen(filename, "r");
if (fi == NULL)
{
fprintf(stderr, "Can't open either %s nor %s\n", hlayout_name,
filename);
fprintf(stderr, "Can't open either %s nor %s\n", hlayout_name, filename);
layout->keys = NULL;
free(filename);
return;
@ -534,8 +523,7 @@ void load_hlayout(osk_layout * layout, char *hlayout_name)
layout->keys[line_number][i].shift_altgr_label = NULL;
}
}
else if (width && height && allocated && strncmp(line, "KEY ", 4) == 0
&& key_number < width)
else if (width && height && allocated && strncmp(line, "KEY ", 4) == 0 && key_number < width)
{
plain_label = malloc(sizeof(char) * 64);
top_label = malloc(sizeof(char) * 64);
@ -546,17 +534,14 @@ void load_hlayout(osk_layout * layout, char *hlayout_name)
"%s %i %i.%i %s %s %s %s %i",
key,
&keycode,
&key_width, &key_width_decimal, plain_label, top_label,
altgr_label, shift_altgr_label, &shiftcaps);
&key_width, &key_width_decimal, plain_label, top_label, altgr_label, shift_altgr_label, &shiftcaps);
layout->keys[line_number][key_number].keycode = keycode;
layout->keys[line_number][key_number].width =
(float) 0.1 *key_width_decimal + key_width;
layout->keys[line_number][key_number].width = (float)0.1 *key_width_decimal + key_width;
layout->keys[line_number][key_number].plain_label = plain_label;
layout->keys[line_number][key_number].top_label = top_label;
layout->keys[line_number][key_number].altgr_label = altgr_label;
layout->keys[line_number][key_number].shift_altgr_label =
shift_altgr_label;
layout->keys[line_number][key_number].shift_altgr_label = shift_altgr_label;
layout->keys[line_number][key_number].shiftcaps = shiftcaps;
layout->keys[line_number][key_number].stick = 0;
key_number++;
@ -653,9 +638,7 @@ void load_keymap(osk_layout * layout, char *keymap_name)
/* FIXME: Why is the us-intl keymap duplicating the two first entries of every keycode? */
/* And why is the arabic keymap using the 5th and 6th entries as plain/shifted keys? */
readed =
sscanf(line, "keycode %i = %s %s %s %s", &keycode, ksname1, ksname2,
ksname3, ksname4);
readed = sscanf(line, "keycode %i = %s %s %s %s", &keycode, ksname1, ksname2, ksname3, ksname4);
if (readed == 5 && keycode > 8 && keycode < 256)
{
@ -695,8 +678,7 @@ void load_keymap(osk_layout * layout, char *keymap_name)
}
/* Scans a line of keysyms and result and classifies them. */
static void gettokens(char *line, char *delim, char **pointer,
osk_composenode * composenode, osk_layout * layout)
static void gettokens(char *line, char *delim, char **pointer, osk_composenode * composenode, osk_layout * layout)
{
int i;
char *tok;
@ -763,9 +745,7 @@ static void gettokens(char *line, char *delim, char **pointer,
}
composenode->size = composenode->size + 1;
composenode->childs =
realloc(composenode->childs,
composenode->size * sizeof(osk_composenode *));
composenode->childs = realloc(composenode->childs, composenode->size * sizeof(osk_composenode *));
mbstowcs(wtok, tok, 255);
auxnode = malloc(sizeof(osk_composenode));
@ -776,8 +756,7 @@ static void gettokens(char *line, char *delim, char **pointer,
/* printf("size %d, keysym %ls =>", composenode->size, composenode->childs[composenode->size - 1]->keysym); */
gettokens(NULL, delim, pointer,
composenode->childs[composenode->size - 1], layout);
gettokens(NULL, delim, pointer, composenode->childs[composenode->size - 1], layout);
free(tok);
return;
}
@ -808,8 +787,7 @@ static void load_composemap(osk_layout * layout, char *composemap_name)
fi = fopen(filename, "r");
if (fi == NULL)
{
fprintf(stderr, "Can't open either %s nor %s\n", composemap_name,
filename);
fprintf(stderr, "Can't open either %s nor %s\n", composemap_name, filename);
layout->keys = NULL;
free(filename);
return;
@ -832,7 +810,7 @@ static void load_composemap(osk_layout * layout, char *composemap_name)
if (is_blank_or_comment(line))
continue;
gettokens(line, (char *) ">< \t", pointer, layout->composemap, layout);
gettokens(line, (char *)">< \t", pointer, layout->composemap, layout);
}
fclose(fi);
@ -917,8 +895,7 @@ static void load_keysymdefs(osk_layout * layout, char *keysymdefs_name)
fi = fopen(filename, "r");
if (fi == NULL)
{
fprintf(stderr, "Can't open either %s nor %s\n", keysymdefs_name,
filename);
fprintf(stderr, "Can't open either %s nor %s\n", keysymdefs_name, filename);
layout->keysymdefs = NULL;
free(filename);
return;
@ -939,15 +916,13 @@ static void load_keysymdefs(osk_layout * layout, char *keysymdefs_name)
continue;
layout->sizeofkeysymdefs = i;
layout->keysymdefs =
realloc(layout->keysymdefs, sizeof(keysymdefs) * (i + 1));
layout->keysymdefs = realloc(layout->keysymdefs, sizeof(keysymdefs) * (i + 1));
/* Some keysyms doesn't correspond to any unicode value, ej. BackSpace */
layout->keysymdefs[i].unicode = 0;
layout->keysymdefs[i].mnemo = malloc(sizeof(char) * 128);
sscanf(line, "#define XK_%s %x /* U+%x",
layout->keysymdefs[i].mnemo, &layout->keysymdefs[i].keysym,
&layout->keysymdefs[i].unicode);
layout->keysymdefs[i].mnemo, &layout->keysymdefs[i].keysym, &layout->keysymdefs[i].unicode);
i++;
}
@ -1004,8 +979,7 @@ static int keysym2unicode(int keysym, on_screen_keyboard * keyboard)
* This software is in the public domain. Share and enjoy!
*/
/* first check for Latin-1 characters (1:1 mapping) */
if ((keysym >= 0x0020 && keysym <= 0x007e)
|| (keysym >= 0x00a0 && keysym <= 0x00ff))
if ((keysym >= 0x0020 && keysym <= 0x007e) || (keysym >= 0x00a0 && keysym <= 0x00ff))
return keysym;
/* also check for directly encoded 24-bit UCS characters */
@ -1023,9 +997,7 @@ static int keysym2unicode(int keysym, on_screen_keyboard * keyboard)
/* Searches in the tree for composing stuff */
static void get_composed_keysym(on_screen_keyboard * keyboard,
osk_composenode * composenode,
wchar_t *keysym)
static void get_composed_keysym(on_screen_keyboard * keyboard, osk_composenode * composenode, wchar_t *keysym)
{
int i;
@ -1145,43 +1117,37 @@ static void keybd_prepare(on_screen_keyboard * keyboard)
if (keyboard->layout->fontpath)
{
/* First try if it is an absolute path */
keyboard->osk_fonty =
TTF_OpenFont(keyboard->layout->fontpath, font_height);
keyboard->osk_fonty = TTF_OpenFont(keyboard->layout->fontpath, font_height);
if (keyboard->osk_fonty == NULL)
{
/* Now trying if it is relative to DATA_PREFIX/fonts/ */
snprintf(fontname, 255, "%s/fonts/%s", DATA_PREFIX,
keyboard->layout->fontpath);
snprintf(fontname, 255, "%s/fonts/%s", DATA_PREFIX, keyboard->layout->fontpath);
keyboard->osk_fonty = TTF_OpenFont(fontname, font_height);
if (keyboard->osk_fonty == NULL)
{
/* Perhaps it is relative to DATA_PREFIX only? */
snprintf(fontname, 255, "%s/%s", DATA_PREFIX,
keyboard->layout->fontpath);
snprintf(fontname, 255, "%s/%s", DATA_PREFIX, keyboard->layout->fontpath);
keyboard->osk_fonty = TTF_OpenFont(fontname, font_height);
if (keyboard->osk_fonty == NULL)
{
/* Or to DATA_PREFIX/fonts/locale/ ? */
snprintf(fontname, 255, "%s/fonts/locale/%s", DATA_PREFIX,
keyboard->layout->fontpath);
snprintf(fontname, 255, "%s/fonts/locale/%s", DATA_PREFIX, keyboard->layout->fontpath);
keyboard->osk_fonty = TTF_OpenFont(fontname, font_height);
if (keyboard->osk_fonty == NULL)
{
/* Fonts are in assets "data" dir in Android builds */
snprintf(fontname, 255, "data/fonts/%s",
keyboard->layout->fontpath);
keyboard->osk_fonty = TTF_OpenFont(fontname, font_height);
if (keyboard->osk_fonty == NULL)
{
/* Fonts are in assets "data" dir in Android builds, checking locale dir */
snprintf(fontname, 255, "data/fonts/locale/%s",
keyboard->layout->fontpath);
keyboard->osk_fonty = TTF_OpenFont(fontname, font_height);
}
}
}
}
if (keyboard->osk_fonty == NULL)
{
/* Fonts are in assets "data" dir in Android builds */
snprintf(fontname, 255, "data/fonts/%s", keyboard->layout->fontpath);
keyboard->osk_fonty = TTF_OpenFont(fontname, font_height);
if (keyboard->osk_fonty == NULL)
{
/* Fonts are in assets "data" dir in Android builds, checking locale dir */
snprintf(fontname, 255, "data/fonts/locale/%s", keyboard->layout->fontpath);
keyboard->osk_fonty = TTF_OpenFont(fontname, font_height);
}
}
}
}
}
}
@ -1193,17 +1159,16 @@ static void keybd_prepare(on_screen_keyboard * keyboard)
if (keyboard->osk_fonty == NULL)
{
/* Also for Android */
sprintf(fontname, "data/fonts/FreeSansBold.ttf");
keyboard->osk_fonty = TTF_OpenFont(fontname, font_height);
/* Also for Android */
sprintf(fontname, "data/fonts/FreeSansBold.ttf");
keyboard->osk_fonty = TTF_OpenFont(fontname, font_height);
}
}
if (keyboard->osk_fonty == NULL)
{
fprintf(stderr, "\nError: Can't open the font!\n"
"The Simple DirectMedia Layer error that occurred was:\n"
"%s\n\n", SDL_GetError());
"The Simple DirectMedia Layer error that occurred was:\n" "%s\n\n", SDL_GetError());
free(fontname);
exit(1);
}
@ -1213,8 +1178,7 @@ static void keybd_prepare(on_screen_keyboard * keyboard)
}
static void apply_surface(int x, int y, SDL_Surface * source,
SDL_Surface * destination, SDL_Rect * clip)
static void apply_surface(int x, int y, SDL_Surface * source, SDL_Surface * destination, SDL_Rect * clip)
{
SDL_Rect offset;
@ -1266,8 +1230,7 @@ static SDL_Surface *stretch_surface(SDL_Surface * orig, int width)
width,
orig->h,
orig->format->BitsPerPixel,
orig->format->Rmask, orig->format->Gmask,
orig->format->Bmask, 0);
orig->format->Rmask, orig->format->Gmask, orig->format->Bmask, 0);
SDL_BlitSurface(orig, NULL, dest, NULL);
rect.y = 0;
@ -1359,38 +1322,26 @@ static void draw_key(osk_key key, on_screen_keyboard * keyboard, int hot)
if (strncmp("NULL", text, 4) != 0 && key.keycode != 0)
{
if (hot)
skey =
stretch_surface(keyboard->button_down,
key.width * keyboard->button_down->w);
skey = stretch_surface(keyboard->button_down, key.width * keyboard->button_down->w);
else if (key.stick)
skey =
stretch_surface(keyboard->button_hold,
key.width * keyboard->button_hold->w);
skey = stretch_surface(keyboard->button_hold, key.width * keyboard->button_hold->w);
else
{
if (key.keycode == 1 || key.keycode == 2)
{
if (keyboard->disable_change)
skey =
stretch_surface(keyboard->button_off,
key.width * keyboard->button_off->w);
skey = stretch_surface(keyboard->button_off, key.width * keyboard->button_off->w);
else
skey =
stretch_surface(keyboard->button_nav,
key.width * keyboard->button_nav->w);
skey = stretch_surface(keyboard->button_nav, key.width * keyboard->button_nav->w);
}
else
skey =
stretch_surface(keyboard->button_up,
key.width * keyboard->button_up->w);
skey = stretch_surface(keyboard->button_up, key.width * keyboard->button_up->w);
}
}
else
skey =
stretch_surface(keyboard->button_off,
key.width * keyboard->button_off->w);
skey = stretch_surface(keyboard->button_off, key.width * keyboard->button_off->w);
apply_surface(key.x, key.y, skey, keyboard->surface, NULL);
@ -1452,8 +1403,7 @@ static void label_key(osk_key key, on_screen_keyboard * keyboard)
}
}
else if (modstate & KMOD_RALT && modstate & KMOD_CAPS
&& !(modstate & KMOD_SHIFT))
else if (modstate & KMOD_RALT && modstate & KMOD_CAPS && !(modstate & KMOD_SHIFT))
{
if (key.shiftcaps)
text = strdup(key.shift_altgr_label);
@ -1486,8 +1436,7 @@ static void label_key(osk_key key, on_screen_keyboard * keyboard)
else if (strncmp("CAPSLOCK", text, 8) == 0)
{
apply_surface(key.x, key.y, keyboard->oskcapslock, keyboard->surface,
NULL);
apply_surface(key.x, key.y, keyboard->oskcapslock, keyboard->surface, NULL);
}
else if (strncmp("SHIFT", text, 5) == 0)
@ -1497,9 +1446,7 @@ static void label_key(osk_key key, on_screen_keyboard * keyboard)
else if (strncmp("SPACE", text, 5) != 0 && strncmp("NULL", text, 4) != 0)
{
messager =
TTF_RenderUTF8_Blended(keyboard->osk_fonty, text,
keyboard->layout->fgcolor);
messager = TTF_RenderUTF8_Blended(keyboard->osk_fonty, text, keyboard->layout->fgcolor);
apply_surface(key.x + 5, key.y, messager, keyboard->surface, NULL);
SDL_FreeSurface(messager);
@ -1516,12 +1463,10 @@ static osk_key *find_key(on_screen_keyboard * keyboard, int x, int y)
key = NULL;
for (j = 0; j < keyboard->layout->height; j++)
{
if (keyboard->layout->keys[j][0].y < y
&& keyboard->layout->keys[j][0].y + keyboard->button_up->h > y)
if (keyboard->layout->keys[j][0].y < y && keyboard->layout->keys[j][0].y + keyboard->button_up->h > y)
for (i = 0; i < keyboard->layout->width; i++)
if (keyboard->layout->keys[j][i].x < x &&
keyboard->layout->keys[j][i].x +
keyboard->layout->keys[j][i].width * keyboard->button_up->w > x)
keyboard->layout->keys[j][i].x + keyboard->layout->keys[j][i].width * keyboard->button_up->w > x)
{
key = &keyboard->layout->keys[j][i];
return key;
@ -1629,8 +1574,7 @@ static char *find_keysym(osk_key key, on_screen_keyboard * keyboard)
}
}
else if (modstate & KMOD_RALT && modstate & KMOD_CAPS
&& !(modstate & KMOD_SHIFT))
else if (modstate & KMOD_RALT && modstate & KMOD_CAPS && !(modstate & KMOD_SHIFT))
{
if (key.shiftcaps)
keysym = keysyms.shiftaltgr;
@ -1650,8 +1594,7 @@ static char *find_keysym(osk_key key, on_screen_keyboard * keyboard)
}
/* We lose the SDL ModState by leaving and entering the tuxpaint window, so using a custom state */
static int handle_keymods(char *keysym, osk_key * key,
on_screen_keyboard * keyboard)
static int handle_keymods(char *keysym, osk_key * key, on_screen_keyboard * keyboard)
{
SDL_Keymod mod;
SDL_Event ev;
@ -1688,8 +1631,7 @@ static int handle_keymods(char *keysym, osk_key * key,
/* Seems ISO_Level3_Shift and ISO_Next_Group are used too for right Alt */
else if (strncmp("ISO_Level3_Shift", keysym, 16) == 0 ||
strncmp("ISO_Next_Group", keysym, 14) == 0
|| strncmp("ALT_R", keysym, 5) == 0)
strncmp("ISO_Next_Group", keysym, 14) == 0 || strncmp("ALT_R", keysym, 5) == 0)
{
if (mod & KMOD_RALT)
{
@ -1904,10 +1846,10 @@ struct osk_keyboard *osk_clicked(on_screen_keyboard * keyboard, int x, int y)
wkeysym = malloc(sizeof(wchar_t) * (strlen(keysym) + 1));
mbsrtowcs(wkeysym, (const char **) &keysym, strlen(keysym) + 1, NULL);
mbsrtowcs(wkeysym, (const char **)&keysym, strlen(keysym) + 1, NULL);
#ifdef OSK_DEBUG
printf("wkeysym %ls %i\n\n", wkeysym, (int) wcslen(wkeysym));
printf("wkeysym %ls %i\n\n", wkeysym, (int)wcslen(wkeysym));
#endif
@ -1932,8 +1874,7 @@ struct osk_keyboard *osk_clicked(on_screen_keyboard * keyboard, int x, int y)
event.text.text[0] = '\r';
event.text.text[1] = '\0';
}
else if (wcsncmp(L"Tab", ks, 3) == 0
|| wcsncmp(L"ISO_Left_Tab", ks, 12) == 0)
else if (wcsncmp(L"Tab", ks, 3) == 0 || wcsncmp(L"ISO_Left_Tab", ks, 12) == 0)
{
event.key.keysym.sym = SDLK_TAB;
event.text.text[0] = '\t';
@ -1966,7 +1907,7 @@ struct osk_keyboard *osk_clicked(on_screen_keyboard * keyboard, int x, int y)
wchar_t buf[2];
iwc = keysym2unicode(mnemo2keysym(mnemo, keyboard), keyboard);
buf[0] = (wchar_t) iwc;
buf[0] = (wchar_t)iwc;
buf[1] = L'\0';
#ifdef OSK_DEBUG
@ -1979,7 +1920,7 @@ struct osk_keyboard *osk_clicked(on_screen_keyboard * keyboard, int x, int y)
printf("len = %d\n", len);
printf("event.text.text = \"%s\"\n", event.text.text);
#else
len = len; /* Avoid 'set but not used' warning */
len = len; /* Avoid 'set but not used' warning */
#endif
}

View file

@ -156,15 +156,12 @@ struct osk_keyboard *osk_create(char *layout_name, SDL_Surface * canvas,
SDL_Surface * BLANK_oskdel,
SDL_Surface * BLANK_osktab,
SDL_Surface * BLANK_oskenter,
SDL_Surface * BLANK_oskcapslock,
SDL_Surface * BLANK_oskshift,
int disable_change);
SDL_Surface * BLANK_oskcapslock, SDL_Surface * BLANK_oskshift, int disable_change);
struct osk_layout *osk_load_layout(char *layout_name);
void osk_get_layout_data(char *layout_name, int *layout_w, int *layout_h,
char *layout_buttons, char *layout_labels,
char *layout_keycodes);
char *layout_buttons, char *layout_labels, char *layout_keycodes);
void osk_reset(on_screen_keyboard * osk);
struct osk_keyboard *osk_clicked(on_screen_keyboard * keyboard, int x, int y);
void osk_released(on_screen_keyboard * osk);

View file

@ -37,9 +37,7 @@ static void putpixel8(SDL_Surface * surface, int x, int y, Uint32 pixel)
Uint8 *p;
/* Assuming the X/Y values are within the bounds of this surface... */
if (likely
(likely((unsigned) x < (unsigned) surface->w)
&& likely((unsigned) y < (unsigned) surface->h)))
if (likely(likely((unsigned)x < (unsigned)surface->w) && likely((unsigned)y < (unsigned)surface->h)))
{
// Set a pointer to the exact location in memory of the pixel
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start: beginning of RAM */
@ -60,9 +58,7 @@ static void putpixel16(SDL_Surface * surface, int x, int y, Uint32 pixel)
Uint8 *p;
/* Assuming the X/Y values are within the bounds of this surface... */
if (likely
(likely((unsigned) x < (unsigned) surface->w)
&& likely((unsigned) y < (unsigned) surface->h)))
if (likely(likely((unsigned)x < (unsigned)surface->w) && likely((unsigned)y < (unsigned)surface->h)))
{
// Set a pointer to the exact location in memory of the pixel
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start: beginning of RAM */
@ -83,9 +79,7 @@ static void putpixel24(SDL_Surface * surface, int x, int y, Uint32 pixel)
Uint8 *p;
/* Assuming the X/Y values are within the bounds of this surface... */
if (likely
(likely((unsigned) x < (unsigned) surface->w)
&& likely((unsigned) y < (unsigned) surface->h)))
if (likely(likely((unsigned)x < (unsigned)surface->w) && likely((unsigned)y < (unsigned)surface->h)))
{
// Set a pointer to the exact location in memory of the pixel
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start: beginning of RAM */
@ -118,9 +112,7 @@ static void putpixel32(SDL_Surface * surface, int x, int y, Uint32 pixel)
Uint8 *p;
/* Assuming the X/Y values are within the bounds of this surface... */
if (likely
(likely((unsigned) x < (unsigned) surface->w)
&& likely((unsigned) y < (unsigned) surface->h)))
if (likely(likely((unsigned)x < (unsigned)surface->w) && likely((unsigned)y < (unsigned)surface->h)))
{
// Set a pointer to the exact location in memory of the pixel
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start: beginning of RAM */
@ -141,9 +133,9 @@ static Uint32 getpixel8(SDL_Surface * surface, int x, int y)
Uint8 *p;
/* get the X/Y values within the bounds of this surface */
if (unlikely((unsigned) x > (unsigned) surface->w - 1u))
if (unlikely((unsigned)x > (unsigned)surface->w - 1u))
x = (x < 0) ? 0 : surface->w - 1;
if (unlikely((unsigned) y > (unsigned) surface->h - 1u))
if (unlikely((unsigned)y > (unsigned)surface->h - 1u))
y = (y < 0) ? 0 : surface->h - 1;
/* Set a pointer to the exact location in memory of the pixel
@ -167,9 +159,9 @@ static Uint32 getpixel16(SDL_Surface * surface, int x, int y)
Uint8 *p;
/* get the X/Y values within the bounds of this surface */
if (unlikely((unsigned) x > (unsigned) surface->w - 1u))
if (unlikely((unsigned)x > (unsigned)surface->w - 1u))
x = (x < 0) ? 0 : surface->w - 1;
if (unlikely((unsigned) y > (unsigned) surface->h - 1u))
if (unlikely((unsigned)y > (unsigned)surface->h - 1u))
y = (y < 0) ? 0 : surface->h - 1;
/* Set a pointer to the exact location in memory of the pixel
@ -194,9 +186,9 @@ static Uint32 getpixel24(SDL_Surface * surface, int x, int y)
Uint32 pixel;
/* get the X/Y values within the bounds of this surface */
if (unlikely((unsigned) x > (unsigned) surface->w - 1u))
if (unlikely((unsigned)x > (unsigned)surface->w - 1u))
x = (x < 0) ? 0 : surface->w - 1;
if (unlikely((unsigned) y > (unsigned) surface->h - 1u))
if (unlikely((unsigned)y > (unsigned)surface->h - 1u))
y = (y < 0) ? 0 : surface->h - 1;
/* Set a pointer to the exact location in memory of the pixel
@ -227,9 +219,9 @@ static Uint32 getpixel32(SDL_Surface * surface, int x, int y)
Uint8 *p;
/* get the X/Y values within the bounds of this surface */
if (unlikely((unsigned) x > (unsigned) surface->w - 1u))
if (unlikely((unsigned)x > (unsigned)surface->w - 1u))
x = (x < 0) ? 0 : surface->w - 1;
if (unlikely((unsigned) y > (unsigned) surface->h - 1u))
if (unlikely((unsigned)y > (unsigned)surface->h - 1u))
y = (y < 0) ? 0 : surface->h - 1;
/* Set a pointer to the exact location in memory of the pixel

View file

@ -49,8 +49,7 @@ static int old_sound[4] = { -1, -1, -1, -1 };
* (low values, near the top of the window, are quieter), or
* SNDDIST_NEAR for full volume
*/
void playsound(SDL_Surface * screen, int chan, int s, int override, int x,
int y)
void playsound(SDL_Surface * screen, int chan, int s, int override, int x, int y)
{
#ifndef NOSOUND
int left, dist;
@ -109,8 +108,7 @@ void playsound(SDL_Surface * screen, int chan, int s, int override, int x,
left = (255 - dist) / 2;
}
#ifdef DEBUG
printf("Panning of sound #%d in channel %d, left=%d, right=%d\n", s,
chan, left, (255 - dist) - left);
printf("Panning of sound #%d in channel %d, left=%d, right=%d\n", s, chan, left, (255 - dist) - left);
fflush(stdout);
#endif
Mix_SetPanning(chan, left, (255 - dist) - left);

View file

@ -38,7 +38,6 @@
extern Mix_Chunk *sounds[NUM_SOUNDS];
extern int mute, use_sound, use_stereo;
void playsound(SDL_Surface * screen, int chan, int s, int override, int x,
int y);
void playsound(SDL_Surface * screen, int chan, int s, int override, int x, int y);
#endif

View file

@ -68,18 +68,17 @@
static int f2int(float f)
{
return ((int) f);
return ((int)f);
}
static int f2dec(float f)
{
return (int) ((f - f2int(f)) * 100);
return (int)((f - f2int(f)) * 100);
}
/* Actually save the PostScript data to the file stream: */
int do_ps_save(FILE * fi,
const char *restrict const fname, SDL_Surface * surf,
const char *restrict pprsize, int is_pipe)
const char *restrict const fname, SDL_Surface * surf, const char *restrict pprsize, int is_pipe)
{
const struct paper *ppr;
int img_w = surf->w;
@ -93,8 +92,7 @@ int do_ps_save(FILE * fi,
Uint8 r, g, b;
char buf[256];
Uint32(*getpixel) (SDL_Surface *, int, int) =
getpixels[surf->format->BytesPerPixel];
Uint32(*getpixel) (SDL_Surface *, int, int) = getpixels[surf->format->BytesPerPixel];
int printed_img_w, printed_img_h;
time_t t = time(NULL);
int rotate;
@ -148,8 +146,7 @@ int do_ps_save(FILE * fi,
ppr_h = paperpsheight(ppr);
#ifdef DEBUG
printf("Paper is %d x %d (%.2f\" x %.2f\")\n", ppr_w, ppr_h,
(float) ppr_w / 72.0, (float) ppr_h / 72.0);
printf("Paper is %d x %d (%.2f\" x %.2f\")\n", ppr_w, ppr_h, (float)ppr_w / 72.0, (float)ppr_h / 72.0);
#endif
paperdone(); // FIXME: Should we do this at quit? -bjk 2007.06.25
@ -157,8 +154,7 @@ int do_ps_save(FILE * fi,
/* Determine whether it's best to rotate the image: */
if ((ppr_w >= ppr_h && img_w >= img_h)
|| (ppr_w <= ppr_h && img_w <= img_h))
if ((ppr_w >= ppr_h && img_w >= img_h) || (ppr_w <= ppr_h && img_w <= img_h))
{
rotate = 0;
r_img_w = img_w;
@ -180,16 +176,13 @@ int do_ps_save(FILE * fi,
/* Determine scale: */
scale =
my_min(((float) (ppr_w - (MARGIN * 2)) / (float) r_img_w),
((float) (ppr_h - (MARGIN * 2)) / (float) r_img_h));
scale = my_min(((float)(ppr_w - (MARGIN * 2)) / (float)r_img_w), ((float)(ppr_h - (MARGIN * 2)) / (float)r_img_h));
printed_img_w = r_img_w * scale;
printed_img_h = r_img_h * scale;
#ifdef DEBUG
printf("Scaling image by %.2f (to %d x %d)\n", scale, printed_img_w,
printed_img_h);
printf("Scaling image by %.2f (to %d x %d)\n", scale, printed_img_w, printed_img_h);
#endif
@ -215,8 +208,7 @@ int do_ps_save(FILE * fi,
fprintf(fi, "%%%%Pages: 1\n");
fprintf(fi, "%%%%BoundingBox: 0 0 %d %d\n", (int) (ppr_w + 0.5),
(int) (ppr_h + 0.5));
fprintf(fi, "%%%%BoundingBox: 0 0 %d %d\n", (int)(ppr_w + 0.5), (int)(ppr_h + 0.5));
fprintf(fi, "%%%%EndComments\n");
@ -235,23 +227,20 @@ int do_ps_save(FILE * fi,
fprintf(fi, "%%%%Page: 1 1\n");
fprintf(fi, "<< /PageSize [ %d %d ] /ImagingBBox null >> setpagedevice\n",
ppr_w, ppr_h);
fprintf(fi, "<< /PageSize [ %d %d ] /ImagingBBox null >> setpagedevice\n", ppr_w, ppr_h);
fprintf(fi, "gsave\n");
/* 'translate' moves the user space origin to a new position with
respect to the current page, leaving the orientation of the axes and
the unit lengths unchanged. */
fprintf(fi, "%d.%02d %d.%02d translate\n", f2int(tlate_x), f2dec(tlate_x),
f2int(tlate_y), f2dec(tlate_y));
fprintf(fi, "%d.%02d %d.%02d translate\n", f2int(tlate_x), f2dec(tlate_x), f2int(tlate_y), f2dec(tlate_y));
/* 'scale' modifies the unit lengths independently along the current
x and y axes, leaving the origin location and the orientation of the
axes unchanged. */
fprintf(fi, "%d.%02d %d.%02d scale\n",
f2int(printed_img_w), f2dec(printed_img_w), f2int(printed_img_h),
f2dec(printed_img_h));
f2int(printed_img_w), f2dec(printed_img_w), f2int(printed_img_h), f2dec(printed_img_h));
/* Rotate the image */
if (rotate)

View file

@ -79,8 +79,7 @@
#ifdef PRINTMETHOD_PS
int do_ps_save(FILE * fi,
const char *restrict const fname, SDL_Surface * surf,
const char *restrict pprsize, int is_pipe);
const char *restrict const fname, SDL_Surface * surf, const char *restrict pprsize, int is_pipe);
#endif

View file

@ -39,8 +39,7 @@ int progress_bar_disabled, prog_bar_ctr;
*
* @param screen Screen surface
*/
void show_progress_bar_(SDL_Surface * screen, SDL_Texture * texture,
SDL_Renderer * renderer)
void show_progress_bar_(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer)
{
SDL_Rect dest, src, r;
int x;
@ -73,9 +72,7 @@ void show_progress_bar_(SDL_Surface * screen, SDL_Texture * texture,
r.w = screen->w;
r.h = 24;
SDL_UpdateTexture(texture, &r,
screen->pixels + ((screen->h - 24) * screen->pitch),
screen->pitch);
SDL_UpdateTexture(texture, &r, screen->pixels + ((screen->h - 24) * screen->pitch), screen->pitch);
/* Docs says one should clear the renderer, even if this means a refresh of the whole thing. */
SDL_RenderClear(renderer);

View file

@ -36,7 +36,6 @@
extern SDL_Surface *img_progress;
extern int progress_bar_disabled, prog_bar_ctr;
void show_progress_bar_(SDL_Surface * screen, SDL_Texture * texture,
SDL_Renderer * renderer);
void show_progress_bar_(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer);
#endif

View file

@ -305,8 +305,7 @@ static const unsigned char linear_to_sRGB_table[4096] =
"\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd"
"\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe"
"\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe"
"\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff";
"\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff" "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff";
unsigned char linear_to_sRGB(float linear) FUNCTION;

View file

@ -327,10 +327,8 @@ const char *const shape_tips[NUM_SHAPES] = {
gettext_noop("A rectangle has four sides and four right angles."),
// Description of a circle
gettext_noop
("A circle is a curve where all points have the same distance from the center."),
gettext_noop
("A circle is a curve where all points have the same distance from the center."),
gettext_noop("A circle is a curve where all points have the same distance from the center."),
gettext_noop("A circle is a curve where all points have the same distance from the center."),
// Description of an ellipse
gettext_noop("An ellipse is a stretched circle."),
@ -357,11 +355,9 @@ const char *const shape_tips[NUM_SHAPES] = {
gettext_noop("An octagon has eight equal sides."),
// Description of a rhombus
gettext_noop
("A rhombus has four equal sides, and opposite sides are parallel."),
gettext_noop
("A rhombus has four equal sides, and opposite sides are parallel."),
gettext_noop("A rhombus has four equal sides, and opposite sides are parallel."),
gettext_noop("A rhombus has four equal sides, and opposite sides are parallel."),
// Description of triangle star (3 points star)
gettext_noop("A star with 3 points."),
gettext_noop("A star with 3 points."),
@ -435,8 +431,7 @@ enum
const char *const shape_tool_tips[NUM_SHAPE_COMPLEXITIES] = {
gettext_noop
("Pick a shape. Click to start drawing, drag, and let go when it is the size and shape you want. Move around to rotate it, and click again to draw it."),
gettext_noop
("Pick a shape. Click to start drawing, drag, and let go when it is the size and shape you want.")
gettext_noop("Pick a shape. Click to start drawing, drag, and let go when it is the size and shape you want.")
};
/* Strings shown when switching between "from center"

View file

@ -57,9 +57,7 @@ int main(int argc, char *argv[])
/* Open each PNG image!... */
for (i = 1; i < argc; i++)
{
printf
("%5d ------------------------------------------------------------------\n",
i);
printf("%5d ------------------------------------------------------------------\n", i);
printf("%s\n", argv[i]);
fflush(stdout);
@ -134,8 +132,7 @@ int main(int argc, char *argv[])
}
/* Fill alpha channel if there is none */
if (ctype == PNG_COLOR_TYPE_RGB ||
ctype == PNG_COLOR_TYPE_GRAY || ctype == PNG_COLOR_TYPE_PALETTE)
if (ctype == PNG_COLOR_TYPE_RGB || ctype == PNG_COLOR_TYPE_GRAY || ctype == PNG_COLOR_TYPE_PALETTE)
{
png_set_filler(png, 0xFF, PNG_FILLER_AFTER);
}
@ -163,8 +160,7 @@ int main(int argc, char *argv[])
rows[y] = (png_byte *) malloc(png_get_rowbytes(png, info));
if (!rows[y])
{
fprintf(stderr,
"Failed to malloc() space for image data row #%d!\n", y);
fprintf(stderr, "Failed to malloc() space for image data row #%d!\n", y);
exit(1);
}
}

File diff suppressed because it is too large Load diff

View file

@ -84,7 +84,7 @@ struct dirent *readdir(struct DIR *pDir)
if (pDir->hFind)
{
strcpy(pDir->de.d_name, (const char *) pDir->wfd.cFileName);
strcpy(pDir->de.d_name, (const char *)pDir->wfd.cFileName);
if (!FindNextFile(pDir->hFind, &pDir->wfd))
{
@ -107,9 +107,7 @@ struct dirent *readdir(struct DIR *pDir)
*/
int alphasort(const void *a, const void *b)
{
return (strcmp
((*(const struct dirent **) a)->d_name,
(*(const struct dirent **) b)->d_name));
return (strcmp((*(const struct dirent **)a)->d_name, (*(const struct dirent **)b)->d_name));
}
/**
@ -126,15 +124,11 @@ static int addToList(int i, struct dirent ***namelist, struct dirent *entry)
int size;
struct dirent *block;
*namelist =
(struct dirent **) realloc((void *) (*namelist),
(size_t) ((i + 1) * sizeof(struct dirent *)));
*namelist = (struct dirent **)realloc((void *)(*namelist), (size_t)((i + 1) * sizeof(struct dirent *)));
if (*namelist == NULL)
return -1;
size =
(((char *) &entry->d_name) - ((char *) entry)) + strlen(entry->d_name) +
1;
block = (struct dirent *) malloc(size);
size = (((char *)&entry->d_name) - ((char *)entry)) + strlen(entry->d_name) + 1;
block = (struct dirent *)malloc(size);
if (block == NULL)
return -1;
(*namelist)[i] = block;
@ -151,8 +145,7 @@ static int addToList(int i, struct dirent ***namelist, struct dirent *entry)
* @param compar Callback for sorting items in the list (via qsort()).
* @return Count of items, or -1 on error.
*/
int scandir(const char *dir, struct dirent ***namelist, selectCB select,
comparCB compar)
int scandir(const char *dir, struct dirent ***namelist, selectCB select, comparCB compar)
{
DIR *pDir;
int count;
@ -173,7 +166,6 @@ int scandir(const char *dir, struct dirent ***namelist, selectCB select,
if (count <= 0)
return -1;
if (compar != NULL)
qsort((void *) (*namelist), (size_t) count, sizeof(struct dirent *),
compar);
qsort((void *)(*namelist), (size_t)count, sizeof(struct dirent *), compar);
return count;
}

View file

@ -71,5 +71,4 @@ extern struct dirent *readdir(struct DIR *pDir);
typedef int (*selectCB)(const struct dirent *);
typedef int (*comparCB)(const void *, const void *);
extern int alphasort(const void *a, const void *b);
extern int scandir(const char *dir, struct dirent ***namelist,
selectCB select, comparCB compar);
extern int scandir(const char *dir, struct dirent ***namelist, selectCB select, comparCB compar);

View file

@ -68,8 +68,7 @@ static SDL_Surface *make24bitDIB(SDL_Surface * surf)
surf24 = SDL_ConvertSurface(surf, &pixfmt, SDL_SWSURFACE);
surfDIB = SDL_CreateRGBSurface(SDL_SWSURFACE, surf24->w, surf24->h, 24,
pixfmt.Rmask, pixfmt.Gmask, pixfmt.Bmask,
pixfmt.Amask);
pixfmt.Rmask, pixfmt.Gmask, pixfmt.Bmask, pixfmt.Amask);
linesize = surf24->w * 3; // Flip top2bottom
dst = surfDIB->pixels;
@ -105,8 +104,7 @@ static int GetDefaultPrinterStrings(char *device, char *driver, char *output)
return 0;
if (((dev = strtok(buff, ",")) != NULL) &&
((drv = strtok(NULL, ", ")) != NULL)
&& ((out = strtok(NULL, ", ")) != NULL))
((drv = strtok(NULL, ", ")) != NULL) && ((out = strtok(NULL, ", ")) != NULL))
{
if (device)
strcpy(device, dev);
@ -145,8 +143,7 @@ static HANDLE LoadCustomPrinterHDEVMODE(HWND hWnd, const char *filepath)
if (!OpenPrinter(device, &hPrinter, NULL))
goto err_exit;
sizeof_devmode =
(int) DocumentProperties(hWnd, hPrinter, device, NULL, NULL, 0);
sizeof_devmode = (int)DocumentProperties(hWnd, hPrinter, device, NULL, NULL, 0);
if (!sizeof_devmode)
goto err_exit;
@ -159,8 +156,7 @@ static HANDLE LoadCustomPrinterHDEVMODE(HWND hWnd, const char *filepath)
if (!devmode)
goto err_exit;
res =
DocumentProperties(hWnd, hPrinter, device, devmode, NULL, DM_OUT_BUFFER);
res = DocumentProperties(hWnd, hPrinter, device, devmode, NULL, DM_OUT_BUFFER);
if (res != IDOK)
goto err_exit;
@ -170,9 +166,7 @@ static HANDLE LoadCustomPrinterHDEVMODE(HWND hWnd, const char *filepath)
goto err_exit;
fclose(fp);
res =
DocumentProperties(hWnd, hPrinter, device, devmode, devmode,
DM_IN_BUFFER | DM_OUT_BUFFER);
res = DocumentProperties(hWnd, hPrinter, device, devmode, devmode, DM_IN_BUFFER | DM_OUT_BUFFER);
if (res != IDOK)
goto err_exit;
@ -195,8 +189,7 @@ err_exit:
/**
* FIXME
*/
static int SaveCustomPrinterHDEVMODE(HWND hWnd, const char *filepath,
HANDLE hDevMode)
static int SaveCustomPrinterHDEVMODE(HWND hWnd, const char *filepath, HANDLE hDevMode)
{
FILE *fp = NULL;
@ -208,7 +201,7 @@ static int SaveCustomPrinterHDEVMODE(HWND hWnd, const char *filepath,
int block_written;
char devname[dmDeviceNameSize];
strcpy(devname, (const char *) devmode->dmDeviceName);
strcpy(devname, (const char *)devmode->dmDeviceName);
fwrite(devname, 1, sizeof(devname), fp);
block_written = fwrite(devmode, 1, block_size, fp);
GlobalUnlock(hDevMode);
@ -272,8 +265,7 @@ static int GetCustomPrinterDC(HWND hWnd, const char *printcfg, int show)
{
DEVMODE *devmode = (DEVMODE *) GlobalLock(pd.hDevMode);
hDCprinter =
CreateDC(NULL, (const char *) devmode->dmDeviceName, NULL, devmode);
hDCprinter = CreateDC(NULL, (const char *)devmode->dmDeviceName, NULL, devmode);
GlobalUnlock(pd.hDevMode);
GlobalFree(pd.hDevMode);
}
@ -326,8 +318,7 @@ int IsPrinterAvailable(void)
/**
* FIXME
*/
const char *SurfacePrint(SDL_Window * window, SDL_Surface * surf,
const char *printcfg, int showdialog)
const char *SurfacePrint(SDL_Window * window, SDL_Surface * surf, const char *printcfg, int showdialog)
{
const char *res = NULL;
HWND hWnd;
@ -424,17 +415,17 @@ const char *SurfacePrint(SDL_Window * window, SDL_Surface * surf,
if (width < pageWidth && height < pageHeight)
{
float dW = (float) pageWidth / width;
float dH = (float) pageHeight / height;
float dW = (float)pageWidth / width;
float dH = (float)pageHeight / height;
if (dW < dH)
{
width = pageWidth;
height = (int) ((height * dW * (sY / sX)) + 0.5f);
height = (int)((height * dW * (sY / sX)) + 0.5f);
}
else
{
width = (int) ((width * dH * (sX / sY)) + 0.5f);
width = (int)((width * dH * (sX / sY)) + 0.5f);
height = pageHeight;
}
}
@ -476,9 +467,8 @@ const char *SurfacePrint(SDL_Window * window, SDL_Surface * surf,
nError = StretchDIBits(hDCprinter, rcDst.left, rcDst.top,
rcDst.right - rcDst.left,
rcDst.bottom - rcDst.top,
0, 0, bmih.biWidth, bmih.biHeight,
surf24->pixels, &bmi, DIB_RGB_COLORS, SRCCOPY);
if (nError == (int) GDI_ERROR)
0, 0, bmih.biWidth, bmih.biHeight, surf24->pixels, &bmi, DIB_RGB_COLORS, SRCCOPY);
if (nError == (int)GDI_ERROR)
{
res = "win32_print: StretchDIBits() failed.";
goto error;
@ -523,8 +513,7 @@ error:
/*
Read access to Windows Registry
*/
static HRESULT ReadRegistry(const char *key, const char *option, char *value,
int size)
static HRESULT ReadRegistry(const char *key, const char *option, char *value, int size)
{
LONG res;
HKEY hKey = NULL;
@ -573,8 +562,7 @@ char *GetDefaultSaveDir(const char *suffix)
{
char prefix[MAX_PATH];
char path[2 * MAX_PATH];
const char *key =
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
const char *key = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
const char *option = "AppData";
HRESULT hr = S_OK;
@ -598,8 +586,7 @@ char *GetDefaultSaveDir(const char *suffix)
char *GetSystemFontDir(void)
{
char path[MAX_PATH];
const char *key =
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
const char *key = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
const char *option = "Fonts";
HRESULT hr = S_OK;
@ -621,8 +608,7 @@ char *GetUserImageDir(void);
char *GetUserImageDir(void)
{
char path[MAX_PATH];
const char *key =
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
const char *key = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
const char *option = "My Pictures";
HRESULT hr = S_OK;
@ -675,8 +661,7 @@ static int g_bWindowActive = 0;
/**
* FIXME
*/
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam,
LPARAM lParam);
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
int bEatKeystroke = 0;
@ -690,8 +675,7 @@ LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
case WM_KEYDOWN:
case WM_KEYUP:
{
bEatKeystroke = g_bWindowActive && ((p->vkCode == VK_LWIN)
|| (p->vkCode == VK_RWIN));
bEatKeystroke = g_bWindowActive && ((p->vkCode == VK_LWIN) || (p->vkCode == VK_RWIN));
break;
}
}
@ -708,9 +692,7 @@ int InstallKeyboardHook(void)
{
if (g_hKeyboardHook)
return -1;
g_hKeyboardHook =
SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc,
GetModuleHandle(NULL), 0);
g_hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, GetModuleHandle(NULL), 0);
return g_hKeyboardHook ? 0 : -2;
}

View file

@ -15,8 +15,7 @@
#endif
/* if printcfg is NULL, uses the default printer */
extern const char *SurfacePrint(SDL_Window * window, SDL_Surface * surf,
const char *printcfg, int showdialog);
extern const char *SurfacePrint(SDL_Window * window, SDL_Surface * surf, const char *printcfg, int showdialog);
extern int IsPrinterAvailable(void);
/* additional windows functions requiring <windows.h> */

View file

@ -19,8 +19,7 @@ int MoveFileToRecycleBin(const TCHAR * fullPathName)
fileOp.hwnd = NULL;
fileOp.wFunc = FO_DELETE;
fileOp.pTo = NULL;
fileOp.fFlags =
FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT | FOF_ALLOWUNDO;
fileOp.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT | FOF_ALLOWUNDO;
return SHFileOperation(&fileOp);
}