Indentation.

This commit is contained in:
Pere Pujal i Carabantes 2017-12-19 02:17:27 +01:00
commit 1e0ea6d4b3
94 changed files with 26586 additions and 26244 deletions

9
.gitignore vendored Normal file
View file

@ -0,0 +1,9 @@
*.o
*.so
tuxpaint
obj/parse.c
obj/parse_step1.c
src/tp_magic_api.h
tp-magic-config
trans/
*~

View file

@ -10,6 +10,7 @@ $Id$
2017.xxx.x (0.9.23)
* New tools
---------
* Color selector
Pere Pujal i Carabantes
@ -102,6 +103,11 @@ $Id$
the program will crash
(SF.net Bug #210)
* Other Improvements:
-------------------
* Reformatted source code via GNU Indent tool; should
greatly increase code readability and formatting consistency.
2014.August.5 (0.9.22)
* New Tools:

View file

@ -11,9 +11,10 @@ static TYPE x UNUSED;
#endif
#ifdef SYMBOL
static int exists UNUSED = !!SYMBOL;
static int exists UNUSED = ! !SYMBOL;
#endif
int main(int argc UNUSED, char *argv[] UNUSED){
int main(int argc UNUSED, char *argv[]UNUSED)
{
return 0;
}

1
macosx/.indent.pro vendored Symbolic link
View file

@ -0,0 +1 @@
../src/.indent.pro

View file

@ -12,7 +12,7 @@
#import <Cocoa/Cocoa.h>
#import "TransparentTextView.h"
@interface SDLMain : NSObject
@ interface SDLMain:NSObject
{
IBOutlet NSWindow *messagePanel;
IBOutlet NSTextField *messageText;
@ -24,22 +24,25 @@
IBOutlet TransparentTextView *acknowledgmentsText;
}
- (IBAction)onAbout:(id)sender;
- (IBAction)onNew:(id)sender;
- (IBAction)onOpen:(id)sender;
- (IBAction)onSave:(id)sender;
- (IBAction)onPrint:(id)sender;
- (IBAction)onPageSetup:(id)sender;
- (IBAction)onUndo:(id)sender;
- (IBAction)onRedo:(id)sender;
- (IBAction)onHelp:(id)sender;
- (IBAction)onQuit:(id)sender;
-(IBAction) onAbout:(id) sender;
-(IBAction) onNew:(id) sender;
-(IBAction) onOpen:(id) sender;
-(IBAction) onSave:(id) sender;
-(IBAction) onPrint:(id) sender;
-(IBAction) onPageSetup:(id) sender;
-(IBAction) onUndo:(id) sender;
-(IBAction) onRedo:(id) sender;
-(IBAction) onHelp:(id) sender;
-(IBAction) onQuit:(id) sender;
- (void) sendSDLControlKeystroke:(int)key;
- (void) sendSDLControlShiftKeystroke:(int)key;
- (void) setupBridge;
-(void)sendSDLControlKeystroke:(int)key;
-(void)sendSDLControlShiftKeystroke:(int)key;
-(void)setupBridge;
- (void) displayMessage:(NSString*)message andStatus:(NSString*)status withProgressIndicator:(BOOL)progress;
- (void) hideMessage;
-(void)displayMessage:(NSString *)
message andStatus:(NSString *)
status withProgressIndicator:(BOOL) progress;
-(void)hideMessage;
@end

View file

@ -23,5 +23,5 @@
#define MSG_FONT_CACHE 1
void displayMessage( int msgId );
void displayMessage(int msgId);
void hideMessage();

View file

@ -17,27 +17,27 @@
// missing from wchar.h on Mac
wchar_t* wcsdup(const wchar_t* ws)
wchar_t *wcsdup(const wchar_t * ws)
{
wchar_t *ret;
size_t len;
len = wcslen (ws);
ret = malloc ((len + 1) * sizeof (wchar_t));
len = wcslen(ws);
ret = malloc((len + 1) * sizeof(wchar_t));
if (ret == 0)
return ret;
return (wcscpy (ret, ws));
return (wcscpy(ret, ws));
}
// missing, needed by __nl_find_msg in libintl.a(dcigettext.o)
// http://forums.macrumors.com/showthread.php?t=1284479
#undef iconv_t
typedef void* iconv_t;
extern size_t libiconv(iconv_t cd, char* * inbuf, size_t *inbytesleft, char* * outbuf, size_t *outbytesleft);
extern iconv_t libiconv_open(const char* tocode, const char* fromcode);
typedef void *iconv_t;
extern size_t libiconv(iconv_t cd, char * *inbuf, size_t * inbytesleft, char * *outbuf, size_t * outbytesleft);
extern iconv_t libiconv_open(const char *tocode, const char *fromcode);
size_t iconv(iconv_t cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
size_t iconv(iconv_t cd, char **inbuf, size_t * inbytesleft, char **outbuf, size_t * outbytesleft)
{
return libiconv(cd, inbuf, inbytesleft, outbuf, outbytesleft);
}
@ -50,7 +50,7 @@ iconv_t iconv_open(const char *tocode, const char *fromcode)
// to fix ineffective setlocale() in i18n.c or force language to Inuktitut
// must be called prior to setup_i18n()
patch_i18n(const char* locale)
patch_i18n(const char *locale)
{
setenv("LANG", locale, 1); // takes language passed as an argument
// setenv("LANG", "iu_CA.UTF-8", 1); // forces language to Inuktitut
@ -64,12 +64,13 @@ patch_i18n(const char* locale)
typedef unsigned su_int;
typedef long long di_int;
typedef unsigned long long du_int;
#ifdef __i386__
typedef int ti_int __attribute__ ((mode (DI)));
typedef unsigned tu_int __attribute__ ((mode (DI)));
typedef int ti_int __attribute__ ((mode(DI)));
typedef unsigned tu_int __attribute__ ((mode(DI)));
#else
typedef int ti_int __attribute__ ((mode (TI)));
typedef unsigned tu_int __attribute__ ((mode (TI)));
typedef int ti_int __attribute__ ((mode(TI)));
typedef unsigned tu_int __attribute__ ((mode(TI)));
#endif
typedef union
{
@ -83,22 +84,25 @@ typedef union
du_int high;
du_int low;
#endif /* _YUGA_LITTLE_ENDIAN */
}s;
} s;
} utwords;
// missing, needed by __umodti3 and __udivti3
// http://www.publicsource.apple.com/source/clang/clang-137/src/projects/compiler-rt/lib/udivmodti4.c
tu_int __udivmodti4(tu_int a, tu_int b, tu_int* rem)
tu_int __udivmodti4(tu_int a, tu_int b, tu_int * rem)
{
const unsigned n_udword_bits = sizeof(du_int) * CHAR_BIT;
const unsigned n_utword_bits = sizeof(tu_int) * CHAR_BIT;
utwords n;
n.all = a;
utwords d;
d.all = b;
utwords q;
utwords r;
unsigned sr;
/* special cases, X is unknown, K != 0 */
if (n.s.high == 0)
{
@ -198,6 +202,7 @@ tu_int __udivmodti4(tu_int a, tu_int b, tu_int* rem)
if (d.s.low == 1)
return n.all;
unsigned sr = __builtin_ctzll(d.s.low);
q.s.high = n.s.high >> sr;
q.s.low = (n.s.high << (n_udword_bits - sr)) | (n.s.low >> sr);
return q.all;
@ -206,8 +211,7 @@ tu_int __udivmodti4(tu_int a, tu_int b, tu_int* rem)
* ---
* 0 K
*/
sr = 1 + n_udword_bits + __builtin_clzll(d.s.low)
- __builtin_clzll(n.s.high);
sr = 1 + n_udword_bits + __builtin_clzll(d.s.low) - __builtin_clzll(n.s.high);
/* 2 <= sr <= n_utword_bits - 1
* q.all = n.all << (n_utword_bits - sr);
* r.all = n.all >> sr;
@ -234,20 +238,16 @@ tu_int __udivmodti4(tu_int a, tu_int b, tu_int* rem)
* r.s.low = n.s.high >> (sr - n_udword_bits);
* }
*/
q.s.low = (n.s.low << (n_utword_bits - sr)) &
((di_int)(int)(n_udword_bits - sr) >> (n_udword_bits-1));
q.s.high = ((n.s.low << ( n_udword_bits - sr)) &
((di_int)(int)(sr - n_udword_bits - 1) >> (n_udword_bits-1))) |
q.s.low = (n.s.low << (n_utword_bits - sr)) & ((di_int) (int)(n_udword_bits - sr) >> (n_udword_bits - 1));
q.s.high = ((n.s.low << (n_udword_bits - sr)) &
((di_int) (int)(sr - n_udword_bits - 1) >> (n_udword_bits - 1))) |
(((n.s.high << (n_utword_bits - sr)) |
(n.s.low >> (sr - n_udword_bits))) &
((di_int)(int)(n_udword_bits - sr) >> (n_udword_bits-1)));
r.s.high = (n.s.high >> sr) &
((di_int)(int)(sr - n_udword_bits) >> (n_udword_bits-1));
(n.s.low >> (sr - n_udword_bits))) & ((di_int) (int)(n_udword_bits - sr) >> (n_udword_bits - 1)));
r.s.high = (n.s.high >> sr) & ((di_int) (int)(sr - n_udword_bits) >> (n_udword_bits - 1));
r.s.low = ((n.s.high >> (sr - n_udword_bits)) &
((di_int)(int)(n_udword_bits - sr - 1) >> (n_udword_bits-1))) |
((di_int) (int)(n_udword_bits - sr - 1) >> (n_udword_bits - 1))) |
(((n.s.high << (n_udword_bits - sr)) |
(n.s.low >> sr)) &
((di_int)(int)(sr - n_udword_bits) >> (n_udword_bits-1)));
(n.s.low >> sr)) & ((di_int) (int)(sr - n_udword_bits) >> (n_udword_bits - 1)));
}
else
{
@ -280,11 +280,9 @@ tu_int __udivmodti4(tu_int a, tu_int b, tu_int* rem)
* r.s.low = n.s.high;
* }
*/
r.s.high = (n.s.high >> sr) &
((di_int)(int)(sr - n_udword_bits) >> (n_udword_bits-1));
r.s.high = (n.s.high >> sr) & ((di_int) (int)(sr - n_udword_bits) >> (n_udword_bits - 1));
r.s.low = (n.s.high << (n_udword_bits - sr)) |
((n.s.low >> sr) &
((di_int)(int)(sr - n_udword_bits) >> (n_udword_bits-1)));
((n.s.low >> sr) & ((di_int) (int)(sr - n_udword_bits) >> (n_udword_bits - 1)));
}
}
/* Not a special case
@ -294,6 +292,7 @@ tu_int __udivmodti4(tu_int a, tu_int b, tu_int* rem)
* 1 <= sr <= n_utword_bits - 1
*/
su_int carry = 0;
for (; sr > 0; --sr)
{
/* r:q = ((r:q) << 1) | carry */
@ -308,7 +307,8 @@ tu_int __udivmodti4(tu_int a, tu_int b, tu_int* rem)
* carry = 1;
* }
*/
const ti_int s = (ti_int)(d.all - r.all - 1) >> (n_utword_bits - 1);
const ti_int s = (ti_int) (d.all - r.all - 1) >> (n_utword_bits - 1);
carry = s & 1;
r.all -= d.all & s;
}
@ -323,6 +323,7 @@ tu_int __udivmodti4(tu_int a, tu_int b, tu_int* rem)
tu_int __umodti3(tu_int a, tu_int b)
{
tu_int r;
__udivmodti4(a, b, &r);
return r;
}
@ -335,7 +336,7 @@ tu_int __udivti3(tu_int a, tu_int b)
}
// missing, needed by __nl_log_untranslated in libintl.a(log.o) for 10.5
FILE* fopen$DARWIN_EXTSN(const char *filename, const char *mode)
FILE *fopen$DARWIN_EXTSN(const char *filename, const char *mode)
{
return fopen(filename, mode);
}
@ -347,7 +348,7 @@ int posix_memalign(void **ptr, size_t align, size_t size)
{
if (ptr)
{
*ptr = _mm_malloc (size, align);
*ptr = _mm_malloc(size, align);
return 0;
}
@ -359,7 +360,6 @@ int posix_memalign(void **ptr, size_t align, size_t size)
// missing in libpng<1.5, needed by _Load_SBit_Png in libfreetype.a(sfnt.o), _error_callback in libfreetype.a(sfnt.o)
// http://stackoverflow.com/questions/5190554/unresolved-external-png-set-longjmp-fn-in-libpng
// http://cpansearch.perl.org/src/JTPALMER/Alien-SDL-1.439_1/patches/SDL_image-1.2.10-libpng15.patch
typedef jmp_buf* (*png_set_longjmp_fnPtr)(png_structp, void*, size_t);
typedef jmp_buf *(*png_set_longjmp_fnPtr) (png_structp, void *, size_t);
png_set_longjmp_fnPtr png_set_longjmp_fn = 0;
#endif

View file

@ -11,4 +11,4 @@
#include <wchar.h>
wchar_t* wcsdup(const wchar_t*);
wchar_t *wcsdup(const wchar_t *);

View file

@ -21,5 +21,4 @@
// (See COPYING.txt)
//
void speak_string(const wchar_t *str);
void speak_string(const wchar_t * str);

View file

@ -22,7 +22,8 @@
/* What tools we contain: */
enum {
enum
{
TOOL_ONE, // Becomes '0'
TOOL_TWO, // Becomes '1'
NUM_TOOLS // Becomes '2'
@ -31,12 +32,12 @@ enum {
/* A list of filenames for sounds and icons to load at startup: */
const char * snd_filenames[NUM_TOOLS] = {
const char *snd_filenames[NUM_TOOLS] = {
"one.wav",
"two.wav"
};
const char * icon_filenames[NUM_TOOLS] = {
const char *icon_filenames[NUM_TOOLS] = {
"one.png",
"two.png"
};
@ -49,7 +50,7 @@ const char * icon_filenames[NUM_TOOLS] = {
/* A list of names for the tools */
const char * names[NUM_TOOLS] = {
const char *names[NUM_TOOLS] = {
gettext_noop("A tool"),
gettext_noop("Another tool")
};
@ -57,7 +58,7 @@ const char * names[NUM_TOOLS] = {
/* A list of descriptions of the tools */
const char * descs[NUM_TOOLS] = {
const char *descs[NUM_TOOLS] = {
gettext_noop("This is example tool number 1."),
gettext_noop("This is example tool number 2.")
};
@ -68,7 +69,7 @@ const char * descs[NUM_TOOLS] = {
/* --------------------- */
/* Sound effects: */
Mix_Chunk * snd_effect[NUM_TOOLS];
Mix_Chunk *snd_effect[NUM_TOOLS];
/* The current color (an "RGB" value) the user has selected in Tux Paint: */
Uint8 example_r, example_g, example_b;
@ -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: */
@ -105,7 +103,7 @@ void example_line_callback(void * ptr, int which,
Uint32 example_api_version(void)
{
return(TP_MAGIC_API_VERSION);
return (TP_MAGIC_API_VERSION);
}
@ -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);
@ -148,7 +144,7 @@ int example_init(magic_api * api)
snd_effect[i] = Mix_LoadWAV(fname);
}
return(1);
return (1);
}
@ -163,7 +159,7 @@ int example_init(magic_api * api)
int example_get_tool_count(magic_api * api)
{
return(NUM_TOOLS);
return (NUM_TOOLS);
}
@ -172,7 +168,7 @@ int example_get_tool_count(magic_api * api)
// When Tux Paint is starting up and loading plugins, it asks us to
// provide icons for the "Magic" tool buttons.
SDL_Surface * example_get_icon(magic_api * api, int which)
SDL_Surface *example_get_icon(magic_api * api, int which)
{
char fname[1024];
@ -186,13 +182,12 @@ 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:
return(IMG_Load(fname));
return (IMG_Load(fname));
}
@ -201,10 +196,10 @@ SDL_Surface * example_get_icon(magic_api * api, int which)
// When Tux Paint is starting up and loading plugins, it asks us to
// provide names (labels) for the "Magic" tool buttons.
char * example_get_name(magic_api * api, int which)
char *example_get_name(magic_api * api, int which)
{
const char * our_name_english;
const char * our_name_localized;
const char *our_name_english;
const char *our_name_localized;
// Get our name from the "names[]" array.
//
@ -226,7 +221,7 @@ char * example_get_name(magic_api * api, int which)
// send it to Tux Paint. (Tux Paint keeps track of the string and
// will free it for us, so we have one less thing to keep track of.)
return(strdup(our_name_localized));
return (strdup(our_name_localized));
}
@ -235,10 +230,10 @@ char * example_get_name(magic_api * api, int which)
// When Tux Paint is starting up and loading plugins, it asks us to
// provide names (labels) for the "Magic" tool buttons.
char * example_get_description(magic_api * api, int which, int mode)
char *example_get_description(magic_api * api, int which, int mode)
{
const char * our_desc_english;
const char * our_desc_localized;
const char *our_desc_english;
const char *our_desc_localized;
// Get our desc from the "descs[]" array.
//
@ -260,7 +255,7 @@ char * example_get_description(magic_api * api, int which, int mode)
// send it to Tux Paint. (Tux Paint keeps track of the string and
// will free it for us, so we have one less thing to keep track of.)
return(strdup(our_desc_localized));
return (strdup(our_desc_localized));
}
// Report whether we accept colors
@ -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.
@ -436,7 +436,7 @@ void example_line_callback(void * ptr, int which,
//
// (The "(magic_api *)" casts the generic pointer into the 'type' of
// pointer we want, a pointer to a "magic_api".)
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
int xx, yy;
@ -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

1
magic/src/.indent.pro vendored Symbolic link
View file

@ -0,0 +1 @@
../../src/.indent.pro

View file

@ -43,27 +43,32 @@
#define gettext_noop(String) String
#endif
static const double alien_ANGLE[] = {0,0,0};
static const double alien_FREQUENCY[] = {1,1,1};
static const double alien_ANGLE[] = { 0, 0, 0 };
static const double alien_FREQUENCY[] = { 1, 1, 1 };
static const int alien_RADIUS = 16;
enum {
enum
{
TOOL_alien,
alien_NUM_TOOLS
};
static Mix_Chunk * alien_snd_effect[alien_NUM_TOOLS];
static Mix_Chunk *alien_snd_effect[alien_NUM_TOOLS];
const char * alien_snd_filenames[alien_NUM_TOOLS] = {
const char *alien_snd_filenames[alien_NUM_TOOLS] = {
"alien.ogg",
};
const char * alien_icon_filenames[alien_NUM_TOOLS] = {
const char *alien_icon_filenames[alien_NUM_TOOLS] = {
"alien.png",
};
const char * alien_names[alien_NUM_TOOLS] = {
const char *alien_names[alien_NUM_TOOLS] = {
gettext_noop("Color Shift"),
};
const char * alien_descs[alien_NUM_TOOLS][2] = {
const char *alien_descs[alien_NUM_TOOLS][2] = {
{gettext_noop("Click and drag the mouse to change the colors in parts of your picture."),
gettext_noop("Click to change the colors in your entire picture."),},
};
@ -72,19 +77,16 @@ const char * alien_descs[alien_NUM_TOOLS][2] = {
Uint32 alien_api_version(void);
int alien_init(magic_api * api);
int alien_get_tool_count(magic_api * api);
SDL_Surface * alien_get_icon(magic_api * api, int which);
char * alien_get_name(magic_api * api, int which);
char * alien_get_description(magic_api * api, int which, int mode);
SDL_Surface *alien_get_icon(magic_api * api, int which);
char *alien_get_name(magic_api * api, int which);
char *alien_get_description(magic_api * api, int which, int mode);
void alien_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
Mix_Chunk * magic_loadsound(char* file);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
Mix_Chunk *magic_loadsound(char *file);
void alien_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void alien_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void alien_shutdown(magic_api * api);
void alien_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int alien_requires_colors(magic_api * api, int which);
@ -93,60 +95,70 @@ void alien_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
int alien_modes(magic_api * api, int which);
Uint32 alien_api_version(void) { return(TP_MAGIC_API_VERSION); }
Uint32 alien_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
//Load sounds
int alien_init(magic_api * api){
int alien_init(magic_api * api)
{
int i;
char fname[1024];
srand(time(0));
for (i = 0; i < alien_NUM_TOOLS; i++){
for (i = 0; i < alien_NUM_TOOLS; i++)
{
snprintf(fname, sizeof(fname), "%s/sounds/magic/%s", api->data_directory, alien_snd_filenames[i]);
alien_snd_effect[i] = Mix_LoadWAV(fname);
}
return(1);
return (1);
}
int alien_get_tool_count(magic_api * api ATTRIBUTE_UNUSED){
return(alien_NUM_TOOLS);
int alien_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return (alien_NUM_TOOLS);
}
// Load our icons:
SDL_Surface * alien_get_icon(magic_api * api, int which){
SDL_Surface *alien_get_icon(magic_api * api, int which)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, alien_icon_filenames[which]);
return(IMG_Load(fname));
return (IMG_Load(fname));
}
// Return our names, localized:
char * alien_get_name(magic_api * api ATTRIBUTE_UNUSED, int which){
return(strdup(gettext_noop(alien_names[which])));
char *alien_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
{
return (strdup(gettext_noop(alien_names[which])));
}
// Return our descriptions, localized:
char * alien_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode){
return(strdup(gettext_noop(alien_descs[which][mode-1])));
char *alien_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode)
{
return (strdup(gettext_noop(alien_descs[which][mode - 1])));
}
//Do the effect for one pixel
static void do_alien_pixel(void * ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
int x, int y){
magic_api * api = (magic_api *) ptr;
static void do_alien_pixel(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
{
magic_api *api = (magic_api *) ptr;
Uint8 temp[3];
double temp2[3];
int k;
SDL_GetRGB(api->getpixel(canvas,x, y), canvas->format, &temp[0], &temp[1], &temp[2]);
for (k =0;k<3;k++){
SDL_GetRGB(api->getpixel(canvas, x, y), canvas->format, &temp[0], &temp[1], &temp[2]);
for (k = 0; k < 3; k++)
{
//EP temp2[k] = clamp(0,127.5 * (1.0 + sin (((temp[k] / 127.5 - 1.0) * alien_FREQUENCY[k] + alien_ANGLE[k] / 180.0) * M_PI)),255);
temp2[k] = clamp(0.0,
127.5 * (
1.0 + sin (((temp[k] / 127.5 - 1.0) * alien_FREQUENCY[k] + alien_ANGLE[k] / 180.0) * M_PI)
),
127.5 * (1.0 +
sin(((temp[k] / 127.5 - 1.0) * alien_FREQUENCY[k] + alien_ANGLE[k] / 180.0) * M_PI)),
255.0);
}
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, temp2[0], temp2[1], temp2[2]));
@ -154,30 +166,33 @@ static void do_alien_pixel(void * ptr, int which ATTRIBUTE_UNUSED,
}
// Do the effect for the full image
static void do_alien_full(void * ptr,SDL_Surface * canvas, SDL_Surface * last, int which){
static void do_alien_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int which)
{
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
int x,y;
int x, y;
for (y = 0; y < last->h; y++){
for (x=0; x < last->w; x++){
for (y = 0; y < last->h; y++)
{
for (x = 0; x < last->w; x++)
{
do_alien_pixel(ptr, which, canvas, last, x, y);
}
}
}
//do the effect for the brush
static void do_alien_brush(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y){
static void do_alien_brush(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
int xx, yy;
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
for (yy = y - alien_RADIUS; yy < y + alien_RADIUS; yy++)
{
for (xx = x - alien_RADIUS; xx < x + alien_RADIUS; xx++)
{
if (api->in_circle(xx - x, yy - y, alien_RADIUS) &&
!api->touched(xx, yy))
if (api->in_circle(xx - x, yy - y, alien_RADIUS) && !api->touched(xx, yy))
{
do_alien_pixel(api, which, canvas, last, xx, yy);
}
@ -187,15 +202,27 @@ static void do_alien_brush(void * ptr, int which, SDL_Surface * canvas, SDL_Surf
// Affect the canvas on drag:
void alien_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect){
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_alien_brush);
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_alien_brush);
api->playsound(alien_snd_effect[which], (x * 255) / canvas->w, 255);
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;
}
update_rect->x = ox - alien_RADIUS;
update_rect->y = oy - alien_RADIUS;
@ -205,11 +232,13 @@ void alien_drag(magic_api * api, int which, SDL_Surface * canvas,
int use_sound = 1;
Mix_Chunk * magic_loadsound(char* file){
Mix_Chunk * temp;
Mix_Chunk *magic_loadsound(char *file)
{
Mix_Chunk *temp;
if (!use_sound){
return (Mix_Chunk*)-1;
if (!use_sound)
{
return (Mix_Chunk *) - 1;
}
temp = Mix_LoadWAV(file);
return temp;
@ -217,11 +246,12 @@ Mix_Chunk * magic_loadsound(char* file){
// Affect the canvas on click:
void alien_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect){
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
if (mode == MODE_PAINT)
alien_drag(api, which, canvas, last, x, y, x, y, update_rect);
else{
else
{
update_rect->x = 0;
update_rect->y = 0;
update_rect->w = canvas->w;
@ -243,15 +273,19 @@ void alien_shutdown(magic_api * api ATTRIBUTE_UNUSED)
{
//Clean up sounds
int i;
for(i=0; i<alien_NUM_TOOLS; i++){
if(alien_snd_effect[i] != NULL){
for (i = 0; i < alien_NUM_TOOLS; i++)
{
if (alien_snd_effect[i] != NULL)
{
Mix_FreeChunk(alien_snd_effect[i]);
}
}
}
// Record the color from Tux Paint:
void alien_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
void alien_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED)
{
}
@ -261,16 +295,17 @@ int alien_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_
return 0;
}
void alien_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void alien_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void alien_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void alien_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int alien_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_FULLSCREEN|MODE_PAINT);
return (MODE_FULLSCREEN | MODE_PAINT);
}

View file

@ -36,39 +36,39 @@ int BLIND_THICKNESS = 30;
int blind_side; /* 0 top, 1 left, 2 bottom, 3 right */
static Uint8 blind_r, blind_g, blind_b, blind_light;
enum blind_sides{
enum blind_sides
{
BLIND_SIDE_TOP,
BLIND_SIDE_LEFT,
BLIND_SIDE_BOTTOM,
BLIND_SIDE_RIGHT};
BLIND_SIDE_RIGHT
};
enum blind_tools{
enum blind_tools
{
BLIND_TOOL_BLIND,
BLIND_NUMTOOLS};
BLIND_NUMTOOLS
};
Mix_Chunk * blind_snd;
Mix_Chunk *blind_snd;
// Prototypes
Uint32 blind_api_version(void);
void blind_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int blind_init(magic_api * api);
int blind_get_tool_count(magic_api * api);
SDL_Surface * blind_get_icon(magic_api * api, int which);
char * blind_get_name(magic_api * api, int which);
char * blind_get_description(magic_api * api, int which, int mode);
SDL_Surface *blind_get_icon(magic_api * api, int which);
char *blind_get_name(magic_api * api, int which);
char *blind_get_description(magic_api * api, int which, int mode);
int blind_requires_colors(magic_api * api, int which);
void blind_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);
void blind_shutdown(magic_api * api);
void blind_paint_blind(void * ptr_to_api, int which_tool,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
void blind_paint_blind(void *ptr_to_api, int which_tool, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
void blind_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 blind_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void blind_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void blind_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int blind_modes(magic_api * api, int which);
@ -77,7 +77,7 @@ int blind_modes(magic_api * api, int which);
Uint32 blind_api_version(void)
{
return(TP_MAGIC_API_VERSION);
return (TP_MAGIC_API_VERSION);
}
void blind_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b) //get the colors from API and store it in structure
@ -94,7 +94,7 @@ int blind_init(magic_api * api)
snprintf(fname, sizeof(fname), "%s/sounds/magic/blind.ogg", api->data_directory);
blind_snd = Mix_LoadWAV(fname);
return(1);
return (1);
}
int blind_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
@ -102,24 +102,25 @@ int blind_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
return BLIND_NUMTOOLS;
}
SDL_Surface * blind_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
SDL_Surface *blind_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/images/magic/blind.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/blind.png", api->data_directory);
return(IMG_Load(fname));
return (IMG_Load(fname));
}
char * blind_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
char *blind_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return strdup(gettext_noop("Blind"));
}
char * blind_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
char *blind_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return strdup(gettext_noop("Click towards the edge of your picture to pull window blinds over it. Move perpendicularly to open or close the blinds."));
return
strdup(gettext_noop
("Click towards the edge of your picture to pull window blinds over it. Move perpendicularly to open or close the blinds."));
}
int blind_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
@ -140,12 +141,14 @@ void blind_shutdown(magic_api * api ATTRIBUTE_UNUSED)
// Interactivity functions
void blind_paint_blind(void * ptr_to_api, int which_tool ATTRIBUTE_UNUSED,
void blind_paint_blind(void *ptr_to_api, int which_tool ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
{
magic_api * api = (magic_api *) ptr_to_api;
magic_api *api = (magic_api *) ptr_to_api;
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, (blind_r + blind_light) / 2, (blind_g + blind_light) / 2, (blind_b + blind_light) / 2));
api->putpixel(canvas, x, y,
SDL_MapRGB(canvas->format, (blind_r + blind_light) / 2, (blind_g + blind_light) / 2,
(blind_b + blind_light) / 2));
}
/* void blind_do_blind(void * ptr_to_api, int which_tool,
@ -159,8 +162,7 @@ void blind_paint_blind(void * ptr_to_api, int which_tool ATTRIBUTE_UNUSED,
*/
void blind_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)
{
int opaque;
@ -168,20 +170,21 @@ void blind_drag(magic_api * api, int which, SDL_Surface * canvas,
switch (blind_side)
{
int i, j;
case BLIND_SIDE_TOP:
opaque = max((x * BLIND_THICKNESS) / canvas->w + 2, 2);
for (i = y;i >= 0; i -= BLIND_THICKNESS)
for (i = y; i >= 0; i -= BLIND_THICKNESS)
{
blind_light = 255;
for (j=i; j > i - opaque/2; j--)
for (j = i; j > i - opaque / 2; j--)
{
api->line(api, which, canvas, snapshot, 0, j, canvas->w, j, 1, blind_paint_blind);
blind_light -=20;
blind_light -= 20;
}
for (j = i - opaque/2; j > i - opaque; j--)
for (j = i - opaque / 2; j > i - opaque; j--)
{
api->line(api, which, canvas, snapshot, 0, j, canvas->w, j, 1, blind_paint_blind);
blind_light +=20;
blind_light += 20;
}
}
update_rect->x = 0;
@ -201,7 +204,7 @@ void blind_drag(magic_api * api, int which, SDL_Surface * canvas,
api->line(api, which, canvas, snapshot, 0, j, canvas->w, j, 1, blind_paint_blind);
blind_light -= 20;
}
for (j = i + opaque / 2; j < i + opaque; j ++)
for (j = i + opaque / 2; j < i + opaque; j++)
{
api->line(api, which, canvas, snapshot, 0, j, canvas->w, j, 1, blind_paint_blind);
blind_light += 20;
@ -225,7 +228,7 @@ void blind_drag(magic_api * api, int which, SDL_Surface * canvas,
api->line(api, which, canvas, snapshot, j, 0, j, canvas->h, 1, blind_paint_blind);
blind_light -= 20;
}
for (j = i + opaque / 2; j < i + opaque; j ++)
for (j = i + opaque / 2; j < i + opaque; j++)
{
api->line(api, which, canvas, snapshot, j, 0, j, canvas->h, 1, blind_paint_blind);
blind_light += 20;
@ -244,15 +247,15 @@ void blind_drag(magic_api * api, int which, SDL_Surface * canvas,
for (i = x; i >= 0; i -= BLIND_THICKNESS)
{
blind_light = 255;
for (j=i; j > i - opaque/2; j--)
for (j = i; j > i - opaque / 2; j--)
{
api->line(api, which, canvas, snapshot, j, 0, j, canvas->h, 1, blind_paint_blind);
blind_light -=20;
blind_light -= 20;
}
for (j = i - opaque/2; j > i - opaque; j--)
for (j = i - opaque / 2; j > i - opaque; j--)
{
api->line(api, which, canvas, snapshot, j, 0, j, canvas->h, 1, blind_paint_blind);
blind_light +=20;
blind_light += 20;
}
}
update_rect->x = 0;
@ -266,37 +269,44 @@ void blind_drag(magic_api * api, int which, SDL_Surface * canvas,
}
void blind_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
if (y < canvas->h / 2)
{
if (x < y) blind_side = 1; /* left */
else if (canvas->w - x < y) blind_side = 3; /* right */
else blind_side = 0; /* top */
if (x < y)
blind_side = 1; /* left */
else if (canvas->w - x < y)
blind_side = 3; /* right */
else
blind_side = 0; /* top */
}
else
{
if (x < canvas->h - y) blind_side = 1; /* left */
else if (canvas->w - x < canvas->h - y) blind_side = 3; /* right */
else blind_side = 2; /* bottom */
if (x < canvas->h - y)
blind_side = 1; /* left */
else if (canvas->w - x < canvas->h - y)
blind_side = 3; /* right */
else
blind_side = 2; /* bottom */
}
blind_drag(api, which, canvas, last, x, y, x, y, update_rect);
}
void blind_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void blind_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void blind_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void blind_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int blind_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_FULLSCREEN | MODE_PAINT);
return (MODE_FULLSCREEN | MODE_PAINT);
}

View file

@ -35,7 +35,8 @@
/* What tools we contain: */
enum {
enum
{
TOOL_BLOCKS,
TOOL_CHALK,
TOOL_DRIP,
@ -45,7 +46,7 @@ enum {
/* Our globals: */
static Mix_Chunk * snd_effect[NUM_TOOLS];
static Mix_Chunk *snd_effect[NUM_TOOLS];
/* Our function prototypes: */
@ -53,21 +54,16 @@ static Mix_Chunk * snd_effect[NUM_TOOLS];
int blocks_chalk_drip_init(magic_api * api);
Uint32 blocks_chalk_drip_api_version(void);
int blocks_chalk_drip_get_tool_count(magic_api * api);
SDL_Surface * blocks_chalk_drip_get_icon(magic_api * api, int which);
char * blocks_chalk_drip_get_name(magic_api * api, int which);
char * blocks_chalk_drip_get_description(magic_api * api, int which, int mode);
static void blocks_chalk_drip_linecb(void * ptr, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y);
SDL_Surface *blocks_chalk_drip_get_icon(magic_api * api, int which);
char *blocks_chalk_drip_get_name(magic_api * api, int which);
char *blocks_chalk_drip_get_description(magic_api * api, int which, int mode);
static void blocks_chalk_drip_linecb(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
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);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void blocks_chalk_drip_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void blocks_chalk_drip_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void blocks_chalk_drip_shutdown(magic_api * api);
void blocks_chalk_drip_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int blocks_chalk_drip_requires_colors(magic_api * api, int which);
@ -81,90 +77,82 @@ int blocks_chalk_drip_init(magic_api * api)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/sounds/magic/blocks.wav",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/sounds/magic/blocks.wav", api->data_directory);
snd_effect[0] = Mix_LoadWAV(fname);
snprintf(fname, sizeof(fname), "%s/sounds/magic/chalk.wav",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/sounds/magic/chalk.wav", api->data_directory);
snd_effect[1] = Mix_LoadWAV(fname);
snprintf(fname, sizeof(fname), "%s/sounds/magic/drip.wav",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/sounds/magic/drip.wav", api->data_directory);
snd_effect[2] = Mix_LoadWAV(fname);
return(1);
return (1);
}
Uint32 blocks_chalk_drip_api_version(void) { return(TP_MAGIC_API_VERSION); }
Uint32 blocks_chalk_drip_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
// We have multiple tools:
int blocks_chalk_drip_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return(NUM_TOOLS);
return (NUM_TOOLS);
}
// Load our icons:
SDL_Surface * blocks_chalk_drip_get_icon(magic_api * api, int which)
SDL_Surface *blocks_chalk_drip_get_icon(magic_api * api, int which)
{
char fname[1024];
if (which == TOOL_BLOCKS)
{
snprintf(fname, sizeof(fname), "%s/images/magic/blocks.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/blocks.png", api->data_directory);
}
else if (which == TOOL_CHALK)
{
snprintf(fname, sizeof(fname), "%s/images/magic/chalk.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/chalk.png", api->data_directory);
}
else if (which == TOOL_DRIP)
{
snprintf(fname, sizeof(fname), "%s/images/magic/drip.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/drip.png", api->data_directory);
}
return(IMG_Load(fname));
return (IMG_Load(fname));
}
// Return our names, localized:
char * blocks_chalk_drip_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
char *blocks_chalk_drip_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
{
if (which == TOOL_BLOCKS)
return(strdup(gettext_noop("Blocks")));
return (strdup(gettext_noop("Blocks")));
else if (which == TOOL_CHALK)
return(strdup(gettext_noop("Chalk")));
return (strdup(gettext_noop("Chalk")));
else if (which == TOOL_DRIP)
return(strdup(gettext_noop("Drip")));
return (strdup(gettext_noop("Drip")));
return(NULL);
return (NULL);
}
// Return our descriptions, localized:
char * blocks_chalk_drip_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
char *blocks_chalk_drip_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
{
if (which == TOOL_BLOCKS)
return(strdup(gettext_noop(
"Click and drag the mouse around to make the picture blocky.")));
return (strdup(gettext_noop("Click and drag the mouse around to make the picture blocky.")));
else if (which == TOOL_CHALK)
return(strdup(gettext_noop(
"Click and drag the mouse around to turn the picture into a chalk drawing.")));
return (strdup(gettext_noop("Click and drag the mouse around to turn the picture into a chalk drawing.")));
else if (which == TOOL_DRIP)
return(strdup(gettext_noop(
"Click and drag the mouse around to make the picture drip.")));
return (strdup(gettext_noop("Click and drag the mouse around to make the picture drip.")));
return(NULL);
return (NULL);
}
// Do the effect:
static void blocks_chalk_drip_linecb(void * ptr, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y)
static void blocks_chalk_drip_linecb(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
int xx, yy;
int h;
SDL_Rect src, dest;
@ -188,9 +176,11 @@ static void blocks_chalk_drip_linecb(void * ptr, int which,
Uint32 p_or = 0;
Uint32 p_and = ~0;
unsigned i = 16;
while (i--)
{
Uint32 p_tmp;
p_tmp = api->getpixel(last, xx + (i >> 2), yy + (i & 3));
p_or |= p_tmp;
p_and &= p_tmp;
@ -205,6 +195,7 @@ static void blocks_chalk_drip_linecb(void * ptr, int which,
double r_sum = 0.0;
double g_sum = 0.0;
double b_sum = 0.0;
i = 16;
while (i--)
{
@ -242,8 +233,7 @@ static void blocks_chalk_drip_linecb(void * ptr, int which,
dest.w = (rand() % 4) + 2;
dest.h = (rand() % 4) + 2;
colr = api->getpixel(last, clamp(0, xx, canvas->w - 1),
clamp(0, yy, canvas->h - 1));
colr = api->getpixel(last, clamp(0, xx, canvas->w - 1), clamp(0, yy, canvas->h - 1));
SDL_FillRect(canvas, &dest, colr);
}
}
@ -272,13 +262,24 @@ static void blocks_chalk_drip_linecb(void * ptr, int which,
// Affect the canvas on drag:
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)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *) api, 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; }
if (ox > x)
{
int tmp = ox;
ox = x;
x = tmp;
}
if (oy > y)
{
int tmp = oy;
oy = y;
y = tmp;
}
update_rect->x = ox - 16;
update_rect->y = oy - 16;
@ -290,8 +291,7 @@ void blocks_chalk_drip_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void blocks_chalk_drip_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
blocks_chalk_drip_drag(api, which, canvas, last, x, y, x, y, update_rect);
}
@ -325,15 +325,17 @@ int blocks_chalk_drip_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int whic
return 0;
}
void blocks_chalk_drip_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void blocks_chalk_drip_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void blocks_chalk_drip_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void blocks_chalk_drip_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int blocks_chalk_drip_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_PAINT); /* FIXME - Blocks and Chalk, at least, can also be turned into a full-image effect */
return (MODE_PAINT); /* FIXME - Blocks and Chalk, at least, can also be turned into a full-image effect */
}

View file

@ -42,18 +42,15 @@
Uint32 blur_api_version(void);
int blur_init(magic_api * api);
int blur_get_tool_count(magic_api * api);
SDL_Surface * blur_get_icon(magic_api * api, int which);
char * blur_get_name(magic_api * api, int which);
char * blur_get_description(magic_api * api, int which, int mode);
SDL_Surface *blur_get_icon(magic_api * api, int which);
char *blur_get_name(magic_api * api, int which);
char *blur_get_description(magic_api * api, int which, int mode);
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);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void blur_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void blur_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void blur_shutdown(magic_api * api);
void blur_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int blur_requires_colors(magic_api * api, int which);
@ -61,124 +58,147 @@ void blur_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void blur_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int blur_modes(magic_api * api, int which);
enum {
enum
{
TOOL_blur,
blur_NUM_TOOLS
};
static const int blur_RADIUS = 16;
static Mix_Chunk * blur_snd_effect[blur_NUM_TOOLS];
static Mix_Chunk *blur_snd_effect[blur_NUM_TOOLS];
const char *blur_snd_filenames[blur_NUM_TOOLS] = {
"blur.wav",
};
const char * blur_icon_filenames[blur_NUM_TOOLS] = {
const char *blur_icon_filenames[blur_NUM_TOOLS] = {
"blur.png",
};
const char * blur_names[blur_NUM_TOOLS] = {
const char *blur_names[blur_NUM_TOOLS] = {
gettext_noop("Blur"),
};
const char * blur_descs[blur_NUM_TOOLS][2] = {
const char *blur_descs[blur_NUM_TOOLS][2] = {
{gettext_noop("Click and drag the mouse around to blur the image."),
gettext_noop("Click to blur the entire image.")},
};
Uint32 blur_api_version(void) { return(TP_MAGIC_API_VERSION); }
Uint32 blur_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
//Load sounds
int blur_init(magic_api * api){
int blur_init(magic_api * api)
{
int i;
char fname[1024];
for (i = 0; i < blur_NUM_TOOLS; i++){
for (i = 0; i < blur_NUM_TOOLS; i++)
{
snprintf(fname, sizeof(fname), "%s/sounds/magic/%s", api->data_directory, blur_snd_filenames[i]);
blur_snd_effect[i] = Mix_LoadWAV(fname);
}
return(1);
return (1);
}
int blur_get_tool_count(magic_api * api ATTRIBUTE_UNUSED){
return(blur_NUM_TOOLS);
int blur_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return (blur_NUM_TOOLS);
}
// Load our icons:
SDL_Surface * blur_get_icon(magic_api * api, int which){
SDL_Surface *blur_get_icon(magic_api * api, int which)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, blur_icon_filenames[which]);
return(IMG_Load(fname));
return (IMG_Load(fname));
}
// Return our names, localized:
char * blur_get_name(magic_api * api ATTRIBUTE_UNUSED, int which){
return(strdup(gettext_noop(blur_names[which])));
char *blur_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
{
return (strdup(gettext_noop(blur_names[which])));
}
// Return our descriptions, localized:
char * blur_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode){
return(strdup(gettext_noop(blur_descs[which][mode-1])));
char *blur_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode)
{
return (strdup(gettext_noop(blur_descs[which][mode - 1])));
}
//Do the effect for one pixel
static void do_blur_pixel(void * ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y){
magic_api * api = (magic_api *) ptr;
int i,j,k;
static void do_blur_pixel(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
magic_api *api = (magic_api *) ptr;
int i, j, k;
Uint8 temp[3];
double blurValue[3];
//5x5 gaussiann weighting window
const int weight[5][5] = { {1,4,7,4,1},
{4,16,26,16,4},
{7,26,41,26,7},
{4,16,26,16,4},
{1,4,7,4,1}};
for (k =0;k<3;k++){
//5x5 gaussiann weighting window
const int weight[5][5] = { {1, 4, 7, 4, 1},
{4, 16, 26, 16, 4},
{7, 26, 41, 26, 7},
{4, 16, 26, 16, 4},
{1, 4, 7, 4, 1}
};
for (k = 0; k < 3; k++)
{
blurValue[k] = 0;
}
for (i=-2;i<3;i++){
for (j=-2;j<3;j++){
for (i = -2; i < 3; i++)
{
for (j = -2; j < 3; j++)
{
//Add the pixels around the current one wieghted
SDL_GetRGB(api->getpixel(last, x + i, y + j), last->format, &temp[0], &temp[1], &temp[2]);
for (k =0;k<3;k++){
blurValue[k] += temp[k]* weight[i+2][j+2];
for (k = 0; k < 3; k++)
{
blurValue[k] += temp[k] * weight[i + 2][j + 2];
}
}
}
for (k =0;k<3;k++){
for (k = 0; k < 3; k++)
{
blurValue[k] /= 273;
}
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, blurValue[0], blurValue[1], blurValue[2]));
}
// Do the effect for the full image
static void do_blur_full(void * ptr,SDL_Surface * canvas, SDL_Surface * last, int which){
static void do_blur_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int which)
{
//magic_api * api = (magic_api *) ptr;
int x,y;
int x, y;
for (y = 0; y < last->h; y++){
for (x=0; x < last->w; x++){
for (y = 0; y < last->h; y++)
{
for (x = 0; x < last->w; x++)
{
do_blur_pixel(ptr, which, canvas, last, x, y);
}
}
}
//do the effect for the brush
static void do_blur_brush(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y){
static void do_blur_brush(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
int xx, yy;
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
for (yy = y - blur_RADIUS; yy < y + blur_RADIUS; yy++)
{
for (xx = x - blur_RADIUS; xx < x + blur_RADIUS; xx++)
{
if (api->in_circle(xx - x, yy - y, blur_RADIUS) &&
!api->touched(xx, yy))
if (api->in_circle(xx - x, yy - y, blur_RADIUS) && !api->touched(xx, yy))
{
do_blur_pixel(api, which, canvas, last, xx, yy);
}
@ -188,15 +208,27 @@ static void do_blur_brush(void * ptr, int which, SDL_Surface * canvas, SDL_Surfa
// Affect the canvas on drag:
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){
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_blur_brush);
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_blur_brush);
api->playsound(blur_snd_effect[which], (x * 255) / canvas->w, 255);
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;
}
update_rect->x = ox - blur_RADIUS;
update_rect->y = oy - blur_RADIUS;
@ -206,11 +238,12 @@ void blur_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void blur_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect){
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
if (mode == MODE_PAINT)
blur_drag(api, which, canvas, last, x, y, x, y, update_rect);
else{
else
{
update_rect->x = 0;
update_rect->y = 0;
update_rect->w = canvas->w;
@ -232,15 +265,19 @@ void blur_shutdown(magic_api * api ATTRIBUTE_UNUSED)
{
//Clean up sounds
int i;
for(i=0; i<blur_NUM_TOOLS; i++){
if(blur_snd_effect[i] != NULL){
for (i = 0; i < blur_NUM_TOOLS; i++)
{
if (blur_snd_effect[i] != NULL)
{
Mix_FreeChunk(blur_snd_effect[i]);
}
}
}
// Record the color from Tux Paint:
void blur_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
void blur_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED)
{
}
@ -250,15 +287,17 @@ int blur_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_U
return 0;
}
void blur_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void blur_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void blur_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void blur_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int blur_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_FULLSCREEN|MODE_PAINT);
return (MODE_FULLSCREEN | MODE_PAINT);
}

View file

@ -38,7 +38,8 @@
/* What tools we contain: */
enum {
enum
{
TOOL_LARGEBRICKS,
TOOL_SMALLBRICKS,
NUM_TOOLS
@ -47,29 +48,24 @@ enum {
/* Our globals: */
static Mix_Chunk * brick_snd;
static Mix_Chunk *brick_snd;
static Uint8 bricks_r, bricks_g, bricks_b;
/* Local function prototype: */
static void do_brick(magic_api * api, SDL_Surface * canvas,
int x, int y, int w, int h);
static void do_brick(magic_api * api, SDL_Surface * canvas, int x, int y, int w, int h);
int bricks_init(magic_api * api);
Uint32 bricks_api_version(void);
int bricks_get_tool_count(magic_api * api);
SDL_Surface * bricks_get_icon(magic_api * api, int which);
char * bricks_get_name(magic_api * api, int which);
char * bricks_get_description(magic_api * api, int which, int mode);
SDL_Surface *bricks_get_icon(magic_api * api, int which);
char *bricks_get_name(magic_api * api, int which);
char *bricks_get_description(magic_api * api, int which, int mode);
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);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void bricks_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
void bricks_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect); //An empty function. Is there a purpose to this? Ask moderator.
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void bricks_release(magic_api * api, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect); //An empty function. Is there a purpose to this? Ask moderator.
void bricks_shutdown(magic_api * api);
void bricks_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int bricks_requires_colors(magic_api * api, int which);
@ -82,65 +78,64 @@ int bricks_init(magic_api * api)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/sounds/magic/brick.wav",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/sounds/magic/brick.wav", api->data_directory);
brick_snd = Mix_LoadWAV(fname);
return(1);
return (1);
}
Uint32 bricks_api_version(void) { return(TP_MAGIC_API_VERSION); }
Uint32 bricks_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
// We have multiple tools:
int bricks_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return(NUM_TOOLS);
return (NUM_TOOLS);
}
// Load our icons:
SDL_Surface * bricks_get_icon(magic_api * api, int which)
SDL_Surface *bricks_get_icon(magic_api * api, int which)
{
char fname[1024];
if (which == TOOL_LARGEBRICKS)
{
snprintf(fname, sizeof(fname), "%s/images/magic/largebrick.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/largebrick.png", api->data_directory);
}
else if (which == TOOL_SMALLBRICKS)
{
snprintf(fname, sizeof(fname), "%s/images/magic/smallbrick.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/smallbrick.png", api->data_directory);
}
return(IMG_Load(fname));
return (IMG_Load(fname));
}
// Return our names, localized:
char * bricks_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
char *bricks_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
/* Both are named "Bricks", at the moment: */
return(strdup(gettext_noop("Bricks")));
return (strdup(gettext_noop("Bricks")));
}
// Return our descriptions, localized:
char * bricks_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
char *bricks_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
{
if (which == TOOL_LARGEBRICKS)
return(strdup(gettext_noop("Click and drag to draw large bricks.")));
return (strdup(gettext_noop("Click and drag to draw large bricks.")));
else if (which == TOOL_SMALLBRICKS)
return(strdup(gettext_noop("Click and drag to draw small bricks.")));
return (strdup(gettext_noop("Click and drag to draw small bricks.")));
return(NULL);
return (NULL);
}
// Do the effect:
static void do_bricks(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
int x, int y)
static void do_bricks(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
{
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
// "specified" means the brick itself, w/o morter
// "nominal" means brick-to-brick (includes morter)
@ -185,11 +180,11 @@ static void do_bricks(void * ptr, int which, SDL_Surface * canvas, SDL_Surface *
mybrick = map + brick_x + 1 + (brick_y + 1) * x_count;
if ((unsigned) x < (unsigned) canvas->w
&& (unsigned) y < (unsigned) canvas->h && !*mybrick)
if ((unsigned)x < (unsigned)canvas->w && (unsigned)y < (unsigned)canvas->h && !*mybrick)
{
int my_x = brick_x * nominal_width;
int my_w = specified_width;
*mybrick = 1;
@ -206,8 +201,7 @@ static void do_bricks(void * ptr, int which, SDL_Surface * canvas, SDL_Surface *
my_x -= nominal_width;
my_w = specified_length;
}
do_brick(api, canvas, my_x, brick_y * nominal_height,
my_w, specified_height);
do_brick(api, canvas, my_x, brick_y * nominal_height, my_w, specified_height);
// FIXME:
@ -227,13 +221,24 @@ static void do_bricks(void * ptr, int which, SDL_Surface * canvas, SDL_Surface *
// Affect the canvas on drag:
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)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *) api, 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; }
if (ox > x)
{
int tmp = ox;
ox = x;
x = tmp;
}
if (oy > y)
{
int tmp = oy;
oy = y;
y = tmp;
}
update_rect->x = x - 64;
update_rect->y = y - 64;
@ -245,8 +250,7 @@ void bricks_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void bricks_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
bricks_drag(api, which, canvas, last, x, y, x, y, update_rect);
}
@ -278,23 +282,16 @@ int bricks_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE
return 1;
}
static void do_brick(magic_api * api, SDL_Surface * canvas,
int x, int y, int w, int h)
static void do_brick(magic_api * api, SDL_Surface * canvas, int x, int y, int w, int h)
{
SDL_Rect dest;
// brick color: 127,76,73
double ran_r = rand() / (double) RAND_MAX;
double ran_g = rand() / (double) RAND_MAX;
double base_r =
api->sRGB_to_linear(bricks_r) * 1.5 +
api->sRGB_to_linear(127) * 5.0 + ran_r;
double base_g =
api->sRGB_to_linear(bricks_g) * 1.5 +
api->sRGB_to_linear(76) * 5.0 + ran_g;
double base_b =
api->sRGB_to_linear(bricks_b) * 1.5 +
api->sRGB_to_linear(73) * 5.0 + (ran_r + ran_g * 2.0) / 3.0;
double ran_r = rand() / (double)RAND_MAX;
double ran_g = rand() / (double)RAND_MAX;
double base_r = api->sRGB_to_linear(bricks_r) * 1.5 + api->sRGB_to_linear(127) * 5.0 + ran_r;
double base_g = api->sRGB_to_linear(bricks_g) * 1.5 + api->sRGB_to_linear(76) * 5.0 + ran_g;
double base_b = api->sRGB_to_linear(bricks_b) * 1.5 + api->sRGB_to_linear(73) * 5.0 + (ran_r + ran_g * 2.0) / 3.0;
Uint8 r = api->linear_to_sRGB(base_r / 7.5);
Uint8 g = api->linear_to_sRGB(base_g / 7.5);
@ -326,5 +323,5 @@ void bricks_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUS
int bricks_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_PAINT);
return (MODE_PAINT);
}

View file

@ -41,32 +41,29 @@ typedef struct
float x, y;
} Point2D;
static Mix_Chunk * calligraphy_snd;
static Mix_Chunk *calligraphy_snd;
static Point2D calligraphy_control_points[4];
static int calligraphy_r, calligraphy_g, calligraphy_b;
static int calligraphy_old_thick;
static Uint32 calligraphy_last_time;
static SDL_Surface * calligraphy_brush, * calligraphy_colored_brush;
static SDL_Surface *calligraphy_brush, *calligraphy_colored_brush;
/* Local Function Prototypes */
static Point2D calligraphy_PointOnCubicBezier(Point2D* cp, float t);
static void calligraphy_ComputeBezier(Point2D* cp, int numberOfPoints, Point2D* curve);
static Point2D calligraphy_PointOnCubicBezier(Point2D * cp, float t);
static void calligraphy_ComputeBezier(Point2D * cp, int numberOfPoints, Point2D * curve);
static float calligraphy_dist(float x1, float y1, float x2, float y2);
int calligraphy_init(magic_api * api);
Uint32 calligraphy_api_version(void);
int calligraphy_get_tool_count(magic_api * api);
SDL_Surface * calligraphy_get_icon(magic_api * api, int which);
char * calligraphy_get_name(magic_api * api, int which);
char * calligraphy_get_description(magic_api * api, int which, int mode);
SDL_Surface *calligraphy_get_icon(magic_api * api, int which);
char *calligraphy_get_name(magic_api * api, int which);
char *calligraphy_get_description(magic_api * api, int which, int mode);
void calligraphy_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void calligraphy_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void calligraphy_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void calligraphy_shutdown(magic_api * api);
void calligraphy_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int calligraphy_requires_colors(magic_api * api, int which);
@ -79,19 +76,17 @@ int calligraphy_init(magic_api * api)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/sounds/magic/calligraphy.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/sounds/magic/calligraphy.ogg", api->data_directory);
calligraphy_snd = Mix_LoadWAV(fname);
snprintf(fname, sizeof(fname), "%s/images/magic/calligraphy_brush.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/calligraphy_brush.png", api->data_directory);
calligraphy_brush = IMG_Load(fname);
calligraphy_colored_brush = NULL;
if (calligraphy_brush == NULL)
return(0);
return (0);
calligraphy_last_time = 0;
@ -100,46 +95,47 @@ int calligraphy_init(magic_api * api)
calligraphy_g = -1;
calligraphy_b = -1;
return(1);
return (1);
}
Uint32 calligraphy_api_version(void) { return(TP_MAGIC_API_VERSION); }
Uint32 calligraphy_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
// Only one tool:
int calligraphy_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return(1);
return (1);
}
// Load our icon:
SDL_Surface * calligraphy_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
SDL_Surface *calligraphy_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/images/magic/calligraphy.png",
api->data_directory);
return(IMG_Load(fname));
snprintf(fname, sizeof(fname), "%s/images/magic/calligraphy.png", api->data_directory);
return (IMG_Load(fname));
}
// Return our name, localized:
char * calligraphy_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
char *calligraphy_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(strdup(gettext_noop("Calligraphy")));
return (strdup(gettext_noop("Calligraphy")));
}
// Return our description, localized:
char * calligraphy_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
char *calligraphy_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED)
{
return(strdup(
gettext_noop("Click and drag the mouse around to draw in calligraphy.")));
return (strdup(gettext_noop("Click and drag the mouse around to draw in calligraphy.")));
}
void calligraphy_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
SDL_Surface * last ATTRIBUTE_UNUSED, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * last ATTRIBUTE_UNUSED, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
Point2D * curve;
Point2D *curve;
int i, n_points, thick, new_thick;
Uint32 colr;
SDL_Rect src, dest;
@ -178,9 +174,7 @@ void calligraphy_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface *
calligraphy_control_points[2].x,
calligraphy_control_points[2].y) +
calligraphy_dist(calligraphy_control_points[2].x,
calligraphy_control_points[2].y,
calligraphy_control_points[3].x,
calligraphy_control_points[3].y);
calligraphy_control_points[2].y, calligraphy_control_points[3].x, calligraphy_control_points[3].y);
if (n_points == 0)
return; // No-op; not any points to plot
@ -190,17 +184,13 @@ void calligraphy_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface *
calligraphy_ComputeBezier(calligraphy_control_points, n_points, curve);
colr = SDL_MapRGB(canvas->format,
calligraphy_r,
calligraphy_g,
calligraphy_b);
colr = SDL_MapRGB(canvas->format, calligraphy_r, calligraphy_g, calligraphy_b);
new_thick = 40 - min((n_points /* / 2 */), 32);
new_thick = 40 - min((n_points /* / 2 */ ), 32);
for (i = 0; i < n_points - 1; i++)
{
thick = ((new_thick * i) +
(calligraphy_old_thick * (n_points - i))) / n_points;
thick = ((new_thick * i) + (calligraphy_old_thick * (n_points - i))) / n_points;
/* The new way, using an antialiased brush bitmap */
@ -253,8 +243,20 @@ void calligraphy_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface *
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;
}
update_rect->x = ox - 16;
update_rect->y = oy - 16;
@ -313,9 +315,7 @@ void calligraphy_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b)
Uint8 a;
Uint32 amask;
if (calligraphy_r == r &&
calligraphy_g == g &&
calligraphy_b == b)
if (calligraphy_r == r && calligraphy_g == g && calligraphy_b == b)
return;
calligraphy_r = r;
@ -325,9 +325,7 @@ void calligraphy_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b)
if (calligraphy_colored_brush != NULL)
SDL_FreeSurface(calligraphy_colored_brush);
amask = ~(calligraphy_brush->format->Rmask |
calligraphy_brush->format->Gmask |
calligraphy_brush->format->Bmask);
amask = ~(calligraphy_brush->format->Rmask | calligraphy_brush->format->Gmask | calligraphy_brush->format->Bmask);
calligraphy_colored_brush =
SDL_CreateRGBSurface(SDL_SWSURFACE,
@ -335,8 +333,7 @@ void calligraphy_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b)
calligraphy_brush->h,
calligraphy_brush->format->BitsPerPixel,
calligraphy_brush->format->Rmask,
calligraphy_brush->format->Gmask,
calligraphy_brush->format->Bmask, amask);
calligraphy_brush->format->Gmask, calligraphy_brush->format->Bmask, amask);
if (calligraphy_colored_brush == NULL)
return; // FIXME: Error!
@ -349,14 +346,10 @@ void calligraphy_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b)
{
for (x = 0; x < calligraphy_brush->w; x++)
{
SDL_GetRGBA(api->getpixel(calligraphy_brush, x, y),
calligraphy_brush->format, &r, &g, &b, &a);
SDL_GetRGBA(api->getpixel(calligraphy_brush, x, y), calligraphy_brush->format, &r, &g, &b, &a);
api->putpixel(calligraphy_colored_brush, x, y,
SDL_MapRGBA(calligraphy_colored_brush->format,
calligraphy_r,
calligraphy_g,
calligraphy_b, a));
SDL_MapRGBA(calligraphy_colored_brush->format, calligraphy_r, calligraphy_g, calligraphy_b, a));
}
}
@ -384,7 +377,7 @@ cp[3] is the end point, or P3 in the above diagram
t is the parameter value, 0 <= t <= 1
*/
static Point2D calligraphy_PointOnCubicBezier( Point2D* cp, float t )
static Point2D calligraphy_PointOnCubicBezier(Point2D * cp, float t)
{
float ax, bx, cx;
float ay, by, cy;
@ -420,34 +413,37 @@ static Point2D calligraphy_PointOnCubicBezier( Point2D* cp, float t )
<sizeof(Point2D) numberOfPoints>
*/
static void calligraphy_ComputeBezier(Point2D* cp, int numberOfPoints, Point2D* curve)
static void calligraphy_ComputeBezier(Point2D * cp, int numberOfPoints, Point2D * curve)
{
float dt;
int i;
dt = 1.0 / ( numberOfPoints - 1 );
dt = 1.0 / (numberOfPoints - 1);
for( i = 0; i < numberOfPoints; i++)
curve[i] = calligraphy_PointOnCubicBezier( cp, i*dt );
for (i = 0; i < numberOfPoints; i++)
curve[i] = calligraphy_PointOnCubicBezier(cp, i * dt);
}
static float calligraphy_dist(float x1, float y1, float x2, float y2)
{
float d;
d = (sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)));
return d;
}
void calligraphy_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void calligraphy_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void calligraphy_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void calligraphy_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int calligraphy_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_PAINT);
return (MODE_PAINT);
}

View file

@ -38,7 +38,7 @@
/* Our globals: */
static Mix_Chunk * cartoon_snd;
static Mix_Chunk *cartoon_snd;
#define OUTLINE_THRESH 48
@ -46,20 +46,16 @@ static Mix_Chunk * cartoon_snd;
int cartoon_init(magic_api * api);
Uint32 cartoon_api_version(void);
int cartoon_get_tool_count(magic_api * api);
SDL_Surface * cartoon_get_icon(magic_api * api, int which);
char * cartoon_get_name(magic_api * api, int which);
char * cartoon_get_description(magic_api * api, int which, int mode);
static void do_cartoon(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
int x, int y);
SDL_Surface *cartoon_get_icon(magic_api * api, int which);
char *cartoon_get_name(magic_api * api, int which);
char *cartoon_get_description(magic_api * api, int which, int mode);
static void do_cartoon(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
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);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void cartoon_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void cartoon_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void cartoon_shutdown(magic_api * api);
void cartoon_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int cartoon_requires_colors(magic_api * api, int which);
@ -74,51 +70,50 @@ int cartoon_init(magic_api * api)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/sounds/magic/cartoon.wav",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/sounds/magic/cartoon.wav", api->data_directory);
cartoon_snd = Mix_LoadWAV(fname);
return(1);
return (1);
}
Uint32 cartoon_api_version(void) { return(TP_MAGIC_API_VERSION); }
Uint32 cartoon_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
// We have multiple tools:
int cartoon_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return(1);
return (1);
}
// Load our icons:
SDL_Surface * cartoon_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
SDL_Surface *cartoon_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/images/magic/cartoon.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/cartoon.png", api->data_directory);
return(IMG_Load(fname));
return (IMG_Load(fname));
}
// Return our names, localized:
char * cartoon_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
char *cartoon_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(strdup(gettext_noop("Cartoon")));
return (strdup(gettext_noop("Cartoon")));
}
// Return our descriptions, localized:
char * cartoon_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
char *cartoon_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return(strdup(gettext_noop(
"Click and drag the mouse around to turn the picture into a cartoon.")));
return (strdup(gettext_noop("Click and drag the mouse around to turn the picture into a cartoon.")));
}
// Do the effect:
static void do_cartoon(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last,
int x, int y)
static void do_cartoon(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
int xx, yy;
Uint8 r1, g1, b1, r2, g2, b2;
Uint8 r, g, b;
@ -171,27 +166,20 @@ static void do_cartoon(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * can
SDL_GetRGB(api->getpixel(last, xx, yy), last->format, &r, &g, &b);
SDL_GetRGB(api->getpixel(last, xx + 1, yy),
last->format, &r1, &g1, &b1);
SDL_GetRGB(api->getpixel(last, xx + 1, yy), last->format, &r1, &g1, &b1);
SDL_GetRGB(api->getpixel(last, xx + 1, yy + 1),
last->format, &r2, &g2, &b2);
SDL_GetRGB(api->getpixel(last, xx + 1, yy + 1), last->format, &r2, &g2, &b2);
if (abs(((r + g + b) / 3) - (r1 + g1 + b1) / 3) > OUTLINE_THRESH
|| abs(((r + g + b) / 3) - (r2 + g2 + b2) / 3) >
OUTLINE_THRESH || abs(r - r1) > OUTLINE_THRESH
|| abs(g - g1) > OUTLINE_THRESH
|| abs(b - b1) > OUTLINE_THRESH
|| abs(r - r2) > OUTLINE_THRESH
|| abs(g - g2) > OUTLINE_THRESH
|| abs(b - b2) > OUTLINE_THRESH)
|| abs(r - r2) > OUTLINE_THRESH || abs(g - g2) > OUTLINE_THRESH || abs(b - b2) > OUTLINE_THRESH)
{
api->putpixel(canvas, xx - 1, yy,
SDL_MapRGB(canvas->format, 0, 0, 0));
api->putpixel(canvas, xx, yy - 1,
SDL_MapRGB(canvas->format, 0, 0, 0));
api->putpixel(canvas, xx - 1, yy - 1,
SDL_MapRGB(canvas->format, 0, 0, 0));
api->putpixel(canvas, xx - 1, yy, SDL_MapRGB(canvas->format, 0, 0, 0));
api->putpixel(canvas, xx, yy - 1, SDL_MapRGB(canvas->format, 0, 0, 0));
api->putpixel(canvas, xx - 1, yy - 1, SDL_MapRGB(canvas->format, 0, 0, 0));
}
}
}
@ -200,13 +188,24 @@ static void do_cartoon(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * can
// Affect the canvas on drag:
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)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *) api, 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; }
if (ox > x)
{
int tmp = ox;
ox = x;
x = tmp;
}
if (oy > y)
{
int tmp = oy;
oy = y;
y = tmp;
}
update_rect->x = ox - 16;
update_rect->y = oy - 16;
@ -218,8 +217,7 @@ void cartoon_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void cartoon_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
cartoon_drag(api, which, canvas, last, x, y, x, y, update_rect);
}
@ -239,7 +237,8 @@ void cartoon_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void cartoon_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
void cartoon_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED)
{
}
@ -249,15 +248,17 @@ int cartoon_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUT
return 0;
}
void cartoon_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void cartoon_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void cartoon_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void cartoon_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int cartoon_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_PAINT); /* FIXME - Can also be turned into a full-image effect */
return (MODE_PAINT); /* FIXME - Can also be turned into a full-image effect */
}

View file

@ -14,27 +14,25 @@ struct confetti_rgb
struct confetti_rgb confetti_colors; //storage for colors, just for having everything in one place
Mix_Chunk * confetti_snd;
Mix_Chunk *confetti_snd;
/* Local function prototypes: */
Uint32 confetti_api_version(void);
void confetti_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int confetti_init(magic_api * api);
int confetti_get_tool_count(magic_api * api);
SDL_Surface * confetti_get_icon(magic_api * api, int which);
char * confetti_get_name(magic_api * api, int which);
char * confetti_get_description(magic_api * api, int which, int mode);
SDL_Surface *confetti_get_icon(magic_api * api, int which);
char *confetti_get_name(magic_api * api, int which);
char *confetti_get_description(magic_api * api, int which, int mode);
int confetti_requires_colors(magic_api * api, int which);
void confetti_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);
void confetti_shutdown(magic_api * api);
inline char confetti_get_greater(const char what1, const char what2);
inline char confetti_get_lesser(const char what1, const char what2);
Uint32 confetti_get_new_color(void * ptr, SDL_Surface * canvas);
Uint32 confetti_get_new_color(void *ptr, SDL_Surface * canvas);
void confetti_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void confetti_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void confetti_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int confetti_modes(magic_api * api, int which);
@ -42,19 +40,18 @@ int confetti_modes(magic_api * api, int which);
// Housekeeping functions
void confetti_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);
Uint32 confetti_api_version(void)
{
return(TP_MAGIC_API_VERSION);
return (TP_MAGIC_API_VERSION);
}
void confetti_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b) //get the colors from API and store it in structure
{
confetti_colors.r=r;
confetti_colors.g=g;
confetti_colors.b=b;
confetti_colors.r = r;
confetti_colors.g = g;
confetti_colors.b = b;
}
int confetti_init(magic_api * api)
@ -64,7 +61,7 @@ int confetti_init(magic_api * api)
snprintf(fname, sizeof(fname), "%s/sounds/magic/confetti.ogg", api->data_directory);
confetti_snd = Mix_LoadWAV(fname);
return(1);
return (1);
}
int confetti_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
@ -72,21 +69,29 @@ int confetti_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
return 1;
}
SDL_Surface * confetti_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
SDL_Surface *confetti_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/images/magic/confetti.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/confetti.png", api->data_directory);
return(IMG_Load(fname));
return (IMG_Load(fname));
}
char * confetti_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) { return strdup(gettext_noop("Confetti")); }
char *confetti_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return strdup(gettext_noop("Confetti"));
}
char * confetti_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED) { return strdup(gettext_noop("Click to throw confetti!")); }
char *confetti_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return strdup(gettext_noop("Click to throw confetti!"));
}
int confetti_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) { return 1; }
int confetti_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 1;
}
void confetti_release(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * snapshot ATTRIBUTE_UNUSED,
@ -96,20 +101,34 @@ void confetti_release(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUS
}
void confetti_shutdown(magic_api * api ATTRIBUTE_UNUSED)
{ Mix_FreeChunk(confetti_snd); }
{
Mix_FreeChunk(confetti_snd);
}
//private functions
inline char confetti_get_greater(const char what1, const char what2) { if (what1>what2) return what1; else return what2; }
inline char confetti_get_greater(const char what1, const char what2)
{
if (what1 > what2)
return what1;
else
return what2;
}
inline char confetti_get_lesser(const char what1, const char what2) { if (what1<what2) return what1; else return what2; }
inline char confetti_get_lesser(const char what1, const char what2)
{
if (what1 < what2)
return what1;
else
return what2;
}
// Interactivity functions
Uint32 confetti_get_new_color(void * ptr, SDL_Surface * canvas) //this function creates new color very similar to the one choosen
Uint32 confetti_get_new_color(void *ptr, SDL_Surface * canvas) //this function creates new color very similar to the one choosen
{
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
float hsv_h, hsv_s, hsv_v;
Uint8 temp_r, temp_g, temp_b;
@ -117,9 +136,9 @@ Uint32 confetti_get_new_color(void * ptr, SDL_Surface * canvas) //this function
api->rgbtohsv(confetti_colors.r, confetti_colors.g, confetti_colors.b, &hsv_h, &hsv_s, &hsv_v); //color choosen by user is converted
//to HSV palette
hsv_h+=((rand()%60)-30)%360; //Every circle has different, but
hsv_h += ((rand() % 60) - 30) % 360; //Every circle has different, but
//smilar color
if (hsv_h<0)
if (hsv_h < 0)
hsv_h *= -1;
api->hsvtorgb(hsv_h, hsv_s, hsv_v, &temp_r, &temp_g, &temp_b); //...and come back to RGB
@ -128,81 +147,90 @@ Uint32 confetti_get_new_color(void * ptr, SDL_Surface * canvas) //this function
}
static void confetti_circle(void * ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
int x, int y)
static void confetti_circle(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
{
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
int xx, yy;
Uint32 color=confetti_get_new_color(api, canvas);
Uint32 color = confetti_get_new_color(api, canvas);
for (yy = y - CONFETTI_BRUSH_SIZE/2; yy < y + CONFETTI_BRUSH_SIZE/2; yy++)
for (yy = y - CONFETTI_BRUSH_SIZE / 2; yy < y + CONFETTI_BRUSH_SIZE / 2; yy++)
for (xx = x - CONFETTI_BRUSH_SIZE/2; xx < x + CONFETTI_BRUSH_SIZE/2; xx++)
for (xx = x - CONFETTI_BRUSH_SIZE / 2; xx < x + CONFETTI_BRUSH_SIZE / 2; xx++)
if (api->in_circle(xx - x , yy - y , CONFETTI_BRUSH_SIZE/2))
if (api->in_circle(xx - x, yy - y, CONFETTI_BRUSH_SIZE / 2))
api->putpixel(canvas, xx, yy, color);
}
void confetti_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
unsigned char i;
char min_x = 0, max_x = 0, min_y = 0, max_y = 0;
char dx = 0, dy = 0;
for (i=0; i<CONFETTI_QUANTITY; i++)
for (i = 0; i < CONFETTI_QUANTITY; i++)
{
srand((dx+dy)/2 + time(0)); //to get a unique seed even if dx and dy aren't defined
dx=(rand()%100)-50; //generate a value between <-50; +50>
dy=(rand()%100)-50; //to spread confetti around the cursor position
srand((dx + dy) / 2 + time(0)); //to get a unique seed even if dx and dy aren't defined
dx = (rand() % 100) - 50; //generate a value between <-50; +50>
dy = (rand() % 100) - 50; //to spread confetti around the cursor position
if (!i)
{
min_x=max_x=dx;
min_y=max_y=dy;
min_x = max_x = dx;
min_y = max_y = dy;
}
else
{
min_x=confetti_get_lesser(min_x, dx); //any candidates to new min/max values? Hands up please...
max_x=confetti_get_greater(max_x, dx);
min_y=confetti_get_lesser(min_y, dy);
max_y=confetti_get_greater(max_y, dy);
min_x = confetti_get_lesser(min_x, dx); //any candidates to new min/max values? Hands up please...
max_x = confetti_get_greater(max_x, dx);
min_y = confetti_get_lesser(min_y, dy);
max_y = confetti_get_greater(max_y, dy);
}
confetti_circle((void *)api, which, canvas, last, x+dx, y+dy);
confetti_circle((void *)api, which, canvas, last, x + dx, y + dy);
}
update_rect->x = x+min_x - CONFETTI_BRUSH_SIZE/2;
update_rect->y = y+ min_y - CONFETTI_BRUSH_SIZE/2;
update_rect->w = CONFETTI_BRUSH_SIZE*1.5+max_x-min_x;
update_rect->h = CONFETTI_BRUSH_SIZE*1.5+max_y-min_y;
update_rect->x = x + min_x - CONFETTI_BRUSH_SIZE / 2;
update_rect->y = y + min_y - CONFETTI_BRUSH_SIZE / 2;
update_rect->w = CONFETTI_BRUSH_SIZE * 1.5 + max_x - min_x;
update_rect->h = CONFETTI_BRUSH_SIZE * 1.5 + max_y - min_y;
api->playsound(confetti_snd, (x * 255) / canvas->w,255);
api->playsound(confetti_snd, (x * 255) / canvas->w, 255);
}
void confetti_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)
{
int temp;
if (ox>x) {temp=x; x=ox; ox=temp;}
if (oy>y) {temp=y; y=oy; oy=temp; }
if (ox > x)
{
temp = x;
x = ox;
ox = temp;
}
if (oy > y)
{
temp = y;
y = oy;
oy = temp;
}
confetti_click(api, which, MODE_PAINT, canvas, snapshot, x, y, update_rect);
}
void confetti_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void confetti_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void confetti_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void confetti_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int confetti_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_PAINT);
return (MODE_PAINT);
}

View file

@ -43,7 +43,7 @@
/* --------------------- */
/* Sound effects: */
static Mix_Chunk * snd_effect;
static Mix_Chunk *snd_effect;
/* Our local function prototypes: */
@ -57,18 +57,16 @@ static Mix_Chunk * snd_effect;
Uint32 distortion_api_version(void);
int distortion_init(magic_api * api);
int distortion_get_tool_count(magic_api * api);
SDL_Surface * distortion_get_icon(magic_api * api, int which);
char * distortion_get_name(magic_api * api, int which);
char * distortion_get_description(magic_api * api, int which, int mode);
SDL_Surface *distortion_get_icon(magic_api * api, int which);
char *distortion_get_name(magic_api * api, int which);
char *distortion_get_description(magic_api * api, int which, int mode);
int distortion_requires_colors(magic_api * api, int which);
void distortion_shutdown(magic_api * api);
void distortion_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);
void distortion_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);
void distortion_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
void distortion_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
@ -76,12 +74,9 @@ void distortion_switchout(magic_api * api, int which, int mode, SDL_Surface * ca
int distortion_modes(magic_api * api, int which);
void distortion_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);
static void distortion_line_callback(void * ptr, int which,
SDL_Surface * canvas, SDL_Surface * snapshot,
int x, int y);
static void distortion_line_callback(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
/* Setup Functions: */
@ -89,7 +84,7 @@ static void distortion_line_callback(void * ptr, int which,
Uint32 distortion_api_version(void)
{
return(TP_MAGIC_API_VERSION);
return (TP_MAGIC_API_VERSION);
}
@ -99,15 +94,13 @@ int distortion_init(magic_api * api)
{
char fname[1024];
snprintf(fname, sizeof(fname),
"%s/sounds/magic/distortion.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/sounds/magic/distortion.ogg", api->data_directory);
// Try to load the file!
snd_effect = Mix_LoadWAV(fname);
return(1);
return (1);
}
@ -115,39 +108,39 @@ int distortion_init(magic_api * api)
int distortion_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return(1);
return (1);
}
// Load icons
SDL_Surface * distortion_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
SDL_Surface *distortion_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/images/magic/distortion.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/distortion.png", api->data_directory);
// Try to load the image, and return the results to Tux Paint:
return(IMG_Load(fname));
return (IMG_Load(fname));
}
// Report our "Magic" tool names
char * distortion_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
char *distortion_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(strdup(gettext_noop("Distortion")));
return (strdup(gettext_noop("Distortion")));
}
// Report our "Magic" tool descriptions
char * distortion_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
char *distortion_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED)
{
return(strdup(gettext_noop("Click and drag the mouse to cause distortion in your picture.")));
return (strdup(gettext_noop("Click and drag the mouse to cause distortion in your picture.")));
}
// Report whether we accept colors
@ -172,8 +165,7 @@ void distortion_shutdown(magic_api * api ATTRIBUTE_UNUSED)
// Affect the canvas on click:
void distortion_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
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)
{
distortion_drag(api, which, canvas, snapshot, x, y, x, y, update_rect);
}
@ -182,15 +174,25 @@ void distortion_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
// Affect the canvas on drag:
void distortion_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)
{
api->line((void *) api, which, canvas, snapshot,
ox, oy, x, y, 1, distortion_line_callback);
api->line((void *)api, which, canvas, snapshot, ox, oy, x, y, 1, distortion_line_callback);
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;
}
update_rect->x = ox - 8;
@ -199,8 +201,7 @@ void distortion_drag(magic_api * api, int which, SDL_Surface * canvas,
update_rect->h = (y + 8) - update_rect->h;
api->playsound(snd_effect,
(x * 255) / canvas->w, // pan
api->playsound(snd_effect, (x * 255) / canvas->w, // pan
255); // distance
}
@ -214,18 +215,18 @@ void distortion_release(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UN
}
void distortion_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
void distortion_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED)
{
}
// Our "callback" function
static void distortion_line_callback(void * ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * snapshot,
int x, int y)
static void distortion_line_callback(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y)
{
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
int xx, yy;
@ -239,23 +240,23 @@ static void distortion_line_callback(void * ptr, int which ATTRIBUTE_UNUSED,
{
if (api->in_circle(xx, yy, 8))
{
api->putpixel(canvas, x + xx, y + yy,
api->getpixel(snapshot,
x + xx / 2, y + yy));
api->putpixel(canvas, x + xx, y + yy, api->getpixel(snapshot, x + xx / 2, y + yy));
}
}
}
}
void distortion_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void distortion_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void distortion_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void distortion_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int distortion_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_PAINT);
return (MODE_PAINT);
}

View file

@ -35,27 +35,24 @@
/* Our globals: */
static Mix_Chunk * emboss_snd;
static Mix_Chunk *emboss_snd;
// Prototypes
Uint32 emboss_api_version(void);
int emboss_init(magic_api * api);
int emboss_get_tool_count(magic_api * api);
SDL_Surface * emboss_get_icon(magic_api * api, int which);
char * emboss_get_name(magic_api * api, int which);
char * emboss_get_description(magic_api * api, int which, int mode);
SDL_Surface *emboss_get_icon(magic_api * api, int which);
char *emboss_get_name(magic_api * api, int which);
char *emboss_get_description(magic_api * api, int which, int mode);
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);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void emboss_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void emboss_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void emboss_shutdown(magic_api * api);
void emboss_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
@ -65,7 +62,10 @@ void emboss_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas
int emboss_modes(magic_api * api, int which);
Uint32 emboss_api_version(void) { return(TP_MAGIC_API_VERSION); }
Uint32 emboss_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
// No setup required:
@ -73,51 +73,47 @@ int emboss_init(magic_api * api)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/sounds/magic/emboss.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/sounds/magic/emboss.ogg", api->data_directory);
emboss_snd = Mix_LoadWAV(fname);
return(1);
return (1);
}
// We have multiple tools:
int emboss_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return(1);
return (1);
}
// Load our icons:
SDL_Surface * emboss_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
SDL_Surface *emboss_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/images/magic/emboss.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/emboss.png", api->data_directory);
return(IMG_Load(fname));
return (IMG_Load(fname));
}
// Return our names, localized:
char * emboss_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
char *emboss_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(strdup(gettext_noop("Emboss")));
return (strdup(gettext_noop("Emboss")));
}
// Return our descriptions, localized:
char * emboss_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
char *emboss_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return(strdup(gettext_noop("Click and drag the mouse to emboss the picture.")));
return (strdup(gettext_noop("Click and drag the mouse to emboss the picture.")));
}
// Do the effect:
static void do_emboss(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last,
int x, int y)
static void do_emboss(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
int xx, yy;
Uint8 r1, g1, b1,
r2, g2, b2;
Uint8 r1, g1, b1, r2, g2, b2;
int r, g, b;
float h, s, v;
int avg1, avg2;
@ -139,8 +135,10 @@ static void do_emboss(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canv
api->rgbtohsv(r1, g1, b1, &h, &s, &v);
r = 128 + (((avg1 - avg2) * 3) / 2);
if (r < 0) r = 0;
if (r > 255) r = 255;
if (r < 0)
r = 0;
if (r > 255)
r = 255;
g = b = r;
v = (r / 255.0);
@ -156,27 +154,36 @@ static void do_emboss(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canv
// Affect the canvas on drag:
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)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *) api, 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; }
if (ox > x)
{
int tmp = ox;
ox = x;
x = tmp;
}
if (oy > y)
{
int tmp = oy;
oy = y;
y = tmp;
}
update_rect->x = ox - 16;
update_rect->y = oy - 16;
update_rect->w = (x + 16) - update_rect->x;
update_rect->h = (y + 16) - update_rect->h;
api->playsound(emboss_snd,
(x * 255) / canvas->w, 255);
api->playsound(emboss_snd, (x * 255) / canvas->w, 255);
}
// Affect the canvas on click:
void emboss_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
emboss_drag(api, which, canvas, last, x, y, x, y, update_rect);
}
@ -196,7 +203,8 @@ void emboss_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void emboss_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
void emboss_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED)
{
}
@ -206,15 +214,17 @@ int emboss_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE
return 0;
}
void emboss_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void emboss_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void emboss_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void emboss_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int emboss_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_PAINT); /* FIXME - Can also be turned into a full-image effect */
return (MODE_PAINT); /* FIXME - Can also be turned into a full-image effect */
}

View file

@ -33,13 +33,14 @@
#include "SDL_image.h"
#include "SDL_mixer.h"
enum {
enum
{
TOOL_FADE,
TOOL_DARKEN,
NUM_TOOLS
};
static Mix_Chunk * snd_effects[NUM_TOOLS];
static Mix_Chunk *snd_effects[NUM_TOOLS];
/* Local function prototypes: */
@ -47,24 +48,17 @@ static Mix_Chunk * snd_effects[NUM_TOOLS];
int fade_darken_init(magic_api * api);
Uint32 fade_darken_api_version(void);
int fade_darken_get_tool_count(magic_api * api);
SDL_Surface * fade_darken_get_icon(magic_api * api, int which);
char * fade_darken_get_name(magic_api * api, int which);
char * fade_darken_get_description(magic_api * api, int which, int mode);
static void do_fade_darken(void * ptr, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y);
static void do_fade_darken_paint(void * ptr, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y);
SDL_Surface *fade_darken_get_icon(magic_api * api, int which);
char *fade_darken_get_name(magic_api * api, int which);
char *fade_darken_get_description(magic_api * api, int which, int mode);
static void do_fade_darken(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
static void do_fade_darken_paint(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
void fade_darken_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void fade_darken_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void fade_darken_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void fade_darken_shutdown(magic_api * api);
void fade_darken_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int fade_darken_requires_colors(magic_api * api, int which);
@ -76,82 +70,79 @@ int fade_darken_init(magic_api * api)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/sounds/magic/fade.wav",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/sounds/magic/fade.wav", api->data_directory);
snd_effects[TOOL_FADE] = Mix_LoadWAV(fname);
snprintf(fname, sizeof(fname), "%s/sounds/magic/darken.wav",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/sounds/magic/darken.wav", api->data_directory);
snd_effects[TOOL_DARKEN] = Mix_LoadWAV(fname);
return(1);
return (1);
}
Uint32 fade_darken_api_version(void) { return(TP_MAGIC_API_VERSION); }
Uint32 fade_darken_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
// Multiple tools:
int fade_darken_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return(NUM_TOOLS);
return (NUM_TOOLS);
}
// Load our icon:
SDL_Surface * fade_darken_get_icon(magic_api * api, int which)
SDL_Surface *fade_darken_get_icon(magic_api * api, int which)
{
char fname[1024];
if (which == TOOL_FADE)
{
snprintf(fname, sizeof(fname), "%s/images/magic/fade.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/fade.png", api->data_directory);
}
else if (which == TOOL_DARKEN)
{
snprintf(fname, sizeof(fname), "%s/images/magic/darken.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/darken.png", api->data_directory);
}
return(IMG_Load(fname));
return (IMG_Load(fname));
}
// Return our name, localized:
char * fade_darken_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
char *fade_darken_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
{
if (which == TOOL_FADE)
return(strdup(gettext_noop("Lighten")));
return (strdup(gettext_noop("Lighten")));
else if (which == TOOL_DARKEN)
return(strdup(gettext_noop("Darken")));
return (strdup(gettext_noop("Darken")));
return(NULL);
return (NULL);
}
// Return our description, localized:
char * fade_darken_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode)
char *fade_darken_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode)
{
if (which == TOOL_FADE)
{
if (mode == MODE_PAINT)
return(strdup(gettext_noop("Click and drag the mouse to lighten parts of your picture.")));
return (strdup(gettext_noop("Click and drag the mouse to lighten parts of your picture.")));
else if (mode == MODE_FULLSCREEN)
return(strdup(gettext_noop("Click to lighten your entire picture.")));
return (strdup(gettext_noop("Click to lighten your entire picture.")));
}
else if (which == TOOL_DARKEN)
{
if (mode == MODE_PAINT)
return(strdup(gettext_noop("Click and drag the mouse to darken parts of your picture.")));
return (strdup(gettext_noop("Click and drag the mouse to darken parts of your picture.")));
else if (mode == MODE_FULLSCREEN)
return(strdup(gettext_noop("Click to darken your entire picture.")));
return (strdup(gettext_noop("Click to darken your entire picture.")));
}
return(NULL);
return (NULL);
}
static void do_fade_darken(void * ptr, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y)
static void do_fade_darken(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
Uint8 r, g, b;
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
SDL_GetRGB(api->getpixel(last, x, y), last->format, &r, &g, &b);
@ -172,19 +163,16 @@ static void do_fade_darken(void * ptr, int which,
}
// Callback that does the fade_darken color effect on a circle centered around x,y
static void do_fade_darken_paint(void * ptr, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y)
static void do_fade_darken_paint(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
int xx, yy;
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
for (yy = y - 16; yy < y + 16; yy++)
{
for (xx = x - 16; xx < x + 16; xx++)
{
if (api->in_circle(xx - x, yy - y, 16) &&
!api->touched(xx, yy))
if (api->in_circle(xx - x, yy - y, 16) && !api->touched(xx, yy))
{
do_fade_darken(api, which, canvas, last, xx, yy);
}
@ -194,21 +182,32 @@ static void do_fade_darken_paint(void * ptr, int which,
// Ask Tux Paint to call our 'do_fade_darken_paint()' callback over a line
void fade_darken_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
SDL_LockSurface(last);
SDL_LockSurface(canvas);
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_fade_darken_paint);
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_fade_darken_paint);
SDL_UnlockSurface(canvas);
SDL_UnlockSurface(last);
api->playsound(snd_effects[which], (x * 255) / canvas->w, 255);
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;
}
update_rect->x = ox - 16;
update_rect->y = oy - 16;
@ -219,8 +218,7 @@ void fade_darken_drag(magic_api * api, int which, SDL_Surface * canvas,
// Ask Tux Paint to call our 'do_fade_darken_paint()' callback at a single point,
// or 'do_fade_darken()' on the entire image
void fade_darken_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
if (mode == MODE_PAINT)
fade_darken_drag(api, which, canvas, last, x, y, x, y, update_rect);
@ -270,15 +268,17 @@ int fade_darken_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTR
return 0;
}
void fade_darken_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void fade_darken_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void fade_darken_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void fade_darken_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int fade_darken_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_PAINT | MODE_FULLSCREEN);
return (MODE_PAINT | MODE_FULLSCREEN);
}

View file

@ -39,15 +39,13 @@
/* Our globals: */
static Mix_Chunk * fill_snd;
static Mix_Chunk *fill_snd;
static Uint8 fill_r, fill_g, fill_b;
/* Local function prototypes: */
static int colors_close(magic_api * api, SDL_Surface * canvas,
Uint32 c1, Uint32 c2);
static void do_flood_fill(magic_api * api, SDL_Surface * canvas, int x, int y,
Uint32 cur_colr, Uint32 old_colr);
static int colors_close(magic_api * api, SDL_Surface * canvas, Uint32 c1, Uint32 c2);
static void do_flood_fill(magic_api * api, SDL_Surface * canvas, int x, int y, Uint32 cur_colr, Uint32 old_colr);
int fill_modes(magic_api * api, int which);
void fill_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
void fill_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
@ -55,18 +53,15 @@ int fill_requires_colors(magic_api * api, int which);
void fill_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
void fill_shutdown(magic_api * api);
void fill_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void fill_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void fill_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
char * fill_get_description(magic_api * api, int which, int mode);
char * fill_get_name(magic_api * api, int which);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
char *fill_get_description(magic_api * api, int which, int mode);
char *fill_get_name(magic_api * api, int which);
int fill_get_tool_count(magic_api * api);
SDL_Surface * fill_get_icon(magic_api * api, int which);
SDL_Surface *fill_get_icon(magic_api * api, int which);
Uint32 fill_api_version(void);
int fill_init(magic_api * api);
@ -76,50 +71,50 @@ int fill_init(magic_api * api)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/sounds/magic/fill.wav",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/sounds/magic/fill.wav", api->data_directory);
fill_snd = Mix_LoadWAV(fname);
return(1);
return (1);
}
Uint32 fill_api_version(void) { return(TP_MAGIC_API_VERSION); }
Uint32 fill_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
// We have multiple tools:
int fill_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return(1);
return (1);
}
// Load our icons:
SDL_Surface * fill_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
SDL_Surface *fill_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/images/magic/fill.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/fill.png", api->data_directory);
return(IMG_Load(fname));
return (IMG_Load(fname));
}
// Return our names, localized:
char * fill_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
char *fill_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(strdup(gettext_noop("Fill")));
return (strdup(gettext_noop("Fill")));
}
// Return our descriptions, localized:
char * fill_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
char *fill_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return(strdup(gettext_noop(
"Click in the picture to fill that area with color.")));
return (strdup(gettext_noop("Click in the picture to fill that area with color.")));
}
// Affect the canvas on drag:
void fill_drag(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
SDL_Surface * last ATTRIBUTE_UNUSED, int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED,
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
@ -128,9 +123,7 @@ void fill_click(magic_api * api, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
int x, int y, SDL_Rect * update_rect)
{
do_flood_fill(api, canvas, x, y, SDL_MapRGB(canvas->format,
fill_r, fill_g, fill_b),
api->getpixel(canvas, x, y));
do_flood_fill(api, canvas, x, y, SDL_MapRGB(canvas->format, fill_r, fill_g, fill_b), api->getpixel(canvas, x, y));
update_rect->x = 0;
update_rect->y = 0;
@ -164,8 +157,7 @@ int fill_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_U
}
static int colors_close(magic_api * api, SDL_Surface * canvas,
Uint32 c1, Uint32 c2)
static int colors_close(magic_api * api, SDL_Surface * canvas, Uint32 c1, Uint32 c2)
{
Uint8 r1, g1, b1, r2, g2, b2;
@ -178,6 +170,7 @@ static int colors_close(magic_api * api, SDL_Surface * canvas,
else
{
double r, g, b;
SDL_GetRGB(c1, canvas->format, &r1, &g1, &b1);
SDL_GetRGB(c2, canvas->format, &r2, &g2, &b2);
@ -198,8 +191,7 @@ static int colors_close(magic_api * api, SDL_Surface * canvas,
}
static void do_flood_fill(magic_api * api, SDL_Surface * canvas, int x, int y,
Uint32 cur_colr, Uint32 old_colr)
static void do_flood_fill(magic_api * api, SDL_Surface * canvas, int x, int y, Uint32 cur_colr, Uint32 old_colr)
{
int fillL, fillR, i, in_line;
static unsigned char prog_anim;
@ -229,10 +221,7 @@ static void do_flood_fill(magic_api * api, SDL_Surface * canvas, int x, int y,
api->putpixel(canvas, fillL, y, cur_colr);
fillL--;
in_line =
(fillL < 0) ? 0 : colors_close(api, canvas,
api->getpixel(canvas, fillL, y),
old_colr);
in_line = (fillL < 0) ? 0 : colors_close(api, canvas, api->getpixel(canvas, fillL, y), old_colr);
}
fillL++;
@ -245,9 +234,7 @@ static void do_flood_fill(magic_api * api, SDL_Surface * canvas, int x, int y,
api->putpixel(canvas, fillR, y, cur_colr);
fillR++;
in_line = (fillR >= canvas->w) ? 0 : colors_close(api, canvas,
api->getpixel(canvas, fillR, y),
old_colr);
in_line = (fillR >= canvas->w) ? 0 : colors_close(api, canvas, api->getpixel(canvas, fillR, y), old_colr);
}
fillR--;
@ -257,25 +244,25 @@ static void do_flood_fill(magic_api * api, SDL_Surface * canvas, int x, int y,
for (i = fillL; i <= fillR; i++)
{
if (y > 0 && colors_close(api, canvas, api->getpixel(canvas, i, y - 1),
old_colr))
if (y > 0 && colors_close(api, canvas, api->getpixel(canvas, i, y - 1), old_colr))
do_flood_fill(api, canvas, i, y - 1, cur_colr, old_colr);
if (y < canvas->h
&& colors_close(api, canvas, api->getpixel(canvas, i, y + 1), old_colr))
if (y < canvas->h && colors_close(api, canvas, api->getpixel(canvas, i, y + 1), old_colr))
do_flood_fill(api, canvas, i, y + 1, cur_colr, old_colr);
}
}
void fill_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void fill_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void fill_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void fill_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int fill_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_PAINT);
return (MODE_PAINT);
}

View file

@ -31,7 +31,7 @@
#include "SDL_image.h"
#include "SDL_mixer.h"
Mix_Chunk * fisheye_snd;
Mix_Chunk *fisheye_snd;
int last_x, last_y;
/* Local function prototypes */
@ -39,22 +39,18 @@ Uint32 fisheye_api_version(void);
void fisheye_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int fisheye_init(magic_api * api);
int fisheye_get_tool_count(magic_api * api);
SDL_Surface * fisheye_get_icon(magic_api * api, int which);
char * fisheye_get_name(magic_api * api, int which);
char * fisheye_get_description(magic_api * api, int which, int mode);
SDL_Surface *fisheye_get_icon(magic_api * api, int which);
char *fisheye_get_name(magic_api * api, int which);
char *fisheye_get_description(magic_api * api, int which, int mode);
int fisheye_requires_colors(magic_api * api, int which);
void fisheye_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);
void fisheye_shutdown(magic_api * api);
void fisheye_draw(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
int x, int y);
void fisheye_draw(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
void fisheye_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 fisheye_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void fisheye_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void fisheye_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int fisheye_modes(magic_api * api, int which);
@ -63,15 +59,15 @@ int fisheye_modes(magic_api * api, int which);
// Housekeeping functions
void fisheye_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);
Uint32 fisheye_api_version(void)
{
return(TP_MAGIC_API_VERSION);
return (TP_MAGIC_API_VERSION);
}
void fisheye_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
void fisheye_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED)
{
}
@ -83,7 +79,7 @@ int fisheye_init(magic_api * api)
snprintf(fname, sizeof(fname), "%s/sounds/magic/fisheye.ogg", api->data_directory);
fisheye_snd = Mix_LoadWAV(fname);
return(1);
return (1);
}
int fisheye_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
@ -91,21 +87,29 @@ int fisheye_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
return 1;
}
SDL_Surface * fisheye_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
SDL_Surface *fisheye_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/images/magic/fisheye.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/fisheye.png", api->data_directory);
return(IMG_Load(fname));
return (IMG_Load(fname));
}
char * fisheye_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) { return strdup(gettext_noop("Fisheye")); } //Needs better name
char *fisheye_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return strdup(gettext_noop("Fisheye"));
} //Needs better name
char * fisheye_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED) { return strdup(gettext_noop("Click on part of your picture to create a fisheye effect.")); }
char *fisheye_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return strdup(gettext_noop("Click on part of your picture to create a fisheye effect."));
}
int fisheye_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) { return 0; }
int fisheye_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 0;
}
void fisheye_release(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * snapshot ATTRIBUTE_UNUSED,
@ -115,120 +119,129 @@ void fisheye_release(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSE
}
void fisheye_shutdown(magic_api * api ATTRIBUTE_UNUSED)
{ Mix_FreeChunk(fisheye_snd); }
{
Mix_FreeChunk(fisheye_snd);
}
// do-fisheye
void fisheye_draw(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
void fisheye_draw(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
int x, int y)
{
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
SDL_Surface * oryg, *temp_src, *temp_dest, *output;
SDL_Surface *oryg, *temp_src, *temp_dest, *output;
SDL_Rect rect, temp_rect;
int xx, yy;
unsigned short int i;
if(api->in_circle(last_x - x, last_y - y, 80)) return;
if (api->in_circle(last_x - x, last_y - y, 80))
return;
last_x = x;
last_y = y;
oryg=SDL_CreateRGBSurface(SDL_SWSURFACE, 80, 80, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
oryg = SDL_CreateRGBSurface(SDL_SWSURFACE, 80, 80, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask,
canvas->format->Amask);
output=SDL_CreateRGBSurface(SDL_SWSURFACE, 80, 80, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
output = SDL_CreateRGBSurface(SDL_SWSURFACE, 80, 80, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask,
canvas->format->Amask);
rect.x=x-40;
rect.y=y-40;
rect.w=rect.h=80;
rect.x = x - 40;
rect.y = y - 40;
rect.w = rect.h = 80;
SDL_BlitSurface(canvas, &rect, oryg, NULL); //here we have a piece of source image. Now we've to scale it (keeping aspect ratio)
//do vertical fisheye
for (i=0; i<40; i++)
for (i = 0; i < 40; i++)
{
temp_src=SDL_CreateRGBSurface(SDL_SWSURFACE, 1, 80, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
temp_src = SDL_CreateRGBSurface(SDL_SWSURFACE, 1, 80, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask,
canvas->format->Amask);
//let's take a smooth bar of scaled bitmap and copy it to temp
//left side first
rect.x=i;
rect.y=0;
rect.w=1;
rect.x = i;
rect.y = 0;
rect.w = 1;
SDL_BlitSurface(oryg, &rect, temp_src, NULL); //this bar is copied to temp_src
temp_dest=SDL_CreateRGBSurface(SDL_SWSURFACE, 1, 80+2*i, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
temp_dest = SDL_CreateRGBSurface(SDL_SWSURFACE, 1, 80 + 2 * i, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask,
canvas->format->Amask);
temp_dest=api->scale(temp_src, 1, 80+2*i, 0); //temp_dest stores scaled temp_src
temp_dest = api->scale(temp_src, 1, 80 + 2 * i, 0); //temp_dest stores scaled temp_src
temp_rect.x=0;
temp_rect.y=i;
temp_rect.w=1;
temp_rect.h=80;
temp_rect.x = 0;
temp_rect.y = i;
temp_rect.w = 1;
temp_rect.h = 80;
SDL_BlitSurface(temp_dest, &temp_rect, output, &rect); //let's copy it to output
//right side then
rect.x=79-i;
rect.x = 79 - i;
SDL_BlitSurface(oryg, &rect, temp_src, NULL); //this bar is copied to temp_src //OK
temp_dest=api->scale(temp_src, 1, 80+2*i, 0); //temp_dest stores scaled temp_src
temp_dest = api->scale(temp_src, 1, 80 + 2 * i, 0); //temp_dest stores scaled temp_src
SDL_BlitSurface(temp_dest, &temp_rect, output, &rect); //let's copy it to output
}
//do horizontal fisheye
for (i=0; i<40; i++)
for (i = 0; i < 40; i++)
{
temp_src=SDL_CreateRGBSurface(SDL_SWSURFACE, 80, 1, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
temp_src = SDL_CreateRGBSurface(SDL_SWSURFACE, 80, 1, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask,
canvas->format->Amask);
temp_dest=SDL_CreateRGBSurface(SDL_SWSURFACE, 80+2*i, 1, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
temp_dest = SDL_CreateRGBSurface(SDL_SWSURFACE, 80 + 2 * i, 1, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask,
canvas->format->Amask);
//upper side first
rect.x=0;
rect.y=i;
rect.w=80;
rect.h=1;
rect.x = 0;
rect.y = i;
rect.w = 80;
rect.h = 1;
temp_rect.x=i;
temp_rect.y=0;
temp_rect.w=80;
temp_rect.h=1;
temp_rect.x = i;
temp_rect.y = 0;
temp_rect.w = 80;
temp_rect.h = 1;
SDL_BlitSurface(output, &rect, temp_src, NULL);
temp_dest=api->scale(temp_src, 80+2*i, 1, 0);
temp_dest = api->scale(temp_src, 80 + 2 * i, 1, 0);
SDL_BlitSurface(temp_dest, &temp_rect, output, &rect);
//lower side then
rect.y=79-i;
rect.y = 79 - i;
SDL_BlitSurface(output, &rect, temp_src, NULL);
temp_dest=api->scale(temp_src, 80+2*i, 1, 0);
temp_dest = api->scale(temp_src, 80 + 2 * i, 1, 0);
SDL_BlitSurface(temp_dest, &temp_rect, output, &rect);
}
rect.x=x-40;
rect.y=y-40;
rect.w=rect.h=80;
rect.x = x - 40;
rect.y = y - 40;
rect.w = rect.h = 80;
//let's blit an area surrounded by a circle
for (yy = y-40; yy < y+40; yy++)
for (xx = x-40; xx < x+40; xx++)
for (yy = y - 40; yy < y + 40; yy++)
for (xx = x - 40; xx < x + 40; xx++)
if (api->in_circle(xx-x, yy-y, 40))
api->putpixel(canvas, xx, yy, api->getpixel(output, xx+40-x, yy+40-y));
if (api->in_circle(xx - x, yy - y, 40))
api->putpixel(canvas, xx, yy, api->getpixel(output, xx + 40 - x, yy + 40 - y));
SDL_FreeSurface(oryg);
@ -236,12 +249,11 @@ void fisheye_draw(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
SDL_FreeSurface(temp_dest);
SDL_FreeSurface(temp_src);
api->playsound(fisheye_snd, (x * 255) / canvas->w,255);
api->playsound(fisheye_snd, (x * 255) / canvas->w, 255);
}
void fisheye_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)
{
api->line(api, which, canvas, snapshot, ox, oy, x, y, 1, fisheye_draw);
@ -252,25 +264,26 @@ void fisheye_drag(magic_api * api, int which, SDL_Surface * canvas,
}
void fisheye_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
last_x = -80; /* A value that will be beyond any clicked position */
last_y = -80;
fisheye_drag(api, which, canvas, last, x, y, x, y, update_rect);
}
void fisheye_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void fisheye_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void fisheye_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void fisheye_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int fisheye_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_PAINT);
return (MODE_PAINT);
}

View file

@ -36,19 +36,21 @@
/* Our globals: */
enum { SIDE_LEFT, SIDE_RIGHT };
enum { LEAFSIDE_RIGHT_DOWN,
enum
{ SIDE_LEFT, SIDE_RIGHT };
enum
{ LEAFSIDE_RIGHT_DOWN,
LEAFSIDE_LEFT_DOWN,
LEAFSIDE_RIGHT_UP,
LEAFSIDE_LEFT_UP };
LEAFSIDE_LEFT_UP
};
static Mix_Chunk * flower_click_snd, * flower_release_snd;
static Mix_Chunk *flower_click_snd, *flower_release_snd;
static Uint8 flower_r, flower_g, flower_b;
static int flower_min_x, flower_max_x, flower_bottom_x, flower_bottom_y;
static int flower_side_first;
static int flower_side_decided;
static SDL_Surface * flower_base, * flower_leaf, * flower_petals,
* flower_petals_colorized;
static SDL_Surface *flower_base, *flower_leaf, *flower_petals, *flower_petals_colorized;
/* Local function prototypes: */
@ -59,36 +61,31 @@ typedef struct
static void flower_drawbase(magic_api * api, SDL_Surface * canvas);
static void flower_drawflower(magic_api * api, SDL_Surface * canvas, int x, int y);
static Point2D flower_PointOnCubicBezier(Point2D* cp, float t);
static void flower_ComputeBezier(Point2D* cp, int numberOfPoints, Point2D* curve);
static Point2D flower_PointOnCubicBezier(Point2D * cp, float t);
static void flower_ComputeBezier(Point2D * cp, int numberOfPoints, Point2D * curve);
static void flower_colorize_petals(magic_api * api);
Uint32 flower_api_version(void);
int flower_init(magic_api * api);
int flower_get_tool_count(magic_api * api);
SDL_Surface * flower_get_icon(magic_api * api, int which);
char * flower_get_name(magic_api * api, int which);
char * flower_get_description(magic_api * api, int which, int mode);
static void flower_predrag(magic_api * api, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y);
SDL_Surface *flower_get_icon(magic_api * api, int which);
char *flower_get_name(magic_api * api, int which);
char *flower_get_description(magic_api * api, int which, int mode);
static void flower_predrag(magic_api * api, SDL_Surface * canvas, SDL_Surface * last, int ox, int oy, int x, int y);
void flower_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void flower_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void flower_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
static void flower_drawflower(magic_api * api, SDL_Surface * canvas, int x, int y);
static void flower_drawbase(magic_api * api, SDL_Surface * canvas);
static void flower_drawstalk(magic_api * api, SDL_Surface * canvas,
int top_x, int top_y, int minx, int maxx,
int bottom_x, int bottom_y, int final);
int top_x, int top_y, int minx, int maxx, int bottom_x, int bottom_y, int final);
void flower_shutdown(magic_api * api);
void flower_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int flower_requires_colors(magic_api * api, int which);
static Point2D flower_PointOnCubicBezier( Point2D* cp, float t );
static void flower_ComputeBezier( Point2D* cp, int numberOfPoints, Point2D* curve );
static Point2D flower_PointOnCubicBezier(Point2D * cp, float t);
static void flower_ComputeBezier(Point2D * cp, int numberOfPoints, Point2D * curve);
static void flower_colorize_petals(magic_api * api);
void flower_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void flower_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
@ -96,7 +93,10 @@ int flower_modes(magic_api * api, int which);
Uint32 flower_api_version(void) { return(TP_MAGIC_API_VERSION); }
Uint32 flower_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
// No setup required:
@ -104,56 +104,50 @@ int flower_init(magic_api * api)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/sounds/magic/flower_click.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/sounds/magic/flower_click.ogg", api->data_directory);
flower_click_snd = Mix_LoadWAV(fname);
snprintf(fname, sizeof(fname), "%s/sounds/magic/flower_release.ogg",
api->data_directory);
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);
snprintf(fname, sizeof(fname), "%s/images/magic/flower_base.png", api->data_directory);
flower_base = IMG_Load(fname);
snprintf(fname, sizeof(fname), "%s/images/magic/flower_leaf.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/flower_leaf.png", api->data_directory);
flower_leaf = IMG_Load(fname);
snprintf(fname, sizeof(fname), "%s/images/magic/flower_petals.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/flower_petals.png", api->data_directory);
flower_petals = IMG_Load(fname);
return(1);
return (1);
}
// We have multiple tools:
int flower_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return(1);
return (1);
}
// Load our icons:
SDL_Surface * flower_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
SDL_Surface *flower_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/images/magic/flower.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/flower.png", api->data_directory);
return(IMG_Load(fname));
return (IMG_Load(fname));
}
// Return our names, localized:
char * flower_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
char *flower_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(strdup(gettext_noop("Flower")));
return (strdup(gettext_noop("Flower")));
}
// Return our descriptions, localized:
char * flower_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
char *flower_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return(strdup(gettext_noop("Click and drag to draw a flower stalk. Let go to finish the flower.")));
return (strdup(gettext_noop("Click and drag to draw a flower stalk. Let go to finish the flower.")));
}
// Affect the canvas on drag:
@ -192,8 +186,7 @@ static void flower_predrag(magic_api * api ATTRIBUTE_UNUSED, SDL_Surface * canva
}
void flower_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
flower_predrag(api, canvas, last, ox, oy, x, y);
@ -206,8 +199,7 @@ void flower_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface * canv
/* Draw the base and the stalk (low-quality) for now: */
flower_drawstalk(api, canvas,
x, y, flower_min_x, flower_max_x,
flower_bottom_x, flower_bottom_y, !(api->button_down()));
x, y, flower_min_x, flower_max_x, flower_bottom_x, flower_bottom_y, !(api->button_down()));
flower_drawbase(api, canvas);
@ -219,8 +211,7 @@ void flower_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface * canv
// Affect the canvas on click:
void flower_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
flower_min_x = x;
flower_max_x = x;
@ -237,8 +228,7 @@ void flower_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
// Affect the canvas on release:
void flower_release(magic_api * api, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
/* Don't let flower be too low compared to base: */
@ -258,9 +248,7 @@ void flower_release(magic_api * api, int which ATTRIBUTE_UNUSED,
/* Draw high-quality stalk, and flower: */
flower_drawstalk(api, canvas,
x, y, flower_min_x, flower_max_x,
flower_bottom_x, flower_bottom_y, 1);
flower_drawstalk(api, canvas, x, y, flower_min_x, flower_max_x, flower_bottom_x, flower_bottom_y, 1);
flower_drawflower(api, canvas, x, y);
@ -297,11 +285,10 @@ static void flower_drawbase(magic_api * api ATTRIBUTE_UNUSED, SDL_Surface * canv
}
static void flower_drawstalk(magic_api * api ATTRIBUTE_UNUSED, SDL_Surface * canvas,
int top_x, int top_y, int minx, int maxx,
int bottom_x, int bottom_y, int final)
int top_x, int top_y, int minx, int maxx, int bottom_x, int bottom_y, int final)
{
Point2D control_points[4];
Point2D * curve;
Point2D *curve;
int i, n_points;
int left, right;
SDL_Rect dest, src;
@ -368,8 +355,7 @@ static void flower_drawstalk(magic_api * api ATTRIBUTE_UNUSED, SDL_Surface * can
/* When we're done (final render), we can add some random leaves: */
if (final && i > 32 && i < n_points - 32 && (i % 16) == 0 &&
(rand() % 5) > 0)
if (final && i > 32 && i < n_points - 32 && (i % 16) == 0 && (rand() % 5) > 0)
{
/* Check for hard left/right angles: */
@ -518,7 +504,7 @@ cp[3] is the end point, or P3 in the above diagram
t is the parameter value, 0 <= t <= 1
*/
static Point2D flower_PointOnCubicBezier( Point2D* cp, float t )
static Point2D flower_PointOnCubicBezier(Point2D * cp, float t)
{
float ax, bx, cx;
float ay, by, cy;
@ -553,15 +539,15 @@ static Point2D flower_PointOnCubicBezier( Point2D* cp, float t )
<sizeof(Point2D) numberOfPoints>
*/
static void flower_ComputeBezier( Point2D* cp, int numberOfPoints, Point2D* curve )
static void flower_ComputeBezier(Point2D * cp, int numberOfPoints, Point2D * curve)
{
float dt;
int i;
dt = 1.0 / ( numberOfPoints - 1 );
dt = 1.0 / (numberOfPoints - 1);
for( i = 0; i < numberOfPoints; i++)
curve[i] = flower_PointOnCubicBezier( cp, i*dt );
for (i = 0; i < numberOfPoints; i++)
curve[i] = flower_PointOnCubicBezier(cp, i * dt);
}
@ -576,9 +562,7 @@ static void flower_colorize_petals(magic_api * api)
/* Create a surface to render into: */
amask = ~(flower_petals->format->Rmask |
flower_petals->format->Gmask |
flower_petals->format->Bmask);
amask = ~(flower_petals->format->Rmask | flower_petals->format->Gmask | flower_petals->format->Bmask);
flower_petals_colorized =
SDL_CreateRGBSurface(SDL_SWSURFACE,
@ -586,8 +570,7 @@ static void flower_colorize_petals(magic_api * api)
flower_petals->h,
flower_petals->format->BitsPerPixel,
flower_petals->format->Rmask,
flower_petals->format->Gmask,
flower_petals->format->Bmask, amask);
flower_petals->format->Gmask, flower_petals->format->Bmask, amask);
/* Render the new petals: */
@ -598,20 +581,15 @@ static void flower_colorize_petals(magic_api * api)
{
for (x = 0; x < flower_petals->w; x++)
{
SDL_GetRGBA(api->getpixel(flower_petals, x, y),
flower_petals->format, &r, &g, &b, &a);
SDL_GetRGBA(api->getpixel(flower_petals, x, y), flower_petals->format, &r, &g, &b, &a);
api->putpixel(flower_petals_colorized, x, y,
SDL_MapRGBA(flower_petals_colorized->format,
flower_r, flower_g, flower_b, a));
SDL_MapRGBA(flower_petals_colorized->format, flower_r, flower_g, flower_b, a));
if (api->in_circle((x - flower_petals->w / 2),
(y - flower_petals->h / 2),
8))
if (api->in_circle((x - flower_petals->w / 2), (y - flower_petals->h / 2), 8))
{
api->putpixel(flower_petals_colorized, x, y,
SDL_MapRGBA(flower_petals_colorized->format,
0xFF, 0xFF, 0x00, a));
SDL_MapRGBA(flower_petals_colorized->format, 0xFF, 0xFF, 0x00, a));
}
}
}
@ -620,15 +598,17 @@ static void flower_colorize_petals(magic_api * api)
SDL_UnlockSurface(flower_petals);
}
void flower_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void flower_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void flower_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void flower_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int flower_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_PAINT_WITH_PREVIEW);
return (MODE_PAINT_WITH_PREVIEW);
}

View file

@ -36,26 +36,23 @@
/* Our globals: */
static Mix_Chunk * foam_snd;
static Mix_Chunk *foam_snd;
static Uint8 foam_r, foam_g, foam_b;
static int foam_mask_w, foam_mask_h;
static int * foam_mask, * foam_mask_tmp;
static SDL_Surface * foam_7, * foam_5, * foam_3, * foam_1;
static int *foam_mask, *foam_mask_tmp;
static SDL_Surface *foam_7, *foam_5, *foam_3, *foam_1;
Uint32 foam_api_version(void);
int foam_init(magic_api * api);
char * foam_get_description(magic_api * api, int which, int mode);
char *foam_get_description(magic_api * api, int which, int mode);
void foam_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
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);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void foam_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * foam_get_icon(magic_api * api, int which);
char * foam_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
SDL_Surface *foam_get_icon(magic_api * api, int which);
char *foam_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED);
void foam_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void foam_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
void foam_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
@ -67,73 +64,70 @@ int foam_requires_colors(magic_api * api, int which);
#define FOAM_PROP 8
#define FOAM_RADIUS 3
Uint32 foam_api_version(void) { return(TP_MAGIC_API_VERSION); }
Uint32 foam_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
// No setup required:
int foam_init(magic_api * api)
{
char fname[1024];
SDL_Surface * foam_data;
SDL_Surface *foam_data;
snprintf(fname, sizeof(fname), "%s/sounds/magic/foam.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/sounds/magic/foam.ogg", api->data_directory);
foam_snd = Mix_LoadWAV(fname);
snprintf(fname, sizeof(fname), "%s/images/magic/foam_data.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/foam_data.png", api->data_directory);
foam_data = IMG_Load(fname);
foam_7 = api->scale(foam_data, ((api->canvas_w / FOAM_PROP) * 4) / 4,
((api->canvas_h / FOAM_PROP) * 4) / 4, 0);
foam_5 = api->scale(foam_data, ((api->canvas_w / FOAM_PROP) * 3) / 4,
((api->canvas_h / FOAM_PROP) * 3) / 4, 0);
foam_3 = api->scale(foam_data, ((api->canvas_w / FOAM_PROP) * 2) / 4,
((api->canvas_h / FOAM_PROP) * 2) / 4, 0);
foam_1 = api->scale(foam_data, ((api->canvas_w / FOAM_PROP) * 1) / 4,
((api->canvas_h / FOAM_PROP) * 1) / 4, 0);
foam_7 = api->scale(foam_data, ((api->canvas_w / FOAM_PROP) * 4) / 4, ((api->canvas_h / FOAM_PROP) * 4) / 4, 0);
foam_5 = api->scale(foam_data, ((api->canvas_w / FOAM_PROP) * 3) / 4, ((api->canvas_h / FOAM_PROP) * 3) / 4, 0);
foam_3 = api->scale(foam_data, ((api->canvas_w / FOAM_PROP) * 2) / 4, ((api->canvas_h / FOAM_PROP) * 2) / 4, 0);
foam_1 = api->scale(foam_data, ((api->canvas_w / FOAM_PROP) * 1) / 4, ((api->canvas_h / FOAM_PROP) * 1) / 4, 0);
SDL_FreeSurface(foam_data);
return(1);
return (1);
}
// We have multiple tools:
int foam_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return(1);
return (1);
}
// Load our icons:
SDL_Surface * foam_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
SDL_Surface *foam_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/images/magic/foam.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/foam.png", api->data_directory);
return(IMG_Load(fname));
return (IMG_Load(fname));
}
// Return our names, localized:
char * foam_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
char *foam_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(strdup(gettext_noop("Foam")));
return (strdup(gettext_noop("Foam")));
}
// Return our descriptions, localized:
char * foam_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
char *foam_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return(strdup(gettext_noop("Click and drag the mouse to cover an area with foamy bubbles.")));
return (strdup(gettext_noop("Click and drag the mouse to cover an area with foamy bubbles.")));
}
// Do the effect:
static void do_foam(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
int x, int y)
static void do_foam(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
{
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
int xx, yy, nx, ny;
/* SDL_Rect dest; */
for (yy = -FOAM_RADIUS; yy < FOAM_RADIUS; yy++)
@ -145,9 +139,7 @@ static void do_foam(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas
nx = (x / FOAM_PROP) + xx;
ny = (y / FOAM_PROP) + yy;
if (nx >= 0 && ny >= 0 &&
nx < foam_mask_w &&
ny < foam_mask_h)
if (nx >= 0 && ny >= 0 && nx < foam_mask_w && ny < foam_mask_h)
{
foam_mask[ny * foam_mask_w + nx] = 1;
}
@ -158,16 +150,27 @@ static void do_foam(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas
// Affect the canvas on drag:
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)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *) api, 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);
/* FIXME */
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;
}
update_rect->x = 0;
update_rect->y = 0;
@ -189,8 +192,8 @@ void foam_click(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, in
foam_mask_w = canvas->w / FOAM_PROP;
foam_mask_h = canvas->h / FOAM_PROP;
foam_mask = (int *) malloc(sizeof(int) * (foam_mask_w * foam_mask_h));
foam_mask_tmp = (int *) malloc(sizeof(int) * (foam_mask_w * foam_mask_h));
foam_mask = (int *)malloc(sizeof(int) * (foam_mask_w * foam_mask_h));
foam_mask_tmp = (int *)malloc(sizeof(int) * (foam_mask_w * foam_mask_h));
}
for (i = 0; i < foam_mask_w * foam_mask_h; i++)
@ -218,7 +221,7 @@ static int foam_mask_test(int r, int x, int y)
}
}
return(tot);
return (tot);
}
// Affect the canvas on release:
@ -230,7 +233,7 @@ void foam_release(magic_api * api ATTRIBUTE_UNUSED ATTRIBUTE_UNUSED, int which A
int changes, max_iters;
SDL_Rect dest;
int n;
SDL_Surface * img;
SDL_Surface *img;
SDL_BlitSurface(last, NULL, canvas, NULL);
@ -434,15 +437,17 @@ int foam_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_U
return 0; /* FIXME: Would be nice to tint the bubbles */
}
void foam_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void foam_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void foam_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void foam_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int foam_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_PAINT);
return (MODE_PAINT);
}

View file

@ -15,66 +15,57 @@ int fold_ox, fold_oy;
int fold_x, fold_y;
Uint8 fold_shadow_value;
Uint8 corner;
Mix_Chunk * fold_snd;
Mix_Chunk *fold_snd;
Uint8 fold_r, fold_g, fold_b;
Uint32 fold_color;
SDL_Surface * fold_surface_src, * fold_surface_dst;
SDL_Surface *fold_surface_src, *fold_surface_dst;
void fold_draw(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot,
int x, int y, SDL_Rect * update_rect);
static void fold_erase(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
int x, int y);
void translate_coords(SDL_Surface * canvas,int angle);
SDL_Surface * rotate(magic_api * api, SDL_Surface * canvas, int angle);
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
static void fold_erase(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
void translate_coords(SDL_Surface * canvas, int angle);
SDL_Surface *rotate(magic_api * api, SDL_Surface * canvas, int angle);
void fold_draw(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot,
int x, int y, SDL_Rect * update_rect);
static void fold_print_line(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
int x, int y);
static void fold_print_dark_line(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
int x, int y);
void translate_xy(SDL_Surface * canvas, int x, int y, int * a, int * b, int rotation);
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
static void fold_print_line(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
static void fold_print_dark_line(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
void translate_xy(SDL_Surface * canvas, int x, int y, int *a, int *b, int rotation);
Uint32 fold_api_version(void);
void fold_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int fold_init(magic_api * api);
int fold_get_tool_count(magic_api * api);
SDL_Surface * fold_get_icon(magic_api * api, int which);
char * fold_get_name(magic_api * api, int which);
char * fold_get_description(magic_api * api, int which, int mode);
SDL_Surface *fold_get_icon(magic_api * api, int which);
char *fold_get_name(magic_api * api, int which);
char *fold_get_description(magic_api * api, int which, int mode);
int fold_requires_colors(magic_api * api, int which);
void fold_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);
void fold_shutdown(magic_api * api);
void fold_click(magic_api * ptr, 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);
void fold_preview(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);
int fold_modes(magic_api * api, int which);
// Housekeeping functions
void fold_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 fold_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
inline Uint8 fold_what_corner(int x, int y, SDL_Surface * canvas);
void fold_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
Uint32 fold_api_version(void)
{
return(TP_MAGIC_API_VERSION);
return (TP_MAGIC_API_VERSION);
}
void fold_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b) //get the colors from API and store it in structure
{
fold_r=r;
fold_g=g;
fold_b=b;
fold_r = r;
fold_g = g;
fold_b = b;
}
int fold_init(magic_api * api)
@ -84,7 +75,7 @@ int fold_init(magic_api * api)
snprintf(fname, sizeof(fname), "%s/sounds/magic/fold.wav", api->data_directory);
fold_snd = Mix_LoadWAV(fname);
return(1);
return (1);
}
int fold_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
@ -92,334 +83,361 @@ int fold_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
return 1;
}
SDL_Surface * fold_get_icon(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
SDL_Surface *fold_get_icon(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/images/magic/fold.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/fold.png", api->data_directory);
return(IMG_Load(fname));
return (IMG_Load(fname));
}
char * fold_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) { return(gettext_noop("Fold")); }
char * fold_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED) { return strdup(gettext_noop("Choose a background color and click to turn the corner of the page over.")); }
int fold_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) { return 1; } //selected color will be a "backpage" color
static void fold_shadow(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * temp,
int x, int y)
char *fold_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
magic_api * api = (magic_api *) ptr;
Uint8 r,g,b,a;
SDL_GetRGBA(api->getpixel(temp, x, y),
temp->format, &r, &g, &b, &a);
return (gettext_noop("Fold"));
}
char *fold_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return strdup(gettext_noop("Choose a background color and click to turn the corner of the page over."));
}
int fold_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 1;
} //selected color will be a "backpage" color
static void fold_shadow(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * temp, int x, int y)
{
magic_api *api = (magic_api *) ptr;
Uint8 r, g, b, a;
SDL_GetRGBA(api->getpixel(temp, x, y), temp->format, &r, &g, &b, &a);
api->putpixel(canvas, x, y, SDL_MapRGBA(canvas->format,
max(r-160+fold_shadow_value*4,0), max(g-160+fold_shadow_value*4,0), max(b-160+fold_shadow_value*4,0), a));
max(r - 160 + fold_shadow_value * 4, 0), max(g - 160 + fold_shadow_value * 4,
0),
max(b - 160 + fold_shadow_value * 4, 0), a));
}
void fold_draw(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot,
int x, int y, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
float right_step_x, right_step_y, left_step_x, left_step_y;
float dist_x, dist_y;
int left_y, right_x;
float w, h;
SDL_Surface * temp;
temp=SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
SDL_BlitSurface(canvas,0,temp,0);
SDL_Surface *temp;
right_step_x=(float)(x-left_arm_x)/(float)(left_arm_x-fold_ox);
right_step_y=(float)(y-left_arm_y)/(float)(left_arm_x-fold_ox);
left_step_x=(float)(x-right_arm_x)/(float)(right_arm_y-fold_oy);
left_step_y=(float)(y-right_arm_y)/(float)(right_arm_y-fold_oy);
for (w=0;w < canvas->w;w+=0.5)
for(h=0;h < canvas->h;h+=0.5)
temp = SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask,
canvas->format->Amask);
SDL_BlitSurface(canvas, 0, temp, 0);
right_step_x = (float)(x - left_arm_x) / (float)(left_arm_x - fold_ox);
right_step_y = (float)(y - left_arm_y) / (float)(left_arm_x - fold_ox);
left_step_x = (float)(x - right_arm_x) / (float)(right_arm_y - fold_oy);
left_step_y = (float)(y - right_arm_y) / (float)(right_arm_y - fold_oy);
for (w = 0; w < canvas->w; w += 0.5)
for (h = 0; h < canvas->h; h += 0.5)
{
dist_x=right_step_x*w+left_step_x*h;
dist_y=right_step_y*w+left_step_y*h;
api->putpixel(canvas, x-dist_x, y-dist_y, api->getpixel(temp,w,h));
dist_x = right_step_x * w + left_step_x * h;
dist_y = right_step_y * w + left_step_y * h;
api->putpixel(canvas, x - dist_x, y - dist_y, api->getpixel(temp, w, h));
}
// Erasing the triangle.
// The 1 pixel in plus is a workaround for api-line not getting the end in some lines.
if (left_arm_x > canvas->w)
{
left_y=(float)right_arm_y/left_arm_x*(left_arm_x-canvas->w);
left_y = (float)right_arm_y / left_arm_x * (left_arm_x - canvas->w);
for (h = 0; h <= right_arm_y; h++)
api->line((void *)api, which, canvas, snapshot, canvas->w, left_y-h, -1, right_arm_y-h, 1, fold_erase);
api->line((void *)api, which, canvas, snapshot, canvas->w, left_y - h, -1, right_arm_y - h, 1, fold_erase);
}
else if (right_arm_y > canvas->h)
{
right_x=(float)left_arm_x/right_arm_y*(right_arm_y-canvas->h);
right_x = (float)left_arm_x / right_arm_y * (right_arm_y - canvas->h);
for (w = 0; w <= left_arm_x; w++)
api->line((void *)api, which, canvas, snapshot, left_arm_x-w, 0, right_x-w, canvas->h +1, 1, fold_erase);
api->line((void *)api, which, canvas, snapshot, left_arm_x - w, 0, right_x - w, canvas->h + 1, 1, fold_erase);
}
else
for (w = 0; w <= min(left_arm_x,right_arm_y); w++) // The -1 values are because api->line
api->line((void *)api, which, canvas, snapshot, left_arm_x-w, 0, -1, right_arm_y-w, 1, fold_erase);
for (w = 0; w <= min(left_arm_x, right_arm_y); w++) // The -1 values are because api->line
api->line((void *)api, which, canvas, snapshot, left_arm_x - w, 0, -1, right_arm_y - w, 1, fold_erase);
SDL_BlitSurface(canvas,0,temp,0);
SDL_BlitSurface(canvas, 0, temp, 0);
// Shadows
if (left_arm_x > canvas->w)
{
for (fold_shadow_value = 0; fold_shadow_value < 40; fold_shadow_value+=1)
api->line((void *)api, which, canvas, temp, canvas->w, left_y-fold_shadow_value, 0, right_arm_y-fold_shadow_value, 1, fold_shadow);
for (fold_shadow_value = 0; fold_shadow_value < 40; fold_shadow_value += 1)
api->line((void *)api, which, canvas, temp, canvas->w, left_y - fold_shadow_value, 0,
right_arm_y - fold_shadow_value, 1, fold_shadow);
}
else if (right_arm_y > canvas->h)
{
for (fold_shadow_value = 0; fold_shadow_value < 40; fold_shadow_value+=1)
api->line((void *)api, which, canvas, temp, left_arm_x-fold_shadow_value, 0, right_x - fold_shadow_value, canvas->h, 1, fold_shadow);
for (fold_shadow_value = 0; fold_shadow_value < 40; fold_shadow_value += 1)
api->line((void *)api, which, canvas, temp, left_arm_x - fold_shadow_value, 0, right_x - fold_shadow_value,
canvas->h, 1, fold_shadow);
}
else
for (fold_shadow_value = 0; fold_shadow_value < 40; fold_shadow_value+=1)
api->line((void *)api, which, canvas, temp, left_arm_x-fold_shadow_value, 0, 0, right_arm_y-fold_shadow_value, 1, fold_shadow);
for (fold_shadow_value = 0; fold_shadow_value < 40; fold_shadow_value += 1)
api->line((void *)api, which, canvas, temp, left_arm_x - fold_shadow_value, 0, 0, right_arm_y - fold_shadow_value,
1, fold_shadow);
SDL_BlitSurface(canvas,0,temp,0);
SDL_BlitSurface(canvas, 0, temp, 0);
for (fold_shadow_value = 0; fold_shadow_value < 40; fold_shadow_value+=1)
for (fold_shadow_value = 0; fold_shadow_value < 40; fold_shadow_value += 1)
{
if (fold_shadow_value*left_step_x > x || fold_shadow_value*right_step_y > y) break;
if (fold_shadow_value * left_step_x > x || fold_shadow_value * right_step_y > y)
break;
dist_x=fold_shadow_value*(right_step_x+left_step_x);
dist_y=fold_shadow_value*(right_step_y+left_step_y);
api->line((void *)api, which, canvas, temp, left_arm_x+fold_shadow_value*right_step_x, fold_shadow_value*right_step_y, fold_shadow_value*left_step_x, right_arm_y+fold_shadow_value*left_step_y, 1, fold_shadow);
dist_x = fold_shadow_value * (right_step_x + left_step_x);
dist_y = fold_shadow_value * (right_step_y + left_step_y);
api->line((void *)api, which, canvas, temp, left_arm_x + fold_shadow_value * right_step_x,
fold_shadow_value * right_step_y, fold_shadow_value * left_step_x,
right_arm_y + fold_shadow_value * left_step_y, 1, fold_shadow);
}
api->line((void *)api, which, canvas, snapshot, x, y, right_arm_x, right_arm_y, 1, fold_print_line);
api->line((void *)api, which, canvas, snapshot, x, y, left_arm_x, left_arm_y, 1, fold_print_line);
api->line((void *)api, which, canvas, snapshot, left_arm_x, left_arm_y, right_arm_x, right_arm_y, 1, fold_print_dark_line);
api->line((void *)api, which, canvas, snapshot, left_arm_x, left_arm_y, right_arm_x, right_arm_y, 1,
fold_print_dark_line);
}
SDL_Surface * rotate(magic_api * api, SDL_Surface * canvas, int angle)
SDL_Surface *rotate(magic_api * api, SDL_Surface * canvas, int angle)
{
SDL_Surface * temp;
int x,y;
int a,b;
SDL_Surface *temp;
int x, y;
int a, b;
if (angle==180)
temp=SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
if (angle == 180)
temp = SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask,
canvas->format->Amask);
else
temp=SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->h, canvas->w, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
temp = SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->h, canvas->w, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask,
canvas->format->Amask);
switch (angle)
{
case 90:
for (x=0; x<canvas->w; x++)
for (y=0; y<canvas->h; y++)
for (x = 0; x < canvas->w; x++)
for (y = 0; y < canvas->h; y++)
{
translate_xy(canvas,x,y,&a,&b,90);
api->putpixel(temp,a,b,api->getpixel(canvas, x, y));
translate_xy(canvas, x, y, &a, &b, 90);
api->putpixel(temp, a, b, api->getpixel(canvas, x, y));
}
break;
case 180:
// printf("%i, %i\n",temp,canvas);
for (x=0; x<canvas->w; x++)
for (y=0; y<canvas->h; y++)
for (x = 0; x < canvas->w; x++)
for (y = 0; y < canvas->h; y++)
{
translate_xy(canvas,x,y,&a,&b,180);
api->putpixel(temp,a,b,api->getpixel(canvas, x, y));
translate_xy(canvas, x, y, &a, &b, 180);
api->putpixel(temp, a, b, api->getpixel(canvas, x, y));
}
break;
case 270:
for (x=0; x<canvas->w; x++)
for (y=0; y<canvas->h; y++)
for (x = 0; x < canvas->w; x++)
for (y = 0; y < canvas->h; y++)
{
translate_xy(canvas,x,y,&a,&b,270);
api->putpixel(temp,a,b,api->getpixel(canvas, x, y));
translate_xy(canvas, x, y, &a, &b, 270);
api->putpixel(temp, a, b, api->getpixel(canvas, x, y));
}
break;
}
return temp;
}
void translate_coords(SDL_Surface * canvas,int angle)
void translate_coords(SDL_Surface * canvas, int angle)
{
int a,b;
int a, b;
switch (angle)
{
case 90:
translate_xy(canvas,right_arm_x,right_arm_y,&a,&b,90);
right_arm_x=a;
right_arm_y=b;
translate_xy(canvas,left_arm_x,left_arm_y,&a,&b,90);
left_arm_x=a;
left_arm_y=b;
translate_xy(canvas, right_arm_x, right_arm_y, &a, &b, 90);
right_arm_x = a;
right_arm_y = b;
translate_xy(canvas, left_arm_x, left_arm_y, &a, &b, 90);
left_arm_x = a;
left_arm_y = b;
break;
case 180:
right_arm_x=canvas->w-1-right_arm_x;
right_arm_y=canvas->h-1-right_arm_y;
left_arm_x=canvas->w-1-left_arm_x;
left_arm_y=canvas->h-1-left_arm_y;
right_arm_x = canvas->w - 1 - right_arm_x;
right_arm_y = canvas->h - 1 - right_arm_y;
left_arm_x = canvas->w - 1 - left_arm_x;
left_arm_y = canvas->h - 1 - left_arm_y;
break;
case 270:
translate_xy(canvas,right_arm_x,right_arm_y,&a,&b,270);
right_arm_x=a;
right_arm_y=b;
translate_xy(canvas,left_arm_x, left_arm_y, &a, &b, 270);
left_arm_x=a;
left_arm_y=b;
translate_xy(canvas, right_arm_x, right_arm_y, &a, &b, 270);
right_arm_x = a;
right_arm_y = b;
translate_xy(canvas, left_arm_x, left_arm_y, &a, &b, 270);
left_arm_x = a;
left_arm_y = b;
break;
}
}
void translate_xy(SDL_Surface * canvas, int x, int y, int * a, int * b, int rotation)
void translate_xy(SDL_Surface * canvas, int x, int y, int *a, int *b, int rotation)
{
switch (rotation)
{
case 90:
*a=y;
*b=canvas->w -1 -x;
*a = y;
*b = canvas->w - 1 - x;
break;
case 180:
*a=canvas->w -1 -x;
*b=canvas->h -1 -y;
*a = canvas->w - 1 - x;
*b = canvas->h - 1 - y;
break;
case 270:
*a=canvas->h -1 -y;
*b=x;
*a = canvas->h - 1 - y;
*b = x;
break;
}
}
void fold_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)
{
int a,b;
SDL_Surface * temp, *temp2;
int a, b;
SDL_Surface *temp, *temp2;
x=fold_x;
y=fold_y;
fold_ox=fold_oy=0;
x = fold_x;
y = fold_y;
fold_ox = fold_oy = 0;
SDL_BlitSurface(snapshot, 0, canvas, 0);
switch (corner)
{
case 1:
translate_xy(canvas,x,y,&a,&b,90);
translate_coords(canvas,90);
temp=rotate(api, canvas, 90);
fold_draw (api, which, temp, snapshot, a, b,update_rect);
temp2=rotate(api,temp,270);
SDL_BlitSurface(temp2,0,canvas,0);
translate_xy(canvas, x, y, &a, &b, 90);
translate_coords(canvas, 90);
temp = rotate(api, canvas, 90);
fold_draw(api, which, temp, snapshot, a, b, update_rect);
temp2 = rotate(api, temp, 270);
SDL_BlitSurface(temp2, 0, canvas, 0);
SDL_FreeSurface(temp);
SDL_FreeSurface(temp2);
break;
case 2:
fold_draw (api, which, canvas, snapshot, x,y,update_rect);
fold_draw(api, which, canvas, snapshot, x, y, update_rect);
break;
case 3:
translate_xy(canvas,x,y,&a,&b,270);
translate_coords(canvas,270);
temp=rotate(api, canvas, 270);
fold_draw (api, which, temp, snapshot, a, b,update_rect);
temp2=rotate(api,temp,90);
SDL_BlitSurface(temp2,0,canvas,0);
translate_xy(canvas, x, y, &a, &b, 270);
translate_coords(canvas, 270);
temp = rotate(api, canvas, 270);
fold_draw(api, which, temp, snapshot, a, b, update_rect);
temp2 = rotate(api, temp, 90);
SDL_BlitSurface(temp2, 0, canvas, 0);
SDL_FreeSurface(temp);
SDL_FreeSurface(temp2);
break;
case 4:
translate_xy(canvas,x,y,&a,&b,180);
translate_coords(canvas,180);
temp=rotate(api, canvas, 180);
fold_draw (api, which, temp, snapshot, a, b,update_rect);
temp2=rotate(api,temp,180);
SDL_BlitSurface(temp2,0,canvas,0);
SDL_FreeSurface (temp);
SDL_FreeSurface (temp2);
translate_xy(canvas, x, y, &a, &b, 180);
translate_coords(canvas, 180);
temp = rotate(api, canvas, 180);
fold_draw(api, which, temp, snapshot, a, b, update_rect);
temp2 = rotate(api, temp, 180);
SDL_BlitSurface(temp2, 0, canvas, 0);
SDL_FreeSurface(temp);
SDL_FreeSurface(temp2);
break;
}
update_rect->x=update_rect->y=0;
update_rect->w=canvas->w;
update_rect->h=canvas->h;
update_rect->x = update_rect->y = 0;
update_rect->w = canvas->w;
update_rect->h = canvas->h;
api->playsound(fold_snd, (x * 255) / canvas->w, 255);
}
void fold_shutdown(magic_api * api ATTRIBUTE_UNUSED)
{
{
Mix_FreeChunk(fold_snd);
SDL_FreeSurface(fold_surface_dst);
SDL_FreeSurface(fold_surface_src);
}
}
// Interactivity functions
inline Uint8 fold_what_corner(int x, int y, SDL_Surface * canvas)
{
if (x>=canvas->w/2)
if (x >= canvas->w / 2)
{
if (y>=canvas->h/2) return 4;
else return 1;
if (y >= canvas->h / 2)
return 4;
else
return 1;
}
else
{
if (y>=canvas->h/2) return 3;
else return 2;
if (y >= canvas->h / 2)
return 3;
else
return 2;
}
}
static void fold_print_line(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last,
static void fold_print_line(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last,
int x, int y)
{
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
api->putpixel(canvas, x, y, SDL_MapRGB(last->format, 222, 222, 222)); //Middle gray. Color have been set arbitrary.
}
static void fold_print_dark_line(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
int x, int y)
static void fold_print_dark_line(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
{
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
api->putpixel(canvas, x, y, SDL_MapRGB(last->format, 90, 90, 90)); //It should not look too black nor too white with shadowed colors.
}
static void fold_erase(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
static void fold_erase(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
int x, int y)
{
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, fold_r, fold_g, fold_b));
}
void fold_click(magic_api * ptr, int which, int mode ATTRIBUTE_UNUSED,
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)
{
magic_api * api = (magic_api *) ptr;
corner=fold_what_corner(x, y, snapshot);
magic_api *api = (magic_api *) ptr;
corner = fold_what_corner(x, y, snapshot);
switch (corner)
{
case 1:
fold_ox=canvas->w-1;
fold_oy=0;
fold_ox = canvas->w - 1;
fold_oy = 0;
break;
case 2:
fold_ox=fold_oy=0;
fold_ox = fold_oy = 0;
break;
case 3:
fold_ox=0;
fold_oy=canvas->h-1;
fold_ox = 0;
fold_oy = canvas->h - 1;
break;
case 4:
fold_ox=canvas->w-1;
fold_oy=canvas->h-1;
fold_ox = canvas->w - 1;
fold_oy = canvas->h - 1;
break;
}
@ -433,45 +451,53 @@ void fold_preview(magic_api * api, int which, SDL_Surface * canvas,
int middle_point_x;
int middle_point_y;
fold_x=x;
fold_y=y;
SDL_BlitSurface(snapshot,0,canvas,0);
fold_x = x;
fold_y = y;
SDL_BlitSurface(snapshot, 0, canvas, 0);
middle_point_x=(fold_ox+x)/2;
middle_point_y=(fold_oy+y)/2;
middle_point_x = (fold_ox + x) / 2;
middle_point_y = (fold_oy + y) / 2;
switch(corner)
switch (corner)
{
case 1: //Right Upper
right_arm_x=fold_ox- (fold_ox-middle_point_x)-middle_point_y*middle_point_y/(fold_ox-middle_point_x);
right_arm_y=fold_oy;
right_arm_x = fold_ox - (fold_ox - middle_point_x) - middle_point_y * middle_point_y / (fold_ox - middle_point_x);
right_arm_y = fold_oy;
left_arm_x=fold_ox;
left_arm_y=fold_oy-(fold_oy-middle_point_y)-(fold_ox-middle_point_x)*(fold_ox-middle_point_x)/(fold_oy-middle_point_y);
left_arm_x = fold_ox;
left_arm_y =
fold_oy - (fold_oy - middle_point_y) - (fold_ox - middle_point_x) * (fold_ox - middle_point_x) / (fold_oy -
middle_point_y);
break;
case 2: //LU
right_arm_x=fold_ox;
right_arm_y=middle_point_y+middle_point_x*middle_point_x/middle_point_y;
right_arm_x = fold_ox;
right_arm_y = middle_point_y + middle_point_x * middle_point_x / middle_point_y;
left_arm_x=middle_point_x+middle_point_y*middle_point_y/middle_point_x;
left_arm_y=fold_oy;
left_arm_x = middle_point_x + middle_point_y * middle_point_y / middle_point_x;
left_arm_y = fold_oy;
break;
case 3: //LL
right_arm_x=middle_point_x+(fold_oy-middle_point_y)*(fold_oy-middle_point_y)/middle_point_x;
right_arm_y=fold_oy;
right_arm_x = middle_point_x + (fold_oy - middle_point_y) * (fold_oy - middle_point_y) / middle_point_x;
right_arm_y = fold_oy;
left_arm_x=fold_ox;
left_arm_y=fold_oy-(fold_oy-middle_point_y)-(fold_ox-middle_point_x)*(fold_ox-middle_point_x)/(fold_oy-middle_point_y);
left_arm_x = fold_ox;
left_arm_y =
fold_oy - (fold_oy - middle_point_y) - (fold_ox - middle_point_x) * (fold_ox - middle_point_x) / (fold_oy -
middle_point_y);
break;
case 4: //RL
right_arm_x=fold_ox;
right_arm_y=fold_oy-(fold_oy-middle_point_y)-(fold_ox-middle_point_x)*(fold_ox-middle_point_x)/(fold_oy-middle_point_y);
right_arm_x = fold_ox;
right_arm_y =
fold_oy - (fold_oy - middle_point_y) - (fold_ox - middle_point_x) * (fold_ox - middle_point_x) / (fold_oy -
middle_point_y);
left_arm_x=fold_ox-(fold_ox-middle_point_x)-(fold_oy-middle_point_y)*(fold_oy-middle_point_y)/(fold_ox-middle_point_x);
left_arm_y=fold_oy;
left_arm_x =
fold_ox - (fold_ox - middle_point_x) - (fold_oy - middle_point_y) * (fold_oy - middle_point_y) / (fold_ox -
middle_point_x);
left_arm_y = fold_oy;
break;
}
@ -479,30 +505,31 @@ void fold_preview(magic_api * api, int which, SDL_Surface * canvas,
api->line((void *)api, which, canvas, snapshot, x, y, left_arm_x, left_arm_y, 1, fold_print_line);
api->line((void *)api, which, canvas, snapshot, left_arm_x, left_arm_y, right_arm_x, right_arm_y, 1, fold_print_line);
update_rect->x=update_rect->y=0;
update_rect->w=canvas->w;
update_rect->h=canvas->h;
update_rect->x = update_rect->y = 0;
update_rect->w = canvas->w;
update_rect->h = canvas->h;
}
void fold_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)
{
// Avoid division by zero when calculating the preview
x=clamp(2,x,canvas->w-2);
y=clamp(2,y,canvas->h-2);
x = clamp(2, x, canvas->w - 2);
y = clamp(2, y, canvas->h - 2);
fold_preview(api, which, canvas, snapshot, ox, oy, x, y, update_rect);
}
void fold_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void fold_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void fold_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void fold_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int fold_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_PAINT_WITH_PREVIEW);
return (MODE_PAINT_WITH_PREVIEW);
}

View file

@ -22,15 +22,15 @@
#define SEG_RIGHT_TOP_BOTTOM (SEG_RIGHT | SEG_TOP | SEG_BOTTOM)
#define SEG_LEFT_RIGHT_TOP_BOTTOM (SEG_LEFT | SEG_RIGHT | SEG_TOP | SEG_BOTTOM)
Mix_Chunk * fretwork_snd;
Mix_Chunk *fretwork_snd;
unsigned int img_w, img_h;
unsigned int fretwork_segments_x, fretwork_segments_y; //how many segments do we have?
static int fretwork_math_ceil(int x, int y); //ceil() in cstdlib returns float and is relative slow, so we'll use our one
static Uint8 * fretwork_status_of_segments; //a place to store an info about bitmap used for selected segment
static char ** fretwork_images; //the pathes to all the images needed
static Uint8 *fretwork_status_of_segments; //a place to store an info about bitmap used for selected segment
static char **fretwork_images; //the pathes to all the images needed
static unsigned int fretwork_segment_modified; //which segment was modified this time?
static unsigned int fretwork_segment_modified_last =0; //which segment was last modified
static unsigned int fretwork_segment_to_add =0; //a segment that should be added to solve corner joint
static unsigned int fretwork_segment_modified_last = 0; //which segment was last modified
static unsigned int fretwork_segment_to_add = 0; //a segment that should be added to solve corner joint
static unsigned int fretwork_segment_last_clicked;
static Uint8 fretwork_r, fretwork_g, fretwork_b;
static unsigned int fretwork_full_runs; //The count of the clicks in full mode
@ -38,8 +38,8 @@ static unsigned int fretwork_segment_start_rectangle; //the segment were t
static unsigned int fretwork_update_rectangle_width; //the width of the update_rectangle
static unsigned int fretwork_update_rectangle_height; //the height of the update_rectangle
static SDL_Rect modification_rect;
static SDL_Surface * canvas_backup;
static SDL_Surface * fretwork_one_back, * fretwork_three_back, * fretwork_four_back, * fretwork_corner_back;
static SDL_Surface *canvas_backup;
static SDL_Surface *fretwork_one_back, *fretwork_three_back, *fretwork_four_back, *fretwork_corner_back;
// Housekeeping functions
@ -47,59 +47,55 @@ static SDL_Surface * fretwork_one_back, * fretwork_three_back, * fretwork_four_b
Uint32 fretwork_api_version(void);
int fretwork_modes(magic_api * api, int which);
void fretwork_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
static void fretwork_colorize(magic_api * api, SDL_Surface * dest, SDL_Surface * src );
static void fretwork_colorize(magic_api * api, SDL_Surface * dest, SDL_Surface * src);
int fretwork_init(magic_api * api);
int fretwork_get_tool_count(magic_api * api);
SDL_Surface * fretwork_get_icon(magic_api * api, int which);
char * fretwork_get_name(magic_api * api, int which);
char * fretwork_get_description(magic_api * api, int which, int mode);
SDL_Surface *fretwork_get_icon(magic_api * api, int which);
char *fretwork_get_name(magic_api * api, int which);
char *fretwork_get_description(magic_api * api, int which, int mode);
int fretwork_requires_colors(magic_api * api, int which);
void fretwork_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);
void fretwork_shutdown(magic_api * api);
void fretwork_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * snapshot);
void fretwork_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * snapshot);
inline void fretwork_extract_coords_from_segment(unsigned int segment, Sint16 * x, Sint16 * y);
void fretwork_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);
void fretwork_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
static void fretwork_draw_wrapper(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
int x, int y);
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
static void fretwork_draw_wrapper(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
inline unsigned int fretwork_get_segment(int x, int y);
SDL_Surface * fretwork_one, * fretwork_three, * fretwork_four, * fretwork_corner;
SDL_Surface *fretwork_one, *fretwork_three, *fretwork_four, *fretwork_corner;
Uint32 fretwork_api_version(void)
{
return(TP_MAGIC_API_VERSION);
return (TP_MAGIC_API_VERSION);
}
int fretwork_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_PAINT|MODE_FULLSCREEN);
return (MODE_PAINT | MODE_FULLSCREEN);
}
void fretwork_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b)
{
fretwork_r=r;
fretwork_g=g;
fretwork_b=b;
fretwork_colorize(api,fretwork_one, fretwork_one_back);
fretwork_r = r;
fretwork_g = g;
fretwork_b = b;
fretwork_colorize(api, fretwork_one, fretwork_one_back);
fretwork_colorize(api, fretwork_three, fretwork_three_back);
fretwork_colorize(api, fretwork_four, fretwork_four_back);
fretwork_colorize(api, fretwork_corner, fretwork_corner_back);
}
/* Adapted from flower.c */
static void fretwork_colorize(magic_api * api, SDL_Surface * dest, SDL_Surface * src )
static void fretwork_colorize(magic_api * api, SDL_Surface * dest, SDL_Surface * src)
{
int x, y;
Uint8 r, g, b, a;
@ -111,12 +107,9 @@ static void fretwork_colorize(magic_api * api, SDL_Surface * dest, SDL_Surface *
{
for (x = 0; x < src->w; x++)
{
SDL_GetRGBA(api->getpixel(src, x, y),
src->format, &r, &g, &b, &a);
SDL_GetRGBA(api->getpixel(src, x, y), src->format, &r, &g, &b, &a);
api->putpixel(dest, x, y,
SDL_MapRGBA(dest->format,
fretwork_r, fretwork_g, fretwork_b, a));
api->putpixel(dest, x, y, SDL_MapRGBA(dest->format, fretwork_r, fretwork_g, fretwork_b, a));
}
}
@ -130,24 +123,24 @@ int fretwork_init(magic_api * api)
char fname[1024];
Uint8 i; //is always < 4, so Uint8 seems to be a good idea
fretwork_images=(char **)malloc(sizeof(char *)*4);
fretwork_images = (char **)malloc(sizeof(char *) * 4);
for (i = 0; i < 4; i++)
fretwork_images[i]=(char *)malloc(sizeof(char)*1024);
fretwork_images[i] = (char *)malloc(sizeof(char) * 1024);
snprintf(fretwork_images[0], 1024*sizeof(char), "%s/images/magic/fretwork_one.png", api->data_directory);
snprintf(fretwork_images[1], 1024*sizeof(char), "%s/images/magic/fretwork_three.png", api->data_directory);
snprintf(fretwork_images[2], 1024*sizeof(char), "%s/images/magic/fretwork_four.png", api->data_directory);
snprintf(fretwork_images[3], 1024*sizeof(char), "%s/images/magic/fretwork_corner.png", api->data_directory);
snprintf(fretwork_images[0], 1024 * sizeof(char), "%s/images/magic/fretwork_one.png", api->data_directory);
snprintf(fretwork_images[1], 1024 * sizeof(char), "%s/images/magic/fretwork_three.png", api->data_directory);
snprintf(fretwork_images[2], 1024 * sizeof(char), "%s/images/magic/fretwork_four.png", api->data_directory);
snprintf(fretwork_images[3], 1024 * sizeof(char), "%s/images/magic/fretwork_corner.png", api->data_directory);
fretwork_one=IMG_Load(fretwork_images[0]);
fretwork_three=IMG_Load(fretwork_images[1]);
fretwork_four=IMG_Load(fretwork_images[2]);
fretwork_corner=IMG_Load(fretwork_images[3]);
fretwork_one_back=IMG_Load(fretwork_images[0]);
fretwork_three_back=IMG_Load(fretwork_images[1]);
fretwork_four_back=IMG_Load(fretwork_images[2]);
fretwork_corner_back=IMG_Load(fretwork_images[3]);
fretwork_one = IMG_Load(fretwork_images[0]);
fretwork_three = IMG_Load(fretwork_images[1]);
fretwork_four = IMG_Load(fretwork_images[2]);
fretwork_corner = IMG_Load(fretwork_images[3]);
fretwork_one_back = IMG_Load(fretwork_images[0]);
fretwork_three_back = IMG_Load(fretwork_images[1]);
fretwork_four_back = IMG_Load(fretwork_images[2]);
fretwork_corner_back = IMG_Load(fretwork_images[3]);
img_w = fretwork_one->w;
img_h = fretwork_one->h;
@ -155,7 +148,7 @@ int fretwork_init(magic_api * api)
snprintf(fname, sizeof(fname), "%s/sounds/magic/fretwork.ogg", api->data_directory);
fretwork_snd = Mix_LoadWAV(fname);
return(1);
return (1);
}
int fretwork_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
@ -163,26 +156,32 @@ int fretwork_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
return 1;
}
SDL_Surface * fretwork_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
SDL_Surface *fretwork_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/images/magic/fretwork.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/fretwork.png", api->data_directory);
return(IMG_Load(fname));
return (IMG_Load(fname));
}
char * fretwork_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) { return strdup(gettext_noop("Fretwork")); }
char *fretwork_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return strdup(gettext_noop("Fretwork"));
}
char * fretwork_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode) {
if (mode==MODE_PAINT)
char *fretwork_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode)
{
if (mode == MODE_PAINT)
return strdup(gettext_noop("Click and drag to draw repetitive patterns. "));
else
return strdup(gettext_noop("Click to surround your picture with repetitive patterns."));
}
}
int fretwork_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) { return 1;}
int fretwork_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 1;
}
void fretwork_release(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * snapshot ATTRIBUTE_UNUSED,
@ -194,7 +193,7 @@ void fretwork_shutdown(magic_api * api ATTRIBUTE_UNUSED)
{
Uint8 i;
if (fretwork_snd!=NULL)
if (fretwork_snd != NULL)
Mix_FreeChunk(fretwork_snd);
SDL_FreeSurface(fretwork_one);
SDL_FreeSurface(fretwork_three);
@ -213,22 +212,25 @@ void fretwork_shutdown(magic_api * api ATTRIBUTE_UNUSED)
free(fretwork_status_of_segments);
}
void fretwork_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED)
void fretwork_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED)
{
//we've to compute the quantity of segments in each direction
canvas_backup=SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
canvas_backup = SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask,
canvas->format->Amask);
SDL_BlitSurface(canvas, NULL, canvas_backup, NULL);
fretwork_segments_x=fretwork_math_ceil(canvas->w,img_w);
fretwork_segments_y=fretwork_math_ceil(canvas->h,img_h);
fretwork_status_of_segments=(Uint8 *)calloc(fretwork_segments_x*fretwork_segments_y + 1, sizeof(Uint8)); //segments starts at 1, while fretwork_status_of_segments[] starts at 0
fretwork_full_runs=1;
fretwork_segments_x = fretwork_math_ceil(canvas->w, img_w);
fretwork_segments_y = fretwork_math_ceil(canvas->h, img_h);
fretwork_status_of_segments = (Uint8 *) calloc(fretwork_segments_x * fretwork_segments_y + 1, sizeof(Uint8)); //segments starts at 1, while fretwork_status_of_segments[] starts at 0
fretwork_full_runs = 1;
}
void fretwork_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * snapshot ATTRIBUTE_UNUSED)
void fretwork_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * snapshot ATTRIBUTE_UNUSED)
{
free(fretwork_status_of_segments);
fretwork_status_of_segments = NULL;
@ -240,27 +242,30 @@ void fretwork_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UN
static int fretwork_math_ceil(int x, int y)
{
int temp;
temp=(int)x/y;
if (x%y)
return temp+1;
else return temp;
temp = (int)x / y;
if (x % y)
return temp + 1;
else
return temp;
}
inline unsigned int fretwork_get_segment(int x, int y)
{
int xx; //segments are numerated just like pixels
int yy; //in computer graphics: left upper (=1), ... ,right upper,
//left bottom, ... , right bottom
xx=fretwork_math_ceil(x, img_w);
yy=fretwork_math_ceil(y, img_h);
return (yy-1)*fretwork_segments_x+xx;
//left bottom, ... , right bottom
xx = fretwork_math_ceil(x, img_w);
yy = fretwork_math_ceil(y, img_h);
return (yy - 1) * fretwork_segments_x + xx;
}
inline void fretwork_extract_coords_from_segment(unsigned int segment, Sint16 * x, Sint16 * y)
{
*x=((segment%fretwork_segments_x)-1)*img_w; //useful to set update_rect as small as possible
*y=(int)(segment/fretwork_segments_x)*img_h;
*x = ((segment % fretwork_segments_x) - 1) * img_w; //useful to set update_rect as small as possible
*y = (int)(segment / fretwork_segments_x) * img_h;
}
/* static void fretwork_flip(void * ptr, SDL_Surface * dest, SDL_Surface * src) */
@ -274,74 +279,79 @@ inline void fretwork_extract_coords_from_segment(unsigned int segment, Sint16 *
/* api->putpixel(dest, x, y, api->getpixel(src, x, src->h-y)); */
/* } */
static void fretwork_flip_flop(void * ptr, SDL_Surface * dest, SDL_Surface * src)
static void fretwork_flip_flop(void *ptr, SDL_Surface * dest, SDL_Surface * src)
{
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
Sint16 x, y;
for (x=0; x<dest->w; x++)
for (y=0; y<dest->h; y++)
api->putpixel(dest, dest->w-1-x, dest->h-1-y, api->getpixel(src, x, y));
for (x = 0; x < dest->w; x++)
for (y = 0; y < dest->h; y++)
api->putpixel(dest, dest->w - 1 - x, dest->h - 1 - y, api->getpixel(src, x, y));
}
static void fretwork_rotate (void * ptr, SDL_Surface * dest, SDL_Surface * src, _Bool direction)
static void fretwork_rotate(void *ptr, SDL_Surface * dest, SDL_Surface * src, _Bool direction)
//src and dest must have same size
{
magic_api * api = (magic_api *) ptr;
Sint16 x,y;
magic_api *api = (magic_api *) ptr;
Sint16 x, y;
if (direction) //rotate -90 degs
{
for (x = 0; x<dest->w; x++)
for (y =0; y<dest->h; y++)
api->putpixel(dest, x, y, api->getpixel(src,y,src->h-1-x));
for (x = 0; x < dest->w; x++)
for (y = 0; y < dest->h; y++)
api->putpixel(dest, x, y, api->getpixel(src, y, src->h - 1 - x));
}
else //rotate +90 degs
{
for (x=0; x<dest->w; x++)
for (y=0; y<dest->h; y++)
api->putpixel(dest,x,y,api->getpixel(src,src->h-y-1,x));
for (x = 0; x < dest->w; x++)
for (y = 0; y < dest->h; y++)
api->putpixel(dest, x, y, api->getpixel(src, src->h - y - 1, x));
}
}
void fretwork_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)
{
int left_x, right_x, top_y, bottom_y;
fretwork_segment_modified_last = 0;
if (mode==MODE_PAINT)
if (mode == MODE_PAINT)
{
fretwork_segment_last_clicked=fretwork_get_segment(x,y);
fretwork_segment_last_clicked = fretwork_get_segment(x, y);
fretwork_drag(api, which, canvas, snapshot, x, y, x, y, update_rect);
}
else
{
if (fretwork_full_runs<=min(fretwork_segments_x,fretwork_segments_y)/2)
if (fretwork_full_runs <= min(fretwork_segments_x, fretwork_segments_y) / 2)
{
left_x=img_w*fretwork_full_runs;
right_x=img_w*fretwork_segments_x-img_w*fretwork_full_runs;
top_y=img_h*fretwork_full_runs;
bottom_y=img_h*fretwork_segments_y-img_h*(fretwork_full_runs-1);
left_x = img_w * fretwork_full_runs;
right_x = img_w * fretwork_segments_x - img_w * fretwork_full_runs;
top_y = img_h * fretwork_full_runs;
bottom_y = img_h * fretwork_segments_y - img_h * (fretwork_full_runs - 1);
//left line
api->line((void *) api, which, canvas, snapshot, left_x, top_y, left_x, bottom_y, img_w/2, fretwork_draw_wrapper);
api->line((void *)api, which, canvas, snapshot, left_x, top_y, left_x, bottom_y, img_w / 2,
fretwork_draw_wrapper);
//top line
api->line((void *) api, which, canvas, snapshot, left_x, top_y, right_x, top_y, img_w/2, fretwork_draw_wrapper);
api->line((void *)api, which, canvas, snapshot, left_x, top_y, right_x, top_y, img_w / 2,
fretwork_draw_wrapper);
//bottom line
api->line((void *) api, which, canvas, snapshot, left_x, bottom_y, right_x, bottom_y, img_w/2, fretwork_draw_wrapper);
api->line((void *)api, which, canvas, snapshot, left_x, bottom_y, right_x, bottom_y, img_w / 2,
fretwork_draw_wrapper);
//right line
api->line((void *) api, which, canvas, snapshot, right_x, top_y, right_x, bottom_y, img_w/2, fretwork_draw_wrapper);
api->line((void *)api, which, canvas, snapshot, right_x, top_y, right_x, bottom_y, img_w / 2,
fretwork_draw_wrapper);
fretwork_full_runs +=1;
update_rect->x=0;
update_rect->y=0;
update_rect->w=canvas->w;
update_rect->h=canvas->h;
fretwork_full_runs += 1;
update_rect->x = 0;
update_rect->y = 0;
update_rect->w = canvas->w;
update_rect->h = canvas->h;
}
}
}
@ -355,7 +365,7 @@ static Uint8 fretwork_select_image(Uint16 segment)
int TOP = 0, BOTTOM = 0, LEFT = 0, RIGHT = 0;
//Checking from were we come...
if (fretwork_segment_modified_last>0)
if (fretwork_segment_modified_last > 0)
{
if (segment == fretwork_segment_modified_last + 1)
from_left = 1;
@ -386,33 +396,42 @@ static Uint8 fretwork_select_image(Uint16 segment)
else if (segment == fretwork_segment_modified_last - fretwork_segments_x + 1)
{
from_bottom_left = 1;
fretwork_segment_to_add = segment -1;
fretwork_segment_to_add = segment - 1;
}
}
take_up=segment-fretwork_segments_x;
if (take_up<=0) val_up = SEG_NONE;
else val_up = fretwork_status_of_segments[take_up];
take_up = segment - fretwork_segments_x;
if (take_up <= 0)
val_up = SEG_NONE;
else
val_up = fretwork_status_of_segments[take_up];
take_down=segment+fretwork_segments_x;
if (take_down>(signed)(fretwork_segments_x*fretwork_segments_y)) val_down = SEG_NONE;
else val_down = fretwork_status_of_segments[take_down];
take_down = segment + fretwork_segments_x;
if (take_down > (signed)(fretwork_segments_x * fretwork_segments_y))
val_down = SEG_NONE;
else
val_down = fretwork_status_of_segments[take_down];
if ((segment%fretwork_segments_x)==1) val_left=SEG_NONE;
else val_left = fretwork_status_of_segments[segment-1];
if ((segment % fretwork_segments_x) == 1)
val_left = SEG_NONE;
else
val_left = fretwork_status_of_segments[segment - 1];
if ((segment%fretwork_segments_x)==0) val_right=SEG_NONE;
else val_right = fretwork_status_of_segments[segment+1];
if ((segment % fretwork_segments_x) == 0)
val_right = SEG_NONE;
else
val_right = fretwork_status_of_segments[segment + 1];
if ( from_left || (val_left & SEG_RIGHT) || from_bottom_left)
if (from_left || (val_left & SEG_RIGHT) || from_bottom_left)
{
LEFT = 1;}
if ( from_right || (val_right & SEG_LEFT) || from_top_right)
RIGHT=1;
if ( from_top || (val_up & SEG_BOTTOM) || from_top_left)
TOP=1;
LEFT = 1;
}
if (from_right || (val_right & SEG_LEFT) || from_top_right)
RIGHT = 1;
if (from_top || (val_up & SEG_BOTTOM) || from_top_left)
TOP = 1;
if (from_bottom || (val_down & SEG_TOP) || from_bottom_right)
BOTTOM=1;
BOTTOM = 1;
if (TOP && BOTTOM && LEFT && RIGHT)
@ -425,56 +444,58 @@ static Uint8 fretwork_select_image(Uint16 segment)
return SEG_LEFT_TOP_BOTTOM;
if (TOP && BOTTOM && RIGHT)
return SEG_RIGHT_TOP_BOTTOM;
if (LEFT &&RIGHT)
if (LEFT && RIGHT)
return SEG_LEFT_RIGHT;
if (TOP&&BOTTOM)
if (TOP && BOTTOM)
return SEG_TOP_BOTTOM;
if (LEFT&&TOP)
if (LEFT && TOP)
return SEG_LEFT_TOP;
if (LEFT&&BOTTOM)
if (LEFT && BOTTOM)
return SEG_LEFT_BOTTOM;
if (RIGHT&&TOP)
if (RIGHT && TOP)
return SEG_RIGHT_TOP;
if (RIGHT&&BOTTOM)
if (RIGHT && BOTTOM)
return SEG_RIGHT_BOTTOM;
if (LEFT|RIGHT)
if (LEFT | RIGHT)
return SEG_LEFT_RIGHT;
//if (TOP||BOTTOM)
return SEG_TOP_BOTTOM;
}
static void fretwork_draw(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
int x, int y ATTRIBUTE_UNUSED, unsigned int segment)
static void fretwork_draw(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y ATTRIBUTE_UNUSED, unsigned int segment)
{
magic_api * api = (magic_api *) ptr;
SDL_Surface * result, * temp;
magic_api *api = (magic_api *) ptr;
SDL_Surface *result, *temp;
Uint8 image;
_Bool use_temp;
use_temp=0;
if ((segment<1)|(segment>fretwork_segments_x*fretwork_segments_y))
use_temp = 0;
if ((segment < 1) | (segment > fretwork_segments_x * fretwork_segments_y))
return;
fretwork_extract_coords_from_segment(segment, &modification_rect.x, &modification_rect.y);
modification_rect.h=img_w;
modification_rect.w=img_h;
modification_rect.h = img_w;
modification_rect.w = img_h;
image=fretwork_select_image(segment); //select the image to display
image = fretwork_select_image(segment); //select the image to display
if (fretwork_status_of_segments[segment] == image)
return;
fretwork_status_of_segments[segment]=image; //and write it to global table
fretwork_status_of_segments[segment] = image; //and write it to global table
result=SDL_CreateRGBSurface(SDL_SWSURFACE, img_w, img_h, fretwork_one->format->BitsPerPixel,
fretwork_one->format->Rmask, fretwork_one->format->Gmask, fretwork_one->format->Bmask, fretwork_one->format->Amask);
result = SDL_CreateRGBSurface(SDL_SWSURFACE, img_w, img_h, fretwork_one->format->BitsPerPixel,
fretwork_one->format->Rmask, fretwork_one->format->Gmask, fretwork_one->format->Bmask,
fretwork_one->format->Amask);
temp=SDL_CreateRGBSurface(SDL_SWSURFACE, img_w, img_h, fretwork_one->format->BitsPerPixel,
fretwork_one->format->Rmask, fretwork_one->format->Gmask, fretwork_one->format->Bmask, fretwork_one->format->Amask);
temp = SDL_CreateRGBSurface(SDL_SWSURFACE, img_w, img_h, fretwork_one->format->BitsPerPixel,
fretwork_one->format->Rmask, fretwork_one->format->Gmask, fretwork_one->format->Bmask,
fretwork_one->format->Amask);
SDL_BlitSurface(canvas_backup, &modification_rect, result, NULL);
switch(image)
switch (image)
{
case 0:
case SEG_TOP_BOTTOM:
@ -485,7 +506,7 @@ static void fretwork_draw(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface *
case SEG_LEFT_RIGHT:
SDL_BlitSurface(canvas_backup, &modification_rect, result, NULL);
fretwork_rotate(api, temp, fretwork_one, 1);
use_temp=1;
use_temp = 1;
break;
case SEG_LEFT_RIGHT_TOP_BOTTOM:
@ -499,17 +520,17 @@ static void fretwork_draw(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface *
case SEG_LEFT_RIGHT_BOTTOM:
fretwork_flip_flop(api, temp, fretwork_three);
use_temp=1;
use_temp = 1;
break;
case SEG_LEFT_TOP_BOTTOM:
fretwork_rotate(api, temp, fretwork_three, 0);
use_temp=1;
use_temp = 1;
break;
case SEG_RIGHT_TOP_BOTTOM:
fretwork_rotate(api, temp, fretwork_three, 1);
use_temp=1;
use_temp = 1;
break;
case SEG_RIGHT_TOP:
@ -517,18 +538,18 @@ static void fretwork_draw(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface *
break;
case SEG_RIGHT_BOTTOM:
fretwork_rotate(api, temp, fretwork_corner,1);
use_temp=1;
fretwork_rotate(api, temp, fretwork_corner, 1);
use_temp = 1;
break;
case SEG_LEFT_TOP:
fretwork_rotate(api, temp, fretwork_corner, 0);
use_temp=1;
use_temp = 1;
break;
case SEG_LEFT_BOTTOM:
fretwork_flip_flop(api, temp, fretwork_corner);
use_temp=1;
use_temp = 1;
break;
}
@ -542,53 +563,58 @@ static void fretwork_draw(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface *
}
static void fretwork_draw_wrapper(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
int x, int y)
static void fretwork_draw_wrapper(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
fretwork_segment_modified=fretwork_get_segment(x,y);
fretwork_segment_modified = fretwork_get_segment(x, y);
fretwork_draw((void *) ptr, which, canvas, last, x, y, fretwork_segment_modified);
fretwork_draw((void *)ptr, which, canvas, last, x, y, fretwork_segment_modified);
if (fretwork_segment_modified_last>0)
if (fretwork_segment_modified_last > 0)
{
fretwork_draw((void *) ptr, which, canvas, last, x, y, fretwork_segment_modified_last);
fretwork_extract_coords_from_segment(fretwork_segment_start_rectangle, &modification_rect.x, &modification_rect.y);
modification_rect.w=fretwork_update_rectangle_width*img_w;
modification_rect.h=fretwork_update_rectangle_height*img_h;
fretwork_draw((void *)ptr, which, canvas, last, x, y, fretwork_segment_modified_last);
fretwork_extract_coords_from_segment(fretwork_segment_start_rectangle, &modification_rect.x,
&modification_rect.y);
modification_rect.w = fretwork_update_rectangle_width * img_w;
modification_rect.h = fretwork_update_rectangle_height * img_h;
}
if (fretwork_segment_to_add>0){
fretwork_draw((void *) ptr, which, canvas, last, x, y, fretwork_segment_to_add);
fretwork_draw((void *) ptr, which, canvas, last, x, y, fretwork_segment_modified_last);
fretwork_segment_to_add=0;}
if (fretwork_segment_to_add > 0)
{
fretwork_draw((void *)ptr, which, canvas, last, x, y, fretwork_segment_to_add);
fretwork_draw((void *)ptr, which, canvas, last, x, y, fretwork_segment_modified_last);
fretwork_segment_to_add = 0;
}
fretwork_segment_modified_last=fretwork_segment_modified;
fretwork_segment_modified_last = fretwork_segment_modified;
}
void fretwork_drag(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
{ int start_x, end_x, start_y, end_y, segment_start, segment_end, w, h;
if ((x<canvas->w)&&(y<canvas->h)&&(ox<canvas->w)&&(oy<canvas->h)&&((signed)x>0)&&((signed)y>0)&&((signed)ox>0)&&((signed)oy>0))
SDL_Surface * canvas, SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
int start_x, end_x, start_y, end_y, segment_start, segment_end, w, h;
if ((x < canvas->w) && (y < canvas->h) && (ox < canvas->w) && (oy < canvas->h) && ((signed)x > 0) && ((signed)y > 0)
&& ((signed)ox > 0) && ((signed)oy > 0))
{
api->line((void *) api, which, canvas, snapshot, ox, oy, x, y, img_w/2, fretwork_draw_wrapper);
api->line((void *)api, which, canvas, snapshot, ox, oy, x, y, img_w / 2, fretwork_draw_wrapper);
// This should be improved, maybe passed to fretwork_draw()
start_x=min(ox,x);
end_x=max(ox,x);
start_y=min(oy,y);
end_y=max(oy,y);
segment_start=fretwork_get_segment(start_x-img_w, start_y-img_h);
segment_end=fretwork_get_segment(end_x+img_w,end_y+img_h);
start_x = min(ox, x);
end_x = max(ox, x);
start_y = min(oy, y);
end_y = max(oy, y);
segment_start = fretwork_get_segment(start_x - img_w, start_y - img_h);
segment_end = fretwork_get_segment(end_x + img_w, end_y + img_h);
x=((segment_start%fretwork_segments_x)-1)*img_w;
y=(int)(segment_start/fretwork_segments_x)*img_h;
w=((segment_end%fretwork_segments_x)-1)*img_w-x+img_w;
h=(int)(segment_end/fretwork_segments_x)*img_h-y+img_h;
x = ((segment_start % fretwork_segments_x) - 1) * img_w;
y = (int)(segment_start / fretwork_segments_x) * img_h;
w = ((segment_end % fretwork_segments_x) - 1) * img_w - x + img_w;
h = (int)(segment_end / fretwork_segments_x) * img_h - y + img_h;
update_rect->x=x;
update_rect->y=y;
update_rect->w=w;
update_rect->h=h;}
update_rect->x = x;
update_rect->y = y;
update_rect->w = w;
update_rect->h = h;
}
}

View file

@ -36,26 +36,22 @@
/* Our globals: */
static Mix_Chunk * glasstile_snd;
static Mix_Chunk *glasstile_snd;
// Prototypes
Uint32 glasstile_api_version(void);
int glasstile_init(magic_api * api);
int glasstile_get_tool_count(magic_api * api);
SDL_Surface * glasstile_get_icon(magic_api * api, int which);
char * glasstile_get_name(magic_api * api, int which);
char * glasstile_get_description(magic_api * api, int which, int mode);
static void do_glasstile(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
int x, int y);
SDL_Surface *glasstile_get_icon(magic_api * api, int which);
char *glasstile_get_name(magic_api * api, int which);
char *glasstile_get_description(magic_api * api, int which, int mode);
static void do_glasstile(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
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);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void glasstile_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void glasstile_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void glasstile_shutdown(magic_api * api);
void glasstile_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int glasstile_requires_colors(magic_api * api, int which);
@ -63,9 +59,12 @@ void glasstile_switchin(magic_api * api, int which, int mode, SDL_Surface * canv
void glasstile_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int glasstile_modes(magic_api * api, int which);
Uint32 glasstile_api_version(void) { return(TP_MAGIC_API_VERSION); }
Uint32 glasstile_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
static int * * glasstile_hit;
static int **glasstile_hit;
static int glasstile_hit_xsize;
static int glasstile_hit_ysize;
@ -74,60 +73,53 @@ int glasstile_init(magic_api * api)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/sounds/magic/glasstile.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/sounds/magic/glasstile.ogg", api->data_directory);
glasstile_snd = Mix_LoadWAV(fname);
glasstile_hit = NULL;
glasstile_hit_ysize = 0;
return(1);
return (1);
}
// We have multiple tools:
int glasstile_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return(1);
return (1);
}
// Load our icons:
SDL_Surface * glasstile_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
SDL_Surface *glasstile_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/images/magic/glasstile.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/glasstile.png", api->data_directory);
return(IMG_Load(fname));
return (IMG_Load(fname));
}
// Return our names, localized:
char * glasstile_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
char *glasstile_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(strdup(gettext_noop("Glass Tile")));
return (strdup(gettext_noop("Glass Tile")));
}
// Return our descriptions, localized:
char * glasstile_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode)
char *glasstile_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode)
{
if (mode == MODE_PAINT)
return(strdup(gettext_noop("Click and drag the mouse to put glass tile over your picture.")));
return (strdup(gettext_noop("Click and drag the mouse to put glass tile over your picture.")));
else
return(strdup(gettext_noop("Click to cover your entire picture in glass tiles.")));
return (strdup(gettext_noop("Click to cover your entire picture in glass tiles.")));
}
// Do the effect:
static void do_glasstile(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last,
int x, int y)
static void do_glasstile(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
int xx, yy, xl, xr, yt, yb;
Uint8 r1, g1, b1,
r2, g2, b2,
r3, g3, b3,
r4, g4, b4,
r, g, b;
Uint8 r1, g1, b1, r2, g2, b2, r3, g3, b3, r4, g4, b4, r, g, b;
Uint32 rgb;
@ -157,14 +149,10 @@ static void do_glasstile(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * c
{
for (xx = -GT_SIZE; xx < GT_SIZE; xx = xx + 2)
{
SDL_GetRGB(api->getpixel(last, x + xx, y + yy), last->format,
&r1, &g1, &b1);
SDL_GetRGB(api->getpixel(last, x + xx + 1, y + yy), last->format,
&r2, &g2, &b2);
SDL_GetRGB(api->getpixel(last, x + xx, y + yy + 1), last->format,
&r3, &g3, &b3);
SDL_GetRGB(api->getpixel(last, x + xx + 1, y + yy + 1), last->format,
&r4, &g4, &b4);
SDL_GetRGB(api->getpixel(last, x + xx, y + yy), last->format, &r1, &g1, &b1);
SDL_GetRGB(api->getpixel(last, x + xx + 1, y + yy), last->format, &r2, &g2, &b2);
SDL_GetRGB(api->getpixel(last, x + xx, y + yy + 1), last->format, &r3, &g3, &b3);
SDL_GetRGB(api->getpixel(last, x + xx + 1, y + yy + 1), last->format, &r4, &g4, &b4);
r = (r1 + r2 + r3 + r4) >> 2;
g = (g1 + g2 + g3 + g4) >> 2;
@ -176,7 +164,7 @@ static void do_glasstile(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * c
g = min(255, g + 64);
b = min(255, b + 64);
}
else if (xx >= GT_SIZE - 3|| yy >= GT_SIZE - 3)
else if (xx >= GT_SIZE - 3 || yy >= GT_SIZE - 3)
{
r = max(0, r - 64);
g = max(0, g - 64);
@ -210,10 +198,9 @@ static void do_glasstile(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * c
// Affect the canvas on drag:
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)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *) api, 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;
@ -246,8 +233,7 @@ void glasstile_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void glasstile_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
int xx, yy;
@ -256,10 +242,10 @@ void glasstile_click(magic_api * api, int which, int mode,
glasstile_hit_ysize = (canvas->h / GT_SIZE) + 1;
glasstile_hit_xsize = (canvas->w / GT_SIZE) + 1;
glasstile_hit = (int * *) malloc(sizeof(int *) * glasstile_hit_ysize);
glasstile_hit = (int * *)malloc(sizeof(int *) * glasstile_hit_ysize);
for (yy = 0; yy < glasstile_hit_ysize; yy++)
glasstile_hit[yy] = (int *) malloc(sizeof(int) * glasstile_hit_xsize);
glasstile_hit[yy] = (int *)malloc(sizeof(int) * glasstile_hit_xsize);
}
for (yy = 0; yy < glasstile_hit_ysize; yy++)
@ -310,7 +296,8 @@ void glasstile_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void glasstile_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
void glasstile_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED)
{
}
@ -320,15 +307,17 @@ int glasstile_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIB
return 0;
}
void glasstile_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void glasstile_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void glasstile_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void glasstile_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int glasstile_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_PAINT | MODE_FULLSCREEN);
return (MODE_PAINT | MODE_FULLSCREEN);
}

View file

@ -37,32 +37,27 @@
/* Our globals: */
static Mix_Chunk * grass_snd;
static Mix_Chunk *grass_snd;
static Uint8 grass_r, grass_g, grass_b;
static SDL_Surface * img_grass;
static SDL_Surface *img_grass;
// Prototypes
int grass_init(magic_api * api);
Uint32 grass_api_version(void);
int grass_get_tool_count(magic_api * api);
SDL_Surface * grass_get_icon(magic_api * api, int which);
char * grass_get_name(magic_api * api, int which);
char * grass_get_description(magic_api * api, int which, int mode);
SDL_Surface *grass_get_icon(magic_api * api, int which);
char *grass_get_name(magic_api * api, int which);
char *grass_get_description(magic_api * api, int which, int mode);
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);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void grass_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void grass_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void grass_shutdown(magic_api * api);
void grass_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int grass_requires_colors(magic_api * api, int which);
static void do_grass(void * ptr, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y);
static void do_grass(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
static int log2int(int x);
void grass_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void grass_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
@ -74,74 +69,83 @@ int grass_init(magic_api * api)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/sounds/magic/grass.wav",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/sounds/magic/grass.wav", api->data_directory);
grass_snd = Mix_LoadWAV(fname);
snprintf(fname, sizeof(fname), "%s/images/magic/grass_data.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/grass_data.png", api->data_directory);
img_grass = IMG_Load(fname);
return(1);
return (1);
}
Uint32 grass_api_version(void) { return(TP_MAGIC_API_VERSION); }
Uint32 grass_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
// We have multiple tools:
int grass_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return(1);
return (1);
}
// Load our icons:
SDL_Surface * grass_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
SDL_Surface *grass_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/images/magic/grass.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/grass.png", api->data_directory);
return(IMG_Load(fname));
return (IMG_Load(fname));
}
// Return our names, localized:
char * grass_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
char *grass_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(strdup(gettext_noop("Grass")));
return (strdup(gettext_noop("Grass")));
}
// Return our descriptions, localized:
char * grass_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
char *grass_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return(strdup(gettext_noop("Click and drag to draw grass. Dont forget the dirt!")));
return (strdup(gettext_noop("Click and drag to draw grass. Dont forget the dirt!")));
}
// Affect the canvas on drag:
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)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *) api, 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; }
if (ox > x)
{
int tmp = ox;
ox = x;
x = tmp;
}
if (oy > y)
{
int tmp = oy;
oy = y;
y = tmp;
}
update_rect->x = ox - 64;
update_rect->y = oy - 64;
update_rect->w = 128;
update_rect->h = 192;
api->playsound(grass_snd,
(x * 255) / canvas->w, (y * 255) / canvas->h);
api->playsound(grass_snd, (x * 255) / canvas->w, (y * 255) / canvas->h);
}
// Affect the canvas on click:
void grass_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
grass_drag(api, which, canvas, last, x, y, x, y, update_rect);
}
@ -173,12 +177,12 @@ int grass_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_
return 1;
}
static void do_grass(void * ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
int x, int y)
static void do_grass(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
{
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
int xx, yy;
// grass color: 82,180,17
static int bucket;
double tmp_red, tmp_green, tmp_blue;
@ -187,13 +191,12 @@ static void do_grass(void * ptr, int which ATTRIBUTE_UNUSED,
if (!api->button_down())
bucket = 0;
bucket += (3.5 + (rand() / (double) RAND_MAX)) * 7.0;
bucket += (3.5 + (rand() / (double)RAND_MAX)) * 7.0;
while (bucket >= 0)
{
int rank =
log2int(((double) y / canvas->h) *
(0.99 + (rand() / (double) RAND_MAX)) * 64);
int rank = log2int(((double)y / canvas->h) * (0.99 + (rand() / (double)RAND_MAX)) * 64);
int ah = 1 << rank;
bucket -= ah;
src.x = (rand() % 4) * 64;
src.y = ah;
@ -201,17 +204,11 @@ static void do_grass(void * ptr, int which ATTRIBUTE_UNUSED,
src.h = ah;
dest.x = x - 32;
dest.y = y - 30 + (int) ((rand() / (double) RAND_MAX) * 30);
dest.y = y - 30 + (int)((rand() / (double)RAND_MAX) * 30);
tmp_red =
api->sRGB_to_linear(grass_r) * 2.0 +
(rand() / (double) RAND_MAX);
tmp_green =
api->sRGB_to_linear(grass_g) * 2.0 +
(rand() / (double) RAND_MAX);
tmp_blue =
api->sRGB_to_linear(grass_b) * 2.0 +
api->sRGB_to_linear(17);
tmp_red = api->sRGB_to_linear(grass_r) * 2.0 + (rand() / (double)RAND_MAX);
tmp_green = api->sRGB_to_linear(grass_g) * 2.0 + (rand() / (double)RAND_MAX);
tmp_blue = api->sRGB_to_linear(grass_b) * 2.0 + api->sRGB_to_linear(17);
for (yy = 0; yy < ah; yy++)
{
@ -219,8 +216,7 @@ static void do_grass(void * ptr, int which ATTRIBUTE_UNUSED,
{
double rd, gd, bd;
SDL_GetRGBA(api->getpixel(img_grass, xx + src.x, yy + src.y),
img_grass->format, &r, &g, &b, &a);
SDL_GetRGBA(api->getpixel(img_grass, xx + src.x, yy + src.y), img_grass->format, &r, &g, &b, &a);
rd = api->sRGB_to_linear(r) * 8.0 + tmp_red;
rd = rd * (a / 255.0) / 11.0;
@ -229,21 +225,13 @@ static void do_grass(void * ptr, int which ATTRIBUTE_UNUSED,
bd = api->sRGB_to_linear(b) * 8.0 + tmp_blue;
bd = bd * (a / 255.0) / 11.0;
SDL_GetRGB(api->getpixel(canvas, xx + dest.x, yy + dest.y),
canvas->format, &r, &g, &b);
SDL_GetRGB(api->getpixel(canvas, xx + dest.x, yy + dest.y), canvas->format, &r, &g, &b);
r =
api->linear_to_sRGB(api->sRGB_to_linear(r) * (1.0 - a / 255.0) +
rd);
g =
api->linear_to_sRGB(api->sRGB_to_linear(g) * (1.0 - a / 255.0) +
gd);
b =
api->linear_to_sRGB(api->sRGB_to_linear(b) * (1.0 - a / 255.0) +
bd);
r = api->linear_to_sRGB(api->sRGB_to_linear(r) * (1.0 - a / 255.0) + rd);
g = api->linear_to_sRGB(api->sRGB_to_linear(g) * (1.0 - a / 255.0) + gd);
b = api->linear_to_sRGB(api->sRGB_to_linear(b) * (1.0 - a / 255.0) + bd);
api->putpixel(canvas, xx + dest.x, yy + dest.y,
SDL_MapRGB(canvas->format, r, g, b));
api->putpixel(canvas, xx + dest.x, yy + dest.y, SDL_MapRGB(canvas->format, r, g, b));
}
}
}
@ -253,6 +241,7 @@ static void do_grass(void * ptr, int which ATTRIBUTE_UNUSED,
static int log2int(int x)
{
int y = 0;
if (x <= 1)
return 0;
x >>= 1;
@ -264,15 +253,17 @@ static int log2int(int x)
return y;
}
void grass_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void grass_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void grass_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void grass_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int grass_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_PAINT);
return (MODE_PAINT);
}

View file

@ -16,55 +16,51 @@
#include "SDL_image.h"
#include "SDL_mixer.h"
enum {
enum
{
TOOL_HALFTONE,
NUM_TOOLS
};
const char * snd_filenames[NUM_TOOLS] = {
const char *snd_filenames[NUM_TOOLS] = {
"halftone.wav",
};
const char * icon_filenames[NUM_TOOLS] = {
const char *icon_filenames[NUM_TOOLS] = {
"halftone.png",
};
const char * names[NUM_TOOLS] = {
const char *names[NUM_TOOLS] = {
gettext_noop("Halftone"),
};
const char * descs[NUM_TOOLS] = {
const char *descs[NUM_TOOLS] = {
gettext_noop("Click and drag to turn your drawing into a newspaper."),
};
Mix_Chunk * snd_effect[NUM_TOOLS];
Mix_Chunk *snd_effect[NUM_TOOLS];
static SDL_Surface * canvas_backup, * square;
static SDL_Surface *canvas_backup, *square;
/* Function Prototypes: */
void halftone_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
void halftone_line_callback(void * ptr, int which,
SDL_Surface * canvas, SDL_Surface * snapshot,
int x, int y);
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void halftone_line_callback(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
Uint32 halftone_api_version(void);
int halftone_init(magic_api * api);
int halftone_get_tool_count(magic_api * api);
SDL_Surface * halftone_get_icon(magic_api * api, int which);
char * halftone_get_name(magic_api * api, int which);
char * halftone_get_description(magic_api * api, int which, int mode);
SDL_Surface *halftone_get_icon(magic_api * api, int which);
char *halftone_get_name(magic_api * api, int which);
char *halftone_get_description(magic_api * api, int which, int mode);
int halftone_requires_colors(magic_api * api, int which);
int halftone_modes(magic_api * api, int which);
void halftone_shutdown(magic_api * api);
void halftone_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);
void halftone_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);
void halftone_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
void halftone_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void halftone_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
@ -72,7 +68,7 @@ void halftone_rgb2cmyk(Uint8 r, Uint8 g, Uint8 b, float cmyk[]);
Uint32 halftone_api_version(void)
{
return(TP_MAGIC_API_VERSION);
return (TP_MAGIC_API_VERSION);
}
int halftone_init(magic_api * api)
@ -85,57 +81,55 @@ int halftone_init(magic_api * api)
for (i = 0; i < NUM_TOOLS; i++)
{
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]);
snd_effect[i] = Mix_LoadWAV(fname);
if (snd_effect[i] == NULL) {
if (snd_effect[i] == NULL)
{
SDL_FreeSurface(canvas_backup);
SDL_FreeSurface(square);
return(0);
return (0);
}
}
return(1);
return (1);
}
int halftone_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return(NUM_TOOLS);
return (NUM_TOOLS);
}
SDL_Surface * halftone_get_icon(magic_api * api, int which)
SDL_Surface *halftone_get_icon(magic_api * api, int which)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/images/magic/%s",
api->data_directory, icon_filenames[which]);
snprintf(fname, sizeof(fname), "%s/images/magic/%s", api->data_directory, icon_filenames[which]);
return(IMG_Load(fname));
return (IMG_Load(fname));
}
char * halftone_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
char *halftone_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
{
const char * our_name_english;
const char * our_name_localized;
const char *our_name_english;
const char *our_name_localized;
our_name_english = names[which];
our_name_localized = gettext_noop(our_name_english);
return(strdup(our_name_localized));
return (strdup(our_name_localized));
}
char * halftone_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
char *halftone_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
{
const char * our_desc_english;
const char * our_desc_localized;
const char *our_desc_english;
const char *our_desc_localized;
our_desc_english = descs[which];
our_desc_localized = gettext_noop(our_desc_english);
return(strdup(our_desc_localized));
return (strdup(our_desc_localized));
}
int halftone_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
@ -160,33 +154,42 @@ void halftone_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
void halftone_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
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)
{
halftone_drag(api, which, canvas, snapshot, x, y, x, y, update_rect);
}
void halftone_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)
{
api->line((void *) api, which, canvas, snapshot,
ox, oy, x, y, 4, halftone_line_callback);
api->line((void *)api, which, canvas, snapshot, ox, oy, x, y, 4, halftone_line_callback);
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;
}
update_rect->x = ox - 16;
update_rect->y = oy - 16;
update_rect->w = (x + 16) - update_rect->x;
update_rect->h = (y + 16) - update_rect->h;
api->playsound(snd_effect[which],
(x * 255) / canvas->w, // pan
api->playsound(snd_effect[which], (x * 255) / canvas->w, // pan
255); // distance
}
enum {
enum
{
CHAN_CYAN,
CHAN_MAGENTA,
CHAN_YELLOW,
@ -195,10 +198,10 @@ enum {
};
Uint8 chan_colors[NUM_CHANS][3] = {
{ 0, 255, 255 },
{ 255, 0, 255 },
{ 255, 255, 0 },
{ 0, 0, 0 }
{0, 255, 255},
{255, 0, 255},
{255, 255, 0},
{0, 0, 0}
};
int chan_angles[NUM_CHANS] = {
@ -210,9 +213,7 @@ int chan_angles[NUM_CHANS] = {
void halftone_release(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * snapshot ATTRIBUTE_UNUSED,
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
@ -221,16 +222,15 @@ void halftone_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUS
{
}
void halftone_line_callback(void * ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED,
int x, int y)
void halftone_line_callback(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
{
Uint8 r, g, b, or, og, ob;
Uint32 total_r, total_g, total_b;
Uint32 pixel;
int xx, yy, xxx, yyy, channel, ox, oy, sqx, sqy;
SDL_Rect dest;
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
float cmyk[4];
pixel = SDL_MapRGB(square->format, 255, 255, 255);
@ -240,15 +240,23 @@ void halftone_line_callback(void * ptr, int which ATTRIBUTE_UNUSED,
x = ((x / 8) - 1) * 8;
y = ((y / 8) - 1) * 8;
if (api->touched(x, y)) { return; }
if (api->touched(x, y))
{
return;
}
for (xx = 0; xx < 16; xx = xx + 4) {
for (yy = 0; yy < 16; yy = yy + 4) {
for (xx = 0; xx < 16; xx = xx + 4)
{
for (yy = 0; yy < 16; yy = yy + 4)
{
/* Get avg color around the mouse */
total_r = total_g = total_b = 0;
for (xxx = 0; xxx < 4; xxx++) {
for (yyy = 0; yyy < 4; yyy++) {
SDL_GetRGB(api->getpixel(canvas_backup, x + xx + xxx, y + yy + yyy), canvas_backup->format, &r, &g, &b);
for (xxx = 0; xxx < 4; xxx++)
{
for (yyy = 0; yyy < 4; yyy++)
{
SDL_GetRGB(api->getpixel(canvas_backup, x + xx + xxx, y + yy + yyy), canvas_backup->format, &r, &g,
&b);
total_r += r;
total_g += g;
total_b += b;
@ -262,13 +270,16 @@ void halftone_line_callback(void * ptr, int which ATTRIBUTE_UNUSED,
halftone_rgb2cmyk(total_r, total_g, total_b, cmyk);
/* Draw C, M, Y and K blobs into our 'square' surface */
for (channel = 0; channel < NUM_CHANS; channel++) {
for (channel = 0; channel < NUM_CHANS; channel++)
{
r = chan_colors[channel][0];
g = chan_colors[channel][1];
b = chan_colors[channel][2];
for (xxx = 0; xxx < 8; xxx++) {
for (yyy = 0; yyy < 8; yyy++) {
for (xxx = 0; xxx < 8; xxx++)
{
for (yyy = 0; yyy < 8; yyy++)
{
/* A circle blob, radius based upon channel (C, M, Y or K) strength for this color */
/* FIXME: Base it upon this channel's angle! -bjk 2011.07.17 */
@ -278,13 +289,17 @@ void halftone_line_callback(void * ptr, int which ATTRIBUTE_UNUSED,
sqx = (xx + ox) % 16;
sqy = (yy + oy) % 16;
if (api->in_circle(xxx - 4, yyy - 4, cmyk[channel] * 6.0)) {
if (api->in_circle(xxx - 4, yyy - 4, cmyk[channel] * 6.0))
{
SDL_GetRGB(api->getpixel(square, sqx, sqy), square->format, &or, &og, &ob);
if (or == 255 && og == 255 && ob == 255) {
if (or == 255 && og == 255 && ob == 255)
{
/* If it's just white, put full color down */
pixel = SDL_MapRGB(square->format, r, g, b);
} else {
}
else
{
/* Otherwise, blend a little */
pixel = SDL_MapRGB(square->format, (r + or) / 2, (g + og) / 2, (b + ob) / 2);
}
@ -303,14 +318,17 @@ void halftone_line_callback(void * ptr, int which ATTRIBUTE_UNUSED,
SDL_BlitSurface(square, NULL, canvas, &dest);
}
void halftone_switchin(magic_api * api, int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas)
void halftone_switchin(magic_api * api, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas)
{
if (canvas_backup == NULL)
canvas_backup = SDL_CreateRGBSurface(SDL_SWSURFACE, api->canvas_w, api->canvas_h, canvas->format->BitsPerPixel, canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
canvas_backup =
SDL_CreateRGBSurface(SDL_SWSURFACE, api->canvas_w, api->canvas_h, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
if (square == NULL)
square = SDL_CreateRGBSurface(SDL_SWSURFACE, 16, 16, canvas->format->BitsPerPixel, canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
square =
SDL_CreateRGBSurface(SDL_SWSURFACE, 16, 16, canvas->format->BitsPerPixel, canvas->format->Rmask,
canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
/* FIXME: What to do if they come back NULL!? :( */
@ -340,9 +358,9 @@ void halftone_rgb2cmyk(Uint8 r, Uint8 g, Uint8 b, float cmyk[])
}
else
{
c = 1.0 - (((float) r) / 255.0);
m = 1.0 - (((float) g) / 255.0);
y = 1.0 - (((float) b) / 255.0);
c = 1.0 - (((float)r) / 255.0);
m = 1.0 - (((float)g) / 255.0);
y = 1.0 - (((float)b) / 255.0);
mincmy = min(c, min(m, y));
c = (c - mincmy) / (1.0 - mincmy);

View file

@ -35,12 +35,13 @@
/* Our globals: */
static Mix_Chunk * kalidescope_snd;
static Mix_Chunk *kalidescope_snd;
static Uint8 kalidescope_r, kalidescope_g, kalidescope_b;
static int square_size = 128;
enum {
enum
{
KAL_UD,
KAL_LR,
KAL_BOTH,
@ -49,7 +50,7 @@ enum {
KAL_COUNT
};
char * kal_icon_names[KAL_COUNT] = {
char *kal_icon_names[KAL_COUNT] = {
"symmetric_updown.png",
"symmetric_leftright.png",
"kalidescope.png",
@ -62,20 +63,16 @@ char * kal_icon_names[KAL_COUNT] = {
Uint32 kalidescope_api_version(void);
int kalidescope_init(magic_api * api);
int kalidescope_get_tool_count(magic_api * api);
SDL_Surface * kalidescope_get_icon(magic_api * api, int which);
char * kalidescope_get_name(magic_api * api, int which);
char * kalidescope_get_description(magic_api * api, int which, int mode);
static void do_kalidescope(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
int x, int y);
SDL_Surface *kalidescope_get_icon(magic_api * api, int which);
char *kalidescope_get_name(magic_api * api, int which);
char *kalidescope_get_description(magic_api * api, int which, int mode);
static void do_kalidescope(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
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);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void kalidescope_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void kalidescope_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void kalidescope_shutdown(magic_api * api);
int kalidescope_requires_colors(magic_api * api, int which);
void kalidescope_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
@ -83,82 +80,102 @@ void kalidescope_switchin(magic_api * api, int which, int mode, SDL_Surface * ca
void kalidescope_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int kalidescope_modes(magic_api * api, int which);
Uint32 kalidescope_api_version(void) { return(TP_MAGIC_API_VERSION); }
Uint32 kalidescope_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
// No setup required:
int kalidescope_init(magic_api * api)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/sounds/magic/kaleidoscope.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/sounds/magic/kaleidoscope.ogg", api->data_directory);
kalidescope_snd = Mix_LoadWAV(fname);
return(1);
return (1);
}
int kalidescope_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return(KAL_COUNT);
return (KAL_COUNT);
}
// Load our icons:
SDL_Surface * kalidescope_get_icon(magic_api * api, int which)
SDL_Surface *kalidescope_get_icon(magic_api * api, int which)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/images/magic/%s",
api->data_directory, kal_icon_names[which]);
snprintf(fname, sizeof(fname), "%s/images/magic/%s", api->data_directory, kal_icon_names[which]);
return(IMG_Load(fname));
return (IMG_Load(fname));
}
// Return our names, localized:
char * kalidescope_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
char *kalidescope_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
{
if (which == KAL_LR) {
return(strdup(gettext_noop("Symmetric Left/Right")));
} else if (which == KAL_UD) {
return(strdup(gettext_noop("Symmetric Up/Down")));
} else if (which == KAL_PATTERN) {
return(strdup(gettext_noop("Pattern")));
} else if (which == KAL_TILES) {
return(strdup(gettext_noop("Tiles")));
} else { /* KAL_BOTH */
return(strdup(gettext_noop("Kaleidoscope")));
if (which == KAL_LR)
{
return (strdup(gettext_noop("Symmetric Left/Right")));
}
else if (which == KAL_UD)
{
return (strdup(gettext_noop("Symmetric Up/Down")));
}
else if (which == KAL_PATTERN)
{
return (strdup(gettext_noop("Pattern")));
}
else if (which == KAL_TILES)
{
return (strdup(gettext_noop("Tiles")));
}
else
{ /* KAL_BOTH */
return (strdup(gettext_noop("Kaleidoscope")));
}
}
// Return our descriptions, localized:
char * kalidescope_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
char *kalidescope_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
{
if (which == KAL_LR) {
return(strdup(gettext_noop("Click and drag the mouse to draw with two brushes that are symmetric across the left and right of your picture.")));
} else if (which == KAL_UD) {
return(strdup(gettext_noop("Click and drag the mouse to draw with two brushes that are symmetric across the top and bottom of your picture.")));
} else if (which == KAL_PATTERN) {
return(strdup(gettext_noop("Click and drag the mouse to draw a pattern across the picture.")));
} else if (which == KAL_TILES) {
return(strdup(gettext_noop("Click and drag the mouse to draw a pattern that is symmetric across the picture.")));
} else { /* KAL_BOTH */
return(strdup(gettext_noop("Click and drag the mouse to draw with symmetric brushes (a kaleidoscope).")));
if (which == KAL_LR)
{
return (strdup
(gettext_noop
("Click and drag the mouse to draw with two brushes that are symmetric across the left and right of your picture.")));
}
else if (which == KAL_UD)
{
return (strdup
(gettext_noop
("Click and drag the mouse to draw with two brushes that are symmetric across the top and bottom of your picture.")));
}
else if (which == KAL_PATTERN)
{
return (strdup(gettext_noop("Click and drag the mouse to draw a pattern across the picture.")));
}
else if (which == KAL_TILES)
{
return (strdup(gettext_noop("Click and drag the mouse to draw a pattern that is symmetric across the picture.")));
}
else
{ /* KAL_BOTH */
return (strdup(gettext_noop("Click and drag the mouse to draw with symmetric brushes (a kaleidoscope).")));
}
}
// Do the effect:
static void do_kalidescope(void * ptr, int which, SDL_Surface * canvas,
static void do_kalidescope(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
{
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
int xx, yy;
int i, j;
Uint32 colr;
colr = SDL_MapRGB(canvas->format,
kalidescope_r,
kalidescope_g,
kalidescope_b);
colr = SDL_MapRGB(canvas->format, kalidescope_r, kalidescope_g, kalidescope_b);
for (yy = -8; yy < 8; yy++)
{
@ -168,19 +185,24 @@ static void do_kalidescope(void * ptr, int which, SDL_Surface * canvas,
{
api->putpixel(canvas, x + xx, y + yy, colr);
if (which == KAL_LR || which == KAL_BOTH) {
if (which == KAL_LR || which == KAL_BOTH)
{
api->putpixel(canvas, canvas->w - 1 - x + xx, y + yy, colr);
if (which == KAL_BOTH) {
if (which == KAL_BOTH)
{
api->putpixel(canvas, canvas->w - 1 - x + xx, canvas->h - 1 - y + yy, colr);
}
}
if (which == KAL_UD || which == KAL_BOTH) {
if (which == KAL_UD || which == KAL_BOTH)
{
api->putpixel(canvas, x + xx, canvas->h - 1 - y + yy, colr);
}
if (which == KAL_PATTERN || which == KAL_TILES) {
if (which == KAL_PATTERN || which == KAL_TILES)
{
for (i = 0; i <= canvas->w; i += square_size)
for (j = 0; j <= canvas->h; j += square_size){
for (j = 0; j <= canvas->h; j += square_size)
{
api->putpixel(canvas, i + xx + x % square_size, j + yy + y % square_size, colr);
if (which == KAL_TILES)
api->putpixel(canvas, i + yy + y % square_size, j + xx + x % square_size, colr);
@ -193,10 +215,9 @@ static void do_kalidescope(void * ptr, int which, SDL_Surface * canvas,
// Affect the canvas on drag:
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)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *) api, 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;
@ -208,8 +229,7 @@ void kalidescope_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void kalidescope_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
kalidescope_drag(api, which, canvas, last, x, y, x, y, update_rect);
}
@ -217,8 +237,7 @@ void kalidescope_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
// Affect the canvas on release:
void kalidescope_release(magic_api * api, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
api->stopsound();
}
@ -256,5 +275,5 @@ void kalidescope_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE
int kalidescope_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_PAINT);
return (MODE_PAINT);
}

View file

@ -38,25 +38,21 @@
/* Our globals: */
static Mix_Chunk * light1_snd, * light2_snd;
static Mix_Chunk *light1_snd, *light2_snd;
static float light_h, light_s, light_v;
Uint32 light_api_version(void);
int light_init(magic_api * api);
int light_get_tool_count(magic_api * api);
SDL_Surface * light_get_icon(magic_api * api, int which);
char * light_get_name(magic_api * api, int which);
char * light_get_description(magic_api * api, int which, int mode);
static void do_light(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
int x, int y);
SDL_Surface *light_get_icon(magic_api * api, int which);
char *light_get_name(magic_api * api, int which);
char *light_get_description(magic_api * api, int which, int mode);
static void do_light(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
void light_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void light_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void light_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void light_shutdown(magic_api * api);
void light_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int light_requires_colors(magic_api * api, int which);
@ -65,7 +61,10 @@ void light_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
int light_modes(magic_api * api, int which);
Uint32 light_api_version(void) { return(TP_MAGIC_API_VERSION); }
Uint32 light_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
// No setup required:
@ -73,52 +72,49 @@ int light_init(magic_api * api)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/sounds/magic/light1.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/sounds/magic/light1.ogg", api->data_directory);
light1_snd = Mix_LoadWAV(fname);
snprintf(fname, sizeof(fname), "%s/sounds/magic/light2.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/sounds/magic/light2.ogg", api->data_directory);
light2_snd = Mix_LoadWAV(fname);
return(1);
return (1);
}
// We have multiple tools:
int light_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return(1);
return (1);
}
// Load our icons:
SDL_Surface * light_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
SDL_Surface *light_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/images/magic/light.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/light.png", api->data_directory);
return(IMG_Load(fname));
return (IMG_Load(fname));
}
// Return our names, localized:
char * light_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
char *light_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(strdup(gettext_noop("Light")));
return (strdup(gettext_noop("Light")));
}
// Return our descriptions, localized:
char * light_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
char *light_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return(strdup(gettext_noop("Click and drag to draw a beam of light on your picture.")));
return (strdup(gettext_noop("Click and drag to draw a beam of light on your picture.")));
}
// Do the effect:
static void do_light(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
static void do_light(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
int x, int y)
{
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
int xx, yy;
Uint32 pix;
Uint8 r, g, b;
@ -139,7 +135,7 @@ static void do_light(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canva
api->rgbtohsv(r, g, b, &h, &s, &v);
v = min((float) 1.0, v + adj);
v = min((float)1.0, v + adj);
if (light_h == -1 && h == -1)
{
@ -168,8 +164,7 @@ static void do_light(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canva
api->hsvtorgb(new_h, new_s, new_v, &r, &g, &b);
api->putpixel(canvas, x + xx, y + yy,
SDL_MapRGB(canvas->format, r, g, b));
api->putpixel(canvas, x + xx, y + yy, SDL_MapRGB(canvas->format, r, g, b));
}
}
}
@ -177,13 +172,24 @@ static void do_light(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canva
// Affect the canvas on drag:
void light_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_light);
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_light);
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;
}
update_rect->x = ox - 8;
update_rect->y = oy - 8;
@ -195,8 +201,7 @@ void light_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void light_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
light_drag(api, which, canvas, last, x, y, x, y, update_rect);
}
@ -230,15 +235,17 @@ int light_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_
return 1;
}
void light_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void light_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void light_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void light_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int light_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_PAINT);
return (MODE_PAINT);
}

View file

@ -35,26 +35,22 @@
/* Our globals: */
static Mix_Chunk * metalpaint_snd;
static Mix_Chunk *metalpaint_snd;
static Uint8 metalpaint_r, metalpaint_g, metalpaint_b;
Uint32 metalpaint_api_version(void);
int metalpaint_init(magic_api * api);
int metalpaint_get_tool_count(magic_api * api);
SDL_Surface * metalpaint_get_icon(magic_api * api, int which);
char * metalpaint_get_name(magic_api * api, int which);
char * metalpaint_get_description(magic_api * api, int which, int mode);
static void do_metalpaint(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
int x, int y);
SDL_Surface *metalpaint_get_icon(magic_api * api, int which);
char *metalpaint_get_name(magic_api * api, int which);
char *metalpaint_get_description(magic_api * api, int which, int mode);
static void do_metalpaint(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
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);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void metalpaint_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void metalpaint_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void metalpaint_shutdown(magic_api * api);
void metalpaint_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int metalpaint_requires_colors(magic_api * api, int which);
@ -63,7 +59,10 @@ void metalpaint_switchout(magic_api * api, int which, int mode, SDL_Surface * ca
int metalpaint_modes(magic_api * api, int which);
Uint32 metalpaint_api_version(void) { return(TP_MAGIC_API_VERSION); }
Uint32 metalpaint_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
// No setup required:
@ -71,40 +70,39 @@ int metalpaint_init(magic_api * api)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/sounds/magic/metalpaint.wav",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/sounds/magic/metalpaint.wav", api->data_directory);
metalpaint_snd = Mix_LoadWAV(fname);
return(1);
return (1);
}
// We have multiple tools:
int metalpaint_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return(1);
return (1);
}
// Load our icons:
SDL_Surface * metalpaint_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
SDL_Surface *metalpaint_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/images/magic/metalpaint.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/metalpaint.png", api->data_directory);
return(IMG_Load(fname));
return (IMG_Load(fname));
}
// Return our names, localized:
char * metalpaint_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
char *metalpaint_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(strdup(gettext_noop("Metal Paint")));
return (strdup(gettext_noop("Metal Paint")));
}
// Return our descriptions, localized:
char * metalpaint_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
char *metalpaint_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED)
{
return(strdup(gettext_noop("Click and drag the mouse to paint with a metallic color.")));
return (strdup(gettext_noop("Click and drag the mouse to paint with a metallic color.")));
}
#define METALPAINT_CYCLE 32
@ -120,10 +118,10 @@ static int metalpaint_gradient[METALPAINT_CYCLE] = {
// Do the effect:
static void do_metalpaint(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
int x, int y)
static void do_metalpaint(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
{
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
int xx, yy;
int n;
Uint8 r, g, b;
@ -145,13 +143,24 @@ static void do_metalpaint(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface *
// Affect the canvas on drag:
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)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *) api, 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; }
if (ox > x)
{
int tmp = ox;
ox = x;
x = tmp;
}
if (oy > y)
{
int tmp = oy;
oy = y;
y = tmp;
}
update_rect->x = ox - 8;
update_rect->y = oy - 8;
@ -163,8 +172,7 @@ void metalpaint_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void metalpaint_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
metalpaint_drag(api, which, canvas, last, x, y, x, y, update_rect);
}
@ -197,15 +205,17 @@ int metalpaint_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRI
return 1;
}
void metalpaint_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void metalpaint_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void metalpaint_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void metalpaint_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int metalpaint_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_PAINT);
return (MODE_PAINT);
}

View file

@ -35,31 +35,25 @@
/* What tools we contain: */
enum {
enum
{
TOOL_MIRROR,
TOOL_FLIP,
NUM_TOOLS
};
static Mix_Chunk * snd_effects[NUM_TOOLS];
static Mix_Chunk *snd_effects[NUM_TOOLS];
/* Prototypes */
int mirror_flip_init(magic_api *);
Uint32 mirror_flip_api_version(void);
int mirror_flip_get_tool_count(magic_api *);
SDL_Surface * mirror_flip_get_icon(magic_api *, int);
char * mirror_flip_get_name(magic_api *, int);
char * mirror_flip_get_description(magic_api *, int, int);
void mirror_flip_drag(magic_api *, int, SDL_Surface *,
SDL_Surface *, int, int, int, int,
SDL_Rect *);
void mirror_flip_release(magic_api *, int, SDL_Surface *,
SDL_Surface *, int, int, int, int,
SDL_Rect *);
void mirror_flip_click(magic_api *, int, int,
SDL_Surface *, SDL_Surface *,
int, int,
SDL_Rect *);
SDL_Surface *mirror_flip_get_icon(magic_api *, int);
char *mirror_flip_get_name(magic_api *, int);
char *mirror_flip_get_description(magic_api *, int, int);
void mirror_flip_drag(magic_api *, int, SDL_Surface *, SDL_Surface *, int, int, int, int, SDL_Rect *);
void mirror_flip_release(magic_api *, int, SDL_Surface *, SDL_Surface *, int, int, int, int, SDL_Rect *);
void mirror_flip_click(magic_api *, int, int, SDL_Surface *, SDL_Surface *, int, int, SDL_Rect *);
void mirror_flip_shutdown(magic_api *);
void mirror_flip_set_color(magic_api *, Uint8, Uint8, Uint8);
int mirror_flip_requires_colors(magic_api *, int);
@ -72,67 +66,63 @@ int mirror_flip_init(magic_api * api)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/sounds/magic/mirror.wav",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/sounds/magic/mirror.wav", api->data_directory);
snd_effects[TOOL_MIRROR] = Mix_LoadWAV(fname);
snprintf(fname, sizeof(fname), "%s/sounds/magic/flip.wav",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/sounds/magic/flip.wav", api->data_directory);
snd_effects[TOOL_FLIP] = Mix_LoadWAV(fname);
return(1);
return (1);
}
Uint32 mirror_flip_api_version(void) { return(TP_MAGIC_API_VERSION); }
Uint32 mirror_flip_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
// We have multiple tools:
int mirror_flip_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return(NUM_TOOLS);
return (NUM_TOOLS);
}
// Load our icons:
SDL_Surface * mirror_flip_get_icon(magic_api * api, int which)
SDL_Surface *mirror_flip_get_icon(magic_api * api, int which)
{
char fname[1024];
if (which == TOOL_MIRROR)
{
snprintf(fname, sizeof(fname), "%s/images/magic/mirror.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/mirror.png", api->data_directory);
}
else if (which == TOOL_FLIP)
{
snprintf(fname, sizeof(fname), "%s/images/magic/flip.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/flip.png", api->data_directory);
}
return(IMG_Load(fname));
return (IMG_Load(fname));
}
// Return our names, localized:
char * mirror_flip_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
char *mirror_flip_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
{
if (which == TOOL_MIRROR)
return(strdup(gettext_noop("Mirror")));
return (strdup(gettext_noop("Mirror")));
else if (which == TOOL_FLIP)
return(strdup(gettext_noop("Flip")));
return (strdup(gettext_noop("Flip")));
return(NULL);
return (NULL);
}
// Return our descriptions, localized:
char * mirror_flip_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which, int mode ATTRIBUTE_UNUSED)
char *mirror_flip_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
{
if (which == TOOL_MIRROR)
return(strdup(
gettext_noop("Click to make a mirror image.")));
return (strdup(gettext_noop("Click to make a mirror image.")));
else
return(strdup(
gettext_noop("Click to flip the picture upside-down.")));
return (strdup(gettext_noop("Click to flip the picture upside-down.")));
return(NULL);
return (NULL);
}
// We affect the whole canvas, so only do things on click, not drag:
@ -140,8 +130,7 @@ void mirror_flip_drag(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED,
int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED,
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
// No-op
}
@ -150,8 +139,7 @@ void mirror_flip_release(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED,
int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED,
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
// No-op
}
@ -159,8 +147,7 @@ void mirror_flip_release(magic_api * api ATTRIBUTE_UNUSED,
// Affect the canvas on click:
void mirror_flip_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last,
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED,
SDL_Rect * update_rect)
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect)
{
int xx, yy;
SDL_Rect src, dest;
@ -219,32 +206,27 @@ void mirror_flip_shutdown(magic_api * api ATTRIBUTE_UNUSED)
// We don't use colors:
void mirror_flip_set_color(magic_api * api ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED)
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
{
}
// We don't use colors:
int mirror_flip_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int mirror_flip_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 0;
}
void mirror_flip_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void mirror_flip_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int mirror_flip_modes(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int mirror_flip_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_FULLSCREEN);
return (MODE_FULLSCREEN);
}

View file

@ -45,29 +45,22 @@
#define gettext_noop(String) String
#endif
static void mosaic_noise_pixel(void * ptr, SDL_Surface * canvas, int noise_AMOUNT, int x, int y);
static void mosaic_blur_pixel(void * ptr, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
static void mosaic_sharpen_pixel(void * ptr, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
static void mosaic_noise_pixel(void *ptr, SDL_Surface * canvas, int noise_AMOUNT, int x, int y);
static void mosaic_blur_pixel(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
static void mosaic_sharpen_pixel(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
static void reset_mosaic_blured(SDL_Surface * canvas);
/* Prototypes */
Uint32 mosaic_api_version(void);
int mosaic_init(magic_api *);
int mosaic_get_tool_count(magic_api *);
SDL_Surface * mosaic_get_icon(magic_api *, int);
char * mosaic_get_name(magic_api *, int);
char * mosaic_get_description(magic_api *, int, int);
void mosaic_paint(void *, int, SDL_Surface *,
SDL_Surface *, int, int);
void mosaic_drag(magic_api *, int, SDL_Surface *,
SDL_Surface *, int, int, int, int,
SDL_Rect *);
void mosaic_click(magic_api *, int, int,
SDL_Surface *, SDL_Surface *,
int, int, SDL_Rect *);
void mosaic_release(magic_api *, int,
SDL_Surface *, SDL_Surface *,
int, int, SDL_Rect *);
SDL_Surface *mosaic_get_icon(magic_api *, int);
char *mosaic_get_name(magic_api *, int);
char *mosaic_get_description(magic_api *, int, int);
void mosaic_paint(void *, int, SDL_Surface *, SDL_Surface *, int, int);
void mosaic_drag(magic_api *, int, SDL_Surface *, SDL_Surface *, int, int, int, int, SDL_Rect *);
void mosaic_click(magic_api *, int, int, SDL_Surface *, SDL_Surface *, int, int, SDL_Rect *);
void mosaic_release(magic_api *, int, SDL_Surface *, SDL_Surface *, int, int, SDL_Rect *);
void mosaic_shutdown(magic_api *);
void mosaic_set_color(magic_api *, Uint8, Uint8, Uint8);
int mosaic_requires_colors(magic_api *, int);
@ -75,91 +68,103 @@ void mosaic_switchin(magic_api *, int, int, SDL_Surface *);
void mosaic_switchout(magic_api *, int, int, SDL_Surface *);
int mosaic_modes(magic_api *, int);
static const int mosaic_AMOUNT= 300;
static const int mosaic_AMOUNT = 300;
static const int mosaic_RADIUS = 16;
static const double mosaic_SHARPEN = 1.0;
static int randnoise ATTRIBUTE_UNUSED;
Uint8 * mosaic_blured;
enum {
Uint8 *mosaic_blured;
enum
{
TOOL_MOSAIC,
mosaic_NUM_TOOLS
};
static Mix_Chunk * mosaic_snd_effect[mosaic_NUM_TOOLS];
static SDL_Surface * canvas_noise;
static SDL_Surface * canvas_blur;
static SDL_Surface * canvas_sharp;
static Mix_Chunk *mosaic_snd_effect[mosaic_NUM_TOOLS];
static SDL_Surface *canvas_noise;
static SDL_Surface *canvas_blur;
static SDL_Surface *canvas_sharp;
const char * mosaic_snd_filenames[mosaic_NUM_TOOLS] = {
const char *mosaic_snd_filenames[mosaic_NUM_TOOLS] = {
"mosaic.ogg", /* FIXME */
};
const char * mosaic_icon_filenames[mosaic_NUM_TOOLS] = {
const char *mosaic_icon_filenames[mosaic_NUM_TOOLS] = {
"mosaic.png",
};
const char * mosaic_names[mosaic_NUM_TOOLS] = {
const char *mosaic_names[mosaic_NUM_TOOLS] = {
gettext_noop("Mosaic"),
};
const char * mosaic_descs[mosaic_NUM_TOOLS][2] = {
const char *mosaic_descs[mosaic_NUM_TOOLS][2] = {
{gettext_noop("Click and drag the mouse to add a mosaic effect to parts of your picture."),
gettext_noop("Click to add a mosaic effect to your entire picture."),},
};
Uint32 mosaic_api_version(void) { return(TP_MAGIC_API_VERSION); }
Uint32 mosaic_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
//Load sounds
int mosaic_init(magic_api * api){
int mosaic_init(magic_api * api)
{
int i;
char fname[1024];
for (i = 0; i < mosaic_NUM_TOOLS; i++){
for (i = 0; i < mosaic_NUM_TOOLS; i++)
{
snprintf(fname, sizeof(fname), "%s/sounds/magic/%s", api->data_directory, mosaic_snd_filenames[i]);
mosaic_snd_effect[i] = Mix_LoadWAV(fname);
}
return(1);
return (1);
}
int mosaic_get_tool_count(magic_api * api ATTRIBUTE_UNUSED){
return(mosaic_NUM_TOOLS);
int mosaic_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return (mosaic_NUM_TOOLS);
}
// Load our icons:
SDL_Surface * mosaic_get_icon(magic_api * api, int which){
SDL_Surface *mosaic_get_icon(magic_api * api, int which)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, mosaic_icon_filenames[which]);
return(IMG_Load(fname));
return (IMG_Load(fname));
}
// Return our names, localized:
char * mosaic_get_name(magic_api * api ATTRIBUTE_UNUSED, int which){
return(strdup(gettext_noop(mosaic_names[which])));
char *mosaic_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
{
return (strdup(gettext_noop(mosaic_names[which])));
}
// Return our descriptions, localized:
char * mosaic_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which, int mode){
return(strdup(gettext_noop(mosaic_descs[which][mode-1])));
char *mosaic_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode)
{
return (strdup(gettext_noop(mosaic_descs[which][mode - 1])));
}
//Calculates the grey scale value for a rgb pixel
static int mosaic_grey(Uint8 r1,Uint8 g1,Uint8 b1){
return 0.3*r1+.59*g1+0.11*b1;
static int mosaic_grey(Uint8 r1, Uint8 g1, Uint8 b1)
{
return 0.3 * r1 + .59 * g1 + 0.11 * b1;
}
// Do the effect for the full image
static void do_mosaic_full(void * ptr, SDL_Surface * canvas,
SDL_Surface * last ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED){
static void do_mosaic_full(void *ptr, SDL_Surface * canvas,
SDL_Surface * last ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
int x,y;
int x, y;
Uint32 amask = ~(canvas->format->Rmask |
canvas->format->Gmask |
canvas->format->Bmask);
SDL_Surface * mosaic_temp =
SDL_CreateRGBSurface(SDL_SWSURFACE,
Uint32 amask = ~(canvas->format->Rmask | canvas->format->Gmask | canvas->format->Bmask);
SDL_Surface *mosaic_temp = SDL_CreateRGBSurface(SDL_SWSURFACE,
canvas->w,
canvas->h,
canvas->format->BitsPerPixel,
@ -171,17 +176,21 @@ Uint32 amask = ~(canvas->format->Rmask |
api->update_progress_bar();
for (y = 0; y < canvas->h; y++){
for (y = 0; y < canvas->h; y++)
{
for (x=0; x < canvas->w; x++){
for (x = 0; x < canvas->w; x++)
{
mosaic_blur_pixel(api, mosaic_temp, canvas_noise, x, y);
}
}
api->update_progress_bar();
for (y = 0; y < canvas->h; y++){
for (x=0; x < canvas->w; x++){
for (y = 0; y < canvas->h; y++)
{
for (x = 0; x < canvas->w; x++)
{
mosaic_sharpen_pixel(api, canvas, mosaic_temp, x, y);
}
}
@ -190,30 +199,28 @@ Uint32 amask = ~(canvas->format->Rmask |
/* Paint the brush, noise is yet done at switchin,
blurs 2 pixels around the brush in order to get sharpen well done.*/
void mosaic_paint(void * ptr_to_api, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
int x, int y)
void mosaic_paint(void *ptr_to_api, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
{
int i, j, pix_row_pos;
magic_api * api = (magic_api *) ptr_to_api;
magic_api *api = (magic_api *) ptr_to_api;
for (j = max(0, y - mosaic_RADIUS - 2); j < min(canvas->h, y + mosaic_RADIUS + 2); j++)
{
pix_row_pos = j * canvas->w;
for (i = max(0, x - mosaic_RADIUS - 2); i < min(canvas->w, x + mosaic_RADIUS + 2); i++)
if( !mosaic_blured[pix_row_pos + i] &&
api->in_circle(i - x,j - y, mosaic_RADIUS + 2))
if (!mosaic_blured[pix_row_pos + i] && api->in_circle(i - x, j - y, mosaic_RADIUS + 2))
{
mosaic_blur_pixel(api, canvas_blur, canvas_noise, i, j);
mosaic_blured[pix_row_pos + i] = 1; /* Track what are yet blured */
}
}
for (i = x - mosaic_RADIUS; i < x + mosaic_RADIUS; i++)
for (j=y - mosaic_RADIUS; j < y + mosaic_RADIUS; j++)
for (i = x - mosaic_RADIUS; i < x + mosaic_RADIUS; i++)
for (j = y - mosaic_RADIUS; j < y + mosaic_RADIUS; j++)
if (api->in_circle(i - x, j - y, mosaic_RADIUS))
if( !api->touched(i, j))
if (!api->touched(i, j))
{
mosaic_sharpen_pixel(api, canvas_sharp, canvas_blur, i, j);
api->putpixel(canvas, i, j, api->getpixel(canvas_sharp, i, j));
@ -222,8 +229,8 @@ for (i = x - mosaic_RADIUS; i < x + mosaic_RADIUS; i++)
// Affect the canvas on drag:
void mosaic_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect){
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line(api, which, canvas, last, ox, oy, x, y, 1, mosaic_paint);
update_rect->x = min(ox, x) - mosaic_RADIUS;
@ -236,8 +243,8 @@ void mosaic_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void mosaic_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect){
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
if (mode == MODE_FULLSCREEN)
{
@ -260,8 +267,7 @@ void mosaic_release(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED,
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
@ -270,8 +276,11 @@ void mosaic_shutdown(magic_api * api ATTRIBUTE_UNUSED)
{
//Clean up sounds
int i;
for(i=0; i<mosaic_NUM_TOOLS; i++){
if(mosaic_snd_effect[i] != NULL){
for (i = 0; i < mosaic_NUM_TOOLS; i++)
{
if (mosaic_snd_effect[i] != NULL)
{
Mix_FreeChunk(mosaic_snd_effect[i]);
}
}
@ -279,100 +288,111 @@ void mosaic_shutdown(magic_api * api ATTRIBUTE_UNUSED)
// Record the color from Tux Paint:
void mosaic_set_color(magic_api * api ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED)
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
{
}
// Use colors:
int mosaic_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
int mosaic_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 0;
}
//Add noise to a pixel
static void mosaic_noise_pixel(void * ptr, SDL_Surface * canvas, int noise_AMOUNT, int x, int y){
magic_api * api = (magic_api *) ptr;
static void mosaic_noise_pixel(void *ptr, SDL_Surface * canvas, int noise_AMOUNT, int x, int y)
{
magic_api *api = (magic_api *) ptr;
Uint8 temp[3];
double temp2[3];
int k;
SDL_GetRGB(api->getpixel(canvas,x, y), canvas->format, &temp[0], &temp[1], &temp[2]);
for (k =0;k<3;k++){
temp2[k] = clamp(0.0, (int)temp[k] - (rand()%noise_AMOUNT) + noise_AMOUNT/2.0, 255.0);
SDL_GetRGB(api->getpixel(canvas, x, y), canvas->format, &temp[0], &temp[1], &temp[2]);
for (k = 0; k < 3; k++)
{
temp2[k] = clamp(0.0, (int)temp[k] - (rand() % noise_AMOUNT) + noise_AMOUNT / 2.0, 255.0);
}
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, temp2[0], temp2[1], temp2[2]));
}
//Blur a pixel
static void mosaic_blur_pixel(void * ptr, SDL_Surface * canvas, SDL_Surface * last, int x, int y){
magic_api * api = (magic_api *) ptr;
int i,j,k;
static void mosaic_blur_pixel(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
magic_api *api = (magic_api *) ptr;
int i, j, k;
Uint8 temp[3];
double blurValue[3];
//5x5 gaussiann weighting window
const int weight[5][5] = { {1,4,7,4,1},
{4,16,26,16,4},
{7,26,41,26,7},
{4,16,26,16,4},
{1,4,7,4,1}};
for (k =0;k<3;k++){
//5x5 gaussiann weighting window
const int weight[5][5] = { {1, 4, 7, 4, 1},
{4, 16, 26, 16, 4},
{7, 26, 41, 26, 7},
{4, 16, 26, 16, 4},
{1, 4, 7, 4, 1}
};
for (k = 0; k < 3; k++)
{
blurValue[k] = 0;
}
for (i=-2;i<3;i++){
for (j=-2;j<3;j++){
for (i = -2; i < 3; i++)
{
for (j = -2; j < 3; j++)
{
//Add the pixels around the current one wieghted
SDL_GetRGB(api->getpixel(last, x + i, y + j), last->format, &temp[0], &temp[1], &temp[2]);
for (k =0;k<3;k++){
blurValue[k] += temp[k]* weight[i+2][j+2];
for (k = 0; k < 3; k++)
{
blurValue[k] += temp[k] * weight[i + 2][j + 2];
}
}
}
for (k =0;k<3;k++){
for (k = 0; k < 3; k++)
{
blurValue[k] /= 273;
}
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, blurValue[0], blurValue[1], blurValue[2]));
}
//Sharpen a pixel
static void mosaic_sharpen_pixel(void * ptr,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y){
static void mosaic_sharpen_pixel(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
Uint8 r1, g1, b1;
int grey;
int i,j;
double sobel_1=0,sobel_2=0;
int i, j;
double sobel_1 = 0, sobel_2 = 0;
double temp;
//Sobel weighting masks
const int sobel_weights_1[3][3] = { {1,2,1},
{0,0,0},
{-1,-2,-1}};
const int sobel_weights_2[3][3] = { {-1,0,1},
{-2,0,2},
{-1,0,1}};
const int sobel_weights_1[3][3] = { {1, 2, 1},
{0, 0, 0},
{-1, -2, -1}
};
const int sobel_weights_2[3][3] = { {-1, 0, 1},
{-2, 0, 2},
{-1, 0, 1}
};
sobel_1=0;
sobel_2=0;
for (i=-1;i<2;i++){
for(j=-1; j<2; j++){
sobel_1 = 0;
sobel_2 = 0;
for (i = -1; i < 2; i++)
{
for (j = -1; j < 2; j++)
{
//No need to check if inside canvas, getpixel does it for us.
SDL_GetRGB(api->getpixel(last, x+i, y+j), last->format, &r1, &g1, &b1);
grey = mosaic_grey(r1,g1,b1);
sobel_1 += grey * sobel_weights_1[i+1][j+1];
sobel_2 += grey * sobel_weights_2[i+1][j+1];
SDL_GetRGB(api->getpixel(last, x + i, y + j), last->format, &r1, &g1, &b1);
grey = mosaic_grey(r1, g1, b1);
sobel_1 += grey * sobel_weights_1[i + 1][j + 1];
sobel_2 += grey * sobel_weights_2[i + 1][j + 1];
}
}
temp = sqrt(sobel_1*sobel_1 + sobel_2*sobel_2);
temp = (temp/1443)*255.0;
temp = sqrt(sobel_1 * sobel_1 + sobel_2 * sobel_2);
temp = (temp / 1443) * 255.0;
SDL_GetRGB(api->getpixel(last, x, y), last->format, &r1, &g1, &b1);
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, clamp(0.0, r1 + mosaic_SHARPEN * temp, 255.0),
@ -381,8 +401,7 @@ static void mosaic_sharpen_pixel(void * ptr,
}
void mosaic_switchin(magic_api * api, int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas)
void mosaic_switchin(magic_api * api, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas)
{
int y, x;
Uint32 amask;
@ -394,22 +413,20 @@ void mosaic_switchin(magic_api * api, int which ATTRIBUTE_UNUSED,
exit(1);
}
amask = ~(canvas->format->Rmask |
canvas->format->Gmask |
canvas->format->Bmask);
amask = ~(canvas->format->Rmask | canvas->format->Gmask | canvas->format->Bmask);
canvas_noise = SDL_CreateRGBSurface(SDL_SWSURFACE,
canvas->w,
canvas->h,
canvas->format->BitsPerPixel,
canvas->format->Rmask,
canvas->format->Gmask,
canvas->format->Bmask, amask);
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, amask);
SDL_BlitSurface(canvas, NULL, canvas_noise, NULL);
for (y = 0; y < canvas->h; y++){
for (x=0; x < canvas->w; x++){
for (y = 0; y < canvas->h; y++)
{
for (x = 0; x < canvas->w; x++)
{
mosaic_noise_pixel(api, canvas_noise, mosaic_AMOUNT, x, y);
}
}
@ -418,33 +435,28 @@ void mosaic_switchin(magic_api * api, int which ATTRIBUTE_UNUSED,
canvas->w,
canvas->h,
canvas->format->BitsPerPixel,
canvas->format->Rmask,
canvas->format->Gmask,
canvas->format->Bmask, amask);
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, amask);
canvas_sharp = SDL_CreateRGBSurface(SDL_SWSURFACE,
canvas->w,
canvas->h,
canvas->format->BitsPerPixel,
canvas->format->Rmask,
canvas->format->Gmask,
canvas->format->Bmask, amask);
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, amask);
reset_mosaic_blured(canvas);
}
void mosaic_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
SDL_FreeSurface(canvas_noise);
SDL_FreeSurface(canvas_blur);
SDL_FreeSurface(canvas_sharp);
free (mosaic_blured);
free(mosaic_blured);
}
int mosaic_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_PAINT|MODE_FULLSCREEN);
return (MODE_PAINT | MODE_FULLSCREEN);
}
void reset_mosaic_blured(SDL_Surface * canvas)

View file

@ -49,35 +49,31 @@
#define gettext_noop(String) String
#endif
static void mosaic_shaped_sharpen_pixel(void * ptr, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
static void mosaic_shaped_sharpen_pixel(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
static void reset_counter(SDL_Surface * canvas, Uint8 * counter);
static void fill_square(magic_api * api, SDL_Surface * canvas, int x, int y, int size, Uint32 color);
static void deform(magic_api * api, SDL_Surface * srfc);
static void do_mosaic_shaped_full(void * ptr, SDL_Surface * canvas, SDL_Surface * last, int which, SDL_Rect * update_rect);
static void mosaic_shaped_fill(void * ptr_to_api, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y);
static void mosaic_shaped_paint(void * ptr, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y);
static void do_mosaic_shaped_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int which,
SDL_Rect * update_rect);
static void mosaic_shaped_fill(void *ptr_to_api, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
static void mosaic_shaped_paint(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
Uint32 mosaic_shaped_api_version(void);
int mosaic_shaped_init(magic_api * api);
int mosaic_shaped_get_tool_count(magic_api * api);
SDL_Surface * mosaic_shaped_get_icon(magic_api * api, int which);
char * mosaic_shaped_get_name(magic_api * api, int which);
SDL_Surface *mosaic_shaped_get_icon(magic_api * api, int which);
char *mosaic_shaped_get_name(magic_api * api, int which);
char * mosaic_shaped_get_description(magic_api * api, int which, int mode);
char *mosaic_shaped_get_description(magic_api * api, int which, int mode);
void mosaic_shaped_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void mosaic_shaped_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void mosaic_shaped_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void mosaic_shaped_shutdown(magic_api * api);
@ -91,10 +87,11 @@ void mosaic_shaped_switchout(magic_api * api, int which, int mode, SDL_Surface *
int mosaic_shaped_modes(magic_api * api, int which);
int scan_fill(magic_api * api, SDL_Surface * canvas, SDL_Surface * srfc, int x, int y, int fill_edge, int fill_tile, int size, Uint32 color);
int scan_fill(magic_api * api, SDL_Surface * canvas, SDL_Surface * srfc, int x, int y, int fill_edge, int fill_tile,
int size, Uint32 color);
Uint8 * mosaic_shaped_counted;
Uint8 * mosaic_shaped_done;
Uint8 *mosaic_shaped_counted;
Uint8 *mosaic_shaped_done;
Uint8 mosaic_shaped_r, mosaic_shaped_g, mosaic_shaped_b;
int mosaic_shaped_average_r, mosaic_shaped_average_g, mosaic_shaped_average_b, mosaic_shaped_average_count;
@ -108,42 +105,37 @@ enum
mosaic_shaped_NUM_TOOLS
};
static Mix_Chunk * mosaic_shaped_snd_effect[mosaic_shaped_NUM_TOOLS];
static SDL_Surface * canvas_shaped;
static SDL_Surface * canvas_back;
static SDL_Surface * mosaic_shaped_pattern;
static Mix_Chunk *mosaic_shaped_snd_effect[mosaic_shaped_NUM_TOOLS];
static SDL_Surface *canvas_shaped;
static SDL_Surface *canvas_back;
static SDL_Surface *mosaic_shaped_pattern;
const char * mosaic_shaped_snd_filenames[mosaic_shaped_NUM_TOOLS] =
{
const char *mosaic_shaped_snd_filenames[mosaic_shaped_NUM_TOOLS] = {
"mosaic_shaped_square.ogg",
"mosaic_shaped_hex.ogg",
"mosaic_shaped_irregular.ogg", /* FIXME */ /*what's problem?*/
"mosaic_shaped_irregular.ogg", /* FIXME *//*what's problem? */
};
const char * mosaic_shaped_icon_filenames[mosaic_shaped_NUM_TOOLS] =
{
const char *mosaic_shaped_icon_filenames[mosaic_shaped_NUM_TOOLS] = {
"mosaic_shaped_square.png",
"mosaic_shaped_hex.png",
"mosaic_shaped_irregular.png",
};
const char * mosaic_shaped_pattern_filenames[mosaic_shaped_NUM_TOOLS] =
{
const char *mosaic_shaped_pattern_filenames[mosaic_shaped_NUM_TOOLS] = {
"mosaic_shaped_square_pattern.png",
"mosaic_shaped_hex_pattern.png",
"mosaic_shaped_irregular_pattern.png",
};
const char * mosaic_shaped_names[mosaic_shaped_NUM_TOOLS] =
{
const char *mosaic_shaped_names[mosaic_shaped_NUM_TOOLS] = {
gettext_noop("Square Mosaic"),
gettext_noop("Hexagon Mosaic"),
gettext_noop("Irregular Mosaic"),
};
const char * mosaic_shaped_descs[mosaic_shaped_NUM_TOOLS][2] =
{
const char *mosaic_shaped_descs[mosaic_shaped_NUM_TOOLS][2] = {
{
gettext_noop("Click and drag the mouse to add a square mosaic to parts of your picture."),
gettext_noop("Click to add a square mosaic to your entire picture."),
@ -170,6 +162,7 @@ int mosaic_shaped_init(magic_api * api)
{
int i;
char fname[1024];
mosaic_shaped_pattern = NULL;
for (i = 0; i < mosaic_shaped_NUM_TOOLS; i++)
@ -187,21 +180,22 @@ int mosaic_shaped_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
}
// Load our icons:
SDL_Surface * mosaic_shaped_get_icon(magic_api * api, int which)
SDL_Surface *mosaic_shaped_get_icon(magic_api * api, int which)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, mosaic_shaped_icon_filenames[which]);
return (IMG_Load(fname));
}
// Return our names, localized:
char * mosaic_shaped_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
char *mosaic_shaped_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
{
return (strdup(gettext_noop(mosaic_shaped_names[which])));
}
// Return our descriptions, localized:
char * mosaic_shaped_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode)
char *mosaic_shaped_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode)
{
return (strdup(gettext_noop(mosaic_shaped_descs[which][mode - 1])));
}
@ -213,11 +207,13 @@ static int mosaic_shaped_grey(Uint8 r1, Uint8 g1, Uint8 b1)
}
// Do the effect for the full image
static void do_mosaic_shaped_full(void * ptr, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
static void do_mosaic_shaped_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
int i, j, size;
Uint32 mosaic_shaped_color;
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
mosaic_shaped_color = SDL_MapRGBA(canvas->format, mosaic_shaped_r, mosaic_shaped_g, mosaic_shaped_b, 0);
for (i = 3; i < canvas->w - 3; i += 2)
@ -241,7 +237,10 @@ static void do_mosaic_shaped_full(void * ptr, SDL_Surface * canvas, SDL_Surface
{
reset_counter(canvas, mosaic_shaped_counted);
size = 0;
pixel_average = SDL_MapRGB(canvas->format, mosaic_shaped_average_r / mosaic_shaped_average_count, mosaic_shaped_average_g / mosaic_shaped_average_count, mosaic_shaped_average_b / mosaic_shaped_average_count);
pixel_average =
SDL_MapRGB(canvas->format, mosaic_shaped_average_r / mosaic_shaped_average_count,
mosaic_shaped_average_g / mosaic_shaped_average_count,
mosaic_shaped_average_b / mosaic_shaped_average_count);
scan_fill(api, canvas, canvas_shaped, i, j, 0, 1, size, pixel_average);
}
}
@ -250,12 +249,13 @@ static void do_mosaic_shaped_full(void * ptr, SDL_Surface * canvas, SDL_Surface
}
/* Fills a tesera */
static void mosaic_shaped_fill(void * ptr_to_api, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
static void mosaic_shaped_fill(void *ptr_to_api, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
{
Uint32 mosaic_shaped_color;
int size;
magic_api * api = (magic_api *) ptr_to_api;
magic_api *api = (magic_api *) ptr_to_api;
x = clamp(0, x, canvas->w - 1);
y = clamp(0, y, canvas->h - 1);
mosaic_shaped_color = SDL_MapRGBA(canvas->format, mosaic_shaped_r, mosaic_shaped_g, mosaic_shaped_b, 0);
@ -274,7 +274,10 @@ static void mosaic_shaped_fill(void * ptr_to_api, int which ATTRIBUTE_UNUSED, SD
if (mosaic_shaped_average_count > 0)
{
size = 0;
pixel_average = SDL_MapRGB(canvas->format, mosaic_shaped_average_r / mosaic_shaped_average_count, mosaic_shaped_average_g / mosaic_shaped_average_count, mosaic_shaped_average_b / mosaic_shaped_average_count);
pixel_average =
SDL_MapRGB(canvas->format, mosaic_shaped_average_r / mosaic_shaped_average_count,
mosaic_shaped_average_g / mosaic_shaped_average_count,
mosaic_shaped_average_b / mosaic_shaped_average_count);
reset_counter(canvas, mosaic_shaped_counted);
scan_fill(api, canvas, canvas_shaped, x, y, 0, 1, size, pixel_average);
}
@ -282,8 +285,7 @@ static void mosaic_shaped_fill(void * ptr_to_api, int which ATTRIBUTE_UNUSED, SD
// Affect the canvas on drag:
void mosaic_shaped_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line(api, which, canvas, last, ox, oy, x, y, 1, mosaic_shaped_fill);
update_rect->x = min(ox, x) - mosaic_shaped_pattern->w;
@ -295,8 +297,7 @@ void mosaic_shaped_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void mosaic_shaped_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
if (mode == MODE_FULLSCREEN)
{
@ -350,24 +351,24 @@ int mosaic_shaped_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which AT
}
//Sharpen a pixel
static void mosaic_shaped_sharpen_pixel(void * ptr,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last,
int x, int y)
static void mosaic_shaped_sharpen_pixel(void *ptr,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last, int x, int y)
{
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
Uint8 r1, g1, b1;
int grey;
int i, j;
double sobel_1 = 0, sobel_2 = 0;
double temp;
//Sobel weighting masks
const int sobel_weights_1[3][3] = { {1, 2, 1},
{0, 0, 0},
{ -1, -2, -1}
{-1, -2, -1}
};
const int sobel_weights_2[3][3] = { { -1, 0, 1},
{ -2, 0, 2},
{ -1, 0, 1}
const int sobel_weights_2[3][3] = { {-1, 0, 1},
{-2, 0, 2},
{-1, 0, 1}
};
sobel_1 = 0;
sobel_2 = 0;
@ -400,8 +401,9 @@ void mosaic_shaped_switchin(magic_api * api, int which, int mode ATTRIBUTE_UNUSE
int y, x;
int i, j;
SDL_Rect rect;
SDL_Surface * surf_aux, *tmp, *tmp2;
SDL_Surface *surf_aux, *tmp, *tmp2;
Uint32 amask;
mosaic_shaped_counted = (Uint8 *) malloc(sizeof(Uint8) * (canvas->w * canvas->h));
if (mosaic_shaped_counted == NULL)
@ -418,17 +420,13 @@ void mosaic_shaped_switchin(magic_api * api, int which, int mode ATTRIBUTE_UNUSE
exit(1);
}
amask = ~(canvas->format->Rmask |
canvas->format->Gmask |
canvas->format->Bmask);
amask = ~(canvas->format->Rmask | canvas->format->Gmask | canvas->format->Bmask);
tmp = SDL_CreateRGBSurface(SDL_SWSURFACE,
canvas->w,
canvas->h,
canvas->format->BitsPerPixel,
canvas->format->Rmask,
canvas->format->Gmask,
canvas->format->Bmask, amask);
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, amask);
canvas_shaped = SDL_ConvertSurfaceFormat(tmp, SDL_PIXELFORMAT_RGB888, 0);
SDL_FreeSurface(tmp);
@ -436,9 +434,7 @@ void mosaic_shaped_switchin(magic_api * api, int which, int mode ATTRIBUTE_UNUSE
canvas->w + 10,
canvas->h + 10,
canvas->format->BitsPerPixel,
canvas->format->Rmask,
canvas->format->Gmask,
canvas->format->Bmask, amask);
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, amask);
/* Generation of patterns now in the program, solves #210 */
if (which == TOOL_SQUARE)
@ -448,30 +444,42 @@ void mosaic_shaped_switchin(magic_api * api, int which, int mode ATTRIBUTE_UNUSE
16,
canvas->format->BitsPerPixel,
canvas->format->Rmask,
canvas->format->Gmask,
canvas->format->Bmask, amask);
SDL_FillRect(mosaic_shaped_pattern, NULL, SDL_MapRGBA(mosaic_shaped_pattern->format, 255, 255, 255, SDL_ALPHA_OPAQUE));
canvas->format->Gmask, canvas->format->Bmask, amask);
SDL_FillRect(mosaic_shaped_pattern, NULL,
SDL_MapRGBA(mosaic_shaped_pattern->format, 255, 255, 255, SDL_ALPHA_OPAQUE));
/* Shape */
for (i = 0;i < mosaic_shaped_pattern->w; i++)
for (i = 0; i < mosaic_shaped_pattern->w; i++)
{
api->putpixel(mosaic_shaped_pattern, 0, i, SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, mosaic_shaped_pattern->w - 1, i, SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, i, 0, SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, i, mosaic_shaped_pattern->w - 1, SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, 0, i,
SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, mosaic_shaped_pattern->w - 1, i,
SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, i, 0,
SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, i, mosaic_shaped_pattern->w - 1,
SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0, SDL_ALPHA_OPAQUE));
}
/* Shadow */
for (i = 1; i < mosaic_shaped_pattern->w - 1; i++)
{
api->putpixel(mosaic_shaped_pattern, 1, i, SDL_MapRGBA(mosaic_shaped_pattern->format, 128, 128, 128, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, mosaic_shaped_pattern->w - 2, i, SDL_MapRGBA(mosaic_shaped_pattern->format, 128, 128, 128, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, i, 1, SDL_MapRGBA(mosaic_shaped_pattern->format, 128, 128, 128, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, i, mosaic_shaped_pattern->w - 2, SDL_MapRGBA(mosaic_shaped_pattern->format, 128, 128, 128, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, 1, i,
SDL_MapRGBA(mosaic_shaped_pattern->format, 128, 128, 128, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, mosaic_shaped_pattern->w - 2, i,
SDL_MapRGBA(mosaic_shaped_pattern->format, 128, 128, 128, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, i, 1,
SDL_MapRGBA(mosaic_shaped_pattern->format, 128, 128, 128, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, i, mosaic_shaped_pattern->w - 2,
SDL_MapRGBA(mosaic_shaped_pattern->format, 128, 128, 128, SDL_ALPHA_OPAQUE));
}
api->putpixel(mosaic_shaped_pattern, 2, 2, SDL_MapRGBA(mosaic_shaped_pattern->format, 152, 152, 152, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, 2, mosaic_shaped_pattern->h - 3, SDL_MapRGBA(mosaic_shaped_pattern->format, 152, 152, 152, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, mosaic_shaped_pattern->w - 3, 2, SDL_MapRGBA(mosaic_shaped_pattern->format, 152, 152, 152, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, mosaic_shaped_pattern->w - 3, mosaic_shaped_pattern->h - 3, SDL_MapRGBA(mosaic_shaped_pattern->format, 152, 152, 152, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, 2, 2,
SDL_MapRGBA(mosaic_shaped_pattern->format, 152, 152, 152, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, 2, mosaic_shaped_pattern->h - 3,
SDL_MapRGBA(mosaic_shaped_pattern->format, 152, 152, 152, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, mosaic_shaped_pattern->w - 3, 2,
SDL_MapRGBA(mosaic_shaped_pattern->format, 152, 152, 152, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, mosaic_shaped_pattern->w - 3, mosaic_shaped_pattern->h - 3,
SDL_MapRGBA(mosaic_shaped_pattern->format, 152, 152, 152, SDL_ALPHA_OPAQUE));
}
else if (which == TOOL_IRREGULAR)
{
@ -480,9 +488,9 @@ void mosaic_shaped_switchin(magic_api * api, int which, int mode ATTRIBUTE_UNUSE
64,
canvas->format->BitsPerPixel,
canvas->format->Rmask,
canvas->format->Gmask,
canvas->format->Bmask, amask);
SDL_FillRect(mosaic_shaped_pattern, NULL, SDL_MapRGBA(mosaic_shaped_pattern->format, 255, 255, 255, SDL_ALPHA_OPAQUE));
canvas->format->Gmask, canvas->format->Bmask, amask);
SDL_FillRect(mosaic_shaped_pattern, NULL,
SDL_MapRGBA(mosaic_shaped_pattern->format, 255, 255, 255, SDL_ALPHA_OPAQUE));
/* Start/end of lines taken from the original mosaic_shaped_irregular_pattern.png */
api->line(api, which, mosaic_shaped_pattern, NULL, 0, 8, 36, 23, 1, mosaic_shaped_paint);
@ -495,8 +503,8 @@ void mosaic_shaped_switchin(magic_api * api, int which, int mode ATTRIBUTE_UNUSE
api->line(api, which, mosaic_shaped_pattern, NULL, 24, 0, 27, 19, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 63, 8, 50, 6, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 10, 0, 4, 10, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 10, 0, 25,7, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 41, 0, 26,12, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 10, 0, 25, 7, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 41, 0, 26, 12, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 41, 63, 28, 53, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 41, 63, 56, 58, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 63, 53, 55, 45, 1, mosaic_shaped_paint);
@ -514,31 +522,37 @@ void mosaic_shaped_switchin(magic_api * api, int which, int mode ATTRIBUTE_UNUSE
api->line(api, which, mosaic_shaped_pattern, NULL, 61, 44, 52, 31, 1, mosaic_shaped_paint);
}
else if(which == TOOL_HEX)
else if (which == TOOL_HEX)
{
mosaic_shaped_pattern = SDL_CreateRGBSurface(SDL_SWSURFACE,
48,
28,
canvas->format->BitsPerPixel,
canvas->format->Rmask,
canvas->format->Gmask,
canvas->format->Bmask, amask);
SDL_FillRect(mosaic_shaped_pattern, NULL, SDL_MapRGBA(mosaic_shaped_pattern->format, 255, 255, 255, SDL_ALPHA_OPAQUE));
canvas->format->Gmask, canvas->format->Bmask, amask);
SDL_FillRect(mosaic_shaped_pattern, NULL,
SDL_MapRGBA(mosaic_shaped_pattern->format, 255, 255, 255, SDL_ALPHA_OPAQUE));
api->line(api, which, mosaic_shaped_pattern, NULL, 0, 16, 8, 0, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 8, 0, 26, 0, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 26, 0, 32, 14, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 32, 14, 26, 27, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 32, 14, 47, 14, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 0,13 ,8, 27, 1, mosaic_shaped_paint);
api->line(api, which, mosaic_shaped_pattern, NULL, 0, 13, 8, 27, 1, mosaic_shaped_paint);
//make pattern more accurate
api->putpixel(mosaic_shaped_pattern, 9 , 27, SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, 9 , 26, SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, 26 , 27, SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, 26 , 26, SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, 26 , 25, SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, 25 , 27, SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, 9, 27,
SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, 9, 26,
SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, 26, 27,
SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, 26, 26,
SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, 26, 25,
SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0, SDL_ALPHA_OPAQUE));
api->putpixel(mosaic_shaped_pattern, 25, 27,
SDL_MapRGBA(mosaic_shaped_pattern->format, 0, 0, 0, SDL_ALPHA_OPAQUE));
}
@ -559,7 +573,7 @@ void mosaic_shaped_switchin(magic_api * api, int which, int mode ATTRIBUTE_UNUSE
deform(api, surf_aux);
}
SDL_SetSurfaceBlendMode (surf_aux, SDL_BLENDMODE_NONE);
SDL_SetSurfaceBlendMode(surf_aux, SDL_BLENDMODE_NONE);
SDL_BlitSurface(surf_aux, NULL, canvas_shaped, NULL);
SDL_FreeSurface(surf_aux);
black = SDL_MapRGBA(canvas->format, 0, 0, 0, 0);
@ -587,9 +601,7 @@ void mosaic_shaped_switchin(magic_api * api, int which, int mode ATTRIBUTE_UNUSE
canvas->w,
canvas->h,
canvas->format->BitsPerPixel,
canvas->format->Rmask,
canvas->format->Gmask,
canvas->format->Bmask, amask);
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, amask);
SDL_BlitSurface(canvas, NULL, canvas_back, NULL);
if (which != TOOL_SQUARE) /* The pattern for square is small enouth to not need an additional shape */
@ -605,7 +617,8 @@ void mosaic_shaped_switchin(magic_api * api, int which, int mode ATTRIBUTE_UNUSE
reset_counter(canvas, mosaic_shaped_done);
}
void mosaic_shaped_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void mosaic_shaped_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
SDL_FreeSurface(canvas_shaped);
SDL_FreeSurface(canvas_back);
@ -632,7 +645,8 @@ void reset_counter(SDL_Surface * canvas, Uint8 * counter)
int scan_fill_count;
int scan_fill(magic_api * api, SDL_Surface * canvas, SDL_Surface * srfc, int x, int y, int fill_edge, int fill_tile, int size, Uint32 color)
int scan_fill(magic_api * api, SDL_Surface * canvas, SDL_Surface * srfc, int x, int y, int fill_edge, int fill_tile,
int size, Uint32 color)
{
int leftx, rightx;
Uint8 r, g, b, a;
@ -643,7 +657,7 @@ int scan_fill(magic_api * api, SDL_Surface * canvas, SDL_Surface * srfc, int x,
/* Abort, if we recurse too deep! -bjk 2014.08.05 */
scan_fill_count++;
if (scan_fill_count > 500 )
if (scan_fill_count > 500)
{
scan_fill_count--;
return (0);
@ -671,6 +685,7 @@ int scan_fill(magic_api * api, SDL_Surface * canvas, SDL_Surface * srfc, int x,
Uint32 shadow;
Uint8 shr, shg, shb, sha;
Uint8 cnvsr, cnvsg, cnvsb, cnvsa;
shadow = api->getpixel(srfc, x, y);
SDL_GetRGBA(shadow, srfc->format, &shr, &shg, &shb, &sha);
SDL_GetRGBA(pixel_average, srfc->format, &cnvsr, &cnvsg, &cnvsb, &cnvsa);
@ -692,13 +707,13 @@ int scan_fill(magic_api * api, SDL_Surface * canvas, SDL_Surface * srfc, int x,
/* Search right */
while (scan_fill(api, canvas, srfc, rightx, y, fill_edge, fill_tile, size, color) && (rightx < canvas->w))
{
rightx ++;
rightx++;
}
/* Search left */
while (scan_fill(api, canvas, srfc, leftx, y, fill_edge, fill_tile, size, color) && (leftx >= 0))
{
leftx --;
leftx--;
}
/* Top / bottom */
@ -749,10 +764,10 @@ void deform(magic_api * api, SDL_Surface * srfc)
}
/* Paints a 2 pixel square with black and shadows around 3 more pixels */
static void mosaic_shaped_paint(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
static void mosaic_shaped_paint(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
{
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
int radius, shadow;
int i, j, ii, jj;
Uint8 r, g, b, a;
@ -768,17 +783,21 @@ static void mosaic_shaped_paint(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surf
{
/* Ensure effects on the edges reaches the opposite side if necessary */
ii = x + i;
if (ii < 0) ii += canvas->w;
if (ii >= canvas->w) ii -= canvas->w;
if (ii < 0)
ii += canvas->w;
if (ii >= canvas->w)
ii -= canvas->w;
jj = y + j;
if (jj < 0) jj += canvas->h;
if (jj >= canvas->h) ii -= canvas->h;
if (jj < 0)
jj += canvas->h;
if (jj >= canvas->h)
ii -= canvas->h;
/* Shadow_tone is also used as a marker, anything already painted on black must finally be black */
shadow_tone = api->getpixel(canvas, ii, jj);
// if (abs(i) <= radius && abs(j) <= radius)
if (0 <=i && i <= 1 && 0 <= j && j <= 1)
if (0 <= i && i <= 1 && 0 <= j && j <= 1)
api->putpixel(canvas, ii, jj, black);
else if (api->in_circle(i, j, radius + shadow) && shadow_tone != black)
@ -786,9 +805,12 @@ static void mosaic_shaped_paint(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surf
SDL_GetRGBA(shadow_tone, canvas->format, &r, &g, &b, &a);
/* Shadows should be shadows, not black */
if (r > 10) r -= 9;
if (g > 10) g -= 9;
if (b > 10) b -= 9;
if (r > 10)
r -= 9;
if (g > 10)
g -= 9;
if (b > 10)
b -= 9;
api->putpixel(canvas, ii, jj, SDL_MapRGBA(canvas->format, r, g, b, SDL_ALPHA_OPAQUE));

View file

@ -33,27 +33,22 @@
#include "SDL_image.h"
#include "SDL_mixer.h"
static Mix_Chunk * negative_snd;
static Mix_Chunk *negative_snd;
int negative_init(magic_api * api);
Uint32 negative_api_version(void);
int negative_get_tool_count(magic_api * api);
SDL_Surface * negative_get_icon(magic_api * api, int which);
char * negative_get_name(magic_api * api, int which);
char * negative_get_description(magic_api * api, int which, int mode);
static void do_negative(void * ptr, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y);
SDL_Surface *negative_get_icon(magic_api * api, int which);
char *negative_get_name(magic_api * api, int which);
char *negative_get_description(magic_api * api, int which, int mode);
static void do_negative(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
void negative_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void negative_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void negative_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void negative_shutdown(magic_api * api);
void negative_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int negative_requires_colors(magic_api * api, int which);
@ -66,59 +61,56 @@ int negative_init(magic_api * api)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/sounds/magic/negative.wav",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/sounds/magic/negative.wav", api->data_directory);
negative_snd = Mix_LoadWAV(fname);
return(1);
return (1);
}
Uint32 negative_api_version(void) { return(TP_MAGIC_API_VERSION); }
Uint32 negative_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
// Only one tool:
int negative_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return(1);
return (1);
}
// Load our icon:
SDL_Surface * negative_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
SDL_Surface *negative_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/images/magic/negative.png",
api->data_directory);
return(IMG_Load(fname));
snprintf(fname, sizeof(fname), "%s/images/magic/negative.png", api->data_directory);
return (IMG_Load(fname));
}
// Return our name, localized:
char * negative_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
char *negative_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(strdup(gettext_noop("Negative")));
return (strdup(gettext_noop("Negative")));
}
// Return our description, localized:
char * negative_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode)
char *negative_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode)
{
if (mode == MODE_PAINT)
return(strdup(
gettext_noop("Click and drag the mouse around to make your painting negative."))); /* Does this make more sense? */
return (strdup(gettext_noop("Click and drag the mouse around to make your painting negative."))); /* Does this make more sense? */
else if (mode == MODE_FULLSCREEN)
return(strdup(
gettext_noop("Click to turn your painting into its negative.")));
return (strdup(gettext_noop("Click to turn your painting into its negative.")));
else
return(NULL);
return (NULL);
}
// Callback that does the negative color effect on a circle centered around x,y
static void do_negative(void * ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y)
static void do_negative(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
int xx, yy;
Uint8 r, g, b;
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
for (yy = y - 16; yy < y + 16; yy++)
{
@ -140,16 +132,27 @@ static void do_negative(void * ptr, int which ATTRIBUTE_UNUSED,
// Ask Tux Paint to call our 'do_negative()' callback over a line
void negative_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
SDL_LockSurface(last);
SDL_LockSurface(canvas);
api->line((void *) api, 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; }
if (ox > x)
{
int tmp = ox;
ox = x;
x = tmp;
}
if (oy > y)
{
int tmp = oy;
oy = y;
y = tmp;
}
update_rect->x = ox - 16;
update_rect->y = oy - 16;
@ -165,8 +168,7 @@ void negative_drag(magic_api * api, int which, SDL_Surface * canvas,
// Ask Tux Paint to call our 'do_negative()' callback at a single point
void negative_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
if (mode == MODE_PAINT)
negative_drag(api, which, canvas, last, x, y, x, y, update_rect);
@ -211,7 +213,8 @@ void negative_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// We don't use colors
void negative_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
void negative_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED)
{
}
@ -221,15 +224,17 @@ int negative_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBU
return 0;
}
void negative_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void negative_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void negative_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void negative_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int negative_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_PAINT | MODE_FULLSCREEN);
return (MODE_PAINT | MODE_FULLSCREEN);
}

View file

@ -46,46 +46,45 @@
static const int noise_AMOUNT = 100.0;
static const int noise_RADIUS = 16;
enum {
enum
{
TOOL_NOISE,
noise_NUM_TOOLS
};
static Mix_Chunk * noise_snd_effect[noise_NUM_TOOLS];
static Mix_Chunk *noise_snd_effect[noise_NUM_TOOLS];
const char * noise_snd_filenames[noise_NUM_TOOLS] = {
const char *noise_snd_filenames[noise_NUM_TOOLS] = {
"noise.ogg",
};
const char * noise_icon_filenames[noise_NUM_TOOLS] = {
const char *noise_icon_filenames[noise_NUM_TOOLS] = {
"noise.png",
};
const char * noise_names[noise_NUM_TOOLS] = {
const char *noise_names[noise_NUM_TOOLS] = {
gettext_noop("Noise"),
};
const char * noise_descs[noise_NUM_TOOLS][2] = {
const char *noise_descs[noise_NUM_TOOLS][2] = {
{gettext_noop("Click and drag the mouse to add noise to parts of your picture."),
gettext_noop("Click to add noise to your entire picture."),},
};
Uint32 noise_api_version(void);
int noise_init(magic_api * api);
SDL_Surface * noise_get_icon(magic_api * api, int which);
char * noise_get_name(magic_api * api, int which);
char * noise_get_description(magic_api * api, int which, int mode);
static void do_noise_pixel(void * ptr, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y);
static void do_noise_full(void * ptr,SDL_Surface * canvas, SDL_Surface * last, int which);
static void do_noise_brush(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
SDL_Surface *noise_get_icon(magic_api * api, int which);
char *noise_get_name(magic_api * api, int which);
char *noise_get_description(magic_api * api, int which, int mode);
static void do_noise_pixel(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
static void do_noise_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int which);
static void do_noise_brush(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
void noise_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void noise_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void noise_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void noise_shutdown(magic_api * api);
void noise_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int noise_requires_colors(magic_api * api, int which);
@ -94,83 +93,97 @@ void noise_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
int noise_modes(magic_api * api, int which);
int noise_get_tool_count(magic_api * api ATTRIBUTE_UNUSED);
Uint32 noise_api_version(void) { return(TP_MAGIC_API_VERSION); }
Uint32 noise_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
//Load sounds
int noise_init(magic_api * api){
int noise_init(magic_api * api)
{
int i;
char fname[1024];
srand(time(0));
for (i = 0; i < noise_NUM_TOOLS; i++){
for (i = 0; i < noise_NUM_TOOLS; i++)
{
snprintf(fname, sizeof(fname), "%s/sounds/magic/%s", api->data_directory, noise_snd_filenames[i]);
noise_snd_effect[i] = Mix_LoadWAV(fname);
}
return(1);
return (1);
}
int noise_get_tool_count(magic_api * api ATTRIBUTE_UNUSED){
return(noise_NUM_TOOLS);
int noise_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return (noise_NUM_TOOLS);
}
// Load our icons:
SDL_Surface * noise_get_icon(magic_api * api, int which){
SDL_Surface *noise_get_icon(magic_api * api, int which)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, noise_icon_filenames[which]);
return(IMG_Load(fname));
return (IMG_Load(fname));
}
// Return our names, localized:
char * noise_get_name(magic_api * api ATTRIBUTE_UNUSED, int which){
return(strdup(gettext_noop(noise_names[which])));
char *noise_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
{
return (strdup(gettext_noop(noise_names[which])));
}
// Return our descriptions, localized:
char * noise_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode){
return(strdup(gettext_noop(noise_descs[which][mode-1])));
char *noise_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode)
{
return (strdup(gettext_noop(noise_descs[which][mode - 1])));
}
//Do the effect for one pixel
static void do_noise_pixel(void * ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
int x, int y){
magic_api * api = (magic_api *) ptr;
static void do_noise_pixel(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
{
magic_api *api = (magic_api *) ptr;
Uint8 temp[3];
double temp2[3];
int k;
SDL_GetRGB(api->getpixel(canvas,x, y), canvas->format, &temp[0], &temp[1], &temp[2]);
for (k =0;k<3;k++){
temp2[k] = clamp(0.0, (int)temp[k] - (rand()%noise_AMOUNT) + noise_AMOUNT/2.0, 255.0);
SDL_GetRGB(api->getpixel(canvas, x, y), canvas->format, &temp[0], &temp[1], &temp[2]);
for (k = 0; k < 3; k++)
{
temp2[k] = clamp(0.0, (int)temp[k] - (rand() % noise_AMOUNT) + noise_AMOUNT / 2.0, 255.0);
}
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, temp2[0], temp2[1], temp2[2]));
}
// Do the effect for the full image
static void do_noise_full(void * ptr,SDL_Surface * canvas, SDL_Surface * last, int which){
int x,y;
static void do_noise_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int which)
{
int x, y;
for (y = 0; y < last->h; y++){
for (x=0; x < last->w; x++){
for (y = 0; y < last->h; y++)
{
for (x = 0; x < last->w; x++)
{
do_noise_pixel(ptr, which, canvas, last, x, y);
}
}
}
//do the effect for the brush
static void do_noise_brush(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y){
static void do_noise_brush(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
int xx, yy;
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
for (yy = y - noise_RADIUS; yy < y + noise_RADIUS; yy++)
{
for (xx = x - noise_RADIUS; xx < x + noise_RADIUS; xx++)
{
if (api->in_circle(xx - x, yy - y, noise_RADIUS) &&
!api->touched(xx, yy))
if (api->in_circle(xx - x, yy - y, noise_RADIUS) && !api->touched(xx, yy))
{
do_noise_pixel(api, which, canvas, last, xx, yy);
}
@ -180,15 +193,27 @@ static void do_noise_brush(void * ptr, int which, SDL_Surface * canvas, SDL_Surf
// Affect the canvas on drag:
void noise_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect){
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_noise_brush);
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_noise_brush);
api->playsound(noise_snd_effect[which], (x * 255) / canvas->w, 255);
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;
}
update_rect->x = ox - noise_RADIUS;
update_rect->y = oy - noise_RADIUS;
@ -198,11 +223,12 @@ void noise_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void noise_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect){
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
if (mode == MODE_PAINT)
noise_drag(api, which, canvas, last, x, y, x, y, update_rect);
else{
else
{
update_rect->x = 0;
update_rect->y = 0;
update_rect->w = canvas->w;
@ -224,15 +250,19 @@ void noise_shutdown(magic_api * api ATTRIBUTE_UNUSED)
{
//Clean up sounds
int i;
for(i=0; i<noise_NUM_TOOLS; i++){
if(noise_snd_effect[i] != NULL){
for (i = 0; i < noise_NUM_TOOLS; i++)
{
if (noise_snd_effect[i] != NULL)
{
Mix_FreeChunk(noise_snd_effect[i]);
}
}
}
// Record the color from Tux Paint:
void noise_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
void noise_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED)
{
}
@ -242,16 +272,17 @@ int noise_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_
return 0;
}
void noise_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void noise_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void noise_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void noise_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int noise_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_FULLSCREEN|MODE_PAINT);
return (MODE_FULLSCREEN | MODE_PAINT);
}

View file

@ -52,22 +52,19 @@ static void perspective_preview(magic_api * api, int which,
Uint32 perspective_api_version(void);
int perspective_init(magic_api * api);
int perspective_get_tool_count(magic_api * api);
SDL_Surface * perspective_get_icon(magic_api * api, int which);
char * perspective_get_name(magic_api * api, int which);
SDL_Surface *perspective_get_icon(magic_api * api, int which);
char *perspective_get_name(magic_api * api, int which);
char * perspective_get_description(magic_api * api, int which, int mode);
char *perspective_get_description(magic_api * api, int which, int mode);
void perspective_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void perspective_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void perspective_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void perspective_shutdown(magic_api * api);
@ -81,14 +78,15 @@ void perspective_switchout(magic_api * api, int which, int mode, SDL_Surface * c
int perspective_modes(magic_api * api, int which);
int scan_fill(magic_api * api, SDL_Surface * canvas, SDL_Surface * srfc,int x,int y, int fill_edge, int fill_tile, int size, Uint32 color);
int scan_fill(magic_api * api, SDL_Surface * canvas, SDL_Surface * srfc, int x, int y, int fill_edge, int fill_tile,
int size, Uint32 color);
void perspective_line(void * ptr_to_api, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
void perspective_line(void *ptr_to_api, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
static const int perspective_AMOUNT= 300;
static const int perspective_AMOUNT = 300;
static const int perspective_RADIUS = 16;
static const double perspective_SHARPEN = 1.0;
Uint8 perspective_r, perspective_g, perspective_b;
@ -111,13 +109,15 @@ float top_advc_x, right_advc_x, bottom_advc_x, left_advc_x;
float top_advc_y, right_advc_y, bottom_advc_y, left_advc_y;
enum {
enum
{
TOOL_PERSPECTIVE,
TOOL_ZOOM,
perspective_NUM_TOOLS
};
enum {
enum
{
TOP_LEFT,
TOP_RIGHT,
BOTTOM_RIGHT,
@ -126,28 +126,28 @@ enum {
/* A copy of canvas at switchin, will be used to draw from it as snapshot changes at each click */
static SDL_Surface * canvas_back;
static SDL_Surface *canvas_back;
static Mix_Chunk * perspective_snd_effect[perspective_NUM_TOOLS + 1];
static Mix_Chunk *perspective_snd_effect[perspective_NUM_TOOLS + 1];
const char * perspective_snd_filenames[perspective_NUM_TOOLS + 1] = {
const char *perspective_snd_filenames[perspective_NUM_TOOLS + 1] = {
"perspective.ogg",
"zoom_up.ogg",
"zoom_down.ogg",
};
const char * perspective_icon_filenames[perspective_NUM_TOOLS] = {
const char *perspective_icon_filenames[perspective_NUM_TOOLS] = {
"perspective.png",
"zoom.png",
};
const char * perspective_names[perspective_NUM_TOOLS] = {
const char *perspective_names[perspective_NUM_TOOLS] = {
gettext_noop("Perspective"),
gettext_noop("Zoom"),
};
const char * perspective_descs[perspective_NUM_TOOLS] = {
const char *perspective_descs[perspective_NUM_TOOLS] = {
gettext_noop("Click on the corners and drag where you want to stretch the picture."),
@ -156,45 +156,57 @@ const char * perspective_descs[perspective_NUM_TOOLS] = {
};
Uint32 perspective_api_version(void) { return(TP_MAGIC_API_VERSION); }
Uint32 perspective_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
//Load sounds
int perspective_init(magic_api * api){
int perspective_init(magic_api * api)
{
int i;
char fname[1024];
for (i = 0; i <= perspective_NUM_TOOLS; i++){
for (i = 0; i <= perspective_NUM_TOOLS; i++)
{
snprintf(fname, sizeof(fname), "%s/sounds/magic/%s", api->data_directory, perspective_snd_filenames[i]);
perspective_snd_effect[i] = Mix_LoadWAV(fname);
}
return(1);
return (1);
}
int perspective_get_tool_count(magic_api * api ATTRIBUTE_UNUSED){
return(perspective_NUM_TOOLS);
int perspective_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return (perspective_NUM_TOOLS);
}
// Load our icons:
SDL_Surface * perspective_get_icon(magic_api * api, int which){
SDL_Surface *perspective_get_icon(magic_api * api, int which)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, perspective_icon_filenames[which]);
return(IMG_Load(fname));
return (IMG_Load(fname));
}
// Return our names, localized:
char * perspective_get_name(magic_api * api ATTRIBUTE_UNUSED, int which){
return(strdup(gettext_noop(perspective_names[which])));
char *perspective_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
{
return (strdup(gettext_noop(perspective_names[which])));
}
// Return our descriptions, localized:
char * perspective_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED){
return(strdup(gettext_noop(perspective_descs[which])));
char *perspective_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
{
return (strdup(gettext_noop(perspective_descs[which])));
}
// Affect the canvas on drag:
void perspective_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, int x, int y,
SDL_Rect * update_rect){
SDL_Rect * update_rect)
{
switch (which)
{
case TOOL_PERSPECTIVE:
@ -232,22 +244,25 @@ void perspective_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_BlitSurface(canvas_back, NULL, canvas, NULL);
perspective_preview( api, which,
canvas , last,
x, y , update_rect , 2.0);
perspective_preview(api, which, canvas, last, x, y, update_rect, 2.0);
/* Draw a square and the current shape relative to it as a visual reference */
/* square */
api->line(api, which, canvas, last, otop_left_x, otop_left_y, otop_right_x, otop_right_y, 1, perspective_line);
api->line(api, which, canvas, last, otop_left_x, otop_left_y, obottom_left_x, obottom_left_y, 1, perspective_line);
api->line(api, which, canvas, last, obottom_left_x, obottom_left_y, obottom_right_x, obottom_right_y, 1, perspective_line);
api->line(api, which, canvas, last, obottom_right_x, obottom_right_y, otop_right_x, otop_right_y, 1, perspective_line);
api->line(api, which, canvas, last, otop_left_x, otop_left_y, obottom_left_x, obottom_left_y, 1,
perspective_line);
api->line(api, which, canvas, last, obottom_left_x, obottom_left_y, obottom_right_x, obottom_right_y, 1,
perspective_line);
api->line(api, which, canvas, last, obottom_right_x, obottom_right_y, otop_right_x, otop_right_y, 1,
perspective_line);
/* shape */
api->line(api, which, canvas, last, top_left_x, top_left_y, top_right_x, top_right_y, 1, perspective_line);
api->line(api, which, canvas, last, top_left_x, top_left_y, bottom_left_x, bottom_left_y, 1, perspective_line);
api->line(api, which, canvas, last, bottom_left_x, bottom_left_y, bottom_right_x, bottom_right_y, 1, perspective_line);
api->line(api, which, canvas, last, bottom_right_x, bottom_right_y, top_right_x, top_right_y, 1, perspective_line);
api->line(api, which, canvas, last, bottom_left_x, bottom_left_y, bottom_right_x, bottom_right_y, 1,
perspective_line);
api->line(api, which, canvas, last, bottom_right_x, bottom_right_y, top_right_x, top_right_y, 1,
perspective_line);
@ -281,11 +296,9 @@ void perspective_drag(magic_api * api, int which, SDL_Surface * canvas,
top_left_y = top_right_y = canvas->h / 2 - y_distance / 2;
bottom_left_y = bottom_right_y = canvas->h / 2 + y_distance / 2;
perspective_preview( api, which,
canvas , last,
x, y , update_rect , 2.0);
perspective_preview(api, which, canvas, last, x, y, update_rect, 2.0);
update_rect->x = update_rect->y =0;
update_rect->x = update_rect->y = 0;
update_rect->w = canvas->w;
update_rect->h = canvas->h;
}
@ -303,10 +316,11 @@ void perspective_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void perspective_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect){
switch(which)
{case TOOL_PERSPECTIVE:
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
switch (which)
{
case TOOL_PERSPECTIVE:
{
if (x < canvas->w / 2)
@ -349,22 +363,20 @@ void perspective_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
// Affect the canvas on release:
void perspective_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
switch (which)
{
case TOOL_PERSPECTIVE:{
perspective_preview( api, which,
canvas , last,
x, y , update_rect , 0.5);
case TOOL_PERSPECTIVE:
{
perspective_preview(api, which, canvas, last, x, y, update_rect, 0.5);
}
break;
case TOOL_ZOOM:
{
SDL_Surface * aux_surf;
SDL_Surface * scaled_surf;
SDL_Surface *aux_surf;
SDL_Surface *scaled_surf;
update_rect->x = update_rect->y = 0;
update_rect->w = canvas->w;
@ -373,7 +385,7 @@ void perspective_release(magic_api * api, int which,
SDL_FillRect(canvas, update_rect, SDL_MapRGB(canvas->format, perspective_r, perspective_g, perspective_b));
if(new_h < canvas->h)
if (new_h < canvas->h)
{
scaled_surf = api->scale(canvas_back, new_w, new_h, 0);
update_rect->x = (canvas->w - new_w) / 2;
@ -385,6 +397,7 @@ void perspective_release(magic_api * api, int which,
else
{
int aux_x, aux_y, aux_h, aux_w;
aux_h = canvas->h * canvas->h / new_h;
aux_w = canvas->w * aux_h / canvas->h;
aux_x = canvas->w / 2 - aux_w / 2;
@ -399,9 +412,7 @@ void perspective_release(magic_api * api, int which,
aux_w,
aux_h,
canvas->format->BitsPerPixel,
canvas->format->Rmask,
canvas->format->Gmask,
canvas->format->Bmask, 0);
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, 0);
SDL_BlitSurface(canvas_back, update_rect, aux_surf, NULL);
scaled_surf = api->scale(aux_surf, canvas->w, canvas->h, 0);
@ -454,17 +465,17 @@ void perspective_preview(magic_api * api, int which ATTRIBUTE_UNUSED,
center_ofset_x = (otop_left_x - top_left_x) * 2;
center_ofset_y = (otop_left_y - top_left_y) * 2;
for(i = 0; i < canvas->w; i += step)
for (i = 0; i < canvas->w; i += step)
{
ax = (float)top_advc_x * i;
ay = (float)top_advc_y * i;
bx = (float)bottom_advc_x * i + (bottom_left_x - top_left_x) * 2 ;
by = (float)bottom_advc_y * i + (bottom_left_y - top_left_y) * 2;
ax = (float)top_advc_x *i;
ay = (float)top_advc_y *i;
bx = (float)bottom_advc_x *i + (bottom_left_x - top_left_x) * 2;
by = (float)bottom_advc_y *i + (bottom_left_y - top_left_y) * 2;
for(j = 0; j < canvas->h; j += step)
for (j = 0; j < canvas->h; j += step)
{
dx = (float)(bx - ax) / canvas->h * j;
dy = (float)(by - ay)/ canvas->h * j;
dy = (float)(by - ay) / canvas->h * j;
api->putpixel(canvas, ax + dx - center_ofset_x, ay + dy - center_ofset_y, api->getpixel(canvas_back, i, j));
}
@ -476,8 +487,11 @@ void perspective_shutdown(magic_api * api ATTRIBUTE_UNUSED)
{
//Clean up sounds
int i;
for(i=0; i<perspective_NUM_TOOLS + 1; i++){
if(perspective_snd_effect[i] != NULL){
for (i = 0; i < perspective_NUM_TOOLS + 1; i++)
{
if (perspective_snd_effect[i] != NULL)
{
Mix_FreeChunk(perspective_snd_effect[i]);
}
}
@ -497,9 +511,11 @@ int perspective_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTR
return 1;
}
void perspective_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas)
void perspective_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas)
{
Uint32 amask;
new_w = canvas->w;
new_h = canvas->h;
@ -513,36 +529,36 @@ void perspective_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_
black = SDL_MapRGBA(canvas->format, 0, 0, 0, 0);
white = SDL_MapRGBA(canvas->format, 255, 255, 255, 0);
amask = ~(canvas->format->Rmask |
canvas->format->Gmask |
canvas->format->Bmask);
amask = ~(canvas->format->Rmask | canvas->format->Gmask | canvas->format->Bmask);
canvas_back = SDL_CreateRGBSurface(SDL_SWSURFACE,
canvas->w,
canvas->h,
canvas->format->BitsPerPixel,
canvas->format->Rmask,
canvas->format->Gmask,
canvas->format->Bmask, amask);
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, amask);
SDL_BlitSurface(canvas, NULL, canvas_back, NULL);
}
void perspective_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void perspective_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
SDL_FreeSurface(canvas_back);
}
int perspective_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_PAINT_WITH_PREVIEW);
return (MODE_PAINT_WITH_PREVIEW);
}
void perspective_line(void * ptr_to_api, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
void perspective_line(void *ptr_to_api, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
{
magic_api * api = (magic_api *) ptr_to_api;
magic_api *api = (magic_api *) ptr_to_api;
dash += 1;
if (dash > 8) dash = 0;
if (dash > 8)
dash = 0;
if (dash > 3)
api->putpixel(canvas, x, y, black);
else

View file

@ -40,49 +40,48 @@
//else not whole the screen will be affected
static Mix_Chunk * puzzle_snd;
static int puzzle_gcd=0; //length of side of each rectangle; 0 is temporary value.
static Mix_Chunk *puzzle_snd;
static int puzzle_gcd = 0; //length of side of each rectangle; 0 is temporary value.
// static int puzzle_rect_q=4; //quantity of rectangles when using paint mode. Must be an odd value - but it's even!
static int rects_w, rects_h;
SDL_Surface * canvas_backup;
SDL_Surface *canvas_backup;
Uint32 puzzle_api_version(void) ;
Uint32 puzzle_api_version(void);
int puzzle_init(magic_api * api);
int puzzle_get_tool_count(magic_api * api);
SDL_Surface * puzzle_get_icon(magic_api * api, int which);
char * puzzle_get_name(magic_api * api, int which);
char * puzzle_get_description(magic_api * api, int which, int mode);
SDL_Surface *puzzle_get_icon(magic_api * api, int which);
char *puzzle_get_name(magic_api * api, int which);
char *puzzle_get_description(magic_api * api, int which, int mode);
void puzzle_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void puzzle_shutdown(magic_api * api);
void puzzle_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int puzzle_requires_colors(magic_api * api, int which);
void puzzle_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void puzzle_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int puzzle_modes(magic_api * api, int which);
static void puzzle_draw(void * ptr, int which_tool,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
static void puzzle_draw(void *ptr, int which_tool, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
void puzzle_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void puzzle_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
int gcd(int a, int b);
Uint32 puzzle_api_version(void) { return(TP_MAGIC_API_VERSION); }
Uint32 puzzle_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
int puzzle_init(magic_api * api)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/sounds/magic/puzzle.wav",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/sounds/magic/puzzle.wav", api->data_directory);
puzzle_snd = Mix_LoadWAV(fname);
return 1 ;
return 1;
}
int puzzle_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
@ -90,25 +89,24 @@ int puzzle_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
return 1;
}
SDL_Surface * puzzle_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
SDL_Surface *puzzle_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/images/magic/puzzle.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/puzzle.png", api->data_directory);
return(IMG_Load(fname));
return (IMG_Load(fname));
}
char * puzzle_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
char *puzzle_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(strdup(gettext_noop("Puzzle")));
return (strdup(gettext_noop("Puzzle")));
}
char * puzzle_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode)
char *puzzle_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode)
{
if (mode==MODE_PAINT)
if (mode == MODE_PAINT)
return strdup(gettext_noop("Click the part of your picture where would you like a puzzle."));
return strdup(gettext_noop("Click to make a puzzle in fullscreen mode."));
}
@ -125,7 +123,8 @@ void puzzle_shutdown(magic_api * api ATTRIBUTE_UNUSED)
Mix_FreeChunk(puzzle_snd);
}
void puzzle_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
void puzzle_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED)
{
}
@ -136,19 +135,24 @@ int puzzle_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE
int gcd(int a, int b) //greatest common divisor
{
if (b==0) return a;
return gcd(b, a%b);
if (b == 0)
return a;
return gcd(b, a % b);
}
void puzzle_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas)
void puzzle_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas)
{
puzzle_gcd=RATIO*gcd(canvas->w, canvas->h);
rects_w=(unsigned int)canvas->w/puzzle_gcd;
rects_h=(unsigned int)canvas->h/puzzle_gcd;
canvas_backup = SDL_CreateRGBSurface(SDL_SWSURFACE,canvas->w, canvas->h, canvas->format->BitsPerPixel, canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
puzzle_gcd = RATIO * gcd(canvas->w, canvas->h);
rects_w = (unsigned int)canvas->w / puzzle_gcd;
rects_h = (unsigned int)canvas->h / puzzle_gcd;
canvas_backup =
SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h, canvas->format->BitsPerPixel, canvas->format->Rmask,
canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
}
void puzzle_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void puzzle_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
SDL_FreeSurface(canvas_backup);
canvas_backup = NULL;
@ -156,15 +160,15 @@ void puzzle_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUS
int puzzle_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_PAINT);
return (MODE_PAINT);
}
static void puzzle_draw(void * ptr, int which_tool ATTRIBUTE_UNUSED,
static void puzzle_draw(void *ptr, int which_tool ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
{
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
Uint8 r; //r - random value
SDL_Rect rect_this, rect_that;
@ -178,38 +182,38 @@ static void puzzle_draw(void * ptr, int which_tool ATTRIBUTE_UNUSED,
{
srand(rand());
r=rand()%4;
r = rand() % 4;
rect_that.x=x;
rect_that.y=y;
rect_that.x = x;
rect_that.y = y;
switch(r)
switch (r)
{
case 0: //upper
if (y>puzzle_gcd)
rect_that.y=y-puzzle_gcd;
if (y > puzzle_gcd)
rect_that.y = y - puzzle_gcd;
break;
case 1: //right
if (x<canvas->w-puzzle_gcd)
rect_that.x=x-puzzle_gcd;
if (x < canvas->w - puzzle_gcd)
rect_that.x = x - puzzle_gcd;
break;
case 2: //lower
if (y<canvas->h-puzzle_gcd)
rect_that.y=y-puzzle_gcd;
if (y < canvas->h - puzzle_gcd)
rect_that.y = y - puzzle_gcd;
break;
case 3: //left
if (x>puzzle_gcd)
rect_that.x=x-puzzle_gcd;
if (x > puzzle_gcd)
rect_that.x = x - puzzle_gcd;
break;
}
rect_this.x=x;
rect_this.y=y;
rect_this.h=rect_this.w=puzzle_gcd;
rect_that.h=rect_that.w=puzzle_gcd;
rect_this.x = x;
rect_this.y = y;
rect_this.h = rect_this.w = puzzle_gcd;
rect_that.h = rect_that.w = puzzle_gcd;
SDL_BlitSurface(canvas, &rect_this, canvas, &rect_that);
@ -222,23 +226,21 @@ void puzzle_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, int x, int y,
SDL_Rect * update_rect)
{
puzzle_draw(api, which, canvas, last, x-puzzle_gcd/2, y-puzzle_gcd/2);
puzzle_draw(api, which, canvas, last, x - puzzle_gcd / 2, y - puzzle_gcd / 2);
puzzle_draw(api, which, canvas, last, x-1.5*puzzle_gcd/2, y-puzzle_gcd/2);
puzzle_draw(api, which, canvas, last, x+0.5*puzzle_gcd, y-puzzle_gcd/2);
puzzle_draw(api, which, canvas, last, x-puzzle_gcd/2, y-1.5*puzzle_gcd);
puzzle_draw(api, which, canvas, last, x-puzzle_gcd/2, y+0.5*puzzle_gcd);
puzzle_draw(api, which, canvas, last, x - 1.5 * puzzle_gcd / 2, y - puzzle_gcd / 2);
puzzle_draw(api, which, canvas, last, x + 0.5 * puzzle_gcd, y - puzzle_gcd / 2);
puzzle_draw(api, which, canvas, last, x - puzzle_gcd / 2, y - 1.5 * puzzle_gcd);
puzzle_draw(api, which, canvas, last, x - puzzle_gcd / 2, y + 0.5 * puzzle_gcd);
update_rect->x=0;
update_rect->y=0;
update_rect->h=canvas->h;
update_rect->w=canvas->w;
update_rect->x = 0;
update_rect->y = 0;
update_rect->h = canvas->h;
update_rect->w = canvas->w;
}
void puzzle_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
puzzle_drag(api, which, canvas, last, x, y, x, y, update_rect);
}

View file

@ -21,66 +21,64 @@
#define SEG_RIGHT_TOP_BOTTOM (SEG_RIGHT | SEG_TOP | SEG_BOTTOM)
#define SEG_LEFT_RIGHT_TOP_BOTTOM (SEG_LEFT | SEG_RIGHT | SEG_TOP | SEG_BOTTOM)
Mix_Chunk * rails_snd;
Mix_Chunk *rails_snd;
unsigned int img_w, img_h;
unsigned int rails_segments_x, rails_segments_y; //how many segments do we have?
static int rails_math_ceil(int x, int y); //ceil() in cstdlib returns float and is relative slow, so we'll use our one
static Uint8 * rails_status_of_segments; //a place to store an info about bitmap used for selected segment
static char ** rails_images; //the pathes to all the images needed
static Uint8 *rails_status_of_segments; //a place to store an info about bitmap used for selected segment
static char **rails_images; //the pathes to all the images needed
static unsigned int rails_segment_modified; //which segment was modified this time?
static unsigned int rails_segment_modified_last =0; //which segment was last modified
static unsigned int rails_segment_to_add =0; //a segment that should be added to solve corner joints
static unsigned int rails_segment_modified_last = 0; //which segment was last modified
static unsigned int rails_segment_to_add = 0; //a segment that should be added to solve corner joints
static SDL_Rect modification_rect;
static SDL_Surface * canvas_backup;
static SDL_Surface *canvas_backup;
// Housekeeping functions
SDL_Surface * rails_one, * rails_three, * rails_four, * rails_corner;
SDL_Surface *rails_one, *rails_three, *rails_four, *rails_corner;
Uint32 rails_api_version(void);
int rails_modes(magic_api * api, int which);
void rails_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int rails_init(magic_api * api);
int rails_get_tool_count(magic_api * api);
SDL_Surface * rails_get_icon(magic_api * api, int which);
char * rails_get_name(magic_api * api, int which);
char * rails_get_description(magic_api * api, int which, int mode);
SDL_Surface *rails_get_icon(magic_api * api, int which);
char *rails_get_name(magic_api * api, int which);
char *rails_get_description(magic_api * api, int which, int mode);
int rails_requires_colors(magic_api * api, int which);
void rails_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);
void rails_shutdown(magic_api * api);
void rails_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void rails_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
static int rails_math_ceil(int x, int y);
inline unsigned int rails_get_segment(int x, int y);
inline void rails_extract_coords_from_segment(unsigned int segment, Sint16 * x, Sint16 * y);
static void rails_flip(void * ptr, SDL_Surface * dest, SDL_Surface * src);
static void rails_flip_flop(void * ptr, SDL_Surface * dest, SDL_Surface * src);
static void rails_rotate (void * ptr, SDL_Surface * dest, SDL_Surface * src, unsigned int direction);
static void rails_flip(void *ptr, SDL_Surface * dest, SDL_Surface * src);
static void rails_flip_flop(void *ptr, SDL_Surface * dest, SDL_Surface * src);
static void rails_rotate(void *ptr, SDL_Surface * dest, SDL_Surface * src, unsigned int direction);
void rails_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);
static Uint8 rails_select_image(Uint16 segment);
static void rails_draw(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
static void rails_draw(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
int x, int y, unsigned int segment);
static void rails_draw_wrapper(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
int x, int y);
static void rails_draw_wrapper(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
void rails_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);
Uint32 rails_api_version(void)
{
return(TP_MAGIC_API_VERSION);
return (TP_MAGIC_API_VERSION);
}
int rails_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_PAINT);
return (MODE_PAINT);
}
void rails_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
void rails_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED)
{
}
@ -89,20 +87,20 @@ int rails_init(magic_api * api)
char fname[1024];
Uint8 i; //is always < 3, so Uint8 seems to be a good idea
rails_images=(char **)malloc(sizeof(char *)*4);
rails_images = (char **)malloc(sizeof(char *) * 4);
for (i = 0; i < 4; i++)
rails_images[i]=(char *)malloc(sizeof(char)*1024);
rails_images[i] = (char *)malloc(sizeof(char) * 1024);
snprintf(rails_images[0], 1024*sizeof(char), "%s/images/magic/rails_one.png", api->data_directory);
snprintf(rails_images[1], 1024*sizeof(char), "%s/images/magic/rails_three.png", api->data_directory);
snprintf(rails_images[2], 1024*sizeof(char), "%s/images/magic/rails_four.png", api->data_directory);
snprintf(rails_images[3], 1024*sizeof(char), "%s/images/magic/rails_corner.png", api->data_directory);
snprintf(rails_images[0], 1024 * sizeof(char), "%s/images/magic/rails_one.png", api->data_directory);
snprintf(rails_images[1], 1024 * sizeof(char), "%s/images/magic/rails_three.png", api->data_directory);
snprintf(rails_images[2], 1024 * sizeof(char), "%s/images/magic/rails_four.png", api->data_directory);
snprintf(rails_images[3], 1024 * sizeof(char), "%s/images/magic/rails_corner.png", api->data_directory);
rails_one=IMG_Load(rails_images[0]);
rails_three=IMG_Load(rails_images[1]);
rails_four=IMG_Load(rails_images[2]);
rails_corner=IMG_Load(rails_images[3]);
rails_one = IMG_Load(rails_images[0]);
rails_three = IMG_Load(rails_images[1]);
rails_four = IMG_Load(rails_images[2]);
rails_corner = IMG_Load(rails_images[3]);
img_w = rails_one->w;
img_h = rails_one->h;
@ -110,7 +108,7 @@ int rails_init(magic_api * api)
snprintf(fname, sizeof(fname), "%s/sounds/magic/rails.wav", api->data_directory);
rails_snd = Mix_LoadWAV(fname);
return(1);
return (1);
}
int rails_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
@ -118,21 +116,29 @@ int rails_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
return 1;
}
SDL_Surface * rails_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
SDL_Surface *rails_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/images/magic/rails.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/rails.png", api->data_directory);
return(IMG_Load(fname));
return (IMG_Load(fname));
}
char * rails_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) { return strdup(gettext_noop("Rails")); }
char *rails_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return strdup(gettext_noop("Rails"));
}
char * rails_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED) { return strdup(gettext_noop("Click and drag to draw train track rails on your picture.")); }
char *rails_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return strdup(gettext_noop("Click and drag to draw train track rails on your picture."));
}
int rails_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) { return 0;}
int rails_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 0;
}
void rails_release(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * snapshot ATTRIBUTE_UNUSED,
@ -144,7 +150,7 @@ void rails_shutdown(magic_api * api ATTRIBUTE_UNUSED)
{
Uint8 i;
if (rails_snd!=NULL)
if (rails_snd != NULL)
Mix_FreeChunk(rails_snd);
SDL_FreeSurface(rails_one);
SDL_FreeSurface(rails_three);
@ -159,21 +165,24 @@ void rails_shutdown(magic_api * api ATTRIBUTE_UNUSED)
free(rails_status_of_segments);
}
void rails_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas)
void rails_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas)
{
//we've to compute the quantity of segments in each direction
canvas_backup=SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
canvas_backup = SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask,
canvas->format->Amask);
SDL_BlitSurface(canvas, NULL, canvas_backup, NULL);
rails_segments_x=rails_math_ceil(canvas->w,img_w);
rails_segments_y=rails_math_ceil(canvas->h,img_h);
rails_segments_x = rails_math_ceil(canvas->w, img_w);
rails_segments_y = rails_math_ceil(canvas->h, img_h);
//status_of_segments[0] will not be used, we write in rails_status_of_segments[1 to segments_x*segments_y]
rails_status_of_segments=(Uint8 *)calloc(rails_segments_x*rails_segments_y + 1, sizeof(Uint8));
rails_status_of_segments = (Uint8 *) calloc(rails_segments_x * rails_segments_y + 1, sizeof(Uint8));
}
void rails_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void rails_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
if (rails_status_of_segments != NULL)
{
@ -187,74 +196,78 @@ void rails_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSE
static int rails_math_ceil(int x, int y)
{
int temp;
temp=(int)x/y;
if (x%y)
return temp+1;
else return temp;
temp = (int)x / y;
if (x % y)
return temp + 1;
else
return temp;
}
inline unsigned int rails_get_segment(int x, int y)
{
int xx; //segments are numerated just like pixels
int yy; //in computer graphics: left upper (=1), ... ,right upper,
//left bottom, ... , right bottom
xx=rails_math_ceil(x, img_w);
yy=rails_math_ceil(y, img_h);
return (yy-1)*rails_segments_x+xx;
//left bottom, ... , right bottom
xx = rails_math_ceil(x, img_w);
yy = rails_math_ceil(y, img_h);
return (yy - 1) * rails_segments_x + xx;
}
inline void rails_extract_coords_from_segment(unsigned int segment, Sint16 * x, Sint16 * y)
{ //extracts the coords of the beginning and the segment
*x=((segment%rails_segments_x)-1)*img_w; //useful to set update_rect as small as possible
*y=(int)(segment/rails_segments_x)*img_h;
*x = ((segment % rails_segments_x) - 1) * img_w; //useful to set update_rect as small as possible
*y = (int)(segment / rails_segments_x) * img_h;
}
static void rails_flip(void * ptr, SDL_Surface * dest, SDL_Surface * src)
static void rails_flip(void *ptr, SDL_Surface * dest, SDL_Surface * src)
{
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
Sint16 x, y;
for (x=0; x<dest->w; x++)
for (y=0; y<dest->h; y++)
api->putpixel(dest, x, y, api->getpixel(src, x, src->h-y-1));
for (x = 0; x < dest->w; x++)
for (y = 0; y < dest->h; y++)
api->putpixel(dest, x, y, api->getpixel(src, x, src->h - y - 1));
}
static void rails_flip_flop(void * ptr, SDL_Surface * dest, SDL_Surface * src)
static void rails_flip_flop(void *ptr, SDL_Surface * dest, SDL_Surface * src)
{
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
Sint16 x, y;
for (x=0; x<dest->w; x++)
for (y=0; y<dest->h; y++)
for (x = 0; x < dest->w; x++)
for (y = 0; y < dest->h; y++)
api->putpixel(dest, x, y, api->getpixel(src, y, x));
}
static void rails_rotate (void * ptr, SDL_Surface * dest, SDL_Surface * src, unsigned int direction)
static void rails_rotate(void *ptr, SDL_Surface * dest, SDL_Surface * src, unsigned int direction)
//src and dest must have same size
{
magic_api * api = (magic_api *) ptr;
Sint16 x,y;
magic_api *api = (magic_api *) ptr;
Sint16 x, y;
if (direction) //rotate -90 degs
{
for (x = 0; x<dest->w; x++)
for (y =0; y<dest->h; y++)
api->putpixel(dest, x, y, api->getpixel(src, y, src->w-x-1));
for (x = 0; x < dest->w; x++)
for (y = 0; y < dest->h; y++)
api->putpixel(dest, x, y, api->getpixel(src, y, src->w - x - 1));
}
else //rotate +90 degs
{
for (x=0; x<dest->w; x++)
for (y=0; y<dest->h; y++)
api->putpixel(dest,x,y,api->getpixel(src,src->h-y-1,x));
for (x = 0; x < dest->w; x++)
for (y = 0; y < dest->h; y++)
api->putpixel(dest, x, y, api->getpixel(src, src->h - y - 1, x));
}
}
void rails_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
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)
{
rails_segment_modified_last = 0;
rails_drag(api, which, canvas, snapshot, x, y, x, y, update_rect);
@ -264,12 +277,12 @@ static Uint8 rails_select_image(Uint16 segment)
{
int take_up, take_down;
int val_up, val_down, val_left, val_right;
int from_top=0, from_bottom=0, from_left = 0, from_right = 0;
int from_top_right=0, from_top_left=0, from_bottom_right=0, from_bottom_left = 0;
int TOP=0, BOTTOM=0, LEFT=0, RIGHT = 0;
int from_top = 0, from_bottom = 0, from_left = 0, from_right = 0;
int from_top_right = 0, from_top_left = 0, from_bottom_right = 0, from_bottom_left = 0;
int TOP = 0, BOTTOM = 0, LEFT = 0, RIGHT = 0;
//Checking from were we come...
if (rails_segment_modified_last>0)
if (rails_segment_modified_last > 0)
{
if (segment == rails_segment_modified_last + 1)
from_left = 1;
@ -305,7 +318,7 @@ static Uint8 rails_select_image(Uint16 segment)
if (segment == rails_segment_modified_last - rails_segments_x + 1)
{
from_bottom_left = 1;
rails_segment_to_add = segment -1;
rails_segment_to_add = segment - 1;
}
}
@ -313,29 +326,38 @@ static Uint8 rails_select_image(Uint16 segment)
take_up=segment-rails_segments_x;
if (take_up<=0) val_up = SEG_NONE;
else val_up = rails_status_of_segments[take_up];
take_up = segment - rails_segments_x;
if (take_up <= 0)
val_up = SEG_NONE;
else
val_up = rails_status_of_segments[take_up];
take_down=segment+rails_segments_x;
if (take_down>(signed)(rails_segments_x*rails_segments_y)) val_down = SEG_NONE;
else val_down = rails_status_of_segments[take_down];
take_down = segment + rails_segments_x;
if (take_down > (signed)(rails_segments_x * rails_segments_y))
val_down = SEG_NONE;
else
val_down = rails_status_of_segments[take_down];
if ((segment%rails_segments_x)==1) val_left=SEG_NONE;
else val_left = rails_status_of_segments[segment-1];
if ((segment % rails_segments_x) == 1)
val_left = SEG_NONE;
else
val_left = rails_status_of_segments[segment - 1];
if ((segment%rails_segments_x)==0) val_right=SEG_NONE;
else val_right = rails_status_of_segments[segment+1];
if ((segment % rails_segments_x) == 0)
val_right = SEG_NONE;
else
val_right = rails_status_of_segments[segment + 1];
if ( from_left || (val_left & SEG_RIGHT) || from_bottom_left)
if (from_left || (val_left & SEG_RIGHT) || from_bottom_left)
{
LEFT = 1;}
if ( from_right || (val_right & SEG_LEFT) || from_top_right)
RIGHT=1;
if ( from_top || (val_up & SEG_BOTTOM) || from_top_left)
TOP=1;
LEFT = 1;
}
if (from_right || (val_right & SEG_LEFT) || from_top_right)
RIGHT = 1;
if (from_top || (val_up & SEG_BOTTOM) || from_top_left)
TOP = 1;
if (from_bottom || (val_down & SEG_TOP) || from_bottom_right)
BOTTOM=1;
BOTTOM = 1;
if (TOP && BOTTOM && LEFT && RIGHT)
@ -348,19 +370,19 @@ static Uint8 rails_select_image(Uint16 segment)
return SEG_LEFT_TOP_BOTTOM;
if (TOP && BOTTOM && RIGHT)
return SEG_RIGHT_TOP_BOTTOM;
if (LEFT &&RIGHT)
if (LEFT && RIGHT)
return SEG_LEFT_RIGHT;
if (TOP&&BOTTOM)
if (TOP && BOTTOM)
return SEG_TOP_BOTTOM;
if (LEFT&&TOP)
if (LEFT && TOP)
return SEG_LEFT_TOP;
if (LEFT&&BOTTOM)
if (LEFT && BOTTOM)
return SEG_LEFT_BOTTOM;
if (RIGHT&&TOP)
if (RIGHT && TOP)
return SEG_RIGHT_TOP;
if (RIGHT&&BOTTOM)
if (RIGHT && BOTTOM)
return SEG_RIGHT_BOTTOM;
if (LEFT|RIGHT)
if (LEFT | RIGHT)
return SEG_LEFT_RIGHT;
return SEG_TOP_BOTTOM;
@ -368,40 +390,42 @@ static Uint8 rails_select_image(Uint16 segment)
}
static void rails_draw(void * ptr, int which ATTRIBUTE_UNUSED, ATTRIBUTE_UNUSED SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
int x, int y ATTRIBUTE_UNUSED, unsigned int segment)
static void rails_draw(void *ptr, int which ATTRIBUTE_UNUSED, ATTRIBUTE_UNUSED SDL_Surface * canvas,
SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y ATTRIBUTE_UNUSED, unsigned int segment)
{
magic_api * api = (magic_api *) ptr;
SDL_Surface * result, * temp;
magic_api *api = (magic_api *) ptr;
SDL_Surface *result, *temp;
Uint8 image;
unsigned int use_temp;
use_temp=0;
if (segment>rails_segments_x*rails_segments_y)
use_temp = 0;
if (segment > rails_segments_x * rails_segments_y)
return;
//modification_rect.x and modification_rect.y are set by function
rails_extract_coords_from_segment(segment, &modification_rect.x, &modification_rect.y);
modification_rect.h=img_w;
modification_rect.w=img_h;
modification_rect.h = img_w;
modification_rect.w = img_h;
image=rails_select_image(segment); //select the image to display
image = rails_select_image(segment); //select the image to display
if (rails_status_of_segments[segment] == image)
return;
rails_status_of_segments[segment]=image; //and write it to global table
rails_status_of_segments[segment] = image; //and write it to global table
result=SDL_CreateRGBSurface(SDL_SWSURFACE, img_w, img_h, rails_one->format->BitsPerPixel,
rails_one->format->Rmask, rails_one->format->Gmask, rails_one->format->Bmask, rails_one->format->Amask);
result = SDL_CreateRGBSurface(SDL_SWSURFACE, img_w, img_h, rails_one->format->BitsPerPixel,
rails_one->format->Rmask, rails_one->format->Gmask, rails_one->format->Bmask,
rails_one->format->Amask);
temp=SDL_CreateRGBSurface(SDL_SWSURFACE, img_w, img_h, rails_one->format->BitsPerPixel,
rails_one->format->Rmask, rails_one->format->Gmask, rails_one->format->Bmask, rails_one->format->Amask);
temp = SDL_CreateRGBSurface(SDL_SWSURFACE, img_w, img_h, rails_one->format->BitsPerPixel,
rails_one->format->Rmask, rails_one->format->Gmask, rails_one->format->Bmask,
rails_one->format->Amask);
SDL_BlitSurface(canvas_backup, &modification_rect, result, NULL);
switch(image)
switch (image)
{
case 0:
case SEG_TOP_BOTTOM:
@ -412,7 +436,7 @@ static void rails_draw(void * ptr, int which ATTRIBUTE_UNUSED, ATTRIBUTE_UNUSED
case SEG_LEFT_RIGHT:
SDL_BlitSurface(canvas_backup, &modification_rect, result, NULL);
rails_rotate(api, temp, rails_one, 1);
use_temp=1;
use_temp = 1;
break;
case SEG_LEFT_RIGHT_TOP_BOTTOM:
@ -426,17 +450,17 @@ static void rails_draw(void * ptr, int which ATTRIBUTE_UNUSED, ATTRIBUTE_UNUSED
case SEG_LEFT_RIGHT_BOTTOM:
rails_flip(api, temp, rails_three);
use_temp=1;
use_temp = 1;
break;
case SEG_LEFT_TOP_BOTTOM:
rails_rotate(api, temp, rails_three, 0);
use_temp=1;
use_temp = 1;
break;
case SEG_RIGHT_TOP_BOTTOM:
rails_rotate(api, temp, rails_three, 1);
use_temp=1;
use_temp = 1;
break;
case SEG_RIGHT_TOP:
@ -445,17 +469,17 @@ static void rails_draw(void * ptr, int which ATTRIBUTE_UNUSED, ATTRIBUTE_UNUSED
case SEG_RIGHT_BOTTOM:
rails_flip(api, temp, rails_corner);
use_temp=1;
use_temp = 1;
break;
case SEG_LEFT_TOP:
rails_rotate(api, temp, rails_corner, 0);
use_temp=1;
use_temp = 1;
break;
case SEG_LEFT_BOTTOM:
rails_flip_flop(api, temp, rails_corner);
use_temp=1;
use_temp = 1;
break;
}
@ -468,57 +492,58 @@ static void rails_draw(void * ptr, int which ATTRIBUTE_UNUSED, ATTRIBUTE_UNUSED
api->playsound(rails_snd, (x * 255) / canvas->w, 255);
}
static void rails_draw_wrapper(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
int x, int y)
static void rails_draw_wrapper(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
rails_segment_modified=rails_get_segment(x,y);
rails_segment_modified = rails_get_segment(x, y);
if ( (rails_segment_modified == rails_segment_modified_last))
if ((rails_segment_modified == rails_segment_modified_last))
return;
if (rails_segment_modified>0)
if (rails_segment_modified > 0)
{
rails_draw((void *) ptr, which, canvas, last, x, y, rails_segment_modified);
rails_draw((void *)ptr, which, canvas, last, x, y, rails_segment_modified);
}
if (rails_segment_modified_last>0)
rails_draw((void *) ptr, which, canvas, last, x, y, rails_segment_modified_last);
if (rails_segment_modified_last > 0)
rails_draw((void *)ptr, which, canvas, last, x, y, rails_segment_modified_last);
if (rails_segment_to_add>0)
if (rails_segment_to_add > 0)
{
rails_draw((void *) ptr, which, canvas, last, x, y, rails_segment_to_add);
rails_draw((void *) ptr, which, canvas, last, x, y, rails_segment_modified_last);
rails_segment_to_add=0;
rails_draw((void *)ptr, which, canvas, last, x, y, rails_segment_to_add);
rails_draw((void *)ptr, which, canvas, last, x, y, rails_segment_modified_last);
rails_segment_to_add = 0;
}
if (rails_segment_modified>0)
rails_segment_modified_last=rails_segment_modified;
if (rails_segment_modified > 0)
rails_segment_modified_last = rails_segment_modified;
}
void rails_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)
{
int start_x, end_x, start_y, end_y, segment_start, segment_end, w, h;
// avoiding to write out of the canvas
if ((x<canvas->w)&&(y<canvas->h)&&(ox<canvas->w)&&(oy<canvas->h)&&((signed)x>0)&&((signed)y>0)&&((signed)ox>0)&&((signed)oy>0))
if ((x < canvas->w) && (y < canvas->h) && (ox < canvas->w) && (oy < canvas->h) && ((signed)x > 0) && ((signed)y > 0)
&& ((signed)ox > 0) && ((signed)oy > 0))
{
api->line((void *) api, which, canvas, snapshot, ox, oy, x, y, img_w/2, rails_draw_wrapper);
api->line((void *)api, which, canvas, snapshot, ox, oy, x, y, img_w / 2, rails_draw_wrapper);
start_x=min(ox,x);
end_x=max(ox,x);
start_y=min(oy,y);
end_y=max(oy,y);
start_x = min(ox, x);
end_x = max(ox, x);
start_y = min(oy, y);
end_y = max(oy, y);
segment_start=rails_get_segment(start_x-img_w, start_y-img_h);
segment_end=rails_get_segment(end_x+img_w,end_y+img_h);
segment_start = rails_get_segment(start_x - img_w, start_y - img_h);
segment_end = rails_get_segment(end_x + img_w, end_y + img_h);
x=((segment_start%rails_segments_x)-1)*img_w;
y=(int)(segment_start/rails_segments_x)*img_h;
w=((segment_end%rails_segments_x)-1)*img_w-x+img_w;
h=(int)(segment_end/rails_segments_x)*img_h-y+img_h;
x = ((segment_start % rails_segments_x) - 1) * img_w;
y = (int)(segment_start / rails_segments_x) * img_h;
w = ((segment_end % rails_segments_x) - 1) * img_w - x + img_w;
h = (int)(segment_end / rails_segments_x) * img_h - y + img_h;
update_rect->x=x;
update_rect->y=y;
update_rect->w=w;
update_rect->h=h;}
update_rect->x = x;
update_rect->y = y;
update_rect->w = w;
update_rect->h = h;
}
}

View file

@ -48,23 +48,27 @@ void rain_click(magic_api *, int, int, SDL_Surface *, SDL_Surface *, int, int, S
static const int rain_SIZE = 30;
static const int rain_AMOUNT = 200;
enum {
enum
{
TOOL_rain,
rain_NUM_TOOLS
};
static Mix_Chunk * rain_snd_effect[rain_NUM_TOOLS];
static Mix_Chunk *rain_snd_effect[rain_NUM_TOOLS];
const char * rain_snd_filenames[rain_NUM_TOOLS] = {
const char *rain_snd_filenames[rain_NUM_TOOLS] = {
"rain.ogg",
};
const char * rain_icon_filenames[rain_NUM_TOOLS] = {
const char *rain_icon_filenames[rain_NUM_TOOLS] = {
"rain.png",
};
const char * rain_names[rain_NUM_TOOLS] = {
const char *rain_names[rain_NUM_TOOLS] = {
gettext_noop("Rain"),
};
const char * rain_descs[rain_NUM_TOOLS][2] = {
const char *rain_descs[rain_NUM_TOOLS][2] = {
{gettext_noop("Click to place a rain drop onto your picture."),
gettext_noop("Click to cover your picture with rain drops."),},
};
@ -72,23 +76,17 @@ const char * rain_descs[rain_NUM_TOOLS][2] = {
Uint32 rain_api_version(void);
int rain_init(magic_api * api);
int rain_get_tool_count(magic_api * api);
SDL_Surface * rain_get_icon(magic_api * api, int which);
char * rain_get_name(magic_api * api, int which);
char * rain_get_description(magic_api * api, int which, int mode);
static void do_rain_drop(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
int x, int y);
static void rain_linecb(void * ptr, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y);
SDL_Surface *rain_get_icon(magic_api * api, int which);
char *rain_get_name(magic_api * api, int which);
char *rain_get_description(magic_api * api, int which, int mode);
static void do_rain_drop(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
static void rain_linecb(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
void rain_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void rain_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void rain_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void rain_shutdown(magic_api * api);
void rain_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int rain_requires_colors(magic_api * api, int which);
@ -96,96 +94,121 @@ void rain_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void rain_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int rain_modes(magic_api * api, int which);
Uint32 rain_api_version(void) { return(TP_MAGIC_API_VERSION); }
Uint32 rain_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
//Checks if a a pixel is inside a raindrop shape centered on the origin
static int rain_inRainShape(double x, double y, double r){
if ( sqrt( x*x + y*y ) < ( r * pow( cos( atan2(x,y) ), 10.0) ) ){
static int rain_inRainShape(double x, double y, double r)
{
if (sqrt(x * x + y * y) < (r * pow(cos(atan2(x, y)), 10.0)))
{
return 1;
}
return 0;
}
int rain_init(magic_api * api){
int rain_init(magic_api * api)
{
int i;
char fname[1024];
//Load sounds
for (i = 0; i < rain_NUM_TOOLS; i++){
for (i = 0; i < rain_NUM_TOOLS; i++)
{
snprintf(fname, sizeof(fname), "%s/sounds/magic/%s", api->data_directory, rain_snd_filenames[i]);
rain_snd_effect[i] = Mix_LoadWAV(fname);
}
return(1);
return (1);
}
int rain_get_tool_count(magic_api * api ATTRIBUTE_UNUSED){
return(rain_NUM_TOOLS);
int rain_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return (rain_NUM_TOOLS);
}
// Load our icons:
SDL_Surface * rain_get_icon(magic_api * api, int which){
SDL_Surface *rain_get_icon(magic_api * api, int which)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, rain_icon_filenames[which]);
return(IMG_Load(fname));
return (IMG_Load(fname));
}
// Return our names, localized:
char * rain_get_name(magic_api * api ATTRIBUTE_UNUSED, int which){
return(strdup(gettext_noop(rain_names[which])));
char *rain_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
{
return (strdup(gettext_noop(rain_names[which])));
}
// Return our descriptions, localized:
char * rain_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode){
return(strdup(gettext_noop(rain_descs[which][mode-1])));
char *rain_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode)
{
return (strdup(gettext_noop(rain_descs[which][mode - 1])));
}
// Do the effect:
static void do_rain_drop(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
int x, int y){
magic_api * api = (magic_api *) ptr;
static void do_rain_drop(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
{
magic_api *api = (magic_api *) ptr;
int xx, yy;
Uint8 r,g,b;
Uint8 r, g, b;
for (yy = y - rain_SIZE/2; yy < y + rain_SIZE/2; yy++){
for (xx = x - rain_SIZE; xx < x + rain_SIZE; xx++){
if (rain_inRainShape(xx - x, yy - y + rain_SIZE/2, rain_SIZE)){
for (yy = y - rain_SIZE / 2; yy < y + rain_SIZE / 2; yy++)
{
for (xx = x - rain_SIZE; xx < x + rain_SIZE; xx++)
{
if (rain_inRainShape(xx - x, yy - y + rain_SIZE / 2, rain_SIZE))
{
//api->rgbtohsv(rain_r, rain_g, rain_b, &h, &s, &v);
//api->hsvtorgb(h, s, rain_weights[(yy-y)*((rain_SIZE*2) -1)+(xx-x)], &r, &g, &b);
SDL_GetRGB(api->getpixel(canvas, xx , yy), canvas->format, &r, &g, &b);
SDL_GetRGB(api->getpixel(canvas, xx, yy), canvas->format, &r, &g, &b);
api->putpixel(canvas, xx, yy, SDL_MapRGB(canvas->format, clamp(0, r - 50, 255),
clamp(0, g - 50, 255),
clamp(0, b + 200, 255)));
clamp(0, g - 50, 255), clamp(0, b + 200, 255)));
}
}
}
}
static void rain_linecb(void * ptr, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y)
static void rain_linecb(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
SDL_Rect rect;
if (rand() % 10 == 0) {
if (rand() % 10 == 0)
{
rain_click(api, which, MODE_PAINT, canvas, last,
x + (rand() % rain_SIZE * 2) - rain_SIZE,
y + (rand() % rain_SIZE * 2) - rain_SIZE,
&rect);
x + (rand() % rain_SIZE * 2) - rain_SIZE, y + (rand() % rain_SIZE * 2) - rain_SIZE, &rect);
}
}
// Affect the canvas on drag:
void rain_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((void *) api, which, canvas, last, ox, oy, x, y, 1, rain_linecb);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, rain_linecb);
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;
}
update_rect->x = ox - rain_SIZE * 2;
update_rect->y = oy - rain_SIZE * 2;
@ -195,10 +218,11 @@ void rain_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void rain_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect){
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
if (mode == MODE_PAINT){
if (mode == MODE_PAINT)
{
do_rain_drop(api, which, canvas, last, x, y);
update_rect->x = x - rain_SIZE;
@ -207,10 +231,14 @@ void rain_click(magic_api * api, int which, int mode,
update_rect->h = rain_SIZE * 2;
api->playsound(rain_snd_effect[which], (x * 255) / canvas->w, 255);
}else{
}
else
{
int i;
for(i=0; i<rain_AMOUNT; i++){
for (i = 0; i < rain_AMOUNT; i++)
{
do_rain_drop(api, which, canvas, last, rand() % canvas->w, rand() % canvas->h);
}
@ -235,15 +263,19 @@ void rain_shutdown(magic_api * api ATTRIBUTE_UNUSED)
{
//Clean up sounds
int i;
for(i=0; i<rain_NUM_TOOLS; i++){
if(rain_snd_effect[i] != NULL){
for (i = 0; i < rain_NUM_TOOLS; i++)
{
if (rain_snd_effect[i] != NULL)
{
Mix_FreeChunk(rain_snd_effect[i]);
}
}
}
// Record the color from Tux Paint:
void rain_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
void rain_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED)
{
}
@ -254,17 +286,17 @@ int rain_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_U
}
void rain_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void rain_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void rain_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void rain_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int rain_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_FULLSCREEN|MODE_PAINT);
return (MODE_FULLSCREEN | MODE_PAINT);
}

View file

@ -65,31 +65,24 @@ static const int rainbow_hexes[NUM_RAINBOW_COLORS][3] = {
static int rainbow_color;
static Uint32 rainbow_rgb;
static Mix_Chunk * rainbow_snd;
static Mix_Chunk *rainbow_snd;
int rainbow_init(magic_api * api);
Uint32 rainbow_api_version(void);
int rainbow_get_tool_count(magic_api * api);
SDL_Surface * rainbow_get_icon(magic_api * api, int which);
char * rainbow_get_name(magic_api * api, int which);
char * rainbow_get_description(magic_api * api, int which, int mode);
static void rainbow_linecb(void * ptr, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y);
SDL_Surface *rainbow_get_icon(magic_api * api, int which);
char *rainbow_get_name(magic_api * api, int which);
char *rainbow_get_description(magic_api * api, int which, int mode);
static void rainbow_linecb(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
void rainbow_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void rainbow_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y,
SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void rainbow_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y,
SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void rainbow_shutdown(magic_api * api);
@ -99,7 +92,10 @@ void rainbow_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas
void rainbow_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int rainbow_modes(magic_api * api, int which);
Uint32 rainbow_api_version(void) { return(TP_MAGIC_API_VERSION); }
Uint32 rainbow_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
// Load our sfx:
int rainbow_init(magic_api * api)
@ -109,50 +105,46 @@ int rainbow_init(magic_api * api)
rainbow_color = 0;
snprintf(fname, sizeof(fname), "%s/sounds/magic/rainbow.wav",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/sounds/magic/rainbow.wav", api->data_directory);
rainbow_snd = Mix_LoadWAV(fname);
return(1);
return (1);
}
// We have multiple tools:
int rainbow_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return(1);
return (1);
}
// Load our icons:
SDL_Surface * rainbow_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
SDL_Surface *rainbow_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/images/magic/rainbow.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/rainbow.png", api->data_directory);
return(IMG_Load(fname));
return (IMG_Load(fname));
}
// Return our names, localized:
char * rainbow_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
char *rainbow_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(strdup(gettext_noop("Rainbow")));
return (strdup(gettext_noop("Rainbow")));
}
// Return our descriptions, localized:
char * rainbow_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
char *rainbow_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return(strdup(
gettext_noop("You can draw in rainbow colors!")));
return (strdup(gettext_noop("You can draw in rainbow colors!")));
}
// Do the effect:
static void rainbow_linecb(void * ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
int x, int y)
static void rainbow_linecb(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
{
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
int xx, yy;
for (yy = y - 16; yy < y + 16; yy++)
@ -169,19 +161,29 @@ static void rainbow_linecb(void * ptr, int which ATTRIBUTE_UNUSED,
// Affect the canvas on drag:
void rainbow_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
rainbow_color = (rainbow_color + 1) % NUM_RAINBOW_COLORS;
rainbow_rgb = SDL_MapRGB(canvas->format,
rainbow_hexes[rainbow_color][0],
rainbow_hexes[rainbow_color][1],
rainbow_hexes[rainbow_color][2]);
rainbow_hexes[rainbow_color][1], rainbow_hexes[rainbow_color][2]);
api->line((void *) api, 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; }
if (ox > x)
{
int tmp = ox;
ox = x;
x = tmp;
}
if (oy > y)
{
int tmp = oy;
oy = y;
y = tmp;
}
update_rect->x = ox - 16;
update_rect->y = oy - 16;
@ -193,17 +195,14 @@ void rainbow_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void rainbow_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
rainbow_drag(api, which, canvas, last, x, y, x, y, update_rect);
}
void rainbow_release(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
@ -215,7 +214,8 @@ void rainbow_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void rainbow_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
void rainbow_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED)
{
}
@ -225,15 +225,17 @@ int rainbow_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUT
return 0;
}
void rainbow_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void rainbow_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void rainbow_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void rainbow_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int rainbow_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_PAINT);
return (MODE_PAINT);
}

View file

@ -20,48 +20,39 @@ FIXME:
#include "tp_magic_api.h"
Mix_Chunk * realrainbow_snd;
Mix_Chunk *realrainbow_snd;
int realrainbow_x1, realrainbow_y1, realrainbow_x2, realrainbow_y2;
SDL_Rect realrainbow_rect;
SDL_Surface * realrainbow_colors[2];
SDL_Surface *realrainbow_colors[2];
Uint8 realrainbow_blendr, realrainbow_blendg, realrainbow_blendb, realrainbow_blenda;
void realrainbow_arc(magic_api * api, int which, SDL_Surface * canvas, SDL_Surface * last,
int x1, int y1, int x2, int y2,
int fulldraw, SDL_Rect * update_rect);
static void realrainbow_linecb(void * ptr, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y);
int x1, int y1, int x2, int y2, int fulldraw, SDL_Rect * update_rect);
static void realrainbow_linecb(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
Uint32 realrainbow_api_version(void);
int realrainbow_init(magic_api * api);
int realrainbow_get_tool_count(magic_api * api);
SDL_Surface * realrainbow_get_icon(magic_api * api, int which);
char * realrainbow_get_name(magic_api * api, int which);
char * realrainbow_get_description(magic_api * api, int which, int mode);
SDL_Surface *realrainbow_get_icon(magic_api * api, int which);
char *realrainbow_get_name(magic_api * api, int which);
char *realrainbow_get_description(magic_api * api, int which, int mode);
int realrainbow_modes(magic_api * api, int which);
int realrainbow_requires_colors(magic_api * api, int which);
void realrainbow_shutdown(magic_api * api);
void realrainbow_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
void realrainbow_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y,
SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void realrainbow_drag(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void realrainbow_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y,
SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void realrainbow_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void realrainbow_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
Uint32 realrainbow_api_version(void)
{
return(TP_MAGIC_API_VERSION);
return (TP_MAGIC_API_VERSION);
}
int realrainbow_init(magic_api * api)
@ -71,60 +62,60 @@ int realrainbow_init(magic_api * api)
snprintf(fname, sizeof(fname), "%s/images/magic/realrainbow-colors.png", api->data_directory);
realrainbow_colors[0] = IMG_Load(fname);
if (realrainbow_colors[0] == NULL)
return(0);
return (0);
snprintf(fname, sizeof(fname), "%s/images/magic/realrainbow-roygbiv-colors.png", api->data_directory);
realrainbow_colors[1] = IMG_Load(fname);
if (realrainbow_colors[1] == NULL)
return(0);
return (0);
snprintf(fname, sizeof(fname), "%s/sounds/magic/realrainbow.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/sounds/magic/realrainbow.ogg", api->data_directory);
realrainbow_snd = Mix_LoadWAV(fname);
return(1);
return (1);
}
int realrainbow_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return(2);
return (2);
}
SDL_Surface * realrainbow_get_icon(magic_api * api, int which)
SDL_Surface *realrainbow_get_icon(magic_api * api, int which)
{
char fname[1024];
if (which == 0)
snprintf(fname, sizeof(fname), "%s/images/magic/realrainbow.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/realrainbow.png", api->data_directory);
else
snprintf(fname, sizeof(fname), "%s/images/magic/realrainbow-roygbiv.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/realrainbow-roygbiv.png", api->data_directory);
return(IMG_Load(fname));
return (IMG_Load(fname));
}
char * realrainbow_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
char *realrainbow_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
{
if (which == 0)
return(strdup(gettext_noop("Real Rainbow")));
return (strdup(gettext_noop("Real Rainbow")));
else
return(strdup(gettext_noop("ROYGBIV Rainbow")));
return (strdup(gettext_noop("ROYGBIV Rainbow")));
}
char * realrainbow_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
char *realrainbow_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED)
{
return(strdup(gettext_noop("Click where you want your rainbow to start, drag to where you want it to end, and then let go to draw a rainbow.")));
return (strdup
(gettext_noop
("Click where you want your rainbow to start, drag to where you want it to end, and then let go to draw a rainbow.")));
}
int realrainbow_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_PAINT_WITH_PREVIEW);
return (MODE_PAINT_WITH_PREVIEW);
}
int realrainbow_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(0);
return (0);
}
void realrainbow_shutdown(magic_api * api ATTRIBUTE_UNUSED)
@ -137,14 +128,14 @@ void realrainbow_shutdown(magic_api * api ATTRIBUTE_UNUSED)
Mix_FreeChunk(realrainbow_snd);
}
void realrainbow_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
void realrainbow_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED)
{
}
void realrainbow_click(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
int x, int y,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
int x, int y, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
realrainbow_x1 = x;
realrainbow_y1 = y;
@ -157,8 +148,7 @@ void realrainbow_click(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNU
void realrainbow_drag(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, int x, int y,
SDL_Rect * update_rect)
int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, int x, int y, SDL_Rect * update_rect)
{
int rx1, ry1, rx2, ry2;
SDL_Rect rect;
@ -168,7 +158,8 @@ void realrainbow_drag(magic_api * api, int which,
SDL_BlitSurface(last, &realrainbow_rect, canvas, &realrainbow_rect);
realrainbow_arc(api, which, canvas, last, realrainbow_x1, realrainbow_y1, realrainbow_x2, realrainbow_y2, 0, update_rect);
realrainbow_arc(api, which, canvas, last, realrainbow_x1, realrainbow_y1, realrainbow_x2, realrainbow_y2, 0,
update_rect);
memcpy(&rect, &realrainbow_rect, sizeof(SDL_Rect));
memcpy(&realrainbow_rect, update_rect, sizeof(SDL_Rect));
@ -194,9 +185,7 @@ void realrainbow_drag(magic_api * api, int which,
}
void realrainbow_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
int rx1, ry1, rx2, ry2;
SDL_Rect rect;
@ -206,7 +195,8 @@ void realrainbow_release(magic_api * api, int which,
SDL_BlitSurface(last, &realrainbow_rect, canvas, &realrainbow_rect);
realrainbow_arc(api, which, canvas, last, realrainbow_x1, realrainbow_y1, realrainbow_x2, realrainbow_y2, 1, update_rect);
realrainbow_arc(api, which, canvas, last, realrainbow_x1, realrainbow_y1, realrainbow_x2, realrainbow_y2, 1,
update_rect);
memcpy(&rect, &realrainbow_rect, sizeof(SDL_Rect));
memcpy(&realrainbow_rect, update_rect, sizeof(SDL_Rect));
@ -233,16 +223,19 @@ void realrainbow_release(magic_api * api, int which,
api->playsound(realrainbow_snd, 128, 255);
}
void realrainbow_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void realrainbow_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void realrainbow_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void realrainbow_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void realrainbow_arc(magic_api * api, int which, SDL_Surface * canvas, SDL_Surface * last, int x1, int y1, int x2, int y2, int fulldraw, SDL_Rect * update_rect)
void realrainbow_arc(magic_api * api, int which, SDL_Surface * canvas, SDL_Surface * last, int x1, int y1, int x2,
int y2, int fulldraw, SDL_Rect * update_rect)
{
int lowx, lowy, hix, hiy, xm, ym, xc, yc, r, a1, atan2_a, atan2_b;
int a, oa, ox, oy, nx, ny, step, thick, rr, done;
@ -333,21 +326,22 @@ void realrainbow_arc(magic_api * api, int which, SDL_Surface * canvas, SDL_Surfa
nx = (rr * cos(a * M_PI / 180.0)) + xc;
ny = (rr * sin(a * M_PI / 180.0)) + yc;
colorindex = realrainbow_colors[which]->h - 1 - (((rr - r + (thick / 2)) * realrainbow_colors[which]->h) / thick);
colorindex =
realrainbow_colors[which]->h - 1 - (((rr - r + (thick / 2)) * realrainbow_colors[which]->h) / thick);
SDL_GetRGBA(api->getpixel(realrainbow_colors[which], 0, colorindex),
realrainbow_colors[which]->format, &realrainbow_blendr, &realrainbow_blendg, &realrainbow_blendb, &realrainbow_blenda);
realrainbow_colors[which]->format, &realrainbow_blendr, &realrainbow_blendg, &realrainbow_blendb,
&realrainbow_blenda);
if (!fulldraw)
realrainbow_blenda = 255;
api->line((void *) api, 0, canvas, last, ox, oy, nx, ny, 1, realrainbow_linecb);
api->line((void *)api, 0, canvas, last, ox, oy, nx, ny, 1, realrainbow_linecb);
}
oa = a;
if ((step > 0 && a + step > theta) ||
(step < 0 && a + step < theta))
if ((step > 0 && a + step > theta) || (step < 0 && a + step < theta))
{
done++;
a = theta - step;
@ -360,16 +354,14 @@ void realrainbow_arc(magic_api * api, int which, SDL_Surface * canvas, SDL_Surfa
update_rect->w = r * 2 + thick * 2;
}
static void realrainbow_linecb(void * ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y)
static void realrainbow_linecb(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
Uint8 origr, origg, origb;
Uint8 newr, newg, newb;
SDL_GetRGB(api->getpixel(last, x, y),
last->format, &origr, &origg, &origb);
SDL_GetRGB(api->getpixel(last, x, y), last->format, &origr, &origg, &origb);
newr = ((realrainbow_blendr * realrainbow_blenda) / 255) + ((origr * (255 - realrainbow_blenda)) / 255);
newg = ((realrainbow_blendg * realrainbow_blenda) / 255) + ((origg * (255 - realrainbow_blenda)) / 255);
@ -377,4 +369,3 @@ static void realrainbow_linecb(void * ptr, int which ATTRIBUTE_UNUSED,
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, newr, newg, newb));
}

View file

@ -37,28 +37,23 @@
/* Our globals: */
static Mix_Chunk * ripples_snd;
static Mix_Chunk *ripples_snd;
static int ripples_z, ripples_brite;
Uint32 ripples_api_version(void);
int ripples_init(magic_api * api);
int ripples_get_tool_count(magic_api * api);
SDL_Surface * ripples_get_icon(magic_api * api, int which);
char * ripples_get_name(magic_api * api, int which);
char * ripples_get_description(magic_api * api, int which, int mode);
SDL_Surface *ripples_get_icon(magic_api * api, int which);
char *ripples_get_name(magic_api * api, int which);
char *ripples_get_description(magic_api * api, int which, int mode);
void ripples_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
static void ripples_linecb(void * ptr, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
static void ripples_linecb(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
void ripples_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void ripples_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void ripples_shutdown(magic_api * api);
void ripples_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int ripples_requires_colors(magic_api * api, int which);
@ -66,7 +61,10 @@ void ripples_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas
void ripples_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int ripples_modes(magic_api * api, int which);
Uint32 ripples_api_version(void) { return(TP_MAGIC_API_VERSION); }
Uint32 ripples_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
#define deg_cos(x) cos((x) * M_PI / 180.0)
#define deg_sin(x) sin((x) * M_PI / 180.0)
@ -76,54 +74,51 @@ int ripples_init(magic_api * api)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/sounds/magic/ripples.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/sounds/magic/ripples.ogg", api->data_directory);
ripples_snd = Mix_LoadWAV(fname);
return(1);
return (1);
}
// We have multiple tools:
int ripples_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return(1);
return (1);
}
// Load our icons:
SDL_Surface * ripples_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
SDL_Surface *ripples_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/images/magic/ripples.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/ripples.png", api->data_directory);
return(IMG_Load(fname));
return (IMG_Load(fname));
}
// Return our names, localized:
char * ripples_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
char *ripples_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(strdup(gettext_noop("Ripples")));
return (strdup(gettext_noop("Ripples")));
}
// Return our descriptions, localized:
char * ripples_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
char *ripples_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return(strdup(gettext_noop("Click to make ripples appear over your picture.")));
return (strdup(gettext_noop("Click to make ripples appear over your picture.")));
}
// Affect the canvas on drag:
void ripples_drag(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
SDL_Surface * last ATTRIBUTE_UNUSED, int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED,
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
static void ripples_linecb(void * ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y)
static void ripples_linecb(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
Uint8 r, g, b;
Uint32 pix;
@ -139,8 +134,7 @@ static void ripples_linecb(void * ptr, int which ATTRIBUTE_UNUSED,
// Affect the canvas on click:
void ripples_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
float radius;
float fli;
@ -162,7 +156,7 @@ void ripples_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
ripples_brite = (ripples_z * 20 * deg_sin(d + 45)) / ((fli / 4) + 1);
api->line((void *) api, 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;
@ -192,7 +186,8 @@ void ripples_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void ripples_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
void ripples_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED)
{
}
@ -202,15 +197,17 @@ int ripples_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUT
return 0;
}
void ripples_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void ripples_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void ripples_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void ripples_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int ripples_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_ONECLICK);
return (MODE_ONECLICK);
}

View file

@ -44,7 +44,7 @@ struct rosette_rgb
struct rosette_rgb rosette_colors;
Mix_Chunk * rosette_snd;
Mix_Chunk *rosette_snd;
// Housekeeping functions
@ -52,39 +52,34 @@ Uint32 rosette_api_version(void);
void rosette_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int rosette_init(magic_api * api);
int rosette_get_tool_count(magic_api * api);
SDL_Surface * rosette_get_icon(magic_api * api, int which);
char * rosette_get_name(magic_api * api, int which);
char * rosette_get_description(magic_api * api, int which, int mode);
SDL_Surface *rosette_get_icon(magic_api * api, int which);
char *rosette_get_name(magic_api * api, int which);
char *rosette_get_description(magic_api * api, int which, int mode);
int rosette_requires_colors(magic_api * api, int which);
void rosette_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);
void rosette_shutdown(magic_api * api);
void rosette_draw(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
void rosette_draw(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
void rosette_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 rosette_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void rosette_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void rosette_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int rosette_modes(magic_api * api, int which);
void rosette_circle(void * ptr, int which,
SDL_Surface * canvas, SDL_Surface * snapshot,
int x, int y);
void rosette_circle(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
Uint32 rosette_api_version(void)
{
return(TP_MAGIC_API_VERSION);
return (TP_MAGIC_API_VERSION);
}
void rosette_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b) //get the colors from API and store it in structure
{
rosette_colors.r=r;
rosette_colors.g=g;
rosette_colors.b=b;
rosette_colors.r = r;
rosette_colors.g = g;
rosette_colors.b = b;
}
int rosette_init(magic_api * api)
@ -94,7 +89,7 @@ int rosette_init(magic_api * api)
snprintf(fname, sizeof(fname), "%s/sounds/magic/picasso.ogg", api->data_directory);
rosette_snd = Mix_LoadWAV(fname);
return(1);
return (1);
}
int rosette_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
@ -102,20 +97,27 @@ int rosette_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
return 2;
}
SDL_Surface * rosette_get_icon(magic_api * api, int which)
SDL_Surface *rosette_get_icon(magic_api * api, int which)
{
char fname[1024];
if (!which)
snprintf(fname, sizeof(fname), "%s/images/magic/rosette.png", api->data_directory);
else snprintf(fname, sizeof(fname), "%s/images/magic/picasso.png", api->data_directory);
else
snprintf(fname, sizeof(fname), "%s/images/magic/picasso.png", api->data_directory);
return(IMG_Load(fname));
return (IMG_Load(fname));
}
char * rosette_get_name(magic_api * api ATTRIBUTE_UNUSED, int which) { if (!which) return strdup(gettext_noop("Rosette")); else return strdup(gettext_noop("Picasso"));}
char *rosette_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
{
if (!which)
return strdup(gettext_noop("Rosette"));
else
return strdup(gettext_noop("Picasso"));
}
char * rosette_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
char *rosette_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
{
if (!which)
return strdup(gettext_noop("Click and start drawing your rosette.")); //just k'scope with 3 bits?
@ -123,7 +125,10 @@ char * rosette_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int
return strdup(gettext_noop("You can draw just like Picasso!")); //what is this actually doing?
}
int rosette_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) { return 1; }
int rosette_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 1;
}
void rosette_release(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * snapshot ATTRIBUTE_UNUSED,
@ -131,102 +136,107 @@ void rosette_release(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSE
{
}
void rosette_shutdown(magic_api * api ATTRIBUTE_UNUSED) { Mix_FreeChunk(rosette_snd); }
void rosette_shutdown(magic_api * api ATTRIBUTE_UNUSED)
{
Mix_FreeChunk(rosette_snd);
}
// Interactivity functions
void rosette_circle(void * ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED,
int x, int y)
void rosette_circle(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
{
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
int xx, yy;
for (yy = y - ROSETTE_R; yy < y + ROSETTE_R; yy++)
for (xx = x - ROSETTE_R; xx < x + ROSETTE_R; xx++)
if (api->in_circle(xx - x , yy - y , ROSETTE_R/2))
if (api->in_circle(xx - x, yy - y, ROSETTE_R / 2))
api->putpixel(canvas, xx, yy, SDL_MapRGB(canvas->format, rosette_colors.r, rosette_colors.g, rosette_colors.b));
}
void rosette_draw(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y)
void rosette_draw(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y)
{
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
double angle;
double xx, yy; //distance to the center of the image
int x1, y1, x2, y2;
xx=(double)(xmid-x);
yy=(double)(y-ymid);
xx = (double)(xmid - x);
yy = (double)(y - ymid);
if (which==0)
if (which == 0)
{
angle=2*M_PI/3; //an angle between brushes
angle = 2 * M_PI / 3; //an angle between brushes
x1=(int)(xx*cos(angle)-yy*sin(angle));
y1=(int)(xx*sin(angle)+yy*cos(angle));
x1 = (int)(xx * cos(angle) - yy * sin(angle));
y1 = (int)(xx * sin(angle) + yy * cos(angle));
x2=(int)(xx*cos(2*angle)-yy*sin(2*angle));
y2=(int)(xx*sin(2*angle)+yy*cos(2*angle));
x2 = (int)(xx * cos(2 * angle) - yy * sin(2 * angle));
y2 = (int)(xx * sin(2 * angle) + yy * cos(2 * angle));
}
else
{
angle=atan(yy/xx);
angle = atan(yy / xx);
if ((xx<0) && (yy>0)) angle+=M_PI;
if ((xx < 0) && (yy > 0))
angle += M_PI;
if ((xx<0) && (yy<0)) angle+=M_PI;
if ((xx < 0) && (yy < 0))
angle += M_PI;
if ((xx>0) && (yy<0)) angle+=2*M_PI;
if ((xx > 0) && (yy < 0))
angle += 2 * M_PI;
if ((y==ymid) && (xx<0)) angle=M_PI;
if ((y == ymid) && (xx < 0))
angle = M_PI;
x1=(int)(xx*cos(2*angle)-yy*sin(2*angle));
y1=(int)(xx*sin(2*angle)-yy*cos(angle));
x1 = (int)(xx * cos(2 * angle) - yy * sin(2 * angle));
y1 = (int)(xx * sin(2 * angle) - yy * cos(angle));
x2=(int)(xx*cos(2*angle)-yy*sin(2*angle));
y2=(int)(xx*sin(2*angle)+yy*cos(2*angle));
x2 = (int)(xx * cos(2 * angle) - yy * sin(2 * angle));
y2 = (int)(xx * sin(2 * angle) + yy * cos(2 * angle));
}
rosette_circle(api, which, canvas, snapshot, x, y);
rosette_circle(api, which, canvas, snapshot, (-1)*(x1-xmid), y1+ymid);
rosette_circle(api, which, canvas, snapshot, (-1)*(x2-xmid), y2+ymid);
rosette_circle(api, which, canvas, snapshot, (-1) * (x1 - xmid), y1 + ymid);
rosette_circle(api, which, canvas, snapshot, (-1) * (x2 - xmid), y2 + ymid);
}
void rosette_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)
{
api->line((void *) api, which, canvas, snapshot, ox, oy, x, y, 1, rosette_draw);
api->line((void *)api, which, canvas, snapshot, ox, oy, x, y, 1, rosette_draw);
api->playsound(rosette_snd, (x * 255) / canvas->w, 255);
update_rect->x=update_rect->y=0;
update_rect->w=canvas->w;
update_rect->h=canvas->h;
update_rect->x = update_rect->y = 0;
update_rect->w = canvas->w;
update_rect->h = canvas->h;
}
void rosette_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
rosette_drag(api, which, canvas, last, x, y, x, y, update_rect);
}
void rosette_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void rosette_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
xmid=canvas->w/2;
ymid=canvas->h/2;
xmid = canvas->w / 2;
ymid = canvas->h / 2;
}
void rosette_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void rosette_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int rosette_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_PAINT);
return (MODE_PAINT);
}

View file

@ -44,7 +44,8 @@
/* Our globals: */
enum {
enum
{
TOOL_TRACE,
TOOL_SHARPEN,
TOOL_SILHOUETTE,
@ -57,24 +58,27 @@ static const int sharpen_RADIUS = 16;
static const double SHARPEN = 0.5;
static Mix_Chunk * sharpen_snd_effect[sharpen_NUM_TOOLS];
static Mix_Chunk *sharpen_snd_effect[sharpen_NUM_TOOLS];
const char * sharpen_snd_filenames[sharpen_NUM_TOOLS] = {
const char *sharpen_snd_filenames[sharpen_NUM_TOOLS] = {
"edges.ogg",
"sharpen.ogg",
"silhouette.ogg"
};
const char * sharpen_icon_filenames[sharpen_NUM_TOOLS] = {
const char *sharpen_icon_filenames[sharpen_NUM_TOOLS] = {
"edges.png",
"sharpen.png",
"silhouette.png"
};
const char * sharpen_names[sharpen_NUM_TOOLS] = {
const char *sharpen_names[sharpen_NUM_TOOLS] = {
gettext_noop("Edges"),
gettext_noop("Sharpen"),
gettext_noop("Silhouette")
};
const char * sharpen_descs[sharpen_NUM_TOOLS][2] = {
const char *sharpen_descs[sharpen_NUM_TOOLS][2] = {
{gettext_noop("Click and drag the mouse to trace edges in parts of your picture."),
gettext_noop("Click to trace edges in your entire picture."),},
{gettext_noop("Click and drag the mouse to sharpen parts of your picture."),
@ -86,25 +90,20 @@ const char * sharpen_descs[sharpen_NUM_TOOLS][2] = {
Uint32 sharpen_api_version(void);
int sharpen_init(magic_api * api);
int sharpen_get_tool_count(magic_api * api);
SDL_Surface * sharpen_get_icon(magic_api * api, int which);
char * sharpen_get_name(magic_api * api, int which);
char * sharpen_get_description(magic_api * api, int which, int mode);
static int sharpen_grey(Uint8 r1,Uint8 g1,Uint8 b1);
static void do_sharpen_pixel(void * ptr, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y);
static void do_sharpen_full(void * ptr,SDL_Surface * canvas, SDL_Surface * last, int which);
static void do_sharpen_brush(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
SDL_Surface *sharpen_get_icon(magic_api * api, int which);
char *sharpen_get_name(magic_api * api, int which);
char *sharpen_get_description(magic_api * api, int which, int mode);
static int sharpen_grey(Uint8 r1, Uint8 g1, Uint8 b1);
static void do_sharpen_pixel(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
static void do_sharpen_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int which);
static void do_sharpen_brush(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
void sharpen_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void sharpen_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void sharpen_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void sharpen_shutdown(magic_api * api);
void sharpen_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
@ -113,99 +112,116 @@ void sharpen_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas
void sharpen_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int sharpen_modes(magic_api * api, int which);
Uint32 sharpen_api_version(void) { return(TP_MAGIC_API_VERSION); }
Uint32 sharpen_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
// No setup required:
int sharpen_init(magic_api * api){
int sharpen_init(magic_api * api)
{
int i;
char fname[1024];
for (i = 0; i < sharpen_NUM_TOOLS; i++){
for (i = 0; i < sharpen_NUM_TOOLS; i++)
{
snprintf(fname, sizeof(fname), "%s/sounds/magic/%s", api->data_directory, sharpen_snd_filenames[i]);
sharpen_snd_effect[i] = Mix_LoadWAV(fname);
}
return(1);
return (1);
}
// We have multiple tools:
int sharpen_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return(sharpen_NUM_TOOLS);
return (sharpen_NUM_TOOLS);
}
// Load our icons:
SDL_Surface * sharpen_get_icon(magic_api * api, int which){
SDL_Surface *sharpen_get_icon(magic_api * api, int which)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, sharpen_icon_filenames[which]);
return(IMG_Load(fname));
return (IMG_Load(fname));
}
// Return our names, localized:
char * sharpen_get_name(magic_api * api ATTRIBUTE_UNUSED, int which){
return(strdup(gettext_noop(sharpen_names[which])));
char *sharpen_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
{
return (strdup(gettext_noop(sharpen_names[which])));
}
// Return our descriptions, localized:
char * sharpen_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode){
return(strdup(gettext_noop(sharpen_descs[which][mode-1])));
char *sharpen_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode)
{
return (strdup(gettext_noop(sharpen_descs[which][mode - 1])));
}
//Calculates the grey scale value for a rgb pixel
static int sharpen_grey(Uint8 r1,Uint8 g1,Uint8 b1){
return 0.3*r1+.59*g1+0.11*b1;
static int sharpen_grey(Uint8 r1, Uint8 g1, Uint8 b1)
{
return 0.3 * r1 + .59 * g1 + 0.11 * b1;
}
// Do the effect:
static void do_sharpen_pixel(void * ptr, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y){
static void do_sharpen_pixel(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
Uint8 r1, g1, b1;
int grey;
int i,j;
double sobel_1=0,sobel_2=0;
int i, j;
double sobel_1 = 0, sobel_2 = 0;
double temp;
//Sobel weighting masks
const int sobel_weights_1[3][3] = { {1,2,1},
{0,0,0},
{-1,-2,-1}};
const int sobel_weights_2[3][3] = { {-1,0,1},
{-2,0,2},
{-1,0,1}};
const int sobel_weights_1[3][3] = { {1, 2, 1},
{0, 0, 0},
{-1, -2, -1}
};
const int sobel_weights_2[3][3] = { {-1, 0, 1},
{-2, 0, 2},
{-1, 0, 1}
};
sobel_1=0;
sobel_2=0;
for (i=-1;i<2;i++){
for(j=-1; j<2; j++){
sobel_1 = 0;
sobel_2 = 0;
for (i = -1; i < 2; i++)
{
for (j = -1; j < 2; j++)
{
//No need to check if inside canvas, getpixel does it for us.
SDL_GetRGB(api->getpixel(last, x+i, y+j), last->format, &r1, &g1, &b1);
grey = sharpen_grey(r1,g1,b1);
sobel_1 += grey * sobel_weights_1[i+1][j+1];
sobel_2 += grey * sobel_weights_2[i+1][j+1];
SDL_GetRGB(api->getpixel(last, x + i, y + j), last->format, &r1, &g1, &b1);
grey = sharpen_grey(r1, g1, b1);
sobel_1 += grey * sobel_weights_1[i + 1][j + 1];
sobel_2 += grey * sobel_weights_2[i + 1][j + 1];
}
}
temp = sqrt(sobel_1*sobel_1 + sobel_2*sobel_2);
temp = (temp/1443)*255.0;
temp = sqrt(sobel_1 * sobel_1 + sobel_2 * sobel_2);
temp = (temp / 1443) * 255.0;
// set image to white where edge value is below THRESHOLD
if (which == TOOL_TRACE){
if (temp<THRESHOLD){
if (which == TOOL_TRACE)
{
if (temp < THRESHOLD)
{
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, 255, 255, 255));
}
}
//Simply display the edge values - provides a nice black and white silhouette image
else if (which == TOOL_SILHOUETTE){
else if (which == TOOL_SILHOUETTE)
{
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, temp, temp, temp));
}
//Add the edge values to the original image, creating a more distinct jump in contrast at edges
else if(which == TOOL_SHARPEN){
else if (which == TOOL_SHARPEN)
{
SDL_GetRGB(api->getpixel(last, x, y), last->format, &r1, &g1, &b1);
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, clamp(0.0, r1 + SHARPEN * temp, 255.0),
clamp(0.0, g1 + SHARPEN * temp, 255.0),
@ -214,30 +230,33 @@ static void do_sharpen_pixel(void * ptr, int which,
}
// Do the effect for the full image
static void do_sharpen_full(void * ptr,SDL_Surface * canvas, SDL_Surface * last, int which){
static void do_sharpen_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int which)
{
// magic_api * api = (magic_api *) ptr;
int x,y;
int x, y;
for (y = 0; y < last->h; y++){
for (x=0; x < last->w; x++){
for (y = 0; y < last->h; y++)
{
for (x = 0; x < last->w; x++)
{
do_sharpen_pixel(ptr, which, canvas, last, x, y);
}
}
}
//do the effect for the brush
static void do_sharpen_brush(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y){
static void do_sharpen_brush(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
int xx, yy;
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
for (yy = y - sharpen_RADIUS; yy < y + sharpen_RADIUS; yy++)
{
for (xx = x - sharpen_RADIUS; xx < x + sharpen_RADIUS; xx++)
{
if (api->in_circle(xx - x, yy - y, sharpen_RADIUS) &&
!api->touched(xx, yy))
if (api->in_circle(xx - x, yy - y, sharpen_RADIUS) && !api->touched(xx, yy))
{
do_sharpen_pixel(api, which, canvas, last, xx, yy);
}
@ -247,15 +266,27 @@ static void do_sharpen_brush(void * ptr, int which, SDL_Surface * canvas, SDL_Su
// Affect the canvas on drag:
void sharpen_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect){
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_sharpen_brush);
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_sharpen_brush);
api->playsound(sharpen_snd_effect[which], (x * 255) / canvas->w, 255);
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;
}
update_rect->x = ox - sharpen_RADIUS;
update_rect->y = oy - sharpen_RADIUS;
@ -265,11 +296,12 @@ void sharpen_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void sharpen_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect){
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
if (mode == MODE_PAINT)
sharpen_drag(api, which, canvas, last, x, y, x, y, update_rect);
else{
else
{
update_rect->x = 0;
update_rect->y = 0;
update_rect->w = canvas->w;
@ -291,15 +323,19 @@ void sharpen_shutdown(magic_api * api ATTRIBUTE_UNUSED)
{
//Clean up sounds
int i;
for(i=0; i<sharpen_NUM_TOOLS; i++){
if(sharpen_snd_effect[i] != NULL){
for (i = 0; i < sharpen_NUM_TOOLS; i++)
{
if (sharpen_snd_effect[i] != NULL)
{
Mix_FreeChunk(sharpen_snd_effect[i]);
}
}
}
// Record the color from Tux Paint:
void sharpen_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
void sharpen_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED)
{
}
@ -309,15 +345,17 @@ int sharpen_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUT
return 0;
}
void sharpen_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void sharpen_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void sharpen_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void sharpen_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int sharpen_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_FULLSCREEN|MODE_PAINT);
return (MODE_FULLSCREEN | MODE_PAINT);
}

View file

@ -38,29 +38,25 @@
/* Our globals: */
static int shift_x, shift_y;
static Mix_Chunk * shift_snd;
static Mix_Chunk *shift_snd;
/* Local function prototypes: */
static void shift_doit(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect, int crosshairs);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect, int crosshairs);
Uint32 shift_api_version(void);
int shift_init(magic_api * api);
int shift_get_tool_count(magic_api * api);
SDL_Surface * shift_get_icon(magic_api * api, int which);
char * shift_get_name(magic_api * api, int which);
char * shift_get_description(magic_api * api, int which, int mode);
SDL_Surface *shift_get_icon(magic_api * api, int which);
char *shift_get_name(magic_api * api, int which);
char *shift_get_description(magic_api * api, int which, int mode);
void shift_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void shift_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void shift_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void shift_shutdown(magic_api * api);
void shift_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int shift_requires_colors(magic_api * api, int which);
@ -71,7 +67,10 @@ int shift_modes(magic_api * api, int which);
Uint32 shift_api_version(void) { return(TP_MAGIC_API_VERSION); }
Uint32 shift_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
// No setup required:
@ -79,47 +78,44 @@ int shift_init(magic_api * api)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/sounds/magic/shift.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/sounds/magic/shift.ogg", api->data_directory);
shift_snd = Mix_LoadWAV(fname);
return(1);
return (1);
}
// We have multiple tools:
int shift_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return(1);
return (1);
}
// Load our icons:
SDL_Surface * shift_get_icon(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
SDL_Surface *shift_get_icon(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/images/magic/shift.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/shift.png", api->data_directory);
return(IMG_Load(fname));
return (IMG_Load(fname));
}
// Return our names, localized:
char * shift_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
char *shift_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(strdup(gettext_noop("Shift")));
return (strdup(gettext_noop("Shift")));
}
// Return our descriptions, localized:
char * shift_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
char *shift_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return(strdup(gettext_noop("Click and drag to shift your picture around on the canvas.")));
return (strdup(gettext_noop("Click and drag to shift your picture around on the canvas.")));
}
// Affect the canvas on drag:
void shift_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
if (ox == x && oy == y)
return; /* No-op */
@ -290,8 +286,7 @@ static void shift_doit(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNU
// Affect the canvas on click:
void shift_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
shift_x = x;
shift_y = y;
@ -301,8 +296,7 @@ void shift_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
// Affect the canvas on release:
void shift_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
shift_doit(api, which, canvas, last, x, y, x, y, update_rect, 0);
api->stopsound();
@ -328,15 +322,17 @@ int shift_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_
return 0;
}
void shift_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void shift_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void shift_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void shift_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int shift_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_PAINT_WITH_PREVIEW);
return (MODE_PAINT_WITH_PREVIEW);
}

View file

@ -37,25 +37,21 @@
/* Our globals: */
static Mix_Chunk * smudge_snd;
static Mix_Chunk *smudge_snd;
static Uint8 smudge_r, smudge_g, smudge_b;
int smudge_init(magic_api * api);
Uint32 smudge_api_version(void);
SDL_Surface * smudge_get_icon(magic_api * api, int which);
char * smudge_get_name(magic_api * api, int which);
char * smudge_get_description(magic_api * api, int which, int mode);
static void do_smudge(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
int x, int y);
SDL_Surface *smudge_get_icon(magic_api * api, int which);
char *smudge_get_name(magic_api * api, int which);
char *smudge_get_description(magic_api * api, int which, int mode);
static void do_smudge(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
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);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void smudge_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void smudge_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void smudge_shutdown(magic_api * api);
void smudge_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int smudge_requires_colors(magic_api * api, int which);
@ -69,63 +65,62 @@ int smudge_init(magic_api * api)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/sounds/magic/smudge.wav",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/sounds/magic/smudge.wav", api->data_directory);
smudge_snd = Mix_LoadWAV(fname);
return(1);
return (1);
}
Uint32 smudge_api_version(void) { return(TP_MAGIC_API_VERSION); }
Uint32 smudge_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
// We have multiple tools:
int smudge_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return(2);
return (2);
}
// Load our icons:
SDL_Surface * smudge_get_icon(magic_api * api, int which)
SDL_Surface *smudge_get_icon(magic_api * api, int which)
{
char fname[1024];
if (which == 0)
snprintf(fname, sizeof(fname), "%s/images/magic/smudge.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/smudge.png", api->data_directory);
else /* if (which == 1) */
snprintf(fname, sizeof(fname), "%s/images/magic/wetpaint.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/wetpaint.png", api->data_directory);
return(IMG_Load(fname));
return (IMG_Load(fname));
}
// Return our names, localized:
char * smudge_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
char *smudge_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
{
if (which == 0)
return(strdup(gettext_noop("Smudge")));
return (strdup(gettext_noop("Smudge")));
else /* if (which == 1) */
return(strdup(gettext_noop("Wet Paint")));
return (strdup(gettext_noop("Wet Paint")));
}
// Return our descriptions, localized:
char * smudge_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
char *smudge_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
{
if (which == 0)
return(strdup(gettext_noop("Click and drag the mouse around to smudge the picture.")));
return (strdup(gettext_noop("Click and drag the mouse around to smudge the picture.")));
else /* if (which == 1) */
return(strdup(gettext_noop("Click and drag the mouse around to draw with wet, smudgy paint.")));
return (strdup(gettext_noop("Click and drag the mouse around to draw with wet, smudgy paint.")));
}
// Do the effect:
static void do_smudge(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
int x, int y)
static void do_smudge(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
static double state[32][32][3];
unsigned i = 32 * 32;
double rate = api->button_down() ? 0.5 : 0.0;
double rate = api->button_down()? 0.5 : 0.0;
Uint8 r, g, b;
int xx, yy, strength;
@ -136,11 +131,10 @@ static void do_smudge(void * ptr, int which, SDL_Surface * canvas, SDL_Surface *
for (xx = -8; xx < 8; xx++)
if (api->in_circle(xx, yy, 8))
{
SDL_GetRGB(api->getpixel(last, x + xx, y + yy),
last->format, &r, &g, &b);
SDL_GetRGB(api->getpixel(last, x + xx, y + yy), last->format, &r, &g, &b);
//strength = (abs(xx * yy) / 8) + 6;
strength = (abs(xx * yy) / 8) + 1;
api->putpixel(canvas, x + xx, y +yy, SDL_MapRGB(canvas->format,
api->putpixel(canvas, x + xx, y + yy, SDL_MapRGB(canvas->format,
(smudge_r + r * strength) / (strength + 1),
(smudge_g + g * strength) / (strength + 1),
(smudge_b + b * strength) / (strength + 1)));
@ -151,39 +145,46 @@ static void do_smudge(void * ptr, int which, SDL_Surface * canvas, SDL_Surface *
{
int iy = i >> 5;
int ix = i & 0x1f;
// is it not on the circle of radius sqrt(120) at location 16,16?
if ((ix - 16) * (ix - 16) + (iy - 16) * (iy - 16) > 120)
continue;
// it is on the circle, so grab it
SDL_GetRGB(api->getpixel(canvas, x + ix - 16, y + iy - 16),
last->format, &r, &g, &b);
state[ix][iy][0] =
rate * state[ix][iy][0] + (1.0 - rate) * api->sRGB_to_linear(r);
state[ix][iy][1] =
rate * state[ix][iy][1] + (1.0 - rate) * api->sRGB_to_linear(g);
state[ix][iy][2] =
rate * state[ix][iy][2] + (1.0 - rate) * api->sRGB_to_linear(b);
SDL_GetRGB(api->getpixel(canvas, x + ix - 16, y + iy - 16), last->format, &r, &g, &b);
state[ix][iy][0] = rate * state[ix][iy][0] + (1.0 - rate) * api->sRGB_to_linear(r);
state[ix][iy][1] = rate * state[ix][iy][1] + (1.0 - rate) * api->sRGB_to_linear(g);
state[ix][iy][2] = rate * state[ix][iy][2] + (1.0 - rate) * api->sRGB_to_linear(b);
// opacity 100% --> new data not blended w/ existing data
api->putpixel(canvas, x + ix - 16, y + iy - 16,
SDL_MapRGB(canvas->format, api->linear_to_sRGB(state[ix][iy][0]),
api->linear_to_sRGB(state[ix][iy][1]),
api->linear_to_sRGB(state[ix][iy][2])));
api->linear_to_sRGB(state[ix][iy][1]), api->linear_to_sRGB(state[ix][iy][2])));
}
}
// Affect the canvas on drag:
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)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *) api, 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);
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;
}
update_rect->x = ox - 16;
update_rect->y = oy - 16;
@ -193,8 +194,7 @@ void smudge_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void smudge_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
smudge_drag(api, which, canvas, last, x, y, x, y, update_rect);
}
@ -230,15 +230,17 @@ int smudge_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE
return 1;
}
void smudge_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void smudge_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void smudge_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void smudge_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int smudge_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_PAINT);
return (MODE_PAINT);
}

View file

@ -45,30 +45,34 @@
static const int snow_AMOUNT = 400;
static const int snow_RADIUS = 5;
static SDL_Surface * snow_flake1;
static SDL_Surface * snow_flake2;
static SDL_Surface *snow_flake1;
static SDL_Surface *snow_flake2;
enum {
enum
{
TOOL_SNOWBALL,
TOOL_SNOWFLAKE,
snow_NUM_TOOLS
};
static Mix_Chunk * snow_snd_effect[snow_NUM_TOOLS];
static Mix_Chunk *snow_snd_effect[snow_NUM_TOOLS];
const char * snow_snd_filenames[snow_NUM_TOOLS] = {
const char *snow_snd_filenames[snow_NUM_TOOLS] = {
"snowball.ogg",
"snowflake.ogg",
};
const char * snow_icon_filenames[snow_NUM_TOOLS] = {
const char *snow_icon_filenames[snow_NUM_TOOLS] = {
"snowball.png",
"snowflake.png",
};
const char * snow_names[snow_NUM_TOOLS] = {
const char *snow_names[snow_NUM_TOOLS] = {
gettext_noop("Snow Ball"),
gettext_noop("Snow Flake"),
};
const char * snow_descs[snow_NUM_TOOLS] = {
const char *snow_descs[snow_NUM_TOOLS] = {
gettext_noop("Click to add snow balls to your picture."),
gettext_noop("Click to add snow flakes to your picture."),
};
@ -76,103 +80,126 @@ const char * snow_descs[snow_NUM_TOOLS] = {
Uint32 snow_api_version(void);
int snow_init(magic_api * api);
int snow_get_tool_count(magic_api * api);
SDL_Surface * snow_get_icon(magic_api * api, int which);
char * snow_get_name(magic_api * api, int which);
char * snow_get_description(magic_api * api, int which);
static void do_snow(void * ptr,SDL_Surface * canvas, SDL_Surface * last, int which, int snowAmount);
SDL_Surface *snow_get_icon(magic_api * api, int which);
char *snow_get_name(magic_api * api, int which);
char *snow_get_description(magic_api * api, int which);
static void do_snow(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int which, int snowAmount);
void snow_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void snow_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void snow_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void snow_shutdown(magic_api * api);
void snow_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int snow_requires_colors(magic_api * api, int which);
void snow_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void snow_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int snow_modes(magic_api * api, int which);
Uint32 snow_api_version(void) { return(TP_MAGIC_API_VERSION); }
Uint32 snow_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
//Load sounds
int snow_init(magic_api * api){
int snow_init(magic_api * api)
{
int i;
char fname[1024];
srand(time(0));
snprintf(fname, sizeof(fname), "%s/images/magic/Snow_flake4.png", api->data_directory);
snow_flake1 = IMG_Load(fname);
if (snow_flake1==NULL){
return(0);
if (snow_flake1 == NULL)
{
return (0);
}
snprintf(fname, sizeof(fname), "%s/images/magic/Snow_flake5.png", api->data_directory);
snow_flake2 = IMG_Load(fname);
if (snow_flake2==NULL){
return(0);
if (snow_flake2 == NULL)
{
return (0);
}
if (snow_flake2==NULL){printf("meh\n");}
for (i = 0; i < snow_NUM_TOOLS; i++){
if (snow_flake2 == NULL)
{
printf("meh\n");
}
for (i = 0; i < snow_NUM_TOOLS; i++)
{
snprintf(fname, sizeof(fname), "%s/sounds/magic/%s", api->data_directory, snow_snd_filenames[i]);
snow_snd_effect[i] = Mix_LoadWAV(fname);
}
return(1);
return (1);
}
int snow_get_tool_count(magic_api * api ATTRIBUTE_UNUSED){
return(snow_NUM_TOOLS);
int snow_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return (snow_NUM_TOOLS);
}
// Load our icons:
SDL_Surface * snow_get_icon(magic_api * api, int which){
SDL_Surface *snow_get_icon(magic_api * api, int which)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, snow_icon_filenames[which]);
return(IMG_Load(fname));
return (IMG_Load(fname));
}
// Return our names, localized:
char * snow_get_name(magic_api * api ATTRIBUTE_UNUSED, int which){
return(strdup(gettext_noop(snow_names[which])));
char *snow_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
{
return (strdup(gettext_noop(snow_names[which])));
}
// Return our descriptions, localized:
char * snow_get_description(magic_api * api ATTRIBUTE_UNUSED, int which){
return(strdup(gettext_noop(snow_descs[which])));
char *snow_get_description(magic_api * api ATTRIBUTE_UNUSED, int which)
{
return (strdup(gettext_noop(snow_descs[which])));
}
// Do the effect:
static void do_snow(void * ptr,SDL_Surface * canvas, SDL_Surface * last, int which, int snowAmount){
magic_api * api = (magic_api *) ptr;
static void do_snow(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int which, int snowAmount)
{
magic_api *api = (magic_api *) ptr;
int i,x,y,centre_x,centre_y;
Uint8 r,g,b;
int i, x, y, centre_x, centre_y;
Uint8 r, g, b;
SDL_Rect dest;
for(i=0; i<snowAmount; i++){
for (i = 0; i < snowAmount; i++)
{
centre_x = rand() % canvas->w;
centre_y = rand() % canvas->h;
if (which == TOOL_SNOWBALL){
for (y = -snow_RADIUS; y < snow_RADIUS; y++){
for (x= -snow_RADIUS; x < snow_RADIUS; x++){
if (api->in_circle(x ,y, snow_RADIUS)){
if (which == TOOL_SNOWBALL)
{
for (y = -snow_RADIUS; y < snow_RADIUS; y++)
{
for (x = -snow_RADIUS; x < snow_RADIUS; x++)
{
if (api->in_circle(x, y, snow_RADIUS))
{
SDL_GetRGB(api->getpixel(last, centre_x + x, centre_y + y), last->format, &r, &g, &b);
api->putpixel(canvas, centre_x + x, centre_y + y, SDL_MapRGB(canvas->format, 255, 255, 255));
}
}
}
}
if(which == TOOL_SNOWFLAKE){
if (which == TOOL_SNOWFLAKE)
{
dest.x = centre_x;
dest.y = centre_y;
if (rand()%2==0){
if (rand() % 2 == 0)
{
SDL_BlitSurface(snow_flake1, NULL, canvas, &dest);
}else {
}
else
{
SDL_BlitSurface(snow_flake2, NULL, canvas, &dest);
}
}
@ -181,15 +208,17 @@ static void do_snow(void * ptr,SDL_Surface * canvas, SDL_Surface * last, int whi
// Affect the canvas on drag:
void snow_drag(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED){
SDL_Surface * last ATTRIBUTE_UNUSED, int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED,
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
// No-op
}
// Affect the canvas on click:
void snow_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last,
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect){
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect)
{
update_rect->x = 0;
update_rect->y = 0;
update_rect->w = canvas->w;
@ -211,21 +240,27 @@ void snow_shutdown(magic_api * api ATTRIBUTE_UNUSED)
{
//Clean up sounds
int i;
for(i=0; i<snow_NUM_TOOLS; i++){
if(snow_snd_effect[i] != NULL){
for (i = 0; i < snow_NUM_TOOLS; i++)
{
if (snow_snd_effect[i] != NULL)
{
Mix_FreeChunk(snow_snd_effect[i]);
}
}
if (snow_flake1 != NULL){
if (snow_flake1 != NULL)
{
SDL_FreeSurface(snow_flake1);
}
if (snow_flake2 != NULL){
if (snow_flake2 != NULL)
{
SDL_FreeSurface(snow_flake2);
}
}
// Record the color from Tux Paint:
void snow_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
void snow_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED)
{
}
@ -235,15 +270,17 @@ int snow_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_U
return 0;
}
void snow_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED){
void snow_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void snow_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void snow_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int snow_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_FULLSCREEN);
return (MODE_FULLSCREEN);
}

View file

@ -6,18 +6,20 @@ unsigned int img_w, img_h;
static Uint8 string_r, string_g, string_b;
static int string_ox, string_oy;
static int string_vertex_x, string_vertex_y, string_vertex_done, string_vertex_distance;
static SDL_Surface * canvas_backup;
enum string_tools{
static SDL_Surface *canvas_backup;
enum string_tools
{
STRING_TOOL_FULL_BY_OFFSET,
STRING_TOOL_TRIANGLE,
STRING_TOOL_ANGLE,
STRING_NUMTOOLS};
STRING_NUMTOOLS
};
Mix_Chunk *string_snd[STRING_NUMTOOLS];
Mix_Chunk * string_snd[STRING_NUMTOOLS];
// Custom function declarations
void string_callback(void * ptr, int which_tool,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
void string_callback(void *ptr, int which_tool, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
void string_draw_triangle(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
@ -30,74 +32,72 @@ void string_draw_triangle_preview(magic_api * api, int which,
void string_draw_angle_preview(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
void scale_xcoord(int * xcoord);
void scale_ycoord(int * ycoord);
void scale_coords(int * ox, int * oy, int * x, int * y);
void scale_xcoord(int *xcoord);
void scale_ycoord(int *ycoord);
void scale_coords(int *ox, int *oy, int *x, int *y);
void string_draw_wrapper(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
void string_set_vertex(int x, int y);
void compute_middle( int start_point, int end_point, int vertex, int * middle);
void compute_middle(int start_point, int end_point, int vertex, int *middle);
// Prototypes for required functions
void string_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);
Uint32 string_api_version(void);
int string_modes(magic_api * api, int which);
void string_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int string_get_tool_count(magic_api * api);
SDL_Surface * string_get_icon(magic_api * api, int which);
char * string_get_name(magic_api * api, int which);
char * string_get_description(magic_api * api, int which, int mode);
SDL_Surface *string_get_icon(magic_api * api, int which);
char *string_get_name(magic_api * api, int which);
char *string_get_description(magic_api * api, int which, int mode);
int string_requires_colors(magic_api * api, int which);
void string_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);
int string_init(magic_api * api);
void string_shutdown(magic_api * api);
void string_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * snapshot);
void string_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * snapshot);
void string_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);
// Required functions
Uint32 string_api_version(void)
{
return(TP_MAGIC_API_VERSION);
return (TP_MAGIC_API_VERSION);
}
int string_modes(__attribute__((unused)) magic_api * api, int which)
int string_modes( __attribute__ ((unused)) magic_api * api, int which)
{
if (which == STRING_TOOL_FULL_BY_OFFSET)
return(MODE_PAINT);
return (MODE_PAINT);
else
return(MODE_PAINT_WITH_PREVIEW);
return (MODE_PAINT_WITH_PREVIEW);
}
void string_set_color(__attribute__((unused)) magic_api * api, Uint8 r, Uint8 g, Uint8 b)
void string_set_color( __attribute__ ((unused)) magic_api * api, Uint8 r, Uint8 g, Uint8 b)
{
string_r=r;
string_g=g;
string_b=b;
string_r = r;
string_g = g;
string_b = b;
}
int string_get_tool_count(__attribute__((unused)) magic_api * api)
int string_get_tool_count( __attribute__ ((unused)) magic_api * api)
{
return STRING_NUMTOOLS;
}
SDL_Surface * string_get_icon(magic_api * api, int which)
SDL_Surface *string_get_icon(magic_api * api, int which)
{
char fname[1024];
switch (which)
{
case STRING_TOOL_FULL_BY_OFFSET:
@ -111,11 +111,12 @@ SDL_Surface * string_get_icon(magic_api * api, int which)
break;
}
return(IMG_Load(fname));
return (IMG_Load(fname));
}
char * string_get_name(__attribute__((unused)) magic_api * api, __attribute__((unused)) int which)
char *string_get_name( __attribute__ ((unused)) magic_api * api, __attribute__ ((unused))
int which)
{
switch (which)
{
@ -130,11 +131,15 @@ char * string_get_name(__attribute__((unused)) magic_api * api, __attribute__((u
}
}
char * string_get_description(__attribute__((unused)) magic_api * api, int which, __attribute__((unused)) int mode) {
char *string_get_description( __attribute__ ((unused)) magic_api * api, int which, __attribute__ ((unused))
int mode)
{
switch (which)
{
case STRING_TOOL_FULL_BY_OFFSET:
return strdup(gettext_noop("Click and drag to draw string art. Drag top-bottom to draw less or more lines, left or right to make a bigger hole."));
return
strdup(gettext_noop
("Click and drag to draw string art. Drag top-bottom to draw less or more lines, left or right to make a bigger hole."));
break;
case STRING_TOOL_TRIANGLE:
return strdup(gettext_noop("Click and drag to draw arrows made of string art."));
@ -144,48 +149,49 @@ char * string_get_description(__attribute__((unused)) magic_api * api, int which
}
}
int string_requires_colors(__attribute__((unused)) magic_api * api, __attribute__((unused)) int which) { return 1;}
int string_requires_colors( __attribute__ ((unused)) magic_api * api, __attribute__ ((unused))
int which)
{
return 1;
}
void string_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)
{
int dx, dy;
if (which==STRING_TOOL_TRIANGLE)
string_draw_triangle((void *) api, which, canvas, snapshot, string_ox, string_oy, x, y, update_rect);
if (which==STRING_TOOL_ANGLE)
if (which == STRING_TOOL_TRIANGLE)
string_draw_triangle((void *)api, which, canvas, snapshot, string_ox, string_oy, x, y, update_rect);
if (which == STRING_TOOL_ANGLE)
{
if(!string_vertex_done) // maybe we face small children, draw square angles aligned to the drag
if (!string_vertex_done) // maybe we face small children, draw square angles aligned to the drag
{
dx=string_ox - x;
dy=string_oy - y;
y=y + dx;
x=x - dy;
dx = string_ox - x;
dy = string_oy - y;
y = y + dx;
x = x - dy;
}
string_draw_angle((void *) api, which, canvas, snapshot, string_ox, string_oy, x, y, update_rect);
string_draw_angle((void *)api, which, canvas, snapshot, string_ox, string_oy, x, y, update_rect);
}
}
int string_init(__attribute__((unused)) magic_api * api)
int string_init( __attribute__ ((unused)) magic_api * api)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/sounds/magic/string.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/sounds/magic/string.ogg", api->data_directory);
string_snd[STRING_TOOL_FULL_BY_OFFSET] = Mix_LoadWAV(fname);
snprintf(fname, sizeof(fname), "%s/sounds/magic/string2.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/sounds/magic/string2.ogg", api->data_directory);
string_snd[STRING_TOOL_TRIANGLE] = Mix_LoadWAV(fname);
snprintf(fname, sizeof(fname), "%s/sounds/magic/string3.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/sounds/magic/string3.ogg", api->data_directory);
string_snd[STRING_TOOL_ANGLE] = Mix_LoadWAV(fname);
return(1);
return (1);
}
void string_shutdown(__attribute__((unused)) magic_api * api)
void string_shutdown( __attribute__ ((unused)) magic_api * api)
{
int i = 0;
@ -196,129 +202,139 @@ void string_shutdown(__attribute__((unused)) magic_api * api)
{
if (string_snd[i] != NULL)
Mix_FreeChunk(string_snd[i]);
i ++;
i++;
}
}
void string_switchin(__attribute__((unused)) magic_api * api, __attribute__((unused)) int which, __attribute__((unused)) int mode, SDL_Surface * canvas, __attribute__((unused)) SDL_Surface * snapshot)
void string_switchin( __attribute__ ((unused)) magic_api * api, __attribute__ ((unused))
int which, __attribute__ ((unused))
int mode, SDL_Surface * canvas, __attribute__ ((unused)) SDL_Surface * snapshot)
{
canvas_backup=SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
canvas_backup = SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h, canvas->format->BitsPerPixel,
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask,
canvas->format->Amask);
}
void string_switchout(__attribute__((unused)) magic_api * api, __attribute__((unused)) int which, __attribute__((unused)) int mode, __attribute__((unused)) SDL_Surface * canvas, __attribute__((unused)) SDL_Surface * snapshot)
void string_switchout( __attribute__ ((unused)) magic_api * api, __attribute__ ((unused))
int which, __attribute__ ((unused))
int mode, __attribute__ ((unused)) SDL_Surface * canvas,
__attribute__ ((unused)) SDL_Surface * snapshot)
{
SDL_FreeSurface(canvas_backup);
canvas_backup=NULL;
canvas_backup = NULL;
}
// Interactivity functions
void string_callback(void * ptr,__attribute__((unused)) int which,
SDL_Surface * canvas,__attribute__((unused)) SDL_Surface * snapshot, int x, int y)
void string_callback(void *ptr, __attribute__ ((unused))
int which, SDL_Surface * canvas, __attribute__ ((unused)) SDL_Surface * snapshot, int x, int y)
{
magic_api * api = (magic_api *) ptr;
api->putpixel(canvas, x, y, SDL_MapRGBA(canvas->format, string_r, string_g, string_b,255));
magic_api *api = (magic_api *) ptr;
api->putpixel(canvas, x, y, SDL_MapRGBA(canvas->format, string_r, string_g, string_b, 255));
}
void string_click(magic_api * api, int which,__attribute__((unused)) int mode,
SDL_Surface * canvas, SDL_Surface * snapshot,
int x, int y, SDL_Rect * update_rect)
void string_click(magic_api * api, int which, __attribute__ ((unused))
int mode, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
{
SDL_BlitSurface(canvas, NULL, canvas_backup, NULL);
string_ox=x;
string_oy=y;
string_vertex_distance=0;
string_vertex_done=0;
string_ox = x;
string_oy = y;
string_vertex_distance = 0;
string_vertex_done = 0;
string_drag(api, which, canvas, snapshot, x, y, x, y, update_rect);
}
static void string_draw_full_by_offset(void * ptr, __attribute__((unused)) int which, SDL_Surface * canvas, __attribute__((unused)) SDL_Surface * snapshot,
static void string_draw_full_by_offset(void *ptr, __attribute__ ((unused))
int which, SDL_Surface * canvas, __attribute__ ((unused)) SDL_Surface * snapshot,
int x, int y, SDL_Rect * update_rect)
{
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
int u;
int i;
int o; //offset
// int n=y/5;
int ** a;
int **a;
float step_w, step_h, aux;
int side=(int)(y/3);
int side = (int)(y / 3);
SDL_BlitSurface(snapshot,0,canvas,0);
SDL_BlitSurface(snapshot, 0, canvas, 0);
if (side<3) side=3;
if (side < 3)
side = 3;
o=(int)(side*4*x/canvas->w);
step_w=canvas->w/(float)side;
step_h=canvas->h/(float)side;
o = (int)(side * 4 * x / canvas->w);
step_w = canvas->w / (float)side;
step_h = canvas->h / (float)side;
a=malloc(sizeof(int*)*side*4*2);
a = malloc(sizeof(int *) * side * 4 * 2);
for (i=0;i<side*4;i++)
for (i = 0; i < side * 4; i++)
{
a[i]=malloc(sizeof(int*)*2);
if (i<side)
a[i] = malloc(sizeof(int *) * 2);
if (i < side)
{
a[i][0]= 0;
aux=step_h*(float)i;
a[i][1]= (int)aux;
a[i][0] = 0;
aux = step_h * (float)i;
a[i][1] = (int)aux;
}
else
if(i<(side*2))
else if (i < (side * 2))
{
a[i][0]= (int)((float)(i%side)*step_w);
a[i][1]= canvas->h;
a[i][0] = (int)((float)(i % side) * step_w);
a[i][1] = canvas->h;
}
else
if (i<(int)(side*3))
else if (i < (int)(side * 3))
{
a[i][0]= canvas->w;
a[i][1]= (int)(canvas->h - (float)((i%side)*step_h));
a[i][0] = canvas->w;
a[i][1] = (int)(canvas->h - (float)((i % side) * step_h));
}
else
if (i<(int)(side*4))
else if (i < (int)(side * 4))
{
a[i][0]=(int)( canvas->w-((float)((i%side)*step_w)));
a[i][1]= 0;
a[i][0] = (int)(canvas->w - ((float)((i % side) * step_w)));
a[i][1] = 0;
}
}
for (i=0;i<side*4;i++)
for (i = 0; i < side * 4; i++)
{
u=(i+o)%(side*4);
api->line((void *) api, which, canvas, snapshot,a[i][0],a[i][1],a[u][0],a[u][1],1, string_callback);
u = (i + o) % (side * 4);
api->line((void *)api, which, canvas, snapshot, a[i][0], a[i][1], a[u][0], a[u][1], 1, string_callback);
}
for (i=0;i<side*4;i++)
for (i = 0; i < side * 4; i++)
{
free( a[i]);
free(a[i]);
}
free(a);
update_rect->x=0;
update_rect->y=0;
update_rect->w=canvas->w;
update_rect->h=canvas->h;
update_rect->x = 0;
update_rect->y = 0;
update_rect->w = canvas->w;
update_rect->h = canvas->h;
}
void scale_xcoord(int * xcoord)
void scale_xcoord(int *xcoord)
{
if (*xcoord < string_ox) *xcoord=string_ox-(string_ox - *xcoord)*4;
else *xcoord=string_ox+(*xcoord-string_ox)*4;
if (*xcoord < string_ox)
*xcoord = string_ox - (string_ox - *xcoord) * 4;
else
*xcoord = string_ox + (*xcoord - string_ox) * 4;
}
void scale_ycoord(int * ycoord)
void scale_ycoord(int *ycoord)
{
if (*ycoord < string_oy) *ycoord=string_oy-(string_oy - *ycoord)*4;
else *ycoord=string_oy+(*ycoord-string_oy)*4;
if (*ycoord < string_oy)
*ycoord = string_oy - (string_oy - *ycoord) * 4;
else
*ycoord = string_oy + (*ycoord - string_oy) * 4;
}
void scale_coords(int * ox, int * oy, int * x, int * y)
void scale_coords(int *ox, int *oy, int *x, int *y)
{
scale_xcoord(ox);
scale_xcoord(x);
@ -326,10 +342,10 @@ void scale_coords(int * ox, int * oy, int * x, int * y)
scale_ycoord(y);
}
void compute_middle( int start_point, int end_point, int vertex, int * middle)
void compute_middle(int start_point, int end_point, int vertex, int *middle)
{
*middle=min(start_point,end_point)+(max(start_point,end_point)-min(start_point,end_point))/2;
*middle=min(*middle,vertex)+(max(*middle,vertex)-min(*middle,vertex))/2;
*middle = min(start_point, end_point) + (max(start_point, end_point) - min(start_point, end_point)) / 2;
*middle = min(*middle, vertex) + (max(*middle, vertex) - min(*middle, vertex)) / 2;
}
void string_draw_triangle_preview(magic_api * api, int which,
@ -338,9 +354,10 @@ void string_draw_triangle_preview(magic_api * api, int which,
{
int middle_x, middle_y;
int w, h;
scale_coords(&ox, &oy,&x, &y);
w=max(string_ox,x)-min(string_ox,x);
h=max(string_oy,y)-min(string_oy,y);
scale_coords(&ox, &oy, &x, &y);
w = max(string_ox, x) - min(string_ox, x);
h = max(string_oy, y) - min(string_oy, y);
/*
This is enouth if you move the mouse slowly, but if you move the mouse fast,
@ -350,137 +367,149 @@ void string_draw_triangle_preview(magic_api * api, int which,
update_rect->x=min(string_ox,x) -40;
update_rect->y=min(string_oy,y) -40;
*/
update_rect->x=0;
update_rect->y=0;
update_rect->w=canvas->w;
update_rect->h=canvas->h;
SDL_BlitSurface(canvas_backup,update_rect,canvas,update_rect);
update_rect->x = 0;
update_rect->y = 0;
update_rect->w = canvas->w;
update_rect->h = canvas->h;
SDL_BlitSurface(canvas_backup, update_rect, canvas, update_rect);
compute_middle(x, string_ox, string_ox, &middle_x);
compute_middle(y, string_oy, string_oy, &middle_y);
api->line((void *) api, which, canvas, snapshot, string_ox,string_oy, string_ox , y,1, string_callback);
api->line((void *) api, which, canvas, snapshot, string_ox,string_oy, x , string_oy,1, string_callback);
api->line((void *) api, which, canvas, snapshot, middle_x,middle_y, x , string_oy,1, string_callback);
api->line((void *) api, which, canvas, snapshot, string_ox,y, middle_x , middle_y,1, string_callback);
api->line((void *)api, which, canvas, snapshot, string_ox, string_oy, string_ox, y, 1, string_callback);
api->line((void *)api, which, canvas, snapshot, string_ox, string_oy, x, string_oy, 1, string_callback);
api->line((void *)api, which, canvas, snapshot, middle_x, middle_y, x, string_oy, 1, string_callback);
api->line((void *)api, which, canvas, snapshot, string_ox, y, middle_x, middle_y, 1, string_callback);
}
void string_draw_angle_preview(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, __attribute__((unused)) int ox, __attribute__ ((unused)) int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * snapshot, __attribute__ ((unused))
int ox, __attribute__ ((unused))
int oy, int x, int y, SDL_Rect * update_rect)
{
int w, h;
int middle_x, middle_y;
int dx, dy;
w=max(string_ox,x)-min(string_ox,x);
h=max(string_oy,y)-min(string_oy,y);
update_rect->x=0;
update_rect->y=0;
update_rect->w=canvas->w;
update_rect->h=canvas->h;
SDL_BlitSurface(canvas_backup,update_rect,canvas,update_rect);
w = max(string_ox, x) - min(string_ox, x);
h = max(string_oy, y) - min(string_oy, y);
api->line((void *) api, which, canvas, snapshot, string_ox,string_oy, string_vertex_x , string_vertex_y,1, string_callback);
if(!string_vertex_done)
update_rect->x = 0;
update_rect->y = 0;
update_rect->w = canvas->w;
update_rect->h = canvas->h;
SDL_BlitSurface(canvas_backup, update_rect, canvas, update_rect);
api->line((void *)api, which, canvas, snapshot, string_ox, string_oy, string_vertex_x, string_vertex_y, 1,
string_callback);
if (!string_vertex_done)
{
// if(!string_vertex_done) // maybe we face small children, draw square angles aligned to the drag
//{
dx=string_ox - x;
dy=string_oy - y;
y=y + dx;
x=x - dy;
dx = string_ox - x;
dy = string_oy - y;
y = y + dx;
x = x - dy;
}
compute_middle(string_ox, x, string_vertex_x, &middle_x);
compute_middle(string_oy, y, string_vertex_y, &middle_y);
api->line((void *) api, which, canvas, snapshot, string_vertex_x,string_vertex_y, x , y,1, string_callback);
api->line((void *) api, which, canvas, snapshot, string_ox,string_oy, middle_x , middle_y,1, string_callback);
api->line((void *) api, which, canvas, snapshot, x, y, middle_x , middle_y,1, string_callback);
api->line((void *)api, which, canvas, snapshot, string_vertex_x, string_vertex_y, x, y, 1, string_callback);
api->line((void *)api, which, canvas, snapshot, string_ox, string_oy, middle_x, middle_y, 1, string_callback);
api->line((void *)api, which, canvas, snapshot, x, y, middle_x, middle_y, 1, string_callback);
}
void string_draw_angle(magic_api * api, __attribute__((unused)) int which,
SDL_Surface * canvas, __attribute__((unused))SDL_Surface * snapshot, __attribute__ ((unused)) int ox, __attribute__ ((unused)) int oy, int x, int y,
SDL_Rect * update_rect)
void string_draw_angle(magic_api * api, __attribute__ ((unused))
int which,
SDL_Surface * canvas, __attribute__ ((unused)) SDL_Surface * snapshot, __attribute__ ((unused))
int ox, __attribute__ ((unused))
int oy, int x, int y, SDL_Rect * update_rect)
{
float first_arm_step_x, first_arm_step_y, second_arm_step_x, second_arm_step_y;
int i;
int max_wh , steps;
int max_separation=10;
int max_wh, steps;
int max_separation = 10;
update_rect->x=min(min(string_ox,string_vertex_x),x);
update_rect->y=min(min(string_oy,string_vertex_y),y);
update_rect->w=max(max(string_ox,string_vertex_x),x)-update_rect->x;
update_rect->h=max(max(string_oy,string_vertex_y),y)-update_rect->y;
SDL_BlitSurface(canvas_backup,update_rect,canvas,update_rect);
update_rect->x = min(min(string_ox, string_vertex_x), x);
update_rect->y = min(min(string_oy, string_vertex_y), y);
update_rect->w = max(max(string_ox, string_vertex_x), x) - update_rect->x;
update_rect->h = max(max(string_oy, string_vertex_y), y) - update_rect->y;
SDL_BlitSurface(canvas_backup, update_rect, canvas, update_rect);
max_wh= max( max(max(string_ox,string_vertex_x),x)- min(min(string_vertex_x , x),string_ox) , max(max(string_oy , string_vertex_y),y)- min(min(string_vertex_y ,y),string_oy));
max_wh =
max(max(max(string_ox, string_vertex_x), x) - min(min(string_vertex_x, x), string_ox),
max(max(string_oy, string_vertex_y), y) - min(min(string_vertex_y, y), string_oy));
steps=max_wh/max_separation;
first_arm_step_x=(float)(string_ox-string_vertex_x)/(float)steps;
first_arm_step_y=(float)(string_oy-string_vertex_y)/(float)steps;
second_arm_step_x=(float)(string_vertex_x-x)/(float)steps;
second_arm_step_y=(float)(string_vertex_y-y)/(float)steps;
steps = max_wh / max_separation;
first_arm_step_x = (float)(string_ox - string_vertex_x) / (float)steps;
first_arm_step_y = (float)(string_oy - string_vertex_y) / (float)steps;
second_arm_step_x = (float)(string_vertex_x - x) / (float)steps;
second_arm_step_y = (float)(string_vertex_y - y) / (float)steps;
for (i=0;i<=steps;i++)
for (i = 0; i <= steps; i++)
{
api->line((void *) api, 0, canvas, snapshot, string_ox-first_arm_step_x*i,string_oy-first_arm_step_y*i, string_vertex_x-second_arm_step_x*i,string_vertex_y-second_arm_step_y*i,1, string_callback);
api->line((void *)api, 0, canvas, snapshot, string_ox - first_arm_step_x * i, string_oy - first_arm_step_y * i,
string_vertex_x - second_arm_step_x * i, string_vertex_y - second_arm_step_y * i, 1, string_callback);
}
}
void string_draw_triangle(magic_api * api, __attribute__((unused)) int which,
void string_draw_triangle(magic_api * api, __attribute__ ((unused))
int which,
SDL_Surface * canvas, SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
{
SDL_BlitSurface(canvas_backup,0,canvas,0);
scale_coords(&ox, &oy,&x, &y);
SDL_BlitSurface(canvas_backup, 0, canvas, 0);
scale_coords(&ox, &oy, &x, &y);
string_vertex_x=string_ox;
string_vertex_y=string_oy;
string_ox=string_vertex_x;
string_oy=y;
y=string_vertex_y;
string_vertex_x = string_ox;
string_vertex_y = string_oy;
string_ox = string_vertex_x;
string_oy = y;
y = string_vertex_y;
string_draw_angle((void *) api, which, canvas, snapshot, string_ox, string_oy, x, y, update_rect);
string_draw_angle((void *)api, which, canvas, snapshot, string_ox, string_oy, x, y, update_rect);
}
void string_draw_wrapper(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
{
if (which==STRING_TOOL_FULL_BY_OFFSET)
string_draw_full_by_offset((void *) api, which, canvas, snapshot, x, y, update_rect);
else if (which==STRING_TOOL_TRIANGLE)
string_draw_triangle_preview ((void *) api, which, canvas, snapshot, ox, oy, x, y, update_rect);
else if (which==STRING_TOOL_ANGLE)
string_draw_angle_preview ((void *) api, which, canvas, snapshot, ox, oy, x, y, update_rect);
if (which == STRING_TOOL_FULL_BY_OFFSET)
string_draw_full_by_offset((void *)api, which, canvas, snapshot, x, y, update_rect);
else if (which == STRING_TOOL_TRIANGLE)
string_draw_triangle_preview((void *)api, which, canvas, snapshot, ox, oy, x, y, update_rect);
else if (which == STRING_TOOL_ANGLE)
string_draw_angle_preview((void *)api, which, canvas, snapshot, ox, oy, x, y, update_rect);
}
void string_set_vertex(int x, int y)
{
int dx, dy;
if (string_vertex_done) return;
dx=max(string_ox,x)-min(string_ox,x);
dy=max(string_oy,y)-min(string_oy,y);
if(dx+dy>string_vertex_distance)
if (string_vertex_done)
return;
dx = max(string_ox, x) - min(string_ox, x);
dy = max(string_oy, y) - min(string_oy, y);
if (dx + dy > string_vertex_distance)
{
string_vertex_distance=dx+dy;
string_vertex_x=x;
string_vertex_y=y;
string_vertex_distance = dx + dy;
string_vertex_x = x;
string_vertex_y = y;
}
if(dx+dy+30<string_vertex_distance) string_vertex_done=1;
if (dx + dy + 30 < string_vertex_distance)
string_vertex_done = 1;
}
void string_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 * canvas, SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
if ((x<canvas->w)&&(y<canvas->h)&&(ox<canvas->w)&&(oy<canvas->h)&&((signed)x>0)&&((signed)y>0)&&((signed)ox>0)&&((signed)oy>0))
if ((x < canvas->w) && (y < canvas->h) && (ox < canvas->w) && (oy < canvas->h) && ((signed)x > 0) && ((signed)y > 0)
&& ((signed)ox > 0) && ((signed)oy > 0))
{
string_set_vertex(x,y);
string_draw_wrapper((void *) api, which, canvas, snapshot,ox,oy, x, y, update_rect);
string_set_vertex(x, y);
string_draw_wrapper((void *)api, which, canvas, snapshot, ox, oy, x, y, update_rect);
api->playsound(string_snd[which], (x * 255) / canvas->w, 255);
}

View file

@ -46,7 +46,8 @@
#define gettext_noop(String) String
#endif
enum {
enum
{
TOOL_TINT,
TOOL_THRESHOLD,
tint_NUM_TOOLS
@ -55,23 +56,26 @@ static Uint8 tint_r, tint_g, tint_b;
static int tint_min = INT_MAX;
static int tint_max = 0;
static const int tint_RADIUS =16;
static const int tint_RADIUS = 16;
static Mix_Chunk * tint_snd_effect[tint_NUM_TOOLS];
static Mix_Chunk *tint_snd_effect[tint_NUM_TOOLS];
const char * tint_snd_filenames[tint_NUM_TOOLS] = {
const char *tint_snd_filenames[tint_NUM_TOOLS] = {
"tint.wav",
"fold.ogg" /* FIXME */
};
const char * tint_icon_filenames[tint_NUM_TOOLS] = {
const char *tint_icon_filenames[tint_NUM_TOOLS] = {
"tint.png",
"colornwhite.png"
};
const char * tint_names[tint_NUM_TOOLS] = {
const char *tint_names[tint_NUM_TOOLS] = {
gettext_noop("Tint"),
gettext_noop("Color & White") // It does more than this but more intuitive than threshold.
};
const char * tint_descs[tint_NUM_TOOLS][2] = {
const char *tint_descs[tint_NUM_TOOLS][2] = {
{gettext_noop("Click and drag the mouse around to change the color of parts of your picture."),
gettext_noop("Click to change the color of your entire picture."),},
{gettext_noop("Click and drag the mouse around to turn parts of your picture into white and a color you choose."),
@ -81,24 +85,19 @@ const char * tint_descs[tint_NUM_TOOLS][2] = {
int tint_init(magic_api * api);
Uint32 tint_api_version(void);
int tint_get_tool_count(magic_api * api);
SDL_Surface * tint_get_icon(magic_api * api, int which);
char * tint_get_name(magic_api * api, int which);
char * tint_get_description(magic_api * api, int which, int mode);
static int tint_grey(Uint8 r1,Uint8 g1,Uint8 b1);
static void do_tint_pixel(void * ptr, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y);
static void do_tint_full(void * ptr,SDL_Surface * canvas, SDL_Surface * last, int which);
static void do_tint_brush(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
SDL_Surface *tint_get_icon(magic_api * api, int which);
char *tint_get_name(magic_api * api, int which);
char *tint_get_description(magic_api * api, int which, int mode);
static int tint_grey(Uint8 r1, Uint8 g1, Uint8 b1);
static void do_tint_pixel(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
static void do_tint_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int which);
static void do_tint_brush(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
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);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void tint_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void tint_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void tint_shutdown(magic_api * api);
void tint_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int tint_requires_colors(magic_api * api, int which);
@ -106,68 +105,85 @@ void tint_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void tint_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int tint_modes(magic_api * api, int which);
Uint32 tint_api_version(void) { return(TP_MAGIC_API_VERSION); }
Uint32 tint_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
//Load sounds
int tint_init(magic_api * api){
int tint_init(magic_api * api)
{
int i;
char fname[1024];
for (i = 0; i < tint_NUM_TOOLS; i++){
for (i = 0; i < tint_NUM_TOOLS; i++)
{
snprintf(fname, sizeof(fname), "%s/sounds/magic/%s", api->data_directory, tint_snd_filenames[i]);
tint_snd_effect[i] = Mix_LoadWAV(fname);
}
return(1);
return (1);
}
int tint_get_tool_count(magic_api * api ATTRIBUTE_UNUSED){
return(tint_NUM_TOOLS);
int tint_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return (tint_NUM_TOOLS);
}
// Load our icons:
SDL_Surface * tint_get_icon(magic_api * api, int which){
SDL_Surface *tint_get_icon(magic_api * api, int which)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, tint_icon_filenames[which]);
return(IMG_Load(fname));
return (IMG_Load(fname));
}
// Return our names, localized:
char * tint_get_name(magic_api * api ATTRIBUTE_UNUSED, int which){
return(strdup(gettext_noop(tint_names[which])));
char *tint_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
{
return (strdup(gettext_noop(tint_names[which])));
}
// Return our descriptions, localized:
char * tint_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode){
return(strdup(gettext_noop(tint_descs[which][mode-1])));
char *tint_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode)
{
return (strdup(gettext_noop(tint_descs[which][mode - 1])));
}
//Calculates the grey scale value for a rgb pixel
static int tint_grey(Uint8 r1,Uint8 g1,Uint8 b1){
return 0.3*r1+.59*g1+0.11*b1;
static int tint_grey(Uint8 r1, Uint8 g1, Uint8 b1)
{
return 0.3 * r1 + .59 * g1 + 0.11 * b1;
}
static void do_tint_pixel(void * ptr, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y){
static void do_tint_pixel(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
magic_api * api = (magic_api *) ptr;
Uint8 r,g,b;
float h,s,v;
magic_api *api = (magic_api *) ptr;
Uint8 r, g, b;
float h, s, v;
SDL_GetRGB(api->getpixel(last, x, y), last->format, &r, &g, &b);
{
int greyValue = tint_grey(r,g,b);
int greyValue = tint_grey(r, g, b);
if (which == TOOL_TINT){
if (which == TOOL_TINT)
{
api->rgbtohsv(tint_r, tint_g, tint_b, &h, &s, &v);
api->hsvtorgb(h, s, greyValue/255.0, &r, &g, &b);
api->hsvtorgb(h, s, greyValue / 255.0, &r, &g, &b);
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, r, g, b));
} else if (which == TOOL_THRESHOLD){
int thresholdValue = (tint_max-tint_min)/2;
if (greyValue < thresholdValue){
}
else if (which == TOOL_THRESHOLD)
{
int thresholdValue = (tint_max - tint_min) / 2;
if (greyValue < thresholdValue)
{
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, tint_r, tint_g, tint_b));
} else{
}
else
{
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, 255, 255, 255));
}
}
@ -175,25 +191,29 @@ int x, int y){
}
// Do the effect:
static void do_tint_full(void * ptr,SDL_Surface * canvas, SDL_Surface * last, int which){
int x,y;
for (y = 0; y < last->h; y++){
for (x=0; x < last->w; x++){
static void do_tint_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int which)
{
int x, y;
for (y = 0; y < last->h; y++)
{
for (x = 0; x < last->w; x++)
{
do_tint_pixel(ptr, which, canvas, last, x, y);
}
}
}
static void do_tint_brush(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y){
static void do_tint_brush(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
int xx, yy;
magic_api * api = (magic_api *) ptr;
magic_api *api = (magic_api *) ptr;
for (yy = y - tint_RADIUS; yy < y + tint_RADIUS; yy++)
{
for (xx = x - tint_RADIUS; xx < x + tint_RADIUS; xx++)
{
if (api->in_circle(xx - x, yy - y, tint_RADIUS) &&
!api->touched(xx, yy))
if (api->in_circle(xx - x, yy - y, tint_RADIUS) && !api->touched(xx, yy))
{
do_tint_pixel(api, which, canvas, last, xx, yy);
}
@ -203,15 +223,27 @@ static void do_tint_brush(void * ptr, int which, SDL_Surface * canvas, SDL_Surfa
// Affect the canvas on drag:
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){
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_tint_brush);
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_tint_brush);
api->playsound(tint_snd_effect[which], (x * 255) / canvas->w, 255);
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;
}
update_rect->x = ox - tint_RADIUS;
update_rect->y = oy - tint_RADIUS;
@ -221,11 +253,12 @@ void tint_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void tint_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect){
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
if (mode == MODE_PAINT)
tint_drag(api, which, canvas, last, x, y, x, y, update_rect);
else{
else
{
update_rect->x = 0;
update_rect->y = 0;
update_rect->w = canvas->w;
@ -247,8 +280,11 @@ void tint_shutdown(magic_api * api ATTRIBUTE_UNUSED)
{
//Clean up sounds
int i;
for(i=0; i<tint_NUM_TOOLS; i++){
if(tint_snd_effect[i] != NULL){
for (i = 0; i < tint_NUM_TOOLS; i++)
{
if (tint_snd_effect[i] != NULL)
{
Mix_FreeChunk(tint_snd_effect[i]);
}
}
@ -268,32 +304,39 @@ int tint_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_U
return 1;
}
void tint_switchin(magic_api * api, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas){
void tint_switchin(magic_api * api, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas)
{
int x,y;
Uint8 r1,g1,b1;
int x, y;
Uint8 r1, g1, b1;
for (y = 0; y < canvas->h; y++){
for (x=0; x < canvas->w; x++){
for (y = 0; y < canvas->h; y++)
{
for (x = 0; x < canvas->w; x++)
{
SDL_GetRGB(api->getpixel(canvas, x, y), canvas->format, &r1, &g1, &b1);
{
int greyValue = tint_grey(r1,g1,b1);
if (greyValue<tint_min){
tint_min=greyValue;
int greyValue = tint_grey(r1, g1, b1);
if (greyValue < tint_min)
{
tint_min = greyValue;
}
if (greyValue>tint_max){
tint_max=greyValue;
if (greyValue > tint_max)
{
tint_max = greyValue;
}
}
}
}
}
void tint_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void tint_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int tint_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_FULLSCREEN|MODE_PAINT);
return (MODE_FULLSCREEN | MODE_PAINT);
}

View file

@ -46,25 +46,29 @@
double pi;
static Uint8 toothpaste_r, toothpaste_g, toothpaste_b;
static const int toothpaste_RADIUS = 10;
double* toothpaste_weights = NULL;
double *toothpaste_weights = NULL;
enum {
enum
{
TOOL_toothpaste,
toothpaste_NUM_TOOLS
};
static Mix_Chunk * toothpaste_snd_effect[toothpaste_NUM_TOOLS];
static Mix_Chunk *toothpaste_snd_effect[toothpaste_NUM_TOOLS];
const char * toothpaste_snd_filenames[toothpaste_NUM_TOOLS] = {
const char *toothpaste_snd_filenames[toothpaste_NUM_TOOLS] = {
"toothpaste.ogg",
};
const char * toothpaste_icon_filenames[toothpaste_NUM_TOOLS] = {
const char *toothpaste_icon_filenames[toothpaste_NUM_TOOLS] = {
"toothpaste.png",
};
const char * toothpaste_names[toothpaste_NUM_TOOLS] = {
const char *toothpaste_names[toothpaste_NUM_TOOLS] = {
gettext_noop("Toothpaste"),
};
const char * toothpaste_descs[toothpaste_NUM_TOOLS] = {
const char *toothpaste_descs[toothpaste_NUM_TOOLS] = {
gettext_noop("Click and drag to squirt toothpaste onto your picture."),
};
@ -72,20 +76,16 @@ const char * toothpaste_descs[toothpaste_NUM_TOOLS] = {
Uint32 toothpaste_api_version(void);
int toothpaste_init(magic_api * api);
int toothpaste_get_tool_count(magic_api * api);
SDL_Surface * toothpaste_get_icon(magic_api * api, int which);
char * toothpaste_get_name(magic_api * api, int which);
char * toothpaste_get_description(magic_api * api, int which, int mode);
static void do_toothpaste(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
int x, int y);
SDL_Surface *toothpaste_get_icon(magic_api * api, int which);
char *toothpaste_get_name(magic_api * api, int which);
char *toothpaste_get_description(magic_api * api, int which, int mode);
static void do_toothpaste(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
void toothpaste_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void toothpaste_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void toothpaste_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void toothpaste_shutdown(magic_api * api);
void toothpaste_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int toothpaste_requires_colors(magic_api * api, int which);
@ -93,75 +93,98 @@ void toothpaste_switchin(magic_api * api, int which, int mode, SDL_Surface * can
void toothpaste_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int toothpaste_modes(magic_api * api, int which);
Uint32 toothpaste_api_version(void) { return(TP_MAGIC_API_VERSION); }
Uint32 toothpaste_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
int toothpaste_init(magic_api * api){
int toothpaste_init(magic_api * api)
{
int i;
char fname[1024];
int k,j;
int k, j;
//Load sounds
for (i = 0; i < toothpaste_NUM_TOOLS; i++){
for (i = 0; i < toothpaste_NUM_TOOLS; i++)
{
snprintf(fname, sizeof(fname), "%s/sounds/magic/%s", api->data_directory, toothpaste_snd_filenames[i]);
toothpaste_snd_effect[i] = Mix_LoadWAV(fname);
}
//Set up weights
pi = acos(0.0) * 2;
toothpaste_weights = (double*)malloc(toothpaste_RADIUS*2 * toothpaste_RADIUS*2 * sizeof(double));
if (toothpaste_weights == NULL){
return(0);
toothpaste_weights = (double *)malloc(toothpaste_RADIUS * 2 * toothpaste_RADIUS * 2 * sizeof(double));
if (toothpaste_weights == NULL)
{
return (0);
}
for (k = - toothpaste_RADIUS; k < + toothpaste_RADIUS; k++){
for (j = - toothpaste_RADIUS; j < + toothpaste_RADIUS; j++){
if (api->in_circle(j , k, toothpaste_RADIUS)){
toothpaste_weights[(k+toothpaste_RADIUS)*((toothpaste_RADIUS*2) -1)+(j+toothpaste_RADIUS)] = ((fabs(atan2((double)(j),(double)(k))))/pi);
for (k = -toothpaste_RADIUS; k < +toothpaste_RADIUS; k++)
{
for (j = -toothpaste_RADIUS; j < +toothpaste_RADIUS; j++)
{
if (api->in_circle(j, k, toothpaste_RADIUS))
{
toothpaste_weights[(k + toothpaste_RADIUS) * ((toothpaste_RADIUS * 2) - 1) + (j + toothpaste_RADIUS)] =
((fabs(atan2((double)(j), (double)(k)))) / pi);
}
}
}
return(1);
return (1);
}
int toothpaste_get_tool_count(magic_api * api ATTRIBUTE_UNUSED){
return(toothpaste_NUM_TOOLS);
int toothpaste_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return (toothpaste_NUM_TOOLS);
}
// Load our icons:
SDL_Surface * toothpaste_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED){
SDL_Surface *toothpaste_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, toothpaste_icon_filenames[which]);
return(IMG_Load(fname));
return (IMG_Load(fname));
}
// Return our names, localized:
char * toothpaste_get_name(magic_api * api ATTRIBUTE_UNUSED, int which){
return(strdup(gettext_noop(toothpaste_names[which])));
char *toothpaste_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
{
return (strdup(gettext_noop(toothpaste_names[which])));
}
// Return our descriptions, localized:
char * toothpaste_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED){
return(strdup(gettext_noop(toothpaste_descs[which])));
char *toothpaste_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
{
return (strdup(gettext_noop(toothpaste_descs[which])));
}
// Do the effect:
static void do_toothpaste(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y){
magic_api * api = (magic_api *) ptr;
static void do_toothpaste(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
{
magic_api *api = (magic_api *) ptr;
int xx, yy;
// double colr;
float h,s,v;
Uint8 r,g,b;
for (yy = y - toothpaste_RADIUS; yy < y + toothpaste_RADIUS; yy++){
for (xx = x - toothpaste_RADIUS; xx < x + toothpaste_RADIUS; xx++){
if (api->in_circle(xx - x, yy - y, toothpaste_RADIUS) &&
!api->touched(xx, yy)){
// double colr;
float h, s, v;
Uint8 r, g, b;
for (yy = y - toothpaste_RADIUS; yy < y + toothpaste_RADIUS; yy++)
{
for (xx = x - toothpaste_RADIUS; xx < x + toothpaste_RADIUS; xx++)
{
if (api->in_circle(xx - x, yy - y, toothpaste_RADIUS) && !api->touched(xx, yy))
{
api->rgbtohsv(toothpaste_r, toothpaste_g, toothpaste_b, &h, &s, &v);
api->hsvtorgb(h, s, toothpaste_weights[(yy-y+toothpaste_RADIUS)*((toothpaste_RADIUS*2) -1)+(xx-x+toothpaste_RADIUS)], &r, &g, &b);
api->hsvtorgb(h, s,
toothpaste_weights[(yy - y + toothpaste_RADIUS) * ((toothpaste_RADIUS * 2) - 1) +
(xx - x + toothpaste_RADIUS)], &r, &g, &b);
api->putpixel(canvas, xx, yy, SDL_MapRGB(canvas->format, r, g, b));
}
@ -172,10 +195,10 @@ static void do_toothpaste(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface *
// Affect the canvas on drag:
void toothpaste_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect){
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_toothpaste);
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_toothpaste);
api->playsound(toothpaste_snd_effect[which], (x * 255) / canvas->w, 255);
@ -188,8 +211,8 @@ void toothpaste_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click:
void toothpaste_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect){
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
toothpaste_drag(api, which, canvas, last, x, y, x, y, update_rect);
}
@ -206,12 +229,16 @@ void toothpaste_shutdown(magic_api * api ATTRIBUTE_UNUSED)
{
//Clean up sounds
int i;
for(i=0; i<toothpaste_NUM_TOOLS; i++){
if(toothpaste_snd_effect[i] != NULL){
for (i = 0; i < toothpaste_NUM_TOOLS; i++)
{
if (toothpaste_snd_effect[i] != NULL)
{
Mix_FreeChunk(toothpaste_snd_effect[i]);
}
}
if (toothpaste_weights != NULL){
if (toothpaste_weights != NULL)
{
free(toothpaste_weights);
toothpaste_weights = NULL;
}
@ -232,17 +259,17 @@ int toothpaste_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRI
}
void toothpaste_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void toothpaste_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void toothpaste_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void toothpaste_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int toothpaste_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_PAINT);
return (MODE_PAINT);
}

View file

@ -40,20 +40,22 @@
/* Our globals: */
enum { SIDE_LEFT, SIDE_RIGHT };
enum { LEAFSIDE_RIGHT_DOWN,
enum
{ SIDE_LEFT, SIDE_RIGHT };
enum
{ LEAFSIDE_RIGHT_DOWN,
LEAFSIDE_LEFT_DOWN,
LEAFSIDE_RIGHT_UP,
LEAFSIDE_LEFT_UP };
LEAFSIDE_LEFT_UP
};
static Mix_Chunk /* * tornado_click_snd, */ * tornado_release_snd;
static Uint8 tornado_r, tornado_g, tornado_b;
static int tornado_min_x, tornado_max_x, tornado_bottom_x, tornado_bottom_y;
static int tornado_side_first;
static int tornado_side_decided;
static SDL_Surface * tornado_base, * tornado_cloud,
* tornado_cloud_colorized;
static int top_w;
static SDL_Surface *tornado_base, *tornado_cloud, *tornado_cloud_colorized;
static int top_w;
/* Local function prototypes: */
@ -62,24 +64,22 @@ typedef struct
float x, y;
} Point2D;
static void tornado_predrag(magic_api * api, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y);
static void tornado_predrag(magic_api * api, SDL_Surface * canvas, SDL_Surface * last, int ox, int oy, int x, int y);
static void tornado_drawbase(magic_api * api, SDL_Surface * canvas);
static void tornado_drawstalk(magic_api * api, SDL_Surface * canvas, SDL_Surface * last,
int top_x, int top_y, int minx, int maxx,
int bottom_x, int bottom_y, int final);
int top_x, int top_y, int minx, int maxx, int bottom_x, int bottom_y, int final);
static void tornado_drawtornado(magic_api * api, SDL_Surface * canvas, int x, int y);
static Point2D tornado_PointOnCubicBezier(Point2D* cp, float t);
static void tornado_ComputeBezier(Point2D* cp, int numberOfPoints, Point2D* curve);
static Point2D tornado_PointOnCubicBezier(Point2D * cp, float t);
static void tornado_ComputeBezier(Point2D * cp, int numberOfPoints, Point2D * curve);
static void tornado_colorize_cloud(magic_api * api);
static Uint32 tornado_mess(Uint32 pixel, SDL_Surface * canvas);
Uint32 tornado_api_version(void);
int tornado_init(magic_api * api);
int tornado_get_tool_count(magic_api * api);
SDL_Surface * tornado_get_icon(magic_api * api, int which);
char * tornado_get_name(magic_api * api, int which);
SDL_Surface *tornado_get_icon(magic_api * api, int which);
char *tornado_get_name(magic_api * api, int which);
char * tornado_get_description(magic_api * api, int which, int mode);
char *tornado_get_description(magic_api * api, int which, int mode);
@ -87,14 +87,11 @@ char * tornado_get_description(magic_api * api, int which, int mode);
void tornado_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void tornado_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void tornado_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void tornado_shutdown(magic_api * api);
void tornado_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
@ -105,7 +102,10 @@ int tornado_modes(magic_api * api, int which);
Uint32 tornado_api_version(void) { return(TP_MAGIC_API_VERSION); }
Uint32 tornado_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
// No setup required:
@ -119,48 +119,44 @@ int tornado_init(magic_api * api)
tornado_click_snd = Mix_LoadWAV(fname);
*/
snprintf(fname, sizeof(fname), "%s/sounds/magic/tornado_release.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/sounds/magic/tornado_release.ogg", api->data_directory);
tornado_release_snd = Mix_LoadWAV(fname);
snprintf(fname, sizeof(fname), "%s/images/magic/tornado_base.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/tornado_base.png", api->data_directory);
tornado_base = IMG_Load(fname);
snprintf(fname, sizeof(fname), "%s/images/magic/tornado_cloud.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/tornado_cloud.png", api->data_directory);
tornado_cloud = IMG_Load(fname);
return(1);
return (1);
}
// We have multiple tools:
int tornado_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return(1);
return (1);
}
// Load our icons:
SDL_Surface * tornado_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
SDL_Surface *tornado_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/images/magic/tornado.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/tornado.png", api->data_directory);
return(IMG_Load(fname));
return (IMG_Load(fname));
}
// Return our names, localized:
char * tornado_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
char *tornado_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(strdup(gettext_noop("Tornado")));
return (strdup(gettext_noop("Tornado")));
}
// Return our descriptions, localized:
char * tornado_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
char *tornado_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return(strdup(gettext_noop("Click and drag to draw a tornado funnel on your picture.")));
return (strdup(gettext_noop("Click and drag to draw a tornado funnel on your picture.")));
}
// Affect the canvas on drag:
@ -199,8 +195,7 @@ static void tornado_predrag(magic_api * api ATTRIBUTE_UNUSED, SDL_Surface * canv
}
void tornado_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
tornado_predrag(api, canvas, last, ox, oy, x, y);
@ -213,8 +208,7 @@ void tornado_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface * can
/* Draw the base and the stalk (low-quality) for now: */
tornado_drawstalk(api, canvas, last,
x, y, tornado_min_x, tornado_max_x,
tornado_bottom_x, tornado_bottom_y, !(api->button_down()));
x, y, tornado_min_x, tornado_max_x, tornado_bottom_x, tornado_bottom_y, !(api->button_down()));
tornado_drawbase(api, canvas);
@ -226,13 +220,12 @@ void tornado_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface * can
// Affect the canvas on click:
void tornado_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
tornado_min_x = x;
tornado_max_x = x;
tornado_bottom_x = x;
tornado_bottom_y = y;// - tornado_base->h;
tornado_bottom_y = y; // - tornado_base->h;
tornado_side_decided = 0;
tornado_side_first = SIDE_LEFT;
@ -246,8 +239,7 @@ void tornado_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
// Affect the canvas on release:
void tornado_release(magic_api * api, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
/* Don't let tornado be too low compared to base: */
@ -267,9 +259,7 @@ void tornado_release(magic_api * api, int which ATTRIBUTE_UNUSED,
/* Draw high-quality stalk, and tornado: */
tornado_drawstalk(api, canvas, last,
x, y, tornado_min_x, tornado_max_x,
tornado_bottom_x, tornado_bottom_y, 1);
tornado_drawstalk(api, canvas, last, x, y, tornado_min_x, tornado_max_x, tornado_bottom_x, tornado_bottom_y, 1);
tornado_drawtornado(api, canvas, x, y);
@ -287,10 +277,10 @@ void tornado_release(magic_api * api, int which ATTRIBUTE_UNUSED,
static void tornado_drawtornado(magic_api * api, SDL_Surface * canvas, int x, int y)
{
SDL_Surface * aux_surf;
SDL_Surface *aux_surf;
SDL_Rect dest;
aux_surf = api->scale(tornado_cloud_colorized, top_w *2, top_w,0);
aux_surf = api->scale(tornado_cloud_colorized, top_w * 2, top_w, 0);
dest.x = x - (aux_surf->w / 2);
dest.y = y - (aux_surf->h / 2);
@ -311,21 +301,19 @@ static void tornado_drawbase(magic_api * api ATTRIBUTE_UNUSED, SDL_Surface * can
static Uint32 tornado_mess(Uint32 pixel, SDL_Surface * canvas)
{
Uint8 r, g, b, a;
float f = (float)rand()*255/RAND_MAX;
float f = (float)rand() * 255 / RAND_MAX;
SDL_GetRGBA(pixel, canvas->format, &r, &g, &b, &a);
return (SDL_MapRGBA(canvas->format,
(tornado_r + r + (Uint8)f * 2) / 4,
(tornado_g + g + (Uint8)f * 2) / 4,
(tornado_b + b + (Uint8)f * 2) / 4,
a));
(tornado_r + r + (Uint8) f * 2) / 4,
(tornado_g + g + (Uint8) f * 2) / 4, (tornado_b + b + (Uint8) f * 2) / 4, a));
}
static void tornado_drawstalk(magic_api * api, SDL_Surface * canvas, SDL_Surface * last,
int top_x, int top_y, int minx, int maxx,
int bottom_x, int bottom_y, int final)
int top_x, int top_y, int minx, int maxx, int bottom_x, int bottom_y, int final)
{
Point2D control_points[4];
Point2D * curve;
Point2D *curve;
int i, n_points;
int left, right;
SDL_Rect dest;
@ -391,8 +379,8 @@ static void tornado_drawstalk(magic_api * api, SDL_Surface * canvas, SDL_Surface
else
ww = 2000;
left = min(curve[i].x, curve[i + 1].x)-5-ii*ii/ww;
right = max(curve[i].x, curve[i + 1].x)+5+ii*ii/ww;
left = min(curve[i].x, curve[i + 1].x) - 5 - ii * ii / ww;
right = max(curve[i].x, curve[i + 1].x) + 5 + ii * ii / ww;
dest.x = left;
dest.y = curve[i].y;
@ -400,17 +388,19 @@ static void tornado_drawstalk(magic_api * api, SDL_Surface * canvas, SDL_Surface
dest.h = 2;
}
rotation +=3;
rotation += 3;
/* The body of the tornado: 3x 1y rotation + some random particles */
for (p = dest.x; p < dest.x + dest.w; p++)
{
if ((float)rand() * 100 / RAND_MAX > 10 )
if ((float)rand() * 100 / RAND_MAX > 10)
{
api->putpixel(canvas, p, dest.y, api->getpixel(last, dest.x + (p - dest.x + rotation) % dest.w , dest.y));
api->putpixel(canvas, p, dest.y, api->getpixel(last, dest.x + (p - dest.x + rotation) % dest.w, dest.y));
}
else
{
api->putpixel(canvas, p, dest.y, tornado_mess(api->getpixel(last, dest.x + (p - dest.x + rotation) % dest.w , dest.y), canvas));
api->putpixel(canvas, p, dest.y,
tornado_mess(api->getpixel(last, dest.x + (p - dest.x + rotation) % dest.w, dest.y),
canvas));
}
}
@ -418,7 +408,8 @@ static void tornado_drawstalk(magic_api * api, SDL_Surface * canvas, SDL_Surface
for (p = dest.x - dest.w * 20 / 100; p < dest.x + dest.w + dest.w * 20 / 100; p++)
{
if ((float)rand() * 100 / RAND_MAX < 5 && ((p < dest.x) || (p > dest.w)))
api->putpixel(canvas, p, dest.y, tornado_mess(api->getpixel(last, dest.x + (p - dest.x + rotation) % dest.w , dest.y), canvas));
api->putpixel(canvas, p, dest.y,
tornado_mess(api->getpixel(last, dest.x + (p - dest.x + rotation) % dest.w, dest.y), canvas));
}
}
@ -474,7 +465,7 @@ cp[3] is the end point, or P3 in the above diagram
t is the parameter value, 0 <= t <= 1
*/
static Point2D tornado_PointOnCubicBezier( Point2D* cp, float t )
static Point2D tornado_PointOnCubicBezier(Point2D * cp, float t)
{
float ax, bx, cx;
float ay, by, cy;
@ -509,15 +500,15 @@ static Point2D tornado_PointOnCubicBezier( Point2D* cp, float t )
<sizeof(Point2D) numberOfPoints>
*/
static void tornado_ComputeBezier( Point2D* cp, int numberOfPoints, Point2D* curve )
static void tornado_ComputeBezier(Point2D * cp, int numberOfPoints, Point2D * curve)
{
float dt;
int i;
dt = 1.0 / ( numberOfPoints - 1 );
dt = 1.0 / (numberOfPoints - 1);
for( i = 0; i < numberOfPoints; i++)
curve[i] = tornado_PointOnCubicBezier( cp, i*dt );
for (i = 0; i < numberOfPoints; i++)
curve[i] = tornado_PointOnCubicBezier(cp, i * dt);
}
@ -532,9 +523,7 @@ static void tornado_colorize_cloud(magic_api * api)
/* Create a surface to render into: */
amask = ~(tornado_cloud->format->Rmask |
tornado_cloud->format->Gmask |
tornado_cloud->format->Bmask);
amask = ~(tornado_cloud->format->Rmask | tornado_cloud->format->Gmask | tornado_cloud->format->Bmask);
tornado_cloud_colorized =
SDL_CreateRGBSurface(SDL_SWSURFACE,
@ -542,8 +531,7 @@ static void tornado_colorize_cloud(magic_api * api)
tornado_cloud->h,
tornado_cloud->format->BitsPerPixel,
tornado_cloud->format->Rmask,
tornado_cloud->format->Gmask,
tornado_cloud->format->Bmask, amask);
tornado_cloud->format->Gmask, tornado_cloud->format->Bmask, amask);
/* Render the new cloud: */
@ -554,8 +542,7 @@ static void tornado_colorize_cloud(magic_api * api)
{
for (x = 0; x < tornado_cloud->w; x++)
{
SDL_GetRGBA(api->getpixel(tornado_cloud, x, y),
tornado_cloud->format, &r, &g, &b, &a);
SDL_GetRGBA(api->getpixel(tornado_cloud, x, y), tornado_cloud->format, &r, &g, &b, &a);
api->putpixel(tornado_cloud_colorized, x, y,
SDL_MapRGBA(tornado_cloud_colorized->format,
@ -567,16 +554,18 @@ static void tornado_colorize_cloud(magic_api * api)
SDL_UnlockSurface(tornado_cloud);
}
void tornado_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void tornado_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void tornado_switchout(magic_api * api, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void tornado_switchout(magic_api * api, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
api->stopsound();
}
int tornado_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_PAINT_WITH_PREVIEW);
return (MODE_PAINT_WITH_PREVIEW);
}

View file

@ -32,30 +32,25 @@
int RADIUS = 16;
Mix_Chunk * tv_snd;
Mix_Chunk *tv_snd;
Uint32 tv_api_version(void);
void tv_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int tv_init(magic_api * api);
int tv_get_tool_count(magic_api * api);
SDL_Surface * tv_get_icon(magic_api * api, int which);
char * tv_get_name(magic_api * api, int which);
char * tv_get_description(magic_api * api, int which, int mode);
SDL_Surface *tv_get_icon(magic_api * api, int which);
char *tv_get_name(magic_api * api, int which);
char *tv_get_description(magic_api * api, int which, int mode);
int tv_requires_colors(magic_api * api, int which);
void tv_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);
void tv_shutdown(magic_api * api);
void tv_paint_tv(void * ptr_to_api, int which_tool,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
void tv_do_tv(void * ptr_to_api, int which_tool,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
void tv_paint_tv(void *ptr_to_api, int which_tool, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
void tv_do_tv(void *ptr_to_api, int which_tool, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
void tv_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 tv_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void tv_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void tv_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int tv_modes(magic_api * api, int which);
@ -64,7 +59,7 @@ int tv_modes(magic_api * api, int which);
Uint32 tv_api_version(void)
{
return(TP_MAGIC_API_VERSION);
return (TP_MAGIC_API_VERSION);
}
void tv_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED) //get the colors from API and store it in structure
@ -79,7 +74,7 @@ int tv_init(magic_api * api ATTRIBUTE_UNUSED)
snprintf(fname, sizeof(fname), "%s/sounds/magic/tv.ogg", api->data_directory);
tv_snd = Mix_LoadWAV(fname);
return(1);
return (1);
}
int tv_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
@ -87,19 +82,21 @@ int tv_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
return 1;
}
SDL_Surface * tv_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
SDL_Surface *tv_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/images/magic/tv.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/tv.png", api->data_directory);
return(IMG_Load(fname));
return (IMG_Load(fname));
}
char * tv_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) { return strdup(gettext_noop("TV")); }
char *tv_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return strdup(gettext_noop("TV"));
}
char * tv_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode)
char *tv_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode)
{
if (mode == MODE_PAINT)
return strdup(gettext_noop("Click and drag to make parts of your picture look like they are on television."));
@ -109,7 +106,10 @@ char * tv_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE
}
int tv_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) { return 0; }
int tv_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return 0;
}
void tv_release(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * snapshot ATTRIBUTE_UNUSED,
@ -118,36 +118,35 @@ void tv_release(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
}
void tv_shutdown(magic_api * api ATTRIBUTE_UNUSED)
{ Mix_FreeChunk(tv_snd); }
{
Mix_FreeChunk(tv_snd);
}
// Interactivity functions
void tv_paint_tv(void * ptr_to_api, int which_tool ATTRIBUTE_UNUSED,
void tv_paint_tv(void *ptr_to_api, int which_tool ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
{
int i, j;
magic_api * api = (magic_api *) ptr_to_api;
magic_api *api = (magic_api *) ptr_to_api;
for (i = x - RADIUS; i < x + RADIUS; i++)
for (j = y - RADIUS; j < y + RADIUS; j++)
if ((j + 1) % 2 &&
api->in_circle(i - x, j - y, RADIUS) &&
! api->touched(i, j))
if ((j + 1) % 2 && api->in_circle(i - x, j - y, RADIUS) && !api->touched(i, j))
api->putpixel(canvas, i, j, SDL_MapRGB(canvas->format, 128, 128, 165));
}
void tv_do_tv(void * ptr_to_api, int which_tool ATTRIBUTE_UNUSED,
void tv_do_tv(void *ptr_to_api, int which_tool ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
{
magic_api * api = (magic_api *) ptr_to_api;
magic_api *api = (magic_api *) ptr_to_api;
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, 128, 128, 165));
//api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, 0, 0, 255));
}
void tv_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)
{
api->line(api, which, canvas, snapshot, ox, oy, x, y, 1, tv_paint_tv);
@ -159,20 +158,19 @@ void tv_drag(magic_api * api, int which, SDL_Surface * canvas,
}
void tv_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
if (mode == MODE_FULLSCREEN)
{
int i;
for (i=0; i<canvas->h; i+=2)
for (i = 0; i < canvas->h; i += 2)
api->line(api, which, canvas, last, 0, i, canvas->w, i, 1, tv_do_tv);
update_rect->w=canvas->w;
update_rect->h=canvas->h;
update_rect->x=update_rect->y=0;
api->playsound(tv_snd, 128,255);
update_rect->w = canvas->w;
update_rect->h = canvas->h;
update_rect->x = update_rect->y = 0;
api->playsound(tv_snd, 128, 255);
}
else
{
@ -180,17 +178,19 @@ void tv_click(magic_api * api, int which, int mode,
}
}
void tv_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void tv_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void tv_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void tv_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int tv_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_FULLSCREEN | MODE_PAINT);
return (MODE_FULLSCREEN | MODE_PAINT);
}

View file

@ -34,25 +34,22 @@
/* Our globals: */
static Mix_Chunk * waves_snd[2];
static Mix_Chunk *waves_snd[2];
/* Local function prototypes: */
Uint32 waves_api_version(void);
int waves_init(magic_api * api);
int waves_get_tool_count(magic_api * api);
SDL_Surface * waves_get_icon(magic_api * api, int which);
char * waves_get_name(magic_api * api, int which);
char * waves_get_description(magic_api * api, int which, int mode);
SDL_Surface *waves_get_icon(magic_api * api, int which);
char *waves_get_name(magic_api * api, int which);
char *waves_get_description(magic_api * api, int which, int mode);
void waves_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void waves_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void waves_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void waves_shutdown(magic_api * api);
void waves_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
int waves_requires_colors(magic_api * api, int which);
@ -60,7 +57,10 @@ void waves_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void waves_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int waves_modes(magic_api * api, int which);
Uint32 waves_api_version(void) { return(TP_MAGIC_API_VERSION); }
Uint32 waves_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
// No setup required:
@ -68,16 +68,14 @@ int waves_init(magic_api * api)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/sounds/magic/waves.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/sounds/magic/waves.ogg", api->data_directory);
waves_snd[0] = Mix_LoadWAV(fname);
snprintf(fname, sizeof(fname), "%s/sounds/magic/wavelet.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/sounds/magic/wavelet.ogg", api->data_directory);
waves_snd[1] = Mix_LoadWAV(fname);
return(1);
return (1);
}
// We have multiple tools:
@ -87,29 +85,37 @@ int waves_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
}
// Load our icons:
SDL_Surface * waves_get_icon(magic_api * api, int which)
SDL_Surface *waves_get_icon(magic_api * api, int which)
{
char fname[1024];
if (!which) snprintf(fname, sizeof(fname), "%s/images/magic/waves.png", api->data_directory);
else snprintf(fname, sizeof(fname), "%s/images/magic/wavelet.png", api->data_directory);
if (!which)
snprintf(fname, sizeof(fname), "%s/images/magic/waves.png", api->data_directory);
else
snprintf(fname, sizeof(fname), "%s/images/magic/wavelet.png", api->data_directory);
return(IMG_Load(fname));
return (IMG_Load(fname));
}
// Return our names, localized:
char * waves_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
char *waves_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
{
if (!which) return(strdup(gettext_noop("Waves")));
else return strdup(gettext_noop("Wavelets"));
if (!which)
return (strdup(gettext_noop("Waves")));
else
return strdup(gettext_noop("Wavelets"));
}
// Return our descriptions, localized:
char * waves_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
char *waves_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
{
if (!which)
return(strdup(gettext_noop("Click to make the picture horizontally wavy. Click toward the top for shorter waves, the bottom for taller waves, the left for small waves, and the right for long waves.")));
return strdup(gettext_noop("Click to make the picture vertically wavy. Click toward the top for shorter waves, the bottom for taller waves, the left for small waves, and the right for long waves."));
return (strdup
(gettext_noop
("Click to make the picture horizontally wavy. Click toward the top for shorter waves, the bottom for taller waves, the left for small waves, and the right for long waves.")));
return
strdup(gettext_noop
("Click to make the picture vertically wavy. Click toward the top for shorter waves, the bottom for taller waves, the left for small waves, and the right for long waves."));
}
@ -124,7 +130,7 @@ void waves_drag(magic_api * api ATTRIBUTE_UNUSED, int which, SDL_Surface * canva
SDL_BlitSurface(last, NULL, canvas, NULL);
if (which==0)
if (which == 0)
{
//waves effect
width = ((x * 10) / canvas->w) + 10;
@ -173,8 +179,7 @@ void waves_drag(magic_api * api ATTRIBUTE_UNUSED, int which, SDL_Surface * canva
// Affect the canvas on click:
void waves_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
waves_drag(api, which, canvas, last, x, y, x, y, update_rect);
api->playsound(waves_snd[which], 128, 255);
@ -197,7 +202,8 @@ void waves_shutdown(magic_api * api ATTRIBUTE_UNUSED)
}
// Record the color from Tux Paint:
void waves_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
void waves_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED)
{
}
@ -207,15 +213,17 @@ int waves_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_
return 0;
}
void waves_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void waves_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void waves_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void waves_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int waves_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_PAINT);
return (MODE_PAINT);
}

View file

@ -34,26 +34,23 @@
#include "SDL_image.h"
#include "SDL_mixer.h"
static Mix_Chunk * xor_snd;
static Mix_Chunk *xor_snd;
Uint32 xor_api_version(void);
int xor_init(magic_api * api);
int xor_get_tool_count(magic_api * api);
SDL_Surface * xor_get_icon(magic_api * api, int which);
char * xor_get_name(magic_api * api, int which);
char * xor_get_description(magic_api * api, int which, int mode);
SDL_Surface *xor_get_icon(magic_api * api, int which);
char *xor_get_name(magic_api * api, int which);
char *xor_get_description(magic_api * api, int which, int mode);
void xor_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
void xor_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void xor_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last,
int x, int y, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void xor_shutdown(magic_api * api);
void xor_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
@ -62,68 +59,72 @@ void xor_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void xor_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
int xor_modes(magic_api * api, int which);
Uint32 xor_api_version(void) { return(TP_MAGIC_API_VERSION); }
Uint32 xor_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
int xor_init(magic_api * api)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/sounds/magic/xor.ogg",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/sounds/magic/xor.ogg", api->data_directory);
xor_snd = Mix_LoadWAV(fname);
return(1);
return (1);
}
int xor_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return(1);
return (1);
}
SDL_Surface * xor_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
SDL_Surface *xor_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%s/images/magic/xor.png",
api->data_directory);
snprintf(fname, sizeof(fname), "%s/images/magic/xor.png", api->data_directory);
return(IMG_Load(fname));
return (IMG_Load(fname));
}
char * xor_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
char *xor_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(strdup(gettext_noop("Xor Colors")));
return (strdup(gettext_noop("Xor Colors")));
}
char * xor_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode)
char *xor_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode)
{
if (mode == MODE_PAINT)
return(strdup(gettext_noop("Click and drag to draw a XOR effect")));
return (strdup(gettext_noop("Click and drag to draw a XOR effect")));
else
return(strdup(gettext_noop("Click to draw a XOR effect on the whole picture")));
return (strdup(gettext_noop("Click to draw a XOR effect on the whole picture")));
}
static void do_xor(void * ptr, int which ATTRIBUTE_UNUSED,
static void do_xor(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
{
magic_api * api = (magic_api *) ptr;
Uint8 r,g,b,xor;
float hue,sat,val;
magic_api *api = (magic_api *) ptr;
Uint8 r, g, b, xor;
float hue, sat, val;
Uint32 pixel;
SDL_GetRGB(api->getpixel(canvas,x,y),canvas->format,&r,&g,&b);
api->rgbtohsv(r,g,b,&hue,&sat,&val);
if (sat == 0) xor = (2*(int)hue+(x^y))%360;
else xor = ((int)hue+(x^y))%360;
api->hsvtorgb(xor,1,1,&r,&g,&b);
pixel = SDL_MapRGB(canvas->format,r,g,b);
api->putpixel(canvas,x,y,pixel);
SDL_GetRGB(api->getpixel(canvas, x, y), canvas->format, &r, &g, &b);
api->rgbtohsv(r, g, b, &hue, &sat, &val);
if (sat == 0)
xor = (2 * (int)hue + (x ^ y)) % 360;
else
xor = ((int)hue + (x ^ y)) % 360;
api->hsvtorgb(xor, 1, 1, &r, &g, &b);
pixel = SDL_MapRGB(canvas->format, r, g, b);
api->putpixel(canvas, x, y, pixel);
}
static void do_xor_circle(void * ptr, int which ATTRIBUTE_UNUSED,
static void do_xor_circle(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
{
magic_api * api = (magic_api *) ptr;
int xx,yy;
magic_api *api = (magic_api *) ptr;
int xx, yy;
for (yy = -16; yy < 16; yy++)
{
@ -131,32 +132,43 @@ static void do_xor_circle(void * ptr, int which ATTRIBUTE_UNUSED,
{
if (api->in_circle(xx, yy, 16))
{
if (!api->touched(xx+x,yy+y)) do_xor(api,which,canvas,last,x + xx,y + yy);
if (!api->touched(xx + x, yy + y))
do_xor(api, which, canvas, last, x + xx, y + yy);
}
}
}
}
void xor_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last ATTRIBUTE_UNUSED, int ox, int oy, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * last ATTRIBUTE_UNUSED, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_xor_circle);
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_xor_circle);
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;
}
update_rect->x = ox - 16;
update_rect->y = oy - 16;
update_rect->w = (x + 16) - update_rect->x;
update_rect->h = (y + 16) - update_rect->h;
api->playsound(xor_snd,(x * 255) / canvas->w, 255);
api->playsound(xor_snd, (x * 255) / canvas->w, 255);
}
void xor_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
int x, int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y, SDL_Rect * update_rect)
{
if (mode == MODE_PAINT)
xor_drag(api, which, canvas, last, x, y, x, y, update_rect);
@ -172,7 +184,7 @@ void xor_click(magic_api * api, int which, int mode,
update_rect->y = 0;
update_rect->w = canvas->w;
update_rect->h = canvas->h;
api->playsound(xor_snd,(x * 255) / canvas->w, 255);
api->playsound(xor_snd, (x * 255) / canvas->w, 255);
}
}
@ -188,7 +200,8 @@ void xor_shutdown(magic_api * api ATTRIBUTE_UNUSED)
Mix_FreeChunk(xor_snd);
}
void xor_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
void xor_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
Uint8 b ATTRIBUTE_UNUSED)
{
}
@ -197,15 +210,17 @@ int xor_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UN
return 0;
}
void xor_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void xor_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
void xor_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
void xor_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
int xor_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return(MODE_PAINT | MODE_FULLSCREEN);
return (MODE_PAINT | MODE_FULLSCREEN);
}

13
src/.indent.pro vendored Normal file
View file

@ -0,0 +1,13 @@
--blank-lines-after-declarations
--blank-lines-after-procedures
--break-before-boolean-operator
--continue-at-parentheses
--declaration-indentation1
--dont-break-function-decl-args
--dont-break-procedure-type
--line-length120
--no-blank-lines-after-commas
--no-space-after-casts
--no-space-after-function-call-names
--no-space-after-parentheses
--no-tabs

View file

@ -67,8 +67,9 @@
///////////////// directory walking callers and callbacks //////////////////
void loadfont_callback(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer, const char *restrict const dir,
unsigned dirlen, tp_ftw_str * files, unsigned i, const char *restrict const locale)
void loadfont_callback(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer,
const char *restrict const dir, unsigned dirlen, tp_ftw_str * files, unsigned i,
const char *restrict const locale)
{
dirlen = dirlen;
@ -76,6 +77,7 @@ void loadfont_callback(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer
{
int loadable = 0;
const char *restrict const cp = strchr(files[i].str, '.');
show_progress_bar_(screen, texture, renderer);
if (cp)
{
@ -83,6 +85,7 @@ void loadfont_callback(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer
const char * /*restrict */ const suffixes[] =
{ "ttc", "dfont", "pfa", "pfb", "otf", "ttf", };
int j = sizeof suffixes / sizeof suffixes[0];
while (j--)
{
// only check part, because of potential .gz or .bz2 suffix
@ -106,6 +109,7 @@ void loadfont_callback(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer
{
char fname[512];
TuxPaint_Font *font;
snprintf(fname, sizeof fname, "%s/%s", dir, files[i].str);
#ifdef DEBUG
printf("Loading font: %s (locale is: %s)\n", fname, (locale ? locale : "NULL")); //EP
@ -113,6 +117,7 @@ void loadfont_callback(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer
if (locale && strstr(fname, "locale") && !all_locale_fonts)
{
char fname_check[512];
/* We're (probably) loading from our locale fonts folder; ONLY load our locale's font */
snprintf(fname_check, sizeof fname_check, "%s/%s.ttf", dir, locale);
#ifdef DEBUG
@ -135,12 +140,11 @@ void loadfont_callback(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer
#ifdef DEBUG
int numfaces = TTF_FontFaces(font->ttf_font);
if (numfaces != 1)
printf("Found %d faces in %s, %s, %s\n", numfaces, files[i].str,
family, style);
printf("success: tpf: 0x%x tpf->ttf_font: 0x%x\n",
(unsigned int)(intptr_t) font, (unsigned int)(intptr_t) font->ttf_font); //EP added (intptr_t) to avoid warning on x64
if (numfaces != 1)
printf("Found %d faces in %s, %s, %s\n", numfaces, files[i].str, family, style);
printf("success: tpf: 0x%x tpf->ttf_font: 0x%x\n", (unsigned int)(intptr_t) font, (unsigned int)(intptr_t) font->ttf_font); //EP added (intptr_t) to avoid warning on x64
#endif
// These fonts crash Tux Paint via a library bug.
@ -165,19 +169,17 @@ void loadfont_callback(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer
// impossible for a user to type ASCII letters.
//
// Most translators should use scoring instead.
if(!charset_works(font, gettext("qx")) || !charset_works(font, gettext("QX")))
if (!charset_works(font, gettext("qx")) || !charset_works(font, gettext("QX")))
blacklisted = 1;
if(!blacklisted){
if (!blacklisted)
{
if (num_font_styles == num_font_styles_max)
{
num_font_styles_max = num_font_styles_max * 5 / 4 + 30;
user_font_styles =
realloc(user_font_styles,
num_font_styles_max * sizeof *user_font_styles);
user_font_styles = realloc(user_font_styles, num_font_styles_max * sizeof *user_font_styles);
}
user_font_styles[num_font_styles] =
malloc(sizeof *user_font_styles[num_font_styles]);
user_font_styles[num_font_styles] = malloc(sizeof *user_font_styles[num_font_styles]);
user_font_styles[num_font_styles]->directory = strdup(dir);
user_font_styles[num_font_styles]->filename = files[i].str; // steal it (mark NULL below)
user_font_styles[num_font_styles]->family = strdup(family);
@ -213,8 +215,8 @@ void loadfont_callback(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer
#if 0
user_font_styles[num_font_styles]->score += charset_works(font, gettext("<1>spare-1a"));
user_font_styles[num_font_styles]->score += charset_works(font, gettext("<1>spare-1b"));
user_font_styles[num_font_styles]->score += charset_works(font, gettext("<9>spare-9a"))*9;
user_font_styles[num_font_styles]->score += charset_works(font, gettext("<9>spare-9b"))*9;
user_font_styles[num_font_styles]->score += charset_works(font, gettext("<9>spare-9a")) * 9;
user_font_styles[num_font_styles]->score += charset_works(font, gettext("<9>spare-9b")) * 9;
#endif
// this really should be dynamic, avoiding the need for a special build
@ -233,8 +235,7 @@ void loadfont_callback(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer
{
#if 0
// THREADED_FONTS
printf("Font is too defective: %s, %s, %s\n", files[i].str, family,
style);
printf("Font is too defective: %s, %s, %s\n", files[i].str, family, style);
#endif
}
TuxPaint_Font_CloseFont(font);
@ -258,15 +259,13 @@ int compare_ftw_str(const void *v1, const void *v2)
{
const char *restrict const s1 = ((tp_ftw_str *) v1)->str;
const char *restrict const s2 = ((tp_ftw_str *) v2)->str;
return -strcmp(s1, s2); /* FIXME: Should we try strcasecmp, to group things together despite uppercase/lowercase in filenames (e.g., Jigsaw* vs jigsaw* Starters)??? -bjk 2009.10.11 */
}
void tp_ftw(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer, char *restrict const dir, unsigned dirlen,
int rsrc, void (*fn) (SDL_Surface * screen,
SDL_Texture * texture,
SDL_Renderer * renderer,
const char *restrict const dir,
unsigned dirlen, tp_ftw_str * files,
void tp_ftw(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer, char *restrict const dir,
unsigned dirlen, int rsrc, void (*fn) (SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer,
const char *restrict const dir, unsigned dirlen, tp_ftw_str * files,
unsigned count, const char *restrict const locale),
const char *restrict const locale)
{
@ -328,6 +327,7 @@ void tp_ftw(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer
if (filetype == TP_FTW_UNKNOWN)
{
struct stat sbuf;
memcpy(dir + dirlen, f->d_name, d_namlen + 1);
if (stat(dir, &sbuf))
continue; // oh well... try the next one
@ -364,6 +364,7 @@ void tp_ftw(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer
if (filetype == TP_FTW_DIRECTORY)
{
char *cp;
if (num_dir_names == max_dir_names)
{
max_dir_names = max_dir_names * 5 / 4 + 3;
@ -401,8 +402,7 @@ void tp_ftw(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer
qsort(dir_names, num_dir_names, sizeof *dir_names, compare_ftw_str);
while (num_dir_names--)
{
memcpy(dir + dirlen, dir_names[num_dir_names].str,
dir_names[num_dir_names].len + 1);
memcpy(dir + dirlen, dir_names[num_dir_names].str, dir_names[num_dir_names].len + 1);
tp_ftw(screen, texture, renderer, dir, dirlen + dir_names[num_dir_names].len, rsrc, fn, locale);
free(dir_names[num_dir_names].str);
}

View file

@ -45,15 +45,13 @@ typedef struct tp_ftw_str
} tp_ftw_str;
void loadfont_callback(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer, const char *restrict const dir,
unsigned dirlen, tp_ftw_str * files, unsigned i, const char *restrict const locale);
void loadfont_callback(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer,
const char *restrict const dir, unsigned dirlen, tp_ftw_str * files, unsigned i,
const char *restrict const locale);
int compare_ftw_str(const void *v1, const void *v2);
void tp_ftw(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer, char *restrict const dir, unsigned dirlen,
int rsrc, void (*fn) (SDL_Surface * screen,
SDL_Texture * texture,
SDL_Renderer * renderer,
const char *restrict const dir,
unsigned dirlen, tp_ftw_str * files,
void tp_ftw(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer, char *restrict const dir,
unsigned dirlen, int rsrc, void (*fn) (SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer,
const char *restrict const dir, unsigned dirlen, tp_ftw_str * files,
unsigned count, const char *restrict const locale),
const char *restrict const locale);

View file

@ -189,6 +189,7 @@ TuxPaint_Font *load_locale_font(TuxPaint_Font * fallback, int size)
else
{
char str[128];
snprintf(str, sizeof(str), "%sfonts/locale/%s.ttf", DATA_PREFIX, lang_prefix);
ret = TuxPaint_Font_OpenFont("", str, size);
@ -238,7 +239,8 @@ void TuxPaint_Font_CloseFont(TuxPaint_Font * tpf)
#ifdef DEBUG
printf("TuxPaint_Font_CloseFont step 1 (%p)\n", tpf); //EP
#endif
if (!tpf) return; //EP
if (!tpf)
return; //EP
#ifndef NO_SDLPANGO
#ifdef DEBUG
@ -265,7 +267,8 @@ void TuxPaint_Font_CloseFont(TuxPaint_Font * tpf)
tpf->ttf_font = NULL;
}
if (tpf->desc != NULL) {
if (tpf->desc != NULL)
{
free(tpf->desc);
tpf->desc = NULL;
}
@ -277,6 +280,7 @@ TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc, const char *ttffile
{
TuxPaint_Font *tpf = NULL;
int i;
#ifndef NO_SDLPANGO
char desc[1024];
#endif
@ -381,9 +385,11 @@ TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc, const char *ttffile
void reliable_write(int fd, const void *buf, size_t count)
{
struct pollfd p;
do
{
ssize_t rc = write(fd, buf, count);
if (rc == -1)
{
switch (errno)
@ -412,9 +418,11 @@ void reliable_write(int fd, const void *buf, size_t count)
static void reliable_read(int fd, void *buf, size_t count)
{
struct pollfd p;
do
{
ssize_t rc = read(fd, buf, count);
if (rc == -1)
{
switch (errno)
@ -570,6 +578,7 @@ static void groupfonts_range(style_info ** base, int count)
while (i--)
{
int b = boldmap[base[i]->boldness];
if (b == -1)
{
#if 0
@ -717,6 +726,7 @@ static void parse_font_style(style_info * si)
{
size_t len = strlen(si->family);
char *name = malloc(len + strlen(" Condensed") + 1);
sp += strlen("Condensed");
memcpy(name, si->family, len);
strcpy(name + len, " Condensed");
@ -809,7 +819,7 @@ static void parse_font_style(style_info * si)
si->boldness = 1;
// we'll count both TrueType and OpenType
si->truetype = !!strcasestr(si->filename, ".ttf") || !!strcasestr(si->filename, ".otf");
si->truetype = ! !strcasestr(si->filename, ".ttf") || ! !strcasestr(si->filename, ".otf");
}
@ -818,9 +828,11 @@ static void dupe_markdown_range(family_info ** base, int count)
int bestscore = -999;
int bestslot = 0;
int i = count;
while (i--)
{
int score = base[i]->score;
if (score <= bestscore)
continue;
bestscore = score;
@ -852,6 +864,7 @@ static void groupfonts(void)
for (;;)
{
int high = low;
if (low >= num_font_styles)
break;
for (;;)
@ -882,6 +895,7 @@ static void groupfonts(void)
for (;;)
{
int high = low;
if (low >= num_font_families)
break;
for (;;)
@ -927,7 +941,8 @@ static void groupfonts(void)
}
static void loadfonts_locale_filter(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer, const char *const dir, const char *restrict const locale)
static void loadfonts_locale_filter(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer,
const char *const dir, const char *restrict const locale)
{
char buf[TP_FTW_PATHSIZE];
unsigned dirlen = strlen(dir);
@ -942,11 +957,12 @@ static void loadfonts(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer
}
/* static */ int load_user_fonts(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer, void *vp, const char *restrict const locale)
/* static */ int load_user_fonts(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer, void *vp,
const char *restrict const locale)
{
char *homedirdir;
(void) vp; // junk passed by threading library
(void)vp; // junk passed by threading library
loadfonts_locale_filter(screen, texture, renderer, DATA_PREFIX "fonts", locale);
@ -962,8 +978,9 @@ static void loadfonts(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer
loadfonts(screen, texture, renderer, "/usr/X11R6/lib/X11/fonts");
#elif defined(__HAIKU__)
dev_t volume = dev_for_path("/boot");
char buffer[B_PATH_NAME_LENGTH+B_FILE_NAME_LENGTH];
char buffer[B_PATH_NAME_LENGTH + B_FILE_NAME_LENGTH];
status_t result;
result = find_directory(B_SYSTEM_FONTS_DIRECTORY, volume, false, buffer, sizeof(buffer));
loadfonts(screen, texture, renderer, buffer);
result = find_directory(B_COMMON_FONTS_DIRECTORY, volume, false, buffer, sizeof(buffer));
@ -1016,7 +1033,8 @@ static void loadfonts(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer
#ifdef FORKED_FONTS
void run_font_scanner(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer, const char *restrict const locale)
void run_font_scanner(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer,
const char *restrict const locale)
{
int sv[2];
int size, i;
@ -1053,6 +1071,7 @@ void run_font_scanner(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer
while (i--)
{
char *s;
s = user_font_families[i]->directory;
if (s)
size += strlen(s);
@ -1170,7 +1189,7 @@ void receive_some_font_info(SDL_Surface * screen, SDL_Texture * texture, SDL_Ren
}
rc = read(font_socket_fd, buf + buf_fill, buf_size - buf_fill);
#ifdef DEBUG
printf("read: fd=%d buf_fill=%u buf_size=%u rc=%ld\n", font_socket_fd, buf_fill, buf_size, (long int) rc);
printf("read: fd=%d buf_fill=%u buf_size=%u rc=%ld\n", font_socket_fd, buf_fill, buf_size, (long int)rc);
#endif
if (rc == -1)
@ -1210,8 +1229,8 @@ void receive_some_font_info(SDL_Surface * screen, SDL_Texture * texture, SDL_Ren
show_progress_bar_(screen, texture, renderer);
walk = buf;
num_font_families = *(unsigned char *) walk++;
num_font_families += *(unsigned char *) walk++ << 8u;
num_font_families = *(unsigned char *)walk++;
num_font_families += *(unsigned char *)walk++ << 8u;
#ifdef DEBUG
printf("Got %u bytes with %u families.\n", buf_fill, num_font_families);
#endif
@ -1224,6 +1243,7 @@ void receive_some_font_info(SDL_Surface * screen, SDL_Texture * texture, SDL_Ren
while (i--)
{
unsigned len;
user_font_families[i] = fip + i;
len = strlen(walk);
@ -1287,7 +1307,7 @@ TuxPaint_Font *getfonthandle(int desire)
if (fi->filename != NULL)
{
#ifdef DEBUG
printf("Setting 'name' to fi->filename[%d (0x%x)]\n", (int) text_state, (int) text_state);
printf("Setting 'name' to fi->filename[%d (0x%x)]\n", (int)text_state, (int)text_state);
fflush(stdout);
#endif
@ -1453,8 +1473,9 @@ static int do_surfcmp(const SDL_Surface * const *const v1, const SDL_Surface * c
return s1->h - s2->h;
{
const char *const c1 = (char *const) s1->pixels;
const char *const c2 = (char *const) s2->pixels;
const char *const c1 = (char *const)s1->pixels;
const char *const c2 = (char *const)s2->pixels;
width = s1->format->BytesPerPixel * s1->w;
if (width == s1->pitch)
return memcmp(c1, c2, width * s1->h);
@ -1475,6 +1496,7 @@ static int do_surfcmp(const SDL_Surface * const *const v1, const SDL_Surface * c
static int surfcmp(const void *s1, const void *s2)
{
int diff = do_surfcmp(s1, s2);
if (!diff)
was_bad_font = 1;
return diff;
@ -1490,6 +1512,7 @@ int charset_works(TuxPaint_Font * font, const char *s)
SDL_Surface **surfs = malloc(strlen(s) * sizeof surfs[0]);
unsigned count = 0;
int ret = 0;
while (*s)
{
char c[8];
@ -1573,7 +1596,7 @@ const char *TuxPaint_Font_FontFaceFamilyName(TuxPaint_Font * tpf)
#ifndef NO_SDLPANGO
if (tpf->typ == FONT_TYPE_PANGO)
{
(void) (tpf);
(void)(tpf);
/* FIXME */
return ("");
@ -1604,7 +1627,7 @@ const char *TuxPaint_Font_FontFaceStyleName(TuxPaint_Font * tpf)
#ifndef NO_SDLPANGO
if (tpf->typ == FONT_TYPE_PANGO)
{
(void) (tpf);
(void)(tpf);
/* FIXME */
return ("");
@ -1650,6 +1673,7 @@ void ssdl_color_to_pango_color(SDL_Color sdl_color, SDLPango_Matrix * pango_colo
memcpy(pango_color, pc, 16);
}
void sdl_color_to_pango_color(SDL_Color sdl_color, SDLPango_Matrix * pango_color)
{
Uint8 pc[4][4];

View file

@ -91,21 +91,23 @@ TTF_Font *BUGFIX_TTF_OpenFont206(const char *const file, int ptsize);
/* Stuff that wraps either SDL_Pango or SDL_TTF for font rendering: */
enum {
enum
{
#ifndef NO_SDLPANGO
FONT_TYPE_PANGO,
#endif
FONT_TYPE_TTF
};
typedef struct TuxPaint_Font_s {
typedef struct TuxPaint_Font_s
{
#ifndef NO_SDLPANGO
SDLPango_Context * pango_context;
SDLPango_Context *pango_context;
#endif
int typ;
TTF_Font * ttf_font;
TTF_Font *ttf_font;
int height;
char * desc;
char *desc;
} TuxPaint_Font;
int TuxPaint_Font_FontHeight(TuxPaint_Font * tpf);
@ -183,15 +185,15 @@ TuxPaint_Font *getfonthandle(int desire);
int charset_works(TuxPaint_Font * font, const char *s);
TuxPaint_Font * TuxPaint_Font_OpenFont(const char * pangodesc, const char * ttffilename, int size);
TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc, const char *ttffilename, int size);
void TuxPaint_Font_CloseFont(TuxPaint_Font * tpf);
const char * TuxPaint_Font_FontFaceFamilyName(TuxPaint_Font * tpf);
const char * TuxPaint_Font_FontFaceStyleName(TuxPaint_Font * tpf);
const char *TuxPaint_Font_FontFaceFamilyName(TuxPaint_Font * tpf);
const char *TuxPaint_Font_FontFaceStyleName(TuxPaint_Font * tpf);
#ifdef NO_SDLPANGO
TuxPaint_Font *load_locale_font(TuxPaint_Font * fallback, int size);
#else
void sdl_color_to_pango_color(SDL_Color sdl_color, SDLPango_Matrix *pango_color);
void sdl_color_to_pango_color(SDL_Color sdl_color, SDLPango_Matrix * pango_color);
#endif
int load_user_fonts(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer, void *vp, const char *restrict const locale);

View file

@ -60,10 +60,10 @@ const char *datadir;
char *get_fname(const char *const name, int kind)
{
char f[512];
const char *restrict const dir = (kind==DIR_SAVE) ? savedir : datadir;
const char *restrict const dir = (kind == DIR_SAVE) ? savedir : datadir;
// Some mkdir()'s don't like trailing slashes
snprintf(f, sizeof(f), "%s%c%s", dir, (*name)?'/':'\0', name);
snprintf(f, sizeof(f), "%s%c%s", dir, (*name) ? '/' : '\0', name);
return strdup(f);
}

View file

@ -28,7 +28,8 @@
extern const char *savedir;
extern const char *datadir;
enum {
enum
{
DIR_SAVE,
DIR_DATA
};

View file

@ -54,7 +54,7 @@
// setlocale cannot get current default locale of the device.
// Here, JNI and Java Locale class can get the default locale
// if user has not set locale and lang in the config file yet.
static char * android_locale ()
static char *android_locale()
{
static char android_locale_buf[32];
JNIEnv *mEnv = Android_JNI_GetEnv();
@ -63,7 +63,8 @@ static char * android_locale ()
jobject mLocaleObject = (*mEnv)->CallStaticObjectMethod(mEnv, mLocaleClass, mGetDefaultMethod);
jmethodID mToStringMethod = (*mEnv)->GetMethodID(mEnv, mLocaleClass, "toString", "()Ljava/lang/String;");
jstring mLocaleString = (*mEnv)->CallObjectMethod(mEnv, mLocaleObject, mToStringMethod);
const char* locale = (*mEnv)->GetStringUTFChars(mEnv, mLocaleString, 0);
const char *locale = (*mEnv)->GetStringUTFChars(mEnv, mLocaleString, 0);
strcpy(android_locale_buf, locale);
(*mEnv)->ReleaseStringUTFChars(mEnv, mLocaleString, locale);
printf("android locale %s\n", android_locale_buf);
@ -449,13 +450,12 @@ static const language_to_locale_struct language_to_locale_array[] = {
/* Show available languages: */
static void show_lang_usage(int exitcode)
{
FILE * f = exitcode ? stderr : stdout;
FILE *f = exitcode ? stderr : stdout;
const char *const prg = "tuxpaint";
fprintf(f,
"\n"
"Usage: %s [--lang LANGUAGE]\n" "\n" "LANGUAGE may be one of:\n"
fprintf(f, "\n" "Usage: %s [--lang LANGUAGE]\n" "\n" "LANGUAGE may be one of:\n"
/* C */ " english american-english\n"
/* ach */" acholi acoli\n"
/* ach */ " acholi acoli\n"
/* af */ " afrikaans\n"
/* ak */ " akan twi-fante\n"
/* sq */ " albanian\n"
@ -464,7 +464,7 @@ static void show_lang_usage(int exitcode)
/* an */ " aragones\n"
/* hy */ " armenian hayeren\n"
/* as */ " assamese\n"
/* ast */" asturian\n"
/* ast */ " asturian\n"
/* en_AU */ " australian-english\n"
/* az */ " azerbaijani\n"
/* bm */ " bambara\n"
@ -498,7 +498,7 @@ static void show_lang_usage(int exitcode)
/* ka */ " georgian\n"
/* de */ " german deutsch\n"
/* el */ " greek\n"
/* gos */" gronings zudelk-veenkelonioals\n"
/* gos */ " gronings zudelk-veenkelonioals\n"
/* gu */ " gujarati\n"
/* he */ " hebrew\n"
/* hi */ " hindi\n"
@ -513,18 +513,18 @@ static void show_lang_usage(int exitcode)
/* ks@devanagari */ " kashmiri-devanagari\n"
/* ks */ " kashmiri-perso-arabic\n"
/* km */ " khmer\n"
/* cgg */" kiga chiga\n"
/* cgg */ " kiga chiga\n"
/* rw */ " kinyarwanda\n"
/* tlh */" klingon tlhIngan\n"
/* kok */" konkani-devaganari\n"
/* kok@roman */" konkani-roman\n"
/* tlh */ " klingon tlhIngan\n"
/* kok */ " konkani-devaganari\n"
/* kok@roman */ " konkani-roman\n"
/* ko */ " korean\n"
/* ku */ " kurdish\n"
/* lv */ " latvian\n"
/* lt */ " lithuanian lietuviu\n"
/* lg */ " luganda\n"
/* lb */ " luxembourgish letzebuergesch\n"
/* mai */" maithili\n"
/* mai */ " maithili\n"
/* mk */ " macedonian\n"
/* ms */ " malay\n"
/* ml */ " malayalam\n"
@ -535,7 +535,7 @@ static void show_lang_usage(int exitcode)
/* mn */ " mongolian\n"
/* nr */ " ndebele\n"
/* ne */ " nepali\n"
/* nso */" northern-sotho sesotho-sa-leboa\n"
/* nso */ " northern-sotho sesotho-sa-leboa\n"
/* nn */ " norwegian nynorsk norsk\n"
/* oc */ " occitan\n"
/* or */ " odia oriya\n"
@ -547,8 +547,8 @@ static void show_lang_usage(int exitcode)
/* ro */ " romanian\n"
/* ru */ " russian russkiy\n"
/* sa */ " sanskrit\n"
/* sat */" santali-devaganari\n"
/* sat@olchiki */" santali-ol-chiki\n"
/* sat */ " santali-devaganari\n"
/* sat@olchiki */ " santali-ol-chiki\n"
/* gd */ " scottish scottish-gaelic ghaidhlig\n"
/* sr */ " serbian\n"
/* sr@latin */ " serbian-latin\n"
@ -575,13 +575,13 @@ static void show_lang_usage(int exitcode)
/* ur */ " urdu\n"
/* ca@valencia */ " valencian valencia\n"
/* ve */ " venda\n"
/* vec */" venetian veneto\n"
/* vec */ " venetian veneto\n"
/* vi */ " vietnamese\n"
/* wa */ " walloon walon\n"
/* wo */ " wolof\n"
/* cy */ " welsh cymraeg\n"
/* xh */ " xhosa\n"
/* zam */" zapotec miahuatlan-zapotec\n"
/* zam */ " zapotec miahuatlan-zapotec\n"
/* zu */ " zulu\n"
"\n", prg);
exit(exitcode);
@ -722,10 +722,7 @@ static void show_locale_usage(FILE * f, const char *const prg)
" wa_BE (Walloon)\n"
" wo_SN (Wolof)\n"
" cy_GB (Welsh Cymraeg)\n"
" xh_ZA (Xhosa)\n"
" zam (Zapoteco-Miahuatlan)\n"
" zu_ZA (Zulu)\n"
"\n", prg);
" xh_ZA (Xhosa)\n" " zam (Zapoteco-Miahuatlan)\n" " zu_ZA (Zulu)\n" "\n", prg);
}
@ -755,15 +752,17 @@ static void ctype_utf8(void)
#ifndef _WIN32
/* FIXME: should this iterate over more locales?
A zapotec speaker may have es_MX.UTF-8 available but not have en_US.UTF-8 for example */
const char *names[] = {"en_US.UTF8","en_US.UTF-8","UTF8","UTF-8","C.UTF-8"};
int i = sizeof(names)/sizeof(names[0]);
for(;;){
if(iswprint((wchar_t)0xf7)) // division symbol -- which is in Latin-1 :-/
const char *names[] = { "en_US.UTF8", "en_US.UTF-8", "UTF8", "UTF-8", "C.UTF-8" };
int i = sizeof(names) / sizeof(names[0]);
for (;;)
{
if (iswprint((wchar_t) 0xf7)) // division symbol -- which is in Latin-1 :-/
return;
if(--i < 0)
if (--i < 0)
break;
setlocale(LC_CTYPE,names[i]);
setlocale(LC_MESSAGES,names[i]);
setlocale(LC_CTYPE, names[i]);
setlocale(LC_MESSAGES, names[i]);
}
fprintf(stderr, "Failed to find a locale with iswprint() working!\n");
#endif
@ -773,6 +772,7 @@ static void ctype_utf8(void)
static const char *language_to_locale(const char *langstr)
{
int i = sizeof language_to_locale_array / sizeof language_to_locale_array[0];
while (i--)
{
if (!strcmp(langstr, language_to_locale_array[i].language))
@ -797,6 +797,7 @@ static void set_langint_from_locale_string(const char *restrict loc)
size_t len_baseloc;
int found = 0;
int i;
// printf("langint %i\n", langint);
if (!loc)
@ -810,7 +811,7 @@ static void set_langint_from_locale_string(const char *restrict loc)
as a last resource reverse the scanning
*/
if(dot)
if (dot)
*dot = '\0';
if (cntrycode)
@ -824,7 +825,7 @@ static void set_langint_from_locale_string(const char *restrict loc)
ataux = strdup(at);
*at = '\0';
if(cntrycode)
if (cntrycode)
{
/* ll_CC@variant */
//if (found == 0) printf("ll_CC@variant check\n");
@ -833,8 +834,7 @@ static void set_langint_from_locale_string(const char *restrict loc)
for (i = 0; i < NUM_LANGS && found == 0; i++)
{
// Case-insensitive (both "pt_BR" and "pt_br" work, etc.)
if (len_baseloc == strlen(lang_prefixes[i]) &&
!strncasecmp(straux, lang_prefixes[i], len_baseloc))
if (len_baseloc == strlen(lang_prefixes[i]) && !strncasecmp(straux, lang_prefixes[i], len_baseloc))
{
langint = i;
found = 1;
@ -842,15 +842,14 @@ static void set_langint_from_locale_string(const char *restrict loc)
}
}
/* ll@variant*/
/* ll@variant */
//if (found == 0) printf("ll@variant check\n");
snprintf(straux, 255, "%s%s", baseloc, ataux);
len_baseloc = strlen(straux);
for (i = 0; i < NUM_LANGS && found == 0; i++)
{
// Case-insensitive (both "pt_BR" and "pt_br" work, etc.)
if (len_baseloc == strlen(lang_prefixes[i]) &&
!strncasecmp(straux, lang_prefixes[i], len_baseloc))
if (len_baseloc == strlen(lang_prefixes[i]) && !strncasecmp(straux, lang_prefixes[i], len_baseloc))
{
langint = i;
found = 1;
@ -858,11 +857,11 @@ static void set_langint_from_locale_string(const char *restrict loc)
}
}
if(cntrycode)
if (cntrycode)
{
/* ll_CC */
//if (found == 0) printf("ll_CC check\n");
snprintf(straux, 255, "%s%s",baseloc, ccodeaux);
snprintf(straux, 255, "%s%s", baseloc, ccodeaux);
len_baseloc = strlen(straux);
/* Which, if any, of the locales is it? */
@ -887,8 +886,7 @@ static void set_langint_from_locale_string(const char *restrict loc)
for (i = 0; i < NUM_LANGS && found == 0; i++)
{
// Case-insensitive (both "pt_BR" and "pt_br" work, etc.)
if (len_baseloc == strlen(lang_prefixes[i]) &&
!strncasecmp(baseloc, lang_prefixes[i], strlen(lang_prefixes[i])))
if (len_baseloc == strlen(lang_prefixes[i]) && !strncasecmp(baseloc, lang_prefixes[i], strlen(lang_prefixes[i])))
{
langint = i;
found = 1;
@ -930,8 +928,9 @@ static void mysetenv(const char *name, const char *value)
#ifdef HAVE_SETENV
setenv(name, value, 1);
#else
int len = strlen(name)+1+strlen(value)+1;
int len = strlen(name) + 1 + strlen(value) + 1;
char *str = malloc(len);
sprintf(str, "%s=%s", name, value);
putenv(str);
#endif
@ -939,11 +938,11 @@ static void mysetenv(const char *name, const char *value)
static int set_current_language(const char *restrict locale_choice) MUST_CHECK;
static int set_current_language(const char *restrict loc)
static int set_current_language(const char *restrict loc)
{
int i;
int y_nudge = 0;
char * oldloc;
char *oldloc;
char *env_language;
@ -972,13 +971,13 @@ static int set_current_language(const char *restrict loc)
after that, ctype_utf8() call will test the compatibility with utf8 and try to load
a different locale if the resulting one is not compatible. */
#ifdef DEBUG
printf ("Locale BEFORE is: %s\n", setlocale(LC_ALL,NULL));//EP
printf("Locale BEFORE is: %s\n", setlocale(LC_ALL, NULL)); //EP
#endif
setlocale(LC_ALL, "");
setlocale(LC_ALL, loc);
ctype_utf8();
#ifdef DEBUG
printf ("Locale AFTER is: %s\n", setlocale(LC_ALL,NULL));//EP
printf("Locale AFTER is: %s\n", setlocale(LC_ALL, NULL)); //EP
#endif
bindtextdomain("tuxpaint", LOCALEDIR);
@ -997,7 +996,8 @@ printf ("Locale AFTER is: %s\n", setlocale(LC_ALL,NULL));//EP
loc = setlocale(LC_MESSAGES, NULL);
#endif
if (oldloc && loc && strcmp(oldloc, "") != 0 && strcmp(loc, oldloc) != 0) {
if (oldloc && loc && strcmp(oldloc, "") != 0 && strcmp(loc, oldloc) != 0)
{
/* System doesn't recognize that locale! Hack, per Albert C., is to set LC_ALL to a valid UTF-8 locale, then set LANGUAGE to the locale we want to force -bjk 2010.10.05 */
/* Albert's comments from December 2009:
@ -1026,7 +1026,9 @@ printf ("Locale AFTER is: %s\n", setlocale(LC_ALL,NULL));//EP
mysetenv("LANGUAGE", oldloc);
set_langint_from_locale_string(oldloc);
} else {
}
else
{
#ifdef _WIN32
if (getenv("LANGUAGE") == NULL)
mysetenv("LANGUAGE", loc);
@ -1038,6 +1040,7 @@ printf ("Locale AFTER is: %s\n", setlocale(LC_ALL,NULL));//EP
env_language = strdup(getenv("LANGUAGE"));
int j = 0;
char *env_language_lang;
if (*env_language)
{
env_language_lang = strtok(env_language, ":");
@ -1096,9 +1099,7 @@ printf ("Locale AFTER is: %s\n", setlocale(LC_ALL,NULL));//EP
#endif
#ifdef DEBUG
fprintf(stderr, "DEBUG: Language is %s (%d) %s/%s\n",
lang_prefix, langint,
need_right_to_left ? "(RTL)" : "",
need_right_to_left_word ? "(RTL words)" : "");
lang_prefix, langint, need_right_to_left ? "(RTL)" : "", need_right_to_left_word ? "(RTL words)" : "");
fflush(stderr);
#endif
@ -1118,16 +1119,16 @@ int setup_i18n(const char *restrict lang, const char *restrict locale)
printf("lang \"%s\", locale \"%s\"\n", lang, locale);
#endif
if(locale)
if (locale)
{
if(!strcmp(locale,"help"))
if (!strcmp(locale, "help"))
{
show_locale_usage(stdout,"tuxpaint");
show_locale_usage(stdout, "tuxpaint");
exit(0);
}
}
if(lang)
if (lang)
locale = language_to_locale(lang);
#ifdef __APPLE__
@ -1135,11 +1136,11 @@ int setup_i18n(const char *restrict lang, const char *restrict locale)
#endif
#ifdef __ANDROID__
if(locale == NULL)
if (locale == NULL)
locale = android_locale();
#endif
if(locale == NULL)
if (locale == NULL)
locale = "";
return set_current_language(locale);
}

View file

@ -114,7 +114,7 @@ enum
LANG_ML, /* Malayalam */
LANG_MK, /* Macedonian */
LANG_MN, /* Mongolian */
LANG_MNI_BENGALI, /* Manipuri (Bengali script)*/
LANG_MNI_BENGALI, /* Manipuri (Bengali script) */
LANG_MNI_METEI_MAYEK, /* Manipuri (Metei Mayek script) */
LANG_MR, /* Marath */
LANG_MS, /* Malay */
@ -207,8 +207,9 @@ extern w_langs wished_langs[255];
int get_current_language(void);
int setup_i18n(const char *restrict lang, const char *restrict locale) MUST_CHECK;
#ifdef NO_SDLPANGO
int smash_i18n(void) MUST_CHECK;
int smash_i18n(void) MUST_CHECK;
#endif
#endif

856
src/im.c

File diff suppressed because it is too large Load diff

View file

@ -33,10 +33,11 @@
* TYPES
*/
typedef struct IM_DATA {
typedef struct IM_DATA
{
int lang; /* Language used in sequence translation */
wchar_t s[16]; /* Characters that should be displayed */
const char* tip_text; /* Tip text, read-only please */
const char *tip_text; /* Tip text, read-only please */
/* For use by language-specific im_event_<lang> calls. PRIVATE! */
wchar_t buf[8]; /* Buffered characters */
@ -49,9 +50,9 @@ typedef struct IM_DATA {
* FUNCTIONS
*/
void im_init(IM_DATA* im, int lang); /* Initialize IM */
void im_softreset(IM_DATA* im); /* Soft Reset IM */
int im_read(IM_DATA* im, SDL_Event event);
void im_init(IM_DATA * im, int lang); /* Initialize IM */
void im_softreset(IM_DATA * im); /* Soft Reset IM */
int im_read(IM_DATA * im, SDL_Event event);
#endif /* TUXPAINT_IM_H */

View file

@ -25,17 +25,16 @@
#include "SDL.h"
const char *SurfacePrint(SDL_Surface *surface, int showDialog);
int DisplayPageSetup(const SDL_Surface *surface);
const char *SurfacePrint(SDL_Surface * surface, int showDialog);
int DisplayPageSetup(const SDL_Surface * surface);
#ifdef OBJECTIVEC
@interface PrintSheetController : NSObject
@interface PrintSheetController:NSObject
{
bool displayPrintSetupSheet;
bool displayPrintSheet;
}
-
@end
#endif OBJECTIVEC
-@end
#endif /* OBJECTIVEC */

View file

@ -5,30 +5,31 @@
#define DEBUG_OSK_COMPOSEMAP
static SDL_Color def_bgcolor = {255, 255, 255, 255};
static SDL_Color def_fgcolor = {0, 0, 0, 0};
static SDL_Color def_bgcolor = { 255, 255, 255, 255 };
static SDL_Color def_fgcolor = { 0, 0, 0, 0 };
static void load_hlayout(osk_layout *layout, char * layout_name);
static void load_keymap(osk_layout *layout, char * keymap_name);
static void load_composemap(osk_layout *layout, char * composemap_name);
static void load_hlayout(osk_layout * layout, char *layout_name);
static void load_keymap(osk_layout * layout, char *keymap_name);
static void load_composemap(osk_layout * layout, char *composemap_name);
static int is_blank_or_comment(char *line);
/* static int isw_blank_or_comment(wchar_t *line); */
static void keybd_prepare(on_screen_keyboard *keyboard);
static void keybd_prepare(on_screen_keyboard * keyboard);
static void draw_key(osk_key key, on_screen_keyboard * keyboard, int hot);
static void label_key(osk_key key, on_screen_keyboard *keyboard);
static void draw_keyboard(on_screen_keyboard *keyboard);
static osk_key * find_key(on_screen_keyboard * keyboard, int x, int y);
static void set_key(osk_key *orig, osk_key *dest, int firsttime);
static void load_keysymdefs(osk_layout * layout, char * keysymdefs_name);
static struct osk_layout *load_layout(on_screen_keyboard *keyboard, char *layout_name);
static void label_key(osk_key key, on_screen_keyboard * keyboard);
static void draw_keyboard(on_screen_keyboard * keyboard);
static osk_key *find_key(on_screen_keyboard * keyboard, int x, int y);
static void set_key(osk_key * orig, osk_key * dest, int firsttime);
static void load_keysymdefs(osk_layout * layout, char *keysymdefs_name);
static struct osk_layout *load_layout(on_screen_keyboard * keyboard, char *layout_name);
#ifdef DEBUG_OSK_COMPOSEMAP
static void print_composemap(osk_composenode *composemap, char * sp);
static void print_composemap(osk_composenode * composemap, char *sp);
#endif
#ifdef WIN32
@ -36,9 +37,9 @@ static void print_composemap(osk_composenode *composemap, char * sp);
#define wcstok(line, delim, pointer) wcstok(line, delim)
#define strtok_r(line, delim, pointer) strtok(line, delim)
static void mtw(wchar_t * wtok, char * tok);
static void mtw(wchar_t * wtok, char *tok);
static void mtw(wchar_t * wtok, char * tok)
static void mtw(wchar_t * wtok, char *tok)
{
/* workaround using iconv to get a functionallity somewhat approximate as mbstowcs() */
Uint16 *ui16;
@ -50,23 +51,28 @@ static void mtw(wchar_t * wtok, char * tok)
in = 250;
out = 250;
ui16 = malloc(sizeof(Uint16) * 255);
wrptr = (char *) ui16;
wrptr = (char *)ui16;
trans = iconv_open("WCHAR_T", "UTF-8");
iconv(trans, (const char **) &tok, &in, &wrptr, &out);
iconv(trans, (const char **)&tok, &in, &wrptr, &out);
*((wchar_t *) wrptr) = L'\0';
swprintf(wtok, L"%ls", ui16);
free(ui16);
iconv_close(trans);
}
#define mbstowcs(wtok, tok, size) mtw(wtok, tok)
#endif
struct osk_keyboard *osk_create(char *layout_name, SDL_Surface *canvas, SDL_Surface *button_up, SDL_Surface *button_down, SDL_Surface *button_off, SDL_Surface *button_nav, SDL_Surface *button_hold, SDL_Surface *oskdel, SDL_Surface *osktab, SDL_Surface *oskenter, SDL_Surface *oskcapslock, SDL_Surface *oskshift, int disable_change)
struct osk_keyboard *osk_create(char *layout_name, SDL_Surface * canvas, SDL_Surface * button_up,
SDL_Surface * button_down, SDL_Surface * button_off, SDL_Surface * button_nav,
SDL_Surface * button_hold, SDL_Surface * oskdel, SDL_Surface * osktab,
SDL_Surface * oskenter, SDL_Surface * oskcapslock, SDL_Surface * oskshift,
int disable_change)
{
SDL_Surface *surface;
osk_layout *layout;
on_screen_keyboard * keyboard;
on_screen_keyboard *keyboard;
keyboard = malloc(sizeof(on_screen_keyboard));
@ -94,9 +100,7 @@ struct osk_keyboard *osk_create(char *layout_name, SDL_Surface *canvas, SDL_Surf
layout->width * button_up->w,
layout->height * button_up->h,
canvas->format->BitsPerPixel,
canvas->format->Rmask,
canvas->format->Gmask,
canvas->format->Bmask, 0);
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, 0);
if (!surface)
{
printf("Error creating the onscreen keyboard surface\n");
@ -136,7 +140,9 @@ struct osk_keyboard *osk_create(char *layout_name, SDL_Surface *canvas, SDL_Surf
keyboard->kmdf.dead3 = NULL;
keyboard->kmdf.dead4 = NULL;
SDL_FillRect(surface, NULL, SDL_MapRGB(surface->format, keyboard->layout->bgcolor.r, keyboard->layout->bgcolor.g, keyboard->layout->bgcolor.b));
SDL_FillRect(surface, NULL,
SDL_MapRGB(surface->format, keyboard->layout->bgcolor.r, keyboard->layout->bgcolor.g,
keyboard->layout->bgcolor.b));
keybd_prepare(keyboard);
@ -144,12 +150,12 @@ struct osk_keyboard *osk_create(char *layout_name, SDL_Surface *canvas, SDL_Surf
return keyboard;
}
static struct osk_layout *load_layout(on_screen_keyboard *keyboard, char *layout_name)
static struct osk_layout *load_layout(on_screen_keyboard * keyboard, char *layout_name)
{
FILE *fi;
int hlayout_loaded;
char * line;
char * filename;
char *line;
char *filename;
char *key, *value;
osk_layout *layout;
@ -260,7 +266,7 @@ static struct osk_layout *load_layout(on_screen_keyboard *keyboard, char *layout
/* A hlayout contains the definitions of the keyboard as seen in the screen.
Things like the number of rows of the keyboard, the font used to render the keys,
the width of the keys, and a code that matches each key like in real hardware keyboards */
void load_hlayout(osk_layout *layout, char * hlayout_name)
void load_hlayout(osk_layout * layout, char *hlayout_name)
{
int width, height;
int key_number, line_number;
@ -273,7 +279,7 @@ void load_hlayout(osk_layout *layout, char * hlayout_name)
char *line;
char *key, *fontpath;
char *plain_label, *top_label, *altgr_label, *shift_altgr_label;
FILE * fi;
FILE *fi;
key_number = line_number = 0;
width = height = 0;
@ -317,24 +323,24 @@ void load_hlayout(osk_layout *layout, char * hlayout_name)
while (!feof(fi))
{
if(width && height && !allocated)
if (width && height && !allocated)
{
layout->keys = malloc(height * sizeof(osk_key *));
layout->keys[0] = malloc(width * sizeof(osk_key ));
layout->keys[0] = malloc(width * sizeof(osk_key));
for (i = 0; i< width; i++)
for (i = 0; i < width; i++)
{
layout->keys[0][i].width = 0;
layout->keys[0][i].plain_label = NULL;
layout->keys[ line_number][i].top_label=NULL;
layout->keys[ line_number][i].altgr_label=NULL;
layout->keys[ line_number][i].shift_altgr_label=NULL;
layout->keys[line_number][i].top_label = NULL;
layout->keys[line_number][i].altgr_label = NULL;
layout->keys[line_number][i].shift_altgr_label = NULL;
}
layout->width = width;
layout->height = height;
#ifdef DEBUG
printf("w %i, h %i\n" , layout->width, layout->height);
printf("w %i, h %i\n", layout->width, layout->height);
#endif
allocated = 1;
}
@ -365,7 +371,7 @@ void load_hlayout(osk_layout *layout, char * hlayout_name)
printf("linefont %s\n", line);
#endif
sscanf(line, "%s %i %i %i", key, &r, &g, &b);
if (r > 0 && r< 256 && g > 0 && g< 256 && b > 0 && b< 256)
if (r > 0 && r < 256 && g > 0 && g < 256 && b > 0 && b < 256)
{
layout->fgcolor.r = r;
layout->fgcolor.g = g;
@ -379,7 +385,7 @@ void load_hlayout(osk_layout *layout, char * hlayout_name)
printf("linefont %s\n", line);
#endif
sscanf(line, "%s %i %i %i", key, &r, &g, &b);
if (r > 0 && r< 256 && g > 0 && g< 256 && b > 0 && b< 256)
if (r > 0 && r < 256 && g > 0 && g < 256 && b > 0 && b < 256)
{
layout->bgcolor.r = r;
layout->bgcolor.g = g;
@ -389,16 +395,16 @@ void load_hlayout(osk_layout *layout, char * hlayout_name)
}
else if (strncmp(line, "NEWLINE", 7) == 0)
{
line_number ++;
line_number++;
key_number = 0;
layout->keys[line_number] = malloc(width * sizeof(osk_key));
for (i = 0; i< width; i++)
for (i = 0; i < width; i++)
{
layout->keys[line_number][i].width = 0;
layout->keys[ line_number][i].plain_label=NULL;
layout->keys[ line_number][i].top_label=NULL;
layout->keys[ line_number][i].altgr_label=NULL;
layout->keys[ line_number][i].shift_altgr_label=NULL;
layout->keys[line_number][i].plain_label = NULL;
layout->keys[line_number][i].top_label = NULL;
layout->keys[line_number][i].altgr_label = NULL;
layout->keys[line_number][i].shift_altgr_label = NULL;
}
}
else if (width && height && allocated && strncmp(line, "KEY ", 4) == 0 && key_number < width)
@ -412,22 +418,17 @@ void load_hlayout(osk_layout *layout, char * hlayout_name)
"%s %i %i.%i %s %s %s %s %i",
key,
&keycode,
&key_width,
&key_width_decimal,
plain_label,
top_label,
altgr_label,
shift_altgr_label,
&shiftcaps);
&key_width, &key_width_decimal, plain_label, top_label, altgr_label, shift_altgr_label, &shiftcaps);
layout->keys[line_number][key_number].keycode = keycode;
layout->keys[line_number][key_number].width = (float)0.1 * key_width_decimal + key_width;
layout->keys[line_number][key_number].width = (float)0.1 *key_width_decimal + key_width;
layout->keys[line_number][key_number].plain_label = plain_label;
layout->keys[line_number][key_number].top_label = top_label;
layout->keys[line_number][key_number].altgr_label = altgr_label;
layout->keys[line_number][key_number].shift_altgr_label = shift_altgr_label;
layout->keys[line_number][key_number].shiftcaps = shiftcaps;
layout->keys[line_number][key_number].stick = 0;
key_number ++;
key_number++;
}
}
@ -461,13 +462,13 @@ void load_hlayout(osk_layout *layout, char * hlayout_name)
/* A keymap contains the keysyms (X keysym mnemonics) associated to each keycode in the hlayout.*/
void load_keymap(osk_layout *layout, char * keymap_name)
void load_keymap(osk_layout * layout, char *keymap_name)
{
int i, keycode, readed;
char *filename;
char *ksname1, *ksname2, *ksname3, *ksname4;
char *line;
FILE * fi;
FILE *fi;
filename = malloc(sizeof(char) * 255);
@ -493,7 +494,7 @@ void load_keymap(osk_layout *layout, char * keymap_name)
line = malloc(sizeof(char) * 1024);
layout->keymap = malloc(256 * sizeof(osk_keymap));
for (i = 0;i < 256; i++)
for (i = 0; i < 256; i++)
{
layout->keymap[i].plain = NULL;
layout->keymap[i].caps = NULL;
@ -520,8 +521,7 @@ void load_keymap(osk_layout *layout, char * keymap_name)
/* FIXME: Why is the us-intl keymap duplicating the two first entries of every keycode? */
/* And why is the arabic keymap using the 5th and 6th entries as plain/shifted keys? */
readed = sscanf(line, "keycode %i = %s %s %s %s", &keycode,
ksname1, ksname2, ksname3, ksname4);
readed = sscanf(line, "keycode %i = %s %s %s %s", &keycode, ksname1, ksname2, ksname3, ksname4);
if (readed == 5 && keycode > 8 && keycode < 256)
{
@ -561,7 +561,7 @@ void load_keymap(osk_layout *layout, char * keymap_name)
}
/* Scans a line of keysyms and result and classifies them. */
static void gettokens(char * line, char * delim, char ** pointer, osk_composenode *composenode, osk_layout *layout)
static void gettokens(char *line, char *delim, char **pointer, osk_composenode * composenode, osk_layout * layout)
{
int i;
char *tok;
@ -572,7 +572,7 @@ static void gettokens(char * line, char * delim, char ** pointer, osk_composenod
tok = strdup(strtok_r(line, delim, pointer));
if(!tok)
if (!tok)
return;
if (tok[0] == ':') /* End of precompose keysyms, next will be the result in UTF-8. */
@ -614,7 +614,7 @@ static void gettokens(char * line, char * delim, char ** pointer, osk_composenod
for (i = 0; i < composenode->size; i++)
{
mbstowcs(wtok, tok, 255);
if(wcscmp(composenode->childs[i]->keysym, wtok) == 0)
if (wcscmp(composenode->childs[i]->keysym, wtok) == 0)
{
/* printf("Size %d, keysym %ls =>", composenode->size, composenode->childs[i]->keysym); */
@ -628,11 +628,11 @@ static void gettokens(char * line, char * delim, char ** pointer, osk_composenod
}
composenode->size = composenode->size + 1;
composenode->childs = realloc(composenode->childs,composenode->size * sizeof(osk_composenode *));
composenode->childs = realloc(composenode->childs, composenode->size * sizeof(osk_composenode *));
mbstowcs(wtok, tok, 255);
auxnode = malloc(sizeof(osk_composenode));
composenode->childs[composenode->size - 1] = auxnode;//malloc(sizeof(osk_composenode));
composenode->childs[composenode->size - 1] = auxnode; //malloc(sizeof(osk_composenode));
composenode->childs[composenode->size - 1]->keysym = wtok;
composenode->childs[composenode->size - 1]->result = NULL;
composenode->childs[composenode->size - 1]->size = 0;
@ -649,12 +649,12 @@ static void gettokens(char * line, char * delim, char ** pointer, osk_composenod
/* A compose map contains the sequences of keysyms (X keysym mnemonics) needed to generate another keysym.
The last in the sequence is the result, the others will be searched in the order they appear.
They will be classified in a multiway tree.*/
static void load_composemap(osk_layout *layout, char * composemap_name)
static void load_composemap(osk_layout * layout, char *composemap_name)
{
char *filename;
char **pointer;
char *line;
FILE * fi;
FILE *fi;
pointer = malloc(sizeof(wchar_t *));
filename = malloc(sizeof(char) * 255);
@ -692,7 +692,7 @@ static void load_composemap(osk_layout *layout, char * composemap_name)
if (is_blank_or_comment(line))
continue;
gettokens(line, (char *) ">< \t", pointer, layout->composemap, layout);
gettokens(line, (char *)">< \t", pointer, layout->composemap, layout);
}
fclose(fi);
@ -704,10 +704,10 @@ static void load_composemap(osk_layout *layout, char * composemap_name)
}
#ifdef DEBUG_OSK_COMPOSEMAP
static void print_composemap(osk_composenode *composemap, char * sp)
static void print_composemap(osk_composenode * composemap, char *sp)
{
int i;
char * space;
char *space;
space = malloc(sizeof(char) * 255);
@ -757,12 +757,12 @@ static void print_composemap(osk_composenode *composemap, char * sp)
/* This parses the contents of keysymdef.h from the source of xorg.
Therefore, if somebody wants to provide custom keysymdefs, he has to follow its syntax. */
static void load_keysymdefs(osk_layout *layout, char * keysymdefs_name)
static void load_keysymdefs(osk_layout * layout, char *keysymdefs_name)
{
int i;
char *filename;
char *line;
FILE * fi;
FILE *fi;
filename = malloc(sizeof(char) * 255);
@ -788,7 +788,7 @@ static void load_keysymdefs(osk_layout *layout, char * keysymdefs_name)
layout->keysymdefs = malloc(sizeof(keysymdefs));
layout->keysymdefs[0].unicode = 0;
i = 0;
line = malloc(1024*sizeof(wchar_t));
line = malloc(1024 * sizeof(wchar_t));
while (!feof(fi))
{
@ -803,9 +803,7 @@ static void load_keysymdefs(osk_layout *layout, char * keysymdefs_name)
layout->keysymdefs[i].unicode = 0;
layout->keysymdefs[i].mnemo = malloc(sizeof(char) * 128);
sscanf(line, "#define XK_%s %x /* U+%x",
layout->keysymdefs[i].mnemo,
&layout->keysymdefs[i].keysym,
&layout->keysymdefs[i].unicode);
layout->keysymdefs[i].mnemo, &layout->keysymdefs[i].keysym, &layout->keysymdefs[i].unicode);
i++;
}
@ -826,26 +824,26 @@ static void load_keysymdefs(osk_layout *layout, char * keysymdefs_name)
/* } */
/* Returns the x keysym corresponding to a mnemonic string */
static int mnemo2keysym(char * mnemo, on_screen_keyboard * keyboard)
static int mnemo2keysym(char *mnemo, on_screen_keyboard * keyboard)
{
unsigned int i;
for (i = 0; i < keyboard->layout->sizeofkeysymdefs; i++)
{
if (strcmp(mnemo , keyboard->layout->keysymdefs[i].mnemo) == 0)
return(keyboard->layout->keysymdefs[i].keysym);
if (strcmp(mnemo, keyboard->layout->keysymdefs[i].mnemo) == 0)
return (keyboard->layout->keysymdefs[i].keysym);
}
i = 0;
/* Perhaps the mnemo is in UXXXX format? */
if(sscanf(mnemo, "U%x", &i))
return(i | 0x01000000);
if (sscanf(mnemo, "U%x", &i))
return (i | 0x01000000);
/* Or maybe mnemo is already a keysym? */
if (sscanf(mnemo, "0x%x", &i))
return(i);
return (i);
return(0);
return (0);
}
/* Returns the unicode value of a x keysym if any, otherwise returns 0 */
@ -862,8 +860,7 @@ static int keysym2unicode(int keysym, on_screen_keyboard * keyboard)
* This software is in the public domain. Share and enjoy!
*/
/* first check for Latin-1 characters (1:1 mapping) */
if ((keysym >= 0x0020 && keysym <= 0x007e) ||
(keysym >= 0x00a0 && keysym <= 0x00ff))
if ((keysym >= 0x0020 && keysym <= 0x007e) || (keysym >= 0x00a0 && keysym <= 0x00ff))
return keysym;
/* also check for directly encoded 24-bit UCS characters */
@ -874,9 +871,9 @@ static int keysym2unicode(int keysym, on_screen_keyboard * keyboard)
for (i = 0; i < keyboard->layout->sizeofkeysymdefs; i++)
if (keysym == keyboard->layout->keysymdefs[i].keysym)
return(keyboard->layout->keysymdefs[i].unicode);
return (keyboard->layout->keysymdefs[i].unicode);
return(keysym);
return (keysym);
}
@ -886,7 +883,7 @@ static void get_composed_keysym(on_screen_keyboard * keyboard, osk_composenode *
int i;
/* If there is not a compose table return the keysym */
if (! composenode)
if (!composenode)
{
if (keyboard->composed)
free(keyboard->composed);
@ -903,7 +900,7 @@ static void get_composed_keysym(on_screen_keyboard * keyboard, osk_composenode *
{
if (composenode->childs[i]->result)
{
if(keyboard->composed)
if (keyboard->composed)
free(keyboard->composed);
keyboard->composed = wcsdup(composenode->childs[i]->result);
keyboard->composing = keyboard->layout->composemap;
@ -913,7 +910,7 @@ static void get_composed_keysym(on_screen_keyboard * keyboard, osk_composenode *
}
else
{
if(keyboard->composed)
if (keyboard->composed)
free(keyboard->composed);
keyboard->composed = NULL;
keyboard->composing = composenode->childs[i];
@ -927,7 +924,7 @@ static void get_composed_keysym(on_screen_keyboard * keyboard, osk_composenode *
if (keyboard->layout->composemap == composenode)
{
if(keyboard->composed)
if (keyboard->composed)
free(keyboard->composed);
keyboard->composed = wcsdup(keysym);
keyboard->composed_type = 0;
@ -935,7 +932,7 @@ static void get_composed_keysym(on_screen_keyboard * keyboard, osk_composenode *
else /* reset */
{
keyboard->composing = keyboard->layout->composemap;
if(keyboard->composed)
if (keyboard->composed)
free(keyboard->composed);
keyboard->composed = NULL;
keyboard->composed_type = 0;
@ -987,32 +984,33 @@ static int is_blank_or_comment(char *line)
/* Fixme: Is it safe to supose that if a font is loaded at one size, it will be loaded at any size? */
/* Fixme: sizes should be dynamically adapted to the button size */
/* Fixme: starting a layout with one font causes all other layouts be in that font */
static void keybd_prepare(on_screen_keyboard *keyboard)
static void keybd_prepare(on_screen_keyboard * keyboard)
{
char * fontname;
char *fontname;
fontname = malloc(sizeof(char) * 255);
if (keyboard->osk_fonty == NULL) {
if (keyboard->osk_fonty == NULL)
{
if (keyboard->layout->fontpath)
{
/* First try if it is an absolute path */
keyboard->osk_fonty = TTF_OpenFont( keyboard->layout->fontpath, 12 );
keyboard->osk_fonty = TTF_OpenFont(keyboard->layout->fontpath, 12);
if (keyboard->osk_fonty == NULL)
{
/* Now trying if it is relative to DATA_PREFIX/fonts/ */
snprintf(fontname, 255, "%s/fonts/%s", DATA_PREFIX, keyboard->layout->fontpath);
keyboard->osk_fonty = TTF_OpenFont( fontname, 12 );
keyboard->osk_fonty = TTF_OpenFont(fontname, 12);
if (keyboard->osk_fonty == NULL)
{
/* Perhaps it is relative to DATA_PREFIX only? */
snprintf(fontname, 255, "%s/%s", DATA_PREFIX, keyboard->layout->fontpath);
keyboard->osk_fonty = TTF_OpenFont( fontname, 12 );
keyboard->osk_fonty = TTF_OpenFont(fontname, 12);
if (keyboard->osk_fonty == NULL)
{
/* Or to DATA_PREFIX/fonts/locale/ ? */
snprintf(fontname, 255, "%s/fonts/locale/%s", DATA_PREFIX, keyboard->layout->fontpath);
keyboard->osk_fonty = TTF_OpenFont( fontname, 12 );
keyboard->osk_fonty = TTF_OpenFont(fontname, 12);
}
}
}
@ -1022,14 +1020,13 @@ static void keybd_prepare(on_screen_keyboard *keyboard)
{
/* Going with the default */
sprintf(fontname, "%s/fonts/FreeSansBold.ttf", DATA_PREFIX);
keyboard->osk_fonty = TTF_OpenFont( fontname, 12 );
keyboard->osk_fonty = TTF_OpenFont(fontname, 12);
}
if (keyboard->osk_fonty == NULL)
{
fprintf(stderr, "\nError: Can't open the font!\n"
"The Simple DirectMedia Layer error that occurred was:\n"
"%s\n\n", SDL_GetError());
"The Simple DirectMedia Layer error that occurred was:\n" "%s\n\n", SDL_GetError());
free(fontname);
exit(1);
}
@ -1039,14 +1036,14 @@ static void keybd_prepare(on_screen_keyboard *keyboard)
}
static void apply_surface (int x, int y, SDL_Surface *source, SDL_Surface *destination, SDL_Rect *clip)
static void apply_surface(int x, int y, SDL_Surface * source, SDL_Surface * destination, SDL_Rect * clip)
{
SDL_Rect offset;
offset.x = x;
offset.y = y;
SDL_BlitSurface( source, clip, destination, &offset );
SDL_BlitSurface(source, clip, destination, &offset);
}
@ -1075,10 +1072,10 @@ static void apply_surface (int x, int y, SDL_Surface *source, SDL_Surface *desti
/* } */
/* Stretches a button from the middle, keeping the extrems intact */
static SDL_Surface * stretch_surface(SDL_Surface * orig, int width)
static SDL_Surface *stretch_surface(SDL_Surface * orig, int width)
{
int i;
SDL_Surface * dest;
SDL_Surface *dest;
SDL_Rect rect;
SDL_Rect orig_rect;
@ -1091,9 +1088,7 @@ static SDL_Surface * stretch_surface(SDL_Surface * orig, int width)
width,
orig->h,
orig->format->BitsPerPixel,
orig->format->Rmask,
orig->format->Gmask,
orig->format->Bmask, 0);
orig->format->Rmask, orig->format->Gmask, orig->format->Bmask, 0);
SDL_BlitSurface(orig, NULL, dest, NULL);
rect.y = 0;
@ -1134,11 +1129,12 @@ static SDL_Surface * stretch_surface(SDL_Surface * orig, int width)
}
/* Draws the keyboard surface */
static void draw_keyboard(on_screen_keyboard *keyboard)
static void draw_keyboard(on_screen_keyboard * keyboard)
{
int i, j;
int key_height, accumulated_width, accumulated_height;
float key_width;
key_width = keyboard->button_up->w;
key_height = keyboard->button_up->h;
@ -1156,7 +1152,8 @@ static void draw_keyboard(on_screen_keyboard *keyboard)
keyboard->layout->keys[j][i].x = accumulated_width;
keyboard->layout->keys[j][i].y = accumulated_height;
draw_key(keyboard->layout->keys[j][i], keyboard, 0); }
draw_key(keyboard->layout->keys[j][i], keyboard, 0);
}
accumulated_width += (keyboard->layout->keys[j][i].width * key_width);
}
accumulated_height += key_height;
@ -1178,9 +1175,9 @@ static void draw_key(osk_key key, on_screen_keyboard * keyboard, int hot)
text = malloc(sizeof(char) * 255);
snprintf(text, 6,"%s", key.plain_label);
snprintf(text, 6, "%s", key.plain_label);
if( strncmp("NULL", text, 4) != 0 && key.keycode != 0)
if (strncmp("NULL", text, 4) != 0 && key.keycode != 0)
{
if (hot)
skey = stretch_surface(keyboard->button_down, key.width * keyboard->button_down->w);
@ -1213,7 +1210,7 @@ static void draw_key(osk_key key, on_screen_keyboard * keyboard, int hot)
/* FIXME: TODO draw top and bottom_right (altgr) labels */
static void label_key(osk_key key, on_screen_keyboard *keyboard)
static void label_key(osk_key key, on_screen_keyboard * keyboard)
{
SDL_Surface *messager;
int modstate;
@ -1227,7 +1224,7 @@ static void label_key(osk_key key, on_screen_keyboard *keyboard)
/* FIXME There MUST be a simpler way to do this. Pere 2011/8/3 */
/* First the plain ones */
if (modstate == KMOD_NONE || (modstate == (KMOD_NONE | KMOD_LALT)))
text=strdup(key.plain_label);
text = strdup(key.plain_label);
else if (modstate == KMOD_SHIFT)
{
@ -1280,52 +1277,51 @@ static void label_key(osk_key key, on_screen_keyboard *keyboard)
text = strdup(key.top_label);
}
if( strncmp("DELETE", text, 6) == 0)
if (strncmp("DELETE", text, 6) == 0)
{
apply_surface(key.x, key.y, keyboard->oskdel, keyboard->surface, NULL);
}
else if( strncmp("TAB", text, 3) == 0)
else if (strncmp("TAB", text, 3) == 0)
{
apply_surface(key.x, key.y, keyboard->osktab, keyboard->surface, NULL);
}
else if( strncmp("ENTER", text, 5) == 0)
else if (strncmp("ENTER", text, 5) == 0)
{
apply_surface(key.x, key.y, keyboard->oskenter, keyboard->surface, NULL);
}
else if( strncmp("CAPSLOCK", text, 8) == 0)
else if (strncmp("CAPSLOCK", text, 8) == 0)
{
apply_surface(key.x, key.y, keyboard->oskcapslock, keyboard->surface, NULL);
}
else if( strncmp("SHIFT", text, 5) == 0)
else if (strncmp("SHIFT", text, 5) == 0)
{
apply_surface(key.x, key.y, keyboard->oskshift, keyboard->surface, NULL);
}
else if( strncmp("SPACE", text, 5) != 0 && strncmp("NULL", text, 4) != 0)
else if (strncmp("SPACE", text, 5) != 0 && strncmp("NULL", text, 4) != 0)
{
messager = TTF_RenderUTF8_Blended(keyboard->osk_fonty, text, keyboard->layout->fgcolor);
apply_surface( key.x + 5, key.y, messager, keyboard->surface, NULL);
apply_surface(key.x + 5, key.y, messager, keyboard->surface, NULL);
SDL_FreeSurface(messager);
}
free(text);
}
/* Searches the key corresponding to coordinates */
static osk_key * find_key(on_screen_keyboard * keyboard, int x, int y)
static osk_key *find_key(on_screen_keyboard * keyboard, int x, int y)
{
int i, j;
osk_key *key;
key = NULL;
for (j = 0; j <keyboard->layout->height; j++)
for (j = 0; j < keyboard->layout->height; j++)
{
if (keyboard->layout->keys[j][0].y < y &&
keyboard->layout->keys[j][0].y + keyboard->button_up->h > y)
if (keyboard->layout->keys[j][0].y < y && keyboard->layout->keys[j][0].y + keyboard->button_up->h > y)
for (i = 0; i < keyboard->layout->width; i++)
if (keyboard->layout->keys[j][i].x < x &&
keyboard->layout->keys[j][i].x + keyboard->layout->keys[j][i].width * keyboard->button_up->w > x)
@ -1340,7 +1336,7 @@ static osk_key * find_key(on_screen_keyboard * keyboard, int x, int y)
/* Copies orig to dest or sets dest to defaults if orig is NULL.
if firstime is setted, don't frees the strings as there aren't. */
static void set_key(osk_key *orig, osk_key *dest, int firsttime)
static void set_key(osk_key * orig, osk_key * dest, int firsttime)
{
if (orig == NULL)
{
@ -1384,7 +1380,7 @@ static void set_key(osk_key *orig, osk_key *dest, int firsttime)
}
}
static char * find_keysym(osk_key key, on_screen_keyboard *keyboard)
static char *find_keysym(osk_key key, on_screen_keyboard * keyboard)
{
int keycode;
char *keysym;
@ -1452,11 +1448,11 @@ static char * find_keysym(osk_key key, on_screen_keyboard *keyboard)
keysym = keysyms.caps;
}
return(keysym);
return (keysym);
}
/* We lose the SDL ModState by leaving and entering the tuxpaint window, so using a custom state */
static int handle_keymods(char * keysym, osk_key * key, on_screen_keyboard *keyboard)
static int handle_keymods(char *keysym, osk_key * key, on_screen_keyboard * keyboard)
{
SDL_Keymod mod;
SDL_Event ev;
@ -1492,9 +1488,8 @@ static int handle_keymods(char * keysym, osk_key * key, on_screen_keyboard *keyb
}
/* Seems ISO_Level3_Shift and ISO_Next_Group are used too for right Alt */
else if (strncmp("ISO_Level3_Shift", keysym, 16) == 0||
strncmp("ISO_Next_Group", keysym, 14) == 0||
strncmp("ALT_R", keysym, 5) == 0)
else if (strncmp("ISO_Level3_Shift", keysym, 16) == 0 ||
strncmp("ISO_Next_Group", keysym, 14) == 0 || strncmp("ALT_R", keysym, 5) == 0)
{
if (mod & KMOD_RALT)
{
@ -1536,9 +1531,9 @@ static int handle_keymods(char * keysym, osk_key * key, on_screen_keyboard *keyb
else
keyboard->modifiers = KMOD_NONE;
if(keyboard->kmdf.shift)
if (keyboard->kmdf.shift)
keyboard->kmdf.shift->stick = 0;
if(keyboard->kmdf.altgr)
if (keyboard->kmdf.altgr)
keyboard->kmdf.altgr->stick = 0;
return 0;
@ -1546,44 +1541,44 @@ static int handle_keymods(char * keysym, osk_key * key, on_screen_keyboard *keyb
/* set_dead_sticks and clear_dead_sticks deals with the persistence of
the keys that are still affecting other key presses. */
static void set_dead_sticks(osk_key *key, on_screen_keyboard *keyboard)
static void set_dead_sticks(osk_key * key, on_screen_keyboard * keyboard)
{
key->stick= 1;
if(!keyboard->kmdf.dead)
key->stick = 1;
if (!keyboard->kmdf.dead)
keyboard->kmdf.dead = key;
else if(!keyboard->kmdf.dead2)
else if (!keyboard->kmdf.dead2)
keyboard->kmdf.dead2 = key;
else if(!keyboard->kmdf.dead3)
else if (!keyboard->kmdf.dead3)
keyboard->kmdf.dead3 = key;
else if(!keyboard->kmdf.dead4)
else if (!keyboard->kmdf.dead4)
keyboard->kmdf.dead4 = key;
}
static void clear_dead_sticks(on_screen_keyboard *keyboard)
static void clear_dead_sticks(on_screen_keyboard * keyboard)
{
if(keyboard->kmdf.dead)
if (keyboard->kmdf.dead)
{
keyboard->kmdf.dead->stick = 0;
keyboard->kmdf.dead = NULL;
}
if(keyboard->kmdf.dead2)
if (keyboard->kmdf.dead2)
{
keyboard->kmdf.dead2->stick = 0;
keyboard->kmdf.dead2 = NULL;
}
if(keyboard->kmdf.dead3)
if (keyboard->kmdf.dead3)
{
keyboard->kmdf.dead3->stick = 0;
keyboard->kmdf.dead3 = NULL;
}
if(keyboard->kmdf.dead4)
if (keyboard->kmdf.dead4)
{
keyboard->kmdf.dead4->stick = 0;
keyboard->kmdf.dead4 = NULL;
}
}
struct osk_keyboard * osk_clicked(on_screen_keyboard *keyboard, int x, int y)
struct osk_keyboard *osk_clicked(on_screen_keyboard * keyboard, int x, int y)
{
int i;
osk_key *key;
@ -1592,7 +1587,7 @@ struct osk_keyboard * osk_clicked(on_screen_keyboard *keyboard, int x, int y)
char *name, *aux_name, *aux_list, *aux_list_ptr;
wchar_t *wkeysym;
wchar_t *ks;
on_screen_keyboard * new_keyboard;
on_screen_keyboard *new_keyboard;
#ifdef DEBUG
printf("list: %s\n", keyboard->keyboard_list);
@ -1613,7 +1608,7 @@ struct osk_keyboard * osk_clicked(on_screen_keyboard *keyboard, int x, int y)
if (keyboard->disable_change)
{
// free(key);
return(keyboard);
return (keyboard);
}
aux_list = strdup(keyboard->keyboard_list);
@ -1626,14 +1621,14 @@ struct osk_keyboard * osk_clicked(on_screen_keyboard *keyboard, int x, int y)
if (key->keycode == 1)
{
for (i = 0;;i++, aux_list = NULL)
for (i = 0;; i++, aux_list = NULL)
{
name = strtok(aux_list, " \n\r\t");
if (i == 0)
aux_name = name;
if(strcmp(name, keyboard->name) == 0)
if (strcmp(name, keyboard->name) == 0)
{
name = strtok(NULL, " \n\r\t");
if (name == NULL)
@ -1645,17 +1640,17 @@ struct osk_keyboard * osk_clicked(on_screen_keyboard *keyboard, int x, int y)
else
{
aux_name = NULL;
for (i = 0;;i++, aux_list = NULL)
for (i = 0;; i++, aux_list = NULL)
{
name = strtok(aux_list, " \n\r\t");
if(name == NULL)
if (name == NULL)
{
name = aux_name;
break;
}
if(strstr(name, keyboard->name))
if (strstr(name, keyboard->name))
{
name = aux_name;
if (name != NULL)
@ -1667,14 +1662,17 @@ struct osk_keyboard * osk_clicked(on_screen_keyboard *keyboard, int x, int y)
}
new_keyboard = osk_create(name, keyboard->surface, keyboard->button_up, keyboard->button_down, keyboard->button_off, keyboard->button_nav, keyboard->button_hold, keyboard->oskdel, keyboard->osktab, keyboard->oskenter, keyboard->oskcapslock, keyboard->oskshift, keyboard->disable_change);
new_keyboard =
osk_create(name, keyboard->surface, keyboard->button_up, keyboard->button_down, keyboard->button_off,
keyboard->button_nav, keyboard->button_hold, keyboard->oskdel, keyboard->osktab,
keyboard->oskenter, keyboard->oskcapslock, keyboard->oskshift, keyboard->disable_change);
free(aux_list_ptr);
if (new_keyboard == NULL)
{
// free(key);
return(keyboard); /* Don't break here, at least the old keyboard should work */
return (keyboard); /* Don't break here, at least the old keyboard should work */
}
else
{
@ -1682,7 +1680,7 @@ struct osk_keyboard * osk_clicked(on_screen_keyboard *keyboard, int x, int y)
new_keyboard->keyboard_list = strdup(keyboard->keyboard_list);
// free(key);
osk_free(keyboard);
return(new_keyboard);
return (new_keyboard);
}
}
@ -1690,21 +1688,19 @@ struct osk_keyboard * osk_clicked(on_screen_keyboard *keyboard, int x, int y)
keysym = find_keysym(*key, keyboard);
if (!keysym)
{
return(keyboard);
return (keyboard);
}
draw_key(*key, keyboard, 1);
if (handle_keymods(keysym, key, keyboard))
{
return(keyboard); /* no more processing is needed */
return (keyboard); /* no more processing is needed */
}
wkeysym = malloc(sizeof(wchar_t) * (strlen(keysym) + 1));
mbsrtowcs(wkeysym, (const char **) &keysym,
strlen(keysym)+1,
NULL);
mbsrtowcs(wkeysym, (const char **)&keysym, strlen(keysym) + 1, NULL);
#ifdef DEBUG
printf("wkeysym %ls %i\n\n", wkeysym, (int)wcslen(wkeysym));
@ -1731,8 +1727,7 @@ struct osk_keyboard * osk_clicked(on_screen_keyboard *keyboard, int x, int y)
event.key.keysym.sym = SDLK_RETURN;
event.text.text[0] = '\r';
}
else if (wcsncmp(L"Tab", ks, 3) == 0 ||
wcsncmp(L"ISO_Left_Tab", ks, 12) == 0)
else if (wcsncmp(L"Tab", ks, 3) == 0 || wcsncmp(L"ISO_Left_Tab", ks, 12) == 0)
{
event.key.keysym.sym = SDLK_TAB;
event.text.text[0] = '\t';
@ -1743,7 +1738,7 @@ struct osk_keyboard * osk_clicked(on_screen_keyboard *keyboard, int x, int y)
event.text.text[0] = '\b';
}
else if (wcsncmp(L"NoSymbol", ks, 8) == 0)
return(keyboard);
return (keyboard);
else
// printf("kcomposed %ls\n", *keyboard->composed);
@ -1783,12 +1778,13 @@ struct osk_keyboard * osk_clicked(on_screen_keyboard *keyboard, int x, int y)
free(wkeysym);
}
return(keyboard);
return (keyboard);
}
void osk_released(on_screen_keyboard *keyboard)
void osk_released(on_screen_keyboard * keyboard)
{
osk_key *key;
key = keyboard->last_key_pressed;
if (key)
{
@ -1800,10 +1796,11 @@ void osk_released(on_screen_keyboard *keyboard)
}
static void free_keymap(osk_keymap *keymap)
static void free_keymap(osk_keymap * keymap)
{
int i;
for (i=0; i<256; i++)
for (i = 0; i < 256; i++)
{
if (keymap[i].plain)
free(keymap[i].plain);
@ -1820,7 +1817,8 @@ static void free_keymap(osk_keymap *keymap)
static void free_composemap(osk_composenode * composenode)
{
int i;
for(i = 0; i < composenode->size; i++)
for (i = 0; i < composenode->size; i++)
{
free_composemap(composenode->childs[i]);
free(composenode->childs[i]);
@ -1834,7 +1832,7 @@ static void free_composemap(osk_composenode * composenode)
free(composenode->keysym);
}
static void free_keysymdefs(keysymdefs *ksd, int size)
static void free_keysymdefs(keysymdefs * ksd, int size)
{
int i;
@ -1842,7 +1840,7 @@ static void free_keysymdefs(keysymdefs *ksd, int size)
free(ksd[i].mnemo);
}
static void free_keys(osk_layout *layout)
static void free_keys(osk_layout * layout)
{
int i, j;
@ -1865,7 +1863,7 @@ static void free_keys(osk_layout *layout)
free(layout->keys);
}
static void free_layout(osk_layout *layout)
static void free_layout(osk_layout * layout)
{
if (layout->name != NULL)
free(layout->name);
@ -1881,15 +1879,15 @@ static void free_layout(osk_layout *layout)
free(layout);
}
void osk_free(on_screen_keyboard *keyboard)
void osk_free(on_screen_keyboard * keyboard)
{
free(keyboard->name);
free_layout(keyboard->layout);
if(keyboard->composed)
if (keyboard->composed)
free(keyboard->composed);
if(keyboard->last_key_pressed)
if (keyboard->last_key_pressed)
free(keyboard->last_key_pressed);
if(keyboard->keyboard_list)
if (keyboard->keyboard_list)
free(keyboard->keyboard_list);
SDL_FreeSurface(keyboard->surface);
set_key(NULL, &keyboard->keymodifiers.shift, 0);
@ -2065,4 +2063,3 @@ void osk_free(on_screen_keyboard *keyboard)
/* } */
/* } */
/* } */

View file

@ -28,10 +28,10 @@ typedef struct osk_keymap
{
int keycode;
int disable_caps; /* If caps lock should affect this key */
char * plain; /* The default Xkeysym for the keycode */
char * caps; /* If CapsLock or Shift + key */
char * altgr; /* If AltGr + key */
char * shiftaltgr; /* If AltGr + Shift + key */
char *plain; /* The default Xkeysym for the keycode */
char *caps; /* If CapsLock or Shift + key */
char *altgr; /* If AltGr + key */
char *shiftaltgr; /* If AltGr + Shift + key */
} osk_keymap;
typedef struct osk_key
@ -51,16 +51,16 @@ typedef struct osk_key
typedef struct osk_composenode
{
wchar_t * keysym;
wchar_t * result;
wchar_t *keysym;
wchar_t *result;
int size; /* How many childs are there. */
struct osk_composenode ** childs;
struct osk_composenode **childs;
// struct osk_composenode **parent;
} osk_composenode;
typedef struct keysymdefs
{
char * mnemo;
char *mnemo;
int keysym;
int unicode;
} keysymdefs;
@ -71,11 +71,11 @@ typedef struct osk_layout
int *rows;
int width;
int height;
char * fontpath;
char *fontpath;
osk_key **keys;
osk_keymap *keymap;
osk_composenode * composemap;
keysymdefs * keysymdefs;
osk_composenode *composemap;
keysymdefs *keysymdefs;
unsigned int sizeofkeysymdefs;
SDL_Color bgcolor;
SDL_Color fgcolor;
@ -91,19 +91,19 @@ typedef struct osk_keymodifiers
typedef struct osk_kmdf
{
osk_key * shift;
osk_key * altgr;
osk_key * compose;
osk_key * dead;
osk_key * dead2;
osk_key * dead3;
osk_key * dead4;
osk_key *shift;
osk_key *altgr;
osk_key *compose;
osk_key *dead;
osk_key *dead2;
osk_key *dead3;
osk_key *dead4;
} osk_kmdf;
typedef struct osk_keyboard
{
char * name; /* The name of the keyboard */
char * keyboard_list; /* The names of the keyboards allowed from this one */
char *name; /* The name of the keyboard */
char *keyboard_list; /* The names of the keyboards allowed from this one */
SDL_Surface *surface; /* The surface containing the keyboard */
SDL_Surface *button_up; /* The surfaces containing the buttons */
SDL_Surface *button_down;
@ -123,24 +123,29 @@ typedef struct osk_keyboard
osk_kmdf kmdf;
osk_layout *layout; /* The layout struct */
char *layout_name[256]; /* The layout name */
TTF_Font * osk_fonty; /* Font */
TTF_Font *osk_fonty; /* Font */
int disable_change; /* If true, stay with the first layout found */
wchar_t * key[256]; /* The text of the key */
wchar_t *key[256]; /* The text of the key */
int keycode; /* The unicode code corresponding to the key */
wchar_t * composed; /* The unicode char found after a sequence of key presses */
wchar_t *composed; /* The unicode char found after a sequence of key presses */
int composed_type; /* 1 if the value stored in composed is yet the unicode value */
osk_composenode * composing; /* The node in the middle of a compose sequence */
osk_key * last_key_pressed; /* The last key pressed */
osk_composenode *composing; /* The node in the middle of a compose sequence */
osk_key *last_key_pressed; /* The last key pressed */
} on_screen_keyboard;
struct osk_keyboard *osk_create(char *layout_name, SDL_Surface *canvas, SDL_Surface *button_up, SDL_Surface *button_down, SDL_Surface *button_off, SDL_Surface *button_nav, SDL_Surface *button_hold, SDL_Surface *oskdel, SDL_Surface *osktab, SDL_Surface *oskenter, SDL_Surface *oskcapslock, SDL_Surface *oskshift, int disable_change);
struct osk_keyboard *osk_create(char *layout_name, SDL_Surface * canvas, SDL_Surface * button_up,
SDL_Surface * button_down, SDL_Surface * button_off, SDL_Surface * button_nav,
SDL_Surface * button_hold, SDL_Surface * oskdel, SDL_Surface * osktab,
SDL_Surface * oskenter, SDL_Surface * oskcapslock, SDL_Surface * oskshift,
int disable_change);
struct osk_layout *osk_load_layout(char *layout_name);
void osk_get_layout_data(char *layout_name, int *layout_w, int *layout_h, char * layout_buttons, char *layout_labels, char *layout_keycodes);
void osk_reset(on_screen_keyboard *osk);
struct osk_keyboard * osk_clicked(on_screen_keyboard *keyboard, int x, int y);
void osk_released(on_screen_keyboard *osk);
void osk_hover(on_screen_keyboard *keyboard, int x, int y);
void osk_free(on_screen_keyboard *osk);
void osk_change_layout(on_screen_keyboard *osk);
void osk_get_layout_data(char *layout_name, int *layout_w, int *layout_h, char *layout_buttons, char *layout_labels,
char *layout_keycodes);
void osk_reset(on_screen_keyboard * osk);
struct osk_keyboard *osk_clicked(on_screen_keyboard * keyboard, int x, int y);
void osk_released(on_screen_keyboard * osk);
void osk_hover(on_screen_keyboard * keyboard, int x, int y);
void osk_free(on_screen_keyboard * osk);
void osk_change_layout(on_screen_keyboard * osk);

View file

@ -86,4 +86,5 @@ struct cfginfo
#define CFGINFO_MAXOFFSET (sizeof(struct cfginfo))
extern void parse_one_option(struct cfginfo *restrict tmpcfg, const char *str, const char *opt, const char *restrict src);
extern void parse_one_option(struct cfginfo *restrict tmpcfg, const char *str, const char *opt,
const char *restrict src);

View file

@ -37,9 +37,7 @@ static void putpixel8(SDL_Surface * surface, int x, int y, Uint32 pixel)
Uint8 *p;
/* Assuming the X/Y values are within the bounds of this surface... */
if (likely
(likely((unsigned) x < (unsigned) surface->w)
&& likely((unsigned) y < (unsigned) surface->h)))
if (likely(likely((unsigned)x < (unsigned)surface->w) && likely((unsigned)y < (unsigned)surface->h)))
{
// Set a pointer to the exact location in memory of the pixel
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start: beginning of RAM */
@ -60,9 +58,7 @@ static void putpixel16(SDL_Surface * surface, int x, int y, Uint32 pixel)
Uint8 *p;
/* Assuming the X/Y values are within the bounds of this surface... */
if (likely
(likely((unsigned) x < (unsigned) surface->w)
&& likely((unsigned) y < (unsigned) surface->h)))
if (likely(likely((unsigned)x < (unsigned)surface->w) && likely((unsigned)y < (unsigned)surface->h)))
{
// Set a pointer to the exact location in memory of the pixel
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start: beginning of RAM */
@ -83,9 +79,7 @@ static void putpixel24(SDL_Surface * surface, int x, int y, Uint32 pixel)
Uint8 *p;
/* Assuming the X/Y values are within the bounds of this surface... */
if (likely
(likely((unsigned) x < (unsigned) surface->w)
&& likely((unsigned) y < (unsigned) surface->h)))
if (likely(likely((unsigned)x < (unsigned)surface->w) && likely((unsigned)y < (unsigned)surface->h)))
{
// Set a pointer to the exact location in memory of the pixel
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start: beginning of RAM */
@ -118,9 +112,7 @@ static void putpixel32(SDL_Surface * surface, int x, int y, Uint32 pixel)
Uint8 *p;
/* Assuming the X/Y values are within the bounds of this surface... */
if (likely
(likely((unsigned) x < (unsigned) surface->w)
&& likely((unsigned) y < (unsigned) surface->h)))
if (likely(likely((unsigned)x < (unsigned)surface->w) && likely((unsigned)y < (unsigned)surface->h)))
{
// Set a pointer to the exact location in memory of the pixel
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start: beginning of RAM */
@ -141,9 +133,9 @@ static Uint32 getpixel8(SDL_Surface * surface, int x, int y)
Uint8 *p;
/* get the X/Y values within the bounds of this surface */
if (unlikely((unsigned) x > (unsigned) surface->w - 1u))
if (unlikely((unsigned)x > (unsigned)surface->w - 1u))
x = (x < 0) ? 0 : surface->w - 1;
if (unlikely((unsigned) y > (unsigned) surface->h - 1u))
if (unlikely((unsigned)y > (unsigned)surface->h - 1u))
y = (y < 0) ? 0 : surface->h - 1;
/* Set a pointer to the exact location in memory of the pixel
@ -167,9 +159,9 @@ static Uint32 getpixel16(SDL_Surface * surface, int x, int y)
Uint8 *p;
/* get the X/Y values within the bounds of this surface */
if (unlikely((unsigned) x > (unsigned) surface->w - 1u))
if (unlikely((unsigned)x > (unsigned)surface->w - 1u))
x = (x < 0) ? 0 : surface->w - 1;
if (unlikely((unsigned) y > (unsigned) surface->h - 1u))
if (unlikely((unsigned)y > (unsigned)surface->h - 1u))
y = (y < 0) ? 0 : surface->h - 1;
/* Set a pointer to the exact location in memory of the pixel
@ -194,9 +186,9 @@ static Uint32 getpixel24(SDL_Surface * surface, int x, int y)
Uint32 pixel;
/* get the X/Y values within the bounds of this surface */
if (unlikely((unsigned) x > (unsigned) surface->w - 1u))
if (unlikely((unsigned)x > (unsigned)surface->w - 1u))
x = (x < 0) ? 0 : surface->w - 1;
if (unlikely((unsigned) y > (unsigned) surface->h - 1u))
if (unlikely((unsigned)y > (unsigned)surface->h - 1u))
y = (y < 0) ? 0 : surface->h - 1;
/* Set a pointer to the exact location in memory of the pixel
@ -227,9 +219,9 @@ static Uint32 getpixel32(SDL_Surface * surface, int x, int y)
Uint8 *p;
/* get the X/Y values within the bounds of this surface */
if (unlikely((unsigned) x > (unsigned) surface->w - 1u))
if (unlikely((unsigned)x > (unsigned)surface->w - 1u))
x = (x < 0) ? 0 : surface->w - 1;
if (unlikely((unsigned) y > (unsigned) surface->h - 1u))
if (unlikely((unsigned)y > (unsigned)surface->h - 1u))
y = (y < 0) ? 0 : surface->h - 1;
/* Set a pointer to the exact location in memory of the pixel

View file

@ -33,8 +33,7 @@ int mute;
int use_sound = 1;
static int old_sound[4] = { -1, -1, -1, -1 };
void playsound(SDL_Surface * screen, int chan, int s, int override, int x,
int y)
void playsound(SDL_Surface * screen, int chan, int s, int override, int x, int y)
{
#ifndef NOSOUND
int left, dist;

View file

@ -37,7 +37,6 @@
extern Mix_Chunk *sounds[NUM_SOUNDS];
extern int mute, use_sound;
void playsound(SDL_Surface * screen, int chan, int s, int override, int x,
int y);
void playsound(SDL_Surface * screen, int chan, int s, int override, int x, int y);
#endif

View file

@ -78,12 +78,9 @@ static int f2dec(float f)
/* Actually save the PostScript data to the file stream: */
int do_ps_save(FILE * fi,
const char *restrict const fname,
SDL_Surface * surf,
const char *restrict pprsize,
int is_pipe)
const char *restrict const fname, SDL_Surface * surf, const char *restrict pprsize, int is_pipe)
{
const struct paper * ppr;
const struct paper *ppr;
int img_w = surf->w;
int img_h = surf->h;
int r_img_w, r_img_h;
@ -94,8 +91,8 @@ int do_ps_save(FILE * fi,
int plane;
Uint8 r, g, b;
char buf[256];
Uint32(*getpixel) (SDL_Surface *, int, int) =
getpixels[surf->format->BytesPerPixel];
Uint32(*getpixel) (SDL_Surface *, int, int) = getpixels[surf->format->BytesPerPixel];
int printed_img_w, printed_img_h;
time_t t = time(NULL);
int rotate;
@ -151,8 +148,7 @@ int do_ps_save(FILE * fi,
ppr_h = paperpsheight(ppr);
#ifdef DEBUG
printf("Paper is %d x %d (%.2f\" x %.2f\")\n", ppr_w, ppr_h,
(float) ppr_w / 72.0, (float) ppr_h / 72.0);
printf("Paper is %d x %d (%.2f\" x %.2f\")\n", ppr_w, ppr_h, (float)ppr_w / 72.0, (float)ppr_h / 72.0);
#endif
paperdone(); // FIXME: Should we do this at quit? -bjk 2007.06.25
@ -160,8 +156,7 @@ int do_ps_save(FILE * fi,
/* Determine whether it's best to rotate the image: */
if ((ppr_w >= ppr_h && img_w >= img_h) ||
(ppr_w <= ppr_h && img_w <= img_h))
if ((ppr_w >= ppr_h && img_w >= img_h) || (ppr_w <= ppr_h && img_w <= img_h))
{
rotate = 0;
r_img_w = img_w;
@ -183,15 +178,13 @@ int do_ps_save(FILE * fi,
/* Determine scale: */
scale = my_min(((float) (ppr_w - (MARGIN * 2)) / (float) r_img_w),
((float) (ppr_h - (MARGIN * 2)) / (float) r_img_h));
scale = my_min(((float)(ppr_w - (MARGIN * 2)) / (float)r_img_w), ((float)(ppr_h - (MARGIN * 2)) / (float)r_img_h));
printed_img_w = r_img_w * scale;
printed_img_h = r_img_h * scale;
#ifdef DEBUG
printf("Scaling image by %.2f (to %d x %d)\n", scale,
printed_img_w, printed_img_h);
printf("Scaling image by %.2f (to %d x %d)\n", scale, printed_img_w, printed_img_h);
#endif
@ -217,8 +210,7 @@ int do_ps_save(FILE * fi,
fprintf(fi, "%%%%Pages: 1\n");
fprintf(fi, "%%%%BoundingBox: 0 0 %d %d\n", (int) (ppr_w + 0.5), (int)
(ppr_h + 0.5));
fprintf(fi, "%%%%BoundingBox: 0 0 %d %d\n", (int)(ppr_w + 0.5), (int)(ppr_h + 0.5));
fprintf(fi, "%%%%EndComments\n");
@ -237,24 +229,20 @@ int do_ps_save(FILE * fi,
fprintf(fi, "%%%%Page: 1 1\n");
fprintf(fi, "<< /PageSize [ %d %d ] /ImagingBBox null >> setpagedevice\n",
ppr_w, ppr_h);
fprintf(fi, "<< /PageSize [ %d %d ] /ImagingBBox null >> setpagedevice\n", ppr_w, ppr_h);
fprintf(fi, "gsave\n");
/* 'translate' moves the user space origin to a new position with
respect to the current page, leaving the orientation of the axes and
the unit lengths unchanged. */
fprintf(fi, "%d.%02d %d.%02d translate\n",
f2int(tlate_x), f2dec(tlate_x),
f2int(tlate_y), f2dec(tlate_y));
fprintf(fi, "%d.%02d %d.%02d translate\n", f2int(tlate_x), f2dec(tlate_x), f2int(tlate_y), f2dec(tlate_y));
/* 'scale' modifies the unit lengths independently along the current
x and y axes, leaving the origin location and the orientation of the
axes unchanged. */
fprintf(fi, "%d.%02d %d.%02d scale\n",
f2int(printed_img_w), f2dec(printed_img_w),
f2int(printed_img_h), f2dec(printed_img_h));
f2int(printed_img_w), f2dec(printed_img_w), f2int(printed_img_h), f2dec(printed_img_h));
/* Rotate the image */
if (rotate)
@ -316,9 +304,12 @@ int do_ps_save(FILE * fi,
printf("errno = %d\n", errno); fflush(stdout);
*/
if (child_pid < 0 || (errno != 0 && errno != EAGAIN)) { /* FIXME: This right? */
if (child_pid < 0 || (errno != 0 && errno != EAGAIN))
{ /* FIXME: This right? */
return 0;
} else if (child_pid == 0) {
}
else if (child_pid == 0)
{
return 1;
}
@ -350,4 +341,3 @@ int do_ps_save(FILE * fi,
}
#endif

View file

@ -79,12 +79,8 @@
#ifdef PRINTMETHOD_PS
int do_ps_save(FILE * fi,
const char *restrict const fname,
SDL_Surface * surf,
const char *restrict pprsize,
int is_pipe);
const char *restrict const fname, SDL_Surface * surf, const char *restrict pprsize, int is_pipe);
#endif
#endif /* POSTSCRIPT_PRINT_H */

View file

@ -34,7 +34,7 @@
SDL_Surface *img_progress;
int progress_bar_disabled, prog_bar_ctr;
void show_progress_bar_(SDL_Surface * screen, SDL_Texture *texture, SDL_Renderer *renderer)
void show_progress_bar_(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer * renderer)
{
SDL_Rect dest, src, r;
int x;

View file

@ -33,6 +33,7 @@
unsigned char linear_to_sRGB(float linear)
{
unsigned slot;
slot = linear * 4096.0 + 0.5;
if (slot > 4095)
{

View file

@ -305,8 +305,7 @@ static const unsigned char linear_to_sRGB_table[4096] =
"\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd"
"\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe"
"\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe"
"\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff"
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff";
"\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff" "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff";
unsigned char linear_to_sRGB(float linear) FUNCTION;

View file

@ -78,12 +78,12 @@ const int shape_sides[NUM_SHAPES] = {
4, /* Rhombus */
8, /* Octagon */
8, /* Octagon */
3, /* 3 points star*/
3, /* 3 points star*/
4, /* 4 points star*/
4, /* 4 points star*/
5, /* 5 points star*/
5 /* 5 points star*/
3, /* 3 points star */
3, /* 3 points star */
4, /* 4 points star */
4, /* 4 points star */
5, /* 5 points star */
5 /* 5 points star */
};
@ -106,12 +106,12 @@ const int shape_locked[NUM_SHAPES] = {
0, /* Rhombus */
1, /* Octagon */
1, /* Octagon */
0, /* 3 points star*/
0, /* 3 points star*/
0, /* 4 points star*/
0, /* 4 points star*/
0, /* 5 points star*/
0 /* 5 points star*/
0, /* 3 points star */
0, /* 3 points star */
0, /* 4 points star */
0, /* 4 points star */
0, /* 5 points star */
0 /* 5 points star */
};
@ -134,12 +134,12 @@ const int shape_filled[NUM_SHAPES] = {
1, /* Rhombus */
0, /* Octagon */
1, /* Octagon */
0, /* 3 points star*/
1, /* 3 points star*/
0, /* 4 points star*/
1, /* 4 points star*/
0, /* 5 points star*/
1 /* 5 points star*/
0, /* 3 points star */
1, /* 3 points star */
0, /* 4 points star */
1, /* 4 points star */
0, /* 5 points star */
1 /* 5 points star */
};
@ -163,10 +163,10 @@ const int shape_init_ang[NUM_SHAPES] = {
0, /* Rhombus */
22, /* Octagon */
22, /* Octagon */
210, /* 3 points star*/
210, /* 3 points star*/
0, /* 4 points star*/
0, /* 4 points star*/
210, /* 3 points star */
210, /* 3 points star */
0, /* 4 points star */
0, /* 4 points star */
162, /* 5 points star */
162 /* 5 points star */
};
@ -279,7 +279,6 @@ const char *const shape_names[NUM_SHAPES] = {
// Pentagone star (5 points star)
gettext_noop("Star")
};
@ -295,10 +294,8 @@ const char *const shape_tips[NUM_SHAPES] = {
gettext_noop("A rectangle has four sides and four right angles."),
// Description of a circle
gettext_noop
("A circle is a curve where all points have the same distance from the center."),
gettext_noop
("A circle is a curve where all points have the same distance from the center."),
gettext_noop("A circle is a curve where all points have the same distance from the center."),
gettext_noop("A circle is a curve where all points have the same distance from the center."),
// Description of an ellipse
gettext_noop("An ellipse is a stretched circle."),
@ -313,16 +310,12 @@ const char *const shape_tips[NUM_SHAPES] = {
gettext_noop("A pentagon has five sides."),
// Description of a rhombus
gettext_noop
("A rhombus has four equal sides, and opposite sides are parallel."),
gettext_noop
("A rhombus has four equal sides, and opposite sides are parallel."),
gettext_noop("A rhombus has four equal sides, and opposite sides are parallel."),
gettext_noop("A rhombus has four equal sides, and opposite sides are parallel."),
// Description of an octagon
gettext_noop
("An octagon has eight equal sides."),
gettext_noop
("An octagon has eight equal sides."),
gettext_noop("An octagon has eight equal sides."),
gettext_noop("An octagon has eight equal sides."),
gettext_noop("A star with 3 points."),
gettext_noop("A star with 3 points."),
@ -330,7 +323,6 @@ const char *const shape_tips[NUM_SHAPES] = {
gettext_noop("A star with 4 points."),
gettext_noop("A star with 5 points."),
gettext_noop("A star with 5 points.")
};
@ -359,5 +351,4 @@ const char *const shape_img_fnames[NUM_SHAPES] = {
DATA_PREFIX "images/shapes/star4p_f.png",
DATA_PREFIX "images/shapes/star5p.png",
DATA_PREFIX "images/shapes/star5p_f.png"
};

View file

@ -121,13 +121,16 @@ const char *const tool_tips[NUM_TOOLS] = {
gettext_noop("Click to start drawing a line. Let go to complete it."),
// Shape tool instructions
gettext_noop("Pick a shape. Click to pick the center, drag, then let go when it is the size you want. Move around to rotate it, and click to draw it."),
gettext_noop
("Pick a shape. Click to pick the center, drag, then let go when it is the size you want. Move around to rotate it, and click to draw it."),
// Text tool instructions
gettext_noop("Choose a style of text. Click on your drawing and you can start typing. Press [Enter] or [Tab] to complete the text."),
gettext_noop
("Choose a style of text. Click on your drawing and you can start typing. Press [Enter] or [Tab] to complete the text."),
// Label tool instructions
gettext_noop("Choose a style of text. Click on your drawing and you can start typing. Press [Enter] or [Tab] to complete the text. By using the selector button and clicking an existing label, you can move it, edit it and change its text style."),
gettext_noop
("Choose a style of text. Click on your drawing and you can start typing. Press [Enter] or [Tab] to complete the text. By using the selector button and clicking an existing label, you can move it, edit it and change its text style."),
// Reserved...
" ",

File diff suppressed because it is too large Load diff

View file

@ -38,6 +38,7 @@
DIR * opendir(const char *pSpec)
{
char pathname[MAX_PATH + 2];
DIR * pDir = calloc(1, sizeof(DIR));
if (!pDir)
return NULL;
@ -51,18 +52,19 @@
pDir = NULL;
}
return pDir;
}
void closedir(DIR * pDir)
}
void closedir(DIR * pDir)
{
assert(pDir != NULL);
free(pDir);
} struct dirent *readdir(struct DIR *pDir)
} struct dirent *readdir(struct DIR *pDir)
{
assert(pDir != NULL);
if (pDir->hFind)
{
strcpy(pDir->de.d_name, (const char *) pDir->wfd.cFileName);
strcpy(pDir->de.d_name, (const char *)pDir->wfd.cFileName);
if (!FindNextFile(pDir->hFind, &pDir->wfd))
{
@ -72,38 +74,34 @@
return &pDir->de;
}
return NULL;
}
int alphasort(const void *a, const void *b)
}
int alphasort(const void *a, const void *b)
{
return (strcmp
((*(const struct dirent **) a)->d_name,
(*(const struct dirent **) b)->d_name));
} static int addToList(int i, struct dirent ***namelist,
struct dirent *entry)
return (strcmp((*(const struct dirent **)a)->d_name, (*(const struct dirent **)b)->d_name));
} static int addToList(int i, struct dirent ***namelist, struct dirent *entry)
{
int size;
struct dirent *block;
*namelist =
(struct dirent **) realloc((void *) (*namelist),
(size_t) ((i + 1) * sizeof(struct dirent *)));
*namelist = (struct dirent **)realloc((void *)(*namelist), (size_t) ((i + 1) * sizeof(struct dirent *)));
if (*namelist == NULL)
return -1;
size =
(((char *) &entry->d_name) - ((char *) entry)) + strlen(entry->d_name) +
1;
block = (struct dirent *) malloc(size);
size = (((char *)&entry->d_name) - ((char *)entry)) + strlen(entry->d_name) + 1;
block = (struct dirent *)malloc(size);
if (block == NULL)
return -1;
(*namelist)[i] = block;
memcpy(block, entry, size);
return ++i;
}
int scandir(const char *dir, struct dirent ***namelist, selectCB select,
comparCB compar)
}
int scandir(const char *dir, struct dirent ***namelist, selectCB select, comparCB compar)
{
DIR * pDir;
int count;
struct dirent *entry;
assert((dir != NULL) && (namelist != NULL));
pDir = opendir(dir);
if (!pDir)
@ -120,9 +118,8 @@
if (count <= 0)
return -1;
if (compar != NULL)
qsort((void *) (*namelist), (size_t) count, sizeof(struct dirent *),
compar);
qsort((void *)(*namelist), (size_t) count, sizeof(struct dirent *), compar);
return count;
}
}

View file

@ -8,20 +8,21 @@
/* */
/****************************************************/
/* $Id$ */
typedef long BOOL;
typedef unsigned int DWORD;
typedef wchar_t TCHAR;
typedef void *HANDLE;
typedef long BOOL;
typedef unsigned int DWORD;
typedef wchar_t TCHAR;
typedef void *HANDLE;
#define MAX_PATH 256
#define INVALID_HANDLE_VALUE ((HANDLE)(-1))
#define WINAPI __stdcall
typedef struct
typedef struct
{
DWORD dwLowDateTime;
DWORD dwHighDateTime;
} FILETIME;
typedef struct
} FILETIME;
typedef struct
{
DWORD dwFileAttributes;
FILETIME ftCreationTime;
@ -33,7 +34,8 @@
DWORD dwReserved1;
TCHAR cFileName[MAX_PATH];
TCHAR cAlternateFileName[14];
} WIN32_FIND_DATA;
} WIN32_FIND_DATA;
#define FindFirstFile FindFirstFileA
#define FindNextFile FindNextFileA
@ -51,23 +53,24 @@ extern "C"
#ifdef __cplusplus
};
#endif /* */
struct dirent
struct dirent
{
char d_name[MAX_PATH];
};
typedef struct
};
typedef struct
{
WIN32_FIND_DATA wfd;
HANDLE hFind;
struct dirent de;
} DIR;
extern DIR *opendir(const char *pSpec);
extern void closedir(DIR * pDir);
extern struct dirent *readdir(struct DIR *pDir);
typedef int (*selectCB) (const struct dirent *);
typedef int (*comparCB) (const void *, const void *);
extern int alphasort(const void *a, const void *b);
extern int scandir(const char *dir, struct dirent ***namelist,
selectCB select, comparCB compar);
} DIR;
extern DIR *opendir(const char *pSpec);
extern void closedir(DIR * pDir);
extern struct dirent *readdir(struct DIR *pDir);
typedef int (*selectCB) (const struct dirent *);
typedef int (*comparCB) (const void *, const void *);
extern int alphasort(const void *a, const void *b);
extern int scandir(const char *dir, struct dirent ***namelist, selectCB select, comparCB compar);

View file

@ -67,8 +67,7 @@ static SDL_Surface *make24bitDIB(SDL_Surface * surf)
surf24 = SDL_ConvertSurface(surf, &pixfmt, SDL_SWSURFACE);
surfDIB = SDL_CreateRGBSurface(SDL_SWSURFACE, surf24->w, surf24->h, 24,
pixfmt.Rmask, pixfmt.Gmask, pixfmt.Bmask,
pixfmt.Amask);
pixfmt.Rmask, pixfmt.Gmask, pixfmt.Bmask, pixfmt.Amask);
linesize = surf24->w * 3; // Flip top2bottom
dst = surfDIB->pixels;
@ -101,8 +100,7 @@ static int GetDefaultPrinterStrings(char *device, char *driver, char *output)
return 0;
if (((dev = strtok(buff, ",")) != NULL) &&
((drv = strtok(NULL, ", ")) != NULL) &&
((out = strtok(NULL, ", ")) != NULL))
((drv = strtok(NULL, ", ")) != NULL) && ((out = strtok(NULL, ", ")) != NULL))
{
if (device)
strcpy(device, dev);
@ -138,8 +136,7 @@ static HANDLE LoadCustomPrinterHDEVMODE(HWND hWnd, const char *filepath)
if (!OpenPrinter(device, &hPrinter, NULL))
goto err_exit;
sizeof_devmode = (int) DocumentProperties(hWnd, hPrinter, device,
NULL, NULL, 0);
sizeof_devmode = (int)DocumentProperties(hWnd, hPrinter, device, NULL, NULL, 0);
if (!sizeof_devmode)
goto err_exit;
@ -152,8 +149,7 @@ static HANDLE LoadCustomPrinterHDEVMODE(HWND hWnd, const char *filepath)
if (!devmode)
goto err_exit;
res = DocumentProperties(hWnd, hPrinter, device, devmode, NULL,
DM_OUT_BUFFER);
res = DocumentProperties(hWnd, hPrinter, device, devmode, NULL, DM_OUT_BUFFER);
if (res != IDOK)
goto err_exit;
@ -163,8 +159,7 @@ static HANDLE LoadCustomPrinterHDEVMODE(HWND hWnd, const char *filepath)
goto err_exit;
fclose(fp);
res = DocumentProperties(hWnd, hPrinter, device, devmode, devmode,
DM_IN_BUFFER | DM_OUT_BUFFER);
res = DocumentProperties(hWnd, hPrinter, device, devmode, devmode, DM_IN_BUFFER | DM_OUT_BUFFER);
if (res != IDOK)
goto err_exit;
@ -185,8 +180,7 @@ err_exit:
}
static int SaveCustomPrinterHDEVMODE(HWND hWnd, const char *filepath,
HANDLE hDevMode)
static int SaveCustomPrinterHDEVMODE(HWND hWnd, const char *filepath, HANDLE hDevMode)
{
FILE *fp = NULL;
@ -198,7 +192,7 @@ static int SaveCustomPrinterHDEVMODE(HWND hWnd, const char *filepath,
int block_written;
char devname[dmDeviceNameSize];
strcpy(devname, (const char *) devmode->dmDeviceName);
strcpy(devname, (const char *)devmode->dmDeviceName);
fwrite(devname, 1, sizeof(devname), fp);
block_written = fwrite(devmode, 1, block_size, fp);
GlobalUnlock(hDevMode);
@ -252,8 +246,7 @@ static int GetCustomPrinterDC(HWND hWnd, const char *printcfg, int show)
{
DEVMODE *devmode = (DEVMODE *) GlobalLock(pd.hDevMode);
hDCprinter =
CreateDC(NULL, (const char *) devmode->dmDeviceName, NULL, devmode);
hDCprinter = CreateDC(NULL, (const char *)devmode->dmDeviceName, NULL, devmode);
GlobalUnlock(pd.hDevMode);
GlobalFree(pd.hDevMode);
}
@ -292,8 +285,7 @@ int IsPrinterAvailable(void)
#define STRETCH_TO_FIT 0
#define SCALE_TO_FIT 1
const char *SurfacePrint(SDL_Surface * surf, const char *printcfg,
int showdialog)
const char *SurfacePrint(SDL_Surface * surf, const char *printcfg, int showdialog)
{
const char *res = NULL;
HWND hWnd;
@ -374,8 +366,10 @@ const char *SurfacePrint(SDL_Surface * surf, const char *printcfg,
{
/* stretches x and y dimensions independently to fit the page */
/* doesn't preserve image aspect-ratio */
rcDst.top = 0; rcDst.left = 0;
rcDst.bottom = pageHeight; rcDst.right = pageWidth;
rcDst.top = 0;
rcDst.left = 0;
rcDst.bottom = pageHeight;
rcDst.right = pageWidth;
break;
}
case SCALE_TO_FIT:
@ -393,29 +387,29 @@ const char *SurfacePrint(SDL_Surface * surf, const char *printcfg,
if (dW < dH)
{
width = pageWidth;
height = (int)((height * dW * (sY/sX)) + 0.5f);
height = (int)((height * dW * (sY / sX)) + 0.5f);
}
else
{
width = (int)((width * dH * (sX/sY)) + 0.5f);
width = (int)((width * dH * (sX / sY)) + 0.5f);
height = pageHeight;
}
}
if (width > pageWidth)
{
height= height*width/pageWidth;
height = height * width / pageWidth;
width = pageWidth;
}
if (height > pageHeight)
{
width= width*height/pageHeight;
width = width * height / pageHeight;
height = pageHeight;
}
rcDst.top = 0;
rcDst.left = (pageWidth-width)/2;
rcDst.bottom = rcDst.top+height;
rcDst.right = rcDst.left+width;
rcDst.left = (pageWidth - width) / 2;
rcDst.bottom = rcDst.top + height;
rcDst.right = rcDst.left + width;
break;
}
default:
@ -439,8 +433,7 @@ const char *SurfacePrint(SDL_Surface * surf, const char *printcfg,
rcDst.right - rcDst.left,
rcDst.bottom - rcDst.top,
0, 0, bmih.biWidth, bmih.biHeight,
surf24->pixels, (BITMAPINFO *) & bmih,
DIB_RGB_COLORS, SRCCOPY);
surf24->pixels, (BITMAPINFO *) & bmih, DIB_RGB_COLORS, SRCCOPY);
if (nError == GDI_ERROR)
{
res = "win32_print: StretchDIBits() failed.";
@ -482,8 +475,7 @@ error:
/*
Read access to Windows Registry
*/
static HRESULT ReadRegistry(const char *key, const char *option, char *value,
int size)
static HRESULT ReadRegistry(const char *key, const char *option, char *value, int size)
{
LONG res;
HKEY hKey = NULL;
@ -491,9 +483,7 @@ static HRESULT ReadRegistry(const char *key, const char *option, char *value,
res = RegOpenKeyEx(HKEY_CURRENT_USER, key, 0, KEY_READ, &hKey);
if (res != ERROR_SUCCESS)
goto err_exit;
res =
RegQueryValueEx(hKey, option, NULL, NULL, (LPBYTE) value,
(LPDWORD) & size);
res = RegQueryValueEx(hKey, option, NULL, NULL, (LPBYTE) value, (LPDWORD) & size);
if (res != ERROR_SUCCESS)
goto err_exit;
res = ERROR_SUCCESS;
@ -529,8 +519,7 @@ char *GetDefaultSaveDir(const char *suffix)
{
char prefix[MAX_PATH];
char path[2 * MAX_PATH];
const char *key =
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
const char *key = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
const char *option = "AppData";
HRESULT hr = S_OK;
@ -551,8 +540,7 @@ char *GetDefaultSaveDir(const char *suffix)
char *GetSystemFontDir(void)
{
char path[MAX_PATH];
const char *key =
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
const char *key = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
const char *option = "Fonts";
HRESULT hr = S_OK;
@ -599,7 +587,7 @@ static int g_bWindowActive = 0;
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
int bEatKeystroke = 0;
KBDLLHOOKSTRUCT *p = (KBDLLHOOKSTRUCT*)lParam;
KBDLLHOOKSTRUCT *p = (KBDLLHOOKSTRUCT *) lParam;
if (nCode < 0 || nCode != HC_ACTION)
return CallNextHookEx(g_hKeyboardHook, nCode, wParam, lParam);
@ -614,7 +602,7 @@ LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
}
}
if(bEatKeystroke)
if (bEatKeystroke)
return 1;
return CallNextHookEx(g_hKeyboardHook, nCode, wParam, lParam);
}
@ -640,5 +628,3 @@ void SetActivationState(int state)
{
g_bWindowActive = state;
}

View file

@ -15,8 +15,7 @@
#endif
/* if printcfg is NULL, uses the default printer */
extern const char *SurfacePrint(SDL_Surface * surf,
const char *printcfg, int showdialog);
extern const char *SurfacePrint(SDL_Surface * surf, const char *printcfg, int showdialog);
extern int IsPrinterAvailable(void);
/* additional windows functions requiring <windows.h> */