indent perspective.c
This commit is contained in:
parent
88e9a3dfcf
commit
04580641df
1 changed files with 245 additions and 229 deletions
|
|
@ -47,27 +47,24 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void perspective_preview(magic_api * api, int which,
|
static void perspective_preview(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, float step);
|
int x, int y, SDL_Rect * update_rect, float step);
|
||||||
Uint32 perspective_api_version(void);
|
Uint32 perspective_api_version(void);
|
||||||
int perspective_init(magic_api * api);
|
int perspective_init(magic_api * api);
|
||||||
int perspective_get_tool_count(magic_api * api);
|
int perspective_get_tool_count(magic_api * api);
|
||||||
SDL_Surface * perspective_get_icon(magic_api * api, int which);
|
SDL_Surface *perspective_get_icon(magic_api * api, int which);
|
||||||
char * perspective_get_name(magic_api * api, int which);
|
char *perspective_get_name(magic_api * api, int which);
|
||||||
|
|
||||||
char * perspective_get_description(magic_api * api, int which, int mode);
|
char *perspective_get_description(magic_api * api, int which, int mode);
|
||||||
|
|
||||||
void perspective_drag(magic_api * api, int which, SDL_Surface * canvas,
|
void perspective_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 perspective_click(magic_api * api, int which, int mode,
|
void perspective_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 perspective_release(magic_api * api, int which,
|
void perspective_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 perspective_shutdown(magic_api * api);
|
void perspective_shutdown(magic_api * api);
|
||||||
|
|
||||||
|
|
@ -81,14 +78,15 @@ void perspective_switchout(magic_api * api, int which, int mode, SDL_Surface * c
|
||||||
|
|
||||||
int perspective_modes(magic_api * api, int which);
|
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);
|
void perspective_line(void *ptr_to_api, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static const int perspective_AMOUNT= 300;
|
static const int perspective_AMOUNT = 300;
|
||||||
static const int perspective_RADIUS = 16;
|
static const int perspective_RADIUS = 16;
|
||||||
static const double perspective_SHARPEN = 1.0;
|
static const double perspective_SHARPEN = 1.0;
|
||||||
Uint8 perspective_r, perspective_g, perspective_b;
|
Uint8 perspective_r, perspective_g, perspective_b;
|
||||||
|
|
@ -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;
|
float top_advc_y, right_advc_y, bottom_advc_y, left_advc_y;
|
||||||
|
|
||||||
|
|
||||||
enum {
|
enum
|
||||||
|
{
|
||||||
TOOL_PERSPECTIVE,
|
TOOL_PERSPECTIVE,
|
||||||
TOOL_ZOOM,
|
TOOL_ZOOM,
|
||||||
perspective_NUM_TOOLS
|
perspective_NUM_TOOLS
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum
|
||||||
|
{
|
||||||
TOP_LEFT,
|
TOP_LEFT,
|
||||||
TOP_RIGHT,
|
TOP_RIGHT,
|
||||||
BOTTOM_RIGHT,
|
BOTTOM_RIGHT,
|
||||||
|
|
@ -126,168 +126,181 @@ enum {
|
||||||
|
|
||||||
|
|
||||||
/* A copy of canvas at switchin, will be used to draw from it as snapshot changes at each click */
|
/* A copy of canvas at switchin, will be used to draw from it as snapshot changes at each click */
|
||||||
static SDL_Surface * canvas_back;
|
static SDL_Surface *canvas_back;
|
||||||
|
|
||||||
static Mix_Chunk * perspective_snd_effect[perspective_NUM_TOOLS + 1];
|
static Mix_Chunk *perspective_snd_effect[perspective_NUM_TOOLS + 1];
|
||||||
|
|
||||||
const char * perspective_snd_filenames[perspective_NUM_TOOLS + 1] = {
|
const char *perspective_snd_filenames[perspective_NUM_TOOLS + 1] = {
|
||||||
"perspective.ogg",
|
"perspective.ogg",
|
||||||
"zoom_up.ogg",
|
"zoom_up.ogg",
|
||||||
"zoom_down.ogg",
|
"zoom_down.ogg",
|
||||||
};
|
};
|
||||||
|
|
||||||
const char * perspective_icon_filenames[perspective_NUM_TOOLS] = {
|
const char *perspective_icon_filenames[perspective_NUM_TOOLS] = {
|
||||||
"perspective.png",
|
"perspective.png",
|
||||||
"zoom.png",
|
"zoom.png",
|
||||||
};
|
};
|
||||||
|
|
||||||
const char * perspective_names[perspective_NUM_TOOLS] = {
|
const char *perspective_names[perspective_NUM_TOOLS] = {
|
||||||
gettext_noop("Perspective"),
|
gettext_noop("Perspective"),
|
||||||
gettext_noop("Zoom"),
|
gettext_noop("Zoom"),
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const char * perspective_descs[perspective_NUM_TOOLS] = {
|
const char *perspective_descs[perspective_NUM_TOOLS] = {
|
||||||
gettext_noop("Click on the corners and drag where you want to stretch the picture."),
|
gettext_noop("Click on the corners and drag where you want to stretch the picture."),
|
||||||
|
|
||||||
|
|
||||||
gettext_noop("Click and drag up to zoom in or drag down to zoom out the picture."),
|
gettext_noop("Click and drag up to zoom in or drag down to zoom out the picture."),
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Uint32 perspective_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
Uint32 perspective_api_version(void)
|
||||||
|
{
|
||||||
//Load sounds
|
return (TP_MAGIC_API_VERSION);
|
||||||
int perspective_init(magic_api * api){
|
|
||||||
int i;
|
|
||||||
char fname[1024];
|
|
||||||
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){
|
//Load sounds
|
||||||
return(perspective_NUM_TOOLS);
|
int perspective_init(magic_api * api)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
char fname[1024];
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
return (perspective_NUM_TOOLS);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load our icons:
|
// 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];
|
char fname[1024];
|
||||||
|
|
||||||
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, perspective_icon_filenames[which]);
|
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, perspective_icon_filenames[which]);
|
||||||
return(IMG_Load(fname));
|
return (IMG_Load(fname));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return our names, localized:
|
// 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 (strdup(gettext_noop(perspective_names[which])));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return our descriptions, localized:
|
// 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])));
|
{
|
||||||
|
return (strdup(gettext_noop(perspective_descs[which])));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Affect the canvas on drag:
|
// Affect the canvas on drag:
|
||||||
void perspective_drag(magic_api * api, int which, SDL_Surface * canvas,
|
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_Surface * last, int ox ATTRIBUTE_UNUSED, int oy ATTRIBUTE_UNUSED, int x, int y,
|
||||||
SDL_Rect * update_rect){
|
SDL_Rect * update_rect)
|
||||||
|
{
|
||||||
switch (which)
|
switch (which)
|
||||||
{
|
{
|
||||||
case TOOL_PERSPECTIVE:
|
case TOOL_PERSPECTIVE:
|
||||||
{
|
{
|
||||||
switch (corner)
|
switch (corner)
|
||||||
{
|
{
|
||||||
case TOP_LEFT:
|
case TOP_LEFT:
|
||||||
{
|
{
|
||||||
top_left_x = x;
|
top_left_x = x;
|
||||||
top_left_y = y;
|
top_left_y = y;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TOP_RIGHT:
|
case TOP_RIGHT:
|
||||||
{
|
{
|
||||||
top_right_x = x;
|
top_right_x = x;
|
||||||
top_right_y = y;
|
top_right_y = y;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BOTTOM_LEFT:
|
case BOTTOM_LEFT:
|
||||||
{
|
{
|
||||||
bottom_left_x = x;
|
bottom_left_x = x;
|
||||||
bottom_left_y = y;
|
bottom_left_y = y;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BOTTOM_RIGHT:
|
case BOTTOM_RIGHT:
|
||||||
{
|
{
|
||||||
bottom_right_x = x;
|
bottom_right_x = x;
|
||||||
bottom_right_y = y;
|
bottom_right_y = y;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_BlitSurface(canvas_back, NULL, canvas, NULL);
|
SDL_BlitSurface(canvas_back, NULL, canvas, NULL);
|
||||||
|
|
||||||
perspective_preview( api, which,
|
perspective_preview(api, which, canvas, last, x, y, update_rect, 2.0);
|
||||||
canvas , last,
|
|
||||||
x, y , update_rect , 2.0);
|
|
||||||
|
|
||||||
/* Draw a square and the current shape relative to it as a visual reference */
|
/* Draw a square and the current shape relative to it as a visual reference */
|
||||||
/* square */
|
/* 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, 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, otop_left_x, otop_left_y, obottom_left_x, obottom_left_y, 1,
|
||||||
api->line(api, which, canvas, last, obottom_left_x, obottom_left_y, obottom_right_x, obottom_right_y, 1, perspective_line);
|
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, 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 */
|
/* 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, 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, 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_left_x, bottom_left_y, bottom_right_x, bottom_right_y, 1,
|
||||||
api->line(api, which, canvas, last, bottom_right_x, bottom_right_y, top_right_x, top_right_y, 1, perspective_line);
|
perspective_line);
|
||||||
|
api->line(api, which, canvas, last, bottom_right_x, bottom_right_y, top_right_x, top_right_y, 1,
|
||||||
|
perspective_line);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
api->playsound(perspective_snd_effect[which], (x * 255) / canvas->w, 255);
|
api->playsound(perspective_snd_effect[which], (x * 255) / canvas->w, 255);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TOOL_ZOOM:
|
case TOOL_ZOOM:
|
||||||
{
|
{
|
||||||
int x_distance, y_distance;
|
int x_distance, y_distance;
|
||||||
|
|
||||||
update_rect->x = update_rect->y = 0;
|
update_rect->x = update_rect->y = 0;
|
||||||
update_rect->w = canvas->w;
|
update_rect->w = canvas->w;
|
||||||
update_rect->h = canvas->h;
|
update_rect->h = canvas->h;
|
||||||
|
|
||||||
SDL_FillRect(canvas, update_rect, SDL_MapRGB(canvas->format, perspective_r, perspective_g, perspective_b));
|
SDL_FillRect(canvas, update_rect, SDL_MapRGB(canvas->format, perspective_r, perspective_g, perspective_b));
|
||||||
|
|
||||||
new_h = max(1, old_h + click_y - y);
|
new_h = max(1, old_h + click_y - y);
|
||||||
new_w = canvas->w * new_h / canvas->h;
|
new_w = canvas->w * new_h / canvas->h;
|
||||||
if (new_h >= sound_h)
|
if (new_h >= sound_h)
|
||||||
api->playsound(perspective_snd_effect[which], 127, 255);
|
api->playsound(perspective_snd_effect[which], 127, 255);
|
||||||
else
|
else
|
||||||
api->playsound(perspective_snd_effect[which + 1], 127, 255);
|
api->playsound(perspective_snd_effect[which + 1], 127, 255);
|
||||||
sound_h = new_h;
|
sound_h = new_h;
|
||||||
|
|
||||||
x_distance = (otop_right_x - otop_left_x) * new_w / canvas->w;
|
x_distance = (otop_right_x - otop_left_x) * new_w / canvas->w;
|
||||||
top_left_x = bottom_left_x = canvas->w / 2 - x_distance / 2;
|
top_left_x = bottom_left_x = canvas->w / 2 - x_distance / 2;
|
||||||
top_right_x = bottom_right_x = canvas->w / 2 + x_distance / 2;
|
top_right_x = bottom_right_x = canvas->w / 2 + x_distance / 2;
|
||||||
|
|
||||||
y_distance = (obottom_left_y - otop_left_y) * new_w / canvas->w;
|
y_distance = (obottom_left_y - otop_left_y) * new_w / canvas->w;
|
||||||
top_left_y = top_right_y = canvas->h / 2 - y_distance / 2;
|
top_left_y = top_right_y = canvas->h / 2 - y_distance / 2;
|
||||||
bottom_left_y = bottom_right_y = canvas->h / 2 + y_distance / 2;
|
bottom_left_y = bottom_right_y = canvas->h / 2 + y_distance / 2;
|
||||||
|
|
||||||
perspective_preview( api, which,
|
perspective_preview(api, which, canvas, last, x, y, update_rect, 2.0);
|
||||||
canvas , last,
|
|
||||||
x, y , update_rect , 2.0);
|
|
||||||
|
|
||||||
update_rect->x = update_rect->y =0;
|
update_rect->x = update_rect->y = 0;
|
||||||
update_rect->w = canvas->w;
|
update_rect->w = canvas->w;
|
||||||
update_rect->h = canvas->h;
|
update_rect->h = canvas->h;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -303,43 +316,44 @@ void perspective_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||||
|
|
||||||
// Affect the canvas on click:
|
// Affect the canvas on click:
|
||||||
void perspective_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
|
void perspective_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){
|
{
|
||||||
switch(which)
|
switch (which)
|
||||||
{case TOOL_PERSPECTIVE:
|
{
|
||||||
{
|
case TOOL_PERSPECTIVE:
|
||||||
|
{
|
||||||
|
|
||||||
if (x < canvas->w / 2)
|
if (x < canvas->w / 2)
|
||||||
{
|
{
|
||||||
if (y < canvas->h / 2)
|
if (y < canvas->h / 2)
|
||||||
{
|
{
|
||||||
corner = TOP_LEFT;
|
corner = TOP_LEFT;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
corner = BOTTOM_LEFT;
|
corner = BOTTOM_LEFT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (y < canvas->h / 2)
|
if (y < canvas->h / 2)
|
||||||
{
|
{
|
||||||
corner = TOP_RIGHT;
|
corner = TOP_RIGHT;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
corner = BOTTOM_RIGHT;
|
corner = BOTTOM_RIGHT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TOOL_ZOOM:
|
case TOOL_ZOOM:
|
||||||
{
|
{
|
||||||
click_x = x;
|
click_x = x;
|
||||||
click_y = y;
|
click_y = y;
|
||||||
old_h = new_h;
|
old_h = new_h;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -349,70 +363,67 @@ void perspective_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
|
||||||
|
|
||||||
// Affect the canvas on release:
|
// Affect the canvas on release:
|
||||||
void perspective_release(magic_api * api, int which,
|
void perspective_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)
|
|
||||||
{
|
{
|
||||||
switch (which)
|
switch (which)
|
||||||
{
|
{
|
||||||
case TOOL_PERSPECTIVE:{
|
case TOOL_PERSPECTIVE:
|
||||||
perspective_preview( api, which,
|
{
|
||||||
canvas , last,
|
perspective_preview(api, which, canvas, last, x, y, update_rect, 0.5);
|
||||||
x, y , update_rect , 0.5);
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TOOL_ZOOM:
|
case TOOL_ZOOM:
|
||||||
{
|
{
|
||||||
SDL_Surface * aux_surf;
|
SDL_Surface *aux_surf;
|
||||||
SDL_Surface * scaled_surf;
|
SDL_Surface *scaled_surf;
|
||||||
|
|
||||||
update_rect->x = update_rect->y = 0;
|
update_rect->x = update_rect->y = 0;
|
||||||
update_rect->w = canvas->w;
|
update_rect->w = canvas->w;
|
||||||
update_rect->h = canvas->h;
|
update_rect->h = canvas->h;
|
||||||
|
|
||||||
SDL_FillRect(canvas, update_rect, SDL_MapRGB(canvas->format, perspective_r, perspective_g, perspective_b));
|
SDL_FillRect(canvas, update_rect, SDL_MapRGB(canvas->format, perspective_r, perspective_g, perspective_b));
|
||||||
|
|
||||||
|
|
||||||
if(new_h < canvas->h)
|
if (new_h < canvas->h)
|
||||||
{
|
{
|
||||||
scaled_surf = api->scale(canvas_back, new_w, new_h, 0);
|
scaled_surf = api->scale(canvas_back, new_w, new_h, 0);
|
||||||
update_rect->x = (canvas->w - new_w) / 2;
|
update_rect->x = (canvas->w - new_w) / 2;
|
||||||
update_rect->y = (canvas->h - new_h) / 2;
|
update_rect->y = (canvas->h - new_h) / 2;
|
||||||
update_rect->w = new_w;
|
update_rect->w = new_w;
|
||||||
update_rect->h = new_h;
|
update_rect->h = new_h;
|
||||||
SDL_BlitSurface(scaled_surf, NULL, canvas, update_rect);
|
SDL_BlitSurface(scaled_surf, NULL, canvas, update_rect);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int aux_x, aux_y, aux_h, aux_w;
|
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;
|
|
||||||
aux_y = canvas->h / 2 - aux_h / 2;
|
|
||||||
|
|
||||||
update_rect->x = canvas->w / 2 - aux_w / 2;
|
aux_h = canvas->h * canvas->h / new_h;
|
||||||
update_rect->y = canvas->h / 2 - aux_h / 2;
|
aux_w = canvas->w * aux_h / canvas->h;
|
||||||
update_rect->w = aux_w;
|
aux_x = canvas->w / 2 - aux_w / 2;
|
||||||
update_rect->h = aux_h;
|
aux_y = canvas->h / 2 - aux_h / 2;
|
||||||
|
|
||||||
aux_surf = SDL_CreateRGBSurface(SDL_SWSURFACE,
|
update_rect->x = canvas->w / 2 - aux_w / 2;
|
||||||
aux_w,
|
update_rect->y = canvas->h / 2 - aux_h / 2;
|
||||||
aux_h,
|
update_rect->w = aux_w;
|
||||||
canvas->format->BitsPerPixel,
|
update_rect->h = aux_h;
|
||||||
canvas->format->Rmask,
|
|
||||||
canvas->format->Gmask,
|
|
||||||
canvas->format->Bmask, 0);
|
|
||||||
|
|
||||||
SDL_BlitSurface(canvas_back, update_rect, aux_surf, NULL);
|
aux_surf = SDL_CreateRGBSurface(SDL_SWSURFACE,
|
||||||
scaled_surf = api->scale(aux_surf, canvas->w, canvas->h, 0);
|
aux_w,
|
||||||
SDL_BlitSurface(scaled_surf, NULL, canvas, NULL);
|
aux_h,
|
||||||
SDL_FreeSurface(aux_surf);
|
canvas->format->BitsPerPixel,
|
||||||
}
|
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, 0);
|
||||||
SDL_FreeSurface(scaled_surf);
|
|
||||||
|
|
||||||
update_rect->x = update_rect->y = 0;
|
SDL_BlitSurface(canvas_back, update_rect, aux_surf, NULL);
|
||||||
update_rect->w = canvas->w;
|
scaled_surf = api->scale(aux_surf, canvas->w, canvas->h, 0);
|
||||||
update_rect->h = canvas->h;
|
SDL_BlitSurface(scaled_surf, NULL, canvas, NULL);
|
||||||
|
SDL_FreeSurface(aux_surf);
|
||||||
|
}
|
||||||
|
SDL_FreeSurface(scaled_surf);
|
||||||
|
|
||||||
|
update_rect->x = update_rect->y = 0;
|
||||||
|
update_rect->w = canvas->w;
|
||||||
|
update_rect->h = canvas->h;
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -420,8 +431,8 @@ void perspective_release(magic_api * api, int which,
|
||||||
}
|
}
|
||||||
|
|
||||||
void perspective_preview(magic_api * api, int which ATTRIBUTE_UNUSED,
|
void perspective_preview(magic_api * api, int which ATTRIBUTE_UNUSED,
|
||||||
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
|
SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect, float step)
|
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect, float step)
|
||||||
{
|
{
|
||||||
float i, j;
|
float i, j;
|
||||||
float ax, ay, bx, by, dx, dy;
|
float ax, ay, bx, by, dx, dy;
|
||||||
|
|
@ -437,7 +448,7 @@ void perspective_preview(magic_api * api, int which ATTRIBUTE_UNUSED,
|
||||||
|
|
||||||
ox_distance = otop_right_x - otop_left_x;
|
ox_distance = otop_right_x - otop_left_x;
|
||||||
oy_distance = obottom_left_y - otop_left_y;
|
oy_distance = obottom_left_y - otop_left_y;
|
||||||
|
|
||||||
top_advc_x = (float)(top_right_x - top_left_x) / ox_distance;
|
top_advc_x = (float)(top_right_x - top_left_x) / ox_distance;
|
||||||
top_advc_y = (float)(top_right_y - top_left_y) / ox_distance;
|
top_advc_y = (float)(top_right_y - top_left_y) / ox_distance;
|
||||||
|
|
||||||
|
|
@ -454,21 +465,21 @@ void perspective_preview(magic_api * api, int which ATTRIBUTE_UNUSED,
|
||||||
center_ofset_x = (otop_left_x - top_left_x) * 2;
|
center_ofset_x = (otop_left_x - top_left_x) * 2;
|
||||||
center_ofset_y = (otop_left_y - top_left_y) * 2;
|
center_ofset_y = (otop_left_y - top_left_y) * 2;
|
||||||
|
|
||||||
for(i = 0; i < canvas->w; i += step)
|
for (i = 0; i < canvas->w; i += step)
|
||||||
{
|
{
|
||||||
ax = (float)top_advc_x * i;
|
ax = (float)top_advc_x *i;
|
||||||
ay = (float)top_advc_y * i;
|
ay = (float)top_advc_y *i;
|
||||||
bx = (float)bottom_advc_x * i + (bottom_left_x - top_left_x) * 2 ;
|
bx = (float)bottom_advc_x *i + (bottom_left_x - top_left_x) * 2;
|
||||||
by = (float)bottom_advc_y * i + (bottom_left_y - top_left_y) * 2;
|
by = (float)bottom_advc_y *i + (bottom_left_y - top_left_y) * 2;
|
||||||
|
|
||||||
for(j = 0; j < canvas->h; j += step)
|
for (j = 0; j < canvas->h; j += step)
|
||||||
{
|
{
|
||||||
dx = (float)(bx - ax) / canvas->h * j;
|
dx = (float)(bx - ax) / canvas->h * j;
|
||||||
dy = (float)(by - ay)/ canvas->h * j;
|
dy = (float)(by - ay) / canvas->h * j;
|
||||||
|
|
||||||
api->putpixel(canvas, ax + dx - center_ofset_x, ay + dy - center_ofset_y, api->getpixel(canvas_back, i, j));
|
api->putpixel(canvas, ax + dx - center_ofset_x, ay + dy - center_ofset_y, api->getpixel(canvas_back, i, j));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// No setup happened:
|
// No setup happened:
|
||||||
|
|
@ -476,11 +487,14 @@ void perspective_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
//Clean up sounds
|
//Clean up sounds
|
||||||
int i;
|
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++)
|
||||||
Mix_FreeChunk(perspective_snd_effect[i]);
|
{
|
||||||
|
if (perspective_snd_effect[i] != NULL)
|
||||||
|
{
|
||||||
|
Mix_FreeChunk(perspective_snd_effect[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Record the color from Tux Paint:
|
// Record the color from Tux Paint:
|
||||||
|
|
@ -497,9 +511,11 @@ int perspective_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTR
|
||||||
return 1;
|
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;
|
Uint32 amask;
|
||||||
|
|
||||||
new_w = canvas->w;
|
new_w = canvas->w;
|
||||||
new_h = canvas->h;
|
new_h = canvas->h;
|
||||||
|
|
||||||
|
|
@ -513,36 +529,36 @@ void perspective_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_
|
||||||
black = SDL_MapRGBA(canvas->format, 0, 0, 0, 0);
|
black = SDL_MapRGBA(canvas->format, 0, 0, 0, 0);
|
||||||
white = SDL_MapRGBA(canvas->format, 255, 255, 255, 0);
|
white = SDL_MapRGBA(canvas->format, 255, 255, 255, 0);
|
||||||
|
|
||||||
amask = ~(canvas->format->Rmask |
|
amask = ~(canvas->format->Rmask | canvas->format->Gmask | canvas->format->Bmask);
|
||||||
canvas->format->Gmask |
|
|
||||||
canvas->format->Bmask);
|
|
||||||
|
|
||||||
canvas_back = SDL_CreateRGBSurface(SDL_SWSURFACE,
|
canvas_back = SDL_CreateRGBSurface(SDL_SWSURFACE,
|
||||||
canvas->w,
|
canvas->w,
|
||||||
canvas->h,
|
canvas->h,
|
||||||
canvas->format->BitsPerPixel,
|
canvas->format->BitsPerPixel,
|
||||||
canvas->format->Rmask,
|
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, amask);
|
||||||
canvas->format->Gmask,
|
|
||||||
canvas->format->Bmask, amask);
|
|
||||||
|
|
||||||
SDL_BlitSurface(canvas, NULL, canvas_back, NULL);
|
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);
|
SDL_FreeSurface(canvas_back);
|
||||||
}
|
}
|
||||||
|
|
||||||
int perspective_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
int perspective_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
return(MODE_PAINT_WITH_PREVIEW);
|
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;
|
magic_api *api = (magic_api *) ptr_to_api;
|
||||||
|
|
||||||
dash += 1;
|
dash += 1;
|
||||||
if (dash > 8) dash = 0;
|
if (dash > 8)
|
||||||
|
dash = 0;
|
||||||
if (dash > 3)
|
if (dash > 3)
|
||||||
api->putpixel(canvas, x, y, black);
|
api->putpixel(canvas, x, y, black);
|
||||||
else
|
else
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue