Magic tools (and tp-magic-config) supports local (user) plugins.

Added copyright & credit info to new Magic tool plugin .c files.
Updated Magic plugin doc API.
This commit is contained in:
William Kendrick 2007-08-08 06:56:04 +00:00
parent cf10090cc1
commit 0d6c2cf1b9
30 changed files with 1146 additions and 350 deletions

View file

@ -7,7 +7,7 @@
# bill@newbreedsoftware.com # bill@newbreedsoftware.com
# http://www.tuxpaint.org/ # http://www.tuxpaint.org/
# June 14, 2002 - August 2, 2007 # June 14, 2002 - August 7, 2007
# The version number, for release: # The version number, for release:
@ -345,8 +345,9 @@ install-magic-plugins:
@cp magic/icons/*.png $(DATA_PREFIX)/images/magic @cp magic/icons/*.png $(DATA_PREFIX)/images/magic
@chmod a+r,g-w,o-w $(DATA_PREFIX)/images/magic/*.png @chmod a+r,g-w,o-w $(DATA_PREFIX)/images/magic/*.png
@install -d $(DATA_PREFIX)/sounds/magic @install -d $(DATA_PREFIX)/sounds/magic
@cp magic/sounds/*.wav $(DATA_PREFIX)/sounds/magic @cp magic/sounds/*.wav magic/sounds/*.ogg $(DATA_PREFIX)/sounds/magic
@chmod a+r,g-w,o-w $(DATA_PREFIX)/sounds/magic/*.wav @chmod a+r,g-w,o-w $(DATA_PREFIX)/sounds/magic/*.wav \
$(DATA_PREFIX)/sounds/magic/*.ogg
install-magic-plugin-dev: src/tp_magic_api.h install-magic-plugin-dev: src/tp_magic_api.h
@echo @echo

View file

@ -119,6 +119,13 @@ $Id$
* Flower * Flower
(utilizes Bezier curve example code from Wikipedia.org) (utilizes Bezier curve example code from Wikipedia.org)
(Glass Tile, Emboss, Flower and Ripples sounds based on sounds
from KDE 3.5.7; http://www.kde.org/ )
(Metal Paint sound based on sound from Engima;
http://www.nongnu.org/enigma/ )
(Waves sound based on sound from Super Tux;
http://supertux.berlios.de/ )
* New Localizations: * New Localizations:
------------------ ------------------
* Esperanto translation * Esperanto translation

View file

@ -6,7 +6,7 @@
bill@newbreedsoftware.com bill@newbreedsoftware.com
http://www.tuxpaint.org/ http://www.tuxpaint.org/
July 5, 2007 - August 2, 2007 July 5, 2007 - August 7, 2007
-------------------------------------------------------------------------- --------------------------------------------------------------------------
@ -356,7 +356,7 @@ Interfaces
'0' otherwise. Useful to create 'Magic' tools that affect the '0' otherwise. Useful to create 'Magic' tools that affect the
canvas with a circular brush shape. canvas with a circular brush shape.
* void line(int which, SDL_Surface * canvas, * void line(void * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int x1, int y1, int x2, int y2, SDL_Surface * snapshot, int x1, int y1, int x2, int y2,
int step, FUNC callback) int step, FUNC callback)
This function calculates all points on a line between the This function calculates all points on a line between the
@ -364,9 +364,10 @@ Interfaces
calls the 'callback' function. calls the 'callback' function.
It sends the 'callback' function the (x,y) coordinates on the It sends the 'callback' function the (x,y) coordinates on the
line, Tux Paint's "magic_api" struct (as a "void *" pointer), a line, Tux Paint's "magic_api" struct (as a "void *" pointer
'which' value, represening which of the plugin's 'Magic' tool is which you need to send to it), a 'which' value, represening
being used, and the current and snapshot canvases. which of the plugin's 'Magic' tool is being used, and the
current and snapshot canvases.
Example prototype of a callback function that may be sent to Example prototype of a callback function that may be sent to
Tux Paint's "line()" 'Magic' tool plugin helper function: Tux Paint's "line()" 'Magic' tool plugin helper function:
@ -374,6 +375,12 @@ Interfaces
void exampleCallBack(void * ptr_to_api, int which_tool, void exampleCallBack(void * ptr_to_api, int which_tool,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y); SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
Example use of the "line()" helper (e.g., within a plugin's
draw() function):
api->line((void *) api, which, canvas, snapshot, ox, oy, x, y,
1, exampleCallBack);
* Uint8 touched(int x, int y) * Uint8 touched(int x, int y)
This function allows you to avoid re-processing the same pixels This function allows you to avoid re-processing the same pixels
multiple times when the user drags the mouse across an area of multiple times when the user drags the mouse across an area of
@ -424,6 +431,11 @@ Interfaces
should be placed for the installed version of Tux Paint to find should be placed for the installed version of Tux Paint to find
them. (See "Installing," below.) them. (See "Installing," below.)
Note: If your plugin is installed locally (e.g., in your
"~/.tuxpaint/plugins/" directory), rather than globally
(system-wide), the "data_directory" value will be different.
(e.g., "/home/username/.tuxpaint/plugins/data/").
Tux Paint System Calls Tux Paint System Calls
* void show_progress_bar(void) * void show_progress_bar(void)
@ -660,6 +672,10 @@ Installing
by this command will be the global location where the installed copy by this command will be the global location where the installed copy
of Tux Paint looks for plugins (e.g., "/usr/lib/tuxpaint/plugins"). of Tux Paint looks for plugins (e.g., "/usr/lib/tuxpaint/plugins").
Alternatively, you may use "tp-magic-config --localpluginprefix" to
find out where Tux Paint expects to find local plugins for the
current user (e.g., "/home/username/.tuxpaint/plugins").
As stand-alone commands, using the BASH shell, for example: As stand-alone commands, using the BASH shell, for example:
# cp my_plugin.so `tp-magic-config --pluginprefix` # cp my_plugin.so `tp-magic-config --pluginprefix`
@ -689,6 +705,8 @@ Installing
Note: See the note above regarding the "`" (grave) character. Note: See the note above regarding the "`" (grave) character.
Note: Currently, there is no "--localplugindocprefix" option.
Icons, Sounds and other Data Files Icons, Sounds and other Data Files
Use the "tp-magic-config --dataprefix" command, supplied as part of Use the "tp-magic-config --dataprefix" command, supplied as part of
@ -696,7 +714,13 @@ Installing
effects, etc.) should be installed. The value returned by this effects, etc.) should be installed. The value returned by this
command will be the same as the value of the "data_directory" string command will be the same as the value of the "data_directory" string
stored within the "magic_api" structure that your plugin's functions stored within the "magic_api" structure that your plugin's functions
receive. receive (e.g., "/usr/share/tuxpaint/").
For locally-installed plugins (for the current user only), use
"tp-magic-config --localdataprefix". It will return the value of
"data_directory" string that locally-installed plugins will see
within their "magic_api" structure (e.g.,
"/home/username/.tuxpaint/plugins/data/").
Note: Tux Paint's default Magic tool plugins install their data Note: Tux Paint's default Magic tool plugins install their data
within "magic" subdirectories of Tux Paint's "images" and "sounds" within "magic" subdirectories of Tux Paint's "images" and "sounds"
@ -764,6 +788,9 @@ Installing
(".html" and ".txt" files) within Tux Paint's documentation (".html" and ".txt" files) within Tux Paint's documentation
directory. directory.
Note: The above Makefile example assumes the user will have
priveleges to install Tux Paint plugins system-wide.
Windows Windows
TBD TBD
@ -864,18 +891,22 @@ Glossary
"int i;". Later, "&i" refers to the memory where "i" is stored, not "int i;". Later, "&i" refers to the memory where "i" is stored, not
the value of "i" itself; it is a 'pointer to "i"'.) the value of "i" itself; it is a 'pointer to "i"'.)
* API: Application Programming Interface. TBD * API: Application Programming Interface. TBD
* argument: TBD * argument: A value sent to a function.
* arrow: "->". A symbol in C that references an element within a pointer * arrow: "->". A symbol in C that references an element within a pointer
to a struct. to a struct.
* backquote: See "grave." * backquote: See "grave."
* backtick: See "grave." * backtick: See "grave."
* blue: See "RGBA" * blue: See "RGBA"
* boolean 'or': TBD * boolean 'or': A mathematical operation that results in a true value if
either operand is true. ("1 | 0", "0 | 1" and "1 | 1" all result in
"1". "0 | 0" results in "0".)
* |: See "boolean 'or'" * |: See "boolean 'or'"
* .: See "dot" * .: See "dot"
* `: See "grave." * `: See "grave."
* *: See "star" * *: See "star"
* byte: TBD * byte: A unit of memory made up of 8 bits. As a signed value, it can
represent -128 through 127. As an unsigned value, it can represent 0
through 255.
* callback: TBD * callback: TBD
* C enumeration: TBD * C enumeration: TBD
* C function: TBD * C function: TBD
@ -894,7 +925,8 @@ Glossary
"#define RADIUS 16"; all instances of "RADIUS" will be replaced with "#define RADIUS 16"; all instances of "RADIUS" will be replaced with
"16"), but can also be used to create macros. Typically placed within "16"), but can also be used to create macros. Typically placed within
C header files. C header files.
* dimensions: TBD * dimensions: The size of an object, in terms of its width (left to
right) and height (top to bottom).
* .dll: See "Shared Object" * .dll: See "Shared Object"
* dot: ".". A symbol in C that references an element within a struct. * dot: ".". A symbol in C that references an element within a struct.
* drag: The action of moving a mouse while the button remains held. * drag: The action of moving a mouse while the button remains held.
@ -904,11 +936,15 @@ Glossary
* enum: See "C enumeration" * enum: See "C enumeration"
* float: See "floating point" * float: See "floating point"
* floating point: TBD * floating point: TBD
* format: TBD * format: An SDL_Surface element (a pointer to an SDL_PixelFormat
structure) that contains information about a surface; for example, the
number of bits used to represent each pixel). (See also the
"SDL_PixelFormat(3) man page)
* free(): A C function that frees (deallocates) memory allocated by * free(): A C function that frees (deallocates) memory allocated by
other C functions (such as "strdup()"). other C functions (such as "strdup()").
* function: See "C function" * function: See "C function"
* gcc: TBD (See also the "gcc(1)" man page) * gcc: The GNU C compiler, a portable Open Source compiler. (See also
the "gcc(1)" man page)
* GNU C Compiler: See "gcc" * GNU C Compiler: See "gcc"
* grave: The "`" character; used by the BASH shell to use the output of * grave: The "`" character; used by the BASH shell to use the output of
a command as the command-line arguments to another. a command as the command-line arguments to another.
@ -930,8 +966,13 @@ Glossary
* macro: TBD * macro: TBD
* magic_api: A C structure that is passed along to a plugin's functions * magic_api: A C structure that is passed along to a plugin's functions
that exposes data and functions within the running copy of Tux Paint. that exposes data and functions within the running copy of Tux Paint.
* make: TBD * make: A utility that automatically determines which pieces of a larger
* Makefile: TBD program need to be recompiled, and issues the commands to recompile
them. (See also "Makefile")
* Makefile: A text file used by the "make" utility; it describes the
relationships among files in your program, and the commands for
updating each file. (For example, to compile a human-readable
source-code file into a computer-readable executable program file.)
* Magic tool: One of a number of effects or drawing tools in Tux Paint, * Magic tool: One of a number of effects or drawing tools in Tux Paint,
made available via the "Magic" tool button. made available via the "Magic" tool button.
* Mix_Chunk *: (A pointer to) a C structure defined by SDL_mixer that * Mix_Chunk *: (A pointer to) a C structure defined by SDL_mixer that
@ -944,7 +985,12 @@ Glossary
* OGG: See "Ogg Vorbis" * OGG: See "Ogg Vorbis"
* Ogg Vorbis: TBD (See also: "WAV") * Ogg Vorbis: TBD (See also: "WAV")
* Plugin: TBD * Plugin: TBD
* PNG: TBD (See also the "png(5) man page) * PNG: Portable Network Graphics. An extensible file format for the
lossless, portable, well-compressed storage of raster images. It's the
file format Tux Paint uses to save images, and for its brushes and
stamps. It's an easy way to store 32bpp RGBA images (24bpp true color
with full 8bpp alpha transparency), excellent for use in graphics
programs like Tux Paint. (See also the "png(5) man page)
* pointer: See "C pointer" * pointer: See "C pointer"
* red: See "RGBA" * red: See "RGBA"
* release: The action of releasing a button on a mouse. * release: The action of releasing a button on a mouse.

View file

@ -15,7 +15,7 @@ New Breed Software</p>
<p><a href="mailto:bill@newbreedsoftware.com">bill@newbreedsoftware.com</a><br> <p><a href="mailto:bill@newbreedsoftware.com">bill@newbreedsoftware.com</a><br>
<a href="http://www.tuxpaint.org/">http://www.tuxpaint.org/</a></p> <a href="http://www.tuxpaint.org/">http://www.tuxpaint.org/</a></p>
<p>July 5, 2007 - August 2, 2007</p> <p>July 5, 2007 - August 7, 2007</p>
</center> </center>
<hr size=2 noshade> <hr size=2 noshade>
@ -41,51 +41,51 @@ concept.)</p>
<h2>Table of Contents</h2> <h2>Table of Contents</h2>
<ul> <ul>
<li><a href="prereq">Prequisites</a> <li><a href="#prereqs">Prequisites</a>
<li><a href="interfaces">Interfaces</a> <li><a href="#interfaces">Interfaces</a>
<ul> <ul>
<li><a href="#">'Magic' tool plugin functions</a> <li><a href="#magic_plugin_funcs">'Magic' tool plugin functions</a>
<ul> <ul>
<li><a href="#">Common arguments to plugin functions</a> <li><a href="#common_args">Common arguments to plugin functions</a>
<li><a href="#">Required Plugin Functions</a> <li><a href="#toolfuncs">Required Plugin Functions</a>
<ul> <ul>
<li><a href="#">Plugin "housekeeping" functions</a> <li><a href="#housekeeping">Plugin "housekeeping" functions</a>
<li><a href="#">Plugin event functions</a> <li><a href="#eventfuncs">Plugin event functions</a>
</ul> </ul>
</ul> </ul>
<li><a href="#tpfuncs">Tux Paint Functions and Data</a> <li><a href="#tpfuncs">Tux Paint Functions and Data</a>
<ul> <ul>
<li><a href="#">Pixel Manipulations</a> <li><a href="#pixel_manip">Pixel Manipulations</a>
<li><a href="#">Helper Functions</a> <li><a href="#helper_funcs">Helper Functions</a>
<li><a href="#">Informational</a> <li><a href="#informational">Informational</a>
<li><a href="#">Tux Paint System Calls</a> <li><a href="#syscalls">Tux Paint System Calls</a>
<li><a href="#">Color Conversions</a> <li><a href="#color_convs">Color Conversions</a>
</ul> </ul>
<li><a href="#">Helper Macros in "tp_magic_api.h"</a> <li><a href="#macros">Helper Macros in "tp_magic_api.h"</a>
<li><a href="#">Constant Definitions in "tp_magic_api.h"</a> <li><a href="#consts">Constant Definitions in "tp_magic_api.h"</a>
</ul> </ul>
<li><a href="#compiling">Compiling</a> <li><a href="#compiling">Compiling</a>
<ul> <ul>
<li><a href="#">Linux and other Unix-like Platforms</a> <li><a href="#compiling-linux">Linux and other Unix-like Platforms</a>
<li><a href="#">Windows</a> <li><a href="#compiling-windows">Windows</a>
<li><a href="#">Mac OS X</a> <li><a href="#compiling-osx">Mac OS X</a>
</ul> </ul>
<li><a href="#installing">Installing</a> <li><a href="#installing">Installing</a>
<ul> <ul>
<li><a href="#">Linux and other Unix-like Platforms</a> <li><a href="#installing-linux">Linux and other Unix-like Platforms</a>
<li><a href="#">Windows</a> <li><a href="#installing-windows">Windows</a>
<li><a href="#">Mac OS X</a> <li><a href="#installing-osx">Mac OS X</a>
</ul> </ul>
<li><a href="#multiple">Creating plugins with multiple effects</a> <li><a href="#multiple">Creating plugins with multiple effects</a>
<li><a href="#">Example Code</a> <li><a href="#examples">Example Code</a>
<li><a href="#">Getting Help</a> <li><a href="#help">Getting Help</a>
<li><a href="#glossary">Glossary</a> <li><a href="#glossary">Glossary</a>
</ul> </ul>
<hr size=1 noshade> <hr size=1 noshade>
<h2><a name="prereq">Prerequisites</a></h2> <h2><a name="prereqs">Prerequisites</a></h2>
<blockquote> <blockquote>
@ -102,7 +102,7 @@ recommended, but some basic SDL concepts will be covered in this document.</p>
<hr size=1 noshade> <hr size=1 noshade>
<h2>Interfaces</h2> <h2><a name="interfaces">Interfaces</a></h2>
<blockquote> <blockquote>
@ -133,7 +133,7 @@ plugin header file, as well as SDL's header files) for building a plugin.
with Tux&nbsp;Paint &mdash; or in some cases, as part of a "Tux&nbsp;Paint with Tux&nbsp;Paint &mdash; or in some cases, as part of a "Tux&nbsp;Paint
'Magic' Tool Plugin Development package".</p> 'Magic' Tool Plugin Development package".</p>
<h3>'Magic' tool plugin functions</h3> <h3><a name="magic_plugin_funcs">'Magic' tool plugin functions</a></h3>
<blockquote> <blockquote>
@ -144,7 +144,7 @@ would have functions whose names begin with "<code>blur_</code>"). <i>This
includes private functions</i> (ones not used by Tux&nbsp;Paint directly), includes private functions</i> (ones not used by Tux&nbsp;Paint directly),
unless you declare those as '<code>static</code>'.</p> unless you declare those as '<code>static</code>'.</p>
<h4>Common arguments to plugin functions:</h4> <h4><a name="common_args">Common arguments to plugin functions:</a></h4>
Here is a description of arguments that many of your plugin's functions Here is a description of arguments that many of your plugin's functions
will need to accept. will need to accept.
@ -222,7 +222,7 @@ preceded by your plugin's filename. That is, if your plugin is called
then the names of your functions must begin with "<code><b>zoom_</b></code>" then the names of your functions must begin with "<code><b>zoom_</b></code>"
(e.g., "<code>zoom_get_name(...)</code>").</p> (e.g., "<code>zoom_get_name(...)</code>").</p>
<h5>Plugin "housekeeping" functions:</h5> <h5><a name="housekeeping">Plugin "housekeeping" functions:</a></h5>
<ul> <ul>
<li><code><b>Uint32 api_version(void)</b></code><br> <li><code><b>Uint32 api_version(void)</b></code><br>
@ -316,7 +316,7 @@ then the names of your functions must begin with "<code><b>zoom_</b></code>"
</ul> </ul>
<h5>Plugin event functions:</h5> <h5><a name="eventfuncs">Plugin event functions:</a></h5>
<ul> <ul>
<li><code><b>void set_color(magic_api&nbsp;*&nbsp;api, <li><code><b>void set_color(magic_api&nbsp;*&nbsp;api,
@ -399,7 +399,7 @@ access via the "<code>magic_api</code>" structure, sent to all of the
plugin's functions. plugin's functions.
(See "<a href="#toolfuncs">Required Plugin Functions</a>," above.)</p> (See "<a href="#toolfuncs">Required Plugin Functions</a>," above.)</p>
<h4>Pixel Manipulations</h4> <h4><a name="pixel_manip">Pixel Manipulations</a></h4>
<blockquote> <blockquote>
@ -434,7 +434,7 @@ plugin's functions.
</blockquote> </blockquote>
<h4>Helper Functions</h4> <h4><a name="helper_funcs">Helper Functions</a></h4>
<blockquote> <blockquote>
@ -447,8 +447,9 @@ plugin's functions.
brush shape.<br> brush shape.<br>
<br> <br>
<li><code><b>void line(int&nbsp;which, SDL_Surface&nbsp;* canvas, <li><code><b>void line(void&nbsp;*&nbsp;api, int&nbsp;which,
SDL_Surface&nbsp;*&nbsp;snapshot, int&nbsp;x1, int&nbsp;y1, SDL_Surface&nbsp;* canvas, SDL_Surface&nbsp;*&nbsp;snapshot,
int&nbsp;x1, int&nbsp;y1,
int&nbsp;x2, int&nbsp;y2, int&nbsp;step, FUNC&nbsp;callback)</b></code><br> int&nbsp;x2, int&nbsp;y2, int&nbsp;step, FUNC&nbsp;callback)</b></code><br>
This function calculates all points on a line between the coordinates This function calculates all points on a line between the coordinates
(x1,y1) and (x2,y2). Every 'step' iterations, it calls the 'callback' (x1,y1) and (x2,y2). Every 'step' iterations, it calls the 'callback'
@ -456,9 +457,9 @@ plugin's functions.
<br> <br>
It sends the 'callback' function the (x,y) coordinates on the line, It sends the 'callback' function the (x,y) coordinates on the line,
Tux&nbsp;Paint's "<code>magic_api</code>" struct (as a Tux&nbsp;Paint's "<code>magic_api</code>" struct (as a
"<code>void&nbsp;*</code>" pointer), a 'which' value, represening which "<code>void&nbsp;*</code>" pointer which you need to send to it),
of the plugin's 'Magic' tool is being used, and the current and snapshot a 'which' value, represening which of the plugin's 'Magic' tool is
canvases.<br> being used, and the current and snapshot canvases.<br>
<br> <br>
Example prototype of a callback function that may be sent to Example prototype of a callback function that may be sent to
Tux&nbsp;Paint's "<code>line()</code>" 'Magic' tool plugin helper function: Tux&nbsp;Paint's "<code>line()</code>" 'Magic' tool plugin helper function:
@ -468,6 +469,13 @@ plugin's functions.
int&nbsp;x, int&nbsp;y); int&nbsp;x, int&nbsp;y);
</code></blockquote> </code></blockquote>
<br> <br>
Example use of the "<code>line()</code>" helper (e.g., within a plugin's
<code>draw()</code> function):
<blockquote><code>
api-&gt;line((void&nbsp;*)&nbsp;api, which, canvas, snapshot, ox,&nbsp;oy,
x,&nbsp;y, 1, exampleCallBack);
</code></blockquote>
<br>
<li><code><b>Uint8 touched(int&nbsp;x, int&nbsp;y)</b></code><br> <li><code><b>Uint8 touched(int&nbsp;x, int&nbsp;y)</b></code><br>
This function allows you to avoid re-processing the same pixels multiple This function allows you to avoid re-processing the same pixels multiple
@ -496,7 +504,7 @@ plugin's functions.
</blockquote> </blockquote>
<h4>Informational</h4> <h4><a name="informational">Informational</a></h4>
<blockquote> <blockquote>
@ -532,12 +540,17 @@ plugin's functions.
placed for the installed version of Tux&nbsp;Paint to find them. placed for the installed version of Tux&nbsp;Paint to find them.
(See "<a href="#installing">Installing</a>," below.)<br> (See "<a href="#installing">Installing</a>," below.)<br>
<br> <br>
<b>Note:</b> If your plugin is installed locally (e.g., in your
"<code>~/.tuxpaint/plugins/</code>" directory), rather than globally
(system-wide), the "<code>data_directory</code>" value will be different.
(e.g., "<code>/home/<i>username</i>/.tuxpaint/plugins/data/</code>").<br>
<br>
</ul> </ul>
</blockquote> </blockquote>
<h4>Tux Paint System Calls</h4> <h4><a name="syscalls">Tux Paint System Calls</a></h4>
<blockquote> <blockquote>
<ul> <ul>
@ -589,7 +602,7 @@ plugin's functions.
</ul> </ul>
</blockquote> </blockquote>
<h4>Color Conversions</h4> <h4><a name="color_convs">Color Conversions</a></h4>
<blockquote> <blockquote>
<ul> <ul>
@ -629,7 +642,7 @@ plugin's functions.
</blockquote> </blockquote>
</blockquote> </blockquote>
<h3>Helper Macros in "<code>tp_magic_api.h</code>":</h3> <h3><a name="macros">Helper Macros in "<code>tp_magic_api.h</code>":</a></h3>
<blockquote> <blockquote>
<p>Along with the "<code>magic_api</code>" C structure containing functions <p>Along with the "<code>magic_api</code>" C structure containing functions
@ -664,7 +677,7 @@ also contains some helper macros that you may use.</p>
</blockquote> </blockquote>
<h3>Constant Defintions in "<code>tp_magic_api.h</code>":</h3> <h3><a name="consts">Constant Defintions in "<code>tp_magic_api.h</code>":</a></h3>
<blockquote> <blockquote>
<p>The following is a summary of constant values that are set <p>The following is a summary of constant values that are set
@ -704,7 +717,7 @@ also contains some helper macros that you may use.</p>
<blockquote> <blockquote>
<h3>Linux and other Unix-like Platforms</h3> <h3><a name="compiling-linux">Linux and other Unix-like Platforms</a></h3>
<blockquote> <blockquote>
@ -824,13 +837,13 @@ also contains some helper macros that you may use.</p>
</blockquote> </blockquote>
<h3>Windows</h3> <h3><a name="compiling-windows">Windows</a></h3>
<blockquote> <blockquote>
<p>TBD</p> <p>TBD</p>
</blockquote> </blockquote>
<h3>Mac OS X</h3> <h3><a name="compiling-osx">Mac OS X</a></h3>
<blockquote> <blockquote>
<p>TBD</p> <p>TBD</p>
@ -844,7 +857,7 @@ also contains some helper macros that you may use.</p>
<blockquote> <blockquote>
<h3>Linux and other Unix-like Platforms</h3> <h3><a name="installing-linux">Linux and other Unix-like Platforms</a></h3>
<blockquote> <blockquote>
<p>Use the "<code>tp-magic-config</code>" command-line tool, supplied as <p>Use the "<code>tp-magic-config</code>" command-line tool, supplied as
@ -862,6 +875,11 @@ also contains some helper macros that you may use.</p>
the global location where the installed copy of Tux&nbsp;Paint looks the global location where the installed copy of Tux&nbsp;Paint looks
for plugins (e.g., "<code>/usr/lib/tuxpaint/plugins</code>").</p> for plugins (e.g., "<code>/usr/lib/tuxpaint/plugins</code>").</p>
<p>Alternatively, you may use
"<code>tp-magic-config&nbsp;--localpluginprefix</code>" to find out where
Tux&nbsp;Paint expects to find local plugins for the current user (e.g.,
"<code>/home/<i>username</i>/.tuxpaint/plugins</code>").</p>
<p>As stand-alone commands, using the BASH shell, for example:</p> <p>As stand-alone commands, using the BASH shell, for example:</p>
<blockquote> <blockquote>
@ -904,6 +922,9 @@ also contains some helper macros that you may use.</p>
<p><b>Note:</b> See the <a href="#grave">note above regarding the <p><b>Note:</b> See the <a href="#grave">note above regarding the
"<font size=+1><b>`</b></font>" (grave) character</a>.</p> "<font size=+1><b>`</b></font>" (grave) character</a>.</p>
<p><b>Note:</b> Currently, there is no "<code>--localplugindocprefix</code>"
option.</p>
</blockquote> </blockquote>
<h4>Icons, Sounds and other Data Files</h4> <h4>Icons, Sounds and other Data Files</h4>
@ -915,7 +936,14 @@ also contains some helper macros that you may use.</p>
(PNG icon, Ogg&nbsp;Vorbis sound effects, etc.) should be installed. (PNG icon, Ogg&nbsp;Vorbis sound effects, etc.) should be installed.
The value returned by this command will be the same as the value of the The value returned by this command will be the same as the value of the
"<code>data_directory</code>" string stored within the "<code>data_directory</code>" string stored within the
"<code>magic_api</code>" structure that your plugin's functions receive.</p> "<code>magic_api</code>" structure that your plugin's functions receive
(e.g., "<code>/usr/share/tuxpaint/</code>").</p>
<p>For locally-installed plugins (for the current user only), use
"<code>tp-magic-config&nbsp;--localdataprefix</code>". It will return the
value of "<code>data_directory</code>" string that locally-installed
plugins will see within their "<code>magic_api</code>" structure
(e.g., "<code>/home/<i>username</i>/.tuxpaint/plugins/data/</code>").</p>
<p><b>Note:</b> Tux&nbsp;Paint's default Magic tool plugins install their <p><b>Note:</b> Tux&nbsp;Paint's default Magic tool plugins install their
data within "<code>magic</code>" subdirectories of Tux&nbsp;Paint's data within "<code>magic</code>" subdirectories of Tux&nbsp;Paint's
@ -997,16 +1025,19 @@ also contains some helper macros that you may use.</p>
("<code>.html</code>" and "<code>.txt</code>" files) within Tux&nbsp;Paint's ("<code>.html</code>" and "<code>.txt</code>" files) within Tux&nbsp;Paint's
documentation directory.</p> documentation directory.</p>
<p><b>Note:</b> The above Makefile example assumes the user will have
priveleges to install Tux&nbsp;Paint plugins system-wide.</p>
</blockquote> </blockquote>
</blockquote> </blockquote>
<h3>Windows</h3> <h3><a name="installing-windows">Windows</a></h3>
<blockquote> <blockquote>
<p>TBD</p> <p>TBD</p>
</blockquote> </blockquote>
<h3>Mac OS X</h3> <h3><a name="installing-osx">Mac OS X</a></h3>
<blockquote> <blockquote>
<p>TBD</p> <p>TBD</p>
@ -1092,7 +1123,7 @@ simply be '1', your arrays will be of length '1', etc.)</p>
<hr size=1 noshade> <hr size=1 noshade>
<h2>Example Code</h2> <h2><a name="examples">Example Code</a></h2>
<blockquote> <blockquote>
<p>The C source file <p>The C source file
@ -1102,7 +1133,7 @@ simply be '1', your arrays will be of length '1', etc.)</p>
<hr size=1 noshade> <hr size=1 noshade>
<h2>Getting Help</h2> <h2><a name="help">Getting Help</a></h2>
<blockquote> <blockquote>
@ -1127,17 +1158,17 @@ mailing lists:
<li><b>&amp;:</b> See "ampersand" <li><b>&amp;:</b> See "ampersand"
<li><b>ampersand:</b> "<code>&amp;</code>". A symbol in C that allows you to refer to the memory address of a variable; that is, a pointer. (For example, consider "<code>int&nbsp;i;</code>". Later, "<code>&amp;i</code>" refers to the memory where "<code>i</code>" is stored, not the value of "<code>i</code>" itself; it is a 'pointer to "<code>i</code>"'.) <li><b>ampersand:</b> "<code>&amp;</code>". A symbol in C that allows you to refer to the memory address of a variable; that is, a pointer. (For example, consider "<code>int&nbsp;i;</code>". Later, "<code>&amp;i</code>" refers to the memory where "<code>i</code>" is stored, not the value of "<code>i</code>" itself; it is a 'pointer to "<code>i</code>"'.)
<li><b>API:</b> Application Programming Interface. <i>TBD</i> <li><b>API:</b> Application Programming Interface. <i>TBD</i>
<li><b>argument:</b> <i>TBD</i> <li><b>argument:</b> A value sent to a function.
<li><b>arrow:</b> "<code>-&gt;</code>". A symbol in C that references an element within a pointer to a struct. <li><b>arrow:</b> "<code>-&gt;</code>". A symbol in C that references an element within a pointer to a struct.
<li><b>backquote:</b> See "grave." <li><b>backquote:</b> See "grave."
<li><b>backtick:</b> See "grave." <li><b>backtick:</b> See "grave."
<li><b>blue:</b> See "RGBA" <li><b>blue:</b> See "RGBA"
<li><b>boolean 'or':</b> <i>TBD</i> <li><b>boolean 'or':</b> A mathematical operation that results in a true value if either operand is true. ("1&nbsp;|&nbsp;0", "0&nbsp;|&nbsp;1" and "1&nbsp;|&nbsp;1" all result in "1". "0&nbsp;|&nbsp;0" results in "0".)
<li><b>|:</b> See "boolean 'or'" <li><b>|:</b> See "boolean 'or'"
<li><b>.:</b> See "dot" <li><b>.:</b> See "dot"
<li><b>`:</b> See "grave." <li><b>`:</b> See "grave."
<li><b>*:</b> See "star" <li><b>*:</b> See "star"
<li><b>byte:</b> <i>TBD</i> <li><b>byte:</b> A unit of memory made up of 8 bits. As a signed value, it can represent -128 through 127. As an unsigned value, it can represent 0 through 255.
<li><b>callback:</b> <i>TBD</i> <li><b>callback:</b> <i>TBD</i>
<li><b>C enumeration:</b> <i>TBD</i> <li><b>C enumeration:</b> <i>TBD</i>
<li><b>C function:</b> <i>TBD</i> <li><b>C function:</b> <i>TBD</i>
@ -1148,7 +1179,7 @@ mailing lists:
<li><b>C pointer:</b> A variable that contains the location of a piece of memory; usually used to 'point' to another variable. Since C functions can only return one value as a result, pointers are often sent to functions to allow the function to change the values of multiple variables. (For example, Tux&nbsp;Paint's "<code>rgbtohsv()</code>" and "<code>hsvtorgb()</code>".) <li><b>C pointer:</b> A variable that contains the location of a piece of memory; usually used to 'point' to another variable. Since C functions can only return one value as a result, pointers are often sent to functions to allow the function to change the values of multiple variables. (For example, Tux&nbsp;Paint's "<code>rgbtohsv()</code>" and "<code>hsvtorgb()</code>".)
<li><b>C structure:</b> <i>TBD</i> <li><b>C structure:</b> <i>TBD</i>
<li><b>#define:</b> A C statement that defines a substitution that can occur later in the code. Generally used for constant values (e.g., "<code>#define&nbsp;RADIUS&nbsp;16</code>"; all instances of "<code>RADIUS</code>" will be replaced with "<code>16</code>"), but can also be used to create macros. Typically placed within C header files. <li><b>#define:</b> A C statement that defines a substitution that can occur later in the code. Generally used for constant values (e.g., "<code>#define&nbsp;RADIUS&nbsp;16</code>"; all instances of "<code>RADIUS</code>" will be replaced with "<code>16</code>"), but can also be used to create macros. Typically placed within C header files.
<li><b>dimensions:</b> <i>TBD</i> <li><b>dimensions:</b> The size of an object, in terms of its width (left to right) and height (top to bottom).
<li><b>.dll:</b> See "Shared Object" <li><b>.dll:</b> See "Shared Object"
<li><b>dot:</b> "<code>.</code>". A symbol in C that references an element within a struct. <li><b>dot:</b> "<code>.</code>". A symbol in C that references an element within a struct.
<li><b>drag:</b> The action of moving a mouse while the button remains held. <li><b>drag:</b> The action of moving a mouse while the button remains held.
@ -1156,10 +1187,10 @@ mailing lists:
<li><b>enum:</b> See "C enumeration" <li><b>enum:</b> See "C enumeration"
<li><b>float:</b> See "floating point" <li><b>float:</b> See "floating point"
<li><b>floating point:</b> <i>TBD</i> <li><b>floating point:</b> <i>TBD</i>
<li><b>format:</b> <i>TBD</i> <li><b>format:</b> An <code>SDL_Surface</code> element (a pointer to an <code>SDL_PixelFormat</code> structure) that contains information about a surface; for example, the number of bits used to represent each pixel). (See also the "<code>SDL_PixelFormat(3)</code> <i>man&nbsp;page</i>)
<li><b>free():</b> A C function that frees (deallocates) memory allocated by other C functions (such as "<code>strdup()</code>"). <li><b>free():</b> A C function that frees (deallocates) memory allocated by other C functions (such as "<code>strdup()</code>").
<li><b>function:</b> See "C function" <li><b>function:</b> See "C function"
<li><b>gcc:</b> <i>TBD</i> (See also the "<code>gcc(1)</code>" <i>man&nbsp;page</i>) <li><b>gcc:</b> The GNU C compiler, a portable Open&nbsp;Source compiler. (See also the "<code>gcc(1)</code>" <i>man&nbsp;page</i>)
<li><b>GNU C Compiler:</b> See "gcc" <li><b>GNU C Compiler:</b> See "gcc"
<li><b>grave:</b> The "<code><font size=+1>`</font></code>" character; used by the BASH shell to use the output of a command as the command-line arguments to another. <li><b>grave:</b> The "<code><font size=+1>`</font></code>" character; used by the BASH shell to use the output of a command as the command-line arguments to another.
<li><b>green:</b> See "RGBA" <li><b>green:</b> See "RGBA"
@ -1177,8 +1208,8 @@ mailing lists:
<li><b>linear:</b> <i>TBD</i> <li><b>linear:</b> <i>TBD</i>
<li><b>macro:</b> <i>TBD</i> <li><b>macro:</b> <i>TBD</i>
<li><b>magic_api:</b> A C structure that is passed along to a plugin's functions that exposes data and functions within the running copy of Tux&nbsp;Paint. <li><b>magic_api:</b> A C structure that is passed along to a plugin's functions that exposes data and functions within the running copy of Tux&nbsp;Paint.
<li><b>make:</b> <i>TBD</i> <li><b>make:</b> A utility that automatically determines which pieces of a larger program need to be recompiled, and issues the commands to recompile them. (See also "Makefile")
<li><b>Makefile:</b> <i>TBD</i> <li><b>Makefile:</b> A text file used by the "make" utility; it describes the relationships among files in your program, and the commands for updating each file. (For example, to compile a human-readable source-code file into a computer-readable executable program file.)
<li><b>Magic tool</b>: One of a number of effects or drawing tools in Tux&nbsp;Paint, made available via the "Magic" tool button. <li><b>Magic tool</b>: One of a number of effects or drawing tools in Tux&nbsp;Paint, made available via the "Magic" tool button.
<li><b>Mix_Chunk&nbsp;*:</b> (A pointer to) a C structure defined by SDL_mixer that contains a sound. <li><b>Mix_Chunk&nbsp;*:</b> (A pointer to) a C structure defined by SDL_mixer that contains a sound.
<li><b>Mix_FreeChunk():</b> An SDL_mixer function that frees (deallocates) memory allocated for an SDL_mixer sound 'chunk' ("<code>Mix_Chunk&nbsp;*</code>"). <li><b>Mix_FreeChunk():</b> An SDL_mixer function that frees (deallocates) memory allocated for an SDL_mixer sound 'chunk' ("<code>Mix_Chunk&nbsp;*</code>").
@ -1187,7 +1218,7 @@ mailing lists:
<li><b>OGG</b>: See "Ogg Vorbis" <li><b>OGG</b>: See "Ogg Vorbis"
<li><b>Ogg&nbsp;Vorbis:</b> <i>TBD</i> (See also: "WAV") <li><b>Ogg&nbsp;Vorbis:</b> <i>TBD</i> (See also: "WAV")
<li><b>Plugin</b>: <i>TBD</i> <li><b>Plugin</b>: <i>TBD</i>
<li><b>PNG:</b> <i>TBD</i> (See also the "<code>png(5)</code> <i>man&nbsp;page</i>) <li><b>PNG:</b> Portable Network Graphics. An extensible file format for the lossless, portable, well-compressed storage of raster images. It's the file format Tux&nbsp;Paint uses to save images, and for its brushes and stamps. It's an easy way to store 32bpp RGBA images (24bpp true color with full 8bpp alpha transparency), excellent for use in graphics programs like Tux&nbsp;Paint. (See also the "<code>png(5)</code> <i>man&nbsp;page</i>)
<li><b>pointer:</b> See "C pointer" <li><b>pointer:</b> See "C pointer"
<li><b>red:</b> See "RGBA" <li><b>red:</b> See "RGBA"
<li><b>release:</b> The action of releasing a button on a mouse. <li><b>release:</b> The action of releasing a button on a mouse.

View file

@ -146,9 +146,10 @@ int example_init(magic_api * api)
// we installed our plugin and its data.) // we installed our plugin and its data.)
snprintf(fname, sizeof(fname), snprintf(fname, sizeof(fname),
"%s/sounds/magic/%s.wav", "%s/sounds/magic/%s",
api->data_directory, snd_filenames[i]); api->data_directory, snd_filenames[i]);
printf("Trying to load %s sound file\n", fname);
// Try to load the file! // Try to load the file!
@ -334,7 +335,8 @@ void example_drag(magic_api * api, int which, SDL_Surface * canvas,
// useful things (which of our "Magic" tools is being used and // useful things (which of our "Magic" tools is being used and
// the current and snapshot canvases). // the current and snapshot canvases).
api->line(which, canvas, snapshot, ox, oy, x, y, 1, example_line_callback); api->line((void *) api, which, canvas, snapshot,
ox, oy, x, y, 1, example_line_callback);
// If we need to, swap the X and/or Y values, so that // If we need to, swap the X and/or Y values, so that

View file

@ -1,3 +1,32 @@
/*
blocks_chalk_drip.c
Blocks, Chalk and Drip Magic Tools Plugin
Tux Paint - A simple drawing program for children.
Copyright (c) 2002-2007 by Bill Kendrick and others; see AUTHORS.txt
bill@newbreedsoftware.com
http://www.tuxpaint.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
Last updated: August 7, 2007
$Id$
*/
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <libintl.h> #include <libintl.h>
@ -217,7 +246,7 @@ 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) SDL_Rect * update_rect)
{ {
api->line(which, canvas, last, ox, oy, x, y, 1, blocks_chalk_drip_linecb); api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, blocks_chalk_drip_linecb);
if (ox > x) { int tmp = ox; ox = x; x = tmp; } if (ox > x) { int tmp = ox; ox = x; x = tmp; }
if (oy > y) { int tmp = oy; oy = y; y = tmp; } if (oy > y) { int tmp = oy; oy = y; y = tmp; }

View file

@ -1,3 +1,34 @@
/*
blur.c
Blur Magic Tool Plugin
Tux Paint - A simple drawing program for children.
Copyright (c) 2002-2007 by Bill Kendrick and others; see AUTHORS.txt
bill@newbreedsoftware.com
http://www.tuxpaint.org/
Major improvements by Albert Cahalan <albert@users.sf.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
Last updated: August 7, 2007
$Id$
*/
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <libintl.h> #include <libintl.h>
@ -130,7 +161,7 @@ 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) SDL_Rect * update_rect)
{ {
api->line(which, canvas, last, ox, oy, x, y, 1, do_blur); api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_blur);
if (ox > x) { int tmp = ox; ox = x; x = tmp; } if (ox > x) { int tmp = ox; ox = x; x = tmp; }
if (oy > y) { int tmp = oy; oy = y; y = tmp; } if (oy > y) { int tmp = oy; oy = y; y = tmp; }

View file

@ -1,3 +1,34 @@
/*
bricks.c
Bricks Magic Tools Plugin
Tux Paint - A simple drawing program for children.
Albert Cahalan <albert@users.sf.net>
Copyright (c) 2002-2007 by Bill Kendrick and others; see AUTHORS.txt
bill@newbreedsoftware.com
http://www.tuxpaint.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
Last updated: August 7, 2007
$Id$
*/
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <libintl.h> #include <libintl.h>
@ -179,7 +210,7 @@ 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) SDL_Rect * update_rect)
{ {
api->line(which, canvas, last, ox, oy, x, y, 1, do_bricks); api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_bricks);
if (ox > x) { int tmp = ox; ox = x; x = tmp; } if (ox > x) { int tmp = ox; ox = x; x = tmp; }
if (oy > y) { int tmp = oy; oy = y; y = tmp; } if (oy > y) { int tmp = oy; oy = y; y = tmp; }

View file

@ -1,3 +1,32 @@
/*
cartoon.c
Cartoon Magic Tool Plugin
Tux Paint - A simple drawing program for children.
Copyright (c) 2002-2007 by Bill Kendrick and others; see AUTHORS.txt
bill@newbreedsoftware.com
http://www.tuxpaint.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
Last updated: August 7, 2007
$Id$
*/
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <libintl.h> #include <libintl.h>
@ -148,7 +177,7 @@ 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) SDL_Rect * update_rect)
{ {
api->line(which, canvas, last, ox, oy, x, y, 1, do_cartoon); api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_cartoon);
if (ox > x) { int tmp = ox; ox = x; x = tmp; } if (ox > x) { int tmp = ox; ox = x; x = tmp; }
if (oy > y) { int tmp = oy; oy = y; y = tmp; } if (oy > y) { int tmp = oy; oy = y; y = tmp; }

View file

@ -1,3 +1,32 @@
/*
emboss.c
Emboss Magic Tool Plugin
Tux Paint - A simple drawing program for children.
Copyright (c) 2002-2007 by Bill Kendrick and others; see AUTHORS.txt
bill@newbreedsoftware.com
http://www.tuxpaint.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
Last updated: August 7, 2007
$Id$
*/
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <libintl.h> #include <libintl.h>
@ -18,7 +47,7 @@ int emboss_init(magic_api * api)
{ {
char fname[1024]; char fname[1024];
snprintf(fname, sizeof(fname), "%s/sounds/magic/emboss.wav", snprintf(fname, sizeof(fname), "%s/sounds/magic/emboss.ogg",
api->data_directory); api->data_directory);
emboss_snd = Mix_LoadWAV(fname); emboss_snd = Mix_LoadWAV(fname);
@ -104,7 +133,7 @@ void emboss_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_Rect * update_rect)
{ {
api->line(which, canvas, last, ox, oy, x, y, 1, do_emboss); api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_emboss);
if (ox > x) { int tmp = ox; ox = x; x = tmp; } if (ox > x) { int tmp = ox; ox = x; x = tmp; }
if (oy > y) { int tmp = oy; oy = y; y = tmp; } if (oy > y) { int tmp = oy; oy = y; y = tmp; }
@ -115,7 +144,7 @@ void emboss_drag(magic_api * api, int which, SDL_Surface * canvas,
update_rect->h = (y + 16) - update_rect->h; update_rect->h = (y + 16) - update_rect->h;
api->playsound(emboss_snd, api->playsound(emboss_snd,
(x * 255) / canvas->w, (y * 255) / canvas->h); (x * 255) / canvas->w, 255);
} }
// Affect the canvas on click: // Affect the canvas on click:

View file

@ -1,3 +1,32 @@
/*
fade_darken.c
Fade and Darken Magic Tools Plugin
Tux Paint - A simple drawing program for children.
Copyright (c) 2002-2007 by Bill Kendrick and others; see AUTHORS.txt
bill@newbreedsoftware.com
http://www.tuxpaint.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
Last updated: August 7, 2007
$Id$
*/
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <libintl.h> #include <libintl.h>
@ -125,7 +154,7 @@ void fade_darken_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_LockSurface(last); SDL_LockSurface(last);
SDL_LockSurface(canvas); SDL_LockSurface(canvas);
api->line(which, canvas, last, ox, oy, x, y, 1, do_fade_darken); api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_fade_darken);
SDL_UnlockSurface(canvas); SDL_UnlockSurface(canvas);
SDL_UnlockSurface(last); SDL_UnlockSurface(last);

View file

@ -1,3 +1,36 @@
/*
fill.c
Fill Magic Tool Plugin
Tux Paint - A simple drawing program for children.
Copyright (c) 2002-2007 by Bill Kendrick and others; see AUTHORS.txt
bill@newbreedsoftware.com
http://www.tuxpaint.org/
Flood fill code based on Wikipedia example:
http://www.wikipedia.org/wiki/Flood_fill/C_example
by Damian Yerrick - http://www.wikipedia.org/wiki/Damian_Yerrick
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
Last updated: August 7, 2007
$Id$
*/
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <libintl.h> #include <libintl.h>

View file

@ -1,3 +1,32 @@
/*
flower.c
Flower Magic Tool Plugin
Tux Paint - A simple drawing program for children.
Copyright (c) 2002-2007 by Bill Kendrick and others; see AUTHORS.txt
bill@newbreedsoftware.com
http://www.tuxpaint.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
Last updated: August 7, 2007
$Id$
*/
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <libintl.h> #include <libintl.h>
@ -13,7 +42,7 @@ enum { LEAFSIDE_RIGHT_DOWN,
LEAFSIDE_RIGHT_UP, LEAFSIDE_RIGHT_UP,
LEAFSIDE_LEFT_UP }; LEAFSIDE_LEFT_UP };
Mix_Chunk * flower_snd; Mix_Chunk * flower_click_snd, * flower_release_snd;
Uint8 flower_r, flower_g, flower_b; Uint8 flower_r, flower_g, flower_b;
int flower_min_x, flower_max_x, flower_bottom_x, flower_bottom_y; int flower_min_x, flower_max_x, flower_bottom_x, flower_bottom_y;
int flower_side_first; int flower_side_first;
@ -49,9 +78,13 @@ int flower_init(magic_api * api)
{ {
char fname[1024]; char fname[1024];
snprintf(fname, sizeof(fname), "%s/sounds/magic/flower.wav", snprintf(fname, sizeof(fname), "%s/sounds/magic/flower_click.ogg",
api->data_directory); api->data_directory);
flower_snd = Mix_LoadWAV(fname); flower_click_snd = Mix_LoadWAV(fname);
snprintf(fname, sizeof(fname), "%s/sounds/magic/flower_release.ogg",
api->data_directory);
flower_release_snd = Mix_LoadWAV(fname);
snprintf(fname, sizeof(fname), "%s/images/magic/flower_base.png", snprintf(fname, sizeof(fname), "%s/images/magic/flower_base.png",
api->data_directory); api->data_directory);
@ -172,6 +205,8 @@ void flower_click(magic_api * api, int which,
flower_side_first = SIDE_LEFT; flower_side_first = SIDE_LEFT;
flower_drag(api, which, canvas, last, x, y, x, y, update_rect); flower_drag(api, which, canvas, last, x, y, x, y, update_rect);
api->playsound(flower_click_snd, (x * 255) / canvas->w, 255);
} }
// Affect the canvas on release: // Affect the canvas on release:
@ -211,7 +246,7 @@ void flower_release(magic_api * api, int which,
update_rect->w = canvas->w; update_rect->w = canvas->w;
update_rect->h = canvas->h; update_rect->h = canvas->h;
api->playsound(flower_snd, (x * 255) / canvas->w, 255); /* FIXME: Distance? */ api->playsound(flower_release_snd, (x * 255) / canvas->w, 255);
} }
@ -410,8 +445,11 @@ void flower_drawstalk(magic_api * api, SDL_Surface * canvas,
void flower_shutdown(magic_api * api) void flower_shutdown(magic_api * api)
{ {
if (flower_snd != NULL) if (flower_click_snd != NULL)
Mix_FreeChunk(flower_snd); Mix_FreeChunk(flower_click_snd);
if (flower_release_snd != NULL)
Mix_FreeChunk(flower_release_snd);
if (flower_base != NULL) if (flower_base != NULL)
SDL_FreeSurface(flower_base); SDL_FreeSurface(flower_base);

View file

@ -1,3 +1,32 @@
/*
foam.c
Foam Magic Tool Plugin
Tux Paint - A simple drawing program for children.
Copyright (c) 2002-2007 by Bill Kendrick and others; see AUTHORS.txt
bill@newbreedsoftware.com
http://www.tuxpaint.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
Last updated: August 7, 2007
$Id$
*/
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <libintl.h> #include <libintl.h>
@ -30,7 +59,7 @@ int foam_init(magic_api * api)
char fname[1024]; char fname[1024];
SDL_Surface * foam_data; SDL_Surface * foam_data;
snprintf(fname, sizeof(fname), "%s/sounds/magic/foam.wav", snprintf(fname, sizeof(fname), "%s/sounds/magic/foam.ogg",
api->data_directory); api->data_directory);
foam_snd = Mix_LoadWAV(fname); foam_snd = Mix_LoadWAV(fname);
@ -115,7 +144,7 @@ void foam_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_Rect * update_rect)
{ {
api->line(which, canvas, last, ox, oy, x, y, 1, do_foam); api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_foam);
foam_release(api, which, canvas, last, x, y, update_rect); foam_release(api, which, canvas, last, x, y, update_rect);

View file

@ -1,3 +1,32 @@
/*
glasstile.c
Glass Tile Magic Tool Plugin
Tux Paint - A simple drawing program for children.
Copyright (c) 2002-2007 by Bill Kendrick and others; see AUTHORS.txt
bill@newbreedsoftware.com
http://www.tuxpaint.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
Last updated: August 7, 2007
$Id$
*/
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <libintl.h> #include <libintl.h>
@ -21,7 +50,7 @@ int glasstile_init(magic_api * api)
{ {
char fname[1024]; char fname[1024];
snprintf(fname, sizeof(fname), "%s/sounds/magic/glasstile.wav", snprintf(fname, sizeof(fname), "%s/sounds/magic/glasstile.ogg",
api->data_directory); api->data_directory);
glasstile_snd = Mix_LoadWAV(fname); glasstile_snd = Mix_LoadWAV(fname);
@ -157,7 +186,7 @@ void glasstile_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_Rect * update_rect)
{ {
api->line(which, canvas, last, ox, oy, x, y, 1, do_glasstile); api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_glasstile);
update_rect->x = 0; update_rect->x = 0;
update_rect->y = 0; update_rect->y = 0;

View file

@ -1,3 +1,33 @@
/*
grass.c
Grass Magic Tool Plugin
Tux Paint - A simple drawing program for children.
by Albert Cahalan <albert@users.sf.net>
Copyright (c) 2002-2007 by Bill Kendrick and others; see AUTHORS.txt
bill@newbreedsoftware.com
http://www.tuxpaint.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
Last updated: August 7, 2007
$Id$
*/
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <libintl.h> #include <libintl.h>
@ -74,7 +104,7 @@ 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) SDL_Rect * update_rect)
{ {
api->line(which, canvas, last, ox, oy, x, y, 4, do_grass); api->line((void *) api, which, canvas, last, ox, oy, x, y, 4, do_grass);
if (ox > x) { int tmp = ox; ox = x; x = tmp; } if (ox > x) { int tmp = ox; ox = x; x = tmp; }
if (oy > y) { int tmp = oy; oy = y; y = tmp; } if (oy > y) { int tmp = oy; oy = y; y = tmp; }

View file

@ -1,3 +1,32 @@
/*
kalidescope.c
Kaleidoscope Magic Tool Plugin
Tux Paint - A simple drawing program for children.
Copyright (c) 2002-2007 by Bill Kendrick and others; see AUTHORS.txt
bill@newbreedsoftware.com
http://www.tuxpaint.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
Last updated: August 7, 2007
$Id$
*/
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <libintl.h> #include <libintl.h>
@ -89,7 +118,7 @@ void kalidescope_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_Rect * update_rect)
{ {
api->line(which, canvas, last, ox, oy, x, y, 1, do_kalidescope); api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_kalidescope);
update_rect->x = 0; update_rect->x = 0;
update_rect->y = 0; update_rect->y = 0;

View file

@ -1,3 +1,32 @@
/*
metalpaint.c
Metal Paint Magic Tool Plugin
Tux Paint - A simple drawing program for children.
Copyright (c) 2002-2007 by Bill Kendrick and others; see AUTHORS.txt
bill@newbreedsoftware.com
http://www.tuxpaint.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
Last updated: August 7, 2007
$Id$
*/
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <libintl.h> #include <libintl.h>
@ -96,7 +125,7 @@ void metalpaint_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_Rect * update_rect)
{ {
api->line(which, canvas, last, ox, oy, x, y, 1, do_metalpaint); api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_metalpaint);
if (ox > x) { int tmp = ox; ox = x; x = tmp; } if (ox > x) { int tmp = ox; ox = x; x = tmp; }
if (oy > y) { int tmp = oy; oy = y; y = tmp; } if (oy > y) { int tmp = oy; oy = y; y = tmp; }

View file

@ -1,3 +1,32 @@
/*
mirror_flip.c
Mirror and Flip Magic Tools Plugin
Tux Paint - A simple drawing program for children.
Copyright (c) 2002-2007 by Bill Kendrick and others; see AUTHORS.txt
bill@newbreedsoftware.com
http://www.tuxpaint.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
Last updated: August 7, 2007
$Id$
*/
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <libintl.h> #include <libintl.h>

View file

@ -1,3 +1,32 @@
/*
negative.c
Negative Magic Tool Plugin
Tux Paint - A simple drawing program for children.
Copyright (c) 2002-2007 by Bill Kendrick and others; see AUTHORS.txt
bill@newbreedsoftware.com
http://www.tuxpaint.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
Last updated: August 7, 2007
$Id$
*/
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <libintl.h> #include <libintl.h>
@ -86,7 +115,7 @@ void negative_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_LockSurface(last); SDL_LockSurface(last);
SDL_LockSurface(canvas); SDL_LockSurface(canvas);
api->line(which, canvas, last, ox, oy, x, y, 1, do_negative); api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_negative);
if (ox > x) { int tmp = ox; ox = x; x = tmp; } if (ox > x) { int tmp = ox; ox = x; x = tmp; }
if (oy > y) { int tmp = oy; oy = y; y = tmp; } if (oy > y) { int tmp = oy; oy = y; y = tmp; }

View file

@ -1,3 +1,32 @@
/*
rainbow.c
Rainbow Magic Tool Plugin
Tux Paint - A simple drawing program for children.
Copyright (c) 2002-2007 by Bill Kendrick and others; see AUTHORS.txt
bill@newbreedsoftware.com
http://www.tuxpaint.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
Last updated: August 7, 2007
$Id$
*/
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <libintl.h> #include <libintl.h>
@ -118,7 +147,7 @@ void rainbow_drag(magic_api * api, int which, SDL_Surface * canvas,
rainbow_hexes[rainbow_color][1], rainbow_hexes[rainbow_color][1],
rainbow_hexes[rainbow_color][2]); rainbow_hexes[rainbow_color][2]);
api->line(which, canvas, last, ox, oy, x, y, 1, rainbow_linecb); api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, rainbow_linecb);
if (ox > x) { int tmp = ox; ox = x; x = tmp; } if (ox > x) { int tmp = ox; ox = x; x = tmp; }
if (oy > y) { int tmp = oy; oy = y; y = tmp; } if (oy > y) { int tmp = oy; oy = y; y = tmp; }

View file

@ -1,3 +1,32 @@
/*
ripples.c
Ripples Magic Tool Plugin
Tux Paint - A simple drawing program for children.
Copyright (c) 2002-2007 by Bill Kendrick and others; see AUTHORS.txt
bill@newbreedsoftware.com
http://www.tuxpaint.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
Last updated: August 7, 2007
$Id$
*/
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <libintl.h> #include <libintl.h>
@ -23,7 +52,7 @@ int ripples_init(magic_api * api)
{ {
char fname[1024]; char fname[1024];
snprintf(fname, sizeof(fname), "%s/sounds/magic/ripples.wav", snprintf(fname, sizeof(fname), "%s/sounds/magic/ripples.ogg",
api->data_directory); api->data_directory);
ripples_snd = Mix_LoadWAV(fname); ripples_snd = Mix_LoadWAV(fname);
@ -109,7 +138,7 @@ void ripples_click(magic_api * api, int which,
ripples_brite = (ripples_z * 20 * deg_sin(d + 45)) / ((fli / 4) + 1); ripples_brite = (ripples_z * 20 * deg_sin(d + 45)) / ((fli / 4) + 1);
api->line(which, canvas, last, ox, oy, nx, ny, 1, ripples_linecb); api->line((void *) api, which, canvas, last, ox, oy, nx, ny, 1, ripples_linecb);
ox = nx; ox = nx;
oy = ny; oy = ny;
@ -120,6 +149,8 @@ void ripples_click(magic_api * api, int which,
update_rect->y = y - 100; update_rect->y = y - 100;
update_rect->w = 200; update_rect->w = 200;
update_rect->h = 200; update_rect->h = 200;
api->playsound(ripples_snd, (x * 255) / api->canvas_w, 255);
} }
// Affect the canvas on release: // Affect the canvas on release:

View file

@ -1,3 +1,33 @@
/*
smudge.c
Magic Tool Plugin
Tux Paint - A simple drawing program for children.
by Albert Cahalan <albert@users.sf.net>
Copyright (c) 2002-2007 by Bill Kendrick and others; see AUTHORS.txt
bill@newbreedsoftware.com
http://www.tuxpaint.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
Last updated: August 7, 2007
$Id$
*/
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <libintl.h> #include <libintl.h>
@ -97,7 +127,7 @@ 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) SDL_Rect * update_rect)
{ {
api->line(which, canvas, last, ox, oy, x, y, 1, do_smudge); api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_smudge);
api->playsound(smudge_snd, (x * 255) / canvas->w, 255); api->playsound(smudge_snd, (x * 255) / canvas->w, 255);

View file

@ -1,3 +1,32 @@
/*
sparkles.c
Sparkles Magic Tool Plugin
Tux Paint - A simple drawing program for children.
Copyright (c) 2002-2007 by Bill Kendrick and others; see AUTHORS.txt
bill@newbreedsoftware.com
http://www.tuxpaint.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
Last updated: August 7, 2007
$Id$
*/
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <libintl.h> #include <libintl.h>
@ -8,7 +37,7 @@
/* Our globals: */ /* Our globals: */
Mix_Chunk * sparkles_snd; Mix_Chunk * sparkles1_snd, * sparkles2_snd;
Uint8 sparkles_r, sparkles_g, sparkles_b; Uint8 sparkles_r, sparkles_g, sparkles_b;
@ -20,9 +49,13 @@ int sparkles_init(magic_api * api)
{ {
char fname[1024]; char fname[1024];
snprintf(fname, sizeof(fname), "%s/sounds/magic/sparkles.wav", snprintf(fname, sizeof(fname), "%s/sounds/magic/sparkles1.wav",
api->data_directory); api->data_directory);
sparkles_snd = Mix_LoadWAV(fname); sparkles1_snd = Mix_LoadWAV(fname);
snprintf(fname, sizeof(fname), "%s/sounds/magic/sparkles2.wav",
api->data_directory);
sparkles2_snd = Mix_LoadWAV(fname);
return(1); return(1);
} }
@ -97,7 +130,7 @@ void sparkles_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_Rect * update_rect)
{ {
api->line(which, canvas, last, ox, oy, x, y, 1, do_sparkles); api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_sparkles);
if (ox > x) { int tmp = ox; ox = x; x = tmp; } if (ox > x) { int tmp = ox; ox = x; x = tmp; }
if (oy > y) { int tmp = oy; oy = y; y = tmp; } if (oy > y) { int tmp = oy; oy = y; y = tmp; }
@ -107,7 +140,13 @@ void sparkles_drag(magic_api * api, int which, SDL_Surface * canvas,
update_rect->w = (x + 8) - update_rect->x; update_rect->w = (x + 8) - update_rect->x;
update_rect->h = (y + 8) - update_rect->h; update_rect->h = (y + 8) - update_rect->h;
api->playsound(sparkles_snd, (x * 255) / canvas->w, 255); if ((rand() % 10) == 0)
{
if ((rand() % 10) < 5)
api->playsound(sparkles1_snd, (x * 255) / canvas->w, 255);
else
api->playsound(sparkles2_snd, (x * 255) / canvas->w, 255);
}
} }
// Affect the canvas on click: // Affect the canvas on click:
@ -128,8 +167,10 @@ void sparkles_release(magic_api * api, int which,
// No setup happened: // No setup happened:
void sparkles_shutdown(magic_api * api) void sparkles_shutdown(magic_api * api)
{ {
if (sparkles_snd != NULL) if (sparkles1_snd != NULL)
Mix_FreeChunk(sparkles_snd); Mix_FreeChunk(sparkles1_snd);
if (sparkles2_snd != NULL)
Mix_FreeChunk(sparkles2_snd);
} }
// Record the color from Tux Paint: // Record the color from Tux Paint:

View file

@ -1,3 +1,32 @@
/*
tint.c
Tint Magic Tool Plugin
Tux Paint - A simple drawing program for children.
Copyright (c) 2002-2007 by Bill Kendrick and others; see AUTHORS.txt
bill@newbreedsoftware.com
http://www.tuxpaint.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
Last updated: August 7, 2007
$Id$
*/
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <libintl.h> #include <libintl.h>
@ -101,7 +130,7 @@ 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) SDL_Rect * update_rect)
{ {
api->line(which, canvas, last, ox, oy, x, y, 1, do_tint); api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_tint);
if (ox > x) { int tmp = ox; ox = x; x = tmp; } if (ox > x) { int tmp = ox; ox = x; x = tmp; }
if (oy > y) { int tmp = oy; oy = y; y = tmp; } if (oy > y) { int tmp = oy; oy = y; y = tmp; }

View file

@ -1,3 +1,32 @@
/*
waves.c
Waves Magic Tool Plugin
Tux Paint - A simple drawing program for children.
Copyright (c) 2002-2007 by Bill Kendrick and others; see AUTHORS.txt
bill@newbreedsoftware.com
http://www.tuxpaint.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
Last updated: August 7, 2007
$Id$
*/
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <libintl.h> #include <libintl.h>
@ -105,6 +134,7 @@ void waves_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last, SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect) int x, int y, SDL_Rect * update_rect)
{ {
api->playsound(waves_snd, 128, 255);
} }
// No setup happened: // No setup happened:

View file

@ -1,11 +1,11 @@
.\" tp-magic-config - 2007.08.02 .\" tp-magic-config - 2007.08.07
.TH TP-MAGIC-CONFIG 1 "02 August 2007" "2007.08.02" "tp-magic-config" .TH TP-MAGIC-CONFIG 1 "07 August 2007" "2007.08.07" "tp-magic-config"
.SH NAME .SH NAME
tp-magic-config -- Helps creating 'Magic' tool plugins for Tux Paint(1) tp-magic-config -- Helps creating 'Magic' tool plugins for Tux Paint(1)
.SH SYNOPSYS .SH SYNOPSYS
.TP 16 .TP 16
.B tp-magic-config [\-\-apiversion | \-\-version | \-\-cflags | \-\-pluginprefix | \-\-plugindocprefix | \-\-dataprefix] .B tp-magic-config [\-\-apiversion | \-\-version | \-\-cflags | \-\-pluginprefix | \-\-plugindocprefix | \-\-dataprefix | \-\-localpluginprefix | \-\-localdataprefix]
.SH DESCRIPTION .SH DESCRIPTION
\fItp-magic-config\fP is a simple shell script that responds with various \fItp-magic-config\fP is a simple shell script that responds with various
@ -29,8 +29,14 @@ compiler where it can find the plugin API header file, "tp_magic_config.h",
that plugins must #include.) that plugins must #include.)
.TP 8 .TP 8
.B \-\-pluginprefix .B \-\-pluginprefix
Outputs the directory where the installed copy of \fITux Paint\fP expects Outputs the system directory where the installed copy of \fITux Paint\fP expects
to find 'Magic' tool plugins (".so" shared objects). to find 'Magic' tool plugins (".so" shared objects).
(e.g., "/usr/share/tuxpaint/plugins")
.TP 8
.B \-\-localpluginprefix
Outputs the user directory where the installed copy of \fITux Paint\fP expects
to find 'Magic' tool plugins (".so" shared objects).
(e.g., "/home/username/.tuxpaint/plugins")
.TP 8 .TP 8
.B \-\-plugindocprefix .B \-\-plugindocprefix
Outputs the directory where the installed copy of \fITux Paint\fP expects Outputs the directory where the installed copy of \fITux Paint\fP expects
@ -39,12 +45,19 @@ to find documentation for 'Magic' tool plugins (".html" and ".txt" files).
under the section on "Magic" tools. under the section on "Magic" tools.
.TP 8 .TP 8
.B \-\-dataprefix .B \-\-dataprefix
Outputs the directory where the installed copy of \fITux Paint\fP keeps its Outputs the system directory where the installed copy of \fITux Paint\fP keeps
global data files (e.g., "/usr/share/tuxpaint/"). This is the same value that its global data files (e.g., "/usr/share/tuxpaint/"). This is the same value
plugins will receive in the "data_directory" string within the that plugins installed system-wide will receive in the "data_directory" string
"magic_api" structure sent to the plugins' functions. within the "magic_api" structure sent to the plugins' functions.
.TP 8
.B \-\-localdataprefix
Outputs the user directory where the installed copy of \fITux Paint\fP
expects plugins to install their local data files.
(e.g., "/home/username/.tuxpaint/plugins/data"). This is the same value
that plugins installed locally will receive in the "data_directory" string
within the "magic_api" structure sent to the plugins' functions.
.SH SHELL EXAMPLES .SH SYSTEM-WIDE SHELL EXAMPLES
$ gcc -shared `tp-magic-config --cflags` my_plugin.c -o my_plugin.so $ gcc -shared `tp-magic-config --cflags` my_plugin.c -o my_plugin.so
.br .br
# cp my_plugin.so `tp-magic-config \-\-pluginprefix` # cp my_plugin.so `tp-magic-config \-\-pluginprefix`
@ -55,7 +68,18 @@ $ gcc -shared `tp-magic-config --cflags` my_plugin.c -o my_plugin.so
.br .br
# cp my_plugin.txt `tp-magic-config \-\-plugindocrefix` # cp my_plugin.txt `tp-magic-config \-\-plugindocrefix`
.SH MAKEFILE EXAMPLE .SH LOCAL SHELL EXAMPLES
$ gcc -shared `tp-magic-config --cflags` my_plugin.c -o my_plugin.so
.br
$ mkdir -p `tp-magic-config \-\-localpluginprefix`
.br
$ cp my_plugin.so `tp-magic-config \-\-localpluginprefix`
.br
$ mkdir -p `tp-magic-config \-\-localdataprefix`/images/magic
.br
$ cp my_plugin_icon.png `tp-magic-config \-\-localdataprefix`/images/magic
.SH SYSTEM-WIDE MAKEFILE EXAMPLE
MAGIC_CFLAGS=$(shell tp-magic-config --cflags) MAGIC_CFLAGS=$(shell tp-magic-config --cflags)
.br .br
MAGIC_PREFIX=$(shell tp-magic-config --pluginprefix) MAGIC_PREFIX=$(shell tp-magic-config --pluginprefix)

View file

@ -50,10 +50,18 @@ if [ $# -ne 0 ]; then
echo "__DATAPREFIX__" echo "__DATAPREFIX__"
exit exit
fi fi
if [ $1 = "--localdataprefix" ]; then
echo "$HOME/.tuxpaint/plugins/data"
exit
fi
if [ $1 = "--pluginprefix" ]; then if [ $1 = "--pluginprefix" ]; then
echo "__PLUGINPREFIX__" echo "__PLUGINPREFIX__"
exit exit
fi fi
if [ $1 = "--localpluginprefix" ]; then
echo "$HOME/.tuxpaint/plugins"
exit
fi
if [ $1 = "--plugindocprefix" ]; then if [ $1 = "--plugindocprefix" ]; then
echo "__PLUGINDOCPREFIX__" echo "__PLUGINDOCPREFIX__"
exit exit

View file

@ -91,9 +91,10 @@ typedef struct magic_api_t {
/* Asks Tux Paint to calculate a line between (x1,y1) and (x2,y2); /* Asks Tux Paint to calculate a line between (x1,y1) and (x2,y2);
every 'step' iterations, it will call your callback function every 'step' iterations, it will call your callback function
(which must accept a 'which' integer for which tool is being used, (which must accept a 'magic_api *' Magic API pointer and 'which' integer
'last' and current ('canvas') SDL_Surfaces, and an (x,y) position) */ for which tool is being used, the 'last' and current ('canvas')
void (*line)(int, SDL_Surface *, SDL_Surface *, int, int, int, int, int, void (*)(void *, int, SDL_Surface *, SDL_Surface *, int, int)); SDL_Surfaces, and an (x,y) position) */
void (*line)(void *, int, SDL_Surface *, SDL_Surface *, int, int, int, int, int, void (*)(void *, int, SDL_Surface *, SDL_Surface *, int, int));
/* Returns whether the mouse button is down */ /* Returns whether the mouse button is down */
int (*button_down)(void); int (*button_down)(void);

View file

@ -22,7 +22,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt) (See COPYING.txt)
June 14, 2002 - July 24, 2007 June 14, 2002 - August 7, 2007
$Id$ $Id$
*/ */
@ -880,6 +880,7 @@ typedef struct magic_funcs_s {
typedef struct magic_s { typedef struct magic_s {
int place;
int handle_idx; // Index to magic funcs for each magic tool (shared objs may report more than 1 tool) int handle_idx; // Index to magic funcs for each magic tool (shared objs may report more than 1 tool)
int idx; // Index to magic tools within shared objects (shared objs may report more than 1 tool) int idx; // Index to magic tools within shared objects (shared objs may report more than 1 tool)
int colors; // Whether magic tool accepts colors int colors; // Whether magic tool accepts colors
@ -899,7 +900,13 @@ magic_funcs_t magic_funcs[512]; // Pointer to shared objects' functions
magic_t magics[512]; magic_t magics[512];
static int num_magics; // How many magic tools were loaded (note: shared objs may report more than 1 tool) static int num_magics; // How many magic tools were loaded (note: shared objs may report more than 1 tool)
magic_api * magic_api_struct; // Pointer to our internal functions; passed to shared object's functions when we call them enum {
MAGIC_PLACE_GLOBAL,
MAGIC_PLACE_LOCAL,
NUM_MAGIC_PLACES
};
magic_api * magic_api_struct[NUM_MAGIC_PLACES]; // Pointer to our internal functions; passed to shared object's functions when we call them
#if !defined(WIN32) && !defined(__APPLE__) && !defined(__BEOS__) #if !defined(WIN32) && !defined(__APPLE__) && !defined(__BEOS__)
@ -1489,7 +1496,8 @@ int magic_sort(const void * a, const void * b);
Mix_Chunk * magic_current_snd_ptr; Mix_Chunk * magic_current_snd_ptr;
void magic_playsound(Mix_Chunk * snd, int left_right, int up_down); void magic_playsound(Mix_Chunk * snd, int left_right, int up_down);
void magic_line_func(int which, SDL_Surface * canvas, SDL_Surface * last, void magic_line_func(void * mapi,
int which, SDL_Surface * canvas, SDL_Surface * last,
int x1, int y1, int x2, int y2, int step, int x1, int y1, int x2, int y2, int step,
void (*cb)(void *, int, SDL_Surface *, SDL_Surface *, void (*cb)(void *, int, SDL_Surface *, SDL_Surface *,
int, int)); int, int));
@ -2401,7 +2409,7 @@ static void mainloop(void)
draw_colors(magics[cur_magic].colors); draw_colors(magics[cur_magic].colors);
if (magics[cur_magic].colors) if (magics[cur_magic].colors)
magic_funcs[magics[cur_magic].handle_idx].set_color( magic_funcs[magics[cur_magic].handle_idx].set_color(
magic_api_struct, magic_api_struct[magics[cur_magic].place],
color_hexes[cur_color][0], color_hexes[cur_color][0],
color_hexes[cur_color][1], color_hexes[cur_color][1],
color_hexes[cur_color][2]); color_hexes[cur_color][2]);
@ -3027,7 +3035,7 @@ static void mainloop(void)
if (magics[cur_magic].colors) if (magics[cur_magic].colors)
magic_funcs[magics[cur_magic].handle_idx].set_color( magic_funcs[magics[cur_magic].handle_idx].set_color(
magic_api_struct, magic_api_struct[magics[cur_magic].place],
color_hexes[cur_color][0], color_hexes[cur_color][0],
color_hexes[cur_color][1], color_hexes[cur_color][1],
color_hexes[cur_color][2]); color_hexes[cur_color][2]);
@ -3100,7 +3108,7 @@ static void mainloop(void)
do_render_cur_text(0); do_render_cur_text(0);
else if (cur_tool == TOOL_MAGIC) else if (cur_tool == TOOL_MAGIC)
magic_funcs[magics[cur_magic].handle_idx].set_color( magic_funcs[magics[cur_magic].handle_idx].set_color(
magic_api_struct, magic_api_struct[magics[cur_magic].place],
color_hexes[cur_color][0], color_hexes[cur_color][0],
color_hexes[cur_color][1], color_hexes[cur_color][1],
color_hexes[cur_color][2]); color_hexes[cur_color][2]);
@ -3231,7 +3239,7 @@ static void mainloop(void)
reset_touched(); reset_touched();
magic_funcs[magics[cur_magic].handle_idx].click(magic_api_struct, magic_funcs[magics[cur_magic].handle_idx].click(magic_api_struct[magics[cur_magic].place],
magics[cur_magic].idx, magics[cur_magic].idx,
canvas, last, canvas, last,
old_x, old_y, old_x, old_y,
@ -3579,7 +3587,7 @@ static void mainloop(void)
update_rect.w = 0; update_rect.w = 0;
update_rect.h = 0; update_rect.h = 0;
magic_funcs[magics[cur_magic].handle_idx].release(magic_api_struct, magic_funcs[magics[cur_magic].handle_idx].release(magic_api_struct[magics[cur_magic].place],
magics[cur_magic].idx, magics[cur_magic].idx,
canvas, last, canvas, last,
old_x, old_y, old_x, old_y,
@ -3815,7 +3823,7 @@ static void mainloop(void)
update_rect.w = 0; update_rect.w = 0;
update_rect.h = 0; update_rect.h = 0;
magic_funcs[magics[cur_magic].handle_idx].drag(magic_api_struct, magic_funcs[magics[cur_magic].handle_idx].drag(magic_api_struct[magics[cur_magic].place],
magics[cur_magic].idx, magics[cur_magic].idx,
canvas, last, canvas, last,
old_x, old_y, old_x, old_y,
@ -8179,7 +8187,11 @@ static void draw_brushes(void)
if (brush < num_brushes) if (brush < num_brushes)
{ {
src.x = 0; if (brushes_directional[brush])
src.x = (img_brushes[brush]->w / abs(brushes_frames[brush])) / 3;
else
src.x = 0;
src.y = brushes_directional[brush] ? (img_brushes[brush]->h / 3) : 0; src.y = brushes_directional[brush] ? (img_brushes[brush]->h / 3) : 0;
src.w = (img_brushes[brush]->w / abs(brushes_frames[brush])) / src.w = (img_brushes[brush]->w / abs(brushes_frames[brush])) /
@ -11667,7 +11679,7 @@ static void cleanup(void)
#endif #endif
for (i = 0; i < num_plugin_files; i++) for (i = 0; i < num_plugin_files; i++)
magic_funcs[i].shutdown(magic_api_struct); magic_funcs[i].shutdown(magic_api_struct[magics[cur_magic].place]);
free_cursor(&cursor_hand); free_cursor(&cursor_hand);
free_cursor(&cursor_arrow); free_cursor(&cursor_arrow);
@ -16478,9 +16490,11 @@ float pick_best_scape(unsigned int orig_w, unsigned int orig_h,
#endif #endif
void load_magic_plugins(void) void load_magic_plugins(void)
{ {
int res, n, i; int res, n, i, plc;
char * place;
int err; int err;
DIR *d; DIR *d;
struct dirent *f; struct dirent *f;
@ -16491,292 +16505,310 @@ void load_magic_plugins(void)
num_plugin_files = 0; num_plugin_files = 0;
num_magics = 0; num_magics = 0;
for (plc = 0; plc < NUM_MAGIC_PLACES; plc++)
{
if (plc == MAGIC_PLACE_GLOBAL)
place = strdup(MAGIC_PREFIX);
else if (plc == MAGIC_PLACE_LOCAL)
place = get_fname("plugins/", DIR_DATA);
else
continue; // Huh?
#ifdef DEBUG #ifdef DEBUG
printf("\n"); printf("\n");
printf("Loading magic plug-ins from %s\n", MAGIC_PREFIX); printf("Loading magic plug-ins from %s\n", place);
fflush(stdout); fflush(stdout);
#endif #endif
/* Set magic API hooks: */
magic_api_struct = (magic_api *) malloc(sizeof(magic_api));
magic_api_struct->tp_version = strdup(VER_VERSION);
magic_api_struct->data_directory = strdup(DATA_PREFIX);
magic_api_struct->update_progress_bar = update_progress_bar;
magic_api_struct->sRGB_to_linear = magic_sRGB_to_linear;
magic_api_struct->linear_to_sRGB = magic_linear_to_sRGB;
magic_api_struct->in_circle = in_circle_rad;
magic_api_struct->getpixel = getpixels[canvas->format->BytesPerPixel];
magic_api_struct->putpixel = putpixels[canvas->format->BytesPerPixel];
magic_api_struct->line = magic_line_func;
magic_api_struct->playsound = magic_playsound;
magic_api_struct->special_notify = special_notify;
magic_api_struct->button_down = magic_button_down;
magic_api_struct->rgbtohsv = rgbtohsv;
magic_api_struct->hsvtorgb = hsvtorgb;
magic_api_struct->canvas_w = canvas->w;
magic_api_struct->canvas_h = canvas->h;
magic_api_struct->scale = magic_scale;
magic_api_struct->touched = magic_touched;
d = opendir(MAGIC_PREFIX);
if (d != NULL)
{
/* Gather list of files (for sorting): */ /* Gather list of files (for sorting): */
do d = opendir(place);
if (d != NULL)
{ {
f = readdir(d); /* Set magic API hooks: */
if (f != NULL) magic_api_struct[plc] = (magic_api *) malloc(sizeof(magic_api));
magic_api_struct[plc]->tp_version = strdup(VER_VERSION);
if (plc == MAGIC_PLACE_GLOBAL)
magic_api_struct[plc]->data_directory = strdup(DATA_PREFIX);
else if (plc == MAGIC_PLACE_LOCAL)
magic_api_struct[plc]->data_directory = get_fname("plugins/data/", DIR_DATA);
else
magic_api_struct[plc]->data_directory = strdup("./");
magic_api_struct[plc]->update_progress_bar = update_progress_bar;
magic_api_struct[plc]->sRGB_to_linear = magic_sRGB_to_linear;
magic_api_struct[plc]->linear_to_sRGB = magic_linear_to_sRGB;
magic_api_struct[plc]->in_circle = in_circle_rad;
magic_api_struct[plc]->getpixel = getpixels[canvas->format->BytesPerPixel];
magic_api_struct[plc]->putpixel = putpixels[canvas->format->BytesPerPixel];
magic_api_struct[plc]->line = magic_line_func;
magic_api_struct[plc]->playsound = magic_playsound;
magic_api_struct[plc]->special_notify = special_notify;
magic_api_struct[plc]->button_down = magic_button_down;
magic_api_struct[plc]->rgbtohsv = rgbtohsv;
magic_api_struct[plc]->hsvtorgb = hsvtorgb;
magic_api_struct[plc]->canvas_w = canvas->w;
magic_api_struct[plc]->canvas_h = canvas->h;
magic_api_struct[plc]->scale = magic_scale;
magic_api_struct[plc]->touched = magic_touched;
do
{ {
if (f->d_type == DT_REG) f = readdir(d);
if (f != NULL)
{ {
snprintf(fname, sizeof(fname), "%s%s", MAGIC_PREFIX, f->d_name); if (f->d_type == DT_REG)
{
snprintf(fname, sizeof(fname), "%s%s", place, f->d_name);
/* Get just the name of the object (e.g., "negative"), w/o filename /* Get just the name of the object (e.g., "negative"), w/o filename
extension: */ extension: */
strcpy(objname, f->d_name); strcpy(objname, f->d_name);
strcpy(strchr(objname, '.'), ""); strcpy(strchr(objname, '.'), "");
magic_handle[num_plugin_files] = SDL_LoadObject(fname); magic_handle[num_plugin_files] = SDL_LoadObject(fname);
if (magic_handle[num_plugin_files] != NULL) if (magic_handle[num_plugin_files] != NULL)
{ {
#ifdef DEBUG #ifdef DEBUG
printf("loading: %s\n", fname); printf("loading: %s\n", fname);
fflush(stdout); fflush(stdout);
#endif #endif
snprintf(funcname, sizeof(funcname), "%s_%s", objname, snprintf(funcname, sizeof(funcname), "%s_%s", objname,
"get_tool_count"); "get_tool_count");
magic_funcs[num_plugin_files].get_tool_count = magic_funcs[num_plugin_files].get_tool_count =
SDL_LoadFunction(magic_handle[num_plugin_files], funcname); SDL_LoadFunction(magic_handle[num_plugin_files], funcname);
snprintf(funcname, sizeof(funcname), "%s_%s", objname, snprintf(funcname, sizeof(funcname), "%s_%s", objname,
"get_name"); "get_name");
magic_funcs[num_plugin_files].get_name = magic_funcs[num_plugin_files].get_name =
SDL_LoadFunction(magic_handle[num_plugin_files], funcname); SDL_LoadFunction(magic_handle[num_plugin_files], funcname);
snprintf(funcname, sizeof(funcname), "%s_%s", objname, snprintf(funcname, sizeof(funcname), "%s_%s", objname,
"get_icon"); "get_icon");
magic_funcs[num_plugin_files].get_icon = magic_funcs[num_plugin_files].get_icon =
SDL_LoadFunction(magic_handle[num_plugin_files], funcname); SDL_LoadFunction(magic_handle[num_plugin_files], funcname);
snprintf(funcname, sizeof(funcname), "%s_%s", objname, snprintf(funcname, sizeof(funcname), "%s_%s", objname,
"get_description"); "get_description");
magic_funcs[num_plugin_files].get_description = magic_funcs[num_plugin_files].get_description =
SDL_LoadFunction(magic_handle[num_plugin_files], funcname); SDL_LoadFunction(magic_handle[num_plugin_files], funcname);
snprintf(funcname, sizeof(funcname), "%s_%s", objname, snprintf(funcname, sizeof(funcname), "%s_%s", objname,
"requires_colors"); "requires_colors");
magic_funcs[num_plugin_files].requires_colors = magic_funcs[num_plugin_files].requires_colors =
SDL_LoadFunction(magic_handle[num_plugin_files], funcname); SDL_LoadFunction(magic_handle[num_plugin_files], funcname);
snprintf(funcname, sizeof(funcname), "%s_%s", objname, snprintf(funcname, sizeof(funcname), "%s_%s", objname,
"set_color"); "set_color");
magic_funcs[num_plugin_files].set_color = magic_funcs[num_plugin_files].set_color =
SDL_LoadFunction(magic_handle[num_plugin_files], funcname); SDL_LoadFunction(magic_handle[num_plugin_files], funcname);
snprintf(funcname, sizeof(funcname), "%s_%s", objname, snprintf(funcname, sizeof(funcname), "%s_%s", objname,
"init"); "init");
magic_funcs[num_plugin_files].init = magic_funcs[num_plugin_files].init =
SDL_LoadFunction(magic_handle[num_plugin_files], funcname); SDL_LoadFunction(magic_handle[num_plugin_files], funcname);
snprintf(funcname, sizeof(funcname), "%s_%s", objname, snprintf(funcname, sizeof(funcname), "%s_%s", objname,
"api_version"); "api_version");
magic_funcs[num_plugin_files].api_version = magic_funcs[num_plugin_files].api_version =
SDL_LoadFunction(magic_handle[num_plugin_files], funcname); SDL_LoadFunction(magic_handle[num_plugin_files], funcname);
snprintf(funcname, sizeof(funcname), "%s_%s", objname, snprintf(funcname, sizeof(funcname), "%s_%s", objname,
"shutdown"); "shutdown");
magic_funcs[num_plugin_files].shutdown = magic_funcs[num_plugin_files].shutdown =
SDL_LoadFunction(magic_handle[num_plugin_files], funcname); SDL_LoadFunction(magic_handle[num_plugin_files], funcname);
snprintf(funcname, sizeof(funcname), "%s_%s", objname, snprintf(funcname, sizeof(funcname), "%s_%s", objname,
"click"); "click");
magic_funcs[num_plugin_files].click = magic_funcs[num_plugin_files].click =
SDL_LoadFunction(magic_handle[num_plugin_files], funcname); SDL_LoadFunction(magic_handle[num_plugin_files], funcname);
snprintf(funcname, sizeof(funcname), "%s_%s", objname, snprintf(funcname, sizeof(funcname), "%s_%s", objname,
"drag"); "drag");
magic_funcs[num_plugin_files].drag = magic_funcs[num_plugin_files].drag =
SDL_LoadFunction(magic_handle[num_plugin_files], funcname); SDL_LoadFunction(magic_handle[num_plugin_files], funcname);
snprintf(funcname, sizeof(funcname), "%s_%s", objname, snprintf(funcname, sizeof(funcname), "%s_%s", objname,
"release"); "release");
magic_funcs[num_plugin_files].release = magic_funcs[num_plugin_files].release =
SDL_LoadFunction(magic_handle[num_plugin_files], funcname); SDL_LoadFunction(magic_handle[num_plugin_files], funcname);
#ifdef DEBUG #ifdef DEBUG
printf("get_tool_count = 0x%x\n", printf("get_tool_count = 0x%x\n",
(int) magic_funcs[num_plugin_files].get_tool_count); (int) magic_funcs[num_plugin_files].get_tool_count);
printf("get_name = 0x%x\n", printf("get_name = 0x%x\n",
(int) magic_funcs[num_plugin_files].get_name); (int) magic_funcs[num_plugin_files].get_name);
printf("get_icon = 0x%x\n", printf("get_icon = 0x%x\n",
(int) magic_funcs[num_plugin_files].get_icon); (int) magic_funcs[num_plugin_files].get_icon);
printf("get_description = 0x%x\n", printf("get_description = 0x%x\n",
(int) magic_funcs[num_plugin_files].get_description); (int) magic_funcs[num_plugin_files].get_description);
printf("requires_colors = 0x%x\n", printf("requires_colors = 0x%x\n",
(int) magic_funcs[num_plugin_files].requires_colors); (int) magic_funcs[num_plugin_files].requires_colors);
printf("set_color = 0x%x\n", printf("set_color = 0x%x\n",
(int) magic_funcs[num_plugin_files].set_color); (int) magic_funcs[num_plugin_files].set_color);
printf("init = 0x%x\n", printf("init = 0x%x\n",
(int) magic_funcs[num_plugin_files].init); (int) magic_funcs[num_plugin_files].init);
printf("api_version = 0x%x\n", printf("api_version = 0x%x\n",
(int) magic_funcs[num_plugin_files].api_version); (int) magic_funcs[num_plugin_files].api_version);
printf("shutdown = 0x%x\n", printf("shutdown = 0x%x\n",
(int) magic_funcs[num_plugin_files].shutdown); (int) magic_funcs[num_plugin_files].shutdown);
printf("click = 0x%x\n", printf("click = 0x%x\n",
(int) magic_funcs[num_plugin_files].click); (int) magic_funcs[num_plugin_files].click);
printf("drag = 0x%x\n", printf("drag = 0x%x\n",
(int) magic_funcs[num_plugin_files].drag); (int) magic_funcs[num_plugin_files].drag);
printf("release = 0x%x\n", printf("release = 0x%x\n",
(int) magic_funcs[num_plugin_files].release); (int) magic_funcs[num_plugin_files].release);
#endif #endif
err = 0; err = 0;
if (magic_funcs[num_plugin_files].get_tool_count == NULL) if (magic_funcs[num_plugin_files].get_tool_count == NULL)
{ {
fprintf(stderr, "Error: plugin %s is missing get_tool_count\n", fprintf(stderr, "Error: plugin %s is missing get_tool_count\n",
fname); fname);
err = 1; err = 1;
} }
if (magic_funcs[num_plugin_files].get_name == NULL) if (magic_funcs[num_plugin_files].get_name == NULL)
{ {
fprintf(stderr, "Error: plugin %s is missing get_name\n", fprintf(stderr, "Error: plugin %s is missing get_name\n",
fname); fname);
err = 1; err = 1;
} }
if (magic_funcs[num_plugin_files].get_icon == NULL) if (magic_funcs[num_plugin_files].get_icon == NULL)
{ {
fprintf(stderr, "Error: plugin %s is missing get_icon\n", fprintf(stderr, "Error: plugin %s is missing get_icon\n",
fname); fname);
err = 1; err = 1;
} }
if (magic_funcs[num_plugin_files].get_description == NULL) if (magic_funcs[num_plugin_files].get_description == NULL)
{ {
fprintf(stderr, "Error: plugin %s is missing get_description\n", fprintf(stderr, "Error: plugin %s is missing get_description\n",
fname); fname);
err = 1; err = 1;
} }
if (magic_funcs[num_plugin_files].requires_colors == NULL) if (magic_funcs[num_plugin_files].requires_colors == NULL)
{ {
fprintf(stderr, "Error: plugin %s is missing requires_colors\n", fprintf(stderr, "Error: plugin %s is missing requires_colors\n",
fname); fname);
err = 1; err = 1;
} }
if (magic_funcs[num_plugin_files].set_color == NULL) if (magic_funcs[num_plugin_files].set_color == NULL)
{ {
fprintf(stderr, "Error: plugin %s is missing set_color\n", fprintf(stderr, "Error: plugin %s is missing set_color\n",
fname); fname);
err = 1; err = 1;
} }
if (magic_funcs[num_plugin_files].init == NULL) if (magic_funcs[num_plugin_files].init == NULL)
{ {
fprintf(stderr, "Error: plugin %s is missing init\n", fprintf(stderr, "Error: plugin %s is missing init\n",
fname); fname);
err = 1; err = 1;
} }
if (magic_funcs[num_plugin_files].shutdown == NULL) if (magic_funcs[num_plugin_files].shutdown == NULL)
{ {
fprintf(stderr, "Error: plugin %s is missing shutdown\n", fprintf(stderr, "Error: plugin %s is missing shutdown\n",
fname); fname);
err = 1; err = 1;
} }
if (magic_funcs[num_plugin_files].click == NULL) if (magic_funcs[num_plugin_files].click == NULL)
{ {
fprintf(stderr, "Error: plugin %s is missing click\n", fprintf(stderr, "Error: plugin %s is missing click\n",
fname); fname);
err = 1; err = 1;
} }
if (magic_funcs[num_plugin_files].release == NULL) if (magic_funcs[num_plugin_files].release == NULL)
{ {
fprintf(stderr, "Error: plugin %s is missing release\n", fprintf(stderr, "Error: plugin %s is missing release\n",
fname); fname);
err = 1; err = 1;
} }
if (magic_funcs[num_plugin_files].drag == NULL) if (magic_funcs[num_plugin_files].drag == NULL)
{ {
fprintf(stderr, "Error: plugin %s is missing drag\n", fprintf(stderr, "Error: plugin %s is missing drag\n",
fname); fname);
err = 1; err = 1;
} }
if (magic_funcs[num_plugin_files].api_version == NULL) if (magic_funcs[num_plugin_files].api_version == NULL)
{ {
fprintf(stderr, "Error: plugin %s is missing api_version\n", fprintf(stderr, "Error: plugin %s is missing api_version\n",
fname); fname);
err = 1; err = 1;
} }
else if (magic_funcs[num_plugin_files].api_version() != TP_MAGIC_API_VERSION) 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); 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; err = 1;
}
if (err)
{
SDL_UnloadObject(magic_handle[num_plugin_files]);
}
else
{
res = magic_funcs[num_plugin_files].init(magic_api_struct);
if (res != 0)
n = magic_funcs[num_plugin_files].get_tool_count(magic_api_struct);
else
{
magic_funcs[num_plugin_files].shutdown(magic_api_struct);
n = 0;
} }
if (err)
if (n == 0) {
{ SDL_UnloadObject(magic_handle[num_plugin_files]);
fprintf(stderr, "Error: plugin %s failed to startup or reported 0 magic tools\n", fname); }
fflush(stderr);
SDL_UnloadObject(magic_handle[num_plugin_files]);
}
else else
{ {
for (i = 0; i < n; i++) res = magic_funcs[num_plugin_files].init(magic_api_struct[plc]);
{
magics[num_magics].idx = i;
magics[num_magics].handle_idx = num_plugin_files;
magics[num_magics].name = magic_funcs[num_plugin_files].get_name(magic_api_struct, i);
magics[num_magics].tip = magic_funcs[num_plugin_files].get_description(magic_api_struct, i);
magics[num_magics].colors = magic_funcs[num_plugin_files].requires_colors(magic_api_struct, i);
magics[num_magics].img_icon = magic_funcs[num_plugin_files].get_icon(magic_api_struct, i); if (res != 0)
n = magic_funcs[num_plugin_files].get_tool_count(magic_api_struct[plc]);
else
{
magic_funcs[num_plugin_files].shutdown(magic_api_struct[plc]);
n = 0;
}
if (n == 0)
{
fprintf(stderr, "Error: plugin %s failed to startup or reported 0 magic tools\n", fname);
fflush(stderr);
SDL_UnloadObject(magic_handle[num_plugin_files]);
}
else
{
for (i = 0; i < n; i++)
{
magics[num_magics].idx = i;
magics[num_magics].place = plc;
magics[num_magics].handle_idx = num_plugin_files;
magics[num_magics].name = magic_funcs[num_plugin_files].get_name(magic_api_struct[plc], i);
magics[num_magics].tip = magic_funcs[num_plugin_files].get_description(magic_api_struct[plc], i);
magics[num_magics].colors = magic_funcs[num_plugin_files].requires_colors(magic_api_struct[plc], i);
magics[num_magics].img_icon = magic_funcs[num_plugin_files].get_icon(magic_api_struct[plc], i);
#ifdef DEBUG #ifdef DEBUG
printf("-- %s\n", magics[num_magics].name); printf("-- %s\n", magics[num_magics].name);
#endif #endif
num_magics++; num_magics++;
} }
num_plugin_files++; num_plugin_files++;
}
} }
} }
} else
else {
{ fprintf(stderr, "Warning: Failed to load object %s: %s\n", fname, SDL_GetError());
fprintf(stderr, "Warning: Failed to load object %s: %s\n", fname, SDL_GetError()); fflush(stderr);
fflush(stderr); }
} }
} }
} }
} while (f != NULL);
while (f != NULL);
closedir(d); closedir(d);
}
} }
@ -16804,7 +16836,8 @@ void update_progress_bar(void)
show_progress_bar(screen); show_progress_bar(screen);
} }
void magic_line_func(int which, SDL_Surface * canvas, SDL_Surface * last, void magic_line_func(void * mapi,
int which, SDL_Surface * canvas, SDL_Surface * last,
int x1, int y1, int x2, int y2, int step, int x1, int y1, int x2, int y2, int step,
void (*cb)(void *, int, SDL_Surface *, SDL_Surface *, void (*cb)(void *, int, SDL_Surface *, SDL_Surface *,
int, int)) int, int))
@ -16848,7 +16881,7 @@ void magic_line_func(int which, SDL_Surface * canvas, SDL_Surface * last,
{ {
cnt = (cnt + 1) % step; cnt = (cnt + 1) % step;
if (cnt == 0) if (cnt == 0)
cb((void *) magic_api_struct, which, canvas, last, x1, y); cb((void *) mapi, which, canvas, last, x1, y);
} }
} }
else else
@ -16857,7 +16890,7 @@ void magic_line_func(int which, SDL_Surface * canvas, SDL_Surface * last,
{ {
cnt = (cnt + 1) % step; cnt = (cnt + 1) % step;
if (cnt == 0) if (cnt == 0)
cb((void *) magic_api_struct, which, canvas, last, x1, y); cb((void *) mapi, which, canvas, last, x1, y);
} }
} }
@ -16872,7 +16905,7 @@ void magic_line_func(int which, SDL_Surface * canvas, SDL_Surface * last,
{ {
cnt = (cnt + 1) % step; cnt = (cnt + 1) % step;
if (cnt == 0) if (cnt == 0)
cb((void *) magic_api_struct, which, canvas, last, x1, y); cb((void *) mapi, which, canvas, last, x1, y);
} }
} }
else else
@ -16881,7 +16914,7 @@ void magic_line_func(int which, SDL_Surface * canvas, SDL_Surface * last,
{ {
cnt = (cnt + 1) % step; cnt = (cnt + 1) % step;
if (cnt == 0) if (cnt == 0)
cb((void *) magic_api_struct, which, canvas, last, x1, y); cb((void *) mapi, which, canvas, last, x1, y);
} }
} }
} }