From c44cf540335e6e6cc046506ce145d8647b171b71 Mon Sep 17 00:00:00 2001 From: William Kendrick Date: Sun, 8 Jul 2007 23:17:18 +0000 Subject: [PATCH] Added dirty rect to magic api. Added 'release' event to magic api. --- magic/docs/README.txt | 28 +++++++++++-- magic/docs/html/README.html | 27 +++++++++++-- magic/docs/tp_magic_example.c | 22 ++++++++-- magic/src/blocks_chalk_drip.c | 22 ++++++++-- magic/src/blur.c | 22 ++++++++-- magic/src/bricks.c | 21 ++++++++-- magic/src/cartoon.c | 22 ++++++++-- magic/src/fade_darken.c | 25 ++++++++++-- magic/src/fill.c | 17 ++++++-- magic/src/grass.c | 21 ++++++++-- magic/src/mirror_flip.c | 18 ++++++++- magic/src/negative.c | 22 ++++++++-- magic/src/rainbow.c | 23 +++++++++-- magic/src/smudge.c | 22 ++++++++-- magic/src/tint.c | 22 ++++++++-- src/tuxpaint.c | 76 ++++++++++++++++++++++++++++++----- 16 files changed, 354 insertions(+), 56 deletions(-) diff --git a/magic/docs/README.txt b/magic/docs/README.txt index 91212943f..63c1b18c0 100644 --- a/magic/docs/README.txt +++ b/magic/docs/README.txt @@ -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' diff --git a/magic/docs/html/README.html b/magic/docs/html/README.html index 2501514ce..674929261 100644 --- a/magic/docs/html/README.html +++ b/magic/docs/html/README.html @@ -15,7 +15,7 @@ New Breed Software

bill@newbreedsoftware.com
http://www.tuxpaint.org/

-

July 5, 2007 - July 6, 2007

+

July 5, 2007 - July 8, 2007


@@ -84,7 +84,9 @@ of a "Tux Paint 'Magic' Tool Plugin Development package".)

'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_").

+would have functions whose names begin with "blur_"). This +includes private functions, unless you declare those as +'static'.

Common arguments to plugin functions:

@@ -160,20 +162,37 @@ would have functions whose names begin with "blur_").

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' canvas. diff --git a/magic/docs/tp_magic_example.c b/magic/docs/tp_magic_example.c index f700412c7..064358150 100644 --- a/magic/docs/tp_magic_example.c +++ b/magic/docs/tp_magic_example.c @@ -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: diff --git a/magic/src/blocks_chalk_drip.c b/magic/src/blocks_chalk_drip.c index b9d165a73..02b36e8fb 100644 --- a/magic/src/blocks_chalk_drip.c +++ b/magic/src/blocks_chalk_drip.c @@ -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: diff --git a/magic/src/blur.c b/magic/src/blur.c index 7a546a792..16e9a383c 100644 --- a/magic/src/blur.c +++ b/magic/src/blur.c @@ -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) diff --git a/magic/src/bricks.c b/magic/src/bricks.c index e122435d9..983010d35 100644 --- a/magic/src/bricks.c +++ b/magic/src/bricks.c @@ -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: diff --git a/magic/src/cartoon.c b/magic/src/cartoon.c index f8dad01ab..6d0bcced3 100644 --- a/magic/src/cartoon.c +++ b/magic/src/cartoon.c @@ -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: diff --git a/magic/src/fade_darken.c b/magic/src/fade_darken.c index fcfe645b7..f3bde7f82 100644 --- a/magic/src/fade_darken.c +++ b/magic/src/fade_darken.c @@ -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); } diff --git a/magic/src/fill.c b/magic/src/fill.c index a714c217c..13cc7e89b 100644 --- a/magic/src/fill.c +++ b/magic/src/fill.c @@ -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); diff --git a/magic/src/grass.c b/magic/src/grass.c index cec6c5a22..ce7206145 100644 --- a/magic/src/grass.c +++ b/magic/src/grass.c @@ -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: diff --git a/magic/src/mirror_flip.c b/magic/src/mirror_flip.c index 5c5a833d7..4746cd6c0 100644 --- a/magic/src/mirror_flip.c +++ b/magic/src/mirror_flip.c @@ -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); } diff --git a/magic/src/negative.c b/magic/src/negative.c index 0b0493ff8..5c6551445 100644 --- a/magic/src/negative.c +++ b/magic/src/negative.c @@ -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); } diff --git a/magic/src/rainbow.c b/magic/src/rainbow.c index 10071f656..39d0d6c34 100644 --- a/magic/src/rainbow.c +++ b/magic/src/rainbow.c @@ -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 diff --git a/magic/src/smudge.c b/magic/src/smudge.c index 41456e2f7..bb568ae3e 100644 --- a/magic/src/smudge.c +++ b/magic/src/smudge.c @@ -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: diff --git a/magic/src/tint.c b/magic/src/tint.c index 510300f76..ca55f20ff 100644 --- a/magic/src/tint.c +++ b/magic/src/tint.c @@ -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: diff --git a/src/tuxpaint.c b/src/tuxpaint.c index b3339bb6c..fce2936d9 100644 --- a/src/tuxpaint.c +++ b/src/tuxpaint.c @@ -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",