diff --git a/Makefile b/Makefile
index 675df0571..2f420d74d 100644
--- a/Makefile
+++ b/Makefile
@@ -7,7 +7,7 @@
# bill@newbreedsoftware.com
# http://www.tuxpaint.org/
-# June 14, 2002 - July 4, 2007
+# June 14, 2002 - July 8, 2007
# The version number, for release:
@@ -15,6 +15,8 @@
VER_VERSION=0.9.18
VER_DATE=`date +"%Y-%m-%d"`
+MAGIC_API_VERSION=0x00000002
+
# Where to install things:
@@ -139,6 +141,7 @@ DEFS=-DDATA_PREFIX=\"$(DATA_PREFIX)/\" \
-DCONFDIR=\"$(CONFDIR)/\" \
-DMAGIC_PREFIX=\"$(MAGIC_PREFIX)/\" \
-DVER_VERSION=\"$(VER_VERSION)\" \
+ -DMAGICAPI_VERSION=$(MAGIC_API_VERSION) \
-DVER_DATE=\"$(VER_DATE)\" \
-D$(MAEMOFLAG)
@@ -335,6 +338,7 @@ install-magic-plugin-dev:
@echo "...Installing Magic Tool plug-in development files and docs..."
@-rm $(BIN_PREFIX)/tp-magic-config
@sed src/tp-magic-config.sh -e s/__VERSION__/$(VER_VERSION)/ \
+ -e s/__APIVERSION__/$(MAGIC_API_VERSION)/ \
-e s=__INCLUDE__=$(INCLUDE_PREFIX)/tuxpaint= > \
$(BIN_PREFIX)/tp-magic-config
@chmod a+rx,g-w,o-w $(BIN_PREFIX)/tp-magic-config
@@ -898,7 +902,7 @@ obj/resource.o: visualc/resources.rc obj visualc/resource.h
# Go into 'magic' subdirectory and buld magic plug-ins
magic-plugins:
- @cd magic ; make
+ @cd magic ; make MAGIC_API_VERSION=$(MAGIC_API_VERSION)
# Make the "obj" directory to throw the object(s) into:
# (not necessary any more; bjk 2006.02.20)
diff --git a/Makefile-i18n b/Makefile-i18n
index 70e72e5c6..b957563da 100644
--- a/Makefile-i18n
+++ b/Makefile-i18n
@@ -477,7 +477,7 @@ install-im:
@cp im/ko.im $(IM_PREFIX)/ko.im
@chmod 644 $(IM_PREFIX)/ko.im
@#
- @echo " ko ...Thai..."
+ @echo " th ...Thai..."
@cp im/th.im $(IM_PREFIX)/th.im
@chmod 644 $(IM_PREFIX)/th.im
else
diff --git a/magic/Makefile b/magic/Makefile
index 86ad339c2..714584888 100644
--- a/magic/Makefile
+++ b/magic/Makefile
@@ -10,7 +10,8 @@ SO_TYPE=so
TP_MAGIC_CFLAGS=$(shell sdl-config --cflags) \
-I../src/ \
$(shell tp-magic-config --cflags)
-CFLAGS=-g -Wall $(TP_MAGIC_CFLAGS)
+CFLAGS=-g -Wall $(TP_MAGIC_CFLAGS) -DMAGICAPI_VERSION=$(MAGIC_API_VERSION)
+
all: negative.$(SO_TYPE) \
diff --git a/magic/docs/README.txt b/magic/docs/README.txt
index 6fd4b1677..91212943f 100644
--- a/magic/docs/README.txt
+++ b/magic/docs/README.txt
@@ -113,6 +113,11 @@ Interfaces
palette. (It will be called whenever one of the plguin's Magic
tools that accept colors becomes active, or the user picks a new
color while such a tool is currently active.)
+ * Uint32 api_version(void)
+ The plugin should return an integer value representing the version
+ of the Tux Paint 'Magic' tool plugin API it was built against.
+ Simply return TP_MAGIC_API_VERSION, which is defined in
+ "tp_magic_api.h", to satisfy this requirement.
* int init(magic_api * api)
The plugin should do any initialization here. This function is
called once, at Tux Paint startup. Return '1' if initialization
diff --git a/magic/docs/html/README.html b/magic/docs/html/README.html
index cb69f9a9e..2501514ce 100644
--- a/magic/docs/html/README.html
+++ b/magic/docs/html/README.html
@@ -143,6 +143,12 @@ would have functions whose names begin with "blur_").
Magic tools that accept colors becomes active, or the user picks a new
color while such a tool is currently active.)
+Uint32 api_version(void)
+ The plugin should return an integer value representing the version of
+ the Tux Paint 'Magic' tool plugin API it was built against.
+ Simply return TP_MAGIC_API_VERSION, which is defined in
+ "tp_magic_api.h", to satisfy this requirement.
+
int init(magic_api * api)
The plugin should do any initialization here. This function is called once,
at Tux Paint startup. Return '1' if initialization was successful,
diff --git a/magic/docs/tp_magic_example.c b/magic/docs/tp_magic_example.c
index fdae9933d..f700412c7 100644
--- a/magic/docs/tp_magic_example.c
+++ b/magic/docs/tp_magic_example.c
@@ -20,6 +20,9 @@ Mix_Chunk * snd_effect[NUM_TOOLS];
Uint8 example_r, example_g, example_b;
+Uint32 example_api_version(void) { return(TP_MAGIC_API_VERSION); }
+
+
// No setup required:
int example_init(magic_api * api)
{
diff --git a/magic/src/blocks_chalk_drip.c b/magic/src/blocks_chalk_drip.c
index 00028d866..b9d165a73 100644
--- a/magic/src/blocks_chalk_drip.c
+++ b/magic/src/blocks_chalk_drip.c
@@ -19,7 +19,6 @@ enum {
Mix_Chunk * snd_effect[NUM_TOOLS];
-// No setup required:
int blocks_chalk_drip_init(magic_api * api)
{
char fname[1024];
@@ -39,6 +38,9 @@ int blocks_chalk_drip_init(magic_api * api)
return(1);
}
+Uint32 blocks_chalk_drip_api_version(void) { return(TP_MAGIC_API_VERSION); }
+
+
// We have multiple tools:
int blocks_chalk_drip_get_tool_count(magic_api * api)
{
@@ -100,8 +102,9 @@ char * blocks_chalk_drip_get_description(magic_api * api, int which)
// Do the effect:
-void do_example(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
- int x, int y)
+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;
@@ -210,7 +213,7 @@ void do_example(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
void blocks_chalk_drip_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y)
{
- api->line(which, canvas, last, ox, oy, x, y, 1, do_example);
+ api->line(which, canvas, last, ox, oy, x, y, 1, blocks_chalk_drip_linecb);
api->playsound(snd_effect[which], (x * 255) / canvas->w, 255);
}
diff --git a/magic/src/blur.c b/magic/src/blur.c
index bc17dabea..7a546a792 100644
--- a/magic/src/blur.c
+++ b/magic/src/blur.c
@@ -22,6 +22,8 @@ int blur_init(magic_api * api)
return(1);
}
+Uint32 blur_api_version(void) { return(TP_MAGIC_API_VERSION); }
+
int blur_get_tool_count(magic_api * api)
{
return(1);
diff --git a/magic/src/bricks.c b/magic/src/bricks.c
index 692592d3b..e122435d9 100644
--- a/magic/src/bricks.c
+++ b/magic/src/bricks.c
@@ -38,6 +38,8 @@ int bricks_init(magic_api * api)
return(1);
}
+Uint32 bricks_api_version(void) { return(TP_MAGIC_API_VERSION); }
+
// We have multiple tools:
int bricks_get_tool_count(magic_api * api)
{
diff --git a/magic/src/cartoon.c b/magic/src/cartoon.c
index c36184406..f8dad01ab 100644
--- a/magic/src/cartoon.c
+++ b/magic/src/cartoon.c
@@ -26,6 +26,8 @@ int cartoon_init(magic_api * api)
return(1);
}
+Uint32 cartoon_api_version(void) { return(TP_MAGIC_API_VERSION); }
+
// We have multiple tools:
int cartoon_get_tool_count(magic_api * api)
{
diff --git a/magic/src/drip.c b/magic/src/drip.c
deleted file mode 100644
index 0bd9aa089..000000000
--- a/magic/src/drip.c
+++ /dev/null
@@ -1,156 +0,0 @@
-#include
-#include
-#include
-#include "tp_magic_api.h"
-#include "SDL_image.h"
-#include "SDL_mixer.h"
-
-/* What tools we contain: */
-
-enum {
- TOOL_ONE,
- TOOL_TWO,
- NUM_TOOLS
-};
-
-
-/* Our globals: */
-
-Mix_Chunk * snd_effect[NUM_TOOLS];
-Uint8 example_r, example_g, example_b;
-
-
-// No setup required:
-int example_init(magic_api * api)
-{
- char fname[1024];
-
- snprintf(fname, sizeof(fname), "%s/sounds/magic/one.wav",
- api->data_directory);
- snd_effect[0] = Mix_LoadWAV(fname);
-
- snprintf(fname, sizeof(fname), "%s/sounds/magic/two.wav",
- api->data_directory);
- snd_effect[1] = Mix_LoadWAV(fname);
-
- return(1);
-}
-
-// We have multiple tools:
-int example_get_tool_count(magic_api * api)
-{
- return(NUM_TOOLS);
-}
-
-// Load our icons:
-SDL_Surface * example_get_icon(magic_api * api, int which)
-{
- char fname[1024];
-
- if (which == TOOL_ONE)
- {
- snprintf(fname, sizeof(fname), "%s/images/magic/one.png",
- api->data_directory);
- }
- else if (which == TOOL_TWO)
- {
- snprintf(fname, sizeof(fname), "%s/images/magic/two.png",
- api->data_directory);
- }
-
- return(IMG_Load(fname));
-}
-
-// Return our names, localized:
-char * example_get_name(magic_api * api, int which)
-{
- if (which == TOOL_ONE)
- return(strdup(gettext("One")));
- else if (which == TOOL_TWO)
- return(strdup(gettext("Two")));
-
- return(NULL);
-}
-
-// Return our descriptions, localized:
-char * example_get_description(magic_api * api, int which)
-{
- if (which == TOOL_ONE)
- return(strdup(gettext("Tool one.")));
- else
- return(strdup(gettext("Tool two.")));
-
- return(NULL);
-}
-
-// Do the effect:
-
-void do_example(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
- int x, int y)
-{
- magic_api * api = (magic_api *) ptr;
- int xx, yy;
-
- if (which == TOOL_ONE)
- {
- api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format,
- example_r,
- example_g,
- example_b));
- }
- else if (which == TOOL_TWO)
- {
- for (yy = -4; yy < 4; yy++)
- {
- for (xx = -4; xx < 4; xx++)
- {
- api->putpixel(canvas, x + xx, y + yy,
- api->getpixel(last,
- canvas->w - x - xx,
- canvas->h - y - yy));
- }
- }
- }
-}
-
-// 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)
-{
- api->line(which, canvas, last, ox, oy, x, y, 1, do_example);
-
- api->playsound(snd_effect[which], (x * 255) / canvas->w, 255);
-}
-
-// Affect the canvas on click:
-void example_click(magic_api * api, int which,
- SDL_Surface * canvas, SDL_Surface * last,
- int x, int y)
-{
- example_drag(api, which, canvas, last, x, y, x, y);
-}
-
-// No setup happened:
-void example_shutdown(magic_api * api)
-{
- if (snd_effect[0] != NULL)
- Mix_FreeChunk(snd_effect[0]);
-
- if (snd_effect[1] != NULL)
- Mix_FreeChunk(snd_effect[1]);
-}
-
-// Record the color from Tux Paint:
-void example_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b)
-{
- example_r = r;
- example_g = g;
- example_b = b;
-}
-
-// Use colors:
-int example_requires_colors(magic_api * api, int which)
-{
- return 1;
-}
-
diff --git a/magic/src/fade_darken.c b/magic/src/fade_darken.c
index 95ea5b74d..fcfe645b7 100644
--- a/magic/src/fade_darken.c
+++ b/magic/src/fade_darken.c
@@ -29,6 +29,8 @@ int fade_darken_init(magic_api * api)
return(1);
}
+Uint32 fade_darken_api_version(void) { return(TP_MAGIC_API_VERSION); }
+
// Multiple tools:
int fade_darken_get_tool_count(magic_api * api)
{
diff --git a/magic/src/fill.c b/magic/src/fill.c
index 04c19adf3..a714c217c 100644
--- a/magic/src/fill.c
+++ b/magic/src/fill.c
@@ -30,6 +30,8 @@ int fill_init(magic_api * api)
return(1);
}
+Uint32 fill_api_version(void) { return(TP_MAGIC_API_VERSION); }
+
// We have multiple tools:
int fill_get_tool_count(magic_api * api)
{
diff --git a/magic/src/grass.c b/magic/src/grass.c
index f8cd4311e..cec6c5a22 100644
--- a/magic/src/grass.c
+++ b/magic/src/grass.c
@@ -37,6 +37,8 @@ int grass_init(magic_api * api)
return(1);
}
+Uint32 grass_api_version(void) { return(TP_MAGIC_API_VERSION); }
+
// We have multiple tools:
int grass_get_tool_count(magic_api * api)
{
diff --git a/magic/src/mirror_flip.c b/magic/src/mirror_flip.c
index ddeb38479..5c5a833d7 100644
--- a/magic/src/mirror_flip.c
+++ b/magic/src/mirror_flip.c
@@ -32,6 +32,8 @@ int mirror_flip_init(magic_api * api)
return(1);
}
+Uint32 mirror_flip_api_version(void) { return(TP_MAGIC_API_VERSION); }
+
// We have multiple tools:
int mirror_flip_get_tool_count(magic_api * api)
{
diff --git a/magic/src/negative.c b/magic/src/negative.c
index a2c2b6c28..0b0493ff8 100644
--- a/magic/src/negative.c
+++ b/magic/src/negative.c
@@ -20,6 +20,8 @@ int negative_init(magic_api * api)
return(1);
}
+Uint32 negative_api_version(void) { return(TP_MAGIC_API_VERSION); }
+
// Only one tool:
int negative_get_tool_count(magic_api * api)
{
diff --git a/magic/src/rainbow.c b/magic/src/rainbow.c
index d31ef51ce..8e34e4026 100644
--- a/magic/src/rainbow.c
+++ b/magic/src/rainbow.c
@@ -54,6 +54,8 @@ int rainbow_init(magic_api * api)
return(1);
}
+Uint32 rainbow_api_version(void) { return(TP_MAGIC_API_VERSION); }
+
// We have multiple tools:
int rainbow_get_tool_count(magic_api * api)
{
diff --git a/magic/src/smudge.c b/magic/src/smudge.c
index afefe67dc..41456e2f7 100644
--- a/magic/src/smudge.c
+++ b/magic/src/smudge.c
@@ -23,6 +23,8 @@ int smudge_init(magic_api * api)
return(1);
}
+Uint32 smudge_api_version(void) { return(TP_MAGIC_API_VERSION); }
+
// We have multiple tools:
int smudge_get_tool_count(magic_api * api)
{
diff --git a/magic/src/tint.c b/magic/src/tint.c
index 5df1c68f7..510300f76 100644
--- a/magic/src/tint.c
+++ b/magic/src/tint.c
@@ -24,6 +24,8 @@ int tint_init(magic_api * api)
return(1);
}
+Uint32 tint_api_version(void) { return(TP_MAGIC_API_VERSION); }
+
// We have multiple tools:
int tint_get_tool_count(magic_api * api)
{
diff --git a/src/tp-magic-config.sh b/src/tp-magic-config.sh
index c11efc179..8d8d554f0 100755
--- a/src/tp-magic-config.sh
+++ b/src/tp-magic-config.sh
@@ -29,7 +29,7 @@
# in Tux Paint's Makefile, via 'sed', by the 'make install-magic-plugin-dev'
# target.
-# July 5, 2007 - July 5, 2007
+# July 5, 2007 - July 8, 2007
if [ $# -ne 0 ]; then
@@ -37,15 +37,15 @@ if [ $# -ne 0 ]; then
echo "__VERSION__"
exit
fi
+ if [ $1 = "--apiversion" ]; then
+ echo "__APIVERSION__"
+ exit
+ fi
if [ $1 = "--cflags" ]; then
echo `sdl-config --cflags` -I__INCLUDE__
exit
fi
- if [ $1 = "--libs" ]; then
- echo `sdl-config --libs`
- exit
- fi
fi
-echo "Usage: tp-magic-config [--version] [--cflags] [--libs]"
+echo "Usage: tp-magic-config [--apiversion] [--version] [--cflags]"
diff --git a/src/tp_magic_api.h b/src/tp_magic_api.h
index 53cea18ae..29813d2a4 100644
--- a/src/tp_magic_api.h
+++ b/src/tp_magic_api.h
@@ -44,5 +44,7 @@ typedef struct magic_api_t {
void (*hsvtorgb)(float, float, float, Uint8 *, Uint8 *, Uint8 *);
} magic_api;
+#define TP_MAGIC_API_VERSION MAGICAPI_VERSION
+
#endif
diff --git a/src/tuxpaint.c b/src/tuxpaint.c
index 2d039c729..b3339bb6c 100644
--- a/src/tuxpaint.c
+++ b/src/tuxpaint.c
@@ -22,7 +22,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
- June 14, 2002 - July 5, 2007
+ June 14, 2002 - July 8, 2007
$Id$
*/
@@ -858,6 +858,7 @@ typedef struct magic_funcs_s {
int (*requires_colors)(magic_api *, int);
void (*set_color)(magic_api *, Uint8, Uint8, Uint8);
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);
@@ -8974,6 +8975,9 @@ static void reset_avail_tools(void)
if (num_stamps[0] == 0)
tool_avail[TOOL_STAMP] = 0;
+ if (num_magics == 0)
+ tool_avail[TOOL_MAGIC] = 0;
+
/* Disable quit? */
@@ -15867,6 +15871,11 @@ void load_magic_plugins(void)
magic_funcs[num_plugin_files].init =
SDL_LoadFunction(magic_handle[num_plugin_files], funcname);
+ snprintf(funcname, sizeof(funcname), "%s_%s", objname,
+ "api_version");
+ magic_funcs[num_plugin_files].api_version =
+ SDL_LoadFunction(magic_handle[num_plugin_files], funcname);
+
snprintf(funcname, sizeof(funcname), "%s_%s", objname,
"shutdown");
magic_funcs[num_plugin_files].shutdown =
@@ -15897,6 +15906,8 @@ void load_magic_plugins(void)
(int) magic_funcs[num_plugin_files].set_color);
printf("init = 0x%x\n",
(int) magic_funcs[num_plugin_files].init);
+ printf("api_version = 0x%x\n",
+ (int) magic_funcs[num_plugin_files].api_version);
printf("shutdown = 0x%x\n",
(int) magic_funcs[num_plugin_files].shutdown);
printf("click = 0x%x\n",
@@ -15967,7 +15978,19 @@ void load_magic_plugins(void)
fname);
err = 1;
}
-
+
+ if (magic_funcs[num_plugin_files].api_version == NULL)
+ {
+ fprintf(stderr, "Error: plugin %s is missing api_version\n",
+ fname);
+ err = 1;
+ }
+ else if (magic_funcs[num_plugin_files].api_version() != TP_MAGIC_API_VERSION)
+ {
+ fprintf(stderr, "Warning: plugin %s uses Tux Paint 'Magic' tool API version %x,\nbut Tux Paint needs version %x.\n", fname, magic_funcs[num_plugin_files].api_version(), TP_MAGIC_API_VERSION);
+ err = 1;
+ }
+
if (err)
{
SDL_UnloadObject(magic_handle[num_plugin_files]);