From 75fcaa22f29f8c7b91247611fb45a1bdf667dbd6 Mon Sep 17 00:00:00 2001 From: lecoanet Date: Mon, 16 Jun 2003 14:41:13 +0000 Subject: * Simplified the gradient prep/drawing interface. * Use of the new ZnGetGradientPixel function in X * (Pick): Changed the picking method used for curve interiors. The new one is based on triangle strips/fans not on the outlines. --- generic/Curve.c | 87 ++++++++++++++++++++++++--------------------------------- 1 file changed, 36 insertions(+), 51 deletions(-) (limited to 'generic') diff --git a/generic/Curve.c b/generic/Curve.c index 912ed16..5c1e8cc 100644 --- a/generic/Curve.c +++ b/generic/Curve.c @@ -1014,16 +1014,7 @@ ComputeCoordinates(ZnItem item, if (!cv->grad_geo) { cv->grad_geo = ZnMalloc(6*sizeof(ZnPoint)); } - if (cv->fill_color->type == ZN_AXIAL_GRADIENT) { - ZnComputeAxialGradient(wi, &cv->shape, (ZnReal) cv->fill_color->g.angle, - cv->grad_geo); - } - else if (cv->fill_color->type == ZN_RADIAL_GRADIENT) { - ZnComputeRadialGradient(wi, &cv->shape, False, &cv->fill_color->g.p, cv->grad_geo); - } - else if (cv->fill_color->type == ZN_PATH_GRADIENT) { - ZnComputePathGradient(wi, &cv->shape, &cv->fill_color->g.p, cv->grad_geo); - } + ZnComputeGradient(cv->fill_color, wi, &cv->shape, cv->grad_geo); } else { if (cv->grad_geo) { @@ -1215,7 +1206,7 @@ Draw(ZnItem item) * Fill if requested. */ if (ISSET(cv->flags, FILLED_OK)) { - values.foreground = ZnPixel(ZnGetGradientColor(cv->fill_color, 0.0, NULL)); + values.foreground = ZnGetGradientPixel(cv->fill_color, 0.0); gc_mask = GCFillStyle; if (cv->tile != ZnUnspecifiedImage) { if (!ZnImageIsBitmap(cv->tile)) { /* Fill tiled */ @@ -1296,7 +1287,7 @@ Draw(ZnItem item) } else { ZnSetLineStyle(wi, cv->line_style); - values.foreground = ZnPixel(ZnGetGradientColor(cv->line_color, 0.0, NULL)); + values.foreground = ZnGetGradientPixel(cv->line_color, 0.0); values.line_width = (cv->line_width == 1) ? 0 : (int) cv->line_width; values.join_style = cv->join_style; values.cap_style = cv->cap_style; @@ -1363,7 +1354,7 @@ Draw(ZnItem item) h_height = (height+1)/2; values.fill_style = FillStippled; values.stipple = ZnImagePixmap(cv->marker); - values.foreground = ZnPixel(ZnGetGradientColor(cv->marker_color, 0.0, NULL)); + values.foreground = ZnGetGradientPixel(cv->marker_color, 0.0); XChangeGC(wi->dpy, wi->gc, GCFillStyle|GCStipple|GCForeground, &values); for (j = 0; j < cv->outlines.num_contours; j++) { num_points = cv->outlines.contours[j].num_points; @@ -1436,8 +1427,6 @@ Render(ZnItem item) CurveItem cv = (CurveItem) item; unsigned int j, num_points; ZnPoint *points; - XColor *color; - unsigned short alpha; if ((cv->outlines.num_contours == 0) || (ISCLEAR(cv->flags, FILLED_OK) && @@ -1465,7 +1454,8 @@ Render(ZnItem item) (ZnPoint *) &item->item_bounding_box); } else { - color = ZnGetGradientColor(cv->fill_color, 0.0, &alpha); + unsigned short alpha; + XColor *color = ZnGetGradientColor(cv->fill_color, 0.0, &alpha); alpha = ZnComposeAlpha(alpha, wi->alpha); glColor4us(color->red, color->green, color->blue, alpha); CurveRenderCB(cv); @@ -1479,8 +1469,6 @@ Render(ZnItem item) /* * Drawing with relief disables: ends, line style and line pattern. */ - ZnGetGradientColor(cv->line_color, 0.0, &alpha); - alpha = ZnComposeAlpha(alpha, wi->alpha); if (ISSET(cv->flags, RELIEF_OK)) { for (j = 0; j < cv->outlines.num_contours; j++) { num_points = cv->outlines.contours[j].num_points; @@ -1496,15 +1484,15 @@ Render(ZnItem item) } } else { - ZnLineEnd first = ISSET(cv->flags, FIRST_END_OK) ? cv->first_end : NULL; - ZnLineEnd last = ISSET(cv->flags, LAST_END_OK) ? cv->last_end : NULL; + ZnLineEnd first = ISSET(cv->flags, FIRST_END_OK) ? cv->first_end : NULL; + ZnLineEnd last = ISSET(cv->flags, LAST_END_OK) ? cv->last_end : NULL; for (j = 0; j < cv->outlines.num_contours; j++) { ZnRenderPolyline(wi, cv->outlines.contours[j].points, cv->outlines.contours[j].num_points, - cv->line_width, cv->line_style, cv->cap_style, cv->join_style, - first, last, cv->line_color); + cv->line_width, cv->line_style, cv->cap_style, + cv->join_style, first, last, cv->line_color); } } } @@ -1585,7 +1573,8 @@ Pick(ZnItem item, double dist=1.0e40, new_dist; ZnPoint *points, *p = ps->point; ZnPoint end_points[ZN_LINE_END_POINTS]; - unsigned int num_points, i; + ZnPoint triangle[3]; + unsigned int num_points, i, j, stop; int width, height; if (cv->outlines.num_contours == 0) { @@ -1594,40 +1583,36 @@ Pick(ZnItem item, /*printf("Pick in curve\n");*/ if (ISSET(cv->flags, FILLED_OK)) { - double hole_dist=1.0e40, new_hole_dist; - /* - * Check all contours. Compute distance to holes - * in the same pass. - */ - for (i = 0; i < cv->outlines.num_contours; i++) { - if (cv->outlines.contours[i].cw) { - new_hole_dist = ZnPolygonToPointDist(cv->outlines.contours[i].points, - cv->outlines.contours[i].num_points, p); - if (new_hole_dist < hole_dist) { - hole_dist = new_hole_dist; - } + for (i = 0; i < cv->tristrip.num_strips; i++) { + num_points = cv->tristrip.strips[i].num_points; + points = cv->tristrip.strips[i].points; + j = 0; + stop = num_points-2; + if (cv->tristrip.strips[i].fan) { + triangle[0] = points[0]; + j++; + points++; + stop++; } - else { - new_dist = ZnPolygonToPointDist(cv->outlines.contours[i].points, - cv->outlines.contours[i].num_points, p); + for (; j < stop; j++, points++) { + if (cv->tristrip.strips[i].fan) { + triangle[1] = points[0]; + triangle[2] = points[1]; + } + else { + triangle[0] = points[0]; + triangle[1] = points[1]; + triangle[2] = points[2]; + } + new_dist = ZnPolygonToPointDist(triangle, 3, p); if (new_dist < dist) { dist = new_dist; } + if (dist <= 0.0) { + return 0.0; + } } } - if ((dist <= 0.0) && (hole_dist >= 0.0)) { - /*printf("dist %g hole dist: %g\n", dist, hole_dist);*/ - return 0.0; - } - if (hole_dist < 0.0) { - hole_dist = -hole_dist; - } - if (dist <= 0.0) { - dist = hole_dist; - } - else if (hole_dist < dist) { - dist = hole_dist; - } } if (cv->line_width > 0) { -- cgit v1.1