Converted Magic tools to plugins.

Updated Magic tool API header.
This commit is contained in:
William Kendrick 2007-07-06 19:29:27 +00:00
parent 76f36e7d03
commit 2f3f118504
5 changed files with 34 additions and 425 deletions

View file

@ -1,153 +0,0 @@
/*
floodfill.c
For Tux Paint
Flood fill functions
Copyright (c) 2002-2006 by Bill Kendrick and others
bill@newbreedsoftware.com
http://www.newbreedsoftware.com/tuxpaint/
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)
June 14, 2002 - February 20, 2006
$Id$
*/
#include "floodfill.h"
#include "pixels.h"
#include "rgblinear.h"
#include "sounds.h"
#include "playsound.h"
#include "progressbar.h"
#include "debug.h"
/* For flood fill... */
static int colors_close(SDL_Surface * canvas, Uint32 c1, Uint32 c2)
{
#ifdef LOW_QUALITY_FLOOD_FILL
return (c1 == c2);
#else
Uint8 r1, g1, b1, r2, g2, b2;
if (c1 == c2)
{
/* Get it over with quick, if possible! */
return 1;
}
else
{
double r, g, b;
SDL_GetRGB(c1, canvas->format, &r1, &g1, &b1);
SDL_GetRGB(c2, canvas->format, &r2, &g2, &b2);
// use distance in linear RGB space
r = sRGB_to_linear_table[r1] - sRGB_to_linear_table[r2];
r *= r;
g = sRGB_to_linear_table[g1] - sRGB_to_linear_table[g2];
g *= g;
b = sRGB_to_linear_table[b1] - sRGB_to_linear_table[b2];
b *= b;
// easy to confuse:
// dark grey, brown, purple
// light grey, tan
// red, orange
return r + g + b < 0.04;
}
#endif
}
/* Flood fill! */
void do_flood_fill(SDL_Surface * screen, SDL_Surface * canvas, int x, int y,
Uint32 cur_colr, Uint32 old_colr)
{
int fillL, fillR, i, in_line;
static unsigned char prog_anim;
Uint32(*getpixel) (SDL_Surface *, int, int) =
getpixels[canvas->format->BytesPerPixel];
void (*putpixel) (SDL_Surface *, int, int, Uint32) =
putpixels[canvas->format->BytesPerPixel];
if (cur_colr == old_colr || colors_close(canvas, cur_colr, old_colr))
return;
fillL = x;
fillR = x;
prog_anim++;
if ((prog_anim % 4) == 0)
{
show_progress_bar(screen);
playsound(screen, 0, SND_BUBBLE, 0, x, SNDDIST_NEAR);
}
/* Find left side, filling along the way */
in_line = 1;
while (in_line)
{
putpixel(canvas, fillL, y, cur_colr);
fillL--;
in_line =
(fillL < 0) ? 0 : colors_close(canvas, getpixel(canvas, fillL, y),
old_colr);
}
fillL++;
/* Find right side, filling along the way */
in_line = 1;
while (in_line)
{
putpixel(canvas, fillR, y, cur_colr);
fillR++;
in_line = (fillR >= canvas->w) ? 0 : colors_close(canvas, getpixel(canvas,
fillR,
y),
old_colr);
}
fillR--;
/* Search top and bottom */
for (i = fillL; i <= fillR; i++)
{
if (y > 0 && colors_close(canvas, getpixel(canvas, i, y - 1), old_colr))
do_flood_fill(screen, canvas, i, y - 1, cur_colr, old_colr);
if (y < canvas->h
&& colors_close(canvas, getpixel(canvas, i, y + 1), old_colr))
do_flood_fill(screen, canvas, i, y + 1, cur_colr, old_colr);
}
}

View file

@ -1,39 +0,0 @@
/*
floodfill.h
For Tux Paint
Flood fill functions
Copyright (c) 2002-2006 by Bill Kendrick and others
bill@newbreedsoftware.com
http://www.newbreedsoftware.com/tuxpaint/
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)
June 14, 2002 - February 17, 2006
$Id$
*/
#ifndef FLOODFILL_H
#define FLOODFILL_H
#include "SDL.h"
void do_flood_fill(SDL_Surface * screen, SDL_Surface * canvas, int x, int y,
Uint32 cur_colr, Uint32 old_colr);
#endif

View file

@ -1,193 +0,0 @@
/*
tools.h
For Tux Paint
List of available tools.
Copyright (c) 2002-2006 by Bill Kendrick
bill@newbreedsoftware.com
http://www.newbreedsoftware.com/tuxpaint/
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)
June 29, 2002 - February 17, 2006
$Id$
*/
/* What tools are available: */
enum
{
MAGIC_FILL,
MAGIC_GRASS,
MAGIC_LARGEBRICK,
MAGIC_SMALLBRICK,
MAGIC_RAINBOW,
MAGIC_SPARKLES,
MAGIC_BLUR,
MAGIC_SMUDGE,
MAGIC_CHALK,
MAGIC_BLOCKS,
MAGIC_TINT,
MAGIC_DRIP,
MAGIC_CARTOON,
NUM_MAGICS
};
/* Need for the color selector: */
const int magic_colors[] = {
COLORSEL_ENABLE, // fill
COLORSEL_ENABLE, // grass
COLORSEL_ENABLE, // large bricks
COLORSEL_ENABLE, // small bricks
COLORSEL_DISABLE, // rainbow
COLORSEL_ENABLE, // sparkles
COLORSEL_DISABLE, // blur
COLORSEL_DISABLE, // smudge
COLORSEL_DISABLE, // chalk
COLORSEL_DISABLE, // blocks
COLORSEL_ENABLE, // tint
COLORSEL_DISABLE, // drip
COLORSEL_DISABLE, // cartoon
};
/* Magic tool names: */
const char *const magic_names[NUM_MAGICS] = {
gettext_noop("Fill"),
gettext_noop("Grass"),
gettext_noop("Bricks"),
gettext_noop("Bricks"),
gettext_noop("Rainbow"),
gettext_noop("Sparkles"),
gettext_noop("Blur"),
gettext_noop("Smudge"),
gettext_noop("Chalk"),
gettext_noop("Blocks"),
gettext_noop("Tint"),
gettext_noop("Drip"),
gettext_noop("Cartoon"),
};
/* Some text to write when each tool is selected: */
const char *const magic_tips[NUM_MAGICS] = {
gettext_noop("Click in the picture to fill that area with color."),
gettext_noop("Click and move to draw grass. Dont forget the dirt!"),
gettext_noop("Click and move to draw large bricks."),
gettext_noop("Click and move to draw small bricks."),
gettext_noop("You can draw in rainbow colors!"),
gettext_noop("Click and move to draw sparkles."),
gettext_noop("Click and move the mouse around to blur the picture."),
gettext_noop("Click and move the mouse around to smudge the picture."),
gettext_noop
("Click and move the mouse around to turn the picture into a chalk drawing."),
gettext_noop("Click and move the mouse around to make the picture blocky."),
gettext_noop
("Click and move the mouse around to change the pictures color."),
gettext_noop("Click and move the mouse around to make the picture drip."),
gettext_noop
("Click and move the mouse around to turn the picture into a cartoon."),
};
/* Tool icon filenames: */
const char *const magic_img_fnames[NUM_MAGICS] = {
DATA_PREFIX "images/magic/fill.png",
DATA_PREFIX "images/magic/grass.png",
DATA_PREFIX "images/magic/largebrick.png",
DATA_PREFIX "images/magic/smallbrick.png",
DATA_PREFIX "images/magic/rainbow.png",
DATA_PREFIX "images/magic/sparkles.png",
DATA_PREFIX "images/magic/blur.png",
DATA_PREFIX "images/magic/smudge.png",
DATA_PREFIX "images/magic/chalk.png",
DATA_PREFIX "images/magic/blocks.png",
DATA_PREFIX "images/magic/tint.png",
DATA_PREFIX "images/magic/drip.png",
DATA_PREFIX "images/magic/cartoon.png",
};
/* FIXME: Should we show different Tux icons depending on magic,
like tools? */
/* Rainbow color values: */
#define NUM_RAINBOW_COLORS 23
const int rainbow_hexes[NUM_RAINBOW_COLORS][3] = {
{255, 0, 0},
{255, 64, 0},
{255, 128, 0},
{255, 192, 0},
{255, 255, 0},
{192, 255, 0},
{128, 255, 0},
{64, 255, 0},
{0, 255, 0},
{0, 255, 64},
{0, 255, 128},
{0, 255, 192},
{0, 255, 255},
{0, 192, 255},
{0, 128, 255},
{0, 64, 255},
{64, 0, 255},
{128, 0, 255},
{192, 0, 255},
{255, 0, 255},
{255, 0, 192},
{255, 0, 128},
{255, 0, 64}
};

View file

@ -4,9 +4,9 @@
For Tux Paint
List of sound effects.
Copyright (c) 2002-2006 by Bill Kendrick and others
Copyright (c) 2002-2007 by Bill Kendrick and others
bill@newbreedsoftware.com
http://www.newbreedsoftware.com/tuxpaint/
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
@ -23,7 +23,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
June 15, 2002 - February 20, 2006
June 15, 2002 - July 5, 2007
$Id$
*/
@ -53,25 +53,8 @@ enum
SND_ERASER2,
SND_SAVE, /* Save sound effect */
SND_PROMPT, /* Prompt animation sound effect */
SND_DRIP, /* Magic drip */
SND_CHALK, /* Magic chalk */
SND_SPARKLES1, /* Magic sparkles */
SND_SPARKLES2,
SND_THICK, /* Magic thick */
SND_THIN, /* Magic thin */
SND_FLIP, /* Magic flip */
SND_MIRROR, /* Magic mirror */
SND_NEGATIVE, /* Magic negative */
SND_BLUR, /* Magic blur */
SND_BLOCKS, /* Magic blocks */
SND_FADE, /* Magic fade */
SND_DARKEN, /* Magic darken */
SND_RAINBOW, /* Magic rainbow */
SND_SMUDGE, /* Magic smudge */
SND_TINT, /* Magic tint */
SND_CARTOON, /* Magic cartoon */
SND_BRICK, /* Magic brick */
SND_GRASS, /* Magic grass */
SND_KEYCLICK, /* Text tool keyboard click feedback */
SND_KEYCLICKRING, /* Text tool keyboard click feedback with bell ring */
SND_RETURN, /* Text tool carriage return sound */
@ -82,6 +65,8 @@ enum
SND_AREYOUSURE, /* "Are you sure?" */
SND_YOUCANNOT, /* "No no no!" */
SND_TUXOK, /* "Ok" */
SND_THICK,
SND_THIN,
NUM_SOUNDS
};
@ -105,25 +90,8 @@ static const char *sound_fnames[NUM_SOUNDS] = {
DATA_PREFIX "sounds/eraser2.wav",
DATA_PREFIX "sounds/save.wav",
DATA_PREFIX "sounds/prompt.wav",
DATA_PREFIX "sounds/drip.wav",
DATA_PREFIX "sounds/chalk.wav",
DATA_PREFIX "sounds/sparkles1.wav",
DATA_PREFIX "sounds/sparkles2.wav",
DATA_PREFIX "sounds/thick.wav",
DATA_PREFIX "sounds/thin.wav",
DATA_PREFIX "sounds/flip.wav",
DATA_PREFIX "sounds/mirror.wav",
DATA_PREFIX "sounds/negative.wav",
DATA_PREFIX "sounds/blur.wav",
DATA_PREFIX "sounds/blocks.wav",
DATA_PREFIX "sounds/fade.wav",
DATA_PREFIX "sounds/darken.wav",
DATA_PREFIX "sounds/rainbow.wav",
DATA_PREFIX "sounds/smudge.wav",
DATA_PREFIX "sounds/tint.wav",
DATA_PREFIX "sounds/cartoon.wav",
DATA_PREFIX "sounds/brick.wav",
DATA_PREFIX "sounds/grass.wav",
DATA_PREFIX "sounds/keyclick.wav",
DATA_PREFIX "sounds/typewriterbell.wav",
DATA_PREFIX "sounds/return.wav",
@ -133,7 +101,9 @@ static const char *sound_fnames[NUM_SOUNDS] = {
DATA_PREFIX "sounds/italic_off.wav",
DATA_PREFIX "sounds/areyousure.wav",
DATA_PREFIX "sounds/youcannot.wav",
DATA_PREFIX "sounds/tuxok.wav"
DATA_PREFIX "sounds/tuxok.wav",
DATA_PREFIX "sounds/thick.wav",
DATA_PREFIX "sounds/thin.wav"
};
#endif

View file

@ -4,6 +4,26 @@
#include "SDL.h"
#include "SDL_mixer.h"
#ifdef __GNUC__
// This version has strict type checking for safety.
// See the "unnecessary" pointer comparison. (from Linux)
#define min(x,y) ({ \
typeof(x) _x = (x); \
typeof(y) _y = (y); \
(void) (&_x == &_y); \
_x < _y ? _x : _y; })
#define max(x,y) ({ \
typeof(x) _x = (x); \
typeof(y) _y = (y); \
(void) (&_x == &_y); \
_x > _y ? _x : _y; })
#else
#define min(a,b) (((a) < (b)) ? (a) : (b))
#define max(a,b) (((a) > (b)) ? (a) : (b))
#endif
#define clamp(lo,value,hi) (min(max(value,lo),hi))
#define SPECIAL_MIRROR 0x0001
#define SPECIAL_FLIP 0x0002
@ -12,13 +32,17 @@ typedef struct magic_api_t {
char * data_directory;
void (*update_progress_bar)(void);
void (*special_notify)(int);
float sRGB_to_linear_table[256];
unsigned char (*linear_to_sRGB)(float);
float (*sRGB_to_linear)(Uint8);
Uint8 (*linear_to_sRGB)(float);
int (*in_circle)(int,int,int);
Uint32 (*getpixel)(SDL_Surface *, int, int);
void (*putpixel)(SDL_Surface *, int, int, Uint32);
void (*playsound)(Mix_Chunk *, int, int);
void (*line)(int, SDL_Surface *, SDL_Surface *, int, int, int, int, int, void (*)(void *, int, SDL_Surface *, SDL_Surface *, int, int));
int (*button_down)(void);
void (*rgbtohsv)(Uint8, Uint8, Uint8, float *, float *, float *);
void (*hsvtorgb)(float, float, float, Uint8 *, Uint8 *, Uint8 *);
} magic_api;
#endif