From 5de4aad21f265022dd3cf9352eca9c6cc40a16ad Mon Sep 17 00:00:00 2001 From: lecoanet Date: Mon, 9 Dec 2002 14:27:35 +0000 Subject: * Utilisation de la routine ZnParseCoordList pour initialiser Les coordonn�es (incompatibilit�s). * Remaniement du code des gradients (incompatibilit�s). * Utilisation des display lists pour am�liorer les perfs en GL. * Adaptation pour g�rer la nouvelle fa�on de traiter les contours. --- generic/Rectangle.c | 141 +++++++++++++++++++++++++++++----------------------- 1 file changed, 80 insertions(+), 61 deletions(-) (limited to 'generic/Rectangle.c') 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 } -- cgit v1.1