Re-ran indent on all .c & .h source code files

Like so --
  find . -name "*.c" -or -name "*.h" -exec  indent -nbfda -npcs -npsl -bli0 --no-tabs {} \;

The `indent` invocation differs from the last one noted in
CHANGES.txt (from 2006!?), in that I've added "--no-tabs",
to ensure indents are all space-based.
This commit is contained in:
Bill Kendrick 2022-09-15 00:11:16 -07:00
parent 09f332367f
commit cc05925d9e
99 changed files with 31659 additions and 27102 deletions

View file

@ -7,7 +7,7 @@ Various contributors (see below, and AUTHORS.txt)
http://www.tuxpaint.org/
2022.September.14 (0.9.29)
2022.September.15 (0.9.29)
* Improvements to "Stamp" tool:
-----------------------------
* Stamps may now be rotated.
@ -131,6 +131,9 @@ http://www.tuxpaint.org/
Tux Paint Config. source updated to make the script's job easier.
Bill Kendrick <bill@newbreedsoftware.com>
* Cleaned up .c and .h source files using `indent`:
find . -name "*.c" -or -name "*.h" -exec indent -nbfda -npcs -npsl -bli0 --no-tabs {} \;
* Documentation updates:
---------------------
* Update macOS build instructions for SDL2.0.

View file

@ -93,9 +93,11 @@ Uint8 example_r, example_g, example_b;
// that are declared _before_ them.
void example_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 example_line_callback(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
void example_line_callback(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y);
/* Setup Functions: */
@ -144,7 +146,8 @@ int example_init(magic_api * api)
// (The "tp-magic-config --dataprefix" command would have told us when
// we installed our plugin and its data.)
snprintf(fname, sizeof(fname), "%s/sounds/magic/%s", api->data_directory, snd_filenames[i]);
snprintf(fname, sizeof(fname), "%s/sounds/magic/%s", api->data_directory,
snd_filenames[i]);
printf("Trying to load %s sound file\n", fname);
@ -191,7 +194,8 @@ SDL_Surface *example_get_icon(magic_api * api, int which)
// We use 'which' (which of our tools Tux Paint is asking about)
// as an index into the array.
snprintf(fname, sizeof(fname), "%s/images/magic/%s.png", api->data_directory, icon_filenames[which]);
snprintf(fname, sizeof(fname), "%s/images/magic/%s.png",
api->data_directory, icon_filenames[which]);
// Try to load the image, and return the results to Tux Paint:
@ -330,7 +334,8 @@ void example_shutdown(magic_api * api)
void
example_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)
{
// In our case, a single click (which is also the start of a drag!)
// is identical to what dragging does, but just at one point, rather
@ -347,7 +352,8 @@ example_click(magic_api * api, int which, int mode,
void
example_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)
{
// Call Tux Paint's "line()" function.
//
@ -358,7 +364,8 @@ example_drag(magic_api * api, int which, SDL_Surface * canvas,
// useful things (which of our "Magic" tools is being used and
// the current and snapshot canvases).
api->line((void *)api, which, canvas, snapshot, ox, oy, x, y, 1, example_line_callback);
api->line((void *) api, which, canvas, snapshot, ox, oy, x, y, 1,
example_line_callback);
// If we need to, swap the X and/or Y values, so that
@ -409,7 +416,8 @@ example_drag(magic_api * api, int which, SDL_Surface * canvas,
void
example_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)
{
// Neither of our effects do anything special when the mouse is released
// from a click or click-and-drag, so there's no code here...
@ -453,7 +461,8 @@ void example_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b)
// It pays attention to 'which' to determine which of our plugin's tools
// is currently selected.
void example_line_callback(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y)
void example_line_callback(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y)
{
// For technical reasons, we can't accept a pointer to the "magic_api"
// struct, like the other functions do.
@ -477,7 +486,9 @@ void example_line_callback(void *ptr, int which, SDL_Surface * canvas, SDL_Surfa
// Tool number 1 simply draws a single pixel at the (x,y) location.
// It's a 1x1 pixel brush
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, example_r, example_g, example_b));
api->putpixel(canvas, x, y,
SDL_MapRGB(canvas->format, example_r, example_g,
example_b));
// We use "SDL_MapRGB()" to convert the RGB value we receive from Tux Paint
// for the user's current color selection to a 'Uint32' pixel value
@ -492,7 +503,9 @@ void example_line_callback(void *ptr, int which, SDL_Surface * canvas, SDL_Surfa
{
for (xx = -4; xx < 4; xx++)
{
api->putpixel(canvas, x + xx, y + yy, api->getpixel(snapshot, canvas->w - x - xx, canvas->h - y - yy));
api->putpixel(canvas, x + xx, y + yy,
api->getpixel(snapshot, canvas->w - x - xx,
canvas->h - y - yy));
// We simply use Tux Paint's "getpixel()" routine to pull pixel
// values from the 'snapshot', and then "putpixel()" to draw them
@ -522,7 +535,8 @@ void example_line_callback(void *ptr, int which, SDL_Surface * canvas, SDL_Surfa
// Our example doesn't do anything when we switch to, or away from, our
// Magic tools, so we just do nothing here.
void example_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas)
void example_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas)
{
}
@ -542,6 +556,7 @@ void example_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas
// Our example doesn't do anything when we switch to, or away from, our
// Magic tools, so we just do nothing here.
void example_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
void example_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas)
{
}

View file

@ -73,7 +73,8 @@ 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,17 +87,21 @@ 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);
void alien_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 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);
void alien_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int alien_requires_colors(magic_api * api, int which);
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);
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);
@ -115,7 +120,8 @@ int alien_init(magic_api * api)
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);
@ -131,7 +137,8 @@ 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));
}
@ -147,14 +154,16 @@ 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;
@ -162,21 +171,25 @@ 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);
sin(((temp[k] / 127.5 -
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;
@ -190,7 +203,8 @@ static void do_alien_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last, i
}
//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;
@ -199,7 +213,8 @@ static void do_alien_brush(void *ptr, int which, SDL_Surface * canvas, SDL_Surfa
{
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);
}
@ -209,10 +224,12 @@ static void do_alien_brush(void *ptr, int which, SDL_Surface * canvas, SDL_Surfa
// 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);
@ -253,7 +270,8 @@ 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);
@ -269,9 +287,12 @@ void alien_click(magic_api * api, int which, int mode,
}
// Affect the canvas on release:
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)
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)
{
}
@ -291,23 +312,27 @@ void alien_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void alien_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
void alien_set_color(magic_api * api ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b 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;
}
void alien_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
void alien_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void alien_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
void alien_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}

View file

@ -62,15 +62,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);
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);
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);
int blind_modes(magic_api * api, int which);
// Housekeeping functions
@ -91,7 +96,8 @@ int blind_init(magic_api * api)
{
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);
@ -106,36 +112,45 @@ 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;
}
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)
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)
{
}
@ -147,12 +162,14 @@ 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,
SDL_MapRGB(canvas->format, (blind_r + blind_light) / 2,
(blind_g + blind_light) / 2,
(blind_b + blind_light) / 2));
}
@ -167,7 +184,8 @@ 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;
@ -183,12 +201,14 @@ 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;
}
}
@ -206,12 +226,14 @@ 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;
}
}
@ -230,12 +252,14 @@ 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;
}
}
@ -254,12 +278,14 @@ 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;
}
}
@ -274,7 +300,8 @@ 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)
@ -299,13 +326,15 @@ void blind_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
blind_drag(api, which, canvas, last, x, y, x, y, update_rect);
}
void blind_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, 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)
{
}
void blind_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
void blind_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{

View file

@ -60,18 +60,25 @@ SDL_Surface *blocks_chalk_drip_get_icon(magic_api * api, int which);
char *blocks_chalk_drip_get_name(magic_api * api, int which);
int blocks_chalk_drip_get_group(magic_api * api, int which);
char *blocks_chalk_drip_get_description(magic_api * api, int which, int mode);
static void blocks_chalk_drip_linecb(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
static void blocks_chalk_drip_linecb(void *ptr, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y);
void blocks_chalk_drip_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
void blocks_chalk_drip_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_chalk_drip_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_chalk_drip_shutdown(magic_api * api);
void blocks_chalk_drip_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int blocks_chalk_drip_requires_colors(magic_api * api, int which);
void blocks_chalk_drip_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void blocks_chalk_drip_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
void blocks_chalk_drip_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void blocks_chalk_drip_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
int blocks_chalk_drip_modes(magic_api * api, int which);
@ -80,13 +87,16 @@ int blocks_chalk_drip_init(magic_api * api)
{
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);
@ -111,15 +121,18 @@ SDL_Surface *blocks_chalk_drip_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));
@ -139,41 +152,52 @@ char *blocks_chalk_drip_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
}
// Return our group (all the same):
int blocks_chalk_drip_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
int blocks_chalk_drip_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_DISTORTS;
}
// Return our descriptions, localized:
char *blocks_chalk_drip_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode)
char *blocks_chalk_drip_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
{
@ -186,7 +210,9 @@ char *blocks_chalk_drip_get_description(magic_api * api ATTRIBUTE_UNUSED, int wh
// Do the effect:
static void blocks_chalk_drip_linecb(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
static void blocks_chalk_drip_linecb(void *ptr, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y)
{
magic_api *api = (magic_api *) ptr;
int xx, yy;
@ -204,9 +230,11 @@ static void blocks_chalk_drip_linecb(void *ptr, int which, SDL_Surface * canvas,
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;
@ -240,9 +268,12 @@ static void blocks_chalk_drip_linecb(void *ptr, int which, SDL_Surface * canvas,
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: */
@ -259,16 +290,20 @@ static void blocks_chalk_drip_linecb(void *ptr, int which, SDL_Surface * canvas,
}
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);
}
}
@ -297,9 +332,11 @@ static void blocks_chalk_drip_linecb(void *ptr, int which, SDL_Surface * canvas,
// Affect the canvas on drag:
void blocks_chalk_drip_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y, SDL_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_chalk_drip_linecb);
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1,
blocks_chalk_drip_linecb);
if (ox > x)
{
@ -326,28 +363,41 @@ void blocks_chalk_drip_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void blocks_chalk_drip_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)
{
if (mode == MODE_PAINT) {
blocks_chalk_drip_drag(api, which, canvas, last, x, y, x, y, update_rect);
} else /* MODE_FULLSCREEN */ {
if (which != TOOL_DRIP) {
for (y = 0; y < canvas->h; y += EFFECT_REZ) {
if (y % 10 == 0) {
}
else /* MODE_FULLSCREEN */
{
if (which != TOOL_DRIP)
{
for (y = 0; y < canvas->h; y += EFFECT_REZ)
{
if (y % 10 == 0)
{
api->update_progress_bar();
}
for (x = 0; x < canvas->w; x += EFFECT_REZ) {
for (x = 0; x < canvas->w; x += EFFECT_REZ)
{
blocks_chalk_drip_linecb(api, which, canvas, last, x, y);
}
}
} else {
}
else
{
/* 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) {
for (y = canvas->h - 1; y >= 0; y -= EFFECT_REZ)
{
if ((y + p) % 10 == 0)
{
api->update_progress_bar();
}
for (x = 0; x < canvas->w; x += EFFECT_REZ) {
for (x = 0; x < canvas->w; x += EFFECT_REZ)
{
blocks_chalk_drip_linecb(api, which, canvas, last, x, y);
}
}
@ -362,9 +412,12 @@ void blocks_chalk_drip_click(magic_api * api, int which, int mode,
}
// Affect the canvas on release:
void blocks_chalk_drip_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)
void blocks_chalk_drip_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)
{
}
@ -380,31 +433,41 @@ void blocks_chalk_drip_shutdown(magic_api * api ATTRIBUTE_UNUSED)
// Record the color from Tux Paint:
void blocks_chalk_drip_set_color(magic_api * api ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
Uint8 r ATTRIBUTE_UNUSED,
Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED)
{
}
// Use colors:
int blocks_chalk_drip_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
int blocks_chalk_drip_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
{
return 0;
}
void blocks_chalk_drip_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
void blocks_chalk_drip_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void blocks_chalk_drip_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void blocks_chalk_drip_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int blocks_chalk_drip_modes(magic_api * api ATTRIBUTE_UNUSED, int which)
{
if (which == TOOL_BLOCKS || TOOL_CHALK) {
if (which == TOOL_BLOCKS || TOOL_CHALK)
{
return (MODE_PAINT | MODE_FULLSCREEN);
} else /* TOOL_DRIP */ {
}
else /* TOOL_DRIP */
{
return (MODE_PAINT);
}
}

View file

@ -47,16 +47,19 @@ 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);
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, SDL_Surface * last, 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,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void blur_shutdown(magic_api * api);
void blur_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int blur_requires_colors(magic_api * api, int which);
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
@ -104,7 +107,8 @@ int blur_init(magic_api * api)
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);
@ -120,7 +124,8 @@ 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));
}
@ -137,13 +142,16 @@ 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;
@ -168,7 +176,8 @@ static void do_blur_pixel(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * c
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];
@ -179,18 +188,22 @@ static void do_blur_pixel(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * c
{
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;
for (y = 0; y < last->h; y++)
{
if (y % 10 == 0) {
if (y % 10 == 0)
{
api->update_progress_bar();
}
@ -202,7 +215,8 @@ static void do_blur_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last, in
}
//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;
@ -211,7 +225,8 @@ static void do_blur_brush(void *ptr, int which, SDL_Surface * canvas, SDL_Surfac
{
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);
}
@ -221,10 +236,12 @@ static void do_blur_brush(void *ptr, int which, SDL_Surface * canvas, SDL_Surfac
// 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);
@ -251,7 +268,8 @@ 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);
@ -267,9 +285,12 @@ void blur_click(magic_api * api, int which, int mode,
}
// Affect the canvas on release:
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)
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)
{
}
@ -289,23 +310,27 @@ void blur_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void blur_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
void blur_set_color(magic_api * api ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED)
{
}
// 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;
}
void blur_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
void blur_switchin(magic_api * api 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,
void blur_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}

View file

@ -54,7 +54,8 @@ static Uint8 bricks_r, bricks_g, bricks_b;
/* 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 bricks_api_version(void);
int bricks_get_tool_count(magic_api * api);
@ -63,15 +64,18 @@ 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);
void bricks_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, 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.
void bricks_shutdown(magic_api * api);
void bricks_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
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);
// No setup required:
@ -79,7 +83,8 @@ int bricks_init(magic_api * api)
{
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);
return (1);
@ -103,18 +108,21 @@ 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: */
@ -122,13 +130,15 @@ char *bricks_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUS
}
// 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 (which == TOOL_LARGEBRICKS)
return (strdup(gettext_noop("Click and drag to draw large bricks.")));
@ -140,7 +150,8 @@ char *bricks_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mo
// 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;
@ -187,7 +198,8 @@ static void do_bricks(void *ptr, int which, SDL_Surface * canvas, SDL_Surface *
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;
@ -208,7 +220,8 @@ static void do_bricks(void *ptr, int which, SDL_Surface * canvas, SDL_Surface *
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:
@ -228,7 +241,8 @@ static void do_bricks(void *ptr, int which, SDL_Surface * canvas, SDL_Surface *
// 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);
@ -257,14 +271,18 @@ 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);
}
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)
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)
{
}
@ -276,7 +294,8 @@ void bricks_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void bricks_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b)
void bricks_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g,
Uint8 b)
{
bricks_r = r;
bricks_g = g;
@ -284,21 +303,29 @@ void bricks_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8
}
// 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 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);
@ -318,13 +345,15 @@ static void do_brick(magic_api * api, SDL_Surface * canvas, int x, int y, int w,
api->playsound(brick_snd, (x * 255) / canvas->w, 255);
}
void bricks_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void bricks_switchin(magic_api * api 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)
void bricks_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}

View file

@ -50,7 +50,8 @@ 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 calligraphy_api_version(void);
@ -60,16 +61,21 @@ 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);
void calligraphy_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 calligraphy_release(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
void calligraphy_shutdown(magic_api * api);
void calligraphy_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
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);
// No setup required:
@ -77,11 +83,13 @@ int calligraphy_init(magic_api * api)
{
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;
@ -115,32 +123,40 @@ 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,
char *calligraphy_get_description(magic_api * api 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)
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)
{
Point2D *curve;
int i, n_points, thick, new_thick;
@ -180,7 +196,9 @@ void calligraphy_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface *
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
@ -194,7 +212,8 @@ void calligraphy_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface *
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 */
@ -260,9 +279,11 @@ void calligraphy_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface *
api->playsound(calligraphy_snd, (x * 255) / canvas->w, 255);
}
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)
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)
{
calligraphy_old_thick = 8;
calligraphy_last_time = 0;
@ -278,9 +299,12 @@ void calligraphy_click(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNU
}
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)
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)
{
}
@ -312,7 +336,9 @@ void calligraphy_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b)
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,
@ -320,7 +346,8 @@ void calligraphy_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b)
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!
@ -333,10 +360,13 @@ void calligraphy_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b)
{
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));
}
}
@ -345,7 +375,8 @@ void calligraphy_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b)
}
// 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;
}
@ -400,7 +431,8 @@ 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;
@ -420,17 +452,22 @@ static float calligraphy_dist(float x1, float y1, float x2, float y2)
return d;
}
void calligraphy_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
void calligraphy_switchin(magic_api * api 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,
void calligraphy_switchout(magic_api * api 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);
}

View file

@ -51,20 +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);
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 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);
void cartoon_shutdown(magic_api * api);
void cartoon_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
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);
@ -74,7 +80,8 @@ int cartoon_init(magic_api * api)
{
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);
@ -96,39 +103,48 @@ 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.")));
}
}
// Do the effect:
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)
{
Uint8 r, g, b;
float hue, sat, val;
@ -149,33 +165,44 @@ 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));
}
void cartoon_apply_outline(magic_api * api, int xx, int yy) {
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)
static void do_cartoon(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas,
SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
{
magic_api *api = (magic_api *) ptr;
int xx, yy;
@ -194,7 +221,8 @@ static void do_cartoon(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canv
// 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)
{
@ -223,11 +251,13 @@ 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++)
{
if (y % 10 == 0) {
if (y % 10 == 0)
{
api->update_progress_bar();
}
@ -238,7 +268,8 @@ void cartoon_click(magic_api * api, int which, int mode,
}
for (y = 0; y < canvas->h; y++)
{
if (y % 10 == 0) {
if (y % 10 == 0)
{
api->update_progress_bar();
}
@ -265,9 +296,12 @@ void cartoon_click(magic_api * api, int which, int mode,
}
// Affect the canvas on release:
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)
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)
{
}
@ -279,39 +313,47 @@ void cartoon_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void cartoon_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
void cartoon_set_color(magic_api * api ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b 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,
void cartoon_switchin(magic_api * api ATTRIBUTE_UNUSED,
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,
void cartoon_switchout(magic_api * api 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);
}

View file

@ -46,15 +46,22 @@ 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);
void checkerboard_paint_checkerboard(void *ptr_to_api, int which_tool,
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);
// Housekeeping functions
@ -75,7 +82,8 @@ int checkerboard_init(magic_api * api)
{
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);
@ -86,40 +94,50 @@ 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)
char *checkerboard_get_description(magic_api * api 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."));
}
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;
}
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)
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)
{
}
@ -130,8 +148,8 @@ void checkerboard_shutdown(magic_api * api ATTRIBUTE_UNUSED)
// Interactivity functions
void checkerboard_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
SDL_Surface * snapshot,
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)
{
@ -142,9 +160,13 @@ void checkerboard_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface
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)
@ -154,11 +176,14 @@ void checkerboard_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface
/* From the mouse Y position down... */
draw_row = draw_start;
for (yy = checkerboard_start_y; yy <= canvas->h; yy += sz) {
for (yy = checkerboard_start_y; yy <= canvas->h; yy += sz)
{
/* From the mouse X position right... */
draw_cell = draw_row;
for (xx = checkerboard_start_x; xx <= canvas->w; xx += sz) {
if (draw_cell) {
for (xx = checkerboard_start_x; xx <= canvas->w; xx += sz)
{
if (draw_cell)
{
dest.x = xx;
dest.y = yy;
dest.w = sz;
@ -170,8 +195,10 @@ void checkerboard_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface
/* From the mouse X position left... */
draw_cell = !draw_row;
for (xx = checkerboard_start_x - sz; xx > -sz; xx -= sz) {
if (draw_cell) {
for (xx = checkerboard_start_x - sz; xx > -sz; xx -= sz)
{
if (draw_cell)
{
dest.x = xx;
dest.y = yy;
dest.w = sz;
@ -186,11 +213,14 @@ void checkerboard_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface
/* From the mouse Y position up... */
draw_row = !draw_start;
for (yy = checkerboard_start_y - sz; yy > -sz; yy -= sz) {
for (yy = checkerboard_start_y - sz; yy > -sz; yy -= sz)
{
/* From the mouse X position right... */
draw_cell = draw_row;
for (xx = checkerboard_start_x; xx <= canvas->w; xx += sz) {
if (draw_cell) {
for (xx = checkerboard_start_x; xx <= canvas->w; xx += sz)
{
if (draw_cell)
{
dest.x = xx;
dest.y = yy;
dest.w = sz;
@ -202,8 +232,10 @@ void checkerboard_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface
/* From the mouse X position left... */
draw_cell = !draw_row;
for (xx = checkerboard_start_x - sz; xx > -sz; xx -= sz) {
if (draw_cell) {
for (xx = checkerboard_start_x - sz; xx > -sz; xx -= sz)
{
if (draw_cell)
{
dest.x = xx;
dest.y = yy;
dest.w = sz;
@ -225,9 +257,9 @@ void checkerboard_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface
api->playsound(checkerboard_snd, 128, 255);
}
void checkerboard_click(magic_api * api, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y,
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)
{
checkerboard_start_x = x;
@ -235,17 +267,22 @@ void checkerboard_click(magic_api * api, int which ATTRIBUTE_UNUSED, int mode AT
checkerboard_drag(api, which, canvas, last, x, y, x, y, update_rect);
}
void checkerboard_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
void checkerboard_switchin(magic_api * api 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,
void checkerboard_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which 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);
}

View file

@ -73,31 +73,38 @@ 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);
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, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
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,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void clone_shutdown(magic_api * api);
void clone_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
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);
// No setup required:
int clone_init(magic_api * api)
{
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;
@ -122,34 +129,42 @@ 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("Click once to pick a spot to begin cloning. Click again and drag to clone that part of the picture.")));
return (strdup
(gettext_noop
("Click once to pick a spot to begin cloning. Click again and drag to clone that part of the picture.")));
return (NULL);
}
// 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;
Uint8 r, g, b;
@ -168,7 +183,8 @@ static void do_clone(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas
{
if (api->in_circle(xx, yy, 16))
{
SDL_GetRGB(api->getpixel(last, srcx + xx, srcy + yy), last->format, &r, &g, &b);
SDL_GetRGB(api->getpixel(last, srcx + xx, srcy + yy), last->format,
&r, &g, &b);
pixel = SDL_MapRGB(canvas->format, r, g, b);
api->putpixel(canvas, x + xx, y + yy, pixel);
}
@ -179,7 +195,8 @@ static void do_clone(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas
// 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) */
@ -192,8 +209,8 @@ 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;
@ -222,7 +239,8 @@ void clone_doit(magic_api * api, int which, SDL_Surface * canvas,
y = tmp;
}
if (crosshairs) {
if (crosshairs)
{
clone_crosshairs(api, canvas, clone_src_x, clone_src_y);
/* FIXME be more clever */
update_rect->x = 0;
@ -230,7 +248,9 @@ void clone_doit(magic_api * api, int which, SDL_Surface * canvas,
update_rect->w = canvas->w;
update_rect->h = canvas->h;
clone_crosshair_visible = 1;
} else {
}
else
{
update_rect->x = x - 64;
update_rect->y = y - 64;
update_rect->w = (ox + 128) - update_rect->x;
@ -242,9 +262,11 @@ 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)
{
if (clone_state == CLONE_READY_TO_START) {
/* Step 1 - Picking a source for the clone */
clone_src_x = x;
clone_src_y = y;
@ -260,7 +282,9 @@ void clone_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
update_rect->y = y - 15;
update_rect->w = 32;
update_rect->h = 32;
} else if (clone_state == CLONE_CLONING) {
}
else if (clone_state == CLONE_CLONING)
{
/* Step 2 - Starting a clone (hopefully holding mouse down here) */
clone_doit(api, which, canvas, clone_last, x, y, x, y, update_rect, 0);
}
@ -268,18 +292,24 @@ 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)
{
if (clone_state == CLONE_STARTING) {
/* Release of the initial click (to pick initial source position);
now ready for second click (to begin cloning) */
clone_state = CLONE_CLONING;
} else {
}
else
{
done_cloning(api, canvas, update_rect);
}
}
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! */
/* Erase crosshairs from source position, now that we're all done */
@ -297,10 +327,12 @@ void done_cloning(magic_api * api, SDL_Surface * canvas, SDL_Rect * update_rect)
api->stopsound();
}
void clone_crosshairs(magic_api * api, SDL_Surface * canvas, int x, int y) {
void clone_crosshairs(magic_api * api, SDL_Surface * canvas, int x, int y)
{
int i;
for (i = -15; i < 16; i++) {
for (i = -15; i < 16; i++)
{
api->xorpixel(canvas, x + i, y);
api->xorpixel(canvas, x, y + i);
}
@ -314,20 +346,26 @@ void clone_shutdown(magic_api * api ATTRIBUTE_UNUSED)
Mix_FreeChunk(clone_start_snd);
}
void clone_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 ATTRIBUTE_UNUSED r, Uint8 ATTRIBUTE_UNUSED g, Uint8 ATTRIBUTE_UNUSED b)
void clone_set_color(magic_api * api ATTRIBUTE_UNUSED,
Uint8 ATTRIBUTE_UNUSED r, Uint8 ATTRIBUTE_UNUSED g,
Uint8 ATTRIBUTE_UNUSED b)
{
}
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)
void clone_switchin(magic_api * api 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,
clone_last =
SDL_CreateRGBSurface(0, canvas->w, canvas->h,
canvas->format->BitsPerPixel, canvas->format->Rmask,
canvas->format->Gmask, canvas->format->Bmask,
canvas->format->Amask);
clone_state = CLONE_READY_TO_START;

View file

@ -33,21 +33,26 @@ 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);
Uint32 confetti_api_version(void)
{
@ -65,7 +70,8 @@ int confetti_init(magic_api * api)
{
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);
@ -80,34 +86,43 @@ 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;
}
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)
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)
{
}
@ -160,23 +175,27 @@ 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,7 +231,8 @@ 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;
@ -232,17 +252,20 @@ void confetti_drag(magic_api * api, int which, SDL_Surface * canvas,
confetti_click(api, which, MODE_PAINT, canvas, snapshot, x, y, update_rect);
}
void confetti_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
void confetti_switchin(magic_api * api 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,
void confetti_switchout(magic_api * api 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);
}

View file

@ -65,19 +65,26 @@ 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);
void distortion_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 distortion_release(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect);
void distortion_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
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);
/* Setup Functions: */
@ -95,7 +102,8 @@ int distortion_init(magic_api * api)
{
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!
@ -119,7 +127,8 @@ 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:
@ -130,7 +139,8 @@ 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")));
}
@ -138,7 +148,8 @@ char *distortion_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_
// 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;
}
@ -146,15 +157,19 @@ int distortion_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_U
// Report our "Magic" tool descriptions
char *distortion_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
char *distortion_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 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;
}
@ -174,7 +189,8 @@ 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);
}
@ -183,9 +199,11 @@ 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)
@ -217,14 +235,18 @@ void distortion_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on release:
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)
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)
{
}
void distortion_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
void distortion_set_color(magic_api * api ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED)
{
}
@ -233,7 +255,8 @@ void distortion_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UN
// 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;
@ -249,23 +272,29 @@ static void distortion_line_callback(void *ptr, int which ATTRIBUTE_UNUSED,
{
if (api->in_circle(xx, yy, 8))
{
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,
void distortion_switchin(magic_api * api 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,
void distortion_switchout(magic_api * api 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);
}

View file

@ -47,19 +47,24 @@ 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, Uint8 r, Uint8 g, Uint8 b);
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);
@ -74,7 +79,8 @@ int emboss_init(magic_api * api)
{
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);
@ -91,28 +97,34 @@ 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.")));
}
@ -120,7 +132,9 @@ char *emboss_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBU
// 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;
int r;
@ -150,7 +164,8 @@ static void emboss_pixel(void * ptr, SDL_Surface * last, int x, int y, SDL_Surfa
// 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;
@ -172,7 +187,8 @@ static void do_emboss(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canva
// 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);
@ -201,17 +217,24 @@ 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)
{
if (mode == MODE_PAINT) {
emboss_drag(api, which, canvas, last, x, y, x, y, update_rect);
} else {
for (y = 0; y < canvas->h; y++) {
if (y % 10 == 0) {
}
else
{
for (y = 0; y < canvas->h; y++)
{
if (y % 10 == 0)
{
api->update_progress_bar();
}
for (x = 0; x < canvas->w; x++) {
for (x = 0; x < canvas->w; x++)
{
emboss_pixel(api, last, x, y, canvas);
}
}
@ -224,9 +247,12 @@ void emboss_click(magic_api * api, int which, int mode,
}
// Affect the canvas on release:
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)
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)
{
}
@ -238,23 +264,27 @@ void emboss_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void emboss_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
void emboss_set_color(magic_api * api ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b 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,
void emboss_switchin(magic_api * api 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,
void emboss_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}

View file

@ -52,29 +52,38 @@ 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);
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 * 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);
void fade_darken_shutdown(magic_api * api);
void fade_darken_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
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);
int fade_darken_init(magic_api * api)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%ssounds/magic/fade.wav", api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/fade.wav",
api->data_directory);
snd_effects[TOOL_FADE] = Mix_LoadWAV(fname);
snprintf(fname, sizeof(fname), "%ssounds/magic/darken.wav", api->data_directory);
snprintf(fname, sizeof(fname), "%ssounds/magic/darken.wav",
api->data_directory);
snd_effects[TOOL_DARKEN] = Mix_LoadWAV(fname);
return (1);
@ -98,11 +107,13 @@ SDL_Surface *fade_darken_get_icon(magic_api * api, int which)
if (which == TOOL_FADE)
{
snprintf(fname, sizeof(fname), "%simages/magic/fade.png", api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/fade.png",
api->data_directory);
}
else if (which == TOOL_DARKEN)
{
snprintf(fname, sizeof(fname), "%simages/magic/darken.png", api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/darken.png",
api->data_directory);
}
return (IMG_Load(fname));
@ -120,25 +131,31 @@ 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)
{
if (which == TOOL_FADE)
{
if (mode == MODE_PAINT)
return (strdup(gettext_noop("Click and drag the mouse to lighten parts of your picture.")));
return (strdup
(gettext_noop
("Click and drag the mouse to lighten parts of your picture.")));
else if (mode == MODE_FULLSCREEN)
return (strdup(gettext_noop("Click to lighten your entire picture.")));
}
else if (which == TOOL_DARKEN)
{
if (mode == MODE_PAINT)
return (strdup(gettext_noop("Click and drag the mouse to darken parts of your picture.")));
return (strdup
(gettext_noop
("Click and drag the mouse to darken parts of your picture.")));
else if (mode == MODE_FULLSCREEN)
return (strdup(gettext_noop("Click to darken your entire picture.")));
}
@ -146,7 +163,8 @@ char *fade_darken_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, i
return (NULL);
}
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;
@ -170,7 +188,8 @@ static void do_fade_darken(void *ptr, int which, SDL_Surface * canvas, SDL_Surfa
}
// 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;
@ -189,12 +208,14 @@ static void do_fade_darken_paint(void *ptr, int which, SDL_Surface * canvas, SDL
// 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);
@ -225,7 +246,8 @@ 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);
@ -247,9 +269,12 @@ void fade_darken_click(magic_api * api, int which, int mode,
}
// Release
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)
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)
{
}
@ -265,27 +290,34 @@ void fade_darken_shutdown(magic_api * api ATTRIBUTE_UNUSED)
// We don't use colors
void fade_darken_set_color(magic_api * api ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED)
{
}
// 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)
{
return 0;
}
void fade_darken_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
void fade_darken_switchin(magic_api * api 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,
void fade_darken_switchout(magic_api * api 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);
}

View file

@ -45,29 +45,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);
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);
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);
int fisheye_modes(magic_api * api, int which);
// 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, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
void fisheye_set_color(magic_api * api ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED)
{
@ -77,7 +84,8 @@ int fisheye_init(magic_api * api)
{
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);
@ -92,34 +100,45 @@ 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;
}
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)
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)
{
}
@ -131,8 +150,8 @@ void fisheye_shutdown(magic_api * api ATTRIBUTE_UNUSED)
// do-fisheye
void fisheye_draw(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
int x, int y)
void fisheye_draw(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
{
magic_api *api = (magic_api *) ptr;
@ -147,13 +166,15 @@ void fisheye_draw(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, S
last_x = x;
last_y = y;
oryg = SDL_CreateRGBSurface(SDL_SWSURFACE, 80, 80, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask,
canvas->format->Amask);
oryg =
SDL_CreateRGBSurface(SDL_SWSURFACE, 80, 80, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask,
canvas->format->Bmask, canvas->format->Amask);
output = SDL_CreateRGBSurface(SDL_SWSURFACE, 80, 80, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask,
canvas->format->Amask);
output =
SDL_CreateRGBSurface(SDL_SWSURFACE, 80, 80, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask,
canvas->format->Bmask, canvas->format->Amask);
rect.x = x - 40;
rect.y = y - 40;
@ -164,9 +185,10 @@ void fisheye_draw(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, S
//do vertical fisheye
for (i = 0; i < 40; i++)
{
temp_src = SDL_CreateRGBSurface(SDL_SWSURFACE, 1, 80, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask,
canvas->format->Amask);
temp_src =
SDL_CreateRGBSurface(SDL_SWSURFACE, 1, 80, canvas->format->BitsPerPixel,
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
@ -176,9 +198,11 @@ void fisheye_draw(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, S
SDL_BlitSurface(oryg, &rect, temp_src, NULL); //this bar is copied to temp_src
temp_dest = SDL_CreateRGBSurface(SDL_SWSURFACE, 1, 80 + 2 * i, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask,
canvas->format->Amask);
temp_dest =
SDL_CreateRGBSurface(SDL_SWSURFACE, 1, 80 + 2 * i,
canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask,
canvas->format->Bmask, canvas->format->Amask);
temp_dest = api->scale(temp_src, 1, 80 + 2 * i, 0); //temp_dest stores scaled temp_src
@ -203,13 +227,16 @@ void fisheye_draw(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, S
//do horizontal fisheye
for (i = 0; i < 40; i++)
{
temp_src = SDL_CreateRGBSurface(SDL_SWSURFACE, 80, 1, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask,
canvas->format->Amask);
temp_src =
SDL_CreateRGBSurface(SDL_SWSURFACE, 80, 1, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask,
canvas->format->Bmask, canvas->format->Amask);
temp_dest = SDL_CreateRGBSurface(SDL_SWSURFACE, 80 + 2 * i, 1, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask,
canvas->format->Amask);
temp_dest =
SDL_CreateRGBSurface(SDL_SWSURFACE, 80 + 2 * i, 1,
canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask,
canvas->format->Bmask, canvas->format->Amask);
//upper side first
rect.x = 0;
@ -247,7 +274,8 @@ void fisheye_draw(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, S
for (xx = x - 40; xx < x + 40; xx++)
if (api->in_circle(xx - x, yy - y, 40))
api->putpixel(canvas, xx, yy, api->getpixel(output, xx + 40 - x, yy + 40 - y));
api->putpixel(canvas, xx, yy,
api->getpixel(output, xx + 40 - x, yy + 40 - y));
SDL_FreeSurface(oryg);
@ -259,7 +287,8 @@ void fisheye_draw(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, S
}
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);
@ -270,26 +299,30 @@ 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 = -80; /* A value that will be beyond any clicked position */
last_y = -80;
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,
void fisheye_switchin(magic_api * api 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,
void fisheye_switchout(magic_api * api 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);
}

View file

@ -51,7 +51,8 @@ static Uint8 flower_r, flower_g, flower_b;
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, *flower_leaf, *flower_petals, *flower_petals_colorized;
static SDL_Surface *flower_base, *flower_leaf, *flower_petals,
*flower_petals_colorized;
/* Local function prototypes: */
@ -61,9 +62,11 @@ 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);
static void flower_colorize_petals(magic_api * api);
Uint32 flower_api_version(void);
int flower_init(magic_api * api);
@ -72,25 +75,32 @@ 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);
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);
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_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, Uint8 r, Uint8 g, Uint8 b);
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);
@ -106,19 +116,24 @@ int flower_init(magic_api * api)
{
char fname[1024];
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);
flower_base = IMG_Load(fname);
snprintf(fname, sizeof(fname), "%simages/magic/flower_leaf.png", api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/flower_leaf.png",
api->data_directory);
flower_leaf = IMG_Load(fname);
snprintf(fname, sizeof(fname), "%simages/magic/flower_petals.png", api->data_directory);
snprintf(fname, sizeof(fname), "%simages/magic/flower_petals.png",
api->data_directory);
flower_petals = IMG_Load(fname);
return (1);
@ -135,32 +150,41 @@ 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)
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)
{
if (x < flower_min_x)
flower_min_x = x;
@ -193,8 +217,9 @@ static void flower_predrag(magic_api * api ATTRIBUTE_UNUSED, SDL_Surface * canva
}
}
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)
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)
{
flower_predrag(api, canvas, last, ox, oy, x, y);
@ -207,7 +232,8 @@ void flower_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface * canv
/* 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);
@ -219,7 +245,8 @@ void flower_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface * canv
// 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;
@ -236,7 +263,8 @@ 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: */
@ -256,7 +284,8 @@ 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);
@ -272,7 +301,8 @@ 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;
@ -282,7 +312,8 @@ static void flower_drawflower(magic_api * api ATTRIBUTE_UNUSED, SDL_Surface * ca
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;
@ -292,8 +323,10 @@ static void flower_drawbase(magic_api * api ATTRIBUTE_UNUSED, SDL_Surface * canv
SDL_BlitSurface(flower_base, NULL, canvas, &dest);
}
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)
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)
{
Point2D control_points[4];
Point2D *curve;
@ -363,7 +396,8 @@ static void flower_drawstalk(magic_api * api ATTRIBUTE_UNUSED, SDL_Surface * can
/* When we're done (final render), we can add some random leaves: */
if (final && i > 32 && i < n_points - 32 && (i % 16) == 0 && (rand() % 5) > 0)
if (final && i > 32 && i < n_points - 32 && (i % 16) == 0
&& (rand() % 5) > 0)
{
/* Check for hard left/right angles: */
@ -492,7 +526,8 @@ void flower_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b)
}
// 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;
}
@ -547,7 +582,8 @@ 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;
@ -570,7 +606,9 @@ static void flower_colorize_petals(magic_api * api)
/* 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,
@ -578,7 +616,8 @@ 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: */
@ -589,15 +628,19 @@ 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), 8))
if (api->in_circle
((x - flower_petals->w / 2), (y - flower_petals->h / 2), 8))
{
api->putpixel(flower_petals_colorized, x, y,
SDL_MapRGBA(flower_petals_colorized->format, 0xFF, 0xFF, 0x00, a));
SDL_MapRGBA(flower_petals_colorized->format, 0xFF, 0xFF,
0x00, a));
}
}
}
@ -606,12 +649,14 @@ static void flower_colorize_petals(magic_api * api)
SDL_UnlockSurface(flower_petals);
}
void flower_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
void flower_switchin(magic_api * api 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,
void flower_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}

View file

@ -46,16 +46,22 @@ Uint32 foam_api_version(void);
int foam_init(magic_api * api);
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);
SDL_Surface * canvas, SDL_Surface * last, int x, int y,
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);
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 * 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, Uint8 r, Uint8 g, Uint8 b);
void foam_shutdown(magic_api * api);
int foam_get_tool_count(magic_api * api);
@ -77,16 +83,26 @@ int foam_init(magic_api * api)
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, 0);
foam_5 = api->scale(foam_data, ((api->canvas_w / FOAM_PROP) * 3) / 4, ((api->canvas_h / FOAM_PROP) * 3) / 4, 0);
foam_3 = api->scale(foam_data, ((api->canvas_w / FOAM_PROP) * 2) / 4, ((api->canvas_h / FOAM_PROP) * 2) / 4, 0);
foam_1 = api->scale(foam_data, ((api->canvas_w / FOAM_PROP) * 1) / 4, ((api->canvas_h / FOAM_PROP) * 1) / 4, 0);
foam_7 =
api->scale(foam_data, ((api->canvas_w / FOAM_PROP) * 4) / 4,
((api->canvas_h / FOAM_PROP) * 4) / 4, 0);
foam_5 =
api->scale(foam_data, ((api->canvas_w / FOAM_PROP) * 3) / 4,
((api->canvas_h / FOAM_PROP) * 3) / 4, 0);
foam_3 =
api->scale(foam_data, ((api->canvas_w / FOAM_PROP) * 2) / 4,
((api->canvas_h / FOAM_PROP) * 2) / 4, 0);
foam_1 =
api->scale(foam_data, ((api->canvas_w / FOAM_PROP) * 1) / 4,
((api->canvas_h / FOAM_PROP) * 1) / 4, 0);
SDL_FreeSurface(foam_data);
@ -104,32 +120,40 @@ 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,
static void do_foam(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
{
magic_api *api = (magic_api *) ptr;
@ -157,7 +181,8 @@ static void do_foam(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas
// 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);
@ -188,9 +213,10 @@ 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)
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)
{
int i;
@ -232,9 +258,10 @@ 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)
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)
{
int xx, yy;
int changes, max_iters;
@ -244,7 +271,8 @@ void foam_release(magic_api * api ATTRIBUTE_UNUSED ATTRIBUTE_UNUSED, int which A
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;
@ -402,7 +430,8 @@ void foam_release(magic_api * api ATTRIBUTE_UNUSED ATTRIBUTE_UNUSED, int which A
}
}
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;
@ -431,7 +460,8 @@ void foam_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void foam_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b)
void foam_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g,
Uint8 b)
{
foam_r = r;
foam_g = g;
@ -439,17 +469,20 @@ void foam_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b)
}
// 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,
void foam_switchin(magic_api * api 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,
void foam_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}

View file

@ -32,15 +32,21 @@ 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, Uint8 r, Uint8 g, Uint8 b);
int fold_init(magic_api * api);
@ -51,21 +57,27 @@ 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);
Uint32 fold_api_version(void)
{
@ -83,7 +95,8 @@ int fold_init(magic_api * api)
{
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);
@ -94,50 +107,65 @@ 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;
SDL_GetRGBA(api->getpixel(temp, x, y), temp->format, &r, &g, &b, &a);
api->putpixel(canvas, x, y, SDL_MapRGBA(canvas->format,
max(r - 160 + fold_shadow_value * 4, 0), max(g - 160 + fold_shadow_value * 4,
max(r - 160 + fold_shadow_value * 4,
0),
max(b - 160 + fold_shadow_value * 4, 0), a));
max(g - 160 + fold_shadow_value * 4,
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;
@ -145,8 +173,10 @@ void fold_draw(magic_api * api, int which,
float w, h;
SDL_Surface *temp;
temp = SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask,
temp =
SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h,
canvas->format->BitsPerPixel, canvas->format->Rmask,
canvas->format->Gmask, canvas->format->Bmask,
canvas->format->Amask);
SDL_BlitSurface(canvas, 0, temp, 0);
@ -164,7 +194,8 @@ 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));
}
}
@ -173,58 +204,72 @@ 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,
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, left_arm_x + fold_shadow_value * right_step_x,
fold_shadow_value * right_step_y, fold_shadow_value * left_step_x,
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);
}
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);
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);
}
@ -235,13 +280,17 @@ SDL_Surface *rotate(magic_api * api, SDL_Surface * canvas, int angle)
int a, b;
if (angle == 180)
temp = SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask,
canvas->format->Amask);
temp =
SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h,
canvas->format->BitsPerPixel,
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);
temp =
SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->h, canvas->w,
canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask,
canvas->format->Bmask, canvas->format->Amask);
switch (angle)
{
@ -308,7 +357,8 @@ 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)
{
@ -328,7 +378,8 @@ void translate_xy(SDL_Surface * canvas, int x, int y, int *a, int *b, int rotati
}
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;
@ -411,32 +462,38 @@ 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)
static void fold_print_line(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, int x,
int y)
{
magic_api *api = (magic_api *) ptr;
api->putpixel(canvas, x, y, SDL_MapRGB(last->format, 222, 222, 222)); //Middle gray. Color have been set arbitrary.
}
static void fold_print_dark_line(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
static void fold_print_dark_line(void *ptr, int which ATTRIBUTE_UNUSED,
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(last->format, 90, 90, 90)); //It should not look too black nor too white with shadowed colors.
}
static void fold_erase(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
int x, int y)
static void fold_erase(void *ptr, int which ATTRIBUTE_UNUSED,
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;
@ -465,7 +522,8 @@ 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_Surface * snapshot, int ox ATTRIBUTE_UNUSED,
int oy ATTRIBUTE_UNUSED, int x, int y,
SDL_Rect * update_rect)
{
int middle_point_x;
@ -481,49 +539,67 @@ 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);
fold_oy - (fold_oy - middle_point_y) - (fold_ox -
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);
fold_oy - (fold_oy - middle_point_y) - (fold_ox -
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);
fold_oy - (fold_oy - middle_point_y) - (fold_ox -
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);
fold_ox - (fold_ox - middle_point_x) - (fold_oy -
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;
@ -531,7 +607,8 @@ 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);
@ -539,12 +616,14 @@ void fold_drag(magic_api * api, int which, SDL_Surface * canvas,
fold_preview(api, which, canvas, snapshot, ox, oy, x, y, update_rect);
}
void fold_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
void fold_switchin(magic_api * api 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,
void fold_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}

View file

@ -49,7 +49,8 @@ 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
@ -57,7 +58,8 @@ static SDL_Surface *fretwork_one_back, *fretwork_three_back, *fretwork_four_back
Uint32 fretwork_api_version(void);
int fretwork_modes(magic_api * api, int which);
void fretwork_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
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);
int fretwork_get_tool_count(magic_api * api);
SDL_Surface *fretwork_get_icon(magic_api * api, int which);
@ -66,20 +68,28 @@ 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);
@ -90,7 +100,8 @@ 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);
}
@ -107,7 +118,8 @@ void fretwork_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b)
}
/* 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;
@ -121,7 +133,9 @@ static void fretwork_colorize(magic_api * api, SDL_Surface * dest, SDL_Surface *
{
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));
}
}
@ -140,10 +154,14 @@ int fretwork_init(magic_api * api)
for (i = 0; i < 4; i++)
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]);
@ -157,7 +175,8 @@ int fretwork_init(magic_api * api)
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);
@ -172,37 +191,48 @@ 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;
}
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)
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)
{
}
@ -229,13 +259,17 @@ void fretwork_shutdown(magic_api * api ATTRIBUTE_UNUSED)
free(fretwork_status_of_segments);
}
void fretwork_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * snapshot 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)
{
//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_backup =
SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h,
canvas->format->BitsPerPixel, canvas->format->Rmask,
canvas->format->Gmask, canvas->format->Bmask,
canvas->format->Amask);
SDL_BlitSurface(canvas, NULL, canvas_backup, NULL);
@ -246,8 +280,10 @@ void fretwork_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNU
}
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)
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)
{
free(fretwork_status_of_segments);
fretwork_status_of_segments = NULL;
@ -279,7 +315,9 @@ 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;
@ -296,17 +334,20 @@ inline void fretwork_extract_coords_from_segment(unsigned int segment, POINT_TYP
/* 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;
@ -329,7 +370,8 @@ static void fretwork_rotate(void *ptr, SDL_Surface * dest, SDL_Surface * src, _B
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;
@ -341,28 +383,30 @@ 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, bottom_y, img_w / 2,
fretwork_draw_wrapper);
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, right_x, bottom_y, img_w / 2,
fretwork_draw_wrapper);
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, right_x, bottom_y, img_w / 2,
fretwork_draw_wrapper);
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;
update_rect->x = 0;
@ -378,7 +422,8 @@ 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...
@ -395,22 +440,26 @@ 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;
@ -480,8 +529,10 @@ 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)
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)
{
magic_api *api = (magic_api *) ptr;
SDL_Surface *result, *temp;
@ -491,7 +542,8 @@ static void fretwork_draw(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * c
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;
@ -502,12 +554,20 @@ static void fretwork_draw(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * c
fretwork_status_of_segments[segment] = image; //and write it to global table
result = SDL_CreateRGBSurface(SDL_SWSURFACE, img_w, img_h, fretwork_one->format->BitsPerPixel,
fretwork_one->format->Rmask, fretwork_one->format->Gmask, fretwork_one->format->Bmask,
result =
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);
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,
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);
SDL_BlitSurface(canvas_backup, &modification_rect, result, NULL);
@ -580,17 +640,21 @@ static void fretwork_draw(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * c
}
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,
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;
@ -598,8 +662,10 @@ static void fretwork_draw_wrapper(void *ptr, int which, SDL_Surface * canvas, SD
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;
}
@ -607,14 +673,17 @@ static void fretwork_draw_wrapper(void *ptr, int which, SDL_Surface * canvas, SD
}
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)
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))
{
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);

View file

@ -46,18 +46,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);
void glasstile_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 glasstile_release(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
void glasstile_shutdown(magic_api * api);
void glasstile_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
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);
Uint32 glasstile_api_version(void)
@ -74,7 +80,8 @@ int glasstile_init(magic_api * api)
{
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;
@ -94,35 +101,45 @@ 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;
@ -156,10 +173,14 @@ static void do_glasstile(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * ca
{
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;
@ -205,7 +226,8 @@ static void do_glasstile(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * ca
// 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);
@ -240,7 +262,8 @@ 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;
@ -277,9 +300,12 @@ void glasstile_click(magic_api * api, int which, int mode,
}
// Affect the canvas on release:
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)
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)
{
}
@ -303,28 +329,34 @@ void glasstile_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void glasstile_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
void glasstile_set_color(magic_api * api ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b 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,
void glasstile_switchin(magic_api * api 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,
void glasstile_switchout(magic_api * api 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);
}

View file

@ -50,18 +50,22 @@ 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);
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, SDL_Surface * last, 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,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void grass_shutdown(magic_api * api);
void grass_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
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);
@ -70,10 +74,12 @@ int grass_init(magic_api * api)
{
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);
@ -97,33 +103,41 @@ 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);
@ -152,14 +166,18 @@ 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);
}
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)
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)
{
}
@ -171,7 +189,8 @@ void grass_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void grass_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b)
void grass_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g,
Uint8 b)
{
grass_r = r;
grass_g = g;
@ -179,13 +198,15 @@ void grass_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b
}
// 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;
@ -201,7 +222,9 @@ static void do_grass(void *ptr, int which ATTRIBUTE_UNUSED,
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;
@ -213,8 +236,10 @@ static void do_grass(void *ptr, int which ATTRIBUTE_UNUSED,
dest.x = x - 32;
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++)
@ -223,7 +248,8 @@ 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;
@ -232,13 +258,21 @@ 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));
}
}
}
@ -260,12 +294,14 @@ static int log2int(int x)
return y;
}
void grass_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
void grass_switchin(magic_api * api 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,
void grass_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}

View file

@ -59,8 +59,10 @@ 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);
int halftone_get_tool_count(magic_api * api);
@ -72,12 +74,16 @@ 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);
void halftone_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 halftone_release(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect);
void halftone_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
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[]);
Uint32 halftone_api_version(void)
@ -95,7 +101,8 @@ int halftone_init(magic_api * api)
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);
}
@ -113,7 +120,8 @@ 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));
}
@ -134,7 +142,8 @@ 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;
@ -145,12 +154,14 @@ char *halftone_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int
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);
}
@ -159,8 +170,10 @@ void halftone_shutdown(magic_api * api ATTRIBUTE_UNUSED)
{
int i;
for (i = 0; i < NUM_TOOLS; i++) {
if (snd_effect[i] != NULL) {
for (i = 0; i < NUM_TOOLS; i++)
{
if (snd_effect[i] != NULL)
{
Mix_FreeChunk(snd_effect[i]);
}
}
@ -170,7 +183,8 @@ 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;
@ -196,9 +210,11 @@ 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)
{
@ -252,20 +268,26 @@ int chan_angles[NUM_CHANS] = {
45 /* Black */
};
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)
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)
{
}
void halftone_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED,
Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
void halftone_set_color(magic_api * api ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b 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;
@ -296,7 +318,8 @@ 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;
@ -339,12 +362,12 @@ 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);
pixel = SDL_MapRGB(square->format,
min((Uint8) (r * 2.0), or),
min((Uint8) (g * 2.0), og),
min((Uint8) (b * 2.0), 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));
api->putpixel(square, sqx, sqy, pixel);
}
}
@ -360,27 +383,33 @@ 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);
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);
}
if (square == NULL)
{
square =
SDL_CreateRGBSurface(SDL_SWSURFACE, GRID_SIZE, GRID_SIZE, canvas->format->BitsPerPixel, canvas->format->Rmask,
canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
SDL_CreateRGBSurface(SDL_SWSURFACE, GRID_SIZE, GRID_SIZE,
canvas->format->BitsPerPixel,
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)
void halftone_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}

View file

@ -67,18 +67,24 @@ 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);
void kalidescope_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 kalidescope_release(magic_api * api, int which, SDL_Surface * canvas,
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);
void kalidescope_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
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);
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)
@ -91,7 +97,8 @@ int kalidescope_init(magic_api * api)
{
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);
@ -107,7 +114,8 @@ 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));
}
@ -138,14 +146,16 @@ 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)
{
@ -161,15 +171,21 @@ char *kalidescope_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, i
}
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).")));
}
}
@ -183,7 +199,8 @@ 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 = -8; yy < 8; yy++)
{
@ -199,7 +216,8 @@ 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)
@ -211,9 +229,11 @@ 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);
}
}
}
@ -223,9 +243,11 @@ 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;
@ -237,15 +259,18 @@ 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);
}
// Affect the canvas on release:
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)
SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED,
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
api->stopsound();
}
@ -258,7 +283,8 @@ void kalidescope_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void kalidescope_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b)
void kalidescope_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g,
Uint8 b)
{
kalidescope_r = r;
kalidescope_g = g;
@ -266,22 +292,28 @@ void kalidescope_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, U
}
// 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;
}
void kalidescope_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void kalidescope_switchin(magic_api * api 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)
void kalidescope_switchout(magic_api * api 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

@ -47,18 +47,22 @@ 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);
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, SDL_Surface * last, 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,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void light_shutdown(magic_api * api);
void light_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
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);
@ -73,10 +77,12 @@ int light_init(magic_api * api)
{
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);
@ -93,33 +99,41 @@ 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)
static void do_light(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas,
SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
{
magic_api *api = (magic_api *) ptr;
int xx, yy;
@ -171,7 +185,8 @@ static void do_light(void *ptr, int which ATTRIBUTE_UNUSED, 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));
}
}
}
@ -179,7 +194,8 @@ static void do_light(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas
// 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);
@ -208,7 +224,8 @@ 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);
}
@ -216,7 +233,8 @@ 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);
}
@ -237,17 +255,20 @@ void light_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b)
}
// 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,
void light_switchin(magic_api * api 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,
void light_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}

View file

@ -31,16 +31,24 @@ 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, Uint8 r, Uint8 g, Uint8 b);
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);
void lightning_draw_bolt(void * ptr, SDL_Surface * canvas, 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 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);
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);
Uint32 lightning_api_version(void)
@ -52,7 +60,8 @@ int lightning_init(magic_api * api)
{
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);
@ -68,32 +77,41 @@ 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;
}
@ -107,7 +125,8 @@ 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;
@ -117,8 +136,8 @@ lightning_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
void
lightning_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)
SDL_Surface * snapshot, int ox ATTRIBUTE_UNUSED,
int oy ATTRIBUTE_UNUSED, int x, int y, SDL_Rect * update_rect)
{
/* FIXME: This could be made more efficient
(only blit and update between (sx,sy) and (x,y), though
@ -131,13 +150,15 @@ 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;
@ -168,7 +189,8 @@ lightning_release(magic_api * api, int which ATTRIBUTE_UNUSED,
angle = -angle;
#ifdef DEBUG
printf("(%d,%d)->(%d,%d) => a = %.2f, b = %.2f, c (len) = %.2f; angle = %.2f degrees\n",
printf
("(%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
@ -177,10 +199,13 @@ 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)
void lightning_draw_bolt(void *ptr, SDL_Surface * canvas,
SDL_Surface * snapshot, float sx, float sy,
float angle, float len, int thickness)
{
magic_api *api = (magic_api *) ptr;
float i;
@ -220,7 +245,8 @@ void lightning_draw_bolt(void * ptr, SDL_Surface * canvas, SDL_Surface * snapsho
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);
@ -245,12 +271,14 @@ void lightning_draw_bolt(void * ptr, SDL_Surface * canvas, SDL_Surface * snapsho
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;
@ -266,8 +294,7 @@ void lightning_draw_bolt(void * ptr, SDL_Surface * canvas, SDL_Surface * snapsho
lightning_draw_bolt((void *) api, canvas, snapshot, x, y,
new_angle,
((len / 8) + (rand() % (int) (len / 4))),
thickness - 1
);
thickness - 1);
}
}
}
@ -279,17 +306,25 @@ void lightning_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b)
}
void lightning_line_callback_drag(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
void lightning_line_callback_drag(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas,
SDL_Surface * snapshot ATTRIBUTE_UNUSED,
int x, int y)
{
magic_api *api = (magic_api *) ptr;
api->xorpixel(canvas, x, y);
}
void lightning_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void lightning_switchin(magic_api * api 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)
void lightning_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}

View file

@ -45,18 +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);
void metalpaint_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 metalpaint_release(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
void metalpaint_shutdown(magic_api * api);
void metalpaint_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
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);
@ -71,7 +77,8 @@ int metalpaint_init(magic_api * api)
{
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);
@ -88,28 +95,34 @@ 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,
char *metalpaint_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 paint with a metallic color.")));
return (strdup
(gettext_noop
("Click and drag the mouse to paint with a metallic color.")));
}
#define METALPAINT_CYCLE 32
@ -125,7 +138,8 @@ static int metalpaint_gradient[METALPAINT_CYCLE] = {
// Do the effect:
static void do_metalpaint(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
static void do_metalpaint(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas,
SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
{
magic_api *api = (magic_api *) ptr;
@ -143,16 +157,19 @@ static void do_metalpaint(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * c
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)
{
@ -179,15 +196,19 @@ 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);
}
// Affect the canvas on release:
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)
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)
{
}
@ -199,7 +220,8 @@ void metalpaint_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void metalpaint_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b)
void metalpaint_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g,
Uint8 b)
{
metalpaint_r = min(255, r + 64);
metalpaint_g = min(255, g + 64);
@ -207,22 +229,28 @@ void metalpaint_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Ui
}
// 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,
void metalpaint_switchin(magic_api * api 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,
void metalpaint_switchout(magic_api * api 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);
}

View file

@ -52,9 +52,12 @@ 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 *, Uint8, Uint8, Uint8);
int mirror_flip_requires_colors(magic_api *, int);
@ -67,10 +70,12 @@ int mirror_flip_init(magic_api * api)
{
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);
@ -94,11 +99,13 @@ 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));
@ -116,13 +123,15 @@ 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.")));
@ -134,19 +143,23 @@ char *mirror_flip_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, i
// We affect the whole canvas, so only do things on click, not drag:
void mirror_flip_drag(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, SDL_Surface * canvas 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 x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
// No-op
}
void mirror_flip_release(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, SDL_Surface * canvas 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 x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
// No-op
}
@ -154,7 +167,8 @@ 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;
@ -213,27 +227,34 @@ void mirror_flip_shutdown(magic_api * api ATTRIBUTE_UNUSED)
// We don't use colors:
void mirror_flip_set_color(magic_api * api ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b 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);
}

View file

@ -45,9 +45,12 @@
#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 */
@ -59,9 +62,12 @@ 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 *, Uint8, Uint8, Uint8);
int mosaic_requires_colors(magic_api *, int);
@ -102,7 +108,8 @@ 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."),},
};
@ -120,7 +127,8 @@ int mosaic_init(magic_api * api)
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);
}
@ -137,7 +145,8 @@ 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));
}
@ -154,7 +163,8 @@ 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])));
}
@ -167,21 +177,25 @@ 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, amask);
canvas->format->Bmask,
amask);
@ -211,17 +225,21 @@ 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 */
@ -240,7 +258,8 @@ 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);
@ -254,7 +273,8 @@ 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)
@ -278,7 +298,8 @@ 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)
{
}
@ -299,18 +320,21 @@ void mosaic_shutdown(magic_api * api ATTRIBUTE_UNUSED)
// Record the color from Tux Paint:
void mosaic_set_color(magic_api * api ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b 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;
@ -318,16 +342,21 @@ static void mosaic_noise_pixel(void *ptr, SDL_Surface * canvas, int noise_AMOUNT
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;
@ -352,7 +381,8 @@ static void mosaic_blur_pixel(void *ptr, SDL_Surface * canvas, SDL_Surface * las
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];
@ -363,11 +393,14 @@ static void mosaic_blur_pixel(void *ptr, SDL_Surface * canvas, SDL_Surface * las
{
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;
@ -395,7 +428,8 @@ static void mosaic_sharpen_pixel(void *ptr, SDL_Surface * canvas, SDL_Surface *
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];
@ -406,13 +440,16 @@ static void mosaic_sharpen_pixel(void *ptr, SDL_Surface * canvas, SDL_Surface *
temp = (temp / 1443) * 255.0;
SDL_GetRGB(api->getpixel(last, x, y), last->format, &r1, &g1, &b1);
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, clamp(0.0, r1 + mosaic_SHARPEN * temp, 255.0),
api->putpixel(canvas, x, y,
SDL_MapRGB(canvas->format,
clamp(0.0, r1 + mosaic_SHARPEN * temp, 255.0),
clamp(0.0, g1 + mosaic_SHARPEN * temp, 255.0),
clamp(0.0, b1 + mosaic_SHARPEN * temp, 255.0)));
}
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;
@ -424,13 +461,16 @@ void mosaic_switchin(magic_api * api, int which ATTRIBUTE_UNUSED, int mode ATTRI
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);
@ -446,18 +486,23 @@ void mosaic_switchin(magic_api * api, int which ATTRIBUTE_UNUSED, int mode ATTRI
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);

View file

@ -49,14 +49,20 @@
#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,
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);
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);
@ -68,13 +74,16 @@ 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);
@ -82,20 +91,24 @@ void mosaic_shaped_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
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 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);
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
@ -138,17 +151,20 @@ 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."),
},
};
@ -168,7 +184,8 @@ int mosaic_shaped_init(magic_api * api)
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);
}
@ -185,7 +202,8 @@ 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));
}
@ -196,13 +214,15 @@ 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])));
}
@ -214,14 +234,18 @@ 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)
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 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)
{
@ -238,17 +262,23 @@ static void do_mosaic_shaped_full(void *ptr, SDL_Surface * canvas, SDL_Surface *
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)
{
reset_counter(canvas, mosaic_shaped_counted);
size = 0;
pixel_average =
SDL_MapRGB(canvas->format, 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);
SDL_MapRGB(canvas->format,
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);
}
}
}
@ -256,8 +286,10 @@ static void do_mosaic_shaped_full(void *ptr, SDL_Surface * canvas, SDL_Surface *
}
/* 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)
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)
{
Uint32 mosaic_shaped_color;
int size;
@ -265,7 +297,9 @@ static void mosaic_shaped_fill(void *ptr_to_api, int which ATTRIBUTE_UNUSED, SDL
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;
@ -282,7 +316,8 @@ static void mosaic_shaped_fill(void *ptr_to_api, int which ATTRIBUTE_UNUSED, SDL
{
size = 0;
pixel_average =
SDL_MapRGB(canvas->format, mosaic_shaped_average_r / mosaic_shaped_average_count,
SDL_MapRGB(canvas->format,
mosaic_shaped_average_r / mosaic_shaped_average_count,
mosaic_shaped_average_g / mosaic_shaped_average_count,
mosaic_shaped_average_b / mosaic_shaped_average_count);
reset_counter(canvas, mosaic_shaped_counted);
@ -292,7 +327,8 @@ static void mosaic_shaped_fill(void *ptr_to_api, int which ATTRIBUTE_UNUSED, SDL
// 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;
@ -304,7 +340,8 @@ 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)
{
@ -322,9 +359,12 @@ void mosaic_shaped_click(magic_api * api, int which, int mode,
}
// Affect the canvas on release:
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)
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)
{
}
@ -344,7 +384,8 @@ 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, Uint8 r, Uint8 g, Uint8 b)
void mosaic_shaped_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r,
Uint8 g, Uint8 b)
{
mosaic_shaped_r = r;
mosaic_shaped_g = g;
@ -352,14 +393,16 @@ void mosaic_shaped_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g,
}
// 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;
@ -385,7 +428,8 @@ 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];
@ -397,13 +441,15 @@ 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;
@ -411,7 +457,8 @@ void mosaic_shaped_switchin(magic_api * api, int which, int mode ATTRIBUTE_UNUSE
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)
{
@ -419,7 +466,8 @@ void mosaic_shaped_switchin(magic_api * api, int which, int mode ATTRIBUTE_UNUSE
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)
{
@ -427,13 +475,15 @@ void mosaic_shaped_switchin(magic_api * api, int which, int mode ATTRIBUTE_UNUSE
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);
@ -441,7 +491,8 @@ void mosaic_shaped_switchin(magic_api * api, int which, int mode ATTRIBUTE_UNUSE
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);
@ -454,42 +505,58 @@ void mosaic_shaped_switchin(magic_api * api, int which, int mode ATTRIBUTE_UNUSE
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));
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));
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, 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));
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));
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));
}
else if (which == TOOL_IRREGULAR)
{
@ -498,38 +565,68 @@ void mosaic_shaped_switchin(magic_api * api, int which, int mode ATTRIBUTE_UNUSE
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)
@ -539,30 +636,45 @@ void mosaic_shaped_switchin(magic_api * api, int which, int mode ATTRIBUTE_UNUSE
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));
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));
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));
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));
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));
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));
SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0,
SDL_ALPHA_OPAQUE));
}
@ -612,7 +724,9 @@ void mosaic_shaped_switchin(magic_api * api, int which, int mode ATTRIBUTE_UNUSE
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 */
@ -628,7 +742,9 @@ void mosaic_shaped_switchin(magic_api * api, int which, int mode ATTRIBUTE_UNUSE
reset_counter(canvas, mosaic_shaped_done);
}
void mosaic_shaped_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
void mosaic_shaped_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
SDL_FreeSurface(canvas_shaped);
@ -637,7 +753,8 @@ void mosaic_shaped_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBU
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);
}
@ -656,8 +773,9 @@ 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 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 leftx, rightx;
Uint8 r, g, b, a;
@ -707,7 +825,8 @@ int scan_fill(magic_api * api, SDL_Surface * canvas, SDL_Surface * srfc, int x,
}
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;
@ -716,13 +835,17 @@ int scan_fill(magic_api * api, SDL_Surface * canvas, SDL_Surface * srfc, int x,
}
/* 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--;
}
@ -732,12 +855,14 @@ int scan_fill(magic_api * api, SDL_Surface * canvas, SDL_Surface * srfc, int x,
{
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);
}
}
@ -746,7 +871,8 @@ int scan_fill(magic_api * api, SDL_Surface * canvas, SDL_Surface * srfc, int x,
}
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;
@ -764,19 +890,23 @@ 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)
static void mosaic_shaped_paint(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas,
SDL_Surface * last ATTRIBUTE_UNUSED, int x,
int y)
{
magic_api *api = (magic_api *) ptr;
int radius, shadow;
@ -823,7 +953,8 @@ static void mosaic_shaped_paint(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surfa
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));
}

View file

@ -42,19 +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);
void negative_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 negative_release(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
void negative_shutdown(magic_api * api);
void negative_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
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);
enum
@ -76,13 +82,14 @@ 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 to turn your painting into its 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.")},
};
@ -90,7 +97,8 @@ int negative_init(magic_api * api)
{
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);
@ -112,7 +120,8 @@ 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));
}
@ -123,28 +132,37 @@ 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;
if (mode == MODE_PAINT) {
if (mode == MODE_PAINT)
{
mode_idx = 0;
} else if (mode == MODE_FULLSCREEN) {
}
else if (mode == MODE_FULLSCREEN)
{
mode_idx = 1;
} else {
}
else
{
return NULL;
}
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;
@ -167,7 +185,8 @@ static void negative_calc(void *ptr, int which, Uint8 r, Uint8 g, Uint8 b, Uint8
}
// 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;
@ -181,7 +200,8 @@ static void do_negative(void *ptr, int which, SDL_Surface * canvas, SDL_Surface
{
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));
}
}
}
@ -189,7 +209,8 @@ static void do_negative(void *ptr, int which, SDL_Surface * canvas, SDL_Surface
// 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);
@ -225,7 +246,8 @@ 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);
@ -240,7 +262,8 @@ 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));
}
}
@ -254,9 +277,12 @@ void negative_click(magic_api * api, int which, int mode,
}
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)
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)
{
}
@ -268,29 +294,33 @@ void negative_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// We don't use colors
void negative_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
void negative_set_color(magic_api * api ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b 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,
void negative_switchin(magic_api * api 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,
void negative_switchout(magic_api * api 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);
}

View file

@ -71,7 +71,8 @@ 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,20 +82,26 @@ 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);
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, SDL_Surface * last, 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,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void noise_shutdown(magic_api * api);
void noise_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
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);
@ -113,7 +120,8 @@ int noise_init(magic_api * api)
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);
@ -129,7 +137,8 @@ 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));
}
@ -146,14 +155,16 @@ 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;
@ -161,17 +172,22 @@ 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;
@ -185,7 +201,8 @@ static void do_noise_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last, i
}
//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;
@ -194,7 +211,8 @@ static void do_noise_brush(void *ptr, int which, SDL_Surface * canvas, SDL_Surfa
{
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);
}
@ -204,10 +222,12 @@ static void do_noise_brush(void *ptr, int which, SDL_Surface * canvas, SDL_Surfa
// 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);
@ -234,7 +254,8 @@ 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);
@ -250,9 +271,12 @@ void noise_click(magic_api * api, int which, int mode,
}
// Affect the canvas on release:
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)
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)
{
}
@ -272,23 +296,27 @@ void noise_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void noise_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
void noise_set_color(magic_api * api ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b 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,
void noise_switchin(magic_api * api 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,
void noise_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}

View file

@ -53,7 +53,8 @@
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);
int perspective_get_tool_count(magic_api * api);
@ -64,13 +65,16 @@ 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);
@ -78,16 +82,20 @@ void perspective_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
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 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);
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);
@ -104,7 +112,8 @@ int dash;
int click_x, click_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;
@ -166,15 +175,19 @@ 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)
@ -190,7 +203,8 @@ int perspective_init(magic_api * api)
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);
@ -206,7 +220,8 @@ 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));
}
@ -217,13 +232,15 @@ 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])));
}
@ -231,7 +248,8 @@ char *perspective_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, i
// 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_Surface * last, int ox ATTRIBUTE_UNUSED,
int oy ATTRIBUTE_UNUSED, int x, int y,
SDL_Rect * update_rect)
{
switch (which)
@ -275,26 +293,30 @@ 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, obottom_left_x, obottom_left_y, 1,
perspective_line);
api->line(api, which, canvas, last, obottom_left_x, obottom_left_y, obottom_right_x, obottom_right_y, 1,
perspective_line);
api->line(api, which, canvas, last, obottom_right_x, obottom_right_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,
obottom_right_x, obottom_right_y, 1, perspective_line);
api->line(api, which, canvas, last, obottom_right_x, obottom_right_y,
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, 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, top_right_x, top_right_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,
top_right_x, top_right_y, 1, perspective_line);
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:
@ -309,7 +331,9 @@ 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);
@ -348,7 +372,8 @@ 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)
{
switch (which)
{
@ -445,7 +470,8 @@ 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 (which == TOOL_PANELS)
return;
@ -455,7 +481,9 @@ 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)
{
@ -515,16 +543,25 @@ void perspective_release(magic_api * api, int which,
{
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);
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)));
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));
}
}
}
@ -546,7 +583,9 @@ 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)
@ -591,7 +630,9 @@ 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);
@ -608,8 +649,10 @@ 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)
SDL_Surface * canvas,
SDL_Surface * last ATTRIBUTE_UNUSED,
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED,
SDL_Rect * update_rect, float step)
{
float i, j;
float ax, ay, bx, by, dx, dy;
@ -622,9 +665,12 @@ 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;
@ -657,7 +703,9 @@ void perspective_preview(magic_api * api, int which,
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));
}
}
@ -706,7 +754,8 @@ void perspective_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void perspective_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b)
void perspective_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g,
Uint8 b)
{
perspective_r = r;
perspective_g = g;
@ -721,8 +770,9 @@ int perspective_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which)
return 1;
}
void perspective_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas)
void perspective_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas)
{
Uint32 amask;
@ -732,25 +782,32 @@ void perspective_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_
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);
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);
SDL_BlitSurface(canvas, NULL, canvas_back, NULL);
}
void perspective_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
void perspective_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
SDL_FreeSurface(canvas_back);
@ -758,14 +815,18 @@ void perspective_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE
int perspective_modes(magic_api * api ATTRIBUTE_UNUSED, int which)
{
if (which == TOOL_PANELS) {
if (which == TOOL_PANELS)
{
return (MODE_FULLSCREEN);
} else {
}
else
{
return (MODE_PAINT_WITH_PREVIEW);
}
}
void perspective_line(void *ptr_to_api, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
void perspective_line(void *ptr_to_api, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas,
SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
{
magic_api *api = (magic_api *) ptr_to_api;

View file

@ -58,15 +58,19 @@ 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);
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, SDL_Surface * last, 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,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void pixels_shutdown(magic_api * api);
void pixels_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
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);
// No setup required:
@ -74,7 +78,8 @@ int pixels_init(magic_api * api)
{
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);
@ -96,25 +101,30 @@ 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.")));
@ -123,7 +133,9 @@ char *pixels_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBU
// 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)
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_Rect dest;
int pixel_size;
@ -135,12 +147,14 @@ static void do_pixels(void *ptr ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SD
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);
@ -169,14 +183,17 @@ 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);
}
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)
SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED,
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
api->stopsound();
}
@ -189,7 +206,8 @@ void pixels_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void pixels_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b)
void pixels_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g,
Uint8 b)
{
pixels_r = r;
pixels_g = g;
@ -197,18 +215,21 @@ void pixels_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8
}
// 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)
void pixels_switchin(magic_api * api 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)
void pixels_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}

View file

@ -57,19 +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, Uint8 r, Uint8 g, Uint8 b);
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);
Uint32 puzzle_api_version(void)
@ -81,7 +87,8 @@ int puzzle_init(magic_api * api)
{
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;
@ -96,32 +103,41 @@ 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."));
}
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)
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)
{
}
@ -131,12 +147,14 @@ void puzzle_shutdown(magic_api * api ATTRIBUTE_UNUSED)
Mix_FreeChunk(puzzle_snd);
}
void puzzle_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
void puzzle_set_color(magic_api * api ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b 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;
}
@ -148,18 +166,22 @@ int gcd(int a, int b) //greatest common divisor
return gcd(b, a % b);
}
void puzzle_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
void puzzle_switchin(magic_api * api ATTRIBUTE_UNUSED,
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;
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);
SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h,
canvas->format->BitsPerPixel, canvas->format->Rmask,
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,
void puzzle_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
SDL_FreeSurface(canvas_backup);
@ -172,7 +194,8 @@ 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)
{
@ -231,15 +254,21 @@ 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_Surface * last, int ox ATTRIBUTE_UNUSED,
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;
@ -248,7 +277,8 @@ 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);
}

View file

@ -53,25 +53,34 @@ 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);
void rails_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
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);
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);
static void rails_draw(void *ptr, int which, SDL_Surface * canvas,
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);
Uint32 rails_api_version(void)
{
@ -83,7 +92,8 @@ int rails_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
return (MODE_PAINT);
}
void rails_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
void rails_set_color(magic_api * api ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED)
{
}
@ -98,10 +108,14 @@ int rails_init(magic_api * api)
for (i = 0; i < 4; i++)
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]);
@ -111,7 +125,8 @@ int rails_init(magic_api * api)
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);
@ -126,34 +141,45 @@ 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;
}
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)
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)
{
}
@ -176,23 +202,28 @@ void rails_shutdown(magic_api * api ATTRIBUTE_UNUSED)
free(rails_status_of_segments);
}
void rails_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
void rails_switchin(magic_api * api ATTRIBUTE_UNUSED,
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_backup =
SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h,
canvas->format->BitsPerPixel, canvas->format->Rmask,
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,
void rails_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
if (rails_status_of_segments != NULL)
@ -229,7 +260,8 @@ 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;
@ -255,7 +287,8 @@ 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;
@ -277,7 +310,8 @@ static void rails_rotate(void *ptr, SDL_Surface * dest, SDL_Surface * src, unsig
}
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);
@ -288,7 +322,8 @@ 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...
@ -400,8 +435,10 @@ 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)
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)
{
magic_api *api = (magic_api *) ptr;
SDL_Surface *result, *temp;
@ -412,7 +449,8 @@ static void rails_draw(void *ptr, int which ATTRIBUTE_UNUSED, ATTRIBUTE_UNUSED S
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;
@ -424,13 +462,17 @@ static void rails_draw(void *ptr, int which ATTRIBUTE_UNUSED, ATTRIBUTE_UNUSED S
rails_status_of_segments[segment] = image; //and write it to global table
result = SDL_CreateRGBSurface(SDL_SWSURFACE, img_w, img_h, rails_one->format->BitsPerPixel,
rails_one->format->Rmask, rails_one->format->Gmask, rails_one->format->Bmask,
rails_one->format->Amask);
result =
SDL_CreateRGBSurface(SDL_SWSURFACE, img_w, img_h,
rails_one->format->BitsPerPixel,
rails_one->format->Rmask, rails_one->format->Gmask,
rails_one->format->Bmask, rails_one->format->Amask);
temp = SDL_CreateRGBSurface(SDL_SWSURFACE, img_w, img_h, rails_one->format->BitsPerPixel,
rails_one->format->Rmask, rails_one->format->Gmask, rails_one->format->Bmask,
rails_one->format->Amask);
temp =
SDL_CreateRGBSurface(SDL_SWSURFACE, img_w, img_h,
rails_one->format->BitsPerPixel,
rails_one->format->Rmask, rails_one->format->Gmask,
rails_one->format->Bmask, rails_one->format->Amask);
SDL_BlitSurface(canvas_backup, &modification_rect, result, NULL);
@ -502,7 +544,8 @@ static void rails_draw(void *ptr, int which ATTRIBUTE_UNUSED, ATTRIBUTE_UNUSED S
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);
@ -511,15 +554,18 @@ static void rails_draw_wrapper(void *ptr, int which, SDL_Surface * canvas, SDL_S
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_modified_last);
rails_segment_to_add = 0;
}
if (rails_segment_modified > 0)
@ -527,15 +573,18 @@ static void rails_draw_wrapper(void *ptr, int which, SDL_Surface * canvas, SDL_S
}
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)
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))
{
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);

View file

@ -43,7 +43,8 @@
#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 const int rain_SIZE = 30;
static const int rain_AMOUNT = 200;
@ -84,19 +85,24 @@ 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);
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, SDL_Surface * last, 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,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void rain_shutdown(magic_api * api);
void rain_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
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);
Uint32 rain_api_version(void)
@ -123,7 +129,8 @@ int rain_init(magic_api * api)
//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);
}
@ -140,7 +147,8 @@ 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));
}
@ -157,13 +165,15 @@ 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,
static void do_rain_drop(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas,
SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
{
magic_api *api = (magic_api *) ptr;
@ -180,15 +190,18 @@ static void do_rain_drop(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * ca
//api->rgbtohsv(rain_r, rain_g, rain_b, &h, &s, &v);
//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)));
api->putpixel(canvas, xx, yy,
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;
@ -196,13 +209,15 @@ static void rain_linecb(void *ptr, int which, SDL_Surface * canvas, SDL_Surface
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);
@ -229,7 +244,8 @@ 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)
@ -250,7 +266,8 @@ 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;
@ -263,9 +280,12 @@ void rain_click(magic_api * api, int which, int mode,
}
// Affect the canvas on release:
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)
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)
{
}
@ -285,24 +305,28 @@ void rain_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void rain_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
void rain_set_color(magic_api * api ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b 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,
void rain_switchin(magic_api * api 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,
void rain_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}

View file

@ -76,23 +76,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, Uint8 r, Uint8 g, Uint8 b);
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);
Uint32 rainbow_api_version(void)
@ -109,7 +115,8 @@ int rainbow_init(magic_api * api)
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);
@ -126,29 +133,37 @@ 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)
{
if (which == 0) {
return (strdup(gettext_noop("Rainbow")));
} else {
}
else
{
return (strdup(gettext_noop("Smooth Rainbow")));
}
}
// 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!")));
}
@ -156,7 +171,8 @@ char *rainbow_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIB
// 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;
@ -175,18 +191,23 @@ 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;
if (which == 1) {
if (which == 1)
{
rainbow_mix += 1;
if (rainbow_mix > MIX_MAX) {
if (rainbow_mix > MIX_MAX)
{
rainbow_mix = 0;
rainbow_color = (rainbow_color + 1) % NUM_RAINBOW_COLORS;
}
} else {
}
else
{
rainbow_mix = 0;
rainbow_color = (rainbow_color + 1) % NUM_RAINBOW_COLORS;
}
@ -201,11 +222,15 @@ void rainbow_drag(magic_api * api, int which, SDL_Surface * canvas,
b2 = rainbow_hexes[rc_tmp][2];
rainbow_rgb = SDL_MapRGB(canvas->format,
((r1 * (MIX_MAX - rainbow_mix)) + (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);
((r1 * (MIX_MAX - rainbow_mix)) +
(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);
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)
{
@ -232,14 +257,18 @@ 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);
}
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)
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)
{
}
@ -251,28 +280,33 @@ void rainbow_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void rainbow_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
void rainbow_set_color(magic_api * api ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b 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,
void rainbow_switchin(magic_api * api 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,
void rainbow_switchout(magic_api * api 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);
}

View file

@ -24,12 +24,15 @@ 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);
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);
Uint32 realrainbow_api_version(void);
int realrainbow_init(magic_api * api);
int realrainbow_get_tool_count(magic_api * api);
@ -42,13 +45,18 @@ int realrainbow_requires_colors(magic_api * api, int which);
void realrainbow_shutdown(magic_api * api);
void realrainbow_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
void realrainbow_click(magic_api * api, int which, int mode,
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);
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 * 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);
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);
Uint32 realrainbow_api_version(void)
@ -60,17 +68,21 @@ int realrainbow_init(magic_api * api)
{
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);
@ -86,9 +98,11 @@ 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));
}
@ -101,12 +115,14 @@ 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,
char *realrainbow_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED)
{
return (strdup
@ -114,12 +130,14 @@ char *realrainbow_get_description(magic_api * api ATTRIBUTE_UNUSED, int which AT
("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);
}
@ -134,14 +152,17 @@ void realrainbow_shutdown(magic_api * api ATTRIBUTE_UNUSED)
Mix_FreeChunk(realrainbow_snd);
}
void realrainbow_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
void realrainbow_set_color(magic_api * api ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b 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)
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)
{
realrainbow_x1 = x;
realrainbow_y1 = y;
@ -154,7 +175,8 @@ void realrainbow_click(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNU
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;
@ -164,8 +186,8 @@ void realrainbow_drag(magic_api * api, int which,
SDL_BlitSurface(last, &realrainbow_rect, canvas, &realrainbow_rect);
realrainbow_arc(api, which, canvas, last, realrainbow_x1, realrainbow_y1, realrainbow_x2, realrainbow_y2, 0,
update_rect);
realrainbow_arc(api, which, canvas, last, realrainbow_x1, realrainbow_y1,
realrainbow_x2, realrainbow_y2, 0, update_rect);
memcpy(&rect, &realrainbow_rect, sizeof(SDL_Rect));
memcpy(&realrainbow_rect, update_rect, sizeof(SDL_Rect));
@ -191,7 +213,8 @@ 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;
@ -201,8 +224,8 @@ void realrainbow_release(magic_api * api, int which,
SDL_BlitSurface(last, &realrainbow_rect, canvas, &realrainbow_rect);
realrainbow_arc(api, which, canvas, last, realrainbow_x1, realrainbow_y1, realrainbow_x2, realrainbow_y2, 1,
update_rect);
realrainbow_arc(api, which, canvas, last, realrainbow_x1, realrainbow_y1,
realrainbow_x2, realrainbow_y2, 1, update_rect);
memcpy(&rect, &realrainbow_rect, sizeof(SDL_Rect));
memcpy(&realrainbow_rect, update_rect, sizeof(SDL_Rect));
@ -229,19 +252,24 @@ void realrainbow_release(magic_api * api, int which,
api->playsound(realrainbow_snd, 128, 255);
}
void realrainbow_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
void realrainbow_switchin(magic_api * api 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,
void realrainbow_switchout(magic_api * api 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)
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)
{
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;
@ -333,16 +361,19 @@ void realrainbow_arc(magic_api * api, int which, SDL_Surface * canvas, SDL_Surfa
ny = (rr * sin(a * M_PI / 180.0)) + yc;
colorindex =
realrainbow_colors[which]->h - 1 - (((rr - r + (thick / 2)) * realrainbow_colors[which]->h) / thick);
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_colors[which]->format, &realrainbow_blendr,
&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;
@ -361,7 +392,8 @@ void realrainbow_arc(magic_api * api, int which, SDL_Surface * canvas, SDL_Surfa
}
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;
@ -369,9 +401,15 @@ 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));
}

View file

@ -60,18 +60,23 @@ 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);
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 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);
void reflection_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 reflection_release(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
void reflection_shutdown(magic_api * api);
void reflection_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
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);
@ -80,7 +85,8 @@ int reflection_init(magic_api * api)
{
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);
@ -105,30 +111,38 @@ 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)
char *reflection_get_description(magic_api * api 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)
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)
{
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;
@ -319,20 +333,24 @@ 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;
@ -341,11 +359,13 @@ 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;
@ -377,29 +397,35 @@ void reflection_shutdown(magic_api * api ATTRIBUTE_UNUSED)
Mix_FreeChunk(reflection_snd);
}
void reflection_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
void reflection_set_color(magic_api * api ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b 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)
void reflection_switchin(magic_api * api ATTRIBUTE_UNUSED,
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,
void reflection_switchout(magic_api * api 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;
}

View file

@ -49,17 +49,22 @@ 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);
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 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);
void ripples_shutdown(magic_api * api);
void ripples_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
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);
Uint32 ripples_api_version(void)
@ -75,7 +80,8 @@ int ripples_init(magic_api * api)
{
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);
@ -92,38 +98,49 @@ 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:
void ripples_drag(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED,
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
void ripples_drag(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED,
int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED,
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED,
SDL_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;
@ -141,7 +158,8 @@ 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 radius;
float fli;
@ -163,7 +181,8 @@ 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;
@ -179,9 +198,12 @@ void ripples_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
}
// Affect the canvas on release:
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)
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)
{
}
@ -193,28 +215,33 @@ void ripples_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void ripples_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
void ripples_set_color(magic_api * api ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b 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,
void ripples_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void ripples_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
void ripples_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int ripples_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
int ripples_modes(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
{
return (MODE_ONECLICK);
}

View file

@ -60,18 +60,25 @@ 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);
Uint32 rosette_api_version(void)
{
@ -89,7 +96,8 @@ int rosette_init(magic_api * api)
{
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);
@ -105,9 +113,11 @@ 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));
}
@ -120,12 +130,14 @@ 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?
@ -133,14 +145,18 @@ char *rosette_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int m
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;
}
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)
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)
{
}
@ -152,7 +168,8 @@ 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;
@ -161,11 +178,14 @@ 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;
@ -215,9 +235,11 @@ void rosette_draw(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * snap
}
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;
@ -226,25 +248,29 @@ 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,
void rosette_switchin(magic_api * api 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,
void rosette_switchout(magic_api * api 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);
}

View file

@ -79,12 +79,15 @@ 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);
@ -95,22 +98,29 @@ 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);
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 * 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, Uint8 r, Uint8 g, Uint8 b);
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);
Uint32 sharpen_api_version(void)
@ -128,7 +138,8 @@ int sharpen_init(magic_api * api)
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);
}
@ -146,7 +157,8 @@ 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));
}
@ -157,13 +169,15 @@ 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])));
}
@ -175,7 +189,8 @@ 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;
@ -202,7 +217,8 @@ static void do_sharpen_pixel(void *ptr, int which, SDL_Surface * canvas, SDL_Sur
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];
@ -229,14 +245,17 @@ static void do_sharpen_pixel(void *ptr, int which, SDL_Surface * canvas, SDL_Sur
else if (which == TOOL_SHARPEN)
{
SDL_GetRGB(api->getpixel(last, x, y), last->format, &r1, &g1, &b1);
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, clamp(0.0, r1 + SHARPEN * temp, 255.0),
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)));
}
}
// 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;
@ -244,7 +263,8 @@ static void do_sharpen_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last,
for (y = 0; y < last->h; y++)
{
if (y % 10 == 0) {
if (y % 10 == 0)
{
api->update_progress_bar();
}
@ -256,7 +276,8 @@ static void do_sharpen_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last,
}
//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;
@ -265,7 +286,8 @@ static void do_sharpen_brush(void *ptr, int which, SDL_Surface * canvas, SDL_Sur
{
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);
}
@ -275,10 +297,12 @@ static void do_sharpen_brush(void *ptr, int which, SDL_Surface * canvas, SDL_Sur
// 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);
@ -305,7 +329,8 @@ 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);
@ -321,9 +346,12 @@ void sharpen_click(magic_api * api, int which, int mode,
}
// Affect the canvas on release:
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)
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)
{
}
@ -343,28 +371,33 @@ void sharpen_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void sharpen_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
void sharpen_set_color(magic_api * api ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b 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,
void sharpen_switchin(magic_api * api 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,
void sharpen_switchout(magic_api * api 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);
}

View file

@ -44,7 +44,8 @@ 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);
int shift_get_tool_count(magic_api * api);
@ -53,17 +54,20 @@ 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);
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, SDL_Surface * last, 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,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void shift_shutdown(magic_api * api);
void shift_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
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);
@ -79,7 +83,8 @@ int shift_init(magic_api * api)
{
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);
@ -92,37 +97,46 @@ 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 */
@ -130,8 +144,10 @@ void shift_drag(magic_api * api, int which, SDL_Surface * canvas,
shift_doit(api, which, canvas, last, ox, oy, x, y, update_rect, 1);
}
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,
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)
{
SDL_Rect dest;
@ -293,7 +309,8 @@ static void shift_doit(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNU
// 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;
@ -303,7 +320,8 @@ 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();
@ -319,22 +337,26 @@ void shift_shutdown(magic_api * api ATTRIBUTE_UNUSED)
// Record the color from Tux Paint:
void shift_set_color(magic_api * api ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b 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,
void shift_switchin(magic_api * api 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,
void shift_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}

View file

@ -46,18 +46,22 @@ 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);
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, SDL_Surface * last, 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,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void smudge_shutdown(magic_api * api);
void smudge_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
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);
@ -66,7 +70,8 @@ int smudge_init(magic_api * api)
{
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);
@ -89,9 +94,11 @@ 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));
}
@ -115,17 +122,23 @@ 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[32][32][3];
@ -141,13 +154,20 @@ static void do_smudge(void *ptr, int which, SDL_Surface * canvas, SDL_Surface *
for (xx = -8; xx < 8; xx++)
if (api->in_circle(xx, yy, 8))
{
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) / 8) + 6;
strength = (abs(xx * yy) / 8) + 1;
api->putpixel(canvas, x + xx, y + yy, SDL_MapRGB(canvas->format,
(smudge_r + r * strength) / (strength + 1),
(smudge_g + g * strength) / (strength + 1),
(smudge_b + b * strength) / (strength + 1)));
(smudge_r +
r * strength) /
(strength + 1),
(smudge_g +
g * strength) /
(strength + 1),
(smudge_b +
b * strength) /
(strength + 1)));
}
}
@ -161,21 +181,28 @@ static void do_smudge(void *ptr, int which, SDL_Surface * canvas, SDL_Surface *
continue;
// it is on the circle, so grab it
SDL_GetRGB(api->getpixel(canvas, x + ix - 16, y + iy - 16), 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 - 16, y + iy - 16), 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 - 16, y + iy - 16,
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])));
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])));
}
}
// 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);
@ -204,15 +231,19 @@ 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);
}
// Affect the canvas on click:
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)
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)
{
}
@ -224,7 +255,8 @@ void smudge_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void smudge_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b)
void smudge_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g,
Uint8 b)
{
smudge_r = r;
smudge_g = g;
@ -232,7 +264,8 @@ void smudge_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8
}
// 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;
@ -240,12 +273,14 @@ int smudge_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE
return 1;
}
void smudge_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
void smudge_switchin(magic_api * api 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,
void smudge_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}

View file

@ -84,19 +84,24 @@ 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);
void snow_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, 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, Uint8 r, Uint8 g, Uint8 b);
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);
Uint32 snow_api_version(void)
{
@ -112,14 +117,16 @@ int snow_init(magic_api * api)
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)
{
@ -132,7 +139,8 @@ int snow_init(magic_api * api)
}
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);
@ -148,7 +156,8 @@ 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));
}
@ -158,7 +167,8 @@ 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 */
}
@ -170,7 +180,8 @@ 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;
@ -190,8 +201,10 @@ static void do_snow(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int whi
{
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));
}
}
}
@ -213,9 +226,12 @@ static void do_snow(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int whi
}
// Affect the canvas on drag:
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)
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)
{
// No-op
}
@ -223,7 +239,8 @@ void snow_drag(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL
// 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;
@ -235,9 +252,12 @@ void snow_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
}
// Affect the canvas on release:
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)
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)
{
}
@ -265,23 +285,27 @@ void snow_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void snow_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
void snow_set_color(magic_api * api ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b 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,
void snow_switchin(magic_api * api 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,
void snow_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}

View file

@ -57,15 +57,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);
void stretch_paint_stretch(void *ptr_to_api, int which_tool,
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);
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);
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);
int stretch_modes(magic_api * api, int which);
// Housekeeping functions
@ -74,7 +80,9 @@ Uint32 stretch_api_version(void)
return (TP_MAGIC_API_VERSION);
}
void stretch_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
void stretch_set_color(magic_api * api ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED)
{
}
@ -82,7 +90,8 @@ int stretch_init(magic_api * api)
{
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);
@ -97,36 +106,45 @@ 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."));
}
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;
}
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)
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)
{
}
@ -137,9 +155,10 @@ void stretch_shutdown(magic_api * api ATTRIBUTE_UNUSED)
// Interactivity functions
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)
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)
{
SDL_Rect src, dest;
float xx, yy;
@ -154,7 +173,8 @@ void stretch_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface * can
if (y != stretch_start_y)
{
divisor1 = (float) y / (float) stretch_start_y;
divisor2 = (float) (canvas->h - y) / (float) (canvas->h - stretch_start_y);
divisor2 =
(float) (canvas->h - y) / (float) (canvas->h - stretch_start_y);
for (yy = 0; yy < y; yy++)
{
@ -196,7 +216,8 @@ void stretch_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface * can
if (x != stretch_start_x)
{
divisor1 = (float) x / (float) stretch_start_x;
divisor2 = (float) (canvas->w - x) / (float) (canvas->w - stretch_start_x);
divisor2 =
(float) (canvas->w - x) / (float) (canvas->w - stretch_start_x);
for (xx = 0; xx < x; xx++)
{
@ -241,7 +262,8 @@ void stretch_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface * can
}
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)
{
@ -268,19 +290,22 @@ void stretch_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
stretch_drag(api, which, canvas, last, x, y, x, y, update_rect);
}
void stretch_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, 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)
{
}
void stretch_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
void stretch_switchout(magic_api * api 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);
}

View file

@ -10,7 +10,8 @@
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
{
@ -24,25 +25,28 @@ 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_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);
void string_draw_angle(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, int ox, int oy, int x, int y,
void string_callback(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);
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);
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 * canvas,
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_Surface * canvas, SDL_Surface * snapshot,
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);
void string_draw_wrapper(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);
void string_set_vertex(int x, int y);
void compute_middle(int start_point, int end_point, int vertex, int *middle);
@ -50,7 +54,8 @@ 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);
@ -63,13 +68,17 @@ 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);
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_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
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);
// Required functions
@ -86,7 +95,8 @@ int string_modes(magic_api * api ATTRIBUTE_UNUSED, int which)
return (MODE_PAINT_WITH_PREVIEW);
}
void string_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b)
void string_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g,
Uint8 b)
{
string_r = r;
string_g = g;
@ -107,13 +117,17 @@ 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;
}
@ -121,7 +135,8 @@ 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)
{
@ -136,12 +151,14 @@ char *string_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUS
}
}
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)
{
@ -151,25 +168,30 @@ char *string_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mo
("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
@ -179,7 +201,8 @@ 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);
}
}
@ -187,13 +210,16 @@ int string_init(magic_api * api 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);
@ -214,14 +240,22 @@ 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)
void string_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode 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_backup =
SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h,
canvas->format->BitsPerPixel, canvas->format->Rmask,
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)
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_FreeSurface(canvas_backup);
canvas_backup = NULL;
@ -230,15 +264,21 @@ void string_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUS
// Interactivity functions
void string_callback(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
void string_callback(void *ptr, int which ATTRIBUTE_UNUSED,
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_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
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_BlitSurface(canvas, NULL, canvas_backup, NULL);
@ -249,8 +289,11 @@ void string_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED, SDL_Sur
string_drag(api, which, canvas, snapshot, x, y, x, y, update_rect);
}
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)
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)
{
magic_api *api = (magic_api *) ptr;
int u;
@ -303,7 +346,8 @@ static void string_draw_full_by_offset(void *ptr, int which ATTRIBUTE_UNUSED, SD
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++)
@ -344,13 +388,18 @@ 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 * canvas,
SDL_Surface * snapshot, int ox, int oy,
int x, int y, SDL_Rect * update_rect)
{
int middle_x, middle_y;
@ -365,14 +414,21 @@ 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);
api->line((void *)api, which, canvas, snapshot, string_ox, string_oy, x, string_oy, 1, string_callback);
api->line((void *)api, which, canvas, snapshot, middle_x, middle_y, x, string_oy, 1, string_callback);
api->line((void *)api, which, canvas, snapshot, string_ox, y, middle_x, middle_y, 1, string_callback);
api->line((void *) api, which, canvas, snapshot, string_ox, string_oy,
string_ox, y, 1, string_callback);
api->line((void *) api, which, canvas, snapshot, string_ox, string_oy, x,
string_oy, 1, string_callback);
api->line((void *) api, which, canvas, snapshot, middle_x, middle_y, x,
string_oy, 1, string_callback);
api->line((void *) api, which, canvas, snapshot, string_ox, y, middle_x,
middle_y, 1, string_callback);
}
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)
SDL_Surface * canvas, SDL_Surface * snapshot,
int ox ATTRIBUTE_UNUSED,
int oy ATTRIBUTE_UNUSED, int x, int y,
SDL_Rect * update_rect)
{
int middle_x, middle_y;
int dx, dy;
@ -383,8 +439,8 @@ 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, string_vertex_x, string_vertex_y, 1,
string_callback);
api->line((void *) api, which, canvas, snapshot, string_ox, string_oy,
string_vertex_x, string_vertex_y, 1, string_callback);
if (!string_vertex_done)
{
// if(!string_vertex_done) // maybe we face small children, draw square angles aligned to the drag
@ -398,16 +454,23 @@ 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);
api->line((void *)api, which, canvas, snapshot, string_ox, string_oy, middle_x, middle_y, 1, string_callback);
api->line((void *)api, which, canvas, snapshot, x, y, middle_x, middle_y, 1, string_callback);
api->line((void *) api, which, canvas, snapshot, string_vertex_x,
string_vertex_y, x, y, 1, string_callback);
api->line((void *) api, which, canvas, snapshot, string_ox, string_oy,
middle_x, middle_y, 1, string_callback);
api->line((void *) api, which, canvas, snapshot, x, y, middle_x, middle_y,
1, string_callback);
}
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)
SDL_Surface * canvas,
SDL_Surface * snapshot ATTRIBUTE_UNUSED,
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;
@ -419,8 +482,10 @@ void string_draw_angle(magic_api * api, int which ATTRIBUTE_UNUSED,
SDL_BlitSurface(canvas_backup, update_rect, canvas, update_rect);
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(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));
steps = max_wh / max_separation;
first_arm_step_x = (float) (string_ox - string_vertex_x) / (float) steps;
@ -430,13 +495,17 @@ void string_draw_angle(magic_api * api, int which ATTRIBUTE_UNUSED,
for (i = 0; i <= steps; i++)
{
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);
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);
}
}
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_Surface * canvas, SDL_Surface * snapshot,
int ox, int oy, int x, int y,
SDL_Rect * update_rect)
{
SDL_BlitSurface(canvas_backup, 0, canvas, 0);
@ -448,19 +517,23 @@ 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,
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 (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)
@ -482,13 +555,16 @@ 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)
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))
{
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);
}

View file

@ -76,10 +76,13 @@ 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);
@ -90,20 +93,26 @@ 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);
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, SDL_Surface * last, 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,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void tint_shutdown(magic_api * api);
void tint_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
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);
Uint32 tint_api_version(void)
@ -119,7 +128,8 @@ int tint_init(magic_api * api)
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);
@ -135,7 +145,8 @@ 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));
}
@ -146,13 +157,15 @@ 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])));
}
@ -163,7 +176,8 @@ 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;
@ -187,18 +201,21 @@ static void do_tint_pixel(void *ptr, int which, SDL_Surface * canvas, SDL_Surfac
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;
@ -211,7 +228,8 @@ static void do_tint_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last, in
}
}
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;
@ -220,7 +238,8 @@ static void do_tint_brush(void *ptr, int which, SDL_Surface * canvas, SDL_Surfac
{
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);
}
@ -230,10 +249,12 @@ static void do_tint_brush(void *ptr, int which, SDL_Surface * canvas, SDL_Surfac
// 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);
@ -260,7 +281,8 @@ 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);
@ -276,9 +298,12 @@ void tint_click(magic_api * api, int which, int mode,
}
// Affect the canvas on release:
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)
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)
{
}
@ -298,7 +323,8 @@ void tint_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void tint_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b)
void tint_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g,
Uint8 b)
{
tint_r = r;
tint_g = g;
@ -306,12 +332,14 @@ void tint_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b)
}
// 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;
@ -338,7 +366,8 @@ void tint_switchin(magic_api * api, int which ATTRIBUTE_UNUSED, int mode ATTRIBU
}
}
void tint_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
void tint_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}

View file

@ -84,18 +84,24 @@ 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);
void toothpaste_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 toothpaste_release(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y,
SDL_Rect * update_rect);
void toothpaste_shutdown(magic_api * api);
void toothpaste_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
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);
Uint32 toothpaste_api_version(void)
@ -114,13 +120,16 @@ int toothpaste_init(magic_api * api)
//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);
}
//Set up weights
pi = acos(0.0) * 2;
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);
@ -132,7 +141,10 @@ int toothpaste_init(magic_api * api)
{
if (api->in_circle(j, k, toothpaste_RADIUS))
{
toothpaste_weights[(k + toothpaste_RADIUS) * ((toothpaste_RADIUS * 2) - 1) + (j + toothpaste_RADIUS)] =
toothpaste_weights[(k +
toothpaste_RADIUS) * ((toothpaste_RADIUS * 2) -
1) + (j +
toothpaste_RADIUS)] =
((fabs(atan2((double) (j), (double) (k)))) / pi);
}
}
@ -151,7 +163,8 @@ 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));
}
@ -168,13 +181,15 @@ 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,
static void do_toothpaste(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas,
SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
{
magic_api *api = (magic_api *) ptr;
@ -189,13 +204,18 @@ static void do_toothpaste(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * c
{
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_weights[(yy - y +
toothpaste_RADIUS) *
((toothpaste_RADIUS * 2) - 1) + (xx -
x +
toothpaste_RADIUS)],
&r, &g, &b);
api->putpixel(canvas, xx, yy, SDL_MapRGB(canvas->format, r, g, b));
}
@ -206,10 +226,12 @@ static void do_toothpaste(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * c
// 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);
@ -222,16 +244,20 @@ 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);
}
// Affect the canvas on release:
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)
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)
{
}
@ -256,7 +282,8 @@ void toothpaste_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void toothpaste_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b)
void toothpaste_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g,
Uint8 b)
{
toothpaste_r = r;
toothpaste_g = g;
@ -264,23 +291,29 @@ void toothpaste_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Ui
}
// 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,
void toothpaste_switchin(magic_api * api 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,
void toothpaste_switchout(magic_api * api 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);
}

View file

@ -64,13 +64,18 @@ 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);
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);
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);
@ -88,17 +93,21 @@ 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);
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 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);
void tornado_shutdown(magic_api * api);
void tornado_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
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);
@ -120,13 +129,16 @@ int tornado_init(magic_api * api)
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);
@ -143,32 +155,41 @@ 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)
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)
{
if (x < tornado_min_x)
tornado_min_x = x;
@ -201,8 +222,9 @@ static void tornado_predrag(magic_api * api ATTRIBUTE_UNUSED, SDL_Surface * canv
}
}
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)
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)
{
tornado_predrag(api, canvas, last, ox, oy, x, y);
@ -215,7 +237,8 @@ void tornado_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface * can
/* 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);
@ -227,7 +250,8 @@ void tornado_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface * can
// 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;
@ -246,7 +270,8 @@ 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: */
@ -266,7 +291,8 @@ 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);
@ -282,7 +308,8 @@ 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;
@ -295,7 +322,8 @@ static void tornado_drawtornado(magic_api * api, SDL_Surface * canvas, int x, in
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;
@ -313,11 +341,14 @@ static Uint32 tornado_mess(Uint32 pixel, SDL_Surface * canvas)
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)
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)
{
Point2D control_points[4];
Point2D *curve;
@ -401,22 +432,32 @@ static void tornado_drawstalk(magic_api * api, SDL_Surface * canvas, SDL_Surface
{
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));
}
}
@ -452,7 +493,8 @@ void tornado_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b)
}
// 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;
}
@ -507,7 +549,8 @@ 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;
@ -530,7 +573,9 @@ 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,
@ -538,7 +583,8 @@ 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: */
@ -549,11 +595,14 @@ 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));
}
}
@ -561,18 +610,21 @@ static void tornado_colorize_cloud(magic_api * api)
SDL_UnlockSurface(tornado_cloud);
}
void tornado_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
void tornado_switchin(magic_api * api 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,
void tornado_switchout(magic_api * api, int which 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);
}

View file

@ -46,14 +46,18 @@ 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);
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 * 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);
void tv_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int tv_modes(magic_api * api, int which);
@ -74,7 +78,8 @@ int tv_init(magic_api * api 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);
@ -89,12 +94,14 @@ 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));
}
char *tv_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
char *tv_get_name(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
{
return strdup(gettext_noop("TV"));
}
@ -104,24 +111,32 @@ 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;
}
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)
SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * snapshot ATTRIBUTE_UNUSED,
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
@ -133,7 +148,8 @@ void tv_shutdown(magic_api * api ATTRIBUTE_UNUSED)
// Interactivity functions
void tv_do_tv(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;
Uint8 r, g, b, i;
@ -141,7 +157,8 @@ void tv_do_tv(void *ptr_to_api, int which_tool ATTRIBUTE_UNUSED,
for (i = 0; i < 2; i++)
{
/* Convert the line below to their red/green/blue elements */
SDL_GetRGB(api->getpixel(snapshot, x, y + i), snapshot->format, &r, &g, &b);
SDL_GetRGB(api->getpixel(snapshot, x, y + i), snapshot->format, &r, &g,
&b);
if (x % 3 == 0)
{
/* Red */
@ -170,7 +187,8 @@ void tv_do_tv(void *ptr_to_api, int which_tool ATTRIBUTE_UNUSED,
}
void tv_paint_tv(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)
{
int i, j;
magic_api *api = (magic_api *) ptr_to_api;
@ -190,7 +208,8 @@ void tv_paint_tv(void *ptr_to_api, int which_tool ATTRIBUTE_UNUSED,
}
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);
@ -202,7 +221,8 @@ 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)
{
@ -225,13 +245,15 @@ 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,
void tv_switchin(magic_api * api ATTRIBUTE_UNUSED, int which 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,
void tv_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{

View file

@ -46,16 +46,19 @@ 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);
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, SDL_Surface * last, 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,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void waves_shutdown(magic_api * api);
void waves_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
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);
Uint32 waves_api_version(void)
@ -69,10 +72,12 @@ int waves_init(magic_api * api)
{
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);
@ -91,15 +96,18 @@ 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;
}
@ -114,7 +122,8 @@ 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
@ -126,9 +135,10 @@ char *waves_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mod
}
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)
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 xx, yy;
SDL_Rect src, dest;
@ -186,16 +196,20 @@ void waves_drag(magic_api * api ATTRIBUTE_UNUSED, int which, SDL_Surface * canva
// 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);
}
// Affect the canvas on release:
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)
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)
{
}
@ -209,23 +223,27 @@ void waves_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void waves_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
void waves_set_color(magic_api * api ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b 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,
void waves_switchin(magic_api * api 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,
void waves_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}

View file

@ -43,19 +43,23 @@ 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, Uint8 r, Uint8 g, Uint8 b);
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);
Uint32 xor_api_version(void)
@ -67,7 +71,8 @@ int xor_init(magic_api * api)
{
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);
@ -82,31 +87,38 @@ 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;
@ -125,7 +137,8 @@ static void do_xor(void *ptr, int which ATTRIBUTE_UNUSED,
}
static void do_xor_circle(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
SDL_Surface * canvas,
SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
{
magic_api *api = (magic_api *) ptr;
int xx, yy;
@ -144,9 +157,11 @@ 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)
{
@ -172,7 +187,8 @@ 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);
@ -193,8 +209,10 @@ 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)
SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, int x ATTRIBUTE_UNUSED,
int y ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
@ -204,22 +222,25 @@ void xor_shutdown(magic_api * api ATTRIBUTE_UNUSED)
Mix_FreeChunk(xor_snd);
}
void xor_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED)
void xor_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED,
Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
{
}
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,
void xor_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void xor_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
void xor_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}

View file

@ -32,7 +32,8 @@ 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;
@ -66,7 +67,12 @@ void load_assets_dir(char * dirname, tp_ftw_str ** ffilenames, unsigned * num_f
*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);
@ -76,7 +82,12 @@ JNIEXPORT jboolean Java_org_tuxpaint_tuxpaintActivity_managertojni(JNIEnv * env,
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);
@ -84,12 +95,15 @@ JNIEXPORT void Java_org_tuxpaint_tuxpaintActivity_setnativelibdir(JNIEnv * env,
}
void load_brushes_from_assets(SDL_Surface * screen, SDL_Texture *texture, SDL_Renderer *renderer, const char * dirname, void (*fn) (SDL_Surface * screen,
void load_brushes_from_assets(SDL_Surface * screen, SDL_Texture * texture,
SDL_Renderer * renderer, const char *dirname,
void (*fn)(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";
@ -107,12 +121,14 @@ void load_brushes_from_assets(SDL_Surface * screen, SDL_Texture *texture, SDL_Re
void load_from_assets(SDL_Surface * screen, SDL_Texture *texture, SDL_Renderer *renderer, const char * dirname, void (*fn) (SDL_Surface * screen,
SDL_Texture * texture,
void load_from_assets(SDL_Surface * screen, SDL_Texture * texture,
SDL_Renderer * renderer, const char *dirname,
void (*fn)(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";
@ -124,5 +140,6 @@ void load_from_assets(SDL_Surface * screen, SDL_Texture *texture, SDL_Renderer *
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

@ -31,24 +31,40 @@
AAssetDir *open_asset_dir(char *dirname);
char *get_nativelibdir();
void load_brushes_from_assets(SDL_Surface * screen, SDL_Texture *texture, SDL_Renderer *renderer, const char * dirname, void (*fn) (SDL_Surface * screen,
void load_brushes_from_assets(SDL_Surface * screen, SDL_Texture * texture,
SDL_Renderer * renderer, const char *dirname,
void (*fn)(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, void (*fn) (SDL_Surface * screen,
SDL_Texture * texture,
void load_from_assets(SDL_Surface * screen, SDL_Texture * texture,
SDL_Renderer * renderer, const char *dirname,
void (*fn)(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

@ -30,26 +30,31 @@
#include <string.h>
// This implementation may be simple, but can work fine for all of Android devices
size_t mbstowcs(wchar_t * __restrict pwcs, const char * __restrict s, size_t n){
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;
while (1) {
while (1)
{
pwcs[w] = '\0';
char first = s[c];
int len = 0;
if ((first & 0x80) == 0) {
if ((first & 0x80) == 0)
{
pwcs[w] = (wchar_t) s[c];
len = 1;
}
else if ((first & 0xe0) == 0xc0) {
else if ((first & 0xe0) == 0xc0)
{
pwcs[w] |= first & 0x1f;
pwcs[w] <<= 6;
pwcs[w] |= s[c + 1] & 0x3f;
len = 2;
}
else if ((first & 0xf0) == 0xe0) {
else if ((first & 0xf0) == 0xe0)
{
pwcs[w] |= first & 0x0f;
pwcs[w] <<= 6;
pwcs[w] |= s[c + 1] & 0x3f;
@ -57,7 +62,8 @@ size_t mbstowcs(wchar_t * __restrict pwcs, const char * __restrict s, size_t n){
pwcs[w] |= s[c + 2] & 0x3f;
len = 3;
}
else if ((first & 0xf8) == 0xf0) {
else if ((first & 0xf8) == 0xf0)
{
pwcs[w] |= first & 0x07;
pwcs[w] <<= 6;
pwcs[w] |= s[c + 1] & 0x3f;
@ -67,18 +73,21 @@ size_t mbstowcs(wchar_t * __restrict pwcs, const char * __restrict s, size_t n){
pwcs[w] |= s[c + 3] & 0x3f;
len = 4;
}
else {
else
{
return -1;
}
c += len;
w++;
if (c > length){
if (c > length)
{
pwcs[w] = '\0';
return -1;
}
if (c == length){
if (c == length)
{
pwcs[w] = '\0';
return w;
}

View file

@ -34,13 +34,17 @@
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;
}
@ -52,28 +56,46 @@ 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");
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");
/* 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");

View file

@ -134,4 +134,3 @@
#define FALL_THROUGH ((void)0)
#endif /* __GNUC__ >= 7 */
#endif

View file

@ -79,8 +79,10 @@ extern char *strcasestr(const char *haystack, const char *needle);
* @param screen Screen surface, for animating progress bar.
* FIXME
*/
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,
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)
{
dirlen = dirlen;
@ -151,8 +153,10 @@ fflush(stdout);
}
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
@ -161,18 +165,22 @@ fflush(stdout);
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
}
#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);
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);
#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
@ -193,7 +201,8 @@ fflush(stdout);
// 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)
@ -201,9 +210,12 @@ fflush(stdout);
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);
@ -218,29 +230,39 @@ fflush(stdout);
// Translators should do whatever is needed to put crummy fonts last.
// distinct uppercase and lowercase (e.g., 'o' vs. 'O')
user_font_styles[num_font_styles]->score += charset_works(font, gettext("oO"));
user_font_styles[num_font_styles]->score +=
charset_works(font, gettext("oO"));
// common punctuation (e.g., '?', '!', '.', ',', etc.)
user_font_styles[num_font_styles]->score += charset_works(font, gettext(",.?!"));
user_font_styles[num_font_styles]->score +=
charset_works(font, gettext(",.?!"));
// uncommon punctuation (e.g., '@', '#', '*', etc.)
user_font_styles[num_font_styles]->score += charset_works(font, gettext("`\%_@$~#{<(^&*"));
user_font_styles[num_font_styles]->score +=
charset_works(font, gettext("`\%_@$~#{<(^&*"));
// digits (e.g., '0', '1' and '7')
user_font_styles[num_font_styles]->score += charset_works(font, gettext("017"));
user_font_styles[num_font_styles]->score +=
charset_works(font, gettext("017"));
// distinct circle-like characters (e.g., 'O' (capital oh) vs. '0' (zero))
user_font_styles[num_font_styles]->score += charset_works(font, gettext("O0"));
user_font_styles[num_font_styles]->score +=
charset_works(font, gettext("O0"));
// distinct line-like characters (e.g., 'l' (lowercase elle) vs. '1' (one) vs. 'I' (capital aye))
user_font_styles[num_font_styles]->score += charset_works(font, gettext("1Il|"));
user_font_styles[num_font_styles]->score +=
charset_works(font, gettext("1Il|"));
// translation spares -- design not finalized
#if 0
user_font_styles[num_font_styles]->score += 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-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;
#endif
// this really should be dynamic, avoiding the need for a special build
@ -258,7 +280,8 @@ fflush(stdout);
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);
@ -305,10 +328,17 @@ int compare_ftw_str(const void *v1, const void *v2)
* @param fn Callback function to invoke
* @param locale Locale, to pass to callback function when applicable (i.e., for fonts), else NULL
*/
void tp_ftw(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer, char *restrict const dir,
unsigned dirlen, int rsrc, void (*fn) (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),
void tp_ftw(SDL_Surface * screen, SDL_Texture * texture,
SDL_Renderer * renderer, char *restrict const dir,
unsigned dirlen, int rsrc, void (*fn)(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),
const char *restrict const locale)
{
DIR *d;
@ -486,10 +516,12 @@ void tp_ftw(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer
#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
}
@ -498,8 +530,10 @@ void tp_ftw(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer
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

@ -45,14 +45,23 @@ typedef struct tp_ftw_str
} 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,
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);
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,
unsigned dirlen, int rsrc, void (*fn) (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),
void tp_ftw(SDL_Surface * screen, SDL_Texture * texture,
SDL_Renderer * renderer, char *restrict const dir,
unsigned dirlen, int rsrc, void (*fn)(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),
const char *restrict const locale);
#endif

View file

@ -64,7 +64,8 @@
#define QUEUE_SIZE_CHUNK 1024
typedef struct queue_s {
typedef struct queue_s
{
int x, y, y_outside;
} queue_t;
@ -80,16 +81,22 @@ 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);
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);
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);
void init_queue(void);
void add_to_queue(int x, int y, int y_outside);
int remove_from_queue(int *x, int *y, int *y_outside);
void cleanup_queue(void);
void init_queue(void) {
void init_queue(void)
{
queue_size = 0;
queue_end = 0;
@ -103,12 +110,15 @@ void init_queue(void) {
queue_size = QUEUE_SIZE_CHUNK;
}
void add_to_queue(int x, int y, int y_outside) {
void add_to_queue(int x, int y, int y_outside)
{
/* Reallocate if we need more space */
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");
@ -137,7 +147,8 @@ void add_to_queue(int x, int y, int y_outside) {
#endif
}
int remove_from_queue(int * x, int * y, int * y_outside) {
int remove_from_queue(int *x, int *y, int *y_outside)
{
if (queue_end == 0)
return 0;
@ -158,7 +169,8 @@ int remove_from_queue(int * x, int * y, int * y_outside) {
return 1;
}
void cleanup_queue(void) {
void cleanup_queue(void)
{
if (queue != NULL)
free(queue);
@ -210,18 +222,27 @@ int would_flood_fill(SDL_Surface * canvas, Uint32 cur_colr, Uint32 old_colr)
if (colors_close(canvas, cur_colr, old_colr) < COLOR_MATCH_NARROW)
{
return 0;
} else {
}
else
{
return 1;
}
}
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)
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)
{
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);
@ -235,7 +256,12 @@ Uint32 blend(SDL_Surface * canvas, Uint32 draw_colr, Uint32 old_colr, double pct
return SDL_MapRGB(canvas->format, new_r, new_g, new_b);
}
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 * extent_x1, int * extent_y1, int * extent_x2, int * extent_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 *extent_x1, int *extent_y1,
int *extent_x2, int *extent_y2, Uint8 * touched)
{
int y_outside;
/* Get ready */
@ -258,7 +284,8 @@ void simulate_flood_fill(SDL_Surface * screen, SDL_Texture * texture, SDL_Render
/* 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();
@ -268,7 +295,10 @@ void simulate_flood_fill(SDL_Surface * screen, SDL_Texture * texture, SDL_Render
*extent_y2 = global_extent_y2;
}
void simulate_flood_fill_outside_check(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer, int x, int y, int y_outside)
void simulate_flood_fill_outside_check(SDL_Surface * screen,
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;
@ -321,18 +351,24 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen, SDL_Texture * textu
/* 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)
{
if (in_line > COLOR_MATCH_NARROW) {
if (in_line > COLOR_MATCH_NARROW)
{
outside++;
} else {
}
else
{
narrowFillL = fillL;
}
if (global_touched != NULL) {
if (global_touched != NULL)
{
touch_byt = (255 - ((Uint8) (in_line * 85)));
if (touch_byt == 0)
touch_byt = 1;
@ -340,11 +376,17 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen, SDL_Texture * textu
global_touched[(y * global_canvas->w) + fillL] = touch_byt;
}
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)));
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)));
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)
{
@ -367,8 +409,13 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen, SDL_Texture * textu
global_touched[(y * global_canvas->w) + fillL] = touch_byt;
}
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)));
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)));
}
@ -382,18 +429,23 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen, SDL_Texture * textu
/* 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)
{
if (in_line > COLOR_MATCH_NARROW) {
if (in_line > COLOR_MATCH_NARROW)
{
outside++;
} else {
}
else
{
narrowFillR = fillR;
}
if (global_touched != NULL) {
if (global_touched != NULL)
{
touch_byt = (255 - ((Uint8) (in_line * 85)));
if (touch_byt == 0)
touch_byt = 1;
@ -401,11 +453,17 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen, SDL_Texture * textu
global_touched[(y * global_canvas->w) + fillR] = touch_byt;
}
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)));
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)));
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)
{
@ -428,8 +486,13 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen, SDL_Texture * textu
global_touched[(y * global_canvas->w) + fillR] = touch_byt;
}
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)));
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)));
}
if (fillR > global_extent_x2)
@ -447,13 +510,15 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen, SDL_Texture * textu
{
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)
)
(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;
@ -478,13 +543,15 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen, SDL_Texture * textu
{
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)
)
(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;
@ -505,8 +572,9 @@ void simulate_flood_fill_outside_check(SDL_Surface * screen, SDL_Texture * textu
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;
Uint8 draw_r, draw_g, draw_b, old_r, old_g, old_b, new_r, new_g, new_b;
@ -521,9 +589,12 @@ void draw_linear_gradient(SDL_Surface * canvas, SDL_Surface * last,
C2 = (A * x2) + (B * y2);
/* FIXME: C2 should be larger than C1? */
for (yy = y_top; yy <= y_bottom; yy++) {
for (xx = x_left; xx <= x_right; xx++) {
if (touched[(yy * canvas->w) + xx]) {
for (yy = y_top; yy <= y_bottom; yy++)
{
for (xx = x_left; xx <= x_right; xx++)
{
if (touched[(yy * canvas->w) + xx])
{
/* Get the old color, and blend it (with a distance-based ratio) with the target color */
old_colr = getpixels[last->format->BytesPerPixel] (last, xx, yy);
SDL_GetRGB(old_colr, last->format, &old_r, &old_g, &old_b);
@ -532,13 +603,18 @@ void draw_linear_gradient(SDL_Surface * canvas, SDL_Surface * last,
https://stackoverflow.com/questions/521493/creating-a-linear-gradient-in-2d-array) */
C = (A * xx) + (B * yy);
if (C < C1) {
if (C < C1)
{
/* At/beyond the click spot (opposite direction of mouse); solid color */
ratio = 0.0;
} else if (C >= C2) {
}
else if (C >= C2)
{
/* At/beyond the mouse; completely faded out */
ratio = 1.0;
} else {
}
else
{
/* The actual gradient... */
ratio = (C - C1) / (C2 - C1);
}
@ -546,9 +622,15 @@ 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));
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);
@ -557,7 +639,9 @@ 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;
for (yy = -16; yy < 16; yy++)
@ -567,17 +651,20 @@ void draw_brush_fill_single(SDL_Surface * canvas, int x, int y, Uint32 draw_colo
if ((xx * xx) + (yy * yy) < (16 * 16) &&
touched[((y + yy) * canvas->w) + (x + xx)])
{
putpixels[canvas->format->BytesPerPixel] (canvas, x + xx, y + yy, draw_color);
putpixels[canvas->format->BytesPerPixel] (canvas, x + xx, y + yy,
draw_color);
}
}
}
}
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 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 dx, dy;
int y;
int orig_x1, orig_y1, orig_x2, orig_y2, tmp;
@ -654,9 +741,10 @@ void draw_brush_fill(SDL_Surface * canvas,
*up_y2 = orig_y2 + 16;
}
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
) {
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)
{
Uint32 old_colr, new_colr;
int xx, yy;
float xd, yd, dist, rad, ratio;
@ -666,7 +754,8 @@ void draw_radial_gradient(SDL_Surface * canvas, int x_left, int y_top, int x_rig
xd = max(abs(x - x_right), abs(x - x_left));
yd = max(abs(y - y_bottom), abs(y - y_top));
rad = sqrt(xd * xd + yd * yd);
if (rad == 0) {
if (rad == 0)
{
return;
}
@ -674,27 +763,38 @@ void draw_radial_gradient(SDL_Surface * canvas, int x_left, int y_top, int x_rig
SDL_GetRGB(draw_color, canvas->format, &draw_r, &draw_g, &draw_b);
/* Traverse the flood-filled zone */
for (yy = y_top; yy <= y_bottom; yy++) {
for (xx = x_left; xx <= x_right; xx++) {
for (yy = y_top; yy <= y_bottom; yy++)
{
for (xx = x_left; xx <= x_right; xx++)
{
/* Only alter the pixels within the flood itself */
if (touched[(yy * canvas->w) + xx]) {
if (touched[(yy * canvas->w) + xx])
{
/* 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) {
if (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);
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[yy * canvas->w + xx] / 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);
@ -703,4 +803,3 @@ void draw_radial_gradient(SDL_Surface * canvas, int x_left, int y_top, int x_rig
}
}
}

View file

@ -37,17 +37,26 @@
#include "SDL.h"
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);
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);
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);
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);
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);
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);
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);
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);
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);
#endif

View file

@ -38,7 +38,8 @@
#define gettext_noop(String) String
#endif
enum {
enum
{
FILL_FLOOD,
FILL_BRUSH,
FILL_GRADIENT_LINEAR,
@ -56,8 +57,10 @@ 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 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).")
};
const char *const fill_img_fnames[NUM_FILLS] = {
@ -68,4 +71,3 @@ const char *const fill_img_fnames[NUM_FILLS] = {
};
#endif

View file

@ -180,7 +180,8 @@ 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);
@ -213,14 +214,16 @@ 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)
@ -233,7 +236,8 @@ 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)
@ -252,7 +256,8 @@ 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;
@ -264,7 +269,8 @@ TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc, const char *ttffile
#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
@ -276,7 +282,8 @@ TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc, const char *ttffile
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
tpf->pango_context = SDLPango_CreateContext_GivenFontDesc(desc);
@ -292,7 +299,9 @@ TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc, const char *ttffile
tpf->height = size; /* FIXME: Is this accurate!? -bjk 2007.07.12 */
#ifdef DEBUG
printf("%s:%d - TuxPaint_Font_OpenFont(\"%s\", \"%s\", %d) done (SDL_Pango)\n\n", __FILE__, __LINE__, pangodesc, ttffilename, size);
printf
("%s:%d - TuxPaint_Font_OpenFont(\"%s\", \"%s\", %d) done (SDL_Pango)\n\n",
__FILE__, __LINE__, pangodesc, ttffilename, size);
fflush(stdout);
#endif
@ -306,7 +315,8 @@ TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc, const char *ttffile
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
@ -316,7 +326,8 @@ TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc, const char *ttffile
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 */
}
@ -328,7 +339,9 @@ TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc, const char *ttffile
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 */
}
@ -336,8 +349,10 @@ TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc, const char *ttffile
ttf_font = TTF_OpenFont(ttffilename, size);
if (ttf_font == NULL) {
fprintf(stderr, "Cannot open TTF font '%s' (size %d)\n", ttffilename, size);
if (ttf_font == NULL)
{
fprintf(stderr, "Cannot open TTF font '%s' (size %d)\n", ttffilename,
size);
return NULL;
}
@ -345,7 +360,8 @@ TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc, const char *ttffile
(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, (familyname != NULL ? familyname : "<NULL>"));
printf("%s:%d - Loaded %s (\"%s\")\n", __FILE__, __LINE__, ttffilename,
(familyname != NULL ? familyname : "<NULL>"));
fflush(stdout);
#endif
@ -355,11 +371,14 @@ TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc, const char *ttffile
#ifndef NO_SDLPANGO
/* -- Try loading the font with Pango, instead! */
tpf = TuxPaint_Font_OpenFont(familyname, "", size);
if (tpf != NULL) {
if (tpf != NULL)
{
/* Success! Clean up and return the TuxPaint_Font that we got back */
#ifdef DEBUG
printf("%s:%d - Loaded via SDL_Pango!\n", __FILE__, __LINE__);
printf("%s:%d - TuxPaint_Font_OpenFont(\"%s\", \"%s\", %d) done (SDL_ttf -> SDL_Pango)\n\n", __FILE__, __LINE__, pangodesc, ttffilename, size);
printf
("%s:%d - TuxPaint_Font_OpenFont(\"%s\", \"%s\", %d) done (SDL_ttf -> SDL_Pango)\n\n",
__FILE__, __LINE__, pangodesc, ttffilename, size);
fflush(stdout);
#endif
TTF_CloseFont(ttf_font);
@ -377,12 +396,15 @@ TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc, const char *ttffile
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);
#ifdef DEBUG
printf("%s:%d - TuxPaint_Font_OpenFont(\"%s\", \"%s\", %d) done (SDL_ttf)\n\n", __FILE__, __LINE__, pangodesc, ttffilename, size);
printf
("%s:%d - TuxPaint_Font_OpenFont(\"%s\", \"%s\", %d) done (SDL_ttf)\n\n",
__FILE__, __LINE__, pangodesc, ttffilename, size);
fflush(stdout);
#endif
@ -415,7 +437,8 @@ void reliable_write(int fd, const void *buf, size_t count)
; // satisfy a C syntax abomination
p = (struct pollfd)
{
fd, POLLOUT, 0};
fd, POLLOUT, 0
};
poll(&p, 1, -1); // try not to burn CPU time
// FALL THROUGH
case EINTR:
@ -447,7 +470,8 @@ static void reliable_read(int fd, void *buf, size_t count)
; // satisfy a C syntax abomination
p = (struct pollfd)
{
fd, POLLIN, 0};
fd, POLLIN, 0
};
poll(&p, 1, -1); // try not to burn CPU time
// FALL THROUGH
case EINTR:
@ -580,7 +604,9 @@ 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);
@ -597,7 +623,8 @@ 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;
}
@ -607,9 +634,11 @@ 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;
}
@ -833,7 +862,8 @@ 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");
}
@ -871,7 +901,8 @@ 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);
@ -904,7 +935,8 @@ 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 (;;)
{
@ -916,13 +948,15 @@ 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)
@ -931,7 +965,8 @@ 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);
@ -955,8 +990,11 @@ 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)
static void loadfonts_locale_filter(SDL_Surface * screen,
SDL_Texture * texture,
SDL_Renderer * renderer,
const char *const dir,
const char *restrict const locale)
{
char buf[TP_FTW_PATHSIZE];
unsigned dirlen = strlen(dir);
@ -964,23 +1002,27 @@ static void loadfonts_locale_filter(SDL_Surface * screen, SDL_Texture * texture,
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,
/* static */ int load_user_fonts(SDL_Surface * screen, SDL_Texture * texture,
SDL_Renderer * renderer, void *vp,
const char *restrict const locale)
{
char *homedirdir;
(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)
{
@ -997,13 +1039,21 @@ static void loadfonts(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer
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");
@ -1042,8 +1092,10 @@ static void loadfonts(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer
#endif
#ifdef __APPLE__
homedirdir = malloc(snprintf(NULL, 0, "%s/fonts", apple_globalPreferencesPath()) + 1);
if(homedirdir) {
homedirdir =
malloc(snprintf(NULL, 0, "%s/fonts", apple_globalPreferencesPath()) + 1);
if (homedirdir)
{
sprintf(homedirdir, "%s/fonts", apple_globalPreferencesPath());
loadfonts(screen, texture, renderer, homedirdir);
free(homedirdir);
@ -1051,7 +1103,8 @@ static void loadfonts(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer
#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
@ -1071,7 +1124,8 @@ static void loadfonts(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer
#ifdef FORKED_FONTS
void run_font_scanner(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer,
void run_font_scanner(SDL_Surface * screen, SDL_Texture * texture,
SDL_Renderer * renderer,
const char *restrict const locale)
{
int sv[2];
@ -1138,7 +1192,8 @@ void run_font_scanner(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer
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;
@ -1207,7 +1262,8 @@ void run_font_scanner(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer
}
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;
@ -1231,7 +1287,8 @@ void receive_some_font_info(SDL_Surface * screen, SDL_Texture * texture, SDL_Ren
}
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);
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);
#endif
if (rc == -1)
@ -1244,7 +1301,8 @@ void receive_some_font_info(SDL_Surface * screen, SDL_Texture * texture, SDL_Ren
; // satisfy a C syntax abomination
p = (struct pollfd)
{
font_socket_fd, POLLIN, 0};
font_socket_fd, POLLIN, 0
};
show_progress_bar_(screen, texture, renderer);
poll(&p, 1, 29); // try not to burn CPU time
continue;
@ -1274,7 +1332,8 @@ void receive_some_font_info(SDL_Surface * screen, SDL_Texture * texture, SDL_Ren
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);
@ -1340,7 +1399,8 @@ 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;
@ -1349,7 +1409,8 @@ 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
@ -1373,7 +1434,8 @@ 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
@ -1439,7 +1501,8 @@ 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)
@ -1463,7 +1526,8 @@ 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
@ -1483,7 +1547,8 @@ 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;
@ -1496,7 +1561,8 @@ static int do_surfcmp(const SDL_Surface * const *const v1, const SDL_Surface * c
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)
{
was_bad_font = 1;
return 0;
@ -1619,7 +1685,8 @@ 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);
@ -1633,7 +1700,8 @@ 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 ("");
@ -1653,7 +1721,8 @@ 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 ("");
@ -1664,7 +1733,8 @@ 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 ("");
@ -1684,7 +1754,8 @@ 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 ("");
@ -1693,7 +1764,8 @@ const char *TuxPaint_Font_FontFaceStyleName(TuxPaint_Font * tpf)
#ifndef NO_SDLPANGO
void ssdl_color_to_pango_color(SDL_Color sdl_color, SDLPango_Matrix * pango_color)
void ssdl_color_to_pango_color(SDL_Color sdl_color,
SDLPango_Matrix * pango_color)
{
Uint8 pc[4][4];
@ -1720,7 +1792,8 @@ void ssdl_color_to_pango_color(SDL_Color sdl_color, SDLPango_Matrix * pango_colo
memcpy(pango_color, pc, 16);
}
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,9 +121,11 @@ 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,
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);
void receive_some_font_info(SDL_Surface * screen, SDL_Texture * texture,
SDL_Renderer * renderer);
#endif
//////////////////////////////////////////////////////////////////////
@ -191,7 +193,8 @@ 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);
@ -199,10 +202,12 @@ 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,
int load_user_fonts(SDL_Surface * screen, SDL_Texture * texture,
SDL_Renderer * renderer, void *vp,
const char *restrict const locale);
#endif

View file

@ -89,33 +89,38 @@ char *get_fname(const char *const name, int kind)
// const char *restrict const dir;
const char *dir;
if (kind == DIR_SAVE) {
if (kind == DIR_SAVE)
{
dir = savedir;
} else if (kind == DIR_DATA) {
}
else if (kind == DIR_DATA)
{
dir = datadir;
} else if (kind == DIR_EXPORT || kind == DIR_EXPORT_PARENT) {
}
else if (kind == DIR_EXPORT || kind == DIR_EXPORT_PARENT)
{
dir = exportdir;
}
snprintf(f, sizeof(f),
"%s%c%s",
dir, (*name) ? '/' : '\0', /* Some mkdir()'s don't like trailing slashes */
snprintf(f, sizeof(f), "%s%c%s", dir, (*name) ? '/' : '\0', /* Some mkdir()'s don't like trailing slashes */
name);
if (kind == DIR_EXPORT_PARENT) {
if (kind == DIR_EXPORT_PARENT)
{
int len, i, stop;
stop = -1;
len = strlen(f);
for (i = len - 1; i >= 0 && stop == -1; i--) {
for (i = len - 1; i >= 0 && stop == -1; i--)
{
if (f[i] == '/')
stop = i;
}
if (stop != -1) {
if (stop != -1)
{
f[stop] = '\0';
}
}
return strdup(f);
}

View file

@ -34,14 +34,14 @@ static uint8_t vga[0x30] = {
0xFF, 0xFF, 0xFF,
};
struct Node {
struct Node
{
uint16_t key;
struct Node *children[];
};
typedef struct Node Node;
static Node *
new_node(uint16_t key, int degree)
static Node *new_node(uint16_t key, int degree)
{
Node *node = calloc(1, sizeof(*node) + degree * sizeof(Node *));
if (node)
@ -49,8 +49,7 @@ new_node(uint16_t key, int degree)
return node;
}
static Node *
new_trie(int degree, int *nkeys)
static Node *new_trie(int degree, int *nkeys)
{
Node *root = new_node(0, degree);
/* Create nodes for single pixels. */
@ -60,8 +59,7 @@ new_trie(int degree, int *nkeys)
return root;
}
static void
del_trie(Node *root, int degree)
static void del_trie(Node * root, int degree)
{
int i;
@ -77,18 +75,16 @@ 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; gif->h = height;
gif->w = width;
gif->h = height;
gif->depth = depth > 1 ? depth : 2;
gif->frame = (uint8_t *) & gif[1];
gif->back = &gif->frame[width * height];
@ -98,29 +94,56 @@ ge_new_gif(
#ifdef _WIN32
setmode(gif->fd, O_BINARY);
#endif
res = write(gif->fd, "GIF89a", 6); OR_ABORT;
res = write_num(gif->fd, width); OR_ABORT;
res = write_num(gif->fd, height); OR_ABORT;
res = write(gif->fd, (uint8_t []) {0xF0 | (depth-1), 0x00, 0x00}, 3); OR_ABORT;
if (palette) {
res = write(gif->fd, palette, 3 << depth); OR_ABORT;
} else if (depth <= 4) {
res = write(gif->fd, vga, 3 << depth); OR_ABORT;
} else {
res = write(gif->fd, vga, sizeof(vga)); OR_ABORT;
res = write(gif->fd, "GIF89a", 6);
OR_ABORT;
res = write_num(gif->fd, width);
OR_ABORT;
res = write_num(gif->fd, height);
OR_ABORT;
res = write(gif->fd, (uint8_t[])
{
0xF0 | (depth - 1), 0x00, 0x00}
, 3);
OR_ABORT;
if (palette)
{
res = write(gif->fd, palette, 3 << depth);
OR_ABORT;
}
else if (depth <= 4)
{
res = write(gif->fd, vga, 3 << depth);
OR_ABORT;
}
else
{
res = write(gif->fd, vga, sizeof(vga));
OR_ABORT;
i = 0x10;
for (r = 0; r < 6; r++) {
for (g = 0; g < 6; g++) {
for (b = 0; b < 6; b++) {
res = write(gif->fd, (uint8_t []) {r*51, g*51, b*51}, 3); OR_ABORT;
for (r = 0; r < 6; r++)
{
for (g = 0; g < 6; g++)
{
for (b = 0; b < 6; b++)
{
res = write(gif->fd, (uint8_t[])
{
r * 51, g * 51, b * 51}
, 3);
OR_ABORT;
if (++i == 1 << depth)
goto done_gct;
}
}
}
for (i = 1; i <= 24; i++) {
for (i = 1; i <= 24; i++)
{
v = i * 0xFF / 25;
res = write(gif->fd, (uint8_t []) {v, v, v}, 3); OR_ABORT;
res = write(gif->fd, (uint8_t[])
{
v, v, v}
, 3);
OR_ABORT;
}
}
done_gct:
@ -133,23 +156,30 @@ no_gif:
return NULL;
}
static void
put_loop(ge_GIF *gif, uint16_t loop)
static void put_loop(ge_GIF * gif, uint16_t loop)
{
ssize_t res;
res = write(gif->fd, (uint8_t []) {'!', 0xFF, 0x0B}, 3); OR_ABORT2;
res = write(gif->fd, "NETSCAPE2.0", 11); OR_ABORT2;
res = write(gif->fd, (uint8_t []) {0x03, 0x01}, 2); OR_ABORT2;
res = write_num(gif->fd, loop); OR_ABORT2;
res = write(gif->fd, "\0", 1); OR_ABORT2;
res = write(gif->fd, (uint8_t[])
{
'!', 0xFF, 0x0B}, 3);
OR_ABORT2;
res = write(gif->fd, "NETSCAPE2.0", 11);
OR_ABORT2;
res = write(gif->fd, (uint8_t[])
{
0x03, 0x01}, 2);
OR_ABORT2;
res = write_num(gif->fd, loop);
OR_ABORT2;
res = write(gif->fd, "\0", 1);
OR_ABORT2;
}
/* Add packed key to buffer, updating offset and partial.
* gif->offset holds position to put next *bit*
* gif->partial holds bits to include in next byte */
static void
put_key(ge_GIF *gif, uint16_t key, int key_size)
static void put_key(ge_GIF * gif, uint16_t key, int key_size)
{
int byte_offset, bit_offset, bits_to_write;
ssize_t res;
@ -158,11 +188,15 @@ put_key(ge_GIF *gif, uint16_t key, int key_size)
bit_offset = gif->offset % 8;
gif->partial |= ((uint32_t) key) << bit_offset;
bits_to_write = bit_offset + key_size;
while (bits_to_write >= 8) {
while (bits_to_write >= 8)
{
gif->buffer[byte_offset++] = gif->partial & 0xFF;
if (byte_offset == 0xFF) {
res = write(gif->fd, "\xFF", 1); OR_ABORT2;
res = write(gif->fd, gif->buffer, 0xFF); OR_ABORT2;
if (byte_offset == 0xFF)
{
res = write(gif->fd, "\xFF", 1);
OR_ABORT2;
res = write(gif->fd, gif->buffer, 0xFF);
OR_ABORT2;
byte_offset = 0;
}
gif->partial >>= 8;
@ -171,8 +205,7 @@ put_key(ge_GIF *gif, uint16_t key, int key_size)
gif->offset = (gif->offset + key_size) % (0xFF * 8);
}
static void
end_key(ge_GIF *gif)
static void end_key(ge_GIF * gif)
{
int byte_offset;
ssize_t res;
@ -180,9 +213,15 @@ end_key(ge_GIF *gif)
byte_offset = gif->offset / 8;
if (gif->offset % 8)
gif->buffer[byte_offset++] = gif->partial & 0xFF;
res = write(gif->fd, (uint8_t []) {byte_offset}, 1); OR_ABORT2;
res = write(gif->fd, gif->buffer, byte_offset); OR_ABORT2;
res = write(gif->fd, "\0", 1); OR_ABORT2;
res = write(gif->fd, (uint8_t[])
{
byte_offset}
, 1);
OR_ABORT2;
res = write(gif->fd, gif->buffer, byte_offset);
OR_ABORT2;
res = write(gif->fd, "\0", 1);
OR_ABORT2;
gif->offset = gif->partial = 0;
}
@ -194,28 +233,44 @@ put_image(ge_GIF *gif, uint16_t w, uint16_t h, uint16_t x, uint16_t y)
ssize_t res;
int degree = 1 << gif->depth;
res = write(gif->fd, ",", 1); OR_ABORT2;
res = write_num(gif->fd, x); OR_ABORT2;
res = write_num(gif->fd, y); OR_ABORT2;
res = write_num(gif->fd, w); OR_ABORT2;
res = write_num(gif->fd, h); OR_ABORT2;
res = write(gif->fd, (uint8_t []) {0x00, gif->depth}, 2); OR_ABORT2;
res = write(gif->fd, ",", 1);
OR_ABORT2;
res = write_num(gif->fd, x);
OR_ABORT2;
res = write_num(gif->fd, y);
OR_ABORT2;
res = write_num(gif->fd, w);
OR_ABORT2;
res = write_num(gif->fd, h);
OR_ABORT2;
res = write(gif->fd, (uint8_t[])
{
0x00, gif->depth}, 2);
OR_ABORT2;
root = node = new_trie(degree, &nkeys);
key_size = gif->depth + 1;
put_key(gif, degree, key_size); /* clear code */
for (i = y; i < y+h; i++) {
for (j = x; j < x+w; j++) {
for (i = y; i < y + h; i++)
{
for (j = x; j < x + w; j++)
{
uint8_t pixel = gif->frame[i * gif->w + j] & (degree - 1);
child = node->children[pixel];
if (child) {
if (child)
{
node = child;
} else {
}
else
{
put_key(gif, node->key, key_size);
if (nkeys < 0x1000) {
if (nkeys < 0x1000)
{
if (nkeys == (1 << key_size))
key_size++;
node->children[pixel] = new_node(nkeys++, degree);
} else {
}
else
{
put_key(gif, degree, key_size); /* clear code */
del_trie(root, degree);
root = node = new_trie(degree, &nkeys);
@ -236,25 +291,38 @@ 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; bottom = 0;
left = gif->w;
right = 0;
top = gif->h;
bottom = 0;
k = 0;
for (i = 0; i < gif->h; i++) {
for (j = 0; j < gif->w; j++, k++) {
if (gif->frame[k] != gif->back[k]) {
if (j < left) left = j;
if (j > right) right = j;
if (i < top) top = i;
if (i > bottom) bottom = i;
for (i = 0; i < gif->h; i++)
{
for (j = 0; j < gif->w; j++, k++)
{
if (gif->frame[k] != gif->back[k])
{
if (j < left)
left = j;
if (j > right)
right = j;
if (i < top)
top = i;
if (i > bottom)
bottom = i;
}
}
}
if (left != gif->w && top != gif->h) {
*x = left; *y = top;
if (left != gif->w && top != gif->h)
{
*x = left;
*y = top;
*w = right - left + 1;
*h = bottom - top + 1;
return 1;
} else {
}
else
{
return 0;
}
}
@ -267,29 +335,35 @@ get_bbox(ge_GIF *gif, uint16_t *w, uint16_t *h, uint16_t *x, uint16_t *y)
* a minimum of `delay` == 6. If `delay` == 0, no delay information will be stored
* for the frame. This can be used when creating still (single-frame) GIF images.
*/
static void
set_delay(ge_GIF *gif, uint16_t d)
static void set_delay(ge_GIF * gif, uint16_t d)
{
ssize_t res;
res = write(gif->fd, (uint8_t []) {'!', 0xF9, 0x04, 0x04}, 4); OR_ABORT2;
res = write_num(gif->fd, d); OR_ABORT2;
res = write(gif->fd, "\0\0", 2); OR_ABORT2;
res = write(gif->fd, (uint8_t[])
{
'!', 0xF9, 0x04, 0x04}, 4);
OR_ABORT2;
res = write_num(gif->fd, d);
OR_ABORT2;
res = write(gif->fd, "\0\0", 2);
OR_ABORT2;
}
void
ge_add_frame(ge_GIF *gif, uint16_t delay)
void ge_add_frame(ge_GIF * gif, uint16_t delay)
{
uint16_t w, h, x, y;
uint8_t *tmp;
if (delay)
set_delay(gif, delay);
if (gif->nframes == 0) {
if (gif->nframes == 0)
{
w = gif->w;
h = gif->h;
x = y = 0;
} else if (!get_bbox(gif, &w, &h, &x, &y)) {
}
else if (!get_bbox(gif, &w, &h, &x, &y))
{
/* image's not changed; save one pixel just to add delay */
w = h = 1;
x = y = 0;
@ -301,12 +375,12 @@ ge_add_frame(ge_GIF *gif, uint16_t delay)
gif->frame = tmp;
}
void
ge_close_gif(ge_GIF* gif)
void ge_close_gif(ge_GIF * gif)
{
ssize_t res;
res = write(gif->fd, ";", 1); OR_ABORT2;
res = write(gif->fd, ";", 1);
OR_ABORT2;
close(gif->fd);
free(gif);
}

View file

@ -3,7 +3,8 @@
#include <stdint.h>
typedef struct ge_GIF {
typedef struct ge_GIF
{
uint16_t w, h;
int depth;
int fd;
@ -14,10 +15,8 @@ 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

@ -60,10 +60,16 @@ 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);
@ -484,7 +490,9 @@ 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"
@ -505,7 +513,8 @@ static void show_lang_usage(int exitcode)
/* brx */ " bodo\n"
/* nb */ " bokmal\n"
/* bs */ " bosnian\n"
/* pt_BR */ " brazilian brazilian-portuguese portugues-brazilian\n"
/* pt_BR */
" brazilian brazilian-portuguese portugues-brazilian\n"
/* br */ " breton brezhoneg\n"
/* en_GB */ " british british-english\n"
/* bg_BG */ " bulgarian\n"
@ -562,7 +571,8 @@ static void show_lang_usage(int exitcode)
/* mni */ " manipuri-bengali\n"
/* mni@meiteimayek */ " manipuri-meitei-mayek\n"
/* nr */ " marathi\n"
/* es_MX */ " mexican mexican-spanish espanol-mejicano\n"
/* es_MX */
" mexican mexican-spanish espanol-mejicano\n"
/* mn */ " mongolian\n"
/* nr */ " ndebele\n"
/* ne */ " nepali\n"
@ -760,7 +770,8 @@ 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);
}
/**
@ -804,7 +815,8 @@ 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 (;;)
@ -828,7 +840,8 @@ 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--)
{
@ -854,7 +867,8 @@ 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;
@ -865,9 +879,11 @@ 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;
if (inlocale[j] != candidate[j])
break;
}
if (j > outlocale_score)
@ -944,7 +960,8 @@ 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;
@ -959,7 +976,8 @@ 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;
@ -996,7 +1014,8 @@ 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;
@ -1048,7 +1067,8 @@ static void mysetenv(const char *name, const char *value)
char *str;
#endif
if (name != NULL && value != NULL) {
if (name != NULL && value != NULL)
{
#ifdef HAVE_SETENV
setenv(name, value, 1);
#else
@ -1058,11 +1078,12 @@ static void mysetenv(const char *name, const char *value)
sprintf(str, "%s=%s", name, value);
putenv(str);
#endif
} else {
fprintf(stderr, "WARNING: mysetenv() received a null pointer. name=%s, value=%s\n",
(name == NULL ? "NULL" : name),
(value == NULL ? "NULL" : value)
);
}
else
{
fprintf(stderr,
"WARNING: mysetenv() received a null pointer. name=%s, value=%s\n",
(name == NULL ? "NULL" : name), (value == NULL ? "NULL" : value));
}
}
@ -1074,7 +1095,8 @@ static 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;
@ -1111,7 +1133,8 @@ static int set_current_language(const char *restrict loc, int * ptr_num_wished_l
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
@ -1228,9 +1251,12 @@ static int set_current_language(const char *restrict loc, int * ptr_num_wished_l
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]);
@ -1264,13 +1290,15 @@ static int set_current_language(const char *restrict loc, int * ptr_num_wished_l
#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;
@ -1289,7 +1317,8 @@ static int set_current_language(const char *restrict loc, int * ptr_num_wished_l
* @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);

View file

@ -206,7 +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;
int setup_i18n(const char *restrict lang, const char *restrict locale,
int *ptr_num_wished_languages) MUST_CHECK;
#ifdef NO_SDLPANGO
int smash_i18n(void) MUST_CHECK;

View file

@ -358,7 +358,8 @@ 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;
@ -379,7 +380,8 @@ 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,
static const wchar_t *sm_search(STATE_MACHINE * start, wchar_t *key,
int *matched, STATE_MACHINE ** penult,
STATE_MACHINE ** end)
{
STATE_MACHINE *sm = sm_search_shallow(start, (char) *key);
@ -416,7 +418,8 @@ 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]);
@ -513,7 +516,8 @@ 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)
{
@ -681,7 +685,9 @@ static const wchar_t *charmap_search(CHARMAP * cm, wchar_t * s)
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
@ -824,7 +830,8 @@ 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;
@ -976,7 +983,8 @@ 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);
}
@ -1047,7 +1055,8 @@ 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)
@ -1072,7 +1081,8 @@ 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? */
@ -1199,7 +1209,8 @@ 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);
}
@ -1293,7 +1304,8 @@ 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? */
@ -1419,7 +1431,8 @@ 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);
}
@ -1493,7 +1506,8 @@ 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)
@ -1518,7 +1532,8 @@ 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? */
@ -1620,7 +1635,8 @@ static int im_event_ko_isvowel(CHARMAP * cm, wchar_t 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);
}
@ -1669,7 +1685,8 @@ 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);
}
@ -1741,7 +1758,8 @@ 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)
@ -1765,7 +1783,8 @@ 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? */

View file

@ -59,7 +59,8 @@ 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);
@ -80,11 +81,16 @@ static SDL_Surface *SDL_DisplayFormatAlpha(SDL_Surface * surface)
}
struct osk_keyboard *osk_create(char *layout_name, SDL_Surface * canvas,
SDL_Surface * BLANK_button_up, SDL_Surface * BLANK_button_down,
SDL_Surface * BLANK_button_off, SDL_Surface * BLANK_button_nav,
SDL_Surface * BLANK_button_up,
SDL_Surface * BLANK_button_down,
SDL_Surface * BLANK_button_off,
SDL_Surface * BLANK_button_nav,
SDL_Surface * BLANK_button_hold,
SDL_Surface * BLANK_oskdel, SDL_Surface * BLANK_osktab, SDL_Surface * BLANK_oskenter,
SDL_Surface * BLANK_oskcapslock, SDL_Surface * BLANK_oskshift,
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 *surface;
@ -105,7 +111,8 @@ 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)
{
@ -123,15 +130,17 @@ struct osk_keyboard *osk_create(char * layout_name, SDL_Surface * canvas,
layout_avail_height = (canvas->h * 0.5);
if (layout->width * BLANK_button_up->w >= layout_avail_width || /* Don't allow it to be > 90% of the width of the canvas */
layout->height * BLANK_button_up->h >= layout_avail_height /* Don't allow it to be > 50% of the height of the canvas */) {
layout->height * BLANK_button_up->h >= layout_avail_height
/* Don't allow it to be > 50% of the height of the canvas */ )
{
/* Full-size buttons too large, resize to fit */
float max_w, max_h;
float scale_w, scale_h;
#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,
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);
#endif
@ -141,8 +150,7 @@ struct osk_keyboard *osk_create(char * layout_name, SDL_Surface * canvas,
#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_height, layout->height, max_w, max_h);
#endif
if (max_w > max_h)
@ -154,8 +162,7 @@ struct osk_keyboard *osk_create(char * layout_name, SDL_Surface * canvas,
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);
printf("...so scaling by w=%.2f & h=%.2f\n", scale_w, scale_h);
#endif
button_up = zoomSurface(BLANK_button_up, scale_w, scale_h, 1);
@ -168,7 +175,9 @@ struct osk_keyboard *osk_create(char * layout_name, SDL_Surface * canvas,
oskenter = zoomSurface(BLANK_oskenter, scale_w, scale_h, 1);
oskcapslock = zoomSurface(BLANK_oskcapslock, scale_w, scale_h, 1);
oskshift = zoomSurface(BLANK_oskshift, scale_w, scale_h, 1);
} else {
}
else
{
button_up = SDL_DisplayFormatAlpha(BLANK_button_up);
button_down = SDL_DisplayFormatAlpha(BLANK_button_down);
button_off = SDL_DisplayFormatAlpha(BLANK_button_off);
@ -185,7 +194,8 @@ 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");
@ -238,7 +248,8 @@ struct osk_keyboard *osk_create(char * layout_name, SDL_Surface * canvas,
keyboard->BLANK_oskshift = BLANK_oskshift;
SDL_FillRect(surface, NULL,
SDL_MapRGB(surface->format, keyboard->layout->bgcolor.r, keyboard->layout->bgcolor.g,
SDL_MapRGB(surface->format, keyboard->layout->bgcolor.r,
keyboard->layout->bgcolor.g,
keyboard->layout->bgcolor.b));
keybd_prepare(keyboard);
@ -247,7 +258,8 @@ 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;
@ -289,7 +301,8 @@ static struct osk_layout *load_layout(on_screen_keyboard * keyboard, char *layou
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");
@ -409,7 +422,8 @@ 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;
@ -518,7 +532,8 @@ 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);
@ -529,14 +544,17 @@ 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++;
@ -633,7 +651,9 @@ 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)
{
@ -673,7 +693,8 @@ 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;
@ -740,7 +761,9 @@ static void gettokens(char *line, char *delim, char **pointer, osk_composenode *
}
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));
@ -751,7 +774,8 @@ static void gettokens(char *line, char *delim, char **pointer, osk_composenode *
/* 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;
}
@ -782,7 +806,8 @@ 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;
@ -890,7 +915,8 @@ 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;
@ -911,13 +937,15 @@ 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++;
}
@ -974,7 +1002,8 @@ 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 */
@ -992,7 +1021,9 @@ 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;
@ -1112,22 +1143,26 @@ 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);
}
}
@ -1144,7 +1179,8 @@ static void keybd_prepare(on_screen_keyboard * keyboard)
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);
}
@ -1154,7 +1190,8 @@ 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;
@ -1206,7 +1243,8 @@ 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;
@ -1298,26 +1336,38 @@ 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);
@ -1379,7 +1429,8 @@ 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);
@ -1412,7 +1463,8 @@ 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)
@ -1422,7 +1474,9 @@ 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);
@ -1439,10 +1493,12 @@ 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;
@ -1550,7 +1606,8 @@ 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;
@ -1570,7 +1627,8 @@ 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;
@ -1607,7 +1665,8 @@ static int handle_keymods(char *keysym, osk_key * key, on_screen_keyboard * keyb
/* 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)
{
@ -1787,8 +1846,7 @@ struct osk_keyboard *osk_clicked(on_screen_keyboard * keyboard, int x, int y)
keyboard->BLANK_button_hold,
keyboard->BLANK_oskdel, keyboard->BLANK_osktab,
keyboard->BLANK_oskenter, keyboard->BLANK_oskcapslock,
keyboard->BLANK_oskshift,
keyboard->disable_change);
keyboard->BLANK_oskshift, keyboard->disable_change);
free(aux_list_ptr);
@ -1851,7 +1909,8 @@ 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';

View file

@ -148,16 +148,22 @@ typedef struct osk_keyboard
} on_screen_keyboard;
struct osk_keyboard *osk_create(char *layout_name, SDL_Surface * canvas,
SDL_Surface * BLANK_button_up, SDL_Surface * BLANK_button_down,
SDL_Surface * BLANK_button_off, SDL_Surface * BLANK_button_nav,
SDL_Surface * BLANK_button_up,
SDL_Surface * BLANK_button_down,
SDL_Surface * BLANK_button_off,
SDL_Surface * BLANK_button_nav,
SDL_Surface * BLANK_button_hold,
SDL_Surface * BLANK_oskdel, SDL_Surface * BLANK_osktab, SDL_Surface * BLANK_oskenter,
SDL_Surface * BLANK_oskcapslock, SDL_Surface * BLANK_oskshift,
SDL_Surface * BLANK_oskdel,
SDL_Surface * BLANK_osktab,
SDL_Surface * BLANK_oskenter,
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,
void osk_get_layout_data(char *layout_name, int *layout_w, int *layout_h,
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);

View file

@ -95,5 +95,5 @@ struct cfginfo
#define CFGINFO_MAXOFFSET (sizeof(struct cfginfo))
extern void parse_one_option(struct cfginfo *restrict tmpcfg, const char *str, const char *opt,
const char *restrict src);
extern void parse_one_option(struct cfginfo *restrict tmpcfg, const char *str,
const char *opt, const char *restrict src);

View file

@ -37,7 +37,9 @@ 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 */
@ -58,7 +60,9 @@ 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 */
@ -79,7 +83,9 @@ 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 */
@ -112,7 +118,9 @@ 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 */
@ -239,11 +247,11 @@ static Uint32 getpixel32(SDL_Surface * surface, int x, int y)
return *(Uint32 *) p; // 32-bit display
}
void (*putpixels[]) (SDL_Surface *, int, int, Uint32) =
{
putpixel8, putpixel8, putpixel16, putpixel24, putpixel32};
void (*putpixels[])(SDL_Surface *, int, int, Uint32) = {
putpixel8, putpixel8, putpixel16, putpixel24, putpixel32
};
Uint32(*getpixels[])(SDL_Surface *, int, int) =
{
getpixel8, getpixel8, getpixel16, getpixel24, getpixel32};
Uint32(*getpixels[])(SDL_Surface *, int, int) = {
getpixel8, getpixel8, getpixel16, getpixel24, getpixel32
};

View file

@ -48,7 +48,8 @@ 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;
@ -56,8 +57,8 @@ void playsound(SDL_Surface * screen, int chan, int s, int override, int x, int y
if (!mute && use_sound && s != SND_NONE)
{
#ifdef DEBUG
printf("playsound #%d in channel %d, pos (%d,%d), %soverride, ptr=%p\n", s, chan, x, y, override ? "" : "no ",
sounds[s]);
printf("playsound #%d in channel %d, pos (%d,%d), %soverride, ptr=%p\n",
s, chan, x, y, override ? "" : "no ", sounds[s]);
fflush(stdout);
#endif
if (override || !Mix_Playing(chan))
@ -107,7 +108,8 @@ void playsound(SDL_Surface * screen, int chan, int s, int override, int x, int y
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

@ -37,6 +37,7 @@
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

@ -79,7 +79,8 @@ static int f2dec(float f)
/* 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,7 +94,8 @@ 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;
@ -147,7 +149,8 @@ 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
@ -155,7 +158,8 @@ 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;
@ -177,13 +181,16 @@ 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
@ -209,7 +216,8 @@ 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");
@ -228,20 +236,23 @@ 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,7 +79,8 @@
#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,7 +39,8 @@ 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;
@ -72,7 +73,9 @@ void show_progress_bar_(SDL_Surface * screen, SDL_Texture * texture, SDL_Rendere
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,6 +36,7 @@
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,7 +305,8 @@ 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

@ -334,8 +334,10 @@ 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."),
@ -362,8 +364,10 @@ 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."),
gettext_noop("A star with 3 points."),
gettext_noop("A star with 3 points."),
@ -423,15 +427,18 @@ const char *const shapemode_img_fnames[NUM_SHAPEMODES] = {
/* String shown when Shapes tool is selected;
one version for normal ("complex shapes"),
the other for simplified mode ("simple shapes") */
enum {
enum
{
SHAPE_COMPLEXITY_NORMAL,
SHAPE_COMPLEXITY_SIMPLE,
NUM_SHAPE_COMPLEXITIES
};
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. 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.")
};
/* Strings shown when switching between "from center"

View file

@ -29,7 +29,8 @@
#include <unistd.h>
#include <png.h>
int main(int argc, char * argv[]) {
int main(int argc, char *argv[])
{
int i, w, h, y;
FILE *fi;
png_structp png;
@ -39,7 +40,8 @@ int main(int argc, char * argv[]) {
/* Usage output */
if (argc == 1 || strcmp(argv[1], "--help") == 0) {
if (argc == 1 || strcmp(argv[1], "--help") == 0)
{
fprintf(stderr, "Usage: %s file.png [file.png ...]\n", argv[0]);
exit(1);
}
@ -53,30 +55,39 @@ int main(int argc, char * argv[]) {
/* Open each PNG image!... */
for (i = 1; i < argc; i++) {
printf("%5d ------------------------------------------------------------------\n", i);
for (i = 1; i < argc; i++)
{
printf
("%5d ------------------------------------------------------------------\n",
i);
printf("%s\n", argv[i]);
fflush(stdout);
/* Open the file */
fi = fopen(argv[i], "rb");
if (fi == NULL) {
if (fi == NULL)
{
printf("Cannot open\n");
} else {
}
else
{
/* Prepare PNG library stuff... */
png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png) {
if (!png)
{
fprintf(stderr, "Cannot png_create_read_struct()!\n");
exit(1);
}
info = png_create_info_struct(png);
if (!info) {
if (!info)
{
fprintf(stderr, "Cannot png_create_info_struct()!\n");
exit(1);
}
if (setjmp(png_jmpbuf(png))) {
if (setjmp(png_jmpbuf(png)))
{
fprintf(stderr, "Cannot setjmp(png_jmpbuf(png)))!\n");
exit(1);
}
@ -95,39 +106,43 @@ int main(int argc, char * argv[]) {
depth = png_get_bit_depth(png, info);
/* If 16-bit, strip to 8-bit */
if (depth == 16) {
if (depth == 16)
{
printf("test-png warning: 16-bit\n");
png_set_strip_16(png);
}
/* Switch palette to RGB */
if (ctype == PNG_COLOR_TYPE_PALETTE) {
if (ctype == PNG_COLOR_TYPE_PALETTE)
{
printf("test-png warning: paletted\n");
png_set_palette_to_rgb(png);
}
/* Expand low-depth greyscale up to 8-bit */
if (ctype == PNG_COLOR_TYPE_GRAY && depth < 8) {
if (ctype == PNG_COLOR_TYPE_GRAY && depth < 8)
{
printf("test-png warning: greyscale with only %d-bit depth\n", depth);
png_set_expand_gray_1_2_4_to_8(png);
}
/* Expand tRNS chunks into alpha */
if (png_get_valid(png, info, PNG_INFO_tRNS)) {
if (png_get_valid(png, info, PNG_INFO_tRNS))
{
printf("test-png warning: contains tRNS chunk\n");
png_set_tRNS_to_alpha(png);
}
/* Fill alpha channel if there is none */
if (ctype == PNG_COLOR_TYPE_RGB ||
ctype == PNG_COLOR_TYPE_GRAY ||
ctype == PNG_COLOR_TYPE_PALETTE) {
ctype == PNG_COLOR_TYPE_GRAY || ctype == PNG_COLOR_TYPE_PALETTE)
{
png_set_filler(png, 0xFF, PNG_FILLER_AFTER);
}
/* Expand grey to color */
if (ctype == PNG_COLOR_TYPE_GRAY ||
ctype == PNG_COLOR_TYPE_GRAY_ALPHA) {
if (ctype == PNG_COLOR_TYPE_GRAY || ctype == PNG_COLOR_TYPE_GRAY_ALPHA)
{
printf("test-png warning: greyscale\n");
png_set_gray_to_rgb(png);
}
@ -137,15 +152,19 @@ int main(int argc, char * argv[]) {
/* Allocate space */
rows = (png_bytep *) malloc(sizeof(png_bytep) * h);
if (!rows) {
if (!rows)
{
fprintf(stderr, "Failed to malloc() space for image data rows!\n");
exit(1);
}
for (y = 0; y < h; y++) {
for (y = 0; y < h; y++)
{
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);
if (!rows[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

@ -107,7 +107,9 @@ 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));
}
/**
@ -124,10 +126,14 @@ 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;
size =
(((char *) &entry->d_name) - ((char *) entry)) + strlen(entry->d_name) +
1;
block = (struct dirent *) malloc(size);
if (block == NULL)
return -1;
@ -145,7 +151,8 @@ 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;
@ -166,6 +173,7 @@ int scandir(const char *dir, struct dirent ***namelist, selectCB select, comparC
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,4 +71,5 @@ 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,7 +68,8 @@ 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;
@ -104,7 +105,8 @@ 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);
@ -143,7 +145,8 @@ 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;
@ -156,7 +159,8 @@ 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;
@ -166,7 +170,9 @@ 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;
@ -189,7 +195,8 @@ 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;
@ -265,7 +272,8 @@ 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);
}
@ -318,7 +326,8 @@ 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;
@ -514,7 +523,8 @@ 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;
@ -563,7 +573,8 @@ 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;
@ -587,7 +598,8 @@ 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;
@ -609,7 +621,8 @@ 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;
@ -662,7 +675,8 @@ 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;
@ -676,7 +690,8 @@ 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;
}
}
@ -693,7 +708,9 @@ 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,7 +15,8 @@
#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

@ -11,13 +11,16 @@ int MoveFileToRecycleBin(const TCHAR *fullPathName)
TCHAR *dest;
fileOp.pFrom = dest = alloca(sizeof(*dest) * (_tcslen(fullPathName) + 2));
while((*dest++ = *src++) != _T('\0')) {}
while ((*dest++ = *src++) != _T('\0'))
{
}
*dest = _T('\0');
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);
}
@ -26,8 +29,10 @@ int win32_trash(const char *path)
char *p, *src;
src = p = strdup(path);
while(*p != '\0'){
if (*p == '/') *p = '\\';
while (*p != '\0')
{
if (*p == '/')
*p = '\\';
p++;
}
return MoveFileToRecycleBin(src);