Adding "indent.sh" to re-indent code; ran it!!!
This commit is contained in:
parent
16336cc854
commit
18f9cad6fe
98 changed files with 5798 additions and 9001 deletions
|
|
@ -60,37 +60,30 @@ int rails_get_group(magic_api * api, int which);
|
|||
char *rails_get_description(magic_api * api, int which, int mode);
|
||||
int rails_requires_colors(magic_api * api, int which);
|
||||
void rails_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
|
||||
void rails_shutdown(magic_api * api);
|
||||
void rails_switchin(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas);
|
||||
void rails_switchout(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas);
|
||||
void rails_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
void rails_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
inline unsigned int rails_get_segment(int x, int y);
|
||||
|
||||
#define POINT_TYPE typeof(((SDL_Rect *)NULL)->x)
|
||||
inline void rails_extract_coords_from_segment(unsigned int segment,
|
||||
POINT_TYPE * x, POINT_TYPE * y);
|
||||
inline void rails_extract_coords_from_segment(unsigned int segment, POINT_TYPE * x, POINT_TYPE * y);
|
||||
static void rails_flip(void *ptr, SDL_Surface * dest, SDL_Surface * src);
|
||||
static void rails_flip_flop(void *ptr, SDL_Surface * dest, SDL_Surface * src);
|
||||
static void rails_rotate(void *ptr, SDL_Surface * dest, SDL_Surface * src,
|
||||
unsigned int direction);
|
||||
static void rails_rotate(void *ptr, SDL_Surface * dest, SDL_Surface * src, unsigned int direction);
|
||||
void rails_click(magic_api * api, int which, int mode, SDL_Surface * canvas,
|
||||
SDL_Surface * snapshot, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
|
||||
static Uint8 rails_select_image(Uint16 segment);
|
||||
static void rails_draw(void *ptr, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int x, int y,
|
||||
unsigned int segment);
|
||||
SDL_Surface * last, int x, int y, unsigned int segment);
|
||||
|
||||
static void rails_draw_wrapper(void *ptr, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int x, int y);
|
||||
static void rails_draw_wrapper(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||
void rails_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
Uint8 rails_accepted_sizes(magic_api * api, int which, int mode);
|
||||
Uint8 rails_default_size(magic_api * api, int which, int mode);
|
||||
void rails_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
|
||||
void rails_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
|
||||
SDL_Rect * update_rect);
|
||||
|
||||
Uint32 rails_api_version(void)
|
||||
{
|
||||
|
|
@ -102,8 +95,10 @@ int rails_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
|||
return (MODE_PAINT);
|
||||
}
|
||||
|
||||
void rails_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
void rails_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED,
|
||||
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -112,19 +107,15 @@ int rails_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
|
|||
char fname[1024];
|
||||
Uint8 i; //is always < 3, so Uint8 seems to be a good idea
|
||||
|
||||
rails_images = (char **) malloc(sizeof(char *) * 4);
|
||||
rails_images = (char **)malloc(sizeof(char *) * 4);
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
rails_images[i] = (char *) malloc(sizeof(char) * 1024);
|
||||
rails_images[i] = (char *)malloc(sizeof(char) * 1024);
|
||||
|
||||
snprintf(rails_images[0], 1024 * sizeof(char),
|
||||
"%simages/magic/rails_one.png", api->data_directory);
|
||||
snprintf(rails_images[1], 1024 * sizeof(char),
|
||||
"%simages/magic/rails_three.png", api->data_directory);
|
||||
snprintf(rails_images[2], 1024 * sizeof(char),
|
||||
"%simages/magic/rails_four.png", api->data_directory);
|
||||
snprintf(rails_images[3], 1024 * sizeof(char),
|
||||
"%simages/magic/rails_corner.png", api->data_directory);
|
||||
snprintf(rails_images[0], 1024 * sizeof(char), "%simages/magic/rails_one.png", api->data_directory);
|
||||
snprintf(rails_images[1], 1024 * sizeof(char), "%simages/magic/rails_three.png", api->data_directory);
|
||||
snprintf(rails_images[2], 1024 * sizeof(char), "%simages/magic/rails_four.png", api->data_directory);
|
||||
snprintf(rails_images[3], 1024 * sizeof(char), "%simages/magic/rails_corner.png", api->data_directory);
|
||||
|
||||
rails_one = IMG_Load(rails_images[0]);
|
||||
rails_three = IMG_Load(rails_images[1]);
|
||||
|
|
@ -134,8 +125,7 @@ int rails_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
|
|||
img_w = rails_one->w;
|
||||
img_h = rails_one->h;
|
||||
|
||||
snprintf(fname, sizeof(fname), "%ssounds/magic/rails.wav",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%ssounds/magic/rails.wav", api->data_directory);
|
||||
rails_snd = Mix_LoadWAV(fname);
|
||||
|
||||
return (1);
|
||||
|
|
@ -150,35 +140,27 @@ SDL_Surface *rails_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
|||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%simages/magic/rails.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%simages/magic/rails.png", api->data_directory);
|
||||
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
char *rails_get_name(magic_api * api ATTRIBUTE_UNUSED,
|
||||
int which ATTRIBUTE_UNUSED)
|
||||
char *rails_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return strdup(gettext_noop("Rails"));
|
||||
}
|
||||
|
||||
int rails_get_group(magic_api * api ATTRIBUTE_UNUSED,
|
||||
int which ATTRIBUTE_UNUSED)
|
||||
int rails_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return MAGIC_TYPE_PAINTING;
|
||||
}
|
||||
|
||||
char *rails_get_description(magic_api * api ATTRIBUTE_UNUSED,
|
||||
int which ATTRIBUTE_UNUSED,
|
||||
int mode ATTRIBUTE_UNUSED)
|
||||
char *rails_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return
|
||||
strdup(gettext_noop
|
||||
("Click and drag to draw train track rails on your picture."));
|
||||
return strdup(gettext_noop("Click and drag to draw train track rails on your picture."));
|
||||
}
|
||||
|
||||
int rails_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
|
||||
int which ATTRIBUTE_UNUSED)
|
||||
int rails_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -187,8 +169,7 @@ void rails_release(magic_api * api ATTRIBUTE_UNUSED,
|
|||
int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * snapshot ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED,
|
||||
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -212,28 +193,24 @@ void rails_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
|||
}
|
||||
|
||||
void rails_switchin(magic_api * api ATTRIBUTE_UNUSED,
|
||||
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas)
|
||||
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas)
|
||||
{
|
||||
//we've to compute the quantity of segments in each direction
|
||||
|
||||
canvas_backup =
|
||||
SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h,
|
||||
canvas->format->BitsPerPixel, canvas->format->Rmask,
|
||||
canvas->format->Gmask, canvas->format->Bmask,
|
||||
canvas->format->Amask);
|
||||
canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
|
||||
|
||||
SDL_BlitSurface(canvas, NULL, canvas_backup, NULL);
|
||||
rails_segments_x = rails_math_ceil(canvas->w, img_w);
|
||||
rails_segments_y = rails_math_ceil(canvas->h, img_h);
|
||||
//status_of_segments[0] will not be used, we write in rails_status_of_segments[1 to segments_x*segments_y]
|
||||
rails_status_of_segments =
|
||||
(Uint8 *) calloc(rails_segments_x * rails_segments_y + 1, sizeof(Uint8));
|
||||
rails_status_of_segments = (Uint8 *) calloc(rails_segments_x * rails_segments_y + 1, sizeof(Uint8));
|
||||
}
|
||||
|
||||
void rails_switchout(magic_api * api ATTRIBUTE_UNUSED,
|
||||
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
if (rails_status_of_segments != NULL)
|
||||
{
|
||||
|
|
@ -248,7 +225,7 @@ inline int rails_math_ceil(int x, int y)
|
|||
{
|
||||
int temp;
|
||||
|
||||
temp = (int) x / y;
|
||||
temp = (int)x / y;
|
||||
|
||||
if (x % y)
|
||||
return temp + 1;
|
||||
|
|
@ -269,11 +246,10 @@ inline unsigned int rails_get_segment(int x, int y)
|
|||
|
||||
}
|
||||
|
||||
inline void rails_extract_coords_from_segment(unsigned int segment,
|
||||
POINT_TYPE * x, POINT_TYPE * y)
|
||||
inline void rails_extract_coords_from_segment(unsigned int segment, POINT_TYPE * x, POINT_TYPE * y)
|
||||
{ //extracts the coords of the beginning and the segment
|
||||
*x = ((segment % rails_segments_x) - 1) * img_w; //useful to set update_rect as small as possible
|
||||
*y = (int) (segment / rails_segments_x) * img_h;
|
||||
*y = (int)(segment / rails_segments_x) * img_h;
|
||||
}
|
||||
|
||||
static void rails_flip(void *ptr, SDL_Surface * dest, SDL_Surface * src)
|
||||
|
|
@ -296,8 +272,7 @@ static void rails_flip_flop(void *ptr, SDL_Surface * dest, SDL_Surface * src)
|
|||
api->putpixel(dest, x, y, api->getpixel(src, y, x));
|
||||
}
|
||||
|
||||
static void rails_rotate(void *ptr, SDL_Surface * dest, SDL_Surface * src,
|
||||
unsigned int direction)
|
||||
static void rails_rotate(void *ptr, SDL_Surface * dest, SDL_Surface * src, unsigned int direction)
|
||||
//src and dest must have same size
|
||||
{
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
|
|
@ -319,8 +294,7 @@ static void rails_rotate(void *ptr, SDL_Surface * dest, SDL_Surface * src,
|
|||
}
|
||||
|
||||
void rails_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
rails_segment_modified_last = 0;
|
||||
rails_drag(api, which, canvas, snapshot, x, y, x, y, update_rect);
|
||||
|
|
@ -331,8 +305,7 @@ static Uint8 rails_select_image(Uint16 segment)
|
|||
int take_up, take_down;
|
||||
int val_up, val_down, val_left, val_right;
|
||||
int from_top = 0, from_bottom = 0, from_left = 0, from_right = 0;
|
||||
int from_top_right = 0, from_top_left = 0, from_bottom_right =
|
||||
0, from_bottom_left = 0;
|
||||
int from_top_right = 0, from_top_left = 0, from_bottom_right = 0, from_bottom_left = 0;
|
||||
int TOP = 0, BOTTOM = 0, LEFT = 0, RIGHT = 0;
|
||||
|
||||
//Checking from were we come...
|
||||
|
|
@ -387,7 +360,7 @@ static Uint8 rails_select_image(Uint16 segment)
|
|||
val_up = rails_status_of_segments[take_up];
|
||||
|
||||
take_down = segment + rails_segments_x;
|
||||
if (take_down > (signed) (rails_segments_x * rails_segments_y))
|
||||
if (take_down > (signed)(rails_segments_x * rails_segments_y))
|
||||
val_down = SEG_NONE;
|
||||
else
|
||||
val_down = rails_status_of_segments[take_down];
|
||||
|
|
@ -446,8 +419,7 @@ static Uint8 rails_select_image(Uint16 segment)
|
|||
|
||||
static void rails_draw(void *ptr, int which ATTRIBUTE_UNUSED,
|
||||
ATTRIBUTE_UNUSED SDL_Surface * canvas,
|
||||
SDL_Surface * last ATTRIBUTE_UNUSED, int x,
|
||||
int y ATTRIBUTE_UNUSED, unsigned int segment)
|
||||
SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y ATTRIBUTE_UNUSED, unsigned int segment)
|
||||
{
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
SDL_Surface *result, *temp;
|
||||
|
|
@ -458,8 +430,7 @@ static void rails_draw(void *ptr, int which ATTRIBUTE_UNUSED,
|
|||
if (segment > rails_segments_x * rails_segments_y)
|
||||
return;
|
||||
//modification_rect.x and modification_rect.y are set by function
|
||||
rails_extract_coords_from_segment(segment, &modification_rect.x,
|
||||
&modification_rect.y);
|
||||
rails_extract_coords_from_segment(segment, &modification_rect.x, &modification_rect.y);
|
||||
modification_rect.h = img_w;
|
||||
modification_rect.w = img_h;
|
||||
|
||||
|
|
@ -553,8 +524,7 @@ static void rails_draw(void *ptr, int which ATTRIBUTE_UNUSED,
|
|||
api->playsound(rails_snd, (x * 255) / canvas->w, 255);
|
||||
}
|
||||
|
||||
static void rails_draw_wrapper(void *ptr, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int x, int y)
|
||||
static void rails_draw_wrapper(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
|
||||
{
|
||||
rails_segment_modified = rails_get_segment(x, y);
|
||||
|
||||
|
|
@ -563,18 +533,15 @@ static void rails_draw_wrapper(void *ptr, int which, SDL_Surface * canvas,
|
|||
return;
|
||||
if (rails_segment_modified > 0)
|
||||
{
|
||||
rails_draw((void *) ptr, which, canvas, last, x, y,
|
||||
rails_segment_modified);
|
||||
rails_draw((void *)ptr, which, canvas, last, x, y, rails_segment_modified);
|
||||
}
|
||||
if (rails_segment_modified_last > 0)
|
||||
rails_draw((void *) ptr, which, canvas, last, x, y,
|
||||
rails_segment_modified_last);
|
||||
rails_draw((void *)ptr, which, canvas, last, x, y, rails_segment_modified_last);
|
||||
|
||||
if (rails_segment_to_add > 0)
|
||||
{
|
||||
rails_draw((void *) ptr, which, canvas, last, x, y, rails_segment_to_add);
|
||||
rails_draw((void *) ptr, which, canvas, last, x, y,
|
||||
rails_segment_modified_last);
|
||||
rails_draw((void *)ptr, which, canvas, last, x, y, rails_segment_to_add);
|
||||
rails_draw((void *)ptr, which, canvas, last, x, y, rails_segment_modified_last);
|
||||
rails_segment_to_add = 0;
|
||||
}
|
||||
if (rails_segment_modified > 0)
|
||||
|
|
@ -582,18 +549,15 @@ static void rails_draw_wrapper(void *ptr, int which, SDL_Surface * canvas,
|
|||
}
|
||||
|
||||
void rails_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
int start_x, end_x, start_y, end_y, segment_start, segment_end, w, h;
|
||||
|
||||
// avoiding to write out of the canvas
|
||||
if ((x < canvas->w) && (y < canvas->h) && (ox < canvas->w)
|
||||
&& (oy < canvas->h) && ((signed) x > 0) && ((signed) y > 0)
|
||||
&& ((signed) ox > 0) && ((signed) oy > 0))
|
||||
&& (oy < canvas->h) && ((signed)x > 0) && ((signed)y > 0) && ((signed)ox > 0) && ((signed)oy > 0))
|
||||
{
|
||||
api->line((void *) api, which, canvas, snapshot, ox, oy, x, y, img_w / 2,
|
||||
rails_draw_wrapper);
|
||||
api->line((void *)api, which, canvas, snapshot, ox, oy, x, y, img_w / 2, rails_draw_wrapper);
|
||||
|
||||
start_x = min(ox, x);
|
||||
end_x = max(ox, x);
|
||||
|
|
@ -604,9 +568,9 @@ void rails_drag(magic_api * api, int which, SDL_Surface * canvas,
|
|||
segment_end = rails_get_segment(end_x + img_w, end_y + img_h);
|
||||
|
||||
x = ((segment_start % rails_segments_x) - 1) * img_w;
|
||||
y = (int) (segment_start / rails_segments_x) * img_h;
|
||||
y = (int)(segment_start / rails_segments_x) * img_h;
|
||||
w = ((segment_end % rails_segments_x) - 1) * img_w - x + img_w;
|
||||
h = (int) (segment_end / rails_segments_x) * img_h - y + img_h;
|
||||
h = (int)(segment_end / rails_segments_x) * img_h - y + img_h;
|
||||
|
||||
update_rect->x = x;
|
||||
update_rect->y = y;
|
||||
|
|
@ -627,6 +591,8 @@ Uint8 rails_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_U
|
|||
return 0;
|
||||
}
|
||||
|
||||
void rails_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
void rails_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue