diff --git a/Makefile b/Makefile index cfcdc5772..9c63d4444 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ # bill@newbreedsoftware.com # http://www.tuxpaint.org/ -# June 14, 2002 - August 2, 2007 +# June 14, 2002 - August 7, 2007 # The version number, for release: @@ -345,8 +345,9 @@ install-magic-plugins: @cp magic/icons/*.png $(DATA_PREFIX)/images/magic @chmod a+r,g-w,o-w $(DATA_PREFIX)/images/magic/*.png @install -d $(DATA_PREFIX)/sounds/magic - @cp magic/sounds/*.wav $(DATA_PREFIX)/sounds/magic - @chmod a+r,g-w,o-w $(DATA_PREFIX)/sounds/magic/*.wav + @cp magic/sounds/*.wav magic/sounds/*.ogg $(DATA_PREFIX)/sounds/magic + @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 @echo diff --git a/docs/CHANGES.txt b/docs/CHANGES.txt index 3bc221439..5eca78bfd 100644 --- a/docs/CHANGES.txt +++ b/docs/CHANGES.txt @@ -119,6 +119,13 @@ $Id$ * Flower (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: ------------------ * Esperanto translation diff --git a/magic/docs/README.txt b/magic/docs/README.txt index 9393c1bf0..109255bc8 100644 --- a/magic/docs/README.txt +++ b/magic/docs/README.txt @@ -6,7 +6,7 @@ bill@newbreedsoftware.com http://www.tuxpaint.org/ - July 5, 2007 - August 2, 2007 + July 5, 2007 - August 7, 2007 -------------------------------------------------------------------------- @@ -356,7 +356,7 @@ Interfaces '0' otherwise. Useful to create 'Magic' tools that affect the 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, int step, FUNC callback) This function calculates all points on a line between the @@ -364,9 +364,10 @@ Interfaces calls the 'callback' function. It sends the 'callback' function the (x,y) coordinates on the - line, Tux Paint's "magic_api" struct (as a "void *" pointer), a - 'which' value, represening which of the plugin's 'Magic' tool is - being used, and the current and snapshot canvases. + line, Tux Paint's "magic_api" struct (as a "void *" pointer + which you need to send to it), a 'which' value, represening + 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 Tux Paint's "line()" 'Magic' tool plugin helper function: @@ -374,6 +375,12 @@ Interfaces void exampleCallBack(void * ptr_to_api, int which_tool, 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) This function allows you to avoid re-processing the same pixels 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 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 * void show_progress_bar(void) @@ -660,6 +672,10 @@ Installing by this command will be the global location where the installed copy 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: # cp my_plugin.so `tp-magic-config --pluginprefix` @@ -689,6 +705,8 @@ Installing Note: See the note above regarding the "`" (grave) character. + Note: Currently, there is no "--localplugindocprefix" option. + Icons, Sounds and other Data Files 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 command will be the same as the value of the "data_directory" string 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 within "magic" subdirectories of Tux Paint's "images" and "sounds" @@ -764,6 +788,9 @@ Installing (".html" and ".txt" files) within Tux Paint's documentation directory. + Note: The above Makefile example assumes the user will have + priveleges to install Tux Paint plugins system-wide. + Windows TBD @@ -864,18 +891,22 @@ Glossary "int i;". Later, "&i" refers to the memory where "i" is stored, not the value of "i" itself; it is a 'pointer to "i"'.) * 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 to a struct. * backquote: See "grave." * backtick: See "grave." * 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 "dot" * `: See "grave." * *: 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 * C enumeration: TBD * C function: TBD @@ -894,7 +925,8 @@ Glossary "#define RADIUS 16"; all instances of "RADIUS" will be replaced with "16"), but can also be used to create macros. Typically placed within 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" * dot: ".". A symbol in C that references an element within a struct. * drag: The action of moving a mouse while the button remains held. @@ -904,11 +936,15 @@ Glossary * enum: See "C enumeration" * float: See "floating point" * 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 other C functions (such as "strdup()"). * 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" * grave: The "`" character; used by the BASH shell to use the output of a command as the command-line arguments to another. @@ -930,8 +966,13 @@ Glossary * macro: TBD * 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. - * make: TBD - * Makefile: TBD + * make: 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") + * 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, made available via the "Magic" tool button. * Mix_Chunk *: (A pointer to) a C structure defined by SDL_mixer that @@ -944,7 +985,12 @@ Glossary * OGG: See "Ogg Vorbis" * Ogg Vorbis: TBD (See also: "WAV") * 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" * red: See "RGBA" * release: The action of releasing a button on a mouse. diff --git a/magic/docs/html/README.html b/magic/docs/html/README.html index e5e044890..f04107277 100644 --- a/magic/docs/html/README.html +++ b/magic/docs/html/README.html @@ -15,7 +15,7 @@ New Breed Software

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

-

July 5, 2007 - August 2, 2007

+

July 5, 2007 - August 7, 2007


@@ -41,51 +41,51 @@ concept.)

Table of Contents


-

Prerequisites

+

Prerequisites

@@ -102,7 +102,7 @@ recommended, but some basic SDL concepts will be covered in this document.


-

Interfaces

+

Interfaces

@@ -133,7 +133,7 @@ plugin header file, as well as SDL's header files) for building a plugin. with Tux Paint — or in some cases, as part of a "Tux Paint 'Magic' Tool Plugin Development package".

-

'Magic' tool plugin functions

+

'Magic' tool plugin functions

@@ -144,7 +144,7 @@ would have functions whose names begin with "blur_"). This includes private functions (ones not used by Tux Paint directly), unless you declare those as 'static'.

-

Common arguments to plugin functions:

+

Common arguments to plugin functions:

Here is a description of arguments that many of your plugin's functions 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 "zoom_" (e.g., "zoom_get_name(...)").

-
Plugin "housekeeping" functions:
+
Plugin "housekeeping" functions:
  • Uint32 api_version(void)
    @@ -316,7 +316,7 @@ then the names of your functions must begin with "zoom_"
-
Plugin event functions:
+
Plugin event functions:
  • void set_color(magic_api * api, @@ -399,7 +399,7 @@ access via the "magic_api" structure, sent to all of the plugin's functions. (See "Required Plugin Functions," above.)

    -

    Pixel Manipulations

    +

    Pixel Manipulations

    @@ -434,7 +434,7 @@ plugin's functions.
    -

    Helper Functions

    +

    Helper Functions

    @@ -447,8 +447,9 @@ plugin's functions. brush shape.

    -
  • void line(int which, SDL_Surface * canvas, - SDL_Surface * snapshot, int x1, int y1, +
  • void line(void * api, int which, + SDL_Surface * canvas, SDL_Surface * snapshot, + int x1, int y1, int x2, int y2, int step, FUNC callback)
    This function calculates all points on a line between the coordinates (x1,y1) and (x2,y2). Every 'step' iterations, it calls the 'callback' @@ -456,9 +457,9 @@ plugin's functions.
    It sends the 'callback' function the (x,y) coordinates on the line, Tux Paint's "magic_api" struct (as a - "void *" pointer), a 'which' value, represening which - of the plugin's 'Magic' tool is being used, and the current and snapshot - canvases.
    + "void *" pointer which you need to send to it), + a 'which' value, represening 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 Tux Paint's "line()" 'Magic' tool plugin helper function: @@ -468,6 +469,13 @@ plugin's functions. 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)
    This function allows you to avoid re-processing the same pixels multiple @@ -496,7 +504,7 @@ plugin's functions.
-

Informational

+

Informational

@@ -532,12 +540,17 @@ plugin's functions. placed for the installed version of Tux Paint to find 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

    @@ -589,7 +602,7 @@ plugin's functions.
-

Color Conversions

+

Color Conversions

    @@ -629,7 +642,7 @@ plugin's functions.
-

Helper Macros in "tp_magic_api.h":

+

Helper Macros in "tp_magic_api.h":

Along with the "magic_api" C structure containing functions @@ -664,7 +677,7 @@ also contains some helper macros that you may use.

-

Constant Defintions in "tp_magic_api.h":

+

Constant Defintions in "tp_magic_api.h":

The following is a summary of constant values that are set @@ -704,7 +717,7 @@ also contains some helper macros that you may use.

-

Linux and other Unix-like Platforms

+

Linux and other Unix-like Platforms

@@ -824,13 +837,13 @@ also contains some helper macros that you may use.

-

Windows

+

Windows

TBD

-

Mac OS X

+

Mac OS X

TBD

@@ -844,7 +857,7 @@ also contains some helper macros that you may use.

-

Linux and other Unix-like Platforms

+

Linux and other Unix-like Platforms

Use the "tp-magic-config" command-line tool, supplied as @@ -862,6 +875,11 @@ also contains some helper macros that you may use.

the global location where the installed copy 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:

@@ -904,6 +922,9 @@ also contains some helper macros that you may use.

Note: See the note above regarding the "`" (grave) character.

+

Note: Currently, there is no "--localplugindocprefix" + option.

+

Icons, Sounds and other Data Files

@@ -915,7 +936,14 @@ also contains some helper macros that you may use.

(PNG icon, Ogg Vorbis sound effects, etc.) should be installed. The value returned by this command will be the same as the value of the "data_directory" string stored within the - "magic_api" structure that your plugin's functions receive.

+ "magic_api" structure that your plugin's functions 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 within "magic" subdirectories of Tux Paint's @@ -997,16 +1025,19 @@ also contains some helper macros that you may use.

(".html" and ".txt" files) within Tux Paint's documentation directory.

+

Note: The above Makefile example assumes the user will have + priveleges to install Tux Paint plugins system-wide.

+
-

Windows

+

Windows

TBD

-

Mac OS X

+

Mac OS X

TBD

@@ -1092,7 +1123,7 @@ simply be '1', your arrays will be of length '1', etc.)


-

Example Code

+

Example Code

The C source file @@ -1102,7 +1133,7 @@ simply be '1', your arrays will be of length '1', etc.)


-

Getting Help

+

Getting Help

@@ -1127,17 +1158,17 @@ mailing lists:
  • &: See "ampersand"
  • ampersand: "&". A symbol in C that allows you to refer to the memory address of a variable; that is, a pointer. (For example, consider "int i;". Later, "&i" refers to the memory where "i" is stored, not the value of "i" itself; it is a 'pointer to "i"'.)
  • 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 to a struct.
  • backquote: See "grave."
  • backtick: See "grave."
  • 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 "dot"
  • `: See "grave."
  • *: 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
  • C enumeration: TBD
  • C function: TBD @@ -1148,7 +1179,7 @@ mailing lists:
  • C pointer: 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 Paint's "rgbtohsv()" and "hsvtorgb()".)
  • C structure: TBD
  • #define: A C statement that defines a substitution that can occur later in the code. Generally used for constant values (e.g., "#define RADIUS 16"; all instances of "RADIUS" will be replaced with "16"), but can also be used to create macros. Typically placed within 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"
  • dot: ".". A symbol in C that references an element within a struct.
  • drag: The action of moving a mouse while the button remains held. @@ -1156,10 +1187,10 @@ mailing lists:
  • enum: See "C enumeration"
  • float: See "floating point"
  • 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 other C functions (such as "strdup()").
  • 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"
  • grave: The "`" character; used by the BASH shell to use the output of a command as the command-line arguments to another.
  • green: See "RGBA" @@ -1177,8 +1208,8 @@ mailing lists:
  • linear: TBD
  • macro: TBD
  • 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. -
  • make: TBD -
  • Makefile: TBD +
  • make: 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") +
  • 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, made available via the "Magic" tool button.
  • Mix_Chunk *: (A pointer to) a C structure defined by SDL_mixer that contains a sound.
  • Mix_FreeChunk(): An SDL_mixer function that frees (deallocates) memory allocated for an SDL_mixer sound 'chunk' ("Mix_Chunk *"). @@ -1187,7 +1218,7 @@ mailing lists:
  • OGG: See "Ogg Vorbis"
  • Ogg Vorbis: TBD (See also: "WAV")
  • 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"
  • red: See "RGBA"
  • release: The action of releasing a button on a mouse. diff --git a/magic/docs/tp_magic_example.c b/magic/docs/tp_magic_example.c index d73bb1266..4e1eb44fa 100644 --- a/magic/docs/tp_magic_example.c +++ b/magic/docs/tp_magic_example.c @@ -146,9 +146,10 @@ int example_init(magic_api * api) // we installed our plugin and its data.) snprintf(fname, sizeof(fname), - "%s/sounds/magic/%s.wav", + "%s/sounds/magic/%s", api->data_directory, snd_filenames[i]); + printf("Trying to load %s sound file\n", fname); // 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 // 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 diff --git a/magic/src/blocks_chalk_drip.c b/magic/src/blocks_chalk_drip.c index 8cd649a35..c5e888412 100644 --- a/magic/src/blocks_chalk_drip.c +++ b/magic/src/blocks_chalk_drip.c @@ -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 #include #include @@ -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_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 (oy > y) { int tmp = oy; oy = y; y = tmp; } diff --git a/magic/src/blur.c b/magic/src/blur.c index 16e9a383c..e8406a6e9 100644 --- a/magic/src/blur.c +++ b/magic/src/blur.c @@ -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 + + 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 #include #include @@ -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_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 (oy > y) { int tmp = oy; oy = y; y = tmp; } diff --git a/magic/src/bricks.c b/magic/src/bricks.c index 798f1ea72..303f72cb2 100644 --- a/magic/src/bricks.c +++ b/magic/src/bricks.c @@ -1,3 +1,34 @@ +/* + bricks.c + + Bricks Magic Tools Plugin + Tux Paint - A simple drawing program for children. + + Albert Cahalan + + 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 #include #include @@ -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_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 (oy > y) { int tmp = oy; oy = y; y = tmp; } diff --git a/magic/src/cartoon.c b/magic/src/cartoon.c index 6d0bcced3..af6c1af50 100644 --- a/magic/src/cartoon.c +++ b/magic/src/cartoon.c @@ -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 #include #include @@ -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_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 (oy > y) { int tmp = oy; oy = y; y = tmp; } diff --git a/magic/src/emboss.c b/magic/src/emboss.c index f80025a6f..b2da481a0 100644 --- a/magic/src/emboss.c +++ b/magic/src/emboss.c @@ -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 #include #include @@ -18,7 +47,7 @@ int emboss_init(magic_api * api) { char fname[1024]; - snprintf(fname, sizeof(fname), "%s/sounds/magic/emboss.wav", + snprintf(fname, sizeof(fname), "%s/sounds/magic/emboss.ogg", api->data_directory); 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_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 (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; api->playsound(emboss_snd, - (x * 255) / canvas->w, (y * 255) / canvas->h); + (x * 255) / canvas->w, 255); } // Affect the canvas on click: diff --git a/magic/src/fade_darken.c b/magic/src/fade_darken.c index 7f3fdfeb5..e804c27bc 100644 --- a/magic/src/fade_darken.c +++ b/magic/src/fade_darken.c @@ -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 #include #include @@ -125,7 +154,7 @@ void fade_darken_drag(magic_api * api, int which, SDL_Surface * canvas, SDL_LockSurface(last); 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(last); diff --git a/magic/src/fill.c b/magic/src/fill.c index 13cc7e89b..790573196 100644 --- a/magic/src/fill.c +++ b/magic/src/fill.c @@ -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 #include #include diff --git a/magic/src/flower.c b/magic/src/flower.c index c58822ff0..c42ab257b 100644 --- a/magic/src/flower.c +++ b/magic/src/flower.c @@ -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 #include #include @@ -13,7 +42,7 @@ enum { LEAFSIDE_RIGHT_DOWN, LEAFSIDE_RIGHT_UP, LEAFSIDE_LEFT_UP }; -Mix_Chunk * flower_snd; +Mix_Chunk * flower_click_snd, * flower_release_snd; Uint8 flower_r, flower_g, flower_b; int flower_min_x, flower_max_x, flower_bottom_x, flower_bottom_y; int flower_side_first; @@ -49,9 +78,13 @@ int flower_init(magic_api * api) { 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); - 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", api->data_directory); @@ -172,6 +205,8 @@ void flower_click(magic_api * api, int which, flower_side_first = SIDE_LEFT; 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: @@ -211,7 +246,7 @@ void flower_release(magic_api * api, int which, update_rect->w = canvas->w; 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) { - if (flower_snd != NULL) - Mix_FreeChunk(flower_snd); + if (flower_click_snd != NULL) + Mix_FreeChunk(flower_click_snd); + + if (flower_release_snd != NULL) + Mix_FreeChunk(flower_release_snd); if (flower_base != NULL) SDL_FreeSurface(flower_base); diff --git a/magic/src/foam.c b/magic/src/foam.c index aead3979a..4213885c3 100644 --- a/magic/src/foam.c +++ b/magic/src/foam.c @@ -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 #include #include @@ -30,7 +59,7 @@ int foam_init(magic_api * api) char fname[1024]; 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); 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_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); diff --git a/magic/src/glasstile.c b/magic/src/glasstile.c index 713201057..d238a57a1 100644 --- a/magic/src/glasstile.c +++ b/magic/src/glasstile.c @@ -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 #include #include @@ -21,7 +50,7 @@ int glasstile_init(magic_api * api) { char fname[1024]; - snprintf(fname, sizeof(fname), "%s/sounds/magic/glasstile.wav", + snprintf(fname, sizeof(fname), "%s/sounds/magic/glasstile.ogg", api->data_directory); 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_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->y = 0; diff --git a/magic/src/grass.c b/magic/src/grass.c index 6b6973a2d..d70e787a8 100644 --- a/magic/src/grass.c +++ b/magic/src/grass.c @@ -1,3 +1,33 @@ +/* + grass.c + + Grass Magic Tool Plugin + Tux Paint - A simple drawing program for children. + + by Albert Cahalan + 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 #include #include @@ -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_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 (oy > y) { int tmp = oy; oy = y; y = tmp; } diff --git a/magic/src/kalidescope.c b/magic/src/kalidescope.c index ed8415b97..adc5775b8 100644 --- a/magic/src/kalidescope.c +++ b/magic/src/kalidescope.c @@ -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 #include #include @@ -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_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->y = 0; diff --git a/magic/src/metalpaint.c b/magic/src/metalpaint.c index de6488f1a..9f563d887 100644 --- a/magic/src/metalpaint.c +++ b/magic/src/metalpaint.c @@ -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 #include #include @@ -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_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 (oy > y) { int tmp = oy; oy = y; y = tmp; } diff --git a/magic/src/mirror_flip.c b/magic/src/mirror_flip.c index 4746cd6c0..8e4114cd7 100644 --- a/magic/src/mirror_flip.c +++ b/magic/src/mirror_flip.c @@ -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 #include #include diff --git a/magic/src/negative.c b/magic/src/negative.c index 867b9c5d1..6be2007ba 100644 --- a/magic/src/negative.c +++ b/magic/src/negative.c @@ -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 #include #include @@ -86,7 +115,7 @@ void negative_drag(magic_api * api, int which, SDL_Surface * canvas, SDL_LockSurface(last); 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 (oy > y) { int tmp = oy; oy = y; y = tmp; } diff --git a/magic/src/rainbow.c b/magic/src/rainbow.c index 17d06c192..05d6cafae 100644 --- a/magic/src/rainbow.c +++ b/magic/src/rainbow.c @@ -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 #include #include @@ -118,7 +147,7 @@ void rainbow_drag(magic_api * api, int which, SDL_Surface * canvas, rainbow_hexes[rainbow_color][1], 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 (oy > y) { int tmp = oy; oy = y; y = tmp; } diff --git a/magic/src/ripples.c b/magic/src/ripples.c index eaf81e134..fc9ae383b 100644 --- a/magic/src/ripples.c +++ b/magic/src/ripples.c @@ -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 #include #include @@ -23,7 +52,7 @@ int ripples_init(magic_api * api) { char fname[1024]; - snprintf(fname, sizeof(fname), "%s/sounds/magic/ripples.wav", + snprintf(fname, sizeof(fname), "%s/sounds/magic/ripples.ogg", api->data_directory); 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); - 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; oy = ny; @@ -120,6 +149,8 @@ void ripples_click(magic_api * api, int which, update_rect->y = y - 100; update_rect->w = 200; update_rect->h = 200; + + api->playsound(ripples_snd, (x * 255) / api->canvas_w, 255); } // Affect the canvas on release: diff --git a/magic/src/smudge.c b/magic/src/smudge.c index b496099fa..6a081db16 100644 --- a/magic/src/smudge.c +++ b/magic/src/smudge.c @@ -1,3 +1,33 @@ +/* + smudge.c + + Magic Tool Plugin + Tux Paint - A simple drawing program for children. + + by Albert Cahalan + 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 #include #include @@ -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_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); diff --git a/magic/src/sparkles.c b/magic/src/sparkles.c index d5a9387f2..97284e6fd 100644 --- a/magic/src/sparkles.c +++ b/magic/src/sparkles.c @@ -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 #include #include @@ -8,7 +37,7 @@ /* Our globals: */ -Mix_Chunk * sparkles_snd; +Mix_Chunk * sparkles1_snd, * sparkles2_snd; Uint8 sparkles_r, sparkles_g, sparkles_b; @@ -20,9 +49,13 @@ int sparkles_init(magic_api * api) { char fname[1024]; - snprintf(fname, sizeof(fname), "%s/sounds/magic/sparkles.wav", + snprintf(fname, sizeof(fname), "%s/sounds/magic/sparkles1.wav", 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); } @@ -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_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 (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->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: @@ -128,8 +167,10 @@ void sparkles_release(magic_api * api, int which, // No setup happened: void sparkles_shutdown(magic_api * api) { - if (sparkles_snd != NULL) - Mix_FreeChunk(sparkles_snd); + if (sparkles1_snd != NULL) + Mix_FreeChunk(sparkles1_snd); + if (sparkles2_snd != NULL) + Mix_FreeChunk(sparkles2_snd); } // Record the color from Tux Paint: diff --git a/magic/src/tint.c b/magic/src/tint.c index 3ef619de1..8f761e629 100644 --- a/magic/src/tint.c +++ b/magic/src/tint.c @@ -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 #include #include @@ -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_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 (oy > y) { int tmp = oy; oy = y; y = tmp; } diff --git a/magic/src/waves.c b/magic/src/waves.c index 10db05af9..be07195a7 100644 --- a/magic/src/waves.c +++ b/magic/src/waves.c @@ -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 #include #include @@ -105,6 +134,7 @@ void waves_release(magic_api * api, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect) { + api->playsound(waves_snd, 128, 255); } // No setup happened: diff --git a/src/manpage/tp-magic-config.1 b/src/manpage/tp-magic-config.1 index fea9a2ed1..5eb28f219 100644 --- a/src/manpage/tp-magic-config.1 +++ b/src/manpage/tp-magic-config.1 @@ -1,11 +1,11 @@ -.\" tp-magic-config - 2007.08.02 -.TH TP-MAGIC-CONFIG 1 "02 August 2007" "2007.08.02" "tp-magic-config" +.\" tp-magic-config - 2007.08.07 +.TH TP-MAGIC-CONFIG 1 "07 August 2007" "2007.08.07" "tp-magic-config" .SH NAME tp-magic-config -- Helps creating 'Magic' tool plugins for Tux Paint(1) .SH SYNOPSYS .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 \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.) .TP 8 .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). +(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 .B \-\-plugindocprefix 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. .TP 8 .B \-\-dataprefix -Outputs the directory where the installed copy of \fITux Paint\fP keeps its -global data files (e.g., "/usr/share/tuxpaint/"). This is the same value that -plugins will receive in the "data_directory" string within the -"magic_api" structure sent to the plugins' functions. +Outputs the system directory where the installed copy of \fITux Paint\fP keeps +its global data files (e.g., "/usr/share/tuxpaint/"). This is the same value +that plugins installed system-wide will receive in the "data_directory" string +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 .br # 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 # 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) .br MAGIC_PREFIX=$(shell tp-magic-config --pluginprefix) diff --git a/src/tp-magic-config.sh.in b/src/tp-magic-config.sh.in index e1f7db362..e3d027a0b 100755 --- a/src/tp-magic-config.sh.in +++ b/src/tp-magic-config.sh.in @@ -50,10 +50,18 @@ if [ $# -ne 0 ]; then echo "__DATAPREFIX__" exit fi + if [ $1 = "--localdataprefix" ]; then + echo "$HOME/.tuxpaint/plugins/data" + exit + fi if [ $1 = "--pluginprefix" ]; then echo "__PLUGINPREFIX__" exit fi + if [ $1 = "--localpluginprefix" ]; then + echo "$HOME/.tuxpaint/plugins" + exit + fi if [ $1 = "--plugindocprefix" ]; then echo "__PLUGINDOCPREFIX__" exit diff --git a/src/tp_magic_api.h.in b/src/tp_magic_api.h.in index 748f254c2..8a3b23024 100644 --- a/src/tp_magic_api.h.in +++ b/src/tp_magic_api.h.in @@ -91,9 +91,10 @@ typedef struct magic_api_t { /* Asks Tux Paint to calculate a line between (x1,y1) and (x2,y2); every 'step' iterations, it will call your callback function - (which must accept a 'which' integer for which tool is being used, - 'last' and current ('canvas') SDL_Surfaces, and an (x,y) position) */ - void (*line)(int, SDL_Surface *, SDL_Surface *, int, int, int, int, int, void (*)(void *, int, SDL_Surface *, SDL_Surface *, int, int)); + (which must accept a 'magic_api *' Magic API pointer and 'which' integer + for which tool is being used, the 'last' and current ('canvas') + 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 */ int (*button_down)(void); diff --git a/src/tuxpaint.c b/src/tuxpaint.c index ca306a532..efc82e873 100644 --- a/src/tuxpaint.c +++ b/src/tuxpaint.c @@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA (See COPYING.txt) - June 14, 2002 - July 24, 2007 + June 14, 2002 - August 7, 2007 $Id$ */ @@ -880,6 +880,7 @@ typedef struct magic_funcs_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 idx; // Index to magic tools within shared objects (shared objs may report more than 1 tool) 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]; 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__) @@ -1489,7 +1496,8 @@ int magic_sort(const void * a, const void * b); Mix_Chunk * magic_current_snd_ptr; 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, void (*cb)(void *, int, SDL_Surface *, SDL_Surface *, int, int)); @@ -2401,7 +2409,7 @@ static void mainloop(void) draw_colors(magics[cur_magic].colors); if (magics[cur_magic].colors) 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][1], color_hexes[cur_color][2]); @@ -3027,7 +3035,7 @@ static void mainloop(void) if (magics[cur_magic].colors) 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][1], color_hexes[cur_color][2]); @@ -3100,7 +3108,7 @@ static void mainloop(void) do_render_cur_text(0); else if (cur_tool == TOOL_MAGIC) 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][1], color_hexes[cur_color][2]); @@ -3231,7 +3239,7 @@ static void mainloop(void) 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, canvas, last, old_x, old_y, @@ -3579,7 +3587,7 @@ static void mainloop(void) update_rect.w = 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, canvas, last, old_x, old_y, @@ -3815,7 +3823,7 @@ static void mainloop(void) update_rect.w = 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, canvas, last, old_x, old_y, @@ -8179,7 +8187,11 @@ static void draw_brushes(void) 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.w = (img_brushes[brush]->w / abs(brushes_frames[brush])) / @@ -11667,7 +11679,7 @@ static void cleanup(void) #endif 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_arrow); @@ -16478,9 +16490,11 @@ float pick_best_scape(unsigned int orig_w, unsigned int orig_h, #endif + void load_magic_plugins(void) { - int res, n, i; + int res, n, i, plc; + char * place; int err; DIR *d; struct dirent *f; @@ -16491,292 +16505,310 @@ void load_magic_plugins(void) num_plugin_files = 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 - printf("\n"); - printf("Loading magic plug-ins from %s\n", MAGIC_PREFIX); - fflush(stdout); + printf("\n"); + printf("Loading magic plug-ins from %s\n", place); + fflush(stdout); #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): */ - 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 - extension: */ + /* Get just the name of the object (e.g., "negative"), w/o filename + extension: */ - strcpy(objname, f->d_name); - strcpy(strchr(objname, '.'), ""); + strcpy(objname, f->d_name); + 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 - printf("loading: %s\n", fname); - fflush(stdout); + printf("loading: %s\n", fname); + fflush(stdout); #endif - snprintf(funcname, sizeof(funcname), "%s_%s", objname, - "get_tool_count"); - magic_funcs[num_plugin_files].get_tool_count = - SDL_LoadFunction(magic_handle[num_plugin_files], funcname); + snprintf(funcname, sizeof(funcname), "%s_%s", objname, + "get_tool_count"); + magic_funcs[num_plugin_files].get_tool_count = + SDL_LoadFunction(magic_handle[num_plugin_files], funcname); - snprintf(funcname, sizeof(funcname), "%s_%s", objname, - "get_name"); - magic_funcs[num_plugin_files].get_name = - SDL_LoadFunction(magic_handle[num_plugin_files], funcname); + snprintf(funcname, sizeof(funcname), "%s_%s", objname, + "get_name"); + magic_funcs[num_plugin_files].get_name = + SDL_LoadFunction(magic_handle[num_plugin_files], funcname); - snprintf(funcname, sizeof(funcname), "%s_%s", objname, - "get_icon"); - magic_funcs[num_plugin_files].get_icon = - SDL_LoadFunction(magic_handle[num_plugin_files], funcname); + snprintf(funcname, sizeof(funcname), "%s_%s", objname, + "get_icon"); + magic_funcs[num_plugin_files].get_icon = + SDL_LoadFunction(magic_handle[num_plugin_files], funcname); - snprintf(funcname, sizeof(funcname), "%s_%s", objname, - "get_description"); - magic_funcs[num_plugin_files].get_description = - SDL_LoadFunction(magic_handle[num_plugin_files], funcname); + snprintf(funcname, sizeof(funcname), "%s_%s", objname, + "get_description"); + magic_funcs[num_plugin_files].get_description = + SDL_LoadFunction(magic_handle[num_plugin_files], funcname); - snprintf(funcname, sizeof(funcname), "%s_%s", objname, - "requires_colors"); - magic_funcs[num_plugin_files].requires_colors = - SDL_LoadFunction(magic_handle[num_plugin_files], funcname); + snprintf(funcname, sizeof(funcname), "%s_%s", objname, + "requires_colors"); + magic_funcs[num_plugin_files].requires_colors = + SDL_LoadFunction(magic_handle[num_plugin_files], funcname); - snprintf(funcname, sizeof(funcname), "%s_%s", objname, + snprintf(funcname, sizeof(funcname), "%s_%s", objname, "set_color"); - magic_funcs[num_plugin_files].set_color = - SDL_LoadFunction(magic_handle[num_plugin_files], funcname); + magic_funcs[num_plugin_files].set_color = + SDL_LoadFunction(magic_handle[num_plugin_files], funcname); - snprintf(funcname, sizeof(funcname), "%s_%s", objname, + snprintf(funcname, sizeof(funcname), "%s_%s", objname, "init"); - magic_funcs[num_plugin_files].init = - SDL_LoadFunction(magic_handle[num_plugin_files], funcname); + magic_funcs[num_plugin_files].init = + SDL_LoadFunction(magic_handle[num_plugin_files], funcname); - snprintf(funcname, sizeof(funcname), "%s_%s", objname, + snprintf(funcname, sizeof(funcname), "%s_%s", objname, "api_version"); - magic_funcs[num_plugin_files].api_version = - SDL_LoadFunction(magic_handle[num_plugin_files], funcname); + magic_funcs[num_plugin_files].api_version = + SDL_LoadFunction(magic_handle[num_plugin_files], funcname); - snprintf(funcname, sizeof(funcname), "%s_%s", objname, + snprintf(funcname, sizeof(funcname), "%s_%s", objname, "shutdown"); - magic_funcs[num_plugin_files].shutdown = - SDL_LoadFunction(magic_handle[num_plugin_files], funcname); + magic_funcs[num_plugin_files].shutdown = + SDL_LoadFunction(magic_handle[num_plugin_files], funcname); - snprintf(funcname, sizeof(funcname), "%s_%s", objname, + snprintf(funcname, sizeof(funcname), "%s_%s", objname, "click"); - magic_funcs[num_plugin_files].click = - SDL_LoadFunction(magic_handle[num_plugin_files], funcname); + magic_funcs[num_plugin_files].click = + SDL_LoadFunction(magic_handle[num_plugin_files], funcname); - snprintf(funcname, sizeof(funcname), "%s_%s", objname, + snprintf(funcname, sizeof(funcname), "%s_%s", objname, "drag"); - magic_funcs[num_plugin_files].drag = - SDL_LoadFunction(magic_handle[num_plugin_files], funcname); + magic_funcs[num_plugin_files].drag = + SDL_LoadFunction(magic_handle[num_plugin_files], funcname); - snprintf(funcname, sizeof(funcname), "%s_%s", objname, + snprintf(funcname, sizeof(funcname), "%s_%s", objname, "release"); - magic_funcs[num_plugin_files].release = - SDL_LoadFunction(magic_handle[num_plugin_files], funcname); + magic_funcs[num_plugin_files].release = + SDL_LoadFunction(magic_handle[num_plugin_files], funcname); #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); - printf("get_name = 0x%x\n", + printf("get_name = 0x%x\n", (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); - printf("get_description = 0x%x\n", + printf("get_description = 0x%x\n", (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); - printf("set_color = 0x%x\n", + printf("set_color = 0x%x\n", (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); - printf("api_version = 0x%x\n", + printf("api_version = 0x%x\n", (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); - printf("click = 0x%x\n", + printf("click = 0x%x\n", (int) magic_funcs[num_plugin_files].click); - printf("drag = 0x%x\n", + printf("drag = 0x%x\n", (int) magic_funcs[num_plugin_files].drag); - printf("release = 0x%x\n", + printf("release = 0x%x\n", (int) magic_funcs[num_plugin_files].release); #endif - err = 0; + err = 0; - if (magic_funcs[num_plugin_files].get_tool_count == NULL) - { - fprintf(stderr, "Error: plugin %s is missing get_tool_count\n", + if (magic_funcs[num_plugin_files].get_tool_count == NULL) + { + fprintf(stderr, "Error: plugin %s is missing get_tool_count\n", fname); - err = 1; - } - if (magic_funcs[num_plugin_files].get_name == NULL) - { - fprintf(stderr, "Error: plugin %s is missing get_name\n", + err = 1; + } + if (magic_funcs[num_plugin_files].get_name == NULL) + { + fprintf(stderr, "Error: plugin %s is missing get_name\n", fname); - err = 1; - } - if (magic_funcs[num_plugin_files].get_icon == NULL) - { - fprintf(stderr, "Error: plugin %s is missing get_icon\n", + err = 1; + } + if (magic_funcs[num_plugin_files].get_icon == NULL) + { + fprintf(stderr, "Error: plugin %s is missing get_icon\n", fname); - err = 1; - } - if (magic_funcs[num_plugin_files].get_description == NULL) - { - fprintf(stderr, "Error: plugin %s is missing get_description\n", + err = 1; + } + if (magic_funcs[num_plugin_files].get_description == NULL) + { + fprintf(stderr, "Error: plugin %s is missing get_description\n", fname); - err = 1; - } - if (magic_funcs[num_plugin_files].requires_colors == NULL) - { - fprintf(stderr, "Error: plugin %s is missing requires_colors\n", + err = 1; + } + if (magic_funcs[num_plugin_files].requires_colors == NULL) + { + fprintf(stderr, "Error: plugin %s is missing requires_colors\n", fname); - err = 1; - } - if (magic_funcs[num_plugin_files].set_color == NULL) - { - fprintf(stderr, "Error: plugin %s is missing set_color\n", + err = 1; + } + if (magic_funcs[num_plugin_files].set_color == NULL) + { + fprintf(stderr, "Error: plugin %s is missing set_color\n", fname); - err = 1; - } - if (magic_funcs[num_plugin_files].init == NULL) - { - fprintf(stderr, "Error: plugin %s is missing init\n", + err = 1; + } + if (magic_funcs[num_plugin_files].init == NULL) + { + fprintf(stderr, "Error: plugin %s is missing init\n", fname); - err = 1; - } - if (magic_funcs[num_plugin_files].shutdown == NULL) - { - fprintf(stderr, "Error: plugin %s is missing shutdown\n", + err = 1; + } + if (magic_funcs[num_plugin_files].shutdown == NULL) + { + fprintf(stderr, "Error: plugin %s is missing shutdown\n", fname); - err = 1; - } - if (magic_funcs[num_plugin_files].click == NULL) - { - fprintf(stderr, "Error: plugin %s is missing click\n", + err = 1; + } + if (magic_funcs[num_plugin_files].click == NULL) + { + fprintf(stderr, "Error: plugin %s is missing click\n", fname); - err = 1; - } - if (magic_funcs[num_plugin_files].release == NULL) - { - fprintf(stderr, "Error: plugin %s is missing release\n", + err = 1; + } + if (magic_funcs[num_plugin_files].release == NULL) + { + fprintf(stderr, "Error: plugin %s is missing release\n", fname); - err = 1; - } - if (magic_funcs[num_plugin_files].drag == NULL) - { - fprintf(stderr, "Error: plugin %s is missing drag\n", + err = 1; + } + if (magic_funcs[num_plugin_files].drag == NULL) + { + fprintf(stderr, "Error: plugin %s is missing drag\n", fname); - err = 1; - } + err = 1; + } - if (magic_funcs[num_plugin_files].api_version == NULL) - { - fprintf(stderr, "Error: plugin %s is missing api_version\n", + if (magic_funcs[num_plugin_files].api_version == NULL) + { + fprintf(stderr, "Error: plugin %s is missing api_version\n", fname); - err = 1; - } - else if (magic_funcs[num_plugin_files].api_version() != TP_MAGIC_API_VERSION) - { - fprintf(stderr, "Warning: plugin %s uses Tux Paint 'Magic' tool API version %x,\nbut Tux Paint needs version %x.\n", fname, magic_funcs[num_plugin_files].api_version(), TP_MAGIC_API_VERSION); - err = 1; - } - - if (err) - { - SDL_UnloadObject(magic_handle[num_plugin_files]); - } - 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; + err = 1; + } + else if (magic_funcs[num_plugin_files].api_version() != TP_MAGIC_API_VERSION) + { + fprintf(stderr, "Warning: plugin %s uses Tux Paint 'Magic' tool API version %x,\nbut Tux Paint needs version %x.\n", fname, magic_funcs[num_plugin_files].api_version(), TP_MAGIC_API_VERSION); + err = 1; } - - if (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]); - } + if (err) + { + SDL_UnloadObject(magic_handle[num_plugin_files]); + } else - { - for (i = 0; i < n; i++) - { - 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); + { + res = magic_funcs[num_plugin_files].init(magic_api_struct[plc]); - 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 - printf("-- %s\n", magics[num_magics].name); + printf("-- %s\n", magics[num_magics].name); #endif - num_magics++; - } + num_magics++; + } - num_plugin_files++; + num_plugin_files++; + } } } - } - else - { - fprintf(stderr, "Warning: Failed to load object %s: %s\n", fname, SDL_GetError()); - fflush(stderr); + else + { + fprintf(stderr, "Warning: Failed to load object %s: %s\n", fname, SDL_GetError()); + 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); } -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, void (*cb)(void *, int, SDL_Surface *, SDL_Surface *, int, int)) @@ -16848,7 +16881,7 @@ void magic_line_func(int which, SDL_Surface * canvas, SDL_Surface * last, { cnt = (cnt + 1) % step; if (cnt == 0) - cb((void *) magic_api_struct, which, canvas, last, x1, y); + cb((void *) mapi, which, canvas, last, x1, y); } } else @@ -16857,7 +16890,7 @@ void magic_line_func(int which, SDL_Surface * canvas, SDL_Surface * last, { cnt = (cnt + 1) % step; 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; if (cnt == 0) - cb((void *) magic_api_struct, which, canvas, last, x1, y); + cb((void *) mapi, which, canvas, last, x1, y); } } else @@ -16881,7 +16914,7 @@ void magic_line_func(int which, SDL_Surface * canvas, SDL_Surface * last, { cnt = (cnt + 1) % step; if (cnt == 0) - cb((void *) magic_api_struct, which, canvas, last, x1, y); + cb((void *) mapi, which, canvas, last, x1, y); } } }