aboutsummaryrefslogtreecommitdiff
path: root/generic/Curve.c
diff options
context:
space:
mode:
authorlecoanet2001-11-12 09:55:06 +0000
committerlecoanet2001-11-12 09:55:06 +0000
commitd19f1f05bebe4aac95841345b91f9ba000e393d8 (patch)
tree6c33ad762bfe61fc3fb2af56daadd3fe3718faad /generic/Curve.c
parent68b099db66c52a7fe656be0709221c588465a019 (diff)
downloadtkzinc-d19f1f05bebe4aac95841345b91f9ba000e393d8.zip
tkzinc-d19f1f05bebe4aac95841345b91f9ba000e393d8.tar.gz
tkzinc-d19f1f05bebe4aac95841345b91f9ba000e393d8.tar.bz2
tkzinc-d19f1f05bebe4aac95841345b91f9ba000e393d8.tar.xz
Correction de l'attribut fillalpha sui doit forcer le recalcul de
la geom�trie. Les d�grad�s radiaux sont sensibles au facteur de forme global de l'item. R�alisation des reliefs.
Diffstat (limited to 'generic/Curve.c')
-rw-r--r--generic/Curve.c218
1 files changed, 131 insertions, 87 deletions
diff --git a/generic/Curve.c b/generic/Curve.c
index 7d7d698..cc1fead 100644
--- a/generic/Curve.c
+++ b/generic/Curve.c
@@ -117,7 +117,7 @@ static ZnAttrConfig cv_attrs[] = {
ZN_COORDS_FLAG, False },
{ ZN_CONFIG_GRADIENT, "-fillcolor", NULL,
Tk_Offset(CurveItemStruct, fill_color), 0,
- ZN_DRAW_FLAG|ZN_BORDER_FLAG, False },
+ ZN_COORDS_FLAG|ZN_BORDER_FLAG, False },
{ ZN_CONFIG_PATTERN, "-fillpattern", NULL,
Tk_Offset(CurveItemStruct, fill_pattern), 0, ZN_DRAW_FLAG, False },
{ ZN_CONFIG_BOOL, "-filled", NULL,
@@ -357,6 +357,9 @@ 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
}
@@ -727,98 +730,98 @@ ComputeCoordinates(Item item,
GetPolygonReliefBBox(points, num_points, (*cw ^ *holes)?-lw:lw, &bbox);
AddBBoxToBBox(&item->item_bounding_box, &bbox);
}
- return;
}
-
- holes = cv->shape.holes;
- c2 = cv->dev_shape.contours;
- for (j = 0; j < num_contours; j++, c2++, holes++) {
- if (!*holes) {
- AddPointsToBBox(&item->item_bounding_box, c2->points, c2->num_points);
- }
- }
-
- /*
- * Add the line width in all directions.
- * This overestimates the space needed to draw the polyline
- * but is simple.
- */
- item->item_bounding_box.orig.x -= lw;
- item->item_bounding_box.orig.y -= lw;
- item->item_bounding_box.corner.x += lw;
- item->item_bounding_box.corner.y += lw;
-
- /*
- * Take care of miters, markers and arrows.
- */
- holes = cv->shape.holes;
- c2 = cv->dev_shape.contours;
- for (j = 0; j < num_contours; j++, c2++, holes++) {
- if (*holes) {
- continue;
- }
- if (cv->join_style == JoinMiter) {
- ZnPoint miter_i, miter_o;
- for (i = c2->num_points-1, points = c2->points; i >= 3; i--, points++) {
- GetMiterPoints(points, points+1, points+2, lw, &miter_i, &miter_o);
- AddPointToBBox(&item->item_bounding_box, miter_i.x, miter_i.y);
- AddPointToBBox(&item->item_bounding_box, miter_o.x, miter_o.y);
+ else {
+ holes = cv->shape.holes;
+ c2 = cv->dev_shape.contours;
+ for (j = 0; j < num_contours; j++, c2++, holes++) {
+ if (!*holes) {
+ AddPointsToBBox(&item->item_bounding_box, c2->points, c2->num_points);
}
}
+
/*
- * Add the markers.
+ * Add the line width in all directions.
+ * This overestimates the space needed to draw the polyline
+ * but is simple.
*/
- if (ISSET(cv->flags, MARKER_OK)) {
- int w, h;
- ZnBBox bbox;
- Tk_SizeOfBitmap(wi->dpy, cv->marker, &w, &h);
- w = w/2 + 2;
- h = w/2 + 2;
+ item->item_bounding_box.orig.x -= lw;
+ item->item_bounding_box.orig.y -= lw;
+ item->item_bounding_box.corner.x += lw;
+ item->item_bounding_box.corner.y += lw;
+
+ /*
+ * Take care of miters, markers and arrows.
+ */
+ holes = cv->shape.holes;
+ c2 = cv->dev_shape.contours;
+ for (j = 0; j < num_contours; j++, c2++, holes++) {
+ if (*holes) {
+ continue;
+ }
+ if (cv->join_style == JoinMiter) {
+ ZnPoint miter_i, miter_o;
+ for (i = c2->num_points-1, points = c2->points; i >= 3; i--, points++) {
+ GetMiterPoints(points, points+1, points+2, lw, &miter_i, &miter_o);
+ AddPointToBBox(&item->item_bounding_box, miter_i.x, miter_i.y);
+ AddPointToBBox(&item->item_bounding_box, miter_o.x, miter_o.y);
+ }
+ }
+ /*
+ * Add the markers.
+ */
+ if (ISSET(cv->flags, MARKER_OK)) {
+ int w, h;
+ ZnBBox bbox;
+ Tk_SizeOfBitmap(wi->dpy, cv->marker, &w, &h);
+ w = w/2 + 2;
+ h = w/2 + 2;
+ num_points = c2->num_points;
+ for (i = 0, points = c2->points; i < num_points; i++, points++) {
+ bbox.orig.x = points->x - w;
+ bbox.orig.y = points->y - h;
+ bbox.corner.x = points->x + w;
+ bbox.corner.y = points->y + h;
+ AddBBoxToBBox(&item->item_bounding_box, &bbox);
+ }
+ }
+ /*
+ * Process arrows.
+ */
num_points = c2->num_points;
- for (i = 0, points = c2->points; i < num_points; i++, points++) {
- bbox.orig.x = points->x - w;
- bbox.orig.y = points->y - h;
- bbox.corner.x = points->x + w;
- bbox.corner.y = points->y + h;
- AddBBoxToBBox(&item->item_bounding_box, &bbox);
+ points = c2->points;
+ if (ISSET(cv->flags, FIRST_END_OK)) {
+ GetLineEnd(&points[0], &points[1], lw, cv->cap_style,
+ cv->first_end, end_points);
+ AddPointsToBBox(&item->item_bounding_box, end_points, LINE_END_POINTS);
+ }
+ if (ISSET(cv->flags, LAST_END_OK)) {
+ GetLineEnd(&points[num_points-1], &points[num_points-2],
+ lw, cv->cap_style, cv->last_end, end_points);
+ AddPointsToBBox(&item->item_bounding_box, end_points, LINE_END_POINTS);
}
}
+
/*
- * Process arrows.
+ * Expand again the bounding box by one pixel in all
+ * directions to take care of rounding errors.
*/
- num_points = c2->num_points;
- points = c2->points;
- if (ISSET(cv->flags, FIRST_END_OK)) {
- GetLineEnd(&points[0], &points[1], lw, cv->cap_style,
- cv->first_end, end_points);
- AddPointsToBBox(&item->item_bounding_box, end_points, LINE_END_POINTS);
- }
- if (ISSET(cv->flags, LAST_END_OK)) {
- GetLineEnd(&points[num_points-1], &points[num_points-2],
- lw, cv->cap_style, cv->last_end, end_points);
- AddPointsToBBox(&item->item_bounding_box, end_points, LINE_END_POINTS);
- }
+ item->item_bounding_box.orig.x -= 1;
+ item->item_bounding_box.orig.y -= 1;
+ item->item_bounding_box.corner.x += 1;
+ item->item_bounding_box.corner.y += 1;
}
-
- /*
- * Expand again the bounding box by one pixel in all
- * directions to take care of rounding errors.
- */
- item->item_bounding_box.orig.x -= 1;
- item->item_bounding_box.orig.y -= 1;
- item->item_bounding_box.corner.x += 1;
- item->item_bounding_box.corner.y += 1;
-
+
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;
+ int angle = cv->fill_color->g.angle;
ZnTransfo *transfo1, *transfo2;
- ZnPoint p[4];
- ZnBBox bbox;
+ ZnPoint p[4];
+ ZnBBox bbox;
+ if (!cv->grad_geo) {
+ cv->grad_geo = ZnMalloc(4*sizeof(ZnPoint));
+ }
transfo1 = ZnTransfoNew();
transfo2 = ZnTransfoNew();
ZnRotateDeg(transfo1, angle);
@@ -848,11 +851,18 @@ ComputeCoordinates(Item item,
ZnTransfoFree(transfo2);
}
else if (cv->fill_color->type == ZN_RADIAL_GRADIENT) {
- ZnReal dist, new, x0, x, y0, y;
-
+ 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]);
- x0 = cv->grad_geo[0].x;
- y0 = cv->grad_geo[0].y;
+ 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;
@@ -860,17 +870,21 @@ ComputeCoordinates(Item item,
if (*holes) {
continue;
}
- points = c1->points;
+ 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-x0)*(x-x0) + (y-y0)*(y-y0);
+ 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);
}
}
else {
@@ -1125,6 +1139,7 @@ Draw(Item item)
* Drawing with relief disables: ends, line style and line pattern.
*/
if (ISSET(cv->flags, RELIEF_OK)) {
+ relief = cv->relief;
for (j = 0; j < cv->dev_shape.num_contours; j++) {
num_points = cv->dev_shape.contours[j].num_points;
points = cv->dev_shape.contours[j].points;
@@ -1133,7 +1148,6 @@ Draw(Item item)
num_points, points[0].x, points[0].y,
points[num_points-1].x, points[num_points-1].y,cv->shape.holes[j],
cv->dev_shape.cw[j], cv->dev_shape.cw[j]^cv->shape.holes[j]);*/
- relief = cv->relief;
if (cv->dev_shape.cw[j]^cv->shape.holes[j]) {
switch (relief) {
case RELIEF_BEVEL_OUT:
@@ -1299,6 +1313,7 @@ Render(Item item)
ZnPoint *points;
XColor *color;
int alpha;
+ ReliefStyle relief;
if ((cv->dev_shape.num_contours == 0) ||
(ISCLEAR(cv->flags, FILLED_OK) &&
@@ -1342,12 +1357,41 @@ Render(Item item)
/*
* Drawing with relief disables: ends, line style and line pattern.
*/
+ alpha = cv->line_alpha*wi->alpha/100*65535/100;
if (ISSET(cv->flags, RELIEF_OK)) {
+ relief = cv->relief;
+ for (j = 0; j < cv->dev_shape.num_contours; j++) {
+ num_points = cv->dev_shape.contours[j].num_points;
+ points = cv->dev_shape.contours[j].points;
+ /*printf("Render: item %d, num_points %d %g@%g %g@%g, holes %d cw %d i/o %d\n",
+ item->id,
+ num_points, points[0].x, points[0].y,
+ points[num_points-1].x, points[num_points-1].y,cv->shape.holes[j],
+ cv->dev_shape.cw[j], cv->dev_shape.cw[j]^cv->shape.holes[j]);*/
+ if (cv->dev_shape.cw[j]^cv->shape.holes[j]) {
+ switch (relief) {
+ case RELIEF_BEVEL_OUT:
+ relief = RELIEF_BEVEL_IN;
+ break;
+ case RELIEF_BEVEL_IN:
+ relief = RELIEF_BEVEL_OUT;
+ break;
+ case RELIEF_RIDGE:
+ relief = RELIEF_GROOVE;
+ break;
+ case RELIEF_GROOVE:
+ relief = RELIEF_RIDGE;
+ break;
+ }
+ }
+ RenderPolygonRelief(wi, relief, cv->gradient, alpha,
+ False, points, num_points,
+ (cv->dev_shape.cw[j]^cv->shape.holes[j])?-cv->line_width:cv->line_width);
+ }
}
else {
color = cv->line_color;
- glColor4us(color->red, color->green, color->blue,
- cv->line_alpha*wi->alpha/100*65535/100);
+ glColor4us(color->red, color->green, color->blue, alpha);
if ((cv->line_width <= wi->max_line_width) &&
(cv->line_width <= wi->max_point_width)) {
glLineWidth(cv->line_width);