Indentation.
This commit is contained in:
commit
1e0ea6d4b3
94 changed files with 26586 additions and 26244 deletions
|
|
@ -9,12 +9,12 @@
|
|||
/* -------------------------- */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h> // For "strdup()"
|
||||
#include <libintl.h> // For "gettext()"
|
||||
#include <string.h> // For "strdup()"
|
||||
#include <libintl.h> // For "gettext()"
|
||||
|
||||
#include "tp_magic_api.h" // Tux Paint "Magic" tool API header
|
||||
#include "SDL_image.h" // For IMG_Load(), to load our PNG icon
|
||||
#include "SDL_mixer.h" // For Mix_LoadWAV(), to load our sound effects
|
||||
#include "tp_magic_api.h" // Tux Paint "Magic" tool API header
|
||||
#include "SDL_image.h" // For IMG_Load(), to load our PNG icon
|
||||
#include "SDL_mixer.h" // For Mix_LoadWAV(), to load our sound effects
|
||||
|
||||
|
||||
/* Tool Enumerations: */
|
||||
|
|
@ -22,21 +22,22 @@
|
|||
|
||||
/* What tools we contain: */
|
||||
|
||||
enum {
|
||||
TOOL_ONE, // Becomes '0'
|
||||
TOOL_TWO, // Becomes '1'
|
||||
NUM_TOOLS // Becomes '2'
|
||||
enum
|
||||
{
|
||||
TOOL_ONE, // Becomes '0'
|
||||
TOOL_TWO, // Becomes '1'
|
||||
NUM_TOOLS // Becomes '2'
|
||||
};
|
||||
|
||||
|
||||
/* A list of filenames for sounds and icons to load at startup: */
|
||||
|
||||
const char * snd_filenames[NUM_TOOLS] = {
|
||||
const char *snd_filenames[NUM_TOOLS] = {
|
||||
"one.wav",
|
||||
"two.wav"
|
||||
};
|
||||
|
||||
const char * icon_filenames[NUM_TOOLS] = {
|
||||
const char *icon_filenames[NUM_TOOLS] = {
|
||||
"one.png",
|
||||
"two.png"
|
||||
};
|
||||
|
|
@ -49,7 +50,7 @@ const char * icon_filenames[NUM_TOOLS] = {
|
|||
|
||||
/* A list of names for the tools */
|
||||
|
||||
const char * names[NUM_TOOLS] = {
|
||||
const char *names[NUM_TOOLS] = {
|
||||
gettext_noop("A tool"),
|
||||
gettext_noop("Another tool")
|
||||
};
|
||||
|
|
@ -57,7 +58,7 @@ const char * names[NUM_TOOLS] = {
|
|||
|
||||
/* A list of descriptions of the tools */
|
||||
|
||||
const char * descs[NUM_TOOLS] = {
|
||||
const char *descs[NUM_TOOLS] = {
|
||||
gettext_noop("This is example tool number 1."),
|
||||
gettext_noop("This is example tool number 2.")
|
||||
};
|
||||
|
|
@ -68,7 +69,7 @@ const char * descs[NUM_TOOLS] = {
|
|||
/* --------------------- */
|
||||
|
||||
/* Sound effects: */
|
||||
Mix_Chunk * snd_effect[NUM_TOOLS];
|
||||
Mix_Chunk *snd_effect[NUM_TOOLS];
|
||||
|
||||
/* The current color (an "RGB" value) the user has selected in Tux Paint: */
|
||||
Uint8 example_r, example_g, example_b;
|
||||
|
|
@ -83,12 +84,9 @@ Uint8 example_r, example_g, example_b;
|
|||
// that are declared _before_ them.
|
||||
|
||||
void example_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
|
||||
void example_line_callback(void * ptr, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y);
|
||||
void example_line_callback(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
|
||||
|
||||
|
||||
/* Setup Functions: */
|
||||
|
|
@ -105,7 +103,7 @@ void example_line_callback(void * ptr, int which,
|
|||
|
||||
Uint32 example_api_version(void)
|
||||
{
|
||||
return(TP_MAGIC_API_VERSION);
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -129,26 +127,24 @@ int example_init(magic_api * api)
|
|||
char fname[1024];
|
||||
|
||||
for (i = 0; i < NUM_TOOLS; i++)
|
||||
{
|
||||
// Assemble the filename from the "snd_filenames[]" array into
|
||||
// a full path to a real file.
|
||||
//
|
||||
// Use "api->data_directory" to figure out where our sounds should be.
|
||||
// (The "tp-magic-config --dataprefix" command would have told us when
|
||||
// we installed our plugin and its data.)
|
||||
{
|
||||
// Assemble the filename from the "snd_filenames[]" array into
|
||||
// a full path to a real file.
|
||||
//
|
||||
// Use "api->data_directory" to figure out where our sounds should be.
|
||||
// (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);
|
||||
printf("Trying to load %s sound file\n", fname);
|
||||
|
||||
// Try to load the file!
|
||||
// Try to load the file!
|
||||
|
||||
snd_effect[i] = Mix_LoadWAV(fname);
|
||||
}
|
||||
snd_effect[i] = Mix_LoadWAV(fname);
|
||||
}
|
||||
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -163,7 +159,7 @@ int example_init(magic_api * api)
|
|||
|
||||
int example_get_tool_count(magic_api * api)
|
||||
{
|
||||
return(NUM_TOOLS);
|
||||
return (NUM_TOOLS);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -172,7 +168,7 @@ int example_get_tool_count(magic_api * api)
|
|||
// When Tux Paint is starting up and loading plugins, it asks us to
|
||||
// provide icons for the "Magic" tool buttons.
|
||||
|
||||
SDL_Surface * example_get_icon(magic_api * api, int which)
|
||||
SDL_Surface *example_get_icon(magic_api * api, int which)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
|
|
@ -186,13 +182,12 @@ SDL_Surface * example_get_icon(magic_api * api, int which)
|
|||
// We use 'which' (which of our tools Tux Paint is asking about)
|
||||
// as an index into the array.
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/%s.png",
|
||||
api->data_directory, icon_filenames[which]);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/%s.png", api->data_directory, icon_filenames[which]);
|
||||
|
||||
|
||||
// Try to load the image, and return the results to Tux Paint:
|
||||
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -201,10 +196,10 @@ SDL_Surface * example_get_icon(magic_api * api, int which)
|
|||
// When Tux Paint is starting up and loading plugins, it asks us to
|
||||
// provide names (labels) for the "Magic" tool buttons.
|
||||
|
||||
char * example_get_name(magic_api * api, int which)
|
||||
char *example_get_name(magic_api * api, int which)
|
||||
{
|
||||
const char * our_name_english;
|
||||
const char * our_name_localized;
|
||||
const char *our_name_english;
|
||||
const char *our_name_localized;
|
||||
|
||||
// Get our name from the "names[]" array.
|
||||
//
|
||||
|
|
@ -226,7 +221,7 @@ char * example_get_name(magic_api * api, int which)
|
|||
// send it to Tux Paint. (Tux Paint keeps track of the string and
|
||||
// will free it for us, so we have one less thing to keep track of.)
|
||||
|
||||
return(strdup(our_name_localized));
|
||||
return (strdup(our_name_localized));
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -235,10 +230,10 @@ char * example_get_name(magic_api * api, int which)
|
|||
// When Tux Paint is starting up and loading plugins, it asks us to
|
||||
// provide names (labels) for the "Magic" tool buttons.
|
||||
|
||||
char * example_get_description(magic_api * api, int which, int mode)
|
||||
char *example_get_description(magic_api * api, int which, int mode)
|
||||
{
|
||||
const char * our_desc_english;
|
||||
const char * our_desc_localized;
|
||||
const char *our_desc_english;
|
||||
const char *our_desc_localized;
|
||||
|
||||
// Get our desc from the "descs[]" array.
|
||||
//
|
||||
|
|
@ -260,7 +255,7 @@ char * example_get_description(magic_api * api, int which, int mode)
|
|||
// send it to Tux Paint. (Tux Paint keeps track of the string and
|
||||
// will free it for us, so we have one less thing to keep track of.)
|
||||
|
||||
return(strdup(our_desc_localized));
|
||||
return (strdup(our_desc_localized));
|
||||
}
|
||||
|
||||
// Report whether we accept colors
|
||||
|
|
@ -309,8 +304,7 @@ void example_shutdown(magic_api * api)
|
|||
// Affect the canvas on click:
|
||||
|
||||
void example_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect)
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
// In our case, a single click (which is also the start of a drag!)
|
||||
// is identical to what dragging does, but just at one point, rather
|
||||
|
|
@ -326,8 +320,7 @@ void example_click(magic_api * api, int which, int mode,
|
|||
// Affect the canvas on drag:
|
||||
|
||||
void example_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
// Call Tux Paint's "line()" function.
|
||||
//
|
||||
|
|
@ -338,16 +331,27 @@ void example_drag(magic_api * api, int which, SDL_Surface * canvas,
|
|||
// useful things (which of our "Magic" tools is being used and
|
||||
// the current and snapshot canvases).
|
||||
|
||||
api->line((void *) api, which, canvas, snapshot,
|
||||
ox, oy, x, y, 1, example_line_callback);
|
||||
api->line((void *)api, which, canvas, snapshot, ox, oy, x, y, 1, example_line_callback);
|
||||
|
||||
|
||||
// If we need to, swap the X and/or Y values, so that
|
||||
// (ox,oy) is always the top left, and (x,y) is always the bottom right,
|
||||
// so the values we put inside "update_rect" make sense:
|
||||
|
||||
if (ox > x) { int tmp = ox; ox = x; x = tmp; }
|
||||
if (oy > y) { int tmp = oy; oy = y; y = tmp; }
|
||||
if (ox > x)
|
||||
{
|
||||
int tmp = ox;
|
||||
|
||||
ox = x;
|
||||
x = tmp;
|
||||
}
|
||||
if (oy > y)
|
||||
{
|
||||
int tmp = oy;
|
||||
|
||||
oy = y;
|
||||
y = tmp;
|
||||
}
|
||||
|
||||
|
||||
// Fill in the elements of the "update_rect" SDL_Rect structure
|
||||
|
|
@ -369,17 +373,15 @@ 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
|
||||
255); // distance
|
||||
api->playsound(snd_effect[which], (x * 255) / canvas->w, // pan
|
||||
255); // distance
|
||||
}
|
||||
|
||||
|
||||
// Affect the canvas on release:
|
||||
|
||||
void example_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect)
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
// Neither of our effects do anything special when the mouse is released
|
||||
// from a click or click-and-drag, so there's no code here...
|
||||
|
|
@ -423,9 +425,7 @@ void example_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b)
|
|||
// It pays attention to 'which' to determine which of our plugin's tools
|
||||
// is currently selected.
|
||||
|
||||
void example_line_callback(void * ptr, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y)
|
||||
void example_line_callback(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y)
|
||||
{
|
||||
// For technical reasons, we can't accept a pointer to the "magic_api"
|
||||
// struct, like the other functions do.
|
||||
|
|
@ -436,7 +436,7 @@ void example_line_callback(void * ptr, int which,
|
|||
//
|
||||
// (The "(magic_api *)" casts the generic pointer into the 'type' of
|
||||
// pointer we want, a pointer to a "magic_api".)
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
int xx, yy;
|
||||
|
||||
|
||||
|
|
@ -445,43 +445,37 @@ void example_line_callback(void * ptr, int which,
|
|||
// Tux Paint sends to us with the values we enumerated above.
|
||||
|
||||
if (which == TOOL_ONE)
|
||||
{
|
||||
// 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));
|
||||
|
||||
// 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
|
||||
// we can send to Tux Paint's "putpixel()" function.
|
||||
}
|
||||
else if (which == TOOL_TWO)
|
||||
{
|
||||
// Tool number 2 copies an 8x8 square of pixels from the opposite side
|
||||
// of the canvas and puts it under the cursor
|
||||
|
||||
for (yy = -4; yy < 4; yy++)
|
||||
{
|
||||
for (xx = -4; xx < 4; xx++)
|
||||
{
|
||||
api->putpixel(canvas, x + xx, y + yy,
|
||||
api->getpixel(snapshot,
|
||||
canvas->w - x - xx,
|
||||
canvas->h - y - yy));
|
||||
// Tool number 1 simply draws a single pixel at the (x,y) location.
|
||||
// It's a 1x1 pixel brush
|
||||
|
||||
// We simply use Tux Paint's "getpixel()" routine to pull pixel
|
||||
// values from the 'snapshot', and then "putpixel()" to draw them
|
||||
// right into the 'canvas'.
|
||||
|
||||
// Note: putpixel() and getpixel() are safe to use, even if your
|
||||
// X,Y values are outside of the SDL surface (e.g., negative, or
|
||||
// greater than the surface's width or height).
|
||||
}
|
||||
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
|
||||
// we can send to Tux Paint's "putpixel()" function.
|
||||
}
|
||||
else if (which == TOOL_TWO)
|
||||
{
|
||||
// Tool number 2 copies an 8x8 square of pixels from the opposite side
|
||||
// of the canvas and puts it under the cursor
|
||||
|
||||
for (yy = -4; yy < 4; yy++)
|
||||
{
|
||||
for (xx = -4; xx < 4; xx++)
|
||||
{
|
||||
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
|
||||
// right into the 'canvas'.
|
||||
|
||||
// Note: putpixel() and getpixel() are safe to use, even if your
|
||||
// X,Y values are outside of the SDL surface (e.g., negative, or
|
||||
// greater than the surface's width or height).
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Switch-In event
|
||||
|
|
|
|||
1
magic/src/.indent.pro
vendored
Symbolic link
1
magic/src/.indent.pro
vendored
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../../src/.indent.pro
|
||||
|
|
@ -43,48 +43,50 @@
|
|||
#define gettext_noop(String) String
|
||||
#endif
|
||||
|
||||
static const double alien_ANGLE[] = {0,0,0};
|
||||
static const double alien_FREQUENCY[] = {1,1,1};
|
||||
static const double alien_ANGLE[] = { 0, 0, 0 };
|
||||
static const double alien_FREQUENCY[] = { 1, 1, 1 };
|
||||
|
||||
static const int alien_RADIUS = 16;
|
||||
|
||||
enum {
|
||||
TOOL_alien,
|
||||
alien_NUM_TOOLS
|
||||
enum
|
||||
{
|
||||
TOOL_alien,
|
||||
alien_NUM_TOOLS
|
||||
};
|
||||
|
||||
static Mix_Chunk * alien_snd_effect[alien_NUM_TOOLS];
|
||||
static Mix_Chunk *alien_snd_effect[alien_NUM_TOOLS];
|
||||
|
||||
const char * alien_snd_filenames[alien_NUM_TOOLS] = {
|
||||
const char *alien_snd_filenames[alien_NUM_TOOLS] = {
|
||||
"alien.ogg",
|
||||
};
|
||||
const char * alien_icon_filenames[alien_NUM_TOOLS] = {
|
||||
|
||||
const char *alien_icon_filenames[alien_NUM_TOOLS] = {
|
||||
"alien.png",
|
||||
};
|
||||
const char * alien_names[alien_NUM_TOOLS] = {
|
||||
|
||||
const char *alien_names[alien_NUM_TOOLS] = {
|
||||
gettext_noop("Color Shift"),
|
||||
};
|
||||
const char * alien_descs[alien_NUM_TOOLS][2] = {
|
||||
|
||||
const char *alien_descs[alien_NUM_TOOLS][2] = {
|
||||
{gettext_noop("Click and drag the mouse to change the colors in parts of your picture."),
|
||||
gettext_noop("Click to change the colors in your entire picture."),},
|
||||
gettext_noop("Click to change the colors in your entire picture."),},
|
||||
};
|
||||
|
||||
// Prototypes
|
||||
Uint32 alien_api_version(void);
|
||||
int alien_init(magic_api * api);
|
||||
int alien_get_tool_count(magic_api * api);
|
||||
SDL_Surface * alien_get_icon(magic_api * api, int which);
|
||||
char * alien_get_name(magic_api * api, int which);
|
||||
char * alien_get_description(magic_api * api, int which, int mode);
|
||||
SDL_Surface *alien_get_icon(magic_api * api, int which);
|
||||
char *alien_get_name(magic_api * api, int which);
|
||||
char *alien_get_description(magic_api * api, int which, int mode);
|
||||
void alien_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
Mix_Chunk * magic_loadsound(char* file);
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
Mix_Chunk *magic_loadsound(char *file);
|
||||
void alien_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void alien_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void alien_shutdown(magic_api * api);
|
||||
void alien_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
int alien_requires_colors(magic_api * api, int which);
|
||||
|
|
@ -93,109 +95,134 @@ 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++){
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/%s", api->data_directory, alien_snd_filenames[i]);
|
||||
alien_snd_effect[i] = Mix_LoadWAV(fname);
|
||||
}
|
||||
return(1);
|
||||
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){
|
||||
return(alien_NUM_TOOLS);
|
||||
int alien_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return (alien_NUM_TOOLS);
|
||||
}
|
||||
|
||||
// Load our icons:
|
||||
SDL_Surface * alien_get_icon(magic_api * api, int which){
|
||||
SDL_Surface *alien_get_icon(magic_api * api, int which)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, alien_icon_filenames[which]);
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our names, localized:
|
||||
char * alien_get_name(magic_api * api ATTRIBUTE_UNUSED, int which){
|
||||
return(strdup(gettext_noop(alien_names[which])));
|
||||
char *alien_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
|
||||
{
|
||||
return (strdup(gettext_noop(alien_names[which])));
|
||||
}
|
||||
|
||||
// Return our descriptions, localized:
|
||||
char * alien_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode){
|
||||
return(strdup(gettext_noop(alien_descs[which][mode-1])));
|
||||
char *alien_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode)
|
||||
{
|
||||
return (strdup(gettext_noop(alien_descs[which][mode - 1])));
|
||||
}
|
||||
|
||||
//Do the effect for one pixel
|
||||
static void do_alien_pixel(void * ptr, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x, int y){
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
static void do_alien_pixel(void *ptr, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
|
||||
{
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
|
||||
Uint8 temp[3];
|
||||
double temp2[3];
|
||||
int k;
|
||||
|
||||
SDL_GetRGB(api->getpixel(canvas,x, y), canvas->format, &temp[0], &temp[1], &temp[2]);
|
||||
for (k =0;k<3;k++){
|
||||
SDL_GetRGB(api->getpixel(canvas, x, y), canvas->format, &temp[0], &temp[1], &temp[2]);
|
||||
for (k = 0; k < 3; k++)
|
||||
{
|
||||
//EP temp2[k] = clamp(0,127.5 * (1.0 + sin (((temp[k] / 127.5 - 1.0) * alien_FREQUENCY[k] + alien_ANGLE[k] / 180.0) * M_PI)),255);
|
||||
temp2[k] = clamp(0.0,
|
||||
127.5 * (
|
||||
1.0 + sin (((temp[k] / 127.5 - 1.0) * alien_FREQUENCY[k] + alien_ANGLE[k] / 180.0) * M_PI)
|
||||
),
|
||||
255.0);
|
||||
}
|
||||
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, temp2[0], temp2[1], temp2[2]));
|
||||
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)),
|
||||
255.0);
|
||||
}
|
||||
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, temp2[0], temp2[1], temp2[2]));
|
||||
|
||||
}
|
||||
|
||||
// Do the effect for the full image
|
||||
static void do_alien_full(void * ptr,SDL_Surface * canvas, SDL_Surface * last, int which){
|
||||
static void do_alien_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int which)
|
||||
{
|
||||
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
|
||||
int x,y;
|
||||
int x, y;
|
||||
|
||||
for (y = 0; y < last->h; y++){
|
||||
for (x=0; x < last->w; x++){
|
||||
do_alien_pixel(ptr, which, canvas, last, x, y);
|
||||
}
|
||||
}
|
||||
for (y = 0; y < last->h; y++)
|
||||
{
|
||||
for (x = 0; x < last->w; x++)
|
||||
{
|
||||
do_alien_pixel(ptr, which, canvas, last, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//do the effect for the brush
|
||||
static void do_alien_brush(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y){
|
||||
static void do_alien_brush(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
|
||||
{
|
||||
int xx, yy;
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
|
||||
for (yy = y - alien_RADIUS; yy < y + alien_RADIUS; yy++)
|
||||
{
|
||||
for (xx = x - alien_RADIUS; xx < x + alien_RADIUS; xx++)
|
||||
{
|
||||
if (api->in_circle(xx - x, yy - y, alien_RADIUS) &&
|
||||
!api->touched(xx, yy))
|
||||
{
|
||||
do_alien_pixel(api, which, canvas, last, xx, yy);
|
||||
}
|
||||
for (xx = x - alien_RADIUS; xx < x + alien_RADIUS; xx++)
|
||||
{
|
||||
if (api->in_circle(xx - x, yy - y, alien_RADIUS) && !api->touched(xx, yy))
|
||||
{
|
||||
do_alien_pixel(api, which, canvas, last, xx, yy);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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){
|
||||
|
||||
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_alien_brush);
|
||||
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,53 +232,60 @@ void alien_drag(magic_api * api, int which, SDL_Surface * canvas,
|
|||
|
||||
int use_sound = 1;
|
||||
|
||||
Mix_Chunk * magic_loadsound(char* file){
|
||||
Mix_Chunk * temp;
|
||||
Mix_Chunk *magic_loadsound(char *file)
|
||||
{
|
||||
Mix_Chunk *temp;
|
||||
|
||||
if (!use_sound){
|
||||
return (Mix_Chunk*)-1;
|
||||
}
|
||||
if (!use_sound)
|
||||
{
|
||||
return (Mix_Chunk *) - 1;
|
||||
}
|
||||
temp = Mix_LoadWAV(file);
|
||||
return temp;
|
||||
}
|
||||
|
||||
// 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{
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
do_alien_full(api, canvas, last, which);
|
||||
api->playsound(alien_snd_effect[which], 128, 255);
|
||||
}
|
||||
else
|
||||
{
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
do_alien_full(api, canvas, last, which);
|
||||
api->playsound(alien_snd_effect[which], 128, 255);
|
||||
}
|
||||
}
|
||||
|
||||
// Affect the canvas on release:
|
||||
void alien_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)
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
// No setup happened:
|
||||
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){
|
||||
Mix_FreeChunk(alien_snd_effect[i]);
|
||||
}
|
||||
}
|
||||
//Clean up sounds
|
||||
int i;
|
||||
|
||||
for (i = 0; i < alien_NUM_TOOLS; i++)
|
||||
{
|
||||
if (alien_snd_effect[i] != NULL)
|
||||
{
|
||||
Mix_FreeChunk(alien_snd_effect[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Record the color from Tux Paint:
|
||||
void alien_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
|
||||
void alien_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
|
||||
Uint8 b ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -261,16 +295,17 @@ int alien_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_
|
|||
return 0;
|
||||
}
|
||||
|
||||
void alien_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void alien_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void alien_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void alien_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
int alien_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_FULLSCREEN|MODE_PAINT);
|
||||
return (MODE_FULLSCREEN | MODE_PAINT);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,54 +33,54 @@
|
|||
int BLIND_RADIUS = 16;
|
||||
int BLIND_OPAQUE = 20;
|
||||
int BLIND_THICKNESS = 30;
|
||||
int blind_side; /* 0 top, 1 left, 2 bottom, 3 right */
|
||||
int blind_side; /* 0 top, 1 left, 2 bottom, 3 right */
|
||||
|
||||
static Uint8 blind_r, blind_g, blind_b, blind_light;
|
||||
enum blind_sides{
|
||||
enum blind_sides
|
||||
{
|
||||
BLIND_SIDE_TOP,
|
||||
BLIND_SIDE_LEFT,
|
||||
BLIND_SIDE_BOTTOM,
|
||||
BLIND_SIDE_RIGHT};
|
||||
BLIND_SIDE_RIGHT
|
||||
};
|
||||
|
||||
enum blind_tools{
|
||||
enum blind_tools
|
||||
{
|
||||
BLIND_TOOL_BLIND,
|
||||
BLIND_NUMTOOLS};
|
||||
BLIND_NUMTOOLS
|
||||
};
|
||||
|
||||
Mix_Chunk * blind_snd;
|
||||
Mix_Chunk *blind_snd;
|
||||
|
||||
// Prototypes
|
||||
Uint32 blind_api_version(void);
|
||||
void blind_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
int blind_init(magic_api * api);
|
||||
int blind_get_tool_count(magic_api * api);
|
||||
SDL_Surface * blind_get_icon(magic_api * api, int which);
|
||||
char * blind_get_name(magic_api * api, int which);
|
||||
char * blind_get_description(magic_api * api, int which, int mode);
|
||||
SDL_Surface *blind_get_icon(magic_api * api, int which);
|
||||
char *blind_get_name(magic_api * api, int which);
|
||||
char *blind_get_description(magic_api * api, int which, int mode);
|
||||
int blind_requires_colors(magic_api * api, int which);
|
||||
void blind_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
|
||||
void blind_shutdown(magic_api * api);
|
||||
void blind_paint_blind(void * ptr_to_api, int which_tool,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
|
||||
void blind_paint_blind(void *ptr_to_api, int which_tool, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
|
||||
void blind_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
void blind_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void blind_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
void blind_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
int blind_modes(magic_api * api, int which);
|
||||
|
||||
// Housekeeping functions
|
||||
// Housekeeping functions
|
||||
|
||||
Uint32 blind_api_version(void)
|
||||
{
|
||||
return(TP_MAGIC_API_VERSION);
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
void blind_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b) //get the colors from API and store it in structure
|
||||
void blind_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b) //get the colors from API and store it in structure
|
||||
{
|
||||
blind_r = r;
|
||||
blind_g = g;
|
||||
|
|
@ -91,10 +91,10 @@ int blind_init(magic_api * api)
|
|||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/blind.ogg", api->data_directory);
|
||||
blind_snd = Mix_LoadWAV(fname);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/blind.ogg", api->data_directory);
|
||||
blind_snd = Mix_LoadWAV(fname);
|
||||
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
int blind_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
|
|
@ -102,24 +102,25 @@ int blind_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
|||
return BLIND_NUMTOOLS;
|
||||
}
|
||||
|
||||
SDL_Surface * blind_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
SDL_Surface *blind_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/blind.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/blind.png", api->data_directory);
|
||||
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
char * blind_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
char *blind_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return strdup(gettext_noop("Blind"));
|
||||
return strdup(gettext_noop("Blind"));
|
||||
}
|
||||
|
||||
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."));
|
||||
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."));
|
||||
}
|
||||
|
||||
int blind_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
|
|
@ -128,24 +129,26 @@ int blind_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_
|
|||
}
|
||||
|
||||
void blind_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)
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * snapshot ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void blind_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
Mix_FreeChunk(blind_snd);
|
||||
Mix_FreeChunk(blind_snd);
|
||||
}
|
||||
|
||||
// Interactivity functions
|
||||
|
||||
void blind_paint_blind(void * ptr_to_api, int which_tool ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
|
||||
void blind_paint_blind(void *ptr_to_api, int which_tool ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr_to_api;
|
||||
magic_api *api = (magic_api *) ptr_to_api;
|
||||
|
||||
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, (blind_r + blind_light) / 2, (blind_g + blind_light) / 2, (blind_b + blind_light) / 2));
|
||||
api->putpixel(canvas, x, y,
|
||||
SDL_MapRGB(canvas->format, (blind_r + blind_light) / 2, (blind_g + blind_light) / 2,
|
||||
(blind_b + blind_light) / 2));
|
||||
}
|
||||
|
||||
/* void blind_do_blind(void * ptr_to_api, int which_tool,
|
||||
|
|
@ -159,31 +162,31 @@ 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;
|
||||
|
||||
|
||||
SDL_BlitSurface(snapshot, NULL, canvas, NULL);
|
||||
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)
|
||||
{
|
||||
blind_light = 255;
|
||||
for (j=i; j > i - opaque/2; j--)
|
||||
{
|
||||
api->line(api, which, canvas, snapshot, 0, j, canvas->w, j, 1, blind_paint_blind);
|
||||
blind_light -=20;
|
||||
}
|
||||
for (j = i - opaque/2; j > i - opaque; j--)
|
||||
{
|
||||
api->line(api, which, canvas, snapshot, 0, j, canvas->w, j, 1, blind_paint_blind);
|
||||
blind_light +=20;
|
||||
}
|
||||
}
|
||||
for (i = y; i >= 0; i -= BLIND_THICKNESS)
|
||||
{
|
||||
blind_light = 255;
|
||||
for (j = i; j > i - opaque / 2; j--)
|
||||
{
|
||||
api->line(api, which, canvas, snapshot, 0, j, canvas->w, j, 1, blind_paint_blind);
|
||||
blind_light -= 20;
|
||||
}
|
||||
for (j = i - opaque / 2; j > i - opaque; j--)
|
||||
{
|
||||
api->line(api, which, canvas, snapshot, 0, j, canvas->w, j, 1, blind_paint_blind);
|
||||
blind_light += 20;
|
||||
}
|
||||
}
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
|
|
@ -194,19 +197,19 @@ void blind_drag(magic_api * api, int which, SDL_Surface * canvas,
|
|||
case BLIND_SIDE_BOTTOM:
|
||||
opaque = max((x * BLIND_THICKNESS) / canvas->w + 2, 2);
|
||||
for (i = y; i <= canvas->h; i += BLIND_THICKNESS)
|
||||
{
|
||||
blind_light = 255;
|
||||
for (j = i; j < i + opaque / 2; j++)
|
||||
{
|
||||
api->line(api, which, canvas, snapshot, 0, j, canvas->w, j, 1, blind_paint_blind);
|
||||
blind_light -= 20;
|
||||
}
|
||||
for (j = i + opaque / 2; j < i + opaque; j ++)
|
||||
{
|
||||
api->line(api, which, canvas, snapshot, 0, j, canvas->w, j, 1, blind_paint_blind);
|
||||
blind_light += 20;
|
||||
}
|
||||
}
|
||||
{
|
||||
blind_light = 255;
|
||||
for (j = i; j < i + opaque / 2; j++)
|
||||
{
|
||||
api->line(api, which, canvas, snapshot, 0, j, canvas->w, j, 1, blind_paint_blind);
|
||||
blind_light -= 20;
|
||||
}
|
||||
for (j = i + opaque / 2; j < i + opaque; j++)
|
||||
{
|
||||
api->line(api, which, canvas, snapshot, 0, j, canvas->w, j, 1, blind_paint_blind);
|
||||
blind_light += 20;
|
||||
}
|
||||
}
|
||||
|
||||
update_rect->x = 0;
|
||||
update_rect->y = min(oy, y);
|
||||
|
|
@ -218,19 +221,19 @@ void blind_drag(magic_api * api, int which, SDL_Surface * canvas,
|
|||
case BLIND_SIDE_RIGHT:
|
||||
opaque = max((y * BLIND_THICKNESS) / canvas->h + 2, 2);
|
||||
for (i = x; i <= canvas->w; i += BLIND_THICKNESS)
|
||||
{
|
||||
blind_light = 255;
|
||||
for (j = i; j < i + opaque / 2; j++)
|
||||
{
|
||||
api->line(api, which, canvas, snapshot, j, 0, j, canvas->h, 1, blind_paint_blind);
|
||||
blind_light -= 20;
|
||||
}
|
||||
for (j = i + opaque / 2; j < i + opaque; j ++)
|
||||
{
|
||||
api->line(api, which, canvas, snapshot, j, 0, j, canvas->h, 1, blind_paint_blind);
|
||||
blind_light += 20;
|
||||
}
|
||||
}
|
||||
{
|
||||
blind_light = 255;
|
||||
for (j = i; j < i + opaque / 2; j++)
|
||||
{
|
||||
api->line(api, which, canvas, snapshot, j, 0, j, canvas->h, 1, blind_paint_blind);
|
||||
blind_light -= 20;
|
||||
}
|
||||
for (j = i + opaque / 2; j < i + opaque; j++)
|
||||
{
|
||||
api->line(api, which, canvas, snapshot, j, 0, j, canvas->h, 1, blind_paint_blind);
|
||||
blind_light += 20;
|
||||
}
|
||||
}
|
||||
|
||||
update_rect->x = min(ox, x);
|
||||
update_rect->y = 0;
|
||||
|
|
@ -242,19 +245,19 @@ void blind_drag(magic_api * api, int which, SDL_Surface * canvas,
|
|||
case BLIND_SIDE_LEFT:
|
||||
opaque = max((y * BLIND_THICKNESS) / canvas->h + 2, 2);
|
||||
for (i = x; i >= 0; i -= BLIND_THICKNESS)
|
||||
{
|
||||
blind_light = 255;
|
||||
for (j=i; j > i - opaque/2; j--)
|
||||
{
|
||||
api->line(api, which, canvas, snapshot, j, 0, j, canvas->h, 1, blind_paint_blind);
|
||||
blind_light -=20;
|
||||
}
|
||||
for (j = i - opaque/2; j > i - opaque; j--)
|
||||
{
|
||||
api->line(api, which, canvas, snapshot, j, 0, j, canvas->h, 1, blind_paint_blind);
|
||||
blind_light +=20;
|
||||
}
|
||||
}
|
||||
{
|
||||
blind_light = 255;
|
||||
for (j = i; j > i - opaque / 2; j--)
|
||||
{
|
||||
api->line(api, which, canvas, snapshot, j, 0, j, canvas->h, 1, blind_paint_blind);
|
||||
blind_light -= 20;
|
||||
}
|
||||
for (j = i - opaque / 2; j > i - opaque; j--)
|
||||
{
|
||||
api->line(api, which, canvas, snapshot, j, 0, j, canvas->h, 1, blind_paint_blind);
|
||||
blind_light += 20;
|
||||
}
|
||||
}
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
update_rect->w = max(ox, x);
|
||||
|
|
@ -266,37 +269,44 @@ void blind_drag(magic_api * api, int which, SDL_Surface * canvas,
|
|||
}
|
||||
|
||||
void blind_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect)
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
if (y < canvas->h / 2)
|
||||
if (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
|
||||
{
|
||||
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_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 */
|
||||
}
|
||||
|
||||
blind_drag(api, which, canvas, last, x, y, x, y, update_rect);
|
||||
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_switchout(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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int blind_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_FULLSCREEN | MODE_PAINT);
|
||||
return (MODE_FULLSCREEN | MODE_PAINT);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,8 @@
|
|||
|
||||
/* What tools we contain: */
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
TOOL_BLOCKS,
|
||||
TOOL_CHALK,
|
||||
TOOL_DRIP,
|
||||
|
|
@ -45,7 +46,7 @@ enum {
|
|||
|
||||
/* Our globals: */
|
||||
|
||||
static Mix_Chunk * snd_effect[NUM_TOOLS];
|
||||
static Mix_Chunk *snd_effect[NUM_TOOLS];
|
||||
|
||||
|
||||
/* Our function prototypes: */
|
||||
|
|
@ -53,21 +54,16 @@ static Mix_Chunk * snd_effect[NUM_TOOLS];
|
|||
int blocks_chalk_drip_init(magic_api * api);
|
||||
Uint32 blocks_chalk_drip_api_version(void);
|
||||
int blocks_chalk_drip_get_tool_count(magic_api * api);
|
||||
SDL_Surface * blocks_chalk_drip_get_icon(magic_api * api, int which);
|
||||
char * blocks_chalk_drip_get_name(magic_api * api, int which);
|
||||
char * blocks_chalk_drip_get_description(magic_api * api, int which, int mode);
|
||||
static void blocks_chalk_drip_linecb(void * ptr, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y);
|
||||
SDL_Surface *blocks_chalk_drip_get_icon(magic_api * api, int which);
|
||||
char *blocks_chalk_drip_get_name(magic_api * api, int which);
|
||||
char *blocks_chalk_drip_get_description(magic_api * api, int which, int mode);
|
||||
static void blocks_chalk_drip_linecb(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||
void blocks_chalk_drip_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
void blocks_chalk_drip_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void blocks_chalk_drip_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void blocks_chalk_drip_shutdown(magic_api * api);
|
||||
void blocks_chalk_drip_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
int blocks_chalk_drip_requires_colors(magic_api * api, int which);
|
||||
|
|
@ -81,90 +77,82 @@ int blocks_chalk_drip_init(magic_api * api)
|
|||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/blocks.wav",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/blocks.wav", api->data_directory);
|
||||
snd_effect[0] = Mix_LoadWAV(fname);
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/chalk.wav",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/chalk.wav", api->data_directory);
|
||||
snd_effect[1] = Mix_LoadWAV(fname);
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/drip.wav",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/drip.wav", api->data_directory);
|
||||
snd_effect[2] = Mix_LoadWAV(fname);
|
||||
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
Uint32 blocks_chalk_drip_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
Uint32 blocks_chalk_drip_api_version(void)
|
||||
{
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
|
||||
// We have multiple tools:
|
||||
int blocks_chalk_drip_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(NUM_TOOLS);
|
||||
return (NUM_TOOLS);
|
||||
}
|
||||
|
||||
// Load our icons:
|
||||
SDL_Surface * blocks_chalk_drip_get_icon(magic_api * api, int which)
|
||||
SDL_Surface *blocks_chalk_drip_get_icon(magic_api * api, int which)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
if (which == TOOL_BLOCKS)
|
||||
{
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/blocks.png",
|
||||
api->data_directory);
|
||||
}
|
||||
{
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/blocks.png", api->data_directory);
|
||||
}
|
||||
else if (which == TOOL_CHALK)
|
||||
{
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/chalk.png",
|
||||
api->data_directory);
|
||||
}
|
||||
{
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/chalk.png", api->data_directory);
|
||||
}
|
||||
else if (which == TOOL_DRIP)
|
||||
{
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/drip.png",
|
||||
api->data_directory);
|
||||
}
|
||||
{
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/drip.png", api->data_directory);
|
||||
}
|
||||
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our names, localized:
|
||||
char * blocks_chalk_drip_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
|
||||
char *blocks_chalk_drip_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
|
||||
{
|
||||
if (which == TOOL_BLOCKS)
|
||||
return(strdup(gettext_noop("Blocks")));
|
||||
return (strdup(gettext_noop("Blocks")));
|
||||
else if (which == TOOL_CHALK)
|
||||
return(strdup(gettext_noop("Chalk")));
|
||||
return (strdup(gettext_noop("Chalk")));
|
||||
else if (which == TOOL_DRIP)
|
||||
return(strdup(gettext_noop("Drip")));
|
||||
return (strdup(gettext_noop("Drip")));
|
||||
|
||||
return(NULL);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
// Return our descriptions, localized:
|
||||
char * blocks_chalk_drip_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
|
||||
char *blocks_chalk_drip_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
|
||||
{
|
||||
if (which == TOOL_BLOCKS)
|
||||
return(strdup(gettext_noop(
|
||||
"Click and drag the mouse around to make the picture blocky.")));
|
||||
return (strdup(gettext_noop("Click and drag the mouse around to make the picture blocky.")));
|
||||
else if (which == TOOL_CHALK)
|
||||
return(strdup(gettext_noop(
|
||||
"Click and drag the mouse around to turn the picture into a chalk drawing.")));
|
||||
return (strdup(gettext_noop("Click and drag the mouse around to turn the picture into a chalk drawing.")));
|
||||
else if (which == TOOL_DRIP)
|
||||
return(strdup(gettext_noop(
|
||||
"Click and drag the mouse around to make the picture drip.")));
|
||||
return (strdup(gettext_noop("Click and drag the mouse around to make the picture drip.")));
|
||||
|
||||
return(NULL);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
// Do the effect:
|
||||
|
||||
static void blocks_chalk_drip_linecb(void * ptr, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y)
|
||||
static void blocks_chalk_drip_linecb(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
int xx, yy;
|
||||
int h;
|
||||
SDL_Rect src, dest;
|
||||
|
|
@ -172,113 +160,126 @@ static void blocks_chalk_drip_linecb(void * ptr, int which,
|
|||
Uint32 colr;
|
||||
|
||||
if (which == TOOL_BLOCKS)
|
||||
{
|
||||
/* Put x/y on exact grid points: */
|
||||
|
||||
x = (x / 4) * 4;
|
||||
y = (y / 4) * 4;
|
||||
|
||||
if (!api->touched(x, y))
|
||||
{
|
||||
for (yy = y - 8; yy < y + 8; yy = yy + 4)
|
||||
{
|
||||
for (xx = x - 8; xx < x + 8; xx = xx + 4)
|
||||
{
|
||||
Uint32 pix[16];
|
||||
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;
|
||||
pix[i] = p_tmp;
|
||||
}
|
||||
if (p_or == p_and) // if all pixels the same already
|
||||
{
|
||||
SDL_GetRGB(p_or, last->format, &r, &g, &b);
|
||||
}
|
||||
else // nope, must average them
|
||||
{
|
||||
double r_sum = 0.0;
|
||||
double g_sum = 0.0;
|
||||
double b_sum = 0.0;
|
||||
i = 16;
|
||||
while (i--)
|
||||
{
|
||||
SDL_GetRGB(pix[i], last->format, &r, &g, &b);
|
||||
r_sum += api->sRGB_to_linear(r);
|
||||
g_sum += api->sRGB_to_linear(g);
|
||||
b_sum += api->sRGB_to_linear(b);
|
||||
}
|
||||
r = api->linear_to_sRGB(r_sum / 16.0);
|
||||
g = api->linear_to_sRGB(g_sum / 16.0);
|
||||
b = api->linear_to_sRGB(b_sum / 16.0);
|
||||
}
|
||||
/* Put x/y on exact grid points: */
|
||||
|
||||
/* Draw block: */
|
||||
x = (x / 4) * 4;
|
||||
y = (y / 4) * 4;
|
||||
|
||||
dest.x = xx;
|
||||
dest.y = yy;
|
||||
dest.w = 4;
|
||||
dest.h = 4;
|
||||
if (!api->touched(x, y))
|
||||
{
|
||||
for (yy = y - 8; yy < y + 8; yy = yy + 4)
|
||||
{
|
||||
for (xx = x - 8; xx < x + 8; xx = xx + 4)
|
||||
{
|
||||
Uint32 pix[16];
|
||||
Uint32 p_or = 0;
|
||||
Uint32 p_and = ~0;
|
||||
unsigned i = 16;
|
||||
|
||||
SDL_FillRect(canvas, &dest, SDL_MapRGB(canvas->format, r, g, b));
|
||||
}
|
||||
}
|
||||
while (i--)
|
||||
{
|
||||
Uint32 p_tmp;
|
||||
|
||||
p_tmp = api->getpixel(last, xx + (i >> 2), yy + (i & 3));
|
||||
p_or |= p_tmp;
|
||||
p_and &= p_tmp;
|
||||
pix[i] = p_tmp;
|
||||
}
|
||||
if (p_or == p_and) // if all pixels the same already
|
||||
{
|
||||
SDL_GetRGB(p_or, last->format, &r, &g, &b);
|
||||
}
|
||||
else // nope, must average them
|
||||
{
|
||||
double r_sum = 0.0;
|
||||
double g_sum = 0.0;
|
||||
double b_sum = 0.0;
|
||||
|
||||
i = 16;
|
||||
while (i--)
|
||||
{
|
||||
SDL_GetRGB(pix[i], last->format, &r, &g, &b);
|
||||
r_sum += api->sRGB_to_linear(r);
|
||||
g_sum += api->sRGB_to_linear(g);
|
||||
b_sum += api->sRGB_to_linear(b);
|
||||
}
|
||||
r = api->linear_to_sRGB(r_sum / 16.0);
|
||||
g = api->linear_to_sRGB(g_sum / 16.0);
|
||||
b = api->linear_to_sRGB(b_sum / 16.0);
|
||||
}
|
||||
|
||||
/* Draw block: */
|
||||
|
||||
dest.x = xx;
|
||||
dest.y = yy;
|
||||
dest.w = 4;
|
||||
dest.h = 4;
|
||||
|
||||
SDL_FillRect(canvas, &dest, SDL_MapRGB(canvas->format, r, g, b));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (which == TOOL_CHALK)
|
||||
{
|
||||
|
||||
for (yy = y - 8; yy <= y + 8; yy = yy + 4)
|
||||
{
|
||||
for (xx = x - 8; xx <= x + 8; xx = xx + 4)
|
||||
{
|
||||
dest.x = xx + ((rand() % 5) - 2);
|
||||
dest.y = yy + ((rand() % 5) - 2);
|
||||
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));
|
||||
SDL_FillRect(canvas, &dest, colr);
|
||||
}
|
||||
for (yy = y - 8; yy <= y + 8; yy = yy + 4)
|
||||
{
|
||||
for (xx = x - 8; xx <= x + 8; xx = xx + 4)
|
||||
{
|
||||
dest.x = xx + ((rand() % 5) - 2);
|
||||
dest.y = yy + ((rand() % 5) - 2);
|
||||
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));
|
||||
SDL_FillRect(canvas, &dest, colr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (which == TOOL_DRIP)
|
||||
{
|
||||
for (xx = x - 8; xx <= x + 8; xx++)
|
||||
{
|
||||
h = (rand() % 8) + 8;
|
||||
for (xx = x - 8; xx <= x + 8; xx++)
|
||||
{
|
||||
h = (rand() % 8) + 8;
|
||||
|
||||
for (yy = y; yy <= y + h; yy++)
|
||||
{
|
||||
src.x = xx;
|
||||
src.y = y;
|
||||
src.w = 1;
|
||||
src.h = 16;
|
||||
for (yy = y; yy <= y + h; yy++)
|
||||
{
|
||||
src.x = xx;
|
||||
src.y = y;
|
||||
src.w = 1;
|
||||
src.h = 16;
|
||||
|
||||
dest.x = xx;
|
||||
dest.y = yy;
|
||||
dest.x = xx;
|
||||
dest.y = yy;
|
||||
|
||||
SDL_BlitSurface(last, &src, canvas, &dest);
|
||||
}
|
||||
SDL_BlitSurface(last, &src, canvas, &dest);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Affect the canvas on drag:
|
||||
void blocks_chalk_drip_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, blocks_chalk_drip_linecb);
|
||||
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, blocks_chalk_drip_linecb);
|
||||
|
||||
if (ox > x) { int tmp = ox; ox = x; x = tmp; }
|
||||
if (oy > y) { int tmp = oy; oy = y; y = tmp; }
|
||||
if (ox > x)
|
||||
{
|
||||
int tmp = ox;
|
||||
|
||||
ox = x;
|
||||
x = tmp;
|
||||
}
|
||||
if (oy > y)
|
||||
{
|
||||
int tmp = oy;
|
||||
|
||||
oy = y;
|
||||
y = tmp;
|
||||
}
|
||||
|
||||
update_rect->x = ox - 16;
|
||||
update_rect->y = oy - 16;
|
||||
|
|
@ -290,16 +291,15 @@ 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);
|
||||
}
|
||||
|
||||
// Affect the canvas on release:
|
||||
void blocks_chalk_drip_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)
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -315,7 +315,7 @@ void blocks_chalk_drip_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
|||
|
||||
// Record the color from Tux Paint:
|
||||
void blocks_chalk_drip_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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -325,15 +325,17 @@ int blocks_chalk_drip_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int whic
|
|||
return 0;
|
||||
}
|
||||
|
||||
void blocks_chalk_drip_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void blocks_chalk_drip_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void blocks_chalk_drip_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void blocks_chalk_drip_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
|
||||
int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
int blocks_chalk_drip_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_PAINT); /* FIXME - Blocks and Chalk, at least, can also be turned into a full-image effect */
|
||||
return (MODE_PAINT); /* FIXME - Blocks and Chalk, at least, can also be turned into a full-image effect */
|
||||
}
|
||||
|
|
|
|||
251
magic/src/blur.c
251
magic/src/blur.c
|
|
@ -42,18 +42,15 @@
|
|||
Uint32 blur_api_version(void);
|
||||
int blur_init(magic_api * api);
|
||||
int blur_get_tool_count(magic_api * api);
|
||||
SDL_Surface * blur_get_icon(magic_api * api, int which);
|
||||
char * blur_get_name(magic_api * api, int which);
|
||||
char * blur_get_description(magic_api * api, int which, int mode);
|
||||
SDL_Surface *blur_get_icon(magic_api * api, int which);
|
||||
char *blur_get_name(magic_api * api, int which);
|
||||
char *blur_get_description(magic_api * api, int which, int mode);
|
||||
void blur_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
void blur_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void blur_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void blur_shutdown(magic_api * api);
|
||||
void blur_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
int blur_requires_colors(magic_api * api, int which);
|
||||
|
|
@ -61,142 +58,177 @@ 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 {
|
||||
TOOL_blur,
|
||||
blur_NUM_TOOLS
|
||||
enum
|
||||
{
|
||||
TOOL_blur,
|
||||
blur_NUM_TOOLS
|
||||
};
|
||||
|
||||
static const int blur_RADIUS = 16;
|
||||
|
||||
static Mix_Chunk * blur_snd_effect[blur_NUM_TOOLS];
|
||||
static Mix_Chunk *blur_snd_effect[blur_NUM_TOOLS];
|
||||
|
||||
const char *blur_snd_filenames[blur_NUM_TOOLS] = {
|
||||
"blur.wav",
|
||||
};
|
||||
const char * blur_icon_filenames[blur_NUM_TOOLS] = {
|
||||
|
||||
const char *blur_icon_filenames[blur_NUM_TOOLS] = {
|
||||
"blur.png",
|
||||
};
|
||||
const char * blur_names[blur_NUM_TOOLS] = {
|
||||
|
||||
const char *blur_names[blur_NUM_TOOLS] = {
|
||||
gettext_noop("Blur"),
|
||||
};
|
||||
const char * blur_descs[blur_NUM_TOOLS][2] = {
|
||||
{gettext_noop("Click and drag the mouse around to blur the image."),
|
||||
gettext_noop("Click to blur the entire image.")},
|
||||
|
||||
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++){
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/%s", api->data_directory, blur_snd_filenames[i]);
|
||||
blur_snd_effect[i] = Mix_LoadWAV(fname);
|
||||
}
|
||||
return(1);
|
||||
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){
|
||||
return(blur_NUM_TOOLS);
|
||||
int blur_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return (blur_NUM_TOOLS);
|
||||
}
|
||||
|
||||
// Load our icons:
|
||||
SDL_Surface * blur_get_icon(magic_api * api, int which){
|
||||
SDL_Surface *blur_get_icon(magic_api * api, int which)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, blur_icon_filenames[which]);
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our names, localized:
|
||||
char * blur_get_name(magic_api * api ATTRIBUTE_UNUSED, int which){
|
||||
return(strdup(gettext_noop(blur_names[which])));
|
||||
char *blur_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
|
||||
{
|
||||
return (strdup(gettext_noop(blur_names[which])));
|
||||
}
|
||||
|
||||
// Return our descriptions, localized:
|
||||
char * blur_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode){
|
||||
return(strdup(gettext_noop(blur_descs[which][mode-1])));
|
||||
char *blur_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode)
|
||||
{
|
||||
return (strdup(gettext_noop(blur_descs[which][mode - 1])));
|
||||
}
|
||||
|
||||
//Do the effect for one pixel
|
||||
static void do_blur_pixel(void * ptr, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y){
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
int i,j,k;
|
||||
Uint8 temp[3];
|
||||
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}};
|
||||
const int weight[5][5] = { {1, 4, 7, 4, 1},
|
||||
{4, 16, 26, 16, 4},
|
||||
{7, 26, 41, 26, 7},
|
||||
{4, 16, 26, 16, 4},
|
||||
{1, 4, 7, 4, 1}
|
||||
};
|
||||
|
||||
for (k =0;k<3;k++){
|
||||
blurValue[k] = 0;
|
||||
}
|
||||
|
||||
for (i=-2;i<3;i++){
|
||||
for (j=-2;j<3;j++){
|
||||
//Add the pixels around the current one wieghted
|
||||
SDL_GetRGB(api->getpixel(last, x + i, y + j), last->format, &temp[0], &temp[1], &temp[2]);
|
||||
for (k =0;k<3;k++){
|
||||
blurValue[k] += temp[k]* weight[i+2][j+2];
|
||||
}
|
||||
for (k = 0; k < 3; k++)
|
||||
{
|
||||
blurValue[k] = 0;
|
||||
}
|
||||
}
|
||||
for (k =0;k<3;k++){
|
||||
blurValue[k] /= 273;
|
||||
}
|
||||
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, blurValue[0], blurValue[1], blurValue[2]));
|
||||
|
||||
for (i = -2; i < 3; i++)
|
||||
{
|
||||
for (j = -2; j < 3; j++)
|
||||
{
|
||||
//Add the pixels around the current one wieghted
|
||||
SDL_GetRGB(api->getpixel(last, x + i, y + j), last->format, &temp[0], &temp[1], &temp[2]);
|
||||
for (k = 0; k < 3; k++)
|
||||
{
|
||||
blurValue[k] += temp[k] * weight[i + 2][j + 2];
|
||||
}
|
||||
}
|
||||
}
|
||||
for (k = 0; k < 3; k++)
|
||||
{
|
||||
blurValue[k] /= 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;
|
||||
//magic_api * api = (magic_api *) ptr;
|
||||
|
||||
int x,y;
|
||||
int x, y;
|
||||
|
||||
for (y = 0; y < last->h; y++){
|
||||
for (x=0; x < last->w; x++){
|
||||
do_blur_pixel(ptr, which, canvas, last, x, y);
|
||||
}
|
||||
}
|
||||
for (y = 0; y < last->h; y++)
|
||||
{
|
||||
for (x = 0; x < last->w; x++)
|
||||
{
|
||||
do_blur_pixel(ptr, which, canvas, last, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//do the effect for the brush
|
||||
static void do_blur_brush(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y){
|
||||
static void do_blur_brush(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
|
||||
{
|
||||
int xx, yy;
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
|
||||
for (yy = y - blur_RADIUS; yy < y + blur_RADIUS; yy++)
|
||||
{
|
||||
for (xx = x - blur_RADIUS; xx < x + blur_RADIUS; xx++)
|
||||
{
|
||||
if (api->in_circle(xx - x, yy - y, blur_RADIUS) &&
|
||||
!api->touched(xx, yy))
|
||||
{
|
||||
do_blur_pixel(api, which, canvas, last, xx, yy);
|
||||
}
|
||||
for (xx = x - blur_RADIUS; xx < x + blur_RADIUS; xx++)
|
||||
{
|
||||
if (api->in_circle(xx - x, yy - y, blur_RADIUS) && !api->touched(xx, yy))
|
||||
{
|
||||
do_blur_pixel(api, which, canvas, last, xx, yy);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Affect the canvas on drag:
|
||||
void blur_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect){
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
|
||||
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_blur_brush);
|
||||
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_blur_brush);
|
||||
|
||||
api->playsound(blur_snd_effect[which], (x * 255) / canvas->w, 255);
|
||||
|
||||
if (ox > x) { int tmp = ox; ox = x; x = tmp; }
|
||||
if (oy > y) { int tmp = oy; oy = y; y = tmp; }
|
||||
if (ox > x)
|
||||
{
|
||||
int tmp = ox;
|
||||
|
||||
ox = x;
|
||||
x = tmp;
|
||||
}
|
||||
if (oy > y)
|
||||
{
|
||||
int tmp = oy;
|
||||
|
||||
oy = y;
|
||||
y = tmp;
|
||||
}
|
||||
|
||||
update_rect->x = ox - blur_RADIUS;
|
||||
update_rect->y = oy - blur_RADIUS;
|
||||
|
|
@ -206,41 +238,46 @@ 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{
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
do_blur_full(api, canvas, last, which);
|
||||
api->playsound(blur_snd_effect[which], 128, 255);
|
||||
}
|
||||
else
|
||||
{
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
do_blur_full(api, canvas, last, which);
|
||||
api->playsound(blur_snd_effect[which], 128, 255);
|
||||
}
|
||||
}
|
||||
|
||||
// Affect the canvas on release:
|
||||
void blur_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)
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
// No setup happened:
|
||||
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){
|
||||
Mix_FreeChunk(blur_snd_effect[i]);
|
||||
}
|
||||
}
|
||||
//Clean up sounds
|
||||
int i;
|
||||
|
||||
for (i = 0; i < blur_NUM_TOOLS; i++)
|
||||
{
|
||||
if (blur_snd_effect[i] != NULL)
|
||||
{
|
||||
Mix_FreeChunk(blur_snd_effect[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Record the color from Tux Paint:
|
||||
void blur_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
|
||||
void blur_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
|
||||
Uint8 b ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -250,15 +287,17 @@ int blur_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_U
|
|||
return 0;
|
||||
}
|
||||
|
||||
void blur_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void blur_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void blur_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void blur_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
int blur_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_FULLSCREEN|MODE_PAINT);
|
||||
return (MODE_FULLSCREEN | MODE_PAINT);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,14 +31,15 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h> /* For RAND_MAX */
|
||||
#include <stdlib.h> /* For RAND_MAX */
|
||||
#include "tp_magic_api.h"
|
||||
#include "SDL_image.h"
|
||||
#include "SDL_mixer.h"
|
||||
|
||||
/* What tools we contain: */
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
TOOL_LARGEBRICKS,
|
||||
TOOL_SMALLBRICKS,
|
||||
NUM_TOOLS
|
||||
|
|
@ -47,29 +48,24 @@ enum {
|
|||
|
||||
/* Our globals: */
|
||||
|
||||
static Mix_Chunk * brick_snd;
|
||||
static Mix_Chunk *brick_snd;
|
||||
static Uint8 bricks_r, bricks_g, bricks_b;
|
||||
|
||||
|
||||
/* Local function prototype: */
|
||||
|
||||
static void do_brick(magic_api * api, SDL_Surface * canvas,
|
||||
int x, int y, int w, int h);
|
||||
static void do_brick(magic_api * api, SDL_Surface * canvas, int x, int y, int w, int h);
|
||||
int bricks_init(magic_api * api);
|
||||
Uint32 bricks_api_version(void);
|
||||
int bricks_get_tool_count(magic_api * api);
|
||||
SDL_Surface * bricks_get_icon(magic_api * api, int which);
|
||||
char * bricks_get_name(magic_api * api, int which);
|
||||
char * bricks_get_description(magic_api * api, int which, int mode);
|
||||
SDL_Surface *bricks_get_icon(magic_api * api, int which);
|
||||
char *bricks_get_name(magic_api * api, int which);
|
||||
char *bricks_get_description(magic_api * api, int which, int mode);
|
||||
void bricks_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
void bricks_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
void bricks_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect); //An empty function. Is there a purpose to this? Ask moderator.
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void bricks_release(magic_api * api, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect); //An empty function. Is there a purpose to this? Ask moderator.
|
||||
void bricks_shutdown(magic_api * api);
|
||||
void bricks_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
int bricks_requires_colors(magic_api * api, int which);
|
||||
|
|
@ -82,65 +78,64 @@ int bricks_init(magic_api * api)
|
|||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/brick.wav",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/brick.wav", api->data_directory);
|
||||
brick_snd = Mix_LoadWAV(fname);
|
||||
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
Uint32 bricks_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
Uint32 bricks_api_version(void)
|
||||
{
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
// We have multiple tools:
|
||||
int bricks_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(NUM_TOOLS);
|
||||
return (NUM_TOOLS);
|
||||
}
|
||||
|
||||
// Load our icons:
|
||||
SDL_Surface * bricks_get_icon(magic_api * api, int which)
|
||||
SDL_Surface *bricks_get_icon(magic_api * api, int which)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
if (which == TOOL_LARGEBRICKS)
|
||||
{
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/largebrick.png",
|
||||
api->data_directory);
|
||||
}
|
||||
{
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/largebrick.png", api->data_directory);
|
||||
}
|
||||
else if (which == TOOL_SMALLBRICKS)
|
||||
{
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/smallbrick.png",
|
||||
api->data_directory);
|
||||
}
|
||||
{
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/smallbrick.png", api->data_directory);
|
||||
}
|
||||
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our names, localized:
|
||||
char * bricks_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
char *bricks_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
/* Both are named "Bricks", at the moment: */
|
||||
|
||||
return(strdup(gettext_noop("Bricks")));
|
||||
return (strdup(gettext_noop("Bricks")));
|
||||
}
|
||||
|
||||
// Return our descriptions, localized:
|
||||
char * bricks_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
|
||||
char *bricks_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
|
||||
{
|
||||
if (which == TOOL_LARGEBRICKS)
|
||||
return(strdup(gettext_noop("Click and drag to draw large bricks.")));
|
||||
return (strdup(gettext_noop("Click and drag to draw large bricks.")));
|
||||
else if (which == TOOL_SMALLBRICKS)
|
||||
return(strdup(gettext_noop("Click and drag to draw small bricks.")));
|
||||
return (strdup(gettext_noop("Click and drag to draw small bricks.")));
|
||||
|
||||
return(NULL);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
// Do the effect:
|
||||
|
||||
static void do_bricks(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x, int y)
|
||||
static void do_bricks(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
|
||||
// "specified" means the brick itself, w/o morter
|
||||
// "nominal" means brick-to-brick (includes morter)
|
||||
|
|
@ -148,22 +143,22 @@ static void do_bricks(void * ptr, int which, SDL_Surface * canvas, SDL_Surface *
|
|||
int nominal_length;
|
||||
int brick_x, brick_y;
|
||||
|
||||
int vertical_joint = 2; // between a brick and the one above/below
|
||||
int horizontal_joint = 2; // between a brick and the one to the side
|
||||
int vertical_joint = 2; // between a brick and the one above/below
|
||||
int horizontal_joint = 2; // between a brick and the one to the side
|
||||
int nominal_width = 18;
|
||||
int nominal_height = 12; // 11 to 14, for joints of 2
|
||||
int nominal_height = 12; // 11 to 14, for joints of 2
|
||||
static unsigned char *map;
|
||||
static int x_count;
|
||||
static int y_count;
|
||||
unsigned char *mybrick;
|
||||
|
||||
if (which == TOOL_LARGEBRICKS)
|
||||
{
|
||||
vertical_joint = 4; // between a brick and the one above/below
|
||||
horizontal_joint = 4; // between a brick and the one to the side
|
||||
nominal_width = 36;
|
||||
nominal_height = 24; // 11 to 14, for joints of 2
|
||||
}
|
||||
{
|
||||
vertical_joint = 4; // between a brick and the one above/below
|
||||
horizontal_joint = 4; // between a brick and the one to the side
|
||||
nominal_width = 36;
|
||||
nominal_height = 24; // 11 to 14, for joints of 2
|
||||
}
|
||||
|
||||
nominal_length = 2 * nominal_width;
|
||||
specified_width = nominal_width - horizontal_joint;
|
||||
|
|
@ -171,69 +166,79 @@ static void do_bricks(void * ptr, int which, SDL_Surface * canvas, SDL_Surface *
|
|||
specified_length = nominal_length - horizontal_joint;
|
||||
|
||||
if (!api->button_down())
|
||||
{
|
||||
if (map)
|
||||
free(map);
|
||||
// the "+ 3" allows for both ends and misalignment
|
||||
x_count = (canvas->w + nominal_width - 1) / nominal_width + 3;
|
||||
y_count = (canvas->h + nominal_height - 1) / nominal_height + 3;
|
||||
map = calloc(x_count, y_count);
|
||||
}
|
||||
{
|
||||
if (map)
|
||||
free(map);
|
||||
// the "+ 3" allows for both ends and misalignment
|
||||
x_count = (canvas->w + nominal_width - 1) / nominal_width + 3;
|
||||
y_count = (canvas->h + nominal_height - 1) / nominal_height + 3;
|
||||
map = calloc(x_count, y_count);
|
||||
}
|
||||
|
||||
brick_x = x / nominal_width;
|
||||
brick_y = y / nominal_height;
|
||||
|
||||
mybrick = map + brick_x + 1 + (brick_y + 1) * x_count;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
// FIXME:
|
||||
//SDL_LockSurface(canvas);
|
||||
|
||||
if ((brick_y ^ brick_x) & 1)
|
||||
if ((unsigned)x < (unsigned)canvas->w && (unsigned)y < (unsigned)canvas->h && !*mybrick)
|
||||
{
|
||||
if (mybrick[1])
|
||||
my_w = specified_length;
|
||||
int my_x = brick_x * nominal_width;
|
||||
int my_w = specified_width;
|
||||
|
||||
*mybrick = 1;
|
||||
|
||||
|
||||
// FIXME:
|
||||
//SDL_LockSurface(canvas);
|
||||
|
||||
if ((brick_y ^ brick_x) & 1)
|
||||
{
|
||||
if (mybrick[1])
|
||||
my_w = specified_length;
|
||||
}
|
||||
else if (mybrick[-1])
|
||||
{
|
||||
my_x -= nominal_width;
|
||||
my_w = specified_length;
|
||||
}
|
||||
do_brick(api, canvas, my_x, brick_y * nominal_height, my_w, specified_height);
|
||||
|
||||
|
||||
// FIXME:
|
||||
// SDL_UnlockSurface(canvas);
|
||||
|
||||
// upper left corner and lower right corner
|
||||
|
||||
// FIXME
|
||||
/*
|
||||
update_canvas(brick_x * nominal_width - nominal_width,
|
||||
brick_y * nominal_height - vertical_joint,
|
||||
brick_x * nominal_width + specified_length,
|
||||
(brick_y + 1) * nominal_height);
|
||||
*/
|
||||
}
|
||||
else if (mybrick[-1])
|
||||
{
|
||||
my_x -= nominal_width;
|
||||
my_w = specified_length;
|
||||
}
|
||||
do_brick(api, canvas, my_x, brick_y * nominal_height,
|
||||
my_w, specified_height);
|
||||
|
||||
|
||||
// FIXME:
|
||||
// SDL_UnlockSurface(canvas);
|
||||
|
||||
// upper left corner and lower right corner
|
||||
|
||||
// FIXME
|
||||
/*
|
||||
update_canvas(brick_x * nominal_width - nominal_width,
|
||||
brick_y * nominal_height - vertical_joint,
|
||||
brick_x * nominal_width + specified_length,
|
||||
(brick_y + 1) * nominal_height);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
// Affect the canvas on drag:
|
||||
void bricks_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_bricks);
|
||||
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_bricks);
|
||||
|
||||
if (ox > x) { int tmp = ox; ox = x; x = tmp; }
|
||||
if (oy > y) { int tmp = oy; oy = y; y = tmp; }
|
||||
if (ox > x)
|
||||
{
|
||||
int tmp = ox;
|
||||
|
||||
ox = x;
|
||||
x = tmp;
|
||||
}
|
||||
if (oy > y)
|
||||
{
|
||||
int tmp = oy;
|
||||
|
||||
oy = y;
|
||||
y = tmp;
|
||||
}
|
||||
|
||||
update_rect->x = x - 64;
|
||||
update_rect->y = y - 64;
|
||||
|
|
@ -245,15 +250,14 @@ 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);
|
||||
}
|
||||
|
||||
void bricks_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)
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -278,23 +282,16 @@ int bricks_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE
|
|||
return 1;
|
||||
}
|
||||
|
||||
static void do_brick(magic_api * api, SDL_Surface * canvas,
|
||||
int x, int y, int w, int h)
|
||||
static void do_brick(magic_api * api, SDL_Surface * canvas, int x, int y, int w, int h)
|
||||
{
|
||||
SDL_Rect dest;
|
||||
|
||||
// brick color: 127,76,73
|
||||
double ran_r = rand() / (double) RAND_MAX;
|
||||
double ran_g = rand() / (double) RAND_MAX;
|
||||
double base_r =
|
||||
api->sRGB_to_linear(bricks_r) * 1.5 +
|
||||
api->sRGB_to_linear(127) * 5.0 + ran_r;
|
||||
double base_g =
|
||||
api->sRGB_to_linear(bricks_g) * 1.5 +
|
||||
api->sRGB_to_linear(76) * 5.0 + ran_g;
|
||||
double base_b =
|
||||
api->sRGB_to_linear(bricks_b) * 1.5 +
|
||||
api->sRGB_to_linear(73) * 5.0 + (ran_r + ran_g * 2.0) / 3.0;
|
||||
double ran_r = rand() / (double)RAND_MAX;
|
||||
double ran_g = rand() / (double)RAND_MAX;
|
||||
double base_r = api->sRGB_to_linear(bricks_r) * 1.5 + api->sRGB_to_linear(127) * 5.0 + ran_r;
|
||||
double base_g = api->sRGB_to_linear(bricks_g) * 1.5 + api->sRGB_to_linear(76) * 5.0 + ran_g;
|
||||
double base_b = api->sRGB_to_linear(bricks_b) * 1.5 + api->sRGB_to_linear(73) * 5.0 + (ran_r + ran_g * 2.0) / 3.0;
|
||||
|
||||
Uint8 r = api->linear_to_sRGB(base_r / 7.5);
|
||||
Uint8 g = api->linear_to_sRGB(base_g / 7.5);
|
||||
|
|
@ -315,16 +312,16 @@ static void do_brick(magic_api * api, SDL_Surface * canvas,
|
|||
}
|
||||
|
||||
void bricks_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
|
||||
int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void bricks_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
|
||||
int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
int bricks_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_PAINT);
|
||||
return (MODE_PAINT);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,32 +41,29 @@ typedef struct
|
|||
float x, y;
|
||||
} Point2D;
|
||||
|
||||
static Mix_Chunk * calligraphy_snd;
|
||||
static Mix_Chunk *calligraphy_snd;
|
||||
static Point2D calligraphy_control_points[4];
|
||||
static int calligraphy_r, calligraphy_g, calligraphy_b;
|
||||
static int calligraphy_old_thick;
|
||||
static Uint32 calligraphy_last_time;
|
||||
static SDL_Surface * calligraphy_brush, * calligraphy_colored_brush;
|
||||
static SDL_Surface *calligraphy_brush, *calligraphy_colored_brush;
|
||||
|
||||
/* Local Function Prototypes */
|
||||
static Point2D calligraphy_PointOnCubicBezier(Point2D* cp, float t);
|
||||
static void calligraphy_ComputeBezier(Point2D* cp, int numberOfPoints, Point2D* curve);
|
||||
static Point2D calligraphy_PointOnCubicBezier(Point2D * cp, float t);
|
||||
static void calligraphy_ComputeBezier(Point2D * cp, int numberOfPoints, Point2D * curve);
|
||||
static float calligraphy_dist(float x1, float y1, float x2, float y2);
|
||||
int calligraphy_init(magic_api * api);
|
||||
Uint32 calligraphy_api_version(void);
|
||||
int calligraphy_get_tool_count(magic_api * api);
|
||||
SDL_Surface * calligraphy_get_icon(magic_api * api, int which);
|
||||
char * calligraphy_get_name(magic_api * api, int which);
|
||||
char * calligraphy_get_description(magic_api * api, int which, int mode);
|
||||
SDL_Surface *calligraphy_get_icon(magic_api * api, int which);
|
||||
char *calligraphy_get_name(magic_api * api, int which);
|
||||
char *calligraphy_get_description(magic_api * api, int which, int mode);
|
||||
void calligraphy_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
void calligraphy_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void calligraphy_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void calligraphy_shutdown(magic_api * api);
|
||||
void calligraphy_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
int calligraphy_requires_colors(magic_api * api, int which);
|
||||
|
|
@ -79,19 +76,17 @@ int calligraphy_init(magic_api * api)
|
|||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/calligraphy.ogg",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/calligraphy.ogg", api->data_directory);
|
||||
|
||||
calligraphy_snd = Mix_LoadWAV(fname);
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/calligraphy_brush.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/calligraphy_brush.png", api->data_directory);
|
||||
|
||||
calligraphy_brush = IMG_Load(fname);
|
||||
calligraphy_colored_brush = NULL;
|
||||
|
||||
if (calligraphy_brush == NULL)
|
||||
return(0);
|
||||
return (0);
|
||||
|
||||
calligraphy_last_time = 0;
|
||||
|
||||
|
|
@ -100,53 +95,54 @@ int calligraphy_init(magic_api * api)
|
|||
calligraphy_g = -1;
|
||||
calligraphy_b = -1;
|
||||
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
Uint32 calligraphy_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
Uint32 calligraphy_api_version(void)
|
||||
{
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
// Only one tool:
|
||||
int calligraphy_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
// Load our icon:
|
||||
SDL_Surface * calligraphy_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
SDL_Surface *calligraphy_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/calligraphy.png",
|
||||
api->data_directory);
|
||||
return(IMG_Load(fname));
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/calligraphy.png", api->data_directory);
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our name, localized:
|
||||
char * calligraphy_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
char *calligraphy_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(strdup(gettext_noop("Calligraphy")));
|
||||
return (strdup(gettext_noop("Calligraphy")));
|
||||
}
|
||||
|
||||
// Return our description, localized:
|
||||
char * calligraphy_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
||||
char *calligraphy_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
|
||||
int mode ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(strdup(
|
||||
gettext_noop("Click and drag the mouse around to draw in calligraphy.")));
|
||||
return (strdup(gettext_noop("Click and drag the mouse around to draw in calligraphy.")));
|
||||
}
|
||||
|
||||
|
||||
void calligraphy_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
|
||||
SDL_Surface * last ATTRIBUTE_UNUSED, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
SDL_Surface * last ATTRIBUTE_UNUSED, int ox, int oy, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
Point2D * curve;
|
||||
Point2D *curve;
|
||||
int i, n_points, thick, new_thick;
|
||||
Uint32 colr;
|
||||
SDL_Rect src, dest;
|
||||
|
||||
// if (SDL_GetTicks() < calligraphy_last_time + 5)
|
||||
// return;
|
||||
|
||||
|
||||
calligraphy_control_points[0].x = calligraphy_control_points[1].x;
|
||||
calligraphy_control_points[0].y = calligraphy_control_points[1].y;
|
||||
calligraphy_control_points[1].x = calligraphy_control_points[2].x;
|
||||
|
|
@ -170,82 +166,76 @@ void calligraphy_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface *
|
|||
*/
|
||||
|
||||
n_points = calligraphy_dist(calligraphy_control_points[0].x,
|
||||
calligraphy_control_points[0].y,
|
||||
calligraphy_control_points[1].x,
|
||||
calligraphy_control_points[1].y) +
|
||||
calligraphy_dist(calligraphy_control_points[1].x,
|
||||
calligraphy_control_points[1].y,
|
||||
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[0].y,
|
||||
calligraphy_control_points[1].x,
|
||||
calligraphy_control_points[1].y) +
|
||||
calligraphy_dist(calligraphy_control_points[1].x,
|
||||
calligraphy_control_points[1].y,
|
||||
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);
|
||||
|
||||
if (n_points == 0)
|
||||
return; // No-op; not any points to plot
|
||||
return; // No-op; not any points to plot
|
||||
|
||||
|
||||
curve = (Point2D *) malloc(sizeof(Point2D) * n_points);
|
||||
|
||||
calligraphy_ComputeBezier(calligraphy_control_points, n_points, curve);
|
||||
|
||||
colr = SDL_MapRGB(canvas->format,
|
||||
calligraphy_r,
|
||||
calligraphy_g,
|
||||
calligraphy_b);
|
||||
colr = SDL_MapRGB(canvas->format, calligraphy_r, calligraphy_g, calligraphy_b);
|
||||
|
||||
new_thick = 40 - min((n_points /* / 2 */), 32);
|
||||
new_thick = 40 - min((n_points /* / 2 */ ), 32);
|
||||
|
||||
for (i = 0; i < n_points - 1; i++)
|
||||
{
|
||||
thick = ((new_thick * i) +
|
||||
(calligraphy_old_thick * (n_points - i))) / n_points;
|
||||
|
||||
|
||||
/* The new way, using an antialiased brush bitmap */
|
||||
|
||||
x = curve[i].x;
|
||||
y = curve[i].y;
|
||||
|
||||
src.x = calligraphy_brush->w - thick / 2 - thick / 4;
|
||||
src.w = thick / 2 + thick / 4;
|
||||
src.y = 0;
|
||||
src.h = thick / 4;
|
||||
|
||||
dest.x = x - thick / 4;
|
||||
dest.y = y - thick / 4;
|
||||
|
||||
SDL_BlitSurface(calligraphy_colored_brush, &src, canvas, &dest);
|
||||
|
||||
|
||||
src.x = 0;
|
||||
src.w = thick / 2 + thick / 4;
|
||||
src.y = calligraphy_brush->h - thick / 4;
|
||||
src.h = thick / 4;
|
||||
|
||||
dest.x = x - thick / 2;
|
||||
dest.y = y;
|
||||
|
||||
SDL_BlitSurface(calligraphy_colored_brush, &src, canvas, &dest);
|
||||
|
||||
/* Old way; using putpixel:
|
||||
SDL_LockSurface(canvas);
|
||||
|
||||
for (j = -(thick / 2); j < (thick / 2) + 1; j++)
|
||||
{
|
||||
x = curve[i].x + j;
|
||||
y = curve[i].y - (j / 2); // 30 degrees
|
||||
thick = ((new_thick * i) + (calligraphy_old_thick * (n_points - i))) / n_points;
|
||||
|
||||
api->putpixel(canvas, x, y, colr);
|
||||
api->putpixel(canvas, x + 1, y, colr);
|
||||
api->putpixel(canvas, x, y + 1, colr);
|
||||
api->putpixel(canvas, x + 1, y + 1, colr);
|
||||
|
||||
/* The new way, using an antialiased brush bitmap */
|
||||
|
||||
x = curve[i].x;
|
||||
y = curve[i].y;
|
||||
|
||||
src.x = calligraphy_brush->w - thick / 2 - thick / 4;
|
||||
src.w = thick / 2 + thick / 4;
|
||||
src.y = 0;
|
||||
src.h = thick / 4;
|
||||
|
||||
dest.x = x - thick / 4;
|
||||
dest.y = y - thick / 4;
|
||||
|
||||
SDL_BlitSurface(calligraphy_colored_brush, &src, canvas, &dest);
|
||||
|
||||
|
||||
src.x = 0;
|
||||
src.w = thick / 2 + thick / 4;
|
||||
src.y = calligraphy_brush->h - thick / 4;
|
||||
src.h = thick / 4;
|
||||
|
||||
dest.x = x - thick / 2;
|
||||
dest.y = y;
|
||||
|
||||
SDL_BlitSurface(calligraphy_colored_brush, &src, canvas, &dest);
|
||||
|
||||
/* Old way; using putpixel:
|
||||
SDL_LockSurface(canvas);
|
||||
|
||||
for (j = -(thick / 2); j < (thick / 2) + 1; j++)
|
||||
{
|
||||
x = curve[i].x + j;
|
||||
y = curve[i].y - (j / 2); // 30 degrees
|
||||
|
||||
api->putpixel(canvas, x, y, colr);
|
||||
api->putpixel(canvas, x + 1, y, colr);
|
||||
api->putpixel(canvas, x, y + 1, colr);
|
||||
api->putpixel(canvas, x + 1, y + 1, colr);
|
||||
}
|
||||
|
||||
SDL_UnlockSurface(canvas);
|
||||
*/
|
||||
}
|
||||
|
||||
SDL_UnlockSurface(canvas);
|
||||
*/
|
||||
}
|
||||
|
||||
calligraphy_old_thick = (calligraphy_old_thick + new_thick) / 2;
|
||||
|
||||
|
|
@ -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;
|
||||
|
|
@ -272,8 +274,8 @@ void calligraphy_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface *
|
|||
}
|
||||
|
||||
void calligraphy_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)
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x, int y, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
calligraphy_old_thick = 8;
|
||||
calligraphy_last_time = 0;
|
||||
|
|
@ -290,8 +292,8 @@ void calligraphy_click(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNU
|
|||
|
||||
|
||||
void calligraphy_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)
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -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,30 +333,25 @@ 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!
|
||||
return; // FIXME: Error!
|
||||
|
||||
SDL_LockSurface(calligraphy_brush);
|
||||
SDL_LockSurface(calligraphy_colored_brush);
|
||||
|
||||
|
||||
for (y = 0; y < calligraphy_brush->h; y++)
|
||||
{
|
||||
for (x = 0; x < calligraphy_brush->w; x++)
|
||||
{
|
||||
SDL_GetRGBA(api->getpixel(calligraphy_brush, x, y),
|
||||
calligraphy_brush->format, &r, &g, &b, &a);
|
||||
for (x = 0; x < calligraphy_brush->w; x++)
|
||||
{
|
||||
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));
|
||||
api->putpixel(calligraphy_colored_brush, x, y,
|
||||
SDL_MapRGBA(calligraphy_colored_brush->format, calligraphy_r, calligraphy_g, calligraphy_b, a));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SDL_UnlockSurface(calligraphy_colored_brush);
|
||||
SDL_UnlockSurface(calligraphy_brush);
|
||||
|
|
@ -384,32 +377,32 @@ cp[3] is the end point, or P3 in the above diagram
|
|||
t is the parameter value, 0 <= t <= 1
|
||||
*/
|
||||
|
||||
static Point2D calligraphy_PointOnCubicBezier( Point2D* cp, float t )
|
||||
static Point2D calligraphy_PointOnCubicBezier(Point2D * cp, float t)
|
||||
{
|
||||
float ax, bx, cx;
|
||||
float ay, by, cy;
|
||||
float tSquared, tCubed;
|
||||
Point2D result;
|
||||
float ax, bx, cx;
|
||||
float ay, by, cy;
|
||||
float tSquared, tCubed;
|
||||
Point2D result;
|
||||
|
||||
/* calculate the polynomial coefficients */
|
||||
/* calculate the polynomial coefficients */
|
||||
|
||||
cx = 3.0 * (cp[1].x - cp[0].x);
|
||||
bx = 3.0 * (cp[2].x - cp[1].x) - cx;
|
||||
ax = cp[3].x - cp[0].x - cx - bx;
|
||||
cx = 3.0 * (cp[1].x - cp[0].x);
|
||||
bx = 3.0 * (cp[2].x - cp[1].x) - cx;
|
||||
ax = cp[3].x - cp[0].x - cx - bx;
|
||||
|
||||
cy = 3.0 * (cp[1].y - cp[0].y);
|
||||
by = 3.0 * (cp[2].y - cp[1].y) - cy;
|
||||
ay = cp[3].y - cp[0].y - cy - by;
|
||||
cy = 3.0 * (cp[1].y - cp[0].y);
|
||||
by = 3.0 * (cp[2].y - cp[1].y) - cy;
|
||||
ay = cp[3].y - cp[0].y - cy - by;
|
||||
|
||||
/* calculate the curve point at parameter value t */
|
||||
/* calculate the curve point at parameter value t */
|
||||
|
||||
tSquared = t * t;
|
||||
tCubed = tSquared * t;
|
||||
tSquared = t * t;
|
||||
tCubed = tSquared * t;
|
||||
|
||||
result.x = (ax * tCubed) + (bx * tSquared) + (cx * t) + cp[0].x;
|
||||
result.y = (ay * tCubed) + (by * tSquared) + (cy * t) + cp[0].y;
|
||||
result.x = (ax * tCubed) + (bx * tSquared) + (cx * t) + cp[0].x;
|
||||
result.y = (ay * tCubed) + (by * tSquared) + (cy * t) + cp[0].y;
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -420,34 +413,37 @@ static Point2D calligraphy_PointOnCubicBezier( Point2D* cp, float t )
|
|||
<sizeof(Point2D) numberOfPoints>
|
||||
*/
|
||||
|
||||
static void calligraphy_ComputeBezier(Point2D* cp, int numberOfPoints, Point2D* curve)
|
||||
static void calligraphy_ComputeBezier(Point2D * cp, int numberOfPoints, Point2D * curve)
|
||||
{
|
||||
float dt;
|
||||
int i;
|
||||
float dt;
|
||||
int i;
|
||||
|
||||
dt = 1.0 / ( numberOfPoints - 1 );
|
||||
dt = 1.0 / (numberOfPoints - 1);
|
||||
|
||||
for( i = 0; i < numberOfPoints; i++)
|
||||
curve[i] = calligraphy_PointOnCubicBezier( cp, i*dt );
|
||||
for (i = 0; i < numberOfPoints; i++)
|
||||
curve[i] = calligraphy_PointOnCubicBezier(cp, i * dt);
|
||||
}
|
||||
|
||||
static float calligraphy_dist(float x1, float y1, float x2, float y2)
|
||||
{
|
||||
float d;
|
||||
|
||||
d = (sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)));
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
void calligraphy_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void calligraphy_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void calligraphy_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void calligraphy_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
int calligraphy_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_PAINT);
|
||||
return (MODE_PAINT);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@
|
|||
|
||||
/* Our globals: */
|
||||
|
||||
static Mix_Chunk * cartoon_snd;
|
||||
static Mix_Chunk *cartoon_snd;
|
||||
|
||||
#define OUTLINE_THRESH 48
|
||||
|
||||
|
|
@ -46,20 +46,16 @@ static Mix_Chunk * cartoon_snd;
|
|||
int cartoon_init(magic_api * api);
|
||||
Uint32 cartoon_api_version(void);
|
||||
int cartoon_get_tool_count(magic_api * api);
|
||||
SDL_Surface * cartoon_get_icon(magic_api * api, int which);
|
||||
char * cartoon_get_name(magic_api * api, int which);
|
||||
char * cartoon_get_description(magic_api * api, int which, int mode);
|
||||
static void do_cartoon(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y);
|
||||
SDL_Surface *cartoon_get_icon(magic_api * api, int which);
|
||||
char *cartoon_get_name(magic_api * api, int which);
|
||||
char *cartoon_get_description(magic_api * api, int which, int mode);
|
||||
static void do_cartoon(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||
void cartoon_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
void cartoon_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void cartoon_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void cartoon_shutdown(magic_api * api);
|
||||
void cartoon_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
int cartoon_requires_colors(magic_api * api, int which);
|
||||
|
|
@ -74,51 +70,50 @@ int cartoon_init(magic_api * api)
|
|||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/cartoon.wav",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/cartoon.wav", api->data_directory);
|
||||
cartoon_snd = Mix_LoadWAV(fname);
|
||||
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
Uint32 cartoon_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
Uint32 cartoon_api_version(void)
|
||||
{
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
// We have multiple tools:
|
||||
int cartoon_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
// Load our icons:
|
||||
SDL_Surface * cartoon_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
SDL_Surface *cartoon_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/cartoon.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/cartoon.png", api->data_directory);
|
||||
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our names, localized:
|
||||
char * cartoon_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
char *cartoon_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(strdup(gettext_noop("Cartoon")));
|
||||
return (strdup(gettext_noop("Cartoon")));
|
||||
}
|
||||
|
||||
// Return our descriptions, localized:
|
||||
char * cartoon_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
||||
char *cartoon_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(strdup(gettext_noop(
|
||||
"Click and drag the mouse around to turn the picture into a cartoon.")));
|
||||
return (strdup(gettext_noop("Click and drag the mouse around to turn the picture into a cartoon.")));
|
||||
}
|
||||
|
||||
// Do the effect:
|
||||
|
||||
static void do_cartoon(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y)
|
||||
static void do_cartoon(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
int xx, yy;
|
||||
Uint8 r1, g1, b1, r2, g2, b2;
|
||||
Uint8 r, g, b;
|
||||
|
|
@ -127,86 +122,90 @@ static void do_cartoon(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * can
|
|||
/* First, convert colors to more cartoony ones: */
|
||||
|
||||
for (yy = y - 16; yy < y + 16; yy = yy + 1)
|
||||
{
|
||||
for (xx = x - 16; xx < x + 16; xx = xx + 1)
|
||||
{
|
||||
if (api->in_circle(xx - x, yy - y, 16))
|
||||
{
|
||||
/* Get original color: */
|
||||
for (xx = x - 16; xx < x + 16; xx = xx + 1)
|
||||
{
|
||||
if (api->in_circle(xx - x, yy - y, 16))
|
||||
{
|
||||
/* Get original color: */
|
||||
|
||||
SDL_GetRGB(api->getpixel(last, xx, yy), last->format, &r, &g, &b);
|
||||
SDL_GetRGB(api->getpixel(last, xx, yy), last->format, &r, &g, &b);
|
||||
|
||||
api->rgbtohsv(r, g, b, &hue, &sat, &val);
|
||||
api->rgbtohsv(r, g, b, &hue, &sat, &val);
|
||||
|
||||
val = val - 0.5;
|
||||
val = val * 4;
|
||||
val = val + 0.5;
|
||||
val = val - 0.5;
|
||||
val = val * 4;
|
||||
val = val + 0.5;
|
||||
|
||||
if (val < 0)
|
||||
val = 0;
|
||||
else if (val > 1.0)
|
||||
val = 1.0;
|
||||
if (val < 0)
|
||||
val = 0;
|
||||
else if (val > 1.0)
|
||||
val = 1.0;
|
||||
|
||||
val = floor(val * 4) / 4;
|
||||
hue = floor(hue * 4) / 4;
|
||||
val = floor(val * 4) / 4;
|
||||
hue = floor(hue * 4) / 4;
|
||||
|
||||
sat = floor(sat * 4) / 4;
|
||||
sat = floor(sat * 4) / 4;
|
||||
|
||||
api->hsvtorgb(hue, sat, val, &r, &g, &b);
|
||||
api->hsvtorgb(hue, sat, val, &r, &g, &b);
|
||||
|
||||
api->putpixel(canvas, xx, yy, SDL_MapRGB(canvas->format, r, g, b));
|
||||
}
|
||||
api->putpixel(canvas, xx, yy, SDL_MapRGB(canvas->format, r, g, b));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Then, draw dark outlines where there's a large contrast change */
|
||||
|
||||
for (yy = y - 16; yy < y + 16; yy++)
|
||||
{
|
||||
for (xx = x - 16; xx < x + 16; xx++)
|
||||
{
|
||||
if (api->in_circle(xx - x, yy - y, 16))
|
||||
{
|
||||
/* Get original color: */
|
||||
|
||||
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 + 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)
|
||||
for (xx = x - 16; xx < x + 16; xx++)
|
||||
{
|
||||
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));
|
||||
if (api->in_circle(xx - x, yy - y, 16))
|
||||
{
|
||||
/* Get original color: */
|
||||
|
||||
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 + 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)
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Affect the canvas on drag:
|
||||
void cartoon_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_cartoon);
|
||||
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_cartoon);
|
||||
|
||||
if (ox > x) { int tmp = ox; ox = x; x = tmp; }
|
||||
if (oy > y) { int tmp = oy; oy = y; y = tmp; }
|
||||
if (ox > x)
|
||||
{
|
||||
int tmp = ox;
|
||||
|
||||
ox = x;
|
||||
x = tmp;
|
||||
}
|
||||
if (oy > y)
|
||||
{
|
||||
int tmp = oy;
|
||||
|
||||
oy = y;
|
||||
y = tmp;
|
||||
}
|
||||
|
||||
update_rect->x = ox - 16;
|
||||
update_rect->y = oy - 16;
|
||||
|
|
@ -218,16 +217,15 @@ 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);
|
||||
}
|
||||
|
||||
// Affect the canvas on release:
|
||||
void cartoon_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)
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -239,7 +237,8 @@ void cartoon_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
|||
}
|
||||
|
||||
// Record the color from Tux Paint:
|
||||
void cartoon_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
|
||||
void cartoon_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
|
||||
Uint8 b ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -249,15 +248,17 @@ int cartoon_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUT
|
|||
return 0;
|
||||
}
|
||||
|
||||
void cartoon_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void cartoon_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void cartoon_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void cartoon_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
int cartoon_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_PAINT); /* FIXME - Can also be turned into a full-image effect */
|
||||
return (MODE_PAINT); /* FIXME - Can also be turned into a full-image effect */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,70 +1,67 @@
|
|||
#include <time.h> //For time()
|
||||
#include <time.h> //For time()
|
||||
|
||||
#include "tp_magic_api.h"
|
||||
#include "SDL_image.h"
|
||||
#include "SDL_mixer.h"
|
||||
|
||||
#define CONFETTI_BRUSH_SIZE 8 //radius of each confetti circle
|
||||
#define CONFETTI_QUANTITY 3 //how many circles will be created every click?
|
||||
#define CONFETTI_BRUSH_SIZE 8 //radius of each confetti circle
|
||||
#define CONFETTI_QUANTITY 3 //how many circles will be created every click?
|
||||
|
||||
struct confetti_rgb
|
||||
{
|
||||
Uint8 r, g, b;
|
||||
Uint8 r, g, b;
|
||||
};
|
||||
|
||||
struct confetti_rgb confetti_colors; //storage for colors, just for having everything in one place
|
||||
struct confetti_rgb confetti_colors; //storage for colors, just for having everything in one place
|
||||
|
||||
Mix_Chunk * confetti_snd;
|
||||
Mix_Chunk *confetti_snd;
|
||||
|
||||
/* Local function prototypes: */
|
||||
Uint32 confetti_api_version(void);
|
||||
void confetti_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
int confetti_init(magic_api * api);
|
||||
int confetti_get_tool_count(magic_api * api);
|
||||
SDL_Surface * confetti_get_icon(magic_api * api, int which);
|
||||
char * confetti_get_name(magic_api * api, int which);
|
||||
char * confetti_get_description(magic_api * api, int which, int mode);
|
||||
SDL_Surface *confetti_get_icon(magic_api * api, int which);
|
||||
char *confetti_get_name(magic_api * api, int which);
|
||||
char *confetti_get_description(magic_api * api, int which, int mode);
|
||||
int confetti_requires_colors(magic_api * api, int which);
|
||||
void confetti_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
|
||||
void confetti_shutdown(magic_api * api);
|
||||
inline char confetti_get_greater(const char what1, const char what2);
|
||||
inline char confetti_get_lesser(const char what1, const char what2);
|
||||
Uint32 confetti_get_new_color(void * ptr, SDL_Surface * canvas);
|
||||
Uint32 confetti_get_new_color(void *ptr, SDL_Surface * canvas);
|
||||
void confetti_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void confetti_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
void confetti_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
int confetti_modes(magic_api * api, int which);
|
||||
|
||||
// Housekeeping functions
|
||||
// Housekeeping functions
|
||||
|
||||
void confetti_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
|
||||
Uint32 confetti_api_version(void)
|
||||
{
|
||||
return(TP_MAGIC_API_VERSION);
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
void confetti_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b) //get the colors from API and store it in structure
|
||||
void confetti_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b) //get the colors from API and store it in structure
|
||||
{
|
||||
confetti_colors.r=r;
|
||||
confetti_colors.g=g;
|
||||
confetti_colors.b=b;
|
||||
confetti_colors.r = r;
|
||||
confetti_colors.g = g;
|
||||
confetti_colors.b = b;
|
||||
}
|
||||
|
||||
int confetti_init(magic_api * api)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/confetti.ogg", api->data_directory);
|
||||
confetti_snd = Mix_LoadWAV(fname);
|
||||
|
||||
return(1);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/confetti.ogg", api->data_directory);
|
||||
confetti_snd = Mix_LoadWAV(fname);
|
||||
|
||||
return (1);
|
||||
}
|
||||
|
||||
int confetti_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
|
|
@ -72,137 +69,168 @@ int confetti_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
|||
return 1;
|
||||
}
|
||||
|
||||
SDL_Surface * confetti_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
SDL_Surface *confetti_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/confetti.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/confetti.png", api->data_directory);
|
||||
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
char * confetti_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) { return strdup(gettext_noop("Confetti")); }
|
||||
char *confetti_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return strdup(gettext_noop("Confetti"));
|
||||
}
|
||||
|
||||
char * confetti_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED) { return strdup(gettext_noop("Click to throw confetti!")); }
|
||||
char *confetti_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return strdup(gettext_noop("Click to throw confetti!"));
|
||||
}
|
||||
|
||||
int confetti_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) { return 1; }
|
||||
int confetti_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void confetti_release(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * snapshot ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect 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)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
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_lesser(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;
|
||||
}
|
||||
|
||||
// Interactivity functions
|
||||
|
||||
Uint32 confetti_get_new_color(void * ptr, SDL_Surface * canvas) //this function creates new color very similar to the one choosen
|
||||
Uint32 confetti_get_new_color(void *ptr, SDL_Surface * canvas) //this function creates new color very similar to the one choosen
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
|
||||
float hsv_h, hsv_s, hsv_v;
|
||||
Uint8 temp_r, temp_g, temp_b;
|
||||
|
||||
api->rgbtohsv(confetti_colors.r, confetti_colors.g, confetti_colors.b, &hsv_h, &hsv_s, &hsv_v); //color choosen by user is converted
|
||||
//to HSV palette
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
|
||||
hsv_h+=((rand()%60)-30)%360; //Every circle has different, but
|
||||
//smilar color
|
||||
if (hsv_h<0)
|
||||
hsv_h *= -1;
|
||||
|
||||
api->hsvtorgb(hsv_h, hsv_s, hsv_v, &temp_r, &temp_g, &temp_b); //...and come back to RGB
|
||||
float hsv_h, hsv_s, hsv_v;
|
||||
Uint8 temp_r, temp_g, temp_b;
|
||||
|
||||
return SDL_MapRGB(canvas->format, temp_r, temp_g, temp_b);
|
||||
api->rgbtohsv(confetti_colors.r, confetti_colors.g, confetti_colors.b, &hsv_h, &hsv_s, &hsv_v); //color choosen by user is converted
|
||||
//to HSV palette
|
||||
|
||||
hsv_h += ((rand() % 60) - 30) % 360; //Every circle has different, but
|
||||
//smilar color
|
||||
if (hsv_h < 0)
|
||||
hsv_h *= -1;
|
||||
|
||||
api->hsvtorgb(hsv_h, hsv_s, hsv_v, &temp_r, &temp_g, &temp_b); //...and come back to RGB
|
||||
|
||||
return SDL_MapRGB(canvas->format, temp_r, temp_g, temp_b);
|
||||
}
|
||||
|
||||
|
||||
static void confetti_circle(void * ptr, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x, int y)
|
||||
|
||||
|
||||
static void confetti_circle(void *ptr, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
|
||||
int xx, yy;
|
||||
Uint32 color=confetti_get_new_color(api, canvas);
|
||||
|
||||
for (yy = y - CONFETTI_BRUSH_SIZE/2; yy < y + CONFETTI_BRUSH_SIZE/2; yy++)
|
||||
|
||||
for (xx = x - CONFETTI_BRUSH_SIZE/2; xx < x + CONFETTI_BRUSH_SIZE/2; xx++)
|
||||
|
||||
if (api->in_circle(xx - x , yy - y , CONFETTI_BRUSH_SIZE/2))
|
||||
api->putpixel(canvas, xx, yy, color);
|
||||
Uint32 color = confetti_get_new_color(api, canvas);
|
||||
|
||||
for (yy = y - CONFETTI_BRUSH_SIZE / 2; yy < y + CONFETTI_BRUSH_SIZE / 2; yy++)
|
||||
|
||||
for (xx = x - CONFETTI_BRUSH_SIZE / 2; xx < x + CONFETTI_BRUSH_SIZE / 2; xx++)
|
||||
|
||||
if (api->in_circle(xx - x, yy - y, CONFETTI_BRUSH_SIZE / 2))
|
||||
api->putpixel(canvas, xx, yy, color);
|
||||
}
|
||||
|
||||
void confetti_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect)
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
unsigned char i;
|
||||
char min_x = 0, max_x = 0, min_y = 0, max_y = 0;
|
||||
char dx = 0, dy = 0;
|
||||
|
||||
for (i=0; i<CONFETTI_QUANTITY; i++)
|
||||
{
|
||||
srand((dx+dy)/2 + time(0)); //to get a unique seed even if dx and dy aren't defined
|
||||
dx=(rand()%100)-50; //generate a value between <-50; +50>
|
||||
dy=(rand()%100)-50; //to spread confetti around the cursor position
|
||||
|
||||
if (!i)
|
||||
{
|
||||
min_x=max_x=dx;
|
||||
min_y=max_y=dy;
|
||||
}
|
||||
else
|
||||
{
|
||||
min_x=confetti_get_lesser(min_x, dx); //any candidates to new min/max values? Hands up please...
|
||||
max_x=confetti_get_greater(max_x, dx);
|
||||
min_y=confetti_get_lesser(min_y, dy);
|
||||
max_y=confetti_get_greater(max_y, dy);
|
||||
}
|
||||
confetti_circle((void *)api, which, canvas, last, x+dx, y+dy);
|
||||
}
|
||||
unsigned char i;
|
||||
char min_x = 0, max_x = 0, min_y = 0, max_y = 0;
|
||||
char dx = 0, dy = 0;
|
||||
|
||||
update_rect->x = x+min_x - CONFETTI_BRUSH_SIZE/2;
|
||||
update_rect->y = y+ min_y - CONFETTI_BRUSH_SIZE/2;
|
||||
update_rect->w = CONFETTI_BRUSH_SIZE*1.5+max_x-min_x;
|
||||
update_rect->h = CONFETTI_BRUSH_SIZE*1.5+max_y-min_y;
|
||||
|
||||
api->playsound(confetti_snd, (x * 255) / canvas->w,255);
|
||||
for (i = 0; i < CONFETTI_QUANTITY; i++)
|
||||
{
|
||||
srand((dx + dy) / 2 + time(0)); //to get a unique seed even if dx and dy aren't defined
|
||||
dx = (rand() % 100) - 50; //generate a value between <-50; +50>
|
||||
dy = (rand() % 100) - 50; //to spread confetti around the cursor position
|
||||
|
||||
if (!i)
|
||||
{
|
||||
min_x = max_x = dx;
|
||||
min_y = max_y = dy;
|
||||
}
|
||||
else
|
||||
{
|
||||
min_x = confetti_get_lesser(min_x, dx); //any candidates to new min/max values? Hands up please...
|
||||
max_x = confetti_get_greater(max_x, dx);
|
||||
min_y = confetti_get_lesser(min_y, dy);
|
||||
max_y = confetti_get_greater(max_y, dy);
|
||||
}
|
||||
confetti_circle((void *)api, which, canvas, last, x + dx, y + dy);
|
||||
}
|
||||
|
||||
update_rect->x = x + min_x - CONFETTI_BRUSH_SIZE / 2;
|
||||
update_rect->y = y + min_y - CONFETTI_BRUSH_SIZE / 2;
|
||||
update_rect->w = CONFETTI_BRUSH_SIZE * 1.5 + max_x - min_x;
|
||||
update_rect->h = CONFETTI_BRUSH_SIZE * 1.5 + max_y - min_y;
|
||||
|
||||
api->playsound(confetti_snd, (x * 255) / canvas->w, 255);
|
||||
}
|
||||
|
||||
void confetti_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
int temp;
|
||||
|
||||
if (ox>x) {temp=x; x=ox; ox=temp;}
|
||||
if (oy>y) {temp=y; y=oy; oy=temp; }
|
||||
|
||||
confetti_click(api, which, MODE_PAINT, canvas, snapshot, x, y, update_rect);
|
||||
int temp;
|
||||
|
||||
if (ox > x)
|
||||
{
|
||||
temp = x;
|
||||
x = ox;
|
||||
ox = temp;
|
||||
}
|
||||
if (oy > y)
|
||||
{
|
||||
temp = y;
|
||||
y = oy;
|
||||
oy = temp;
|
||||
}
|
||||
|
||||
confetti_click(api, which, MODE_PAINT, canvas, snapshot, x, y, update_rect);
|
||||
}
|
||||
|
||||
void confetti_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void confetti_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void confetti_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void confetti_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
int confetti_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_PAINT);
|
||||
return (MODE_PAINT);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,11 +31,11 @@
|
|||
/* -------------------------- */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h> // For "strdup()"
|
||||
#include <string.h> // For "strdup()"
|
||||
|
||||
#include "tp_magic_api.h" // Tux Paint "Magic" tool API header
|
||||
#include "SDL_image.h" // For IMG_Load(), to load our PNG icon
|
||||
#include "SDL_mixer.h" // For Mix_LoadWAV(), to load our sound effects
|
||||
#include "tp_magic_api.h" // Tux Paint "Magic" tool API header
|
||||
#include "SDL_image.h" // For IMG_Load(), to load our PNG icon
|
||||
#include "SDL_mixer.h" // For Mix_LoadWAV(), to load our sound effects
|
||||
|
||||
|
||||
|
||||
|
|
@ -43,7 +43,7 @@
|
|||
/* --------------------- */
|
||||
|
||||
/* Sound effects: */
|
||||
static Mix_Chunk * snd_effect;
|
||||
static Mix_Chunk *snd_effect;
|
||||
|
||||
|
||||
/* Our local function prototypes: */
|
||||
|
|
@ -57,18 +57,16 @@ static Mix_Chunk * snd_effect;
|
|||
Uint32 distortion_api_version(void);
|
||||
int distortion_init(magic_api * api);
|
||||
int distortion_get_tool_count(magic_api * api);
|
||||
SDL_Surface * distortion_get_icon(magic_api * api, int which);
|
||||
char * distortion_get_name(magic_api * api, int which);
|
||||
char * distortion_get_description(magic_api * api, int which, int mode);
|
||||
SDL_Surface *distortion_get_icon(magic_api * api, int which);
|
||||
char *distortion_get_name(magic_api * api, int which);
|
||||
char *distortion_get_description(magic_api * api, int which, int mode);
|
||||
int distortion_requires_colors(magic_api * api, int which);
|
||||
void distortion_shutdown(magic_api * api);
|
||||
|
||||
void distortion_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
|
||||
void distortion_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
|
||||
|
||||
void distortion_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
void distortion_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
|
|
@ -76,12 +74,9 @@ void distortion_switchout(magic_api * api, int which, int mode, SDL_Surface * ca
|
|||
int distortion_modes(magic_api * api, int which);
|
||||
|
||||
void distortion_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
|
||||
static void distortion_line_callback(void * ptr, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y);
|
||||
static void distortion_line_callback(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
|
||||
|
||||
|
||||
/* Setup Functions: */
|
||||
|
|
@ -89,7 +84,7 @@ static void distortion_line_callback(void * ptr, int which,
|
|||
|
||||
Uint32 distortion_api_version(void)
|
||||
{
|
||||
return(TP_MAGIC_API_VERSION);
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -99,15 +94,13 @@ int distortion_init(magic_api * api)
|
|||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname),
|
||||
"%s/sounds/magic/distortion.ogg",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/distortion.ogg", api->data_directory);
|
||||
|
||||
// Try to load the file!
|
||||
|
||||
snd_effect = Mix_LoadWAV(fname);
|
||||
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -115,39 +108,39 @@ int distortion_init(magic_api * api)
|
|||
|
||||
int distortion_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
|
||||
// Load icons
|
||||
|
||||
SDL_Surface * distortion_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
SDL_Surface *distortion_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/distortion.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/distortion.png", api->data_directory);
|
||||
|
||||
|
||||
// Try to load the image, and return the results to Tux Paint:
|
||||
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
|
||||
// Report our "Magic" tool names
|
||||
|
||||
char * distortion_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
char *distortion_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(strdup(gettext_noop("Distortion")));
|
||||
return (strdup(gettext_noop("Distortion")));
|
||||
}
|
||||
|
||||
|
||||
// Report our "Magic" tool descriptions
|
||||
|
||||
char * distortion_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
||||
char *distortion_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
|
||||
int mode ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(strdup(gettext_noop("Click and drag the mouse to cause distortion in your picture.")));
|
||||
return (strdup(gettext_noop("Click and drag the mouse to cause distortion in your picture.")));
|
||||
}
|
||||
|
||||
// Report whether we accept colors
|
||||
|
|
@ -172,8 +165,7 @@ void distortion_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
|||
// Affect the canvas on click:
|
||||
|
||||
void distortion_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect)
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
distortion_drag(api, which, canvas, snapshot, x, y, x, y, update_rect);
|
||||
}
|
||||
|
|
@ -182,15 +174,25 @@ void distortion_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
|
|||
// Affect the canvas on drag:
|
||||
|
||||
void distortion_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
api->line((void *) api, which, canvas, snapshot,
|
||||
ox, oy, x, y, 1, distortion_line_callback);
|
||||
api->line((void *)api, which, canvas, snapshot, ox, oy, x, y, 1, distortion_line_callback);
|
||||
|
||||
|
||||
if (ox > x) { int tmp = ox; ox = x; x = tmp; }
|
||||
if (oy > y) { int tmp = oy; oy = y; y = tmp; }
|
||||
if (ox > x)
|
||||
{
|
||||
int tmp = ox;
|
||||
|
||||
ox = x;
|
||||
x = tmp;
|
||||
}
|
||||
if (oy > y)
|
||||
{
|
||||
int tmp = oy;
|
||||
|
||||
oy = y;
|
||||
y = tmp;
|
||||
}
|
||||
|
||||
|
||||
update_rect->x = ox - 8;
|
||||
|
|
@ -199,33 +201,32 @@ 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
|
||||
255); // distance
|
||||
api->playsound(snd_effect, (x * 255) / canvas->w, // pan
|
||||
255); // distance
|
||||
}
|
||||
|
||||
|
||||
// Affect the canvas on release:
|
||||
|
||||
void distortion_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)
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * snapshot ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void distortion_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
|
||||
void distortion_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
|
||||
Uint8 b ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// Our "callback" function
|
||||
|
||||
static void distortion_line_callback(void * ptr, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y)
|
||||
static void distortion_line_callback(void *ptr, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y)
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
int xx, yy;
|
||||
|
||||
|
||||
|
|
@ -234,28 +235,28 @@ static void distortion_line_callback(void * ptr, int which ATTRIBUTE_UNUSED,
|
|||
// Tux Paint sends to us with the values we enumerated above.
|
||||
|
||||
for (yy = -8; yy < 8; yy++)
|
||||
{
|
||||
for (xx = -8; xx < 8; xx++)
|
||||
{
|
||||
if (api->in_circle(xx, yy, 8))
|
||||
{
|
||||
api->putpixel(canvas, x + xx, y + yy,
|
||||
api->getpixel(snapshot,
|
||||
x + xx / 2, y + yy));
|
||||
}
|
||||
for (xx = -8; xx < 8; xx++)
|
||||
{
|
||||
if (api->in_circle(xx, yy, 8))
|
||||
{
|
||||
api->putpixel(canvas, x + xx, y + yy, api->getpixel(snapshot, x + xx / 2, y + yy));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void distortion_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void distortion_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void distortion_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void distortion_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
int distortion_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_PAINT);
|
||||
return (MODE_PAINT);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,27 +35,24 @@
|
|||
|
||||
/* Our globals: */
|
||||
|
||||
static Mix_Chunk * emboss_snd;
|
||||
static Mix_Chunk *emboss_snd;
|
||||
|
||||
// Prototypes
|
||||
Uint32 emboss_api_version(void);
|
||||
int emboss_init(magic_api * api);
|
||||
int emboss_get_tool_count(magic_api * api);
|
||||
SDL_Surface * emboss_get_icon(magic_api * api, int which);
|
||||
char * emboss_get_name(magic_api * api, int which);
|
||||
char * emboss_get_description(magic_api * api, int which, int mode);
|
||||
SDL_Surface *emboss_get_icon(magic_api * api, int which);
|
||||
char *emboss_get_name(magic_api * api, int which);
|
||||
char *emboss_get_description(magic_api * api, int which, int mode);
|
||||
|
||||
void emboss_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
|
||||
void emboss_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
|
||||
void emboss_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
|
||||
void emboss_shutdown(magic_api * api);
|
||||
void emboss_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
|
|
@ -65,7 +62,10 @@ void emboss_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas
|
|||
int emboss_modes(magic_api * api, int which);
|
||||
|
||||
|
||||
Uint32 emboss_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
Uint32 emboss_api_version(void)
|
||||
{
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
|
||||
// No setup required:
|
||||
|
|
@ -73,118 +73,125 @@ int emboss_init(magic_api * api)
|
|||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/emboss.ogg",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/emboss.ogg", api->data_directory);
|
||||
emboss_snd = Mix_LoadWAV(fname);
|
||||
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
// We have multiple tools:
|
||||
int emboss_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
// Load our icons:
|
||||
SDL_Surface * emboss_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
SDL_Surface *emboss_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/emboss.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/emboss.png", api->data_directory);
|
||||
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our names, localized:
|
||||
char * emboss_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
char *emboss_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(strdup(gettext_noop("Emboss")));
|
||||
return (strdup(gettext_noop("Emboss")));
|
||||
}
|
||||
|
||||
// Return our descriptions, localized:
|
||||
char * emboss_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
||||
char *emboss_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(strdup(gettext_noop("Click and drag the mouse to emboss the picture.")));
|
||||
return (strdup(gettext_noop("Click and drag the mouse to emboss the picture.")));
|
||||
}
|
||||
|
||||
// Do the effect:
|
||||
|
||||
static void do_emboss(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y)
|
||||
static void do_emboss(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
int xx, yy;
|
||||
Uint8 r1, g1, b1,
|
||||
r2, g2, b2;
|
||||
Uint8 r1, g1, b1, r2, g2, b2;
|
||||
int r, g, b;
|
||||
float h, s, v;
|
||||
int avg1, avg2;
|
||||
|
||||
for (yy = -16; yy < 16; yy++)
|
||||
{
|
||||
for (xx = -16; xx < 16; xx++)
|
||||
{
|
||||
if (api->in_circle(xx, yy, 16))
|
||||
{
|
||||
if (!api->touched(x + xx, y + yy))
|
||||
for (xx = -16; xx < 16; xx++)
|
||||
{
|
||||
SDL_GetRGB(api->getpixel(last, x + xx, y + yy), last->format, &r1, &g1, &b1);
|
||||
SDL_GetRGB(api->getpixel(last, x + xx + 2, y + yy + 2), last->format, &r2, &g2, &b2);
|
||||
if (api->in_circle(xx, yy, 16))
|
||||
{
|
||||
if (!api->touched(x + xx, y + yy))
|
||||
{
|
||||
SDL_GetRGB(api->getpixel(last, x + xx, y + yy), last->format, &r1, &g1, &b1);
|
||||
SDL_GetRGB(api->getpixel(last, x + xx + 2, y + yy + 2), last->format, &r2, &g2, &b2);
|
||||
|
||||
avg1 = (r1 + g1 + b1) / 3;
|
||||
avg2 = (r2 + g2 + b2) / 3;
|
||||
avg1 = (r1 + g1 + b1) / 3;
|
||||
avg2 = (r2 + g2 + b2) / 3;
|
||||
|
||||
api->rgbtohsv(r1, g1, b1, &h, &s, &v);
|
||||
api->rgbtohsv(r1, g1, b1, &h, &s, &v);
|
||||
|
||||
r = 128 + (((avg1 - avg2) * 3) / 2);
|
||||
if (r < 0) r = 0;
|
||||
if (r > 255) r = 255;
|
||||
g = b = r;
|
||||
r = 128 + (((avg1 - avg2) * 3) / 2);
|
||||
if (r < 0)
|
||||
r = 0;
|
||||
if (r > 255)
|
||||
r = 255;
|
||||
g = b = r;
|
||||
|
||||
v = (r / 255.0);
|
||||
v = (r / 255.0);
|
||||
|
||||
api->hsvtorgb(h, s, v, &r1, &g1, &b1);
|
||||
api->hsvtorgb(h, s, v, &r1, &g1, &b1);
|
||||
|
||||
api->putpixel(canvas, x + xx, y + yy, SDL_MapRGB(canvas->format, r1, g1, b1));
|
||||
api->putpixel(canvas, x + xx, y + yy, SDL_MapRGB(canvas->format, r1, g1, b1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Affect the canvas on drag:
|
||||
void emboss_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_emboss);
|
||||
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_emboss);
|
||||
|
||||
if (ox > x) { int tmp = ox; ox = x; x = tmp; }
|
||||
if (oy > y) { int tmp = oy; oy = y; y = tmp; }
|
||||
if (ox > x)
|
||||
{
|
||||
int tmp = ox;
|
||||
|
||||
ox = x;
|
||||
x = tmp;
|
||||
}
|
||||
if (oy > y)
|
||||
{
|
||||
int tmp = oy;
|
||||
|
||||
oy = y;
|
||||
y = tmp;
|
||||
}
|
||||
|
||||
update_rect->x = ox - 16;
|
||||
update_rect->y = oy - 16;
|
||||
update_rect->w = (x + 16) - update_rect->x;
|
||||
update_rect->h = (y + 16) - update_rect->h;
|
||||
|
||||
api->playsound(emboss_snd,
|
||||
(x * 255) / canvas->w, 255);
|
||||
api->playsound(emboss_snd, (x * 255) / canvas->w, 255);
|
||||
}
|
||||
|
||||
// Affect the canvas on click:
|
||||
void emboss_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect)
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
emboss_drag(api, which, canvas, last, x, y, x, y, update_rect);
|
||||
}
|
||||
|
||||
// Affect the canvas on release:
|
||||
void emboss_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)
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -196,7 +203,8 @@ void emboss_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
|||
}
|
||||
|
||||
// Record the color from Tux Paint:
|
||||
void emboss_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
|
||||
void emboss_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
|
||||
Uint8 b ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -206,15 +214,17 @@ int emboss_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE
|
|||
return 0;
|
||||
}
|
||||
|
||||
void emboss_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void emboss_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void emboss_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void emboss_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
int emboss_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_PAINT); /* FIXME - Can also be turned into a full-image effect */
|
||||
return (MODE_PAINT); /* FIXME - Can also be turned into a full-image effect */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,13 +33,14 @@
|
|||
#include "SDL_image.h"
|
||||
#include "SDL_mixer.h"
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
TOOL_FADE,
|
||||
TOOL_DARKEN,
|
||||
NUM_TOOLS
|
||||
};
|
||||
|
||||
static Mix_Chunk * snd_effects[NUM_TOOLS];
|
||||
static Mix_Chunk *snd_effects[NUM_TOOLS];
|
||||
|
||||
|
||||
/* Local function prototypes: */
|
||||
|
|
@ -47,24 +48,17 @@ static Mix_Chunk * snd_effects[NUM_TOOLS];
|
|||
int fade_darken_init(magic_api * api);
|
||||
Uint32 fade_darken_api_version(void);
|
||||
int fade_darken_get_tool_count(magic_api * api);
|
||||
SDL_Surface * fade_darken_get_icon(magic_api * api, int which);
|
||||
char * fade_darken_get_name(magic_api * api, int which);
|
||||
char * fade_darken_get_description(magic_api * api, int which, int mode);
|
||||
static void do_fade_darken(void * ptr, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y);
|
||||
static void do_fade_darken_paint(void * ptr, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y);
|
||||
SDL_Surface *fade_darken_get_icon(magic_api * api, int which);
|
||||
char *fade_darken_get_name(magic_api * api, int which);
|
||||
char *fade_darken_get_description(magic_api * api, int which, int mode);
|
||||
static void do_fade_darken(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||
static void do_fade_darken_paint(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||
void fade_darken_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
void fade_darken_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void fade_darken_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void fade_darken_shutdown(magic_api * api);
|
||||
void fade_darken_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
int fade_darken_requires_colors(magic_api * api, int which);
|
||||
|
|
@ -76,139 +70,144 @@ int fade_darken_init(magic_api * api)
|
|||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/fade.wav",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/fade.wav", api->data_directory);
|
||||
snd_effects[TOOL_FADE] = Mix_LoadWAV(fname);
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/darken.wav",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/darken.wav", api->data_directory);
|
||||
snd_effects[TOOL_DARKEN] = Mix_LoadWAV(fname);
|
||||
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
Uint32 fade_darken_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
Uint32 fade_darken_api_version(void)
|
||||
{
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
// Multiple tools:
|
||||
int fade_darken_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(NUM_TOOLS);
|
||||
return (NUM_TOOLS);
|
||||
}
|
||||
|
||||
// Load our icon:
|
||||
SDL_Surface * fade_darken_get_icon(magic_api * api, int which)
|
||||
SDL_Surface *fade_darken_get_icon(magic_api * api, int which)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
if (which == TOOL_FADE)
|
||||
{
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/fade.png",
|
||||
api->data_directory);
|
||||
}
|
||||
{
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/fade.png", api->data_directory);
|
||||
}
|
||||
else if (which == TOOL_DARKEN)
|
||||
{
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/darken.png",
|
||||
api->data_directory);
|
||||
}
|
||||
{
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/darken.png", api->data_directory);
|
||||
}
|
||||
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our name, localized:
|
||||
char * fade_darken_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
|
||||
char *fade_darken_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
|
||||
{
|
||||
if (which == TOOL_FADE)
|
||||
return(strdup(gettext_noop("Lighten")));
|
||||
return (strdup(gettext_noop("Lighten")));
|
||||
else if (which == TOOL_DARKEN)
|
||||
return(strdup(gettext_noop("Darken")));
|
||||
return (strdup(gettext_noop("Darken")));
|
||||
|
||||
return(NULL);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
// Return our description, localized:
|
||||
char * fade_darken_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode)
|
||||
char *fade_darken_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode)
|
||||
{
|
||||
if (which == TOOL_FADE)
|
||||
{
|
||||
if (mode == MODE_PAINT)
|
||||
return(strdup(gettext_noop("Click and drag the mouse to lighten parts of your picture.")));
|
||||
else if (mode == MODE_FULLSCREEN)
|
||||
return(strdup(gettext_noop("Click to lighten your entire picture.")));
|
||||
}
|
||||
{
|
||||
if (mode == MODE_PAINT)
|
||||
return (strdup(gettext_noop("Click and drag the mouse to lighten parts of your picture.")));
|
||||
else if (mode == MODE_FULLSCREEN)
|
||||
return (strdup(gettext_noop("Click to lighten your entire picture.")));
|
||||
}
|
||||
else if (which == TOOL_DARKEN)
|
||||
{
|
||||
if (mode == MODE_PAINT)
|
||||
return(strdup(gettext_noop("Click and drag the mouse to darken parts of your picture.")));
|
||||
else if (mode == MODE_FULLSCREEN)
|
||||
return(strdup(gettext_noop("Click to darken your entire picture.")));
|
||||
}
|
||||
{
|
||||
if (mode == MODE_PAINT)
|
||||
return (strdup(gettext_noop("Click and drag the mouse to darken parts of your picture.")));
|
||||
else if (mode == MODE_FULLSCREEN)
|
||||
return (strdup(gettext_noop("Click to darken your entire picture.")));
|
||||
}
|
||||
|
||||
return(NULL);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
static void do_fade_darken(void * ptr, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y)
|
||||
static void do_fade_darken(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
|
||||
{
|
||||
Uint8 r, g, b;
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
|
||||
SDL_GetRGB(api->getpixel(last, x, y), last->format, &r, &g, &b);
|
||||
|
||||
if (which == TOOL_FADE)
|
||||
{
|
||||
r = min(r + 48, 255);
|
||||
g = min(g + 48, 255);
|
||||
b = min(b + 48, 255);
|
||||
}
|
||||
{
|
||||
r = min(r + 48, 255);
|
||||
g = min(g + 48, 255);
|
||||
b = min(b + 48, 255);
|
||||
}
|
||||
else if (which == TOOL_DARKEN)
|
||||
{
|
||||
r = max(r - 48, 0);
|
||||
g = max(g - 48, 0);
|
||||
b = max(b - 48, 0);
|
||||
}
|
||||
{
|
||||
r = max(r - 48, 0);
|
||||
g = max(g - 48, 0);
|
||||
b = max(b - 48, 0);
|
||||
}
|
||||
|
||||
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, r, g, b));
|
||||
}
|
||||
|
||||
// Callback that does the fade_darken color effect on a circle centered around x,y
|
||||
static void do_fade_darken_paint(void * ptr, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y)
|
||||
static void do_fade_darken_paint(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
|
||||
{
|
||||
int xx, yy;
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
|
||||
for (yy = y - 16; yy < y + 16; yy++)
|
||||
{
|
||||
for (xx = x - 16; xx < x + 16; xx++)
|
||||
{
|
||||
if (api->in_circle(xx - x, yy - y, 16) &&
|
||||
!api->touched(xx, yy))
|
||||
{
|
||||
do_fade_darken(api, which, canvas, last, xx, yy);
|
||||
}
|
||||
for (xx = x - 16; xx < x + 16; xx++)
|
||||
{
|
||||
if (api->in_circle(xx - x, yy - y, 16) && !api->touched(xx, yy))
|
||||
{
|
||||
do_fade_darken(api, which, canvas, last, xx, yy);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Ask Tux Paint to call our 'do_fade_darken_paint()' callback over a line
|
||||
void fade_darken_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
SDL_LockSurface(last);
|
||||
SDL_LockSurface(canvas);
|
||||
|
||||
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_fade_darken_paint);
|
||||
|
||||
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_fade_darken_paint);
|
||||
|
||||
SDL_UnlockSurface(canvas);
|
||||
SDL_UnlockSurface(last);
|
||||
|
||||
api->playsound(snd_effects[which], (x * 255) / canvas->w, 255);
|
||||
|
||||
if (ox > x) { int tmp = ox; ox = x; x = tmp; }
|
||||
if (oy > y) { int tmp = oy; oy = y; y = tmp; }
|
||||
if (ox > x)
|
||||
{
|
||||
int tmp = ox;
|
||||
|
||||
ox = x;
|
||||
x = tmp;
|
||||
}
|
||||
if (oy > y)
|
||||
{
|
||||
int tmp = oy;
|
||||
|
||||
oy = y;
|
||||
y = tmp;
|
||||
}
|
||||
|
||||
update_rect->x = ox - 16;
|
||||
update_rect->y = oy - 16;
|
||||
|
|
@ -219,32 +218,31 @@ 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);
|
||||
else
|
||||
{
|
||||
int xx, yy;
|
||||
{
|
||||
int xx, yy;
|
||||
|
||||
for (yy = 0; yy < canvas->h; yy++)
|
||||
for (xx = 0; xx < canvas->w; xx++)
|
||||
do_fade_darken(api, which, canvas, last, xx, yy);
|
||||
for (yy = 0; yy < canvas->h; yy++)
|
||||
for (xx = 0; xx < canvas->w; xx++)
|
||||
do_fade_darken(api, which, canvas, last, xx, yy);
|
||||
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
|
||||
/* FIXME: Play sfx */
|
||||
}
|
||||
/* FIXME: Play sfx */
|
||||
}
|
||||
}
|
||||
|
||||
// Release
|
||||
void fade_darken_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)
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -260,7 +258,7 @@ void fade_darken_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
|||
|
||||
// We don't use colors
|
||||
void fade_darken_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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -270,15 +268,17 @@ int fade_darken_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTR
|
|||
return 0;
|
||||
}
|
||||
|
||||
void fade_darken_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void fade_darken_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void fade_darken_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void fade_darken_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
int fade_darken_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_PAINT | MODE_FULLSCREEN);
|
||||
return (MODE_PAINT | MODE_FULLSCREEN);
|
||||
}
|
||||
|
|
|
|||
171
magic/src/fill.c
171
magic/src/fill.c
|
|
@ -39,15 +39,13 @@
|
|||
|
||||
/* Our globals: */
|
||||
|
||||
static Mix_Chunk * fill_snd;
|
||||
static Mix_Chunk *fill_snd;
|
||||
static Uint8 fill_r, fill_g, fill_b;
|
||||
|
||||
/* Local function prototypes: */
|
||||
|
||||
static int colors_close(magic_api * api, SDL_Surface * canvas,
|
||||
Uint32 c1, Uint32 c2);
|
||||
static void do_flood_fill(magic_api * api, SDL_Surface * canvas, int x, int y,
|
||||
Uint32 cur_colr, Uint32 old_colr);
|
||||
static int colors_close(magic_api * api, SDL_Surface * canvas, Uint32 c1, Uint32 c2);
|
||||
static void do_flood_fill(magic_api * api, SDL_Surface * canvas, int x, int y, Uint32 cur_colr, Uint32 old_colr);
|
||||
int fill_modes(magic_api * api, int which);
|
||||
void fill_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
void fill_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
|
|
@ -55,18 +53,15 @@ int fill_requires_colors(magic_api * api, int which);
|
|||
void fill_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
void fill_shutdown(magic_api * api);
|
||||
void fill_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void fill_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void fill_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
char * fill_get_description(magic_api * api, int which, int mode);
|
||||
char * fill_get_name(magic_api * api, int which);
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
char *fill_get_description(magic_api * api, int which, int mode);
|
||||
char *fill_get_name(magic_api * api, int which);
|
||||
int fill_get_tool_count(magic_api * api);
|
||||
SDL_Surface * fill_get_icon(magic_api * api, int which);
|
||||
SDL_Surface *fill_get_icon(magic_api * api, int which);
|
||||
Uint32 fill_api_version(void);
|
||||
int fill_init(magic_api * api);
|
||||
|
||||
|
|
@ -76,61 +71,59 @@ int fill_init(magic_api * api)
|
|||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/fill.wav",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/fill.wav", api->data_directory);
|
||||
fill_snd = Mix_LoadWAV(fname);
|
||||
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
Uint32 fill_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
Uint32 fill_api_version(void)
|
||||
{
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
// We have multiple tools:
|
||||
int fill_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
// Load our icons:
|
||||
SDL_Surface * fill_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
SDL_Surface *fill_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/fill.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/fill.png", api->data_directory);
|
||||
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our names, localized:
|
||||
char * fill_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
char *fill_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(strdup(gettext_noop("Fill")));
|
||||
return (strdup(gettext_noop("Fill")));
|
||||
}
|
||||
|
||||
// Return our descriptions, localized:
|
||||
char * fill_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
||||
char *fill_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(strdup(gettext_noop(
|
||||
"Click in the picture to fill that area with color.")));
|
||||
return (strdup(gettext_noop("Click in the picture to fill that area with color.")));
|
||||
}
|
||||
|
||||
|
||||
// Affect the canvas on drag:
|
||||
void fill_drag(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * last ATTRIBUTE_UNUSED, int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED,
|
||||
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
SDL_Surface * last ATTRIBUTE_UNUSED, int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
// Affect the canvas on click:
|
||||
void fill_click(magic_api * api, 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)
|
||||
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;
|
||||
|
|
@ -139,8 +132,8 @@ void fill_click(magic_api * api, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_
|
|||
}
|
||||
|
||||
void fill_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)
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -164,42 +157,41 @@ 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;
|
||||
|
||||
if (c1 == c2)
|
||||
{
|
||||
/* Get it over with quick, if possible! */
|
||||
{
|
||||
/* Get it over with quick, if possible! */
|
||||
|
||||
return 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
double r, g, b;
|
||||
SDL_GetRGB(c1, canvas->format, &r1, &g1, &b1);
|
||||
SDL_GetRGB(c2, canvas->format, &r2, &g2, &b2);
|
||||
{
|
||||
double r, g, b;
|
||||
|
||||
// use distance in linear RGB space
|
||||
r = api->sRGB_to_linear(r1) - api->sRGB_to_linear(r2);
|
||||
r *= r;
|
||||
g = api->sRGB_to_linear(g1) - api->sRGB_to_linear(g2);
|
||||
g *= g;
|
||||
b = api->sRGB_to_linear(b1) - api->sRGB_to_linear(b2);
|
||||
b *= b;
|
||||
SDL_GetRGB(c1, canvas->format, &r1, &g1, &b1);
|
||||
SDL_GetRGB(c2, canvas->format, &r2, &g2, &b2);
|
||||
|
||||
// easy to confuse:
|
||||
// dark grey, brown, purple
|
||||
// light grey, tan
|
||||
// red, orange
|
||||
return r + g + b < 0.04;
|
||||
}
|
||||
// use distance in linear RGB space
|
||||
r = api->sRGB_to_linear(r1) - api->sRGB_to_linear(r2);
|
||||
r *= r;
|
||||
g = api->sRGB_to_linear(g1) - api->sRGB_to_linear(g2);
|
||||
g *= g;
|
||||
b = api->sRGB_to_linear(b1) - api->sRGB_to_linear(b2);
|
||||
b *= b;
|
||||
|
||||
// easy to confuse:
|
||||
// dark grey, brown, purple
|
||||
// light grey, tan
|
||||
// red, orange
|
||||
return r + g + b < 0.04;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
|
|
@ -214,10 +206,10 @@ static void do_flood_fill(magic_api * api, SDL_Surface * canvas, int x, int y,
|
|||
|
||||
prog_anim++;
|
||||
if ((prog_anim % 4) == 0)
|
||||
{
|
||||
api->update_progress_bar();
|
||||
api->playsound(fill_snd, (x * 255) / canvas->w, 255);
|
||||
}
|
||||
{
|
||||
api->update_progress_bar();
|
||||
api->playsound(fill_snd, (x * 255) / canvas->w, 255);
|
||||
}
|
||||
|
||||
|
||||
/* Find left side, filling along the way */
|
||||
|
|
@ -225,15 +217,12 @@ static void do_flood_fill(magic_api * api, SDL_Surface * canvas, int x, int y,
|
|||
in_line = 1;
|
||||
|
||||
while (in_line)
|
||||
{
|
||||
api->putpixel(canvas, fillL, y, cur_colr);
|
||||
fillL--;
|
||||
{
|
||||
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++;
|
||||
|
||||
|
|
@ -241,14 +230,12 @@ static void do_flood_fill(magic_api * api, SDL_Surface * canvas, int x, int y,
|
|||
|
||||
in_line = 1;
|
||||
while (in_line)
|
||||
{
|
||||
api->putpixel(canvas, fillR, y, cur_colr);
|
||||
fillR++;
|
||||
{
|
||||
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--;
|
||||
|
||||
|
|
@ -256,26 +243,26 @@ static void do_flood_fill(magic_api * api, SDL_Surface * canvas, int x, int y,
|
|||
/* Search top and bottom */
|
||||
|
||||
for (i = fillL; i <= fillR; i++)
|
||||
{
|
||||
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 > 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))
|
||||
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))
|
||||
do_flood_fill(api, canvas, i, y + 1, cur_colr, old_colr);
|
||||
}
|
||||
}
|
||||
|
||||
void fill_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void fill_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void fill_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void fill_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
int fill_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_PAINT);
|
||||
return (MODE_PAINT);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
#include "SDL_image.h"
|
||||
#include "SDL_mixer.h"
|
||||
|
||||
Mix_Chunk * fisheye_snd;
|
||||
Mix_Chunk *fisheye_snd;
|
||||
int last_x, last_y;
|
||||
|
||||
/* Local function prototypes */
|
||||
|
|
@ -39,39 +39,35 @@ Uint32 fisheye_api_version(void);
|
|||
void fisheye_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
int fisheye_init(magic_api * api);
|
||||
int fisheye_get_tool_count(magic_api * api);
|
||||
SDL_Surface * fisheye_get_icon(magic_api * api, int which);
|
||||
char * fisheye_get_name(magic_api * api, int which);
|
||||
char * fisheye_get_description(magic_api * api, int which, int mode);
|
||||
SDL_Surface *fisheye_get_icon(magic_api * api, int which);
|
||||
char *fisheye_get_name(magic_api * api, int which);
|
||||
char *fisheye_get_description(magic_api * api, int which, int mode);
|
||||
int fisheye_requires_colors(magic_api * api, int which);
|
||||
void fisheye_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
|
||||
void fisheye_shutdown(magic_api * api);
|
||||
void fisheye_draw(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y);
|
||||
void fisheye_draw(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||
void fisheye_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
void fisheye_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void fisheye_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
void fisheye_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
int fisheye_modes(magic_api * api, int which);
|
||||
|
||||
|
||||
// Housekeeping functions
|
||||
// Housekeeping functions
|
||||
|
||||
void fisheye_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
|
||||
Uint32 fisheye_api_version(void)
|
||||
{
|
||||
return(TP_MAGIC_API_VERSION);
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
void fisheye_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
|
||||
void fisheye_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
|
||||
Uint8 b ATTRIBUTE_UNUSED)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -79,11 +75,11 @@ void fisheye_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSE
|
|||
int fisheye_init(magic_api * api)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/fisheye.ogg", api->data_directory);
|
||||
fisheye_snd = Mix_LoadWAV(fname);
|
||||
|
||||
return(1);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/fisheye.ogg", api->data_directory);
|
||||
fisheye_snd = Mix_LoadWAV(fname);
|
||||
|
||||
return (1);
|
||||
}
|
||||
|
||||
int fisheye_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
|
|
@ -91,186 +87,203 @@ int fisheye_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
|||
return 1;
|
||||
}
|
||||
|
||||
SDL_Surface * fisheye_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
SDL_Surface *fisheye_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/fisheye.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/fisheye.png", api->data_directory);
|
||||
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
char * fisheye_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) { return strdup(gettext_noop("Fisheye")); } //Needs better name
|
||||
char *fisheye_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return strdup(gettext_noop("Fisheye"));
|
||||
} //Needs better name
|
||||
|
||||
char * fisheye_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED) { return strdup(gettext_noop("Click on part of your picture to create a fisheye effect.")); }
|
||||
char *fisheye_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return strdup(gettext_noop("Click on part of your picture to create a fisheye effect."));
|
||||
}
|
||||
|
||||
int fisheye_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) { return 0; }
|
||||
int fisheye_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void fisheye_release(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * snapshot ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect 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)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
void fisheye_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{ Mix_FreeChunk(fisheye_snd); }
|
||||
{
|
||||
Mix_FreeChunk(fisheye_snd);
|
||||
}
|
||||
|
||||
// do-fisheye
|
||||
|
||||
void fisheye_draw(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x, int y)
|
||||
void fisheye_draw(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x, int y)
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
|
||||
SDL_Surface * oryg, *temp_src, *temp_dest, *output;
|
||||
SDL_Rect rect, temp_rect;
|
||||
int xx, yy;
|
||||
unsigned short int i;
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
|
||||
if(api->in_circle(last_x - x, last_y - y, 80)) return;
|
||||
SDL_Surface *oryg, *temp_src, *temp_dest, *output;
|
||||
SDL_Rect rect, temp_rect;
|
||||
int xx, yy;
|
||||
unsigned short int i;
|
||||
|
||||
last_x = x;
|
||||
last_y = y;
|
||||
if (api->in_circle(last_x - x, last_y - y, 80))
|
||||
return;
|
||||
|
||||
oryg=SDL_CreateRGBSurface(SDL_SWSURFACE, 80, 80, canvas->format->BitsPerPixel,
|
||||
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
|
||||
last_x = x;
|
||||
last_y = y;
|
||||
|
||||
output=SDL_CreateRGBSurface(SDL_SWSURFACE, 80, 80, canvas->format->BitsPerPixel,
|
||||
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
|
||||
|
||||
rect.x=x-40;
|
||||
rect.y=y-40;
|
||||
rect.w=rect.h=80;
|
||||
|
||||
SDL_BlitSurface(canvas, &rect, oryg, NULL); //here we have a piece of source image. Now we've to scale it (keeping aspect ratio)
|
||||
|
||||
//do vertical fisheye
|
||||
for (i=0; i<40; i++)
|
||||
{
|
||||
temp_src=SDL_CreateRGBSurface(SDL_SWSURFACE, 1, 80, canvas->format->BitsPerPixel,
|
||||
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
|
||||
|
||||
//let's take a smooth bar of scaled bitmap and copy it to temp
|
||||
//left side first
|
||||
rect.x=i;
|
||||
rect.y=0;
|
||||
rect.w=1;
|
||||
|
||||
SDL_BlitSurface(oryg, &rect, temp_src, NULL); //this bar is copied to temp_src
|
||||
|
||||
temp_dest=SDL_CreateRGBSurface(SDL_SWSURFACE, 1, 80+2*i, canvas->format->BitsPerPixel,
|
||||
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
|
||||
|
||||
temp_dest=api->scale(temp_src, 1, 80+2*i, 0); //temp_dest stores scaled temp_src
|
||||
|
||||
temp_rect.x=0;
|
||||
temp_rect.y=i;
|
||||
temp_rect.w=1;
|
||||
temp_rect.h=80;
|
||||
oryg = SDL_CreateRGBSurface(SDL_SWSURFACE, 80, 80, canvas->format->BitsPerPixel,
|
||||
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask,
|
||||
canvas->format->Amask);
|
||||
|
||||
SDL_BlitSurface(temp_dest, &temp_rect, output, &rect); //let's copy it to output
|
||||
|
||||
//right side then
|
||||
|
||||
rect.x=79-i;
|
||||
|
||||
SDL_BlitSurface(oryg, &rect, temp_src, NULL); //this bar is copied to temp_src //OK
|
||||
|
||||
temp_dest=api->scale(temp_src, 1, 80+2*i, 0); //temp_dest stores scaled temp_src
|
||||
output = SDL_CreateRGBSurface(SDL_SWSURFACE, 80, 80, canvas->format->BitsPerPixel,
|
||||
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask,
|
||||
canvas->format->Amask);
|
||||
|
||||
SDL_BlitSurface(temp_dest, &temp_rect, output, &rect); //let's copy it to output
|
||||
}
|
||||
|
||||
//do horizontal fisheye
|
||||
for (i=0; i<40; i++)
|
||||
{
|
||||
temp_src=SDL_CreateRGBSurface(SDL_SWSURFACE, 80, 1, canvas->format->BitsPerPixel,
|
||||
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
|
||||
|
||||
temp_dest=SDL_CreateRGBSurface(SDL_SWSURFACE, 80+2*i, 1, canvas->format->BitsPerPixel,
|
||||
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
|
||||
|
||||
//upper side first
|
||||
rect.x=0;
|
||||
rect.y=i;
|
||||
rect.w=80;
|
||||
rect.h=1;
|
||||
|
||||
temp_rect.x=i;
|
||||
temp_rect.y=0;
|
||||
temp_rect.w=80;
|
||||
temp_rect.h=1;
|
||||
|
||||
SDL_BlitSurface(output, &rect, temp_src, NULL);
|
||||
|
||||
temp_dest=api->scale(temp_src, 80+2*i, 1, 0);
|
||||
|
||||
SDL_BlitSurface(temp_dest, &temp_rect, output, &rect);
|
||||
|
||||
//lower side then
|
||||
rect.x = x - 40;
|
||||
rect.y = y - 40;
|
||||
rect.w = rect.h = 80;
|
||||
|
||||
rect.y=79-i;
|
||||
SDL_BlitSurface(output, &rect, temp_src, NULL);
|
||||
|
||||
temp_dest=api->scale(temp_src, 80+2*i, 1, 0);
|
||||
SDL_BlitSurface(temp_dest, &temp_rect, output, &rect);
|
||||
}
|
||||
SDL_BlitSurface(canvas, &rect, oryg, NULL); //here we have a piece of source image. Now we've to scale it (keeping aspect ratio)
|
||||
|
||||
rect.x=x-40;
|
||||
rect.y=y-40;
|
||||
rect.w=rect.h=80;
|
||||
//do vertical fisheye
|
||||
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);
|
||||
|
||||
//let's blit an area surrounded by a circle
|
||||
//let's take a smooth bar of scaled bitmap and copy it to temp
|
||||
//left side first
|
||||
rect.x = i;
|
||||
rect.y = 0;
|
||||
rect.w = 1;
|
||||
|
||||
for (yy = y-40; yy < y+40; yy++)
|
||||
for (xx = x-40; xx < x+40; xx++)
|
||||
SDL_BlitSurface(oryg, &rect, temp_src, NULL); //this bar is copied to temp_src
|
||||
|
||||
if (api->in_circle(xx-x, yy-y, 40))
|
||||
api->putpixel(canvas, xx, yy, api->getpixel(output, xx+40-x, yy+40-y));
|
||||
temp_dest = SDL_CreateRGBSurface(SDL_SWSURFACE, 1, 80 + 2 * i, canvas->format->BitsPerPixel,
|
||||
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask,
|
||||
canvas->format->Amask);
|
||||
|
||||
temp_dest = api->scale(temp_src, 1, 80 + 2 * i, 0); //temp_dest stores scaled temp_src
|
||||
|
||||
temp_rect.x = 0;
|
||||
temp_rect.y = i;
|
||||
temp_rect.w = 1;
|
||||
temp_rect.h = 80;
|
||||
|
||||
SDL_BlitSurface(temp_dest, &temp_rect, output, &rect); //let's copy it to output
|
||||
|
||||
//right side then
|
||||
|
||||
rect.x = 79 - i;
|
||||
|
||||
SDL_BlitSurface(oryg, &rect, temp_src, NULL); //this bar is copied to temp_src //OK
|
||||
|
||||
temp_dest = api->scale(temp_src, 1, 80 + 2 * i, 0); //temp_dest stores scaled temp_src
|
||||
|
||||
SDL_BlitSurface(temp_dest, &temp_rect, output, &rect); //let's copy it to output
|
||||
}
|
||||
|
||||
//do horizontal fisheye
|
||||
for (i = 0; i < 40; i++)
|
||||
{
|
||||
temp_src = SDL_CreateRGBSurface(SDL_SWSURFACE, 80, 1, canvas->format->BitsPerPixel,
|
||||
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask,
|
||||
canvas->format->Amask);
|
||||
|
||||
temp_dest = SDL_CreateRGBSurface(SDL_SWSURFACE, 80 + 2 * i, 1, canvas->format->BitsPerPixel,
|
||||
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask,
|
||||
canvas->format->Amask);
|
||||
|
||||
//upper side first
|
||||
rect.x = 0;
|
||||
rect.y = i;
|
||||
rect.w = 80;
|
||||
rect.h = 1;
|
||||
|
||||
temp_rect.x = i;
|
||||
temp_rect.y = 0;
|
||||
temp_rect.w = 80;
|
||||
temp_rect.h = 1;
|
||||
|
||||
SDL_BlitSurface(output, &rect, temp_src, NULL);
|
||||
|
||||
temp_dest = api->scale(temp_src, 80 + 2 * i, 1, 0);
|
||||
|
||||
SDL_BlitSurface(temp_dest, &temp_rect, output, &rect);
|
||||
|
||||
//lower side then
|
||||
|
||||
rect.y = 79 - i;
|
||||
SDL_BlitSurface(output, &rect, temp_src, NULL);
|
||||
|
||||
temp_dest = api->scale(temp_src, 80 + 2 * i, 1, 0);
|
||||
SDL_BlitSurface(temp_dest, &temp_rect, output, &rect);
|
||||
}
|
||||
|
||||
rect.x = x - 40;
|
||||
rect.y = y - 40;
|
||||
rect.w = rect.h = 80;
|
||||
|
||||
//let's blit an area surrounded by a circle
|
||||
|
||||
for (yy = y - 40; yy < y + 40; yy++)
|
||||
for (xx = x - 40; xx < x + 40; xx++)
|
||||
|
||||
if (api->in_circle(xx - x, yy - y, 40))
|
||||
api->putpixel(canvas, xx, yy, api->getpixel(output, xx + 40 - x, yy + 40 - y));
|
||||
|
||||
|
||||
SDL_FreeSurface(oryg);
|
||||
SDL_FreeSurface(output);
|
||||
SDL_FreeSurface(temp_dest);
|
||||
SDL_FreeSurface(temp_src);
|
||||
|
||||
api->playsound(fisheye_snd, (x * 255) / canvas->w,255);
|
||||
SDL_FreeSurface(oryg);
|
||||
SDL_FreeSurface(output);
|
||||
SDL_FreeSurface(temp_dest);
|
||||
SDL_FreeSurface(temp_src);
|
||||
|
||||
api->playsound(fisheye_snd, (x * 255) / canvas->w, 255);
|
||||
}
|
||||
|
||||
void fisheye_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
|
||||
api->line(api, which, canvas, snapshot, ox, oy, x, y, 1, fisheye_draw);
|
||||
update_rect->x = min(ox, x) - 40;
|
||||
update_rect->y = min(oy, y) - 40;
|
||||
update_rect->w = max(ox, x) - update_rect->x + 40;
|
||||
update_rect->h = max(oy, y) - update_rect->y + 40;
|
||||
api->line(api, which, canvas, snapshot, ox, oy, x, y, 1, fisheye_draw);
|
||||
update_rect->x = min(ox, x) - 40;
|
||||
update_rect->y = min(oy, y) - 40;
|
||||
update_rect->w = max(ox, x) - update_rect->x + 40;
|
||||
update_rect->h = max(oy, y) - update_rect->y + 40;
|
||||
}
|
||||
|
||||
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);
|
||||
last_x = -80; /* A value that will be beyond any clicked position */
|
||||
last_y = -80;
|
||||
fisheye_drag(api, which, canvas, last, x, y, x, y, update_rect);
|
||||
}
|
||||
|
||||
void fisheye_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
|
||||
void fisheye_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void fisheye_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void fisheye_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
int fisheye_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_PAINT);
|
||||
return (MODE_PAINT);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,19 +36,21 @@
|
|||
|
||||
/* Our globals: */
|
||||
|
||||
enum { SIDE_LEFT, SIDE_RIGHT };
|
||||
enum { LEAFSIDE_RIGHT_DOWN,
|
||||
LEAFSIDE_LEFT_DOWN,
|
||||
LEAFSIDE_RIGHT_UP,
|
||||
LEAFSIDE_LEFT_UP };
|
||||
enum
|
||||
{ SIDE_LEFT, SIDE_RIGHT };
|
||||
enum
|
||||
{ LEAFSIDE_RIGHT_DOWN,
|
||||
LEAFSIDE_LEFT_DOWN,
|
||||
LEAFSIDE_RIGHT_UP,
|
||||
LEAFSIDE_LEFT_UP
|
||||
};
|
||||
|
||||
static Mix_Chunk * flower_click_snd, * flower_release_snd;
|
||||
static Mix_Chunk *flower_click_snd, *flower_release_snd;
|
||||
static Uint8 flower_r, flower_g, flower_b;
|
||||
static int flower_min_x, flower_max_x, flower_bottom_x, flower_bottom_y;
|
||||
static int flower_side_first;
|
||||
static int flower_side_decided;
|
||||
static SDL_Surface * flower_base, * flower_leaf, * flower_petals,
|
||||
* flower_petals_colorized;
|
||||
static SDL_Surface *flower_base, *flower_leaf, *flower_petals, *flower_petals_colorized;
|
||||
|
||||
/* Local function prototypes: */
|
||||
|
||||
|
|
@ -59,36 +61,31 @@ typedef struct
|
|||
|
||||
static void flower_drawbase(magic_api * api, SDL_Surface * canvas);
|
||||
static void flower_drawflower(magic_api * api, SDL_Surface * canvas, int x, int y);
|
||||
static Point2D flower_PointOnCubicBezier(Point2D* cp, float t);
|
||||
static void flower_ComputeBezier(Point2D* cp, int numberOfPoints, Point2D* curve);
|
||||
static Point2D flower_PointOnCubicBezier(Point2D * cp, float t);
|
||||
static void flower_ComputeBezier(Point2D * cp, int numberOfPoints, Point2D * curve);
|
||||
static void flower_colorize_petals(magic_api * api);
|
||||
Uint32 flower_api_version(void);
|
||||
int flower_init(magic_api * api);
|
||||
int flower_get_tool_count(magic_api * api);
|
||||
SDL_Surface * flower_get_icon(magic_api * api, int which);
|
||||
char * flower_get_name(magic_api * api, int which);
|
||||
char * flower_get_description(magic_api * api, int which, int mode);
|
||||
static void flower_predrag(magic_api * api, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y);
|
||||
SDL_Surface *flower_get_icon(magic_api * api, int which);
|
||||
char *flower_get_name(magic_api * api, int which);
|
||||
char *flower_get_description(magic_api * api, int which, int mode);
|
||||
static void flower_predrag(magic_api * api, SDL_Surface * canvas, SDL_Surface * last, int ox, int oy, int x, int y);
|
||||
void flower_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
void flower_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void flower_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
static void flower_drawflower(magic_api * api, SDL_Surface * canvas, int x, int y);
|
||||
static void flower_drawbase(magic_api * api, SDL_Surface * canvas);
|
||||
static void flower_drawstalk(magic_api * api, SDL_Surface * canvas,
|
||||
int top_x, int top_y, int minx, int maxx,
|
||||
int bottom_x, int bottom_y, int final);
|
||||
int top_x, int top_y, int minx, int maxx, int bottom_x, int bottom_y, int final);
|
||||
void flower_shutdown(magic_api * api);
|
||||
void flower_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
int flower_requires_colors(magic_api * api, int which);
|
||||
static Point2D flower_PointOnCubicBezier( Point2D* cp, float t );
|
||||
static void flower_ComputeBezier( Point2D* cp, int numberOfPoints, Point2D* curve );
|
||||
static Point2D flower_PointOnCubicBezier(Point2D * cp, float t);
|
||||
static void flower_ComputeBezier(Point2D * cp, int numberOfPoints, Point2D * curve);
|
||||
static void flower_colorize_petals(magic_api * api);
|
||||
void flower_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
void flower_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
|
|
@ -96,7 +93,10 @@ int flower_modes(magic_api * api, int which);
|
|||
|
||||
|
||||
|
||||
Uint32 flower_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
Uint32 flower_api_version(void)
|
||||
{
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
|
||||
// No setup required:
|
||||
|
|
@ -104,61 +104,55 @@ int flower_init(magic_api * api)
|
|||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/flower_click.ogg",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/flower_click.ogg", api->data_directory);
|
||||
flower_click_snd = Mix_LoadWAV(fname);
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/flower_release.ogg",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/flower_release.ogg", api->data_directory);
|
||||
flower_release_snd = Mix_LoadWAV(fname);
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/flower_base.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/flower_base.png", api->data_directory);
|
||||
flower_base = IMG_Load(fname);
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/flower_leaf.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/flower_leaf.png", api->data_directory);
|
||||
flower_leaf = IMG_Load(fname);
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/flower_petals.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/flower_petals.png", api->data_directory);
|
||||
flower_petals = IMG_Load(fname);
|
||||
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
// We have multiple tools:
|
||||
int flower_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
// Load our icons:
|
||||
SDL_Surface * flower_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
SDL_Surface *flower_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/flower.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/flower.png", api->data_directory);
|
||||
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our names, localized:
|
||||
char * flower_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
char *flower_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(strdup(gettext_noop("Flower")));
|
||||
return (strdup(gettext_noop("Flower")));
|
||||
}
|
||||
|
||||
// Return our descriptions, localized:
|
||||
char * flower_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
||||
char *flower_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(strdup(gettext_noop("Click and drag to draw a flower stalk. Let go to finish the flower.")));
|
||||
return (strdup(gettext_noop("Click and drag to draw a flower stalk. Let go to finish the flower.")));
|
||||
}
|
||||
|
||||
// Affect the canvas on drag:
|
||||
static void flower_predrag(magic_api * api ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * last ATTRIBUTE_UNUSED, int ox, int oy, int x, int y)
|
||||
SDL_Surface * last ATTRIBUTE_UNUSED, int ox, int oy, int x, int y)
|
||||
{
|
||||
if (x < flower_min_x)
|
||||
flower_min_x = x;
|
||||
|
|
@ -177,23 +171,22 @@ static void flower_predrag(magic_api * api ATTRIBUTE_UNUSED, SDL_Surface * canva
|
|||
// Determine which way to bend first:
|
||||
//
|
||||
if (flower_side_decided == 0)
|
||||
{
|
||||
if (x < flower_bottom_x - 10)
|
||||
{
|
||||
flower_side_first = SIDE_LEFT;
|
||||
flower_side_decided = 1;
|
||||
if (x < flower_bottom_x - 10)
|
||||
{
|
||||
flower_side_first = SIDE_LEFT;
|
||||
flower_side_decided = 1;
|
||||
}
|
||||
else if (x > flower_bottom_x + 10)
|
||||
{
|
||||
flower_side_first = SIDE_RIGHT;
|
||||
flower_side_decided = 1;
|
||||
}
|
||||
}
|
||||
else if (x > flower_bottom_x + 10)
|
||||
{
|
||||
flower_side_first = SIDE_RIGHT;
|
||||
flower_side_decided = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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,21 +199,19 @@ 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);
|
||||
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
|
@ -231,14 +222,13 @@ void flower_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
|
|||
flower_side_first = SIDE_LEFT;
|
||||
|
||||
flower_drag(api, which, canvas, last, x, y, x, y, update_rect);
|
||||
|
||||
|
||||
api->playsound(flower_click_snd, (x * 255) / canvas->w, 255);
|
||||
}
|
||||
|
||||
// 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: */
|
||||
|
||||
|
|
@ -250,7 +240,7 @@ void flower_release(magic_api * api, int which ATTRIBUTE_UNUSED,
|
|||
|
||||
flower_predrag(api, canvas, last, x, y, x, y);
|
||||
|
||||
|
||||
|
||||
/* Erase any old stuff: */
|
||||
|
||||
SDL_BlitSurface(last, NULL, canvas, NULL);
|
||||
|
|
@ -258,15 +248,13 @@ 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);
|
||||
|
||||
flower_drawbase(api, canvas);
|
||||
|
||||
|
||||
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
|
|
@ -297,11 +285,10 @@ static void flower_drawbase(magic_api * api ATTRIBUTE_UNUSED, SDL_Surface * canv
|
|||
}
|
||||
|
||||
static void flower_drawstalk(magic_api * api ATTRIBUTE_UNUSED, SDL_Surface * canvas,
|
||||
int top_x, int top_y, int minx, int maxx,
|
||||
int bottom_x, int bottom_y, int final)
|
||||
int top_x, int top_y, int minx, int maxx, int bottom_x, int bottom_y, int final)
|
||||
{
|
||||
Point2D control_points[4];
|
||||
Point2D * curve;
|
||||
Point2D *curve;
|
||||
int i, n_points;
|
||||
int left, right;
|
||||
SDL_Rect dest, src;
|
||||
|
|
@ -315,22 +302,22 @@ static void flower_drawstalk(magic_api * api ATTRIBUTE_UNUSED, SDL_Surface * can
|
|||
control_points[0].y = top_y;
|
||||
|
||||
if (flower_side_first == SIDE_LEFT)
|
||||
{
|
||||
control_points[1].x = minx;
|
||||
control_points[2].x = maxx;
|
||||
}
|
||||
{
|
||||
control_points[1].x = minx;
|
||||
control_points[2].x = maxx;
|
||||
}
|
||||
else
|
||||
{
|
||||
control_points[1].x = maxx;
|
||||
control_points[2].x = minx;
|
||||
}
|
||||
{
|
||||
control_points[1].x = maxx;
|
||||
control_points[2].x = minx;
|
||||
}
|
||||
|
||||
control_points[1].y = ((bottom_y - top_y) / 3) + top_y;
|
||||
control_points[2].y = (((bottom_y - top_y) / 3) * 2) + top_y;
|
||||
|
||||
|
||||
control_points[3].x = bottom_x;
|
||||
control_points[3].y = bottom_y;
|
||||
|
||||
|
||||
if (final == 0)
|
||||
n_points = 8;
|
||||
else
|
||||
|
|
@ -342,129 +329,128 @@ static void flower_drawstalk(magic_api * api ATTRIBUTE_UNUSED, SDL_Surface * can
|
|||
|
||||
|
||||
/* Draw the curve: */
|
||||
|
||||
|
||||
for (i = 0; i < n_points - 1; i++)
|
||||
{
|
||||
if (final == 0)
|
||||
{
|
||||
dest.x = curve[i].x;
|
||||
dest.y = curve[i].y;
|
||||
dest.w = 2;
|
||||
dest.h = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
left = min(curve[i].x, curve[i + 1].x);
|
||||
right = max(curve[i].x, curve[i + 1].x);
|
||||
|
||||
dest.x = left;
|
||||
dest.y = curve[i].y;
|
||||
dest.w = right - left + 1;
|
||||
dest.h = 2;
|
||||
}
|
||||
|
||||
SDL_FillRect(canvas, &dest, SDL_MapRGB(canvas->format, 0, 128, 0));
|
||||
|
||||
|
||||
/* 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)
|
||||
{
|
||||
/* Check for hard left/right angles: */
|
||||
|
||||
side = -1;
|
||||
|
||||
if (curve[i - 2].x - curve[i + 2].x > 5)
|
||||
{
|
||||
/* Hard lower-left-to-upper-right (/),
|
||||
stick either a left-upward or right-downward facing leaf */
|
||||
|
||||
if (rand() % 10 < 5)
|
||||
side = LEAFSIDE_LEFT_UP;
|
||||
else
|
||||
side = LEAFSIDE_RIGHT_DOWN;
|
||||
}
|
||||
else if (curve[i - 2].x - curve[i + 2].x < -5)
|
||||
{
|
||||
/* Hard lower-right-to-upper-left (\)
|
||||
stick either a right-upward or left-downward facing leaf */
|
||||
|
||||
if (rand() % 10 < 5)
|
||||
side = LEAFSIDE_LEFT_DOWN;
|
||||
else
|
||||
side = LEAFSIDE_RIGHT_UP;
|
||||
}
|
||||
else if (abs(curve[i - 2].x - curve[i + 2].x) < 5)
|
||||
{
|
||||
/* Mostly up; stick left- or right-downward: */
|
||||
|
||||
if (rand() % 10 < 5)
|
||||
side = LEAFSIDE_LEFT_DOWN;
|
||||
else
|
||||
side = LEAFSIDE_RIGHT_DOWN;
|
||||
}
|
||||
|
||||
|
||||
/* Draw the appropriately-oriented leaf, if any: */
|
||||
|
||||
if (side == LEAFSIDE_RIGHT_DOWN)
|
||||
{
|
||||
dest.x = curve[i].x;
|
||||
dest.y = curve[i].y;
|
||||
|
||||
SDL_BlitSurface(flower_leaf, NULL, canvas, &dest);
|
||||
}
|
||||
else if (side == LEAFSIDE_LEFT_DOWN)
|
||||
{
|
||||
for (xx = 0; xx < flower_leaf->w; xx++)
|
||||
if (final == 0)
|
||||
{
|
||||
src.x = xx;
|
||||
src.y = 0;
|
||||
src.w = 1;
|
||||
src.h = flower_leaf->h;
|
||||
|
||||
dest.x = curve[i].x - xx;
|
||||
dest.y = curve[i].y;
|
||||
|
||||
SDL_BlitSurface(flower_leaf, &src, canvas, &dest);
|
||||
}
|
||||
}
|
||||
else if (side == LEAFSIDE_RIGHT_UP)
|
||||
{
|
||||
for (yy = 0; yy < flower_leaf->h; yy++)
|
||||
{
|
||||
src.x = 0;
|
||||
src.y = yy;
|
||||
src.w = flower_leaf->w;
|
||||
src.h = 1;
|
||||
|
||||
dest.x = curve[i].x;
|
||||
dest.y = curve[i].y - yy;
|
||||
|
||||
SDL_BlitSurface(flower_leaf, &src, canvas, &dest);
|
||||
dest.y = curve[i].y;
|
||||
dest.w = 2;
|
||||
dest.h = 2;
|
||||
}
|
||||
}
|
||||
else if (side == LEAFSIDE_LEFT_UP)
|
||||
{
|
||||
for (xx = 0; xx < flower_leaf->w; xx++)
|
||||
else
|
||||
{
|
||||
for (yy = 0; yy < flower_leaf->h; yy++)
|
||||
{
|
||||
src.x = xx;
|
||||
src.y = yy;
|
||||
src.w = 1;
|
||||
src.h = 1;
|
||||
left = min(curve[i].x, curve[i + 1].x);
|
||||
right = max(curve[i].x, curve[i + 1].x);
|
||||
|
||||
dest.x = curve[i].x - xx;
|
||||
dest.y = curve[i].y - yy;
|
||||
|
||||
SDL_BlitSurface(flower_leaf, &src, canvas, &dest);
|
||||
}
|
||||
dest.x = left;
|
||||
dest.y = curve[i].y;
|
||||
dest.w = right - left + 1;
|
||||
dest.h = 2;
|
||||
}
|
||||
|
||||
SDL_FillRect(canvas, &dest, SDL_MapRGB(canvas->format, 0, 128, 0));
|
||||
|
||||
|
||||
/* 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)
|
||||
{
|
||||
/* Check for hard left/right angles: */
|
||||
|
||||
side = -1;
|
||||
|
||||
if (curve[i - 2].x - curve[i + 2].x > 5)
|
||||
{
|
||||
/* Hard lower-left-to-upper-right (/),
|
||||
stick either a left-upward or right-downward facing leaf */
|
||||
|
||||
if (rand() % 10 < 5)
|
||||
side = LEAFSIDE_LEFT_UP;
|
||||
else
|
||||
side = LEAFSIDE_RIGHT_DOWN;
|
||||
}
|
||||
else if (curve[i - 2].x - curve[i + 2].x < -5)
|
||||
{
|
||||
/* Hard lower-right-to-upper-left (\)
|
||||
stick either a right-upward or left-downward facing leaf */
|
||||
|
||||
if (rand() % 10 < 5)
|
||||
side = LEAFSIDE_LEFT_DOWN;
|
||||
else
|
||||
side = LEAFSIDE_RIGHT_UP;
|
||||
}
|
||||
else if (abs(curve[i - 2].x - curve[i + 2].x) < 5)
|
||||
{
|
||||
/* Mostly up; stick left- or right-downward: */
|
||||
|
||||
if (rand() % 10 < 5)
|
||||
side = LEAFSIDE_LEFT_DOWN;
|
||||
else
|
||||
side = LEAFSIDE_RIGHT_DOWN;
|
||||
}
|
||||
|
||||
|
||||
/* Draw the appropriately-oriented leaf, if any: */
|
||||
|
||||
if (side == LEAFSIDE_RIGHT_DOWN)
|
||||
{
|
||||
dest.x = curve[i].x;
|
||||
dest.y = curve[i].y;
|
||||
|
||||
SDL_BlitSurface(flower_leaf, NULL, canvas, &dest);
|
||||
}
|
||||
else if (side == LEAFSIDE_LEFT_DOWN)
|
||||
{
|
||||
for (xx = 0; xx < flower_leaf->w; xx++)
|
||||
{
|
||||
src.x = xx;
|
||||
src.y = 0;
|
||||
src.w = 1;
|
||||
src.h = flower_leaf->h;
|
||||
|
||||
dest.x = curve[i].x - xx;
|
||||
dest.y = curve[i].y;
|
||||
|
||||
SDL_BlitSurface(flower_leaf, &src, canvas, &dest);
|
||||
}
|
||||
}
|
||||
else if (side == LEAFSIDE_RIGHT_UP)
|
||||
{
|
||||
for (yy = 0; yy < flower_leaf->h; yy++)
|
||||
{
|
||||
src.x = 0;
|
||||
src.y = yy;
|
||||
src.w = flower_leaf->w;
|
||||
src.h = 1;
|
||||
|
||||
dest.x = curve[i].x;
|
||||
dest.y = curve[i].y - yy;
|
||||
|
||||
SDL_BlitSurface(flower_leaf, &src, canvas, &dest);
|
||||
}
|
||||
}
|
||||
else if (side == LEAFSIDE_LEFT_UP)
|
||||
{
|
||||
for (xx = 0; xx < flower_leaf->w; xx++)
|
||||
{
|
||||
for (yy = 0; yy < flower_leaf->h; yy++)
|
||||
{
|
||||
src.x = xx;
|
||||
src.y = yy;
|
||||
src.w = 1;
|
||||
src.h = 1;
|
||||
|
||||
dest.x = curve[i].x - xx;
|
||||
dest.y = curve[i].y - yy;
|
||||
|
||||
SDL_BlitSurface(flower_leaf, &src, canvas, &dest);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free(curve);
|
||||
}
|
||||
|
|
@ -518,32 +504,32 @@ cp[3] is the end point, or P3 in the above diagram
|
|||
t is the parameter value, 0 <= t <= 1
|
||||
*/
|
||||
|
||||
static Point2D flower_PointOnCubicBezier( Point2D* cp, float t )
|
||||
static Point2D flower_PointOnCubicBezier(Point2D * cp, float t)
|
||||
{
|
||||
float ax, bx, cx;
|
||||
float ay, by, cy;
|
||||
float tSquared, tCubed;
|
||||
Point2D result;
|
||||
float ax, bx, cx;
|
||||
float ay, by, cy;
|
||||
float tSquared, tCubed;
|
||||
Point2D result;
|
||||
|
||||
/* calculate the polynomial coefficients */
|
||||
/* calculate the polynomial coefficients */
|
||||
|
||||
cx = 3.0 * (cp[1].x - cp[0].x);
|
||||
bx = 3.0 * (cp[2].x - cp[1].x) - cx;
|
||||
ax = cp[3].x - cp[0].x - cx - bx;
|
||||
|
||||
cy = 3.0 * (cp[1].y - cp[0].y);
|
||||
by = 3.0 * (cp[2].y - cp[1].y) - cy;
|
||||
ay = cp[3].y - cp[0].y - cy - by;
|
||||
|
||||
/* calculate the curve point at parameter value t */
|
||||
|
||||
tSquared = t * t;
|
||||
tCubed = tSquared * t;
|
||||
|
||||
result.x = (ax * tCubed) + (bx * tSquared) + (cx * t) + cp[0].x;
|
||||
result.y = (ay * tCubed) + (by * tSquared) + (cy * t) + cp[0].y;
|
||||
|
||||
return result;
|
||||
cx = 3.0 * (cp[1].x - cp[0].x);
|
||||
bx = 3.0 * (cp[2].x - cp[1].x) - cx;
|
||||
ax = cp[3].x - cp[0].x - cx - bx;
|
||||
|
||||
cy = 3.0 * (cp[1].y - cp[0].y);
|
||||
by = 3.0 * (cp[2].y - cp[1].y) - cy;
|
||||
ay = cp[3].y - cp[0].y - cy - by;
|
||||
|
||||
/* calculate the curve point at parameter value t */
|
||||
|
||||
tSquared = t * t;
|
||||
tCubed = tSquared * t;
|
||||
|
||||
result.x = (ax * tCubed) + (bx * tSquared) + (cx * t) + cp[0].x;
|
||||
result.y = (ay * tCubed) + (by * tSquared) + (cy * t) + cp[0].y;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -553,15 +539,15 @@ static Point2D flower_PointOnCubicBezier( Point2D* cp, float t )
|
|||
<sizeof(Point2D) numberOfPoints>
|
||||
*/
|
||||
|
||||
static void flower_ComputeBezier( Point2D* cp, int numberOfPoints, Point2D* curve )
|
||||
static void flower_ComputeBezier(Point2D * cp, int numberOfPoints, Point2D * curve)
|
||||
{
|
||||
float dt;
|
||||
int i;
|
||||
float dt;
|
||||
int i;
|
||||
|
||||
dt = 1.0 / ( numberOfPoints - 1 );
|
||||
dt = 1.0 / (numberOfPoints - 1);
|
||||
|
||||
for( i = 0; i < numberOfPoints; i++)
|
||||
curve[i] = flower_PointOnCubicBezier( cp, i*dt );
|
||||
for (i = 0; i < numberOfPoints; i++)
|
||||
curve[i] = flower_PointOnCubicBezier(cp, i * dt);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -576,9 +562,7 @@ static void flower_colorize_petals(magic_api * api)
|
|||
|
||||
/* Create a surface to render into: */
|
||||
|
||||
amask = ~(flower_petals->format->Rmask |
|
||||
flower_petals->format->Gmask |
|
||||
flower_petals->format->Bmask);
|
||||
amask = ~(flower_petals->format->Rmask | flower_petals->format->Gmask | flower_petals->format->Bmask);
|
||||
|
||||
flower_petals_colorized =
|
||||
SDL_CreateRGBSurface(SDL_SWSURFACE,
|
||||
|
|
@ -586,8 +570,7 @@ static void flower_colorize_petals(magic_api * api)
|
|||
flower_petals->h,
|
||||
flower_petals->format->BitsPerPixel,
|
||||
flower_petals->format->Rmask,
|
||||
flower_petals->format->Gmask,
|
||||
flower_petals->format->Bmask, amask);
|
||||
flower_petals->format->Gmask, flower_petals->format->Bmask, amask);
|
||||
|
||||
/* Render the new petals: */
|
||||
|
||||
|
|
@ -595,40 +578,37 @@ static void flower_colorize_petals(magic_api * api)
|
|||
SDL_LockSurface(flower_petals_colorized);
|
||||
|
||||
for (y = 0; y < flower_petals->h; y++)
|
||||
{
|
||||
for (x = 0; x < flower_petals->w; x++)
|
||||
{
|
||||
SDL_GetRGBA(api->getpixel(flower_petals, x, y),
|
||||
flower_petals->format, &r, &g, &b, &a);
|
||||
for (x = 0; x < flower_petals->w; x++)
|
||||
{
|
||||
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));
|
||||
api->putpixel(flower_petals_colorized, x, y,
|
||||
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))
|
||||
{
|
||||
api->putpixel(flower_petals_colorized, x, y,
|
||||
SDL_MapRGBA(flower_petals_colorized->format,
|
||||
0xFF, 0xFF, 0x00, a));
|
||||
}
|
||||
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_UnlockSurface(flower_petals_colorized);
|
||||
SDL_UnlockSurface(flower_petals);
|
||||
}
|
||||
|
||||
void flower_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void flower_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void flower_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void flower_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
int flower_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_PAINT_WITH_PREVIEW);
|
||||
return (MODE_PAINT_WITH_PREVIEW);
|
||||
}
|
||||
|
|
|
|||
435
magic/src/foam.c
435
magic/src/foam.c
|
|
@ -36,26 +36,23 @@
|
|||
|
||||
/* Our globals: */
|
||||
|
||||
static Mix_Chunk * foam_snd;
|
||||
static Mix_Chunk *foam_snd;
|
||||
static Uint8 foam_r, foam_g, foam_b;
|
||||
static int foam_mask_w, foam_mask_h;
|
||||
static int * foam_mask, * foam_mask_tmp;
|
||||
static SDL_Surface * foam_7, * foam_5, * foam_3, * foam_1;
|
||||
static int *foam_mask, *foam_mask_tmp;
|
||||
static SDL_Surface *foam_7, *foam_5, *foam_3, *foam_1;
|
||||
|
||||
Uint32 foam_api_version(void);
|
||||
int foam_init(magic_api * api);
|
||||
char * foam_get_description(magic_api * api, int which, int mode);
|
||||
char *foam_get_description(magic_api * api, int which, int mode);
|
||||
void foam_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void foam_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
void foam_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * foam_get_icon(magic_api * api, int which);
|
||||
char * foam_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface *foam_get_icon(magic_api * api, int which);
|
||||
char *foam_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED);
|
||||
void foam_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
void foam_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
void foam_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
|
|
@ -67,107 +64,113 @@ int foam_requires_colors(magic_api * api, int which);
|
|||
#define FOAM_PROP 8
|
||||
#define FOAM_RADIUS 3
|
||||
|
||||
Uint32 foam_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
Uint32 foam_api_version(void)
|
||||
{
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
|
||||
// No setup required:
|
||||
int foam_init(magic_api * api)
|
||||
{
|
||||
char fname[1024];
|
||||
SDL_Surface * foam_data;
|
||||
SDL_Surface *foam_data;
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/foam.ogg",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/foam.ogg", api->data_directory);
|
||||
foam_snd = Mix_LoadWAV(fname);
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/foam_data.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/foam_data.png", api->data_directory);
|
||||
foam_data = IMG_Load(fname);
|
||||
|
||||
foam_7 = api->scale(foam_data, ((api->canvas_w / FOAM_PROP) * 4) / 4,
|
||||
((api->canvas_h / FOAM_PROP) * 4) / 4, 0);
|
||||
foam_5 = api->scale(foam_data, ((api->canvas_w / FOAM_PROP) * 3) / 4,
|
||||
((api->canvas_h / FOAM_PROP) * 3) / 4, 0);
|
||||
foam_3 = api->scale(foam_data, ((api->canvas_w / FOAM_PROP) * 2) / 4,
|
||||
((api->canvas_h / FOAM_PROP) * 2) / 4, 0);
|
||||
foam_1 = api->scale(foam_data, ((api->canvas_w / FOAM_PROP) * 1) / 4,
|
||||
((api->canvas_h / FOAM_PROP) * 1) / 4, 0);
|
||||
foam_7 = api->scale(foam_data, ((api->canvas_w / FOAM_PROP) * 4) / 4, ((api->canvas_h / FOAM_PROP) * 4) / 4, 0);
|
||||
foam_5 = api->scale(foam_data, ((api->canvas_w / FOAM_PROP) * 3) / 4, ((api->canvas_h / FOAM_PROP) * 3) / 4, 0);
|
||||
foam_3 = api->scale(foam_data, ((api->canvas_w / FOAM_PROP) * 2) / 4, ((api->canvas_h / FOAM_PROP) * 2) / 4, 0);
|
||||
foam_1 = api->scale(foam_data, ((api->canvas_w / FOAM_PROP) * 1) / 4, ((api->canvas_h / FOAM_PROP) * 1) / 4, 0);
|
||||
|
||||
SDL_FreeSurface(foam_data);
|
||||
|
||||
return(1);
|
||||
|
||||
return (1);
|
||||
}
|
||||
|
||||
// We have multiple tools:
|
||||
int foam_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
// Load our icons:
|
||||
SDL_Surface * foam_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
SDL_Surface *foam_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/foam.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/foam.png", api->data_directory);
|
||||
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our names, localized:
|
||||
char * foam_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
char *foam_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(strdup(gettext_noop("Foam")));
|
||||
return (strdup(gettext_noop("Foam")));
|
||||
}
|
||||
|
||||
// Return our descriptions, localized:
|
||||
char * foam_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
||||
char *foam_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(strdup(gettext_noop("Click and drag the mouse to cover an area with foamy bubbles.")));
|
||||
return (strdup(gettext_noop("Click and drag the mouse to cover an area with foamy bubbles.")));
|
||||
}
|
||||
|
||||
// Do the effect:
|
||||
|
||||
static void do_foam(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x, int y)
|
||||
static void do_foam(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
int xx, yy, nx, ny;
|
||||
|
||||
/* SDL_Rect dest; */
|
||||
|
||||
for (yy = -FOAM_RADIUS; yy < FOAM_RADIUS; yy++)
|
||||
{
|
||||
for (xx = -FOAM_RADIUS; xx < FOAM_RADIUS; xx++)
|
||||
{
|
||||
if (api->in_circle(xx, yy, FOAM_RADIUS))
|
||||
{
|
||||
nx = (x / FOAM_PROP) + xx;
|
||||
ny = (y / FOAM_PROP) + yy;
|
||||
|
||||
if (nx >= 0 && ny >= 0 &&
|
||||
nx < foam_mask_w &&
|
||||
ny < foam_mask_h)
|
||||
for (xx = -FOAM_RADIUS; xx < FOAM_RADIUS; xx++)
|
||||
{
|
||||
foam_mask[ny * foam_mask_w + nx] = 1;
|
||||
if (api->in_circle(xx, yy, FOAM_RADIUS))
|
||||
{
|
||||
nx = (x / FOAM_PROP) + xx;
|
||||
ny = (y / FOAM_PROP) + yy;
|
||||
|
||||
if (nx >= 0 && ny >= 0 && nx < foam_mask_w && ny < foam_mask_h)
|
||||
{
|
||||
foam_mask[ny * foam_mask_w + nx] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Affect the canvas on drag:
|
||||
void foam_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_foam);
|
||||
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_foam);
|
||||
|
||||
foam_release(api, which, canvas, last, x, y, update_rect);
|
||||
|
||||
/* FIXME */
|
||||
if (ox > x) { int tmp = ox; ox = x; x = tmp; }
|
||||
if (oy > y) { int tmp = oy; oy = y; y = tmp; }
|
||||
if (ox > x)
|
||||
{
|
||||
int tmp = ox;
|
||||
|
||||
ox = x;
|
||||
x = tmp;
|
||||
}
|
||||
if (oy > y)
|
||||
{
|
||||
int tmp = oy;
|
||||
|
||||
oy = y;
|
||||
y = tmp;
|
||||
}
|
||||
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
|
|
@ -179,19 +182,19 @@ void foam_drag(magic_api * api, int which, SDL_Surface * canvas,
|
|||
|
||||
// Affect the canvas on click:
|
||||
void foam_click(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect)
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (foam_mask == NULL)
|
||||
{
|
||||
foam_mask_w = canvas->w / FOAM_PROP;
|
||||
foam_mask_h = canvas->h / FOAM_PROP;
|
||||
{
|
||||
foam_mask_w = canvas->w / FOAM_PROP;
|
||||
foam_mask_h = canvas->h / FOAM_PROP;
|
||||
|
||||
foam_mask = (int *) malloc(sizeof(int) * (foam_mask_w * foam_mask_h));
|
||||
foam_mask_tmp = (int *) malloc(sizeof(int) * (foam_mask_w * foam_mask_h));
|
||||
}
|
||||
foam_mask = (int *)malloc(sizeof(int) * (foam_mask_w * foam_mask_h));
|
||||
foam_mask_tmp = (int *)malloc(sizeof(int) * (foam_mask_w * foam_mask_h));
|
||||
}
|
||||
|
||||
for (i = 0; i < foam_mask_w * foam_mask_h; i++)
|
||||
foam_mask[i] = 0;
|
||||
|
|
@ -207,30 +210,30 @@ static int foam_mask_test(int r, int x, int y)
|
|||
tot = 0;
|
||||
|
||||
for (yy = 0; yy < r; yy++)
|
||||
{
|
||||
for (xx = 0; xx < r; xx++)
|
||||
{
|
||||
if (x + xx < foam_mask_w && y + yy < foam_mask_h)
|
||||
{
|
||||
bub_r = foam_mask[((y + yy) * foam_mask_w) + (x + xx)];
|
||||
tot = tot + bub_r;
|
||||
}
|
||||
for (xx = 0; xx < r; xx++)
|
||||
{
|
||||
if (x + xx < foam_mask_w && y + yy < foam_mask_h)
|
||||
{
|
||||
bub_r = foam_mask[((y + yy) * foam_mask_w) + (x + xx)];
|
||||
tot = tot + bub_r;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return(tot);
|
||||
return (tot);
|
||||
}
|
||||
|
||||
// Affect the canvas on release:
|
||||
void foam_release(magic_api * api ATTRIBUTE_UNUSED ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect)
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect)
|
||||
{
|
||||
int xx, yy;
|
||||
int changes, max_iters;
|
||||
SDL_Rect dest;
|
||||
int n;
|
||||
SDL_Surface * img;
|
||||
SDL_Surface *img;
|
||||
|
||||
SDL_BlitSurface(last, NULL, canvas, NULL);
|
||||
|
||||
|
|
@ -240,161 +243,161 @@ void foam_release(magic_api * api ATTRIBUTE_UNUSED ATTRIBUTE_UNUSED, int which A
|
|||
max_iters = 2;
|
||||
|
||||
do
|
||||
{
|
||||
changes = 0;
|
||||
max_iters--;
|
||||
|
||||
for (yy = 0; yy < foam_mask_h - 7; yy++)
|
||||
{
|
||||
for (xx = 0; xx < foam_mask_w - 7; xx++)
|
||||
{
|
||||
if (foam_mask_test(7, xx, yy) >= 40)
|
||||
changes = 0;
|
||||
max_iters--;
|
||||
|
||||
for (yy = 0; yy < foam_mask_h - 7; yy++)
|
||||
{
|
||||
foam_mask[((yy + 0) * foam_mask_w) + (xx + 0)] = 7;
|
||||
foam_mask[((yy + 0) * foam_mask_w) + (xx + 1)] = 0;
|
||||
foam_mask[((yy + 0) * foam_mask_w) + (xx + 2)] = 1;
|
||||
foam_mask[((yy + 0) * foam_mask_w) + (xx + 3)] = 0;
|
||||
foam_mask[((yy + 0) * foam_mask_w) + (xx + 4)] = 1;
|
||||
foam_mask[((yy + 0) * foam_mask_w) + (xx + 5)] = 2;
|
||||
foam_mask[((yy + 0) * foam_mask_w) + (xx + 6)] = 0;
|
||||
for (xx = 0; xx < foam_mask_w - 7; xx++)
|
||||
{
|
||||
if (foam_mask_test(7, xx, yy) >= 40)
|
||||
{
|
||||
foam_mask[((yy + 0) * foam_mask_w) + (xx + 0)] = 7;
|
||||
foam_mask[((yy + 0) * foam_mask_w) + (xx + 1)] = 0;
|
||||
foam_mask[((yy + 0) * foam_mask_w) + (xx + 2)] = 1;
|
||||
foam_mask[((yy + 0) * foam_mask_w) + (xx + 3)] = 0;
|
||||
foam_mask[((yy + 0) * foam_mask_w) + (xx + 4)] = 1;
|
||||
foam_mask[((yy + 0) * foam_mask_w) + (xx + 5)] = 2;
|
||||
foam_mask[((yy + 0) * foam_mask_w) + (xx + 6)] = 0;
|
||||
|
||||
foam_mask[((yy + 1) * foam_mask_w) + (xx + 0)] = 0;
|
||||
foam_mask[((yy + 1) * foam_mask_w) + (xx + 1)] = 1;
|
||||
foam_mask[((yy + 1) * foam_mask_w) + (xx + 2)] = 0;
|
||||
foam_mask[((yy + 1) * foam_mask_w) + (xx + 3)] = 0;
|
||||
foam_mask[((yy + 1) * foam_mask_w) + (xx + 4)] = 0;
|
||||
foam_mask[((yy + 1) * foam_mask_w) + (xx + 5)] = 2;
|
||||
foam_mask[((yy + 1) * foam_mask_w) + (xx + 6)] = 0;
|
||||
foam_mask[((yy + 1) * foam_mask_w) + (xx + 0)] = 0;
|
||||
foam_mask[((yy + 1) * foam_mask_w) + (xx + 1)] = 1;
|
||||
foam_mask[((yy + 1) * foam_mask_w) + (xx + 2)] = 0;
|
||||
foam_mask[((yy + 1) * foam_mask_w) + (xx + 3)] = 0;
|
||||
foam_mask[((yy + 1) * foam_mask_w) + (xx + 4)] = 0;
|
||||
foam_mask[((yy + 1) * foam_mask_w) + (xx + 5)] = 2;
|
||||
foam_mask[((yy + 1) * foam_mask_w) + (xx + 6)] = 0;
|
||||
|
||||
foam_mask[((yy + 2) * foam_mask_w) + (xx + 0)] = 1;
|
||||
foam_mask[((yy + 2) * foam_mask_w) + (xx + 1)] = 0;
|
||||
foam_mask[((yy + 2) * foam_mask_w) + (xx + 2)] = 0;
|
||||
foam_mask[((yy + 2) * foam_mask_w) + (xx + 3)] = 0;
|
||||
foam_mask[((yy + 2) * foam_mask_w) + (xx + 4)] = 0;
|
||||
foam_mask[((yy + 2) * foam_mask_w) + (xx + 5)] = 0;
|
||||
foam_mask[((yy + 2) * foam_mask_w) + (xx + 6)] = 1;
|
||||
foam_mask[((yy + 2) * foam_mask_w) + (xx + 0)] = 1;
|
||||
foam_mask[((yy + 2) * foam_mask_w) + (xx + 1)] = 0;
|
||||
foam_mask[((yy + 2) * foam_mask_w) + (xx + 2)] = 0;
|
||||
foam_mask[((yy + 2) * foam_mask_w) + (xx + 3)] = 0;
|
||||
foam_mask[((yy + 2) * foam_mask_w) + (xx + 4)] = 0;
|
||||
foam_mask[((yy + 2) * foam_mask_w) + (xx + 5)] = 0;
|
||||
foam_mask[((yy + 2) * foam_mask_w) + (xx + 6)] = 1;
|
||||
|
||||
foam_mask[((yy + 3) * foam_mask_w) + (xx + 0)] = 0;
|
||||
foam_mask[((yy + 3) * foam_mask_w) + (xx + 1)] = 1;
|
||||
foam_mask[((yy + 3) * foam_mask_w) + (xx + 2)] = 0;
|
||||
foam_mask[((yy + 3) * foam_mask_w) + (xx + 3)] = 0;
|
||||
foam_mask[((yy + 3) * foam_mask_w) + (xx + 4)] = 0;
|
||||
foam_mask[((yy + 3) * foam_mask_w) + (xx + 5)] = 0;
|
||||
foam_mask[((yy + 3) * foam_mask_w) + (xx + 6)] = 0;
|
||||
foam_mask[((yy + 3) * foam_mask_w) + (xx + 0)] = 0;
|
||||
foam_mask[((yy + 3) * foam_mask_w) + (xx + 1)] = 1;
|
||||
foam_mask[((yy + 3) * foam_mask_w) + (xx + 2)] = 0;
|
||||
foam_mask[((yy + 3) * foam_mask_w) + (xx + 3)] = 0;
|
||||
foam_mask[((yy + 3) * foam_mask_w) + (xx + 4)] = 0;
|
||||
foam_mask[((yy + 3) * foam_mask_w) + (xx + 5)] = 0;
|
||||
foam_mask[((yy + 3) * foam_mask_w) + (xx + 6)] = 0;
|
||||
|
||||
foam_mask[((yy + 4) * foam_mask_w) + (xx + 0)] = 1;
|
||||
foam_mask[((yy + 4) * foam_mask_w) + (xx + 1)] = 0;
|
||||
foam_mask[((yy + 4) * foam_mask_w) + (xx + 2)] = 0;
|
||||
foam_mask[((yy + 4) * foam_mask_w) + (xx + 3)] = 0;
|
||||
foam_mask[((yy + 4) * foam_mask_w) + (xx + 4)] = 0;
|
||||
foam_mask[((yy + 4) * foam_mask_w) + (xx + 5)] = 0;
|
||||
foam_mask[((yy + 4) * foam_mask_w) + (xx + 6)] = 1;
|
||||
foam_mask[((yy + 4) * foam_mask_w) + (xx + 0)] = 1;
|
||||
foam_mask[((yy + 4) * foam_mask_w) + (xx + 1)] = 0;
|
||||
foam_mask[((yy + 4) * foam_mask_w) + (xx + 2)] = 0;
|
||||
foam_mask[((yy + 4) * foam_mask_w) + (xx + 3)] = 0;
|
||||
foam_mask[((yy + 4) * foam_mask_w) + (xx + 4)] = 0;
|
||||
foam_mask[((yy + 4) * foam_mask_w) + (xx + 5)] = 0;
|
||||
foam_mask[((yy + 4) * foam_mask_w) + (xx + 6)] = 1;
|
||||
|
||||
foam_mask[((yy + 5) * foam_mask_w) + (xx + 0)] = 2;
|
||||
foam_mask[((yy + 5) * foam_mask_w) + (xx + 1)] = 0;
|
||||
foam_mask[((yy + 5) * foam_mask_w) + (xx + 2)] = 0;
|
||||
foam_mask[((yy + 5) * foam_mask_w) + (xx + 3)] = 7;
|
||||
foam_mask[((yy + 5) * foam_mask_w) + (xx + 4)] = 0;
|
||||
foam_mask[((yy + 5) * foam_mask_w) + (xx + 5)] = 3;
|
||||
foam_mask[((yy + 5) * foam_mask_w) + (xx + 6)] = 0;
|
||||
foam_mask[((yy + 5) * foam_mask_w) + (xx + 0)] = 2;
|
||||
foam_mask[((yy + 5) * foam_mask_w) + (xx + 1)] = 0;
|
||||
foam_mask[((yy + 5) * foam_mask_w) + (xx + 2)] = 0;
|
||||
foam_mask[((yy + 5) * foam_mask_w) + (xx + 3)] = 7;
|
||||
foam_mask[((yy + 5) * foam_mask_w) + (xx + 4)] = 0;
|
||||
foam_mask[((yy + 5) * foam_mask_w) + (xx + 5)] = 3;
|
||||
foam_mask[((yy + 5) * foam_mask_w) + (xx + 6)] = 0;
|
||||
|
||||
foam_mask[((yy + 6) * foam_mask_w) + (xx + 0)] = 0;
|
||||
foam_mask[((yy + 6) * foam_mask_w) + (xx + 1)] = 0;
|
||||
foam_mask[((yy + 6) * foam_mask_w) + (xx + 2)] = 1;
|
||||
foam_mask[((yy + 6) * foam_mask_w) + (xx + 3)] = 0;
|
||||
foam_mask[((yy + 6) * foam_mask_w) + (xx + 4)] = 1;
|
||||
foam_mask[((yy + 6) * foam_mask_w) + (xx + 5)] = 0;
|
||||
foam_mask[((yy + 6) * foam_mask_w) + (xx + 6)] = 2;
|
||||
foam_mask[((yy + 6) * foam_mask_w) + (xx + 0)] = 0;
|
||||
foam_mask[((yy + 6) * foam_mask_w) + (xx + 1)] = 0;
|
||||
foam_mask[((yy + 6) * foam_mask_w) + (xx + 2)] = 1;
|
||||
foam_mask[((yy + 6) * foam_mask_w) + (xx + 3)] = 0;
|
||||
foam_mask[((yy + 6) * foam_mask_w) + (xx + 4)] = 1;
|
||||
foam_mask[((yy + 6) * foam_mask_w) + (xx + 5)] = 0;
|
||||
foam_mask[((yy + 6) * foam_mask_w) + (xx + 6)] = 2;
|
||||
|
||||
changes = 1;
|
||||
changes = 1;
|
||||
}
|
||||
else if (foam_mask_test(5, xx, yy) >= 30)
|
||||
{
|
||||
foam_mask[((yy + 0) * foam_mask_w) + (xx + 0)] = 2;
|
||||
foam_mask[((yy + 0) * foam_mask_w) + (xx + 1)] = 1;
|
||||
foam_mask[((yy + 0) * foam_mask_w) + (xx + 2)] = 0;
|
||||
foam_mask[((yy + 0) * foam_mask_w) + (xx + 3)] = 1;
|
||||
foam_mask[((yy + 0) * foam_mask_w) + (xx + 4)] = 2;
|
||||
|
||||
foam_mask[((yy + 1) * foam_mask_w) + (xx + 0)] = 1;
|
||||
foam_mask[((yy + 1) * foam_mask_w) + (xx + 1)] = 0;
|
||||
foam_mask[((yy + 1) * foam_mask_w) + (xx + 2)] = 0;
|
||||
foam_mask[((yy + 1) * foam_mask_w) + (xx + 3)] = 0;
|
||||
foam_mask[((yy + 1) * foam_mask_w) + (xx + 4)] = 1;
|
||||
|
||||
foam_mask[((yy + 2) * foam_mask_w) + (xx + 0)] = 0;
|
||||
foam_mask[((yy + 2) * foam_mask_w) + (xx + 1)] = 0;
|
||||
foam_mask[((yy + 2) * foam_mask_w) + (xx + 2)] = 5;
|
||||
foam_mask[((yy + 2) * foam_mask_w) + (xx + 3)] = 0;
|
||||
foam_mask[((yy + 2) * foam_mask_w) + (xx + 4)] = 0;
|
||||
|
||||
foam_mask[((yy + 3) * foam_mask_w) + (xx + 0)] = 2;
|
||||
foam_mask[((yy + 3) * foam_mask_w) + (xx + 1)] = 0;
|
||||
foam_mask[((yy + 3) * foam_mask_w) + (xx + 2)] = 1;
|
||||
foam_mask[((yy + 3) * foam_mask_w) + (xx + 3)] = 2;
|
||||
foam_mask[((yy + 3) * foam_mask_w) + (xx + 4)] = 0;
|
||||
|
||||
foam_mask[((yy + 4) * foam_mask_w) + (xx + 0)] = 0;
|
||||
foam_mask[((yy + 4) * foam_mask_w) + (xx + 1)] = 1;
|
||||
foam_mask[((yy + 4) * foam_mask_w) + (xx + 2)] = 0;
|
||||
foam_mask[((yy + 4) * foam_mask_w) + (xx + 3)] = 1;
|
||||
foam_mask[((yy + 4) * foam_mask_w) + (xx + 4)] = 0;
|
||||
|
||||
changes = 1;
|
||||
}
|
||||
else if (foam_mask_test(3, xx, yy) >= 8)
|
||||
{
|
||||
foam_mask[((yy + 0) * foam_mask_w) + (xx + 0)] = 1;
|
||||
foam_mask[((yy + 0) * foam_mask_w) + (xx + 1)] = 0;
|
||||
foam_mask[((yy + 0) * foam_mask_w) + (xx + 2)] = 1;
|
||||
|
||||
foam_mask[((yy + 1) * foam_mask_w) + (xx + 0)] = 0;
|
||||
foam_mask[((yy + 1) * foam_mask_w) + (xx + 1)] = 3;
|
||||
foam_mask[((yy + 1) * foam_mask_w) + (xx + 2)] = 0;
|
||||
|
||||
foam_mask[((yy + 2) * foam_mask_w) + (xx + 0)] = 1;
|
||||
foam_mask[((yy + 2) * foam_mask_w) + (xx + 1)] = 0;
|
||||
foam_mask[((yy + 2) * foam_mask_w) + (xx + 2)] = 1;
|
||||
|
||||
changes = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (foam_mask_test(5, xx, yy) >= 30)
|
||||
{
|
||||
foam_mask[((yy + 0) * foam_mask_w) + (xx + 0)] = 2;
|
||||
foam_mask[((yy + 0) * foam_mask_w) + (xx + 1)] = 1;
|
||||
foam_mask[((yy + 0) * foam_mask_w) + (xx + 2)] = 0;
|
||||
foam_mask[((yy + 0) * foam_mask_w) + (xx + 3)] = 1;
|
||||
foam_mask[((yy + 0) * foam_mask_w) + (xx + 4)] = 2;
|
||||
|
||||
foam_mask[((yy + 1) * foam_mask_w) + (xx + 0)] = 1;
|
||||
foam_mask[((yy + 1) * foam_mask_w) + (xx + 1)] = 0;
|
||||
foam_mask[((yy + 1) * foam_mask_w) + (xx + 2)] = 0;
|
||||
foam_mask[((yy + 1) * foam_mask_w) + (xx + 3)] = 0;
|
||||
foam_mask[((yy + 1) * foam_mask_w) + (xx + 4)] = 1;
|
||||
|
||||
foam_mask[((yy + 2) * foam_mask_w) + (xx + 0)] = 0;
|
||||
foam_mask[((yy + 2) * foam_mask_w) + (xx + 1)] = 0;
|
||||
foam_mask[((yy + 2) * foam_mask_w) + (xx + 2)] = 5;
|
||||
foam_mask[((yy + 2) * foam_mask_w) + (xx + 3)] = 0;
|
||||
foam_mask[((yy + 2) * foam_mask_w) + (xx + 4)] = 0;
|
||||
|
||||
foam_mask[((yy + 3) * foam_mask_w) + (xx + 0)] = 2;
|
||||
foam_mask[((yy + 3) * foam_mask_w) + (xx + 1)] = 0;
|
||||
foam_mask[((yy + 3) * foam_mask_w) + (xx + 2)] = 1;
|
||||
foam_mask[((yy + 3) * foam_mask_w) + (xx + 3)] = 2;
|
||||
foam_mask[((yy + 3) * foam_mask_w) + (xx + 4)] = 0;
|
||||
|
||||
foam_mask[((yy + 4) * foam_mask_w) + (xx + 0)] = 0;
|
||||
foam_mask[((yy + 4) * foam_mask_w) + (xx + 1)] = 1;
|
||||
foam_mask[((yy + 4) * foam_mask_w) + (xx + 2)] = 0;
|
||||
foam_mask[((yy + 4) * foam_mask_w) + (xx + 3)] = 1;
|
||||
foam_mask[((yy + 4) * foam_mask_w) + (xx + 4)] = 0;
|
||||
|
||||
changes = 1;
|
||||
}
|
||||
else if (foam_mask_test(3, xx, yy) >= 8)
|
||||
{
|
||||
foam_mask[((yy + 0) * foam_mask_w) + (xx + 0)] = 1;
|
||||
foam_mask[((yy + 0) * foam_mask_w) + (xx + 1)] = 0;
|
||||
foam_mask[((yy + 0) * foam_mask_w) + (xx + 2)] = 1;
|
||||
|
||||
foam_mask[((yy + 1) * foam_mask_w) + (xx + 0)] = 0;
|
||||
foam_mask[((yy + 1) * foam_mask_w) + (xx + 1)] = 3;
|
||||
foam_mask[((yy + 1) * foam_mask_w) + (xx + 2)] = 0;
|
||||
|
||||
foam_mask[((yy + 2) * foam_mask_w) + (xx + 0)] = 1;
|
||||
foam_mask[((yy + 2) * foam_mask_w) + (xx + 1)] = 0;
|
||||
foam_mask[((yy + 2) * foam_mask_w) + (xx + 2)] = 1;
|
||||
|
||||
changes = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
while (changes && max_iters > 0);
|
||||
|
||||
|
||||
for (yy = 0; yy < foam_mask_h; yy++)
|
||||
{
|
||||
for (xx = 0; xx < foam_mask_w; xx++)
|
||||
{
|
||||
n = foam_mask[yy * foam_mask_w + xx];
|
||||
for (xx = 0; xx < foam_mask_w; xx++)
|
||||
{
|
||||
n = foam_mask[yy * foam_mask_w + xx];
|
||||
|
||||
img = NULL;
|
||||
img = NULL;
|
||||
|
||||
|
||||
if (n == 1)
|
||||
img = foam_1;
|
||||
else if (n == 3)
|
||||
img = foam_3;
|
||||
else if (n == 5)
|
||||
img = foam_5;
|
||||
else if (n == 7)
|
||||
img = foam_7;
|
||||
|
||||
if (img != NULL)
|
||||
{
|
||||
dest.x = (xx * FOAM_PROP) - (img->w / 2) + ((rand() % 15) - 7);
|
||||
dest.y = (yy * FOAM_PROP) - (img->h / 2) + ((rand() % 15) - 7);
|
||||
if (n == 1)
|
||||
img = foam_1;
|
||||
else if (n == 3)
|
||||
img = foam_3;
|
||||
else if (n == 5)
|
||||
img = foam_5;
|
||||
else if (n == 7)
|
||||
img = foam_7;
|
||||
|
||||
SDL_BlitSurface(img, NULL, canvas, &dest);
|
||||
}
|
||||
if (img != NULL)
|
||||
{
|
||||
dest.x = (xx * FOAM_PROP) - (img->w / 2) + ((rand() % 15) - 7);
|
||||
dest.y = (yy * FOAM_PROP) - (img->h / 2) + ((rand() % 15) - 7);
|
||||
|
||||
SDL_BlitSurface(img, NULL, canvas, &dest);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
memcpy(foam_mask, foam_mask_tmp, (sizeof(int) * (foam_mask_w * foam_mask_h)));
|
||||
|
||||
|
||||
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
|
|
@ -409,7 +412,7 @@ void foam_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
|||
|
||||
if (foam_mask != NULL)
|
||||
free(foam_mask);
|
||||
|
||||
|
||||
if (foam_1 != NULL)
|
||||
SDL_FreeSurface(foam_1);
|
||||
if (foam_3 != NULL)
|
||||
|
|
@ -431,18 +434,20 @@ void foam_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b)
|
|||
// Use colors:
|
||||
int foam_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return 0; /* FIXME: Would be nice to tint the bubbles */
|
||||
return 0; /* FIXME: Would be nice to tint the bubbles */
|
||||
}
|
||||
|
||||
void foam_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void foam_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void foam_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void foam_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
int foam_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_PAINT);
|
||||
return (MODE_PAINT);
|
||||
}
|
||||
|
|
|
|||
577
magic/src/fold.c
577
magic/src/fold.c
|
|
@ -15,76 +15,67 @@ int fold_ox, fold_oy;
|
|||
int fold_x, fold_y;
|
||||
Uint8 fold_shadow_value;
|
||||
Uint8 corner;
|
||||
Mix_Chunk * fold_snd;
|
||||
Mix_Chunk *fold_snd;
|
||||
Uint8 fold_r, fold_g, fold_b;
|
||||
Uint32 fold_color;
|
||||
SDL_Surface * fold_surface_src, * fold_surface_dst;
|
||||
SDL_Surface *fold_surface_src, *fold_surface_dst;
|
||||
|
||||
|
||||
void fold_draw(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
static void fold_erase(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y);
|
||||
void translate_coords(SDL_Surface * canvas,int angle);
|
||||
SDL_Surface * rotate(magic_api * api, SDL_Surface * canvas, int angle);
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
|
||||
static void fold_erase(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||
void translate_coords(SDL_Surface * canvas, int angle);
|
||||
SDL_Surface *rotate(magic_api * api, SDL_Surface * canvas, int angle);
|
||||
void fold_draw(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
static void fold_print_line(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y);
|
||||
static void fold_print_dark_line(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y);
|
||||
void translate_xy(SDL_Surface * canvas, int x, int y, int * a, int * b, int rotation);
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
|
||||
static void fold_print_line(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||
static void fold_print_dark_line(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||
void translate_xy(SDL_Surface * canvas, int x, int y, int *a, int *b, int rotation);
|
||||
Uint32 fold_api_version(void);
|
||||
void fold_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
int fold_init(magic_api * api);
|
||||
int fold_get_tool_count(magic_api * api);
|
||||
SDL_Surface * fold_get_icon(magic_api * api, int which);
|
||||
char * fold_get_name(magic_api * api, int which);
|
||||
char * fold_get_description(magic_api * api, int which, int mode);
|
||||
SDL_Surface *fold_get_icon(magic_api * api, int which);
|
||||
char *fold_get_name(magic_api * api, int which);
|
||||
char *fold_get_description(magic_api * api, int which, int mode);
|
||||
int fold_requires_colors(magic_api * api, int which);
|
||||
void fold_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
|
||||
void fold_shutdown(magic_api * api);
|
||||
void fold_click(magic_api * ptr, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
|
||||
void fold_preview(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
int fold_modes(magic_api * api, int which);
|
||||
// Housekeeping functions
|
||||
|
||||
// Housekeeping functions
|
||||
|
||||
void fold_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
void fold_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
inline Uint8 fold_what_corner(int x, int y, SDL_Surface * canvas);
|
||||
void fold_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
|
||||
Uint32 fold_api_version(void)
|
||||
|
||||
{
|
||||
return(TP_MAGIC_API_VERSION);
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
void fold_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b) //get the colors from API and store it in structure
|
||||
void fold_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b) //get the colors from API and store it in structure
|
||||
{
|
||||
fold_r=r;
|
||||
fold_g=g;
|
||||
fold_b=b;
|
||||
fold_r = r;
|
||||
fold_g = g;
|
||||
fold_b = b;
|
||||
}
|
||||
|
||||
int fold_init(magic_api * api)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/fold.wav", api->data_directory);
|
||||
fold_snd = Mix_LoadWAV(fname);
|
||||
|
||||
return(1);
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/fold.wav", api->data_directory);
|
||||
fold_snd = Mix_LoadWAV(fname);
|
||||
|
||||
return (1);
|
||||
}
|
||||
|
||||
int fold_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
|
|
@ -92,386 +83,421 @@ int fold_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
|||
return 1;
|
||||
}
|
||||
|
||||
SDL_Surface * fold_get_icon(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
SDL_Surface *fold_get_icon(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/fold.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/fold.png", api->data_directory);
|
||||
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
char * fold_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) { return(gettext_noop("Fold")); }
|
||||
|
||||
char * fold_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED) { return strdup(gettext_noop("Choose a background color and click to turn the corner of the page over.")); }
|
||||
|
||||
int fold_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) { return 1; } //selected color will be a "backpage" color
|
||||
|
||||
|
||||
static void fold_shadow(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * temp,
|
||||
int x, int y)
|
||||
char *fold_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
Uint8 r,g,b,a;
|
||||
SDL_GetRGBA(api->getpixel(temp, x, y),
|
||||
temp->format, &r, &g, &b, &a);
|
||||
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));
|
||||
return (gettext_noop("Fold"));
|
||||
}
|
||||
|
||||
char *fold_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return strdup(gettext_noop("Choose a background color and click to turn the corner of the page over."));
|
||||
}
|
||||
|
||||
int fold_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return 1;
|
||||
} //selected color will be a "backpage" color
|
||||
|
||||
|
||||
static void fold_shadow(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * temp, int x, int y)
|
||||
{
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
Uint8 r, g, b, a;
|
||||
|
||||
SDL_GetRGBA(api->getpixel(temp, x, y), temp->format, &r, &g, &b, &a);
|
||||
api->putpixel(canvas, x, y, SDL_MapRGBA(canvas->format,
|
||||
max(r - 160 + fold_shadow_value * 4, 0), max(g - 160 + fold_shadow_value * 4,
|
||||
0),
|
||||
max(b - 160 + fold_shadow_value * 4, 0), a));
|
||||
}
|
||||
|
||||
void fold_draw(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
float right_step_x, right_step_y, left_step_x, left_step_y;
|
||||
float dist_x, dist_y;
|
||||
int left_y, right_x;
|
||||
float w, h;
|
||||
SDL_Surface * temp;
|
||||
temp=SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h, canvas->format->BitsPerPixel,
|
||||
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
|
||||
SDL_BlitSurface(canvas,0,temp,0);
|
||||
SDL_Surface *temp;
|
||||
|
||||
right_step_x=(float)(x-left_arm_x)/(float)(left_arm_x-fold_ox);
|
||||
right_step_y=(float)(y-left_arm_y)/(float)(left_arm_x-fold_ox);
|
||||
left_step_x=(float)(x-right_arm_x)/(float)(right_arm_y-fold_oy);
|
||||
left_step_y=(float)(y-right_arm_y)/(float)(right_arm_y-fold_oy);
|
||||
for (w=0;w < canvas->w;w+=0.5)
|
||||
for(h=0;h < canvas->h;h+=0.5)
|
||||
temp = SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h, canvas->format->BitsPerPixel,
|
||||
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask,
|
||||
canvas->format->Amask);
|
||||
SDL_BlitSurface(canvas, 0, temp, 0);
|
||||
|
||||
right_step_x = (float)(x - left_arm_x) / (float)(left_arm_x - fold_ox);
|
||||
right_step_y = (float)(y - left_arm_y) / (float)(left_arm_x - fold_ox);
|
||||
left_step_x = (float)(x - right_arm_x) / (float)(right_arm_y - fold_oy);
|
||||
left_step_y = (float)(y - right_arm_y) / (float)(right_arm_y - fold_oy);
|
||||
for (w = 0; w < canvas->w; w += 0.5)
|
||||
for (h = 0; h < canvas->h; h += 0.5)
|
||||
{
|
||||
dist_x=right_step_x*w+left_step_x*h;
|
||||
dist_y=right_step_y*w+left_step_y*h;
|
||||
api->putpixel(canvas, x-dist_x, y-dist_y, api->getpixel(temp,w,h));
|
||||
dist_x = right_step_x * w + left_step_x * h;
|
||||
dist_y = right_step_y * w + left_step_y * h;
|
||||
api->putpixel(canvas, x - dist_x, y - dist_y, api->getpixel(temp, w, h));
|
||||
}
|
||||
|
||||
// Erasing the triangle.
|
||||
// The 1 pixel in plus is a workaround for api-line not getting the end in some lines.
|
||||
if (left_arm_x > canvas->w)
|
||||
{
|
||||
left_y=(float)right_arm_y/left_arm_x*(left_arm_x-canvas->w);
|
||||
left_y = (float)right_arm_y / left_arm_x * (left_arm_x - canvas->w);
|
||||
for (h = 0; h <= right_arm_y; h++)
|
||||
api->line((void *)api, which, canvas, snapshot, canvas->w, left_y-h, -1, right_arm_y-h, 1, fold_erase);
|
||||
api->line((void *)api, which, canvas, snapshot, canvas->w, left_y - h, -1, right_arm_y - h, 1, fold_erase);
|
||||
}
|
||||
else if (right_arm_y > canvas->h)
|
||||
{
|
||||
right_x=(float)left_arm_x/right_arm_y*(right_arm_y-canvas->h);
|
||||
right_x = (float)left_arm_x / right_arm_y * (right_arm_y - canvas->h);
|
||||
for (w = 0; w <= left_arm_x; w++)
|
||||
api->line((void *)api, which, canvas, snapshot, left_arm_x-w, 0, right_x-w, canvas->h +1, 1, fold_erase);
|
||||
api->line((void *)api, which, canvas, snapshot, left_arm_x - w, 0, right_x - w, canvas->h + 1, 1, fold_erase);
|
||||
}
|
||||
else
|
||||
for (w = 0; w <= min(left_arm_x,right_arm_y); w++) // The -1 values are because api->line
|
||||
api->line((void *)api, which, canvas, snapshot, left_arm_x-w, 0, -1, right_arm_y-w, 1, fold_erase);
|
||||
for (w = 0; w <= min(left_arm_x, right_arm_y); w++) // The -1 values are because api->line
|
||||
api->line((void *)api, which, canvas, snapshot, left_arm_x - w, 0, -1, right_arm_y - w, 1, fold_erase);
|
||||
|
||||
SDL_BlitSurface(canvas,0,temp,0);
|
||||
SDL_BlitSurface(canvas, 0, temp, 0);
|
||||
|
||||
// Shadows
|
||||
if (left_arm_x > canvas->w)
|
||||
{
|
||||
for (fold_shadow_value = 0; fold_shadow_value < 40; fold_shadow_value+=1)
|
||||
api->line((void *)api, which, canvas, temp, canvas->w, left_y-fold_shadow_value, 0, right_arm_y-fold_shadow_value, 1, fold_shadow);
|
||||
for (fold_shadow_value = 0; fold_shadow_value < 40; fold_shadow_value += 1)
|
||||
api->line((void *)api, which, canvas, temp, canvas->w, left_y - fold_shadow_value, 0,
|
||||
right_arm_y - fold_shadow_value, 1, fold_shadow);
|
||||
|
||||
}
|
||||
else if (right_arm_y > canvas->h)
|
||||
{
|
||||
for (fold_shadow_value = 0; fold_shadow_value < 40; fold_shadow_value+=1)
|
||||
api->line((void *)api, which, canvas, temp, left_arm_x-fold_shadow_value, 0, right_x - fold_shadow_value, canvas->h, 1, fold_shadow);
|
||||
for (fold_shadow_value = 0; fold_shadow_value < 40; fold_shadow_value += 1)
|
||||
api->line((void *)api, which, canvas, temp, left_arm_x - fold_shadow_value, 0, right_x - fold_shadow_value,
|
||||
canvas->h, 1, fold_shadow);
|
||||
|
||||
}
|
||||
|
||||
else
|
||||
for (fold_shadow_value = 0; fold_shadow_value < 40; fold_shadow_value+=1)
|
||||
api->line((void *)api, which, canvas, temp, left_arm_x-fold_shadow_value, 0, 0, right_arm_y-fold_shadow_value, 1, fold_shadow);
|
||||
for (fold_shadow_value = 0; fold_shadow_value < 40; fold_shadow_value += 1)
|
||||
api->line((void *)api, which, canvas, temp, left_arm_x - fold_shadow_value, 0, 0, right_arm_y - fold_shadow_value,
|
||||
1, fold_shadow);
|
||||
|
||||
SDL_BlitSurface(canvas,0,temp,0);
|
||||
SDL_BlitSurface(canvas, 0, temp, 0);
|
||||
|
||||
for (fold_shadow_value = 0; fold_shadow_value < 40; fold_shadow_value+=1)
|
||||
for (fold_shadow_value = 0; fold_shadow_value < 40; fold_shadow_value += 1)
|
||||
{
|
||||
if (fold_shadow_value*left_step_x > x || fold_shadow_value*right_step_y > y) break;
|
||||
if (fold_shadow_value * left_step_x > x || fold_shadow_value * right_step_y > y)
|
||||
break;
|
||||
|
||||
dist_x=fold_shadow_value*(right_step_x+left_step_x);
|
||||
dist_y=fold_shadow_value*(right_step_y+left_step_y);
|
||||
api->line((void *)api, which, canvas, temp, left_arm_x+fold_shadow_value*right_step_x, fold_shadow_value*right_step_y, fold_shadow_value*left_step_x, right_arm_y+fold_shadow_value*left_step_y, 1, fold_shadow);
|
||||
dist_x = fold_shadow_value * (right_step_x + left_step_x);
|
||||
dist_y = fold_shadow_value * (right_step_y + left_step_y);
|
||||
api->line((void *)api, which, canvas, temp, left_arm_x + fold_shadow_value * right_step_x,
|
||||
fold_shadow_value * right_step_y, fold_shadow_value * left_step_x,
|
||||
right_arm_y + fold_shadow_value * left_step_y, 1, fold_shadow);
|
||||
}
|
||||
|
||||
api->line((void *)api, which, canvas, snapshot, x, y, right_arm_x, right_arm_y, 1, fold_print_line);
|
||||
api->line((void *)api, which, canvas, snapshot, x, y, left_arm_x, left_arm_y, 1, fold_print_line);
|
||||
api->line((void *)api, which, canvas, snapshot, left_arm_x, left_arm_y, right_arm_x, right_arm_y, 1, fold_print_dark_line);
|
||||
api->line((void *)api, which, canvas, snapshot, left_arm_x, left_arm_y, right_arm_x, right_arm_y, 1,
|
||||
fold_print_dark_line);
|
||||
|
||||
}
|
||||
|
||||
SDL_Surface * rotate(magic_api * api, SDL_Surface * canvas, int angle)
|
||||
SDL_Surface *rotate(magic_api * api, SDL_Surface * canvas, int angle)
|
||||
{
|
||||
SDL_Surface * temp;
|
||||
int x,y;
|
||||
int a,b;
|
||||
SDL_Surface *temp;
|
||||
int x, y;
|
||||
int a, b;
|
||||
|
||||
if (angle==180)
|
||||
temp=SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h, canvas->format->BitsPerPixel,
|
||||
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
|
||||
if (angle == 180)
|
||||
temp = SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h, canvas->format->BitsPerPixel,
|
||||
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask,
|
||||
canvas->format->Amask);
|
||||
else
|
||||
temp=SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->h, canvas->w, canvas->format->BitsPerPixel,
|
||||
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
|
||||
temp = SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->h, canvas->w, canvas->format->BitsPerPixel,
|
||||
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask,
|
||||
canvas->format->Amask);
|
||||
|
||||
switch (angle)
|
||||
{
|
||||
case 90:
|
||||
for (x=0; x<canvas->w; x++)
|
||||
for (y=0; y<canvas->h; y++)
|
||||
{
|
||||
translate_xy(canvas,x,y,&a,&b,90);
|
||||
api->putpixel(temp,a,b,api->getpixel(canvas, x, y));
|
||||
}
|
||||
break;
|
||||
|
||||
for (x = 0; x < canvas->w; x++)
|
||||
for (y = 0; y < canvas->h; y++)
|
||||
{
|
||||
translate_xy(canvas, x, y, &a, &b, 90);
|
||||
api->putpixel(temp, a, b, api->getpixel(canvas, x, y));
|
||||
}
|
||||
break;
|
||||
|
||||
case 180:
|
||||
// printf("%i, %i\n",temp,canvas);
|
||||
for (x=0; x<canvas->w; x++)
|
||||
for (y=0; y<canvas->h; y++)
|
||||
{
|
||||
translate_xy(canvas,x,y,&a,&b,180);
|
||||
api->putpixel(temp,a,b,api->getpixel(canvas, x, y));
|
||||
}
|
||||
for (x = 0; x < canvas->w; x++)
|
||||
for (y = 0; y < canvas->h; y++)
|
||||
{
|
||||
translate_xy(canvas, x, y, &a, &b, 180);
|
||||
api->putpixel(temp, a, b, api->getpixel(canvas, x, y));
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case 270:
|
||||
for (x=0; x<canvas->w; x++)
|
||||
for (y=0; y<canvas->h; y++)
|
||||
{
|
||||
translate_xy(canvas,x,y,&a,&b,270);
|
||||
api->putpixel(temp,a,b,api->getpixel(canvas, x, y));
|
||||
}
|
||||
for (x = 0; x < canvas->w; x++)
|
||||
for (y = 0; y < canvas->h; y++)
|
||||
{
|
||||
translate_xy(canvas, x, y, &a, &b, 270);
|
||||
api->putpixel(temp, a, b, api->getpixel(canvas, x, y));
|
||||
}
|
||||
break;
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
void translate_coords(SDL_Surface * canvas,int angle)
|
||||
void translate_coords(SDL_Surface * canvas, int angle)
|
||||
{
|
||||
int a,b;
|
||||
int a, b;
|
||||
|
||||
switch (angle)
|
||||
{
|
||||
case 90:
|
||||
translate_xy(canvas,right_arm_x,right_arm_y,&a,&b,90);
|
||||
right_arm_x=a;
|
||||
right_arm_y=b;
|
||||
translate_xy(canvas,left_arm_x,left_arm_y,&a,&b,90);
|
||||
left_arm_x=a;
|
||||
left_arm_y=b;
|
||||
case 90:
|
||||
translate_xy(canvas, right_arm_x, right_arm_y, &a, &b, 90);
|
||||
right_arm_x = a;
|
||||
right_arm_y = b;
|
||||
translate_xy(canvas, left_arm_x, left_arm_y, &a, &b, 90);
|
||||
left_arm_x = a;
|
||||
left_arm_y = b;
|
||||
|
||||
break;
|
||||
case 180:
|
||||
right_arm_x=canvas->w-1-right_arm_x;
|
||||
right_arm_y=canvas->h-1-right_arm_y;
|
||||
left_arm_x=canvas->w-1-left_arm_x;
|
||||
left_arm_y=canvas->h-1-left_arm_y;
|
||||
break;
|
||||
case 270:
|
||||
translate_xy(canvas,right_arm_x,right_arm_y,&a,&b,270);
|
||||
right_arm_x=a;
|
||||
right_arm_y=b;
|
||||
translate_xy(canvas,left_arm_x, left_arm_y, &a, &b, 270);
|
||||
left_arm_x=a;
|
||||
left_arm_y=b;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 180:
|
||||
right_arm_x = canvas->w - 1 - right_arm_x;
|
||||
right_arm_y = canvas->h - 1 - right_arm_y;
|
||||
left_arm_x = canvas->w - 1 - left_arm_x;
|
||||
left_arm_y = canvas->h - 1 - left_arm_y;
|
||||
break;
|
||||
case 270:
|
||||
translate_xy(canvas, right_arm_x, right_arm_y, &a, &b, 270);
|
||||
right_arm_x = a;
|
||||
right_arm_y = b;
|
||||
translate_xy(canvas, left_arm_x, left_arm_y, &a, &b, 270);
|
||||
left_arm_x = a;
|
||||
left_arm_y = b;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void translate_xy(SDL_Surface * canvas, int x, int y, int * a, int * b, int rotation)
|
||||
void translate_xy(SDL_Surface * canvas, int x, int y, int *a, int *b, int rotation)
|
||||
{
|
||||
switch (rotation)
|
||||
{
|
||||
case 90:
|
||||
*a=y;
|
||||
*b=canvas->w -1 -x;
|
||||
*a = y;
|
||||
*b = canvas->w - 1 - x;
|
||||
break;
|
||||
case 180:
|
||||
*a=canvas->w -1 -x;
|
||||
*b=canvas->h -1 -y;
|
||||
*a = canvas->w - 1 - x;
|
||||
*b = canvas->h - 1 - y;
|
||||
break;
|
||||
case 270:
|
||||
*a=canvas->h -1 -y;
|
||||
*b=x;
|
||||
break;
|
||||
*a = canvas->h - 1 - y;
|
||||
*b = x;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void fold_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect)
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
int a,b;
|
||||
SDL_Surface * temp, *temp2;
|
||||
int a, b;
|
||||
SDL_Surface *temp, *temp2;
|
||||
|
||||
x=fold_x;
|
||||
y=fold_y;
|
||||
fold_ox=fold_oy=0;
|
||||
x = fold_x;
|
||||
y = fold_y;
|
||||
fold_ox = fold_oy = 0;
|
||||
SDL_BlitSurface(snapshot, 0, canvas, 0);
|
||||
switch (corner)
|
||||
{
|
||||
case 1:
|
||||
translate_xy(canvas,x,y,&a,&b,90);
|
||||
translate_coords(canvas,90);
|
||||
temp=rotate(api, canvas, 90);
|
||||
fold_draw (api, which, temp, snapshot, a, b,update_rect);
|
||||
temp2=rotate(api,temp,270);
|
||||
SDL_BlitSurface(temp2,0,canvas,0);
|
||||
translate_xy(canvas, x, y, &a, &b, 90);
|
||||
translate_coords(canvas, 90);
|
||||
temp = rotate(api, canvas, 90);
|
||||
fold_draw(api, which, temp, snapshot, a, b, update_rect);
|
||||
temp2 = rotate(api, temp, 270);
|
||||
SDL_BlitSurface(temp2, 0, canvas, 0);
|
||||
SDL_FreeSurface(temp);
|
||||
SDL_FreeSurface(temp2);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
fold_draw (api, which, canvas, snapshot, x,y,update_rect);
|
||||
fold_draw(api, which, canvas, snapshot, x, y, update_rect);
|
||||
break;
|
||||
|
||||
|
||||
case 3:
|
||||
translate_xy(canvas,x,y,&a,&b,270);
|
||||
translate_coords(canvas,270);
|
||||
temp=rotate(api, canvas, 270);
|
||||
fold_draw (api, which, temp, snapshot, a, b,update_rect);
|
||||
temp2=rotate(api,temp,90);
|
||||
SDL_BlitSurface(temp2,0,canvas,0);
|
||||
SDL_FreeSurface(temp);
|
||||
SDL_FreeSurface(temp2);
|
||||
break;
|
||||
translate_xy(canvas, x, y, &a, &b, 270);
|
||||
translate_coords(canvas, 270);
|
||||
temp = rotate(api, canvas, 270);
|
||||
fold_draw(api, which, temp, snapshot, a, b, update_rect);
|
||||
temp2 = rotate(api, temp, 90);
|
||||
SDL_BlitSurface(temp2, 0, canvas, 0);
|
||||
SDL_FreeSurface(temp);
|
||||
SDL_FreeSurface(temp2);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
translate_xy(canvas,x,y,&a,&b,180);
|
||||
translate_coords(canvas,180);
|
||||
temp=rotate(api, canvas, 180);
|
||||
fold_draw (api, which, temp, snapshot, a, b,update_rect);
|
||||
temp2=rotate(api,temp,180);
|
||||
SDL_BlitSurface(temp2,0,canvas,0);
|
||||
SDL_FreeSurface (temp);
|
||||
SDL_FreeSurface (temp2);
|
||||
break;
|
||||
translate_xy(canvas, x, y, &a, &b, 180);
|
||||
translate_coords(canvas, 180);
|
||||
temp = rotate(api, canvas, 180);
|
||||
fold_draw(api, which, temp, snapshot, a, b, update_rect);
|
||||
temp2 = rotate(api, temp, 180);
|
||||
SDL_BlitSurface(temp2, 0, canvas, 0);
|
||||
SDL_FreeSurface(temp);
|
||||
SDL_FreeSurface(temp2);
|
||||
break;
|
||||
}
|
||||
|
||||
update_rect->x=update_rect->y=0;
|
||||
update_rect->w=canvas->w;
|
||||
update_rect->h=canvas->h;
|
||||
update_rect->x = update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
api->playsound(fold_snd, (x * 255) / canvas->w, 255);
|
||||
}
|
||||
|
||||
void fold_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
Mix_FreeChunk(fold_snd);
|
||||
SDL_FreeSurface(fold_surface_dst);
|
||||
SDL_FreeSurface(fold_surface_src);
|
||||
}
|
||||
void fold_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
Mix_FreeChunk(fold_snd);
|
||||
SDL_FreeSurface(fold_surface_dst);
|
||||
SDL_FreeSurface(fold_surface_src);
|
||||
}
|
||||
|
||||
// Interactivity functions
|
||||
|
||||
inline Uint8 fold_what_corner(int x, int y, SDL_Surface * canvas)
|
||||
{
|
||||
if (x>=canvas->w/2)
|
||||
{
|
||||
if (y>=canvas->h/2) return 4;
|
||||
else return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (y>=canvas->h/2) return 3;
|
||||
else return 2;
|
||||
}
|
||||
if (x >= canvas->w / 2)
|
||||
{
|
||||
if (y >= canvas->h / 2)
|
||||
return 4;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (y >= canvas->h / 2)
|
||||
return 3;
|
||||
else
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void fold_print_line(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y)
|
||||
static void fold_print_line(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y)
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
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)
|
||||
{
|
||||
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.
|
||||
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_erase(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(canvas->format, fold_r, fold_g, fold_b));
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
|
||||
api->putpixel(canvas, x, y, SDL_MapRGB(last->format, 90, 90, 90)); //It should not look too black nor too white with shadowed colors.
|
||||
}
|
||||
|
||||
static void fold_erase(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
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);
|
||||
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
|
||||
corner = fold_what_corner(x, y, snapshot);
|
||||
|
||||
switch (corner)
|
||||
{
|
||||
case 1:
|
||||
fold_ox=canvas->w-1;
|
||||
fold_oy=0;
|
||||
fold_ox = canvas->w - 1;
|
||||
fold_oy = 0;
|
||||
break;
|
||||
case 2:
|
||||
fold_ox=fold_oy=0;
|
||||
fold_ox = fold_oy = 0;
|
||||
break;
|
||||
case 3:
|
||||
fold_ox=0;
|
||||
fold_oy=canvas->h-1;
|
||||
fold_ox = 0;
|
||||
fold_oy = canvas->h - 1;
|
||||
break;
|
||||
case 4:
|
||||
fold_ox=canvas->w-1;
|
||||
fold_oy=canvas->h-1;
|
||||
fold_ox = canvas->w - 1;
|
||||
fold_oy = canvas->h - 1;
|
||||
break;
|
||||
}
|
||||
|
||||
fold_drag(api, which, canvas, snapshot, x, y, x, y, update_rect);
|
||||
fold_drag(api, which, canvas, snapshot, x, y, x, y, update_rect);
|
||||
}
|
||||
|
||||
void fold_preview(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * snapshot, int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
SDL_Surface * snapshot, int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
{
|
||||
int middle_point_x;
|
||||
int middle_point_y;
|
||||
|
||||
fold_x=x;
|
||||
fold_y=y;
|
||||
SDL_BlitSurface(snapshot,0,canvas,0);
|
||||
fold_x = x;
|
||||
fold_y = y;
|
||||
SDL_BlitSurface(snapshot, 0, canvas, 0);
|
||||
|
||||
middle_point_x=(fold_ox+x)/2;
|
||||
middle_point_y=(fold_oy+y)/2;
|
||||
middle_point_x = (fold_ox + x) / 2;
|
||||
middle_point_y = (fold_oy + y) / 2;
|
||||
|
||||
switch(corner)
|
||||
switch (corner)
|
||||
{
|
||||
case 1: //Right Upper
|
||||
right_arm_x=fold_ox- (fold_ox-middle_point_x)-middle_point_y*middle_point_y/(fold_ox-middle_point_x);
|
||||
right_arm_y=fold_oy;
|
||||
case 1: //Right Upper
|
||||
right_arm_x = fold_ox - (fold_ox - middle_point_x) - middle_point_y * middle_point_y / (fold_ox - middle_point_x);
|
||||
right_arm_y = fold_oy;
|
||||
|
||||
left_arm_x=fold_ox;
|
||||
left_arm_y=fold_oy-(fold_oy-middle_point_y)-(fold_ox-middle_point_x)*(fold_ox-middle_point_x)/(fold_oy-middle_point_y);
|
||||
left_arm_x = fold_ox;
|
||||
left_arm_y =
|
||||
fold_oy - (fold_oy - middle_point_y) - (fold_ox - middle_point_x) * (fold_ox - middle_point_x) / (fold_oy -
|
||||
middle_point_y);
|
||||
break;
|
||||
|
||||
case 2: //LU
|
||||
right_arm_x=fold_ox;
|
||||
right_arm_y=middle_point_y+middle_point_x*middle_point_x/middle_point_y;
|
||||
case 2: //LU
|
||||
right_arm_x = fold_ox;
|
||||
right_arm_y = middle_point_y + middle_point_x * middle_point_x / middle_point_y;
|
||||
|
||||
left_arm_x=middle_point_x+middle_point_y*middle_point_y/middle_point_x;
|
||||
left_arm_y=fold_oy;
|
||||
break;
|
||||
|
||||
case 3: //LL
|
||||
right_arm_x=middle_point_x+(fold_oy-middle_point_y)*(fold_oy-middle_point_y)/middle_point_x;
|
||||
right_arm_y=fold_oy;
|
||||
|
||||
left_arm_x=fold_ox;
|
||||
left_arm_y=fold_oy-(fold_oy-middle_point_y)-(fold_ox-middle_point_x)*(fold_ox-middle_point_x)/(fold_oy-middle_point_y);
|
||||
left_arm_x = middle_point_x + middle_point_y * middle_point_y / middle_point_x;
|
||||
left_arm_y = fold_oy;
|
||||
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);
|
||||
case 3: //LL
|
||||
right_arm_x = middle_point_x + (fold_oy - middle_point_y) * (fold_oy - middle_point_y) / middle_point_x;
|
||||
right_arm_y = fold_oy;
|
||||
|
||||
left_arm_x=fold_ox-(fold_ox-middle_point_x)-(fold_oy-middle_point_y)*(fold_oy-middle_point_y)/(fold_ox-middle_point_x);
|
||||
left_arm_y=fold_oy;
|
||||
left_arm_x = fold_ox;
|
||||
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);
|
||||
|
||||
left_arm_x =
|
||||
fold_ox - (fold_ox - middle_point_x) - (fold_oy - middle_point_y) * (fold_oy - middle_point_y) / (fold_ox -
|
||||
middle_point_x);
|
||||
left_arm_y = fold_oy;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -479,30 +505,31 @@ void fold_preview(magic_api * api, int which, SDL_Surface * canvas,
|
|||
api->line((void *)api, which, canvas, snapshot, x, y, left_arm_x, left_arm_y, 1, fold_print_line);
|
||||
api->line((void *)api, which, canvas, snapshot, left_arm_x, left_arm_y, right_arm_x, right_arm_y, 1, fold_print_line);
|
||||
|
||||
update_rect->x=update_rect->y=0;
|
||||
update_rect->w=canvas->w;
|
||||
update_rect->h=canvas->h;
|
||||
update_rect->x = update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
}
|
||||
|
||||
void fold_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
// Avoid division by zero when calculating the preview
|
||||
x=clamp(2,x,canvas->w-2);
|
||||
y=clamp(2,y,canvas->h-2);
|
||||
x = clamp(2, x, canvas->w - 2);
|
||||
y = clamp(2, y, canvas->h - 2);
|
||||
fold_preview(api, which, canvas, snapshot, ox, oy, x, y, update_rect);
|
||||
}
|
||||
|
||||
void fold_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void fold_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void fold_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void fold_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
int fold_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_PAINT_WITH_PREVIEW);
|
||||
return (MODE_PAINT_WITH_PREVIEW);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,84 +22,80 @@
|
|||
#define SEG_RIGHT_TOP_BOTTOM (SEG_RIGHT | SEG_TOP | SEG_BOTTOM)
|
||||
#define SEG_LEFT_RIGHT_TOP_BOTTOM (SEG_LEFT | SEG_RIGHT | SEG_TOP | SEG_BOTTOM)
|
||||
|
||||
Mix_Chunk * fretwork_snd;
|
||||
Mix_Chunk *fretwork_snd;
|
||||
unsigned int img_w, img_h;
|
||||
unsigned int fretwork_segments_x, fretwork_segments_y; //how many segments do we have?
|
||||
static int fretwork_math_ceil(int x, int y); //ceil() in cstdlib returns float and is relative slow, so we'll use our one
|
||||
static Uint8 * fretwork_status_of_segments; //a place to store an info about bitmap used for selected segment
|
||||
static char ** fretwork_images; //the pathes to all the images needed
|
||||
static unsigned int fretwork_segment_modified; //which segment was modified this time?
|
||||
static unsigned int fretwork_segment_modified_last =0; //which segment was last modified
|
||||
static unsigned int fretwork_segment_to_add =0; //a segment that should be added to solve corner joint
|
||||
unsigned int fretwork_segments_x, fretwork_segments_y; //how many segments do we have?
|
||||
static int fretwork_math_ceil(int x, int y); //ceil() in cstdlib returns float and is relative slow, so we'll use our one
|
||||
static Uint8 *fretwork_status_of_segments; //a place to store an info about bitmap used for selected segment
|
||||
static char **fretwork_images; //the pathes to all the images needed
|
||||
static unsigned int fretwork_segment_modified; //which segment was modified this time?
|
||||
static unsigned int fretwork_segment_modified_last = 0; //which segment was last modified
|
||||
static unsigned int fretwork_segment_to_add = 0; //a segment that should be added to solve corner joint
|
||||
static unsigned int fretwork_segment_last_clicked;
|
||||
static Uint8 fretwork_r, fretwork_g, fretwork_b;
|
||||
static unsigned int fretwork_full_runs; //The count of the clicks in full mode
|
||||
static unsigned int fretwork_segment_start_rectangle; //the segment were the update_rectangle will start
|
||||
static unsigned int fretwork_update_rectangle_width; //the width of the update_rectangle
|
||||
static unsigned int fretwork_update_rectangle_height; //the height of the update_rectangle
|
||||
static Uint8 fretwork_r, fretwork_g, fretwork_b;
|
||||
static unsigned int fretwork_full_runs; //The count of the clicks in full mode
|
||||
static unsigned int fretwork_segment_start_rectangle; //the segment were the update_rectangle will start
|
||||
static unsigned int fretwork_update_rectangle_width; //the width of the update_rectangle
|
||||
static unsigned int fretwork_update_rectangle_height; //the height of the update_rectangle
|
||||
static SDL_Rect modification_rect;
|
||||
static SDL_Surface * canvas_backup;
|
||||
static SDL_Surface * fretwork_one_back, * fretwork_three_back, * fretwork_four_back, * fretwork_corner_back;
|
||||
static SDL_Surface *canvas_backup;
|
||||
static SDL_Surface *fretwork_one_back, *fretwork_three_back, *fretwork_four_back, *fretwork_corner_back;
|
||||
|
||||
|
||||
// Housekeeping functions
|
||||
// Housekeeping functions
|
||||
|
||||
Uint32 fretwork_api_version(void);
|
||||
int fretwork_modes(magic_api * api, int which);
|
||||
void fretwork_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
static void fretwork_colorize(magic_api * api, SDL_Surface * dest, SDL_Surface * src );
|
||||
static void fretwork_colorize(magic_api * api, SDL_Surface * dest, SDL_Surface * src);
|
||||
int fretwork_init(magic_api * api);
|
||||
int fretwork_get_tool_count(magic_api * api);
|
||||
SDL_Surface * fretwork_get_icon(magic_api * api, int which);
|
||||
char * fretwork_get_name(magic_api * api, int which);
|
||||
char * fretwork_get_description(magic_api * api, int which, int mode);
|
||||
SDL_Surface *fretwork_get_icon(magic_api * api, int which);
|
||||
char *fretwork_get_name(magic_api * api, int which);
|
||||
char *fretwork_get_description(magic_api * api, int which, int mode);
|
||||
int fretwork_requires_colors(magic_api * api, int which);
|
||||
void fretwork_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
|
||||
void fretwork_shutdown(magic_api * api);
|
||||
void fretwork_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * snapshot);
|
||||
void fretwork_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * snapshot);
|
||||
inline void fretwork_extract_coords_from_segment(unsigned int segment, Sint16 * x, Sint16 * y);
|
||||
void fretwork_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
|
||||
|
||||
|
||||
|
||||
void fretwork_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
static void fretwork_draw_wrapper(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y);
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
static void fretwork_draw_wrapper(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||
inline unsigned int fretwork_get_segment(int x, int y);
|
||||
|
||||
|
||||
SDL_Surface * fretwork_one, * fretwork_three, * fretwork_four, * fretwork_corner;
|
||||
SDL_Surface *fretwork_one, *fretwork_three, *fretwork_four, *fretwork_corner;
|
||||
|
||||
Uint32 fretwork_api_version(void)
|
||||
{
|
||||
return(TP_MAGIC_API_VERSION);
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
int fretwork_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_PAINT|MODE_FULLSCREEN);
|
||||
return (MODE_PAINT | MODE_FULLSCREEN);
|
||||
}
|
||||
|
||||
void fretwork_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b)
|
||||
{
|
||||
fretwork_r=r;
|
||||
fretwork_g=g;
|
||||
fretwork_b=b;
|
||||
fretwork_colorize(api,fretwork_one, fretwork_one_back);
|
||||
fretwork_r = r;
|
||||
fretwork_g = g;
|
||||
fretwork_b = b;
|
||||
fretwork_colorize(api, fretwork_one, fretwork_one_back);
|
||||
fretwork_colorize(api, fretwork_three, fretwork_three_back);
|
||||
fretwork_colorize(api, fretwork_four, fretwork_four_back);
|
||||
fretwork_colorize(api, fretwork_corner, fretwork_corner_back);
|
||||
}
|
||||
|
||||
/* Adapted from flower.c */
|
||||
static void fretwork_colorize(magic_api * api, SDL_Surface * dest, SDL_Surface * src )
|
||||
static void fretwork_colorize(magic_api * api, SDL_Surface * dest, SDL_Surface * src)
|
||||
{
|
||||
int x, y;
|
||||
Uint8 r, g, b, a;
|
||||
|
|
@ -110,14 +106,11 @@ static void fretwork_colorize(magic_api * api, SDL_Surface * dest, SDL_Surface *
|
|||
for (y = 0; y < src->h; y++)
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
SDL_UnlockSurface(src);
|
||||
|
|
@ -128,34 +121,34 @@ static void fretwork_colorize(magic_api * api, SDL_Surface * dest, SDL_Surface *
|
|||
int fretwork_init(magic_api * api)
|
||||
{
|
||||
char fname[1024];
|
||||
Uint8 i; //is always < 4, so Uint8 seems to be a good idea
|
||||
|
||||
fretwork_images=(char **)malloc(sizeof(char *)*4);
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
fretwork_images[i]=(char *)malloc(sizeof(char)*1024);
|
||||
|
||||
snprintf(fretwork_images[0], 1024*sizeof(char), "%s/images/magic/fretwork_one.png", api->data_directory);
|
||||
snprintf(fretwork_images[1], 1024*sizeof(char), "%s/images/magic/fretwork_three.png", api->data_directory);
|
||||
snprintf(fretwork_images[2], 1024*sizeof(char), "%s/images/magic/fretwork_four.png", api->data_directory);
|
||||
snprintf(fretwork_images[3], 1024*sizeof(char), "%s/images/magic/fretwork_corner.png", api->data_directory);
|
||||
Uint8 i; //is always < 4, so Uint8 seems to be a good idea
|
||||
|
||||
fretwork_one=IMG_Load(fretwork_images[0]);
|
||||
fretwork_three=IMG_Load(fretwork_images[1]);
|
||||
fretwork_four=IMG_Load(fretwork_images[2]);
|
||||
fretwork_corner=IMG_Load(fretwork_images[3]);
|
||||
fretwork_one_back=IMG_Load(fretwork_images[0]);
|
||||
fretwork_three_back=IMG_Load(fretwork_images[1]);
|
||||
fretwork_four_back=IMG_Load(fretwork_images[2]);
|
||||
fretwork_corner_back=IMG_Load(fretwork_images[3]);
|
||||
fretwork_images = (char **)malloc(sizeof(char *) * 4);
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
fretwork_images[i] = (char *)malloc(sizeof(char) * 1024);
|
||||
|
||||
snprintf(fretwork_images[0], 1024 * sizeof(char), "%s/images/magic/fretwork_one.png", api->data_directory);
|
||||
snprintf(fretwork_images[1], 1024 * sizeof(char), "%s/images/magic/fretwork_three.png", api->data_directory);
|
||||
snprintf(fretwork_images[2], 1024 * sizeof(char), "%s/images/magic/fretwork_four.png", api->data_directory);
|
||||
snprintf(fretwork_images[3], 1024 * sizeof(char), "%s/images/magic/fretwork_corner.png", api->data_directory);
|
||||
|
||||
fretwork_one = IMG_Load(fretwork_images[0]);
|
||||
fretwork_three = IMG_Load(fretwork_images[1]);
|
||||
fretwork_four = IMG_Load(fretwork_images[2]);
|
||||
fretwork_corner = IMG_Load(fretwork_images[3]);
|
||||
fretwork_one_back = IMG_Load(fretwork_images[0]);
|
||||
fretwork_three_back = IMG_Load(fretwork_images[1]);
|
||||
fretwork_four_back = IMG_Load(fretwork_images[2]);
|
||||
fretwork_corner_back = IMG_Load(fretwork_images[3]);
|
||||
|
||||
img_w = fretwork_one->w;
|
||||
img_h = fretwork_one->h;
|
||||
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/fretwork.ogg", api->data_directory);
|
||||
fretwork_snd = Mix_LoadWAV(fname);
|
||||
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
int fretwork_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
|
|
@ -163,38 +156,44 @@ int fretwork_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
|||
return 1;
|
||||
}
|
||||
|
||||
SDL_Surface * fretwork_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
SDL_Surface *fretwork_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/fretwork.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/fretwork.png", api->data_directory);
|
||||
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
char * fretwork_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) { return strdup(gettext_noop("Fretwork")); }
|
||||
char *fretwork_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return strdup(gettext_noop("Fretwork"));
|
||||
}
|
||||
|
||||
char * fretwork_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode) {
|
||||
if (mode==MODE_PAINT)
|
||||
char *fretwork_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode)
|
||||
{
|
||||
if (mode == MODE_PAINT)
|
||||
return strdup(gettext_noop("Click and drag to draw repetitive patterns. "));
|
||||
else
|
||||
return strdup(gettext_noop("Click to surround your picture with repetitive patterns."));
|
||||
}
|
||||
}
|
||||
|
||||
int fretwork_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) { return 1;}
|
||||
int fretwork_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void fretwork_release(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * snapshot ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect 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)
|
||||
{
|
||||
}
|
||||
|
||||
void fretwork_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
Uint8 i;
|
||||
|
||||
if (fretwork_snd!=NULL)
|
||||
|
||||
if (fretwork_snd != NULL)
|
||||
Mix_FreeChunk(fretwork_snd);
|
||||
SDL_FreeSurface(fretwork_one);
|
||||
SDL_FreeSurface(fretwork_three);
|
||||
|
|
@ -205,7 +204,7 @@ void fretwork_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
|||
SDL_FreeSurface(fretwork_four_back);
|
||||
SDL_FreeSurface(fretwork_corner_back);
|
||||
SDL_FreeSurface(canvas_backup);
|
||||
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
free(fretwork_images[i]);
|
||||
free(fretwork_images);
|
||||
|
|
@ -213,22 +212,25 @@ void fretwork_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
|||
free(fretwork_status_of_segments);
|
||||
}
|
||||
|
||||
void fretwork_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED)
|
||||
void fretwork_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED)
|
||||
{
|
||||
//we've to compute the quantity of segments in each direction
|
||||
|
||||
canvas_backup=SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h, canvas->format->BitsPerPixel,
|
||||
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
|
||||
canvas_backup = SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h, canvas->format->BitsPerPixel,
|
||||
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask,
|
||||
canvas->format->Amask);
|
||||
|
||||
SDL_BlitSurface(canvas, NULL, canvas_backup, NULL);
|
||||
fretwork_segments_x=fretwork_math_ceil(canvas->w,img_w);
|
||||
fretwork_segments_y=fretwork_math_ceil(canvas->h,img_h);
|
||||
fretwork_status_of_segments=(Uint8 *)calloc(fretwork_segments_x*fretwork_segments_y + 1, sizeof(Uint8)); //segments starts at 1, while fretwork_status_of_segments[] starts at 0
|
||||
fretwork_full_runs=1;
|
||||
fretwork_segments_x = fretwork_math_ceil(canvas->w, img_w);
|
||||
fretwork_segments_y = fretwork_math_ceil(canvas->h, img_h);
|
||||
fretwork_status_of_segments = (Uint8 *) calloc(fretwork_segments_x * fretwork_segments_y + 1, sizeof(Uint8)); //segments starts at 1, while fretwork_status_of_segments[] starts at 0
|
||||
fretwork_full_runs = 1;
|
||||
}
|
||||
|
||||
|
||||
void fretwork_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * snapshot ATTRIBUTE_UNUSED)
|
||||
void fretwork_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * snapshot ATTRIBUTE_UNUSED)
|
||||
{
|
||||
free(fretwork_status_of_segments);
|
||||
fretwork_status_of_segments = NULL;
|
||||
|
|
@ -238,29 +240,32 @@ void fretwork_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UN
|
|||
|
||||
|
||||
static int fretwork_math_ceil(int x, int y)
|
||||
{
|
||||
{
|
||||
int temp;
|
||||
temp=(int)x/y;
|
||||
if (x%y)
|
||||
return temp+1;
|
||||
else return temp;
|
||||
|
||||
temp = (int)x / y;
|
||||
if (x % y)
|
||||
return temp + 1;
|
||||
else
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
inline unsigned int fretwork_get_segment(int x, int y)
|
||||
{
|
||||
int xx; //segments are numerated just like pixels
|
||||
int yy; //in computer graphics: left upper (=1), ... ,right upper,
|
||||
//left bottom, ... , right bottom
|
||||
xx=fretwork_math_ceil(x, img_w);
|
||||
yy=fretwork_math_ceil(y, img_h);
|
||||
int xx; //segments are numerated just like pixels
|
||||
int yy; //in computer graphics: left upper (=1), ... ,right upper,
|
||||
|
||||
return (yy-1)*fretwork_segments_x+xx;
|
||||
//left bottom, ... , right bottom
|
||||
xx = fretwork_math_ceil(x, img_w);
|
||||
yy = fretwork_math_ceil(y, img_h);
|
||||
|
||||
return (yy - 1) * fretwork_segments_x + xx;
|
||||
}
|
||||
|
||||
inline void fretwork_extract_coords_from_segment(unsigned int segment, Sint16 * x, Sint16 * y)
|
||||
{
|
||||
*x=((segment%fretwork_segments_x)-1)*img_w; //useful to set update_rect as small as possible
|
||||
*y=(int)(segment/fretwork_segments_x)*img_h;
|
||||
*x = ((segment % fretwork_segments_x) - 1) * img_w; //useful to set update_rect as small as possible
|
||||
*y = (int)(segment / fretwork_segments_x) * img_h;
|
||||
}
|
||||
|
||||
/* static void fretwork_flip(void * ptr, SDL_Surface * dest, SDL_Surface * src) */
|
||||
|
|
@ -274,75 +279,80 @@ inline void fretwork_extract_coords_from_segment(unsigned int segment, Sint16 *
|
|||
/* api->putpixel(dest, x, y, api->getpixel(src, x, src->h-y)); */
|
||||
/* } */
|
||||
|
||||
static void fretwork_flip_flop(void * ptr, SDL_Surface * dest, SDL_Surface * src)
|
||||
static void fretwork_flip_flop(void *ptr, SDL_Surface * dest, SDL_Surface * src)
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
Sint16 x, y;
|
||||
for (x=0; x<dest->w; x++)
|
||||
for (y=0; y<dest->h; y++)
|
||||
api->putpixel(dest, dest->w-1-x, dest->h-1-y, api->getpixel(src, x, y));
|
||||
|
||||
for (x = 0; x < dest->w; x++)
|
||||
for (y = 0; y < dest->h; y++)
|
||||
api->putpixel(dest, dest->w - 1 - x, dest->h - 1 - y, api->getpixel(src, x, y));
|
||||
}
|
||||
|
||||
static void fretwork_rotate (void * ptr, SDL_Surface * dest, SDL_Surface * src, _Bool direction)
|
||||
static void fretwork_rotate(void *ptr, SDL_Surface * dest, SDL_Surface * src, _Bool direction)
|
||||
//src and dest must have same size
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
Sint16 x,y;
|
||||
|
||||
if (direction) //rotate -90 degs
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
Sint16 x, y;
|
||||
|
||||
if (direction) //rotate -90 degs
|
||||
{
|
||||
for (x = 0; x<dest->w; x++)
|
||||
for (y =0; y<dest->h; y++)
|
||||
api->putpixel(dest, x, y, api->getpixel(src,y,src->h-1-x));
|
||||
for (x = 0; x < dest->w; x++)
|
||||
for (y = 0; y < dest->h; y++)
|
||||
api->putpixel(dest, x, y, api->getpixel(src, y, src->h - 1 - x));
|
||||
}
|
||||
else //rotate +90 degs
|
||||
else //rotate +90 degs
|
||||
{
|
||||
for (x=0; x<dest->w; x++)
|
||||
for (y=0; y<dest->h; y++)
|
||||
api->putpixel(dest,x,y,api->getpixel(src,src->h-y-1,x));
|
||||
for (x = 0; x < dest->w; x++)
|
||||
for (y = 0; y < dest->h; y++)
|
||||
api->putpixel(dest, x, y, api->getpixel(src, src->h - y - 1, x));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void fretwork_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect)
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
int left_x, right_x, top_y, bottom_y;
|
||||
|
||||
fretwork_segment_modified_last = 0;
|
||||
if (mode==MODE_PAINT)
|
||||
if (mode == MODE_PAINT)
|
||||
{
|
||||
fretwork_segment_last_clicked=fretwork_get_segment(x,y);
|
||||
fretwork_drag(api, which, canvas, snapshot, x, y, x, y, update_rect);
|
||||
fretwork_segment_last_clicked = fretwork_get_segment(x, y);
|
||||
fretwork_drag(api, which, canvas, snapshot, x, y, x, y, update_rect);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fretwork_full_runs<=min(fretwork_segments_x,fretwork_segments_y)/2)
|
||||
{
|
||||
left_x=img_w*fretwork_full_runs;
|
||||
right_x=img_w*fretwork_segments_x-img_w*fretwork_full_runs;
|
||||
top_y=img_h*fretwork_full_runs;
|
||||
bottom_y=img_h*fretwork_segments_y-img_h*(fretwork_full_runs-1);
|
||||
if (fretwork_full_runs <= min(fretwork_segments_x, fretwork_segments_y) / 2)
|
||||
{
|
||||
left_x = img_w * fretwork_full_runs;
|
||||
right_x = img_w * fretwork_segments_x - img_w * fretwork_full_runs;
|
||||
top_y = img_h * fretwork_full_runs;
|
||||
bottom_y = img_h * fretwork_segments_y - img_h * (fretwork_full_runs - 1);
|
||||
|
||||
//left line
|
||||
api->line((void *) api, which, canvas, snapshot, left_x, top_y, left_x, bottom_y, img_w/2, fretwork_draw_wrapper);
|
||||
//left line
|
||||
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);
|
||||
//top line
|
||||
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);
|
||||
//bottom line
|
||||
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);
|
||||
//right line
|
||||
api->line((void *)api, which, canvas, snapshot, right_x, top_y, right_x, bottom_y, img_w / 2,
|
||||
fretwork_draw_wrapper);
|
||||
|
||||
fretwork_full_runs +=1;
|
||||
update_rect->x=0;
|
||||
update_rect->y=0;
|
||||
update_rect->w=canvas->w;
|
||||
update_rect->h=canvas->h;
|
||||
}
|
||||
fretwork_full_runs += 1;
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -355,64 +365,73 @@ static Uint8 fretwork_select_image(Uint16 segment)
|
|||
int TOP = 0, BOTTOM = 0, LEFT = 0, RIGHT = 0;
|
||||
|
||||
//Checking from were we come...
|
||||
if (fretwork_segment_modified_last>0)
|
||||
if (fretwork_segment_modified_last > 0)
|
||||
{
|
||||
if (segment == fretwork_segment_modified_last + 1)
|
||||
from_left = 1;
|
||||
from_left = 1;
|
||||
else if (segment == fretwork_segment_modified_last - 1)
|
||||
from_right = 1;
|
||||
from_right = 1;
|
||||
else if (segment == fretwork_segment_modified_last - fretwork_segments_x)
|
||||
from_bottom = 1;
|
||||
from_bottom = 1;
|
||||
else if (segment == fretwork_segment_modified_last + fretwork_segments_x)
|
||||
from_top = 1;
|
||||
|
||||
from_top = 1;
|
||||
|
||||
// Very very few cases will reach this, segments are joining by the corner
|
||||
// We need to add a new segment to join by side, adding clockwise
|
||||
else if (segment == fretwork_segment_modified_last + fretwork_segments_x + 1)
|
||||
{
|
||||
from_top_left = 1;
|
||||
fretwork_segment_to_add = segment - fretwork_segments_x;
|
||||
}
|
||||
{
|
||||
from_top_left = 1;
|
||||
fretwork_segment_to_add = segment - fretwork_segments_x;
|
||||
}
|
||||
else if (segment == fretwork_segment_modified_last + fretwork_segments_x - 1)
|
||||
{
|
||||
from_top_right = 1;
|
||||
fretwork_segment_to_add = segment + 1;
|
||||
}
|
||||
{
|
||||
from_top_right = 1;
|
||||
fretwork_segment_to_add = segment + 1;
|
||||
}
|
||||
else if (segment == fretwork_segment_modified_last - fretwork_segments_x - 1)
|
||||
{
|
||||
from_bottom_right = 1;
|
||||
fretwork_segment_to_add = segment + fretwork_segments_x;
|
||||
}
|
||||
{
|
||||
from_bottom_right = 1;
|
||||
fretwork_segment_to_add = segment + fretwork_segments_x;
|
||||
}
|
||||
else if (segment == fretwork_segment_modified_last - fretwork_segments_x + 1)
|
||||
{
|
||||
from_bottom_left = 1;
|
||||
fretwork_segment_to_add = segment -1;
|
||||
}
|
||||
{
|
||||
from_bottom_left = 1;
|
||||
fretwork_segment_to_add = segment - 1;
|
||||
}
|
||||
}
|
||||
|
||||
take_up=segment-fretwork_segments_x;
|
||||
if (take_up<=0) val_up = SEG_NONE;
|
||||
else val_up = fretwork_status_of_segments[take_up];
|
||||
take_up = segment - fretwork_segments_x;
|
||||
if (take_up <= 0)
|
||||
val_up = SEG_NONE;
|
||||
else
|
||||
val_up = fretwork_status_of_segments[take_up];
|
||||
|
||||
take_down=segment+fretwork_segments_x;
|
||||
if (take_down>(signed)(fretwork_segments_x*fretwork_segments_y)) val_down = SEG_NONE;
|
||||
else val_down = fretwork_status_of_segments[take_down];
|
||||
|
||||
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];
|
||||
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 ( from_left || (val_left & SEG_RIGHT) || from_bottom_left)
|
||||
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 (from_left || (val_left & SEG_RIGHT) || from_bottom_left)
|
||||
{
|
||||
LEFT = 1;}
|
||||
if ( from_right || (val_right & SEG_LEFT) || from_top_right)
|
||||
RIGHT=1;
|
||||
if ( from_top || (val_up & SEG_BOTTOM) || from_top_left)
|
||||
TOP=1;
|
||||
LEFT = 1;
|
||||
}
|
||||
if (from_right || (val_right & SEG_LEFT) || from_top_right)
|
||||
RIGHT = 1;
|
||||
if (from_top || (val_up & SEG_BOTTOM) || from_top_left)
|
||||
TOP = 1;
|
||||
if (from_bottom || (val_down & SEG_TOP) || from_bottom_right)
|
||||
BOTTOM=1;
|
||||
BOTTOM = 1;
|
||||
|
||||
|
||||
if (TOP && BOTTOM && LEFT && RIGHT)
|
||||
|
|
@ -425,91 +444,93 @@ static Uint8 fretwork_select_image(Uint16 segment)
|
|||
return SEG_LEFT_TOP_BOTTOM;
|
||||
if (TOP && BOTTOM && RIGHT)
|
||||
return SEG_RIGHT_TOP_BOTTOM;
|
||||
if (LEFT &&RIGHT)
|
||||
if (LEFT && RIGHT)
|
||||
return SEG_LEFT_RIGHT;
|
||||
if (TOP&&BOTTOM)
|
||||
if (TOP && BOTTOM)
|
||||
return SEG_TOP_BOTTOM;
|
||||
if (LEFT&&TOP)
|
||||
if (LEFT && TOP)
|
||||
return SEG_LEFT_TOP;
|
||||
if (LEFT&&BOTTOM)
|
||||
if (LEFT && BOTTOM)
|
||||
return SEG_LEFT_BOTTOM;
|
||||
if (RIGHT&&TOP)
|
||||
if (RIGHT && TOP)
|
||||
return SEG_RIGHT_TOP;
|
||||
if (RIGHT&&BOTTOM)
|
||||
if (RIGHT && BOTTOM)
|
||||
return SEG_RIGHT_BOTTOM;
|
||||
if (LEFT|RIGHT)
|
||||
if (LEFT | RIGHT)
|
||||
return SEG_LEFT_RIGHT;
|
||||
//if (TOP||BOTTOM)
|
||||
return SEG_TOP_BOTTOM;
|
||||
}
|
||||
|
||||
|
||||
static void fretwork_draw(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x, int y ATTRIBUTE_UNUSED, unsigned int segment)
|
||||
static void fretwork_draw(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
|
||||
SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y ATTRIBUTE_UNUSED, unsigned int segment)
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
SDL_Surface * result, * temp;
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
SDL_Surface *result, *temp;
|
||||
Uint8 image;
|
||||
_Bool use_temp;
|
||||
|
||||
use_temp=0;
|
||||
if ((segment<1)|(segment>fretwork_segments_x*fretwork_segments_y))
|
||||
|
||||
use_temp = 0;
|
||||
if ((segment < 1) | (segment > fretwork_segments_x * fretwork_segments_y))
|
||||
return;
|
||||
fretwork_extract_coords_from_segment(segment, &modification_rect.x, &modification_rect.y);
|
||||
modification_rect.h=img_w;
|
||||
modification_rect.w=img_h;
|
||||
|
||||
image=fretwork_select_image(segment); //select the image to display
|
||||
modification_rect.h = img_w;
|
||||
modification_rect.w = img_h;
|
||||
|
||||
image = fretwork_select_image(segment); //select the image to display
|
||||
|
||||
if (fretwork_status_of_segments[segment] == image)
|
||||
return;
|
||||
|
||||
fretwork_status_of_segments[segment]=image; //and write it to global table
|
||||
|
||||
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_status_of_segments[segment] = image; //and write it to global table
|
||||
|
||||
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);
|
||||
result = SDL_CreateRGBSurface(SDL_SWSURFACE, img_w, img_h, fretwork_one->format->BitsPerPixel,
|
||||
fretwork_one->format->Rmask, fretwork_one->format->Gmask, fretwork_one->format->Bmask,
|
||||
fretwork_one->format->Amask);
|
||||
|
||||
temp = SDL_CreateRGBSurface(SDL_SWSURFACE, img_w, img_h, fretwork_one->format->BitsPerPixel,
|
||||
fretwork_one->format->Rmask, fretwork_one->format->Gmask, fretwork_one->format->Bmask,
|
||||
fretwork_one->format->Amask);
|
||||
|
||||
SDL_BlitSurface(canvas_backup, &modification_rect, result, NULL);
|
||||
|
||||
switch(image)
|
||||
|
||||
switch (image)
|
||||
{
|
||||
case 0:
|
||||
case SEG_TOP_BOTTOM:
|
||||
case SEG_TOP_BOTTOM:
|
||||
SDL_BlitSurface(canvas_backup, &modification_rect, result, NULL);
|
||||
SDL_BlitSurface(fretwork_one, NULL, result, NULL);
|
||||
break;
|
||||
|
||||
|
||||
case SEG_LEFT_RIGHT:
|
||||
SDL_BlitSurface(canvas_backup, &modification_rect, result, NULL);
|
||||
fretwork_rotate(api, temp, fretwork_one, 1);
|
||||
use_temp=1;
|
||||
use_temp = 1;
|
||||
break;
|
||||
|
||||
|
||||
case SEG_LEFT_RIGHT_TOP_BOTTOM:
|
||||
SDL_BlitSurface(canvas_backup, &modification_rect, result, NULL);
|
||||
SDL_BlitSurface(fretwork_four, NULL, result, NULL);
|
||||
break;
|
||||
|
||||
|
||||
case SEG_LEFT_RIGHT_TOP:
|
||||
SDL_BlitSurface(fretwork_three, NULL, result, NULL);
|
||||
break;
|
||||
|
||||
|
||||
case SEG_LEFT_RIGHT_BOTTOM:
|
||||
fretwork_flip_flop(api, temp, fretwork_three);
|
||||
use_temp=1;
|
||||
use_temp = 1;
|
||||
break;
|
||||
|
||||
|
||||
case SEG_LEFT_TOP_BOTTOM:
|
||||
fretwork_rotate(api, temp, fretwork_three, 0);
|
||||
use_temp=1;
|
||||
use_temp = 1;
|
||||
break;
|
||||
|
||||
|
||||
case SEG_RIGHT_TOP_BOTTOM:
|
||||
fretwork_rotate(api, temp, fretwork_three, 1);
|
||||
use_temp=1;
|
||||
use_temp = 1;
|
||||
break;
|
||||
|
||||
case SEG_RIGHT_TOP:
|
||||
|
|
@ -517,24 +538,24 @@ static void fretwork_draw(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface *
|
|||
break;
|
||||
|
||||
case SEG_RIGHT_BOTTOM:
|
||||
fretwork_rotate(api, temp, fretwork_corner,1);
|
||||
use_temp=1;
|
||||
fretwork_rotate(api, temp, fretwork_corner, 1);
|
||||
use_temp = 1;
|
||||
break;
|
||||
|
||||
case SEG_LEFT_TOP:
|
||||
fretwork_rotate(api, temp, fretwork_corner, 0);
|
||||
use_temp=1;
|
||||
use_temp = 1;
|
||||
break;
|
||||
|
||||
case SEG_LEFT_BOTTOM:
|
||||
fretwork_flip_flop(api, temp, fretwork_corner);
|
||||
use_temp=1;
|
||||
use_temp = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (use_temp)
|
||||
|
||||
if (use_temp)
|
||||
SDL_BlitSurface(temp, NULL, result, NULL);
|
||||
|
||||
|
||||
SDL_FreeSurface(temp);
|
||||
SDL_BlitSurface(result, NULL, canvas, &modification_rect);
|
||||
SDL_FreeSurface(result);
|
||||
|
|
@ -542,53 +563,58 @@ static void fretwork_draw(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface *
|
|||
}
|
||||
|
||||
|
||||
static void fretwork_draw_wrapper(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y)
|
||||
static void fretwork_draw_wrapper(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
|
||||
{
|
||||
fretwork_segment_modified=fretwork_get_segment(x,y);
|
||||
fretwork_segment_modified = fretwork_get_segment(x, y);
|
||||
|
||||
fretwork_draw((void *) ptr, which, canvas, last, x, y, fretwork_segment_modified);
|
||||
fretwork_draw((void *)ptr, which, canvas, last, x, y, fretwork_segment_modified);
|
||||
|
||||
if (fretwork_segment_modified_last>0)
|
||||
if (fretwork_segment_modified_last > 0)
|
||||
|
||||
{
|
||||
fretwork_draw((void *) ptr, which, canvas, last, x, y, fretwork_segment_modified_last);
|
||||
fretwork_extract_coords_from_segment(fretwork_segment_start_rectangle, &modification_rect.x, &modification_rect.y);
|
||||
modification_rect.w=fretwork_update_rectangle_width*img_w;
|
||||
modification_rect.h=fretwork_update_rectangle_height*img_h;
|
||||
fretwork_draw((void *)ptr, which, canvas, last, x, y, fretwork_segment_modified_last);
|
||||
fretwork_extract_coords_from_segment(fretwork_segment_start_rectangle, &modification_rect.x,
|
||||
&modification_rect.y);
|
||||
modification_rect.w = fretwork_update_rectangle_width * img_w;
|
||||
modification_rect.h = fretwork_update_rectangle_height * img_h;
|
||||
}
|
||||
|
||||
if (fretwork_segment_to_add>0){
|
||||
fretwork_draw((void *) ptr, which, canvas, last, x, y, fretwork_segment_to_add);
|
||||
fretwork_draw((void *) ptr, which, canvas, last, x, y, fretwork_segment_modified_last);
|
||||
fretwork_segment_to_add=0;}
|
||||
if (fretwork_segment_to_add > 0)
|
||||
{
|
||||
fretwork_draw((void *)ptr, which, canvas, last, x, y, fretwork_segment_to_add);
|
||||
fretwork_draw((void *)ptr, which, canvas, last, x, y, fretwork_segment_modified_last);
|
||||
fretwork_segment_to_add = 0;
|
||||
}
|
||||
|
||||
fretwork_segment_modified_last=fretwork_segment_modified;
|
||||
fretwork_segment_modified_last = fretwork_segment_modified;
|
||||
}
|
||||
|
||||
void fretwork_drag(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
{ int start_x, end_x, start_y, end_y, segment_start, segment_end, w, h;
|
||||
if ((x<canvas->w)&&(y<canvas->h)&&(ox<canvas->w)&&(oy<canvas->h)&&((signed)x>0)&&((signed)y>0)&&((signed)ox>0)&&((signed)oy>0))
|
||||
{
|
||||
api->line((void *) api, which, canvas, snapshot, ox, oy, x, y, img_w/2, fretwork_draw_wrapper);
|
||||
// This should be improved, maybe passed to fretwork_draw()
|
||||
start_x=min(ox,x);
|
||||
end_x=max(ox,x);
|
||||
start_y=min(oy,y);
|
||||
end_y=max(oy,y);
|
||||
segment_start=fretwork_get_segment(start_x-img_w, start_y-img_h);
|
||||
segment_end=fretwork_get_segment(end_x+img_w,end_y+img_h);
|
||||
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;
|
||||
|
||||
x=((segment_start%fretwork_segments_x)-1)*img_w;
|
||||
y=(int)(segment_start/fretwork_segments_x)*img_h;
|
||||
w=((segment_end%fretwork_segments_x)-1)*img_w-x+img_w;
|
||||
h=(int)(segment_end/fretwork_segments_x)*img_h-y+img_h;
|
||||
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()
|
||||
start_x = min(ox, x);
|
||||
end_x = max(ox, x);
|
||||
start_y = min(oy, y);
|
||||
end_y = max(oy, y);
|
||||
segment_start = fretwork_get_segment(start_x - img_w, start_y - img_h);
|
||||
segment_end = fretwork_get_segment(end_x + img_w, end_y + img_h);
|
||||
|
||||
update_rect->x=x;
|
||||
update_rect->y=y;
|
||||
update_rect->w=w;
|
||||
update_rect->h=h;}
|
||||
x = ((segment_start % fretwork_segments_x) - 1) * img_w;
|
||||
y = (int)(segment_start / fretwork_segments_x) * img_h;
|
||||
w = ((segment_end % fretwork_segments_x) - 1) * img_w - x + img_w;
|
||||
h = (int)(segment_end / fretwork_segments_x) * img_h - y + img_h;
|
||||
|
||||
update_rect->x = x;
|
||||
update_rect->y = y;
|
||||
update_rect->w = w;
|
||||
update_rect->h = h;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,26 +36,22 @@
|
|||
|
||||
/* Our globals: */
|
||||
|
||||
static Mix_Chunk * glasstile_snd;
|
||||
static Mix_Chunk *glasstile_snd;
|
||||
|
||||
// Prototypes
|
||||
Uint32 glasstile_api_version(void);
|
||||
int glasstile_init(magic_api * api);
|
||||
int glasstile_get_tool_count(magic_api * api);
|
||||
SDL_Surface * glasstile_get_icon(magic_api * api, int which);
|
||||
char * glasstile_get_name(magic_api * api, int which);
|
||||
char * glasstile_get_description(magic_api * api, int which, int mode);
|
||||
static void do_glasstile(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y);
|
||||
SDL_Surface *glasstile_get_icon(magic_api * api, int which);
|
||||
char *glasstile_get_name(magic_api * api, int which);
|
||||
char *glasstile_get_description(magic_api * api, int which, int mode);
|
||||
static void do_glasstile(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||
void glasstile_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
void glasstile_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void glasstile_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void glasstile_shutdown(magic_api * api);
|
||||
void glasstile_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
int glasstile_requires_colors(magic_api * api, int which);
|
||||
|
|
@ -63,9 +59,12 @@ void glasstile_switchin(magic_api * api, int which, int mode, SDL_Surface * canv
|
|||
void glasstile_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
int glasstile_modes(magic_api * api, int which);
|
||||
|
||||
Uint32 glasstile_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
Uint32 glasstile_api_version(void)
|
||||
{
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
static int * * glasstile_hit;
|
||||
static int **glasstile_hit;
|
||||
static int glasstile_hit_xsize;
|
||||
static int glasstile_hit_ysize;
|
||||
|
||||
|
|
@ -74,60 +73,53 @@ int glasstile_init(magic_api * api)
|
|||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/glasstile.ogg",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/glasstile.ogg", api->data_directory);
|
||||
glasstile_snd = Mix_LoadWAV(fname);
|
||||
|
||||
|
||||
glasstile_hit = NULL;
|
||||
glasstile_hit_ysize = 0;
|
||||
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
// We have multiple tools:
|
||||
int glasstile_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
// Load our icons:
|
||||
SDL_Surface * glasstile_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
SDL_Surface *glasstile_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/glasstile.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/glasstile.png", api->data_directory);
|
||||
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our names, localized:
|
||||
char * glasstile_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
char *glasstile_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(strdup(gettext_noop("Glass Tile")));
|
||||
return (strdup(gettext_noop("Glass Tile")));
|
||||
}
|
||||
|
||||
// Return our descriptions, localized:
|
||||
char * glasstile_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode)
|
||||
char *glasstile_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode)
|
||||
{
|
||||
if (mode == MODE_PAINT)
|
||||
return(strdup(gettext_noop("Click and drag the mouse to put glass tile over your picture.")));
|
||||
return (strdup(gettext_noop("Click and drag the mouse to put glass tile over your picture.")));
|
||||
else
|
||||
return(strdup(gettext_noop("Click to cover your entire picture in glass tiles.")));
|
||||
return (strdup(gettext_noop("Click to cover your entire picture in glass tiles.")));
|
||||
}
|
||||
|
||||
// Do the effect:
|
||||
|
||||
static void do_glasstile(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y)
|
||||
static void do_glasstile(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
int xx, yy, xl, xr, yt, yb;
|
||||
Uint8 r1, g1, b1,
|
||||
r2, g2, b2,
|
||||
r3, g3, b3,
|
||||
r4, g4, b4,
|
||||
r, g, b;
|
||||
Uint8 r1, g1, b1, r2, g2, b2, r3, g3, b3, r4, g4, b4, r, g, b;
|
||||
Uint32 rgb;
|
||||
|
||||
|
||||
|
|
@ -154,66 +146,61 @@ static void do_glasstile(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * c
|
|||
/* Apply the effect: */
|
||||
|
||||
for (yy = -GT_SIZE; yy < GT_SIZE; yy = yy + 2)
|
||||
{
|
||||
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);
|
||||
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);
|
||||
|
||||
r = (r1 + r2 + r3 + r4) >> 2;
|
||||
g = (g1 + g2 + g3 + g4) >> 2;
|
||||
b = (b1 + b2 + b3 + b4) >> 2;
|
||||
r = (r1 + r2 + r3 + r4) >> 2;
|
||||
g = (g1 + g2 + g3 + g4) >> 2;
|
||||
b = (b1 + b2 + b3 + b4) >> 2;
|
||||
|
||||
if (xx <= -GT_SIZE + 2 || yy == -GT_SIZE + 2)
|
||||
{
|
||||
r = min(255, r + 64);
|
||||
g = min(255, g + 64);
|
||||
b = min(255, b + 64);
|
||||
}
|
||||
else if (xx >= GT_SIZE - 3|| yy >= GT_SIZE - 3)
|
||||
{
|
||||
r = max(0, r - 64);
|
||||
g = max(0, g - 64);
|
||||
b = max(0, b - 64);
|
||||
}
|
||||
if (xx <= -GT_SIZE + 2 || yy == -GT_SIZE + 2)
|
||||
{
|
||||
r = min(255, r + 64);
|
||||
g = min(255, g + 64);
|
||||
b = min(255, b + 64);
|
||||
}
|
||||
else if (xx >= GT_SIZE - 3 || yy >= GT_SIZE - 3)
|
||||
{
|
||||
r = max(0, r - 64);
|
||||
g = max(0, g - 64);
|
||||
b = max(0, b - 64);
|
||||
}
|
||||
|
||||
rgb = SDL_MapRGB(canvas->format, r, g, b);
|
||||
rgb = SDL_MapRGB(canvas->format, r, g, b);
|
||||
|
||||
xl = (xx / 3) - GT_SIZE + (GT_SIZE / 3);
|
||||
xr = (xx / 3) + (GT_SIZE * 2) / 3;
|
||||
yt = (yy / 3) - GT_SIZE + (GT_SIZE / 3);
|
||||
yb = (yy / 3) + (GT_SIZE * 2) / 3;
|
||||
xl = (xx / 3) - GT_SIZE + (GT_SIZE / 3);
|
||||
xr = (xx / 3) + (GT_SIZE * 2) / 3;
|
||||
yt = (yy / 3) - GT_SIZE + (GT_SIZE / 3);
|
||||
yb = (yy / 3) + (GT_SIZE * 2) / 3;
|
||||
|
||||
api->putpixel(canvas, x + xl, y + yt, rgb);
|
||||
api->putpixel(canvas, x + xx / 2, y + yt, rgb);
|
||||
api->putpixel(canvas, x + xr, y + yt, rgb);
|
||||
api->putpixel(canvas, x + xl, y + yt, rgb);
|
||||
api->putpixel(canvas, x + xx / 2, y + yt, rgb);
|
||||
api->putpixel(canvas, x + xr, y + yt, rgb);
|
||||
|
||||
api->putpixel(canvas, x + xl, y + yy / 2, rgb);
|
||||
api->putpixel(canvas, x + xr, y + yy / 2, rgb);
|
||||
api->putpixel(canvas, x + xl, y + yy / 2, rgb);
|
||||
api->putpixel(canvas, x + xr, y + yy / 2, rgb);
|
||||
|
||||
api->putpixel(canvas, x + xl, y + yb, rgb);
|
||||
api->putpixel(canvas, x + xx / 2, y + yb, rgb);
|
||||
api->putpixel(canvas, x + xr, y + yb, rgb);
|
||||
api->putpixel(canvas, x + xl, y + yb, rgb);
|
||||
api->putpixel(canvas, x + xx / 2, y + yb, rgb);
|
||||
api->putpixel(canvas, x + xr, y + yb, rgb);
|
||||
|
||||
/* Center */
|
||||
/* Center */
|
||||
|
||||
api->putpixel(canvas, x + xx / 2, y + yy / 2, rgb);
|
||||
api->putpixel(canvas, x + xx / 2, y + yy / 2, rgb);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Affect the canvas on drag:
|
||||
void glasstile_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_glasstile);
|
||||
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_glasstile);
|
||||
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
|
|
@ -246,21 +233,20 @@ 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;
|
||||
|
||||
if (glasstile_hit == NULL)
|
||||
{
|
||||
glasstile_hit_ysize = (canvas->h / GT_SIZE) + 1;
|
||||
glasstile_hit_xsize = (canvas->w / GT_SIZE) + 1;
|
||||
{
|
||||
glasstile_hit_ysize = (canvas->h / GT_SIZE) + 1;
|
||||
glasstile_hit_xsize = (canvas->w / GT_SIZE) + 1;
|
||||
|
||||
glasstile_hit = (int * *) malloc(sizeof(int *) * glasstile_hit_ysize);
|
||||
glasstile_hit = (int * *)malloc(sizeof(int *) * glasstile_hit_ysize);
|
||||
|
||||
for (yy = 0; yy < glasstile_hit_ysize; yy++)
|
||||
glasstile_hit[yy] = (int *) malloc(sizeof(int) * glasstile_hit_xsize);
|
||||
}
|
||||
for (yy = 0; yy < glasstile_hit_ysize; yy++)
|
||||
glasstile_hit[yy] = (int *)malloc(sizeof(int) * glasstile_hit_xsize);
|
||||
}
|
||||
|
||||
for (yy = 0; yy < glasstile_hit_ysize; yy++)
|
||||
for (xx = 0; xx < glasstile_hit_xsize; xx++)
|
||||
|
|
@ -269,24 +255,24 @@ void glasstile_click(magic_api * api, int which, int mode,
|
|||
if (mode == MODE_PAINT)
|
||||
glasstile_drag(api, which, canvas, last, x, y, x, y, update_rect);
|
||||
else if (mode == MODE_FULLSCREEN)
|
||||
{
|
||||
for (y = 0; y < canvas->h; y = y + GT_SIZE)
|
||||
for (x = 0; x < canvas->w; x = x + GT_SIZE)
|
||||
do_glasstile(api, which, canvas, last, x, y);
|
||||
{
|
||||
for (y = 0; y < canvas->h; y = y + GT_SIZE)
|
||||
for (x = 0; x < canvas->w; x = x + GT_SIZE)
|
||||
do_glasstile(api, which, canvas, last, x, y);
|
||||
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
|
||||
/* FIXME: Play sfx */
|
||||
}
|
||||
/* FIXME: Play sfx */
|
||||
}
|
||||
}
|
||||
|
||||
// Affect the canvas on release:
|
||||
void glasstile_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)
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -297,20 +283,21 @@ void glasstile_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
|||
|
||||
if (glasstile_snd != NULL)
|
||||
Mix_FreeChunk(glasstile_snd);
|
||||
|
||||
|
||||
if (glasstile_hit != NULL)
|
||||
{
|
||||
for (y = 0; y < glasstile_hit_ysize; y++)
|
||||
{
|
||||
if (glasstile_hit[y] != NULL)
|
||||
free(glasstile_hit[y]);
|
||||
for (y = 0; y < glasstile_hit_ysize; y++)
|
||||
{
|
||||
if (glasstile_hit[y] != NULL)
|
||||
free(glasstile_hit[y]);
|
||||
}
|
||||
free(glasstile_hit);
|
||||
}
|
||||
free(glasstile_hit);
|
||||
}
|
||||
}
|
||||
|
||||
// Record the color from Tux Paint:
|
||||
void glasstile_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
|
||||
void glasstile_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
|
||||
Uint8 b ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -320,15 +307,17 @@ int glasstile_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIB
|
|||
return 0;
|
||||
}
|
||||
|
||||
void glasstile_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void glasstile_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void glasstile_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void glasstile_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
int glasstile_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_PAINT | MODE_FULLSCREEN);
|
||||
return (MODE_PAINT | MODE_FULLSCREEN);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,39 +30,34 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h> /* for RAND_MAX */
|
||||
#include <stdlib.h> /* for RAND_MAX */
|
||||
#include "tp_magic_api.h"
|
||||
#include "SDL_image.h"
|
||||
#include "SDL_mixer.h"
|
||||
|
||||
/* Our globals: */
|
||||
|
||||
static Mix_Chunk * grass_snd;
|
||||
static Mix_Chunk *grass_snd;
|
||||
static Uint8 grass_r, grass_g, grass_b;
|
||||
static SDL_Surface * img_grass;
|
||||
static SDL_Surface *img_grass;
|
||||
|
||||
// Prototypes
|
||||
int grass_init(magic_api * api);
|
||||
Uint32 grass_api_version(void);
|
||||
int grass_get_tool_count(magic_api * api);
|
||||
SDL_Surface * grass_get_icon(magic_api * api, int which);
|
||||
char * grass_get_name(magic_api * api, int which);
|
||||
char * grass_get_description(magic_api * api, int which, int mode);
|
||||
SDL_Surface *grass_get_icon(magic_api * api, int which);
|
||||
char *grass_get_name(magic_api * api, int which);
|
||||
char *grass_get_description(magic_api * api, int which, int mode);
|
||||
void grass_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
void grass_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void grass_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void grass_shutdown(magic_api * api);
|
||||
void grass_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
int grass_requires_colors(magic_api * api, int which);
|
||||
static void do_grass(void * ptr, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y);
|
||||
static void do_grass(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||
static int log2int(int x);
|
||||
void grass_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
void grass_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
|
|
@ -74,81 +69,90 @@ int grass_init(magic_api * api)
|
|||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/grass.wav",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/grass.wav", api->data_directory);
|
||||
grass_snd = Mix_LoadWAV(fname);
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/grass_data.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/grass_data.png", api->data_directory);
|
||||
img_grass = IMG_Load(fname);
|
||||
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Uint32 grass_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
Uint32 grass_api_version(void)
|
||||
{
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
// We have multiple tools:
|
||||
int grass_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
// Load our icons:
|
||||
SDL_Surface * grass_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
SDL_Surface *grass_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/grass.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/grass.png", api->data_directory);
|
||||
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our names, localized:
|
||||
char * grass_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
char *grass_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(strdup(gettext_noop("Grass")));
|
||||
return (strdup(gettext_noop("Grass")));
|
||||
}
|
||||
|
||||
// Return our descriptions, localized:
|
||||
char * grass_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
||||
char *grass_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(strdup(gettext_noop("Click and drag to draw grass. Don’t forget the dirt!")));
|
||||
return (strdup(gettext_noop("Click and drag to draw grass. Don’t forget the dirt!")));
|
||||
}
|
||||
|
||||
|
||||
// Affect the canvas on drag:
|
||||
void grass_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
api->line((void *) api, which, canvas, last, ox, oy, x, y, 4, do_grass);
|
||||
api->line((void *)api, which, canvas, last, ox, oy, x, y, 4, do_grass);
|
||||
|
||||
if (ox > x) { int tmp = ox; ox = x; x = tmp; }
|
||||
if (oy > y) { int tmp = oy; oy = y; y = tmp; }
|
||||
if (ox > x)
|
||||
{
|
||||
int tmp = ox;
|
||||
|
||||
ox = x;
|
||||
x = tmp;
|
||||
}
|
||||
if (oy > y)
|
||||
{
|
||||
int tmp = oy;
|
||||
|
||||
oy = y;
|
||||
y = tmp;
|
||||
}
|
||||
|
||||
update_rect->x = ox - 64;
|
||||
update_rect->y = oy - 64;
|
||||
update_rect->w = 128;
|
||||
update_rect->h = 192;
|
||||
|
||||
api->playsound(grass_snd,
|
||||
(x * 255) / canvas->w, (y * 255) / canvas->h);
|
||||
api->playsound(grass_snd, (x * 255) / canvas->w, (y * 255) / canvas->h);
|
||||
}
|
||||
|
||||
// Affect the canvas on click:
|
||||
void grass_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect)
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
grass_drag(api, which, canvas, last, x, y, x, y, update_rect);
|
||||
}
|
||||
|
||||
void grass_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)
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -173,12 +177,12 @@ int grass_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_
|
|||
return 1;
|
||||
}
|
||||
|
||||
static void do_grass(void * ptr, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x, int y)
|
||||
static void do_grass(void *ptr, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
int xx, yy;
|
||||
|
||||
// grass color: 82,180,17
|
||||
static int bucket;
|
||||
double tmp_red, tmp_green, tmp_blue;
|
||||
|
|
@ -187,92 +191,79 @@ static void do_grass(void * ptr, int which ATTRIBUTE_UNUSED,
|
|||
|
||||
if (!api->button_down())
|
||||
bucket = 0;
|
||||
bucket += (3.5 + (rand() / (double) RAND_MAX)) * 7.0;
|
||||
bucket += (3.5 + (rand() / (double)RAND_MAX)) * 7.0;
|
||||
while (bucket >= 0)
|
||||
{
|
||||
int rank =
|
||||
log2int(((double) y / canvas->h) *
|
||||
(0.99 + (rand() / (double) RAND_MAX)) * 64);
|
||||
int ah = 1 << rank;
|
||||
bucket -= ah;
|
||||
src.x = (rand() % 4) * 64;
|
||||
src.y = ah;
|
||||
src.w = 64;
|
||||
src.h = ah;
|
||||
|
||||
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);
|
||||
|
||||
for (yy = 0; yy < ah; yy++)
|
||||
{
|
||||
for (xx = 0; xx < 64; xx++)
|
||||
{
|
||||
double rd, gd, bd;
|
||||
int rank = log2int(((double)y / canvas->h) * (0.99 + (rand() / (double)RAND_MAX)) * 64);
|
||||
int ah = 1 << rank;
|
||||
|
||||
SDL_GetRGBA(api->getpixel(img_grass, xx + src.x, yy + src.y),
|
||||
img_grass->format, &r, &g, &b, &a);
|
||||
bucket -= ah;
|
||||
src.x = (rand() % 4) * 64;
|
||||
src.y = ah;
|
||||
src.w = 64;
|
||||
src.h = ah;
|
||||
|
||||
rd = api->sRGB_to_linear(r) * 8.0 + tmp_red;
|
||||
rd = rd * (a / 255.0) / 11.0;
|
||||
gd = api->sRGB_to_linear(g) * 8.0 + tmp_green;
|
||||
gd = gd * (a / 255.0) / 11.0;
|
||||
bd = api->sRGB_to_linear(b) * 8.0 + tmp_blue;
|
||||
bd = bd * (a / 255.0) / 11.0;
|
||||
dest.x = x - 32;
|
||||
dest.y = y - 30 + (int)((rand() / (double)RAND_MAX) * 30);
|
||||
|
||||
SDL_GetRGB(api->getpixel(canvas, xx + dest.x, yy + dest.y),
|
||||
canvas->format, &r, &g, &b);
|
||||
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);
|
||||
|
||||
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);
|
||||
for (yy = 0; yy < ah; yy++)
|
||||
{
|
||||
for (xx = 0; xx < 64; xx++)
|
||||
{
|
||||
double rd, gd, bd;
|
||||
|
||||
api->putpixel(canvas, xx + dest.x, yy + dest.y,
|
||||
SDL_MapRGB(canvas->format, r, g, b));
|
||||
}
|
||||
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;
|
||||
gd = api->sRGB_to_linear(g) * 8.0 + tmp_green;
|
||||
gd = gd * (a / 255.0) / 11.0;
|
||||
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);
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// this one rounds down
|
||||
static int log2int(int x)
|
||||
{
|
||||
int y = 0;
|
||||
|
||||
if (x <= 1)
|
||||
return 0;
|
||||
x >>= 1;
|
||||
while (x)
|
||||
{
|
||||
x >>= 1;
|
||||
y++;
|
||||
}
|
||||
{
|
||||
x >>= 1;
|
||||
y++;
|
||||
}
|
||||
return y;
|
||||
}
|
||||
|
||||
void grass_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void grass_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void grass_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void grass_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
int grass_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_PAINT);
|
||||
return (MODE_PAINT);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,55 +16,51 @@
|
|||
#include "SDL_image.h"
|
||||
#include "SDL_mixer.h"
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
TOOL_HALFTONE,
|
||||
NUM_TOOLS
|
||||
};
|
||||
|
||||
|
||||
const char * snd_filenames[NUM_TOOLS] = {
|
||||
const char *snd_filenames[NUM_TOOLS] = {
|
||||
"halftone.wav",
|
||||
};
|
||||
|
||||
const char * icon_filenames[NUM_TOOLS] = {
|
||||
const char *icon_filenames[NUM_TOOLS] = {
|
||||
"halftone.png",
|
||||
};
|
||||
|
||||
const char * names[NUM_TOOLS] = {
|
||||
const char *names[NUM_TOOLS] = {
|
||||
gettext_noop("Halftone"),
|
||||
};
|
||||
|
||||
const char * descs[NUM_TOOLS] = {
|
||||
const char *descs[NUM_TOOLS] = {
|
||||
gettext_noop("Click and drag to turn your drawing into a newspaper."),
|
||||
};
|
||||
|
||||
Mix_Chunk * snd_effect[NUM_TOOLS];
|
||||
Mix_Chunk *snd_effect[NUM_TOOLS];
|
||||
|
||||
static SDL_Surface * canvas_backup, * square;
|
||||
static SDL_Surface *canvas_backup, *square;
|
||||
|
||||
/* Function Prototypes: */
|
||||
|
||||
void halftone_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
void halftone_line_callback(void * ptr, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y);
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
void halftone_line_callback(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
|
||||
Uint32 halftone_api_version(void);
|
||||
int halftone_init(magic_api * api);
|
||||
int halftone_get_tool_count(magic_api * api);
|
||||
SDL_Surface * halftone_get_icon(magic_api * api, int which);
|
||||
char * halftone_get_name(magic_api * api, int which);
|
||||
char * halftone_get_description(magic_api * api, int which, int mode);
|
||||
SDL_Surface *halftone_get_icon(magic_api * api, int which);
|
||||
char *halftone_get_name(magic_api * api, int which);
|
||||
char *halftone_get_description(magic_api * api, int which, int mode);
|
||||
int halftone_requires_colors(magic_api * api, int which);
|
||||
int halftone_modes(magic_api * api, int which);
|
||||
void halftone_shutdown(magic_api * api);
|
||||
void halftone_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
|
||||
void halftone_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
|
||||
void halftone_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
void halftone_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
void halftone_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
|
|
@ -72,7 +68,7 @@ void halftone_rgb2cmyk(Uint8 r, Uint8 g, Uint8 b, float cmyk[]);
|
|||
|
||||
Uint32 halftone_api_version(void)
|
||||
{
|
||||
return(TP_MAGIC_API_VERSION);
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
int halftone_init(magic_api * api)
|
||||
|
|
@ -84,58 +80,56 @@ int halftone_init(magic_api * api)
|
|||
square = NULL;
|
||||
|
||||
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) {
|
||||
SDL_FreeSurface(canvas_backup);
|
||||
SDL_FreeSurface(square);
|
||||
return(0);
|
||||
snd_effect[i] = Mix_LoadWAV(fname);
|
||||
if (snd_effect[i] == NULL)
|
||||
{
|
||||
SDL_FreeSurface(canvas_backup);
|
||||
SDL_FreeSurface(square);
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
int halftone_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(NUM_TOOLS);
|
||||
return (NUM_TOOLS);
|
||||
}
|
||||
|
||||
SDL_Surface * halftone_get_icon(magic_api * api, int which)
|
||||
SDL_Surface *halftone_get_icon(magic_api * api, int which)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/%s",
|
||||
api->data_directory, icon_filenames[which]);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/%s", api->data_directory, icon_filenames[which]);
|
||||
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
char * halftone_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
|
||||
char *halftone_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
|
||||
{
|
||||
const char * our_name_english;
|
||||
const char * our_name_localized;
|
||||
const char *our_name_english;
|
||||
const char *our_name_localized;
|
||||
|
||||
our_name_english = names[which];
|
||||
our_name_localized = gettext_noop(our_name_english);
|
||||
|
||||
return(strdup(our_name_localized));
|
||||
return (strdup(our_name_localized));
|
||||
}
|
||||
|
||||
char * halftone_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
|
||||
char *halftone_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
|
||||
{
|
||||
const char * our_desc_english;
|
||||
const char * our_desc_localized;
|
||||
const char *our_desc_english;
|
||||
const char *our_desc_localized;
|
||||
|
||||
our_desc_english = descs[which];
|
||||
our_desc_localized = gettext_noop(our_desc_english);
|
||||
|
||||
return(strdup(our_desc_localized));
|
||||
return (strdup(our_desc_localized));
|
||||
}
|
||||
|
||||
int halftone_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
|
|
@ -160,33 +154,42 @@ void halftone_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
|||
}
|
||||
|
||||
void halftone_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect)
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
halftone_drag(api, which, canvas, snapshot, x, y, x, y, update_rect);
|
||||
}
|
||||
|
||||
void halftone_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
api->line((void *) api, which, canvas, snapshot,
|
||||
ox, oy, x, y, 4, halftone_line_callback);
|
||||
api->line((void *)api, which, canvas, snapshot, ox, oy, x, y, 4, halftone_line_callback);
|
||||
|
||||
if (ox > x) { int tmp = ox; ox = x; x = tmp; }
|
||||
if (oy > y) { int tmp = oy; oy = y; y = tmp; }
|
||||
if (ox > x)
|
||||
{
|
||||
int tmp = ox;
|
||||
|
||||
ox = x;
|
||||
x = tmp;
|
||||
}
|
||||
if (oy > y)
|
||||
{
|
||||
int tmp = oy;
|
||||
|
||||
oy = y;
|
||||
y = tmp;
|
||||
}
|
||||
|
||||
update_rect->x = ox - 16;
|
||||
update_rect->y = oy - 16;
|
||||
update_rect->w = (x + 16) - update_rect->x;
|
||||
update_rect->h = (y + 16) - update_rect->h;
|
||||
|
||||
api->playsound(snd_effect[which],
|
||||
(x * 255) / canvas->w, // pan
|
||||
255); // distance
|
||||
api->playsound(snd_effect[which], (x * 255) / canvas->w, // pan
|
||||
255); // distance
|
||||
}
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
CHAN_CYAN,
|
||||
CHAN_MAGENTA,
|
||||
CHAN_YELLOW,
|
||||
|
|
@ -195,10 +198,10 @@ enum {
|
|||
};
|
||||
|
||||
Uint8 chan_colors[NUM_CHANS][3] = {
|
||||
{ 0, 255, 255 },
|
||||
{ 255, 0, 255 },
|
||||
{ 255, 255, 0 },
|
||||
{ 0, 0, 0 }
|
||||
{0, 255, 255},
|
||||
{255, 0, 255},
|
||||
{255, 255, 0},
|
||||
{0, 0, 0}
|
||||
};
|
||||
|
||||
int chan_angles[NUM_CHANS] = {
|
||||
|
|
@ -209,28 +212,25 @@ 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)
|
||||
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * snapshot ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void halftone_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED,
|
||||
Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
|
||||
void halftone_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED,
|
||||
Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void halftone_line_callback(void * ptr, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED,
|
||||
int x, int y)
|
||||
void halftone_line_callback(void *ptr, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
|
||||
{
|
||||
Uint8 r, g, b, or, og, ob;
|
||||
Uint32 total_r, total_g, total_b;
|
||||
Uint32 pixel;
|
||||
int xx, yy, xxx, yyy, channel, ox, oy, sqx, sqy;
|
||||
SDL_Rect dest;
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
float cmyk[4];
|
||||
|
||||
pixel = SDL_MapRGB(square->format, 255, 255, 255);
|
||||
|
|
@ -240,62 +240,77 @@ 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; }
|
||||
|
||||
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);
|
||||
total_r += r;
|
||||
total_g += g;
|
||||
total_b += b;
|
||||
}
|
||||
}
|
||||
total_r /= 16;
|
||||
total_g /= 16;
|
||||
total_b /= 16;
|
||||
|
||||
/* Convert to CMYK values */
|
||||
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++) {
|
||||
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++) {
|
||||
/* 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 */
|
||||
ox = xxx;
|
||||
oy = yyy;
|
||||
|
||||
sqx = (xx + ox) % 16;
|
||||
sqy = (yy + oy) % 16;
|
||||
|
||||
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 it's just white, put full color down */
|
||||
pixel = SDL_MapRGB(square->format, r, g, b);
|
||||
} else {
|
||||
/* Otherwise, blend a little */
|
||||
pixel = SDL_MapRGB(square->format, (r + or) / 2, (g + og) / 2, (b + ob) / 2);
|
||||
}
|
||||
|
||||
api->putpixel(square, sqx, sqy, pixel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (api->touched(x, y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
total_r += r;
|
||||
total_g += g;
|
||||
total_b += b;
|
||||
}
|
||||
}
|
||||
total_r /= 16;
|
||||
total_g /= 16;
|
||||
total_b /= 16;
|
||||
|
||||
/* Convert to CMYK values */
|
||||
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++)
|
||||
{
|
||||
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++)
|
||||
{
|
||||
/* 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 */
|
||||
ox = xxx;
|
||||
oy = yyy;
|
||||
|
||||
sqx = (xx + ox) % 16;
|
||||
sqy = (yy + oy) % 16;
|
||||
|
||||
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 it's just white, put full color down */
|
||||
pixel = SDL_MapRGB(square->format, r, g, b);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Otherwise, blend a little */
|
||||
pixel = SDL_MapRGB(square->format, (r + or) / 2, (g + og) / 2, (b + ob) / 2);
|
||||
}
|
||||
|
||||
api->putpixel(square, sqx, sqy, pixel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dest.x = x;
|
||||
dest.y = y;
|
||||
|
|
@ -303,22 +318,25 @@ 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!? :( */
|
||||
|
||||
SDL_BlitSurface(canvas, NULL, canvas_backup, NULL);
|
||||
}
|
||||
|
||||
void halftone_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
|
||||
int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void halftone_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
|
||||
int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -331,25 +349,25 @@ void halftone_rgb2cmyk(Uint8 r, Uint8 g, Uint8 b, float cmyk[])
|
|||
by Alexei Kourbatov <alexei@kourbatov.com> */
|
||||
|
||||
if (r == 0 && g == 0 && b == 0)
|
||||
{
|
||||
/* Black */
|
||||
c = 0.0;
|
||||
m = 0.0;
|
||||
y = 0.0;
|
||||
k = 1.0;
|
||||
}
|
||||
{
|
||||
/* Black */
|
||||
c = 0.0;
|
||||
m = 0.0;
|
||||
y = 0.0;
|
||||
k = 1.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
c = 1.0 - (((float) r) / 255.0);
|
||||
m = 1.0 - (((float) g) / 255.0);
|
||||
y = 1.0 - (((float) b) / 255.0);
|
||||
|
||||
mincmy = min(c, min(m, y));
|
||||
c = (c - mincmy) / (1.0 - mincmy);
|
||||
m = (m - mincmy) / (1.0 - mincmy);
|
||||
y = (y - mincmy) / (1.0 - mincmy);
|
||||
k = mincmy;
|
||||
}
|
||||
{
|
||||
c = 1.0 - (((float)r) / 255.0);
|
||||
m = 1.0 - (((float)g) / 255.0);
|
||||
y = 1.0 - (((float)b) / 255.0);
|
||||
|
||||
mincmy = min(c, min(m, y));
|
||||
c = (c - mincmy) / (1.0 - mincmy);
|
||||
m = (m - mincmy) / (1.0 - mincmy);
|
||||
y = (y - mincmy) / (1.0 - mincmy);
|
||||
k = mincmy;
|
||||
}
|
||||
|
||||
cmyk[0] = c;
|
||||
cmyk[1] = m;
|
||||
|
|
|
|||
|
|
@ -35,12 +35,13 @@
|
|||
|
||||
/* Our globals: */
|
||||
|
||||
static Mix_Chunk * kalidescope_snd;
|
||||
static Mix_Chunk *kalidescope_snd;
|
||||
static Uint8 kalidescope_r, kalidescope_g, kalidescope_b;
|
||||
static int square_size = 128;
|
||||
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
KAL_UD,
|
||||
KAL_LR,
|
||||
KAL_BOTH,
|
||||
|
|
@ -49,7 +50,7 @@ enum {
|
|||
KAL_COUNT
|
||||
};
|
||||
|
||||
char * kal_icon_names[KAL_COUNT] = {
|
||||
char *kal_icon_names[KAL_COUNT] = {
|
||||
"symmetric_updown.png",
|
||||
"symmetric_leftright.png",
|
||||
"kalidescope.png",
|
||||
|
|
@ -62,20 +63,16 @@ char * kal_icon_names[KAL_COUNT] = {
|
|||
Uint32 kalidescope_api_version(void);
|
||||
int kalidescope_init(magic_api * api);
|
||||
int kalidescope_get_tool_count(magic_api * api);
|
||||
SDL_Surface * kalidescope_get_icon(magic_api * api, int which);
|
||||
char * kalidescope_get_name(magic_api * api, int which);
|
||||
char * kalidescope_get_description(magic_api * api, int which, int mode);
|
||||
static void do_kalidescope(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y);
|
||||
SDL_Surface *kalidescope_get_icon(magic_api * api, int which);
|
||||
char *kalidescope_get_name(magic_api * api, int which);
|
||||
char *kalidescope_get_description(magic_api * api, int which, int mode);
|
||||
static void do_kalidescope(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||
void kalidescope_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
void kalidescope_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void kalidescope_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void kalidescope_shutdown(magic_api * api);
|
||||
int kalidescope_requires_colors(magic_api * api, int which);
|
||||
void kalidescope_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
|
|
@ -83,120 +80,144 @@ void kalidescope_switchin(magic_api * api, int which, int mode, SDL_Surface * ca
|
|||
void kalidescope_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
int kalidescope_modes(magic_api * api, int which);
|
||||
|
||||
Uint32 kalidescope_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
Uint32 kalidescope_api_version(void)
|
||||
{
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
// No setup required:
|
||||
int kalidescope_init(magic_api * api)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/kaleidoscope.ogg",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/kaleidoscope.ogg", api->data_directory);
|
||||
kalidescope_snd = Mix_LoadWAV(fname);
|
||||
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
int kalidescope_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(KAL_COUNT);
|
||||
return (KAL_COUNT);
|
||||
}
|
||||
|
||||
// Load our icons:
|
||||
SDL_Surface * kalidescope_get_icon(magic_api * api, int which)
|
||||
SDL_Surface *kalidescope_get_icon(magic_api * api, int which)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/%s",
|
||||
api->data_directory, kal_icon_names[which]);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/%s", api->data_directory, kal_icon_names[which]);
|
||||
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our names, localized:
|
||||
char * kalidescope_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
|
||||
char *kalidescope_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
|
||||
{
|
||||
if (which == KAL_LR) {
|
||||
return(strdup(gettext_noop("Symmetric Left/Right")));
|
||||
} else if (which == KAL_UD) {
|
||||
return(strdup(gettext_noop("Symmetric Up/Down")));
|
||||
} else if (which == KAL_PATTERN) {
|
||||
return(strdup(gettext_noop("Pattern")));
|
||||
} else if (which == KAL_TILES) {
|
||||
return(strdup(gettext_noop("Tiles")));
|
||||
} else { /* KAL_BOTH */
|
||||
return(strdup(gettext_noop("Kaleidoscope")));
|
||||
}
|
||||
if (which == KAL_LR)
|
||||
{
|
||||
return (strdup(gettext_noop("Symmetric Left/Right")));
|
||||
}
|
||||
else if (which == KAL_UD)
|
||||
{
|
||||
return (strdup(gettext_noop("Symmetric Up/Down")));
|
||||
}
|
||||
else if (which == KAL_PATTERN)
|
||||
{
|
||||
return (strdup(gettext_noop("Pattern")));
|
||||
}
|
||||
else if (which == KAL_TILES)
|
||||
{
|
||||
return (strdup(gettext_noop("Tiles")));
|
||||
}
|
||||
else
|
||||
{ /* KAL_BOTH */
|
||||
return (strdup(gettext_noop("Kaleidoscope")));
|
||||
}
|
||||
}
|
||||
|
||||
// Return our descriptions, localized:
|
||||
char * kalidescope_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
|
||||
char *kalidescope_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
|
||||
{
|
||||
if (which == KAL_LR) {
|
||||
return(strdup(gettext_noop("Click and drag the mouse to draw with two brushes that are symmetric across the left and right of your picture.")));
|
||||
} else if (which == KAL_UD) {
|
||||
return(strdup(gettext_noop("Click and drag the mouse to draw with two brushes that are symmetric across the top and bottom of your picture.")));
|
||||
} else if (which == KAL_PATTERN) {
|
||||
return(strdup(gettext_noop("Click and drag the mouse to draw a pattern across the picture.")));
|
||||
} else if (which == KAL_TILES) {
|
||||
return(strdup(gettext_noop("Click and drag the mouse to draw a pattern that is symmetric across the picture.")));
|
||||
} else { /* KAL_BOTH */
|
||||
return(strdup(gettext_noop("Click and drag the mouse to draw with symmetric brushes (a kaleidoscope).")));
|
||||
}
|
||||
if (which == KAL_LR)
|
||||
{
|
||||
return (strdup
|
||||
(gettext_noop
|
||||
("Click and drag the mouse to draw with two brushes that are symmetric across the left and right of your picture.")));
|
||||
}
|
||||
else if (which == KAL_UD)
|
||||
{
|
||||
return (strdup
|
||||
(gettext_noop
|
||||
("Click and drag the mouse to draw with two brushes that are symmetric across the top and bottom of your picture.")));
|
||||
}
|
||||
else if (which == KAL_PATTERN)
|
||||
{
|
||||
return (strdup(gettext_noop("Click and drag the mouse to draw a pattern across the picture.")));
|
||||
}
|
||||
else if (which == KAL_TILES)
|
||||
{
|
||||
return (strdup(gettext_noop("Click and drag the mouse to draw a pattern that is symmetric across the picture.")));
|
||||
}
|
||||
else
|
||||
{ /* KAL_BOTH */
|
||||
return (strdup(gettext_noop("Click and drag the mouse to draw with symmetric brushes (a kaleidoscope).")));
|
||||
}
|
||||
}
|
||||
|
||||
// Do the effect:
|
||||
|
||||
static void do_kalidescope(void * ptr, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
|
||||
static void do_kalidescope(void *ptr, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
int xx, yy;
|
||||
int i, j;
|
||||
Uint32 colr;
|
||||
|
||||
colr = SDL_MapRGB(canvas->format,
|
||||
kalidescope_r,
|
||||
kalidescope_g,
|
||||
kalidescope_b);
|
||||
colr = SDL_MapRGB(canvas->format, kalidescope_r, kalidescope_g, kalidescope_b);
|
||||
|
||||
for (yy = -8; yy < 8; yy++)
|
||||
{
|
||||
for (xx = -8; xx < 8; xx++)
|
||||
{
|
||||
if (api->in_circle(xx, yy, 8))
|
||||
{
|
||||
api->putpixel(canvas, x + xx, y + yy, colr);
|
||||
for (xx = -8; xx < 8; xx++)
|
||||
{
|
||||
if (api->in_circle(xx, yy, 8))
|
||||
{
|
||||
api->putpixel(canvas, x + xx, y + yy, colr);
|
||||
|
||||
if (which == KAL_LR || which == KAL_BOTH) {
|
||||
api->putpixel(canvas, canvas->w - 1 - x + xx, y + yy, colr);
|
||||
if (which == KAL_LR || which == KAL_BOTH)
|
||||
{
|
||||
api->putpixel(canvas, canvas->w - 1 - x + xx, y + yy, colr);
|
||||
|
||||
if (which == KAL_BOTH) {
|
||||
api->putpixel(canvas, canvas->w - 1 - x + xx, canvas->h - 1 - y + yy, colr);
|
||||
}
|
||||
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)
|
||||
{
|
||||
api->putpixel(canvas, x + xx, canvas->h - 1 - y + yy, colr);
|
||||
}
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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) {
|
||||
for (i = 0; i <= canvas->w; i += 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Affect the canvas on drag:
|
||||
void kalidescope_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_kalidescope);
|
||||
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_kalidescope);
|
||||
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
|
|
@ -208,17 +229,15 @@ 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);
|
||||
}
|
||||
|
||||
// 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)
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
api->stopsound();
|
||||
}
|
||||
|
|
@ -244,17 +263,17 @@ int kalidescope_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTR
|
|||
return 1;
|
||||
}
|
||||
|
||||
void kalidescope_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
|
||||
int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void kalidescope_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
|
||||
int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void kalidescope_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
|
||||
int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void kalidescope_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
|
||||
int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
int kalidescope_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_PAINT);
|
||||
return (MODE_PAINT);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,25 +38,21 @@
|
|||
|
||||
/* Our globals: */
|
||||
|
||||
static Mix_Chunk * light1_snd, * light2_snd;
|
||||
static Mix_Chunk *light1_snd, *light2_snd;
|
||||
static float light_h, light_s, light_v;
|
||||
Uint32 light_api_version(void);
|
||||
int light_init(magic_api * api);
|
||||
int light_get_tool_count(magic_api * api);
|
||||
SDL_Surface * light_get_icon(magic_api * api, int which);
|
||||
char * light_get_name(magic_api * api, int which);
|
||||
char * light_get_description(magic_api * api, int which, int mode);
|
||||
static void do_light(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y);
|
||||
SDL_Surface *light_get_icon(magic_api * api, int which);
|
||||
char *light_get_name(magic_api * api, int which);
|
||||
char *light_get_description(magic_api * api, int which, int mode);
|
||||
static void do_light(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||
void light_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
void light_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void light_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void light_shutdown(magic_api * api);
|
||||
void light_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
int light_requires_colors(magic_api * api, int which);
|
||||
|
|
@ -65,7 +61,10 @@ void light_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
|
|||
int light_modes(magic_api * api, int which);
|
||||
|
||||
|
||||
Uint32 light_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
Uint32 light_api_version(void)
|
||||
{
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
|
||||
// No setup required:
|
||||
|
|
@ -73,52 +72,49 @@ int light_init(magic_api * api)
|
|||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/light1.ogg",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/light1.ogg", api->data_directory);
|
||||
light1_snd = Mix_LoadWAV(fname);
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/light2.ogg",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/light2.ogg", api->data_directory);
|
||||
light2_snd = Mix_LoadWAV(fname);
|
||||
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
// We have multiple tools:
|
||||
int light_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
// Load our icons:
|
||||
SDL_Surface * light_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
SDL_Surface *light_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/light.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/light.png", api->data_directory);
|
||||
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our names, localized:
|
||||
char * light_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
char *light_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(strdup(gettext_noop("Light")));
|
||||
return (strdup(gettext_noop("Light")));
|
||||
}
|
||||
|
||||
// Return our descriptions, localized:
|
||||
char * light_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
||||
char *light_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(strdup(gettext_noop("Click and drag to draw a beam of light on your picture.")));
|
||||
return (strdup(gettext_noop("Click and drag to draw a beam of light on your picture.")));
|
||||
}
|
||||
|
||||
// Do the effect:
|
||||
|
||||
static void do_light(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x, int y)
|
||||
static void do_light(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x, int y)
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
int xx, yy;
|
||||
Uint32 pix;
|
||||
Uint8 r, g, b;
|
||||
|
|
@ -126,64 +122,74 @@ static void do_light(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canva
|
|||
float adj;
|
||||
|
||||
for (yy = -8; yy < 8; yy++)
|
||||
{
|
||||
for (xx = -8; xx < 8; xx++)
|
||||
{
|
||||
if (api->in_circle(xx, yy, 8))
|
||||
{
|
||||
pix = api->getpixel(canvas, x + xx, y + yy);
|
||||
|
||||
SDL_GetRGB(pix, canvas->format, &r, &g, &b);
|
||||
|
||||
adj = (7.99 - sqrt(abs(xx * yy))) / 128.0;
|
||||
|
||||
api->rgbtohsv(r, g, b, &h, &s, &v);
|
||||
|
||||
v = min((float) 1.0, v + adj);
|
||||
|
||||
if (light_h == -1 && h == -1)
|
||||
for (xx = -8; xx < 8; xx++)
|
||||
{
|
||||
new_h = -1;
|
||||
new_s = 0;
|
||||
new_v = v;
|
||||
}
|
||||
else if (light_h == -1)
|
||||
{
|
||||
new_h = h;
|
||||
new_s = max(0.0, s - adj / 2.0);
|
||||
new_v = v;
|
||||
}
|
||||
else if (h == -1)
|
||||
{
|
||||
new_h = light_h;
|
||||
new_s = max(0.0, light_s - adj / 2.0);
|
||||
new_v = v;
|
||||
}
|
||||
else
|
||||
{
|
||||
new_h = (light_h + h) / 2;
|
||||
new_s = max(0.0, s - adj / 2.0);
|
||||
new_v = v;
|
||||
}
|
||||
if (api->in_circle(xx, yy, 8))
|
||||
{
|
||||
pix = api->getpixel(canvas, x + xx, y + yy);
|
||||
|
||||
api->hsvtorgb(new_h, new_s, new_v, &r, &g, &b);
|
||||
SDL_GetRGB(pix, canvas->format, &r, &g, &b);
|
||||
|
||||
api->putpixel(canvas, x + xx, y + yy,
|
||||
SDL_MapRGB(canvas->format, r, g, b));
|
||||
}
|
||||
adj = (7.99 - sqrt(abs(xx * yy))) / 128.0;
|
||||
|
||||
api->rgbtohsv(r, g, b, &h, &s, &v);
|
||||
|
||||
v = min((float)1.0, v + adj);
|
||||
|
||||
if (light_h == -1 && h == -1)
|
||||
{
|
||||
new_h = -1;
|
||||
new_s = 0;
|
||||
new_v = v;
|
||||
}
|
||||
else if (light_h == -1)
|
||||
{
|
||||
new_h = h;
|
||||
new_s = max(0.0, s - adj / 2.0);
|
||||
new_v = v;
|
||||
}
|
||||
else if (h == -1)
|
||||
{
|
||||
new_h = light_h;
|
||||
new_s = max(0.0, light_s - adj / 2.0);
|
||||
new_v = v;
|
||||
}
|
||||
else
|
||||
{
|
||||
new_h = (light_h + h) / 2;
|
||||
new_s = max(0.0, s - adj / 2.0);
|
||||
new_v = v;
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Affect the canvas on drag:
|
||||
void light_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_light);
|
||||
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_light);
|
||||
|
||||
if (ox > x) { int tmp = ox; ox = x; x = tmp; }
|
||||
if (oy > y) { int tmp = oy; oy = y; y = tmp; }
|
||||
if (ox > x)
|
||||
{
|
||||
int tmp = ox;
|
||||
|
||||
ox = x;
|
||||
x = tmp;
|
||||
}
|
||||
if (oy > y)
|
||||
{
|
||||
int tmp = oy;
|
||||
|
||||
oy = y;
|
||||
y = tmp;
|
||||
}
|
||||
|
||||
update_rect->x = ox - 8;
|
||||
update_rect->y = oy - 8;
|
||||
|
|
@ -195,16 +201,15 @@ 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);
|
||||
}
|
||||
|
||||
// Affect the canvas on release:
|
||||
void light_release(magic_api * api, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
api->playsound(light2_snd, (x * 255) / canvas->w, 255);
|
||||
}
|
||||
|
|
@ -230,15 +235,17 @@ int light_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_
|
|||
return 1;
|
||||
}
|
||||
|
||||
void light_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
void light_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void light_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void light_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
int light_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_PAINT);
|
||||
return (MODE_PAINT);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,26 +35,22 @@
|
|||
|
||||
/* Our globals: */
|
||||
|
||||
static Mix_Chunk * metalpaint_snd;
|
||||
static Mix_Chunk *metalpaint_snd;
|
||||
static Uint8 metalpaint_r, metalpaint_g, metalpaint_b;
|
||||
|
||||
Uint32 metalpaint_api_version(void);
|
||||
int metalpaint_init(magic_api * api);
|
||||
int metalpaint_get_tool_count(magic_api * api);
|
||||
SDL_Surface * metalpaint_get_icon(magic_api * api, int which);
|
||||
char * metalpaint_get_name(magic_api * api, int which);
|
||||
char * metalpaint_get_description(magic_api * api, int which, int mode);
|
||||
static void do_metalpaint(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y);
|
||||
SDL_Surface *metalpaint_get_icon(magic_api * api, int which);
|
||||
char *metalpaint_get_name(magic_api * api, int which);
|
||||
char *metalpaint_get_description(magic_api * api, int which, int mode);
|
||||
static void do_metalpaint(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||
void metalpaint_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
void metalpaint_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void metalpaint_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void metalpaint_shutdown(magic_api * api);
|
||||
void metalpaint_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
int metalpaint_requires_colors(magic_api * api, int which);
|
||||
|
|
@ -63,7 +59,10 @@ void metalpaint_switchout(magic_api * api, int which, int mode, SDL_Surface * ca
|
|||
int metalpaint_modes(magic_api * api, int which);
|
||||
|
||||
|
||||
Uint32 metalpaint_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
Uint32 metalpaint_api_version(void)
|
||||
{
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
|
||||
// No setup required:
|
||||
|
|
@ -71,40 +70,39 @@ int metalpaint_init(magic_api * api)
|
|||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/metalpaint.wav",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/metalpaint.wav", api->data_directory);
|
||||
metalpaint_snd = Mix_LoadWAV(fname);
|
||||
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
// We have multiple tools:
|
||||
int metalpaint_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
// Load our icons:
|
||||
SDL_Surface * metalpaint_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
SDL_Surface *metalpaint_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/metalpaint.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/metalpaint.png", api->data_directory);
|
||||
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our names, localized:
|
||||
char * metalpaint_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
char *metalpaint_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(strdup(gettext_noop("Metal Paint")));
|
||||
return (strdup(gettext_noop("Metal Paint")));
|
||||
}
|
||||
|
||||
// Return our descriptions, localized:
|
||||
char * metalpaint_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
||||
char *metalpaint_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
|
||||
int mode ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(strdup(gettext_noop("Click and drag the mouse to paint with a metallic color.")));
|
||||
return (strdup(gettext_noop("Click and drag the mouse to paint with a metallic color.")));
|
||||
}
|
||||
|
||||
#define METALPAINT_CYCLE 32
|
||||
|
|
@ -112,7 +110,7 @@ char * metalpaint_get_description(magic_api * api ATTRIBUTE_UNUSED, int which AT
|
|||
/* Based on 'Golden' gradient in The GIMP: */
|
||||
|
||||
static int metalpaint_gradient[METALPAINT_CYCLE] = {
|
||||
56, 64, 73, 83, 93, 102, 113, 123,
|
||||
56, 64, 73, 83, 93, 102, 113, 123,
|
||||
139, 154, 168, 180, 185, 189, 183, 174,
|
||||
164, 152, 142, 135, 129, 138, 149, 158,
|
||||
166, 163, 158, 149, 140, 122, 103, 82
|
||||
|
|
@ -120,38 +118,49 @@ static int metalpaint_gradient[METALPAINT_CYCLE] = {
|
|||
|
||||
// Do the effect:
|
||||
|
||||
static void do_metalpaint(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x, int y)
|
||||
static void do_metalpaint(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
|
||||
SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
int xx, yy;
|
||||
int n;
|
||||
Uint8 r, g, b;
|
||||
|
||||
for (yy = -8; yy < 8; yy++)
|
||||
{
|
||||
for (xx = -8; xx < 8; xx++)
|
||||
{
|
||||
n = metalpaint_gradient[((x + xx + y + yy) / 4) % METALPAINT_CYCLE];
|
||||
for (xx = -8; xx < 8; xx++)
|
||||
{
|
||||
n = metalpaint_gradient[((x + xx + y + yy) / 4) % METALPAINT_CYCLE];
|
||||
|
||||
r = (metalpaint_r * n) / 255;
|
||||
g = (metalpaint_g * n) / 255;
|
||||
b = (metalpaint_b * n) / 255;
|
||||
r = (metalpaint_r * n) / 255;
|
||||
g = (metalpaint_g * n) / 255;
|
||||
b = (metalpaint_b * n) / 255;
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Affect the canvas on drag:
|
||||
void metalpaint_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_metalpaint);
|
||||
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_metalpaint);
|
||||
|
||||
if (ox > x) { int tmp = ox; ox = x; x = tmp; }
|
||||
if (oy > y) { int tmp = oy; oy = y; y = tmp; }
|
||||
if (ox > x)
|
||||
{
|
||||
int tmp = ox;
|
||||
|
||||
ox = x;
|
||||
x = tmp;
|
||||
}
|
||||
if (oy > y)
|
||||
{
|
||||
int tmp = oy;
|
||||
|
||||
oy = y;
|
||||
y = tmp;
|
||||
}
|
||||
|
||||
update_rect->x = ox - 8;
|
||||
update_rect->y = oy - 8;
|
||||
|
|
@ -162,17 +171,16 @@ 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)
|
||||
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)
|
||||
{
|
||||
metalpaint_drag(api, which, canvas, last, x, y, x, y, update_rect);
|
||||
}
|
||||
|
||||
// Affect the canvas on release:
|
||||
void metalpaint_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)
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -197,15 +205,17 @@ int metalpaint_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRI
|
|||
return 1;
|
||||
}
|
||||
|
||||
void metalpaint_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void metalpaint_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void metalpaint_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void metalpaint_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
int metalpaint_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_PAINT);
|
||||
return (MODE_PAINT);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,31 +35,25 @@
|
|||
|
||||
/* What tools we contain: */
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
TOOL_MIRROR,
|
||||
TOOL_FLIP,
|
||||
NUM_TOOLS
|
||||
};
|
||||
|
||||
static Mix_Chunk * snd_effects[NUM_TOOLS];
|
||||
static Mix_Chunk *snd_effects[NUM_TOOLS];
|
||||
|
||||
/* Prototypes */
|
||||
int mirror_flip_init(magic_api *);
|
||||
Uint32 mirror_flip_api_version(void);
|
||||
int mirror_flip_get_tool_count(magic_api *);
|
||||
SDL_Surface * mirror_flip_get_icon(magic_api *, int);
|
||||
char * mirror_flip_get_name(magic_api *, int);
|
||||
char * mirror_flip_get_description(magic_api *, int, int);
|
||||
void mirror_flip_drag(magic_api *, int, SDL_Surface *,
|
||||
SDL_Surface *, int, int, int, int,
|
||||
SDL_Rect *);
|
||||
void mirror_flip_release(magic_api *, int, SDL_Surface *,
|
||||
SDL_Surface *, int, int, int, int,
|
||||
SDL_Rect *);
|
||||
void mirror_flip_click(magic_api *, int, int,
|
||||
SDL_Surface *, SDL_Surface *,
|
||||
int, int,
|
||||
SDL_Rect *);
|
||||
SDL_Surface *mirror_flip_get_icon(magic_api *, int);
|
||||
char *mirror_flip_get_name(magic_api *, int);
|
||||
char *mirror_flip_get_description(magic_api *, int, int);
|
||||
void mirror_flip_drag(magic_api *, int, SDL_Surface *, SDL_Surface *, int, int, int, int, SDL_Rect *);
|
||||
void mirror_flip_release(magic_api *, int, SDL_Surface *, SDL_Surface *, int, int, int, int, SDL_Rect *);
|
||||
void mirror_flip_click(magic_api *, int, int, SDL_Surface *, SDL_Surface *, int, int, SDL_Rect *);
|
||||
void mirror_flip_shutdown(magic_api *);
|
||||
void mirror_flip_set_color(magic_api *, Uint8, Uint8, Uint8);
|
||||
int mirror_flip_requires_colors(magic_api *, int);
|
||||
|
|
@ -72,134 +66,127 @@ int mirror_flip_init(magic_api * api)
|
|||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/mirror.wav",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/mirror.wav", api->data_directory);
|
||||
snd_effects[TOOL_MIRROR] = Mix_LoadWAV(fname);
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/flip.wav",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/flip.wav", api->data_directory);
|
||||
snd_effects[TOOL_FLIP] = Mix_LoadWAV(fname);
|
||||
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
Uint32 mirror_flip_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
Uint32 mirror_flip_api_version(void)
|
||||
{
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
// We have multiple tools:
|
||||
int mirror_flip_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(NUM_TOOLS);
|
||||
return (NUM_TOOLS);
|
||||
}
|
||||
|
||||
// Load our icons:
|
||||
SDL_Surface * mirror_flip_get_icon(magic_api * api, int which)
|
||||
SDL_Surface *mirror_flip_get_icon(magic_api * api, int which)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
if (which == TOOL_MIRROR)
|
||||
{
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/mirror.png",
|
||||
api->data_directory);
|
||||
}
|
||||
{
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/mirror.png", api->data_directory);
|
||||
}
|
||||
else if (which == TOOL_FLIP)
|
||||
{
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/flip.png",
|
||||
api->data_directory);
|
||||
}
|
||||
{
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/flip.png", api->data_directory);
|
||||
}
|
||||
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our names, localized:
|
||||
char * mirror_flip_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
|
||||
char *mirror_flip_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
|
||||
{
|
||||
if (which == TOOL_MIRROR)
|
||||
return(strdup(gettext_noop("Mirror")));
|
||||
return (strdup(gettext_noop("Mirror")));
|
||||
else if (which == TOOL_FLIP)
|
||||
return(strdup(gettext_noop("Flip")));
|
||||
return (strdup(gettext_noop("Flip")));
|
||||
|
||||
return(NULL);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
// Return our descriptions, localized:
|
||||
char * mirror_flip_get_description(magic_api * api ATTRIBUTE_UNUSED,
|
||||
int which, int mode ATTRIBUTE_UNUSED)
|
||||
char *mirror_flip_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
|
||||
{
|
||||
if (which == TOOL_MIRROR)
|
||||
return(strdup(
|
||||
gettext_noop("Click to make a mirror image.")));
|
||||
return (strdup(gettext_noop("Click to make a mirror image.")));
|
||||
else
|
||||
return(strdup(
|
||||
gettext_noop("Click to flip the picture upside-down.")));
|
||||
return (strdup(gettext_noop("Click to flip the picture upside-down.")));
|
||||
|
||||
return(NULL);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
// We affect the whole canvas, so only do things on click, not drag:
|
||||
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)
|
||||
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)
|
||||
{
|
||||
// No-op
|
||||
}
|
||||
|
||||
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 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)
|
||||
{
|
||||
// No-op
|
||||
}
|
||||
|
||||
// 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)
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect)
|
||||
{
|
||||
int xx, yy;
|
||||
SDL_Rect src, dest;
|
||||
|
||||
if (which == TOOL_MIRROR)
|
||||
{
|
||||
for (xx = 0; xx < canvas->w; xx++)
|
||||
{
|
||||
src.x = xx;
|
||||
src.y = 0;
|
||||
src.w = 1;
|
||||
src.h = canvas->h;
|
||||
for (xx = 0; xx < canvas->w; xx++)
|
||||
{
|
||||
src.x = xx;
|
||||
src.y = 0;
|
||||
src.w = 1;
|
||||
src.h = canvas->h;
|
||||
|
||||
dest.x = canvas->w - xx - 1;
|
||||
dest.y = 0;
|
||||
dest.x = canvas->w - xx - 1;
|
||||
dest.y = 0;
|
||||
|
||||
SDL_BlitSurface(last, &src, canvas, &dest);
|
||||
SDL_BlitSurface(last, &src, canvas, &dest);
|
||||
}
|
||||
|
||||
api->special_notify(SPECIAL_MIRROR);
|
||||
}
|
||||
|
||||
api->special_notify(SPECIAL_MIRROR);
|
||||
}
|
||||
else if (which == TOOL_FLIP)
|
||||
{
|
||||
for (yy = 0; yy < canvas->h; yy++)
|
||||
{
|
||||
src.x = 0;
|
||||
src.y = yy;
|
||||
src.w = canvas->w;
|
||||
src.h = 1;
|
||||
for (yy = 0; yy < canvas->h; yy++)
|
||||
{
|
||||
src.x = 0;
|
||||
src.y = yy;
|
||||
src.w = canvas->w;
|
||||
src.h = 1;
|
||||
|
||||
dest.x = 0;
|
||||
dest.y = canvas->h - yy - 1;
|
||||
dest.x = 0;
|
||||
dest.y = canvas->h - yy - 1;
|
||||
|
||||
SDL_BlitSurface(last, &src, canvas, &dest);
|
||||
SDL_BlitSurface(last, &src, canvas, &dest);
|
||||
}
|
||||
|
||||
api->special_notify(SPECIAL_FLIP);
|
||||
}
|
||||
|
||||
api->special_notify(SPECIAL_FLIP);
|
||||
}
|
||||
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
|
|
@ -218,33 +205,28 @@ 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)
|
||||
void mirror_flip_set_color(magic_api * api 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)
|
||||
void mirror_flip_switchin(magic_api * api 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)
|
||||
void mirror_flip_switchout(magic_api * api ATTRIBUTE_UNUSED,
|
||||
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
int mirror_flip_modes(magic_api * api ATTRIBUTE_UNUSED,
|
||||
int which ATTRIBUTE_UNUSED)
|
||||
int mirror_flip_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_FULLSCREEN);
|
||||
return (MODE_FULLSCREEN);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,29 +45,22 @@
|
|||
#define gettext_noop(String) String
|
||||
#endif
|
||||
|
||||
static void mosaic_noise_pixel(void * ptr, SDL_Surface * canvas, int noise_AMOUNT, int x, int y);
|
||||
static void mosaic_blur_pixel(void * ptr, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||
static void mosaic_sharpen_pixel(void * ptr, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||
static void mosaic_noise_pixel(void *ptr, SDL_Surface * canvas, int noise_AMOUNT, int x, int y);
|
||||
static void mosaic_blur_pixel(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||
static void mosaic_sharpen_pixel(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||
static void reset_mosaic_blured(SDL_Surface * canvas);
|
||||
|
||||
/* Prototypes */
|
||||
Uint32 mosaic_api_version(void);
|
||||
int mosaic_init(magic_api *);
|
||||
int mosaic_get_tool_count(magic_api *);
|
||||
SDL_Surface * mosaic_get_icon(magic_api *, int);
|
||||
char * mosaic_get_name(magic_api *, int);
|
||||
char * mosaic_get_description(magic_api *, int, int);
|
||||
void mosaic_paint(void *, int, SDL_Surface *,
|
||||
SDL_Surface *, int, int);
|
||||
void mosaic_drag(magic_api *, int, SDL_Surface *,
|
||||
SDL_Surface *, int, int, int, int,
|
||||
SDL_Rect *);
|
||||
void mosaic_click(magic_api *, int, int,
|
||||
SDL_Surface *, SDL_Surface *,
|
||||
int, int, SDL_Rect *);
|
||||
void mosaic_release(magic_api *, int,
|
||||
SDL_Surface *, SDL_Surface *,
|
||||
int, int, SDL_Rect *);
|
||||
SDL_Surface *mosaic_get_icon(magic_api *, int);
|
||||
char *mosaic_get_name(magic_api *, int);
|
||||
char *mosaic_get_description(magic_api *, int, int);
|
||||
void mosaic_paint(void *, int, SDL_Surface *, SDL_Surface *, int, int);
|
||||
void mosaic_drag(magic_api *, int, SDL_Surface *, SDL_Surface *, int, int, int, int, SDL_Rect *);
|
||||
void mosaic_click(magic_api *, int, int, SDL_Surface *, SDL_Surface *, int, int, SDL_Rect *);
|
||||
void mosaic_release(magic_api *, int, SDL_Surface *, SDL_Surface *, int, int, SDL_Rect *);
|
||||
void mosaic_shutdown(magic_api *);
|
||||
void mosaic_set_color(magic_api *, Uint8, Uint8, Uint8);
|
||||
int mosaic_requires_colors(magic_api *, int);
|
||||
|
|
@ -75,155 +68,169 @@ void mosaic_switchin(magic_api *, int, int, SDL_Surface *);
|
|||
void mosaic_switchout(magic_api *, int, int, SDL_Surface *);
|
||||
int mosaic_modes(magic_api *, int);
|
||||
|
||||
static const int mosaic_AMOUNT= 300;
|
||||
static const int mosaic_AMOUNT = 300;
|
||||
static const int mosaic_RADIUS = 16;
|
||||
static const double mosaic_SHARPEN = 1.0;
|
||||
static int randnoise ATTRIBUTE_UNUSED;
|
||||
Uint8 * mosaic_blured;
|
||||
enum {
|
||||
TOOL_MOSAIC,
|
||||
mosaic_NUM_TOOLS
|
||||
Uint8 *mosaic_blured;
|
||||
enum
|
||||
{
|
||||
TOOL_MOSAIC,
|
||||
mosaic_NUM_TOOLS
|
||||
};
|
||||
|
||||
static Mix_Chunk * mosaic_snd_effect[mosaic_NUM_TOOLS];
|
||||
static SDL_Surface * canvas_noise;
|
||||
static SDL_Surface * canvas_blur;
|
||||
static SDL_Surface * canvas_sharp;
|
||||
static Mix_Chunk *mosaic_snd_effect[mosaic_NUM_TOOLS];
|
||||
static SDL_Surface *canvas_noise;
|
||||
static SDL_Surface *canvas_blur;
|
||||
static SDL_Surface *canvas_sharp;
|
||||
|
||||
const char * mosaic_snd_filenames[mosaic_NUM_TOOLS] = {
|
||||
"mosaic.ogg", /* FIXME */
|
||||
const char *mosaic_snd_filenames[mosaic_NUM_TOOLS] = {
|
||||
"mosaic.ogg", /* FIXME */
|
||||
};
|
||||
const char * mosaic_icon_filenames[mosaic_NUM_TOOLS] = {
|
||||
|
||||
const char *mosaic_icon_filenames[mosaic_NUM_TOOLS] = {
|
||||
"mosaic.png",
|
||||
};
|
||||
const char * mosaic_names[mosaic_NUM_TOOLS] = {
|
||||
|
||||
const char *mosaic_names[mosaic_NUM_TOOLS] = {
|
||||
gettext_noop("Mosaic"),
|
||||
};
|
||||
const char * mosaic_descs[mosaic_NUM_TOOLS][2] = {
|
||||
|
||||
const char *mosaic_descs[mosaic_NUM_TOOLS][2] = {
|
||||
{gettext_noop("Click and drag the mouse to add a mosaic effect to parts of your picture."),
|
||||
gettext_noop("Click to add a mosaic effect to your entire picture."),},
|
||||
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++){
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/%s", api->data_directory, mosaic_snd_filenames[i]);
|
||||
mosaic_snd_effect[i] = Mix_LoadWAV(fname);
|
||||
}
|
||||
for (i = 0; i < mosaic_NUM_TOOLS; i++)
|
||||
{
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/%s", api->data_directory, mosaic_snd_filenames[i]);
|
||||
mosaic_snd_effect[i] = Mix_LoadWAV(fname);
|
||||
}
|
||||
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
int mosaic_get_tool_count(magic_api * api ATTRIBUTE_UNUSED){
|
||||
return(mosaic_NUM_TOOLS);
|
||||
int mosaic_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return (mosaic_NUM_TOOLS);
|
||||
}
|
||||
|
||||
// Load our icons:
|
||||
SDL_Surface * mosaic_get_icon(magic_api * api, int which){
|
||||
SDL_Surface *mosaic_get_icon(magic_api * api, int which)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, mosaic_icon_filenames[which]);
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our names, localized:
|
||||
char * mosaic_get_name(magic_api * api ATTRIBUTE_UNUSED, int which){
|
||||
return(strdup(gettext_noop(mosaic_names[which])));
|
||||
char *mosaic_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
|
||||
{
|
||||
return (strdup(gettext_noop(mosaic_names[which])));
|
||||
}
|
||||
|
||||
// Return our descriptions, localized:
|
||||
char * mosaic_get_description(magic_api * api ATTRIBUTE_UNUSED,
|
||||
int which, int mode){
|
||||
return(strdup(gettext_noop(mosaic_descs[which][mode-1])));
|
||||
char *mosaic_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode)
|
||||
{
|
||||
return (strdup(gettext_noop(mosaic_descs[which][mode - 1])));
|
||||
}
|
||||
|
||||
//Calculates the grey scale value for a rgb pixel
|
||||
static int mosaic_grey(Uint8 r1,Uint8 g1,Uint8 b1){
|
||||
return 0.3*r1+.59*g1+0.11*b1;
|
||||
static int mosaic_grey(Uint8 r1, Uint8 g1, Uint8 b1)
|
||||
{
|
||||
return 0.3 * r1 + .59 * g1 + 0.11 * b1;
|
||||
}
|
||||
|
||||
// Do the effect for the full image
|
||||
static void do_mosaic_full(void * ptr, SDL_Surface * canvas,
|
||||
SDL_Surface * last ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED){
|
||||
static void do_mosaic_full(void *ptr, SDL_Surface * canvas,
|
||||
SDL_Surface * last ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
|
||||
int x, y;
|
||||
|
||||
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,
|
||||
canvas->format->Rmask,
|
||||
canvas->format->Gmask,
|
||||
canvas->format->Bmask, amask);
|
||||
|
||||
int x,y;
|
||||
|
||||
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,
|
||||
canvas->format->Rmask,
|
||||
canvas->format->Gmask,
|
||||
canvas->format->Bmask, amask);
|
||||
|
||||
|
||||
|
||||
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++){
|
||||
mosaic_blur_pixel(api, mosaic_temp, canvas_noise, x, y);
|
||||
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++){
|
||||
mosaic_sharpen_pixel(api, canvas, mosaic_temp, x, y);
|
||||
|
||||
for (y = 0; y < canvas->h; y++)
|
||||
{
|
||||
for (x = 0; x < canvas->w; x++)
|
||||
{
|
||||
mosaic_sharpen_pixel(api, canvas, mosaic_temp, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
SDL_FreeSurface(mosaic_temp);
|
||||
}
|
||||
|
||||
/* Paint the brush, noise is yet done at switchin,
|
||||
blurs 2 pixels around the brush in order to get sharpen well done.*/
|
||||
void mosaic_paint(void * ptr_to_api, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x, int y)
|
||||
void mosaic_paint(void *ptr_to_api, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
|
||||
{
|
||||
int i, j, pix_row_pos;
|
||||
|
||||
magic_api * api = (magic_api *) ptr_to_api;
|
||||
magic_api *api = (magic_api *) ptr_to_api;
|
||||
|
||||
for (j = max(0, y - mosaic_RADIUS - 2); j < min(canvas->h, y + mosaic_RADIUS + 2); j++)
|
||||
{
|
||||
pix_row_pos = j * canvas->w;
|
||||
for (i = max(0, x - mosaic_RADIUS - 2); i < min(canvas->w, x + mosaic_RADIUS + 2); i++)
|
||||
if( !mosaic_blured[pix_row_pos + i] &&
|
||||
api->in_circle(i - x,j - y, mosaic_RADIUS + 2))
|
||||
{
|
||||
mosaic_blur_pixel(api, canvas_blur, canvas_noise, i, j);
|
||||
mosaic_blured[pix_row_pos + i] = 1; /* Track what are yet blured */
|
||||
}
|
||||
if (!mosaic_blured[pix_row_pos + i] && api->in_circle(i - x, j - y, mosaic_RADIUS + 2))
|
||||
{
|
||||
mosaic_blur_pixel(api, canvas_blur, canvas_noise, i, j);
|
||||
mosaic_blured[pix_row_pos + i] = 1; /* Track what are yet blured */
|
||||
}
|
||||
}
|
||||
|
||||
for (i = x - mosaic_RADIUS; i < x + mosaic_RADIUS; i++)
|
||||
for (j=y - mosaic_RADIUS; j < y + mosaic_RADIUS; j++)
|
||||
for (i = x - mosaic_RADIUS; i < x + mosaic_RADIUS; i++)
|
||||
for (j = y - mosaic_RADIUS; j < y + mosaic_RADIUS; j++)
|
||||
if (api->in_circle(i - x, j - y, mosaic_RADIUS))
|
||||
if( !api->touched(i, j))
|
||||
{
|
||||
mosaic_sharpen_pixel(api, canvas_sharp, canvas_blur, i, j);
|
||||
api->putpixel(canvas, i, j, api->getpixel(canvas_sharp, i, j));
|
||||
}
|
||||
if (!api->touched(i, j))
|
||||
{
|
||||
mosaic_sharpen_pixel(api, canvas_sharp, canvas_blur, i, j);
|
||||
api->putpixel(canvas, i, j, api->getpixel(canvas_sharp, i, j));
|
||||
}
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
|
|
@ -246,7 +253,7 @@ void mosaic_click(magic_api * api, int which, int mode,
|
|||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
|
||||
do_mosaic_full(api, canvas_noise, last, which);
|
||||
do_mosaic_full(api, canvas_noise, last, which);
|
||||
SDL_BlitSurface(canvas_noise, NULL, canvas, NULL);
|
||||
api->playsound(mosaic_snd_effect[which], 128, 255);
|
||||
}
|
||||
|
|
@ -256,195 +263,200 @@ void mosaic_click(magic_api * api, int which, int mode,
|
|||
}
|
||||
|
||||
// Affect the canvas on release:
|
||||
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)
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
// No setup happened:
|
||||
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){
|
||||
Mix_FreeChunk(mosaic_snd_effect[i]);
|
||||
}
|
||||
}
|
||||
//Clean up sounds
|
||||
int i;
|
||||
|
||||
for (i = 0; i < mosaic_NUM_TOOLS; i++)
|
||||
{
|
||||
if (mosaic_snd_effect[i] != NULL)
|
||||
{
|
||||
Mix_FreeChunk(mosaic_snd_effect[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Record the color from Tux Paint:
|
||||
void mosaic_set_color(magic_api * api ATTRIBUTE_UNUSED,
|
||||
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
|
||||
Uint8 b ATTRIBUTE_UNUSED)
|
||||
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
// Use colors:
|
||||
int mosaic_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
|
||||
int which ATTRIBUTE_UNUSED)
|
||||
int mosaic_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//Add noise to a pixel
|
||||
static void mosaic_noise_pixel(void * ptr, SDL_Surface * canvas, int noise_AMOUNT, int x, int y){
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
static void mosaic_noise_pixel(void *ptr, SDL_Surface * canvas, int noise_AMOUNT, int x, int y)
|
||||
{
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
|
||||
Uint8 temp[3];
|
||||
double temp2[3];
|
||||
int k;
|
||||
|
||||
SDL_GetRGB(api->getpixel(canvas,x, y), canvas->format, &temp[0], &temp[1], &temp[2]);
|
||||
for (k =0;k<3;k++){
|
||||
temp2[k] = clamp(0.0, (int)temp[k] - (rand()%noise_AMOUNT) + noise_AMOUNT/2.0, 255.0);
|
||||
}
|
||||
SDL_GetRGB(api->getpixel(canvas, x, y), canvas->format, &temp[0], &temp[1], &temp[2]);
|
||||
for (k = 0; k < 3; k++)
|
||||
{
|
||||
temp2[k] = clamp(0.0, (int)temp[k] - (rand() % noise_AMOUNT) + noise_AMOUNT / 2.0, 255.0);
|
||||
}
|
||||
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, temp2[0], temp2[1], temp2[2]));
|
||||
}
|
||||
|
||||
//Blur a pixel
|
||||
static void mosaic_blur_pixel(void * ptr, SDL_Surface * canvas, SDL_Surface * last, int x, int y){
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
int i,j,k;
|
||||
Uint8 temp[3];
|
||||
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}};
|
||||
const int weight[5][5] = { {1, 4, 7, 4, 1},
|
||||
{4, 16, 26, 16, 4},
|
||||
{7, 26, 41, 26, 7},
|
||||
{4, 16, 26, 16, 4},
|
||||
{1, 4, 7, 4, 1}
|
||||
};
|
||||
|
||||
for (k =0;k<3;k++){
|
||||
blurValue[k] = 0;
|
||||
}
|
||||
|
||||
for (i=-2;i<3;i++){
|
||||
for (j=-2;j<3;j++){
|
||||
//Add the pixels around the current one wieghted
|
||||
SDL_GetRGB(api->getpixel(last, x + i, y + j), last->format, &temp[0], &temp[1], &temp[2]);
|
||||
for (k =0;k<3;k++){
|
||||
blurValue[k] += temp[k]* weight[i+2][j+2];
|
||||
}
|
||||
for (k = 0; k < 3; k++)
|
||||
{
|
||||
blurValue[k] = 0;
|
||||
}
|
||||
}
|
||||
for (k =0;k<3;k++){
|
||||
blurValue[k] /= 273;
|
||||
}
|
||||
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, blurValue[0], blurValue[1], blurValue[2]));
|
||||
|
||||
for (i = -2; i < 3; i++)
|
||||
{
|
||||
for (j = -2; j < 3; j++)
|
||||
{
|
||||
//Add the pixels around the current one wieghted
|
||||
SDL_GetRGB(api->getpixel(last, x + i, y + j), last->format, &temp[0], &temp[1], &temp[2]);
|
||||
for (k = 0; k < 3; k++)
|
||||
{
|
||||
blurValue[k] += temp[k] * weight[i + 2][j + 2];
|
||||
}
|
||||
}
|
||||
}
|
||||
for (k = 0; k < 3; k++)
|
||||
{
|
||||
blurValue[k] /= 273;
|
||||
}
|
||||
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, blurValue[0], blurValue[1], blurValue[2]));
|
||||
}
|
||||
|
||||
//Sharpen a pixel
|
||||
static void mosaic_sharpen_pixel(void * ptr,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y){
|
||||
static void mosaic_sharpen_pixel(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
|
||||
{
|
||||
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
|
||||
Uint8 r1, g1, b1;
|
||||
int grey;
|
||||
int i,j;
|
||||
double sobel_1=0,sobel_2=0;
|
||||
double temp;
|
||||
Uint8 r1, g1, b1;
|
||||
int grey;
|
||||
int i, j;
|
||||
double sobel_1 = 0, sobel_2 = 0;
|
||||
double temp;
|
||||
|
||||
//Sobel weighting masks
|
||||
const int sobel_weights_1[3][3] = { {1,2,1},
|
||||
{0,0,0},
|
||||
{-1,-2,-1}};
|
||||
const int sobel_weights_2[3][3] = { {-1,0,1},
|
||||
{-2,0,2},
|
||||
{-1,0,1}};
|
||||
//Sobel weighting masks
|
||||
const int sobel_weights_1[3][3] = { {1, 2, 1},
|
||||
{0, 0, 0},
|
||||
{-1, -2, -1}
|
||||
};
|
||||
const int sobel_weights_2[3][3] = { {-1, 0, 1},
|
||||
{-2, 0, 2},
|
||||
{-1, 0, 1}
|
||||
};
|
||||
|
||||
sobel_1=0;
|
||||
sobel_2=0;
|
||||
for (i=-1;i<2;i++){
|
||||
for(j=-1; j<2; j++){
|
||||
//No need to check if inside canvas, getpixel does it for us.
|
||||
SDL_GetRGB(api->getpixel(last, x+i, y+j), last->format, &r1, &g1, &b1);
|
||||
grey = mosaic_grey(r1,g1,b1);
|
||||
sobel_1 += grey * sobel_weights_1[i+1][j+1];
|
||||
sobel_2 += grey * sobel_weights_2[i+1][j+1];
|
||||
}
|
||||
}
|
||||
|
||||
temp = sqrt(sobel_1*sobel_1 + sobel_2*sobel_2);
|
||||
temp = (temp/1443)*255.0;
|
||||
sobel_1 = 0;
|
||||
sobel_2 = 0;
|
||||
for (i = -1; i < 2; i++)
|
||||
{
|
||||
for (j = -1; j < 2; j++)
|
||||
{
|
||||
//No need to check if inside canvas, getpixel does it for us.
|
||||
SDL_GetRGB(api->getpixel(last, x + i, y + j), last->format, &r1, &g1, &b1);
|
||||
grey = mosaic_grey(r1, g1, b1);
|
||||
sobel_1 += grey * sobel_weights_1[i + 1][j + 1];
|
||||
sobel_2 += grey * sobel_weights_2[i + 1][j + 1];
|
||||
}
|
||||
}
|
||||
|
||||
temp = sqrt(sobel_1 * sobel_1 + sobel_2 * sobel_2);
|
||||
temp = (temp / 1443) * 255.0;
|
||||
|
||||
SDL_GetRGB(api->getpixel(last, x, y), last->format, &r1, &g1, &b1);
|
||||
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, clamp(0.0, r1 + mosaic_SHARPEN * temp, 255.0),
|
||||
clamp(0.0, g1 + mosaic_SHARPEN * temp, 255.0),
|
||||
clamp(0.0, b1 + mosaic_SHARPEN * temp, 255.0)));
|
||||
|
||||
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, clamp(0.0, r1 + mosaic_SHARPEN * temp, 255.0),
|
||||
clamp(0.0, g1 + mosaic_SHARPEN * temp, 255.0),
|
||||
clamp(0.0, b1 + mosaic_SHARPEN * temp, 255.0)));
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
mosaic_blured = (Uint8 *) malloc(sizeof(Uint8) * (canvas->w * canvas->h));
|
||||
if (mosaic_blured == NULL)
|
||||
{
|
||||
fprintf(stderr, "\nError: Can't build drawing touch mask!\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
SDL_BlitSurface(canvas, NULL, canvas_noise, NULL);
|
||||
|
||||
for (y = 0; y < canvas->h; y++){
|
||||
for (x=0; x < canvas->w; x++){
|
||||
mosaic_noise_pixel(api, canvas_noise, mosaic_AMOUNT, x, y);
|
||||
{
|
||||
fprintf(stderr, "\nError: Can't build drawing touch mask!\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
canvas_blur = SDL_CreateRGBSurface(SDL_SWSURFACE,
|
||||
canvas->w,
|
||||
canvas->h,
|
||||
canvas->format->BitsPerPixel,
|
||||
canvas->format->Rmask,
|
||||
canvas->format->Gmask,
|
||||
canvas->format->Bmask, amask);
|
||||
amask = ~(canvas->format->Rmask | canvas->format->Gmask | canvas->format->Bmask);
|
||||
|
||||
canvas_sharp = SDL_CreateRGBSurface(SDL_SWSURFACE,
|
||||
canvas->w,
|
||||
canvas->h,
|
||||
canvas->format->BitsPerPixel,
|
||||
canvas->format->Rmask,
|
||||
canvas->format->Gmask,
|
||||
canvas->format->Bmask, amask);
|
||||
reset_mosaic_blured(canvas);
|
||||
canvas_noise = SDL_CreateRGBSurface(SDL_SWSURFACE,
|
||||
canvas->w,
|
||||
canvas->h,
|
||||
canvas->format->BitsPerPixel,
|
||||
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++)
|
||||
{
|
||||
mosaic_noise_pixel(api, canvas_noise, mosaic_AMOUNT, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
canvas_blur = SDL_CreateRGBSurface(SDL_SWSURFACE,
|
||||
canvas->w,
|
||||
canvas->h,
|
||||
canvas->format->BitsPerPixel,
|
||||
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);
|
||||
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)
|
||||
void mosaic_switchout(magic_api * api ATTRIBUTE_UNUSED,
|
||||
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
SDL_FreeSurface(canvas_noise);
|
||||
SDL_FreeSurface(canvas_blur);
|
||||
SDL_FreeSurface(canvas_sharp);
|
||||
free (mosaic_blured);
|
||||
free(mosaic_blured);
|
||||
}
|
||||
|
||||
int mosaic_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_PAINT|MODE_FULLSCREEN);
|
||||
return (MODE_PAINT | MODE_FULLSCREEN);
|
||||
}
|
||||
|
||||
void reset_mosaic_blured(SDL_Surface * canvas)
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -33,27 +33,22 @@
|
|||
#include "SDL_image.h"
|
||||
#include "SDL_mixer.h"
|
||||
|
||||
static Mix_Chunk * negative_snd;
|
||||
static Mix_Chunk *negative_snd;
|
||||
|
||||
int negative_init(magic_api * api);
|
||||
Uint32 negative_api_version(void);
|
||||
int negative_get_tool_count(magic_api * api);
|
||||
SDL_Surface * negative_get_icon(magic_api * api, int which);
|
||||
char * negative_get_name(magic_api * api, int which);
|
||||
char * negative_get_description(magic_api * api, int which, int mode);
|
||||
static void do_negative(void * ptr, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y);
|
||||
SDL_Surface *negative_get_icon(magic_api * api, int which);
|
||||
char *negative_get_name(magic_api * api, int which);
|
||||
char *negative_get_description(magic_api * api, int which, int mode);
|
||||
static void do_negative(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||
void negative_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
|
||||
void negative_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void negative_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void negative_shutdown(magic_api * api);
|
||||
void negative_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
int negative_requires_colors(magic_api * api, int which);
|
||||
|
|
@ -66,90 +61,98 @@ int negative_init(magic_api * api)
|
|||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/negative.wav",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/negative.wav", api->data_directory);
|
||||
|
||||
negative_snd = Mix_LoadWAV(fname);
|
||||
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
Uint32 negative_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
Uint32 negative_api_version(void)
|
||||
{
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
// Only one tool:
|
||||
int negative_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
// Load our icon:
|
||||
SDL_Surface * negative_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
SDL_Surface *negative_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/negative.png",
|
||||
api->data_directory);
|
||||
return(IMG_Load(fname));
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/negative.png", api->data_directory);
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our name, localized:
|
||||
char * negative_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
char *negative_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(strdup(gettext_noop("Negative")));
|
||||
return (strdup(gettext_noop("Negative")));
|
||||
}
|
||||
|
||||
// Return our description, localized:
|
||||
char * negative_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode)
|
||||
char *negative_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode)
|
||||
{
|
||||
if (mode == MODE_PAINT)
|
||||
return(strdup(
|
||||
gettext_noop("Click and drag the mouse around to make your painting negative."))); /* Does this make more sense? */
|
||||
return (strdup(gettext_noop("Click and drag the mouse around to make your painting negative."))); /* Does this make more sense? */
|
||||
else if (mode == MODE_FULLSCREEN)
|
||||
return(strdup(
|
||||
gettext_noop("Click to turn your painting into its negative.")));
|
||||
return (strdup(gettext_noop("Click to turn your painting into its negative.")));
|
||||
else
|
||||
return(NULL);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
// Callback that does the negative color effect on a circle centered around x,y
|
||||
static void do_negative(void * ptr, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y)
|
||||
static void do_negative(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
|
||||
{
|
||||
int xx, yy;
|
||||
Uint8 r, g, b;
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
|
||||
for (yy = y - 16; yy < y + 16; yy++)
|
||||
{
|
||||
for (xx = x - 16; xx < x + 16; xx++)
|
||||
{
|
||||
if (api->in_circle(xx - x, yy - y, 16))
|
||||
{
|
||||
SDL_GetRGB(api->getpixel(last, xx, yy), last->format, &r, &g, &b);
|
||||
for (xx = x - 16; xx < x + 16; xx++)
|
||||
{
|
||||
if (api->in_circle(xx - x, yy - y, 16))
|
||||
{
|
||||
SDL_GetRGB(api->getpixel(last, xx, yy), last->format, &r, &g, &b);
|
||||
|
||||
r = 0xFF - r;
|
||||
g = 0xFF - g;
|
||||
b = 0xFF - b;
|
||||
r = 0xFF - r;
|
||||
g = 0xFF - g;
|
||||
b = 0xFF - b;
|
||||
|
||||
api->putpixel(canvas, xx, yy, SDL_MapRGB(canvas->format, r, g, b));
|
||||
}
|
||||
api->putpixel(canvas, xx, yy, SDL_MapRGB(canvas->format, r, g, b));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Ask Tux Paint to call our 'do_negative()' callback over a line
|
||||
void negative_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
SDL_LockSurface(last);
|
||||
SDL_LockSurface(canvas);
|
||||
|
||||
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_negative);
|
||||
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_negative);
|
||||
|
||||
if (ox > x) { int tmp = ox; ox = x; x = tmp; }
|
||||
if (oy > y) { int tmp = oy; oy = y; y = tmp; }
|
||||
if (ox > x)
|
||||
{
|
||||
int tmp = ox;
|
||||
|
||||
ox = x;
|
||||
x = tmp;
|
||||
}
|
||||
if (oy > y)
|
||||
{
|
||||
int tmp = oy;
|
||||
|
||||
oy = y;
|
||||
y = tmp;
|
||||
}
|
||||
|
||||
update_rect->x = ox - 16;
|
||||
update_rect->y = oy - 16;
|
||||
|
|
@ -165,41 +168,40 @@ 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);
|
||||
else
|
||||
{
|
||||
int xx, yy;
|
||||
Uint8 r, g, b;
|
||||
|
||||
for (yy = 0; yy < canvas->h; yy++)
|
||||
{
|
||||
for (xx = 0; xx < canvas->w; xx++)
|
||||
{
|
||||
SDL_GetRGB(api->getpixel(last, xx, yy), last->format, &r, &g, &b);
|
||||
int xx, yy;
|
||||
Uint8 r, g, b;
|
||||
|
||||
r = 0xFF - r;
|
||||
g = 0xFF - g;
|
||||
b = 0xFF - b;
|
||||
for (yy = 0; yy < canvas->h; yy++)
|
||||
{
|
||||
for (xx = 0; xx < canvas->w; xx++)
|
||||
{
|
||||
SDL_GetRGB(api->getpixel(last, xx, yy), last->format, &r, &g, &b);
|
||||
|
||||
api->putpixel(canvas, xx, yy, SDL_MapRGB(canvas->format, r, g, b));
|
||||
}
|
||||
r = 0xFF - r;
|
||||
g = 0xFF - g;
|
||||
b = 0xFF - b;
|
||||
|
||||
api->putpixel(canvas, xx, yy, SDL_MapRGB(canvas->format, r, g, b));
|
||||
}
|
||||
}
|
||||
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
}
|
||||
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void negative_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)
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -211,7 +213,8 @@ void negative_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
|||
}
|
||||
|
||||
// We don't use colors
|
||||
void negative_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
|
||||
void negative_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
|
||||
Uint8 b ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -221,15 +224,17 @@ int negative_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBU
|
|||
return 0;
|
||||
}
|
||||
|
||||
void negative_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void negative_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void negative_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void negative_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
int negative_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_PAINT | MODE_FULLSCREEN);
|
||||
return (MODE_PAINT | MODE_FULLSCREEN);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,46 +46,45 @@
|
|||
static const int noise_AMOUNT = 100.0;
|
||||
static const int noise_RADIUS = 16;
|
||||
|
||||
enum {
|
||||
TOOL_NOISE,
|
||||
noise_NUM_TOOLS
|
||||
enum
|
||||
{
|
||||
TOOL_NOISE,
|
||||
noise_NUM_TOOLS
|
||||
};
|
||||
|
||||
static Mix_Chunk * noise_snd_effect[noise_NUM_TOOLS];
|
||||
static Mix_Chunk *noise_snd_effect[noise_NUM_TOOLS];
|
||||
|
||||
const char * noise_snd_filenames[noise_NUM_TOOLS] = {
|
||||
const char *noise_snd_filenames[noise_NUM_TOOLS] = {
|
||||
"noise.ogg",
|
||||
};
|
||||
const char * noise_icon_filenames[noise_NUM_TOOLS] = {
|
||||
|
||||
const char *noise_icon_filenames[noise_NUM_TOOLS] = {
|
||||
"noise.png",
|
||||
};
|
||||
const char * noise_names[noise_NUM_TOOLS] = {
|
||||
|
||||
const char *noise_names[noise_NUM_TOOLS] = {
|
||||
gettext_noop("Noise"),
|
||||
};
|
||||
const char * noise_descs[noise_NUM_TOOLS][2] = {
|
||||
|
||||
const char *noise_descs[noise_NUM_TOOLS][2] = {
|
||||
{gettext_noop("Click and drag the mouse to add noise to parts of your picture."),
|
||||
gettext_noop("Click to add noise to your entire picture."),},
|
||||
gettext_noop("Click to add noise to your entire picture."),},
|
||||
};
|
||||
|
||||
Uint32 noise_api_version(void);
|
||||
int noise_init(magic_api * api);
|
||||
SDL_Surface * noise_get_icon(magic_api * api, int which);
|
||||
char * noise_get_name(magic_api * api, int which);
|
||||
char * noise_get_description(magic_api * api, int which, int mode);
|
||||
static void do_noise_pixel(void * ptr, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y);
|
||||
static void do_noise_full(void * ptr,SDL_Surface * canvas, SDL_Surface * last, int which);
|
||||
static void do_noise_brush(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||
SDL_Surface *noise_get_icon(magic_api * api, int which);
|
||||
char *noise_get_name(magic_api * api, int which);
|
||||
char *noise_get_description(magic_api * api, int which, int mode);
|
||||
static void do_noise_pixel(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||
static void do_noise_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int which);
|
||||
static void do_noise_brush(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||
void noise_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
void noise_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void noise_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void noise_shutdown(magic_api * api);
|
||||
void noise_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
int noise_requires_colors(magic_api * api, int which);
|
||||
|
|
@ -94,101 +93,127 @@ 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++){
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/%s", api->data_directory, noise_snd_filenames[i]);
|
||||
noise_snd_effect[i] = Mix_LoadWAV(fname);
|
||||
}
|
||||
return(1);
|
||||
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){
|
||||
return(noise_NUM_TOOLS);
|
||||
int noise_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return (noise_NUM_TOOLS);
|
||||
}
|
||||
|
||||
// Load our icons:
|
||||
SDL_Surface * noise_get_icon(magic_api * api, int which){
|
||||
SDL_Surface *noise_get_icon(magic_api * api, int which)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, noise_icon_filenames[which]);
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our names, localized:
|
||||
char * noise_get_name(magic_api * api ATTRIBUTE_UNUSED, int which){
|
||||
return(strdup(gettext_noop(noise_names[which])));
|
||||
char *noise_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
|
||||
{
|
||||
return (strdup(gettext_noop(noise_names[which])));
|
||||
}
|
||||
|
||||
// Return our descriptions, localized:
|
||||
char * noise_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode){
|
||||
return(strdup(gettext_noop(noise_descs[which][mode-1])));
|
||||
char *noise_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode)
|
||||
{
|
||||
return (strdup(gettext_noop(noise_descs[which][mode - 1])));
|
||||
}
|
||||
|
||||
//Do the effect for one pixel
|
||||
static void do_noise_pixel(void * ptr, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x, int y){
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
static void do_noise_pixel(void *ptr, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
|
||||
{
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
|
||||
Uint8 temp[3];
|
||||
double temp2[3];
|
||||
int k;
|
||||
|
||||
SDL_GetRGB(api->getpixel(canvas,x, y), canvas->format, &temp[0], &temp[1], &temp[2]);
|
||||
for (k =0;k<3;k++){
|
||||
temp2[k] = clamp(0.0, (int)temp[k] - (rand()%noise_AMOUNT) + noise_AMOUNT/2.0, 255.0);
|
||||
}
|
||||
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, temp2[0], temp2[1], temp2[2]));
|
||||
SDL_GetRGB(api->getpixel(canvas, x, y), canvas->format, &temp[0], &temp[1], &temp[2]);
|
||||
for (k = 0; k < 3; k++)
|
||||
{
|
||||
temp2[k] = clamp(0.0, (int)temp[k] - (rand() % noise_AMOUNT) + noise_AMOUNT / 2.0, 255.0);
|
||||
}
|
||||
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, temp2[0], temp2[1], temp2[2]));
|
||||
|
||||
}
|
||||
|
||||
// Do the effect for the full image
|
||||
static void do_noise_full(void * ptr,SDL_Surface * canvas, SDL_Surface * last, int which){
|
||||
int x,y;
|
||||
static void do_noise_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int which)
|
||||
{
|
||||
int x, y;
|
||||
|
||||
for (y = 0; y < last->h; y++){
|
||||
for (x=0; x < last->w; x++){
|
||||
do_noise_pixel(ptr, which, canvas, last, x, y);
|
||||
}
|
||||
}
|
||||
for (y = 0; y < last->h; y++)
|
||||
{
|
||||
for (x = 0; x < last->w; x++)
|
||||
{
|
||||
do_noise_pixel(ptr, which, canvas, last, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//do the effect for the brush
|
||||
static void do_noise_brush(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y){
|
||||
static void do_noise_brush(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
|
||||
{
|
||||
int xx, yy;
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
|
||||
for (yy = y - noise_RADIUS; yy < y + noise_RADIUS; yy++)
|
||||
{
|
||||
for (xx = x - noise_RADIUS; xx < x + noise_RADIUS; xx++)
|
||||
{
|
||||
if (api->in_circle(xx - x, yy - y, noise_RADIUS) &&
|
||||
!api->touched(xx, yy))
|
||||
{
|
||||
do_noise_pixel(api, which, canvas, last, xx, yy);
|
||||
}
|
||||
for (xx = x - noise_RADIUS; xx < x + noise_RADIUS; xx++)
|
||||
{
|
||||
if (api->in_circle(xx - x, yy - y, noise_RADIUS) && !api->touched(xx, yy))
|
||||
{
|
||||
do_noise_pixel(api, which, canvas, last, xx, yy);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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){
|
||||
|
||||
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_noise_brush);
|
||||
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,41 +223,46 @@ 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{
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
do_noise_full(api, canvas, last, which);
|
||||
api->playsound(noise_snd_effect[which], 128, 255);
|
||||
}
|
||||
else
|
||||
{
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
do_noise_full(api, canvas, last, which);
|
||||
api->playsound(noise_snd_effect[which], 128, 255);
|
||||
}
|
||||
}
|
||||
|
||||
// Affect the canvas on release:
|
||||
void noise_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)
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
// No setup happened:
|
||||
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){
|
||||
Mix_FreeChunk(noise_snd_effect[i]);
|
||||
}
|
||||
}
|
||||
//Clean up sounds
|
||||
int i;
|
||||
|
||||
for (i = 0; i < noise_NUM_TOOLS; i++)
|
||||
{
|
||||
if (noise_snd_effect[i] != NULL)
|
||||
{
|
||||
Mix_FreeChunk(noise_snd_effect[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Record the color from Tux Paint:
|
||||
void noise_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
|
||||
void noise_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
|
||||
Uint8 b ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -242,16 +272,17 @@ int noise_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_
|
|||
return 0;
|
||||
}
|
||||
|
||||
void noise_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void noise_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void noise_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void noise_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
int noise_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_FULLSCREEN|MODE_PAINT);
|
||||
return (MODE_FULLSCREEN | MODE_PAINT);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,27 +47,24 @@
|
|||
#endif
|
||||
|
||||
static void perspective_preview(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect, float step);
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect, float step);
|
||||
Uint32 perspective_api_version(void);
|
||||
int perspective_init(magic_api * api);
|
||||
int perspective_get_tool_count(magic_api * api);
|
||||
SDL_Surface * perspective_get_icon(magic_api * api, int which);
|
||||
char * perspective_get_name(magic_api * api, int which);
|
||||
SDL_Surface *perspective_get_icon(magic_api * api, int which);
|
||||
char *perspective_get_name(magic_api * api, int which);
|
||||
|
||||
char * perspective_get_description(magic_api * api, int which, int mode);
|
||||
char *perspective_get_description(magic_api * api, int which, int mode);
|
||||
|
||||
void perspective_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
|
||||
void perspective_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
|
||||
void perspective_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
|
||||
void perspective_shutdown(magic_api * api);
|
||||
|
||||
|
|
@ -81,14 +78,15 @@ void perspective_switchout(magic_api * api, int which, int mode, SDL_Surface * c
|
|||
|
||||
int perspective_modes(magic_api * api, int which);
|
||||
|
||||
int scan_fill(magic_api * api, SDL_Surface * canvas, SDL_Surface * srfc,int x,int y, int fill_edge, int fill_tile, int size, Uint32 color);
|
||||
int scan_fill(magic_api * api, SDL_Surface * canvas, SDL_Surface * srfc, int x, int y, int fill_edge, int fill_tile,
|
||||
int size, Uint32 color);
|
||||
|
||||
void perspective_line(void * ptr_to_api, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
|
||||
void perspective_line(void *ptr_to_api, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
|
||||
|
||||
|
||||
|
||||
|
||||
static const int perspective_AMOUNT= 300;
|
||||
static const int perspective_AMOUNT = 300;
|
||||
static const int perspective_RADIUS = 16;
|
||||
static const double perspective_SHARPEN = 1.0;
|
||||
Uint8 perspective_r, perspective_g, perspective_b;
|
||||
|
|
@ -111,13 +109,15 @@ float top_advc_x, right_advc_x, bottom_advc_x, left_advc_x;
|
|||
float top_advc_y, right_advc_y, bottom_advc_y, left_advc_y;
|
||||
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
TOOL_PERSPECTIVE,
|
||||
TOOL_ZOOM,
|
||||
perspective_NUM_TOOLS
|
||||
};
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
TOP_LEFT,
|
||||
TOP_RIGHT,
|
||||
BOTTOM_RIGHT,
|
||||
|
|
@ -126,168 +126,181 @@ enum {
|
|||
|
||||
|
||||
/* A copy of canvas at switchin, will be used to draw from it as snapshot changes at each click */
|
||||
static SDL_Surface * canvas_back;
|
||||
static SDL_Surface *canvas_back;
|
||||
|
||||
static Mix_Chunk * perspective_snd_effect[perspective_NUM_TOOLS + 1];
|
||||
static Mix_Chunk *perspective_snd_effect[perspective_NUM_TOOLS + 1];
|
||||
|
||||
const char * perspective_snd_filenames[perspective_NUM_TOOLS + 1] = {
|
||||
const char *perspective_snd_filenames[perspective_NUM_TOOLS + 1] = {
|
||||
"perspective.ogg",
|
||||
"zoom_up.ogg",
|
||||
"zoom_down.ogg",
|
||||
};
|
||||
|
||||
const char * perspective_icon_filenames[perspective_NUM_TOOLS] = {
|
||||
const char *perspective_icon_filenames[perspective_NUM_TOOLS] = {
|
||||
"perspective.png",
|
||||
"zoom.png",
|
||||
};
|
||||
|
||||
const char * perspective_names[perspective_NUM_TOOLS] = {
|
||||
const char *perspective_names[perspective_NUM_TOOLS] = {
|
||||
gettext_noop("Perspective"),
|
||||
gettext_noop("Zoom"),
|
||||
|
||||
};
|
||||
|
||||
const char * perspective_descs[perspective_NUM_TOOLS] = {
|
||||
const char *perspective_descs[perspective_NUM_TOOLS] = {
|
||||
gettext_noop("Click on the corners and drag where you want to stretch the picture."),
|
||||
|
||||
|
||||
|
||||
gettext_noop("Click and drag up to zoom in or drag down to zoom out the picture."),
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
Uint32 perspective_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
|
||||
//Load sounds
|
||||
int perspective_init(magic_api * api){
|
||||
int i;
|
||||
char fname[1024];
|
||||
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);
|
||||
Uint32 perspective_api_version(void)
|
||||
{
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
int perspective_get_tool_count(magic_api * api ATTRIBUTE_UNUSED){
|
||||
return(perspective_NUM_TOOLS);
|
||||
//Load sounds
|
||||
int perspective_init(magic_api * api)
|
||||
{
|
||||
int i;
|
||||
char fname[1024];
|
||||
|
||||
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)
|
||||
{
|
||||
return (perspective_NUM_TOOLS);
|
||||
}
|
||||
|
||||
// Load our icons:
|
||||
SDL_Surface * perspective_get_icon(magic_api * api, int which){
|
||||
SDL_Surface *perspective_get_icon(magic_api * api, int which)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, perspective_icon_filenames[which]);
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our names, localized:
|
||||
char * perspective_get_name(magic_api * api ATTRIBUTE_UNUSED, int which){
|
||||
return(strdup(gettext_noop(perspective_names[which])));
|
||||
char *perspective_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
|
||||
{
|
||||
return (strdup(gettext_noop(perspective_names[which])));
|
||||
}
|
||||
|
||||
// Return our descriptions, localized:
|
||||
char * perspective_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED){
|
||||
return(strdup(gettext_noop(perspective_descs[which])));
|
||||
char *perspective_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return (strdup(gettext_noop(perspective_descs[which])));
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Affect the canvas on drag:
|
||||
void perspective_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, int x, int y,
|
||||
SDL_Rect * update_rect){
|
||||
SDL_Surface * last, int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
{
|
||||
switch (which)
|
||||
{
|
||||
case TOOL_PERSPECTIVE:
|
||||
{
|
||||
switch (corner)
|
||||
{
|
||||
case TOP_LEFT:
|
||||
{
|
||||
top_left_x = x;
|
||||
top_left_y = y;
|
||||
}
|
||||
break;
|
||||
switch (corner)
|
||||
{
|
||||
case TOP_LEFT:
|
||||
{
|
||||
top_left_x = x;
|
||||
top_left_y = y;
|
||||
}
|
||||
break;
|
||||
|
||||
case TOP_RIGHT:
|
||||
{
|
||||
top_right_x = x;
|
||||
top_right_y = y;
|
||||
}
|
||||
break;
|
||||
case TOP_RIGHT:
|
||||
{
|
||||
top_right_x = x;
|
||||
top_right_y = y;
|
||||
}
|
||||
break;
|
||||
|
||||
case BOTTOM_LEFT:
|
||||
{
|
||||
bottom_left_x = x;
|
||||
bottom_left_y = y;
|
||||
}
|
||||
break;
|
||||
case BOTTOM_LEFT:
|
||||
{
|
||||
bottom_left_x = x;
|
||||
bottom_left_y = y;
|
||||
}
|
||||
break;
|
||||
|
||||
case BOTTOM_RIGHT:
|
||||
{
|
||||
bottom_right_x = x;
|
||||
bottom_right_y = y;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BOTTOM_RIGHT:
|
||||
{
|
||||
bottom_right_x = x;
|
||||
bottom_right_y = y;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
SDL_BlitSurface(canvas_back, NULL, canvas, NULL);
|
||||
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);
|
||||
/* 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);
|
||||
|
||||
/* 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);
|
||||
/* 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->playsound(perspective_snd_effect[which], (x * 255) / canvas->w, 255);
|
||||
api->playsound(perspective_snd_effect[which], (x * 255) / canvas->w, 255);
|
||||
}
|
||||
break;
|
||||
case TOOL_ZOOM:
|
||||
{
|
||||
int x_distance, y_distance;
|
||||
int x_distance, y_distance;
|
||||
|
||||
update_rect->x = update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
update_rect->x = update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
|
||||
SDL_FillRect(canvas, update_rect, SDL_MapRGB(canvas->format, perspective_r, perspective_g, perspective_b));
|
||||
SDL_FillRect(canvas, update_rect, SDL_MapRGB(canvas->format, perspective_r, perspective_g, perspective_b));
|
||||
|
||||
new_h = max(1, old_h + click_y - y);
|
||||
new_w = canvas->w * new_h / canvas->h;
|
||||
if (new_h >= sound_h)
|
||||
api->playsound(perspective_snd_effect[which], 127, 255);
|
||||
else
|
||||
api->playsound(perspective_snd_effect[which + 1], 127, 255);
|
||||
sound_h = new_h;
|
||||
new_h = max(1, old_h + click_y - y);
|
||||
new_w = canvas->w * new_h / canvas->h;
|
||||
if (new_h >= sound_h)
|
||||
api->playsound(perspective_snd_effect[which], 127, 255);
|
||||
else
|
||||
api->playsound(perspective_snd_effect[which + 1], 127, 255);
|
||||
sound_h = new_h;
|
||||
|
||||
x_distance = (otop_right_x - otop_left_x) * new_w / canvas->w;
|
||||
top_left_x = bottom_left_x = canvas->w / 2 - x_distance / 2;
|
||||
top_right_x = bottom_right_x = canvas->w / 2 + x_distance / 2;
|
||||
x_distance = (otop_right_x - otop_left_x) * new_w / canvas->w;
|
||||
top_left_x = bottom_left_x = canvas->w / 2 - x_distance / 2;
|
||||
top_right_x = bottom_right_x = canvas->w / 2 + x_distance / 2;
|
||||
|
||||
y_distance = (obottom_left_y - otop_left_y) * new_w / canvas->w;
|
||||
top_left_y = top_right_y = canvas->h / 2 - y_distance / 2;
|
||||
bottom_left_y = bottom_right_y = canvas->h / 2 + y_distance / 2;
|
||||
y_distance = (obottom_left_y - otop_left_y) * new_w / canvas->w;
|
||||
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;
|
||||
update_rect->h = canvas->h;
|
||||
update_rect->x = update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -303,43 +316,44 @@ void perspective_drag(magic_api * api, int which, SDL_Surface * canvas,
|
|||
|
||||
// Affect the canvas on click:
|
||||
void perspective_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect){
|
||||
switch(which)
|
||||
{case TOOL_PERSPECTIVE:
|
||||
{
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
switch (which)
|
||||
{
|
||||
case TOOL_PERSPECTIVE:
|
||||
{
|
||||
|
||||
if (x < canvas->w / 2)
|
||||
{
|
||||
if (y < canvas->h / 2)
|
||||
{
|
||||
corner = TOP_LEFT;
|
||||
}
|
||||
else
|
||||
{
|
||||
corner = BOTTOM_LEFT;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (y < canvas->h / 2)
|
||||
{
|
||||
corner = TOP_RIGHT;
|
||||
}
|
||||
else
|
||||
{
|
||||
corner = BOTTOM_RIGHT;
|
||||
}
|
||||
}
|
||||
if (x < canvas->w / 2)
|
||||
{
|
||||
if (y < canvas->h / 2)
|
||||
{
|
||||
corner = TOP_LEFT;
|
||||
}
|
||||
else
|
||||
{
|
||||
corner = BOTTOM_LEFT;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (y < canvas->h / 2)
|
||||
{
|
||||
corner = TOP_RIGHT;
|
||||
}
|
||||
else
|
||||
{
|
||||
corner = BOTTOM_RIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case TOOL_ZOOM:
|
||||
{
|
||||
click_x = x;
|
||||
click_y = y;
|
||||
old_h = new_h;
|
||||
click_x = x;
|
||||
click_y = y;
|
||||
old_h = new_h;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -349,70 +363,67 @@ void perspective_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
|
|||
|
||||
// Affect the canvas on release:
|
||||
void perspective_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect)
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
switch (which)
|
||||
{
|
||||
case TOOL_PERSPECTIVE:{
|
||||
perspective_preview( api, which,
|
||||
canvas , last,
|
||||
x, y , update_rect , 0.5);
|
||||
}
|
||||
case TOOL_PERSPECTIVE:
|
||||
{
|
||||
perspective_preview(api, which, canvas, last, x, y, update_rect, 0.5);
|
||||
}
|
||||
break;
|
||||
|
||||
case TOOL_ZOOM:
|
||||
{
|
||||
SDL_Surface * aux_surf;
|
||||
SDL_Surface * scaled_surf;
|
||||
{
|
||||
SDL_Surface *aux_surf;
|
||||
SDL_Surface *scaled_surf;
|
||||
|
||||
update_rect->x = update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
update_rect->x = update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
|
||||
SDL_FillRect(canvas, update_rect, SDL_MapRGB(canvas->format, perspective_r, perspective_g, perspective_b));
|
||||
SDL_FillRect(canvas, update_rect, SDL_MapRGB(canvas->format, perspective_r, perspective_g, perspective_b));
|
||||
|
||||
|
||||
if(new_h < canvas->h)
|
||||
{
|
||||
scaled_surf = api->scale(canvas_back, new_w, new_h, 0);
|
||||
update_rect->x = (canvas->w - new_w) / 2;
|
||||
update_rect->y = (canvas->h - new_h) / 2;
|
||||
update_rect->w = new_w;
|
||||
update_rect->h = new_h;
|
||||
SDL_BlitSurface(scaled_surf, NULL, canvas, update_rect);
|
||||
}
|
||||
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;
|
||||
aux_y = canvas->h / 2 - aux_h / 2;
|
||||
if (new_h < canvas->h)
|
||||
{
|
||||
scaled_surf = api->scale(canvas_back, new_w, new_h, 0);
|
||||
update_rect->x = (canvas->w - new_w) / 2;
|
||||
update_rect->y = (canvas->h - new_h) / 2;
|
||||
update_rect->w = new_w;
|
||||
update_rect->h = new_h;
|
||||
SDL_BlitSurface(scaled_surf, NULL, canvas, update_rect);
|
||||
}
|
||||
else
|
||||
{
|
||||
int aux_x, aux_y, aux_h, aux_w;
|
||||
|
||||
update_rect->x = canvas->w / 2 - aux_w / 2;
|
||||
update_rect->y = canvas->h / 2 - aux_h / 2;
|
||||
update_rect->w = aux_w;
|
||||
update_rect->h = aux_h;
|
||||
aux_h = canvas->h * canvas->h / new_h;
|
||||
aux_w = canvas->w * aux_h / canvas->h;
|
||||
aux_x = canvas->w / 2 - aux_w / 2;
|
||||
aux_y = canvas->h / 2 - aux_h / 2;
|
||||
|
||||
aux_surf = SDL_CreateRGBSurface(SDL_SWSURFACE,
|
||||
aux_w,
|
||||
aux_h,
|
||||
canvas->format->BitsPerPixel,
|
||||
canvas->format->Rmask,
|
||||
canvas->format->Gmask,
|
||||
canvas->format->Bmask, 0);
|
||||
update_rect->x = canvas->w / 2 - aux_w / 2;
|
||||
update_rect->y = canvas->h / 2 - aux_h / 2;
|
||||
update_rect->w = aux_w;
|
||||
update_rect->h = aux_h;
|
||||
|
||||
SDL_BlitSurface(canvas_back, update_rect, aux_surf, NULL);
|
||||
scaled_surf = api->scale(aux_surf, canvas->w, canvas->h, 0);
|
||||
SDL_BlitSurface(scaled_surf, NULL, canvas, NULL);
|
||||
SDL_FreeSurface(aux_surf);
|
||||
}
|
||||
SDL_FreeSurface(scaled_surf);
|
||||
aux_surf = SDL_CreateRGBSurface(SDL_SWSURFACE,
|
||||
aux_w,
|
||||
aux_h,
|
||||
canvas->format->BitsPerPixel,
|
||||
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, 0);
|
||||
|
||||
update_rect->x = update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
SDL_BlitSurface(canvas_back, update_rect, aux_surf, NULL);
|
||||
scaled_surf = api->scale(aux_surf, canvas->w, canvas->h, 0);
|
||||
SDL_BlitSurface(scaled_surf, NULL, canvas, NULL);
|
||||
SDL_FreeSurface(aux_surf);
|
||||
}
|
||||
SDL_FreeSurface(scaled_surf);
|
||||
|
||||
update_rect->x = update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
|
||||
}
|
||||
break;
|
||||
|
|
@ -420,8 +431,8 @@ void perspective_release(magic_api * api, int which,
|
|||
}
|
||||
|
||||
void perspective_preview(magic_api * api, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect, float step)
|
||||
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect, float step)
|
||||
{
|
||||
float i, j;
|
||||
float ax, ay, bx, by, dx, dy;
|
||||
|
|
@ -437,7 +448,7 @@ void perspective_preview(magic_api * api, int which ATTRIBUTE_UNUSED,
|
|||
|
||||
ox_distance = otop_right_x - otop_left_x;
|
||||
oy_distance = obottom_left_y - otop_left_y;
|
||||
|
||||
|
||||
top_advc_x = (float)(top_right_x - top_left_x) / ox_distance;
|
||||
top_advc_y = (float)(top_right_y - top_left_y) / ox_distance;
|
||||
|
||||
|
|
@ -454,21 +465,21 @@ void perspective_preview(magic_api * api, int which ATTRIBUTE_UNUSED,
|
|||
center_ofset_x = (otop_left_x - top_left_x) * 2;
|
||||
center_ofset_y = (otop_left_y - top_left_y) * 2;
|
||||
|
||||
for(i = 0; i < canvas->w; i += step)
|
||||
for (i = 0; i < canvas->w; i += step)
|
||||
{
|
||||
ax = (float)top_advc_x * i;
|
||||
ay = (float)top_advc_y * i;
|
||||
bx = (float)bottom_advc_x * i + (bottom_left_x - top_left_x) * 2 ;
|
||||
by = (float)bottom_advc_y * i + (bottom_left_y - top_left_y) * 2;
|
||||
ax = (float)top_advc_x *i;
|
||||
ay = (float)top_advc_y *i;
|
||||
bx = (float)bottom_advc_x *i + (bottom_left_x - top_left_x) * 2;
|
||||
by = (float)bottom_advc_y *i + (bottom_left_y - top_left_y) * 2;
|
||||
|
||||
for(j = 0; j < canvas->h; j += step)
|
||||
{
|
||||
dx = (float)(bx - ax) / canvas->h * j;
|
||||
dy = (float)(by - ay)/ canvas->h * j;
|
||||
for (j = 0; j < canvas->h; j += step)
|
||||
{
|
||||
dx = (float)(bx - ax) / canvas->h * j;
|
||||
dy = (float)(by - ay) / canvas->h * j;
|
||||
|
||||
api->putpixel(canvas, ax + dx - center_ofset_x, ay + dy - center_ofset_y, api->getpixel(canvas_back, i, j));
|
||||
}
|
||||
}
|
||||
api->putpixel(canvas, ax + dx - center_ofset_x, ay + dy - center_ofset_y, api->getpixel(canvas_back, i, j));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// No setup happened:
|
||||
|
|
@ -476,11 +487,14 @@ 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){
|
||||
Mix_FreeChunk(perspective_snd_effect[i]);
|
||||
|
||||
for (i = 0; i < perspective_NUM_TOOLS + 1; i++)
|
||||
{
|
||||
if (perspective_snd_effect[i] != NULL)
|
||||
{
|
||||
Mix_FreeChunk(perspective_snd_effect[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Record the color from Tux Paint:
|
||||
|
|
@ -497,9 +511,11 @@ int perspective_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTR
|
|||
return 1;
|
||||
}
|
||||
|
||||
void perspective_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas)
|
||||
void perspective_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas)
|
||||
{
|
||||
Uint32 amask;
|
||||
|
||||
new_w = canvas->w;
|
||||
new_h = canvas->h;
|
||||
|
||||
|
|
@ -513,36 +529,36 @@ void perspective_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_
|
|||
black = SDL_MapRGBA(canvas->format, 0, 0, 0, 0);
|
||||
white = SDL_MapRGBA(canvas->format, 255, 255, 255, 0);
|
||||
|
||||
amask = ~(canvas->format->Rmask |
|
||||
canvas->format->Gmask |
|
||||
canvas->format->Bmask);
|
||||
amask = ~(canvas->format->Rmask | canvas->format->Gmask | canvas->format->Bmask);
|
||||
|
||||
canvas_back = SDL_CreateRGBSurface(SDL_SWSURFACE,
|
||||
canvas->w,
|
||||
canvas->h,
|
||||
canvas->format->BitsPerPixel,
|
||||
canvas->format->Rmask,
|
||||
canvas->format->Gmask,
|
||||
canvas->format->Bmask, amask);
|
||||
canvas->w,
|
||||
canvas->h,
|
||||
canvas->format->BitsPerPixel,
|
||||
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, amask);
|
||||
|
||||
SDL_BlitSurface(canvas, NULL, canvas_back, NULL);
|
||||
}
|
||||
|
||||
void perspective_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void perspective_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
SDL_FreeSurface(canvas_back);
|
||||
}
|
||||
|
||||
int perspective_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_PAINT_WITH_PREVIEW);
|
||||
return (MODE_PAINT_WITH_PREVIEW);
|
||||
}
|
||||
|
||||
void perspective_line(void * ptr_to_api, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
|
||||
void perspective_line(void *ptr_to_api, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
|
||||
SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr_to_api;
|
||||
magic_api *api = (magic_api *) ptr_to_api;
|
||||
|
||||
dash += 1;
|
||||
if (dash > 8) dash = 0;
|
||||
if (dash > 8)
|
||||
dash = 0;
|
||||
if (dash > 3)
|
||||
api->putpixel(canvas, x, y, black);
|
||||
else
|
||||
|
|
|
|||
|
|
@ -27,12 +27,12 @@
|
|||
*/
|
||||
|
||||
|
||||
#include <time.h> //for time()
|
||||
#include <time.h> //for time()
|
||||
#include "tp_magic_api.h"
|
||||
#include "SDL_image.h"
|
||||
#include "SDL_mixer.h"
|
||||
|
||||
#define RATIO 5 //change this value to get bigger puzzle
|
||||
#define RATIO 5 //change this value to get bigger puzzle
|
||||
|
||||
//TODO: Fullscreen mode
|
||||
//In fullscreen mode RATIO _should_ be 1
|
||||
|
|
@ -40,49 +40,48 @@
|
|||
//else not whole the screen will be affected
|
||||
|
||||
|
||||
static Mix_Chunk * puzzle_snd;
|
||||
static int puzzle_gcd=0; //length of side of each rectangle; 0 is temporary value.
|
||||
// static 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;
|
||||
static Mix_Chunk *puzzle_snd;
|
||||
static int puzzle_gcd = 0; //length of side of each rectangle; 0 is temporary value.
|
||||
|
||||
Uint32 puzzle_api_version(void) ;
|
||||
// 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;
|
||||
|
||||
Uint32 puzzle_api_version(void);
|
||||
int puzzle_init(magic_api * api);
|
||||
int puzzle_get_tool_count(magic_api * api);
|
||||
SDL_Surface * puzzle_get_icon(magic_api * api, int which);
|
||||
char * puzzle_get_name(magic_api * api, int which);
|
||||
char * puzzle_get_description(magic_api * api, int which, int mode);
|
||||
SDL_Surface *puzzle_get_icon(magic_api * api, int which);
|
||||
char *puzzle_get_name(magic_api * api, int which);
|
||||
char *puzzle_get_description(magic_api * api, int which, int mode);
|
||||
void puzzle_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void puzzle_shutdown(magic_api * api);
|
||||
void puzzle_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
int puzzle_requires_colors(magic_api * api, int which);
|
||||
void puzzle_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
void puzzle_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
int puzzle_modes(magic_api * api, int which);
|
||||
static void puzzle_draw(void * ptr, int which_tool,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
|
||||
static void puzzle_draw(void *ptr, int which_tool, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
|
||||
void puzzle_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
|
||||
void puzzle_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
int gcd(int a, int b);
|
||||
|
||||
Uint32 puzzle_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
Uint32 puzzle_api_version(void)
|
||||
{
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
int puzzle_init(magic_api * api)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/puzzle.wav",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/puzzle.wav", api->data_directory);
|
||||
puzzle_snd = Mix_LoadWAV(fname);
|
||||
|
||||
return 1 ;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int puzzle_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
|
|
@ -90,32 +89,31 @@ int puzzle_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
|||
return 1;
|
||||
}
|
||||
|
||||
SDL_Surface * puzzle_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
SDL_Surface *puzzle_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/puzzle.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/puzzle.png", api->data_directory);
|
||||
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
char * puzzle_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
char *puzzle_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(strdup(gettext_noop("Puzzle")));
|
||||
return (strdup(gettext_noop("Puzzle")));
|
||||
}
|
||||
|
||||
|
||||
char * puzzle_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode)
|
||||
char *puzzle_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode)
|
||||
{
|
||||
if (mode==MODE_PAINT)
|
||||
return strdup(gettext_noop("Click the part of your picture where would you like a puzzle."));
|
||||
if (mode == MODE_PAINT)
|
||||
return strdup(gettext_noop("Click the part of your picture where would you like a puzzle."));
|
||||
return strdup(gettext_noop("Click to make a puzzle in fullscreen mode."));
|
||||
}
|
||||
|
||||
void puzzle_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)
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -134,21 +133,26 @@ int puzzle_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE
|
|||
return 0;
|
||||
}
|
||||
|
||||
int gcd(int a, int b) //greatest common divisor
|
||||
int gcd(int a, int b) //greatest common divisor
|
||||
{
|
||||
if (b==0) return a;
|
||||
return gcd(b, a%b);
|
||||
if (b == 0)
|
||||
return a;
|
||||
return gcd(b, a % b);
|
||||
}
|
||||
|
||||
void puzzle_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas)
|
||||
void puzzle_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas)
|
||||
{
|
||||
puzzle_gcd=RATIO*gcd(canvas->w, canvas->h);
|
||||
rects_w=(unsigned int)canvas->w/puzzle_gcd;
|
||||
rects_h=(unsigned int)canvas->h/puzzle_gcd;
|
||||
canvas_backup = SDL_CreateRGBSurface(SDL_SWSURFACE,canvas->w, canvas->h, canvas->format->BitsPerPixel, canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
|
||||
puzzle_gcd = RATIO * gcd(canvas->w, canvas->h);
|
||||
rects_w = (unsigned int)canvas->w / puzzle_gcd;
|
||||
rects_h = (unsigned int)canvas->h / puzzle_gcd;
|
||||
canvas_backup =
|
||||
SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h, canvas->format->BitsPerPixel, canvas->format->Rmask,
|
||||
canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
|
||||
}
|
||||
|
||||
void puzzle_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void puzzle_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
SDL_FreeSurface(canvas_backup);
|
||||
canvas_backup = NULL;
|
||||
|
|
@ -156,17 +160,17 @@ void puzzle_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUS
|
|||
|
||||
int puzzle_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_PAINT);
|
||||
return (MODE_PAINT);
|
||||
}
|
||||
|
||||
static void puzzle_draw(void * ptr, int which_tool ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
|
||||
{
|
||||
|
||||
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
|
||||
Uint8 r; //r - random value
|
||||
static void puzzle_draw(void *ptr, int which_tool ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
|
||||
{
|
||||
|
||||
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
|
||||
Uint8 r; //r - random value
|
||||
SDL_Rect rect_this, rect_that;
|
||||
|
||||
SDL_BlitSurface(canvas, NULL, canvas_backup, NULL);
|
||||
|
|
@ -175,70 +179,68 @@ static void puzzle_draw(void * ptr, int which_tool ATTRIBUTE_UNUSED,
|
|||
y = (y / puzzle_gcd) * puzzle_gcd;
|
||||
|
||||
if (!api->touched(x, y))
|
||||
{
|
||||
srand(rand());
|
||||
|
||||
r=rand()%4;
|
||||
|
||||
rect_that.x=x;
|
||||
rect_that.y=y;
|
||||
|
||||
switch(r)
|
||||
{
|
||||
case 0: //upper
|
||||
if (y>puzzle_gcd)
|
||||
rect_that.y=y-puzzle_gcd;
|
||||
|
||||
break;
|
||||
case 1: //right
|
||||
if (x<canvas->w-puzzle_gcd)
|
||||
rect_that.x=x-puzzle_gcd;
|
||||
|
||||
break;
|
||||
case 2: //lower
|
||||
if (y<canvas->h-puzzle_gcd)
|
||||
rect_that.y=y-puzzle_gcd;
|
||||
|
||||
break;
|
||||
case 3: //left
|
||||
if (x>puzzle_gcd)
|
||||
rect_that.x=x-puzzle_gcd;
|
||||
break;
|
||||
}
|
||||
|
||||
rect_this.x=x;
|
||||
rect_this.y=y;
|
||||
rect_this.h=rect_this.w=puzzle_gcd;
|
||||
rect_that.h=rect_that.w=puzzle_gcd;
|
||||
{
|
||||
srand(rand());
|
||||
|
||||
|
||||
SDL_BlitSurface(canvas, &rect_this, canvas, &rect_that);
|
||||
SDL_BlitSurface(canvas_backup, &rect_that, canvas, &rect_this);
|
||||
api->playsound(puzzle_snd, (x * 255) / canvas->w, 255);
|
||||
}
|
||||
r = rand() % 4;
|
||||
|
||||
rect_that.x = x;
|
||||
rect_that.y = y;
|
||||
|
||||
switch (r)
|
||||
{
|
||||
case 0: //upper
|
||||
if (y > puzzle_gcd)
|
||||
rect_that.y = y - puzzle_gcd;
|
||||
|
||||
break;
|
||||
case 1: //right
|
||||
if (x < canvas->w - puzzle_gcd)
|
||||
rect_that.x = x - puzzle_gcd;
|
||||
|
||||
break;
|
||||
case 2: //lower
|
||||
if (y < canvas->h - puzzle_gcd)
|
||||
rect_that.y = y - puzzle_gcd;
|
||||
|
||||
break;
|
||||
case 3: //left
|
||||
if (x > puzzle_gcd)
|
||||
rect_that.x = x - puzzle_gcd;
|
||||
break;
|
||||
}
|
||||
|
||||
rect_this.x = x;
|
||||
rect_this.y = y;
|
||||
rect_this.h = rect_this.w = puzzle_gcd;
|
||||
rect_that.h = rect_that.w = puzzle_gcd;
|
||||
|
||||
|
||||
SDL_BlitSurface(canvas, &rect_this, canvas, &rect_that);
|
||||
SDL_BlitSurface(canvas_backup, &rect_that, canvas, &rect_this);
|
||||
api->playsound(puzzle_snd, (x * 255) / canvas->w, 255);
|
||||
}
|
||||
}
|
||||
|
||||
void puzzle_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
SDL_Surface * last, int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
{
|
||||
puzzle_draw(api, which, canvas, last, x-puzzle_gcd/2, y-puzzle_gcd/2);
|
||||
puzzle_draw(api, which, canvas, last, x - puzzle_gcd / 2, y - puzzle_gcd / 2);
|
||||
|
||||
puzzle_draw(api, which, canvas, last, x-1.5*puzzle_gcd/2, y-puzzle_gcd/2);
|
||||
puzzle_draw(api, which, canvas, last, x+0.5*puzzle_gcd, y-puzzle_gcd/2);
|
||||
puzzle_draw(api, which, canvas, last, x-puzzle_gcd/2, y-1.5*puzzle_gcd);
|
||||
puzzle_draw(api, which, canvas, last, x-puzzle_gcd/2, y+0.5*puzzle_gcd);
|
||||
|
||||
update_rect->x=0;
|
||||
update_rect->y=0;
|
||||
update_rect->h=canvas->h;
|
||||
update_rect->w=canvas->w;
|
||||
puzzle_draw(api, which, canvas, last, x - 1.5 * puzzle_gcd / 2, y - puzzle_gcd / 2);
|
||||
puzzle_draw(api, which, canvas, last, x + 0.5 * puzzle_gcd, y - puzzle_gcd / 2);
|
||||
puzzle_draw(api, which, canvas, last, x - puzzle_gcd / 2, y - 1.5 * puzzle_gcd);
|
||||
puzzle_draw(api, which, canvas, last, x - puzzle_gcd / 2, y + 0.5 * puzzle_gcd);
|
||||
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
update_rect->h = canvas->h;
|
||||
update_rect->w = canvas->w;
|
||||
}
|
||||
|
||||
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);
|
||||
puzzle_drag(api, which, canvas, last, x, y, x, y, update_rect);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,96 +21,94 @@
|
|||
#define SEG_RIGHT_TOP_BOTTOM (SEG_RIGHT | SEG_TOP | SEG_BOTTOM)
|
||||
#define SEG_LEFT_RIGHT_TOP_BOTTOM (SEG_LEFT | SEG_RIGHT | SEG_TOP | SEG_BOTTOM)
|
||||
|
||||
Mix_Chunk * rails_snd;
|
||||
Mix_Chunk *rails_snd;
|
||||
unsigned int img_w, img_h;
|
||||
unsigned int rails_segments_x, rails_segments_y; //how many segments do we have?
|
||||
static int rails_math_ceil(int x, int y); //ceil() in cstdlib returns float and is relative slow, so we'll use our one
|
||||
static Uint8 * rails_status_of_segments; //a place to store an info about bitmap used for selected segment
|
||||
static char ** rails_images; //the pathes to all the images needed
|
||||
static unsigned int rails_segment_modified; //which segment was modified this time?
|
||||
static unsigned int rails_segment_modified_last =0; //which segment was last modified
|
||||
static unsigned int rails_segment_to_add =0; //a segment that should be added to solve corner joints
|
||||
unsigned int rails_segments_x, rails_segments_y; //how many segments do we have?
|
||||
static int rails_math_ceil(int x, int y); //ceil() in cstdlib returns float and is relative slow, so we'll use our one
|
||||
static Uint8 *rails_status_of_segments; //a place to store an info about bitmap used for selected segment
|
||||
static char **rails_images; //the pathes to all the images needed
|
||||
static unsigned int rails_segment_modified; //which segment was modified this time?
|
||||
static unsigned int rails_segment_modified_last = 0; //which segment was last modified
|
||||
static unsigned int rails_segment_to_add = 0; //a segment that should be added to solve corner joints
|
||||
static SDL_Rect modification_rect;
|
||||
static SDL_Surface * canvas_backup;
|
||||
// Housekeeping functions
|
||||
static SDL_Surface *canvas_backup;
|
||||
|
||||
SDL_Surface * rails_one, * rails_three, * rails_four, * rails_corner;
|
||||
// Housekeeping functions
|
||||
|
||||
SDL_Surface *rails_one, *rails_three, *rails_four, *rails_corner;
|
||||
|
||||
Uint32 rails_api_version(void);
|
||||
int rails_modes(magic_api * api, int which);
|
||||
void rails_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
int rails_init(magic_api * api);
|
||||
int rails_get_tool_count(magic_api * api);
|
||||
SDL_Surface * rails_get_icon(magic_api * api, int which);
|
||||
char * rails_get_name(magic_api * api, int which);
|
||||
char * rails_get_description(magic_api * api, int which, int mode);
|
||||
SDL_Surface *rails_get_icon(magic_api * api, int which);
|
||||
char *rails_get_name(magic_api * api, int which);
|
||||
char *rails_get_description(magic_api * api, int which, int mode);
|
||||
int rails_requires_colors(magic_api * api, int which);
|
||||
void rails_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
|
||||
void rails_shutdown(magic_api * api);
|
||||
void rails_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
void rails_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
static int rails_math_ceil(int x, int y);
|
||||
inline unsigned int rails_get_segment(int x, int y);
|
||||
inline unsigned int rails_get_segment(int x, int y);
|
||||
inline void rails_extract_coords_from_segment(unsigned int segment, Sint16 * x, Sint16 * y);
|
||||
static void rails_flip(void * ptr, SDL_Surface * dest, SDL_Surface * src);
|
||||
static void rails_flip_flop(void * ptr, SDL_Surface * dest, SDL_Surface * src);
|
||||
static void rails_rotate (void * ptr, SDL_Surface * dest, SDL_Surface * src, unsigned int direction);
|
||||
static void rails_flip(void *ptr, SDL_Surface * dest, SDL_Surface * src);
|
||||
static void rails_flip_flop(void *ptr, SDL_Surface * dest, SDL_Surface * src);
|
||||
static void rails_rotate(void *ptr, SDL_Surface * dest, SDL_Surface * src, unsigned int direction);
|
||||
void rails_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
|
||||
static Uint8 rails_select_image(Uint16 segment);
|
||||
static void rails_draw(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, unsigned int 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)
|
||||
{
|
||||
return(TP_MAGIC_API_VERSION);
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
int rails_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_PAINT);
|
||||
return (MODE_PAINT);
|
||||
}
|
||||
|
||||
void rails_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
|
||||
void rails_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
|
||||
Uint8 b ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
int rails_init(magic_api * api)
|
||||
{
|
||||
char fname[1024];
|
||||
Uint8 i; //is always < 3, so Uint8 seems to be a good idea
|
||||
|
||||
rails_images=(char **)malloc(sizeof(char *)*4);
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
rails_images[i]=(char *)malloc(sizeof(char)*1024);
|
||||
|
||||
snprintf(rails_images[0], 1024*sizeof(char), "%s/images/magic/rails_one.png", api->data_directory);
|
||||
snprintf(rails_images[1], 1024*sizeof(char), "%s/images/magic/rails_three.png", api->data_directory);
|
||||
snprintf(rails_images[2], 1024*sizeof(char), "%s/images/magic/rails_four.png", api->data_directory);
|
||||
snprintf(rails_images[3], 1024*sizeof(char), "%s/images/magic/rails_corner.png", api->data_directory);
|
||||
char fname[1024];
|
||||
Uint8 i; //is always < 3, so Uint8 seems to be a good idea
|
||||
|
||||
rails_one=IMG_Load(rails_images[0]);
|
||||
rails_three=IMG_Load(rails_images[1]);
|
||||
rails_four=IMG_Load(rails_images[2]);
|
||||
rails_corner=IMG_Load(rails_images[3]);
|
||||
rails_images = (char **)malloc(sizeof(char *) * 4);
|
||||
|
||||
img_w = rails_one->w;
|
||||
img_h = rails_one->h;
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/rails.wav", api->data_directory);
|
||||
rails_snd = Mix_LoadWAV(fname);
|
||||
for (i = 0; i < 4; i++)
|
||||
rails_images[i] = (char *)malloc(sizeof(char) * 1024);
|
||||
|
||||
return(1);
|
||||
snprintf(rails_images[0], 1024 * sizeof(char), "%s/images/magic/rails_one.png", api->data_directory);
|
||||
snprintf(rails_images[1], 1024 * sizeof(char), "%s/images/magic/rails_three.png", api->data_directory);
|
||||
snprintf(rails_images[2], 1024 * sizeof(char), "%s/images/magic/rails_four.png", api->data_directory);
|
||||
snprintf(rails_images[3], 1024 * sizeof(char), "%s/images/magic/rails_corner.png", api->data_directory);
|
||||
|
||||
rails_one = IMG_Load(rails_images[0]);
|
||||
rails_three = IMG_Load(rails_images[1]);
|
||||
rails_four = IMG_Load(rails_images[2]);
|
||||
rails_corner = IMG_Load(rails_images[3]);
|
||||
|
||||
img_w = rails_one->w;
|
||||
img_h = rails_one->h;
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/rails.wav", api->data_directory);
|
||||
rails_snd = Mix_LoadWAV(fname);
|
||||
|
||||
return (1);
|
||||
}
|
||||
|
||||
int rails_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
|
|
@ -118,407 +116,434 @@ int rails_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
|||
return 1;
|
||||
}
|
||||
|
||||
SDL_Surface * rails_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
SDL_Surface *rails_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/rails.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/rails.png", api->data_directory);
|
||||
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
char * rails_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) { return strdup(gettext_noop("Rails")); }
|
||||
char *rails_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return strdup(gettext_noop("Rails"));
|
||||
}
|
||||
|
||||
char * rails_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED) { return strdup(gettext_noop("Click and drag to draw train track rails on your picture.")); }
|
||||
char *rails_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return strdup(gettext_noop("Click and drag to draw train track rails on your picture."));
|
||||
}
|
||||
|
||||
int rails_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) { return 0;}
|
||||
int rails_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void rails_release(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * snapshot ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect 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)
|
||||
{
|
||||
}
|
||||
|
||||
void rails_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
Uint8 i;
|
||||
|
||||
if (rails_snd!=NULL)
|
||||
Mix_FreeChunk(rails_snd);
|
||||
SDL_FreeSurface(rails_one);
|
||||
SDL_FreeSurface(rails_three);
|
||||
SDL_FreeSurface(rails_four);
|
||||
SDL_FreeSurface(rails_corner);
|
||||
SDL_FreeSurface(canvas_backup);
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
free(rails_images[i]);
|
||||
free(rails_images);
|
||||
if (rails_status_of_segments != NULL)
|
||||
free(rails_status_of_segments);
|
||||
Uint8 i;
|
||||
|
||||
if (rails_snd != NULL)
|
||||
Mix_FreeChunk(rails_snd);
|
||||
SDL_FreeSurface(rails_one);
|
||||
SDL_FreeSurface(rails_three);
|
||||
SDL_FreeSurface(rails_four);
|
||||
SDL_FreeSurface(rails_corner);
|
||||
SDL_FreeSurface(canvas_backup);
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
free(rails_images[i]);
|
||||
free(rails_images);
|
||||
if (rails_status_of_segments != NULL)
|
||||
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
|
||||
//we've to compute the quantity of segments in each direction
|
||||
|
||||
canvas_backup=SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h, canvas->format->BitsPerPixel,
|
||||
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
|
||||
canvas_backup = SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h, canvas->format->BitsPerPixel,
|
||||
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask,
|
||||
canvas->format->Amask);
|
||||
|
||||
SDL_BlitSurface(canvas, NULL, canvas_backup, NULL);
|
||||
rails_segments_x=rails_math_ceil(canvas->w,img_w);
|
||||
rails_segments_y=rails_math_ceil(canvas->h,img_h);
|
||||
//status_of_segments[0] will not be used, we write in rails_status_of_segments[1 to segments_x*segments_y]
|
||||
rails_status_of_segments=(Uint8 *)calloc(rails_segments_x*rails_segments_y + 1, sizeof(Uint8));
|
||||
SDL_BlitSurface(canvas, NULL, canvas_backup, NULL);
|
||||
rails_segments_x = rails_math_ceil(canvas->w, img_w);
|
||||
rails_segments_y = rails_math_ceil(canvas->h, img_h);
|
||||
//status_of_segments[0] will not be used, we write in rails_status_of_segments[1 to segments_x*segments_y]
|
||||
rails_status_of_segments = (Uint8 *) calloc(rails_segments_x * rails_segments_y + 1, sizeof(Uint8));
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
free(rails_status_of_segments);
|
||||
rails_status_of_segments = NULL;
|
||||
}
|
||||
if (rails_status_of_segments != NULL)
|
||||
{
|
||||
free(rails_status_of_segments);
|
||||
rails_status_of_segments = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// Interactivity functions
|
||||
|
||||
static int rails_math_ceil(int x, int y)
|
||||
{
|
||||
int temp;
|
||||
temp=(int)x/y;
|
||||
|
||||
if (x%y)
|
||||
return temp+1;
|
||||
else return temp;
|
||||
}
|
||||
|
||||
inline unsigned int rails_get_segment(int x, int y)
|
||||
{
|
||||
int xx; //segments are numerated just like pixels
|
||||
int yy; //in computer graphics: left upper (=1), ... ,right upper,
|
||||
//left bottom, ... , right bottom
|
||||
xx=rails_math_ceil(x, img_w);
|
||||
yy=rails_math_ceil(y, img_h);
|
||||
|
||||
return (yy-1)*rails_segments_x+xx;
|
||||
|
||||
int temp;
|
||||
|
||||
temp = (int)x / y;
|
||||
|
||||
if (x % y)
|
||||
return temp + 1;
|
||||
else
|
||||
return temp;
|
||||
}
|
||||
|
||||
inline unsigned int rails_get_segment(int x, int y)
|
||||
{
|
||||
int xx; //segments are numerated just like pixels
|
||||
int yy; //in computer graphics: left upper (=1), ... ,right upper,
|
||||
|
||||
//left bottom, ... , right bottom
|
||||
xx = rails_math_ceil(x, img_w);
|
||||
yy = rails_math_ceil(y, img_h);
|
||||
|
||||
return (yy - 1) * rails_segments_x + xx;
|
||||
|
||||
}
|
||||
|
||||
inline void rails_extract_coords_from_segment(unsigned int segment, Sint16 * x, Sint16 * y)
|
||||
{ //extracts the coords of the beginning and the segment
|
||||
*x=((segment%rails_segments_x)-1)*img_w; //useful to set update_rect as small as possible
|
||||
*y=(int)(segment/rails_segments_x)*img_h;
|
||||
{ //extracts the coords of the beginning and the segment
|
||||
*x = ((segment % rails_segments_x) - 1) * img_w; //useful to set update_rect as small as possible
|
||||
*y = (int)(segment / rails_segments_x) * img_h;
|
||||
}
|
||||
|
||||
static void rails_flip(void * ptr, SDL_Surface * dest, SDL_Surface * src)
|
||||
static void rails_flip(void *ptr, SDL_Surface * dest, SDL_Surface * src)
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
|
||||
Sint16 x, y;
|
||||
|
||||
for (x=0; x<dest->w; x++)
|
||||
for (y=0; y<dest->h; y++)
|
||||
api->putpixel(dest, x, y, api->getpixel(src, x, src->h-y-1));
|
||||
}
|
||||
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++)
|
||||
|
||||
for (x = 0; x < dest->w; x++)
|
||||
for (y = 0; y < dest->h; y++)
|
||||
api->putpixel(dest, x, y, api->getpixel(src, x, src->h - y - 1));
|
||||
}
|
||||
|
||||
static void rails_flip_flop(void *ptr, SDL_Surface * dest, SDL_Surface * src)
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
static void rails_rotate (void * ptr, SDL_Surface * dest, SDL_Surface * src, unsigned int direction)
|
||||
static void rails_rotate(void *ptr, SDL_Surface * dest, SDL_Surface * src, unsigned int direction)
|
||||
//src and dest must have same size
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
Sint16 x,y;
|
||||
|
||||
if (direction) //rotate -90 degs
|
||||
{
|
||||
for (x = 0; x<dest->w; x++)
|
||||
for (y =0; y<dest->h; y++)
|
||||
api->putpixel(dest, x, y, api->getpixel(src, y, src->w-x-1));
|
||||
}
|
||||
else //rotate +90 degs
|
||||
{
|
||||
for (x=0; x<dest->w; x++)
|
||||
for (y=0; y<dest->h; y++)
|
||||
api->putpixel(dest,x,y,api->getpixel(src,src->h-y-1,x));
|
||||
}
|
||||
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
Sint16 x, y;
|
||||
|
||||
if (direction) //rotate -90 degs
|
||||
{
|
||||
for (x = 0; x < dest->w; x++)
|
||||
for (y = 0; y < dest->h; y++)
|
||||
api->putpixel(dest, x, y, api->getpixel(src, y, src->w - x - 1));
|
||||
}
|
||||
else //rotate +90 degs
|
||||
{
|
||||
for (x = 0; x < dest->w; x++)
|
||||
for (y = 0; y < dest->h; y++)
|
||||
api->putpixel(dest, x, y, api->getpixel(src, src->h - y - 1, x));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
rails_segment_modified_last = 0;
|
||||
rails_drag(api, which, canvas, snapshot, x, y, x, y, update_rect);
|
||||
}
|
||||
|
||||
static Uint8 rails_select_image(Uint16 segment)
|
||||
{
|
||||
int take_up, take_down;
|
||||
int val_up, val_down, val_left, val_right;
|
||||
int from_top=0, from_bottom=0, from_left = 0, from_right = 0;
|
||||
int from_top_right=0, from_top_left=0, from_bottom_right=0, from_bottom_left = 0;
|
||||
int TOP=0, BOTTOM=0, LEFT=0, RIGHT = 0;
|
||||
|
||||
//Checking from were we come...
|
||||
if (rails_segment_modified_last>0)
|
||||
{
|
||||
if (segment == rails_segment_modified_last + 1)
|
||||
from_left = 1;
|
||||
int take_up, take_down;
|
||||
int val_up, val_down, val_left, val_right;
|
||||
int from_top = 0, from_bottom = 0, from_left = 0, from_right = 0;
|
||||
int from_top_right = 0, from_top_left = 0, from_bottom_right = 0, from_bottom_left = 0;
|
||||
int TOP = 0, BOTTOM = 0, LEFT = 0, RIGHT = 0;
|
||||
|
||||
if (segment == rails_segment_modified_last - 1)
|
||||
from_right = 1;
|
||||
//Checking from were we come...
|
||||
if (rails_segment_modified_last > 0)
|
||||
{
|
||||
if (segment == rails_segment_modified_last + 1)
|
||||
from_left = 1;
|
||||
|
||||
if (segment == rails_segment_modified_last - rails_segments_x)
|
||||
from_bottom = 1;
|
||||
if (segment == rails_segment_modified_last - 1)
|
||||
from_right = 1;
|
||||
|
||||
if (segment == rails_segment_modified_last + rails_segments_x)
|
||||
from_top = 1;
|
||||
if (segment == rails_segment_modified_last - rails_segments_x)
|
||||
from_bottom = 1;
|
||||
|
||||
// Segments are joining by the corner
|
||||
// We need to add a new segment to join by side, adding clockwise
|
||||
if (segment == rails_segment_modified_last + rails_segments_x + 1)
|
||||
{
|
||||
from_top_left = 1;
|
||||
rails_segment_to_add = segment - rails_segments_x;
|
||||
}
|
||||
if (segment == rails_segment_modified_last + rails_segments_x)
|
||||
from_top = 1;
|
||||
|
||||
if (segment == rails_segment_modified_last + rails_segments_x - 1)
|
||||
{
|
||||
from_top_right = 1;
|
||||
rails_segment_to_add = segment + 1;
|
||||
}
|
||||
// Segments are joining by the corner
|
||||
// We need to add a new segment to join by side, adding clockwise
|
||||
if (segment == rails_segment_modified_last + rails_segments_x + 1)
|
||||
{
|
||||
from_top_left = 1;
|
||||
rails_segment_to_add = segment - rails_segments_x;
|
||||
}
|
||||
|
||||
if (segment == rails_segment_modified_last - rails_segments_x - 1)
|
||||
{
|
||||
from_bottom_right = 1;
|
||||
rails_segment_to_add = segment + rails_segments_x;
|
||||
}
|
||||
if (segment == rails_segment_modified_last - rails_segments_x + 1)
|
||||
{
|
||||
from_bottom_left = 1;
|
||||
rails_segment_to_add = segment -1;
|
||||
}
|
||||
}
|
||||
if (segment == rails_segment_modified_last + rails_segments_x - 1)
|
||||
{
|
||||
from_top_right = 1;
|
||||
rails_segment_to_add = segment + 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
take_up=segment-rails_segments_x;
|
||||
if (take_up<=0) val_up = SEG_NONE;
|
||||
else val_up = rails_status_of_segments[take_up];
|
||||
|
||||
take_down=segment+rails_segments_x;
|
||||
if (take_down>(signed)(rails_segments_x*rails_segments_y)) val_down = SEG_NONE;
|
||||
else val_down = rails_status_of_segments[take_down];
|
||||
|
||||
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 ( from_left || (val_left & SEG_RIGHT) || from_bottom_left)
|
||||
{
|
||||
LEFT = 1;}
|
||||
if ( from_right || (val_right & SEG_LEFT) || from_top_right)
|
||||
RIGHT=1;
|
||||
if ( from_top || (val_up & SEG_BOTTOM) || from_top_left)
|
||||
TOP=1;
|
||||
if (from_bottom || (val_down & SEG_TOP) || from_bottom_right)
|
||||
BOTTOM=1;
|
||||
|
||||
|
||||
if (TOP && BOTTOM && LEFT && RIGHT)
|
||||
return SEG_LEFT_RIGHT_TOP_BOTTOM;
|
||||
if (LEFT && RIGHT && TOP)
|
||||
return SEG_LEFT_RIGHT_TOP;
|
||||
if (LEFT && RIGHT && BOTTOM)
|
||||
return SEG_LEFT_RIGHT_BOTTOM;
|
||||
if (TOP && BOTTOM && LEFT)
|
||||
return SEG_LEFT_TOP_BOTTOM;
|
||||
if (TOP && BOTTOM && RIGHT)
|
||||
return SEG_RIGHT_TOP_BOTTOM;
|
||||
if (LEFT &&RIGHT)
|
||||
return SEG_LEFT_RIGHT;
|
||||
if (TOP&&BOTTOM)
|
||||
return SEG_TOP_BOTTOM;
|
||||
if (LEFT&&TOP)
|
||||
return SEG_LEFT_TOP;
|
||||
if (LEFT&&BOTTOM)
|
||||
return SEG_LEFT_BOTTOM;
|
||||
if (RIGHT&&TOP)
|
||||
return SEG_RIGHT_TOP;
|
||||
if (RIGHT&&BOTTOM)
|
||||
return SEG_RIGHT_BOTTOM;
|
||||
if (LEFT|RIGHT)
|
||||
return SEG_LEFT_RIGHT;
|
||||
return SEG_TOP_BOTTOM;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
Uint8 image;
|
||||
unsigned int use_temp;
|
||||
|
||||
use_temp=0;
|
||||
if (segment>rails_segments_x*rails_segments_y)
|
||||
return;
|
||||
//modification_rect.x and modification_rect.y are set by function
|
||||
rails_extract_coords_from_segment(segment, &modification_rect.x, &modification_rect.y);
|
||||
modification_rect.h=img_w;
|
||||
modification_rect.w=img_h;
|
||||
|
||||
image=rails_select_image(segment); //select the image to display
|
||||
|
||||
if (rails_status_of_segments[segment] == image)
|
||||
return;
|
||||
|
||||
rails_status_of_segments[segment]=image; //and write it to global table
|
||||
|
||||
|
||||
result=SDL_CreateRGBSurface(SDL_SWSURFACE, img_w, img_h, rails_one->format->BitsPerPixel,
|
||||
rails_one->format->Rmask, rails_one->format->Gmask, rails_one->format->Bmask, rails_one->format->Amask);
|
||||
|
||||
temp=SDL_CreateRGBSurface(SDL_SWSURFACE, img_w, img_h, rails_one->format->BitsPerPixel,
|
||||
rails_one->format->Rmask, rails_one->format->Gmask, rails_one->format->Bmask, rails_one->format->Amask);
|
||||
|
||||
SDL_BlitSurface(canvas_backup, &modification_rect, result, NULL);
|
||||
|
||||
|
||||
switch(image)
|
||||
{
|
||||
case 0:
|
||||
case SEG_TOP_BOTTOM:
|
||||
SDL_BlitSurface(canvas_backup, &modification_rect, result, NULL);
|
||||
SDL_BlitSurface(rails_one, NULL, result, NULL);
|
||||
break;
|
||||
|
||||
case SEG_LEFT_RIGHT:
|
||||
SDL_BlitSurface(canvas_backup, &modification_rect, result, NULL);
|
||||
rails_rotate(api, temp, rails_one, 1);
|
||||
use_temp=1;
|
||||
break;
|
||||
|
||||
case SEG_LEFT_RIGHT_TOP_BOTTOM:
|
||||
SDL_BlitSurface(canvas_backup, &modification_rect, result, NULL);
|
||||
SDL_BlitSurface(rails_four, NULL, result, NULL);
|
||||
break;
|
||||
|
||||
case SEG_LEFT_RIGHT_TOP:
|
||||
SDL_BlitSurface(rails_three, NULL, result, NULL);
|
||||
break;
|
||||
|
||||
case SEG_LEFT_RIGHT_BOTTOM:
|
||||
rails_flip(api, temp, rails_three);
|
||||
use_temp=1;
|
||||
break;
|
||||
|
||||
case SEG_LEFT_TOP_BOTTOM:
|
||||
rails_rotate(api, temp, rails_three, 0);
|
||||
use_temp=1;
|
||||
break;
|
||||
|
||||
case SEG_RIGHT_TOP_BOTTOM:
|
||||
rails_rotate(api, temp, rails_three, 1);
|
||||
use_temp=1;
|
||||
break;
|
||||
|
||||
case SEG_RIGHT_TOP:
|
||||
SDL_BlitSurface(rails_corner, NULL, result, NULL);
|
||||
break;
|
||||
|
||||
case SEG_RIGHT_BOTTOM:
|
||||
rails_flip(api, temp, rails_corner);
|
||||
use_temp=1;
|
||||
break;
|
||||
|
||||
case SEG_LEFT_TOP:
|
||||
rails_rotate(api, temp, rails_corner, 0);
|
||||
use_temp=1;
|
||||
break;
|
||||
|
||||
case SEG_LEFT_BOTTOM:
|
||||
rails_flip_flop(api, temp, rails_corner);
|
||||
use_temp=1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (use_temp)
|
||||
SDL_BlitSurface(temp, NULL, result, NULL);
|
||||
|
||||
SDL_FreeSurface(temp);
|
||||
SDL_BlitSurface(result, NULL, canvas, &modification_rect);
|
||||
SDL_FreeSurface(result);
|
||||
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)
|
||||
{
|
||||
rails_segment_modified=rails_get_segment(x,y);
|
||||
|
||||
|
||||
if ( (rails_segment_modified == rails_segment_modified_last))
|
||||
return;
|
||||
if (rails_segment_modified>0)
|
||||
{
|
||||
rails_draw((void *) ptr, which, canvas, last, x, y, rails_segment_modified);
|
||||
}
|
||||
if (rails_segment_modified_last>0)
|
||||
rails_draw((void *) ptr, which, canvas, last, x, y, rails_segment_modified_last);
|
||||
|
||||
if (rails_segment_to_add>0)
|
||||
{
|
||||
rails_draw((void *) ptr, which, canvas, last, x, y, rails_segment_to_add);
|
||||
rails_draw((void *) ptr, which, canvas, last, x, y, rails_segment_modified_last);
|
||||
rails_segment_to_add=0;
|
||||
if (segment == rails_segment_modified_last - rails_segments_x - 1)
|
||||
{
|
||||
from_bottom_right = 1;
|
||||
rails_segment_to_add = segment + rails_segments_x;
|
||||
}
|
||||
if (segment == rails_segment_modified_last - rails_segments_x + 1)
|
||||
{
|
||||
from_bottom_left = 1;
|
||||
rails_segment_to_add = segment - 1;
|
||||
}
|
||||
}
|
||||
if (rails_segment_modified>0)
|
||||
rails_segment_modified_last=rails_segment_modified;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
take_up = segment - rails_segments_x;
|
||||
if (take_up <= 0)
|
||||
val_up = SEG_NONE;
|
||||
else
|
||||
val_up = rails_status_of_segments[take_up];
|
||||
|
||||
take_down = segment + rails_segments_x;
|
||||
if (take_down > (signed)(rails_segments_x * rails_segments_y))
|
||||
val_down = SEG_NONE;
|
||||
else
|
||||
val_down = rails_status_of_segments[take_down];
|
||||
|
||||
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 (from_left || (val_left & SEG_RIGHT) || from_bottom_left)
|
||||
{
|
||||
LEFT = 1;
|
||||
}
|
||||
if (from_right || (val_right & SEG_LEFT) || from_top_right)
|
||||
RIGHT = 1;
|
||||
if (from_top || (val_up & SEG_BOTTOM) || from_top_left)
|
||||
TOP = 1;
|
||||
if (from_bottom || (val_down & SEG_TOP) || from_bottom_right)
|
||||
BOTTOM = 1;
|
||||
|
||||
|
||||
if (TOP && BOTTOM && LEFT && RIGHT)
|
||||
return SEG_LEFT_RIGHT_TOP_BOTTOM;
|
||||
if (LEFT && RIGHT && TOP)
|
||||
return SEG_LEFT_RIGHT_TOP;
|
||||
if (LEFT && RIGHT && BOTTOM)
|
||||
return SEG_LEFT_RIGHT_BOTTOM;
|
||||
if (TOP && BOTTOM && LEFT)
|
||||
return SEG_LEFT_TOP_BOTTOM;
|
||||
if (TOP && BOTTOM && RIGHT)
|
||||
return SEG_RIGHT_TOP_BOTTOM;
|
||||
if (LEFT && RIGHT)
|
||||
return SEG_LEFT_RIGHT;
|
||||
if (TOP && BOTTOM)
|
||||
return SEG_TOP_BOTTOM;
|
||||
if (LEFT && TOP)
|
||||
return SEG_LEFT_TOP;
|
||||
if (LEFT && BOTTOM)
|
||||
return SEG_LEFT_BOTTOM;
|
||||
if (RIGHT && TOP)
|
||||
return SEG_RIGHT_TOP;
|
||||
if (RIGHT && BOTTOM)
|
||||
return SEG_RIGHT_BOTTOM;
|
||||
if (LEFT | RIGHT)
|
||||
return SEG_LEFT_RIGHT;
|
||||
return SEG_TOP_BOTTOM;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
Uint8 image;
|
||||
unsigned int use_temp;
|
||||
|
||||
use_temp = 0;
|
||||
if (segment > rails_segments_x * rails_segments_y)
|
||||
return;
|
||||
//modification_rect.x and modification_rect.y are set by function
|
||||
rails_extract_coords_from_segment(segment, &modification_rect.x, &modification_rect.y);
|
||||
modification_rect.h = img_w;
|
||||
modification_rect.w = img_h;
|
||||
|
||||
image = rails_select_image(segment); //select the image to display
|
||||
|
||||
if (rails_status_of_segments[segment] == image)
|
||||
return;
|
||||
|
||||
rails_status_of_segments[segment] = image; //and write it to global table
|
||||
|
||||
|
||||
result = SDL_CreateRGBSurface(SDL_SWSURFACE, img_w, img_h, rails_one->format->BitsPerPixel,
|
||||
rails_one->format->Rmask, rails_one->format->Gmask, rails_one->format->Bmask,
|
||||
rails_one->format->Amask);
|
||||
|
||||
temp = SDL_CreateRGBSurface(SDL_SWSURFACE, img_w, img_h, rails_one->format->BitsPerPixel,
|
||||
rails_one->format->Rmask, rails_one->format->Gmask, rails_one->format->Bmask,
|
||||
rails_one->format->Amask);
|
||||
|
||||
SDL_BlitSurface(canvas_backup, &modification_rect, result, NULL);
|
||||
|
||||
|
||||
switch (image)
|
||||
{
|
||||
case 0:
|
||||
case SEG_TOP_BOTTOM:
|
||||
SDL_BlitSurface(canvas_backup, &modification_rect, result, NULL);
|
||||
SDL_BlitSurface(rails_one, NULL, result, NULL);
|
||||
break;
|
||||
|
||||
case SEG_LEFT_RIGHT:
|
||||
SDL_BlitSurface(canvas_backup, &modification_rect, result, NULL);
|
||||
rails_rotate(api, temp, rails_one, 1);
|
||||
use_temp = 1;
|
||||
break;
|
||||
|
||||
case SEG_LEFT_RIGHT_TOP_BOTTOM:
|
||||
SDL_BlitSurface(canvas_backup, &modification_rect, result, NULL);
|
||||
SDL_BlitSurface(rails_four, NULL, result, NULL);
|
||||
break;
|
||||
|
||||
case SEG_LEFT_RIGHT_TOP:
|
||||
SDL_BlitSurface(rails_three, NULL, result, NULL);
|
||||
break;
|
||||
|
||||
case SEG_LEFT_RIGHT_BOTTOM:
|
||||
rails_flip(api, temp, rails_three);
|
||||
use_temp = 1;
|
||||
break;
|
||||
|
||||
case SEG_LEFT_TOP_BOTTOM:
|
||||
rails_rotate(api, temp, rails_three, 0);
|
||||
use_temp = 1;
|
||||
break;
|
||||
|
||||
case SEG_RIGHT_TOP_BOTTOM:
|
||||
rails_rotate(api, temp, rails_three, 1);
|
||||
use_temp = 1;
|
||||
break;
|
||||
|
||||
case SEG_RIGHT_TOP:
|
||||
SDL_BlitSurface(rails_corner, NULL, result, NULL);
|
||||
break;
|
||||
|
||||
case SEG_RIGHT_BOTTOM:
|
||||
rails_flip(api, temp, rails_corner);
|
||||
use_temp = 1;
|
||||
break;
|
||||
|
||||
case SEG_LEFT_TOP:
|
||||
rails_rotate(api, temp, rails_corner, 0);
|
||||
use_temp = 1;
|
||||
break;
|
||||
|
||||
case SEG_LEFT_BOTTOM:
|
||||
rails_flip_flop(api, temp, rails_corner);
|
||||
use_temp = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (use_temp)
|
||||
SDL_BlitSurface(temp, NULL, result, NULL);
|
||||
|
||||
SDL_FreeSurface(temp);
|
||||
SDL_BlitSurface(result, NULL, canvas, &modification_rect);
|
||||
SDL_FreeSurface(result);
|
||||
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)
|
||||
{
|
||||
rails_segment_modified = rails_get_segment(x, y);
|
||||
|
||||
|
||||
if ((rails_segment_modified == rails_segment_modified_last))
|
||||
return;
|
||||
if (rails_segment_modified > 0)
|
||||
{
|
||||
rails_draw((void *)ptr, which, canvas, last, x, y, rails_segment_modified);
|
||||
}
|
||||
if (rails_segment_modified_last > 0)
|
||||
rails_draw((void *)ptr, which, canvas, last, x, y, rails_segment_modified_last);
|
||||
|
||||
if (rails_segment_to_add > 0)
|
||||
{
|
||||
rails_draw((void *)ptr, which, canvas, last, x, y, rails_segment_to_add);
|
||||
rails_draw((void *)ptr, which, canvas, last, x, y, rails_segment_modified_last);
|
||||
rails_segment_to_add = 0;
|
||||
}
|
||||
if (rails_segment_modified > 0)
|
||||
rails_segment_modified_last = rails_segment_modified;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
start_x=min(ox,x);
|
||||
end_x=max(ox,x);
|
||||
start_y=min(oy,y);
|
||||
end_y=max(oy,y);
|
||||
api->line((void *)api, which, canvas, snapshot, ox, oy, x, y, img_w / 2, rails_draw_wrapper);
|
||||
|
||||
segment_start=rails_get_segment(start_x-img_w, start_y-img_h);
|
||||
segment_end=rails_get_segment(end_x+img_w,end_y+img_h);
|
||||
start_x = min(ox, x);
|
||||
end_x = max(ox, x);
|
||||
start_y = min(oy, y);
|
||||
end_y = max(oy, y);
|
||||
|
||||
x=((segment_start%rails_segments_x)-1)*img_w;
|
||||
y=(int)(segment_start/rails_segments_x)*img_h;
|
||||
w=((segment_end%rails_segments_x)-1)*img_w-x+img_w;
|
||||
h=(int)(segment_end/rails_segments_x)*img_h-y+img_h;
|
||||
segment_start = rails_get_segment(start_x - img_w, start_y - img_h);
|
||||
segment_end = rails_get_segment(end_x + img_w, end_y + img_h);
|
||||
|
||||
update_rect->x=x;
|
||||
update_rect->y=y;
|
||||
update_rect->w=w;
|
||||
update_rect->h=h;}
|
||||
x = ((segment_start % rails_segments_x) - 1) * img_w;
|
||||
y = (int)(segment_start / rails_segments_x) * img_h;
|
||||
w = ((segment_end % rails_segments_x) - 1) * img_w - x + img_w;
|
||||
h = (int)(segment_end / rails_segments_x) * img_h - y + img_h;
|
||||
|
||||
update_rect->x = x;
|
||||
update_rect->y = y;
|
||||
update_rect->w = w;
|
||||
update_rect->h = h;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
248
magic/src/rain.c
248
magic/src/rain.c
|
|
@ -48,47 +48,45 @@ 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 {
|
||||
TOOL_rain,
|
||||
rain_NUM_TOOLS
|
||||
enum
|
||||
{
|
||||
TOOL_rain,
|
||||
rain_NUM_TOOLS
|
||||
};
|
||||
|
||||
static Mix_Chunk * rain_snd_effect[rain_NUM_TOOLS];
|
||||
static Mix_Chunk *rain_snd_effect[rain_NUM_TOOLS];
|
||||
|
||||
const char * rain_snd_filenames[rain_NUM_TOOLS] = {
|
||||
const char *rain_snd_filenames[rain_NUM_TOOLS] = {
|
||||
"rain.ogg",
|
||||
};
|
||||
const char * rain_icon_filenames[rain_NUM_TOOLS] = {
|
||||
|
||||
const char *rain_icon_filenames[rain_NUM_TOOLS] = {
|
||||
"rain.png",
|
||||
};
|
||||
const char * rain_names[rain_NUM_TOOLS] = {
|
||||
|
||||
const char *rain_names[rain_NUM_TOOLS] = {
|
||||
gettext_noop("Rain"),
|
||||
};
|
||||
const char * rain_descs[rain_NUM_TOOLS][2] = {
|
||||
|
||||
const char *rain_descs[rain_NUM_TOOLS][2] = {
|
||||
{gettext_noop("Click to place a rain drop onto your picture."),
|
||||
gettext_noop("Click to cover your picture with rain drops."),},
|
||||
gettext_noop("Click to cover your picture with rain drops."),},
|
||||
};
|
||||
|
||||
Uint32 rain_api_version(void);
|
||||
int rain_init(magic_api * api);
|
||||
int rain_get_tool_count(magic_api * api);
|
||||
SDL_Surface * rain_get_icon(magic_api * api, int which);
|
||||
char * rain_get_name(magic_api * api, int which);
|
||||
char * rain_get_description(magic_api * api, int which, int mode);
|
||||
static void do_rain_drop(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y);
|
||||
static void rain_linecb(void * ptr, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y);
|
||||
SDL_Surface *rain_get_icon(magic_api * api, int which);
|
||||
char *rain_get_name(magic_api * api, int which);
|
||||
char *rain_get_description(magic_api * api, int which, int mode);
|
||||
static void do_rain_drop(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||
static void rain_linecb(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||
void rain_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
void rain_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void rain_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void rain_shutdown(magic_api * api);
|
||||
void rain_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
int rain_requires_colors(magic_api * api, int which);
|
||||
|
|
@ -96,96 +94,121 @@ void rain_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
|||
void rain_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
int rain_modes(magic_api * api, int which);
|
||||
|
||||
Uint32 rain_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
Uint32 rain_api_version(void)
|
||||
{
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
//Checks if a a pixel is inside a raindrop shape centered on the origin
|
||||
static int rain_inRainShape(double x, double y, double r){
|
||||
if ( sqrt( x*x + y*y ) < ( r * pow( cos( atan2(x,y) ), 10.0) ) ){
|
||||
return 1;
|
||||
}
|
||||
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++){
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/%s", api->data_directory, rain_snd_filenames[i]);
|
||||
rain_snd_effect[i] = Mix_LoadWAV(fname);
|
||||
}
|
||||
|
||||
return(1);
|
||||
//Load sounds
|
||||
for (i = 0; i < rain_NUM_TOOLS; i++)
|
||||
{
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/%s", api->data_directory, rain_snd_filenames[i]);
|
||||
rain_snd_effect[i] = Mix_LoadWAV(fname);
|
||||
}
|
||||
|
||||
return (1);
|
||||
}
|
||||
|
||||
int rain_get_tool_count(magic_api * api ATTRIBUTE_UNUSED){
|
||||
return(rain_NUM_TOOLS);
|
||||
int rain_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return (rain_NUM_TOOLS);
|
||||
}
|
||||
|
||||
// Load our icons:
|
||||
SDL_Surface * rain_get_icon(magic_api * api, int which){
|
||||
SDL_Surface *rain_get_icon(magic_api * api, int which)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, rain_icon_filenames[which]);
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our names, localized:
|
||||
char * rain_get_name(magic_api * api ATTRIBUTE_UNUSED, int which){
|
||||
return(strdup(gettext_noop(rain_names[which])));
|
||||
char *rain_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
|
||||
{
|
||||
return (strdup(gettext_noop(rain_names[which])));
|
||||
}
|
||||
|
||||
// Return our descriptions, localized:
|
||||
char * rain_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode){
|
||||
return(strdup(gettext_noop(rain_descs[which][mode-1])));
|
||||
char *rain_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode)
|
||||
{
|
||||
return (strdup(gettext_noop(rain_descs[which][mode - 1])));
|
||||
}
|
||||
|
||||
// Do the effect:
|
||||
static void do_rain_drop(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x, int y){
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
static void do_rain_drop(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
|
||||
SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
|
||||
{
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
|
||||
int xx, yy;
|
||||
Uint8 r,g,b;
|
||||
Uint8 r, g, b;
|
||||
|
||||
for (yy = y - rain_SIZE/2; yy < y + rain_SIZE/2; yy++){
|
||||
for (xx = x - rain_SIZE; xx < x + rain_SIZE; xx++){
|
||||
if (rain_inRainShape(xx - x, yy - y + rain_SIZE/2, rain_SIZE)){
|
||||
//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)));
|
||||
}
|
||||
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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void rain_linecb(void * ptr, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y)
|
||||
static void rain_linecb(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
SDL_Rect rect;
|
||||
|
||||
if (rand() % 10 == 0) {
|
||||
rain_click(api, which, MODE_PAINT, canvas, last,
|
||||
x + (rand() % rain_SIZE * 2) - rain_SIZE,
|
||||
y + (rand() % rain_SIZE * 2) - rain_SIZE,
|
||||
&rect);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// Affect the canvas on drag:
|
||||
void rain_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect){
|
||||
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, rain_linecb);
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, rain_linecb);
|
||||
|
||||
if (ox > x) { int tmp = ox; ox = x; x = tmp; }
|
||||
if (oy > y) { int tmp = oy; oy = y; y = tmp; }
|
||||
if (ox > x)
|
||||
{
|
||||
int tmp = ox;
|
||||
|
||||
ox = x;
|
||||
x = tmp;
|
||||
}
|
||||
if (oy > y)
|
||||
{
|
||||
int tmp = oy;
|
||||
|
||||
oy = y;
|
||||
y = tmp;
|
||||
}
|
||||
|
||||
update_rect->x = ox - rain_SIZE * 2;
|
||||
update_rect->y = oy - rain_SIZE * 2;
|
||||
|
|
@ -195,55 +218,64 @@ 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){
|
||||
do_rain_drop(api, which, canvas, last, x, y);
|
||||
if (mode == MODE_PAINT)
|
||||
{
|
||||
do_rain_drop(api, which, canvas, last, x, y);
|
||||
|
||||
update_rect->x = x - rain_SIZE;
|
||||
update_rect->y = y - rain_SIZE;
|
||||
update_rect->w = rain_SIZE * 2;
|
||||
update_rect->h = rain_SIZE * 2;
|
||||
update_rect->x = x - rain_SIZE;
|
||||
update_rect->y = y - rain_SIZE;
|
||||
update_rect->w = rain_SIZE * 2;
|
||||
update_rect->h = rain_SIZE * 2;
|
||||
|
||||
api->playsound(rain_snd_effect[which], (x * 255) / canvas->w, 255);
|
||||
}else{
|
||||
|
||||
int i;
|
||||
for(i=0; i<rain_AMOUNT; i++){
|
||||
do_rain_drop(api, which, canvas, last, rand() % canvas->w, rand() % canvas->h);
|
||||
api->playsound(rain_snd_effect[which], (x * 255) / canvas->w, 255);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
int i;
|
||||
|
||||
api->playsound(rain_snd_effect[which], 128, 255);
|
||||
}
|
||||
for (i = 0; i < rain_AMOUNT; i++)
|
||||
{
|
||||
do_rain_drop(api, which, canvas, last, rand() % canvas->w, rand() % canvas->h);
|
||||
}
|
||||
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
|
||||
api->playsound(rain_snd_effect[which], 128, 255);
|
||||
}
|
||||
}
|
||||
|
||||
// Affect the canvas on release:
|
||||
void rain_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)
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
// No setup happened:
|
||||
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){
|
||||
Mix_FreeChunk(rain_snd_effect[i]);
|
||||
}
|
||||
}
|
||||
//Clean up sounds
|
||||
int i;
|
||||
|
||||
for (i = 0; i < rain_NUM_TOOLS; i++)
|
||||
{
|
||||
if (rain_snd_effect[i] != NULL)
|
||||
{
|
||||
Mix_FreeChunk(rain_snd_effect[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Record the color from Tux Paint:
|
||||
void rain_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
|
||||
void rain_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
|
||||
Uint8 b ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -254,17 +286,17 @@ int rain_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_U
|
|||
}
|
||||
|
||||
|
||||
void rain_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void rain_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void rain_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void rain_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
int rain_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_FULLSCREEN|MODE_PAINT);
|
||||
return (MODE_FULLSCREEN | MODE_PAINT);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -65,31 +65,24 @@ static const int rainbow_hexes[NUM_RAINBOW_COLORS][3] = {
|
|||
|
||||
static int rainbow_color;
|
||||
static Uint32 rainbow_rgb;
|
||||
static Mix_Chunk * rainbow_snd;
|
||||
static Mix_Chunk *rainbow_snd;
|
||||
|
||||
int rainbow_init(magic_api * api);
|
||||
Uint32 rainbow_api_version(void);
|
||||
int rainbow_get_tool_count(magic_api * api);
|
||||
SDL_Surface * rainbow_get_icon(magic_api * api, int which);
|
||||
char * rainbow_get_name(magic_api * api, int which);
|
||||
char * rainbow_get_description(magic_api * api, int which, int mode);
|
||||
static void rainbow_linecb(void * ptr, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y);
|
||||
SDL_Surface *rainbow_get_icon(magic_api * api, int which);
|
||||
char *rainbow_get_name(magic_api * api, int which);
|
||||
char *rainbow_get_description(magic_api * api, int which, int mode);
|
||||
static void rainbow_linecb(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||
|
||||
void rainbow_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
|
||||
void rainbow_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
|
||||
void rainbow_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
|
||||
|
||||
void rainbow_shutdown(magic_api * api);
|
||||
|
|
@ -99,7 +92,10 @@ void rainbow_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas
|
|||
void rainbow_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
int rainbow_modes(magic_api * api, int which);
|
||||
|
||||
Uint32 rainbow_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
Uint32 rainbow_api_version(void)
|
||||
{
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
// Load our sfx:
|
||||
int rainbow_init(magic_api * api)
|
||||
|
|
@ -109,79 +105,85 @@ int rainbow_init(magic_api * api)
|
|||
|
||||
rainbow_color = 0;
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/rainbow.wav",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/rainbow.wav", api->data_directory);
|
||||
rainbow_snd = Mix_LoadWAV(fname);
|
||||
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
// We have multiple tools:
|
||||
int rainbow_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
// Load our icons:
|
||||
SDL_Surface * rainbow_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
SDL_Surface *rainbow_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/rainbow.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/rainbow.png", api->data_directory);
|
||||
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our names, localized:
|
||||
char * rainbow_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
char *rainbow_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(strdup(gettext_noop("Rainbow")));
|
||||
return (strdup(gettext_noop("Rainbow")));
|
||||
}
|
||||
|
||||
// Return our descriptions, localized:
|
||||
char * rainbow_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
||||
char *rainbow_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(strdup(
|
||||
gettext_noop("You can draw in rainbow colors!")));
|
||||
return (strdup(gettext_noop("You can draw in rainbow colors!")));
|
||||
}
|
||||
|
||||
// Do the effect:
|
||||
|
||||
static void rainbow_linecb(void * ptr, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x, int y)
|
||||
static void rainbow_linecb(void *ptr, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
int xx, yy;
|
||||
|
||||
for (yy = y - 16; yy < y + 16; yy++)
|
||||
{
|
||||
for (xx = x - 16; xx < x + 16; xx++)
|
||||
{
|
||||
if (api->in_circle(xx - x, yy - y, 16))
|
||||
{
|
||||
api->putpixel(canvas, xx, yy, rainbow_rgb);
|
||||
}
|
||||
for (xx = x - 16; xx < x + 16; xx++)
|
||||
{
|
||||
if (api->in_circle(xx - x, yy - y, 16))
|
||||
{
|
||||
api->putpixel(canvas, xx, yy, rainbow_rgb);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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][0],
|
||||
rainbow_hexes[rainbow_color][1], rainbow_hexes[rainbow_color][2]);
|
||||
|
||||
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, rainbow_linecb);
|
||||
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, rainbow_linecb);
|
||||
|
||||
if (ox > x) { int tmp = ox; ox = x; x = tmp; }
|
||||
if (oy > y) { int tmp = oy; oy = y; y = tmp; }
|
||||
if (ox > x)
|
||||
{
|
||||
int tmp = ox;
|
||||
|
||||
ox = x;
|
||||
x = tmp;
|
||||
}
|
||||
if (oy > y)
|
||||
{
|
||||
int tmp = oy;
|
||||
|
||||
oy = y;
|
||||
y = tmp;
|
||||
}
|
||||
|
||||
update_rect->x = ox - 16;
|
||||
update_rect->y = oy - 16;
|
||||
|
|
@ -193,17 +195,14 @@ void rainbow_drag(magic_api * api, int which, SDL_Surface * canvas,
|
|||
|
||||
// Affect the canvas on click:
|
||||
void rainbow_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
rainbow_drag(api, which, canvas, last, x, y, x, y, update_rect);
|
||||
}
|
||||
|
||||
void rainbow_release(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED,
|
||||
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -215,7 +214,8 @@ void rainbow_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
|||
}
|
||||
|
||||
// Record the color from Tux Paint:
|
||||
void rainbow_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
|
||||
void rainbow_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
|
||||
Uint8 b ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -225,15 +225,17 @@ int rainbow_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUT
|
|||
return 0;
|
||||
}
|
||||
|
||||
void rainbow_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void rainbow_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void rainbow_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void rainbow_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
int rainbow_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_PAINT);
|
||||
return (MODE_PAINT);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,48 +20,39 @@ FIXME:
|
|||
|
||||
#include "tp_magic_api.h"
|
||||
|
||||
Mix_Chunk * realrainbow_snd;
|
||||
Mix_Chunk *realrainbow_snd;
|
||||
int realrainbow_x1, realrainbow_y1, realrainbow_x2, realrainbow_y2;
|
||||
SDL_Rect realrainbow_rect;
|
||||
SDL_Surface * realrainbow_colors[2];
|
||||
SDL_Surface *realrainbow_colors[2];
|
||||
Uint8 realrainbow_blendr, realrainbow_blendg, realrainbow_blendb, realrainbow_blenda;
|
||||
|
||||
|
||||
void realrainbow_arc(magic_api * api, int which, SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x1, int y1, int x2, int y2,
|
||||
int fulldraw, SDL_Rect * update_rect);
|
||||
static void realrainbow_linecb(void * ptr, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y);
|
||||
int x1, int y1, int x2, int y2, int fulldraw, SDL_Rect * update_rect);
|
||||
static void realrainbow_linecb(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||
Uint32 realrainbow_api_version(void);
|
||||
int realrainbow_init(magic_api * api);
|
||||
int realrainbow_get_tool_count(magic_api * api);
|
||||
SDL_Surface * realrainbow_get_icon(magic_api * api, int which);
|
||||
char * realrainbow_get_name(magic_api * api, int which);
|
||||
char * realrainbow_get_description(magic_api * api, int which, int mode);
|
||||
SDL_Surface *realrainbow_get_icon(magic_api * api, int which);
|
||||
char *realrainbow_get_name(magic_api * api, int which);
|
||||
char *realrainbow_get_description(magic_api * api, int which, int mode);
|
||||
int realrainbow_modes(magic_api * api, int which);
|
||||
int realrainbow_requires_colors(magic_api * api, int which);
|
||||
void realrainbow_shutdown(magic_api * api);
|
||||
void realrainbow_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
void realrainbow_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void realrainbow_drag(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
void realrainbow_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void realrainbow_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
void realrainbow_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
|
||||
|
||||
Uint32 realrainbow_api_version(void)
|
||||
{
|
||||
return(TP_MAGIC_API_VERSION);
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
int realrainbow_init(magic_api * api)
|
||||
|
|
@ -71,60 +62,60 @@ int realrainbow_init(magic_api * api)
|
|||
snprintf(fname, sizeof(fname), "%s/images/magic/realrainbow-colors.png", api->data_directory);
|
||||
realrainbow_colors[0] = IMG_Load(fname);
|
||||
if (realrainbow_colors[0] == NULL)
|
||||
return(0);
|
||||
return (0);
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/realrainbow-roygbiv-colors.png", api->data_directory);
|
||||
realrainbow_colors[1] = IMG_Load(fname);
|
||||
if (realrainbow_colors[1] == NULL)
|
||||
return(0);
|
||||
return (0);
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/realrainbow.ogg",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/realrainbow.ogg", api->data_directory);
|
||||
realrainbow_snd = Mix_LoadWAV(fname);
|
||||
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
int realrainbow_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(2);
|
||||
return (2);
|
||||
}
|
||||
|
||||
SDL_Surface * realrainbow_get_icon(magic_api * api, int which)
|
||||
SDL_Surface *realrainbow_get_icon(magic_api * api, int which)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
if (which == 0)
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/realrainbow.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/realrainbow.png", api->data_directory);
|
||||
else
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/realrainbow-roygbiv.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/realrainbow-roygbiv.png", api->data_directory);
|
||||
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
char * realrainbow_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
|
||||
char *realrainbow_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
|
||||
{
|
||||
if (which == 0)
|
||||
return(strdup(gettext_noop("Real Rainbow")));
|
||||
return (strdup(gettext_noop("Real Rainbow")));
|
||||
else
|
||||
return(strdup(gettext_noop("ROYGBIV Rainbow")));
|
||||
return (strdup(gettext_noop("ROYGBIV Rainbow")));
|
||||
}
|
||||
|
||||
char * realrainbow_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
||||
char *realrainbow_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
|
||||
int mode ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(strdup(gettext_noop("Click where you want your rainbow to start, drag to where you want it to end, and then let go to draw a rainbow.")));
|
||||
return (strdup
|
||||
(gettext_noop
|
||||
("Click where you want your rainbow to start, drag to where you want it to end, and then let go to draw a rainbow.")));
|
||||
}
|
||||
|
||||
int realrainbow_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_PAINT_WITH_PREVIEW);
|
||||
return (MODE_PAINT_WITH_PREVIEW);
|
||||
}
|
||||
|
||||
int realrainbow_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
void realrainbow_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
||||
|
|
@ -137,14 +128,14 @@ void realrainbow_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
|||
Mix_FreeChunk(realrainbow_snd);
|
||||
}
|
||||
|
||||
void realrainbow_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
|
||||
void realrainbow_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
|
||||
Uint8 b ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void realrainbow_click(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x, int y,
|
||||
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
int x, int y, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
realrainbow_x1 = x;
|
||||
realrainbow_y1 = y;
|
||||
|
|
@ -157,8 +148,7 @@ void realrainbow_click(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNU
|
|||
|
||||
void realrainbow_drag(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
int rx1, ry1, rx2, ry2;
|
||||
SDL_Rect rect;
|
||||
|
|
@ -168,7 +158,8 @@ void realrainbow_drag(magic_api * api, int which,
|
|||
|
||||
SDL_BlitSurface(last, &realrainbow_rect, canvas, &realrainbow_rect);
|
||||
|
||||
realrainbow_arc(api, which, canvas, last, realrainbow_x1, realrainbow_y1, realrainbow_x2, realrainbow_y2, 0, update_rect);
|
||||
realrainbow_arc(api, which, canvas, last, realrainbow_x1, realrainbow_y1, realrainbow_x2, realrainbow_y2, 0,
|
||||
update_rect);
|
||||
|
||||
memcpy(&rect, &realrainbow_rect, sizeof(SDL_Rect));
|
||||
memcpy(&realrainbow_rect, update_rect, sizeof(SDL_Rect));
|
||||
|
|
@ -194,9 +185,7 @@ void realrainbow_drag(magic_api * api, int which,
|
|||
}
|
||||
|
||||
void realrainbow_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
int rx1, ry1, rx2, ry2;
|
||||
SDL_Rect rect;
|
||||
|
|
@ -206,7 +195,8 @@ void realrainbow_release(magic_api * api, int which,
|
|||
|
||||
SDL_BlitSurface(last, &realrainbow_rect, canvas, &realrainbow_rect);
|
||||
|
||||
realrainbow_arc(api, which, canvas, last, realrainbow_x1, realrainbow_y1, realrainbow_x2, realrainbow_y2, 1, update_rect);
|
||||
realrainbow_arc(api, which, canvas, last, realrainbow_x1, realrainbow_y1, realrainbow_x2, realrainbow_y2, 1,
|
||||
update_rect);
|
||||
|
||||
memcpy(&rect, &realrainbow_rect, sizeof(SDL_Rect));
|
||||
memcpy(&realrainbow_rect, update_rect, sizeof(SDL_Rect));
|
||||
|
|
@ -233,16 +223,19 @@ void realrainbow_release(magic_api * api, int which,
|
|||
api->playsound(realrainbow_snd, 128, 255);
|
||||
}
|
||||
|
||||
void realrainbow_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void realrainbow_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void realrainbow_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void realrainbow_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void realrainbow_arc(magic_api * api, int which, SDL_Surface * canvas, SDL_Surface * last, int x1, int y1, int x2, int y2, int fulldraw, SDL_Rect * update_rect)
|
||||
void realrainbow_arc(magic_api * api, int which, SDL_Surface * canvas, SDL_Surface * last, int x1, int y1, int x2,
|
||||
int y2, int fulldraw, SDL_Rect * update_rect)
|
||||
{
|
||||
int lowx, lowy, hix, hiy, xm, ym, xc, yc, r, a1, atan2_a, atan2_b;
|
||||
int a, oa, ox, oy, nx, ny, step, thick, rr, done;
|
||||
|
|
@ -250,71 +243,71 @@ void realrainbow_arc(magic_api * api, int which, SDL_Surface * canvas, SDL_Surfa
|
|||
int colorindex;
|
||||
|
||||
if (abs(x2 - x1) < 50)
|
||||
{
|
||||
if (x2 > x1)
|
||||
x2 = x1 + 50;
|
||||
else
|
||||
x2 = x1 - 50;
|
||||
}
|
||||
{
|
||||
if (x2 > x1)
|
||||
x2 = x1 + 50;
|
||||
else
|
||||
x2 = x1 - 50;
|
||||
}
|
||||
|
||||
if (y1 == y2)
|
||||
{
|
||||
xc = x1 + (x2 - x1) / 2;
|
||||
yc = y1;
|
||||
r = abs(xc - x1);
|
||||
|
||||
a1 = 0;
|
||||
theta = -180;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (y1 > y2)
|
||||
{
|
||||
lowx = x1;
|
||||
lowy = y1;
|
||||
hix = x2;
|
||||
hiy = y2;
|
||||
}
|
||||
else
|
||||
{
|
||||
lowx = x2;
|
||||
lowy = y2;
|
||||
hix = x1;
|
||||
hiy = y1;
|
||||
}
|
||||
xc = x1 + (x2 - x1) / 2;
|
||||
yc = y1;
|
||||
r = abs(xc - x1);
|
||||
|
||||
xm = (lowx + hix) / 2;
|
||||
ym = (lowy + hiy) / 2;
|
||||
|
||||
if (hix == lowx)
|
||||
return;
|
||||
|
||||
slope = (float)(hiy - lowy) / (float)(hix - lowx);
|
||||
|
||||
yc = lowy;
|
||||
xc = slope * (ym - yc) + xm;
|
||||
|
||||
r = abs(xc - lowx);
|
||||
atan2_b = hix - xc;
|
||||
atan2_a = hiy - yc;
|
||||
theta = atan2(atan2_a, atan2_b) * (180.0 / M_PI);
|
||||
|
||||
if (slope > 0)
|
||||
a1 = 0;
|
||||
else
|
||||
a1 = -180;
|
||||
}
|
||||
theta = -180;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (y1 > y2)
|
||||
{
|
||||
lowx = x1;
|
||||
lowy = y1;
|
||||
hix = x2;
|
||||
hiy = y2;
|
||||
}
|
||||
else
|
||||
{
|
||||
lowx = x2;
|
||||
lowy = y2;
|
||||
hix = x1;
|
||||
hiy = y1;
|
||||
}
|
||||
|
||||
xm = (lowx + hix) / 2;
|
||||
ym = (lowy + hiy) / 2;
|
||||
|
||||
if (hix == lowx)
|
||||
return;
|
||||
|
||||
slope = (float)(hiy - lowy) / (float)(hix - lowx);
|
||||
|
||||
yc = lowy;
|
||||
xc = slope * (ym - yc) + xm;
|
||||
|
||||
r = abs(xc - lowx);
|
||||
atan2_b = hix - xc;
|
||||
atan2_a = hiy - yc;
|
||||
theta = atan2(atan2_a, atan2_b) * (180.0 / M_PI);
|
||||
|
||||
if (slope > 0)
|
||||
a1 = 0;
|
||||
else
|
||||
a1 = -180;
|
||||
}
|
||||
|
||||
if (fulldraw)
|
||||
{
|
||||
step = 1;
|
||||
/* thick = (r / 5); */
|
||||
}
|
||||
{
|
||||
step = 1;
|
||||
/* thick = (r / 5); */
|
||||
}
|
||||
else
|
||||
{
|
||||
step = 30;
|
||||
/* thick = 1; */
|
||||
}
|
||||
{
|
||||
step = 30;
|
||||
/* thick = 1; */
|
||||
}
|
||||
thick = (r / 5);
|
||||
|
||||
if (theta < a1)
|
||||
|
|
@ -324,52 +317,51 @@ void realrainbow_arc(magic_api * api, int which, SDL_Surface * canvas, SDL_Surfa
|
|||
oa = a1;
|
||||
|
||||
for (a = (a1 + step); done < 2; a = a + step)
|
||||
{
|
||||
for (rr = r - (thick / 2); rr <= r + (thick / 2); rr++)
|
||||
{
|
||||
ox = (rr * cos(oa * M_PI / 180.0)) + xc;
|
||||
oy = (rr * sin(oa * M_PI / 180.0)) + yc;
|
||||
for (rr = r - (thick / 2); rr <= r + (thick / 2); rr++)
|
||||
{
|
||||
ox = (rr * cos(oa * M_PI / 180.0)) + xc;
|
||||
oy = (rr * sin(oa * M_PI / 180.0)) + yc;
|
||||
|
||||
nx = (rr * cos(a * M_PI / 180.0)) + xc;
|
||||
ny = (rr * sin(a * M_PI / 180.0)) + yc;
|
||||
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);
|
||||
SDL_GetRGBA(api->getpixel(realrainbow_colors[which], 0, colorindex),
|
||||
realrainbow_colors[which]->format, &realrainbow_blendr, &realrainbow_blendg, &realrainbow_blendb,
|
||||
&realrainbow_blenda);
|
||||
|
||||
if (!fulldraw)
|
||||
realrainbow_blenda = 255;
|
||||
if (!fulldraw)
|
||||
realrainbow_blenda = 255;
|
||||
|
||||
api->line((void *) api, 0, canvas, last, ox, oy, nx, ny, 1, realrainbow_linecb);
|
||||
api->line((void *)api, 0, canvas, last, ox, oy, nx, ny, 1, realrainbow_linecb);
|
||||
}
|
||||
|
||||
oa = a;
|
||||
|
||||
if ((step > 0 && a + step > theta) || (step < 0 && a + step < theta))
|
||||
{
|
||||
done++;
|
||||
a = theta - step;
|
||||
}
|
||||
}
|
||||
|
||||
oa = a;
|
||||
|
||||
if ((step > 0 && a + step > theta) ||
|
||||
(step < 0 && a + step < theta))
|
||||
{
|
||||
done++;
|
||||
a = theta - step;
|
||||
}
|
||||
}
|
||||
|
||||
update_rect->y = yc - r - thick - 2;
|
||||
update_rect->h = r + thick * 2 + 4;
|
||||
update_rect->x = xc - r - thick;
|
||||
update_rect->w = r * 2 + thick * 2;
|
||||
}
|
||||
|
||||
static void realrainbow_linecb(void * ptr, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y)
|
||||
static void realrainbow_linecb(void *ptr, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y)
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
Uint8 origr, origg, origb;
|
||||
Uint8 newr, newg, newb;
|
||||
|
||||
SDL_GetRGB(api->getpixel(last, x, y),
|
||||
last->format, &origr, &origg, &origb);
|
||||
SDL_GetRGB(api->getpixel(last, x, y), last->format, &origr, &origg, &origb);
|
||||
|
||||
newr = ((realrainbow_blendr * realrainbow_blenda) / 255) + ((origr * (255 - realrainbow_blenda)) / 255);
|
||||
newg = ((realrainbow_blendg * realrainbow_blenda) / 255) + ((origg * (255 - realrainbow_blenda)) / 255);
|
||||
|
|
@ -377,4 +369,3 @@ static void realrainbow_linecb(void * ptr, int which ATTRIBUTE_UNUSED,
|
|||
|
||||
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, newr, newg, newb));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,28 +37,23 @@
|
|||
|
||||
/* Our globals: */
|
||||
|
||||
static Mix_Chunk * ripples_snd;
|
||||
static Mix_Chunk *ripples_snd;
|
||||
|
||||
static int ripples_z, ripples_brite;
|
||||
|
||||
Uint32 ripples_api_version(void);
|
||||
int ripples_init(magic_api * api);
|
||||
int ripples_get_tool_count(magic_api * api);
|
||||
SDL_Surface * ripples_get_icon(magic_api * api, int which);
|
||||
char * ripples_get_name(magic_api * api, int which);
|
||||
char * ripples_get_description(magic_api * api, int which, int mode);
|
||||
SDL_Surface *ripples_get_icon(magic_api * api, int which);
|
||||
char *ripples_get_name(magic_api * api, int which);
|
||||
char *ripples_get_description(magic_api * api, int which, int mode);
|
||||
void ripples_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
static void ripples_linecb(void * ptr, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y);
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
static void ripples_linecb(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||
void ripples_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void ripples_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void ripples_shutdown(magic_api * api);
|
||||
void ripples_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
int ripples_requires_colors(magic_api * api, int which);
|
||||
|
|
@ -66,7 +61,10 @@ void ripples_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas
|
|||
void ripples_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
int ripples_modes(magic_api * api, int which);
|
||||
|
||||
Uint32 ripples_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
Uint32 ripples_api_version(void)
|
||||
{
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
#define deg_cos(x) cos((x) * M_PI / 180.0)
|
||||
#define deg_sin(x) sin((x) * M_PI / 180.0)
|
||||
|
|
@ -76,54 +74,51 @@ int ripples_init(magic_api * api)
|
|||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/ripples.ogg",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/ripples.ogg", api->data_directory);
|
||||
ripples_snd = Mix_LoadWAV(fname);
|
||||
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
// We have multiple tools:
|
||||
int ripples_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
// Load our icons:
|
||||
SDL_Surface * ripples_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
SDL_Surface *ripples_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/ripples.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/ripples.png", api->data_directory);
|
||||
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our names, localized:
|
||||
char * ripples_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
char *ripples_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(strdup(gettext_noop("Ripples")));
|
||||
return (strdup(gettext_noop("Ripples")));
|
||||
}
|
||||
|
||||
// Return our descriptions, localized:
|
||||
char * ripples_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
||||
char *ripples_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(strdup(gettext_noop("Click to make ripples appear over your picture.")));
|
||||
return (strdup(gettext_noop("Click to make ripples appear over your picture.")));
|
||||
}
|
||||
|
||||
// Affect the canvas on drag:
|
||||
void ripples_drag(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * last ATTRIBUTE_UNUSED, int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED,
|
||||
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
SDL_Surface * last ATTRIBUTE_UNUSED, int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
static void ripples_linecb(void * ptr, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y)
|
||||
static void ripples_linecb(void *ptr, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y)
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
Uint8 r, g, b;
|
||||
Uint32 pix;
|
||||
|
||||
|
|
@ -139,8 +134,7 @@ static void ripples_linecb(void * ptr, int which ATTRIBUTE_UNUSED,
|
|||
|
||||
// Affect the canvas on click:
|
||||
void ripples_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect)
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
float radius;
|
||||
float fli;
|
||||
|
|
@ -149,25 +143,25 @@ void ripples_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
|
|||
radius = 100;
|
||||
|
||||
for (fli = 0; fli < radius; fli = fli + .25)
|
||||
{
|
||||
ripples_z = (10 * deg_sin(((50 * 50) / (fli + 4)) * 10));
|
||||
|
||||
ox = fli * deg_cos(0) + x;
|
||||
oy = -fli * deg_sin(0) + y;
|
||||
|
||||
for (d = 0; d <= 360 + (360 / (fli + 1)); d = d + 360 / (fli + 1))
|
||||
{
|
||||
nx = fli * deg_cos(d) + x;
|
||||
ny = -fli * deg_sin(d) + y;
|
||||
|
||||
ripples_brite = (ripples_z * 20 * deg_sin(d + 45)) / ((fli / 4) + 1);
|
||||
ripples_z = (10 * deg_sin(((50 * 50) / (fli + 4)) * 10));
|
||||
|
||||
api->line((void *) api, which, canvas, last, ox, oy, nx, ny, 1, ripples_linecb);
|
||||
|
||||
ox = nx;
|
||||
oy = ny;
|
||||
ox = fli * deg_cos(0) + x;
|
||||
oy = -fli * deg_sin(0) + y;
|
||||
|
||||
for (d = 0; d <= 360 + (360 / (fli + 1)); d = d + 360 / (fli + 1))
|
||||
{
|
||||
nx = fli * deg_cos(d) + x;
|
||||
ny = -fli * deg_sin(d) + y;
|
||||
|
||||
ripples_brite = (ripples_z * 20 * deg_sin(d + 45)) / ((fli / 4) + 1);
|
||||
|
||||
api->line((void *)api, which, canvas, last, ox, oy, nx, ny, 1, ripples_linecb);
|
||||
|
||||
ox = nx;
|
||||
oy = ny;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
update_rect->x = x - 100;
|
||||
update_rect->y = y - 100;
|
||||
|
|
@ -179,8 +173,8 @@ void ripples_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
|
|||
|
||||
// Affect the canvas on release:
|
||||
void ripples_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)
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -192,7 +186,8 @@ void ripples_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
|||
}
|
||||
|
||||
// Record the color from Tux Paint:
|
||||
void ripples_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
|
||||
void ripples_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
|
||||
Uint8 b ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -202,15 +197,17 @@ int ripples_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUT
|
|||
return 0;
|
||||
}
|
||||
|
||||
void ripples_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void ripples_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void ripples_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void ripples_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
int ripples_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_ONECLICK);
|
||||
return (MODE_ONECLICK);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,69 +32,64 @@
|
|||
#include "tp_magic_api.h"
|
||||
#include "SDL_image.h"
|
||||
#include "SDL_mixer.h"
|
||||
#include <math.h> //for sin, cos, ...
|
||||
#define ROSETTE_R 8 //circle's diameter
|
||||
#include <math.h> //for sin, cos, ...
|
||||
#define ROSETTE_R 8 //circle's diameter
|
||||
|
||||
static int xmid, ymid;
|
||||
|
||||
struct rosette_rgb
|
||||
{
|
||||
Uint8 r, g, b;
|
||||
Uint8 r, g, b;
|
||||
};
|
||||
|
||||
struct rosette_rgb rosette_colors;
|
||||
|
||||
Mix_Chunk * rosette_snd;
|
||||
Mix_Chunk *rosette_snd;
|
||||
|
||||
// Housekeeping functions
|
||||
// Housekeeping functions
|
||||
|
||||
Uint32 rosette_api_version(void);
|
||||
void rosette_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
int rosette_init(magic_api * api);
|
||||
int rosette_get_tool_count(magic_api * api);
|
||||
SDL_Surface * rosette_get_icon(magic_api * api, int which);
|
||||
char * rosette_get_name(magic_api * api, int which);
|
||||
char * rosette_get_description(magic_api * api, int which, int mode);
|
||||
SDL_Surface *rosette_get_icon(magic_api * api, int which);
|
||||
char *rosette_get_name(magic_api * api, int which);
|
||||
char *rosette_get_description(magic_api * api, int which, int mode);
|
||||
int rosette_requires_colors(magic_api * api, int which);
|
||||
void rosette_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
|
||||
void rosette_shutdown(magic_api * api);
|
||||
void rosette_draw(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
|
||||
void rosette_draw(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
|
||||
void rosette_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
|
||||
void rosette_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void rosette_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
void rosette_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
int rosette_modes(magic_api * api, int which);
|
||||
void rosette_circle(void * ptr, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y);
|
||||
void rosette_circle(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
|
||||
|
||||
Uint32 rosette_api_version(void)
|
||||
{
|
||||
return(TP_MAGIC_API_VERSION);
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
void rosette_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b) //get the colors from API and store it in structure
|
||||
void rosette_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b) //get the colors from API and store it in structure
|
||||
{
|
||||
rosette_colors.r=r;
|
||||
rosette_colors.g=g;
|
||||
rosette_colors.b=b;
|
||||
rosette_colors.r = r;
|
||||
rosette_colors.g = g;
|
||||
rosette_colors.b = b;
|
||||
}
|
||||
|
||||
int rosette_init(magic_api * api)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/picasso.ogg", api->data_directory);
|
||||
rosette_snd = Mix_LoadWAV(fname);
|
||||
|
||||
return(1);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/picasso.ogg", api->data_directory);
|
||||
rosette_snd = Mix_LoadWAV(fname);
|
||||
|
||||
return (1);
|
||||
}
|
||||
|
||||
int rosette_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
|
|
@ -102,131 +97,146 @@ int rosette_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
|||
return 2;
|
||||
}
|
||||
|
||||
SDL_Surface * rosette_get_icon(magic_api * api, int which)
|
||||
SDL_Surface *rosette_get_icon(magic_api * api, int which)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
if (!which)
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/rosette.png", api->data_directory);
|
||||
else snprintf(fname, sizeof(fname), "%s/images/magic/picasso.png", api->data_directory);
|
||||
|
||||
return(IMG_Load(fname));
|
||||
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);
|
||||
|
||||
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_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
|
||||
char *rosette_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
|
||||
{
|
||||
if (!which)
|
||||
return strdup(gettext_noop("Click and start drawing your rosette.")); //just k'scope with 3 bits?
|
||||
else
|
||||
return strdup(gettext_noop("You can draw just like Picasso!")); //what is this actually doing?
|
||||
if (!which)
|
||||
return strdup(gettext_noop("Rosette"));
|
||||
else
|
||||
return strdup(gettext_noop("Picasso"));
|
||||
}
|
||||
|
||||
int rosette_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) { return 1; }
|
||||
char *rosette_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
|
||||
{
|
||||
if (!which)
|
||||
return strdup(gettext_noop("Click and start drawing your rosette.")); //just k'scope with 3 bits?
|
||||
else
|
||||
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;
|
||||
}
|
||||
|
||||
void rosette_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)
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * snapshot ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void rosette_shutdown(magic_api * api ATTRIBUTE_UNUSED) { Mix_FreeChunk(rosette_snd); }
|
||||
void rosette_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
Mix_FreeChunk(rosette_snd);
|
||||
}
|
||||
|
||||
// Interactivity functions
|
||||
|
||||
void rosette_circle(void * ptr, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED,
|
||||
int x, int y)
|
||||
void rosette_circle(void *ptr, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
|
||||
int xx, yy;
|
||||
|
||||
for (yy = y - ROSETTE_R; yy < y + ROSETTE_R; yy++)
|
||||
for (xx = x - ROSETTE_R; xx < x + ROSETTE_R; xx++)
|
||||
if (api->in_circle(xx - x , yy - y , ROSETTE_R/2))
|
||||
api->putpixel(canvas, xx, yy, SDL_MapRGB(canvas->format, rosette_colors.r, rosette_colors.g, rosette_colors.b));
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
|
||||
int xx, yy;
|
||||
|
||||
for (yy = y - ROSETTE_R; yy < y + ROSETTE_R; yy++)
|
||||
for (xx = x - ROSETTE_R; xx < x + ROSETTE_R; xx++)
|
||||
if (api->in_circle(xx - x, yy - y, ROSETTE_R / 2))
|
||||
api->putpixel(canvas, xx, yy, SDL_MapRGB(canvas->format, rosette_colors.r, rosette_colors.g, rosette_colors.b));
|
||||
|
||||
}
|
||||
|
||||
void rosette_draw(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y)
|
||||
void rosette_draw(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y)
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
|
||||
double angle;
|
||||
double xx, yy; //distance to the center of the image
|
||||
int x1, y1, x2, y2;
|
||||
|
||||
xx=(double)(xmid-x);
|
||||
yy=(double)(y-ymid);
|
||||
|
||||
if (which==0)
|
||||
{
|
||||
angle=2*M_PI/3; //an angle between brushes
|
||||
|
||||
x1=(int)(xx*cos(angle)-yy*sin(angle));
|
||||
y1=(int)(xx*sin(angle)+yy*cos(angle));
|
||||
|
||||
x2=(int)(xx*cos(2*angle)-yy*sin(2*angle));
|
||||
y2=(int)(xx*sin(2*angle)+yy*cos(2*angle));
|
||||
}
|
||||
else
|
||||
{
|
||||
angle=atan(yy/xx);
|
||||
|
||||
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;
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
|
||||
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));
|
||||
|
||||
x2=(int)(xx*cos(2*angle)-yy*sin(2*angle));
|
||||
y2=(int)(xx*sin(2*angle)+yy*cos(2*angle));
|
||||
}
|
||||
double angle;
|
||||
double xx, yy; //distance to the center of the image
|
||||
int x1, y1, x2, y2;
|
||||
|
||||
rosette_circle(api, which, canvas, snapshot, x, y);
|
||||
rosette_circle(api, which, canvas, snapshot, (-1)*(x1-xmid), y1+ymid);
|
||||
rosette_circle(api, which, canvas, snapshot, (-1)*(x2-xmid), y2+ymid);
|
||||
xx = (double)(xmid - x);
|
||||
yy = (double)(y - ymid);
|
||||
|
||||
if (which == 0)
|
||||
{
|
||||
angle = 2 * M_PI / 3; //an angle between brushes
|
||||
|
||||
x1 = (int)(xx * cos(angle) - yy * sin(angle));
|
||||
y1 = (int)(xx * sin(angle) + yy * cos(angle));
|
||||
|
||||
x2 = (int)(xx * cos(2 * angle) - yy * sin(2 * angle));
|
||||
y2 = (int)(xx * sin(2 * angle) + yy * cos(2 * angle));
|
||||
}
|
||||
else
|
||||
{
|
||||
angle = atan(yy / xx);
|
||||
|
||||
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 ((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));
|
||||
|
||||
x2 = (int)(xx * cos(2 * angle) - yy * sin(2 * angle));
|
||||
y2 = (int)(xx * sin(2 * angle) + yy * cos(2 * angle));
|
||||
}
|
||||
|
||||
rosette_circle(api, which, canvas, snapshot, x, y);
|
||||
rosette_circle(api, which, canvas, snapshot, (-1) * (x1 - xmid), y1 + ymid);
|
||||
rosette_circle(api, which, canvas, snapshot, (-1) * (x2 - xmid), y2 + ymid);
|
||||
}
|
||||
|
||||
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);
|
||||
api->line((void *)api, which, canvas, snapshot, ox, oy, x, y, 1, rosette_draw);
|
||||
api->playsound(rosette_snd, (x * 255) / canvas->w, 255);
|
||||
|
||||
update_rect->x=update_rect->y=0;
|
||||
update_rect->w=canvas->w;
|
||||
update_rect->h=canvas->h;
|
||||
update_rect->x = update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
}
|
||||
|
||||
void rosette_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect)
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
rosette_drag(api, which, canvas, last, x, y, x, y, update_rect);
|
||||
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)
|
||||
{
|
||||
xmid=canvas->w/2;
|
||||
ymid=canvas->h/2;
|
||||
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)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
int rosette_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_PAINT);
|
||||
return (MODE_PAINT);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,11 +44,12 @@
|
|||
|
||||
/* Our globals: */
|
||||
|
||||
enum {
|
||||
TOOL_TRACE,
|
||||
TOOL_SHARPEN,
|
||||
TOOL_SILHOUETTE,
|
||||
sharpen_NUM_TOOLS
|
||||
enum
|
||||
{
|
||||
TOOL_TRACE,
|
||||
TOOL_SHARPEN,
|
||||
TOOL_SILHOUETTE,
|
||||
sharpen_NUM_TOOLS
|
||||
};
|
||||
|
||||
static const int THRESHOLD = 50;
|
||||
|
|
@ -57,54 +58,52 @@ static const int sharpen_RADIUS = 16;
|
|||
|
||||
static const double SHARPEN = 0.5;
|
||||
|
||||
static Mix_Chunk * sharpen_snd_effect[sharpen_NUM_TOOLS];
|
||||
static Mix_Chunk *sharpen_snd_effect[sharpen_NUM_TOOLS];
|
||||
|
||||
const char * sharpen_snd_filenames[sharpen_NUM_TOOLS] = {
|
||||
const char *sharpen_snd_filenames[sharpen_NUM_TOOLS] = {
|
||||
"edges.ogg",
|
||||
"sharpen.ogg",
|
||||
"silhouette.ogg"
|
||||
};
|
||||
const char * sharpen_icon_filenames[sharpen_NUM_TOOLS] = {
|
||||
|
||||
const char *sharpen_icon_filenames[sharpen_NUM_TOOLS] = {
|
||||
"edges.png",
|
||||
"sharpen.png",
|
||||
"silhouette.png"
|
||||
};
|
||||
const char * sharpen_names[sharpen_NUM_TOOLS] = {
|
||||
|
||||
const char *sharpen_names[sharpen_NUM_TOOLS] = {
|
||||
gettext_noop("Edges"),
|
||||
gettext_noop("Sharpen"),
|
||||
gettext_noop("Silhouette")
|
||||
};
|
||||
const char * sharpen_descs[sharpen_NUM_TOOLS][2] = {
|
||||
|
||||
const char *sharpen_descs[sharpen_NUM_TOOLS][2] = {
|
||||
{gettext_noop("Click and drag the mouse to trace edges in parts of your picture."),
|
||||
gettext_noop("Click to trace edges in your entire picture."),},
|
||||
gettext_noop("Click to trace edges in your entire picture."),},
|
||||
{gettext_noop("Click and drag the mouse to sharpen parts of your picture."),
|
||||
gettext_noop("Click to sharpen the entire picture."),},
|
||||
gettext_noop("Click to sharpen the entire picture."),},
|
||||
{gettext_noop("Click and drag the mouse to create a black and white silhouette."),
|
||||
gettext_noop("Click to create a black and white silhouette of your entire picture.")},
|
||||
gettext_noop("Click to create a black and white silhouette of your entire picture.")},
|
||||
};
|
||||
|
||||
Uint32 sharpen_api_version(void);
|
||||
int sharpen_init(magic_api * api);
|
||||
int sharpen_get_tool_count(magic_api * api);
|
||||
SDL_Surface * sharpen_get_icon(magic_api * api, int which);
|
||||
char * sharpen_get_name(magic_api * api, int which);
|
||||
char * sharpen_get_description(magic_api * api, int which, int mode);
|
||||
static int sharpen_grey(Uint8 r1,Uint8 g1,Uint8 b1);
|
||||
static void do_sharpen_pixel(void * ptr, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y);
|
||||
static void do_sharpen_full(void * ptr,SDL_Surface * canvas, SDL_Surface * last, int which);
|
||||
static void do_sharpen_brush(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||
SDL_Surface *sharpen_get_icon(magic_api * api, int which);
|
||||
char *sharpen_get_name(magic_api * api, int which);
|
||||
char *sharpen_get_description(magic_api * api, int which, int mode);
|
||||
static int sharpen_grey(Uint8 r1, Uint8 g1, Uint8 b1);
|
||||
static void do_sharpen_pixel(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||
static void do_sharpen_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int which);
|
||||
static void do_sharpen_brush(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||
void sharpen_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
void sharpen_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
|
||||
void sharpen_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
|
||||
void sharpen_shutdown(magic_api * api);
|
||||
void sharpen_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
|
|
@ -113,149 +112,181 @@ 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++){
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/%s", api->data_directory, sharpen_snd_filenames[i]);
|
||||
sharpen_snd_effect[i] = Mix_LoadWAV(fname);
|
||||
}
|
||||
for (i = 0; i < sharpen_NUM_TOOLS; i++)
|
||||
{
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/%s", api->data_directory, sharpen_snd_filenames[i]);
|
||||
sharpen_snd_effect[i] = Mix_LoadWAV(fname);
|
||||
}
|
||||
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
// We have multiple tools:
|
||||
int sharpen_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(sharpen_NUM_TOOLS);
|
||||
return (sharpen_NUM_TOOLS);
|
||||
}
|
||||
|
||||
// Load our icons:
|
||||
SDL_Surface * sharpen_get_icon(magic_api * api, int which){
|
||||
SDL_Surface *sharpen_get_icon(magic_api * api, int which)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, sharpen_icon_filenames[which]);
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our names, localized:
|
||||
char * sharpen_get_name(magic_api * api ATTRIBUTE_UNUSED, int which){
|
||||
return(strdup(gettext_noop(sharpen_names[which])));
|
||||
char *sharpen_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
|
||||
{
|
||||
return (strdup(gettext_noop(sharpen_names[which])));
|
||||
}
|
||||
|
||||
// Return our descriptions, localized:
|
||||
char * sharpen_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode){
|
||||
return(strdup(gettext_noop(sharpen_descs[which][mode-1])));
|
||||
char *sharpen_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode)
|
||||
{
|
||||
return (strdup(gettext_noop(sharpen_descs[which][mode - 1])));
|
||||
}
|
||||
|
||||
//Calculates the grey scale value for a rgb pixel
|
||||
static int sharpen_grey(Uint8 r1,Uint8 g1,Uint8 b1){
|
||||
return 0.3*r1+.59*g1+0.11*b1;
|
||||
static int sharpen_grey(Uint8 r1, Uint8 g1, Uint8 b1)
|
||||
{
|
||||
return 0.3 * r1 + .59 * g1 + 0.11 * b1;
|
||||
}
|
||||
|
||||
// Do the effect:
|
||||
static void do_sharpen_pixel(void * ptr, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y){
|
||||
static void do_sharpen_pixel(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
|
||||
{
|
||||
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
|
||||
Uint8 r1, g1, b1;
|
||||
int grey;
|
||||
int i,j;
|
||||
double sobel_1=0,sobel_2=0;
|
||||
double temp;
|
||||
Uint8 r1, g1, b1;
|
||||
int grey;
|
||||
int i, j;
|
||||
double sobel_1 = 0, sobel_2 = 0;
|
||||
double temp;
|
||||
|
||||
//Sobel weighting masks
|
||||
const int sobel_weights_1[3][3] = { {1,2,1},
|
||||
{0,0,0},
|
||||
{-1,-2,-1}};
|
||||
const int sobel_weights_2[3][3] = { {-1,0,1},
|
||||
{-2,0,2},
|
||||
{-1,0,1}};
|
||||
//Sobel weighting masks
|
||||
const int sobel_weights_1[3][3] = { {1, 2, 1},
|
||||
{0, 0, 0},
|
||||
{-1, -2, -1}
|
||||
};
|
||||
const int sobel_weights_2[3][3] = { {-1, 0, 1},
|
||||
{-2, 0, 2},
|
||||
{-1, 0, 1}
|
||||
};
|
||||
|
||||
sobel_1=0;
|
||||
sobel_2=0;
|
||||
for (i=-1;i<2;i++){
|
||||
for(j=-1; j<2; j++){
|
||||
//No need to check if inside canvas, getpixel does it for us.
|
||||
SDL_GetRGB(api->getpixel(last, x+i, y+j), last->format, &r1, &g1, &b1);
|
||||
grey = sharpen_grey(r1,g1,b1);
|
||||
sobel_1 += grey * sobel_weights_1[i+1][j+1];
|
||||
sobel_2 += grey * sobel_weights_2[i+1][j+1];
|
||||
}
|
||||
}
|
||||
|
||||
temp = sqrt(sobel_1*sobel_1 + sobel_2*sobel_2);
|
||||
temp = (temp/1443)*255.0;
|
||||
sobel_1 = 0;
|
||||
sobel_2 = 0;
|
||||
for (i = -1; i < 2; i++)
|
||||
{
|
||||
for (j = -1; j < 2; j++)
|
||||
{
|
||||
//No need to check if inside canvas, getpixel does it for us.
|
||||
SDL_GetRGB(api->getpixel(last, x + i, y + j), last->format, &r1, &g1, &b1);
|
||||
grey = sharpen_grey(r1, g1, b1);
|
||||
sobel_1 += grey * sobel_weights_1[i + 1][j + 1];
|
||||
sobel_2 += grey * sobel_weights_2[i + 1][j + 1];
|
||||
}
|
||||
}
|
||||
|
||||
// set image to white where edge value is below 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){
|
||||
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){
|
||||
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),
|
||||
clamp(0.0, b1 + SHARPEN * temp, 255.0)));
|
||||
}
|
||||
temp = sqrt(sobel_1 * sobel_1 + sobel_2 * sobel_2);
|
||||
temp = (temp / 1443) * 255.0;
|
||||
|
||||
// set image to white where edge value is below THRESHOLD
|
||||
if (which == TOOL_TRACE)
|
||||
{
|
||||
if (temp < THRESHOLD)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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),
|
||||
clamp(0.0, b1 + SHARPEN * temp, 255.0)));
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
// magic_api * api = (magic_api *) ptr;
|
||||
|
||||
int x,y;
|
||||
int x, y;
|
||||
|
||||
for (y = 0; y < last->h; y++){
|
||||
for (x=0; x < last->w; x++){
|
||||
do_sharpen_pixel(ptr, which, canvas, last, x, y);
|
||||
}
|
||||
}
|
||||
for (y = 0; y < last->h; y++)
|
||||
{
|
||||
for (x = 0; x < last->w; x++)
|
||||
{
|
||||
do_sharpen_pixel(ptr, which, canvas, last, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//do the effect for the brush
|
||||
static void do_sharpen_brush(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y){
|
||||
static void do_sharpen_brush(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
|
||||
{
|
||||
int xx, yy;
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
|
||||
for (yy = y - sharpen_RADIUS; yy < y + sharpen_RADIUS; yy++)
|
||||
{
|
||||
for (xx = x - sharpen_RADIUS; xx < x + sharpen_RADIUS; xx++)
|
||||
{
|
||||
if (api->in_circle(xx - x, yy - y, sharpen_RADIUS) &&
|
||||
!api->touched(xx, yy))
|
||||
{
|
||||
do_sharpen_pixel(api, which, canvas, last, xx, yy);
|
||||
}
|
||||
for (xx = x - sharpen_RADIUS; xx < x + sharpen_RADIUS; xx++)
|
||||
{
|
||||
if (api->in_circle(xx - x, yy - y, sharpen_RADIUS) && !api->touched(xx, yy))
|
||||
{
|
||||
do_sharpen_pixel(api, which, canvas, last, xx, yy);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Affect the canvas on drag:
|
||||
void sharpen_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect){
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
|
||||
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_sharpen_brush);
|
||||
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_sharpen_brush);
|
||||
|
||||
api->playsound(sharpen_snd_effect[which], (x * 255) / canvas->w, 255);
|
||||
|
||||
if (ox > x) { int tmp = ox; ox = x; x = tmp; }
|
||||
if (oy > y) { int tmp = oy; oy = y; y = tmp; }
|
||||
if (ox > x)
|
||||
{
|
||||
int tmp = ox;
|
||||
|
||||
ox = x;
|
||||
x = tmp;
|
||||
}
|
||||
if (oy > y)
|
||||
{
|
||||
int tmp = oy;
|
||||
|
||||
oy = y;
|
||||
y = tmp;
|
||||
}
|
||||
|
||||
update_rect->x = ox - sharpen_RADIUS;
|
||||
update_rect->y = oy - sharpen_RADIUS;
|
||||
|
|
@ -265,41 +296,46 @@ 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{
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
do_sharpen_full(api, canvas, last, which);
|
||||
api->playsound(sharpen_snd_effect[which], 128, 255);
|
||||
}
|
||||
else
|
||||
{
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
do_sharpen_full(api, canvas, last, which);
|
||||
api->playsound(sharpen_snd_effect[which], 128, 255);
|
||||
}
|
||||
}
|
||||
|
||||
// Affect the canvas on release:
|
||||
void sharpen_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)
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
// No setup happened:
|
||||
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){
|
||||
Mix_FreeChunk(sharpen_snd_effect[i]);
|
||||
}
|
||||
}
|
||||
//Clean up sounds
|
||||
int i;
|
||||
|
||||
for (i = 0; i < sharpen_NUM_TOOLS; i++)
|
||||
{
|
||||
if (sharpen_snd_effect[i] != NULL)
|
||||
{
|
||||
Mix_FreeChunk(sharpen_snd_effect[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Record the color from Tux Paint:
|
||||
void sharpen_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
|
||||
void sharpen_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
|
||||
Uint8 b ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -309,15 +345,17 @@ int sharpen_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUT
|
|||
return 0;
|
||||
}
|
||||
|
||||
void sharpen_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void sharpen_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void sharpen_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void sharpen_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
int sharpen_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_FULLSCREEN|MODE_PAINT);
|
||||
return (MODE_FULLSCREEN | MODE_PAINT);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,29 +38,25 @@
|
|||
/* Our globals: */
|
||||
|
||||
static int shift_x, shift_y;
|
||||
static Mix_Chunk * shift_snd;
|
||||
static Mix_Chunk *shift_snd;
|
||||
|
||||
|
||||
/* Local function prototypes: */
|
||||
|
||||
static void shift_doit(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect, int crosshairs);
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect, int crosshairs);
|
||||
Uint32 shift_api_version(void);
|
||||
int shift_init(magic_api * api);
|
||||
int shift_get_tool_count(magic_api * api);
|
||||
SDL_Surface * shift_get_icon(magic_api * api, int which);
|
||||
char * shift_get_name(magic_api * api, int which);
|
||||
char * shift_get_description(magic_api * api, int which, int mode);
|
||||
SDL_Surface *shift_get_icon(magic_api * api, int which);
|
||||
char *shift_get_name(magic_api * api, int which);
|
||||
char *shift_get_description(magic_api * api, int which, int mode);
|
||||
void shift_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
void shift_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void shift_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void shift_shutdown(magic_api * api);
|
||||
void shift_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
int shift_requires_colors(magic_api * api, int which);
|
||||
|
|
@ -71,7 +67,10 @@ int shift_modes(magic_api * api, int which);
|
|||
|
||||
|
||||
|
||||
Uint32 shift_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
Uint32 shift_api_version(void)
|
||||
{
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
|
||||
// No setup required:
|
||||
|
|
@ -79,57 +78,54 @@ int shift_init(magic_api * api)
|
|||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/shift.ogg",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/shift.ogg", api->data_directory);
|
||||
shift_snd = Mix_LoadWAV(fname);
|
||||
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
// We have multiple tools:
|
||||
int shift_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
// Load our icons:
|
||||
SDL_Surface * shift_get_icon(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
SDL_Surface *shift_get_icon(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/shift.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/shift.png", api->data_directory);
|
||||
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our names, localized:
|
||||
char * shift_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
char *shift_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(strdup(gettext_noop("Shift")));
|
||||
return (strdup(gettext_noop("Shift")));
|
||||
}
|
||||
|
||||
// Return our descriptions, localized:
|
||||
char * shift_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
||||
char *shift_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(strdup(gettext_noop("Click and drag to shift your picture around on the canvas.")));
|
||||
return (strdup(gettext_noop("Click and drag to shift your picture around on the canvas.")));
|
||||
}
|
||||
|
||||
|
||||
// Affect the canvas on drag:
|
||||
void shift_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
if (ox == x && oy == y)
|
||||
return; /* No-op */
|
||||
return; /* No-op */
|
||||
|
||||
shift_doit(api, which, canvas, last, ox, oy, x, y, update_rect, 1);
|
||||
}
|
||||
|
||||
static void shift_doit(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, int x, int y,
|
||||
SDL_Rect * update_rect, int crosshairs)
|
||||
SDL_Surface * last, int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, int x, int y,
|
||||
SDL_Rect * update_rect, int crosshairs)
|
||||
{
|
||||
SDL_Rect dest;
|
||||
int dx, dy;
|
||||
|
|
@ -159,123 +155,123 @@ static void shift_doit(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNU
|
|||
|
||||
|
||||
if (dy > 0)
|
||||
{
|
||||
if (dx > 0)
|
||||
{
|
||||
/* Top Left */
|
||||
if (dx > 0)
|
||||
{
|
||||
/* Top Left */
|
||||
|
||||
dest.x = dx - canvas->w;
|
||||
dest.x = dx - canvas->w;
|
||||
dest.y = dy - canvas->h;
|
||||
|
||||
SDL_BlitSurface(last, NULL, canvas, &dest);
|
||||
}
|
||||
|
||||
|
||||
/* Top */
|
||||
|
||||
dest.x = dx;
|
||||
dest.y = dy - canvas->h;
|
||||
|
||||
SDL_BlitSurface(last, NULL, canvas, &dest);
|
||||
|
||||
|
||||
if (dx < 0)
|
||||
{
|
||||
/* Top Right */
|
||||
|
||||
dest.x = dx + canvas->w;
|
||||
dest.y = dy - canvas->h;
|
||||
|
||||
SDL_BlitSurface(last, NULL, canvas, &dest);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Top */
|
||||
|
||||
dest.x = dx;
|
||||
dest.y = dy - canvas->h;
|
||||
|
||||
SDL_BlitSurface(last, NULL, canvas, &dest);
|
||||
|
||||
|
||||
if (dx < 0)
|
||||
{
|
||||
/* Top Right */
|
||||
|
||||
dest.x = dx + canvas->w;
|
||||
dest.y = dy - canvas->h;
|
||||
|
||||
SDL_BlitSurface(last, NULL, canvas, &dest);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (dx > 0)
|
||||
{
|
||||
/* Left */
|
||||
{
|
||||
/* Left */
|
||||
|
||||
dest.x = dx - canvas->w;
|
||||
dest.y = dy;
|
||||
dest.x = dx - canvas->w;
|
||||
dest.y = dy;
|
||||
|
||||
SDL_BlitSurface(last, NULL, canvas, &dest);
|
||||
}
|
||||
SDL_BlitSurface(last, NULL, canvas, &dest);
|
||||
}
|
||||
|
||||
if (dx < 0)
|
||||
{
|
||||
/* Right */
|
||||
{
|
||||
/* Right */
|
||||
|
||||
dest.x = dx + canvas->w;
|
||||
dest.y = dy;
|
||||
dest.x = dx + canvas->w;
|
||||
dest.y = dy;
|
||||
|
||||
SDL_BlitSurface(last, NULL, canvas, &dest);
|
||||
}
|
||||
SDL_BlitSurface(last, NULL, canvas, &dest);
|
||||
}
|
||||
|
||||
|
||||
if (dy < 0)
|
||||
{
|
||||
if (dx > 0)
|
||||
{
|
||||
/* Bottom Left */
|
||||
if (dx > 0)
|
||||
{
|
||||
/* Bottom Left */
|
||||
|
||||
dest.x = dx - canvas->w;
|
||||
dest.x = dx - canvas->w;
|
||||
dest.y = dy + canvas->h;
|
||||
|
||||
SDL_BlitSurface(last, NULL, canvas, &dest);
|
||||
}
|
||||
|
||||
|
||||
/* Bottom */
|
||||
|
||||
dest.x = dx;
|
||||
dest.y = dy + canvas->h;
|
||||
|
||||
SDL_BlitSurface(last, NULL, canvas, &dest);
|
||||
|
||||
|
||||
if (dx < 0)
|
||||
{
|
||||
/* Bottom Right */
|
||||
|
||||
dest.x = dx + canvas->w;
|
||||
dest.y = dy + canvas->h;
|
||||
|
||||
SDL_BlitSurface(last, NULL, canvas, &dest);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Bottom */
|
||||
|
||||
dest.x = dx;
|
||||
dest.y = dy + canvas->h;
|
||||
|
||||
SDL_BlitSurface(last, NULL, canvas, &dest);
|
||||
|
||||
|
||||
if (dx < 0)
|
||||
{
|
||||
/* Bottom Right */
|
||||
|
||||
dest.x = dx + canvas->w;
|
||||
dest.y = dy + canvas->h;
|
||||
|
||||
SDL_BlitSurface(last, NULL, canvas, &dest);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (crosshairs)
|
||||
{
|
||||
dest.x = (canvas->w / 2) - 1;
|
||||
dest.y = 0;
|
||||
dest.w = 3;
|
||||
dest.h = canvas->h;
|
||||
{
|
||||
dest.x = (canvas->w / 2) - 1;
|
||||
dest.y = 0;
|
||||
dest.w = 3;
|
||||
dest.h = canvas->h;
|
||||
|
||||
SDL_FillRect(canvas, &dest, SDL_MapRGB(canvas->format, 255, 255, 255));
|
||||
SDL_FillRect(canvas, &dest, SDL_MapRGB(canvas->format, 255, 255, 255));
|
||||
|
||||
dest.x = 0;
|
||||
dest.y = (canvas->h / 2) - 1;
|
||||
dest.w = canvas->w;
|
||||
dest.h = 3;
|
||||
dest.x = 0;
|
||||
dest.y = (canvas->h / 2) - 1;
|
||||
dest.w = canvas->w;
|
||||
dest.h = 3;
|
||||
|
||||
SDL_FillRect(canvas, &dest, SDL_MapRGB(canvas->format, 255, 255, 255));
|
||||
SDL_FillRect(canvas, &dest, SDL_MapRGB(canvas->format, 255, 255, 255));
|
||||
|
||||
|
||||
dest.x = canvas->w / 2;
|
||||
dest.y = 0;
|
||||
dest.w = 1;
|
||||
dest.h = canvas->h;
|
||||
dest.x = canvas->w / 2;
|
||||
dest.y = 0;
|
||||
dest.w = 1;
|
||||
dest.h = canvas->h;
|
||||
|
||||
SDL_FillRect(canvas, &dest, SDL_MapRGB(canvas->format, 0, 0, 0));
|
||||
SDL_FillRect(canvas, &dest, SDL_MapRGB(canvas->format, 0, 0, 0));
|
||||
|
||||
dest.x = 0;
|
||||
dest.y = canvas->h / 2;
|
||||
dest.w = canvas->w;
|
||||
dest.h = 1;
|
||||
dest.x = 0;
|
||||
dest.y = canvas->h / 2;
|
||||
dest.w = canvas->w;
|
||||
dest.h = 1;
|
||||
|
||||
SDL_FillRect(canvas, &dest, SDL_MapRGB(canvas->format, 0, 0, 0));
|
||||
}
|
||||
SDL_FillRect(canvas, &dest, SDL_MapRGB(canvas->format, 0, 0, 0));
|
||||
}
|
||||
|
||||
|
||||
/* Update everything! */
|
||||
|
|
@ -290,19 +286,17 @@ 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;
|
||||
|
||||
|
||||
shift_doit(api, which, canvas, last, x, y, x, y, update_rect, 1);
|
||||
}
|
||||
|
||||
// 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();
|
||||
|
|
@ -318,7 +312,7 @@ void shift_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
|||
|
||||
// Record the color from Tux Paint:
|
||||
void shift_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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -328,15 +322,17 @@ int shift_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_
|
|||
return 0;
|
||||
}
|
||||
|
||||
void shift_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void shift_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void shift_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void shift_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
int shift_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_PAINT_WITH_PREVIEW);
|
||||
return (MODE_PAINT_WITH_PREVIEW);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,25 +37,21 @@
|
|||
|
||||
/* Our globals: */
|
||||
|
||||
static Mix_Chunk * smudge_snd;
|
||||
static Mix_Chunk *smudge_snd;
|
||||
static Uint8 smudge_r, smudge_g, smudge_b;
|
||||
|
||||
int smudge_init(magic_api * api);
|
||||
Uint32 smudge_api_version(void);
|
||||
SDL_Surface * smudge_get_icon(magic_api * api, int which);
|
||||
char * smudge_get_name(magic_api * api, int which);
|
||||
char * smudge_get_description(magic_api * api, int which, int mode);
|
||||
static void do_smudge(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y);
|
||||
SDL_Surface *smudge_get_icon(magic_api * api, int which);
|
||||
char *smudge_get_name(magic_api * api, int which);
|
||||
char *smudge_get_description(magic_api * api, int which, int mode);
|
||||
static void do_smudge(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||
void smudge_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
void smudge_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void smudge_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void smudge_shutdown(magic_api * api);
|
||||
void smudge_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
int smudge_requires_colors(magic_api * api, int which);
|
||||
|
|
@ -69,121 +65,126 @@ int smudge_init(magic_api * api)
|
|||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/smudge.wav",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/smudge.wav", api->data_directory);
|
||||
smudge_snd = Mix_LoadWAV(fname);
|
||||
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
Uint32 smudge_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
Uint32 smudge_api_version(void)
|
||||
{
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
// We have multiple tools:
|
||||
int smudge_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(2);
|
||||
return (2);
|
||||
}
|
||||
|
||||
// Load our icons:
|
||||
SDL_Surface * smudge_get_icon(magic_api * api, int which)
|
||||
SDL_Surface *smudge_get_icon(magic_api * api, int which)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
if (which == 0)
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/smudge.png",
|
||||
api->data_directory);
|
||||
else /* if (which == 1) */
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/wetpaint.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);
|
||||
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our names, localized:
|
||||
char * smudge_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
|
||||
char *smudge_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
|
||||
{
|
||||
if (which == 0)
|
||||
return(strdup(gettext_noop("Smudge")));
|
||||
else /* if (which == 1) */
|
||||
return(strdup(gettext_noop("Wet Paint")));
|
||||
return (strdup(gettext_noop("Smudge")));
|
||||
else /* if (which == 1) */
|
||||
return (strdup(gettext_noop("Wet Paint")));
|
||||
}
|
||||
|
||||
// Return our descriptions, localized:
|
||||
char * smudge_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
|
||||
char *smudge_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
|
||||
{
|
||||
if (which == 0)
|
||||
return(strdup(gettext_noop("Click and drag the mouse around to smudge the picture.")));
|
||||
else /* if (which == 1) */
|
||||
return(strdup(gettext_noop("Click and drag the mouse around to draw with wet, smudgy paint.")));
|
||||
return (strdup(gettext_noop("Click and drag the mouse around to smudge the picture.")));
|
||||
else /* if (which == 1) */
|
||||
return (strdup(gettext_noop("Click and drag the mouse around to draw with wet, smudgy paint.")));
|
||||
}
|
||||
|
||||
// Do the effect:
|
||||
|
||||
static void do_smudge(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y)
|
||||
static void do_smudge(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
static double state[32][32][3];
|
||||
unsigned i = 32 * 32;
|
||||
double rate = api->button_down() ? 0.5 : 0.0;
|
||||
double rate = api->button_down()? 0.5 : 0.0;
|
||||
Uint8 r, g, b;
|
||||
int xx, yy, strength;
|
||||
|
||||
if (which == 1)
|
||||
{
|
||||
/* Wet paint */
|
||||
for (yy = -8; yy < 8; yy++)
|
||||
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);
|
||||
//strength = (abs(xx * yy) / 8) + 6;
|
||||
strength = (abs(xx * yy) / 8) + 1;
|
||||
api->putpixel(canvas, x + xx, y +yy, SDL_MapRGB(canvas->format,
|
||||
(smudge_r + r * strength) / (strength + 1),
|
||||
(smudge_g + g * strength) / (strength + 1),
|
||||
(smudge_b + b * strength) / (strength + 1)));
|
||||
}
|
||||
}
|
||||
{
|
||||
/* Wet paint */
|
||||
for (yy = -8; yy < 8; yy++)
|
||||
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);
|
||||
//strength = (abs(xx * yy) / 8) + 6;
|
||||
strength = (abs(xx * yy) / 8) + 1;
|
||||
api->putpixel(canvas, x + xx, y + yy, SDL_MapRGB(canvas->format,
|
||||
(smudge_r + r * strength) / (strength + 1),
|
||||
(smudge_g + g * strength) / (strength + 1),
|
||||
(smudge_b + b * strength) / (strength + 1)));
|
||||
}
|
||||
}
|
||||
|
||||
while (i--)
|
||||
{
|
||||
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
|
||||
{
|
||||
int iy = i >> 5;
|
||||
int ix = i & 0x1f;
|
||||
|
||||
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);
|
||||
// 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
|
||||
|
||||
// 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])));
|
||||
}
|
||||
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])));
|
||||
}
|
||||
}
|
||||
|
||||
// Affect the canvas on drag:
|
||||
void smudge_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_smudge);
|
||||
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_smudge);
|
||||
|
||||
api->playsound(smudge_snd, (x * 255) / canvas->w, 255);
|
||||
|
||||
if (ox > x) { int tmp = ox; ox = x; x = tmp; }
|
||||
if (oy > y) { int tmp = oy; oy = y; y = tmp; }
|
||||
if (ox > x)
|
||||
{
|
||||
int tmp = ox;
|
||||
|
||||
ox = x;
|
||||
x = tmp;
|
||||
}
|
||||
if (oy > y)
|
||||
{
|
||||
int tmp = oy;
|
||||
|
||||
oy = y;
|
||||
y = tmp;
|
||||
}
|
||||
|
||||
update_rect->x = ox - 16;
|
||||
update_rect->y = oy - 16;
|
||||
|
|
@ -193,16 +194,15 @@ 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);
|
||||
}
|
||||
|
||||
// Affect the canvas on click:
|
||||
void smudge_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)
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -226,19 +226,21 @@ int smudge_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE
|
|||
{
|
||||
if (which == 0)
|
||||
return 0;
|
||||
else /* if (which == 1) */
|
||||
else /* if (which == 1) */
|
||||
return 1;
|
||||
}
|
||||
|
||||
void smudge_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void smudge_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void smudge_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void smudge_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
int smudge_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_PAINT);
|
||||
return (MODE_PAINT);
|
||||
}
|
||||
|
|
|
|||
221
magic/src/snow.c
221
magic/src/snow.c
|
|
@ -45,30 +45,34 @@
|
|||
|
||||
static const int snow_AMOUNT = 400;
|
||||
static const int snow_RADIUS = 5;
|
||||
static SDL_Surface * snow_flake1;
|
||||
static SDL_Surface * snow_flake2;
|
||||
static SDL_Surface *snow_flake1;
|
||||
static SDL_Surface *snow_flake2;
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
TOOL_SNOWBALL,
|
||||
TOOL_SNOWFLAKE,
|
||||
snow_NUM_TOOLS
|
||||
snow_NUM_TOOLS
|
||||
};
|
||||
|
||||
static Mix_Chunk * snow_snd_effect[snow_NUM_TOOLS];
|
||||
static Mix_Chunk *snow_snd_effect[snow_NUM_TOOLS];
|
||||
|
||||
const char * snow_snd_filenames[snow_NUM_TOOLS] = {
|
||||
const char *snow_snd_filenames[snow_NUM_TOOLS] = {
|
||||
"snowball.ogg",
|
||||
"snowflake.ogg",
|
||||
};
|
||||
const char * snow_icon_filenames[snow_NUM_TOOLS] = {
|
||||
|
||||
const char *snow_icon_filenames[snow_NUM_TOOLS] = {
|
||||
"snowball.png",
|
||||
"snowflake.png",
|
||||
};
|
||||
const char * snow_names[snow_NUM_TOOLS] = {
|
||||
|
||||
const char *snow_names[snow_NUM_TOOLS] = {
|
||||
gettext_noop("Snow Ball"),
|
||||
gettext_noop("Snow Flake"),
|
||||
};
|
||||
const char * snow_descs[snow_NUM_TOOLS] = {
|
||||
|
||||
const char *snow_descs[snow_NUM_TOOLS] = {
|
||||
gettext_noop("Click to add snow balls to your picture."),
|
||||
gettext_noop("Click to add snow flakes to your picture."),
|
||||
};
|
||||
|
|
@ -76,156 +80,187 @@ const char * snow_descs[snow_NUM_TOOLS] = {
|
|||
Uint32 snow_api_version(void);
|
||||
int snow_init(magic_api * api);
|
||||
int snow_get_tool_count(magic_api * api);
|
||||
SDL_Surface * snow_get_icon(magic_api * api, int which);
|
||||
char * snow_get_name(magic_api * api, int which);
|
||||
char * snow_get_description(magic_api * api, int which);
|
||||
static void do_snow(void * ptr,SDL_Surface * canvas, SDL_Surface * last, int which, int snowAmount);
|
||||
SDL_Surface *snow_get_icon(magic_api * api, int which);
|
||||
char *snow_get_name(magic_api * api, int which);
|
||||
char *snow_get_description(magic_api * api, int which);
|
||||
static void do_snow(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int which, int snowAmount);
|
||||
void snow_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
void snow_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
|
||||
void snow_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void snow_shutdown(magic_api * api);
|
||||
void snow_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
int snow_requires_colors(magic_api * api, int which);
|
||||
void snow_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
void snow_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
int snow_modes(magic_api * api, int which);
|
||||
Uint32 snow_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
Uint32 snow_api_version(void)
|
||||
{
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
//Load sounds
|
||||
int snow_init(magic_api * api){
|
||||
int snow_init(magic_api * api)
|
||||
{
|
||||
|
||||
int i;
|
||||
char fname[1024];
|
||||
|
||||
srand(time(0));
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/Snow_flake4.png", api->data_directory);
|
||||
snow_flake1 = IMG_Load(fname);
|
||||
if (snow_flake1==NULL){
|
||||
return(0);
|
||||
}
|
||||
if (snow_flake1 == NULL)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/Snow_flake5.png", api->data_directory);
|
||||
snow_flake2 = IMG_Load(fname);
|
||||
if (snow_flake2==NULL){
|
||||
return(0);
|
||||
}
|
||||
if (snow_flake2 == NULL)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (snow_flake2==NULL){printf("meh\n");}
|
||||
for (i = 0; i < snow_NUM_TOOLS; i++){
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/%s", api->data_directory, snow_snd_filenames[i]);
|
||||
snow_snd_effect[i] = Mix_LoadWAV(fname);
|
||||
}
|
||||
return(1);
|
||||
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){
|
||||
return(snow_NUM_TOOLS);
|
||||
int snow_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return (snow_NUM_TOOLS);
|
||||
}
|
||||
|
||||
// Load our icons:
|
||||
SDL_Surface * snow_get_icon(magic_api * api, int which){
|
||||
SDL_Surface *snow_get_icon(magic_api * api, int which)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, snow_icon_filenames[which]);
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our names, localized:
|
||||
char * snow_get_name(magic_api * api ATTRIBUTE_UNUSED, int which){
|
||||
return(strdup(gettext_noop(snow_names[which])));
|
||||
char *snow_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
|
||||
{
|
||||
return (strdup(gettext_noop(snow_names[which])));
|
||||
}
|
||||
|
||||
// Return our descriptions, localized:
|
||||
char * snow_get_description(magic_api * api ATTRIBUTE_UNUSED, int which){
|
||||
return(strdup(gettext_noop(snow_descs[which])));
|
||||
char *snow_get_description(magic_api * api ATTRIBUTE_UNUSED, int which)
|
||||
{
|
||||
return (strdup(gettext_noop(snow_descs[which])));
|
||||
}
|
||||
|
||||
// Do the effect:
|
||||
static void do_snow(void * ptr,SDL_Surface * canvas, SDL_Surface * last, int which, int snowAmount){
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
static void do_snow(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int which, int snowAmount)
|
||||
{
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
|
||||
int i,x,y,centre_x,centre_y;
|
||||
Uint8 r,g,b;
|
||||
int i, x, y, centre_x, centre_y;
|
||||
Uint8 r, g, b;
|
||||
SDL_Rect dest;
|
||||
|
||||
for(i=0; i<snowAmount; i++){
|
||||
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)){
|
||||
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));
|
||||
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))
|
||||
{
|
||||
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)
|
||||
{
|
||||
dest.x = centre_x;
|
||||
dest.y = centre_y;
|
||||
if (rand() % 2 == 0)
|
||||
{
|
||||
SDL_BlitSurface(snow_flake1, NULL, canvas, &dest);
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_BlitSurface(snow_flake2, NULL, canvas, &dest);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(which == TOOL_SNOWFLAKE){
|
||||
dest.x = centre_x;
|
||||
dest.y = centre_y;
|
||||
if (rand()%2==0){
|
||||
SDL_BlitSurface(snow_flake1, NULL, canvas, &dest);
|
||||
}else {
|
||||
SDL_BlitSurface(snow_flake2, NULL, canvas, &dest);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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){
|
||||
// No-op
|
||||
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){
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
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;
|
||||
update_rect->h = canvas->h;
|
||||
|
||||
do_snow(api, canvas, last, which, snow_AMOUNT);
|
||||
|
||||
do_snow(api, canvas, last, which, snow_AMOUNT);
|
||||
api->playsound(snow_snd_effect[which], 128, 255);
|
||||
}
|
||||
|
||||
// Affect the canvas on release:
|
||||
void snow_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)
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
// No setup happened:
|
||||
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){
|
||||
Mix_FreeChunk(snow_snd_effect[i]);
|
||||
}
|
||||
}
|
||||
if (snow_flake1 != NULL){
|
||||
SDL_FreeSurface(snow_flake1);
|
||||
}
|
||||
if (snow_flake2 != NULL){
|
||||
SDL_FreeSurface(snow_flake2);
|
||||
}
|
||||
//Clean up sounds
|
||||
int i;
|
||||
|
||||
for (i = 0; i < snow_NUM_TOOLS; i++)
|
||||
{
|
||||
if (snow_snd_effect[i] != NULL)
|
||||
{
|
||||
Mix_FreeChunk(snow_snd_effect[i]);
|
||||
}
|
||||
}
|
||||
if (snow_flake1 != NULL)
|
||||
{
|
||||
SDL_FreeSurface(snow_flake1);
|
||||
}
|
||||
if (snow_flake2 != NULL)
|
||||
{
|
||||
SDL_FreeSurface(snow_flake2);
|
||||
}
|
||||
}
|
||||
|
||||
// Record the color from Tux Paint:
|
||||
void snow_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
|
||||
void snow_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
|
||||
Uint8 b ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -235,15 +270,17 @@ int snow_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_U
|
|||
return 0;
|
||||
}
|
||||
|
||||
void snow_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED){
|
||||
void snow_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void snow_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void snow_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
int snow_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_FULLSCREEN);
|
||||
return (MODE_FULLSCREEN);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,107 +3,107 @@
|
|||
#include "SDL_mixer.h"
|
||||
|
||||
unsigned int img_w, img_h;
|
||||
static Uint8 string_r, string_g, string_b;
|
||||
static Uint8 string_r, string_g, string_b;
|
||||
static int string_ox, string_oy;
|
||||
static int string_vertex_x, string_vertex_y, string_vertex_done, string_vertex_distance;
|
||||
static SDL_Surface * canvas_backup;
|
||||
enum string_tools{
|
||||
static SDL_Surface *canvas_backup;
|
||||
enum string_tools
|
||||
{
|
||||
STRING_TOOL_FULL_BY_OFFSET,
|
||||
STRING_TOOL_TRIANGLE,
|
||||
STRING_TOOL_ANGLE,
|
||||
STRING_NUMTOOLS};
|
||||
STRING_NUMTOOLS
|
||||
};
|
||||
|
||||
Mix_Chunk *string_snd[STRING_NUMTOOLS];
|
||||
|
||||
Mix_Chunk * string_snd[STRING_NUMTOOLS];
|
||||
// Custom function declarations
|
||||
|
||||
void string_callback(void * ptr, int which_tool,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
|
||||
void string_callback(void *ptr, int which_tool, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
|
||||
void string_draw_triangle(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
void string_draw_angle(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);
|
||||
void string_draw_triangle_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 * canvas, SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
void string_draw_angle_preview(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
void scale_xcoord(int * xcoord);
|
||||
void scale_ycoord(int * ycoord);
|
||||
void scale_coords(int * ox, int * oy, int * x, int * y);
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
void scale_xcoord(int *xcoord);
|
||||
void scale_ycoord(int *ycoord);
|
||||
void scale_coords(int *ox, int *oy, int *x, int *y);
|
||||
void string_draw_wrapper(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
void string_set_vertex(int x, int y);
|
||||
void compute_middle( int start_point, int end_point, int vertex, int * middle);
|
||||
void compute_middle(int start_point, int end_point, int vertex, int *middle);
|
||||
|
||||
|
||||
// Prototypes for required functions
|
||||
|
||||
void string_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
|
||||
|
||||
Uint32 string_api_version(void);
|
||||
int string_modes(magic_api * api, int which);
|
||||
void string_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
int string_get_tool_count(magic_api * api);
|
||||
SDL_Surface * string_get_icon(magic_api * api, int which);
|
||||
char * string_get_name(magic_api * api, int which);
|
||||
char * string_get_description(magic_api * api, int which, int mode);
|
||||
SDL_Surface *string_get_icon(magic_api * api, int which);
|
||||
char *string_get_name(magic_api * api, int which);
|
||||
char *string_get_description(magic_api * api, int which, int mode);
|
||||
int string_requires_colors(magic_api * api, int which);
|
||||
void string_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
|
||||
int string_init(magic_api * api);
|
||||
void string_shutdown(magic_api * api);
|
||||
void string_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * snapshot);
|
||||
void string_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * snapshot);
|
||||
void string_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
|
||||
|
||||
// Required functions
|
||||
|
||||
Uint32 string_api_version(void)
|
||||
{
|
||||
return(TP_MAGIC_API_VERSION);
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
int string_modes(__attribute__((unused)) magic_api * api, int which)
|
||||
int string_modes( __attribute__ ((unused)) magic_api * api, int which)
|
||||
{
|
||||
if (which == STRING_TOOL_FULL_BY_OFFSET)
|
||||
return(MODE_PAINT);
|
||||
if (which == STRING_TOOL_FULL_BY_OFFSET)
|
||||
return (MODE_PAINT);
|
||||
else
|
||||
return(MODE_PAINT_WITH_PREVIEW);
|
||||
return (MODE_PAINT_WITH_PREVIEW);
|
||||
}
|
||||
|
||||
void string_set_color(__attribute__((unused)) magic_api * api, Uint8 r, Uint8 g, Uint8 b)
|
||||
void string_set_color( __attribute__ ((unused)) magic_api * api, Uint8 r, Uint8 g, Uint8 b)
|
||||
{
|
||||
string_r=r;
|
||||
string_g=g;
|
||||
string_b=b;
|
||||
string_r = r;
|
||||
string_g = g;
|
||||
string_b = b;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int string_get_tool_count(__attribute__((unused)) magic_api * api)
|
||||
|
||||
int string_get_tool_count( __attribute__ ((unused)) magic_api * api)
|
||||
{
|
||||
return STRING_NUMTOOLS;
|
||||
}
|
||||
|
||||
SDL_Surface * string_get_icon(magic_api * api, int which)
|
||||
SDL_Surface *string_get_icon(magic_api * api, int which)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
switch (which)
|
||||
{
|
||||
case STRING_TOOL_FULL_BY_OFFSET:
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/string_art_full_by_offset.png", api->data_directory);
|
||||
break;
|
||||
case STRING_TOOL_TRIANGLE:
|
||||
case STRING_TOOL_TRIANGLE:
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/string_art_triangles.png", api->data_directory);
|
||||
break;
|
||||
case STRING_TOOL_ANGLE:
|
||||
|
|
@ -111,18 +111,19 @@ SDL_Surface * string_get_icon(magic_api * api, int which)
|
|||
break;
|
||||
}
|
||||
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
|
||||
char * string_get_name(__attribute__((unused)) magic_api * api, __attribute__((unused)) int which)
|
||||
char *string_get_name( __attribute__ ((unused)) magic_api * api, __attribute__ ((unused))
|
||||
int which)
|
||||
{
|
||||
switch (which)
|
||||
{
|
||||
case STRING_TOOL_FULL_BY_OFFSET:
|
||||
return strdup(gettext_noop("String edges"));
|
||||
break;
|
||||
case STRING_TOOL_TRIANGLE:
|
||||
case STRING_TOOL_TRIANGLE:
|
||||
return strdup(gettext_noop("String corner"));
|
||||
break;
|
||||
default:
|
||||
|
|
@ -130,13 +131,17 @@ 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:
|
||||
case STRING_TOOL_TRIANGLE:
|
||||
return strdup(gettext_noop("Click and drag to draw arrows made of string art."));
|
||||
break;
|
||||
default:
|
||||
|
|
@ -144,181 +149,192 @@ char * string_get_description(__attribute__((unused)) magic_api * api, int which
|
|||
}
|
||||
}
|
||||
|
||||
int string_requires_colors(__attribute__((unused)) magic_api * api, __attribute__((unused)) int which) { return 1;}
|
||||
int string_requires_colors( __attribute__ ((unused)) magic_api * api, __attribute__ ((unused))
|
||||
int which)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void string_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect)
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
int dx, dy;
|
||||
if (which==STRING_TOOL_TRIANGLE)
|
||||
string_draw_triangle((void *) api, which, canvas, snapshot, string_ox, string_oy, x, y, update_rect);
|
||||
if (which==STRING_TOOL_ANGLE)
|
||||
|
||||
if (which == STRING_TOOL_TRIANGLE)
|
||||
string_draw_triangle((void *)api, which, canvas, snapshot, string_ox, string_oy, x, y, update_rect);
|
||||
if (which == STRING_TOOL_ANGLE)
|
||||
{
|
||||
if(!string_vertex_done) // maybe we face small children, draw square angles aligned to the drag
|
||||
{
|
||||
dx=string_ox - x;
|
||||
dy=string_oy - y;
|
||||
y=y + dx;
|
||||
x=x - dy;
|
||||
}
|
||||
string_draw_angle((void *) api, which, canvas, snapshot, string_ox, string_oy, x, y, update_rect);
|
||||
if (!string_vertex_done) // maybe we face small children, draw square angles aligned to the drag
|
||||
{
|
||||
dx = string_ox - x;
|
||||
dy = string_oy - y;
|
||||
y = y + dx;
|
||||
x = x - dy;
|
||||
}
|
||||
string_draw_angle((void *)api, which, canvas, snapshot, string_ox, string_oy, x, y, update_rect);
|
||||
}
|
||||
}
|
||||
|
||||
int string_init(__attribute__((unused)) magic_api * api)
|
||||
int string_init( __attribute__ ((unused)) magic_api * api)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/string.ogg",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/string.ogg", api->data_directory);
|
||||
string_snd[STRING_TOOL_FULL_BY_OFFSET] = Mix_LoadWAV(fname);
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/string2.ogg",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/string2.ogg", api->data_directory);
|
||||
string_snd[STRING_TOOL_TRIANGLE] = Mix_LoadWAV(fname);
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/string3.ogg",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/string3.ogg", api->data_directory);
|
||||
string_snd[STRING_TOOL_ANGLE] = Mix_LoadWAV(fname);
|
||||
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
void string_shutdown(__attribute__((unused)) magic_api * api)
|
||||
void string_shutdown( __attribute__ ((unused)) magic_api * api)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
if (canvas_backup)
|
||||
if (canvas_backup)
|
||||
SDL_FreeSurface(canvas_backup);
|
||||
|
||||
while (i < STRING_NUMTOOLS)
|
||||
{
|
||||
if (string_snd[i] != NULL)
|
||||
Mix_FreeChunk(string_snd[i]);
|
||||
i ++;
|
||||
Mix_FreeChunk(string_snd[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void string_switchin(__attribute__((unused)) magic_api * api, __attribute__((unused)) int which, __attribute__((unused)) int mode, SDL_Surface * canvas, __attribute__((unused)) SDL_Surface * snapshot)
|
||||
void string_switchin( __attribute__ ((unused)) magic_api * api, __attribute__ ((unused))
|
||||
int which, __attribute__ ((unused))
|
||||
int mode, SDL_Surface * canvas, __attribute__ ((unused)) SDL_Surface * snapshot)
|
||||
{
|
||||
canvas_backup=SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h, canvas->format->BitsPerPixel,
|
||||
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
|
||||
canvas_backup = SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h, canvas->format->BitsPerPixel,
|
||||
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask,
|
||||
canvas->format->Amask);
|
||||
}
|
||||
|
||||
void string_switchout(__attribute__((unused)) magic_api * api, __attribute__((unused)) int which, __attribute__((unused)) int mode, __attribute__((unused)) SDL_Surface * canvas, __attribute__((unused)) SDL_Surface * snapshot)
|
||||
void string_switchout( __attribute__ ((unused)) magic_api * api, __attribute__ ((unused))
|
||||
int which, __attribute__ ((unused))
|
||||
int mode, __attribute__ ((unused)) SDL_Surface * canvas,
|
||||
__attribute__ ((unused)) SDL_Surface * snapshot)
|
||||
{
|
||||
SDL_FreeSurface(canvas_backup);
|
||||
canvas_backup=NULL;
|
||||
canvas_backup = NULL;
|
||||
}
|
||||
|
||||
// Interactivity functions
|
||||
|
||||
|
||||
void string_callback(void * ptr,__attribute__((unused)) int which,
|
||||
SDL_Surface * canvas,__attribute__((unused)) SDL_Surface * snapshot, int x, int y)
|
||||
void string_callback(void *ptr, __attribute__ ((unused))
|
||||
int which, SDL_Surface * canvas, __attribute__ ((unused)) SDL_Surface * snapshot, int x, int y)
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
api->putpixel(canvas, x, y, SDL_MapRGBA(canvas->format, string_r, string_g, string_b,255));
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
|
||||
api->putpixel(canvas, x, y, SDL_MapRGBA(canvas->format, string_r, string_g, string_b, 255));
|
||||
}
|
||||
|
||||
|
||||
void string_click(magic_api * api, int which,__attribute__((unused)) int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect)
|
||||
void string_click(magic_api * api, int which, __attribute__ ((unused))
|
||||
int mode, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
SDL_BlitSurface(canvas, NULL, canvas_backup, NULL);
|
||||
|
||||
string_ox=x;
|
||||
string_oy=y;
|
||||
string_vertex_distance=0;
|
||||
string_vertex_done=0;
|
||||
string_ox = x;
|
||||
string_oy = y;
|
||||
string_vertex_distance = 0;
|
||||
string_vertex_done = 0;
|
||||
string_drag(api, which, canvas, snapshot, x, y, x, y, update_rect);
|
||||
}
|
||||
|
||||
static void string_draw_full_by_offset(void * ptr, __attribute__((unused)) int which, SDL_Surface * canvas, __attribute__((unused)) SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect)
|
||||
static void string_draw_full_by_offset(void *ptr, __attribute__ ((unused))
|
||||
int which, SDL_Surface * canvas, __attribute__ ((unused)) SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
int u;
|
||||
int i;
|
||||
int o; //offset
|
||||
int o; //offset
|
||||
|
||||
// int n=y/5;
|
||||
int ** a;
|
||||
int **a;
|
||||
float step_w, step_h, aux;
|
||||
int side=(int)(y/3);
|
||||
int side = (int)(y / 3);
|
||||
|
||||
SDL_BlitSurface(snapshot,0,canvas,0);
|
||||
SDL_BlitSurface(snapshot, 0, canvas, 0);
|
||||
|
||||
if (side<3) side=3;
|
||||
if (side < 3)
|
||||
side = 3;
|
||||
|
||||
o=(int)(side*4*x/canvas->w);
|
||||
step_w=canvas->w/(float)side;
|
||||
step_h=canvas->h/(float)side;
|
||||
o = (int)(side * 4 * x / canvas->w);
|
||||
step_w = canvas->w / (float)side;
|
||||
step_h = canvas->h / (float)side;
|
||||
|
||||
a=malloc(sizeof(int*)*side*4*2);
|
||||
a = malloc(sizeof(int *) * side * 4 * 2);
|
||||
|
||||
for (i=0;i<side*4;i++)
|
||||
for (i = 0; i < side * 4; i++)
|
||||
{
|
||||
a[i]=malloc(sizeof(int*)*2);
|
||||
if (i<side)
|
||||
{
|
||||
a[i][0]= 0;
|
||||
aux=step_h*(float)i;
|
||||
a[i][1]= (int)aux;
|
||||
}
|
||||
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))
|
||||
{
|
||||
a[i][0]= canvas->w;
|
||||
a[i][1]= (int)(canvas->h - (float)((i%side)*step_h));
|
||||
}
|
||||
else
|
||||
if (i<(int)(side*4))
|
||||
{
|
||||
a[i][0]=(int)( canvas->w-((float)((i%side)*step_w)));
|
||||
a[i][1]= 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (i=0;i<side*4;i++)
|
||||
{
|
||||
u=(i+o)%(side*4);
|
||||
api->line((void *) api, which, canvas, snapshot,a[i][0],a[i][1],a[u][0],a[u][1],1, string_callback);
|
||||
a[i] = malloc(sizeof(int *) * 2);
|
||||
if (i < side)
|
||||
{
|
||||
a[i][0] = 0;
|
||||
aux = step_h * (float)i;
|
||||
a[i][1] = (int)aux;
|
||||
}
|
||||
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))
|
||||
{
|
||||
a[i][0] = canvas->w;
|
||||
a[i][1] = (int)(canvas->h - (float)((i % side) * step_h));
|
||||
}
|
||||
else if (i < (int)(side * 4))
|
||||
{
|
||||
a[i][0] = (int)(canvas->w - ((float)((i % side) * step_w)));
|
||||
a[i][1] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
for (i=0;i<side*4;i++)
|
||||
|
||||
for (i = 0; i < side * 4; i++)
|
||||
{
|
||||
free( a[i]);
|
||||
u = (i + o) % (side * 4);
|
||||
api->line((void *)api, which, canvas, snapshot, a[i][0], a[i][1], a[u][0], a[u][1], 1, string_callback);
|
||||
}
|
||||
|
||||
for (i = 0; i < side * 4; i++)
|
||||
{
|
||||
free(a[i]);
|
||||
}
|
||||
free(a);
|
||||
|
||||
update_rect->x=0;
|
||||
update_rect->y=0;
|
||||
update_rect->w=canvas->w;
|
||||
update_rect->h=canvas->h;
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
}
|
||||
|
||||
void scale_xcoord(int * xcoord)
|
||||
void scale_xcoord(int *xcoord)
|
||||
{
|
||||
if (*xcoord < string_ox) *xcoord=string_ox-(string_ox - *xcoord)*4;
|
||||
else *xcoord=string_ox+(*xcoord-string_ox)*4;
|
||||
if (*xcoord < string_ox)
|
||||
*xcoord = string_ox - (string_ox - *xcoord) * 4;
|
||||
else
|
||||
*xcoord = string_ox + (*xcoord - string_ox) * 4;
|
||||
}
|
||||
|
||||
void scale_ycoord(int * ycoord)
|
||||
void scale_ycoord(int *ycoord)
|
||||
{
|
||||
if (*ycoord < string_oy) *ycoord=string_oy-(string_oy - *ycoord)*4;
|
||||
else *ycoord=string_oy+(*ycoord-string_oy)*4;
|
||||
if (*ycoord < string_oy)
|
||||
*ycoord = string_oy - (string_oy - *ycoord) * 4;
|
||||
else
|
||||
*ycoord = string_oy + (*ycoord - string_oy) * 4;
|
||||
}
|
||||
|
||||
void scale_coords(int * ox, int * oy, int * x, int * y)
|
||||
void scale_coords(int *ox, int *oy, int *x, int *y)
|
||||
{
|
||||
scale_xcoord(ox);
|
||||
scale_xcoord(x);
|
||||
|
|
@ -326,161 +342,174 @@ void scale_coords(int * ox, int * oy, int * x, int * y)
|
|||
scale_ycoord(y);
|
||||
}
|
||||
|
||||
void compute_middle( int start_point, int end_point, int vertex, int * middle)
|
||||
void compute_middle(int start_point, int end_point, int vertex, int *middle)
|
||||
{
|
||||
*middle=min(start_point,end_point)+(max(start_point,end_point)-min(start_point,end_point))/2;
|
||||
*middle=min(*middle,vertex)+(max(*middle,vertex)-min(*middle,vertex))/2;
|
||||
*middle = min(start_point, end_point) + (max(start_point, end_point) - min(start_point, end_point)) / 2;
|
||||
*middle = min(*middle, vertex) + (max(*middle, vertex) - min(*middle, vertex)) / 2;
|
||||
}
|
||||
|
||||
void string_draw_triangle_preview(magic_api * api, int which,
|
||||
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)
|
||||
{
|
||||
int middle_x, middle_y;
|
||||
int w, h;
|
||||
scale_coords(&ox, &oy,&x, &y);
|
||||
w=max(string_ox,x)-min(string_ox,x);
|
||||
h=max(string_oy,y)-min(string_oy,y);
|
||||
|
||||
scale_coords(&ox, &oy, &x, &y);
|
||||
w = max(string_ox, x) - min(string_ox, x);
|
||||
h = max(string_oy, y) - min(string_oy, y);
|
||||
|
||||
/*
|
||||
This is enouth if you move the mouse slowly, but if you move the mouse fast,
|
||||
there are rests of old previews left around.
|
||||
update_rect->w=max(max(string_ox,x),max(ox,x))-min(min(string_ox,x),min(ox,x)) +80;
|
||||
update_rect->h=max(max(string_oy,y),max(oy,y))-min(min(string_oy,y),min(oy,y)) +80;
|
||||
update_rect->x=min(string_ox,x) -40;
|
||||
update_rect->y=min(string_oy,y) -40;
|
||||
*/
|
||||
update_rect->x=0;
|
||||
update_rect->y=0;
|
||||
update_rect->w=canvas->w;
|
||||
update_rect->h=canvas->h;
|
||||
SDL_BlitSurface(canvas_backup,update_rect,canvas,update_rect);
|
||||
This is enouth if you move the mouse slowly, but if you move the mouse fast,
|
||||
there are rests of old previews left around.
|
||||
update_rect->w=max(max(string_ox,x),max(ox,x))-min(min(string_ox,x),min(ox,x)) +80;
|
||||
update_rect->h=max(max(string_oy,y),max(oy,y))-min(min(string_oy,y),min(oy,y)) +80;
|
||||
update_rect->x=min(string_ox,x) -40;
|
||||
update_rect->y=min(string_oy,y) -40;
|
||||
*/
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
SDL_BlitSurface(canvas_backup, update_rect, canvas, update_rect);
|
||||
|
||||
compute_middle(x, string_ox, string_ox, &middle_x);
|
||||
compute_middle(y, string_oy, string_oy, &middle_y);
|
||||
|
||||
api->line((void *) api, which, canvas, snapshot, string_ox,string_oy, string_ox , y,1, string_callback);
|
||||
api->line((void *) api, which, canvas, snapshot, string_ox,string_oy, x , string_oy,1, string_callback);
|
||||
api->line((void *) api, which, canvas, snapshot, middle_x,middle_y, x , string_oy,1, string_callback);
|
||||
api->line((void *) api, which, canvas, snapshot, string_ox,y, middle_x , middle_y,1, string_callback);
|
||||
api->line((void *)api, which, canvas, snapshot, string_ox, string_oy, string_ox, y, 1, string_callback);
|
||||
api->line((void *)api, which, canvas, snapshot, string_ox, string_oy, x, string_oy, 1, string_callback);
|
||||
api->line((void *)api, which, canvas, snapshot, middle_x, middle_y, x, string_oy, 1, string_callback);
|
||||
api->line((void *)api, which, canvas, snapshot, string_ox, y, middle_x, middle_y, 1, string_callback);
|
||||
}
|
||||
|
||||
void string_draw_angle_preview(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, __attribute__((unused)) int ox, __attribute__ ((unused)) int oy, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
{
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, __attribute__ ((unused))
|
||||
int ox, __attribute__ ((unused))
|
||||
int oy, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
int w, h;
|
||||
int middle_x, middle_y;
|
||||
int dx, dy;
|
||||
w=max(string_ox,x)-min(string_ox,x);
|
||||
h=max(string_oy,y)-min(string_oy,y);
|
||||
|
||||
update_rect->x=0;
|
||||
update_rect->y=0;
|
||||
update_rect->w=canvas->w;
|
||||
update_rect->h=canvas->h;
|
||||
SDL_BlitSurface(canvas_backup,update_rect,canvas,update_rect);
|
||||
w = max(string_ox, x) - min(string_ox, x);
|
||||
h = max(string_oy, y) - min(string_oy, y);
|
||||
|
||||
api->line((void *) api, which, canvas, snapshot, string_ox,string_oy, string_vertex_x , string_vertex_y,1, string_callback);
|
||||
if(!string_vertex_done)
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
SDL_BlitSurface(canvas_backup, update_rect, canvas, update_rect);
|
||||
|
||||
api->line((void *)api, which, canvas, snapshot, string_ox, string_oy, string_vertex_x, string_vertex_y, 1,
|
||||
string_callback);
|
||||
if (!string_vertex_done)
|
||||
{
|
||||
// if(!string_vertex_done) // maybe we face small children, draw square angles aligned to the drag
|
||||
//{
|
||||
dx=string_ox - x;
|
||||
dy=string_oy - y;
|
||||
y=y + dx;
|
||||
x=x - dy;
|
||||
}
|
||||
dx = string_ox - x;
|
||||
dy = string_oy - y;
|
||||
y = y + dx;
|
||||
x = x - dy;
|
||||
}
|
||||
|
||||
compute_middle(string_ox, x, string_vertex_x, &middle_x);
|
||||
compute_middle(string_oy, y, string_vertex_y, &middle_y);
|
||||
compute_middle(string_ox, x, string_vertex_x, &middle_x);
|
||||
compute_middle(string_oy, y, string_vertex_y, &middle_y);
|
||||
|
||||
api->line((void *)api, which, canvas, snapshot, string_vertex_x, string_vertex_y, x, y, 1, string_callback);
|
||||
api->line((void *)api, which, canvas, snapshot, string_ox, string_oy, middle_x, middle_y, 1, string_callback);
|
||||
api->line((void *)api, which, canvas, snapshot, x, y, middle_x, middle_y, 1, string_callback);
|
||||
|
||||
api->line((void *) api, which, canvas, snapshot, string_vertex_x,string_vertex_y, x , y,1, string_callback);
|
||||
api->line((void *) api, which, canvas, snapshot, string_ox,string_oy, middle_x , middle_y,1, string_callback);
|
||||
api->line((void *) api, which, canvas, snapshot, x, y, middle_x , middle_y,1, string_callback);
|
||||
|
||||
}
|
||||
|
||||
void string_draw_angle(magic_api * api, __attribute__((unused)) int which,
|
||||
SDL_Surface * canvas, __attribute__((unused))SDL_Surface * snapshot, __attribute__ ((unused)) int ox, __attribute__ ((unused)) int oy, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
void string_draw_angle(magic_api * api, __attribute__ ((unused))
|
||||
int which,
|
||||
SDL_Surface * canvas, __attribute__ ((unused)) SDL_Surface * snapshot, __attribute__ ((unused))
|
||||
int ox, __attribute__ ((unused))
|
||||
int oy, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
float first_arm_step_x, first_arm_step_y, second_arm_step_x, second_arm_step_y;
|
||||
int i;
|
||||
int max_wh , steps;
|
||||
int max_separation=10;
|
||||
int max_wh, steps;
|
||||
int max_separation = 10;
|
||||
|
||||
update_rect->x=min(min(string_ox,string_vertex_x),x);
|
||||
update_rect->y=min(min(string_oy,string_vertex_y),y);
|
||||
update_rect->w=max(max(string_ox,string_vertex_x),x)-update_rect->x;
|
||||
update_rect->h=max(max(string_oy,string_vertex_y),y)-update_rect->y;
|
||||
SDL_BlitSurface(canvas_backup,update_rect,canvas,update_rect);
|
||||
update_rect->x = min(min(string_ox, string_vertex_x), x);
|
||||
update_rect->y = min(min(string_oy, string_vertex_y), y);
|
||||
update_rect->w = max(max(string_ox, string_vertex_x), x) - update_rect->x;
|
||||
update_rect->h = max(max(string_oy, string_vertex_y), y) - update_rect->y;
|
||||
SDL_BlitSurface(canvas_backup, update_rect, canvas, update_rect);
|
||||
|
||||
max_wh= max( max(max(string_ox,string_vertex_x),x)- min(min(string_vertex_x , x),string_ox) , max(max(string_oy , string_vertex_y),y)- min(min(string_vertex_y ,y),string_oy));
|
||||
max_wh =
|
||||
max(max(max(string_ox, string_vertex_x), x) - min(min(string_vertex_x, x), string_ox),
|
||||
max(max(string_oy, string_vertex_y), y) - min(min(string_vertex_y, y), string_oy));
|
||||
|
||||
steps=max_wh/max_separation;
|
||||
first_arm_step_x=(float)(string_ox-string_vertex_x)/(float)steps;
|
||||
first_arm_step_y=(float)(string_oy-string_vertex_y)/(float)steps;
|
||||
second_arm_step_x=(float)(string_vertex_x-x)/(float)steps;
|
||||
second_arm_step_y=(float)(string_vertex_y-y)/(float)steps;
|
||||
steps = max_wh / max_separation;
|
||||
first_arm_step_x = (float)(string_ox - string_vertex_x) / (float)steps;
|
||||
first_arm_step_y = (float)(string_oy - string_vertex_y) / (float)steps;
|
||||
second_arm_step_x = (float)(string_vertex_x - x) / (float)steps;
|
||||
second_arm_step_y = (float)(string_vertex_y - y) / (float)steps;
|
||||
|
||||
for (i=0;i<=steps;i++)
|
||||
for (i = 0; i <= steps; i++)
|
||||
{
|
||||
api->line((void *) api, 0, canvas, snapshot, string_ox-first_arm_step_x*i,string_oy-first_arm_step_y*i, string_vertex_x-second_arm_step_x*i,string_vertex_y-second_arm_step_y*i,1, string_callback);
|
||||
api->line((void *)api, 0, canvas, snapshot, string_ox - first_arm_step_x * i, string_oy - first_arm_step_y * i,
|
||||
string_vertex_x - second_arm_step_x * i, string_vertex_y - second_arm_step_y * i, 1, string_callback);
|
||||
}
|
||||
}
|
||||
|
||||
void string_draw_triangle(magic_api * api, __attribute__((unused)) int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
void string_draw_triangle(magic_api * api, __attribute__ ((unused))
|
||||
int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
{
|
||||
SDL_BlitSurface(canvas_backup,0,canvas,0);
|
||||
scale_coords(&ox, &oy,&x, &y);
|
||||
SDL_BlitSurface(canvas_backup, 0, canvas, 0);
|
||||
scale_coords(&ox, &oy, &x, &y);
|
||||
|
||||
string_vertex_x=string_ox;
|
||||
string_vertex_y=string_oy;
|
||||
string_ox=string_vertex_x;
|
||||
string_oy=y;
|
||||
y=string_vertex_y;
|
||||
string_vertex_x = string_ox;
|
||||
string_vertex_y = string_oy;
|
||||
string_ox = string_vertex_x;
|
||||
string_oy = y;
|
||||
y = string_vertex_y;
|
||||
|
||||
string_draw_angle((void *) api, which, canvas, snapshot, string_ox, string_oy, x, y, update_rect);
|
||||
string_draw_angle((void *)api, which, canvas, snapshot, string_ox, string_oy, x, y, update_rect);
|
||||
}
|
||||
|
||||
void string_draw_wrapper(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
{
|
||||
if (which==STRING_TOOL_FULL_BY_OFFSET)
|
||||
string_draw_full_by_offset((void *) api, which, canvas, snapshot, x, y, update_rect);
|
||||
else if (which==STRING_TOOL_TRIANGLE)
|
||||
string_draw_triangle_preview ((void *) api, which, canvas, snapshot, ox, oy, x, y, update_rect);
|
||||
else if (which==STRING_TOOL_ANGLE)
|
||||
string_draw_angle_preview ((void *) api, which, canvas, snapshot, ox, oy, x, y, update_rect);
|
||||
if (which == STRING_TOOL_FULL_BY_OFFSET)
|
||||
string_draw_full_by_offset((void *)api, which, canvas, snapshot, x, y, update_rect);
|
||||
else if (which == STRING_TOOL_TRIANGLE)
|
||||
string_draw_triangle_preview((void *)api, which, canvas, snapshot, ox, oy, x, y, update_rect);
|
||||
else if (which == STRING_TOOL_ANGLE)
|
||||
string_draw_angle_preview((void *)api, which, canvas, snapshot, ox, oy, x, y, update_rect);
|
||||
}
|
||||
|
||||
void string_set_vertex(int x, int y)
|
||||
{
|
||||
int dx, dy;
|
||||
if (string_vertex_done) return;
|
||||
dx=max(string_ox,x)-min(string_ox,x);
|
||||
dy=max(string_oy,y)-min(string_oy,y);
|
||||
if(dx+dy>string_vertex_distance)
|
||||
|
||||
if (string_vertex_done)
|
||||
return;
|
||||
dx = max(string_ox, x) - min(string_ox, x);
|
||||
dy = max(string_oy, y) - min(string_oy, y);
|
||||
if (dx + dy > string_vertex_distance)
|
||||
{
|
||||
string_vertex_distance=dx+dy;
|
||||
string_vertex_x=x;
|
||||
string_vertex_y=y;
|
||||
string_vertex_distance = dx + dy;
|
||||
string_vertex_x = x;
|
||||
string_vertex_y = y;
|
||||
}
|
||||
if(dx+dy+30<string_vertex_distance) string_vertex_done=1;
|
||||
if (dx + dy + 30 < string_vertex_distance)
|
||||
string_vertex_done = 1;
|
||||
}
|
||||
|
||||
void string_drag(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
if ((x<canvas->w)&&(y<canvas->h)&&(ox<canvas->w)&&(oy<canvas->h)&&((signed)x>0)&&((signed)y>0)&&((signed)ox>0)&&((signed)oy>0))
|
||||
if ((x < canvas->w) && (y < canvas->h) && (ox < canvas->w) && (oy < canvas->h) && ((signed)x > 0) && ((signed)y > 0)
|
||||
&& ((signed)ox > 0) && ((signed)oy > 0))
|
||||
{
|
||||
string_set_vertex(x,y);
|
||||
string_draw_wrapper((void *) api, which, canvas, snapshot,ox,oy, x, y, update_rect);
|
||||
string_set_vertex(x, y);
|
||||
string_draw_wrapper((void *)api, which, canvas, snapshot, ox, oy, x, y, update_rect);
|
||||
api->playsound(string_snd[which], (x * 255) / canvas->w, 255);
|
||||
|
||||
}
|
||||
|
|
|
|||
317
magic/src/tint.c
317
magic/src/tint.c
|
|
@ -46,59 +46,58 @@
|
|||
#define gettext_noop(String) String
|
||||
#endif
|
||||
|
||||
enum {
|
||||
TOOL_TINT,
|
||||
TOOL_THRESHOLD,
|
||||
tint_NUM_TOOLS
|
||||
enum
|
||||
{
|
||||
TOOL_TINT,
|
||||
TOOL_THRESHOLD,
|
||||
tint_NUM_TOOLS
|
||||
};
|
||||
static Uint8 tint_r, tint_g, tint_b;
|
||||
static int tint_min = INT_MAX;
|
||||
static int tint_max = 0;
|
||||
|
||||
static const int tint_RADIUS =16;
|
||||
static const int tint_RADIUS = 16;
|
||||
|
||||
static Mix_Chunk * tint_snd_effect[tint_NUM_TOOLS];
|
||||
static Mix_Chunk *tint_snd_effect[tint_NUM_TOOLS];
|
||||
|
||||
const char * tint_snd_filenames[tint_NUM_TOOLS] = {
|
||||
const char *tint_snd_filenames[tint_NUM_TOOLS] = {
|
||||
"tint.wav",
|
||||
"fold.ogg" /* FIXME */
|
||||
"fold.ogg" /* FIXME */
|
||||
};
|
||||
const char * tint_icon_filenames[tint_NUM_TOOLS] = {
|
||||
|
||||
const char *tint_icon_filenames[tint_NUM_TOOLS] = {
|
||||
"tint.png",
|
||||
"colornwhite.png"
|
||||
};
|
||||
const char * tint_names[tint_NUM_TOOLS] = {
|
||||
|
||||
const char *tint_names[tint_NUM_TOOLS] = {
|
||||
gettext_noop("Tint"),
|
||||
gettext_noop("Color & White") // It does more than this but more intuitive than threshold.
|
||||
};
|
||||
const char * tint_descs[tint_NUM_TOOLS][2] = {
|
||||
|
||||
const char *tint_descs[tint_NUM_TOOLS][2] = {
|
||||
{gettext_noop("Click and drag the mouse around to change the color of parts of your picture."),
|
||||
gettext_noop("Click to change the color of your entire picture."),},
|
||||
gettext_noop("Click to change the color of your entire picture."),},
|
||||
{gettext_noop("Click and drag the mouse around to turn parts of your picture into white and a color you choose."),
|
||||
gettext_noop("Click to turn your entire picture into white and a color you choose.")}
|
||||
gettext_noop("Click to turn your entire picture into white and a color you choose.")}
|
||||
};
|
||||
|
||||
int tint_init(magic_api * api);
|
||||
Uint32 tint_api_version(void);
|
||||
int tint_get_tool_count(magic_api * api);
|
||||
SDL_Surface * tint_get_icon(magic_api * api, int which);
|
||||
char * tint_get_name(magic_api * api, int which);
|
||||
char * tint_get_description(magic_api * api, int which, int mode);
|
||||
static int tint_grey(Uint8 r1,Uint8 g1,Uint8 b1);
|
||||
static void do_tint_pixel(void * ptr, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y);
|
||||
static void do_tint_full(void * ptr,SDL_Surface * canvas, SDL_Surface * last, int which);
|
||||
static void do_tint_brush(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||
SDL_Surface *tint_get_icon(magic_api * api, int which);
|
||||
char *tint_get_name(magic_api * api, int which);
|
||||
char *tint_get_description(magic_api * api, int which, int mode);
|
||||
static int tint_grey(Uint8 r1, Uint8 g1, Uint8 b1);
|
||||
static void do_tint_pixel(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||
static void do_tint_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int which);
|
||||
static void do_tint_brush(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||
void tint_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
void tint_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void tint_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void tint_shutdown(magic_api * api);
|
||||
void tint_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
int tint_requires_colors(magic_api * api, int which);
|
||||
|
|
@ -106,112 +105,145 @@ 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++){
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/%s", api->data_directory, tint_snd_filenames[i]);
|
||||
tint_snd_effect[i] = Mix_LoadWAV(fname);
|
||||
}
|
||||
return(1);
|
||||
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){
|
||||
return(tint_NUM_TOOLS);
|
||||
int tint_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return (tint_NUM_TOOLS);
|
||||
}
|
||||
|
||||
// Load our icons:
|
||||
SDL_Surface * tint_get_icon(magic_api * api, int which){
|
||||
SDL_Surface *tint_get_icon(magic_api * api, int which)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, tint_icon_filenames[which]);
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our names, localized:
|
||||
char * tint_get_name(magic_api * api ATTRIBUTE_UNUSED, int which){
|
||||
return(strdup(gettext_noop(tint_names[which])));
|
||||
char *tint_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
|
||||
{
|
||||
return (strdup(gettext_noop(tint_names[which])));
|
||||
}
|
||||
|
||||
// Return our descriptions, localized:
|
||||
char * tint_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode){
|
||||
return(strdup(gettext_noop(tint_descs[which][mode-1])));
|
||||
char *tint_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode)
|
||||
{
|
||||
return (strdup(gettext_noop(tint_descs[which][mode - 1])));
|
||||
}
|
||||
|
||||
//Calculates the grey scale value for a rgb pixel
|
||||
static int tint_grey(Uint8 r1,Uint8 g1,Uint8 b1){
|
||||
return 0.3*r1+.59*g1+0.11*b1;
|
||||
static int tint_grey(Uint8 r1, Uint8 g1, Uint8 b1)
|
||||
{
|
||||
return 0.3 * r1 + .59 * g1 + 0.11 * b1;
|
||||
}
|
||||
|
||||
static void do_tint_pixel(void * ptr, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y){
|
||||
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
Uint8 r,g,b;
|
||||
float h,s,v;
|
||||
|
||||
SDL_GetRGB(api->getpixel(last, x, y), last->format, &r, &g, &b);
|
||||
static void do_tint_pixel(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
|
||||
{
|
||||
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
Uint8 r, g, b;
|
||||
float h, s, v;
|
||||
|
||||
SDL_GetRGB(api->getpixel(last, x, y), last->format, &r, &g, &b);
|
||||
{
|
||||
|
||||
int greyValue = tint_grey(r, g, b);
|
||||
|
||||
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)
|
||||
{
|
||||
int thresholdValue = (tint_max - tint_min) / 2;
|
||||
|
||||
if (greyValue < thresholdValue)
|
||||
{
|
||||
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, tint_r, tint_g, tint_b));
|
||||
}
|
||||
else
|
||||
{
|
||||
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, 255, 255, 255));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Do the effect:
|
||||
static void do_tint_full(void *ptr, SDL_Surface * canvas, SDL_Surface * last, int which)
|
||||
{
|
||||
int x, y;
|
||||
|
||||
for (y = 0; y < last->h; y++)
|
||||
{
|
||||
|
||||
int greyValue = tint_grey(r,g,b);
|
||||
|
||||
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){
|
||||
int thresholdValue = (tint_max-tint_min)/2;
|
||||
if (greyValue < thresholdValue){
|
||||
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, tint_r, tint_g, tint_b));
|
||||
} else{
|
||||
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, 255, 255, 255));
|
||||
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)
|
||||
{
|
||||
int xx, yy;
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
|
||||
for (yy = y - tint_RADIUS; yy < y + tint_RADIUS; yy++)
|
||||
{
|
||||
for (xx = x - tint_RADIUS; xx < x + tint_RADIUS; xx++)
|
||||
{
|
||||
if (api->in_circle(xx - x, yy - y, tint_RADIUS) && !api->touched(xx, yy))
|
||||
{
|
||||
do_tint_pixel(api, which, canvas, last, xx, yy);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Do the effect:
|
||||
static void do_tint_full(void * ptr,SDL_Surface * canvas, SDL_Surface * last, int which){
|
||||
int x,y;
|
||||
for (y = 0; y < last->h; y++){
|
||||
for (x=0; x < last->w; x++){
|
||||
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){
|
||||
int xx, yy;
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
|
||||
for (yy = y - tint_RADIUS; yy < y + tint_RADIUS; yy++)
|
||||
{
|
||||
for (xx = x - tint_RADIUS; xx < x + tint_RADIUS; xx++)
|
||||
{
|
||||
if (api->in_circle(xx - x, yy - y, tint_RADIUS) &&
|
||||
!api->touched(xx, yy))
|
||||
{
|
||||
do_tint_pixel(api, which, canvas, last, xx, yy);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Affect the canvas on drag:
|
||||
void tint_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect){
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
|
||||
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_tint_brush);
|
||||
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_tint_brush);
|
||||
|
||||
api->playsound(tint_snd_effect[which], (x * 255) / canvas->w, 255);
|
||||
|
||||
if (ox > x) { int tmp = ox; ox = x; x = tmp; }
|
||||
if (oy > y) { int tmp = oy; oy = y; y = tmp; }
|
||||
if (ox > x)
|
||||
{
|
||||
int tmp = ox;
|
||||
|
||||
ox = x;
|
||||
x = tmp;
|
||||
}
|
||||
if (oy > y)
|
||||
{
|
||||
int tmp = oy;
|
||||
|
||||
oy = y;
|
||||
y = tmp;
|
||||
}
|
||||
|
||||
update_rect->x = ox - tint_RADIUS;
|
||||
update_rect->y = oy - tint_RADIUS;
|
||||
|
|
@ -221,37 +253,41 @@ 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{
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
do_tint_full(api, canvas, last, which);
|
||||
api->playsound(tint_snd_effect[which], 128, 255);
|
||||
}
|
||||
else
|
||||
{
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
do_tint_full(api, canvas, last, which);
|
||||
api->playsound(tint_snd_effect[which], 128, 255);
|
||||
}
|
||||
}
|
||||
|
||||
// Affect the canvas on release:
|
||||
void tint_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)
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
// No setup happened:
|
||||
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){
|
||||
Mix_FreeChunk(tint_snd_effect[i]);
|
||||
}
|
||||
}
|
||||
//Clean up sounds
|
||||
int i;
|
||||
|
||||
for (i = 0; i < tint_NUM_TOOLS; i++)
|
||||
{
|
||||
if (tint_snd_effect[i] != NULL)
|
||||
{
|
||||
Mix_FreeChunk(tint_snd_effect[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Record the color from Tux Paint:
|
||||
|
|
@ -268,32 +304,39 @@ int tint_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_U
|
|||
return 1;
|
||||
}
|
||||
|
||||
void tint_switchin(magic_api * api, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas){
|
||||
void tint_switchin(magic_api * api, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas)
|
||||
{
|
||||
|
||||
int x,y;
|
||||
Uint8 r1,g1,b1;
|
||||
int x, y;
|
||||
Uint8 r1, g1, b1;
|
||||
|
||||
for (y = 0; y < canvas->h; y++){
|
||||
for (x=0; x < canvas->w; x++){
|
||||
SDL_GetRGB(api->getpixel(canvas, x, y), canvas->format, &r1, &g1, &b1);
|
||||
{
|
||||
int greyValue = tint_grey(r1,g1,b1);
|
||||
if (greyValue<tint_min){
|
||||
tint_min=greyValue;
|
||||
}
|
||||
if (greyValue>tint_max){
|
||||
tint_max=greyValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (y = 0; y < canvas->h; y++)
|
||||
{
|
||||
for (x = 0; x < canvas->w; x++)
|
||||
{
|
||||
SDL_GetRGB(api->getpixel(canvas, x, y), canvas->format, &r1, &g1, &b1);
|
||||
{
|
||||
int greyValue = tint_grey(r1, g1, b1);
|
||||
|
||||
if (greyValue < tint_min)
|
||||
{
|
||||
tint_min = greyValue;
|
||||
}
|
||||
if (greyValue > tint_max)
|
||||
{
|
||||
tint_max = greyValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void tint_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void tint_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
int tint_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_FULLSCREEN|MODE_PAINT);
|
||||
return (MODE_FULLSCREEN | MODE_PAINT);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,25 +46,29 @@
|
|||
double pi;
|
||||
static Uint8 toothpaste_r, toothpaste_g, toothpaste_b;
|
||||
static const int toothpaste_RADIUS = 10;
|
||||
double* toothpaste_weights = NULL;
|
||||
double *toothpaste_weights = NULL;
|
||||
|
||||
enum {
|
||||
TOOL_toothpaste,
|
||||
toothpaste_NUM_TOOLS
|
||||
enum
|
||||
{
|
||||
TOOL_toothpaste,
|
||||
toothpaste_NUM_TOOLS
|
||||
};
|
||||
|
||||
static Mix_Chunk * toothpaste_snd_effect[toothpaste_NUM_TOOLS];
|
||||
static Mix_Chunk *toothpaste_snd_effect[toothpaste_NUM_TOOLS];
|
||||
|
||||
const char * toothpaste_snd_filenames[toothpaste_NUM_TOOLS] = {
|
||||
const char *toothpaste_snd_filenames[toothpaste_NUM_TOOLS] = {
|
||||
"toothpaste.ogg",
|
||||
};
|
||||
const char * toothpaste_icon_filenames[toothpaste_NUM_TOOLS] = {
|
||||
|
||||
const char *toothpaste_icon_filenames[toothpaste_NUM_TOOLS] = {
|
||||
"toothpaste.png",
|
||||
};
|
||||
const char * toothpaste_names[toothpaste_NUM_TOOLS] = {
|
||||
|
||||
const char *toothpaste_names[toothpaste_NUM_TOOLS] = {
|
||||
gettext_noop("Toothpaste"),
|
||||
};
|
||||
const char * toothpaste_descs[toothpaste_NUM_TOOLS] = {
|
||||
|
||||
const char *toothpaste_descs[toothpaste_NUM_TOOLS] = {
|
||||
gettext_noop("Click and drag to squirt toothpaste onto your picture."),
|
||||
};
|
||||
|
||||
|
|
@ -72,20 +76,16 @@ const char * toothpaste_descs[toothpaste_NUM_TOOLS] = {
|
|||
Uint32 toothpaste_api_version(void);
|
||||
int toothpaste_init(magic_api * api);
|
||||
int toothpaste_get_tool_count(magic_api * api);
|
||||
SDL_Surface * toothpaste_get_icon(magic_api * api, int which);
|
||||
char * toothpaste_get_name(magic_api * api, int which);
|
||||
char * toothpaste_get_description(magic_api * api, int which, int mode);
|
||||
static void do_toothpaste(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y);
|
||||
SDL_Surface *toothpaste_get_icon(magic_api * api, int which);
|
||||
char *toothpaste_get_name(magic_api * api, int which);
|
||||
char *toothpaste_get_description(magic_api * api, int which, int mode);
|
||||
static void do_toothpaste(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||
void toothpaste_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
void toothpaste_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void toothpaste_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void toothpaste_shutdown(magic_api * api);
|
||||
void toothpaste_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
int toothpaste_requires_colors(magic_api * api, int which);
|
||||
|
|
@ -93,89 +93,112 @@ void toothpaste_switchin(magic_api * api, int which, int mode, SDL_Surface * can
|
|||
void toothpaste_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
int toothpaste_modes(magic_api * api, int which);
|
||||
|
||||
Uint32 toothpaste_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
Uint32 toothpaste_api_version(void)
|
||||
{
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
|
||||
int toothpaste_init(magic_api * api){
|
||||
int toothpaste_init(magic_api * api)
|
||||
{
|
||||
|
||||
int i;
|
||||
char fname[1024];
|
||||
int k,j;
|
||||
int k, j;
|
||||
|
||||
//Load sounds
|
||||
for (i = 0; i < toothpaste_NUM_TOOLS; i++){
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/%s", api->data_directory, toothpaste_snd_filenames[i]);
|
||||
toothpaste_snd_effect[i] = Mix_LoadWAV(fname);
|
||||
}
|
||||
|
||||
for (i = 0; i < toothpaste_NUM_TOOLS; i++)
|
||||
{
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/%s", api->data_directory, toothpaste_snd_filenames[i]);
|
||||
toothpaste_snd_effect[i] = Mix_LoadWAV(fname);
|
||||
}
|
||||
|
||||
//Set up weights
|
||||
pi = acos(0.0) * 2;
|
||||
toothpaste_weights = (double*)malloc(toothpaste_RADIUS*2 * toothpaste_RADIUS*2 * sizeof(double));
|
||||
if (toothpaste_weights == NULL){
|
||||
return(0);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
toothpaste_weights = (double *)malloc(toothpaste_RADIUS * 2 * toothpaste_RADIUS * 2 * sizeof(double));
|
||||
if (toothpaste_weights == NULL)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
||||
return(1);
|
||||
for (k = -toothpaste_RADIUS; k < +toothpaste_RADIUS; k++)
|
||||
{
|
||||
for (j = -toothpaste_RADIUS; j < +toothpaste_RADIUS; j++)
|
||||
{
|
||||
if (api->in_circle(j, k, toothpaste_RADIUS))
|
||||
{
|
||||
toothpaste_weights[(k + toothpaste_RADIUS) * ((toothpaste_RADIUS * 2) - 1) + (j + toothpaste_RADIUS)] =
|
||||
((fabs(atan2((double)(j), (double)(k)))) / pi);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (1);
|
||||
}
|
||||
|
||||
int toothpaste_get_tool_count(magic_api * api ATTRIBUTE_UNUSED){
|
||||
return(toothpaste_NUM_TOOLS);
|
||||
int toothpaste_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return (toothpaste_NUM_TOOLS);
|
||||
}
|
||||
|
||||
// Load our icons:
|
||||
SDL_Surface * toothpaste_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED){
|
||||
SDL_Surface *toothpaste_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, toothpaste_icon_filenames[which]);
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our names, localized:
|
||||
char * toothpaste_get_name(magic_api * api ATTRIBUTE_UNUSED, int which){
|
||||
return(strdup(gettext_noop(toothpaste_names[which])));
|
||||
char *toothpaste_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
|
||||
{
|
||||
return (strdup(gettext_noop(toothpaste_names[which])));
|
||||
}
|
||||
|
||||
// Return our descriptions, localized:
|
||||
char * toothpaste_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED){
|
||||
return(strdup(gettext_noop(toothpaste_descs[which])));
|
||||
char *toothpaste_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return (strdup(gettext_noop(toothpaste_descs[which])));
|
||||
}
|
||||
|
||||
// Do the effect:
|
||||
static void do_toothpaste(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y){
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
static void do_toothpaste(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
|
||||
SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
|
||||
{
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
|
||||
int xx, yy;
|
||||
|
||||
// double colr;
|
||||
float h,s,v;
|
||||
Uint8 r,g,b;
|
||||
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->putpixel(canvas, xx, yy, SDL_MapRGB(canvas->format, r, g, b));
|
||||
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->putpixel(canvas, xx, yy, SDL_MapRGB(canvas->format, r, g, b));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Affect the canvas on drag:
|
||||
void toothpaste_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect){
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
|
||||
api->line((void *) api, which, canvas, last, ox, oy, x, y, 1, do_toothpaste);
|
||||
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_toothpaste);
|
||||
|
||||
api->playsound(toothpaste_snd_effect[which], (x * 255) / canvas->w, 255);
|
||||
|
||||
|
|
@ -188,33 +211,37 @@ 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);
|
||||
}
|
||||
|
||||
// Affect the canvas on release:
|
||||
void toothpaste_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)
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
// No setup happened:
|
||||
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){
|
||||
Mix_FreeChunk(toothpaste_snd_effect[i]);
|
||||
}
|
||||
}
|
||||
if (toothpaste_weights != NULL){
|
||||
free(toothpaste_weights);
|
||||
toothpaste_weights = NULL;
|
||||
}
|
||||
//Clean up sounds
|
||||
int i;
|
||||
|
||||
for (i = 0; i < toothpaste_NUM_TOOLS; i++)
|
||||
{
|
||||
if (toothpaste_snd_effect[i] != NULL)
|
||||
{
|
||||
Mix_FreeChunk(toothpaste_snd_effect[i]);
|
||||
}
|
||||
}
|
||||
if (toothpaste_weights != NULL)
|
||||
{
|
||||
free(toothpaste_weights);
|
||||
toothpaste_weights = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// Record the color from Tux Paint:
|
||||
|
|
@ -232,17 +259,17 @@ int toothpaste_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRI
|
|||
}
|
||||
|
||||
|
||||
void toothpaste_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void toothpaste_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void toothpaste_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void toothpaste_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
int toothpaste_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_PAINT);
|
||||
return (MODE_PAINT);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -40,20 +40,22 @@
|
|||
|
||||
/* Our globals: */
|
||||
|
||||
enum { SIDE_LEFT, SIDE_RIGHT };
|
||||
enum { LEAFSIDE_RIGHT_DOWN,
|
||||
LEAFSIDE_LEFT_DOWN,
|
||||
LEAFSIDE_RIGHT_UP,
|
||||
LEAFSIDE_LEFT_UP };
|
||||
enum
|
||||
{ SIDE_LEFT, SIDE_RIGHT };
|
||||
enum
|
||||
{ LEAFSIDE_RIGHT_DOWN,
|
||||
LEAFSIDE_LEFT_DOWN,
|
||||
LEAFSIDE_RIGHT_UP,
|
||||
LEAFSIDE_LEFT_UP
|
||||
};
|
||||
|
||||
static Mix_Chunk /* * tornado_click_snd, */ * tornado_release_snd;
|
||||
static Mix_Chunk /* * tornado_click_snd, */ * tornado_release_snd;
|
||||
static Uint8 tornado_r, tornado_g, tornado_b;
|
||||
static int tornado_min_x, tornado_max_x, tornado_bottom_x, tornado_bottom_y;
|
||||
static int tornado_side_first;
|
||||
static int tornado_side_decided;
|
||||
static SDL_Surface * tornado_base, * tornado_cloud,
|
||||
* tornado_cloud_colorized;
|
||||
static int top_w;
|
||||
static SDL_Surface *tornado_base, *tornado_cloud, *tornado_cloud_colorized;
|
||||
static int top_w;
|
||||
|
||||
/* Local function prototypes: */
|
||||
|
||||
|
|
@ -62,24 +64,22 @@ typedef struct
|
|||
float x, y;
|
||||
} Point2D;
|
||||
|
||||
static void tornado_predrag(magic_api * api, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y);
|
||||
static void tornado_predrag(magic_api * api, SDL_Surface * canvas, SDL_Surface * last, int ox, int oy, int x, int y);
|
||||
static void tornado_drawbase(magic_api * api, SDL_Surface * canvas);
|
||||
static void tornado_drawstalk(magic_api * api, SDL_Surface * canvas, SDL_Surface * last,
|
||||
int top_x, int top_y, int minx, int maxx,
|
||||
int bottom_x, int bottom_y, int final);
|
||||
int top_x, int top_y, int minx, int maxx, int bottom_x, int bottom_y, int final);
|
||||
static void tornado_drawtornado(magic_api * api, SDL_Surface * canvas, int x, int y);
|
||||
static Point2D tornado_PointOnCubicBezier(Point2D* cp, float t);
|
||||
static void tornado_ComputeBezier(Point2D* cp, int numberOfPoints, Point2D* curve);
|
||||
static Point2D tornado_PointOnCubicBezier(Point2D * cp, float t);
|
||||
static void tornado_ComputeBezier(Point2D * cp, int numberOfPoints, Point2D * curve);
|
||||
static void tornado_colorize_cloud(magic_api * api);
|
||||
static Uint32 tornado_mess(Uint32 pixel, SDL_Surface * canvas);
|
||||
Uint32 tornado_api_version(void);
|
||||
int tornado_init(magic_api * api);
|
||||
int tornado_get_tool_count(magic_api * api);
|
||||
SDL_Surface * tornado_get_icon(magic_api * api, int which);
|
||||
char * tornado_get_name(magic_api * api, int which);
|
||||
SDL_Surface *tornado_get_icon(magic_api * api, int which);
|
||||
char *tornado_get_name(magic_api * api, int which);
|
||||
|
||||
char * tornado_get_description(magic_api * api, int which, int mode);
|
||||
char *tornado_get_description(magic_api * api, int which, int mode);
|
||||
|
||||
|
||||
|
||||
|
|
@ -87,14 +87,11 @@ char * tornado_get_description(magic_api * api, int which, int mode);
|
|||
|
||||
|
||||
void tornado_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
void tornado_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void tornado_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
|
||||
void tornado_shutdown(magic_api * api);
|
||||
void tornado_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
|
|
@ -105,7 +102,10 @@ int tornado_modes(magic_api * api, int which);
|
|||
|
||||
|
||||
|
||||
Uint32 tornado_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
Uint32 tornado_api_version(void)
|
||||
{
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
|
||||
// No setup required:
|
||||
|
|
@ -119,53 +119,49 @@ int tornado_init(magic_api * api)
|
|||
tornado_click_snd = Mix_LoadWAV(fname);
|
||||
*/
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/tornado_release.ogg",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/tornado_release.ogg", api->data_directory);
|
||||
tornado_release_snd = Mix_LoadWAV(fname);
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/tornado_base.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/tornado_base.png", api->data_directory);
|
||||
tornado_base = IMG_Load(fname);
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/tornado_cloud.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/tornado_cloud.png", api->data_directory);
|
||||
tornado_cloud = IMG_Load(fname);
|
||||
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
// We have multiple tools:
|
||||
int tornado_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
// Load our icons:
|
||||
SDL_Surface * tornado_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
SDL_Surface *tornado_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/tornado.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/tornado.png", api->data_directory);
|
||||
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our names, localized:
|
||||
char * tornado_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
char *tornado_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(strdup(gettext_noop("Tornado")));
|
||||
return (strdup(gettext_noop("Tornado")));
|
||||
}
|
||||
|
||||
// Return our descriptions, localized:
|
||||
char * tornado_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
||||
char *tornado_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(strdup(gettext_noop("Click and drag to draw a tornado funnel on your picture.")));
|
||||
return (strdup(gettext_noop("Click and drag to draw a tornado funnel on your picture.")));
|
||||
}
|
||||
|
||||
// Affect the canvas on drag:
|
||||
static void tornado_predrag(magic_api * api ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * last ATTRIBUTE_UNUSED, int ox, int oy, int x, int y)
|
||||
SDL_Surface * last ATTRIBUTE_UNUSED, int ox, int oy, int x, int y)
|
||||
{
|
||||
if (x < tornado_min_x)
|
||||
tornado_min_x = x;
|
||||
|
|
@ -184,23 +180,22 @@ static void tornado_predrag(magic_api * api ATTRIBUTE_UNUSED, SDL_Surface * canv
|
|||
// Determine which way to bend first:
|
||||
//
|
||||
if (tornado_side_decided == 0)
|
||||
{
|
||||
if (x < tornado_bottom_x - 10)
|
||||
{
|
||||
tornado_side_first = SIDE_LEFT;
|
||||
tornado_side_decided = 1;
|
||||
if (x < tornado_bottom_x - 10)
|
||||
{
|
||||
tornado_side_first = SIDE_LEFT;
|
||||
tornado_side_decided = 1;
|
||||
}
|
||||
else if (x > tornado_bottom_x + 10)
|
||||
{
|
||||
tornado_side_first = SIDE_RIGHT;
|
||||
tornado_side_decided = 1;
|
||||
}
|
||||
}
|
||||
else if (x > tornado_bottom_x + 10)
|
||||
{
|
||||
tornado_side_first = SIDE_RIGHT;
|
||||
tornado_side_decided = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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,32 +208,30 @@ 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);
|
||||
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
}
|
||||
|
||||
// Affect the canvas on click:
|
||||
void tornado_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect)
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
tornado_min_x = x;
|
||||
tornado_max_x = x;
|
||||
tornado_bottom_x = x;
|
||||
tornado_bottom_y = y;// - tornado_base->h;
|
||||
tornado_bottom_y = y; // - tornado_base->h;
|
||||
|
||||
tornado_side_decided = 0;
|
||||
tornado_side_first = SIDE_LEFT;
|
||||
|
||||
tornado_drag(api, which, canvas, last, x, y, x, y, update_rect);
|
||||
|
||||
|
||||
/*
|
||||
api->playsound(tornado_click_snd, (x * 255) / canvas->w, 255);
|
||||
*/
|
||||
|
|
@ -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: */
|
||||
|
||||
|
|
@ -259,7 +251,7 @@ void tornado_release(magic_api * api, int which ATTRIBUTE_UNUSED,
|
|||
|
||||
tornado_predrag(api, canvas, last, x, y, x, y);
|
||||
|
||||
|
||||
|
||||
/* Erase any old stuff: */
|
||||
|
||||
SDL_BlitSurface(last, NULL, canvas, NULL);
|
||||
|
|
@ -267,15 +259,13 @@ 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);
|
||||
tornado_drawtornado(api, canvas, x, y);
|
||||
|
||||
tornado_drawbase(api, canvas);
|
||||
|
||||
tornado_drawbase(api, canvas);
|
||||
|
||||
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
|
|
@ -287,10 +277,10 @@ void tornado_release(magic_api * api, int which ATTRIBUTE_UNUSED,
|
|||
|
||||
static void tornado_drawtornado(magic_api * api, SDL_Surface * canvas, int x, int y)
|
||||
{
|
||||
SDL_Surface * aux_surf;
|
||||
SDL_Surface *aux_surf;
|
||||
SDL_Rect dest;
|
||||
|
||||
aux_surf = api->scale(tornado_cloud_colorized, top_w *2, top_w,0);
|
||||
aux_surf = api->scale(tornado_cloud_colorized, top_w * 2, top_w, 0);
|
||||
dest.x = x - (aux_surf->w / 2);
|
||||
dest.y = y - (aux_surf->h / 2);
|
||||
|
||||
|
|
@ -311,21 +301,19 @@ static void tornado_drawbase(magic_api * api ATTRIBUTE_UNUSED, SDL_Surface * can
|
|||
static Uint32 tornado_mess(Uint32 pixel, SDL_Surface * canvas)
|
||||
{
|
||||
Uint8 r, g, b, a;
|
||||
float f = (float)rand()*255/RAND_MAX;
|
||||
float f = (float)rand() * 255 / RAND_MAX;
|
||||
|
||||
SDL_GetRGBA(pixel, canvas->format, &r, &g, &b, &a);
|
||||
return (SDL_MapRGBA(canvas->format,
|
||||
(tornado_r + r + (Uint8)f * 2) / 4,
|
||||
(tornado_g + g + (Uint8)f * 2) / 4,
|
||||
(tornado_b + b + (Uint8)f * 2) / 4,
|
||||
a));
|
||||
(tornado_r + r + (Uint8) f * 2) / 4,
|
||||
(tornado_g + g + (Uint8) f * 2) / 4, (tornado_b + b + (Uint8) f * 2) / 4, a));
|
||||
}
|
||||
|
||||
static void tornado_drawstalk(magic_api * api, SDL_Surface * canvas, SDL_Surface * last,
|
||||
int top_x, int top_y, int minx, int maxx,
|
||||
int bottom_x, int bottom_y, int final)
|
||||
int top_x, int top_y, int minx, int maxx, int bottom_x, int bottom_y, int final)
|
||||
{
|
||||
Point2D control_points[4];
|
||||
Point2D * curve;
|
||||
Point2D *curve;
|
||||
int i, n_points;
|
||||
int left, right;
|
||||
SDL_Rect dest;
|
||||
|
|
@ -340,22 +328,22 @@ static void tornado_drawstalk(magic_api * api, SDL_Surface * canvas, SDL_Surface
|
|||
control_points[0].y = top_y;
|
||||
|
||||
if (tornado_side_first == SIDE_LEFT)
|
||||
{
|
||||
control_points[1].x = minx;
|
||||
control_points[2].x = maxx;
|
||||
}
|
||||
{
|
||||
control_points[1].x = minx;
|
||||
control_points[2].x = maxx;
|
||||
}
|
||||
else
|
||||
{
|
||||
control_points[1].x = maxx;
|
||||
control_points[2].x = minx;
|
||||
}
|
||||
{
|
||||
control_points[1].x = maxx;
|
||||
control_points[2].x = minx;
|
||||
}
|
||||
|
||||
control_points[1].y = ((bottom_y - top_y) / 3) + top_y;
|
||||
control_points[2].y = (((bottom_y - top_y) / 3) * 2) + top_y;
|
||||
|
||||
|
||||
control_points[3].x = bottom_x;
|
||||
control_points[3].y = bottom_y;
|
||||
|
||||
|
||||
if (final == 0)
|
||||
n_points = 8;
|
||||
else
|
||||
|
|
@ -370,58 +358,61 @@ static void tornado_drawstalk(magic_api * api, SDL_Surface * canvas, SDL_Surface
|
|||
top_w = max(32, n_points * n_points / 1000);
|
||||
|
||||
/* Draw the curve: */
|
||||
|
||||
|
||||
for (i = 0; i < n_points - 1; i++)
|
||||
{
|
||||
if (final == 0)
|
||||
{
|
||||
dest.x = curve[i].x;
|
||||
dest.y = curve[i].y;
|
||||
dest.w = 2;
|
||||
dest.h = 2;
|
||||
SDL_FillRect(canvas, &dest, SDL_MapRGB(canvas->format, 0, 0, 0));
|
||||
}
|
||||
else
|
||||
{
|
||||
ii = n_points - i;
|
||||
/* min 10 pixels then ii^2 / 2000 or 4 * ii^2 / canvas->w,
|
||||
don't let the top of funnel be wider than the half of canvas */
|
||||
if (n_points * n_points / 2000 > canvas->w / 4)
|
||||
ww = 4 * n_points * n_points / canvas->w;
|
||||
if (final == 0)
|
||||
{
|
||||
dest.x = curve[i].x;
|
||||
dest.y = curve[i].y;
|
||||
dest.w = 2;
|
||||
dest.h = 2;
|
||||
SDL_FillRect(canvas, &dest, SDL_MapRGB(canvas->format, 0, 0, 0));
|
||||
}
|
||||
else
|
||||
ww = 2000;
|
||||
{
|
||||
ii = n_points - i;
|
||||
/* min 10 pixels then ii^2 / 2000 or 4 * ii^2 / canvas->w,
|
||||
don't let the top of funnel be wider than the half of canvas */
|
||||
if (n_points * n_points / 2000 > canvas->w / 4)
|
||||
ww = 4 * n_points * n_points / canvas->w;
|
||||
else
|
||||
ww = 2000;
|
||||
|
||||
left = min(curve[i].x, curve[i + 1].x)-5-ii*ii/ww;
|
||||
right = max(curve[i].x, curve[i + 1].x)+5+ii*ii/ww;
|
||||
left = min(curve[i].x, curve[i + 1].x) - 5 - ii * ii / ww;
|
||||
right = max(curve[i].x, curve[i + 1].x) + 5 + ii * ii / ww;
|
||||
|
||||
dest.x = left;
|
||||
dest.y = curve[i].y;
|
||||
dest.w = right - left + 1;
|
||||
dest.h = 2;
|
||||
dest.x = left;
|
||||
dest.y = curve[i].y;
|
||||
dest.w = right - left + 1;
|
||||
dest.h = 2;
|
||||
}
|
||||
|
||||
rotation += 3;
|
||||
/* The body of the tornado: 3x 1y rotation + some random particles */
|
||||
for (p = dest.x; p < dest.x + dest.w; p++)
|
||||
{
|
||||
if ((float)rand() * 100 / RAND_MAX > 10)
|
||||
{
|
||||
api->putpixel(canvas, p, dest.y, api->getpixel(last, dest.x + (p - dest.x + rotation) % dest.w, dest.y));
|
||||
}
|
||||
else
|
||||
{
|
||||
api->putpixel(canvas, p, dest.y,
|
||||
tornado_mess(api->getpixel(last, dest.x + (p - dest.x + rotation) % dest.w, dest.y),
|
||||
canvas));
|
||||
}
|
||||
}
|
||||
|
||||
/* Some random particles flying around the tornado */
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
rotation +=3;
|
||||
/* The body of the tornado: 3x 1y rotation + some random particles */
|
||||
for (p = dest.x; p < dest.x + dest.w; p++)
|
||||
{
|
||||
if ((float)rand() * 100 / RAND_MAX > 10 )
|
||||
{
|
||||
api->putpixel(canvas, p, dest.y, api->getpixel(last, dest.x + (p - dest.x + rotation) % dest.w , dest.y));
|
||||
}
|
||||
else
|
||||
{
|
||||
api->putpixel(canvas, p, dest.y, tornado_mess(api->getpixel(last, dest.x + (p - dest.x + rotation) % dest.w , dest.y), canvas));
|
||||
}
|
||||
}
|
||||
|
||||
/* Some random particles flying around the tornado */
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
free(curve);
|
||||
}
|
||||
|
||||
|
|
@ -474,32 +465,32 @@ cp[3] is the end point, or P3 in the above diagram
|
|||
t is the parameter value, 0 <= t <= 1
|
||||
*/
|
||||
|
||||
static Point2D tornado_PointOnCubicBezier( Point2D* cp, float t )
|
||||
static Point2D tornado_PointOnCubicBezier(Point2D * cp, float t)
|
||||
{
|
||||
float ax, bx, cx;
|
||||
float ay, by, cy;
|
||||
float tSquared, tCubed;
|
||||
Point2D result;
|
||||
float ax, bx, cx;
|
||||
float ay, by, cy;
|
||||
float tSquared, tCubed;
|
||||
Point2D result;
|
||||
|
||||
/* calculate the polynomial coefficients */
|
||||
/* calculate the polynomial coefficients */
|
||||
|
||||
cx = 3.0 * (cp[1].x - cp[0].x);
|
||||
bx = 3.0 * (cp[2].x - cp[1].x) - cx;
|
||||
ax = cp[3].x - cp[0].x - cx - bx;
|
||||
|
||||
cy = 3.0 * (cp[1].y - cp[0].y);
|
||||
by = 3.0 * (cp[2].y - cp[1].y) - cy;
|
||||
ay = cp[3].y - cp[0].y - cy - by;
|
||||
|
||||
/* calculate the curve point at parameter value t */
|
||||
|
||||
tSquared = t * t;
|
||||
tCubed = tSquared * t;
|
||||
|
||||
result.x = (ax * tCubed) + (bx * tSquared) + (cx * t) + cp[0].x;
|
||||
result.y = (ay * tCubed) + (by * tSquared) + (cy * t) + cp[0].y;
|
||||
|
||||
return result;
|
||||
cx = 3.0 * (cp[1].x - cp[0].x);
|
||||
bx = 3.0 * (cp[2].x - cp[1].x) - cx;
|
||||
ax = cp[3].x - cp[0].x - cx - bx;
|
||||
|
||||
cy = 3.0 * (cp[1].y - cp[0].y);
|
||||
by = 3.0 * (cp[2].y - cp[1].y) - cy;
|
||||
ay = cp[3].y - cp[0].y - cy - by;
|
||||
|
||||
/* calculate the curve point at parameter value t */
|
||||
|
||||
tSquared = t * t;
|
||||
tCubed = tSquared * t;
|
||||
|
||||
result.x = (ax * tCubed) + (bx * tSquared) + (cx * t) + cp[0].x;
|
||||
result.y = (ay * tCubed) + (by * tSquared) + (cy * t) + cp[0].y;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -509,15 +500,15 @@ static Point2D tornado_PointOnCubicBezier( Point2D* cp, float t )
|
|||
<sizeof(Point2D) numberOfPoints>
|
||||
*/
|
||||
|
||||
static void tornado_ComputeBezier( Point2D* cp, int numberOfPoints, Point2D* curve )
|
||||
static void tornado_ComputeBezier(Point2D * cp, int numberOfPoints, Point2D * curve)
|
||||
{
|
||||
float dt;
|
||||
int i;
|
||||
float dt;
|
||||
int i;
|
||||
|
||||
dt = 1.0 / ( numberOfPoints - 1 );
|
||||
dt = 1.0 / (numberOfPoints - 1);
|
||||
|
||||
for( i = 0; i < numberOfPoints; i++)
|
||||
curve[i] = tornado_PointOnCubicBezier( cp, i*dt );
|
||||
for (i = 0; i < numberOfPoints; i++)
|
||||
curve[i] = tornado_PointOnCubicBezier(cp, i * dt);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -532,9 +523,7 @@ static void tornado_colorize_cloud(magic_api * api)
|
|||
|
||||
/* Create a surface to render into: */
|
||||
|
||||
amask = ~(tornado_cloud->format->Rmask |
|
||||
tornado_cloud->format->Gmask |
|
||||
tornado_cloud->format->Bmask);
|
||||
amask = ~(tornado_cloud->format->Rmask | tornado_cloud->format->Gmask | tornado_cloud->format->Bmask);
|
||||
|
||||
tornado_cloud_colorized =
|
||||
SDL_CreateRGBSurface(SDL_SWSURFACE,
|
||||
|
|
@ -542,8 +531,7 @@ static void tornado_colorize_cloud(magic_api * api)
|
|||
tornado_cloud->h,
|
||||
tornado_cloud->format->BitsPerPixel,
|
||||
tornado_cloud->format->Rmask,
|
||||
tornado_cloud->format->Gmask,
|
||||
tornado_cloud->format->Bmask, amask);
|
||||
tornado_cloud->format->Gmask, tornado_cloud->format->Bmask, amask);
|
||||
|
||||
/* Render the new cloud: */
|
||||
|
||||
|
|
@ -551,32 +539,33 @@ static void tornado_colorize_cloud(magic_api * api)
|
|||
SDL_LockSurface(tornado_cloud_colorized);
|
||||
|
||||
for (y = 0; y < tornado_cloud->h; y++)
|
||||
{
|
||||
for (x = 0; x < tornado_cloud->w; x++)
|
||||
{
|
||||
SDL_GetRGBA(api->getpixel(tornado_cloud, x, y),
|
||||
tornado_cloud->format, &r, &g, &b, &a);
|
||||
for (x = 0; x < tornado_cloud->w; x++)
|
||||
{
|
||||
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,
|
||||
(tornado_r + r * 2) / 3, (tornado_g + g * 2) / 3, (tornado_b + b * 2) / 3, a));
|
||||
api->putpixel(tornado_cloud_colorized, x, y,
|
||||
SDL_MapRGBA(tornado_cloud_colorized->format,
|
||||
(tornado_r + r * 2) / 3, (tornado_g + g * 2) / 3, (tornado_b + b * 2) / 3, a));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SDL_UnlockSurface(tornado_cloud_colorized);
|
||||
SDL_UnlockSurface(tornado_cloud);
|
||||
}
|
||||
|
||||
void tornado_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void tornado_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void tornado_switchout(magic_api * api, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void tornado_switchout(magic_api * api, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
api->stopsound();
|
||||
}
|
||||
|
||||
int tornado_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_PAINT_WITH_PREVIEW);
|
||||
return (MODE_PAINT_WITH_PREVIEW);
|
||||
}
|
||||
|
|
|
|||
134
magic/src/tv.c
134
magic/src/tv.c
|
|
@ -32,42 +32,37 @@
|
|||
|
||||
int RADIUS = 16;
|
||||
|
||||
Mix_Chunk * tv_snd;
|
||||
Mix_Chunk *tv_snd;
|
||||
|
||||
Uint32 tv_api_version(void);
|
||||
void tv_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
int tv_init(magic_api * api);
|
||||
int tv_get_tool_count(magic_api * api);
|
||||
SDL_Surface * tv_get_icon(magic_api * api, int which);
|
||||
char * tv_get_name(magic_api * api, int which);
|
||||
char * tv_get_description(magic_api * api, int which, int mode);
|
||||
SDL_Surface *tv_get_icon(magic_api * api, int which);
|
||||
char *tv_get_name(magic_api * api, int which);
|
||||
char *tv_get_description(magic_api * api, int which, int mode);
|
||||
int tv_requires_colors(magic_api * api, int which);
|
||||
void tv_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
|
||||
void tv_shutdown(magic_api * api);
|
||||
void tv_paint_tv(void * ptr_to_api, int which_tool,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
|
||||
void tv_do_tv(void * ptr_to_api, int which_tool,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
|
||||
void tv_paint_tv(void *ptr_to_api, int which_tool, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
|
||||
void tv_do_tv(void *ptr_to_api, int which_tool, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
|
||||
void tv_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
void tv_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void tv_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
void tv_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
int tv_modes(magic_api * api, int which);
|
||||
|
||||
// Housekeeping functions
|
||||
// Housekeeping functions
|
||||
|
||||
Uint32 tv_api_version(void)
|
||||
{
|
||||
return(TP_MAGIC_API_VERSION);
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
void tv_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED) //get the colors from API and store it in structure
|
||||
void tv_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED) //get the colors from API and store it in structure
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -75,79 +70,83 @@ void tv_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Ui
|
|||
int tv_init(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/tv.ogg", api->data_directory);
|
||||
tv_snd = Mix_LoadWAV(fname);
|
||||
|
||||
return(1);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/tv.ogg", api->data_directory);
|
||||
tv_snd = Mix_LoadWAV(fname);
|
||||
|
||||
return (1);
|
||||
}
|
||||
|
||||
int tv_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
int tv_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
SDL_Surface * tv_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
SDL_Surface *tv_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/tv.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/tv.png", api->data_directory);
|
||||
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
char * tv_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED) { return strdup(gettext_noop("TV")); }
|
||||
char *tv_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return strdup(gettext_noop("TV"));
|
||||
}
|
||||
|
||||
char * tv_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode)
|
||||
{
|
||||
char *tv_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode)
|
||||
{
|
||||
if (mode == MODE_PAINT)
|
||||
return strdup(gettext_noop("Click and drag to make parts of your picture look like they are on television."));
|
||||
return strdup(gettext_noop("Click and drag to make parts of your picture look like they are on television."));
|
||||
|
||||
else
|
||||
return strdup(gettext_noop("Click to make your picture look like it's on television."));
|
||||
return strdup(gettext_noop("Click to make your picture look like it's on television."));
|
||||
|
||||
}
|
||||
|
||||
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,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect 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)
|
||||
{
|
||||
}
|
||||
|
||||
void tv_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{ Mix_FreeChunk(tv_snd); }
|
||||
void tv_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
Mix_FreeChunk(tv_snd);
|
||||
}
|
||||
|
||||
// Interactivity functions
|
||||
|
||||
void tv_paint_tv(void * ptr_to_api, int which_tool ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
|
||||
void tv_paint_tv(void *ptr_to_api, int which_tool ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
|
||||
{
|
||||
int i, j;
|
||||
magic_api * api = (magic_api *) ptr_to_api;
|
||||
magic_api *api = (magic_api *) ptr_to_api;
|
||||
|
||||
for (i = x - RADIUS; i < x + RADIUS; i++)
|
||||
for (j = y - RADIUS; j < y + RADIUS; j++)
|
||||
if ((j + 1) % 2 &&
|
||||
api->in_circle(i - x, j - y, RADIUS) &&
|
||||
! api->touched(i, j))
|
||||
api->putpixel(canvas, i, j, SDL_MapRGB(canvas->format, 128, 128, 165));
|
||||
if ((j + 1) % 2 && api->in_circle(i - x, j - y, RADIUS) && !api->touched(i, j))
|
||||
api->putpixel(canvas, i, j, SDL_MapRGB(canvas->format, 128, 128, 165));
|
||||
}
|
||||
|
||||
void tv_do_tv(void * ptr_to_api, int which_tool ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
|
||||
void tv_do_tv(void *ptr_to_api, int which_tool ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr_to_api;
|
||||
|
||||
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, 128, 128, 165));
|
||||
//api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, 0, 0, 255));
|
||||
magic_api *api = (magic_api *) ptr_to_api;
|
||||
|
||||
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, 128, 128, 165));
|
||||
//api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, 0, 0, 255));
|
||||
}
|
||||
|
||||
void tv_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
api->line(api, which, canvas, snapshot, ox, oy, x, y, 1, tv_paint_tv);
|
||||
|
||||
|
|
@ -159,38 +158,39 @@ void tv_drag(magic_api * api, int which, SDL_Surface * canvas,
|
|||
}
|
||||
|
||||
void tv_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect)
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
if (mode == MODE_FULLSCREEN)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
for (i=0; i<canvas->h; i+=2)
|
||||
api->line(api, which, canvas, last, 0, i, canvas->w, i, 1, tv_do_tv);
|
||||
for (i = 0; i < canvas->h; i += 2)
|
||||
api->line(api, which, canvas, last, 0, i, canvas->w, i, 1, tv_do_tv);
|
||||
|
||||
update_rect->w=canvas->w;
|
||||
update_rect->h=canvas->h;
|
||||
update_rect->x=update_rect->y=0;
|
||||
api->playsound(tv_snd, 128,255);
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
update_rect->x = update_rect->y = 0;
|
||||
api->playsound(tv_snd, 128, 255);
|
||||
}
|
||||
else
|
||||
{
|
||||
tv_drag(api, which, canvas, last, x, y, x, y, update_rect);
|
||||
tv_drag(api, which, canvas, last, x, y, x, y, update_rect);
|
||||
}
|
||||
}
|
||||
|
||||
void tv_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
|
||||
void tv_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void tv_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void tv_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
int tv_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_FULLSCREEN | MODE_PAINT);
|
||||
return (MODE_FULLSCREEN | MODE_PAINT);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,25 +34,22 @@
|
|||
|
||||
/* Our globals: */
|
||||
|
||||
static Mix_Chunk * waves_snd[2];
|
||||
static Mix_Chunk *waves_snd[2];
|
||||
|
||||
/* Local function prototypes: */
|
||||
|
||||
Uint32 waves_api_version(void);
|
||||
int waves_init(magic_api * api);
|
||||
int waves_get_tool_count(magic_api * api);
|
||||
SDL_Surface * waves_get_icon(magic_api * api, int which);
|
||||
char * waves_get_name(magic_api * api, int which);
|
||||
char * waves_get_description(magic_api * api, int which, int mode);
|
||||
SDL_Surface *waves_get_icon(magic_api * api, int which);
|
||||
char *waves_get_name(magic_api * api, int which);
|
||||
char *waves_get_description(magic_api * api, int which, int mode);
|
||||
void waves_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
void waves_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void waves_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void waves_shutdown(magic_api * api);
|
||||
void waves_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
int waves_requires_colors(magic_api * api, int which);
|
||||
|
|
@ -60,7 +57,10 @@ void waves_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
|||
void waves_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
int waves_modes(magic_api * api, int which);
|
||||
|
||||
Uint32 waves_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
Uint32 waves_api_version(void)
|
||||
{
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
|
||||
// No setup required:
|
||||
|
|
@ -68,16 +68,14 @@ int waves_init(magic_api * api)
|
|||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/waves.ogg",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/waves.ogg", api->data_directory);
|
||||
waves_snd[0] = Mix_LoadWAV(fname);
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/wavelet.ogg",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/wavelet.ogg", api->data_directory);
|
||||
waves_snd[1] = Mix_LoadWAV(fname);
|
||||
|
||||
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
// We have multiple tools:
|
||||
|
|
@ -87,35 +85,43 @@ int waves_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
|||
}
|
||||
|
||||
// Load our icons:
|
||||
SDL_Surface * waves_get_icon(magic_api * api, int which)
|
||||
SDL_Surface *waves_get_icon(magic_api * api, int which)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
if (!which) snprintf(fname, sizeof(fname), "%s/images/magic/waves.png", api->data_directory);
|
||||
else snprintf(fname, sizeof(fname), "%s/images/magic/wavelet.png", api->data_directory);
|
||||
if (!which)
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/waves.png", api->data_directory);
|
||||
else
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/wavelet.png", api->data_directory);
|
||||
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our names, localized:
|
||||
char * waves_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
|
||||
char *waves_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
|
||||
{
|
||||
if (!which) return(strdup(gettext_noop("Waves")));
|
||||
else return strdup(gettext_noop("Wavelets"));
|
||||
if (!which)
|
||||
return (strdup(gettext_noop("Waves")));
|
||||
else
|
||||
return strdup(gettext_noop("Wavelets"));
|
||||
}
|
||||
|
||||
// Return our descriptions, localized:
|
||||
char * waves_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
|
||||
char *waves_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
|
||||
{
|
||||
if (!which)
|
||||
return(strdup(gettext_noop("Click to make the picture horizontally wavy. Click toward the top for shorter waves, the bottom for taller waves, the left for small waves, and the right for long waves.")));
|
||||
return strdup(gettext_noop("Click to make the picture vertically wavy. Click toward the top for shorter waves, the bottom for taller waves, the left for small waves, and the right for long waves."));
|
||||
}
|
||||
return (strdup
|
||||
(gettext_noop
|
||||
("Click to make the picture horizontally wavy. Click toward the top for shorter waves, the bottom for taller waves, the left for small waves, and the right for long waves.")));
|
||||
return
|
||||
strdup(gettext_noop
|
||||
("Click to make the picture vertically wavy. Click toward the top for shorter waves, the bottom for taller waves, the left for small waves, and the right for long waves."));
|
||||
}
|
||||
|
||||
|
||||
void waves_drag(magic_api * api ATTRIBUTE_UNUSED, 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_Surface * last, int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
{
|
||||
int xx, yy;
|
||||
SDL_Rect src, dest;
|
||||
|
|
@ -123,48 +129,48 @@ void waves_drag(magic_api * api ATTRIBUTE_UNUSED, int which, SDL_Surface * canva
|
|||
int height;
|
||||
|
||||
SDL_BlitSurface(last, NULL, canvas, NULL);
|
||||
|
||||
if (which==0)
|
||||
{
|
||||
//waves effect
|
||||
width = ((x * 10) / canvas->w) + 10;
|
||||
height = ((canvas->h - y) / 10) + 1;
|
||||
|
||||
for (yy = 0; yy < canvas->h; yy++)
|
||||
{
|
||||
xx = sin((yy * height) * M_PI / 180.0) * width;
|
||||
|
||||
src.x = 0;
|
||||
src.y = yy;
|
||||
src.w = canvas->w;
|
||||
src.h = 1;
|
||||
if (which == 0)
|
||||
{
|
||||
//waves effect
|
||||
width = ((x * 10) / canvas->w) + 10;
|
||||
height = ((canvas->h - y) / 10) + 1;
|
||||
|
||||
dest.x = xx;
|
||||
dest.y = yy;
|
||||
for (yy = 0; yy < canvas->h; yy++)
|
||||
{
|
||||
xx = sin((yy * height) * M_PI / 180.0) * width;
|
||||
|
||||
SDL_BlitSurface(last, &src, canvas, &dest);
|
||||
}
|
||||
}
|
||||
src.x = 0;
|
||||
src.y = yy;
|
||||
src.w = canvas->w;
|
||||
src.h = 1;
|
||||
|
||||
dest.x = xx;
|
||||
dest.y = yy;
|
||||
|
||||
SDL_BlitSurface(last, &src, canvas, &dest);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
width = ((x * 10) / canvas->w) + 10;
|
||||
height = ((canvas->h - y) / 10) + 1;
|
||||
|
||||
for (xx = 0; xx < canvas->w; xx++)
|
||||
{
|
||||
yy = sin((xx * height) * M_PI / 180.0) * width;
|
||||
{
|
||||
width = ((x * 10) / canvas->w) + 10;
|
||||
height = ((canvas->h - y) / 10) + 1;
|
||||
|
||||
src.x = xx;
|
||||
src.y = 0;
|
||||
src.w = 1;
|
||||
src.h = canvas->h;
|
||||
for (xx = 0; xx < canvas->w; xx++)
|
||||
{
|
||||
yy = sin((xx * height) * M_PI / 180.0) * width;
|
||||
|
||||
dest.x = xx;
|
||||
dest.y = yy;
|
||||
src.x = xx;
|
||||
src.y = 0;
|
||||
src.w = 1;
|
||||
src.h = canvas->h;
|
||||
|
||||
SDL_BlitSurface(last, &src, canvas, &dest);
|
||||
}
|
||||
}
|
||||
dest.x = xx;
|
||||
dest.y = yy;
|
||||
|
||||
SDL_BlitSurface(last, &src, canvas, &dest);
|
||||
}
|
||||
}
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
|
|
@ -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);
|
||||
|
|
@ -182,8 +187,8 @@ void waves_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
|
|||
|
||||
// Affect the canvas on release:
|
||||
void waves_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)
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -197,7 +202,8 @@ void waves_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
|||
}
|
||||
|
||||
// Record the color from Tux Paint:
|
||||
void waves_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
|
||||
void waves_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
|
||||
Uint8 b ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -207,15 +213,17 @@ int waves_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_
|
|||
return 0;
|
||||
}
|
||||
|
||||
void waves_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void waves_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void waves_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void waves_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
int waves_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_PAINT);
|
||||
return (MODE_PAINT);
|
||||
}
|
||||
|
|
|
|||
181
magic/src/xor.c
181
magic/src/xor.c
|
|
@ -34,26 +34,23 @@
|
|||
#include "SDL_image.h"
|
||||
#include "SDL_mixer.h"
|
||||
|
||||
static Mix_Chunk * xor_snd;
|
||||
static Mix_Chunk *xor_snd;
|
||||
|
||||
Uint32 xor_api_version(void);
|
||||
int xor_init(magic_api * api);
|
||||
int xor_get_tool_count(magic_api * api);
|
||||
SDL_Surface * xor_get_icon(magic_api * api, int which);
|
||||
char * xor_get_name(magic_api * api, int which);
|
||||
char * xor_get_description(magic_api * api, int which, int mode);
|
||||
SDL_Surface *xor_get_icon(magic_api * api, int which);
|
||||
char *xor_get_name(magic_api * api, int which);
|
||||
char *xor_get_description(magic_api * api, int which, int mode);
|
||||
|
||||
void xor_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
|
||||
void xor_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
|
||||
void xor_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
|
||||
void xor_shutdown(magic_api * api);
|
||||
void xor_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
|
|
@ -62,123 +59,138 @@ void xor_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
|||
void xor_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
int xor_modes(magic_api * api, int which);
|
||||
|
||||
Uint32 xor_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
Uint32 xor_api_version(void)
|
||||
{
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
int xor_init(magic_api * api)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/xor.ogg",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/xor.ogg", api->data_directory);
|
||||
xor_snd = Mix_LoadWAV(fname);
|
||||
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
int xor_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
SDL_Surface * xor_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
SDL_Surface *xor_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/xor.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/xor.png", api->data_directory);
|
||||
|
||||
return(IMG_Load(fname));
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
char * xor_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
char *xor_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(strdup(gettext_noop("Xor Colors")));
|
||||
return (strdup(gettext_noop("Xor Colors")));
|
||||
}
|
||||
|
||||
char * xor_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode)
|
||||
char *xor_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode)
|
||||
{
|
||||
if (mode == MODE_PAINT)
|
||||
return(strdup(gettext_noop("Click and drag to draw a XOR effect")));
|
||||
return (strdup(gettext_noop("Click and drag to draw a XOR effect")));
|
||||
else
|
||||
return(strdup(gettext_noop("Click to draw a XOR effect on the whole picture")));
|
||||
return (strdup(gettext_noop("Click to draw a XOR effect on the whole picture")));
|
||||
}
|
||||
|
||||
static void do_xor(void * ptr, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
|
||||
static void do_xor(void *ptr, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
Uint8 r,g,b,xor;
|
||||
float hue,sat,val;
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
Uint8 r, g, b, xor;
|
||||
float hue, sat, val;
|
||||
Uint32 pixel;
|
||||
|
||||
SDL_GetRGB(api->getpixel(canvas,x,y),canvas->format,&r,&g,&b);
|
||||
api->rgbtohsv(r,g,b,&hue,&sat,&val);
|
||||
if (sat == 0) xor = (2*(int)hue+(x^y))%360;
|
||||
else xor = ((int)hue+(x^y))%360;
|
||||
api->hsvtorgb(xor,1,1,&r,&g,&b);
|
||||
pixel = SDL_MapRGB(canvas->format,r,g,b);
|
||||
api->putpixel(canvas,x,y,pixel);
|
||||
}
|
||||
static void do_xor_circle(void * ptr, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
|
||||
{
|
||||
magic_api * api = (magic_api *) ptr;
|
||||
int xx,yy;
|
||||
|
||||
for (yy = -16; yy < 16; yy++)
|
||||
{
|
||||
for (xx = -16; xx < 16; xx++)
|
||||
{
|
||||
if (api->in_circle(xx, yy, 16))
|
||||
{
|
||||
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)
|
||||
{
|
||||
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; }
|
||||
SDL_GetRGB(api->getpixel(canvas, x, y), canvas->format, &r, &g, &b);
|
||||
api->rgbtohsv(r, g, b, &hue, &sat, &val);
|
||||
if (sat == 0)
|
||||
xor = (2 * (int)hue + (x ^ y)) % 360;
|
||||
else
|
||||
xor = ((int)hue + (x ^ y)) % 360;
|
||||
api->hsvtorgb(xor, 1, 1, &r, &g, &b);
|
||||
pixel = SDL_MapRGB(canvas->format, r, g, b);
|
||||
api->putpixel(canvas, x, y, pixel);
|
||||
}
|
||||
|
||||
static void do_xor_circle(void *ptr, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
|
||||
{
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
int xx, yy;
|
||||
|
||||
for (yy = -16; yy < 16; yy++)
|
||||
{
|
||||
for (xx = -16; xx < 16; xx++)
|
||||
{
|
||||
if (api->in_circle(xx, yy, 16))
|
||||
{
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
update_rect->x = ox - 16;
|
||||
update_rect->y = oy - 16;
|
||||
update_rect->w = (x + 16) - update_rect->x;
|
||||
update_rect->h = (y + 16) - update_rect->h;
|
||||
|
||||
api->playsound(xor_snd,(x * 255) / canvas->w, 255);
|
||||
api->playsound(xor_snd, (x * 255) / canvas->w, 255);
|
||||
}
|
||||
|
||||
void xor_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x, int y, SDL_Rect * update_rect)
|
||||
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
if (mode == MODE_PAINT)
|
||||
xor_drag(api, which, canvas, last, x, y, x, y, update_rect);
|
||||
else
|
||||
{
|
||||
int xx, yy;
|
||||
{
|
||||
int xx, yy;
|
||||
|
||||
for (yy = 0; yy < canvas->h; yy++)
|
||||
for (xx = 0; xx < canvas->w; xx++)
|
||||
do_xor(api, which, canvas, last, xx, yy);
|
||||
for (yy = 0; yy < canvas->h; yy++)
|
||||
for (xx = 0; xx < canvas->w; xx++)
|
||||
do_xor(api, which, canvas, last, xx, yy);
|
||||
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
api->playsound(xor_snd,(x * 255) / canvas->w, 255);
|
||||
}
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
update_rect->h = canvas->h;
|
||||
api->playsound(xor_snd, (x * 255) / canvas->w, 255);
|
||||
}
|
||||
}
|
||||
|
||||
void xor_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)
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -188,7 +200,8 @@ void xor_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
|||
Mix_FreeChunk(xor_snd);
|
||||
}
|
||||
|
||||
void xor_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
|
||||
void xor_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
|
||||
Uint8 b ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -197,15 +210,17 @@ int xor_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UN
|
|||
return 0;
|
||||
}
|
||||
|
||||
void xor_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void xor_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void xor_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void xor_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
int xor_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return(MODE_PAINT | MODE_FULLSCREEN);
|
||||
return (MODE_PAINT | MODE_FULLSCREEN);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue