indent magic tool example code (tp_magic_example.c)
Sure, why not? Running `indent` on "tp_magic_example.c" in the Magic Tool development docs :-)
This commit is contained in:
parent
4ab8280bbe
commit
1bb6bbeef4
1 changed files with 93 additions and 99 deletions
|
|
@ -22,7 +22,8 @@
|
|||
|
||||
/* What tools we contain: */
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
TOOL_ONE, // Becomes '0'
|
||||
TOOL_TWO, // Becomes '1'
|
||||
NUM_TOOLS // Becomes '2'
|
||||
|
|
@ -83,12 +84,9 @@ Uint8 example_r, example_g, example_b;
|
|||
// that are declared _before_ them.
|
||||
|
||||
void example_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
|
||||
void example_line_callback(void * ptr, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y);
|
||||
void example_line_callback(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
|
||||
|
||||
|
||||
/* Setup Functions: */
|
||||
|
|
@ -137,9 +135,7 @@ int example_init(magic_api * api)
|
|||
// (The "tp-magic-config --dataprefix" command would have told us when
|
||||
// we installed our plugin and its data.)
|
||||
|
||||
snprintf(fname, sizeof(fname),
|
||||
"%s/sounds/magic/%s",
|
||||
api->data_directory, snd_filenames[i]);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/%s", api->data_directory, snd_filenames[i]);
|
||||
|
||||
printf("Trying to load %s sound file\n", fname);
|
||||
|
||||
|
|
@ -186,8 +182,7 @@ SDL_Surface * example_get_icon(magic_api * api, int which)
|
|||
// We use 'which' (which of our tools Tux Paint is asking about)
|
||||
// as an index into the array.
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/%s.png",
|
||||
api->data_directory, icon_filenames[which]);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/%s.png", api->data_directory, icon_filenames[which]);
|
||||
|
||||
|
||||
// Try to load the image, and return the results to Tux Paint:
|
||||
|
|
@ -309,8 +304,7 @@ void example_shutdown(magic_api * api)
|
|||
// Affect the canvas on click:
|
||||
|
||||
void example_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect)
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
// In our case, a single click (which is also the start of a drag!)
|
||||
// is identical to what dragging does, but just at one point, rather
|
||||
|
|
@ -326,8 +320,7 @@ void example_click(magic_api * api, int which, int mode,
|
|||
// Affect the canvas on drag:
|
||||
|
||||
void example_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
// Call Tux Paint's "line()" function.
|
||||
//
|
||||
|
|
@ -338,16 +331,27 @@ 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((void *) api, 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
|
||||
// (ox,oy) is always the top left, and (x,y) is always the bottom right,
|
||||
// so the values we put inside "update_rect" make sense:
|
||||
|
||||
if (ox > x) { int tmp = ox; ox = x; x = tmp; }
|
||||
if (oy > y) { int tmp = oy; oy = y; y = tmp; }
|
||||
if (ox > x)
|
||||
{
|
||||
int tmp = ox;
|
||||
|
||||
ox = x;
|
||||
x = tmp;
|
||||
}
|
||||
if (oy > y)
|
||||
{
|
||||
int tmp = oy;
|
||||
|
||||
oy = y;
|
||||
y = tmp;
|
||||
}
|
||||
|
||||
|
||||
// Fill in the elements of the "update_rect" SDL_Rect structure
|
||||
|
|
@ -369,8 +373,7 @@ void example_drag(magic_api * api, int which, SDL_Surface * canvas,
|
|||
// (So the sound will pan from speaker to speaker as you drag the
|
||||
// mouse around the canvas!)
|
||||
|
||||
api->playsound(snd_effect[which],
|
||||
(x * 255) / canvas->w, // pan
|
||||
api->playsound(snd_effect[which], (x * 255) / canvas->w, // pan
|
||||
255); // distance
|
||||
}
|
||||
|
||||
|
|
@ -378,8 +381,7 @@ void example_drag(magic_api * api, int which, SDL_Surface * canvas,
|
|||
// Affect the canvas on release:
|
||||
|
||||
void example_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect)
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
// Neither of our effects do anything special when the mouse is released
|
||||
// from a click or click-and-drag, so there's no code here...
|
||||
|
|
@ -423,9 +425,7 @@ void example_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b)
|
|||
// It pays attention to 'which' to determine which of our plugin's tools
|
||||
// is currently selected.
|
||||
|
||||
void example_line_callback(void * ptr, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y)
|
||||
void example_line_callback(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y)
|
||||
{
|
||||
// For technical reasons, we can't accept a pointer to the "magic_api"
|
||||
// struct, like the other functions do.
|
||||
|
|
@ -449,10 +449,7 @@ void example_line_callback(void * ptr, int which,
|
|||
// Tool number 1 simply draws a single pixel at the (x,y) location.
|
||||
// It's a 1x1 pixel brush
|
||||
|
||||
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format,
|
||||
example_r,
|
||||
example_g,
|
||||
example_b));
|
||||
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, example_r, example_g, example_b));
|
||||
|
||||
// We use "SDL_MapRGB()" to convert the RGB value we receive from Tux Paint
|
||||
// for the user's current color selection to a 'Uint32' pixel value
|
||||
|
|
@ -467,10 +464,7 @@ void example_line_callback(void * ptr, int which,
|
|||
{
|
||||
for (xx = -4; xx < 4; xx++)
|
||||
{
|
||||
api->putpixel(canvas, x + xx, y + yy,
|
||||
api->getpixel(snapshot,
|
||||
canvas->w - x - xx,
|
||||
canvas->h - y - yy));
|
||||
api->putpixel(canvas, x + xx, y + yy, api->getpixel(snapshot, canvas->w - x - xx, canvas->h - y - yy));
|
||||
|
||||
// We simply use Tux Paint's "getpixel()" routine to pull pixel
|
||||
// values from the 'snapshot', and then "putpixel()" to draw them
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue