Lua: Fixed drawdisk which was drawing a square instead of a circle (doh!). Radius can now be a multiple of 0.5 to draw circles of even sizes (r=0 -> 1x1, r=0.5 -> 2x2, r=1 -> 3x3 etc.)
git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1798 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
parent
2f3e1e3294
commit
bf28d19f20
@ -457,30 +457,44 @@ int L_DrawCircle(lua_State* L)
|
|||||||
|
|
||||||
int L_DrawDisk(lua_State* L)
|
int L_DrawDisk(lua_State* L)
|
||||||
{
|
{
|
||||||
int center_x, center_y, r, c;
|
int center_x, center_y, diameter, c, r, even;
|
||||||
long circle_limit;
|
long circle_limit;
|
||||||
short x_pos,y_pos;
|
short x_pos,y_pos;
|
||||||
short min_x,max_x,min_y,max_y;
|
short min_x,max_x,min_y,max_y;
|
||||||
|
double r_float;
|
||||||
|
|
||||||
int nb_args = lua_gettop(L);
|
int nb_args = lua_gettop(L);
|
||||||
|
|
||||||
LUA_ARG_LIMIT(4, "drawdisk");
|
LUA_ARG_LIMIT(4, "drawdisk");
|
||||||
LUA_ARG_NUMBER(1, "drawdisk", center_x, INT_MIN, INT_MAX);
|
LUA_ARG_NUMBER(1, "drawdisk", center_x, INT_MIN, INT_MAX);
|
||||||
LUA_ARG_NUMBER(2, "drawdisk", center_y, INT_MIN, INT_MAX);
|
LUA_ARG_NUMBER(2, "drawdisk", center_y, INT_MIN, INT_MAX);
|
||||||
LUA_ARG_NUMBER(3, "drawdisk", r, INT_MIN, INT_MAX);
|
LUA_ARG_NUMBER(3, "drawdisk", r_float, INT_MIN, INT_MAX);
|
||||||
LUA_ARG_NUMBER(4, "drawdisk", c, INT_MIN, INT_MAX);
|
LUA_ARG_NUMBER(4, "drawdisk", c, INT_MIN, INT_MAX);
|
||||||
|
|
||||||
circle_limit = r*r;
|
if (r_float<0.0)
|
||||||
|
return 0;
|
||||||
|
diameter=(int)(floor(r_float*2.0+1.0));
|
||||||
|
r=diameter/2;
|
||||||
|
even=!(diameter&1);
|
||||||
|
|
||||||
|
circle_limit = Circle_squared_diameter(diameter);
|
||||||
|
|
||||||
// Compute clipping limits
|
// Compute clipping limits
|
||||||
min_x=center_x-r<0 ? 0 : center_x-r;
|
min_x=center_x-r+even<0 ? 0 : center_x-r+even;
|
||||||
max_x=center_x+r>=Main_image_width? Main_image_width-1 : center_x+r;
|
max_x=center_x+r>=Main_image_width? Main_image_width-1 : center_x+r;
|
||||||
min_y=center_y-r<0 ? 0 : center_y-r;
|
min_y=center_y-r+even<0 ? 0 : center_y-r+even;
|
||||||
max_y=center_y+r>=Main_image_height? Main_image_height-1 : center_y+r;
|
max_y=center_y+r>=Main_image_height? Main_image_height-1 : center_y+r;
|
||||||
|
|
||||||
for (y_pos=min_y;y_pos<=max_y;y_pos++)
|
for (y_pos=min_y;y_pos<=max_y;y_pos++)
|
||||||
|
{
|
||||||
|
short y=(y_pos-center_y)*2-even;
|
||||||
for (x_pos=min_x;x_pos<=max_x;x_pos++)
|
for (x_pos=min_x;x_pos<=max_x;x_pos++)
|
||||||
Pixel_in_current_screen(x_pos,y_pos,c,0);
|
{
|
||||||
|
short x=(x_pos-center_x)*2-even;
|
||||||
|
if (x*x+y*y <= circle_limit)
|
||||||
|
Pixel_in_current_screen(x_pos,y_pos,c,0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
14
src/graph.c
14
src/graph.c
@ -1340,6 +1340,20 @@ void Draw_filled_circle(short center_x,short center_y,short radius,byte color)
|
|||||||
Update_part_of_screen(start_x,start_y,end_x+1-start_x,end_y+1-start_y);
|
Update_part_of_screen(start_x,start_y,end_x+1-start_x,end_y+1-start_y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Circle_squared_diameter(int diameter)
|
||||||
|
{
|
||||||
|
int result = diameter*diameter;
|
||||||
|
// Trick to make some circles rounder, even though
|
||||||
|
// mathematically incorrect.
|
||||||
|
if (diameter==3 || diameter==9)
|
||||||
|
return result-2;
|
||||||
|
if (diameter==11)
|
||||||
|
return result-6;
|
||||||
|
if (diameter==14)
|
||||||
|
return result-4;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
// -- Tracer général d'une ellipse vide -----------------------------------
|
// -- Tracer général d'une ellipse vide -----------------------------------
|
||||||
|
|
||||||
|
|||||||
@ -66,6 +66,8 @@ void Hide_empty_circle_preview (short center_x,short center_y,short radius);
|
|||||||
void Draw_empty_circle_general(short center_x,short center_y,short radius,byte color);
|
void Draw_empty_circle_general(short center_x,short center_y,short radius,byte color);
|
||||||
void Draw_filled_circle (short center_x,short center_y,short radius,byte color);
|
void Draw_filled_circle (short center_x,short center_y,short radius,byte color);
|
||||||
|
|
||||||
|
int Circle_squared_diameter(int diameter);
|
||||||
|
|
||||||
void Draw_empty_ellipse_permanent(short center_x,short center_y,short horizontal_radius,short vertical_radius,byte color);
|
void Draw_empty_ellipse_permanent(short center_x,short center_y,short horizontal_radius,short vertical_radius,byte color);
|
||||||
void Draw_empty_ellipse_preview (short center_x,short center_y,short horizontal_radius,short vertical_radius,byte color);
|
void Draw_empty_ellipse_preview (short center_x,short center_y,short horizontal_radius,short vertical_radius,byte color);
|
||||||
void Hide_empty_ellipse_preview (short center_x,short center_y,short horizontal_radius,short vertical_radius);
|
void Hide_empty_ellipse_preview (short center_x,short center_y,short horizontal_radius,short vertical_radius);
|
||||||
|
|||||||
@ -37,21 +37,6 @@
|
|||||||
|
|
||||||
//---------------------- Modifier le pinceau spécial -------------------------
|
//---------------------- Modifier le pinceau spécial -------------------------
|
||||||
|
|
||||||
int Circle_squared_diameter(int diameter)
|
|
||||||
{
|
|
||||||
int result = diameter*diameter;
|
|
||||||
// Trick to make some circles rounder, even though
|
|
||||||
// mathematically incorrect.
|
|
||||||
if (diameter==3 || diameter==9)
|
|
||||||
return result-2;
|
|
||||||
if (diameter==11)
|
|
||||||
return result-6;
|
|
||||||
if (diameter==14)
|
|
||||||
return result-4;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Set_paintbrush_size(int width, int height)
|
void Set_paintbrush_size(int width, int height)
|
||||||
{
|
{
|
||||||
int x_pos,y_pos;
|
int x_pos,y_pos;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user