aboutsummaryrefslogtreecommitdiff
path: root/generic/Curve.c
diff options
context:
space:
mode:
authorlecoanet2003-05-09 14:58:40 +0000
committerlecoanet2003-05-09 14:58:40 +0000
commitbfcc3438325ba1b9ebce8fb8a7ed66e0d0e84bd1 (patch)
tree39a63d2e2adea5f9064daf0f62c9f46a3f467b55 /generic/Curve.c
parent84f41cc1d6e3ed41ed7f036f3e9f1d1ddad8bd05 (diff)
downloadtkzinc-bfcc3438325ba1b9ebce8fb8a7ed66e0d0e84bd1.zip
tkzinc-bfcc3438325ba1b9ebce8fb8a7ed66e0d0e84bd1.tar.gz
tkzinc-bfcc3438325ba1b9ebce8fb8a7ed66e0d0e84bd1.tar.bz2
tkzinc-bfcc3438325ba1b9ebce8fb8a7ed66e0d0e84bd1.tar.xz
* (Contour): Allocation of points and control arrays is controlled
by the Contour procedure in tkZinc.c so there no point in duplicating the effort here. Moreover the extra space is never deallocated. * (Render): Fixed the pattern filling under openGL. Stippling can't be used to fill patterns. Now texture mapping is used instead. As a side effect -fillpattern and -tile use the same internal variable reducing memory requirements. * (Init): Properly initialize the winding direction of the first contour given at creation time.
Diffstat (limited to 'generic/Curve.c')
-rw-r--r--generic/Curve.c68
1 files changed, 25 insertions, 43 deletions
diff --git a/generic/Curve.c b/generic/Curve.c
index b58c59a..912ed16 100644
--- a/generic/Curve.c
+++ b/generic/Curve.c
@@ -79,7 +79,6 @@ typedef struct _CurveItemStruct {
int join_style;
ZnReliefStyle relief;
ZnDim line_width; /* If 0 the path is not drawn, if <2 relief is flat */
- ZnImage fill_pattern;
ZnGradient *fill_color;
ZnImage line_pattern;
ZnGradient *line_color;
@@ -115,7 +114,7 @@ static ZnAttrConfig cv_attrs[] = {
{ ZN_CONFIG_BOOL, "-filled", NULL,
Tk_Offset(CurveItemStruct, flags), FILLED_BIT, ZN_COORDS_FLAG, False },
{ ZN_CONFIG_BITMAP, "-fillpattern", NULL,
- Tk_Offset(CurveItemStruct, fill_pattern), 0, ZN_DRAW_FLAG, False },
+ Tk_Offset(CurveItemStruct, tile), 0, ZN_DRAW_FLAG, False },
{ ZN_CONFIG_FILL_RULE, "-fillrule", NULL,
Tk_Offset(CurveItemStruct, fill_rule), 0, ZN_COORDS_FLAG, False },
{ ZN_CONFIG_LINE_END, "-firstend", NULL,
@@ -246,7 +245,7 @@ Init(ZnItem item,
/*printf("plain contour, numpoints: %d %g@%g\n",
num_points, points[0].x, points[0].y);*/
memcpy(p, points, num_points * sizeof(ZnPoint));
- ZnPolyContour1(&cv->shape, p, num_points, False);
+ ZnPolyContour1(&cv->shape, p, num_points, !ZnTestCCW(p, num_points));
cv->shape.contours[0].controls = controls;
}
(*args)++;
@@ -259,7 +258,6 @@ Init(ZnItem item,
cv->relief = ZN_RELIEF_FLAT;
cv->line_width = 1;
cv->tile = ZnUnspecifiedImage;
- cv->fill_pattern = ZnUnspecifiedImage;
cv->line_pattern = ZnUnspecifiedImage;
cv->cap_style = CapRound;
cv->join_style = JoinRound;
@@ -328,9 +326,6 @@ Clone(ZnItem item)
if (cv->line_pattern != ZnUnspecifiedImage) {
cv->line_pattern = ZnGetImageByValue(cv->line_pattern);
}
- if (cv->fill_pattern != ZnUnspecifiedImage) {
- cv->fill_pattern = ZnGetImageByValue(cv->fill_pattern);
- }
if (cv->marker != ZnUnspecifiedImage) {
cv->marker = ZnGetImageByValue(cv->marker);
}
@@ -389,10 +384,6 @@ Destroy(ZnItem item)
ZnFreeImage(cv->line_pattern);
cv->line_pattern = ZnUnspecifiedImage;
}
- if (cv->fill_pattern != ZnUnspecifiedImage) {
- ZnFreeImage(cv->fill_pattern);
- cv->fill_pattern = ZnUnspecifiedImage;
- }
if (cv->marker != ZnUnspecifiedImage) {
ZnFreeImage(cv->marker);
cv->marker = ZnUnspecifiedImage;
@@ -652,7 +643,7 @@ UpdateTristrip(CurveItem cv,
for (j = 0; j < poly->num_contours; j++){
gluTessBeginContour(wi->tess);
/*printf("Début contour %d num_points %d\n",
- j, poly->contours[j].num_points);*/
+ j, poly->contours[j].num_points);*/
for (k = 0; k < poly->contours[j].num_points; k++) {
/*printf("%g@%g ", poly->contours[j].points[k].x, poly->contours[j].points[k].y);*/
v[0] = poly->contours[j].points[k].x;
@@ -660,7 +651,7 @@ UpdateTristrip(CurveItem cv,
v[2] = 0;
gluTessVertex(wi->tess, v, &poly->contours[j].points[k]);
}
- /*printf("\n");*/
+ /*printf("\n");*/
gluTessEndContour(wi->tess);
}
}
@@ -668,7 +659,7 @@ UpdateTristrip(CurveItem cv,
for (j = 0; j < poly->num_contours; j++){
gluTessBeginContour(wi->tess);
/*printf("revert Début contour %d num_points %d\n",
- j, poly->contours[j].num_points);*/
+ j, poly->contours[j].num_points);*/
for (i = (int) (poly->contours[j].num_points-1); i >= 0; i--) {
/*printf("%g@%g ", poly->contours[j].points[i].x, poly->contours[j].points[i].y);*/
v[0] = poly->contours[j].points[i].x;
@@ -1226,19 +1217,21 @@ Draw(ZnItem item)
if (ISSET(cv->flags, FILLED_OK)) {
values.foreground = ZnPixel(ZnGetGradientColor(cv->fill_color, 0.0, NULL));
gc_mask = GCFillStyle;
- if (cv->tile != ZnUnspecifiedImage) { /* Fill tiled */
- values.fill_style = FillTiled;
- values.tile = ZnImagePixmap(cv->tile);
- values.ts_x_origin = ZnNearestInt(item->item_bounding_box.orig.x);
- values.ts_y_origin = ZnNearestInt(item->item_bounding_box.orig.y);
- gc_mask |= GCTileStipXOrigin|GCTileStipYOrigin|GCTile;
- }
- else if (cv->fill_pattern != ZnUnspecifiedImage) { /* Fill stippled */
- values.fill_style = FillStippled;
- values.stipple = ZnImagePixmap(cv->fill_pattern);
- values.ts_x_origin = ZnNearestInt(item->item_bounding_box.orig.x);
- values.ts_y_origin = ZnNearestInt(item->item_bounding_box.orig.y);
- gc_mask |= GCTileStipXOrigin|GCTileStipYOrigin|GCStipple|GCForeground;
+ if (cv->tile != ZnUnspecifiedImage) {
+ if (!ZnImageIsBitmap(cv->tile)) { /* Fill tiled */
+ values.fill_style = FillTiled;
+ values.tile = ZnImagePixmap(cv->tile);
+ values.ts_x_origin = ZnNearestInt(item->item_bounding_box.orig.x);
+ values.ts_y_origin = ZnNearestInt(item->item_bounding_box.orig.y);
+ gc_mask |= GCTileStipXOrigin|GCTileStipYOrigin|GCTile;
+ }
+ else { /* Fill stippled */
+ values.fill_style = FillStippled;
+ values.stipple = ZnImagePixmap(cv->tile);
+ values.ts_x_origin = ZnNearestInt(item->item_bounding_box.orig.x);
+ values.ts_y_origin = ZnNearestInt(item->item_bounding_box.orig.y);
+ gc_mask |= GCTileStipXOrigin|GCTileStipYOrigin|GCStipple|GCForeground;
+ }
}
else { /* Fill solid */
values.fill_style = FillSolid;
@@ -1467,23 +1460,15 @@ Render(ZnItem item)
ZnRenderGradient(wi, cv->fill_color, CurveRenderCB, cv, cv->grad_geo,
&cv->outlines);
}
- else if (cv->tile != ZnUnspecifiedImage) { /* Fill tiled */
+ else if (cv->tile != ZnUnspecifiedImage) { /* Fill tiled/stippled */
ZnRenderTile(wi, cv->tile, cv->fill_color, CurveRenderCB, cv,
(ZnPoint *) &item->item_bounding_box);
}
else {
- if (cv->fill_pattern != ZnUnspecifiedImage) { /* Fill stippled */
- /*
- * Setup polygon stippling.
- */
- glEnable(GL_POLYGON_STIPPLE);
- glPolygonStipple(ZnImageMask(cv->fill_pattern, NULL));
- }
color = ZnGetGradientColor(cv->fill_color, 0.0, &alpha);
alpha = ZnComposeAlpha(alpha, wi->alpha);
glColor4us(color->red, color->green, color->blue, alpha);
CurveRenderCB(cv);
- glDisable(GL_POLYGON_STIPPLE);
}
}
@@ -1505,7 +1490,8 @@ Render(ZnItem item)
num_points, points[0].x, points[0].y,
points[num_points-1].x, points[num_points-1].y,
cv->outlines.contours[j].cw);*/
- ZnRenderPolygonRelief(wi, cv->relief, cv->gradient, ISSET(cv->flags, SMOOTH_RELIEF_BIT),
+ ZnRenderPolygonRelief(wi, cv->relief, cv->gradient,
+ ISSET(cv->flags, SMOOTH_RELIEF_BIT),
points, num_points, cv->line_width);
}
}
@@ -2148,18 +2134,14 @@ Contour(ZnItem item,
for (j = 0; j < poly->num_contours; j++, index++) {
cv->shape.contours[index].num_points = poly->contours[j].num_points;
cv->shape.contours[index].cw = poly->contours[j].cw;
- cv->shape.contours[index].points = ZnMalloc(poly->contours[j].num_points * sizeof(ZnPoint));
- memcpy(cv->shape.contours[index].points, poly->contours[j].points,
- poly->contours[j].num_points * sizeof(ZnPoint));
+ cv->shape.contours[index].points = poly->contours[j].points;
cv->shape.contours[index].controls = NULL;
if (poly->contours[j].controls) {
/*
* The controls array in poly is shared, duplicate it
* to keep a locally owned copy.
*/
- cv->shape.contours[index].controls = ZnMalloc(poly->contours[j].num_points * sizeof(char));
- memcpy(cv->shape.contours[index].controls, poly->contours[j].controls,
- poly->contours[j].num_points * sizeof(char));
+ cv->shape.contours[index].controls = poly->contours[j].controls;
}
}
cv->shape.num_contours = num_contours;