indent string.c
This commit is contained in:
parent
29b25992ad
commit
d311aeb236
1 changed files with 276 additions and 247 deletions
|
|
@ -7,17 +7,19 @@ static Uint8 string_r, string_g, string_b;
|
||||||
static int string_ox, string_oy;
|
static int string_ox, string_oy;
|
||||||
static int string_vertex_x, string_vertex_y, string_vertex_done, string_vertex_distance;
|
static int string_vertex_x, string_vertex_y, string_vertex_done, string_vertex_distance;
|
||||||
static SDL_Surface *canvas_backup;
|
static SDL_Surface *canvas_backup;
|
||||||
enum string_tools{
|
enum string_tools
|
||||||
|
{
|
||||||
STRING_TOOL_FULL_BY_OFFSET,
|
STRING_TOOL_FULL_BY_OFFSET,
|
||||||
STRING_TOOL_TRIANGLE,
|
STRING_TOOL_TRIANGLE,
|
||||||
STRING_TOOL_ANGLE,
|
STRING_TOOL_ANGLE,
|
||||||
STRING_NUMTOOLS};
|
STRING_NUMTOOLS
|
||||||
|
};
|
||||||
|
|
||||||
Mix_Chunk *string_snd[STRING_NUMTOOLS];
|
Mix_Chunk *string_snd[STRING_NUMTOOLS];
|
||||||
|
|
||||||
// Custom function declarations
|
// Custom function declarations
|
||||||
|
|
||||||
void string_callback(void * ptr, int which_tool,
|
void string_callback(void *ptr, int which_tool, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
|
||||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
|
|
||||||
void string_draw_triangle(magic_api * api, int which,
|
void string_draw_triangle(magic_api * api, int which,
|
||||||
SDL_Surface * canvas, SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
SDL_Surface * canvas, SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||||
SDL_Rect * update_rect);
|
SDL_Rect * update_rect);
|
||||||
|
|
@ -43,8 +45,7 @@ void compute_middle( int start_point, int end_point, int vertex, int * middle);
|
||||||
// Prototypes for required functions
|
// Prototypes for required functions
|
||||||
|
|
||||||
void string_drag(magic_api * api, int which, SDL_Surface * canvas,
|
void string_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);
|
|
||||||
|
|
||||||
|
|
||||||
Uint32 string_api_version(void);
|
Uint32 string_api_version(void);
|
||||||
|
|
@ -56,15 +57,13 @@ char * string_get_name(magic_api * api, int which);
|
||||||
char *string_get_description(magic_api * api, int which, int mode);
|
char *string_get_description(magic_api * api, int which, int mode);
|
||||||
int string_requires_colors(magic_api * api, int which);
|
int string_requires_colors(magic_api * api, int which);
|
||||||
void string_release(magic_api * api, int which,
|
void string_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);
|
|
||||||
int string_init(magic_api * api);
|
int string_init(magic_api * api);
|
||||||
void string_shutdown(magic_api * api);
|
void string_shutdown(magic_api * api);
|
||||||
void string_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * snapshot);
|
void string_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * snapshot);
|
||||||
void string_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * snapshot);
|
void string_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * snapshot);
|
||||||
void string_click(magic_api * api, int which, int mode,
|
void string_click(magic_api * api, int which, int mode,
|
||||||
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);
|
|
||||||
|
|
||||||
// Required functions
|
// Required functions
|
||||||
|
|
||||||
|
|
@ -98,6 +97,7 @@ int string_get_tool_count(__attribute__((unused)) magic_api * api)
|
||||||
SDL_Surface *string_get_icon(magic_api * api, int which)
|
SDL_Surface *string_get_icon(magic_api * api, int which)
|
||||||
{
|
{
|
||||||
char fname[1024];
|
char fname[1024];
|
||||||
|
|
||||||
switch (which)
|
switch (which)
|
||||||
{
|
{
|
||||||
case STRING_TOOL_FULL_BY_OFFSET:
|
case STRING_TOOL_FULL_BY_OFFSET:
|
||||||
|
|
@ -115,7 +115,8 @@ SDL_Surface * string_get_icon(magic_api * api, int which)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char * string_get_name(__attribute__((unused)) magic_api * api, __attribute__((unused)) int which)
|
char *string_get_name( __attribute__ ((unused)) magic_api * api, __attribute__ ((unused))
|
||||||
|
int which)
|
||||||
{
|
{
|
||||||
switch (which)
|
switch (which)
|
||||||
{
|
{
|
||||||
|
|
@ -130,11 +131,15 @@ char * string_get_name(__attribute__((unused)) magic_api * api, __attribute__((u
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char * string_get_description(__attribute__((unused)) magic_api * api, int which, __attribute__((unused)) int mode) {
|
char *string_get_description( __attribute__ ((unused)) magic_api * api, int which, __attribute__ ((unused))
|
||||||
|
int mode)
|
||||||
|
{
|
||||||
switch (which)
|
switch (which)
|
||||||
{
|
{
|
||||||
case STRING_TOOL_FULL_BY_OFFSET:
|
case STRING_TOOL_FULL_BY_OFFSET:
|
||||||
return strdup(gettext_noop("Click and drag to draw string art. Drag top-bottom to draw less or more lines, left or right to make a bigger hole."));
|
return
|
||||||
|
strdup(gettext_noop
|
||||||
|
("Click and drag to draw string art. Drag top-bottom to draw less or more lines, left or right to make a bigger hole."));
|
||||||
break;
|
break;
|
||||||
case STRING_TOOL_TRIANGLE:
|
case STRING_TOOL_TRIANGLE:
|
||||||
return strdup(gettext_noop("Click and drag to draw arrows made of string art."));
|
return strdup(gettext_noop("Click and drag to draw arrows made of string art."));
|
||||||
|
|
@ -144,13 +149,17 @@ char * string_get_description(__attribute__((unused)) magic_api * api, int which
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int string_requires_colors(__attribute__((unused)) magic_api * api, __attribute__((unused)) int which) { return 1;}
|
int string_requires_colors( __attribute__ ((unused)) magic_api * api, __attribute__ ((unused))
|
||||||
|
int which)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
void string_release(magic_api * api, int which,
|
void string_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)
|
|
||||||
{
|
{
|
||||||
int dx, dy;
|
int dx, dy;
|
||||||
|
|
||||||
if (which == STRING_TOOL_TRIANGLE)
|
if (which == STRING_TOOL_TRIANGLE)
|
||||||
string_draw_triangle((void *)api, which, canvas, snapshot, string_ox, string_oy, x, y, update_rect);
|
string_draw_triangle((void *)api, which, canvas, snapshot, string_ox, string_oy, x, y, update_rect);
|
||||||
if (which == STRING_TOOL_ANGLE)
|
if (which == STRING_TOOL_ANGLE)
|
||||||
|
|
@ -170,16 +179,13 @@ int string_init(__attribute__((unused)) magic_api * api)
|
||||||
{
|
{
|
||||||
char fname[1024];
|
char fname[1024];
|
||||||
|
|
||||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/string.ogg",
|
snprintf(fname, sizeof(fname), "%s/sounds/magic/string.ogg", api->data_directory);
|
||||||
api->data_directory);
|
|
||||||
string_snd[STRING_TOOL_FULL_BY_OFFSET] = Mix_LoadWAV(fname);
|
string_snd[STRING_TOOL_FULL_BY_OFFSET] = Mix_LoadWAV(fname);
|
||||||
|
|
||||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/string2.ogg",
|
snprintf(fname, sizeof(fname), "%s/sounds/magic/string2.ogg", api->data_directory);
|
||||||
api->data_directory);
|
|
||||||
string_snd[STRING_TOOL_TRIANGLE] = Mix_LoadWAV(fname);
|
string_snd[STRING_TOOL_TRIANGLE] = Mix_LoadWAV(fname);
|
||||||
|
|
||||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/string3.ogg",
|
snprintf(fname, sizeof(fname), "%s/sounds/magic/string3.ogg", api->data_directory);
|
||||||
api->data_directory);
|
|
||||||
string_snd[STRING_TOOL_ANGLE] = Mix_LoadWAV(fname);
|
string_snd[STRING_TOOL_ANGLE] = Mix_LoadWAV(fname);
|
||||||
|
|
||||||
return (1);
|
return (1);
|
||||||
|
|
@ -200,13 +206,19 @@ void string_shutdown(__attribute__((unused)) magic_api * api)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void string_switchin(__attribute__((unused)) magic_api * api, __attribute__((unused)) int which, __attribute__((unused)) int mode, SDL_Surface * canvas, __attribute__((unused)) SDL_Surface * snapshot)
|
void string_switchin( __attribute__ ((unused)) magic_api * api, __attribute__ ((unused))
|
||||||
|
int which, __attribute__ ((unused))
|
||||||
|
int mode, SDL_Surface * canvas, __attribute__ ((unused)) SDL_Surface * snapshot)
|
||||||
{
|
{
|
||||||
canvas_backup = SDL_CreateRGBSurface(SDL_ANYFORMAT, canvas->w, canvas->h, canvas->format->BitsPerPixel,
|
canvas_backup = SDL_CreateRGBSurface(SDL_ANYFORMAT, canvas->w, canvas->h, canvas->format->BitsPerPixel,
|
||||||
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
|
canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask,
|
||||||
|
canvas->format->Amask);
|
||||||
}
|
}
|
||||||
|
|
||||||
void string_switchout(__attribute__((unused)) magic_api * api, __attribute__((unused)) int which, __attribute__((unused)) int mode, __attribute__((unused)) SDL_Surface * canvas, __attribute__((unused)) SDL_Surface * snapshot)
|
void string_switchout( __attribute__ ((unused)) magic_api * api, __attribute__ ((unused))
|
||||||
|
int which, __attribute__ ((unused))
|
||||||
|
int mode, __attribute__ ((unused)) SDL_Surface * canvas,
|
||||||
|
__attribute__ ((unused)) SDL_Surface * snapshot)
|
||||||
{
|
{
|
||||||
SDL_FreeSurface(canvas_backup);
|
SDL_FreeSurface(canvas_backup);
|
||||||
canvas_backup = NULL;
|
canvas_backup = NULL;
|
||||||
|
|
@ -215,17 +227,17 @@ void string_switchout(__attribute__((unused)) magic_api * api, __attribute__((un
|
||||||
// Interactivity functions
|
// Interactivity functions
|
||||||
|
|
||||||
|
|
||||||
void string_callback(void * ptr,__attribute__((unused)) int which,
|
void string_callback(void *ptr, __attribute__ ((unused))
|
||||||
SDL_Surface * canvas,__attribute__((unused)) SDL_Surface * snapshot, int x, int y)
|
int which, SDL_Surface * canvas, __attribute__ ((unused)) SDL_Surface * snapshot, int x, int y)
|
||||||
{
|
{
|
||||||
magic_api *api = (magic_api *) ptr;
|
magic_api *api = (magic_api *) ptr;
|
||||||
|
|
||||||
api->putpixel(canvas, x, y, SDL_MapRGBA(canvas->format, string_r, string_g, string_b, 255));
|
api->putpixel(canvas, x, y, SDL_MapRGBA(canvas->format, string_r, string_g, string_b, 255));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void string_click(magic_api * api, int which,__attribute__((unused)) int mode,
|
void string_click(magic_api * api, int which, __attribute__ ((unused))
|
||||||
SDL_Surface * canvas, SDL_Surface * snapshot,
|
int mode, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
|
||||||
int x, int y, SDL_Rect * update_rect)
|
|
||||||
{
|
{
|
||||||
SDL_BlitSurface(canvas, NULL, canvas_backup, NULL);
|
SDL_BlitSurface(canvas, NULL, canvas_backup, NULL);
|
||||||
|
|
||||||
|
|
@ -236,13 +248,15 @@ void string_click(magic_api * api, int which,__attribute__((unused)) int mode,
|
||||||
string_drag(api, which, canvas, snapshot, x, y, x, y, update_rect);
|
string_drag(api, which, canvas, snapshot, x, y, x, y, update_rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void string_draw_full_by_offset(void * ptr, __attribute__((unused)) int which, SDL_Surface * canvas, __attribute__((unused)) SDL_Surface * snapshot,
|
static void string_draw_full_by_offset(void *ptr, __attribute__ ((unused))
|
||||||
|
int which, SDL_Surface * canvas, __attribute__ ((unused)) SDL_Surface * snapshot,
|
||||||
int x, int y, SDL_Rect * update_rect)
|
int x, int y, SDL_Rect * update_rect)
|
||||||
{
|
{
|
||||||
magic_api *api = (magic_api *) ptr;
|
magic_api *api = (magic_api *) ptr;
|
||||||
int u;
|
int u;
|
||||||
int i;
|
int i;
|
||||||
int o; //offset
|
int o; //offset
|
||||||
|
|
||||||
// int n=y/5;
|
// int n=y/5;
|
||||||
int **a;
|
int **a;
|
||||||
float step_w, step_h, aux;
|
float step_w, step_h, aux;
|
||||||
|
|
@ -250,7 +264,8 @@ static void string_draw_full_by_offset(void * ptr, __attribute__((unused)) int w
|
||||||
|
|
||||||
SDL_BlitSurface(snapshot, 0, canvas, 0);
|
SDL_BlitSurface(snapshot, 0, canvas, 0);
|
||||||
|
|
||||||
if (side<3) side=3;
|
if (side < 3)
|
||||||
|
side = 3;
|
||||||
|
|
||||||
o = (int)(side * 4 * x / canvas->w);
|
o = (int)(side * 4 * x / canvas->w);
|
||||||
step_w = canvas->w / (float)side;
|
step_w = canvas->w / (float)side;
|
||||||
|
|
@ -267,20 +282,17 @@ static void string_draw_full_by_offset(void * ptr, __attribute__((unused)) int w
|
||||||
aux = step_h * (float)i;
|
aux = step_h * (float)i;
|
||||||
a[i][1] = (int)aux;
|
a[i][1] = (int)aux;
|
||||||
}
|
}
|
||||||
else
|
else if (i < (side * 2))
|
||||||
if(i<(side*2))
|
|
||||||
{
|
{
|
||||||
a[i][0] = (int)((float)(i % side) * step_w);
|
a[i][0] = (int)((float)(i % side) * step_w);
|
||||||
a[i][1] = canvas->h;
|
a[i][1] = canvas->h;
|
||||||
}
|
}
|
||||||
else
|
else if (i < (int)(side * 3))
|
||||||
if (i<(int)(side*3))
|
|
||||||
{
|
{
|
||||||
a[i][0] = canvas->w;
|
a[i][0] = canvas->w;
|
||||||
a[i][1] = (int)(canvas->h - (float)((i % side) * step_h));
|
a[i][1] = (int)(canvas->h - (float)((i % side) * step_h));
|
||||||
}
|
}
|
||||||
else
|
else if (i < (int)(side * 4))
|
||||||
if (i<(int)(side*4))
|
|
||||||
{
|
{
|
||||||
a[i][0] = (int)(canvas->w - ((float)((i % side) * step_w)));
|
a[i][0] = (int)(canvas->w - ((float)((i % side) * step_w)));
|
||||||
a[i][1] = 0;
|
a[i][1] = 0;
|
||||||
|
|
@ -308,14 +320,18 @@ static void string_draw_full_by_offset(void * ptr, __attribute__((unused)) int w
|
||||||
|
|
||||||
void scale_xcoord(int *xcoord)
|
void scale_xcoord(int *xcoord)
|
||||||
{
|
{
|
||||||
if (*xcoord < string_ox) *xcoord=string_ox-(string_ox - *xcoord)*4;
|
if (*xcoord < string_ox)
|
||||||
else *xcoord=string_ox+(*xcoord-string_ox)*4;
|
*xcoord = string_ox - (string_ox - *xcoord) * 4;
|
||||||
|
else
|
||||||
|
*xcoord = string_ox + (*xcoord - string_ox) * 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
void scale_ycoord(int *ycoord)
|
void scale_ycoord(int *ycoord)
|
||||||
{
|
{
|
||||||
if (*ycoord < string_oy) *ycoord=string_oy-(string_oy - *ycoord)*4;
|
if (*ycoord < string_oy)
|
||||||
else *ycoord=string_oy+(*ycoord-string_oy)*4;
|
*ycoord = string_oy - (string_oy - *ycoord) * 4;
|
||||||
|
else
|
||||||
|
*ycoord = string_oy + (*ycoord - string_oy) * 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
void scale_coords(int *ox, int *oy, int *x, int *y)
|
void scale_coords(int *ox, int *oy, int *x, int *y)
|
||||||
|
|
@ -338,6 +354,7 @@ void string_draw_triangle_preview(magic_api * api, int which,
|
||||||
{
|
{
|
||||||
int middle_x, middle_y;
|
int middle_x, middle_y;
|
||||||
int w, h;
|
int w, h;
|
||||||
|
|
||||||
scale_coords(&ox, &oy, &x, &y);
|
scale_coords(&ox, &oy, &x, &y);
|
||||||
w = max(string_ox, x) - min(string_ox, x);
|
w = max(string_ox, x) - min(string_ox, x);
|
||||||
h = max(string_oy, y) - min(string_oy, y);
|
h = max(string_oy, y) - min(string_oy, y);
|
||||||
|
|
@ -366,12 +383,14 @@ void string_draw_triangle_preview(magic_api * api, int which,
|
||||||
}
|
}
|
||||||
|
|
||||||
void string_draw_angle_preview(magic_api * api, int which,
|
void string_draw_angle_preview(magic_api * api, int which,
|
||||||
SDL_Surface * canvas, SDL_Surface * snapshot, __attribute__((unused)) int ox, __attribute__ ((unused)) int oy, int x, int y,
|
SDL_Surface * canvas, SDL_Surface * snapshot, __attribute__ ((unused))
|
||||||
SDL_Rect * update_rect)
|
int ox, __attribute__ ((unused))
|
||||||
|
int oy, int x, int y, SDL_Rect * update_rect)
|
||||||
{
|
{
|
||||||
int w, h;
|
int w, h;
|
||||||
int middle_x, middle_y;
|
int middle_x, middle_y;
|
||||||
int dx, dy;
|
int dx, dy;
|
||||||
|
|
||||||
w = max(string_ox, x) - min(string_ox, x);
|
w = max(string_ox, x) - min(string_ox, x);
|
||||||
h = max(string_oy, y) - min(string_oy, y);
|
h = max(string_oy, y) - min(string_oy, y);
|
||||||
|
|
||||||
|
|
@ -381,7 +400,8 @@ void string_draw_angle_preview(magic_api * api, int which,
|
||||||
update_rect->h = canvas->h;
|
update_rect->h = canvas->h;
|
||||||
SDL_BlitSurface(canvas_backup, update_rect, canvas, update_rect);
|
SDL_BlitSurface(canvas_backup, update_rect, canvas, update_rect);
|
||||||
|
|
||||||
api->line((void *) api, which, canvas, snapshot, string_ox,string_oy, string_vertex_x , string_vertex_y,1, string_callback);
|
api->line((void *)api, which, canvas, snapshot, string_ox, string_oy, string_vertex_x, string_vertex_y, 1,
|
||||||
|
string_callback);
|
||||||
if (!string_vertex_done)
|
if (!string_vertex_done)
|
||||||
{
|
{
|
||||||
// if(!string_vertex_done) // maybe we face small children, draw square angles aligned to the drag
|
// if(!string_vertex_done) // maybe we face small children, draw square angles aligned to the drag
|
||||||
|
|
@ -401,9 +421,11 @@ void string_draw_angle_preview(magic_api * api, int which,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void string_draw_angle(magic_api * api, __attribute__((unused)) int which,
|
void string_draw_angle(magic_api * api, __attribute__ ((unused))
|
||||||
SDL_Surface * canvas, __attribute__((unused))SDL_Surface * snapshot, __attribute__ ((unused)) int ox, __attribute__ ((unused)) int oy, int x, int y,
|
int which,
|
||||||
SDL_Rect * update_rect)
|
SDL_Surface * canvas, __attribute__ ((unused)) SDL_Surface * snapshot, __attribute__ ((unused))
|
||||||
|
int ox, __attribute__ ((unused))
|
||||||
|
int oy, int x, int y, SDL_Rect * update_rect)
|
||||||
{
|
{
|
||||||
float first_arm_step_x, first_arm_step_y, second_arm_step_x, second_arm_step_y;
|
float first_arm_step_x, first_arm_step_y, second_arm_step_x, second_arm_step_y;
|
||||||
int i;
|
int i;
|
||||||
|
|
@ -416,7 +438,9 @@ void string_draw_angle(magic_api * api, __attribute__((unused)) int which,
|
||||||
update_rect->h = max(max(string_oy, string_vertex_y), y) - update_rect->y;
|
update_rect->h = max(max(string_oy, string_vertex_y), y) - update_rect->y;
|
||||||
SDL_BlitSurface(canvas_backup, update_rect, canvas, update_rect);
|
SDL_BlitSurface(canvas_backup, update_rect, canvas, update_rect);
|
||||||
|
|
||||||
max_wh= max( max(max(string_ox,string_vertex_x),x)- min(min(string_vertex_x , x),string_ox) , max(max(string_oy , string_vertex_y),y)- min(min(string_vertex_y ,y),string_oy));
|
max_wh =
|
||||||
|
max(max(max(string_ox, string_vertex_x), x) - min(min(string_vertex_x, x), string_ox),
|
||||||
|
max(max(string_oy, string_vertex_y), y) - min(min(string_vertex_y, y), string_oy));
|
||||||
|
|
||||||
steps = max_wh / max_separation;
|
steps = max_wh / max_separation;
|
||||||
first_arm_step_x = (float)(string_ox - string_vertex_x) / (float)steps;
|
first_arm_step_x = (float)(string_ox - string_vertex_x) / (float)steps;
|
||||||
|
|
@ -426,11 +450,13 @@ void string_draw_angle(magic_api * api, __attribute__((unused)) int which,
|
||||||
|
|
||||||
for (i = 0; i <= steps; i++)
|
for (i = 0; i <= steps; i++)
|
||||||
{
|
{
|
||||||
api->line((void *) api, 0, canvas, snapshot, string_ox-first_arm_step_x*i,string_oy-first_arm_step_y*i, string_vertex_x-second_arm_step_x*i,string_vertex_y-second_arm_step_y*i,1, string_callback);
|
api->line((void *)api, 0, canvas, snapshot, string_ox - first_arm_step_x * i, string_oy - first_arm_step_y * i,
|
||||||
|
string_vertex_x - second_arm_step_x * i, string_vertex_y - second_arm_step_y * i, 1, string_callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void string_draw_triangle(magic_api * api, __attribute__((unused)) int which,
|
void string_draw_triangle(magic_api * api, __attribute__ ((unused))
|
||||||
|
int which,
|
||||||
SDL_Surface * canvas, SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
SDL_Surface * canvas, SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||||
SDL_Rect * update_rect)
|
SDL_Rect * update_rect)
|
||||||
{
|
{
|
||||||
|
|
@ -461,7 +487,9 @@ void string_draw_wrapper(magic_api * api, int which,
|
||||||
void string_set_vertex(int x, int y)
|
void string_set_vertex(int x, int y)
|
||||||
{
|
{
|
||||||
int dx, dy;
|
int dx, dy;
|
||||||
if (string_vertex_done) return;
|
|
||||||
|
if (string_vertex_done)
|
||||||
|
return;
|
||||||
dx = max(string_ox, x) - min(string_ox, x);
|
dx = max(string_ox, x) - min(string_ox, x);
|
||||||
dy = max(string_oy, y) - min(string_oy, y);
|
dy = max(string_oy, y) - min(string_oy, y);
|
||||||
if (dx + dy > string_vertex_distance)
|
if (dx + dy > string_vertex_distance)
|
||||||
|
|
@ -470,14 +498,15 @@ void string_set_vertex(int x, int y)
|
||||||
string_vertex_x = x;
|
string_vertex_x = x;
|
||||||
string_vertex_y = y;
|
string_vertex_y = y;
|
||||||
}
|
}
|
||||||
if(dx+dy+30<string_vertex_distance) string_vertex_done=1;
|
if (dx + dy + 30 < string_vertex_distance)
|
||||||
|
string_vertex_done = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void string_drag(magic_api * api, int which,
|
void string_drag(magic_api * api, int which,
|
||||||
SDL_Surface * canvas, SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
SDL_Surface * canvas, SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect)
|
||||||
SDL_Rect * update_rect)
|
|
||||||
{
|
{
|
||||||
if ((x<canvas->w)&&(y<canvas->h)&&(ox<canvas->w)&&(oy<canvas->h)&&((signed)x>0)&&((signed)y>0)&&((signed)ox>0)&&((signed)oy>0))
|
if ((x < canvas->w) && (y < canvas->h) && (ox < canvas->w) && (oy < canvas->h) && ((signed)x > 0) && ((signed)y > 0)
|
||||||
|
&& ((signed)ox > 0) && ((signed)oy > 0))
|
||||||
{
|
{
|
||||||
string_set_vertex(x, y);
|
string_set_vertex(x, y);
|
||||||
string_draw_wrapper((void *)api, which, canvas, snapshot, ox, oy, x, y, update_rect);
|
string_draw_wrapper((void *)api, which, canvas, snapshot, ox, oy, x, y, update_rect);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue