indent puzzle.c
This commit is contained in:
parent
04580641df
commit
6a89ec2384
1 changed files with 111 additions and 109 deletions
|
|
@ -42,6 +42,7 @@
|
||||||
|
|
||||||
static Mix_Chunk *puzzle_snd;
|
static Mix_Chunk *puzzle_snd;
|
||||||
static int puzzle_gcd = 0; //length of side of each rectangle; 0 is temporary value.
|
static int puzzle_gcd = 0; //length of side of each rectangle; 0 is temporary value.
|
||||||
|
|
||||||
// static int puzzle_rect_q=4; //quantity of rectangles when using paint mode. Must be an odd value - but it's even!
|
// static int puzzle_rect_q=4; //quantity of rectangles when using paint mode. Must be an odd value - but it's even!
|
||||||
static int rects_w, rects_h;
|
static int rects_w, rects_h;
|
||||||
SDL_Surface *canvas_backup;
|
SDL_Surface *canvas_backup;
|
||||||
|
|
@ -53,33 +54,31 @@ SDL_Surface * puzzle_get_icon(magic_api * api, int which);
|
||||||
char *puzzle_get_name(magic_api * api, int which);
|
char *puzzle_get_name(magic_api * api, int which);
|
||||||
char *puzzle_get_description(magic_api * api, int which, int mode);
|
char *puzzle_get_description(magic_api * api, int which, int mode);
|
||||||
void puzzle_release(magic_api * api, int which,
|
void puzzle_release(magic_api * api, int which,
|
||||||
SDL_Surface * canvas, SDL_Surface * last,
|
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||||
int x, int y, SDL_Rect * update_rect);
|
|
||||||
void puzzle_shutdown(magic_api * api);
|
void puzzle_shutdown(magic_api * api);
|
||||||
void puzzle_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
void puzzle_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||||
int puzzle_requires_colors(magic_api * api, int which);
|
int puzzle_requires_colors(magic_api * api, int which);
|
||||||
void puzzle_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
void puzzle_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||||
void puzzle_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
void puzzle_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||||
int puzzle_modes(magic_api * api, int which);
|
int puzzle_modes(magic_api * api, int which);
|
||||||
static void puzzle_draw(void * ptr, int which_tool,
|
static void puzzle_draw(void *ptr, int which_tool, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
|
||||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
|
|
||||||
void puzzle_drag(magic_api * api, int which, SDL_Surface * canvas,
|
void puzzle_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||||
SDL_Rect * update_rect);
|
|
||||||
|
|
||||||
void puzzle_click(magic_api * api, int which, int mode,
|
void puzzle_click(magic_api * api, int which, int mode,
|
||||||
SDL_Surface * canvas, SDL_Surface * last,
|
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||||
int x, int y, SDL_Rect * update_rect);
|
|
||||||
int gcd(int a, int b);
|
int gcd(int a, int b);
|
||||||
|
|
||||||
Uint32 puzzle_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
Uint32 puzzle_api_version(void)
|
||||||
|
{
|
||||||
|
return (TP_MAGIC_API_VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
int puzzle_init(magic_api * api)
|
int puzzle_init(magic_api * api)
|
||||||
{
|
{
|
||||||
char fname[1024];
|
char fname[1024];
|
||||||
|
|
||||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/puzzle.wav",
|
snprintf(fname, sizeof(fname), "%s/sounds/magic/puzzle.wav", api->data_directory);
|
||||||
api->data_directory);
|
|
||||||
puzzle_snd = Mix_LoadWAV(fname);
|
puzzle_snd = Mix_LoadWAV(fname);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
@ -94,8 +93,7 @@ SDL_Surface * puzzle_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
char fname[1024];
|
char fname[1024];
|
||||||
|
|
||||||
snprintf(fname, sizeof(fname), "%s/images/magic/puzzle.png",
|
snprintf(fname, sizeof(fname), "%s/images/magic/puzzle.png", api->data_directory);
|
||||||
api->data_directory);
|
|
||||||
|
|
||||||
return (IMG_Load(fname));
|
return (IMG_Load(fname));
|
||||||
}
|
}
|
||||||
|
|
@ -125,7 +123,8 @@ void puzzle_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
||||||
Mix_FreeChunk(puzzle_snd);
|
Mix_FreeChunk(puzzle_snd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void puzzle_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
|
void puzzle_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
|
||||||
|
Uint8 b ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -136,19 +135,24 @@ int puzzle_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE
|
||||||
|
|
||||||
int gcd(int a, int b) //greatest common divisor
|
int gcd(int a, int b) //greatest common divisor
|
||||||
{
|
{
|
||||||
if (b==0) return a;
|
if (b == 0)
|
||||||
|
return a;
|
||||||
return gcd(b, a % b);
|
return gcd(b, a % b);
|
||||||
}
|
}
|
||||||
|
|
||||||
void puzzle_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas)
|
void puzzle_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||||
|
SDL_Surface * canvas)
|
||||||
{
|
{
|
||||||
puzzle_gcd = RATIO * gcd(canvas->w, canvas->h);
|
puzzle_gcd = RATIO * gcd(canvas->w, canvas->h);
|
||||||
rects_w = (unsigned int)canvas->w / puzzle_gcd;
|
rects_w = (unsigned int)canvas->w / puzzle_gcd;
|
||||||
rects_h = (unsigned int)canvas->h / puzzle_gcd;
|
rects_h = (unsigned int)canvas->h / puzzle_gcd;
|
||||||
canvas_backup = SDL_CreateRGBSurface(SDL_ANYFORMAT,canvas->w, canvas->h, canvas->format->BitsPerPixel, canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
|
canvas_backup =
|
||||||
|
SDL_CreateRGBSurface(SDL_ANYFORMAT, canvas->w, canvas->h, canvas->format->BitsPerPixel, canvas->format->Rmask,
|
||||||
|
canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
|
||||||
}
|
}
|
||||||
|
|
||||||
void puzzle_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
void puzzle_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||||
|
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
SDL_FreeSurface(canvas_backup);
|
SDL_FreeSurface(canvas_backup);
|
||||||
canvas_backup = NULL;
|
canvas_backup = NULL;
|
||||||
|
|
@ -236,9 +240,7 @@ void puzzle_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||||
}
|
}
|
||||||
|
|
||||||
void puzzle_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
|
void puzzle_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
|
||||||
SDL_Surface * canvas, SDL_Surface * last,
|
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
|
||||||
int x, int y, SDL_Rect * update_rect)
|
|
||||||
{
|
{
|
||||||
puzzle_drag(api, which, canvas, last, x, y, x, y, update_rect);
|
puzzle_drag(api, which, canvas, last, x, y, x, y, update_rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue