Creating Tux Paint Magic Tool Plugins

Copyright 2007-2007 by Bill Kendrick and others
New Breed Software

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

July 5, 2007 - July 6, 2007


Overview

Beginning with version 0.9.18, Tux Paint's 'Magic' tools were converted from routines that lived within the application itself, to a set of 'plugins' that are loaded when Tux Paint starts up.

This division allows more rapid development of 'Magic' tools, and allows programmers to create and test new tools without needing to integrate them within the main Tux Paint source code. (Users of more professional graphics tools, such as The GIMP, should be familiar with this plugin concept.)


Prerequisites

Tux Paint is written in the C programming language, and uses the Simple DirectMedia Layer library ('libSDL', or simply 'SDL'). Therefore, for the moment at least, one must understand the C language, how to compile C-based programs. Familiarity with the SDL API is highly recommended, but some basic SDL concepts will be covered in this document.


Interfaces

Those who create 'Magic' tool plugins for Tux Paint must provide some interfaces (C functions) that Tux Paint may invoke.

Tux Paint utilizes SDL's "SDL_LoadObject()" and "SDL_LoadFunction()" routines to load plugins (shared objects files; e.g., ".so" files on Linux or ".dll" files on Windows) and find the functions within.

In turn, Tux Paint provides a number of helper functions that the plugin may (or sometimes should) use. This is exposed as a C structure (containing pointers to functions inside Tux Paint and other data) that gets passed along to the plugin's functions as an argument.

Plugins should #include the file "tp_magic_api.h", and compiler flags which should be used when building plugins (to find the aforementioned header file, as well as SDL's header files) can be acquired by invoking the tool "tp-magic-config".

(These are included with Tux Paint — or in some cases, as part of a "Tux Paint 'Magic' Tool Plugin Development package".)

'Magic' tool plugin functions

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

Common arguments to plugin functions:

Required plugin functions:

Tux Paint Functions

Tux Paint provides a number of helper functions that plugins may access via the "magic_api" structure, sent to all of the plugin's functions (see above).


Compiling

Linux and other Unix-like Platforms

Use the C compiler's "-shared" command-line option to generate a shared object file (".so") based on your 'Magic' tool plugin's C source code.

Additionally, use the "tp-magic-config --cflags" command, supplied as part of Tux Paint, to provide additional command-line flags to your C compiler that will help it build your plugin.

As a stand-alone command, using the GNU C Compiler and BASH shell, for example:

gcc -shared `tp-magic-config --cflags` my_plugin.c -o my_plugin.so

A snippet from a more generalized Makefile might look like this:

CFLAGS=-Wall -O2 $(shell tp-magic-config --cflags)

my_plugin.so: my_plugin.c    $(CC) -shared $(CFLAGS) -o $@ $<

Then install globally into: /usr/[local/]lib/tuxpaint/. Or locally into: ~/.tuxpaint/magic/

Windows

TBD

Mac OS X

TBD


Example Code


Summary and contact info TBD.