From 47e0af9d913947e54d35b9bcade9a395749abd62 Mon Sep 17 00:00:00 2001 From: lecoanet Date: Tue, 22 Jan 2002 10:36:06 +0000 Subject: Ajout de la fonction RenderPolyline pour centraliser le dessin des lignes. --- generic/Draw.c | 146 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 142 insertions(+), 4 deletions(-) (limited to 'generic') diff --git a/generic/Draw.c b/generic/Draw.c index 555888a..95a6013 100644 --- a/generic/Draw.c +++ b/generic/Draw.c @@ -115,9 +115,9 @@ SetLineStyle(WidgetInfo *wi, case LINE_DOTTED : XSetDashes(wi->dpy, wi->gc, 0, dotted, 2); break; - default: - values.line_style = LineSolid; - break; + default: + values.line_style = LineSolid; + break; } XChangeGC(wi->dpy, wi->gc, GCLineStyle, &values); } @@ -942,6 +942,143 @@ RenderPolygonRelief(WidgetInfo *wi, } void +RenderPolyline(WidgetInfo *wi, + ZnPoint *points, + int num_points, + int line_width, + ZnBool closed, + LineStyle line_style, + int cap_style, + int join_style, + ZnLineEnd first_end, + ZnLineEnd last_end, + XColor *color, + int alpha) +{ + int num_clips = ZnListSize(wi->clip_stack); + ZnPoint end_points[LINE_END_POINTS]; + ZnBool need_rcaps, thin; + int pass, i, k, m; + ZnPoint c1, c2; + + /* + * The code below draws curves thiner than the min + * of GL_ALIASED_LINE_WIDTH_RANGE and GL_ALIASED_POINT_SIZE_RANGE + * with a mix of anti-aliased lines and points. The curves that + * are thicker are drawn using regular polygons. + * The joints are drawn only rounded, the caps can be either round + * or butt (but not projecting). + */ + thin = ((line_width <= wi->max_line_width) && + (line_width <= wi->max_point_width)); + glColor4us(color->red, color->green, color->blue, alpha); + SetLineStyle(wi, line_style); + glLineWidth(line_width); + glPointSize(line_width); + + for (pass = 0; pass < 2; pass++) { + if (pass == 0) { + glStencilFunc(GL_EQUAL, num_clips, 0xFF); + glStencilOp(GL_KEEP, GL_INCR, GL_INCR); + if (num_clips == 0) { + glEnable(GL_STENCIL_TEST); + } + } + else { + glStencilFunc(GL_EQUAL, num_clips+1, 0xFF); + glStencilOp(GL_KEEP, GL_DECR, GL_DECR); + glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); + } + if (first_end) { + GetLineEnd(&points[0], &points[1], line_width, cap_style, + first_end, end_points); + glBegin(GL_TRIANGLE_FAN); + for (m = 0; m < LINE_END_POINTS; m++) { + glVertex2f(end_points[m].x, end_points[m].y); + } + glEnd(); + } + if (last_end) { + GetLineEnd(&points[num_points-1], &points[num_points-2], + line_width, cap_style, last_end, end_points); + glBegin(GL_TRIANGLE_FAN); + for (m = 0; m < LINE_END_POINTS; m++) { + glVertex2f(end_points[m].x, end_points[m].y); + } + glEnd(); + } + if (thin) { + glBegin(GL_LINE_STRIP); + for (i = 0; i < num_points; i++) { + glVertex2f(points[i].x, points[i].y); + } + glEnd(); + } + else { + glBegin(GL_QUADS); + for (i = 0; i < num_points-1; i++) { + GetButtPoints(&points[i+1], &points[i], line_width, False, &c1, &c2); + glVertex2f(c1.x, c1.y); + glVertex2f(c2.x, c2.y); + GetButtPoints(&points[i], &points[i+1], line_width, False, &c1, &c2); + glVertex2f(c1.x, c1.y); + glVertex2f(c2.x, c2.y); + } + glEnd(); + } + + if (pass == 0) { + glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); + } + else { + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); + glStencilFunc(GL_EQUAL, num_clips, 0xFF); + if (num_clips == 0) { + glDisable(GL_STENCIL_TEST); + } + return; + } + need_rcaps = ((line_width > 1) && (cap_style == CapRound) && !closed); + i = 0; + k = num_points; + if (closed) { + k--; + } + if (!need_rcaps || first_end) { + i++; + } + if (!need_rcaps || last_end) { + k--; + } + if (thin) { + glBegin(GL_POINTS); + for ( ; i < k; i++) { + glVertex2f(points[i].x, points[i].y); + } + glEnd(); + } + else { + int num_cpoints; + ZnReal lw_2 = line_width / 2.0; + ZnPoint *cpoints = GetCirclePoints(3, ZN_CIRCLE_COARSE, + 0, 360, &num_cpoints, NULL); + + for ( ; i < k; i++) { + glBegin(GL_TRIANGLE_FAN); + glVertex2f(points[i].x, points[i].y); + for (m = 0; m < num_cpoints; m++) { + glVertex2f(points[i].x + cpoints[m].x*lw_2, + points[i].y + cpoints[m].y*lw_2); + } + glEnd(); + } + } + } +} + + +void RenderImage(struct _WidgetInfo *wi, ImageBits *image, /* ImageBits or BitmapBits */ XColor *color, @@ -1179,6 +1316,7 @@ RenderGradient(struct _WidgetInfo *wi, if (!cb && (type == ZN_AXIAL_GRADIENT)) { /* Render an aligned * axial gradient in the quad */ + angle = gradient->g.angle; /* * Adjust the quad for 90 180 and 270 degrees axial * gradients. Other angles not supported. @@ -1487,7 +1625,7 @@ getTCVI(TexFont *txf, } } /* ZnWarning("Tried to access unavailable texture font character");*/ - printf("Tried to access unavailable texture font character '%c'(%d)\n", c, c); + printf("Tried to access unavailable texture font character '%c'(\\0%o)\n", c, c); return txf->lut[(int)'!' - txf->min_glyph]; } -- cgit v1.1