indent bricks.c
This commit is contained in:
parent
6ccb464ab8
commit
1ee28d1abd
1 changed files with 114 additions and 117 deletions
|
|
@ -38,7 +38,8 @@
|
|||
|
||||
/* What tools we contain: */
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
TOOL_LARGEBRICKS,
|
||||
TOOL_SMALLBRICKS,
|
||||
NUM_TOOLS
|
||||
|
|
@ -53,8 +54,7 @@ static Uint8 bricks_r, bricks_g, bricks_b;
|
|||
|
||||
/* Local function prototype: */
|
||||
|
||||
static void do_brick(magic_api * api, SDL_Surface * canvas,
|
||||
int x, int y, int w, int h);
|
||||
static void do_brick(magic_api * api, SDL_Surface * canvas, int x, int y, int w, int h);
|
||||
int bricks_init(magic_api * api);
|
||||
Uint32 bricks_api_version(void);
|
||||
int bricks_get_tool_count(magic_api * api);
|
||||
|
|
@ -62,14 +62,10 @@ SDL_Surface * bricks_get_icon(magic_api * api, int which);
|
|||
char *bricks_get_name(magic_api * api, int which);
|
||||
char *bricks_get_description(magic_api * api, int which, int mode);
|
||||
void bricks_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
void bricks_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect);
|
||||
void bricks_release(magic_api * api, int which,
|
||||
SDL_Surface * canvas, SDL_Surface * last,
|
||||
int x, int y, SDL_Rect * update_rect); //An empty function. Is there a purpose to this? Ask moderator.
|
||||
SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
|
||||
void bricks_release(magic_api * api, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect); //An empty function. Is there a purpose to this? Ask moderator.
|
||||
void bricks_shutdown(magic_api * api);
|
||||
void bricks_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
int bricks_requires_colors(magic_api * api, int which);
|
||||
|
|
@ -82,14 +78,16 @@ int bricks_init(magic_api * api)
|
|||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/brick.wav",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/brick.wav", api->data_directory);
|
||||
brick_snd = Mix_LoadWAV(fname);
|
||||
|
||||
return (1);
|
||||
}
|
||||
|
||||
Uint32 bricks_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
Uint32 bricks_api_version(void)
|
||||
{
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
// We have multiple tools:
|
||||
int bricks_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
|
|
@ -104,13 +102,11 @@ SDL_Surface * bricks_get_icon(magic_api * api, int which)
|
|||
|
||||
if (which == TOOL_LARGEBRICKS)
|
||||
{
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/largebrick.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/largebrick.png", api->data_directory);
|
||||
}
|
||||
else if (which == TOOL_SMALLBRICKS)
|
||||
{
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/smallbrick.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/smallbrick.png", api->data_directory);
|
||||
}
|
||||
|
||||
return (IMG_Load(fname));
|
||||
|
|
@ -137,8 +133,7 @@ char * bricks_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int m
|
|||
|
||||
// Do the effect:
|
||||
|
||||
static void do_bricks(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
int x, int y)
|
||||
static void do_bricks(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
|
||||
{
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
|
||||
|
|
@ -185,11 +180,11 @@ static void do_bricks(void * ptr, int which, SDL_Surface * canvas, SDL_Surface *
|
|||
|
||||
mybrick = map + brick_x + 1 + (brick_y + 1) * x_count;
|
||||
|
||||
if ((unsigned) x < (unsigned) canvas->w
|
||||
&& (unsigned) y < (unsigned) canvas->h && !*mybrick)
|
||||
if ((unsigned)x < (unsigned)canvas->w && (unsigned)y < (unsigned)canvas->h && !*mybrick)
|
||||
{
|
||||
int my_x = brick_x * nominal_width;
|
||||
int my_w = specified_width;
|
||||
|
||||
*mybrick = 1;
|
||||
|
||||
|
||||
|
|
@ -206,8 +201,7 @@ static void do_bricks(void * ptr, int which, SDL_Surface * canvas, SDL_Surface *
|
|||
my_x -= nominal_width;
|
||||
my_w = specified_length;
|
||||
}
|
||||
do_brick(api, canvas, my_x, brick_y * nominal_height,
|
||||
my_w, specified_height);
|
||||
do_brick(api, canvas, my_x, brick_y * nominal_height, my_w, specified_height);
|
||||
|
||||
|
||||
// FIXME:
|
||||
|
|
@ -227,13 +221,24 @@ static void do_bricks(void * ptr, int which, SDL_Surface * canvas, SDL_Surface *
|
|||
|
||||
// Affect the canvas on drag:
|
||||
void bricks_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, do_bricks);
|
||||
|
||||
if (ox > x) { int tmp = ox; ox = x; x = tmp; }
|
||||
if (oy > y) { int tmp = oy; oy = y; y = tmp; }
|
||||
if (ox > x)
|
||||
{
|
||||
int tmp = ox;
|
||||
|
||||
ox = x;
|
||||
x = tmp;
|
||||
}
|
||||
if (oy > y)
|
||||
{
|
||||
int tmp = oy;
|
||||
|
||||
oy = y;
|
||||
y = tmp;
|
||||
}
|
||||
|
||||
update_rect->x = x - 64;
|
||||
update_rect->y = y - 64;
|
||||
|
|
@ -245,8 +250,7 @@ void bricks_drag(magic_api * api, int which, SDL_Surface * canvas,
|
|||
|
||||
// Affect the canvas on click:
|
||||
void bricks_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)
|
||||
{
|
||||
bricks_drag(api, which, canvas, last, x, y, x, y, update_rect);
|
||||
}
|
||||
|
|
@ -278,23 +282,16 @@ int bricks_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE
|
|||
return 1;
|
||||
}
|
||||
|
||||
static void do_brick(magic_api * api, SDL_Surface * canvas,
|
||||
int x, int y, int w, int h)
|
||||
static void do_brick(magic_api * api, SDL_Surface * canvas, int x, int y, int w, int h)
|
||||
{
|
||||
SDL_Rect dest;
|
||||
|
||||
// brick color: 127,76,73
|
||||
double ran_r = rand() / (double)RAND_MAX;
|
||||
double ran_g = rand() / (double)RAND_MAX;
|
||||
double base_r =
|
||||
api->sRGB_to_linear(bricks_r) * 1.5 +
|
||||
api->sRGB_to_linear(127) * 5.0 + ran_r;
|
||||
double base_g =
|
||||
api->sRGB_to_linear(bricks_g) * 1.5 +
|
||||
api->sRGB_to_linear(76) * 5.0 + ran_g;
|
||||
double base_b =
|
||||
api->sRGB_to_linear(bricks_b) * 1.5 +
|
||||
api->sRGB_to_linear(73) * 5.0 + (ran_r + ran_g * 2.0) / 3.0;
|
||||
double base_r = api->sRGB_to_linear(bricks_r) * 1.5 + api->sRGB_to_linear(127) * 5.0 + ran_r;
|
||||
double base_g = api->sRGB_to_linear(bricks_g) * 1.5 + api->sRGB_to_linear(76) * 5.0 + ran_g;
|
||||
double base_b = api->sRGB_to_linear(bricks_b) * 1.5 + api->sRGB_to_linear(73) * 5.0 + (ran_r + ran_g * 2.0) / 3.0;
|
||||
|
||||
Uint8 r = api->linear_to_sRGB(base_r / 7.5);
|
||||
Uint8 g = api->linear_to_sRGB(base_g / 7.5);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue