indent flower.c
This commit is contained in:
parent
b11972979c
commit
8eff6a9930
1 changed files with 233 additions and 253 deletions
|
|
@ -36,19 +36,21 @@
|
|||
|
||||
/* Our globals: */
|
||||
|
||||
enum { SIDE_LEFT, SIDE_RIGHT };
|
||||
enum { LEAFSIDE_RIGHT_DOWN,
|
||||
enum
|
||||
{ SIDE_LEFT, SIDE_RIGHT };
|
||||
enum
|
||||
{ LEAFSIDE_RIGHT_DOWN,
|
||||
LEAFSIDE_LEFT_DOWN,
|
||||
LEAFSIDE_RIGHT_UP,
|
||||
LEAFSIDE_LEFT_UP };
|
||||
LEAFSIDE_LEFT_UP
|
||||
};
|
||||
|
||||
static Mix_Chunk *flower_click_snd, *flower_release_snd;
|
||||
static Uint8 flower_r, flower_g, flower_b;
|
||||
static int flower_min_x, flower_max_x, flower_bottom_x, flower_bottom_y;
|
||||
static int flower_side_first;
|
||||
static int flower_side_decided;
|
||||
static SDL_Surface * flower_base, * flower_leaf, * flower_petals,
|
||||
* flower_petals_colorized;
|
||||
static SDL_Surface *flower_base, *flower_leaf, *flower_petals, *flower_petals_colorized;
|
||||
|
||||
/* Local function prototypes: */
|
||||
|
||||
|
|
@ -68,22 +70,17 @@ int flower_get_tool_count(magic_api * api);
|
|||
SDL_Surface *flower_get_icon(magic_api * api, int which);
|
||||
char *flower_get_name(magic_api * api, int which);
|
||||
char *flower_get_description(magic_api * api, int which, int mode);
|
||||
static void flower_predrag(magic_api * api, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox, int oy, int x, int y);
|
||||
static void flower_predrag(magic_api * api, SDL_Surface * canvas, SDL_Surface * last, int ox, int oy, int x, int y);
|
||||
void flower_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 flower_click(magic_api * api, int which, int mode,
|
||||
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);
|
||||
void flower_release(magic_api * api, int which,
|
||||
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);
|
||||
static void flower_drawflower(magic_api * api, SDL_Surface * canvas, int x, int y);
|
||||
static void flower_drawbase(magic_api * api, SDL_Surface * canvas);
|
||||
static void flower_drawstalk(magic_api * api, SDL_Surface * canvas,
|
||||
int top_x, int top_y, int minx, int maxx,
|
||||
int bottom_x, int bottom_y, int final);
|
||||
int top_x, int top_y, int minx, int maxx, int bottom_x, int bottom_y, int final);
|
||||
void flower_shutdown(magic_api * api);
|
||||
void flower_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||
int flower_requires_colors(magic_api * api, int which);
|
||||
|
|
@ -96,7 +93,10 @@ int flower_modes(magic_api * api, int which);
|
|||
|
||||
|
||||
|
||||
Uint32 flower_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
Uint32 flower_api_version(void)
|
||||
{
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
|
||||
// No setup required:
|
||||
|
|
@ -104,24 +104,19 @@ int flower_init(magic_api * api)
|
|||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/flower_click.ogg",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/flower_click.ogg", api->data_directory);
|
||||
flower_click_snd = Mix_LoadWAV(fname);
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/flower_release.ogg",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/flower_release.ogg", api->data_directory);
|
||||
flower_release_snd = Mix_LoadWAV(fname);
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/flower_base.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/flower_base.png", api->data_directory);
|
||||
flower_base = IMG_Load(fname);
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/flower_leaf.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/flower_leaf.png", api->data_directory);
|
||||
flower_leaf = IMG_Load(fname);
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/flower_petals.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/flower_petals.png", api->data_directory);
|
||||
flower_petals = IMG_Load(fname);
|
||||
|
||||
return (1);
|
||||
|
|
@ -138,8 +133,7 @@ SDL_Surface * flower_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
|||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/flower.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%s/images/magic/flower.png", api->data_directory);
|
||||
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
|
@ -192,8 +186,7 @@ static void flower_predrag(magic_api * api ATTRIBUTE_UNUSED, SDL_Surface * canva
|
|||
}
|
||||
|
||||
void flower_drag(magic_api * api, int which ATTRIBUTE_UNUSED, 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)
|
||||
{
|
||||
flower_predrag(api, canvas, last, ox, oy, x, y);
|
||||
|
||||
|
|
@ -206,8 +199,7 @@ void flower_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface * canv
|
|||
/* Draw the base and the stalk (low-quality) for now: */
|
||||
|
||||
flower_drawstalk(api, canvas,
|
||||
x, y, flower_min_x, flower_max_x,
|
||||
flower_bottom_x, flower_bottom_y, !(api->button_down()));
|
||||
x, y, flower_min_x, flower_max_x, flower_bottom_x, flower_bottom_y, !(api->button_down()));
|
||||
|
||||
flower_drawbase(api, canvas);
|
||||
|
||||
|
|
@ -219,8 +211,7 @@ void flower_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface * canv
|
|||
|
||||
// Affect the canvas on click:
|
||||
void flower_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)
|
||||
{
|
||||
flower_min_x = x;
|
||||
flower_max_x = x;
|
||||
|
|
@ -237,8 +228,7 @@ void flower_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
|
|||
|
||||
// Affect the canvas on release:
|
||||
void flower_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)
|
||||
{
|
||||
/* Don't let flower be too low compared to base: */
|
||||
|
||||
|
|
@ -258,9 +248,7 @@ void flower_release(magic_api * api, int which ATTRIBUTE_UNUSED,
|
|||
|
||||
/* Draw high-quality stalk, and flower: */
|
||||
|
||||
flower_drawstalk(api, canvas,
|
||||
x, y, flower_min_x, flower_max_x,
|
||||
flower_bottom_x, flower_bottom_y, 1);
|
||||
flower_drawstalk(api, canvas, x, y, flower_min_x, flower_max_x, flower_bottom_x, flower_bottom_y, 1);
|
||||
|
||||
flower_drawflower(api, canvas, x, y);
|
||||
|
||||
|
|
@ -297,8 +285,7 @@ static void flower_drawbase(magic_api * api ATTRIBUTE_UNUSED, SDL_Surface * canv
|
|||
}
|
||||
|
||||
static void flower_drawstalk(magic_api * api ATTRIBUTE_UNUSED, SDL_Surface * canvas,
|
||||
int top_x, int top_y, int minx, int maxx,
|
||||
int bottom_x, int bottom_y, int final)
|
||||
int top_x, int top_y, int minx, int maxx, int bottom_x, int bottom_y, int final)
|
||||
{
|
||||
Point2D control_points[4];
|
||||
Point2D *curve;
|
||||
|
|
@ -368,8 +355,7 @@ static void flower_drawstalk(magic_api * api ATTRIBUTE_UNUSED, SDL_Surface * can
|
|||
|
||||
/* When we're done (final render), we can add some random leaves: */
|
||||
|
||||
if (final && i > 32 && i < n_points - 32 && (i % 16) == 0 &&
|
||||
(rand() % 5) > 0)
|
||||
if (final && i > 32 && i < n_points - 32 && (i % 16) == 0 && (rand() % 5) > 0)
|
||||
{
|
||||
/* Check for hard left/right angles: */
|
||||
|
||||
|
|
@ -576,9 +562,7 @@ static void flower_colorize_petals(magic_api * api)
|
|||
|
||||
/* Create a surface to render into: */
|
||||
|
||||
amask = ~(flower_petals->format->Rmask |
|
||||
flower_petals->format->Gmask |
|
||||
flower_petals->format->Bmask);
|
||||
amask = ~(flower_petals->format->Rmask | flower_petals->format->Gmask | flower_petals->format->Bmask);
|
||||
|
||||
flower_petals_colorized =
|
||||
SDL_CreateRGBSurface(SDL_SWSURFACE,
|
||||
|
|
@ -586,8 +570,7 @@ static void flower_colorize_petals(magic_api * api)
|
|||
flower_petals->h,
|
||||
flower_petals->format->BitsPerPixel,
|
||||
flower_petals->format->Rmask,
|
||||
flower_petals->format->Gmask,
|
||||
flower_petals->format->Bmask, amask);
|
||||
flower_petals->format->Gmask, flower_petals->format->Bmask, amask);
|
||||
|
||||
/* Render the new petals: */
|
||||
|
||||
|
|
@ -598,20 +581,15 @@ static void flower_colorize_petals(magic_api * api)
|
|||
{
|
||||
for (x = 0; x < flower_petals->w; x++)
|
||||
{
|
||||
SDL_GetRGBA(api->getpixel(flower_petals, x, y),
|
||||
flower_petals->format, &r, &g, &b, &a);
|
||||
SDL_GetRGBA(api->getpixel(flower_petals, x, y), flower_petals->format, &r, &g, &b, &a);
|
||||
|
||||
api->putpixel(flower_petals_colorized, x, y,
|
||||
SDL_MapRGBA(flower_petals_colorized->format,
|
||||
flower_r, flower_g, flower_b, a));
|
||||
SDL_MapRGBA(flower_petals_colorized->format, flower_r, flower_g, flower_b, a));
|
||||
|
||||
if (api->in_circle((x - flower_petals->w / 2),
|
||||
(y - flower_petals->h / 2),
|
||||
8))
|
||||
if (api->in_circle((x - flower_petals->w / 2), (y - flower_petals->h / 2), 8))
|
||||
{
|
||||
api->putpixel(flower_petals_colorized, x, y,
|
||||
SDL_MapRGBA(flower_petals_colorized->format,
|
||||
0xFF, 0xFF, 0x00, a));
|
||||
SDL_MapRGBA(flower_petals_colorized->format, 0xFF, 0xFF, 0x00, a));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -620,11 +598,13 @@ static void flower_colorize_petals(magic_api * api)
|
|||
SDL_UnlockSurface(flower_petals);
|
||||
}
|
||||
|
||||
void flower_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void flower_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
void flower_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void flower_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue