forked from old/legacy-imlib2
Polygons. Not filled ones yet =P Empty ones are easier ;-)
Hard to come up with a nice API for this, but here's what I have: ImlibPolygon imlib_polygon_new(int type); void imlib_polygon_free(ImlibPolygon poly); void imlib_polygon_add_point(ImlibPolygon poly, int x, int y); void imlib_image_draw_polygon(ImlibPolygon poly); Clipping works with these, as demonstrated by test/imlib2 The type paramter may be: POLY_OPEN, POLY_CLOSED or POLY_FILLED (last one not implemented yet). I was wondering if draw_polygon should genererate updates, like draw_line. Thoughts? SVN revision: 3279
This commit is contained in:
parent
cebd7a0c23
commit
b5ababf0b7
|
@ -248,6 +248,7 @@ void imlib_image_copy_rect(int x, int y, int width, int height, int new_x,int ne
|
||||||
ImlibPolygon imlib_polygon_new(int type);
|
ImlibPolygon imlib_polygon_new(int type);
|
||||||
void imlib_polygon_free(ImlibPolygon poly);
|
void imlib_polygon_free(ImlibPolygon poly);
|
||||||
void imlib_polygon_add_point(ImlibPolygon poly, int x, int y);
|
void imlib_polygon_add_point(ImlibPolygon poly, int x, int y);
|
||||||
|
void imlib_image_draw_polygon(ImlibPolygon poly);
|
||||||
|
|
||||||
Imlib_Color_Range imlib_create_color_range(void);
|
Imlib_Color_Range imlib_create_color_range(void);
|
||||||
void imlib_free_color_range(void);
|
void imlib_free_color_range(void);
|
||||||
|
|
28
src/api.c
28
src/api.c
|
@ -2720,3 +2720,31 @@ void imlib_polygon_free(ImlibPolygon poly)
|
||||||
__imlib_polygon_free(poly);
|
__imlib_polygon_free(poly);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void imlib_image_draw_polygon(ImlibPolygon poly)
|
||||||
|
{
|
||||||
|
ImlibImage *im;
|
||||||
|
|
||||||
|
CHECK_PARAM_POINTER("imlib_image_draw_polygon", "image", ctxt_image);
|
||||||
|
CAST_IMAGE(im, ctxt_image);
|
||||||
|
if ((!(im->data)) && (im->loader) && (im->loader->load))
|
||||||
|
im->loader->load(im, NULL, 0, 1);
|
||||||
|
if (!(im->data))
|
||||||
|
return;
|
||||||
|
__imlib_DirtyImage(im);
|
||||||
|
__imlib_DirtyPixmapsForImage(im);
|
||||||
|
if(ctxt_cliprect.w)
|
||||||
|
{
|
||||||
|
__imlib_draw_polygon_clipped(im, poly,
|
||||||
|
ctxt_cliprect.x,
|
||||||
|
ctxt_cliprect.x + ctxt_cliprect.w,
|
||||||
|
ctxt_cliprect.y,
|
||||||
|
ctxt_cliprect.y + ctxt_cliprect.h,
|
||||||
|
ctxt_color.red, ctxt_color.green,
|
||||||
|
ctxt_color.blue, ctxt_color.alpha, ctxt_operation);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
__imlib_draw_polygon(im, poly, ctxt_color.red, ctxt_color.green,
|
||||||
|
ctxt_color.blue, ctxt_color.alpha, ctxt_operation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1666,3 +1666,42 @@ void __imlib_polygon_free(ImlibPoly poly)
|
||||||
free(poly->points);
|
free(poly->points);
|
||||||
free(poly);
|
free(poly);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
__imlib_draw_polygon(ImlibImage * im, ImlibPoly poly, DATA8 r, DATA8 g,
|
||||||
|
DATA8 b, DATA8 a, ImlibOp op)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
if(!poly || !poly->points || (poly->pointcount < 2))
|
||||||
|
return;
|
||||||
|
|
||||||
|
for(i = 0; i < poly->pointcount; i++)
|
||||||
|
{
|
||||||
|
if(i < poly->pointcount - 1)
|
||||||
|
__imlib_draw_line(im, poly->points[i].x, poly->points[i].y, poly->points[i+1].x, poly->points[i+1].y, r, g, b, a, op, 0);
|
||||||
|
else if(poly->closed)
|
||||||
|
__imlib_draw_line(im, poly->points[i].x, poly->points[i].y, poly->points[0].x, poly->points[0].y, r, g, b, a, op, 0);
|
||||||
|
else break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
__imlib_draw_polygon_clipped(ImlibImage * im, ImlibPoly poly, int clip_xmin,
|
||||||
|
int clip_xmax, int clip_ymin, int clip_ymax, DATA8 r, DATA8 g, DATA8 b,
|
||||||
|
DATA8 a, ImlibOp op)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
if(!poly || !poly->points || (poly->pointcount < 2))
|
||||||
|
return;
|
||||||
|
|
||||||
|
for(i = 0; i < poly->pointcount; i++)
|
||||||
|
{
|
||||||
|
if(i < poly->pointcount - 1)
|
||||||
|
__imlib_draw_line_clipped(im, poly->points[i].x, poly->points[i].y, poly->points[i+1].x, poly->points[i+1].y, clip_xmin, clip_xmax, clip_ymin, clip_ymax, r, g, b, a, op, 0);
|
||||||
|
else if(poly->closed)
|
||||||
|
__imlib_draw_line_clipped(im, poly->points[i].x, poly->points[i].y, poly->points[0].x, poly->points[0].y, clip_xmin, clip_xmax, clip_ymin, clip_ymax, r, g, b, a, op, 0);
|
||||||
|
else break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,6 @@ struct _imlib_polygon
|
||||||
unsigned char closed, filled;
|
unsigned char closed, filled;
|
||||||
ImlibPoint *points;
|
ImlibPoint *points;
|
||||||
int pointcount;
|
int pointcount;
|
||||||
DATA8 r,g,b,a;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void __imlib_polygon_free(ImlibPoly poly);
|
void __imlib_polygon_free(ImlibPoly poly);
|
||||||
|
@ -60,6 +59,9 @@ void __imlib_copy_image_data(ImlibImage *im, int x, int y, int w, int h, int nx,
|
||||||
void __imlib_copy_alpha_data(ImlibImage *src, ImlibImage *dst, int x, int y, int w, int h, int nx, int ny);
|
void __imlib_copy_alpha_data(ImlibImage *src, ImlibImage *dst, int x, int y, int w, int h, int nx, int ny);
|
||||||
ImlibOutCode __imlib_comp_outcode(double x, double y, double xmin, double xmax,
|
ImlibOutCode __imlib_comp_outcode(double x, double y, double xmin, double xmax,
|
||||||
double ymin, double ymax);
|
double ymin, double ymax);
|
||||||
|
void
|
||||||
|
__imlib_draw_polygon(ImlibImage * im, ImlibPoly poly, DATA8 r, DATA8 g,
|
||||||
|
DATA8 b, DATA8 a, ImlibOp op);
|
||||||
ImlibUpdate *
|
ImlibUpdate *
|
||||||
__imlib_draw_line_clipped(ImlibImage * im, int x1, int y1, int x2, int y2,
|
__imlib_draw_line_clipped(ImlibImage * im, int x1, int y1, int x2, int y2,
|
||||||
int clip_xmin, int clip_xmax, int clip_ymin,
|
int clip_xmin, int clip_xmax, int clip_ymin,
|
||||||
|
@ -70,4 +72,8 @@ __imlib_draw_box_clipped(ImlibImage * im, int x, int y, int w, int h,
|
||||||
int clip_xmin, int clip_xmax, int clip_ymin,
|
int clip_xmin, int clip_xmax, int clip_ymin,
|
||||||
int clip_ymax, DATA8 r, DATA8 g, DATA8 b, DATA8 a,
|
int clip_ymax, DATA8 r, DATA8 g, DATA8 b, DATA8 a,
|
||||||
ImlibOp op);
|
ImlibOp op);
|
||||||
|
void
|
||||||
|
__imlib_draw_polygon_clipped(ImlibImage * im, ImlibPoly poly, int clip_xmin,
|
||||||
|
int clip_xmax, int clip_ymin, int clip_ymax, DATA8 r, DATA8 g, DATA8 b,
|
||||||
|
DATA8 a, ImlibOp op);
|
||||||
#endif
|
#endif
|
||||||
|
|
31
test/main.c
31
test/main.c
|
@ -79,6 +79,7 @@ int main (int argc, char **argv)
|
||||||
int origone = 0;
|
int origone = 0;
|
||||||
int bump_map_to_point = 0;
|
int bump_map_to_point = 0;
|
||||||
Imlib_Color_Modifier colormod = 0;
|
Imlib_Color_Modifier colormod = 0;
|
||||||
|
ImlibPolygon poly, poly2, poly3;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse all the command line arguments
|
* Parse all the command line arguments
|
||||||
|
@ -293,6 +294,21 @@ int main (int argc, char **argv)
|
||||||
gettimeofday(&timev,NULL);
|
gettimeofday(&timev,NULL);
|
||||||
sec1=(int)timev.tv_sec; /* and stores it so we can time outselves */
|
sec1=(int)timev.tv_sec; /* and stores it so we can time outselves */
|
||||||
usec1=(int)timev.tv_usec; /* we will use this to vary speed of rot */
|
usec1=(int)timev.tv_usec; /* we will use this to vary speed of rot */
|
||||||
|
|
||||||
|
poly = imlib_polygon_new(POLY_CLOSED);
|
||||||
|
imlib_polygon_add_point(poly, 400,50);
|
||||||
|
imlib_polygon_add_point(poly, 450,100);
|
||||||
|
imlib_polygon_add_point(poly, 350,100);
|
||||||
|
|
||||||
|
poly2 = imlib_polygon_new(POLY_OPEN);
|
||||||
|
imlib_polygon_add_point(poly2, 400,150);
|
||||||
|
imlib_polygon_add_point(poly2, 450,200);
|
||||||
|
imlib_polygon_add_point(poly2, 350,200);
|
||||||
|
|
||||||
|
poly3 = imlib_polygon_new(POLY_CLOSED);
|
||||||
|
imlib_polygon_add_point(poly3, 400,250);
|
||||||
|
imlib_polygon_add_point(poly3, 450,300);
|
||||||
|
imlib_polygon_add_point(poly3, 350,300);
|
||||||
|
|
||||||
if (loop)
|
if (loop)
|
||||||
{
|
{
|
||||||
|
@ -816,6 +832,21 @@ int main (int argc, char **argv)
|
||||||
imlib_image_draw_rectangle(30,120,50,50);
|
imlib_image_draw_rectangle(30,120,50,50);
|
||||||
up = imlib_update_append_rect(up, 30,120,50,50);
|
up = imlib_update_append_rect(up, 30,120,50,50);
|
||||||
|
|
||||||
|
imlib_context_set_cliprect(0,0,0,0);
|
||||||
|
|
||||||
|
/* test polygons */
|
||||||
|
imlib_context_set_color(255, 255, 255, 255);
|
||||||
|
imlib_image_draw_polygon(poly);
|
||||||
|
imlib_image_draw_polygon(poly2);
|
||||||
|
imlib_image_draw_polygon(poly3);
|
||||||
|
imlib_image_draw_rectangle(380,260,50,50);
|
||||||
|
|
||||||
|
imlib_context_set_color(255, 55, 55, 255);
|
||||||
|
imlib_context_set_cliprect(380,260,50,50);
|
||||||
|
imlib_image_draw_polygon(poly3);
|
||||||
|
imlib_context_set_cliprect(0,0,0,0);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
static Imlib_Color_Range rg = NULL;
|
static Imlib_Color_Range rg = NULL;
|
||||||
|
|
Loading…
Reference in New Issue