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

@ -19,32 +19,34 @@
#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] = {
"dither.ogg", // FIXME
char *polyfill_snd_filenames[NUM_TOOLS] = {
"dither.ogg", // FIXME
};
#define SNAP_SIZE 16
#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));
}
@ -118,7 +117,7 @@ int polyfill_get_group(magic_api * api, int which)
int polyfill_get_order(int which)
{
return 610 + which; // FIXME
return 610 + which; // FIXME
}
@ -164,7 +163,8 @@ void polyfill_shutdown(magic_api * api)
}
}
if (polyfill_snapshot != NULL) {
if (polyfill_snapshot != NULL)
{
SDL_FreeSurface(polyfill_snapshot);
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);
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)