Ran indent.sh to re-indent all source files

This commit is contained in:
Bill Kendrick 2024-05-10 00:26:10 -07:00
parent fbb46751c6
commit 5bdbc2766b
27 changed files with 1591 additions and 1273 deletions

View file

@ -33,20 +33,21 @@
#include "SDL_mixer.h" #include "SDL_mixer.h"
#include "SDL2_gfxPrimitives.h" #include "SDL2_gfxPrimitives.h"
enum { enum
{
TOOL_WARP, TOOL_WARP,
NUM_TOOLS NUM_TOOLS
}; };
char * warp_icons[NUM_TOOLS] = { char *warp_icons[NUM_TOOLS] = {
"rainbow.png", // FIXME "rainbow.png", // FIXME
}; };
char * warp_snd_fnames[NUM_TOOLS] = { char *warp_snd_fnames[NUM_TOOLS] = {
"rainbow.ogg", // FIXME "rainbow.ogg", // FIXME
}; };
char * warp_tool_names[NUM_TOOLS] = { char *warp_tool_names[NUM_TOOLS] = {
gettext_noop("Warp"), gettext_noop("Warp"),
}; };
@ -54,7 +55,8 @@ char * warp_tool_names[NUM_TOOLS] = {
#define MAX_WARP_RADIUS 64 #define MAX_WARP_RADIUS 64
#define WARP_MESH_RES 16 #define WARP_MESH_RES 16
typedef struct warp_mesh_s { typedef struct warp_mesh_s
{
int scr_x; int scr_x;
int scr_y; int scr_y;
float pt_x; float pt_x;
@ -66,9 +68,9 @@ typedef struct warp_mesh_s {
static int warp_radius; static int warp_radius;
int warp_mesh_w, warp_mesh_h; int warp_mesh_w, warp_mesh_h;
float warp_dx, warp_dy; float warp_dx, warp_dy;
static warp_mesh_t * * warp_mesh = NULL; static warp_mesh_t **warp_mesh = NULL;
static Mix_Chunk * warp_snd[NUM_TOOLS]; static Mix_Chunk *warp_snd[NUM_TOOLS];
int warp_init(magic_api * api, Uint32 disabled_features); int warp_init(magic_api * api, Uint32 disabled_features);
Uint32 warp_api_version(void); Uint32 warp_api_version(void);
@ -80,18 +82,18 @@ char *warp_get_description(magic_api * api, int which, int mode);
static void warp_linecb(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y); static void warp_linecb(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
void warp_drag(magic_api * api, int which, SDL_Surface * canvas, void warp_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 warp_click(magic_api * api, int which, int mode, void warp_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 warp_release(magic_api * api, int which, void warp_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 warp_shutdown(magic_api * api); void warp_shutdown(magic_api * api);
void warp_set_color(magic_api * api, int which, SDL_Surface * canvas, void warp_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect); SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
int warp_requires_colors(magic_api * api, int which); int warp_requires_colors(magic_api * api, int which);
void warp_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas); void warp_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void warp_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas); void warp_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
@ -99,7 +101,7 @@ int warp_modes(magic_api * api, int which);
Uint8 warp_accepted_sizes(magic_api * api, int which, int mode); Uint8 warp_accepted_sizes(magic_api * api, int which, int mode);
Uint8 warp_default_size(magic_api * api, int which, int mode); Uint8 warp_default_size(magic_api * api, int which, int mode);
void warp_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, void warp_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect); SDL_Rect * update_rect);
Uint32 warp_api_version(void) Uint32 warp_api_version(void)
@ -113,7 +115,8 @@ int warp_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
int i; int i;
char fname[1024]; char fname[1024];
for (i = 0; i < NUM_TOOLS; i++) { for (i = 0; i < NUM_TOOLS; i++)
{
snprintf(fname, sizeof(fname), "%ssounds/magic/%s", api->data_directory, warp_snd_fnames[i]); snprintf(fname, sizeof(fname), "%ssounds/magic/%s", api->data_directory, warp_snd_fnames[i]);
warp_snd[i] = Mix_LoadWAV(fname); warp_snd[i] = Mix_LoadWAV(fname);
} }
@ -151,12 +154,12 @@ int warp_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
// Return our descriptions, localized: // Return our descriptions, localized:
char *warp_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED) char *warp_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
{ {
return (strdup(gettext_noop("Warp"))); // FIXME return (strdup(gettext_noop("Warp"))); // FIXME
} }
// Affect the canvas on drag: // Affect the canvas on drag:
void warp_drag(magic_api * api, int which, SDL_Surface * canvas, void warp_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)
{ {
int xx, yy; int xx, yy;
float stroke_len; float stroke_len;
@ -168,53 +171,55 @@ void warp_drag(magic_api * api, int which, SDL_Surface * canvas,
return; return;
stroke_len = sqrt((ox - x) * (ox - x) + (oy - y) * (oy - y)); stroke_len = sqrt((ox - x) * (ox - x) + (oy - y) * (oy - y));
warp_dx = (float) (x - ox) / stroke_len; warp_dx = (float)(x - ox) / stroke_len;
warp_dy = (float) (y - oy) / stroke_len; warp_dy = (float)(y - oy) / stroke_len;
api->line(api, which, canvas, last, ox, oy, x, y, 1, warp_linecb); api->line(api, which, canvas, last, ox, oy, x, y, 1, warp_linecb);
SDL_BlitSurface(last, NULL, canvas, NULL); SDL_BlitSurface(last, NULL, canvas, NULL);
for (yy = 0; yy < warp_mesh_h - 1; yy++) { for (yy = 0; yy < warp_mesh_h - 1; yy++)
for (xx = 0; xx < warp_mesh_w - 1; xx++) { {
for (xx = 0; xx < warp_mesh_w - 1; xx++)
{
/* FIXME: Just crib perspective_preview() from perspective.c? */ /* FIXME: Just crib perspective_preview() from perspective.c? */
/* /*
Sint16 pts_x[4]; Sint16 pts_x[4];
Sint16 pts_y[4]; Sint16 pts_y[4];
pts_x[0] = (Sint16) warp_mesh[yy][xx].pt_x; pts_x[0] = (Sint16) warp_mesh[yy][xx].pt_x;
pts_y[0] = (Sint16) warp_mesh[yy][xx].pt_y; pts_y[0] = (Sint16) warp_mesh[yy][xx].pt_y;
pts_x[1] = (Sint16) warp_mesh[yy][xx + 1].pt_x; pts_x[1] = (Sint16) warp_mesh[yy][xx + 1].pt_x;
pts_y[1] = (Sint16) warp_mesh[yy][xx + 1].pt_y; pts_y[1] = (Sint16) warp_mesh[yy][xx + 1].pt_y;
pts_x[2] = (Sint16) warp_mesh[yy + 1][xx].pt_x; pts_x[2] = (Sint16) warp_mesh[yy + 1][xx].pt_x;
pts_y[2] = (Sint16) warp_mesh[yy + 1][xx].pt_y; pts_y[2] = (Sint16) warp_mesh[yy + 1][xx].pt_y;
pts_x[3] = (Sint16) warp_mesh[yy + 1][xx + 1].pt_x; pts_x[3] = (Sint16) warp_mesh[yy + 1][xx + 1].pt_x;
pts_y[3] = (Sint16) warp_mesh[yy + 1][xx + 1].pt_y; pts_y[3] = (Sint16) warp_mesh[yy + 1][xx + 1].pt_y;
filledPolygonColor(canvas, pts_x, pts_y, 4, api->getpixel(last, warp_mesh[yy][xx].scr_x, warp_mesh[yy][xx].scr_y)); filledPolygonColor(canvas, pts_x, pts_y, 4, api->getpixel(last, warp_mesh[yy][xx].scr_x, warp_mesh[yy][xx].scr_y));
*/ */
} }
} }
/* /*
if (ox > x) { if (ox > x) {
int tmp; int tmp;
tmp = ox; tmp = ox;
ox = x; ox = x;
x = tmp; x = tmp;
} }
if (oy > y) { if (oy > y) {
int tmp; int tmp;
tmp = oy; tmp = oy;
oy = x; oy = x;
y = tmp; y = tmp;
} }
update_rect->x = x - warp_radius; update_rect->x = x - warp_radius;
update_rect->y = y - warp_radius; update_rect->y = y - warp_radius;
update_rect->w = warp_radius * 2; update_rect->w = warp_radius * 2;
update_rect->h = warp_radius * 2; update_rect->h = warp_radius * 2;
*/ */
update_rect->x = 0; update_rect->x = 0;
update_rect->y = 0; update_rect->y = 0;
@ -224,18 +229,22 @@ void warp_drag(magic_api * api, int which, SDL_Surface * canvas,
api->playsound(warp_snd[which], (x * 255) / canvas->w, 255); api->playsound(warp_snd[which], (x * 255) / canvas->w, 255);
} }
static void warp_linecb(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y) { static void warp_linecb(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
{
float intensity; float intensity;
magic_api *api = (magic_api *) ptr; magic_api *api = (magic_api *) ptr;
int mx, my; int mx, my;
float dx, dy; float dx, dy;
for (my = 0; my < warp_mesh_h; my++) { for (my = 0; my < warp_mesh_h; my++)
for (mx = 0; mx < warp_mesh_w; mx++) { {
if (api->in_circle(warp_mesh[my][mx].pt_x - x, warp_mesh[my][mx].pt_y - y, warp_radius)) { for (mx = 0; mx < warp_mesh_w; mx++)
dx = warp_mesh[my][mx].pt_x - (float) x; {
dy = warp_mesh[my][mx].pt_y - (float) y; if (api->in_circle(warp_mesh[my][mx].pt_x - x, warp_mesh[my][mx].pt_y - y, warp_radius))
intensity = ((float) warp_radius - sqrt(dx * dx + dy * dy)) / (float) warp_radius; {
dx = warp_mesh[my][mx].pt_x - (float)x;
dy = warp_mesh[my][mx].pt_y - (float)y;
intensity = ((float)warp_radius - sqrt(dx * dx + dy * dy)) / (float)warp_radius;
warp_mesh[my][mx].pt_x += (warp_dx * intensity); warp_mesh[my][mx].pt_x += (warp_dx * intensity);
warp_mesh[my][mx].pt_y += (warp_dy * intensity); warp_mesh[my][mx].pt_y += (warp_dy * intensity);
@ -247,7 +256,7 @@ static void warp_linecb(void *ptr, int which, SDL_Surface * canvas, SDL_Surface
// Affect the canvas on click: // Affect the canvas on click:
void warp_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED, void warp_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 (warp_mesh == NULL) if (warp_mesh == NULL)
return; return;
@ -258,10 +267,10 @@ void warp_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
} }
void warp_release(magic_api * api ATTRIBUTE_UNUSED, void warp_release(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED) int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{ {
} }
@ -270,16 +279,17 @@ void warp_shutdown(magic_api * api ATTRIBUTE_UNUSED)
{ {
int i; int i;
for (i = 0; i < NUM_TOOLS; i++) { for (i = 0; i < NUM_TOOLS; i++)
{
if (warp_snd[i] != NULL) if (warp_snd[i] != NULL)
Mix_FreeChunk(warp_snd[i]); Mix_FreeChunk(warp_snd[i]);
} }
} }
void warp_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, void warp_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last 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,
SDL_Rect * update_rect ATTRIBUTE_UNUSED) SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{ {
} }
@ -289,29 +299,34 @@ int warp_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_U
} }
void warp_switchin(magic_api * api ATTRIBUTE_UNUSED, void warp_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED) int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{ {
int x, y; int x, y;
warp_mesh_w = (canvas->w / WARP_MESH_RES); warp_mesh_w = (canvas->w / WARP_MESH_RES);
warp_mesh_h = (canvas->h / WARP_MESH_RES); warp_mesh_h = (canvas->h / WARP_MESH_RES);
warp_mesh = (warp_mesh_t * *) malloc(sizeof(warp_mesh_t *) * warp_mesh_h); warp_mesh = (warp_mesh_t * *)malloc(sizeof(warp_mesh_t *) * warp_mesh_h);
memset(warp_mesh, (int) NULL, sizeof(warp_mesh_t *) * warp_mesh_h); memset(warp_mesh, (int)NULL, sizeof(warp_mesh_t *) * warp_mesh_h);
if (warp_mesh == NULL) { if (warp_mesh == NULL)
{
fprintf(stderr, "warp cannot allocate warp_mesh!\n"); fprintf(stderr, "warp cannot allocate warp_mesh!\n");
return; return;
} }
for (y = 0; y < warp_mesh_h; y++) { for (y = 0; y < warp_mesh_h; y++)
{
warp_mesh[y] = (warp_mesh_t *) malloc(sizeof(warp_mesh_t) * warp_mesh_w); warp_mesh[y] = (warp_mesh_t *) malloc(sizeof(warp_mesh_t) * warp_mesh_w);
if (warp_mesh[y] == NULL) { if (warp_mesh[y] == NULL)
{
fprintf(stderr, "warp cannot allocate warp_mesh!\n"); fprintf(stderr, "warp cannot allocate warp_mesh!\n");
return; return;
} }
} }
for (y = 0; y < warp_mesh_h; y++) { for (y = 0; y < warp_mesh_h; y++)
for (x = 0; x < warp_mesh_w; x++) { {
for (x = 0; x < warp_mesh_w; x++)
{
warp_mesh[y][x].scr_x = x * WARP_MESH_RES; warp_mesh[y][x].scr_x = x * WARP_MESH_RES;
warp_mesh[y][x].scr_y = y * WARP_MESH_RES; warp_mesh[y][x].scr_y = y * WARP_MESH_RES;
warp_mesh[y][x].pt_x = x * WARP_MESH_RES; warp_mesh[y][x].pt_x = x * WARP_MESH_RES;
@ -321,17 +336,21 @@ void warp_switchin(magic_api * api ATTRIBUTE_UNUSED,
} }
void warp_switchout(magic_api * api ATTRIBUTE_UNUSED, void warp_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED) int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{ {
int y; int y;
/* FIXME: Crashes! */ /* FIXME: Crashes! */
return; return;
if (warp_mesh != NULL) { if (warp_mesh != NULL)
for (y = 0; y < warp_mesh_h; y++) { {
if (warp_mesh[y] != NULL) { for (y = 0; y < warp_mesh_h; y++)
printf("freeing mesh row %d\n", y); fflush(stdout); {
if (warp_mesh[y] != NULL)
{
printf("freeing mesh row %d\n", y);
fflush(stdout);
free(warp_mesh); free(warp_mesh);
warp_mesh[y] = NULL; warp_mesh[y] = NULL;
} }
@ -358,8 +377,8 @@ Uint8 warp_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UN
} }
void warp_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, void warp_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size,
SDL_Rect * update_rect ATTRIBUTE_UNUSED) SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{ {
warp_radius = (size * MAX_WARP_RADIUS) / NUM_WARP_SIZES; warp_radius = (size * MAX_WARP_RADIUS) / NUM_WARP_SIZES;
} }

View file

@ -152,19 +152,20 @@ int blocks_etc_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_U
// Return our order // Return our order
int blocks_etc_get_order(int which) int blocks_etc_get_order(int which)
{ {
switch (which) { switch (which)
case TOOL_BLOCKS: {
return 4; case TOOL_BLOCKS:
break; return 4;
case TOOL_CHALK: break;
return 5; case TOOL_CHALK:
break; return 5;
case TOOL_DRIP: break;
return 6; case TOOL_DRIP:
break; return 6;
default: break;
return 0; default:
break; return 0;
break;
} }
} }

View file

@ -86,7 +86,8 @@ void checkerboard_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUT
checkerboard_b = b; checkerboard_b = b;
} }
int checkerboard_init(magic_api * api, Uint8 disabled_features ATTRIBUTE_UNUSED, Uint8 complexity_level ATTRIBUTE_UNUSED) int checkerboard_init(magic_api * api, Uint8 disabled_features ATTRIBUTE_UNUSED,
Uint8 complexity_level ATTRIBUTE_UNUSED)
{ {
char fname[1024]; char fname[1024];

View file

@ -100,9 +100,10 @@ int clone_init(magic_api * api, Uint8 disabled_features ATTRIBUTE_UNUSED, Uint8
{ {
char fname[1024]; char fname[1024];
if (complexity_level == MAGIC_COMPLEXITY_NOVICE) { if (complexity_level == MAGIC_COMPLEXITY_NOVICE)
{
/* Clone tool not available in "novice" mode */ /* Clone tool not available in "novice" mode */
return(0); return (0);
} }
snprintf(fname, sizeof(fname), "%ssounds/magic/clone_start.ogg", api->data_directory); snprintf(fname, sizeof(fname), "%ssounds/magic/clone_start.ogg", api->data_directory);

View file

@ -52,7 +52,7 @@ char *colorsep_descrs[NUM_TOOLS] = {
char *colorsep_descr_anaglyph_simple = char *colorsep_descr_anaglyph_simple =
gettext_noop gettext_noop
("Click and drag left and right to separate your picture's red and cyan, to make anaglyphs you can view with 3D glasses!"); ("Click and drag left and right to separate your picture's red and cyan, to make anaglyphs you can view with 3D glasses!");
Mix_Chunk *snd_effects[NUM_TOOLS]; Mix_Chunk *snd_effects[NUM_TOOLS];
int colorsep_click_x, colorsep_click_y; int colorsep_click_x, colorsep_click_y;
@ -62,8 +62,9 @@ int colorsep_complexity;
/* 3D Glasses mode (except in Novice complexity setting) /* 3D Glasses mode (except in Novice complexity setting)
offers different variations offers different variations
(Suggested by O'Hare The Rabbit) */ (Suggested by O'Hare The Rabbit) */
enum { enum
COLORSEP_3DGLASS_VARIATION_RED_CYAN, // default; and the only option in Novice complexity {
COLORSEP_3DGLASS_VARIATION_RED_CYAN, // default; and the only option in Novice complexity
COLORSEP_3DGLASS_VARIATION_RED_BLUE, COLORSEP_3DGLASS_VARIATION_RED_BLUE,
// COLORSEP_3DGLASS_VARIATION_ANACHROME, // dark red / dark blue // COLORSEP_3DGLASS_VARIATION_ANACHROME, // dark red / dark blue
COLORSEP_3DGLASS_VARIATION_RED_GREEN, COLORSEP_3DGLASS_VARIATION_RED_GREEN,
@ -155,9 +156,12 @@ int colorsep_get_order(int which)
char *colorsep_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED) char *colorsep_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
{ {
if (which == COLORSEP_TOOL_3DGLASSES && colorsep_complexity == MAGIC_COMPLEXITY_NOVICE) { if (which == COLORSEP_TOOL_3DGLASSES && colorsep_complexity == MAGIC_COMPLEXITY_NOVICE)
{
return strdup(colorsep_descr_anaglyph_simple); return strdup(colorsep_descr_anaglyph_simple);
} else { }
else
{
return strdup(gettext(colorsep_descrs[which])); return strdup(gettext(colorsep_descrs[which]));
} }
} }
@ -254,7 +258,8 @@ void colorsep_apply(magic_api * api, int which, SDL_Surface * canvas,
{ {
r = g = b = 128; r = g = b = 128;
if (colorsep_3dglass_variation == COLORSEP_3DGLASS_VARIATION_RED_CYAN) { if (colorsep_3dglass_variation == COLORSEP_3DGLASS_VARIATION_RED_CYAN)
{
/* Split red apart from green & blue (cyan) */ /* Split red apart from green & blue (cyan) */
/* RR GG BB */ /* RR GG BB */
/* 1 2 2 */ /* 1 2 2 */
@ -265,7 +270,9 @@ void colorsep_apply(magic_api * api, int which, SDL_Surface * canvas,
// cyan // cyan
g = g2; g = g2;
b = b2; b = b2;
} else if (colorsep_3dglass_variation == COLORSEP_3DGLASS_VARIATION_RED_BLUE) { }
else if (colorsep_3dglass_variation == COLORSEP_3DGLASS_VARIATION_RED_BLUE)
{
/* Split red apart blue */ /* Split red apart blue */
/* RR GG BB */ /* RR GG BB */
/* 1 12 2 */ /* 1 12 2 */
@ -286,7 +293,9 @@ void colorsep_apply(magic_api * api, int which, SDL_Surface * canvas,
// r = r1 / 2; // r = r1 / 2;
// g = (g1 + g2 + r1 + b2) / 4; // g = (g1 + g2 + r1 + b2) / 4;
// b = b1 / 2; // b = b1 / 2;
} else if (colorsep_3dglass_variation == COLORSEP_3DGLASS_VARIATION_RED_GREEN) { }
else if (colorsep_3dglass_variation == COLORSEP_3DGLASS_VARIATION_RED_GREEN)
{
/* Split red apart green */ /* Split red apart green */
/* RR GG BB */ /* RR GG BB */
/* 1 2 12 */ /* 1 2 12 */
@ -299,7 +308,9 @@ void colorsep_apply(magic_api * api, int which, SDL_Surface * canvas,
// blue shared // blue shared
b = (b1 + b2) / 2; b = (b1 + b2) / 2;
} else if (colorsep_3dglass_variation == COLORSEP_3DGLASS_VARIATION_MAGENTA_CYAN) { }
else if (colorsep_3dglass_variation == COLORSEP_3DGLASS_VARIATION_MAGENTA_CYAN)
{
/* Split magenta apart from cyan */ /* Split magenta apart from cyan */
/* RR GG BB */ /* RR GG BB */
/* 1 2 12 */ /* 1 2 12 */
@ -394,11 +405,14 @@ void colorsep_switchout(magic_api * api ATTRIBUTE_UNUSED,
Uint8 colorsep_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED) Uint8 colorsep_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
{ {
if (which == COLORSEP_TOOL_3DGLASSES && colorsep_complexity > MAGIC_COMPLEXITY_NOVICE) { if (which == COLORSEP_TOOL_3DGLASSES && colorsep_complexity > MAGIC_COMPLEXITY_NOVICE)
{
/* 3D Glasses mode (in all complexity levels except novice) /* 3D Glasses mode (in all complexity levels except novice)
uses (abuses) the size option to change styles */ uses (abuses) the size option to change styles */
return NUM_COLORSEP_3DGLASS_VARIATIONS; return NUM_COLORSEP_3DGLASS_VARIATIONS;
} else { }
else
{
/* All other tools (and 3D Glasses in novice complexity) /* All other tools (and 3D Glasses in novice complexity)
do not use the size option */ do not use the size option */
return 0; return 0;

View file

@ -20,7 +20,8 @@
#include "SDL_image.h" #include "SDL_image.h"
#include "SDL_mixer.h" #include "SDL_mixer.h"
enum { enum
{
/* Use the chosen color for the non-white pixels */ /* Use the chosen color for the non-white pixels */
TOOL_DITHER_VIA_COLOR, TOOL_DITHER_VIA_COLOR,
/* Use the image's color (hue/saturation w/ low value) for the non-white pixels */ /* Use the image's color (hue/saturation w/ low value) for the non-white pixels */
@ -28,28 +29,30 @@ enum {
NUM_TOOLS NUM_TOOLS
}; };
char * dither_names[NUM_TOOLS] = { char *dither_names[NUM_TOOLS] = {
gettext_noop("Dither"), gettext_noop("Dither"),
gettext_noop("Dither (Keep Color)"), gettext_noop("Dither (Keep Color)"),
}; };
char * dither_descr[NUM_TOOLS][2] = { char *dither_descr[NUM_TOOLS][2] = {
{ {
gettext_noop("Click and drag to replace parts of your image with a dithered pattern of dots in your chosen color."), gettext_noop("Click and drag to replace parts of your image with a dithered pattern of dots in your chosen color."),
gettext_noop("Click to replace your entire image with a dithered pattern of dots in your chosen color."), gettext_noop("Click to replace your entire image with a dithered pattern of dots in your chosen color."),
}, },
{ {
gettext_noop("Click and drag to replace parts of your image with a dithered pattern of dots using the picture's original colors."), gettext_noop
gettext_noop("Click to replace your entire image with a dithered pattern of dots using the picture's original colors."), ("Click and drag to replace parts of your image with a dithered pattern of dots using the picture's original colors."),
}, gettext_noop
("Click to replace your entire image with a dithered pattern of dots using the picture's original colors."),
},
}; };
char * dither_icon_filenames[NUM_TOOLS] = { char *dither_icon_filenames[NUM_TOOLS] = {
"dither.png", "dither.png",
"dither_keep_color.png", "dither_keep_color.png",
}; };
char * dither_snd_filenames[NUM_TOOLS] = { char *dither_snd_filenames[NUM_TOOLS] = {
"dither.ogg", "dither.ogg",
"dither_keep_color.ogg", "dither_keep_color.ogg",
}; };
@ -63,17 +66,15 @@ Mix_Chunk *snd_effects[NUM_TOOLS];
Uint8 dither_sizes[NUM_TOOLS]; Uint8 dither_sizes[NUM_TOOLS];
Uint32 dither_white, dither_black, dither_color; Uint32 dither_white, dither_black, dither_color;
Uint8 * dither_touched; Uint8 *dither_touched;
float * dither_vals; float *dither_vals;
int dither_click_mode; int dither_click_mode;
void dither_drag(magic_api * api, int which, SDL_Surface * canvas, void dither_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int old_x, int old_y, int x, int y, SDL_Surface * snapshot, int old_x, int old_y, int x, int y, SDL_Rect * update_rect);
SDL_Rect * update_rect);
void dither_line_callback(void *pointer, int which, SDL_Surface * canvas, void dither_line_callback(void *pointer, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
SDL_Surface * snapshot, int x, int y);
Uint32 dither_api_version(void); Uint32 dither_api_version(void);
int dither_init(magic_api * api, Uint8 disabled_features, Uint8 complexity_level); int dither_init(magic_api * api, Uint8 disabled_features, Uint8 complexity_level);
@ -87,17 +88,13 @@ int dither_requires_colors(magic_api * api, int which);
void dither_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas); void dither_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void dither_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas); void dither_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
void dither_set_size(magic_api * api, int which, int mode, void dither_set_size(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * snapshot, SDL_Surface * canvas, SDL_Surface * snapshot, Uint8 size, SDL_Rect * update_rect);
Uint8 size, SDL_Rect * update_rect);
void dither_set_color(magic_api * api, int which, void dither_set_color(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, SDL_Surface * canvas, SDL_Surface * snapshot, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
void dither_release(magic_api * api, int which, void dither_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
SDL_Rect * update_rect);
void dither_click(magic_api * api, int which, int mode, void dither_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
SDL_Rect * update_rect);
void dither_shutdown(magic_api * api); void dither_shutdown(magic_api * api);
Uint8 dither_default_size(magic_api * api, int which, int mode); Uint8 dither_default_size(magic_api * api, int which, int mode);
Uint8 dither_accepted_sizes(magic_api * api, int which, int mode); Uint8 dither_accepted_sizes(magic_api * api, int which, int mode);
@ -114,9 +111,9 @@ int dither_init(magic_api * api, Uint8 disabled_features ATTRIBUTE_UNUSED, Uint8
int i; int i;
char filename[1024]; char filename[1024];
for (i = 0; i < NUM_TOOLS; i++) { for (i = 0; i < NUM_TOOLS; i++)
snprintf(filename, sizeof(filename), "%ssounds/magic/%s", api->data_directory, {
dither_snd_filenames[i]); snprintf(filename, sizeof(filename), "%ssounds/magic/%s", api->data_directory, dither_snd_filenames[i]);
snd_effects[i] = Mix_LoadWAV(filename); snd_effects[i] = Mix_LoadWAV(filename);
} }
@ -138,8 +135,7 @@ SDL_Surface *dither_get_icon(magic_api * api, int which)
{ {
char filename[1024]; char filename[1024];
snprintf(filename, sizeof(filename), "%simages/magic/%s", snprintf(filename, sizeof(filename), "%simages/magic/%s", api->data_directory, dither_icon_filenames[which]);
api->data_directory, dither_icon_filenames[which]);
return (IMG_Load(filename)); return (IMG_Load(filename));
} }
@ -165,9 +161,12 @@ int dither_get_order(int which)
char *dither_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode) char *dither_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode)
{ {
if (mode == MODE_PAINT) { if (mode == MODE_PAINT)
{
return strdup(gettext(dither_descr[which][0])); return strdup(gettext(dither_descr[which][0]));
} else /* if (mode == MODE_FULLSCREEN) */ { }
else /* if (mode == MODE_FULLSCREEN) */
{
return strdup(gettext(dither_descr[which][1])); return strdup(gettext(dither_descr[which][1]));
} }
} }
@ -225,8 +224,7 @@ void dither_shutdown(magic_api * api ATTRIBUTE_UNUSED)
void void
dither_click(magic_api * api, int which, int mode, dither_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
SDL_Rect * update_rect)
{ {
int xx, yy; int xx, yy;
Uint8 r, g, b; Uint8 r, g, b;
@ -246,7 +244,8 @@ dither_click(magic_api * api, int which, int mode,
dither_touched[yy * canvas->w + xx] = 1; dither_touched[yy * canvas->w + xx] = 1;
SDL_GetRGB(api->getpixel(snapshot, xx, yy), snapshot->format, &r, &g, &b); SDL_GetRGB(api->getpixel(snapshot, xx, yy), snapshot->format, &r, &g, &b);
dither_vals[yy * canvas->w + xx] = (api->sRGB_to_linear(r) + api->sRGB_to_linear(g) + api->sRGB_to_linear(b)) / 3.0; dither_vals[yy * canvas->w + xx] =
(api->sRGB_to_linear(r) + api->sRGB_to_linear(g) + api->sRGB_to_linear(b)) / 3.0;
if (xx == 0) if (xx == 0)
{ {
@ -270,18 +269,14 @@ dither_click(magic_api * api, int which, int mode,
void void
dither_drag(magic_api * api, int which, dither_drag(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, SDL_Surface * canvas, SDL_Surface * snapshot, int old_x, int old_y, int x, int y, SDL_Rect * update_rect)
int old_x, int old_y, int x, int y,
SDL_Rect * update_rect)
{ {
int dither_size; int dither_size;
SDL_LockSurface(snapshot); SDL_LockSurface(snapshot);
SDL_LockSurface(canvas); SDL_LockSurface(canvas);
api->line((void *) api, which, canvas, snapshot, api->line((void *)api, which, canvas, snapshot, old_x, old_y, x, y, 1, dither_line_callback);
old_x, old_y, x, y, 1,
dither_line_callback);
SDL_UnlockSurface(canvas); SDL_UnlockSurface(canvas);
SDL_UnlockSurface(snapshot); SDL_UnlockSurface(snapshot);
@ -317,11 +312,10 @@ dither_drag(magic_api * api, int which,
* [ . 5 . . ] * [ . 5 . . ]
*/ */
int dither_x_pos[6] = { 1, 2, -1, 0, 1, 0 }; int dither_x_pos[6] = { 1, 2, -1, 0, 1, 0 };
int dither_y_pos[6] = { 0, 0, 1, 1, 1, 2 }; int dither_y_pos[6] = { 0, 0, 1, 1, 1, 2 };
void dither_release(magic_api * api, int which, void dither_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
SDL_Rect * update_rect)
{ {
Uint8 r, g, b; Uint8 r, g, b;
float val, err, h, s, v; float val, err, h, s, v;
@ -334,7 +328,8 @@ void dither_release(magic_api * api, int which,
if (dither_touched[y * canvas->w + x]) if (dither_touched[y * canvas->w + x])
{ {
val = dither_vals[y * canvas->w + x]; val = dither_vals[y * canvas->w + x];
if (val >= 0.5) { if (val >= 0.5)
{
api->putpixel(canvas, x, y, dither_white); api->putpixel(canvas, x, y, dither_white);
err = val - 1.0; err = val - 1.0;
} }
@ -383,14 +378,15 @@ void dither_release(magic_api * api, int which,
update_rect->w = canvas->w; update_rect->w = canvas->w;
update_rect->h = canvas->h; update_rect->h = canvas->h;
if (dither_click_mode == MODE_PAINT) { if (dither_click_mode == MODE_PAINT)
{
api->stopsound(); api->stopsound();
} }
} }
void dither_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, void dither_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED,
Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED) Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{ {
if (r <= 240 || g <= 240 || b <= 240) if (r <= 240 || g <= 240 || b <= 240)
{ {
@ -404,15 +400,14 @@ void dither_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUS
} }
void dither_set_size(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED, void dither_set_size(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * snapshot ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * snapshot ATTRIBUTE_UNUSED,
Uint8 size, SDL_Rect * update_rect ATTRIBUTE_UNUSED) Uint8 size, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{ {
dither_sizes[which] = size * DITHER_SIZE_SCALE; dither_sizes[which] = size * DITHER_SIZE_SCALE;
} }
void dither_line_callback(void *pointer, int which, SDL_Surface * canvas, void dither_line_callback(void *pointer, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y)
SDL_Surface * snapshot, int x, int y)
{ {
magic_api *api = (magic_api *) pointer; magic_api *api = (magic_api *) pointer;
int xx, yy, dither_size; int xx, yy, dither_size;
@ -451,7 +446,7 @@ void dither_line_callback(void *pointer, int which, SDL_Surface * canvas,
void dither_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, void dither_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas) SDL_Surface * canvas)
{ {
if (dither_touched == NULL) if (dither_touched == NULL)
{ {
@ -459,7 +454,7 @@ void dither_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSE
} }
if (dither_vals == NULL) if (dither_vals == NULL)
{ {
dither_vals = (float *) malloc(sizeof(float) * canvas->h * canvas->w); dither_vals = (float *)malloc(sizeof(float) * canvas->h * canvas->w);
} }
dither_white = SDL_MapRGB(canvas->format, 255, 255, 255); dither_white = SDL_MapRGB(canvas->format, 255, 255, 255);
@ -467,6 +462,6 @@ void dither_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSE
} }
void dither_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, void dither_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED) SDL_Surface * canvas ATTRIBUTE_UNUSED)
{ {
} }

View file

@ -104,7 +104,7 @@ int foam_init(magic_api * api, Uint8 disabled_features ATTRIBUTE_UNUSED, Uint8 c
if (foam_7 == NULL || foam_5 == NULL || foam_3 == NULL || foam_1 == NULL) if (foam_7 == NULL || foam_5 == NULL || foam_3 == NULL || foam_1 == NULL)
{ {
fprintf(stderr, "Cannot scale %s\n", fname); fprintf(stderr, "Cannot scale %s\n", fname);
return(0); return (0);
} }
return (1); return (1);

View file

@ -163,21 +163,25 @@ int fretwork_init(magic_api * api, Uint8 disabled_features ATTRIBUTE_UNUSED, Uin
fretwork_four_back = IMG_Load(fretwork_images[2]); fretwork_four_back = IMG_Load(fretwork_images[2]);
fretwork_corner_back = IMG_Load(fretwork_images[3]); fretwork_corner_back = IMG_Load(fretwork_images[3]);
if (fretwork_one == NULL || fretwork_one_back == NULL) { if (fretwork_one == NULL || fretwork_one_back == NULL)
{
fprintf(stderr, "Cannot load %s\n", fretwork_images[0]); fprintf(stderr, "Cannot load %s\n", fretwork_images[0]);
return(0); return (0);
} }
if (fretwork_three == NULL || fretwork_three_back == NULL) { if (fretwork_three == NULL || fretwork_three_back == NULL)
{
fprintf(stderr, "Cannot load %s\n", fretwork_images[1]); fprintf(stderr, "Cannot load %s\n", fretwork_images[1]);
return(0); return (0);
} }
if (fretwork_four == NULL || fretwork_four_back == NULL) { if (fretwork_four == NULL || fretwork_four_back == NULL)
{
fprintf(stderr, "Cannot load %s\n", fretwork_images[2]); fprintf(stderr, "Cannot load %s\n", fretwork_images[2]);
return(0); return (0);
} }
if (fretwork_corner == NULL || fretwork_corner_back == NULL) { if (fretwork_corner == NULL || fretwork_corner_back == NULL)
{
fprintf(stderr, "Cannot load %s\n", fretwork_images[3]); fprintf(stderr, "Cannot load %s\n", fretwork_images[3]);
return(0); return (0);
} }
img_w = fretwork_one->w; img_w = fretwork_one->w;

View file

@ -78,7 +78,8 @@ static int **glasstile_hit;
static int glasstile_hit_xsize; static int glasstile_hit_xsize;
static int glasstile_hit_ysize; static int glasstile_hit_ysize;
int glasstile_init(magic_api * api, Uint8 disabled_features ATTRIBUTE_UNUSED /* FIXME */, Uint8 complexity_level ATTRIBUTE_UNUSED) int glasstile_init(magic_api * api, Uint8 disabled_features ATTRIBUTE_UNUSED /* FIXME */ ,
Uint8 complexity_level ATTRIBUTE_UNUSED)
{ {
char fname[1024]; char fname[1024];

View file

@ -53,7 +53,7 @@ const char *descs[NUM_TOOLS][2] = {
{ {
gettext_noop("Click and drag to turn your drawing into a newspaper."), gettext_noop("Click and drag to turn your drawing into a newspaper."),
gettext_noop("Click to turn your drawing into a newspaper."), gettext_noop("Click to turn your drawing into a newspaper."),
}, },
}; };
Mix_Chunk *snd_effect[NUM_TOOLS]; Mix_Chunk *snd_effect[NUM_TOOLS];

View file

@ -171,7 +171,8 @@ Uint32 mosaic_shaped_api_version(void)
} }
//Load sounds //Load sounds
int mosaic_shaped_init(magic_api * api, Uint8 disabled_features ATTRIBUTE_UNUSED, Uint8 complexity_level ATTRIBUTE_UNUSED) int mosaic_shaped_init(magic_api * api, Uint8 disabled_features ATTRIBUTE_UNUSED,
Uint8 complexity_level ATTRIBUTE_UNUSED)
{ {
int i; int i;
char fname[1024]; char fname[1024];

File diff suppressed because it is too large Load diff

View file

@ -19,32 +19,34 @@
#include "SDL_image.h" #include "SDL_image.h"
#include "SDL_mixer.h" #include "SDL_mixer.h"
enum { enum
{
TOOL_POLYFILL, TOOL_POLYFILL,
NUM_TOOLS NUM_TOOLS
}; };
char * polyfill_names[NUM_TOOLS] = { char *polyfill_names[NUM_TOOLS] = {
gettext_noop("Filled Polygon"), gettext_noop("Filled Polygon"),
}; };
char * polyfill_descr[NUM_TOOLS] = { char *polyfill_descr[NUM_TOOLS] = {
gettext_noop("Click multiple times in your picture to create a filled polygon. You may drag control points to alter the shape. Click the first point to complete the shape."), gettext_noop
("Click multiple times in your picture to create a filled polygon. You may drag control points to alter the shape. Click the first point to complete the shape."),
}; };
char * polyfill_icon_filenames[NUM_TOOLS] = { char *polyfill_icon_filenames[NUM_TOOLS] = {
"polyfill.png", "polyfill.png",
}; };
char * polyfill_snd_filenames[NUM_TOOLS] = { char *polyfill_snd_filenames[NUM_TOOLS] = {
"dither.ogg", // FIXME "dither.ogg", // FIXME
}; };
#define SNAP_SIZE 16 #define SNAP_SIZE 16
#define MAX_PTS 17 #define MAX_PTS 17
SDL_Surface * polyfill_snapshot = NULL; SDL_Surface *polyfill_snapshot = NULL;
int polyfill_pt_x[MAX_PTS]; int polyfill_pt_x[MAX_PTS];
int polyfill_pt_y[MAX_PTS]; int polyfill_pt_y[MAX_PTS];
int polyfill_num_pts = 0; int polyfill_num_pts = 0;
@ -58,11 +60,9 @@ Uint32 polyfill_color, polyfill_color_red, polyfill_color_green;
void polyfill_drag(magic_api * api, int which, SDL_Surface * canvas, void polyfill_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int old_x, int old_y, int x, int y, SDL_Surface * snapshot, int old_x, int old_y, int x, int y, SDL_Rect * update_rect);
SDL_Rect * update_rect);
void polyfill_line_callback(void *pointer, int which, SDL_Surface * canvas, void polyfill_line_callback(void *pointer, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
SDL_Surface * snapshot, int x, int y);
void polyfill_draw_preview(magic_api * api, SDL_Surface * canvas, int show_handles); void polyfill_draw_preview(magic_api * api, SDL_Surface * canvas, int show_handles);
void polyfill_draw_final(magic_api * api, SDL_Surface * canvas); void polyfill_draw_final(magic_api * api, SDL_Surface * canvas);
@ -78,9 +78,9 @@ int polyfill_init(magic_api * api, Uint8 disabled_features, Uint8 complexity_lev
int i; int i;
char filename[1024]; char filename[1024];
for (i = 0; i < NUM_TOOLS; i++) { for (i = 0; i < NUM_TOOLS; i++)
snprintf(filename, sizeof(filename), "%ssounds/magic/%s", api->data_directory, {
polyfill_snd_filenames[i]); snprintf(filename, sizeof(filename), "%ssounds/magic/%s", api->data_directory, polyfill_snd_filenames[i]);
snd_effects[i] = Mix_LoadWAV(filename); snd_effects[i] = Mix_LoadWAV(filename);
} }
@ -97,8 +97,7 @@ SDL_Surface *polyfill_get_icon(magic_api * api, int which)
{ {
char filename[1024]; char filename[1024];
snprintf(filename, sizeof(filename), "%simages/magic/%s", snprintf(filename, sizeof(filename), "%simages/magic/%s", api->data_directory, polyfill_icon_filenames[which]);
api->data_directory, polyfill_icon_filenames[which]);
return (IMG_Load(filename)); return (IMG_Load(filename));
} }
@ -118,7 +117,7 @@ int polyfill_get_group(magic_api * api, int which)
int polyfill_get_order(int which) int polyfill_get_order(int which)
{ {
return 610 + which; // FIXME return 610 + which; // FIXME
} }
@ -164,7 +163,8 @@ void polyfill_shutdown(magic_api * api)
} }
} }
if (polyfill_snapshot != NULL) { if (polyfill_snapshot != NULL)
{
SDL_FreeSurface(polyfill_snapshot); SDL_FreeSurface(polyfill_snapshot);
polyfill_snapshot = NULL; polyfill_snapshot = NULL;
} }
@ -172,8 +172,7 @@ void polyfill_shutdown(magic_api * api)
void void
polyfill_click(magic_api * api, int which, int mode, polyfill_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
SDL_Rect * update_rect)
{ {
int i; int i;
@ -183,21 +182,24 @@ polyfill_click(magic_api * api, int which, int mode,
/* See if we're clicking a pre-existing point, to edit it? */ /* See if we're clicking a pre-existing point, to edit it? */
polyfill_editing = MAX_PTS; polyfill_editing = MAX_PTS;
for (i = 0; i < polyfill_num_pts && polyfill_editing == MAX_PTS; i++) { for (i = 0; i < polyfill_num_pts && polyfill_editing == MAX_PTS; i++)
if (abs(x - polyfill_pt_x[i]) <= SNAP_SIZE && {
abs(y - polyfill_pt_y[i]) <= SNAP_SIZE) { if (abs(x - polyfill_pt_x[i]) <= SNAP_SIZE && abs(y - polyfill_pt_y[i]) <= SNAP_SIZE)
{
polyfill_editing = i; polyfill_editing = i;
} }
} }
if (polyfill_editing != MAX_PTS) { if (polyfill_editing != MAX_PTS)
{
printf("Clicked %d to edit it\n", polyfill_editing); printf("Clicked %d to edit it\n", polyfill_editing);
polyfill_draw_preview(api, canvas, 1); polyfill_draw_preview(api, canvas, 1);
return; return;
} }
/* Trying to add a new point? */ /* Trying to add a new point? */
if (polyfill_num_pts < MAX_PTS) { if (polyfill_num_pts < MAX_PTS)
{
printf("Adding new point %d\n", polyfill_num_pts); printf("Adding new point %d\n", polyfill_num_pts);
polyfill_pt_x[polyfill_num_pts] = x; polyfill_pt_x[polyfill_num_pts] = x;
@ -207,7 +209,9 @@ polyfill_click(magic_api * api, int which, int mode,
/* Add the new point */ /* Add the new point */
polyfill_drag(api, which, canvas, snapshot, x, y, x, y, update_rect); polyfill_drag(api, which, canvas, snapshot, x, y, x, y, update_rect);
} else { }
else
{
/* Out of points! */ /* Out of points! */
printf("Out of space for new points!\n"); printf("Out of space for new points!\n");
} }
@ -216,9 +220,7 @@ polyfill_click(magic_api * api, int which, int mode,
void void
polyfill_drag(magic_api * api, int which, polyfill_drag(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, SDL_Surface * canvas, SDL_Surface * snapshot, int old_x, int old_y, int x, int y, SDL_Rect * update_rect)
int old_x, int old_y, int x, int y,
SDL_Rect * update_rect)
{ {
polyfill_dragged = 1; polyfill_dragged = 1;
@ -236,7 +238,8 @@ polyfill_drag(magic_api * api, int which,
update_rect->h = canvas->h; update_rect->h = canvas->h;
} }
void polyfill_draw_preview(magic_api * api, SDL_Surface * canvas, int show_handles) { void polyfill_draw_preview(magic_api * api, SDL_Surface * canvas, int show_handles)
{
int i, xx, yy, max; int i, xx, yy, max;
SDL_Rect dest; SDL_Rect dest;
@ -245,24 +248,28 @@ void polyfill_draw_preview(magic_api * api, SDL_Surface * canvas, int show_handl
SDL_BlitSurface(polyfill_snapshot, NULL, canvas, NULL); SDL_BlitSurface(polyfill_snapshot, NULL, canvas, NULL);
for (i = 0; i < polyfill_num_pts - 1; i++) { for (i = 0; i < polyfill_num_pts - 1; i++)
api->line((void *) api, 0 /* which */, canvas, NULL /* snapshot */, {
api->line((void *)api, 0 /* which */ , canvas, NULL /* snapshot */ ,
polyfill_pt_x[i], polyfill_pt_y[i], polyfill_pt_x[i], polyfill_pt_y[i],
polyfill_pt_x[i + 1], polyfill_pt_y[i + 1], polyfill_pt_x[i + 1], polyfill_pt_y[i + 1], 1, polyfill_line_callback);
1,
polyfill_line_callback);
} }
if (show_handles) { if (show_handles)
for (i = 1; i < polyfill_num_pts - 1; i++) { {
for (yy = -4; yy <= 4; yy++) { for (i = 1; i < polyfill_num_pts - 1; i++)
for (xx = -4; xx <= 4; xx++) { {
for (yy = -4; yy <= 4; yy++)
{
for (xx = -4; xx <= 4; xx++)
{
api->xorpixel(canvas, polyfill_pt_x[i] + xx, polyfill_pt_y[i] + yy); api->xorpixel(canvas, polyfill_pt_x[i] + xx, polyfill_pt_y[i] + yy);
} }
} }
} }
if (polyfill_num_pts > 0) { if (polyfill_num_pts > 0)
{
dest.x = polyfill_pt_x[0] - SNAP_SIZE; dest.x = polyfill_pt_x[0] - SNAP_SIZE;
dest.y = polyfill_pt_y[0] - SNAP_SIZE; dest.y = polyfill_pt_y[0] - SNAP_SIZE;
dest.w = SNAP_SIZE * 2; dest.w = SNAP_SIZE * 2;
@ -270,7 +277,8 @@ void polyfill_draw_preview(magic_api * api, SDL_Surface * canvas, int show_handl
SDL_FillRect(canvas, &dest, polyfill_color_green); SDL_FillRect(canvas, &dest, polyfill_color_green);
} }
if (polyfill_num_pts > 1) { if (polyfill_num_pts > 1)
{
dest.x = polyfill_pt_x[polyfill_num_pts - 1] - SNAP_SIZE; dest.x = polyfill_pt_x[polyfill_num_pts - 1] - SNAP_SIZE;
dest.y = polyfill_pt_y[polyfill_num_pts - 1] - SNAP_SIZE; dest.y = polyfill_pt_y[polyfill_num_pts - 1] - SNAP_SIZE;
dest.w = SNAP_SIZE * 2; dest.w = SNAP_SIZE * 2;
@ -284,8 +292,7 @@ void polyfill_draw_preview(magic_api * api, SDL_Surface * canvas, int show_handl
void void
polyfill_release(magic_api * api, int which, polyfill_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
SDL_Rect * update_rect)
{ {
int i; int i;
@ -300,7 +307,8 @@ polyfill_release(magic_api * api, int which,
/* If they simply clicked the first point (without /* If they simply clicked the first point (without
drawing to move it), and there are enough points, consider drawing to move it), and there are enough points, consider
it a final placement of a new point! */ it a final placement of a new point! */
if (polyfill_editing == 0 && polyfill_dragged == 0 && polyfill_num_pts > 2 && polyfill_num_pts < MAX_PTS) { if (polyfill_editing == 0 && polyfill_dragged == 0 && polyfill_num_pts > 2 && polyfill_num_pts < MAX_PTS)
{
printf("Clicked first point to end polygon!\n"); printf("Clicked first point to end polygon!\n");
polyfill_pt_x[polyfill_num_pts] = polyfill_pt_x[0]; polyfill_pt_x[polyfill_num_pts] = polyfill_pt_x[0];
polyfill_pt_y[polyfill_num_pts] = polyfill_pt_y[0]; polyfill_pt_y[polyfill_num_pts] = polyfill_pt_y[0];
@ -310,22 +318,23 @@ polyfill_release(magic_api * api, int which,
/* Moved (or placed) the final spot at the beginning? */ /* Moved (or placed) the final spot at the beginning? */
if (polyfill_num_pts > 2 && if (polyfill_num_pts > 2 &&
( ((polyfill_editing == polyfill_num_pts - 1 &&
(polyfill_editing == polyfill_num_pts - 1 &&
abs(x - polyfill_pt_x[0]) <= SNAP_SIZE && abs(x - polyfill_pt_x[0]) <= SNAP_SIZE &&
abs(y - polyfill_pt_y[0]) <= SNAP_SIZE) || abs(y - polyfill_pt_y[0]) <= SNAP_SIZE) ||
(polyfill_editing == 0 && (polyfill_editing == 0 &&
abs(x - polyfill_pt_x[polyfill_num_pts - 1]) <= SNAP_SIZE && abs(x - polyfill_pt_x[polyfill_num_pts - 1]) <= SNAP_SIZE &&
abs(y - polyfill_pt_y[polyfill_num_pts - 1]) <= SNAP_SIZE) abs(y - polyfill_pt_y[polyfill_num_pts - 1]) <= SNAP_SIZE)))
) {
) {
printf("Ending the polygon!\n"); printf("Ending the polygon!\n");
/* Snap the points */ /* Snap the points */
if (polyfill_editing == 0) { if (polyfill_editing == 0)
{
polyfill_pt_x[0] = polyfill_pt_x[polyfill_num_pts - 1]; polyfill_pt_x[0] = polyfill_pt_x[polyfill_num_pts - 1];
polyfill_pt_y[0] = polyfill_pt_y[polyfill_num_pts - 1]; polyfill_pt_y[0] = polyfill_pt_y[polyfill_num_pts - 1];
} else { }
else
{
polyfill_pt_x[polyfill_num_pts - 1] = polyfill_pt_x[0]; polyfill_pt_x[polyfill_num_pts - 1] = polyfill_pt_x[0];
polyfill_pt_y[polyfill_num_pts - 1] = polyfill_pt_y[0]; polyfill_pt_y[polyfill_num_pts - 1] = polyfill_pt_y[0];
} }
@ -337,26 +346,34 @@ polyfill_release(magic_api * api, int which,
/* Update snapshot ahead of next polygon */ /* Update snapshot ahead of next polygon */
SDL_BlitSurface(canvas, NULL, polyfill_snapshot, NULL); SDL_BlitSurface(canvas, NULL, polyfill_snapshot, NULL);
} else { }
else
{
/* Did not move (or place) the final spot at the beginning */ /* Did not move (or place) the final spot at the beginning */
/* Did we stick to points together? We can merge them */ /* Did we stick to points together? We can merge them */
if (polyfill_num_pts > 2) { if (polyfill_num_pts > 2)
{
int to_merge = MAX_PTS; int to_merge = MAX_PTS;
for (i = polyfill_editing - 1; i < polyfill_editing + 1; i++) { for (i = polyfill_editing - 1; i < polyfill_editing + 1; i++)
if (i >= 0 && i < polyfill_num_pts - 1) { {
if (i >= 0 && i < polyfill_num_pts - 1)
{
if (abs(polyfill_pt_x[i] - polyfill_pt_x[i + 1]) <= SNAP_SIZE && if (abs(polyfill_pt_x[i] - polyfill_pt_x[i + 1]) <= SNAP_SIZE &&
abs(polyfill_pt_y[i] - polyfill_pt_y[i + 1]) <= SNAP_SIZE) { abs(polyfill_pt_y[i] - polyfill_pt_y[i + 1]) <= SNAP_SIZE)
{
printf("%d & %d can be merged\n", i, i + 1); printf("%d & %d can be merged\n", i, i + 1);
to_merge = i; to_merge = i;
} }
} }
} }
if (to_merge != MAX_PTS) { if (to_merge != MAX_PTS)
{
printf("Merging %d with %d\n", to_merge, to_merge + 1); printf("Merging %d with %d\n", to_merge, to_merge + 1);
for (i = to_merge; i < polyfill_num_pts - 1; i++) { for (i = to_merge; i < polyfill_num_pts - 1; i++)
{
polyfill_pt_x[i] = polyfill_pt_x[i + 1]; polyfill_pt_x[i] = polyfill_pt_x[i + 1];
polyfill_pt_y[i] = polyfill_pt_y[i + 1]; polyfill_pt_y[i] = polyfill_pt_y[i + 1];
} }
@ -373,22 +390,24 @@ polyfill_release(magic_api * api, int which,
update_rect->h = canvas->h; update_rect->h = canvas->h;
} }
void polyfill_set_color(magic_api * api, int which, SDL_Surface * canvas, SDL_Surface * snapshot, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect) void polyfill_set_color(magic_api * api, int which, SDL_Surface * canvas, SDL_Surface * snapshot, Uint8 r, Uint8 g,
Uint8 b, SDL_Rect * update_rect)
{ {
polyfill_color = SDL_MapRGB(canvas->format, r, g, b); polyfill_color = SDL_MapRGB(canvas->format, r, g, b);
if (polyfill_active) { if (polyfill_active)
{
polyfill_draw_preview(api, canvas, 1); polyfill_draw_preview(api, canvas, 1);
} }
} }
void polyfill_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * snapshot, Uint8 size, SDL_Rect * update_rect) void polyfill_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * snapshot, Uint8 size,
SDL_Rect * update_rect)
{ {
} }
void polyfill_line_callback(void *pointer, int which, SDL_Surface * canvas, void polyfill_line_callback(void *pointer, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y)
SDL_Surface * snapshot, int x, int y)
{ {
SDL_Rect dest; SDL_Rect dest;
@ -403,33 +422,34 @@ void polyfill_line_callback(void *pointer, int which, SDL_Surface * canvas,
} }
void polyfill_switchin(magic_api * api, int which, int mode, void polyfill_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas)
SDL_Surface * canvas)
{ {
polyfill_color_red = SDL_MapRGB(canvas->format, 255, 0, 0); polyfill_color_red = SDL_MapRGB(canvas->format, 255, 0, 0);
polyfill_color_green = SDL_MapRGB(canvas->format, 0, 255, 0); polyfill_color_green = SDL_MapRGB(canvas->format, 0, 255, 0);
if (polyfill_snapshot == NULL) { if (polyfill_snapshot == NULL)
{
polyfill_snapshot = SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h, polyfill_snapshot = SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h,
canvas->format->BitsPerPixel, canvas->format->Rmask, canvas->format->BitsPerPixel, canvas->format->Rmask,
canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask); canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
} }
if (polyfill_snapshot != NULL) { if (polyfill_snapshot != NULL)
{
SDL_BlitSurface(canvas, NULL, polyfill_snapshot, NULL); SDL_BlitSurface(canvas, NULL, polyfill_snapshot, NULL);
} }
polyfill_active = 1; polyfill_active = 1;
} }
void polyfill_switchout(magic_api * api, int which, int mode, void polyfill_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
SDL_Surface * canvas)
{ {
polyfill_num_pts = 0; polyfill_num_pts = 0;
polyfill_editing = MAX_PTS; polyfill_editing = MAX_PTS;
polyfill_active = 0; polyfill_active = 0;
if (polyfill_snapshot != NULL) { if (polyfill_snapshot != NULL)
{
SDL_BlitSurface(polyfill_snapshot, NULL, canvas, NULL); SDL_BlitSurface(polyfill_snapshot, NULL, canvas, NULL);
} }
} }
@ -437,7 +457,8 @@ void polyfill_switchout(magic_api * api, int which, int mode,
/* Based on public-domain code by Darel Rex Finley, 2007 /* Based on public-domain code by Darel Rex Finley, 2007
https://alienryderflex.com/polygon_fill/ https://alienryderflex.com/polygon_fill/
*/ */
void polyfill_draw_final(magic_api * api, SDL_Surface * canvas) { void polyfill_draw_final(magic_api * api, SDL_Surface * canvas)
{
int i, j, ymin, ymax, y, nodes, swap; int i, j, ymin, ymax, y, nodes, swap;
int nodeX[256]; int nodeX[256];
SDL_Rect rect; SDL_Rect rect;
@ -446,30 +467,32 @@ void polyfill_draw_final(magic_api * api, SDL_Surface * canvas) {
ymin = canvas->w; ymin = canvas->w;
ymax = 0; ymax = 0;
for (i = 0; i < polyfill_num_pts; i++) { for (i = 0; i < polyfill_num_pts; i++)
if (polyfill_pt_y[i] < ymin) { {
if (polyfill_pt_y[i] < ymin)
{
ymin = polyfill_pt_y[i]; ymin = polyfill_pt_y[i];
} }
if (polyfill_pt_y[i] > ymax) { if (polyfill_pt_y[i] > ymax)
{
ymax = polyfill_pt_y[i]; ymax = polyfill_pt_y[i];
} }
} }
printf("ymin %d -> ymax %d\n", ymin, ymax); printf("ymin %d -> ymax %d\n", ymin, ymax);
for (y = ymin; y <= ymax; y++) { for (y = ymin; y <= ymax; y++)
{
nodes = 0; nodes = 0;
j = polyfill_num_pts - 2; j = polyfill_num_pts - 2;
for (i = 0; i < polyfill_num_pts - 1; i++) { for (i = 0; i < polyfill_num_pts - 1; i++)
if ((polyfill_pt_y[i] < y && polyfill_pt_y[j] >= y) || {
(polyfill_pt_y[j] < y && polyfill_pt_y[i] >= y)) { if ((polyfill_pt_y[i] < y && polyfill_pt_y[j] >= y) || (polyfill_pt_y[j] < y && polyfill_pt_y[i] >= y))
{
nodeX[nodes++] = (int) nodeX[nodes++] = (int)
( ((double)polyfill_pt_x[i] +
(double) polyfill_pt_x[i] + (double)(y - polyfill_pt_y[i]) /
(double) (y - polyfill_pt_y[i]) / (double)(polyfill_pt_y[j] - polyfill_pt_y[i]) * (double)(polyfill_pt_x[j] - polyfill_pt_x[i]));
(double) (polyfill_pt_y[j] - polyfill_pt_y[i]) *
(double) (polyfill_pt_x[j] - polyfill_pt_x[i])
);
} }
j = i; j = i;
@ -477,24 +500,30 @@ void polyfill_draw_final(magic_api * api, SDL_Surface * canvas) {
// Sort the nodes, via a simple “Bubble” sort. // Sort the nodes, via a simple “Bubble” sort.
i = 0; i = 0;
while (i < nodes - 1) { while (i < nodes - 1)
if (nodeX[i] > nodeX[i+1]) { {
if (nodeX[i] > nodeX[i + 1])
{
swap = nodeX[i]; swap = nodeX[i];
nodeX[i] = nodeX[i + 1]; nodeX[i] = nodeX[i + 1];
nodeX[i + 1] = swap; nodeX[i + 1] = swap;
if (i) if (i)
i--; i--;
} else { }
else
{
i++; i++;
} }
} }
// Fill the pixels between node pairs. // Fill the pixels between node pairs.
for (i = 0; i < nodes; i += 2) { for (i = 0; i < nodes; i += 2)
{
if (nodeX[i] >= canvas->w) if (nodeX[i] >= canvas->w)
break; break;
if (nodeX[i + 1] > 0) { if (nodeX[i + 1] > 0)
{
if (nodeX[i] < 0) if (nodeX[i] < 0)
nodeX[i] = 0; nodeX[i] = 0;
if (nodeX[i + 1] > canvas->w - 1) if (nodeX[i + 1] > canvas->w - 1)

View file

@ -123,21 +123,25 @@ int rails_init(magic_api * api, Uint8 disabled_features ATTRIBUTE_UNUSED, Uint8
rails_four = IMG_Load(rails_images[2]); rails_four = IMG_Load(rails_images[2]);
rails_corner = IMG_Load(rails_images[3]); rails_corner = IMG_Load(rails_images[3]);
if (rails_one == NULL) { if (rails_one == NULL)
{
fprintf(stderr, "Can't load image %s\n", rails_images[0]); fprintf(stderr, "Can't load image %s\n", rails_images[0]);
return(0); return (0);
} }
if (rails_three == NULL) { if (rails_three == NULL)
{
fprintf(stderr, "Can't load image %s\n", rails_images[1]); fprintf(stderr, "Can't load image %s\n", rails_images[1]);
return(0); return (0);
} }
if (rails_four == NULL) { if (rails_four == NULL)
{
fprintf(stderr, "Can't load image %s\n", rails_images[2]); fprintf(stderr, "Can't load image %s\n", rails_images[2]);
return(0); return (0);
} }
if (rails_corner == NULL) { if (rails_corner == NULL)
{
fprintf(stderr, "Can't load image %s\n", rails_images[3]); fprintf(stderr, "Can't load image %s\n", rails_images[3]);
return(0); return (0);
} }
img_w = rails_one->w; img_w = rails_one->w;

View file

@ -36,7 +36,8 @@
static int rainbow_radius = 16; static int rainbow_radius = 16;
enum { enum
{
TOOL_RAINBOW, TOOL_RAINBOW,
TOOL_SMOOTH_RAINBOW, TOOL_SMOOTH_RAINBOW,
TOOL_RAINBOW_CYCLE, TOOL_RAINBOW_CYCLE,
@ -158,7 +159,7 @@ char *rainbow_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNU
{ {
return (strdup(gettext_noop("Smooth Rainbow"))); return (strdup(gettext_noop("Smooth Rainbow")));
} }
else /* TOOL_RAINBOW_CYCLE */ else /* TOOL_RAINBOW_CYCLE */
{ {
return (strdup(gettext_noop("Rainbow Cycle"))); return (strdup(gettext_noop("Rainbow Cycle")));
} }
@ -223,7 +224,7 @@ void rainbow_drag(magic_api * api, int which, SDL_Surface * canvas,
rainbow_mix = 0; rainbow_mix = 0;
rainbow_color = (rainbow_color + 1) % NUM_RAINBOW_COLORS; rainbow_color = (rainbow_color + 1) % NUM_RAINBOW_COLORS;
} }
else /* TOOL_RAINBOW_CYCLE */ else /* TOOL_RAINBOW_CYCLE */
{ {
rainbow_mix = 0; rainbow_mix = 0;
} }
@ -273,7 +274,8 @@ void rainbow_drag(magic_api * api, int which, SDL_Surface * canvas,
void rainbow_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED, 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)
{ {
if (which == TOOL_RAINBOW_CYCLE) { if (which == TOOL_RAINBOW_CYCLE)
{
rainbow_color = (rainbow_color + 1) % NUM_RAINBOW_COLORS; rainbow_color = (rainbow_color + 1) % NUM_RAINBOW_COLORS;
} }

View file

@ -58,18 +58,18 @@ char *ribbon_get_description(magic_api * api, int which, int mode);
static void ribbon_linecb(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y); static void ribbon_linecb(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
void ribbon_drag(magic_api * api, int which, SDL_Surface * canvas, void ribbon_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 ribbon_click(magic_api * api, int which, int mode, void ribbon_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 ribbon_release(magic_api * api, int which, void ribbon_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 ribbon_shutdown(magic_api * api); void ribbon_shutdown(magic_api * api);
void ribbon_set_color(magic_api * api, int which, SDL_Surface * canvas, void ribbon_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect); SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
int ribbon_requires_colors(magic_api * api, int which); int ribbon_requires_colors(magic_api * api, int which);
void ribbon_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas); void ribbon_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void ribbon_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas); void ribbon_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
@ -77,7 +77,7 @@ int ribbon_modes(magic_api * api, int which);
Uint8 ribbon_accepted_sizes(magic_api * api, int which, int mode); Uint8 ribbon_accepted_sizes(magic_api * api, int which, int mode);
Uint8 ribbon_default_size(magic_api * api, int which, int mode); Uint8 ribbon_default_size(magic_api * api, int which, int mode);
void ribbon_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, void ribbon_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect); SDL_Rect * update_rect);
Uint32 ribbon_api_version(void) Uint32 ribbon_api_version(void)
@ -139,12 +139,12 @@ char *ribbon_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBU
// Do the effect: // Do the effect:
static void ribbon_linecb(void *ptr, int which ATTRIBUTE_UNUSED, static void ribbon_linecb(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y) SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
{ {
magic_api *api = (magic_api *) ptr; magic_api *api = (magic_api *) ptr;
int i; int i;
for (i = - ribbon_radius; i < ribbon_radius; i++) for (i = -ribbon_radius; i < ribbon_radius; i++)
{ {
api->putpixel(canvas, x + i, y + i, ribbon_segment_color); api->putpixel(canvas, x + i, y + i, ribbon_segment_color);
api->putpixel(canvas, x + i, y + i + 1, ribbon_segment_color); api->putpixel(canvas, x + i, y + i + 1, ribbon_segment_color);
@ -154,7 +154,7 @@ static void ribbon_linecb(void *ptr, int which ATTRIBUTE_UNUSED,
// Affect the canvas on drag: // Affect the canvas on drag:
void ribbon_drag(magic_api * api, int which, SDL_Surface * canvas, void ribbon_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)
{ {
int pt, pt2, first_click; int pt, pt2, first_click;
Uint8 r, g, b; Uint8 r, g, b;
@ -175,7 +175,8 @@ void ribbon_drag(magic_api * api, int which, SDL_Surface * canvas,
angle = 0.0; angle = 0.0;
if (!first_click) { if (!first_click)
{
double x_angle; double x_angle;
if (sqrt((x - ox) * (x - ox) + (y - oy) * (y - oy)) > 16) if (sqrt((x - ox) * (x - ox) + (y - oy) * (y - oy)) > 16)
@ -188,7 +189,8 @@ void ribbon_drag(magic_api * api, int which, SDL_Surface * canvas,
} }
pt = ribbon_tail; pt = ribbon_tail;
do { do
{
int brt; int brt;
pt2 = ((pt + 1) % ribbon_max_length); pt2 = ((pt + 1) % ribbon_max_length);
@ -212,7 +214,8 @@ void ribbon_drag(magic_api * api, int which, SDL_Surface * canvas,
ribbon_segment_color = SDL_MapRGB(canvas->format, r, g, b); ribbon_segment_color = SDL_MapRGB(canvas->format, r, g, b);
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, ribbon_linecb); api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, ribbon_linecb);
pt = pt2; pt = pt2;
} while (((pt + 1) % ribbon_max_length) != ribbon_head); }
while (((pt + 1) % ribbon_max_length) != ribbon_head);
} }
update_rect->x = 0; update_rect->x = 0;
@ -223,17 +226,17 @@ void ribbon_drag(magic_api * api, int which, SDL_Surface * canvas,
// Affect the canvas on click: // Affect the canvas on click:
void ribbon_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED, void ribbon_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)
{ {
ribbon_head = ribbon_tail = ribbon_old_angle = 0; ribbon_head = ribbon_tail = ribbon_old_angle = 0;
ribbon_drag(api, which, canvas, last, x, y, x, y, update_rect); ribbon_drag(api, which, canvas, last, x, y, x, y, update_rect);
} }
void ribbon_release(magic_api * api ATTRIBUTE_UNUSED, void ribbon_release(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED) int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{ {
} }
@ -246,9 +249,8 @@ void ribbon_shutdown(magic_api * api ATTRIBUTE_UNUSED)
// Record the color from Tux Paint: // Record the color from Tux Paint:
void ribbon_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, void ribbon_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 r, Uint8 g, Uint8 b, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{ {
ribbon_r = r; ribbon_r = r;
ribbon_g = g; ribbon_g = g;
@ -262,12 +264,12 @@ int ribbon_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE
} }
void ribbon_switchin(magic_api * api ATTRIBUTE_UNUSED, void ribbon_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED) int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{ {
} }
void ribbon_switchout(magic_api * api ATTRIBUTE_UNUSED, void ribbon_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED) int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{ {
} }
@ -288,8 +290,8 @@ Uint8 ribbon_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_
} }
void ribbon_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, void ribbon_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size,
SDL_Rect * update_rect ATTRIBUTE_UNUSED) SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{ {
ribbon_max_length = (size * MAX_LENGTH) / NUM_LENGTH_OPTIONS; ribbon_max_length = (size * MAX_LENGTH) / NUM_LENGTH_OPTIONS;
} }

View file

@ -122,7 +122,7 @@ int shift_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED
// Return our order // Return our order
int shift_get_order(int which ATTRIBUTE_UNUSED) int shift_get_order(int which ATTRIBUTE_UNUSED)
{ {
return 200; return 200;
} }
// Return our descriptions, localized: // Return our descriptions, localized:

View file

@ -39,32 +39,33 @@
#include "SDL_mixer.h" #include "SDL_mixer.h"
#include <math.h> #include <math.h>
enum { enum
{
TOOL_SMOOTH, TOOL_SMOOTH,
TOOL_SQUIGGLES, TOOL_SQUIGGLES,
TOOL_LOOPS, TOOL_LOOPS,
NUM_TOOLS NUM_TOOLS
}; };
char * smooth_icon_fnames[NUM_TOOLS] = { char *smooth_icon_fnames[NUM_TOOLS] = {
"smooth.png", "smooth.png",
"squiggles.png", "squiggles.png",
"loops.png", "loops.png",
}; };
char * smooth_snd_fnames[NUM_TOOLS] = { char *smooth_snd_fnames[NUM_TOOLS] = {
"smooth.ogg", "smooth.ogg",
"squiggles.ogg", "squiggles.ogg",
"loops.ogg", "loops.ogg",
}; };
char * smooth_names[NUM_TOOLS] = { char *smooth_names[NUM_TOOLS] = {
gettext_noop("Smooth"), gettext_noop("Smooth"),
gettext_noop("Squiggles"), gettext_noop("Squiggles"),
gettext_noop("Loops"), gettext_noop("Loops"),
}; };
char * smooth_descrs[NUM_TOOLS] = { char *smooth_descrs[NUM_TOOLS] = {
gettext_noop("Click and drag the mouse around to draw in freehand; it will be smoothed when you let go."), gettext_noop("Click and drag the mouse around to draw in freehand; it will be smoothed when you let go."),
gettext_noop("Click and drag the mouse around to draw squiggles."), gettext_noop("Click and drag the mouse around to draw squiggles."),
gettext_noop("Click and drag the mouse around to draw loop-the-loops."), gettext_noop("Click and drag the mouse around to draw loop-the-loops."),
@ -107,14 +108,14 @@ static void smooth_linecb(void *ptr, int which, SDL_Surface * canvas, SDL_Surfac
static void smooth_squiggle_linecb(void *ptr, int which, static void smooth_squiggle_linecb(void *ptr, int which,
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y); SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y);
void smooth_drag(magic_api * api, int which, SDL_Surface * canvas, void smooth_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 smooth_click(magic_api * api, int which, int mode, void smooth_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 smooth_release(magic_api * api, int which, SDL_Surface * canvas, void smooth_release(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int x, int y, SDL_Rect * update_rect); SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
void smooth_shutdown(magic_api * api); void smooth_shutdown(magic_api * api);
void smooth_set_color(magic_api * api, int which, SDL_Surface * canvas, void smooth_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect); SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
int smooth_requires_colors(magic_api * api, int which); int smooth_requires_colors(magic_api * api, int which);
void smooth_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas); void smooth_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void smooth_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas); void smooth_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
@ -122,7 +123,7 @@ int smooth_modes(magic_api * api, int which);
Uint8 smooth_accepted_sizes(magic_api * api, int which, int mode); Uint8 smooth_accepted_sizes(magic_api * api, int which, int mode);
Uint8 smooth_default_size(magic_api * api, int which, int mode); Uint8 smooth_default_size(magic_api * api, int which, int mode);
void smooth_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, void smooth_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
SDL_Rect * update_rect); SDL_Rect * update_rect);
@ -131,7 +132,8 @@ int smooth_init(magic_api * api, Uint8 disabled_features ATTRIBUTE_UNUSED, Uint8
char fname[1024]; char fname[1024];
int i; int i;
for (i = 0; i < NUM_TOOLS; i++) { for (i = 0; i < NUM_TOOLS; i++)
{
snprintf(fname, sizeof(fname), "%ssounds/magic/%s", api->data_directory, smooth_snd_fnames[i]); snprintf(fname, sizeof(fname), "%ssounds/magic/%s", api->data_directory, smooth_snd_fnames[i]);
smooth_snds[i] = Mix_LoadWAV(fname); smooth_snds[i] = Mix_LoadWAV(fname);
} }
@ -178,20 +180,19 @@ int smooth_get_order(int which)
} }
// Return our description, localized: // Return our description, localized:
char *smooth_get_description(magic_api * api ATTRIBUTE_UNUSED, char *smooth_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
int which, int mode ATTRIBUTE_UNUSED)
{ {
return (strdup(gettext(smooth_descrs[which]))); return (strdup(gettext(smooth_descrs[which])));
} }
static void smooth_linecb(void *ptr, int which, static void smooth_linecb(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
{ {
magic_api *api = (magic_api *) ptr; magic_api *api = (magic_api *) ptr;
SDL_Rect dest; SDL_Rect dest;
if (which == TOOL_SMOOTH) { if (which == TOOL_SMOOTH)
{
/* FIXME */ /* FIXME */
dest.x = x; dest.x = x;
dest.y = y; dest.y = y;
@ -199,7 +200,9 @@ static void smooth_linecb(void *ptr, int which,
dest.h = smooth_size; dest.h = smooth_size;
SDL_FillRect(canvas, &dest, smooth_color); SDL_FillRect(canvas, &dest, smooth_color);
} else if (which == TOOL_LOOPS) { }
else if (which == TOOL_LOOPS)
{
/* FIXME */ /* FIXME */
dest.x = x; dest.x = x;
dest.y = y; dest.y = y;
@ -207,7 +210,9 @@ static void smooth_linecb(void *ptr, int which,
dest.h = 2; dest.h = 2;
SDL_FillRect(canvas, &dest, smooth_color); SDL_FillRect(canvas, &dest, smooth_color);
} else if (which == TOOL_SQUIGGLES) { }
else if (which == TOOL_SQUIGGLES)
{
api->putpixel(canvas, x, y, smooth_color); api->putpixel(canvas, x, y, smooth_color);
} }
} }
@ -223,19 +228,26 @@ static void smooth_squiggle_linecb(void *ptr, int which,
xx2 = x + (cos(smooth_squiggle_angle * M_PI / 180.0) * smooth_squiggle_rad); xx2 = x + (cos(smooth_squiggle_angle * M_PI / 180.0) * smooth_squiggle_rad);
yy2 = y - (sin(smooth_squiggle_angle * M_PI / 180.0) * smooth_squiggle_rad); yy2 = y - (sin(smooth_squiggle_angle * M_PI / 180.0) * smooth_squiggle_rad);
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++)
{
xx1 = xx2; xx1 = xx2;
yy1 = yy2; yy1 = yy2;
if (which == TOOL_LOOPS) { if (which == TOOL_LOOPS)
{
smooth_squiggle_angle += 5; smooth_squiggle_angle += 5;
smooth_squiggle_rad = LOOP_RAD_CALC; smooth_squiggle_rad = LOOP_RAD_CALC;
} else if (which == TOOL_SQUIGGLES) { }
else if (which == TOOL_SQUIGGLES)
{
smooth_squiggle_angle += (rand() % 5) + 5; smooth_squiggle_angle += (rand() % 5) + 5;
smooth_squiggle_rad += ((rand() % 3 * smooth_size) - smooth_size); smooth_squiggle_rad += ((rand() % 3 * smooth_size) - smooth_size);
if (smooth_squiggle_rad < 5) { if (smooth_squiggle_rad < 5)
{
smooth_squiggle_rad += 5; smooth_squiggle_rad += 5;
} else if (smooth_squiggle_rad >= 15 * smooth_size) { }
else if (smooth_squiggle_rad >= 15 * smooth_size)
{
smooth_squiggle_rad -= ((rand() % 10) + 10); smooth_squiggle_rad -= ((rand() % 10) + 10);
} }
} }
@ -246,35 +258,42 @@ static void smooth_squiggle_linecb(void *ptr, int which,
api->line((void *)api, which, canvas, last, xx1, yy1, xx2, yy2, 1, smooth_linecb); api->line((void *)api, which, canvas, last, xx1, yy1, xx2, yy2, 1, smooth_linecb);
} }
if (smooth_squiggle_angle >= 360) { if (smooth_squiggle_angle >= 360)
{
smooth_squiggle_angle -= 360; smooth_squiggle_angle -= 360;
} }
} }
void smooth_drag(magic_api * api, int which, void smooth_drag(magic_api * api, int which,
SDL_Surface * canvas, 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 (which == TOOL_SMOOTH) { if (which == TOOL_SMOOTH)
if (num_input_points >= MAX_CTRL_POINTS) { {
if (num_input_points >= MAX_CTRL_POINTS)
{
return; return;
} }
smooth_capture = (smooth_capture + 1) % 4; smooth_capture = (smooth_capture + 1) % 4;
if (smooth_capture == 1) { if (smooth_capture == 1)
{
num_input_points++; num_input_points++;
smooth_control_points[num_input_points].x = x; smooth_control_points[num_input_points].x = x;
smooth_control_points[num_input_points].y = y; smooth_control_points[num_input_points].y = y;
} }
} }
if (which == TOOL_SMOOTH) { if (which == TOOL_SMOOTH)
{
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, smooth_linecb); api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, smooth_linecb);
} else if (which == TOOL_SQUIGGLES || which == TOOL_LOOPS) { }
else if (which == TOOL_SQUIGGLES || which == TOOL_LOOPS)
{
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, smooth_squiggle_linecb); api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, smooth_squiggle_linecb);
} }
if (which == TOOL_SMOOTH) { if (which == TOOL_SMOOTH)
{
if (ox > x) if (ox > x)
{ {
int tmp = ox; int tmp = ox;
@ -295,13 +314,17 @@ void smooth_drag(magic_api * api, int which,
update_rect->y = oy - 16; update_rect->y = oy - 16;
update_rect->w = (x + 16) - update_rect->x; update_rect->w = (x + 16) - update_rect->x;
update_rect->h = (y + 16) - update_rect->y; update_rect->h = (y + 16) - update_rect->y;
} else if (which == TOOL_LOOPS) { }
else if (which == TOOL_LOOPS)
{
// FIXME // FIXME
update_rect->x = 0; update_rect->x = 0;
update_rect->y = 0; update_rect->y = 0;
update_rect->w = canvas->w; update_rect->w = canvas->w;
update_rect->h = canvas->h; update_rect->h = canvas->h;
} else if (which == TOOL_SQUIGGLES) { }
else if (which == TOOL_SQUIGGLES)
{
// FIXME // FIXME
update_rect->x = 0; update_rect->x = 0;
update_rect->y = 0; update_rect->y = 0;
@ -314,19 +337,21 @@ void smooth_drag(magic_api * api, int which,
void smooth_click(magic_api * api, void smooth_click(magic_api * api,
int which, int mode ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
int x, int y, SDL_Rect * update_rect)
{ {
num_input_points = 0; num_input_points = 0;
smooth_control_points[num_input_points].x = x; smooth_control_points[num_input_points].x = x;
smooth_control_points[num_input_points].y = y; smooth_control_points[num_input_points].y = y;
smooth_capture = 0; smooth_capture = 0;
if (which == TOOL_SQUIGGLES) { if (which == TOOL_SQUIGGLES)
{
smooth_squiggle_angle = 0; smooth_squiggle_angle = 0;
smooth_squiggle_rad = 0; smooth_squiggle_rad = 0;
smooth_drag(api, which, canvas, last, x, y, x, y, update_rect); smooth_drag(api, which, canvas, last, x, y, x, y, update_rect);
} else if (which == TOOL_LOOPS) { }
else if (which == TOOL_LOOPS)
{
smooth_squiggle_angle = 0; smooth_squiggle_angle = 0;
smooth_squiggle_rad = LOOP_RAD_CALC; smooth_squiggle_rad = LOOP_RAD_CALC;
smooth_drag(api, which, canvas, last, x, y, x, y, update_rect); smooth_drag(api, which, canvas, last, x, y, x, y, update_rect);
@ -335,16 +360,16 @@ void smooth_click(magic_api * api,
void smooth_release(magic_api * api, void smooth_release(magic_api * api,
int which ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
{ {
if (which == TOOL_SMOOTH) { if (which == TOOL_SMOOTH)
{
Point2D *curve; Point2D *curve;
int p, i, n_points; int p, i, n_points;
for (p = 0; p < 4; p++) { for (p = 0; p < 4; p++)
{
num_input_points++; num_input_points++;
smooth_control_points[num_input_points].x = x; smooth_control_points[num_input_points].x = x;
smooth_control_points[num_input_points].y = y; smooth_control_points[num_input_points].y = y;
@ -352,22 +377,21 @@ void smooth_release(magic_api * api,
SDL_BlitSurface(last, NULL, canvas, NULL); SDL_BlitSurface(last, NULL, canvas, NULL);
for (p = 0; p < num_input_points - 3; p += 3) { for (p = 0; p < num_input_points - 3; p += 3)
{
n_points = smooth_dist(smooth_control_points[p + 0].x, n_points = smooth_dist(smooth_control_points[p + 0].x,
smooth_control_points[p + 0].y, smooth_control_points[p + 0].y,
smooth_control_points[p + 1].x, smooth_control_points[p + 1].x,
smooth_control_points[p + 1].y) + smooth_control_points[p + 1].y) +
smooth_dist(smooth_control_points[p + 1].x, smooth_dist(smooth_control_points[p + 1].x,
smooth_control_points[p + 1].y, smooth_control_points[p + 1].y,
smooth_control_points[p + 2].x, smooth_control_points[p + 2].x,
smooth_control_points[p + 2].y) + smooth_control_points[p + 2].y) +
smooth_dist(smooth_control_points[p + 2].x, smooth_dist(smooth_control_points[p + 2].x,
smooth_control_points[p + 2].y, smooth_control_points[p + 2].y, smooth_control_points[p + 3].x, smooth_control_points[p + 3].y);
smooth_control_points[p + 3].x,
smooth_control_points[p + 3].y);
if (n_points == 0) if (n_points == 0)
continue; // No-op; not any points to plot continue; // No-op; not any points to plot
curve = (Point2D *) malloc(sizeof(Point2D) * n_points); curve = (Point2D *) malloc(sizeof(Point2D) * n_points);
@ -376,7 +400,8 @@ void smooth_release(magic_api * api,
for (i = 0; i < n_points - 1; i++) for (i = 0; i < n_points - 1; i++)
{ {
api->line((void *)api, which, canvas, last, curve[i].x, curve[i].y, curve[i + 1].x, curve[i + 1].y, 1, smooth_linecb); api->line((void *)api, which, canvas, last, curve[i].x, curve[i].y, curve[i + 1].x, curve[i + 1].y, 1,
smooth_linecb);
} }
free(curve); free(curve);
@ -397,16 +422,17 @@ void smooth_shutdown(magic_api * api ATTRIBUTE_UNUSED)
{ {
int i; int i;
for (i = 0; i < NUM_TOOLS; i++) { for (i = 0; i < NUM_TOOLS; i++)
{
if (smooth_snds[i] != NULL) if (smooth_snds[i] != NULL)
Mix_FreeChunk(smooth_snds[i]); Mix_FreeChunk(smooth_snds[i]);
} }
} }
void smooth_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, void smooth_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * canvas,
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b,
SDL_Rect * update_rect ATTRIBUTE_UNUSED) SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{ {
smooth_color = SDL_MapRGB(canvas->format, r, g, b); smooth_color = SDL_MapRGB(canvas->format, r, g, b);
} }
@ -487,12 +513,12 @@ static float smooth_dist(float x1, float y1, float x2, float y2)
} }
void smooth_switchin(magic_api * api ATTRIBUTE_UNUSED, void smooth_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED) int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{ {
} }
void smooth_switchout(magic_api * api ATTRIBUTE_UNUSED, void smooth_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED) int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
{ {
} }
@ -513,8 +539,8 @@ Uint8 smooth_default_size(magic_api * api ATTRIBUTE_UNUSED, int which, int mode
} }
void smooth_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, void smooth_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 size, SDL_Rect * update_rect ATTRIBUTE_UNUSED) Uint8 size, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{ {
smooth_size = size; smooth_size = size;
} }

View file

@ -126,9 +126,9 @@ int smudge_get_group(magic_api * api ATTRIBUTE_UNUSED, int which)
int smudge_get_order(int which) int smudge_get_order(int which)
{ {
if (which == 0) if (which == 0)
return 3; /* within MAGIC_TYPE_DISTORTS */ return 3; /* within MAGIC_TYPE_DISTORTS */
else else
return 2500; /* within MAGIC_TYPE_PAINTING */ return 2500; /* within MAGIC_TYPE_PAINTING */
} }
// Return our descriptions, localized: // Return our descriptions, localized:

View file

@ -29,11 +29,9 @@ Uint8 specular_size = 32;
void specular_drag(magic_api * api, int which, SDL_Surface * canvas, void specular_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int old_x, int old_y, int x, int y, SDL_Surface * snapshot, int old_x, int old_y, int x, int y, SDL_Rect * update_rect);
SDL_Rect * update_rect);
void specular_line_callback(void *pointer, int which, SDL_Surface * canvas, void specular_line_callback(void *pointer, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
SDL_Surface * snapshot, int x, int y);
Uint32 specular_api_version(void) Uint32 specular_api_version(void)
@ -46,8 +44,7 @@ int specular_init(magic_api * api, Uint8 disabled_features, Uint8 complexity_lev
int i; int i;
char filename[1024]; char filename[1024];
snprintf(filename, sizeof(filename), "%ssounds/magic/%s", api->data_directory, snprintf(filename, sizeof(filename), "%ssounds/magic/%s", api->data_directory, "reflection.ogg"); // FIXME
"reflection.ogg"); // FIXME
snd_effect = Mix_LoadWAV(filename); snd_effect = Mix_LoadWAV(filename);
return (1); return (1);
@ -63,8 +60,7 @@ SDL_Surface *specular_get_icon(magic_api * api, int which)
{ {
char filename[1024]; char filename[1024];
snprintf(filename, sizeof(filename), "%simages/magic/%s", snprintf(filename, sizeof(filename), "%simages/magic/%s", api->data_directory, "reflection.png"); // FIXME
api->data_directory, "reflection.png"); // FIXME
return (IMG_Load(filename)); return (IMG_Load(filename));
} }
@ -90,7 +86,9 @@ int specular_get_order(int which)
char *specular_get_description(magic_api * api, int which, int mode) char *specular_get_description(magic_api * api, int which, int mode)
{ {
return strdup(gettext("Click and drag on the bottom half of your picture to draw a specular reflection — like a puddle, pond, or lake — that mirrors the top half of your picture.")); return
strdup(gettext
("Click and drag on the bottom half of your picture to draw a specular reflection — like a puddle, pond, or lake — that mirrors the top half of your picture."));
} }
@ -120,7 +118,8 @@ Uint8 specular_default_size(magic_api * api, int which, int mode)
void specular_shutdown(magic_api * api) void specular_shutdown(magic_api * api)
{ {
if (snd_effect != NULL) { if (snd_effect != NULL)
{
Mix_FreeChunk(snd_effect); Mix_FreeChunk(snd_effect);
} }
} }
@ -128,8 +127,7 @@ void specular_shutdown(magic_api * api)
void void
specular_click(magic_api * api, int which, int mode, specular_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
SDL_Rect * update_rect)
{ {
specular_drag(api, which, canvas, snapshot, x, y, x, y, update_rect); specular_drag(api, which, canvas, snapshot, x, y, x, y, update_rect);
} }
@ -137,16 +135,12 @@ specular_click(magic_api * api, int which, int mode,
void void
specular_drag(magic_api * api, int which, specular_drag(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, SDL_Surface * canvas, SDL_Surface * snapshot, int old_x, int old_y, int x, int y, SDL_Rect * update_rect)
int old_x, int old_y, int x, int y,
SDL_Rect * update_rect)
{ {
SDL_LockSurface(snapshot); SDL_LockSurface(snapshot);
SDL_LockSurface(canvas); SDL_LockSurface(canvas);
api->line((void *) api, which, canvas, snapshot, api->line((void *)api, which, canvas, snapshot, old_x, old_y, x, y, 1, specular_line_callback);
old_x, old_y, x, y, 1,
specular_line_callback);
SDL_UnlockSurface(canvas); SDL_UnlockSurface(canvas);
SDL_UnlockSurface(snapshot); SDL_UnlockSurface(snapshot);
@ -176,23 +170,23 @@ specular_drag(magic_api * api, int which,
void void
specular_release(magic_api * api, int which, specular_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
SDL_Rect * update_rect)
{ {
} }
void specular_set_color(magic_api * api, int which, SDL_Surface * canvas, SDL_Surface * snapshot, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect) void specular_set_color(magic_api * api, int which, SDL_Surface * canvas, SDL_Surface * snapshot, Uint8 r, Uint8 g,
Uint8 b, SDL_Rect * update_rect)
{ {
} }
void specular_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * snapshot, Uint8 size, SDL_Rect * update_rect) void specular_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * snapshot, Uint8 size,
SDL_Rect * update_rect)
{ {
specular_size = size * 16; specular_size = size * 16;
} }
void specular_line_callback(void *pointer, int which, SDL_Surface * canvas, void specular_line_callback(void *pointer, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y)
SDL_Surface * snapshot, int x, int y)
{ {
magic_api *api = (magic_api *) pointer; magic_api *api = (magic_api *) pointer;
int xx, yy, ysrc; int xx, yy, ysrc;
@ -220,12 +214,10 @@ void specular_line_callback(void *pointer, int which, SDL_Surface * canvas,
} }
} }
void specular_switchin(magic_api * api, int which, int mode, void specular_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas)
SDL_Surface * canvas)
{ {
} }
void specular_switchout(magic_api * api, int which, int mode, void specular_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
SDL_Surface * canvas)
{ {
} }

View file

@ -34,9 +34,9 @@ char *swirl_names[NUM_SWIRL_TOOLS] = {
}; };
int swirls_orders[NUM_SWIRL_TOOLS] = { int swirls_orders[NUM_SWIRL_TOOLS] = {
200, /* within MAGIC_TYPE_DISTORTS */ 200, /* within MAGIC_TYPE_DISTORTS */
201, /* within MAGIC_TYPE_DISTORTS */ 201, /* within MAGIC_TYPE_DISTORTS */
1800, /* within MAGIC_TYPE_PAINTING */ 1800, /* within MAGIC_TYPE_PAINTING */
}; };
char *swirl_descriptions[NUM_SWIRL_TOOLS][2] = { char *swirl_descriptions[NUM_SWIRL_TOOLS][2] = {

View file

@ -38,31 +38,31 @@ enum
Uint8 tp_offers_sizes = 1; Uint8 tp_offers_sizes = 1;
int num_tools[2] = { int num_tools[2] = {
6, /* when sizes not available */ 6, /* when sizes not available */
2, /* when sizes available */ 2, /* when sizes available */
}; };
int * which_to_tool; int *which_to_tool;
int which_to_tool_per_size_availability[2][6] = { int which_to_tool_per_size_availability[2][6] = {
/* when sizes not available */ /* when sizes not available */
{ {
TOOL_EPITROCHOID_NOSIZES_1, TOOL_EPITROCHOID_NOSIZES_1,
TOOL_EPITROCHOID_NOSIZES_2, TOOL_EPITROCHOID_NOSIZES_2,
TOOL_EPITROCHOID_NOSIZES_3, TOOL_EPITROCHOID_NOSIZES_3,
TOOL_HYPOTROCHOID_NOSIZES_1, TOOL_HYPOTROCHOID_NOSIZES_1,
TOOL_HYPOTROCHOID_NOSIZES_2, TOOL_HYPOTROCHOID_NOSIZES_2,
TOOL_HYPOTROCHOID_NOSIZES_3, TOOL_HYPOTROCHOID_NOSIZES_3,
}, },
/* when sizes available */ /* when sizes available */
{ {
TOOL_EPITROCHOID_SIZES, TOOL_EPITROCHOID_SIZES,
TOOL_HYPOTROCHOID_SIZES, TOOL_HYPOTROCHOID_SIZES,
-1, -1,
-1, -1,
-1, -1,
-1, -1,
}, },
}; };
#define SIZE_WELLINSIDE 0.33 #define SIZE_WELLINSIDE 0.33
@ -79,26 +79,27 @@ float trochoids_sizes_per_size_setting[NUM_SIZES] = {
SIZE_OUTSIDE, SIZE_OUTSIDE,
SIZE_WELLOUTSIDE, SIZE_WELLOUTSIDE,
}; };
/* Default to "SIZE_EDGE" */ /* Default to "SIZE_EDGE" */
#define DEFAULT_SIZE 3 #define DEFAULT_SIZE 3
float trochoids_sizes_per_tool[NUM_TOOLS] = { float trochoids_sizes_per_tool[NUM_TOOLS] = {
0, // N/A; size controls available 0, // N/A; size controls available
SIZE_INSIDE, SIZE_INSIDE,
SIZE_EDGE, SIZE_EDGE,
SIZE_WELLOUTSIDE, SIZE_WELLOUTSIDE,
0, // N/A; size controls available 0, // N/A; size controls available
SIZE_INSIDE, SIZE_INSIDE,
SIZE_EDGE, SIZE_EDGE,
SIZE_WELLOUTSIDE, SIZE_WELLOUTSIDE,
}; };
const char *icon_filenames[NUM_TOOLS] = { const char *icon_filenames[NUM_TOOLS] = {
"epitrochoid_edge.png", /* use "edge" variation when sizes are available */ "epitrochoid_edge.png", /* use "edge" variation when sizes are available */
"epitrochoid_inside.png", "epitrochoid_inside.png",
"epitrochoid_edge.png", "epitrochoid_edge.png",
"epitrochoid_outside.png", "epitrochoid_outside.png",
"hypotrochoid_edge.png", /* use "edge" variation when sizes are available */ "hypotrochoid_edge.png", /* use "edge" variation when sizes are available */
"hypotrochoid_inside.png", "hypotrochoid_inside.png",
"hypotrochoid_edge.png", "hypotrochoid_edge.png",
"hypotrochoid_outside.png", "hypotrochoid_outside.png",
@ -119,20 +120,29 @@ const char *tool_names[NUM_TOOLS] = {
const char *tool_descriptions[NUM_TOOLS] = { const char *tool_descriptions[NUM_TOOLS] = {
/* Epitrochoids */ /* Epitrochoids */
gettext_noop("Click to start drawing an epitrochoid. Drag left/right to change the size of the fixed circle, and up/down to change the size of the circle rolling outside of it. Use the size option to change where the pen is."), gettext_noop
gettext_noop("Click to start drawing an epitrochoid. Drag left/right to change the size of the fixed circle, and up/down to change the size of the circle rolling outside of it. Then pen is within the rolling circle."), ("Click to start drawing an epitrochoid. Drag left/right to change the size of the fixed circle, and up/down to change the size of the circle rolling outside of it. Use the size option to change where the pen is."),
gettext_noop("Click to start drawing an epitrochoid. Drag left/right to change the size of the fixed circle, and up/down to change the size of the circle rolling outside of it. Then pen is on the edge of the rolling circle."), gettext_noop
gettext_noop("Click to start drawing an epitrochoid. Drag left/right to change the size of the fixed circle, and up/down to change the size of the circle rolling outside of it. Then pen is outside the rolling circle."), ("Click to start drawing an epitrochoid. Drag left/right to change the size of the fixed circle, and up/down to change the size of the circle rolling outside of it. Then pen is within the rolling circle."),
gettext_noop
("Click to start drawing an epitrochoid. Drag left/right to change the size of the fixed circle, and up/down to change the size of the circle rolling outside of it. Then pen is on the edge of the rolling circle."),
gettext_noop
("Click to start drawing an epitrochoid. Drag left/right to change the size of the fixed circle, and up/down to change the size of the circle rolling outside of it. Then pen is outside the rolling circle."),
/* Hypotrochoids */ /* Hypotrochoids */
gettext_noop("Click to start drawing a hypotrochoid. Drag left/right to change the size of the fixed circle, and up/down to change the size of the circle rolling inside it. Use the size option to change where the pen is."), gettext_noop
gettext_noop("Click to start drawing a hypotrochoid. Drag left/right to change the size of the fixed circle, and up/down to change the size of the circle rolling inside it. Then pen is within the rolling circle."), ("Click to start drawing a hypotrochoid. Drag left/right to change the size of the fixed circle, and up/down to change the size of the circle rolling inside it. Use the size option to change where the pen is."),
gettext_noop("Click to start drawing a hypotrochoid. Drag left/right to change the size of the fixed circle, and up/down to change the size of the circle rolling inside it. Then pen is on the edge of the rolling circle."), gettext_noop
gettext_noop("Click to start drawing a hypotrochoid. Drag left/right to change the size of the fixed circle, and up/down to change the size of the circle rolling inside it. Then pen is outside the rolling circle."), ("Click to start drawing a hypotrochoid. Drag left/right to change the size of the fixed circle, and up/down to change the size of the circle rolling inside it. Then pen is within the rolling circle."),
gettext_noop
("Click to start drawing a hypotrochoid. Drag left/right to change the size of the fixed circle, and up/down to change the size of the circle rolling inside it. Then pen is on the edge of the rolling circle."),
gettext_noop
("Click to start drawing a hypotrochoid. Drag left/right to change the size of the fixed circle, and up/down to change the size of the circle rolling inside it. Then pen is outside the rolling circle."),
}; };
/* Sound effects (same for everyone) */ /* Sound effects (same for everyone) */
enum { enum
{
SND_DRAG, SND_DRAG,
SND_RELEASE_EPITROCHOID, SND_RELEASE_EPITROCHOID,
SND_RELEASE_HYPOTROCHOID, SND_RELEASE_HYPOTROCHOID,
@ -167,33 +177,23 @@ Uint8 trochoids_accepted_sizes(magic_api * api, int which, int mode);
Uint8 trochoids_default_size(magic_api * api, int which, int mode); Uint8 trochoids_default_size(magic_api * api, int which, int mode);
void trochoids_shutdown(magic_api * api); void trochoids_shutdown(magic_api * api);
void trochoids_click(magic_api * api, int which, int mode, void trochoids_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
SDL_Rect * update_rect);
void trochoids_drag(magic_api * api, int which, void trochoids_drag(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot,
int old_x, int old_y, int x, int y,
SDL_Rect * update_rect);
void trochoids_work(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, SDL_Surface * canvas, SDL_Surface * snapshot,
int x, int y, SDL_Rect * update_rect, int guides); int old_x, int old_y, int x, int y, SDL_Rect * update_rect);
void trochoids_work(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect, int guides);
void trochoids_release(magic_api * api, int which, void trochoids_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
SDL_Rect * update_rect);
void trochoids_sound(magic_api * api, int snd_idx, int x, int y); void trochoids_sound(magic_api * api, int snd_idx, int x, int y);
void trochoids_set_color(magic_api * api, int which, SDL_Surface * canvas, void trochoids_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, Uint8 r, Uint8 g, Uint8 b, SDL_Surface * snapshot, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
SDL_Rect * update_rect);
void trochoids_set_size(magic_api * api, int which, int mode, void trochoids_set_size(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
Uint8 size, SDL_Rect * update_rect); void trochoids_line_callback(void *pointer, int tool, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
void trochoids_line_callback(void *pointer, int tool, SDL_Surface * canvas, void trochoids_xorline_callback(void *pointer, int tool, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
SDL_Surface * snapshot, int x, int y); void trochoids_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
void trochoids_xorline_callback(void *pointer, int tool, SDL_Surface * canvas, void trochoids_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
SDL_Surface * snapshot, int x, int y);
void trochoids_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void trochoids_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
int calc_lcm(int a, int b); int calc_lcm(int a, int b);
@ -208,13 +208,17 @@ int trochoids_init(magic_api * api, Uint8 disabled_features, Uint8 complexity_le
int i; int i;
char filename[1024]; char filename[1024];
for (i = 0; i < NUM_SNDS; i++) { for (i = 0; i < NUM_SNDS; i++)
{
sound_effects[i] = NULL; sound_effects[i] = NULL;
} }
if (disabled_features & MAGIC_FEATURE_SIZE) { if (disabled_features & MAGIC_FEATURE_SIZE)
{
tp_offers_sizes = 0; tp_offers_sizes = 0;
} else { }
else
{
tp_offers_sizes = 1; tp_offers_sizes = 1;
} }
@ -222,8 +226,7 @@ int trochoids_init(magic_api * api, Uint8 disabled_features, Uint8 complexity_le
for (i = 0; i < NUM_SNDS; i++) for (i = 0; i < NUM_SNDS; i++)
{ {
snprintf(filename, sizeof(filename), "%ssounds/magic/%s", api->data_directory, snprintf(filename, sizeof(filename), "%ssounds/magic/%s", api->data_directory, sound_filenames[i]);
sound_filenames[i]);
sound_effects[i] = Mix_LoadWAV(filename); sound_effects[i] = Mix_LoadWAV(filename);
} }
@ -241,8 +244,7 @@ SDL_Surface *trochoids_get_icon(magic_api * api, int which)
{ {
char filename[1024]; char filename[1024];
snprintf(filename, sizeof(filename), "%simages/magic/%s", snprintf(filename, sizeof(filename), "%simages/magic/%s", api->data_directory, icon_filenames[which_to_tool[which]]);
api->data_directory, icon_filenames[which_to_tool[which]]);
return (IMG_Load(filename)); return (IMG_Load(filename));
} }
@ -289,8 +291,7 @@ Uint8 trochoids_accepted_sizes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRI
} }
Uint8 trochoids_default_size(magic_api * api ATTRIBUTE_UNUSED, Uint8 trochoids_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{ {
return DEFAULT_SIZE; return DEFAULT_SIZE;
} }
@ -300,8 +301,10 @@ void trochoids_shutdown(magic_api * api ATTRIBUTE_UNUSED)
{ {
int i; int i;
for (i = 0; i < NUM_SNDS; i++) { for (i = 0; i < NUM_SNDS; i++)
if (sound_effects[i] != NULL) { {
if (sound_effects[i] != NULL)
{
Mix_FreeChunk(sound_effects[i]); Mix_FreeChunk(sound_effects[i]);
} }
} }
@ -309,8 +312,7 @@ void trochoids_shutdown(magic_api * api ATTRIBUTE_UNUSED)
void trochoids_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED, void trochoids_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
SDL_Rect * update_rect)
{ {
trochoids_x = x; trochoids_x = x;
trochoids_y = y; trochoids_y = y;
@ -322,8 +324,7 @@ void trochoids_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
/* Affect the canvas on drag: */ /* Affect the canvas on drag: */
void trochoids_drag(magic_api * api, int which, void trochoids_drag(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, SDL_Surface * canvas, SDL_Surface * snapshot,
int old_x ATTRIBUTE_UNUSED, int old_y ATTRIBUTE_UNUSED, int old_x ATTRIBUTE_UNUSED, int old_y ATTRIBUTE_UNUSED, int x, int y, SDL_Rect * update_rect)
int x, int y, SDL_Rect * update_rect)
{ {
dragged = 1; dragged = 1;
trochoids_work(api, which, canvas, snapshot, x, y, update_rect, 1); trochoids_work(api, which, canvas, snapshot, x, y, update_rect, 1);
@ -331,8 +332,8 @@ void trochoids_drag(magic_api * api, int which,
} }
void trochoids_work(magic_api * api, int which, void trochoids_work(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect, int guides)
int x, int y, SDL_Rect * update_rect, int guides) { {
int R, r, d, LCM; int R, r, d, LCM;
int px, py, px2, py2; int px, py, px2, py2;
float a, r_ratio, size; float a, r_ratio, size;
@ -342,7 +343,8 @@ void trochoids_work(magic_api * api, int which,
/* Drag left/right to change radius of stator (fixed circle) */ /* Drag left/right to change radius of stator (fixed circle) */
R = abs(trochoids_x - x); R = abs(trochoids_x - x);
if (R < 20) { if (R < 20)
{
R = 20; R = 20;
} }
@ -350,7 +352,8 @@ void trochoids_work(magic_api * api, int which,
/* Drag down to increase radius of rotator (rolling circle) */ /* Drag down to increase radius of rotator (rolling circle) */
r = abs(y - trochoids_y); r = abs(y - trochoids_y);
if (r < 10) { if (r < 10)
{
r = 10; r = 10;
} }
@ -358,25 +361,31 @@ void trochoids_work(magic_api * api, int which,
if (which == TOOL_HYPOTROCHOID_SIZES || if (which == TOOL_HYPOTROCHOID_SIZES ||
which == TOOL_HYPOTROCHOID_NOSIZES_1 || which == TOOL_HYPOTROCHOID_NOSIZES_1 ||
which == TOOL_HYPOTROCHOID_NOSIZES_2 || which == TOOL_HYPOTROCHOID_NOSIZES_2 || which == TOOL_HYPOTROCHOID_NOSIZES_3)
which == TOOL_HYPOTROCHOID_NOSIZES_3) { {
/* Hypotrochoid */ /* Hypotrochoid */
if (R == r) { if (R == r)
{
r += 10; r += 10;
} }
r_ratio = (float) (R - r) / (float) r; r_ratio = (float)(R - r) / (float)r;
} else { }
else
{
/* Epitrochoid */ /* Epitrochoid */
r_ratio = (float) (R + r) / (float) r; r_ratio = (float)(R + r) / (float)r;
} }
/* Size option (or use of alternate tools, if --nomagicsizes) /* Size option (or use of alternate tools, if --nomagicsizes)
determines the distance from the center of the rotator determines the distance from the center of the rotator
that the pen draws */ that the pen draws */
if (tp_offers_sizes) { if (tp_offers_sizes)
{
size = trochoids_sizes_per_size_setting[trochoids_size]; size = trochoids_sizes_per_size_setting[trochoids_size];
} else { }
else
{
size = trochoids_sizes_per_tool[which]; size = trochoids_sizes_per_tool[which];
} }
d = r * size; d = r * size;
@ -394,19 +403,22 @@ void trochoids_work(magic_api * api, int which,
/* Draw the lines */ /* Draw the lines */
LCM = calc_lcm(r, R); LCM = calc_lcm(r, R);
for (a = 0; a < 360.0 * (float) (LCM / R); a++) { for (a = 0; a < 360.0 * (float)(LCM / R); a++)
{
float a2 = (a + 1); float a2 = (a + 1);
if (which == TOOL_HYPOTROCHOID_SIZES || if (which == TOOL_HYPOTROCHOID_SIZES ||
which == TOOL_HYPOTROCHOID_NOSIZES_1 || which == TOOL_HYPOTROCHOID_NOSIZES_1 ||
which == TOOL_HYPOTROCHOID_NOSIZES_2 || which == TOOL_HYPOTROCHOID_NOSIZES_2 || which == TOOL_HYPOTROCHOID_NOSIZES_3)
which == TOOL_HYPOTROCHOID_NOSIZES_3) { {
/* Hypotrochoid */ /* Hypotrochoid */
px = trochoids_x + (((R - r) * deg_cos(a)) + (d * deg_cos(r_ratio * a))); px = trochoids_x + (((R - r) * deg_cos(a)) + (d * deg_cos(r_ratio * a)));
py = trochoids_y + (((R - r) * deg_sin(a)) - (d * deg_sin(r_ratio * a))); py = trochoids_y + (((R - r) * deg_sin(a)) - (d * deg_sin(r_ratio * a)));
px2 = trochoids_x + (((R - r) * deg_cos((a2))) + (d * deg_cos(r_ratio * a2))); px2 = trochoids_x + (((R - r) * deg_cos((a2))) + (d * deg_cos(r_ratio * a2)));
py2 = trochoids_y + (((R - r) * deg_sin((a2))) - (d * deg_sin(r_ratio * a2))); py2 = trochoids_y + (((R - r) * deg_sin((a2))) - (d * deg_sin(r_ratio * a2)));
} else { }
else
{
/* Epitrochoid */ /* Epitrochoid */
px = trochoids_x + (((R + r) * deg_cos(a)) - (d * deg_cos(r_ratio * a))); px = trochoids_x + (((R + r) * deg_cos(a)) - (d * deg_cos(r_ratio * a)));
py = trochoids_y + (((R + r) * deg_sin(a)) - (d * deg_sin(r_ratio * a))); py = trochoids_y + (((R + r) * deg_sin(a)) - (d * deg_sin(r_ratio * a)));
@ -414,25 +426,29 @@ void trochoids_work(magic_api * api, int which,
py2 = trochoids_y + (((R + r) * deg_sin((a2))) - (d * deg_sin(r_ratio * a2))); py2 = trochoids_y + (((R + r) * deg_sin((a2))) - (d * deg_sin(r_ratio * a2)));
} }
api->line((void *)api, which, canvas, snapshot, px, py, px2, py2, (20 * (guides && (a >= 360.0))) + 1, trochoids_line_callback); api->line((void *)api, which, canvas, snapshot, px, py, px2, py2, (20 * (guides && (a >= 360.0))) + 1,
trochoids_line_callback);
} }
if (guides) { if (guides)
{
int guide_spacing; int guide_spacing;
/* When still dragging (before release), draw some "guides", /* When still dragging (before release), draw some "guides",
showing the mechanism that would be used to generate the pattern */ showing the mechanism that would be used to generate the pattern */
rotator_anim_a = (int) (atan2(y - trochoids_y, x - trochoids_x) / M_PI * 180.0); rotator_anim_a = (int)(atan2(y - trochoids_y, x - trochoids_x) / M_PI * 180.0);
/* Stator (fixed circle) */ /* Stator (fixed circle) */
guide_spacing = 360 / R; guide_spacing = 360 / R;
if (guide_spacing < 2) { if (guide_spacing < 2)
{
guide_spacing = 2; guide_spacing = 2;
} }
for (a = 0; a < 360; a = a + guide_spacing) { for (a = 0; a < 360; a = a + guide_spacing)
px = (int) ((float) trochoids_x + ((float) R * deg_cos(a))); {
py = (int) ((float) trochoids_y - ((float) R * deg_sin(a))); px = (int)((float)trochoids_x + ((float)R * deg_cos(a)));
py = (int)((float)trochoids_y - ((float)R * deg_sin(a)));
api->putpixel(canvas, px, py, 0); api->putpixel(canvas, px, py, 0);
api->putpixel(canvas, px + 1, py, 0xff); api->putpixel(canvas, px + 1, py, 0xff);
api->putpixel(canvas, px, py + 1, 0); api->putpixel(canvas, px, py + 1, 0);
@ -441,22 +457,26 @@ void trochoids_work(magic_api * api, int which,
/* Rotator (rolling circle) */ /* Rotator (rolling circle) */
guide_spacing = 360 / r; guide_spacing = 360 / r;
if (guide_spacing < 2) { if (guide_spacing < 2)
{
guide_spacing = 2; guide_spacing = 2;
} }
for (a = 0; a < 360; a = a + guide_spacing) { for (a = 0; a < 360; a = a + guide_spacing)
{
if (which == TOOL_HYPOTROCHOID_SIZES || if (which == TOOL_HYPOTROCHOID_SIZES ||
which == TOOL_HYPOTROCHOID_NOSIZES_1 || which == TOOL_HYPOTROCHOID_NOSIZES_1 ||
which == TOOL_HYPOTROCHOID_NOSIZES_2 || which == TOOL_HYPOTROCHOID_NOSIZES_2 || which == TOOL_HYPOTROCHOID_NOSIZES_3)
which == TOOL_HYPOTROCHOID_NOSIZES_3) { {
/* Hypotrochoid */ /* Hypotrochoid */
px = (int) ((float) trochoids_x + ((R - r) * deg_cos(rotator_anim_a)) + ((float) -r * deg_cos(a))); px = (int)((float)trochoids_x + ((R - r) * deg_cos(rotator_anim_a)) + ((float)-r * deg_cos(a)));
py = (int) ((float) trochoids_y + ((R - r) * deg_sin(rotator_anim_a)) - ((float) -r * deg_sin(a))); py = (int)((float)trochoids_y + ((R - r) * deg_sin(rotator_anim_a)) - ((float)-r * deg_sin(a)));
} else { }
else
{
/* Epitrochoid */ /* Epitrochoid */
px = (int) ((float) trochoids_x + ((R + r) * deg_cos(rotator_anim_a)) + ((float) r * deg_cos(a))); px = (int)((float)trochoids_x + ((R + r) * deg_cos(rotator_anim_a)) + ((float)r * deg_cos(a)));
py = (int) ((float) trochoids_y + ((R + r) * deg_sin(rotator_anim_a)) - ((float) r * deg_sin(a))); py = (int)((float)trochoids_y + ((R + r) * deg_sin(rotator_anim_a)) - ((float)r * deg_sin(a)));
} }
api->xorpixel(canvas, px, py); api->xorpixel(canvas, px, py);
api->xorpixel(canvas, px + 1, py); api->xorpixel(canvas, px + 1, py);
@ -468,15 +488,17 @@ void trochoids_work(magic_api * api, int which,
/* Pen */ /* Pen */
if (which == TOOL_HYPOTROCHOID_SIZES || if (which == TOOL_HYPOTROCHOID_SIZES ||
which == TOOL_HYPOTROCHOID_NOSIZES_1 || which == TOOL_HYPOTROCHOID_NOSIZES_1 ||
which == TOOL_HYPOTROCHOID_NOSIZES_2 || which == TOOL_HYPOTROCHOID_NOSIZES_2 || which == TOOL_HYPOTROCHOID_NOSIZES_3)
which == TOOL_HYPOTROCHOID_NOSIZES_3) { {
/* Hypotrochoid */ /* Hypotrochoid */
px = trochoids_x + (((R - r) * deg_cos(rotator_anim_a)) + (d * deg_cos(360 - rotator_anim_a))); px = trochoids_x + (((R - r) * deg_cos(rotator_anim_a)) + (d * deg_cos(360 - rotator_anim_a)));
py = trochoids_y + (((R - r) * deg_sin(rotator_anim_a)) - (d * deg_sin(360 - rotator_anim_a))); py = trochoids_y + (((R - r) * deg_sin(rotator_anim_a)) - (d * deg_sin(360 - rotator_anim_a)));
px2 = trochoids_x + (((R - r) * deg_cos(rotator_anim_a))); px2 = trochoids_x + (((R - r) * deg_cos(rotator_anim_a)));
py2 = trochoids_y + (((R - r) * deg_sin(rotator_anim_a))); py2 = trochoids_y + (((R - r) * deg_sin(rotator_anim_a)));
} else { }
else
{
/* Epitrochoid */ /* Epitrochoid */
px = trochoids_x + (((R + r) * deg_cos(rotator_anim_a)) - (d * deg_cos(360 - rotator_anim_a))); px = trochoids_x + (((R + r) * deg_cos(rotator_anim_a)) - (d * deg_cos(360 - rotator_anim_a)));
py = trochoids_y + (((R + r) * deg_sin(rotator_anim_a)) - (d * deg_sin(360 - rotator_anim_a))); py = trochoids_y + (((R + r) * deg_sin(rotator_anim_a)) - (d * deg_sin(360 - rotator_anim_a)));
@ -487,8 +509,10 @@ void trochoids_work(magic_api * api, int which,
api->line((void *)api, which, canvas, snapshot, px, py, px2, py2, 2, trochoids_line_callback); api->line((void *)api, which, canvas, snapshot, px, py, px2, py2, 2, trochoids_line_callback);
for (yy = -2; yy <= 2; yy++) { for (yy = -2; yy <= 2; yy++)
for (xx = -2; xx <= 2; xx++) { {
for (xx = -2; xx <= 2; xx++)
{
api->putpixel(canvas, px + xx, py + yy, trochoids_color); api->putpixel(canvas, px + xx, py + yy, trochoids_color);
} }
} }
@ -497,8 +521,7 @@ void trochoids_work(magic_api * api, int which,
void trochoids_release(magic_api * api, int which, void trochoids_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
int x, int y, SDL_Rect * update_rect)
{ {
int tool, snd_idx; int tool, snd_idx;
@ -511,11 +534,12 @@ void trochoids_release(magic_api * api, int which,
/* Pick which sound to play & play it */ /* Pick which sound to play & play it */
tool = which_to_tool[which]; tool = which_to_tool[which];
if (tool == TOOL_EPITROCHOID_SIZES || if (tool == TOOL_EPITROCHOID_SIZES ||
tool == TOOL_EPITROCHOID_NOSIZES_1 || tool == TOOL_EPITROCHOID_NOSIZES_1 || tool == TOOL_EPITROCHOID_NOSIZES_2 || tool == TOOL_EPITROCHOID_NOSIZES_3)
tool == TOOL_EPITROCHOID_NOSIZES_2 || {
tool == TOOL_EPITROCHOID_NOSIZES_3) {
snd_idx = SND_RELEASE_EPITROCHOID; snd_idx = SND_RELEASE_EPITROCHOID;
} else { }
else
{
snd_idx = SND_RELEASE_HYPOTROCHOID; snd_idx = SND_RELEASE_HYPOTROCHOID;
} }
trochoids_sound(api, snd_idx, x, y); trochoids_sound(api, snd_idx, x, y);
@ -525,14 +549,16 @@ void trochoids_release(magic_api * api, int which,
ignore the (x,y) we received; we want the ignore the (x,y) we received; we want the
'default' offset to get a reasonably pleasant 'default' offset to get a reasonably pleasant
shape -- for users who tried clicking w/o dragging */ shape -- for users who tried clicking w/o dragging */
if (dragged == 0) { if (dragged == 0)
{
if (tool == TOOL_EPITROCHOID_SIZES || if (tool == TOOL_EPITROCHOID_SIZES ||
tool == TOOL_EPITROCHOID_NOSIZES_1 || tool == TOOL_EPITROCHOID_NOSIZES_1 || tool == TOOL_EPITROCHOID_NOSIZES_2 || tool == TOOL_EPITROCHOID_NOSIZES_3)
tool == TOOL_EPITROCHOID_NOSIZES_2 || {
tool == TOOL_EPITROCHOID_NOSIZES_3) {
x = trochoids_x + 50; x = trochoids_x + 50;
y = trochoids_y + 20; y = trochoids_y + 20;
} else { }
else
{
x = trochoids_x + 70; x = trochoids_x + 70;
y = trochoids_y + 30; y = trochoids_y + 30;
} }
@ -546,19 +572,24 @@ void trochoids_release(magic_api * api, int which,
/* Play a sound; volume and panning will be based /* Play a sound; volume and panning will be based
on the size and position of the shape being generated on the size and position of the shape being generated
by the user's UI interaction */ by the user's UI interaction */
void trochoids_sound(magic_api * api, int snd_idx, int x, int y) { void trochoids_sound(magic_api * api, int snd_idx, int x, int y)
{
int R, vol, pan; int R, vol, pan;
/* Volume based on the radii of the stator (fixed circle) /* Volume based on the radii of the stator (fixed circle)
and the rotator (rolling circle), combined; larger = louder */ and the rotator (rolling circle), combined; larger = louder */
R = abs(trochoids_x - x) + abs(trochoids_y - y); R = abs(trochoids_x - x) + abs(trochoids_y - y);
if (R < 20) { if (R < 20)
{
R = 20; R = 20;
} else if (R > api->canvas_w) { }
else if (R > api->canvas_w)
{
R = api->canvas_w; R = api->canvas_w;
} }
vol = (255 * R * 2) / api->canvas_w; vol = (255 * R * 2) / api->canvas_w;
if (vol > 255) { if (vol > 255)
{
vol = 255; vol = 255;
} }
@ -569,26 +600,24 @@ void trochoids_sound(magic_api * api, int snd_idx, int x, int y) {
void trochoids_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, void trochoids_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * snapshot ATTRIBUTE_UNUSED, SDL_Surface * snapshot ATTRIBUTE_UNUSED,
Uint8 r, Uint8 g, Uint8 b, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{ {
trochoids_color = SDL_MapRGB(canvas->format, r, g, b); trochoids_color = SDL_MapRGB(canvas->format, r, g, b);
} }
void trochoids_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, void trochoids_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 size, SDL_Rect * update_rect ATTRIBUTE_UNUSED) Uint8 size, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{ {
trochoids_size = (size - 1); /* array index is 0-based, but Tux Paint returns between 1...{accepted sizes} */ trochoids_size = (size - 1); /* array index is 0-based, but Tux Paint returns between 1...{accepted sizes} */
} }
void trochoids_line_callback(void *pointer ATTRIBUTE_UNUSED, int tool ATTRIBUTE_UNUSED, void trochoids_line_callback(void *pointer ATTRIBUTE_UNUSED, int tool ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
int x, int y)
{ {
magic_api *api = (magic_api *) pointer; magic_api *api = (magic_api *) pointer;
@ -596,8 +625,7 @@ void trochoids_line_callback(void *pointer ATTRIBUTE_UNUSED, int tool ATTRIBUTE_
} }
void trochoids_xorline_callback(void *pointer ATTRIBUTE_UNUSED, int tool ATTRIBUTE_UNUSED, void trochoids_xorline_callback(void *pointer ATTRIBUTE_UNUSED, int tool ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
int x, int y)
{ {
magic_api *api = (magic_api *) pointer; magic_api *api = (magic_api *) pointer;
@ -608,25 +636,30 @@ void trochoids_xorline_callback(void *pointer ATTRIBUTE_UNUSED, int tool ATTRIBU
} }
void trochoids_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, void trochoids_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED) SDL_Surface * canvas ATTRIBUTE_UNUSED)
{ {
} }
void trochoids_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, void trochoids_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED) SDL_Surface * canvas ATTRIBUTE_UNUSED)
{ {
} }
int calc_lcm(int a, int b) { int calc_lcm(int a, int b)
{
int max; int max;
if (a > b) { if (a > b)
{
max = a; max = a;
} else { }
else
{
max = b; max = b;
} }
while ((max % a) != 0 || (max % b) != 0) { while ((max % a) != 0 || (max % b) != 0)
{
max++; max++;
} }

View file

@ -236,16 +236,12 @@ void loadfont_callback(SDL_Surface * screen, SDL_Texture * texture,
charset_works(font, /* digits (e.g., '0', '1' and '7') */ gettext("017") charset_works(font, /* digits (e.g., '0', '1' and '7') */ gettext("017")
); );
user_font_styles[num_font_styles]->score += user_font_styles[num_font_styles]->score += charset_works(font, /* distinct circle-like characters (e.g., 'O' (capital oh) vs. '0' (zero)) */
charset_works(font, /* distinct circle-like characters (e.g., 'O' (capital oh) vs. '0' (zero)) */ gettext("O0"));
gettext("O0")
);
user_font_styles[num_font_styles]->score += user_font_styles[num_font_styles]->score += charset_works(font,
charset_works(font, /* distinct line-like characters (e.g., 'l' (lowercase elle) vs. '1' (one) vs. 'I' (capital aye)) */
/* distinct line-like characters (e.g., 'l' (lowercase elle) vs. '1' (one) vs. 'I' (capital aye)) */ gettext("1Il|"));
gettext("1Il|")
);
// Translation spares // Translation spares

View file

@ -174,8 +174,8 @@ int button_label_y_nudge;
static void reliable_read(int fd, void *buf, size_t count); static void reliable_read(int fd, void *buf, size_t count);
#endif #endif
const char * PANGO_DEFAULT_FONT = "DejaVu Sans"; const char *PANGO_DEFAULT_FONT = "DejaVu Sans";
const char * PANGO_DEFAULT_FONT_FALLBACK = NULL; const char *PANGO_DEFAULT_FONT_FALLBACK = NULL;
/* Names of the fonts we include in `fonts/locale/` /* Names of the fonts we include in `fonts/locale/`
(LANG_* codes are from `src/i18n.h`) */ (LANG_* codes are from `src/i18n.h`) */
@ -186,22 +186,22 @@ const char * PANGO_DEFAULT_FONT_FALLBACK = NULL;
download of the full (much larger) font TTF file. download of the full (much larger) font TTF file.
(https://tuxpaint.org/download/fonts/) */ (https://tuxpaint.org/download/fonts/) */
default_locale_font_t default_local_fonts[] = { default_locale_font_t default_local_fonts[] = {
{ LANG_AR, "ae_Nice", NULL }, {LANG_AR, "ae_Nice", NULL},
{ LANG_BO, "Tsampa Keyboard", NULL }, // NOTE: Our current translation is Wylie transliterated, not Unicode! */ {LANG_BO, "Tsampa Keyboard", NULL}, // NOTE: Our current translation is Wylie transliterated, not Unicode! */
{ LANG_EL, "Thryomanes", NULL}, {LANG_EL, "Thryomanes", NULL},
{ LANG_GU, "Lohit Gujarati", NULL }, {LANG_GU, "Lohit Gujarati", NULL},
{ LANG_HE, "Nachlieli Light", NULL }, {LANG_HE, "Nachlieli Light", NULL},
{ LANG_HI, "Raghindi", NULL }, {LANG_HI, "Raghindi", NULL},
{ LANG_JA, "Noto Sans CJK JP", "GJGothicPNSubset" }, {LANG_JA, "Noto Sans CJK JP", "GJGothicPNSubset"},
{ LANG_KA, "TuxPaint Georgian", NULL }, /* FIXME: Upon what was this font based? Never knew -bjk 2023.06.12 */ {LANG_KA, "TuxPaint Georgian", NULL}, /* FIXME: Upon what was this font based? Never knew -bjk 2023.06.12 */
{ LANG_KO, "Baekmuk Gulim", NULL }, {LANG_KO, "Baekmuk Gulim", NULL},
{ LANG_TA, "TSCu_Comic", NULL }, {LANG_TA, "TSCu_Comic", NULL},
{ LANG_TE, "Vemana2000", NULL }, {LANG_TE, "Vemana2000", NULL},
{ LANG_TH, "Garuda", NULL }, {LANG_TH, "Garuda", NULL},
{ LANG_ZH_CN, "AR PL SungtiL GB", NULL }, {LANG_ZH_CN, "AR PL SungtiL GB", NULL},
{ LANG_ZH_TW, "HanWangKaiMediumChuIn", "SubsetForTuxPaint" }, {LANG_ZH_TW, "HanWangKaiMediumChuIn", "SubsetForTuxPaint"},
{ -1, NULL, NULL }, {-1, NULL, NULL},
}; };
void TuxPaint_Font_CloseFont(TuxPaint_Font * tpf) void TuxPaint_Font_CloseFont(TuxPaint_Font * tpf)
{ {
@ -340,7 +340,7 @@ TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc, const char *ttffile
return NULL; return NULL;
} }
familyname = (char *) TTF_FontFaceFamilyName(ttf_font); /* N.B.: I don't believe we're supposed to free() this... -bjk 2021.10.26 */ familyname = (char *)TTF_FontFaceFamilyName(ttf_font); /* N.B.: I don't believe we're supposed to free() this... -bjk 2021.10.26 */
(void)familyname; // avoid compiler complaints if ALWAYS_LOAD_FONT_WITH_PANGO is not set, and DEBUG is not set (void)familyname; // avoid compiler complaints if ALWAYS_LOAD_FONT_WITH_PANGO is not set, and DEBUG is not set
#ifdef DEBUG #ifdef DEBUG
@ -1715,72 +1715,72 @@ void sdl_color_to_pango_color(SDL_Color sdl_color, SDLPango_Matrix * pango_color
* (e.g., "tuxpaint --uifont bookman" finds and uses "URW Bookman" * (e.g., "tuxpaint --uifont bookman" finds and uses "URW Bookman"
* on my system -bjk 2023.06.01) * on my system -bjk 2023.06.01)
*/ */
char * ask_pango_for_font(char * pangodesc) char *ask_pango_for_font(char *pangodesc)
{ {
PangoFontMap * font_map; PangoFontMap *font_map;
PangoContext * context; PangoContext *context;
PangoFontDescription * font_desc; PangoFontDescription *font_desc;
PangoFont *font; PangoFont *font;
PangoFontDescription * pfd; PangoFontDescription *pfd;
char * descr; char *descr;
font_map = pango_ft2_font_map_new(); font_map = pango_ft2_font_map_new();
if (font_map == NULL) if (font_map == NULL)
{ {
fprintf(stderr, "pango_ft2_font_map_new() failed\n"); fprintf(stderr, "pango_ft2_font_map_new() failed\n");
fflush(stderr); fflush(stderr);
return NULL; return NULL;
} }
context = pango_font_map_create_context(font_map); context = pango_font_map_create_context(font_map);
if (context == NULL) if (context == NULL)
{ {
fprintf(stderr, "pango_font_map_create_context() failed\n"); fprintf(stderr, "pango_font_map_create_context() failed\n");
fflush(stderr); fflush(stderr);
g_object_unref(font_map); g_object_unref(font_map);
return NULL; return NULL;
} }
font_desc = pango_font_description_from_string(pangodesc); font_desc = pango_font_description_from_string(pangodesc);
if (font_desc == NULL) if (font_desc == NULL)
{ {
fprintf(stderr, "pango_font_description_from_string() failed\n"); fprintf(stderr, "pango_font_description_from_string() failed\n");
fflush(stderr); fflush(stderr);
g_object_unref(font_map); g_object_unref(font_map);
g_object_unref(context); g_object_unref(context);
return NULL; return NULL;
} }
font = pango_font_map_load_font(font_map, context, font_desc); font = pango_font_map_load_font(font_map, context, font_desc);
if (font == NULL) if (font == NULL)
{ {
fprintf(stderr, "pango_font_map_load_font() failed\n"); fprintf(stderr, "pango_font_map_load_font() failed\n");
fflush(stderr); fflush(stderr);
g_object_unref(font_map); g_object_unref(font_map);
g_object_unref(context); g_object_unref(context);
pango_font_description_free(font_desc); pango_font_description_free(font_desc);
return NULL; return NULL;
} }
pfd = pango_font_describe(font);
if (pfd == NULL)
{
fprintf(stderr, "pango_font_describe() failed\n");
fflush(stderr);
g_object_unref(font_map);
g_object_unref(context);
pango_font_description_free(font_desc);
g_object_unref(font);
return NULL;
}
descr = strdup(pango_font_description_get_family(pfd));
pfd = pango_font_describe(font);
if (pfd == NULL)
{
fprintf(stderr, "pango_font_describe() failed\n");
fflush(stderr);
g_object_unref(font_map); g_object_unref(font_map);
g_object_unref(context); g_object_unref(context);
pango_font_description_free(font_desc); pango_font_description_free(font_desc);
g_object_unref(font); g_object_unref(font);
/* N.B. Not free'ing `pfd`: The data is owned by the instance */ return NULL;
}
return descr; descr = strdup(pango_font_description_get_family(pfd));
g_object_unref(font_map);
g_object_unref(context);
pango_font_description_free(font_desc);
g_object_unref(font);
/* N.B. Not free'ing `pfd`: The data is owned by the instance */
return descr;
} }

View file

@ -49,14 +49,15 @@
based on locale. based on locale.
*/ */
typedef struct default_locale_font_s { typedef struct default_locale_font_s
{
int locale_id; int locale_id;
const char * font_name; const char *font_name;
const char * font_name_fallback; const char *font_name_fallback;
} default_locale_font_t; } default_locale_font_t;
extern default_locale_font_t default_local_fonts[]; extern default_locale_font_t default_local_fonts[];
extern const char * PANGO_DEFAULT_FONT, * PANGO_DEFAULT_FONT_FALLBACK; extern const char *PANGO_DEFAULT_FONT, *PANGO_DEFAULT_FONT_FALLBACK;
#include "compiler.h" #include "compiler.h"
@ -177,6 +178,6 @@ void sdl_color_to_pango_color(SDL_Color sdl_color, SDLPango_Matrix * pango_color
int load_user_fonts(SDL_Surface * screen, SDL_Texture * texture, int load_user_fonts(SDL_Surface * screen, SDL_Texture * texture,
SDL_Renderer * renderer, void *vp, const char *restrict const locale); SDL_Renderer * renderer, void *vp, const char *restrict const locale);
char * ask_pango_for_font(char * pangodesc); char *ask_pango_for_font(char *pangodesc);
#endif #endif

View file

@ -22,7 +22,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt) (See COPYING.txt)
June 14, 2002 - April 10, 2024 June 14, 2002 - May 10, 2024
*/ */
#include "platform.h" #include "platform.h"
@ -582,7 +582,7 @@ int iswprint(wchar_t wc)
#include "compiler.h" #include "compiler.h"
char * tp_ui_font = NULL; char *tp_ui_font = NULL;
/* Convert floats to fractions between (min/max) and ((max-min)/max) /* Convert floats to fractions between (min/max) and ((max-min)/max)
(anything with smaller resolution will round up or down) */ (anything with smaller resolution will round up or down) */
@ -860,7 +860,8 @@ static void set_max_buttonscale(void)
max_h = (float)WINDOW_HEIGHT / (40 + (6 * 48) + (gd_colors.rows * 48) + 56); max_h = (float)WINDOW_HEIGHT / (40 + (6 * 48) + (gd_colors.rows * 48) + 56);
button_scale = min(max_w, max_h); button_scale = min(max_w, max_h);
fprintf(stderr, "Will use a button size of %d (scale = %f)\n", (int)(button_scale * ORIGINAL_BUTTON_SIZE), button_scale); fprintf(stderr, "Will use a button size of %d (scale = %f)\n", (int)(button_scale * ORIGINAL_BUTTON_SIZE),
button_scale);
} }
/** /**
@ -1558,13 +1559,13 @@ typedef struct magic_funcs_s
SDL_Surface *(*get_icon)(magic_api *, int); SDL_Surface *(*get_icon)(magic_api *, int);
char *(*get_description)(magic_api *, int, int); char *(*get_description)(magic_api *, int, int);
int (*requires_colors)(magic_api *, int); int (*requires_colors)(magic_api *, int);
Uint8(*accepted_sizes) (magic_api *, int, int); Uint8(*accepted_sizes) (magic_api *, int, int);
Uint8(*default_size) (magic_api *, int, int); Uint8(*default_size) (magic_api *, int, int);
int (*modes)(magic_api *, int); int (*modes)(magic_api *, int);
void (*set_color)(magic_api *, int, SDL_Surface *, SDL_Surface *, Uint8, Uint8, Uint8, SDL_Rect *); void (*set_color)(magic_api *, int, SDL_Surface *, SDL_Surface *, Uint8, Uint8, Uint8, SDL_Rect *);
void (*set_size)(magic_api *, int, int, SDL_Surface *, SDL_Surface *, Uint8, SDL_Rect *); void (*set_size)(magic_api *, int, int, SDL_Surface *, SDL_Surface *, Uint8, SDL_Rect *);
int (*init)(magic_api *, Uint8, Uint8); int (*init)(magic_api *, Uint8, Uint8);
Uint32(*api_version) (void); Uint32(*api_version) (void);
void (*shutdown)(magic_api *); void (*shutdown)(magic_api *);
void (*click)(magic_api *, int, int, SDL_Surface *, SDL_Surface *, int, int, SDL_Rect *); void (*click)(magic_api *, int, int, SDL_Surface *, SDL_Surface *, int, int, SDL_Rect *);
void (*drag)(magic_api *, int, SDL_Surface *, SDL_Surface *, int, int, int, int, SDL_Rect *); void (*drag)(magic_api *, int, SDL_Surface *, SDL_Surface *, int, int, int, int, SDL_Rect *);
@ -1971,7 +1972,8 @@ static int img_cur_brush_frame_w, img_cur_brush_w, img_cur_brush_h,
img_cur_brush_frames, img_cur_brush_directional, img_cur_brush_rotate, img_cur_brush_spacing; img_cur_brush_frames, img_cur_brush_directional, img_cur_brush_rotate, img_cur_brush_spacing;
static int brush_counter, brush_frame; static int brush_counter, brush_frame;
enum { enum
{
ERASER_TYPE_SQUARE, ERASER_TYPE_SQUARE,
ERASER_TYPE_CIRCLE, ERASER_TYPE_CIRCLE,
ERASER_TYPE_CIRCLE_FUZZY, ERASER_TYPE_CIRCLE_FUZZY,
@ -2220,25 +2222,27 @@ static int export_gif(int *selected, int num_selected, char *dirname, char **d_n
int export_gif_monitor_events(void); int export_gif_monitor_events(void);
/* Locations where export_pict() can save */ /* Locations where export_pict() can save */
enum { enum
{
EXPORT_LOC_PICTURES, EXPORT_LOC_PICTURES,
EXPORT_LOC_TEMPLATES EXPORT_LOC_TEMPLATES
}; };
/* Return values of export_pict() */ /* Return values of export_pict() */
enum { enum
{
EXPORT_SUCCESS, EXPORT_SUCCESS,
EXPORT_ERR_CANNOT_MKDIR, /* Need to mkdir() but cannot */ EXPORT_ERR_CANNOT_MKDIR, /* Need to mkdir() but cannot */
EXPORT_ERR_FILENAME_PROBLEM, /* Problem creating output file's filename */ EXPORT_ERR_FILENAME_PROBLEM, /* Problem creating output file's filename */
EXPORT_ERR_CANNOT_OPEN_SOURCE, /* Can't open input file for read */ EXPORT_ERR_CANNOT_OPEN_SOURCE, /* Can't open input file for read */
EXPORT_ERR_CANNOT_SAVE, /* Can't open export file for write */ EXPORT_ERR_CANNOT_SAVE, /* Can't open export file for write */
EXPORT_ERR_ALREADY_EXPORTED /* Exported template appears to already exist */ EXPORT_ERR_ALREADY_EXPORTED /* Exported template appears to already exist */
}; };
static int export_pict(char *fname, int where, char * orig_fname); static int export_pict(char *fname, int where, char *orig_fname);
static char *get_export_filepath(const char *ext); static char *get_export_filepath(const char *ext);
void get_img_dimensions(char * fpath, int * widht, int * height); void get_img_dimensions(char *fpath, int *widht, int *height);
uLong get_img_crc(char * fpath); uLong get_img_crc(char *fpath);
static void wait_for_sfx(void); static void wait_for_sfx(void);
static void rgbtohsv(Uint8 r8, Uint8 g8, Uint8 b8, float *h, float *s, float *v); static void rgbtohsv(Uint8 r8, Uint8 g8, Uint8 b8, float *h, float *s, float *v);
@ -4424,8 +4428,12 @@ static void mainloop(void)
} }
playsound(screen, 0, SND_CLICK, 0, SNDPOS_CENTER, SNDDIST_NEAR); playsound(screen, 0, SND_CLICK, 0, SNDPOS_CENTER, SNDDIST_NEAR);
if (magics[grp][cur].sizes[magic_modeint(magics[grp][cur].mode)]) { if (magics[grp][cur].sizes[magic_modeint(magics[grp][cur].mode)])
DEBUG_PRINTF("group %d thing %d in mode %04x (%d) has %d sizes; size is %d\n", grp, cur, magics[grp][cur].mode, magic_modeint(magics[grp][cur].mode), magics[grp][cur].sizes[magic_modeint(magics[grp][cur].mode)], magics[grp][cur].size[magic_modeint(magics[grp][cur].mode)]); {
DEBUG_PRINTF("group %d thing %d in mode %04x (%d) has %d sizes; size is %d\n", grp, cur,
magics[grp][cur].mode, magic_modeint(magics[grp][cur].mode),
magics[grp][cur].sizes[magic_modeint(magics[grp][cur].mode)],
magics[grp][cur].size[magic_modeint(magics[grp][cur].mode)]);
magic_set_size(); magic_set_size();
} }
} }
@ -4962,7 +4970,7 @@ static void mainloop(void)
else if (cur_tool == TOOL_TEXT || cur_tool == TOOL_LABEL) else if (cur_tool == TOOL_TEXT || cur_tool == TOOL_LABEL)
{ {
char font_tux_text[1024]; char font_tux_text[1024];
const char * fmt_str; const char *fmt_str;
cur_font = cur_thing; cur_font = cur_thing;
@ -4973,9 +4981,8 @@ static void mainloop(void)
fmt_str = TIP_LABEL_FONTCHANGE; fmt_str = TIP_LABEL_FONTCHANGE;
safe_snprintf(font_tux_text, sizeof(font_tux_text), gettext(fmt_str), safe_snprintf(font_tux_text, sizeof(font_tux_text), gettext(fmt_str),
TTF_FontFaceFamilyName(getfonthandle(cur_font)->ttf_font), TTF_FontFaceFamilyName(getfonthandle(cur_font)->ttf_font),
TTF_FontFaceStyleName(getfonthandle(cur_font)->ttf_font), TTF_FontFaceStyleName(getfonthandle(cur_font)->ttf_font), getfonthandle(cur_font)->height);
getfonthandle(cur_font)->height);
draw_tux_text(TUX_GREAT, font_tux_text, 1); draw_tux_text(TUX_GREAT, font_tux_text, 1);
if (do_draw) if (do_draw)
@ -6461,7 +6468,7 @@ static void mainloop(void)
/* A selectable item */ /* A selectable item */
do_setcursor(cursor_hand); do_setcursor(cursor_hand);
} }
else if (which >= (buttons_tall - control_rows) * 2 - 2 /* account for scroll button */) else if (which >= (buttons_tall - control_rows) * 2 - 2 /* account for scroll button */ )
{ {
/* Controls at the bottom (below scroll-down button, if any) */ /* Controls at the bottom (below scroll-down button, if any) */
do_setcursor(cursor_hand); do_setcursor(cursor_hand);
@ -8186,37 +8193,38 @@ void show_usage(int exitcode)
* Show a list of fonts that Pango finds (and hence * Show a list of fonts that Pango finds (and hence
* should be available to "--uifont" argument) and exit. * should be available to "--uifont" argument) and exit.
*/ */
void show_fonts(void) { void show_fonts(void)
{
PangoFontMap *fontmap; PangoFontMap *fontmap;
PangoFontFamily **families; PangoFontFamily **families;
int i, n_families; int i, n_families;
char * * family_names; char **family_names;
char locale_fontdir[MAX_PATH]; char locale_fontdir[MAX_PATH];
FcBool fontAddStatus; FcBool fontAddStatus;
snprintf(locale_fontdir, sizeof(locale_fontdir), "%s/fonts", DATA_PREFIX); snprintf(locale_fontdir, sizeof(locale_fontdir), "%s/fonts", DATA_PREFIX);
fontAddStatus = FcConfigAppFontAddDir(FcConfigGetCurrent(), (const FcChar8 *) locale_fontdir); fontAddStatus = FcConfigAppFontAddDir(FcConfigGetCurrent(), (const FcChar8 *)locale_fontdir);
if (fontAddStatus == FcFalse) if (fontAddStatus == FcFalse)
{ {
fprintf(stderr, "Unable to add font dir %s\n", locale_fontdir); fprintf(stderr, "Unable to add font dir %s\n", locale_fontdir);
} }
FcDirCacheRead((const FcChar8 *) locale_fontdir, FcTrue /* force */, FcConfigGetCurrent()); FcDirCacheRead((const FcChar8 *)locale_fontdir, FcTrue /* force */ , FcConfigGetCurrent());
FcDirCacheRescan((const FcChar8 *) locale_fontdir, FcConfigGetCurrent()); FcDirCacheRescan((const FcChar8 *)locale_fontdir, FcConfigGetCurrent());
generate_fontconfig_cache_real(); generate_fontconfig_cache_real();
fontmap = pango_ft2_font_map_new(); fontmap = pango_ft2_font_map_new();
pango_font_map_list_families(fontmap, &families, &n_families); pango_font_map_list_families(fontmap, &families, &n_families);
family_names = (char * *) malloc(sizeof(char *) * n_families); family_names = (char * *)malloc(sizeof(char *) * n_families);
for (i = 0; i < n_families; i++) for (i = 0; i < n_families; i++)
{ {
family_names[i] = strdup(pango_font_family_get_name(families[i])); family_names[i] = strdup(pango_font_family_get_name(families[i]));
} }
qsort(family_names, n_families, sizeof(char*), compare_font_family); qsort(family_names, n_families, sizeof(char *), compare_font_family);
for (i = 0; i < n_families; i++) for (i = 0; i < n_families; i++)
{ {
@ -8230,7 +8238,7 @@ void show_fonts(void) {
int compare_font_family(const void *a, const void *b) int compare_font_family(const void *a, const void *b)
{ {
return strcasecmp(*(char * const*) a, *(char * const*) b); return strcasecmp(*(char *const *)a, *(char *const *)b);
} }
/** /**
@ -8322,7 +8330,8 @@ static void loadbrush_callback(SDL_Surface * screen,
/* Load brush description, if any: */ /* Load brush description, if any: */
brushes_descr[num_brushes] = loaddesc(fname, &(brushes_descr_localized[num_brushes])); brushes_descr[num_brushes] = loaddesc(fname, &(brushes_descr_localized[num_brushes]));
DEBUG_PRINTF("%s: %s (%d)\n", fname, (brushes_descr[num_brushes] != NULL ? brushes_descr[num_brushes] : "NULL"), brushes_descr_localized[num_brushes]); DEBUG_PRINTF("%s: %s (%d)\n", fname, (brushes_descr[num_brushes] != NULL ? brushes_descr[num_brushes] : "NULL"),
brushes_descr_localized[num_brushes]);
/* Load brush metadata, if any: */ /* Load brush metadata, if any: */
@ -9430,7 +9439,7 @@ static int generate_fontconfig_cache_real(void)
DEBUG_PRINTF("-- Hello from generate_fontconfig_cache() (thread # %d)\n", SDL_ThreadID()); DEBUG_PRINTF("-- Hello from generate_fontconfig_cache() (thread # %d)\n", SDL_ThreadID());
tmp_font = TuxPaint_Font_OpenFont(PANGO_DEFAULT_FONT, NULL, 12); /* always just using the default font for the purpose of getting FontConfig to generate its cache */ tmp_font = TuxPaint_Font_OpenFont(PANGO_DEFAULT_FONT, NULL, 12); /* always just using the default font for the purpose of getting FontConfig to generate its cache */
if (tmp_font != NULL) if (tmp_font != NULL)
{ {
@ -11423,7 +11432,8 @@ static void draw_erasers(void)
int rad, rad_sqr; int rad, rad_sqr;
int yy, w, sx, sy; int yy, w, sx, sy;
if (fuzzy || trans) { if (fuzzy || trans)
{
/* Fuzzy or transparent; draw dithered circle */ /* Fuzzy or transparent; draw dithered circle */
rad = sz / 2; rad = sz / 2;
rad_sqr = (rad * rad); rad_sqr = (rad * rad);
@ -11434,11 +11444,14 @@ static void draw_erasers(void)
sx = x + rad - w; sx = x + rad - w;
sy = y + rad + yy; sy = y + rad + yy;
if (fuzzy || trans) { if (fuzzy || trans)
{
int xxx; int xxx;
for (xxx = 0; xxx < w * 2; xxx++) { for (xxx = 0; xxx < w * 2; xxx++)
if ((sx + xxx) % 2 == sy % 2) { {
if ((sx + xxx) % 2 == sy % 2)
{
putpixel(screen, sx + xxx, sy, SDL_MapRGB(screen->format, 0, 0, 0)); putpixel(screen, sx + xxx, sy, SDL_MapRGB(screen->format, 0, 0, 0));
} }
} }
@ -11446,17 +11459,20 @@ static void draw_erasers(void)
} }
} }
if (fuzzy || !trans) { if (fuzzy || !trans)
{
/* Solid or fuzzy, draw solid circle */ /* Solid or fuzzy, draw solid circle */
if (fuzzy) { if (fuzzy)
{
/* Fuzzy's solid circle is within the dithered circle drawn above */ /* Fuzzy's solid circle is within the dithered circle drawn above */
sz -= 2; sz -= 2;
x++; x++;
y++; y++;
} }
if (sz > 0) { if (sz > 0)
{
rad = sz / 2; rad = sz / 2;
rad_sqr = (rad * rad); rad_sqr = (rad * rad);
@ -12203,10 +12219,9 @@ static void render_brush(void)
*/ */
static void show_brush_tip(void) static void show_brush_tip(void)
{ {
if (brushes_descr[cur_brush] != NULL ) if (brushes_descr[cur_brush] != NULL)
{ {
draw_tux_text_ex(TUX_GREAT, brushes_descr[cur_brush], draw_tux_text_ex(TUX_GREAT, brushes_descr[cur_brush], 1, brushes_descr_localized[cur_brush]);
1, brushes_descr_localized[cur_brush]);
} }
else else
@ -12401,7 +12416,7 @@ static void do_eraser(int x, int y, int update)
int xx, yy, n, hit; int xx, yy, n, hit;
int eraser_type; int eraser_type;
int undo_ctr; int undo_ctr;
SDL_Surface * last; SDL_Surface *last;
if (cur_undo > 0) if (cur_undo > 0)
undo_ctr = cur_undo - 1; undo_ctr = cur_undo - 1;
@ -12468,14 +12483,14 @@ static void do_eraser(int x, int y, int update)
} }
} }
} }
else if (eraser_type == ERASER_TYPE_CIRCLE_FUZZY || else if (eraser_type == ERASER_TYPE_CIRCLE_FUZZY || eraser_type == ERASER_TYPE_CIRCLE_TRANSPARENT)
eraser_type == ERASER_TYPE_CIRCLE_TRANSPARENT)
{ {
Uint8 r_erase, g_erase, b_erase; Uint8 r_erase, g_erase, b_erase;
Uint8 r_canvas, g_canvas, b_canvas; Uint8 r_canvas, g_canvas, b_canvas;
Uint32 (*getpixel_bkgd) (SDL_Surface *, int, int) = NULL;
Uint32 (*getpixel_canvas) (SDL_Surface *, int, int) = getpixels[canvas->format->BytesPerPixel]; Uint32(*getpixel_bkgd) (SDL_Surface *, int, int) = NULL;
void (*putpixel) (SDL_Surface *, int, int, Uint32) = putpixels[canvas->format->BytesPerPixel]; Uint32(*getpixel_canvas) (SDL_Surface *, int, int) = getpixels[canvas->format->BytesPerPixel];
void (*putpixel)(SDL_Surface *, int, int, Uint32) = putpixels[canvas->format->BytesPerPixel];
float sq, erase_pct, canvas_pct, r, g, b; float sq, erase_pct, canvas_pct, r, g, b;
/* Round fuzzy eraser & round transparent erasers: */ /* Round fuzzy eraser & round transparent erasers: */
@ -12496,29 +12511,30 @@ static void do_eraser(int x, int y, int update)
if (sq <= sz / 2) if (sq <= sz / 2)
{ {
if (img_starter_bkgd != NULL) if (img_starter_bkgd != NULL)
SDL_GetRGB(getpixel_bkgd(img_starter_bkgd, x + xx, y + yy), img_starter_bkgd->format, &r_erase, &g_erase, &b_erase); SDL_GetRGB(getpixel_bkgd(img_starter_bkgd, x + xx, y + yy), img_starter_bkgd->format, &r_erase, &g_erase,
&b_erase);
if (eraser_type == ERASER_TYPE_CIRCLE_FUZZY) if (eraser_type == ERASER_TYPE_CIRCLE_FUZZY)
{ {
/* Fuzzy */ /* Fuzzy */
SDL_GetRGB(getpixel_canvas(canvas, x + xx, y + yy), canvas->format, &r_canvas, &g_canvas, &b_canvas); SDL_GetRGB(getpixel_canvas(canvas, x + xx, y + yy), canvas->format, &r_canvas, &g_canvas, &b_canvas);
canvas_pct = (float) sq / (sz / 2); canvas_pct = (float)sq / (sz / 2);
erase_pct = 1.0 - canvas_pct; erase_pct = 1.0 - canvas_pct;
} else { }
else
{
/* Transparent */ /* Transparent */
SDL_GetRGB( SDL_GetRGB(getpixels[last->format->BytesPerPixel] (last, x + xx, y + yy),
getpixels[last->format->BytesPerPixel](last, x + xx, y + yy), last->format, &r_canvas, &g_canvas, &b_canvas);
last->format, &r_canvas, &g_canvas, &b_canvas
);
canvas_pct = 0.75; canvas_pct = 0.75;
erase_pct = 0.25; erase_pct = 0.25;
} }
r = (((float) r_erase * erase_pct) + ((float) r_canvas) * canvas_pct); r = (((float)r_erase * erase_pct) + ((float)r_canvas) * canvas_pct);
g = (((float) g_erase * erase_pct) + ((float) g_canvas) * canvas_pct); g = (((float)g_erase * erase_pct) + ((float)g_canvas) * canvas_pct);
b = (((float) b_erase * erase_pct) + ((float) b_canvas) * canvas_pct); b = (((float)b_erase * erase_pct) + ((float)b_canvas) * canvas_pct);
putpixel(canvas, x + xx, y + yy, SDL_MapRGB(canvas->format, (Uint8) r, (Uint8) g, (Uint8) b)); putpixel(canvas, x + xx, y + yy, SDL_MapRGB(canvas->format, (Uint8) r, (Uint8) g, (Uint8) b));
} }
@ -13180,11 +13196,11 @@ static void strip_quotes(char *buf)
{ {
if (buf[0] == '"') if (buf[0] == '"')
{ {
for (k = 0; k < (int) i - 2; k++) for (k = 0; k < (int)i - 2; k++)
{ {
buf[k] = buf[k+1]; buf[k] = buf[k + 1];
} }
buf[i-2] = '\0'; buf[i - 2] = '\0';
} }
} }
} }
@ -15159,8 +15175,10 @@ static void cleanup(void)
free(brushes_rotate); free(brushes_rotate);
free(brushes_spacing); free(brushes_spacing);
free(brushes_spacing_default); free(brushes_spacing_default);
for (i = 0; i < num_brushes; i++) { for (i = 0; i < num_brushes; i++)
if (brushes_descr[i] != NULL) { {
if (brushes_descr[i] != NULL)
{
free(brushes_descr[i]); free(brushes_descr[i]);
} }
} }
@ -16563,7 +16581,9 @@ static void do_png_embed_data(png_structp png_ptr)
for (x = 0; x < current_node->save_width; x++) for (x = 0; x < current_node->save_width; x++)
for (y = 0; y < current_node->save_height; y++) for (y = 0; y < current_node->save_height; y++)
{ {
pix = getpixels[current_node->label_node_surface->format->BytesPerPixel](current_node->label_node_surface, x, y); pix =
getpixels[current_node->label_node_surface->format->BytesPerPixel] (current_node->label_node_surface, x,
y);
SDL_GetRGBA(pix, current_label_node->label_node_surface->format, &r, &g, &b, &a); SDL_GetRGBA(pix, current_label_node->label_node_surface->format, &r, &g, &b, &a);
fwrite(&a, alpha_size, 1, lfi); fwrite(&a, alpha_size, 1, lfi);
} }
@ -17221,10 +17241,17 @@ static int do_open(void)
char *instructions; char *instructions;
int num_left_buttons; int num_left_buttons;
if (!disable_template_export) { if (!disable_template_export)
instructions = textdir(gettext_noop("Choose a picture and then click “Open”, “Export”, “Template“, or “Erase”. Click “Slides” to create a slideshow animation or “Back“ to return to your current picture.")); {
} else { instructions =
instructions = textdir(gettext_noop("Choose a picture and then click “Open”, “Export”, or “Erase”. Click “Slides” to create a slideshow animation or “Back“ to return to your current picture.")); textdir(gettext_noop
("Choose a picture and then click “Open”, “Export”, “Template“, or “Erase”. Click “Slides” to create a slideshow animation or “Back“ to return to your current picture."));
}
else
{
instructions =
textdir(gettext_noop
("Choose a picture and then click “Open”, “Export”, or “Erase”. Click “Slides” to create a slideshow animation or “Back“ to return to your current picture."));
} }
draw_tux_text(TUX_BORED, instructions, 1); draw_tux_text(TUX_BORED, instructions, 1);
@ -17339,7 +17366,8 @@ static int do_open(void)
SDL_BlitSurface(img_openlabels_slideshow, NULL, screen, &dest); SDL_BlitSurface(img_openlabels_slideshow, NULL, screen, &dest);
if (!disable_template_export) { if (!disable_template_export)
{
/* "Template" (make template) button: */ /* "Template" (make template) button: */
num_left_buttons = 3; num_left_buttons = 3;
@ -17358,7 +17386,9 @@ static int do_open(void)
dest.x = r_ttools.w + button_w * 2 + (button_w - img_openlabels_template->w) / 2; dest.x = r_ttools.w + button_w * 2 + (button_w - img_openlabels_template->w) / 2;
dest.y = (button_h * buttons_tall + r_ttools.h) - img_openlabels_template->h; dest.y = (button_h * buttons_tall + r_ttools.h) - img_openlabels_template->h;
SDL_BlitSurface(img_openlabels_template, NULL, screen, &dest); SDL_BlitSurface(img_openlabels_template, NULL, screen, &dest);
} else { }
else
{
num_left_buttons = 2; num_left_buttons = 2;
} }
@ -17512,11 +17542,8 @@ static int do_open(void)
done = 1; done = 1;
playsound(screen, 1, SND_CLICK, 1, SNDPOS_RIGHT, SNDDIST_NEAR); playsound(screen, 1, SND_CLICK, 1, SNDPOS_RIGHT, SNDDIST_NEAR);
} }
else if (!disable_erase && else if (!disable_erase && key == SDLK_d && (event.key.keysym.mod & KMOD_CTRL) && d_places[which] != PLACE_STARTERS_DIR && // FIXME: Meaningless?
key == SDLK_d && d_places[which] != PLACE_PERSONAL_STARTERS_DIR && !noshortcuts) // FIXME: Meaningless?
(event.key.keysym.mod & KMOD_CTRL) &&
d_places[which] != PLACE_STARTERS_DIR && // FIXME: Meaningless?
d_places[which] != PLACE_PERSONAL_STARTERS_DIR && !noshortcuts) // FIXME: Meaningless?
{ {
/* Delete! */ /* Delete! */
@ -17767,7 +17794,7 @@ static int do_open(void)
do_setcursor(cursor_down); do_setcursor(cursor_down);
} }
else if (event.button.y >= (button_h * buttons_tall + r_ttools.h) - button_h else if (event.button.y >= (button_h * buttons_tall + r_ttools.h) - button_h
&& event.button.y < (button_h * buttons_tall + r_ttools.h)) && event.button.y < (button_h * buttons_tall + r_ttools.h))
{ {
if (event.button.x >= r_ttools.w && event.button.x < r_ttools.w + (button_w * num_left_buttons)) if (event.button.x >= r_ttools.w && event.button.x < r_ttools.w + (button_w * num_left_buttons))
{ {
@ -17781,8 +17808,7 @@ static int do_open(void)
do_setcursor(cursor_hand); do_setcursor(cursor_hand);
} }
else if (event.button.x >= (WINDOW_WIDTH - r_ttoolopt.w - button_w * 2) else if (event.button.x >= (WINDOW_WIDTH - r_ttoolopt.w - button_w * 2)
&& event.button.x < (WINDOW_WIDTH - r_ttoolopt.w - button_w) && event.button.x < (WINDOW_WIDTH - r_ttoolopt.w - button_w) && !disable_erase)
&& !disable_erase)
{ {
/* Command button on the right: Erase [maybe] */ /* Command button on the right: Erase [maybe] */
do_setcursor(cursor_hand); do_setcursor(cursor_hand);
@ -21121,6 +21147,7 @@ static SDL_Surface *_load_svg(const char *file)
int width, height, stride; int width, height, stride;
float scale; float scale;
int bpp = 32, btpp = 4; int bpp = 32, btpp = 4;
#if !(LIBRSVG_MAJOR_VERSION < 2 || LIBRSVG_MINOR_VERSION < 46) #if !(LIBRSVG_MAJOR_VERSION < 2 || LIBRSVG_MINOR_VERSION < 46)
RsvgRectangle viewport; RsvgRectangle viewport;
#endif #endif
@ -21158,8 +21185,8 @@ static SDL_Surface *_load_svg(const char *file)
gdouble d_rwidth, d_rheight; gdouble d_rwidth, d_rheight;
rsvg_handle_get_intrinsic_size_in_pixels(rsvg_handle, &d_rwidth, &d_rheight); rsvg_handle_get_intrinsic_size_in_pixels(rsvg_handle, &d_rwidth, &d_rheight);
rwidth = (int) d_rwidth; rwidth = (int)d_rwidth;
rheight = (int) d_rheight; rheight = (int)d_rheight;
DEBUG_PRINTF("SVG is %f x %f (%d x %d)\n", d_rwidth, d_rheight, rwidth, rheight); DEBUG_PRINTF("SVG is %f x %f (%d x %d)\n", d_rwidth, d_rheight, rwidth, rheight);
} }
@ -21239,11 +21266,7 @@ static SDL_Surface *_load_svg(const char *file)
viewport.height = height; viewport.height = height;
/* FIXME: This returns a gboolean; not using (not 100% sure what to expect) -bjk 2023.06.18 */ /* FIXME: This returns a gboolean; not using (not 100% sure what to expect) -bjk 2023.06.18 */
rsvg_handle_render_document( rsvg_handle_render_document(rsvg_handle, cr, &viewport, &gerr);
rsvg_handle,
cr,
&viewport,
&gerr);
/* FIXME: ignoring errors (gerr) for now -bjk 2023.06.18 */ /* FIXME: ignoring errors (gerr) for now -bjk 2023.06.18 */
#endif #endif
@ -21780,7 +21803,8 @@ static void load_magic_plugins(void)
} }
else else
{ {
res = magic_funcs[num_plugin_files].init(magic_api_struct, magic_disabled_features, magic_complexity_level); res =
magic_funcs[num_plugin_files].init(magic_api_struct, magic_disabled_features, magic_complexity_level);
if (res != 0) if (res != 0)
n = magic_funcs[num_plugin_files].get_tool_count(magic_api_struct); n = magic_funcs[num_plugin_files].get_tool_count(magic_api_struct);
@ -21793,7 +21817,9 @@ static void load_magic_plugins(void)
if (n == 0) if (n == 0)
{ {
fprintf(stderr, "Notice: plugin %1$s failed to startup or reported 0 magic tools (Tux Paint is in complexity mode \"%2$s\")\n", fname, MAGIC_COMPLEXITY_LEVEL_NAMES[magic_complexity_level]); fprintf(stderr,
"Notice: plugin %1$s failed to startup or reported 0 magic tools (Tux Paint is in complexity mode \"%2$s\")\n",
fname, MAGIC_COMPLEXITY_LEVEL_NAMES[magic_complexity_level]);
fflush(stderr); fflush(stderr);
SDL_UnloadObject(magic_handle[num_plugin_files]); SDL_UnloadObject(magic_handle[num_plugin_files]);
} }
@ -21924,10 +21950,11 @@ static void load_magic_plugins(void)
num_magics[group]++; num_magics[group]++;
num_magics_total++; num_magics_total++;
if (num_magics[group] >= MAX_MAGICS_PER_GROUP) { if (num_magics[group] >= MAX_MAGICS_PER_GROUP)
{
fprintf(stderr, "Error: exceeded maximum number of Magic tools (%d) in group %d!\n", fprintf(stderr, "Error: exceeded maximum number of Magic tools (%d) in group %d!\n",
MAX_MAGICS_PER_GROUP, group); MAX_MAGICS_PER_GROUP, group);
num_magics[group]--; // FIXME: Do something better than just this! -bjk 2024.04.08 num_magics[group]--; // FIXME: Do something better than just this! -bjk 2024.04.08
} }
} }
else else
@ -21974,9 +22001,11 @@ static void load_magic_plugins(void)
/* Start out with the first magic group that _has_ any tools */ /* Start out with the first magic group that _has_ any tools */
tries = 0; tries = 0;
while (num_magics[magic_group] == 0 && tries < MAX_MAGIC_GROUPS) { while (num_magics[magic_group] == 0 && tries < MAX_MAGIC_GROUPS)
{
magic_group++; magic_group++;
if (magic_group >= MAX_MAGIC_GROUPS) { if (magic_group >= MAX_MAGIC_GROUPS)
{
magic_group = 0; magic_group = 0;
} }
} }
@ -21992,10 +22021,13 @@ static int magic_sort(const void *a, const void *b)
magic_t *am = (magic_t *) a; magic_t *am = (magic_t *) a;
magic_t *bm = (magic_t *) b; magic_t *bm = (magic_t *) b;
if (am->order != bm->order) { if (am->order != bm->order)
{
/* Different 'order's, use them */ /* Different 'order's, use them */
return (am->order - bm->order); return (am->order - bm->order);
} else { }
else
{
/* Same 'order', use the (localized) name */ /* Same 'order', use the (localized) name */
return (strcoll(gettext(am->name), gettext(bm->name))); return (strcoll(gettext(am->name), gettext(bm->name)));
} }
@ -22267,6 +22299,7 @@ static int do_new_dialog(void)
int val_x, val_y, motioner; int val_x, val_y, motioner;
int valhat_x, valhat_y, hatmotioner; int valhat_x, valhat_y, hatmotioner;
int skip; int skip;
#ifndef NOSVG #ifndef NOSVG
int k; int k;
#endif #endif
@ -24124,15 +24157,14 @@ static void do_quick_eraser(void)
/* Remember current eraser & switch to a suitable default */ /* Remember current eraser & switch to a suitable default */
old_eraser = cur_eraser; old_eraser = cur_eraser;
cur_eraser = (NUM_ERASER_SIZES * 2) - 2; /* 2nd-smallest circle */ cur_eraser = (NUM_ERASER_SIZES * 2) - 2; /* 2nd-smallest circle */
/* Snapshot the canvas, so we can undo */ /* Snapshot the canvas, so we can undo */
rec_undo_buffer(); rec_undo_buffer();
/* Do an initial erase at the click location */ /* Do an initial erase at the click location */
SDL_GetMouseState(&mx, &my); SDL_GetMouseState(&mx, &my);
eraser_draw(mx - r_canvas.x, my - r_canvas.y, eraser_draw(mx - r_canvas.x, my - r_canvas.y, mx - r_canvas.x, my - r_canvas.y);
mx - r_canvas.x, my - r_canvas.y);
done = 0; done = 0;
do do
@ -26068,12 +26100,20 @@ static void render_color_button(int the_color, SDL_Surface * icon)
linear_to_sRGB(rh * aa + ru * (1.0 - aa)), linear_to_sRGB(rh * aa + ru * (1.0 - aa)),
linear_to_sRGB(gh * aa + gu * (1.0 - aa)), linear_to_sRGB(bh * aa + bu * (1.0 - aa)))); linear_to_sRGB(gh * aa + gu * (1.0 - aa)), linear_to_sRGB(bh * aa + bu * (1.0 - aa))));
putpixels[img_color_btns[the_color + NUM_COLORS]-> putpixels[img_color_btns[the_color + NUM_COLORS]->format->BytesPerPixel] (img_color_btns[the_color + NUM_COLORS],
format->BytesPerPixel] (img_color_btns[the_color + NUM_COLORS], x, y, x, y,
SDL_MapRGB(img_color_btns[the_color + NUM_COLORS]->format, SDL_MapRGB(img_color_btns
linear_to_sRGB(rh * aa + rd * (1.0 - aa)), [the_color +
linear_to_sRGB(gh * aa + gd * (1.0 - aa)), NUM_COLORS]->format,
linear_to_sRGB(bh * aa + bd * (1.0 - aa)))); linear_to_sRGB(rh * aa +
rd * (1.0 -
aa)),
linear_to_sRGB(gh * aa +
gd * (1.0 -
aa)),
linear_to_sRGB(bh * aa +
bd * (1.0 -
aa))));
} }
} }
@ -26180,7 +26220,10 @@ static void magic_set_size()
last = undo_bufs[undo_ctr]; last = undo_bufs[undo_ctr];
DEBUG_PRINTF("set_size for mode %04x (%d) being set to %d\n", magics[magic_group][cur_magic[magic_group]].mode, magic_modeint(magics[magic_group][cur_magic[magic_group]].mode), magics[magic_group][cur_magic[magic_group]].size[magic_modeint(magics[magic_group][cur_magic[magic_group]].mode)]); DEBUG_PRINTF("set_size for mode %04x (%d) being set to %d\n", magics[magic_group][cur_magic[magic_group]].mode,
magic_modeint(magics[magic_group][cur_magic[magic_group]].mode),
magics[magic_group][cur_magic[magic_group]].size[magic_modeint
(magics[magic_group][cur_magic[magic_group]].mode)]);
magic_funcs[magics[magic_group][cur_magic[magic_group]].handle_idx].set_size(magic_api_struct, magic_funcs[magics[magic_group][cur_magic[magic_group]].handle_idx].set_size(magic_api_struct,
magics[magic_group][cur_magic magics[magic_group][cur_magic
@ -26189,10 +26232,10 @@ static void magic_set_size()
[magic_group]].mode, [magic_group]].mode,
canvas, last, canvas, last,
magics[magic_group][cur_magic magics[magic_group][cur_magic
[magic_group]]. [magic_group]].size
size[magic_modeint [magic_modeint
(magics[magic_group] (magics[magic_group]
[cur_magic[magic_group]].mode)], [cur_magic[magic_group]].mode)],
&update_rect); &update_rect);
if (update_rect.w > 0 && update_rect.h > 0) if (update_rect.w > 0 && update_rect.h > 0)
@ -27069,7 +27112,7 @@ static void set_label_fonts()
/* FIXME: 2009/09/13 TTF_FontFaceFamilyName() appends random "\n" at the end /* FIXME: 2009/09/13 TTF_FontFaceFamilyName() appends random "\n" at the end
of the returned string. Should investigate why, and when corrected, of the returned string. Should investigate why, and when corrected,
remove the code that deals whith the ending "\n"s in ttffont */ remove the code that deals whith the ending "\n"s in ttffont */
ttffont = (char *) TTF_FontFaceFamilyName(getfonthandle(i)->ttf_font); ttffont = (char *)TTF_FontFaceFamilyName(getfonthandle(i)->ttf_font);
for (c = 0; c < strlen(ttffont); c++) for (c = 0; c < strlen(ttffont); c++)
if (ttffont[c] == '\n') if (ttffont[c] == '\n')
ttffont[c] = '\0'; ttffont[c] = '\0';
@ -27350,7 +27393,7 @@ int chunk_is_valid(const char *chunk_name, png_unknown_chunk unknown)
if (unknown.data[count] == '\n') if (unknown.data[count] == '\n')
{ {
if (new_field == 1) if (new_field == 1)
return (SDL_FALSE); /* Avoid empty fields */ return (SDL_FALSE); /* Avoid empty fields */
fields++; fields++;
if (fields == 4) if (fields == 4)
{ /* Last check, see if the sizes match */ { /* Last check, see if the sizes match */
@ -27975,7 +28018,9 @@ static void parse_file_options(struct cfginfo *restrict tmpcfg, const char *file
} }
else else
{ {
fprintf(stderr, "Shell expansion of '%s' on line %d of '%s' failed! (You probably need to wrap it in quotes (\")!)\n", str, line, filename); fprintf(stderr,
"Shell expansion of '%s' on line %d of '%s' failed! (You probably need to wrap it in quotes (\")!)\n",
str, line, filename);
continue; continue;
} }
#endif #endif
@ -28304,15 +28349,15 @@ static void setup_config(char *argv[])
tp_ui_font_fallback = NULL; tp_ui_font_fallback = NULL;
char * tmp_str; char *tmp_str;
FcBool fontAddStatus; FcBool fontAddStatus;
char locale_fontdir[MAX_PATH]; char locale_fontdir[MAX_PATH];
if (tmpcfg.tp_ui_font) if (tmpcfg.tp_ui_font)
{ {
if (strcmp(tmpcfg.tp_ui_font, "default") == 0) if (strcmp(tmpcfg.tp_ui_font, "default") == 0)
{ {
printf/*DEBUG_PRINTF*/("Requested default UI font, \"%s\"\n", PANGO_DEFAULT_FONT); printf /*DEBUG_PRINTF */ ("Requested default UI font, \"%s\"\n", PANGO_DEFAULT_FONT);
tp_ui_font = strdup(PANGO_DEFAULT_FONT); tp_ui_font = strdup(PANGO_DEFAULT_FONT);
if (PANGO_DEFAULT_FONT_FALLBACK != NULL) if (PANGO_DEFAULT_FONT_FALLBACK != NULL)
{ {
@ -28322,71 +28367,75 @@ static void setup_config(char *argv[])
else else
{ {
tp_ui_font = strdup(tmpcfg.tp_ui_font); tp_ui_font = strdup(tmpcfg.tp_ui_font);
printf/*DEBUG_PRINTF*/("Requested UI font described by \"%s\"\n", tp_ui_font); printf /*DEBUG_PRINTF */ ("Requested UI font described by \"%s\"\n", tp_ui_font);
} }
} }
else{ else
printf/*DEBUG_PRINTF*/("Requested default UI font, \"%s\"\n", PANGO_DEFAULT_FONT); {
printf /*DEBUG_PRINTF */ ("Requested default UI font, \"%s\"\n", PANGO_DEFAULT_FONT);
tp_ui_font = strdup(PANGO_DEFAULT_FONT); tp_ui_font = strdup(PANGO_DEFAULT_FONT);
if (PANGO_DEFAULT_FONT_FALLBACK != NULL) if (PANGO_DEFAULT_FONT_FALLBACK != NULL)
{ {
tp_ui_font_fallback = strdup(PANGO_DEFAULT_FONT_FALLBACK); tp_ui_font_fallback = strdup(PANGO_DEFAULT_FONT_FALLBACK);
} }
} }
/* Add Tux Paint's own set of fonts to FontConfig, /* Add Tux Paint's own set of fonts to FontConfig,
so SDL2_Pango can find and use them */ so SDL2_Pango can find and use them */
snprintf(locale_fontdir, sizeof(locale_fontdir), "%s/fonts", DATA_PREFIX); snprintf(locale_fontdir, sizeof(locale_fontdir), "%s/fonts", DATA_PREFIX);
fontAddStatus = FcConfigAppFontAddDir(FcConfigGetCurrent(), (const FcChar8 *) locale_fontdir); fontAddStatus = FcConfigAppFontAddDir(FcConfigGetCurrent(), (const FcChar8 *)locale_fontdir);
if (fontAddStatus == FcFalse) if (fontAddStatus == FcFalse)
{ {
fprintf(stderr, "Unable to add font dir %s\n", locale_fontdir); fprintf(stderr, "Unable to add font dir %s\n", locale_fontdir);
} }
/* FIXME: Unclear whether this is necessary? -bjk 2023.06.12 */ /* FIXME: Unclear whether this is necessary? -bjk 2023.06.12 */
DEBUG_PRINTF("Rescanning fonts..."); fflush(stdout); DEBUG_PRINTF("Rescanning fonts...");
FcDirCacheRead((const FcChar8 *) locale_fontdir, FcTrue /* force */, FcConfigGetCurrent()); fflush(stdout);
FcDirCacheRescan((const FcChar8 *) locale_fontdir, FcConfigGetCurrent()); FcDirCacheRead((const FcChar8 *)locale_fontdir, FcTrue /* force */ , FcConfigGetCurrent());
DEBUG_PRINTF("done\n"); FcDirCacheRescan((const FcChar8 *)locale_fontdir, FcConfigGetCurrent());
DEBUG_PRINTF("done\n");
#ifdef DEBUG #ifdef DEBUG
{
FcStrList *str_list;
FcChar8 *path;
str_list = FcConfigGetFontDirs(FcConfigGetCurrent());
printf("FcConfigGetFontDirs():\n");
while ((path = FcStrListNext(str_list)) != NULL)
{ {
FcStrList *str_list; printf(" * %s\n", (const char *)path);
FcChar8 *path;
str_list = FcConfigGetFontDirs(FcConfigGetCurrent());
printf("FcConfigGetFontDirs():\n");
while ((path = FcStrListNext(str_list)) != NULL) {
printf(" * %s\n", (const char *) path);
}
printf("\n");
} }
printf("\n");
}
#endif #endif
tmp_str = ask_pango_for_font(tp_ui_font); tmp_str = ask_pango_for_font(tp_ui_font);
if (tmp_str != NULL) if (tmp_str != NULL)
{
if (strcmp(tp_ui_font, tmp_str) != 0 && tp_ui_font_fallback != NULL)
{ {
if (strcmp(tp_ui_font, tmp_str) != 0 && tp_ui_font_fallback != NULL) free(tp_ui_font);
{ tp_ui_font = strdup(tp_ui_font_fallback);
free(tp_ui_font); tp_ui_font_fallback = NULL;
tp_ui_font = strdup(tp_ui_font_fallback);
tp_ui_font_fallback = NULL;
printf/*DEBUG_PRINTF*/("Requested fallback default UI font, \"%s\"\n", tp_ui_font); printf /*DEBUG_PRINTF */ ("Requested fallback default UI font, \"%s\"\n", tp_ui_font);
tmp_str = ask_pango_for_font(tp_ui_font); tmp_str = ask_pango_for_font(tp_ui_font);
}
} }
}
if (tmp_str != NULL) if (tmp_str != NULL)
{ {
printf("Actual UI font will be \"%s\"\n", tmp_str); printf("Actual UI font will be \"%s\"\n", tmp_str);
free(tmp_str); free(tmp_str);
} }
else else
{ {
printf("Error asking pango for actual font!\n"); printf("Error asking pango for actual font!\n");
} }
/* FIXME: most of this is not required before starting the font scanner */ /* FIXME: most of this is not required before starting the font scanner */
@ -28482,8 +28531,9 @@ static void setup_config(char *argv[])
fprintf(stderr, "Button size (now %s) must be between 24 and 192.\n", tmpcfg.button_size); fprintf(stderr, "Button size (now %s) must be between 24 and 192.\n", tmpcfg.button_size);
exit(1); exit(1);
} }
button_scale = (float) strtof(tmpcfg.button_size, NULL) / (float) ORIGINAL_BUTTON_SIZE; button_scale = (float)strtof(tmpcfg.button_size, NULL) / (float)ORIGINAL_BUTTON_SIZE;
DEBUG_PRINTF("Button size %s requested = %d (scale = %f)\n", tmpcfg.button_size, (int)(button_scale * ORIGINAL_BUTTON_SIZE), button_scale); DEBUG_PRINTF("Button size %s requested = %d (scale = %f)\n", tmpcfg.button_size,
(int)(button_scale * ORIGINAL_BUTTON_SIZE), button_scale);
} }
} }
else else
@ -28517,13 +28567,20 @@ static void setup_config(char *argv[])
{ {
/* FIXME: Could maybe iterate the array of MAGIC_COMPLEXITY_LEVEL_NAMES[], /* FIXME: Could maybe iterate the array of MAGIC_COMPLEXITY_LEVEL_NAMES[],
but just hard-coding for now -bjk 2023.12.29 */ but just hard-coding for now -bjk 2023.12.29 */
if (!strcmp(tmpcfg.complexity, "novice")) { if (!strcmp(tmpcfg.complexity, "novice"))
{
magic_complexity_level = MAGIC_COMPLEXITY_NOVICE; magic_complexity_level = MAGIC_COMPLEXITY_NOVICE;
} else if (!strcmp(tmpcfg.complexity, "beginner")) { }
else if (!strcmp(tmpcfg.complexity, "beginner"))
{
magic_complexity_level = MAGIC_COMPLEXITY_BEGINNER; magic_complexity_level = MAGIC_COMPLEXITY_BEGINNER;
} else if (!strcmp(tmpcfg.complexity, "advanced")) { }
else if (!strcmp(tmpcfg.complexity, "advanced"))
{
magic_complexity_level = MAGIC_COMPLEXITY_ADVANCED; magic_complexity_level = MAGIC_COMPLEXITY_ADVANCED;
} else { }
else
{
fprintf(stderr, "Ignoring unknown 'complexity' value \"%s\"\n", tmpcfg.complexity); fprintf(stderr, "Ignoring unknown 'complexity' value \"%s\"\n", tmpcfg.complexity);
} }
} }
@ -29259,6 +29316,7 @@ static void setup(void)
Uint32 init_flags; Uint32 init_flags;
char tmp_str[128]; char tmp_str[128];
SDL_Surface *img1; SDL_Surface *img1;
Uint32(*getpixel_tmp_btn_up) (SDL_Surface *, int, int); Uint32(*getpixel_tmp_btn_up) (SDL_Surface *, int, int);
Uint32(*getpixel_tmp_btn_down) (SDL_Surface *, int, int); Uint32(*getpixel_tmp_btn_down) (SDL_Surface *, int, int);
Uint32(*getpixel_img_paintwell) (SDL_Surface *, int, int); Uint32(*getpixel_img_paintwell) (SDL_Surface *, int, int);
@ -29506,8 +29564,7 @@ static void setup(void)
printf("window_screen = NULL 1\n"); printf("window_screen = NULL 1\n");
#else #else
window_screen = SDL_CreateWindow(NULL, win_x, win_y, window_screen = SDL_CreateWindow(NULL, win_x, win_y, WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_FULLSCREEN_DESKTOP);
WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_FULLSCREEN_DESKTOP);
if (window_screen == NULL) if (window_screen == NULL)
printf("window_screen = NULL 2\n"); printf("window_screen = NULL 2\n");
#endif #endif
@ -29836,8 +29893,7 @@ static void setup(void)
#endif #endif
medium_font = TuxPaint_Font_OpenFont(tp_ui_font, medium_font = TuxPaint_Font_OpenFont(tp_ui_font, DATA_PREFIX "fonts/default_font.ttf", /* FIXME: Does this matter any more? -bjk 2023.05.29 */
DATA_PREFIX "fonts/default_font.ttf", /* FIXME: Does this matter any more? -bjk 2023.05.29 */
(18 - (only_uppercase * 3)) * button_scale); (18 - (only_uppercase * 3)) * button_scale);
if (medium_font == NULL) if (medium_font == NULL)
@ -30176,8 +30232,7 @@ static void setup(void)
/* Load system fonts: */ /* Load system fonts: */
large_font = TuxPaint_Font_OpenFont(tp_ui_font, large_font = TuxPaint_Font_OpenFont(tp_ui_font, DATA_PREFIX "fonts/default_font.ttf", /* FIXME: Does this matter any more? -bjk 2023.05.29 */
DATA_PREFIX "fonts/default_font.ttf", /* FIXME: Does this matter any more? -bjk 2023.05.29 */
(30 - (only_uppercase * 3)) * button_scale); (30 - (only_uppercase * 3)) * button_scale);
if (large_font == NULL) if (large_font == NULL)
@ -30192,8 +30247,7 @@ static void setup(void)
} }
small_font = TuxPaint_Font_OpenFont(tp_ui_font, small_font = TuxPaint_Font_OpenFont(tp_ui_font, DATA_PREFIX "fonts/default_font.ttf", /* FIXME: Does this matter any more? -bjk 2023.05.29 */
DATA_PREFIX "fonts/default_font.ttf", /* FIXME: Does this matter any more? -bjk 2023.05.29 */
#ifdef __APPLE__ #ifdef __APPLE__
(12 - (only_uppercase * 2)) * button_scale (12 - (only_uppercase * 2)) * button_scale
#else #else
@ -30221,7 +30275,7 @@ static void setup(void)
/* Load magic tool plugins: */ /* Load magic tool plugins: */
magic_disabled_features = 0b00000000; magic_disabled_features = 0x00; // 0b00000000
if (disable_magic_sizes) if (disable_magic_sizes)
{ {
magic_disabled_features |= MAGIC_FEATURE_SIZE; magic_disabled_features |= MAGIC_FEATURE_SIZE;
@ -30388,8 +30442,7 @@ static void setup(void)
gd * (1.0 - gd * (1.0 -
aa)), aa)),
linear_to_sRGB(bh * aa + linear_to_sRGB(bh * aa +
bd * (1.0 - bd * (1.0 - aa))));
aa))));
} }
} }
} }
@ -30656,7 +30709,7 @@ int main(int argc, char *argv[])
/* EP added block to log messages */ /* EP added block to log messages */
freopen("/tmp/tuxpaint.log", "w", stdout); /* redirect stdout to a file */ freopen("/tmp/tuxpaint.log", "w", stdout); /* redirect stdout to a file */
#elif defined (__ANDROID__) #elif defined (__ANDROID__)
freopen("/storage/emulated/0/Android/data/org.tuxpaint/files/tuxpaint.log", "w", stdout); /* redirect stdout to a file */ freopen("/storage/emulated/0/Android/data/org.tuxpaint/files/tuxpaint.log", "w", stdout); /* redirect stdout to a file */
#endif #endif
dup2(fileno(stdout), fileno(stderr)); /* redirect stderr to stdout */ dup2(fileno(stdout), fileno(stderr)); /* redirect stderr to stdout */
@ -31798,7 +31851,7 @@ int export_gif_monitor_events(void)
* + unused by EXPORT_LOC_PICTURES (just send NULL) * + unused by EXPORT_LOC_PICTURES (just send NULL)
* @return EXPORT_SUCCESS on success, or one of the EXPORT_ERR_... values on failure * @return EXPORT_SUCCESS on success, or one of the EXPORT_ERR_... values on failure
*/ */
static int export_pict(char *fname, int where, char * orig_fname) static int export_pict(char *fname, int where, char *orig_fname)
{ {
FILE *fi, *fo; FILE *fi, *fo;
size_t len; size_t len;
@ -31823,9 +31876,9 @@ static int export_pict(char *fname, int where, char * orig_fname)
{ {
pict_fname = get_export_filepath("png"); pict_fname = get_export_filepath("png");
} }
else /* where == EXPORT_LOC_TEMPLATES */ else /* where == EXPORT_LOC_TEMPLATES */
{ {
char * dir; char *dir;
pict_fname = NULL; pict_fname = NULL;
@ -31930,12 +31983,15 @@ static int export_pict(char *fname, int where, char * orig_fname)
} }
else else
{ {
DEBUG_PRINTF(" ...but appear to have the different content (template crc = %ld, saved file's is now %ld)\n", templ_crc, orig_crc); DEBUG_PRINTF
(" ...but appear to have the different content (template crc = %ld, saved file's is now %ld)\n",
templ_crc, orig_crc);
} }
} }
else else
{ {
DEBUG_PRINTF(" ...but dimensions differ (template = %d x %d, saved file is now %d x %d)\n", templ_w, templ_h, orig_w, orig_h); DEBUG_PRINTF(" ...but dimensions differ (template = %d x %d, saved file is now %d x %d)\n",
templ_w, templ_h, orig_w, orig_h);
} }
} }
else else
@ -31967,7 +32023,7 @@ static int export_pict(char *fname, int where, char * orig_fname)
/* Create a unique filename, within that dir */ /* Create a unique filename, within that dir */
t = time(NULL); t = time(NULL);
strftime(timestamp, sizeof(timestamp), "%Y%m%d%H%M%S", localtime(&t)); strftime(timestamp, sizeof(timestamp), "%Y%m%d%H%M%S", localtime(&t));
pict_fname = (char *) malloc(sizeof(char) * len); pict_fname = (char *)malloc(sizeof(char) * len);
snprintf(pict_fname, len, "%s/%s-%s-%s.png", dir, EXPORTED_TEMPLATE_PREFIX, orig_fname, timestamp); snprintf(pict_fname, len, "%s/%s-%s-%s.png", dir, EXPORTED_TEMPLATE_PREFIX, orig_fname, timestamp);
} }
@ -32025,9 +32081,9 @@ static int export_pict(char *fname, int where, char * orig_fname)
* @param int * w -- pointer to an int where we'll fill in the width * @param int * w -- pointer to an int where we'll fill in the width
* @param int * h -- pointer to an int where we'll fill in the height * @param int * h -- pointer to an int where we'll fill in the height
*/ */
void get_img_dimensions(char * fpath, int * w, int * h) void get_img_dimensions(char *fpath, int *w, int *h)
{ {
FILE * fi; FILE *fi;
png_structp png; png_structp png;
png_infop info; png_infop info;
@ -32068,10 +32124,10 @@ void get_img_dimensions(char * fpath, int * w, int * h)
png_destroy_read_struct(&png, &info, NULL); png_destroy_read_struct(&png, &info, NULL);
} }
uLong get_img_crc(char * fpath) uLong get_img_crc(char *fpath)
{ {
uLong crc; uLong crc;
FILE * fi; FILE *fi;
size_t len; size_t len;
unsigned char buf[1024]; unsigned char buf[1024];
@ -32483,4 +32539,3 @@ void maybe_redraw_eraser_xor(void)
} }
} }
} }

View file

@ -13,39 +13,61 @@ void win32_print_version(void)
Version = GetVersion(); Version = GetVersion();
if (Version < 0x80000000) if (Version < 0x80000000)
Build = (DWORD)(HIWORD(Version)); Build = (DWORD) (HIWORD(Version));
if (IsWindows10OrGreater()) { if (IsWindows10OrGreater())
if (Build < 22000){ {
if (Build < 22000)
{
verStr = strdup("Windows 10"); verStr = strdup("Windows 10");
}else{ }
else
{
verStr = strdup("Windows 11"); verStr = strdup("Windows 11");
} }
}else if (IsWindows8Point1OrGreater()){ }
else if (IsWindows8Point1OrGreater())
{
verStr = strdup("Windows 8.1"); verStr = strdup("Windows 8.1");
}else if (IsWindows8OrGreater()){ }
else if (IsWindows8OrGreater())
{
verStr = strdup("Windows 8"); verStr = strdup("Windows 8");
}else if (IsWindows7SP1OrGreater()){ }
else if (IsWindows7SP1OrGreater())
{
verStr = strdup("Windows 7 Service Pack 1"); verStr = strdup("Windows 7 Service Pack 1");
}else if (IsWindows7OrGreater()){ }
else if (IsWindows7OrGreater())
{
verStr = strdup("Windows 7"); verStr = strdup("Windows 7");
}else if (IsWindowsVistaSP2OrGreater()){ }
else if (IsWindowsVistaSP2OrGreater())
{
verStr = strdup("Windows Vista Service Pack 2"); verStr = strdup("Windows Vista Service Pack 2");
}else if (IsWindowsVistaSP1OrGreater()){ }
else if (IsWindowsVistaSP1OrGreater())
{
verStr = strdup("Windows Vista Service Pack 1"); verStr = strdup("Windows Vista Service Pack 1");
}else if (IsWindowsVistaOrGreater()){ }
else if (IsWindowsVistaOrGreater())
{
verStr = strdup("Windows Vista"); verStr = strdup("Windows Vista");
}else{ }
else
{
verStr = strdup("unknown"); verStr = strdup("unknown");
} }
printf ("Microsoft %s", verStr); printf("Microsoft %s", verStr);
if (IsWindowsServer()){ if (IsWindowsServer())
{
printf(" Server"); printf(" Server");
} }
if (Version < 0x80000000){ if (Version < 0x80000000)
{
printf(" (Build %d)\n", Build); printf(" (Build %d)\n", Build);
} }
} }