switchin() and switchout() now accept mode.

This commit is contained in:
William Kendrick 2008-07-10 20:26:38 +00:00
parent 0b7b36c734
commit f556b503b9
34 changed files with 103 additions and 82 deletions

View file

@ -33,7 +33,8 @@ $Id$
* Magic Tool Improvememnts:
--------------------------
* Added "_switchin()" and "_switchout()" functions to Magic tool API,
to tell Magic tools when they are selected or deselected.
to tell Magic tools when they are selected or deselected, or when
their mode changes..
* Added "_modes()" function to Magic tool API, so Magic tool plugins
can tell Tux Paint what modes it accepts, 'paint' or 'fullscreen'.

View file

@ -6,7 +6,7 @@
bill@newbreedsoftware.com
http://www.tuxpaint.org/
July 5, 2007 - July 8, 2008
July 5, 2007 - July 10, 2008
----------------------------------------------------------------------
@ -271,9 +271,9 @@ Interfaces
Plugin event functions:
* void switchin(magic_api * api, int which,
* void switchin(magic_api * api, int which, int mode,
SDL_Surface * snapshot, SDL_Surface * canvas)
void switchout(magic_api * api, int which,
void switchout(magic_api * api, int which, int mode,
SDL_Surface * snapshot, SDL_Surface * canvas)
switchin() is called whenever one of the plugin's Magic tools
becomes active, and switchout() is called whenever one becomes
@ -290,6 +290,11 @@ Interfaces
tool is first 'switched-out', and then 'switched-back-in',
usually moments later.
Finally, it can also happen when the user changes the 'mode' of
a tool (i.e., from paint mode to full-image mode). First
switchout() is called for the old mode, then switchin() is
called for the new mode.
These functions allow users to interact in complicated was with
Magic tools (for example, a tool that lets the user draw
multiple freehand strokes, and then uses that as input such as

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 8, 2008</p>
<p>July 5, 2007 - July 10, 2008</p>
</center>
<hr size=2 noshade>
@ -352,11 +352,11 @@ then the names of your functions must begin with "<code><b>zoom_</b></code>"
<ul>
<li><code><b>void switchin(magic_api&nbsp;*&nbsp;api,
int&nbsp;which,
int&nbsp;which, int&nbsp;mode,
SDL_Surface&nbsp;*&nbsp;snapshot, SDL_Surface&nbsp;*&nbsp;canvas)
</b></code><br>
<code><b>void switchout(magic_api&nbsp;*&nbsp;api,
int&nbsp;which,
int&nbsp;which, int&nbsp;mode,
SDL_Surface&nbsp;*&nbsp;snapshot, SDL_Surface&nbsp;*&nbsp;canvas)
</b></code><br>
<code>switchin()</code> is called whenever one of the plugin's Magic
@ -374,6 +374,11 @@ then the names of your functions must begin with "<code><b>zoom_</b></code>"
Magic tool is first 'switched-out', and then 'switched-back-in', usually
moments later.<br>
<br>
Finally, it can also happen when the user changes the 'mode' of a tool
(i.e., from paint mode to full-image mode). First
<code>switchout()</code> is called for the old mode, then
<code>switchin()</code> is called for the new mode.<br>
<br>
These functions allow users to interact in complicated was with Magic
tools (for example, a tool that lets the user draw <i>multiple</i>
freehand strokes, and then uses that as input such as handwriting &mdash;

View file

@ -1,7 +1,7 @@
/* tp_magic_example.c
An example of a "Magic" tool plugin for Tux Paint
Last modified: 2008.07.09
Last modified: 2008.07.10
*/
@ -489,13 +489,18 @@ void example_line_callback(void * ptr, int which,
// This happens whenever a Magic tool is enabled, either because the
// user just selected it, or they just came back to "Magic" after using
// another tool (e.g., Brush or Text), and this was the most-recently
// selected Magic tool. (This also applies to momentary tools, like
// selected Magic tool.
//
// (This also applies to momentary tools, like
// Undo and Redo, and image-changing tools such as New and Open.)
//
// It also happens when a Magic tool's mode changes (it first
// receives a 'switchout()', below, for the old mode).
//
// 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, SDL_Surface * canvas)
void example_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}
@ -504,14 +509,17 @@ void example_switchin(magic_api * api, int which, SDL_Surface * canvas)
// This happens whenever a Magic tool is disabled, either because the
// user selected a different Magic tool, or they selected a completely
// different tool (e.g., Brush or Text).
//
// (This also applies to momentary tools, like Undo and Redo, and
// image-changing tools such as New and Open, in which case the
// switchin() function will be called moments later.)
//
// It also happens when a Magic tool's mode changes (it then
// receives a 'switchin()', above, for the new mode).
//
// 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, SDL_Surface * canvas)
void example_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}

View file

@ -205,11 +205,11 @@ int blackAndWhite_requires_colors(magic_api * api, int which)
return 0;
}
void blackAndWhite_switchin(magic_api * api, int which, SDL_Surface * canvas)
void blackAndWhite_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}
void blackAndWhite_switchout(magic_api * api, int which, SDL_Surface * canvas)
void blackAndWhite_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}

View file

@ -321,11 +321,11 @@ int blocks_chalk_drip_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int whic
return 0;
}
void blocks_chalk_drip_switchin(magic_api * api, int which, 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, SDL_Surface * canvas)
void blocks_chalk_drip_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}

View file

@ -222,11 +222,11 @@ int blur_requires_colors(magic_api * api, int which)
return 0;
}
void blur_switchin(magic_api * api, int which, SDL_Surface * canvas)
void blur_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}
void blur_switchout(magic_api * api, int which, SDL_Surface * canvas)
void blur_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}

View file

@ -188,11 +188,11 @@ int blurAll_requires_colors(magic_api * api, int which)
return 0;
}
void blurAll_switchin(magic_api * api, int which, SDL_Surface * canvas)
void blurAll_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}
void blurAll_switchout(magic_api * api, int which, SDL_Surface * canvas)
void blurAll_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}

View file

@ -294,11 +294,11 @@ static void do_brick(magic_api * api, SDL_Surface * canvas,
api->playsound(brick_snd, (x * 255) / canvas->w, 255);
}
void bricks_switchin(magic_api * api, int which, SDL_Surface * canvas)
void bricks_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}
void bricks_switchout(magic_api * api, int which, SDL_Surface * canvas)
void bricks_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}

View file

@ -420,11 +420,11 @@ static float calligraphy_dist(float x1, float y1, float x2, float y2)
return d;
}
void calligraphy_switchin(magic_api * api, int which, SDL_Surface * canvas)
void calligraphy_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}
void calligraphy_switchout(magic_api * api, int which, SDL_Surface * canvas)
void calligraphy_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}

View file

@ -223,11 +223,11 @@ int cartoon_requires_colors(magic_api * api, int which)
return 0;
}
void cartoon_switchin(magic_api * api, int which, SDL_Surface * canvas)
void cartoon_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}
void cartoon_switchout(magic_api * api, int which, SDL_Surface * canvas)
void cartoon_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}

View file

@ -172,14 +172,12 @@ 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, int which, SDL_Surface * canvas)
void confetti_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}
void confetti_switchout(magic_api * api, int which, SDL_Surface * canvas)
void confetti_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}
int confetti_modes(magic_api * api, int which)

View file

@ -226,11 +226,11 @@ static void distortion_line_callback(void * ptr, int which,
}
}
void distortion_switchin(magic_api * api, int which, SDL_Surface * canvas)
void distortion_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}
void distortion_switchout(magic_api * api, int which, SDL_Surface * canvas)
void distortion_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}

View file

@ -179,11 +179,11 @@ int emboss_requires_colors(magic_api * api, int which)
return 0;
}
void emboss_switchin(magic_api * api, int which, SDL_Surface * canvas)
void emboss_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}
void emboss_switchout(magic_api * api, int which, SDL_Surface * canvas)
void emboss_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}

View file

@ -268,11 +268,11 @@ int fade_darken_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTR
return 0;
}
void fade_darken_switchin(magic_api * api, int which, 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, SDL_Surface * canvas)
void fade_darken_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}

View file

@ -246,11 +246,11 @@ static void do_flood_fill(magic_api * api, SDL_Surface * canvas, int x, int y,
}
}
void fill_switchin(magic_api * api, int which, SDL_Surface * canvas)
void fill_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}
void fill_switchout(magic_api * api, int which, SDL_Surface * canvas)
void fill_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}

View file

@ -594,11 +594,11 @@ static void flower_colorize_petals(magic_api * api)
SDL_UnlockSurface(flower_petals);
}
void flower_switchin(magic_api * api, int which, SDL_Surface * canvas)
void flower_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}
void flower_switchout(magic_api * api, int which, SDL_Surface * canvas)
void flower_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}

View file

@ -417,11 +417,11 @@ int foam_requires_colors(magic_api * api, int which)
return 0; /* FIXME: Would be nice to tint the bubbles */
}
void foam_switchin(magic_api * api, int which, SDL_Surface * canvas)
void foam_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}
void foam_switchout(magic_api * api, int which, SDL_Surface * canvas)
void foam_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}

View file

@ -252,14 +252,12 @@ void fold_drag(magic_api * api, int which, SDL_Surface * canvas,
}
void fold_switchin(magic_api * api, int which, SDL_Surface * canvas)
void fold_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}
void fold_switchout(magic_api * api, int which, SDL_Surface * canvas)
void fold_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}
int fold_modes(magic_api * api, int which)

View file

@ -296,11 +296,11 @@ int glasstile_requires_colors(magic_api * api, int which)
return 0;
}
void glasstile_switchin(magic_api * api, int which, SDL_Surface * canvas)
void glasstile_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}
void glasstile_switchout(magic_api * api, int which, SDL_Surface * canvas)
void glasstile_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}

View file

@ -244,11 +244,11 @@ static int log2int(int x)
return y;
}
void grass_switchin(magic_api * api, int which, SDL_Surface * canvas)
void grass_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}
void grass_switchout(magic_api * api, int which, SDL_Surface * canvas)
void grass_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}

View file

@ -164,11 +164,11 @@ int kalidescope_requires_colors(magic_api * api, int which)
return 1;
}
void kalidescope_switchin(magic_api * api, int which, SDL_Surface * canvas)
void kalidescope_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}
void kalidescope_switchout(magic_api * api, int which, SDL_Surface * canvas)
void kalidescope_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}

View file

@ -207,11 +207,11 @@ int light_requires_colors(magic_api * api, int which)
return 1;
}
void light_switchin(magic_api * api, int which, SDL_Surface * canvas)
void light_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}
void light_switchout(magic_api * api, int which, SDL_Surface * canvas)
void light_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}

View file

@ -173,11 +173,11 @@ int metalpaint_requires_colors(magic_api * api, int which)
return 1;
}
void metalpaint_switchin(magic_api * api, int which, SDL_Surface * canvas)
void metalpaint_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}
void metalpaint_switchout(magic_api * api, int which, SDL_Surface * canvas)
void metalpaint_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}

View file

@ -198,11 +198,11 @@ int mirror_flip_requires_colors(magic_api * api, int which)
return 0;
}
void mirror_flip_switchin(magic_api * api, int which, SDL_Surface * canvas)
void mirror_flip_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}
void mirror_flip_switchout(magic_api * api, int which, SDL_Surface * canvas)
void mirror_flip_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}

View file

@ -195,11 +195,11 @@ int negative_requires_colors(magic_api * api, int which)
return 0;
}
void negative_switchin(magic_api * api, int which, SDL_Surface * canvas)
void negative_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}
void negative_switchout(magic_api * api, int which, SDL_Surface * canvas)
void negative_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}

View file

@ -193,11 +193,11 @@ int rainbow_requires_colors(magic_api * api, int which)
return 0;
}
void rainbow_switchin(magic_api * api, int which, SDL_Surface * canvas)
void rainbow_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}
void rainbow_switchout(magic_api * api, int which, SDL_Surface * canvas)
void rainbow_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}

View file

@ -177,11 +177,11 @@ int ripples_requires_colors(magic_api * api, int which)
return 0;
}
void ripples_switchin(magic_api * api, int which, SDL_Surface * canvas)
void ripples_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}
void ripples_switchout(magic_api * api, int which, SDL_Surface * canvas)
void ripples_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}

View file

@ -268,11 +268,11 @@ int sharpen_requires_colors(magic_api * api, int which)
return 0;
}
void sharpen_switchin(magic_api * api, int which, SDL_Surface * canvas)
void sharpen_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}
void sharpen_switchout(magic_api * api, int which, SDL_Surface * canvas)
void sharpen_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}

View file

@ -323,11 +323,11 @@ int shift_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_
return 0;
}
void shift_switchin(magic_api * api, int which, SDL_Surface * canvas)
void shift_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}
void shift_switchout(magic_api * api, int which, SDL_Surface * canvas)
void shift_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}

View file

@ -172,11 +172,11 @@ int smudge_requires_colors(magic_api * api, int which)
return 0;
}
void smudge_switchin(magic_api * api, int which, SDL_Surface * canvas)
void smudge_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}
void smudge_switchout(magic_api * api, int which, SDL_Surface * canvas)
void smudge_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}

View file

@ -204,11 +204,11 @@ int tint_requires_colors(magic_api * api, int which)
return 1;
}
void tint_switchin(magic_api * api, int which, SDL_Surface * canvas)
void tint_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}
void tint_switchout(magic_api * api, int which, SDL_Surface * canvas)
void tint_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}

View file

@ -154,11 +154,11 @@ int waves_requires_colors(magic_api * api, int which)
return 0;
}
void waves_switchin(magic_api * api, int which, SDL_Surface * canvas)
void waves_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}
void waves_switchout(magic_api * api, int which, SDL_Surface * canvas)
void waves_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}

View file

@ -22,7 +22,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
June 14, 2002 - July 8, 2008
June 14, 2002 - July 10, 2008
$Id$
*/
@ -905,8 +905,8 @@ typedef struct magic_funcs_s {
void (*click)(magic_api *, int, 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 *);
void (*switchin)(magic_api *, int, SDL_Surface *, SDL_Surface *);
void (*switchout)(magic_api *, int, SDL_Surface *, SDL_Surface *);
void (*switchin)(magic_api *, int, int, SDL_Surface *, SDL_Surface *);
void (*switchout)(magic_api *, int, int, SDL_Surface *, SDL_Surface *);
} magic_funcs_t;
@ -2905,13 +2905,17 @@ static void mainloop(void)
/* Magic controls! */
if (which == 1 && magics[cur_magic].avail_modes & MODE_FULLSCREEN)
{
magics[cur_magic].mode = MODE_FULLSCREEN;
magic_switchout(canvas);
magics[cur_magic].mode = MODE_FULLSCREEN;
magic_switchin(canvas);
draw_magic();
update_screen_rect(&r_toolopt);
}
else if (which == 0 && magics[cur_magic].avail_modes & MODE_PAINT)
{
magic_switchout(canvas);
magics[cur_magic].mode = MODE_PAINT;
magic_switchin(canvas);
draw_magic();
update_screen_rect(&r_toolopt);
}
@ -3171,10 +3175,10 @@ static void mainloop(void)
}
else if (cur_tool == TOOL_MAGIC)
{
magic_switchout(canvas);
if (cur_thing != cur_magic)
{
magic_switchout(canvas);
cur_magic = cur_thing;
draw_colors(magics[cur_magic].colors);
@ -3184,14 +3188,14 @@ static void mainloop(void)
color_hexes[cur_color][0],
color_hexes[cur_color][1],
color_hexes[cur_color][2]);
magic_switchin(canvas);
}
draw_tux_text(TUX_GREAT, magics[cur_magic].tip[magic_modeint(magics[cur_magic].mode)], 1);
if (do_draw)
draw_magic();
magic_switchin(canvas);
}
/* Update the screen: */
@ -18965,6 +18969,7 @@ void magic_switchout(SDL_Surface * last)
if (cur_tool == TOOL_MAGIC)
magic_funcs[magics[cur_magic].handle_idx].switchout(magic_api_struct,
magics[cur_magic].idx,
magics[cur_magic].mode,
canvas, last);
}
@ -18973,6 +18978,7 @@ void magic_switchin(SDL_Surface * last)
if (cur_tool == TOOL_MAGIC)
magic_funcs[magics[cur_magic].handle_idx].switchin(magic_api_struct,
magics[cur_magic].idx,
magics[cur_magic].mode,
canvas, last);
}