Indentation.
This commit is contained in:
commit
1e0ea6d4b3
94 changed files with 26586 additions and 26244 deletions
9
.gitignore
vendored
Normal file
9
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
*.o
|
||||
*.so
|
||||
tuxpaint
|
||||
obj/parse.c
|
||||
obj/parse_step1.c
|
||||
src/tp_magic_api.h
|
||||
tp-magic-config
|
||||
trans/
|
||||
*~
|
||||
|
|
@ -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:
|
||||
|
|
|
|||
3
dummy.c
3
dummy.c
|
|
@ -14,6 +14,7 @@ static TYPE x UNUSED;
|
|||
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
1
macosx/.indent.pro
vendored
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../src/.indent.pro
|
||||
|
|
@ -39,7 +39,10 @@
|
|||
-(void)sendSDLControlShiftKeystroke:(int)key;
|
||||
-(void)setupBridge;
|
||||
|
||||
- (void) displayMessage:(NSString*)message andStatus:(NSString*)status withProgressIndicator:(BOOL)progress;
|
||||
-(void)displayMessage:(NSString *)
|
||||
message andStatus:(NSString *)
|
||||
status withProgressIndicator:(BOOL) progress;
|
||||
|
||||
-(void)hideMessage;
|
||||
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ 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)));
|
||||
|
|
@ -93,12 +94,15 @@ 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.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))) |
|
||||
(((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 */
|
||||
|
|
@ -309,6 +308,7 @@ tu_int __udivmodti4(tu_int a, tu_int b, tu_int* rem)
|
|||
* }
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
|
@ -362,4 +363,3 @@ int posix_memalign(void **ptr, size_t align, size_t size)
|
|||
typedef jmp_buf *(*png_set_longjmp_fnPtr) (png_structp, void *, size_t);
|
||||
png_set_longjmp_fnPtr png_set_longjmp_fn = 0;
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -22,4 +22,3 @@
|
|||
//
|
||||
|
||||
void speak_string(const wchar_t * str);
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,8 @@
|
|||
|
||||
/* What tools we contain: */
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
TOOL_ONE, // Becomes '0'
|
||||
TOOL_TWO, // Becomes '1'
|
||||
NUM_TOOLS // Becomes '2'
|
||||
|
|
@ -83,12 +84,9 @@ Uint8 example_r, example_g, example_b;
|
|||
// that are declared _before_ them.
|
||||
|
||||
void example_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
|
||||
void example_line_callback(void * ptr, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y);
|
||||
void example_line_callback(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
|
||||
|
||||
|
||||
/* Setup Functions: */
|
||||
|
|
@ -137,9 +135,7 @@ int example_init(magic_api * api)
|
|||
// (The "tp-magic-config --dataprefix" command would have told us when
|
||||
// we installed our plugin and its data.)
|
||||
|
||||
snprintf(fname, sizeof(fname),
|
||||
"%s/sounds/magic/%s",
|
||||
api->data_directory, snd_filenames[i]);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/%s", api->data_directory, snd_filenames[i]);
|
||||
|
||||
printf("Trying to load %s sound file\n", fname);
|
||||
|
||||
|
|
@ -186,8 +182,7 @@ SDL_Surface * example_get_icon(magic_api * api, int which)
|
|||
// We use 'which' (which of our tools Tux Paint is asking about)
|
||||
// as an index into the array.
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/%s.png",
|
||||
api->data_directory, icon_filenames[which]);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/%s.png", api->data_directory, icon_filenames[which]);
|
||||
|
||||
|
||||
// Try to load the image, and return the results to Tux Paint:
|
||||
|
|
@ -309,8 +304,7 @@ void example_shutdown(magic_api * api)
|
|||
// Affect the canvas on click:
|
||||
|
||||
void example_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect)
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
// In our case, a single click (which is also the start of a drag!)
|
||||
// is identical to what dragging does, but just at one point, rather
|
||||
|
|
@ -326,8 +320,7 @@ void example_click(magic_api * api, int which, int mode,
|
|||
// Affect the canvas on drag:
|
||||
|
||||
void example_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
// Call Tux Paint's "line()" function.
|
||||
//
|
||||
|
|
@ -338,16 +331,27 @@ void example_drag(magic_api * api, int which, SDL_Surface * canvas,
|
|||
// useful things (which of our "Magic" tools is being used and
|
||||
// the current and snapshot canvases).
|
||||
|
||||
api->line((void *) api, which, canvas, snapshot,
|
||||
ox, oy, x, y, 1, example_line_callback);
|
||||
api->line((void *)api, which, canvas, snapshot, ox, oy, x, y, 1, example_line_callback);
|
||||
|
||||
|
||||
// If we need to, swap the X and/or Y values, so that
|
||||
// (ox,oy) is always the top left, and (x,y) is always the bottom right,
|
||||
// so the values we put inside "update_rect" make sense:
|
||||
|
||||
if (ox > x) { int tmp = ox; ox = x; x = tmp; }
|
||||
if (oy > y) { int tmp = oy; oy = y; y = tmp; }
|
||||
if (ox > x)
|
||||
{
|
||||
int tmp = ox;
|
||||
|
||||
ox = x;
|
||||
x = tmp;
|
||||
}
|
||||
if (oy > y)
|
||||
{
|
||||
int tmp = oy;
|
||||
|
||||
oy = y;
|
||||
y = tmp;
|
||||
}
|
||||
|
||||
|
||||
// Fill in the elements of the "update_rect" SDL_Rect structure
|
||||
|
|
@ -369,8 +373,7 @@ void example_drag(magic_api * api, int which, SDL_Surface * canvas,
|
|||
// (So the sound will pan from speaker to speaker as you drag the
|
||||
// mouse around the canvas!)
|
||||
|
||||
api->playsound(snd_effect[which],
|
||||
(x * 255) / canvas->w, // pan
|
||||
api->playsound(snd_effect[which], (x * 255) / canvas->w, // pan
|
||||
255); // distance
|
||||
}
|
||||
|
||||
|
|
@ -378,8 +381,7 @@ void example_drag(magic_api * api, int which, SDL_Surface * canvas,
|
|||
// Affect the canvas on release:
|
||||
|
||||
void example_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect)
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
// Neither of our effects do anything special when the mouse is released
|
||||
// from a click or click-and-drag, so there's no code here...
|
||||
|
|
@ -423,9 +425,7 @@ void example_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b)
|
|||
// It pays attention to 'which' to determine which of our plugin's tools
|
||||
// is currently selected.
|
||||
|
||||
void example_line_callback(void * ptr, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y)
|
||||
void example_line_callback(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y)
|
||||
{
|
||||
// For technical reasons, we can't accept a pointer to the "magic_api"
|
||||
// struct, like the other functions do.
|
||||
|
|
@ -449,10 +449,7 @@ void example_line_callback(void * ptr, int which,
|
|||
// Tool number 1 simply draws a single pixel at the (x,y) location.
|
||||
// It's a 1x1 pixel brush
|
||||
|
||||
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format,
|
||||
example_r,
|
||||
example_g,
|
||||
example_b));
|
||||
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, example_r, example_g, example_b));
|
||||
|
||||
// We use "SDL_MapRGB()" to convert the RGB value we receive from Tux Paint
|
||||
// for the user's current color selection to a 'Uint32' pixel value
|
||||
|
|
@ -467,10 +464,7 @@ void example_line_callback(void * ptr, int which,
|
|||
{
|
||||
for (xx = -4; xx < 4; xx++)
|
||||
{
|
||||
api->putpixel(canvas, x + xx, y + yy,
|
||||
api->getpixel(snapshot,
|
||||
canvas->w - x - xx,
|
||||
canvas->h - y - yy));
|
||||
api->putpixel(canvas, x + xx, y + yy, api->getpixel(snapshot, canvas->w - x - xx, canvas->h - y - yy));
|
||||
|
||||
// We simply use Tux Paint's "getpixel()" routine to pull pixel
|
||||
// values from the 'snapshot', and then "putpixel()" to draw them
|
||||
|
|
|
|||
1
magic/src/.indent.pro
vendored
Symbolic link
1
magic/src/.indent.pro
vendored
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../../src/.indent.pro
|
||||
|
|
@ -45,9 +45,11 @@
|
|||
|
||||
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
|
||||
};
|
||||
|
|
@ -57,12 +59,15 @@ static Mix_Chunk * alien_snd_effect[alien_NUM_TOOLS];
|
|||
const char *alien_snd_filenames[alien_NUM_TOOLS] = {
|
||||
"alien.ogg",
|
||||
};
|
||||
|
||||
const char *alien_icon_filenames[alien_NUM_TOOLS] = {
|
||||
"alien.png",
|
||||
};
|
||||
|
||||
const char *alien_names[alien_NUM_TOOLS] = {
|
||||
gettext_noop("Color Shift"),
|
||||
};
|
||||
|
||||
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."),},
|
||||
|
|
@ -76,15 +81,12 @@ 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);
|
||||
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,47 +95,57 @@ 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);
|
||||
}
|
||||
|
||||
int alien_get_tool_count(magic_api * api ATTRIBUTE_UNUSED){
|
||||
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 our names, localized:
|
||||
char * alien_get_name(magic_api * api ATTRIBUTE_UNUSED, int 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){
|
||||
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){
|
||||
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
|
||||
{
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
|
||||
Uint8 temp[3];
|
||||
|
|
@ -141,12 +153,12 @@ static void do_alien_pixel(void * ptr, int which ATTRIBUTE_UNUSED,
|
|||
int k;
|
||||
|
||||
SDL_GetRGB(api->getpixel(canvas, x, y), canvas->format, &temp[0], &temp[1], &temp[2]);
|
||||
for (k =0;k<3;k++){
|
||||
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,21 +166,25 @@ 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;
|
||||
|
||||
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;
|
||||
|
||||
|
|
@ -176,8 +192,7 @@ static void do_alien_brush(void * ptr, int which, SDL_Surface * canvas, SDL_Surf
|
|||
{
|
||||
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->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,10 +232,12 @@ void alien_drag(magic_api * api, int which, SDL_Surface * canvas,
|
|||
|
||||
int use_sound = 1;
|
||||
|
||||
Mix_Chunk * magic_loadsound(char* file){
|
||||
Mix_Chunk *magic_loadsound(char *file)
|
||||
{
|
||||
Mix_Chunk *temp;
|
||||
|
||||
if (!use_sound){
|
||||
if (!use_sound)
|
||||
{
|
||||
return (Mix_Chunk *) - 1;
|
||||
}
|
||||
temp = Mix_LoadWAV(file);
|
||||
|
|
@ -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,11 +295,13 @@ 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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -273,4 +309,3 @@ int alien_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
|||
{
|
||||
return (MODE_FULLSCREEN | MODE_PAINT);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,15 +36,19 @@ 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;
|
||||
|
||||
|
|
@ -58,17 +62,13 @@ 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);
|
||||
|
|
@ -106,8 +106,7 @@ 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));
|
||||
}
|
||||
|
|
@ -119,7 +118,9 @@ char * blind_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUS
|
|||
|
||||
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)
|
||||
|
|
@ -145,7 +146,9 @@ void blind_paint_blind(void * ptr_to_api, int which_tool ATTRIBUTE_UNUSED,
|
|||
{
|
||||
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,6 +170,7 @@ 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)
|
||||
|
|
@ -266,32 +269,39 @@ 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)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,8 @@
|
|||
|
||||
/* What tools we contain: */
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
TOOL_BLOCKS,
|
||||
TOOL_CHALK,
|
||||
TOOL_DRIP,
|
||||
|
|
@ -56,18 +57,13 @@ 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);
|
||||
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,22 +77,22 @@ 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);
|
||||
}
|
||||
|
||||
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:
|
||||
|
|
@ -112,18 +108,15 @@ SDL_Surface * blocks_chalk_drip_get_icon(magic_api * api, int which)
|
|||
|
||||
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));
|
||||
|
|
@ -146,23 +139,18 @@ char * blocks_chalk_drip_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
|
|||
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);
|
||||
}
|
||||
|
||||
// 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;
|
||||
int xx, yy;
|
||||
|
|
@ -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);
|
||||
|
||||
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,11 +325,13 @@ 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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
121
magic/src/blur.c
121
magic/src/blur.c
|
|
@ -46,14 +46,11 @@ 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,7 +58,8 @@ 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
|
||||
};
|
||||
|
|
@ -73,103 +71,126 @@ 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] = {
|
||||
"blur.png",
|
||||
};
|
||||
|
||||
const char *blur_names[blur_NUM_TOOLS] = {
|
||||
gettext_noop("Blur"),
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
int blur_get_tool_count(magic_api * api ATTRIBUTE_UNUSED){
|
||||
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 our names, localized:
|
||||
char * blur_get_name(magic_api * api ATTRIBUTE_UNUSED, int 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){
|
||||
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){
|
||||
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}};
|
||||
{1, 4, 7, 4, 1}
|
||||
};
|
||||
|
||||
for (k =0;k<3;k++){
|
||||
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++){
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
|
|
@ -177,8 +198,7 @@ static void do_blur_brush(void * ptr, int which, SDL_Surface * canvas, SDL_Surfa
|
|||
{
|
||||
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->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,11 +287,13 @@ 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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,8 @@
|
|||
|
||||
/* What tools we contain: */
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
TOOL_LARGEBRICKS,
|
||||
TOOL_SMALLBRICKS,
|
||||
NUM_TOOLS
|
||||
|
|
@ -53,8 +54,7 @@ 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);
|
||||
|
|
@ -62,14 +62,10 @@ 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,14 +78,16 @@ 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);
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
@ -104,13 +102,11 @@ SDL_Surface * bricks_get_icon(magic_api * api, int which)
|
|||
|
||||
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));
|
||||
|
|
@ -137,8 +133,7 @@ char * bricks_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int m
|
|||
|
||||
// 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;
|
||||
|
||||
|
|
@ -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);
|
||||
|
||||
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 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);
|
||||
|
|
|
|||
|
|
@ -59,14 +59,11 @@ 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,13 +76,11 @@ 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;
|
||||
|
|
@ -103,7 +98,10 @@ int calligraphy_init(magic_api * api)
|
|||
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)
|
||||
|
|
@ -116,8 +114,7 @@ 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);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/calligraphy.png", api->data_directory);
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
|
|
@ -128,16 +125,15 @@ char * calligraphy_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUT
|
|||
}
|
||||
|
||||
// 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;
|
||||
int i, n_points, thick, new_thick;
|
||||
|
|
@ -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);
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -434,16 +427,19 @@ static void calligraphy_ComputeBezier(Point2D* cp, int numberOfPoints, Point2D*
|
|||
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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,17 +49,13 @@ 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);
|
||||
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,14 +70,16 @@ 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);
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
@ -94,8 +92,7 @@ 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));
|
||||
}
|
||||
|
|
@ -109,14 +106,12 @@ char * cartoon_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UN
|
|||
// Return our descriptions, localized:
|
||||
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;
|
||||
int xx, yy;
|
||||
|
|
@ -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);
|
||||
|
||||
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,11 +248,13 @@ 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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,15 +26,13 @@ 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);
|
||||
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,8 +40,7 @@ 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)
|
||||
{
|
||||
|
|
@ -76,17 +73,25 @@ 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));
|
||||
}
|
||||
|
||||
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,14 +101,28 @@ 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
|
||||
|
||||
|
|
@ -129,8 +148,7 @@ 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)
|
||||
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
|
||||
{
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
|
||||
|
|
@ -146,8 +164,7 @@ static void confetti_circle(void * ptr, int which ATTRIBUTE_UNUSED,
|
|||
}
|
||||
|
||||
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;
|
||||
|
|
@ -183,22 +200,33 @@ void confetti_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
|
|||
}
|
||||
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -64,11 +64,9 @@ 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: */
|
||||
|
|
@ -99,9 +94,7 @@ 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!
|
||||
|
||||
|
|
@ -125,8 +118,7 @@ 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:
|
||||
|
|
@ -145,7 +137,8 @@ char * distortion_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE
|
|||
|
||||
// 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.")));
|
||||
}
|
||||
|
|
@ -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,7 +215,8 @@ 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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -222,8 +224,7 @@ void distortion_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UN
|
|||
// Our "callback" function
|
||||
|
||||
static void distortion_line_callback(void *ptr, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y)
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y)
|
||||
{
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
int xx, yy;
|
||||
|
|
@ -239,19 +240,19 @@ 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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,16 +46,13 @@ 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,8 +73,7 @@ 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);
|
||||
|
|
@ -91,8 +90,7 @@ 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));
|
||||
}
|
||||
|
|
@ -111,13 +109,11 @@ char * emboss_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIB
|
|||
|
||||
// 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;
|
||||
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);
|
||||
|
||||
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,11 +214,13 @@ 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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,8 @@
|
|||
#include "SDL_image.h"
|
||||
#include "SDL_mixer.h"
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
TOOL_FADE,
|
||||
TOOL_DARKEN,
|
||||
NUM_TOOLS
|
||||
|
|
@ -50,21 +51,14 @@ 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);
|
||||
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,18 +70,19 @@ 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);
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
@ -102,13 +97,11 @@ SDL_Surface * fade_darken_get_icon(magic_api * api, int which)
|
|||
|
||||
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));
|
||||
|
|
@ -146,9 +139,7 @@ char * fade_darken_get_description(magic_api * api ATTRIBUTE_UNUSED, int which,
|
|||
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;
|
||||
|
|
@ -172,9 +163,7 @@ 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;
|
||||
|
|
@ -183,8 +172,7 @@ static void do_fade_darken_paint(void * ptr, int which,
|
|||
{
|
||||
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,8 +182,7 @@ 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);
|
||||
|
|
@ -207,8 +194,20 @@ void fade_darken_drag(magic_api * api, int which, SDL_Surface * canvas,
|
|||
|
||||
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,11 +268,13 @@ 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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,10 +44,8 @@ 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,14 +53,11 @@ 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);
|
||||
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);
|
||||
|
|
@ -76,14 +71,16 @@ 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);
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
@ -96,8 +93,7 @@ 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));
|
||||
}
|
||||
|
|
@ -111,15 +107,14 @@ char * fill_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSE
|
|||
// Return our descriptions, localized:
|
||||
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,21 +244,21 @@ 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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,17 +44,13 @@ 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);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -95,17 +91,25 @@ 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));
|
||||
}
|
||||
|
||||
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,7 +119,9 @@ 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
|
||||
|
||||
|
|
@ -129,16 +135,19 @@ void fisheye_draw(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
|
|||
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);
|
||||
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);
|
||||
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask,
|
||||
canvas->format->Amask);
|
||||
|
||||
rect.x = x - 40;
|
||||
rect.y = y - 40;
|
||||
|
|
@ -150,7 +159,8 @@ void fisheye_draw(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
|
|||
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);
|
||||
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
|
||||
|
|
@ -161,7 +171,8 @@ void fisheye_draw(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
|
|||
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);
|
||||
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
|
||||
|
||||
|
|
@ -187,10 +198,12 @@ void fisheye_draw(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
|
|||
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);
|
||||
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);
|
||||
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask,
|
||||
canvas->format->Amask);
|
||||
|
||||
//upper side first
|
||||
rect.x = 0;
|
||||
|
|
@ -240,8 +253,7 @@ void fisheye_draw(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
|
|||
}
|
||||
|
||||
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,20 +264,21 @@ 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)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 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: */
|
||||
|
||||
|
|
@ -68,22 +70,17 @@ 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);
|
||||
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);
|
||||
|
|
@ -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,24 +104,19 @@ 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);
|
||||
|
|
@ -138,8 +133,7 @@ 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));
|
||||
}
|
||||
|
|
@ -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,8 +285,7 @@ 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;
|
||||
|
|
@ -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: */
|
||||
|
||||
|
|
@ -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,11 +598,13 @@ 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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,14 +46,11 @@ Uint32 foam_api_version(void);
|
|||
int foam_init(magic_api * api);
|
||||
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 * 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);
|
||||
|
|
@ -67,7 +64,10 @@ 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:
|
||||
|
|
@ -76,22 +76,16 @@ int foam_init(magic_api * api)
|
|||
char fname[1024];
|
||||
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);
|
||||
|
||||
|
|
@ -109,8 +103,7 @@ 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));
|
||||
}
|
||||
|
|
@ -129,11 +122,12 @@ char * foam_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUT
|
|||
|
||||
// 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;
|
||||
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);
|
||||
|
||||
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;
|
||||
|
|
@ -434,11 +437,13 @@ 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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
143
magic/src/fold.c
143
magic/src/fold.c
|
|
@ -22,19 +22,14 @@ 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);
|
||||
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);
|
||||
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);
|
||||
|
|
@ -45,27 +40,23 @@ 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);
|
||||
}
|
||||
|
|
@ -96,41 +87,51 @@ SDL_Surface * fold_get_icon(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUT
|
|||
{
|
||||
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));
|
||||
}
|
||||
|
||||
char * fold_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) { return(gettext_noop("Fold")); }
|
||||
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.")); }
|
||||
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
|
||||
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)
|
||||
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);
|
||||
|
||||
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);
|
||||
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);
|
||||
|
|
@ -169,34 +170,41 @@ void fold_draw(magic_api * api, int which,
|
|||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -208,10 +216,12 @@ SDL_Surface * rotate(magic_api * api, SDL_Surface * canvas, int angle)
|
|||
|
||||
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);
|
||||
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);
|
||||
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask,
|
||||
canvas->format->Amask);
|
||||
|
||||
switch (angle)
|
||||
{
|
||||
|
|
@ -249,6 +259,7 @@ SDL_Surface * rotate(magic_api * api, SDL_Surface * canvas, int angle)
|
|||
void translate_coords(SDL_Surface * canvas, int angle)
|
||||
{
|
||||
int a, b;
|
||||
|
||||
switch (angle)
|
||||
{
|
||||
case 90:
|
||||
|
|
@ -297,8 +308,7 @@ void translate_xy(SDL_Surface * canvas, int x, int y, int * a, int * b, int rota
|
|||
}
|
||||
|
||||
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;
|
||||
|
|
@ -366,13 +376,17 @@ inline Uint8 fold_what_corner(int x, int y, SDL_Surface * canvas)
|
|||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -381,12 +395,15 @@ static void fold_print_line(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface
|
|||
int x, int y)
|
||||
{
|
||||
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;
|
||||
|
||||
api->putpixel(canvas, x, y, SDL_MapRGB(last->format, 90, 90, 90)); //It should not look too black nor too white with shadowed colors.
|
||||
}
|
||||
|
||||
|
|
@ -394,14 +411,15 @@ static void fold_erase(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * can
|
|||
int x, int y)
|
||||
{
|
||||
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);
|
||||
|
||||
switch (corner)
|
||||
|
|
@ -447,7 +465,9 @@ void fold_preview(magic_api * api, int which, SDL_Surface * canvas,
|
|||
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_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
|
||||
|
|
@ -463,14 +483,20 @@ void fold_preview(magic_api * api, int which, SDL_Surface * canvas,
|
|||
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_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_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_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;
|
||||
}
|
||||
|
|
@ -485,8 +511,7 @@ void fold_preview(magic_api * api, int which, SDL_Surface * canvas,
|
|||
}
|
||||
|
||||
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);
|
||||
|
|
@ -494,11 +519,13 @@ void fold_drag(magic_api * api, int which, SDL_Surface * canvas,
|
|||
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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -55,23 +55,19 @@ 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);
|
||||
|
||||
|
||||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -167,22 +160,28 @@ 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));
|
||||
}
|
||||
|
||||
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) {
|
||||
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,
|
||||
|
|
@ -213,12 +212,14 @@ 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->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);
|
||||
|
|
@ -228,7 +229,8 @@ void fretwork_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNU
|
|||
}
|
||||
|
||||
|
||||
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,16 +242,19 @@ 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;
|
||||
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);
|
||||
|
|
@ -278,6 +283,7 @@ static void fretwork_flip_flop(void * ptr, SDL_Surface * dest, SDL_Surface * src
|
|||
{
|
||||
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));
|
||||
|
|
@ -306,10 +312,10 @@ static void fretwork_rotate (void * ptr, SDL_Surface * dest, SDL_Surface * src,
|
|||
|
||||
|
||||
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)
|
||||
{
|
||||
|
|
@ -326,16 +332,20 @@ void fretwork_click(magic_api * api, int which, int mode,
|
|||
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;
|
||||
|
|
@ -391,22 +401,31 @@ static Uint8 fretwork_select_image(Uint16 segment)
|
|||
}
|
||||
|
||||
take_up = segment - fretwork_segments_x;
|
||||
if (take_up<=0) val_up = SEG_NONE;
|
||||
else val_up = fretwork_status_of_segments[take_up];
|
||||
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];
|
||||
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)
|
||||
{
|
||||
LEFT = 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)
|
||||
|
|
@ -444,8 +463,8 @@ static Uint8 fretwork_select_image(Uint16 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)
|
||||
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;
|
||||
|
|
@ -467,10 +486,12 @@ static void fretwork_draw(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface *
|
|||
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);
|
||||
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);
|
||||
fretwork_one->format->Rmask, fretwork_one->format->Gmask, fretwork_one->format->Bmask,
|
||||
fretwork_one->format->Amask);
|
||||
|
||||
SDL_BlitSurface(canvas_backup, &modification_rect, result, NULL);
|
||||
|
||||
|
|
@ -542,8 +563,7 @@ 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);
|
||||
|
||||
|
|
@ -553,24 +573,29 @@ static void fretwork_draw_wrapper(void * ptr, int which, SDL_Surface * canvas, S
|
|||
|
||||
{
|
||||
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);
|
||||
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){
|
||||
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_to_add = 0;
|
||||
}
|
||||
|
||||
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);
|
||||
// This should be improved, maybe passed to fretwork_draw()
|
||||
|
|
@ -589,6 +614,7 @@ void fretwork_drag(magic_api * api, int which,
|
|||
update_rect->x = x;
|
||||
update_rect->y = y;
|
||||
update_rect->w = w;
|
||||
update_rect->h=h;}
|
||||
update_rect->h = h;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,17 +45,13 @@ 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);
|
||||
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,7 +59,10 @@ 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_xsize;
|
||||
|
|
@ -74,8 +73,7 @@ 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;
|
||||
|
|
@ -95,8 +93,7 @@ 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));
|
||||
}
|
||||
|
|
@ -118,16 +115,11 @@ char * glasstile_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATT
|
|||
|
||||
// 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;
|
||||
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;
|
||||
|
|
@ -210,8 +198,7 @@ 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);
|
||||
|
||||
|
|
@ -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;
|
||||
|
||||
|
|
@ -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,11 +307,13 @@ 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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,20 +49,15 @@ 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,12 +69,10 @@ 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);
|
||||
|
|
@ -87,7 +80,10 @@ int grass_init(magic_api * api)
|
|||
|
||||
|
||||
|
||||
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)
|
||||
|
|
@ -100,8 +96,7 @@ 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));
|
||||
}
|
||||
|
|
@ -121,27 +116,36 @@ char * grass_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBU
|
|||
|
||||
// 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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
@ -174,11 +178,11 @@ int grass_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_
|
|||
}
|
||||
|
||||
static void do_grass(void *ptr, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x, int y)
|
||||
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
|
||||
{
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
int xx, yy;
|
||||
|
||||
// grass color: 82,180,17
|
||||
static int bucket;
|
||||
double tmp_red, tmp_green, tmp_blue;
|
||||
|
|
@ -190,10 +194,9 @@ static void do_grass(void * ptr, int which ATTRIBUTE_UNUSED,
|
|||
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;
|
||||
|
|
@ -203,15 +206,9 @@ static void do_grass(void * ptr, int which ATTRIBUTE_UNUSED,
|
|||
dest.x = x - 32;
|
||||
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,11 +253,13 @@ 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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,8 @@
|
|||
#include "SDL_image.h"
|
||||
#include "SDL_mixer.h"
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
TOOL_HALFTONE,
|
||||
NUM_TOOLS
|
||||
};
|
||||
|
|
@ -45,11 +46,8 @@ 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);
|
||||
|
|
@ -60,11 +58,9 @@ 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);
|
||||
|
|
@ -85,12 +81,11 @@ 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);
|
||||
|
|
@ -110,8 +105,7 @@ 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));
|
||||
}
|
||||
|
|
@ -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,
|
||||
|
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -222,8 +223,7 @@ 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)
|
||||
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;
|
||||
|
|
@ -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!? :( */
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,8 @@ static Uint8 kalidescope_r, kalidescope_g, kalidescope_b;
|
|||
static int square_size = 128;
|
||||
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
KAL_UD,
|
||||
KAL_LR,
|
||||
KAL_BOTH,
|
||||
|
|
@ -65,17 +66,13 @@ 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);
|
||||
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,15 +80,17 @@ 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);
|
||||
|
|
@ -107,8 +106,7 @@ 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));
|
||||
}
|
||||
|
|
@ -116,15 +114,24 @@ SDL_Surface * kalidescope_get_icon(magic_api * api, int which)
|
|||
// Return our names, localized:
|
||||
char *kalidescope_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
|
||||
{
|
||||
if (which == KAL_LR) {
|
||||
if (which == KAL_LR)
|
||||
{
|
||||
return (strdup(gettext_noop("Symmetric Left/Right")));
|
||||
} else if (which == KAL_UD) {
|
||||
}
|
||||
else if (which == KAL_UD)
|
||||
{
|
||||
return (strdup(gettext_noop("Symmetric Up/Down")));
|
||||
} else if (which == KAL_PATTERN) {
|
||||
}
|
||||
else if (which == KAL_PATTERN)
|
||||
{
|
||||
return (strdup(gettext_noop("Pattern")));
|
||||
} else if (which == KAL_TILES) {
|
||||
}
|
||||
else if (which == KAL_TILES)
|
||||
{
|
||||
return (strdup(gettext_noop("Tiles")));
|
||||
} else { /* KAL_BOTH */
|
||||
}
|
||||
else
|
||||
{ /* KAL_BOTH */
|
||||
return (strdup(gettext_noop("Kaleidoscope")));
|
||||
}
|
||||
}
|
||||
|
|
@ -132,15 +139,28 @@ char * kalidescope_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
|
|||
// Return our descriptions, localized:
|
||||
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) {
|
||||
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) {
|
||||
}
|
||||
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 */
|
||||
}
|
||||
else
|
||||
{ /* KAL_BOTH */
|
||||
return (strdup(gettext_noop("Click and drag the mouse to draw with symmetric brushes (a kaleidoscope).")));
|
||||
}
|
||||
}
|
||||
|
|
@ -155,10 +175,7 @@ static void do_kalidescope(void * ptr, int which, SDL_Surface * canvas,
|
|||
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,8 +215,7 @@ 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);
|
||||
|
||||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,17 +46,13 @@ 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);
|
||||
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,12 +72,10 @@ 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);
|
||||
|
|
@ -95,8 +92,7 @@ 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));
|
||||
}
|
||||
|
|
@ -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);
|
||||
|
||||
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,11 +235,13 @@ 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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,17 +44,13 @@ 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);
|
||||
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,8 +70,7 @@ 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);
|
||||
|
|
@ -89,8 +87,7 @@ 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));
|
||||
}
|
||||
|
|
@ -102,7 +99,8 @@ char * metalpaint_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE
|
|||
}
|
||||
|
||||
// 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.")));
|
||||
}
|
||||
|
|
@ -120,8 +118,8 @@ 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;
|
||||
int xx, yy;
|
||||
|
|
@ -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);
|
||||
|
||||
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,11 +205,13 @@ 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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,8 @@
|
|||
|
||||
/* What tools we contain: */
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
TOOL_MIRROR,
|
||||
TOOL_FLIP,
|
||||
NUM_TOOLS
|
||||
|
|
@ -50,16 +51,9 @@ 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 *);
|
||||
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,18 +66,19 @@ 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);
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
@ -98,13 +93,11 @@ SDL_Surface * mirror_flip_get_icon(magic_api * api, int which)
|
|||
|
||||
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));
|
||||
|
|
@ -122,15 +115,12 @@ char * mirror_flip_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
|
|||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,17 +57,10 @@ 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 *);
|
||||
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);
|
||||
|
|
@ -80,7 +73,8 @@ static const int mosaic_RADIUS = 16;
|
|||
static const double mosaic_SHARPEN = 1.0;
|
||||
static int randnoise ATTRIBUTE_UNUSED;
|
||||
Uint8 *mosaic_blured;
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
TOOL_MOSAIC,
|
||||
mosaic_NUM_TOOLS
|
||||
};
|
||||
|
|
@ -93,26 +87,34 @@ static SDL_Surface * canvas_sharp;
|
|||
const char *mosaic_snd_filenames[mosaic_NUM_TOOLS] = {
|
||||
"mosaic.ogg", /* FIXME */
|
||||
};
|
||||
|
||||
const char *mosaic_icon_filenames[mosaic_NUM_TOOLS] = {
|
||||
"mosaic.png",
|
||||
};
|
||||
|
||||
const char *mosaic_names[mosaic_NUM_TOOLS] = {
|
||||
gettext_noop("Mosaic"),
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
@ -120,46 +122,49 @@ int mosaic_init(magic_api * api){
|
|||
return (1);
|
||||
}
|
||||
|
||||
int mosaic_get_tool_count(magic_api * api ATTRIBUTE_UNUSED){
|
||||
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 our names, localized:
|
||||
char * mosaic_get_name(magic_api * api ATTRIBUTE_UNUSED, int 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){
|
||||
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){
|
||||
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){
|
||||
SDL_Surface * last ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -191,8 +200,7 @@ 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)
|
||||
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
|
||||
{
|
||||
int i, j, pix_row_pos;
|
||||
|
||||
|
|
@ -202,8 +210,7 @@ void mosaic_paint(void * ptr_to_api, int which ATTRIBUTE_UNUSED,
|
|||
{
|
||||
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 */
|
||||
|
|
@ -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,20 +288,19 @@ 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){
|
||||
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];
|
||||
|
|
@ -300,48 +308,56 @@ static void mosaic_noise_pixel(void * ptr, SDL_Surface * canvas, int noise_AMOUN
|
|||
int k;
|
||||
|
||||
SDL_GetRGB(api->getpixel(canvas, x, y), canvas->format, &temp[0], &temp[1], &temp[2]);
|
||||
for (k =0;k<3;k++){
|
||||
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){
|
||||
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}};
|
||||
{1, 4, 7, 4, 1}
|
||||
};
|
||||
|
||||
for (k =0;k<3;k++){
|
||||
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++){
|
||||
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;
|
||||
|
||||
|
|
@ -354,15 +370,19 @@ static void mosaic_sharpen_pixel(void * ptr,
|
|||
//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}};
|
||||
{-1, 0, 1}
|
||||
};
|
||||
|
||||
sobel_1 = 0;
|
||||
sobel_2 = 0;
|
||||
for (i=-1;i<2;i++){
|
||||
for(j=-1; j<2; j++){
|
||||
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);
|
||||
|
|
@ -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,23 +435,18 @@ 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);
|
||||
|
|
|
|||
|
|
@ -53,11 +53,10 @@ static void mosaic_shaped_sharpen_pixel(void * ptr, SDL_Surface * canvas, SDL_Su
|
|||
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);
|
||||
|
|
@ -68,16 +67,13 @@ char * mosaic_shaped_get_name(magic_api * api, int which);
|
|||
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,7 +87,8 @@ 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;
|
||||
|
|
@ -113,37 +110,32 @@ 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? */
|
||||
};
|
||||
|
||||
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++)
|
||||
|
|
@ -190,6 +183,7 @@ int mosaic_shaped_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
|||
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));
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -256,6 +255,7 @@ static void mosaic_shaped_fill(void * ptr_to_api, int which ATTRIBUTE_UNUSED, SD
|
|||
Uint32 mosaic_shaped_color;
|
||||
int size;
|
||||
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)
|
||||
{
|
||||
|
|
@ -351,8 +352,7 @@ 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)
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last, int x, int y)
|
||||
{
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
Uint8 r1, g1, b1;
|
||||
|
|
@ -360,6 +360,7 @@ static void mosaic_shaped_sharpen_pixel(void * ptr,
|
|||
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},
|
||||
|
|
@ -402,6 +403,7 @@ void mosaic_shaped_switchin(magic_api * api, int which, int mode ATTRIBUTE_UNUSE
|
|||
SDL_Rect rect;
|
||||
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++)
|
||||
{
|
||||
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);
|
||||
|
|
@ -521,9 +529,9 @@ void mosaic_shaped_switchin(magic_api * api, int which, int mode ATTRIBUTE_UNUSE
|
|||
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);
|
||||
|
|
@ -533,12 +541,18 @@ void mosaic_shaped_switchin(magic_api * api, int which, int mode ATTRIBUTE_UNUSE
|
|||
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));
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -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;
|
||||
|
|
@ -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);
|
||||
|
|
@ -768,11 +783,15 @@ 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);
|
||||
|
|
@ -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));
|
||||
|
||||
|
|
|
|||
|
|
@ -41,19 +41,14 @@ 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);
|
||||
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,15 +61,17 @@ 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);
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
@ -87,8 +84,7 @@ 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);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/negative.png", api->data_directory);
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
|
|
@ -102,19 +98,15 @@ char * negative_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_U
|
|||
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);
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
|
@ -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);
|
||||
|
||||
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,11 +224,13 @@ 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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,8 @@
|
|||
static const int noise_AMOUNT = 100.0;
|
||||
static const int noise_RADIUS = 16;
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
TOOL_NOISE,
|
||||
noise_NUM_TOOLS
|
||||
};
|
||||
|
|
@ -56,12 +57,15 @@ static Mix_Chunk * noise_snd_effect[noise_NUM_TOOLS];
|
|||
const char *noise_snd_filenames[noise_NUM_TOOLS] = {
|
||||
"noise.ogg",
|
||||
};
|
||||
|
||||
const char *noise_icon_filenames[noise_NUM_TOOLS] = {
|
||||
"noise.png",
|
||||
};
|
||||
|
||||
const char *noise_names[noise_NUM_TOOLS] = {
|
||||
gettext_noop("Noise"),
|
||||
};
|
||||
|
||||
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."),},
|
||||
|
|
@ -72,20 +76,15 @@ 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_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,47 +93,57 @@ 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);
|
||||
}
|
||||
|
||||
int noise_get_tool_count(magic_api * api ATTRIBUTE_UNUSED){
|
||||
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 our names, localized:
|
||||
char * noise_get_name(magic_api * api ATTRIBUTE_UNUSED, int 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){
|
||||
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){
|
||||
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
|
||||
{
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
|
||||
Uint8 temp[3];
|
||||
|
|
@ -142,7 +151,8 @@ static void do_noise_pixel(void * ptr, int which ATTRIBUTE_UNUSED,
|
|||
int k;
|
||||
|
||||
SDL_GetRGB(api->getpixel(canvas, x, y), canvas->format, &temp[0], &temp[1], &temp[2]);
|
||||
for (k =0;k<3;k++){
|
||||
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]));
|
||||
|
|
@ -150,18 +160,22 @@ static void do_noise_pixel(void * ptr, int which ATTRIBUTE_UNUSED,
|
|||
}
|
||||
|
||||
// Do the effect for the full image
|
||||
static void do_noise_full(void * ptr,SDL_Surface * canvas, SDL_Surface * last, int which){
|
||||
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;
|
||||
|
||||
|
|
@ -169,8 +183,7 @@ static void do_noise_brush(void * ptr, int which, SDL_Surface * canvas, SDL_Surf
|
|||
{
|
||||
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->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,11 +272,13 @@ 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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -254,4 +286,3 @@ int noise_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
|||
{
|
||||
return (MODE_FULLSCREEN | MODE_PAINT);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -58,16 +58,13 @@ char * perspective_get_name(magic_api * api, int which);
|
|||
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,7 +78,8 @@ 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);
|
||||
|
||||
|
|
@ -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,
|
||||
|
|
@ -156,37 +156,48 @@ 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);
|
||||
}
|
||||
|
||||
int perspective_get_tool_count(magic_api * api ATTRIBUTE_UNUSED){
|
||||
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 our names, localized:
|
||||
char * perspective_get_name(magic_api * api ATTRIBUTE_UNUSED, int 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){
|
||||
char *perspective_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return (strdup(gettext_noop(perspective_descs[which])));
|
||||
}
|
||||
|
||||
|
|
@ -194,7 +205,8 @@ char * perspective_get_description(magic_api * api ATTRIBUTE_UNUSED, int 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,9 +296,7 @@ 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->w = canvas->w;
|
||||
|
|
@ -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){
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
switch (which)
|
||||
{case TOOL_PERSPECTIVE:
|
||||
{
|
||||
case TOOL_PERSPECTIVE:
|
||||
{
|
||||
|
||||
if (x < canvas->w / 2)
|
||||
|
|
@ -349,15 +363,13 @@ 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;
|
||||
|
||||
|
|
@ -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);
|
||||
|
|
@ -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,22 +529,19 @@ 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);
|
||||
}
|
||||
|
|
@ -538,11 +551,14 @@ int perspective_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUS
|
|||
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;
|
||||
|
||||
dash += 1;
|
||||
if (dash > 8) dash = 0;
|
||||
if (dash > 8)
|
||||
dash = 0;
|
||||
if (dash > 3)
|
||||
api->putpixel(canvas, x, y, black);
|
||||
else
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@
|
|||
|
||||
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;
|
||||
|
|
@ -53,33 +54,31 @@ 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;
|
||||
|
|
@ -94,8 +93,7 @@ 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));
|
||||
}
|
||||
|
|
@ -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;
|
||||
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);
|
||||
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;
|
||||
|
|
@ -236,9 +240,7 @@ void puzzle_drag(magic_api * api, int which, SDL_Surface * canvas,
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ static unsigned int rails_segment_modified_last =0; //which segment was last
|
|||
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;
|
||||
|
||||
// Housekeeping functions
|
||||
|
||||
SDL_Surface *rails_one, *rails_three, *rails_four, *rails_corner;
|
||||
|
|
@ -46,8 +47,7 @@ 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);
|
||||
|
|
@ -58,17 +58,14 @@ 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,
|
||||
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)
|
||||
{
|
||||
|
|
@ -80,7 +77,8 @@ int rails_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
|||
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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -122,17 +120,25 @@ 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));
|
||||
}
|
||||
|
||||
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,
|
||||
|
|
@ -159,12 +165,14 @@ 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->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);
|
||||
|
|
@ -173,7 +181,8 @@ void rails_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED
|
|||
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,17 +196,20 @@ 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;
|
||||
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);
|
||||
|
|
@ -222,10 +234,12 @@ static void rails_flip(void * ptr, SDL_Surface * dest, SDL_Surface * src)
|
|||
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)
|
||||
{
|
||||
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, y, x));
|
||||
|
|
@ -253,8 +267,7 @@ static void rails_rotate (void * ptr, SDL_Surface * dest, SDL_Surface * src, uns
|
|||
}
|
||||
|
||||
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);
|
||||
|
|
@ -314,22 +327,31 @@ 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];
|
||||
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];
|
||||
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)
|
||||
{
|
||||
LEFT = 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)
|
||||
|
|
@ -368,8 +390,8 @@ 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;
|
||||
|
|
@ -393,10 +415,12 @@ static void rails_draw(void * ptr, int which ATTRIBUTE_UNUSED, ATTRIBUTE_UNUSED
|
|||
|
||||
|
||||
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);
|
||||
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);
|
||||
rails_one->format->Rmask, rails_one->format->Gmask, rails_one->format->Bmask,
|
||||
rails_one->format->Amask);
|
||||
|
||||
SDL_BlitSurface(canvas_backup, &modification_rect, result, NULL);
|
||||
|
||||
|
|
@ -468,8 +492,7 @@ 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);
|
||||
|
||||
|
|
@ -494,12 +517,13 @@ if (rails_segment_modified>0)
|
|||
}
|
||||
|
||||
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);
|
||||
|
||||
|
|
@ -519,6 +543,7 @@ void rails_drag(magic_api * api, int which, SDL_Surface * canvas,
|
|||
update_rect->x = x;
|
||||
update_rect->y = y;
|
||||
update_rect->w = w;
|
||||
update_rect->h=h;}
|
||||
update_rect->h = h;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
134
magic/src/rain.c
134
magic/src/rain.c
|
|
@ -48,7 +48,8 @@ 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
|
||||
};
|
||||
|
|
@ -58,12 +59,15 @@ static Mix_Chunk * rain_snd_effect[rain_NUM_TOOLS];
|
|||
const char *rain_snd_filenames[rain_NUM_TOOLS] = {
|
||||
"rain.ogg",
|
||||
};
|
||||
|
||||
const char *rain_icon_filenames[rain_NUM_TOOLS] = {
|
||||
"rain.png",
|
||||
};
|
||||
|
||||
const char *rain_names[rain_NUM_TOOLS] = {
|
||||
gettext_noop("Rain"),
|
||||
};
|
||||
|
||||
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."),},
|
||||
|
|
@ -75,20 +79,14 @@ 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);
|
||||
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,22 +94,30 @@ 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);
|
||||
}
|
||||
|
|
@ -119,73 +125,90 @@ int rain_init(magic_api * api){
|
|||
return (1);
|
||||
}
|
||||
|
||||
int rain_get_tool_count(magic_api * api ATTRIBUTE_UNUSED){
|
||||
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 our names, localized:
|
||||
char * rain_get_name(magic_api * api ATTRIBUTE_UNUSED, int 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){
|
||||
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){
|
||||
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;
|
||||
|
||||
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);
|
||||
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;
|
||||
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){
|
||||
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,11 +286,13 @@ 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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -266,5 +300,3 @@ int rain_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
|||
{
|
||||
return (MODE_FULLSCREEN | MODE_PAINT);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -73,23 +73,16 @@ 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);
|
||||
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,8 +105,7 @@ 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);
|
||||
|
|
@ -127,8 +122,7 @@ 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));
|
||||
}
|
||||
|
|
@ -142,15 +136,13 @@ char * rainbow_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UN
|
|||
// Return our descriptions, localized:
|
||||
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)
|
||||
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
|
||||
{
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
int xx, 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);
|
||||
|
||||
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,11 +225,13 @@ 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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,11 +28,8 @@ Uint8 realrainbow_blendr, realrainbow_blendg, realrainbow_blendb, realrainbow_bl
|
|||
|
||||
|
||||
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);
|
||||
|
|
@ -44,17 +41,11 @@ 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);
|
||||
|
||||
|
|
@ -78,8 +69,7 @@ int realrainbow_init(magic_api * api)
|
|||
if (realrainbow_colors[1] == NULL)
|
||||
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);
|
||||
|
|
@ -95,11 +85,9 @@ 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));
|
||||
}
|
||||
|
|
@ -112,9 +100,12 @@ char * realrainbow_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
|
|||
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)
|
||||
|
|
@ -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,10 +326,12 @@ 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;
|
||||
|
|
@ -346,8 +341,7 @@ void realrainbow_arc(magic_api * api, int which, SDL_Surface * canvas, SDL_Surfa
|
|||
|
||||
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;
|
||||
|
|
@ -361,15 +355,13 @@ void realrainbow_arc(magic_api * api, int which, SDL_Surface * canvas, SDL_Surfa
|
|||
}
|
||||
|
||||
static void realrainbow_linecb(void *ptr, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y)
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y)
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -48,17 +48,12 @@ 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,8 +74,7 @@ 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);
|
||||
|
|
@ -94,8 +91,7 @@ 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));
|
||||
}
|
||||
|
|
@ -114,14 +110,13 @@ char * ripples_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRI
|
|||
|
||||
// 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)
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y)
|
||||
{
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
Uint8 r, g, b;
|
||||
|
|
@ -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;
|
||||
|
|
@ -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,11 +197,13 @@ 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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -57,23 +57,18 @@ 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_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)
|
||||
{
|
||||
|
|
@ -108,12 +103,19 @@ SDL_Surface * rosette_get_icon(magic_api * api, int which)
|
|||
|
||||
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));
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
|
@ -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,13 +136,15 @@ 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)
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
|
||||
{
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
|
||||
|
|
@ -175,13 +182,17 @@ void rosette_draw(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * sna
|
|||
{
|
||||
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));
|
||||
|
|
@ -196,8 +207,7 @@ void rosette_draw(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * sna
|
|||
}
|
||||
|
||||
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->playsound(rosette_snd, (x * 255) / canvas->w, 255);
|
||||
|
|
@ -208,19 +218,20 @@ void rosette_drag(magic_api * api, int which, SDL_Surface * canvas,
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -229,4 +240,3 @@ int rosette_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
|||
{
|
||||
return (MODE_PAINT);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,8 @@
|
|||
|
||||
/* Our globals: */
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
TOOL_TRACE,
|
||||
TOOL_SHARPEN,
|
||||
TOOL_SILHOUETTE,
|
||||
|
|
@ -64,16 +65,19 @@ const char * sharpen_snd_filenames[sharpen_NUM_TOOLS] = {
|
|||
"sharpen.ogg",
|
||||
"silhouette.ogg"
|
||||
};
|
||||
|
||||
const char *sharpen_icon_filenames[sharpen_NUM_TOOLS] = {
|
||||
"edges.png",
|
||||
"sharpen.png",
|
||||
"silhouette.png"
|
||||
};
|
||||
|
||||
const char *sharpen_names[sharpen_NUM_TOOLS] = {
|
||||
gettext_noop("Edges"),
|
||||
gettext_noop("Sharpen"),
|
||||
gettext_noop("Silhouette")
|
||||
};
|
||||
|
||||
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."),},
|
||||
|
|
@ -90,21 +94,16 @@ 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_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,16 +112,21 @@ 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);
|
||||
}
|
||||
|
|
@ -137,31 +141,35 @@ int sharpen_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
|||
}
|
||||
|
||||
// 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 our names, localized:
|
||||
char * sharpen_get_name(magic_api * api ATTRIBUTE_UNUSED, int 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){
|
||||
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){
|
||||
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;
|
||||
|
||||
|
|
@ -174,15 +182,19 @@ static void do_sharpen_pixel(void * ptr, int which,
|
|||
//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}};
|
||||
{-1, 0, 1}
|
||||
};
|
||||
|
||||
sobel_1 = 0;
|
||||
sobel_2 = 0;
|
||||
for (i=-1;i<2;i++){
|
||||
for(j=-1; j<2; j++){
|
||||
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);
|
||||
|
|
@ -195,17 +207,21 @@ static void do_sharpen_pixel(void * ptr, int which,
|
|||
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,21 +230,25 @@ 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;
|
||||
|
||||
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;
|
||||
|
||||
|
|
@ -236,8 +256,7 @@ static void do_sharpen_brush(void * ptr, int which, SDL_Surface * canvas, SDL_Su
|
|||
{
|
||||
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->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,11 +345,13 @@ 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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,8 +44,7 @@ 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);
|
||||
|
|
@ -53,14 +52,11 @@ 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,8 +78,7 @@ 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);
|
||||
|
|
@ -97,8 +95,7 @@ SDL_Surface * shift_get_icon(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBU
|
|||
{
|
||||
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));
|
||||
}
|
||||
|
|
@ -118,8 +115,7 @@ char * shift_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBU
|
|||
|
||||
// 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,11 +322,13 @@ 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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,17 +45,13 @@ 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);
|
||||
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,14 +65,16 @@ 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);
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
@ -90,11 +88,9 @@ 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));
|
||||
}
|
||||
|
|
@ -119,8 +115,7 @@ char * smudge_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int m
|
|||
|
||||
// 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;
|
||||
static double state[32][32][3];
|
||||
|
|
@ -136,8 +131,7 @@ 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,
|
||||
|
|
@ -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->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,11 +230,13 @@ 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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
111
magic/src/snow.c
111
magic/src/snow.c
|
|
@ -48,7 +48,8 @@ static const int snow_RADIUS = 5;
|
|||
static SDL_Surface *snow_flake1;
|
||||
static SDL_Surface *snow_flake2;
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
TOOL_SNOWBALL,
|
||||
TOOL_SNOWFLAKE,
|
||||
snow_NUM_TOOLS
|
||||
|
|
@ -60,14 +61,17 @@ const char * snow_snd_filenames[snow_NUM_TOOLS] = {
|
|||
"snowball.ogg",
|
||||
"snowflake.ogg",
|
||||
};
|
||||
|
||||
const char *snow_icon_filenames[snow_NUM_TOOLS] = {
|
||||
"snowball.png",
|
||||
"snowflake.png",
|
||||
};
|
||||
|
||||
const char *snow_names[snow_NUM_TOOLS] = {
|
||||
gettext_noop("Snow Ball"),
|
||||
gettext_noop("Snow Flake"),
|
||||
};
|
||||
|
||||
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."),
|
||||
|
|
@ -81,98 +85,121 @@ 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){
|
||||
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){
|
||||
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);
|
||||
}
|
||||
|
||||
int snow_get_tool_count(magic_api * api ATTRIBUTE_UNUSED){
|
||||
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 our names, localized:
|
||||
char * snow_get_name(magic_api * api ATTRIBUTE_UNUSED, int 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){
|
||||
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){
|
||||
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;
|
||||
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,10 +270,13 @@ 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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -246,4 +284,3 @@ int snow_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
|||
{
|
||||
return (MODE_FULLSCREEN);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,17 +7,19 @@ 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{
|
||||
enum string_tools
|
||||
{
|
||||
STRING_TOOL_FULL_BY_OFFSET,
|
||||
STRING_TOOL_TRIANGLE,
|
||||
STRING_TOOL_ANGLE,
|
||||
STRING_NUMTOOLS};
|
||||
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);
|
||||
|
|
@ -43,8 +45,7 @@ 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);
|
||||
|
|
@ -56,15 +57,13 @@ 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
|
||||
|
||||
|
|
@ -98,6 +97,7 @@ int string_get_tool_count(__attribute__((unused)) magic_api * api)
|
|||
SDL_Surface *string_get_icon(magic_api * api, int which)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
switch (which)
|
||||
{
|
||||
case STRING_TOOL_FULL_BY_OFFSET:
|
||||
|
|
@ -115,7 +115,8 @@ SDL_Surface * string_get_icon(magic_api * api, int which)
|
|||
}
|
||||
|
||||
|
||||
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,13 +149,17 @@ 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)
|
||||
|
|
@ -170,16 +179,13 @@ 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);
|
||||
|
|
@ -200,13 +206,19 @@ void string_shutdown(__attribute__((unused)) magic_api * api)
|
|||
}
|
||||
}
|
||||
|
||||
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->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;
|
||||
|
|
@ -215,17 +227,17 @@ void string_switchout(__attribute__((unused)) magic_api * api, __attribute__((un
|
|||
// 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));
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
|
||||
|
|
@ -236,13 +248,15 @@ void string_click(magic_api * api, int which,__attribute__((unused)) int mode,
|
|||
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;
|
||||
int u;
|
||||
int i;
|
||||
int o; //offset
|
||||
|
||||
// int n=y/5;
|
||||
int **a;
|
||||
float step_w, step_h, aux;
|
||||
|
|
@ -250,7 +264,8 @@ static void string_draw_full_by_offset(void * ptr, __attribute__((unused)) int w
|
|||
|
||||
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;
|
||||
|
|
@ -267,20 +282,17 @@ static void string_draw_full_by_offset(void * ptr, __attribute__((unused)) int w
|
|||
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;
|
||||
}
|
||||
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));
|
||||
}
|
||||
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;
|
||||
|
|
@ -308,14 +320,18 @@ static void string_draw_full_by_offset(void * ptr, __attribute__((unused)) int w
|
|||
|
||||
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)
|
||||
{
|
||||
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)
|
||||
|
|
@ -338,6 +354,7 @@ 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);
|
||||
|
|
@ -366,12 +383,14 @@ 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, __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);
|
||||
|
||||
|
|
@ -381,7 +400,8 @@ void string_draw_angle_preview(magic_api * api, int which,
|
|||
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);
|
||||
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
|
||||
|
|
@ -401,9 +421,11 @@ void string_draw_angle_preview(magic_api * api, int which,
|
|||
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
@ -416,7 +438,9 @@ void string_draw_angle(magic_api * api, __attribute__((unused)) int which,
|
|||
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;
|
||||
|
|
@ -426,11 +450,13 @@ void string_draw_angle(magic_api * api, __attribute__((unused)) int which,
|
|||
|
||||
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)
|
||||
{
|
||||
|
|
@ -461,7 +487,9 @@ void string_draw_wrapper(magic_api * api, int which,
|
|||
void string_set_vertex(int x, int y)
|
||||
{
|
||||
int dx, dy;
|
||||
if (string_vertex_done) return;
|
||||
|
||||
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)
|
||||
|
|
@ -470,14 +498,15 @@ void string_set_vertex(int x, int y)
|
|||
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);
|
||||
|
|
|
|||
135
magic/src/tint.c
135
magic/src/tint.c
|
|
@ -46,7 +46,8 @@
|
|||
#define gettext_noop(String) String
|
||||
#endif
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
TOOL_TINT,
|
||||
TOOL_THRESHOLD,
|
||||
tint_NUM_TOOLS
|
||||
|
|
@ -63,14 +64,17 @@ const char * tint_snd_filenames[tint_NUM_TOOLS] = {
|
|||
"tint.wav",
|
||||
"fold.ogg" /* FIXME */
|
||||
};
|
||||
|
||||
const char *tint_icon_filenames[tint_NUM_TOOLS] = {
|
||||
"tint.png",
|
||||
"colornwhite.png"
|
||||
};
|
||||
|
||||
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] = {
|
||||
{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."),},
|
||||
|
|
@ -85,20 +89,15 @@ 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_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,49 +105,59 @@ 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);
|
||||
}
|
||||
|
||||
int tint_get_tool_count(magic_api * api ATTRIBUTE_UNUSED){
|
||||
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 our names, localized:
|
||||
char * tint_get_name(magic_api * api ATTRIBUTE_UNUSED, int 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){
|
||||
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){
|
||||
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;
|
||||
|
|
@ -159,15 +168,22 @@ int x, int y){
|
|||
|
||||
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->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, r, g, b));
|
||||
} else if (which == TOOL_THRESHOLD){
|
||||
}
|
||||
else if (which == TOOL_THRESHOLD)
|
||||
{
|
||||
int thresholdValue = (tint_max - tint_min) / 2;
|
||||
if (greyValue < thresholdValue){
|
||||
|
||||
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,16 +191,21 @@ int x, int y){
|
|||
}
|
||||
|
||||
// Do the effect:
|
||||
static void do_tint_full(void * ptr,SDL_Surface * canvas, SDL_Surface * last, int which){
|
||||
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++){
|
||||
|
||||
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;
|
||||
|
||||
|
|
@ -192,8 +213,7 @@ static void do_tint_brush(void * ptr, int which, SDL_Surface * canvas, SDL_Surfa
|
|||
{
|
||||
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->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,20 +304,26 @@ 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;
|
||||
|
||||
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){
|
||||
|
||||
if (greyValue < tint_min)
|
||||
{
|
||||
tint_min = greyValue;
|
||||
}
|
||||
if (greyValue>tint_max){
|
||||
if (greyValue > tint_max)
|
||||
{
|
||||
tint_max = greyValue;
|
||||
}
|
||||
}
|
||||
|
|
@ -289,7 +331,8 @@ void tint_switchin(magic_api * api, int which ATTRIBUTE_UNUSED, int mode ATTRIBU
|
|||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -48,7 +48,8 @@ static Uint8 toothpaste_r, toothpaste_g, toothpaste_b;
|
|||
static const int toothpaste_RADIUS = 10;
|
||||
double *toothpaste_weights = NULL;
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
TOOL_toothpaste,
|
||||
toothpaste_NUM_TOOLS
|
||||
};
|
||||
|
|
@ -58,12 +59,15 @@ static Mix_Chunk * toothpaste_snd_effect[toothpaste_NUM_TOOLS];
|
|||
const char *toothpaste_snd_filenames[toothpaste_NUM_TOOLS] = {
|
||||
"toothpaste.ogg",
|
||||
};
|
||||
|
||||
const char *toothpaste_icon_filenames[toothpaste_NUM_TOOLS] = {
|
||||
"toothpaste.png",
|
||||
};
|
||||
|
||||
const char *toothpaste_names[toothpaste_NUM_TOOLS] = {
|
||||
gettext_noop("Toothpaste"),
|
||||
};
|
||||
|
||||
const char *toothpaste_descs[toothpaste_NUM_TOOLS] = {
|
||||
gettext_noop("Click and drag to squirt toothpaste onto your picture."),
|
||||
};
|
||||
|
|
@ -75,17 +79,13 @@ 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);
|
||||
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,16 +93,22 @@ 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;
|
||||
|
||||
//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);
|
||||
}
|
||||
|
|
@ -110,14 +116,19 @@ int toothpaste_init(magic_api * api){
|
|||
//Set up weights
|
||||
pi = acos(0.0) * 2;
|
||||
toothpaste_weights = (double *)malloc(toothpaste_RADIUS * 2 * toothpaste_RADIUS * 2 * sizeof(double));
|
||||
if (toothpaste_weights == NULL){
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -125,43 +136,55 @@ int toothpaste_init(magic_api * api){
|
|||
return (1);
|
||||
}
|
||||
|
||||
int toothpaste_get_tool_count(magic_api * api ATTRIBUTE_UNUSED){
|
||||
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 our names, localized:
|
||||
char * toothpaste_get_name(magic_api * api ATTRIBUTE_UNUSED, int 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){
|
||||
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){
|
||||
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)){
|
||||
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,8 +195,8 @@ 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);
|
||||
|
||||
|
|
@ -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,11 +259,13 @@ 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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -244,5 +273,3 @@ int toothpaste_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSE
|
|||
{
|
||||
return (MODE_PAINT);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -40,19 +40,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 /* * 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 SDL_Surface *tornado_base, *tornado_cloud, *tornado_cloud_colorized;
|
||||
static int top_w;
|
||||
|
||||
/* Local function prototypes: */
|
||||
|
|
@ -62,12 +64,10 @@ 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);
|
||||
|
|
@ -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,16 +119,13 @@ 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);
|
||||
|
|
@ -145,8 +142,7 @@ 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));
|
||||
}
|
||||
|
|
@ -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,8 +220,7 @@ 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;
|
||||
|
|
@ -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);
|
||||
|
||||
|
|
@ -312,17 +302,15 @@ static Uint32 tornado_mess(Uint32 pixel, SDL_Surface * canvas)
|
|||
{
|
||||
Uint8 r, g, b, a;
|
||||
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_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;
|
||||
|
|
@ -410,7 +398,9 @@ static void tornado_drawstalk(magic_api * api, SDL_Surface * canvas, SDL_Surface
|
|||
}
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -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,11 +554,13 @@ 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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,19 +43,14 @@ 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);
|
||||
|
|
@ -91,13 +86,15 @@ 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));
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
|
@ -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,7 +118,9 @@ 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
|
||||
|
||||
|
|
@ -130,9 +132,7 @@ void tv_paint_tv(void * ptr_to_api, int which_tool ATTRIBUTE_UNUSED,
|
|||
|
||||
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));
|
||||
}
|
||||
|
||||
|
|
@ -146,8 +146,7 @@ void tv_do_tv(void * ptr_to_api, int which_tool ATTRIBUTE_UNUSED,
|
|||
}
|
||||
|
||||
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,8 +158,7 @@ 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)
|
||||
{
|
||||
|
|
@ -180,12 +178,14 @@ 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)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,14 +45,11 @@ 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,12 +68,10 @@ 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);
|
||||
|
||||
|
||||
|
|
@ -91,8 +89,10 @@ 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));
|
||||
}
|
||||
|
|
@ -100,16 +100,22 @@ SDL_Surface * waves_get_icon(magic_api * api, int which)
|
|||
// Return our names, localized:
|
||||
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)
|
||||
{
|
||||
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."));
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -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,11 +213,13 @@ 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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,16 +44,13 @@ 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,14 +59,16 @@ 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);
|
||||
|
|
@ -84,8 +83,7 @@ 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));
|
||||
}
|
||||
|
|
@ -113,12 +111,15 @@ static void do_xor(void * ptr, int which ATTRIBUTE_UNUSED,
|
|||
|
||||
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;
|
||||
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,
|
||||
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
|
||||
{
|
||||
|
|
@ -131,20 +132,32 @@ 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);
|
||||
|
||||
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;
|
||||
|
|
@ -155,8 +168,7 @@ void xor_drag(magic_api * api, int which, SDL_Surface * canvas,
|
|||
}
|
||||
|
||||
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);
|
||||
|
|
@ -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,11 +210,13 @@ 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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
13
src/.indent.pro
vendored
Normal file
13
src/.indent.pro
vendored
Normal 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
|
||||
|
|
@ -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.
|
||||
|
|
@ -168,16 +172,14 @@ void loadfont_callback(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer
|
|||
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);
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
34
src/fonts.c
34
src/fonts.c
|
|
@ -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");
|
||||
|
|
@ -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,7 +957,8 @@ 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;
|
||||
|
||||
|
|
@ -964,6 +980,7 @@ static void loadfonts(SDL_Surface * screen, SDL_Texture * texture, SDL_Renderer
|
|||
dev_t volume = dev_for_path("/boot");
|
||||
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);
|
||||
|
|
@ -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);
|
||||
|
|
@ -1455,6 +1475,7 @@ static int do_surfcmp(const SDL_Surface * const *const v1, const SDL_Surface * c
|
|||
{
|
||||
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];
|
||||
|
|
@ -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];
|
||||
|
|
|
|||
|
|
@ -91,14 +91,16 @@ 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;
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -28,7 +28,8 @@
|
|||
extern const char *savedir;
|
||||
extern const char *datadir;
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
DIR_SAVE,
|
||||
DIR_DATA
|
||||
};
|
||||
|
|
|
|||
39
src/i18n.c
39
src/i18n.c
|
|
@ -64,6 +64,7 @@ static char * android_locale ()
|
|||
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);
|
||||
|
||||
strcpy(android_locale_buf, locale);
|
||||
(*mEnv)->ReleaseStringUTFChars(mEnv, mLocaleString, locale);
|
||||
printf("android locale %s\n", android_locale_buf);
|
||||
|
|
@ -451,9 +452,8 @@ static void show_lang_usage(int exitcode)
|
|||
{
|
||||
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"
|
||||
/* af */ " afrikaans\n"
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -757,7 +754,9 @@ static void ctype_utf8(void)
|
|||
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(;;){
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (iswprint((wchar_t) 0xf7)) // division symbol -- which is in Latin-1 :-/
|
||||
return;
|
||||
if (--i < 0)
|
||||
|
|
@ -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)
|
||||
|
|
@ -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;
|
||||
|
|
@ -849,8 +849,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;
|
||||
|
|
@ -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;
|
||||
|
|
@ -932,6 +930,7 @@ static void mysetenv(const char *name, const char *value)
|
|||
#else
|
||||
int len = strlen(name) + 1 + strlen(value) + 1;
|
||||
char *str = malloc(len);
|
||||
|
||||
sprintf(str, "%s=%s", name, value);
|
||||
putenv(str);
|
||||
#endif
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -207,6 +207,7 @@ 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;
|
||||
#endif
|
||||
|
|
|
|||
3
src/im.h
3
src/im.h
|
|
@ -33,7 +33,8 @@
|
|||
* 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 */
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ int DisplayPageSetup(const SDL_Surface *surface);
|
|||
bool displayPrintSetupSheet;
|
||||
bool displayPrintSheet;
|
||||
}
|
||||
-
|
||||
@end
|
||||
|
||||
#endif OBJECTIVEC
|
||||
-@end
|
||||
#endif /* OBJECTIVEC */
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ 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); */
|
||||
|
||||
|
||||
|
|
@ -59,10 +60,15 @@ static void mtw(wchar_t * wtok, char * tok)
|
|||
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;
|
||||
|
|
@ -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);
|
||||
|
||||
|
|
@ -412,15 +418,10 @@ 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].plain_label = plain_label;
|
||||
layout->keys[line_number][key_number].top_label = top_label;
|
||||
layout->keys[line_number][key_number].altgr_label = altgr_label;
|
||||
|
|
@ -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)
|
||||
{
|
||||
|
|
@ -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++;
|
||||
}
|
||||
|
||||
|
|
@ -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 */
|
||||
|
|
@ -992,7 +989,8 @@ static void keybd_prepare(on_screen_keyboard *keyboard)
|
|||
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 */
|
||||
|
|
@ -1028,8 +1026,7 @@ static void keybd_prepare(on_screen_keyboard *keyboard)
|
|||
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);
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
@ -1139,6 +1134,7 @@ 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;
|
||||
|
|
@ -1324,8 +1321,7 @@ static osk_key * find_key(on_screen_keyboard * keyboard, int x, int y)
|
|||
key = NULL;
|
||||
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)
|
||||
|
|
@ -1493,8 +1489,7 @@ 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)
|
||||
strncmp("ISO_Next_Group", keysym, 14) == 0 || strncmp("ALT_R", keysym, 5) == 0)
|
||||
{
|
||||
if (mod & KMOD_RALT)
|
||||
{
|
||||
|
|
@ -1667,7 +1662,10 @@ 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);
|
||||
|
||||
|
|
@ -1702,9 +1700,7 @@ struct osk_keyboard * osk_clicked(on_screen_keyboard *keyboard, int x, int y)
|
|||
|
||||
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';
|
||||
|
|
@ -1789,6 +1784,7 @@ struct osk_keyboard * osk_clicked(on_screen_keyboard *keyboard, int x, int y)
|
|||
void osk_released(on_screen_keyboard * keyboard)
|
||||
{
|
||||
osk_key *key;
|
||||
|
||||
key = keyboard->last_key_pressed;
|
||||
if (key)
|
||||
{
|
||||
|
|
@ -1803,6 +1799,7 @@ void osk_released(on_screen_keyboard *keyboard)
|
|||
static void free_keymap(osk_keymap * keymap)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 256; i++)
|
||||
{
|
||||
if (keymap[i].plain)
|
||||
|
|
@ -1820,6 +1817,7 @@ static void free_keymap(osk_keymap *keymap)
|
|||
static void free_composemap(osk_composenode * composenode)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < composenode->size; i++)
|
||||
{
|
||||
free_composemap(composenode->childs[i]);
|
||||
|
|
@ -2065,4 +2063,3 @@ void osk_free(on_screen_keyboard *keyboard)
|
|||
/* } */
|
||||
/* } */
|
||||
/* } */
|
||||
|
||||
|
|
|
|||
|
|
@ -133,11 +133,16 @@ typedef struct osk_keyboard
|
|||
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_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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
16
src/pixels.c
16
src/pixels.c
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -78,10 +78,7 @@ 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;
|
||||
int img_w = surf->w;
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@
|
|||
unsigned char linear_to_sRGB(float linear)
|
||||
{
|
||||
unsigned slot;
|
||||
|
||||
slot = linear * 4096.0 + 0.5;
|
||||
if (slot > 4095)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
21
src/shapes.h
21
src/shapes.h
|
|
@ -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"
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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...
|
||||
" ",
|
||||
|
|
|
|||
2758
src/tuxpaint.c
2758
src/tuxpaint.c
File diff suppressed because it is too large
Load diff
|
|
@ -38,6 +38,7 @@
|
|||
DIR * opendir(const char *pSpec)
|
||||
{
|
||||
char pathname[MAX_PATH + 2];
|
||||
|
||||
DIR * pDir = calloc(1, sizeof(DIR));
|
||||
if (!pDir)
|
||||
return NULL;
|
||||
|
|
@ -52,6 +53,7 @@
|
|||
}
|
||||
return pDir;
|
||||
}
|
||||
|
||||
void closedir(DIR * pDir)
|
||||
{
|
||||
assert(pDir != NULL);
|
||||
|
|
@ -73,24 +75,19 @@
|
|||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
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;
|
||||
size = (((char *)&entry->d_name) - ((char *)entry)) + strlen(entry->d_name) + 1;
|
||||
block = (struct dirent *)malloc(size);
|
||||
if (block == NULL)
|
||||
return -1;
|
||||
|
|
@ -98,12 +95,13 @@
|
|||
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,8 +118,7 @@
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
typedef wchar_t TCHAR;
|
||||
typedef void *HANDLE;
|
||||
|
||||
|
||||
#define MAX_PATH 256
|
||||
#define INVALID_HANDLE_VALUE ((HANDLE)(-1))
|
||||
#define WINAPI __stdcall
|
||||
|
|
@ -35,6 +36,7 @@
|
|||
TCHAR cAlternateFileName[14];
|
||||
} WIN32_FIND_DATA;
|
||||
|
||||
|
||||
#define FindFirstFile FindFirstFileA
|
||||
#define FindNextFile FindNextFileA
|
||||
#define FindClose FindClose
|
||||
|
|
@ -51,6 +53,7 @@ extern "C"
|
|||
#ifdef __cplusplus
|
||||
};
|
||||
|
||||
|
||||
#endif /* */
|
||||
struct dirent
|
||||
{
|
||||
|
|
@ -68,6 +71,6 @@ extern "C"
|
|||
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);
|
||||
extern int scandir(const char *dir, struct dirent ***namelist, selectCB select, comparCB compar);
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
@ -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:
|
||||
|
|
@ -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;
|
||||
|
||||
|
|
@ -640,5 +628,3 @@ void SetActivationState(int state)
|
|||
{
|
||||
g_bWindowActive = state;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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> */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue