indent blind.c
This commit is contained in:
parent
d62e1ec901
commit
5b76d99ae6
1 changed files with 127 additions and 117 deletions
|
|
@ -33,54 +33,54 @@
|
||||||
int BLIND_RADIUS = 16;
|
int BLIND_RADIUS = 16;
|
||||||
int BLIND_OPAQUE = 20;
|
int BLIND_OPAQUE = 20;
|
||||||
int BLIND_THICKNESS = 30;
|
int BLIND_THICKNESS = 30;
|
||||||
int blind_side; /* 0 top, 1 left, 2 bottom, 3 right */
|
int blind_side; /* 0 top, 1 left, 2 bottom, 3 right */
|
||||||
|
|
||||||
static Uint8 blind_r, blind_g, blind_b, blind_light;
|
static Uint8 blind_r, blind_g, blind_b, blind_light;
|
||||||
enum blind_sides{
|
enum blind_sides
|
||||||
|
{
|
||||||
BLIND_SIDE_TOP,
|
BLIND_SIDE_TOP,
|
||||||
BLIND_SIDE_LEFT,
|
BLIND_SIDE_LEFT,
|
||||||
BLIND_SIDE_BOTTOM,
|
BLIND_SIDE_BOTTOM,
|
||||||
BLIND_SIDE_RIGHT};
|
BLIND_SIDE_RIGHT
|
||||||
|
};
|
||||||
|
|
||||||
enum blind_tools{
|
enum blind_tools
|
||||||
|
{
|
||||||
BLIND_TOOL_BLIND,
|
BLIND_TOOL_BLIND,
|
||||||
BLIND_NUMTOOLS};
|
BLIND_NUMTOOLS
|
||||||
|
};
|
||||||
|
|
||||||
Mix_Chunk * blind_snd;
|
Mix_Chunk *blind_snd;
|
||||||
|
|
||||||
// Prototypes
|
// Prototypes
|
||||||
Uint32 blind_api_version(void);
|
Uint32 blind_api_version(void);
|
||||||
void blind_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
void blind_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||||
int blind_init(magic_api * api);
|
int blind_init(magic_api * api);
|
||||||
int blind_get_tool_count(magic_api * api);
|
int blind_get_tool_count(magic_api * api);
|
||||||
SDL_Surface * blind_get_icon(magic_api * api, int which);
|
SDL_Surface *blind_get_icon(magic_api * api, int which);
|
||||||
char * blind_get_name(magic_api * api, int which);
|
char *blind_get_name(magic_api * api, int which);
|
||||||
char * blind_get_description(magic_api * api, int which, int mode);
|
char *blind_get_description(magic_api * api, int which, int mode);
|
||||||
int blind_requires_colors(magic_api * api, int which);
|
int blind_requires_colors(magic_api * api, int which);
|
||||||
void blind_release(magic_api * api, int which,
|
void blind_release(magic_api * api, int which,
|
||||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
|
||||||
int x, int y, SDL_Rect * update_rect);
|
|
||||||
void blind_shutdown(magic_api * api);
|
void blind_shutdown(magic_api * api);
|
||||||
void blind_paint_blind(void * ptr_to_api, int which_tool,
|
void blind_paint_blind(void *ptr_to_api, int which_tool, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
|
||||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
|
|
||||||
void blind_drag(magic_api * api, int which, SDL_Surface * canvas,
|
void blind_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||||
SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||||
SDL_Rect * update_rect);
|
|
||||||
void blind_click(magic_api * api, int which, int mode,
|
void blind_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);
|
|
||||||
void blind_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
void blind_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||||
void blind_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
void blind_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||||
int blind_modes(magic_api * api, int which);
|
int blind_modes(magic_api * api, int which);
|
||||||
|
|
||||||
// Housekeeping functions
|
// Housekeeping functions
|
||||||
|
|
||||||
Uint32 blind_api_version(void)
|
Uint32 blind_api_version(void)
|
||||||
{
|
{
|
||||||
return(TP_MAGIC_API_VERSION);
|
return (TP_MAGIC_API_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
void blind_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b) //get the colors from API and store it in structure
|
void blind_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b) //get the colors from API and store it in structure
|
||||||
{
|
{
|
||||||
blind_r = r;
|
blind_r = r;
|
||||||
blind_g = g;
|
blind_g = g;
|
||||||
|
|
@ -91,10 +91,10 @@ int blind_init(magic_api * api)
|
||||||
{
|
{
|
||||||
char fname[1024];
|
char fname[1024];
|
||||||
|
|
||||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/blind.ogg", api->data_directory);
|
snprintf(fname, sizeof(fname), "%s/sounds/magic/blind.ogg", api->data_directory);
|
||||||
blind_snd = Mix_LoadWAV(fname);
|
blind_snd = Mix_LoadWAV(fname);
|
||||||
|
|
||||||
return(1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int blind_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
int blind_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||||
|
|
@ -102,24 +102,25 @@ int blind_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||||
return BLIND_NUMTOOLS;
|
return BLIND_NUMTOOLS;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Surface * blind_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
SDL_Surface *blind_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
char fname[1024];
|
char fname[1024];
|
||||||
|
|
||||||
snprintf(fname, sizeof(fname), "%s/images/magic/blind.png",
|
snprintf(fname, sizeof(fname), "%s/images/magic/blind.png", api->data_directory);
|
||||||
api->data_directory);
|
|
||||||
|
|
||||||
return(IMG_Load(fname));
|
return (IMG_Load(fname));
|
||||||
}
|
}
|
||||||
|
|
||||||
char * blind_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
char *blind_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
return strdup(gettext_noop("Blind"));
|
return strdup(gettext_noop("Blind"));
|
||||||
}
|
}
|
||||||
|
|
||||||
char * blind_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
char *blind_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
return strdup(gettext_noop("Click towards the edge of your picture to pull window blinds over it. Move perpendicularly to open or close the blinds."));
|
return
|
||||||
|
strdup(gettext_noop
|
||||||
|
("Click towards the edge of your picture to pull window blinds over it. Move perpendicularly to open or close the blinds."));
|
||||||
}
|
}
|
||||||
|
|
||||||
int blind_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
int blind_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||||
|
|
@ -128,24 +129,26 @@ int blind_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_
|
||||||
}
|
}
|
||||||
|
|
||||||
void blind_release(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
|
void blind_release(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
|
||||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * snapshot 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)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void blind_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
void blind_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
Mix_FreeChunk(blind_snd);
|
Mix_FreeChunk(blind_snd);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Interactivity functions
|
// Interactivity functions
|
||||||
|
|
||||||
void blind_paint_blind(void * ptr_to_api, int which_tool ATTRIBUTE_UNUSED,
|
void blind_paint_blind(void *ptr_to_api, int which_tool ATTRIBUTE_UNUSED,
|
||||||
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
|
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
|
||||||
{
|
{
|
||||||
magic_api * api = (magic_api *) ptr_to_api;
|
magic_api *api = (magic_api *) ptr_to_api;
|
||||||
|
|
||||||
api->putpixel(canvas, x, y, SDL_MapRGB(canvas->format, (blind_r + blind_light) / 2, (blind_g + blind_light) / 2, (blind_b + blind_light) / 2));
|
api->putpixel(canvas, x, y,
|
||||||
|
SDL_MapRGB(canvas->format, (blind_r + blind_light) / 2, (blind_g + blind_light) / 2,
|
||||||
|
(blind_b + blind_light) / 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* void blind_do_blind(void * ptr_to_api, int which_tool,
|
/* void blind_do_blind(void * ptr_to_api, int which_tool,
|
||||||
|
|
@ -159,31 +162,31 @@ void blind_paint_blind(void * ptr_to_api, int which_tool ATTRIBUTE_UNUSED,
|
||||||
|
|
||||||
*/
|
*/
|
||||||
void blind_drag(magic_api * api, int which, SDL_Surface * canvas,
|
void blind_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||||
SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect)
|
||||||
SDL_Rect * update_rect)
|
|
||||||
{
|
{
|
||||||
int opaque;
|
int opaque;
|
||||||
|
|
||||||
SDL_BlitSurface(snapshot, NULL, canvas, NULL);
|
SDL_BlitSurface(snapshot, NULL, canvas, NULL);
|
||||||
switch (blind_side)
|
switch (blind_side)
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
case BLIND_SIDE_TOP:
|
case BLIND_SIDE_TOP:
|
||||||
opaque = max((x * BLIND_THICKNESS) / canvas->w + 2, 2);
|
opaque = max((x * BLIND_THICKNESS) / canvas->w + 2, 2);
|
||||||
for (i = y;i >= 0; i -= BLIND_THICKNESS)
|
for (i = y; i >= 0; i -= BLIND_THICKNESS)
|
||||||
{
|
{
|
||||||
blind_light = 255;
|
blind_light = 255;
|
||||||
for (j=i; j > i - opaque/2; j--)
|
for (j = i; j > i - opaque / 2; j--)
|
||||||
{
|
{
|
||||||
api->line(api, which, canvas, snapshot, 0, j, canvas->w, j, 1, blind_paint_blind);
|
api->line(api, which, canvas, snapshot, 0, j, canvas->w, j, 1, blind_paint_blind);
|
||||||
blind_light -=20;
|
blind_light -= 20;
|
||||||
}
|
}
|
||||||
for (j = i - opaque/2; j > i - opaque; j--)
|
for (j = i - opaque / 2; j > i - opaque; j--)
|
||||||
{
|
{
|
||||||
api->line(api, which, canvas, snapshot, 0, j, canvas->w, j, 1, blind_paint_blind);
|
api->line(api, which, canvas, snapshot, 0, j, canvas->w, j, 1, blind_paint_blind);
|
||||||
blind_light +=20;
|
blind_light += 20;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
update_rect->x = 0;
|
update_rect->x = 0;
|
||||||
update_rect->y = 0;
|
update_rect->y = 0;
|
||||||
update_rect->w = canvas->w;
|
update_rect->w = canvas->w;
|
||||||
|
|
@ -194,19 +197,19 @@ void blind_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||||
case BLIND_SIDE_BOTTOM:
|
case BLIND_SIDE_BOTTOM:
|
||||||
opaque = max((x * BLIND_THICKNESS) / canvas->w + 2, 2);
|
opaque = max((x * BLIND_THICKNESS) / canvas->w + 2, 2);
|
||||||
for (i = y; i <= canvas->h; i += BLIND_THICKNESS)
|
for (i = y; i <= canvas->h; i += BLIND_THICKNESS)
|
||||||
{
|
{
|
||||||
blind_light = 255;
|
blind_light = 255;
|
||||||
for (j = i; j < i + opaque / 2; j++)
|
for (j = i; j < i + opaque / 2; j++)
|
||||||
{
|
{
|
||||||
api->line(api, which, canvas, snapshot, 0, j, canvas->w, j, 1, blind_paint_blind);
|
api->line(api, which, canvas, snapshot, 0, j, canvas->w, j, 1, blind_paint_blind);
|
||||||
blind_light -= 20;
|
blind_light -= 20;
|
||||||
}
|
}
|
||||||
for (j = i + opaque / 2; j < i + opaque; j ++)
|
for (j = i + opaque / 2; j < i + opaque; j++)
|
||||||
{
|
{
|
||||||
api->line(api, which, canvas, snapshot, 0, j, canvas->w, j, 1, blind_paint_blind);
|
api->line(api, which, canvas, snapshot, 0, j, canvas->w, j, 1, blind_paint_blind);
|
||||||
blind_light += 20;
|
blind_light += 20;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
update_rect->x = 0;
|
update_rect->x = 0;
|
||||||
update_rect->y = min(oy, y);
|
update_rect->y = min(oy, y);
|
||||||
|
|
@ -218,19 +221,19 @@ void blind_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||||
case BLIND_SIDE_RIGHT:
|
case BLIND_SIDE_RIGHT:
|
||||||
opaque = max((y * BLIND_THICKNESS) / canvas->h + 2, 2);
|
opaque = max((y * BLIND_THICKNESS) / canvas->h + 2, 2);
|
||||||
for (i = x; i <= canvas->w; i += BLIND_THICKNESS)
|
for (i = x; i <= canvas->w; i += BLIND_THICKNESS)
|
||||||
{
|
{
|
||||||
blind_light = 255;
|
blind_light = 255;
|
||||||
for (j = i; j < i + opaque / 2; j++)
|
for (j = i; j < i + opaque / 2; j++)
|
||||||
{
|
{
|
||||||
api->line(api, which, canvas, snapshot, j, 0, j, canvas->h, 1, blind_paint_blind);
|
api->line(api, which, canvas, snapshot, j, 0, j, canvas->h, 1, blind_paint_blind);
|
||||||
blind_light -= 20;
|
blind_light -= 20;
|
||||||
}
|
}
|
||||||
for (j = i + opaque / 2; j < i + opaque; j ++)
|
for (j = i + opaque / 2; j < i + opaque; j++)
|
||||||
{
|
{
|
||||||
api->line(api, which, canvas, snapshot, j, 0, j, canvas->h, 1, blind_paint_blind);
|
api->line(api, which, canvas, snapshot, j, 0, j, canvas->h, 1, blind_paint_blind);
|
||||||
blind_light += 20;
|
blind_light += 20;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
update_rect->x = min(ox, x);
|
update_rect->x = min(ox, x);
|
||||||
update_rect->y = 0;
|
update_rect->y = 0;
|
||||||
|
|
@ -242,19 +245,19 @@ void blind_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||||
case BLIND_SIDE_LEFT:
|
case BLIND_SIDE_LEFT:
|
||||||
opaque = max((y * BLIND_THICKNESS) / canvas->h + 2, 2);
|
opaque = max((y * BLIND_THICKNESS) / canvas->h + 2, 2);
|
||||||
for (i = x; i >= 0; i -= BLIND_THICKNESS)
|
for (i = x; i >= 0; i -= BLIND_THICKNESS)
|
||||||
{
|
{
|
||||||
blind_light = 255;
|
blind_light = 255;
|
||||||
for (j=i; j > i - opaque/2; j--)
|
for (j = i; j > i - opaque / 2; j--)
|
||||||
{
|
{
|
||||||
api->line(api, which, canvas, snapshot, j, 0, j, canvas->h, 1, blind_paint_blind);
|
api->line(api, which, canvas, snapshot, j, 0, j, canvas->h, 1, blind_paint_blind);
|
||||||
blind_light -=20;
|
blind_light -= 20;
|
||||||
}
|
}
|
||||||
for (j = i - opaque/2; j > i - opaque; j--)
|
for (j = i - opaque / 2; j > i - opaque; j--)
|
||||||
{
|
{
|
||||||
api->line(api, which, canvas, snapshot, j, 0, j, canvas->h, 1, blind_paint_blind);
|
api->line(api, which, canvas, snapshot, j, 0, j, canvas->h, 1, blind_paint_blind);
|
||||||
blind_light +=20;
|
blind_light += 20;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
update_rect->x = 0;
|
update_rect->x = 0;
|
||||||
update_rect->y = 0;
|
update_rect->y = 0;
|
||||||
update_rect->w = max(ox, x);
|
update_rect->w = max(ox, x);
|
||||||
|
|
@ -266,37 +269,44 @@ void blind_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||||
}
|
}
|
||||||
|
|
||||||
void blind_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
|
void blind_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)
|
|
||||||
{
|
{
|
||||||
if (y < canvas->h / 2)
|
if (y < canvas->h / 2)
|
||||||
|
|
||||||
{
|
{
|
||||||
if (x < y) blind_side = 1; /* left */
|
if (x < y)
|
||||||
else if (canvas->w - x < y) blind_side = 3; /* right */
|
blind_side = 1; /* left */
|
||||||
else blind_side = 0; /* top */
|
else if (canvas->w - x < y)
|
||||||
}
|
blind_side = 3; /* right */
|
||||||
else
|
else
|
||||||
{
|
blind_side = 0; /* top */
|
||||||
if (x < canvas->h - y) blind_side = 1; /* left */
|
}
|
||||||
else if (canvas->w - x < canvas->h - y) blind_side = 3; /* right */
|
else
|
||||||
else blind_side = 2; /* bottom */
|
{
|
||||||
}
|
if (x < canvas->h - y)
|
||||||
|
blind_side = 1; /* left */
|
||||||
|
else if (canvas->w - x < canvas->h - y)
|
||||||
|
blind_side = 3; /* right */
|
||||||
|
else
|
||||||
|
blind_side = 2; /* bottom */
|
||||||
|
}
|
||||||
|
|
||||||
blind_drag(api, which, canvas, last, x, y, x, y, update_rect);
|
blind_drag(api, which, canvas, last, x, y, x, y, update_rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
void blind_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
void blind_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||||
{
|
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void blind_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void blind_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||||
|
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int blind_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
int blind_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
return(MODE_FULLSCREEN | MODE_PAINT);
|
return (MODE_FULLSCREEN | MODE_PAINT);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue