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

@ -6,7 +6,7 @@
bill@newbreedsoftware.com
http://www.tuxpaint.org/
July 5, 2007 - July 6, 2007
July 5, 2007 - July 8, 2007
--------------------------------------------------------------------------
@ -62,7 +62,8 @@ Interfaces
'Magic' tool plugins must provide the functions listed below. Note: To
avoid namespace collisions, each function's name must start with the
shared object's filename (e.g., "blur.so" or "blur.dll" would have
functions whose names begin with "blur_").
functions whose names begin with "blur_"). This includes private
functions, unless you declare those as 'static'.
Common arguments to plugin functions:
@ -127,20 +128,39 @@ Interfaces
The plugin should do any cleanup here. This function is called
once, at Tux Paint exit.
* void click(magic_api * api, int which, SDL_Surface * snapshot,
SDL_Surface * canvas, int x, int y)
SDL_Surface * canvas, int x, int y, SDL_Rect * update_rect)
The plugin should apply the appropriate 'Magic' tool on the
'canvas' surface. The (x,y) coordinates are where the mouse was
(within the canvas) when the mouse button was clicked.
The plugin should report back what part of the canvas was
affected, by filling in the (x,y) and (w,h) values in
'update_rect'.
The contents of the drawing canvas immediately prior to the mouse
button click is stored within the 'snapshot' canvas.
* void drag(magic_api * api, int which, SDL_Surface * snapshot,
SDL_Surface * canvas, int ox, int oy, int x, int y)
SDL_Surface * canvas, int ox, int oy, int x, int y, SDL_Rect *
update_rect)
The plugin should apply the appropriate 'Magic' tool on the
'canvas' surface. The (ox,oy) and (x,y) coordinates are the
location of the mouse at the beginning and end of the stroke.
Typically, plugins that let the user "draw" effects onto the
canvas call the Tux Paint 'Magic' tool plugin "line()" helper
function. (See below).
The plugin should report back what part of the canvas was
affected, by filling in the (x,y) and (w,h) values in
'update_rect'.
Note: The contents of the drawing canvas immediately prior to the
mouse button click remains as it was (when the plugin's "click()"
function was called), and is still available in the 'snapshot'
canvas.
* void release(magic_api * api, int which, SDL_Surface * snapshot,
SDL_Surface * canvas, int x, int y, SDL_Rect * update_rect)
The plugin should apply the appropriate 'Magic' tool on the
'canvas' surface. The (x,y) coordinates are where the mouse was
(within the canvas) when the mouse button was released.
The plugin should report back what part of the canvas was
affected, by filling in the (x,y) and (w,h) values in
'update_rect'.
Note: The contents of the drawing canvas immediately prior to the
mouse button click remains as it was (when the plugin's "click()"
function was called), and is still available in the 'snapshot'

View file

@ -15,7 +15,7 @@ New Breed Software</p>
<p><a href="mailto:bill@newbreedsoftware.com">bill@newbreedsoftware.com</a><br>
<a href="http://www.tuxpaint.org/">http://www.tuxpaint.org/</a></p>
<p>July 5, 2007 - July 6, 2007</p>
<p>July 5, 2007 - July 8, 2007</p>
</center>
<hr size=2 noshade>
@ -84,7 +84,9 @@ of a "Tux&nbsp;Paint 'Magic' Tool Plugin Development package".)</p>
<p>'Magic' tool plugins must provide the functions listed below.
<b>Note:</b> To avoid namespace collisions, each function's name must
start with the shared object's filename (e.g., "blur.so" or "blur.dll"
would have functions whose names begin with "blur_").</p>
would have functions whose names begin with "blur_"). <i>This
includes private functions</i>, unless you declare those as
'static'.</p>
<h4>Common arguments to plugin functions:</h4>
@ -160,20 +162,37 @@ would have functions whose names begin with "blur_").</p>
at Tux&nbsp;Paint exit.
<li>void click(magic_api * api, int which, SDL_Surface * snapshot,
SDL_Surface * canvas, int x, int y)<br>
SDL_Surface * canvas, int x, int y, SDL_Rect * update_rect)<br>
The plugin should apply the appropriate 'Magic' tool on the 'canvas'
surface. The (x,y) coordinates are where the mouse was (within the canvas)
when the mouse button was clicked.<br>
The plugin should report back what part of the canvas was affected, by
filling in the (x,y) and (w,h) values in 'update_rect'.<br>
The contents of the drawing canvas immediately prior to the mouse button
click is stored within the 'snapshot' canvas.
<li>void drag(magic_api * api, int which, SDL_Surface * snapshot,
SDL_Surface * canvas, int ox, int oy, int x, int y)<br>
SDL_Surface * canvas, int ox, int oy, int x, int y,
SDL_Rect * update_rect)<br>
The plugin should apply the appropriate 'Magic' tool on the 'canvas'
surface. The (ox,oy) and (x,y) coordinates are the location of the mouse
at the beginning and end of the stroke. Typically, plugins that let the
user "draw" effects onto the canvas call the Tux&nbsp;Paint 'Magic' tool
plugin "line()" helper function. (See below).<br>
The plugin should report back what part of the canvas was affected, by
filling in the (x,y) and (w,h) values in 'update_rect'.<br>
Note: The contents of the drawing canvas immediately prior to the mouse
button click remains as it was (when the plugin's "click()" function was
called), and is still available in the 'snapshot' canvas.
<li>void release(magic_api * api, int which, SDL_Surface * snapshot,
SDL_Surface * canvas, int x, int y,
SDL_Rect * update_rect)<br>
The plugin should apply the appropriate 'Magic' tool on the 'canvas'
surface. The (x,y) coordinates are where the mouse was (within the canvas)
when the mouse button was released.<br>
The plugin should report back what part of the canvas was affected, by
filling in the (x,y) and (w,h) values in 'update_rect'.<br>
Note: The contents of the drawing canvas immediately prior to the mouse
button click remains as it was (when the plugin's "click()" function was
called), and is still available in the 'snapshot' canvas.

View file

@ -118,10 +118,19 @@ void do_example(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
// Affect the canvas on drag:
void example_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_example);
if (ox > x) { int tmp = ox; ox = x; x = tmp; }
if (oy > y) { int tmp = oy; oy = y; y = tmp; }
update_rect->x = x - 4;
update_rect->y = y - 4;
update_rect->w = (ox + 4) - update_rect->x;
update_rect->h = (oy + 4) - update_rect->h;
api->playsound(snd_effect[which],
(x * 255) / canvas->w, (y * 255) / canvas->h);
}
@ -129,9 +138,16 @@ void example_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void example_click(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y)
int x, int y, SDL_Rect * update_rect)
{
example_drag(api, which, canvas, last, x, y, x, y, SDL_Rect * update_rect);
}
// Affect the canvas on release:
void example_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
{
example_drag(api, which, canvas, last, x, y, x, y);
}
// No setup happened:

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:

View file

@ -860,8 +860,9 @@ typedef struct magic_funcs_s {
int (*init)(magic_api *);
Uint32 (*api_version)(void);
void (*shutdown)(magic_api *);
void (*click)(magic_api *, int, SDL_Surface *, SDL_Surface *, int, int);
void (*drag)(magic_api *, int, SDL_Surface *, SDL_Surface *, int, int, int, int);
void (*click)(magic_api *, int, SDL_Surface *, SDL_Surface *, int, int, SDL_Rect *);
void (*drag)(magic_api *, int, SDL_Surface *, SDL_Surface *, int, int, int, int, SDL_Rect *);
void (*release)(magic_api *, int, SDL_Surface *, SDL_Surface *, int, int, SDL_Rect *);
} magic_funcs_t;
// FIXME: Drop the 512 constant :P
@ -1691,6 +1692,7 @@ static void mainloop(void)
SDLMod mod;
Uint32 last_cursor_blink, cur_cursor_blink,
pre_event_time, current_event_time;
SDL_Rect update_rect;
num_things = num_brushes;
@ -3009,17 +3011,22 @@ static void mainloop(void)
last = undo_bufs[undo_ctr];
// FIXME: Lock surfaces? Probably better to let tool plugins do it
update_rect.x = 0;
update_rect.y = 0;
update_rect.w = 0;
update_rect.h = 0;
magic_funcs[magic_handle_idx[cur_magic]].click(magic_api_struct,
magic_idx[cur_magic],
canvas, last,
old_x, old_y);
old_x, old_y,
&update_rect);
draw_tux_text(TUX_GREAT, magic_tips[cur_magic], 1);
// FIXME: Maybe 'click' should return an update rect?
update_canvas(0, 0, canvas->w, canvas->h);
update_canvas(update_rect.x, update_rect.y,
update_rect.x + update_rect.w,
update_rect.y + update_rect.h);
}
else if (cur_tool == TOOL_ERASER)
{
@ -3338,6 +3345,37 @@ static void mainloop(void)
}
}
}
else if (cur_tool == TOOL_MAGIC)
{
int undo_ctr;
SDL_Surface * last;
/* Releasing button: Finish the magic: */
if (cur_undo > 0)
undo_ctr = cur_undo - 1;
else
undo_ctr = NUM_UNDO_BUFS - 1;
last = undo_bufs[undo_ctr];
update_rect.x = 0;
update_rect.y = 0;
update_rect.w = 0;
update_rect.h = 0;
magic_funcs[magic_handle_idx[cur_magic]].release(magic_api_struct,
magic_idx[cur_magic],
canvas, last,
old_x, old_y,
&update_rect);
draw_tux_text(TUX_GREAT, magic_tips[cur_magic], 1);
update_canvas(update_rect.x, update_rect.y,
update_rect.x + update_rect.w,
update_rect.y + update_rect.h);
}
}
button_down = 0;
@ -3557,14 +3595,21 @@ static void mainloop(void)
last = undo_bufs[undo_ctr];
update_rect.x = 0;
update_rect.y = 0;
update_rect.w = 0;
update_rect.h = 0;
magic_funcs[magic_handle_idx[cur_magic]].drag(magic_api_struct,
magic_idx[cur_magic],
canvas, last,
old_x, old_y,
new_x, new_y);
new_x, new_y,
&update_rect);
// FIXME: Maybe 'drag' should return an update rect?
update_canvas(0, 0, canvas->w, canvas->h);
update_canvas(update_rect.x, update_rect.y,
update_rect.x + update_rect.w,
update_rect.y + update_rect.h);
}
else if (cur_tool == TOOL_ERASER)
{
@ -15891,6 +15936,11 @@ void load_magic_plugins(void)
magic_funcs[num_plugin_files].drag =
SDL_LoadFunction(magic_handle[num_plugin_files], funcname);
snprintf(funcname, sizeof(funcname), "%s_%s", objname,
"release");
magic_funcs[num_plugin_files].release =
SDL_LoadFunction(magic_handle[num_plugin_files], funcname);
#ifdef DEBUG
printf("get_tool_count = 0x%x\n",
(int) magic_funcs[num_plugin_files].get_tool_count);
@ -15914,6 +15964,8 @@ void load_magic_plugins(void)
(int) magic_funcs[num_plugin_files].click);
printf("drag = 0x%x\n",
(int) magic_funcs[num_plugin_files].drag);
printf("release = 0x%x\n",
(int) magic_funcs[num_plugin_files].release);
#endif
err = 0;
@ -15972,6 +16024,12 @@ void load_magic_plugins(void)
fname);
err = 1;
}
if (magic_funcs[num_plugin_files].release == NULL)
{
fprintf(stderr, "Error: plugin %s is missing release\n",
fname);
err = 1;
}
if (magic_funcs[num_plugin_files].drag == NULL)
{
fprintf(stderr, "Error: plugin %s is missing drag\n",