indent perspective.c
This commit is contained in:
parent
88e9a3dfcf
commit
04580641df
1 changed files with 245 additions and 229 deletions
|
|
@ -58,16 +58,13 @@ char * perspective_get_name(magic_api * api, int which);
|
|||
char *perspective_get_description(magic_api * api, int which, int mode);
|
||||
|
||||
void perspective_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 perspective_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 perspective_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);
|
||||
|
||||
void perspective_shutdown(magic_api * api);
|
||||
|
||||
|
|
@ -81,7 +78,8 @@ void perspective_switchout(magic_api * api, int which, int mode, SDL_Surface * c
|
|||
|
||||
int perspective_modes(magic_api * api, int which);
|
||||
|
||||
int scan_fill(magic_api * api, SDL_Surface * canvas, SDL_Surface * srfc,int x,int y, int fill_edge, int fill_tile, int size, Uint32 color);
|
||||
int scan_fill(magic_api * api, SDL_Surface * canvas, SDL_Surface * srfc, int x, int y, int fill_edge, int fill_tile,
|
||||
int size, Uint32 color);
|
||||
|
||||
void perspective_line(void *ptr_to_api, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
|
||||
|
||||
|
|
@ -111,13 +109,15 @@ float top_advc_x, right_advc_x, bottom_advc_x, left_advc_x;
|
|||
float top_advc_y, right_advc_y, bottom_advc_y, left_advc_y;
|
||||
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
TOOL_PERSPECTIVE,
|
||||
TOOL_ZOOM,
|
||||
perspective_NUM_TOOLS
|
||||
};
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
TOP_LEFT,
|
||||
TOP_RIGHT,
|
||||
BOTTOM_RIGHT,
|
||||
|
|
@ -156,37 +156,48 @@ const char * perspective_descs[perspective_NUM_TOOLS] = {
|
|||
|
||||
};
|
||||
|
||||
Uint32 perspective_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
||||
Uint32 perspective_api_version(void)
|
||||
{
|
||||
return (TP_MAGIC_API_VERSION);
|
||||
}
|
||||
|
||||
//Load sounds
|
||||
int perspective_init(magic_api * api){
|
||||
int perspective_init(magic_api * api)
|
||||
{
|
||||
int i;
|
||||
char fname[1024];
|
||||
for (i = 0; i <= perspective_NUM_TOOLS; i++){
|
||||
|
||||
for (i = 0; i <= perspective_NUM_TOOLS; i++)
|
||||
{
|
||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/%s", api->data_directory, perspective_snd_filenames[i]);
|
||||
perspective_snd_effect[i] = Mix_LoadWAV(fname);
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
int perspective_get_tool_count(magic_api * api ATTRIBUTE_UNUSED){
|
||||
int perspective_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return (perspective_NUM_TOOLS);
|
||||
}
|
||||
|
||||
// Load our icons:
|
||||
SDL_Surface * perspective_get_icon(magic_api * api, int which){
|
||||
SDL_Surface *perspective_get_icon(magic_api * api, int which)
|
||||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, perspective_icon_filenames[which]);
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
// Return our names, localized:
|
||||
char * perspective_get_name(magic_api * api ATTRIBUTE_UNUSED, int which){
|
||||
char *perspective_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
|
||||
{
|
||||
return (strdup(gettext_noop(perspective_names[which])));
|
||||
}
|
||||
|
||||
// Return our descriptions, localized:
|
||||
char * perspective_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED){
|
||||
char *perspective_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return (strdup(gettext_noop(perspective_descs[which])));
|
||||
}
|
||||
|
||||
|
|
@ -194,7 +205,8 @@ char * perspective_get_description(magic_api * api ATTRIBUTE_UNUSED, int which,
|
|||
// Affect the canvas on drag:
|
||||
void perspective_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, int x, int y,
|
||||
SDL_Rect * update_rect){
|
||||
SDL_Rect * update_rect)
|
||||
{
|
||||
switch (which)
|
||||
{
|
||||
case TOOL_PERSPECTIVE:
|
||||
|
|
@ -232,22 +244,25 @@ void perspective_drag(magic_api * api, int which, SDL_Surface * canvas,
|
|||
|
||||
SDL_BlitSurface(canvas_back, NULL, canvas, NULL);
|
||||
|
||||
perspective_preview( api, which,
|
||||
canvas , last,
|
||||
x, y , update_rect , 2.0);
|
||||
perspective_preview(api, which, canvas, last, x, y, update_rect, 2.0);
|
||||
|
||||
/* Draw a square and the current shape relative to it as a visual reference */
|
||||
/* square */
|
||||
api->line(api, which, canvas, last, otop_left_x, otop_left_y, otop_right_x, otop_right_y, 1, perspective_line);
|
||||
api->line(api, which, canvas, last, otop_left_x, otop_left_y, obottom_left_x, obottom_left_y, 1, perspective_line);
|
||||
api->line(api, which, canvas, last, obottom_left_x, obottom_left_y, obottom_right_x, obottom_right_y, 1, perspective_line);
|
||||
api->line(api, which, canvas, last, obottom_right_x, obottom_right_y, otop_right_x, otop_right_y, 1, perspective_line);
|
||||
api->line(api, which, canvas, last, otop_left_x, otop_left_y, obottom_left_x, obottom_left_y, 1,
|
||||
perspective_line);
|
||||
api->line(api, which, canvas, last, obottom_left_x, obottom_left_y, obottom_right_x, obottom_right_y, 1,
|
||||
perspective_line);
|
||||
api->line(api, which, canvas, last, obottom_right_x, obottom_right_y, otop_right_x, otop_right_y, 1,
|
||||
perspective_line);
|
||||
|
||||
/* shape */
|
||||
api->line(api, which, canvas, last, top_left_x, top_left_y, top_right_x, top_right_y, 1, perspective_line);
|
||||
api->line(api, which, canvas, last, top_left_x, top_left_y, bottom_left_x, bottom_left_y, 1, perspective_line);
|
||||
api->line(api, which, canvas, last, bottom_left_x, bottom_left_y, bottom_right_x, bottom_right_y, 1, perspective_line);
|
||||
api->line(api, which, canvas, last, bottom_right_x, bottom_right_y, top_right_x, top_right_y, 1, perspective_line);
|
||||
api->line(api, which, canvas, last, bottom_left_x, bottom_left_y, bottom_right_x, bottom_right_y, 1,
|
||||
perspective_line);
|
||||
api->line(api, which, canvas, last, bottom_right_x, bottom_right_y, top_right_x, top_right_y, 1,
|
||||
perspective_line);
|
||||
|
||||
|
||||
|
||||
|
|
@ -281,9 +296,7 @@ void perspective_drag(magic_api * api, int which, SDL_Surface * canvas,
|
|||
top_left_y = top_right_y = canvas->h / 2 - y_distance / 2;
|
||||
bottom_left_y = bottom_right_y = canvas->h / 2 + y_distance / 2;
|
||||
|
||||
perspective_preview( api, which,
|
||||
canvas , last,
|
||||
x, y , update_rect , 2.0);
|
||||
perspective_preview(api, which, canvas, last, x, y, update_rect, 2.0);
|
||||
|
||||
update_rect->x = update_rect->y = 0;
|
||||
update_rect->w = canvas->w;
|
||||
|
|
@ -303,10 +316,11 @@ void perspective_drag(magic_api * api, int which, SDL_Surface * canvas,
|
|||
|
||||
// Affect the canvas on click:
|
||||
void perspective_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)
|
||||
{
|
||||
switch (which)
|
||||
{case TOOL_PERSPECTIVE:
|
||||
{
|
||||
case TOOL_PERSPECTIVE:
|
||||
{
|
||||
|
||||
if (x < canvas->w / 2)
|
||||
|
|
@ -349,15 +363,13 @@ void perspective_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
|
|||
|
||||
// Affect the canvas on release:
|
||||
void perspective_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)
|
||||
{
|
||||
switch (which)
|
||||
{
|
||||
case TOOL_PERSPECTIVE:{
|
||||
perspective_preview( api, which,
|
||||
canvas , last,
|
||||
x, y , update_rect , 0.5);
|
||||
case TOOL_PERSPECTIVE:
|
||||
{
|
||||
perspective_preview(api, which, canvas, last, x, y, update_rect, 0.5);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -385,6 +397,7 @@ void perspective_release(magic_api * api, int which,
|
|||
else
|
||||
{
|
||||
int aux_x, aux_y, aux_h, aux_w;
|
||||
|
||||
aux_h = canvas->h * canvas->h / new_h;
|
||||
aux_w = canvas->w * aux_h / canvas->h;
|
||||
aux_x = canvas->w / 2 - aux_w / 2;
|
||||
|
|
@ -399,9 +412,7 @@ void perspective_release(magic_api * api, int which,
|
|||
aux_w,
|
||||
aux_h,
|
||||
canvas->format->BitsPerPixel,
|
||||
canvas->format->Rmask,
|
||||
canvas->format->Gmask,
|
||||
canvas->format->Bmask, 0);
|
||||
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, 0);
|
||||
|
||||
SDL_BlitSurface(canvas_back, update_rect, aux_surf, NULL);
|
||||
scaled_surf = api->scale(aux_surf, canvas->w, canvas->h, 0);
|
||||
|
|
@ -476,8 +487,11 @@ void perspective_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
|||
{
|
||||
//Clean up sounds
|
||||
int i;
|
||||
for(i=0; i<perspective_NUM_TOOLS + 1; i++){
|
||||
if(perspective_snd_effect[i] != NULL){
|
||||
|
||||
for (i = 0; i < perspective_NUM_TOOLS + 1; i++)
|
||||
{
|
||||
if (perspective_snd_effect[i] != NULL)
|
||||
{
|
||||
Mix_FreeChunk(perspective_snd_effect[i]);
|
||||
}
|
||||
}
|
||||
|
|
@ -497,9 +511,11 @@ int perspective_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTR
|
|||
return 1;
|
||||
}
|
||||
|
||||
void perspective_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas)
|
||||
void perspective_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas)
|
||||
{
|
||||
Uint32 amask;
|
||||
|
||||
new_w = canvas->w;
|
||||
new_h = canvas->h;
|
||||
|
||||
|
|
@ -513,22 +529,19 @@ void perspective_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_
|
|||
black = SDL_MapRGBA(canvas->format, 0, 0, 0, 0);
|
||||
white = SDL_MapRGBA(canvas->format, 255, 255, 255, 0);
|
||||
|
||||
amask = ~(canvas->format->Rmask |
|
||||
canvas->format->Gmask |
|
||||
canvas->format->Bmask);
|
||||
amask = ~(canvas->format->Rmask | canvas->format->Gmask | canvas->format->Bmask);
|
||||
|
||||
canvas_back = SDL_CreateRGBSurface(SDL_SWSURFACE,
|
||||
canvas->w,
|
||||
canvas->h,
|
||||
canvas->format->BitsPerPixel,
|
||||
canvas->format->Rmask,
|
||||
canvas->format->Gmask,
|
||||
canvas->format->Bmask, amask);
|
||||
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, amask);
|
||||
|
||||
SDL_BlitSurface(canvas, NULL, canvas_back, NULL);
|
||||
}
|
||||
|
||||
void perspective_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
void perspective_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
SDL_FreeSurface(canvas_back);
|
||||
}
|
||||
|
|
@ -538,11 +551,14 @@ int perspective_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUS
|
|||
return (MODE_PAINT_WITH_PREVIEW);
|
||||
}
|
||||
|
||||
void perspective_line(void * ptr_to_api, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
|
||||
void perspective_line(void *ptr_to_api, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
|
||||
SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
|
||||
{
|
||||
magic_api *api = (magic_api *) ptr_to_api;
|
||||
|
||||
dash += 1;
|
||||
if (dash > 8) dash = 0;
|
||||
if (dash > 8)
|
||||
dash = 0;
|
||||
if (dash > 3)
|
||||
api->putpixel(canvas, x, y, black);
|
||||
else
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue