diff options
Diffstat (limited to 'generic')
-rw-r--r-- | generic/Arc.c | 142 | ||||
-rw-r--r-- | generic/Rectangle.c | 141 |
2 files changed, 154 insertions, 129 deletions
diff --git a/generic/Arc.c b/generic/Arc.c index 155bc06..080d57f 100644 --- a/generic/Arc.c +++ b/generic/Arc.c @@ -33,8 +33,9 @@ #include "Geo.h" #include "Draw.h" #include "Types.h" -#include "WidgetInfo.h" #include "Image.h" +#include "WidgetInfo.h" +#include "tkZinc.h" static const char rcsid[] = "$Id$"; @@ -160,8 +161,8 @@ Init(Item item, { WidgetInfo *wi = item->wi; ArcItem arc = (ArcItem) item; - Tcl_Obj **elems; - int num_elems; + int num_points; + ZnPoint *points; /* Init attributes */ SET(item->flags, VISIBLE_BIT); @@ -190,15 +191,15 @@ Init(Item item, Tcl_AppendResult(wi->interp, " arc coords expected", NULL); return ZN_ERROR; } - if ((Tcl_ListObjGetElements(wi->interp, (*args)[0], &num_elems, &elems) == ZN_ERROR) || - (num_elems != 4) || - (Tcl_GetDoubleFromObj(wi->interp, elems[0], &arc->coords[0].x) == ZN_ERROR) || - (Tcl_GetDoubleFromObj(wi->interp, elems[1], &arc->coords[0].y) == ZN_ERROR) || - (Tcl_GetDoubleFromObj(wi->interp, elems[2], &arc->coords[1].x) == ZN_ERROR) || - (Tcl_GetDoubleFromObj(wi->interp, elems[3], &arc->coords[1].y) == ZN_ERROR)) { + if (ZnParseCoordList(wi, (*args)[0], &points, NULL, &num_points) == ZN_ERROR) { + return ZN_ERROR; + } + if (num_points != 2) { Tcl_AppendResult(wi->interp, " malformed arc coords", NULL); return ZN_ERROR; }; + arc->coords[0] = points[0]; + arc->coords[1] = points[1]; (*args)++; (*argc)--; @@ -538,11 +539,12 @@ ComputeCoordinates(Item item, AddPointsToBBox(&item->item_bounding_box, end_points, LINE_END_POINTS); } +#ifdef GLX if (!ZnGradientFlat(arc->fill_color)) { ZnPoly shape; if (!arc->grad_geo) { - arc->grad_geo = ZnMalloc(4*sizeof(ZnPoint)); + arc->grad_geo = ZnMalloc(6*sizeof(ZnPoint)); } if (arc->fill_color->type == ZN_AXIAL_GRADIENT) { ZnPoint p[4]; @@ -553,19 +555,16 @@ ComputeCoordinates(Item item, p[1].y = p[0].y; p[3].x = p[0].x; p[3].y = p[2].y; - POLY_CONTOUR1(&shape, p, 4); - ZnComputeAxialGradient(wi, &shape, arc->fill_color->g.angle, - arc->grad_geo); + POLY_CONTOUR1(&shape, p, 4, False); + ZnComputeAxialGradient(wi, &shape, arc->fill_color->g.angle, arc->grad_geo); } else if (arc->fill_color->type == ZN_RADIAL_GRADIENT) { - POLY_CONTOUR1(&shape, ZnListArray(arc->render_shape), - ZnListSize(arc->render_shape)); - ZnComputeRadialGradient(wi, &shape, &item->item_bounding_box, - &arc->fill_color->g.p, arc->grad_geo); + POLY_CONTOUR1(&shape, arc->coords, 2, False); + ZnComputeRadialGradient(wi, &shape, True, &arc->fill_color->g.p, arc->grad_geo); } else if (arc->fill_color->type == ZN_PATH_GRADIENT) { - ZnTransformPoint(wi->current_transfo, &arc->fill_color->g.p, - &arc->grad_geo[0]); + POLY_CONTOUR1(&shape, arc->coords, 2, False); + ZnComputePathGradient(wi, &shape, &arc->fill_color->g.p, arc->grad_geo); } } else { @@ -574,7 +573,7 @@ ComputeCoordinates(Item item, arc->grad_geo = NULL; } } - +#endif return; } @@ -1208,60 +1207,68 @@ Render(Item item) return; } - /* Fill if requested */ - if (ISSET(arc->flags, FILLED_BIT)) { - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - - if (!ZnGradientFlat(arc->fill_color)) { - ZnPoly poly; - - POLY_CONTOUR1(&poly, ZnListArray(arc->render_shape), - ZnListSize(arc->render_shape)); - ZnRenderGradient(wi, arc->fill_color,ArcRenderCB, arc, - arc->grad_geo, &poly); - } - else if (arc->tile != ZnUnspecifiedImage) { /* Fill tiled */ - ZnRenderTile(wi, arc->tile, arc->fill_color, ArcRenderCB, arc, - (ZnPoint *) &item->item_bounding_box); - } - else { - if (arc->fill_pattern != ZnUnspecifiedImage) { /* Fill stippled */ - /* - * Setup polygon stippling. - */ - glEnable(GL_POLYGON_STIPPLE); - glPolygonStipple(ZnImagePattern(arc->fill_pattern, NULL)); + if (!item->gl_list) { + item->gl_list = glGenLists(1); + glNewList(item->gl_list, GL_COMPILE); + + /* Fill if requested */ + if (ISSET(arc->flags, FILLED_BIT)) { + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + + if (!ZnGradientFlat(arc->fill_color)) { + ZnPoly poly; + + POLY_CONTOUR1(&poly, ZnListArray(arc->render_shape), + ZnListSize(arc->render_shape), False); + ZnRenderGradient(wi, arc->fill_color, ArcRenderCB, arc, + arc->grad_geo, &poly); + } + else if (arc->tile != ZnUnspecifiedImage) { /* Fill tiled */ + ZnRenderTile(wi, arc->tile, arc->fill_color, ArcRenderCB, arc, + (ZnPoint *) &item->item_bounding_box); + } + else { + if (arc->fill_pattern != ZnUnspecifiedImage) { /* Fill stippled */ + /* + * Setup polygon stippling. + */ + glEnable(GL_POLYGON_STIPPLE); + glPolygonStipple(ZnImagePattern(arc->fill_pattern, NULL)); + } + color = ZnGetGradientColor(arc->fill_color, 0.0, &alpha); + alpha = ZnComposeAlpha(alpha, wi->alpha); + glColor4us(color->red, color->green, color->blue, alpha); + ArcRenderCB(arc); + glDisable(GL_POLYGON_STIPPLE); } - color = ZnGetGradientColor(arc->fill_color, 0.0, &alpha); - alpha = ZnComposeAlpha(alpha, wi->alpha); - glColor4us(color->red, color->green, color->blue, alpha); - ArcRenderCB(arc); - glDisable(GL_POLYGON_STIPPLE); } - } - - /* - * Draw the arc. - */ - if (arc->line_width) { - ZnLineEnd first = ISSET(arc->flags, FIRST_END_OK) ? arc->first_end : NULL; - ZnLineEnd last = ISSET(arc->flags, LAST_END_OK) ? arc->last_end : NULL; - ZnBool closed = ISSET(arc->flags, CLOSED_BIT); - p = ZnListArray(arc->render_shape); - num_points = ZnListSize(arc->render_shape); - if (!closed) { - if (arc->angle_extent != 360) { - num_points--; - if (ISSET(arc->flags, PIE_SLICE_BIT)) { + /* + * Draw the arc. + */ + if (arc->line_width) { + ZnLineEnd first = ISSET(arc->flags, FIRST_END_OK) ? arc->first_end : NULL; + ZnLineEnd last = ISSET(arc->flags, LAST_END_OK) ? arc->last_end : NULL; + ZnBool closed = ISSET(arc->flags, CLOSED_BIT); + + p = ZnListArray(arc->render_shape); + num_points = ZnListSize(arc->render_shape); + if (!closed) { + if (arc->angle_extent != 360) { num_points--; + if (ISSET(arc->flags, PIE_SLICE_BIT)) { + num_points--; + } } } + ZnRenderPolyline(wi, p, num_points, arc->line_width, + arc->line_style, CapRound, JoinRound, first, last, + arc->line_color); } - ZnRenderPolyline(wi, p, num_points, arc->line_width, - arc->line_style, CapRound, JoinRound, first, last, - arc->line_color); + glEndList(); } + + glCallList(item->gl_list); #endif } @@ -1639,8 +1646,7 @@ GetContours(Item item, } POLY_CONTOUR1(poly, ZnListArray(arc->render_shape), - ZnListSize(arc->render_shape)); - poly->contour1.cw = 1; + ZnListSize(arc->render_shape), True); poly->contour1.controls = NULL; return False; diff --git a/generic/Rectangle.c b/generic/Rectangle.c index bc7a814..3a630da 100644 --- a/generic/Rectangle.c +++ b/generic/Rectangle.c @@ -36,6 +36,7 @@ #include "Image.h" #include "Color.h" #include "WidgetInfo.h" +#include "tkZinc.h" static const char rcsid[] = "$Id$"; @@ -139,9 +140,9 @@ Init(Item item, { WidgetInfo *wi = item->wi; RectangleItem rect = (RectangleItem) item; - Tcl_Obj **elems; - int num_elems; - + int num_points; + ZnPoint *points; + rect->gradient = NULL; rect->grad_geo = NULL; @@ -157,15 +158,15 @@ Init(Item item, Tcl_AppendResult(wi->interp, " rectangle coords expected", NULL); return ZN_ERROR; } - if ((Tcl_ListObjGetElements(wi->interp, (*args)[0], &num_elems, &elems) == ZN_ERROR) || - (num_elems != 4) || - (Tcl_GetDoubleFromObj(wi->interp, elems[0], &rect->coords[0].x) == ZN_ERROR) || - (Tcl_GetDoubleFromObj(wi->interp, elems[1], &rect->coords[0].y) == ZN_ERROR) || - (Tcl_GetDoubleFromObj(wi->interp, elems[2], &rect->coords[1].x) == ZN_ERROR) || - (Tcl_GetDoubleFromObj(wi->interp, elems[3], &rect->coords[1].y) == ZN_ERROR)) { + if (ZnParseCoordList(wi, (*args)[0], &points, NULL, &num_points) == ZN_ERROR) { + return ZN_ERROR; + } + if (num_points != 2) { Tcl_AppendResult(wi->interp, " malformed rectangle coords", NULL); return ZN_ERROR; }; + rect->coords[0] = points[0]; + rect->coords[1] = points[1]; (*args)++; (*argc)--; @@ -370,6 +371,7 @@ ComputeCoordinates(Item item, aligned |= delta < X_PRECISION_LIMIT; ASSIGN(rect->flags, ALIGNED_BIT, aligned); +#ifdef GLX /* * If there is an axial gradient with an unaligned axis * compute the bbox in the coordinate system defined @@ -383,9 +385,9 @@ ComputeCoordinates(Item item, if ((angle != 0) && (angle != 90) && (angle != 180) && (angle != 270)) { if (!rect->grad_geo) { - rect->grad_geo = ZnMalloc(4*sizeof(ZnPoint)); + rect->grad_geo = ZnMalloc(6*sizeof(ZnPoint)); } - POLY_CONTOUR1(&shape, p, 4); + POLY_CONTOUR1(&shape, p, 4, False); ZnComputeAxialGradient(wi, &shape, angle, rect->grad_geo); } else { @@ -394,18 +396,25 @@ ComputeCoordinates(Item item, } else if (rect->fill_color->type == ZN_RADIAL_GRADIENT) { + ZnPoint pp[4]; if (!rect->grad_geo) { - rect->grad_geo = ZnMalloc(4*sizeof(ZnPoint)); + rect->grad_geo = ZnMalloc(6*sizeof(ZnPoint)); } - POLY_CONTOUR1(&shape, rect->dev, 4); - ZnComputeRadialGradient(wi, &shape, &item->item_bounding_box, - &rect->fill_color->g.p, rect->grad_geo); + pp[0] = rect->coords[0]; + pp[2] = rect->coords[1]; + pp[1].x = pp[2].x; + pp[1].y = pp[0].y; + pp[3].x = pp[0].x; + pp[3].y = pp[2].y; + POLY_CONTOUR1(&shape, pp, 4, False); + ZnComputeRadialGradient(wi, &shape, False, &rect->fill_color->g.p, rect->grad_geo); } else if (rect->fill_color->type == ZN_PATH_GRADIENT) { if (!rect->grad_geo) { - rect->grad_geo = ZnMalloc(4*sizeof(ZnPoint)); + rect->grad_geo = ZnMalloc(6*sizeof(ZnPoint)); } - ZnTransformPoint(wi->current_transfo, &rect->fill_color->g.p, &rect->grad_geo[0]); + POLY_CONTOUR1(&shape, rect->coords, 2, False); + ZnComputePathGradient(wi, &shape, &rect->fill_color->g.p, rect->grad_geo); } } else { @@ -415,6 +424,7 @@ ComputeCoordinates(Item item, rect->grad_geo = NULL; } } +#endif } @@ -627,57 +637,66 @@ Render(Item item) XColor *color; int i, alpha; - if (ISSET(rect->flags, FILLED_BIT)) { - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - - if (!ZnGradientFlat(rect->fill_color)) { - ZnBool fast = (rect->fill_color->type == ZN_AXIAL_GRADIENT) && !rect->grad_geo; - ZnPoly poly; - - POLY_CONTOUR1(&poly, rect->dev, 4); - ZnRenderGradient(wi, rect->fill_color, - fast ? NULL: RectRenderCB, rect, - fast ? rect->dev : rect->grad_geo, &poly); - } - else { - if (rect->tile != ZnUnspecifiedImage) { /* Fill tiled */ - ZnRenderTile(wi, rect->tile, rect->fill_color, RectRenderCB, - rect, (ZnPoint *) &item->item_bounding_box); + if (!item->gl_list) { + item->gl_list = glGenLists(1); + glNewList(item->gl_list, GL_COMPILE); + + if (ISSET(rect->flags, FILLED_BIT)) { + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + + if (!ZnGradientFlat(rect->fill_color)) { + ZnBool fast = (rect->fill_color->type == ZN_AXIAL_GRADIENT) && !rect->grad_geo; + ZnPoly poly; + + POLY_CONTOUR1(&poly, rect->dev, 4, False); + ZnRenderGradient(wi, rect->fill_color, + fast ? NULL: RectRenderCB, rect, + fast ? rect->dev : rect->grad_geo, &poly); } else { - if (rect->fill_pattern != ZnUnspecifiedImage) { /* Fill stippled */ - /* - * Setup polygon stippling. - */ - glEnable(GL_POLYGON_STIPPLE); - glPolygonStipple(ZnImagePattern(rect->fill_pattern, NULL)); + if (rect->tile != ZnUnspecifiedImage) { /* Fill tiled */ + ZnRenderTile(wi, rect->tile, rect->fill_color, RectRenderCB, + rect, (ZnPoint *) &item->item_bounding_box); + } + else { + if (rect->fill_pattern != ZnUnspecifiedImage) { /* Fill stippled */ + /* + * Setup polygon stippling. + */ + glEnable(GL_POLYGON_STIPPLE); + glPolygonStipple(ZnImagePattern(rect->fill_pattern, NULL)); + } + color = ZnGetGradientColor(rect->fill_color, 0.0, &alpha); + alpha = ZnComposeAlpha(alpha, wi->alpha); + glColor4us(color->red, color->green, color->blue, alpha); + RectRenderCB(rect); + glDisable(GL_POLYGON_STIPPLE); } - color = ZnGetGradientColor(rect->fill_color, 0.0, &alpha); - alpha = ZnComposeAlpha(alpha, wi->alpha); - glColor4us(color->red, color->green, color->blue, alpha); - RectRenderCB(rect); - glDisable(GL_POLYGON_STIPPLE); } } - } - - if (rect->line_width) { - ZnPoint p[5]; - for (i = 0; i < 4; i++) { - p[4-i].x = rect->dev[i].x; - p[4-i].y = rect->dev[i].y; - } - p[0] = p[4]; - if (rect->relief != RELIEF_FLAT) { - ZnRenderPolygonRelief(wi, rect->relief, rect->gradient, False, - p, 5, rect->line_width); - } - else { - ZnRenderPolyline(wi, p, 5, rect->line_width, - rect->line_style, CapRound, JoinMiter, - NULL, NULL, rect->line_color); + + if (rect->line_width) { + ZnPoint p[5]; + for (i = 0; i < 4; i++) { + p[4-i].x = rect->dev[i].x; + p[4-i].y = rect->dev[i].y; + } + p[0] = p[4]; + if (rect->relief != RELIEF_FLAT) { + ZnRenderPolygonRelief(wi, rect->relief, rect->gradient, False, + p, 5, rect->line_width); + } + else { + ZnRenderPolyline(wi, p, 5, rect->line_width, + rect->line_style, CapRound, JoinMiter, + NULL, NULL, rect->line_color); + } } + + glEndList(); } + + glCallList(item->gl_list); #endif } |