1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>Creating Tux Paint Magic Tool Plugins</title>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#FF0000"
alink="#FF00FF">
<center>
<h1>Creating Tux Paint Magic Tool Plugins</h1>
<p>Copyright 2007-2007 by Bill Kendrick and others<br>
New Breed Software</p>
<p><a href="mailto:bill@newbreedsoftware.com">bill@newbreedsoftware.com</a><br>
<a href="http://www.tuxpaint.org/">http://www.tuxpaint.org/</a></p>
<p>July 5, 2007 - November 21, 2007</p>
</center>
<hr size=2 noshade>
<h2>Overview</h2>
<blockquote>
<p>Beginning with version 0.9.18, Tux Paint's 'Magic' tools were converted
from routines that lived within the application itself, to a set of 'plugins'
that are loaded when Tux Paint starts up.</p>
<p>This division allows more rapid development of 'Magic' tools, and allows
programmers to create and test new tools without needing to integrate them
within the main Tux Paint source code. (Users of more professional
graphics tools, such as The GIMP, should be familiar with this plugin
concept.)</p>
</blockquote>
<hr size=1 noshade>
<h2>Table of Contents</h2>
<ul>
<li><a href="#prereqs">Prequisites</a>
<li><a href="#interfaces">Interfaces</a>
<ul>
<li><a href="#magic_plugin_funcs">'Magic' tool plugin functions</a>
<ul>
<li><a href="#common_args">Common arguments to plugin functions</a>
<li><a href="#toolfuncs">Required Plugin Functions</a>
<ul>
<li><a href="#housekeeping">Plugin "housekeeping" functions</a>
<li><a href="#eventfuncs">Plugin event functions</a>
</ul>
</ul>
<li><a href="#tpfuncs">Tux Paint Functions and Data</a>
<ul>
<li><a href="#pixel_manip">Pixel Manipulations</a>
<li><a href="#helper_funcs">Helper Functions</a>
<li><a href="#informational">Informational</a>
<li><a href="#syscalls">Tux Paint System Calls</a>
<li><a href="#color_convs">Color Conversions</a>
</ul>
<li><a href="#macros">Helper Macros in "tp_magic_api.h"</a>
<li><a href="#consts">Constant Definitions in "tp_magic_api.h"</a>
</ul>
<li><a href="#compiling">Compiling</a>
<ul>
<li><a href="#compiling-linux">Linux and other Unix-like Platforms</a>
<li><a href="#compiling-windows">Windows</a>
<li><a href="#compiling-osx">Mac OS X</a>
</ul>
<li><a href="#installing">Installing</a>
<ul>
<li><a href="#installing-linux">Linux and other Unix-like Platforms</a>
<li><a href="#installing-windows">Windows</a>
<li><a href="#installing-osx">Mac OS X</a>
</ul>
<li><a href="#multiple">Creating plugins with multiple effects</a>
<li><a href="#examples">Example Code</a>
<li><a href="#help">Getting Help</a>
<li><a href="#glossary">Glossary</a>
</ul>
<hr size=1 noshade>
<h2><a name="prereqs">Prerequisites</a></h2>
<blockquote>
<p>Tux Paint is written in the
<a href="http://en.wikipedia.org/wiki/C_(programming_language)">C programming
language</a>, and uses the
Simple DirectMedia Layer library ('libSDL', or simply 'SDL';
available from <a href="http://www.libsdl.org/">http://www.libsdl.org/</a>).
Therefore, for the moment at least, one must understand the C language and
how to compile C-based programs. Familiarity with the SDL API is highly
recommended, but some basic SDL concepts will be covered in this document.</p>
</blockquote>
<hr size=1 noshade>
<h2><a name="interfaces">Interfaces</a></h2>
<blockquote>
<p>Those who create 'Magic' tool plugins for Tux Paint must provide
some interfaces (C functions) that Tux Paint may invoke.</p>
<p>Tux Paint utilizes SDL's "SDL_LoadObject()" and "SDL_LoadFunction()"
routines to load plugins (shared objects files; e.g., "<code>.so</code>"
files on Linux or "<code>.dll</code>" files on Windows) and find the
functions within.</p>
<p>In turn, Tux Paint provides a number of helper functions that the
plugin may (or sometimes is required to) use. This is exposed as a C
structure (or "<code>struct</code>") which contains pointers to functions
and other data inside Tux Paint. A pointer to this structure gets
passed along to the plugin's functions as an argument when Tux Paint
invokes them.</p>
<p>Plugins should <code>#include</code> the C header file
"<code>tp_magic_api.h</code>", which exposes the 'Magic' tool plugin API.
Also, when you run the C compiler to build a plugin, you should use the
command-line tool "<code>tp-magic-config</code>" to get the appropriate
compiler flags (such as where the compiler can find the Tux Paint
plugin header file, as well as SDL's header files) for building a plugin.
(See "<a href="#compiling">Compiling</a>", below.)</p>
<p>The C header file and command-line tool mentioned above are included
with Tux Paint — or in some cases, as part of a "Tux Paint
'Magic' Tool Plugin Development package".</p>
<h3><a name="magic_plugin_funcs">'Magic' tool plugin functions</a></h3>
<blockquote>
<p>'Magic' tool plugins <i>must</i> contain the functions listed below.
<b>Note:</b> To avoid 'namespace' collisions, each function's name must
start with the shared object's filename (e.g., "blur.so" or "blur.dll"
would have functions whose names begin with "<code>blur_</code>"). <i>This
includes private functions</i> (ones not used by Tux Paint directly),
unless you declare those as '<code>static</code>'.</p>
<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
will need to accept.
<ul>
<li><code><b>magic_api * api</b></code><br>
Pointer to a C structure containing pointers to Tux Paint functions and
other data that the plugin can (and sometimes should) use.
The contents of this struct are <a href="#tpfuncs">described below</a>.<br>
<br>
Note: The <code>magic_api</code> struct is defined in the C header file
"<code>tp_magic_api.h</code>", which you should include at the top of your
plugin's C source file:
<blockquote><code>
#include "tp_magic_api.h"
</code></blockquote>
<li><code><b>int which</b></code><br>
An index the plugin should use to differentiate different 'Magic' tools,
if the plugin provides more than one. (If not, "which" will always be 0.)
See <a href="#multiple">"Creating plugins with multiple effects"</a>,
below.<br>
<br>
<li><code><b>SDL_Surface * snapshot</b></code><br>
A snapshot of the previous Tux Paint canvas, taken when the the
mouse was first clicked to activate the current magic tool. If you don't
continuously affect the image during one hold of the mouse button,
you should base your effects off the contents of this canvas.
(That is, read from "<code>snapshot</code>" and write to
"<code>canvas</code>", below.)<br>
<br>
<li><code><b>SDL_Surface * canvas</b></code><br>
The current Tux Paint drawing canvas. Your magical effects should end
up here!<br>
<br>
<li><code><b>SDL_Rect * update_rect</b></code><br>
A pointer to an SDL 'rectangle' structure that you use to tell Tux Paint
what part of the canvas has been updated. If your effect affects a
32x32 area centered around the mouse pointer, you would fill the SDL_Rect
as follows:
<blockquote><code>
update_rect->x = x - 16;<br>
update_rect->y = y - 16;<br>
update_rect->w = 32;<br>
update_rect->h = 32;
</code></blockquote>
Or, if your effect changes the entire canvas (e.g., flips it upside-down),
you'd fill it as follows:
<blockquote><code>
update_rect->x = 0;<br>
update_rect->y = 0;<br>
update_rect->w = canvas->w;<br>
update_rect->h = canvas->h;
</code></blockquote>
Note: "<code>update_rect</code>" is a C pointer
(an "<code>SDL_Rect *</code>" rather than just an
"<code>SDL_Rect</code>") because you need to fill in its contents.
Because it is a pointer, you access its elements via
"<code>-></code>" (arrow) rather than "<code>.</code>" (dot).
</ul>
<h4><a name="toolfuncs">Required Plugin Functions:</a></h4>
<blockquote>
<p>Your plugin is required to contain, at the least, all of the
following functions.</p>
<p><b>Note:</b> Remember, your plugin's function names must be
preceded by your plugin's filename. That is, if your plugin is called
"<code>zoom.so</code>" (on Linux) or "<code>zoom.dll</code>" (on Windows),
then the names of your functions must begin with "<code><b>zoom_</b></code>"
(e.g., "<code>zoom_get_name(...)</code>").</p>
<h5><a name="housekeeping">Plugin "housekeeping" functions:</a></h5>
<ul>
<li><code><b>Uint32 api_version(void)</b></code><br>
The plugin should return an integer value representing the version of
the Tux Paint 'Magic' tool plugin API the plugin was built against.
The safest thing to do is return the value of
<code>TP_MAGIC_API_VERSION</code>, which is defined in
"<code>tp_magic_api.h</code>". If Tux Paint deems your plugin to
be compatible, it will go ahead and use it.<br>
<br>
<b>Note:</b> Called once by Tux Paint, at startup. It is called
first.<br>
<br>
<li><code><b>int init(magic_api * api)</b></code><br>
The plugin should do any initialization here.
Return '1' if initialization was successful,
or '0' if not (and Tux Paint will not present any 'Magic' tools
from the plugin).<br>
<br>
<b>Note:</b> Called once by Tux Paint, at startup. It is called
first. It is called after "<code>api_version()</code>", if
Tux Paint believes your plugin to be compatible.<br>
<br>
<li><code><b>int get_tool_count(magic_api * api)</b></code><br>
This should return the number of Magic tools this plugin provides to
Tux Paint.<br>
<br>
<b>Note:</b> Called once by Tux Paint, at startup. It is called
after your "<code>init()</code>", if it succeeded.<br>
<br>
<li><code><b>char * get_name(magic_api * api,
int which)</b></code><br>
This should return a string containing the name of a magic tool.
This will appear on the button in the 'Magic' selector within
Tux Paint.<br>
<br>
Tux Paint will <code>free()</code> the string upon exit, so you should
wrap it in a C <code>strdup()</code> call.<br>
<br>
<b>Note:</b> Called once for each Magic tool your plugin claims to
contain (by your "<code>get_tool_count()</code>").<br>
<br>
<li><code><b>SDL_Surface * get_icon(magic_api * api,
int which)</b></code><br>
This should return an SDL_Surface containing the icon representing
the tool. (A greyscale image with alpha, no larger than 40x40.)
This will appear on the button in the 'Magic' selector within
Tux Paint.<br>
<br>
Tux Paint will free ("<code>SDL_FreeSurface()</code>") the surface upon
exit.<br>
<br>
<b>Note:</b> Called once for each Magic tool your plugin claims to
contain (by your "<code>get_tool_count()</code>").<br>
<br>
<li><code><b>char * get_description(magic_api * api,
int which)</b></code><br>
This should return a string containing the description of a magic tool.
This will appear as a help tip, explained by Tux the Penguin, within
Tux Paint.<br>
<br>
Tux Paint will <code>free()</code> the string upon exit, so you should
wrap it in a C <code>strdup()</code> call.<br>
<br>
<b>Note:</b> Called once for each Magic tool your plugin claims to
contain (by your "<code>get_tool_count()</code>").<br>
<br>
<li><code><b>int requires_colors(magic_api * api,
int which)</b></code><br>
Return a '1' if the 'Magic' tool accepts colors (the 'Colors' palette in
Tux Paint will be available), or '0' if not.<br>
<br>
<b>Note:</b> Called once for each Magic tool your plugin claims to
contain (by your "<code>get_tool_count()</code>").<br>
<br>
<li><code><b>void shutdown(magic_api * api)</b></code><br>
The plugin should do any cleanup here. If you allocated any memory
or used SDL_Mixer to load any sounds during <code>init()</code>,
for example, you should <code>free()</code> the allocated memory
and <code>Mix_FreeChunk()</code> the sounds here.<br>
<br>
<b>Note:</b> This function is called once, when Tux Paint exits.<br>
<br>
</ul>
<h5><a name="eventfuncs">Plugin event functions:</a></h5>
<ul>
<li><code><b>void set_color(magic_api * api,
Uint8 r, Uint8 g, Uint8 g)
</b></code><br>
Tux Paint will call this function to inform the plugin of the
RGB values of the currently-selected color in Tux Paint's
'Colors' palette. (It will be called whenever one of the plugin's
Magic tools that accept colors becomes active, and whenever the user
picks a new color while such a tool is currently active.)<br>
<br>
<li><code><b>void click(magic_api * api, int which,
SDL_Surface * snapshot, SDL_Surface * canvas,
int x, int y, SDL_Rect * update_rect)
</b></code><br>
The plugin should apply the appropriate 'Magic' tool on the
'<code>canvas</code>' surface. The (x,y) coordinates are where the
mouse was (within the canvas) when the mouse button was clicked.<br>
<br>
The plugin should report back what part of the canvas was affected, by
filling in the (x,y) and (w,h) elements of '<code>update_rect</code>'.<br>
<br>
The contents of the drawing canvas immediately prior to the mouse button
click is stored within the '<code>snapshot</code>' canvas.<br>
<br>
<li><code><b>void drag(magic_api * api, int which,
SDL_Surface * snapshot, SDL_Surface * canvas,
int ox, int oy, int x, int y,
SDL_Rect * update_rect)</b></code><br>
The plugin should apply the appropriate 'Magic' tool on the
'<code>canvas</code>'
surface. The (ox,oy) and (x,y) coordinates are the location of the mouse
at the beginning and end of the stroke.<br>
<br>
Typically, plugins that let the user "draw" effects onto the canvas
utilize Tux Paint's "<code>line()</code>" 'Magic' tool plugin
helper function to calculate the points of the line between (ox,oy)
and (x,y), and call another function within the plugin to apply the effect
at each point.
(See "<a href="#tpfuncs">Tux Paint Functions and Data</a>," below).<br>
<br>
The plugin should report back what part of the canvas was affected, by
filling in the (x,y) and (w,h) elements of '<code>update_rect</code>'.<br>
<br>
Note: The contents of the drawing canvas immediately prior to the mouse
button click remains as it was (when the plugin's "<code>click()</code>"
function was called), and is still available in the '<code>snapshot</code>'
canvas.<br>
<br>
<li><code><b>void release(magic_api * api, int which,
SDL_Surface * snapshot, SDL_Surface * canvas,
int x, int y, SDL_Rect * update_rect)</b></code><br>
The plugin should apply the appropriate 'Magic' tool on the
'<code>canvas</code>'
surface. The (x,y) coordinates are where the mouse was (within the canvas)
when the mouse button was released.<br>
<br>
The plugin should report back what part of the canvas was affected, by
filling in the (x,y) and (w,h) elements of 'update_rect'.<br>
<br>
<b>Note:</b> The contents of the drawing canvas immediately prior to the mouse
button click remains as it was (when the plugin's "<code>click()</code>"
function was called), and is still available in the 'snapshot' canvas.<br>
<br>
</ul>
</blockquote>
</blockquote>
<h3><a name="tpfuncs">Tux Paint Functions and Data</a></h3>
<blockquote>
<p>Tux Paint provides a number of helper functions that plugins may
access via the "<code>magic_api</code>" structure, sent to all of the
plugin's functions.
(See "<a href="#toolfuncs">Required Plugin Functions</a>," above.)</p>
<h4><a name="pixel_manip">Pixel Manipulations</a></h4>
<blockquote>
<ul>
<li><code><b>Uint32 getpixel(SDL_Surface * surf,
int x, int y)</b></code><br>
Retreives the pixel value from the (x,y) coordinates of an SDL_Surface.
(You can use SDL's "SDL_GetRGB()" function to convert the Uint32 'pixel'
to a set of Uint8 RGB values.)<br>
<br>
<li><code><b>void putpixel(SDL_Surface * surf, int x, int y,
Uint32 pixel)</b></code><br>
Sets the pixel value at position (x,y) of an SDL_Surface.
(You can use SDL's "SDL_MapRGB()" function to convert a set of Uint8
RGB values to a Uint32 'pixel' value appropriate to the destination
surface.)<br>
<br>
<li><code><b>SDL_Surface * scale(SDL_Surface * surf,
int w, int h, int keep_aspect)</b></code><br>
This accepts an existing SDL surface and creates a new one scaled to an
arbitrary size. (The original surface remains untouched.)<br>
<br>
The "<code>keep_aspect</code>" flag can be set to '1' to force the new
surface to stay the same shape (aspect ratio) as the original, meaning
it may not be the same width and height you requested. (Check the
"<code>->w</code>" and "<code>->h</code>" elements of the output
"SDL_Surface *" to determine the <i>actual</i> size.)<br>
<br>
</ul>
</blockquote>
<h4><a name="helper_funcs">Helper Functions</a></h4>
<blockquote>
<ul>
<li><code><b>int in_circle(int x, int y,
int radius)</b></code><br>
Returns '1' if the (x,y) location is within a circle of a particular
radius (centered around the origin: (0,0)). Returns '0' otherwise.
Useful to create 'Magic' tools that affect the canvas with a circular
brush shape.<br>
<br>
<li><code><b>void line(void * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot,
int x1, int y1,
int x2, int y2, int step, FUNC callback)</b></code><br>
This function calculates all points on a line between the coordinates
(x1,y1) and (x2,y2). Every 'step' iterations, it calls the 'callback'
function.<br>
<br>
It sends the 'callback' function the (x,y) coordinates on the line,
Tux Paint's "<code>magic_api</code>" struct (as a
"<code>void *</code>" 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.<br>
<br>
Example prototype of a callback function that may be sent to
Tux Paint's "<code>line()</code>" 'Magic' tool plugin helper function:
<blockquote><code>
void exampleCallBack(void * ptr_to_api, int which_tool,
SDL_Surface * canvas, SDL_Surface * snapshot,
int x, int y);
</code></blockquote>
<br>
Example use of the "<code>line()</code>" helper (e.g., within a plugin's
<code>draw()</code> function):
<blockquote><code>
api->line((void *) api, which, canvas, snapshot, ox, oy,
x, y, 1, exampleCallBack);
</code></blockquote>
<br>
<li><code><b>Uint8 touched(int x, int y)</b></code><br>
This function allows you to avoid re-processing the same pixels multiple
times when the user drags the mouse across an area of the canvas, thus
increasing Tux Paint's response time, especially with math-heavy
effects.<br>
<br>
If your effect's "<code>click()</code>", "<code>drag()</code>" and/or
"<code>release()</code>" functions take the contents of the
source surface ("<code>snapshot</code>") and always create the same
results in the desintation surface ("<code>canvas</code>"), you should
wrap the effect in a call to "<code>api->touched()</code>".<br>
<br>
This function simply returns whether or not it had already been called for
the same (x,y) coordinates, since the user first clicked the mouse.
In other words, the first time you call it for a particular (x,y) coordinate,
it returns '0'. Future calls will return '1' until the user releases
the mouse button.<br>
<br>
<b>Note:</b> Magic effects that continuously affect the destination
surface ("<code>canvas</code>") (ignoring the "<code>snapshot</code>
surface) have no reason to use this function. The "Blur" and "Smudge"
tools that ship with Tux Paint are examples of such effects.<br>
<br>
</ul>
</blockquote>
<h4><a name="informational">Informational</a></h4>
<blockquote>
<ul>
<li><code><b>char * tp_version</b></code><br>
A string containing the version of Tux Paint that's running
(e.g., "0.9.18").<br>
<br>
<li><code><b>int canvas_w</b></code>
Returns the width of the drawing canvas.<br>
<br>
<li><code><b>int canvas_h</b></code>
Returns the height of the drawing canvas.<br>
<br>
<li><code><b>int button_down(void)</b></code><br>
A '1' is returned if the mouse button is down; '0' otherwise.<br>
<br>
<li><code><b>char * data_directory</b></code><br>
This string contains the directory where Tux Paint's data files are
stored. For example, on Linux, this may be
"<code>/usr/share/tuxpaint/</code>".<br>
<br>
Magic tools should include an icon (see "<code>get_icon()</code>", above)
and are encouraged to include sound effects, it's useful for plugins to
know where such things are located.<br>
<br>
When compiling and installing a plugin, the "<code>tp-magic-config</code>"
command-line tool should be used to determine where such data should be
placed for the installed version of Tux Paint to find them.
(See "<a href="#installing">Installing</a>," below.)<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>
</blockquote>
<h4><a name="syscalls">Tux Paint System Calls</a></h4>
<blockquote>
<ul>
<li><code><b>void show_progress_bar(void)</b></code><br>
Asks Tux Paint to animate and draw one frame of its progress bar
(at the bottom of the screen). Useful for routines that may take a
long time, to provide feedback to the user that Tux Paint has not
crashed or frozen.<br>
<br>
<li><code><b>void playsound(Mix_Chunk * snd, int pan,
int dist)</b></code><br>
This function plays a sound (one loaded by the SDL helper library
"SDL_mixer"). It uses SDL_mixer's "<code>Mix_SetPanning()</code>" to set
the volume of the sound on the left and right speakers, based on the
'<code>pan</code>' and '<code>dist</code>' values sent to it.<br>
<br>
A '<code>pan</code>' of 128 causes the sound to be played at equal volume
on the left and right speakers. A '<code>pan</code>' of 0 causes it to be
played completely on the left, and 255 completely on the right.<br>
<br>
The '<code>dist</code>' value affects overall volume. 255 is loudest,
and 0 is silent.<br>
<br>
The '<code>pan</code>' and '<code>dist</code>' values can be used to
simulate location and distance of the 'Magic' tool effect.<br>
<br>
<li><code><b>void stopsound(void)</b></code><br>
This function stops playing a sound played by <code>playsound()</code>.
It is useful to silence effects when the user stops using the tool
(in your '<code>release</code>' function).
<br>
<li><a name="special_notify">
<code><b>void special_notify(int flag)</b></code>
</a><br>
This function notifies Tux Paint of special events. Various values
defined in "<code>tp_magic_api.h</code>" can be 'or'ed together
(using C's boolean 'or': "<code>|</code>") and sent to this function.
<ul>
<li><code>SPECIAL_FLIP</code> — The contents of the canvas has been
flipped vertically.<br>
<br>
If a 'Starter' image was used as the basis of this image, it should be
flipped too, and a record of the flip should be stored as part of
Tux Paint's undo buffer stack. Additionally, the fact that the
starter has been flipped (or unflipped) should be recorded on disk
when the current drawing is saved.<br>
<br>
<li><code>SPECIAL_MIRROR</code> — Similar to <code>SPECIAL_FLIP</code>,
but for magic tools that mirror the contents of the canvas horizontally.
</ul>
<br>
</ul>
</blockquote>
<h4><a name="color_convs">Color Conversions</a></h4>
<blockquote>
<ul>
<li><code><b>float sRGB_to_linear(Uint8 srbg)</b></code><br>
Converts an 8-bit sRGB value (one between 0 and 255) to a linear
floating point value (between 0.0 and 1.0).<br>
<br>
<b>See also:</b>
<a href="http://en.wikipedia.org/wiki/SRGB">sRGB article at Wikipedia</a>.
<br>
<br>
<li><code><b>uint8 linear_to_sRGB(float linear)</b></code><br>
Converts a linear floating point value (one between 0.0 and 1.0) to
an 8-bit sRGB value (between 0 and 255).<br>
<br>
<li><code><b>void rgbtohsv(Uint8 r, Uint8 g, Uint8 b,
float * h, float * s, float * v)</b></code><br>
Converts 8-bit sRGB values (between 0 and 255) to floating-point
HSV (Hue, Saturation and Value) values (Hue between 0.0 and 360.0,
and Saturation and Value between 0.0 and 1.0).<br>
<br>
<b>See also:</b>
<a href="http://en.wikipedia.org/wiki/HSV_color_space">HSV Color Space
article at Wikipedia</a>.<br>
<br>
<li><code><b>void hsvtorgb(float h, float s, float v,
Uint8 * r, Uint8 * g, Uint8 * b)</b></code><br>
Converts floating-point HSV (Hue, Saturation and Value) values
(Hue between 0.0 and 360.0, and Saturation and Value between 0.0 and 1.0)
to 8-bit sRGB values (between 0 and 255).<br>
<br>
</ul>
</blockquote>
</blockquote>
<h3><a name="macros">Helper Macros in "<code>tp_magic_api.h</code>":</a></h3>
<blockquote>
<p>Along with the "<code>magic_api</code>" C structure containing functions
and data described above, the <code>tp_magic_api.h</code> C header file
also contains some helper macros that you may use.</p>
<ul>
<li><code><b>min(x, y)</b></code><br>
The minimum of 'x' and 'y'. (That is, if 'x' is less than or
equal to 'y', then the value of 'x' will be used. If 'y' is less than 'x',
it will be used.)<br>
<br>
<li><code><b>max(x, y)</b></code><br>
The maximum of 'x' and 'y'. The opposite of <code>min()</code>.<br>
<br>
<li><code><b>clamp(lo, value, hi)</b></code><br>
A value, clamped to be no smaller than 'lo', and no higher than 'hi'.
(That is, if 'value' is less than 'lo', then 'lo' will be used;
if 'value' is greater than 'hi', then 'hi' will be used;
otherwise, 'value' will be used.)<br>
<br>
<b>Example:</b> <code>red = clamp(0, n, 255);</code><br>
Tries to set 'red' to be the value of 'n', but without allowing it to
become less than 0 or greater than 255.<br>
<br>
<b>Note:</b> This macro is simply a <code>#define</code> of:
"<code>(min(max(value,lo),hi))</code>".<br>
<br>
</ul>
</blockquote>
<h3><a name="consts">Constant Defintions in "<code>tp_magic_api.h</code>":</a></h3>
<blockquote>
<p>The following is a summary of constant values that are set
(via "<code>#define</code>") within the 'Magic' tool API header file.</p>
<ul>
<li><code><b>TP_MAGIC_API_VERSION</b></code><br>
This integer value represents which version of the Tux Paint 'Magic'
tool API the header corresponds to.<br>
<br>
It should be referenced by your magic tool's "<code>api_version()</code>"
function, to inform the running copy of Tux Paint whether or not your
plugin is compatible.<br>
<br>
<b>Note:</b> This version number does not correspond to Tux Paint's
own release number (e.g., "0.9.18"). The API will not change every time
a new version of Tux Paint is released, which means plugins compiled
for earlier versions of Tux Paint will often run under newer
versions.<br>
<br>
<li><code><b>SPECIAL_MIRROR<br>
SPECIAL_FLIP</b></code><br>
These are flags for Tux Paint's "<code>special_notify()</code>"
helper function. They are described <a href="#special_notify">above</a>.<br>
<br>
</ul>
</blockquote>
</blockquote>
<hr size=1 noshade>
<h2><a name="compiling">Compiling</a></h2>
<blockquote>
<h3><a name="compiling-linux">Linux and other Unix-like Platforms</a></h3>
<blockquote>
<p>Use the C compiler's "<code>-shared</code>" command-line option to generate
a shared object file ("<code>.so</code>") based on your 'Magic' tool
plugin's C source code.</p>
<p>Use the "<code>tp-magic-config --cflags</code>" command,
supplied as part of Tux Paint — or in some cases, as part of a
"Tux Paint 'Magic' Tool Plugin Development package" —
to provide additional command-line flags to your C compiler that will help
it build your plugin.</p>
<h4>Command-Line Example</h4>
<blockquote>
<p>As a stand-alone command, using the GNU C Compiler and BASH shell,
for example:</p>
<blockquote>
<p><code>
$ gcc -shared `tp-magic-config --cflags` my_plugin.c -o my_plugin.so
</code></p>
</blockquote>
<p><a name="grave"><b>Note:</b></a>
The characters around the "<code>tp-magic-config</code>"
command are a grave/backtick/backquote
("<code><b><font size=+1>`</font></b></code>"), and
not an apostrophe/single-quote ("<code><b><font size=+1>'</font></b></code>").
They tell the shell to execute the command within (in this case,
"<code>tp-magic-config ...</code>"), and use its output
as an argument to the command being executed (in this case,
"<code>gcc ...</code>").</p>
</blockquote>
<h4>Makefile Example</h4>
<blockquote>
<p>A snippet from a Makefile to compile a Tux Paint "Magic" tool
plugin might look like this:</p>
<blockquote><table border=1 cellspacing=0 cellpadding=4><tr><td>
<p><code>
CFLAGS=-Wall -O2 $(shell tp-magic-config --cflags)<br>
<br>
my_plugin.so: my_plugin.c<br>
gcc -shared $(CFLAGS) -o my_plugin.so my_plugin.c
</code></p>
</td></tr></table></blockquote>
<p>The first line sets up Makefile variable ("<code>CFLAGS</code>") that
contains flags for the compiler. "<code>-Wall</code>" asks for all compiler
warnings to be shown. "<code>-O2</code>" asks for level 2 optimization.
"<code>($shell tp-magic-config --cflags)</code>" runs
"<code>tp-magic-config</code>" to retrieve additional compiler flags that
"Magic" tool plugins require. (The "<code>$(shell ...)</code>"
directive is similar to the <a href="#grave"><b><font size=+1>`</font></b>
("grave")</a> character in the BASH shell examples, above.)</p>
<p>The next line defines a Makefile target, "<code>my_plugin.so</code>",
and states that it <i>depends on</i> the C source file
"<code>my_plugin.c</code>". (Any time the C file changes, "<code>make</code>"
will know to recompile it and produce an updated "<code>.so</code>" file.
If the C file hadn't changed, it won't bother recompiling.)</p>
<p>The last line defines the command "<code>make</code>" should
run when it determines that it needs to (re)compile the "<code>.so</code>"
file. Here, we're using "<code>gcc</code>", with "<code>-shared</code> and
"<code>$(CFLAGS)</code>" command-line arguments, like above.
"<code>-o my_plugin.so</code>" tells the C compiler that the output file
should be "<code>my_plugin.so</code>". The last argument is the C file to
compile, in this case "<code>my_plugin.c</code>".</p>
<p><b>Note:</b> Commands listed below a Makefile target should be
intented using a single <b>tab</b> character.</p>
</blockquote>
<h4>Advanced Makefile</h4>
<blockquote>
<p>An even more generalized Makefile might look like this:</p>
<blockquote><table border=1 cellspacing=0 cellpadding=4><tr><td>
<p><code>
CFLAGS=-Wall -O2 $(shell tp-magic-config --cflags)<br>
<br>
my_plugin_1.so: my_plugin_1.c<br>
$(CC) -shared $(CFLAGS) -o $@ $<<br>
<br>
my_plugin_2.so: my_plugin_2.c<br>
$(CC) -shared $(CFLAGS) -o $@ $<
</code></p>
</td></tr></table></blockquote>
<p>As before, there are lines that define the command "<code>make</code>"
should run when it determines that it needs to (re)compile the
"<code>.so</code>" file(s). However, more general terms are used...</p>
<p>"<code>$(CC)</code>" gets expanded to your default C compiler (e.g.,
"<code>gcc</code>"). "<code>-shared</code> and "<code>$(CFLAGS)</code>"
are command-line arguments to the compiler, like above.
"<code>-o $@</code>" tells the C compiler what the output file
should be; "<code>make</code>" replaces "<code>$@</code>" with the name
of the target, in this case "<code>my_plugin_1.so</code>" or
"<code>my_plugin_2.so</code>". And finally,
the last argument is the C file to compile; "<code>make</code>" replaces
it with the target's dependency, in this case
"<code>my_plugin_1.c</code>" or "<code>my_plugin_2.c</code>".</p>
</blockquote>
</blockquote>
<h3><a name="compiling-windows">Windows</a></h3>
<blockquote>
<p>TBD</p>
</blockquote>
<h3><a name="compiling-osx">Mac OS X</a></h3>
<blockquote>
<p>TBD</p>
</blockquote>
</blockquote>
<hr size=1 noshade>
<h2><a name="installing">Installing</a></h2>
<blockquote>
<h3><a name="installing-linux">Linux and other Unix-like Platforms</a></h3>
<blockquote>
<p>Use the "<code>tp-magic-config</code>" command-line tool, supplied as
part of Tux Paint — or in some cases, as part of a "Tux
Paint 'Magic' Tool Plugin Development package" — to determine
where your plugins' files should go.</p>
<h4>Shared Object</h4>
<blockquote>
<p>Use "<code>tp-magic-config --pluginprefix</code>"
to determine where the plugin shared object ("<code>.so</code>")
files should be installed. The value returned by this command will be
the global location where the installed copy of Tux Paint looks
for plugins (e.g., "<code>/usr/lib/tuxpaint/plugins</code>").</p>
<p>Alternatively, you may use
"<code>tp-magic-config --localpluginprefix</code>" to find out where
Tux 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>
<blockquote>
<p><code>
# cp my_plugin.so `tp-magic-config --pluginprefix`<br>
# chmod 644 `tp-magic-config --pluginprefix`/my_plugin.so<br>
</code></p>
</blockquote>
<p><b>Note:</b> See the <a href="#grave">note above regarding the
"<font size=+1><b>`</b></font>" (grave) character</a>.</p>
</blockquote>
<h4>Documentation</h4>
<blockquote>
<p>Use the "<code>tp-magic-config --plugindocprefix</code>"
command to determine where documentation for your "Magic" tools should go.
The value returned by this command will be the location where the
documentation to the installed copy of Tux Paint is stored.
The main documentation includes a link to a folder where "Magic" tools'
documentation is expected to be installed</p>
(e.g., "<code>/usr/share/doc/tuxpaint/magic-docs</code>").</p>
<p><b>Note:</b> It's best to include both HTML and plain-text versions
of your documentation. An "<code>html</code>" subdirectory exists within
the "<code>magic-docs</code>" directory, and is where the HTML versions
should go.</p>
<p>As stand-alone commands, using the BASH shell, for example:</p>
<blockquote>
<p><code>
# cp my_plugin.html `tp-magic-config --plugindocprefix`/html<br>
# cp my_plugin.txt `tp-magic-config --plugindocprefix`
</code></p>
</blockquote>
<p><b>Note:</b> See the <a href="#grave">note above regarding the
"<font size=+1><b>`</b></font>" (grave) character</a>.</p>
<p><b>Note:</b> Currently, there is no "<code>--localplugindocprefix</code>"
option.</p>
</blockquote>
<h4>Icons, Sounds and other Data Files</h4>
<blockquote>
<p>Use the "<code>tp-magic-config --dataprefix</code>"
command, supplied as part of Tux Paint, to determine where data files
(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
"<code>data_directory</code>" string stored within the
"<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 --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 Paint's default Magic tool plugins install their
data within "<code>magic</code>" subdirectories of Tux Paint's
"<code>images</code>" and "<code>sounds</code>" data directories (e.g.,
"<code>/usr/share/tuxpaint/images/magic/</code>"). You are encouraged to
do the same.</p>
<p>As stand-alone commands, using the BASH shell, for example:</p>
<blockquote>
<p><code>
# cp my_plugin_icon.png `tp-magic-config --dataprefix`/images/magic/<br>
# chmod 644 `tp-magic-config --dataprefix`/images/magic/my_plugin_icon.png
</code></p>
</blockquote>
<p><b>Note:</b> See the <a href="#grave">note above regarding the
"<font size=+1><b>`</b></font>" (grave) character</a>.</p>
</blockquote>
<h4>Putting it Together in a Makefile</h4>
<blockquote>
<p>A snippet from a more generalized Makefile might look like this:</p>
<blockquote><table border=1 cellspacing=0 cellpadding=4><tr><td>
<p><code>
PLUGINPREFIX=$(shell tp-magic-config --pluginprefix)<br>
PLUGINDOCPREFIX=$(shell tp-magic-config --plugindocprefix)<br>
DATAPREFIX=$(shell tp-magic-config --dataprefix)<br>
<br>
install:<br>
#<br>
# Install plugin<br>
mkdir -p $(PLUGINPREFIX)<br>
cp *.so $(PLUGINPREFIX)/<br>
chmod 644 $(PLUGINPREFIX)/*.so<br>
#<br>
# Install icons<br>
mkdir -p $(DATAPREFIX)/images/magic<br>
cp icons/*.png $(DATAPREFIX)/images/magic/<br>
chmod 644 $(DATAPREFIX)/images/magic/*.png<br>
#<br>
# Install sound effects<br>
mkdir -p $(DATAPREFIX)/sounds/magic<br>
cp sounds/*.ogg $(DATAPREFIX)/sounds/magic/<br>
chmod 644 $(DATAPREFIX)/sounds/magic/*.ogg<br>
#<br>
# Install docs<br>
mkdir -p $(PLUGINDOCPREFIX)/html<br>
cp docs/*.html $(PLUGINDOCPREFIX)/html/<br>
cp docs/*.txt $(PLUGINDOCPREFIX)/<br>
chmod 644 $(PLUGINDOCPREFIX)/html/*.html<br>
chmod 644 $(PLUGINDOCPREFIX)/*.txt<br>
</code></p>
</td></tr></table></blockquote>
<p>The first three lines set up Makefile variables that contain the
paths returned by the "<code>tp-magic-config</code>" command-line tool.
(The "<code>$(shell ...)</code>" directive is similar to the
<a href="#grave"><b><font size=+1>`</font></b> ("grave")</a> character
in the BASH shell examples, above.)</p>
<p>Below that is an "<code>install</code>" target in the Makefile.
(Invoked by, for example, "<code>$ sudo make install</code>"
or "<code># make install</code>".)</p>
<p>The "<code>install</code>" target uses "<code>mkdir -p</code>" to
make sure that the plugin directory exists, then uses "<code>cp</code>" to
copy all plugin ("<code>.so</code>") files into it, and invokes
"<code>chmod</code>" to make sure they are readable.</p>
<p>It then does a similar series of commands to install icon files
("<code>.png</code>" images) and sound effects
("<code>.ogg</code>" files) into subdirectories within Tux Paint's
data directory, and to install documentation
("<code>.html</code>" and "<code>.txt</code>" files) within Tux Paint's
documentation directory.</p>
<p><b>Note:</b> The above Makefile example assumes the user will have
priveleges to install Tux Paint plugins system-wide.</p>
</blockquote>
</blockquote>
<h3><a name="installing-windows">Windows</a></h3>
<blockquote>
<p>TBD</p>
</blockquote>
<h3><a name="installing-osx">Mac OS X</a></h3>
<blockquote>
<p>TBD</p>
</blockquote>
</blockquote>
<hr size=1 noshade>
<h2><a name="multiple">Creating plugins with multiple effects</a></h2>
<blockquote>
<p>Plugins for Tux Paint may contain more than one effect. If you have
multiple effects that are similar, it may make sense to place them in one
plugin file, to reduce overhead and share code.</p>
<p>These following suggestions can help you create plugins that contain multiple
effects:</p>
<ul>
<li>Use a C "<code>enum</code>" to enumerate the effects, and count them.<br>
<blockquote><code>
enum {<br>
ONE_TOOL,<br>
ANOTHER_TOOL,<br>
AND_YET_ANOTHER_TOOL,<br>
NUM_TOOLS };
</code></blockquote>
<li>Return the value of "<code>NUM_TOOLS</code>" when
"<code>get_tool_count()</code>" is called, and compare "<code>which</code>"
values sent to other functions with the other enumerated values.<br>
<br>
<li>Create arrays of "<code>NUM_TOOLS</code>" length to contain effect-specific
data.<br>
<blockquote><code>
char * my_plugin_snd_filenames[NUM_TOOLS] = {<br>
"one.ogg", "another.ogg", "yet_another.ogg" };<br>
Mix_Chunk * my_plugin_snds[NUM_TOOLS];
</code></blockquote>
<li>Use a C "<code>for</code>"-loop to load or create the
effect-specific data (such as loading sound effects during your
"<code>init()</code>").<br>
<blockquote><code>
int i;<br>
char fname[1024];<br>
<br>
for (i = 0; i < NUM_TOOLS; i++)<br>
{<br>
/* Becomes, for example, "/usr/share/tuxpaint/sounds/magic/one.ogg" */<br>
<br>
snprintf(fname, sizeof(fname), "%s/sounds/magic/%s",<br>
api->data_prefix, my_plugin_snd_filenames[i];<br>
<br>
my_plugin_snds[i] = Mix_LoadWAV(fname);<br>
}
</code></blockquote>
<li>Similarly, do the same to free them later (such as freeing
sound effects during your "<code>shutdown()</code>").<br>
<blockquote><code>
int i;<br>
<br>
for (i = 0; i < NUM_TOOLS; i++)<br>
Mix_FreeChunk(my_plugin_snds[i]);
</code></blockquote>
<li>Use "<code>which</code>" values sent to your functions as an
index into those arrays (e.g., for playing the appropriate sound effect
for a tool).<br>
<br>
</ul>
<p><b>Note:</b> Even if your plugin currently contains only one effect,
it may be useful to follow the steps above so that you can add a new
variation of an effect with little effort. ("<code>NUM_TOOLS</code>" will
simply be '1', your arrays will be of length '1', etc.)</p>
</blockquote>
<hr size=1 noshade>
<h2><a name="examples">Example Code</a></h2>
<blockquote>
<p>The C source file
"<a href="../tp_magic_example.c"><code>tp_magic_example.c</code></a>" contains
a complete example of a plugin with multiple simple effects.</p>
</blockquote>
<hr size=1 noshade>
<h2><a name="help">Getting Help</a></h2>
<blockquote>
<p>For more information, check the Tux Paint website:
<a href="http://www.tuxpaint.org/">http://www.tuxpaint.org/</a>,
and the Simple DirectMedia Layer library website:
<a href="http://www.libsdl.org/">http://www.libsdl.org/</a>.</p>
<p>Additionally, other Tux Paint developers and users can be found on the
"<code>tuxpaint-devel</code>" and "<code>tuxpaint-users</code>"
mailing lists:
<a href="http://www.tuxpaint.org/lists/">http://www.tuxpaint.org/lists/</a>.</p>
</blockquote>
<hr size=1 noshade>
<h2><a name="glossary">Glossary</a></h2>
<ul>
<li><b>alpha:</b> See "RGBA"
<li><b>&:</b> See "ampersand"
<li><b>ampersand:</b> "<code>&</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 i;</code>". Later, "<code>&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>argument:</b> A value sent to a function.
<li><b>arrow:</b> "<code>-></code>". A symbol in C that references an element within a pointer to a struct.
<li><b>backquote:</b> See "grave."
<li><b>backtick:</b> See "grave."
<li><b>bit:</b> "Binary digit." Bits are the basic storage unit in a computer's memory, disk, networking, etc. They represent either 0 or 1. (Compared to a decimal digit, which can be anything between 0 and 9.) Just as a series of decimal digits can represent a larger number (e.g., "1" and "5" is fifteen (15)), so can bits (e.g., "1" and "0", is two). In decimal, we go from right to left: ones place, tens place, hundreds place, thousands place, etc. In binary, it is: ones place, twos place, fours place, eights place, etc. (See also "byte.")
<li><b>blue:</b> See "RGBA"
<li><b>boolean 'or':</b> 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".)
<li><b>|:</b> See "boolean 'or'"
<li><b>.:</b> See "dot"
<li><b>`:</b> See "grave."
<li><b>*:</b> See "star"
<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. As a series of bits, for example, the byte "00001100" represents the decimal value 12.
<li><b>callback:</b> <i>TBD</i>
<li><b>C enumeration:</b> A construct in C that allows you to label numeric values (usually starting at 0 and incrementing by one). (e.g., "<code>enum { ONE, TWO, THREE };</code>"
<li><b>C function:</b> <i>TBD</i>
<li><b>C header file:</b> <i>TBD</i>
<li><b>channel:</b> <i>TBD</i>
<li><b>click:</b> The action of pressing a button on a mouse.
<li><b>coordinates:</b> A set of numbers corresponding to a physical position; for example, in a two-dimensional (2D) image, "X" and "Y" coordinates specify the position across (left-to-right) and down the image, respectively. In SDL, the coordinates (0,0) is the top-leftmost pixel of a surface.
<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 Paint's "<code>rgbtohsv()</code>" and "<code>hsvtorgb()</code>".)
<li><b>C structure:</b> A construct in C that allows you to declare a new variable 'type' which may contain other types within. For example, SDL's "<code>SDL_Rect</code>" contains four integer values, the coordinates of the rectangle (X,Y), and its dimensions (width and height).
<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 RADIUS 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> 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>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>element:</b> A variable stored within a C structure. (Example: "<code>w</code>" and "<code>h</code>" elements of SDL_Surface store the surface's width and height, respectively.)
<li><b>enum:</b> See "C enumeration"
<li><b>float:</b> See "floating point"
<li><b>floating point:</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 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>function:</b> See "C function"
<li><b>gcc:</b> The GNU C compiler, a portable Open Source compiler. (See also the "<code>gcc(1)</code>" <i>man page</i>)
<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>green:</b> See "RGBA"
<li><b>->:</b> See "arrow"
<li><b>.h:</b> See "C header file"
<li><b>header:</b> See "C header file"
<li><b>header file:</b> See "C header file"
<li><b>HSV:</b> Hue, Saturation and Value. <i>TBD</i>
<li><b>hue:</b> See "HSV"
<li><b>IMG_Load():</b> An SDL_image function that loads an image file (e.g., a PNG) and returns it as an "<code>SDL_Surface *</code>".
<li><b>#include:</b> A C statement that asks the compiler to read the contents of another file (usually a header file).
<li><b>int:</b> See "integer"
<li><b>integer:</b> <i>TBD</i>
<li><b>libSDL:</b> See "Simple DirectMedia Layer"
<li><b>linear:</b> <i>TBD</i>
<li><b>macro:</b> A C construct that looks similar to a C function, but is simply a #define that is expanded 'inline'. For example, if you declared the macro "<code>#define ADD(A,B) ((A)+(B))</code>", and then used it with "<code>c = ADD(1,2);</code>", that line of code would literally expand to "<code>c = ((1) + (2));</code>", or more simply, "<code>c = 1 + 2;</code>".
<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 Paint.
<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> 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 Paint, made available via the "Magic" tool button.
<li><b>Mix_Chunk *:</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 *</code>").
<li><b>Mix_LoadWAV():</b> An SDL_mixer function that loads a sound file (WAV, Ogg Vorbis, etc.) and returns it as a "<code>Mix_Chunk *</code>".
<li><b>namespace:</b> <i>TBD</i>
<li><b>OGG</b>: See "Ogg Vorbis"
<li><b>Ogg Vorbis:</b> <i>TBD</i> (See also: "WAV")
<li><b>Plugin</b>: <i>TBD</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 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 "<code>png(5)</code> <i>man page</i>)
<li><b>pointer:</b> See "C pointer"
<li><b>red:</b> See "RGBA"
<li><b>release:</b> The action of releasing a button on a mouse.
<li><b>RGBA:</b> "Red, Green, Blue, Alpha." <i>TBD</i>
<li><b>RGB:</b> See "RBGA"
<li><b>saturation:</b> See "HSV"
<li><b>SDL:</b> See "Simple DirectMedia Layer"
<li><b>SDL_FreeSurface():</b> An libSDL function that frees (deallocates) memory allocated for an SDL surface ("<code>SDL_Surface *</code>"). (See also the "<code>SDL_FreeSurface(3)</code>" <i>man page</i>)
<li><b>SDL_GetRGB():</b> A libSDL function that, given a <code>Uint32</code> pixel value (e.g., one returned from the Tux Paint's Magic tool API helper function "<code>getpixel()</code>"), the format of the surface the pixel was taken from, and pointers to three <code>Uint8</code> variables, will place the Red, Green and Blue (RGB) values of the pixel into the three <code>Uint8</code> variables. (Example: "<code>SDL_GetRGB(getpixel(surf, x, y), surf->format, &r, &g, &b);</code>".) (See also the "<code>SDL_GetRGB(3)</code>" <i>man page</i>)
<li><b>SDL_MapRGB():</b> A libSDL function that, given the format of a surface and <code>Uint8</code> values representing Red, Green and Blue values for a pixel, returns a <code>Uint32</code> pixel value that can be placed in the surface (e.g., using Tux Paint's Magic tool API helper function "<code>putpixel()</code>"). (Example: "<code>putpixel(surf, x, y, SDL_MapRGB(surf->format, r, g, b));</code>".) (See also the "<code>SDL_MapRGB(3)</code>" <i>man page</i>)
<li><b>SDL_image:</b> A library on top of libSDL that can load various kinds of image files (e.g., PNG) and return them as an "<code>SDL_Surface *</code>".
<li><b>SDL_mixer:</b> A library on top of libSDL that can load various kinds of sound files (WAV, Ogg Vorbis, etc.) and play back multiple sounds at once (mix them).
<li><b>SDL_Rect:</b> A C structure defined by libSDL that represents a rectangular area. It contains elements representing the coordinates of the top left corner of the rectange (x,y) and the dimensions of the rectangle (w,h). (See also the "<code>SDL_Rect(3)</code>" <i>man page</i>)
<li><b>SDL_Surface *:</b> (A pointer to) a C structure defined by libSDL that contains a drawing surface. (See also the "<code>SDL_Surface(3)</code>" <i>man page</i>)
<li><b>Shared Object:</b> A piece of code that's compiled separately from the main application, and loaded dynamically, at runtime.
<li><b>Simple DirectMedia Layer:</b> A programming library that allows programs portable low level access to a video framebuffer, audio output, mouse, and keyboard. (See also: <a href="http://www.libsdl.org/">http://www.libsdl.org/</a>)
<li><b>snprintf():</b> A C function, related to "printf()", which takes a 'format' string and one or more additional arguments, and puts them together. "snprintf()" takes the resulting output and stores it into a string, making sure not to go beyond the string's buffer size (which must also be supplied). For example, assume a string "char str[20];" has been declared; "snprintf(str, 20, "Name: %s, Age: %d", "Bill", "32");" will store "Name: Bill, Age: 32" into 'str'. (See also the "<code>snprintf(3)</code>" <i>man page</i>)
<li><b>.so:</b> See "Shared Object"
<li><b>sRBG:</b> See "RGBA"
<li><b>star:</b> "<code>*</code>". A symbol in C that, when used in the declaration of variables (e.g., arguments to a function), denotes that the variable is a pointer. (For example, "<code>int * p;</code>" means that "<code>p</code>" is a <i>pointer</i> to an integer.) When used next to a pointer, it 'dereferences' the variable. (For example, later "<code>*p = 50;</code>" assigns the value of 50 to the memory that "<code>p</code>" points to; it does not change the value of "<code>p</code>", which is still a pointer to an integer. In essence, it changed the integer that's being pointed to.)
<li><b>strdup():</b> A C function that allocates enough memory to store a copy of a string, copies the string to it, and returns a "<code>char *</code>" pointer to the new copy. (See also the "<code>strdup(3)</code>" <i>man page</i>)
<li><b>struct:</b> See "C structure"
<li><b>The GIMP</b>: An Open Source image manipulation and paint program.
<li><b>tp_magic_api.h:</b> A header file that defines Tux Paint's Magic tool API. Plugins must '#include' it.
<li><b>tp-magic-config:</b> A command-line program that provides information about the installed version of Tux Paint to plugin developers (such as what C compiler flags they should compile with, and where plugin shared objects and data files should be installed). (See also the "<code>tp-magic-config(3)</code>" <i>man page</i>.)
<li><b>Uint32:</b> A 32-bit, unsigned integer (defined by libSDL). In other words, four bytes that can represent 0 through 4294967295. (Typically used to hold enough information to store three or four bytes representing a pixel's color; i.e., RBGA value).
<li><b>Uint8:</b> An 8-bit, unsigned integer (defined by libSDL). In other words, a byte that can represent 0 through 255.
<li><b>unsigned:</b> In C, a variable that can store a numeric value can be declared as either "signed" (the default), or "unsigned". In the former case, one bit of the value is used to denote the sign of the value (either positive or negative). In the latter case, the value can only be positive, but benefits from one extra bit of storage for the number. A signed byte (8 bits), for example, can represent any number between -128 and 127. An unsigned byte can go up to 255, but it cannot go below 0. For the purposes of graphics in SDL, unsigned values should be used for RGB values, since each channel (red, green and blue) may be between 0 (off) and 255 (brightest).
<li><b>value:</b> See "HSV"
<li><b>variable:</b> A construct in computer programming that contains a value which can be referenced again later by referring to the variable's name, and typically changed later. For example, a variable to hold someone's age could be declared as an integer: "int a;". It can be examined later: "if (a >= 18) { /* they are an adult */ } else { /* they are not an adult */ }".
<li><b>WAV:</b> <i>TBD</i> (See also "Ogg Vorbis")
<li><b>(w,h):</b> See "Dimensions"
<li><b>(x,y):</b> See "Coordinates"
</ul>
</body></html>
|