From 3261805fee19e346b4d1f84b23816daa1628764a Mon Sep 17 00:00:00 2001 From: lecoanet Date: Wed, 16 Apr 2003 09:49:22 +0000 Subject: Update from the Windows port and general cleanup/restructure --- generic/Triangles.c | 246 +++++++++++++++++++++++++++------------------------- 1 file changed, 126 insertions(+), 120 deletions(-) (limited to 'generic/Triangles.c') diff --git a/generic/Triangles.c b/generic/Triangles.c index 3c18eff..84b5cbf 100644 --- a/generic/Triangles.c +++ b/generic/Triangles.c @@ -37,7 +37,6 @@ #include "Color.h" #include -#include static const char rcsid[] = "$Id"; @@ -58,7 +57,7 @@ static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ " ********************************************************************************** */ typedef struct _TrianglesItemStruct { - ItemStruct header; + ZnItemStruct header; /* Public data */ ZnList points; @@ -74,13 +73,13 @@ static ZnAttrConfig tr_attrs[] = { { ZN_CONFIG_GRADIENT_LIST, "-colors", NULL, Tk_Offset(TrianglesItemStruct, colors), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-composealpha", NULL, - Tk_Offset(TrianglesItemStruct, header.flags), COMPOSE_ALPHA_BIT, + Tk_Offset(TrianglesItemStruct, header.flags), ZN_COMPOSE_ALPHA_BIT, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-composerotation", NULL, - Tk_Offset(TrianglesItemStruct, header.flags), COMPOSE_ROTATION_BIT, + Tk_Offset(TrianglesItemStruct, header.flags), ZN_COMPOSE_ROTATION_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_BOOL, "-composescale", NULL, - Tk_Offset(TrianglesItemStruct, header.flags), COMPOSE_SCALE_BIT, + Tk_Offset(TrianglesItemStruct, header.flags), ZN_COMPOSE_SCALE_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_BOOL, "-fan", NULL, Tk_Offset(TrianglesItemStruct, flags), FAN_BIT, ZN_COORDS_FLAG, False }, @@ -88,15 +87,15 @@ static ZnAttrConfig tr_attrs[] = { Tk_Offset(TrianglesItemStruct, header.priority), 0, ZN_DRAW_FLAG|ZN_REPICK_FLAG, False }, { ZN_CONFIG_BOOL, "-sensitive", NULL, - Tk_Offset(TrianglesItemStruct, header.flags), SENSITIVE_BIT, + Tk_Offset(TrianglesItemStruct, header.flags), ZN_SENSITIVE_BIT, ZN_REPICK_FLAG, False }, { ZN_CONFIG_TAG_LIST, "-tags", NULL, Tk_Offset(TrianglesItemStruct, header.tags), 0, 0, False }, { ZN_CONFIG_BOOL, "-visible", NULL, - Tk_Offset(TrianglesItemStruct, header.flags), VISIBLE_BIT, + Tk_Offset(TrianglesItemStruct, header.flags), ZN_VISIBLE_BIT, ZN_DRAW_FLAG|ZN_REPICK_FLAG|ZN_VIS_FLAG, False }, - { ZN_CONFIG_END, NULL, NULL, 0, 0, 0 } + { ZN_CONFIG_END, NULL, NULL, 0, 0, 0, False } }; @@ -108,13 +107,13 @@ static ZnAttrConfig tr_attrs[] = { ********************************************************************************** */ static int -Init(Item item, +Init(ZnItem item, int *argc, Tcl_Obj *CONST *args[]) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; TrianglesItem tr = (TrianglesItem) item; - int num_points; + unsigned int num_points; ZnPoint *points; ZnList l; ZnGradient **grads; @@ -122,25 +121,25 @@ Init(Item item, tr->dev_points.num_strips = 0; /* Init attributes */ - SET(item->flags, VISIBLE_BIT); - SET(item->flags, SENSITIVE_BIT); - SET(item->flags, COMPOSE_ALPHA_BIT); - SET(item->flags, COMPOSE_ROTATION_BIT); - SET(item->flags, COMPOSE_SCALE_BIT); - item->priority = DEFAULT_TRIANGLES_PRIORITY; + SET(item->flags, ZN_VISIBLE_BIT); + SET(item->flags, ZN_SENSITIVE_BIT); + SET(item->flags, ZN_COMPOSE_ALPHA_BIT); + SET(item->flags, ZN_COMPOSE_ROTATION_BIT); + SET(item->flags, ZN_COMPOSE_SCALE_BIT); + item->priority = 1; tr->points = NULL; if (*argc < 1) { Tcl_AppendResult(wi->interp, " triangles coords expected", NULL); - return ZN_ERROR; + return TCL_ERROR; } if (ZnParseCoordList(wi, (*args)[0], &points, - NULL, &num_points, NULL) == ZN_ERROR) { - return ZN_ERROR; + NULL, &num_points, NULL) == TCL_ERROR) { + return TCL_ERROR; } if (num_points < 3) { Tcl_AppendResult(wi->interp, " malformed triangles coords, need at least 3 points", NULL); - return ZN_ERROR; + return TCL_ERROR; } tr->points = ZnListNew(num_points, sizeof(ZnPoint)); @@ -156,7 +155,7 @@ Init(Item item, grads = ZnListArray(tr->colors); *grads = ZnGetGradientByValue(wi->fore_color); - return ZN_OK; + return TCL_OK; } @@ -168,7 +167,7 @@ Init(Item item, ********************************************************************************** */ static void -Clone(Item item) +Clone(ZnItem item) { TrianglesItem tr = (TrianglesItem) item; @@ -197,7 +196,7 @@ Clone(Item item) ********************************************************************************** */ static void -Destroy(Item item) +Destroy(ZnItem item) { TrianglesItem tr = (TrianglesItem) item; @@ -227,12 +226,12 @@ Destroy(Item item) ********************************************************************************** */ static int -Configure(Item item, +Configure(ZnItem item, int argc, Tcl_Obj *CONST argv[], int *flags) { - int status = ZN_OK; + int status = TCL_OK; status = ZnConfigureAttributes(item->wi, item, tr_attrs, argc, argv, flags); @@ -248,15 +247,15 @@ Configure(Item item, ********************************************************************************** */ static int -Query(Item item, - int argc, +Query(ZnItem item, + int argc __unused, Tcl_Obj *CONST argv[]) { - if (ZnQueryAttribute(item->wi, item, tr_attrs, argv[0]) == ZN_ERROR) { - return ZN_ERROR; + if (ZnQueryAttribute(item->wi, item, tr_attrs, argv[0]) == TCL_ERROR) { + return TCL_ERROR; } - return ZN_OK; + return TCL_OK; } @@ -268,16 +267,16 @@ Query(Item item, ********************************************************************************** */ static void -ComputeCoordinates(Item item, - ZnBool force) +ComputeCoordinates(ZnItem item, + ZnBool force __unused) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; TrianglesItem tr = (TrianglesItem) item; ZnPoint *points; ZnPoint *dev_points; - int num_points; + unsigned int num_points; - ResetBBox(&item->item_bounding_box); + ZnResetBBox(&item->item_bounding_box); points = (ZnPoint *) ZnListArray(tr->points); num_points = ZnListSize(tr->points); @@ -294,8 +293,8 @@ ComputeCoordinates(Item item, dev_points = ZnRealloc(dev_points, num_points * sizeof(ZnPoint)); } } - TRI_STRIP1(&tr->dev_points, dev_points, num_points, - ISSET(tr->flags, FAN_BIT)); + ZnTriStrip1(&tr->dev_points, dev_points, num_points, + ISSET(tr->flags, FAN_BIT)); /* * Compute device coordinates. @@ -305,7 +304,7 @@ ComputeCoordinates(Item item, /* * Compute the bounding box. */ - AddPointsToBBox(&item->item_bounding_box, dev_points, num_points); + ZnAddPointsToBBox(&item->item_bounding_box, dev_points, num_points); /* * Expand the bounding box by one pixel in all @@ -329,12 +328,13 @@ ComputeCoordinates(Item item, ********************************************************************************** */ static int -ToArea(Item item, +ToArea(ZnItem item, ZnToArea ta) { TrianglesItem tr = (TrianglesItem) item; ZnPoint *points; - int i, num_points, result=-1, result2; + unsigned int i, num_points; + int result=-1, result2; ZnBBox *area = ta->area; if (tr->dev_points.num_strips == 0) { @@ -345,13 +345,13 @@ ToArea(Item item, num_points = tr->dev_points.strips->num_points; if (ISCLEAR(tr->flags, FAN_BIT)) { - result = PolygonInBBox(points, 3, area, NULL); + result = ZnPolygonInBBox(points, 3, area, NULL); if (result == 0) { return 0; } points++; for (i = 0; i < num_points-3; i++, points++) { - result2 = PolygonInBBox(points, 3, area, NULL); + result2 = ZnPolygonInBBox(points, 3, area, NULL); if (result2 != result) { return 0; } @@ -363,7 +363,7 @@ ToArea(Item item, tri[0] = points[0]; tri[1] = points[1]; tri[2] = points[2]; - result = PolygonInBBox(points, num_points, area, NULL); + result = ZnPolygonInBBox(points, num_points, area, NULL); if (result == 0) { return 0; } @@ -371,7 +371,7 @@ ToArea(Item item, for (i = 0; i < num_points-3; i++, points++) { tri[1] = tri[2]; tri[2] = *points; - result2 = PolygonInBBox(points, num_points, area, NULL); + result2 = ZnPolygonInBBox(points, num_points, area, NULL); if (result2 != result) { return 0; } @@ -390,11 +390,11 @@ ToArea(Item item, ********************************************************************************** */ static void -Draw(Item item) +Draw(ZnItem item) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; TrianglesItem tr = (TrianglesItem) item; - int i, num_points, last_color_index; + unsigned int i, num_points, last_color_index; ZnPoint *points; ZnGradient **grads; @@ -414,13 +414,13 @@ Draw(Item item) ZnListAssertSize(wi->work_xpts, num_points); xpoints = ZnListArray(wi->work_xpts); for (i = 0; i < num_points; i++) { - xpoints[i].x = REAL_TO_INT(points[i].x); - xpoints[i].y = REAL_TO_INT(points[i].y); + xpoints[i].x = ZnNearestInt(points[i].x); + xpoints[i].y = ZnNearestInt(points[i].y); } for (i = 0; i < num_points-2; i++, xpoints++) { if (i <= last_color_index) { XSetForeground(wi->dpy, wi->gc, - ZnPixel(ZnGetGradientColor(grads[i], 0, NULL))); + ZnPixel(ZnGetGradientColor(grads[i], 0.0, NULL))); } XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc, xpoints, 3, Convex, CoordModeOrigin); @@ -429,12 +429,12 @@ Draw(Item item) else { XPoint tri[3]; - tri[0].x = REAL_TO_INT(points[0].x); - tri[0].y = REAL_TO_INT(points[0].y); - tri[1].x = REAL_TO_INT(points[1].x); - tri[1].y = REAL_TO_INT(points[1].y); - tri[2].x = REAL_TO_INT(points[2].x); - tri[2].y = REAL_TO_INT(points[2].y); + tri[0].x = ZnNearestInt(points[0].x); + tri[0].y = ZnNearestInt(points[0].y); + tri[1].x = ZnNearestInt(points[1].x); + tri[1].y = ZnNearestInt(points[1].y); + tri[2].x = ZnNearestInt(points[2].x); + tri[2].y = ZnNearestInt(points[2].y); points += 3; for (i = 0; i < num_points-2; i++, points++) { if (i <= last_color_index) { @@ -444,8 +444,8 @@ Draw(Item item) XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc, tri, 3, Convex, CoordModeOrigin); tri[1] = tri[2]; - tri[2].x = REAL_TO_INT(points->x); - tri[2].y = REAL_TO_INT(points->y); + tri[2].x = ZnNearestInt(points->x); + tri[2].y = ZnNearestInt(points->y); } } } @@ -458,16 +458,16 @@ Draw(Item item) * ********************************************************************************** */ +#ifdef GL static void -Render(Item item) +Render(ZnItem item) { -#ifdef GLX - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; TrianglesItem tr = (TrianglesItem) item; int i, num_points, last_color_index; ZnPoint *points; ZnGradient **grads; - int alpha; + unsigned short alpha; XColor *color; if (tr->dev_points.num_strips == 0) { @@ -494,11 +494,16 @@ Render(Item item) alpha = ZnComposeAlpha(alpha, wi->alpha); glColor4us(color->red, color->green, color->blue, alpha); } - glVertex2f(points->x, points->y); + glVertex2d(points->x, points->y); } glEnd(); -#endif } +#else +static void +Render(ZnItem item __unused) +{ +} +#endif /* @@ -509,10 +514,10 @@ Render(Item item) ********************************************************************************** */ static ZnBool -IsSensitive(Item item, - int item_part) +IsSensitive(ZnItem item, + int item_part __unused) { - return (ISSET(item->flags, SENSITIVE_BIT) && + return (ISSET(item->flags, ZN_SENSITIVE_BIT) && item->parent->class->IsSensitive(item->parent, ZN_NO_PART)); } @@ -525,7 +530,7 @@ IsSensitive(Item item, ********************************************************************************** */ static double -Pick(Item item, +Pick(ZnItem item, ZnPick ps) { TrianglesItem tr = (TrianglesItem) item; @@ -542,7 +547,7 @@ Pick(Item item, if (ISCLEAR(tr->flags, FAN_BIT)) { for (i = 0; i < num_points-2; i++, points++) { - new_dist = PolygonToPointDist(points, 3, p); + new_dist = ZnPolygonToPointDist(points, 3, p); if (new_dist <= 0.0) { return 0.0; } @@ -558,7 +563,7 @@ Pick(Item item, tri[1] = points[1]; tri[2] = points[2]; for (i = 0; i < num_points-2; i++, points++) { - new_dist = PolygonToPointDist(tri, 3, p); + new_dist = ZnPolygonToPointDist(tri, 3, p); if (new_dist <= 0.0) { return 0.0; } @@ -582,8 +587,8 @@ Pick(Item item, ********************************************************************************** */ static void -PostScript(Item item, - PostScriptInfo ps_info) +PostScript(ZnItem item __unused, + ZnPostScriptInfo ps_info __unused) { } @@ -593,12 +598,12 @@ PostScript(Item item, * * GetClipVertices -- * Get the clipping shape. - * Never ever call TRI_FREE on the tristrip returned by GetClipVertices. + * Never ever call ZnTriFree on the tristrip returned by GetClipVertices. * ********************************************************************************** */ static ZnBool -GetClipVertices(Item item, +GetClipVertices(ZnItem item, ZnTriStrip *tristrip) { TrianglesItem tr = (TrianglesItem) item; @@ -608,9 +613,9 @@ GetClipVertices(Item item, return True; } - TRI_STRIP1(tristrip, tr->dev_points.strips->points, - tr->dev_points.strips->num_points, - tr->dev_points.strips[0].fan); + ZnTriStrip1(tristrip, tr->dev_points.strips->points, + tr->dev_points.strips->num_points, + tr->dev_points.strips[0].fan); return False; } @@ -620,18 +625,19 @@ GetClipVertices(Item item, * * GetContours -- * Get the external contour(s). - * Never ever call POLY_FREE on the poly returned by GetContours. + * Never ever call ZnPolyFree on the poly returned by GetContours. * ********************************************************************************** */ static ZnBool -GetContours(Item item, +GetContours(ZnItem item, ZnPoly *poly) { TrianglesItem tr = (TrianglesItem) item; - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; ZnPoint *points; - int i, j, num_points; + unsigned int k, j, num_points; + int i; if (tr->dev_points.num_strips == 0) { poly->num_contours = 0; @@ -644,8 +650,8 @@ GetContours(Item item, ZnListAssertSize(wi->work_pts, num_points); points = ZnListArray(wi->work_pts); - for (i = 1, j = 0; i < num_points; i += 2, j++) { - points[j] = tr->dev_points.strips->points[i]; + for (k = 1, j = 0; k < num_points; k += 2, j++) { + points[j] = tr->dev_points.strips->points[k]; } i = num_points - 1; if (num_points % 2 == 0) { @@ -654,12 +660,12 @@ GetContours(Item item, for ( ; i >= 0; i -= 2, j++) { points[j] = tr->dev_points.strips->points[i]; } - POLY_CONTOUR1(poly, points, num_points, False); + ZnPolyContour1(poly, points, num_points, False); } else { - POLY_CONTOUR1(poly, tr->dev_points.strips->points, num_points, False); + ZnPolyContour1(poly, tr->dev_points.strips->points, num_points, False); } - poly->contours[0].cw = !TestCCW(poly->contours[0].points, poly->contours[0].num_points); + poly->contours[0].cw = !ZnTestCCW(poly->contours[0].points, poly->contours[0].num_points); poly->contours[0].controls = NULL; return False; } @@ -674,25 +680,25 @@ GetContours(Item item, ********************************************************************************** */ static int -Coords(Item item, - int contour, - int index, - int cmd, - ZnPoint **pts, - char **controls, - int *num_pts) +Coords(ZnItem item, + int contour __unused, + int index, + int cmd, + ZnPoint **pts, + char **controls __unused, + unsigned int *num_pts) { TrianglesItem tr = (TrianglesItem) item; - int num_points, i; + unsigned int num_points, i; ZnPoint *points; - if ((cmd == COORDS_REPLACE) || (cmd == COORDS_REPLACE_ALL)) { - if (cmd == COORDS_REPLACE_ALL) { + if ((cmd == ZN_COORDS_REPLACE) || (cmd == ZN_COORDS_REPLACE_ALL)) { + if (cmd == ZN_COORDS_REPLACE_ALL) { ZnList tmp; if (*num_pts == 0) { Tcl_AppendResult(item->wi->interp, " coords command need at least 3 points on triangles", NULL); - return ZN_ERROR; + return TCL_ERROR; } tmp = ZnListFromArray(*pts, *num_pts, sizeof(ZnPoint)); ZnListEmpty(tr->points); @@ -703,26 +709,26 @@ Coords(Item item, if (*num_pts == 0) { Tcl_AppendResult(item->wi->interp, " coords command need at least 1 point on triangles", NULL); - return ZN_ERROR; + return TCL_ERROR; } points = ZnListArray(tr->points); num_points = ZnListSize(tr->points); if (index < 0) { index += num_points; } - if ((index < 0) || (index >= num_points)) { + if ((index < 0) || ((unsigned int) index >= num_points)) { range_err: Tcl_AppendResult(item->wi->interp, " coord index out of range", NULL); - return ZN_ERROR; + return TCL_ERROR; } points[index] = (*pts)[0]; } - ITEM.Invalidate(item, ZN_COORDS_FLAG); + ZnITEM.Invalidate(item, ZN_COORDS_FLAG); } - else if ((cmd == COORDS_READ) || (cmd == COORDS_READ_ALL)) { + else if ((cmd == ZN_COORDS_READ) || (cmd == ZN_COORDS_READ_ALL)) { points = ZnListArray(tr->points); num_points = ZnListSize(tr->points); - if (cmd == COORDS_READ_ALL) { + if (cmd == ZN_COORDS_READ_ALL) { *num_pts = num_points; *pts = points; } @@ -730,24 +736,24 @@ Coords(Item item, if (index < 0) { index += num_points; } - if ((index < 0) || (index >= num_points)) { + if ((index < 0) || ((unsigned int)index >= num_points)) { goto range_err; } *num_pts = 1; *pts = &points[index]; } } - else if ((cmd == COORDS_ADD) || (cmd == COORDS_ADD_LAST)) { - if (cmd == COORDS_ADD) { + else if ((cmd == ZN_COORDS_ADD) || (cmd == ZN_COORDS_ADD_LAST)) { + if (cmd == ZN_COORDS_ADD) { num_points = ZnListSize(tr->points); if (index < 0) { index += num_points; } - if ((index < 0) || (index >= num_points)) { + if ((index < 0) || ((unsigned int)index >= num_points)) { goto range_err; } for (i = 0; i < *num_pts; i++, index++) { - ZnListAdd(tr->points, &(*pts)[i], index); + ZnListAdd(tr->points, &(*pts)[i], (unsigned int) index); } } else { @@ -756,27 +762,27 @@ Coords(Item item, ZnListAppend(tr->points, tmp); ZnListFree(tmp); } - ITEM.Invalidate(item, ZN_COORDS_FLAG); + ZnITEM.Invalidate(item, ZN_COORDS_FLAG); } - else if (cmd == COORDS_REMOVE) { + else if (cmd == ZN_COORDS_REMOVE) { if (ZnListSize(tr->points) < 4) { Tcl_AppendResult(item->wi->interp, " triangles should keep at least 3 points", NULL); - return ZN_ERROR; + return TCL_ERROR; } points = ZnListArray(tr->points); num_points = ZnListSize(tr->points); if (index < 0) { index += num_points; } - if ((index < 0) || (index >= num_points)) { + if ((index < 0) || ((unsigned int)index >= num_points)) { goto range_err; } - ZnListDelete(tr->points, index); - ITEM.Invalidate(item, ZN_COORDS_FLAG); + ZnListDelete(tr->points, (unsigned int) index); + ZnITEM.Invalidate(item, ZN_COORDS_FLAG); } - return ZN_OK; + return TCL_OK; } @@ -791,7 +797,7 @@ Coords(Item item, ********************************************************************************** */ static void -PickVertex(Item item, +PickVertex(ZnItem item, ZnPoint *p, int *contour, int *vertex, @@ -818,9 +824,9 @@ PickVertex(Item item, * Update the opposite vertex. */ i = (*vertex+1) % num_points; - new_dist = LineToPointDist(&points[*vertex], &points[i], p); + new_dist = ZnLineToPointDist(&points[*vertex], &points[i], p); k = ((unsigned)(*vertex-1)) % num_points; - dist2 = LineToPointDist(&points[*vertex], &points[k], p); + dist2 = ZnLineToPointDist(&points[*vertex], &points[k], p); if (dist2 < new_dist) { *o_vertex = k; } @@ -837,7 +843,7 @@ PickVertex(Item item, * ********************************************************************************** */ -static ItemClassStruct TRIANGLES_ITEM_CLASS = { +static ZnItemClassStruct TRIANGLES_ITEM_CLASS = { sizeof(TrianglesItemStruct), 0, /* num_parts */ False, /* has_anchors */ -- cgit v1.1