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 "SDL2_gfxPrimitives.h"
enum {
enum
{
TOOL_WARP,
NUM_TOOLS
};
char * warp_icons[NUM_TOOLS] = {
char *warp_icons[NUM_TOOLS] = {
"rainbow.png", // FIXME
};
char * warp_snd_fnames[NUM_TOOLS] = {
char *warp_snd_fnames[NUM_TOOLS] = {
"rainbow.ogg", // FIXME
};
char * warp_tool_names[NUM_TOOLS] = {
char *warp_tool_names[NUM_TOOLS] = {
gettext_noop("Warp"),
};
@ -54,7 +55,8 @@ char * warp_tool_names[NUM_TOOLS] = {
#define MAX_WARP_RADIUS 64
#define WARP_MESH_RES 16
typedef struct warp_mesh_s {
typedef struct warp_mesh_s
{
int scr_x;
int scr_y;
float pt_x;
@ -66,9 +68,9 @@ typedef struct warp_mesh_s {
static int warp_radius;
int warp_mesh_w, warp_mesh_h;
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);
Uint32 warp_api_version(void);
@ -113,7 +115,8 @@ int warp_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
int i;
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]);
warp_snd[i] = Mix_LoadWAV(fname);
}
@ -168,15 +171,17 @@ void warp_drag(magic_api * api, int which, SDL_Surface * canvas,
return;
stroke_len = sqrt((ox - x) * (ox - x) + (oy - y) * (oy - y));
warp_dx = (float) (x - ox) / stroke_len;
warp_dy = (float) (y - oy) / stroke_len;
warp_dx = (float)(x - ox) / stroke_len;
warp_dy = (float)(y - oy) / stroke_len;
api->line(api, which, canvas, last, ox, oy, x, y, 1, warp_linecb);
SDL_BlitSurface(last, NULL, canvas, NULL);
for (yy = 0; yy < warp_mesh_h - 1; yy++) {
for (xx = 0; xx < warp_mesh_w - 1; xx++) {
for (yy = 0; yy < warp_mesh_h - 1; yy++)
{
for (xx = 0; xx < warp_mesh_w - 1; xx++)
{
/* FIXME: Just crib perspective_preview() from perspective.c? */
/*
Sint16 pts_x[4];
@ -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);
}
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;
magic_api *api = (magic_api *) ptr;
int mx, my;
float dx, dy;
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)) {
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;
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))
{
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_y += (warp_dy * intensity);
@ -270,7 +279,8 @@ void warp_shutdown(magic_api * api ATTRIBUTE_UNUSED)
{
int i;
for (i = 0; i < NUM_TOOLS; i++) {
for (i = 0; i < NUM_TOOLS; i++)
{
if (warp_snd[i] != NULL)
Mix_FreeChunk(warp_snd[i]);
}
@ -295,23 +305,28 @@ void warp_switchin(magic_api * api ATTRIBUTE_UNUSED,
warp_mesh_w = (canvas->w / WARP_MESH_RES);
warp_mesh_h = (canvas->h / WARP_MESH_RES);
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);
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);
if (warp_mesh == NULL) {
if (warp_mesh == NULL)
{
fprintf(stderr, "warp cannot allocate warp_mesh!\n");
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);
if (warp_mesh[y] == NULL) {
if (warp_mesh[y] == NULL)
{
fprintf(stderr, "warp cannot allocate warp_mesh!\n");
return;
}
}
for (y = 0; y < warp_mesh_h; y++) {
for (x = 0; x < warp_mesh_w; x++) {
for (y = 0; y < warp_mesh_h; y++)
{
for (x = 0; x < warp_mesh_w; x++)
{
warp_mesh[y][x].scr_x = x * WARP_MESH_RES;
warp_mesh[y][x].scr_y = y * WARP_MESH_RES;
warp_mesh[y][x].pt_x = x * WARP_MESH_RES;
@ -328,10 +343,14 @@ void warp_switchout(magic_api * api ATTRIBUTE_UNUSED,
/* FIXME: Crashes! */
return;
if (warp_mesh != NULL) {
for (y = 0; y < warp_mesh_h; y++) {
if (warp_mesh[y] != NULL) {
printf("freeing mesh row %d\n", y); fflush(stdout);
if (warp_mesh != NULL)
{
for (y = 0; y < warp_mesh_h; y++)
{
if (warp_mesh[y] != NULL)
{
printf("freeing mesh row %d\n", y);
fflush(stdout);
free(warp_mesh);
warp_mesh[y] = NULL;
}

View file

@ -152,7 +152,8 @@ int blocks_etc_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_U
// Return our order
int blocks_etc_get_order(int which)
{
switch (which) {
switch (which)
{
case TOOL_BLOCKS:
return 4;
break;

View file

@ -86,7 +86,8 @@ void checkerboard_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUT
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];

View file

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

View file

@ -62,7 +62,8 @@ int colorsep_complexity;
/* 3D Glasses mode (except in Novice complexity setting)
offers different variations
(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_BLUE,
// COLORSEP_3DGLASS_VARIATION_ANACHROME, // dark red / dark blue
@ -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)
{
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);
} else {
}
else
{
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;
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) */
/* RR GG BB */
/* 1 2 2 */
@ -265,7 +270,9 @@ void colorsep_apply(magic_api * api, int which, SDL_Surface * canvas,
// cyan
g = g2;
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 */
/* RR GG BB */
/* 1 12 2 */
@ -286,7 +293,9 @@ void colorsep_apply(magic_api * api, int which, SDL_Surface * canvas,
// r = r1 / 2;
// g = (g1 + g2 + r1 + b2) / 4;
// 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 */
/* RR GG BB */
/* 1 2 12 */
@ -299,7 +308,9 @@ void colorsep_apply(magic_api * api, int which, SDL_Surface * canvas,
// blue shared
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 */
/* RR GG BB */
/* 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)
{
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)
uses (abuses) the size option to change styles */
return NUM_COLORSEP_3DGLASS_VARIATIONS;
} else {
}
else
{
/* All other tools (and 3D Glasses in novice complexity)
do not use the size option */
return 0;

View file

@ -20,7 +20,8 @@
#include "SDL_image.h"
#include "SDL_mixer.h"
enum {
enum
{
/* Use the chosen color for the non-white pixels */
TOOL_DITHER_VIA_COLOR,
/* Use the image's color (hue/saturation w/ low value) for the non-white pixels */
@ -28,28 +29,30 @@ enum {
NUM_TOOLS
};
char * dither_names[NUM_TOOLS] = {
char *dither_names[NUM_TOOLS] = {
gettext_noop("Dither"),
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 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("Click to replace your entire image with a dithered pattern of dots using the picture's original colors."),
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
("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_keep_color.png",
};
char * dither_snd_filenames[NUM_TOOLS] = {
char *dither_snd_filenames[NUM_TOOLS] = {
"dither.ogg",
"dither_keep_color.ogg",
};
@ -63,17 +66,15 @@ Mix_Chunk *snd_effects[NUM_TOOLS];
Uint8 dither_sizes[NUM_TOOLS];
Uint32 dither_white, dither_black, dither_color;
Uint8 * dither_touched;
float * dither_vals;
Uint8 *dither_touched;
float *dither_vals;
int dither_click_mode;
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_Rect * update_rect);
SDL_Surface * snapshot, int old_x, int old_y, int x, int y, SDL_Rect * update_rect);
void dither_line_callback(void *pointer, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y);
void dither_line_callback(void *pointer, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
Uint32 dither_api_version(void);
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_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
void dither_set_size(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * snapshot,
Uint8 size, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * snapshot, Uint8 size, SDL_Rect * update_rect);
void dither_set_color(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot,
Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * snapshot, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
void dither_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
void dither_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
void dither_shutdown(magic_api * api);
Uint8 dither_default_size(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;
char filename[1024];
for (i = 0; i < NUM_TOOLS; i++) {
snprintf(filename, sizeof(filename), "%ssounds/magic/%s", api->data_directory,
dither_snd_filenames[i]);
for (i = 0; i < NUM_TOOLS; i++)
{
snprintf(filename, sizeof(filename), "%ssounds/magic/%s", api->data_directory, dither_snd_filenames[i]);
snd_effects[i] = Mix_LoadWAV(filename);
}
@ -138,8 +135,7 @@ SDL_Surface *dither_get_icon(magic_api * api, int which)
{
char filename[1024];
snprintf(filename, sizeof(filename), "%simages/magic/%s",
api->data_directory, dither_icon_filenames[which]);
snprintf(filename, sizeof(filename), "%simages/magic/%s", api->data_directory, dither_icon_filenames[which]);
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)
{
if (mode == MODE_PAINT) {
if (mode == MODE_PAINT)
{
return strdup(gettext(dither_descr[which][0]));
} else /* if (mode == MODE_FULLSCREEN) */ {
}
else /* if (mode == MODE_FULLSCREEN) */
{
return strdup(gettext(dither_descr[which][1]));
}
}
@ -225,8 +224,7 @@ void dither_shutdown(magic_api * api ATTRIBUTE_UNUSED)
void
dither_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
{
int xx, yy;
Uint8 r, g, b;
@ -246,7 +244,8 @@ dither_click(magic_api * api, int which, int mode,
dither_touched[yy * canvas->w + xx] = 1;
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)
{
@ -270,18 +269,14 @@ dither_click(magic_api * api, int which, int mode,
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_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * snapshot, int old_x, int old_y, int x, int y, SDL_Rect * update_rect)
{
int dither_size;
SDL_LockSurface(snapshot);
SDL_LockSurface(canvas);
api->line((void *) api, which, canvas, snapshot,
old_x, old_y, x, y, 1,
dither_line_callback);
api->line((void *)api, which, canvas, snapshot, old_x, old_y, x, y, 1, dither_line_callback);
SDL_UnlockSurface(canvas);
SDL_UnlockSurface(snapshot);
@ -320,8 +315,7 @@ int dither_x_pos[6] = { 1, 2, -1, 0, 1, 0 };
int dither_y_pos[6] = { 0, 0, 1, 1, 1, 2 };
void dither_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
{
Uint8 r, g, b;
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])
{
val = dither_vals[y * canvas->w + x];
if (val >= 0.5) {
if (val >= 0.5)
{
api->putpixel(canvas, x, y, dither_white);
err = val - 1.0;
}
@ -383,7 +378,8 @@ void dither_release(magic_api * api, int which,
update_rect->w = canvas->w;
update_rect->h = canvas->h;
if (dither_click_mode == MODE_PAINT) {
if (dither_click_mode == MODE_PAINT)
{
api->stopsound();
}
}
@ -411,8 +407,7 @@ void dither_set_size(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRI
}
void dither_line_callback(void *pointer, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y)
void dither_line_callback(void *pointer, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y)
{
magic_api *api = (magic_api *) pointer;
int xx, yy, dither_size;
@ -459,7 +454,7 @@ void dither_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSE
}
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);

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)
{
fprintf(stderr, "Cannot scale %s\n", fname);
return(0);
return (0);
}
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_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]);
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]);
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]);
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]);
return(0);
return (0);
}
img_w = fretwork_one->w;

View file

@ -78,7 +78,8 @@ static int **glasstile_hit;
static int glasstile_hit_xsize;
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];

View file

@ -171,7 +171,8 @@ Uint32 mosaic_shaped_api_version(void)
}
//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;
char fname[1024];

File diff suppressed because it is too large Load diff

View file

@ -19,24 +19,26 @@
#include "SDL_image.h"
#include "SDL_mixer.h"
enum {
enum
{
TOOL_POLYFILL,
NUM_TOOLS
};
char * polyfill_names[NUM_TOOLS] = {
char *polyfill_names[NUM_TOOLS] = {
gettext_noop("Filled Polygon"),
};
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."),
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."),
};
char * polyfill_icon_filenames[NUM_TOOLS] = {
char *polyfill_icon_filenames[NUM_TOOLS] = {
"polyfill.png",
};
char * polyfill_snd_filenames[NUM_TOOLS] = {
char *polyfill_snd_filenames[NUM_TOOLS] = {
"dither.ogg", // FIXME
};
@ -44,7 +46,7 @@ char * polyfill_snd_filenames[NUM_TOOLS] = {
#define MAX_PTS 17
SDL_Surface * polyfill_snapshot = NULL;
SDL_Surface *polyfill_snapshot = NULL;
int polyfill_pt_x[MAX_PTS];
int polyfill_pt_y[MAX_PTS];
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,
SDL_Surface * snapshot, int old_x, int old_y, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * snapshot, int old_x, int old_y, int x, int y, SDL_Rect * update_rect);
void polyfill_line_callback(void *pointer, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y);
void polyfill_line_callback(void *pointer, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
void polyfill_draw_preview(magic_api * api, SDL_Surface * canvas, int show_handles);
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;
char filename[1024];
for (i = 0; i < NUM_TOOLS; i++) {
snprintf(filename, sizeof(filename), "%ssounds/magic/%s", api->data_directory,
polyfill_snd_filenames[i]);
for (i = 0; i < NUM_TOOLS; i++)
{
snprintf(filename, sizeof(filename), "%ssounds/magic/%s", api->data_directory, polyfill_snd_filenames[i]);
snd_effects[i] = Mix_LoadWAV(filename);
}
@ -97,8 +97,7 @@ SDL_Surface *polyfill_get_icon(magic_api * api, int which)
{
char filename[1024];
snprintf(filename, sizeof(filename), "%simages/magic/%s",
api->data_directory, polyfill_icon_filenames[which]);
snprintf(filename, sizeof(filename), "%simages/magic/%s", api->data_directory, polyfill_icon_filenames[which]);
return (IMG_Load(filename));
}
@ -164,7 +163,8 @@ void polyfill_shutdown(magic_api * api)
}
}
if (polyfill_snapshot != NULL) {
if (polyfill_snapshot != NULL)
{
SDL_FreeSurface(polyfill_snapshot);
polyfill_snapshot = NULL;
}
@ -172,8 +172,7 @@ void polyfill_shutdown(magic_api * api)
void
polyfill_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
{
int 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? */
polyfill_editing = MAX_PTS;
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) {
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)
{
polyfill_editing = i;
}
}
if (polyfill_editing != MAX_PTS) {
if (polyfill_editing != MAX_PTS)
{
printf("Clicked %d to edit it\n", polyfill_editing);
polyfill_draw_preview(api, canvas, 1);
return;
}
/* 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);
polyfill_pt_x[polyfill_num_pts] = x;
@ -207,7 +209,9 @@ polyfill_click(magic_api * api, int which, int mode,
/* Add the new point */
polyfill_drag(api, which, canvas, snapshot, x, y, x, y, update_rect);
} else {
}
else
{
/* Out of points! */
printf("Out of space for new points!\n");
}
@ -216,9 +220,7 @@ polyfill_click(magic_api * api, int which, int mode,
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_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * snapshot, int old_x, int old_y, int x, int y, SDL_Rect * update_rect)
{
polyfill_dragged = 1;
@ -236,7 +238,8 @@ polyfill_drag(magic_api * api, int which,
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;
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);
for (i = 0; i < polyfill_num_pts - 1; i++) {
api->line((void *) api, 0 /* which */, canvas, NULL /* snapshot */,
for (i = 0; i < polyfill_num_pts - 1; i++)
{
api->line((void *)api, 0 /* which */ , canvas, NULL /* snapshot */ ,
polyfill_pt_x[i], polyfill_pt_y[i],
polyfill_pt_x[i + 1], polyfill_pt_y[i + 1],
1,
polyfill_line_callback);
polyfill_pt_x[i + 1], polyfill_pt_y[i + 1], 1, polyfill_line_callback);
}
if (show_handles) {
for (i = 1; i < polyfill_num_pts - 1; i++) {
for (yy = -4; yy <= 4; yy++) {
for (xx = -4; xx <= 4; xx++) {
if (show_handles)
{
for (i = 1; i < polyfill_num_pts - 1; i++)
{
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);
}
}
}
if (polyfill_num_pts > 0) {
if (polyfill_num_pts > 0)
{
dest.x = polyfill_pt_x[0] - SNAP_SIZE;
dest.y = polyfill_pt_y[0] - SNAP_SIZE;
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);
}
if (polyfill_num_pts > 1) {
if (polyfill_num_pts > 1)
{
dest.x = polyfill_pt_x[polyfill_num_pts - 1] - SNAP_SIZE;
dest.y = polyfill_pt_y[polyfill_num_pts - 1] - SNAP_SIZE;
dest.w = SNAP_SIZE * 2;
@ -284,8 +292,7 @@ void polyfill_draw_preview(magic_api * api, SDL_Surface * canvas, int show_handl
void
polyfill_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
{
int i;
@ -300,7 +307,8 @@ polyfill_release(magic_api * api, int which,
/* If they simply clicked the first point (without
drawing to move it), and there are enough points, consider
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");
polyfill_pt_x[polyfill_num_pts] = polyfill_pt_x[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? */
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(y - polyfill_pt_y[0]) <= SNAP_SIZE) ||
(polyfill_editing == 0 &&
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");
/* Snap the points */
if (polyfill_editing == 0) {
if (polyfill_editing == 0)
{
polyfill_pt_x[0] = polyfill_pt_x[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_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 */
SDL_BlitSurface(canvas, NULL, polyfill_snapshot, NULL);
} else {
}
else
{
/* Did not move (or place) the final spot at the beginning */
/* 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;
for (i = polyfill_editing - 1; i < polyfill_editing + 1; i++) {
if (i >= 0 && i < polyfill_num_pts - 1) {
for (i = polyfill_editing - 1; i < polyfill_editing + 1; i++)
{
if (i >= 0 && i < polyfill_num_pts - 1)
{
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);
to_merge = i;
}
}
}
if (to_merge != MAX_PTS) {
if (to_merge != MAX_PTS)
{
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_y[i] = polyfill_pt_y[i + 1];
}
@ -373,22 +390,24 @@ polyfill_release(magic_api * api, int which,
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);
if (polyfill_active) {
if (polyfill_active)
{
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,
SDL_Surface * snapshot, int x, int y)
void polyfill_line_callback(void *pointer, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y)
{
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,
SDL_Surface * canvas)
void polyfill_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
polyfill_color_red = SDL_MapRGB(canvas->format, 255, 0, 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,
canvas->format->BitsPerPixel, canvas->format->Rmask,
canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
}
if (polyfill_snapshot != NULL) {
if (polyfill_snapshot != NULL)
{
SDL_BlitSurface(canvas, NULL, polyfill_snapshot, NULL);
}
polyfill_active = 1;
}
void polyfill_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas)
void polyfill_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
polyfill_num_pts = 0;
polyfill_editing = MAX_PTS;
polyfill_active = 0;
if (polyfill_snapshot != NULL) {
if (polyfill_snapshot != 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
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 nodeX[256];
SDL_Rect rect;
@ -446,30 +467,32 @@ void polyfill_draw_final(magic_api * api, SDL_Surface * canvas) {
ymin = canvas->w;
ymax = 0;
for (i = 0; i < polyfill_num_pts; i++) {
if (polyfill_pt_y[i] < ymin) {
for (i = 0; i < polyfill_num_pts; i++)
{
if (polyfill_pt_y[i] < ymin)
{
ymin = polyfill_pt_y[i];
}
if (polyfill_pt_y[i] > ymax) {
if (polyfill_pt_y[i] > ymax)
{
ymax = polyfill_pt_y[i];
}
}
printf("ymin %d -> ymax %d\n", ymin, ymax);
for (y = ymin; y <= ymax; y++) {
for (y = ymin; y <= ymax; y++)
{
nodes = 0;
j = polyfill_num_pts - 2;
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)) {
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))
{
nodeX[nodes++] = (int)
(
(double) polyfill_pt_x[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_x[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]));
}
j = i;
@ -477,24 +500,30 @@ void polyfill_draw_final(magic_api * api, SDL_Surface * canvas) {
// Sort the nodes, via a simple “Bubble” sort.
i = 0;
while (i < nodes - 1) {
if (nodeX[i] > nodeX[i+1]) {
while (i < nodes - 1)
{
if (nodeX[i] > nodeX[i + 1])
{
swap = nodeX[i];
nodeX[i] = nodeX[i + 1];
nodeX[i + 1] = swap;
if (i)
i--;
} else {
}
else
{
i++;
}
}
// 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)
break;
if (nodeX[i + 1] > 0) {
if (nodeX[i + 1] > 0)
{
if (nodeX[i] < 0)
nodeX[i] = 0;
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_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]);
return(0);
return (0);
}
if (rails_three == NULL) {
if (rails_three == NULL)
{
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]);
return(0);
return (0);
}
if (rails_corner == NULL) {
if (rails_corner == NULL)
{
fprintf(stderr, "Can't load image %s\n", rails_images[3]);
return(0);
return (0);
}
img_w = rails_one->w;

View file

@ -36,7 +36,8 @@
static int rainbow_radius = 16;
enum {
enum
{
TOOL_RAINBOW,
TOOL_SMOOTH_RAINBOW,
TOOL_RAINBOW_CYCLE,
@ -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,
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;
}

View file

@ -144,7 +144,7 @@ static void ribbon_linecb(void *ptr, int which ATTRIBUTE_UNUSED,
magic_api *api = (magic_api *) ptr;
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 + 1, ribbon_segment_color);
@ -175,7 +175,8 @@ void ribbon_drag(magic_api * api, int which, SDL_Surface * canvas,
angle = 0.0;
if (!first_click) {
if (!first_click)
{
double x_angle;
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;
do {
do
{
int brt;
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);
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, ribbon_linecb);
pt = pt2;
} while (((pt + 1) % ribbon_max_length) != ribbon_head);
}
while (((pt + 1) % ribbon_max_length) != ribbon_head);
}
update_rect->x = 0;
@ -247,8 +250,7 @@ void ribbon_shutdown(magic_api * api ATTRIBUTE_UNUSED)
// Record the color from Tux Paint:
void ribbon_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last 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)
{
ribbon_r = r;
ribbon_g = g;

View file

@ -39,32 +39,33 @@
#include "SDL_mixer.h"
#include <math.h>
enum {
enum
{
TOOL_SMOOTH,
TOOL_SQUIGGLES,
TOOL_LOOPS,
NUM_TOOLS
};
char * smooth_icon_fnames[NUM_TOOLS] = {
char *smooth_icon_fnames[NUM_TOOLS] = {
"smooth.png",
"squiggles.png",
"loops.png",
};
char * smooth_snd_fnames[NUM_TOOLS] = {
char *smooth_snd_fnames[NUM_TOOLS] = {
"smooth.ogg",
"squiggles.ogg",
"loops.ogg",
};
char * smooth_names[NUM_TOOLS] = {
char *smooth_names[NUM_TOOLS] = {
gettext_noop("Smooth"),
gettext_noop("Squiggles"),
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 squiggles."),
gettext_noop("Click and drag the mouse around to draw loop-the-loops."),
@ -131,7 +132,8 @@ int smooth_init(magic_api * api, Uint8 disabled_features ATTRIBUTE_UNUSED, Uint8
char fname[1024];
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]);
smooth_snds[i] = Mix_LoadWAV(fname);
}
@ -178,20 +180,19 @@ int smooth_get_order(int which)
}
// Return our description, localized:
char *smooth_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which, int mode ATTRIBUTE_UNUSED)
char *smooth_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
{
return (strdup(gettext(smooth_descrs[which])));
}
static void smooth_linecb(void *ptr, int which,
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
static void smooth_linecb(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
{
magic_api *api = (magic_api *) ptr;
SDL_Rect dest;
if (which == TOOL_SMOOTH) {
if (which == TOOL_SMOOTH)
{
/* FIXME */
dest.x = x;
dest.y = y;
@ -199,7 +200,9 @@ static void smooth_linecb(void *ptr, int which,
dest.h = smooth_size;
SDL_FillRect(canvas, &dest, smooth_color);
} else if (which == TOOL_LOOPS) {
}
else if (which == TOOL_LOOPS)
{
/* FIXME */
dest.x = x;
dest.y = y;
@ -207,7 +210,9 @@ static void smooth_linecb(void *ptr, int which,
dest.h = 2;
SDL_FillRect(canvas, &dest, smooth_color);
} else if (which == TOOL_SQUIGGLES) {
}
else if (which == TOOL_SQUIGGLES)
{
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);
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;
yy1 = yy2;
if (which == TOOL_LOOPS) {
if (which == TOOL_LOOPS)
{
smooth_squiggle_angle += 5;
smooth_squiggle_rad = LOOP_RAD_CALC;
} else if (which == TOOL_SQUIGGLES) {
}
else if (which == TOOL_SQUIGGLES)
{
smooth_squiggle_angle += (rand() % 5) + 5;
smooth_squiggle_rad += ((rand() % 3 * smooth_size) - smooth_size);
if (smooth_squiggle_rad < 5) {
if (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);
}
}
@ -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);
}
if (smooth_squiggle_angle >= 360) {
if (smooth_squiggle_angle >= 360)
{
smooth_squiggle_angle -= 360;
}
}
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 * canvas, SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
if (which == TOOL_SMOOTH) {
if (num_input_points >= MAX_CTRL_POINTS) {
if (which == TOOL_SMOOTH)
{
if (num_input_points >= MAX_CTRL_POINTS)
{
return;
}
smooth_capture = (smooth_capture + 1) % 4;
if (smooth_capture == 1) {
if (smooth_capture == 1)
{
num_input_points++;
smooth_control_points[num_input_points].x = x;
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);
} 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);
}
if (which == TOOL_SMOOTH) {
if (which == TOOL_SMOOTH)
{
if (ox > x)
{
int tmp = ox;
@ -295,13 +314,17 @@ void smooth_drag(magic_api * api, int which,
update_rect->y = oy - 16;
update_rect->w = (x + 16) - update_rect->x;
update_rect->h = (y + 16) - update_rect->y;
} else if (which == TOOL_LOOPS) {
}
else if (which == TOOL_LOOPS)
{
// FIXME
update_rect->x = 0;
update_rect->y = 0;
update_rect->w = canvas->w;
update_rect->h = canvas->h;
} else if (which == TOOL_SQUIGGLES) {
}
else if (which == TOOL_SQUIGGLES)
{
// FIXME
update_rect->x = 0;
update_rect->y = 0;
@ -314,19 +337,21 @@ void smooth_drag(magic_api * api, int which,
void smooth_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)
{
num_input_points = 0;
smooth_control_points[num_input_points].x = x;
smooth_control_points[num_input_points].y = y;
smooth_capture = 0;
if (which == TOOL_SQUIGGLES) {
if (which == TOOL_SQUIGGLES)
{
smooth_squiggle_angle = 0;
smooth_squiggle_rad = 0;
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_rad = LOOP_RAD_CALC;
smooth_drag(api, which, canvas, last, x, y, x, y, update_rect);
@ -336,15 +361,15 @@ void smooth_click(magic_api * api,
void smooth_release(magic_api * api,
int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas,
SDL_Surface * last,
int x, int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
{
if (which == TOOL_SMOOTH) {
if (which == TOOL_SMOOTH)
{
Point2D *curve;
int p, i, n_points;
for (p = 0; p < 4; p++) {
for (p = 0; p < 4; p++)
{
num_input_points++;
smooth_control_points[num_input_points].x = x;
smooth_control_points[num_input_points].y = y;
@ -352,7 +377,8 @@ void smooth_release(magic_api * api,
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,
smooth_control_points[p + 0].y,
smooth_control_points[p + 1].x,
@ -362,9 +388,7 @@ void smooth_release(magic_api * api,
smooth_control_points[p + 2].x,
smooth_control_points[p + 2].y) +
smooth_dist(smooth_control_points[p + 2].x,
smooth_control_points[p + 2].y,
smooth_control_points[p + 3].x,
smooth_control_points[p + 3].y);
smooth_control_points[p + 2].y, smooth_control_points[p + 3].x, smooth_control_points[p + 3].y);
if (n_points == 0)
continue; // No-op; not any points to plot
@ -376,7 +400,8 @@ void smooth_release(magic_api * api,
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);
@ -397,7 +422,8 @@ void smooth_shutdown(magic_api * api ATTRIBUTE_UNUSED)
{
int i;
for (i = 0; i < NUM_TOOLS; i++) {
for (i = 0; i < NUM_TOOLS; i++)
{
if (smooth_snds[i] != NULL)
Mix_FreeChunk(smooth_snds[i]);
}

View file

@ -29,11 +29,9 @@ Uint8 specular_size = 32;
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_Rect * update_rect);
SDL_Surface * snapshot, int old_x, int old_y, int x, int y, SDL_Rect * update_rect);
void specular_line_callback(void *pointer, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y);
void specular_line_callback(void *pointer, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
Uint32 specular_api_version(void)
@ -46,8 +44,7 @@ int specular_init(magic_api * api, Uint8 disabled_features, Uint8 complexity_lev
int i;
char filename[1024];
snprintf(filename, sizeof(filename), "%ssounds/magic/%s", api->data_directory,
"reflection.ogg"); // FIXME
snprintf(filename, sizeof(filename), "%ssounds/magic/%s", api->data_directory, "reflection.ogg"); // FIXME
snd_effect = Mix_LoadWAV(filename);
return (1);
@ -63,8 +60,7 @@ SDL_Surface *specular_get_icon(magic_api * api, int which)
{
char filename[1024];
snprintf(filename, sizeof(filename), "%simages/magic/%s",
api->data_directory, "reflection.png"); // FIXME
snprintf(filename, sizeof(filename), "%simages/magic/%s", api->data_directory, "reflection.png"); // FIXME
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)
{
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)
{
if (snd_effect != NULL) {
if (snd_effect != NULL)
{
Mix_FreeChunk(snd_effect);
}
}
@ -128,8 +127,7 @@ void specular_shutdown(magic_api * api)
void
specular_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
{
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
specular_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)
SDL_Surface * canvas, SDL_Surface * snapshot, int old_x, int old_y, int x, int y, SDL_Rect * update_rect)
{
SDL_LockSurface(snapshot);
SDL_LockSurface(canvas);
api->line((void *) api, which, canvas, snapshot,
old_x, old_y, x, y, 1,
specular_line_callback);
api->line((void *)api, which, canvas, snapshot, old_x, old_y, x, y, 1, specular_line_callback);
SDL_UnlockSurface(canvas);
SDL_UnlockSurface(snapshot);
@ -176,23 +170,23 @@ specular_drag(magic_api * api, int which,
void
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)
{
}
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_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)
{
specular_size = size * 16;
}
void specular_line_callback(void *pointer, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y)
void specular_line_callback(void *pointer, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y)
{
magic_api *api = (magic_api *) pointer;
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,
SDL_Surface * canvas)
void specular_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}
void specular_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas)
void specular_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas)
{
}

View file

@ -42,7 +42,7 @@ int num_tools[2] = {
2, /* when sizes available */
};
int * which_to_tool;
int *which_to_tool;
int which_to_tool_per_size_availability[2][6] = {
/* when sizes not available */
@ -79,6 +79,7 @@ float trochoids_sizes_per_size_setting[NUM_SIZES] = {
SIZE_OUTSIDE,
SIZE_WELLOUTSIDE,
};
/* Default to "SIZE_EDGE" */
#define DEFAULT_SIZE 3
@ -119,20 +120,29 @@ const char *tool_names[NUM_TOOLS] = {
const char *tool_descriptions[NUM_TOOLS] = {
/* 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("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."),
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
("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 */
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("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."),
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
("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) */
enum {
enum
{
SND_DRAG,
SND_RELEASE_EPITROCHOID,
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);
void trochoids_shutdown(magic_api * api);
void trochoids_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
void 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);
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);
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect, int guides);
void trochoids_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect);
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
void trochoids_sound(magic_api * api, int snd_idx, int x, int y);
void trochoids_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, Uint8 r, Uint8 g, Uint8 b,
SDL_Rect * update_rect);
SDL_Surface * snapshot, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
void trochoids_set_size(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last,
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_xorline_callback(void *pointer, int tool, 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);
SDL_Surface * canvas, SDL_Surface * last, 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_xorline_callback(void *pointer, int tool, 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);
@ -208,13 +208,17 @@ int trochoids_init(magic_api * api, Uint8 disabled_features, Uint8 complexity_le
int i;
char filename[1024];
for (i = 0; i < NUM_SNDS; i++) {
for (i = 0; i < NUM_SNDS; i++)
{
sound_effects[i] = NULL;
}
if (disabled_features & MAGIC_FEATURE_SIZE) {
if (disabled_features & MAGIC_FEATURE_SIZE)
{
tp_offers_sizes = 0;
} else {
}
else
{
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++)
{
snprintf(filename, sizeof(filename), "%ssounds/magic/%s", api->data_directory,
sound_filenames[i]);
snprintf(filename, sizeof(filename), "%ssounds/magic/%s", api->data_directory, sound_filenames[i]);
sound_effects[i] = Mix_LoadWAV(filename);
}
@ -241,8 +244,7 @@ SDL_Surface *trochoids_get_icon(magic_api * api, int which)
{
char filename[1024];
snprintf(filename, sizeof(filename), "%simages/magic/%s",
api->data_directory, icon_filenames[which_to_tool[which]]);
snprintf(filename, sizeof(filename), "%simages/magic/%s", api->data_directory, icon_filenames[which_to_tool[which]]);
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,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
Uint8 trochoids_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
{
return DEFAULT_SIZE;
}
@ -300,8 +301,10 @@ void trochoids_shutdown(magic_api * api ATTRIBUTE_UNUSED)
{
int i;
for (i = 0; i < NUM_SNDS; i++) {
if (sound_effects[i] != NULL) {
for (i = 0; i < NUM_SNDS; i++)
{
if (sound_effects[i] != NULL)
{
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,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
{
trochoids_x = x;
trochoids_y = y;
@ -322,8 +324,7 @@ void trochoids_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
/* Affect the canvas on drag: */
void trochoids_drag(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * snapshot,
int old_x ATTRIBUTE_UNUSED, int old_y ATTRIBUTE_UNUSED,
int x, int y, SDL_Rect * update_rect)
int old_x ATTRIBUTE_UNUSED, int old_y ATTRIBUTE_UNUSED, int x, int y, SDL_Rect * update_rect)
{
dragged = 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,
SDL_Surface * canvas, SDL_Surface * snapshot,
int x, int y, SDL_Rect * update_rect, int guides) {
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect, int guides)
{
int R, r, d, LCM;
int px, py, px2, py2;
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) */
R = abs(trochoids_x - x);
if (R < 20) {
if (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) */
r = abs(y - trochoids_y);
if (r < 10) {
if (r < 10)
{
r = 10;
}
@ -358,25 +361,31 @@ void trochoids_work(magic_api * api, int which,
if (which == TOOL_HYPOTROCHOID_SIZES ||
which == TOOL_HYPOTROCHOID_NOSIZES_1 ||
which == TOOL_HYPOTROCHOID_NOSIZES_2 ||
which == TOOL_HYPOTROCHOID_NOSIZES_3) {
which == TOOL_HYPOTROCHOID_NOSIZES_2 || which == TOOL_HYPOTROCHOID_NOSIZES_3)
{
/* Hypotrochoid */
if (R == r) {
if (R == r)
{
r += 10;
}
r_ratio = (float) (R - r) / (float) r;
} else {
r_ratio = (float)(R - r) / (float)r;
}
else
{
/* Epitrochoid */
r_ratio = (float) (R + r) / (float) r;
r_ratio = (float)(R + r) / (float)r;
}
/* Size option (or use of alternate tools, if --nomagicsizes)
determines the distance from the center of the rotator
that the pen draws */
if (tp_offers_sizes) {
if (tp_offers_sizes)
{
size = trochoids_sizes_per_size_setting[trochoids_size];
} else {
}
else
{
size = trochoids_sizes_per_tool[which];
}
d = r * size;
@ -394,19 +403,22 @@ void trochoids_work(magic_api * api, int which,
/* Draw the lines */
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);
if (which == TOOL_HYPOTROCHOID_SIZES ||
which == TOOL_HYPOTROCHOID_NOSIZES_1 ||
which == TOOL_HYPOTROCHOID_NOSIZES_2 ||
which == TOOL_HYPOTROCHOID_NOSIZES_3) {
which == TOOL_HYPOTROCHOID_NOSIZES_2 || which == TOOL_HYPOTROCHOID_NOSIZES_3)
{
/* Hypotrochoid */
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)));
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)));
} else {
}
else
{
/* Epitrochoid */
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)));
@ -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)));
}
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;
/* When still dragging (before release), draw some "guides",
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) */
guide_spacing = 360 / R;
if (guide_spacing < 2) {
if (guide_spacing < 2)
{
guide_spacing = 2;
}
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)));
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)));
api->putpixel(canvas, px, py, 0);
api->putpixel(canvas, px + 1, py, 0xff);
api->putpixel(canvas, px, py + 1, 0);
@ -441,22 +457,26 @@ void trochoids_work(magic_api * api, int which,
/* Rotator (rolling circle) */
guide_spacing = 360 / r;
if (guide_spacing < 2) {
if (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 ||
which == TOOL_HYPOTROCHOID_NOSIZES_1 ||
which == TOOL_HYPOTROCHOID_NOSIZES_2 ||
which == TOOL_HYPOTROCHOID_NOSIZES_3) {
which == TOOL_HYPOTROCHOID_NOSIZES_2 || which == TOOL_HYPOTROCHOID_NOSIZES_3)
{
/* Hypotrochoid */
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)));
} else {
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)));
}
else
{
/* Epitrochoid */
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)));
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)));
}
api->xorpixel(canvas, px, py);
api->xorpixel(canvas, px + 1, py);
@ -468,15 +488,17 @@ void trochoids_work(magic_api * api, int which,
/* Pen */
if (which == TOOL_HYPOTROCHOID_SIZES ||
which == TOOL_HYPOTROCHOID_NOSIZES_1 ||
which == TOOL_HYPOTROCHOID_NOSIZES_2 ||
which == TOOL_HYPOTROCHOID_NOSIZES_3) {
which == TOOL_HYPOTROCHOID_NOSIZES_2 || which == TOOL_HYPOTROCHOID_NOSIZES_3)
{
/* Hypotrochoid */
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)));
px2 = trochoids_x + (((R - r) * deg_cos(rotator_anim_a)));
py2 = trochoids_y + (((R - r) * deg_sin(rotator_anim_a)));
} else {
}
else
{
/* Epitrochoid */
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)));
@ -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);
for (yy = -2; yy <= 2; yy++) {
for (xx = -2; xx <= 2; xx++) {
for (yy = -2; yy <= 2; yy++)
{
for (xx = -2; xx <= 2; xx++)
{
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,
SDL_Surface * canvas, SDL_Surface * snapshot,
int x, int y, SDL_Rect * update_rect)
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
{
int tool, snd_idx;
@ -511,11 +534,12 @@ void trochoids_release(magic_api * api, int which,
/* Pick which sound to play & play it */
tool = which_to_tool[which];
if (tool == TOOL_EPITROCHOID_SIZES ||
tool == TOOL_EPITROCHOID_NOSIZES_1 ||
tool == TOOL_EPITROCHOID_NOSIZES_2 ||
tool == TOOL_EPITROCHOID_NOSIZES_3) {
tool == TOOL_EPITROCHOID_NOSIZES_1 || tool == TOOL_EPITROCHOID_NOSIZES_2 || tool == TOOL_EPITROCHOID_NOSIZES_3)
{
snd_idx = SND_RELEASE_EPITROCHOID;
} else {
}
else
{
snd_idx = SND_RELEASE_HYPOTROCHOID;
}
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
'default' offset to get a reasonably pleasant
shape -- for users who tried clicking w/o dragging */
if (dragged == 0) {
if (dragged == 0)
{
if (tool == TOOL_EPITROCHOID_SIZES ||
tool == TOOL_EPITROCHOID_NOSIZES_1 ||
tool == TOOL_EPITROCHOID_NOSIZES_2 ||
tool == TOOL_EPITROCHOID_NOSIZES_3) {
tool == TOOL_EPITROCHOID_NOSIZES_1 || tool == TOOL_EPITROCHOID_NOSIZES_2 || tool == TOOL_EPITROCHOID_NOSIZES_3)
{
x = trochoids_x + 50;
y = trochoids_y + 20;
} else {
}
else
{
x = trochoids_x + 70;
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
on the size and position of the shape being generated
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;
/* Volume based on the radii of the stator (fixed circle)
and the rotator (rolling circle), combined; larger = louder */
R = abs(trochoids_x - x) + abs(trochoids_y - y);
if (R < 20) {
if (R < 20)
{
R = 20;
} else if (R > api->canvas_w) {
}
else if (R > api->canvas_w)
{
R = api->canvas_w;
}
vol = (255 * R * 2) / api->canvas_w;
if (vol > 255) {
if (vol > 255)
{
vol = 255;
}
@ -571,8 +602,7 @@ 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,
SDL_Surface * canvas ATTRIBUTE_UNUSED,
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)
{
trochoids_color = SDL_MapRGB(canvas->format, r, g, b);
}
@ -587,8 +617,7 @@ void trochoids_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UN
void trochoids_line_callback(void *pointer ATTRIBUTE_UNUSED, int tool ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED,
int x, int y)
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
{
magic_api *api = (magic_api *) 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,
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED,
int x, int y)
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
{
magic_api *api = (magic_api *) pointer;
@ -617,16 +645,21 @@ void trochoids_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_U
{
}
int calc_lcm(int a, int b) {
int calc_lcm(int a, int b)
{
int max;
if (a > b) {
if (a > b)
{
max = a;
} else {
}
else
{
max = b;
}
while ((max % a) != 0 || (max % b) != 0) {
while ((max % a) != 0 || (max % b) != 0)
{
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")
);
user_font_styles[num_font_styles]->score +=
charset_works(font, /* distinct circle-like characters (e.g., 'O' (capital oh) vs. '0' (zero)) */
gettext("O0")
);
user_font_styles[num_font_styles]->score += charset_works(font, /* distinct circle-like characters (e.g., 'O' (capital oh) vs. '0' (zero)) */
gettext("O0"));
user_font_styles[num_font_styles]->score +=
charset_works(font,
user_font_styles[num_font_styles]->score += charset_works(font,
/* distinct line-like characters (e.g., 'l' (lowercase elle) vs. '1' (one) vs. 'I' (capital aye)) */
gettext("1Il|")
);
gettext("1Il|"));
// Translation spares

View file

@ -174,8 +174,8 @@ int button_label_y_nudge;
static void reliable_read(int fd, void *buf, size_t count);
#endif
const char * PANGO_DEFAULT_FONT = "DejaVu Sans";
const char * PANGO_DEFAULT_FONT_FALLBACK = NULL;
const char *PANGO_DEFAULT_FONT = "DejaVu Sans";
const char *PANGO_DEFAULT_FONT_FALLBACK = NULL;
/* Names of the fonts we include in `fonts/locale/`
(LANG_* codes are from `src/i18n.h`) */
@ -186,21 +186,21 @@ const char * PANGO_DEFAULT_FONT_FALLBACK = NULL;
download of the full (much larger) font TTF file.
(https://tuxpaint.org/download/fonts/) */
default_locale_font_t default_local_fonts[] = {
{ LANG_AR, "ae_Nice", NULL },
{ LANG_BO, "Tsampa Keyboard", NULL }, // NOTE: Our current translation is Wylie transliterated, not Unicode! */
{ LANG_EL, "Thryomanes", NULL},
{ LANG_GU, "Lohit Gujarati", NULL },
{ LANG_HE, "Nachlieli Light", NULL },
{ LANG_HI, "Raghindi", NULL },
{ 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_KO, "Baekmuk Gulim", NULL },
{ LANG_TA, "TSCu_Comic", NULL },
{ LANG_TE, "Vemana2000", NULL },
{ LANG_TH, "Garuda", NULL },
{ LANG_ZH_CN, "AR PL SungtiL GB", NULL },
{ LANG_ZH_TW, "HanWangKaiMediumChuIn", "SubsetForTuxPaint" },
{ -1, NULL, NULL },
{LANG_AR, "ae_Nice", NULL},
{LANG_BO, "Tsampa Keyboard", NULL}, // NOTE: Our current translation is Wylie transliterated, not Unicode! */
{LANG_EL, "Thryomanes", NULL},
{LANG_GU, "Lohit Gujarati", NULL},
{LANG_HE, "Nachlieli Light", NULL},
{LANG_HI, "Raghindi", NULL},
{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_KO, "Baekmuk Gulim", NULL},
{LANG_TA, "TSCu_Comic", NULL},
{LANG_TE, "Vemana2000", NULL},
{LANG_TH, "Garuda", NULL},
{LANG_ZH_CN, "AR PL SungtiL GB", NULL},
{LANG_ZH_TW, "HanWangKaiMediumChuIn", "SubsetForTuxPaint"},
{-1, NULL, NULL},
};
void TuxPaint_Font_CloseFont(TuxPaint_Font * tpf)
@ -340,7 +340,7 @@ TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc, const char *ttffile
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
#ifdef DEBUG
@ -1715,14 +1715,14 @@ void sdl_color_to_pango_color(SDL_Color sdl_color, SDLPango_Matrix * pango_color
* (e.g., "tuxpaint --uifont bookman" finds and uses "URW Bookman"
* on my system -bjk 2023.06.01)
*/
char * ask_pango_for_font(char * pangodesc)
char *ask_pango_for_font(char *pangodesc)
{
PangoFontMap * font_map;
PangoContext * context;
PangoFontDescription * font_desc;
PangoFontMap *font_map;
PangoContext *context;
PangoFontDescription *font_desc;
PangoFont *font;
PangoFontDescription * pfd;
char * descr;
PangoFontDescription *pfd;
char *descr;
font_map = pango_ft2_font_map_new();
if (font_map == NULL)

View file

@ -49,14 +49,15 @@
based on locale.
*/
typedef struct default_locale_font_s {
typedef struct default_locale_font_s
{
int locale_id;
const char * font_name;
const char * font_name_fallback;
const char *font_name;
const char *font_name_fallback;
} default_locale_font_t;
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"
@ -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,
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

View file

@ -22,7 +22,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
June 14, 2002 - April 10, 2024
June 14, 2002 - May 10, 2024
*/
#include "platform.h"
@ -582,7 +582,7 @@ int iswprint(wchar_t wc)
#include "compiler.h"
char * tp_ui_font = NULL;
char *tp_ui_font = NULL;
/* Convert floats to fractions between (min/max) and ((max-min)/max)
(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);
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);
}
/**
@ -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;
static int brush_counter, brush_frame;
enum {
enum
{
ERASER_TYPE_SQUARE,
ERASER_TYPE_CIRCLE,
ERASER_TYPE_CIRCLE_FUZZY,
@ -2220,13 +2222,15 @@ static int export_gif(int *selected, int num_selected, char *dirname, char **d_n
int export_gif_monitor_events(void);
/* Locations where export_pict() can save */
enum {
enum
{
EXPORT_LOC_PICTURES,
EXPORT_LOC_TEMPLATES
};
/* Return values of export_pict() */
enum {
enum
{
EXPORT_SUCCESS,
EXPORT_ERR_CANNOT_MKDIR, /* Need to mkdir() but cannot */
EXPORT_ERR_FILENAME_PROBLEM, /* Problem creating output file's filename */
@ -2235,10 +2239,10 @@ enum {
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);
void get_img_dimensions(char * fpath, int * widht, int * height);
uLong get_img_crc(char * fpath);
void get_img_dimensions(char *fpath, int *widht, int *height);
uLong get_img_crc(char *fpath);
static void wait_for_sfx(void);
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);
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)]);
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)]);
magic_set_size();
}
}
@ -4962,7 +4970,7 @@ static void mainloop(void)
else if (cur_tool == TOOL_TEXT || cur_tool == TOOL_LABEL)
{
char font_tux_text[1024];
const char * fmt_str;
const char *fmt_str;
cur_font = cur_thing;
@ -4974,8 +4982,7 @@ static void mainloop(void)
safe_snprintf(font_tux_text, sizeof(font_tux_text), gettext(fmt_str),
TTF_FontFaceFamilyName(getfonthandle(cur_font)->ttf_font),
TTF_FontFaceStyleName(getfonthandle(cur_font)->ttf_font),
getfonthandle(cur_font)->height);
TTF_FontFaceStyleName(getfonthandle(cur_font)->ttf_font), getfonthandle(cur_font)->height);
draw_tux_text(TUX_GREAT, font_tux_text, 1);
if (do_draw)
@ -6461,7 +6468,7 @@ static void mainloop(void)
/* A selectable item */
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) */
do_setcursor(cursor_hand);
@ -8186,37 +8193,38 @@ void show_usage(int exitcode)
* Show a list of fonts that Pango finds (and hence
* should be available to "--uifont" argument) and exit.
*/
void show_fonts(void) {
void show_fonts(void)
{
PangoFontMap *fontmap;
PangoFontFamily **families;
int i, n_families;
char * * family_names;
char **family_names;
char locale_fontdir[MAX_PATH];
FcBool fontAddStatus;
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)
{
fprintf(stderr, "Unable to add font dir %s\n", locale_fontdir);
}
FcDirCacheRead((const FcChar8 *) locale_fontdir, FcTrue /* force */, FcConfigGetCurrent());
FcDirCacheRescan((const FcChar8 *) locale_fontdir, FcConfigGetCurrent());
FcDirCacheRead((const FcChar8 *)locale_fontdir, FcTrue /* force */ , FcConfigGetCurrent());
FcDirCacheRescan((const FcChar8 *)locale_fontdir, FcConfigGetCurrent());
generate_fontconfig_cache_real();
fontmap = pango_ft2_font_map_new();
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++)
{
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++)
{
@ -8230,7 +8238,7 @@ void show_fonts(void) {
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: */
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: */
@ -11423,7 +11432,8 @@ static void draw_erasers(void)
int rad, rad_sqr;
int yy, w, sx, sy;
if (fuzzy || trans) {
if (fuzzy || trans)
{
/* Fuzzy or transparent; draw dithered circle */
rad = sz / 2;
rad_sqr = (rad * rad);
@ -11434,11 +11444,14 @@ static void draw_erasers(void)
sx = x + rad - w;
sy = y + rad + yy;
if (fuzzy || trans) {
if (fuzzy || trans)
{
int xxx;
for (xxx = 0; xxx < w * 2; xxx++) {
if ((sx + xxx) % 2 == sy % 2) {
for (xxx = 0; xxx < w * 2; xxx++)
{
if ((sx + xxx) % 2 == sy % 2)
{
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 */
if (fuzzy) {
if (fuzzy)
{
/* Fuzzy's solid circle is within the dithered circle drawn above */
sz -= 2;
x++;
y++;
}
if (sz > 0) {
if (sz > 0)
{
rad = sz / 2;
rad_sqr = (rad * rad);
@ -12203,10 +12219,9 @@ static void render_brush(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],
1, brushes_descr_localized[cur_brush]);
draw_tux_text_ex(TUX_GREAT, brushes_descr[cur_brush], 1, brushes_descr_localized[cur_brush]);
}
else
@ -12401,7 +12416,7 @@ static void do_eraser(int x, int y, int update)
int xx, yy, n, hit;
int eraser_type;
int undo_ctr;
SDL_Surface * last;
SDL_Surface *last;
if (cur_undo > 0)
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 ||
eraser_type == ERASER_TYPE_CIRCLE_TRANSPARENT)
else if (eraser_type == ERASER_TYPE_CIRCLE_FUZZY || eraser_type == ERASER_TYPE_CIRCLE_TRANSPARENT)
{
Uint8 r_erase, g_erase, b_erase;
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];
void (*putpixel) (SDL_Surface *, int, int, Uint32) = putpixels[canvas->format->BytesPerPixel];
Uint32(*getpixel_bkgd) (SDL_Surface *, int, int) = NULL;
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;
/* 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 (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)
{
/* Fuzzy */
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;
} else {
}
else
{
/* Transparent */
SDL_GetRGB(
getpixels[last->format->BytesPerPixel](last, x + xx, y + yy),
last->format, &r_canvas, &g_canvas, &b_canvas
);
SDL_GetRGB(getpixels[last->format->BytesPerPixel] (last, x + xx, y + yy),
last->format, &r_canvas, &g_canvas, &b_canvas);
canvas_pct = 0.75;
erase_pct = 0.25;
}
r = (((float) r_erase * erase_pct) + ((float) r_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);
r = (((float)r_erase * erase_pct) + ((float)r_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);
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] == '"')
{
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_spacing);
free(brushes_spacing_default);
for (i = 0; i < num_brushes; i++) {
if (brushes_descr[i] != NULL) {
for (i = 0; i < num_brushes; i++)
{
if (brushes_descr[i] != NULL)
{
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 (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);
fwrite(&a, alpha_size, 1, lfi);
}
@ -17221,10 +17241,17 @@ static int do_open(void)
char *instructions;
int num_left_buttons;
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 = 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."));
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 =
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);
@ -17339,7 +17366,8 @@ static int do_open(void)
SDL_BlitSurface(img_openlabels_slideshow, NULL, screen, &dest);
if (!disable_template_export) {
if (!disable_template_export)
{
/* "Template" (make template) button: */
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.y = (button_h * buttons_tall + r_ttools.h) - img_openlabels_template->h;
SDL_BlitSurface(img_openlabels_template, NULL, screen, &dest);
} else {
}
else
{
num_left_buttons = 2;
}
@ -17512,10 +17542,7 @@ static int do_open(void)
done = 1;
playsound(screen, 1, SND_CLICK, 1, SNDPOS_RIGHT, SNDDIST_NEAR);
}
else if (!disable_erase &&
key == SDLK_d &&
(event.key.keysym.mod & KMOD_CTRL) &&
d_places[which] != PLACE_STARTERS_DIR && // FIXME: Meaningless?
else if (!disable_erase && key == SDLK_d && (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! */
@ -17781,8 +17808,7 @@ static int do_open(void)
do_setcursor(cursor_hand);
}
else if (event.button.x >= (WINDOW_WIDTH - r_ttoolopt.w - button_w * 2)
&& event.button.x < (WINDOW_WIDTH - r_ttoolopt.w - button_w)
&& !disable_erase)
&& event.button.x < (WINDOW_WIDTH - r_ttoolopt.w - button_w) && !disable_erase)
{
/* Command button on the right: Erase [maybe] */
do_setcursor(cursor_hand);
@ -21121,6 +21147,7 @@ static SDL_Surface *_load_svg(const char *file)
int width, height, stride;
float scale;
int bpp = 32, btpp = 4;
#if !(LIBRSVG_MAJOR_VERSION < 2 || LIBRSVG_MINOR_VERSION < 46)
RsvgRectangle viewport;
#endif
@ -21158,8 +21185,8 @@ static SDL_Surface *_load_svg(const char *file)
gdouble d_rwidth, d_rheight;
rsvg_handle_get_intrinsic_size_in_pixels(rsvg_handle, &d_rwidth, &d_rheight);
rwidth = (int) d_rwidth;
rheight = (int) d_rheight;
rwidth = (int)d_rwidth;
rheight = (int)d_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;
/* FIXME: This returns a gboolean; not using (not 100% sure what to expect) -bjk 2023.06.18 */
rsvg_handle_render_document(
rsvg_handle,
cr,
&viewport,
&gerr);
rsvg_handle_render_document(rsvg_handle, cr, &viewport, &gerr);
/* FIXME: ignoring errors (gerr) for now -bjk 2023.06.18 */
#endif
@ -21780,7 +21803,8 @@ static void load_magic_plugins(void)
}
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)
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)
{
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);
SDL_UnloadObject(magic_handle[num_plugin_files]);
}
@ -21924,7 +21950,8 @@ static void load_magic_plugins(void)
num_magics[group]++;
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",
MAX_MAGICS_PER_GROUP, group);
num_magics[group]--; // FIXME: Do something better than just this! -bjk 2024.04.08
@ -21974,9 +22001,11 @@ static void load_magic_plugins(void)
/* Start out with the first magic group that _has_ any tools */
tries = 0;
while (num_magics[magic_group] == 0 && tries < MAX_MAGIC_GROUPS) {
while (num_magics[magic_group] == 0 && tries < MAX_MAGIC_GROUPS)
{
magic_group++;
if (magic_group >= MAX_MAGIC_GROUPS) {
if (magic_group >= MAX_MAGIC_GROUPS)
{
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 *bm = (magic_t *) b;
if (am->order != bm->order) {
if (am->order != bm->order)
{
/* Different 'order's, use them */
return (am->order - bm->order);
} else {
}
else
{
/* Same 'order', use the (localized) 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 valhat_x, valhat_y, hatmotioner;
int skip;
#ifndef NOSVG
int k;
#endif
@ -24131,8 +24164,7 @@ static void do_quick_eraser(void)
/* Do an initial erase at the click location */
SDL_GetMouseState(&mx, &my);
eraser_draw(mx - r_canvas.x, my - r_canvas.y,
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);
done = 0;
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(gh * aa + gu * (1.0 - aa)), linear_to_sRGB(bh * aa + bu * (1.0 - aa))));
putpixels[img_color_btns[the_color + NUM_COLORS]->
format->BytesPerPixel] (img_color_btns[the_color + NUM_COLORS], x, y,
SDL_MapRGB(img_color_btns[the_color + NUM_COLORS]->format,
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))));
putpixels[img_color_btns[the_color + NUM_COLORS]->format->BytesPerPixel] (img_color_btns[the_color + NUM_COLORS],
x, y,
SDL_MapRGB(img_color_btns
[the_color +
NUM_COLORS]->format,
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];
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,
magics[magic_group][cur_magic
@ -26189,8 +26232,8 @@ static void magic_set_size()
[magic_group]].mode,
canvas, last,
magics[magic_group][cur_magic
[magic_group]].
size[magic_modeint
[magic_group]].size
[magic_modeint
(magics[magic_group]
[cur_magic[magic_group]].mode)],
&update_rect);
@ -27069,7 +27112,7 @@ static void set_label_fonts()
/* FIXME: 2009/09/13 TTF_FontFaceFamilyName() appends random "\n" at the end
of the returned string. Should investigate why, and when corrected,
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++)
if (ttffont[c] == '\n')
ttffont[c] = '\0';
@ -27975,7 +28018,9 @@ static void parse_file_options(struct cfginfo *restrict tmpcfg, const char *file
}
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;
}
#endif
@ -28304,7 +28349,7 @@ static void setup_config(char *argv[])
tp_ui_font_fallback = NULL;
char * tmp_str;
char *tmp_str;
FcBool fontAddStatus;
char locale_fontdir[MAX_PATH];
@ -28312,7 +28357,7 @@ static void setup_config(char *argv[])
{
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);
if (PANGO_DEFAULT_FONT_FALLBACK != NULL)
{
@ -28322,11 +28367,12 @@ static void setup_config(char *argv[])
else
{
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{
printf/*DEBUG_PRINTF*/("Requested default UI font, \"%s\"\n", PANGO_DEFAULT_FONT);
else
{
printf /*DEBUG_PRINTF */ ("Requested default UI font, \"%s\"\n", PANGO_DEFAULT_FONT);
tp_ui_font = strdup(PANGO_DEFAULT_FONT);
if (PANGO_DEFAULT_FONT_FALLBACK != NULL)
{
@ -28338,26 +28384,29 @@ static void setup_config(char *argv[])
so SDL2_Pango can find and use them */
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)
{
fprintf(stderr, "Unable to add font dir %s\n", locale_fontdir);
}
/* FIXME: Unclear whether this is necessary? -bjk 2023.06.12 */
DEBUG_PRINTF("Rescanning fonts..."); fflush(stdout);
FcDirCacheRead((const FcChar8 *) locale_fontdir, FcTrue /* force */, FcConfigGetCurrent());
FcDirCacheRescan((const FcChar8 *) locale_fontdir, FcConfigGetCurrent());
DEBUG_PRINTF("Rescanning fonts...");
fflush(stdout);
FcDirCacheRead((const FcChar8 *)locale_fontdir, FcTrue /* force */ , FcConfigGetCurrent());
FcDirCacheRescan((const FcChar8 *)locale_fontdir, FcConfigGetCurrent());
DEBUG_PRINTF("done\n");
#ifdef DEBUG
{
FcStrList *str_list;
FcChar8 *path;
str_list = FcConfigGetFontDirs(FcConfigGetCurrent());
printf("FcConfigGetFontDirs():\n");
while ((path = FcStrListNext(str_list)) != NULL) {
printf(" * %s\n", (const char *) path);
while ((path = FcStrListNext(str_list)) != NULL)
{
printf(" * %s\n", (const char *)path);
}
printf("\n");
}
@ -28373,7 +28422,7 @@ static void setup_config(char *argv[])
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);
}
}
@ -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);
exit(1);
}
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);
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);
}
}
else
@ -28517,13 +28567,20 @@ static void setup_config(char *argv[])
{
/* FIXME: Could maybe iterate the array of MAGIC_COMPLEXITY_LEVEL_NAMES[],
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;
} else if (!strcmp(tmpcfg.complexity, "beginner")) {
}
else if (!strcmp(tmpcfg.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;
} else {
}
else
{
fprintf(stderr, "Ignoring unknown 'complexity' value \"%s\"\n", tmpcfg.complexity);
}
}
@ -29259,6 +29316,7 @@ static void setup(void)
Uint32 init_flags;
char tmp_str[128];
SDL_Surface *img1;
Uint32(*getpixel_tmp_btn_up) (SDL_Surface *, int, int);
Uint32(*getpixel_tmp_btn_down) (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");
#else
window_screen = SDL_CreateWindow(NULL, win_x, win_y,
WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_FULLSCREEN_DESKTOP);
window_screen = SDL_CreateWindow(NULL, win_x, win_y, WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_FULLSCREEN_DESKTOP);
if (window_screen == NULL)
printf("window_screen = NULL 2\n");
#endif
@ -29836,8 +29893,7 @@ static void setup(void)
#endif
medium_font = TuxPaint_Font_OpenFont(tp_ui_font,
DATA_PREFIX "fonts/default_font.ttf", /* FIXME: Does this matter any more? -bjk 2023.05.29 */
medium_font = TuxPaint_Font_OpenFont(tp_ui_font, DATA_PREFIX "fonts/default_font.ttf", /* FIXME: Does this matter any more? -bjk 2023.05.29 */
(18 - (only_uppercase * 3)) * button_scale);
if (medium_font == NULL)
@ -30176,8 +30232,7 @@ static void setup(void)
/* Load system fonts: */
large_font = TuxPaint_Font_OpenFont(tp_ui_font,
DATA_PREFIX "fonts/default_font.ttf", /* FIXME: Does this matter any more? -bjk 2023.05.29 */
large_font = TuxPaint_Font_OpenFont(tp_ui_font, DATA_PREFIX "fonts/default_font.ttf", /* FIXME: Does this matter any more? -bjk 2023.05.29 */
(30 - (only_uppercase * 3)) * button_scale);
if (large_font == NULL)
@ -30192,8 +30247,7 @@ static void setup(void)
}
small_font = TuxPaint_Font_OpenFont(tp_ui_font,
DATA_PREFIX "fonts/default_font.ttf", /* FIXME: Does this matter any more? -bjk 2023.05.29 */
small_font = TuxPaint_Font_OpenFont(tp_ui_font, DATA_PREFIX "fonts/default_font.ttf", /* FIXME: Does this matter any more? -bjk 2023.05.29 */
#ifdef __APPLE__
(12 - (only_uppercase * 2)) * button_scale
#else
@ -30221,7 +30275,7 @@ static void setup(void)
/* Load magic tool plugins: */
magic_disabled_features = 0b00000000;
magic_disabled_features = 0x00; // 0b00000000
if (disable_magic_sizes)
{
magic_disabled_features |= MAGIC_FEATURE_SIZE;
@ -30388,8 +30442,7 @@ static void setup(void)
gd * (1.0 -
aa)),
linear_to_sRGB(bh * aa +
bd * (1.0 -
aa))));
bd * (1.0 - aa))));
}
}
}
@ -31798,7 +31851,7 @@ int export_gif_monitor_events(void)
* + unused by EXPORT_LOC_PICTURES (just send NULL)
* @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;
size_t len;
@ -31825,7 +31878,7 @@ static int export_pict(char *fname, int where, char * orig_fname)
}
else /* where == EXPORT_LOC_TEMPLATES */
{
char * dir;
char *dir;
pict_fname = NULL;
@ -31930,12 +31983,15 @@ static int export_pict(char *fname, int where, char * orig_fname)
}
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
{
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
@ -31967,7 +32023,7 @@ static int export_pict(char *fname, int where, char * orig_fname)
/* Create a unique filename, within that dir */
t = time(NULL);
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);
}
@ -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 * 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_infop info;
@ -32068,10 +32124,10 @@ void get_img_dimensions(char * fpath, int * w, int * h)
png_destroy_read_struct(&png, &info, NULL);
}
uLong get_img_crc(char * fpath)
uLong get_img_crc(char *fpath)
{
uLong crc;
FILE * fi;
FILE *fi;
size_t len;
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();
if (Version < 0x80000000)
Build = (DWORD)(HIWORD(Version));
Build = (DWORD) (HIWORD(Version));
if (IsWindows10OrGreater()) {
if (Build < 22000){
if (IsWindows10OrGreater())
{
if (Build < 22000)
{
verStr = strdup("Windows 10");
}else{
}
else
{
verStr = strdup("Windows 11");
}
}else if (IsWindows8Point1OrGreater()){
}
else if (IsWindows8Point1OrGreater())
{
verStr = strdup("Windows 8.1");
}else if (IsWindows8OrGreater()){
}
else if (IsWindows8OrGreater())
{
verStr = strdup("Windows 8");
}else if (IsWindows7SP1OrGreater()){
}
else if (IsWindows7SP1OrGreater())
{
verStr = strdup("Windows 7 Service Pack 1");
}else if (IsWindows7OrGreater()){
}
else if (IsWindows7OrGreater())
{
verStr = strdup("Windows 7");
}else if (IsWindowsVistaSP2OrGreater()){
}
else if (IsWindowsVistaSP2OrGreater())
{
verStr = strdup("Windows Vista Service Pack 2");
}else if (IsWindowsVistaSP1OrGreater()){
}
else if (IsWindowsVistaSP1OrGreater())
{
verStr = strdup("Windows Vista Service Pack 1");
}else if (IsWindowsVistaOrGreater()){
}
else if (IsWindowsVistaOrGreater())
{
verStr = strdup("Windows Vista");
}else{
}
else
{
verStr = strdup("unknown");
}
printf ("Microsoft %s", verStr);
printf("Microsoft %s", verStr);
if (IsWindowsServer()){
if (IsWindowsServer())
{
printf(" Server");
}
if (Version < 0x80000000){
if (Version < 0x80000000)
{
printf(" (Build %d)\n", Build);
}
}