aboutsummaryrefslogtreecommitdiff
path: root/generic/Curve.c
diff options
context:
space:
mode:
authorlecoanet2001-11-26 10:20:48 +0000
committerlecoanet2001-11-26 10:20:48 +0000
commitf1334599eb7771dd0749603a3bc3f4c1f3bab120 (patch)
tree5fe47c0a5c8e1b64d61681099d798e1700113626 /generic/Curve.c
parent6d04c4660278086fdf10964f4a29cdff59eadf43 (diff)
downloadtkzinc-f1334599eb7771dd0749603a3bc3f4c1f3bab120.zip
tkzinc-f1334599eb7771dd0749603a3bc3f4c1f3bab120.tar.gz
tkzinc-f1334599eb7771dd0749603a3bc3f4c1f3bab120.tar.bz2
tkzinc-f1334599eb7771dd0749603a3bc3f4c1f3bab120.tar.xz
Gestion des tristrips en interne sur le mod�le de gpc.
R�alisation du clipping non rectangulaire. Ajout du gradient PATH. Factorisation des gradients.
Diffstat (limited to 'generic/Curve.c')
-rw-r--r--generic/Curve.c170
1 files changed, 75 insertions, 95 deletions
diff --git a/generic/Curve.c b/generic/Curve.c
index cc1fead..ee48f7a 100644
--- a/generic/Curve.c
+++ b/generic/Curve.c
@@ -97,9 +97,7 @@ typedef struct _CurveItemStruct {
ZnImage tile;
ZnPoly dev_shape;
ZnGradient *gradient;
-#ifdef GPC
- gpc_tristrip tristrip;
-#endif
+ ZnTriStrip tristrip;
ZnPoint *grad_geo;
} CurveItemStruct, *CurveItem;
@@ -208,9 +206,7 @@ Init(Item item,
double dbl;
POLY_INIT(&cv->dev_shape);
-#ifdef GPC
cv->tristrip.num_strips = 0;
-#endif
cv->gradient = NULL;
cv->grad_geo = NULL;
@@ -357,9 +353,7 @@ Clone(Item item)
cv->line_color = ZnGetColorByValue(wi->win, cv->line_color);
cv->fill_color = ZnGetGradientByValue(cv->fill_color);
cv->marker_color = ZnGetColorByValue(wi->win, cv->marker_color);
-#ifdef GPC
cv->tristrip.num_strips = 0;
-#endif
}
@@ -411,11 +405,10 @@ Destroy(Item item)
ZnFreeGradient(cv->fill_color);
ZnFreeColor(cv->line_color);
ZnFreeColor(cv->marker_color);
-#ifdef GPC
+
if (cv->tristrip.num_strips) {
- gpc_free_tristrip(&cv->tristrip);
+ TRI_FREE(&cv->tristrip);
}
-#endif
}
@@ -654,11 +647,9 @@ ComputeCoordinates(Item item,
return;
}
-#ifdef GPC
if (cv->tristrip.num_strips) {
- gpc_free_tristrip(&cv->tristrip);
+ TRI_FREE(&cv->tristrip);
}
-#endif
/*
* Allocate space for devices coordinates, the holes array is _NOT_
@@ -813,78 +804,18 @@ ComputeCoordinates(Item item,
}
if (!ZnGradientFlat(cv->fill_color)) {
+ if (!cv->grad_geo) {
+ cv->grad_geo = ZnMalloc(4*sizeof(ZnPoint));
+ }
if (cv->fill_color->type == ZN_AXIAL_GRADIENT) {
- int angle = cv->fill_color->g.angle;
- ZnTransfo *transfo1, *transfo2;
- ZnPoint p[4];
- ZnBBox bbox;
-
- if (!cv->grad_geo) {
- cv->grad_geo = ZnMalloc(4*sizeof(ZnPoint));
- }
- transfo1 = ZnTransfoNew();
- transfo2 = ZnTransfoNew();
- ZnRotateDeg(transfo1, angle);
- ZnRotateDeg(transfo2, -angle);
- holes = cv->shape.holes;
- c1 = cv->shape.contours;
- ResetBBox(&bbox);
- for (j = 0; j < num_contours; j++, c1++, holes++) {
- if (*holes) {
- continue;
- }
- ZnListAssertSize(wi->work_pts, c1->num_points);
- points = ZnListArray(wi->work_pts);
- ZnTransformPoints(transfo1, c1->points, points, c1->num_points);
- AddPointsToBBox(&bbox, points, c1->num_points);
- }
- p[0] = bbox.orig;
- p[2] = bbox.corner;
- p[1].x = p[2].x;
- p[1].y = p[0].y;
- p[3].x = p[0].x;
- p[3].y = p[2].y;
- ZnTransfoSetIdentity(transfo1);
- ZnTransfoCompose(transfo1, transfo2, wi->current_transfo);
- ZnTransformPoints(transfo1, p, cv->grad_geo, 4);
- ZnTransfoFree(transfo1);
- ZnTransfoFree(transfo2);
+ ComputeAxialGradient(wi, &cv->shape, cv->fill_color->g.angle, cv->grad_geo);
}
else if (cv->fill_color->type == ZN_RADIAL_GRADIENT) {
- ZnReal dist, new, x, y, fact;
- ZnBBox *bbox = &item->item_bounding_box;
- ZnTransfo *transfo1;
-
- if (!cv->grad_geo) {
- cv->grad_geo = ZnMalloc(2*sizeof(ZnPoint));
- }
- ZnTransformPoint(wi->current_transfo, &cv->fill_color->g.p, &cv->grad_geo[0]);
- transfo1 = ZnTransfoNew();
- ZnTranslate(transfo1, -cv->grad_geo[0].x, -cv->grad_geo[0].y);
- fact = (bbox->corner.x-bbox->orig.x)/(bbox->corner.y-bbox->orig.y);
- ZnScale(transfo1, 1.0, fact);
- dist = 0.0;
- holes = cv->shape.holes;
- c1 = cv->dev_shape.contours;
- for (j = 0; j < num_contours; j++, c1++, holes++) {
- if (*holes) {
- continue;
- }
- ZnListAssertSize(wi->work_pts, c1->num_points);
- points = ZnListArray(wi->work_pts);
- ZnTransformPoints(transfo1, c1->points, points, c1->num_points);
- for (i = 0; i < c1->num_points; i++, points++) {
- x = points->x;
- y = points->y;
- new = x*x+y*y;
- if (new > dist) {
- dist = new;
- }
- }
- }
- cv->grad_geo[1].x = sqrt(dist) + 2; /* Max radius plus a fuzz factor */
- cv->grad_geo[1].y = cv->grad_geo[1].x / fact;
- ZnTransfoFree(transfo1);
+ ComputeRadialGradient(wi, &cv->dev_shape, &item->item_bounding_box,
+ &cv->fill_color->g.p, cv->grad_geo);
+ }
+ else if (cv->fill_color->type == ZN_PATH_GRADIENT) {
+ ZnTransformPoint(wi->current_transfo, &cv->fill_color->g.p, &cv->grad_geo[0]);
}
}
else {
@@ -1098,11 +1029,12 @@ Draw(Item item)
#ifdef GPC
if (cv->tristrip.num_strips == 0) {
- gpc_polygon_to_tristrip((gpc_polygon *) &cv->dev_shape, &cv->tristrip);
+ gpc_polygon_to_tristrip((gpc_polygon *) &cv->dev_shape,
+ (gpc_tristrip *) &cv->tristrip);
}
for (i = 0; i < cv->tristrip.num_strips; i++) {
- num_points = cv->tristrip.strip[i].num_vertices;
- points = (ZnPoint *) cv->tristrip.strip[i].vertex;
+ num_points = cv->tristrip.strips[i].num_points;
+ points = cv->tristrip.strips[i].points;
ZnListAssertSize(wi->work_xpts, num_points);
xpoints = (XPoint *) ZnListArray(wi->work_xpts);
for (j = 0; j < num_points; j++) {
@@ -1287,17 +1219,18 @@ CurveRenderCB(void *closure)
#ifdef GPC
if (cv->tristrip.num_strips == 0) {
- gpc_polygon_to_tristrip((gpc_polygon *) &cv->dev_shape, &cv->tristrip);
+ gpc_polygon_to_tristrip((gpc_polygon *) &cv->dev_shape,
+ (gpc_tristrip *) &cv->tristrip);
}
#else
#error "GPC needed to render filled curves with GLX"
#endif
for (i = 0; i < cv->tristrip.num_strips; i++) {
- num_points = cv->tristrip.strip[i].num_vertices;
- points = (ZnPoint *) cv->tristrip.strip[i].vertex;
+ num_points = cv->tristrip.strips[i].num_points;
+ points = cv->tristrip.strips[i].points;
glBegin(GL_TRIANGLE_STRIP);
- for (j = 0; j < num_points; j++) {
- glVertex2f(points[j].x, points[j].y);
+ for (j = 0; j < num_points; j++, points++) {
+ glVertex2f(points->x, points->y);
}
glEnd();
}
@@ -1328,7 +1261,7 @@ Render(Item item)
if (ISSET(cv->flags, FILLED_OK)) {
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
if (!ZnGradientFlat(cv->fill_color)) {
- RenderGradient(wi, cv->fill_color, CurveRenderCB, cv, cv->grad_geo);
+ RenderGradient(wi, cv->fill_color, CurveRenderCB, cv, cv->grad_geo, &cv->dev_shape);
}
else if (cv->tile != ZnUnspecifiedImage) { /* Fill tiled */
RenderTile(wi, GetImageTexture(wi->win, cv->tile_name, cv->tile),
@@ -1696,20 +1629,66 @@ PostScript(Item item,
*
* GetClipVertices --
* Get the clipping shape.
+ * Never ever call TRI_FREE on the tristrip returned by GetClipVertices.
*
**********************************************************************************
*/
static ZnBool
-GetClipVertices(Item item,
- ZnPoly *poly)
+GetClipVertices(Item item,
+ ZnTriStrip *tristrip)
{
CurveItem cv = (CurveItem) item;
+#ifndef GPC
+ ZnPoint *points;
+#endif
- POLY_INIT(poly);
+#ifdef GPC
+ if (cv->tristrip.num_strips == 0) {
+ gpc_polygon_to_tristrip((gpc_polygon *) &cv->dev_shape,
+ (gpc_tristrip *) &cv->tristrip);
+ }
+
+ if (cv->tristrip.num_strips == 1) {
+ TRI_STRIP1(tristrip,
+ cv->tristrip.strips[0].points,
+ cv->tristrip.strips[0].num_points);
+ }
+ else if (cv->tristrip.num_strips > 1) {
+ tristrip->num_strips = cv->tristrip.num_strips;
+ tristrip->strips = cv->tristrip.strips;
+ }
+
+ return False;
+#else
+ ZnListAssertSize(item->wi->work_pts, 2);
+ points = (ZnPoint *) ZnListArray(item->wi->work_pts);
+ TRI_STRIP1(tristrip, points, 2);
+ points[0] = item->item_bounding_box.orig;
+ points[1] = item->item_bounding_box.corner;
+
+ return True;
+#endif
+}
+
+
+/*
+ **********************************************************************************
+ *
+ * GetContours --
+ * Get the external contour(s).
+ * Never ever call POLY_FREE on the poly returned by GetContours.
+ *
+ **********************************************************************************
+ */
+static ZnBool
+GetContours(Item item,
+ ZnPoly *poly)
+{
+ CurveItem cv = (CurveItem) item;
if (cv->dev_shape.num_contours == 1) {
POLY_CONTOUR1(poly, cv->dev_shape.contours[0].points,
- cv->dev_shape.contours[0].num_points);
+ cv->dev_shape.contours[0].num_points);
}
else if (cv->dev_shape.num_contours > 1) {
poly->num_contours = cv->dev_shape.num_contours;
@@ -2031,6 +2010,7 @@ static ItemClassStruct CURVE_ITEM_CLASS = {
NULL, /* GetFieldSet */
NULL, /* GetAnchor */
GetClipVertices,
+ GetContours,
Coords,
NULL, /* InsertChars */
NULL, /* DeleteChars */