Added dirty rect to magic api.

Added 'release' event to magic api.
This commit is contained in:
William Kendrick 2007-07-08 23:17:18 +00:00
parent f61128527d
commit c44cf54033
16 changed files with 354 additions and 56 deletions

View file

@ -211,19 +211,35 @@ void blocks_chalk_drip_linecb(void * ptr, int which,
// 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_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
{
api->line(which, canvas, last, ox, oy, x, y, 1, blocks_chalk_drip_linecb);
if (ox > x) { int tmp = ox; ox = x; x = tmp; }
if (oy > y) { int tmp = oy; oy = y; y = tmp; }
update_rect->x = ox - 16;
update_rect->y = oy - 16;
update_rect->w = (x + 16) - update_rect->x;
update_rect->h = (y + 16) - update_rect->y;
api->playsound(snd_effect[which], (x * 255) / canvas->w, 255);
}
// Affect the canvas on click:
void blocks_chalk_drip_click(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y)
int x, int y, SDL_Rect * update_rect)
{
blocks_chalk_drip_drag(api, which, canvas, last, x, y, x, y, update_rect);
}
// Affect the canvas on release:
void blocks_chalk_drip_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
{
blocks_chalk_drip_drag(api, which, canvas, last, x, y, x, y);
}
// No setup happened:

View file

@ -127,19 +127,35 @@ void do_blur(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
// 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_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
{
api->line(which, canvas, last, ox, oy, x, y, 1, do_blur);
if (ox > x) { int tmp = ox; ox = x; x = tmp; }
if (oy > y) { int tmp = oy; oy = y; y = tmp; }
update_rect->x = ox - 16;
update_rect->y = oy - 16;
update_rect->w = (x + 16) - update_rect->x;
update_rect->h = (y + 16) - update_rect->y;
api->playsound(blur_snd, (x * 255) / canvas->w, 255);
}
// Affect the canvas on click:
void blur_click(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y)
int x, int y, SDL_Rect * update_rect)
{
blur_drag(api, which, canvas, last, x, y, x, y, update_rect);
}
// Affect the canvas on release:
void blur_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
{
blur_drag(api, which, canvas, last, x, y, x, y);
}
void blur_shutdown(magic_api * api)

View file

@ -176,19 +176,34 @@ void do_bricks(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
// 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_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
{
api->line(which, canvas, last, ox, oy, x, y, 1, do_bricks);
if (ox > x) { int tmp = ox; ox = x; x = tmp; }
if (oy > y) { int tmp = oy; oy = y; y = tmp; }
update_rect->x = x - 36;
update_rect->y = y - 24;
update_rect->w = (ox + 36) - update_rect->x;
update_rect->h = (oy + 24) - update_rect->h;
api->playsound(brick_snd, (x * 255) / canvas->w, 255);
}
// Affect the canvas on click:
void bricks_click(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y)
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, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
{
bricks_drag(api, which, canvas, last, x, y, x, y);
}
// No setup happened:

View file

@ -145,19 +145,35 @@ void do_cartoon(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
// 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_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
{
api->line(which, canvas, last, ox, oy, x, y, 1, do_cartoon);
if (ox > x) { int tmp = ox; ox = x; x = tmp; }
if (oy > y) { int tmp = oy; oy = y; y = tmp; }
update_rect->x = ox - 16;
update_rect->y = oy - 16;
update_rect->w = (x + 16) - update_rect->x;
update_rect->h = (y + 16) - update_rect->h;
api->playsound(cartoon_snd, (x * 255) / canvas->w, 255);
}
// Affect the canvas on click:
void cartoon_click(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y)
int x, int y, SDL_Rect * update_rect)
{
cartoon_drag(api, which, canvas, last, x, y, x, y, update_rect);
}
// Affect the canvas on release:
void cartoon_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
{
cartoon_drag(api, which, canvas, last, x, y, x, y);
}
// No setup happened:

View file

@ -118,24 +118,41 @@ void do_fade_darken(void * ptr, int which,
// Ask Tux Paint to call our 'do_fade_darken()' 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_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
{
SDL_LockSurface(last);
SDL_LockSurface(canvas);
api->line(which, canvas, last, ox, oy, x, y, 1, do_fade_darken);
api->playsound(snd_effects[which], (x * 255) / canvas->w, 255);
SDL_UnlockSurface(canvas);
SDL_UnlockSurface(last);
api->playsound(snd_effects[which], (x * 255) / canvas->w, 255);
if (ox > x) { int tmp = ox; ox = x; x = tmp; }
if (oy > y) { int tmp = oy; oy = y; y = tmp; }
update_rect->x = ox - 16;
update_rect->y = oy - 16;
update_rect->w = (x + 16) - update_rect->x;
update_rect->h = (y + 16) - update_rect->y;
}
// Ask Tux Paint to call our 'do_fade_darken()' callback at a single point
void fade_darken_click(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y)
int x, int y, SDL_Rect * update_rect)
{
fade_darken_drag(api, which, canvas, last, x, y, x, y, update_rect);
}
// Release
void fade_darken_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
{
fade_darken_drag(api, which, canvas, last, x, y, x, y);
}

View file

@ -65,21 +65,32 @@ char * fill_get_description(magic_api * api, int which)
// Affect the canvas on drag:
void fill_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y)
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
{
}
// Affect the canvas on click:
void fill_click(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y)
int x, int y, SDL_Rect * update_rect)
{
do_flood_fill(api, canvas, x, y, SDL_MapRGB(canvas->format,
fill_r, fill_g, fill_b),
api->getpixel(canvas, x, y));
update_rect->x = 0;
update_rect->y = 0;
update_rect->w = canvas->w;
update_rect->h = canvas->h;
}
void fill_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
{
}
// No setup happened:
void fill_shutdown(magic_api * api)
{
Mix_FreeChunk(fill_snd);

View file

@ -71,10 +71,19 @@ char * grass_get_description(magic_api * api, int which)
// 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_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
{
api->line(which, canvas, last, ox, oy, x, y, 4, do_grass);
if (ox > x) { int tmp = ox; ox = x; x = tmp; }
if (oy > y) { int tmp = oy; oy = y; y = tmp; }
update_rect->x = ox - 32;
update_rect->y = oy - 32;
update_rect->w = 64;
update_rect->h = 64;
api->playsound(grass_snd,
(x * 255) / canvas->w, (y * 255) / canvas->h);
}
@ -82,9 +91,15 @@ void grass_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void grass_click(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y)
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, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
{
grass_drag(api, which, canvas, last, x, y, x, y);
}
// No setup happened:

View file

@ -85,7 +85,15 @@ char * mirror_flip_get_description(magic_api * api, int which)
// We affect the whole canvas, so only do things on click, not drag:
void mirror_flip_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y)
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
{
// No-op
}
void mirror_flip_release(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
{
// No-op
}
@ -93,7 +101,8 @@ void mirror_flip_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void mirror_flip_click(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y)
int x, int y,
SDL_Rect * update_rect)
{
int xx, yy;
SDL_Rect src, dest;
@ -133,6 +142,11 @@ void mirror_flip_click(magic_api * api, int which,
api->special_notify(SPECIAL_FLIP);
}
update_rect->x = 0;
update_rect->y = 0;
update_rect->w = canvas->w;
update_rect->h = canvas->h;
api->playsound(snd_effects[which], 128, 255);
}

View file

@ -80,13 +80,22 @@ void do_negative(void * ptr, int which,
// 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_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
{
SDL_LockSurface(last);
SDL_LockSurface(canvas);
api->line(which, canvas, last, ox, oy, x, y, 1, do_negative);
if (ox > x) { int tmp = ox; ox = x; x = tmp; }
if (oy > y) { int tmp = oy; oy = y; y = tmp; }
update_rect->x = x - 16;
update_rect->y = y - 16;
update_rect->w = (ox + 16) - update_rect->x;
update_rect->h = (oy + 16) - update_rect->h;
api->playsound(negative_snd, (x * 255) / canvas->w, 255);
SDL_UnlockSurface(canvas);
@ -96,9 +105,16 @@ 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,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y)
int x, int y, SDL_Rect * update_rect)
{
negative_drag(api, which, canvas, last, x, y, x, y, update_rect);
}
void negative_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
{
negative_drag(api, which, canvas, last, x, y, x, y);
}

View file

@ -109,7 +109,8 @@ void rainbow_linecb(void * ptr, int which,
// 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_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
{
rainbow_color = (rainbow_color + 1) % NUM_RAINBOW_COLORS;
rainbow_rgb = SDL_MapRGB(canvas->format,
@ -119,15 +120,31 @@ void rainbow_drag(magic_api * api, int which, SDL_Surface * canvas,
api->line(which, canvas, last, ox, oy, x, y, 1, rainbow_linecb);
if (ox > x) { int tmp = ox; ox = x; x = tmp; }
if (oy > y) { int tmp = oy; oy = y; y = tmp; }
update_rect->x = x - 16;
update_rect->y = y - 16;
update_rect->w = (ox + 16) - update_rect->x;
update_rect->h = (oy + 16) - update_rect->y;
api->playsound(rainbow_snd, (x * 255) / canvas->w, 255);
}
// Affect the canvas on click:
void rainbow_click(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y)
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, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y,
SDL_Rect * update_rect)
{
rainbow_drag(api, which, canvas, last, x, y, x, y);
}
// Clean up

View file

@ -94,19 +94,35 @@ void do_smudge(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
// 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_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
{
api->line(which, canvas, last, ox, oy, x, y, 1, do_smudge);
api->playsound(smudge_snd, (x * 255) / canvas->w, 255);
if (ox > x) { int tmp = ox; ox = x; x = tmp; }
if (oy > y) { int tmp = oy; oy = y; y = tmp; }
update_rect->x = x - 16;
update_rect->y = y - 16;
update_rect->w = (ox + 16) - update_rect->x;
update_rect->h = (oy + 16) - update_rect->y;
}
// Affect the canvas on click:
void smudge_click(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y)
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, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
{
smudge_drag(api, which, canvas, last, x, y, x, y);
}
// No setup happened:

View file

@ -95,19 +95,35 @@ void do_tint(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
// 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_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
{
api->line(which, canvas, last, ox, oy, x, y, 1, do_tint);
if (ox > x) { int tmp = ox; ox = x; x = tmp; }
if (oy > y) { int tmp = oy; oy = y; y = tmp; }
update_rect->x = x - 16;
update_rect->y = y - 16;
update_rect->w = (ox + 16) - update_rect->x;
update_rect->h = (oy + 16) - update_rect->y;
api->playsound(tint_snd, (x * 255) / canvas->w, 255);
}
// Affect the canvas on click:
void tint_click(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y)
int x, int y, SDL_Rect * update_rect)
{
tint_drag(api, which, canvas, last, x, y, x, y, update_rect);
}
void tint_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
{
tint_drag(api, which, canvas, last, x, y, x, y);
}
// No setup happened: