forked from old/legacy-imlib2
Better API, simpler polygon struct. imlib_polygon_new() now, no type member.
Then _draw_polygon(polygon, unsigned int closed), and _fill_polygon(poly). SVN revision: 3305
This commit is contained in:
parent
222e1b5f32
commit
e3d927d32c
|
@ -245,10 +245,11 @@ void imlib_image_scroll_rect(int x, int y, int width, int height, int delta_x, i
|
|||
void imlib_image_copy_rect(int x, int y, int width, int height, int new_x,int new_y);
|
||||
|
||||
/* polygons */
|
||||
ImlibPolygon imlib_polygon_new(int type);
|
||||
ImlibPolygon imlib_polygon_new(void);
|
||||
void imlib_polygon_free(ImlibPolygon poly);
|
||||
void imlib_polygon_add_point(ImlibPolygon poly, int x, int y);
|
||||
void imlib_image_draw_polygon(ImlibPolygon poly);
|
||||
void imlib_image_draw_polygon(ImlibPolygon poly, unsigned char closed);
|
||||
void imlib_image_fill_polygon(ImlibPolygon poly);
|
||||
void imlib_polygon_get_bounds(ImlibPolygon poly, int *px1, int *py1, int *px2, int *py2);
|
||||
|
||||
/* ellipses */
|
||||
|
|
41
src/api.c
41
src/api.c
|
@ -2762,9 +2762,9 @@ imlib_apply_filter(char *script, ...)
|
|||
}
|
||||
|
||||
ImlibPolygon
|
||||
imlib_polygon_new(int type)
|
||||
imlib_polygon_new(void)
|
||||
{
|
||||
return (ImlibPolygon) __imlib_polygon_new(type);
|
||||
return (ImlibPolygon) __imlib_polygon_new();
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -2782,7 +2782,7 @@ imlib_polygon_free(ImlibPolygon poly)
|
|||
}
|
||||
|
||||
void
|
||||
imlib_image_draw_polygon(ImlibPolygon poly)
|
||||
imlib_image_draw_polygon(ImlibPolygon poly, unsigned char closed)
|
||||
{
|
||||
ImlibImage *im;
|
||||
|
||||
|
@ -2796,7 +2796,7 @@ imlib_image_draw_polygon(ImlibPolygon poly)
|
|||
__imlib_DirtyPixmapsForImage(im);
|
||||
if (ctxt_cliprect.w)
|
||||
{
|
||||
__imlib_draw_polygon_clipped(im, poly, ctxt_cliprect.x,
|
||||
__imlib_draw_polygon_clipped(im, poly, closed, ctxt_cliprect.x,
|
||||
ctxt_cliprect.x + ctxt_cliprect.w,
|
||||
ctxt_cliprect.y,
|
||||
ctxt_cliprect.y + ctxt_cliprect.h,
|
||||
|
@ -2806,11 +2806,42 @@ imlib_image_draw_polygon(ImlibPolygon poly)
|
|||
}
|
||||
else
|
||||
{
|
||||
__imlib_draw_polygon(im, poly, ctxt_color.red, ctxt_color.green,
|
||||
__imlib_draw_polygon(im, poly, closed, ctxt_color.red, ctxt_color.green,
|
||||
ctxt_color.blue, ctxt_color.alpha, ctxt_operation);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
imlib_image_fill_polygon(ImlibPolygon poly)
|
||||
{
|
||||
ImlibImage *im;
|
||||
|
||||
CHECK_PARAM_POINTER("imlib_image_fill_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_filled_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_filled(im, poly, ctxt_color.red, ctxt_color.green,
|
||||
ctxt_color.blue, ctxt_color.alpha, ctxt_operation);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
imlib_polygon_get_bounds(ImlibPolygon poly, int *px1, int *py1, int *px2,
|
||||
int *py2)
|
||||
|
|
|
@ -1614,9 +1614,8 @@ imlib_clip_line(int x0, int y0, int x1, int y1, int xmin, int xmax, int ymin,
|
|||
return accept;
|
||||
}
|
||||
|
||||
ImlibOutCode
|
||||
__imlib_comp_outcode(double x, double y, double xmin, double xmax,
|
||||
double ymin, double ymax)
|
||||
ImlibOutCode __imlib_comp_outcode(double x, double y, double xmin,
|
||||
double xmax, double ymin, double ymax)
|
||||
{
|
||||
ImlibOutCode code = 0;
|
||||
|
||||
|
@ -1631,7 +1630,8 @@ __imlib_comp_outcode(double x, double y, double xmin, double xmax,
|
|||
return code;
|
||||
}
|
||||
|
||||
ImlibPoly __imlib_polygon_new(int type)
|
||||
ImlibPoly
|
||||
__imlib_polygon_new()
|
||||
{
|
||||
ImlibPoly poly;
|
||||
|
||||
|
@ -1639,19 +1639,6 @@ ImlibPoly __imlib_polygon_new(int type)
|
|||
if (!poly)
|
||||
return NULL;
|
||||
memset(poly, 0, sizeof(_ImlibPoly));
|
||||
switch (type)
|
||||
{
|
||||
case P_OPEN:
|
||||
break;
|
||||
case P_CLOSED:
|
||||
poly->closed = 1;
|
||||
break;
|
||||
case P_FILLED:
|
||||
poly->filled = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return poly;
|
||||
}
|
||||
|
||||
|
@ -1677,27 +1664,21 @@ __imlib_polygon_free(ImlibPoly poly)
|
|||
|
||||
|
||||
void
|
||||
__imlib_draw_polygon(ImlibImage * im, ImlibPoly poly, DATA8 r, DATA8 g,
|
||||
DATA8 b, DATA8 a, ImlibOp op)
|
||||
__imlib_draw_polygon(ImlibImage * im, ImlibPoly poly, unsigned char closed,
|
||||
DATA8 r, DATA8 g, DATA8 b, DATA8 a, ImlibOp op)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!poly || !poly->points || (poly->pointcount < 2))
|
||||
return;
|
||||
|
||||
if (poly->filled)
|
||||
{
|
||||
__imlib_draw_polygon_filled(im, poly, r, g, b, a, op);
|
||||
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)
|
||||
else if (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);
|
||||
|
@ -1707,7 +1688,8 @@ __imlib_draw_polygon(ImlibImage * im, ImlibPoly poly, DATA8 r, DATA8 g,
|
|||
}
|
||||
|
||||
void
|
||||
__imlib_draw_polygon_clipped(ImlibImage * im, ImlibPoly poly, int clip_xmin,
|
||||
__imlib_draw_polygon_clipped(ImlibImage * im, ImlibPoly poly,
|
||||
unsigned char closed, int clip_xmin,
|
||||
int clip_xmax, int clip_ymin, int clip_ymax,
|
||||
DATA8 r, DATA8 g, DATA8 b, DATA8 a, ImlibOp op)
|
||||
{
|
||||
|
@ -1716,14 +1698,6 @@ __imlib_draw_polygon_clipped(ImlibImage * im, ImlibPoly poly, int clip_xmin,
|
|||
if (!poly || !poly->points || (poly->pointcount < 2))
|
||||
return;
|
||||
|
||||
if (poly->filled)
|
||||
{
|
||||
__imlib_draw_polygon_filled_clipped(im, poly, clip_xmin, clip_xmax,
|
||||
clip_ymin, clip_ymax, r, g, b, a,
|
||||
op);
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < poly->pointcount; i++)
|
||||
{
|
||||
if (i < poly->pointcount - 1)
|
||||
|
@ -1732,7 +1706,7 @@ __imlib_draw_polygon_clipped(ImlibImage * im, ImlibPoly poly, int clip_xmin,
|
|||
poly->points[i + 1].y, clip_xmin,
|
||||
clip_xmax, clip_ymin, clip_ymax, r, g, b,
|
||||
a, op, 0);
|
||||
else if (poly->closed)
|
||||
else if (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,
|
||||
|
|
|
@ -44,14 +44,13 @@ typedef _ImlibPoly * ImlibPoly;
|
|||
|
||||
struct _imlib_polygon
|
||||
{
|
||||
unsigned char closed, filled;
|
||||
ImlibPoint *points;
|
||||
int pointcount;
|
||||
};
|
||||
|
||||
void __imlib_polygon_free(ImlibPoly poly);
|
||||
void __imlib_polygon_add_point(ImlibPoly poly, int x, int y);
|
||||
ImlibPoly __imlib_polygon_new(int type);
|
||||
ImlibPoly __imlib_polygon_new(void);
|
||||
|
||||
typedef unsigned int ImlibOutCode;
|
||||
enum
|
||||
|
@ -76,7 +75,7 @@ void __imlib_copy_alpha_data(ImlibImage *src, ImlibImage *dst, int x, int y, int
|
|||
ImlibOutCode __imlib_comp_outcode(double x, double y, double xmin, double xmax,
|
||||
double ymin, double ymax);
|
||||
void
|
||||
__imlib_draw_polygon(ImlibImage * im, ImlibPoly poly, DATA8 r, DATA8 g,
|
||||
__imlib_draw_polygon(ImlibImage * im, ImlibPoly poly, unsigned char closed, DATA8 r, DATA8 g,
|
||||
DATA8 b, DATA8 a, ImlibOp op);
|
||||
ImlibUpdate *
|
||||
__imlib_draw_line_clipped(ImlibImage * im, int x1, int y1, int x2, int y2,
|
||||
|
@ -89,7 +88,7 @@ __imlib_draw_box_clipped(ImlibImage * im, int x, int y, int w, int h,
|
|||
int clip_ymax, DATA8 r, DATA8 g, DATA8 b, DATA8 a,
|
||||
ImlibOp op);
|
||||
void
|
||||
__imlib_draw_polygon_clipped(ImlibImage * im, ImlibPoly poly, int clip_xmin,
|
||||
__imlib_draw_polygon_clipped(ImlibImage * im, ImlibPoly poly, unsigned char closed, int clip_xmin,
|
||||
int clip_xmax, int clip_ymin, int clip_ymax, DATA8 r, DATA8 g, DATA8 b,
|
||||
DATA8 a, ImlibOp op);
|
||||
void __imlib_polygon_get_bounds(ImlibPoly poly, int *px1, int *py1, int *px2, int *py2);
|
||||
|
|
14
test/main.c
14
test/main.c
|
@ -295,17 +295,17 @@ int main (int argc, char **argv)
|
|||
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 */
|
||||
|
||||
poly = imlib_polygon_new(POLY_FILLED);
|
||||
poly = imlib_polygon_new();
|
||||
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);
|
||||
poly2 = imlib_polygon_new();
|
||||
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);
|
||||
poly3 = imlib_polygon_new();
|
||||
imlib_polygon_add_point(poly3, 400,250);
|
||||
imlib_polygon_add_point(poly3, 450,300);
|
||||
imlib_polygon_add_point(poly3, 350,300);
|
||||
|
@ -849,15 +849,15 @@ int main (int argc, char **argv)
|
|||
|
||||
/* test polygons */
|
||||
imlib_context_set_color(255, 0, 0, 255);
|
||||
imlib_image_draw_polygon(poly);
|
||||
imlib_image_fill_polygon(poly);
|
||||
imlib_context_set_color(255, 255, 255, 255);
|
||||
imlib_image_draw_polygon(poly2);
|
||||
imlib_image_draw_polygon(poly3);
|
||||
imlib_image_draw_polygon(poly2,0);
|
||||
imlib_image_draw_polygon(poly3,1);
|
||||
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_image_draw_polygon(poly3,1);
|
||||
imlib_context_set_cliprect(0,0,0,0);
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue