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/Arc.c | 562 ++++++------ generic/Attrs.c | 805 ++++++++++++++---- generic/Attrs.h | 217 +++-- generic/Color.c | 813 +----------------- generic/Color.h | 25 +- generic/Curve.c | 693 +++++++-------- generic/Draw.c | 670 ++++++++------- generic/Draw.h | 101 ++- generic/Field.c | 692 +++++++-------- generic/Field.h | 60 +- generic/Geo.c | 823 ++++++++---------- generic/Geo.h | 466 +++++----- generic/Group.c | 451 +++++----- generic/Group.h | 22 +- generic/Icon.c | 308 ++++--- generic/Image.c | 1151 ++++++++++--------------- generic/Image.h | 32 +- generic/Item.c | 1086 ++++++++---------------- generic/Item.h | 401 +++++---- generic/List.c | 102 +-- generic/List.h | 34 +- generic/Map.c | 579 +++++++------ generic/MapInfo.c | 1245 +++++++++++++-------------- generic/MapInfo.h | 84 +- generic/OverlapMan.c | 52 +- generic/PostScript.c | 54 +- generic/PostScript.h | 15 +- generic/Rectangle.c | 274 +++--- generic/Reticle.c | 192 +++-- generic/Tabular.c | 229 ++--- generic/Text.c | 474 ++++++----- generic/Track.c | 1223 +++++++++++++------------- generic/Track.h | 24 +- generic/Transfo.c | 13 +- generic/Transfo.h | 2 +- generic/Triangles.c | 246 +++--- generic/Types.h | 468 +++------- generic/WidgetInfo.h | 140 +-- generic/Window.c | 187 ++-- generic/perfos.c | 75 +- generic/perfos.h | 28 +- generic/tkZinc.c | 2313 +++++++++++++++++++++++++++++++------------------- generic/tkZinc.h | 37 +- generic/version.c | 33 - 44 files changed, 8713 insertions(+), 8788 deletions(-) delete mode 100644 generic/version.c (limited to 'generic') diff --git a/generic/Arc.c b/generic/Arc.c index e50cd22..5b69992 100644 --- a/generic/Arc.c +++ b/generic/Arc.c @@ -27,8 +27,6 @@ */ -#include - #include "Item.h" #include "Geo.h" #include "Draw.h" @@ -54,7 +52,7 @@ static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ " #define USING_POLY_BIT 1<<5 -static double Pick(Item item, ZnPick ps); +static double Pick(ZnItem item, ZnPick ps); /* @@ -65,7 +63,7 @@ static double Pick(Item item, ZnPick ps); ********************************************************************************** */ typedef struct _ArcItemStruct { - ItemStruct header; + ZnItemStruct header; /* Public data */ ZnPoint coords[2]; @@ -76,7 +74,7 @@ typedef struct _ArcItemStruct { ZnGradient *fill_color; ZnGradient *line_color; ZnDim line_width; - LineStyle line_style; + ZnLineStyle line_style; ZnLineEnd first_end; ZnLineEnd last_end; ZnImage tile; @@ -96,13 +94,13 @@ static ZnAttrConfig arc_attrs[] = { { ZN_CONFIG_BOOL, "-closed", NULL, Tk_Offset(ArcItemStruct, flags), CLOSED_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_BOOL, "-composealpha", NULL, - Tk_Offset(ArcItemStruct, header.flags), COMPOSE_ALPHA_BIT, + Tk_Offset(ArcItemStruct, header.flags), ZN_COMPOSE_ALPHA_BIT, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-composerotation", NULL, - Tk_Offset(ArcItemStruct, header.flags), COMPOSE_ROTATION_BIT, + Tk_Offset(ArcItemStruct, header.flags), ZN_COMPOSE_ROTATION_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_BOOL, "-composescale", NULL, - Tk_Offset(ArcItemStruct, header.flags), COMPOSE_SCALE_BIT, + Tk_Offset(ArcItemStruct, header.flags), ZN_COMPOSE_SCALE_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_ANGLE, "-extent", NULL, Tk_Offset(ArcItemStruct, angle_extent), 0, ZN_COORDS_FLAG, False }, @@ -131,7 +129,7 @@ static ZnAttrConfig arc_attrs[] = { Tk_Offset(ArcItemStruct, header.priority), 0, ZN_DRAW_FLAG|ZN_REPICK_FLAG, False }, { ZN_CONFIG_BOOL, "-sensitive", NULL, - Tk_Offset(ArcItemStruct, header.flags), SENSITIVE_BIT, + Tk_Offset(ArcItemStruct, header.flags), ZN_SENSITIVE_BIT, ZN_REPICK_FLAG, False }, { ZN_CONFIG_ANGLE, "-startangle", NULL, Tk_Offset(ArcItemStruct, start_angle), 0, ZN_COORDS_FLAG, False }, @@ -140,10 +138,10 @@ static ZnAttrConfig arc_attrs[] = { { ZN_CONFIG_IMAGE, "-tile", NULL, Tk_Offset(ArcItemStruct, tile), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-visible", NULL, - Tk_Offset(ArcItemStruct, header.flags), VISIBLE_BIT, + Tk_Offset(ArcItemStruct, 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 } }; @@ -155,22 +153,22 @@ static ZnAttrConfig arc_attrs[] = { ********************************************************************************** */ static int -Init(Item item, +Init(ZnItem item, int *argc, Tcl_Obj *CONST *args[]) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; ArcItem arc = (ArcItem) item; - int num_points; + unsigned int num_points; ZnPoint *points; /* 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_ARC_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; arc->start_angle = 0; arc->angle_extent = 360; @@ -181,7 +179,7 @@ Init(Item item, arc->line_pattern = ZnUnspecifiedImage; arc->fill_pattern = ZnUnspecifiedImage; arc->tile = ZnUnspecifiedImage; - arc->line_style = LINE_SIMPLE; + arc->line_style = ZN_LINE_SIMPLE; arc->line_width = 1; arc->first_end = arc->last_end = NULL; arc->render_shape = NULL; @@ -189,15 +187,15 @@ Init(Item item, if (*argc < 1) { Tcl_AppendResult(wi->interp, " arc 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 != 2) { Tcl_AppendResult(wi->interp, " malformed arc coords", NULL); - return ZN_ERROR; + return TCL_ERROR; }; arc->coords[0] = points[0]; arc->coords[1] = points[1]; @@ -207,7 +205,7 @@ Init(Item item, arc->fill_color = ZnGetGradientByValue(wi->fore_color); arc->line_color = ZnGetGradientByValue(wi->fore_color); - return ZN_OK; + return TCL_OK; } @@ -219,23 +217,18 @@ Init(Item item, ********************************************************************************** */ static void -Clone(Item item) +Clone(ZnItem item) { ArcItem arc = (ArcItem) item; - if (arc->grad_geo) { - ZnPoint *grad_geo = ZnMalloc(4*sizeof(ZnPoint)); - memcpy(grad_geo, arc->grad_geo, 4*sizeof(ZnPoint)); - arc->grad_geo = grad_geo; - } if (arc->tile != ZnUnspecifiedImage) { arc->tile = ZnGetImageByValue(arc->tile); } if (arc->first_end) { - LineEndDuplicate(arc->first_end); + ZnLineEndDuplicate(arc->first_end); } if (arc->last_end) { - LineEndDuplicate(arc->last_end); + ZnLineEndDuplicate(arc->last_end); } if (arc->line_pattern != ZnUnspecifiedImage) { arc->line_pattern = ZnGetImageByValue(arc->line_pattern); @@ -245,6 +238,7 @@ Clone(Item item) } arc->line_color = ZnGetGradientByValue(arc->line_color); arc->fill_color = ZnGetGradientByValue(arc->fill_color); + arc->grad_geo = NULL; if (arc->render_shape) { arc->render_shape = ZnListDuplicate(arc->render_shape); } @@ -259,7 +253,7 @@ Clone(Item item) ********************************************************************************** */ static void -Destroy(Item item) +Destroy(ZnItem item) { ArcItem arc = (ArcItem) item; @@ -267,10 +261,10 @@ Destroy(Item item) ZnListFree(arc->render_shape); } if (arc->first_end) { - LineEndDelete(arc->first_end); + ZnLineEndDelete(arc->first_end); } if (arc->last_end) { - LineEndDelete(arc->last_end); + ZnLineEndDelete(arc->last_end); } if (arc->tile != ZnUnspecifiedImage) { ZnFreeImage(arc->tile); @@ -323,13 +317,13 @@ SetRenderFlags(ArcItem arc) ********************************************************************************** */ static int -Configure(Item item, +Configure(ZnItem item, int argc, Tcl_Obj *CONST argv[], int *flags) { ArcItem arc = (ArcItem) item; - int status = ZN_OK; + int status = TCL_OK; status = ZnConfigureAttributes(item->wi, item, arc_attrs, argc, argv, flags); if (arc->start_angle < 0) { @@ -350,15 +344,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, arc_attrs, argv[0]) == ZN_ERROR) { - return ZN_ERROR; + if (ZnQueryAttribute(item->wi, item, arc_attrs, argv[0]) == TCL_ERROR) { + return TCL_ERROR; } - return ZN_OK; + return TCL_OK; } @@ -368,7 +362,7 @@ Query(Item item, * end of the arc. The point is on the tangent segment next to * the arc (ie: it is suitable for drawing arrows). */ -void +static void Tangent(ArcItem arc, ZnBool first, ZnPoint *p) @@ -378,10 +372,10 @@ Tangent(ArcItem arc, ZnPoint p1, center; if (first) { - angle = DegreesToRadian(arc->start_angle); + angle = ZnDegRad(arc->start_angle); } else { - angle = DegreesToRadian(arc->start_angle + arc->angle_extent); + angle = ZnDegRad(arc->start_angle + arc->angle_extent); } p1.x = cos(angle); p1.y = sin(angle); @@ -417,8 +411,8 @@ Tangent(ArcItem arc, } p->y = a2*p->x + b2; } - p->x = center.x + REAL_TO_INT(p->x*w_2); - p->y = center.y + REAL_TO_INT(p->y*h_2); + p->x = center.x + ZnNearestInt(p->x*w_2); + p->y = center.y + ZnNearestInt(p->y*h_2); } @@ -435,7 +429,7 @@ UpdateRenderShape(ArcItem arc) ZnPoint *p_list, p, p2, o, o2; ZnReal width, height, d; int num_p, i, quality; - ZnTransfo *t = ((Item) arc)->wi->current_transfo; + ZnTransfo *t = ((ZnItem) arc)->wi->current_transfo; if (!arc->render_shape) { arc->render_shape = ZnListNew(8, sizeof(ZnPoint)); @@ -446,12 +440,12 @@ UpdateRenderShape(ArcItem arc) height = (arc->coords[1].y - arc->coords[0].y)/2.0; d = MAX(width, height); quality = ZN_CIRCLE_COARSE; - p_list = GetCirclePoints(ISCLEAR(arc->flags, PIE_SLICE_BIT) ? 1 : 2, - quality, - DegreesToRadian(arc->start_angle), - DegreesToRadian(arc->angle_extent), - &num_p, - arc->render_shape); + p_list = ZnGetCirclePoints(ISCLEAR(arc->flags, PIE_SLICE_BIT) ? 1 : 2, + quality, + ZnDegRad(arc->start_angle), + ZnDegRad(arc->angle_extent), + &num_p, + arc->render_shape); /* * Adapt the number of arc circles to the radius of the arc. @@ -471,12 +465,12 @@ UpdateRenderShape(ArcItem arc) quality = ZN_CIRCLE_MEDIUM; } if (quality != ZN_CIRCLE_COARSE) { - p_list = GetCirclePoints(ISCLEAR(arc->flags, PIE_SLICE_BIT) ? 1 : 2, - quality, - DegreesToRadian(arc->start_angle), - DegreesToRadian(arc->angle_extent), - &num_p, - arc->render_shape); + p_list = ZnGetCirclePoints(ISCLEAR(arc->flags, PIE_SLICE_BIT) ? 1 : 2, + quality, + ZnDegRad(arc->start_angle), + ZnDegRad(arc->angle_extent), + &num_p, + arc->render_shape); } for (i = 0; i < num_p; i++, p_list++) { @@ -487,18 +481,18 @@ UpdateRenderShape(ArcItem arc) } static void -ComputeCoordinates(Item item, - ZnBool force) +ComputeCoordinates(ZnItem item, + ZnBool force __unused) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; ArcItem arc = (ArcItem) item; ZnReal angle, sin1, cos1, sin2, cos2; ZnReal tmp, w_2, h_2, center_x, center_y; - int num_p; + unsigned int num_p; ZnPoint *p_list, p; - ZnPoint end_points[LINE_END_POINTS]; + ZnPoint end_points[ZN_LINE_END_POINTS]; - ResetBBox(&item->item_bounding_box); + ZnResetBBox(&item->item_bounding_box); /* * If it is neither filled nor outlined, then nothing to show. */ @@ -518,7 +512,7 @@ ComputeCoordinates(Item item, UpdateRenderShape(arc); p_list = ZnListArray(arc->render_shape); num_p = ZnListSize(arc->render_shape); - AddPointsToBBox(&item->item_bounding_box, p_list, num_p); + ZnAddPointsToBBox(&item->item_bounding_box, p_list, num_p); tmp = (arc->line_width + 1.0) / 2.0 + 1.0; item->item_bounding_box.orig.x -= tmp; @@ -530,17 +524,17 @@ ComputeCoordinates(Item item, * Add the arrows if any. */ if (ISSET(arc->flags, FIRST_END_OK)) { - GetLineEnd(p_list, p_list+1, arc->line_width, CapRound, - arc->first_end, end_points); - AddPointsToBBox(&item->item_bounding_box, end_points, LINE_END_POINTS); + ZnGetLineEnd(p_list, p_list+1, arc->line_width, CapRound, + arc->first_end, end_points); + ZnAddPointsToBBox(&item->item_bounding_box, end_points, ZN_LINE_END_POINTS); } if (ISSET(arc->flags, LAST_END_OK)) { - GetLineEnd(&p_list[num_p-1], &p_list[num_p-2], arc->line_width, CapRound, - arc->last_end, end_points); - AddPointsToBBox(&item->item_bounding_box, end_points, LINE_END_POINTS); + ZnGetLineEnd(&p_list[num_p-1], &p_list[num_p-2], arc->line_width, CapRound, + arc->last_end, end_points); + ZnAddPointsToBBox(&item->item_bounding_box, end_points, ZN_LINE_END_POINTS); } -#ifdef GLX +#ifdef GL if (!ZnGradientFlat(arc->fill_color)) { ZnPoly shape; ZnPoint p[4]; @@ -555,15 +549,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, False); - ZnComputeAxialGradient(wi, &shape, arc->fill_color->g.angle, arc->grad_geo); + ZnPolyContour1(&shape, p, 4, False); + ZnComputeAxialGradient(wi, &shape, (ZnReal) arc->fill_color->g.angle, + arc->grad_geo); } else if (arc->fill_color->type == ZN_RADIAL_GRADIENT) { - POLY_CONTOUR1(&shape, arc->coords, 2, False); + ZnPolyContour1(&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) { - POLY_CONTOUR1(&shape, arc->coords, 2, False); + ZnPolyContour1(&shape, arc->coords, 2, False); ZnComputePathGradient(wi, &shape, &arc->fill_color->g.p, arc->grad_geo); } } @@ -603,10 +598,10 @@ ComputeCoordinates(Item item, * to fit the shape. * Angles are running clockwise and y coordinates are inverted. */ - angle = DegreesToRadian(arc->start_angle); + angle = ZnDegRad(arc->start_angle); sin1 = sin(angle); cos1 = cos(angle); - angle += DegreesToRadian(arc->angle_extent); + angle += ZnDegRad(arc->angle_extent); sin2 = sin(angle); cos2 = cos(angle); @@ -615,16 +610,16 @@ ComputeCoordinates(Item item, center_x = (arc->corner.x + arc->orig.x) / 2; center_y = (arc->corner.y + arc->orig.y) / 2; - arc->center1.x = center_x + REAL_TO_INT(cos1*w_2); - arc->center1.y = center_y + REAL_TO_INT(sin1*h_2); - arc->center2.x = center_x + REAL_TO_INT(cos2*w_2); - arc->center2.y = center_y + REAL_TO_INT(sin2*h_2); + arc->center1.x = center_x + ZnNearestInt(cos1*w_2); + arc->center1.y = center_y + ZnNearestInt(sin1*h_2); + arc->center2.x = center_x + ZnNearestInt(cos2*w_2); + arc->center2.y = center_y + ZnNearestInt(sin2*h_2); /* * Add the ends centers to the bbox. */ - AddPointToBBox(&item->item_bounding_box, arc->center1.x, arc->center1.y); - AddPointToBBox(&item->item_bounding_box, arc->center2.x, arc->center2.y); + ZnAddPointToBBox(&item->item_bounding_box, arc->center1.x, arc->center1.y); + ZnAddPointToBBox(&item->item_bounding_box, arc->center2.x, arc->center2.y); /* * If the arc is filled or if the outline is closed in pie slice, @@ -632,7 +627,7 @@ ComputeCoordinates(Item item, */ if ((ISSET(arc->flags, FILLED_BIT) || ISSET(arc->flags, CLOSED_BIT)) && ISSET(arc->flags, PIE_SLICE_BIT)) { - AddPointToBBox(&item->item_bounding_box, center_x, center_y); + ZnAddPointToBBox(&item->item_bounding_box, center_x, center_y); } /* @@ -644,7 +639,7 @@ ComputeCoordinates(Item item, tmp += 360; } if ((tmp < arc->angle_extent) || ((tmp - 360) > arc->angle_extent)) { - AddPointToBBox(&item->item_bounding_box, arc->corner.x, center_y); + ZnAddPointToBBox(&item->item_bounding_box, arc->corner.x, center_y); } tmp = 180 - arc->start_angle; @@ -652,7 +647,7 @@ ComputeCoordinates(Item item, tmp += 360; } if ((tmp < arc->angle_extent) || ((tmp - 360) > arc->angle_extent)) { - AddPointToBBox(&item->item_bounding_box, arc->orig.x, center_y); + ZnAddPointToBBox(&item->item_bounding_box, arc->orig.x, center_y); } tmp = 90 - arc->start_angle; @@ -660,7 +655,7 @@ ComputeCoordinates(Item item, tmp += 360; } if ((tmp < arc->angle_extent) || ((tmp - 360) > arc->angle_extent)) { - AddPointToBBox(&item->item_bounding_box, center_x, arc->corner.y); + ZnAddPointToBBox(&item->item_bounding_box, center_x, arc->corner.y); } tmp = 270 - arc->start_angle; @@ -668,7 +663,7 @@ ComputeCoordinates(Item item, tmp += 360; } if ((tmp < arc->angle_extent) || ((tmp - 360) > arc->angle_extent)) { - AddPointToBBox(&item->item_bounding_box, center_x, arc->orig.y); + ZnAddPointToBBox(&item->item_bounding_box, center_x, arc->orig.y); } /* @@ -685,15 +680,15 @@ ComputeCoordinates(Item item, */ if (ISSET(arc->flags, FIRST_END_OK)) { Tangent(arc, True, &p); - GetLineEnd(&arc->center1, &p, arc->line_width, CapRound, - arc->first_end, end_points); - AddPointsToBBox(&item->item_bounding_box, end_points, LINE_END_POINTS); + ZnGetLineEnd(&arc->center1, &p, arc->line_width, CapRound, + arc->first_end, end_points); + ZnAddPointsToBBox(&item->item_bounding_box, end_points, ZN_LINE_END_POINTS); } if (ISSET(arc->flags, LAST_END_OK)) { Tangent(arc, False, &p); - GetLineEnd(&arc->center2, &p, arc->line_width, CapRound, - arc->last_end, end_points); - AddPointsToBBox(&item->item_bounding_box, end_points, LINE_END_POINTS); + ZnGetLineEnd(&arc->center2, &p, arc->line_width, CapRound, + arc->last_end, end_points); + ZnAddPointsToBBox(&item->item_bounding_box, end_points, ZN_LINE_END_POINTS); } } @@ -708,15 +703,16 @@ ComputeCoordinates(Item item, ********************************************************************************** */ static int -ToArea(Item item, +ToArea(ZnItem item, ZnToArea ta) { ArcItem arc = (ArcItem) item; ZnPoint *points; - ZnPoint pts[20]; /* Should be at least LINE_END_POINTS large */ + ZnPoint pts[20]; /* Should be at least ZN_LINE_END_POINTS large */ ZnPoint center, tang; ZnBBox t_area, *area = ta->area; - int num_points, result=-1, result2; + unsigned int num_points; + int result=-1, result2; ZnReal lw = arc->line_width; ZnReal rx, ry, angle, tmp; ZnBool inside, new_inside; @@ -728,14 +724,14 @@ ToArea(Item item, num_points = ZnListSize(arc->render_shape); if (ISSET(arc->flags, FILLED_BIT)) { - result = PolygonInBBox(points, num_points, area, NULL); + result = ZnPolygonInBBox(points, num_points, area, NULL); if (result == 0) { return 0; } } if (arc->line_width > 0) { - result2 = PolylineInBBox(points, num_points, arc->line_width, - CapRound, JoinRound, area); + result2 = ZnPolylineInBBox(points, num_points, arc->line_width, + CapRound, JoinRound, area); if (ISCLEAR(arc->flags, FILLED_BIT)) { if (result2 == 0) { return 0; @@ -748,8 +744,8 @@ ToArea(Item item, if (ISSET(arc->flags, CLOSED_BIT) && ISSET(arc->flags, PIE_SLICE_BIT)) { pts[0] = points[num_points-1]; pts[1] = points[0]; - if (PolylineInBBox(pts, 2, arc->line_width, - CapRound, JoinRound, area) != result) { + if (ZnPolylineInBBox(pts, 2, arc->line_width, + CapRound, JoinRound, area) != result) { return 0; } } @@ -757,16 +753,16 @@ ToArea(Item item, * Check line ends. */ if (ISSET(arc->flags, FIRST_END_OK)) { - GetLineEnd(&points[0], &points[1], arc->line_width, CapRound, - arc->first_end, pts); - if (PolygonInBBox(pts, LINE_END_POINTS, area, NULL) != result) { + ZnGetLineEnd(&points[0], &points[1], arc->line_width, CapRound, + arc->first_end, pts); + if (ZnPolygonInBBox(pts, ZN_LINE_END_POINTS, area, NULL) != result) { return 0; } } if (ISSET(arc->flags, LAST_END_OK)) { - GetLineEnd(&points[num_points-1], &points[num_points-2], arc->line_width, - CapRound, arc->last_end, pts); - if (PolygonInBBox(pts, LINE_END_POINTS, area, NULL) != result) { + ZnGetLineEnd(&points[num_points-1], &points[num_points-2], arc->line_width, + CapRound, arc->last_end, pts); + if (ZnPolygonInBBox(pts, ZN_LINE_END_POINTS, area, NULL) != result) { return 0; } } @@ -807,10 +803,10 @@ ToArea(Item item, * includes those angles). */ points = pts; - angle = DegreesToRadian(arc->start_angle); + angle = ZnDegRad(arc->start_angle); points->x = rx*cos(angle); points->y = ry*sin(angle); - angle += DegreesToRadian(arc->angle_extent); + angle += ZnDegRad(arc->angle_extent); points[1].x = rx*cos(angle); points[1].y = ry*sin(angle); num_points = 2; @@ -867,9 +863,9 @@ ToArea(Item item, * Now that we've located the extreme points, loop through them all * to see which are inside the rectangle. */ - inside = PointInBBox(&t_area, pts->x, pts->y); + inside = ZnPointInBBox(&t_area, pts->x, pts->y); for (points = pts+1; num_points > 1; points++, num_points--) { - new_inside = PointInBBox(&t_area, points->x, points->y); + new_inside = ZnPointInBBox(&t_area, points->x, points->y); if (new_inside != inside) { return 0; } @@ -895,19 +891,19 @@ ToArea(Item item, pts[1] = arc->center2; num_points = 2; } - if (PolylineInBBox(pts, num_points, lw, CapRound, JoinRound, area) != result) { + if (ZnPolylineInBBox(pts, num_points, lw, CapRound, JoinRound, area) != result) { return 0; } } else if (ISSET(arc->flags, FILLED_BIT)) { if (ISSET(arc->flags, PIE_SLICE_BIT)) { - if ((LineInBBox(¢er, &arc->center1, area) != result) || - (LineInBBox(¢er, &arc->center2, area) != result)) { + if ((ZnLineInBBox(¢er, &arc->center1, area) != result) || + (ZnLineInBBox(¢er, &arc->center2, area) != result)) { return 0; } } else { - if (LineInBBox(&arc->center1, &arc->center2, area) != result) { + if (ZnLineInBBox(&arc->center1, &arc->center2, area) != result) { return 0; } } @@ -918,17 +914,17 @@ ToArea(Item item, */ if (ISSET(arc->flags, FIRST_END_OK)) { Tangent(arc, True, &tang); - GetLineEnd(&arc->center1, &tang, arc->line_width, CapRound, - arc->first_end, pts); - if (PolygonInBBox(pts, LINE_END_POINTS, area, NULL) != result) { + ZnGetLineEnd(&arc->center1, &tang, arc->line_width, CapRound, + arc->first_end, pts); + if (ZnPolygonInBBox(pts, ZN_LINE_END_POINTS, area, NULL) != result) { return 0; } } if (ISSET(arc->flags, LAST_END_OK)) { Tangent(arc, False, &tang); - GetLineEnd(&arc->center2, &tang, arc->line_width, CapRound, - arc->last_end, pts); - if (PolygonInBBox(pts, LINE_END_POINTS, area, NULL) != result) { + ZnGetLineEnd(&arc->center2, &tang, arc->line_width, CapRound, + arc->last_end, pts); + if (ZnPolygonInBBox(pts, ZN_LINE_END_POINTS, area, NULL) != result) { return 0; } } @@ -941,27 +937,27 @@ ToArea(Item item, * outer perimiter of the arc. If the arc isn't filled, then also * check the inner perimeter of the arc. */ - if (HorizLineToArc(t_area.orig.x, t_area.corner.x, t_area.orig.y, - rx, ry, arc->start_angle, arc->angle_extent) || - HorizLineToArc(t_area.orig.x, t_area.corner.x, t_area.corner.y, - rx, ry, arc->start_angle, arc->angle_extent) || - VertLineToArc(t_area.orig.x, t_area.orig.y, t_area.corner.y, + if (ZnHorizLineToArc(t_area.orig.x, t_area.corner.x, t_area.orig.y, + rx, ry, arc->start_angle, arc->angle_extent) || + ZnHorizLineToArc(t_area.orig.x, t_area.corner.x, t_area.corner.y, rx, ry, arc->start_angle, arc->angle_extent) || - VertLineToArc(t_area.corner.x, t_area.orig.y, t_area.corner.y, - rx, ry, arc->start_angle, arc->angle_extent)) { + ZnVertLineToArc(t_area.orig.x, t_area.orig.y, t_area.corner.y, + rx, ry, arc->start_angle, arc->angle_extent) || + ZnVertLineToArc(t_area.corner.x, t_area.orig.y, t_area.corner.y, + rx, ry, arc->start_angle, arc->angle_extent)) { return 0; } if ((lw > 1.0) && ISCLEAR(arc->flags, FILLED_BIT)) { rx -= lw; ry -= lw; - if (HorizLineToArc(t_area.orig.x, t_area.corner.x, t_area.orig.y, - rx, ry, arc->start_angle, arc->angle_extent) || - HorizLineToArc(t_area.orig.x, t_area.corner.x, t_area.corner.y, - rx, ry, arc->start_angle, arc->angle_extent) || - VertLineToArc(t_area.orig.x, t_area.orig.y, t_area.corner.y, - rx, ry, arc->start_angle, arc->angle_extent) || - VertLineToArc(t_area.corner.x, t_area.orig.y, t_area.corner.y, - rx, ry, arc->start_angle, arc->angle_extent)) { + if (ZnHorizLineToArc(t_area.orig.x, t_area.corner.x, t_area.orig.y, + rx, ry, arc->start_angle, arc->angle_extent) || + ZnHorizLineToArc(t_area.orig.x, t_area.corner.x, t_area.corner.y, + rx, ry, arc->start_angle, arc->angle_extent) || + ZnVertLineToArc(t_area.orig.x, t_area.orig.y, t_area.corner.y, + rx, ry, arc->start_angle, arc->angle_extent) || + ZnVertLineToArc(t_area.corner.x, t_area.orig.y, t_area.corner.y, + rx, ry, arc->start_angle, arc->angle_extent)) { return 0; } } @@ -990,15 +986,15 @@ ToArea(Item item, ********************************************************************************** */ static void -Draw(Item item) +Draw(ZnItem item) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; ArcItem arc = (ArcItem) item; XGCValues values; - int width=0, height=0; + unsigned int width=0, height=0; ZnPoint *p=NULL; XPoint *xp=NULL; - int num_points=0, i; + unsigned int num_points=0, i; if (ISSET(arc->flags, USING_POLY_BIT) && (ISSET(arc->flags, FILLED_BIT) || (arc->line_width))) { @@ -1013,8 +1009,8 @@ Draw(Item item) p = ZnListArray(arc->render_shape); } else { - width = arc->corner.x - arc->orig.x; - height = arc->corner.y - arc->orig.y; + width = ((int) (arc->corner.x - arc->orig.x)); + height = ((int) (arc->corner.y - arc->orig.y)); } /* Fill if requested */ @@ -1023,7 +1019,7 @@ Draw(Item item) values.arc_mode = ISSET(arc->flags, PIE_SLICE_BIT) ? ArcPieSlice : ArcChord; if (arc->tile != ZnUnspecifiedImage) { /* Fill Tiled */ values.fill_style = FillTiled; - values.tile = ZnImagePixmap(arc->tile, NULL); + values.tile = ZnImagePixmap(arc->tile); values.ts_x_origin = (int) item->item_bounding_box.orig.x; values.ts_y_origin = (int) item->item_bounding_box.orig.y; XChangeGC(wi->dpy, wi->gc, @@ -1032,7 +1028,7 @@ Draw(Item item) } else if (arc->fill_pattern != ZnUnspecifiedImage) { /* Fill stippled */ values.fill_style = FillStippled; - values.stipple = ZnImagePixmap(arc->fill_pattern, NULL); + values.stipple = ZnImagePixmap(arc->fill_pattern); values.ts_x_origin = (int) item->item_bounding_box.orig.x; values.ts_y_origin = (int) item->item_bounding_box.orig.y; XChangeGC(wi->dpy, wi->gc, @@ -1045,11 +1041,14 @@ Draw(Item item) } if (ISSET(arc->flags, USING_POLY_BIT)) { XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc, - xp, num_points, Nonconvex, CoordModeOrigin); + xp, (int) num_points, Nonconvex, CoordModeOrigin); } else { XFillArc(wi->dpy, wi->draw_buffer, wi->gc, - arc->orig.x, arc->orig.y, width, height, + (int) arc->orig.x, + (int) arc->orig.y, + (unsigned int) width, + (unsigned int) height, -arc->start_angle*64, -arc->angle_extent*64); } } @@ -1058,13 +1057,13 @@ Draw(Item item) * Draw the arc. */ if (arc->line_width) { - ZnPoint end_points[LINE_END_POINTS]; - XPoint xap[LINE_END_POINTS]; + ZnPoint end_points[ZN_LINE_END_POINTS]; + XPoint xap[ZN_LINE_END_POINTS]; ZnPoint tang; ZnSetLineStyle(wi, arc->line_style); - values.foreground = ZnPixel(ZnGetGradientColor(arc->line_color, 0, NULL)); - values.line_width = (arc->line_width == 1) ? 0 : arc->line_width; + values.foreground = ZnPixel(ZnGetGradientColor(arc->line_color, 0.0, NULL)); + values.line_width = (arc->line_width == 1) ? 0 : (int) arc->line_width; values.cap_style = CapRound; values.join_style = JoinRound; if (arc->line_pattern == ZnUnspecifiedImage) { @@ -1074,7 +1073,7 @@ Draw(Item item) } else { values.fill_style = FillStippled; - values.stipple = ZnImagePixmap(arc->line_pattern, NULL); + values.stipple = ZnImagePixmap(arc->line_pattern); XChangeGC(wi->dpy, wi->gc, GCFillStyle|GCStipple|GCLineWidth|GCCapStyle|GCJoinStyle|GCForeground, &values); @@ -1087,34 +1086,37 @@ Draw(Item item) } } XDrawLines(wi->dpy, wi->draw_buffer, wi->gc, - xp, num_points, CoordModeOrigin); + xp, (int) num_points, CoordModeOrigin); if (ISSET(arc->flags, FIRST_END_OK)) { p = (ZnPoint *) ZnListArray(arc->render_shape); - GetLineEnd(p, p+1, arc->line_width, CapRound, - arc->first_end, end_points); - for (i = 0; i < LINE_END_POINTS; i++) { - xap[i].x = end_points[i].x; - xap[i].y = end_points[i].y; + ZnGetLineEnd(p, p+1, arc->line_width, CapRound, + arc->first_end, end_points); + for (i = 0; i < ZN_LINE_END_POINTS; i++) { + xap[i].x = (short) end_points[i].x; + xap[i].y = (short) end_points[i].y; } - XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc, xap, LINE_END_POINTS, + XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc, xap, ZN_LINE_END_POINTS, Nonconvex, CoordModeOrigin); } if (ISSET(arc->flags, LAST_END_OK)) { p = (ZnPoint *) ZnListArray(arc->render_shape); num_points = ZnListSize(arc->render_shape); - GetLineEnd(&p[num_points-1], &p[num_points-2], arc->line_width, - CapRound, arc->last_end, end_points); - for (i = 0; i < LINE_END_POINTS; i++) { - xap[i].x = end_points[i].x; - xap[i].y = end_points[i].y; + ZnGetLineEnd(&p[num_points-1], &p[num_points-2], arc->line_width, + CapRound, arc->last_end, end_points); + for (i = 0; i < ZN_LINE_END_POINTS; i++) { + xap[i].x = (short) end_points[i].x; + xap[i].y = (short) end_points[i].y; } - XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc, xap, LINE_END_POINTS, + XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc, xap, ZN_LINE_END_POINTS, Nonconvex, CoordModeOrigin); } } else { XDrawArc(wi->dpy, wi->draw_buffer, wi->gc, - arc->orig.x, arc->orig.y, width, height, + (int) arc->orig.x, + (int) arc->orig.y, + (unsigned int) width, + (unsigned int) height, -arc->start_angle*64, -arc->angle_extent*64); /* * If the outline is closed, draw the closure. @@ -1123,39 +1125,43 @@ Draw(Item item) if (ISSET(arc->flags, PIE_SLICE_BIT)) { XPoint points[3]; - points[0].x = arc->center1.x; - points[0].y = arc->center1.y; - points[1].x = (arc->corner.x + arc->orig.x) / 2; - points[1].y = (arc->corner.y + arc->orig.y) / 2; - points[2].x = arc->center2.x; - points[2].y = arc->center2.y; - XDrawLines(wi->dpy, wi->draw_buffer, wi->gc, points, 3, CoordModeOrigin); + points[0].x = (short) arc->center1.x; + points[0].y = (short) arc->center1.y; + points[1].x = (short) ((arc->corner.x + arc->orig.x) / 2); + points[1].y = (short) ((arc->corner.y + arc->orig.y) / 2); + points[2].x = (short) arc->center2.x; + points[2].y = (short) arc->center2.y; + XDrawLines(wi->dpy, wi->draw_buffer, wi->gc, points, 3, + CoordModeOrigin); } else { XDrawLine(wi->dpy, wi->draw_buffer, wi->gc, - arc->center1.x, arc->center1.y, arc->center2.x, arc->center2.y); + (int) arc->center1.x, + (int) arc->center1.y, + (int) arc->center2.x, + (int) arc->center2.y); } } if (ISSET(arc->flags, FIRST_END_OK)) { Tangent(arc, True, &tang); - GetLineEnd(&arc->center1, &tang, arc->line_width, CapRound, - arc->first_end, end_points); - for (i = 0; i < LINE_END_POINTS; i++) { - xap[i].x = end_points[i].x; - xap[i].y = end_points[i].y; + ZnGetLineEnd(&arc->center1, &tang, arc->line_width, CapRound, + arc->first_end, end_points); + for (i = 0; i < ZN_LINE_END_POINTS; i++) { + xap[i].x = (short) end_points[i].x; + xap[i].y = (short) end_points[i].y; } - XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc, xap, LINE_END_POINTS, + XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc, xap, ZN_LINE_END_POINTS, Nonconvex, CoordModeOrigin); } if (ISSET(arc->flags, LAST_END_OK)) { Tangent(arc, False, &tang); - GetLineEnd(&arc->center2, &tang, arc->line_width, CapRound, - arc->last_end, end_points); - for (i = 0; i < LINE_END_POINTS; i++) { - xap[i].x = end_points[i].x; - xap[i].y = end_points[i].y; + ZnGetLineEnd(&arc->center2, &tang, arc->line_width, CapRound, + arc->last_end, end_points); + for (i = 0; i < ZN_LINE_END_POINTS; i++) { + xap[i].x = (short) end_points[i].x; + xap[i].y = (short) end_points[i].y; } - XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc, xap, LINE_END_POINTS, + XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc, xap, ZN_LINE_END_POINTS, Nonconvex, CoordModeOrigin); } } @@ -1170,11 +1176,11 @@ Draw(Item item) * ********************************************************************************** */ -#ifdef GLX +#ifdef GL static void ArcRenderCB(void *closure) { - Item item = (Item) closure; + ZnItem item = (ZnItem) closure; ArcItem arc = (ArcItem) item; int num_points=0, i; ZnPoint *p=NULL; @@ -1185,23 +1191,24 @@ ArcRenderCB(void *closure) p = ZnListArray(arc->render_shape); num_points = ZnListSize(arc->render_shape); glBegin(GL_TRIANGLE_FAN); - glVertex2f(center.x, center.y); + glVertex2d(center.x, center.y); for (i = 0; i < num_points; i++) { - glVertex2f(p[i].x, p[i].y); + glVertex2d(p[i].x, p[i].y); } glEnd(); } #endif + +#ifdef GL static void -Render(Item item) +Render(ZnItem item) { -#ifdef GLX - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; ArcItem arc = (ArcItem) item; - int num_points=0; + unsigned int num_points=0; ZnPoint *p=NULL; XColor *color; - int alpha; + unsigned short alpha; if (ISCLEAR(arc->flags, FILLED_BIT) && !arc->line_width) { return; @@ -1219,8 +1226,8 @@ Render(Item item) if (!ZnGradientFlat(arc->fill_color)) { ZnPoly poly; - POLY_CONTOUR1(&poly, ZnListArray(arc->render_shape), - ZnListSize(arc->render_shape), False); + ZnPolyContour1(&poly, ZnListArray(arc->render_shape), + ZnListSize(arc->render_shape), False); ZnRenderGradient(wi, arc->fill_color, ArcRenderCB, arc, arc->grad_geo, &poly); } @@ -1234,7 +1241,7 @@ Render(Item item) * Setup polygon stippling. */ glEnable(GL_POLYGON_STIPPLE); - glPolygonStipple(ZnImagePattern(arc->fill_pattern, NULL)); + glPolygonStipple(ZnImageMask(arc->fill_pattern, NULL)); } color = ZnGetGradientColor(arc->fill_color, 0.0, &alpha); alpha = ZnComposeAlpha(alpha, wi->alpha); @@ -1272,8 +1279,13 @@ Render(Item item) glCallList(item->gl_list); #endif -#endif } +#else +static void +Render(ZnItem item __unused) +{ +} +#endif /* @@ -1284,10 +1296,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)); } @@ -1299,8 +1311,8 @@ IsSensitive(Item item, * ********************************************************************************** */ -static double -Pick(Item item, +static ZnReal +Pick(ZnItem item, ZnPick ps) { ArcItem arc = (ArcItem) item; @@ -1309,9 +1321,9 @@ Pick(Item item, ZnBool in_triangle, acute_angle; ZnPoint p1, center, tang; ZnPoint *points, *p = ps->point; - ZnPoint end_points[LINE_END_POINTS]; - int num_points; - int width, height; + ZnPoint end_points[ZN_LINE_END_POINTS]; + unsigned int num_points; + ZnDim width, height; ZnDim lw = arc->line_width; if (ISSET(arc->flags, USING_POLY_BIT) && @@ -1320,7 +1332,7 @@ Pick(Item item, num_points = ZnListSize(arc->render_shape); if (ISSET(arc->flags, FILLED_BIT)) { - dist = PolygonToPointDist(points, num_points, p); + dist = ZnPolygonToPointDist(points, num_points, p); if (dist <= 0.0) { return 0.0; } @@ -1332,8 +1344,8 @@ Pick(Item item, num_points--; } } - new_dist = PolylineToPointDist(points, num_points, arc->line_width, - CapRound, JoinRound, p); + new_dist = ZnPolylineToPointDist(points, num_points, arc->line_width, + CapRound, JoinRound, p); if (new_dist < dist) { dist = new_dist; } @@ -1345,9 +1357,9 @@ Pick(Item item, * Check line ends. */ if (ISSET(arc->flags, FIRST_END_OK)) { - GetLineEnd(&points[0], &points[1], arc->line_width, CapRound, - arc->first_end, end_points); - new_dist = PolygonToPointDist(end_points, LINE_END_POINTS, p); + ZnGetLineEnd(&points[0], &points[1], arc->line_width, CapRound, + arc->first_end, end_points); + new_dist = ZnPolygonToPointDist(end_points, ZN_LINE_END_POINTS, p); if (new_dist < dist) { dist = new_dist; } @@ -1356,9 +1368,9 @@ Pick(Item item, } } if (ISSET(arc->flags, LAST_END_OK)) { - GetLineEnd(&points[num_points-1], &points[num_points-2], arc->line_width, - CapRound, arc->last_end, end_points); - new_dist = PolygonToPointDist(end_points, LINE_END_POINTS, p); + ZnGetLineEnd(&points[num_points-1], &points[num_points-2], arc->line_width, + CapRound, arc->last_end, end_points); + new_dist = ZnPolygonToPointDist(end_points, ZN_LINE_END_POINTS, p); if (new_dist < dist) { dist = new_dist; } @@ -1386,7 +1398,7 @@ Pick(Item item, */ p1.y = (p->y - center.y) / height; p1.x = (p->x - center.x) / width; - point_in_angle = PointInAngle(arc->start_angle, arc->angle_extent, &p1); + point_in_angle = ZnPointInAngle(arc->start_angle, arc->angle_extent, &p1); /* * Now try to compute the distance dealing with the @@ -1402,7 +1414,7 @@ Pick(Item item, */ if (!filled && !closed) { if (point_in_angle) { - dist = OvalToPointDist(¢er, width, height, lw, p); + dist = ZnOvalToPointDist(¢er, width, height, lw, p); if (dist < 0.0) { dist = -dist; } @@ -1430,9 +1442,9 @@ Pick(Item item, */ if (ISSET(arc->flags, FIRST_END_OK)) { Tangent(arc, True, &tang); - GetLineEnd(&arc->center1, &tang, arc->line_width, CapRound, - arc->first_end, end_points); - new_dist = PolygonToPointDist(end_points, LINE_END_POINTS, p); + ZnGetLineEnd(&arc->center1, &tang, arc->line_width, CapRound, + arc->first_end, end_points); + new_dist = ZnPolygonToPointDist(end_points, ZN_LINE_END_POINTS, p); if (new_dist < dist) { dist = new_dist; } @@ -1442,9 +1454,9 @@ Pick(Item item, } if (ISSET(arc->flags, LAST_END_OK)) { Tangent(arc, False, &tang); - GetLineEnd(&arc->center2, &tang, arc->line_width, - CapRound, arc->last_end, end_points); - new_dist = PolygonToPointDist(end_points, LINE_END_POINTS, p); + ZnGetLineEnd(&arc->center2, &tang, arc->line_width, + CapRound, arc->last_end, end_points); + new_dist = ZnPolygonToPointDist(end_points, ZN_LINE_END_POINTS, p); if (new_dist < dist) { dist = new_dist; } @@ -1460,8 +1472,8 @@ Pick(Item item, * angular extent). */ if (ISSET(arc->flags, PIE_SLICE_BIT)) { - dist = LineToPointDist(¢er, &arc->center1, p); - new_dist = LineToPointDist(¢er, &arc->center2, p); + dist = ZnLineToPointDist(¢er, &arc->center1, p); + new_dist = ZnLineToPointDist(¢er, &arc->center2, p); if (new_dist < dist) { dist = new_dist; } @@ -1488,7 +1500,7 @@ Pick(Item item, return 0.0; } if (point_in_angle) { - new_dist = OvalToPointDist(¢er, width, height, lw, p); + new_dist = ZnOvalToPointDist(¢er, width, height, lw, p); if (new_dist < dist) { dist = new_dist; } @@ -1502,7 +1514,7 @@ Pick(Item item, /* * This is a chord closed oval. */ - dist = LineToPointDist(&arc->center1, &arc->center2, p); + dist = ZnLineToPointDist(&arc->center1, &arc->center2, p); if (arc->line_width > 1) { if (closed) { dist -= arc->line_width/2; @@ -1554,7 +1566,7 @@ Pick(Item item, } if (point_in_angle && (!acute_angle || !in_triangle)) { - new_dist = OvalToPointDist(¢er, width, height, lw, p); + new_dist = ZnOvalToPointDist(¢er, width, height, lw, p); if (new_dist < dist) { dist = new_dist; } @@ -1575,7 +1587,7 @@ Pick(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. * ********************************************************************************** */ @@ -1589,11 +1601,11 @@ UpdateRenderShapeX(ArcItem arc) if (!arc->render_shape) { arc->render_shape = ZnListNew(8, sizeof(ZnPoint)); } - p_list = GetCirclePoints(ISCLEAR(arc->flags, PIE_SLICE_BIT) ? 1 : 2, - ZN_CIRCLE_FINE, - DegreesToRadian(arc->start_angle), - DegreesToRadian(arc->angle_extent), - &num_p, arc->render_shape); + p_list = ZnGetCirclePoints(ISCLEAR(arc->flags, PIE_SLICE_BIT) ? 1 : 2, + ZN_CIRCLE_FINE, + ZnDegRad(arc->start_angle), + ZnDegRad(arc->angle_extent), + &num_p, arc->render_shape); ox = (arc->corner.x + arc->orig.x) / 2.0; oy = (arc->corner.y + arc->orig.y) / 2.0; width_2 = (arc->corner.x - arc->orig.x) / 2.0; @@ -1605,7 +1617,7 @@ UpdateRenderShapeX(ArcItem arc) } static ZnBool -GetClipVertices(Item item, +GetClipVertices(ZnItem item, ZnTriStrip *tristrip) { ArcItem arc = (ArcItem) item; @@ -1622,8 +1634,8 @@ GetClipVertices(Item item, ZnListEmpty(item->wi->work_pts); ZnListAdd(item->wi->work_pts, ¢er, ZnListTail); ZnListAppend(item->wi->work_pts, arc->render_shape); - TRI_STRIP1(tristrip, ZnListArray(item->wi->work_pts), - ZnListSize(item->wi->work_pts), True); + ZnTriStrip1(tristrip, ZnListArray(item->wi->work_pts), + ZnListSize(item->wi->work_pts), True); return False; } @@ -1634,12 +1646,12 @@ GetClipVertices(Item item, * * GetContours -- * Get the external contour(s). - * Never ever call POLY_FREE on the tristrip returned by GetContours. + * Never ever call ZnPolyFree on the tristrip returned by GetContours. * ********************************************************************************** */ static ZnBool -GetContours(Item item, +GetContours(ZnItem item, ZnPoly *poly) { ArcItem arc = (ArcItem) item; @@ -1648,8 +1660,8 @@ GetContours(Item item, UpdateRenderShapeX(arc); } - POLY_CONTOUR1(poly, ZnListArray(arc->render_shape), - ZnListSize(arc->render_shape), True); + ZnPolyContour1(poly, ZnListArray(arc->render_shape), + ZnListSize(arc->render_shape), True); poly->contour1.controls = NULL; return False; @@ -1665,36 +1677,36 @@ 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) { ArcItem arc = (ArcItem) item; - if ((cmd == COORDS_ADD) || (cmd == COORDS_ADD_LAST) || (cmd == COORDS_REMOVE)) { + if ((cmd == ZN_COORDS_ADD) || (cmd == ZN_COORDS_ADD_LAST) || (cmd == ZN_COORDS_REMOVE)) { Tcl_AppendResult(item->wi->interp, " arcs can't add or remove vertices", NULL); - return ZN_ERROR; + return TCL_ERROR; } - else if (cmd == COORDS_REPLACE_ALL) { + else if (cmd == ZN_COORDS_REPLACE_ALL) { if (*num_pts != 2) { Tcl_AppendResult(item->wi->interp, " coords command need 2 points on arcs", NULL); - return ZN_ERROR; + return TCL_ERROR; } arc->coords[0] = (*pts)[0]; arc->coords[1] = (*pts)[1]; - ITEM.Invalidate(item, ZN_COORDS_FLAG); + ZnITEM.Invalidate(item, ZN_COORDS_FLAG); } - else if (cmd == COORDS_REPLACE) { + else if (cmd == ZN_COORDS_REPLACE) { if (*num_pts < 1) { Tcl_AppendResult(item->wi->interp, " coords command need at least 1 point", NULL); - return ZN_ERROR; + return TCL_ERROR; } if (index < 0) { index += 2; @@ -1703,16 +1715,16 @@ Coords(Item item, range_err: Tcl_AppendResult(item->wi->interp, " incorrect coord index, should be between -2 and 1", NULL); - return ZN_ERROR; + return TCL_ERROR; } arc->coords[index] = (*pts)[0]; - ITEM.Invalidate(item, ZN_COORDS_FLAG); + ZnITEM.Invalidate(item, ZN_COORDS_FLAG); } - else if (cmd == COORDS_READ_ALL) { + else if (cmd == ZN_COORDS_READ_ALL) { *num_pts = 2; *pts = arc->coords; } - else if (cmd == COORDS_READ) { + else if (cmd == ZN_COORDS_READ) { if (index < 0) { index += 2; } @@ -1723,7 +1735,7 @@ Coords(Item item, *pts = &arc->coords[index]; } - return ZN_OK; + return TCL_OK; } /* @@ -1734,16 +1746,16 @@ Coords(Item item, ********************************************************************************** */ static void -GetAnchor(Item item, - ZnAnchor anchor, +GetAnchor(ZnItem item, + Tk_Anchor anchor, ZnPoint *p) { ZnBBox *bbox = &item->item_bounding_box; - Origin2Anchor(&bbox->orig, - bbox->corner.x - bbox->orig.x, - bbox->corner.y - bbox->orig.y, - anchor, p); + ZnOrigin2Anchor(&bbox->orig, + bbox->corner.x - bbox->orig.x, + bbox->corner.y - bbox->orig.y, + anchor, p); } /* @@ -1754,8 +1766,8 @@ GetAnchor(Item item, ********************************************************************************** */ static void -PostScript(Item item, - PostScriptInfo ps_info) +PostScript(ZnItem item __unused, + ZnPostScriptInfo ps_info __unused) { } @@ -1767,7 +1779,7 @@ PostScript(Item item, * ********************************************************************************** */ -static ItemClassStruct ARC_ITEM_CLASS = { +static ZnItemClassStruct ARC_ITEM_CLASS = { sizeof(ArcItemStruct), 0, /* num_parts */ False, /* has_anchors */ diff --git a/generic/Attrs.c b/generic/Attrs.c index 175a0ee..77ce2a5 100644 --- a/generic/Attrs.c +++ b/generic/Attrs.c @@ -34,7 +34,6 @@ #include "WidgetInfo.h" #include -#include #include @@ -43,88 +42,6 @@ static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ " /* - ****************************************************************** - * - * Code for label formats. - * - ****************************************************************** - */ -static Tcl_HashTable format_cache; -static ZnBool format_inited = False; - -#if 0 -static char -AttachToChar(char attach) -{ - switch (attach) { - case LF_ATTACH_FWD: - return '>'; - case LF_ATTACH_BWD: - return '<'; - case LF_ATTACH_LEFT: - return '^'; - case LF_ATTACH_RIGHT: - return '$'; - case LF_ATTACH_PIXEL: - default: - return '+'; - } -} - -static char -DimToChar(char dim) -{ - switch (dim) { - case LF_DIM_FONT: - return 'f'; - case LF_DIM_ICON: - return 'i'; - case LF_DIM_AUTO: - return 'a'; - case LF_DIM_PIXEL: - default: - return 'x'; - } -} -#endif - -static char -CharToAttach(char attach) -{ - switch (attach) { - case '>': - return LF_ATTACH_FWD; - case '<': - return LF_ATTACH_BWD; - case '^': - return LF_ATTACH_LEFT; - case '$': - return LF_ATTACH_RIGHT; - case '+': - default: - return LF_ATTACH_PIXEL; - } -} - -static char -CharToDim(char dim) -{ - switch (dim) { - case 'f': - return LF_DIM_FONT; - case 'i': - return LF_DIM_ICON; - case 'a': - return LF_DIM_AUTO; - case 'l': - return LF_DIM_LABEL; - case 'x': - default: - return LF_DIM_PIXEL; - } -} - -/* **************************************************************** * * Code for reliefs. @@ -144,48 +61,48 @@ CharToDim(char dim) #define RELIEF_RAISED_RULE_SPEC "raisedrule" int -ZnGetRelief(WidgetInfo *wi, - char *name, - ReliefStyle *relief) +ZnGetRelief(ZnWInfo *wi, + char *name, + ZnReliefStyle *relief) { size_t length; length = strlen(name); - if (strncasecmp(name, RELIEF_FLAT_SPEC, length) == 0) { - *relief = RELIEF_FLAT; + if (strncmp(name, RELIEF_FLAT_SPEC, length) == 0) { + *relief = ZN_RELIEF_FLAT; } - else if (strncasecmp(name, RELIEF_SUNKEN_SPEC, length) == 0) { - *relief = RELIEF_SUNKEN; + else if (strncmp(name, RELIEF_SUNKEN_SPEC, length) == 0) { + *relief = ZN_RELIEF_SUNKEN; } - else if ((strncasecmp(name, RELIEF_RAISED_SPEC, length) == 0) && (length >= 2)) { - *relief = RELIEF_RAISED; + else if ((strncmp(name, RELIEF_RAISED_SPEC, length) == 0) && (length >= 2)) { + *relief = ZN_RELIEF_RAISED; } - else if ((strncasecmp(name, RELIEF_RIDGE_SPEC, length) == 0) && (length >= 2)) { - *relief = RELIEF_RIDGE; + else if ((strncmp(name, RELIEF_RIDGE_SPEC, length) == 0) && (length >= 2)) { + *relief = ZN_RELIEF_RIDGE; } - else if (strncasecmp(name, RELIEF_GROOVE_SPEC, length) == 0) { - *relief = RELIEF_GROOVE; + else if (strncmp(name, RELIEF_GROOVE_SPEC, length) == 0) { + *relief = ZN_RELIEF_GROOVE; } - else if ((strncasecmp(name, RELIEF_ROUND_SUNKEN_SPEC, length) == 0) && (length >= 6)) { - *relief = RELIEF_ROUND_SUNKEN; + else if ((strncmp(name, RELIEF_ROUND_SUNKEN_SPEC, length) == 0) && (length >= 6)) { + *relief = ZN_RELIEF_ROUND_SUNKEN; } - else if ((strncasecmp(name, RELIEF_ROUND_RAISED_SPEC, length) == 0) && (length >= 7)) { - *relief = RELIEF_ROUND_RAISED; + else if ((strncmp(name, RELIEF_ROUND_RAISED_SPEC, length) == 0) && (length >= 7)) { + *relief = ZN_RELIEF_ROUND_RAISED; } - else if ((strncasecmp(name, RELIEF_ROUND_RIDGE_SPEC, length) == 0) && (length >= 7)) { - *relief = RELIEF_ROUND_RIDGE; + else if ((strncmp(name, RELIEF_ROUND_RIDGE_SPEC, length) == 0) && (length >= 7)) { + *relief = ZN_RELIEF_ROUND_RIDGE; } - else if ((strncasecmp(name, RELIEF_ROUND_GROOVE_SPEC, length) == 0) && (length >= 6)) { - *relief = RELIEF_ROUND_GROOVE; + else if ((strncmp(name, RELIEF_ROUND_GROOVE_SPEC, length) == 0) && (length >= 6)) { + *relief = ZN_RELIEF_ROUND_GROOVE; } - else if ((strncasecmp(name, RELIEF_SUNKEN_RULE_SPEC, length) == 0) && (length >= 7)) { - *relief = RELIEF_SUNKEN_RULE; + else if ((strncmp(name, RELIEF_SUNKEN_RULE_SPEC, length) == 0) && (length >= 7)) { + *relief = ZN_RELIEF_SUNKEN_RULE; } - else if ((strncasecmp(name, RELIEF_RAISED_RULE_SPEC, length) == 0) && (length >= 7)) { - *relief = RELIEF_RAISED_RULE; + else if ((strncmp(name, RELIEF_RAISED_RULE_SPEC, length) == 0) && (length >= 7)) { + *relief = ZN_RELIEF_RAISED_RULE; } else { - Tcl_AppendResult(wi->interp, "bad relief type \"", name, "\": must be ", + Tcl_AppendResult(wi->interp, "bad relief \"", name, "\": must be ", RELIEF_FLAT_SPEC, ", ", RELIEF_RAISED_SPEC, ", ", RELIEF_SUNKEN_SPEC, ", ", @@ -198,40 +115,40 @@ ZnGetRelief(WidgetInfo *wi, RELIEF_SUNKEN_RULE_SPEC, ", ", RELIEF_RAISED_RULE_SPEC, NULL); - return ZN_ERROR; + return TCL_ERROR; } if (!wi->render) { - *relief = *relief & ~(RELIEF_ROUND|RELIEF_RULE); + *relief = *relief & ~(ZN_RELIEF_ROUND|ZN_RELIEF_RULE); } - return ZN_OK; + return TCL_OK; } char * -ZnNameOfRelief(ReliefStyle relief) +ZnNameOfRelief(ZnReliefStyle relief) { switch (relief) { - case RELIEF_FLAT: + case ZN_RELIEF_FLAT: return RELIEF_FLAT_SPEC; - case RELIEF_SUNKEN: + case ZN_RELIEF_SUNKEN: return RELIEF_SUNKEN_SPEC; - case RELIEF_RAISED: + case ZN_RELIEF_RAISED: return RELIEF_RAISED_SPEC; - case RELIEF_GROOVE: + case ZN_RELIEF_GROOVE: return RELIEF_GROOVE_SPEC; - case RELIEF_RIDGE: + case ZN_RELIEF_RIDGE: return RELIEF_RIDGE_SPEC; - case RELIEF_ROUND_SUNKEN: + case ZN_RELIEF_ROUND_SUNKEN: return RELIEF_ROUND_SUNKEN_SPEC; - case RELIEF_ROUND_RAISED: + case ZN_RELIEF_ROUND_RAISED: return RELIEF_ROUND_RAISED_SPEC; - case RELIEF_ROUND_GROOVE: + case ZN_RELIEF_ROUND_GROOVE: return RELIEF_ROUND_GROOVE_SPEC; - case RELIEF_ROUND_RIDGE: + case ZN_RELIEF_ROUND_RIDGE: return RELIEF_ROUND_RIDGE_SPEC; - case RELIEF_SUNKEN_RULE: + case ZN_RELIEF_SUNKEN_RULE: return RELIEF_SUNKEN_RULE_SPEC; - case RELIEF_RAISED_RULE: + case ZN_RELIEF_RAISED_RULE: return RELIEF_RAISED_RULE_SPEC; default: return "unknown relief"; @@ -239,6 +156,437 @@ ZnNameOfRelief(ReliefStyle relief) } /* + **************************************************************** + * + * Code for borders. + * + **************************************************************** + */ +#define BORDER_LEFT_SPEC "left" +#define BORDER_RIGHT_SPEC "right" +#define BORDER_TOP_SPEC "top" +#define BORDER_BOTTOM_SPEC "bottom" +#define BORDER_CONTOUR_SPEC "contour" +#define BORDER_COUNTER_OBLIQUE_SPEC "counteroblique" +#define BORDER_OBLIQUE_SPEC "oblique" +#define NO_BORDER_SPEC "noborder" + +int +ZnGetBorder(ZnWInfo *wi, + Tcl_Obj *name, + ZnBorder *border) +{ + unsigned int j, len, largc; + Tcl_Obj **largv; + char *str; + + *border = ZN_NO_BORDER; + if (Tcl_ListObjGetElements(wi->interp, name, + &largc, &largv) == TCL_ERROR) { + border_error: + Tcl_AppendResult(wi->interp, "bad line shape \"", Tcl_GetString(name), + "\": must be a list of ", + BORDER_LEFT_SPEC, ", ", + BORDER_RIGHT_SPEC, ", ", + BORDER_TOP_SPEC, ", ", + BORDER_BOTTOM_SPEC, ", ", + BORDER_COUNTER_OBLIQUE_SPEC, ", ", + BORDER_OBLIQUE_SPEC, " or ", + BORDER_CONTOUR_SPEC, ", ", + NO_BORDER_SPEC, " alone", + NULL); + return TCL_ERROR; + } + for (j = 0; j < largc; j++) { + str = Tcl_GetString(largv[j]); + len = strlen(str); + if (strncmp(str, BORDER_LEFT_SPEC, len) == 0) { + *border |= ZN_LEFT_BORDER; + } + else if (strncmp(str, BORDER_RIGHT_SPEC, len) == 0) { + *border |= ZN_RIGHT_BORDER; + } + else if (strncmp(str, BORDER_TOP_SPEC, len) == 0) { + *border |= ZN_TOP_BORDER; + } + else if (strncmp(str, BORDER_BOTTOM_SPEC, len) == 0) { + *border |= ZN_BOTTOM_BORDER; + } + else if (strncmp(str, BORDER_CONTOUR_SPEC, len) == 0) { + *border |= ZN_CONTOUR_BORDER; + } + else if (strncmp(str, BORDER_OBLIQUE_SPEC, len) == 0) { + *border |= ZN_OBLIQUE; + } + else if (strncmp(str, BORDER_COUNTER_OBLIQUE_SPEC, len) == 0) { + *border |= ZN_COUNTER_OBLIQUE; + } + else if (strncmp(str, NO_BORDER_SPEC, len) == 0) { + *border = ZN_NO_BORDER; + } + else { + goto border_error; + } + } + return TCL_OK; +} + +/* + * name must be large enough to hold the returned string. + * 64 chars should be enough with the current values. + */ +void +ZnNameOfBorder(ZnBorder border, + char *name) +{ + if (border == ZN_NO_BORDER) { + strcpy(name, NO_BORDER_SPEC); + return; + } + name[0] = 0; + if ((border & ZN_CONTOUR_BORDER) == ZN_CONTOUR_BORDER) { + strcat(name, BORDER_CONTOUR_SPEC); + } + else { + if (border & ZN_LEFT_BORDER) { + strcat(name, BORDER_LEFT_SPEC); + } + if (border & ZN_RIGHT_BORDER) { + if (name[0] != 0) { + strcat(name, " "); + } + strcat(name, BORDER_RIGHT_SPEC); + } + if (border & ZN_TOP_BORDER) { + if (name[0] != 0) { + strcat(name, " "); + } + strcat(name, BORDER_TOP_SPEC); + } + if (border & ZN_BOTTOM_BORDER) { + if (name[0] != 0) { + strcat(name, " "); + } + strcat(name, BORDER_BOTTOM_SPEC); + } + } + if (border & ZN_OBLIQUE) { + if (name[0] != 0) { + strcat(name, " "); + } + strcat(name, BORDER_OBLIQUE_SPEC); + } + if (border & ZN_COUNTER_OBLIQUE) { + if (name[0] != 0) { + strcat(name, " "); + } + strcat(name, BORDER_COUNTER_OBLIQUE_SPEC); + } +} + +/* + **************************************************************** + * + * Code for line shapes. + * + **************************************************************** + */ +#define STRAIGHT_SPEC "straight" +#define RIGHT_LIGHTNING_SPEC "rightlightning" +#define LEFT_LIGHTNING_SPEC "leftlightning" +#define RIGHT_CORNER_SPEC "rightcorner" +#define LEFT_CORNER_SPEC "leftcorner" +#define DOUBLE_RIGHT_CORNER_SPEC "doublerightcorner" +#define DOUBLE_LEFT_CORNER_SPEC "doubleleftcorner" + +int +ZnGetLineShape(ZnWInfo *wi, + char *name, + ZnLineShape *line_shape) +{ + unsigned int len; + + len = strlen(name); + if (strncmp(name, STRAIGHT_SPEC, len) == 0) { + *line_shape = ZN_LINE_STRAIGHT; + } + else if (strncmp(name, RIGHT_LIGHTNING_SPEC, len) == 0) { + *line_shape = ZN_LINE_RIGHT_LIGHTNING; + } + else if (strncmp(name, LEFT_LIGHTNING_SPEC, len) == 0) { + *line_shape = ZN_LINE_LEFT_LIGHTNING; + } + else if (strncmp(name, RIGHT_CORNER_SPEC, len) == 0) { + *line_shape = ZN_LINE_RIGHT_CORNER; + } + else if (strncmp(name, LEFT_CORNER_SPEC, len) == 0) { + *line_shape = ZN_LINE_LEFT_CORNER; + } + else if (strncmp(name, DOUBLE_RIGHT_CORNER_SPEC, len) == 0) { + *line_shape = ZN_LINE_DOUBLE_RIGHT_CORNER; + } + else if (strncmp(name, DOUBLE_LEFT_CORNER_SPEC, len) == 0) { + *line_shape = ZN_LINE_DOUBLE_LEFT_CORNER; + } + else { + Tcl_AppendResult(wi->interp, "bad line shape \"", name, "\": must be ", + STRAIGHT_SPEC, ", ", + RIGHT_LIGHTNING_SPEC, ", ", + LEFT_LIGHTNING_SPEC, ", ", + RIGHT_CORNER_SPEC, ", ", + LEFT_CORNER_SPEC, ", ", + DOUBLE_RIGHT_CORNER_SPEC, ", ", + DOUBLE_LEFT_CORNER_SPEC, + NULL); + return TCL_ERROR; + } + return TCL_OK; +} + +char * +ZnNameOfLineShape(ZnLineShape line_shape) +{ + switch (line_shape) { + case ZN_LINE_STRAIGHT: + return STRAIGHT_SPEC; + case ZN_LINE_RIGHT_LIGHTNING: + return RIGHT_LIGHTNING_SPEC; + case ZN_LINE_LEFT_LIGHTNING: + return LEFT_LIGHTNING_SPEC; + case ZN_LINE_RIGHT_CORNER: + return RIGHT_CORNER_SPEC; + case ZN_LINE_LEFT_CORNER: + return LEFT_CORNER_SPEC; + case ZN_LINE_DOUBLE_RIGHT_CORNER: + return DOUBLE_RIGHT_CORNER_SPEC; + case ZN_LINE_DOUBLE_LEFT_CORNER: + return DOUBLE_LEFT_CORNER_SPEC; + default: + return "unknown line shape"; + } +} + +/* + **************************************************************** + * + * Code for line styles. + * + **************************************************************** + */ +#define SIMPLE_SPEC "simple" +#define DASHED_SPEC "dashed" +#define DOTTED_SPEC "dotted" +#define MIXED_SPEC "mixed" + +int +ZnGetLineStyle(ZnWInfo *wi, + char *name, + ZnLineStyle *line_style) +{ + unsigned int len; + + len = strlen(name); + if (strncmp(name, SIMPLE_SPEC, len) == 0) + *line_style = ZN_LINE_SIMPLE; + else if (strncmp(name, DASHED_SPEC, len) == 0) + *line_style = ZN_LINE_DASHED; + else if (strncmp(name, MIXED_SPEC, len) == 0) + *line_style = ZN_LINE_MIXED; + else if (strncmp(name, DOTTED_SPEC, len) == 0) + *line_style = ZN_LINE_DOTTED; + else { + Tcl_AppendResult(wi->interp, "bad line style \"", name, "\": must be ", + SIMPLE_SPEC, ", ", + DASHED_SPEC, ", ", + DOTTED_SPEC, ", ", + MIXED_SPEC, + NULL); + return TCL_ERROR; + } + return TCL_OK; +} + +char * +ZnNameOfLineStyle(ZnLineStyle line_style) +{ + switch (line_style) { + case ZN_LINE_SIMPLE: + return SIMPLE_SPEC; + case ZN_LINE_DASHED: + return DASHED_SPEC; + case ZN_LINE_MIXED: + return MIXED_SPEC; + case ZN_LINE_DOTTED: + return DOTTED_SPEC; + default: + return "unknown line style"; + } +} + +/* + **************************************************************** + * + * Code for leader anchors. + * + * Format is: lChar leftLeaderAnchor [ lChar rightLeaderAnchor] + * + * If lChar is a '|', leftLeaderAnchor and rightLeaderAnchor are the indices + * of the fields that serve to anchor the label's leader. More specifically + * the bottom left corner of the left field and the bottom right corner of + * the right field are used as the anchors. + * If lChar is '%', leftLeaderAnchor and rightLeaderAnchor should be + * specified as 'valxval', 'val' being a percentage (max 100) of the + * width/height of the label bounding box. + * If rightLeaderAnchor is not specified it defaults to leftLeaderAnchor. + * If neither of them are specified, the center of the label is used as an + * anchor. + * + **************************************************************** + */ +int +ZnGetLeaderAnchors(ZnWInfo *wi, + char *name, + ZnLeaderAnchors *leader_anchors) +{ + int anchors[4]; + int index, num_tok, anchor_index=0; + + *leader_anchors = NULL; + while (*name && (*name == ' ')) { + name++; + } + while (*name && (anchor_index < 4)) { + switch (*name) { + case '|': + num_tok = sscanf(name, "|%d%n", &anchors[anchor_index], &index); + if (num_tok != 1) { + la_error: + Tcl_AppendResult(wi->interp, " incorrect leader anchors \"", + name, "\"", NULL); + return TCL_ERROR; + } + anchors[anchor_index+1] = -1; + break; + case '%': + num_tok = sscanf(name, "%%%dx%d%n", &anchors[anchor_index], + &anchors[anchor_index+1], &index); + if (num_tok != 2) { + goto la_error; + } + if (anchors[anchor_index] < 0) { + anchors[anchor_index] = 0; + } + if (anchors[anchor_index] > 100) { + anchors[anchor_index] = 100; + } + if (anchors[anchor_index+1] < 0) { + anchors[anchor_index+1] = 0; + } + if (anchors[anchor_index+1] > 100) { + anchors[anchor_index+1] = 100; + } + break; + } + anchor_index += 2; + name += index; + } + /* + * If empty, pick the default (center of the bounding box). + */ + if (anchor_index != 0) { + *leader_anchors = ZnMalloc(sizeof(ZnLeaderAnchorsStruct)); + (*leader_anchors)->left_x = anchors[0]; + (*leader_anchors)->left_y = anchors[1]; + if (anchor_index == 2) { + (*leader_anchors)->right_x = (*leader_anchors)->left_x; + (*leader_anchors)->right_y = (*leader_anchors)->left_y; + } + else { + (*leader_anchors)->right_x = anchors[2]; + (*leader_anchors)->right_y = anchors[3]; + } + } + return TCL_OK; +} + +/* + * name must be large enough to hold the returned string. + */ +void +ZnNameOfLeaderAnchors(ZnLeaderAnchors leader_anchors, + char *name) +{ + unsigned int count; + + if (!leader_anchors) { + strcpy(name, "%50x50"); + } + else { + if (leader_anchors->left_y < 0) { + count = sprintf(name, "|%d", leader_anchors->left_x); + } + else { + count = sprintf(name, "%%%dx%d", leader_anchors->left_x, + leader_anchors->left_y); + } + name += count; + if (leader_anchors->right_y < 0) { + sprintf(name, "|%d", leader_anchors->right_x); + } + else { + sprintf(name, "%%%dx%d", leader_anchors->right_x, leader_anchors->right_y); + } + } +} + +/* + ****************************************************************** + * + * Code for label formats. + * + ****************************************************************** + */ +static Tcl_HashTable format_cache; +static ZnBool format_inited = False; + + +static char +CharToAttach(int attach) +{ + switch (attach) { + case '>': + return ZN_LF_ATTACH_FWD; + case '<': + return ZN_LF_ATTACH_BWD; + case '^': + return ZN_LF_ATTACH_LEFT; + case '$': + return ZN_LF_ATTACH_RIGHT; + case '+': + default: + return ZN_LF_ATTACH_PIXEL; + } +} + +static char +CharToDim(int dim) +{ + switch (dim) { + case 'f': + return ZN_LF_DIM_FONT; + case 'i': + return ZN_LF_DIM_ICON; + case 'a': + return ZN_LF_DIM_AUTO; + case 'l': + return ZN_LF_DIM_LABEL; + case 'x': + default: + return ZN_LF_DIM_PIXEL; + } +} + +/* * The new format is as follow. Parameters between [] are * optional and take default values when omitted. The spaces can appear * between blocks but not inside. @@ -272,9 +620,9 @@ ZnNameOfRelief(ReliefStyle relief) * */ ZnLabelFormat -LabelFormatCreate(Tcl_Interp *interp, - char *format_str, - int num_fields) +ZnLFCreate(Tcl_Interp *interp, + char *format_str, + unsigned int num_fields) { ZnList fields; Tcl_HashEntry *entry; @@ -284,7 +632,7 @@ LabelFormatCreate(Tcl_Interp *interp, int width, height; ZnDim c_width=0.0, c_height=0.0; int index, num_tok, num_ffs, new; - int field_index=0; + unsigned int field_index=0; char *ptr = format_str, *next_ptr; char x_char, y_char; @@ -338,8 +686,8 @@ LabelFormatCreate(Tcl_Interp *interp, } if (!*ptr) { /* It is a simple spec, one field. */ - field_struct.x_attach = field_struct.y_attach = LF_ATTACH_PIXEL; - field_struct.x_dim = field_struct.y_dim = LF_DIM_PIXEL; + field_struct.x_attach = field_struct.y_attach = ZN_LF_ATTACH_PIXEL; + field_struct.x_dim = field_struct.y_dim = ZN_LF_DIM_PIXEL; field_struct.x_spec = field_struct.y_spec = 0; field_struct.width_spec = (short) c_width; field_struct.height_spec = (short) c_height; @@ -360,8 +708,8 @@ LabelFormatCreate(Tcl_Interp *interp, } /* Preset the default field values. */ field_struct.x_spec = field_struct.y_spec = 0; - field_struct.x_attach = field_struct.y_attach = LF_ATTACH_PIXEL; - field_struct.x_dim = field_struct.y_dim = LF_DIM_PIXEL; + field_struct.x_attach = field_struct.y_attach = ZN_LF_ATTACH_PIXEL; + field_struct.x_dim = field_struct.y_dim = ZN_LF_DIM_PIXEL; if ((*ptr == 'x') || (*ptr == 'f') || (*ptr == 'i') || (*ptr == 'a') || (*ptr == 'l')) { num_tok = sscanf(ptr, "%c%d%c%d%n", &x_char, &width, @@ -433,7 +781,7 @@ LabelFormatCreate(Tcl_Interp *interp, ZnLabelFormat -LabelFormatDuplicate(ZnLabelFormat lf) +ZnLFDuplicate(ZnLabelFormat lf) { lf->ref_count++; return lf; @@ -441,7 +789,7 @@ LabelFormatDuplicate(ZnLabelFormat lf) void -LabelFormatDelete(ZnLabelFormat lf) +ZnLFDelete(ZnLabelFormat lf) { lf->ref_count--; if (lf->ref_count == 0) { @@ -452,7 +800,7 @@ LabelFormatDelete(ZnLabelFormat lf) char * -LabelFormatGetString(ZnLabelFormat lf) +ZnLFGetString(ZnLabelFormat lf) { return Tcl_GetHashKey(&format_cache, lf->entry); @@ -460,7 +808,7 @@ LabelFormatGetString(ZnLabelFormat lf) ZnFieldFormat ff; char *ptr; char x_char, y_char, w_char, h_char; - int i, count; + unsigned int i, count; ptr = str; if ((lf->clip_width != 0) || (lf->clip_height != 0)) { @@ -502,9 +850,9 @@ LabelFormatGetString(ZnLabelFormat lf) * set to zero, it means that there is no clipbox. */ ZnBool -LabelFormatGetClipBox(ZnLabelFormat lf, - ZnDim *w, - ZnDim *h) +ZnLFGetClipBox(ZnLabelFormat lf, + ZnDim *w, + ZnDim *h) { if ((lf->clip_width == 0) && (lf->clip_height == 0)) { return False; @@ -518,16 +866,16 @@ LabelFormatGetClipBox(ZnLabelFormat lf, void -LabelFormatGetField(ZnLabelFormat lf, - int field, - char *x_attach, - char *y_attach, - char *x_dim, - char *y_dim, - int *x_spec, - int *y_spec, - short *width_spec, - short *height_spec) +ZnLFGetField(ZnLabelFormat lf, + unsigned int field, + char *x_attach, + char *y_attach, + char *x_dim, + char *y_dim, + int *x_spec, + int *y_spec, + short *width_spec, + short *height_spec) { ZnFieldFormat fptr; @@ -555,8 +903,8 @@ static ZnBool line_end_inited = False; ZnLineEnd -LineEndCreate(Tcl_Interp *interp, - char *line_end_str) +ZnLineEndCreate(Tcl_Interp *interp, + char *line_end_str) { Tcl_HashEntry *entry; ZnLineEnd le; @@ -595,14 +943,14 @@ LineEndCreate(Tcl_Interp *interp, char * -LineEndGetString(ZnLineEnd le) +ZnLineEndGetString(ZnLineEnd le) { return Tcl_GetHashKey(&line_end_cache, le->entry); } void -LineEndDelete(ZnLineEnd le) +ZnLineEndDelete(ZnLineEnd le) { le->ref_count--; if (le->ref_count == 0) { @@ -613,8 +961,157 @@ LineEndDelete(ZnLineEnd le) ZnLineEnd -LineEndDuplicate(ZnLineEnd le) +ZnLineEndDuplicate(ZnLineEnd le) { le->ref_count++; return le; } + + +/* + ****************************************************************** + * + * Code for fill rules. They are directly inhereted from the + * GLU tesselator constants. + * + ****************************************************************** + */ +#define FILL_RULE_ODD_SPEC "odd" +#define FILL_RULE_NON_ZERO_SPEC "nonzero" +#define FILL_RULE_POSITIVE_SPEC "positive" +#define FILL_RULE_NEGATIVE_SPEC "negative" +#define FILL_RULE_ABS_GEQ_2_SPEC "abs_geq_2" + +int +ZnGetFillRule(ZnWInfo *wi, + char *name, + ZnFillRule *fill_rule) +{ + unsigned int len; + + len = strlen(name); + if (strncmp(name, FILL_RULE_ODD_SPEC, len) == 0) { + *fill_rule = GLU_TESS_WINDING_ODD; + } + else if (strncmp(name, FILL_RULE_NON_ZERO_SPEC, len) == 0) { + *fill_rule = GLU_TESS_WINDING_NONZERO; + } + else if (strncmp(name, FILL_RULE_POSITIVE_SPEC, len) == 0) { + *fill_rule = GLU_TESS_WINDING_POSITIVE; + } + else if (strncmp(name, FILL_RULE_NEGATIVE_SPEC, len) == 0) { + *fill_rule = GLU_TESS_WINDING_NEGATIVE; + } + else if (strncmp(name, FILL_RULE_ABS_GEQ_2_SPEC, len) == 0) { + *fill_rule = GLU_TESS_WINDING_ABS_GEQ_TWO; + } + else { + Tcl_AppendResult(wi->interp, "bad fill rule \"", name, "\": must be ", + FILL_RULE_ODD_SPEC, ", ", + FILL_RULE_NON_ZERO_SPEC, ", ", + FILL_RULE_POSITIVE_SPEC, ", ", + FILL_RULE_NEGATIVE_SPEC, ", ", + FILL_RULE_ABS_GEQ_2_SPEC, + NULL); + return TCL_ERROR; + } + return TCL_OK; +} + +char * +ZnNameOfFillRule(ZnFillRule fill_rule) +{ + switch (fill_rule) { + case GLU_TESS_WINDING_ODD: + return FILL_RULE_ODD_SPEC; + case GLU_TESS_WINDING_NONZERO: + return FILL_RULE_NON_ZERO_SPEC; + case GLU_TESS_WINDING_POSITIVE: + return FILL_RULE_POSITIVE_SPEC; + case GLU_TESS_WINDING_NEGATIVE: + return FILL_RULE_NEGATIVE_SPEC; + case GLU_TESS_WINDING_ABS_GEQ_TWO: + return FILL_RULE_ABS_GEQ_2_SPEC; + default: + return "unknown fill rule"; + } +} + + +/* + ****************************************************************** + * + * Code for auto alignments in fields. + * + ****************************************************************** + */ +int +ZnGetAutoAlign(ZnWInfo *wi, + char *name, + ZnAutoAlign *aa) +{ + int j; + + if (strcmp(name, "-") == 0) { + aa->automatic = False; + } + else if (strlen(name) == 3) { + aa->automatic = True; + for (j = 0; j < 3; j++) { + switch(name[j]) { + case 'l': + case 'L': + aa->align[j] = TK_JUSTIFY_LEFT; + break; + case 'c': + case 'C': + aa->align[j] = TK_JUSTIFY_CENTER; + break; + case 'r': + case 'R': + aa->align[j] = TK_JUSTIFY_RIGHT; + break; + default: + goto aa_error; + } + } + } + else { + aa_error: + Tcl_AppendResult(wi->interp, "invalid auto alignment specification \"", name, + "\" should be - or a triple of lcr", NULL); + return TCL_ERROR; + } + return TCL_OK; +} + +/* + * name must be large enough to hold the returned string. + * 64 chars should be enough with the current values. + */ +void +ZnNameOfAutoAlign(ZnAutoAlign *aa, + char *name) +{ + unsigned int i; + + if (aa->automatic == False) { + strcpy(name, "-"); + } + else { + name[0] = 0; + for (i = 0; i < 3; i++) { + switch (aa->align[i]) { + case TK_JUSTIFY_LEFT: + strcat(name, "l"); + break; + case TK_JUSTIFY_CENTER: + strcat(name, "c"); + break; + case TK_JUSTIFY_RIGHT: + strcat(name, "r"); + break; + } + } + } +} diff --git a/generic/Attrs.h b/generic/Attrs.h index 25d377d..2c12835 100644 --- a/generic/Attrs.h +++ b/generic/Attrs.h @@ -38,7 +38,114 @@ extern "C" { #include -struct _WidgetInfo; +struct _ZnWInfo; + +/* + * Type and constant values for line styles. + */ +typedef unsigned char ZnLineStyle; + +#define ZN_LINE_SIMPLE 0 +#define ZN_LINE_DASHED 1 +#define ZN_LINE_MIXED 2 +#define ZN_LINE_DOTTED 3 + +int ZnGetLineStyle(struct _ZnWInfo *wi, char *name, ZnLineStyle *line_style); +char *ZnNameOfLineStyle(ZnLineStyle line_style); + + +/* + * Type and constant values for line shapes. + */ +typedef unsigned char ZnLineShape; + +#define ZN_LINE_STRAIGHT 0 +#define ZN_LINE_LEFT_LIGHTNING 1 +#define ZN_LINE_LEFT_CORNER 2 +#define ZN_LINE_DOUBLE_LEFT_CORNER 3 +#define ZN_LINE_RIGHT_LIGHTNING 4 +#define ZN_LINE_RIGHT_CORNER 5 +#define ZN_LINE_DOUBLE_RIGHT_CORNER 6 + +int ZnGetLineShape(struct _ZnWInfo *wi, char *name, ZnLineShape *line_shape); +char *ZnNameOfLineShape(ZnLineShape line_shape); + + +/* + * Type and constant values for relief styles. + */ +typedef unsigned char ZnReliefStyle; +#define ZN_RELIEF_FLAT 0 +#define ZN_RELIEF_RAISED 1 +#define ZN_RELIEF_SUNKEN 2 +#define ZN_RELIEF_GROOVE (ZN_RELIEF_TWO_FACES|ZN_RELIEF_SUNKEN) +#define ZN_RELIEF_RIDGE (ZN_RELIEF_TWO_FACES|ZN_RELIEF_RAISED) +#define ZN_RELIEF_ROUND_SUNKEN (ZN_RELIEF_ROUND|ZN_RELIEF_SUNKEN) +#define ZN_RELIEF_ROUND_RAISED (ZN_RELIEF_ROUND|ZN_RELIEF_RAISED) +#define ZN_RELIEF_ROUND_GROOVE (ZN_RELIEF_ROUND|ZN_RELIEF_TWO_FACES|ZN_RELIEF_SUNKEN) +#define ZN_RELIEF_ROUND_RIDGE (ZN_RELIEF_ROUND|ZN_RELIEF_TWO_FACES|ZN_RELIEF_RAISED) +#define ZN_RELIEF_SUNKEN_RULE (ZN_RELIEF_ROUND|ZN_RELIEF_TWO_FACES|ZN_RELIEF_SUNKEN|ZN_RELIEF_RULE) +#define ZN_RELIEF_RAISED_RULE (ZN_RELIEF_ROUND|ZN_RELIEF_TWO_FACES|ZN_RELIEF_RAISED|ZN_RELIEF_RULE) +#define ZN_RELIEF_ROUND 0x80 +#define ZN_RELIEF_TWO_FACES 0x40 +#define ZN_RELIEF_RULE 0x20 +#define ZN_RELIEF_MASK 0x3 + +/* + * Number of steps for relief drawing. This translate in + * RELIEF_STEPS*2+1 color shades in the color gradient. + */ +#define ZN_RELIEF_STEPS 6 + +int ZnGetRelief(struct _ZnWInfo *wi, char *name, ZnReliefStyle *relief); +char *ZnNameOfRelief(ZnReliefStyle relief); + + +/* + * Type and constant values for borders. + */ +typedef unsigned char ZnBorder; +#define ZN_NO_BORDER 0 +#define ZN_LEFT_BORDER 1 +#define ZN_RIGHT_BORDER 2 +#define ZN_TOP_BORDER 4 +#define ZN_BOTTOM_BORDER 8 +#define ZN_CONTOUR_BORDER (ZN_LEFT_BORDER|ZN_RIGHT_BORDER|ZN_TOP_BORDER|ZN_BOTTOM_BORDER) +#define ZN_COUNTER_OBLIQUE 16 +#define ZN_OBLIQUE 32 + +void ZnNameOfBorder(ZnBorder border, char *str); +int ZnGetBorder(struct _ZnWInfo *wi, Tcl_Obj *name, ZnBorder *border); + + +/* + * Type for leader anchors. + */ +typedef struct { + int left_x; /* left leader anchor field or percent of bbox */ + int right_x; /* right leader anchor field or percent of bbox */ + short left_y; /* left leader percent of bbox or < 0 if field */ + short right_y; /* right leader percent of bbox or < 0 if field */ +} ZnLeaderAnchorsStruct, *ZnLeaderAnchors; + +int ZnGetLeaderAnchors(struct _ZnWInfo *wi, char *name, ZnLeaderAnchors *leader_anchors); +void ZnNameOfLeaderAnchors(ZnLeaderAnchors leader_anchors, char *name); + + +/* + * Type and constant values for automatic alignments. + */ +typedef struct { + ZnBool automatic; + Tk_Justify align[3]; +} ZnAutoAlign; +#define ZN_AA_LEFT 0 +#define ZN_AA_CENTER 1 +#define ZN_AA_RIGHT 2 + +int ZnGetAutoAlign(struct _ZnWInfo *wi, char *name, ZnAutoAlign *aa); +void ZnNameOfAutoAlign(ZnAutoAlign *aa, char *name); + /* * Label Formats. @@ -47,65 +154,65 @@ struct _WidgetInfo; /* * field flags. */ -#define LF_ATTACH_PIXEL 0 -#define LF_ATTACH_FWD 1 -#define LF_ATTACH_BWD 2 -#define LF_ATTACH_LEFT 3 /* Align left on left or top on top */ -#define LF_ATTACH_RIGHT 4 /* Align right on right or bottom on bottom */ - -#define LF_DIM_PIXEL 0 -#define LF_DIM_FONT 1 -#define LF_DIM_ICON 2 -#define LF_DIM_AUTO 3 -#define LF_DIM_LABEL 4 +#define ZN_LF_ATTACH_PIXEL 0 +#define ZN_LF_ATTACH_FWD 1 +#define ZN_LF_ATTACH_BWD 2 +#define ZN_LF_ATTACH_LEFT 3 /* Align left on left or top on top */ +#define ZN_LF_ATTACH_RIGHT 4 /* Align right on right or bottom on bottom */ + +#define ZN_LF_DIM_PIXEL 0 +#define ZN_LF_DIM_FONT 1 +#define ZN_LF_DIM_ICON 2 +#define ZN_LF_DIM_AUTO 3 +#define ZN_LF_DIM_LABEL 4 typedef struct { - int x_spec; - int y_spec; - short width_spec; - short height_spec; - char x_attach; - char y_attach; - char x_dim; - char y_dim; + int x_spec; + int y_spec; + short width_spec; + short height_spec; + char x_attach; + char y_attach; + char x_dim; + char y_dim; } ZnFieldFormatStruct, *ZnFieldFormat; typedef struct { short clip_width; short clip_height; - int num_fields; + unsigned int num_fields; Tcl_HashEntry *entry; - int ref_count; + unsigned int ref_count; ZnFieldFormatStruct fields[1]; } ZnLabelFormatStruct, *ZnLabelFormat; ZnLabelFormat -LabelFormatCreate(Tcl_Interp * /* interp */, - char * /* format_str */, - int /* num_fields */); +ZnLFCreate(Tcl_Interp * /* interp */, + char * /* format_str */, + unsigned int /* num_fields */); ZnLabelFormat -LabelFormatDuplicate(ZnLabelFormat /* label_format */); +ZnLFDuplicate(ZnLabelFormat /* label_format */); void -LabelFormatDelete(ZnLabelFormat /* label_format */); +ZnLFDelete(ZnLabelFormat /* label_format */); char * -LabelFormatGetString(ZnLabelFormat /* label_format */); +ZnLFGetString(ZnLabelFormat /* label_format */); ZnBool -LabelFormatGetClipBox(ZnLabelFormat /* label_format */, - ZnDim */* width */, - ZnDim */* height */); -#define LabelFormatNumFields(lf) ((lf)->num_fields) +ZnLFGetClipBox(ZnLabelFormat /* label_format */, + ZnDim * /* width */, + ZnDim * /* height */); +#define ZnLFNumFields(lf) ((lf)->num_fields) void -LabelFormatGetField(ZnLabelFormat /* label_format */, - int /* field */, - char */* x_attach */, - char */* y_attach */, - char */* x_dim */, - char */* y_dim */, - int */* x_spec */, - int */* y_spec */, - short */* width_spec */, - short */* height_spec */); +ZnLFGetField(ZnLabelFormat /* label_format */, + unsigned int /* field */, + char * /* x_attach */, + char * /* y_attach */, + char * /* x_dim */, + char * /* y_dim */, + int * /* x_spec */, + int * /* y_spec */, + short * /* width_spec */, + short * /* height_spec */); /* * Line Ends. @@ -115,25 +222,29 @@ typedef struct { ZnReal shape_b; ZnReal shape_c; Tcl_HashEntry *entry; - int ref_count; + unsigned int ref_count; } ZnLineEndStruct, *ZnLineEnd; ZnLineEnd -LineEndCreate(Tcl_Interp *interp, - char *line_end_str); +ZnLineEndCreate(Tcl_Interp *interp, + char *line_end_str); ZnLineEnd -LineEndDuplicate(ZnLineEnd le); +ZnLineEndDuplicate(ZnLineEnd le); void -LineEndDelete(ZnLineEnd le); +ZnLineEndDelete(ZnLineEnd le); char * -LineEndGetString(ZnLineEnd le); +ZnLineEndGetString(ZnLineEnd le); + + +/* + * Type and protypes for fill rules. + */ +typedef unsigned int ZnFillRule; + +char *ZnNameOfFillRule(ZnFillRule fill_rule); +int ZnGetFillRule(struct _ZnWInfo *wi, char *name, ZnFillRule *fill_rule); -int -ZnGetRelief(struct _WidgetInfo *wi, char *name, ReliefStyle *relief); -char * -ZnNameOfRelief(ReliefStyle relief); - #ifdef __CPLUSPLUS__ } #endif diff --git a/generic/Color.c b/generic/Color.c index 6518aa0..d0c3a81 100644 --- a/generic/Color.c +++ b/generic/Color.c @@ -36,7 +36,6 @@ */ -#include #include #include @@ -47,101 +46,6 @@ /* - * If a colormap fills up, attempts to allocate new colors from that - * colormap will fail. When that happens, we'll just choose the - * closest color from those that are available in the colormap. - * One of the following structures will be created for each "stressed" - * colormap to keep track of the colors that are available in the - * colormap (otherwise we would have to re-query from the server on - * each allocation, which would be very slow). These entries are - * flushed after a few seconds, since other clients may release or - * reallocate colors over time. - */ -typedef struct StressedCmap { - Colormap colormap; /* X's token for the colormap. */ - int num_colors; /* Number of entries currently active - * at *colorPtr. */ - XColor *color; /* Pointer to malloc'ed array of all - * colors that seem to be available in - * the colormap. Some may not actually - * be available, e.g. because they are - * read-write for another client; when - * we find this out, we remove them - * from the array. */ - struct StressedCmap *next; /* Next in list of all stressed - * colormaps for the display. */ -} StressedCmap; - -typedef struct StressedDpy { - Display *dpy; - StressedCmap *stress; - struct StressedDpy *next; -} StressedDpy; - -static StressedDpy *stressed_display_list = NULL; - - -#define COLOR_MAGIC ((unsigned int) 0x46140277) - -typedef struct ZnColorInfo { - XColor color; /* Information about this color. */ - unsigned int magic; /* Used for quick integrity check on this - * structure. Must always have the - * value COLOR_MAGIC. */ - Screen *screen; /* Screen where this color is valid. Used - * to delete it, and to find its display. */ - Colormap colormap; /* Colormap from which this entry was - * allocated. */ - Visual *visual; /* Visual associated with colormap. */ - int ref_count; /* Number of uses of this structure. */ - Tcl_HashTable *table; /* Hash table that indexes this structure - * (needed when deleting structure). */ - Tcl_HashEntry *hash; /* Pointer to hash table entry for this - * structure. (for use in deleting entry). */ -} ZnColorInfo; - - -/* - * A two-level data structure is used to manage the color database. - * The top level consists of one entry for each color name that is - * currently active, and the bottom level contains one entry for each - * pixel value that is still in use. The distinction between - * levels is necessary because the same pixel may have several - * different names. There are two hash tables, one used to index into - * each of the data structures. The name hash table is used when - * allocating colors, and the pixel hash table is used when freeing - * colors. - */ - -/* - * Hash table for name -> ZnColorInfo mapping, and key structure used to - * index into that table: - */ -static Tcl_HashTable name_table; - -typedef struct { - Tk_Uid name; /* Name of desired color. */ - Colormap colormap; /* Colormap from which color will be - * allocated. */ - Display *display; /* Display for colormap. */ -} NameKey; - - -/* - * Hash table for value -> ZnColorInfo mapping, and key structure used to - * index into that table: - */ -static Tcl_HashTable value_table; - -typedef struct { - int red, green, blue; /* Values for desired color. */ - Colormap colormap; /* Colormap from which color will be - * allocated. */ - Display *display; /* Display for colormap. */ -} ValueKey; - - -/* * Maximum size of a color name including the \0. */ #define COLOR_NAME_SIZE 32 @@ -164,238 +68,6 @@ static int initialized = 0; /* 0 means static structures haven't been /* *---------------------------------------------------------------------- * - * GetStressedDisplay -- - * - * - *---------------------------------------------------------------------- - */ -static StressedDpy * -GetStressedDisplay(Display *dpy) -{ - StressedDpy *cur; - - for (cur = stressed_display_list; cur != NULL; cur = cur->next) { - if (cur->dpy == dpy) { - break; - } - } - if (cur == NULL) { - /* - * Not found, allocate a new one. - */ - cur = (StressedDpy *) ZnMalloc(sizeof(StressedDpy)); - cur->dpy = dpy; - cur->stress = NULL; - cur->next = stressed_display_list; - stressed_display_list = cur; - } - - return cur; -} - - -/* - *---------------------------------------------------------------------- - * - * DeleteStressedCmap -- - * - * This procedure releases the information cached for "colormap" - * so that it will be refetched from the X server the next time - * it is needed. - * - * Results: - * None. - * - * Side effects: - * The StressedCmap structure for colormap is deleted; the - * colormap is no longer considered to be "stressed". - * - * Note: - * This procedure is invoked whenever a color in a colormap is - * freed, and whenever a color allocation in a colormap succeeds. - * This guarantees that StressedCmap structures are always - * deleted before the corresponding Colormap is freed. - * - *---------------------------------------------------------------------- - */ -static void -DeleteStressedCmap(Display *display, - Colormap colormap) -{ - StressedDpy *dpy = GetStressedDisplay(display); - StressedCmap *prev, *stress; - - for (prev = NULL, stress = dpy->stress; stress != NULL; - prev = stress, stress = stress->next) { - if (stress->colormap == colormap) { - if (prev == NULL) { - dpy->stress = stress->next; - } - else { - prev->next = stress->next; - } - ZnFree(stress->color); - ZnFree(stress); - return; - } - } -} - - -/* - *---------------------------------------------------------------------- - * - * FindClosestColor -- - * - * When Tk can't allocate a color because a colormap has filled - * up, this procedure is called to find and allocate the closest - * available color in the colormap. - * - * Results: - * There is no return value, but *actualColorPtr is filled in - * with information about the closest available color in tkwin's - * colormap. This color has been allocated via X, so it must - * be released by the caller when the caller is done with it. - * - * Side effects: - * A color is allocated. - * - *---------------------------------------------------------------------- - */ -static void -FindClosestColor(Tk_Window tkwin, /* Window where color will - * be used. */ - XColor *desired_color, /* RGB values of color that was - * wanted (but unavailable). */ - XColor *actual_color) /* Structure to fill in with - * RGB and pixel for closest - * available color. */ -{ - StressedDpy *dpy = GetStressedDisplay(Tk_Display(tkwin)); - StressedCmap *stress; - double tmp, distance, closest_dist; - int i, closest, num_found; - XColor *color; - Colormap colormap = Tk_Colormap(tkwin); - XVisualInfo template, *vis_info; - - /* - * Find the StressedCmap structure for this colormap, or create - * a new one if needed. - */ - for (stress = dpy->stress; ; stress = stress->next) { - if (stress == NULL) { - stress = (StressedCmap *) ZnMalloc(sizeof(StressedCmap)); - stress->colormap = colormap; - template.visualid = XVisualIDFromVisual(Tk_Visual(tkwin)); - vis_info = XGetVisualInfo(Tk_Display(tkwin), VisualIDMask, - &template, &num_found); - if (num_found < 1) { - ZnWarning("FindClosestColor (Zinc) couldn't lookup visual\n"); - abort(); - } - stress->num_colors = vis_info->colormap_size; - XFree((char *) vis_info); - stress->color = (XColor *) ZnMalloc((unsigned) - (stress->num_colors*sizeof(XColor))); - for (i = 0; i < stress->num_colors; i++) { - stress->color[i].pixel = (unsigned long) i; - } - XQueryColors(Tk_Display(tkwin), colormap, stress->color, stress->num_colors); - stress->next = dpy->stress; - dpy->stress = stress; - break; - } - if (stress->colormap == colormap) { - break; - } - } - - /* - * Find the color that best approximates the desired one, then - * try to allocate that color. If that fails, it must mean that - * the color was read-write (so we can't use it, since it's owner - * might change it) or else it was already freed. Try again, - * over and over again, until something succeeds. - */ - while (1) { - if (stress->num_colors == 0) { - ZnWarning("FindClosestColor (Zinc) ran out of colors\n"); - abort(); - } - closest_dist = 1e30; - closest = 0; - for (color = stress->color, i = 0; i < stress->num_colors; - color++, i++) { - /* - * Use Euclidean distance in RGB space, weighted by Y (of YIQ) - * as the objective function; this accounts for differences - * in the color sensitivity of the eye. - */ - tmp = 0.30*(((int) desired_color->red) - (int) color->red); - distance = tmp*tmp; - tmp = 0.61*(((int) desired_color->green) - (int) color->green); - distance += tmp*tmp; - tmp = 0.11*(((int) desired_color->blue) - (int) color->blue); - distance += tmp*tmp; - if (distance < closest_dist) { - closest = i; - closest_dist = distance; - } - } - if (XAllocColor(Tk_Display(tkwin), colormap, &stress->color[closest]) != 0) { - *actual_color = stress->color[closest]; - return; - } - - /* - * Couldn't allocate the color. Remove it from the table and - * go back to look for the next best color. - */ - stress->color[closest] = stress->color[stress->num_colors-1]; - stress->num_colors -= 1; - } -} - - -/* - *---------------------------------------------------------------------- - * - * CmapStressed -- - * - * Check to see whether a given colormap is known to be out - * of entries. - * - * Results: - * 1 is returned if "colormap" is stressed (i.e. it has run out - * of entries recently), 0 otherwise. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ -#if 0 -static ZnBool -CmapStressed(Tk_Window tkwin, - Colormap colormap) -{ - StressedDpy *dpy = GetStressedDisplay(Tk_Display(tkwin)); - StressedCmap *stress; - - for (stress = dpy->stress; stress != NULL; stress = stress->next) { - if (stress->colormap == colormap) { - return True; - } - } - return False; -} -#endif - - -/* - *---------------------------------------------------------------------- - * * ColorInit -- * * Initialize the structure used for color management. @@ -412,8 +84,6 @@ static void ColorInit() { initialized = 1; - Tcl_InitHashTable(&name_table, sizeof(NameKey)/sizeof(int)); - Tcl_InitHashTable(&value_table, sizeof(ValueKey)/sizeof(int)); Tcl_InitHashTable(&gradient_table, TCL_STRING_KEYS); } @@ -421,431 +91,6 @@ ColorInit() /* *---------------------------------------------------------------------- * - * ZnGetColor -- - * - * Given a string name for a color, map the name to a corresponding - * XColor structure. - * - * Results: - * The return value is a pointer to an XColor structure that - * indicates the red, blue, and green intensities for the color - * given by "name", and also specifies a pixel value to use to - * draw in that color. If an error occurs, NULL is returned and - * an error message will be left in interp->result. - * - * Side effects: - * The color is added to an internal database with a reference count. - * For each call to this procedure, there should eventually be a call - * to ZnFreeColor so that the database is cleaned up when colors - * aren't in use anymore. - * - *---------------------------------------------------------------------- - */ -XColor * -ZnGetColor(Tcl_Interp *interp, - Tk_Window tkwin, /* Window in which color will be used. */ - Tk_Uid name) /* Name of color to allocated (in form - * suitable for passing to XParseColor). */ -{ - NameKey name_key; - Tcl_HashEntry *name_hash; - int new; - Display *dpy = Tk_Display(tkwin); - Colormap colormap = Tk_Colormap(tkwin); - XColor color, screen; - ZnColorInfo *tk_col; - - if (!initialized) { - ColorInit(); - } - - /* - * First, check to see if there's already a mapping for this color - * name. - */ - name = Tk_GetUid(name); - name_key.name = name; - name_key.colormap = Tk_Colormap(tkwin); - name_key.display = Tk_Display(tkwin); - name_hash = Tcl_CreateHashEntry(&name_table, (char *) &name_key, &new); - if (!new) { - tk_col = (ZnColorInfo *) Tcl_GetHashValue(name_hash); - tk_col->ref_count++; - /*printf("ZnGetColor cache hit for: %d %d %d\n", - tk_col->color.red, tk_col->color.green, tk_col->color.blue);*/ - return &tk_col->color; - } - - /* - * Map from the name to a pixel value. Call XAllocNamedColor rather than - * XParseColor for non-# names: this saves a server round-trip for those - * names. - */ - if (*name != '#') { - if (XAllocNamedColor(dpy, colormap, name, &screen, &color) != 0) { - DeleteStressedCmap(dpy, colormap); - } - else { - /* - * Couldn't allocate the color. Try translating the name to - * a color value, to see whether the problem is a bad color - * name or a full colormap. If the colormap is full, then - * pick an approximation to the desired color. - */ - if (XLookupColor(dpy, colormap, name, &color, &screen) == 0) { - col_err: - if (*name == '#') { - Tcl_AppendResult(interp, "invalid color name \"", name, - "\"", (char *) NULL); - } - else { - Tcl_AppendResult(interp, "unknown color name \"", name, - "\"", (char *) NULL); - } - Tcl_DeleteHashEntry(name_hash); - return (XColor *) NULL; - } - FindClosestColor(tkwin, &screen, &color); - } - } - else { - if (XParseColor(dpy, colormap, name, &color) == 0) { - goto col_err; - } - /*printf("parsed color : %d %d %d\n", color.red, color.green, color.blue);*/ - if (XAllocColor(dpy, colormap, &color) != 0) { - /*printf("alloced color : %d %d %d\n", color.red, color.green, color.blue);*/ - DeleteStressedCmap(dpy, colormap); - } - else { - FindClosestColor(tkwin, &color, &color); - } - } - - tk_col = (ZnColorInfo *) ZnMalloc(sizeof(ZnColorInfo)); - tk_col->color = color; - - /* - * Now create a new ZnColorInfo structure and add it to nameTable. - */ - tk_col->magic = COLOR_MAGIC; - tk_col->screen = Tk_Screen(tkwin); - tk_col->colormap = name_key.colormap; - tk_col->visual = Tk_Visual(tkwin); - tk_col->ref_count = 1; - tk_col->table = &name_table; - tk_col->hash = name_hash; - Tcl_SetHashValue(name_hash, tk_col); - - /*printf("ZnGetColor created: %x %x %x\n", - tk_col->color.red, tk_col->color.green, tk_col->color.blue);*/ - return &tk_col->color; -} - - -/* - *---------------------------------------------------------------------- - * - * ZnGetColorByValue -- - * - * Given a desired set of red-green-blue intensities for a color, - * locate a pixel value to use to draw that color in a given - * window. - * - * Results: - * The return value is a pointer to an XColor structure that - * indicates the closest red, blue, and green intensities available - * to those specified in colorPtr, and also specifies a pixel - * value to use to draw in that color. - * - * Side effects: - * The color is added to an internal database with a reference count. - * For each call to this procedure, there should eventually be a call - * to ZnFreeColor, so that the database is cleaned up when colors - * aren't in use anymore. - * - *---------------------------------------------------------------------- - */ -XColor * -ZnGetColorByValue(Tk_Window tkwin, - XColor *color) -{ - ValueKey value_key; - Tcl_HashEntry *value_hash; - int new; - ZnColorInfo *tk_col; - Display *dpy = Tk_Display(tkwin); - Colormap colormap = Tk_Colormap(tkwin); - - if (!initialized) { - ColorInit(); - } - - /*printf("ZnGetColorByValue input color: %x %x %x\n", - color->red, color->green, color->blue);*/ - /* - * First, check to see if there's already a mapping for this color - * name. - */ - value_key.red = color->red; - value_key.green = color->green; - value_key.blue = color->blue; - value_key.colormap = Tk_Colormap(tkwin); - value_key.display = Tk_Display(tkwin); - value_hash = Tcl_CreateHashEntry(&value_table, (char *) &value_key, &new); - if (!new) { - tk_col = (ZnColorInfo *) Tcl_GetHashValue(value_hash); - tk_col->ref_count++; - return &tk_col->color; - } - - /* - * The name isn't currently known. Find a pixel value - * to use to draw that color in a given window. - */ - tk_col = (ZnColorInfo *) ZnMalloc(sizeof(ZnColorInfo)); - tk_col->color.red = color->red; - tk_col->color.green = color->green; - tk_col->color.blue = color->blue; - if (XAllocColor(dpy, colormap, &tk_col->color) != 0) { - /*if (tk_col->color.red != color->red || - tk_col->color.green != color->green || - tk_col->color.blue != color->blue) { - printf("couleur allouée approximative %d %d %d --> %d %d %d\n", - tk_col->color.red, tk_col->color.green, tk_col->color.blue, - color->red, color->green, color->blue); - }*/ - DeleteStressedCmap(dpy, colormap); - } - else { - /*printf("ZnGetColorByValue XAllocColor failed\n");*/ - FindClosestColor(tkwin, &tk_col->color, &tk_col->color); - } - - tk_col->magic = COLOR_MAGIC; - tk_col->screen = Tk_Screen(tkwin); - tk_col->colormap = value_key.colormap; - tk_col->visual = Tk_Visual(tkwin); - tk_col->ref_count = 1; - tk_col->table = &value_table; - tk_col->hash = value_hash; - Tcl_SetHashValue(value_hash, tk_col); - - /*printf("ZnGetColorByValue created: %x %x %x\n", - tk_col->color.red, tk_col->color.green, tk_col->color.blue);*/ - - return &tk_col->color; -} - - -/* - *-------------------------------------------------------------- - * - * ZnNameOfColor -- - * - * Given a color, return a textual string identifying - * the color. - * - * Results: - * If colorPtr was created by Tk_GetColor, then the return - * value is the "string" that was used to create it. - * Otherwise the return value is a string that could have - * been passed to Tk_GetColor to allocate that color. The - * storage for the returned string is only guaranteed to - * persist up until the next call to this procedure. - * - * Side effects: - * None. - * - *-------------------------------------------------------------- - */ -Tk_Uid -ZnNameOfColor(XColor *color) -{ - register ZnColorInfo *tk_col = (ZnColorInfo *) color; - static char string[20]; - - if ((tk_col->magic == COLOR_MAGIC) && (tk_col->table == &name_table)) { - return ((NameKey *) tk_col->hash->key.words)->name; - } - sprintf(string, "#%04x%04x%04x", color->red, color->green, color->blue); - return string; -} - - -/* - *---------------------------------------------------------------------- - * - * ZnFreeColor -- - * - * This procedure is called to release a color allocated by - * ZnGetColor or ZnGetColorByValue. - * - * Results: - * None. - * - * Side effects: - * The reference count associated with colorPtr is deleted, and - * the color is released to X if there are no remaining uses - * for it. - * - *---------------------------------------------------------------------- - */ -void -ZnFreeColor(XColor *color) /* Color to be released. Must have been - * allocated by ZnGetColor or - * ZnGetColorByValue. */ -{ - ZnColorInfo *tk_col = (ZnColorInfo *) color; - Visual *visual; - Screen *screen = tk_col->screen; - Tk_ErrorHandler handler; - - /* - * Do a quick sanity check to make sure this color was really - * allocated by ZnGetColor. - */ - if (tk_col->magic != COLOR_MAGIC) { - ZnWarning("ZnFreeColor called with bogus color\n"); - abort(); - } - - tk_col->ref_count--; - if (tk_col->ref_count == 0) { - /*printf("ZnFreeColor freeing %s\n", ZnNameOfColor(color));*/ - /* - * Careful! Don't free black or white, since this will - * make some servers very unhappy. Also, there is a bug in - * some servers (such Sun's X11/NeWS server) where reference - * counting is performed incorrectly, so that if a color is - * allocated twice in different places and then freed twice, - * the second free generates an error (this bug existed as of - * 10/1/92). To get around this problem, ignore errors that - * occur during the free operation. - */ - visual = tk_col->visual; - if ((visual->class != StaticGray) && (visual->class != StaticColor) && - (tk_col->color.pixel != BlackPixelOfScreen(screen)) && - (tk_col->color.pixel != WhitePixelOfScreen(screen))) { - handler = Tk_CreateErrorHandler(DisplayOfScreen(screen), - -1, -1, -1, (Tk_ErrorProc *) NULL, - (ClientData) NULL); - XFreeColors(DisplayOfScreen(screen), tk_col->colormap, - &tk_col->color.pixel, 1, 0L); - Tk_DeleteErrorHandler(handler); - } - DeleteStressedCmap(DisplayOfScreen(screen), tk_col->colormap); - - Tcl_DeleteHashEntry(tk_col->hash); - tk_col->magic = 0; - ZnFree(tk_col); - } -} - - -/* - *---------------------------------------------------------------------- - * - * RgbToHsv - * HsvToRgb -- - * - *---------------------------------------------------------------------- - */ -#if 0 -static void -RgbToHsv(int r, - int g, - int b, - ZnReal *h, - ZnReal *s, - ZnReal *v) -{ - ZnReal max, min, range, rc, gc, bc; - - max = (r > g) ? ((b > r) ? b : r) : ((b > g) ? b : g); - min = (r < g) ? ((b < r) ? b : r) : ((b < g) ? b : g); - range = max - min; - if (max == 0) { - *s = 0.0; - } - else { - *s = range / max; - } - if (*s == 0) { - *h = 0; - } - else { - rc = (max - r) / range; - gc = (max - g) / range; - bc = (max - b) / range; - *h = (max == r) ? (0.166667*(bc-gc)) : ((max == g) ? (0.166667*(2+rc-bc)) : (0.166667*(4+gc-rc))); - } - *v = max/65535.0; -} - -static void -HsvToRgb(ZnReal h, - ZnReal s, - ZnReal v, - unsigned short *r, - unsigned short *g, - unsigned short *b) -{ - int lv, i, p, q, t; - ZnReal f; - - lv = (int) (65535 * v); - if (s == 0) { - *r = *g = *b = lv; - return; - } - h *= 6.0; - if (h >= 6.0) { - h = 0.0; - } - i = (int) h; - f = h - i; - p = (int) (65535 * v * (1 - s)); - q = (int) (65535 * v * (1 - (s * f))); - t = (int) (65535 * v * (1 - (s * (1 - f)))); - switch (i) { - case 0: - *r = lv; - *g = t; - *b = p; - break; - case 1: - *r = q; - *g = lv; - *b = p; - break; - case 2: - *r = p; - *g = lv; - *b = t; - break; - case 3: - *r = p; - *g = q; - *b = lv; - break; - case 4: - *r = t; - *g = p; - *b = lv; - break; - case 5: - *r = lv; - *g = p; - *b = q; - break; - } -} -#endif - -/* - *---------------------------------------------------------------------- - * * ZnGetGradientColor -- * *---------------------------------------------------------------------- @@ -853,7 +98,7 @@ HsvToRgb(ZnReal h, XColor * ZnGetGradientColor(ZnGradient *grad, ZnReal position, - int *alpha) + unsigned short *alpha) { int index, min, max; XColor *shade=NULL; @@ -941,15 +186,15 @@ ZnGradient * ZnGetReliefGradient(Tcl_Interp *interp, Tk_Window tkwin, Tk_Uid name, - int alpha) + unsigned short alpha) { - XColor *base, light_color, dark_color, color; - char color_name[COLOR_NAME_SIZE]; - char buffer[COLOR_NAME_SIZE*(3+2*RELIEF_STEPS)]; - int j, tmp1, tmp2; - int red_range, green_range, blue_range; + XColor *base, light_color, dark_color, color; + char color_name[COLOR_NAME_SIZE]; + char buffer[COLOR_NAME_SIZE*(3+2*ZN_RELIEF_STEPS)]; + int j, tmp1, tmp2; + int red_range, green_range, blue_range; - base = ZnGetColor(interp, tkwin, name); + base = Tk_GetColor(interp, tkwin, name); /* * Compute the border gradient. * @@ -1006,12 +251,12 @@ ZnGetReliefGradient(Tcl_Interp *interp, green_range = (int) base->green - (int) dark_color.green; blue_range = (int) base->blue - (int) dark_color.blue; strcat(buffer, color_name); - for (j = 1; j < RELIEF_STEPS; j++) { - color.red =(int) dark_color.red + red_range * j/RELIEF_STEPS; - color.green = (int) dark_color.green + green_range * j/RELIEF_STEPS; - color.blue = (int) dark_color.blue + blue_range * j/RELIEF_STEPS; + for (j = 1; j < ZN_RELIEF_STEPS; j++) { + color.red =(int) dark_color.red + red_range * j/ZN_RELIEF_STEPS; + color.green = (int) dark_color.green + green_range * j/ZN_RELIEF_STEPS; + color.blue = (int) dark_color.blue + blue_range * j/ZN_RELIEF_STEPS; sprintf(color_name, "#%02x%02x%02x;%d %d|", - color.red/256, color.green/256, color.blue/256, alpha, 50/RELIEF_STEPS*j); + color.red/256, color.green/256, color.blue/256, alpha, 50/ZN_RELIEF_STEPS*j); strcat(buffer, color_name); } sprintf(color_name, "#%02x%02x%02x;%d 50|", @@ -1020,12 +265,12 @@ ZnGetReliefGradient(Tcl_Interp *interp, red_range = (int) light_color.red - (int) base->red; green_range = (int) light_color.green - (int) base->green; blue_range = (int) light_color.blue - (int) base->blue; - for (j = 1; j < RELIEF_STEPS; j++) { - color.red = (int) base->red + red_range * j/RELIEF_STEPS; - color.green = (int) base->green + green_range * j/RELIEF_STEPS; - color.blue = (int) base->blue + blue_range * j/RELIEF_STEPS; + for (j = 1; j < ZN_RELIEF_STEPS; j++) { + color.red = (int) base->red + red_range * j/ZN_RELIEF_STEPS; + color.green = (int) base->green + green_range * j/ZN_RELIEF_STEPS; + color.blue = (int) base->blue + blue_range * j/ZN_RELIEF_STEPS; sprintf(color_name, "#%02x%02x%02x;%d %d|", - color.red/256, color.green/256, color.blue/256, alpha, 50+50/RELIEF_STEPS*j); + color.red/256, color.green/256, color.blue/256, alpha, 50+50/ZN_RELIEF_STEPS*j); strcat(buffer, color_name); } sprintf(color_name, "#%02x%02x%02x;%d", @@ -1128,7 +373,7 @@ ZnDeleteGradientName(char *name) * gradient := [graddesc|]color[|....|color] * where the | are real characters not meta-syntax. * - * graddesc := @type args + * graddesc := =type args * where type := axial | radial | path * args := angle if type = axial; angle in (0..360) * args := x y if type = (radial| path); x and @@ -1172,7 +417,7 @@ ZnGetGradient(Tcl_Interp *interp, #define SEGMENT_SIZE 64 Tcl_HashEntry *hash; ZnGradient *grad; - int i, j, nspace, new, num_colors; + unsigned int i, j, nspace, num_colors; unsigned int size; char type; char const *scan_ptr, *next_ptr, *str_ptr; @@ -1181,7 +426,7 @@ ZnGetGradient(Tcl_Interp *interp, char *color_ptr, *end, segment[SEGMENT_SIZE]; ZnGradientColor *first, *last; XColor color; - int red_range, green_range, blue_range; + int new, red_range, green_range, blue_range; /* printf("ZnGetGradient : %s\n", desc);*/ if (!desc || !*desc) { @@ -1325,7 +570,7 @@ ZnGetGradient(Tcl_Interp *interp, desc, "\",", NULL); grad_err2: for (j = 0; j < i; j++) { - ZnFreeColor(grad->colors[j].rgb); + Tk_FreeColor(grad->colors[j].rgb); } ZnFree(grad); goto grad_err1; @@ -1362,7 +607,7 @@ ZnGetGradient(Tcl_Interp *interp, if (color_ptr) { *color_ptr = 0; } - grad->colors[i].rgb = ZnGetColor(interp, tkwin, Tk_GetUid(segment)); + grad->colors[i].rgb = Tk_GetColor(interp, tkwin, Tk_GetUid(segment)); if (grad->colors[i].rgb == NULL) { Tcl_AppendResult(interp, "incorrect color value in gradient \"", desc, "\",", NULL); @@ -1412,7 +657,7 @@ ZnGetGradient(Tcl_Interp *interp, color.red =(int) first->rgb->red + red_range/2; color.green = (int) first->rgb->green + green_range/2; color.blue = (int) first->rgb->blue + blue_range/2; - first->mid_rgb = ZnGetColorByValue(tkwin, &color); + first->mid_rgb = Tk_GetColorByValue(tkwin, &color); first->mid_alpha = first->alpha + (last->alpha-first->alpha)/2; } grad->colors[grad->num_colors-1].mid_rgb = NULL; @@ -1467,15 +712,15 @@ ZnNameOfGradient(ZnGradient *grad) void ZnFreeGradient(ZnGradient *grad) { - int i; + unsigned int i; grad->ref_count--; if (grad->ref_count == 0) { Tcl_DeleteHashEntry(grad->hash); for (i = 0; i < grad->num_colors; i++) { - ZnFreeColor(grad->colors[i].rgb); + Tk_FreeColor(grad->colors[i].rgb); if (grad->colors[i].mid_rgb) { - ZnFreeColor(grad->colors[i].mid_rgb); + Tk_FreeColor(grad->colors[i].mid_rgb); } } ZnFree(grad); @@ -1494,8 +739,8 @@ ZnFreeGradient(ZnGradient *grad) *-------------------------------------------------------------- */ int -ZnComposeAlpha(int alpha1, - int alpha2) +ZnComposeAlpha(unsigned short alpha1, + unsigned short alpha2) { return (alpha1*alpha2/100)*65535/100; } diff --git a/generic/Color.h b/generic/Color.h index c55a256..a3fe2ce 100644 --- a/generic/Color.h +++ b/generic/Color.h @@ -32,9 +32,17 @@ #include "Types.h" +#include "Geo.h" -typedef struct _GradientColor { +/* + * Types of gradients. + */ +#define ZN_AXIAL_GRADIENT 0 +#define ZN_RADIAL_GRADIENT 1 +#define ZN_PATH_GRADIENT 2 + +typedef struct _ZnGradientColor { unsigned char position; /* Color starting position along the gradient axis. * This is in percent of the gradient total size. */ unsigned char control; /* Middle-shade position in percent of this color @@ -45,7 +53,7 @@ typedef struct _GradientColor { XColor *mid_rgb; } ZnGradientColor; -typedef struct _Gradient { +typedef struct _ZnGradient { int ref_count; Tcl_HashEntry *hash; char type; /* Either ZN_AXIAL_GRADIENT (lines) or @@ -54,30 +62,25 @@ typedef struct _Gradient { int angle; /* Angle spec for an axial gradient (Degrees). */ ZnPoint p; /* Center for a radial gradiant. */ } g; - int num_colors; /* Number of colors in gradient spec. */ + unsigned int num_colors; /* Number of colors in gradient spec. */ ZnGradientColor colors[1]; } ZnGradient; -XColor *ZnGetColor(Tcl_Interp *interp, Tk_Window tkwin, Tk_Uid name); -XColor *ZnGetColorByValue(Tk_Window tkwin, XColor *color); -Tk_Uid ZnNameOfColor(XColor *color); -void ZnFreeColor(XColor *color); - ZnGradient *ZnGetGradient(Tcl_Interp *interp, Tk_Window tkwin, Tk_Uid name); ZnGradient *ZnGetGradientByValue(ZnGradient *gradient); ZnGradient *ZnGetReliefGradient(Tcl_Interp *interp, Tk_Window tkwin, - Tk_Uid name, int alpha); + Tk_Uid name, unsigned short alpha); ZnBool ZnGradientFlat(ZnGradient *grad); XColor *ZnGetGradientColor(ZnGradient *gradient, - ZnReal position, int *alpha); + ZnReal position, unsigned short *alpha); char *ZnNameOfGradient(ZnGradient *gradient); void ZnFreeGradient(ZnGradient *gradient); void ZnDeleteGradientName(char *name); ZnBool ZnGradientNameExists(char *name); ZnBool ZnNameGradient(Tcl_Interp *interp, Tk_Window tkwin, char *grad_descr, char *name); -int ZnComposeAlpha(int alpha1, int alpha2); +int ZnComposeAlpha(unsigned short alpha1, unsigned short alpha2); #endif /* _Color_h */ diff --git a/generic/Curve.c b/generic/Curve.c index 6c9b5ad..b58c59a 100644 --- a/generic/Curve.c +++ b/generic/Curve.c @@ -35,10 +35,9 @@ #include "Image.h" #include "Color.h" #include "tkZinc.h" +#include "glu.h" #include -#include -#include static const char rcsid[] = "$Id$"; static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ " $"; @@ -67,7 +66,7 @@ static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ " ********************************************************************************** */ typedef struct _CurveItemStruct { - ItemStruct header; + ZnItemStruct header; /* Public data */ ZnPoly shape; @@ -75,10 +74,10 @@ typedef struct _CurveItemStruct { ZnImage marker; ZnLineEnd first_end; /* These two are considered only if relief is flat */ ZnLineEnd last_end; - LineStyle line_style; /* This is considered only if relief is flat */ + ZnLineStyle line_style; /* This is considered only if relief is flat */ int cap_style; int join_style; - ReliefStyle relief; + ZnReliefStyle relief; ZnDim line_width; /* If 0 the path is not drawn, if <2 relief is flat */ ZnImage fill_pattern; ZnGradient *fill_color; @@ -102,13 +101,13 @@ static ZnAttrConfig cv_attrs[] = { { ZN_CONFIG_BOOL, "-closed", NULL, Tk_Offset(CurveItemStruct, flags), CLOSED_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_BOOL, "-composealpha", NULL, - Tk_Offset(CurveItemStruct, header.flags), COMPOSE_ALPHA_BIT, + Tk_Offset(CurveItemStruct, header.flags), ZN_COMPOSE_ALPHA_BIT, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-composerotation", NULL, - Tk_Offset(CurveItemStruct, header.flags), COMPOSE_ROTATION_BIT, + Tk_Offset(CurveItemStruct, header.flags), ZN_COMPOSE_ROTATION_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_BOOL, "-composescale", NULL, - Tk_Offset(CurveItemStruct, header.flags), COMPOSE_SCALE_BIT, + Tk_Offset(CurveItemStruct, header.flags), ZN_COMPOSE_SCALE_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_GRADIENT, "-fillcolor", NULL, Tk_Offset(CurveItemStruct, fill_color), 0, @@ -145,7 +144,7 @@ static ZnAttrConfig cv_attrs[] = { { ZN_CONFIG_RELIEF, "-relief", NULL, Tk_Offset(CurveItemStruct, relief), 0, ZN_COORDS_FLAG, False }, { ZN_CONFIG_BOOL, "-sensitive", NULL, - Tk_Offset(CurveItemStruct, header.flags), SENSITIVE_BIT, + Tk_Offset(CurveItemStruct, header.flags), ZN_SENSITIVE_BIT, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-smoothrelief", NULL, Tk_Offset(CurveItemStruct, flags), SMOOTH_RELIEF_BIT, @@ -155,10 +154,10 @@ static ZnAttrConfig cv_attrs[] = { { ZN_CONFIG_IMAGE, "-tile", NULL, Tk_Offset(CurveItemStruct, tile), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-visible", NULL, - Tk_Offset(CurveItemStruct, header.flags), VISIBLE_BIT, + Tk_Offset(CurveItemStruct, 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 } }; @@ -170,13 +169,13 @@ static ZnAttrConfig cv_attrs[] = { ********************************************************************************** */ static int -Init(Item item, +Init(ZnItem item, int *argc, Tcl_Obj *CONST *args[]) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; CurveItem cv = (CurveItem) item; - int i, num_points, count; + unsigned int i, num_points, count; ZnPoint *p, *points; char *controls; @@ -188,28 +187,27 @@ Init(Item item, cv->grad_geo = NULL; /* 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); + 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); CLEAR(cv->flags, CLOSED_BIT); CLEAR(cv->flags, SMOOTH_RELIEF_BIT); cv->fill_rule = GLU_TESS_WINDING_ODD; - - item->priority = DEFAULT_CURVE_PRIORITY; + item->priority = 1; if (*argc < 1) { Tcl_AppendResult(wi->interp, " curve coords expected", NULL); - return ZN_ERROR; + return TCL_ERROR; } if (ZnParseCoordList(wi, (*args)[0], &points, - &controls, &num_points, NULL) == ZN_ERROR) { - return ZN_ERROR; + &controls, &num_points, NULL) == TCL_ERROR) { + return TCL_ERROR; } if (num_points == 0) { - POLY_INIT(&cv->shape); + ZnPolyInit(&cv->shape); } else { /* @@ -236,7 +234,7 @@ Init(Item item, contr_err: ZnFree(controls); Tcl_AppendResult(wi->interp, " curve coords expected", NULL); - return ZN_ERROR; + return TCL_ERROR; } } } @@ -248,7 +246,7 @@ Init(Item item, /*printf("plain contour, numpoints: %d %g@%g\n", num_points, points[0].x, points[0].y);*/ memcpy(p, points, num_points * sizeof(ZnPoint)); - POLY_CONTOUR1(&cv->shape, p, num_points, False); + ZnPolyContour1(&cv->shape, p, num_points, False); cv->shape.contours[0].controls = controls; } (*args)++; @@ -257,8 +255,8 @@ Init(Item item, CLEAR(cv->flags, FILLED_BIT); cv->first_end = NULL; cv->last_end = NULL; - cv->line_style = LINE_SIMPLE; - cv->relief = RELIEF_FLAT; + cv->line_style = ZN_LINE_SIMPLE; + cv->relief = ZN_RELIEF_FLAT; cv->line_width = 1; cv->tile = ZnUnspecifiedImage; cv->fill_pattern = ZnUnspecifiedImage; @@ -276,7 +274,7 @@ Init(Item item, cv->line_color = ZnGetGradientByValue(wi->fore_color); cv->marker_color = ZnGetGradientByValue(wi->fore_color); - return ZN_OK; + return TCL_OK; } @@ -288,17 +286,12 @@ Init(Item item, ********************************************************************************** */ static void -Clone(Item item) +Clone(ZnItem item) { CurveItem cv = (CurveItem) item; - int i; + unsigned int i; ZnContour *conts; - if (cv->grad_geo) { - ZnPoint *grad_geo = ZnMalloc(4*sizeof(ZnPoint)); - memcpy(grad_geo, cv->grad_geo, 4*sizeof(ZnPoint)); - cv->grad_geo = grad_geo; - } if (cv->shape.num_contours) { conts = cv->shape.contours; @@ -324,10 +317,10 @@ Clone(Item item) cv->gradient = ZnGetGradientByValue(cv->gradient); } if (cv->first_end) { - LineEndDuplicate(cv->first_end); + ZnLineEndDuplicate(cv->first_end); } if (cv->last_end) { - LineEndDuplicate(cv->last_end); + ZnLineEndDuplicate(cv->last_end); } if (cv->tile != ZnUnspecifiedImage) { cv->tile = ZnGetImageByValue(cv->tile); @@ -343,6 +336,7 @@ Clone(Item item) } cv->line_color = ZnGetGradientByValue(cv->line_color); cv->fill_color = ZnGetGradientByValue(cv->fill_color); + cv->grad_geo = NULL; cv->marker_color = ZnGetGradientByValue(cv->marker_color); cv->tristrip.num_strips = 0; cv->tristrip.strips = NULL; @@ -359,10 +353,10 @@ Clone(Item item) ********************************************************************************** */ static void -Destroy(Item item) +Destroy(ZnItem item) { CurveItem cv = (CurveItem) item; - int i; + unsigned int i; /* * Need to free the control array here, it is only known @@ -373,16 +367,16 @@ Destroy(Item item) ZnFree(cv->shape.contours[i].controls); } } - POLY_FREE(&cv->shape); + ZnPolyFree(&cv->shape); if (cv->grad_geo) { ZnFree(cv->grad_geo); } if (cv->first_end) { - LineEndDelete(cv->first_end); + ZnLineEndDelete(cv->first_end); } if (cv->last_end) { - LineEndDelete(cv->last_end); + ZnLineEndDelete(cv->last_end); } if (cv->gradient) { ZnFreeGradient(cv->gradient); @@ -408,10 +402,10 @@ Destroy(Item item) ZnFreeGradient(cv->marker_color); if (cv->tristrip.num_strips) { - TRI_FREE(&cv->tristrip); + ZnTriFree(&cv->tristrip); } if (cv->outlines.num_contours) { - POLY_FREE(&cv->outlines); + ZnPolyFree(&cv->outlines); } } @@ -431,7 +425,7 @@ SetRenderFlags(CurveItem cv) ISSET(cv->flags, FILLED_BIT) && (cv->shape.num_contours >= 1)); ASSIGN(cv->flags, RELIEF_OK, - (cv->relief != RELIEF_FLAT) && + (cv->relief != ZN_RELIEF_FLAT) && (cv->shape.num_contours >= 1) && (cv->line_width > 1)); @@ -462,30 +456,30 @@ SetRenderFlags(CurveItem cv) ********************************************************************************** */ static int -Configure(Item item, +Configure(ZnItem item, int argc, Tcl_Obj *CONST argv[], int *flags) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; CurveItem cv = (CurveItem) item; - int status = ZN_OK; + int status = TCL_OK; XColor *color; - int alpha; + unsigned short alpha; status = ZnConfigureAttributes(wi, item, cv_attrs, argc, argv, flags); if (cv->gradient && - (ISSET(*flags, ZN_BORDER_FLAG) || (cv->relief == RELIEF_FLAT))) { + (ISSET(*flags, ZN_BORDER_FLAG) || (cv->relief == ZN_RELIEF_FLAT))) { ZnFreeGradient(cv->gradient); cv->gradient = NULL; } - if ((cv->relief != RELIEF_FLAT) && !cv->gradient) { + if ((cv->relief != ZN_RELIEF_FLAT) && !cv->gradient) { color = ZnGetGradientColor(cv->line_color, 51.0, &alpha); cv->gradient = ZnGetReliefGradient(wi->interp, wi->win, - ZnNameOfColor(color), alpha); + Tk_NameOfColor(color), alpha); if (cv->gradient == NULL) { - status = ZN_ERROR; + status = TCL_ERROR; } } @@ -501,15 +495,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, cv_attrs, argv[0]) == ZN_ERROR) { - return ZN_ERROR; + if (ZnQueryAttribute(item->wi, item, cv_attrs, argv[0]) == TCL_ERROR) { + return TCL_ERROR; } - return ZN_OK; + return TCL_OK; } @@ -518,7 +512,7 @@ CurveTessBegin(GLenum type, void *data) { CurveItem cv = data; - WidgetInfo *wi = ((Item) data)->wi; + ZnWInfo *wi = ((ZnItem) data)->wi; ZnListEmpty(wi->work_pts); wi->tess_type = type; @@ -544,7 +538,7 @@ CurveTessVertex(void *vertex_data, void *data) { CurveItem cv = data; - WidgetInfo *wi = ((Item) data)->wi; + ZnWInfo *wi = ((ZnItem) data)->wi; ZnPoint p; int size; @@ -571,9 +565,9 @@ static void CurveTessEnd(void *data) { CurveItem cv = data; - WidgetInfo *wi = ((Item) data)->wi; - int size = ZnListSize(wi->work_pts); - int num; + ZnWInfo *wi = ((ZnItem) data)->wi; + unsigned int size = ZnListSize(wi->work_pts); + unsigned int num; if (wi->tess_type == GL_LINE_LOOP) { /* Add the last point to close the outline */ @@ -584,7 +578,7 @@ CurveTessEnd(void *data) memcpy(cv->outlines.contours[num-1].points, ZnListArray(wi->work_pts), size * sizeof(ZnPoint)); cv->outlines.contours[num-1].points[size-1] = cv->outlines.contours[num-1].points[0]; - cv->outlines.contours[num-1].cw = !TestCCW(cv->outlines.contours[num-1].points, size); + cv->outlines.contours[num-1].cw = !ZnTestCCW(cv->outlines.contours[num-1].points, size); } else { num = cv->tristrip.num_strips; @@ -597,12 +591,12 @@ CurveTessEnd(void *data) } static void CurveTessCombine(GLdouble coords[3], - void *vertex_data[4], - GLfloat weight[4], + void *vertex_data[4] __unused, + GLfloat weight[4] __unused, void **out_data, void *data) { - WidgetInfo *wi = ((Item) data)->wi; + ZnWInfo *wi = ((ZnItem) data)->wi; ZnCombineData *cdata; cdata = ZnMalloc(sizeof(ZnCombineData)); @@ -616,36 +610,38 @@ CurveTessCombine(GLdouble coords[3], } static void CurveTessError(GLenum errno, - void *data) + void *data __unused) { fprintf(stderr, "Tesselation error in curve item: %d\n", errno); } -#ifndef WIN -#define CALLBACK -#endif - static void UpdateTristrip(CurveItem cv, ZnPoly *poly, ZnBool revert) { - WidgetInfo *wi = ((Item) cv)->wi; + ZnWInfo *wi = ((ZnItem) cv)->wi; ZnCombineData *cdata, *cnext; GLdouble v[3]; - int i, j; + unsigned int j, k; + int i; - /*printf("UpdateTristrips sur %d\n", ((Item) cv)->id);*/ - gluTessCallback(wi->tess, GLU_TESS_BEGIN_DATA, (void (CALLBACK *)()) CurveTessBegin); - gluTessCallback(wi->tess, GLU_TESS_VERTEX_DATA, (void (*)()) CurveTessVertex); - gluTessCallback(wi->tess, GLU_TESS_END_DATA, (void (*)()) CurveTessEnd); - gluTessCallback(wi->tess, GLU_TESS_COMBINE_DATA, (void (*)()) CurveTessCombine); - gluTessCallback(wi->tess, GLU_TESS_ERROR_DATA, (void (*)()) CurveTessError); - gluTessProperty(wi->tess, GLU_TESS_WINDING_RULE, cv->fill_rule); - gluTessNormal(wi->tess, 0, 0, -1); + /*printf("UpdateTristrips sur %d\n", ((ZnItem) cv)->id);*/ + gluTessCallback(wi->tess, GLU_TESS_BEGIN_DATA, + (_GLUfuncptr) CurveTessBegin); + gluTessCallback(wi->tess, GLU_TESS_VERTEX_DATA, + (_GLUfuncptr) CurveTessVertex); + gluTessCallback(wi->tess, GLU_TESS_END_DATA, + (_GLUfuncptr) CurveTessEnd); + gluTessCallback(wi->tess, GLU_TESS_COMBINE_DATA, + (_GLUfuncptr) CurveTessCombine); + gluTessCallback(wi->tess, GLU_TESS_ERROR_DATA, + (_GLUfuncptr) CurveTessError); + gluTessProperty(wi->tess, GLU_TESS_WINDING_RULE, (GLdouble) cv->fill_rule); + gluTessNormal(wi->tess, 0.0, 0.0, -1.0); if (cv->tristrip.num_strips == 0) { - gluTessProperty(wi->tess, GLU_TESS_BOUNDARY_ONLY, GL_FALSE); + gluTessProperty(wi->tess, GLU_TESS_BOUNDARY_ONLY, (GLdouble) GL_FALSE); gluTessBeginPolygon(wi->tess, cv); /* * We need to take care of the final (after transformation) winding @@ -657,13 +653,13 @@ UpdateTristrip(CurveItem cv, gluTessBeginContour(wi->tess); /*printf("Début contour %d num_points %d\n", j, poly->contours[j].num_points);*/ - for (i = 0; i < poly->contours[j].num_points; i++) { - /*printf("%g@%g ", poly->contours[j].points[i].x, poly->contours[j].points[i].y);*/ - v[0] = poly->contours[j].points[i].x; - v[1] = poly->contours[j].points[i].y; + 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; + v[1] = poly->contours[j].points[k].y; v[2] = 0; - gluTessVertex(wi->tess, v, &poly->contours[j].points[i]); - } + gluTessVertex(wi->tess, v, &poly->contours[j].points[k]); + } /*printf("\n");*/ gluTessEndContour(wi->tess); } @@ -673,7 +669,7 @@ UpdateTristrip(CurveItem cv, gluTessBeginContour(wi->tess); /*printf("revert Début contour %d num_points %d\n", j, poly->contours[j].num_points);*/ - for (i = poly->contours[j].num_points-1; i >= 0; i--) { + 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; v[1] = poly->contours[j].points[i].y; @@ -693,7 +689,7 @@ UpdateTristrip(CurveItem cv, } wi->tess_combine_list = NULL; } - /*printf("Fin UpdateTristrips sur %d\n", ((Item) cv)->id);*/ + /*printf("Fin UpdateTristrips sur %d\n", ((ZnItem) cv)->id);*/ } static void @@ -701,22 +697,28 @@ UpdateOutlines(CurveItem cv, ZnPoly *poly, ZnBool revert) { - WidgetInfo *wi = ((Item) cv)->wi; + ZnWInfo *wi = ((ZnItem) cv)->wi; ZnCombineData *cdata, *cnext; GLdouble v[3]; - int i, j; + unsigned int j, k; + int i; - /*printf("UpdateOutlines sur %d\n", ((Item) cv)->id);*/ - gluTessCallback(wi->tess, GLU_TESS_BEGIN_DATA, (void (*)()) CurveTessBegin); - gluTessCallback(wi->tess, GLU_TESS_VERTEX_DATA, (void (*)()) CurveTessVertex); - gluTessCallback(wi->tess, GLU_TESS_END_DATA, (void (*)()) CurveTessEnd); - gluTessCallback(wi->tess, GLU_TESS_COMBINE_DATA, (void (*)()) CurveTessCombine); - gluTessCallback(wi->tess, GLU_TESS_ERROR_DATA, (void (*)()) CurveTessError); - gluTessProperty(wi->tess, GLU_TESS_WINDING_RULE, cv->fill_rule); - gluTessNormal(wi->tess, 0, 0, -1); + /*printf("UpdateOutlines sur %d\n", ((ZnItem) cv)->id);*/ + gluTessCallback(wi->tess, GLU_TESS_BEGIN_DATA, + (_GLUfuncptr) CurveTessBegin); + gluTessCallback(wi->tess, GLU_TESS_VERTEX_DATA, + (_GLUfuncptr) CurveTessVertex); + gluTessCallback(wi->tess, GLU_TESS_END_DATA, + (_GLUfuncptr) CurveTessEnd); + gluTessCallback(wi->tess, GLU_TESS_COMBINE_DATA, + (_GLUfuncptr) CurveTessCombine); + gluTessCallback(wi->tess, GLU_TESS_ERROR_DATA, + (_GLUfuncptr) CurveTessError); + gluTessProperty(wi->tess, GLU_TESS_WINDING_RULE, (GLdouble) cv->fill_rule); + gluTessNormal(wi->tess, 0.0, 0.0, -1.0); if (cv->outlines.num_contours == 0) { - gluTessProperty(wi->tess, GLU_TESS_BOUNDARY_ONLY, GL_TRUE); + gluTessProperty(wi->tess, GLU_TESS_BOUNDARY_ONLY, (GLdouble) GL_TRUE); gluTessBeginPolygon(wi->tess, cv); /* @@ -727,11 +729,11 @@ UpdateOutlines(CurveItem cv, if (!revert) { for (j = 0; j < poly->num_contours; j++){ gluTessBeginContour(wi->tess); - for (i = 0; i < poly->contours[j].num_points; i++) { - v[0] = poly->contours[j].points[i].x; - v[1] = poly->contours[j].points[i].y; + for (k = 0; k < poly->contours[j].num_points; k++) { + v[0] = poly->contours[j].points[k].x; + v[1] = poly->contours[j].points[k].y; v[2] = 0; - gluTessVertex(wi->tess, v, &poly->contours[j].points[i]); + gluTessVertex(wi->tess, v, &poly->contours[j].points[k]); } gluTessEndContour(wi->tess); } @@ -739,7 +741,7 @@ UpdateOutlines(CurveItem cv, else { for (j = 0; j < poly->num_contours; j++){ gluTessBeginContour(wi->tess); - for (i = poly->contours[j].num_points-1; i >= 0; i--) { + for (i = (int) (poly->contours[j].num_points-1); i >= 0; i--) { v[0] = poly->contours[j].points[i].x; v[1] = poly->contours[j].points[i].y; v[2] = 0; @@ -757,7 +759,7 @@ UpdateOutlines(CurveItem cv, } wi->tess_combine_list = NULL; } - /*printf("Fin UpdateOutlines sur %d\n", ((Item) cv)->id);*/ + /*printf("Fin UpdateOutlines sur %d\n", ((ZnItem) cv)->id);*/ } @@ -769,22 +771,22 @@ UpdateOutlines(CurveItem cv, ********************************************************************************** */ static void -ComputeCoordinates(Item item, - ZnBool force) +ComputeCoordinates(ZnItem item, + ZnBool force __unused) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; CurveItem cv = (CurveItem) item; - int i, j; - ZnPoint end_points[LINE_END_POINTS]; + unsigned int i, j; + ZnPoint end_points[ZN_LINE_END_POINTS]; ZnPoint *points; - int num_points, num_contours, segment_start; + unsigned int num_points, num_contours, segment_start; ZnBBox bbox; - int lw; + ZnDim lw; ZnContour *c1, *c2; ZnPoly dev; ZnBool revert; - ResetBBox(&item->item_bounding_box); + ZnResetBBox(&item->item_bounding_box); /*printf("Curve CC: flags %x\n", cv->flags);*/ SetRenderFlags(cv); @@ -795,13 +797,13 @@ ComputeCoordinates(Item item, } if (cv->tristrip.num_strips) { - TRI_FREE(&cv->tristrip); + ZnTriFree(&cv->tristrip); } if (cv->outlines.num_contours) { - POLY_FREE(&cv->outlines); + ZnPolyFree(&cv->outlines); }; - POLY_INIT(&dev); + ZnPolyInit(&dev); if (num_contours != 1) { dev.contours = ZnMalloc(num_contours * sizeof(ZnContour)); dev.num_contours = num_contours; @@ -851,9 +853,9 @@ ComputeCoordinates(Item item, c2->points[segment_start+1].x, c2->points[segment_start+1].y, c2->points[j-1].x, c2->points[j-1].y, c2->points[j].x, c2->points[j].y);*/ - GetBezierPoints(&c2->points[segment_start], - &c2->points[segment_start+1], &c2->points[j-1], - &c2->points[j], wi->work_pts, 0.5); + ZnGetBezierPoints(&c2->points[segment_start], + &c2->points[segment_start+1], &c2->points[j-1], + &c2->points[j], wi->work_pts, 0.5); } else { /*printf("lineto %g@%g\n", c2->points[j].x, c2->points[j].y);*/ @@ -868,9 +870,9 @@ ComputeCoordinates(Item item, * multiple contours). */ if (c1->controls[c1->num_points-1]) { - GetBezierPoints(&c2->points[segment_start], - &c2->points[segment_start+1], &c2->points[c1->num_points-1], - &c2->points[0], wi->work_pts, 0.5); + ZnGetBezierPoints(&c2->points[segment_start], + &c2->points[segment_start+1], &c2->points[c1->num_points-1], + &c2->points[0], wi->work_pts, 0.5); } /* @@ -911,8 +913,8 @@ ComputeCoordinates(Item item, printf("\n"); }*/ } - POLY_CONTOUR1(&cv->outlines, dev.contours[0].points, dev.contours[0].num_points, - cv->shape.contours[0].cw); + ZnPolyContour1(&cv->outlines, dev.contours[0].points, dev.contours[0].num_points, + cv->shape.contours[0].cw); } else { UpdateTristrip(cv, &dev, revert); @@ -923,7 +925,7 @@ ComputeCoordinates(Item item, cv->shape.contours[0].cw, cw_dev_contour1, cv->tristrip.num_strips); }*/ UpdateOutlines(cv, &dev, revert); - POLY_FREE(&dev); + ZnPolyFree(&dev); } lw = cv->line_width; @@ -935,13 +937,13 @@ ComputeCoordinates(Item item, * Add to bounding box. */ ZnGetPolygonReliefBBox(c2->points, c2->num_points, lw, &bbox); - AddBBoxToBBox(&item->item_bounding_box, &bbox); + ZnAddBBoxToBBox(&item->item_bounding_box, &bbox); } } else { c2 = cv->outlines.contours; for (i = 0; i < num_contours; i++, c2++) { - AddPointsToBBox(&item->item_bounding_box, c2->points, c2->num_points); + ZnAddPointsToBBox(&item->item_bounding_box, c2->points, c2->num_points); } /* @@ -965,9 +967,9 @@ ComputeCoordinates(Item item, if (cv->join_style == JoinMiter) { ZnPoint miter_i, miter_o; for (i = c2->num_points-1, points = c2->points; i >= 3; i--, points++) { - GetMiterPoints(points, points+1, points+2, lw, &miter_i, &miter_o); - AddPointToBBox(&item->item_bounding_box, miter_i.x, miter_i.y); - AddPointToBBox(&item->item_bounding_box, miter_o.x, miter_o.y); + ZnGetMiterPoints(points, points+1, points+2, lw, &miter_i, &miter_o); + ZnAddPointToBBox(&item->item_bounding_box, miter_i.x, miter_i.y); + ZnAddPointToBBox(&item->item_bounding_box, miter_o.x, miter_o.y); } } /* @@ -986,7 +988,7 @@ ComputeCoordinates(Item item, bbox.orig.y = points->y - h; bbox.corner.x = points->x + w; bbox.corner.y = points->y + h; - AddBBoxToBBox(&item->item_bounding_box, &bbox); + ZnAddBBoxToBBox(&item->item_bounding_box, &bbox); } } /* @@ -995,14 +997,14 @@ ComputeCoordinates(Item item, num_points = c2->num_points; points = c2->points; if (ISSET(cv->flags, FIRST_END_OK)) { - GetLineEnd(&points[0], &points[1], lw, cv->cap_style, - cv->first_end, end_points); - AddPointsToBBox(&item->item_bounding_box, end_points, LINE_END_POINTS); + ZnGetLineEnd(&points[0], &points[1], lw, cv->cap_style, + cv->first_end, end_points); + ZnAddPointsToBBox(&item->item_bounding_box, end_points, ZN_LINE_END_POINTS); } if (ISSET(cv->flags, LAST_END_OK)) { - GetLineEnd(&points[num_points-1], &points[num_points-2], - lw, cv->cap_style, cv->last_end, end_points); - AddPointsToBBox(&item->item_bounding_box, end_points, LINE_END_POINTS); + ZnGetLineEnd(&points[num_points-1], &points[num_points-2], + lw, cv->cap_style, cv->last_end, end_points); + ZnAddPointsToBBox(&item->item_bounding_box, end_points, ZN_LINE_END_POINTS); } } @@ -1016,13 +1018,14 @@ ComputeCoordinates(Item item, item->item_bounding_box.corner.y += 1; } -#ifdef GLX +#ifdef GL if (!ZnGradientFlat(cv->fill_color)) { if (!cv->grad_geo) { cv->grad_geo = ZnMalloc(6*sizeof(ZnPoint)); } if (cv->fill_color->type == ZN_AXIAL_GRADIENT) { - ZnComputeAxialGradient(wi, &cv->shape, cv->fill_color->g.angle, cv->grad_geo); + ZnComputeAxialGradient(wi, &cv->shape, (ZnReal) cv->fill_color->g.angle, + cv->grad_geo); } else if (cv->fill_color->type == ZN_RADIAL_GRADIENT) { ZnComputeRadialGradient(wi, &cv->shape, False, &cv->fill_color->g.p, cv->grad_geo); @@ -1052,16 +1055,16 @@ ComputeCoordinates(Item item, ********************************************************************************** */ static int -ToArea(Item item, +ToArea(ZnItem item, ZnToArea ta) { CurveItem cv = (CurveItem) item; ZnBBox bbox, *area = ta->area; ZnPoint *points; ZnPoint triangle[3]; - ZnPoint end_points[LINE_END_POINTS]; - int i, j, num_points, stop, result=-1, result2; - int width, height; + ZnPoint end_points[ZN_LINE_END_POINTS]; + unsigned int i, j, num_points, stop; + int width, height, result=-1, result2; ZnBool first_done = False; if (cv->outlines.num_contours == 0) { @@ -1094,10 +1097,10 @@ ToArea(Item item, } if (!first_done) { first_done = True; - result = PolygonInBBox(triangle, 3, area, NULL); + result = ZnPolygonInBBox(triangle, 3, area, NULL); } else { - result2 = PolygonInBBox(triangle, 3, area, NULL); + result2 = ZnPolygonInBBox(triangle, 3, area, NULL); if (result2 != result) { return 0; } @@ -1114,8 +1117,8 @@ ToArea(Item item, if (!first_done) { first_done = True; if (ISCLEAR(cv->flags, RELIEF_OK)) { - result = PolylineInBBox(points, num_points, - cv->line_width, cv->cap_style, cv->join_style, area); + result = ZnPolylineInBBox(points, num_points, + cv->line_width, cv->cap_style, cv->join_style, area); } else { result = ZnPolygonReliefInBBox(points, num_points, cv->line_width, area); @@ -1126,8 +1129,8 @@ ToArea(Item item, } else { if (ISCLEAR(cv->flags, RELIEF_OK)) { - result2 = PolylineInBBox(points, num_points, - cv->line_width, cv->cap_style, cv->join_style, area); + result2 = ZnPolylineInBBox(points, num_points, + cv->line_width, cv->cap_style, cv->join_style, area); } else { result2 = ZnPolygonReliefInBBox(points, num_points, cv->line_width, area); @@ -1144,16 +1147,16 @@ ToArea(Item item, points = cv->outlines.contours[0].points; num_points = cv->outlines.contours[0].num_points; if (ISSET(cv->flags, FIRST_END_OK)) { - GetLineEnd(&points[0], &points[1], cv->line_width, cv->cap_style, - cv->first_end, end_points); - if (PolygonInBBox(end_points, LINE_END_POINTS, area, NULL) != result) { + ZnGetLineEnd(&points[0], &points[1], cv->line_width, cv->cap_style, + cv->first_end, end_points); + if (ZnPolygonInBBox(end_points, ZN_LINE_END_POINTS, area, NULL) != result) { return 0; } } if (ISSET(cv->flags, LAST_END_OK)) { - GetLineEnd(&points[num_points-1], &points[num_points-2], cv->line_width, - cv->cap_style, cv->last_end, end_points); - if (PolygonInBBox(end_points, LINE_END_POINTS, area, NULL) != result) { + ZnGetLineEnd(&points[num_points-1], &points[num_points-2], cv->line_width, + cv->cap_style, cv->last_end, end_points); + if (ZnPolygonInBBox(end_points, ZN_LINE_END_POINTS, area, NULL) != result) { return 0; } } @@ -1181,7 +1184,7 @@ ToArea(Item item, bbox.orig.y = points->y - (height+1)/2; bbox.corner.x = bbox.orig.x + width; bbox.corner.y = bbox.orig.y + height; - if (BBoxInBBox(&bbox, area) != result) { + if (ZnBBoxInBBox(&bbox, area) != result) { return 0; } } @@ -1200,12 +1203,12 @@ ToArea(Item item, ********************************************************************************** */ static void -Draw(Item item) +Draw(ZnItem item) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; CurveItem cv = (CurveItem) item; XGCValues values; - int i, j, num_points=0, num2; + unsigned int i, j, num_points=0, num2; unsigned int gc_mask; ZnPoint *points=NULL; XPoint *xpoints=NULL; @@ -1225,16 +1228,16 @@ Draw(Item item) gc_mask = GCFillStyle; if (cv->tile != ZnUnspecifiedImage) { /* Fill tiled */ values.fill_style = FillTiled; - values.tile = ZnImagePixmap(cv->tile, NULL); - values.ts_x_origin = REAL_TO_INT(item->item_bounding_box.orig.x); - values.ts_y_origin = REAL_TO_INT(item->item_bounding_box.orig.y); + 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, NULL); - values.ts_x_origin = REAL_TO_INT(item->item_bounding_box.orig.x); - values.ts_y_origin = REAL_TO_INT(item->item_bounding_box.orig.y); + 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; } else { /* Fill solid */ @@ -1249,13 +1252,13 @@ Draw(Item item) points = cv->tristrip.strips[i].points; if (cv->tristrip.strips[i].fan) { XPoint xpoints[3]; - xpoints[0].x = REAL_TO_INT(points[0].x); - xpoints[0].y = REAL_TO_INT(points[0].y); - xpoints[1].x = REAL_TO_INT(points[1].x); - xpoints[1].y = REAL_TO_INT(points[1].y); + xpoints[0].x = ZnNearestInt(points[0].x); + xpoints[0].y = ZnNearestInt(points[0].y); + xpoints[1].x = ZnNearestInt(points[1].x); + xpoints[1].y = ZnNearestInt(points[1].y); for (j = 2; j < num_points; j++) { - xpoints[2].x = REAL_TO_INT(points[j].x); - xpoints[2].y = REAL_TO_INT(points[j].y); + xpoints[2].x = ZnNearestInt(points[j].x); + xpoints[2].y = ZnNearestInt(points[j].y); XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc, xpoints, 3, Convex, CoordModeOrigin); xpoints[1] = xpoints[2]; @@ -1265,8 +1268,8 @@ Draw(Item item) ZnListAssertSize(wi->work_xpts, num_points); xpoints = ZnListArray(wi->work_xpts); for (j = 0; j < num_points; j++) { - xpoints[j].x = REAL_TO_INT(points[j].x); - xpoints[j].y = REAL_TO_INT(points[j].y); + xpoints[j].x = ZnNearestInt(points[j].x); + xpoints[j].y = ZnNearestInt(points[j].y); } for (j = 0; j < num_points-2; j++) { XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc, @@ -1280,8 +1283,8 @@ Draw(Item item) * Draw the lines between points */ if (cv->line_width) { - ZnPoint end_points[LINE_END_POINTS]; - XPoint xp[LINE_END_POINTS]; + ZnPoint end_points[ZN_LINE_END_POINTS]; + XPoint xp[ZN_LINE_END_POINTS]; /* * Drawing with relief disables: ends, line style and line pattern. @@ -1300,8 +1303,8 @@ Draw(Item item) } else { ZnSetLineStyle(wi, cv->line_style); - values.foreground = ZnPixel(ZnGetGradientColor(cv->line_color, 0, NULL)); - values.line_width = (cv->line_width == 1) ? 0 : cv->line_width; + values.foreground = ZnPixel(ZnGetGradientColor(cv->line_color, 0.0, NULL)); + values.line_width = (cv->line_width == 1) ? 0 : (int) cv->line_width; values.join_style = cv->join_style; values.cap_style = cv->cap_style; if (cv->line_pattern == ZnUnspecifiedImage) { @@ -1311,7 +1314,7 @@ Draw(Item item) } else { values.fill_style = FillStippled; - values.stipple = ZnImagePixmap(cv->line_pattern, NULL); + values.stipple = ZnImagePixmap(cv->line_pattern); XChangeGC(wi->dpy, wi->gc, GCFillStyle|GCStipple|GCLineWidth|GCJoinStyle|GCCapStyle|GCForeground, &values); @@ -1322,33 +1325,33 @@ Draw(Item item) ZnListAssertSize(wi->work_xpts, num_points); xpoints = ZnListArray(wi->work_xpts); for (i = 0; i < num2; 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); } if (ISSET(cv->flags, CLOSED_BIT)) { xpoints[num2] = xpoints[0]; } XDrawLines(wi->dpy, wi->draw_buffer, wi->gc, - xpoints, num_points, CoordModeOrigin); + xpoints, (int) num_points, CoordModeOrigin); } if (ISSET(cv->flags, FIRST_END_OK)) { - GetLineEnd(&points[0], &points[1], cv->line_width, cv->cap_style, - cv->first_end, end_points); - for (i = 0; i < LINE_END_POINTS; i++) { - xp[i].x = end_points[i].x; - xp[i].y = end_points[i].y; + ZnGetLineEnd(&points[0], &points[1], cv->line_width, cv->cap_style, + cv->first_end, end_points); + for (i = 0; i < ZN_LINE_END_POINTS; i++) { + xp[i].x = (short) end_points[i].x; + xp[i].y = (short) end_points[i].y; } - XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc, xp, LINE_END_POINTS, + XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc, xp, ZN_LINE_END_POINTS, Nonconvex, CoordModeOrigin); } if (ISSET(cv->flags, LAST_END_OK)) { - GetLineEnd(&points[num_points-1], &points[num_points-2], cv->line_width, - cv->cap_style, cv->last_end, end_points); - for (i = 0; i < LINE_END_POINTS; i++) { - xp[i].x = end_points[i].x; - xp[i].y = end_points[i].y; + ZnGetLineEnd(&points[num_points-1], &points[num_points-2], cv->line_width, + cv->cap_style, cv->last_end, end_points); + for (i = 0; i < ZN_LINE_END_POINTS; i++) { + xp[i].x = (short) end_points[i].x; + xp[i].y = (short) end_points[i].y; } - XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc, xp, LINE_END_POINTS, + XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc, xp, ZN_LINE_END_POINTS, Nonconvex, CoordModeOrigin); } } @@ -1359,15 +1362,15 @@ Draw(Item item) * if last point join first point suppress markers at end points. */ if (ISSET(cv->flags, MARKER_OK)) { - int h_width, h_height, width, height; - ZnPoint ptmp; + unsigned int h_width, h_height, width, height; + int tmp_x, tmp_y; ZnSizeOfImage(cv->marker, &width, &height); h_width = (width+1)/2; h_height = (height+1)/2; values.fill_style = FillStippled; - values.stipple = ZnImagePixmap(cv->marker, NULL); - values.foreground = ZnPixel(ZnGetGradientColor(cv->marker_color, 0, NULL)); + values.stipple = ZnImagePixmap(cv->marker); + values.foreground = ZnPixel(ZnGetGradientColor(cv->marker_color, 0.0, NULL)); XChangeGC(wi->dpy, wi->gc, GCFillStyle|GCStipple|GCForeground, &values); for (j = 0; j < cv->outlines.num_contours; j++) { num_points = cv->outlines.contours[j].num_points; @@ -1375,8 +1378,8 @@ Draw(Item item) ZnListAssertSize(wi->work_xpts, num_points); xpoints = (XPoint *) 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 = (short) ZnNearestInt(points[i].x); + xpoints[i].y = (short) ZnNearestInt(points[i].y); } if (ISSET(cv->flags, FIRST_END_OK)) { num_points--; @@ -1386,14 +1389,14 @@ Draw(Item item) num_points--; } for (; num_points > 0; num_points--, points++) { - ptmp.x = points->x - h_width; - ptmp.y = points->y - h_height; - values.ts_x_origin = ptmp.x; - values.ts_y_origin = ptmp.y; + tmp_x = ((int) points->x) - h_width; + tmp_y = ((int) points->y) - h_height; + values.ts_x_origin = tmp_x; + values.ts_y_origin = tmp_y; XChangeGC(wi->dpy, wi->gc, GCTileStipXOrigin|GCTileStipYOrigin|GCForeground, &values); - XFillRectangle(wi->dpy, wi->draw_buffer, wi->gc, ptmp.x, ptmp.y, - width, height); + XFillRectangle(wi->dpy, wi->draw_buffer, wi->gc, + tmp_x, tmp_y, width, height); } } } @@ -1407,12 +1410,12 @@ Draw(Item item) * ********************************************************************************** */ -#ifdef GLX +#ifdef GL static void CurveRenderCB(void *closure) { CurveItem cv = (CurveItem) closure; - int i, j, num_points; + unsigned int i, j, num_points; ZnPoint *points; for (i = 0; i < cv->tristrip.num_strips; i++) { @@ -1425,22 +1428,23 @@ CurveRenderCB(void *closure) glBegin(GL_TRIANGLE_STRIP); } for (j = 0; j < num_points; j++, points++) { - glVertex2f(points->x, points->y); + glVertex2d(points->x, points->y); } glEnd(); } } #endif + +#ifdef GL static void -Render(Item item) +Render(ZnItem item) { -#ifdef GLX - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; CurveItem cv = (CurveItem) item; - int j, num_points; + unsigned int j, num_points; ZnPoint *points; XColor *color; - int alpha; + unsigned short alpha; if ((cv->outlines.num_contours == 0) || (ISCLEAR(cv->flags, FILLED_OK) && @@ -1473,7 +1477,7 @@ Render(Item item) * Setup polygon stippling. */ glEnable(GL_POLYGON_STIPPLE); - glPolygonStipple(ZnImagePattern(cv->fill_pattern, NULL)); + glPolygonStipple(ZnImageMask(cv->fill_pattern, NULL)); } color = ZnGetGradientColor(cv->fill_color, 0.0, &alpha); alpha = ZnComposeAlpha(alpha, wi->alpha); @@ -1490,7 +1494,7 @@ Render(Item item) /* * Drawing with relief disables: ends, line style and line pattern. */ - ZnGetGradientColor(cv->line_color, 0, &alpha); + ZnGetGradientColor(cv->line_color, 0.0, &alpha); alpha = ZnComposeAlpha(alpha, wi->alpha); if (ISSET(cv->flags, RELIEF_OK)) { for (j = 0; j < cv->outlines.num_contours; j++) { @@ -1524,12 +1528,13 @@ Render(Item item) * if last point join first point suppress markers at end points. */ if (ISSET(cv->flags, MARKER_OK)) { - int h_width, h_height; - ZnPoint ptmp; + int i_width, i_height; + ZnReal r_width, r_height; + ZnPoint ptmp; - ZnSizeOfImage(cv->marker, &h_width, & h_height); - h_width = (h_width+1.0)/2.0; - h_height = (h_height+1.0)/2.0; + ZnSizeOfImage(cv->marker, &i_width, &i_height); + r_width = (i_width+1.0)/2.0; + r_height = (i_height+1.0)/2.0; for (j = 0; j < cv->outlines.num_contours; j++) { num_points = cv->outlines.contours[j].num_points; points = cv->outlines.contours[j].points; @@ -1541,8 +1546,8 @@ Render(Item item) num_points--; } for (; num_points > 0; num_points--, points++) { - ptmp.x = points->x - h_width; - ptmp.y = points->y - h_height; + ptmp.x = points->x - r_width; + ptmp.y = points->y - r_height; ZnRenderIcon(wi, cv->marker, cv->marker_color, &ptmp, True); } } @@ -1553,8 +1558,13 @@ Render(Item item) glCallList(item->gl_list); #endif -#endif } +#else +static void +Render(ZnItem item __unused) +{ +} +#endif /* @@ -1565,10 +1575,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)); } @@ -1581,17 +1591,16 @@ IsSensitive(Item item, ********************************************************************************** */ static double -Pick(Item item, +Pick(ZnItem item, ZnPick ps) { CurveItem cv = (CurveItem) item; ZnBBox bbox; double dist=1.0e40, new_dist; ZnPoint *points, *p = ps->point; - ZnPoint end_points[LINE_END_POINTS]; - int num_points; + ZnPoint end_points[ZN_LINE_END_POINTS]; + unsigned int num_points, i; int width, height; - int i; if (cv->outlines.num_contours == 0) { return dist; @@ -1606,15 +1615,15 @@ Pick(Item item, */ for (i = 0; i < cv->outlines.num_contours; i++) { if (cv->outlines.contours[i].cw) { - new_hole_dist = PolygonToPointDist(cv->outlines.contours[i].points, - cv->outlines.contours[i].num_points, p); + new_hole_dist = ZnPolygonToPointDist(cv->outlines.contours[i].points, + cv->outlines.contours[i].num_points, p); if (new_hole_dist < hole_dist) { hole_dist = new_hole_dist; } } else { - new_dist = PolygonToPointDist(cv->outlines.contours[i].points, - cv->outlines.contours[i].num_points, p); + new_dist = ZnPolygonToPointDist(cv->outlines.contours[i].points, + cv->outlines.contours[i].num_points, p); if (new_dist < dist) { dist = new_dist; } @@ -1643,8 +1652,8 @@ Pick(Item item, points = cv->outlines.contours[i].points; num_points = cv->outlines.contours[i].num_points; if (ISCLEAR(cv->flags, RELIEF_OK)) { - new_dist = PolylineToPointDist(points, num_points, - cv->line_width, cv->cap_style, cv->join_style, p); + new_dist = ZnPolylineToPointDist(points, num_points, + cv->line_width, cv->cap_style, cv->join_style, p); if (new_dist < dist) { dist = new_dist; } @@ -1675,9 +1684,9 @@ Pick(Item item, * Check line ends. */ if (ISSET(cv->flags, FIRST_END_OK)) { - GetLineEnd(&points[0], &points[1], cv->line_width, cv->cap_style, - cv->first_end, end_points); - new_dist = PolygonToPointDist(end_points, LINE_END_POINTS, p); + ZnGetLineEnd(&points[0], &points[1], cv->line_width, cv->cap_style, + cv->first_end, end_points); + new_dist = ZnPolygonToPointDist(end_points, ZN_LINE_END_POINTS, p); if (new_dist < dist) { dist = new_dist; } @@ -1687,9 +1696,9 @@ Pick(Item item, } } if (ISSET(cv->flags, LAST_END_OK)) { - GetLineEnd(&points[num_points-1], &points[num_points-2], cv->line_width, - cv->cap_style, cv->last_end, end_points); - new_dist = PolygonToPointDist(end_points, LINE_END_POINTS, p); + ZnGetLineEnd(&points[num_points-1], &points[num_points-2], cv->line_width, + cv->cap_style, cv->last_end, end_points); + new_dist = ZnPolygonToPointDist(end_points, ZN_LINE_END_POINTS, p); if (new_dist < dist) { dist = new_dist; } @@ -1721,7 +1730,7 @@ Pick(Item item, bbox.orig.y = points->y - (height+1)/2; bbox.corner.x = bbox.orig.x + width; bbox.corner.y = bbox.orig.y + height; - new_dist = RectangleToPointDist(&bbox, p); + new_dist = ZnRectangleToPointDist(&bbox, p); if (new_dist < dist) { dist = new_dist; } @@ -1746,8 +1755,8 @@ Pick(Item item, ********************************************************************************** */ static void -PostScript(Item item, - PostScriptInfo ps_info) +PostScript(ZnItem item __unused, + ZnPostScriptInfo ps_info __unused) { } @@ -1757,12 +1766,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) { CurveItem cv = (CurveItem) item; @@ -1770,10 +1779,10 @@ GetClipVertices(Item item, tristrip->num_strips = 0; if (cv->tristrip.num_strips == 1) { - TRI_STRIP1(tristrip, - cv->tristrip.strips[0].points, - cv->tristrip.strips[0].num_points, - cv->tristrip.strips[0].fan); + ZnTriStrip1(tristrip, + cv->tristrip.strips[0].points, + cv->tristrip.strips[0].num_points, + cv->tristrip.strips[0].fan); } else if (cv->tristrip.num_strips > 1) { tristrip->num_strips = cv->tristrip.num_strips; @@ -1789,20 +1798,20 @@ 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) { CurveItem cv = (CurveItem) item; if (cv->outlines.num_contours == 1) { - POLY_CONTOUR1(poly, cv->outlines.contours[0].points, - cv->outlines.contours[0].num_points, - cv->outlines.contours[0].cw); + ZnPolyContour1(poly, cv->outlines.contours[0].points, + cv->outlines.contours[0].num_points, + cv->outlines.contours[0].cw); } else if (cv->outlines.num_contours > 1) { poly->num_contours = cv->outlines.num_contours; @@ -1822,16 +1831,17 @@ 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, + int index, + int cmd, + ZnPoint **pts, + char **controls, + unsigned int *num_pts) { CurveItem cv = (CurveItem) item; - int i, num_controls; + unsigned int j, num_controls; + int i; ZnContour *c=NULL; /*printf("contour %d, num_pts %d, index %d, cmd %d\n", @@ -1840,10 +1850,10 @@ Coords(Item item, if (contour < 0) { contour += cv->shape.num_contours; } - if ((contour < 0) || (contour >= cv->shape.num_contours)) { + if ((contour < 0) || ((unsigned int) contour >= cv->shape.num_contours)) { Tcl_AppendResult(item->wi->interp, " curve contour index out of range", NULL); - return ZN_ERROR; + return TCL_ERROR; } if (cv->shape.num_contours != 0) { c = &cv->shape.contours[contour]; @@ -1851,8 +1861,8 @@ Coords(Item item, /* REPLACE */ - 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) { /* * Replacing all the coordinates of a contour by no coordinates * is also legal, resulting in the contour being removed. @@ -1874,15 +1884,15 @@ Coords(Item item, if (*num_pts == 0) { Tcl_AppendResult(item->wi->interp, " coords replace command need at least 1 point on curves", NULL); - return ZN_ERROR; + return TCL_ERROR; } if (index < 0) { index += c->num_points; } - if ((index < 0) || (index >= c->num_points)) { + if ((index < 0) || ((unsigned int) index >= c->num_points)) { range_err: Tcl_AppendResult(item->wi->interp, " coord index out of range", NULL); - return ZN_ERROR; + return TCL_ERROR; } /*printf("--->%g@%g\n", (*pts)[0].x, (*pts)[0].y);*/ c->points[index] = (*pts)[0]; @@ -1905,37 +1915,37 @@ Coords(Item item, if (!index) { control_first: Tcl_AppendResult(item->wi->interp, " the first point must not be a control", NULL); - return ZN_ERROR; + return TCL_ERROR; } - else if (index == c->num_points-1) { + else if ((unsigned int) index == c->num_points-1) { if (ISCLEAR(cv->flags, CLOSED_BIT) && (cv->shape.num_contours == 1)) { control_last: Tcl_AppendResult(item->wi->interp, " the last point must not be a control", NULL); - return ZN_ERROR; + return TCL_ERROR; } } else { for (i = index-1; c->controls[i] && (i >= 0); i--, num_controls++); } - for (i = index+1; c->controls[i] && (i < c->num_points); i++, num_controls++); + for (j = index+1; c->controls[j] && (j < c->num_points); j++, num_controls++); if (num_controls > 1) { control_err: Tcl_AppendResult(item->wi->interp, " too many consecutive control points in a curve", NULL); - return ZN_ERROR; + return TCL_ERROR; } } c->controls[index] = (*controls)[0]; } } } - ITEM.Invalidate(item, ZN_COORDS_FLAG); + ZnITEM.Invalidate(item, ZN_COORDS_FLAG); } /* READ */ - else if ((cmd == COORDS_READ) || (cmd == COORDS_READ_ALL)) { - if (cmd == COORDS_READ_ALL) { + else if ((cmd == ZN_COORDS_READ) || (cmd == ZN_COORDS_READ_ALL)) { + if (cmd == ZN_COORDS_READ_ALL) { *num_pts = c->num_points; *pts = c->points; if (c->controls) { @@ -1946,7 +1956,7 @@ Coords(Item item, if (index < 0) { index += c->num_points; } - if ((index < 0) || (index >= c->num_points)) { + if ((index < 0) || ((unsigned int) index >= c->num_points)) { goto range_err; } *num_pts = 1; @@ -1959,17 +1969,17 @@ Coords(Item item, /* ADD */ - else if ((cmd == COORDS_ADD) || (cmd == COORDS_ADD_LAST)) { + else if ((cmd == ZN_COORDS_ADD) || (cmd == ZN_COORDS_ADD_LAST)) { if (*num_pts == 0) { - return ZN_OK; + return TCL_OK; } - if (cmd == COORDS_ADD_LAST) { + if (cmd == ZN_COORDS_ADD_LAST) { index = c->num_points; } if (index < 0) { index += c->num_points; } - if ((index < 0) || (index > c->num_points)) { + if ((index < 0) || ((unsigned int) index > c->num_points)) { goto range_err; } if (*controls) { @@ -1981,8 +1991,10 @@ Coords(Item item, if ((index == 0) && (*controls)[0]) { goto control_first; } - else if ((index == c->num_points-1) && (*controls)[*num_pts-1] && - ISCLEAR(cv->flags, CLOSED_BIT) && (cv->shape.num_contours == 1)) { + else if (((unsigned int) index == (c->num_points-1)) && + (*controls)[*num_pts-1] && + ISCLEAR(cv->flags, CLOSED_BIT) && + (cv->shape.num_contours == 1)) { goto control_last; } @@ -1993,8 +2005,8 @@ Coords(Item item, } } /*printf("******* num controls: %d\n", num_controls);*/ - for (i = 0; i < *num_pts; i++) { - if (!(*controls)[i]) { + for (j = 0; j < *num_pts; j++) { + if (!(*controls)[j]) { num_controls = 0; } else { @@ -2006,7 +2018,7 @@ Coords(Item item, } /*printf("******* num controls(2): %d\n", num_controls);*/ if (c->controls) { - for (i = index; c->controls[i] && (i < c->num_points); i++, num_controls++); + for (j = index; c->controls[j] && (j < c->num_points); j++, num_controls++); } /*printf("******* num controls(3): %d\n", num_controls);*/ if (num_controls > 2) { @@ -2032,23 +2044,23 @@ Coords(Item item, c->controls[i+*num_pts] = c->controls[i]; } } - for (i = 0; i < *num_pts; i++, index++) { - c->points[index] = (*pts)[i]; + for (j = 0; j < *num_pts; j++, index++) { + c->points[index] = (*pts)[j]; if (c->controls) { - c->controls[index] = (*controls)?(*controls)[i]:0; + c->controls[index] = (*controls)?(*controls)[j]:0; } } c->num_points += *num_pts; - ITEM.Invalidate(item, ZN_COORDS_FLAG); + ZnITEM.Invalidate(item, ZN_COORDS_FLAG); } /* REMOVE */ - else if (cmd == COORDS_REMOVE) { + else if (cmd == ZN_COORDS_REMOVE) { if (index < 0) { index += c->num_points; } - if ((index < 0) || (index >= c->num_points)) { + if ((index < 0) || ((unsigned int) index >= c->num_points)) { goto range_err; } @@ -2064,11 +2076,11 @@ Coords(Item item, } c->num_points--; - if ((c->num_points != 0) && (index != c->num_points)) { - for (i = index; i < c->num_points; i++) { - c->points[i] = c->points[i+1]; + if ((c->num_points != 0) && ((unsigned int) index != c->num_points)) { + for (j = index; j < c->num_points; j++) { + c->points[j] = c->points[j+1]; if (c->controls) { - c->controls[i] = c->controls[i+1]; + c->controls[j] = c->controls[j+1]; } } } @@ -2076,10 +2088,10 @@ Coords(Item item, if (c->controls) { c->controls = ZnRealloc(c->controls, (c->num_points)*sizeof(char)); } - ITEM.Invalidate(item, ZN_COORDS_FLAG); + ZnITEM.Invalidate(item, ZN_COORDS_FLAG); } - return ZN_OK; + return TCL_OK; } @@ -2092,26 +2104,27 @@ Coords(Item item, ********************************************************************************** */ static int -Contour(Item item, +Contour(ZnItem item, int cmd, int index, ZnPoly *poly) { CurveItem cv = (CurveItem) item; - int i, num_contours; + unsigned int j, num_contours; + int i; switch (cmd) { case ZN_CONTOUR_ADD: if (index < 0) { index += cv->shape.num_contours; } - if (index > cv->shape.num_contours) { + if ((unsigned int) index > cv->shape.num_contours) { index = cv->shape.num_contours; } if (index < 0) { contour_err: Tcl_AppendResult(item->wi->interp, " contour index out of range", NULL); - return ZN_ERROR; + return TCL_ERROR; } num_contours = cv->shape.num_contours + poly->num_contours; if (cv->shape.contours == &cv->shape.contour1) { @@ -2132,31 +2145,31 @@ Contour(Item item, for (i = cv->shape.num_contours-1; i >= index; i--) { cv->shape.contours[i+poly->num_contours] = cv->shape.contours[i]; } - for (i = 0; i < poly->num_contours; i++, index++) { - cv->shape.contours[index].num_points = poly->contours[i].num_points; - cv->shape.contours[index].cw = poly->contours[i].cw; - cv->shape.contours[index].points = ZnMalloc(poly->contours[i].num_points * sizeof(ZnPoint)); - memcpy(cv->shape.contours[index].points, poly->contours[i].points, - poly->contours[i].num_points * sizeof(ZnPoint)); + 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].controls = NULL; - if (poly->contours[i].controls) { + 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[i].num_points * sizeof(char)); - memcpy(cv->shape.contours[index].controls, poly->contours[i].controls, - poly->contours[i].num_points * sizeof(char)); + 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.num_contours = num_contours; - ITEM.Invalidate(item, ZN_COORDS_FLAG); + ZnITEM.Invalidate(item, ZN_COORDS_FLAG); break; case ZN_CONTOUR_REMOVE: if (index < 0) { index += cv->shape.num_contours; } - if (index >= cv->shape.num_contours) { + if ((unsigned int) index >= cv->shape.num_contours) { index = cv->shape.num_contours - 1; } if (index < 0) { @@ -2164,18 +2177,18 @@ Contour(Item item, } cv->shape.num_contours--; if (cv->shape.num_contours == 0) { - POLY_FREE(&cv->shape); + ZnPolyFree(&cv->shape); } else { ZnFree(cv->shape.contours[index].points); if (cv->shape.contours[index].controls) { ZnFree(cv->shape.contours[index].controls); } - for (i = index; i < cv->shape.num_contours; i++) { - cv->shape.contours[i] = cv->shape.contours[i+1]; + for (j = index; j < cv->shape.num_contours; j++) { + cv->shape.contours[j] = cv->shape.contours[j+1]; } } - ITEM.Invalidate(item, ZN_COORDS_FLAG); + ZnITEM.Invalidate(item, ZN_COORDS_FLAG); break; } @@ -2194,14 +2207,14 @@ Contour(Item item, ********************************************************************************** */ static void -PickVertex(Item item, +PickVertex(ZnItem item, ZnPoint *p, int *contour, int *vertex, int *o_vertex) { CurveItem cv = (CurveItem) item; - int i, j, k, num_points; + unsigned int i, j, k, num_points; ZnPoint *points, po; ZnReal dist=1.0e40, new_dist, dist2; ZnTransfo t, inv; @@ -2215,7 +2228,7 @@ PickVertex(Item item, /* * Get the point in the item coordinate space. */ - ITEM.GetItemTransform(item, &t); + ZnITEM.GetItemTransform(item, &t); ZnTransfoInvert(&t, &inv); ZnTransformPoint(&inv, p, &po); @@ -2237,11 +2250,11 @@ PickVertex(Item item, * If the closest vertex is in the current contour update * the opposite vertex. */ - if (i == *contour) { + if (i == (unsigned int) *contour) { j = (*vertex+1) % num_points; - new_dist = LineToPointDist(&points[*vertex], &points[j], &po); - k = ((unsigned)(*vertex-1)) % num_points; - dist2 = LineToPointDist(&points[*vertex], &points[k], &po); + new_dist = ZnLineToPointDist(&points[*vertex], &points[j], &po); + k = ((unsigned int)(*vertex-1)) % num_points; + dist2 = ZnLineToPointDist(&points[*vertex], &points[k], &po); if (dist2 < new_dist) { *o_vertex = k; } @@ -2261,16 +2274,16 @@ PickVertex(Item item, ********************************************************************************** */ static void -GetAnchor(Item item, - ZnAnchor anchor, +GetAnchor(ZnItem item, + Tk_Anchor anchor, ZnPoint *p) { ZnBBox *bbox = &item->item_bounding_box; - Origin2Anchor(&bbox->orig, - bbox->corner.x - bbox->orig.x, - bbox->corner.y - bbox->orig.y, - anchor, p); + ZnOrigin2Anchor(&bbox->orig, + bbox->corner.x - bbox->orig.x, + bbox->corner.y - bbox->orig.y, + anchor, p); } @@ -2281,7 +2294,7 @@ GetAnchor(Item item, * ********************************************************************************** */ -static ItemClassStruct CURVE_ITEM_CLASS = { +static ZnItemClassStruct CURVE_ITEM_CLASS = { sizeof(CurveItemStruct), 0, /* num_parts */ False, /* has_anchors */ diff --git a/generic/Draw.c b/generic/Draw.c index f033e49..29552ea 100644 --- a/generic/Draw.c +++ b/generic/Draw.c @@ -36,7 +36,6 @@ ********************************************************************************** */ -#include "config.h" #include "Types.h" #include "Draw.h" #include "Geo.h" @@ -66,6 +65,11 @@ #define LIGHTNING_SHAPE_A_RATIO 10.0 #define LIGHTNING_SHAPE_B_RATIO 8.0 +#define LIGHTNING_POINTS 4 +#define CORNER_POINTS 3 +#define DOUBLE_CORNER_POINTS 4 +#define STRAIGHT_POINTS 2 + /* ********************************************************************************** @@ -75,21 +79,21 @@ ********************************************************************************** */ void -ZnSetLineStyle(WidgetInfo *wi, - LineStyle line_style) +ZnSetLineStyle(ZnWInfo *wi, + ZnLineStyle line_style) { if (wi->render) { -#ifdef GLX +#ifdef GL switch (line_style) { - case LINE_DASHED : + case ZN_LINE_DASHED : glLineStipple(1, 0xF0F0); glEnable(GL_LINE_STIPPLE); break; - case LINE_MIXED : + case ZN_LINE_MIXED : glLineStipple(1, 0x27FF); glEnable(GL_LINE_STIPPLE); break; - case LINE_DOTTED : + case ZN_LINE_DOTTED : glLineStipple(1, 0x18C3); glEnable(GL_LINE_STIPPLE); break; @@ -106,13 +110,13 @@ ZnSetLineStyle(WidgetInfo *wi, values.line_style = LineOnOffDash; switch (line_style) { - case LINE_DASHED : + case ZN_LINE_DASHED : XSetDashes(wi->dpy, wi->gc, 0, dashed, 1); break; - case LINE_MIXED : + case ZN_LINE_MIXED : XSetDashes(wi->dpy, wi->gc, 0, mixed, 4); break; - case LINE_DOTTED : + case ZN_LINE_DOTTED : XSetDashes(wi->dpy, wi->gc, 0, dotted, 2); break; default: @@ -127,7 +131,7 @@ ZnSetLineStyle(WidgetInfo *wi, /* ********************************************************************************** * - * ZnGetLineShape -- + * ZnLineShapePoints -- * Compute the points describing the given line shape between point p1 and p2. * If bbox is non null, it is filled with the bounding box of the shape. * @@ -162,21 +166,21 @@ ZnSetLineStyle(WidgetInfo *wi, ********************************************************************************** */ void -ZnGetLineShape(ZnPoint *p1, - ZnPoint *p2, - unsigned int line_width, - LineShape shape, - ZnBBox *bbox, - ZnList to_points) +ZnLineShapePoints(ZnPoint *p1, + ZnPoint *p2, + ZnDim line_width, + ZnLineShape shape, + ZnBBox *bbox, + ZnList to_points) { ZnPoint *points; - int num_points, i; + unsigned int num_points, i; /* * Compute all line points according to shape. */ - if ((shape == LINE_LEFT_LIGHTNING) || - (shape == LINE_RIGHT_LIGHTNING)) { + if ((shape == ZN_LINE_LEFT_LIGHTNING) || + (shape == ZN_LINE_RIGHT_LIGHTNING)) { double alpha, theta; double length, length2; double shape_a, shape_b; @@ -193,10 +197,10 @@ ZnGetLineShape(ZnPoint *p1, dx = p2->x - p1->x; dy = p2->y - p1->y; length = hypot(dx, dy); - shape_a = length/LIGHTNING_SHAPE_A_RATIO + ((double) line_width)/2; - shape_b = length/LIGHTNING_SHAPE_B_RATIO + ((double) line_width)/2; + shape_a = length/LIGHTNING_SHAPE_A_RATIO + line_width/2.0; + shape_b = length/LIGHTNING_SHAPE_B_RATIO + line_width/2.0; - if (shape == LINE_LEFT_LIGHTNING) + if (shape == ZN_LINE_LEFT_LIGHTNING) alpha = atan2(shape_a, shape_b); else alpha = -atan2(shape_a, shape_b); @@ -212,8 +216,8 @@ ZnGetLineShape(ZnPoint *p1, points[1].y = dy - temp; points[2].y = dy + temp; } - else if (shape == LINE_LEFT_CORNER || - shape == LINE_RIGHT_CORNER) { + else if (shape == ZN_LINE_LEFT_CORNER || + shape == ZN_LINE_RIGHT_CORNER) { num_points = CORNER_POINTS; ZnListAssertSize(to_points, num_points); points = (ZnPoint *) ZnListArray(to_points); @@ -221,7 +225,7 @@ ZnGetLineShape(ZnPoint *p1, points[0] = *p1; points[2] = *p2; - if (shape == LINE_LEFT_CORNER) { + if (shape == ZN_LINE_LEFT_CORNER) { points[1].x = p1->x; points[1].y = p2->y; } @@ -230,8 +234,8 @@ ZnGetLineShape(ZnPoint *p1, points[1].y = p1->y; } } - else if (shape == LINE_DOUBLE_LEFT_CORNER || - shape == LINE_DOUBLE_RIGHT_CORNER) { + else if (shape == ZN_LINE_DOUBLE_LEFT_CORNER || + shape == ZN_LINE_DOUBLE_RIGHT_CORNER) { int dx, dy; num_points = DOUBLE_CORNER_POINTS; @@ -241,20 +245,20 @@ ZnGetLineShape(ZnPoint *p1, points[0] = *p1; points[3] = *p2; - if (shape == LINE_DOUBLE_LEFT_CORNER) { - dy = p2->y - p1->y; + if (shape == ZN_LINE_DOUBLE_LEFT_CORNER) { + dy = (int) (p2->y - p1->y); points[1].x = p1->x; points[2].x = p2->x; points[1].y = points[2].y = p1->y + dy/2; } else { - dx = p2->x - p1->x; + dx = (int) (p2->x - p1->x); points[1].x = points[2].x = p1->x + dx/2; points[1].y = p1->y; points[2].y = p2->y; } } - else /* if (shape) == LINE_STRAIGHT) */ { + else /* if (shape) == ZN_LINE_STRAIGHT) */ { num_points = STRAIGHT_POINTS; ZnListAssertSize(to_points, num_points); points = (ZnPoint *) ZnListArray(to_points); @@ -267,14 +271,14 @@ ZnGetLineShape(ZnPoint *p1, * Fill in the bbox, if requested. */ if (bbox) { - ResetBBox(bbox); + ZnResetBBox(bbox); for (i = 0; i < num_points; i++) { - AddPointToBBox(bbox, points[i].x, points[i].y); + ZnAddPointToBBox(bbox, points[i].x, points[i].y); } /* Enlarge to take line_width into account. */ if (line_width > 1) { - int lw_2 = (line_width+1)/2; + ZnDim lw_2 = (line_width+1)/2; bbox->orig.x -= lw_2; bbox->orig.y -= lw_2; @@ -298,16 +302,16 @@ ZnGetLineShape(ZnPoint *p1, ********************************************************************************** */ void -ZnDrawLineShape(WidgetInfo *wi, +ZnDrawLineShape(ZnWInfo *wi, ZnPoint *p, - int num_p, - LineStyle line_style, - ZnColor foreground, - unsigned int line_width, - LineShape shape) + unsigned int num_p, + ZnLineStyle line_style, + XColor *foreground, + ZnDim line_width, + ZnLineShape shape __unused) { XPoint *xpoints; - int i; + unsigned int i; XGCValues values; /* @@ -315,7 +319,7 @@ ZnDrawLineShape(WidgetInfo *wi, */ ZnSetLineStyle(wi, line_style); values.foreground = ZnPixel(foreground); - values.line_width = (line_width == 1) ? 0 : line_width; + values.line_width = (line_width == 1) ? 0 : (int) line_width; values.fill_style = FillSolid; values.join_style = JoinRound; values.cap_style = CapRound; @@ -324,10 +328,94 @@ ZnDrawLineShape(WidgetInfo *wi, ZnListAssertSize(wi->work_xpts, num_p); xpoints = (XPoint *) ZnListArray(wi->work_xpts); for (i = 0; i < num_p; i++) { - xpoints[i].x = p[i].x; - xpoints[i].y = p[i].y; + xpoints[i].x = (short) p[i].x; + xpoints[i].y = (short) p[i].y; + } + XDrawLines(wi->dpy, wi->draw_buffer, wi->gc, xpoints, (int) num_p, CoordModeOrigin); +} + + +/* + ********************************************************************************** + * + * ZnGetLineEnd -- + * Compute the points describing the given line end style at point p1 for + * the line p1,p2. Point p1 is adjusted to fit the line end. + * If bbox is non null, it is filled with the bounding box of the end. + * + * For the time being this procedure handles open/filled arrows. + * + * Here are the parameters describing arrows. + * + * * | ARROW_SHAPE_C + * ** | + * * *************************** + * * * + * * * +p1 +p2 + * | * |* + * | * *************************** + * | | ** + * | | * + * | | | + * |---| | ARROW_SHAPE_A + * | | + * |-------| ARROW_SHAPE_B + * + ********************************************************************************** + */ +void +ZnGetLineEnd(ZnPoint *p1, + ZnPoint *p2, + ZnDim line_width, + int cap_style, + ZnLineEnd end_style, + ZnPoint *points) +{ + ZnReal dx, dy, length, temp, backup; + ZnReal frac_height, sin_theta, cos_theta; + ZnReal vert_x, vert_y; + ZnReal shape_a, shape_b, shape_c; + + if (end_style != NULL) { + shape_a = end_style->shape_a + 0.001; + shape_b = end_style->shape_b + 0.001; + shape_c = end_style->shape_c + line_width/2.0 + 0.001; + + frac_height = (line_width/2.0) / shape_c; + dx = p1->x - p2->x; + dy = p1->y - p2->y; + length = hypot(dx, dy); + if (length == 0) { + sin_theta = cos_theta = 0.0; + } + else { + sin_theta = dy/length; + cos_theta = dx/length; + } + + if (cap_style != CapProjecting) { + temp = frac_height; + } + else { + temp = line_width / shape_c; + } + backup = temp * shape_b + shape_a * (1.0 - temp) / 2.0; + points[0].x = points[5].x = p1->x + backup * cos_theta; + points[0].y = points[5].y = p1->y + backup * sin_theta; + + vert_x = points[0].x - shape_a*cos_theta; + vert_y = points[0].y - shape_a*sin_theta; + temp = shape_c*sin_theta; + points[1].x = ZnNearestInt(points[0].x - shape_b*cos_theta + temp); + points[4].x = ZnNearestInt(points[1].x - 2*temp); + temp = shape_c*cos_theta; + points[1].y = ZnNearestInt(points[0].y - shape_b*sin_theta - temp); + points[4].y = ZnNearestInt(points[1].y + 2*temp); + points[2].x = ZnNearestInt(points[1].x*frac_height + vert_x*(1.0-frac_height)); + points[2].y = ZnNearestInt(points[1].y*frac_height + vert_y*(1.0-frac_height)); + points[3].x = ZnNearestInt(points[4].x*frac_height + vert_x*(1.0-frac_height)); + points[3].y = ZnNearestInt(points[4].y*frac_height + vert_y*(1.0-frac_height)); } - XDrawLines(wi->dpy, wi->draw_buffer, wi->gc, xpoints, num_p, CoordModeOrigin); } @@ -339,21 +427,21 @@ ReliefColorOfSegment(ZnReal x1, ZnReal y1, ZnReal x2, ZnReal y2, - ReliefStyle relief, + ZnReliefStyle relief, ZnGradient *gradient, - WidgetInfo *wi) + ZnWInfo *wi) { ZnReal angle, angle_step, origin, position; int num_colors, color_index; - num_colors = RELIEF_STEPS*2+1; + num_colors = ZN_RELIEF_STEPS*2+1; angle_step = M_PI / (num_colors-1); - origin = -(DegreesToRadian(wi->light_angle))-(angle_step/2.0); - if (relief == RELIEF_SUNKEN) { + origin = -(ZnDegRad(wi->light_angle))-(angle_step/2.0); + if (relief == ZN_RELIEF_SUNKEN) { origin += M_PI; } - angle = ProjectionToAngle(y1 - y2, x2 - x1) + M_PI - origin; + angle = ZnProjectionToAngle(y1 - y2, x2 - x1) + M_PI - origin; while (angle < 0.0) { angle += 2*M_PI; } @@ -394,11 +482,11 @@ ReliefColorOfSegment(ZnReal x1, ********************************************************************************** */ void -ZnDrawRectangleRelief(WidgetInfo *wi, - ReliefStyle relief, +ZnDrawRectangleRelief(ZnWInfo *wi, + ZnReliefStyle relief, ZnGradient *gradient, XRectangle *bbox, - unsigned int line_width) + ZnDim line_width) { XPoint bevel[4]; @@ -413,23 +501,23 @@ ZnDrawRectangleRelief(WidgetInfo *wi, * Grooves and ridges are drawn with two recursives calls with * half the width of the original one. */ - if ((relief == RELIEF_RIDGE) || (relief == RELIEF_GROOVE)) { - unsigned int new_line_width; - int offset; - XRectangle internal_bbox; + if ((relief == ZN_RELIEF_RIDGE) || (relief == ZN_RELIEF_GROOVE)) { + ZnDim new_line_width; + unsigned int offset; + XRectangle internal_bbox; - new_line_width = line_width/2; - offset = line_width - new_line_width; + new_line_width = line_width/2.0; + offset = (unsigned) (line_width - new_line_width); ZnDrawRectangleRelief(wi, - (relief==RELIEF_GROOVE)?RELIEF_SUNKEN:RELIEF_RAISED, + (unsigned) ((relief==ZN_RELIEF_GROOVE)?ZN_RELIEF_SUNKEN:ZN_RELIEF_RAISED), gradient, bbox, new_line_width); internal_bbox = *bbox; - internal_bbox.x +=offset; + internal_bbox.x += offset; internal_bbox.y += offset; internal_bbox.width -= offset*2; internal_bbox.height -= offset*2; ZnDrawRectangleRelief(wi, - (relief==RELIEF_GROOVE)?RELIEF_RAISED:RELIEF_SUNKEN, + (unsigned) ((relief==ZN_RELIEF_GROOVE)?ZN_RELIEF_RAISED:ZN_RELIEF_SUNKEN), gradient, &internal_bbox, new_line_width); return; } @@ -439,29 +527,32 @@ ZnDrawRectangleRelief(WidgetInfo *wi, bevel[0].x = bbox->x; bevel[0].y = bevel[1].y = bbox->y; bevel[1].x = bbox->x + bbox->width; - bevel[2].y = bevel[3].y = bbox->y + line_width; - bevel[2].x = bevel[1].x - line_width; - bevel[3].x = bevel[0].x + line_width; + bevel[2].y = bevel[3].y = bbox->y + (short) line_width; + bevel[2].x = bevel[1].x - (short) line_width; + bevel[3].x = bevel[0].x + (short) line_width; XSetForeground(wi->dpy, wi->gc, - ZnPixel(ReliefColorOfSegment(bevel[1].x, bevel[1].y, bevel[0].x, bevel[0].y, + ZnPixel(ReliefColorOfSegment((ZnReal) bevel[1].x, (ZnReal) bevel[1].y, + (ZnReal) bevel[0].x, (ZnReal) bevel[0].y, relief, gradient, wi))); XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc, bevel, 4, Convex, CoordModeOrigin); bevel[0] = bevel[1]; bevel[3] = bevel[2]; bevel[1].y += bbox->height; - bevel[2].y = bevel[1].y - line_width; + bevel[2].y = bevel[1].y - (short) line_width; XSetForeground(wi->dpy, wi->gc, - ZnPixel(ReliefColorOfSegment(bevel[1].x, bevel[1].y, bevel[0].x, bevel[0].y, + ZnPixel(ReliefColorOfSegment((ZnReal) bevel[1].x, (ZnReal) bevel[1].y, + (ZnReal) bevel[0].x, (ZnReal) bevel[0].y, relief, gradient, wi))); XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc, bevel, 4, Convex, CoordModeOrigin); bevel[0] = bevel[1]; bevel[3] = bevel[2]; bevel[1].x -= bbox->width; - bevel[2].x = bevel[1].x + line_width; + bevel[2].x = bevel[1].x + (short) line_width; XSetForeground(wi->dpy, wi->gc, - ZnPixel(ReliefColorOfSegment(bevel[1].x, bevel[1].y, bevel[0].x, bevel[0].y, + ZnPixel(ReliefColorOfSegment((ZnReal) bevel[1].x, (ZnReal) bevel[1].y, + (ZnReal) bevel[0].x, (ZnReal) bevel[0].y, relief, gradient, wi))); XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc, bevel, 4, Convex, CoordModeOrigin); @@ -470,24 +561,25 @@ ZnDrawRectangleRelief(WidgetInfo *wi, bevel[1].x = bbox->x; bevel[1].y = bbox->y; bevel[2].x = bevel[3].x; - bevel[2].y = bbox->y + line_width; + bevel[2].y = bbox->y + (short) line_width; XSetForeground(wi->dpy, wi->gc, - ZnPixel(ReliefColorOfSegment(bevel[1].x, bevel[1].y, bevel[0].x, bevel[0].y, + ZnPixel(ReliefColorOfSegment((ZnReal) bevel[1].x, (ZnReal) bevel[1].y, + (ZnReal) bevel[0].x, (ZnReal) bevel[0].y, relief, gradient, wi))); XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc, bevel, 4, Convex, CoordModeOrigin); } typedef struct { - WidgetInfo *wi; + ZnWInfo *wi; ZnPoint *pp; ZnPoint *p0; ZnPoint *p1; double dist; ZnBBox *bbox; - ReliefStyle relief; + ZnReliefStyle relief; ZnGradient *gradient; - int alpha; + unsigned short alpha; ZnBool smooth; int result; int count; @@ -496,18 +588,23 @@ typedef struct { static void DoPolygon(ZnPoint *p, - int num_points, - int line_width, + unsigned int num_points, + ZnDim line_width, ZnBool (*cb)(ZnPoint *bevels, PolygonData *pd), PolygonData *pd) { - int i, processed_points; - ZnPoint *p1, *p11=NULL, *p2; - ZnPoint pp1, pp2, new_pp1, new_pp2; - ZnPoint perp, c, shift1, shift2; - ZnPoint bevel_points[4]; - ZnBool folded, closed, colinear; - ZnReal dx, dy; + int i; + unsigned int processed_points; + ZnPoint *p1, *p11=NULL, *p2; + ZnPoint pp1, pp2, new_pp1, new_pp2; + ZnPoint perp, c, shift1, shift2; + ZnPoint bevel_points[4]; + ZnBool folded, closed, colinear; + ZnReal dx, dy; + + if (num_points < 2) { + return; + } /* * If the polygon is closed (last point is the same as first) open it by @@ -583,11 +680,11 @@ DoPolygon(ZnPoint *p, p1 = &p[num_points-2]; } - for (p2 = p1+1; i < num_points; i++, p2++) { + for (p2 = p1+1; i < (int) num_points; i++, p2++) { /* * When it is time to wrap, do it */ - if ((i == -1) || (i == num_points-1)) { + if ((i == -1) || (i == (int) num_points-1)) { p2 = p; } /* @@ -599,7 +696,7 @@ DoPolygon(ZnPoint *p, continue; } - ShiftLine(p1, p2, line_width, &new_pp1, &new_pp2); + ZnShiftLine(p1, p2, line_width, &new_pp1, &new_pp2); bevel_points[3] = *p1; folded = False; colinear = False; @@ -610,12 +707,12 @@ DoPolygon(ZnPoint *p, if ((processed_points == 0) && !closed) { perp.x = p1->x + (p2->y - p1->y); perp.y = p1->y - (p2->x - p1->x); - IntersectLines(p1, &perp, &new_pp1, &new_pp2, &bevel_points[2]); + ZnIntersectLines(p1, &perp, &new_pp1, &new_pp2, &bevel_points[2]); } else if ((processed_points == num_points-1) && !closed) { perp.x = p1->x + (p11->y - p1->y); perp.y = p1->y - (p11->x - p1->x); - IntersectLines(p1, &perp, &pp1, &pp2, &bevel_points[2]); + ZnIntersectLines(p1, &perp, &pp1, &pp2, &bevel_points[2]); } else if (processed_points >= 1) { ZnReal dotp, dist, odx, ody; @@ -627,15 +724,15 @@ DoPolygon(ZnPoint *p, odx = p11->x - p1->x; ody = p11->y - p1->y; dotp = odx*dx + ody*dy; - dist = LineToPointDist(p11, p2, p1); + dist = ZnLineToPointDist(p11, p2, p1); if ((dist < 4.0) && (dotp <= 0)) { perp.x = p1->x + (p2->y - p1->y); perp.y = p1->y - (p2->x - p1->x); - IntersectLines(p1, &perp, &new_pp1, &new_pp2, &bevel_points[2]); + ZnIntersectLines(p1, &perp, &new_pp1, &new_pp2, &bevel_points[2]); colinear = True; } else { - folded = !IntersectLines(&new_pp1, &new_pp2, &pp1, &pp2, &bevel_points[2]); + folded = !ZnIntersectLines(&new_pp1, &new_pp2, &pp1, &pp2, &bevel_points[2]); /*printf("new_pp1 %g@%g, new_pp2 %g@%g, pp1 %g@%g, pp2 %g@%g, inter %g@%g\n", new_pp1.x, new_pp1.y, new_pp2.x, new_pp2.y, pp1.x, pp1.y, pp2.x, pp2.y, @@ -647,10 +744,10 @@ DoPolygon(ZnPoint *p, new_pp2.x, new_pp2.y);*/ perp.x = p1->x + (p2->y - p1->y); perp.y = p1->y - (p2->x - p1->x); - IntersectLines(p1, &perp, &pp1, &pp2, &bevel_points[2]); - IntersectLines(p1, &perp, &new_pp1, &new_pp2, &c); - ShiftLine(p1, &perp, line_width, &shift1, &shift2); - IntersectLines(p1, p2, &shift1, &shift2, &bevel_points[3]); + ZnIntersectLines(p1, &perp, &pp1, &pp2, &bevel_points[2]); + ZnIntersectLines(p1, &perp, &new_pp1, &new_pp2, &c); + ZnShiftLine(p1, &perp, line_width, &shift1, &shift2); + ZnIntersectLines(p1, p2, &shift1, &shift2, &bevel_points[3]); } } } @@ -700,21 +797,21 @@ PolygonBBoxCB(ZnPoint *bevels, int i; for (i = 0; i < 4; i++) { - AddPointToBBox(pd->bbox, bevels[i].x, bevels[i].y); + ZnAddPointToBBox(pd->bbox, bevels[i].x, bevels[i].y); } return 0; } void -ZnGetPolygonReliefBBox(ZnPoint *points, - int num_points, - int line_width, - ZnBBox *bbox) +ZnGetPolygonReliefBBox(ZnPoint *points, + unsigned int num_points, + ZnDim line_width, + ZnBBox *bbox) { PolygonData pd; pd.bbox = bbox; - ResetBBox(bbox); + ZnResetBBox(bbox); DoPolygon(points, num_points, line_width, PolygonBBoxCB, &pd); } @@ -734,13 +831,13 @@ PolygonInBBoxCB(ZnPoint *bevels, { if (pd->count == 0) { pd->count++; - pd->result = PolygonInBBox(bevels, 4, pd->bbox, NULL); + pd->result = ZnPolygonInBBox(bevels, 4, pd->bbox, NULL); if (pd->result == 0) { return 1; } } else { - if (PolygonInBBox(bevels, 4, pd->bbox, NULL) != pd->result) { + if (ZnPolygonInBBox(bevels, 4, pd->bbox, NULL) != pd->result) { pd->result = 0; return 1; } @@ -749,10 +846,10 @@ PolygonInBBoxCB(ZnPoint *bevels, } int -ZnPolygonReliefInBBox(ZnPoint *points, - int num_points, - int line_width, - ZnBBox *area) +ZnPolygonReliefInBBox(ZnPoint *points, + unsigned int num_points, + ZnDim line_width, + ZnBBox *area) { PolygonData pd; @@ -780,7 +877,7 @@ PolygonDistCB(ZnPoint *bevels, { double new_dist; - new_dist = PolygonToPointDist(bevels, 4, pd->pp); + new_dist = ZnPolygonToPointDist(bevels, 4, pd->pp); if (new_dist < 0.0) { new_dist = 0.0; } @@ -792,8 +889,8 @@ PolygonDistCB(ZnPoint *bevels, double ZnPolygonReliefToPointDist(ZnPoint *points, - int num_points, - int line_width, + unsigned int num_points, + ZnDim line_width, ZnPoint *pp) { PolygonData pd; @@ -818,7 +915,7 @@ static ZnBool PolygonDrawCB(ZnPoint *bevels, PolygonData *pd) { - WidgetInfo *wi = pd->wi; + ZnWInfo *wi = pd->wi; XPoint bevel_xpoints[5]; XGCValues values; int j; @@ -831,8 +928,8 @@ PolygonDrawCB(ZnPoint *bevels, XChangeGC(wi->dpy, wi->gc, GCFillStyle|GCForeground, &values); for (j = 0; j < 4; j++) { - bevel_xpoints[j].x = REAL_TO_INT(bevels[j].x); - bevel_xpoints[j].y = REAL_TO_INT(bevels[j].y); + bevel_xpoints[j].x = ZnNearestInt(bevels[j].x); + bevel_xpoints[j].y = ZnNearestInt(bevels[j].y); } XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc, bevel_xpoints, 4, @@ -842,12 +939,12 @@ PolygonDrawCB(ZnPoint *bevels, } void -ZnDrawPolygonRelief(WidgetInfo *wi, - ReliefStyle relief, - ZnGradient *gradient, - ZnPoint *points, - int num_points, - int line_width) +ZnDrawPolygonRelief(ZnWInfo *wi, + ZnReliefStyle relief, + ZnGradient *gradient, + ZnPoint *points, + unsigned int num_points, + ZnDim line_width) { PolygonData pd; @@ -858,10 +955,10 @@ ZnDrawPolygonRelief(WidgetInfo *wi, * Grooves and ridges are drawn with two calls. The first * with the original width, the second with half the width. */ - if ((relief == RELIEF_RIDGE) || (relief == RELIEF_GROOVE)) { - pd.relief = (relief==RELIEF_GROOVE)?RELIEF_RAISED:RELIEF_SUNKEN; + if ((relief == ZN_RELIEF_RIDGE) || (relief == ZN_RELIEF_GROOVE)) { + pd.relief = (relief==ZN_RELIEF_GROOVE)?ZN_RELIEF_RAISED:ZN_RELIEF_SUNKEN; DoPolygon(points, num_points, line_width, PolygonDrawCB, &pd); - pd.relief = (relief==RELIEF_GROOVE)?RELIEF_SUNKEN:RELIEF_RAISED; + pd.relief = (relief==ZN_RELIEF_GROOVE)?ZN_RELIEF_SUNKEN:ZN_RELIEF_RAISED; DoPolygon(points, num_points, line_width/2, PolygonDrawCB, &pd); } else { @@ -878,7 +975,7 @@ ZnDrawPolygonRelief(WidgetInfo *wi, * ********************************************************************************** */ -#ifdef GLX +#ifdef GL static ZnBool PolygonRenderCB(ZnPoint *bevels, PolygonData *pd) @@ -886,17 +983,17 @@ PolygonRenderCB(ZnPoint *bevels, int i; ZnPoint p[6]; XColor *c[8]; - XColor *color = ZnGetGradientColor(pd->gradient, 51, NULL); - ReliefStyle relief, int_relief; + XColor *color = ZnGetGradientColor(pd->gradient, 51.0, NULL); + ZnReliefStyle relief, int_relief; ZnBool two_faces, round, rule; - rule = pd->relief & RELIEF_RULE; - round = pd->relief & RELIEF_ROUND; - two_faces = pd->relief & RELIEF_TWO_FACES; - relief = pd->relief & RELIEF_MASK; + rule = pd->relief & ZN_RELIEF_RULE; + round = pd->relief & ZN_RELIEF_ROUND; + two_faces = pd->relief & ZN_RELIEF_TWO_FACES; + relief = pd->relief & ZN_RELIEF_MASK; for (i = 0; i < 4; i++) { - p[i].x = REAL_TO_INT(bevels[i].x); - p[i].y = REAL_TO_INT(bevels[i].y); + p[i].x = ZnNearestInt(bevels[i].x); + p[i].y = ZnNearestInt(bevels[i].y); } if (two_faces) { @@ -905,11 +1002,11 @@ PolygonRenderCB(ZnPoint *bevels, p[5].x = (p[2].x+p[3].x)/2; p[5].y = (p[2].y+p[3].y)/2; - if (relief == RELIEF_SUNKEN) { - int_relief = RELIEF_RAISED; + if (relief == ZN_RELIEF_SUNKEN) { + int_relief = ZN_RELIEF_RAISED; } else { - int_relief = RELIEF_SUNKEN; + int_relief = ZN_RELIEF_SUNKEN; } c[0]=c[1]=c[2]=c[3] = ReliefColorOfSegment(bevels[0].x, bevels[0].y, bevels[3].x, bevels[3].y, @@ -935,28 +1032,28 @@ PolygonRenderCB(ZnPoint *bevels, } glBegin(GL_QUADS); glColor4us(c[0]->red, c[0]->green, c[0]->blue, pd->alpha); - glVertex2f(p[0].x, p[0].y); + glVertex2d(p[0].x, p[0].y); glColor4us(c[1]->red, c[1]->green, c[1]->blue, pd->alpha); - glVertex2f(p[4].x, p[4].y); + glVertex2d(p[4].x, p[4].y); glColor4us(c[2]->red, c[2]->green, c[2]->blue, pd->alpha); - glVertex2f(p[5].x, p[5].y); + glVertex2d(p[5].x, p[5].y); glColor4us(c[3]->red, c[3]->green, c[3]->blue, pd->alpha); - glVertex2f(p[3].x, p[3].y); + glVertex2d(p[3].x, p[3].y); glColor4us(c[4]->red, c[4]->green, c[4]->blue, pd->alpha); - glVertex2f(p[4].x, p[4].y); + glVertex2d(p[4].x, p[4].y); glColor4us(c[5]->red, c[5]->green, c[5]->blue, pd->alpha); - glVertex2f(p[1].x, p[1].y); + glVertex2d(p[1].x, p[1].y); glColor4us(c[6]->red, c[6]->green, c[6]->blue, pd->alpha); - glVertex2f(p[2].x, p[2].y); + glVertex2d(p[2].x, p[2].y); glColor4us(c[7]->red, c[7]->green, c[7]->blue, pd->alpha); - glVertex2f(p[5].x, p[5].y); + glVertex2d(p[5].x, p[5].y); glEnd(); } else { /* Single face */ @@ -973,13 +1070,13 @@ PolygonRenderCB(ZnPoint *bevels, } glBegin(GL_QUADS); glColor4us(c[0]->red, c[0]->green, c[0]->blue, pd->alpha); - glVertex2f(p[0].x, p[0].y); + glVertex2d(p[0].x, p[0].y); glColor4us(c[1]->red, c[1]->green, c[1]->blue, pd->alpha); - glVertex2f(p[1].x, p[1].y); + glVertex2d(p[1].x, p[1].y); glColor4us(c[2]->red, c[2]->green, c[2]->blue, pd->alpha); - glVertex2f(p[2].x, p[2].y); + glVertex2d(p[2].x, p[2].y); glColor4us(c[3]->red, c[3]->green, c[3]->blue, pd->alpha); - glVertex2f(p[3].x, p[3].y); + glVertex2d(p[3].x, p[3].y); glEnd(); } @@ -987,19 +1084,19 @@ PolygonRenderCB(ZnPoint *bevels, } void -ZnRenderPolygonRelief(WidgetInfo *wi, - ReliefStyle relief, +ZnRenderPolygonRelief(ZnWInfo *wi, + ZnReliefStyle relief, ZnGradient *gradient, ZnBool smooth, ZnPoint *points, - int num_points, - ZnReal line_width) + unsigned int num_points, + ZnDim line_width) { PolygonData pd; pd.wi = wi; pd.gradient = gradient; - ZnGetGradientColor(gradient, 0, &pd.alpha); + ZnGetGradientColor(gradient, 0.0, &pd.alpha); pd.alpha = ZnComposeAlpha(pd.alpha, wi->alpha); pd.smooth = smooth; glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); @@ -1010,24 +1107,24 @@ ZnRenderPolygonRelief(WidgetInfo *wi, } void -ZnRenderPolyline(WidgetInfo *wi, +ZnRenderPolyline(ZnWInfo *wi, ZnPoint *points, - int num_points, - ZnReal line_width, - LineStyle line_style, + unsigned int num_points, + ZnDim line_width, + ZnLineStyle line_style, int cap_style, - int join_style, + int join_style __unused, ZnLineEnd first_end, ZnLineEnd last_end, ZnGradient *gradient) { int num_clips = ZnListSize(wi->clip_stack); - ZnPoint end_points[LINE_END_POINTS]; + ZnPoint end_points[ZN_LINE_END_POINTS]; ZnBool need_rcaps, thin, closed, transparent; int pass, num_passes, i, k, m; ZnPoint c1, c2; XColor *color; - int alpha; + unsigned short alpha; /* * The code below draws curves thiner than the min @@ -1040,11 +1137,11 @@ ZnRenderPolyline(WidgetInfo *wi, thin = ((line_width <= wi->max_line_width) && (line_width <= wi->max_point_width)); closed = (points->x == points[num_points-1].x) && (points->y == points[num_points-1].y); - color = ZnGetGradientColor(gradient, 0, &alpha); + color = ZnGetGradientColor(gradient, 0.0, &alpha); alpha = ZnComposeAlpha(alpha, wi->alpha); glColor4us(color->red, color->green, color->blue, alpha); ZnSetLineStyle(wi, line_style); - glLineWidth(line_width); + glLineWidth((GLfloat) line_width); /* * Do not use joints under this transparency value. */ @@ -1064,11 +1161,11 @@ ZnRenderPolyline(WidgetInfo *wi, * We have chosen to drawn transparent lines with a * correct coverage but NOT antialiased. */ - glPointSize(line_width>1?line_width-1:line_width); + glPointSize((GLfloat)(line_width>1.0?line_width-1:line_width)); glDisable(GL_LINE_SMOOTH); } else { - glPointSize(line_width>1?line_width-1:line_width); + glPointSize((GLfloat)(line_width>1.0?line_width-1:line_width)); } num_passes = 1; @@ -1079,55 +1176,55 @@ ZnRenderPolyline(WidgetInfo *wi, for (pass = 0; pass < num_passes; pass++) { if (transparent) { if (pass == 0) { - GLX_START_CLIP(num_clips, True); + ZnGlStartClip(num_clips, True); } else { - GLX_RESTORE_STENCIL(num_clips, False); + ZnGlRestoreStencil(num_clips, False); } } if (first_end) { - GetLineEnd(&points[0], &points[1], line_width, cap_style, - first_end, end_points); + ZnGetLineEnd(&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); + for (m = 0; m < ZN_LINE_END_POINTS; m++) { + glVertex2d(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); + ZnGetLineEnd(&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); + for (m = 0; m < ZN_LINE_END_POINTS; m++) { + glVertex2d(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); + for (i = 0; i < (int) num_points; i++) { + glVertex2d(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); + for (i = 0; i < (int) num_points-1; i++) { + ZnGetButtPoints(&points[i+1], &points[i], line_width, False, &c1, &c2); + glVertex2d(c1.x, c1.y); + glVertex2d(c2.x, c2.y); + ZnGetButtPoints(&points[i], &points[i+1], line_width, False, &c1, &c2); + glVertex2d(c1.x, c1.y); + glVertex2d(c2.x, c2.y); } glEnd(); } /* if (pass == 0) { - GLX_RENDER_CLIPPED(); + ZnGlRenderClipped(); } else { - GLX_END_CLIP(num_clips); + ZnGlEndClip(num_clips); break; }*/ need_rcaps = ((line_width > 1) && (cap_style == CapRound)); @@ -1146,21 +1243,21 @@ ZnRenderPolyline(WidgetInfo *wi, if (thin) { glBegin(GL_POINTS); for ( ; i < k; i++) { - glVertex2f(points[i].x, points[i].y); + glVertex2d(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, 2*M_PI, &num_cpoints, NULL); + ZnPoint *cpoints = ZnGetCirclePoints(3, ZN_CIRCLE_COARSE, + 0.0, 2*M_PI, &num_cpoints, NULL); for ( ; i < k; i++) { glBegin(GL_TRIANGLE_FAN); - glVertex2f(points[i].x, points[i].y); + glVertex2d(points[i].x, points[i].y); for (m = 0; m < num_cpoints; m++) { - glVertex2f(points[i].x + cpoints[m].x*lw_2, + glVertex2d(points[i].x + cpoints[m].x*lw_2, points[i].y + cpoints[m].y*lw_2); } glEnd(); @@ -1168,7 +1265,7 @@ ZnRenderPolyline(WidgetInfo *wi, } } - GLX_END_CLIP(num_clips); + ZnGlEndClip(num_clips); if (thin) { glEnable(GL_LINE_SMOOTH); } @@ -1176,7 +1273,7 @@ ZnRenderPolyline(WidgetInfo *wi, void -ZnRenderIcon(WidgetInfo *wi, +ZnRenderIcon(ZnWInfo *wi, ZnImage image, ZnGradient *gradient, ZnPoint *origin, @@ -1198,18 +1295,18 @@ ZnRenderIcon(WidgetInfo *wi, void -ZnRenderImage(WidgetInfo *wi, +ZnRenderImage(ZnWInfo *wi, ZnImage image, ZnGradient *gradient, ZnPoint *quad, ZnBool modulate) { - XColor *color; - int alpha; - ZnReal t, s; - GLuint texobj; + XColor *color; + unsigned short alpha; + ZnReal t, s; + GLuint texobj; - color = ZnGetGradientColor(gradient, 0, &alpha); + color = ZnGetGradientColor(gradient, 0.0, &alpha); alpha = ZnComposeAlpha(alpha, wi->alpha); texobj = ZnImageTex(image, &t, &s); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); @@ -1223,28 +1320,29 @@ ZnRenderImage(WidgetInfo *wi, glColor4us(65535, 65535, 65535, alpha); } glBegin(GL_QUADS); - glTexCoord2f(0.0, 0.0); - glVertex2f(quad[0].x, quad[0].y); - glTexCoord2f(0.0, t); - glVertex2f(quad[1].x, quad[1].y); - glTexCoord2f(s, t); - glVertex2f(quad[2].x, quad[2].y); - glTexCoord2f(s, 0.0); - glVertex2f(quad[3].x, quad[3].y); + glTexCoord2d(0.0, 0.0); + glVertex2d(quad[0].x, quad[0].y); + glTexCoord2d(0.0, t); + glVertex2d(quad[1].x, quad[1].y); + glTexCoord2d(s, t); + glVertex2d(quad[2].x, quad[2].y); + glTexCoord2d(s, 0.0); + glVertex2d(quad[3].x, quad[3].y); glEnd(); glDisable(GL_TEXTURE_2D); } void -ZnRenderTile(WidgetInfo *wi, +ZnRenderTile(ZnWInfo *wi, ZnImage tile, ZnGradient *gradient, - void cb(void *), + void (*cb)(void *), void *closure, ZnPoint *quad) /* Right now it's a ZnBBox */ { ZnReal x, y, nx, ny, lx, ly, s, t, tiles, tilet; - int width, height, alpha, num_clips = ZnListSize(wi->clip_stack); + int width, height, num_clips = ZnListSize(wi->clip_stack); + unsigned short alpha; GLuint texobj; if (gradient) { @@ -1259,10 +1357,10 @@ ZnRenderTile(WidgetInfo *wi, /* * Setup the stencil buffer with the shape to be drawn. */ - GLX_START_CLIP(num_clips, False); + ZnGlStartClip(num_clips, False); (*cb)(closure); - GLX_RESTORE_STENCIL(num_clips, True); + ZnGlRestoreStencil(num_clips, True); } /* @@ -1298,14 +1396,14 @@ ZnRenderTile(WidgetInfo *wi, s = (lx - x) / (ZnReal) width; } s *= tiles; - glTexCoord2f(0.0, 0.0); - glVertex2f(x, y); - glTexCoord2f(0.0, t); - glVertex2f(x, ny); - glTexCoord2f(s, t); - glVertex2f(nx, ny); - glTexCoord2f(s, 0.0); - glVertex2f(nx, y); + glTexCoord2d(0.0, 0.0); + glVertex2d(x, y); + glTexCoord2d(0.0, t); + glVertex2d(x, ny); + glTexCoord2d(s, t); + glVertex2d(nx, ny); + glTexCoord2d(s, 0.0); + glVertex2d(nx, y); x = nx; } while (x != lx); @@ -1315,29 +1413,29 @@ ZnRenderTile(WidgetInfo *wi, glEnd(); if (cb) { - GLX_END_CLIP(num_clips); + ZnGlEndClip(num_clips); } glDisable(GL_TEXTURE_2D); } void -ZnComputeAxialGradient(WidgetInfo *wi, - ZnPoly *shape, - int angle, - ZnPoint *grad_geo) +ZnComputeAxialGradient(ZnWInfo *wi, + ZnPoly *shape, + ZnReal angle, + ZnPoint *grad_geo) { ZnTransfo *transfo1, *transfo2; ZnContour *c; ZnBBox bbox; ZnPoint *points, p[4]; - int i; + unsigned int i; transfo1 = ZnTransfoNew(); transfo2 = ZnTransfoNew(); ZnRotateDeg(transfo1, angle); ZnRotateDeg(transfo2, -angle); c = shape->contours; - ResetBBox(&bbox); + ZnResetBBox(&bbox); for (i = 0; i < shape->num_contours; i++, c++) { if (c->cw) { continue; @@ -1345,7 +1443,7 @@ ZnComputeAxialGradient(WidgetInfo *wi, ZnListAssertSize(wi->work_pts, c->num_points); points = ZnListArray(wi->work_pts); ZnTransformPoints(transfo1, c->points, points, c->num_points); - AddPointsToBBox(&bbox, points, c->num_points); + ZnAddPointsToBBox(&bbox, points, c->num_points); } bbox.orig.x--; bbox.orig.y--; @@ -1365,7 +1463,7 @@ ZnComputeAxialGradient(WidgetInfo *wi, } void -ZnComputeRadialGradient(WidgetInfo *wi, +ZnComputeRadialGradient(ZnWInfo *wi, ZnPoly *shape, ZnBool oval, ZnPoint *focal_pp, /* in percent of bbox */ @@ -1377,19 +1475,19 @@ ZnComputeRadialGradient(WidgetInfo *wi, ZnPoint offset, focal_point, radius; ZnPoint *points; ZnTransfo t1; - int i, j; + unsigned int i, j; /* * Compute the shape bbox (which should be in the item space). */ - ResetBBox(&bbox); + ZnResetBBox(&bbox); c = shape->contours; dist = 0.0; for (j = 0; j < shape->num_contours; j++, c++) { if (c->cw) { continue; } - AddPointsToBBox(&bbox, c->points, c->num_points); + ZnAddPointsToBBox(&bbox, c->points, c->num_points); } /* @@ -1476,26 +1574,26 @@ ZnComputeRadialGradient(WidgetInfo *wi, } void -ZnComputePathGradient(WidgetInfo *wi, - ZnPoly *shape, - ZnPoint *focal_pp, /* in percent of the bbox */ - ZnPoint *grad_geo) +ZnComputePathGradient(ZnWInfo *wi, + ZnPoly *shape, + ZnPoint *focal_pp, /* in percent of the bbox */ + ZnPoint *grad_geo) { ZnBBox bbox; ZnContour *c; ZnPoint focal_point; - int j; + unsigned int j; /* * Compute the shape bbox (which should be in the item space). */ - ResetBBox(&bbox); + ZnResetBBox(&bbox); c = shape->contours; for (j = 0; j < shape->num_contours; j++, c++) { if (c->cw) { continue; } - AddPointsToBBox(&bbox, c->points, c->num_points); + ZnAddPointsToBBox(&bbox, c->points, c->num_points); } /* @@ -1510,10 +1608,10 @@ ZnComputePathGradient(WidgetInfo *wi, } void -ZnRenderGradient(WidgetInfo *wi, +ZnRenderGradient(ZnWInfo *wi, ZnGradient *gradient, /* The grdient to be drawn (static * parameters). */ - void cb(void *), /* A callback called to clip the shape + void (*cb)(void *), /* A callback called to clip the shape * containing the gradient. */ void *closure, /* The callback parameter. */ ZnPoint *quad, /* The gradient geometric parameters @@ -1521,14 +1619,16 @@ ZnRenderGradient(WidgetInfo *wi, ZnPoly *poly /* Used only by ZN_PATH_GRADIENT */ ) { - int alpha, angle, i, j; + unsigned short alpha, alpha2; + int angle; + unsigned int i, j; int type = gradient->type; XColor *color; ZnPoint p; ZnPoint dposa, dposb, dposc, dposd; ZnPoint dcontrol; ZnReal npos, pos, control; - int num_clips = ZnListSize(wi->clip_stack); + unsigned int num_clips = ZnListSize(wi->clip_stack); ZnPoint iquad[4]; if (!cb && (type == ZN_AXIAL_GRADIENT)) { /* Render an aligned @@ -1568,9 +1668,9 @@ ZnRenderGradient(WidgetInfo *wi, * Draw the gradient shape in the stencil using the provided * callback (clipping). */ - GLX_START_CLIP(num_clips, False); + ZnGlStartClip(num_clips, False); (*cb)(closure); - GLX_RESTORE_STENCIL(num_clips, True); + ZnGlRestoreStencil(num_clips, True); } if (type == ZN_AXIAL_GRADIENT) { @@ -1591,13 +1691,13 @@ ZnRenderGradient(WidgetInfo *wi, dposa.y = (quad[1].y - quad[0].y)*pos/100.0; p.x = quad[0].x + dposa.x; p.y = quad[0].y + dposa.y; - glVertex2f(p.x, p.y); + glVertex2d(p.x, p.y); dposb.x = (quad[2].x - quad[3].x)*pos/100.0; dposb.y = (quad[2].y - quad[3].y)*pos/100.0; p.x = quad[3].x + dposb.x; p.y = quad[3].y + dposb.y; - glVertex2f(p.x, p.y); + glVertex2d(p.x, p.y); if ((control != 50.0) && (i != gradient->num_colors-1)) { color = gradient->colors[i].mid_rgb; @@ -1611,7 +1711,7 @@ ZnRenderGradient(WidgetInfo *wi, dcontrol.y = (dposc.y - dposa.y)*control/100.0; p.x = quad[0].x + dposa.x + dcontrol.x; p.y = quad[0].y + dposa.y + dcontrol.y; - glVertex2f(p.x, p.y); + glVertex2d(p.x, p.y); dposd.x = (quad[2].x - quad[3].x)*npos/100.0; dposd.y = (quad[2].y - quad[3].y)*npos/100.0; @@ -1619,20 +1719,20 @@ ZnRenderGradient(WidgetInfo *wi, dcontrol.y = (dposd.y - dposb.y)*control/100.0; p.x = quad[3].x + dposb.x + dcontrol.x; p.y = quad[3].y + dposb.y + dcontrol.y; - glVertex2f(p.x, p.y); + glVertex2d(p.x, p.y); } } glEnd(); } else if (type == ZN_RADIAL_GRADIENT) { - ZnReal x, position, position2, position3; - ZnReal y; - int num_p, alpha2; - ZnPoint *genarc, *tarc, p, focalp; - XColor *color2; + ZnReal x, position, position2, position3; + ZnReal y; + unsigned int num_p; + ZnPoint *genarc, *tarc, p, focalp; + XColor *color2; - genarc = GetCirclePoints(3, ZN_CIRCLE_FINE, 0, 2*M_PI, &num_p, NULL); + genarc = ZnGetCirclePoints(3, ZN_CIRCLE_FINE, 0.0, 2*M_PI, &num_p, NULL); ZnListAssertSize(wi->work_pts, num_p); tarc = ZnListArray(wi->work_pts); ZnTransformPoints((ZnTransfo *) quad, genarc, tarc, num_p); @@ -1654,11 +1754,11 @@ ZnRenderGradient(WidgetInfo *wi, x = focalp.x + (tarc[i].x-focalp.x) * position; y = focalp.y + (tarc[i].y-focalp.y) * position; glColor4us(color->red, color->green, color->blue, alpha); - glVertex2f(x, y); + glVertex2d(x, y); x = focalp.x + (tarc[i].x-focalp.x) * position3; y = focalp.y + (tarc[i].y-focalp.y) * position3; glColor4us(color2->red, color2->green, color2->blue, alpha); - glVertex2f(x, y); + glVertex2d(x, y); } position = position3; color = color2; @@ -1672,11 +1772,11 @@ ZnRenderGradient(WidgetInfo *wi, x = focalp.x + (tarc[i].x-focalp.x) * position; y = focalp.y + (tarc[i].y-focalp.y) * position; glColor4us(color->red, color->green, color->blue, alpha); - glVertex2f(x, y); + glVertex2d(x, y); x = focalp.x + (tarc[i].x-focalp.x) * position2; y = focalp.y + (tarc[i].y-focalp.y) * position2; glColor4us(color2->red, color2->green, color2->blue, alpha2); - glVertex2f(x, y); + glVertex2d(x, y); } glEnd(); position = position2; @@ -1686,10 +1786,10 @@ ZnRenderGradient(WidgetInfo *wi, } } else if (type == ZN_PATH_GRADIENT) { - ZnPoint p, pp, p2, pp2, p3, pp3; - int num_p, k, ii; - ZnPoint *points; - ZnReal position; + ZnPoint p, pp, p2, pp2, p3, pp3; + unsigned int num_p, k, ii; + ZnPoint *points; + ZnReal position; for (k = 0; k < poly->num_contours; k++) { if (poly->contours[k].cw) { @@ -1713,8 +1813,8 @@ ZnRenderGradient(WidgetInfo *wi, alpha = ZnComposeAlpha(gradient->colors[0].alpha, wi->alpha); color = gradient->colors[0].rgb; glColor4us(color->red, color->green, color->blue, alpha); - glVertex2f(quad[0].x+p.x, quad[0].y+p.y); - glVertex2f(quad[0].x+pp.x, quad[0].y+pp.y); + glVertex2d(quad[0].x+p.x, quad[0].y+p.y); + glVertex2d(quad[0].x+pp.x, quad[0].y+pp.y); for (j = 0; j < gradient->num_colors-1; j++) { position = gradient->colors[j+1].position; p2.x = (points[i].x-quad[0].x)*position/100.0; @@ -1729,8 +1829,8 @@ ZnRenderGradient(WidgetInfo *wi, pp3.x = pp.x+(pp2.x-pp.x)*control/100.0; pp3.y = pp.y+(pp2.y-pp.y)*control/100.0; glColor4us(color->red, color->green, color->blue, alpha); - glVertex2f(quad[0].x+p3.x, quad[0].y+p3.y); - glVertex2f(quad[0].x+pp3.x, quad[0].y+pp3.y); + glVertex2d(quad[0].x+p3.x, quad[0].y+p3.y); + glVertex2d(quad[0].x+pp3.x, quad[0].y+pp3.y); } control = gradient->colors[j+1].control; alpha = ZnComposeAlpha(gradient->colors[j+1].alpha, wi->alpha); @@ -1738,8 +1838,8 @@ ZnRenderGradient(WidgetInfo *wi, p = p2; pp = pp2; glColor4us(color->red, color->green, color->blue, alpha); - glVertex2f(quad[0].x+p.x, quad[0].y+p.y); - glVertex2f(quad[0].x+pp.x, quad[0].y+pp.y); + glVertex2d(quad[0].x+p.x, quad[0].y+p.y); + glVertex2d(quad[0].x+pp.x, quad[0].y+pp.y); } glEnd(); } @@ -1750,44 +1850,44 @@ ZnRenderGradient(WidgetInfo *wi, /* * Restore the previous GL state. */ - GLX_END_CLIP(num_clips); + ZnGlEndClip(num_clips); } } void -ZnRenderHollowDot(WidgetInfo *wi, +ZnRenderHollowDot(ZnWInfo *wi, ZnPoint *p, ZnReal size) { int num_clips = ZnListSize(wi->clip_stack); - GLX_START_CLIP(num_clips, False); + ZnGlStartClip(num_clips, False); - glPointSize(size-2); + glPointSize((GLfloat) (size-2)); glBegin(GL_POINTS); - glVertex2f(p->x, p->y); + glVertex2d(p->x, p->y); glEnd(); - GLX_RENDER_CLIPPED(); + ZnGlRenderClipped(); - glPointSize(size); + glPointSize((GLfloat) size); glBegin(GL_POINTS); - glVertex2f(p->x, p->y); + glVertex2d(p->x, p->y); glEnd(); - GLX_RESTORE_STENCIL(num_clips, False); + ZnGlRestoreStencil(num_clips, False); glBegin(GL_POINTS); - glVertex2f(p->x, p->y); + glVertex2d(p->x, p->y); glEnd(); - GLX_END_CLIP(num_clips); + ZnGlEndClip(num_clips); } #endif -#ifdef GLX +#ifdef GL /* Copyright (c) Mark J. Kilgard, 1997. */ /* This program is freely distributable without licensing fees and is @@ -1819,9 +1919,9 @@ ZnRenderGlyph(ZnTexFontInfo *tfi, void ZnRenderString(ZnTexFontInfo *tfi, unsigned char *string, - int len) + unsigned int len) { - int i; + unsigned int i; for (i = 0; i < len; i++) { ZnRenderGlyph(tfi, string[i]); @@ -1835,12 +1935,12 @@ enum { void ZnRenderFancyString(ZnTexFontInfo *tfi, unsigned char *string, - int len) + unsigned int len) { ZnTexGVI *tgvi; GLubyte c[4][3]; int mode = MONO; - int i; + unsigned int i; for (i = 0; i < len; i++) { if (string[i] == 27) { diff --git a/generic/Draw.h b/generic/Draw.h index 038b379..f0166ef 100644 --- a/generic/Draw.h +++ b/generic/Draw.h @@ -36,37 +36,28 @@ #include "Attrs.h" #include "Image.h" -#include -#ifdef GLX -#include -#endif - -#define LIGHTNING_POINTS 4 -#define CORNER_POINTS 3 -#define DOUBLE_CORNER_POINTS 4 -#define STRAIGHT_POINTS 2 -#define LINE_SHAPE_POINTS 4 /* Maximum of all above */ +#define ZN_LINE_SHAPE_POINTS 4 /* Maximum of all *_SHAPE_POINTS */ -struct _WidgetInfo; +struct _ZnWInfo; -#ifdef GLX -#define GLX_START_CLIP(num_clips, render) { \ +#ifdef GL +#define ZnGlStartClip(num_clips, render) { \ if (!num_clips) { \ glEnable(GL_STENCIL_TEST); \ } \ - glStencilFunc(GL_EQUAL, num_clips, 0xFF); \ + glStencilFunc(GL_EQUAL, (GLint) num_clips, 0xFF); \ glStencilOp(GL_KEEP, GL_INCR, GL_INCR); \ if (!render) { \ glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); \ } \ } -#define GLX_RENDER_CLIPPED() { \ +#define ZnGlRenderClipped() { \ glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); \ glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); \ } -#define GLX_RESTORE_STENCIL(num_clips, render) { \ - glStencilFunc(GL_EQUAL, num_clips+1, 0xFF); \ +#define ZnGlRestoreStencil(num_clips, render) { \ + glStencilFunc(GL_EQUAL, (GLint) (num_clips+1), 0xFF); \ glStencilOp(GL_KEEP, GL_DECR, GL_DECR); \ if (render) { \ glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); \ @@ -75,8 +66,8 @@ struct _WidgetInfo; glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); \ } \ } -#define GLX_END_CLIP(num_clips) { \ - glStencilFunc(GL_EQUAL, num_clips, 0xFF); \ +#define ZnGlEndClip(num_clips) { \ + glStencilFunc(GL_EQUAL, (GLint) num_clips, 0xFF); \ glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); \ glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); \ if (!num_clips) { \ @@ -86,52 +77,56 @@ struct _WidgetInfo; #endif -void ZnSetLineStyle(struct _WidgetInfo *wi, LineStyle line_style); -void ZnGetLineShape(ZnPoint *p1, ZnPoint *p2, unsigned int line_width, - LineShape shape, ZnBBox *bbox, ZnList to_points); -void ZnDrawLineShape(struct _WidgetInfo *wi, ZnPoint *points, int num_points, - LineStyle line_style, ZnColor line_foreground, - unsigned int line_width, LineShape shape); -int ZnPolygonReliefInBBox(ZnPoint *points, int num_points, int line_width, - ZnBBox *bbox); -void ZnGetPolygonReliefBBox(ZnPoint *points, int num_points, int line_width, - ZnBBox *bbox); -double ZnPolygonReliefToPointDist(ZnPoint *points, int num_points, int line_width, - ZnPoint *pp); -void ZnDrawRectangleRelief(struct _WidgetInfo *wi, - ReliefStyle relief, ZnGradient *gradient, - XRectangle *bbox, unsigned int line_width); -void ZnDrawPolygonRelief(struct _WidgetInfo *wi, ReliefStyle relief, +void ZnSetLineStyle(struct _ZnWInfo *wi, ZnLineStyle line_style); +void ZnLineShapePoints(ZnPoint *p1, ZnPoint *p2, ZnDim line_width, + ZnLineShape shape, ZnBBox *bbox, ZnList to_points); +void ZnDrawLineShape(struct _ZnWInfo *wi, ZnPoint *points, unsigned int num_points, + ZnLineStyle line_style, XColor *line_foreground, + ZnDim line_width, ZnLineShape shape); +void +ZnGetLineEnd(ZnPoint *p1, ZnPoint *p2, ZnDim line_width, + int cap_style, ZnLineEnd end_style, ZnPoint *points); + +int ZnPolygonReliefInBBox(ZnPoint *points, unsigned int num_points, + ZnDim line_width, ZnBBox *bbox); +void ZnGetPolygonReliefBBox(ZnPoint *points, unsigned int num_points, + ZnDim line_width, ZnBBox *bbox); +double ZnPolygonReliefToPointDist(ZnPoint *points, unsigned int num_points, + ZnDim line_width, ZnPoint *pp); +void ZnDrawRectangleRelief(struct _ZnWInfo *wi, + ZnReliefStyle relief, ZnGradient *gradient, + XRectangle *bbox, ZnDim line_width); +void ZnDrawPolygonRelief(struct _ZnWInfo *wi, ZnReliefStyle relief, ZnGradient *gradient, ZnPoint *points, - int num_points, int line_width); -#ifdef GLX -void ZnRenderPolygonRelief(struct _WidgetInfo *wi, ReliefStyle relief, + unsigned int num_points, ZnDim line_width); +#ifdef GL +void ZnRenderPolygonRelief(struct _ZnWInfo *wi, ZnReliefStyle relief, ZnGradient *gradient, ZnBool smooth, - ZnPoint *points, int num_points, ZnReal line_width); -void ZnRenderPolyline(struct _WidgetInfo *wi, ZnPoint *points, int num_points, - ZnReal line_width, LineStyle line_style, int cap_style, + ZnPoint *points, unsigned int num_points, ZnDim line_width); +void ZnRenderPolyline(struct _ZnWInfo *wi, ZnPoint *points, unsigned int num_points, + ZnDim line_width, ZnLineStyle line_style, int cap_style, int join_style, ZnLineEnd first_end, ZnLineEnd last_end, ZnGradient *gradient); -void ZnComputeAxialGradient(struct _WidgetInfo *wi, ZnPoly *shape, int angle, +void ZnComputeAxialGradient(struct _ZnWInfo *wi, ZnPoly *shape, ZnReal angle, ZnPoint *grad_geo); -void ZnComputeRadialGradient(struct _WidgetInfo *wi, ZnPoly *shape, ZnBool oval, +void ZnComputeRadialGradient(struct _ZnWInfo *wi, ZnPoly *shape, ZnBool oval, ZnPoint *center, ZnPoint *grad_geo); -void ZnComputePathGradient(struct _WidgetInfo *wi, ZnPoly *shape, ZnPoint *center, +void ZnComputePathGradient(struct _ZnWInfo *wi, ZnPoly *shape, ZnPoint *center, ZnPoint *grad_geo); -void ZnRenderGradient(struct _WidgetInfo *wi, ZnGradient *gradient, - void cb(void *), void *closure, ZnPoint *quad, +void ZnRenderGradient(struct _ZnWInfo *wi, ZnGradient *gradient, + void (*cb)(void *), void *closure, ZnPoint *quad, ZnPoly *poly); -void ZnRenderTile(struct _WidgetInfo *wi, ZnImage tile, ZnGradient *gradient, - void cb(void *), void *closure, ZnPoint *quad); -void ZnRenderIcon(struct _WidgetInfo *wi, ZnImage image, ZnGradient *gradient, +void ZnRenderTile(struct _ZnWInfo *wi, ZnImage tile, ZnGradient *gradient, + void (*cb)(void *), void *closure, ZnPoint *quad); +void ZnRenderIcon(struct _ZnWInfo *wi, ZnImage image, ZnGradient *gradient, ZnPoint *origin, ZnBool modulate); -void ZnRenderImage(struct _WidgetInfo *wi, ZnImage image, ZnGradient *gradient, +void ZnRenderImage(struct _ZnWInfo *wi, ZnImage image, ZnGradient *gradient, ZnPoint *quad, ZnBool modulate); -void RenderHollowDot(struct _WidgetInfo *wi, ZnPoint *p, ZnReal size); +void RenderHollowDot(struct _ZnWInfo *wi, ZnPoint *p, ZnReal size); void ZnRenderGlyph(ZnTexFontInfo *tfi, int c); -void ZnRenderString(ZnTexFontInfo *tfi, unsigned char *str, int len); -void ZnRenderFancyString(ZnTexFontInfo *tfi, unsigned char *str, int len); +void ZnRenderString(ZnTexFontInfo *tfi, unsigned char *str, unsigned int len); +void ZnRenderFancyString(ZnTexFontInfo *tfi, unsigned char *str, unsigned int len); #endif #endif /* _Draw_h */ diff --git a/generic/Field.c b/generic/Field.c index 8d24264..4893633 100644 --- a/generic/Field.c +++ b/generic/Field.c @@ -27,13 +27,6 @@ */ -#include -#include -#include -#ifdef GLX -#include -#endif - #include "Item.h" #include "Types.h" #include "WidgetInfo.h" @@ -41,6 +34,9 @@ #include "Geo.h" #include "tkZinc.h" +#include +#include + static const char rcsid[] = "$Id$"; static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ " $"; @@ -65,13 +61,13 @@ typedef struct _FieldStruct { char *text; ZnImage image; ZnImage tile; - ZnFont font; + Tk_Font font; unsigned short flags; - Border border_edges; - ZnJustify alignment; - ReliefStyle relief; + ZnBorder border_edges; + Tk_Justify alignment; + ZnReliefStyle relief; ZnDim relief_thickness; - AutoAlign auto_alignment; + ZnAutoAlign auto_alignment; /* Private data */ ZnGradient *gradient; @@ -80,9 +76,9 @@ typedef struct _FieldStruct { short orig_y; short corner_x; short corner_y; - FieldSet field_set; /* Only used by the image update callbacks */ + ZnFieldSet field_set; /* Only used by the image update callbacks */ int insert_index; -#ifdef GLX +#ifdef GL ZnTexFontInfo *tfi; #endif } FieldStruct, *Field; @@ -131,10 +127,10 @@ ZnAttrConfig field_attrs[] = { Tk_Offset(FieldStruct, flags), FIELD_VISIBLE_BIT, ZN_COORDS_FLAG|ZN_CLFC_FLAG, False }, /* Keep ZN_COORDS_FLAG here */ - { ZN_CONFIG_END, NULL, NULL, 0, 0, 0 } + { ZN_CONFIG_END, NULL, NULL, 0, 0, 0, False } }; -static void GetLabelBBox(FieldSet field_set, ZnDim *w, ZnDim *h); +static void GetLabelBBox(ZnFieldSet field_set, ZnDim *w, ZnDim *h); @@ -147,14 +143,14 @@ static void GetLabelBBox(FieldSet field_set, ZnDim *w, ZnDim *h); ********************************************************************************** */ static void -ComputeFieldAttachment(FieldSet field_set, - int field, - ZnBBox *field_bbox) +ComputeFieldAttachment(ZnFieldSet field_set, + unsigned int field, + ZnBBox *field_bbox) { ZnBBox ref_bbox; ZnDim real_width, real_height; - int ref_field, num_fields; + unsigned int ref_field, num_fields; char x_attach, y_attach, x_dim, y_dim; short width_spec, height_spec; int x_spec, y_spec, icon_width=0, icon_height=0; @@ -180,29 +176,29 @@ ComputeFieldAttachment(FieldSet field_set, field_bbox->corner.x = field_bbox->corner.y = 0; SET(fptr->flags, CACHE_OK); - num_fields = LabelFormatNumFields(field_set->label_format); - LabelFormatGetField(field_set->label_format, field, - &x_attach, &y_attach, &x_dim, &y_dim, - &x_spec, &y_spec, &width_spec, &height_spec); + num_fields = ZnLFNumFields(field_set->label_format); + ZnLFGetField(field_set->label_format, field, + &x_attach, &y_attach, &x_dim, &y_dim, + &x_spec, &y_spec, &width_spec, &height_spec); /* * First try to compute the field size which may be a factor * of the field content (but not a factor of other fields). */ if ((fptr->image != ZnUnspecifiedImage) && - ((x_dim == LF_DIM_ICON) || (y_dim == LF_DIM_ICON) || - (x_dim == LF_DIM_AUTO) || (y_dim == LF_DIM_AUTO))) { + ((x_dim == ZN_LF_DIM_ICON) || (y_dim == ZN_LF_DIM_ICON) || + (x_dim == ZN_LF_DIM_AUTO) || (y_dim == ZN_LF_DIM_AUTO))) { ZnSizeOfImage(fptr->image, &icon_width, &icon_height); } switch (x_dim) { - case LF_DIM_FONT: - real_width = (ZnDim) (width_spec*ZnTextWidth(fptr->font, "N", 1)/100); + case ZN_LF_DIM_FONT: + real_width = (ZnDim) (width_spec*Tk_TextWidth(fptr->font, "N", 1)/100); break; - case LF_DIM_ICON: + case ZN_LF_DIM_ICON: real_width = (ZnDim) (width_spec*icon_width/100); break; - case LF_DIM_AUTO: + case ZN_LF_DIM_AUTO: { int len = 0; ZnDim text_width; @@ -218,20 +214,20 @@ ComputeFieldAttachment(FieldSet field_set, /* * The 4 extra pixels are needed for border and padding. */ - text_width = (ZnDim) ZnTextWidth(fptr->font, fptr->text, len) + 4; + text_width = (ZnDim) Tk_TextWidth(fptr->font, fptr->text, len) + 4; real_width = text_width < real_width ? real_width : text_width; } real_width += (ZnDim) width_spec; break; } - case LF_DIM_LABEL: + case ZN_LF_DIM_LABEL: { ZnDim lh; GetLabelBBox(field_set, &real_width, &lh); break; } - case LF_DIM_PIXEL: + case ZN_LF_DIM_PIXEL: default: real_width = (ZnDim) width_spec; break; @@ -239,16 +235,16 @@ ComputeFieldAttachment(FieldSet field_set, /*printf("field %d, width = %g\n", field, real_width);*/ switch (y_dim) { - case LF_DIM_FONT: + case ZN_LF_DIM_FONT: { Tk_GetFontMetrics(fptr->font, &fm); real_height = (ZnDim) (height_spec*(fm.ascent + fm.descent)/100); break; } - case LF_DIM_ICON: + case ZN_LF_DIM_ICON: real_height = (ZnDim) (height_spec*icon_height/100); break; - case LF_DIM_AUTO: + case ZN_LF_DIM_AUTO: { ZnDim text_height; @@ -264,14 +260,14 @@ ComputeFieldAttachment(FieldSet field_set, real_height += (ZnDim) height_spec; break; } - case LF_DIM_LABEL: + case ZN_LF_DIM_LABEL: { ZnDim lw; GetLabelBBox(field_set, &lw, &real_height); break; } - case LF_DIM_PIXEL: + case ZN_LF_DIM_PIXEL: default: real_height = (ZnDim) height_spec; break; @@ -282,8 +278,10 @@ ComputeFieldAttachment(FieldSet field_set, * Update the cache with the newly computed infos * (breaking of deadlocks). */ - field_bbox->corner.x = fptr->corner_x = real_width; - field_bbox->corner.y = fptr->corner_y = real_height; + field_bbox->corner.x = real_width; + field_bbox->corner.y = real_height; + fptr->corner_x = (short) real_width; + fptr->corner_y = (short) real_height; /* * Then try to deduce the position, resolving any attachments @@ -293,21 +291,21 @@ ComputeFieldAttachment(FieldSet field_set, /* * Do the x axis. */ - if (x_dim != LF_DIM_LABEL) { - if (x_attach == LF_ATTACH_PIXEL) { + if (x_dim != ZN_LF_DIM_LABEL) { + if (x_attach == ZN_LF_ATTACH_PIXEL) { field_bbox->orig.x = (ZnPos) x_spec; field_bbox->corner.x = field_bbox->orig.x + real_width; } else { ref_field = x_spec; field_bbox->orig.x = field_bbox->corner.x = 0; - if ((ref_field < 0) || (ref_field >= num_fields)) { + if (ref_field >= num_fields) { ZnWarning ("Attached (x) to an inexistant field geometry\n"); } else { ComputeFieldAttachment(field_set, ref_field, &ref_bbox); switch (x_attach) { - case LF_ATTACH_FWD: + case ZN_LF_ATTACH_FWD: if (ISSET(field_set->fields[ref_field].flags, FIELD_VISIBLE_BIT)) { field_bbox->orig.x = ref_bbox.corner.x; } @@ -316,7 +314,7 @@ ComputeFieldAttachment(FieldSet field_set, } field_bbox->corner.x = field_bbox->orig.x + real_width; break; - case LF_ATTACH_BWD: + case ZN_LF_ATTACH_BWD: if (ISSET(field_set->fields[ref_field].flags, FIELD_VISIBLE_BIT)) { field_bbox->corner.x = ref_bbox.orig.x; } @@ -325,11 +323,11 @@ ComputeFieldAttachment(FieldSet field_set, } field_bbox->orig.x = field_bbox->corner.x - real_width; break; - case LF_ATTACH_LEFT: + case ZN_LF_ATTACH_LEFT: field_bbox->orig.x = ref_bbox.orig.x; field_bbox->corner.x = field_bbox->orig.x + real_width; break; - case LF_ATTACH_RIGHT: + case ZN_LF_ATTACH_RIGHT: if (ISSET(field_set->fields[ref_field].flags, FIELD_VISIBLE_BIT)) { field_bbox->corner.x = ref_bbox.corner.x; } @@ -347,21 +345,21 @@ ComputeFieldAttachment(FieldSet field_set, /* * Then the y axis. */ - if (y_dim != LF_DIM_LABEL) { - if (y_attach == LF_ATTACH_PIXEL) { + if (y_dim != ZN_LF_DIM_LABEL) { + if (y_attach == ZN_LF_ATTACH_PIXEL) { field_bbox->orig.y = (ZnPos) y_spec; field_bbox->corner.y = field_bbox->orig.y + real_height; } else { ref_field = y_spec; field_bbox->orig.y = field_bbox->corner.y = 0; - if ((ref_field < 0) || (ref_field >= num_fields)) { + if (ref_field >= num_fields) { ZnWarning ("Attached (y) to an inexistant field geometry\n"); } else { ComputeFieldAttachment(field_set, ref_field, &ref_bbox); switch (y_attach) { - case LF_ATTACH_FWD: + case ZN_LF_ATTACH_FWD: if (ISSET(field_set->fields[ref_field].flags, FIELD_VISIBLE_BIT)) { field_bbox->orig.y = ref_bbox.corner.y; } @@ -370,7 +368,7 @@ ComputeFieldAttachment(FieldSet field_set, } field_bbox->corner.y = field_bbox->orig.y + real_height; break; - case LF_ATTACH_BWD: + case ZN_LF_ATTACH_BWD: if (ISSET(field_set->fields[ref_field].flags, FIELD_VISIBLE_BIT)) { field_bbox->corner.y = ref_bbox.orig.y; } @@ -379,11 +377,11 @@ ComputeFieldAttachment(FieldSet field_set, } field_bbox->orig.y = field_bbox->corner.y - real_height; break; - case LF_ATTACH_LEFT: + case ZN_LF_ATTACH_LEFT: field_bbox->orig.y = ref_bbox.orig.y; field_bbox->corner.y = field_bbox->orig.y + real_height; break; - case LF_ATTACH_RIGHT: + case ZN_LF_ATTACH_RIGHT: if (ISSET(field_set->fields[ref_field].flags, FIELD_VISIBLE_BIT)) { field_bbox->corner.y = ref_bbox.corner.y; } @@ -417,10 +415,10 @@ ComputeFieldAttachment(FieldSet field_set, ********************************************************************************** */ static void -ClearFieldCache(FieldSet field_set, +ClearFieldCache(ZnFieldSet field_set, int field) { - int i, num_fields; + unsigned int i, num_fields; ZnBool clear_bbox; int x_spec, y_spec; char x_attach, y_attach, x_dim, y_dim; @@ -441,35 +439,35 @@ ClearFieldCache(FieldSet field_set, if (!field_set->label_format) { return; } - num_fields = LabelFormatNumFields(field_set->label_format); - if (field >= num_fields) { + num_fields = ZnLFNumFields(field_set->label_format); + if ((unsigned int) field >= num_fields) { return; } - LabelFormatGetField(field_set->label_format, field, - &x_attach, &y_attach, &x_dim, &y_dim, - &x_spec, &y_spec, &width_spec, &height_spec); - if ((x_dim != LF_DIM_PIXEL) || (y_dim != LF_DIM_PIXEL)) { + ZnLFGetField(field_set->label_format, (unsigned int) field, + &x_attach, &y_attach, &x_dim, &y_dim, + &x_spec, &y_spec, &width_spec, &height_spec); + if ((x_dim != ZN_LF_DIM_PIXEL) || (y_dim != ZN_LF_DIM_PIXEL)) { CLEAR(field_set->fields[field].flags, CACHE_OK); clear_bbox = True; } for (i = 0; i < num_fields; i++) { - LabelFormatGetField(field_set->label_format, i, - &x_attach, &y_attach, &x_dim, &y_dim, - &x_spec, &y_spec, &width_spec, &height_spec); - if ((x_attach == LF_ATTACH_PIXEL) && (y_attach == LF_ATTACH_PIXEL)) { + ZnLFGetField(field_set->label_format, i, + &x_attach, &y_attach, &x_dim, &y_dim, + &x_spec, &y_spec, &width_spec, &height_spec); + if ((x_attach == ZN_LF_ATTACH_PIXEL) && (y_attach == ZN_LF_ATTACH_PIXEL)) { continue; } - if (x_attach != LF_ATTACH_PIXEL) { + if (x_attach != ZN_LF_ATTACH_PIXEL) { if ((x_spec == field) && ISSET(field_set->fields[i].flags, CACHE_OK)) { CLEAR(field_set->fields[i].flags, CACHE_OK); - ClearFieldCache(field_set, i); + ClearFieldCache(field_set, (int) i); clear_bbox = True; } } - if (y_attach != LF_ATTACH_PIXEL) { + if (y_attach != ZN_LF_ATTACH_PIXEL) { if ((y_spec == field) && ISSET(field_set->fields[i].flags, CACHE_OK)) { CLEAR(field_set->fields[i].flags, CACHE_OK); - ClearFieldCache(field_set, i); + ClearFieldCache(field_set, (int) i); clear_bbox = True; } } @@ -489,13 +487,13 @@ ClearFieldCache(FieldSet field_set, ********************************************************************************** */ static void -GetLabelBBox(FieldSet field_set, +GetLabelBBox(ZnFieldSet field_set, ZnDim *w, ZnDim *h) { ZnBBox bbox, tmp_bbox; ZnLabelFormat lf; - int i, num_fields; + unsigned int i, num_fields; ZnDim clip_w, clip_h; if ((field_set->label_width >= 0.0) && (field_set->label_height >= 0.0)) { @@ -510,20 +508,20 @@ GetLabelBBox(FieldSet field_set, return; } - ResetBBox(&bbox); - num_fields = LabelFormatNumFields(lf); + ZnResetBBox(&bbox); + num_fields = ZnLFNumFields(lf); for (i = 0; i < num_fields; i++) { ComputeFieldAttachment(field_set, i, &tmp_bbox); /*printf("field %d bbox %g %g %g %g\n", i, tmp_bbox.orig.x, tmp_bbox.orig.y, tmp_bbox.corner.x, tmp_bbox.corner.y);*/ - AddBBoxToBBox(&bbox, &tmp_bbox); + ZnAddBBoxToBBox(&bbox, &tmp_bbox); } field_set->label_width = bbox.corner.x; field_set->label_height = bbox.corner.y; /*printf("GetLabelBBox size before clipping; w = %g, h = %g\n", field_set->label_width, field_set->label_height);*/ - if (LabelFormatGetClipBox(lf, &clip_w, &clip_h)) { + if (ZnLFGetClipBox(lf, &clip_w, &clip_h)) { if (clip_w < field_set->label_width) { field_set->label_width = clip_w; } @@ -548,15 +546,15 @@ GetLabelBBox(FieldSet field_set, ********************************************************************************** */ static void -GetFieldBBox(FieldSet field_set, +GetFieldBBox(ZnFieldSet field_set, unsigned int index, ZnBBox *field_bbox) { ZnReal ox, oy; if (field_set->label_format) { - ox = REAL_TO_INT(field_set->label_pos.x); - oy = REAL_TO_INT(field_set->label_pos.y); + ox = ZnNearestInt(field_set->label_pos.x); + oy = ZnNearestInt(field_set->label_pos.y); ComputeFieldAttachment(field_set, index, field_bbox); field_bbox->orig.x += ox; field_bbox->orig.y += oy; @@ -564,7 +562,7 @@ GetFieldBBox(FieldSet field_set, field_bbox->corner.y += oy; } else { - ResetBBox(field_bbox); + ZnResetBBox(field_bbox); } } @@ -592,7 +590,7 @@ ComputeFieldTextLocation(Field fptr, Tk_GetFontMetrics(fptr->font, &fm); w = 0; if (fptr->text) { - w = ZnTextWidth(fptr->font, fptr->text, strlen(fptr->text)); + w = Tk_TextWidth(fptr->font, fptr->text, (int) strlen(fptr->text)); } h = fm.ascent + fm.descent; text_bbox->orig.y = (bbox->orig.y + bbox->corner.y - h) / 2.0; @@ -600,10 +598,10 @@ ComputeFieldTextLocation(Field fptr, pos->y = text_bbox->orig.y + fm.ascent; switch (fptr->alignment) { - case ZnJustifyLeft: + case TK_JUSTIFY_LEFT: text_bbox->orig.x = bbox->orig.x + 2; break; - case ZnJustifyRight: + case TK_JUSTIFY_RIGHT: text_bbox->orig.x = bbox->corner.x - w - 2; break; default: @@ -625,7 +623,7 @@ ComputeFieldTextLocation(Field fptr, ********************************************************************************** */ static void -LeaderToLabel(FieldSet field_set, +LeaderToLabel(ZnFieldSet field_set, ZnPoint *start, ZnPoint *end) { @@ -633,7 +631,7 @@ LeaderToLabel(FieldSet field_set, ZnPoint delta, inf, sup; ZnPos xt=0, yu=0, yw=0, xv=0; Field fptr; - int i; + unsigned int i; ZnBBox field_bbox; /* Intersection points : */ @@ -646,9 +644,9 @@ LeaderToLabel(FieldSet field_set, delta.x = start->x - end->x; delta.y = start->y - end->y; - b_num = start->y*delta.x - start->x*delta.y; + b_num = (int) (start->y*delta.x - start->x*delta.y); - for (i = 0; i < LabelFormatNumFields(field_set->label_format); i++) { + for (i = 0; i < ZnLFNumFields(field_set->label_format); i++) { fptr = &field_set->fields[i]; /* * If the field is made invisible or has no graphics of @@ -657,8 +655,8 @@ LeaderToLabel(FieldSet field_set, if (ISCLEAR(fptr->flags, FIELD_VISIBLE_BIT) || (!fptr->text && ISCLEAR(fptr->flags, FILLED_BIT) && - (fptr->border_edges == NO_BORDER) && - (fptr->relief == RELIEF_FLAT) && + (fptr->border_edges == ZN_NO_BORDER) && + (fptr->relief == ZN_RELIEF_FLAT) && (fptr->image == ZnUnspecifiedImage))) { continue; } @@ -674,14 +672,14 @@ LeaderToLabel(FieldSet field_set, */ if (fptr->text && ISCLEAR(fptr->flags, FILLED_BIT) && - (fptr->border_edges == NO_BORDER) && - (fptr->relief == RELIEF_FLAT) && + (fptr->border_edges == ZN_NO_BORDER) && + (fptr->relief == ZN_RELIEF_FLAT) && (fptr->image == ZnUnspecifiedImage)) { ZnBBox text_bbox; ZnPoint text_pos; /* dummy */ int space_width; int scan_forw, scan_back; - space_width = ZnTextWidth(fptr->font, " ", 1); + space_width = Tk_TextWidth(fptr->font, " ", 1); ComputeFieldTextLocation(fptr, &field_bbox, &text_pos, &text_bbox); /* @@ -799,23 +797,20 @@ LeaderToLabel(FieldSet field_set, * * InitFields -- * - * Perform the init of each field in a FieldSet. The number of such + * Perform the init of each field in a ZnFieldSet. The number of such * fields must have been inited before calling this fun. * ********************************************************************************** */ static void -InitFields(FieldSet field_set) +InitFields(ZnFieldSet field_set) { - WidgetInfo *wi = field_set->item->wi; + ZnWInfo *wi = field_set->item->wi; Field field; unsigned int i, num_fields; /*printf("size of a field = %d\n", sizeof(FieldStruct));*/ - if (field_set->num_fields < 0) { - field_set->num_fields = 0; - } if (!field_set->num_fields) { return; } @@ -838,17 +833,17 @@ InitFields(FieldSet field_set) field->image = ZnUnspecifiedImage; field->tile = ZnUnspecifiedImage; field->font = Tk_GetFont(wi->interp, wi->win, Tk_NameOfFont(wi->font)); -#ifdef GLX +#ifdef GL field->tfi = NULL; if (wi->render) { field->tfi = ZnGetTexFont(wi, field->font); } #endif - field->border_edges = NO_BORDER; - field->alignment = ZnJustifyLeft; + field->border_edges = ZN_NO_BORDER; + field->alignment = TK_JUSTIFY_LEFT; field->auto_alignment.automatic = False; - field->relief = RELIEF_FLAT; + field->relief = ZN_RELIEF_FLAT; field->relief_thickness = 2; SET(field->flags, TEXT_ON_TOP_BIT); @@ -868,9 +863,9 @@ InitFields(FieldSet field_set) ********************************************************************************** */ static void -CloneFields(FieldSet field_set) +CloneFields(ZnFieldSet field_set) { - WidgetInfo *wi = field_set->item->wi; + ZnWInfo *wi = field_set->item->wi; Field field, fields_ret; unsigned int i, num_fields; char *text; @@ -880,7 +875,7 @@ CloneFields(FieldSet field_set) return; } if (field_set->label_format) { - field_set->label_format = LabelFormatDuplicate(field_set->label_format); + field_set->label_format = ZnLFDuplicate(field_set->label_format); } fields_ret = (Field) ZnMalloc(num_fields*sizeof(FieldStruct)); memcpy(fields_ret, field_set->fields, num_fields*sizeof(FieldStruct)); @@ -906,7 +901,7 @@ CloneFields(FieldSet field_set) field->fill_pattern = ZnGetImageByValue(field->fill_pattern); } field->font = Tk_GetFont(wi->interp, wi->win, Tk_NameOfFont(field->font)); -#ifdef GLX +#ifdef GL if (wi->render) { field->tfi = ZnGetTexFont(wi, field->font); } @@ -932,47 +927,48 @@ CloneFields(FieldSet field_set) ********************************************************************************** */ static int -ConfigureField(FieldSet fs, +ConfigureField(ZnFieldSet fs, int field, int argc, Tcl_Obj *CONST argv[], int *flags) { - int i; + unsigned int i; Field fptr; ZnBBox bbox; - WidgetInfo *wi = fs->item->wi; + ZnWInfo *wi = fs->item->wi; XColor *color; - int alpha, old_num_chars, num_chars; -#ifdef GLX - ZnFont old_font; + unsigned short alpha; + int old_num_chars, num_chars; +#ifdef GL + Tk_Font old_font; #endif - if ((field == ZN_NO_PART) || (field >= fs->num_fields)) { + if ((field < 0) || ((unsigned int) field >= fs->num_fields)) { Tcl_AppendResult(wi->interp, "invalid field index", NULL); - return ZN_ERROR; + return TCL_ERROR; } fptr = &fs->fields[field]; -#ifdef GLX +#ifdef GL old_font = fptr->font; #endif old_num_chars = 0; if (fptr->text) { - old_num_chars = Tcl_NumUtfChars(fptr->text, strlen(fptr->text)); + old_num_chars = Tcl_NumUtfChars(fptr->text, (int) strlen(fptr->text)); } if (ZnConfigureAttributes(wi, fptr, field_attrs, - argc, argv, flags) == ZN_ERROR) { - return ZN_ERROR; + argc, argv, flags) == TCL_ERROR) { + return TCL_ERROR; } num_chars = 0; if (fptr->text) { - num_chars = Tcl_NumUtfChars(fptr->text, strlen(fptr->text)); + num_chars = Tcl_NumUtfChars(fptr->text, (int) strlen(fptr->text)); } if (old_num_chars != num_chars) { - TextInfo *ti = &wi->text_info; + ZnTextInfo *ti = &wi->text_info; /* * The text has changed, update the selection and * insertion pos to keep them valid. @@ -995,7 +991,7 @@ ConfigureField(FieldSet fs, } } -#ifdef GLX +#ifdef GL if (old_font != fptr->font) { if (fptr->tfi) { ZnFreeTexFont(fptr->tfi); @@ -1005,30 +1001,30 @@ ConfigureField(FieldSet fs, if (!fptr->tfi) { Tcl_AppendResult(wi->interp, "impossible to get the texture for font \"", Tk_NameOfFont(fptr->font), "\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } } } #endif if (ISSET(*flags, ZN_REPICK_FLAG)) { - SET(wi->events_flags, INTERNAL_NEED_REPICK); + SET(wi->flags, ZN_INTERNAL_NEED_REPICK); } if (ISSET(*flags, ZN_CLFC_FLAG)) { ClearFieldCache(fs, field); } if (fptr->gradient && - (ISSET(*flags, ZN_BORDER_FLAG) || (fptr->relief == RELIEF_FLAT))) { + (ISSET(*flags, ZN_BORDER_FLAG) || (fptr->relief == ZN_RELIEF_FLAT))) { ZnFreeGradient(fptr->gradient); fptr->gradient = NULL; } - if ((fptr->relief != RELIEF_FLAT) && !fptr->gradient) { + if ((fptr->relief != ZN_RELIEF_FLAT) && !fptr->gradient) { color = ZnGetGradientColor(fptr->border_color, 51.0, &alpha); fptr->gradient = ZnGetReliefGradient(wi->interp, wi->win, - ZnNameOfColor(color), alpha); + Tk_NameOfColor(color), alpha); if (fptr->gradient == NULL) { - return ZN_ERROR; + return TCL_ERROR; } } @@ -1038,8 +1034,8 @@ ConfigureField(FieldSet fs, */ if (ISCLEAR(*flags, ZN_COORDS_FLAG) && fs->label_format && ISSET(*flags, ZN_DRAW_FLAG)) { - for (i = 0; i < LabelFormatNumFields(fs->label_format); i++) { - if (i == field) { + for (i = 0; i < ZnLFNumFields(fs->label_format); i++) { + if (i == (unsigned int) field) { GetFieldBBox(fs, i, &bbox); ZnDamage(wi, &bbox); break; @@ -1047,7 +1043,7 @@ ConfigureField(FieldSet fs, } } - return ZN_OK; + return TCL_OK; } @@ -1059,22 +1055,22 @@ ConfigureField(FieldSet fs, ********************************************************************************** */ static int -QueryField(FieldSet fs, +QueryField(ZnFieldSet fs, int field, - int argc, + int argc __unused, Tcl_Obj *CONST argv[]) { - if ((field == ZN_NO_PART) || (field >= fs->num_fields)) { + if ((field < 0) || ((unsigned int) field >= fs->num_fields)) { Tcl_AppendResult(fs->item->wi->interp, "invalid field index \"", NULL); - return ZN_ERROR; + return TCL_ERROR; } if (ZnQueryAttribute(fs->item->wi, &fs->fields[field], field_attrs, - argv[0]) == ZN_ERROR) { - return ZN_ERROR; + argv[0]) == TCL_ERROR) { + return TCL_ERROR; } - return ZN_OK; + return TCL_OK; } @@ -1086,13 +1082,13 @@ QueryField(FieldSet fs, ********************************************************************************** */ static void -FreeFields(FieldSet field_set) +FreeFields(ZnFieldSet field_set) { unsigned int i, num_fields; Field field; if (field_set->label_format) { - LabelFormatDelete(field_set->label_format); + ZnLFDelete(field_set->label_format); } num_fields = field_set->num_fields; @@ -1121,7 +1117,7 @@ FreeFields(FieldSet field_set) field->fill_pattern = ZnUnspecifiedImage; } Tk_FreeFont(field->font); -#ifdef GLX +#ifdef GL if (field->tfi) { ZnFreeTexFont(field->tfi); } @@ -1150,16 +1146,16 @@ FreeFields(FieldSet field_set) ********************************************************************************** */ static int -FieldPointToChar(FieldSet fs, - int field, +FieldPointToChar(ZnFieldSet fs, + unsigned int field, int x, int y) { Field fptr; - int num_bytes, byte_index; + int byte_index; ZnBBox f_bbox, t_bbox; ZnPoint t_orig; - int n, dummy; + unsigned int num_bytes, n, dummy; fptr = &fs->fields[field]; num_bytes = 0; @@ -1199,16 +1195,16 @@ FieldPointToChar(FieldSet fs, goto convrt; } n = Tk_MeasureChars(fptr->font, fptr->text, num_bytes, - x + 2 - t_bbox.orig.x, TK_PARTIAL_OK, &dummy); + x + 2 - (int) t_bbox.orig.x, TK_PARTIAL_OK, &dummy); byte_index = n - 1; goto convrt; } /* * Point below all lines, return the index after * the last char. - */ - convrt: + */ byte_index = num_bytes; + convrt: return Tcl_NumUtfChars(fptr->text, byte_index); } @@ -1245,22 +1241,22 @@ WordMoveFromIndex(char *text, } static int -FieldIndex(FieldSet fs, +FieldIndex(ZnFieldSet fs, int field, Tcl_Obj *index_spec, int *index) { Field fptr; - WidgetInfo *wi = fs->item->wi; - TextInfo *ti = &wi->text_info; - int c, length; - int x, y; + ZnWInfo *wi = fs->item->wi; + ZnTextInfo *ti = &wi->text_info; + unsigned int length; + int c, x, y; double tmp; char *end, *p; - if ((field == ZN_NO_PART) || (field >= fs->num_fields)) { + if ((field < 0) || ((unsigned int) field >= fs->num_fields)) { *index = 0; - return ZN_OK; + return TCL_OK; } fptr = &fs->fields[field]; @@ -1270,10 +1266,10 @@ FieldIndex(FieldSet fs, length = strlen(p); if ((c == 'e') && (strncmp(p, "end", length) == 0)) { - *index = fptr->text?Tcl_NumUtfChars(fptr->text, strlen(fptr->text)):0; + *index = fptr->text ? Tcl_NumUtfChars(fptr->text, (int) strlen(fptr->text)) : 0; } else if ((c == 'e') && (length > 1) && (strncmp(p, "eol", length) == 0)) { - *index = fptr->text?Tcl_NumUtfChars(fptr->text, strlen(fptr->text)):0; + *index = fptr->text ? Tcl_NumUtfChars(fptr->text, (int) strlen(fptr->text)) : 0; } else if ((c == 'b') && (length > 1) && (strncmp(p, "bol", length) == 0)) { *index = 0; @@ -1298,7 +1294,7 @@ FieldIndex(FieldSet fs, if ((ti->sel_item != fs->item) || (ti->sel_field != field)) { sel_err: Tcl_AppendResult(wi->interp, "selection isn't in field", (char *) NULL); - return ZN_ERROR; + return TCL_ERROR; } *index = ti->sel_first; } @@ -1320,18 +1316,18 @@ FieldIndex(FieldSet fs, if ((end == p) || (*end != ',')) { goto badIndex; } - x = tmp; + x = (int) tmp; p = end+1; tmp = strtod(p, &end); if ((end == p) || (*end != 0)) { goto badIndex; } - y = tmp; + y = (int) tmp; - *index = FieldPointToChar(fs, field, x, y); + *index = FieldPointToChar(fs, (unsigned int) field, x, y); } else if (Tcl_GetIntFromObj(wi->interp, index_spec, index) == TCL_OK) { - int num_chars = fptr->text?Tcl_NumUtfChars(fptr->text, strlen(fptr->text)):0; + int num_chars = fptr->text ? Tcl_NumUtfChars(fptr->text, (int) strlen(fptr->text)) : 0; if (*index < 0){ *index = 0; } @@ -1342,25 +1338,25 @@ FieldIndex(FieldSet fs, else { badIndex: Tcl_AppendResult(wi->interp, "bad index \"", p, "\"", (char *) NULL); - return ZN_ERROR; + return TCL_ERROR; } - return ZN_OK; + return TCL_OK; } static ZnBool -FieldInsertChars(FieldSet fs, +FieldInsertChars(ZnFieldSet fs, int field, int *index, char *chars) { - Field fptr; - TextInfo *ti = &fs->item->wi->text_info; - int num_chars, num_bytes, chars_added; - int byte_index, bytes_added = strlen(chars); - char *new; + Field fptr; + ZnTextInfo *ti = &fs->item->wi->text_info; + int num_chars, num_bytes, chars_added; + unsigned int byte_index, bytes_added = strlen(chars); + char *new; - if ((field == ZN_NO_PART) || (field >= fs->num_fields)) { + if ((field < 0) || ((unsigned int) field >= fs->num_fields)) { return False; } @@ -1381,8 +1377,8 @@ FieldInsertChars(FieldSet fs, if (*index > num_chars) { *index = num_chars; } - byte_index = Tcl_UtfAtIndex(fptr->text, *index)-fptr->text; - chars_added = Tcl_NumUtfChars(chars, bytes_added); + byte_index = Tcl_UtfAtIndex(fptr->text, *index) - fptr->text; + chars_added = Tcl_NumUtfChars(chars, (int) bytes_added); new = ZnMalloc(num_bytes + bytes_added + 1); if (fptr->text) { @@ -1397,7 +1393,7 @@ FieldInsertChars(FieldSet fs, /* * Insert the new text. */ - strcpy(new + byte_index, chars); + memcpy(new + byte_index, chars, bytes_added); fptr->text = new; if (fptr->insert_index >= *index) { @@ -1424,18 +1420,18 @@ FieldInsertChars(FieldSet fs, } static ZnBool -FieldDeleteChars(FieldSet fs, +FieldDeleteChars(ZnFieldSet fs, int field, int *first, int *last) { - Field fptr; - TextInfo *ti = &fs->item->wi->text_info; - int char_count, byte_count; - int num_bytes, num_chars, first_offset; - char *new; + Field fptr; + ZnTextInfo *ti = &fs->item->wi->text_info; + unsigned int char_count, byte_count; + unsigned int num_bytes, num_chars, first_offset; + char *new; - if ((field == ZN_NO_PART) || (field >= fs->num_fields)) { + if ((field < 0) || ((unsigned int) field >= fs->num_fields)) { return False; } @@ -1444,7 +1440,7 @@ FieldDeleteChars(FieldSet fs, num_bytes = 0; if (fptr->text) { num_bytes = strlen(fptr->text); - num_chars = Tcl_NumUtfChars(fptr->text, num_bytes); + num_chars = Tcl_NumUtfChars(fptr->text, (int) num_bytes); } if (num_chars == 0) { return False; @@ -1453,7 +1449,7 @@ FieldDeleteChars(FieldSet fs, if (*first < 0) { *first = 0; } - if (*last >= num_chars) { + if (*last >= (int) num_chars) { *last = num_chars-1; } if (*first > *last) { @@ -1461,7 +1457,7 @@ FieldDeleteChars(FieldSet fs, } char_count = *last + 1 - *first; first_offset = Tcl_UtfAtIndex(fptr->text, *first)-fptr->text; - byte_count = Tcl_UtfAtIndex(fptr->text + first_offset, char_count)- + byte_count = Tcl_UtfAtIndex(fptr->text + first_offset, (int) char_count) - (fptr->text+first_offset); if (num_bytes - byte_count) { @@ -1518,21 +1514,21 @@ FieldDeleteChars(FieldSet fs, } static void -FieldCursor(FieldSet fs, +FieldCursor(ZnFieldSet fs, int field, int index) { Field fptr; int num_chars; - if ((field == ZN_NO_PART) || (field >= fs->num_fields)) { + if ((field < 0) || ((unsigned int) field >= fs->num_fields)) { return; } fptr = &fs->fields[field]; num_chars = 0; if (fptr->text) { - num_chars = Tcl_NumUtfChars(fptr->text, strlen(fptr->text)); + num_chars = Tcl_NumUtfChars(fptr->text, (int) strlen(fptr->text)); } if (index < 0) { @@ -1547,7 +1543,7 @@ FieldCursor(FieldSet fs, } static int -FieldSelection(FieldSet fs, +FieldSelection(ZnFieldSet fs, int field, int offset, char *chars, @@ -1556,9 +1552,9 @@ FieldSelection(FieldSet fs, Field fptr; int count; char const *sel_first, *sel_last; - TextInfo *ti; + ZnTextInfo *ti; - if ((field == ZN_NO_PART) || (field >= fs->num_fields)) { + if ((field < 0) || ((unsigned int) field >= fs->num_fields)) { return 0; } ti = &fs->item->wi->text_info; @@ -1610,10 +1606,10 @@ ComputeFieldImageLocation(Field fptr, pm_bbox->corner.y = pm_bbox->orig.y + height; switch (fptr->alignment) { - case ZnJustifyLeft: + case TK_JUSTIFY_LEFT: pm_bbox->orig.x = bbox->orig.x; break; - case ZnJustifyRight: + case TK_JUSTIFY_RIGHT: pm_bbox->orig.x = bbox->corner.x - width - 1; break; default: @@ -1632,14 +1628,14 @@ ComputeFieldImageLocation(Field fptr, ********************************************************************************** */ static void -FieldsEngine(FieldSet field_set, +FieldsEngine(ZnFieldSet field_set, void (*cb)()) { - WidgetInfo *wi = field_set->item->wi; - int i; /* This one *NEED* to be an int */ - int num_fields, num_chars; + ZnWInfo *wi = field_set->item->wi; + /*int i; This one *NEED* to be an int */ + unsigned int i, num_fields, num_chars; Field fptr; - TextInfo *ti = &wi->text_info; + ZnTextInfo *ti = &wi->text_info; ZnBBox lclip_bbox, fclip_bbox, bbox, *global_clip_box; ZnBBox tmp_bbox, text_bbox, pm_bbox; ZnPoint pts[2]; @@ -1655,17 +1651,17 @@ FieldsEngine(FieldSet field_set, return; } - if (field_set->label_format && LabelFormatNumFields(field_set->label_format)) { - bbox.orig.x = REAL_TO_INT(field_set->label_pos.x); - bbox.orig.y = REAL_TO_INT(field_set->label_pos.y); + if (field_set->label_format && ZnLFNumFields(field_set->label_format)) { + bbox.orig.x = ZnNearestInt(field_set->label_pos.x); + bbox.orig.y = ZnNearestInt(field_set->label_pos.y); GetLabelBBox(field_set, &lwidth, &lheight); bbox.corner.x = bbox.orig.x + lwidth; bbox.corner.y = bbox.orig.y + lheight; ZnCurrentClip(wi, NULL, &global_clip_box, NULL); if (!wi->render) { - IntersectBBox(global_clip_box, &bbox, &lclip_bbox); - if (IsEmptyBBox(&lclip_bbox)) { + ZnIntersectBBox(global_clip_box, &bbox, &lclip_bbox); + if (ZnIsEmptyBBox(&lclip_bbox)) { return; } } @@ -1673,7 +1669,7 @@ FieldsEngine(FieldSet field_set, lclip_bbox = bbox; } - num_fields = LabelFormatNumFields(field_set->label_format); + num_fields = ZnLFNumFields(field_set->label_format); for (i = 0; i < num_fields; i++) { fptr = &field_set->fields[i]; @@ -1682,8 +1678,8 @@ FieldsEngine(FieldSet field_set, } GetFieldBBox(field_set, i, &bbox); - IntersectBBox(&lclip_bbox, &bbox, &fclip_bbox); - if (IsEmptyBBox(&fclip_bbox)) { + ZnIntersectBBox(&lclip_bbox, &bbox, &fclip_bbox); + if (ZnIsEmptyBBox(&fclip_bbox)) { continue; } @@ -1702,16 +1698,17 @@ FieldsEngine(FieldSet field_set, if (fptr->text) { if ((field_set->item == wi->focus_item) && - (wi->focus_field == i) && wi->got_focus && ti->cursor_on) { + ((unsigned int) wi->focus_field == i) && + ISSET(wi->flags, ZN_GOT_FOCUS) && ti->cursor_on) { cursor = Tk_TextWidth(fptr->font, fptr->text, Tcl_UtfAtIndex(fptr->text, fptr->insert_index)-fptr->text); } ComputeFieldTextLocation(fptr, &bbox, &text_pos, &text_bbox); - num_chars = Tcl_NumUtfChars(fptr->text, strlen(fptr->text)); + num_chars = Tcl_NumUtfChars(fptr->text, (int) strlen(fptr->text)); if (num_chars) { - if ((field_set->item == ti->sel_item) && (ti->sel_field == i) && - (ti->sel_last >= 0) && (ti->sel_first <= num_chars)) { + if ((field_set->item == ti->sel_item) && ((unsigned int) ti->sel_field == i) && + (ti->sel_last >= 0) && (ti->sel_first <= (int) num_chars)) { sel_start = Tk_TextWidth(fptr->font, fptr->text, Tcl_UtfAtIndex(fptr->text, ti->sel_first)-fptr->text); @@ -1720,7 +1717,7 @@ FieldsEngine(FieldSet field_set, ti->sel_last)-fptr->text); } - IntersectBBox(&fclip_bbox, &text_bbox, &tmp_bbox); + ZnIntersectBBox(&fclip_bbox, &text_bbox, &tmp_bbox); val = tmp_bbox.orig.x - text_bbox.orig.x; restore |= val > 0; @@ -1736,7 +1733,7 @@ FieldsEngine(FieldSet field_set, if (fptr->image != ZnUnspecifiedImage) { ComputeFieldImageLocation(fptr, &bbox, &pm_bbox); - IntersectBBox(&fclip_bbox, &pm_bbox, &tmp_bbox); + ZnIntersectBBox(&fclip_bbox, &pm_bbox, &tmp_bbox); val = tmp_bbox.orig.x - pm_bbox.orig.x; restore |= val > 0; @@ -1754,7 +1751,7 @@ FieldsEngine(FieldSet field_set, /*printf("clip: %d\n", i);*/ pts[0] = fclip_bbox.orig; pts[1] = fclip_bbox.corner; - TRI_STRIP1(&tristrip, pts, 2, False); + ZnTriStrip1(&tristrip, pts, 2, False); ZnPushClip(wi, &tristrip, True, True); } @@ -1779,7 +1776,7 @@ FieldsEngine(FieldSet field_set, ********************************************************************************** */ static void -DrawField(WidgetInfo *wi, +DrawField(ZnWInfo *wi, Field fptr, ZnBBox *bbox, ZnBBox *pm_bbox, @@ -1789,16 +1786,17 @@ DrawField(WidgetInfo *wi, int sel_start, int sel_stop) { - TextInfo *ti = &wi->text_info; + ZnTextInfo *ti = &wi->text_info; XGCValues values; XRectangle r; int j, xs, num_bytes; int pw, ph, fw, fh; - Region clip_region; + TkRegion clip_region; ZnBool simple; - Pixmap pixmap, mask_pmap; - - BBox2XRect(bbox, &r); + Pixmap pixmap; + TkRegion photo_region, clip; + + ZnBBox2XRect(bbox, &r); /* * Draw the background. @@ -1808,7 +1806,7 @@ DrawField(WidgetInfo *wi, if (fptr->tile != ZnUnspecifiedImage) { /* Fill tiled */ values.fill_style = FillTiled; - values.tile = ZnImagePixmap(fptr->tile, NULL); + values.tile = ZnImagePixmap(fptr->tile); values.ts_x_origin = (int) bbox->orig.x; values.ts_y_origin = (int) bbox->orig.y; XChangeGC(wi->dpy, wi->gc, @@ -1817,7 +1815,7 @@ DrawField(WidgetInfo *wi, } else if (fptr->fill_pattern != ZnUnspecifiedImage) { /* Fill stippled */ values.fill_style = FillStippled; - values.stipple = ZnImagePixmap(fptr->fill_pattern, NULL); + values.stipple = ZnImagePixmap(fptr->fill_pattern); values.ts_x_origin = (int) bbox->orig.x; values.ts_y_origin = (int) bbox->orig.y; XChangeGC(wi->dpy, wi->gc, @@ -1842,31 +1840,44 @@ DrawField(WidgetInfo *wi, * Draw the image. */ if (fptr->image != ZnUnspecifiedImage) { - pixmap = ZnImagePixmap(fptr->image, &mask_pmap); - if (mask_pmap != ZnUnspecifiedImage) { - ZnCurrentClip(wi, &clip_region, NULL, &simple); - XSetClipMask(wi->dpy, wi->gc, mask_pmap); - XSetClipOrigin(wi->dpy, wi->gc, pm_bbox->orig.x, pm_bbox->orig.y); - } + pw = ZnNearestInt(pm_bbox->corner.x - pm_bbox->orig.x); + ph = ZnNearestInt(pm_bbox->corner.y - pm_bbox->orig.y); + fw = ZnNearestInt(bbox->corner.x - bbox->orig.x); + fh = ZnNearestInt(bbox->corner.y - bbox->orig.y); + + pixmap = ZnImagePixmap(fptr->image); + photo_region = ZnImageRegion(fptr->image); + ZnCurrentClip(wi, &clip_region, NULL, &simple); + clip = TkCreateRegion(); /* - * The image is clipped on the field boundary. - * This is needed to be compatible with image coming with - * a clip mask. The image clip mask resets the clip area in - * the GC, so we must fake the field clipping in the copyarea. + * ZnImageRegion may fail: perl/Tk 800.24 doesn't support + * some internal TkPhoto functions. + * This is a workaround using a rectangular region based + * on the image size. */ - pw = REAL_TO_INT(pm_bbox->corner.x - pm_bbox->orig.x); - ph = REAL_TO_INT(pm_bbox->corner.y - pm_bbox->orig.y); - fw = REAL_TO_INT(bbox->corner.x - bbox->orig.x); - fh = REAL_TO_INT(bbox->corner.y - bbox->orig.y); - XCopyArea(wi->dpy, pixmap, wi->draw_buffer, wi->gc, - REAL_TO_INT(bbox->orig.x-pm_bbox->orig.x), - REAL_TO_INT(bbox->orig.y-pm_bbox->orig.y), - MIN(pw, fw), MIN(ph, fh), - MAX(bbox->orig.x, pm_bbox->orig.x), - MAX(bbox->orig.y, pm_bbox->orig.y)); - if (mask_pmap != ZnUnspecifiedImage) { - XSetRegion(wi->dpy, wi->gc, clip_region); + if (photo_region == NULL) { + XRectangle rect; + rect.x = rect.y = 0; + rect.width = pw; + rect.height = ph; + TkUnionRectWithRegion(&rect, clip, clip); + } + else { + ZnUnionRegion(clip, photo_region, clip); } + ZnOffsetRegion(clip, (int) pm_bbox->orig.x, (int) pm_bbox->orig.y); + TkIntersectRegion(clip_region, clip, clip); + TkSetRegion(wi->dpy, wi->gc, clip); + XCopyArea(wi->dpy, pixmap, wi->draw_buffer, wi->gc, + (int) ZnNearestInt(bbox->orig.x-pm_bbox->orig.x), + (int) ZnNearestInt(bbox->orig.y-pm_bbox->orig.y), + (unsigned int) MIN(pw, fw), + (unsigned int) MIN(ph, fh), + (int) MAX(bbox->orig.x, pm_bbox->orig.x), + (int) MAX(bbox->orig.y, pm_bbox->orig.y)); + + TkSetRegion(wi->dpy, wi->gc, clip_region); + TkDestroyRegion(clip); } } else if (fptr->text) { @@ -1876,30 +1887,31 @@ DrawField(WidgetInfo *wi, num_bytes = strlen(fptr->text); if (num_bytes) { if (sel_start >= 0) { - values.foreground = ZnPixel(ZnGetGradientColor(ti->sel_color, 0, NULL)); + values.foreground = ZnPixel(ZnGetGradientColor(ti->sel_color, 0.0, NULL)); values.fill_style = FillSolid; XChangeGC(wi->dpy, wi->gc, GCForeground|GCFillStyle, &values); XFillRectangle(wi->dpy, wi->draw_buffer, wi->gc, - text_bbox->orig.x+sel_start, text_bbox->orig.y, - sel_stop-sel_start, - text_bbox->corner.y-text_bbox->orig.y); + (int) (text_bbox->orig.x+sel_start), + (int) text_bbox->orig.y, + (unsigned int) (sel_stop-sel_start), + (unsigned int) (text_bbox->corner.y-text_bbox->orig.y)); } - values.foreground = ZnPixel(ZnGetGradientColor(fptr->color, 0, NULL)); + values.foreground = ZnPixel(ZnGetGradientColor(fptr->color, 0.0, NULL)); values.fill_style = FillSolid; - values.font = ZnFontId(fptr->font); + values.font = Tk_FontId(fptr->font); XChangeGC(wi->dpy, wi->gc, GCForeground | GCFillStyle | GCFont, &values); Tk_DrawChars(wi->dpy, wi->draw_buffer, wi->gc, fptr->font, - fptr->text, num_bytes, text_pos->x, text_pos->y); + fptr->text, num_bytes, (int) text_pos->x, (int) text_pos->y); } if (cursor >= 0) { values.line_width = ti->insert_width; - values.foreground = ZnPixel(ZnGetGradientColor(ti->insert_color, 0, NULL)); + values.foreground = ZnPixel(ZnGetGradientColor(ti->insert_color, 0.0, NULL)); values.fill_style = FillSolid; XChangeGC(wi->dpy, wi->gc, GCForeground|GCLineWidth|GCFillStyle, &values); - xs = text_bbox->orig.x + cursor; + xs = (int) text_bbox->orig.x + cursor; XDrawLine(wi->dpy, wi->draw_buffer, wi->gc, - xs, text_bbox->orig.y, - xs, text_bbox->corner.y); + xs, (int) text_bbox->orig.y, + xs, (int) text_bbox->corner.y); } } } @@ -1907,44 +1919,44 @@ DrawField(WidgetInfo *wi, /* * Draw the border relief. */ - if ((fptr->relief != RELIEF_FLAT) && (fptr->relief_thickness > 1)) { + if ((fptr->relief != ZN_RELIEF_FLAT) && (fptr->relief_thickness > 1)) { ZnDrawRectangleRelief(wi, fptr->relief, fptr->gradient, - &r, (unsigned int) fptr->relief_thickness); + &r, fptr->relief_thickness); } /* * Draw the border line. */ - if (fptr->border_edges != NO_BORDER) { - values.foreground = ZnPixel(ZnGetGradientColor(fptr->border_color, 0, NULL)); + if (fptr->border_edges != ZN_NO_BORDER) { + values.foreground = ZnPixel(ZnGetGradientColor(fptr->border_color, 0.0, NULL)); values.line_width = 0; values.line_style = LineSolid; values.fill_style = FillSolid; XChangeGC(wi->dpy, wi->gc, GCForeground | GCLineWidth | GCLineStyle | GCFillStyle, &values); - if (fptr->border_edges & LEFT_BORDER) { + if (fptr->border_edges & ZN_LEFT_BORDER) { XDrawLine(wi->dpy, wi->draw_buffer, wi->gc, r.x, r.y, r.x, r.y + r.height - 1); } - if (fptr->border_edges & RIGHT_BORDER) { + if (fptr->border_edges & ZN_RIGHT_BORDER) { XDrawLine(wi->dpy, wi->draw_buffer, wi->gc, r.x + r.width - 1, r.y, r.x + r.width - 1, r.y + r.height - 1); } - if (fptr->border_edges & TOP_BORDER) { + if (fptr->border_edges & ZN_TOP_BORDER) { XDrawLine(wi->dpy, wi->draw_buffer, wi->gc, r.x, r.y, r.x + r.width - 1, r.y); } - if (fptr->border_edges & BOTTOM_BORDER) { + if (fptr->border_edges & ZN_BOTTOM_BORDER) { XDrawLine(wi->dpy, wi->draw_buffer, wi->gc, r.x, r.y + r.height - 1, r.x + r.width - 1, r.y + r.height - 1); } - if (fptr->border_edges & OBLIQUE) { + if (fptr->border_edges & ZN_OBLIQUE) { XDrawLine(wi->dpy, wi->draw_buffer, wi->gc, r.x, r.y, r.x + r.width - 1, r.y + r.height - 1); } - if (fptr->border_edges & COUNTER_OBLIQUE) { + if (fptr->border_edges & ZN_COUNTER_OBLIQUE) { XDrawLine(wi->dpy, wi->draw_buffer, wi->gc, r.x, r.y + r.height - 1, r.x + r.width - 1, r.y); @@ -1953,7 +1965,7 @@ DrawField(WidgetInfo *wi, } static void -DrawFields(FieldSet field_set) +DrawFields(ZnFieldSet field_set) { FieldsEngine(field_set, DrawField); } @@ -1966,23 +1978,24 @@ DrawFields(FieldSet field_set) * ********************************************************************************** */ -#ifdef GLX +#ifdef GL static void FieldRenderCB(void *closure) { ZnBBox *bbox = (ZnBBox *) closure; glBegin(GL_QUADS); - glVertex2f(bbox->orig.x, bbox->orig.y); - glVertex2f(bbox->orig.x, bbox->corner.y); - glVertex2f(bbox->corner.x, bbox->corner.y); - glVertex2f(bbox->corner.x, bbox->orig.y); + glVertex2d(bbox->orig.x, bbox->orig.y); + glVertex2d(bbox->orig.x, bbox->corner.y); + glVertex2d(bbox->corner.x, bbox->corner.y); + glVertex2d(bbox->corner.x, bbox->orig.y); glEnd(); } #endif +#ifdef GL static void -RenderField(WidgetInfo *wi, +RenderField(ZnWInfo *wi, Field fptr, ZnBBox *bbox, ZnBBox *pm_bbox, @@ -1992,11 +2005,11 @@ RenderField(WidgetInfo *wi, int sel_start, int sel_stop) { -#ifdef GLX - int j, alpha, num_bytes; + unsigned short alpha; + unsigned int j, num_bytes; XColor *color; ZnReal xs; - TextInfo *ti = &wi->text_info; + ZnTextInfo *ti = &wi->text_info; /* * Draw the background. @@ -2004,7 +2017,7 @@ RenderField(WidgetInfo *wi, if (ISSET(fptr->flags, FILLED_BIT)) { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); if (!ZnGradientFlat(fptr->fill_color)) { -#if 0 /* TODO_GLX Faire le dégradé dans le fond des champs. */ +#if 0 /* TODO_GL Faire le dégradé dans le fond des champs. */ int type = fptr->fill_color->type; ZnBool fast = (type == ZN_AXIAL_GRADIENT) && !fptr->grad_geo; @@ -2024,7 +2037,7 @@ RenderField(WidgetInfo *wi, * Setup polygon stippling. */ glEnable(GL_POLYGON_STIPPLE); - glPolygonStipple(ZnImagePattern(fptr->fill_pattern, NULL)); + glPolygonStipple(ZnImageMask(fptr->fill_pattern, NULL)); } color = ZnGetGradientColor(fptr->fill_color, 0.0, &alpha); alpha = ZnComposeAlpha(alpha, wi->alpha); @@ -2059,38 +2072,38 @@ RenderField(WidgetInfo *wi, if (fptr->tfi) { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); if (sel_start >= 0) { - color = ZnGetGradientColor(ti->sel_color, 0, &alpha); + color = ZnGetGradientColor(ti->sel_color, 0.0, &alpha); alpha = ZnComposeAlpha(alpha, wi->alpha); glColor4us(color->red, color->green, color->blue, alpha); glBegin(GL_QUADS); - glVertex2f(text_bbox->orig.x+sel_start, text_bbox->orig.y); - glVertex2f(text_bbox->orig.x+sel_stop, text_bbox->orig.y); - glVertex2f(text_bbox->orig.x+sel_stop, text_bbox->corner.y); - glVertex2f(text_bbox->orig.x+sel_start, text_bbox->corner.y); + glVertex2d(text_bbox->orig.x+sel_start, text_bbox->orig.y); + glVertex2d(text_bbox->orig.x+sel_stop, text_bbox->orig.y); + glVertex2d(text_bbox->orig.x+sel_stop, text_bbox->corner.y); + glVertex2d(text_bbox->orig.x+sel_start, text_bbox->corner.y); glEnd(); } glEnable(GL_TEXTURE_2D); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - color = ZnGetGradientColor(fptr->color, 0, &alpha); + color = ZnGetGradientColor(fptr->color, 0.0, &alpha); alpha = ZnComposeAlpha(alpha, wi->alpha); glColor4us(color->red, color->green, color->blue, alpha); glBindTexture(GL_TEXTURE_2D, ZnTexFontTex(fptr->tfi)); glPushMatrix(); - glTranslatef(text_pos->x, text_pos->y, 0.0); + glTranslated(text_pos->x, text_pos->y, 0.0); ZnRenderString(fptr->tfi, fptr->text, num_bytes); glPopMatrix(); glDisable(GL_TEXTURE_2D); } } if (cursor >= 0) { - glLineWidth(ti->insert_width); - color = ZnGetGradientColor(ti->insert_color, 0, &alpha); + glLineWidth((GLfloat) ti->insert_width); + color = ZnGetGradientColor(ti->insert_color, 0.0, &alpha); alpha = ZnComposeAlpha(alpha, wi->alpha); glColor4us(color->red, color->green, color->blue, alpha); xs = text_bbox->orig.x + cursor; glBegin(GL_LINES); - glVertex2f(xs, text_bbox->orig.y); - glVertex2f(xs, text_bbox->corner.y); + glVertex2d(xs, text_bbox->orig.y); + glVertex2d(xs, text_bbox->corner.y); glEnd(); } } @@ -2099,7 +2112,7 @@ RenderField(WidgetInfo *wi, /* * Draw the border relief. */ - if ((fptr->relief != RELIEF_FLAT) && (fptr->relief_thickness > 1)) { + if ((fptr->relief != ZN_RELIEF_FLAT) && (fptr->relief_thickness > 1)) { ZnPoint p[5]; p[0].x = bbox->orig.x; @@ -2118,44 +2131,57 @@ RenderField(WidgetInfo *wi, /* * Draw the border line. */ - if (fptr->border_edges != NO_BORDER) { - color = ZnGetGradientColor(fptr->border_color, 0, &alpha); + if (fptr->border_edges != ZN_NO_BORDER) { + color = ZnGetGradientColor(fptr->border_color, 0.0, &alpha); alpha = ZnComposeAlpha(alpha, wi->alpha); glColor4us(color->red, color->green, color->blue, alpha); glLineWidth(1.5); - ZnSetLineStyle(wi, LINE_SIMPLE); + ZnSetLineStyle(wi, ZN_LINE_SIMPLE); glBegin(GL_LINES); - if (fptr->border_edges & LEFT_BORDER) { - glVertex2f(bbox->orig.x, bbox->orig.y); - glVertex2f(bbox->orig.x, bbox->corner.y); + if (fptr->border_edges & ZN_LEFT_BORDER) { + glVertex2d(bbox->orig.x, bbox->orig.y); + glVertex2d(bbox->orig.x, bbox->corner.y); } - if (fptr->border_edges & RIGHT_BORDER) { - glVertex2f(bbox->corner.x, bbox->orig.y); - glVertex2f(bbox->corner.x, bbox->corner.y); + if (fptr->border_edges & ZN_RIGHT_BORDER) { + glVertex2d(bbox->corner.x, bbox->orig.y); + glVertex2d(bbox->corner.x, bbox->corner.y); } - if (fptr->border_edges & TOP_BORDER) { - glVertex2f(bbox->orig.x, bbox->orig.y); - glVertex2f(bbox->corner.x, bbox->orig.y); + if (fptr->border_edges & ZN_TOP_BORDER) { + glVertex2d(bbox->orig.x, bbox->orig.y); + glVertex2d(bbox->corner.x, bbox->orig.y); } - if (fptr->border_edges & BOTTOM_BORDER) { - glVertex2f(bbox->orig.x, bbox->corner.y); - glVertex2f(bbox->corner.x, bbox->corner.y); + if (fptr->border_edges & ZN_BOTTOM_BORDER) { + glVertex2d(bbox->orig.x, bbox->corner.y); + glVertex2d(bbox->corner.x, bbox->corner.y); } - if (fptr->border_edges & OBLIQUE) { - glVertex2f(bbox->orig.x, bbox->orig.y); - glVertex2f(bbox->corner.x, bbox->corner.y); + if (fptr->border_edges & ZN_OBLIQUE) { + glVertex2d(bbox->orig.x, bbox->orig.y); + glVertex2d(bbox->corner.x, bbox->corner.y); } - if (fptr->border_edges & COUNTER_OBLIQUE) { - glVertex2f(bbox->orig.x, bbox->corner.y); - glVertex2f(bbox->corner.x, bbox->orig.y); + if (fptr->border_edges & ZN_COUNTER_OBLIQUE) { + glVertex2d(bbox->orig.x, bbox->corner.y); + glVertex2d(bbox->corner.x, bbox->orig.y); } glEnd(); } -#endif } +#else +static void +RenderField(ZnWInfo *wi __unused, + Field fptr __unused, + ZnBBox *bbox __unused, + ZnBBox *pm_bbox __unused, + ZnPoint *text_pos __unused, + ZnBBox *text_bbox __unused, + int cursor __unused, + int sel_start __unused, + int sel_stop __unused) +{ +} +#endif static void -RenderFields(FieldSet field_set) +RenderFields(ZnFieldSet field_set) { FieldsEngine(field_set, RenderField); } @@ -2169,10 +2195,10 @@ RenderFields(FieldSet field_set) ********************************************************************************** */ static ZnBool -IsFieldSensitive(FieldSet field_set, +IsFieldSensitive(ZnFieldSet field_set, int part) { - if ((part >= 0) && (part < field_set->num_fields)) { + if ((part >= 0) && ((unsigned int) part < field_set->num_fields)) { return ISSET(field_set->fields[part].flags, FIELD_SENSITIVE_BIT); } else { @@ -2196,21 +2222,22 @@ IsFieldSensitive(FieldSet field_set, ********************************************************************************** */ static double -FieldsPick(FieldSet field_set, +FieldsPick(ZnFieldSet field_set, ZnPoint *p, int *part) { Field fptr; ZnBBox bbox; - int i, best_field = 0; - double new_dist, dist = 1e40; + unsigned int best_field = 0; + int i; + ZnReal new_dist, dist = 1e40; if (!field_set->num_fields) { return dist; } if (field_set->label_format) { - for (i = LabelFormatNumFields(field_set->label_format)-1; i >= 0; i--) { + for (i = ZnLFNumFields(field_set->label_format)-1; i >= 0; i--) { fptr = &field_set->fields[i]; if (ISCLEAR(fptr->flags, FIELD_VISIBLE_BIT) && @@ -2218,9 +2245,9 @@ FieldsPick(FieldSet field_set, continue; } - GetFieldBBox(field_set, i, &bbox); + GetFieldBBox(field_set, (unsigned int) i, &bbox); - new_dist = RectangleToPointDist(&bbox, p); + new_dist = ZnRectangleToPointDist(&bbox, p); if (new_dist < dist) { dist = new_dist; best_field = i; @@ -2248,20 +2275,19 @@ FieldsPick(FieldSet field_set, ********************************************************************************** */ static int -FieldsToArea(FieldSet field_set, +FieldsToArea(ZnFieldSet field_set, ZnBBox *area) { Field fptr; ZnBBox bbox; - int inside = -1; - int i; + int i, inside = -1; ZnBool first_done = False; if (!field_set->num_fields) { return inside; } - for (i = LabelFormatNumFields(field_set->label_format)-1; i >= 0; i--) { + for (i = ZnLFNumFields(field_set->label_format)-1; i >= 0; i--) { fptr = &field_set->fields[i]; if (ISCLEAR(fptr->flags, FIELD_VISIBLE_BIT) && @@ -2269,16 +2295,16 @@ FieldsToArea(FieldSet field_set, continue; } - GetFieldBBox(field_set, i, &bbox); + GetFieldBBox(field_set, (unsigned int) i, &bbox); if (!first_done) { first_done = True; - inside = BBoxInBBox(&bbox, area); + inside = ZnBBoxInBBox(&bbox, area); if (inside == 0) { return 0; } } else { - if (BBoxInBBox(&bbox, area) != inside) { + if (ZnBBoxInBBox(&bbox, area) != inside) { return 0; } } @@ -2296,16 +2322,16 @@ FieldsToArea(FieldSet field_set, ********************************************************************************** */ static void -SetFieldsAutoAlign(FieldSet fs, +SetFieldsAutoAlign(ZnFieldSet fs, int alignment) { - int i; + unsigned int i; Field field; if (!fs->num_fields) { return; } - if ((alignment >= AA_LEFT) && (alignment <= AA_RIGHT)) { + if ((alignment >= ZN_AA_LEFT) && (alignment <= ZN_AA_RIGHT)) { for (i = 0; i < fs->num_fields; i++) { field = &fs->fields[i]; if (field->auto_alignment.automatic) { @@ -2316,24 +2342,24 @@ SetFieldsAutoAlign(FieldSet fs, } static char * -GetFieldStruct(FieldSet fs, - int field) +GetFieldStruct(ZnFieldSet fs, + int field) { - if (field >= fs->num_fields) { + if ((unsigned int) field >= fs->num_fields) { return NULL; } return (char *) &fs->fields[field]; } -static int -NumFields(FieldSet fs) +static unsigned int +NumFields(ZnFieldSet fs) { return fs->num_fields; } -struct _FIELD FIELD = { +struct _ZnFIELD ZnFIELD = { field_attrs, InitFields, diff --git a/generic/Field.h b/generic/Field.h index 3b4e648..9d80e73 100644 --- a/generic/Field.h +++ b/generic/Field.h @@ -37,7 +37,8 @@ #include "Image.h" -struct _ItemStruct; +struct _ZnItemStruct; +struct _ZnAttrConfig; /* @@ -48,8 +49,8 @@ struct _ItemStruct; * should use the methods in FIELD. * */ -typedef struct _FieldSetStruct { - struct _ItemStruct *item; +typedef struct _ZnFieldSetStruct { + struct _ZnItemStruct *item; ZnLabelFormat label_format; unsigned int num_fields; struct _FieldStruct *fields; @@ -57,39 +58,38 @@ typedef struct _FieldSetStruct { ZnDim label_height; /* 2 only with GetLabelBBox. -1 means * not up to date. */ ZnPoint label_pos; /* Describe the label origin. */ -} FieldSetStruct, *FieldSet; +} ZnFieldSetStruct, *ZnFieldSet; +extern struct _ZnFIELD { + struct _ZnAttrConfig *attr_desc; -extern struct _FIELD { - ZnAttrConfig *attr_desc; - - void (*InitFields)(FieldSet fs); - void (*CloneFields)(FieldSet fs); - void (*FreeFields)(FieldSet fs); - int (*ConfigureField)(FieldSet fs, int field, int argc, Tcl_Obj *CONST argv[], int *flags); - int (*QueryField)(FieldSet fs, int field, int argc, Tcl_Obj *CONST argv[]); - void (*DrawFields)(FieldSet fs); - void (*RenderFields)(FieldSet fs); - int (*FieldsToArea)(FieldSet fs, ZnBBox *area); - ZnBool (*IsFieldSensitive)(FieldSet fs, int part); - double (*FieldsPick)(FieldSet fs, ZnPoint *p, int *part); - int (*FieldIndex)(FieldSet fs, int field, Tcl_Obj *index_spec, int *index); - ZnBool (*FieldInsertChars)(FieldSet fs, int field, int *index, char *chars); - ZnBool (*FieldDeleteChars)(FieldSet fs, int field, + void (*InitFields)(ZnFieldSet fs); + void (*CloneFields)(ZnFieldSet fs); + void (*FreeFields)(ZnFieldSet fs); + int (*ConfigureField)(ZnFieldSet fs, int field, int argc, Tcl_Obj *CONST argv[], int *flags); + int (*QueryField)(ZnFieldSet fs, int field, int argc, Tcl_Obj *CONST argv[]); + void (*DrawFields)(ZnFieldSet fs); + void (*RenderFields)(ZnFieldSet fs); + int (*FieldsToArea)(ZnFieldSet fs, ZnBBox *area); + ZnBool (*IsFieldSensitive)(ZnFieldSet fs, int part); + double (*FieldsPick)(ZnFieldSet fs, ZnPoint *p, int *part); + int (*FieldIndex)(ZnFieldSet fs, int field, Tcl_Obj *index_spec, int *index); + ZnBool (*FieldInsertChars)(ZnFieldSet fs, int field, int *index, char *chars); + ZnBool (*FieldDeleteChars)(ZnFieldSet fs, int field, int *first, int *last); - void (*FieldCursor)(FieldSet fs, int field, int index); - int (*FieldSelection)(FieldSet fs, int field, int offset, + void (*FieldCursor)(ZnFieldSet fs, int field, int index); + int (*FieldSelection)(ZnFieldSet fs, int field, int offset, char *chars, int max_chars); - void (*LeaderToLabel)(FieldSet fs, ZnPoint *start, ZnPoint *end); - void (*GetLabelBBox)(FieldSet fs, ZnDim *w, ZnDim *h); - void (*GetFieldBBox)(FieldSet fs, unsigned int index, + void (*LeaderToLabel)(ZnFieldSet fs, ZnPoint *start, ZnPoint *end); + void (*GetLabelBBox)(ZnFieldSet fs, ZnDim *w, ZnDim *h); + void (*GetFieldBBox)(ZnFieldSet fs, unsigned int index, ZnBBox *field_bbox); - void (*SetFieldsAutoAlign)(FieldSet fs, int alignment); - void (*ClearFieldCache)(FieldSet fs, int field); - char *(*GetFieldStruct)(FieldSet fs, int field); - int (*NumFields)(FieldSet fs); -} FIELD; + void (*SetFieldsAutoAlign)(ZnFieldSet fs, int alignment); + void (*ClearFieldCache)(ZnFieldSet fs, int field); + char *(*GetFieldStruct)(ZnFieldSet fs, int field); + unsigned int (*NumFields)(ZnFieldSet fs); +} ZnFIELD; #endif /* _Field_h */ diff --git a/generic/Geo.c b/generic/Geo.c index 7efab22..d1b89af 100644 --- a/generic/Geo.c +++ b/generic/Geo.c @@ -35,7 +35,6 @@ #include "WidgetInfo.h" #include -#include static const char rcsid[] = "$Id$"; @@ -43,17 +42,17 @@ static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ " void -POLY_INIT(ZnPoly *poly) +ZnPolyInit(ZnPoly *poly) { poly->num_contours = 0; poly->contours = NULL; } void -POLY_CONTOUR1(ZnPoly *poly, - ZnPoint *pts, - int num_pts, - ZnBool cw) +ZnPolyContour1(ZnPoly *poly, + ZnPoint *pts, + unsigned int num_pts, + ZnBool cw) { poly->num_contours = 1; poly->contours = &poly->contour1; @@ -63,13 +62,13 @@ POLY_CONTOUR1(ZnPoly *poly, } void -POLY_SET(ZnPoly *poly1, - ZnPoly *poly2) +ZnPolySet(ZnPoly *poly1, + ZnPoly *poly2) { - POLY_FREE(poly1); + ZnPolyFree(poly1); if (poly2->num_contours == 1) { - POLY_CONTOUR1(poly1, poly2->contours[0].points, poly2->contours[0].num_points, - poly2->contours[0].cw); + ZnPolyContour1(poly1, poly2->contours[0].points, poly2->contours[0].num_points, + poly2->contours[0].cw); if (poly2->contours != &poly2->contour1) { ZnFree(poly2->contours); } @@ -81,10 +80,10 @@ POLY_SET(ZnPoly *poly1, } void -POLY_FREE(ZnPoly *poly) +ZnPolyFree(ZnPoly *poly) { if (poly->num_contours) { - int i; + unsigned int i; for (i = 0; i < poly->num_contours; i++) { ZnFree(poly->contours[i].points); } @@ -98,10 +97,10 @@ POLY_FREE(ZnPoly *poly) } void -TRI_STRIP1(ZnTriStrip *tristrip, - ZnPoint *pts, - int num_pts, - ZnBool fan) +ZnTriStrip1(ZnTriStrip *tristrip, + ZnPoint *pts, + unsigned int num_pts, + ZnBool fan) { tristrip->num_strips = 1; tristrip->strips = &tristrip->strip1; @@ -111,10 +110,10 @@ TRI_STRIP1(ZnTriStrip *tristrip, } void -TRI_FREE(ZnTriStrip *tristrip) +ZnTriFree(ZnTriStrip *tristrip) { if (tristrip->num_strips) { - int i; + unsigned int i; for (i = 0; i < tristrip->num_strips; i++) { ZnFree(tristrip->strips[i].points); } @@ -132,45 +131,45 @@ TRI_FREE(ZnTriStrip *tristrip) * by position, anchor, width and height. */ void -Anchor2Origin(ZnPoint *position, - ZnDim width, - ZnDim height, - ZnAnchor anchor, - ZnPoint *origin) +ZnAnchor2Origin(ZnPoint *position, + ZnDim width, + ZnDim height, + Tk_Anchor anchor, + ZnPoint *origin) { switch (anchor) { - case ZnAnchorCenter: + case TK_ANCHOR_CENTER: origin->x = position->x - width/2; origin->y = position->y - height/2; break; - case ZnAnchorNW: + case TK_ANCHOR_NW: *origin = *position; break; - case ZnAnchorN: + case TK_ANCHOR_N: origin->x = position->x - width/2; origin->y = position->y; break; - case ZnAnchorNE: + case TK_ANCHOR_NE: origin->x = position->x - width; origin->y = position->y; break; - case ZnAnchorE: + case TK_ANCHOR_E: origin->x = position->x - width; origin->y = position->y - height/2; break; - case ZnAnchorSE: + case TK_ANCHOR_SE: origin->x = position->x - width; origin->y = position->y - height; break; - case ZnAnchorS: + case TK_ANCHOR_S: origin->x = position->x - width/2; origin->y = position->y - height; break; - case ZnAnchorSW: + case TK_ANCHOR_SW: origin->x = position->x; origin->y = position->y - height; break; - case ZnAnchorW: + case TK_ANCHOR_W: origin->x = position->x; origin->y = position->y - height/2; break; @@ -183,45 +182,45 @@ Anchor2Origin(ZnPoint *position, * height and the anchor. */ void -Origin2Anchor(ZnPoint *origin, - ZnDim width, - ZnDim height, - ZnAnchor anchor, - ZnPoint *position) +ZnOrigin2Anchor(ZnPoint *origin, + ZnDim width, + ZnDim height, + Tk_Anchor anchor, + ZnPoint *position) { switch (anchor) { - case ZnAnchorCenter: + case TK_ANCHOR_CENTER: position->x = origin->x + width/2; position->y = origin->y + height/2; break; - case ZnAnchorNW: + case TK_ANCHOR_NW: *position = *origin; break; - case ZnAnchorN: + case TK_ANCHOR_N: position->x = origin->x + width/2; position->y = origin->y; break; - case ZnAnchorNE: + case TK_ANCHOR_NE: position->x = origin->x + width; position->y = origin->y; break; - case ZnAnchorE: + case TK_ANCHOR_E: position->x = origin->x + width; position->y = origin->y + height/2; break; - case ZnAnchorSE: + case TK_ANCHOR_SE: position->x = origin->x + width; position->y = origin->y + height; break; - case ZnAnchorS: + case TK_ANCHOR_S: position->x = origin->x + width/2; position->y = origin->y + height; break; - case ZnAnchorSW: + case TK_ANCHOR_SW: position->x = origin->x; position->y = origin->y + height; break; - case ZnAnchorW: + case TK_ANCHOR_W: position->x = origin->x; position->y = origin->y + height/2; break; @@ -230,27 +229,27 @@ Origin2Anchor(ZnPoint *origin, void -BBox2XRect(ZnBBox *bbox, - XRectangle *r) +ZnBBox2XRect(ZnBBox *bbox, + XRectangle *r) { - r->x = REAL_TO_INT(bbox->orig.x); - r->y = REAL_TO_INT(bbox->orig.y); - r->width = REAL_TO_INT(bbox->corner.x) - r->x; - r->height = REAL_TO_INT(bbox->corner.y) - r->y; + r->x = ZnNearestInt(bbox->orig.x); + r->y = ZnNearestInt(bbox->orig.y); + r->width = ZnNearestInt(bbox->corner.x) - r->x; + r->height = ZnNearestInt(bbox->corner.y) - r->y; } void -GetStringBBox(char *str, - ZnFont font, - ZnPos x, - ZnPos y, - ZnBBox *str_bbox) +ZnGetStringBBox(char *str, + Tk_Font font, + ZnPos x, + ZnPos y, + ZnBBox *str_bbox) { Tk_FontMetrics fm; str_bbox->orig.x = x; - str_bbox->corner.x = x + ZnTextWidth(font, str, strlen(str)); + str_bbox->corner.x = x + Tk_TextWidth(font, str, (int) strlen(str)); Tk_GetFontMetrics(font, &fm); str_bbox->orig.y = y - fm.ascent; str_bbox->corner.y = str_bbox->orig.y + fm.ascent + fm.descent; @@ -258,7 +257,7 @@ GetStringBBox(char *str, void -ResetBBox(ZnBBox *bbox) +ZnResetBBox(ZnBBox *bbox) { bbox->orig.x = bbox->orig.y = 0; bbox->corner = bbox->orig; @@ -266,8 +265,8 @@ ResetBBox(ZnBBox *bbox) void -CopyBBox(ZnBBox *bbox_from, - ZnBBox *bbox_to) +ZnCopyBBox(ZnBBox *bbox_from, + ZnBBox *bbox_to) { bbox_to->orig = bbox_from->orig; bbox_to->corner = bbox_from->corner; @@ -275,15 +274,15 @@ CopyBBox(ZnBBox *bbox_from, void -IntersectBBox(ZnBBox *bbox1, - ZnBBox *bbox2, - ZnBBox *bbox_inter) +ZnIntersectBBox(ZnBBox *bbox1, + ZnBBox *bbox2, + ZnBBox *bbox_inter) { if ((bbox1->corner.x < bbox2->orig.x) || (bbox1->corner.y < bbox2->orig.y) || (bbox2->corner.x < bbox1->orig.x) || (bbox2->corner.y < bbox1->orig.y)) { - ResetBBox(bbox_inter); + ZnResetBBox(bbox_inter); } else { bbox_inter->orig.x = MAX(bbox1->orig.x, bbox2->orig.x); @@ -295,21 +294,21 @@ IntersectBBox(ZnBBox *bbox1, ZnBool -IsEmptyBBox(ZnBBox *bbox) +ZnIsEmptyBBox(ZnBBox *bbox) { return (bbox->orig.x >= bbox->corner.x) || (bbox->orig.y >= bbox->corner.y); } void -AddBBoxToBBox(ZnBBox *bbox, - ZnBBox *bbox2) +ZnAddBBoxToBBox(ZnBBox *bbox, + ZnBBox *bbox2) { - if (IsEmptyBBox(bbox2)) { + if (ZnIsEmptyBBox(bbox2)) { return; } - if (IsEmptyBBox(bbox)) { - CopyBBox(bbox2, bbox); + if (ZnIsEmptyBBox(bbox)) { + ZnCopyBBox(bbox2, bbox); } else { bbox->orig.x = MIN(bbox->orig.x, bbox2->orig.x); @@ -321,11 +320,11 @@ AddBBoxToBBox(ZnBBox *bbox, void -AddPointToBBox(ZnBBox *bbox, - ZnPos px, - ZnPos py) +ZnAddPointToBBox(ZnBBox *bbox, + ZnPos px, + ZnPos py) { - if (IsEmptyBBox(bbox)) { + if (ZnIsEmptyBBox(bbox)) { bbox->orig.x = px; bbox->orig.y = py; bbox->corner.x = bbox->orig.x + 1; @@ -341,11 +340,11 @@ AddPointToBBox(ZnBBox *bbox, void -AddPointsToBBox(ZnBBox *bbox, - ZnPoint *points, - int num_points) +ZnAddPointsToBBox(ZnBBox *bbox, + ZnPoint *points, + unsigned int num_points) { - int x1, y1, x2, y2, cur; + ZnReal x1, y1, x2, y2, cur; if (points == NULL) { return; @@ -355,7 +354,7 @@ AddPointsToBBox(ZnBBox *bbox, return; } - if (IsEmptyBBox(bbox)) { + if (ZnIsEmptyBBox(bbox)) { x1 = points->x; y1 = points->y; x2 = x1 + 1; @@ -394,22 +393,22 @@ AddPointsToBBox(ZnBBox *bbox, void -AddStringToBBox(ZnBBox *bbox, - char *str, - ZnFont font, - ZnPos cx, - ZnPos cy) +ZnAddStringToBBox(ZnBBox *bbox, + char *str, + Tk_Font font, + ZnPos cx, + ZnPos cy) { ZnBBox str_bbox; - GetStringBBox(str, font, cx, cy, &str_bbox); - AddBBoxToBBox(bbox, &str_bbox); + ZnGetStringBBox(str, font, cx, cy, &str_bbox); + ZnAddBBoxToBBox(bbox, &str_bbox); } ZnBool -PointInBBox(ZnBBox *bbox, - ZnPos x, - ZnPos y) +ZnPointInBBox(ZnBBox *bbox, + ZnPos x, + ZnPos y) { return ((x >= bbox->orig.x) && (x < bbox->corner.x) && (y >= bbox->orig.y) && (y < bbox->corner.y)); @@ -422,8 +421,8 @@ PointInBBox(ZnBBox *bbox, * 1 if it is entirely inside and 0 otherwise. */ int -BBoxInBBox(ZnBBox *bbox1, - ZnBBox *bbox2) +ZnBBoxInBBox(ZnBBox *bbox1, + ZnBBox *bbox2) { if ((bbox1->corner.x <= bbox2->orig.x) || (bbox1->orig.x >= bbox2->corner.x) || @@ -446,12 +445,12 @@ BBoxInBBox(ZnBBox *bbox1, * if it is entirely inside and 0 otherwise. */ int -LineInBBox(ZnPoint *p1, - ZnPoint *p2, - ZnBBox *bbox) +ZnLineInBBox(ZnPoint *p1, + ZnPoint *p2, + ZnBBox *bbox) { - ZnBool p1_inside = PointInBBox(bbox, p1->x, p1->y); - ZnBool p2_inside = PointInBBox(bbox, p2->x, p2->y); + ZnBool p1_inside = ZnPointInBBox(bbox, p1->x, p1->y); + ZnBool p2_inside = ZnPointInBBox(bbox, p2->x, p2->y); if (p1_inside != p2_inside) { return 0; @@ -482,10 +481,10 @@ LineInBBox(ZnPoint *p1, } /* Diagonal, do it the hard way. */ else { - double slope = ((double) p2->y - p1->y) / ((double) p2->x - p1->x); - int low, high, x, y; - int bbox_width = bbox->corner.x - bbox->orig.x; - int bbox_height = bbox->corner.y - bbox->orig.y; + ZnReal slope = (p2->y - p1->y) / (p2->x - p1->x); + ZnDim low, high, x, y; + ZnDim bbox_width = bbox->corner.x - bbox->orig.x; + ZnDim bbox_height = bbox->corner.y - bbox->orig.y; /* Check against left edge */ if (p1->x < p2->x) { @@ -535,12 +534,12 @@ LineInBBox(ZnPoint *p1, ZnBool -TestCCW(ZnPoint *points, - int num_points) +ZnTestCCW(ZnPoint *points, + unsigned int num_points) { ZnPoint *p, *p_p=NULL, *p_n=NULL, min; ZnReal xprod; - int i, min_index; + unsigned int i, min_index; if (num_points < 3) { return True; @@ -591,7 +590,7 @@ TestCCW(ZnPoint *points, /* - * ShiftLine -- + * ZnShiftLine -- * Given two points describing a line and a distance, return * to points describing a line parallel to it at the given distance. * When looking the line from p1 to p2 the new line will be dist away @@ -599,11 +598,11 @@ TestCCW(ZnPoint *points, * on the right. */ void -ShiftLine(ZnPoint *p1, - ZnPoint *p2, - ZnReal dist, - ZnPoint *p3, - ZnPoint *p4) +ZnShiftLine(ZnPoint *p1, + ZnPoint *p2, + ZnReal dist, + ZnPoint *p3, + ZnPoint *p4) { static int shift_table[129]; ZnBool dx_neg, dy_neg; @@ -624,8 +623,8 @@ ShiftLine(ZnPoint *p1, } *p3 = *p1; - dx = p2->x - p1->x; - dy = p2->y - p1->y; + dx = (int) (p2->x - p1->x); + dy = (int) (p2->y - p1->y); if (dx < 0) { dx = -dx; dx_neg = True; @@ -646,14 +645,14 @@ ShiftLine(ZnPoint *p1, } if (dy <= dx) { - dy = ((dist * shift_table[(dy*128)/dx]) + 64) / 128; + dy = (((int) dist * shift_table[(dy*128)/dx]) + 64) / 128; if (!dx_neg) { dy = -dy; } p3->y += dy; } else { - dx = ((dist * shift_table[(dx*128)/dy]) + 64) / 128; + dx = (((int) dist * shift_table[(dx*128)/dy]) + 64) / 128; if (dy_neg) { dx = -dx; } @@ -672,11 +671,11 @@ ShiftLine(ZnPoint *p1, * otherwise. */ ZnBool -IntersectLines(ZnPoint *a1, - ZnPoint *a2, - ZnPoint *b1, - ZnPoint *b2, - ZnPoint *pi) +ZnIntersectLines(ZnPoint *a1, + ZnPoint *a2, + ZnPoint *b1, + ZnPoint *b2, + ZnPoint *pi) { ZnReal dxadyb, dxbdya, dxadxb, dyadyb, p, q; @@ -727,14 +726,14 @@ IntersectLines(ZnPoint *a1, */ /**** A FINIR ****/ void -InsetPolygon(ZnPoint *p, - int num_points, - ZnDim inset) +ZnInsetPolygon(ZnPoint *p, + unsigned int num_points, + ZnDim inset) { ZnPoint *p1, *p2; ZnPoint new_p1, new_p2; /* ZnPoint shift1, shift2;*/ - int i, processed_points; + unsigned int i, processed_points; processed_points = 0; @@ -755,7 +754,7 @@ InsetPolygon(ZnPoint *p, continue; } - ShiftLine(p1, p2, inset, &new_p1, &new_p2); + ZnShiftLine(p1, p2, inset, &new_p1, &new_p2); if (processed_points >= 1) { } @@ -771,16 +770,16 @@ InsetPolygon(ZnPoint *p, * end is located around p2. */ void -GetButtPoints(ZnPoint *p1, - ZnPoint *p2, - int width, - ZnBool projecting, - ZnPoint *c1, - ZnPoint *c2) -{ - double w_2 = width/2.0; - double length = hypot(p2->x - p1->x, p2->y - p1->y); - double delta_x, delta_y; +ZnGetButtPoints(ZnPoint *p1, + ZnPoint *p2, + ZnDim width, + ZnBool projecting, + ZnPoint *c1, + ZnPoint *c2) +{ + ZnReal w_2 = width/2.0; + ZnDim length = hypot(p2->x - p1->x, p2->y - p1->y); + ZnReal delta_x, delta_y; if (length == 0.0) { c1->x = c2->x = p2->x; @@ -816,23 +815,23 @@ GetButtPoints(ZnPoint *p1, * Hmmm, the switch has been done but not the rounding ;-) */ ZnBool -GetMiterPoints(ZnPoint *p1, - ZnPoint *p2, - ZnPoint *p3, - int width, - ZnPoint *c1, - ZnPoint *c2) -{ - static double deg11 = (11.0*2.0*M_PI)/360.0; - double theta1; /* angle of p2-p1 segment. */ - double theta2; /* angle of p2-p3 segment. */ - double theta; /* angle of the joint */ - double theta3; /* angle of bisector of the joint toward +ZnGetMiterPoints(ZnPoint *p1, + ZnPoint *p2, + ZnPoint *p3, + ZnDim width, + ZnPoint *c1, + ZnPoint *c2) +{ + static ZnReal deg11 = (11.0*2.0*M_PI)/360.0; + ZnReal theta1; /* angle of p2-p1 segment. */ + ZnReal theta2; /* angle of p2-p3 segment. */ + ZnReal theta; /* angle of the joint */ + ZnReal theta3; /* angle of bisector of the joint toward * the external point of the joint. */ - double dist; /* distance of the external points + ZnReal dist; /* distance of the external points * of the corner from the mid point * p2. */ - double delta_x, delta_y; /* projection of (dist,theta3) on x + ZnReal delta_x, delta_y; /* projection of (dist,theta3) on x * and y. */ if (p2->y == p1->y) { @@ -899,14 +898,15 @@ GetMiterPoints(ZnPoint *p1, * can be: CapRound, CapButt, CapProjecting. */ int -PolylineInBBox(ZnPoint *points, - int num_points, - int width, - int cap_style, - int join_style, - ZnBBox *bbox) -{ - int count, inside = -1; +ZnPolylineInBBox(ZnPoint *points, + unsigned int num_points, + ZnDim width, + int cap_style, + int join_style, + ZnBBox *bbox) +{ + unsigned int count; + int inside = -1; ZnBool do_miter_as_bevel; ZnPoint poly[4]; @@ -934,7 +934,7 @@ PolylineInBBox(ZnPoint *points, */ if (((cap_style == CapRound) && (count == num_points)) || ((join_style == JoinRound) && (count != num_points))) { - if (OvalInBBox(points, width, width, bbox) != inside) { + if (ZnOvalInBBox(points, width, width, bbox) != inside) { return 0; } } @@ -947,8 +947,8 @@ PolylineInBBox(ZnPoint *points, * First vertex of the edge */ if (count == num_points) { - GetButtPoints(&points[1], points, width, - cap_style == CapProjecting, poly, &poly[1]); + ZnGetButtPoints(&points[1], points, width, + cap_style == CapProjecting, poly, &poly[1]); } /* * Here we are at a joint starting a new edge. If the @@ -961,7 +961,7 @@ PolylineInBBox(ZnPoint *points, poly[1] = poly[2]; } else { - GetButtPoints(&points[1], points, width, 0, poly, &poly[1]); + ZnGetButtPoints(&points[1], points, width, 0, poly, &poly[1]); /* * If the previous joint was beveled (or considered so), * check the polygon that fill the bevel. It has more or @@ -970,7 +970,7 @@ PolylineInBBox(ZnPoint *points, * poly[2]. */ if ((join_style == JoinBevel) || do_miter_as_bevel) { - if (PolygonInBBox(poly, 4, bbox, NULL) != inside) { + if (ZnPolygonInBBox(poly, 4, bbox, NULL) != inside) { return 0; } do_miter_as_bevel = False; @@ -981,21 +981,21 @@ PolylineInBBox(ZnPoint *points, * Opposite vertex of the edge. */ if (count == 2) { - GetButtPoints(points, &points[1], width, cap_style == CapProjecting, - &poly[2], &poly[3]); + ZnGetButtPoints(points, &points[1], width, cap_style == CapProjecting, + &poly[2], &poly[3]); } else if (join_style == JoinMiter) { - if (GetMiterPoints(points, &points[1], &points[2], width, + if (ZnGetMiterPoints(points, &points[1], &points[2], width, &poly[2], &poly[3]) == False) { do_miter_as_bevel = True; - GetButtPoints(points, &points[1], width, 0, &poly[2], &poly[3]); + ZnGetButtPoints(points, &points[1], width, 0, &poly[2], &poly[3]); } } else { - GetButtPoints(points, &points[1], width, 0, &poly[2], &poly[3]); + ZnGetButtPoints(points, &points[1], width, 0, &poly[2], &poly[3]); } - if (PolygonInBBox(poly, 4, bbox, NULL) != inside) { + if (ZnPolygonInBBox(poly, 4, bbox, NULL) != inside) { return 0; } } @@ -1004,7 +1004,7 @@ PolylineInBBox(ZnPoint *points, * Test a circle around the last point if CapRound. */ if (cap_style == CapRound) { - if (OvalInBBox(points, width, width, bbox) != inside) { + if (ZnOvalInBBox(points, width, width, bbox) != inside) { return 0; } } @@ -1021,10 +1021,10 @@ PolylineInBBox(ZnPoint *points, * polygon or not. */ int -PolygonInBBox(ZnPoint *points, - int num_points, - ZnBBox *bbox, - ZnBool *area_enclosed) +ZnPolygonInBBox(ZnPoint *points, + unsigned int num_points, + ZnBBox *bbox, + ZnBool *area_enclosed) { int inside, count; ZnPoint *p, *head, *first, *second; @@ -1049,7 +1049,7 @@ PolygonInBBox(ZnPoint *points, /* * Get the status of the first edge. */ - inside = LineInBBox(&p[0], &p[1], bbox); + inside = ZnLineInBBox(&p[0], &p[1], bbox); p++; if (inside == 0) { return 0; @@ -1066,7 +1066,7 @@ PolygonInBBox(ZnPoint *points, second = &p[1]; } - if (LineInBBox(first, second, bbox) != inside) { + if (ZnLineInBBox(first, second, bbox) != inside) { return 0; } } @@ -1084,7 +1084,7 @@ PolygonInBBox(ZnPoint *points, /*printf("PolygonInBBox, np = %d, x = %g, y = %g, dist = %g\n", num_points, bbox->orig.x, bbox->orig.y, PolygonToPointDist(points, num_points, &bbox->orig));*/ - if (PolygonToPointDist(points, num_points, &bbox->orig) <= 0.0) { + if (ZnPolygonToPointDist(points, num_points, &bbox->orig) <= 0.0) { if (area_enclosed) { *area_enclosed = True; } @@ -1101,14 +1101,14 @@ PolygonInBBox(ZnPoint *points, * if it is entirely inside and 0 otherwise. */ int -OvalInBBox(ZnPoint *center, - int width, - int height, - ZnBBox *bbox) +ZnOvalInBBox(ZnPoint *center, + ZnDim width, + ZnDim height, + ZnBBox *bbox) { ZnPoint origin, corner; - int w_2, h_2; - double delta_x, delta_y; + ZnDim w_2, h_2; + ZnReal delta_x, delta_y; w_2 = (width+1)/2; h_2 = (height+1)/2; @@ -1207,12 +1207,12 @@ OvalInBBox(ZnPoint *center, * the result needs precision. */ ZnBool -PointInAngle(int start_angle, - int angle_extent, - ZnPoint *p) +ZnPointInAngle(int start_angle, + int angle_extent, + ZnPoint *p) { - double point_angle; - int angle_diff; + ZnReal point_angle; + int angle_diff; if ((p->x == 0) && (p->y == 0)) { point_angle = 0.0; @@ -1220,7 +1220,7 @@ PointInAngle(int start_angle, else { point_angle = atan2(p->y, p->x) * 180.0 / M_PI; } - angle_diff = (REAL_TO_INT(point_angle) - start_angle) % 360; + angle_diff = (ZnNearestInt(point_angle) - start_angle) % 360; if (angle_diff < 0) { angle_diff += 360; } @@ -1237,17 +1237,17 @@ PointInAngle(int start_angle, * */ void -PointPolarToCartesian(ZnReal heading, - int rho, - int theta, - ZnDim *delta_x, - ZnDim *delta_y) +ZnPointPolarToCartesian(ZnReal heading, + ZnReal rho, + ZnReal theta, + ZnReal *delta_x, + ZnReal *delta_y) { ZnReal to_angle; /* Compute angle in trigonometric system */ - /* to_angle = DegreesToRadian(theta) + heading - M_PI_2;*/ - to_angle = heading - DegreesToRadian(theta) - M_PI_2; + /* to_angle = ZnDegRad(theta) + heading - M_PI_2;*/ + to_angle = heading - ZnDegRad(theta) - M_PI_2; /* Compute cartesian coordinates */ *delta_x = rho * cos(to_angle); *delta_y = rho * sin(to_angle); @@ -1257,8 +1257,8 @@ PointPolarToCartesian(ZnReal heading, * Return a vector angle given its projections */ ZnReal -ProjectionToAngle(ZnDim dx, - ZnDim dy) +ZnProjectionToAngle(ZnReal dx, + ZnReal dy) { if (dx == 0) { if (dy < 0) { @@ -1272,10 +1272,10 @@ ProjectionToAngle(ZnDim dx, } } else if (dx < 0) { - return atan((double) dy / (double) dx) - M_PI; + return atan(dy / dx) - M_PI; } else { - return atan((double) dy / (double) dx); + return atan(dy / dx); } return 0.0; } @@ -1290,13 +1290,13 @@ ProjectionToAngle(ZnDim dx, * This arc is origin centered. */ ZnBool -HorizLineToArc(ZnReal x1, - ZnReal x2, - ZnReal y, - ZnReal rx, - ZnReal ry, - ZnReal start_angle, - ZnReal angle_extent) +ZnHorizLineToArc(ZnReal x1, + ZnReal x2, + ZnReal y, + ZnReal rx, + ZnReal ry, + int start_angle, + int angle_extent) { ZnReal tmp, x; ZnPoint t; @@ -1318,11 +1318,11 @@ HorizLineToArc(ZnReal x1, /* * Test both intersection points. */ - if ((x >= x1) && (x <= x2) && PointInAngle(start_angle, angle_extent, &t)) { + if ((x >= x1) && (x <= x2) && ZnPointInAngle((int) start_angle, (int) angle_extent, &t)) { return True; } t.x = -t.x; - if ((-x >= x1) && (-x <= x2) && PointInAngle(start_angle, angle_extent, &t)) { + if ((-x >= x1) && (-x <= x2) && ZnPointInAngle((int) start_angle, (int) angle_extent, &t)) { return True; } return False; @@ -1338,13 +1338,13 @@ HorizLineToArc(ZnReal x1, * This arc is origin centered. */ ZnBool -VertLineToArc(ZnReal x, - ZnReal y1, - ZnReal y2, - ZnReal rx, - ZnReal ry, - ZnReal start_angle, - ZnReal angle_extent) +ZnVertLineToArc(ZnReal x, + ZnReal y1, + ZnReal y2, + ZnReal rx, + ZnReal ry, + int start_angle, + int angle_extent) { ZnReal tmp, y; ZnPoint t; @@ -1366,11 +1366,11 @@ VertLineToArc(ZnReal x, /* * Test both intersection points. */ - if ((y > y1) && (y < y2) && PointInAngle(start_angle, angle_extent, &t)) { + if ((y > y1) && (y < y2) && ZnPointInAngle((int) start_angle, (int) angle_extent, &t)) { return True; } t.y = -t.y; - if ((-y > y1) && (-y < y2) && PointInAngle(start_angle, angle_extent, &t)) { + if ((-y > y1) && (-y < y2) && ZnPointInAngle((int) start_angle, (int) angle_extent, &t)) { return True; } return False; @@ -1382,24 +1382,24 @@ VertLineToArc(ZnReal x, * described by rect. Return negative values for points in * the rectangle. */ -double -RectangleToPointDist(ZnBBox *bbox, - ZnPoint *p) +ZnDim +ZnRectangleToPointDist(ZnBBox *bbox, + ZnPoint *p) { - double new_dist, dist; + ZnDim new_dist, dist; ZnPoint p1, p2; p1.x = bbox->orig.x; p1.y = p2.y = bbox->orig.y; p2.x = bbox->corner.x; - dist = LineToPointDist(&p1, &p2, p); + dist = ZnLineToPointDist(&p1, &p2, p); if (dist == 0.0) { return 0.0; } p1 = p2; p2.y = bbox->corner.y; - new_dist = LineToPointDist(&p1, &p2, p); + new_dist = ZnLineToPointDist(&p1, &p2, p); dist = MIN(dist, new_dist); if (dist == 0.0) { return 0.0; @@ -1407,7 +1407,7 @@ RectangleToPointDist(ZnBBox *bbox, p1 = p2; p2.x = bbox->orig.x; - new_dist = LineToPointDist(&p1, &p2, p); + new_dist = ZnLineToPointDist(&p1, &p2, p); dist = MIN(dist, new_dist); if (dist == 0.0) { return 0.0; @@ -1415,10 +1415,10 @@ RectangleToPointDist(ZnBBox *bbox, p1 = p2; p2.y = bbox->orig.y; - new_dist = LineToPointDist(&p1, &p2, p); + new_dist = ZnLineToPointDist(&p1, &p2, p); dist = MIN(dist, new_dist); - if (PointInBBox(bbox, p->x, p->y)) { + if (ZnPointInBBox(bbox, p->x, p->y)) { return -dist; } else { @@ -1431,13 +1431,13 @@ RectangleToPointDist(ZnBBox *bbox, * Return the distance of the given point to the line * described by , .. */ -double -LineToPointDist(ZnPoint *p1, - ZnPoint *p2, - ZnPoint *p) +ZnDim +ZnLineToPointDist(ZnPoint *p1, + ZnPoint *p2, + ZnPoint *p) { - double x, y; - double x_int, y_int; + ZnReal x, y; + ZnReal x_int, y_int; /* * First compute the closest point on the line. This is done @@ -1479,9 +1479,9 @@ LineToPointDist(ZnPoint *p1, * on the segment. */ else { - double a1, a2, b1, b2; + ZnReal a1, a2, b1, b2; - a1 = ((double) (p2->y - p1->y)) / ((double) (p2->x - p1->x)); + a1 = (p2->y - p1->y) / (p2->x - p1->x); b1 = p1->y - a1*p1->x; a2 = -1.0/a1; @@ -1522,16 +1522,16 @@ LineToPointDist(ZnPoint *p1, * points, to the given point. If the point is * inside return values are negative. */ -double -PolygonToPointDist(ZnPoint *points, - int num_points, - ZnPoint *p) +ZnDim +ZnPolygonToPointDist(ZnPoint *points, + unsigned int num_points, + ZnPoint *p) { - double best_distance; + ZnDim best_distance, dist; int intersections; int x_int, y_int; ZnPoint *first_point; - double x, y, dist; + ZnReal x, y; ZnPoint p1, p2; /* @@ -1576,12 +1576,12 @@ PolygonToPointDist(ZnPoint *points, if (p1.x == p2.x) { x = p1.x; if (p1.y >= p2.y) { - y_int = MIN(p1.y, p->y); - y_int = MAX(y_int, p2.y); + y_int = (int) MIN(p1.y, p->y); + y_int = (int) MAX(y_int, p2.y); } else { - y_int = MIN(p2.y, p->y); - y_int = MAX(y_int, p1.y); + y_int = (int) MIN(p2.y, p->y); + y_int = (int) MAX(y_int, p1.y); } y = y_int; } @@ -1590,15 +1590,15 @@ PolygonToPointDist(ZnPoint *points, else if (p1.y == p2.y) { y = p1.y; if (p1.x >= p2.x) { - x_int = MIN(p1.x, p->x); - x_int = MAX(x_int, p2.x); + x_int = (int) MIN(p1.x, p->x); + x_int = (int) MAX(x_int, p2.x); if ((p->y < y) && (p->x < p1.x) && (p->x >= p2.x)) { intersections++; } } else { - x_int = MIN(p2.x, p->x); - x_int = MAX(x_int, p1.x); + x_int = (int) MIN(p2.x, p->x); + x_int = (int) MAX(x_int, p1.x); if ((p->y < y) && (p->x < p2.x) && (p->x >= p1.x)) { intersections++; } @@ -1608,9 +1608,9 @@ PolygonToPointDist(ZnPoint *points, /* Other */ else { - double a1, b1, a2, b2; + ZnReal a1, b1, a2, b2; - a1 = ((double) (p2.y - p1.y)) / ((double) (p2.x - p1.x)); + a1 = (p2.y - p1.y) / (p2.x - p1.x); b1 = p1.y - a1 * p1.x; a2 = -1.0/a1; @@ -1679,19 +1679,19 @@ PolygonToPointDist(ZnPoint *points, * given point. Cap and Join parameters are considered * in the process. */ -double -PolylineToPointDist(ZnPoint *points, - int num_points, - int width, - int cap_style, - int join_style, - ZnPoint *p) +ZnDim +ZnPolylineToPointDist(ZnPoint *points, + unsigned int num_points, + ZnDim width, + int cap_style, + int join_style, + ZnPoint *p) { ZnBool miter2bevel = False; - int count; + unsigned int count; ZnPoint *ptr; ZnPoint outline[5]; - double dist, best_dist, h_width; + ZnDim dist, best_dist, h_width; best_dist = 1.0e36; h_width = width/2.0; @@ -1712,21 +1712,21 @@ PolylineToPointDist(ZnPoint *points, * Build the polygonal outline of the current edge. */ if (count == num_points) { - GetButtPoints(&ptr[1], ptr, width, cap_style==CapProjecting, outline, &outline[1]); + ZnGetButtPoints(&ptr[1], ptr, width, cap_style==CapProjecting, outline, &outline[1]); } else if ((join_style == JoinMiter) && !miter2bevel) { outline[0] = outline[3]; outline[1] = outline[2]; } else { - GetButtPoints(&ptr[1], ptr, width, 0, outline, &outline[1]); + ZnGetButtPoints(&ptr[1], ptr, width, 0, outline, &outline[1]); /* * If joints are beveled, check the distance to the polygon * that fills the joint. */ if ((join_style == JoinBevel) || miter2bevel) { outline[4] = outline[0]; - dist = PolygonToPointDist(outline, 5, p); + dist = ZnPolygonToPointDist(outline, 5, p); if (dist <= 0.0) { best_dist = 0.0; goto done; @@ -1738,27 +1738,27 @@ PolylineToPointDist(ZnPoint *points, } } if (count == 2) { - GetButtPoints(ptr, &ptr[1], width, cap_style==CapProjecting, - &outline[2], &outline[3]); + ZnGetButtPoints(ptr, &ptr[1], width, cap_style==CapProjecting, + &outline[2], &outline[3]); } else if (join_style == JoinMiter) { - if (GetMiterPoints(ptr, &ptr[1], &ptr[2], width, + if (ZnGetMiterPoints(ptr, &ptr[1], &ptr[2], width, &outline[2], &outline[3]) == False) { miter2bevel = True; - GetButtPoints(ptr, &ptr[1], width, 0, &outline[2], &outline[3]); + ZnGetButtPoints(ptr, &ptr[1], width, 0, &outline[2], &outline[3]); } /*printf("2=%g+%g, 3=%g+%g\n", outline[2].x, outline[2].y, outline[3].x, outline[3].y);*/ } else { - GetButtPoints(ptr, &ptr[1], width, 0, &outline[2], &outline[3]); + ZnGetButtPoints(ptr, &ptr[1], width, 0, &outline[2], &outline[3]); } outline[4] = outline[0]; /*printf("0=%g+%g, 1=%g+%g, 2=%g+%g, 3=%g+%g, 4=%g+%g\n", outline[0].x, outline[0].y, outline[1].x, outline[1].y, outline[2].x, outline[2].y, outline[3].x, outline[3].y, outline[4].x, outline[4].y);*/ - dist = PolygonToPointDist(outline, 5, p); + dist = ZnPolygonToPointDist(outline, 5, p); if (dist <= 0.0) { best_dist = 0.0; goto done; @@ -1794,18 +1794,18 @@ PolylineToPointDist(ZnPoint *points, * the thickness of its outline . Return values are negative * if the point is inside. */ -double -OvalToPointDist(ZnPoint *center, - int width, - int height, - unsigned int line_width, - ZnPoint *p) -{ - double x_delta, y_delta; - /* double x_diameter, y_diameter;*/ - double scaled_distance; - double distance_to_outline; - double distance_to_center; +ZnDim +ZnOvalToPointDist(ZnPoint *center, + ZnDim width, + ZnDim height, + ZnDim line_width, + ZnPoint *p) +{ + ZnReal x_delta, y_delta; + /* ZnReal x_diameter, y_diameter;*/ + ZnDim scaled_distance; + ZnDim distance_to_outline; + ZnDim distance_to_center; /* * Compute the distance from the point given to the center @@ -1844,9 +1844,9 @@ OvalToPointDist(ZnPoint *center, * very small number, take another method. */ if (width < height) - distance_to_outline = ((double) (width - line_width)) / 2; + distance_to_outline = (width - line_width) / 2; else - distance_to_outline = ((double) (height - line_width)) / 2; + distance_to_outline = (height - line_width) / 2; } if (distance_to_outline < 0.0) @@ -1976,7 +1976,7 @@ BezierSubdivide(ZnPoint *controls, /* ********************************************************************************** * - * GetBezierPoints -- + * ZnGetBezierPoints -- * Use recursive subdivision to approximate the curve. The subdivision stops * when the error is under eps. * This algorithm is adaptive, meaning that it computes the minimum number @@ -1985,18 +1985,18 @@ BezierSubdivide(ZnPoint *controls, ********************************************************************************** */ void -GetBezierPoints(ZnPoint *p1, - ZnPoint *c1, - ZnPoint *c2, - ZnPoint *p2, - ZnList to_points, - double eps) +ZnGetBezierPoints(ZnPoint *p1, + ZnPoint *c1, + ZnPoint *c2, + ZnPoint *p2, + ZnList to_points, + ZnReal eps) { ZnReal dist; - dist = LineToPointDist(p1, p2, c1); + dist = ZnLineToPointDist(p1, p2, c1); if ((dist < eps) && ((c1->x != c2->x) || (c1->y != c2->y))) { - dist = LineToPointDist(p1, p2, c2); + dist = ZnLineToPointDist(p1, p2, c2); } if (dist > eps) { @@ -2011,13 +2011,13 @@ GetBezierPoints(ZnPoint *p1, new_c1.y = (p1->y + c1->y) / 2.0; new_c2.x = (p1->x + 2*c1->x + c2->x) / 4.0; new_c2.y = (p1->y + 2*c1->y + c2->y) / 4.0; - GetBezierPoints(p1, &new_c1, &new_c2, &mid_segm, to_points, eps); + ZnGetBezierPoints(p1, &new_c1, &new_c2, &mid_segm, to_points, eps); new_c1.x = (c1->x + 2*c2->x + p2->x) / 4.0; new_c1.y = (c1->y + 2*c2->y + p2->y) / 4.0; new_c2.x = (c2->x + (p2->x)) / 2.0; new_c2.y = (c2->y + (p2->y)) / 2.0; - GetBezierPoints(&mid_segm, &new_c1, &new_c2, p2, to_points, eps); + ZnGetBezierPoints(&mid_segm, &new_c1, &new_c2, p2, to_points, eps); } else { /* @@ -2032,7 +2032,7 @@ GetBezierPoints(ZnPoint *p1, /* ********************************************************************************** * - * GetBezierPath -- + * ZnGetBezierPath -- * Compute in to_points a new set of points describing a Bezier path based * on the control points given in from_points. * If more than four points are given, the algorithm iterate over the @@ -2044,8 +2044,8 @@ GetBezierPoints(ZnPoint *p1, ********************************************************************************** */ void -GetBezierPath(ZnList from_points, - ZnList to_points) +ZnGetBezierPath(ZnList from_points, + ZnList to_points) { ZnPoint *fp; int num_fp, i; @@ -2061,7 +2061,7 @@ GetBezierPath(ZnList from_points, for (i = 0; i < num_fp; ) { if (i < (num_fp-3)) { - GetBezierPoints(fp, fp+1, fp+2, fp+3, to_points, 1.0); + ZnGetBezierPoints(fp, fp+1, fp+2, fp+3, to_points, 1.0); if (i < (num_fp-4)) { fp += 3; i += 3; @@ -2071,7 +2071,7 @@ GetBezierPath(ZnList from_points, } } else if (i == (num_fp-3)) { - GetBezierPoints(fp, fp+1, fp+1, fp+2, to_points, 1.0); + ZnGetBezierPoints(fp, fp+1, fp+1, fp+2, to_points, 1.0); break; } else if (i == (num_fp-2)) { @@ -2085,7 +2085,7 @@ GetBezierPath(ZnList from_points, /* ********************************************************************************** * - * GetCirclePoints -- + * ZnGetCirclePoints -- * Return a pointer to an array of points describing a * circle arc of radius 1.0. The arc is described by start_angle, * end_angle and the type: 0 for arc, 1 for chord, 2 for pie slice, @@ -2098,12 +2098,12 @@ GetBezierPath(ZnList from_points, ********************************************************************************** */ ZnPoint * -GetCirclePoints(int type, - int quality, - ZnReal start_angle, - ZnReal angle_extent, - int *num_points, - ZnList point_list) +ZnGetCirclePoints(int type, + int quality, + ZnReal start_angle, + ZnReal angle_extent, + unsigned int *num_points, + ZnList point_list) { static ZnPoint genarc_finest[] = { /* 64 */ {1.0, 0.0}, @@ -2251,7 +2251,7 @@ GetCirclePoints(int type, {0.809017043478, -0.587785184709}, {1.0, 0.0} }; - int num_p, i; + unsigned int num_p, i; ZnPoint *p, *p_from; ZnPoint center_p = { 0.0, 0.0 }; ZnPoint start_p, wp; @@ -2319,7 +2319,7 @@ GetCirclePoints(int type, start_p.x = cos(start_angle); start_p.y = sin(start_angle); ZnListAdd(point_list, &start_p, ZnListTail); - i = start_angle / iangle; + i = (unsigned int) (start_angle / iangle); if ((i * iangle) < start_angle) { i++; } @@ -2358,7 +2358,7 @@ GetCirclePoints(int type, /* ********************************************************************************** * - * GetArcPath -- + * ZnGetArcPath -- * Compute in to_points a set of Bezier control points describing an arc * path given the start angle, the stop angle and the type: 0 for arc, * 1 for chord, 2 for pie slice. @@ -2368,15 +2368,15 @@ GetCirclePoints(int type, * ********************************************************************************** */ -static double arc_nodes_x[4] = { 1.0, 0.0, -1.0, 0.0 }; -static double arc_nodes_y[4] = { 0.0, 1.0, 0.0, -1.0 }; -static double arc_controls_x[8] = { 1.0, 0.55197, -0.55197, -1.0, -1.0, -0.55197, 0.55197, 1.0 }; -static double arc_controls_y[8] = { 0.55197, 1.0, 1.0, 0.55197, -0.55197, -1.0, -1.0, -0.55197 }; +static ZnReal arc_nodes_x[4] = { 1.0, 0.0, -1.0, 0.0 }; +static ZnReal arc_nodes_y[4] = { 0.0, 1.0, 0.0, -1.0 }; +static ZnReal arc_controls_x[8] = { 1.0, 0.55197, -0.55197, -1.0, -1.0, -0.55197, 0.55197, 1.0 }; +static ZnReal arc_controls_y[8] = { 0.55197, 1.0, 1.0, 0.55197, -0.55197, -1.0, -1.0, -0.55197 }; void -GetArcPath(ZnReal start_angle, - ZnReal end_angle, - int type, - ZnList to_points) +ZnGetArcPath(ZnReal start_angle, + ZnReal end_angle, + int type, + ZnList to_points) { int start_quad, end_quad, quadrant; ZnPoint center_p = { 0.0, 0.0 }; @@ -2409,8 +2409,8 @@ GetArcPath(ZnReal start_angle, * Now 0 <= start_angle < 2 * M_PI and start_angle <= end_angle. */ - start_quad = start_angle / (M_PI / 2.0); - end_quad = end_angle / (M_PI / 2.0); + start_quad = (int) (start_angle / (M_PI / 2.0)); + end_quad = (int) (end_angle / (M_PI / 2.0)); for (quadrant = start_quad; quadrant <= end_quad; quadrant++) { ZnPoint controls[4]; @@ -2473,13 +2473,13 @@ GetArcPath(ZnReal start_angle, ********************************************************************************** */ void -SmoothPathWithBezier(ZnPoint *fp, - int num_fp, - ZnList to_points) +ZnSmoothPathWithBezier(ZnPoint *fp, + unsigned int num_fp, + ZnList to_points) { ZnBool closed; ZnPoint s[4]; - int i; + unsigned int i; /* * make sure the output vector is empty @@ -2502,7 +2502,7 @@ SmoothPathWithBezier(ZnPoint *fp, s[3].x = 0.5*fp[0].x + 0.5*fp[1].x; s[3].y = 0.5*fp[0].y + 0.5*fp[1].y; ZnListAdd(to_points, s, ZnListTail); - GetBezierPoints(s, s+1, s+2, s+3, to_points, 1.0); + ZnGetBezierPoints(s, s+1, s+2, s+3, to_points, 1.0); } else { closed = False; @@ -2552,7 +2552,7 @@ SmoothPathWithBezier(ZnPoint *fp, ZnListAdd(to_points, &s[3], ZnListTail); } else { - GetBezierPoints(s, s+1, s+2, s+3, to_points, 1.0); + ZnGetBezierPoints(s, s+1, s+2, s+3, to_points, 1.0); } } } @@ -2703,11 +2703,11 @@ B3(ZnReal u) * using relative distances between points. */ static ZnReal * -ChordLengthParameterize(ZnPoint *d, - int first, - int last) +ChordLengthParameterize(ZnPoint *d, + unsigned int first, + unsigned int last) { - int i; + unsigned int i; ZnReal *u; u = (ZnReal *) ZnMalloc((unsigned) (last-first+1) * sizeof(ZnReal)); @@ -2770,7 +2770,7 @@ NewtonRaphsonRootFind(ZnPoint *Q, ZnPoint Q1[3], Q2[2]; /* Q' and Q'' */ ZnPoint Q_u, Q1_u, Q2_u; /*u evaluated at Q, Q', & Q'' */ ZnReal uPrime; /* Improved u */ - int i; + unsigned int i; /* Compute Q(u) */ Q_u = BezierII(3, Q, u); @@ -2807,14 +2807,14 @@ NewtonRaphsonRootFind(ZnPoint *Q, * a better parameterization. */ static ZnReal * -Reparameterize(ZnPoint *d, - int first, - int last, - ZnReal *u, - ZnPoint *bezCurve) -{ - int nPts = last-first+1; - int i; +Reparameterize(ZnPoint *d, + unsigned int first, + unsigned int last, + ZnReal *u, + ZnPoint *bezCurve) +{ + unsigned int nPts = last-first+1; + unsigned int i; ZnReal *uPrime; /* New parameter values */ uPrime = (ZnReal *) ZnMalloc(nPts * sizeof(ZnReal)); @@ -2830,17 +2830,17 @@ Reparameterize(ZnPoint *d, * points for region. */ static void -GenerateBezier(ZnPoint *d, - int first, - int last, - ZnReal *uPrime, - ZnPoint tHat1, - ZnPoint tHat2, - ZnPoint *bez_curve) -{ - int i; +GenerateBezier(ZnPoint *d, + unsigned int first, + unsigned int last, + ZnReal *uPrime, + ZnPoint tHat1, + ZnPoint tHat2, + ZnPoint *bez_curve) +{ + unsigned int i; ZnPoint *A0, *A1; /* Precomputed rhs for eqn */ - int num_points; /* Number of pts in sub-curve */ + unsigned int num_points; /* Number of pts in sub-curve */ ZnReal C[2][2]; /* Matrix C */ ZnReal X[2]; /* Matrix X */ ZnReal det_C0_C1; /* Determinants of matrices */ @@ -2929,14 +2929,14 @@ GenerateBezier(ZnPoint *d, * to fitted curve. */ static ZnReal -ComputeMaxError(ZnPoint *d, - int first, - int last, - ZnPoint *bez_curve, - ZnReal *u, - int *splitPoint) -{ - int i; +ComputeMaxError(ZnPoint *d, + unsigned int first, + unsigned int last, + ZnPoint *bez_curve, + ZnReal *u, + unsigned int *splitPoint) +{ + unsigned int i; ZnReal maxDist; /* Maximum error */ ZnReal dist; /* Current error */ ZnPoint P; /* Point on curve */ @@ -2965,7 +2965,7 @@ ComputeMaxError(ZnPoint *d, */ static ZnPoint ComputeLeftTangent(ZnPoint *d, - int end) + unsigned int end) { ZnPoint tHat1; tHat1 = V2SubII(d[end+1], d[end]); @@ -2974,8 +2974,8 @@ ComputeLeftTangent(ZnPoint *d, } static ZnPoint -ComputeRightTangent(ZnPoint *d, - int end) +ComputeRightTangent(ZnPoint *d, + unsigned int end) { ZnPoint tHat2; tHat2 = V2SubII(d[end-1], d[end]); @@ -2985,8 +2985,8 @@ ComputeRightTangent(ZnPoint *d, static ZnPoint -ComputeCenterTangent(ZnPoint *d, - int center) +ComputeCenterTangent(ZnPoint *d, + unsigned int center) { ZnPoint V1, V2, tHatCenter; @@ -3000,8 +3000,8 @@ ComputeCenterTangent(ZnPoint *d, static void FitCubic(ZnPoint *d, - int first, - int last, + unsigned int first, + unsigned int last, ZnPoint tHat1, ZnPoint tHat2, ZnReal error, @@ -3011,12 +3011,12 @@ FitCubic(ZnPoint *d, ZnReal *u; /* Parameter values for point */ ZnReal *uPrime; /* Improved parameter values */ ZnReal max_err; /* Maximum fitting error */ - int splitPoint; /* Point to split point set at */ - int num_points; /* Number of points in subset */ + unsigned int splitPoint; /* Point to split point set at */ + unsigned int num_points; /* Number of points in subset */ ZnReal iteration_err; /* Error below which you try iterating */ - int max_iter = 4; /* Max times to try iterating */ + unsigned int max_iter = 4; /* Max times to try iterating */ ZnPoint tHatCenter; /* Unit tangent vector at splitPoint */ - int i; + unsigned int i; iteration_err = error * error; num_points = last - first + 1; @@ -3074,10 +3074,10 @@ FitCubic(ZnPoint *d, } void -FitBezier(ZnPoint *pts, - int num_points, - ZnReal error, - ZnList controls) +ZnFitBezier(ZnPoint *pts, + unsigned int num_points, + ZnReal error, + ZnList controls) { ZnPoint tHat1, tHat2; /* Unit tangent vectors at endpoints */ @@ -3086,86 +3086,3 @@ FitBezier(ZnPoint *pts, FitCubic(pts, 0, num_points-1, tHat1, tHat2, error, controls); } - -/* - ********************************************************************************** - * - * GetLineEnd -- - * Compute the points describing the given line end style at point p1 for - * the line p1,p2. Point p1 is adjusted to fit the line end. - * If bbox is non null, it is filled with the bounding box of the end. - * - * For the time being this procedure handles open/filled arrows. - * - * Here are the parameters describing arrows. - * - * * | ARROW_SHAPE_C - * ** | - * * *************************** - * * * - * * * +p1 +p2 - * | * |* - * | * *************************** - * | | ** - * | | * - * | | | - * |---| | ARROW_SHAPE_A - * | | - * |-------| ARROW_SHAPE_B - * - ********************************************************************************** - */ -void -GetLineEnd(ZnPoint *p1, - ZnPoint *p2, - unsigned int line_width, - int cap_style, - ZnLineEnd end_style, - ZnPoint *points) -{ - ZnReal dx, dy, length, temp, backup; - ZnReal frac_height, sin_theta, cos_theta; - ZnReal vert_x, vert_y; - ZnReal shape_a, shape_b, shape_c; - - if (end_style != NULL) { - shape_a = end_style->shape_a + 0.001; - shape_b = end_style->shape_b + 0.001; - shape_c = end_style->shape_c + line_width/2.0 + 0.001; - - frac_height = (line_width/2.0) / shape_c; - dx = p1->x - p2->x; - dy = p1->y - p2->y; - length = hypot(dx, dy); - if (length == 0) { - sin_theta = cos_theta = 0.0; - } - else { - sin_theta = dy/length; - cos_theta = dx/length; - } - - if (cap_style != CapProjecting) { - temp = frac_height; - } - else { - temp = line_width / shape_c; - } - backup = temp * shape_b + shape_a * (1.0 - temp) / 2.0; - points[0].x = points[5].x = p1->x + backup * cos_theta; - points[0].y = points[5].y = p1->y + backup * sin_theta; - - vert_x = points[0].x - shape_a*cos_theta; - vert_y = points[0].y - shape_a*sin_theta; - temp = shape_c*sin_theta; - points[1].x = REAL_TO_INT(points[0].x - shape_b*cos_theta + temp); - points[4].x = REAL_TO_INT(points[1].x - 2*temp); - temp = shape_c*cos_theta; - points[1].y = REAL_TO_INT(points[0].y - shape_b*sin_theta - temp); - points[4].y = REAL_TO_INT(points[1].y + 2*temp); - points[2].x = REAL_TO_INT(points[1].x*frac_height + vert_x*(1.0-frac_height)); - points[2].y = REAL_TO_INT(points[1].y*frac_height + vert_y*(1.0-frac_height)); - points[3].x = REAL_TO_INT(points[4].x*frac_height + vert_x*(1.0-frac_height)); - points[3].y = REAL_TO_INT(points[4].y*frac_height + vert_y*(1.0-frac_height)); - } -} diff --git a/generic/Geo.h b/generic/Geo.h index 3e9dac6..031524b 100644 --- a/generic/Geo.h +++ b/generic/Geo.h @@ -38,15 +38,6 @@ #include -#ifndef MIN -#define MIN(a, b) ((a) <= (b) ? (a) : (b)) -#endif -#ifndef MAX -#define MAX(a, b) ((a) >= (b) ? (a) : (b)) -#endif -#ifndef ABS -#define ABS(a) ((a) < 0 ? -(a) : (a)) -#endif #ifndef M_PI #define M_PI 3.14159265358979323846264338327 #endif @@ -57,268 +48,343 @@ #define M_PI_4 0.78539816339744830962 #endif -#define PRECISION_LIMIT 1.0e-10 +#define PRECISION_LIMIT 1.0e-10 #define X_PRECISION_LIMIT 5.0e-2 -#define LINE_END_POINTS 6 +#define ZN_LINE_END_POINTS 6 + +/* + * Constants used to specify circle approximation quality. + */ +#define ZN_CIRCLE_COARSE 0 +#define ZN_CIRCLE_MEDIUM ZN_CIRCLE_COARSE+1 +#define ZN_CIRCLE_FINE ZN_CIRCLE_MEDIUM+1 +#define ZN_CIRCLE_FINEST ZN_CIRCLE_FINE+1 + + +typedef struct { + ZnPos x, y; +} ZnPoint; + +typedef struct { + ZnPos x, y, w, h; +} ZnRect; + +/* + * ZnBBox: orig is into the area while corner is not. + * Thus the test: ((bbox.orig.x == bbox.corner.x) || + * (bbox.orig.y == bbox.corner.y)) + * tells whether the bbox is empty or not. + * When interpreting bboxes the X coordinate system is + * the norm. x goes from left toward the right and y + * goes from the top toward the bottom. Bboxes are + * always axes aligned. + */ +typedef struct { + ZnPoint orig, corner; +} ZnBBox; + +typedef struct { + unsigned int num_points; + ZnPoint *points; + char *controls; + ZnBool cw; +} ZnContour; + +/* + * contour1 can be used to store a single contour + * without having to alloc the contours array. + */ +typedef struct { + unsigned int num_contours; + ZnContour *contours; + ZnContour contour1; +} ZnPoly; + +/* + * Keep this enum in sync with op_strings in Contour() + * in tkZinc.c. + */ +typedef enum { + ZN_CONTOUR_ADD, ZN_CONTOUR_REMOVE +} ZnContourCmd; + +typedef struct { + unsigned int num_points; + ZnPoint *points; + ZnBool fan; /* When using a fan, all contour vertices must be + * included to describe the contour as a polygon + * (clipping code use that to speed up region + * rendering) and the center must be the first + * vertex. */ +} ZnStrip; + +typedef struct { + unsigned int num_strips; + ZnStrip *strips; + ZnStrip strip1; +} ZnTriStrip; + + +#ifndef MIN +#define MIN(a, b) ((a) <= (b) ? (a) : (b)) +#endif +#ifndef MAX +#define MAX(a, b) ((a) >= (b) ? (a) : (b)) +#endif +#ifndef ABS +#define ABS(a) ((a) < 0 ? -(a) : (a)) +#endif -#define DegreesToRadian(angle) \ +#define ZnDegRad(angle) \ (M_PI * (double) (angle) / 180.0) -#define RadianToDegrees(angle) \ +#define ZnRadDeg(angle) \ (fmod((angle) * 180.0 / M_PI, 360.0)) -#define RadianToDegrees360(angle) \ - (fmod(RadianToDegrees(angle)+360.0,360.0)) +#define ZnRadDeg360(angle) \ + (fmod(ZnRadDeg(angle)+360.0,360.0)) -#define REAL_TO_INT(d) \ +#define ZnNearestInt(d) \ (((int) ((d) + (((d) > 0) ? 0.5 : -0.5)))) void -POLY_INIT(ZnPoly *poly); +ZnPolyInit(ZnPoly *poly); void -POLY_CONTOUR1(ZnPoly *poly, - ZnPoint *pts, - int num_pts, - ZnBool cw); +ZnPolyContour1(ZnPoly *poly, + ZnPoint *pts, + unsigned int num_pts, + ZnBool cw); void -POLY_SET(ZnPoly *poly1, - ZnPoly *poly2); +ZnPolySet(ZnPoly *poly1, + ZnPoly *poly2); void -POLY_FREE(ZnPoly *poly); +ZnPolyFree(ZnPoly *poly); void -TRI_STRIP1(ZnTriStrip *tristrip, - ZnPoint *pts, - int num_pts, - ZnBool fan); +ZnTriStrip1(ZnTriStrip *tristrip, + ZnPoint *pts, + unsigned int num_pts, + ZnBool fan); void -TRI_FREE(ZnTriStrip *tristrip); +ZnTriFree(ZnTriStrip *tristrip); void -Anchor2Origin(ZnPoint *position, - ZnDim width, - ZnDim height, - ZnAnchor anchor, - ZnPoint *origin); +ZnAnchor2Origin(ZnPoint *position, + ZnDim width, + ZnDim height, + Tk_Anchor anchor, + ZnPoint *origin); void -Origin2Anchor(ZnPoint *origin, - ZnDim width, - ZnDim height, - ZnAnchor anchor, - ZnPoint *position); +ZnOrigin2Anchor(ZnPoint *origin, + ZnDim width, + ZnDim height, + Tk_Anchor anchor, + ZnPoint *position); void -BBox2XRect(ZnBBox *bbox, - XRectangle *rect); +ZnBBox2XRect(ZnBBox *bbox, + XRectangle *rect); void -GetStringBBox(char *str, - ZnFont font, - ZnPos x, - ZnPos y, - ZnBBox *str_bbox); +ZnGetStringBBox(char *str, + Tk_Font font, + ZnPos x, + ZnPos y, + ZnBBox *str_bbox); void -ResetBBox(ZnBBox *bbox); +ZnResetBBox(ZnBBox *bbox); void -CopyBBox(ZnBBox *bbox_from, - ZnBBox *bbox_to); +ZnCopyBBox(ZnBBox *bbox_from, + ZnBBox *bbox_to); void -IntersectBBox(ZnBBox *bbox1, - ZnBBox *bbox2, - ZnBBox *bbox_inter); +ZnIntersectBBox(ZnBBox *bbox1, + ZnBBox *bbox2, + ZnBBox *bbox_inter); ZnBool -IsEmptyBBox(ZnBBox *bbox); +ZnIsEmptyBBox(ZnBBox *bbox); void -AddBBoxToBBox(ZnBBox *bbox, - ZnBBox *bbox2); +ZnAddBBoxToBBox(ZnBBox *bbox, + ZnBBox *bbox2); void -AddPointToBBox(ZnBBox *bbox, - ZnPos px, - ZnPos py); +ZnAddPointToBBox(ZnBBox *bbox, + ZnPos px, + ZnPos py); void -AddPointsToBBox(ZnBBox *bbox, - ZnPoint *points, - int num_points); +ZnAddPointsToBBox(ZnBBox *bbox, + ZnPoint *points, + unsigned int num_points); void -AddStringToBBox(ZnBBox *bbox, - char *str, - ZnFont font, - ZnPos cx, - ZnPos cy); +ZnAddStringToBBox(ZnBBox *bbox, + char *str, + Tk_Font font, + ZnPos cx, + ZnPos cy); ZnBool -PointInBBox(ZnBBox *bbox, - ZnPos x, - ZnPos y); +ZnPointInBBox(ZnBBox *bbox, + ZnPos x, + ZnPos y); int -LineInBBox(ZnPoint *p1, - ZnPoint *p2, - ZnBBox *bbox); +ZnLineInBBox(ZnPoint *p1, + ZnPoint *p2, + ZnBBox *bbox); int -BBoxInBBox(ZnBBox *bbox1, - ZnBBox *bbox2); +ZnBBoxInBBox(ZnBBox *bbox1, + ZnBBox *bbox2); int -PolylineInBBox(ZnPoint *points, - int num_points, - int width, - int cap_style, - int join_style, - ZnBBox *bbox); +ZnPolylineInBBox(ZnPoint *points, + unsigned int num_points, + ZnDim width, + int cap_style, + int join_style, + ZnBBox *bbox); int -PolygonInBBox(ZnPoint *points, - int num_points, - ZnBBox *bbox, - ZnBool *area_enclosed); +ZnPolygonInBBox(ZnPoint *points, + unsigned int num_points, + ZnBBox *bbox, + ZnBool *area_enclosed); int -OvalInBBox(ZnPoint *center, - int width, - int height, - ZnBBox *bbox); +ZnOvalInBBox(ZnPoint *center, + ZnDim width, + ZnDim height, + ZnBBox *bbox); ZnBool -HorizLineToArc(ZnReal x1, - ZnReal x2, - ZnReal y, - ZnReal rx, - ZnReal ry, - ZnReal start_angle, - ZnReal angle_extent); +ZnHorizLineToArc(ZnReal x1, + ZnReal x2, + ZnReal y, + ZnReal rx, + ZnReal ry, + int start_angle, + int angle_extent); ZnBool -VertLineToArc(ZnReal x, - ZnReal y1, - ZnReal y2, - ZnReal rx, - ZnReal ry, - ZnReal start_angle, - ZnReal angle_extent); +ZnVertLineToArc(ZnReal x, + ZnReal y1, + ZnReal y2, + ZnReal rx, + ZnReal ry, + int start_angle, + int angle_extent); ZnBool -PointInAngle(int start_angle, - int angle_extent, - ZnPoint *p); +ZnPointInAngle(int start_angle, + int angle_extent, + ZnPoint *p); void -PointPolarToCartesian(ZnReal heading, - int rho, - int theta, - ZnDim *delta_x, - ZnDim *delta_y); +ZnPointPolarToCartesian(ZnReal heading, + ZnReal rho, + ZnReal theta, + ZnReal *delta_x, + ZnReal *delta_y); ZnReal -ProjectionToAngle(ZnDim dx, - ZnDim dy); - -double -RectangleToPointDist(ZnBBox *bbox, - ZnPoint *p); -double -LineToPointDist(ZnPoint *p1, - ZnPoint *p2, - ZnPoint *p); - -double -PolygonToPointDist(ZnPoint *points, - int num_points, - ZnPoint *p); - -double -PolylineToPointDist(ZnPoint *points, - int num_points, - int width, - int cap_style, - int join_style, - ZnPoint *p); - -double -OvalToPointDist(ZnPoint *center, - int width, - int height, - unsigned int line_width, - ZnPoint *p); +ZnProjectionToAngle(ZnReal dx, + ZnReal dy); + +ZnDim +ZnRectangleToPointDist(ZnBBox *bbox, + ZnPoint *p); +ZnDim +ZnLineToPointDist(ZnPoint *p1, + ZnPoint *p2, + ZnPoint *p); + +ZnDim +ZnPolygonToPointDist(ZnPoint *points, + unsigned int num_points, + ZnPoint *p); + +ZnDim +ZnPolylineToPointDist(ZnPoint *points, + unsigned int num_points, + ZnDim width, + int cap_style, + int join_style, + ZnPoint *p); + +ZnDim +ZnOvalToPointDist(ZnPoint *center, + ZnDim width, + ZnDim height, + ZnDim line_width, + ZnPoint *p); void -GetButtPoints(ZnPoint *p1, - ZnPoint *p2, - int width, - ZnBool projecting, - ZnPoint *c1, - ZnPoint *c2); +ZnGetButtPoints(ZnPoint *p1, + ZnPoint *p2, + ZnDim width, + ZnBool projecting, + ZnPoint *c1, + ZnPoint *c2); ZnBool -GetMiterPoints(ZnPoint *p1, - ZnPoint *p2, - ZnPoint *p3, - int width, - ZnPoint *c1, - ZnPoint *c2); +ZnGetMiterPoints(ZnPoint *p1, + ZnPoint *p2, + ZnPoint *p3, + ZnDim width, + ZnPoint *c1, + ZnPoint *c2); ZnBool -IntersectLines(ZnPoint *a1, - ZnPoint *a2, - ZnPoint *b1, - ZnPoint *b2, - ZnPoint *pi); +ZnIntersectLines(ZnPoint *a1, + ZnPoint *a2, + ZnPoint *b1, + ZnPoint *b2, + ZnPoint *pi); void -ShiftLine(ZnPoint *p1, - ZnPoint *p2, - ZnReal dist, - ZnPoint *p3, - ZnPoint *p4); +ZnShiftLine(ZnPoint *p1, + ZnPoint *p2, + ZnDim dist, + ZnPoint *p3, + ZnPoint *p4); void -InsetPolygon(ZnPoint *p, - int num_points, - ZnDim inset); +ZnInsetPolygon(ZnPoint *p, + unsigned int num_points, + ZnDim inset); void -SmoothPathWithBezier(ZnPoint *from_points, - int num_points, - ZnList to_points); +ZnSmoothPathWithBezier(ZnPoint *from_points, + unsigned int num_points, + ZnList to_points); void -GetBezierPoints(ZnPoint *p1, - ZnPoint *c1, - ZnPoint *c2, - ZnPoint *p2, - ZnList to_points, - double eps); +ZnGetBezierPoints(ZnPoint *p1, + ZnPoint *c1, + ZnPoint *c2, + ZnPoint *p2, + ZnList to_points, + double eps); void -GetBezierPath(ZnList from_points, - ZnList to_points); +ZnGetBezierPath(ZnList from_points, + ZnList to_points); ZnPoint * -GetCirclePoints(int type, - int quality, - ZnReal start_angle, - ZnReal angle_extent, - int *num_points, - ZnList point_list); - -void -GetArcPath(ZnReal start_angle, - ZnReal end_angle, - int type, - ZnList to_points); +ZnGetCirclePoints(int type, + int quality, + ZnReal start_angle, + ZnReal angle_extent, + unsigned int *num_points, + ZnList point_list); void -FitBezier(ZnPoint *pts, - int num_points, - ZnReal error, - ZnList controls); +ZnGetArcPath(ZnReal start_angle, + ZnReal end_angle, + int type, + ZnList to_points); void -GetLineEnd(ZnPoint *p1, - ZnPoint *p2, - unsigned int line_width, - int cap_style, - ZnLineEnd end_style, - ZnPoint *points); +ZnFitBezier(ZnPoint *pts, + unsigned int num_points, + ZnReal error, + ZnList controls); ZnBool -TestCCW(ZnPoint *p, - int num_points); +ZnTestCCW(ZnPoint *p, + unsigned int num_points); #endif /* _Geo_h */ diff --git a/generic/Group.c b/generic/Group.c index d020186..a8cea20 100644 --- a/generic/Group.c +++ b/generic/Group.c @@ -34,8 +34,10 @@ #include "Geo.h" #include "tkZinc.h" -#include +#ifndef _WIN32 #include +#endif + static const char rcsid[] = "$Id$"; static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ " $"; @@ -45,15 +47,15 @@ static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ " * Group item special record. */ typedef struct _GroupItemStruct { - ItemStruct header; + ZnItemStruct header; /* Public data */ - Item clip; + ZnItem clip; unsigned char alpha; /* Private data */ - Item head; /* Doubly linked list of all items. */ - Item tail; + ZnItem head; /* Doubly linked list of all items. */ + ZnItem tail; ZnList dependents; /* List of dependent items. */ #ifdef OM /* Overlap manager variables. @@ -65,6 +67,9 @@ typedef struct _GroupItemStruct { } GroupItemStruct, *GroupItem; +#define ATOMIC_BIT (1<clip = ZN_NO_ITEM; group->alpha = 100; group->dependents = NULL; - 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); + 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); CLEAR(item->flags, ATOMIC_BIT); - item->priority = DEFAULT_GROUP_PRIORITY; + item->priority = 1; #ifdef OM group->call_om = False; #endif - return ZN_OK; + return TCL_OK; } @@ -148,12 +153,12 @@ Init(Item item, ********************************************************************************** */ static void -Clone(Item item) +Clone(ZnItem item) { GroupItem group = (GroupItem) item; ZnList dependents; - Item connected, current_item, new_item; - Item *items; + ZnItem connected, current_item, new_item; + ZnItem *items; Tcl_HashTable mapping; Tcl_HashEntry *entry; int new, num_items, i; @@ -179,9 +184,9 @@ Clone(Item item) */ while (current_item != ZN_NO_ITEM) { connected = current_item->connected_item; - new_item = ITEM.CloneItem(current_item); + new_item = ZnITEM.CloneItem(current_item); new_item->connected_item = connected; - ITEM.InsertItem(new_item, item, ZN_NO_ITEM, True); + ZnITEM.InsertItem(new_item, item, ZN_NO_ITEM, True); if (dependents) { entry = Tcl_CreateHashEntry(&mapping, (char *) current_item, &new); @@ -200,7 +205,7 @@ Clone(Item item) if (dependents) { /*printf("rebuilding dependents\n");*/ group->dependents = NULL; - items = (Item *) ZnListArray(dependents); + items = (ZnItem *) ZnListArray(dependents); num_items = ZnListSize(dependents); for (i = 0; i < num_items; i++, items++) { entry = Tcl_FindHashEntry(&mapping, (char *) *items); @@ -209,7 +214,7 @@ Clone(Item item) abort(); } else { - current_item = (Item) Tcl_GetHashValue(entry); + current_item = (ZnItem) Tcl_GetHashValue(entry); } entry = Tcl_FindHashEntry(&mapping, (char *) current_item->connected_item); if (entry == NULL) { @@ -218,7 +223,7 @@ Clone(Item item) } else { /*printf("item %d correspond to ", current_item->connected_item->id);*/ - current_item->connected_item = (Item) Tcl_GetHashValue(entry); + current_item->connected_item = (ZnItem) Tcl_GetHashValue(entry); /*printf("%d\n", current_item->connected_item->id);*/ ZnInsertDependentItem(current_item); } @@ -236,15 +241,15 @@ Clone(Item item) ********************************************************************************** */ static void -Destroy(Item item) +Destroy(ZnItem item) { GroupItem group = (GroupItem) item; - Item current_item, next_item; + ZnItem current_item, next_item; current_item = group->head; while (current_item != ZN_NO_ITEM) { next_item = current_item->next; - ITEM.DestroyItem(current_item); + ZnITEM.DestroyItem(current_item); current_item = next_item; } if (group->dependents) { @@ -260,22 +265,22 @@ Destroy(Item item) * ********************************************************************************** */ +#if defined(SHAPE) && !defined(_WIN32) static void -SetXShape(Item grp) +SetXShape(ZnItem grp) { -#ifdef SHAPE - WidgetInfo *wi = grp->wi; - Item clip = ((GroupItem) grp)->clip; - int i, j, num_pts, max_num_pts; + ZnWInfo *wi = grp->wi; + ZnItem clip = ((GroupItem) grp)->clip; + unsigned int i, j, num_pts, max_num_pts; ZnPos min_x, min_y, max_x, max_y; ZnTriStrip tristrip; ZnPoint *p; ZnBool simple; ZnDim width, height; XPoint xpts[3], *xp2, *xpts2; - Region reg, reg_op, reg_to; + TkRegion reg, reg_op, reg_to; - if (!wi->has_x_shape) { + if (ISCLEAR(wi->flags, ZN_HAS_X_SHAPE)) { return; } @@ -284,7 +289,7 @@ SetXShape(Item grp) * Reset both clip just to be sure (the application can have * changed wi->full_reshape while resetting wi->reshape). */ - XShapeCombineMask(wi->dpy, ZnWindowId(wi->win), ShapeBounding, + XShapeCombineMask(wi->dpy, Tk_WindowId(wi->win), ShapeBounding, 0, 0, None, ShapeSet); XShapeCombineMask(wi->dpy, wi->real_top, ShapeBounding, 0, 0, None, ShapeSet); @@ -301,7 +306,7 @@ SetXShape(Item grp) * fit exactly the window. We may test here if a shape is currently * active and reset the mask only in this case (need a flag in wi). */ - XShapeCombineMask(wi->dpy, ZnWindowId(wi->win), ShapeBounding, + XShapeCombineMask(wi->dpy, Tk_WindowId(wi->win), ShapeBounding, 0, 0, None, ShapeSet); XShapeCombineMask(wi->dpy, wi->real_top, ShapeBounding, 0, 0, None, ShapeSet); @@ -340,9 +345,9 @@ SetXShape(Item grp) } max_x -= min_x; max_y -= min_y; - XShapeCombineMask(wi->dpy, wi->full_reshape?ZnWindowId(wi->win):wi->real_top, + XShapeCombineMask(wi->dpy, wi->full_reshape?Tk_WindowId(wi->win):wi->real_top, ShapeBounding, 0, 0, None, ShapeSet); - reg = XCreateRegion(); + reg = TkCreateRegion(); /* * Now normalize the shape and map it to the window size, @@ -370,11 +375,11 @@ SetXShape(Item grp) xp2->x = (short) ((p->x - min_x) * width / max_x); xp2->y = (short) ((p->y - min_y) * height / max_y); } - reg_op = XPolygonRegion(xpts2, num_pts, EvenOddRule); - reg_to = XCreateRegion(); - XUnionRegion(reg, reg_op, reg_to); - XDestroyRegion(reg); - XDestroyRegion(reg_op); + reg_op = ZnPolygonRegion(xpts2, num_pts, EvenOddRule); + reg_to = TkCreateRegion(); + ZnUnionRegion(reg, reg_op, reg_to); + TkDestroyRegion(reg); + TkDestroyRegion(reg_op); reg = reg_to; ZnFree(xpts2); } @@ -388,24 +393,29 @@ SetXShape(Item grp) for (i = 2 ; i < num_pts; i++, p++) { xpts[2].x = (short) ((p->x - min_x) * width / max_x); xpts[2].y = (short) ((p->y - min_y) * height / max_y); - reg_op = XPolygonRegion(xpts, 3, EvenOddRule); - reg_to = XCreateRegion(); - XUnionRegion(reg, reg_op, reg_to); - XDestroyRegion(reg); - XDestroyRegion(reg_op); + reg_op = ZnPolygonRegion(xpts, 3, EvenOddRule); + reg_to = TkCreateRegion(); + ZnUnionRegion(reg, reg_op, reg_to); + TkDestroyRegion(reg); + TkDestroyRegion(reg_op); reg = reg_to; xpts[0] = xpts[1]; xpts[1] = xpts[2]; } } } - XShapeCombineRegion(wi->dpy, wi->full_reshape?wi->real_top:ZnWindowId(wi->win), - ShapeBounding, 0, 0, reg, ShapeSet); - XDestroyRegion(reg); + XShapeCombineRegion(wi->dpy, wi->full_reshape?wi->real_top:Tk_WindowId(wi->win), + ShapeBounding, 0, 0, (Region) reg, ShapeSet); + TkDestroyRegion(reg); } } -#endif } +#else +static void +SetXShape(ZnItem grp __unused) +{ +} +#endif /* @@ -416,16 +426,16 @@ SetXShape(Item grp) ********************************************************************************** */ static int -Configure(Item item, +Configure(ZnItem item, int argc, Tcl_Obj *CONST argv[], int *flags) { GroupItem group = (GroupItem) item; - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; - if (ZnConfigureAttributes(wi, item, group_attrs, argc, argv, flags) == ZN_ERROR) { - return ZN_ERROR; + if (ZnConfigureAttributes(wi, item, group_attrs, argc, argv, flags) == TCL_ERROR) { + return TCL_ERROR; } /* @@ -438,14 +448,14 @@ Configure(Item item, group->clip = ZN_NO_ITEM; Tcl_AppendResult(wi->interp, " clip item must be a child of the group", NULL); - return ZN_ERROR; + return TCL_ERROR; } if (!group->clip && (item == wi->top_group)) { SetXShape(item); } } - return ZN_OK; + return TCL_OK; } @@ -457,15 +467,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, group_attrs, argv[0]) == ZN_ERROR) { - return ZN_ERROR; + if (ZnQueryAttribute(item->wi, item, group_attrs, argv[0]) == TCL_ERROR) { + return TCL_ERROR; } - return ZN_OK; + return TCL_OK; } @@ -484,14 +494,18 @@ static void PushClip(GroupItem group, ZnBool set_gc) { - WidgetInfo *wi = ((Item) group)->wi; + ZnWInfo *wi = ((ZnItem) group)->wi; ZnTriStrip tristrip; ZnBool simple; if ((group->clip != ZN_NO_ITEM) && - ((((Item) group) != wi->top_group) || !wi->reshape)) { + ((((ZnItem) group) != wi->top_group) +#if defined(SHAPE) && ! defined (_WIN32) + || !wi->reshape +#endif + )) { simple = group->clip->class->GetClipVertices(group->clip, &tristrip); - /*printf("Group: PushClip group %d\n", ((Item) group)->id);*/ + /*printf("Group: PushClip group %d\n", ((ZnItem) group)->id);*/ if (tristrip.num_strips) { ZnPushClip(wi, &tristrip, simple, set_gc); } @@ -511,11 +525,15 @@ static void PopClip(GroupItem group, ZnBool set_gc) { - WidgetInfo *wi = ((Item) group)->wi; + ZnWInfo *wi = ((ZnItem) group)->wi; if ((group->clip != ZN_NO_ITEM) && - ((((Item) group) != wi->top_group) || !wi->reshape)) { - /*printf("Group: PopClip group %d\n", ((Item) group)->id);*/ + ((((ZnItem) group) != wi->top_group) +#if defined(SHAPE) && !defined(_WIN32) + || !wi->reshape +#endif + )) { + /*printf("Group: PopClip group %d\n", ((ZnItem) group)->id);*/ ZnPopClip(wi, set_gc); } } @@ -531,17 +549,17 @@ PopClip(GroupItem group, ********************************************************************************** */ static void -PushTransform(Item item) +PushTransform(ZnItem item) { if (!item->transfo && - ISSET(item->flags, COMPOSE_SCALE_BIT) && - ISSET(item->flags, COMPOSE_ROTATION_BIT)) { + ISSET(item->flags, ZN_COMPOSE_SCALE_BIT) && + ISSET(item->flags, ZN_COMPOSE_ROTATION_BIT)) { return; } ZnPushTransform(item->wi, item->transfo, - ISSET(item->flags, COMPOSE_SCALE_BIT), - ISSET(item->flags, COMPOSE_ROTATION_BIT)); + ISSET(item->flags, ZN_COMPOSE_SCALE_BIT), + ISSET(item->flags, ZN_COMPOSE_ROTATION_BIT)); /*printf("Pushing transfo for item: %d\n;", item->id); ZnPrintTransfo(wi->current_transfo);*/ } @@ -556,11 +574,11 @@ PushTransform(Item item) ********************************************************************************** */ static void -PopTransform(Item item) +PopTransform(ZnItem item) { if (!item->transfo && - ISSET(item->flags, COMPOSE_SCALE_BIT) && - ISSET(item->flags, COMPOSE_ROTATION_BIT)) { + ISSET(item->flags, ZN_COMPOSE_SCALE_BIT) && + ISSET(item->flags, ZN_COMPOSE_ROTATION_BIT)) { return; } @@ -583,15 +601,15 @@ PopTransform(Item item) ********************************************************************************** */ static void -CallRegularCC(Item item) +CallRegularCC(ZnItem item) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; /*ZnBBox *clip_box;*/ /* * Do some generic pre-work in behalf of the (regular) children. */ - if (ISSET(item->flags, VISIBLE_BIT)) { + if (ISSET(item->flags, ZN_VISIBLE_BIT)) { ZnDamage(wi, &item->item_bounding_box); } PushTransform(item); @@ -616,13 +634,13 @@ CallRegularCC(Item item) if (ZnCurrentClip(wi, NULL, &clip_box, NULL)) { ZnBBox inter; - IntersectBBox(&item->item_bounding_box, clip_box, &inter); + ZnIntersectBBox(&item->item_bounding_box, clip_box, &inter); item->item_bounding_box = inter; }*/ /* * Do some generic post-work in behalf of the (regular) children. */ -#ifdef GLX +#ifdef GL #ifdef GL_LIST /* * Remove the item display list so that it will be recreated @@ -635,18 +653,18 @@ CallRegularCC(Item item) #endif #endif if (ISSET(item->inv_flags, ZN_REPICK_FLAG)) { - SET(wi->events_flags, INTERNAL_NEED_REPICK); + SET(wi->flags, ZN_INTERNAL_NEED_REPICK); } if (ISSET(item->inv_flags, ZN_COORDS_FLAG) && - (ISSET(item->flags, SENSITIVE_BIT) || - ISSET(item->flags, VISIBLE_BIT))) { - SET(wi->events_flags, INTERNAL_NEED_REPICK); + (ISSET(item->flags, ZN_SENSITIVE_BIT) || + ISSET(item->flags, ZN_VISIBLE_BIT))) { + SET(wi->flags, ZN_INTERNAL_NEED_REPICK); } /* * Damage if the item is visible or if it is * a group clipper. */ - if (ISSET(item->flags, VISIBLE_BIT) || + if (ISSET(item->flags, ZN_VISIBLE_BIT) || (item == ((GroupItem) item->parent)->clip)) { ZnDamage(wi, &item->item_bounding_box); } @@ -656,12 +674,12 @@ CallRegularCC(Item item) } static void -ComputeCoordinates(Item item, +ComputeCoordinates(ZnItem item, ZnBool force) { GroupItem group = (GroupItem) item; - Item current_item; - Item *deps; + ZnItem current_item; + ZnItem *deps; int num_deps, i; PushTransform(item); @@ -737,13 +755,13 @@ ComputeCoordinates(Item item, */ if (group->dependents) { num_deps = ZnListSize(group->dependents); - deps = (Item *) ZnListArray(group->dependents); + deps = (ZnItem *) ZnListArray(group->dependents); for (i = 0; i < num_deps; i++) { current_item = deps[i]; if (force || ISSET(current_item->inv_flags, ZN_COORDS_FLAG) || ISSET(current_item->inv_flags, ZN_TRANSFO_FLAG) || - ISSET(current_item->connected_item->flags, UPDATE_DEPENDENT_BIT)) { + ISSET(current_item->connected_item->flags, ZN_UPDATE_DEPENDENT_BIT)) { /*printf("Updating dependent: %d\n", current_item->id);*/ CallRegularCC(current_item); } @@ -752,17 +770,17 @@ ComputeCoordinates(Item item, * Now, we must reset the update_dependent flag */ for (i = 0; i < num_deps; i++) { - CLEAR(deps[i]->connected_item->flags, UPDATE_DEPENDENT_BIT); + CLEAR(deps[i]->connected_item->flags, ZN_UPDATE_DEPENDENT_BIT); } /*printf("... done\n");*/ } /* * Compute the bounding box. */ - ResetBBox(&item->item_bounding_box); + ZnResetBBox(&item->item_bounding_box); current_item = group->head; while (current_item != ZN_NO_ITEM) { - AddBBoxToBBox(&item->item_bounding_box, ¤t_item->item_bounding_box); + ZnAddBBoxToBBox(&item->item_bounding_box, ¤t_item->item_bounding_box); current_item = current_item->next; } item->inv_flags = 0; @@ -782,11 +800,11 @@ ComputeCoordinates(Item item, ********************************************************************************** */ static int -ToArea(Item item, +ToArea(ZnItem item, ZnToArea ta) { GroupItem group = (GroupItem) item; - Item current_item; + ZnItem current_item; ZnBBox enclosing, inter; int result = -1; ZnBool outside, inside; @@ -854,13 +872,13 @@ ToArea(Item item, for (current_item = group->head; current_item != ZN_NO_ITEM; current_item = current_item->next) { - if (ISCLEAR(current_item->flags, VISIBLE_BIT) && - ISCLEAR(current_item->flags, SENSITIVE_BIT)) { + if (ISCLEAR(current_item->flags, ZN_VISIBLE_BIT) && + ISCLEAR(current_item->flags, ZN_SENSITIVE_BIT)) { continue; } /*printf("visible&sensitive %d\n", current_item?current_item->id:0);*/ - IntersectBBox(&enclosing, ¤t_item->item_bounding_box, &inter); - if (IsEmptyBBox(&inter)) { + ZnIntersectBBox(&enclosing, ¤t_item->item_bounding_box, &inter); + if (ZnIsEmptyBBox(&inter)) { continue; } /*printf("bbox test passed %d\n", current_item?current_item->id:0);*/ @@ -940,11 +958,11 @@ ToArea(Item item, ********************************************************************************** */ static void -Draw(Item item) +Draw(ZnItem item) { GroupItem group = (GroupItem) item; - WidgetInfo *wi = item->wi; - Item current_item; + ZnWInfo *wi = item->wi; + ZnItem current_item; ZnBBox bbox, old_damaged_area, *clip_box; PushTransform(item); @@ -952,36 +970,35 @@ Draw(Item item) if (group->clip != ZN_NO_ITEM) { old_damaged_area = wi->damaged_area; if (ZnCurrentClip(wi, NULL, &clip_box, NULL)) { - IntersectBBox(&wi->damaged_area, clip_box, &bbox); + ZnIntersectBBox(&wi->damaged_area, clip_box, &bbox); wi->damaged_area = bbox; } } current_item = group->tail; while (current_item != ZN_NO_ITEM) { - if (ISSET(current_item->flags, VISIBLE_BIT)) { - IntersectBBox(&wi->damaged_area, ¤t_item->item_bounding_box, &bbox); - if (!IsEmptyBBox(&bbox)) { + if (ISSET(current_item->flags, ZN_VISIBLE_BIT)) { + ZnIntersectBBox(&wi->damaged_area, ¤t_item->item_bounding_box, &bbox); + if (!ZnIsEmptyBBox(&bbox)) { if (current_item->class != ZnGroup) { PushTransform(current_item); } current_item->class->Draw(current_item); if (wi->draw_bboxes) { XGCValues values; - values.foreground = ZnPixel(ZnGetGradientColor(wi->bbox_color, - 0, NULL)); + values.foreground = ZnPixel(ZnGetGradientColor(wi->bbox_color, 0.0, NULL)); values.fill_style = FillSolid; values.line_width = 1; values.line_style = (current_item->class==ZnGroup)?LineOnOffDash:LineSolid; XChangeGC(wi->dpy, wi->gc, GCForeground|GCLineStyle|GCLineWidth|GCFillStyle, &values); XDrawRectangle(wi->dpy, wi->draw_buffer, wi->gc, - current_item->item_bounding_box.orig.x, - current_item->item_bounding_box.orig.y, - current_item->item_bounding_box.corner.x - - current_item->item_bounding_box.orig.x, - current_item->item_bounding_box.corner.y - - current_item->item_bounding_box.orig.y); + (int) current_item->item_bounding_box.orig.x, + (int) current_item->item_bounding_box.orig.y, + (unsigned int) (current_item->item_bounding_box.corner.x - + current_item->item_bounding_box.orig.x), + (unsigned int) (current_item->item_bounding_box.corner.y - + current_item->item_bounding_box.orig.y)); } if (current_item->class != ZnGroup) { PopTransform(current_item); @@ -1006,21 +1023,21 @@ Draw(Item item) * ********************************************************************************** */ +#ifdef GL static void -Render(Item item) +Render(ZnItem item) { -#ifdef GLX GroupItem group = (GroupItem) item; - Item current_item; - WidgetInfo *wi = item->wi; -#ifdef GLX_DAMAGE + ZnItem current_item; + ZnWInfo *wi = item->wi; +#ifdef GL_DAMAGE ZnBBox *clip_box; ZnBBox bbox, old_damaged_area; #endif unsigned char save_alpha = wi->alpha; unsigned char save_alpha2; - if (ISSET(item->flags, COMPOSE_ALPHA_BIT)) { + if (ISSET(item->flags, ZN_COMPOSE_ALPHA_BIT)) { wi->alpha = wi->alpha * group->alpha / 100; } else { @@ -1030,11 +1047,11 @@ Render(Item item) PushTransform(item); PushClip(group, True); -#ifdef GLX_DAMAGE +#ifdef GL_DAMAGE if (group->clip != ZN_NO_ITEM) { old_damaged_area = wi->damaged_area; if (ZnCurrentClip(wi, NULL, &clip_box, NULL)) { - IntersectBBox(&wi->damaged_area, clip_box, &bbox); + ZnIntersectBBox(&wi->damaged_area, clip_box, &bbox); wi->damaged_area = bbox; } } @@ -1042,14 +1059,14 @@ Render(Item item) current_item = group->tail; while (current_item != ZN_NO_ITEM) { - if (ISSET(current_item->flags, VISIBLE_BIT)) { -#ifdef GLX_DAMAGE - IntersectBBox(&wi->damaged_area, ¤t_item->item_bounding_box, &bbox); - if (!IsEmptyBBox(&bbox)) { + if (ISSET(current_item->flags, ZN_VISIBLE_BIT)) { +#ifdef GL_DAMAGE + ZnIntersectBBox(&wi->damaged_area, ¤t_item->item_bounding_box, &bbox); + if (!ZnIsEmptyBBox(&bbox)) { #endif if (current_item->class != ZnGroup) { PushTransform(current_item); - if (ISCLEAR(current_item->flags, COMPOSE_ALPHA_BIT)) { + if (ISCLEAR(current_item->flags, ZN_COMPOSE_ALPHA_BIT)) { wi->alpha = 100; } } @@ -1058,14 +1075,14 @@ Render(Item item) PopTransform(current_item); wi->alpha = save_alpha2; } -#ifdef GLX_DAMAGE +#ifdef GL_DAMAGE } #endif } current_item = current_item->previous; } -#ifdef GLX_DAMAGE +#ifdef GL_DAMAGE if (group->clip != ZN_NO_ITEM) { wi->damaged_area = old_damaged_area; } @@ -1075,8 +1092,13 @@ Render(Item item) PopTransform(item); wi->alpha = save_alpha; -#endif } +#else +static void +Render(ZnItem item __unused) +{ +} +#endif /* @@ -1087,14 +1109,14 @@ Render(Item item) ********************************************************************************** */ static ZnBool -IsSensitive(Item item, - int item_part) +IsSensitive(ZnItem item, + int item_part __unused) { - ZnBool sensitive = ISSET(item->flags, SENSITIVE_BIT); - Item parent = item->parent; + ZnBool sensitive = ISSET(item->flags, ZN_SENSITIVE_BIT); + ZnItem parent = item->parent; while (sensitive && (parent != ZN_NO_ITEM)) { - sensitive &= ISSET(parent->flags, SENSITIVE_BIT); + sensitive &= ISSET(parent->flags, ZN_SENSITIVE_BIT); parent = parent->parent; } return sensitive; @@ -1123,12 +1145,12 @@ IsSensitive(Item item, ********************************************************************************** */ static double -Pick(Item item, +Pick(ZnItem item, ZnPick ps) { GroupItem group = (GroupItem) item; - Item p_item=ZN_NO_ITEM, current_item; - WidgetInfo *wi = item->wi; + ZnItem p_item=ZN_NO_ITEM, current_item; + ZnWInfo *wi = item->wi; int p_part=0, aperture = ps->aperture; double dist, best = 1e10; ZnBBox bbox, inter, *clip_box; @@ -1182,8 +1204,8 @@ Pick(Item item, bbox.corner.y = p->y + (aperture?aperture:1); if (ZnCurrentClip(wi, NULL, &clip_box, NULL)) { - IntersectBBox(&bbox, clip_box, &inter); - if (IsEmptyBBox(&inter)) { + ZnIntersectBBox(&bbox, clip_box, &inter); + if (ZnIsEmptyBBox(&inter)) { goto out; } } @@ -1197,8 +1219,8 @@ Pick(Item item, * It is legal to fire bindings on invisible sensitive items. * This is _not_ a bug do _not_ modify the test below. */ - if (ISCLEAR(current_item->flags, SENSITIVE_BIT) && - ISCLEAR(current_item->flags, VISIBLE_BIT)) { + if (ISCLEAR(current_item->flags, ZN_SENSITIVE_BIT) && + ISCLEAR(current_item->flags, ZN_VISIBLE_BIT)) { continue; } if (current_item->class != ZnGroup) { @@ -1259,32 +1281,32 @@ Pick(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 __unused, + int cmd, + ZnPoint **pts, + char **controls __unused, + unsigned int *num_pts) { - if ((cmd == COORDS_ADD) || (cmd == COORDS_ADD_LAST) || (cmd == COORDS_REMOVE)) { + if ((cmd == ZN_COORDS_ADD) || (cmd == ZN_COORDS_ADD_LAST) || (cmd == ZN_COORDS_REMOVE)) { Tcl_AppendResult(item->wi->interp, " groups can't add or remove vertices", NULL); - return ZN_ERROR; + return TCL_ERROR; } - else if ((cmd == COORDS_REPLACE) || (cmd == COORDS_REPLACE_ALL)) { + else if ((cmd == ZN_COORDS_REPLACE) || (cmd == ZN_COORDS_REPLACE_ALL)) { if (*num_pts == 0) { Tcl_AppendResult(item->wi->interp, " coords command need 1 point on groups", NULL); - return ZN_ERROR; + return TCL_ERROR; } if (!item->transfo) { item->transfo = ZnTransfoNew(); } ZnSetTranslation(item->transfo, (*pts)[0].x, (*pts)[0].y); - ITEM.Invalidate(item, ZN_TRANSFO_FLAG); + ZnITEM.Invalidate(item, ZN_TRANSFO_FLAG); } - else if ((cmd == COORDS_READ) || (cmd == COORDS_READ_ALL)) { + else if ((cmd == ZN_COORDS_READ) || (cmd == ZN_COORDS_READ_ALL)) { ZnPoint *p; ZnListAssertSize(item->wi->work_pts, 1); @@ -1293,7 +1315,7 @@ Coords(Item item, *num_pts = 1; *pts = p; } - return ZN_OK; + return TCL_OK; } @@ -1305,15 +1327,15 @@ Coords(Item item, ********************************************************************************** */ static void -PostScript(Item item, - PostScriptInfo ps_info) +PostScript(ZnItem item __unused, + ZnPostScriptInfo ps_info __unused) { } -Item -ZnGroupHead(Item group) +ZnItem +ZnGroupHead(ZnItem group) { if (group->class != ZnGroup) { return ZN_NO_ITEM; @@ -1321,8 +1343,8 @@ ZnGroupHead(Item group) return ((GroupItem) group)->head; } -Item -ZnGroupTail(Item group) +ZnItem +ZnGroupTail(ZnItem group) { if (group->class != ZnGroup) { return ZN_NO_ITEM; @@ -1330,8 +1352,9 @@ ZnGroupTail(Item group) return ((GroupItem) group)->tail; } +#ifdef OM ZnBool -ZnGroupCallOm(Item group) +ZnGroupCallOm(ZnItem group) { if (group->class != ZnGroup) { return False; @@ -1339,35 +1362,48 @@ ZnGroupCallOm(Item group) return ((GroupItem) group)->call_om; } -ZnBool -ZnGroupAtomic(Item group) +void +ZnGroupSetCallOm(ZnItem group, + ZnBool set) { if (group->class != ZnGroup) { - return True; + return; } - return ISSET(group->flags, ATOMIC_BIT); + ((GroupItem) group)->call_om = set; +} +#else +ZnBool +ZnGroupCallOm(ZnItem group __unused) +{ + return False; } void -ZnGroupSetCallOm(Item group, - ZnBool set) +ZnGroupSetCallOm(ZnItem group __unused, + ZnBool set __unused) +{ + return; +} +#endif + +ZnBool +ZnGroupAtomic(ZnItem group) { if (group->class != ZnGroup) { - return; + return True; } - ((GroupItem) group)->call_om = set; + return ISSET(group->flags, ATOMIC_BIT); } - void -ZnGroupRemoveClip(Item group, - Item clip) +ZnGroupRemoveClip(ZnItem group, + ZnItem clip) { GroupItem grp = (GroupItem) group; if (grp->clip == clip) { grp->clip = ZN_NO_ITEM; - ITEM.Invalidate(group, ZN_COORDS_FLAG); + ZnITEM.Invalidate(group, ZN_COORDS_FLAG); } } @@ -1380,7 +1416,7 @@ ZnGroupRemoveClip(Item group, ********************************************************************************** */ void -ZnInsertDependentItem(Item item) +ZnInsertDependentItem(ZnItem item) { GroupItem group = (GroupItem) item->parent; @@ -1388,7 +1424,7 @@ ZnInsertDependentItem(Item item) return; } if (!group->dependents) { - group->dependents = ZnListNew(2, sizeof(Item)); + group->dependents = ZnListNew(2, sizeof(ZnItem)); } ZnListAdd(group->dependents, &item, ZnListTail); } @@ -1402,17 +1438,17 @@ ZnInsertDependentItem(Item item) ********************************************************************************** */ void -ZnExtractDependentItem(Item item) +ZnExtractDependentItem(ZnItem item) { GroupItem group = (GroupItem) item->parent; - int index, num_items; - Item *deps; + unsigned int index, num_items; + ZnItem *deps; if (!group || !group->dependents) { return; } num_items = ZnListSize(group->dependents); - deps = (Item *) ZnListArray(group->dependents); + deps = (ZnItem *) ZnListArray(group->dependents); for (index = 0; index < num_items; index++) { if (deps[index]->id == item->id) { ZnListDelete(group->dependents, index); @@ -1435,17 +1471,18 @@ ZnExtractDependentItem(Item item) ********************************************************************************** */ void -ZnDisconnectDependentItems(Item item) +ZnDisconnectDependentItems(ZnItem item) { - Item current_item; + ZnItem current_item; GroupItem group = (GroupItem) item->parent; - Item *deps; - int num_deps, i; + ZnItem *deps; + unsigned int num_deps; + int i; if (!group || !group->dependents) { return; } - deps = (Item *) ZnListArray(group->dependents); + deps = (ZnItem *) ZnListArray(group->dependents); num_deps = ZnListSize(group->dependents); for (i = num_deps-1; i >= 0; i--) { @@ -1453,7 +1490,7 @@ ZnDisconnectDependentItems(Item item) if (current_item->connected_item == item) { current_item->connected_item = ZN_NO_ITEM; ZnListDelete(group->dependents, i); - ITEM.Invalidate(current_item, ZN_COORDS_FLAG); + ZnITEM.Invalidate(current_item, ZN_COORDS_FLAG); } } if (ZnListSize(group->dependents) == 0) { @@ -1471,7 +1508,7 @@ ZnDisconnectDependentItems(Item item) ********************************************************************************** */ void -ZnGroupExtractItem(Item item) +ZnGroupExtractItem(ZnItem item) { GroupItem group; @@ -1494,7 +1531,7 @@ ZnGroupExtractItem(Item item) group->tail = item->previous; } - ITEM.Invalidate((Item) group, ZN_COORDS_FLAG); + ZnITEM.Invalidate((ZnItem) group, ZN_COORDS_FLAG); item->previous = ZN_NO_ITEM; item->next = ZN_NO_ITEM; @@ -1510,9 +1547,9 @@ ZnGroupExtractItem(Item item) ********************************************************************************** */ void -ZnGroupInsertItem(Item group, - Item item, - Item mark_item, +ZnGroupInsertItem(ZnItem group, + ZnItem item, + ZnItem mark_item, ZnBool before) { GroupItem grp = (GroupItem) group; @@ -1587,7 +1624,7 @@ ZnGroupInsertItem(Item group, } } - ITEM.Invalidate(group, ZN_COORDS_FLAG); + ZnITEM.Invalidate(group, ZN_COORDS_FLAG); } /* @@ -1598,16 +1635,16 @@ ZnGroupInsertItem(Item group, ********************************************************************************** */ static void -GetAnchor(Item item, - ZnAnchor anchor, +GetAnchor(ZnItem item, + Tk_Anchor anchor, ZnPoint *p) { ZnBBox *bbox = &item->item_bounding_box; - Origin2Anchor(&bbox->orig, - bbox->corner.x - bbox->orig.x, - bbox->corner.y - bbox->orig.y, - anchor, p); + ZnOrigin2Anchor(&bbox->orig, + bbox->corner.x - bbox->orig.x, + bbox->corner.y - bbox->orig.y, + anchor, p); } @@ -1618,7 +1655,7 @@ GetAnchor(Item item, * ********************************************************************************** */ -static ItemClassStruct GROUP_ITEM_CLASS = { +static ZnItemClassStruct GROUP_ITEM_CLASS = { sizeof(GroupItemStruct), 0, /* num_parts */ False, /* has_anchors */ diff --git a/generic/Group.h b/generic/Group.h index 14c9871..a31e06f 100644 --- a/generic/Group.h +++ b/generic/Group.h @@ -31,16 +31,16 @@ #define _Group_h -Item ZnGroupHead(Item group); -Item ZnGroupTail(Item group); -ZnBool ZnGroupCallOm(Item group); -ZnBool ZnGroupAtomic(Item group); -void ZnGroupSetCallOm(Item group, ZnBool set); -void ZnInsertDependentItem(Item item); -void ZnExtractDependentItem(Item item); -void ZnDisconnectDependentItems(Item item); -void ZnGroupInsertItem(Item group, Item item, Item mark_item, ZnBool before); -void ZnGroupExtractItem(Item item); -void ZnGroupRemoveClip(Item group, Item clip); +ZnItem ZnGroupHead(ZnItem group); +ZnItem ZnGroupTail(ZnItem group); +ZnBool ZnGroupCallOm(ZnItem group); +ZnBool ZnGroupAtomic(ZnItem group); +void ZnGroupSetCallOm(ZnItem group, ZnBool set); +void ZnInsertDependentItem(ZnItem item); +void ZnExtractDependentItem(ZnItem item); +void ZnDisconnectDependentItems(ZnItem item); +void ZnGroupInsertItem(ZnItem group, ZnItem item, ZnItem mark_item, ZnBool before); +void ZnGroupExtractItem(ZnItem item); +void ZnGroupRemoveClip(ZnItem group, ZnItem clip); #endif /* _Group_h */ diff --git a/generic/Icon.c b/generic/Icon.c index a16acaf..a1bd7a1 100644 --- a/generic/Icon.c +++ b/generic/Icon.c @@ -25,8 +25,6 @@ */ -#include - #include "Item.h" #include "Geo.h" #include "Draw.h" @@ -47,14 +45,14 @@ static const char compile_id[] = "$Compile: " __FILE__ " " __DATE__ " " __TIME__ ********************************************************************************** */ typedef struct _IconItemStruct { - ItemStruct header; + ZnItemStruct header; /* Public data */ ZnPoint pos; ZnImage image; - ZnAnchor anchor; - ZnAnchor connection_anchor; - ZnGradient *color; /* Used only if the image is a bitmap (in GLX alpha part + Tk_Anchor anchor; + Tk_Anchor connection_anchor; + ZnGradient *color; /* Used only if the image is a bitmap (in GL alpha part * is always meaningful). */ /* Private data */ @@ -68,13 +66,13 @@ static ZnAttrConfig icon_attrs[] = { { ZN_CONFIG_GRADIENT, "-color", NULL, Tk_Offset(IconItemStruct, color), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-composealpha", NULL, - Tk_Offset(IconItemStruct, header.flags), COMPOSE_ALPHA_BIT, + Tk_Offset(IconItemStruct, header.flags), ZN_COMPOSE_ALPHA_BIT, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-composerotation", NULL, - Tk_Offset(IconItemStruct, header.flags), COMPOSE_ROTATION_BIT, + Tk_Offset(IconItemStruct, header.flags), ZN_COMPOSE_ROTATION_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_BOOL, "-composescale", NULL, - Tk_Offset(IconItemStruct, header.flags), COMPOSE_SCALE_BIT, + Tk_Offset(IconItemStruct, header.flags), ZN_COMPOSE_SCALE_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_ITEM, "-connecteditem", NULL, Tk_Offset(IconItemStruct, header.connected_item), 0, @@ -91,15 +89,15 @@ static ZnAttrConfig icon_attrs[] = { Tk_Offset(IconItemStruct, header.priority), 0, ZN_DRAW_FLAG|ZN_REPICK_FLAG, False }, { ZN_CONFIG_BOOL, "-sensitive", NULL, - Tk_Offset(IconItemStruct, header.flags), SENSITIVE_BIT, + Tk_Offset(IconItemStruct, header.flags), ZN_SENSITIVE_BIT, ZN_REPICK_FLAG, False }, { ZN_CONFIG_TAG_LIST, "-tags", NULL, Tk_Offset(IconItemStruct, header.tags), 0, 0, False }, { ZN_CONFIG_BOOL, "-visible", NULL, - Tk_Offset(IconItemStruct, header.flags), VISIBLE_BIT, + Tk_Offset(IconItemStruct, 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 } }; @@ -112,28 +110,28 @@ static ZnAttrConfig icon_attrs[] = { ********************************************************************************** */ static int -Init(Item item, - int *argc, - Tcl_Obj *CONST *args[]) +Init(ZnItem item, + int *argc __unused, + Tcl_Obj *CONST *args[] __unused) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; IconItem icon = (IconItem) item; /* 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_ICON_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; icon->pos.x = icon->pos.y = 0.0; icon->image = ZnUnspecifiedImage; - icon->anchor = ZnAnchorNW; - icon->connection_anchor = ZnAnchorSW; + icon->anchor = TK_ANCHOR_NW; + icon->connection_anchor = TK_ANCHOR_SW; icon->color = ZnGetGradientByValue(wi->fore_color); - return ZN_OK; + return TCL_OK; } @@ -145,7 +143,7 @@ Init(Item item, ********************************************************************************** */ static void -Clone(Item item) +Clone(ZnItem item) { IconItem icon = (IconItem) item; @@ -164,7 +162,7 @@ Clone(Item item) ********************************************************************************** */ static void -Destroy(Item item) +Destroy(ZnItem item) { IconItem icon = (IconItem) item; @@ -184,17 +182,17 @@ Destroy(Item item) ********************************************************************************** */ static int -Configure(Item item, +Configure(ZnItem item, int argc, Tcl_Obj *CONST argv[], int *flags) { - Item old_connected; + ZnItem old_connected; old_connected = item->connected_item; if (ZnConfigureAttributes(item->wi, item, icon_attrs, - argc, argv, flags) == ZN_ERROR) { - return ZN_ERROR; + argc, argv, flags) == TCL_ERROR) { + return TCL_ERROR; } if (ISSET(*flags, ZN_ITEM_FLAG)) { @@ -205,14 +203,14 @@ Configure(Item item, if ((item->connected_item == ZN_NO_ITEM) || (item->connected_item->class->has_anchors && (item->parent == item->connected_item->parent))) { - ITEM.UpdateItemDependency(item, old_connected); + ZnITEM.UpdateItemDependency(item, old_connected); } else { item->connected_item = old_connected; } } - return ZN_OK; + return TCL_OK; } @@ -224,15 +222,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, icon_attrs, argv[0]) == ZN_ERROR) { - return ZN_ERROR; + if (ZnQueryAttribute(item->wi, item, icon_attrs, argv[0]) == TCL_ERROR) { + return TCL_ERROR; } - return ZN_OK; + return TCL_OK; } @@ -244,14 +242,14 @@ Query(Item item, ********************************************************************************** */ static void -ComputeCoordinates(Item item, - ZnBool force) +ComputeCoordinates(ZnItem item, + ZnBool force __unused) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; IconItem icon = (IconItem) item; int width, height; - ResetBBox(&item->item_bounding_box); + ZnResetBBox(&item->item_bounding_box); /* * If there is no image then nothing to show. @@ -283,7 +281,7 @@ ComputeCoordinates(Item item, else { pos = icon->pos; } - Anchor2Origin(&pos, width, height, icon->anchor, quad); + ZnAnchor2Origin(&pos, (ZnReal) width, (ZnReal) height, icon->anchor, quad); quad[1].x = quad[0].x; quad[1].y = quad[0].y + height; quad[2].x = quad[0].x + width; @@ -293,14 +291,14 @@ ComputeCoordinates(Item item, ZnTransformPoints(wi->current_transfo, quad, icon->dev, 4); for (i = 0; i < 4; i++) { - icon->dev[i].x = REAL_TO_INT(icon->dev[i].x); - icon->dev[i].y = REAL_TO_INT(icon->dev[i].y); + icon->dev[i].x = ZnNearestInt(icon->dev[i].x); + icon->dev[i].y = ZnNearestInt(icon->dev[i].y); } /* * Compute the bounding box. */ - AddPointsToBBox(&item->item_bounding_box, icon->dev, 4); + ZnAddPointsToBBox(&item->item_bounding_box, icon->dev, 4); } else { if (item->connected_item != ZN_NO_ITEM) { @@ -312,16 +310,16 @@ ComputeCoordinates(Item item, ZnTransformPoint(wi->current_transfo, &icon->pos, icon->dev); } - Anchor2Origin(icon->dev, width, height, icon->anchor, icon->dev); - icon->dev->x = REAL_TO_INT(icon->dev->x); - icon->dev->y = REAL_TO_INT(icon->dev->y); + ZnAnchor2Origin(icon->dev, (ZnReal) width, (ZnReal) height, icon->anchor, icon->dev); + icon->dev->x = ZnNearestInt(icon->dev->x); + icon->dev->y = ZnNearestInt(icon->dev->y); /* * Compute the bounding box. */ - AddPointToBBox(&item->item_bounding_box, icon->dev->x, icon->dev->y); - AddPointToBBox(&item->item_bounding_box, icon->dev->x+width, - icon->dev->y+height); + ZnAddPointToBBox(&item->item_bounding_box, icon->dev->x, icon->dev->y); + ZnAddPointToBBox(&item->item_bounding_box, icon->dev->x+width, + icon->dev->y+height); } item->item_bounding_box.orig.x -= 1.0; @@ -332,7 +330,7 @@ ComputeCoordinates(Item item, /* * Update connected items. */ - SET(item->flags, UPDATE_DEPENDENT_BIT); + SET(item->flags, ZN_UPDATE_DEPENDENT_BIT); } @@ -346,7 +344,7 @@ ComputeCoordinates(Item item, ********************************************************************************** */ static int -ToArea(Item item, +ToArea(ZnItem item, ZnToArea ta) { IconItem icon = (IconItem) item; @@ -356,7 +354,7 @@ ToArea(Item item, return -1; } if (item->wi->render) { - return PolygonInBBox(icon->dev, 4, ta->area, NULL); + return ZnPolygonInBBox(icon->dev, 4, ta->area, NULL); } else { int w, h; @@ -366,7 +364,7 @@ ToArea(Item item, box.corner.x = box.orig.x + w; box.corner.y = box.orig.y + h; - return BBoxInBBox(&box, area); + return ZnBBoxInBBox(&box, area); } } @@ -379,17 +377,17 @@ ToArea(Item item, ********************************************************************************** */ static void -Draw(Item item) +Draw(ZnItem item) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; IconItem icon = (IconItem) item; XGCValues values; - int gc_mask = 0; + unsigned int gc_mask = 0; int w, h; ZnBBox box, inter, *clip_box; - Region clip_region; + TkRegion clip_region, photo_region, clip; ZnBool simple; - Pixmap pixmap, mask_pmap; + Pixmap pixmap; if (icon->image == ZnUnspecifiedImage) { return; @@ -401,88 +399,65 @@ Draw(Item item) box.corner.y = icon->dev->y + h; if (!ZnImageIsBitmap(icon->image)) { /* - * Added the case of a rectangular aligned clipping and the - * simple case of the damaged area clip. These are done here - * to avoid the use of Tk_RedrawImage which use a different - * GC and lead to wrong clip behaviour. - * - * Non rectangular clipping. Two cases here: if the image - * has no contour mask, simply use the clipping set in the - * current gc, if not, we have to generate a bitmap mask - * using the image mask and the current clip and use this - * bitmap as the current clip. + * The code below does not use of Tk_RedrawImage to be + * able to clip with the current clip region. */ - IntersectBBox(&box, &wi->damaged_area, &inter); + ZnIntersectBBox(&box, &wi->damaged_area, &inter); box = inter; ZnCurrentClip(wi, &clip_region, NULL, &simple); - pixmap = ZnImagePixmap(icon->image, &mask_pmap); - if (mask_pmap == ZnUnspecifiedImage || simple) { - if (mask_pmap != ZnUnspecifiedImage) { - XSetClipMask(wi->dpy, wi->gc, mask_pmap); - values.clip_x_origin = (int) icon->dev->x; - values.clip_y_origin = (int) icon->dev->y; - XChangeGC(wi->dpy, wi->gc, GCClipXOrigin|GCClipYOrigin, &values); - } - XCopyArea(wi->dpy, pixmap, wi->draw_buffer, wi->gc, - box.orig.x-icon->dev->x, box.orig.y-icon->dev->y, - box.corner.x-box.orig.x, box.corner.y-box.orig.y, - box.orig.x, box.orig.y); - values.clip_x_origin = values.clip_y_origin = 0; - XChangeGC(wi->dpy, wi->gc, GCClipXOrigin|GCClipYOrigin, &values); - XSetRegion(wi->dpy, wi->gc, clip_region); + pixmap = ZnImagePixmap(icon->image); + photo_region = ZnImageRegion(icon->image); + clip = TkCreateRegion(); + /* + * ZnImageRegion may fail: perl/Tk 800.24 doesn't support + * some internal TkPhoto functions. + * This is a workaround using a rectangular region based + * on the image size. + */ + if (photo_region == NULL) { + XRectangle rect; + rect.x = rect.y = 0; + rect.width = w; + rect.height = h; + TkUnionRectWithRegion(&rect, clip, clip); } else { - GC gc; - /* - * Build of the mask - */ - Pixmap mask_pmap = XCreatePixmap(wi->dpy, ZnWindowId(wi->win), w, h, 1); - gc = XCreateGC(wi->dpy, mask_pmap, 0, NULL); - XFillRectangle(wi->dpy, mask_pmap, gc, 0, 0, w, h); - XSetRegion(wi->dpy, gc, clip_region); - values.foreground = 1; - values.background = 0; - values.clip_x_origin = (int) -icon->dev->x; - values.clip_y_origin = (int) -icon->dev->y; - XChangeGC(wi->dpy, gc, - GCForeground|GCBackground|GCClipXOrigin|GCClipYOrigin, - &values); - XPutImage(wi->dpy, mask_pmap, gc, ZnImageMask(icon->image), 0, 0, 0, 0, w, h); - XFreeGC(wi->dpy, gc); - /* - * Drawing of the icon using the mask. - */ - XSetClipMask(wi->dpy, wi->gc, mask_pmap); - values.clip_x_origin = (int) icon->dev->x; - values.clip_y_origin = (int) icon->dev->y; - XChangeGC(wi->dpy, wi->gc, GCClipXOrigin|GCClipYOrigin, &values); - XCopyArea(wi->dpy, pixmap, wi->draw_buffer, wi->gc, - box.orig.x-icon->dev->x, box.orig.y-icon->dev->y, - box.corner.x-box.orig.x, box.corner.y-box.orig.y, - box.orig.x, box.orig.y); - values.clip_x_origin = values.clip_y_origin = 0; - XChangeGC(wi->dpy, wi->gc, GCClipXOrigin|GCClipYOrigin, &values); - XSetRegion(wi->dpy, wi->gc, clip_region); - XFreePixmap(wi->dpy, mask_pmap); + ZnUnionRegion(clip, photo_region, clip); } + ZnOffsetRegion(clip, (int) icon->dev->x, (int) icon->dev->y); + TkIntersectRegion(clip_region, clip, clip); + TkSetRegion(wi->dpy, wi->gc, clip); + XCopyArea(wi->dpy, pixmap, wi->draw_buffer, wi->gc, + (int) (box.orig.x-icon->dev->x), + (int) (box.orig.y-icon->dev->y), + (unsigned int) (box.corner.x-box.orig.x), + (unsigned int) (box.corner.y-box.orig.y), + (int) box.orig.x, + (int) box.orig.y); + values.clip_x_origin = values.clip_y_origin = 0; + XChangeGC(wi->dpy, wi->gc, GCClipXOrigin|GCClipYOrigin, &values); + TkSetRegion(wi->dpy, wi->gc, clip_region); + TkDestroyRegion(clip); } else { - pixmap = ZnImagePixmap(icon->image, NULL); + pixmap = ZnImagePixmap(icon->image); ZnCurrentClip(wi, NULL, &clip_box, &simple); if (simple) { - IntersectBBox(&box, clip_box, &inter); + ZnIntersectBBox(&box, clip_box, &inter); box = inter; } values.fill_style = FillStippled; values.stipple = pixmap; - values.ts_x_origin = icon->dev->x; - values.ts_y_origin = icon->dev->y; - values.foreground = ZnPixel(ZnGetGradientColor(icon->color, 0, NULL)); + values.ts_x_origin = (int) icon->dev->x; + values.ts_y_origin = (int) icon->dev->y; + values.foreground = ZnPixel(ZnGetGradientColor(icon->color, 0.0, NULL)); gc_mask |= GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin | GCForeground; XChangeGC(wi->dpy, wi->gc, gc_mask, &values); XFillRectangle(wi->dpy, wi->draw_buffer, wi->gc, - box.orig.x, box.orig.y, - box.corner.x-box.orig.x, box.corner.y-box.orig.y); + (int) box.orig.x, + (int) box.orig.y, + (unsigned int) (box.corner.x-box.orig.x), + (unsigned int) (box.corner.y-box.orig.y)); } } @@ -494,19 +469,24 @@ Draw(Item item) * ********************************************************************************** */ +#ifdef GL static void -Render(Item item) +Render(ZnItem item) { -#ifdef GLX - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; IconItem icon = (IconItem) item; if (icon->image != ZnUnspecifiedImage) { ZnRenderImage(wi, icon->image, icon->color, icon->dev, ZnImageIsBitmap(icon->image)); } -#endif } +#else +static void +Render(ZnItem item __unused) +{ +} +#endif /* @@ -517,10 +497,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)); } @@ -533,16 +513,16 @@ IsSensitive(Item item, ********************************************************************************** */ static double -Pick(Item item, +Pick(ZnItem item, ZnPick ps) { IconItem icon = (IconItem) item; - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; double dist; double off_dist = MAX(1, wi->pick_aperture+1); ZnPoint *p = ps->point; - dist = RectangleToPointDist(&item->item_bounding_box, p); + dist = ZnRectangleToPointDist(&item->item_bounding_box, p); /* * If inside the icon rectangle, try to see if the point * is actually on the image or not. If it lies in an @@ -563,7 +543,7 @@ Pick(Item item, dp.y = p->y - icon->dev->y; if (icon->image != ZnUnspecifiedImage) { ZnSizeOfImage(icon->image, &w, &h); - bpixels = ZnImagePattern(icon->image, &stride); + bpixels = ZnImageMask(icon->image, &stride); if (!bpixels) { /* * The image has no bitmap pattern @@ -604,8 +584,8 @@ Pick(Item item, ********************************************************************************** */ static void -PostScript(Item item, - PostScriptInfo ps_info) +PostScript(ZnItem item __unused, + ZnPostScriptInfo ps_info __unused) { } @@ -618,8 +598,8 @@ PostScript(Item item, ********************************************************************************** */ static void -GetAnchor(Item item, - ZnAnchor anchor, +GetAnchor(ZnItem item, + Tk_Anchor anchor, ZnPoint *p) { IconItem icon = (IconItem) item; @@ -629,10 +609,10 @@ GetAnchor(Item item, } else { ZnBBox *bbox = &item->item_bounding_box; - Origin2Anchor(&bbox->orig, - bbox->corner.x - bbox->orig.x, - bbox->corner.y - bbox->orig.y, - anchor, p); + ZnOrigin2Anchor(&bbox->orig, + bbox->corner.x - bbox->orig.x, + bbox->corner.y - bbox->orig.y, + anchor, p); } } @@ -642,12 +622,12 @@ GetAnchor(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) { IconItem icon = (IconItem) item; @@ -655,7 +635,7 @@ GetClipVertices(Item item, ZnPoint *points; if (item->wi->render) { - TRI_STRIP1(tristrip, icon->dev, 4, False); + ZnTriStrip1(tristrip, icon->dev, 4, False); return False; } @@ -665,7 +645,7 @@ GetClipVertices(Item item, ZnSizeOfImage(icon->image, &w, &h); } points = ZnListArray(item->wi->work_pts); - TRI_STRIP1(tristrip, points, 2, False); + ZnTriStrip1(tristrip, points, 2, False); points[0] = *icon->dev; points[1].x = points[0].x + w; points[1].y = points[0].y + h; @@ -686,35 +666,35 @@ GetClipVertices(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 __unused, + int cmd, + ZnPoint **pts, + char **controls __unused, + unsigned int *num_pts) { IconItem icon = (IconItem) item; - if ((cmd == COORDS_ADD) || (cmd == COORDS_ADD_LAST) || (cmd == COORDS_REMOVE)) { + if ((cmd == ZN_COORDS_ADD) || (cmd == ZN_COORDS_ADD_LAST) || (cmd == ZN_COORDS_REMOVE)) { Tcl_AppendResult(item->wi->interp, " icons can't add or remove vertices", NULL); - return ZN_ERROR; + return TCL_ERROR; } - else if ((cmd == COORDS_REPLACE) || (cmd == COORDS_REPLACE_ALL)) { + else if ((cmd == ZN_COORDS_REPLACE) || (cmd == ZN_COORDS_REPLACE_ALL)) { if (*num_pts == 0) { Tcl_AppendResult(item->wi->interp, " coords command need 1 point on icons", NULL); - return ZN_ERROR; + return TCL_ERROR; } icon->pos = (*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)) { *num_pts = 1; *pts = &icon->pos; } - return ZN_OK; + return TCL_OK; } @@ -725,7 +705,7 @@ Coords(Item item, * ********************************************************************************** */ -static ItemClassStruct ICON_ITEM_CLASS = { +static ZnItemClassStruct ICON_ITEM_CLASS = { sizeof(IconItemStruct), 0, /* num_parts */ True, /* has_anchors */ diff --git a/generic/Image.c b/generic/Image.c index 00f5f22..2a0f7c3 100644 --- a/generic/Image.c +++ b/generic/Image.c @@ -25,20 +25,16 @@ */ -#include -#include - #include "Types.h" #include "Image.h" #include "WidgetInfo.h" #include "Geo.h" +#include "Draw.h" + +#include #include -#ifdef GLX +#ifdef GL #include -#include -#include -#include -#include "Draw.h" #endif @@ -48,7 +44,7 @@ static const char compile_id[] = "$Compile: " __FILE__ " " __DATE__ " " __TIME__ static int images_inited = 0; static Tcl_HashTable images; -#ifdef GLX +#ifdef GL static Tcl_HashTable font_textures; #endif @@ -56,14 +52,13 @@ typedef struct _ImageStruct { union { struct { Pixmap pixmap; - Pixmap mask_pmap; Screen *screen; } x; struct { -#ifdef GLX +#ifdef GL GLuint texobj; #endif - struct _WidgetInfo *wi; + struct _ZnWInfo *wi; } gl; } i; struct _ImageBits *bits; @@ -77,177 +72,34 @@ typedef struct _ImageStruct { typedef struct _ImageBits { - int width; - int height; - unsigned char *bpixels; /* Needed at least to know the bounds (Pick), or if - * the image is a bitmap. Can be NULL if no mask is - * defined for the image (i.e the image is - * rectangular) and the image is not a bitmap. */ + unsigned char *bpixels; /* Needed for bitmaps. Set to NULL if the image + * is a photo. */ int rowstride; -#ifdef GLX +#ifdef GL ZnReal t; /* Texture parameters for the image. */ ZnReal s; -#endif - - /* Bookeeping */ - - Tcl_HashEntry *hash; /* From this it is easy to get the image/bitmap - * name. */ - XImage *ipixels; /* Keep this to create textures and pixmaps as - * needed. NULL if the image is a bitmap. This - * can be tested to tell if this is an image or - * a bitmap. */ - XImage *mask; /* Keep this to build special clip mask in X (Icon). - * Can be NULL if no mask is defined for the image - * (i.e the image is rectangular) or if the image - * is a bitmap. */ -#ifdef GLX int t_width; /* Texture size used for this image. */ int t_height; unsigned char *t_bits; /* Can be NULL if texture is not used (no GL * rendering active on this image). */ #endif + + /* Bookeeping */ + Tk_Image tkimage; /* Keep this handle to be informed of changes */ + Tk_PhotoHandle tkphoto; + int width; + int height; + Tcl_HashEntry *hash; /* From this it is easy to get the image/bitmap + * name. */ Image images; /* Linked list of widget/display dependant * specializations of this image. If NULL, the * image has no specialization and can be freed. */ } ImageBits; -#ifdef GLX -/* - * Working only for 16 bits displays with 5r6g5b mask, - * and 24/32 bits displays. Byte ordering ok on Intel - * plateform only. - */ -static void -From5r6g5b(unsigned char *data, - int width, - int height, - int bytes_per_line, - int t_width, - int t_height, - unsigned char *bpixels, - int bstride, - unsigned char *t_bits) -{ - int x, y; - int rowstride = t_width * 4; - unsigned char *obptr; - unsigned char *bptr, *bp2; - unsigned char alpha; - unsigned short temp; - - bptr = t_bits; - - for (y = 0; y < height; y++) { - bp2 = bptr; - obptr = data; - for (x = 0; x < width; x++) { - /* - * Configure the alpha value. - */ - if (bpixels) { - alpha = ZnGetBitmapPixel(bpixels, bstride, x, y) ? 255 : 0; - } - else { - alpha = 255; - } +char *ZnNameOfImage(ZnImage image); - /* - * Dispatch the 3 color components. - */ - temp = ((unsigned short *)obptr)[0]; - *bp2 = (temp >> 8) & 0xf8; /* r */ - bp2++; - *bp2 = (temp >> 3) & 0xfc; /* v */ - bp2++; - *bp2 = (temp << 3); /* b */ - bp2++; - *bp2 = alpha; - bp2++; - obptr += 2; - } - for (x = width; x < t_width; x++) { - *bp2 = 0; - bp2++; - *bp2 = 0; - bp2++; - *bp2 = 0; - bp2++; - *bp2 = 0; - bp2++; - } - bptr += rowstride; - data += bytes_per_line; - } - for (y = height; y < t_height; y++) { - memset(bptr, 0, rowstride); - bptr += rowstride; - } -} - -static void -From8r8g8b(unsigned char *data, - int width, - int height, - int bytes_per_line, - int t_width, - int t_height, - unsigned char *bpixels, - int bstride, - unsigned char *t_bits) -{ - int x, y; - int rowstride = t_width * 4; - unsigned char *obptr; - unsigned char *bptr, *bp2; - unsigned char alpha; - - bptr = t_bits; - - for (y = 0; y < height; y++) { - bp2 = bptr; - obptr = data; - for (x = 0; x < width; x++) { - /* - * Configure the alpha value. - */ - if (bpixels) { - alpha = ZnGetBitmapPixel(bpixels, bstride, x, y) ? 255 : 0; - } - else { - alpha = 255; - } - - /* - * Dispatch the 3 color components. - * Be careful the Red and Blue are swapped it works on an Intel - * plateform but may need some more tests to be fully generic. - */ - *bp2++ = obptr[2]; /* r */ - *bp2++ = obptr[1]; /* v */ - *bp2++ = obptr[0]; /* b */ - obptr += 4; - *bp2++ = alpha; - } - for (x = width; x < t_width; x++) { - *bp2 = 0; - bp2++; - *bp2 = 0; - bp2++; - *bp2 = 0; - bp2++; - *bp2 = 0; - bp2++; - } - bptr += rowstride; - data += bytes_per_line; - } - for (y = height; y < t_height; y++) { - memset(bptr, 0, rowstride); - bptr += rowstride; - } -} +#ifdef GL static int To2Power(int a) @@ -270,99 +122,73 @@ To2Power(int a) ********************************************************************************** */ static void -InvalidateImage(ClientData client_data, - int x, - int y, - int width, - int height, - int image_width, - int image_height) +InvalidateImage(ClientData client_data __unused, + int x __unused, + int y __unused, + int width __unused, + int height __unused, + int image_width __unused, + int image_height __unused) { /* * Void stub that keeps the Tk image mecanism happy. Zinc does - * _not_ implement image update. + * _not_ implement image update yet. */ } -static void -GatherImageBits(WidgetInfo *wi, - Tk_Image tkimage, - ImageBits *bits) +ZnImage +ZnGetImage(ZnWInfo *wi, + Tk_Uid image_name) { - Pixmap pmap; - int depth = DefaultDepthOfScreen(wi->screen); - int x, y; - unsigned char *line; - GC gc; - XImage *im1, *im2; - ZnBool full_mask=True; + Tcl_HashEntry *entry; + int new; + ImageBits *bits; + ZnBool for_gl = wi->render>0; + Image image; - /* - * Nothing known about this image, collect the image bits. - */ - pmap = XCreatePixmap(wi->dpy, RootWindowOfScreen(wi->screen), - bits->width, bits->height, depth); - gc = XCreateGC(wi->dpy, pmap, 0, NULL); - XSetForeground(wi->dpy, gc, 0); - XFillRectangle(wi->dpy, pmap, gc, 0, 0, bits->width, bits->height); - Tk_RedrawImage(tkimage, 0, 0, bits->width, bits->height, pmap, 0, 0); - im1 = bits->ipixels = XGetImage(wi->dpy, pmap, 0, 0, - bits->width, bits->height, ~0L, ZPixmap); - - XSetForeground(wi->dpy, gc, 1); - XFillRectangle(wi->dpy, pmap, gc, 0, 0, bits->width, bits->height); - Tk_RedrawImage(tkimage, 0, 0, bits->width, bits->height, pmap, 0, 0); - im2 = XGetImage(wi->dpy, pmap, 0, 0, bits->width, bits->height, ~0L, ZPixmap); - XFreePixmap(wi->dpy, pmap); - - /* - * The image structure can be setup locally (TODO). - */ - XFreeGC(wi->dpy, gc); - pmap = XCreatePixmap(wi->dpy, RootWindowOfScreen(wi->screen), - bits->width, bits->height, 1); - gc = XCreateGC(wi->dpy, pmap, 0, NULL); - XSetForeground(wi->dpy, gc, 0); - XFillRectangle(wi->dpy, pmap, gc, 0, 0, bits->width, bits->height); - XFreeGC(wi->dpy, gc); - bits->mask = XGetImage(wi->dpy, pmap, 0, 0, bits->width, bits->height, 1, XYPixmap); - XFreePixmap(wi->dpy, pmap); - - bits->rowstride = bits->mask->bytes_per_line; - bits->bpixels = ZnMalloc(bits->height * bits->rowstride); - memset(bits->bpixels, 0, bits->height * bits->rowstride); - line = bits->bpixels; - for (y = 0; y < bits->height; y++) { - for (x = 0; x < bits->width; x++) { - if (XGetPixel(im1, x, y) == XGetPixel(im2, x, y)) { - XPutPixel(bits->mask, x, y, 1L); - line[x >> 3] |= 0x80 >> (x & 7); - } - else { - full_mask = False; + /*printf("ZnGetImage: %s\n", image_name);*/ + if (!images_inited) { + Tcl_InitHashTable(&images, TCL_STRING_KEYS); + images_inited = 1; + } + image_name = Tk_GetUid(image_name); + entry = Tcl_FindHashEntry(&images, image_name); + if (entry != NULL) { + /*printf("Image %s déjà connue\n", image_name);*/ + bits = (ImageBits *) Tcl_GetHashValue(entry); + } + else { + /*printf("Nouvelle Image %s\n", image_name);*/ + if (strcmp(image_name, "") == 0) { + return ZnUnspecifiedImage; + } + bits = ZnMalloc(sizeof(ImageBits)); + bits->tkphoto = Tk_FindPhoto(wi->interp, image_name); + if (bits->tkphoto == NULL) { + im_val_err: + ZnWarning("unknown or bogus photo image \""); + ZnWarning(image_name); + ZnWarning("\"\n"); + ZnFree(bits); + return ZnUnspecifiedImage; + } + else { + Tk_PhotoGetSize(bits->tkphoto, &bits->width, &bits->height); + if ((bits->width == 0) || (bits->height == 0)) { + goto im_val_err; } +#ifdef GL + bits->t_bits = NULL; +#endif + bits->images = NULL; + bits->bpixels = NULL; + bits->tkimage = Tk_GetImage(wi->interp, wi->win, image_name, + InvalidateImage, (ClientData) bits); + entry = Tcl_CreateHashEntry(&images, image_name, &new); + bits->hash = entry; + Tcl_SetHashValue(entry, (ClientData) bits); } - line += bits->rowstride; } - - XDestroyImage(im2); - if (full_mask) { - XDestroyImage(bits->mask); - bits->mask = NULL; - ZnFree(bits->bpixels); - bits->bpixels = NULL; - } -} - -static Image -GetImageInstance(WidgetInfo *wi, - ImageBits *bits) -{ - int depth = DefaultDepthOfScreen(wi->screen); - ZnBool for_gl = wi->render>0; - XGCValues values; - GC gc; - Image image; /* * Try to find an image instance that fits this widget/display. @@ -386,33 +212,35 @@ GetImageInstance(WidgetInfo *wi, image->bits = bits; image->refcount = 1; image->for_gl = for_gl; + if (image->for_gl) { image->i.gl.wi = wi; -#ifdef GLX +#ifdef GL image->i.gl.texobj = 0; #endif } else { + Tk_Image tkimage; + image->i.x.screen = wi->screen; - image->i.x.pixmap = XCreatePixmap(wi->dpy, RootWindowOfScreen(wi->screen), - bits->width, bits->height, depth); - gc = XCreateGC(wi->dpy, image->i.x.pixmap, 0, NULL); - XPutImage(wi->dpy, image->i.x.pixmap, gc, bits->ipixels, 0, 0, 0, 0, - bits->width, bits->height); - XFreeGC(wi->dpy, gc); - if (bits->mask) { - image->i.x.mask_pmap = XCreatePixmap(wi->dpy, RootWindowOfScreen(wi->screen), - bits->width, bits->height, 1); - values.foreground = 1; - values.background = 0; - gc = XCreateGC(wi->dpy, image->i.x.mask_pmap, - GCForeground|GCBackground, &values); - XPutImage(wi->dpy, image->i.x.mask_pmap, gc, bits->mask, 0, 0, 0, 0, - bits->width, bits->height); - XFreeGC(wi->dpy, gc); + if (bits->images == NULL) { + /* This is the first instance we can use safely the + * main tkimage. + */ + tkimage = bits->tkimage; } else { - image->i.x.mask_pmap = None; + /* Create a temporary tkimage to draw the pixmap. + */ + tkimage = Tk_GetImage(wi->interp, wi->win, image_name, NULL, NULL); + } + image->i.x.pixmap = Tk_GetPixmap(wi->dpy, RootWindowOfScreen(wi->screen), + bits->width, bits->height, + DefaultDepthOfScreen(wi->screen)); + Tk_RedrawImage(tkimage, 0, 0, bits->width, bits->height, + image->i.x.pixmap, 0, 0); + if (tkimage != bits->tkimage) { + Tk_FreeImage(tkimage); } } image->next = bits->images; @@ -421,73 +249,6 @@ GetImageInstance(WidgetInfo *wi, return image; } -ZnImage -ZnGetImage(WidgetInfo *wi, - Tk_Uid image_name) -{ - Tcl_HashEntry *entry; - int new; - ImageBits *bits; - Tk_Image tkimage; - - /*printf("ZnGetImage: %s\n", image_name);*/ - if (!images_inited) { - Tcl_InitHashTable(&images, TCL_STRING_KEYS); - images_inited = 1; - } - image_name = Tk_GetUid(image_name); - entry = Tcl_FindHashEntry(&images, image_name); - if (entry != NULL) { - /*printf("Image %s déjà connue\n", image_name);*/ - bits = (ImageBits *) Tcl_GetHashValue(entry); - return GetImageInstance(wi, bits); - } - else { - /*printf("Nouvelle Image %s\n", image_name);*/ - if (strcmp(image_name, "") == 0) { - return ZnUnspecifiedImage; - } - bits = ZnMalloc(sizeof(ImageBits)); - tkimage = Tk_GetImage(wi->interp, wi->win, image_name, - InvalidateImage, (ClientData) bits); - if (tkimage == NULL) { - im_val_err: - ZnFree(bits); - ZnWarning("unknown or bogus image \""); - ZnWarning(image_name); - ZnWarning("\"\n"); - return ZnUnspecifiedImage; - } - else { - Tk_SizeOfImage(tkimage, &bits->width, &bits->height); - if ((bits->width == 0) || (bits->height == 0)) { - Tk_FreeImage(tkimage); - goto im_val_err; - } - } -#ifdef GLX - bits->t_bits = NULL; -#endif - bits->images = NULL; - bits->mask = NULL; - bits->bpixels = NULL; - bits->ipixels = NULL; - entry = Tcl_CreateHashEntry(&images, image_name, &new); - bits->hash = entry; - Tcl_SetHashValue(entry, (ClientData) bits); - } - - if (!bits->ipixels) { - /* - * First time use of the image, read in - * the bits and free the Tk image. - */ - GatherImageBits(wi, tkimage, bits); - Tk_FreeImage(tkimage); - } - return GetImageInstance(wi, bits); -} - /* ********************************************************************************** * @@ -496,17 +257,13 @@ ZnGetImage(WidgetInfo *wi, ********************************************************************************** */ ZnImage -ZnGetBitmap(WidgetInfo *wi, +ZnGetBitmap(ZnWInfo *wi, Tk_Uid bitmap_name) { Tcl_HashEntry *entry; ImageBits *bits; - Pixmap pmap; - XImage *mask; Image image; ZnBool for_gl = wi->render>0; - int x, y, new, width, height; - unsigned char *line; /*printf("ZnGetBitmap: %s\n", bitmap_name);*/ if (!images_inited) { @@ -519,28 +276,29 @@ ZnGetBitmap(WidgetInfo *wi, bits = (ImageBits *) Tcl_GetHashValue(entry); } else { + Pixmap pmap; + XImage *mask; + int x, y, new; + unsigned char *line; + pmap = Tk_GetBitmap(wi->interp, wi->win, bitmap_name); if (pmap == ZnUnspecifiedImage) { return ZnUnspecifiedImage; } - Tk_SizeOfBitmap(wi->dpy, pmap, &width, &height); bits = ZnMalloc(sizeof(ImageBits)); - bits->width = width; - bits->height = height; -#ifdef GLX + Tk_SizeOfBitmap(wi->dpy, pmap, &bits->width, &bits->height); +#ifdef GL bits->t_bits = NULL; #endif bits->images = NULL; - bits->mask = NULL; - bits->bpixels = NULL; - bits->ipixels = NULL; - mask = XGetImage(wi->dpy, pmap, 0, 0, width, height, 1L, XYPixmap); + mask = XGetImage(wi->dpy, pmap, 0, 0, (unsigned int) bits->width, + (unsigned int) bits->height, 1L, XYPixmap); bits->rowstride = mask->bytes_per_line; - bits->bpixels = ZnMalloc(height * bits->rowstride); - memset(bits->bpixels, 0, height * bits->rowstride); + bits->bpixels = ZnMalloc((unsigned int) (bits->height * bits->rowstride)); + memset(bits->bpixels, 0, (unsigned int) (bits->height * bits->rowstride)); line = bits->bpixels; - for (y = 0; y < height; y++) { - for (x = 0; x < width; x++) { + for (y = 0; y < bits->height; y++) { + for (x = 0; x < bits->width; x++) { if (XGetPixel(mask, x, y)) { line[x >> 3] |= 0x80 >> (x & 7); } @@ -579,13 +337,12 @@ ZnGetBitmap(WidgetInfo *wi, image->for_gl = for_gl; if (image->for_gl) { image->i.gl.wi = wi; -#ifdef GLX +#ifdef GL image->i.gl.texobj = 0; #endif } else { image->i.x.screen = wi->screen; - image->i.x.mask_pmap = None; /* * Need to get a pixmap that match this dpy. */ @@ -615,6 +372,19 @@ ZnGetImageByValue(ZnImage image) /* ********************************************************************************** * + * ZnImageIsBitmap -- + * + ********************************************************************************** + */ +ZnBool +ZnImageIsBitmap(ZnImage image) +{ + return (((Image) image)->bits->bpixels != NULL); +} + +/* + ********************************************************************************** + * * ZnFreeImage -- * ********************************************************************************** @@ -649,24 +419,20 @@ ZnFreeImage(ZnImage image) prev->next = this->next; } if (this->for_gl) { -#ifdef GLX - WidgetInfo *wi = this->i.gl.wi; +#ifdef GL + ZnWInfo *wi = this->i.gl.wi; if (this->i.gl.texobj && wi->win) { - glXMakeCurrent(wi->dpy, ZnWindowId(wi->win), wi->gl_context); + ZnGLMakeCurrent(wi); glDeleteTextures(1, &this->i.gl.texobj); + ZnGLRelease(wi); } #endif } - else if (bits->ipixels) { + else if (!ZnImageIsBitmap(image)) { /* - * This is an image, we need to free the pixmaps. + * This is an image, we need to free the instances. */ - if (this->i.x.pixmap != None) { - XFreePixmap(DisplayOfScreen(this->i.x.screen), this->i.x.pixmap); - } - if (this->i.x.mask_pmap != None) { - XFreePixmap(DisplayOfScreen(this->i.x.screen), this->i.x.mask_pmap); - } + Tk_FreePixmap(DisplayOfScreen(this->i.x.screen), this->i.x.pixmap); } else { /* @@ -681,20 +447,17 @@ ZnFreeImage(ZnImage image) */ if (bits->images == NULL) { /*printf("destruction complète de l'image %s\n", ZnNameOfImage(this));*/ -#ifdef GLX +#ifdef GL if (bits->t_bits) { ZnFree(bits->t_bits); } #endif - if (bits->mask) { - XDestroyImage(bits->mask); - } - if (bits->ipixels) { - XDestroyImage(bits->ipixels); - } - if (bits->bpixels) { + if (ZnImageIsBitmap(image)) { ZnFree(bits->bpixels); } + else { + Tk_FreeImage(bits->tkimage); + } Tcl_DeleteHashEntry(bits->hash); ZnFree(bits); } @@ -727,40 +490,30 @@ ZnSizeOfImage(ZnImage image, int *width, int *height) { - Image im = (Image) image; - *width = im->bits->width; - *height = im->bits->height; + Image this = (Image) image; + + *width = this->bits->width; + *height = this->bits->height; } /* ********************************************************************************** * - * ZnImagePattern -- + * ZnImagePixmap -- * ********************************************************************************** */ -char * -ZnImagePattern(ZnImage image, - int *stride) +Pixmap +ZnImagePixmap(ZnImage image) { - if (stride) { - *stride = ((Image) image)->bits->rowstride; - } - return ((Image) image)->bits->bpixels; -} + Image this = (Image) image; -/* - ********************************************************************************** - * - * ZnImageIsBitmap -- - * - ********************************************************************************** - */ -ZnBool -ZnImageIsBitmap(ZnImage image) -{ - return (((Image) image)->bits->ipixels == NULL); + if (this->for_gl) { + printf("Bogus use of an image, it was created for GL and used in an X11 context\n"); + return None; + } + return this->i.x.pixmap; } /* @@ -770,31 +523,38 @@ ZnImageIsBitmap(ZnImage image) * ********************************************************************************** */ -XImage * -ZnImageMask(ZnImage image) +char * +ZnImageMask(ZnImage image, + int *stride) { - return ((Image) image)->bits->mask; + Image this = (Image) image; + + if (stride) { + *stride = this->bits->rowstride; + } + return this->bits->bpixels; } /* ********************************************************************************** * - * ZnImagePixmap -- + * ZnImageRegion -- * ********************************************************************************** */ -Pixmap -ZnImagePixmap(ZnImage image, - Pixmap *mask_pmap) +TkRegion +ZnImageRegion(ZnImage image) { - if (((Image) image)->for_gl) { - printf("Bogus use of an image, it was created for GL and use in an X11 context\n"); - return None; + if (ZnImageIsBitmap(image)) { + return NULL; } - if (mask_pmap) { - *mask_pmap = ((Image) image)->i.x.mask_pmap; + else { +#ifdef PTK + return NULL; +#else + return TkPhotoGetValidRegion(((Image) image)->bits->tkphoto); +#endif } - return ((Image) image)->i.x.pixmap; } /* @@ -804,28 +564,32 @@ ZnImagePixmap(ZnImage image, * ********************************************************************************** */ -#ifdef GLX +#ifdef GL GLuint ZnImageTex(ZnImage image, ZnReal *t, ZnReal *s) { - Image this = (Image) image; - ImageBits *bits = this->bits; - ZnBool is_bmap = ZnImageIsBitmap(image); - int depth, t_size; + Image this = (Image) image; + ImageBits *bits = this->bits; + ZnBool is_bmap = ZnImageIsBitmap(image); + unsigned int t_size, width, height; + Tk_PhotoImageBlock block; + int green_off, blue_off, alpha_off; if (!this->for_gl) { + printf("Bogus use of an image, it was created for X11 and used in a GL context\n"); return 0; } + ZnSizeOfImage(image, &width, &height); if (!bits->t_bits) { /*printf("chargement texture pour image %s\n", ZnNameOfImage(this));*/ - bits->t_width = To2Power(bits->width); - bits->t_height = To2Power(bits->height); - bits->s = bits->width / (ZnReal) bits->t_width; - bits->t = bits->height / (ZnReal) bits->t_height; + bits->t_width = To2Power((int) width); + bits->t_height = To2Power((int) height); + bits->s = width / (ZnReal) bits->t_width; + bits->t = height / (ZnReal) bits->t_height; if (is_bmap) { - int i, j; + unsigned int i, j; unsigned char *ostart, *dstart, *d, *o; t_size = bits->t_width * bits->t_height; @@ -833,10 +597,10 @@ ZnImageTex(ZnImage image, memset(bits->t_bits, 0, t_size); ostart = bits->bpixels; dstart = bits->t_bits; - for (i = 0; i < bits->height; i++) { + for (i = 0; i < height; i++) { d = dstart; o = ostart; - for (j = 0; j < bits->width; j++) { + for (j = 0; j < width; j++) { *d++ = ZnGetBitmapPixel(bits->bpixels, bits->rowstride, j, i) ? 255 : 0; } ostart += bits->rowstride; @@ -844,24 +608,42 @@ ZnImageTex(ZnImage image, } } else { - t_size = bits->t_width * 4 * bits->t_height; + unsigned int x, y, t_stride; + unsigned char *obptr, *bptr, *bp2, *pixels; + + t_stride = bits->t_width * 4; + t_size = t_stride * bits->t_height; bits->t_bits = ZnMalloc(t_size); - if (this->for_gl) { - depth = DefaultDepthOfScreen(this->i.gl.wi->screen); - } - else { - depth = DefaultDepthOfScreen(this->i.x.screen); - } - if (depth == 16) { - From5r6g5b(bits->ipixels->data, bits->width, bits->height, - bits->ipixels->bytes_per_line, bits->t_width, bits->t_height, - bits->bpixels, bits->rowstride, bits->t_bits); - } - else if ((depth == 24) || (depth == 32)) { - From8r8g8b(bits->ipixels->data, bits->width, bits->height, - bits->ipixels->bytes_per_line, bits->t_width, bits->t_height, - bits->bpixels, bits->rowstride, bits->t_bits); + Tk_PhotoGetImage(bits->tkphoto, &block); + green_off = block.offset[1] - block.offset[0]; + blue_off = block.offset[2] - block.offset[0]; + alpha_off = block.offset[3] - block.offset[0]; + pixels = block.pixelPtr; + bptr = bits->t_bits; + + for (y = 0; y < height; y++) { + bp2 = bptr; + obptr = pixels; + for (x = 0; x < width; x++) { + *bp2++ = obptr[0]; /* r */ + *bp2++ = obptr[green_off]; /* g */ + *bp2++ = obptr[blue_off]; /* b */ + *bp2++ = obptr[alpha_off]; /* alpha */ + obptr += 4; + } + /*for (x = width; x < t_width; x++) { + *bp2 = 0; bp2++; + *bp2 = 0; bp2++; + *bp2 = 0; bp2++; + *bp2 = 0; bp2++; + }*/ + bptr += t_stride; + pixels += block.pitch; } + /*for (y = height; y < t_height; y++) { + memset(bptr, 0, t_stride); + bptr += t_stride; + }*/ } } if (!this->i.gl.texobj) { @@ -885,6 +667,7 @@ ZnImageTex(ZnImage image, } glBindTexture(GL_TEXTURE_2D, 0); } + *t = this->bits->t; *s = this->bits->s; return this->i.gl.texobj; @@ -892,25 +675,25 @@ ZnImageTex(ZnImage image, #endif - -#ifdef GLX +#ifdef GL /* Copyright (c) Mark J. Kilgard, 1997. */ /* This program is freely distributable without licensing fees and is provided without guarantee or warrantee expressed or implied. This program is -not- in the public domain. */ -#define MAX_GLYPHS_PER_GRAB 512 /* this is big enough for 2^9 glyph - * character sets */ +#define MAX_CHAR (256-32-1) +#define MIN_CHAR 32 +#define MAX_GLYPHS_PER_GRAB 256 typedef struct { - unsigned short c; /* Potentially support 16-bit glyphs. */ - unsigned char width; - unsigned char height; - char xoffset; - char yoffset; - char advance; + unsigned char c; char dummy; /* Space holder for alignment reasons. */ + short width; + short height; + short xoffset; + short yoffset; + short advance; short x; short y; } TexGlyphInfo; @@ -918,21 +701,21 @@ typedef struct { typedef struct _TexFontInfo { GLuint texobj; struct _TexFont *txf; - WidgetInfo *wi; - int refcount; + ZnWInfo *wi; + unsigned int refcount; struct _TexFontInfo *next; } TexFontInfo; typedef struct _TexFont { TexFontInfo *tfi; - ZnFont tkfont; + Tk_Font tkfont; int tex_width; int tex_height; - int max_ascent; - int max_descent; - int num_glyphs; - int min_glyph; - int range; + int ascent; + int descent; + unsigned int num_glyphs; + unsigned int min_glyph; + unsigned int range; unsigned char *teximage; TexGlyphInfo *tgi; ZnTexGVI *tgvi; @@ -952,9 +735,9 @@ typedef struct { typedef struct { int min_char; int max_char; - int max_ascent; - int max_descent; - int num_glyphs; + int ascent; + int descent; + unsigned int num_glyphs; PerGlyphInfo glyph[1]; } FontInfo, *FontInfoPtr; @@ -1015,7 +798,7 @@ void placeGlyph(FontInfoPtr font, int c, unsigned char *texarea, - int stride, + unsigned int stride, int x, int y) { @@ -1044,51 +827,50 @@ placeGlyph(FontInfoPtr font, } FontInfoPtr -SuckGlyphsFromServer(ZnWindow win, - ZnFont font) +SuckGlyphsFromServer(ZnWInfo *wi, + Tk_Font font) { - Display *dpy = Tk_Display(win); - XFontStruct *fontinfo = NULL; Pixmap offscreen = 0; XImage *image = NULL; GC xgc = 0; XGCValues values; - int width, height, pixwidth; - int i, j; - XCharStruct *charinfo=NULL; - XChar2b character; + unsigned int width, height, length, pixwidth; + unsigned int i, j; + char str[] = " "; unsigned char *bitmapData = NULL; - int x, y; - int numchars, spanLength=0; - int charWidth=0, charHeight=0, maxSpanLength; + unsigned int x, y; + int num_chars, spanLength=0; + unsigned int charWidth=0, maxSpanLength; int grabList[MAX_GLYPHS_PER_GRAB]; - int glyphsPerGrab = MAX_GLYPHS_PER_GRAB; - int numToGrab, thisglyph; + unsigned int glyphsPerGrab = MAX_GLYPHS_PER_GRAB; + unsigned int numToGrab, thisglyph; FontInfoPtr myfontinfo = NULL; - - fontinfo = XQueryFont(dpy, Tk_FontId(font)); - if (!fontinfo) { - return NULL; - } - - numchars = fontinfo->max_char_or_byte2 - fontinfo->min_char_or_byte2 + 1; - if (numchars < 1) { - return NULL; - } + Tk_FontMetrics fm; - myfontinfo = (FontInfoPtr) ZnMalloc(sizeof(FontInfo) + (numchars - 1) * sizeof(PerGlyphInfo)); + Tk_GetFontMetrics(font, &fm); + num_chars = (MAX_CHAR-MIN_CHAR)+1; + myfontinfo = ZnMalloc(sizeof(FontInfo) + num_chars * sizeof(PerGlyphInfo)); if (!myfontinfo) { return NULL; } - myfontinfo->num_glyphs = numchars; - myfontinfo->min_char = fontinfo->min_char_or_byte2; - myfontinfo->max_char = fontinfo->max_char_or_byte2; - myfontinfo->max_ascent = fontinfo->max_bounds.ascent; - myfontinfo->max_descent = fontinfo->max_bounds.descent; + myfontinfo->min_char = MIN_CHAR; + myfontinfo->max_char = MAX_CHAR; + myfontinfo->num_glyphs = num_chars; + myfontinfo->ascent = fm.ascent; + myfontinfo->descent = fm.descent; - width = fontinfo->max_bounds.rbearing - fontinfo->min_bounds.lbearing; - height = fontinfo->max_bounds.ascent + fontinfo->max_bounds.descent; + /* + * Try to guess a good approximation for the largest character + * in the font. This guess may be quite wrong for symbol fonts + * and for non european languages. + */ + *str = 'W'; + Tk_MeasureChars(font, str, 1, 0, TK_AT_LEAST_ONE, &width); + *str = 'M'; + Tk_MeasureChars(font, str, 1, 0, TK_AT_LEAST_ONE, &length); + width = MAX(width, length); + height = myfontinfo->ascent + myfontinfo->descent; maxSpanLength = (width + 7) / 8; /* Be careful determining the width of the pixmap; the X protocol allows @@ -1099,110 +881,85 @@ SuckGlyphsFromServer(ZnWindow win, glyphsPerGrab = (1 << 15) / (8 * maxSpanLength); } pixwidth = glyphsPerGrab * 8 * maxSpanLength; - offscreen = XCreatePixmap(dpy, RootWindow(dpy, DefaultScreen(dpy)), - pixwidth, height, 1); - + offscreen = Tk_GetPixmap(wi->dpy, RootWindowOfScreen(wi->screen), + (int) pixwidth, (int) height, 1); + + values.background = WhitePixelOfScreen(wi->screen); + values.foreground = WhitePixelOfScreen(wi->screen); values.font = Tk_FontId(font); - values.background = 0; - values.foreground = 0; - xgc = XCreateGC(dpy, offscreen, GCFont | GCBackground | GCForeground, &values); - - XFillRectangle(dpy, offscreen, xgc, 0, 0, 8 * maxSpanLength * glyphsPerGrab, height); - XSetForeground(dpy, xgc, 1); + xgc = XCreateGC(wi->dpy, offscreen, GCBackground|GCForeground|GCFont, &values); + XFillRectangle(wi->dpy, offscreen, xgc, 0, 0, pixwidth, height); + values.foreground = BlackPixelOfScreen(wi->screen); + XChangeGC(wi->dpy, xgc, GCForeground, &values); numToGrab = 0; - if (fontinfo->per_char == NULL) { - charinfo = &(fontinfo->min_bounds); - charWidth = charinfo->rbearing - charinfo->lbearing; - charHeight = charinfo->ascent + charinfo->descent; - spanLength = (charWidth + 7) / 8; - } for (i = 0; i < myfontinfo->num_glyphs; i++) { - if (fontinfo->per_char != NULL) { - charinfo = &(fontinfo->per_char[i]); - charWidth = charinfo->rbearing - charinfo->lbearing; - charHeight = charinfo->ascent + charinfo->descent; - if (charWidth == 0 || charHeight == 0) { - /* Still must move raster pos even if empty character */ - myfontinfo->glyph[i].width = 0; - myfontinfo->glyph[i].height = 0; - myfontinfo->glyph[i].xoffset = 0; - myfontinfo->glyph[i].yoffset = 0; - myfontinfo->glyph[i].advance = charinfo->width; - myfontinfo->glyph[i].bitmap = NULL; - goto PossiblyDoGrab; - } + *str = i + myfontinfo->min_char; + Tk_MeasureChars(font, str, 1, 0, TK_AT_LEAST_ONE, &charWidth); + + myfontinfo->glyph[i].width = charWidth; + myfontinfo->glyph[i].height = height; + myfontinfo->glyph[i].xoffset = 0; + myfontinfo->glyph[i].yoffset = myfontinfo->descent; + myfontinfo->glyph[i].advance = charWidth; + myfontinfo->glyph[i].bitmap = NULL; + if (charWidth != 0) { + Tk_DrawChars(wi->dpy, offscreen, xgc, font, str, 1, + (int) (8*maxSpanLength*numToGrab), myfontinfo->ascent); + grabList[numToGrab] = i; + numToGrab++; } - grabList[numToGrab] = i; - - /* XXX is this right for large fonts? */ - character.byte2 = (i + fontinfo->min_char_or_byte2) & 255; - character.byte1 = (i + fontinfo->min_char_or_byte2) >> 8; - - XDrawString16(dpy, offscreen, xgc, - -charinfo->lbearing + 8 * maxSpanLength * numToGrab, - charinfo->ascent, &character, 1); - - numToGrab++; - PossiblyDoGrab: if ((numToGrab >= glyphsPerGrab) || (i == myfontinfo->num_glyphs - 1)) { - image = XGetImage(dpy, offscreen, 0, 0, pixwidth, height, 1, XYPixmap); + image = XGetImage(wi->dpy, offscreen, 0, 0, pixwidth, height, 1, XYPixmap); + for (j = 0; j < numToGrab; j++) { - thisglyph = grabList[j]; - if (fontinfo->per_char != NULL) { - charinfo = &(fontinfo->per_char[thisglyph]); - charWidth = charinfo->rbearing - charinfo->lbearing; - charHeight = charinfo->ascent + charinfo->descent; - spanLength = (charWidth + 7) / 8; - } - bitmapData = ZnMalloc(height * spanLength * sizeof(char)); - if (bitmapData == NULL) { - goto FreeFontAndReturn; + thisglyph = grabList[j]; + charWidth = myfontinfo->glyph[thisglyph].width; + spanLength = (charWidth + 7) / 8; + bitmapData = ZnMalloc(height * spanLength * sizeof(char)); + if (bitmapData == NULL) { + goto FreeFontAndReturn; } memset(bitmapData, 0, height * spanLength * sizeof(char)); - for (y = 0; y < charHeight; y++) { - for (x = 0; x < charWidth; x++) { - /* XXX The algorithm used to suck across the font ensures that - each glyph begins on a byte boundary. In theory this would - make it convienent to copy the glyph into a byte oriented - bitmap. We actually use the XGetPixel function to extract - each pixel from the image which is not that efficient. We - could either do tighter packing in the pixmap or more - efficient extraction from the image. Oh well. */ - if (XGetPixel(image, j * maxSpanLength * 8 + x, y)) { - bitmapData[y * spanLength + x / 8] |= (1 << (x & 7)); - } - } - } - myfontinfo->glyph[thisglyph].width = charWidth; - myfontinfo->glyph[thisglyph].height = charHeight; - myfontinfo->glyph[thisglyph].xoffset = charinfo->lbearing; - myfontinfo->glyph[thisglyph].yoffset = charinfo->descent; - myfontinfo->glyph[thisglyph].advance = charinfo->width; - myfontinfo->glyph[thisglyph].bitmap = bitmapData; + myfontinfo->glyph[thisglyph].bitmap = bitmapData; + for (y = 0; y < height; y++) { + for (x = 0; x < charWidth; x++) { + /* XXX The algorithm used to suck across the font ensures that + each glyph begins on a byte boundary. In theory this would + make it convienent to copy the glyph into a byte oriented + bitmap. We actually use the XGetPixel function to extract + each pixel from the image which is not that efficient. We + could either do tighter packing in the pixmap or more + efficient extraction from the image. Oh well. */ + if (XGetPixel(image, (int) (j*maxSpanLength*8) + x, y) == BlackPixelOfScreen(wi->screen)) { + bitmapData[y * spanLength + x / 8] |= (1 << (x & 7)); + } + } + } } XDestroyImage(image); numToGrab = 0; /* do we need to clear the offscreen pixmap to get more? */ if (i < myfontinfo->num_glyphs - 1) { - XSetForeground(dpy, xgc, 0); - XFillRectangle(dpy, offscreen, xgc, 0, 0, + values.foreground = WhitePixelOfScreen(wi->screen); + XChangeGC(wi->dpy, xgc, GCForeground, &values); + XFillRectangle(wi->dpy, offscreen, xgc, 0, 0, 8 * maxSpanLength * glyphsPerGrab, height); - XSetForeground(dpy, xgc, 1); + values.foreground = BlackPixelOfScreen(wi->screen); + XChangeGC(wi->dpy, xgc, GCForeground, &values); } } } - XFreeFontInfo(NULL, fontinfo, 1); - XFreeGC(dpy, xgc); - XFreePixmap(dpy, offscreen); + + XFreeGC(wi->dpy, xgc); + Tk_FreePixmap(wi->dpy, offscreen); return myfontinfo; FreeFontAndReturn: - XFreeFontInfo(NULL, fontinfo, 1); XDestroyImage(image); - XFreeGC(dpy, xgc); - XFreePixmap(dpy, offscreen); + XFreeGC(wi->dpy, xgc); + Tk_FreePixmap(wi->dpy, offscreen); for (i = 0; i < myfontinfo->num_glyphs; i++) { if (myfontinfo->glyph[i].bitmap) ZnFree(myfontinfo->glyph[i].bitmap); @@ -1219,28 +976,37 @@ SuckGlyphsFromServer(ZnWindow win, ********************************************************************************** */ ZnTexFontInfo -ZnGetTexFont(WidgetInfo *wi, - ZnFont font) +ZnGetTexFont(ZnWInfo *wi, + Tk_Font font) { TexFont *txf; TexFontInfo *tfi; static int inited = 0; Tcl_HashEntry *entry; - char const *fontname = Tk_NameOfFont(font); int new; + unsigned char *glisto = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_abcdefghijmklmnopqrstuvwxyz{|}~°ÀÂÇÈÉÊËÎÏÔÙÛÜàâçèéêëîïôùûü~`"; + unsigned char *glist=NULL, *glist2=NULL; + TexGlyphInfo *tgi; + unsigned int i, j; + int min_glyph, max_glyph; + int gap = 1; /* gap between glyphs */ + int px, py, maxheight; + int width, height; + unsigned int texw, texh; + GLfloat xstep, ystep; + GLuint max_tex_size[1]; if (!inited) { - Tcl_InitHashTable(&font_textures, TCL_STRING_KEYS); + Tcl_InitHashTable(&font_textures, TCL_ONE_WORD_KEYS); inited = 1; } - entry = Tcl_FindHashEntry(&font_textures, fontname); + entry = Tcl_FindHashEntry(&font_textures, (char *) font); if (entry != NULL) { - /*printf("found font: %d |%s|\n", wi, fontname);*/ txf = (TexFont *) Tcl_GetHashValue(entry); } else { - /*printf("new font: %d |%s|\n", wi, fontname);*/ + /*printf("Loading a new texture font for %s\n", Tk_NameOfFont(font));*/ txf = ZnMalloc(sizeof(TexFont)); if (txf == NULL) { return NULL; @@ -1249,88 +1015,21 @@ ZnGetTexFont(WidgetInfo *wi, txf->tgi = NULL; txf->tgvi = NULL; txf->lut = NULL; - txf->teximage = NULL; txf->tkfont = font; - entry = Tcl_CreateHashEntry(&font_textures, fontname, &new); + entry = Tcl_CreateHashEntry(&font_textures, (char *) font, &new); Tcl_SetHashValue(entry, (ClientData) txf); txf->hash = entry; - } - - /* - * Now locate the texture obj in the texture list for this widget. - */ - for (tfi = txf->tfi; tfi != NULL; tfi = tfi->next) { - if (tfi->wi == wi) { - tfi->refcount++; - return tfi; - } - } - /* - * Not found allocate a new texture object. - */ - tfi = ZnMalloc(sizeof(TexFontInfo)); - if (tfi == NULL) { - ZnFree(txf); - return NULL; - } - tfi->refcount = 1; - tfi->texobj = 0; - tfi->wi = wi; - tfi->txf = txf; - tfi->next = txf->tfi; - txf->tfi = tfi; - - return tfi; -} - - -/* - ********************************************************************************** - * - * ZnNameOfTexFont -- - * - ********************************************************************************** - */ -char * -ZnNameOfTexFont(ZnTexFontInfo tfi) -{ - return Tcl_GetHashKey(&font_textures, ((TexFontInfo *) tfi)->txf->hash); -} - -/* - ********************************************************************************** - * - * ZnTexFontTex -- - * - ********************************************************************************** - */ -GLuint -ZnTexFontTex(ZnTexFontInfo tfi) -{ - TexFontInfo *this = (TexFontInfo *) tfi; - TexFont *txf = this->txf; - unsigned char *glisto = "\t\x14\x15\x16\x17 !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_abcdefghijmklmnopqrstuvwxyz{|}~°ÀÂÇÈÉÊËÎÏÔÙÛÜàâçèéêëîïôùûü~`"; - unsigned char *glist=NULL, *glist2=NULL; - TexGlyphInfo *tgi; - int i, j; - int min_glyph, max_glyph; - int gap = 1; /* gap between glyphs */ - int px, py, maxheight; - int width, height; - GLfloat xstep, ystep, texw, texh; - GLuint max_tex_size[1]; - if (!txf->teximage) { /*printf("Chargement de la texture pour la fonte %s\n", ZnNameOfTexFont(tfi));*/ glGetIntegerv(GL_MAX_TEXTURE_SIZE, max_tex_size); - fontinfo = SuckGlyphsFromServer(this->wi->win, txf->tkfont); + fontinfo = SuckGlyphsFromServer(wi, txf->tkfont); if (fontinfo == NULL) { goto error; } - txf->max_ascent = fontinfo->max_ascent; - txf->max_descent = fontinfo->max_descent; + txf->ascent = fontinfo->ascent; + txf->descent = fontinfo->descent; txf->num_glyphs = strlen(glisto); /* @@ -1339,7 +1038,7 @@ ZnTexFontTex(ZnTexFontInfo tfi) */ texw = 128; texh = 64; - while (texh < txf->max_ascent+txf->max_descent) { + while (texh < (unsigned int) (txf->ascent+txf->descent)) { texh *= 2; } if (texh > max_tex_size[0]) { @@ -1352,7 +1051,6 @@ ZnTexFontTex(ZnTexFontInfo tfi) if (txf->teximage == NULL) { goto error; } - /*memset(txf->teximage, 0x55, texw * texh * sizeof(unsigned char));*/ txf->tgi = ZnMalloc(txf->num_glyphs * sizeof(TexGlyphInfo)); if (txf->tgi == NULL) { @@ -1392,7 +1090,7 @@ ZnTexFontTex(ZnTexFontInfo tfi) if ((height > 0) && (width > 0)) { for (j = i; j < txf->num_glyphs;) { if ((height > 0) && (width > 0)) { - if (px + width + gap < texw) { + if ((unsigned int) (px + width + gap) < texw) { foundWidthFit = 1; if (j != i) { i--; /* Step back so i loop increment leaves us at same character. */ @@ -1428,7 +1126,7 @@ ZnTexFontTex(ZnTexFontInfo tfi) py += maxheight + gap; px = gap; maxheight = height; - if (py + height + gap >= texh) { + if ((unsigned int) (py + height + gap) >= texh) { if (texh*2 < max_tex_size[0]) { texh *= 2; ZnFree(txf->teximage); @@ -1469,20 +1167,20 @@ ZnTexFontTex(ZnTexFontInfo tfi) c = i; } glist[c] = 0; /* Mark processed; don't process again. */ - txf->tgvi[c].t0[0] = tgi->x / texw + xstep; - txf->tgvi[c].t0[1] = tgi->y / texh + ystep; + txf->tgvi[c].t0[0] = tgi->x / ((GLfloat) texw) + xstep; + txf->tgvi[c].t0[1] = tgi->y / ((GLfloat) texh) + ystep; txf->tgvi[c].v0[0] = tgi->xoffset; txf->tgvi[c].v0[1] = tgi->yoffset - tgi->height; - txf->tgvi[c].t1[0] = (tgi->x + tgi->width) / texw + xstep; - txf->tgvi[c].t1[1] = tgi->y / texh + ystep; + txf->tgvi[c].t1[0] = (tgi->x + tgi->width) / ((GLfloat) texw) + xstep; + txf->tgvi[c].t1[1] = tgi->y / ((GLfloat) texh) + ystep; txf->tgvi[c].v1[0] = (tgi->xoffset + tgi->width); txf->tgvi[c].v1[1] = tgi->yoffset - tgi->height; - txf->tgvi[c].t2[0] = (tgi->x + tgi->width) / texw + xstep; - txf->tgvi[c].t2[1] = (tgi->y + tgi->height) / texh + ystep; + txf->tgvi[c].t2[0] = (tgi->x + tgi->width) / ((GLfloat) texw) + xstep; + txf->tgvi[c].t2[1] = (tgi->y + tgi->height) / ((GLfloat) texh) + ystep; txf->tgvi[c].v2[0] = (tgi->xoffset + tgi->width); txf->tgvi[c].v2[1] = tgi->yoffset; - txf->tgvi[c].t3[0] = tgi->x / texw + xstep; - txf->tgvi[c].t3[1] = (tgi->y + tgi->height) / texh + ystep; + txf->tgvi[c].t3[0] = tgi->x / ((GLfloat) texw) + xstep; + txf->tgvi[c].t3[1] = (tgi->y + tgi->height) / ((GLfloat) texh) + ystep; txf->tgvi[c].v3[0] = tgi->xoffset; txf->tgvi[c].v3[1] = tgi->yoffset; txf->tgvi[c].advance = tgi->advance; @@ -1509,7 +1207,37 @@ ZnTexFontTex(ZnTexFontInfo tfi) txf->lut = ZnMalloc(txf->range * sizeof(ZnTexGVI *)); if (txf->lut == NULL) { - goto error; + error: + if (glist) { + ZnFree(glist); + } + if (glist2) { + ZnFree(glist2); + } + if (fontinfo) { + for (i = 0; i < fontinfo->num_glyphs; i++) { + if (fontinfo->glyph[i].bitmap) + ZnFree(fontinfo->glyph[i].bitmap); + } + ZnFree(fontinfo); + } + if (txf->tgi) { + ZnFree(txf->tgi); + txf->tgi = NULL; + } + if (txf->tgvi) { + ZnFree(txf->tgvi); + txf->tgvi = NULL; + } + if (txf->lut) { + ZnFree(txf->lut); + txf->lut = NULL; + } + if (txf->teximage) { + ZnFree(txf->teximage); + txf->teximage = NULL; + } + return 0; } memset(txf->lut, 0, txf->range * sizeof(ZnTexGVI *)); for (i = 0; i < txf->num_glyphs; i++) { @@ -1525,6 +1253,61 @@ ZnTexFontTex(ZnTexFontInfo tfi) ZnFree(glist2); } + /* + * Now locate the texture obj in the texture list for this widget. + */ + for (tfi = txf->tfi; tfi != NULL; tfi = tfi->next) { + if (tfi->wi == wi) { + tfi->refcount++; + return tfi; + } + } + /* + * Not found allocate a new texture object. + */ + tfi = ZnMalloc(sizeof(TexFontInfo)); + if (tfi == NULL) { + ZnFree(txf); + return NULL; + } + tfi->refcount = 1; + tfi->texobj = 0; + tfi->wi = wi; + tfi->txf = txf; + tfi->next = txf->tfi; + txf->tfi = tfi; + + return tfi; +} + + +/* + ********************************************************************************** + * + * ZnNameOfTexFont -- + * + ********************************************************************************** + */ +char const * +ZnNameOfTexFont(ZnTexFontInfo tfi) +{ + return Tk_NameOfFont((Tk_Font) Tcl_GetHashKey(&font_textures, + ((TexFontInfo *) tfi)->txf->hash)); +} + +/* + ********************************************************************************** + * + * ZnTexFontTex -- + * + ********************************************************************************** + */ +GLuint +ZnTexFontTex(ZnTexFontInfo tfi) +{ + TexFontInfo *this = (TexFontInfo *) tfi; + TexFont *txf = this->txf; + if (!this->texobj) { glGenTextures(1, &this->texobj); /*printf("%d creation texture %d pour la fonte %s\n", @@ -1541,40 +1324,6 @@ ZnTexFontTex(ZnTexFontInfo tfi) /*printf("%d utilisation de la texture %d\n", this->wi, this->texobj);*/ return this->texobj; - - error: - if (glist) { - ZnFree(glist); - } - if (glist2) { - ZnFree(glist2); - } - if (fontinfo) { - for (i = 0; i < fontinfo->num_glyphs; i++) { - if (fontinfo->glyph[i].bitmap) - ZnFree(fontinfo->glyph[i].bitmap); - } - ZnFree(fontinfo); - } - - if (txf->tgi) { - ZnFree(txf->tgi); - txf->tgi = NULL; - } - if (txf->tgvi) { - ZnFree(txf->tgvi); - txf->tgvi = NULL; - } - if (txf->lut) { - ZnFree(txf->lut); - txf->lut = NULL; - } - if (txf->teximage) { - ZnFree(txf->teximage); - txf->teximage = NULL; - } - - return 0; } @@ -1589,7 +1338,7 @@ void ZnFreeTexFont(ZnTexFontInfo tfi) { TexFontInfo *this = ((TexFontInfo *) tfi); - WidgetInfo *wi = this->wi; + ZnWInfo *wi = this->wi; TexFont *txf = this->txf; TexFontInfo *prev, *scan; @@ -1619,8 +1368,9 @@ ZnFreeTexFont(ZnTexFontInfo tfi) if (this->texobj && wi->win) { /*printf("%d Libération de la texture %d pour la fonte %s\n", wi, this->texobj, ZnNameOfTexFont(tfi));*/ - glXMakeCurrent(wi->dpy, ZnWindowId(wi->win), wi->gl_context); + ZnGLMakeCurrent(wi); glDeleteTextures(1, &this->texobj); + ZnGLRelease(wi); } /* @@ -1649,7 +1399,7 @@ ZnFreeTexFont(ZnTexFontInfo tfi) */ ZnBool ZnCharInTexFont(ZnTexFontInfo tfi, - int c) + unsigned int c) { TexFont *txf = ((TexFontInfo *) tfi)->txf; @@ -1670,7 +1420,7 @@ ZnCharInTexFont(ZnTexFontInfo tfi, */ ZnTexGVI * ZnTexFontGVI(ZnTexFontInfo tfi, - int c) + unsigned int c) { TexFont *txf = ((TexFontInfo *) tfi)->txf; ZnTexGVI *tgvi; @@ -1701,5 +1451,4 @@ ZnTexFontGVI(ZnTexFontInfo tfi, return txf->lut[(int)'!' - txf->min_glyph]; } - #endif diff --git a/generic/Image.h b/generic/Image.h index 21b625d..0a3a82a 100644 --- a/generic/Image.h +++ b/generic/Image.h @@ -30,13 +30,9 @@ #ifndef _Image_h #define _Image_h -#ifdef GLX -#include -#endif - #include "Types.h" -struct _WidgetInfo; +struct _ZnWInfo; typedef void *ZnImage; @@ -45,31 +41,29 @@ typedef void *ZnImage; (((bits)[(y)*(stride)+((x)>>3)]<<((x)&7))&0x80) ZnImage -ZnGetImage(struct _WidgetInfo *wi, Tk_Uid image_name); +ZnGetImage(struct _ZnWInfo *wi, Tk_Uid image_name); ZnImage ZnGetImageByValue(ZnImage image); ZnImage -ZnGetBitmap(struct _WidgetInfo *wi, Tk_Uid bitmap_name); +ZnGetBitmap(struct _ZnWInfo *wi, Tk_Uid bitmap_name); void ZnFreeImage(ZnImage image); char * ZnNameOfImage(ZnImage image); void ZnSizeOfImage(ZnImage image, int *width, int *height); -char * -ZnImagePattern(ZnImage image, int *stride); -XImage * -ZnImageMask(ZnImage image); +Pixmap +ZnImagePixmap(ZnImage image); ZnBool ZnImageIsBitmap(ZnImage image); -Pixmap -ZnImagePixmap(ZnImage image, Pixmap *mask_pmap); -#ifdef GLX +char * +ZnImageMask(ZnImage image, int *stride); +TkRegion +ZnImageRegion(ZnImage image); +#ifdef GL GLuint ZnImageTex(ZnImage image, ZnReal *t, ZnReal *s); -#endif -#ifdef GLX typedef struct _ZnTexGlyphVertexInfo { GLfloat t0[2]; GLshort v0[2]; @@ -86,13 +80,13 @@ typedef struct _ZnTexGlyphVertexInfo { typedef void *ZnTexFontInfo; ZnTexFontInfo -ZnGetTexFont(struct _WidgetInfo *wi, ZnFont font); +ZnGetTexFont(struct _ZnWInfo *wi, Tk_Font font); void ZnFreeTexFont(ZnTexFontInfo tfi); ZnBool -ZnCharInTexFont(ZnTexFontInfo tfi, int c); +ZnCharInTexFont(ZnTexFontInfo tfi, unsigned int c); ZnTexGVI * -ZnTexFontGVI(ZnTexFontInfo tfi, int c); +ZnTexFontGVI(ZnTexFontInfo tfi, unsigned int c); GLuint ZnTexFontTex(ZnTexFontInfo tfi); #endif diff --git a/generic/Item.c b/generic/Item.c index 4dbc315..45581e3 100644 --- a/generic/Item.c +++ b/generic/Item.c @@ -27,16 +27,6 @@ */ -#include /* For INT_MAX */ -#include -#include -#include -#include -#include -#ifdef GLX -#include -#endif - #include "libtess/glu.h" #include "Field.h" #include "Item.h" @@ -51,6 +41,11 @@ #include "tkZinc.h" #include "OverlapMan.h" +#include /* For INT_MAX */ +#include +#include +#include + static const char rcsid[] = "$Id$"; static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ " $"; @@ -108,8 +103,8 @@ static char *attribute_type_strings[] = { * ********************************************************************************** */ -static void Invalidate(Item item, int reason); -static void AttributeToObj(WidgetInfo *wi, void *record, ZnAttrConfig *desc, +static void Invalidate(ZnItem item, int reason); +static void AttributeToObj(ZnWInfo *wi, void *record, ZnAttrConfig *desc, char *buffer, Tcl_Obj *result); @@ -142,7 +137,7 @@ InitAttrDesc(ZnAttrConfig *attr_desc) ********************************************************************************** */ int -ZnAttributesInfo(WidgetInfo *wi, +ZnAttributesInfo(ZnWInfo *wi, void *record, ZnAttrConfig *desc, int argc, @@ -159,7 +154,7 @@ ZnAttributesInfo(WidgetInfo *wi, if (desc->type == ZN_CONFIG_END) { Tcl_AppendResult(wi->interp, "unknown attribute \"", Tcl_GetString(args[0]), "\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } else if (attr_uid == desc->uid) { break; @@ -168,22 +163,22 @@ ZnAttributesInfo(WidgetInfo *wi, desc++; } } - entries[0] = NewStringObj(desc->name); - entries[1] = NewStringObj(attribute_type_strings[desc->type]); - entries[2] = NewBooleanObj(desc->read_only ? 1 : 0); - entries[3] = NewStringObj(""); - entries[4] = NewStringObj(""); + entries[0] = Tcl_NewStringObj(desc->name, -1); + entries[1] = Tcl_NewStringObj(attribute_type_strings[desc->type], -1); + entries[2] = Tcl_NewBooleanObj(desc->read_only ? 1 : 0); + entries[3] = Tcl_NewStringObj("", -1); + entries[4] = Tcl_NewStringObj("", -1); AttributeToObj(wi, record, desc, buffer, entries[4]); Tcl_SetObjResult(wi->interp, Tcl_NewListObj(5, entries)); } else { l = Tcl_GetObjResult(wi->interp); while (desc->type != ZN_CONFIG_END) { - entries[0] = NewStringObj(desc->name); - entries[1] = NewStringObj(attribute_type_strings[desc->type]); - entries[2] = NewBooleanObj(desc->read_only ? 1 : 0); - entries[3] = NewStringObj(""); - entries[4] = NewStringObj(""); + entries[0] = Tcl_NewStringObj(desc->name, -1); + entries[1] = Tcl_NewStringObj(attribute_type_strings[desc->type], -1); + entries[2] = Tcl_NewBooleanObj(desc->read_only ? 1 : 0); + entries[3] = Tcl_NewStringObj("", -1); + entries[4] = Tcl_NewStringObj("", -1); AttributeToObj(wi, record, desc, buffer, entries[4]); Tcl_ListObjAppendElement(wi->interp, l, Tcl_NewListObj(5, entries)); desc++; @@ -202,7 +197,7 @@ ZnAttributesInfo(WidgetInfo *wi, ********************************************************************************** */ int -ZnConfigureAttributes(WidgetInfo *wi, +ZnConfigureAttributes(ZnWInfo *wi, void *record, ZnAttrConfig *attr_desc, int argc, @@ -223,13 +218,13 @@ ZnConfigureAttributes(WidgetInfo *wi, if (desc->type == ZN_CONFIG_END) { Tcl_AppendResult(wi->interp, "unknown attribute \"", Tcl_GetString(args[i]), "\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } else if (attr_uid == desc->uid) { if (desc->read_only) { Tcl_AppendResult(wi->interp, "attribute \"", Tcl_GetString(args[i]), "\" can only be read", NULL); - return ZN_ERROR; + return TCL_ERROR; } valp = ((char *) record) + desc->offset; /*printf("record <0x%X>, valp <0x%X>, offset %d\n", record, valp, desc->offset);*/ @@ -248,7 +243,7 @@ ZnConfigureAttributes(WidgetInfo *wi, Tcl_AppendResult(wi->interp, " gradient expected for attribute \"", Tcl_GetString(args[i]), "\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } if (*((ZnGradient **) valp)) { ZnFreeGradient(*((ZnGradient **) valp)); @@ -260,17 +255,17 @@ ZnConfigureAttributes(WidgetInfo *wi, } case ZN_CONFIG_GRADIENT_LIST: { - ZnList new_grad_list = NULL; - ZnGradient **grads; - int num_grads, j, k; - Tcl_Obj **elems; + ZnList new_grad_list = NULL; + ZnGradient **grads; + unsigned int num_grads, j, k; + Tcl_Obj **elems; if (Tcl_ListObjGetElements(wi->interp, args[i+1], - &num_grads, &elems) == ZN_ERROR) { + &num_grads, &elems) == TCL_ERROR) { Tcl_AppendResult(wi->interp, " gradient list expected for attribute \"", Tcl_GetString(args[i]), "\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } if (num_grads) { new_grad_list = ZnListNew(num_grads, sizeof(ZnGradient *)); @@ -295,7 +290,7 @@ ZnConfigureAttributes(WidgetInfo *wi, ZnFreeGradient(grads[k]); } ZnListFree(new_grad_list); - return ZN_ERROR; + return TCL_ERROR; } } } @@ -322,10 +317,10 @@ ZnConfigureAttributes(WidgetInfo *wi, case ZN_CONFIG_BOOL: { int b; - if (Tcl_GetBooleanFromObj(wi->interp, args[i+1], &b) != ZN_OK) { + if (Tcl_GetBooleanFromObj(wi->interp, args[i+1], &b) != TCL_OK) { Tcl_AppendResult(wi->interp, " boolean expected for attribute \"", Tcl_GetString(args[i]), "\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } if (b ^ (ISSET(*((unsigned short *) valp), desc->bool_bit) != 0)) { ASSIGN(*((unsigned short *) valp), desc->bool_bit, b); @@ -360,7 +355,7 @@ ZnConfigureAttributes(WidgetInfo *wi, } if (image == ZnUnspecifiedImage) { Tcl_AppendResult(wi->interp, msg, Tcl_GetString(args[i]), "\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } } if (*((ZnImage *) valp) != ZnUnspecifiedImage) { @@ -375,17 +370,17 @@ ZnConfigureAttributes(WidgetInfo *wi, } case ZN_CONFIG_BITMAP_LIST: { - ZnList new_pat_list = NULL; - ZnImage *pats; - int num_pats, j, k; - Tcl_Obj **elems; + ZnList new_pat_list = NULL; + ZnImage *pats; + unsigned int num_pats, j, k; + Tcl_Obj **elems; if (Tcl_ListObjGetElements(wi->interp, args[i+1], - &num_pats, &elems) == ZN_ERROR) { + &num_pats, &elems) == TCL_ERROR) { Tcl_AppendResult(wi->interp, " pattern list expected for attribute \"", Tcl_GetString(args[i]), "\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } if (num_pats) { new_pat_list = ZnListNew(num_pats, sizeof(Pixmap)); @@ -402,7 +397,7 @@ ZnConfigureAttributes(WidgetInfo *wi, ZnFreeImage(pats[k]); } ZnListFree(new_pat_list); - return ZN_ERROR; + return TCL_ERROR; } } else { @@ -436,19 +431,19 @@ ZnConfigureAttributes(WidgetInfo *wi, Tcl_Obj **elems; if (Tcl_ListObjGetElements(wi->interp, args[i+1], - &num_tags, &elems) == ZN_ERROR) { + &num_tags, &elems) == TCL_ERROR) { Tcl_AppendResult(wi->interp, " tag list expected for attribute \"", Tcl_GetString(args[i]), "\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } if (*((ZnList *) valp)) { - ITEM.FreeTags((Item) record); + ZnITEM.FreeTags((ZnItem) record); *flags |= desc->flags; } if (num_tags) { for (j = 0; j < num_tags; j++) { - ITEM.AddTag((Item) record, Tk_GetUid(Tcl_GetString(elems[j]))); + ZnITEM.AddTag((ZnItem) record, Tk_GetUid(Tcl_GetString(elems[j]))); } *flags |= desc->flags; } @@ -485,7 +480,7 @@ ZnConfigureAttributes(WidgetInfo *wi, if (!font) { Tcl_AppendResult(wi->interp, " font expected for attribute \"", Tcl_GetString(args[i]), "\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } if (*((Tk_Font *) valp)) { Tk_FreeFont(*((Tk_Font *) valp)); @@ -497,113 +492,45 @@ ZnConfigureAttributes(WidgetInfo *wi, } case ZN_CONFIG_EDGE_LIST: { - Border border = NO_BORDER; - int j, len, largc; - Tcl_Obj **largv; - - if (Tcl_ListObjGetElements(wi->interp, args[i+1], - &largc, &largv) == ZN_ERROR) { - border_error: - Tcl_AppendResult(wi->interp, " border expected for attribute \"", + ZnBorder border; + + if (ZnGetBorder(wi, args[i+1], &border) == TCL_ERROR) { + Tcl_AppendResult(wi->interp, " edge list expected for attribute \"", Tcl_GetString(args[i]), "\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } - for (j = 0; j < largc; j++) { - str = Tcl_GetString(largv[j]); - len = strlen(str); - if (strncasecmp(str, LEFT_SPEC, len) == 0) { - border |= LEFT_BORDER; - } - else if (strncasecmp(str, RIGHT_SPEC, len) == 0) { - border |= RIGHT_BORDER; - } - else if (strncasecmp(str, TOP_SPEC, len) == 0) { - border |= TOP_BORDER; - } - else if (strncasecmp(str, BOTTOM_SPEC, len) == 0) { - border |= BOTTOM_BORDER; - } - else if (strncasecmp(str, CONTOUR_SPEC, len) == 0) { - border |= CONTOUR_BORDER; - } - else if (strncasecmp(str, OBLIQUE_SPEC, len) == 0) { - border |= OBLIQUE; - } - else if (strncasecmp(str, COUNTER_OBLIQUE_SPEC, len) == 0) { - border |= COUNTER_OBLIQUE; - } - else if (strncasecmp(str, NO_BORDER_SPEC, len) == 0) { - border |= NO_BORDER; - } - else { - goto border_error; - } - } - if (border != *((Border *) valp)) { - *((Border *) valp) = border; + if (border != *((ZnBorder *) valp)) { + *((ZnBorder *) valp) = border; *flags |= desc->flags; } break; } case ZN_CONFIG_LINE_SHAPE: { - LineShape line_shape; - int len; - str = Tcl_GetString(args[i+1]); - len = strlen(str); - if (strncasecmp(str, STRAIGHT_SPEC, len) == 0) { - line_shape = LINE_STRAIGHT; - } - else if (strncasecmp(str, RIGHT_LIGHTNING_SPEC, len) == 0) { - line_shape = LINE_RIGHT_LIGHTNING; - } - else if (strncasecmp(str, LEFT_LIGHTNING_SPEC, len) == 0) { - line_shape = LINE_LEFT_LIGHTNING; - } - else if (strncasecmp(str, RIGHT_CORNER_SPEC, len) == 0) { - line_shape = LINE_RIGHT_CORNER; - } - else if (strncasecmp(str, LEFT_CORNER_SPEC, len) == 0) { - line_shape = LINE_LEFT_CORNER; - } - else if (strncasecmp(str, DOUBLE_RIGHT_CORNER_SPEC, len) == 0) { - line_shape = LINE_DOUBLE_RIGHT_CORNER; - } - else if (strncasecmp(str, DOUBLE_LEFT_CORNER_SPEC, len) == 0) { - line_shape = LINE_DOUBLE_LEFT_CORNER; - } - else { + ZnLineShape line_shape; + + if (ZnGetLineShape(wi, Tcl_GetString(args[i+1]), &line_shape) == TCL_ERROR) { Tcl_AppendResult(wi->interp, " line shape expected for attribute \"", Tcl_GetString(args[i]), "\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } - if (line_shape != *((LineShape *) valp)) { - *((LineShape *) valp) = line_shape; + if (line_shape != *((ZnLineShape *) valp)) { + *((ZnLineShape *) valp) = line_shape; *flags |= desc->flags; } break; } case ZN_CONFIG_LINE_STYLE: { - LineStyle line_style; - int len; - str = Tcl_GetString(args[i+1]); - len = strlen(str); - if (strncasecmp(str, SIMPLE_SPEC, len) == 0) - line_style = LINE_SIMPLE; - else if (strncasecmp(str, DASHED_SPEC, len) == 0) - line_style = LINE_DASHED; - else if (strncasecmp(str, MIXED_SPEC, len) == 0) - line_style = LINE_MIXED; - else if (strncasecmp(str, DOTTED_SPEC, len) == 0) - line_style = LINE_DOTTED; - else { + ZnLineStyle line_style; + + if (ZnGetLineStyle(wi, Tcl_GetString(args[i+1]), &line_style) == TCL_ERROR) { Tcl_AppendResult(wi->interp, " line style expected for attribute \"", Tcl_GetString(args[i]), "\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } - if (line_style != *((LineStyle *) valp)) { - *((LineStyle *) valp) = line_style; + if (line_style != *((ZnLineStyle *) valp)) { + *((ZnLineStyle *) valp) = line_style; *flags |= desc->flags; } break; @@ -613,13 +540,13 @@ ZnConfigureAttributes(WidgetInfo *wi, ZnLineEnd line_end = NULL; str = Tcl_GetString(args[i+1]); if (strlen(str) != 0) { - line_end = LineEndCreate(wi->interp, str); + line_end = ZnLineEndCreate(wi->interp, str); if (line_end == NULL) { - return ZN_ERROR; + return TCL_ERROR; } } if (*((ZnLineEnd *) valp) != NULL) { - LineEndDelete(*((ZnLineEnd *) valp)); + ZnLineEndDelete(*((ZnLineEnd *) valp)); *((ZnLineEnd *) valp) = line_end; *flags |= desc->flags; } @@ -633,15 +560,15 @@ ZnConfigureAttributes(WidgetInfo *wi, } case ZN_CONFIG_RELIEF: { - ReliefStyle relief; - if (ZnGetRelief(wi, Tcl_GetString(args[i+1]), &relief) == ZN_ERROR) { + ZnReliefStyle relief; + if (ZnGetRelief(wi, Tcl_GetString(args[i+1]), &relief) == TCL_ERROR) { Tcl_AppendResult(wi->interp, " relief expected for attribute \"", Tcl_GetString(args[i]), "\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } - if (relief != *((ReliefStyle *) valp)) { + if (relief != *((ZnReliefStyle *) valp)) { /*printf("valp <0x%X>, flags <0x%X>, relief %d\n", valp, flags, relief);*/ - *((ReliefStyle *) valp) = relief; + *((ZnReliefStyle *) valp) = relief; *flags |= desc->flags; } break; @@ -649,10 +576,10 @@ ZnConfigureAttributes(WidgetInfo *wi, case ZN_CONFIG_JOIN_STYLE: { int join; - if (Tk_GetJoinStyle(wi->interp, Tcl_GetString(args[i+1]), &join) == ZN_ERROR) { + if (Tk_GetJoinStyle(wi->interp, Tcl_GetString(args[i+1]), &join) == TCL_ERROR) { Tcl_AppendResult(wi->interp, " join expected for attribute \"", Tcl_GetString(args[i]), "\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } if (join != *((int *) valp)) { *((int *) valp) = join; @@ -663,10 +590,10 @@ ZnConfigureAttributes(WidgetInfo *wi, case ZN_CONFIG_CAP_STYLE: { int cap; - if (Tk_GetCapStyle(wi->interp, Tcl_GetString(args[i+1]), &cap) == ZN_ERROR) { + if (Tk_GetCapStyle(wi->interp, Tcl_GetString(args[i+1]), &cap) == TCL_ERROR) { Tcl_AppendResult(wi->interp, " cap expected for attribute \"", Tcl_GetString(args[i]), "\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } if (cap != *((int *) valp)) { *((int *) valp) = cap; @@ -681,15 +608,15 @@ ZnConfigureAttributes(WidgetInfo *wi, Tcl_Obj **largv; if ((Tcl_ListObjGetElements(wi->interp, args[i+1], - &largc, &largv) == ZN_ERROR) || + &largc, &largv) == TCL_ERROR) || (largc != 2)) { point_error: Tcl_AppendResult(wi->interp, " position expected for attribute \"", Tcl_GetString(args[i]), "\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } - if ((Tcl_GetDoubleFromObj(wi->interp, largv[0], &point.x) == ZN_ERROR) || - (Tcl_GetDoubleFromObj(wi->interp, largv[1], &point.y) == ZN_ERROR)) { + if ((Tcl_GetDoubleFromObj(wi->interp, largv[0], &point.x) == TCL_ERROR) || + (Tcl_GetDoubleFromObj(wi->interp, largv[1], &point.y) == TCL_ERROR)) { goto point_error; } if ((point.x != ((ZnPoint *) valp)->x) || @@ -702,10 +629,10 @@ ZnConfigureAttributes(WidgetInfo *wi, case ZN_CONFIG_DIM: { ZnDim dim; - if (Tcl_GetDoubleFromObj(wi->interp, args[i+1], &dim) == ZN_ERROR) { + if (Tcl_GetDoubleFromObj(wi->interp, args[i+1], &dim) == TCL_ERROR) { Tcl_AppendResult(wi->interp, " dimension expected for attribute \"", Tcl_GetString(args[i+1]), "\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } if (dim != *((ZnDim *) valp)) { *((ZnDim *) valp) = dim; @@ -716,17 +643,17 @@ ZnConfigureAttributes(WidgetInfo *wi, case ZN_CONFIG_PRI: { int pri; - if (Tcl_GetIntFromObj(wi->interp, args[i+1], &pri) == ZN_ERROR) { - return ZN_ERROR; + if (Tcl_GetIntFromObj(wi->interp, args[i+1], &pri) == TCL_ERROR) { + return TCL_ERROR; } if (pri < 0) { Tcl_AppendResult(wi->interp, " priority must be a positive integer \"", Tcl_GetString(args[i+1]), "\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } if (pri != *((int *) valp)) { *((int *) valp) = pri; - ITEM.UpdateItemPriority((Item) record, ZN_NO_ITEM, True); + ZnITEM.UpdateItemPriority((ZnItem) record, ZN_NO_ITEM, True); *flags |= desc->flags; } break; @@ -738,9 +665,9 @@ ZnConfigureAttributes(WidgetInfo *wi, * associated with the tag. */ { - Item item2; + ZnItem item2; int result; - TagSearch *search_var = NULL; + ZnTagSearch *search_var = NULL; if (strlen(Tcl_GetString(args[i+1])) == 0) { item2 = ZN_NO_ITEM; @@ -748,21 +675,21 @@ ZnConfigureAttributes(WidgetInfo *wi, else { result = ZnItemWithTagOrId(wi, args[i+1], &item2, &search_var); ZnTagSearchDestroy(search_var); - if ((result == ZN_ERROR) || (item2 == ZN_NO_ITEM)) { + if ((result == TCL_ERROR) || (item2 == ZN_NO_ITEM)) { Tcl_AppendResult(wi->interp, " unknown item \"", Tcl_GetString(args[i+1]), "\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } } - if (item2 != *((Item *) valp)) { - *((Item *) valp) = item2; + if (item2 != *((ZnItem *) valp)) { + *((ZnItem *) valp) = item2; *flags |= desc->flags; } } break; case ZN_CONFIG_WINDOW: { - ZnWindow win, ancestor, parent; + Tk_Window win, ancestor, parent; str = Tcl_GetString(args[i+1]); if (strlen(str) == 0) { win = NULL; @@ -770,7 +697,7 @@ ZnConfigureAttributes(WidgetInfo *wi, else { win = Tk_NameToWindow(wi->interp, str, wi->win); if (win == NULL) { - return ZN_ERROR; + return TCL_ERROR; } else { /* @@ -800,8 +727,8 @@ ZnConfigureAttributes(WidgetInfo *wi, if (win == wi->win) { goto badWindow; } - if (win != *((ZnWindow *) valp)) { - *((ZnWindow *) valp) = win; + if (win != *((Tk_Window *) valp)) { + *((Tk_Window *) valp) = win; *flags |= desc->flags; } } @@ -814,8 +741,8 @@ ZnConfigureAttributes(WidgetInfo *wi, case ZN_CONFIG_ALPHA: { int integer; - if (Tcl_GetIntFromObj(wi->interp, args[i+1], &integer) == ZN_ERROR) { - return ZN_ERROR; + if (Tcl_GetIntFromObj(wi->interp, args[i+1], &integer) == TCL_ERROR) { + return TCL_ERROR; } switch (desc->type) { case ZN_CONFIG_ANGLE: @@ -845,32 +772,15 @@ ZnConfigureAttributes(WidgetInfo *wi, } case ZN_CONFIG_FILL_RULE: { - int fill_rule; - int len; - str = Tcl_GetString(args[i+1]); - len = strlen(str); - if (strncasecmp(str, "odd", len) == 0) { - fill_rule = GLU_TESS_WINDING_ODD; - } - else if (strncasecmp(str, "nonzero", len) == 0) { - fill_rule = GLU_TESS_WINDING_NONZERO; - } - else if (strncasecmp(str, "positive", len) == 0) { - fill_rule = GLU_TESS_WINDING_POSITIVE; - } - else if (strncasecmp(str, "negative", len) == 0) { - fill_rule = GLU_TESS_WINDING_NEGATIVE; - } - else if (strncasecmp(str, "abs_geq_2", len) == 0) { - fill_rule = GLU_TESS_WINDING_ABS_GEQ_TWO; - } - else { + ZnFillRule fill_rule; + + if (ZnGetFillRule(wi, Tcl_GetString(args[i+1]), &fill_rule) == TCL_ERROR) { Tcl_AppendResult(wi->interp, " fill rule expected for attribute \"", Tcl_GetString(args[i]), "\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } - if (fill_rule != *((int *) valp)) { - *((int *) valp) = fill_rule; + if (fill_rule != *((ZnFillRule *) valp)) { + *((ZnFillRule *) valp) = fill_rule; *flags |= desc->flags; } break; @@ -878,13 +788,13 @@ ZnConfigureAttributes(WidgetInfo *wi, case ZN_CONFIG_ALIGNMENT: { Tk_Justify justify; - if (Tk_GetJustify(wi->interp, Tcl_GetString(args[i+1]), &justify) == ZN_ERROR) { + if (Tk_GetJustify(wi->interp, Tcl_GetString(args[i+1]), &justify) == TCL_ERROR) { Tcl_AppendResult(wi->interp, " justify expected for attribute \"", Tcl_GetString(args[i]), "\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } - if (justify != *((ZnJustify *) valp)) { - *((ZnJustify *) valp) = justify; + if (justify != *((Tk_Justify *) valp)) { + *((Tk_Justify *) valp) = justify; *flags |= desc->flags; } break; @@ -892,13 +802,13 @@ ZnConfigureAttributes(WidgetInfo *wi, case ZN_CONFIG_ANCHOR: { Tk_Anchor anchor; - if (Tk_GetAnchor(wi->interp, Tcl_GetString(args[i+1]), &anchor) == ZN_ERROR) { + if (Tk_GetAnchor(wi->interp, Tcl_GetString(args[i+1]), &anchor) == TCL_ERROR) { Tcl_AppendResult(wi->interp, " anchor expected for attribute \"", Tcl_GetString(args[i]), "\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } - if (anchor != *((ZnAnchor *) valp)) { - *((ZnAnchor *) valp) = anchor; + if (anchor != *((Tk_Anchor *) valp)) { + *((Tk_Anchor *) valp) = anchor; *flags |= desc->flags; } break; @@ -912,16 +822,16 @@ ZnConfigureAttributes(WidgetInfo *wi, str++; } if (strlen(str) != 0) { - Item item = (Item) record; - frmt = LabelFormatCreate(wi->interp, str, - FIELD.NumFields(item->class->GetFieldSet(item))); + ZnItem item = (ZnItem) record; + frmt = ZnLFCreate(wi->interp, str, + ZnFIELD.NumFields(item->class->GetFieldSet(item))); if (frmt == NULL) { - return ZN_ERROR; + return TCL_ERROR; } } if (*((ZnLabelFormat *) valp) != NULL) { - LabelFormatDelete(*((ZnLabelFormat *) valp)); + ZnLFDelete(*((ZnLabelFormat *) valp)); *((ZnLabelFormat *) valp) = frmt; *flags |= desc->flags; } @@ -936,136 +846,39 @@ ZnConfigureAttributes(WidgetInfo *wi, case ZN_CONFIG_AUTO_ALIGNMENT: { - AutoAlign aa; - int j; + ZnAutoAlign aa; - str = Tcl_GetString(args[i+1]); - if (strcmp(str, "-") == 0) { - aa.automatic = False; - } - else if (strlen(str) == 3) { - aa.automatic = True; - for (j = 0; j < 3; j++) { - switch(str[j]) { - case 'l': - case 'L': - aa.align[j] = ZnJustifyLeft; - break; - case 'c': - case 'C': - aa.align[j] = ZnJustifyCenter; - break; - case 'r': - case 'R': - aa.align[j] = ZnJustifyRight; - break; - default: - Tcl_AppendResult(wi->interp, "invalid auto justify specifcation \"", - Tcl_GetString(args[i+1]), - "\" should be - or a triple of lcr", NULL); - return ZN_ERROR; - } - } + if (ZnGetAutoAlign(wi, Tcl_GetString(args[i+1]), &aa) == TCL_ERROR) { + Tcl_AppendResult(wi->interp, " auto alignment expected for attribute \"", + Tcl_GetString(args[i]), "\"", NULL); + return TCL_ERROR; } - else { - Tcl_AppendResult(wi->interp, "invalid auto alignment specification \"", - Tcl_GetString(args[i+1]), - "\" should be - or a triple of lcr", NULL); - return ZN_ERROR; - } - if ((aa.automatic != ((AutoAlign *) valp)->automatic) || - (aa.align[0] != ((AutoAlign *) valp)->align[0]) || - (aa.align[1] != ((AutoAlign *) valp)->align[1]) || - (aa.align[2] != ((AutoAlign *) valp)->align[2])) { - *((AutoAlign *) valp) = aa; + if ((aa.automatic != ((ZnAutoAlign *) valp)->automatic) || + (aa.align[0] != ((ZnAutoAlign *) valp)->align[0]) || + (aa.align[1] != ((ZnAutoAlign *) valp)->align[1]) || + (aa.align[2] != ((ZnAutoAlign *) valp)->align[2])) { + *((ZnAutoAlign *) valp) = aa; *flags |= desc->flags; } break; } case ZN_CONFIG_LEADER_ANCHORS: - /* - * Format is: lChar leftLeaderAnchor [ lChar rightLeaderAnchor] - * - * If lChar is a '|', leftLeaderAnchor and rightLeaderAnchor are the indices - * of the fields that serve to anchor the label's leader. More specifically - * the bottom left corner of the left field and the bottom right corner of - * the right field are used as the anchors. - * If lChar is '%', leftLeaderAnchor and rightLeaderAnchor should be - * specified as 'valxval', 'val' being a percentage (max 100) of the - * width/height of the label bounding box. - * If rightLeaderAnchor is not specified it defaults to leftLeaderAnchor. - * If neither of them are specified, the center of the label is used as an - * anchor. - */ { - LeaderAnchors lanch = NULL; - int anchors[4]; - int index, num_tok, anchor_index=0; - - str = Tcl_GetString(args[i+1]); - while (*str && (*str == ' ')) { - str++; - } - while (*str && (anchor_index < 4)) { - switch (*str) { - case '|': - num_tok = sscanf(str, "|%d%n", &anchors[anchor_index], &index); - if (num_tok != 1) { - la_error: - Tcl_AppendResult(wi->interp, " incorrect leader anchors \"", - Tcl_GetString(args[i+1]), "\"", NULL); - return ZN_ERROR; - } - anchors[anchor_index+1] = -1; - break; - case '%': - num_tok = sscanf(str, "%%%dx%d%n", &anchors[anchor_index], - &anchors[anchor_index+1], &index); - if (num_tok != 2) { - goto la_error; - } - if (anchors[anchor_index] < 0) { - anchors[anchor_index] = 0; - } - if (anchors[anchor_index] > 100) { - anchors[anchor_index] = 100; - } - if (anchors[anchor_index+1] < 0) { - anchors[anchor_index+1] = 0; - } - if (anchors[anchor_index+1] > 100) { - anchors[anchor_index+1] = 100; - } - break; - } - anchor_index += 2; - str += index; - } - /* - * If empty, pick the default (center of the bounding box). - */ - if (anchor_index != 0) { - lanch = (LeaderAnchors ) ZnMalloc(sizeof(LeaderAnchorsStruct)); - lanch->left_x = anchors[0]; - lanch->left_y = anchors[1]; - if (anchor_index == 2) { - lanch->right_x = lanch->left_x; - lanch->right_y = lanch->left_y; - } - else { - lanch->right_x = anchors[2]; - lanch->right_y = anchors[3]; - } + ZnLeaderAnchors lanch = NULL; + if (ZnGetLeaderAnchors(wi, Tcl_GetString(args[i+1]), &lanch) == TCL_ERROR) { + Tcl_AppendResult(wi->interp, " leader anchors expected for attribute \"", + Tcl_GetString(args[i]), "\"", NULL); + return TCL_ERROR; } - if (*((LeaderAnchors *) valp) != NULL) { - ZnFree(*((LeaderAnchors *) valp)); - *((LeaderAnchors *) valp) = lanch; + if (*((ZnLeaderAnchors *) valp) != NULL) { + ZnFree(*((ZnLeaderAnchors *) valp)); + *((ZnLeaderAnchors *) valp) = lanch; *flags |= desc->flags; } else { if (lanch != NULL) { - *((LeaderAnchors *) valp) = lanch; + *((ZnLeaderAnchors *) valp) = lanch; *flags |= desc->flags; } } @@ -1079,7 +892,7 @@ ZnConfigureAttributes(WidgetInfo *wi, } } } - return ZN_OK; + return TCL_OK; } @@ -1096,55 +909,53 @@ ZnConfigureAttributes(WidgetInfo *wi, ********************************************************************************** */ static void -AttributeToObj(WidgetInfo *wi, +AttributeToObj(ZnWInfo *wi, void *record, ZnAttrConfig *desc, char *buffer, Tcl_Obj *result) { char *valp = ((char *) record) + desc->offset; - Tk_Uid str = ""; + char *str = ""; Tcl_Obj *o; - int i; - + unsigned int i; + switch (desc->type) { case ZN_CONFIG_GRADIENT: if (*((ZnGradient **) valp)) { str = ZnNameOfGradient(*((ZnGradient **) valp)); - Tcl_SetStringObj(result, str, strlen(str)); } break; case ZN_CONFIG_GRADIENT_LIST: { - int num_grads; - ZnGradient **grads; + unsigned int num_grads; + ZnGradient **grads; if (*((ZnList *) valp)) { grads = ZnListArray(*((ZnList *) valp)); num_grads = ZnListSize(*((ZnList *) valp)); for (i = 0; i < num_grads; i++) { - o = NewStringObj(ZnNameOfGradient(grads[i])); + o = Tcl_NewStringObj(ZnNameOfGradient(grads[i]), -1); Tcl_ListObjAppendElement(wi->interp, result, o); } + return; } } break; case ZN_CONFIG_BOOL: Tcl_SetBooleanObj(result, ISSET(*((unsigned short *) valp), desc->bool_bit)?1:0); - break; + return; case ZN_CONFIG_IMAGE: case ZN_CONFIG_BITMAP: - str = ""; if (*((ZnImage *) valp)) { str = ZnNameOfImage(*((ZnImage *) valp)); } - Tcl_SetStringObj(result, str, strlen(str)); break; case ZN_CONFIG_BITMAP_LIST: { - int num_pats=0; - ZnImage *pats; + unsigned int num_pats=0; + ZnImage *pats; if (*((ZnList *) valp)) { pats = (ZnImage *) ZnListArray(*((ZnList *) valp)); @@ -1152,206 +963,84 @@ AttributeToObj(WidgetInfo *wi, for (i = 0; i < num_pats; i++) { if (pats[i] != ZnUnspecifiedImage) { - o = NewStringObj(ZnNameOfImage(pats[i])); + o = Tcl_NewStringObj(ZnNameOfImage(pats[i]), -1); } else { - o = NewStringObj(""); + o = Tcl_NewStringObj("", -1); } Tcl_ListObjAppendElement(wi->interp, result, o); } + return; } break; } case ZN_CONFIG_TAG_LIST: { - int num_tags=0; - Tk_Uid *tags; + unsigned int num_tags=0; + Tk_Uid *tags; if (*((ZnList *) valp)) { tags = (Tk_Uid *) ZnListArray(*((ZnList *) valp)); num_tags = ZnListSize(*((ZnList *) valp)); for (i = 0; i < num_tags; i++) { Tcl_ListObjAppendElement(wi->interp, result, - NewStringObj(tags[i])); + Tcl_NewStringObj(tags[i], -1)); } + return; } break; } case ZN_CONFIG_STRING: case ZN_CONFIG_MAP_INFO: - str = *((char **) valp); - if (str) { - Tcl_SetStringObj(result, str, strlen(str)); - } - else { - Tcl_SetStringObj(result, "", 0); + if (*((char **) valp)) { + str = *((char **) valp); } break; case ZN_CONFIG_FONT: - str = ""; if (*((Tk_Font *) valp)) { - str = Tk_NameOfFont(*((Tk_Font *) valp)); + str = (char *) Tk_NameOfFont(*((Tk_Font *) valp)); } - Tcl_SetStringObj(result, str, strlen(str)); break; case ZN_CONFIG_EDGE_LIST: - { - Border border = *((Border *) valp); - if (border == NO_BORDER) { - Tcl_SetStringObj(result, NO_BORDER_SPEC, strlen(NO_BORDER_SPEC)); - break; - } - buffer[0] = 0; - if ((border & CONTOUR_BORDER) == CONTOUR_BORDER) { - strcat(buffer, CONTOUR_SPEC); - } - else { - if (border & LEFT_BORDER) { - strcat(buffer, LEFT_SPEC); - } - if (border & RIGHT_BORDER) { - if (buffer[0] != 0) { - strcat(buffer, " "); - } - strcat(buffer, RIGHT_SPEC); - } - if (border & TOP_BORDER) { - if (buffer[0] != 0) { - strcat(buffer, " "); - } - strcat(buffer, TOP_SPEC); - } - if (border & BOTTOM_BORDER) { - if (buffer[0] != 0) { - strcat(buffer, " "); - } - strcat(buffer, BOTTOM_SPEC); - } - } - if (border & OBLIQUE) { - if (buffer[0] != 0) { - strcat(buffer, " "); - } - strcat(buffer, OBLIQUE_SPEC); - } - if (border & COUNTER_OBLIQUE) { - if (buffer[0] != 0) { - strcat(buffer, " "); - } - strcat(buffer, COUNTER_OBLIQUE_SPEC); - } - Tcl_SetStringObj(result, buffer, strlen(buffer)); - } - break; + str = buffer; + ZnNameOfBorder(*((ZnBorder *) valp), buffer); + break; case ZN_CONFIG_LINE_SHAPE: - { - LineShape line_shape = *((LineShape *) valp); - switch (line_shape) { - case LINE_STRAIGHT: - str = STRAIGHT_SPEC; - break; - case LINE_RIGHT_LIGHTNING: - str = RIGHT_LIGHTNING_SPEC; - break; - case LINE_LEFT_LIGHTNING: - str = LEFT_LIGHTNING_SPEC; - break; - case LINE_RIGHT_CORNER: - str = RIGHT_CORNER_SPEC; - break; - case LINE_LEFT_CORNER: - str = LEFT_CORNER_SPEC; - break; - case LINE_DOUBLE_RIGHT_CORNER: - str = DOUBLE_RIGHT_CORNER_SPEC; - break; - case LINE_DOUBLE_LEFT_CORNER: - str = DOUBLE_LEFT_CORNER_SPEC; - break; - } - Tcl_SetStringObj(result, str, strlen(str)); - break; - } + str = ZnNameOfLineShape(*((ZnLineShape *) valp)); + break; case ZN_CONFIG_FILL_RULE: - { - int fill_rule = *((int *) valp); - switch (fill_rule) { - case GLU_TESS_WINDING_ODD: - str = "odd"; - break; - case GLU_TESS_WINDING_NONZERO: - str = "nonzero"; - break; - case GLU_TESS_WINDING_POSITIVE: - str = "positive"; - break; - case GLU_TESS_WINDING_NEGATIVE: - str = "negative"; - break; - case GLU_TESS_WINDING_ABS_GEQ_TWO: - str = "abs_geq_2"; - break; - } - Tcl_SetStringObj(result, str, strlen(str)); - break; - } + str = ZnNameOfFillRule(*((ZnFillRule *) valp)); + break; case ZN_CONFIG_LINE_STYLE: - { - LineStyle line_style = *((LineStyle *) valp); - switch (line_style) { - case LINE_SIMPLE: - str = SIMPLE_SPEC; - break; - case LINE_DASHED: - str = DASHED_SPEC; - break; - case LINE_MIXED: - str = MIXED_SPEC; - break; - case LINE_DOTTED: - str = DOTTED_SPEC; - break; - } - Tcl_SetStringObj(result, str, strlen(str)); - break; - } + str = ZnNameOfLineStyle(*((ZnLineStyle *) valp)); + break; case ZN_CONFIG_LINE_END: - { - ZnLineEnd line_end = *((ZnLineEnd *) valp); - - if (line_end) { - str = LineEndGetString(line_end); - Tcl_SetStringObj(result, str, strlen(str)); - } - break; + if (*((ZnLineEnd *) valp)) { + str = ZnLineEndGetString(*((ZnLineEnd *) valp)); } + break; case ZN_CONFIG_RELIEF: - str = ZnNameOfRelief(*((ReliefStyle *) valp)); - Tcl_SetStringObj(result, str, strlen(str)); + str = ZnNameOfRelief(*((ZnReliefStyle *) valp)); break; case ZN_CONFIG_JOIN_STYLE: - str = Tk_NameOfJoinStyle(*((int *) valp)); - Tcl_SetStringObj(result, str, strlen(str)); + str = (char *) Tk_NameOfJoinStyle(*((int *) valp)); break; case ZN_CONFIG_CAP_STYLE: - str = Tk_NameOfCapStyle(*((int *) valp)); - Tcl_SetStringObj(result, str, strlen(str)); + str = (char *) Tk_NameOfCapStyle(*((int *) valp)); break; case ZN_CONFIG_POINT: - { - Tcl_ListObjAppendElement(wi->interp, result, NewDoubleObj(((ZnPoint *) valp)->x)); - Tcl_ListObjAppendElement(wi->interp, result, NewDoubleObj(((ZnPoint *) valp)->y)); - break; - } + Tcl_ListObjAppendElement(wi->interp, result, Tcl_NewDoubleObj(((ZnPoint *) valp)->x)); + Tcl_ListObjAppendElement(wi->interp, result, Tcl_NewDoubleObj(((ZnPoint *) valp)->y)); + return; case ZN_CONFIG_ITEM: - if (*((Item *) valp) != ZN_NO_ITEM) { - Tcl_SetLongObj(result, (*((Item *) valp))->id); + if (*((ZnItem *) valp) != ZN_NO_ITEM) { + Tcl_SetLongObj(result, (int) (*((ZnItem *) valp))->id); + return; } break; case ZN_CONFIG_WINDOW: - if (*((ZnWindow *) valp) != NULL) { - str = Tk_PathName(*((ZnWindow *) valp)); - Tcl_SetStringObj(result, str, strlen(str)); + if (*((Tk_Window *) valp) != NULL) { + str = Tk_PathName(*((Tk_Window *) valp)); } break; case ZN_CONFIG_INT: @@ -1360,85 +1049,31 @@ AttributeToObj(WidgetInfo *wi, case ZN_CONFIG_ANGLE: case ZN_CONFIG_ALPHA: Tcl_SetIntObj(result, *((int *) valp)); - break; + return; case ZN_CONFIG_DIM: Tcl_SetDoubleObj(result, *((ZnDim *) valp)); - break; + return; case ZN_CONFIG_ALIGNMENT: - str = Tk_NameOfJustify(*((ZnJustify *) valp)); - Tcl_SetStringObj(result, str, strlen(str)); + str = (char *) Tk_NameOfJustify(*((Tk_Justify *) valp)); break; case ZN_CONFIG_ANCHOR: - str = Tk_NameOfAnchor(*((Tk_Anchor *) valp)); - Tcl_SetStringObj(result, str, strlen(str)); + str = (char *) Tk_NameOfAnchor(*((Tk_Anchor *) valp)); break; case ZN_CONFIG_LABEL_FORMAT: - { - ZnLabelFormat frmt = *((ZnLabelFormat *) valp); - - if (frmt) { - str = LabelFormatGetString(frmt); - Tcl_SetStringObj(result, str, strlen(str)); - } - break; + if (*((ZnLabelFormat *) valp)) { + str = ZnLFGetString(*((ZnLabelFormat *) valp)); } + break; case ZN_CONFIG_AUTO_ALIGNMENT: - { - AutoAlign *aa = (AutoAlign *) valp; - int i; - if (aa->automatic == False) { - str = "-"; - Tcl_SetStringObj(result, str, strlen(str)); - } - else { - buffer[0] = 0; - str = buffer; - for (i = 0; i < 3; i++) { - switch (aa->align[i]) { - case ZnJustifyLeft: - strcat(buffer, "l"); - break; - case ZnJustifyCenter: - strcat(buffer, "c"); - break; - case ZnJustifyRight: - strcat(buffer, "r"); - break; - } - } - Tcl_SetStringObj(result, buffer, strlen(buffer)); - } - } + str = buffer; + ZnNameOfAutoAlign((ZnAutoAlign *) valp, buffer); break; - case ZN_CONFIG_LEADER_ANCHORS: - { - LeaderAnchors lanch = *((LeaderAnchors *) valp); - char *ptr = buffer; - int count; - - if (!lanch) { - ptr = "%50x50"; - } - else { - if (lanch->left_y < 0) { - count = sprintf(ptr, "|%d", lanch->left_x); - } - else { - count = sprintf(ptr, "%%%dx%d", lanch->left_x, lanch->left_y); - } - ptr += count; - if (lanch->right_y < 0) { - count = sprintf(ptr, "|%d", lanch->right_x); - } - else { - count = sprintf(ptr, "%%%dx%d", lanch->right_x, lanch->right_y); - } - ptr = buffer; - } - Tcl_SetStringObj(result, ptr, strlen(ptr)); - } + str = buffer; + ZnNameOfLeaderAnchors(*((ZnLeaderAnchors *) valp), buffer); + break; } + Tcl_SetStringObj(result, str, -1); } @@ -1450,7 +1085,7 @@ AttributeToObj(WidgetInfo *wi, ********************************************************************************** */ int -ZnQueryAttribute(WidgetInfo *wi, +ZnQueryAttribute(ZnWInfo *wi, void *record, ZnAttrConfig *desc, Tcl_Obj *attr_name) @@ -1462,7 +1097,7 @@ ZnQueryAttribute(WidgetInfo *wi, while (True) { if (desc->type == ZN_CONFIG_END) { Tcl_AppendResult(wi->interp, "unknown attribute \"", attr_uid, "\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } else if (attr_uid == desc->uid) { result = Tcl_GetObjResult(wi->interp); @@ -1473,7 +1108,7 @@ ZnQueryAttribute(WidgetInfo *wi, desc++; } } - return ZN_OK; + return TCL_OK; } @@ -1497,16 +1132,16 @@ ZnItemClassList() * ********************************************************************************** */ -ItemClass +ZnItemClass ZnLookupItemClass(char *class_name) { - ItemClass *class; + ZnItemClass *class; int i, num_classes; - class = (ItemClass *) ZnListArray(item_classes); + class = (ZnItemClass *) ZnListArray(item_classes); num_classes = ZnListSize(item_classes); for (i = 0; i < num_classes; i++) { - if (strcasecmp((class[i])->name, class_name) == 0) { + if (strcmp((class[i])->name, class_name) == 0) { return class[i]; } } @@ -1522,7 +1157,7 @@ ZnLookupItemClass(char *class_name) ********************************************************************************** */ void -ZnAddItemClass(ItemClass class) +ZnAddItemClass(ZnItemClass class) { if (!ZnLookupItemClass(class->name)) { ZnListAdd(item_classes, &class, ZnListTail); @@ -1543,7 +1178,7 @@ ZnItemInit() { /* First check if static part already inited */ if (item_classes == NULL) { - item_classes = ZnListNew(16, sizeof(ItemClass)); + item_classes = ZnListNew(16, sizeof(ZnItemClass)); ZnAddItemClass(ZnTrack); ZnAddItemClass(ZnWayPoint); ZnAddItemClass(ZnMap); @@ -1556,8 +1191,8 @@ ZnItemInit() ZnAddItemClass(ZnGroup); ZnAddItemClass(ZnIcon); ZnAddItemClass(ZnText); - ZnAddItemClass(ZnWind); - InitAttrDesc(FIELD.attr_desc); + ZnAddItemClass(ZnWindow); + InitAttrDesc(ZnFIELD.attr_desc); } } @@ -1572,8 +1207,8 @@ ZnItemInit() ********************************************************************************** */ static void -UpdateItemDependency(Item item, - Item old_connection) +UpdateItemDependency(ZnItem item, + ZnItem old_connection) { if (old_connection == ZN_NO_ITEM) { /* Add a connection */ @@ -1603,13 +1238,13 @@ UpdateItemDependency(Item item, ********************************************************************************** */ static void -ExtractItem(Item item) +ExtractItem(ZnItem item) { - WidgetInfo *wi = item->wi; - Item group = item->parent; + ZnWInfo *wi = item->wi; + ZnItem group = item->parent; /* damage bounding boxes */ - if (ISSET(item->flags, VISIBLE_BIT)) { + if (ISSET(item->flags, ZN_VISIBLE_BIT)) { ZnDamage(wi, &item->item_bounding_box); } @@ -1617,7 +1252,7 @@ ExtractItem(Item item) * Tell that we need to repick */ if (item->class != ZnGroup) { - SET(wi->events_flags, INTERNAL_NEED_REPICK); + SET(wi->flags, ZN_INTERNAL_NEED_REPICK); } if (group != ZN_NO_ITEM) { @@ -1652,9 +1287,9 @@ ExtractItem(Item item) ********************************************************************************** */ static void -InsertItem(Item item, - Item grp, - Item mark_item, +InsertItem(ZnItem item, + ZnItem grp, + ZnItem mark_item, ZnBool before) { if (!grp) { @@ -1680,16 +1315,16 @@ InsertItem(Item item, ********************************************************************************** */ static void -UpdateItemPriority(Item item, - Item mark_item, +UpdateItemPriority(ZnItem item, + ZnItem mark_item, ZnBool before) { - Item parent = item->parent; + ZnItem parent = item->parent; ZnGroupExtractItem(item); InsertItem(item, parent, mark_item, before); Invalidate(item, ZN_DRAW_FLAG); - SET(item->wi->events_flags, INTERNAL_NEED_REPICK); + SET(item->wi->flags, ZN_INTERNAL_NEED_REPICK); } @@ -1706,9 +1341,9 @@ UpdateItemPriority(Item item, ********************************************************************************** */ static void -SetId(Item item) +SetId(ZnItem item) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; Tcl_HashEntry *entry; int dummy; @@ -1719,7 +1354,7 @@ SetId(Item item) } static void -FreeId(Item item) +FreeId(ZnItem item) { Tcl_HashEntry *entry; @@ -1744,11 +1379,11 @@ FreeId(Item item) ********************************************************************************** */ static void -AddTag(Item item, +AddTag(ZnItem item, Tk_Uid tag) { - int num, i; - char **ptr; + int num, i; + char **ptr; /* * No tags yet. @@ -1771,7 +1406,7 @@ AddTag(Item item, /* * Add it. */ - ZnListAdd(item->tags, &tag, ZnListTail); + ZnListAdd(item->tags, (void *) &tag, ZnListTail); } /* @@ -1782,10 +1417,10 @@ AddTag(Item item, ********************************************************************************** */ static void -RemoveTag(Item item, +RemoveTag(ZnItem item, Tk_Uid tag) { - int indx, num; + unsigned int indx, num; char **ptr; if (!item->tags) { @@ -1814,7 +1449,7 @@ RemoveTag(Item item, ********************************************************************************** */ static void -FreeTags(Item item) +FreeTags(ZnItem item) { if (!item->tags) { return; @@ -1832,7 +1467,7 @@ FreeTags(Item item) ********************************************************************************** */ static ZnBool -HasTag(Item item, +HasTag(ZnItem item, Tk_Uid tag) { int num; @@ -1867,15 +1502,15 @@ HasTag(Item item, * ********************************************************************************** */ -Item -ZnCreateItem(WidgetInfo *wi, - ItemClass item_class, +ZnItem +ZnCreateItem(ZnWInfo *wi, + ZnItemClass item_class, int *argc, Tcl_Obj *CONST *args[]) { - Item item; + ZnItem item; - item = (Item) ZnMalloc(item_class->size); + item = ZnMalloc(item_class->size); /* Initialize common state */ item->class = item_class; @@ -1883,20 +1518,20 @@ ZnCreateItem(WidgetInfo *wi, item->parent = NULL; item->previous = ZN_NO_ITEM; item->next = ZN_NO_ITEM; - CLEAR(item->flags, UPDATE_DEPENDENT_BIT); + CLEAR(item->flags, ZN_UPDATE_DEPENDENT_BIT); item->inv_flags = 0; item->transfo = NULL; item->parent = NULL; item->connected_item = ZN_NO_ITEM; -#ifdef GLX +#ifdef GL #ifdef GL_LIST item->gl_list = 0; #endif #endif - ResetBBox(&item->item_bounding_box); + ZnResetBBox(&item->item_bounding_box); /* Init item specific attributes */ - if (item_class->Init(item, argc, args) == ZN_ERROR) { + if (item_class->Init(item, argc, args) == TCL_ERROR) { ZnFree(item); return ZN_NO_ITEM; } @@ -1904,7 +1539,7 @@ ZnCreateItem(WidgetInfo *wi, SetId(item); item->tags = NULL; - SET(wi->events_flags, INTERNAL_NEED_REPICK); + SET(wi->flags, ZN_INTERNAL_NEED_REPICK); wi->num_items++; return (item); @@ -1919,25 +1554,26 @@ ZnCreateItem(WidgetInfo *wi, * ********************************************************************************** */ -static Item -CloneItem(Item model) +static ZnItem +CloneItem(ZnItem model) { - WidgetInfo *wi = model->wi; - Item item; + ZnWInfo *wi = model->wi; + ZnItem item; Tk_Uid *tags; - int i, num_tags; + unsigned int num_tags; + int i; if (!model->parent) { return ZN_NO_ITEM; } - item = (Item) ZnMalloc(model->class->size); + item = ZnMalloc(model->class->size); memcpy(item, model, model->class->size); item->previous = ZN_NO_ITEM; item->next = ZN_NO_ITEM; item->connected_item = ZN_NO_ITEM; - CLEAR(item->flags, UPDATE_DEPENDENT_BIT); + CLEAR(item->flags, ZN_UPDATE_DEPENDENT_BIT); item->inv_flags = 0; SetId(item); @@ -1957,9 +1593,11 @@ CloneItem(Item model) /* Call item's clone to duplicate non shared resources */ item->class->Clone(item); - SET(wi->events_flags, INTERNAL_NEED_REPICK); + SET(wi->flags, ZN_INTERNAL_NEED_REPICK); wi->num_items++; + Invalidate(item, ZN_COORDS_FLAG); + return item; } @@ -1972,39 +1610,39 @@ CloneItem(Item model) ********************************************************************************** */ static int -ConfigureItem(Item item, +ConfigureItem(ZnItem item, int field, int argc, Tcl_Obj *CONST argv[], ZnBool init) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; int flags; - ZnBool previous_visible = init ? False : ISSET(item->flags, VISIBLE_BIT); + ZnBool previous_visible = init ? False : ISSET(item->flags, ZN_VISIBLE_BIT); flags = 0; ASSIGN(flags, ZN_COORDS_FLAG, init); if (argv) { if (field < 0){ - if (item->class->Configure(item, argc, argv, &flags) == ZN_ERROR) { - return ZN_ERROR; + if (item->class->Configure(item, argc, argv, &flags) == TCL_ERROR) { + return TCL_ERROR; } if (item->class->GetFieldSet && ISSET(flags, ZN_CLFC_FLAG)) { - FIELD.ClearFieldCache(item->class->GetFieldSet(item), -1); + ZnFIELD.ClearFieldCache(item->class->GetFieldSet(item), -1); } } else if (item->class->GetFieldSet) { - if (FIELD.ConfigureField(item->class->GetFieldSet(item), - field, argc, argv, &flags) == ZN_ERROR) { - return ZN_ERROR; + if (ZnFIELD.ConfigureField(item->class->GetFieldSet(item), + field, argc, argv, &flags) == TCL_ERROR) { + return TCL_ERROR; } } else { - return ZN_ERROR; + return TCL_ERROR; } } - if (previous_visible && ISCLEAR(item->flags, VISIBLE_BIT)) { + if (previous_visible && ISCLEAR(item->flags, ZN_VISIBLE_BIT)) { /* * Special case when the item has its visibility * just turned out. @@ -2014,7 +1652,7 @@ ConfigureItem(Item item, Invalidate(item, flags); - return ZN_OK; + return TCL_OK; } @@ -2026,7 +1664,7 @@ ConfigureItem(Item item, ********************************************************************************** */ static int -QueryItem(Item item, +QueryItem(ZnItem item, int field, int argc, Tcl_Obj *CONST argv[]) @@ -2035,11 +1673,11 @@ QueryItem(Item item, return item->class->Query(item, argc, argv); } else if (item->class->GetFieldSet) { - return FIELD.QueryField(item->class->GetFieldSet(item), - field, argc, argv); + return ZnFIELD.QueryField(item->class->GetFieldSet(item), + field, argc, argv); } - return ZN_ERROR; + return TCL_ERROR; } @@ -2110,15 +1748,15 @@ ComposeTransform(ZnTransfo *transfo, ********************************************************************************** */ static void -GetItemTransform(Item item, +GetItemTransform(ZnItem item, ZnTransfo *t) { - Item *items; + ZnItem *items; int i; ZnTransfo t_tmp, *t1, *t2, *swap; if (item_stack == NULL) { - item_stack = ZnListNew(16, sizeof(Item)); + item_stack = ZnListNew(16, sizeof(ZnItem)); } else { ZnListEmpty(item_stack); @@ -2132,11 +1770,11 @@ GetItemTransform(Item item, ZnTransfoSetIdentity(t); t1 = t; t2 = &t_tmp; - items = (Item *) ZnListArray(item_stack); + items = (ZnItem *) ZnListArray(item_stack); for (i = ZnListSize(item_stack)-1; i >= 0; i--) { ComposeTransform(items[i]->transfo, t1, t2, - ISSET(items[i]->flags, COMPOSE_SCALE_BIT), - ISSET(items[i]->flags, COMPOSE_ROTATION_BIT)); + ISSET(items[i]->flags, ZN_COMPOSE_SCALE_BIT), + ISSET(items[i]->flags, ZN_COMPOSE_ROTATION_BIT)); swap = t2; t2 = t1; t1 = swap; @@ -2161,7 +1799,7 @@ GetItemTransform(Item item, ********************************************************************************** */ void -ZnResetTransformStack(WidgetInfo *wi) +ZnResetTransformStack(ZnWInfo *wi) { ZnListAssertSize(wi->transfo_stack, 1); wi->current_transfo = (ZnTransfo *) ZnListAt(wi->transfo_stack, 0); @@ -2169,26 +1807,26 @@ ZnResetTransformStack(WidgetInfo *wi) } void -ZnInitTransformStack(WidgetInfo *wi) +ZnInitTransformStack(ZnWInfo *wi) { wi->transfo_stack = ZnListNew(8, sizeof(ZnTransfo)); ZnResetTransformStack(wi); } void -ZnFreeTransformStack(WidgetInfo *wi) +ZnFreeTransformStack(ZnWInfo *wi) { ZnListFree(wi->transfo_stack); } void -ZnPushTransform(WidgetInfo *wi, +ZnPushTransform(ZnWInfo *wi, ZnTransfo *transfo, ZnBool compose_scale, ZnBool compose_rot) { ZnTransfo *next_t; - int num_t; + unsigned int num_t; /* * Push the current transform and concatenate @@ -2204,7 +1842,7 @@ ZnPushTransform(WidgetInfo *wi, } void -ZnPopTransform(WidgetInfo *wi) +ZnPopTransform(ZnWInfo *wi) { /* * Restore the previous transform. @@ -2232,13 +1870,13 @@ ZnPopTransform(WidgetInfo *wi) */ typedef struct _ClipState { ZnBool simple; /* The clip is an aligned rectangle. */ - Region region; /* The X region used to draw and to */ + TkRegion region; /* The region used to draw and to */ /* probe for picking. */ ZnBBox clip_box; /* The bounding box of the clip area. */ } ClipState; void -ZnResetClipStack(WidgetInfo *wi) +ZnResetClipStack(ZnWInfo *wi) { int i; ClipState *clips = (ClipState *) ZnListArray(wi->clip_stack); @@ -2248,30 +1886,30 @@ ZnResetClipStack(WidgetInfo *wi) * empty when this function is called. */ for (i = ZnListSize(wi->clip_stack)-1; i >= 0; i--) { - XDestroyRegion(clips[i].region); + TkDestroyRegion(clips[i].region); } ZnListEmpty(wi->clip_stack); wi->current_clip = NULL; } void -ZnInitClipStack(WidgetInfo *wi) +ZnInitClipStack(ZnWInfo *wi) { wi->clip_stack = ZnListNew(8, sizeof(ClipState)); ZnResetClipStack(wi); } void -ZnFreeClipStack(WidgetInfo *wi) +ZnFreeClipStack(ZnWInfo *wi) { ZnListFree(wi->clip_stack); } ZnBool -ZnCurrentClip(WidgetInfo *wi, - Region *reg, - ZnBBox **clip_box, - ZnBool *simple) +ZnCurrentClip(ZnWInfo *wi, + TkRegion *reg, + ZnBBox **clip_box, + ZnBool *simple) { if (wi->current_clip) { if (reg) { @@ -2295,16 +1933,16 @@ ZnCurrentClip(WidgetInfo *wi, * is a regular pointer to a multi contour poly. */ void -ZnPushClip(WidgetInfo *wi, +ZnPushClip(ZnWInfo *wi, ZnTriStrip *tristrip, ZnBool simple, ZnBool set_gc) { - int i, j, num_clips; - int num_pts, max_num_pts; + unsigned int i, j, num_clips; + unsigned int num_pts, max_num_pts; ZnPoint *p; ClipState *previous_clip=NULL; - Region reg, reg_op, reg_to; + TkRegion reg, reg_op, reg_to; XRectangle rect; XPoint xpts[3]; @@ -2336,54 +1974,56 @@ ZnPushClip(WidgetInfo *wi, * Compute the local region. */ if (simple) { - rect.x = tristrip->strips[0].points[0].x; - rect.y = tristrip->strips[0].points[0].y; - rect.width = tristrip->strips[0].points[1].x - tristrip->strips[0].points[0].x; - rect.height = tristrip->strips[0].points[1].y - tristrip->strips[0].points[0].y; - reg = XCreateRegion(); - XUnionRectWithRegion(&rect, reg, reg); + rect.x = (short) tristrip->strips[0].points[0].x; + rect.y = (short) tristrip->strips[0].points[0].y; + rect.width = ((unsigned short) (tristrip->strips[0].points[1].x - + tristrip->strips[0].points[0].x)); + rect.height = ((unsigned short) (tristrip->strips[0].points[1].y - + tristrip->strips[0].points[0].y)); + reg = TkCreateRegion(); + TkUnionRectWithRegion(&rect, reg, reg); /*printf("Adding a simple clip: %d, %d, %d, %d\n", rect.x, rect.y, rect.width, rect.height);*/ } else { - reg = XCreateRegion(); + reg = TkCreateRegion(); for (j = 0; j < tristrip->num_strips; j++) { num_pts = tristrip->strips[j].num_points; p = tristrip->strips[j].points; if (tristrip->strips[j].fan) { - xpts[0].x = REAL_TO_INT(p->x); - xpts[0].y = REAL_TO_INT(p->y); + xpts[0].x = ZnNearestInt(p->x); + xpts[0].y = ZnNearestInt(p->y); p++; - xpts[1].x = REAL_TO_INT(p->x); - xpts[1].y = REAL_TO_INT(p->y); + xpts[1].x = ZnNearestInt(p->x); + xpts[1].y = ZnNearestInt(p->y); p++; for (i = 2; i < num_pts; i++, p++) { - xpts[2].x = REAL_TO_INT(p->x); - xpts[2].y = REAL_TO_INT(p->y); - reg_op = XPolygonRegion(xpts, 3, EvenOddRule); - reg_to = XCreateRegion(); - XUnionRegion(reg, reg_op, reg_to); - XDestroyRegion(reg); - XDestroyRegion(reg_op); + xpts[2].x = ZnNearestInt(p->x); + xpts[2].y = ZnNearestInt(p->y); + reg_op = (TkRegion) ZnPolygonRegion(xpts, 3, EvenOddRule); + reg_to = TkCreateRegion(); + ZnUnionRegion(reg, reg_op, reg_to); + TkDestroyRegion(reg); + TkDestroyRegion(reg_op); reg = reg_to; xpts[1] = xpts[2]; } } else { - xpts[0].x = p->x; - xpts[0].y = p->y; + xpts[0].x = (short) p->x; + xpts[0].y = (short) p->y; p++; - xpts[1].x = p->x; - xpts[1].y = p->y; + xpts[1].x = (short) p->x; + xpts[1].y = (short) p->y; p++; for (i = 2 ; i < num_pts; i++, p++) { - xpts[2].x = p->x; - xpts[2].y = p->y; - reg_op = XPolygonRegion(xpts, 3, EvenOddRule); - reg_to = XCreateRegion(); - XUnionRegion(reg, reg_op, reg_to); - XDestroyRegion(reg); - XDestroyRegion(reg_op); + xpts[2].x = (short) p->x; + xpts[2].y = (short) p->y; + reg_op = (TkRegion) ZnPolygonRegion(xpts, 3, EvenOddRule); + reg_to = TkCreateRegion(); + ZnUnionRegion(reg, reg_op, reg_to); + TkDestroyRegion(reg); + TkDestroyRegion(reg_op); reg = reg_to; xpts[0] = xpts[1]; xpts[1] = xpts[2]; @@ -2396,15 +2036,15 @@ ZnPushClip(WidgetInfo *wi, * Combine with previous region if any. */ if (previous_clip) { - wi->current_clip->region = XCreateRegion(); - XIntersectRegion(reg, previous_clip->region, wi->current_clip->region); - XDestroyRegion(reg); + wi->current_clip->region = TkCreateRegion(); + TkIntersectRegion(reg, previous_clip->region, wi->current_clip->region); + TkDestroyRegion(reg); /*printf("Merging with previous clip\n");*/ } else { wi->current_clip->region = reg; } - XClipBox(wi->current_clip->region, &rect); + TkClipBox(wi->current_clip->region, &rect); wi->current_clip->clip_box.orig.x = rect.x; wi->current_clip->clip_box.orig.y = rect.y; wi->current_clip->clip_box.corner.x = rect.x + rect.width; @@ -2415,20 +2055,20 @@ ZnPushClip(WidgetInfo *wi, */ if (set_gc) { if (wi->render) { -#ifdef GLX +#ifdef GL glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glEnable(GL_STENCIL_TEST); - glStencilFunc(GL_EQUAL, num_clips, 0xFF); + glStencilFunc(GL_EQUAL, (GLint) num_clips, 0xFF); glStencilOp(GL_KEEP, GL_INCR, GL_INCR); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); if (simple) { /* printf("Clip box is : %d, %d, %d, %d, num_clips : %d\n", rect.x, rect.y, rect.width, rect.height, num_clips);*/ glBegin(GL_QUADS); - glVertex2f(wi->current_clip->clip_box.orig.x, wi->current_clip->clip_box.orig.y); - glVertex2f(wi->current_clip->clip_box.orig.x, wi->current_clip->clip_box.corner.y); - glVertex2f(wi->current_clip->clip_box.corner.x, wi->current_clip->clip_box.corner.y); - glVertex2f(wi->current_clip->clip_box.corner.x, wi->current_clip->clip_box.orig.y); + glVertex2d(wi->current_clip->clip_box.orig.x, wi->current_clip->clip_box.orig.y); + glVertex2d(wi->current_clip->clip_box.orig.x, wi->current_clip->clip_box.corner.y); + glVertex2d(wi->current_clip->clip_box.corner.x, wi->current_clip->clip_box.corner.y); + glVertex2d(wi->current_clip->clip_box.corner.x, wi->current_clip->clip_box.orig.y); glEnd(); } else { @@ -2442,24 +2082,24 @@ ZnPushClip(WidgetInfo *wi, glBegin(GL_TRIANGLE_STRIP); } for (i = 0; i < num_pts; i++, p++) { - glVertex2f(p->x, p->y); + glVertex2d(p->x, p->y); } glEnd(); } } glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - glStencilFunc(GL_EQUAL, num_clips+1, 0xFF); + glStencilFunc(GL_EQUAL, (GLint) (num_clips+1), 0xFF); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); #endif } else { - XSetRegion(wi->dpy, wi->gc, wi->current_clip->region); + TkSetRegion(wi->dpy, wi->gc, wi->current_clip->region); } } } void -ZnPopClip(WidgetInfo *wi, +ZnPopClip(ZnWInfo *wi, ZnBool set_gc) { int num_clips; @@ -2468,7 +2108,7 @@ ZnPopClip(WidgetInfo *wi, return; } - XDestroyRegion(wi->current_clip->region); + TkDestroyRegion(wi->current_clip->region); ZnListDelete(wi->clip_stack, ZnListTail); num_clips = ZnListSize(wi->clip_stack); @@ -2485,18 +2125,18 @@ ZnPopClip(WidgetInfo *wi, if (set_gc) { if (num_clips != 0) { if (wi->render) { -#ifdef GLX - glStencilFunc(GL_EQUAL, num_clips+1, 0xFF); +#ifdef GL + glStencilFunc(GL_EQUAL, (GLint) (num_clips+1), 0xFF); glStencilOp(GL_KEEP, GL_DECR, GL_DECR); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); #if 0 if (wi->current_clip->simple) { #endif glBegin(GL_QUADS); - glVertex2f(wi->current_clip->clip_box.orig.x, wi->current_clip->clip_box.orig.y); - glVertex2f(wi->current_clip->clip_box.orig.x, wi->current_clip->clip_box.corner.y); - glVertex2f(wi->current_clip->clip_box.corner.x, wi->current_clip->clip_box.corner.y); - glVertex2f(wi->current_clip->clip_box.corner.x, wi->current_clip->clip_box.orig.y); + glVertex2d(wi->current_clip->clip_box.orig.x, wi->current_clip->clip_box.orig.y); + glVertex2d(wi->current_clip->clip_box.orig.x, wi->current_clip->clip_box.corner.y); + glVertex2d(wi->current_clip->clip_box.corner.x, wi->current_clip->clip_box.corner.y); + glVertex2d(wi->current_clip->clip_box.corner.x, wi->current_clip->clip_box.orig.y); glEnd(); #if 0 } @@ -2504,18 +2144,18 @@ ZnPopClip(WidgetInfo *wi, } #endif glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - glStencilFunc(GL_EQUAL, num_clips, 0xFF); + glStencilFunc(GL_EQUAL, (GLint) num_clips, 0xFF); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); #endif } else { - XSetRegion(wi->dpy, wi->gc, wi->current_clip->region); + TkSetRegion(wi->dpy, wi->gc, wi->current_clip->region); } } else { /*printf("resetting clip mask\n");*/ if (wi->render) { -#ifdef GLX +#ifdef GL glClear(GL_STENCIL_BUFFER_BIT); glDisable(GL_STENCIL_TEST); #endif @@ -2537,7 +2177,7 @@ ZnPopClip(WidgetInfo *wi, ********************************************************************************** */ static void -Invalidate(Item item, +Invalidate(ZnItem item, int reason) { if (ISSET(item->inv_flags, ZN_TRANSFO_FLAG)) { @@ -2546,7 +2186,7 @@ Invalidate(Item item, if (ISSET(reason, ZN_COORDS_FLAG) || ISSET(reason, ZN_TRANSFO_FLAG)) { - Item parent = item->parent; + ZnItem parent = item->parent; while ((parent != NULL) && ISCLEAR(parent->inv_flags, ZN_COORDS_FLAG) && ISCLEAR(parent->inv_flags, ZN_TRANSFO_FLAG)) { @@ -2566,10 +2206,10 @@ Invalidate(Item item, ZnNeedRedisplay(item->wi); } else if (ISSET(reason, ZN_DRAW_FLAG)) { - if (ISSET(item->flags, VISIBLE_BIT)) { + if (ISSET(item->flags, ZN_VISIBLE_BIT)) { /*printf("invalidate graphics for item %d\n", item->id);*/ ZnDamage(item->wi, &item->item_bounding_box); -#ifdef GLX +#ifdef GL #ifdef GL_LIST /* * Remove the item display list so that it will be recreated @@ -2597,10 +2237,10 @@ Invalidate(Item item, ********************************************************************************** */ static void -InvalidateItems(Item group, - ItemClass item_class) +InvalidateItems(ZnItem group, + ZnItemClass item_class) { - Item item; + ZnItem item; if (group->class != ZnGroup) { return; @@ -2633,7 +2273,7 @@ InvalidateItems(Item group, ********************************************************************************** */ static void -ResetTransfo(Item item) +ResetTransfo(ZnItem item) { if (item->transfo) { ZnFree(item->transfo); @@ -2644,7 +2284,7 @@ ResetTransfo(Item item) static void -SetTransfo(Item item, +SetTransfo(ZnItem item, ZnTransfo *t) { if (item->transfo) { @@ -2661,7 +2301,7 @@ SetTransfo(Item item, static void -TranslateItem(Item item, +TranslateItem(ZnItem item, ZnReal dx, ZnReal dy) { @@ -2674,7 +2314,7 @@ TranslateItem(Item item, static void -ScaleItem(Item item, +ScaleItem(ZnItem item, ZnReal sx, ZnReal sy) { @@ -2687,7 +2327,7 @@ ScaleItem(Item item, static void -RotateItem(Item item, +RotateItem(ZnItem item, ZnReal angle, ZnPoint *p) { @@ -2714,10 +2354,10 @@ RotateItem(Item item, ********************************************************************************** */ static void -DestroyItem(Item item) +DestroyItem(ZnItem item) { - WidgetInfo *wi = item->wi; - TextInfo *ti = &wi->text_info; + ZnWInfo *wi = item->wi; + ZnTextInfo *ti = &wi->text_info; /* * Extract it from its group. @@ -2783,7 +2423,7 @@ DestroyItem(Item item) ********************************************************************************** */ -struct _ITEM ITEM = { +struct _ZnITEM ZnITEM = { CloneItem, DestroyItem, ConfigureItem, diff --git a/generic/Item.h b/generic/Item.h index b44604c..3c89560 100644 --- a/generic/Item.h +++ b/generic/Item.h @@ -38,99 +38,176 @@ #include "Field.h" #include +#include -#define DEFAULT_TRACK_PRIORITY 5 -#define DEFAULT_WAY_POINT_PRIORITY 4 -#define DEFAULT_TABULAR_PRIORITY 3 -#define DEFAULT_RECTANGLE_PRIORITY 2 -#define DEFAULT_CURVE_PRIORITY 2 -#define DEFAULT_BEZIER_PRIORITY 2 -#define DEFAULT_TRIANGLES_PRIORITY 2 -#define DEFAULT_ARC_PRIORITY 2 -#define DEFAULT_RETICLE_PRIORITY 2 -#define DEFAULT_MAP_PRIORITY 1 -#define DEFAULT_GROUP_PRIORITY 6 -#define DEFAULT_ICON_PRIORITY 2 -#define DEFAULT_TEXT_PRIORITY 2 -#define DEFAULT_WINDOW_PRIORITY 0 /* N/A */ -#define DEFAULT_MOSAIC_PRIORITY 0 - -#define DEFAULT_MARKER_SIZE 0 -#define DEFAULT_VISIBLE_HISTORY_SIZE 6 -#define DEFAULT_MANAGED_HISTORY_SIZE 6 -#define DEFAULT_SPEED_VECTOR_LENGTH 3 -#define DEFAULT_RETICLE_STEP_SIZE 80 -#define DEFAULT_RETICLE_PERIOD 5 -#define DEFAULT_LABEL_ANGLE 20 -#define DEFAULT_LABEL_DISTANCE 50 -#define DEFAULT_LINE_WIDTH 1 -#define DEFAULT_TILE_SIZE 1 -#define DEFAULT_ROW_COUNT 1 -#define DEFAULT_COLUMN_COUNT 1 - -#define DEFAULT_LABEL_PREFERRED_ANGLE 0 -#define DEFAULT_CONVERGENCE_STYLE 0 +/* + * Types and constants for attribute processing. + */ +typedef struct _ZnAttrConfig { + int type; + char *name; + Tk_Uid uid; + int offset; + int bool_bit; + int flags; + ZnBool read_only; +} ZnAttrConfig; + +/* + * When adding new type in the following enum + * do not forget to update attribute_type_strings + * in Item.c. + */ +#define ZN_CONFIG_END 0 +#define ZN_CONFIG_BOOL 1 +#define ZN_CONFIG_BITMAP 2 +#define ZN_CONFIG_BITMAP_LIST 3 +#define ZN_CONFIG_STRING 4 +#define ZN_CONFIG_FONT 5 +#define ZN_CONFIG_EDGE_LIST 6 +#define ZN_CONFIG_RELIEF 7 +#define ZN_CONFIG_DIM 8 +#define ZN_CONFIG_PRI 9 +#define ZN_CONFIG_ALIGNMENT 10 +#define ZN_CONFIG_AUTO_ALIGNMENT 11 +#define ZN_CONFIG_LINE_END 12 +#define ZN_CONFIG_LABEL_FORMAT 13 +#define ZN_CONFIG_LINE_STYLE 14 +#define ZN_CONFIG_LINE_SHAPE 15 +#define ZN_CONFIG_ITEM 16 +#define ZN_CONFIG_ANGLE 17 +#define ZN_CONFIG_INT 18 +#define ZN_CONFIG_UINT 19 +#define ZN_CONFIG_POINT 20 +#define ZN_CONFIG_ANCHOR 21 +#define ZN_CONFIG_TAG_LIST 22 +#define ZN_CONFIG_MAP_INFO 23 +#define ZN_CONFIG_IMAGE 24 +#define ZN_CONFIG_LEADER_ANCHORS 25 +#define ZN_CONFIG_JOIN_STYLE 26 +#define ZN_CONFIG_CAP_STYLE 27 +#define ZN_CONFIG_GRADIENT 28 +#define ZN_CONFIG_GRADIENT_LIST 29 +#define ZN_CONFIG_WINDOW 30 +#define ZN_CONFIG_ALPHA 31 +#define ZN_CONFIG_FILL_RULE 32 + +#define ZN_DRAW_FLAG 1 << 0 +#define ZN_COORDS_FLAG 1 << 1 +#define ZN_TRANSFO_FLAG 1 << 2 +#define ZN_REPICK_FLAG 1 << 3 +#define ZN_BORDER_FLAG 1 << 4 +#define ZN_CLFC_FLAG 1 << 5 /* Clear Label Format Cache. */ +#define ZN_IMAGE_FLAG 1 << 6 /* Update image pointer. */ +#define ZN_VIS_FLAG 1 << 7 /* Visibility has changed. */ +#define ZN_MOVED_FLAG 1 << 8 /* Item has moved. */ +#define ZN_ITEM_FLAG 1 << 9 /* Signal a change in an item type attribute. */ +#define ZN_MAP_INFO_FLAG 1 << 10 /* Update mapinfo pointer. */ +#define ZN_LAYOUT_FLAG 1 << 10 /* A layout need update. */ +#define ZN_POLAR_FLAG 1 << 11 /* Signal a cartesian to polar change. */ +#define ZN_CARTESIAN_FLAG 1 << 12 /* Signal a polar to cartesian change. */ +#define ZN_TILE_FLAG 1 << 13 /* Update tile pointer. */ +#define ZN_WINDOW_FLAG 1 << 14 /* Signal a change in a window type attribute. */ + + +/* + * This constant marks a non existant item +*/ +#define ZN_NO_ITEM NULL + +/* + * Constants for item parts. The item indexable parts (named fields) are coded + * as positive or null integers. The item specific parts (not indexable) are + * coded as negatives beginning at -2 up to -9 which is the current limit. The + * -1 value is reserved to indicate no part. + */ +#define ZnPartToBit(part) (1 << (ABS(part)-2)) +#define ZN_NO_PART -1 + +/* + * Some flags macros. + */ +#define ISSET(var, mask) ((var) & (mask)) +#define ISCLEAR(var, mask) (((var) & (mask)) == 0) +#define SET(var,mask) ((var) |= (mask)) +#define CLEAR(var, mask) ((var) &= ~(mask)) +#define ASSIGN(var, mask, bool) ((bool) ? SET((var), (mask)) : CLEAR((var), (mask))) /* * Item flags values. */ -#define VISIBLE_BIT 1 -#define SENSITIVE_BIT 2 -#define ATOMIC_BIT 4 -#define UPDATE_DEPENDENT_BIT 16 -#define COMPOSE_SCALE_BIT 32 -#define COMPOSE_ROTATION_BIT 64 -#define COMPOSE_ALPHA_BIT 128 +#define ZN_VISIBLE_BIT (1<<0) +#define ZN_SENSITIVE_BIT (1<<1) +#define ZN_UPDATE_DEPENDENT_BIT (1<<2) +#define ZN_COMPOSE_SCALE_BIT (1<<3) +#define ZN_COMPOSE_ROTATION_BIT (1<<4) +#define ZN_COMPOSE_ALPHA_BIT (1<<5) +/* + * Must be kept one greater than the last flag shift count. + */ +#define ZN_PRIVATE_FLAGS_OFFSET 6 -struct _WidgetInfo; +/* + * Operator constants for the coord method. + */ +#define ZN_COORDS_READ 0 +#define ZN_COORDS_READ_ALL 1 +#define ZN_COORDS_REPLACE 2 +#define ZN_COORDS_REPLACE_ALL 3 +#define ZN_COORDS_ADD 4 +#define ZN_COORDS_ADD_LAST 5 +#define ZN_COORDS_REMOVE 6 + + +struct _ZnWInfo; struct _ZnTransfo; /* * Item record header -- */ -typedef struct _ItemStruct { +typedef struct _ZnItemStruct { /* Private data */ - int id; + long id; ZnList tags; - struct _WidgetInfo *wi; /* The widget this item is on */ - struct _ItemClassStruct *class; /* item class */ - struct _ItemStruct *previous; /* previous item in group list */ - struct _ItemStruct *next; /* next item in group list */ + struct _ZnWInfo *wi; /* The widget this item is on */ + struct _ZnItemClassStruct *class; /* item class */ + struct _ZnItemStruct *previous; /* previous item in group list */ + struct _ZnItemStruct *next; /* next item in group list */ ZnBBox item_bounding_box; /* device item bounding box */ /* Common attributes */ unsigned short flags; unsigned short part_sensitive; /* Currently limited to 16 parts per item */ short inv_flags; - struct _ItemStruct *parent; + struct _ZnItemStruct *parent; int priority; struct _ZnTransfo *transfo; - struct _ItemStruct *connected_item; /* Item this item is connected to */ -#ifdef GLX + struct _ZnItemStruct *connected_item; /* Item this item is connected to */ +#ifdef GL #ifdef GL_LIST GLuint gl_list; /* Display list storing the item graphics */ #endif #endif -} ItemStruct, *Item; +} ZnItemStruct, *ZnItem; -typedef struct _ToAreaStruct { +typedef struct _ZnToAreaStruct { Tk_Uid tag_uid; ZnBool enclosed; - Item in_group; + ZnItem in_group; ZnBool report; ZnBool recursive; ZnBBox *area; } ZnToAreaStruct, *ZnToArea; -typedef struct _PickStruct { +typedef struct _ZnPickStruct { int aperture; - Item in_group; - Item start_item; + ZnItem in_group; + ZnItem start_item; ZnBool recursive; ZnPoint *point; - Item a_item; + ZnItem a_item; int a_part; } ZnPickStruct, *ZnPick; @@ -138,72 +215,75 @@ typedef struct _PickStruct { /* * Item class record -- */ -typedef int (*ItemInitMethod)(Item item, int *argc, Tcl_Obj *CONST *args[]); -typedef int (*ItemConfigureMethod)(Item item, int argc, Tcl_Obj *CONST args[], - int *flags); -typedef int (*ItemQueryMethod)(Item item, int argc, Tcl_Obj *CONST args[]); -typedef void (*ItemCloneMethod)(Item item); -typedef void (*ItemDestroyMethod)(Item item); -typedef void (*ItemDrawMethod)(Item item); -typedef void (*ItemRenderMethod)(Item item); -typedef void (*ItemComputeCoordinatesMethod)(Item item, ZnBool force); -typedef int (*ItemToAreaMethod)(Item item, ZnToArea ta); -typedef double (*ItemPickMethod)(Item item, ZnPick ps); -typedef ZnBool (*ItemIsSensitiveMethod)(Item item, int part); -typedef struct _FieldSetStruct* (*ItemGetFieldSetMethod)(Item item); -typedef int (*ItemContourMethod)(Item item, int cmd, int index, ZnPoly *poly); -typedef void (*ItemPickVertexMethod)(Item item, ZnPoint *p, int *contour, - int *vertex, int *o_vertex); -typedef void (*ItemGetAnchorMethod)(Item item, ZnAnchor anchor, ZnPoint *p); -typedef ZnBool (*ItemGetClipVerticesMethod)(Item item, ZnTriStrip *tristrip); -typedef ZnBool (*ItemGetContoursMethod)(Item item, ZnPoly *poly); -typedef int (*ItemCoordsMethod)(Item item, int contour, int index, int cmd, - ZnPoint **points, char **controls, int *num_points); -typedef void (*ItemInsertCharsMethod)(Item item, int field, int *index, - char *chars); -typedef void (*ItemDeleteCharsMethod)(Item item, int field, int *first, - int *last); -typedef void (*ItemCursorMethod)(Item item, int field, int index); -typedef int (*ItemIndexMethod)(Item item, int field, Tcl_Obj *index_spec, - int *index); -typedef int (*ItemPartMethod)(Item item, Tcl_Obj **part_spec, int *part); -typedef int (*ItemSelectionMethod)(Item item, int field, int offset, - char *chars, int max_chars); -typedef void (*ItemPostScriptMethod)(Item item, PostScriptInfo ps_info); - -typedef struct _ItemClassStruct { - int size; - int num_parts; /* 0 if no special parts, else +typedef int (*ZnItemInitMethod)(ZnItem item, int *argc, Tcl_Obj *CONST *args[]); +typedef int (*ZnItemConfigureMethod)(ZnItem item, int argc, Tcl_Obj *CONST args[], + int *flags); +typedef int (*ZnItemQueryMethod)(ZnItem item, int argc, Tcl_Obj *CONST args[]); +typedef void (*ZnItemCloneMethod)(ZnItem item); +typedef void (*ZnItemDestroyMethod)(ZnItem item); +typedef void (*ZnItemDrawMethod)(ZnItem item); +typedef void (*ZnItemRenderMethod)(ZnItem item); +typedef void (*ZnItemComputeCoordinatesMethod)(ZnItem item, ZnBool force); +typedef int (*ZnItemToAreaMethod)(ZnItem item, ZnToArea ta); +typedef ZnReal (*ZnItemPickMethod)(ZnItem item, ZnPick ps); +typedef ZnBool (*ZnItemIsSensitiveMethod)(ZnItem item, int part); +typedef struct _ZnFieldSetStruct* (*ZnItemGetFieldSetMethod)(ZnItem item); +typedef int (*ZnItemContourMethod)(ZnItem item, int cmd, int index, ZnPoly *poly); +typedef void (*ZnItemPickVertexMethod)(ZnItem item, ZnPoint *p, int *contour, + int *vertex, int *o_vertex); +typedef void (*ZnItemGetAnchorMethod)(ZnItem item, Tk_Anchor anchor, ZnPoint *p); +typedef ZnBool (*ZnItemGetClipVerticesMethod)(ZnItem item, ZnTriStrip *tristrip); +typedef ZnBool (*ZnItemGetContoursMethod)(ZnItem item, ZnPoly *poly); +typedef int (*ZnItemCoordsMethod)(ZnItem item, int contour, int index, int cmd, + ZnPoint **points, char **controls, unsigned int *num_points); +typedef void (*ZnItemInsertCharsMethod)(ZnItem item, int field, int *index, + char *chars); +typedef void (*ZnItemDeleteCharsMethod)(ZnItem item, int field, int *first, + int *last); +typedef void (*ZnItemCursorMethod)(ZnItem item, int field, int index); +typedef int (*ZnItemIndexMethod)(ZnItem item, int field, Tcl_Obj *index_spec, + int *index); +typedef int (*ZnItemPartMethod)(ZnItem item, Tcl_Obj **part_spec, int *part); +typedef int (*ZnItemSelectionMethod)(ZnItem item, int field, int offset, + char *chars, int max_chars); +typedef void (*ZnItemPostScriptMethod)(ZnItem item, ZnPostScriptInfo ps_info); + + +typedef void *ZnItemClassId; + +typedef struct _ZnItemClassStruct { + unsigned int size; + unsigned int num_parts; /* 0 if no special parts, else * gives how many parts exist. */ ZnBool has_anchors; /* 1 if anchors are supported */ char *name; ZnAttrConfig *attr_desc; - ItemInitMethod Init; - ItemCloneMethod Clone; - ItemDestroyMethod Destroy; - ItemConfigureMethod Configure; - ItemQueryMethod Query; - ItemGetFieldSetMethod GetFieldSet; - ItemGetAnchorMethod GetAnchor; - ItemGetClipVerticesMethod GetClipVertices; - ItemGetContoursMethod GetContours; - ItemCoordsMethod Coords; - ItemInsertCharsMethod InsertChars; - ItemDeleteCharsMethod DeleteChars; - ItemCursorMethod Cursor; - ItemIndexMethod Index; - ItemPartMethod Part; - ItemSelectionMethod Selection; - ItemContourMethod Contour; - ItemComputeCoordinatesMethod ComputeCoordinates; - ItemToAreaMethod ToArea; - ItemDrawMethod Draw; - ItemRenderMethod Render; - ItemIsSensitiveMethod IsSensitive; - ItemPickMethod Pick; - ItemPickVertexMethod PickVertex; - ItemPostScriptMethod PostScript; -} ItemClassStruct, *ItemClass; + ZnItemInitMethod Init; + ZnItemCloneMethod Clone; + ZnItemDestroyMethod Destroy; + ZnItemConfigureMethod Configure; + ZnItemQueryMethod Query; + ZnItemGetFieldSetMethod GetFieldSet; + ZnItemGetAnchorMethod GetAnchor; + ZnItemGetClipVerticesMethod GetClipVertices; + ZnItemGetContoursMethod GetContours; + ZnItemCoordsMethod Coords; + ZnItemInsertCharsMethod InsertChars; + ZnItemDeleteCharsMethod DeleteChars; + ZnItemCursorMethod Cursor; + ZnItemIndexMethod Index; + ZnItemPartMethod Part; + ZnItemSelectionMethod Selection; + ZnItemContourMethod Contour; + ZnItemComputeCoordinatesMethod ComputeCoordinates; + ZnItemToAreaMethod ToArea; + ZnItemDrawMethod Draw; + ZnItemRenderMethod Render; + ZnItemIsSensitiveMethod IsSensitive; + ZnItemPickMethod Pick; + ZnItemPickVertexMethod PickVertex; + ZnItemPostScriptMethod PostScript; +} ZnItemClassStruct, *ZnItemClass; /* @@ -213,73 +293,72 @@ typedef struct _ItemClassStruct { * ********************************************************************************** */ -extern struct _ITEM { - Item (*CloneItem)(Item model); - void (*DestroyItem)(Item item); - int (*ConfigureItem)(Item item, int field, int argc, Tcl_Obj *CONST args[], +extern struct _ZnITEM { + ZnItem (*CloneItem)(ZnItem model); + void (*DestroyItem)(ZnItem item); + int (*ConfigureItem)(ZnItem item, int field, int argc, Tcl_Obj *CONST args[], ZnBool init); - int (*QueryItem)(Item item, int field, int argc, Tcl_Obj *CONST args[]); - void (*InsertItem)(Item item, Item group, Item mark_item, ZnBool before); - void (*UpdateItemPriority)(Item item, Item mark_item, ZnBool before); - void (*UpdateItemDependency)(Item item, Item old_connection); - void (*ExtractItem)(Item item); - void (*SetId)(Item item); - void (*FreeId)(Item item); - void (*AddTag)(Item item, Tk_Uid tag); - void (*RemoveTag)(Item item, Tk_Uid tag); - void (*FreeTags)(Item item); - ZnBool (*HasTag)(Item item, Tk_Uid tag); - void (*ResetTransfo)(Item item); - void (*SetTransfo)(Item item, struct _ZnTransfo *t); - void (*TranslateItem)(Item item, ZnReal tx, ZnReal ty); - void (*ScaleItem)(Item item, ZnReal sx, ZnReal sy); - void (*RotateItem)(Item item, ZnReal angle, ZnPoint *p); - void (*Invalidate)(Item item, int reason); - void (*InvalidateItems)(Item group, ItemClass item_class); - void (*GetItemTransform)(Item item, struct _ZnTransfo *t); -} ITEM; + int (*QueryItem)(ZnItem item, int field, int argc, Tcl_Obj *CONST args[]); + void (*InsertItem)(ZnItem item, ZnItem group, ZnItem mark_item, ZnBool before); + void (*UpdateItemPriority)(ZnItem item, ZnItem mark_item, ZnBool before); + void (*UpdateItemDependency)(ZnItem item, ZnItem old_connection); + void (*ExtractItem)(ZnItem item); + void (*SetId)(ZnItem item); + void (*FreeId)(ZnItem item); + void (*AddTag)(ZnItem item, Tk_Uid tag); + void (*RemoveTag)(ZnItem item, Tk_Uid tag); + void (*FreeTags)(ZnItem item); + ZnBool (*HasTag)(ZnItem item, Tk_Uid tag); + void (*ResetTransfo)(ZnItem item); + void (*SetTransfo)(ZnItem item, struct _ZnTransfo *t); + void (*TranslateItem)(ZnItem item, ZnReal tx, ZnReal ty); + void (*ScaleItem)(ZnItem item, ZnReal sx, ZnReal sy); + void (*RotateItem)(ZnItem item, ZnReal angle, ZnPoint *p); + void (*Invalidate)(ZnItem item, int reason); + void (*InvalidateItems)(ZnItem group, ZnItemClass item_class); + void (*GetItemTransform)(ZnItem item, struct _ZnTransfo *t); +} ZnITEM; /* ********************************************************************************** * - * Methods defined in item.c useful for writing items. + * Methods defined in Item.c useful for writing items. * ********************************************************************************** */ void ZnItemInit(); -Item ZnCreateItem(struct _WidgetInfo *wi, ItemClass item_class, +ZnItem ZnCreateItem(struct _ZnWInfo *wi, ZnItemClass item_class, int *argc, Tcl_Obj *CONST *args[]); -void ZnAddItemClass(ItemClass class); -ItemClass ZnLookupItemClass(char *class_name); +void ZnAddItemClass(ZnItemClass class); +ZnItemClass ZnLookupItemClass(char *class_name); ZnList ZnItemClassList(); -int ZnConfigureAttributes(struct _WidgetInfo *wi, void *record, +int ZnConfigureAttributes(struct _ZnWInfo *wi, void *record, ZnAttrConfig *attr_desc, int argc, Tcl_Obj *CONST args[], int *flags); -int ZnAttributesInfo(struct _WidgetInfo *wi, void *record, +int ZnAttributesInfo(struct _ZnWInfo *wi, void *record, ZnAttrConfig *attr_desc, int argc, Tcl_Obj *CONST args[]); -int ZnQueryAttribute(struct _WidgetInfo *wi, void *record, ZnAttrConfig *attr_desc, +int ZnQueryAttribute(struct _ZnWInfo *wi, void *record, ZnAttrConfig *attr_desc, Tcl_Obj *attr_name); -void ZnInitTransformStack(struct _WidgetInfo *wi); -void ZnFreeTransformStack(struct _WidgetInfo *wi); -void ZnResetTransformStack(struct _WidgetInfo *wi); -void ZnPushTransform(struct _WidgetInfo *wi, struct _ZnTransfo *transfo, +void ZnInitTransformStack(struct _ZnWInfo *wi); +void ZnFreeTransformStack(struct _ZnWInfo *wi); +void ZnResetTransformStack(struct _ZnWInfo *wi); +void ZnPushTransform(struct _ZnWInfo *wi, struct _ZnTransfo *transfo, ZnBool compose_scale, ZnBool compose_rot); -void ZnPopTransform(struct _WidgetInfo *wi); -void ZnInitClipStack(struct _WidgetInfo *wi); -void ZnFreeClipStack(struct _WidgetInfo *wi); -void ZnResetClipStack(struct _WidgetInfo *wi); -void ZnPushClip(struct _WidgetInfo *wi, ZnTriStrip *tristrip, ZnBool simple, +void ZnPopTransform(struct _ZnWInfo *wi); +void ZnInitClipStack(struct _ZnWInfo *wi); +void ZnFreeClipStack(struct _ZnWInfo *wi); +void ZnResetClipStack(struct _ZnWInfo *wi); +void ZnPushClip(struct _ZnWInfo *wi, ZnTriStrip *tristrip, ZnBool simple, ZnBool set_gc); -void ZnPopClip(struct _WidgetInfo *wi, ZnBool set_gc); -ZnBool ZnCurrentClip(struct _WidgetInfo *wi, Region *reg, ZnBBox **clip_box, +void ZnPopClip(struct _ZnWInfo *wi, ZnBool set_gc); +ZnBool ZnCurrentClip(struct _ZnWInfo *wi, TkRegion *reg, ZnBBox **clip_box, ZnBool *simple); extern ZnItemClassId ZnArc; extern ZnItemClassId ZnMap; extern ZnItemClassId ZnTabular; -extern ZnItemClassId ZnMosaic; extern ZnItemClassId ZnCurve; extern ZnItemClassId ZnBezier; extern ZnItemClassId ZnTriangles; @@ -290,7 +369,7 @@ extern ZnItemClassId ZnWayPoint; extern ZnItemClassId ZnGroup; extern ZnItemClassId ZnIcon; extern ZnItemClassId ZnText; -extern ZnItemClassId ZnWind; +extern ZnItemClassId ZnWindow; #endif /* _Item_h */ diff --git a/generic/List.c b/generic/List.c index 8695df0..3d0e9db 100644 --- a/generic/List.c +++ b/generic/List.c @@ -66,7 +66,6 @@ #include "Types.h" #include "List.h" -#include "config.h" #include #include @@ -98,10 +97,10 @@ static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ " */ typedef struct { - char *list; - long elem_size; - long alloc_size; - long used_size; + char *list; + unsigned long elem_size; + unsigned long alloc_size; + unsigned long used_size; } _ZnList; @@ -116,8 +115,8 @@ typedef struct { */ static void -GrowIfNeeded(_ZnList *list, - int min_size) +GrowIfNeeded(_ZnList *list, + unsigned int min_size) { if (list->used_size+min_size <= list->alloc_size) { return; @@ -127,7 +126,7 @@ GrowIfNeeded(_ZnList *list, if (list->list == NULL) { /* Normal case if we have created a zero sized list */ list->alloc_size = min_size; - list->list = (char *) ZnMalloc(list->alloc_size*list->elem_size); + list->list = ZnMalloc(list->alloc_size*list->elem_size); } else { /* Case of a list made by ZnListFromArray. If we try to make @@ -135,7 +134,7 @@ GrowIfNeeded(_ZnList *list, char *new_list; list->alloc_size = list->used_size+min_size; - new_list = (char *) ZnMalloc(list->alloc_size*list->elem_size); + new_list = ZnMalloc(list->alloc_size*list->elem_size); memcpy(new_list, list->list, list->used_size*list->elem_size); @@ -146,8 +145,8 @@ GrowIfNeeded(_ZnList *list, list->alloc_size = MAX(MIN(list->alloc_size*2, MAX_CHUNCK_SIZE), list->alloc_size+min_size); - list->list = (char *) ZnRealloc(list->list, - list->alloc_size*list->elem_size); + list->list = ZnRealloc(list->list, + list->alloc_size*list->elem_size); } memset(list->list+(list->used_size*list->elem_size), @@ -166,27 +165,23 @@ GrowIfNeeded(_ZnList *list, */ ZnList -ZnListNew(int initial_size, - int element_size) +ZnListNew(unsigned int initial_size, + unsigned int element_size) { _ZnList *new_list; - if (initial_size < 0) { - initial_size = 0; - } - - if (element_size <= 0) { + if (element_size == 0) { element_size = 1; } - new_list = (_ZnList *) ZnMalloc(sizeof(_ZnList)); + new_list = ZnMalloc(sizeof(_ZnList)); new_list->alloc_size = initial_size; new_list->used_size = 0; new_list->elem_size = element_size; if (initial_size) { - long size = new_list->alloc_size*new_list->elem_size; + unsigned long size = new_list->alloc_size*new_list->elem_size; new_list->list = ZnMalloc(size); memset(new_list->list, 0, size); @@ -214,7 +209,7 @@ ZnListDuplicate(ZnList list) _ZnList *cur_list = (_ZnList *) list; _ZnList *new_list; - new_list = (_ZnList *) ZnMalloc(sizeof(_ZnList)); + new_list = ZnMalloc(sizeof(_ZnList)); new_list->alloc_size = cur_list->alloc_size == 0 ? cur_list->used_size : cur_list->alloc_size; @@ -222,8 +217,8 @@ ZnListDuplicate(ZnList list) new_list->elem_size = cur_list->elem_size; if (new_list->alloc_size) { - long used_size = new_list->used_size*new_list->elem_size; - long size = new_list->alloc_size*new_list->elem_size; + unsigned long used_size = new_list->used_size*new_list->elem_size; + unsigned long size = new_list->alloc_size*new_list->elem_size; new_list->list = ZnMalloc(size); @@ -269,9 +264,9 @@ ZnListEmpty(ZnList list) */ ZnList -ZnListFromArray(void *array, - int array_size, - int element_size) +ZnListFromArray(void *array, + unsigned int array_size, + unsigned int element_size) { _ZnList *new_list; @@ -333,7 +328,7 @@ ZnListFree(ZnList list) ********************************************************************************** */ -int +unsigned int ZnListSize(ZnList list) { return ((_ZnList *)list)->used_size; @@ -350,8 +345,8 @@ ZnListSize(ZnList list) */ void -ZnListAssertSize(ZnList list, - int size) +ZnListAssertSize(ZnList list, + unsigned int size) { _ZnList *cur_list = (_ZnList *) list; @@ -437,19 +432,15 @@ ZnListAppend(ZnList to, void ZnListAdd(ZnList list, void *value, - int index) + unsigned int index) { - _ZnList *cur_list = (_ZnList *) list; - int i; + _ZnList *cur_list = (_ZnList *) list; + int i; GrowIfNeeded(cur_list, 1); - if (index < 0) { - index = 0; - } - if (index < cur_list->used_size) { - for (i = cur_list->used_size-1; i >= index; i--) { + for (i = cur_list->used_size-1; i >= (int) index; i--) { memcpy(cur_list->list+((i+1)*cur_list->elem_size), cur_list->list+(i*cur_list->elem_size), cur_list->elem_size); @@ -479,8 +470,8 @@ ZnListAdd(ZnList list, */ void * -ZnListAt(ZnList list, - int index) +ZnListAt(ZnList list, + unsigned int index) { if (!((_ZnList *) list)->used_size) { return NULL; @@ -488,11 +479,8 @@ ZnListAt(ZnList list, if (index >= ((_ZnList *) list)->used_size) { index = ((_ZnList *) list)->used_size - 1; } - if (index < 0) { - index = 0; - } - return (void *) ((_ZnList *) list)->list+(index*((_ZnList *) list)->elem_size); + return (void *) (((_ZnList *) list)->list+(index*((_ZnList *) list)->elem_size)); } @@ -508,9 +496,9 @@ ZnListAt(ZnList list, */ void -ZnListAtPut(ZnList list, - void *value, - int index) +ZnListAtPut(ZnList list, + void *value, + unsigned int index) { if (!((_ZnList *) list)->used_size) { return; @@ -518,9 +506,6 @@ ZnListAtPut(ZnList list, if (index >= ((_ZnList *) list)->used_size) { index = ((_ZnList *) list)->used_size - 1; } - if (index < 0) { - index = 0; - } memcpy(((_ZnList *) list)->list+(index*((_ZnList *) list)->elem_size), (char *) value, @@ -539,11 +524,11 @@ ZnListAtPut(ZnList list, */ void -ZnListDelete(ZnList list, - int index) +ZnListDelete(ZnList list, + unsigned int index) { _ZnList *cur_list = (_ZnList *) list; - int i; + unsigned int i; if (!((_ZnList *) list)->used_size) { return; @@ -551,9 +536,6 @@ ZnListDelete(ZnList list, if (index >= ((_ZnList *) list)->used_size) { index = ((_ZnList *) list)->used_size - 1; } - if (index < 0) { - index = 0; - } for (i = index; i < cur_list->used_size-1; i++) { memcpy(cur_list->list+(i*cur_list->elem_size), @@ -573,20 +555,14 @@ ZnListDelete(ZnList list, */ void -ZnListTruncate(ZnList list, - int index) +ZnListTruncate(ZnList list, + unsigned int index) { _ZnList *cur_list = (_ZnList *) list; - if (!((_ZnList *) list)->used_size) { - return; - } if (index >= ((_ZnList *) list)->used_size) { return; } - if (index < 0) { - index = 0; - } cur_list->used_size = index; } diff --git a/generic/List.h b/generic/List.h index f63f0e0..49aed9b 100644 --- a/generic/List.h +++ b/generic/List.h @@ -43,34 +43,34 @@ extern "C" { typedef void *ZnList; -ZnList ZnListNew(int /* initial_size */, - int /* element_size */); +ZnList ZnListNew(unsigned int /* initial_size */, + unsigned int /* element_size */); ZnList ZnListDuplicate(ZnList /* list */); void ZnListEmpty(ZnList /* list */); -ZnList ZnListFromArray(void */* array */, - int /* array_size */, - int /* element_size */); +ZnList ZnListFromArray(void * /* array */, + unsigned int /* array_size */, + unsigned int /* element_size */); void *ZnListArray(ZnList /* list */); void ZnListFree(ZnList /* list */); -int ZnListSize(ZnList /* list */); +unsigned int ZnListSize(ZnList /* list */); void ZnListAssertSize(ZnList /* list */, - int /* size */); + unsigned int /* size */); void ZnListCopy(ZnList /* to */, ZnList /* from */); void ZnListAppend(ZnList /* to */, ZnList /* from */); void ZnListAdd(ZnList /* list */, - void */* value */, - int /* index */); + void * /* value */, + unsigned int /* index */); void *ZnListAt(ZnList /* list */, - int /* index */); -void ZnListAtPut(ZnList /* list */, - void */* value */, - int /* index */); -void ZnListDelete(ZnList /* list */, - int /* index */); -void ZnListTruncate(ZnList /* list */, - int /* index */); + unsigned int /* index */); +void ZnListAtPut(ZnList /* list */, + void * /* value */, + unsigned int /* index */); +void ZnListDelete(ZnList /* list */, + unsigned int /* index */); +void ZnListTruncate(ZnList /* list */, + unsigned int /* index */); #ifdef __CPLUSPLUS__ } diff --git a/generic/Map.c b/generic/Map.c index 4d6244f..be00b17 100644 --- a/generic/Map.c +++ b/generic/Map.c @@ -37,7 +37,6 @@ #include "Image.h" #include -#include #include @@ -54,18 +53,18 @@ static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ " */ typedef struct _MapItemStruct { - ItemStruct header; + ZnItemStruct header; /* Public data */ ZnBool filled; ZnImage fill_pattern; ZnGradient *color; - ZnFont text_font; /* null value -> use zn_map_text_font */ + Tk_Font text_font; /* null value -> use zn_map_text_font */ char *map_info_name; ZnList symbol_patterns; /* Private data */ - MapInfoId map_info; + ZnMapInfoId map_info; ZnList vectors; ZnList dashed_vectors; ZnList dotted_vectors; @@ -77,7 +76,7 @@ typedef struct _MapItemStruct { ZnList marks; ZnList symbols; ZnList texts; -#ifdef GLX +#ifdef GL ZnTexFontInfo *tfi; #endif } MapItemStruct, *MapItem; @@ -87,13 +86,13 @@ static ZnAttrConfig map_attrs[] = { { ZN_CONFIG_GRADIENT, "-color", NULL, Tk_Offset(MapItemStruct, color), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-composealpha", NULL, - Tk_Offset(MapItemStruct, header.flags), COMPOSE_ALPHA_BIT, + Tk_Offset(MapItemStruct, header.flags), ZN_COMPOSE_ALPHA_BIT, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-composerotation", NULL, - Tk_Offset(MapItemStruct, header.flags), COMPOSE_ROTATION_BIT, + Tk_Offset(MapItemStruct, header.flags), ZN_COMPOSE_ROTATION_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_BOOL, "-composescale", NULL, - Tk_Offset(MapItemStruct, header.flags), COMPOSE_SCALE_BIT, + Tk_Offset(MapItemStruct, header.flags), ZN_COMPOSE_SCALE_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_BOOL, "-filled", NULL, Tk_Offset(MapItemStruct, filled), 1, ZN_COORDS_FLAG, False }, @@ -108,28 +107,28 @@ static ZnAttrConfig map_attrs[] = { Tk_Offset(MapItemStruct, header.priority), 0, ZN_DRAW_FLAG|ZN_REPICK_FLAG, False }, { ZN_CONFIG_BOOL, "-sensitive", NULL, - Tk_Offset(MapItemStruct, header.flags), SENSITIVE_BIT, ZN_REPICK_FLAG, False }, + Tk_Offset(MapItemStruct, header.flags), ZN_SENSITIVE_BIT, ZN_REPICK_FLAG, False }, { ZN_CONFIG_BITMAP_LIST, "-symbols", NULL, Tk_Offset(MapItemStruct, symbol_patterns), 0, ZN_COORDS_FLAG, False }, { ZN_CONFIG_TAG_LIST, "-tags", NULL, Tk_Offset(MapItemStruct, header.tags), 0, 0, False }, { ZN_CONFIG_BOOL, "-visible", NULL, - Tk_Offset(MapItemStruct, header.flags), VISIBLE_BIT, + Tk_Offset(MapItemStruct, 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 } }; void UpdateMapInfo(ClientData client_data, - MapInfoId map_info) + ZnMapInfoId map_info __unused) { - Item item = (Item) client_data; + ZnItem item = (ZnItem) client_data; /*printf("updating a map 'cause of a change in mapinfo\n");*/ - ITEM.Invalidate(item, ZN_COORDS_FLAG); + ZnITEM.Invalidate(item, ZN_COORDS_FLAG); } @@ -195,27 +194,27 @@ FreeLists(MapItem map) ********************************************************************************** */ static int -Init(Item item, - int *argc, - Tcl_Obj *CONST *args[]) +Init(ZnItem item, + int *argc __unused, + Tcl_Obj *CONST *args[] __unused) { MapItem map = (MapItem) item; - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; - SET(item->flags, VISIBLE_BIT); - CLEAR(item->flags, SENSITIVE_BIT); - SET(item->flags, COMPOSE_ALPHA_BIT); - SET(item->flags, COMPOSE_ROTATION_BIT); - SET(item->flags, COMPOSE_SCALE_BIT); + SET(item->flags, ZN_VISIBLE_BIT); + CLEAR(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->part_sensitive = 0; - item->priority = DEFAULT_MAP_PRIORITY; + item->priority = 0; map->filled = False; map->fill_pattern = ZnUnspecifiedImage; map->symbol_patterns = NULL; map->color = ZnGetGradientByValue(wi->fore_color); map->text_font = Tk_GetFont(wi->interp, wi->win, Tk_NameOfFont(wi->map_text_font)); -#ifdef GLX +#ifdef GL map->tfi = ZnGetTexFont(wi, map->text_font); #endif @@ -234,7 +233,7 @@ Init(Item item, map->symbols = NULL; map->texts = NULL; - return ZN_OK; + return TCL_OK; } @@ -247,10 +246,10 @@ Init(Item item, */ static void -Clone(Item item) +Clone(ZnItem item) { MapItem map = (MapItem) item; - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; if (map->vectors) { map->vectors = ZnListDuplicate(map->vectors); @@ -301,7 +300,7 @@ Clone(Item item) map->color = ZnGetGradientByValue(map->color); map->text_font = Tk_GetFont(wi->interp, wi->win, Tk_NameOfFont(map->text_font)); -#ifdef GLX +#ifdef GL map->tfi = ZnGetTexFont(wi, map->text_font); #endif if (map->fill_pattern != ZnUnspecifiedImage) { @@ -309,7 +308,7 @@ Clone(Item item) } if (map->symbol_patterns) { ZnImage *pats, *new_pats; - int i, num_pats; + unsigned int i, num_pats; pats = ZnListArray(map->symbol_patterns); num_pats = ZnListSize(map->symbol_patterns); @@ -331,14 +330,14 @@ Clone(Item item) ********************************************************************************** */ static void -Destroy(Item item) +Destroy(ZnItem item) { MapItem map = (MapItem) item; FreeLists(map); ZnFreeGradient(map->color); Tk_FreeFont(map->text_font); -#ifdef GLX +#ifdef GL if (map->tfi) { ZnFreeTexFont(map->tfi); } @@ -375,34 +374,34 @@ Destroy(Item item) ********************************************************************************** */ static int -Configure(Item item, +Configure(ZnItem item, int argc, Tcl_Obj *CONST argv[], int *flags) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; MapItem map = (MapItem) item; -#ifdef GLX - ZnFont old_font = map->text_font; +#ifdef GL + Tk_Font old_font = map->text_font; #endif - if (ZnConfigureAttributes(wi, item, map_attrs, argc, argv, flags) == ZN_ERROR) { - return ZN_ERROR; + if (ZnConfigureAttributes(wi, item, map_attrs, argc, argv, flags) == TCL_ERROR) { + return TCL_ERROR; } -#ifdef GLX +#ifdef GL if (old_font != map->text_font) { if (map->tfi) { ZnFreeTexFont(map->tfi); } map->tfi = ZnGetTexFont(wi, map->text_font); if (!map->tfi) { - return ZN_ERROR; + return TCL_ERROR; } } #endif if (ISSET(*flags, ZN_MAP_INFO_FLAG)) { - MapInfoId map_info; + ZnMapInfoId map_info; ZnBool error = False; if (map->map_info_name) { @@ -422,11 +421,11 @@ Configure(Item item, map->map_info = map_info; } else { - return ZN_ERROR; + return TCL_ERROR; } } - return ZN_OK; + return TCL_OK; } @@ -438,15 +437,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, map_attrs, argv[0]) == ZN_ERROR) { - return ZN_ERROR; + if (ZnQueryAttribute(item->wi, item, map_attrs, argv[0]) == TCL_ERROR) { + return TCL_ERROR; } - return ZN_OK; + return TCL_OK; } @@ -459,15 +458,15 @@ Query(Item item, */ static void -ComputeCoordinates(Item item, - ZnBool force) +ComputeCoordinates(ZnItem item, + ZnBool force __unused) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; MapItem map = (MapItem) item; - MapInfoId map_info; - MapInfoLineStyle line_style; + ZnMapInfoId map_info; + ZnMapInfoLineStyle line_style; int line_width; - MapInfoTextStyle text_style; + ZnMapInfoTextStyle text_style; char symbol; char *text; unsigned int i, j, cnt; @@ -490,13 +489,13 @@ ComputeCoordinates(Item item, ZnBBox bbox, bbox_inter, zn_bbox; int x_from_w, y_from_w, x_to_w, y_to_w; int radius, start_angle, extend; - unsigned int radius_w; - MapInfoPoint new_marks; + int radius_w; + ZnMapInfoPoint new_marks; unsigned int n_new_marks; - ZnFont text_font; + Tk_Font text_font; int sym_w2=0, sym_h2=0; - ResetBBox(&item->item_bounding_box); + ZnResetBBox(&item->item_bounding_box); if (map->map_info == NULL) { return; @@ -530,67 +529,67 @@ ComputeCoordinates(Item item, * First discover how many component of each kind * there is in the MapInfo. */ - cnt = MapInfoNumLines(map_info); + cnt = ZnMapInfoNumLines(map_info); for (i = 0; i < cnt; i++) { - MapInfoGetLine(map_info, i, NULL, &line_style, NULL, NULL, NULL, NULL, NULL); + ZnMapInfoGetLine(map_info, i, NULL, &line_style, NULL, NULL, NULL, NULL, NULL); switch (line_style) { - case MapInfoLineSimple: + case ZnMapInfoLineSimple: num_points += 2; break; - case MapInfoLineDashed: + case ZnMapInfoLineDashed: num_dashed_points += 2; break; - case MapInfoLineDotted: + case ZnMapInfoLineDotted: num_dotted_points += 2; break; - case MapInfoLineMixed: + case ZnMapInfoLineMixed: num_mixed_points += 2; break; - case MapInfoLineMarked: + case ZnMapInfoLineMarked: num_points += 2; - MapInfoGetMarks(map_info, i, NULL, &n_new_marks); + ZnMapInfoGetMarks(map_info, i, NULL, &n_new_marks); num_marks += n_new_marks; break; } } - cnt = MapInfoNumTexts(map_info); + cnt = ZnMapInfoNumTexts(map_info); for (i = 0; i < cnt; i++) { - MapInfoGetText(map_info, i, NULL, &text_style, &line_style, NULL, NULL, NULL); - if (text_style == MapInfoUnderlinedText) { + ZnMapInfoGetText(map_info, i, NULL, &text_style, &line_style, NULL, NULL, NULL); + if (text_style == ZnMapInfoUnderlinedText) { switch (line_style) { - case MapInfoLineSimple: - case MapInfoLineMarked: + case ZnMapInfoLineSimple: + case ZnMapInfoLineMarked: num_points += 2; break; - case MapInfoLineDotted: + case ZnMapInfoLineDotted: num_dotted_points += 2; break; - case MapInfoLineMixed: + case ZnMapInfoLineMixed: num_mixed_points += 2; break; - case MapInfoLineDashed: + case ZnMapInfoLineDashed: num_dashed_points += 2; break; } } } - cnt = MapInfoNumArcs(map_info); + cnt = ZnMapInfoNumArcs(map_info); for (i = 0; i < cnt; i++) { - MapInfoGetArc(map_info, i, NULL, &line_style, NULL, NULL, NULL, NULL, NULL, NULL); + ZnMapInfoGetArc(map_info, i, NULL, &line_style, NULL, NULL, NULL, NULL, NULL, NULL); switch (line_style) { - case MapInfoLineSimple: - case MapInfoLineMarked: + case ZnMapInfoLineSimple: + case ZnMapInfoLineMarked: num_arcs += 2; break; - case MapInfoLineDotted: + case ZnMapInfoLineDotted: num_dotted_arcs += 2; break; - case MapInfoLineMixed: + case ZnMapInfoLineMixed: num_mixed_arcs += 2; break; - case MapInfoLineDashed: + case ZnMapInfoLineDashed: num_dashed_arcs += 2; break; } @@ -639,13 +638,13 @@ ComputeCoordinates(Item item, } ZnListAssertSize(map->marks, num_marks); if (!map->symbols) { - map->symbols = ZnListNew(MapInfoNumSymbols(map_info), sizeof(ZnPoint)); + map->symbols = ZnListNew(ZnMapInfoNumSymbols(map_info), sizeof(ZnPoint)); } - ZnListAssertSize(map->symbols, MapInfoNumSymbols(map_info)); + ZnListAssertSize(map->symbols, ZnMapInfoNumSymbols(map_info)); if (!map->texts) { - map->texts = ZnListNew(MapInfoNumTexts(map_info), sizeof(ZnPoint)); + map->texts = ZnListNew(ZnMapInfoNumTexts(map_info), sizeof(ZnPoint)); } - ZnListAssertSize(map->texts, MapInfoNumTexts(map_info)); + ZnListAssertSize(map->texts, ZnMapInfoNumTexts(map_info)); /* * Ask the pointers to the actual arrays. @@ -668,7 +667,7 @@ ComputeCoordinates(Item item, sym_h2 = (sym_h2+1)/2; } /*printf("Map: %d %d %d %d %d, texts: %d, symbols: %d\n", num_points, num_dashed_points, num_dotted_points, - num_mixed_points, num_marks, MapInfoNumTexts(map_info), MapInfoNumSymbols(map_info));*/ + num_mixed_points, num_marks, ZnMapInfoNumTexts(map_info), ZnMapInfoNumSymbols(map_info));*/ /* * Reset the counts of points to compute the actual * counts taking into account the clipping and the @@ -684,9 +683,9 @@ ComputeCoordinates(Item item, num_dotted_arcs = 0; num_mixed_arcs = 0; - cnt = MapInfoNumLines(map_info); + cnt = ZnMapInfoNumLines(map_info); for (i = 0; i < cnt; i++) { - MapInfoGetLine(map_info, i, NULL, &line_style, &line_width, + ZnMapInfoGetLine(map_info, i, NULL, &line_style, &line_width, &x_from_w, &y_from_w, &x_to_w, &y_to_w); tmp_from.x = x_from_w; @@ -704,19 +703,19 @@ ComputeCoordinates(Item item, } if (!map->filled) { - if (LineInBBox(&from, &to, &zn_bbox) < 0) { + if (ZnLineInBBox(&from, &to, &zn_bbox) < 0) { continue; } } switch (line_style) { - case MapInfoLineSimple: + case ZnMapInfoLineSimple: vectors[num_points] = from; num_points++; vectors[num_points] = to; num_points++; break; - case MapInfoLineDashed: + case ZnMapInfoLineDashed: if (!map->filled) { dashed_vectors[num_dashed_points] = from; num_dashed_points++; @@ -724,7 +723,7 @@ ComputeCoordinates(Item item, num_dashed_points++; } break; - case MapInfoLineDotted: + case ZnMapInfoLineDotted: if (!map->filled) { dotted_vectors[num_dotted_points] = from; num_dotted_points++; @@ -732,7 +731,7 @@ ComputeCoordinates(Item item, num_dotted_points++; } break; - case MapInfoLineMixed: + case ZnMapInfoLineMixed: if (!map->filled) { mixed_vectors[num_mixed_points] = from; num_mixed_points++; @@ -740,14 +739,14 @@ ComputeCoordinates(Item item, num_mixed_points++; } break; - case MapInfoLineMarked: + case ZnMapInfoLineMarked: if (!map->filled) { vectors[num_points] = from; num_points++; vectors[num_points] = to; num_points++; if (wi->map_distance_symbol != ZnUnspecifiedImage) { - MapInfoGetMarks(map_info, i, &new_marks, &n_new_marks); + ZnMapInfoGetMarks(map_info, i, &new_marks, &n_new_marks); for (j = 0; j < n_new_marks; j++) { /* * The transform can be put outside the loop when @@ -757,10 +756,10 @@ ComputeCoordinates(Item item, tmp_from.x = new_marks[j].x; tmp_from.y = new_marks[j].y; ZnTransformPoint(wi->current_transfo, &tmp_from, &marks[num_marks]); - AddPointToBBox(&item->item_bounding_box, - marks[num_marks].x-sym_w2, marks[num_marks].y-sym_h2); - AddPointToBBox(&item->item_bounding_box, - marks[num_marks].x+sym_w2, marks[num_marks].x+sym_h2); + ZnAddPointToBBox(&item->item_bounding_box, + marks[num_marks].x-sym_w2, marks[num_marks].y-sym_h2); + ZnAddPointToBBox(&item->item_bounding_box, + marks[num_marks].x+sym_w2, marks[num_marks].x+sym_h2); num_marks++; } } @@ -769,11 +768,11 @@ ComputeCoordinates(Item item, } } - cnt = MapInfoNumArcs(map_info); + cnt = ZnMapInfoNumArcs(map_info); for (i = 0; i < cnt; i++) { ZnPoint xp; - MapInfoGetArc(map_info, i, NULL, &line_style, &line_width, + ZnMapInfoGetArc(map_info, i, NULL, &line_style, &line_width, &x_from_w, &y_from_w, &radius_w, &start_angle, &extend); tmp_from.x = x_from_w; @@ -782,7 +781,7 @@ ComputeCoordinates(Item item, tmp_from.x += radius_w; tmp_from.y = 0; ZnTransformPoint(wi->current_transfo, &tmp_from, &xp); - radius = xp.x - center.x; + radius = ((int) (xp.x - center.x)); bbox.orig.x = center.x - radius; bbox.orig.y = center.y - radius; @@ -796,21 +795,21 @@ ComputeCoordinates(Item item, continue; } - IntersectBBox(&zn_bbox, &bbox, &bbox_inter); - if (IsEmptyBBox(&bbox_inter)) { + ZnIntersectBBox(&zn_bbox, &bbox, &bbox_inter); + if (ZnIsEmptyBBox(&bbox_inter)) { continue; } - arc.x = center.x - radius; - arc.y = center.y - radius; + arc.x = (int) (center.x - radius); + arc.y = (int) (center.y - radius); arc.width = 2 * radius; arc.height = arc.width; arc.angle1 = start_angle*64; arc.angle2 = extend*64; switch (line_style) { - case MapInfoLineSimple: - case MapInfoLineMarked: + case ZnMapInfoLineSimple: + case ZnMapInfoLineMarked: arcs[num_arcs] = arc; num_arcs++; @@ -818,9 +817,9 @@ ComputeCoordinates(Item item, bbox.orig.y = arc.y; bbox.corner.x = bbox.orig.x + arc.width + 1; bbox.corner.y = bbox.orig.y + arc.height + 1; - AddBBoxToBBox(&item->item_bounding_box, &bbox); + ZnAddBBoxToBBox(&item->item_bounding_box, &bbox); break; - case MapInfoLineDashed: + case ZnMapInfoLineDashed: if (!map->filled) { dashed_arcs[num_dashed_arcs] = arc; num_dashed_arcs++; @@ -829,10 +828,10 @@ ComputeCoordinates(Item item, bbox.orig.y = arc.y; bbox.corner.x = bbox.orig.x + arc.width + 1; bbox.corner.y = bbox.orig.y + arc.height + 1; - AddBBoxToBBox(&item->item_bounding_box, &bbox); + ZnAddBBoxToBBox(&item->item_bounding_box, &bbox); } break; - case MapInfoLineDotted: + case ZnMapInfoLineDotted: if (!map->filled) { dotted_arcs[num_dotted_arcs] = arc; num_dotted_arcs++; @@ -841,10 +840,10 @@ ComputeCoordinates(Item item, bbox.orig.y = arc.y; bbox.corner.x = bbox.orig.x + arc.width + 1; bbox.corner.y = bbox.orig.y + arc.height + 1; - AddBBoxToBBox(&item->item_bounding_box, &bbox); + ZnAddBBoxToBBox(&item->item_bounding_box, &bbox); } break; - case MapInfoLineMixed: + case ZnMapInfoLineMixed: if (!map->filled) { mixed_arcs[num_mixed_arcs] = arc; num_mixed_arcs++; @@ -853,7 +852,7 @@ ComputeCoordinates(Item item, bbox.orig.y = arc.y; bbox.corner.x = bbox.orig.x + arc.width + 1; bbox.corner.y = bbox.orig.y + arc.height + 1; - AddBBoxToBBox(&item->item_bounding_box, &bbox); + ZnAddBBoxToBBox(&item->item_bounding_box, &bbox); } break; } @@ -873,9 +872,9 @@ ComputeCoordinates(Item item, ZnImage sym, *syms = ZnListArray(map->symbol_patterns); int num_syms = ZnListSize(map->symbol_patterns); - cnt = MapInfoNumSymbols(map_info); + cnt = ZnMapInfoNumSymbols(map_info); for (i = 0; i < cnt; i++) { - MapInfoGetSymbol(map_info, i, NULL, &x_from_w, &y_from_w, &symbol); + ZnMapInfoGetSymbol(map_info, i, NULL, &x_from_w, &y_from_w, &symbol); tmp_from.x = x_from_w; tmp_from.y = y_from_w; ZnTransformPoint(wi->current_transfo, &tmp_from, &symbols[i]); @@ -884,28 +883,28 @@ ComputeCoordinates(Item item, ZnSizeOfImage(sym, &sym_w2, &sym_h2); sym_w2 = (sym_w2+1)/2; sym_h2 = (sym_h2+1)/2; - AddPointToBBox(&item->item_bounding_box, - symbols[i].x-sym_w2, symbols[i].y-sym_h2); - AddPointToBBox(&item->item_bounding_box, - symbols[i].x+sym_w2, symbols[i].y+sym_h2); + ZnAddPointToBBox(&item->item_bounding_box, + symbols[i].x-sym_w2, symbols[i].y-sym_h2); + ZnAddPointToBBox(&item->item_bounding_box, + symbols[i].x+sym_w2, symbols[i].y+sym_h2); } } ZnListAssertSize(map->symbols, cnt); } - cnt = MapInfoNumTexts(map_info); + cnt = ZnMapInfoNumTexts(map_info); text_font = map->text_font ? map->text_font : wi->map_text_font; for (i = 0; i < cnt; i++) { - MapInfoGetText(map_info, i, NULL, + ZnMapInfoGetText(map_info, i, NULL, &text_style, &line_style, &x_from_w, &y_from_w, &text); tmp_from.x = x_from_w; tmp_from.y = y_from_w; ZnTransformPoint(wi->current_transfo, &tmp_from, &texts[i]); - AddStringToBBox(&item->item_bounding_box, text, text_font, - texts[i].x, texts[i].y); + ZnAddStringToBBox(&item->item_bounding_box, text, text_font, + texts[i].x, texts[i].y); - if (text_style == MapInfoUnderlinedText) { - GetStringBBox(text, text_font, texts[i].x, texts[i].y, &bbox); + if (text_style == ZnMapInfoUnderlinedText) { + ZnGetStringBBox(text, text_font, texts[i].x, texts[i].y, &bbox); from.x = bbox.orig.x; from.y = bbox.corner.y; @@ -913,26 +912,26 @@ ComputeCoordinates(Item item, to.y = bbox.corner.y; switch (line_style) { - case MapInfoLineSimple: - case MapInfoLineMarked: + case ZnMapInfoLineSimple: + case ZnMapInfoLineMarked: vectors[num_points] = from; num_points++; vectors[num_points] = to; num_points++; break; - case MapInfoLineDashed: + case ZnMapInfoLineDashed: dashed_vectors[num_dashed_points] = from; num_dashed_points++; dashed_vectors[num_dashed_points] = to; num_dashed_points++; break; - case MapInfoLineDotted: + case ZnMapInfoLineDotted: dotted_vectors[num_dotted_points] = from; num_dotted_points++; dotted_vectors[num_dotted_points] = to; num_dotted_points++; break; - case MapInfoLineMixed: + case ZnMapInfoLineMixed: mixed_vectors[num_mixed_points] = from; num_mixed_points++; mixed_vectors[num_mixed_points] = to; @@ -953,18 +952,18 @@ ComputeCoordinates(Item item, ZnListAssertSize(map->mixed_vectors, num_mixed_points); ZnListAssertSize(map->marks, num_marks); - AddPointsToBBox(&item->item_bounding_box, - (ZnPoint *) ZnListArray(map->vectors), - ZnListSize(map->vectors)); - AddPointsToBBox(&item->item_bounding_box, - (ZnPoint *) ZnListArray(map->dashed_vectors), - ZnListSize(map->dashed_vectors)); - AddPointsToBBox(&item->item_bounding_box, - (ZnPoint *) ZnListArray(map->dotted_vectors), - ZnListSize(map->dotted_vectors)); - AddPointsToBBox(&item->item_bounding_box, - (ZnPoint *) ZnListArray(map->mixed_vectors), - ZnListSize(map->mixed_vectors)); + ZnAddPointsToBBox(&item->item_bounding_box, + (ZnPoint *) ZnListArray(map->vectors), + ZnListSize(map->vectors)); + ZnAddPointsToBBox(&item->item_bounding_box, + (ZnPoint *) ZnListArray(map->dashed_vectors), + ZnListSize(map->dashed_vectors)); + ZnAddPointsToBBox(&item->item_bounding_box, + (ZnPoint *) ZnListArray(map->dotted_vectors), + ZnListSize(map->dotted_vectors)); + ZnAddPointsToBBox(&item->item_bounding_box, + (ZnPoint *) ZnListArray(map->mixed_vectors), + ZnListSize(map->mixed_vectors)); } @@ -979,8 +978,8 @@ ComputeCoordinates(Item item, */ static int -ToArea(Item item, - ZnToArea ta) +ToArea(ZnItem item __unused, + ZnToArea ta __unused) { return -1; } @@ -995,13 +994,14 @@ ToArea(Item item, */ static void -Draw(Item item) +Draw(ZnItem item) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; MapItem map = (MapItem) item; - MapInfoId map_info; + ZnMapInfoId map_info; ZnPoint *points; XPoint *xpoints; + XArc *arcs; char *text; char tmp_str[] = "."; XGCValues values; @@ -1014,7 +1014,7 @@ Draw(Item item) map_info = map->map_info; - values.foreground = ZnPixel(ZnGetGradientColor(map->color, 0, NULL)); + values.foreground = ZnPixel(ZnGetGradientColor(map->color, 0.0, NULL)); if (map->filled) { if (ZnListSize(map->vectors) || ZnListSize(map->arcs)) { @@ -1024,7 +1024,7 @@ Draw(Item item) } else { /* Fill stippled */ values.fill_style = FillStippled; - values.stipple = ZnImagePixmap(map->fill_pattern, NULL); + values.stipple = ZnImagePixmap(map->fill_pattern); XChangeGC(wi->dpy, wi->gc, GCFillStyle | GCStipple | GCForeground, &values); } @@ -1035,23 +1035,28 @@ Draw(Item item) xpoints = (XPoint *) ZnListArray(wi->work_xpts); points = (ZnPoint *) ZnListArray(map->vectors); for (i = 0; i < cnt; i++) { - xpoints[i].x = points[i].x; - xpoints[i].y = points[i].y; + xpoints[i].x = (int) points[i].x; + xpoints[i].y = (int) points[i].y; } - XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc, xpoints, cnt, + XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc, xpoints, (int) cnt, Nonconvex, CoordModeOrigin); } if (ZnListSize(map->arcs)) { - XFillArcs(wi->dpy, wi->draw_buffer, wi->gc, - (XArc *) ZnListArray(map->arcs), ZnListSize(map->arcs)); + arcs = ZnListArray(map->arcs); + cnt = ZnListSize(map->arcs); + for (i = 0; i < cnt; i++, arcs++) { + XFillArc(wi->dpy, wi->draw_buffer, wi->gc, + arcs->x, arcs->y, arcs->width, arcs->height, + arcs->angle1, arcs->angle2); + } } } } else { /* Not filled */ if (ZnListSize(map->vectors)) { - ZnSetLineStyle(wi, LINE_SIMPLE); + ZnSetLineStyle(wi, ZN_LINE_SIMPLE); values.fill_style = FillSolid; values.line_width = 0; XChangeGC(wi->dpy, wi->gc, @@ -1065,21 +1070,24 @@ Draw(Item item) cnt = ZnListSize(map->vectors); points = (ZnPoint *) ZnListArray(map->vectors); for (i = 0; i < cnt; i += 2) { - if (LineInBBox(&points[i], &points[i+1], &wi->damaged_area) >= 0) { - MapInfoGetLine(map_info, i/2, NULL, NULL, &line_width, NULL, + if (ZnLineInBBox(&points[i], &points[i+1], &wi->damaged_area) >= 0) { + ZnMapInfoGetLine(map_info, i/2, NULL, NULL, &line_width, NULL, NULL, NULL, NULL); if (line_width != values.line_width) { values.line_width = line_width; XChangeGC(wi->dpy, wi->gc, GCLineWidth, &values); } XDrawLine(wi->dpy, wi->draw_buffer, wi->gc, - points[i].x, points[i].y, points[i+1].x, points[i+1].y); + (int) points[i].x, + (int) points[i].y, + (int) points[i+1].x, + (int) points[i+1].y); } } } if (ZnListSize(map->dashed_vectors)) { - ZnSetLineStyle(wi, LINE_DASHED); + ZnSetLineStyle(wi, ZN_LINE_DASHED); values.fill_style = FillSolid; values.line_width = 0; XChangeGC(wi->dpy, wi->gc, GCFillStyle | GCLineWidth | GCForeground, &values); @@ -1091,20 +1099,23 @@ Draw(Item item) cnt = ZnListSize(map->dashed_vectors); points = (ZnPoint *) ZnListArray(map->dashed_vectors); for (i = 0; i < cnt; i += 2) { - if (LineInBBox(&points[i], &points[i+1], &wi->damaged_area) >= 0) { - MapInfoGetLine(map_info, i/2, NULL, NULL, &line_width, NULL, NULL, NULL, NULL); + if (ZnLineInBBox(&points[i], &points[i+1], &wi->damaged_area) >= 0) { + ZnMapInfoGetLine(map_info, i/2, NULL, NULL, &line_width, NULL, NULL, NULL, NULL); if (line_width != values.line_width) { values.line_width = line_width; XChangeGC(wi->dpy, wi->gc, GCLineWidth, &values); } XDrawLine(wi->dpy, wi->draw_buffer, wi->gc, - points[i].x, points[i].y, points[i+1].x, points[i+1].y); + (int) points[i].x, + (int) points[i].y, + (int) points[i+1].x, + (int) points[i+1].y); } } } if (ZnListSize(map->dotted_vectors)) { - ZnSetLineStyle(wi, LINE_DOTTED); + ZnSetLineStyle(wi, ZN_LINE_DOTTED); values.fill_style = FillSolid; values.line_width = 0; XChangeGC(wi->dpy, wi->gc, @@ -1117,20 +1128,23 @@ Draw(Item item) cnt = ZnListSize(map->dotted_vectors); points = (ZnPoint *) ZnListArray(map->dotted_vectors); for (i = 0; i < cnt; i += 2) { - if (LineInBBox(&points[i], &points[i+1], &wi->damaged_area) >= 0) { - MapInfoGetLine(map_info, i/2, NULL, NULL, &line_width, NULL, NULL, NULL, NULL); + if (ZnLineInBBox(&points[i], &points[i+1], &wi->damaged_area) >= 0) { + ZnMapInfoGetLine(map_info, i/2, NULL, NULL, &line_width, NULL, NULL, NULL, NULL); if (line_width != values.line_width) { values.line_width = line_width; XChangeGC(wi->dpy, wi->gc, GCLineWidth, &values); } XDrawLine(wi->dpy, wi->draw_buffer, wi->gc, - points[i].x, points[i].y, points[i+1].x, points[i+1].y); + (int) points[i].x, + (int) points[i].y, + (int) points[i+1].x, + (int) points[i+1].y); } } } if (ZnListSize(map->mixed_vectors)) { - ZnSetLineStyle(wi, LINE_MIXED); + ZnSetLineStyle(wi, ZN_LINE_MIXED); values.fill_style = FillSolid; values.line_width = 0; XChangeGC(wi->dpy, wi->gc, GCFillStyle | GCLineWidth | GCForeground, &values); @@ -1142,82 +1156,86 @@ Draw(Item item) cnt = ZnListSize(map->mixed_vectors); points = (ZnPoint *) ZnListArray(map->mixed_vectors); for (i = 0; i < cnt; i += 2) { - if (LineInBBox(&points[i], &points[i+1], &wi->damaged_area) >= 0) { - MapInfoGetLine(map_info, i/2, NULL, NULL, &line_width, NULL, NULL, NULL, NULL); + if (ZnLineInBBox(&points[i], &points[i+1], &wi->damaged_area) >= 0) { + ZnMapInfoGetLine(map_info, i/2, NULL, NULL, &line_width, NULL, NULL, NULL, NULL); if (line_width != values.line_width) { values.line_width = line_width; XChangeGC(wi->dpy, wi->gc, GCLineWidth, &values); } XDrawLine(wi->dpy, wi->draw_buffer, wi->gc, - points[i].x, points[i].y, points[i+1].x, points[i+1].y); + (int) points[i].x, + (int) points[i].y, + (int) points[i+1].x, + (int) points[i+1].y); } } } if (ZnListSize(map->arcs)) { - ZnSetLineStyle(wi, LINE_SIMPLE); + ZnSetLineStyle(wi, ZN_LINE_SIMPLE); values.fill_style = FillSolid; values.line_width = 0; XChangeGC(wi->dpy, wi->gc, GCFillStyle | GCLineWidth | GCForeground, &values); - - /* !! WARNING !! XDrawArcs can't handle an unlimited number of arcs - in releases R4 and older */ - - XDrawArcs(wi->dpy, wi->draw_buffer, wi->gc, - (XArc *) ZnListArray(map->arcs), ZnListSize(map->arcs)); + arcs = ZnListArray(map->arcs); + cnt = ZnListSize(map->arcs); + for (i = 0; i < cnt; i++, arcs++) { + XDrawArc(wi->dpy, wi->draw_buffer, wi->gc, + arcs->x, arcs->y, arcs->width, arcs->height, + arcs->angle1, arcs->angle2); + } } if (ZnListSize(map->dashed_arcs)) { - ZnSetLineStyle(wi, LINE_DASHED); + ZnSetLineStyle(wi, ZN_LINE_DASHED); values.fill_style = FillSolid; values.line_width = 0; XChangeGC(wi->dpy, wi->gc, GCFillStyle | GCLineWidth | GCForeground, &values); - - /* !! WARNING !! XDrawArcs can't handle an unlimited number of arcs - in releases R4 and older */ - - XDrawArcs(wi->dpy, wi->draw_buffer, wi->gc, - (XArc *) ZnListArray(map->dashed_arcs), - ZnListSize(map->dashed_arcs)); + arcs = ZnListArray(map->arcs); + cnt = ZnListSize(map->arcs); + for (i = 0; i < cnt; i++, arcs++) { + XDrawArc(wi->dpy, wi->draw_buffer, wi->gc, + arcs->x, arcs->y, arcs->width, arcs->height, + arcs->angle1, arcs->angle2); + } } if (ZnListSize(map->dotted_arcs)) { - ZnSetLineStyle(wi, LINE_DOTTED); + ZnSetLineStyle(wi, ZN_LINE_DOTTED); values.fill_style = FillSolid; values.line_width = 0; XChangeGC(wi->dpy, wi->gc, GCFillStyle | GCLineWidth | GCForeground, &values); - - /* !! WARNING !! XDrawArcs can't handle an unlimited number of arcs - in releases R4 and older */ - - XDrawArcs(wi->dpy, wi->draw_buffer, wi->gc, - (XArc *) ZnListArray(map->dotted_arcs), - ZnListSize(map->dotted_arcs)); + arcs = ZnListArray(map->arcs); + cnt = ZnListSize(map->arcs); + for (i = 0; i < cnt; i++, arcs++) { + XDrawArc(wi->dpy, wi->draw_buffer, wi->gc, + arcs->x, arcs->y, arcs->width, arcs->height, + arcs->angle1, arcs->angle2); + } } if (ZnListSize(map->mixed_arcs)) { - ZnSetLineStyle(wi, LINE_MIXED); + ZnSetLineStyle(wi, ZN_LINE_MIXED); values.fill_style = FillSolid; values.line_width = 0; XChangeGC(wi->dpy, wi->gc, GCFillStyle | GCLineWidth | GCForeground, &values); - - /* !! WARNING !! XDrawArcs can't handle an unlimited number of arcs - in releases R4 and older */ - - XDrawArcs(wi->dpy, wi->draw_buffer, wi->gc, - (XArc *) ZnListArray(map->mixed_arcs), - ZnListSize(map->mixed_arcs)); + arcs = ZnListArray(map->arcs); + cnt = ZnListSize(map->arcs); + for (i = 0; i < cnt; i++, arcs++) { + XDrawArc(wi->dpy, wi->draw_buffer, wi->gc, + arcs->x, arcs->y, arcs->width, arcs->height, + arcs->angle1, arcs->angle2); + } } if (ZnListSize(map->texts)) { /* For the Tk widget we don't have to bother with old * compatibility issues. */ - values.font = ZnFontId(map->text_font); + values.font = Tk_FontId(map->text_font); values.fill_style = FillSolid; XChangeGC(wi->dpy, wi->gc, GCFillStyle | GCFont | GCForeground, &values); @@ -1225,14 +1243,16 @@ Draw(Item item) cnt = ZnListSize(map->texts); points = (ZnPoint *) ZnListArray(map->texts); for (i = 0; i < cnt; i++) { - MapInfoGetText(map_info, i, NULL, NULL, NULL, NULL, NULL, &text); - XDrawString(wi->dpy, wi->draw_buffer, wi->gc, - points[i].x, points[i].y, text, strlen(text)); + ZnMapInfoGetText(map_info, i, NULL, NULL, NULL, NULL, NULL, &text); + Tk_DrawChars(wi->dpy, wi->draw_buffer, wi->gc, + map->text_font, text, (int) strlen(text), + (int) points[i].x, (int) points[i].y); } } if (ZnListSize(map->symbols) || ZnListSize(map->marks)) { - int w, h, ox, oy; + int ox, oy; + unsigned int w, h; ZnImage sym; values.fill_style = FillStippled; @@ -1245,13 +1265,13 @@ Draw(Item item) cnt = ZnListSize(map->symbols); points = ZnListArray(map->symbols); for (i = 0; i < cnt; i++) { - MapInfoGetSymbol(map_info, i, NULL, NULL, NULL, &(tmp_str[0])); + ZnMapInfoGetSymbol(map_info, i, NULL, NULL, NULL, &(tmp_str[0])); sym = syms[tmp_str[0]%num_syms]; if (sym != ZnUnspecifiedImage) { ZnSizeOfImage(sym, &w ,&h); - ox = points[i].x-w/2; - oy = points[i].y-h/2; - values.stipple = ZnImagePixmap(sym, NULL); + ox = ((int) points[i].x) - w/2; + oy = ((int) points[i].y) - h/2; + values.stipple = ZnImagePixmap(sym); values.ts_x_origin = ox; values.ts_y_origin = oy; XChangeGC(wi->dpy, wi->gc, @@ -1265,11 +1285,11 @@ Draw(Item item) ZnSizeOfImage(wi->map_distance_symbol, &w, &h); cnt = ZnListSize(map->marks); points = ZnListArray(map->marks); - values.stipple = ZnImagePixmap(wi->map_distance_symbol, NULL); + values.stipple = ZnImagePixmap(wi->map_distance_symbol); XChangeGC(wi->dpy, wi->gc, GCStipple, &values); for (i = 0; i < cnt; i++) { - ox = points[i].x-w/2; - oy = points[i].y-h/2; + ox = ((int) points[i].x) - w/2; + oy = ((int) points[i].y) - h/2; values.ts_x_origin = ox; values.ts_y_origin = oy; XChangeGC(wi->dpy, wi->gc, GCTileStipXOrigin|GCTileStipYOrigin, &values); @@ -1288,27 +1308,27 @@ Draw(Item item) * ********************************************************************************** */ +#ifdef GL static void -Render(Item item) +Render(ZnItem item) { -#ifdef GLX - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; MapItem map = (MapItem) item; - MapInfoId map_info; + ZnMapInfoId map_info; ZnPoint *points, p; char *text; char tmp_str[] = "."; unsigned int i, cnt; - int line_width, new_width; XColor *color; - int alpha, w, h; - + int line_width, new_width, w, h; + unsigned short alpha; + if (!map->map_info) { return; } map_info = map->map_info; - color = ZnGetGradientColor(map->color, 0, &alpha); + color = ZnGetGradientColor(map->color, 0.0, &alpha); alpha = ZnComposeAlpha(alpha, wi->alpha); glColor4us(color->red, color->green, color->blue, alpha); if (map->filled) { @@ -1316,11 +1336,11 @@ Render(Item item) if (map->fill_pattern != ZnUnspecifiedImage) { /* Fill stippled */ glEnable(GL_POLYGON_STIPPLE); - glPolygonStipple(ZnImagePattern(map->fill_pattern, NULL)); + glPolygonStipple(ZnImageMask(map->fill_pattern, NULL)); } cnt = ZnListSize(map->vectors); if (cnt) { - /* TODO_GLX: Need to have a tesselated polygon */ + /* TODO_GL: Need to have a tesselated polygon */ } if (ZnListSize(map->arcs)) { } @@ -1330,42 +1350,42 @@ Render(Item item) else { /* Not filled */ if (ZnListSize(map->vectors)) { line_width = 1; - glLineWidth(line_width); - ZnSetLineStyle(wi, LINE_SIMPLE); + glLineWidth((GLfloat) line_width); + ZnSetLineStyle(wi, ZN_LINE_SIMPLE); cnt = ZnListSize(map->vectors); points = ZnListArray(map->vectors); glBegin(GL_LINES); for (i = 0; i < cnt; i += 2) { - if (LineInBBox(&points[i], &points[i+1], &wi->damaged_area) >= 0) { - MapInfoGetLine(map_info, i/2, NULL, NULL, &new_width, NULL, + if (ZnLineInBBox(&points[i], &points[i+1], &wi->damaged_area) >= 0) { + ZnMapInfoGetLine(map_info, i/2, NULL, NULL, &new_width, NULL, NULL, NULL, NULL); if (new_width != line_width) { line_width = new_width; - glLineWidth(line_width); + glLineWidth((GLfloat) line_width); } - glVertex2f(points[i].x, points[i].y); - glVertex2f(points[i+1].x, points[i+1].y); + glVertex2d(points[i].x, points[i].y); + glVertex2d(points[i+1].x, points[i+1].y); } } glEnd(); } if (ZnListSize(map->dashed_vectors)) { line_width = 1; - glLineWidth(line_width); - ZnSetLineStyle(wi, LINE_DASHED); + glLineWidth((GLfloat) line_width); + ZnSetLineStyle(wi, ZN_LINE_DASHED); cnt = ZnListSize(map->dashed_vectors); points = ZnListArray(map->dashed_vectors); glBegin(GL_LINES); for (i = 0; i < cnt; i += 2) { - if (LineInBBox(&points[i], &points[i+1], &wi->damaged_area) >= 0) { - MapInfoGetLine(map_info, i/2, NULL, NULL, &new_width, NULL, + if (ZnLineInBBox(&points[i], &points[i+1], &wi->damaged_area) >= 0) { + ZnMapInfoGetLine(map_info, i/2, NULL, NULL, &new_width, NULL, NULL, NULL, NULL); if (new_width != line_width) { line_width = new_width; - glLineWidth(line_width); + glLineWidth((GLfloat) line_width); } - glVertex2f(points[i].x, points[i].y); - glVertex2f(points[i+1].x, points[i+1].y); + glVertex2d(points[i].x, points[i].y); + glVertex2d(points[i+1].x, points[i+1].y); } } glEnd(); @@ -1373,21 +1393,21 @@ Render(Item item) } if (ZnListSize(map->dotted_vectors)) { line_width = 1; - glLineWidth(line_width); - ZnSetLineStyle(wi, LINE_DOTTED); + glLineWidth((GLfloat) line_width); + ZnSetLineStyle(wi, ZN_LINE_DOTTED); cnt = ZnListSize(map->dotted_vectors); points = ZnListArray(map->dotted_vectors); glBegin(GL_LINES); for (i = 0; i < cnt; i += 2) { - if (LineInBBox(&points[i], &points[i+1], &wi->damaged_area) >= 0) { - MapInfoGetLine(map_info, i/2, NULL, NULL, &new_width, NULL, + if (ZnLineInBBox(&points[i], &points[i+1], &wi->damaged_area) >= 0) { + ZnMapInfoGetLine(map_info, i/2, NULL, NULL, &new_width, NULL, NULL, NULL, NULL); if (new_width != line_width) { line_width = new_width; - glLineWidth(line_width); + glLineWidth((GLfloat) line_width); } - glVertex2f(points[i].x, points[i].y); - glVertex2f(points[i+1].x, points[i+1].y); + glVertex2d(points[i].x, points[i].y); + glVertex2d(points[i+1].x, points[i+1].y); } } glEnd(); @@ -1395,21 +1415,21 @@ Render(Item item) } if (ZnListSize(map->mixed_vectors)) { line_width = 1; - glLineWidth(line_width); - ZnSetLineStyle(wi, LINE_MIXED); + glLineWidth((GLfloat) line_width); + ZnSetLineStyle(wi, ZN_LINE_MIXED); cnt = ZnListSize(map->mixed_vectors); points = ZnListArray(map->mixed_vectors); glBegin(GL_LINES); for (i = 0; i < cnt; i += 2) { - if (LineInBBox(&points[i], &points[i+1], &wi->damaged_area) >= 0) { - MapInfoGetLine(map_info, i/2, NULL, NULL, &new_width, NULL, + if (ZnLineInBBox(&points[i], &points[i+1], &wi->damaged_area) >= 0) { + ZnMapInfoGetLine(map_info, i/2, NULL, NULL, &new_width, NULL, NULL, NULL, NULL); if (new_width != line_width) { line_width = new_width; - glLineWidth(line_width); + glLineWidth((GLfloat) line_width); } - glVertex2f(points[i].x, points[i].y); - glVertex2f(points[i+1].x, points[i+1].y); + glVertex2d(points[i].x, points[i].y); + glVertex2d(points[i+1].x, points[i+1].y); } } glEnd(); @@ -1418,25 +1438,25 @@ Render(Item item) if (ZnListSize(map->arcs)) { line_width = 1; - glLineWidth(line_width); + glLineWidth((GLfloat) line_width); } if (ZnListSize(map->dashed_arcs)) { line_width = 1; - glLineWidth(line_width); + glLineWidth((GLfloat) line_width); glLineStipple(1, 0xF0F0); glEnable(GL_LINE_STIPPLE); glDisable(GL_LINE_STIPPLE); } if (ZnListSize(map->dotted_arcs)) { line_width = 1; - glLineWidth(line_width); + glLineWidth((GLfloat) line_width); glLineStipple(1, 0x18C3); glEnable(GL_LINE_STIPPLE); glDisable(GL_LINE_STIPPLE); } if (ZnListSize(map->mixed_arcs)) { line_width = 1; - glLineWidth(line_width); + glLineWidth((GLfloat) line_width); glLineStipple(1, 0x27FF); glEnable(GL_LINE_STIPPLE); glDisable(GL_LINE_STIPPLE); @@ -1451,8 +1471,8 @@ Render(Item item) points = ZnListArray(map->texts); for (i = 0; i < cnt; i++, points++) { glPushMatrix(); - MapInfoGetText(map_info, i, NULL, NULL, NULL, NULL, NULL, &text); - glTranslatef(points->x, points->y, 0.0); + ZnMapInfoGetText(map_info, i, NULL, NULL, NULL, NULL, NULL, &text); + glTranslated(points->x, points->y, 0.0); ZnRenderString(map->tfi, text, strlen(text)); glPopMatrix(); } @@ -1466,7 +1486,7 @@ Render(Item item) cnt = ZnListSize(map->symbols); points = ZnListArray(map->symbols); for (i = 0; i < cnt; i++) { - MapInfoGetSymbol(map_info, i, NULL, NULL, NULL, &(tmp_str[0])); + ZnMapInfoGetSymbol(map_info, i, NULL, NULL, NULL, &(tmp_str[0])); sym = syms[tmp_str[0]%num_syms]; if (sym != ZnUnspecifiedImage) { ZnSizeOfImage(sym, &w, &h); @@ -1488,8 +1508,13 @@ Render(Item item) } } } -#endif } +#else +static void +Render(ZnItem item __unused) +{ +} +#endif /* @@ -1500,10 +1525,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)); } @@ -1521,8 +1546,8 @@ IsSensitive(Item item, ********************************************************************************** */ static double -Pick(Item item, - ZnPick ps) +Pick(ZnItem item __unused, + ZnPick ps __unused) { return 1e40; } @@ -1537,17 +1562,17 @@ Pick(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 __unused, + int cmd __unused, + ZnPoint **pts __unused, + char **controls __unused, + unsigned int *num_pts __unused) { Tcl_AppendResult(item->wi->interp, " maps doesn't support the coords command", NULL); - return ZN_ERROR; + return TCL_ERROR; } @@ -1559,8 +1584,8 @@ Coords(Item item, ********************************************************************************** */ static void -PostScript(Item item, - PostScriptInfo ps_info) +PostScript(ZnItem item __unused, + ZnPostScriptInfo ps_info __unused) { } @@ -1573,7 +1598,7 @@ PostScript(Item item, ********************************************************************************** */ -static ItemClassStruct MAP_ITEM_CLASS = { +static ZnItemClassStruct MAP_ITEM_CLASS = { sizeof(MapItemStruct), 0, /* num_parts */ False, /* has_anchors */ diff --git a/generic/MapInfo.c b/generic/MapInfo.c index ddbbc16..f050898 100644 --- a/generic/MapInfo.c +++ b/generic/MapInfo.c @@ -29,7 +29,12 @@ #include #include +#ifndef _WIN32 #include +#include +#else +#include +#endif #include "MapInfo.h" #include "tkZinc.h" @@ -37,7 +42,6 @@ #include #include -#include static const char rcsid[] = "$Id$"; @@ -53,37 +57,37 @@ static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ " */ typedef struct { ZnPtr tag; - MapInfoLineStyle style; + ZnMapInfoLineStyle style; int width; - MapInfoPointStruct center; + ZnMapInfoPointStruct center; unsigned int radius; int start_angle; int extend; -} MapInfoArcStruct, *MapInfoArc; +} ZnMapInfoArcStruct, *ZnMapInfoArc; typedef struct { ZnPtr tag; - MapInfoLineStyle style; + ZnMapInfoLineStyle style; int width; - MapInfoPointStruct from; - MapInfoPointStruct to; + ZnMapInfoPointStruct from; + ZnMapInfoPointStruct to; unsigned int num_marks; - MapInfoPoint marks; -} MapInfoLineStruct, *MapInfoLine; + ZnMapInfoPoint marks; +} ZnMapInfoLineStruct, *ZnMapInfoLine; typedef struct { ZnPtr tag; - MapInfoPointStruct at; + ZnMapInfoPointStruct at; char symbol[2]; -} MapInfoSymbolStruct, *MapInfoSymbol; +} ZnMapInfoSymbolStruct, *ZnMapInfoSymbol; typedef struct { ZnPtr tag; - MapInfoTextStyle text_style; - MapInfoLineStyle line_style; - MapInfoPointStruct at; + ZnMapInfoTextStyle text_style; + ZnMapInfoLineStyle line_style; + ZnMapInfoPointStruct at; char *text; -} MapInfoTextStruct, *MapInfoText; +} ZnMapInfoTextStruct, *ZnMapInfoText; typedef struct { char *name; @@ -91,7 +95,7 @@ typedef struct { ZnList symbols; ZnList texts; ZnList arcs; -} MapInfoStruct, *MapInfo; +} ZnMapInfoStruct, *ZnMapInfo; #define MARKERS_SPACING 80.0 /* 10 nautic miles in 1/8 of a mile */ @@ -106,7 +110,7 @@ typedef struct { *----------------------------------------------------------------------- */ #define NOT_MARKED_STYLE(style) \ -((style) == MapInfoLineMarked ? MapInfoLineSimple : (style)); +((style) == ZnMapInfoLineMarked ? ZnMapInfoLineSimple : (style)); /* @@ -119,7 +123,7 @@ typedef struct { */ static void -ComputeLineMarks(MapInfoLine marked_line) +ComputeLineMarks(ZnMapInfoLine marked_line) { double length; unsigned int j; @@ -134,7 +138,7 @@ ComputeLineMarks(MapInfoLine marked_line) length = sqrt((double)((delta_x) * (delta_x) + (delta_y) * (delta_y))); step_x = (int) ((x_to - x_from) * MARKERS_SPACING / length); step_y = (int) ((y_to - y_from) * MARKERS_SPACING / length); - marked_line->num_marks = (int) length / MARKERS_SPACING; + marked_line->num_marks = (int) (length / MARKERS_SPACING); /* We don't want markers at ends, so we get rid of the last one if it is at an end */ @@ -143,7 +147,7 @@ ComputeLineMarks(MapInfoLine marked_line) } if (marked_line->num_marks) { - marked_line->marks = (MapInfoPoint) ZnMalloc(marked_line->num_marks * sizeof(MapInfoPointStruct)); + marked_line->marks = (ZnMapInfoPoint) ZnMalloc(marked_line->num_marks * sizeof(ZnMapInfoPointStruct)); } for (j = 0; j < marked_line->num_marks; j++) { @@ -153,62 +157,62 @@ ComputeLineMarks(MapInfoLine marked_line) } -static MapInfoId -MapInfoCreate(char *name) +static ZnMapInfoId +ZnMapInfoCreate(char *name) { - MapInfo new_map; + ZnMapInfo new_map; - new_map = (MapInfo) ZnMalloc(sizeof(MapInfoStruct)); - memset((char *) new_map, 0, sizeof(MapInfoStruct)); + new_map = (ZnMapInfo) ZnMalloc(sizeof(ZnMapInfoStruct)); + memset((char *) new_map, 0, sizeof(ZnMapInfoStruct)); if (!name) { name = ""; } new_map->name = (char *) ZnMalloc(strlen(name)+1); strcpy(new_map->name, name); - return((MapInfoId) new_map); + return((ZnMapInfoId) new_map); } static char * -MapInfoName(MapInfoId map_info) +ZnMapInfoName(ZnMapInfoId map_info) { if (!map_info) { return ""; } - return ((MapInfo) map_info)->name; + return ((ZnMapInfo) map_info)->name; } -static MapInfoId -MapInfoDuplicate(MapInfoId map_info) +static ZnMapInfoId +ZnMapInfoDuplicate(ZnMapInfoId map_info) { - MapInfo cur_map = (MapInfo) map_info; - MapInfo new_map; + ZnMapInfo cur_map = (ZnMapInfo) map_info; + ZnMapInfo new_map; int i, num_lines, num_texts; - MapInfoText new_texts, cur_texts; - MapInfoLine new_lines, cur_lines; + ZnMapInfoText new_texts, cur_texts; + ZnMapInfoLine new_lines, cur_lines; if (!cur_map) { - return ((MapInfoId) NULL); + return ((ZnMapInfoId) NULL); } - new_map = (MapInfo) MapInfoCreate(cur_map->name); + new_map = (ZnMapInfo) ZnMapInfoCreate(cur_map->name); if (cur_map->lines) { new_map->lines = ZnListDuplicate(cur_map->lines); - cur_lines = (MapInfoLine) ZnListArray(cur_map->lines); - new_lines = (MapInfoLine) ZnListArray(new_map->lines); + cur_lines = (ZnMapInfoLine) ZnListArray(cur_map->lines); + new_lines = (ZnMapInfoLine) ZnListArray(new_map->lines); num_lines = ZnListSize(cur_map->lines); for (i = 0; i < num_lines; i++) { - if (new_lines[i].style == MapInfoLineMarked) { - new_lines[i].marks = (MapInfoPoint) ZnMalloc(new_lines[i].num_marks * - sizeof(MapInfoPointStruct)); + if (new_lines[i].style == ZnMapInfoLineMarked) { + new_lines[i].marks = (ZnMapInfoPoint) ZnMalloc(new_lines[i].num_marks * + sizeof(ZnMapInfoPointStruct)); memcpy((char *) new_lines[i].marks, (char *) cur_lines[i].marks, - new_lines[i].num_marks * sizeof(MapInfoPointStruct)); + new_lines[i].num_marks * sizeof(ZnMapInfoPointStruct)); } } } @@ -218,8 +222,8 @@ MapInfoDuplicate(MapInfoId map_info) if (cur_map->texts) { new_map->texts = ZnListDuplicate(cur_map->texts); - cur_texts = (MapInfoText) ZnListArray(cur_map->texts); - new_texts = (MapInfoText) ZnListArray(new_map->texts); + cur_texts = (ZnMapInfoText) ZnListArray(cur_map->texts); + new_texts = (ZnMapInfoText) ZnListArray(new_map->texts); num_texts = ZnListSize(cur_map->texts); for (i = 0; i < num_texts; i++) { @@ -231,22 +235,22 @@ MapInfoDuplicate(MapInfoId map_info) new_map->arcs = ZnListDuplicate(cur_map->arcs); } - return((MapInfoId) new_map); + return((ZnMapInfoId) new_map); } static void -MapInfoDelete(MapInfoId map_info) +ZnMapInfoDelete(ZnMapInfoId map_info) { - MapInfo cur_map = (MapInfo) map_info; + ZnMapInfo cur_map = (ZnMapInfo) map_info; int i, num_texts, num_lines; - MapInfoText cur_texts; - MapInfoLine cur_lines; + ZnMapInfoText cur_texts; + ZnMapInfoLine cur_lines; if (cur_map) { if (cur_map->texts) { num_texts = ZnListSize(cur_map->texts); - cur_texts = (MapInfoText) ZnListArray(cur_map->texts); + cur_texts = (ZnMapInfoText) ZnListArray(cur_map->texts); for (i = 0; i < num_texts; i++) { ZnFree((char *) cur_texts[i].text); @@ -257,10 +261,10 @@ MapInfoDelete(MapInfoId map_info) if (cur_map->lines) { num_lines = ZnListSize(cur_map->lines); - cur_lines = (MapInfoLine) ZnListArray(cur_map->lines); + cur_lines = (ZnMapInfoLine) ZnListArray(cur_map->lines); for (i = 0; i < num_lines; i++) { - if (cur_lines[i].style == MapInfoLineMarked) { + if (cur_lines[i].style == ZnMapInfoLineMarked) { ZnFree((char *) cur_lines[i].marks); } } @@ -282,9 +286,9 @@ MapInfoDelete(MapInfoId map_info) } static void -MapInfoEmpty(MapInfoId map_info) +ZnMapInfoEmpty(ZnMapInfoId map_info) { - MapInfo cur_map = (MapInfo) map_info; + ZnMapInfo cur_map = (ZnMapInfo) map_info; if (cur_map) { if (cur_map->texts) { @@ -304,22 +308,22 @@ MapInfoEmpty(MapInfoId map_info) static void -MapInfoAddLine(MapInfoId map_info, - unsigned int index, - ZnPtr tag, - MapInfoLineStyle line_style, - int line_width, - int x_from, - int y_from, - int x_to, - int y_to) +ZnMapInfoAddLine(ZnMapInfoId map_info, + unsigned int index, + ZnPtr tag, + ZnMapInfoLineStyle line_style, + int line_width, + int x_from, + int y_from, + int x_to, + int y_to) { - MapInfo cur_map = (MapInfo) map_info; - MapInfoLineStruct line_struct; + ZnMapInfo cur_map = (ZnMapInfo) map_info; + ZnMapInfoLineStruct line_struct; if (cur_map) { if (!cur_map->lines) { - cur_map->lines = ZnListNew(16, sizeof(MapInfoLineStruct)); + cur_map->lines = ZnListNew(16, sizeof(ZnMapInfoLineStruct)); } line_struct.style = line_style; @@ -335,7 +339,7 @@ MapInfoAddLine(MapInfoId map_info, line_struct.to.x = x_to; line_struct.to.y = y_to; - if (line_style == MapInfoLineMarked) { + if (line_style == ZnMapInfoLineMarked) { ComputeLineMarks(&line_struct); } @@ -345,23 +349,23 @@ MapInfoAddLine(MapInfoId map_info, static void -MapInfoReplaceLine(MapInfoId map_info, - unsigned int index, - ZnPtr tag, - MapInfoLineStyle line_style, - int line_width, - int x_from, - int y_from, - int x_to, - int y_to) +ZnMapInfoReplaceLine(ZnMapInfoId map_info, + unsigned int index, + ZnPtr tag, + ZnMapInfoLineStyle line_style, + int line_width, + int x_from, + int y_from, + int x_to, + int y_to) { - MapInfo cur_map = (MapInfo) map_info; - MapInfoLine line_ptr; + ZnMapInfo cur_map = (ZnMapInfo) map_info; + ZnMapInfoLine line_ptr; if (cur_map && cur_map->lines) { - line_ptr = (MapInfoLine) ZnListAt(cur_map->lines, index); + line_ptr = (ZnMapInfoLine) ZnListAt(cur_map->lines, index); if (line_ptr) { - if (line_ptr->style == MapInfoLineMarked) { + if (line_ptr->style == ZnMapInfoLineMarked) { ZnFree((char *) line_ptr->marks); } @@ -378,7 +382,7 @@ MapInfoReplaceLine(MapInfoId map_info, line_ptr->to.x = x_to; line_ptr->to.y = y_to; - if (line_ptr->style == MapInfoLineMarked) { + if (line_ptr->style == ZnMapInfoLineMarked) { ComputeLineMarks(line_ptr); } } @@ -387,16 +391,16 @@ MapInfoReplaceLine(MapInfoId map_info, static void -MapInfoRemoveLine(MapInfoId map_info, - unsigned int index) +ZnMapInfoRemoveLine(ZnMapInfoId map_info, + unsigned int index) { - MapInfo cur_map = (MapInfo) map_info; - MapInfoLine line_ptr; + ZnMapInfo cur_map = (ZnMapInfo) map_info; + ZnMapInfoLine line_ptr; if (cur_map && cur_map->lines) { - line_ptr = (MapInfoLine) ZnListAt(cur_map->lines, index); + line_ptr = (ZnMapInfoLine) ZnListAt(cur_map->lines, index); if (line_ptr) { - if (line_ptr->style == MapInfoLineMarked) { + if (line_ptr->style == ZnMapInfoLineMarked) { ZnFree((char *) line_ptr->marks); } @@ -407,21 +411,21 @@ MapInfoRemoveLine(MapInfoId map_info, void -MapInfoGetLine(MapInfoId map_info, - unsigned int index, - ZnPtr *tag, - MapInfoLineStyle *line_style, - int *line_width, - int *x_from, - int *y_from, - int *x_to, - int *y_to) +ZnMapInfoGetLine(ZnMapInfoId map_info, + unsigned int index, + ZnPtr *tag, + ZnMapInfoLineStyle *line_style, + int *line_width, + int *x_from, + int *y_from, + int *x_to, + int *y_to) { - MapInfo cur_map = (MapInfo) map_info; - MapInfoLine line_ptr; + ZnMapInfo cur_map = (ZnMapInfo) map_info; + ZnMapInfoLine line_ptr; if (cur_map && cur_map->lines) { - line_ptr = (MapInfoLine) ZnListAt(cur_map->lines, index); + line_ptr = (ZnMapInfoLine) ZnListAt(cur_map->lines, index); if (line_ptr) { if (tag) { *tag = line_ptr->tag; @@ -455,17 +459,17 @@ MapInfoGetLine(MapInfoId map_info, void -MapInfoGetMarks(MapInfoId map_info, - unsigned int index, - MapInfoPoint *marks, - unsigned int *num_marks) +ZnMapInfoGetMarks(ZnMapInfoId map_info, + unsigned int index, + ZnMapInfoPoint *marks, + unsigned int *num_marks) { - MapInfo cur_map = (MapInfo) map_info; - MapInfoLine line_ptr; + ZnMapInfo cur_map = (ZnMapInfo) map_info; + ZnMapInfoLine line_ptr; if (cur_map && cur_map->lines) { - line_ptr = (MapInfoLine) ZnListAt(cur_map->lines, index); - if (line_ptr && line_ptr->style == MapInfoLineMarked) { + line_ptr = (ZnMapInfoLine) ZnListAt(cur_map->lines, index); + if (line_ptr && line_ptr->style == ZnMapInfoLineMarked) { if (marks) { *marks = line_ptr->marks; } @@ -478,9 +482,9 @@ MapInfoGetMarks(MapInfoId map_info, unsigned int -MapInfoNumLines(MapInfoId map_info) +ZnMapInfoNumLines(ZnMapInfoId map_info) { - MapInfo cur_map = (MapInfo) map_info; + ZnMapInfo cur_map = (ZnMapInfo) map_info; if (cur_map && cur_map->lines) { return ZnListSize(cur_map->lines); @@ -492,19 +496,19 @@ MapInfoNumLines(MapInfoId map_info) static void -MapInfoAddSymbol(MapInfoId map_info, - unsigned int index, - ZnPtr tag, - int x, - int y, - char symbol) +ZnMapInfoAddSymbol(ZnMapInfoId map_info, + unsigned int index, + ZnPtr tag, + int x, + int y, + int symbol) { - MapInfo cur_map = (MapInfo) map_info; - MapInfoSymbolStruct symbol_struct; + ZnMapInfo cur_map = (ZnMapInfo) map_info; + ZnMapInfoSymbolStruct symbol_struct; if (cur_map) { if (!cur_map->symbols) { - cur_map->symbols = ZnListNew(16, sizeof(MapInfoSymbolStruct)); + cur_map->symbols = ZnListNew(16, sizeof(ZnMapInfoSymbolStruct)); } symbol_struct.tag = tag; @@ -519,15 +523,15 @@ MapInfoAddSymbol(MapInfoId map_info, static void -MapInfoReplaceSymbol(MapInfoId map_info, - unsigned int index, - ZnPtr tag, - int x, - int y, - char symbol) +ZnMapInfoReplaceSymbol(ZnMapInfoId map_info, + unsigned int index, + ZnPtr tag, + int x, + int y, + int symbol) { - MapInfo cur_map = (MapInfo) map_info; - MapInfoSymbolStruct symbol_struct; + ZnMapInfo cur_map = (ZnMapInfo) map_info; + ZnMapInfoSymbolStruct symbol_struct; if (cur_map && cur_map->symbols) { symbol_struct.tag = tag; @@ -542,10 +546,10 @@ MapInfoReplaceSymbol(MapInfoId map_info, static void -MapInfoRemoveSymbol(MapInfoId map_info, - unsigned int index) +ZnMapInfoRemoveSymbol(ZnMapInfoId map_info, + unsigned int index) { - MapInfo cur_map = (MapInfo) map_info; + ZnMapInfo cur_map = (ZnMapInfo) map_info; if (cur_map && cur_map->symbols) { ZnListDelete(cur_map->symbols, index); @@ -554,18 +558,18 @@ MapInfoRemoveSymbol(MapInfoId map_info, void -MapInfoGetSymbol(MapInfoId map_info, - unsigned int index, - ZnPtr *tag, - int *x, - int *y, - char *symbol) +ZnMapInfoGetSymbol(ZnMapInfoId map_info, + unsigned int index, + ZnPtr *tag, + int *x, + int *y, + char *symbol) { - MapInfo cur_map = (MapInfo) map_info; - MapInfoSymbol symbol_ptr; + ZnMapInfo cur_map = (ZnMapInfo) map_info; + ZnMapInfoSymbol symbol_ptr; if (cur_map && cur_map->symbols) { - symbol_ptr = (MapInfoSymbol) ZnListAt(cur_map->symbols, index); + symbol_ptr = (ZnMapInfoSymbol) ZnListAt(cur_map->symbols, index); if (symbol_ptr) { if (tag) { *tag = symbol_ptr->tag; @@ -585,9 +589,9 @@ MapInfoGetSymbol(MapInfoId map_info, unsigned int -MapInfoNumSymbols(MapInfoId map_info) +ZnMapInfoNumSymbols(ZnMapInfoId map_info) { - MapInfo cur_map = (MapInfo) map_info; + ZnMapInfo cur_map = (ZnMapInfo) map_info; if (cur_map && cur_map->symbols) { return ZnListSize(cur_map->symbols); @@ -599,21 +603,21 @@ MapInfoNumSymbols(MapInfoId map_info) static void -MapInfoAddText(MapInfoId map_info, - unsigned int index, - ZnPtr tag, - MapInfoTextStyle text_style, - MapInfoLineStyle line_style, - int x, - int y, - char *text) +ZnMapInfoAddText(ZnMapInfoId map_info, + unsigned int index, + ZnPtr tag, + ZnMapInfoTextStyle text_style, + ZnMapInfoLineStyle line_style, + int x, + int y, + char *text) { - MapInfo cur_map = (MapInfo) map_info; - MapInfoTextStruct text_struct; + ZnMapInfo cur_map = (ZnMapInfo) map_info; + ZnMapInfoTextStruct text_struct; if (cur_map) { if (!cur_map->texts) { - cur_map->texts = ZnListNew(16, sizeof(MapInfoTextStruct)); + cur_map->texts = ZnListNew(16, sizeof(ZnMapInfoTextStruct)); } text_struct.tag = tag; @@ -630,20 +634,20 @@ MapInfoAddText(MapInfoId map_info, static void -MapInfoReplaceText(MapInfoId map_info, - unsigned int index, - ZnPtr tag, - MapInfoTextStyle text_style, - MapInfoLineStyle line_style, - int x, - int y, - char *text) +ZnMapInfoReplaceText(ZnMapInfoId map_info, + unsigned int index, + ZnPtr tag, + ZnMapInfoTextStyle text_style, + ZnMapInfoLineStyle line_style, + int x, + int y, + char *text) { - MapInfo cur_map = (MapInfo) map_info; - MapInfoText text_ptr; + ZnMapInfo cur_map = (ZnMapInfo) map_info; + ZnMapInfoText text_ptr; if (cur_map && cur_map->texts) { - text_ptr = (MapInfoText) ZnListAt(cur_map->texts, index); + text_ptr = (ZnMapInfoText) ZnListAt(cur_map->texts, index); if (text_ptr) { ZnFree(text_ptr->text); @@ -660,14 +664,14 @@ MapInfoReplaceText(MapInfoId map_info, static void -MapInfoRemoveText(MapInfoId map_info, - unsigned int index) +ZnMapInfoRemoveText(ZnMapInfoId map_info, + unsigned int index) { - MapInfo cur_map = (MapInfo) map_info; - MapInfoText text_ptr; + ZnMapInfo cur_map = (ZnMapInfo) map_info; + ZnMapInfoText text_ptr; if (cur_map && cur_map->texts) { - text_ptr = (MapInfoText) ZnListAt(cur_map->texts, index); + text_ptr = (ZnMapInfoText) ZnListAt(cur_map->texts, index); if (text_ptr) { ZnFree(text_ptr->text); @@ -678,20 +682,20 @@ MapInfoRemoveText(MapInfoId map_info, void -MapInfoGetText(MapInfoId map_info, - unsigned int index, - ZnPtr *tag, - MapInfoTextStyle *text_style, - MapInfoLineStyle *line_style, - int *x, - int *y, - char **text) +ZnMapInfoGetText(ZnMapInfoId map_info, + unsigned int index, + ZnPtr *tag, + ZnMapInfoTextStyle *text_style, + ZnMapInfoLineStyle *line_style, + int *x, + int *y, + char **text) { - MapInfo cur_map = (MapInfo) map_info; - MapInfoText text_ptr; + ZnMapInfo cur_map = (ZnMapInfo) map_info; + ZnMapInfoText text_ptr; if (cur_map && cur_map->texts) { - text_ptr = (MapInfoText) ZnListAt(cur_map->texts, index); + text_ptr = (ZnMapInfoText) ZnListAt(cur_map->texts, index); if (text_ptr) { if (tag) { *tag = text_ptr->tag; @@ -717,9 +721,9 @@ MapInfoGetText(MapInfoId map_info, unsigned int -MapInfoNumTexts(MapInfoId map_info) +ZnMapInfoNumTexts(ZnMapInfoId map_info) { - MapInfo cur_map = (MapInfo) map_info; + ZnMapInfo cur_map = (ZnMapInfo) map_info; if (cur_map && cur_map->texts) { return ZnListSize(cur_map->texts); @@ -731,23 +735,23 @@ MapInfoNumTexts(MapInfoId map_info) static void -MapInfoAddArc(MapInfoId map_info, - unsigned int index, - ZnPtr tag, - MapInfoLineStyle line_style, - int line_width, - int center_x, - int center_y, - unsigned int radius, - int start_angle, - int extend) +ZnMapInfoAddArc(ZnMapInfoId map_info, + unsigned int index, + ZnPtr tag, + ZnMapInfoLineStyle line_style, + int line_width, + int center_x, + int center_y, + unsigned int radius, + int start_angle, + int extend) { - MapInfo cur_map = (MapInfo) map_info; - MapInfoArcStruct arc_struct; + ZnMapInfo cur_map = (ZnMapInfo) map_info; + ZnMapInfoArcStruct arc_struct; if (cur_map) { if (!cur_map->arcs) { - cur_map->arcs = ZnListNew(16, sizeof(MapInfoArcStruct)); + cur_map->arcs = ZnListNew(16, sizeof(ZnMapInfoArcStruct)); } arc_struct.style = NOT_MARKED_STYLE(line_style); @@ -770,22 +774,22 @@ MapInfoAddArc(MapInfoId map_info, static void -MapInfoReplaceArc(MapInfoId map_info, - unsigned int index, - ZnPtr tag, - MapInfoLineStyle line_style, - int line_width, - int center_x, - int center_y, - unsigned int radius, - int start_angle, - int extend) +ZnMapInfoReplaceArc(ZnMapInfoId map_info, + unsigned int index, + ZnPtr tag, + ZnMapInfoLineStyle line_style, + int line_width, + int center_x, + int center_y, + unsigned int radius, + int start_angle, + int extend) { - MapInfo cur_map = (MapInfo) map_info; - MapInfoArc arc_ptr; + ZnMapInfo cur_map = (ZnMapInfo) map_info; + ZnMapInfoArc arc_ptr; if (cur_map && cur_map->arcs) { - arc_ptr = (MapInfoArc) ZnListAt(cur_map->arcs, index); + arc_ptr = (ZnMapInfoArc) ZnListAt(cur_map->arcs, index); if (arc_ptr) { arc_ptr->style = NOT_MARKED_STYLE(line_style); if (line_width == 1) { @@ -806,14 +810,14 @@ MapInfoReplaceArc(MapInfoId map_info, static void -MapInfoRemoveArc(MapInfoId map_info, - unsigned int index) +ZnMapInfoRemoveArc(ZnMapInfoId map_info, + unsigned int index) { - MapInfo cur_map = (MapInfo) map_info; - MapInfoArc arc_ptr; + ZnMapInfo cur_map = (ZnMapInfo) map_info; + ZnMapInfoArc arc_ptr; if (cur_map && cur_map->arcs) { - arc_ptr = (MapInfoArc) ZnListAt(cur_map->arcs, index); + arc_ptr = (ZnMapInfoArc) ZnListAt(cur_map->arcs, index); if (arc_ptr) { ZnListDelete(cur_map->arcs, index); } @@ -822,22 +826,22 @@ MapInfoRemoveArc(MapInfoId map_info, void -MapInfoGetArc(MapInfoId map_info, - unsigned int index, - ZnPtr *tag, - MapInfoLineStyle *line_style, - int *line_width, - int *center_x, - int *center_y, - unsigned int *radius, - int *start_angle, - int *extend) +ZnMapInfoGetArc(ZnMapInfoId map_info, + unsigned int index, + ZnPtr *tag, + ZnMapInfoLineStyle *line_style, + int *line_width, + int *center_x, + int *center_y, + int *radius, + int *start_angle, + int *extend) { - MapInfo cur_map = (MapInfo) map_info; - MapInfoArc arc_ptr; + ZnMapInfo cur_map = (ZnMapInfo) map_info; + ZnMapInfoArc arc_ptr; if (cur_map && cur_map->arcs) { - arc_ptr = (MapInfoArc) ZnListAt(cur_map->arcs, index); + arc_ptr = (ZnMapInfoArc) ZnListAt(cur_map->arcs, index); if (arc_ptr) { if (tag) { *tag = arc_ptr->tag; @@ -873,9 +877,9 @@ MapInfoGetArc(MapInfoId map_info, } unsigned int -MapInfoNumArcs(MapInfoId map_info) +ZnMapInfoNumArcs(ZnMapInfoId map_info) { - MapInfo cur_map = (MapInfo) map_info; + ZnMapInfo cur_map = (ZnMapInfo) map_info; if (cur_map && cur_map->arcs) { return ZnListSize(cur_map->arcs); @@ -886,68 +890,68 @@ MapInfoNumArcs(MapInfoId map_info) } static void -MapInfoScale(MapInfoId map_info, - double factor) +ZnMapInfoScale(ZnMapInfoId map_info, + double factor) { - MapInfo mp = (MapInfo) map_info; - int i, num; - MapInfoLine line_ptr; - MapInfoSymbol sym_ptr; - MapInfoText text_ptr; - MapInfoArc arc_ptr; + ZnMapInfo mp = (ZnMapInfo) map_info; + int i, num, int_factor = (int) factor; + ZnMapInfoLine line_ptr; + ZnMapInfoSymbol sym_ptr; + ZnMapInfoText text_ptr; + ZnMapInfoArc arc_ptr; if (mp && mp->lines) { num = ZnListSize(mp->lines); - line_ptr = (MapInfoLine) ZnListArray(mp->lines); + line_ptr = (ZnMapInfoLine) ZnListArray(mp->lines); for (i = 0; i < num; i++, line_ptr++) { - line_ptr->from.x *= factor; - line_ptr->from.y *= factor; - line_ptr->to.x *= factor; - line_ptr->to.y *= factor; + line_ptr->from.x *= int_factor; + line_ptr->from.y *= int_factor; + line_ptr->to.x *= int_factor; + line_ptr->to.y *= int_factor; } } if (mp && mp->symbols) { num = ZnListSize(mp->symbols); - sym_ptr = (MapInfoSymbol) ZnListArray(mp->symbols); + sym_ptr = (ZnMapInfoSymbol) ZnListArray(mp->symbols); for (i = 0; i < num; i++, sym_ptr++) { - sym_ptr->at.x *= factor; - sym_ptr->at.y *= factor; + sym_ptr->at.x *= int_factor; + sym_ptr->at.y *= int_factor; } } if (mp && mp->texts) { num = ZnListSize(mp->texts); - text_ptr = (MapInfoText) ZnListArray(mp->texts); + text_ptr = (ZnMapInfoText) ZnListArray(mp->texts); for (i = 0; i < num; i++, text_ptr++) { - text_ptr->at.x *= factor; - text_ptr->at.y *= factor; + text_ptr->at.x *= int_factor; + text_ptr->at.y *= int_factor; } } if (mp && mp->arcs) { num = ZnListSize(mp->arcs); - arc_ptr = (MapInfoArc) ZnListArray(mp->arcs); + arc_ptr = (ZnMapInfoArc) ZnListArray(mp->arcs); for (i = 0; i < num; i++, arc_ptr++) { - arc_ptr->center.x *= factor; - arc_ptr->center.y *= factor; - arc_ptr->radius *= factor; + arc_ptr->center.x *= int_factor; + arc_ptr->center.y *= int_factor; + arc_ptr->radius *= int_factor; } } } static void -MapInfoTranslate(MapInfoId map_info, - int x, - int y) +ZnMapInfoTranslate(ZnMapInfoId map_info, + int x, + int y) { - MapInfo mp = (MapInfo) map_info; + ZnMapInfo mp = (ZnMapInfo) map_info; int i, num; - MapInfoLine line_ptr; - MapInfoSymbol sym_ptr; - MapInfoText text_ptr; - MapInfoArc arc_ptr; + ZnMapInfoLine line_ptr; + ZnMapInfoSymbol sym_ptr; + ZnMapInfoText text_ptr; + ZnMapInfoArc arc_ptr; if (mp && mp->lines) { num = ZnListSize(mp->lines); - line_ptr = (MapInfoLine) ZnListArray(mp->lines); + line_ptr = (ZnMapInfoLine) ZnListArray(mp->lines); for (i = 0; i < num; i++, line_ptr++) { line_ptr->from.x += x; line_ptr->from.y += y; @@ -957,7 +961,7 @@ MapInfoTranslate(MapInfoId map_info, } if (mp && mp->symbols) { num = ZnListSize(mp->symbols); - sym_ptr = (MapInfoSymbol) ZnListArray(mp->symbols); + sym_ptr = (ZnMapInfoSymbol) ZnListArray(mp->symbols); for (i = 0; i < num; i++, sym_ptr++) { sym_ptr->at.x += x; sym_ptr->at.y += y; @@ -965,7 +969,7 @@ MapInfoTranslate(MapInfoId map_info, } if (mp && mp->texts) { num = ZnListSize(mp->texts); - text_ptr = (MapInfoText) ZnListArray(mp->texts); + text_ptr = (ZnMapInfoText) ZnListArray(mp->texts); for (i = 0; i < num; i++, text_ptr++) { text_ptr->at.x += x; text_ptr->at.y += y; @@ -973,7 +977,7 @@ MapInfoTranslate(MapInfoId map_info, } if (mp && mp->arcs) { num = ZnListSize(mp->arcs); - arc_ptr = (MapInfoArc) ZnListArray(mp->arcs); + arc_ptr = (ZnMapInfoArc) ZnListArray(mp->arcs); for (i = 0; i < num; i++, arc_ptr++) { arc_ptr->center.x += x; arc_ptr->center.y += y; @@ -1021,19 +1025,19 @@ ReorderVidomap(VideoMap *vm) { int loop; - vm->id = ntohi(vm->id); - vm->dashed = ntohi(vm->dashed); - vm->expanded = ntohi(vm->expanded); - vm->marked = ntohi(vm->marked); - vm->color = ntohi(vm->color); + vm->id = ntohi((unsigned int) vm->id); + vm->dashed = ntohi((unsigned int) vm->dashed); + vm->expanded = ntohi((unsigned int) vm->expanded); + vm->marked = ntohi((unsigned int) vm->marked); + vm->color = ntohi((unsigned int) vm->color); for (loop = 0; loop < 50; loop++) { - vm->elements[loop] = ntohi(vm->elements[loop]); - vm->x[loop] = ntohi(vm->x[loop]); - vm->y[loop] = ntohi(vm->y[loop]); - vm->symbol[loop] = ntohi(vm->symbol[loop]); - vm->text[loop] = ntohi(vm->text[loop]); + vm->elements[loop] = ntohi((unsigned int) vm->elements[loop]); + vm->x[loop] = ntohi((unsigned int) vm->x[loop]); + vm->y[loop] = ntohi((unsigned int) vm->y[loop]); + vm->symbol[loop] = ntohi((unsigned int) vm->symbol[loop]); + vm->text[loop] = ntohi((unsigned int) vm->text[loop]); } - vm->num_elements = ntohi(vm->num_elements); + vm->num_elements = ntohi((unsigned int) vm->num_elements); } /* @@ -1045,9 +1049,9 @@ ReorderVidomap(VideoMap *vm) */ static void -FillMap(MapInfoId map, VideoMap *vm) +FillMap(ZnMapInfoId map, VideoMap *vm) { - unsigned int i; + int i; ZnBool has_start_pos = False; int x_cur=0, y_cur=0; char ch; @@ -1059,103 +1063,103 @@ FillMap(MapInfoId map, VideoMap *vm) for (i = 0; i < vm->num_elements; i++) { switch(vm->elements[i] & 0xFF) { - case 'p': - case 'P': - if (in_text) { - in_text = in_mod_text = False; - while (text[text_size - 1] == ' ') { - text_size--; - } - text[text_size] = (char) 0; - MapInfoAddText(map, MapInfoNumTexts(map), NULL, MapInfoNormalText, - MapInfoLineSimple, text_x, text_y, text); + case 'p': + case 'P': + if (in_text) { + in_text = in_mod_text = False; + while (text[text_size - 1] == ' ') { + text_size--; } + text[text_size] = (char) 0; + ZnMapInfoAddText(map, ZnMapInfoNumTexts(map), NULL, ZnMapInfoNormalText, + ZnMapInfoLineSimple, text_x, text_y, text); + } - x_cur = (int) (short) vm->x[i]; - y_cur = (int) (short) vm->y[i]; - has_start_pos = True; + x_cur = (int) (short) vm->x[i]; + y_cur = (int) (short) vm->y[i]; + has_start_pos = True; - if (vm->symbol[i]) { - MapInfoAddSymbol(map, MapInfoNumSymbols(map), NULL, x_cur, y_cur, vm->symbol[i]); - } - break; + if (vm->symbol[i]) { + ZnMapInfoAddSymbol(map, ZnMapInfoNumSymbols(map), NULL, x_cur, y_cur, (char) vm->symbol[i]); + } + break; - /* We gather consecutive 'T' elements in a text. We skip - leading and trailing spaces and mod texts (between '@' - and now obsolete) */ + /* We gather consecutive 'T' elements in a text. We skip + leading and trailing spaces and mod texts (between '@' + and now obsolete) */ - case 't': - case 'T': - if (!has_start_pos) { - ZnWarning("Bogus map block, it has been discarded\n"); - return; - } + case 't': + case 'T': + if (!has_start_pos) { + ZnWarning("Bogus map block, it has been discarded\n"); + return; + } - if (in_text == False) { - ch = (char) vm->text[i] & 0xFF; - if (ch == '@') { - if (in_mod_text == True) { - in_mod_text = False; - } - else { - in_mod_text = True; - } + if (in_text == False) { + ch = (char) vm->text[i] & 0xFF; + if (ch == '@') { + if (in_mod_text == True) { + in_mod_text = False; } - else if (in_mod_text == False) { - in_text = True; - text_size = 0; - text_x = x_cur; - text_y = y_cur; - text[0] = (char) 0; + else { + in_mod_text = True; } } - if (in_text) { - text[text_size] = (char) vm->text[i] & 0xFF; - text_size++; + else if (in_mod_text == False) { + in_text = True; + text_size = 0; + text_x = x_cur; + text_y = y_cur; + text[0] = (char) 0; } - break; + } + if (in_text) { + text[text_size] = (char) vm->text[i] & 0xFF; + text_size++; + } + break; - case 'v': - case 'V': - if (!has_start_pos) { - ZnWarning("Bogus map block, it has been discarded\n"); - return; - } + case 'v': + case 'V': + if (!has_start_pos) { + ZnWarning("Bogus map block, it has been discarded\n"); + return; + } - if (in_text) { - in_text = in_mod_text = False; - while (text[text_size - 1] == ' ') { - text_size--; - } - text[text_size] = (char) 0; - MapInfoAddText(map, MapInfoNumTexts(map), NULL, MapInfoNormalText, - MapInfoLineSimple, text_x, text_y, text); + if (in_text) { + in_text = in_mod_text = False; + while (text[text_size - 1] == ' ') { + text_size--; } + text[text_size] = (char) 0; + ZnMapInfoAddText(map, ZnMapInfoNumTexts(map), NULL, ZnMapInfoNormalText, + ZnMapInfoLineSimple, text_x, text_y, text); + } - if (vm->dashed) { - MapInfoAddLine(map, MapInfoNumLines(map), NULL, MapInfoLineDashed, 0, + if (vm->dashed) { + ZnMapInfoAddLine(map, ZnMapInfoNumLines(map), NULL, ZnMapInfoLineDashed, 0, x_cur, y_cur, (int) (short) vm->x[i], (int) (short) vm->y[i]); - } - else if (vm->marked) { - MapInfoAddLine(map, MapInfoNumLines(map), NULL, MapInfoLineMarked, 0, + } + else if (vm->marked) { + ZnMapInfoAddLine(map, ZnMapInfoNumLines(map), NULL, ZnMapInfoLineMarked, 0, x_cur, y_cur, (int) (short) vm->x[i], (int) (short) vm->y[i]); - } - else { - MapInfoAddLine(map, MapInfoNumLines(map), NULL, MapInfoLineSimple, 0, + } + else { + ZnMapInfoAddLine(map, ZnMapInfoNumLines(map), NULL, ZnMapInfoLineSimple, 0, x_cur, y_cur, (int) (short) vm->x[i], (int) (short) vm->y[i]); - } + } - x_cur = (int) (short) vm->x[i]; - y_cur = (int) (short) vm->y[i]; + x_cur = (int) (short) vm->x[i]; + y_cur = (int) (short) vm->y[i]; - if (vm->symbol[i]) { - MapInfoAddSymbol(map, MapInfoNumSymbols(map), NULL, x_cur, y_cur, vm->symbol[i]); - } - break; + if (vm->symbol[i]) { + ZnMapInfoAddSymbol(map, ZnMapInfoNumSymbols(map), NULL, x_cur, y_cur, (char) vm->symbol[i]); } + break; + } } if (in_text) { @@ -1164,15 +1168,15 @@ FillMap(MapInfoId map, VideoMap *vm) text_size--; } text[text_size] = (char) 0; - MapInfoAddText(map, MapInfoNumTexts(map), NULL, MapInfoNormalText, - MapInfoLineSimple, text_x, text_y, text); + ZnMapInfoAddText(map, ZnMapInfoNumTexts(map), NULL, ZnMapInfoNormalText, + ZnMapInfoLineSimple, text_x, text_y, text); } } /* *----------------------------------------------------------------------- * - * MapInfoGetVideomap - Load a mapinfo with the content of a videomap + * ZnMapInfoGetVideomap - Load a mapinfo with the content of a videomap * file named 'filename'. Only the sub map 'index' will be loaded. * If successful a new mapinfo is returned, NULL otherwise. The * index is zero based. @@ -1180,35 +1184,39 @@ FillMap(MapInfoId map, VideoMap *vm) *----------------------------------------------------------------------- */ static int -MapInfoGetVideomap(MapInfoId map, - char *filename, - int index) +ZnMapInfoGetVideomap(ZnMapInfoId map, + char *filename, + unsigned int index) { VideoMap current_vm; FILE *file; - int cur_index, cur_id; + unsigned int cur_index, cur_id; /* Open the specified map file. */ +#ifdef _WIN32 + file = fopen(filename, "rb"); +#else file = fopen(filename, "r"); +#endif if (file == NULL) { - return ZN_ERROR; + return TCL_ERROR; } /* Load the map */ /* First skip the leading maps up to index. */ cur_index = 0; - if (fread(¤t_vm, sizeof(VideoMap), 1, file) < 0) { + if (fread(¤t_vm, sizeof(VideoMap), 1, file) != 1) { goto error; } - cur_id = ntohi(current_vm.id); + cur_id = ntohi((unsigned int) current_vm.id); while (cur_index != index) { - if (fread(¤t_vm, sizeof(VideoMap), 1, file) < 0) { + if (fread(¤t_vm, sizeof(VideoMap), 1, file) != 1) { goto error; } - if (cur_id != ntohi(current_vm.id)) { + if (cur_id != ntohi((unsigned int) current_vm.id)) { cur_index++; - cur_id = ntohi(current_vm.id); + cur_id = ntohi((unsigned int) current_vm.id); } }; @@ -1220,20 +1228,20 @@ MapInfoGetVideomap(MapInfoId map, goto error; } } - while ((cur_id == ntohi(current_vm.id)) && !feof(file)); + while ((cur_id == ntohi((unsigned int) current_vm.id)) && !feof(file)); fclose(file); - return ZN_OK; + return TCL_OK; -error: + error: fclose(file); - return ZN_ERROR; + return TCL_ERROR; } /* *----------------------------------------------------------------------- * - * MapInfoVideomapIds - Return the list of sub map ids contained in a + * ZnMapInfoVideomapIds - Return the list of sub map ids contained in a * videomap file. This makes it possible to iterate through such * a file without stumbling on an error, to know how much maps * are there and to sort them according to their ids. @@ -1242,33 +1250,40 @@ error: */ static ZnList -MapInfoVideomapIds(char *filename) +ZnMapInfoVideomapIds(char *filename) { FILE *file; VideoMap current_vm; - int cur_id; + unsigned int cur_id; ZnList ids; /* Open the specified map file. */ +#ifdef _WIN32 + file = fopen(filename, "rb"); +#else file = fopen(filename, "r"); +#endif if (file == NULL) { return NULL; } - if (fread(¤t_vm, sizeof(VideoMap), 1, file) < 0) { - goto error; + if (fread(¤t_vm, sizeof(VideoMap), 1, file) != 1) { + error: + fclose(file); + return NULL; } - cur_id = ntohi(current_vm.id); + cur_id = ntohi((unsigned int) current_vm.id); ids = ZnListNew(16, sizeof(int)); /*printf("id %d\n", cur_id);*/ ZnListAdd(ids, &cur_id, ZnListTail); do { - if (fread(¤t_vm, sizeof(VideoMap), 1, file) < 0) { + if (fread(¤t_vm, sizeof(VideoMap), 1, file) != 1) { + ZnListFree(ids); goto error; } - if (cur_id != ntohi(current_vm.id)) { - cur_id = ntohi(current_vm.id); + if (cur_id != ntohi((unsigned int) current_vm.id)) { + cur_id = ntohi((unsigned int) current_vm.id); /*printf("id %d\n", cur_id);*/ ZnListAdd(ids, &cur_id, ZnListTail); } @@ -1277,18 +1292,13 @@ MapInfoVideomapIds(char *filename) fclose(file); return ids; - -error: - fclose(file); - ZnListFree(ids); - return NULL; } /* *-------------------------------------------------------------------------- * - * MapInfo and Videomapstuff that should go eventually in its own file. + * ZnMapInfo and Videomapstuff that should go eventually in its own file. * *-------------------------------------------------------------------------- */ @@ -1298,17 +1308,17 @@ static ZnBool map_info_inited = False; typedef struct { ClientData client_data; - MapInfoChangeProc proc; -} MapInfoClient; + ZnMapInfoChangeProc proc; +} ZnMapInfoClient; typedef struct { - MapInfoId map_info; + ZnMapInfoId map_info; ZnBool deleted; ZnList clients; -} MapInfoMaster; +} ZnMapInfoMaster; static void -MapInfoInit() +ZnMapInfoInit() { Tcl_InitHashTable(&mapInfoTable, TCL_ONE_WORD_KEYS); @@ -1316,30 +1326,30 @@ MapInfoInit() } static void -UpdateMapInfoClients(MapInfoMaster *master) +UpdateMapInfoClients(ZnMapInfoMaster *master) { - int i, num; - MapInfoClient *client; + int i, num; + ZnMapInfoClient *client; num = ZnListSize(master->clients); - client = (MapInfoClient *) ZnListArray(master->clients); + client = (ZnMapInfoClient *) ZnListArray(master->clients); for (i = 0; i < num; i++, client++) { (*client->proc)(client->client_data, master->map_info); } } static int -ZnCreateMapInfo(Tcl_Interp *interp, +ZnCreateMapInfo(Tcl_Interp *interp __unused, char *name, - MapInfoId *map_info) + ZnMapInfoId *map_info) { - Tk_Uid uid = Tk_GetUid(name); - Tcl_HashEntry *entry; - int new; - MapInfoMaster *master; + Tk_Uid uid = Tk_GetUid(name); + Tcl_HashEntry *entry; + int new; + ZnMapInfoMaster *master; if (!map_info_inited) { - MapInfoInit(); + ZnMapInfoInit(); } entry = Tcl_CreateHashEntry(&mapInfoTable, uid, &new); @@ -1347,20 +1357,20 @@ ZnCreateMapInfo(Tcl_Interp *interp, /* * Empty the map info if it is not. */ - master = (MapInfoMaster *) Tcl_GetHashValue(entry); + master = (ZnMapInfoMaster *) Tcl_GetHashValue(entry); if (master->deleted) { master->deleted = False; } else { - MapInfoEmpty(master->map_info); + ZnMapInfoEmpty(master->map_info); UpdateMapInfoClients(master); } } else { - master = (MapInfoMaster *) ZnMalloc(sizeof(MapInfoMaster)); - master->map_info = MapInfoCreate(name); + master = (ZnMapInfoMaster *) ZnMalloc(sizeof(ZnMapInfoMaster)); + master->map_info = ZnMapInfoCreate(name); master->deleted = False; - master->clients = ZnListNew(1, sizeof(MapInfoClient)); + master->clients = ZnListNew(1, sizeof(ZnMapInfoClient)); Tcl_SetHashValue(entry, master); } if (map_info) { @@ -1370,43 +1380,43 @@ ZnCreateMapInfo(Tcl_Interp *interp, } static int -ZnDuplicateMapInfo(Tcl_Interp *interp, - char *name, - MapInfoId map_info) +ZnDuplicateZnMapInfo(Tcl_Interp *interp, + char *name, + ZnMapInfoId map_info) { - Tk_Uid uid = Tk_GetUid(name); - Tcl_HashEntry *entry; - int new; - MapInfoMaster *master; + Tk_Uid uid = Tk_GetUid(name); + Tcl_HashEntry *entry; + int new; + ZnMapInfoMaster *master; if (!map_info_inited) { - MapInfoInit(); + ZnMapInfoInit(); } entry = Tcl_CreateHashEntry(&mapInfoTable, uid, &new); if (!new) { Tcl_AppendResult(interp, "duplicate mapinfo \"", name, "\" already exists", NULL); - return ZN_ERROR; + return TCL_ERROR; } - master = (MapInfoMaster *) ZnMalloc(sizeof(MapInfoMaster)); - master->map_info = MapInfoDuplicate(map_info); + master = (ZnMapInfoMaster *) ZnMalloc(sizeof(ZnMapInfoMaster)); + master->map_info = ZnMapInfoDuplicate(map_info); master->deleted = False; - master->clients = ZnListNew(1, sizeof(MapInfoClient)); + master->clients = ZnListNew(1, sizeof(ZnMapInfoClient)); Tcl_SetHashValue(entry, master); return TCL_OK; } -static MapInfoMaster * +static ZnMapInfoMaster * LookupMapInfoMaster(Tcl_Interp *interp, char *name) { - Tk_Uid uid = Tk_GetUid(name); - Tcl_HashEntry *entry; - MapInfoMaster *master; + Tk_Uid uid = Tk_GetUid(name); + Tcl_HashEntry *entry; + ZnMapInfoMaster *master; if (!map_info_inited) { - MapInfoInit(); + ZnMapInfoInit(); } entry = Tcl_FindHashEntry(&mapInfoTable, uid); @@ -1415,7 +1425,7 @@ LookupMapInfoMaster(Tcl_Interp *interp, Tcl_AppendResult(interp, "mapinfo \"", name, "\" doesn't exist", NULL); return NULL; } - master = (MapInfoMaster *) Tcl_GetHashValue(entry); + master = (ZnMapInfoMaster *) Tcl_GetHashValue(entry); if (master->deleted) { goto mp_error; } @@ -1423,30 +1433,30 @@ LookupMapInfoMaster(Tcl_Interp *interp, } static int -ZnDeleteMapInfo(Tcl_Interp *interp, +ZnDeleteMapInfo(Tcl_Interp *interp __unused, char *name) { - MapInfoMaster *master; - Tk_Uid uid = Tk_GetUid(name); - Tcl_HashEntry *entry; + ZnMapInfoMaster *master; + Tk_Uid uid = Tk_GetUid(name); + Tcl_HashEntry *entry; if (!map_info_inited) { - MapInfoInit(); + ZnMapInfoInit(); } entry = Tcl_FindHashEntry(&mapInfoTable, uid); if (entry == NULL) { - return ZN_ERROR; + return TCL_ERROR; } - master = (MapInfoMaster *) Tcl_GetHashValue(entry); + master = (ZnMapInfoMaster *) Tcl_GetHashValue(entry); if (ZnListSize(master->clients) != 0) { master->deleted = True; - MapInfoEmpty(master->map_info); + ZnMapInfoEmpty(master->map_info); UpdateMapInfoClients(master); } else { - MapInfoDelete(master->map_info); + ZnMapInfoDelete(master->map_info); ZnListFree(master->clients); Tcl_DeleteHashEntry(entry); ZnFree(master); @@ -1455,14 +1465,14 @@ ZnDeleteMapInfo(Tcl_Interp *interp, return TCL_OK; } -MapInfoId +ZnMapInfoId ZnGetMapInfo(Tcl_Interp *interp, char *name, - MapInfoChangeProc proc, + ZnMapInfoChangeProc proc, ClientData client_data) { - MapInfoMaster *master; - MapInfoClient client; + ZnMapInfoMaster *master; + ZnMapInfoClient client; master = LookupMapInfoMaster(interp, name); if (master == NULL) { @@ -1476,26 +1486,26 @@ ZnGetMapInfo(Tcl_Interp *interp, } void -ZnFreeMapInfo(MapInfoId map_info, - MapInfoChangeProc proc, +ZnFreeMapInfo(ZnMapInfoId map_info, + ZnMapInfoChangeProc proc, ClientData client_data) { - Tk_Uid uid = Tk_GetUid(MapInfoName(map_info)); + Tk_Uid uid = Tk_GetUid(ZnMapInfoName(map_info)); Tcl_HashEntry *entry; - MapInfoMaster *master; - MapInfoClient *client; - int num, i; + ZnMapInfoMaster *master; + ZnMapInfoClient *client; + unsigned int num, i; if (!map_info_inited) { - MapInfoInit(); + ZnMapInfoInit(); } entry = Tcl_FindHashEntry(&mapInfoTable, uid); if (entry == NULL) { return; } - master = (MapInfoMaster *) Tcl_GetHashValue(entry); - client = (MapInfoClient *) ZnListArray(master->clients); + master = (ZnMapInfoMaster *) Tcl_GetHashValue(entry); + client = (ZnMapInfoClient *) ZnListArray(master->clients); num = ZnListSize(master->clients); for (i = 0; i < num; i++, client++) { if ((client->client_data == client_data) && @@ -1507,28 +1517,28 @@ ZnFreeMapInfo(MapInfoId map_info, } static void -ZnUpdateMapInfoClients(MapInfoId map_info) +ZnUpdateMapInfoClients(ZnMapInfoId map_info) { - Tk_Uid uid = Tk_GetUid(MapInfoName(map_info)); - Tcl_HashEntry *entry; - MapInfoMaster *master; + Tk_Uid uid = Tk_GetUid(ZnMapInfoName(map_info)); + Tcl_HashEntry *entry; + ZnMapInfoMaster *master; if (!map_info_inited) { - MapInfoInit(); + ZnMapInfoInit(); } entry = Tcl_FindHashEntry(&mapInfoTable, uid); if (entry == NULL) { return; } - master = (MapInfoMaster *) Tcl_GetHashValue(entry); + master = (ZnMapInfoMaster *) Tcl_GetHashValue(entry); UpdateMapInfoClients(master); } /* - * These arrays must be kept in sync with the MapInfoLineStyle - * and MapInfoTextStyle enums. + * These arrays must be kept in sync with the ZnMapInfoLineStyle + * and ZnMapInfoTextStyle enums. */ static char *line_style_strings[] = { "simple", @@ -1544,15 +1554,15 @@ static char *text_style_strings[] = { }; static char * -MapInfoLineStyleToString(MapInfoLineStyle line_style) +ZnMapInfoLineStyleToString(ZnMapInfoLineStyle line_style) { return line_style_strings[line_style]; } static int -MapInfoLineStyleFromString(Tcl_Interp *interp, - char *str, - MapInfoLineStyle *line_style) +ZnMapInfoLineStyleFromString(Tcl_Interp *interp, + char *str, + ZnMapInfoLineStyle *line_style) { int i, num = sizeof(line_style_strings)/sizeof(char *); @@ -1564,19 +1574,19 @@ MapInfoLineStyleFromString(Tcl_Interp *interp, } Tcl_AppendResult(interp, " incorrect mapinfo line style \"", str,"\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } static char * -MapInfoTextStyleToString(MapInfoTextStyle text_style) +ZnMapInfoTextStyleToString(ZnMapInfoTextStyle text_style) { return text_style_strings[text_style]; } static int -MapInfoTextStyleFromString(Tcl_Interp *interp, - char *str, - MapInfoTextStyle *text_style) +ZnMapInfoTextStyleFromString(Tcl_Interp *interp, + char *str, + ZnMapInfoTextStyle *text_style) { int i, num = sizeof(text_style_strings)/sizeof(char *); @@ -1588,23 +1598,31 @@ MapInfoTextStyleFromString(Tcl_Interp *interp, } Tcl_AppendResult(interp, " incorrect mapinfo text style \"", str,"\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } int -MapInfoObjCmd(ClientData client_data, - Tcl_Interp *interp, /* Current interpreter. */ - int argc, /* Number of arguments. */ - Tcl_Obj *CONST args[]) +ZnMapInfoObjCmd(ClientData client_data __unused, + Tcl_Interp *interp, /* Current interpreter. */ + int argc, /* Number of arguments. */ + Tcl_Obj *CONST args[]) { - int index, index2, result; - MapInfoMaster *master; - Tcl_Obj *l; + int index, index2, result; + ZnMapInfoMaster *master; + Tcl_Obj *l; +#ifdef PTK + static char *sub_cmd_strings[] = { +#else static CONST char *sub_cmd_strings[] = { +#endif "add", "count", "create", "delete", "duplicate", "get", "remove", "replace", "scale", "translate", NULL }; +#ifdef PTK + static char *e_type_strings[] = { +#else static CONST char *e_type_strings[] = { +#endif "arc", "line", "symbol", "text", NULL }; enum sub_cmds { @@ -1618,12 +1636,12 @@ MapInfoObjCmd(ClientData client_data, if (argc < 3) { Tcl_WrongNumArgs(interp, 1, args, "mapInfo/name subCmd ?args?"); - return ZN_ERROR; + return TCL_ERROR; } if (Tcl_GetIndexFromObj(interp, args[2], sub_cmd_strings, - "subCmd", 0, &index) != ZN_OK) { - return ZN_ERROR; + "subCmd", 0, &index) != TCL_OK) { + return TCL_ERROR; } result = TCL_OK; /*printf("mapinfo command \"%s\", argc=%d\n", @@ -1637,10 +1655,10 @@ MapInfoObjCmd(ClientData client_data, { if (argc != 3) { Tcl_WrongNumArgs(interp, 1, args, "name create"); - return ZN_ERROR; + return TCL_ERROR; } - if (ZnCreateMapInfo(interp, Tcl_GetString(args[1]), NULL) == ZN_ERROR) { - return ZN_ERROR; + if (ZnCreateMapInfo(interp, Tcl_GetString(args[1]), NULL) == TCL_ERROR) { + return TCL_ERROR; } } break; @@ -1651,10 +1669,10 @@ MapInfoObjCmd(ClientData client_data, { if (argc != 3) { Tcl_WrongNumArgs(interp, 1, args, "mapInfo delete"); - return ZN_ERROR; + return TCL_ERROR; } - if (ZnDeleteMapInfo(interp, Tcl_GetString(args[1])) == ZN_ERROR) { - return ZN_ERROR; + if (ZnDeleteMapInfo(interp, Tcl_GetString(args[1])) == TCL_ERROR) { + return TCL_ERROR; } } break; @@ -1665,15 +1683,15 @@ MapInfoObjCmd(ClientData client_data, { if (argc != 4) { Tcl_WrongNumArgs(interp, 1, args, "mapInfo duplicate name"); - return ZN_ERROR; + return TCL_ERROR; } master = LookupMapInfoMaster(interp, Tcl_GetString(args[1])); if (master == NULL) { - return ZN_ERROR; + return TCL_ERROR; } - if (ZnDuplicateMapInfo(interp, Tcl_GetString(args[3]), - master->map_info) == ZN_ERROR) { - return ZN_ERROR; + if (ZnDuplicateZnMapInfo(interp, Tcl_GetString(args[3]), + master->map_info) == TCL_ERROR) { + return TCL_ERROR; } } break; @@ -1683,33 +1701,30 @@ MapInfoObjCmd(ClientData client_data, case ZN_MI_ADD: case ZN_MI_REPLACE: { - MapInfoLineStyle line_style; - MapInfoTextStyle text_style; - int i, insert; - int coords[6]; - ZnBool add_cmd = (enum sub_cmds) index == ZN_MI_ADD; - int num_param = add_cmd ? 4 : 5; + ZnMapInfoLineStyle line_style; + ZnMapInfoTextStyle text_style; + int i, insert; + int coords[6]; + ZnBool add_cmd = (enum sub_cmds) index == ZN_MI_ADD; + int num_param = add_cmd ? 4 : 5; if (argc < num_param) { Tcl_WrongNumArgs(interp, 3, args, add_cmd ? "elementType ?args?" : "elementType index ?args?"); - return ZN_ERROR; + return TCL_ERROR; } master = LookupMapInfoMaster(interp, Tcl_GetString(args[1])); if (master == NULL) { - return ZN_ERROR; + return TCL_ERROR; } if (!add_cmd) { - if (Tcl_GetIntFromObj(interp, args[4], &insert) == ZN_ERROR) { - return ZN_ERROR; - } - if (insert < 0) { - insert = 0; + if (Tcl_GetIntFromObj(interp, args[4], &insert) == TCL_ERROR) { + return TCL_ERROR; } } if (Tcl_GetIndexFromObj(interp, args[3], e_type_strings, - "elementType", 0, &index2) != ZN_OK) { - return ZN_ERROR; + "elementType", 0, &index2) != TCL_OK) { + return TCL_ERROR; } switch ((enum e_types) index2) { case ZN_E_LINE: @@ -1717,27 +1732,27 @@ MapInfoObjCmd(ClientData client_data, if (argc != (num_param+6)) { Tcl_WrongNumArgs(interp, 4, args, add_cmd ? "style width x1 y1 x2 y2" : "index style width x1 y1 x2 y2"); - return ZN_ERROR; + return TCL_ERROR; } - if (MapInfoLineStyleFromString(interp, Tcl_GetString(args[num_param]), - &line_style) == ZN_ERROR) { - return ZN_ERROR; + if (ZnMapInfoLineStyleFromString(interp, Tcl_GetString(args[num_param]), + &line_style) == TCL_ERROR) { + return TCL_ERROR; } for (i = 0; i < 5; i++) { - if (Tcl_GetIntFromObj(interp, args[num_param+i+1], &coords[i]) == ZN_ERROR) { - return ZN_ERROR; + if (Tcl_GetIntFromObj(interp, args[num_param+i+1], &coords[i]) == TCL_ERROR) { + return TCL_ERROR; } } if (coords[0] < 0) { coords[0] = 0; } if (add_cmd) { - MapInfoAddLine(master->map_info, ZnListTail, NULL, line_style, - coords[0], coords[1], coords[2], coords[3], coords[4]); + ZnMapInfoAddLine(master->map_info, ZnListTail, NULL, line_style, + coords[0], coords[1], coords[2], coords[3], coords[4]); } else { - MapInfoReplaceLine(master->map_info, insert, NULL, line_style, - coords[0], coords[1], coords[2], coords[3], coords[4]); + ZnMapInfoReplaceLine(master->map_info, insert, NULL, line_style, + coords[0], coords[1], coords[2], coords[3], coords[4]); } } break; @@ -1746,23 +1761,23 @@ MapInfoObjCmd(ClientData client_data, if (argc != (num_param+3)) { Tcl_WrongNumArgs(interp, 4, args, add_cmd ? "x y intVal" : "index x y intVal"); - return ZN_ERROR; + return TCL_ERROR; } for (i = 0; i < 3; i++) { - if (Tcl_GetIntFromObj(interp, args[num_param+i], &coords[i]) == ZN_ERROR) { - return ZN_ERROR; + if (Tcl_GetIntFromObj(interp, args[num_param+i], &coords[i]) == TCL_ERROR) { + return TCL_ERROR; } } if (coords[2] < 0) { coords[2] = 0; } if (add_cmd) { - MapInfoAddSymbol(master->map_info, ZnListTail, NULL, coords[0], - coords[1], coords[2]); + ZnMapInfoAddSymbol(master->map_info, ZnListTail, NULL, coords[0], + coords[1], (char) coords[2]); } else { - MapInfoReplaceSymbol(master->map_info, insert, NULL, coords[0], - coords[1], coords[2]); + ZnMapInfoReplaceSymbol(master->map_info, insert, NULL, coords[0], + coords[1], (char) coords[2]); } } break; @@ -1771,32 +1786,32 @@ MapInfoObjCmd(ClientData client_data, if (argc != (num_param+5)) { Tcl_WrongNumArgs(interp, 4, args, add_cmd ? "textStyle lineStyle x y string" : "index textStyle lineStyle x y string"); - return ZN_ERROR; + return TCL_ERROR; } - if (MapInfoTextStyleFromString(interp, Tcl_GetString(args[num_param]), - &text_style) == ZN_ERROR) { - return ZN_ERROR; + if (ZnMapInfoTextStyleFromString(interp, Tcl_GetString(args[num_param]), + &text_style) == TCL_ERROR) { + return TCL_ERROR; } - if (MapInfoLineStyleFromString(interp, Tcl_GetString(args[num_param+1]), - &line_style) == ZN_ERROR) { - return ZN_ERROR; + if (ZnMapInfoLineStyleFromString(interp, Tcl_GetString(args[num_param+1]), + &line_style) == TCL_ERROR) { + return TCL_ERROR; } for (i = 0; i < 2; i++) { - if (Tcl_GetIntFromObj(interp, args[num_param+i+2], &coords[i]) == ZN_ERROR) { - return ZN_ERROR; + if (Tcl_GetIntFromObj(interp, args[num_param+i+2], &coords[i]) == TCL_ERROR) { + return TCL_ERROR; } } if (add_cmd) { - MapInfoAddText(master->map_info, ZnListTail, NULL, text_style, - line_style, coords[0], coords[1], - Tcl_GetString(args[num_param+4])); + ZnMapInfoAddText(master->map_info, ZnListTail, NULL, text_style, + line_style, coords[0], coords[1], + Tcl_GetString(args[num_param+4])); } else { /*printf("replace text ts %d ls %d %d %d %s\n", text_style, line_style, coords[0], coords[1], Tcl_GetString(args[num_param+4]));*/ - MapInfoReplaceText(master->map_info, insert, NULL, text_style, - line_style, coords[0], coords[1], - Tcl_GetString(args[num_param+4])); + ZnMapInfoReplaceText(master->map_info, insert, NULL, text_style, + line_style, coords[0], coords[1], + Tcl_GetString(args[num_param+4])); } } break; @@ -1805,28 +1820,27 @@ MapInfoObjCmd(ClientData client_data, if (argc != (num_param+7)) { Tcl_WrongNumArgs(interp, 4, args, add_cmd ? "style width cx cy radius start extent" : "index style width cx cy radius start extent"); - return ZN_ERROR; + return TCL_ERROR; } - if (MapInfoLineStyleFromString(interp, Tcl_GetString(args[num_param]), - &line_style) == ZN_ERROR) { - return ZN_ERROR; + if (ZnMapInfoLineStyleFromString(interp, Tcl_GetString(args[num_param]), + &line_style) == TCL_ERROR) { + return TCL_ERROR; } for (i = 0; i < 6; i++) { - if (Tcl_GetIntFromObj(interp, args[num_param+i+1], &coords[i]) == ZN_ERROR) { - return ZN_ERROR; + if (Tcl_GetIntFromObj(interp, args[num_param+i+1], &coords[i]) == TCL_ERROR) { + return TCL_ERROR; } } if (coords[0] < 0) { coords[0] = 0; } if (add_cmd) { - MapInfoAddArc(master->map_info, ZnListTail, NULL, line_style, - coords[0], coords[1], coords[2], coords[3], coords[4], - coords[5]); + ZnMapInfoAddArc(master->map_info, ZnListTail, NULL, line_style, coords[0], + coords[1], coords[2], (unsigned int) coords[3], coords[4], coords[5]); } else { - MapInfoReplaceArc(master->map_info, insert, NULL, line_style, coords[0], - coords[1], coords[2], coords[3], coords[4], coords[5]); + ZnMapInfoReplaceArc(master->map_info, insert, NULL, line_style, coords[0], + coords[1], coords[2], (unsigned int) coords[3], coords[4], coords[5]); } } break; @@ -1842,28 +1856,28 @@ MapInfoObjCmd(ClientData client_data, int count = 0; if (argc != 4) { Tcl_WrongNumArgs(interp, 1, args, "mapInfo count type"); - return ZN_ERROR; + return TCL_ERROR; } master = LookupMapInfoMaster(interp, Tcl_GetString(args[1])); if (master == NULL) { - return ZN_ERROR; + return TCL_ERROR; } if (Tcl_GetIndexFromObj(interp, args[3], e_type_strings, - "elementType", 0, &index2) != ZN_OK) { - return ZN_ERROR; + "elementType", 0, &index2) != TCL_OK) { + return TCL_ERROR; } switch ((enum e_types) index2) { case ZN_E_LINE: - count = MapInfoNumLines(master->map_info); + count = ZnMapInfoNumLines(master->map_info); break; case ZN_E_SYMBOL: - count = MapInfoNumSymbols(master->map_info); + count = ZnMapInfoNumSymbols(master->map_info); break; case ZN_E_TEXT: - count = MapInfoNumTexts(master->map_info); + count = ZnMapInfoNumTexts(master->map_info); break; case ZN_E_ARC: - count = MapInfoNumArcs(master->map_info); + count = ZnMapInfoNumArcs(master->map_info); break; } l = Tcl_NewIntObj(count); @@ -1875,35 +1889,35 @@ MapInfoObjCmd(ClientData client_data, */ case ZN_MI_GET: { - int insert; + int insert; if (argc != 5) { Tcl_WrongNumArgs(interp, 1, args, "mapInfo get type index"); - return ZN_ERROR; + return TCL_ERROR; } master = LookupMapInfoMaster(interp, Tcl_GetString(args[1])); if (master == NULL) { - return ZN_ERROR; + return TCL_ERROR; } - if (Tcl_GetIntFromObj(interp, args[4], &insert) == ZN_ERROR) { - return ZN_ERROR; + if (Tcl_GetIntFromObj(interp, args[4], &insert) == TCL_ERROR) { + return TCL_ERROR; } if (insert < 0) { insert = 0; } if (Tcl_GetIndexFromObj(interp, args[3], e_type_strings, - "elementType", 0, &index2) != ZN_OK) { - return ZN_ERROR; + "elementType", 0, &index2) != TCL_OK) { + return TCL_ERROR; } switch ((enum e_types) index2) { case ZN_E_LINE: { - MapInfoLineStyle line_style; + ZnMapInfoLineStyle line_style; int line_width; int x_from, y_from, x_to, y_to; - MapInfoGetLine(master->map_info, insert, NULL, &line_style, - &line_width, &x_from, &y_from, &x_to, &y_to); + ZnMapInfoGetLine(master->map_info, insert, NULL, &line_style, + &line_width, &x_from, &y_from, &x_to, &y_to); l = Tcl_GetObjResult(interp); - Tcl_ListObjAppendElement(interp, l, NewStringObj(MapInfoLineStyleToString(line_style))); + Tcl_ListObjAppendElement(interp, l, Tcl_NewStringObj(ZnMapInfoLineStyleToString(line_style), -1)); Tcl_ListObjAppendElement(interp, l, Tcl_NewIntObj(line_width)); Tcl_ListObjAppendElement(interp, l, Tcl_NewIntObj(x_from)); Tcl_ListObjAppendElement(interp, l, Tcl_NewIntObj(y_from)); @@ -1915,7 +1929,7 @@ MapInfoObjCmd(ClientData client_data, { int x, y; char symbol; - MapInfoGetSymbol(master->map_info, insert, NULL, &x, &y, &symbol); + ZnMapInfoGetSymbol(master->map_info, insert, NULL, &x, &y, &symbol); l = Tcl_GetObjResult(interp); Tcl_ListObjAppendElement(interp, l, Tcl_NewIntObj(x)); Tcl_ListObjAppendElement(interp, l, Tcl_NewIntObj(y)); @@ -1926,28 +1940,27 @@ MapInfoObjCmd(ClientData client_data, { int x, y; char *text; - MapInfoTextStyle text_style; - MapInfoLineStyle line_style; - MapInfoGetText(master->map_info, insert, NULL, &text_style, &line_style, - &x, &y, &text); + ZnMapInfoTextStyle text_style; + ZnMapInfoLineStyle line_style; + ZnMapInfoGetText(master->map_info, insert, NULL, &text_style, &line_style, + &x, &y, &text); l = Tcl_GetObjResult(interp); Tcl_ListObjAppendElement(interp, l, Tcl_NewIntObj(x)); Tcl_ListObjAppendElement(interp, l, Tcl_NewIntObj(y)); - Tcl_ListObjAppendElement(interp, l, NewStringObj(MapInfoTextStyleToString(text_style))); - Tcl_ListObjAppendElement(interp, l, NewStringObj(MapInfoLineStyleToString(line_style))); - Tcl_ListObjAppendElement(interp, l, NewStringObj(text)); + Tcl_ListObjAppendElement(interp, l, Tcl_NewStringObj(ZnMapInfoTextStyleToString(text_style), -1)); + Tcl_ListObjAppendElement(interp, l, Tcl_NewStringObj(ZnMapInfoLineStyleToString(line_style), -1)); + Tcl_ListObjAppendElement(interp, l, Tcl_NewStringObj(text, -1)); } break; case ZN_E_ARC: { - MapInfoLineStyle line_style; - int line_width; - int center_x, center_y, start, extent; - unsigned int radius; - MapInfoGetArc(master->map_info, insert, NULL, &line_style, &line_width, - ¢er_x, ¢er_y, &radius, &start, &extent); + ZnMapInfoLineStyle line_style; + int line_width, radius; + int center_x, center_y, start, extent; + ZnMapInfoGetArc(master->map_info, insert, NULL, &line_style, &line_width, + ¢er_x, ¢er_y, &radius, &start, &extent); l = Tcl_GetObjResult(interp); - Tcl_ListObjAppendElement(interp, l, NewStringObj(MapInfoLineStyleToString(line_style))); + Tcl_ListObjAppendElement(interp, l, Tcl_NewStringObj(ZnMapInfoLineStyleToString(line_style), -1)); Tcl_ListObjAppendElement(interp, l, Tcl_NewIntObj(line_width)); Tcl_ListObjAppendElement(interp, l, Tcl_NewIntObj(center_x)); Tcl_ListObjAppendElement(interp, l, Tcl_NewIntObj(center_y)); @@ -1964,37 +1977,37 @@ MapInfoObjCmd(ClientData client_data, */ case ZN_MI_REMOVE: { - int insert; + int insert; if (argc != 5) { Tcl_WrongNumArgs(interp, 1, args, "mapInfo remove type index"); - return ZN_ERROR; + return TCL_ERROR; } master = LookupMapInfoMaster(interp, Tcl_GetString(args[1])); if (master == NULL) { - return ZN_ERROR; + return TCL_ERROR; } - if (Tcl_GetIntFromObj(interp, args[4], &insert) == ZN_ERROR) { - return ZN_ERROR; + if (Tcl_GetIntFromObj(interp, args[4], &insert) == TCL_ERROR) { + return TCL_ERROR; } if (insert < 0) { insert = 0; } if (Tcl_GetIndexFromObj(interp, args[3], e_type_strings, - "elementType", 0, &index2) != ZN_OK) { - return ZN_ERROR; + "elementType", 0, &index2) != TCL_OK) { + return TCL_ERROR; } switch ((enum e_types) index2) { case ZN_E_LINE: - MapInfoRemoveLine(master->map_info, insert); + ZnMapInfoRemoveLine(master->map_info, insert); break; case ZN_E_SYMBOL: - MapInfoRemoveSymbol(master->map_info, insert); + ZnMapInfoRemoveSymbol(master->map_info, insert); break; case ZN_E_TEXT: - MapInfoRemoveText(master->map_info, insert); + ZnMapInfoRemoveText(master->map_info, insert); break; case ZN_E_ARC: - MapInfoRemoveArc(master->map_info, insert); + ZnMapInfoRemoveArc(master->map_info, insert); break; } UpdateMapInfoClients(master); @@ -2009,16 +2022,16 @@ MapInfoObjCmd(ClientData client_data, if (argc != 4) { Tcl_WrongNumArgs(interp, 1, args, "mapInfo scale factor"); - return ZN_ERROR; + return TCL_ERROR; } master = LookupMapInfoMaster(interp, Tcl_GetString(args[1])); if (master == NULL) { - return ZN_ERROR; + return TCL_ERROR; } - if (Tcl_GetDoubleFromObj(interp, args[3], &factor) == ZN_ERROR) { - return ZN_ERROR; + if (Tcl_GetDoubleFromObj(interp, args[3], &factor) == TCL_ERROR) { + return TCL_ERROR; } - MapInfoScale(master->map_info, factor); + ZnMapInfoScale(master->map_info, factor); UpdateMapInfoClients(master); } break; @@ -2031,19 +2044,19 @@ MapInfoObjCmd(ClientData client_data, if (argc != 5) { Tcl_WrongNumArgs(interp, 1, args, "mapInfo translate xAmount yAmount"); - return ZN_ERROR; + return TCL_ERROR; } master = LookupMapInfoMaster(interp, Tcl_GetString(args[1])); if (master == NULL) { - return ZN_ERROR; + return TCL_ERROR; } - if (Tcl_GetIntFromObj(interp, args[3], &x) == ZN_ERROR) { - return ZN_ERROR; + if (Tcl_GetIntFromObj(interp, args[3], &x) == TCL_ERROR) { + return TCL_ERROR; } - if (Tcl_GetIntFromObj(interp, args[4], &y) == ZN_ERROR) { - return ZN_ERROR; + if (Tcl_GetIntFromObj(interp, args[4], &y) == TCL_ERROR) { + return TCL_ERROR; } - MapInfoTranslate(master->map_info, x, y); + ZnMapInfoTranslate(master->map_info, x, y); UpdateMapInfoClients(master); } break; @@ -2062,16 +2075,20 @@ MapInfoObjCmd(ClientData client_data, *---------------------------------------------------------------------- */ int -VideomapObjCmd(ClientData client_data, - Tcl_Interp *interp, /* Current interpreter. */ - int argc, /* Number of arguments. */ - Tcl_Obj *CONST args[]) +ZnVideomapObjCmd(ClientData client_data __unused, + Tcl_Interp *interp, /* Current interpreter. */ + int argc, /* Number of arguments. */ + Tcl_Obj *CONST args[]) { ZnList ids; int index; int *id_array, id_num, i; Tcl_Obj *l; +#ifdef PTK + static char *sub_cmd_strings[] = { +#else static CONST char *sub_cmd_strings[] = { +#endif "ids", "load", NULL }; enum sub_cmds { @@ -2081,12 +2098,12 @@ VideomapObjCmd(ClientData client_data, if (argc < 2) { Tcl_WrongNumArgs(interp, 1, args, "?subCmd? filename $args?"); - return ZN_ERROR; + return TCL_ERROR; } if (Tcl_GetIndexFromObj(interp, args[1], sub_cmd_strings, - "subCmd", 0, &index) != ZN_OK) { - return ZN_ERROR; + "subCmd", 0, &index) != TCL_OK) { + return TCL_ERROR; } switch((enum sub_cmds) index) { @@ -2097,13 +2114,13 @@ VideomapObjCmd(ClientData client_data, { if (argc != 3) { Tcl_WrongNumArgs(interp, 1, args,"ids filename"); - return ZN_ERROR; + return TCL_ERROR; } - ids = MapInfoVideomapIds(Tcl_GetString(args[2])); + ids = ZnMapInfoVideomapIds(Tcl_GetString(args[2])); if (ids == NULL) { Tcl_AppendResult(interp, "unable to look at videomap file \"", Tcl_GetString(args[2]), "\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } id_array = (int *) ZnListArray(ids); id_num = ZnListSize(ids); @@ -2119,27 +2136,27 @@ VideomapObjCmd(ClientData client_data, */ case ZN_V_LOAD: { - MapInfoId map_info; - int insert; + ZnMapInfoId map_info; + int insert; if (argc != 5) { Tcl_WrongNumArgs(interp, 1, args, "load filename index mapInfo"); - return ZN_ERROR; + return TCL_ERROR; } - if (Tcl_GetIntFromObj(interp, args[3], &insert) == ZN_ERROR) { - return ZN_ERROR; + if (Tcl_GetIntFromObj(interp, args[3], &insert) == TCL_ERROR) { + return TCL_ERROR; } if (insert < 0) { insert = 0; } - if (ZnCreateMapInfo(interp, Tcl_GetString(args[4]), &map_info) == ZN_ERROR) { - return ZN_ERROR; + if (ZnCreateMapInfo(interp, Tcl_GetString(args[4]), &map_info) == TCL_ERROR) { + return TCL_ERROR; } - if (MapInfoGetVideomap(map_info, Tcl_GetString(args[2]), insert) == ZN_ERROR) { + if (ZnMapInfoGetVideomap(map_info, Tcl_GetString(args[2]), insert) == TCL_ERROR) { Tcl_AppendResult(interp, "unable to load videomap file \"", Tcl_GetString(args[2]), ":", Tcl_GetString(args[3]), "\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } ZnUpdateMapInfoClients(map_info); } diff --git a/generic/MapInfo.h b/generic/MapInfo.h index 26bb7d7..dd1b0cd 100644 --- a/generic/MapInfo.h +++ b/generic/MapInfo.h @@ -1,5 +1,5 @@ /* - * MapInfo.c -- Public include file for MapInfo interface. + * MapInfo.h -- Public include file for MapInfo interface. * * Authors : Patrick Lecoanet. * Creation date : @@ -47,58 +47,58 @@ extern "C" { *----------------------------------------------------------------------- */ -typedef void *MapInfoId; +typedef void *ZnMapInfoId; typedef enum { - MapInfoLineSimple, - MapInfoLineDashed, - MapInfoLineDotted, - MapInfoLineMixed, - MapInfoLineMarked -} MapInfoLineStyle; + ZnMapInfoLineSimple, + ZnMapInfoLineDashed, + ZnMapInfoLineDotted, + ZnMapInfoLineMixed, + ZnMapInfoLineMarked +} ZnMapInfoLineStyle; typedef enum { - MapInfoNormalText, - MapInfoUnderlinedText -} MapInfoTextStyle; + ZnMapInfoNormalText, + ZnMapInfoUnderlinedText +} ZnMapInfoTextStyle; typedef struct { int x, y; -} MapInfoPointStruct, *MapInfoPoint; +} ZnMapInfoPointStruct, *ZnMapInfoPoint; -void MapInfoGetLine(MapInfoId map_info, unsigned int index, ZnPtr *tag, - MapInfoLineStyle *line_style, int *line_width, - int *x_from, int *y_from, int *x_to, int *y_to); -unsigned int MapInfoNumLines(MapInfoId map_info); -void MapInfoGetMarks(MapInfoId map_info, unsigned int index, - MapInfoPoint *marks, unsigned int *num_marks); -void MapInfoGetSymbol(MapInfoId map_info, unsigned int index, ZnPtr *tag, - int *x, int *y, char *symbol); -unsigned int MapInfoNumSymbols(MapInfoId map_info); -void MapInfoGetText(MapInfoId map_info, unsigned int index, ZnPtr *tag, - MapInfoTextStyle *text_style, MapInfoLineStyle *line_style, - int *x, int *y, char **text); -unsigned int MapInfoNumTexts(MapInfoId map_info); -void MapInfoGetArc(MapInfoId map_info, unsigned int index, ZnPtr *tag, - MapInfoLineStyle *line_style, int *line_width, - int *center_x, int *center_y, unsigned int *radius, - int *start_angle, int *extend); -unsigned int MapInfoNumArcs(MapInfoId map_info); - - -typedef void (*MapInfoChangeProc)(ClientData client_data, MapInfoId map_info); - -MapInfoId ZnGetMapInfo(Tcl_Interp *interp, char *name, MapInfoChangeProc proc, - ClientData client_data); -void ZnFreeMapInfo(MapInfoId map_info, MapInfoChangeProc proc, +void ZnMapInfoGetLine(ZnMapInfoId map_info, unsigned int index, ZnPtr *tag, + ZnMapInfoLineStyle *line_style, int *line_width, + int *x_from, int *y_from, int *x_to, int *y_to); +unsigned int ZnMapInfoNumLines(ZnMapInfoId map_info); +void ZnMapInfoGetMarks(ZnMapInfoId map_info, unsigned int index, + ZnMapInfoPoint *marks, unsigned int *num_marks); +void ZnMapInfoGetSymbol(ZnMapInfoId map_info, unsigned int index, ZnPtr *tag, + int *x, int *y, char *symbol); +unsigned int ZnMapInfoNumSymbols(ZnMapInfoId map_info); +void ZnMapInfoGetText(ZnMapInfoId map_info, unsigned int index, ZnPtr *tag, + ZnMapInfoTextStyle *text_style, ZnMapInfoLineStyle *line_style, + int *x, int *y, char **text); +unsigned int ZnMapInfoNumTexts(ZnMapInfoId map_info); +void ZnMapInfoGetArc(ZnMapInfoId map_info, unsigned int index, ZnPtr *tag, + ZnMapInfoLineStyle *line_style, int *line_width, + int *center_x, int *center_y, int *radius, + int *start_angle, int *extend); +unsigned int ZnMapInfoNumArcs(ZnMapInfoId map_info); + + +typedef void (*ZnMapInfoChangeProc)(ClientData client_data, ZnMapInfoId map_info); + +ZnMapInfoId ZnGetMapInfo(Tcl_Interp *interp, char *name, ZnMapInfoChangeProc proc, + ClientData client_data); +void ZnFreeMapInfo(ZnMapInfoId map_info, ZnMapInfoChangeProc proc, ClientData client_data); -int MapInfoObjCmd(ClientData client_data, Tcl_Interp *interp, - int argc, Tcl_Obj *CONST args[]); -int VideomapObjCmd(ClientData client_data, Tcl_Interp *interp, - int argc, Tcl_Obj *CONST args[]); - +int ZnMapInfoObjCmd(ClientData client_data, Tcl_Interp *interp, + int argc, Tcl_Obj *CONST args[]); +int ZnVideomapObjCmd(ClientData client_data, Tcl_Interp *interp, + int argc, Tcl_Obj *CONST args[]); + #ifdef __CPLUSPLUS__ } diff --git a/generic/OverlapMan.c b/generic/OverlapMan.c index 75b5158..29f872f 100644 --- a/generic/OverlapMan.c +++ b/generic/OverlapMan.c @@ -40,14 +40,25 @@ static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ " #include "OverlapMan.h" +#include "malloc.h" +#include "private.h" #include #include -#include #include + #define signe(a) ((a) < (0) ? (-1) : (1)) #define abs(a) ((a) < (0) ? -(a) : (a)) +#ifndef M_PI +#define M_PI 3.14159265358979323846264338327 +#endif +#ifndef M_PI_2 +#define M_PI_2 1.57079632679489661923 +#endif +#ifndef M_PI_4 +#define M_PI_4 0.78539816339744830962 +#endif #define DegreesToRadian(angle) \ (M_PI * (double) (angle) / 180.0) #define RadianToDegrees(angle) \ @@ -249,11 +260,7 @@ AllocW(void *w, if (NBzincs == NBalloc_zincs) { NBalloc_zincs += NB_ALLOC; - /* - * Don't use ZnRealloc it creates dependencies on - * Tcl even if ptk is used instead. - */ - wr = (ZINCS *) realloc((void *) wr, sizeof(ZINCS) * NBalloc_zincs); + wr = realloc(wr, sizeof(ZINCS) * NBalloc_zincs); } for (i = NBzincs-1; i >= pos; i--) { @@ -330,9 +337,15 @@ OmInit() */ void OmRegister(void *w, - void *(*_fnext_track)(), - void (*_fset_label_angle)(), - void (*_fquery_label_pos)()) + void *(*_fnext_track)(void *, void *, + int *, int *, + int *, int *, + int *, int *, + int *, int *, + int *, int *), + void (*_fset_label_angle)(void *, void *, int, int), + void (*_fquery_label_pos)(void *, void *, int, + int *, int *, int *, int *) __unused) { int iw=0; BOOLEAN found=FALSE; @@ -428,12 +441,11 @@ FindPosId(int iw, *************************************************************************** */ static void -SetTrackInitValues(int iw, - int pos) +SetTrackInitValues() { info1.alpha = ProjToAngle(info1.vv_dx, info1.vv_dy) - 3.0 * M_PI_4; - info1.dx = (int) info1.rho * cos(info1.alpha); - info1.dy = (int) info1.rho * sin(info1.alpha); + info1.dx = (int) (info1.rho * cos(info1.alpha)); + info1.dy = (int) (info1.rho * sin(info1.alpha)); info1.alpha_point = 0.0; } @@ -477,8 +489,8 @@ PutTrackLoaded(int iw) */ if (wr[iw].NBinfos == wr[iw].NBalloc_infos) { wr[iw].NBalloc_infos += NB_ALLOC; - wr[iw].infos = (INFOS *) realloc((void *) wr[iw].infos, - sizeof(INFOS)*wr[iw].NBalloc_infos); + wr[iw].infos = realloc((void *) wr[iw].infos, + sizeof(INFOS)*wr[iw].NBalloc_infos); } if (pos < wr[iw].NBinfos) { @@ -539,8 +551,8 @@ ReadTracks(int iw) &trash1,&trash1,&trash1))) { info1.alpha = (ProjToAngle(info1.vv_dx, info1.vv_dy ) - M_PI_2 - DegreesToRadian(info1.theta)); - info1.dx = (int) info1.rho * cos(info1.alpha); - info1.dy = (int) info1.rho * sin(info1.alpha); + info1.dx = (int) (info1.rho * cos(info1.alpha)); + info1.dy = (int) (info1.rho * sin(info1.alpha)); info1.Refresh = TRUE; /* printf("OverlapMan(Om): ReadTracks id[%-10d], x[%4.4i], y[%4.4i], \ vv_dx[%4.4i], vv_dy[%4.4i], rho[%-3.3d], theta[%-3.3d], visi[%d]\n", @@ -586,7 +598,7 @@ OmSetNParam(char *name, /* parameter's name */ /* a parameter named name has been found */ if (OmParamAccess[accessid].rw) { memcpy(OmParamAccess[accessid].data, value, - OmParamAccess[accessid].size); + (unsigned int) OmParamAccess[accessid].size); status = 1; break; } @@ -619,7 +631,7 @@ OmGetNParam(char *name, /* parameter's name */ if (!strcmp(name, OmParamAccess[accessid].name)) { /* a parameter named "name" has been found */ memcpy(ptvalue, OmParamAccess[accessid].data, - OmParamAccess[accessid].size); + (unsigned int) OmParamAccess[accessid].size); status = 1; break; }; @@ -1045,7 +1057,7 @@ void OmProcessOverlap(void *zinc, int width, int height, - double scale) + double scale __unused) { double acceleration = 0.0; int ip, iw; diff --git a/generic/PostScript.c b/generic/PostScript.c index 71781f1..27923e2 100644 --- a/generic/PostScript.c +++ b/generic/PostScript.c @@ -35,10 +35,13 @@ ********************************************************************************** */ -#include +#ifndef _WIN32 + +#ifndef _WIN32 #include -#include #include +#endif +#include #include #include @@ -75,9 +78,9 @@ static char ps_prolog[] = ""; ********************************************************************************** */ static void -SetPostScriptFont(WidgetInfo *wi, - PostScriptInfo ps_info, - XFontStruct *fs) +SetPostScriptFont(ZnWInfo *wi __unused, + ZnPostScriptInfo ps_info __unused, + XFontStruct *fs __unused) { } @@ -90,31 +93,31 @@ SetPostScriptFont(WidgetInfo *wi, ********************************************************************************** */ static void -EmitPostScript(WidgetInfo *wi, - FILE *file, - char *title, - ZnBool landscape, - int color_mode, - int x_world, - int y_world, - int world_width, - int world_height, - int bbox_ox, - int bbox_oy, - int bbox_cx, - int bbox_cy) +EmitPostScript(ZnWInfo *wi, + FILE *file, + char *title, + ZnBool landscape, + int color_mode, + int x_world, + int y_world, + int world_width, + int world_height, + int bbox_ox, + int bbox_oy, + int bbox_cx, + int bbox_cy) { - PostScriptInfo ps_info; + ZnPostScriptInfo ps_info; /* double scale;*/ ZnBBox damaged_area, bbox; - Item current_item; + ZnItem current_item; struct passwd *pwd_info; time_t now; char *s; XFontStruct *fs; int i; - ps_info = (PostScriptInfo) ZnMalloc(sizeof(PostScriptStruct)); + ps_info = (ZnPostScriptInfo) ZnMalloc(sizeof(ZnPostScriptStruct)); ps_info->file = file; ps_info->title = title; ps_info->landscape = landscape; @@ -193,9 +196,9 @@ EmitPostScript(WidgetInfo *wi, */ current_item = ZnGroupTail(wi->top_group); while (current_item != ZN_NO_ITEM) { - if (ISSET(current_item->flags, VISIBLE_BIT)) { - IntersectBBox(&ps_info->page_bbox, ¤t_item->item_bounding_box, &bbox); - if (!IsEmptyBBox(&bbox)) { + if (ISSET(current_item->flags, ZN_VISIBLE_BIT)) { + ZnIntersectBBox(&ps_info->page_bbox, ¤t_item->item_bounding_box, &bbox); + if (!ZnIsEmptyBBox(&bbox)) { current_item->class->PostScript(current_item, ps_info); } } @@ -240,7 +243,8 @@ EmitPostScript(WidgetInfo *wi, ********************************************************************************** */ -struct _POSTSCRIPT_P POSTSCRIPT_P = { +struct _ZnPOSTSCRIPT ZnPOSTSCRIPT = { EmitPostScript, SetPostScriptFont }; +#endif /* _WIN32 */ diff --git a/generic/PostScript.h b/generic/PostScript.h index a7cd084..e62786a 100644 --- a/generic/PostScript.h +++ b/generic/PostScript.h @@ -33,6 +33,7 @@ #include "List.h" #include "Types.h" +#include "Geo.h" #include #include @@ -41,7 +42,7 @@ /* * PostScript information record -- */ -typedef struct _PostScriptStruct { +typedef struct _ZnPostScriptStruct { FILE *file; char *title; ZnBool landscape; @@ -52,10 +53,10 @@ typedef struct _PostScriptStruct { int world_height; ZnBBox page_bbox; ZnList fonts; -} PostScriptStruct, *PostScriptInfo; +} ZnPostScriptStruct, *ZnPostScriptInfo; -struct _WidgetInfo; +struct _ZnWInfo; /* @@ -66,15 +67,15 @@ struct _WidgetInfo; ********************************************************************************** */ -extern struct _POSTSCRIPT_P { - void (*EmitPostScript)(struct _WidgetInfo *wi, FILE *file, char *title, +extern struct _ZnPOSTSCRIPT { + void (*EmitPostScript)(struct _ZnWInfo *wi, FILE *file, char *title, ZnBool landscape, int color_mode, int x_world, int y_world, int world_width, int world_height, int bbox_ox, int bbox_oy, int bbox_cx, int bbox_cy); - void (*SetPostScriptFont)(struct _WidgetInfo *wi, PostScriptInfo ps_info, + void (*SetPostScriptFont)(struct _ZnWInfo *wi, ZnPostScriptInfo ps_info, XFontStruct *fs); -} POSTSCRIPT_P; +} ZnPOSTSCRIPT; #endif /* _PostScript_h */ diff --git a/generic/Rectangle.c b/generic/Rectangle.c index 2552884..9aa98cb 100644 --- a/generic/Rectangle.c +++ b/generic/Rectangle.c @@ -27,8 +27,6 @@ */ -#include - #include "Item.h" #include "Geo.h" #include "Draw.h" @@ -58,13 +56,13 @@ static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ " */ typedef struct _RectangleItemStruct { - ItemStruct header; + ZnItemStruct header; /* Public data */ ZnPoint coords[2]; unsigned short flags; - ReliefStyle relief; - LineStyle line_style; + ZnReliefStyle relief; + ZnLineStyle line_style; ZnDim line_width; ZnGradient *line_color; ZnImage fill_pattern; @@ -81,13 +79,13 @@ typedef struct _RectangleItemStruct { static ZnAttrConfig rect_attrs[] = { { ZN_CONFIG_BOOL, "-composealpha", NULL, - Tk_Offset(RectangleItemStruct, header.flags), COMPOSE_ALPHA_BIT, + Tk_Offset(RectangleItemStruct, header.flags), ZN_COMPOSE_ALPHA_BIT, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-composerotation", NULL, - Tk_Offset(RectangleItemStruct, header.flags), COMPOSE_ROTATION_BIT, + Tk_Offset(RectangleItemStruct, header.flags), ZN_COMPOSE_ROTATION_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_BOOL, "-composescale", NULL, - Tk_Offset(RectangleItemStruct, header.flags), COMPOSE_SCALE_BIT, + Tk_Offset(RectangleItemStruct, header.flags), ZN_COMPOSE_SCALE_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_GRADIENT, "-fillcolor", NULL, Tk_Offset(RectangleItemStruct, fill_color), 0, @@ -111,17 +109,17 @@ static ZnAttrConfig rect_attrs[] = { { ZN_CONFIG_RELIEF, "-relief", NULL, Tk_Offset(RectangleItemStruct, relief), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-sensitive", NULL, - Tk_Offset(RectangleItemStruct, header.flags), SENSITIVE_BIT, + Tk_Offset(RectangleItemStruct, header.flags), ZN_SENSITIVE_BIT, ZN_REPICK_FLAG, False }, { ZN_CONFIG_TAG_LIST, "-tags", NULL, Tk_Offset(RectangleItemStruct, header.tags), 0, 0, False }, { ZN_CONFIG_IMAGE, "-tile", NULL, Tk_Offset(RectangleItemStruct, tile), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-visible", NULL, - Tk_Offset(RectangleItemStruct, header.flags), VISIBLE_BIT, + Tk_Offset(RectangleItemStruct, 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 } }; @@ -134,37 +132,37 @@ static ZnAttrConfig rect_attrs[] = { ********************************************************************************** */ static int -Init(Item item, +Init(ZnItem item, int *argc, Tcl_Obj *CONST *args[]) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; RectangleItem rect = (RectangleItem) item; - int num_points; + unsigned int num_points; ZnPoint *points; rect->gradient = NULL; rect->grad_geo = NULL; /* 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_RECTANGLE_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; if (*argc < 1) { Tcl_AppendResult(wi->interp, " rectangle 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 != 2) { Tcl_AppendResult(wi->interp, " malformed rectangle coords", NULL); - return ZN_ERROR; + return TCL_ERROR; }; rect->coords[0] = points[0]; rect->coords[1] = points[1]; @@ -172,8 +170,8 @@ Init(Item item, (*argc)--; CLEAR(rect->flags, FILLED_BIT); - rect->relief = RELIEF_FLAT; - rect->line_style = LINE_SIMPLE; + rect->relief = ZN_RELIEF_FLAT; + rect->line_style = ZN_LINE_SIMPLE; rect->line_width = 1; rect->line_pattern = ZnUnspecifiedImage; rect->tile = ZnUnspecifiedImage; @@ -181,7 +179,7 @@ Init(Item item, rect->line_color = ZnGetGradientByValue(wi->fore_color); rect->fill_color = ZnGetGradientByValue(wi->fore_color); - return ZN_OK; + return TCL_OK; } @@ -193,18 +191,13 @@ Init(Item item, ********************************************************************************** */ static void -Clone(Item item) +Clone(ZnItem item) { RectangleItem rect = (RectangleItem) item; if (rect->gradient) { rect->gradient = ZnGetGradientByValue(rect->gradient); } - if (rect->grad_geo) { - ZnPoint *grad_geo = ZnMalloc(4*sizeof(ZnPoint)); - memcpy(grad_geo, rect->grad_geo, 4*sizeof(ZnPoint)); - rect->grad_geo = grad_geo; - } if (rect->tile != ZnUnspecifiedImage) { rect->tile = ZnGetImageByValue(rect->tile); } @@ -216,6 +209,7 @@ Clone(Item item) } rect->line_color = ZnGetGradientByValue(rect->line_color); rect->fill_color = ZnGetGradientByValue(rect->fill_color); + rect->grad_geo = NULL; } @@ -227,7 +221,7 @@ Clone(Item item) ********************************************************************************** */ static void -Destroy(Item item) +Destroy(ZnItem item) { RectangleItem rect = (RectangleItem) item; @@ -262,30 +256,30 @@ Destroy(Item item) ********************************************************************************** */ static int -Configure(Item item, +Configure(ZnItem item, int argc, Tcl_Obj *CONST argv[], int *flags) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; RectangleItem rect = (RectangleItem) item; - int status = ZN_OK; + int status = TCL_OK; XColor *color; - int alpha; + unsigned short alpha; status = ZnConfigureAttributes(wi, item, rect_attrs, argc, argv, flags); if (rect->gradient && - (ISSET(*flags, ZN_BORDER_FLAG) || (rect->relief == RELIEF_FLAT))) { + (ISSET(*flags, ZN_BORDER_FLAG) || (rect->relief == ZN_RELIEF_FLAT))) { ZnFreeGradient(rect->gradient); rect->gradient = NULL; } - if ((rect->relief != RELIEF_FLAT) && !rect->gradient) { + if ((rect->relief != ZN_RELIEF_FLAT) && !rect->gradient) { color = ZnGetGradientColor(rect->line_color, 51.0, &alpha); rect->gradient = ZnGetReliefGradient(wi->interp, wi->win, - ZnNameOfColor(color), alpha); + Tk_NameOfColor(color), alpha); if (rect->gradient == NULL) { - status = ZN_ERROR; + status = TCL_ERROR; } } @@ -301,15 +295,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, rect_attrs, argv[0]) == ZN_ERROR) { - return ZN_ERROR; + if (ZnQueryAttribute(item->wi, item, rect_attrs, argv[0]) == TCL_ERROR) { + return TCL_ERROR; } - return ZN_OK; + return TCL_OK; } @@ -321,17 +315,17 @@ Query(Item item, ********************************************************************************** */ static void -ComputeCoordinates(Item item, - ZnBool force) +ComputeCoordinates(ZnItem item, + ZnBool force __unused) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; RectangleItem rect = (RectangleItem) item; ZnPoint p[4]; int i; ZnBool aligned; ZnDim delta; - ResetBBox(&item->item_bounding_box); + ZnResetBBox(&item->item_bounding_box); if (!rect->line_width && ISCLEAR(rect->flags, FILLED_BIT)) { return; } @@ -344,15 +338,15 @@ ComputeCoordinates(Item item, p[3].y = p[2].y; ZnTransformPoints(wi->current_transfo, p, rect->dev, 4); for (i = 0; i < 4; i++) { - rect->dev[i].x = REAL_TO_INT(rect->dev[i].x); - rect->dev[i].y = REAL_TO_INT(rect->dev[i].y); + rect->dev[i].x = ZnNearestInt(rect->dev[i].x); + rect->dev[i].y = ZnNearestInt(rect->dev[i].y); } /* * Add all points to the bounding box. Then expand by the line * width to account for mitered corners. This is an overestimate. */ - AddPointsToBBox(&item->item_bounding_box, rect->dev, 4); + ZnAddPointsToBBox(&item->item_bounding_box, rect->dev, 4); if (rect->line_width > 0) { item->item_bounding_box.orig.x -= rect->line_width; item->item_bounding_box.orig.y -= rect->line_width; @@ -372,7 +366,7 @@ ComputeCoordinates(Item item, aligned |= delta < X_PRECISION_LIMIT; ASSIGN(rect->flags, ALIGNED_BIT, aligned); -#ifdef GLX +#ifdef GL /* * If there is an axial gradient with an unaligned axis * compute the bbox in the coordinate system defined @@ -388,8 +382,8 @@ ComputeCoordinates(Item item, if (!rect->grad_geo) { rect->grad_geo = ZnMalloc(6*sizeof(ZnPoint)); } - POLY_CONTOUR1(&shape, p, 4, False); - ZnComputeAxialGradient(wi, &shape, angle, rect->grad_geo); + ZnPolyContour1(&shape, p, 4, False); + ZnComputeAxialGradient(wi, &shape, (ZnReal) angle, rect->grad_geo); } else { goto free_ggeo; @@ -407,14 +401,14 @@ ComputeCoordinates(Item item, pp[1].y = pp[0].y; pp[3].x = pp[0].x; pp[3].y = pp[2].y; - POLY_CONTOUR1(&shape, pp, 4, False); + ZnPolyContour1(&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(6*sizeof(ZnPoint)); } - POLY_CONTOUR1(&shape, rect->coords, 2, False); + ZnPolyContour1(&shape, rect->coords, 2, False); ZnComputePathGradient(wi, &shape, &rect->fill_color->g.p, rect->grad_geo); } } @@ -439,7 +433,7 @@ ComputeCoordinates(Item item, ********************************************************************************** */ static int -ToArea(Item item, +ToArea(ZnItem item, ZnToArea ta) { RectangleItem rect = (RectangleItem) item; @@ -449,7 +443,7 @@ ToArea(Item item, result = -1; if (ISSET(rect->flags, FILLED_BIT)) { - result = PolygonInBBox(rect->dev, 4, area, NULL); + result = ZnPolygonInBBox(rect->dev, 4, area, NULL); } else if (rect->line_width > 0) { int i; @@ -459,8 +453,8 @@ ToArea(Item item, pts[i] = rect->dev[i]; } pts[4] = pts[0]; - result = PolylineInBBox(pts, 5, rect->line_width, - CapProjecting, JoinMiter, area); + result = ZnPolylineInBBox(pts, 5, rect->line_width, + CapProjecting, JoinMiter, area); } return result; @@ -475,37 +469,37 @@ ToArea(Item item, ********************************************************************************** */ static void -Draw(Item item) +Draw(ZnItem item) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; RectangleItem rect = (RectangleItem) item; XGCValues values; - int i, gc_mask; + unsigned int i, gc_mask; XRectangle r; XPoint xp[5]; if (ISSET(rect->flags, ALIGNED_BIT)) { if (rect->dev[0].x < rect->dev[2].x) { - r.x = rect->dev[0].x; - r.width = rect->dev[2].x - r.x; + r.x = (int) rect->dev[0].x; + r.width = ((int) rect->dev[2].x) - r.x; } else { - r.x = rect->dev[2].x; - r.width = rect->dev[0].x - r.x; + r.x = (int) rect->dev[2].x; + r.width = ((int) rect->dev[0].x) - r.x; } if (rect->dev[0].y < rect->dev[2].y) { - r.y = rect->dev[0].y; - r.height = rect->dev[2].y - r.y; + r.y = (int) rect->dev[0].y; + r.height = ((int) rect->dev[2].y) - r.y; } else { - r.y = rect->dev[2].y; - r.height = rect->dev[0].y - r.y; + r.y = (int) rect->dev[2].y; + r.height = ((int) rect->dev[0].y) - r.y; } } else { for (i = 0; i < 4; i++) { - xp[i].x = rect->dev[i].x; - xp[i].y = rect->dev[i].y; + xp[i].x = (int) rect->dev[i].x; + xp[i].y = (int) rect->dev[i].y; } xp[i] = xp[0]; } @@ -517,7 +511,7 @@ Draw(Item item) values.foreground = ZnPixel(ZnGetGradientColor(rect->fill_color, 0.0, NULL)); if (rect->tile != ZnUnspecifiedImage) { /* Fill tiled */ values.fill_style = FillTiled; - values.tile = ZnImagePixmap(rect->tile, NULL); + values.tile = ZnImagePixmap(rect->tile); if (ISSET(rect->flags, ALIGNED_BIT)) { values.ts_x_origin = (int) r.x; values.ts_y_origin = (int) r.y; @@ -531,7 +525,7 @@ Draw(Item item) } else if (rect->fill_pattern != ZnUnspecifiedImage) { /* Fill stippled */ values.fill_style = FillStippled; - values.stipple = ZnImagePixmap(rect->fill_pattern, NULL); + values.stipple = ZnImagePixmap(rect->fill_pattern); if (ISSET(rect->flags, ALIGNED_BIT)) { values.ts_x_origin = (int) r.x; values.ts_y_origin = (int) r.y; @@ -559,7 +553,7 @@ Draw(Item item) /* Draw the outline */ if (rect->line_width) { - if (rect->relief != RELIEF_FLAT) { + if (rect->relief != ZN_RELIEF_FLAT) { if (ISSET(rect->flags, ALIGNED_BIT)) { ZnDrawRectangleRelief(wi, rect->relief, rect->gradient, &r, rect->line_width); @@ -578,8 +572,8 @@ Draw(Item item) else { ZnSetLineStyle(wi, rect->line_style); gc_mask = GCFillStyle|GCLineWidth|GCForeground|GCJoinStyle; - values.foreground = ZnPixel(ZnGetGradientColor(rect->line_color, 0, NULL)); - values.line_width = (rect->line_width == 1) ? 0 : rect->line_width; + values.foreground = ZnPixel(ZnGetGradientColor(rect->line_color, 0.0, NULL)); + values.line_width = (rect->line_width == 1) ? 0 : (int) rect->line_width; values.join_style = JoinMiter; if (ISCLEAR(rect->flags, ALIGNED_BIT)) { gc_mask |= GCCapStyle; @@ -591,7 +585,7 @@ Draw(Item item) } else { values.fill_style = FillStippled; - values.stipple = ZnImagePixmap(rect->line_pattern, NULL); + values.stipple = ZnImagePixmap(rect->line_pattern); gc_mask |= GCStipple; XChangeGC(wi->dpy, wi->gc, gc_mask, &values); } @@ -614,30 +608,31 @@ Draw(Item item) * ********************************************************************************** */ -#ifdef GLX +#ifdef GL static void RectRenderCB(void *closure) { RectangleItem rect = (RectangleItem) closure; glBegin(GL_TRIANGLE_STRIP); - glVertex2f(rect->dev[0].x, rect->dev[0].y); - glVertex2f(rect->dev[3].x, rect->dev[3].y); - glVertex2f(rect->dev[1].x, rect->dev[1].y); - glVertex2f(rect->dev[2].x, rect->dev[2].y); + glVertex2d(rect->dev[0].x, rect->dev[0].y); + glVertex2d(rect->dev[3].x, rect->dev[3].y); + glVertex2d(rect->dev[1].x, rect->dev[1].y); + glVertex2d(rect->dev[2].x, rect->dev[2].y); glEnd(); } #endif +#ifdef GL static void -Render(Item item) +Render(ZnItem item) { -#ifdef GLX - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; RectangleItem rect = (RectangleItem) item; XColor *color; - int i, alpha; - + int i; + unsigned short alpha; + #ifdef GL_LIST if (!item->gl_list) { item->gl_list = glGenLists(1); @@ -650,7 +645,7 @@ Render(Item item) ZnBool fast = (rect->fill_color->type == ZN_AXIAL_GRADIENT) && !rect->grad_geo; ZnPoly poly; - POLY_CONTOUR1(&poly, rect->dev, 4, False); + ZnPolyContour1(&poly, rect->dev, 4, False); ZnRenderGradient(wi, rect->fill_color, fast ? NULL: RectRenderCB, rect, fast ? rect->dev : rect->grad_geo, &poly); @@ -666,7 +661,7 @@ Render(Item item) * Setup polygon stippling. */ glEnable(GL_POLYGON_STIPPLE); - glPolygonStipple(ZnImagePattern(rect->fill_pattern, NULL)); + glPolygonStipple(ZnImageMask(rect->fill_pattern, NULL)); } color = ZnGetGradientColor(rect->fill_color, 0.0, &alpha); alpha = ZnComposeAlpha(alpha, wi->alpha); @@ -684,7 +679,7 @@ Render(Item item) p[4-i].y = rect->dev[i].y; } p[0] = p[4]; - if (rect->relief != RELIEF_FLAT) { + if (rect->relief != ZN_RELIEF_FLAT) { ZnRenderPolygonRelief(wi, rect->relief, rect->gradient, False, p, 5, rect->line_width); } @@ -700,9 +695,14 @@ Render(Item item) glCallList(item->gl_list); #endif -#endif } - +#else +static void +Render(ZnItem item __unused) +{ +} +#endif + /* ********************************************************************************** @@ -712,10 +712,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)); } @@ -728,14 +728,14 @@ IsSensitive(Item item, ********************************************************************************** */ static double -Pick(Item item, +Pick(ZnItem item, ZnPick ps) { RectangleItem rect = (RectangleItem) item; double best_dist; ZnPoint *p = ps->point; - best_dist = PolygonToPointDist(rect->dev, 4, p); + best_dist = ZnPolygonToPointDist(rect->dev, 4, p); if (ISSET(rect->flags, FILLED_BIT)) { if (best_dist <= 0.0) { @@ -753,8 +753,8 @@ Pick(Item item, pts[i] = rect->dev[i]; } pts[4] = pts[0]; - dist = PolylineToPointDist(pts, 5, rect->line_width, - CapProjecting, JoinMiter, p); + dist = ZnPolylineToPointDist(pts, 5, rect->line_width, + CapProjecting, JoinMiter, p); if (dist <= 0.0) { return 0.0; } @@ -773,8 +773,8 @@ Pick(Item item, ********************************************************************************** */ static void -PostScript(Item item, - PostScriptInfo ps_info) +PostScript(ZnItem item __unused, + ZnPostScriptInfo ps_info __unused) { } @@ -784,12 +784,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) { RectangleItem rect = (RectangleItem) item; @@ -798,7 +798,7 @@ GetClipVertices(Item item, if (ISSET(rect->flags, ALIGNED_BIT)) { ZnListAssertSize(item->wi->work_pts, 2); points = (ZnPoint *) ZnListArray(item->wi->work_pts); - TRI_STRIP1(tristrip, points, 2, False); + ZnTriStrip1(tristrip, points, 2, False); tristrip->strips[0].fan = False; if (rect->dev[0].x < rect->dev[2].x) { @@ -819,7 +819,7 @@ GetClipVertices(Item item, } } else { - TRI_STRIP1(tristrip, rect->dev, 4, False); + ZnTriStrip1(tristrip, rect->dev, 4, False); } return ISSET(rect->flags, ALIGNED_BIT); @@ -835,36 +835,36 @@ GetClipVertices(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) { RectangleItem rect = (RectangleItem) item; - if ((cmd == COORDS_ADD) || (cmd == COORDS_ADD_LAST) || (cmd == COORDS_REMOVE)) { + if ((cmd == ZN_COORDS_ADD) || (cmd == ZN_COORDS_ADD_LAST) || (cmd == ZN_COORDS_REMOVE)) { Tcl_AppendResult(item->wi->interp, " rectangles can't add or remove vertices", NULL); - return ZN_ERROR; + return TCL_ERROR; } - else if (cmd == COORDS_REPLACE_ALL) { + else if (cmd == ZN_COORDS_REPLACE_ALL) { if (*num_pts != 2) { Tcl_AppendResult(item->wi->interp, " coords command need 2 points on rectangles", NULL); - return ZN_ERROR; + return TCL_ERROR; } rect->coords[0] = (*pts)[0]; rect->coords[1] = (*pts)[1]; - ITEM.Invalidate(item, ZN_COORDS_FLAG); + ZnITEM.Invalidate(item, ZN_COORDS_FLAG); } - else if (cmd == COORDS_REPLACE) { + else if (cmd == ZN_COORDS_REPLACE) { if (*num_pts < 1) { Tcl_AppendResult(item->wi->interp, " coords command need at least 1 point", NULL); - return ZN_ERROR; + return TCL_ERROR; } if (index < 0) { index += 2; @@ -873,16 +873,16 @@ Coords(Item item, range_err: Tcl_AppendResult(item->wi->interp, " incorrect coord index, should be between -2 and 1", NULL); - return ZN_ERROR; + return TCL_ERROR; } rect->coords[index] = (*pts)[0]; - ITEM.Invalidate(item, ZN_COORDS_FLAG); + ZnITEM.Invalidate(item, ZN_COORDS_FLAG); } - else if (cmd == COORDS_READ_ALL) { + else if (cmd == ZN_COORDS_READ_ALL) { *num_pts = 2; *pts = rect->coords; } - else if (cmd == COORDS_READ) { + else if (cmd == ZN_COORDS_READ) { if (index < 0) { index += 2; } @@ -893,7 +893,7 @@ Coords(Item item, *pts = &rect->coords[index]; } - return ZN_OK; + return TCL_OK; } @@ -905,16 +905,16 @@ Coords(Item item, ********************************************************************************** */ static void -GetAnchor(Item item, - ZnAnchor anchor, +GetAnchor(ZnItem item, + Tk_Anchor anchor, ZnPoint *p) { ZnBBox *bbox = &item->item_bounding_box; - Origin2Anchor(&bbox->orig, - bbox->corner.x - bbox->orig.x, - bbox->corner.y - bbox->orig.y, - anchor, p); + ZnOrigin2Anchor(&bbox->orig, + bbox->corner.x - bbox->orig.x, + bbox->corner.y - bbox->orig.y, + anchor, p); } @@ -924,8 +924,8 @@ GetAnchor(Item item, * Exported functions struct -- * ********************************************************************************** - */ -static ItemClassStruct RECTANGLE_ITEM_CLASS = { + */ +static ZnItemClassStruct RECTANGLE_ITEM_CLASS = { sizeof(RectangleItemStruct), 0, /* num_parts */ False, /* has_anchors */ diff --git a/generic/Reticle.c b/generic/Reticle.c index 9fa9616..4855499 100644 --- a/generic/Reticle.c +++ b/generic/Reticle.c @@ -41,6 +41,17 @@ static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ " /* + * Draw as many circles as visible. + */ +#define ANY_CIRCLES -1 + +/* + * Some default values. + */ +#define DEFAULT_RETICLE_STEP_SIZE 80 +#define DEFAULT_RETICLE_PERIOD 5 + +/* ********************************************************************************** * * Specific Reticle item record @@ -49,7 +60,7 @@ static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ " */ typedef struct _ReticleItemStruct { - ItemStruct header; + ZnItemStruct header; /* Public data */ ZnPoint pos; /* Origin world coordinates */ @@ -59,8 +70,8 @@ typedef struct _ReticleItemStruct { ZnDim step_size; /* step world size */ int period; /* bright circle period */ int num_circles; /* num cercles max */ - LineStyle line_style; /* circles lines styles */ - LineStyle bright_line_style; + ZnLineStyle line_style; /* circles lines styles */ + ZnLineStyle bright_line_style; /* Private data */ ZnPoint dev; /* item device coordinate */ @@ -75,13 +86,13 @@ static ZnAttrConfig reticle_attrs[] = { { ZN_CONFIG_LINE_STYLE, "-brightlinestyle", NULL, Tk_Offset(ReticleItemStruct, bright_line_style), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-composealpha", NULL, - Tk_Offset(ReticleItemStruct, header.flags), COMPOSE_ALPHA_BIT, + Tk_Offset(ReticleItemStruct, header.flags), ZN_COMPOSE_ALPHA_BIT, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-composerotation", NULL, - Tk_Offset(ReticleItemStruct, header.flags), COMPOSE_ROTATION_BIT, + Tk_Offset(ReticleItemStruct, header.flags), ZN_COMPOSE_ROTATION_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_BOOL, "-composescale", NULL, - Tk_Offset(ReticleItemStruct, header.flags), COMPOSE_SCALE_BIT, + Tk_Offset(ReticleItemStruct, header.flags), ZN_COMPOSE_SCALE_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_DIM, "-stepsize", NULL, Tk_Offset(ReticleItemStruct, step_size), 0, @@ -105,15 +116,15 @@ static ZnAttrConfig reticle_attrs[] = { Tk_Offset(ReticleItemStruct, header.priority), 0, ZN_DRAW_FLAG|ZN_REPICK_FLAG, False }, { ZN_CONFIG_BOOL, "-sensitive", NULL, - Tk_Offset(ReticleItemStruct, header.flags), SENSITIVE_BIT, + Tk_Offset(ReticleItemStruct, header.flags), ZN_SENSITIVE_BIT, ZN_REPICK_FLAG, False }, { ZN_CONFIG_TAG_LIST, "-tags", NULL, Tk_Offset(ReticleItemStruct, header.tags), 0, 0, False }, { ZN_CONFIG_BOOL, "-visible", NULL, - Tk_Offset(ReticleItemStruct, header.flags), VISIBLE_BIT, + Tk_Offset(ReticleItemStruct, 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 } }; @@ -125,28 +136,28 @@ static ZnAttrConfig reticle_attrs[] = { ********************************************************************************** */ static int -Init(Item item, - int *argc, - Tcl_Obj *CONST *args[]) +Init(ZnItem item, + int *argc __unused, + Tcl_Obj *CONST *args[] __unused) { ReticleItem reticle = (ReticleItem) item; - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; - SET(item->flags, VISIBLE_BIT); - CLEAR(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_RETICLE_PRIORITY; + SET(item->flags, ZN_VISIBLE_BIT); + CLEAR(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 = 0; item->part_sensitive = 0; reticle->line_color = ZnGetGradientByValue(wi->fore_color); reticle->bright_line_color = ZnGetGradientByValue(wi->fore_color); reticle->first_radius = DEFAULT_RETICLE_STEP_SIZE; reticle->step_size = DEFAULT_RETICLE_STEP_SIZE; reticle->period = DEFAULT_RETICLE_PERIOD; - reticle->num_circles = ZN_ANY_CIRCLES; - reticle->line_style = LINE_SIMPLE; - reticle->bright_line_style = LINE_SIMPLE; + reticle->num_circles = ANY_CIRCLES; + reticle->line_style = ZN_LINE_SIMPLE; + reticle->bright_line_style = ZN_LINE_SIMPLE; reticle->pos.x = 0; reticle->pos.y = 0; reticle->dev.x = 0; @@ -154,7 +165,7 @@ Init(Item item, reticle->first_radius_dev = 0; reticle->step_size_dev = 0; - return ZN_OK; + return TCL_OK; } @@ -166,7 +177,7 @@ Init(Item item, ********************************************************************************** */ static void -Clone(Item item) +Clone(ZnItem item) { ReticleItem reticle = (ReticleItem) item; @@ -183,7 +194,7 @@ Clone(Item item) ********************************************************************************** */ static void -Destroy(Item item) +Destroy(ZnItem item) { ReticleItem reticle = (ReticleItem) item; @@ -200,17 +211,17 @@ Destroy(Item item) ********************************************************************************** */ static int -Configure(Item item, +Configure(ZnItem item, int argc, Tcl_Obj *CONST argv[], int *flags) { if (ZnConfigureAttributes(item->wi, item, reticle_attrs, - argc, argv, flags) == ZN_ERROR) { - return ZN_ERROR; + argc, argv, flags) == TCL_ERROR) { + return TCL_ERROR; } - return ZN_OK; + return TCL_OK; } @@ -222,15 +233,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, reticle_attrs, argv[0]) == ZN_ERROR) { - return ZN_ERROR; + if (ZnQueryAttribute(item->wi, item, reticle_attrs, argv[0]) == TCL_ERROR) { + return TCL_ERROR; } - return ZN_OK; + return TCL_OK; } @@ -242,10 +253,10 @@ Query(Item item, ********************************************************************************** */ static void -ComputeCoordinates(Item item, - ZnBool force) +ComputeCoordinates(ZnItem item, + ZnBool force __unused) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; ReticleItem reticle = (ReticleItem) item; ZnDim half_width; ZnPoint p, xp; @@ -267,7 +278,7 @@ ComputeCoordinates(Item item, } /* Reticle bounding box is zn bounding box or depends on num_circles */ - if (reticle->num_circles == ZN_ANY_CIRCLES) { + if (reticle->num_circles == ANY_CIRCLES) { item->item_bounding_box.orig.x = 0; item->item_bounding_box.orig.y = 0; item->item_bounding_box.corner.x = wi->width; @@ -294,8 +305,8 @@ ComputeCoordinates(Item item, ********************************************************************************** */ static int -ToArea(Item item, - ZnToArea ta) +ToArea(ZnItem item __unused, + ZnToArea ta __unused) { return -1; } @@ -309,14 +320,14 @@ ToArea(Item item, ********************************************************************************** */ static void -Draw(Item item) +Draw(ZnItem item) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; ReticleItem reticle = (ReticleItem) item; ZnDim radius = reticle->first_radius_dev; ZnDim radius_max_dev; XGCValues values; - unsigned int i; + int i; ZnDim l1, l2, l3, l4; /* int count = 0;*/ @@ -338,18 +349,20 @@ Draw(Item item) while (radius <= radius_max_dev) { ZnSetLineStyle(wi, reticle->line_style); - values.foreground = ZnPixel(ZnGetGradientColor(reticle->line_color, 0, NULL)); + values.foreground = ZnPixel(ZnGetGradientColor(reticle->line_color, 0.0, NULL)); values.line_width = 0; values.fill_style = FillSolid; XChangeGC(wi->dpy, wi->gc, GCForeground | GCLineWidth | GCFillStyle, &values); - for (i = 1; (radius <= radius_max_dev && i < reticle->period); i++) { + for (i = 1; ((radius <= radius_max_dev) && (i < reticle->period)); i++) { if ((reticle->dev.x >= wi->damaged_area.orig.x - radius) && (reticle->dev.x <= wi->damaged_area.corner.x + radius) && (reticle->dev.y >= wi->damaged_area.orig.y - radius) && (reticle->dev.y <= wi->damaged_area.corner.y + radius)) { XDrawArc(wi->dpy, wi->draw_buffer, wi->gc, - reticle->dev.x - (ZnPos) radius, reticle->dev.y - (ZnPos) radius, - (ZnPos) radius * 2 - 1, (ZnPos) radius * 2 - 1, + (int) (reticle->dev.x - radius), + (int) (reticle->dev.y - radius), + (unsigned int) (radius * 2 - 1), + (unsigned int) (radius * 2 - 1), 0, 360 * 64); /* count++;*/ } @@ -361,13 +374,16 @@ Draw(Item item) (reticle->dev.y >= wi->damaged_area.orig.y - radius) && (reticle->dev.y <= wi->damaged_area.corner.y + radius)) { ZnSetLineStyle(wi, reticle->bright_line_style); - values.foreground = ZnPixel(ZnGetGradientColor(reticle->bright_line_color, 0, NULL)); + values.foreground = ZnPixel(ZnGetGradientColor(reticle->bright_line_color, 0.0, NULL)); values.line_width = 0; values.fill_style = FillSolid; XChangeGC(wi->dpy, wi->gc, GCForeground | GCLineWidth | GCFillStyle, &values); XDrawArc(wi->dpy, wi->draw_buffer, wi->gc, - reticle->dev.x - (ZnPos) radius, reticle->dev.y - (ZnPos) radius, - (ZnPos) radius * 2 - 1, (ZnPos) radius * 2 - 1, 0, 360 * 64); + (int) (reticle->dev.x - radius), + (int) (reticle->dev.y - radius), + (unsigned int) (radius * 2 - 1), + (unsigned int) (radius * 2 - 1), + 0, 360 * 64); /*count++;*/ } radius += (reticle->step_size_dev); @@ -383,17 +399,18 @@ Draw(Item item) * ********************************************************************************** */ +#ifdef GL static void -Render(Item item) +Render(ZnItem item) { -#ifdef GLX - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; ReticleItem reticle = (ReticleItem) item; ZnDim radius = reticle->first_radius_dev; ZnDim radius_max_dev, new, x, y, xo, yo; - unsigned int i, j; + int i, j; ZnPoint *genarc; - int num_p, alpha; + int num_p; + unsigned short alpha; XColor *color; xo = reticle->dev.x; @@ -431,14 +448,14 @@ Render(Item item) (reticle->num_circles - 1) * reticle->step_size_dev); } - genarc = GetCirclePoints(3, ZN_CIRCLE_FINEST, 0, 2*M_PI, &num_p, NULL); - glLineWidth(1); + genarc = ZnGetCirclePoints(3, ZN_CIRCLE_FINEST, 0.0, 2*M_PI, &num_p, NULL); + glLineWidth(1.0); while (radius <= radius_max_dev) { ZnSetLineStyle(wi, reticle->line_style); - color = ZnGetGradientColor(reticle->line_color, 0, &alpha); + color = ZnGetGradientColor(reticle->line_color, 0.0, &alpha); alpha = ZnComposeAlpha(alpha, wi->alpha); glColor4us(color->red, color->green, color->blue, alpha); - for (i = 1; (radius <= radius_max_dev && i < reticle->period); i++) { + for (i = 1; ((radius <= radius_max_dev) && (i < reticle->period)); i++) { if ((xo >= wi->damaged_area.orig.x - radius) && (xo <= wi->damaged_area.corner.x + radius) && (yo >= wi->damaged_area.orig.y - radius) && @@ -447,7 +464,7 @@ Render(Item item) for (j = 0; j < num_p; j++) { x = xo + genarc[j].x * radius; y = yo + genarc[j].y * radius; - glVertex2f(x, y); + glVertex2d(x, y); } glEnd(); } @@ -459,22 +476,27 @@ Render(Item item) (yo >= wi->damaged_area.orig.y - radius) && (yo <= wi->damaged_area.corner.y + radius)) { ZnSetLineStyle(wi, reticle->bright_line_style); - color = ZnGetGradientColor(reticle->bright_line_color, 0, &alpha); + color = ZnGetGradientColor(reticle->bright_line_color, 0.0, &alpha); alpha = ZnComposeAlpha(alpha, wi->alpha); glColor4us(color->red, color->green, color->blue, alpha); glBegin(GL_LINE_LOOP); for (j = 0; j < num_p; j++) { x = xo + genarc[j].x * radius; y = yo + genarc[j].y * radius; - glVertex2f(x, y); + glVertex2d(x, y); } glEnd(); } radius += (reticle->step_size_dev); } glDisable(GL_LINE_STIPPLE); -#endif } +#else +static void +Render(ZnItem item __unused) +{ +} +#endif /* @@ -485,10 +507,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)); } @@ -502,8 +524,8 @@ IsSensitive(Item item, ********************************************************************************** */ static double -Pick(Item item, - ZnPick ps) +Pick(ZnItem item __unused, + ZnPick ps __unused) { return 1e40; } @@ -518,35 +540,35 @@ Pick(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 __unused, + int cmd, + ZnPoint **pts, + char **controls __unused, + unsigned int *num_pts) { ReticleItem reticle = (ReticleItem) item; - if ((cmd == COORDS_ADD) || (cmd == COORDS_ADD_LAST) || (cmd == COORDS_REMOVE)) { + if ((cmd == ZN_COORDS_ADD) || (cmd == ZN_COORDS_ADD_LAST) || (cmd == ZN_COORDS_REMOVE)) { Tcl_AppendResult(item->wi->interp, " reticles can't add or remove vertices", NULL); - return ZN_ERROR; + return TCL_ERROR; } - else if ((cmd == COORDS_REPLACE) || (cmd == COORDS_REPLACE_ALL)) { + else if ((cmd == ZN_COORDS_REPLACE) || (cmd == ZN_COORDS_REPLACE_ALL)) { if (*num_pts == 0) { Tcl_AppendResult(item->wi->interp, " coords command need 1 point on reticles", NULL); - return ZN_ERROR; + return TCL_ERROR; } reticle->pos = (*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)) { *num_pts = 1; *pts = &reticle->pos; } - return ZN_OK; + return TCL_OK; } @@ -558,8 +580,8 @@ Coords(Item item, ********************************************************************************** */ static void -PostScript(Item item, - PostScriptInfo ps_info) +PostScript(ZnItem item __unused, + ZnPostScriptInfo ps_info __unused) { } @@ -571,7 +593,7 @@ PostScript(Item item, * ********************************************************************************** */ -static ItemClassStruct RETICLE_ITEM_CLASS = { +static ZnItemClassStruct RETICLE_ITEM_CLASS = { sizeof(ReticleItemStruct), 0, /* num_parts */ False, /* has_anchors */ diff --git a/generic/Tabular.c b/generic/Tabular.c index 6e77fa9..cca3b71 100644 --- a/generic/Tabular.c +++ b/generic/Tabular.c @@ -49,15 +49,15 @@ static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ " ********************************************************************************** */ typedef struct _TabularItemStruct { - ItemStruct header; + ZnItemStruct header; /* Public data */ ZnPoint pos; - ZnAnchor anchor; - ZnAnchor connection_anchor; + Tk_Anchor anchor; + Tk_Anchor connection_anchor; /* Private data */ - FieldSetStruct field_set; + ZnFieldSetStruct field_set; } TabularItemStruct, *TabularItem; @@ -65,13 +65,13 @@ static ZnAttrConfig tabular_attrs[] = { { ZN_CONFIG_ANCHOR, "-anchor", NULL, Tk_Offset(TabularItemStruct, anchor), 0, ZN_COORDS_FLAG, False }, { ZN_CONFIG_BOOL, "-composealpha", NULL, - Tk_Offset(TabularItemStruct, header.flags), COMPOSE_ALPHA_BIT, + Tk_Offset(TabularItemStruct, header.flags), ZN_COMPOSE_ALPHA_BIT, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-composerotation", NULL, - Tk_Offset(TabularItemStruct, header.flags), COMPOSE_ROTATION_BIT, + Tk_Offset(TabularItemStruct, header.flags), ZN_COMPOSE_ROTATION_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_BOOL, "-composescale", NULL, - Tk_Offset(TabularItemStruct, header.flags), COMPOSE_SCALE_BIT, + Tk_Offset(TabularItemStruct, header.flags), ZN_COMPOSE_SCALE_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_ITEM, "-connecteditem", NULL, Tk_Offset(TabularItemStruct, header.connected_item), 0, @@ -89,15 +89,15 @@ static ZnAttrConfig tabular_attrs[] = { Tk_Offset(TabularItemStruct, header.priority), 0, ZN_DRAW_FLAG|ZN_REPICK_FLAG, False }, { ZN_CONFIG_BOOL, "-sensitive", NULL, - Tk_Offset(TabularItemStruct, header.flags), SENSITIVE_BIT, + Tk_Offset(TabularItemStruct, header.flags), ZN_SENSITIVE_BIT, ZN_REPICK_FLAG, False }, { ZN_CONFIG_TAG_LIST, "-tags", NULL, Tk_Offset(TabularItemStruct, header.tags), 0, 0, False }, { ZN_CONFIG_BOOL, "-visible", NULL, - Tk_Offset(TabularItemStruct, header.flags), VISIBLE_BIT, + Tk_Offset(TabularItemStruct, 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 } }; @@ -109,24 +109,25 @@ static ZnAttrConfig tabular_attrs[] = { ********************************************************************************** */ static int -Init(Item item, +Init(ZnItem item, int *argc, Tcl_Obj *CONST *args[]) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; TabularItem tab = (TabularItem) item; - FieldSet field_set = &tab->field_set; - - item->priority = DEFAULT_TABULAR_PRIORITY; + ZnFieldSet field_set = &tab->field_set; + int num_fields; + + item->priority = 1; - SET(item->flags, VISIBLE_BIT); - SET(item->flags, SENSITIVE_BIT); - SET(item->flags, COMPOSE_ALPHA_BIT); - SET(item->flags, COMPOSE_SCALE_BIT); - SET(item->flags, COMPOSE_ROTATION_BIT); + SET(item->flags, ZN_VISIBLE_BIT); + SET(item->flags, ZN_SENSITIVE_BIT); + SET(item->flags, ZN_COMPOSE_ALPHA_BIT); + SET(item->flags, ZN_COMPOSE_SCALE_BIT); + SET(item->flags, ZN_COMPOSE_ROTATION_BIT); - tab->anchor = ZnAnchorNW; - tab->connection_anchor = ZnAnchorSW; + tab->anchor = TK_ANCHOR_NW; + tab->connection_anchor = TK_ANCHOR_SW; tab->pos.x = tab->pos.y = 0.0; field_set->item = item; @@ -136,20 +137,20 @@ Init(Item item, * Then try to see if some fields are needed. */ if ((*argc > 0) && (Tcl_GetString((*args)[0])[0] != '-') && - (Tcl_GetIntFromObj(wi->interp, (*args)[0], - &field_set->num_fields) != ZN_ERROR)) { + (Tcl_GetIntFromObj(wi->interp, (*args)[0], &num_fields) != TCL_ERROR)) { + field_set->num_fields = num_fields; *args += 1; *argc -= 1; - FIELD.InitFields(field_set); + ZnFIELD.InitFields(field_set); } else { Tcl_AppendResult(wi->interp, " number of fields expected", NULL); - return ZN_ERROR; + return TCL_ERROR; } item->part_sensitive = 0; - return ZN_OK; + return TCL_OK; } @@ -161,11 +162,11 @@ Init(Item item, ********************************************************************************** */ static void -Clone(Item item) +Clone(ZnItem item) { - FieldSet fs = &((TabularItem) item)->field_set; + ZnFieldSet fs = &((TabularItem) item)->field_set; - FIELD.CloneFields(fs); + ZnFIELD.CloneFields(fs); fs->item = item; } @@ -178,9 +179,9 @@ Clone(Item item) ********************************************************************************** */ static void -Destroy(Item item) +Destroy(ZnItem item) { - FIELD.FreeFields(&((TabularItem) item)->field_set); + ZnFIELD.FreeFields(&((TabularItem) item)->field_set); } @@ -192,17 +193,17 @@ Destroy(Item item) ********************************************************************************** */ static int -Configure(Item item, +Configure(ZnItem item, int argc, Tcl_Obj *CONST argv[], int *flags) { - Item old_connected; + ZnItem old_connected; old_connected = item->connected_item; if (ZnConfigureAttributes(item->wi, item, tabular_attrs, - argc, argv, flags) == ZN_ERROR) { - return ZN_ERROR; + argc, argv, flags) == TCL_ERROR) { + return TCL_ERROR; } if (ISSET(*flags, ZN_ITEM_FLAG)) { /* @@ -212,14 +213,14 @@ Configure(Item item, if ((item->connected_item == ZN_NO_ITEM) || (item->connected_item->class->has_anchors && (item->parent == item->connected_item->parent))) { - ITEM.UpdateItemDependency(item, old_connected); + ZnITEM.UpdateItemDependency(item, old_connected); } else { item->connected_item = old_connected; } } - return ZN_OK; + return TCL_OK; } @@ -231,15 +232,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, tabular_attrs, argv[0]) == ZN_ERROR) { - return ZN_ERROR; + if (ZnQueryAttribute(item->wi, item, tabular_attrs, argv[0]) == TCL_ERROR) { + return TCL_ERROR; } - return ZN_OK; + return TCL_OK; } @@ -251,17 +252,17 @@ Query(Item item, ********************************************************************************** */ static void -ComputeCoordinates(Item item, - ZnBool force) +ComputeCoordinates(ZnItem item, + ZnBool force __unused) { TabularItem tab = (TabularItem) item; - WidgetInfo *wi = item->wi; - FieldSet field_set = &tab->field_set; + ZnWInfo *wi = item->wi; + ZnFieldSet field_set = &tab->field_set; ZnDim width, height; - ResetBBox(&item->item_bounding_box); + ZnResetBBox(&item->item_bounding_box); if (field_set->label_format && field_set->num_fields) { - FIELD.GetLabelBBox(field_set, &width, &height); + ZnFIELD.GetLabelBBox(field_set, &width, &height); /* * The connected item support anchors, this is checked by @@ -277,8 +278,8 @@ ComputeCoordinates(Item item, &field_set->label_pos); } - Anchor2Origin(&field_set->label_pos, width, height, tab->anchor, - &field_set->label_pos); + ZnAnchor2Origin(&field_set->label_pos, width, height, tab->anchor, + &field_set->label_pos); /* * Setup the item bounding box. @@ -290,7 +291,7 @@ ComputeCoordinates(Item item, /* * Update connected items. */ - SET(item->flags, UPDATE_DEPENDENT_BIT); + SET(item->flags, ZN_UPDATE_DEPENDENT_BIT); } } @@ -305,10 +306,10 @@ ComputeCoordinates(Item item, ********************************************************************************** */ static int -ToArea(Item item, +ToArea(ZnItem item, ZnToArea ta) { - return FIELD.FieldsToArea(&((TabularItem) item)->field_set, ta->area); + return ZnFIELD.FieldsToArea(&((TabularItem) item)->field_set, ta->area); } @@ -320,9 +321,9 @@ ToArea(Item item, ********************************************************************************** */ static void -Draw(Item item) +Draw(ZnItem item) { - FIELD.DrawFields(&((TabularItem) item)->field_set); + ZnFIELD.DrawFields(&((TabularItem) item)->field_set); } @@ -334,9 +335,9 @@ Draw(Item item) ********************************************************************************** */ static void -Render(Item item) +Render(ZnItem item) { - FIELD.RenderFields(&((TabularItem) item)->field_set); + ZnFIELD.RenderFields(&((TabularItem) item)->field_set); } @@ -348,18 +349,18 @@ Render(Item item) ********************************************************************************** */ static ZnBool -IsSensitive(Item item, +IsSensitive(ZnItem item, int item_part) { - if (ISCLEAR(item->flags, SENSITIVE_BIT) || + if (ISCLEAR(item->flags, ZN_SENSITIVE_BIT) || !item->parent->class->IsSensitive(item->parent, ZN_NO_PART)) { return False; } if (item_part == ZN_NO_PART) { - return ISSET(item->flags, SENSITIVE_BIT); + return ISSET(item->flags, ZN_SENSITIVE_BIT); } else { - return FIELD.IsFieldSensitive(&((TabularItem) item)->field_set, item_part); + return ZnFIELD.IsFieldSensitive(&((TabularItem) item)->field_set, item_part); } } @@ -373,13 +374,13 @@ IsSensitive(Item item, ********************************************************************************** */ static double -Pick(Item item, +Pick(ZnItem item, ZnPick ps) { int best_part; double dist; - dist = FIELD.FieldsPick(&((TabularItem) item)->field_set, ps->point, &best_part); + dist = ZnFIELD.FieldsPick(&((TabularItem) item)->field_set, ps->point, &best_part); /*printf("tabular %d reporting part %d, distance %lf\n", item->id, best_part, dist);*/ if (dist <= 0.0) { @@ -399,8 +400,8 @@ Pick(Item item, ********************************************************************************** */ static void -PostScript(Item item, - PostScriptInfo ps_info) +PostScript(ZnItem item __unused, + ZnPostScriptInfo ps_info __unused) { } @@ -412,8 +413,8 @@ PostScript(Item item, * ********************************************************************************** */ -static FieldSet -GetFieldSet(Item item) +static ZnFieldSet +GetFieldSet(ZnItem item) { return &((TabularItem) item)->field_set; } @@ -427,16 +428,16 @@ GetFieldSet(Item item) ********************************************************************************** */ static void -GetAnchor(Item item, - ZnAnchor anchor, +GetAnchor(ZnItem item, + Tk_Anchor anchor, ZnPoint *p) { - FieldSet field_set = &((TabularItem) item)->field_set; + ZnFieldSet field_set = &((TabularItem) item)->field_set; ZnDim width, height; if (field_set->label_format) { - FIELD.GetLabelBBox(field_set, &width, &height); - Origin2Anchor(&field_set->label_pos, width, height, anchor, p); + ZnFIELD.GetLabelBBox(field_set, &width, &height); + ZnOrigin2Anchor(&field_set->label_pos, width, height, anchor, p); } else { p->x = p->y = 0.0; @@ -449,23 +450,23 @@ GetAnchor(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) { - FieldSet field_set = &((TabularItem) item)->field_set; + ZnFieldSet field_set = &((TabularItem) item)->field_set; ZnDim width, height; ZnPoint *points; if (field_set->label_format) { - FIELD.GetLabelBBox(field_set, &width, &height); + ZnFIELD.GetLabelBBox(field_set, &width, &height); ZnListAssertSize(item->wi->work_pts, 2); points = (ZnPoint *) ZnListArray(item->wi->work_pts); - TRI_STRIP1(tristrip, points, 2, False); + ZnTriStrip1(tristrip, points, 2, False); points[0] = field_set->label_pos; points[1].x = points[0].x + width; points[1].y = points[0].y + height; @@ -486,35 +487,35 @@ GetClipVertices(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 __unused, + int cmd, + ZnPoint **pts, + char **controls __unused, + unsigned int *num_pts) { TabularItem tabular = (TabularItem) item; - if ((cmd == COORDS_ADD) || (cmd == COORDS_ADD_LAST) || (cmd == COORDS_REMOVE)) { + if ((cmd == ZN_COORDS_ADD) || (cmd == ZN_COORDS_ADD_LAST) || (cmd == ZN_COORDS_REMOVE)) { Tcl_AppendResult(item->wi->interp, " tabulars can't add or remove vertices", NULL); - return ZN_ERROR; + return TCL_ERROR; } - else if ((cmd == COORDS_REPLACE) || (cmd == COORDS_REPLACE_ALL)) { + else if ((cmd == ZN_COORDS_REPLACE) || (cmd == ZN_COORDS_REPLACE_ALL)) { if (*num_pts == 0) { Tcl_AppendResult(item->wi->interp, " coords command need 1 point on tabulars", NULL); - return ZN_ERROR; + return TCL_ERROR; } tabular->pos = (*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)) { *num_pts = 1; *pts = &tabular->pos; } - return ZN_OK; + return TCL_OK; } @@ -527,7 +528,7 @@ Coords(Item item, ********************************************************************************** */ static int -Part(Item item, +Part(ZnItem item, Tcl_Obj **part_spec, int *part) { @@ -542,14 +543,14 @@ Part(Item item, else if (isdigit(part_str[0])) { *part = strtol(part_str, &end, 0); if ((*end != 0) || (*part < 0) || - (*part >= ((TabularItem) item)->field_set.num_fields)) { + ((unsigned int) *part >= ((TabularItem) item)->field_set.num_fields)) { goto part_error; } } else { part_error: Tcl_AppendResult(item->wi->interp, " invalid item part specification", NULL); - return ZN_ERROR; + return TCL_ERROR; } } else { @@ -557,10 +558,10 @@ Part(Item item, *part_spec = Tcl_NewIntObj(*part); } else { - *part_spec = NewStringObj(""); + *part_spec = Tcl_NewStringObj("", -1); } } - return ZN_OK; + return TCL_OK; } @@ -574,12 +575,12 @@ Part(Item item, ********************************************************************************** */ static int -Index(Item item, +Index(ZnItem item, int field, Tcl_Obj *index_spec, int *index) { - return FIELD.FieldIndex(&((TabularItem) item)->field_set, field, + return ZnFIELD.FieldIndex(&((TabularItem) item)->field_set, field, index_spec, index); } @@ -592,14 +593,14 @@ Index(Item item, ********************************************************************************** */ static void -InsertChars(Item item, +InsertChars(ZnItem item, int field, int *index, char *chars) { - if (FIELD.FieldInsertChars(&((TabularItem) item)->field_set, + if (ZnFIELD.FieldInsertChars(&((TabularItem) item)->field_set, field, index, chars)) { - ITEM.Invalidate(item, ZN_COORDS_FLAG); + ZnITEM.Invalidate(item, ZN_COORDS_FLAG); } } @@ -612,14 +613,14 @@ InsertChars(Item item, ********************************************************************************** */ static void -DeleteChars(Item item, +DeleteChars(ZnItem item, int field, int *first, int *last) { - if (FIELD.FieldDeleteChars(&((TabularItem) item)->field_set, + if (ZnFIELD.FieldDeleteChars(&((TabularItem) item)->field_set, field, first, last)) { - ITEM.Invalidate(item, ZN_COORDS_FLAG); + ZnITEM.Invalidate(item, ZN_COORDS_FLAG); } } @@ -632,11 +633,11 @@ DeleteChars(Item item, ********************************************************************************** */ static void -TabularCursor(Item item, +TabularCursor(ZnItem item, int field, int index) { - FIELD.FieldCursor(&((TabularItem) item)->field_set, field, index); + ZnFIELD.FieldCursor(&((TabularItem) item)->field_set, field, index); } @@ -648,13 +649,13 @@ TabularCursor(Item item, ********************************************************************************** */ static int -Selection(Item item, - int field, - int offset, - char *chars, - int max_chars) +Selection(ZnItem item, + int field, + int offset, + char *chars, + int max_chars) { - return FIELD.FieldSelection(&((TabularItem) item)->field_set, field, + return ZnFIELD.FieldSelection(&((TabularItem) item)->field_set, field, offset, chars, max_chars); } @@ -666,7 +667,7 @@ Selection(Item item, * ********************************************************************************** */ -static ItemClassStruct TABULAR_ITEM_CLASS = { +static ZnItemClassStruct TABULAR_ITEM_CLASS = { sizeof(TabularItemStruct), 0, /* num_parts */ True, /* has_anchors */ diff --git a/generic/Text.c b/generic/Text.c index e0dfd00..047354e 100644 --- a/generic/Text.c +++ b/generic/Text.c @@ -36,7 +36,6 @@ #include #include #include -#include #include #include @@ -70,34 +69,34 @@ static const char compile_id[] = "$Compile: " __FILE__ " " __DATE__ " " __TIME__ typedef struct _TextLineInfo { char *start; /* Index of first char in line */ - int num_bytes; /* Number of displayed bytes in line (NOT chars)*/ + unsigned int num_bytes; /* Number of displayed bytes in line (NOT chars)*/ ZnPoint text_origin; /* X pos for drawing the line */ - int width; /* Line width in pixels */ + unsigned int width; /* Line width in pixels */ } TextLineInfoStruct, *TextLineInfo; typedef struct _TextItemStruct { - ItemStruct header; + ZnItemStruct header; /* Public data */ ZnPoint pos; - ZnAnchor anchor; - ZnAnchor connection_anchor; + Tk_Anchor anchor; + Tk_Anchor connection_anchor; ZnGradient *color; char *text; ZnImage fill_pattern; - ZnFont font; - ZnJustify alignment; - ZnDim width; - ZnDim spacing; + Tk_Font font; + Tk_Justify alignment; + unsigned int width; + unsigned int spacing; unsigned short flags; /* Private data */ ZnPoint pos_dev; - int num_chars; - int insert_index; + unsigned int num_chars; + unsigned int insert_index; ZnList text_info; - int max_width; -#ifdef GLX + unsigned int max_width; +#ifdef GL ZnTexFontInfo *tfi; #endif } TextItemStruct, *TextItem; @@ -112,13 +111,13 @@ static ZnAttrConfig text_attrs[] = { { ZN_CONFIG_GRADIENT, "-color", NULL, Tk_Offset(TextItemStruct, color), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-composealpha", NULL, - Tk_Offset(TextItemStruct, header.flags), COMPOSE_ALPHA_BIT, + Tk_Offset(TextItemStruct, header.flags), ZN_COMPOSE_ALPHA_BIT, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-composerotation", NULL, - Tk_Offset(TextItemStruct, header.flags), COMPOSE_ROTATION_BIT, + Tk_Offset(TextItemStruct, header.flags), ZN_COMPOSE_ROTATION_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_BOOL, "-composescale", NULL, - Tk_Offset(TextItemStruct, header.flags), COMPOSE_SCALE_BIT, + Tk_Offset(TextItemStruct, header.flags), ZN_COMPOSE_SCALE_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_ITEM, "-connecteditem", NULL, Tk_Offset(TextItemStruct, header.connected_item), 0, @@ -138,9 +137,9 @@ static ZnAttrConfig text_attrs[] = { Tk_Offset(TextItemStruct, header.priority), 0, ZN_DRAW_FLAG|ZN_REPICK_FLAG, False }, { ZN_CONFIG_BOOL, "-sensitive", NULL, - Tk_Offset(TextItemStruct, header.flags), SENSITIVE_BIT, + Tk_Offset(TextItemStruct, header.flags), ZN_SENSITIVE_BIT, ZN_REPICK_FLAG, False }, - { ZN_CONFIG_DIM, "-spacing", NULL, + { ZN_CONFIG_INT, "-spacing", NULL, Tk_Offset(TextItemStruct, spacing), 0, ZN_COORDS_FLAG|ZN_LAYOUT_FLAG, False }, { ZN_CONFIG_TAG_LIST, "-tags", NULL, @@ -151,13 +150,13 @@ static ZnAttrConfig text_attrs[] = { { ZN_CONFIG_BOOL, "-underlined", NULL, Tk_Offset(TextItemStruct, flags), UNDERLINED, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-visible", NULL, - Tk_Offset(TextItemStruct, header.flags), VISIBLE_BIT, + Tk_Offset(TextItemStruct, header.flags), ZN_VISIBLE_BIT, ZN_DRAW_FLAG|ZN_REPICK_FLAG|ZN_VIS_FLAG, False }, - { ZN_CONFIG_DIM, "-width", NULL, + { ZN_CONFIG_INT, "-width", NULL, Tk_Offset(TextItemStruct, width), 0, ZN_COORDS_FLAG|ZN_LAYOUT_FLAG, False }, - { ZN_CONFIG_END, NULL, NULL, 0, 0, 0 } + { ZN_CONFIG_END, NULL, NULL, 0, 0, 0, False } }; @@ -169,33 +168,33 @@ static ZnAttrConfig text_attrs[] = { ********************************************************************************** */ static int -Init(Item item, - int *argc, - Tcl_Obj *CONST *args[]) +Init(ZnItem item, + int *argc __unused, + Tcl_Obj *CONST *args[] __unused) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; TextItem text = (TextItem) item; text->text_info = NULL; /* 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_TEXT_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; text->pos.x = text->pos.y = 0.0; text->text = NULL; text->num_chars = 0; text->fill_pattern = ZnUnspecifiedImage; - text->anchor = ZnAnchorNW; - text->connection_anchor = ZnAnchorSW; + text->anchor = TK_ANCHOR_NW; + text->connection_anchor = TK_ANCHOR_SW; text->color = ZnGetGradientByValue(wi->fore_color); - text->alignment = ZnJustifyLeft; + text->alignment = TK_JUSTIFY_LEFT; text->font = Tk_GetFont(wi->interp, wi->win, Tk_NameOfFont(wi->font)); -#ifdef GLX +#ifdef GL text->tfi = NULL; if (wi->render) { text->tfi = ZnGetTexFont(wi, text->font); @@ -207,7 +206,7 @@ Init(Item item, CLEAR(text->flags, UNDERLINED); CLEAR(text->flags, OVERSTRIKED); - return ZN_OK; + return TCL_OK; } @@ -219,10 +218,10 @@ Init(Item item, ********************************************************************************** */ static void -Clone(Item item) +Clone(ZnItem item) { TextItem text = (TextItem) item; - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; char *str; if (text->text) { @@ -235,7 +234,7 @@ Clone(Item item) } text->color = ZnGetGradientByValue(text->color); text->font = Tk_GetFont(wi->interp, wi->win, Tk_NameOfFont(text->font)); -#ifdef GLX +#ifdef GL if (wi->render) { text->tfi = ZnGetTexFont(wi, text->font); } @@ -248,7 +247,7 @@ Clone(Item item) * text_info. */ text->text_info = NULL; - ITEM.Invalidate(item, ZN_COORDS_FLAG|ZN_LAYOUT_FLAG); + ZnITEM.Invalidate(item, ZN_COORDS_FLAG|ZN_LAYOUT_FLAG); } @@ -260,7 +259,7 @@ Clone(Item item) ********************************************************************************** */ static void -Destroy(Item item) +Destroy(ZnItem item) { TextItem text = (TextItem) item; @@ -273,7 +272,7 @@ Destroy(Item item) } ZnFreeGradient(text->color); Tk_FreeFont(text->font); -#ifdef GLX +#ifdef GL if (text->tfi) { ZnFreeTexFont(text->tfi); } @@ -293,24 +292,24 @@ Destroy(Item item) ********************************************************************************** */ static int -Configure(Item item, +Configure(ZnItem item, int argc, Tcl_Obj *CONST argv[], int *flags) { TextItem text = (TextItem) item; - Item old_connected = item->connected_item; - int num_chars; -#ifdef GLX - ZnFont old_font = text->font; + ZnItem old_connected = item->connected_item; + unsigned int num_chars; +#ifdef GL + Tk_Font old_font = text->font; #endif if (ZnConfigureAttributes(item->wi, item, text_attrs, - argc, argv, flags) == ZN_ERROR) { - return ZN_ERROR; + argc, argv, flags) == TCL_ERROR) { + return TCL_ERROR; } -#ifdef GLX +#ifdef GL if (old_font != text->font) { if (text->tfi) { ZnFreeTexFont(text->tfi); @@ -318,30 +317,30 @@ Configure(Item item, if (item->wi->render) { text->tfi = ZnGetTexFont(item->wi, text->font); if (!text->tfi) { - return ZN_ERROR; + return TCL_ERROR; } } } #endif num_chars = 0; if (text->text) { - num_chars = Tcl_NumUtfChars(text->text, strlen(text->text)); + num_chars = Tcl_NumUtfChars(text->text, (int) strlen(text->text)); } if (text->num_chars != num_chars) { - TextInfo *ti = &item->wi->text_info; + ZnTextInfo *ti = &item->wi->text_info; /* * The text has changed, update the selection and * insertion pos to keep them valid. */ if (item == ti->sel_item) { - if (ti->sel_last > num_chars) { + if (ti->sel_last > (int) num_chars) { ti->sel_last = num_chars; } if (ti->sel_first >= ti->sel_last) { ti->sel_item = ZN_NO_ITEM; ti->sel_field = ZN_NO_PART; } - if ((ti->anchor_item == item) && (ti->sel_anchor > num_chars)) { + if ((ti->anchor_item == item) && (ti->sel_anchor > (int) num_chars)) { ti->sel_anchor = num_chars; } } @@ -359,14 +358,14 @@ Configure(Item item, if ((item->connected_item == ZN_NO_ITEM) || (item->connected_item->class->has_anchors && (item->parent == item->connected_item->parent))) { - ITEM.UpdateItemDependency(item, old_connected); + ZnITEM.UpdateItemDependency(item, old_connected); } else { item->connected_item = old_connected; } } - return ZN_OK; + return TCL_OK; } @@ -378,15 +377,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, text_attrs, argv[0]) == ZN_ERROR) { - return ZN_ERROR; + if (ZnQueryAttribute(item->wi, item, text_attrs, argv[0]) == TCL_ERROR) { + return TCL_ERROR; } - return ZN_OK; + return TCL_OK; } @@ -398,10 +397,10 @@ Query(Item item, ********************************************************************************** */ static void -ComputeCoordinates(Item item, - ZnBool force) +ComputeCoordinates(ZnItem item, + ZnBool force __unused) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; TextItem text = (TextItem) item; TextLineInfo infos; Tk_FontMetrics fm; @@ -409,7 +408,7 @@ ComputeCoordinates(Item item, int cur_dy; int font_height, height; - ResetBBox(&item->item_bounding_box); + ZnResetBBox(&item->item_bounding_box); Tk_GetFontMetrics(text->font, &fm); font_height = fm.ascent+fm.descent; @@ -419,8 +418,8 @@ ComputeCoordinates(Item item, * or rotated. */ if (ISSET(item->inv_flags, ZN_LAYOUT_FLAG)) { - char *scan; - int wrap, prev_num_lines; + char *scan; + int wrap, prev_num_lines; text->max_width = 0; if (text->text_info != NULL) { @@ -493,13 +492,13 @@ ComputeCoordinates(Item item, for (i = 0; i < num_lines; i++) { switch (text->alignment) { - case ZnJustifyLeft: + case TK_JUSTIFY_LEFT: infos[i].text_origin.x = 0; break; - case ZnJustifyCenter: + case TK_JUSTIFY_CENTER: infos[i].text_origin.x = (text->max_width + 1 - infos[i].width)/2; break; - case ZnJustifyRight: + case TK_JUSTIFY_RIGHT: infos[i].text_origin.x = text->max_width + 1 - infos[i].width; break; } @@ -529,19 +528,19 @@ ComputeCoordinates(Item item, } else { ZnTransformPoint(wi->current_transfo, &text->pos, &text->pos_dev); - text->pos_dev.x = REAL_TO_INT(text->pos_dev.x); - text->pos_dev.y = REAL_TO_INT(text->pos_dev.y); + text->pos_dev.x = ZnNearestInt(text->pos_dev.x); + text->pos_dev.y = ZnNearestInt(text->pos_dev.y); } - Anchor2Origin(&text->pos_dev, text->max_width, height, text->anchor, - &text->pos_dev); + ZnAnchor2Origin(&text->pos_dev, (ZnReal) text->max_width, (ZnReal) height, text->anchor, + &text->pos_dev); /* * Compute the bounding box. */ - AddPointToBBox(&item->item_bounding_box, text->pos_dev.x, text->pos_dev.y); - AddPointToBBox(&item->item_bounding_box, text->pos_dev.x+text->max_width+1, - text->pos_dev.y+height); + ZnAddPointToBBox(&item->item_bounding_box, text->pos_dev.x, text->pos_dev.y); + ZnAddPointToBBox(&item->item_bounding_box, text->pos_dev.x+text->max_width+1, + text->pos_dev.y+height); fuzz = 1+(wi->text_info.insert_width/2); item->item_bounding_box.orig.x -= fuzz; item->item_bounding_box.orig.y -= fuzz; @@ -551,7 +550,7 @@ ComputeCoordinates(Item item, /* * Update connected items. */ - SET(item->flags, UPDATE_DEPENDENT_BIT); + SET(item->flags, ZN_UPDATE_DEPENDENT_BIT); } @@ -565,7 +564,7 @@ ComputeCoordinates(Item item, ********************************************************************************** */ static int -ToArea(Item item, +ToArea(ZnItem item, ZnToArea ta) { TextItem text = (TextItem) item; @@ -592,20 +591,20 @@ ToArea(Item item, /*printf("text %d, num lines=%d\n", item->id, num_lines);*/ for (i = 0, lines_ptr = lines; i < num_lines; i++, lines_ptr++) { - ResetBBox(&line_bbox); + ZnResetBBox(&line_bbox); o.x = text->pos_dev.x + lines_ptr->text_origin.x; o.y = text->pos_dev.y + lines_ptr->text_origin.y - fm.ascent; - AddPointToBBox(&line_bbox, o.x, o.y); - AddPointToBBox(&line_bbox, o.x + lines_ptr->width, o.y + font_height); + ZnAddPointToBBox(&line_bbox, o.x, o.y); + ZnAddPointToBBox(&line_bbox, o.x + lines_ptr->width, o.y + font_height); if (!first_done) { first_done = True; - inside = BBoxInBBox(&line_bbox, area); + inside = ZnBBoxInBBox(&line_bbox, area); if (inside == 0) { return 0; } } else { - if (BBoxInBBox(&line_bbox, area) == 0) { + if (ZnBBoxInBBox(&line_bbox, area) == 0) { return 0; } } @@ -618,28 +617,28 @@ ToArea(Item item, * Compute the selection and the cursor geometry. */ static void -ComputeCursorAndSel(Item item, +ComputeCursorAndSel(ZnItem item, TextLineInfo lines, - int num_lines, + unsigned int num_lines, int *sel_first_line, int *sel_last_line, int *cursor_line, - int *sel_start_offset, - int *sel_stop_offset, - int *cursor_offset) + unsigned int *sel_start_offset, + unsigned int *sel_stop_offset, + unsigned int *cursor_offset) { TextItem text = (TextItem) item; - WidgetInfo *wi = item->wi; - TextInfo *ti = &wi->text_info; + ZnWInfo *wi = item->wi; + ZnTextInfo *ti = &wi->text_info; TextLineInfo lines_ptr; - int i, line_index, byte_index; - int insert_index, sel_first, sel_last; + unsigned int i, line_index, byte_index; + unsigned int insert_index, sel_first, sel_last; if (num_lines == 0) { *cursor_line = 0; } - if ((wi->focus_item == item) && wi->got_focus && ti->cursor_on) { - insert_index = Tcl_UtfAtIndex(text->text, text->insert_index)-text->text; + if ((wi->focus_item == item) && ISSET(wi->flags, ZN_GOT_FOCUS) && ti->cursor_on) { + insert_index = Tcl_UtfAtIndex(text->text, (int) text->insert_index)-text->text; for (i = 0, lines_ptr = lines; i < num_lines; i++, lines_ptr++) { /* * Mark the line with the cursor and compute its @@ -700,20 +699,20 @@ ComputeCursorAndSel(Item item, ********************************************************************************** */ static void -Draw(Item item) +Draw(ZnItem item) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; TextItem text = (TextItem) item; XGCValues values; - int gc_mask = 0; + unsigned int gc_mask = 0; Tk_FontMetrics fm; - int font_height; + unsigned int font_height; int num_lines, i; TextLineInfo lines, lines_ptr; - TextInfo *ti = &wi->text_info; - int underline_thickness, underline_pos=0, overstrike_pos=0; + ZnTextInfo *ti = &wi->text_info; + unsigned int underline_thickness, underline_pos=0, overstrike_pos=0; int sel_first_line=-1, sel_last_line=-1, cursor_line=-1; - int sel_start_offset=0, sel_stop_offset=0, cursor_offset=0; + unsigned int sel_start_offset=0, sel_stop_offset=0, cursor_offset=0; if (!text->text_info || !text->text) { return; @@ -739,7 +738,7 @@ Draw(Item item) if ((ti->sel_item == item) && (sel_first_line >= 0)) { int x, y; - values.foreground = ZnPixel(ZnGetGradientColor(ti->sel_color, 0, NULL)); + values.foreground = ZnPixel(ZnGetGradientColor(ti->sel_color, 0.0, NULL)); values.fill_style = FillSolid; XChangeGC(wi->dpy, wi->gc, GCFillStyle | GCForeground, &values); @@ -754,7 +753,7 @@ Draw(Item item) y = (int)(text->pos_dev.y + lines[sel_first_line].text_origin.y - fm.ascent); XFillRectangle(wi->dpy, wi->draw_buffer, wi->gc, x, y, - text->max_width-lines[sel_first_line].text_origin.x-sel_start_offset, + text->max_width-(int)lines[sel_first_line].text_origin.x-sel_start_offset, font_height); for (i = sel_first_line+1, lines_ptr = &lines[sel_first_line+1]; i < sel_last_line; i++, lines_ptr++) { @@ -766,7 +765,7 @@ Draw(Item item) x = (int)text->pos_dev.x; y = (int)(text->pos_dev.y + lines[sel_last_line].text_origin.y - fm.ascent); XFillRectangle(wi->dpy, wi->draw_buffer, wi->gc, - x, y, lines[sel_last_line].text_origin.x+sel_stop_offset, + x, y, (int)lines[sel_last_line].text_origin.x+sel_stop_offset, font_height); } } @@ -781,23 +780,23 @@ Draw(Item item) values.fill_style = FillSolid; values.line_width = ti->insert_width; - values.foreground = ZnPixel(ZnGetGradientColor(ti->insert_color, 0, NULL)); + values.foreground = ZnPixel(ZnGetGradientColor(ti->insert_color, 0.0, NULL)); XChangeGC(wi->dpy, wi->gc, GCForeground|GCFillStyle|GCLineWidth, &values); xs = (int)(text->pos_dev.x + lines[cursor_line].text_origin.x + cursor_offset); ys = (int)(text->pos_dev.y + lines[cursor_line].text_origin.y - fm.ascent + 1); - XDrawLine(wi->dpy, wi->draw_buffer, wi->gc, xs, ys, xs, ys + font_height - 1); + XDrawLine(wi->dpy, wi->draw_buffer, wi->gc, xs, ys, xs, ys + (int) font_height - 1); } /* * Setup the gc to render the text and draw it. */ - values.font = ZnFontId(text->font); - values.foreground = ZnPixel(ZnGetGradientColor(text->color, 0, NULL)); + values.font = Tk_FontId(text->font); + values.foreground = ZnPixel(ZnGetGradientColor(text->color, 0.0, NULL)); gc_mask = GCFont | GCForeground; if (text->fill_pattern != ZnUnspecifiedImage) { values.fill_style = FillStippled; - values.stipple = ZnImagePixmap(text->fill_pattern, NULL); + values.stipple = ZnImagePixmap(text->fill_pattern); gc_mask |= GCFillStyle | GCStipple; } else { @@ -824,19 +823,19 @@ Draw(Item item) tmp_x = (int)(text->pos_dev.x + lines_ptr->text_origin.x); tmp_y = (int)(text->pos_dev.y + lines_ptr->text_origin.y); Tk_DrawChars(wi->dpy, wi->draw_buffer, wi->gc, - text->font, (char *) lines_ptr->start, lines_ptr->num_bytes, - tmp_x, tmp_y); + text->font, (char *) lines_ptr->start, + (int) lines_ptr->num_bytes, tmp_x, tmp_y); if (ISSET(text->flags, UNDERLINED)) { int y_under = tmp_y + underline_pos; XDrawLine(wi->dpy, wi->draw_buffer, wi->gc, - tmp_x, y_under, tmp_x+lines_ptr->width, y_under); + tmp_x, y_under, tmp_x + (int) lines_ptr->width, y_under); } if (ISSET(text->flags, OVERSTRIKED)) { int y_over = tmp_y-overstrike_pos; XDrawLine(wi->dpy, wi->draw_buffer, wi->gc, - tmp_x, y_over, tmp_x+lines_ptr->width, y_over); + tmp_x, y_over, tmp_x + (int) lines_ptr->width, y_over); } } } @@ -849,17 +848,17 @@ Draw(Item item) * ********************************************************************************** */ +#ifdef GL static void -Render(Item item) +Render(ZnItem item) { -#ifdef GLX - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; TextItem text = (TextItem) item; TextLineInfo lines, lines_ptr; - TextInfo *ti = &wi->text_info; + ZnTextInfo *ti = &wi->text_info; int i, num_lines; XColor *color; - int alpha; + unsigned short alpha; Tk_FontMetrics fm; int font_height; int underline_thickness, underline_pos=0, overstrike_pos=0; @@ -905,7 +904,7 @@ Render(Item item) if ((ti->sel_item == item) && (sel_first_line >= 0)) { ZnReal xo, yo, xc, yc; - color = ZnGetGradientColor(ti->sel_color, 0, &alpha); + color = ZnGetGradientColor(ti->sel_color, 0.0, &alpha); alpha = ZnComposeAlpha(alpha, wi->alpha); glColor4us(color->red, color->green, color->blue, alpha); glBegin(GL_QUADS); @@ -914,39 +913,39 @@ Render(Item item) yo = text->pos_dev.y + lines[sel_first_line].text_origin.y - fm.ascent; xc = xo + sel_stop_offset - sel_start_offset; yc = yo + font_height; - glVertex2f(xo, yo); - glVertex2f(xc, yo); - glVertex2f(xc, yc); - glVertex2f(xo, yc); + glVertex2d(xo, yo); + glVertex2d(xc, yo); + glVertex2d(xc, yc); + glVertex2d(xo, yc); } else { xo = text->pos_dev.x + lines[sel_first_line].text_origin.x + sel_start_offset; yo = text->pos_dev.y + lines[sel_first_line].text_origin.y - fm.ascent; xc = xo + text->max_width-lines[sel_first_line].text_origin.x-sel_start_offset; yc = yo + font_height; - glVertex2f(xo, yo); - glVertex2f(xc, yo); - glVertex2f(xc, yc); - glVertex2f(xo, yc); + glVertex2d(xo, yo); + glVertex2d(xc, yo); + glVertex2d(xc, yc); + glVertex2d(xo, yc); for (i = sel_first_line+1, lines_ptr = &lines[sel_first_line+1]; i < sel_last_line; i++, lines_ptr++) { xo = text->pos_dev.x; yo = text->pos_dev.y + lines_ptr->text_origin.y - fm.ascent; xc = xo + text->max_width; yc = yo + font_height; - glVertex2f(xo, yo); - glVertex2f(xc, yo); - glVertex2f(xc, yc); - glVertex2f(xo, yc); + glVertex2d(xo, yo); + glVertex2d(xc, yo); + glVertex2d(xc, yc); + glVertex2d(xo, yc); } xo = text->pos_dev.x; yo = text->pos_dev.y + lines[sel_last_line].text_origin.y - fm.ascent; xc = xo + lines[sel_last_line].text_origin.x+sel_stop_offset; yc = yo + font_height; - glVertex2f(xo, yo); - glVertex2f(xc, yo); - glVertex2f(xc, yc); - glVertex2f(xo, yc); + glVertex2d(xo, yo); + glVertex2d(xc, yo); + glVertex2d(xc, yc); + glVertex2d(xo, yc); } glEnd(); } @@ -958,15 +957,15 @@ Render(Item item) (wi->focus_item == item) && ti->cursor_on) { int xs, ys; - color = ZnGetGradientColor(ti->insert_color, 0, &alpha); + color = ZnGetGradientColor(ti->insert_color, 0.0, &alpha); alpha = ZnComposeAlpha(alpha, wi->alpha); glColor4us(color->red, color->green, color->blue, alpha); - glLineWidth(ti->insert_width); - xs = text->pos_dev.x + lines[cursor_line].text_origin.x + cursor_offset; - ys = text->pos_dev.y + lines[cursor_line].text_origin.y - fm.ascent + 1; + glLineWidth((GLfloat) ti->insert_width); + xs = (int) (text->pos_dev.x + lines[cursor_line].text_origin.x) + cursor_offset; + ys = (int) (text->pos_dev.y + lines[cursor_line].text_origin.y) - fm.ascent + 1; glBegin(GL_LINES); - glVertex2f(xs, ys); - glVertex2f(xs, ys + font_height - 1); + glVertex2i(xs, ys); + glVertex2i(xs, ys + font_height - 1); glEnd(); } @@ -976,7 +975,7 @@ Render(Item item) glEnable(GL_TEXTURE_2D); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glBindTexture(GL_TEXTURE_2D, ZnTexFontTex(text->tfi)); - color = ZnGetGradientColor(text->color, 0, &alpha); + color = ZnGetGradientColor(text->color, 0.0, &alpha); alpha = ZnComposeAlpha(alpha, wi->alpha); glColor4us(color->red, color->green, color->blue, alpha); @@ -987,23 +986,23 @@ Render(Item item) ys = text->pos_dev.y + lines_ptr->text_origin.y; glPushMatrix(); - glTranslatef(xs, ys, 0.0); + glTranslated(xs, ys, 0.0); ZnRenderString(text->tfi, lines_ptr->start, lines_ptr->num_bytes); glPopMatrix(); if (ISSET(text->flags, UNDERLINED) || ISSET(text->flags, OVERSTRIKED)) { - glLineWidth(underline_thickness); + glLineWidth((GLfloat) underline_thickness); glDisable(GL_TEXTURE_2D); if (ISSET(text->flags, UNDERLINED)) { glBegin(GL_LINES); - glVertex2f(xs, ys+underline_pos); - glVertex2f(xs+lines_ptr->width, ys+underline_pos); + glVertex2d(xs, ys+underline_pos); + glVertex2d(xs+lines_ptr->width, ys+underline_pos); glEnd(); } if (ISSET(text->flags, OVERSTRIKED)) { glBegin(GL_LINES); - glVertex2f(xs, ys-overstrike_pos); - glVertex2f(xs+lines_ptr->width, ys-overstrike_pos); + glVertex2d(xs, ys-overstrike_pos); + glVertex2d(xs+lines_ptr->width, ys-overstrike_pos); glEnd(); } glEnable(GL_TEXTURE_2D); @@ -1016,8 +1015,13 @@ Render(Item item) glCallList(item->gl_list); #endif -#endif } +#else +static void +Render(ZnItem item __unused) +{ +} +#endif /* @@ -1028,10 +1032,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)); } @@ -1044,7 +1048,7 @@ IsSensitive(Item item, ********************************************************************************** */ static double -Pick(Item item, +Pick(ZnItem item, ZnPick ps) { TextItem text = (TextItem) item; @@ -1069,12 +1073,12 @@ Pick(Item item, } for (i = 0, lines_ptr = lines; i < num_lines; i++, lines_ptr++) { - ResetBBox(&line_bbox); + ZnResetBBox(&line_bbox); o.x = text->pos_dev.x + lines_ptr->text_origin.x; o.y = text->pos_dev.y + lines_ptr->text_origin.y - fm.ascent; - AddPointToBBox(&line_bbox, o.x, o.y); - AddPointToBBox(&line_bbox, o.x + lines_ptr->width, o.y + font_height); - new_dist = RectangleToPointDist(&line_bbox, p); + ZnAddPointToBBox(&line_bbox, o.x, o.y); + ZnAddPointToBBox(&line_bbox, o.x + lines_ptr->width, o.y + font_height); + new_dist = ZnRectangleToPointDist(&line_bbox, p); dist = MIN(dist, new_dist); if (dist <= 0.0) { dist = 0.0; @@ -1094,8 +1098,8 @@ Pick(Item item, ********************************************************************************** */ static void -PostScript(Item item, - PostScriptInfo ps_info) +PostScript(ZnItem item __unused, + ZnPostScriptInfo ps_info __unused) { } @@ -1108,17 +1112,17 @@ PostScript(Item item, ********************************************************************************** */ static void -GetAnchor(Item item, - ZnAnchor anchor, +GetAnchor(ZnItem item, + Tk_Anchor anchor, ZnPoint *p) { TextItem text = (TextItem) item; if (text->num_chars != 0) { - Origin2Anchor(&text->pos_dev, - item->item_bounding_box.corner.x-item->item_bounding_box.orig.x, - item->item_bounding_box.corner.y-item->item_bounding_box.orig.y, - anchor, p); + ZnOrigin2Anchor(&text->pos_dev, + item->item_bounding_box.corner.x-item->item_bounding_box.orig.x, + item->item_bounding_box.corner.y-item->item_bounding_box.orig.y, + anchor, p); } else { p->x = p->y = 0.0; @@ -1131,19 +1135,19 @@ GetAnchor(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) { ZnPoint *points; ZnListAssertSize(item->wi->work_pts, 2); points = (ZnPoint *) ZnListArray(item->wi->work_pts); - TRI_STRIP1(tristrip, points, 2, False); + ZnTriStrip1(tristrip, points, 2, False); points[0] = item->item_bounding_box.orig; points[1] = item->item_bounding_box.corner; @@ -1162,35 +1166,35 @@ GetClipVertices(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 __unused, + int cmd, + ZnPoint **pts, + char **controls __unused, + unsigned int *num_pts) { TextItem text = (TextItem) item; - if ((cmd == COORDS_ADD) || (cmd == COORDS_ADD_LAST) || (cmd == COORDS_REMOVE)) { + if ((cmd == ZN_COORDS_ADD) || (cmd == ZN_COORDS_ADD_LAST) || (cmd == ZN_COORDS_REMOVE)) { Tcl_AppendResult(item->wi->interp, " texts can't add or remove vertices", NULL); - return ZN_ERROR; + return TCL_ERROR; } - else if ((cmd == COORDS_REPLACE) || (cmd == COORDS_REPLACE_ALL)) { + else if ((cmd == ZN_COORDS_REPLACE) || (cmd == ZN_COORDS_REPLACE_ALL)) { if (*num_pts == 0) { Tcl_AppendResult(item->wi->interp, " coords command need 1 point on texts", NULL); - return ZN_ERROR; + return TCL_ERROR; } text->pos = (*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)) { *num_pts = 1; *pts = &text->pos; } - return ZN_OK; + return TCL_OK; } @@ -1217,8 +1221,8 @@ PointToChar(TextItem text, return 0; } - x -= text->pos_dev.x; - y -= text->pos_dev.y; + x -= (int) text->pos_dev.x; + y -= (int) text->pos_dev.y; /* * Point above text, returns index 0. @@ -1251,8 +1255,8 @@ PointToChar(TextItem text, byte_index = p->start + p->num_bytes - text->text; break; } - n = Tk_MeasureChars(text->font, p->start, p->num_bytes, - x + 2 - p->text_origin.x, TK_PARTIAL_OK, &dummy); + n = Tk_MeasureChars(text->font, p->start, (int) p->num_bytes, + x + 2 - (int) p->text_origin.x, TK_PARTIAL_OK, &dummy); byte_index = (p->start + n - 1) - text->text; break; } @@ -1282,19 +1286,19 @@ PointToChar(TextItem text, * */ static int -MoveFromIndex(TextItem text, - int char_index, - int move) +MoveFromIndex(TextItem text, + unsigned int char_index, + int move) { - int num_lines, byte_index, num_bytes=0; - int line_index, line_start=0; + unsigned int num_lines, byte_index, num_bytes=0; + unsigned int line_index, line_start=0; TextLineInfo lines, p; char *strp; if (!text->text_info || !text->text) { return char_index; } - byte_index = Tcl_UtfAtIndex(text->text, char_index)-text->text; + byte_index = Tcl_UtfAtIndex(text->text, (int) char_index)-text->text; num_lines = ZnListSize(text->text_info); lines = p = ZnListArray(text->text_info); for (line_index = 0; line_index < num_lines; line_index++, p++) { @@ -1354,23 +1358,23 @@ MoveFromIndex(TextItem text, byte_index += line_start; } convert_it: - Tcl_NumUtfChars(text->text, byte_index); + char_index = Tcl_NumUtfChars(text->text, (int) byte_index); default: return char_index; } } static int -Index(Item item, - int field, +Index(ZnItem item, + int field __unused, Tcl_Obj *index_spec, int *index) { TextItem text = (TextItem) item; - WidgetInfo *wi = item->wi; - TextInfo *ti = &wi->text_info; - int c, length; - int x, y; + ZnWInfo *wi = item->wi; + ZnTextInfo *ti = &wi->text_info; + unsigned int length; + int c, x, y; double tmp; char *end, *p; @@ -1430,14 +1434,14 @@ Index(Item item, goto badIndex; } /*x = (int) ((tmp < 0) ? tmp - 0.5 : tmp + 0.5);*/ - x = tmp; + x = (int) tmp; p = end+1; tmp = strtod(p, &end); if ((end == p) || (*end != 0)) { goto badIndex; } /*y = (int) ((tmp < 0) ? tmp - 0.5 : tmp + 0.5);*/ - y = tmp; + y = (int) tmp; *index = PointToChar(text, x, y); } @@ -1445,7 +1449,7 @@ Index(Item item, if (*index < 0){ *index = 0; } - else if (*index > text->num_chars) { + else if ((unsigned int) *index > text->num_chars) { *index = text->num_chars; } } @@ -1467,14 +1471,14 @@ Index(Item item, ********************************************************************************** */ static void -InsertChars(Item item, - int field, +InsertChars(ZnItem item, + int field __unused, int *index, char *chars) { TextItem text = (TextItem) item; - TextInfo *ti = &item->wi->text_info; - int num_chars, byte_index, num_bytes = strlen(chars); + ZnTextInfo *ti = &item->wi->text_info; + unsigned int num_chars, byte_index, num_bytes = strlen(chars); char *new; if (num_bytes == 0) { @@ -1483,26 +1487,28 @@ InsertChars(Item item, if (*index < 0) { *index = 0; } - if (*index > text->num_chars) { + if ((unsigned int) *index > text->num_chars) { *index = text->num_chars; } - byte_index = Tcl_UtfAtIndex(text->text, *index)-text->text; - num_chars = Tcl_NumUtfChars(chars, num_bytes); + num_chars = Tcl_NumUtfChars(chars, (int) num_bytes); if (text->text) { + byte_index = Tcl_UtfAtIndex(text->text, *index)-text->text; new = ZnMalloc(strlen(text->text) + num_bytes + 1); memcpy(new, text->text, (size_t) byte_index); strcpy(new + byte_index + num_bytes, text->text + byte_index); ZnFree(text->text); } else { + byte_index = 0; new = ZnMalloc(num_bytes + 1); + new[num_bytes] = 0; } - strcpy(new + byte_index, chars); + memcpy(new + byte_index, chars, num_bytes); text->text = new; text->num_chars += num_chars; - if (text->insert_index >= *index) { + if (text->insert_index >= (unsigned int) *index) { text->insert_index += num_chars; } if (ti->sel_item == item) { @@ -1517,7 +1523,7 @@ InsertChars(Item item, } } - ITEM.Invalidate(item, ZN_COORDS_FLAG|ZN_LAYOUT_FLAG); + ZnITEM.Invalidate(item, ZN_COORDS_FLAG|ZN_LAYOUT_FLAG); } @@ -1529,15 +1535,15 @@ InsertChars(Item item, ********************************************************************************** */ static void -DeleteChars(Item item, - int field, +DeleteChars(ZnItem item, + int field __unused, int *first, int *last) { TextItem text = (TextItem) item; int byte_count, first_offset; int char_count, num_bytes; - TextInfo *ti = &item->wi->text_info; + ZnTextInfo *ti = &item->wi->text_info; char *new; if (!text->text) { @@ -1546,7 +1552,7 @@ DeleteChars(Item item, if (*first < 0) { *first = 0; } - if (*last >= text->num_chars) { + if (*last >= (int) text->num_chars) { *last = text->num_chars-1; } if (*first > *last) { @@ -1572,9 +1578,9 @@ DeleteChars(Item item, text->num_chars = 0; } - if (text->insert_index > *first) { + if (text->insert_index > (unsigned int) *first) { text->insert_index -= char_count; - if (text->insert_index < *first) { + if (text->insert_index < (unsigned int) *first) { text->insert_index = *first; } } @@ -1602,7 +1608,7 @@ DeleteChars(Item item, } } - ITEM.Invalidate(item, ZN_COORDS_FLAG|ZN_LAYOUT_FLAG); + ZnITEM.Invalidate(item, ZN_COORDS_FLAG|ZN_LAYOUT_FLAG); } @@ -1614,16 +1620,16 @@ DeleteChars(Item item, ********************************************************************************** */ static void -TextCursor(Item item, - int field, - int index) +TextCursor(ZnItem item, + int field __unused, + int index) { TextItem text = (TextItem) item; if (index < 0) { text->insert_index = 0; } - else if (index > text->num_chars) { + else if ((unsigned int) index > text->num_chars) { text->insert_index = text->num_chars; } else { @@ -1640,15 +1646,15 @@ TextCursor(Item item, ********************************************************************************** */ static int -Selection(Item item, - int field, - int offset, - char *chars, - int max_bytes) +Selection(ZnItem item, + int field __unused, + int offset, + char *chars, + int max_bytes) { TextItem text = (TextItem) item; - WidgetInfo *wi = item->wi; - TextInfo *ti = &wi->text_info; + ZnWInfo *wi = item->wi; + ZnTextInfo *ti = &wi->text_info; int count; char const *sel_first, *sel_last; @@ -1682,7 +1688,7 @@ Selection(Item item, * ********************************************************************************** */ -static ItemClassStruct TEXT_ITEM_CLASS = { +static ZnItemClassStruct TEXT_ITEM_CLASS = { sizeof(TextItemStruct), 0, /* num_parts */ True, /* has_anchors */ diff --git a/generic/Track.c b/generic/Track.c index ab3a79e..95f6ac1 100644 --- a/generic/Track.c +++ b/generic/Track.c @@ -27,12 +27,12 @@ */ +#include "Types.h" #include "Track.h" #include "Draw.h" #include "Geo.h" #include "Item.h" #include "Group.h" -#include "Types.h" #include "WidgetInfo.h" #include "Image.h" #include "tkZinc.h" @@ -50,6 +50,17 @@ static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ " */ #undef DP +/* + * Some default values +*/ +#define DEFAULT_MARKER_SIZE 0 +#define DEFAULT_LABEL_ANGLE 20 +#define DEFAULT_LABEL_DISTANCE 50 +#define DEFAULT_LINE_WIDTH 1 +#define DEFAULT_LABEL_PREFERRED_ANGLE 0 +#define DEFAULT_CONVERGENCE_STYLE 0 +#define DEFAULT_VISIBLE_HISTORY_SIZE 6 + #define SPEED_VECTOR_PICKING_THRESHOLD 5 /* In pixels */ /* @@ -76,12 +87,12 @@ static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ " /* - ********************************************************************************** - * - * Specific Track item record - * - ********************************************************************************** - */ +********************************************************************************** +* +* Specific Track item record +* +********************************************************************************** +*/ typedef struct { ZnPoint world; /* world coord of pos */ ZnPoint dev; /* dev coord of pos */ @@ -89,7 +100,7 @@ typedef struct { } HistoryStruct, *History; typedef struct _TrackItemStruct { - ItemStruct header; + ZnItemStruct header; /* Public data */ unsigned short flags; @@ -101,30 +112,30 @@ typedef struct _TrackItemStruct { ZnDim label_dy; int label_preferred_angle; int label_convergence_style; - ZnAnchor label_anchor; - LeaderAnchors leader_anchors; /* Spec of the leader attachment */ + Tk_Anchor label_anchor; + ZnLeaderAnchors leader_anchors; /* Spec of the leader attachment */ ZnGradient *leader_color; /* leader color */ - LineStyle leader_style; - LineShape leader_shape; + ZnLineStyle leader_style; + ZnLineShape leader_shape; ZnLineEnd leader_first_end; ZnLineEnd leader_last_end; ZnDim leader_width; ZnDim marker_size; /* world size of error circle */ ZnGradient *marker_color; /* error circle color */ - LineStyle marker_style; /* error circle style */ + ZnLineStyle marker_style; /* error circle style */ ZnImage marker_fill_pattern; /* error circle fill pattern */ ZnGradient *connection_color; /* connection color */ - LineStyle connection_style; + ZnLineStyle connection_style; ZnDim connection_width; ZnGradient *speed_vector_color; /* s. v. color */ - int visible_history_size; /* Number of visible positions */ + unsigned int visible_history_size; /* Number of visible positions */ ZnPoint pos; /* item world coordinates */ ZnPoint speed_vector; /* s. v. slope in world coord */ ZnDim speed_vector_width; ZnGradient *history_color; /* Private data */ - FieldSetStruct field_set; + ZnFieldSetStruct field_set; ZnPoint dev; /* device coords of current pos */ ZnPoint speed_vector_dev; /* s. v. end in device coord */ ZnDim marker_size_dev; /* dev size of error circle */ @@ -137,13 +148,13 @@ static ZnAttrConfig track_attrs[] = { { ZN_CONFIG_BOOL, "-circlehistory", NULL, Tk_Offset(TrackItemStruct, flags), CIRCLE_HISTORY_BIT, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-composealpha", NULL, - Tk_Offset(TrackItemStruct, header.flags), COMPOSE_ALPHA_BIT, + Tk_Offset(TrackItemStruct, header.flags), ZN_COMPOSE_ALPHA_BIT, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-composerotation", NULL, - Tk_Offset(TrackItemStruct, header.flags), COMPOSE_ROTATION_BIT, + Tk_Offset(TrackItemStruct, header.flags), ZN_COMPOSE_ROTATION_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_BOOL, "-composescale", NULL, - Tk_Offset(TrackItemStruct, header.flags), COMPOSE_SCALE_BIT, + Tk_Offset(TrackItemStruct, header.flags), ZN_COMPOSE_SCALE_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_ITEM, "-connecteditem", NULL, Tk_Offset(TrackItemStruct, header.connected_item), 0, @@ -151,7 +162,7 @@ static ZnAttrConfig track_attrs[] = { { ZN_CONFIG_GRADIENT, "-connectioncolor", NULL, Tk_Offset(TrackItemStruct, connection_color), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-connectionsensitive", NULL, - Tk_Offset(TrackItemStruct, header.part_sensitive), PART_NUMBER_TO_BIT(CONNECTION), + Tk_Offset(TrackItemStruct, header.part_sensitive), ZnPartToBit(CONNECTION), ZN_REPICK_FLAG, False }, { ZN_CONFIG_LINE_STYLE, "-connectionstyle", NULL, Tk_Offset(TrackItemStruct, connection_style), 0, ZN_DRAW_FLAG, False }, @@ -197,7 +208,7 @@ static ZnAttrConfig track_attrs[] = { { ZN_CONFIG_LINE_END, "-leaderlastend", NULL, Tk_Offset(TrackItemStruct, leader_last_end), 0, ZN_COORDS_FLAG, False }, { ZN_CONFIG_BOOL, "-leadersensitive", NULL, - Tk_Offset(TrackItemStruct, header.part_sensitive), PART_NUMBER_TO_BIT(LEADER), + Tk_Offset(TrackItemStruct, header.part_sensitive), ZnPartToBit(LEADER), ZN_REPICK_FLAG, False }, { ZN_CONFIG_LINE_STYLE, "-leaderstyle", NULL, Tk_Offset(TrackItemStruct, leader_style), 0, ZN_DRAW_FLAG, False }, @@ -223,7 +234,7 @@ static ZnAttrConfig track_attrs[] = { Tk_Offset(TrackItemStruct, header.priority), 0, ZN_DRAW_FLAG|ZN_REPICK_FLAG, False }, { ZN_CONFIG_BOOL, "-sensitive", NULL, - Tk_Offset(TrackItemStruct, header.flags), SENSITIVE_BIT, ZN_REPICK_FLAG, False }, + Tk_Offset(TrackItemStruct, header.flags), ZN_SENSITIVE_BIT, ZN_REPICK_FLAG, False }, { ZN_CONFIG_POINT, "-speedvector", NULL, Tk_Offset(TrackItemStruct, speed_vector), 0, ZN_COORDS_FLAG, False }, { ZN_CONFIG_GRADIENT, "-speedvectorcolor", NULL, @@ -231,7 +242,7 @@ static ZnAttrConfig track_attrs[] = { { ZN_CONFIG_BOOL, "-speedvectormark", NULL, Tk_Offset(TrackItemStruct, flags), SV_MARK_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_BOOL, "-speedvectorsensitive", NULL, - Tk_Offset(TrackItemStruct, header.part_sensitive), PART_NUMBER_TO_BIT(SPEED_VECTOR), + Tk_Offset(TrackItemStruct, header.part_sensitive), ZnPartToBit(SPEED_VECTOR), ZN_REPICK_FLAG, False }, { ZN_CONFIG_BOOL, "-speedvectorticks", NULL, Tk_Offset(TrackItemStruct, flags), SV_TICKS_BIT, ZN_DRAW_FLAG, False }, @@ -242,28 +253,28 @@ static ZnAttrConfig track_attrs[] = { { ZN_CONFIG_GRADIENT, "-symbolcolor", NULL, Tk_Offset(TrackItemStruct, symbol_color), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-symbolsensitive", NULL, - Tk_Offset(TrackItemStruct, header.part_sensitive), PART_NUMBER_TO_BIT(CURRENT_POSITION), + Tk_Offset(TrackItemStruct, header.part_sensitive), ZnPartToBit(CURRENT_POSITION), ZN_REPICK_FLAG, False }, { ZN_CONFIG_TAG_LIST, "-tags", NULL, Tk_Offset(TrackItemStruct, header.tags), 0, 0, False }, { ZN_CONFIG_BOOL, "-visible", NULL, - Tk_Offset(TrackItemStruct, header.flags), VISIBLE_BIT, + Tk_Offset(TrackItemStruct, header.flags), ZN_VISIBLE_BIT, ZN_DRAW_FLAG|ZN_REPICK_FLAG|ZN_VIS_FLAG, False }, { ZN_CONFIG_UINT, "-visiblehistorysize", NULL, Tk_Offset(TrackItemStruct, visible_history_size), 0, ZN_DRAW_FLAG, False }, - { ZN_CONFIG_END, NULL, NULL, 0, 0, 0 } + { ZN_CONFIG_END, NULL, NULL, 0, 0, 0, False } }; static ZnAttrConfig wp_attrs[] = { { ZN_CONFIG_BOOL, "-composealpha", NULL, - Tk_Offset(TrackItemStruct, header.flags), COMPOSE_ALPHA_BIT, + Tk_Offset(TrackItemStruct, header.flags), ZN_COMPOSE_ALPHA_BIT, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-composerotation", NULL, - Tk_Offset(TrackItemStruct, header.flags), COMPOSE_ROTATION_BIT, + Tk_Offset(TrackItemStruct, header.flags), ZN_COMPOSE_ROTATION_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_BOOL, "-composescale", NULL, - Tk_Offset(TrackItemStruct, header.flags), COMPOSE_SCALE_BIT, + Tk_Offset(TrackItemStruct, header.flags), ZN_COMPOSE_SCALE_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_ITEM, "-connecteditem", NULL, Tk_Offset(TrackItemStruct, header.connected_item), 0, @@ -271,7 +282,7 @@ static ZnAttrConfig wp_attrs[] = { { ZN_CONFIG_GRADIENT, "-connectioncolor", NULL, Tk_Offset(TrackItemStruct, connection_color), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-connectionsensitive", NULL, - Tk_Offset(TrackItemStruct, header.part_sensitive), PART_NUMBER_TO_BIT(CONNECTION), + Tk_Offset(TrackItemStruct, header.part_sensitive), ZnPartToBit(CONNECTION), ZN_REPICK_FLAG, False }, { ZN_CONFIG_LINE_STYLE, "-connectionstyle", NULL, Tk_Offset(TrackItemStruct, connection_style), 0, ZN_DRAW_FLAG, False }, @@ -305,7 +316,7 @@ static ZnAttrConfig wp_attrs[] = { { ZN_CONFIG_LINE_END, "-leaderlastend", NULL, Tk_Offset(TrackItemStruct, leader_last_end), 0, ZN_COORDS_FLAG, False }, { ZN_CONFIG_BOOL, "-leadersensitive", NULL, - Tk_Offset(TrackItemStruct, header.part_sensitive), PART_NUMBER_TO_BIT(LEADER), + Tk_Offset(TrackItemStruct, header.part_sensitive), ZnPartToBit(LEADER), ZN_REPICK_FLAG, False }, { ZN_CONFIG_LINE_SHAPE, "-leadershape", NULL, Tk_Offset(TrackItemStruct, leader_shape), 0, ZN_COORDS_FLAG, False }, @@ -329,55 +340,56 @@ static ZnAttrConfig wp_attrs[] = { Tk_Offset(TrackItemStruct, header.priority), 0, ZN_DRAW_FLAG|ZN_REPICK_FLAG, False }, { ZN_CONFIG_BOOL, "-sensitive", NULL, - Tk_Offset(TrackItemStruct, header.flags), SENSITIVE_BIT, ZN_REPICK_FLAG, False }, + Tk_Offset(TrackItemStruct, header.flags), ZN_SENSITIVE_BIT, ZN_REPICK_FLAG, False }, { ZN_CONFIG_BITMAP, "-symbol", NULL, Tk_Offset(TrackItemStruct, symbol), 0, ZN_COORDS_FLAG, False }, { ZN_CONFIG_GRADIENT, "-symbolcolor", NULL, Tk_Offset(TrackItemStruct, symbol_color), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-symbolsensitive", NULL, - Tk_Offset(TrackItemStruct, header.part_sensitive), PART_NUMBER_TO_BIT(CURRENT_POSITION), + Tk_Offset(TrackItemStruct, header.part_sensitive), ZnPartToBit(CURRENT_POSITION), ZN_REPICK_FLAG, False }, { ZN_CONFIG_TAG_LIST, "-tags", NULL, Tk_Offset(TrackItemStruct, header.tags), 0, 0, False }, { ZN_CONFIG_BOOL, "-visible", NULL, - Tk_Offset(TrackItemStruct, header.flags), VISIBLE_BIT, + Tk_Offset(TrackItemStruct, 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 } }; /* - ********************************************************************************** - * - * Init -- - * - ********************************************************************************** - */ +********************************************************************************** +* +* Init -- +* +********************************************************************************** +*/ static int -Init(Item item, +Init(ZnItem item, int *argc, Tcl_Obj *CONST *args[]) { TrackItem track = (TrackItem) item; - FieldSet field_set = &track->field_set; - WidgetInfo *wi = item->wi; - + ZnFieldSet field_set = &track->field_set; + ZnWInfo *wi = item->wi; + int num_fields; + /*printf("size of a track = %d\n", sizeof(TrackItemStruct));*/ - 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); - SET(item->part_sensitive, PART_NUMBER_TO_BIT(CURRENT_POSITION)); - SET(item->part_sensitive, PART_NUMBER_TO_BIT(LEADER)); - SET(item->part_sensitive, PART_NUMBER_TO_BIT(CONNECTION)); - SET(item->part_sensitive, PART_NUMBER_TO_BIT(SPEED_VECTOR)); + 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); + SET(item->part_sensitive, ZnPartToBit(CURRENT_POSITION)); + SET(item->part_sensitive, ZnPartToBit(LEADER)); + SET(item->part_sensitive, ZnPartToBit(CONNECTION)); + SET(item->part_sensitive, ZnPartToBit(SPEED_VECTOR)); track->symbol_color = ZnGetGradientByValue(wi->fore_color); track->symbol = ZnGetBitmap(wi, Tk_GetUid("AtcSymbol15")); - track->label_anchor = ZnAnchorCenter; + track->label_anchor = TK_ANCHOR_CENTER; track->label_angle = DEFAULT_LABEL_ANGLE; track->label_distance = DEFAULT_LABEL_DISTANCE; SET(track->flags, POLAR_BIT); @@ -388,14 +400,14 @@ Init(Item item, track->leader_anchors = NULL; track->leader_color = ZnGetGradientByValue(wi->fore_color); - track->leader_style = LINE_SIMPLE; - track->leader_shape = LINE_STRAIGHT; + track->leader_style = ZN_LINE_SIMPLE; + track->leader_shape = ZN_LINE_STRAIGHT; track->leader_width = DEFAULT_LINE_WIDTH; track->connection_color = ZnGetGradientByValue(wi->fore_color); - track->connection_style = LINE_SIMPLE; + track->connection_style = ZN_LINE_SIMPLE; track->connection_width = DEFAULT_LINE_WIDTH; track->marker_color = ZnGetGradientByValue(wi->fore_color); - track->marker_style = LINE_SIMPLE; + track->marker_style = ZN_LINE_SIMPLE; track->marker_fill_pattern = ZnUnspecifiedImage; track->speed_vector_color = ZnGetGradientByValue(wi->fore_color); track->history_color = ZnGetGradientByValue(wi->fore_color); @@ -408,7 +420,7 @@ Init(Item item, CLEAR(track->flags, SV_TICKS_BIT); if (item->class == ZnTrack) { - item->priority = DEFAULT_TRACK_PRIORITY; + item->priority = 1; track->visible_history_size = DEFAULT_VISIBLE_HISTORY_SIZE; track->marker_size = DEFAULT_MARKER_SIZE; track->speed_vector.x = 0; @@ -416,7 +428,7 @@ Init(Item item, track->speed_vector_width = DEFAULT_LINE_WIDTH; } else { - item->priority = DEFAULT_WAY_POINT_PRIORITY; + item->priority = 1; track->visible_history_size = 0; track->marker_size = 0; track->speed_vector.x = 0.0; @@ -428,14 +440,15 @@ Init(Item item, * Then try to see if some fields are needed. */ if ((*argc > 0) && (Tcl_GetString((*args)[0])[0] != '-') && - (Tcl_GetIntFromObj(wi->interp, (*args)[0], &field_set->num_fields) != ZN_ERROR)) { + (Tcl_GetIntFromObj(wi->interp, (*args)[0], &num_fields) != TCL_ERROR)) { + field_set->num_fields = num_fields; *args += 1; *argc -= 1; - FIELD.InitFields(field_set); + ZnFIELD.InitFields(field_set); } else { Tcl_AppendResult(wi->interp, " number of fields expected", NULL); - return ZN_ERROR; + return TCL_ERROR; } track->pos.x = 0; @@ -453,19 +466,19 @@ Init(Item item, track->marker_size_dev = 0; track->leader_points = NULL; - return ZN_OK; + return TCL_OK; } /* - ********************************************************************************** - * - * Clone -- - * - ********************************************************************************** - */ +********************************************************************************** +* +* Clone -- +* +********************************************************************************** +*/ static void -Clone(Item item) +Clone(ZnItem item) { TrackItem track = (TrackItem) item; @@ -481,13 +494,13 @@ Clone(Item item) track->leader_points = ZnListDuplicate(track->leader_points); } if (track->leader_first_end) { - LineEndDuplicate(track->leader_first_end); + ZnLineEndDuplicate(track->leader_first_end); } if (track->leader_last_end) { - LineEndDuplicate(track->leader_last_end); + ZnLineEndDuplicate(track->leader_last_end); } - FIELD.CloneFields(&track->field_set); + ZnFIELD.CloneFields(&track->field_set); track->field_set.item = item; /* @@ -509,14 +522,14 @@ Clone(Item item) /* - ********************************************************************************** - * - * Destroy -- - * - ********************************************************************************** - */ +********************************************************************************** +* +* Destroy -- +* +********************************************************************************** +*/ static void -Destroy(Item item) +Destroy(ZnItem item) { TrackItem track = (TrackItem) item; @@ -524,10 +537,10 @@ Destroy(Item item) ZnListFree(track->leader_points); } if (track->leader_first_end) { - LineEndDelete(track->leader_first_end); + ZnLineEndDelete(track->leader_first_end); } if (track->leader_last_end) { - LineEndDelete(track->leader_last_end); + ZnLineEndDelete(track->leader_last_end); } if (track->history) { @@ -552,22 +565,22 @@ Destroy(Item item) track->marker_fill_pattern = ZnUnspecifiedImage; } - FIELD.FreeFields(&track->field_set); + ZnFIELD.FreeFields(&track->field_set); } /* - ********************************************************************************** - * - * Configure -- - * - ********************************************************************************** - */ +********************************************************************************** +* +* Configure -- +* +********************************************************************************** +*/ static void AddToHistory(TrackItem track, ZnPoint old_pos) { - WidgetInfo *wi = ((Item) track)->wi; + ZnWInfo *wi = ((ZnItem) track)->wi; /*printf("Track moved, manage history: %d\n", wi->track_manage_history);*/ if (track->history) { @@ -586,26 +599,26 @@ AddToHistory(TrackItem track, * is not valid. */ /*printf("creating history\n");*/ track->history = ZnListNew(wi->track_managed_history_size+1, - sizeof(HistoryStruct)); + sizeof(HistoryStruct)); } } static int -Configure(Item item, +Configure(ZnItem item, int argc, Tcl_Obj *CONST argv[], int *flags) { TrackItem track = (TrackItem) item; - WidgetInfo *wi = item->wi; - Item old_connected; + ZnWInfo *wi = item->wi; + ZnItem old_connected; ZnPoint old_pos; old_pos = track->pos; old_connected = item->connected_item; - if (ZnConfigureAttributes(wi, item, track_attrs, argc, argv, flags) == ZN_ERROR) { - return ZN_ERROR; + if (ZnConfigureAttributes(wi, item, track_attrs, argc, argv, flags) == TCL_ERROR) { + return TCL_ERROR; } if (track->label_angle < 0) { @@ -638,7 +651,7 @@ Configure(Item item, (((item->connected_item->class == ZnTrack) || (item->connected_item->class == ZnWayPoint)) && (item->parent == item->connected_item->parent))) { - ITEM.UpdateItemDependency(item, old_connected); + ZnITEM.UpdateItemDependency(item, old_connected); } else { item->connected_item = old_connected; @@ -647,7 +660,7 @@ Configure(Item item, if (ISSET(*flags, ZN_VIS_FLAG)) { /* Record the change to trigger the overlap manager latter */ - if ((item->class == ZnTrack) && ISSET(item->flags, VISIBLE_BIT)) { + if ((item->class == ZnTrack) && ISSET(item->flags, ZN_VISIBLE_BIT)) { ZnGroupSetCallOm(item->parent, True); } } @@ -660,56 +673,56 @@ Configure(Item item, } } - return ZN_OK; + return TCL_OK; } /* - ********************************************************************************** - * - * Query -- - * - ********************************************************************************** - */ +********************************************************************************** +* +* Query -- +* +********************************************************************************** +*/ static int -Query(Item item, - int argc, +Query(ZnItem item, + int argc __unused, Tcl_Obj *CONST argv[]) { - if (ZnQueryAttribute(item->wi, item, track_attrs, argv[0]) == ZN_ERROR) { - return ZN_ERROR; + if (ZnQueryAttribute(item->wi, item, track_attrs, argv[0]) == TCL_ERROR) { + return TCL_ERROR; } - return ZN_OK; + return TCL_OK; } /* - ********************************************************************************** - * - * ComputeCoordinates -- - * - ********************************************************************************** - */ +********************************************************************************** +* +* ComputeCoordinates -- +* +********************************************************************************** +*/ static void -ComputeCoordinates(Item item, - ZnBool force) +ComputeCoordinates(ZnItem item, + ZnBool force __unused) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; TrackItem track = (TrackItem) item; - FieldSet field_set = &track->field_set; - Item c_item; + ZnFieldSet field_set = &track->field_set; + ZnItem c_item; History hist; ZnPoint old_label_pos, old_pos, p, xp; ZnDim old_label_width, old_label_height; ZnReal rotation; ZnBBox bbox; ZnPoint *points; - int num_acc_pos, i; - int num_points, alignment; + unsigned int num_points, num_acc_pos, i; + int alignment; int w2=0, h2=0, w=0, h=0; - ResetBBox(&item->item_bounding_box); + ZnResetBBox(&item->item_bounding_box); old_label_pos = field_set->label_pos; old_label_width = field_set->label_width; old_label_height = field_set->label_height; @@ -724,8 +737,8 @@ ComputeCoordinates(Item item, old_pos = track->dev; ZnTransformPoint(wi->current_transfo, &track->pos, &track->dev); - track->dev.x = REAL_TO_INT(track->dev.x); - track->dev.y = REAL_TO_INT(track->dev.y); + track->dev.x = ZnNearestInt(track->dev.x); + track->dev.y = ZnNearestInt(track->dev.y); /*printf("track pos %g %g --> %g %g\n", track->pos.x, track->pos.y, track->dev.x, track->dev.y);*/ if (track->symbol != ZnUnspecifiedImage) { ZnSizeOfImage(track->symbol, &w, &h); @@ -737,16 +750,16 @@ ComputeCoordinates(Item item, bbox.corner.x = bbox.orig.x + w; bbox.corner.y = bbox.orig.y + h; - AddBBoxToBBox(&item->item_bounding_box, &bbox); + ZnAddBBoxToBBox(&item->item_bounding_box, &bbox); } /* Here we approximate the past position sizes to the size of the current position. They are actually smaller but who care :-). In fact it is even worse as we use the overall information from the symbol font. - */ + */ if ((item->class == ZnTrack) && track->history) { - ResetBBox(&bbox); + ZnResetBBox(&bbox); num_acc_pos = ZnListSize(track->history); hist = ZnListArray(track->history); for (i = 0; i < num_acc_pos; i++) { @@ -756,7 +769,7 @@ ComputeCoordinates(Item item, bbox.orig.y = hist[i].dev.y - h2; bbox.corner.x = bbox.orig.x + w; bbox.corner.y = bbox.orig.y + h; - AddBBoxToBBox(&item->item_bounding_box, &bbox); + ZnAddBBoxToBBox(&item->item_bounding_box, &bbox); } } } @@ -768,20 +781,20 @@ ComputeCoordinates(Item item, p.x = track->pos.x + track->speed_vector.x * wi->speed_vector_length; p.y = track->pos.y + track->speed_vector.y * wi->speed_vector_length; ZnTransformPoint(wi->current_transfo, &p, &track->speed_vector_dev); - track->speed_vector_dev.x = REAL_TO_INT(track->speed_vector_dev.x); - track->speed_vector_dev.y = REAL_TO_INT(track->speed_vector_dev.y); + track->speed_vector_dev.x = ZnNearestInt(track->speed_vector_dev.x); + track->speed_vector_dev.y = ZnNearestInt(track->speed_vector_dev.y); if (ISSET(track->flags, SV_MARK_BIT)) { - int w = track->speed_vector_width + 1; - AddPointToBBox(&item->item_bounding_box, - track->speed_vector_dev.x - w, - track->speed_vector_dev.y - w); - AddPointToBBox(&item->item_bounding_box, - track->speed_vector_dev.x + w, - track->speed_vector_dev.y + w); + int w = (int) track->speed_vector_width + 1; + ZnAddPointToBBox(&item->item_bounding_box, + track->speed_vector_dev.x - w, + track->speed_vector_dev.y - w); + ZnAddPointToBBox(&item->item_bounding_box, + track->speed_vector_dev.x + w, + track->speed_vector_dev.y + w); } else { - AddPointToBBox(&item->item_bounding_box, track->speed_vector_dev.x, - track->speed_vector_dev.y); + ZnAddPointToBBox(&item->item_bounding_box, track->speed_vector_dev.x, + track->speed_vector_dev.y); } } @@ -790,11 +803,11 @@ ComputeCoordinates(Item item, */ c_item = item->connected_item; if ((c_item != ZN_NO_ITEM) && (track->connection_width > 0)) { - ResetBBox(&bbox); - w2 = track->connection_width/2; - AddPointToBBox(&item->item_bounding_box, track->dev.x-w2, track->dev.y-w2); - AddPointToBBox(&item->item_bounding_box, ((TrackItem)c_item)->dev.x+w2, - ((TrackItem)c_item)->dev.y+w2); + ZnResetBBox(&bbox); + w2 = (int) track->connection_width/2; + ZnAddPointToBBox(&item->item_bounding_box, track->dev.x-w2, track->dev.y-w2); + ZnAddPointToBBox(&item->item_bounding_box, ((TrackItem)c_item)->dev.x+w2, + ((TrackItem)c_item)->dev.y+w2); } /* @@ -806,14 +819,14 @@ ComputeCoordinates(Item item, xp.x = xp.x - track->dev.x; xp.y = xp.y - track->dev.y; track->marker_size_dev = sqrt(xp.x*xp.x + xp.y*xp.y); - track->marker_size_dev = REAL_TO_INT(track->marker_size_dev); + track->marker_size_dev = ZnNearestInt(track->marker_size_dev); if (track->marker_size_dev > PRECISION_LIMIT) { - AddPointToBBox(&item->item_bounding_box, - track->dev.x - (ZnPos) track->marker_size_dev, - track->dev.y - (ZnPos) track->marker_size_dev); - AddPointToBBox(&item->item_bounding_box, - track->dev.x + (ZnPos) track->marker_size_dev, - track->dev.y + (ZnPos) track->marker_size_dev); + ZnAddPointToBBox(&item->item_bounding_box, + track->dev.x - (ZnPos) track->marker_size_dev, + track->dev.y - (ZnPos) track->marker_size_dev); + ZnAddPointToBBox(&item->item_bounding_box, + track->dev.x + (ZnPos) track->marker_size_dev, + track->dev.y + (ZnPos) track->marker_size_dev); } /* Compute the new label bounding box. */ @@ -821,7 +834,7 @@ ComputeCoordinates(Item item, ZnDim bb_width, bb_height, dist; ZnPoint leader_end; - FIELD.GetLabelBBox(field_set, &bb_width, &bb_height); + ZnFIELD.GetLabelBBox(field_set, &bb_width, &bb_height); /* * Compute the label position. */ @@ -829,7 +842,7 @@ ComputeCoordinates(Item item, #ifdef DP /* Alternative on ne calcule pas une distance minimum mais * on fait confiance à la distance effective track->label_distance - * attention aux problemes d'arrondi de PointPolarToCartesian !!! + * attention aux problemes d'arrondi de ZnPointPolarToCartesian !!! */ dist = track->label_distance ; #else @@ -837,9 +850,9 @@ ComputeCoordinates(Item item, * Adjust the min dist spec given in label_distance by * the size of the label. */ - if ((track->label_anchor == ZnAnchorN) || - (track->label_anchor == ZnAnchorCenter) || - (track->label_anchor == ZnAnchorS)) { + if ((track->label_anchor == TK_ANCHOR_N) || + (track->label_anchor == TK_ANCHOR_CENTER) || + (track->label_anchor == TK_ANCHOR_S)) { dist = sqrt(bb_width*bb_width/4+bb_height*bb_height/4); } else { @@ -852,31 +865,31 @@ ComputeCoordinates(Item item, */ ZnTransfoDecompose(wi->current_transfo, NULL, NULL, &rotation, NULL); /*printf("rotation=%g, heading=%g, angle=%d\n", rotation, - ProjectionToAngle(track->speed_vector.x, track->speed_vector.y), + ZnProjectionToAngle(track->speed_vector.x, track->speed_vector.y), track->label_angle);*/ - rotation = ProjectionToAngle(track->speed_vector.x, track->speed_vector.y)-rotation; - PointPolarToCartesian(rotation, dist, track->label_angle, - &track->label_dx, &track->label_dy); + rotation = ZnProjectionToAngle(track->speed_vector.x, track->speed_vector.y)-rotation; + ZnPointPolarToCartesian(rotation, dist, (ZnReal) track->label_angle, + &track->label_dx, &track->label_dy); } field_set->label_pos.x = track->dev.x + track->label_dx; field_set->label_pos.y = track->dev.y - track->label_dy; - Anchor2Origin(&field_set->label_pos, bb_width, bb_height, - track->label_anchor, &field_set->label_pos); - field_set->label_pos.x = REAL_TO_INT(field_set->label_pos.x); - field_set->label_pos.y = REAL_TO_INT(field_set->label_pos.y); - - AddPointToBBox(&item->item_bounding_box, field_set->label_pos.x, - field_set->label_pos.y); - AddPointToBBox(&item->item_bounding_box, - field_set->label_pos.x + (ZnPos) bb_width, - field_set->label_pos.y + (ZnPos) bb_height); + ZnAnchor2Origin(&field_set->label_pos, bb_width, bb_height, + track->label_anchor, &field_set->label_pos); + field_set->label_pos.x = ZnNearestInt(field_set->label_pos.x); + field_set->label_pos.y = ZnNearestInt(field_set->label_pos.y); + + ZnAddPointToBBox(&item->item_bounding_box, field_set->label_pos.x, + field_set->label_pos.y); + ZnAddPointToBBox(&item->item_bounding_box, + field_set->label_pos.x + (ZnPos) bb_width, + field_set->label_pos.y + (ZnPos) bb_height); /* * Process the leader. */ if (track->leader_width > 0) { int left_x, left_y, right_x, right_y; - ZnPoint end_points[LINE_END_POINTS]; + ZnPoint end_points[ZN_LINE_END_POINTS]; /* * Compute the actual leader end in the label. @@ -892,7 +905,7 @@ ComputeCoordinates(Item item, } if (track->label_angle >= 270 || track->label_angle < 90) { if (track->leader_anchors && (left_y < 0)) { - FIELD.GetFieldBBox(field_set, left_x, &bbox); + ZnFIELD.GetFieldBBox(field_set, (unsigned int) left_x, &bbox); leader_end.x = bbox.orig.x; leader_end.y = bbox.corner.y; } @@ -900,11 +913,11 @@ ComputeCoordinates(Item item, leader_end.x = field_set->label_pos.x + left_x*bb_width/100; leader_end.y = field_set->label_pos.y + left_y*bb_height/100; } - alignment = AA_LEFT; + alignment = ZN_AA_LEFT; } else { if (track->leader_anchors && (right_y < 0)) { - FIELD.GetFieldBBox(field_set, right_x, &bbox); + ZnFIELD.GetFieldBBox(field_set, (unsigned int) right_x, &bbox); leader_end.x = bbox.corner.x; leader_end.y = bbox.corner.y; } @@ -912,34 +925,34 @@ ComputeCoordinates(Item item, leader_end.x = field_set->label_pos.x + right_x*bb_width/100; leader_end.y = field_set->label_pos.y + right_y*bb_height/100; } - alignment = AA_RIGHT; + alignment = ZN_AA_RIGHT; } - FIELD.SetFieldsAutoAlign(field_set, alignment); + ZnFIELD.SetFieldsAutoAlign(field_set, alignment); /* Clip the leader on the label's fields */ - FIELD.LeaderToLabel(field_set, &track->dev, &leader_end); + ZnFIELD.LeaderToLabel(field_set, &track->dev, &leader_end); /* Setup leader shape points */ if (!track->leader_points) { - track->leader_points = ZnListNew(LINE_SHAPE_POINTS, sizeof(ZnPoint)); + track->leader_points = ZnListNew(ZN_LINE_SHAPE_POINTS, sizeof(ZnPoint)); } - ZnGetLineShape(&track->dev, &leader_end, track->leader_width, - track->leader_shape, &bbox, track->leader_points); - AddBBoxToBBox(&item->item_bounding_box, &bbox); + ZnLineShapePoints(&track->dev, &leader_end, track->leader_width, + track->leader_shape, &bbox, track->leader_points); + ZnAddBBoxToBBox(&item->item_bounding_box, &bbox); points = (ZnPoint *) ZnListArray(track->leader_points); num_points = ZnListSize(track->leader_points); /* Setup leader ends */ if (track->leader_first_end != NULL) { - GetLineEnd(&points[0], &points[1], track->leader_width, - CapRound, track->leader_first_end, end_points); - AddPointsToBBox(&item->item_bounding_box, end_points, LINE_END_POINTS); + ZnGetLineEnd(&points[0], &points[1], track->leader_width, + CapRound, track->leader_first_end, end_points); + ZnAddPointsToBBox(&item->item_bounding_box, end_points, ZN_LINE_END_POINTS); } if (track->leader_last_end != NULL) { - GetLineEnd(&points[num_points-1], &points[num_points-2], track->leader_width, - CapRound, track->leader_last_end, end_points); - AddPointsToBBox(&item->item_bounding_box, end_points, LINE_END_POINTS); + ZnGetLineEnd(&points[num_points-1], &points[num_points-2], track->leader_width, + CapRound, track->leader_last_end, end_points); + ZnAddPointsToBBox(&item->item_bounding_box, end_points, ZN_LINE_END_POINTS); } } } @@ -952,22 +965,22 @@ ComputeCoordinates(Item item, (old_pos.x != track->dev.x) || (old_pos.y != track->dev.y)) { /* Update connected items */ - SET(item->flags, UPDATE_DEPENDENT_BIT); + SET(item->flags, ZN_UPDATE_DEPENDENT_BIT); } } /* - ********************************************************************************** - * - * ToArea -- - * Tell if the object is entirely outside (-1), - * entirely inside (1) or in between (0). - * - ********************************************************************************** - */ +********************************************************************************** +* +* ToArea -- +* Tell if the object is entirely outside (-1), +* entirely inside (1) or in between (0). +* +********************************************************************************** +*/ static int -ToArea(Item item, +ToArea(ZnItem item, ZnToArea ta) { TrackItem track = (TrackItem) item; @@ -980,7 +993,7 @@ ToArea(Item item, /* * Try the current position. */ - ResetBBox(&bbox); + ZnResetBBox(&bbox); if (track->symbol != ZnUnspecifiedImage) { ZnSizeOfImage(track->symbol, &width, &height); bbox.orig.x = track->dev.x-(width+1)/2; @@ -988,7 +1001,7 @@ ToArea(Item item, bbox.corner.x = bbox.orig.x + width; bbox.corner.y = bbox.orig.y + height; } - inside = BBoxInBBox(&bbox, area); + inside = ZnBBoxInBBox(&bbox, area); if (inside == 0) { /*printf("track pos\n");*/ return 0; @@ -997,9 +1010,9 @@ ToArea(Item item, /* * Try the fields. */ - FIELD.GetLabelBBox(&track->field_set, &lwidth, &lheight); + ZnFIELD.GetLabelBBox(&track->field_set, &lwidth, &lheight); if ((lwidth > 0.0) && (lheight > 0.0)) { - if (FIELD.FieldsToArea(&track->field_set, area) != inside) { + if (ZnFIELD.FieldsToArea(&track->field_set, area) != inside) { return 0; } } @@ -1008,30 +1021,30 @@ ToArea(Item item, * Try the leader. */ if (track->field_set.label_format && (track->leader_width > 0)) { - ZnPoint end_points[LINE_END_POINTS]; - ZnPoint *points; - int num_points; + ZnPoint end_points[ZN_LINE_END_POINTS]; + ZnPoint *points; + unsigned int num_points; points = (ZnPoint *) ZnListArray(track->leader_points); num_points = ZnListSize(track->leader_points); - width = track->leader_width > 1 ? track->leader_width : 0; - if (PolylineInBBox(points, num_points, width, - CapRound, JoinRound, area) != inside) { + lwidth = track->leader_width > 1 ? track->leader_width : 0; + if (ZnPolylineInBBox(points, num_points, lwidth, + CapRound, JoinRound, area) != inside) { /*printf("track leader\n");*/ return 0; } if (track->leader_first_end != NULL) { - GetLineEnd(&points[0], &points[1], track->leader_width, - CapRound, track->leader_first_end, end_points); - if (PolygonInBBox(end_points, LINE_END_POINTS, area, NULL) != inside) { + ZnGetLineEnd(&points[0], &points[1], track->leader_width, + CapRound, track->leader_first_end, end_points); + if (ZnPolygonInBBox(end_points, ZN_LINE_END_POINTS, area, NULL) != inside) { /*printf("track leader\n");*/ return 0; } } if (track->leader_last_end != NULL) { - GetLineEnd(&points[num_points-1], &points[num_points-2], track->leader_width, - CapRound, track->leader_last_end, end_points); - if (PolygonInBBox(end_points, LINE_END_POINTS, area, NULL) != inside) { + ZnGetLineEnd(&points[num_points-1], &points[num_points-2], track->leader_width, + CapRound, track->leader_last_end, end_points); + if (ZnPolygonInBBox(end_points, ZN_LINE_END_POINTS, area, NULL) != inside) { /*printf("track leader\n");*/ return 0; } @@ -1044,8 +1057,8 @@ ToArea(Item item, if ((item->class == ZnTrack) && (track->speed_vector_width > 0)) { pts[0] = track->dev; pts[1] = track->speed_vector_dev; - width = track->speed_vector_width > 1 ? track->speed_vector_width : 0; - if (PolylineInBBox(pts, 2, width, CapRound, JoinRound, area) != inside) { + lwidth = track->speed_vector_width > 1 ? track->speed_vector_width : 0; + if (ZnPolylineInBBox(pts, 2, lwidth, CapRound, JoinRound, area) != inside) { /*printf("track speed vector\n");*/ return 0; } @@ -1057,8 +1070,8 @@ ToArea(Item item, if ((item->connected_item != ZN_NO_ITEM) && (track->connection_width > 0)) { pts[0] = track->dev; pts[1] = ((TrackItem) item->connected_item)->dev; - width = track->connection_width > 1 ? track->connection_width : 0; - if (PolylineInBBox(pts, 2, width, CapRound, JoinRound, area) != inside) { + lwidth = track->connection_width > 1 ? track->connection_width : 0; + if (ZnPolylineInBBox(pts, 2, lwidth, CapRound, JoinRound, area) != inside) { /*printf("track connection\n");*/ return 0; } @@ -1069,27 +1082,28 @@ ToArea(Item item, /* - ********************************************************************************** - * - * Draw -- - * - ********************************************************************************** - */ +********************************************************************************** +* +* Draw -- +* +********************************************************************************** +*/ static void -Draw(Item item) +Draw(ZnItem item) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; TrackItem track = (TrackItem) item; - Item c_item; + ZnItem c_item; XGCValues values; History hist; - int h_side_size, side_size, width=0, height=0; - int i, nb_hist, num_acc_pos; + unsigned int h_side_size, side_size, width=0, height=0; + unsigned int i, nb_hist, num_acc_pos, visible_history_size; + int x, y; /* Draw the marker */ if (track->marker_size_dev != 0) { ZnSetLineStyle(wi, track->marker_style); - values.foreground = ZnPixel(ZnGetGradientColor(track->marker_color, 0, NULL)); + values.foreground = ZnPixel(ZnGetGradientColor(track->marker_color, 0.0, NULL)); values.line_width = 0; if (ISSET(track->flags, MARKER_FILLED_BIT)) { if (track->marker_fill_pattern == ZnUnspecifiedImage) { @@ -1100,23 +1114,25 @@ Draw(Item item) else { /* Fill stippled */ values.fill_style = FillStippled; - values.stipple = ZnImagePixmap(track->marker_fill_pattern, NULL); + values.stipple = ZnImagePixmap(track->marker_fill_pattern); XChangeGC(wi->dpy, wi->gc, GCFillStyle | GCStipple | GCLineWidth | GCForeground, &values); } XFillArc(wi->dpy, wi->draw_buffer, wi->gc, - track->dev.x - (ZnPos) track->marker_size_dev, - track->dev.y - (ZnPos) track->marker_size_dev, - track->marker_size_dev * 2, track->marker_size_dev * 2, + (int) (track->dev.x - (ZnPos) track->marker_size_dev), + (int) (track->dev.y - (ZnPos) track->marker_size_dev), + (unsigned int) track->marker_size_dev * 2, + (unsigned int) track->marker_size_dev * 2, 0, 360 * 64); } else { values.fill_style = FillSolid; XChangeGC(wi->dpy, wi->gc, GCFillStyle | GCLineWidth | GCForeground, &values); XDrawArc(wi->dpy, wi->draw_buffer, wi->gc, - track->dev.x - (ZnPos) track->marker_size_dev, - track->dev.y - (ZnPos) track->marker_size_dev, - track->marker_size_dev * 2, track->marker_size_dev * 2, + (int) (track->dev.x - (ZnPos) track->marker_size_dev), + (int) (track->dev.y - (ZnPos) track->marker_size_dev), + (unsigned int) (track->marker_size_dev * 2), + (unsigned int) (track->marker_size_dev * 2), 0, 360 * 64); } } @@ -1131,56 +1147,59 @@ Draw(Item item) pts[0] = track->dev; pts[1] = ((TrackItem) item->connected_item)->dev; ZnDrawLineShape(wi, pts, 2, track->connection_style, - ZnGetGradientColor(track->connection_color, 0, NULL), - track->connection_width, LINE_STRAIGHT); + ZnGetGradientColor(track->connection_color, 0.0, NULL), + track->connection_width, ZN_LINE_STRAIGHT); } /* * Draw the speed vector. */ if ((item->class == ZnTrack) && (track->speed_vector_width > 0)) { - values.foreground = ZnPixel(ZnGetGradientColor(track->speed_vector_color, 0, NULL)); - values.line_width = track->speed_vector_width > 1 ? track->speed_vector_width : 0; + values.foreground = ZnPixel(ZnGetGradientColor(track->speed_vector_color, 0.0, NULL)); + values.line_width = (int) (track->speed_vector_width > 1 ? track->speed_vector_width : 0); values.line_style = LineSolid; values.fill_style = FillSolid; XChangeGC(wi->dpy, wi->gc, GCForeground | GCLineWidth | GCLineStyle | GCFillStyle, &values); - XDrawLine(wi->dpy, wi->draw_buffer, wi->gc, track->dev.x, track->dev.y, - track->speed_vector_dev.x, track->speed_vector_dev.y); + XDrawLine(wi->dpy, wi->draw_buffer, wi->gc, + (int) track->dev.x, + (int) track->dev.y, + (int) track->speed_vector_dev.x, + (int) track->speed_vector_dev.y); } /* * Draw the leader. */ if (track->field_set.label_format && (track->leader_width > 0)) { - ZnPoint end_points[LINE_END_POINTS]; - XPoint xpoints[LINE_END_POINTS]; - ZnPoint *points; - int num_points; + ZnPoint end_points[ZN_LINE_END_POINTS]; + XPoint xpoints[ZN_LINE_END_POINTS]; + ZnPoint *points; + unsigned int num_points; points = (ZnPoint *) ZnListArray(track->leader_points); num_points = ZnListSize(track->leader_points); ZnDrawLineShape(wi, points, num_points, track->leader_style, - ZnGetGradientColor(track->leader_color, 0, NULL), + ZnGetGradientColor(track->leader_color, 0.0, NULL), track->leader_width, track->leader_shape); if (track->leader_first_end != NULL) { - GetLineEnd(&points[0], &points[1], track->leader_width, - CapRound, track->leader_first_end, end_points); - for (i = 0; i < LINE_END_POINTS; i++) { - xpoints[i].x = end_points[i].x; - xpoints[i].y = end_points[i].y; + ZnGetLineEnd(&points[0], &points[1], track->leader_width, + CapRound, track->leader_first_end, end_points); + for (i = 0; i < ZN_LINE_END_POINTS; i++) { + xpoints[i].x = (short) end_points[i].x; + xpoints[i].y = (short) end_points[i].y; } - XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc, xpoints, LINE_END_POINTS, + XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc, xpoints, ZN_LINE_END_POINTS, Nonconvex, CoordModeOrigin); } if (track->leader_last_end != NULL) { - GetLineEnd(&points[num_points-1], &points[num_points-2], track->leader_width, - CapRound, track->leader_last_end, end_points); - for (i = 0; i < LINE_END_POINTS; i++) { - xpoints[i].x = end_points[i].x; - xpoints[i].y = end_points[i].y; + ZnGetLineEnd(&points[num_points-1], &points[num_points-2], track->leader_width, + CapRound, track->leader_last_end, end_points); + for (i = 0; i < ZN_LINE_END_POINTS; i++) { + xpoints[i].x = (short) end_points[i].x; + xpoints[i].y = (short) end_points[i].y; } - XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc, xpoints, LINE_END_POINTS, + XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc, xpoints, ZN_LINE_END_POINTS, Nonconvex, CoordModeOrigin); } } @@ -1193,7 +1212,7 @@ Draw(Item item) * Draw the history, current pos excepted. */ if ((item->class == ZnTrack) && track->history) { - values.foreground = ZnPixel(ZnGetGradientColor(track->history_color, 0, NULL)); + values.foreground = ZnPixel(ZnGetGradientColor(track->history_color, 0.0, NULL)); values.fill_style = FillSolid; XChangeGC(wi->dpy, wi->gc, GCForeground|GCFillStyle, &values); if (ISCLEAR(track->flags, FILLED_HISTORY_BIT)) { @@ -1202,13 +1221,13 @@ Draw(Item item) XChangeGC(wi->dpy, wi->gc, GCLineWidth | GCLineStyle, &values); } num_acc_pos = MIN(track->visible_history_size, ZnListSize(track->history)); + visible_history_size = MIN(track->visible_history_size-1, 0); hist = ZnListArray(track->history); side_size = MAX(width, height); for (i = 0, nb_hist = 0; i < num_acc_pos; i++) { - if (ISSET(track->flags, LAST_AS_FIRST_BIT) && - (i == track->visible_history_size-1)) { - values.foreground = ZnPixel(ZnGetGradientColor(track->symbol_color, 0, NULL)); + if (ISSET(track->flags, LAST_AS_FIRST_BIT) && (i == visible_history_size)) { + values.foreground = ZnPixel(ZnGetGradientColor(track->symbol_color, 0.0, NULL)); XChangeGC(wi->dpy, wi->gc, GCForeground, &values); } side_size--; @@ -1216,31 +1235,32 @@ Draw(Item item) h_side_size = (side_size+1)/2; if (hist[i].visible) { if (ISSET(track->flags, DOT_MIXED_HISTORY_BIT) && !(nb_hist++ % 2)) { - XDrawPoint(wi->dpy, wi->draw_buffer, wi->gc, hist[i].dev.x, hist[i].dev.y); + x = (int) hist[i].dev.x; + y = (int) hist[i].dev.y; + /* Draw a point (portability layer doesn't define a XDrawPoint) */ + XDrawLine(wi->dpy, wi->draw_buffer, wi->gc, x, y, x, y); } else { + x = ((int) hist[i].dev.x) - h_side_size; + y = ((int) hist[i].dev.y) - h_side_size; if (ISSET(track->flags, CIRCLE_HISTORY_BIT)) { if (ISSET(track->flags, FILLED_HISTORY_BIT)) { XFillArc(wi->dpy, wi->draw_buffer, wi->gc, - hist[i].dev.x - h_side_size, hist[i].dev.y - h_side_size, - side_size, side_size, 0, 360*64); + x, y, side_size, side_size, 0, 360*64); } else { XDrawArc(wi->dpy, wi->draw_buffer, wi->gc, - hist[i].dev.x - h_side_size, hist[i].dev.y - h_side_size, - side_size - 1, side_size - 1, 0, 360*64); + x, y, side_size - 1, side_size - 1, 0, 360*64); } } else { if (ISSET(track->flags, FILLED_HISTORY_BIT)) { XFillRectangle(wi->dpy, wi->draw_buffer, wi->gc, - hist[i].dev.x - h_side_size, hist[i].dev.y - h_side_size, - side_size, side_size); + x, y, side_size, side_size); } else { XDrawRectangle(wi->dpy, wi->draw_buffer, wi->gc, - hist[i].dev.x - h_side_size, hist[i].dev.y - h_side_size, - side_size - 1, side_size - 1); + x, y, side_size - 1, side_size - 1); } } } @@ -1252,11 +1272,11 @@ Draw(Item item) * Draw the current position using a pattern for Tk. */ if (track->symbol != ZnUnspecifiedImage) { - int x = track->dev.x - (width+1)/2; - int y = track->dev.y - (height+1)/2; - values.foreground = ZnPixel(ZnGetGradientColor(track->symbol_color, 0, NULL)); + x = ((int) track->dev.x) - (width+1)/2; + y = ((int) track->dev.y) - (height+1)/2; + values.foreground = ZnPixel(ZnGetGradientColor(track->symbol_color, 0.0, NULL)); values.fill_style = FillStippled; - values.stipple = ZnImagePixmap(track->symbol, NULL); + values.stipple = ZnImagePixmap(track->symbol); values.ts_x_origin = x; values.ts_y_origin = y; XChangeGC(wi->dpy, wi->gc, @@ -1268,39 +1288,40 @@ Draw(Item item) /* * Draw the label. */ - FIELD.DrawFields(&track->field_set); + ZnFIELD.DrawFields(&track->field_set); } /* - ********************************************************************************** - * - * Render -- - * - ********************************************************************************** - */ +********************************************************************************** +* +* Render -- +* +********************************************************************************** +*/ +#ifdef GL static void -Render(Item item) +Render(ZnItem item) { -#ifdef GLX - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; TrackItem track = (TrackItem) item; TrackItem c_item; History hist; - int h_side_size, side_size, width=0, height=0; - int i, j, nb_hist, num_acc_pos, alpha; + unsigned int h_side_size, side_size, width=0, height=0; + unsigned int i, j, nb_hist, num_acc_pos, visible_history_size; + unsigned short alpha; XColor *color; ZnPoint *points; - int num_points; + unsigned int num_points; ZnReal x0, y0, size; /* Draw the marker */ if (track->marker_size_dev != 0) { - points = GetCirclePoints(3, ZN_CIRCLE_MEDIUM, 0, 2*M_PI, &num_points, NULL); + points = ZnGetCirclePoints(3, ZN_CIRCLE_MEDIUM, 0.0, 2*M_PI, &num_points, NULL); x0 = track->dev.x; y0 = track->dev.y; size = track->marker_size_dev; - color = ZnGetGradientColor(track->marker_color, 0, &alpha); + color = ZnGetGradientColor(track->marker_color, 0.0, &alpha); alpha = ZnComposeAlpha(alpha, wi->alpha); glColor4us(color->red, color->green, color->blue, alpha); if (ISSET(track->flags, MARKER_FILLED_BIT)) { @@ -1310,21 +1331,21 @@ Render(Item item) * Setup polygon stippling. */ glEnable(GL_POLYGON_STIPPLE); - glPolygonStipple(ZnImagePattern(track->marker_fill_pattern, NULL)); + glPolygonStipple(ZnImageMask(track->marker_fill_pattern, NULL)); } glBegin(GL_TRIANGLE_FAN); for (i = 0; i < num_points; i++) { - glVertex2f(x0, y0); - glVertex2f(x0 + points[i].x*size, y0 + points[i].y*size); + glVertex2d(x0, y0); + glVertex2d(x0 + points[i].x*size, y0 + points[i].y*size); } glEnd(); } else { - glLineWidth(1); + glLineWidth(1.0); ZnSetLineStyle(wi, track->marker_style); glBegin(GL_LINE_LOOP); for (i = 0; i < num_points; i++) { - glVertex2f(x0 + points[i].x*size, y0 + points[i].y*size); + glVertex2d(x0 + points[i].x*size, y0 + points[i].y*size); } glEnd(); } @@ -1335,13 +1356,13 @@ Render(Item item) */ c_item = (TrackItem) item->connected_item; if ((c_item != ZN_NO_ITEM) && (track->connection_width > 0)) { - color = ZnGetGradientColor(track->connection_color, 0, &alpha); + color = ZnGetGradientColor(track->connection_color, 0.0, &alpha); alpha = ZnComposeAlpha(alpha, wi->alpha); glColor4us(color->red, color->green, color->blue, alpha); - glLineWidth(track->connection_width); + glLineWidth((GLfloat)track->connection_width); glBegin(GL_LINES); - glVertex2f(track->dev.x, track->dev.y); - glVertex2f(c_item->dev.x, c_item->dev.y); + glVertex2d(track->dev.x, track->dev.y); + glVertex2d(c_item->dev.x, c_item->dev.y); glEnd(); } @@ -1349,13 +1370,14 @@ Render(Item item) * Draw the speed vector. */ if ((item->class == ZnTrack) && (track->speed_vector_width > 0)) { - int num_clips=0, svlength=0, ticksize=0; - ZnReal svxstep=0, svystep=0; + unsigned int num_clips=0, svlength=0; + ZnReal svxstep=0, svystep=0; + GLfloat ticksize=0; - color = ZnGetGradientColor(track->speed_vector_color, 0, &alpha); + color = ZnGetGradientColor(track->speed_vector_color, 0.0, &alpha); alpha = ZnComposeAlpha(alpha, wi->alpha); glColor4us(color->red, color->green, color->blue, alpha); - glLineWidth(track->speed_vector_width); + glLineWidth((GLfloat)track->speed_vector_width); /* * Turn off AA to obtain a square point precisely defined @@ -1371,25 +1393,25 @@ Render(Item item) svxstep = (track->speed_vector_dev.x-track->dev.x)/svlength; svystep = (track->speed_vector_dev.y-track->dev.y)/svlength; glPointSize(ticksize); - GLX_START_CLIP(num_clips, False); + ZnGlStartClip(num_clips, False); glBegin(GL_POINTS); for (i = 1; i < svlength; i++) { - glVertex2f(track->dev.x + i*svxstep, track->dev.y + i*svystep); + glVertex2d(track->dev.x + i*svxstep, track->dev.y + i*svystep); } glEnd(); - GLX_RENDER_CLIPPED(); + ZnGlRenderClipped(); } } glBegin(GL_LINES); - glVertex2f(track->dev.x, track->dev.y); - glVertex2f(track->speed_vector_dev.x, track->speed_vector_dev.y); + glVertex2d(track->dev.x, track->dev.y); + glVertex2d(track->speed_vector_dev.x, track->speed_vector_dev.y); glEnd(); if (ISSET(track->flags, SV_MARK_BIT)) { - glPointSize(track->speed_vector_width + 2); + glPointSize((GLfloat) (track->speed_vector_width + 2.0)); glBegin(GL_POINTS); - glVertex2f(track->speed_vector_dev.x, track->speed_vector_dev.y); + glVertex2d(track->speed_vector_dev.x, track->speed_vector_dev.y); glEnd(); } @@ -1399,13 +1421,13 @@ Render(Item item) if (ISSET(track->flags, SV_TICKS_BIT)) { glPointSize(ticksize); - GLX_RESTORE_STENCIL(num_clips, False); + ZnGlRestoreStencil(num_clips, False); glBegin(GL_POINTS); for (i = 1; i < svlength; i++) { - glVertex2f(track->dev.x + i*svxstep, track->dev.y + i*svystep); + glVertex2d(track->dev.x + i*svxstep, track->dev.y + i*svystep); } glEnd(); - GLX_END_CLIP(num_clips); + ZnGlEndClip(num_clips); } } } @@ -1431,13 +1453,14 @@ Render(Item item) * Draw the history, current pos excepted. */ if ((item->class == ZnTrack) && track->history) { - points = GetCirclePoints(3, ZN_CIRCLE_COARSE, 0, 2*M_PI, &num_points, NULL); - color = ZnGetGradientColor(track->history_color, 0, &alpha); + points = ZnGetCirclePoints(3, ZN_CIRCLE_COARSE, 0.0, 2*M_PI, &num_points, NULL); + color = ZnGetGradientColor(track->history_color, 0.0, &alpha); alpha = ZnComposeAlpha(alpha, wi->alpha); glColor4us(color->red, color->green, color->blue, alpha); - glLineWidth(1); + glLineWidth(1.0); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); num_acc_pos = MIN(track->visible_history_size, ZnListSize(track->history)); + visible_history_size = MIN(track->visible_history_size-1, 0); hist = ZnListArray(track->history); side_size = MAX(width, height); /* @@ -1447,9 +1470,8 @@ Render(Item item) glDisable(GL_LINE_SMOOTH); glDisable(GL_POINT_SMOOTH); for (i = 0, nb_hist = 0; i < num_acc_pos; i++) { - if (ISSET(track->flags, LAST_AS_FIRST_BIT) && - (i == track->visible_history_size-1)) { - color = ZnGetGradientColor(track->symbol_color, 0, &alpha); + if (ISSET(track->flags, LAST_AS_FIRST_BIT) && (i == visible_history_size)) { + color = ZnGetGradientColor(track->symbol_color, 0.0, &alpha); alpha = ZnComposeAlpha(alpha, wi->alpha); glColor4us(color->red, color->green, color->blue, alpha); } @@ -1461,24 +1483,24 @@ Render(Item item) y0 = hist[i].dev.y; if ((ISSET(track->flags, DOT_MIXED_HISTORY_BIT) && !(nb_hist++ % 2)) || (side_size == 1)) { - glPointSize(1); + glPointSize(1.0); glBegin(GL_POINTS); - glVertex2f(x0, y0); + glVertex2d(x0, y0); glEnd(); } else { if (ISSET(track->flags, CIRCLE_HISTORY_BIT)) { if (ISSET(track->flags, FILLED_HISTORY_BIT)) { - glPointSize(side_size); + glPointSize((GLfloat) side_size); glBegin(GL_POINTS); - glVertex2f(x0, y0); + glVertex2d(x0, y0); glEnd(); } else { #if 1 glBegin(GL_LINE_LOOP); for (j = 0; j < num_points; j++) { - glVertex2f(x0 + points[j].x*h_side_size, + glVertex2d(x0 + points[j].x*h_side_size, y0 + points[j].y*h_side_size); } glEnd(); @@ -1490,18 +1512,18 @@ Render(Item item) else { if (ISSET(track->flags, FILLED_HISTORY_BIT)) { glBegin(GL_QUADS); - glVertex2f(x0 - h_side_size, y0 - h_side_size); - glVertex2f(x0 - h_side_size, y0 + h_side_size); - glVertex2f(x0 + h_side_size, y0 + h_side_size); - glVertex2f(x0 + h_side_size, y0 - h_side_size); + glVertex2d(x0 - h_side_size, y0 - h_side_size); + glVertex2d(x0 - h_side_size, y0 + h_side_size); + glVertex2d(x0 + h_side_size, y0 + h_side_size); + glVertex2d(x0 + h_side_size, y0 - h_side_size); glEnd(); } else { glBegin(GL_LINE_LOOP); - glVertex2f(x0 - h_side_size, y0 - h_side_size); - glVertex2f(x0 - h_side_size, y0 + h_side_size); - glVertex2f(x0 + h_side_size, y0 + h_side_size); - glVertex2f(x0 + h_side_size, y0 - h_side_size); + glVertex2d(x0 - h_side_size, y0 - h_side_size); + glVertex2d(x0 - h_side_size, y0 + h_side_size); + glVertex2d(x0 + h_side_size, y0 + h_side_size); + glVertex2d(x0 + h_side_size, y0 - h_side_size); glEnd(); } } @@ -1526,52 +1548,58 @@ Render(Item item) /* * Render the label. */ - FIELD.RenderFields(&track->field_set); -#endif + ZnFIELD.RenderFields(&track->field_set); } +#else +static void +Render(ZnItem item __unused) +{ +} +#endif + /* - ********************************************************************************** - * - * IsSensitive -- - * - ********************************************************************************** - */ +********************************************************************************** +* +* IsSensitive -- +* +********************************************************************************** +*/ static ZnBool -IsSensitive(Item item, +IsSensitive(ZnItem item, int item_part) { - if (ISCLEAR(item->flags, SENSITIVE_BIT) || + if (ISCLEAR(item->flags, ZN_SENSITIVE_BIT) || !item->parent->class->IsSensitive(item->parent, ZN_NO_PART)) { return False; } if (item_part < ZN_NO_PART) { - return ISSET(item->part_sensitive, PART_NUMBER_TO_BIT(item_part)); + return ISSET(item->part_sensitive, ZnPartToBit(item_part)); } else if (item_part >= 0) { - return FIELD.IsFieldSensitive(&((TrackItem) item)->field_set, item_part); + return ZnFIELD.IsFieldSensitive(&((TrackItem) item)->field_set, item_part); } else if (item_part == ZN_NO_PART) { - return ISSET(item->flags, SENSITIVE_BIT); + return ISSET(item->flags, ZN_SENSITIVE_BIT); } return True; } /* - ********************************************************************************** - * - * Pick -- - * - ********************************************************************************** - */ +********************************************************************************** +* +* Pick -- +* +********************************************************************************** +*/ static double -Pick(Item item, +Pick(ZnItem item, ZnPick ps) { TrackItem track = (TrackItem) item; - Item c_item; + ZnItem c_item; ZnBBox bbox; double dist=0, new_dist; ZnPoint *points, *p = ps->point; @@ -1584,7 +1612,7 @@ Pick(Item item, /* * Try one of the fields. */ - dist = FIELD.FieldsPick(&track->field_set, p, &best_part); + dist = ZnFIELD.FieldsPick(&track->field_set, p, &best_part); if (dist <= 0.0) { goto report0; } @@ -1592,7 +1620,7 @@ Pick(Item item, /* * Try the current position symbol. */ - ResetBBox(&bbox); + ZnResetBBox(&bbox); if (track->symbol != ZnUnspecifiedImage) { ZnSizeOfImage(track->symbol, &width, &height); bbox.orig.x = track->dev.x-(width+1)/2; @@ -1601,7 +1629,7 @@ Pick(Item item, bbox.corner.y = bbox.orig.y + height; } - new_dist = RectangleToPointDist(&bbox, p); + new_dist = ZnRectangleToPointDist(&bbox, p); if (new_dist < dist) { best_part = CURRENT_POSITION; dist = new_dist; @@ -1615,13 +1643,13 @@ Pick(Item item, */ if (track->field_set.label_format && (track->leader_width > 0) && track->leader_points) { - ZnPoint end_points[LINE_END_POINTS]; + ZnPoint end_points[ZN_LINE_END_POINTS]; width_2 = (track->leader_width>1) ? ((double) track->leader_width)/2.0 : 0; points = (ZnPoint *) ZnListArray(track->leader_points); num_points = ZnListSize(track->leader_points)-1; for (i = 0; i < num_points; i++) { - new_dist = LineToPointDist(&points[i], &points[i+1], p); + new_dist = ZnLineToPointDist(&points[i], &points[i+1], p); new_dist -= width_2; if (new_dist < dist) { best_part = LEADER; @@ -1632,9 +1660,9 @@ Pick(Item item, } } if (track->leader_first_end != NULL) { - GetLineEnd(&points[0], &points[1], track->leader_width, - CapRound, track->leader_first_end, end_points); - new_dist = PolygonToPointDist(end_points, LINE_END_POINTS, p); + ZnGetLineEnd(&points[0], &points[1], track->leader_width, + CapRound, track->leader_first_end, end_points); + new_dist = ZnPolygonToPointDist(end_points, ZN_LINE_END_POINTS, p); if (new_dist < dist) { best_part = LEADER; dist = new_dist; @@ -1644,9 +1672,9 @@ Pick(Item item, } } if (track->leader_last_end != NULL) { - GetLineEnd(&points[num_points-1], &points[num_points-2], track->leader_width, - CapRound, track->leader_last_end, end_points); - new_dist = PolygonToPointDist(end_points, LINE_END_POINTS, p); + ZnGetLineEnd(&points[num_points-1], &points[num_points-2], track->leader_width, + CapRound, track->leader_last_end, end_points); + new_dist = ZnPolygonToPointDist(end_points, ZN_LINE_END_POINTS, p); if (new_dist < dist) { best_part = LEADER; dist = new_dist; @@ -1663,8 +1691,8 @@ Pick(Item item, if ((item->class == ZnTrack) && (track->speed_vector_width > 0)) { pts[0] = track->dev; pts[1] = track->speed_vector_dev; - new_dist = PolylineToPointDist(pts, 2, track->speed_vector_width, - CapRound, JoinRound, p); + new_dist = ZnPolylineToPointDist(pts, 2, track->speed_vector_width, + CapRound, JoinRound, p); if (new_dist < dist) { best_part = SPEED_VECTOR; dist = new_dist; @@ -1681,8 +1709,8 @@ Pick(Item item, if ((c_item != ZN_NO_ITEM) && (track->connection_width > 0)) { pts[0] = track->dev; pts[1] = ((TrackItem) item->connected_item)->dev; - new_dist = PolylineToPointDist(pts, 2, track->connection_width, - CapRound, JoinRound, p); + new_dist = ZnPolylineToPointDist(pts, 2, track->connection_width, + CapRound, JoinRound, p); if (new_dist < dist) { dist = new_dist; best_part = CONNECTION; @@ -1694,34 +1722,34 @@ Pick(Item item, } /* printf("track %d reporting part %d, distance %lf\n", - item->id, best_part, dist); */ + item->id, best_part, dist); */ ps->a_part = best_part; return dist; } /* - ********************************************************************************** - * - * PostScript -- - * - ********************************************************************************** - */ +********************************************************************************** +* +* PostScript -- +* +********************************************************************************** +*/ static void -PostScript(Item item, - PostScriptInfo ps_info) +PostScript(ZnItem item __unused, + ZnPostScriptInfo ps_info __unused) { } #ifdef OM /* - ********************************************************************************** - * - * SendTrackToOm -- - * - ********************************************************************************** - */ +********************************************************************************** +* +* ZnSendTrackToOm -- +* +********************************************************************************** +*/ /* * TODO: * @@ -1731,25 +1759,25 @@ PostScript(Item item, * dealing with tracks. */ void * -SendTrackToOm(void *ptr, - void *item, - int *x, - int *y, - int *sv_dx, - int *sv_dy, - /*int *label_x, - int *label_y, - int *label_width, - int *label_height,*/ - int *rho, - int *theta, - int *visibility, - int *locked, - int *preferred_angle, - int *convergence_style) +ZnSendTrackToOm(void *ptr, + void *item, + int *x, + int *y, + int *sv_dx, + int *sv_dy, + /*int *label_x, + int *label_y, + int *label_width, + int *label_height,*/ + int *rho, + int *theta, + int *visibility, + int *locked, + int *preferred_angle, + int *convergence_style) { - WidgetInfo *wi = (WidgetInfo *) ptr; - Item current_item = (Item) item; + ZnWInfo *wi = (ZnWInfo *) ptr; + ZnItem current_item = (ZnItem) item; TrackItem track; ZnBBox zn_bbox, bbox; ZnBool to_be_sent; @@ -1772,46 +1800,47 @@ SendTrackToOm(void *ptr, /* We send invisibles items because the current algorithm take care of the age of the tracks. - to_be_sent &= ISSET(current_item->flags, VISIBLE_BIT);*/ + to_be_sent &= ISSET(current_item->flags, ZN_VISIBLE_BIT);*/ - IntersectBBox(&zn_bbox, ¤t_item->item_bounding_box, &bbox); - to_be_sent &= !IsEmptyBBox(&bbox); + ZnIntersectBBox(&zn_bbox, ¤t_item->item_bounding_box, &bbox); + to_be_sent &= !ZnIsEmptyBBox(&bbox); if (to_be_sent) { track = (TrackItem) current_item; - *x = track->dev.x; - *y = wi->height - track->dev.y; + *x = (int) track->dev.x; + *y = wi->height - ((int) track->dev.y); /* * We must send world values for speed vector deltas as device * equivalents can be null. But then if the image is rotated this * is nonsense. */ - *sv_dx = track->speed_vector.x; - *sv_dy = track->speed_vector.y; + *sv_dx = (int) track->speed_vector.x; + *sv_dy = (int) track->speed_vector.y; /* Fri Oct 13 15:16:38 2000 - *label_x = track->field_set.label_pos.x; - *label_y = wi->height - track->field_set.label_pos.y; - if (track->field_set.label_format) { - ZnDim bb_width, bb_height; - - FIELD.GetLabelBBox(&track->field_set, &bb_width, &bb_height); - *label_width = bb_width; - *label_height = bb_height; - } - else { - *label_width = 0; - *label_height = 0; - } + *label_x = track->field_set.label_pos.x; + *label_y = wi->height - track->field_set.label_pos.y; + if (track->field_set.label_format) { + ZnDim bb_width, bb_height; + + ZnFIELD.GetLabelBBox(&track->field_set, &bb_width, &bb_height); + *label_width = bb_width; + *label_height = bb_height; + } + else { + *label_width = 0; + *label_height = 0; + } */ /* - * Trial to fix rho drift due to PointPolarToCartesian + * Trial to fix rho drift due to ZnPointPolarToCartesian * roundoff error. */ - rho_derived = sqrt(track->label_dx*track->label_dx + track->label_dy*track->label_dy); + rho_derived = (int) sqrt(track->label_dx*track->label_dx + + track->label_dy*track->label_dy); #ifdef DP if (ABS(rho_derived - track->label_distance) < LABEL_DISTANCE_THRESHOLD) { /* The error is narrow so value discarded */ @@ -1825,11 +1854,11 @@ SendTrackToOm(void *ptr, *rho = rho_derived; #endif *theta = track->label_angle; - *visibility = (ISSET(current_item->flags, VISIBLE_BIT) ? 1 : 0 ); + *visibility = (ISSET(current_item->flags, ZN_VISIBLE_BIT) ? 1 : 0 ); *locked = (ISSET(track->flags, FROZEN_LABEL_BIT) ? 1 : 0); *preferred_angle = track->label_preferred_angle; *convergence_style = track->label_convergence_style; - break; + break; } current_item = current_item->next; @@ -1840,17 +1869,17 @@ SendTrackToOm(void *ptr, /* - ********************************************************************************** - * - * SetLabelAngleFromOm -- - * - ********************************************************************************** - */ +********************************************************************************** +* +* ZnSetLabelAngleFromOm -- +* +********************************************************************************** +*/ void -SetLabelAngleFromOm(void *ptr, /* No longer in use. */ - void *item, - int rho, - int theta) +ZnSetLabelAngleFromOm(void *ptr __unused, /* No longer in use. */ + void *item, + int rho __unused, + int theta) { TrackItem track = (TrackItem) item; @@ -1864,31 +1893,31 @@ SetLabelAngleFromOm(void *ptr, /* No longer in use. */ track->label_distance = rho; #endif SET(track->flags, POLAR_BIT); - ITEM.Invalidate((Item) item, ZN_COORDS_FLAG); - /* ZnGroupSetCallOm(((Item)item)->parent, True);*/ + ZnITEM.Invalidate((ZnItem) item, ZN_COORDS_FLAG); + /* ZnGroupSetCallOm(((ZnItem)item)->parent, True);*/ } } /* - ********************************************************************************** - * - * QueryLabelPosition -- OverlapMan query the widget about what would be the - * label position if label_angle is theta - * - ********************************************************************************** - */ +********************************************************************************** +* +* ZnQueryLabelPosition -- OverlapMan query the widget about what would be the +* label position if label_angle is theta +* +********************************************************************************** +*/ void -QueryLabelPosition(void *ptr, /* No longer in use. */ - void *item, - int theta, - int *x, - int *y, - int *w, - int *h) +ZnQueryLabelPosition(void *ptr __unused, /* No longer in use. */ + void *item, + int theta, + int *x, + int *y, + int *w, + int *h) { - Item it = (Item) item; - WidgetInfo *wi = it->wi; + ZnItem it = (ZnItem) item; + ZnWInfo *wi = it->wi; TrackItem track = (TrackItem) it; if (track->field_set.label_format) { @@ -1899,18 +1928,18 @@ QueryLabelPosition(void *ptr, /* No longer in use. */ /* * !! BUG !! This doesn't work if the current transform has some rotation. */ - heading = ProjectionToAngle(track->speed_vector.x, track->speed_vector.y); - PointPolarToCartesian(heading, track->label_distance, theta, &delta_x, &delta_y); - FIELD.GetLabelBBox(&track->field_set, &bb_width, &bb_height); + heading = ZnProjectionToAngle(track->speed_vector.x, track->speed_vector.y); + ZnPointPolarToCartesian(heading, track->label_distance, (ZnReal) theta, &delta_x, &delta_y); + ZnFIELD.GetLabelBBox(&track->field_set, &bb_width, &bb_height); /* * !! BUG !! This assume a label placing relative to the center anchor. * We must fix this by taking into account the label anchor. */ - *x = track->dev.x + (ZnPos) (delta_x - bb_width/2); - *y = track->dev.y - (ZnPos) (delta_y + bb_height/2); - *y = wi->height - *y; - *w = bb_width; - *h = bb_height; + *x = (int) track->dev.x + (int) (delta_x - bb_width/2); + *y = (int) track->dev.y - (int) (delta_y + bb_height/2); + *y = ((int) wi->height) - *y; + *w = (int) bb_width; + *h = (int) bb_height; } else { *x = *y = *w = *h = 0; @@ -1920,29 +1949,29 @@ QueryLabelPosition(void *ptr, /* No longer in use. */ /* - ********************************************************************************** - * - * SetHistoryVisibility -- PLC - not yet implemented - * - ********************************************************************************** - */ +********************************************************************************** +* +* ZnSetHistoryVisibility -- PLC - not yet implemented +* +********************************************************************************** +*/ void -SetHistoryVisibility(Item item, - int index, - ZnBool visible) +ZnSetHistoryVisibility(ZnItem item __unused, + int index __unused, + ZnBool visible __unused) { } /* - ********************************************************************************** - * - * TruncHistory -- PLC - not yet interfaced - * - ********************************************************************************** - */ +********************************************************************************** +* +* ZnTruncHistory -- PLC - not yet interfaced +* +********************************************************************************** +*/ void -TruncHistory(Item item) +ZnTruncHistory(ZnItem item) { TrackItem track = (TrackItem) item; @@ -1952,43 +1981,43 @@ TruncHistory(Item item) while (size--) { hist_tbl[size].visible = False; } - ITEM.Invalidate(item, ZN_COORDS_FLAG); + ZnITEM.Invalidate(item, ZN_COORDS_FLAG); } } /* - ********************************************************************************** - * - * GetFieldSet -- - * - ********************************************************************************** - */ -static FieldSet -GetFieldSet(Item item) +********************************************************************************** +* +* GetFieldSet -- +* +********************************************************************************** +*/ +static ZnFieldSet +GetFieldSet(ZnItem item) { return &((TrackItem) item)->field_set; } /* - ********************************************************************************** - * - * GetAnchor -- - * - ********************************************************************************** - */ +********************************************************************************** +* +* GetAnchor -- +* +********************************************************************************** +*/ static void -GetAnchor(Item item, - ZnAnchor anchor, +GetAnchor(ZnItem item, + Tk_Anchor anchor, ZnPoint *p) { - FieldSet field_set = &((TrackItem) item)->field_set; + ZnFieldSet field_set = &((TrackItem) item)->field_set; ZnDim width, height; if (field_set->label_format) { - FIELD.GetLabelBBox(field_set, &width, &height); - Origin2Anchor(&field_set->label_pos, width, height, anchor, p); + ZnFIELD.GetLabelBBox(field_set, &width, &height); + ZnOrigin2Anchor(&field_set->label_pos, width, height, anchor, p); } else { p->x = p->y = 0.0; @@ -1997,60 +2026,60 @@ GetAnchor(Item item, /* - ********************************************************************************** - * - * Coords -- - * Return or edit the item position. - * - ********************************************************************************** - */ +********************************************************************************** +* +* Coords -- +* Return or edit the item position. +* +********************************************************************************** +*/ 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 __unused, + int cmd, + ZnPoint **pts, + char **controls __unused, + unsigned int *num_pts) { TrackItem track = (TrackItem) item; - if ((cmd == COORDS_ADD) || (cmd == COORDS_ADD_LAST) || (cmd == COORDS_REMOVE)) { + if ((cmd == ZN_COORDS_ADD) || (cmd == ZN_COORDS_ADD_LAST) || (cmd == ZN_COORDS_REMOVE)) { Tcl_AppendResult(item->wi->interp, " ", item->class->name, "s can't add or remove vertices", NULL); - return ZN_ERROR; + return TCL_ERROR; } - else if ((cmd == COORDS_REPLACE) || (cmd == COORDS_REPLACE_ALL)) { + else if ((cmd == ZN_COORDS_REPLACE) || (cmd == ZN_COORDS_REPLACE_ALL)) { if (*num_pts == 0) { Tcl_AppendResult(item->wi->interp, " coords command need 1 point on ", item->class->name, "s", NULL); - return ZN_ERROR; + return TCL_ERROR; } if (item->class == ZnTrack) { AddToHistory(track, track->pos); } track->pos = (*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)) { *num_pts = 1; *pts = &track->pos; } - return ZN_OK; + return TCL_OK; } /* - ********************************************************************************** - * - * Part -- - * Convert a private part from/to symbolic representation. - * - ********************************************************************************** - */ +********************************************************************************** +* +* Part -- +* Convert a private part from/to symbolic representation. +* +********************************************************************************** +*/ static int -Part(Item item, +Part(ZnItem item, Tcl_Obj **part_spec, int *part) { @@ -2066,7 +2095,7 @@ Part(Item item, else if (isdigit(part_str[0])) { *part = strtol(part_str, &end, 0); if ((*end != 0) || (*part < 0) || - (*part >= ((TrackItem) item)->field_set.num_fields)) { + ((unsigned int) *part >= ((TrackItem) item)->field_set.num_fields)) { goto part_error; } } @@ -2090,7 +2119,7 @@ Part(Item item, else { part_error: Tcl_AppendResult(item->wi->interp, " invalid item part specification", NULL); - return ZN_ERROR; + return TCL_ERROR; } } } @@ -2120,117 +2149,117 @@ Part(Item item, } } if (part_str[0]) { - *part_spec = NewStringObj(part_str); + *part_spec = Tcl_NewStringObj(part_str, -1); } } } - return ZN_OK; + return TCL_OK; } /* - ********************************************************************************** - * - * Index -- - * Parse a text index and return its value and aa - * error status (standard Tcl result). - * - ********************************************************************************** - */ +********************************************************************************** +* +* Index -- +* Parse a text index and return its value and aa +* error status (standard Tcl result). +* +********************************************************************************** +*/ static int -Index(Item item, +Index(ZnItem item, int field, Tcl_Obj *index_spec, int *index) { - return FIELD.FieldIndex(&((TrackItem) item)->field_set, field, - index_spec, index); + return ZnFIELD.FieldIndex(&((TrackItem) item)->field_set, field, + index_spec, index); } /* - ********************************************************************************** - * - * InsertChars -- - * - ********************************************************************************** - */ +********************************************************************************** +* +* InsertChars -- +* +********************************************************************************** +*/ static void -InsertChars(Item item, +InsertChars(ZnItem item, int field, int *index, char *chars) { - if (FIELD.FieldInsertChars(&((TrackItem) item)->field_set, - field, index, chars)) { - ITEM.Invalidate(item, ZN_COORDS_FLAG); + if (ZnFIELD.FieldInsertChars(&((TrackItem) item)->field_set, + field, index, chars)) { + ZnITEM.Invalidate(item, ZN_COORDS_FLAG); } } /* - ********************************************************************************** - * - * DeleteChars -- - * - ********************************************************************************** - */ +********************************************************************************** +* +* DeleteChars -- +* +********************************************************************************** +*/ static void -DeleteChars(Item item, +DeleteChars(ZnItem item, int field, int *first, int *last) { - if (FIELD.FieldDeleteChars(&((TrackItem) item)->field_set, - field, first, last)) { - ITEM.Invalidate(item, ZN_COORDS_FLAG); + if (ZnFIELD.FieldDeleteChars(&((TrackItem) item)->field_set, + field, first, last)) { + ZnITEM.Invalidate(item, ZN_COORDS_FLAG); } } /* - ********************************************************************************** - * - * Cursor -- - * - ********************************************************************************** - */ +********************************************************************************** +* +* Cursor -- +* +********************************************************************************** +*/ static void -TrackCursor(Item item, - int field, - int index) +TrackCursor(ZnItem item, + int field, + int index) { - FIELD.FieldCursor(&((TrackItem) item)->field_set, field, index); + ZnFIELD.FieldCursor(&((TrackItem) item)->field_set, field, index); } /* - ********************************************************************************** - * - * Selection -- - * - ********************************************************************************** - */ +********************************************************************************** +* +* Selection -- +* +********************************************************************************** +*/ static int -Selection(Item item, - int field, - int offset, - char *chars, - int max_chars) +Selection(ZnItem item, + int field, + int offset, + char *chars, + int max_chars) { - return FIELD.FieldSelection(&((TrackItem) item)->field_set, field, - offset, chars, max_chars); + return ZnFIELD.FieldSelection(&((TrackItem) item)->field_set, field, + offset, chars, max_chars); } /* - ********************************************************************************** - * - * Exported functions struct -- - * - ********************************************************************************** - */ -static ItemClassStruct TRACK_ITEM_CLASS = { +********************************************************************************** +* +* Exported functions struct -- +* +********************************************************************************** +*/ +static ZnItemClassStruct TRACK_ITEM_CLASS = { sizeof(TrackItemStruct), 4, /* num_parts */ True, /* has_anchors */ @@ -2263,7 +2292,7 @@ static ItemClassStruct TRACK_ITEM_CLASS = { PostScript }; -static ItemClassStruct WAY_POINT_ITEM_CLASS = { +static ZnItemClassStruct WAY_POINT_ITEM_CLASS = { sizeof(TrackItemStruct), 3, /* num_parts */ True, /* has_anchors */ diff --git a/generic/Track.h b/generic/Track.h index ce29dba..36aa951 100644 --- a/generic/Track.h +++ b/generic/Track.h @@ -42,18 +42,18 @@ ********************************************************************************** */ -void *SendTrackToOm(void *ptr, void *item, int *x, int *y, - int *sv_dx, int *sv_dy, - /* Fri Oct 13 15:18:11 2000 - int *label_x, int *label_y, - int *label_width, int *label_height,*/ - int *rho, int *theta, int *visibility, int *locked, - int *preferred_angle, int *convergence_style); -void SetLabelAngleFromOm(void *ptr, void *item, int rho, int theta); -void QueryLabelPosition(void *ptr, void *item, int theta, - int *x, int *y, int *w, int *h); -void SetHistoryVisibility(Item item, int index, ZnBool visibility); -void TruncHistory(Item item); +void *ZnSendTrackToOm(void *ptr, void *item, int *x, int *y, + int *sv_dx, int *sv_dy, + /* Fri Oct 13 15:18:11 2000 + int *label_x, int *label_y, + int *label_width, int *label_height,*/ + int *rho, int *theta, int *visibility, int *locked, + int *preferred_angle, int *convergence_style); +void ZnSetLabelAngleFromOm(void *ptr, void *item, int rho, int theta); +void ZnQueryLabelPosition(void *ptr, void *item, int theta, + int *x, int *y, int *w, int *h); +void ZnSetHistoryVisibility(ZnItem item, int index, ZnBool visibility); +void ZnTruncHistory(ZnItem item); #endif /* _Track_h */ diff --git a/generic/Transfo.c b/generic/Transfo.c index 6c1c408..1395c17 100644 --- a/generic/Transfo.c +++ b/generic/Transfo.c @@ -194,7 +194,12 @@ ZnTransfoIsIdentity(ZnTransfo *t) void ZnTransfoSetIdentity(ZnTransfo *t) { - *t = ((ZnTransfo) {{{1, 0}, {0, 1}, {0, 0}}}); + t->_[0][0] = 1; + t->_[0][1] = 0; + t->_[1][0] = 0; + t->_[1][1] = 1; + t->_[2][0] = 0; + t->_[2][1] = 0; } @@ -563,13 +568,13 @@ void ZnTransformPoints(ZnTransfo *t, ZnPoint *p, ZnPoint *xp, - int num) + unsigned int num) { if (t == NULL) { memcpy(xp, p, sizeof(ZnPoint)*num); } else { - int i; + unsigned int i; for (i = 0; i < num; i++) { xp[i].x = t->_[0][0]*p[i].x + t->_[1][0]*p[i].y + t->_[2][0]; @@ -686,7 +691,7 @@ ZnTransfo * ZnRotateDeg(ZnTransfo *t, ZnReal angle) { - return ZnRotateRad(t, DegreesToRadian(angle)); + return ZnRotateRad(t, ZnDegRad(angle)); } diff --git a/generic/Transfo.h b/generic/Transfo.h index 9ce9b8e..b56f40a 100644 --- a/generic/Transfo.h +++ b/generic/Transfo.h @@ -88,7 +88,7 @@ void ZnTransformPoints(ZnTransfo *t, ZnPoint *p, ZnPoint *xp, - int num); + unsigned int num); ZnTransfo * ZnTranslate(ZnTransfo *t, ZnReal delta_x, 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 */ diff --git a/generic/Types.h b/generic/Types.h index 41b1aff..b84350c 100644 --- a/generic/Types.h +++ b/generic/Types.h @@ -1,5 +1,5 @@ /* - * Types.h -- Types used by the Zinc widget. + * Types.h -- Some types and macros used by the Zinc widget. * * Authors : Patrick Lecoanet. * Creation date : Mon Feb 1 12:13:24 1999 @@ -30,321 +30,74 @@ #ifndef _Types_h #define _Types_h +#include "private.h" + +#ifdef _WIN32 +# define WIN32_LEAN_AND_MEAN +# include +# undef WIN32_LEAN_AND_MEAN +# if defined(_MSC_VER) +# define DllEntryPoint DllMain +# endif +#endif + +#ifdef GL +# ifdef _WIN32 +# include +# else +# include +# endif +#endif + #define NEED_REAL_STDIO + #include +#include +#include #include #ifdef PTK -#include +# include +# include +# include +#else +# include #endif #include -#ifdef __CPLUSPLUS__ -extern "C" { +/* This EXTERN declaration is needed for Tcl < 8.0.3 */ +#ifndef EXTERN +# ifdef __cplusplus +# define EXTERN extern "C" +# else +# define EXTERN extern +# endif #endif +#ifdef TCL_STORAGE_CLASS +# undef TCL_STORAGE_CLASS +#endif +#ifdef BUILD_Tkzinc +# define TCL_STORAGE_CLASS DLLEXPORT +#else +# define TCL_STORAGE_CLASS DLLIMPORT +#endif -typedef void *ZnItemClassId; -typedef void *ZnItemId; - -typedef double ZnReal; /* Keep it a double for GL. */ -typedef int ZnBool; /* Keep it an int to keep Tk happy */ -typedef ZnReal ZnPos; -typedef ZnReal ZnDim; -typedef XColor *ZnColor; -typedef Tk_Font ZnFont; -typedef Tk_Window ZnWindow; -typedef void *ZnPtr; - -typedef struct { - ZnPos x, y; -} ZnPoint; - -typedef struct { - ZnPos x, y, w, h; -} ZnRect; - -typedef struct { - int num_points; - ZnPoint *points; - char *controls; - ZnBool cw; -} ZnContour; - -/* - * contour1 can be used to store a single contour - * without having to alloc the contours array. - */ -typedef struct { - int num_contours; - ZnContour *contours; - ZnContour contour1; -} ZnPoly; - -/* - * Keep this enum in sync with op_strings in Contour() - * in tkZinc.c. - */ -typedef enum { - ZN_CONTOUR_ADD, ZN_CONTOUR_REMOVE -} ZnContourCmd; - -typedef struct { - int num_points; - ZnPoint *points; - ZnBool fan; /* When using a fan, all contour vertices must be - * included to describe the contour as a polygon - * (clipping code use that to speed up region - * rendering) and the center must be the first - * vertex. */ -} ZnStrip; - -typedef struct { - int num_strips; - ZnStrip *strips; - ZnStrip strip1; -} ZnTriStrip; - -typedef struct _ZnCombineData { - ZnReal v[2]; - struct _ZnCombineData *next; -} ZnCombineData; - -/* - * ZnBBox: orig is into the area while corner is not. - * Thus the test: ((bbox.orig.x == bbox.corner.x) || - * (bbox.orig.y == bbox.corner.y)) - * tells whether the bbox is empty or not. - * When interpreting bboxes the X coordinate system is - * the norm. x goes from left toward the right and y - * goes from the top toward the bottom. Bboxes are - * always axes aligned. - */ -typedef struct { - ZnPoint orig, corner; -} ZnBBox; - -/* - * Operator constants for the coord method. - */ -#define COORDS_READ 0 -#define COORDS_READ_ALL 1 -#define COORDS_REPLACE 2 -#define COORDS_REPLACE_ALL 3 -#define COORDS_ADD 4 -#define COORDS_ADD_LAST 5 -#define COORDS_REMOVE 6 - -/* - * Types and constants for attribute processing. - */ -typedef struct { - int type; - char *name; - Tk_Uid uid; - int offset; - int bool_bit; - int flags; - ZnBool read_only; -} ZnAttrConfig; - -/* - * When adding new type in the following enum - * do not forget to update attribute_type_strings - * in Item.c. - */ -#define ZN_CONFIG_END 0 -#define ZN_CONFIG_BOOL 1 -#define ZN_CONFIG_BITMAP 2 -#define ZN_CONFIG_BITMAP_LIST 3 -#define ZN_CONFIG_STRING 4 -#define ZN_CONFIG_FONT 5 -#define ZN_CONFIG_EDGE_LIST 6 -#define ZN_CONFIG_RELIEF 7 -#define ZN_CONFIG_DIM 8 -#define ZN_CONFIG_PRI 9 -#define ZN_CONFIG_ALIGNMENT 10 -#define ZN_CONFIG_AUTO_ALIGNMENT 11 -#define ZN_CONFIG_LINE_END 12 -#define ZN_CONFIG_LABEL_FORMAT 13 -#define ZN_CONFIG_LINE_STYLE 14 -#define ZN_CONFIG_LINE_SHAPE 15 -#define ZN_CONFIG_ITEM 16 -#define ZN_CONFIG_ANGLE 17 -#define ZN_CONFIG_INT 18 -#define ZN_CONFIG_UINT 19 -#define ZN_CONFIG_POINT 20 -#define ZN_CONFIG_ANCHOR 21 -#define ZN_CONFIG_TAG_LIST 22 -#define ZN_CONFIG_MAP_INFO 23 -#define ZN_CONFIG_IMAGE 24 -#define ZN_CONFIG_LEADER_ANCHORS 25 -#define ZN_CONFIG_JOIN_STYLE 26 -#define ZN_CONFIG_CAP_STYLE 27 -#define ZN_CONFIG_GRADIENT 28 -#define ZN_CONFIG_GRADIENT_LIST 29 -#define ZN_CONFIG_WINDOW 30 -#define ZN_CONFIG_ALPHA 31 -#define ZN_CONFIG_FILL_RULE 32 - -#define ZN_DRAW_FLAG 1 << 0 -#define ZN_COORDS_FLAG 1 << 1 -#define ZN_TRANSFO_FLAG 1 << 2 -#define ZN_REPICK_FLAG 1 << 3 -#define ZN_BORDER_FLAG 1 << 4 -#define ZN_CLFC_FLAG 1 << 5 /* Clear Label Format Cache. */ -#define ZN_IMAGE_FLAG 1 << 6 /* Update image pointer. */ -#define ZN_VIS_FLAG 1 << 7 /* Visibility has changed. */ -#define ZN_MOVED_FLAG 1 << 8 /* Item has moved. */ -#define ZN_ITEM_FLAG 1 << 9 /* Signal a change in an item type attribute. */ -#define ZN_MAP_INFO_FLAG 1 << 10 /* Update mapinfo pointer. */ -#define ZN_LAYOUT_FLAG 1 << 10 /* A layout need update. */ -#define ZN_POLAR_FLAG 1 << 11 /* Signal a cartesian to polar change. */ -#define ZN_CARTESIAN_FLAG 1 << 12 /* Signal a polar to cartesian change. */ -#define ZN_TILE_FLAG 1 << 13 /* Update tile pointer. */ -#define ZN_WINDOW_FLAG 1 << 14 /* Signal a change in a window type attribute. */ - -/* - * Type and constant values for alignments. - */ -typedef char ZnJustify; -#define ZnJustifyLeft TK_JUSTIFY_LEFT -#define ZnJustifyRight TK_JUSTIFY_RIGHT -#define ZnJustifyCenter TK_JUSTIFY_CENTER - -/* - * Type and constant values for anchors. - */ -typedef Tk_Anchor ZnAnchor; -#define ZnAnchorN TK_ANCHOR_N -#define ZnAnchorS TK_ANCHOR_S -#define ZnAnchorE TK_ANCHOR_E -#define ZnAnchorW TK_ANCHOR_W -#define ZnAnchorNE TK_ANCHOR_NE -#define ZnAnchorNW TK_ANCHOR_NW -#define ZnAnchorSE TK_ANCHOR_SE -#define ZnAnchorSW TK_ANCHOR_SW -#define ZnAnchorCenter TK_ANCHOR_CENTER - -/* - * Type and constant values for borders. - */ -typedef unsigned char Border; -#define NO_BORDER 0 -#define LEFT_BORDER 1 -#define RIGHT_BORDER 2 -#define TOP_BORDER 4 -#define BOTTOM_BORDER 8 -#define CONTOUR_BORDER (LEFT_BORDER|RIGHT_BORDER|TOP_BORDER|BOTTOM_BORDER) -#define COUNTER_OBLIQUE 16 -#define OBLIQUE 32 - -#define LEFT_SPEC "left" -#define RIGHT_SPEC "right" -#define TOP_SPEC "top" -#define BOTTOM_SPEC "bottom" -#define CONTOUR_SPEC "contour" -#define COUNTER_OBLIQUE_SPEC "counteroblique" -#define OBLIQUE_SPEC "oblique" -#define NO_BORDER_SPEC "noborder" - -/* - * Type and constant values for line styles, line shapes and line ends. - */ -typedef unsigned char LineStyle; -typedef unsigned char LineEndStyle; -typedef unsigned char LineShape; - -/* LineStyle */ -#define LINE_SIMPLE 0 -#define LINE_DASHED 1 -#define LINE_MIXED 2 -#define LINE_DOTTED 3 -/* LineShape */ -#define LINE_STRAIGHT 0 -#define LINE_LEFT_LIGHTNING 1 -#define LINE_LEFT_CORNER 2 -#define LINE_DOUBLE_LEFT_CORNER 3 -#define LINE_RIGHT_LIGHTNING 4 -#define LINE_RIGHT_CORNER 5 -#define LINE_DOUBLE_RIGHT_CORNER 6 - -#define SIMPLE_SPEC "simple" -#define DASHED_SPEC "dashed" -#define DOTTED_SPEC "dotted" -#define MIXED_SPEC "mixed" -#define STRAIGHT_SPEC "straight" -#define RIGHT_LIGHTNING_SPEC "rightlightning" -#define LEFT_LIGHTNING_SPEC "leftlightning" -#define RIGHT_CORNER_SPEC "rightcorner" -#define LEFT_CORNER_SPEC "leftcorner" -#define DOUBLE_RIGHT_CORNER_SPEC "doublerightcorner" -#define DOUBLE_LEFT_CORNER_SPEC "doubleleftcorner" +#ifdef __CPLUSPLUS__ +extern "C" { +#endif -/* - * Type and constant values for relief styles. - */ -typedef int ReliefStyle; -#define RELIEF_FLAT 0 -#define RELIEF_RAISED 1 -#define RELIEF_SUNKEN 2 -#define RELIEF_GROOVE (RELIEF_TWO_FACES|RELIEF_SUNKEN) -#define RELIEF_RIDGE (RELIEF_TWO_FACES|RELIEF_RAISED) -#define RELIEF_ROUND_SUNKEN (RELIEF_ROUND|RELIEF_SUNKEN) -#define RELIEF_ROUND_RAISED (RELIEF_ROUND|RELIEF_RAISED) -#define RELIEF_ROUND_GROOVE (RELIEF_ROUND|RELIEF_TWO_FACES|RELIEF_SUNKEN) -#define RELIEF_ROUND_RIDGE (RELIEF_ROUND|RELIEF_TWO_FACES|RELIEF_RAISED) -#define RELIEF_SUNKEN_RULE (RELIEF_ROUND|RELIEF_TWO_FACES|RELIEF_SUNKEN|RELIEF_RULE) -#define RELIEF_RAISED_RULE (RELIEF_ROUND|RELIEF_TWO_FACES|RELIEF_RAISED|RELIEF_RULE) -#define RELIEF_ROUND 0x80 -#define RELIEF_TWO_FACES 0x40 -#define RELIEF_RULE 0x20 -#define RELIEF_MASK 0x3 -/* - * Number of steps for relief drawing. This translate in - * RELIEF_STEPS*2+1 color shades in the color gradient. - */ -#define RELIEF_STEPS 6 - -/* - * Types of gradients. - */ -#define ZN_AXIAL_GRADIENT 0 -#define ZN_RADIAL_GRADIENT 1 -#define ZN_PATH_GRADIENT 2 +typedef double ZnReal; /* Keep it a double for GL. */ +typedef int ZnBool; /* Keep it an int to keep Tk happy */ +typedef ZnReal ZnPos; +typedef ZnReal ZnDim; +typedef void *ZnPtr; -/* - * Type and constant values for automatic alignments. - */ -typedef struct { - ZnBool automatic; - ZnJustify align[3]; -} AutoAlign; -#define AA_LEFT 0 -#define AA_CENTER 1 -#define AA_RIGHT 2 -#define AA_LEFT_SPEC "l" -#define AA_CENTER_SPEC "c" -#define AA_RIGHT_SPEC "r" -#define AA_AUTO_SPEC "-" - -/* - * Type for leader anchors. - */ -typedef struct { - int left_x; /* left leader anchor field or percent of bbox */ - int right_x; /* right leader anchor field or percent of bbox */ - short left_y; /* left leader percent of bbox or < 0 if field */ - short right_y; /* right leader percent of bbox or < 0 if field */ -} LeaderAnchorsStruct, *LeaderAnchors; #define ZnPixel(color) ((color)->pixel) -#define ZnFontId(font) (Tk_FontId(font)) -#define ZnWindowId(win) (Tk_WindowId(win)) -#define ZnTextWidth(font, text, len) (Tk_TextWidth(font, text, len)) #define ZnMalloc(size) ((void *)ckalloc(size)) #define ZnFree(ptr) (ckfree((char *)(ptr))) #define ZnRealloc(ptr, size) ((void *)ckrealloc((void *)(ptr), size)) @@ -352,49 +105,98 @@ typedef struct { #define ZnUnspecifiedImage None #define ZnUnspecifiedColor NULL -#define ZN_OK TCL_OK -#define ZN_ERROR TCL_ERROR -#define ZN_NO_ITEM NULL - -/* - * Various constants used by items. - */ -#define ZN_ANY_CIRCLES -1 -/* - * Constants for item parts. The fields or item indexable parts are coded - * as positive or null integers. The item specific parts (not indexable) are - * coded as negatives begining at -2 up to -9 which is the current limit. The - * -1 value is reserved to indicate no part. - */ - -#define PART_NUMBER_TO_BIT(part) (1 << (ABS(part)-2)) -#define ZN_NO_PART -1 - -/* - * Constants used to specify circle approximation quality. - */ -#define ZN_CIRCLE_COARSE 0 -#define ZN_CIRCLE_MEDIUM ZN_CIRCLE_COARSE+1 -#define ZN_CIRCLE_FINE ZN_CIRCLE_MEDIUM+1 -#define ZN_CIRCLE_FINEST ZN_CIRCLE_FINE+1 - -/* - * Some flags macros. - */ -#define ISSET(var, mask) ((var) & (mask)) -#define ISCLEAR(var, mask) (((var) & (mask)) == 0) -#define SET(var,mask) ((var) |= (mask)) -#define CLEAR(var, mask) ((var) &= ~(mask)) -#define ASSIGN(var, mask, bool) ((bool) ? SET((var), (mask)) : CLEAR((var), (mask))) +#ifndef TCL_INTEGER_SPACE +# define TCL_INTEGER_SPACE 24 +#endif +#ifdef PTK /* * Macros for Tk8.4/perl/Tk utf compatibility */ -#ifdef PTK #define Tcl_NumUtfChars(str, len) ((len)<0?strlen(str):(len)) #define Tcl_UtfAtIndex(str, index) (&(str)[(index)]) #define Tcl_GetString(str) (Tcl_GetStringFromObj(str, NULL)) + +#define Tk_GetScrollInfoObj(interp, argc, args, fract, count) \ + Tk_GetScrollInfo(interp, argc, (Tcl_Obj **) args, fract, count) +#endif + +/* + * Macros for Windows compatibility + */ +#ifdef _WIN32 +# include +#undef XFillRectangle + void XFillRectangle(Display* display, Drawable d, GC gc, + int x, int y, unsigned int width, unsigned int height); +#undef XFillRectangles +void XFillRectangles(Display*display, Drawable d, GC gc, + XRectangle *rectangles, int nrectangles); +#undef XFillArc +void XFillArc(Display* display, Drawable d, GC gc, + int x, int y, unsigned int width, unsigned int height, + int start, int extent); +#undef XFillPolygon +void XFillPolygon(Display* display, Drawable d, GC gc, + XPoint* points, int npoints, int shape, int mode); +#undef XDrawRectangle +void XDrawRectangle(Display* display, Drawable d, GC gc, + int x, int y, unsigned int width, unsigned int height); +#undef XDrawArc +void XDrawArc(Display* display, Drawable d, GC gc, + int x, int y, unsigned int width, unsigned int height, + int start, int extent); +#undef XDrawLine + void XDrawLine(Display* display, Drawable d, GC gc, + int x1, int y1, int x2, int y2); +#undef XDrawLines +void XDrawLines(Display* display, Drawable d, GC gc, + XPoint* points, int npoints, int mode); + +void ZnUnionRegion(TkRegion sra, TkRegion srb, + TkRegion dr_return); +void ZnOffsetRegion(TkRegion reg, int dx, int dy); +TkRegion ZnPolygonRegion(XPoint *points, int n, + int fill_rule); +# ifdef GL +# define ZnGLContext HGLRC +# define ZnGLMakeCurrent(wi) \ +{ \ + wi->hdc = GetDC(wi->hwnd); \ + wglMakeCurrent(wi->hdc, wi->gl_context); \ +} +# define ZnGLRelease(wi) \ + ReleaseDC(wi->hwnd, wi->hdc); +# define ZnGLDestroyContext(wi) \ + wglDeleteContext(wi->gl_context) +# define ZnGLSwapBuffers(wi) \ + SwapBuffers(wi->hdc) +# define ZnGLWaitGL() +# define ZN_GL_LINE_WIDTH_RANGE GL_LINE_WIDTH_RANGE +# define ZN_GL_POINT_SIZE_RANGE GL_POINT_SIZE_RANGE +# endif +#else /* !_WIN32 */ +# define ZnPolygonRegion(points, npoints, fillrule) \ + ((TkRegion) XPolygonRegion(points, npoints, fillrule)) +# define ZnUnionRegion(sra, srb, rreturn) \ + XUnionRegion((Region) sra, (Region) srb, (Region) rreturn) +# define ZnOffsetRegion(reg, dx, dy) \ + XOffsetRegion((Region) reg, dx, dy) +# ifdef GL +# define ZnGLContext GLXContext +# define ZnGLMakeCurrent(wi) \ + glXMakeCurrent(wi->dpy, Tk_WindowId(wi->win), wi->gl_context); +# define ZnGLRelease(wi) +# define ZnGLDestroyContext(wi) \ + glXDestroyContext(wi->dpy, wi->gl_context); +# define ZnGLSwapBuffers(wi) \ + glXSwapBuffers(wi->dpy, Tk_WindowId(wi->win)) +# define ZnGLWaitGL() \ + glXWaitGL() +# define ZN_GL_LINE_WIDTH_RANGE GL_SMOOTH_LINE_WIDTH_RANGE +# define ZN_GL_POINT_SIZE_RANGE GL_SMOOTH_POINT_SIZE_RANGE +# endif #endif #ifdef __CPLUSPLUS__ diff --git a/generic/WidgetInfo.h b/generic/WidgetInfo.h index b9f5ac8..dbccff0 100644 --- a/generic/WidgetInfo.h +++ b/generic/WidgetInfo.h @@ -31,28 +31,46 @@ #define _WidgetInfo_h -#include -#include -#ifdef GLX -#include -#endif - #include "libtess/glu.h" #include "Item.h" #include "Transfo.h" #include "Types.h" +#ifndef _WIN32 #include "perfos.h" +#endif #include "Color.h" -#ifndef NUM_ALPHA_STEPS -#define NUM_ALPHA_STEPS 16 + +#define ZN_NUM_ALPHA_STEPS 16 + +/* + * Constants for flags + */ +#define ZN_REPICK_IN_PROGRESS (1<<0) +#define ZN_LEFT_GRABBED_ITEM (1<<1) +#define ZN_REALIZED (1<<2) +#define ZN_INTERNAL_NEED_REPICK (1<<3) +#define ZN_UPDATE_SCROLLBARS (1<<4) /* If set, the scrollbars must be updated. */ +#define ZN_GOT_FOCUS (1<<5) /* Set means that the widget has the input focus. */ +#define ZN_UPDATE_PENDING (1<<6) /* Set means there is a pending graphic update. */ +#define ZN_HAS_GL (1<<7) /* Tell if openGL can be used. */ +#define ZN_HAS_X_SHAPE (1<<8) /* Tell if the X shape extension is available. */ +#define ZN_MONITORING (1<<9) /* Set if performance monitoring is on. */ +#define ZN_PRINT_CONFIG (1<<10) /* If set the openGL hardware configuration is printed + * on startup. */ + +#ifdef __CPLUSPLUS__ +extern "C" { #endif -/* Constants for flags */ -#define REPICK_IN_PROGRESS 1 -#define LEFT_GRABBED_ITEM 2 -#define INTERNAL_NEED_REPICK 8 +/* + * Structure used by the tesselator. + */ +typedef struct _ZnCombineData { + ZnReal v[2]; + struct _ZnCombineData *next; +} ZnCombineData; /* @@ -62,10 +80,10 @@ * and the item-specific code, but most of the fields should be written * only by the canvas generic code. */ -typedef struct _TextInfo { +typedef struct _ZnTextInfo { ZnGradient *sel_color; /* Background color for selected text. * Read-only to items.*/ - Item sel_item; /* Pointer to selected item. ZN_NO_ITEM + ZnItem sel_item; /* Pointer to selected item. ZN_NO_ITEM * means that the widget doesn't own the * selection. Writable by items. */ int sel_field; @@ -73,7 +91,7 @@ typedef struct _TextInfo { * Writable by items. */ int sel_last; /* Index of last selected character. * Writable by items. */ - Item anchor_item; /* Item corresponding to sel_anchor: not + ZnItem anchor_item; /* Item corresponding to sel_anchor: not * necessarily sel_item. Read-only to items. */ int anchor_field; int sel_anchor; /* Fixed end of selection (i.e. "select to" @@ -81,19 +99,20 @@ typedef struct _TextInfo { * selection). Writable by items. */ ZnGradient *insert_color; /* Used to draw vertical bar for insertion * cursor. Read-only to items. */ - int insert_width; /* Total width of insertion cursor. Read-only + unsigned int insert_width; /* Total width of insertion cursor. Read-only * to items. */ ZnBool cursor_on; /* True means that an insertion cursor should * be displayed in focus_item. Read-only to * items.*/ -} TextInfo; +} ZnTextInfo; -typedef struct _WidgetInfo { +typedef struct _ZnWInfo { Tcl_Interp *interp; /* Interpreter associated with widget. */ Tcl_Command cmd; /* Token for zinc widget command. */ Tcl_HashTable *id_table; /* Hash table for object ids. */ Tcl_HashTable *t_table; /* Hash table for transformations. */ unsigned long obj_id; /* Id for the next new object. */ + int flags; Tk_BindingTable binding_table; /* Table of all bindings currently defined * for this widget. NULL means that no * bindings exist, so the table hasn't been @@ -103,26 +122,22 @@ typedef struct _WidgetInfo { int state; /* Last known modifier state. Used to * defer picking a new current object * while buttons are down. */ - Item current_item; /* Item picked from previous pick sequence */ - Item new_item; /* Item picked from current pick sequence */ + ZnItem current_item; /* Item picked from previous pick sequence */ + ZnItem new_item; /* Item picked from current pick sequence */ int current_part; int new_part; - Item hot_item; - Item hot_prev; - Item focus_item; /* Item that currently has the input focus, + ZnItem hot_item; + ZnItem hot_prev; + ZnItem focus_item; /* Item that currently has the input focus, * or ZN_NO_ITEM if no such item. Read-only to * items. */ int focus_field; - ZnBool got_focus; /* True means that the widget has the input - * focus. Read-only to items.*/ XEvent pick_event; /* Event used to forge fake events and to do * repicks. */ - ZnBool update_pending; /* True means there is a pending graphic - * update. */ ZnBBox exposed_area; /* Window area that need to be rexposed. * It is distinct from redraw_area which * is updated when items are changed. */ - Pixmap alpha_stipples[NUM_ALPHA_STEPS]; + Pixmap alpha_stipples[ZN_NUM_ALPHA_STEPS]; int border_width; int opt_width; /* Window size as stated/reported by the option. */ int opt_height; /* They are equal to the width/height fields after @@ -131,21 +146,21 @@ typedef struct _WidgetInfo { * manager. */ ZnGradient *relief_grad; /* The gradient describing the border relief * colors. */ - ReliefStyle relief; /* The border relief. */ + ZnReliefStyle relief; /* The border relief. */ /* Tracks global resources */ - int track_managed_history_size; /* Size of history for tracks */ + unsigned int track_managed_history_size; /* Size of history for tracks */ ZnBool track_manage_history; /* Tell if the tracks manage their */ /* histories. */ ZnReal speed_vector_length; /* How long (in time) are speedvectors*/ #ifdef OM int om_group_id; /* Tell which group contains tracks to be */ - Item om_group; /* processed for anti label overlap. */ + ZnItem om_group; /* processed for anti label overlap. */ #endif /* Maps global resources */ - ZnFont map_text_font; /* Font for texts in Map items */ -#ifdef GLX + Tk_Font map_text_font; /* Font for texts in Map items */ +#ifdef GL ZnTexFontInfo map_font_tfi; /* Used to preserve the default font from * being freed again and again */ #endif @@ -167,13 +182,11 @@ typedef struct _WidgetInfo { int light_angle; int pick_aperture; /* size of pick aperture in pixels */ - ZnFont font; /* Default font used in new items */ -#ifdef GLX + Tk_Font font; /* Default font used in new items */ +#ifdef GL ZnTexFontInfo font_tfi; /* Used to preserve the default font from * being freed again and again */ #endif - ZnBool reshape; /* Use the Shape Extension on the window.*/ - ZnBool full_reshape; /* Use it on the top level window. */ ZnImage tile; /* Zinc private resources */ @@ -184,28 +197,30 @@ typedef struct _WidgetInfo { /* Graphic variables */ Display *dpy; /* The display of the widget window. */ Screen *screen; - ZnWindow win; /* The window of the widget. */ - ZnBool realized; -#ifdef GLX - GLXContext gl_context; + Tk_Window win; /* The window of the widget. */ +#ifdef GL + ZnGLContext gl_context; +# ifdef _WIN32 + HDC hdc; + HWND hwnd; +# else XVisualInfo *gl_visual; +# endif ZnReal max_line_width; ZnReal max_point_width; -#endif +#endif /* GL */ GLUtesselator *tess; ZnCombineData *tess_combine_list; int tess_type; Pixmap draw_buffer; /* Pixmap for double buffering */ ZnBBox damaged_area; /* The current damaged rectangle */ GC gc; - ZnBool has_glx; /* Tell if openGL can be used. */ - ZnBool has_x_shape; /* Tell if the X shape ext. is avail. */ - ZnBool has_x_input; /* Tell if the X input ext. is avail. */ + ZnBool reshape; /* Use the Shape Extension on the window.*/ + ZnBool full_reshape; /* Use it on the top level window. */ + Window real_top; int render; unsigned char alpha; /* Current composite group alpha. */ - int events_flags; /* NEED_REPICK et al */ - Window real_top; - Item top_group; + ZnItem top_group; ZnList work_item_list; /* Temporary item list used in internal * works. */ ZnList work_pts; /* Temporary point lists. */ @@ -214,7 +229,7 @@ typedef struct _WidgetInfo { ZnList work_strs; /* Temporary string list */ /* Text management */ - TextInfo text_info; + ZnTextInfo text_info; int insert_on_time; int insert_off_time; Tcl_TimerToken blink_handler; @@ -226,14 +241,33 @@ typedef struct _WidgetInfo { * area when highlight is off. */ ZnGradient *highlight_color; /* Color for drawing traversal highlight.*/ + /* Scrollbar management */ + ZnPoint origin; /* Coordinate mapped to the upper left corner + * of the zinc window. */ + char *x_scroll_cmd; /* Command prefixes for communicating with */ + char *y_scroll_cmd; /* scrollbars. NULL means no scrollbar. + * Malloc'ed */ + int x_scroll_incr; /* If >0, defines a grid for horiz/vert */ + int y_scroll_incr; /* scrolling. This is the size of the "unit", + * and the left edge of the screen will always + * lie on an even unit boundary. */ + int scroll_xo; /* This bbox define the region that is the */ + int scroll_yo; /* 100% area for scrolling (i.e. it determines */ + int scroll_xc; /* the size and location of the sliders on */ +int scroll_yc; /* scrollbars). */ + ZnBool confine; /* When true, it is not possible to scroll the + * viewing area past the scroll region. */ + char *region; /* Scroll region option string source of the + * scroll_region above. */ /* Perf measurement variables. */ - ZnBool monitoring; - Chrono this_draw_chrono; - Chrono total_draw_chrono; +#ifndef _WIN32 + ZnChrono this_draw_chrono; + ZnChrono total_draw_chrono; +#endif int num_items; int damaged_area_w; int damaged_area_h; -} WidgetInfo; +} ZnWInfo; #ifdef __CPLUSPLUS__ diff --git a/generic/Window.c b/generic/Window.c index c577ff6..ddc21a3 100644 --- a/generic/Window.c +++ b/generic/Window.c @@ -24,7 +24,6 @@ * */ -#include #include "Item.h" #include "Geo.h" @@ -43,15 +42,15 @@ static const char compile_id[] = "$Compile: " __FILE__ " " __DATE__ " " __TIME__ ********************************************************************************** */ typedef struct _WindowItemStruct { - ItemStruct header; + ZnItemStruct header; /* Public data */ ZnPoint pos; - ZnAnchor anchor; - ZnAnchor connection_anchor; - ZnWindow win; - ZnDim width; - ZnDim height; + Tk_Anchor anchor; + Tk_Anchor connection_anchor; + Tk_Window win; + int width; + int height; /* Private data */ ZnPoint pos_dev; @@ -64,20 +63,20 @@ static ZnAttrConfig wind_attrs[] = { { ZN_CONFIG_ANCHOR, "-anchor", NULL, Tk_Offset(WindowItemStruct, anchor), 0, ZN_COORDS_FLAG, False }, { ZN_CONFIG_BOOL, "-composealpha", NULL, - Tk_Offset(WindowItemStruct, header.flags), COMPOSE_ALPHA_BIT, + Tk_Offset(WindowItemStruct, header.flags), ZN_COMPOSE_ALPHA_BIT, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-composerotation", NULL, - Tk_Offset(WindowItemStruct, header.flags), COMPOSE_ROTATION_BIT, + Tk_Offset(WindowItemStruct, header.flags), ZN_COMPOSE_ROTATION_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_BOOL, "-composescale", NULL, - Tk_Offset(WindowItemStruct, header.flags), COMPOSE_SCALE_BIT, + Tk_Offset(WindowItemStruct, header.flags), ZN_COMPOSE_SCALE_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_ITEM, "-connecteditem", NULL, Tk_Offset(WindowItemStruct, header.connected_item), 0, ZN_COORDS_FLAG|ZN_ITEM_FLAG, False }, { ZN_CONFIG_ANCHOR, "-connectionanchor", NULL, Tk_Offset(WindowItemStruct, connection_anchor), 0, ZN_COORDS_FLAG, False }, - { ZN_CONFIG_DIM, "-height", NULL, + { ZN_CONFIG_INT, "-height", NULL, Tk_Offset(WindowItemStruct, height), 0, ZN_COORDS_FLAG, False }, { ZN_CONFIG_POINT, "-position", NULL, Tk_Offset(WindowItemStruct, pos), 0, ZN_COORDS_FLAG, False}, @@ -85,20 +84,20 @@ static ZnAttrConfig wind_attrs[] = { Tk_Offset(WindowItemStruct, header.priority), 0, ZN_DRAW_FLAG|ZN_REPICK_FLAG, False }, { ZN_CONFIG_BOOL, "-sensitive", NULL, - Tk_Offset(WindowItemStruct, header.flags), SENSITIVE_BIT, + Tk_Offset(WindowItemStruct, header.flags), ZN_SENSITIVE_BIT, ZN_REPICK_FLAG, False }, { ZN_CONFIG_TAG_LIST, "-tags", NULL, Tk_Offset(WindowItemStruct, header.tags), 0, 0, False }, { ZN_CONFIG_BOOL, "-visible", NULL, - Tk_Offset(WindowItemStruct, header.flags), VISIBLE_BIT, + Tk_Offset(WindowItemStruct, header.flags), ZN_VISIBLE_BIT, ZN_DRAW_FLAG|ZN_REPICK_FLAG|ZN_VIS_FLAG, False }, - { ZN_CONFIG_DIM, "-width", NULL, + { ZN_CONFIG_INT, "-width", NULL, Tk_Offset(WindowItemStruct, width), 0, ZN_COORDS_FLAG, False }, { ZN_CONFIG_WINDOW, "-window", NULL, Tk_Offset(WindowItemStruct, win), 0, ZN_COORDS_FLAG|ZN_WINDOW_FLAG, False }, - { ZN_CONFIG_END, NULL, NULL, 0, 0, 0 } + { ZN_CONFIG_END, NULL, NULL, 0, 0, 0, False } }; @@ -136,11 +135,11 @@ WindowDeleted(ClientData client_data, */ static void WindowItemRequest(ClientData client_data, - ZnWindow win) + Tk_Window win __unused) { WindowItem wind = (WindowItem) client_data; - ITEM.Invalidate((Item) wind, ZN_COORDS_FLAG); + ZnITEM.Invalidate((ZnItem) wind, ZN_COORDS_FLAG); } /* @@ -149,10 +148,10 @@ WindowItemRequest(ClientData client_data, */ static void WindowItemLostSlave(ClientData client_data, - ZnWindow win) + Tk_Window win __unused) { WindowItem wind = (WindowItem) client_data; - WidgetInfo *wi = ((Item) wind)->wi; + ZnWInfo *wi = ((ZnItem) wind)->wi; Tk_DeleteEventHandler(wi->win, StructureNotifyMask, WindowDeleted, (ClientData) wind); @@ -178,27 +177,27 @@ static Tk_GeomMgr wind_geom_type = { ********************************************************************************** */ static int -Init(Item item, - int *argc, - Tcl_Obj *CONST *args[]) +Init(ZnItem item, + int *argc __unused, + Tcl_Obj *CONST *args[] __unused) { WindowItem wind = (WindowItem) item; /* Init attributes */ - SET(item->flags, VISIBLE_BIT); - SET(item->flags, SENSITIVE_BIT); - SET(item->flags, COMPOSE_ALPHA_BIT); /* N.A */ - SET(item->flags, COMPOSE_ROTATION_BIT); - SET(item->flags, COMPOSE_SCALE_BIT); - item->priority = DEFAULT_WINDOW_PRIORITY; /* N.A */ + SET(item->flags, ZN_VISIBLE_BIT); + SET(item->flags, ZN_SENSITIVE_BIT); + SET(item->flags, ZN_COMPOSE_ALPHA_BIT); /* N.A */ + SET(item->flags, ZN_COMPOSE_ROTATION_BIT); + SET(item->flags, ZN_COMPOSE_SCALE_BIT); + item->priority = 0; wind->pos.x = wind->pos.y = 0.0; wind->width = wind->height = 0; - wind->anchor = ZnAnchorNW; - wind->connection_anchor = ZnAnchorSW; + wind->anchor = TK_ANCHOR_NW; + wind->connection_anchor = TK_ANCHOR_SW; wind->win = NULL; - return ZN_OK; + return TCL_OK; } @@ -210,7 +209,7 @@ Init(Item item, ********************************************************************************** */ static void -Clone(Item item) +Clone(ZnItem item) { WindowItem wind = (WindowItem) item; @@ -229,9 +228,9 @@ Clone(Item item) ********************************************************************************** */ static void -Destroy(Item item) +Destroy(ZnItem item) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; WindowItem wind = (WindowItem) item; /* @@ -257,20 +256,20 @@ Destroy(Item item) ********************************************************************************** */ static int -Configure(Item item, +Configure(ZnItem item, int argc, Tcl_Obj *CONST argv[], int *flags) { WindowItem wind = (WindowItem) item; - WidgetInfo *wi = item->wi; - Item old_connected; - ZnWindow old_win; + ZnWInfo *wi = item->wi; + ZnItem old_connected; + Tk_Window old_win; old_connected = item->connected_item; old_win = wind->win; - if (ZnConfigureAttributes(wi, item, wind_attrs, argc, argv, flags) == ZN_ERROR) { - return ZN_ERROR; + if (ZnConfigureAttributes(wi, item, wind_attrs, argc, argv, flags) == TCL_ERROR) { + return TCL_ERROR; } if (ISSET(*flags, ZN_ITEM_FLAG)) { @@ -281,7 +280,7 @@ Configure(Item item, if ((item->connected_item == ZN_NO_ITEM) || (item->connected_item->class->has_anchors && (item->parent == item->connected_item->parent))) { - ITEM.UpdateItemDependency(item, old_connected); + ZnITEM.UpdateItemDependency(item, old_connected); } else { item->connected_item = old_connected; @@ -305,11 +304,11 @@ Configure(Item item, if ((wind->win != NULL) && ISSET(*flags, ZN_VIS_FLAG) && - ISCLEAR(item->flags, VISIBLE_BIT)) { + ISCLEAR(item->flags, ZN_VISIBLE_BIT)) { Tk_UnmapWindow(wind->win); } - return ZN_OK; + return TCL_OK; } @@ -321,15 +320,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, wind_attrs, argv[0]) == ZN_ERROR) { - return ZN_ERROR; + if (ZnQueryAttribute(item->wi, item, wind_attrs, argv[0]) == TCL_ERROR) { + return TCL_ERROR; } - return ZN_OK; + return TCL_OK; } @@ -341,13 +340,13 @@ Query(Item item, ********************************************************************************** */ static void -ComputeCoordinates(Item item, - ZnBool force) +ComputeCoordinates(ZnItem item, + ZnBool force __unused) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; WindowItem wind = (WindowItem) item; - ResetBBox(&item->item_bounding_box); + ZnResetBBox(&item->item_bounding_box); if (wind->win == NULL) { return; @@ -381,17 +380,17 @@ ComputeCoordinates(Item item, ZnTransformPoint(wi->current_transfo, &wind->pos, &wind->pos_dev); } - Anchor2Origin(&wind->pos_dev, wind->real_width, wind->real_height, wind->anchor, - &wind->pos_dev); - wind->pos_dev.x = REAL_TO_INT(wind->pos_dev.x); - wind->pos_dev.y = REAL_TO_INT(wind->pos_dev.y); + ZnAnchor2Origin(&wind->pos_dev, (ZnReal) wind->real_width, (ZnReal) wind->real_height, + wind->anchor, &wind->pos_dev); + wind->pos_dev.x = ZnNearestInt(wind->pos_dev.x); + wind->pos_dev.y = ZnNearestInt(wind->pos_dev.y); /* * Compute the bounding box. */ - AddPointToBBox(&item->item_bounding_box, wind->pos_dev.x, wind->pos_dev.y); - AddPointToBBox(&item->item_bounding_box, wind->pos_dev.x+wind->real_width, - wind->pos_dev.y+wind->real_height); + ZnAddPointToBBox(&item->item_bounding_box, wind->pos_dev.x, wind->pos_dev.y); + ZnAddPointToBBox(&item->item_bounding_box, wind->pos_dev.x+wind->real_width, + wind->pos_dev.y+wind->real_height); item->item_bounding_box.orig.x -= 1.0; item->item_bounding_box.orig.y -= 1.0; item->item_bounding_box.corner.x += 1.0; @@ -400,7 +399,7 @@ ComputeCoordinates(Item item, /* * Update connected items. */ - SET(item->flags, UPDATE_DEPENDENT_BIT); + SET(item->flags, ZN_UPDATE_DEPENDENT_BIT); } @@ -414,7 +413,7 @@ ComputeCoordinates(Item item, ********************************************************************************** */ static int -ToArea(Item item, +ToArea(ZnItem item, ZnToArea ta) { WindowItem wind = (WindowItem) item; @@ -429,7 +428,7 @@ ToArea(Item item, box.corner.x = box.orig.x + w; box.corner.y = box.orig.y + h; - return BBoxInBBox(&box, ta->area); + return ZnBBoxInBBox(&box, ta->area); } /* @@ -440,9 +439,9 @@ ToArea(Item item, ********************************************************************************** */ static void -Draw(Item item) +Draw(ZnItem item) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; WindowItem wind = (WindowItem) item; if (wind->win == NULL) { @@ -474,14 +473,14 @@ Draw(Item item) (wind->real_width != Tk_Width(wind->win)) || (wind->real_height != Tk_Height(wind->win))) { Tk_MoveResizeWindow(wind->win, - wind->pos_dev.x, wind->pos_dev.y, + (int) wind->pos_dev.x, (int) wind->pos_dev.y, wind->real_width, wind->real_height); } Tk_MapWindow(wind->win); } else { Tk_MaintainGeometry(wind->win, wi->win, - wind->pos_dev.x, wind->pos_dev.y, + (int) wind->pos_dev.x, (int) wind->pos_dev.y, wind->real_width, wind->real_height); } @@ -496,8 +495,8 @@ Draw(Item item) ********************************************************************************** */ static ZnBool -IsSensitive(Item item, - int item_part) +IsSensitive(ZnItem item __unused, + int item_part __unused) { /* * Sensitivity can't be controlled. @@ -514,7 +513,7 @@ IsSensitive(Item item, ********************************************************************************** */ static double -Pick(Item item, +Pick(ZnItem item, ZnPick ps) { WindowItem wind = (WindowItem) item; @@ -526,7 +525,7 @@ Pick(Item item, if (wind->win != NULL) { box.corner.x = box.orig.x + wind->real_width; box.corner.y = box.orig.y + wind->real_height; - dist = RectangleToPointDist(&box, p); + dist = ZnRectangleToPointDist(&box, p); if (dist <= 0.0) { dist = 0.0; } @@ -543,8 +542,8 @@ Pick(Item item, ********************************************************************************** */ static void -PostScript(Item item, - PostScriptInfo ps_info) +PostScript(ZnItem item __unused, + ZnPostScriptInfo ps_info __unused) { } @@ -557,15 +556,15 @@ PostScript(Item item, ********************************************************************************** */ static void -GetAnchor(Item item, - ZnAnchor anchor, +GetAnchor(ZnItem item, + Tk_Anchor anchor, ZnPoint *p) { WindowItem wind = (WindowItem) item; if (wind->win != NULL) { - Origin2Anchor(&wind->pos_dev, wind->real_width, - wind->real_height, anchor, p); + ZnOrigin2Anchor(&wind->pos_dev, (ZnReal) wind->real_width, + (ZnReal) wind->real_height, anchor, p); } else { p->x = p->y = 0.0; @@ -582,7 +581,7 @@ GetAnchor(Item item, ********************************************************************************** */ static ZnBool -GetClipVertices(Item item, +GetClipVertices(ZnItem item, ZnTriStrip *tristrip) { WindowItem wind = (WindowItem) item; @@ -595,7 +594,7 @@ GetClipVertices(Item item, h = wind->real_height; } points = ZnListArray(item->wi->work_pts); - TRI_STRIP1(tristrip, points, 2, False); + ZnTriStrip1(tristrip, points, 2, False); points[0] = wind->pos_dev; points[1].x = points[0].x + w; points[1].y = points[0].y + h; @@ -615,35 +614,35 @@ GetClipVertices(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 __unused, + int cmd, + ZnPoint **pts, + char **controls __unused, + unsigned int *num_pts) { WindowItem wind = (WindowItem) item; - if ((cmd == COORDS_ADD) || (cmd == COORDS_ADD_LAST) || (cmd == COORDS_REMOVE)) { + if ((cmd == ZN_COORDS_ADD) || (cmd == ZN_COORDS_ADD_LAST) || (cmd == ZN_COORDS_REMOVE)) { Tcl_AppendResult(item->wi->interp, " windows can't add or remove vertices", NULL); - return ZN_ERROR; + return TCL_ERROR; } - else if ((cmd == COORDS_REPLACE) || (cmd == COORDS_REPLACE_ALL)) { + else if ((cmd == ZN_COORDS_REPLACE) || (cmd == ZN_COORDS_REPLACE_ALL)) { if (*num_pts == 0) { Tcl_AppendResult(item->wi->interp, " coords command need 1 point on windows", NULL); - return ZN_ERROR; + return TCL_ERROR; } wind->pos = (*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)) { *num_pts = 1; *pts = &wind->pos; } - return ZN_OK; + return TCL_OK; } @@ -654,7 +653,7 @@ Coords(Item item, * ********************************************************************************** */ -static ItemClassStruct WINDOW_ITEM_CLASS = { +static ZnItemClassStruct WINDOW_ITEM_CLASS = { sizeof(WindowItemStruct), 0, /* num_parts */ True, /* has_anchors */ @@ -687,4 +686,4 @@ static ItemClassStruct WINDOW_ITEM_CLASS = { PostScript }; -ZnItemClassId ZnWind = (ZnItemClassId) &WINDOW_ITEM_CLASS; +ZnItemClassId ZnWindow = (ZnItemClassId) &WINDOW_ITEM_CLASS; diff --git a/generic/perfos.c b/generic/perfos.c index df7af11..3a0847a 100644 --- a/generic/perfos.c +++ b/generic/perfos.c @@ -26,13 +26,13 @@ * */ +#ifndef _WIN32 #include "perfos.h" #include "List.h" #include "Types.h" #include -#include static const char rcsid[] = "$Id$"; @@ -50,7 +50,8 @@ static ZnList Chronos = NULL; ********************************************************************************** */ static void -HardwareSynchronize(Display *test_display, Drawable test_window) +HardwareSynchronize(Display *test_display __unused, + Drawable test_window __unused) { /*XImage *image;*/ @@ -139,12 +140,12 @@ XCorrectionValue(Display *display, Drawable window) /* ********************************************************************************** * - * XStartChrono - Start a perf chrono with X synchronize. + * ZnXStartChrono - Start a perf chrono with X synchronize. * ********************************************************************************** */ void -XStartChrono(Chrono chrono, Display *display, Drawable window) +ZnXStartChrono(ZnChrono chrono, Display *display, Drawable window) { chrono->current_correction = XCorrectionValue(display, window); chrono->current_delay = XGetCurrentTime(display, window); @@ -154,12 +155,12 @@ XStartChrono(Chrono chrono, Display *display, Drawable window) /* ********************************************************************************** * - * XStopChrono - Stop a perf chrono with X synchronize. + * ZnXStopChrono - Stop a perf chrono with X synchronize. * ********************************************************************************** */ void -XStopChrono(Chrono chrono, Display *display, Drawable window) +ZnXStopChrono(ZnChrono chrono, Display *display, Drawable window) { chrono->total_delay = chrono->total_delay + (XGetCurrentTime(display, window) - @@ -171,12 +172,12 @@ XStopChrono(Chrono chrono, Display *display, Drawable window) /* ********************************************************************************** * - * StartChrono - Start a perf chrono in user time. + * ZnStartChrono - Start a perf chrono in user time. * ********************************************************************************** */ void -StartChrono(Chrono chrono) +ZnStartChrono(ZnChrono chrono) { chrono->current_delay = GetCurrentTime(); } @@ -185,12 +186,12 @@ StartChrono(Chrono chrono) /* ********************************************************************************** * - * StopChrono - Stop a perf chrono in user time. + * ZnStopChrono - Stop a perf chrono in user time. * ********************************************************************************** */ void -StopChrono(Chrono chrono) +ZnStopChrono(ZnChrono chrono) { chrono->total_delay = chrono->total_delay + (GetCurrentTime() - chrono->current_delay); chrono->actions++; @@ -200,12 +201,12 @@ StopChrono(Chrono chrono) /* ********************************************************************************** * - * StartUCChrono - Start a perf chrono in uc time. + * ZnStartUCChrono - Start a perf chrono in uc time. * ********************************************************************************** */ void -StartUCChrono(Chrono chrono) +ZnStartUCChrono(ZnChrono chrono) { chrono->current_delay = GetUCTime(); } @@ -214,12 +215,12 @@ StartUCChrono(Chrono chrono) /* ********************************************************************************** * - * StopUCChrono - Stop a perf chrono in uc time. + * ZnStopUCChrono - Stop a perf chrono in uc time. * ********************************************************************************** */ void -StopUCChrono(Chrono chrono) +ZnStopUCChrono(ZnChrono chrono) { chrono->total_delay = chrono->total_delay + (GetUCTime() - chrono->current_delay); chrono->actions++; @@ -229,19 +230,19 @@ StopUCChrono(Chrono chrono) /* ********************************************************************************** * - * PrintChronos - Print the currently available stats on all + * ZnPrintChronos - Print the currently available stats on all * chronos registered so far. * ********************************************************************************** */ void -PrintChronos(void) +ZnPrintChronos(void) { int i, cnt; - Chrono *chrs; + ZnChrono *chrs; cnt = ZnListSize(Chronos); - chrs = (Chrono *) ZnListArray(Chronos); + chrs = (ZnChrono *) ZnListArray(Chronos); for (i = 0; i < cnt; i++) { if (chrs[i]->actions != 0) { printf("%s : %ld ms on %d times\n", @@ -256,14 +257,14 @@ PrintChronos(void) /* ********************************************************************************** * - * GetChrono - Return the number of runs and the total time of the Chrono. + * ZnGetChrono - Return the number of runs and the total time of the Chrono. * ********************************************************************************** */ void -GetChrono(Chrono chrono, - long *time, - int *actions) +ZnGetChrono(ZnChrono chrono, + long *time, + int *actions) { if (time) { *time = chrono->total_delay*10; @@ -277,15 +278,15 @@ GetChrono(Chrono chrono, /* ********************************************************************************** * - * ResetChronos - Reset all chronos or only the specified. + * ZnResetChronos - Reset all chronos or only the specified. * ********************************************************************************** */ void -ResetChronos(Chrono chrono) +ZnResetChronos(ZnChrono chrono) { int i, cnt; - Chrono *chrs; + ZnChrono *chrs; if (chrono) { chrono->actions = 0; @@ -293,7 +294,7 @@ ResetChronos(Chrono chrono) } else { cnt = ZnListSize(Chronos); - chrs = (Chrono *) ZnListArray(Chronos); + chrs = (ZnChrono *) ZnListArray(Chronos); for (i = 0; i < cnt; i++) { chrs[i]->actions = 0; chrs[i]->total_delay = 0; @@ -305,21 +306,21 @@ ResetChronos(Chrono chrono) /* ********************************************************************************** * - * NewChrono - Return a new initialized chrono associated with + * ZnNewChrono - Return a new initialized chrono associated with * message. * ********************************************************************************** */ -Chrono -NewChrono(char *message) +ZnChrono +ZnNewChrono(char *message) { - Chrono new; + ZnChrono new; if (!Chronos) { - Chronos = ZnListNew(8, sizeof(Chrono)); + Chronos = ZnListNew(8, sizeof(ZnChrono)); } - new = (Chrono) ZnMalloc(sizeof(ChronoRec)); + new = (ZnChrono) ZnMalloc(sizeof(ZnChronoRec)); new->actions = 0; new->total_delay = 0; new->message = message; @@ -332,15 +333,15 @@ NewChrono(char *message) /* ********************************************************************************** * - * FreeChrono - Free the resources of a chrono. + * ZnFreeChrono - Free the resources of a chrono. * ********************************************************************************** */ void -FreeChrono(Chrono chrono) +ZnFreeChrono(ZnChrono chrono) { - int i; - Chrono *chrs = ZnListArray(Chronos); + int i; + ZnChrono *chrs = ZnListArray(Chronos); ZnFree(chrono); @@ -351,3 +352,5 @@ FreeChrono(Chrono chrono) } } } + +#endif /* _WIN32 */ diff --git a/generic/perfos.h b/generic/perfos.h index 9e5627c..4fef0b6 100644 --- a/generic/perfos.h +++ b/generic/perfos.h @@ -34,6 +34,8 @@ extern "C" { #endif +#ifndef _WIN32 + #include #include #include @@ -48,20 +50,22 @@ extern "C" { long total_delay; int actions; char *message; - } ChronoRec, *Chrono; + } ZnChronoRec, *ZnChrono; - void XStartChrono(Chrono /*chrono*/, Display */*dpy*/, Drawable /*win*/); - void XStopChrono(Chrono /*chrono*/, Display */*dpy*/, Drawable /*win*/); - void StartChrono(Chrono /*chrono*/); - void StopChrono(Chrono /*chrono*/); - void StartUCChrono(Chrono /*chrono*/); - void StopUCChrono(Chrono /*chrono*/); - Chrono NewChrono(char */*message*/); - void FreeChrono(Chrono /*chrono*/); - void PrintChronos(void); - void GetChrono(Chrono /*chrono*/, long */*time*/, int */*actions*/); - void ResetChronos(Chrono /*chrono*/); + void ZnXStartChrono(ZnChrono /*chrono*/, Display */*dpy*/, Drawable /*win*/); + void ZnXStopChrono(ZnChrono /*chrono*/, Display */*dpy*/, Drawable /*win*/); + void ZnStartChrono(ZnChrono /*chrono*/); + void ZnStopChrono(ZnChrono /*chrono*/); + void ZnStartUCChrono(ZnChrono /*chrono*/); + void ZnStopUCChrono(ZnChrono /*chrono*/); + ZnChrono ZnNewChrono(char */*message*/); + void ZnFreeChrono(ZnChrono /*chrono*/); + void ZnPrintChronos(void); + void ZnGetChrono(ZnChrono /*chrono*/, long */*time*/, int */*actions*/); + void ZnResetChronos(ZnChrono /*chrono*/); + +#endif /* _WIN32 */ #ifdef __CPLUSPLUS__ } diff --git a/generic/tkZinc.c b/generic/tkZinc.c index 1a8a3f0..4f5e7a3 100644 --- a/generic/tkZinc.c +++ b/generic/tkZinc.c @@ -27,16 +27,18 @@ */ /* - * Some functions in this file are derived from tkCanvas.c and thus - * copyrighted: + * Some functions and code excerpts in this file are from tkCanvas.c + * and thus copyrighted: * * Copyright (c) 1991-1994 The Regents of the University of California. - * Copyright (c) 1994-1995 Sun Microsystems, Inc. + * Copyright (c) 1994-1997 Sun Microsystems, Inc. + * Copyright (c) 1998-1999 by Scriptics Corporation. * */ static const char rcs_id[]="$Id$"; static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ " $"; +static const char * const zinc_version = "zinc-version-" VERSION; #include "Types.h" @@ -46,14 +48,15 @@ static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ " #include "WidgetInfo.h" #include "tkZinc.h" #include "MapInfo.h" -#include "patchlvl.h" #include "OverlapMan.h" #include "Track.h" #include "Transfo.h" #include "Image.h" #include "Draw.h" #include "Color.h" +#ifndef _WIN32 #include "perfos.h" +#endif #include "libtess/glu.h" #include @@ -62,9 +65,6 @@ static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ " #include #include #include -#ifdef GLX -#include -#endif typedef struct _TagSearchExpr { @@ -78,11 +78,9 @@ typedef struct _TagSearchExpr { } TagSearchExpr; -#define INTEGER_SPACE 30 - #define SYMBOL_WIDTH 8 #define SYMBOL_HEIGHT 8 -static char SYMBOLS_BITS[][SYMBOL_WIDTH*SYMBOL_HEIGHT/8] = { +static unsigned char SYMBOLS_BITS[][SYMBOL_WIDTH*SYMBOL_HEIGHT/8] = { { 0x18, 0x18, 0x24, 0x24, 0x5a, 0x5a, 0x81, 0xff }, { 0xff, 0x81, 0x99, 0xbd, 0xbd, 0x99, 0x81, 0xff }, { 0x18, 0x24, 0x42, 0x99, 0x99, 0x42, 0x24, 0x18 }, @@ -113,7 +111,8 @@ static unsigned char dither4x4[4][4] = { { 3, 11, 1, 9 }, { 15, 7, 13, 5 } }; -static unsigned char bitmaps[NUM_ALPHA_STEPS][32][4]; + +static unsigned char bitmaps[ZN_NUM_ALPHA_STEPS][32][4]; static Tk_Uid all_uid; static Tk_Uid current_uid; @@ -175,77 +174,91 @@ static Tk_CustomOption bitmapOption = { */ static Tk_ConfigSpec config_specs[] = { {TK_CONFIG_PIXELS, "-borderwidth", "borderWidth", "BorderWidth", - "2", Tk_Offset(WidgetInfo, border_width), 0}, + "2", Tk_Offset(ZnWInfo, border_width), 0, NULL}, {TK_CONFIG_CUSTOM, "-backcolor", "backColor", "BackColor", - "#c3c3c3", Tk_Offset(WidgetInfo, back_color), 0, &gradientOption}, + "#c3c3c3", Tk_Offset(ZnWInfo, back_color), 0, &gradientOption}, + {TK_CONFIG_BOOLEAN, "-confine", "confine", "Confine", + "1", Tk_Offset(ZnWInfo, confine), 0, NULL}, {TK_CONFIG_ACTIVE_CURSOR, "-cursor", "cursor", "Cursor", - "", Tk_Offset(WidgetInfo, cursor), TK_CONFIG_NULL_OK}, + "", Tk_Offset(ZnWInfo, cursor), TK_CONFIG_NULL_OK, NULL}, {TK_CONFIG_FONT, "-font", "font", "Font", "-adobe-helvetica-bold-r-normal--*-120-*-*-*-*-*-*", - Tk_Offset(WidgetInfo, font), 0}, + Tk_Offset(ZnWInfo, font), 0, NULL}, {TK_CONFIG_CUSTOM, "-forecolor", "foreColor", "Foreground", - "Black", Tk_Offset(WidgetInfo, fore_color), 0, &gradientOption}, + "Black", Tk_Offset(ZnWInfo, fore_color), 0, &gradientOption}, +#ifndef _WIN32 {TK_CONFIG_BOOLEAN, "-fullreshape", "fullReshape", "FullReshape", - "1", Tk_Offset(WidgetInfo, full_reshape), 0}, + "1", Tk_Offset(ZnWInfo, full_reshape), 0, NULL}, +#endif {TK_CONFIG_PIXELS, "-height", "height", "Height", - "7c", Tk_Offset(WidgetInfo, opt_height), 0}, + "7c", Tk_Offset(ZnWInfo, opt_height), 0, NULL}, {TK_CONFIG_CUSTOM, "-highlightbackground", "highlightBackground", "HighlightBackground", - "#c3c3c3", Tk_Offset(WidgetInfo, highlight_bg_color), 0, &gradientOption}, + "#c3c3c3", Tk_Offset(ZnWInfo, highlight_bg_color), 0, &gradientOption}, {TK_CONFIG_CUSTOM, "-highlightcolor", "highlightColor", "HighlightColor", - "Black", Tk_Offset(WidgetInfo, highlight_color), 0, &gradientOption}, + "Black", Tk_Offset(ZnWInfo, highlight_color), 0, &gradientOption}, {TK_CONFIG_PIXELS, "-highlightthickness", "highlightThickness", "HighlightThickness", - "2", Tk_Offset(WidgetInfo, highlight_width), 0}, + "2", Tk_Offset(ZnWInfo, highlight_width), 0, NULL}, {TK_CONFIG_CUSTOM, "-insertbackground", "insertBackground", "Foreground", - "Black", Tk_Offset(WidgetInfo, text_info.insert_color), 0, &gradientOption}, + "Black", Tk_Offset(ZnWInfo, text_info.insert_color), 0, &gradientOption}, {TK_CONFIG_INT, "-insertofftime", "insertOffTime", "OffTime", - "300", Tk_Offset(WidgetInfo, insert_off_time), 0}, + "300", Tk_Offset(ZnWInfo, insert_off_time), 0, NULL}, {TK_CONFIG_INT, "-insertontime", "insertOnTime", "OnTime", - "600", Tk_Offset(WidgetInfo, insert_on_time), 0}, + "600", Tk_Offset(ZnWInfo, insert_on_time), 0, NULL}, {TK_CONFIG_PIXELS, "-insertwidth", "insertWidth", "InsertWidth", - "2", Tk_Offset(WidgetInfo, text_info.insert_width), 0}, + "2", Tk_Offset(ZnWInfo, text_info.insert_width), 0, NULL}, {TK_CONFIG_CUSTOM, "-mapdistancesymbol", "mapDistanceSymbol", "MapDistanceSymbol", - "AtcSymbol19", Tk_Offset(WidgetInfo, map_distance_symbol), + "AtcSymbol19", Tk_Offset(ZnWInfo, map_distance_symbol), TK_CONFIG_NULL_OK, &bitmapOption}, {TK_CONFIG_FONT, "-maptextfont", "mapTextFont", "MapTextFont", "-adobe-helvetica-bold-r-normal--*-120-*-*-*-*-*-*", - Tk_Offset(WidgetInfo, map_text_font), 0}, + Tk_Offset(ZnWInfo, map_text_font), 0, NULL}, #ifdef OM {TK_CONFIG_INT, "-overlapmanager", "overlapManager", "OverlapManager", "1", - Tk_Offset(WidgetInfo, om_group_id), 0}, + Tk_Offset(ZnWInfo, om_group_id), 0, NULL}, #endif {TK_CONFIG_INT, "-pickaperture", "pickAperture", "PickAperture", - "1", Tk_Offset(WidgetInfo, pick_aperture), 0}, + "1", Tk_Offset(ZnWInfo, pick_aperture), 0, NULL}, {TK_CONFIG_CUSTOM, "-relief", "relief", "Relief", - "flat", Tk_Offset(WidgetInfo, relief), 0, &reliefOption}, + "flat", Tk_Offset(ZnWInfo, relief), 0, &reliefOption}, {TK_CONFIG_INT, "-render", "render", "Render", - "0", Tk_Offset(WidgetInfo, render), 0}, + "0", Tk_Offset(ZnWInfo, render), 0, NULL}, {TK_CONFIG_BOOLEAN, "-reshape", "reshape", "Reshape", - "1", Tk_Offset(WidgetInfo, reshape), 0}, + "1", Tk_Offset(ZnWInfo, reshape), 0, NULL}, + {TK_CONFIG_STRING, "-scrollregion", "scrollRegion", "ScrollRegion", + "", Tk_Offset(ZnWInfo, region), TK_CONFIG_NULL_OK, NULL}, {TK_CONFIG_CUSTOM, "-selectbackground", "selectBackground", "Foreground", - "#a0a0a0", Tk_Offset(WidgetInfo, text_info.sel_color), 0, &gradientOption}, + "#a0a0a0", Tk_Offset(ZnWInfo, text_info.sel_color), 0, &gradientOption}, {TK_CONFIG_DOUBLE, "-speedvectorlength", "speedVectorLength", - "SpeedVectorLength", "3", Tk_Offset(WidgetInfo, speed_vector_length), 0}, + "SpeedVectorLength", "3", Tk_Offset(ZnWInfo, speed_vector_length), 0, NULL}, {TK_CONFIG_STRING, "-takefocus", "takeFocus", "TakeFocus", - NULL, Tk_Offset(WidgetInfo, take_focus), TK_CONFIG_NULL_OK}, + NULL, Tk_Offset(ZnWInfo, take_focus), TK_CONFIG_NULL_OK, NULL}, {TK_CONFIG_CUSTOM, "-tile", "tile", "Tile", - "", Tk_Offset(WidgetInfo, tile), 0, &imageOption}, + "", Tk_Offset(ZnWInfo, tile), 0, &imageOption}, {TK_CONFIG_BOOLEAN, "-trackmanagehistory", "trackManageHistory", "TrackManageHistory", - "1", Tk_Offset(WidgetInfo, track_manage_history), 0}, + "1", Tk_Offset(ZnWInfo, track_manage_history), 0, NULL}, {TK_CONFIG_INT, "-trackmanagedhistorysize", "trackManagedHistorySize", - "TrackManagedHistorySize", "6", Tk_Offset(WidgetInfo, track_managed_history_size), 0}, + "TrackManagedHistorySize", "6", Tk_Offset(ZnWInfo, track_managed_history_size), 0, NULL}, {TK_CONFIG_PIXELS, "-width", "width", "Width", - "10c", Tk_Offset(WidgetInfo, opt_width), 0}, + "10c", Tk_Offset(ZnWInfo, opt_width), 0, NULL}, + {TK_CONFIG_STRING, "-xscrollcommand", "xScrollCommand", "ScrollCommand", + "", Tk_Offset(ZnWInfo, x_scroll_cmd), TK_CONFIG_NULL_OK, NULL}, + {TK_CONFIG_PIXELS, "-xscrollincrement", "xScrollIncrement", "ScrollIncrement", + "0", Tk_Offset(ZnWInfo, x_scroll_incr), 0, NULL}, + {TK_CONFIG_STRING, "-yscrollcommand", "yScrollCommand", "ScrollCommand", + "", Tk_Offset(ZnWInfo, y_scroll_cmd), TK_CONFIG_NULL_OK, NULL}, + {TK_CONFIG_PIXELS, "-yscrollincrement", "yScrollIncrement", "ScrollIncrement", + "0", Tk_Offset(ZnWInfo, y_scroll_incr), 0, NULL}, /* * Debug options. */ {TK_CONFIG_BOOLEAN, "-drawbboxes", "drawBBoxes", - "DrawBBoxes", "0", Tk_Offset(WidgetInfo, draw_bboxes), 0}, + "DrawBBoxes", "0", Tk_Offset(ZnWInfo, draw_bboxes), 0, NULL}, {TK_CONFIG_CUSTOM, "-bboxcolor", "bboxColor", "BBoxColor", - "Pink", Tk_Offset(WidgetInfo, bbox_color), 0, &gradientOption}, + "Pink", Tk_Offset(ZnWInfo, bbox_color), 0, &gradientOption}, {TK_CONFIG_INT, "-lightangle", "lightAngle", "LightAngle", - "120", Tk_Offset(WidgetInfo, light_angle), 0}, + "120", Tk_Offset(ZnWInfo, light_angle), 0, NULL}, - {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0} + {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0, NULL} }; /* @@ -253,35 +266,41 @@ static Tk_ConfigSpec config_specs[] = { */ #define BORDER_WIDTH_SPEC 0 #define BACK_COLOR_SPEC 1 -#define CURSOR_SPEC 2 -#define FONT_SPEC 3 -#define FORE_COLOR_SPEC 4 -#define FULL_RESHAPE_SPEC 5 -#define HEIGHT_SPEC 6 -#define HIGHLIGHT_BACK_COLOR_SPEC 7 -#define HIGHLIGHT_COLOR_SPEC 8 -#define HIGHLIGHT_THICKNESS_SPEC 9 -#define INSERT_COLOR_SPEC 10 -#define INSERT_OFF_TIME_SPEC 11 -#define INSERT_ON_TIME_SPEC 12 -#define INSERT_WIDTH_SPEC 13 -#define MAP_DISTANCE_SYMBOL_SPEC 14 -#define MAP_TEXT_FONT_SPEC 15 -#define OVERLAP_MANAGER_SPEC 16 -#define PICK_APERTURE_SPEC 17 -#define RELIEF_SPEC 18 -#define RENDER_SPEC 19 -#define RESHAPE_SPEC 20 -#define SELECT_COLOR_SPEC 21 -#define SPEED_VECTOR_LENGTH_SPEC 22 -#define TAKE_FOCUS_SPEC 23 -#define TILE_SPEC 24 -#define MANAGE_HISTORY_SPEC 25 -#define MANAGED_HISTORY_SIZE_SPEC 26 -#define WIDTH_SPEC 27 -#define BBOXES_SPEC 28 -#define BBOXES_COLOR_SPEC 29 -#define LIGHT_ANGLE_SPEC 30 +#define CONFINE_SPEC 2 +#define CURSOR_SPEC 3 +#define FONT_SPEC 4 +#define FORE_COLOR_SPEC 5 +#define FULL_RESHAPE_SPEC 6 +#define HEIGHT_SPEC 7 +#define HIGHLIGHT_BACK_COLOR_SPEC 8 +#define HIGHLIGHT_COLOR_SPEC 9 +#define HIGHLIGHT_THICKNESS_SPEC 10 +#define INSERT_COLOR_SPEC 11 +#define INSERT_OFF_TIME_SPEC 12 +#define INSERT_ON_TIME_SPEC 13 +#define INSERT_WIDTH_SPEC 14 +#define MAP_DISTANCE_SYMBOL_SPEC 15 +#define MAP_TEXT_FONT_SPEC 16 +#define OVERLAP_MANAGER_SPEC 17 +#define PICK_APERTURE_SPEC 18 +#define RELIEF_SPEC 19 +#define RENDER_SPEC 20 +#define RESHAPE_SPEC 21 +#define SCROLL_REGION_SPEC 22 +#define SELECT_COLOR_SPEC 23 +#define SPEED_VECTOR_LENGTH_SPEC 24 +#define TAKE_FOCUS_SPEC 25 +#define TILE_SPEC 26 +#define MANAGE_HISTORY_SPEC 27 +#define MANAGED_HISTORY_SIZE_SPEC 28 +#define WIDTH_SPEC 29 +#define X_SCROLL_CMD_SPEC 30 +#define X_SCROLL_INCREMENT_SPEC 31 +#define Y_SCROLL_CMD_SPEC 32 +#define Y_SCROLL_INCREMENT_SPEC 33 +#define BBOXES_SPEC 34 +#define BBOXES_COLOR_SPEC 35 +#define LIGHT_ANGLE_SPEC 36 static void CmdDeleted _ANSI_ARGS_((ClientData client_data)); @@ -289,30 +308,19 @@ static void Event _ANSI_ARGS_((ClientData client_data, XEvent *eventPtr)); static void Bind _ANSI_ARGS_((ClientData client_data, XEvent *eventPtr)); static int FetchSelection _ANSI_ARGS_((ClientData clientData, int offset, char *buffer, int maxBytes)); -static void SelectTo _ANSI_ARGS_((Item item, int field, int index)); +static void SelectTo _ANSI_ARGS_((ZnItem item, int field, int index)); static int WidgetObjCmd _ANSI_ARGS_((ClientData client_data, Tcl_Interp *, int argc, Tcl_Obj *CONST args[])); -static int Configure _ANSI_ARGS_((Tcl_Interp *interp, WidgetInfo *wi, +static int Configure _ANSI_ARGS_((Tcl_Interp *interp, ZnWInfo *wi, int argc, Tcl_Obj *CONST args[], int flags)); static void Redisplay _ANSI_ARGS_((ClientData client_data)); static void Destroy _ANSI_ARGS_((char *mem_ptr)); static void InitZinc _ANSI_ARGS_((Tcl_Interp *interp)); -static void Focus _ANSI_ARGS_((WidgetInfo *wi, ZnBool got_focus)); -static void Update _ANSI_ARGS_((WidgetInfo *wi)); -static void Repair _ANSI_ARGS_((WidgetInfo *wi)); +static void Focus _ANSI_ARGS_((ZnWInfo *wi, ZnBool got_focus)); +static void Update _ANSI_ARGS_((ZnWInfo *wi)); +static void Repair _ANSI_ARGS_((ZnWInfo *wi)); -Tcl_Obj * -NewStringObj(CONST char *str) { - return Tcl_NewStringObj(str, strlen(str)); -} - -void -SetStringObj(Tcl_Obj *o, - char *str) { - return Tcl_SetStringObj(o, str, strlen(str)); -} - /* *---------------------------------------------------------------------- @@ -324,25 +332,25 @@ SetStringObj(Tcl_Obj *o, *---------------------------------------------------------------------- */ static int -ZnReliefParse(ClientData client_data, - Tcl_Interp *interp, - Tk_Window tkwin, +ZnReliefParse(ClientData client_data __unused, + Tcl_Interp *interp __unused, + Tk_Window tkwin __unused, Tcl_Obj *ovalue, char *widget_rec, int offset) { - ReliefStyle *relief_ptr = (ReliefStyle *) (widget_rec + offset); - ReliefStyle relief; + ZnReliefStyle *relief_ptr = (ZnReliefStyle *) (widget_rec + offset); + ZnReliefStyle relief; #ifdef PTK char *value = Tcl_GetString(ovalue); #else char *value = (char *) ovalue; #endif - int result = ZN_OK; + int result = TCL_OK; if (value != NULL) { - result = ZnGetRelief((WidgetInfo *) widget_rec, value, &relief); - if (result == ZN_OK) { + result = ZnGetRelief((ZnWInfo *) widget_rec, value, &relief); + if (result == TCL_OK) { *relief_ptr = relief; } } @@ -350,15 +358,15 @@ ZnReliefParse(ClientData client_data, } static Tcl_Obj * -ZnReliefPrint(ClientData client_data, - Tk_Window tkwin, +ZnReliefPrint(ClientData client_data __unused, + Tk_Window tkwin __unused, char *widget_rec, int offset, - Tcl_FreeProc **free_proc) + Tcl_FreeProc **free_proc __unused) { - ReliefStyle relief = *(ReliefStyle *) (widget_rec + offset); + ZnReliefStyle relief = *(ZnReliefStyle *) (widget_rec + offset); #ifdef PTK - return NewStringObj(ZnNameOfRelief(relief)); + return Tcl_NewStringObj(ZnNameOfRelief(relief), -1); #else return (Tcl_Obj *) ZnNameOfRelief(relief); #endif @@ -375,7 +383,7 @@ ZnReliefPrint(ClientData client_data, *---------------------------------------------------------------------- */ static int -ZnGradientParse(ClientData client_data, +ZnGradientParse(ClientData client_data __unused, Tcl_Interp *interp, Tk_Window tkwin, Tcl_Obj *ovalue, @@ -394,26 +402,26 @@ ZnGradientParse(ClientData client_data, if ((value != NULL) && (*value != '\0')) { grad = ZnGetGradient(interp, tkwin, value); if (grad == NULL) { - return ZN_ERROR; + return TCL_ERROR; } if (prev_grad != NULL) { ZnFreeGradient(prev_grad); } *grad_ptr = grad; } - return ZN_OK; + return TCL_OK; } static Tcl_Obj * -ZnGradientPrint(ClientData client_data, - Tk_Window tkwin, +ZnGradientPrint(ClientData client_data __unused, + Tk_Window tkwin __unused, char *widget_rec, int offset, - Tcl_FreeProc **free_proc) + Tcl_FreeProc **free_proc __unused) { ZnGradient *gradient = *(ZnGradient **) (widget_rec + offset); #ifdef PTK - return NewStringObj(ZnNameOfGradient(gradient)); + return Tcl_NewStringObj(ZnNameOfGradient(gradient), -1); #else return (Tcl_Obj *) ZnNameOfGradient(gradient); #endif @@ -426,14 +434,14 @@ ZnGradientPrint(ClientData client_data, * ZnBitmapParse * ZnImageParse * ZnImagePrint -- - * Converter for the -*color* options. + * Converter for the -*image* options. * *---------------------------------------------------------------------- */ static int -ZnBitmapParse(ClientData client_data, - Tcl_Interp *interp, - Tk_Window tkwin, +ZnBitmapParse(ClientData client_data __unused, + Tcl_Interp *interp __unused, + Tk_Window tkwin __unused, Tcl_Obj *ovalue, char *widget_rec, int offset) @@ -445,13 +453,13 @@ ZnBitmapParse(ClientData client_data, #else char *value = (char *) ovalue; #endif - WidgetInfo *wi = (WidgetInfo*) widget_rec; + ZnWInfo *wi = (ZnWInfo*) widget_rec; prev_image = *image_ptr; if ((value != NULL) && (*value != '\0')) { image = ZnGetBitmap(wi, value); if (image == NULL) { - return ZN_ERROR; + return TCL_ERROR; } if (prev_image != NULL) { ZnFreeImage(prev_image); @@ -462,13 +470,13 @@ ZnBitmapParse(ClientData client_data, ZnFreeImage(prev_image); *image_ptr = NULL; } - return ZN_OK; + return TCL_OK; } static int -ZnImageParse(ClientData client_data, - Tcl_Interp *interp, - Tk_Window tkwin, +ZnImageParse(ClientData client_data __unused, + Tcl_Interp *interp __unused, + Tk_Window tkwin __unused, Tcl_Obj *ovalue, char *widget_rec, int offset) @@ -480,13 +488,13 @@ ZnImageParse(ClientData client_data, #else char *value = (char *) ovalue; #endif - WidgetInfo *wi = (WidgetInfo*) widget_rec; + ZnWInfo *wi = (ZnWInfo*) widget_rec; prev_image = *image_ptr; if ((value != NULL) && (*value != '\0')) { image = ZnGetImage(wi, value); if (image == NULL) { - return ZN_ERROR; + return TCL_ERROR; } if (prev_image != NULL) { ZnFreeImage(prev_image); @@ -497,19 +505,19 @@ ZnImageParse(ClientData client_data, ZnFreeImage(prev_image); *image_ptr = NULL; } - return ZN_OK; + return TCL_OK; } static Tcl_Obj * -ZnImagePrint(ClientData client_data, - Tk_Window tkwin, +ZnImagePrint(ClientData client_data __unused, + Tk_Window tkwin __unused, char *widget_rec, int offset, - Tcl_FreeProc **free_proc) + Tcl_FreeProc **free_proc __unused) { ZnImage image = *(ZnImage *) (widget_rec + offset); #ifdef PTK - return NewStringObj(image?ZnNameOfImage(image):""); + return Tcl_NewStringObj(image?ZnNameOfImage(image):"", -1); #else return (Tcl_Obj *) (image?ZnNameOfImage(image):""); #endif @@ -525,9 +533,9 @@ ZnImagePrint(ClientData client_data, * *---------------------------------------------------------------------- */ -Pixmap -ZnGetAlphaStipple(WidgetInfo *wi, - unsigned char val) +static Pixmap +ZnGetAlphaStipple(ZnWInfo *wi, + unsigned int val) { if (val >= 255) return None; @@ -543,7 +551,7 @@ ZnGetAlphaStipple(WidgetInfo *wi, *---------------------------------------------------------------------- */ Pixmap -ZnGetInactiveStipple(WidgetInfo *wi) +ZnGetInactiveStipple(ZnWInfo *wi) { return ZnGetAlphaStipple(wi, 128); } @@ -557,12 +565,12 @@ ZnGetInactiveStipple(WidgetInfo *wi) *---------------------------------------------------------------------- */ void -ZnNeedRedisplay(WidgetInfo *wi) +ZnNeedRedisplay(ZnWInfo *wi) { - if (!wi->update_pending) { + if (ISCLEAR(wi->flags, ZN_UPDATE_PENDING) && ISSET(wi->flags, ZN_REALIZED)) { /*printf("scheduling an update\n");*/ Tcl_DoWhenIdle(Redisplay, (ClientData) wi); - wi->update_pending = 1; + SET(wi->flags, ZN_UPDATE_PENDING); } } @@ -585,12 +593,15 @@ ZincObjCmd(ClientData client_data, /* Main window associated with Tcl_Obj *CONST args[]) /* Argument strings. */ { Tk_Window top_w = (Tk_Window) client_data; - WidgetInfo *wi; + ZnWInfo *wi; Tk_Window tkwin; unsigned int num; + ZnBool has_gl = False; +#ifndef _WIN32 +# if defined(GL) || defined(SHAPE) int major_op, first_err, first_evt; - ZnBool has_glx = False; -#ifdef GLX +# endif +# ifdef GL int major_glx, minor_glx; Display *dpy = Tk_Display(top_w); Screen *screen = Tk_Screen(top_w); @@ -603,59 +614,68 @@ ZincObjCmd(ClientData client_data, /* Main window associated with /*GLX_ALPHA_SIZE, 8,*/ None }; +# endif #endif InitZinc(interp); -#ifdef GLX +#ifdef GL +# ifdef _WIN32 + has_gl = True; +# else if (XQueryExtension(dpy, "GLX", &major_op, &first_evt, &first_err)) { if (glXQueryExtension(dpy, &first_err, &first_evt)) { if (glXQueryVersion(dpy, &major_glx, &minor_glx)) { if ((major_glx == 1) && (minor_glx >= 1)) { - has_glx = True; + has_gl = True; } } } } +# endif #endif + if (argc == 1) { - Tcl_AppendResult(interp, ZINCVERSION, NULL); + Tcl_AppendResult(interp, VERSION, NULL); Tcl_AppendResult(interp, " X11", NULL); -#ifdef GLX - if (has_glx && glXChooseVisual(dpy, - XScreenNumberOfScreen(screen), - attribs)) { +#ifdef GL +# ifdef _WIN32 + Tcl_AppendResult(interp, " GL", NULL); +# else + if (has_gl && glXChooseVisual(dpy, + XScreenNumberOfScreen(screen), + attribs)) { Tcl_AppendResult(interp, " GL", NULL); } +# endif #endif return TCL_OK; } tkwin = Tk_CreateWindowFromPath(interp, top_w, Tcl_GetString(args[1]), NULL); if (tkwin == NULL) { - return ZN_ERROR; + return TCL_ERROR; } Tk_SetClass(tkwin, "Zinc"); /* * Allocate and initialize the widget record. */ - wi = (WidgetInfo *) ZnMalloc(sizeof(WidgetInfo)); + wi = (ZnWInfo *) ZnMalloc(sizeof(ZnWInfo)); wi->win = tkwin; wi->interp = interp; wi->dpy = Tk_Display(tkwin); wi->screen = Tk_Screen(tkwin); - wi->has_glx = has_glx;; + ASSIGN(wi->flags, ZN_HAS_GL, has_gl); -#ifdef SHAPE - wi->has_x_shape = XQueryExtension(wi->dpy, "SHAPE", - &major_op, &first_evt, &first_err); +#if defined(SHAPE) && !defined(_WIN32) + ASSIGN(wi->flags, ZN_HAS_X_SHAPE, + XQueryExtension(wi->dpy, "SHAPE", &major_op, &first_evt, &first_err)); + wi->reshape = wi->full_reshape = True; #else - wi->has_x_shape = False; + CLEAR(wi->flags, ZN_HAS_X_SHAPE); + wi->reshape = wi->full_reshape = False; #endif - wi->has_x_input = XQueryExtension(wi->dpy, "XInputExtension", - &major_op, &first_evt, &first_err); - wi->reshape = wi->full_reshape = True; wi->render = 0; wi->real_top = None; @@ -667,9 +687,8 @@ ZincObjCmd(ClientData client_data, /* Main window associated with wi->cmd = Tcl_CreateObjCommand(interp, Tk_PathName(tkwin), WidgetObjCmd, (ClientData) wi, CmdDeleted); #endif + wi->flags = 0; wi->binding_table = 0; - wi->realized = False; - wi->update_pending = 0; wi->fore_color = NULL; wi->back_color = NULL; wi->relief_grad = NULL; @@ -677,14 +696,18 @@ ZincObjCmd(ClientData client_data, /* Main window associated with wi->draw_bboxes = 0; wi->light_angle = 120; wi->border_width = 0; - wi->relief = TK_RELIEF_FLAT; + wi->relief = ZN_RELIEF_FLAT; wi->opt_width = None; wi->opt_height = None; wi->font = 0; wi->map_text_font = 0; -#ifdef GLX +#ifdef GL wi->font_tfi = NULL; wi->map_font_tfi = NULL; + wi->gl_context = NULL; +# ifndef _WIN32 + wi->gl_visual = NULL; +# endif #endif wi->map_distance_symbol = None; wi->cursor = None; @@ -694,6 +717,13 @@ ZincObjCmd(ClientData client_data, /* Main window associated with wi->track_managed_history_size = 0; wi->speed_vector_length = 0; wi->tile = ZnUnspecifiedImage; + wi->confine = 0; + wi->origin.x = wi->origin.y = 0; + wi->scroll_xo = wi->scroll_yo = 0; + wi->scroll_xc = wi->scroll_yc = 0; + wi->x_scroll_incr = wi->y_scroll_incr = 0; + wi->x_scroll_cmd = wi->y_scroll_cmd = NULL; + wi->region = NULL; wi->id_table = (Tcl_HashTable *) ZnMalloc(sizeof(Tcl_HashTable)); Tcl_InitHashTable(wi->id_table, TCL_ONE_WORD_KEYS); @@ -708,26 +738,26 @@ ZincObjCmd(ClientData client_data, /* Main window associated with #ifdef OM wi->om_group_id = 0; wi->om_group = wi->top_group; - OmRegister((void *) wi, SendTrackToOm, SetLabelAngleFromOm, QueryLabelPosition); + OmRegister((void *) wi, ZnSendTrackToOm, ZnSetLabelAngleFromOm, ZnQueryLabelPosition); #endif wi->gc = 0; wi->draw_buffer = 0; - wi->events_flags = 0; wi->pick_aperture = 0; wi->new_item = wi->current_item = ZN_NO_ITEM; wi->new_part = wi->current_part = ZN_NO_PART; wi->focus_item = ZN_NO_ITEM; wi->focus_field = ZN_NO_PART; - wi->got_focus = False; - wi->monitoring = False; - wi->total_draw_chrono = NewChrono("Total draw time"); - wi->this_draw_chrono = NewChrono("Last draw time"); + CLEAR(wi->flags, ZN_MONITORING); +#ifndef _WIN32 + wi->total_draw_chrono = ZnNewChrono("Total draw time"); + wi->this_draw_chrono = ZnNewChrono("Last draw time"); +#endif wi->damaged_area_w = wi->damaged_area_h = 0; wi->work_item_list = NULL; wi->work_pts = ZnListNew(8, sizeof(ZnPoint)); -#ifdef GLX +#ifdef GL wi->work_doubles = ZnListNew(8, sizeof(double)); #endif wi->work_xpts = ZnListNew(8, sizeof(XPoint)); @@ -758,8 +788,8 @@ ZincObjCmd(ClientData client_data, /* Main window associated with ZnInitClipStack(wi); ZnInitTransformStack(wi); - for (num = 0; num < NUM_ALPHA_STEPS; num++) { - char name[INTEGER_SPACE+12]; + for (num = 0; num < ZN_NUM_ALPHA_STEPS; num++) { + char name[TCL_INTEGER_SPACE+12]; sprintf(name, "AlphaStipple%d", num); wi->alpha_stipples[num] = Tk_GetBitmap(interp, tkwin, Tk_GetUid(name)); @@ -777,10 +807,10 @@ ZincObjCmd(ClientData client_data, /* Main window associated with if (Configure(interp, wi, argc-2, args+2, 0) != TCL_OK) { Tk_DestroyWindow(tkwin); - return ZN_ERROR; + return TCL_ERROR; } - ResetBBox(&wi->exposed_area); + ZnResetBBox(&wi->exposed_area); wi->damaged_area.orig.x = wi->damaged_area.orig.y = 0; wi->damaged_area.corner.x = wi->width = wi->opt_width; wi->damaged_area.corner.y = wi->height = wi->opt_height; @@ -795,19 +825,63 @@ ZincObjCmd(ClientData client_data, /* Main window associated with * Allocate double buffer pixmap/image. */ if (wi->render) { -#ifdef GLX +#ifdef GL wi->gl_context = 0; - - if (wi->has_glx) { -#ifdef GLX_PRINT_CONFIG + ASSIGN(wi->flags, ZN_PRINT_CONFIG, (getenv("ZINC_GLX_INFO") != NULL)); + + if (ISSET(wi->flags, ZN_HAS_GL)) { +# ifdef _WIN32 + PIXELFORMATDESCRIPTOR pfd = { + sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd + 1, // version number + PFD_DRAW_TO_WINDOW | + PFD_SUPPORT_OPENGL | // support OpenGL + PFD_DOUBLEBUFFER, // double buffered + PFD_TYPE_RGBA, // RGBA type + 0, // Color bits ignored + 8, 0, 8, 0, 8, 0, 8, 0, // R, G, B, A (color shifts ignored ) + 0, // accum bits ignored + 0, 0, 0, 0, // accum R, G, B, A ignored + 0, // no depth buffer + 8, // 8 bits stencil buffer + 0, // no auxiliary buffer + PFD_MAIN_PLANE, // main layer + 0, // reserved + 0, 0, 0 // layer masks ignored + }; + int ipixel; + + Tk_MakeWindowExist(wi->win); + wi->hwnd = Tk_GetHWND(Tk_WindowId(wi->win)); + wi->hdc = GetDC(wi->hwnd); + if (!wi->hdc) { + OutputDebugString("Unable to get the hdc\n"); + } + ipixel = ChoosePixelFormat(wi->hdc, &pfd); + /* sprintf(msg, "ipixel=%d dwFlags=0x%x req=0x%x iPixelType=%d\n", + ipixel, + pfd.dwFlags, + PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER, + pfd.iPixelType==PFD_TYPE_RGBA); + OutputDebugString(msg);*/ + if (!ipixel) { + OutputDebugString("ChoosePixelFormat failed\n"); + } + wi->render = (SetPixelFormat(wi->hdc, ipixel, &pfd) == TRUE); + if (wi->render) { + wi->gl_context = wglCreateContext(wi->hdc); + if (!wi->gl_context) { + OutputDebugString("wglCreateContext failed\n"); + } + } + ZnGLRelease(wi); +# else /* _WIN32 */ int val; -#endif - -#if GLX_PRINT_CONFIG - if (getenv("ZINC_GLX_INFO")) { + + if (ISSET(wi->flags, ZN_PRINT_CONFIG)) { fprintf(stderr, "GLX version %d.%d\n", major_glx, minor_glx); } -#endif + wi->gl_visual = glXChooseVisual(wi->dpy, XScreenNumberOfScreen(wi->screen), attribs); @@ -823,8 +897,7 @@ ZincObjCmd(ClientData client_data, /* Main window associated with wi->render = 0; } else { -#ifdef GLX_PRINT_CONFIG - if (getenv("ZINC_GLX_INFO")) { + if (ISSET(wi->flags, ZN_PRINT_CONFIG)) { fprintf(stderr, " Visual : 0x%x, ", (int) wi->gl_visual->visualid); glXGetConfig(wi->dpy, wi->gl_visual, GLX_RGBA, &val); @@ -846,29 +919,31 @@ ZincObjCmd(ClientData client_data, /* Main window associated with fprintf(stderr, " Direct Rendering: %d\n", glXIsDirect(wi->dpy, wi->gl_context)); } -#endif Tk_SetWindowVisual(wi->win, wi->gl_visual->visual, 24, XCreateColormap(wi->dpy, RootWindowOfScreen(wi->screen), wi->gl_visual->visual, AllocNone)); } } +# endif /* _WIN32 */ } else { - fprintf(stderr, "glx not available\n"); + fprintf(stderr, "GL not available\n"); wi->render = 0; } -#endif +#else /* GL */ + wi->render = 0; +#endif /* GL */ } if (!wi->render) { - wi->draw_buffer = XCreatePixmap(wi->dpy, RootWindowOfScreen(wi->screen), - wi->width, wi->height, Tk_Depth(wi->win)); + wi->draw_buffer = Tk_GetPixmap(wi->dpy, RootWindowOfScreen(wi->screen), + wi->width, wi->height, Tk_Depth(wi->win)); } #ifdef PTK Tcl_SetObjResult(interp, LangWidgetObj(interp, tkwin)); #else - Tcl_SetObjResult(interp, NewStringObj(Tk_PathName(tkwin))); + Tcl_SetObjResult(interp, Tcl_NewStringObj(Tk_PathName(tkwin), -1)); #endif return TCL_OK; @@ -886,16 +961,16 @@ ZincObjCmd(ClientData client_data, /* Main window associated with *---------------------------------------------------------------------- */ ClientData -EncodeItemPart(Item item, +EncodeItemPart(ZnItem item, int part) { if (part >= 0) { - FieldSet fs; + ZnFieldSet fs; if (!item->class->GetFieldSet) { return item; } fs = item->class->GetFieldSet(item); - return (ClientData) (FIELD.GetFieldStruct(fs, part%FIELD.NumFields(fs))); + return (ClientData) (ZnFIELD.GetFieldStruct(fs, part % (int) ZnFIELD.NumFields(fs))); } else if (part == ZN_NO_PART) { return item; @@ -984,7 +1059,7 @@ TagSearchExprDestroy(TagSearchExpr *expr) */ static int TagSearchScanExpr(Tcl_Interp *interp, /* Current interpreter. */ - TagSearch *search, /* Search data */ + ZnTagSearch *search, /* Search data */ TagSearchExpr *expr) /* Compiled expression result */ { int looking_for_tag; /* When true, scanner expects next char(s) @@ -1023,7 +1098,7 @@ TagSearchScanExpr(Tcl_Interp *interp, /* Current interpreter. */ if (looking_for_tag > 1) { Tcl_AppendResult(interp, "Too many '!' in tag search expression", (char *) NULL); - return ZN_ERROR; + return TCL_ERROR; } looking_for_tag++; negate_result = 1; @@ -1039,7 +1114,7 @@ TagSearchScanExpr(Tcl_Interp *interp, /* Current interpreter. */ if (TagSearchScanExpr(interp, search, expr) != TCL_OK) { /* Result string should be already set * by nested call to tag_expr_scan() */ - return ZN_ERROR; + return TCL_ERROR; } looking_for_tag = 0; found_tag = 1; @@ -1068,13 +1143,13 @@ TagSearchScanExpr(Tcl_Interp *interp, /* Current interpreter. */ if (! found_endquote) { Tcl_AppendResult(interp, "Missing endquote in tag search expression", (char *) NULL); - return ZN_ERROR; + return TCL_ERROR; } if (! (tag - search->rewrite_buf)) { Tcl_AppendResult(interp, "Null quoted tag string in tag search expression", (char *) NULL); - return ZN_ERROR; + return TCL_ERROR; } *tag++ = '\0'; expr->uids[expr->index++] = Tk_GetUid(search->rewrite_buf); @@ -1087,7 +1162,7 @@ TagSearchScanExpr(Tcl_Interp *interp, /* Current interpreter. */ case ')': Tcl_AppendResult(interp, "Unexpected operator in tag search expression", (char *) NULL); - return ZN_ERROR; + return TCL_ERROR; default: /* unquoted tag string */ if (negate_result) { expr->uids[expr->index++] = neg_tag_val_uid; @@ -1136,7 +1211,7 @@ TagSearchScanExpr(Tcl_Interp *interp, /* Current interpreter. */ if (c != '&') { Tcl_AppendResult(interp, "Singleton '&' in tag search expression", (char *) NULL); - return ZN_ERROR; + return TCL_ERROR; } expr->uids[expr->index++] = and_uid; looking_for_tag = 1; @@ -1146,7 +1221,7 @@ TagSearchScanExpr(Tcl_Interp *interp, /* Current interpreter. */ if (c != '|') { Tcl_AppendResult(interp, "Singleton '|' in tag search expression", (char *) NULL); - return ZN_ERROR; + return TCL_ERROR; } expr->uids[expr->index++] = or_uid; looking_for_tag = 1; @@ -1162,17 +1237,17 @@ TagSearchScanExpr(Tcl_Interp *interp, /* Current interpreter. */ Tcl_AppendResult(interp, "Invalid boolean operator in tag search expression", (char *) NULL); - return ZN_ERROR; + return TCL_ERROR; } } } breakwhile: if (found_tag && ! looking_for_tag) { - return ZN_OK; + return TCL_OK; } Tcl_AppendResult(interp, "Missing tag in tag search expression", (char *) NULL); - return ZN_ERROR; + return TCL_ERROR; } @@ -1193,7 +1268,7 @@ TagSearchScanExpr(Tcl_Interp *interp, /* Current interpreter. */ */ static int TagSearchEvalExpr(TagSearchExpr *expr, /* Search expression */ - Item item) /* Item being test for match */ + ZnItem item) /* Item being test for match */ { int looking_for_tag; /* When true, scanner expects next char(s) * to be a tag, else operand expected */ @@ -1215,7 +1290,7 @@ TagSearchEvalExpr(TagSearchExpr *expr, /* Search expression */ /* * set result 1 if tag is found in item's tags */ - result = ITEM.HasTag(item, uid) ? 1 : 0; + result = ZnITEM.HasTag(item, uid) ? 1 : 0; } else if (uid == neg_tag_val_uid) { negate_result = ! negate_result; @@ -1226,7 +1301,7 @@ TagSearchEvalExpr(TagSearchExpr *expr, /* Search expression */ /* * set result 1 if tag is found in item's tags */ - result = ITEM.HasTag(item, uid) ? 1 : 0; + result = ZnITEM.HasTag(item, uid) ? 1 : 0; } else if (uid == paren_uid) { /* @@ -1303,15 +1378,15 @@ TagSearchEvalExpr(TagSearchExpr *expr, /* Search expression */ } -static Item -LookupGroupFromPath(Item start, - Tk_Uid *names, - int num_names) +static ZnItem +LookupGroupFromPath(ZnItem start, + Tk_Uid *names, + unsigned int num_names) { Tk_Uid name, *tags; - int count; + unsigned int count; ZnBool recursive; - Item result, current = ZnGroupHead(start); + ZnItem result, current = ZnGroupHead(start); if (num_names == 0) { return start; @@ -1377,16 +1452,16 @@ LookupGroupFromPath(Item start, *-------------------------------------------------------------- */ static int -ZnTagSearchScan(WidgetInfo *wi, - Tcl_Obj *tag_obj, /* Object giving tag value, NULL - * is the same as 'all'. */ - TagSearch **search_var) /* Record describing tag search; - * will be initialized here. */ +ZnTagSearchScan(ZnWInfo *wi, + Tcl_Obj *tag_obj, /* Object giving tag value, NULL + * is the same as 'all'. */ + ZnTagSearch **search_var) /* Record describing tag search; + * will be initialized here. */ { Tk_Uid tag; int i; - TagSearch *search; - Item group = wi->top_group; + ZnTagSearch *search; + ZnItem group = wi->top_group; ZnBool recursive = True; if (tag_obj) { @@ -1404,13 +1479,13 @@ ZnTagSearchScan(WidgetInfo *wi, } else { /* Allocate primary search struct on first call */ - *search_var = search = (TagSearch *) ZnMalloc(sizeof(TagSearch)); + *search_var = search = (ZnTagSearch *) ZnMalloc(sizeof(ZnTagSearch)); search->expr = NULL; /* Allocate buffer for rewritten tags (after de-escaping) */ search->rewrite_buf_alloc = 100; search->rewrite_buf = ZnMalloc(search->rewrite_buf_alloc); - search->item_stack = ZnListNew(16, sizeof(Item)); + search->item_stack = ZnListNew(16, sizeof(ZnItem)); } TagSearchExprInit(&(search->expr)); @@ -1427,7 +1502,7 @@ ZnTagSearchScan(WidgetInfo *wi, */ if (search->tag_len == 0) { search->over = True; - return ZN_OK; + return TCL_OK; } /* @@ -1435,9 +1510,9 @@ ZnTagSearchScan(WidgetInfo *wi, * tag and search for a matching group. */ if (strpbrk(tag, ".*")) { - Tk_Uid path; - char c, *next; - unsigned long id; + Tk_Uid path; + char c, *next; + long id; Tcl_HashEntry *entry; ZnListEmpty(wi->work_strs); @@ -1458,33 +1533,35 @@ ZnTagSearchScan(WidgetInfo *wi, if ((group == ZN_NO_ITEM) || (group->id != id)) { entry = Tcl_FindHashEntry(wi->id_table, (char *) id); if (entry != NULL) { - group = (Item) Tcl_GetHashValue(entry); + group = (ZnItem) Tcl_GetHashValue(entry); } else { Tcl_AppendResult(wi->interp, "unknown group in path \"", tag, "\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } } if (group->class != ZnGroup) { Tcl_AppendResult(wi->interp, "item is not a group in path \"", tag, "\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } } else { Tcl_AppendResult(wi->interp, "misplaced group id in path \"", tag, "\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } } else { - ZnListAdd(wi->work_strs, recursive ? &star_uid : &dot_uid, ZnListTail); + ZnListAdd(wi->work_strs, + (void *) (recursive ? &star_uid : &dot_uid), + ZnListTail); c = *next; *next = '\0'; path = Tk_GetUid(path); *next = c; - ZnListAdd(wi->work_strs, &path, ZnListTail); + ZnListAdd(wi->work_strs, (void *) &path, ZnListTail); } recursive = (*next == '*'); path = next+1; @@ -1496,7 +1573,7 @@ ZnTagSearchScan(WidgetInfo *wi, if (group == ZN_NO_ITEM) { Tcl_AppendResult(wi->interp, "path does not lead to a valid group\"", tag, "\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } /* @@ -1517,8 +1594,8 @@ ZnTagSearchScan(WidgetInfo *wi, /* * Make sure there is enough buffer to hold rewritten tags (30%). */ - if ((unsigned int)search->tag_len*1.3 >= search->rewrite_buf_alloc) { - search->rewrite_buf_alloc = (unsigned int)search->tag_len*1.3; + if ((unsigned int)(search->tag_len*1.3) >= search->rewrite_buf_alloc) { + search->rewrite_buf_alloc = (unsigned int) (search->tag_len*1.3); search->rewrite_buf = ZnRealloc(search->rewrite_buf, search->rewrite_buf_alloc); } @@ -1542,7 +1619,7 @@ ZnTagSearchScan(WidgetInfo *wi, search->id = strtoul(tag, &end, 0); if (*end == 0) { search->type = 1; - return ZN_OK; + return TCL_OK; } } @@ -1581,10 +1658,10 @@ ZnTagSearchScan(WidgetInfo *wi, * now compile the tag expression into array of Tk_Uid * flagging any syntax errors found */ - if (TagSearchScanExpr(wi->interp, search, search->expr) != ZN_OK) { + if (TagSearchScanExpr(wi->interp, search, search->expr) != TCL_OK) { /* Syntax error in tag expression */ /* Result message set by TagSearchScanExpr */ - return ZN_ERROR; + return TCL_ERROR; } search->expr->length = search->expr->index; } @@ -1607,7 +1684,7 @@ ZnTagSearchScan(WidgetInfo *wi, search->type = 3; } } - return ZN_OK; + return TCL_OK; } @@ -1633,10 +1710,10 @@ ZnTagSearchScan(WidgetInfo *wi, * *-------------------------------------------------------------- */ -static Item -ZnTagSearchFirst(TagSearch *search) /* Record describing tag search */ +static ZnItem +ZnTagSearchFirst(ZnTagSearch *search) /* Record describing tag search */ { - Item item, previous; + ZnItem item, previous; /* short circuit impossible searches for null tags */ if (search->over == True) { @@ -1658,7 +1735,7 @@ ZnTagSearchFirst(TagSearch *search) /* Record describing tag search */ (previous == ZN_NO_ITEM) || (previous->next != item)) { entry = Tcl_FindHashEntry(search->wi->id_table, (char *) search->id); if (entry != NULL) { - item = (Item) Tcl_GetHashValue(entry); + item = (ZnItem) Tcl_GetHashValue(entry); previous = item->previous; } else { @@ -1689,7 +1766,7 @@ ZnTagSearchFirst(TagSearch *search) /* Record describing tag search */ /* * Optimized single-tag search */ - if (ITEM.HasTag(item, search->expr->uid)) { + if (ZnITEM.HasTag(item, search->expr->uid)) { search->previous = previous; search->current = item; return item; @@ -1708,7 +1785,7 @@ ZnTagSearchFirst(TagSearch *search) /* Record describing tag search */ } } if ((item->class == ZnGroup) && (search->recursive)) { - Item prev_group = (Item) search->group; + ZnItem prev_group = (ZnItem) search->group; /* * Explore the hierarchy depth first using the item stack * to save the current node. @@ -1739,9 +1816,9 @@ ZnTagSearchFirst(TagSearch *search) /* Record describing tag search */ /*printf("ZnTagSearchFirst backup for tag, detph %d\n", ZnListSize(search->item_stack)/2);*/ while ((item == ZN_NO_ITEM) && ZnListSize(search->item_stack)) { - item = *(Item *) ZnListAt(search->item_stack, ZnListTail); + item = *(ZnItem *) ZnListAt(search->item_stack, ZnListTail); ZnListDelete(search->item_stack, ZnListTail); - previous = *(Item *) ZnListAt(search->item_stack, ZnListTail); + previous = *(ZnItem *) ZnListAt(search->item_stack, ZnListTail); ZnListDelete(search->item_stack, ZnListTail); } if (item != ZN_NO_ITEM) { @@ -1776,10 +1853,10 @@ ZnTagSearchFirst(TagSearch *search) /* Record describing tag search */ * *-------------------------------------------------------------- */ -static Item -ZnTagSearchNext(TagSearch *search) /* Record describing search in progress. */ +static ZnItem +ZnTagSearchNext(ZnTagSearch *search) /* Record describing search in progress. */ { - Item item, previous; + ZnItem item, previous; if (search->over) { return ZN_NO_ITEM; @@ -1829,9 +1906,9 @@ ZnTagSearchNext(TagSearch *search) /* Record describing search in progress. */ /* * End of list at this level, back up one level. */ - item = *(Item *) ZnListAt(search->item_stack, ZnListTail); + item = *(ZnItem *) ZnListAt(search->item_stack, ZnListTail); ZnListDelete(search->item_stack, ZnListTail); - previous = *(Item *) ZnListAt(search->item_stack, ZnListTail); + previous = *(ZnItem *) ZnListAt(search->item_stack, ZnListTail); ZnListDelete(search->item_stack, ZnListTail); } if (item != ZN_NO_ITEM) { @@ -1864,7 +1941,7 @@ ZnTagSearchNext(TagSearch *search) /* Record describing search in progress. */ /* * Optimized single-tag search */ - if (ITEM.HasTag(item, search->expr->uid)) { + if (ZnITEM.HasTag(item, search->expr->uid)) { search->previous = previous; search->current = item; return item; @@ -1904,9 +1981,9 @@ ZnTagSearchNext(TagSearch *search) /* Record describing search in progress. */ /*printf("ZnTagSearchNext backup for tag, depth %d\n", ZnListSize(search->item_stack)/2);*/ while ((item == ZN_NO_ITEM) && ZnListSize(search->item_stack)) { - item = *(Item *) ZnListAt(search->item_stack, ZnListTail); + item = *(ZnItem *) ZnListAt(search->item_stack, ZnListTail); ZnListDelete(search->item_stack, ZnListTail); - previous = *(Item *) ZnListAt(search->item_stack, ZnListTail); + previous = *(ZnItem *) ZnListAt(search->item_stack, ZnListTail); ZnListDelete(search->item_stack, ZnListTail); } if (item != ZN_NO_ITEM) { @@ -1935,7 +2012,7 @@ ZnTagSearchNext(TagSearch *search) /* Record describing search in progress. */ *-------------------------------------------------------------- */ void -ZnTagSearchDestroy(TagSearch *search) /* Record describing tag search */ +ZnTagSearchDestroy(ZnTagSearch *search) /* Record describing tag search */ { if (search) { TagSearchExprDestroy(search->expr); @@ -1958,16 +2035,16 @@ ZnTagSearchDestroy(TagSearch *search) /* Record describing tag search */ *---------------------------------------------------------------------- */ int -ZnItemWithTagOrId(WidgetInfo *wi, +ZnItemWithTagOrId(ZnWInfo *wi, Tcl_Obj *tag_or_id, - Item *item, - TagSearch **search_var) + ZnItem *item, + ZnTagSearch **search_var) { - if (ZnTagSearchScan(wi, tag_or_id, search_var) != ZN_OK) { - return ZN_ERROR; + if (ZnTagSearchScan(wi, tag_or_id, search_var) != TCL_OK) { + return TCL_ERROR; } *item = ZnTagSearchFirst(*search_var); - return ZN_OK; + return TCL_OK; } @@ -1984,13 +2061,17 @@ ZnItemWithTagOrId(WidgetInfo *wi, *---------------------------------------------------------------------- */ static int -LayoutItems(WidgetInfo *wi, - int argc, +LayoutItems(ZnWInfo *wi, + int argc __unused, Tcl_Obj *CONST args[]) { - int index, result; - Item item; + int index/*, result*/; + /*ZnItem item;*/ +#ifdef PTK + static char *layout_cmd_strings[] = { +#else static CONST char *layout_cmd_strings[] = { +#endif "align", "grid", "position", "scale", "space", NULL }; enum layout_cmds { @@ -1998,8 +2079,8 @@ LayoutItems(WidgetInfo *wi, }; if (Tcl_GetIndexFromObj(wi->interp, args[0], layout_cmd_strings, - "layout command", 0, &index) != ZN_OK) { - return ZN_ERROR; + "layout command", 0, &index) != TCL_OK) { + return TCL_ERROR; } switch((enum layout_cmds) index) { /* @@ -2029,7 +2110,243 @@ LayoutItems(WidgetInfo *wi, break; } - return ZN_OK; + return TCL_OK; +} + + +/* + *---------------------------------------------------------------------- + * + * SetOrigin -- + * + * This procedure is invoked to translate the viewed area so + * that the given point is displayed in the top left corner. + * + * Results: + * None. + * + * Side effects: + * Zinc will be redisplayed to reflect the change in ciew. + * The scrollbars will be updated if there are any. + * The top group transform is modified to achieve the effect, + * it is not a good idea to mix view control and application + * control of the top group transform. + * + *---------------------------------------------------------------------- + */ +static void +SetOrigin(ZnWInfo *wi, + ZnReal x_origin, + ZnReal y_origin) +{ + int left, right, top, bottom, delta; + + /* + * If scroll increments have been set, round the window origin + * to the nearest multiple of the increments. + */ + if (wi->x_scroll_incr > 0) { + if (x_origin >= 0) { + x_origin += wi->x_scroll_incr/2; + } + else { + x_origin = (-x_origin) + wi->x_scroll_incr/2; + } + } + if (wi->y_scroll_incr > 0) { + if (y_origin >= 0) { + y_origin += wi->y_scroll_incr/2; + } + else { + y_origin = (-y_origin) + wi->y_scroll_incr/2; + } + } + + /* + * Adjust the origin if necessary to keep as much as possible of the + * canvas in the view. The variables left, right, etc. keep track of + * how much extra space there is on each side of the view before it + * will stick out past the scroll region. If one side sticks out past + * the edge of the scroll region, adjust the view to bring that side + * back to the edge of the scrollregion (but don't move it so much that + * the other side sticks out now). If scroll increments are in effect, + * be sure to adjust only by full increments. + */ + if (wi->confine && (wi->region != NULL)) { + left = x_origin - wi->scroll_xo; + right = wi->scroll_xc - (x_origin + Tk_Width(wi->win)); + top = y_origin - wi->scroll_yo; + bottom = wi->scroll_yc - (y_origin + Tk_Height(wi->win)); + if ((left < 0) && (right > 0)) { + delta = (right > -left) ? -left : right; + if (wi->x_scroll_incr > 0) { + delta -= delta % wi->x_scroll_incr; + } + x_origin += delta; + } + else if ((right < 0) && (left > 0)) { + delta = (left > -right) ? -right : left; + if (wi->x_scroll_incr > 0) { + delta -= delta % wi->x_scroll_incr; + } + x_origin -= delta; + } + if ((top < 0) && (bottom > 0)) { + delta = (bottom > -top) ? -top : bottom; + if (wi->y_scroll_incr > 0) { + delta -= delta % wi->y_scroll_incr; + } + y_origin += delta; + } + else if ((bottom < 0) && (top > 0)) { + delta = (top > -bottom) ? -bottom : top; + if (wi->y_scroll_incr > 0) { + delta -= delta % wi->y_scroll_incr; + } + y_origin -= delta; + } + } + + /* + * If the requested origin is not already set, translate the + * top group and update the scrollbars. + */ + if ((wi->origin.x != x_origin) || (wi->origin.y != y_origin)) { + wi->origin.x = x_origin; + wi->origin.y = y_origin; + ZnITEM.ResetTransfo(wi->top_group); + ZnITEM.TranslateItem(wi->top_group, -x_origin, -y_origin); + SET(wi->flags, ZN_UPDATE_SCROLLBARS); + } +} + + +/* + *---------------------------------------------------------------------- + * + * ScrollFractions -- + * + * Given the range that's visible in the window and the "100% + * range", return a list of two real representing the scroll + * fractions. This procedure is used for both x and y scrolling. + * + * Results: + * Return a string as a Tcl_Obj holding two real numbers + * describing the scroll fraction (between 0 and 1) corresponding + * to the arguments. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ +static Tcl_Obj * +ScrollFractions(ZnReal view1, /* Lowest coordinate visible in the window. */ + ZnReal view2, /* Highest coordinate visible in the window. */ + ZnReal region1,/* Lowest coordinate in the object. */ + ZnReal region2)/* Highest coordinate in the object. */ +{ + ZnReal range, f1, f2; + char buffer[2*TCL_DOUBLE_SPACE+2]; + + range = region2 - region1; + if (range <= 0) { + f1 = 0; + f2 = 1.0; + } + else { + f1 = (view1 - region1)/range; + if (f1 < 0) { + f1 = 0.0; + } + f2 = (view2 - region1)/range; + if (f2 > 1.0) { + f2 = 1.0; + } + if (f2 < f1) { + f2 = f1; + } + } + sprintf(buffer, "%g %g", f1, f2); + return Tcl_NewStringObj(buffer, -1); +} + + +/* + *-------------------------------------------------------------- + * + * UpdateScrollbars -- + * + * This procedure is invoked whenever zinc has changed in + * a way that requires scrollbars to be redisplayed (e.g. + * the view has changed). + * + * Results: + * None. + * + * Side effects: + * If there are scrollbars associated with zinc, then + * their scrolling commands are invoked to cause them to + * redisplay. If errors occur, additional Tcl commands may + * be invoked to process the errors. + * + *-------------------------------------------------------------- + */ +static void +UpdateScrollbars(ZnWInfo *wi) +{ + int result; + Tcl_Interp *interp; + int x_origin, y_origin, width, height; + int scroll_xo, scroll_xc, scroll_yo, scroll_yc; + char *x_scroll_cmd, *y_scroll_cmd; + Tcl_Obj *fractions; + + /* + * Save all the relevant values from wi, because it might be + * deleted as part of either of the two calls to Tcl_VarEval below. + */ + interp = wi->interp; + Tcl_Preserve((ClientData) interp); + x_scroll_cmd = wi->x_scroll_cmd; + if (x_scroll_cmd != NULL) { + Tcl_Preserve((ClientData) x_scroll_cmd); + } + y_scroll_cmd = wi->y_scroll_cmd; + if (y_scroll_cmd != NULL) { + Tcl_Preserve((ClientData) y_scroll_cmd); + } + x_origin = wi->origin.x; + y_origin = wi->origin.y; + width = Tk_Width(wi->win); + height = Tk_Height(wi->win); + scroll_xo = wi->scroll_xo; + scroll_xc = wi->scroll_xc; + scroll_yo = wi->scroll_yo; + scroll_yc = wi->scroll_yc; + CLEAR(wi->flags, ZN_UPDATE_SCROLLBARS); + if (wi->x_scroll_cmd != NULL) { + fractions = ScrollFractions(x_origin, x_origin + width, scroll_xo, scroll_xc); + result = Tcl_VarEval(interp, x_scroll_cmd, " ", Tcl_GetString(fractions), NULL); + Tcl_DecrRefCount(fractions); + if (result != TCL_OK) { + Tcl_BackgroundError(interp); + } + Tcl_ResetResult(interp); + Tcl_Release((ClientData) x_scroll_cmd); + } + + if (y_scroll_cmd != NULL) { + fractions = ScrollFractions(y_origin, y_origin + height, scroll_yo, scroll_yc); + result = Tcl_VarEval(interp, y_scroll_cmd, " ", Tcl_GetString(fractions), NULL); + Tcl_DecrRefCount(fractions); + if (result != TCL_OK) { + Tcl_BackgroundError(interp); + } + Tcl_ResetResult(interp); + Tcl_Release((ClientData) y_scroll_cmd); + } + Tcl_Release((ClientData) interp); } @@ -2047,21 +2364,21 @@ LayoutItems(WidgetInfo *wi, */ void ZnDoItem(Tcl_Interp *interp, - Item item, + ZnItem item, int part, Tk_Uid tag_uid) { if (tag_uid == NULL) { Tcl_Obj *l; l = Tcl_GetObjResult(interp); - Tcl_ListObjAppendElement(interp, l, NewLongObj(item->id)); + Tcl_ListObjAppendElement(interp, l, Tcl_NewLongObj(item->id)); if (part != ZN_NO_PART) { Tcl_ListObjAppendElement(interp, l, Tcl_NewIntObj(part)); } } else { /*printf("Adding tag %s to item %d\n", tag_uid, item->id);*/ - ITEM.AddTag(item, tag_uid); + ZnITEM.AddTag(item, tag_uid); } } @@ -2078,33 +2395,33 @@ ZnDoItem(Tcl_Interp *interp, * items enclosed in the area. If enclosed is 0, it looks * for overlapping and enclosed items. * If an error occurs, a message is left in the interp result - * and ZN_ERROR is returned. + * and TCL_ERROR is returned. * *---------------------------------------------------------------------- */ static int -FindArea(WidgetInfo *wi, +FindArea(ZnWInfo *wi, Tcl_Obj *CONST args[], Tk_Uid tag_uid, ZnBool enclosed, ZnBool recursive, - Item group) + ZnItem group) { ZnPos pos; ZnBBox area; ZnToAreaStruct ta; - if (Tcl_GetDoubleFromObj(wi->interp, args[0], &area.orig.x) == ZN_ERROR) { - return ZN_ERROR; + if (Tcl_GetDoubleFromObj(wi->interp, args[0], &area.orig.x) == TCL_ERROR) { + return TCL_ERROR; } - if (Tcl_GetDoubleFromObj(wi->interp, args[1], &area.orig.y) == ZN_ERROR) { - return ZN_ERROR; + if (Tcl_GetDoubleFromObj(wi->interp, args[1], &area.orig.y) == TCL_ERROR) { + return TCL_ERROR; } - if (Tcl_GetDoubleFromObj(wi->interp, args[2], &area.corner.x) == ZN_ERROR) { - return ZN_ERROR; + if (Tcl_GetDoubleFromObj(wi->interp, args[2], &area.corner.x) == TCL_ERROR) { + return TCL_ERROR; } - if (Tcl_GetDoubleFromObj(wi->interp, args[3], &area.corner.y) == ZN_ERROR) { - return ZN_ERROR; + if (Tcl_GetDoubleFromObj(wi->interp, args[3], &area.corner.y) == TCL_ERROR) { + return TCL_ERROR; } if (area.corner.x < area.orig.x) { pos = area.orig.x; @@ -2127,7 +2444,7 @@ FindArea(WidgetInfo *wi, ta.area = &area; wi->top_group->class->ToArea(wi->top_group, &ta); - return ZN_OK; + return TCL_OK; } @@ -2147,19 +2464,23 @@ FindArea(WidgetInfo *wi, *---------------------------------------------------------------------- */ static int -FindItems(WidgetInfo *wi, +FindItems(ZnWInfo *wi, int argc, Tcl_Obj *CONST args[], Tcl_Obj *tag, /* NULL to search or tag to add tag. */ int first, /* First arg to process in args */ - TagSearch **search_var) + ZnTagSearch **search_var) { Tk_Uid tag_uid = NULL; int index, result; - Item item; + ZnItem item; ZnBool recursive = True; ZnPickStruct ps; +#ifdef PTK + static char *search_cmd_strings[] = { +#else static CONST char *search_cmd_strings[] = { +#endif "above", "ancestors", "atpriority", "below", "closest", "enclosed", "overlapping", "withtag", "withtype", NULL }; @@ -2169,8 +2490,8 @@ FindItems(WidgetInfo *wi, }; if (Tcl_GetIndexFromObj(wi->interp, args[first], search_cmd_strings, - "search command", 0, &index) != ZN_OK) { - return ZN_ERROR; + "search command", 0, &index) != TCL_OK) { + return TCL_ERROR; } if (tag) { @@ -2185,16 +2506,16 @@ FindItems(WidgetInfo *wi, { if (argc != first+2) { Tcl_WrongNumArgs(wi->interp, first+1, args, "tagOrId"); - return ZN_ERROR; + return TCL_ERROR; } result = ZnItemWithTagOrId(wi, args[first+1], &item, search_var); - if (result == ZN_OK) { + if (result == TCL_OK) { if ((item != ZN_NO_ITEM) && (item->previous != ZN_NO_ITEM)) { ZnDoItem(wi->interp, item->previous, ZN_NO_PART, tag_uid); } } else { - return ZN_ERROR; + return TCL_ERROR; } } break; @@ -2206,18 +2527,18 @@ FindItems(WidgetInfo *wi, Tk_Uid uid = NULL; if ((argc != first+2) && (argc != first+3)) { Tcl_WrongNumArgs(wi->interp, first+1, args, "tagOrId ?withTag?"); - return ZN_ERROR; + return TCL_ERROR; } result = ZnItemWithTagOrId(wi, args[first+1], &item, search_var); - if (result == ZN_ERROR) { - return ZN_ERROR; + if (result == TCL_ERROR) { + return TCL_ERROR; } item = item->parent; if (argc == first+3) { uid = Tk_GetUid(Tcl_GetString(args[first+2])); } while (item != ZN_NO_ITEM) { - if (!uid || ITEM.HasTag(item, uid)) { + if (!uid || ZnITEM.HasTag(item, uid)) { ZnDoItem(wi->interp, item, ZN_NO_PART, tag_uid); } item = item->parent; @@ -2233,10 +2554,10 @@ FindItems(WidgetInfo *wi, if ((argc != first+2) && (argc != first+3)) { Tcl_WrongNumArgs(wi->interp, first+1, args, "pri ?tagOrId?"); - return ZN_ERROR; + return TCL_ERROR; } - if (Tcl_GetIntFromObj(wi->interp, args[first+1], &pri) == ZN_ERROR) { - return ZN_ERROR; + if (Tcl_GetIntFromObj(wi->interp, args[first+1], &pri) == TCL_ERROR) { + return TCL_ERROR; } /* @@ -2244,8 +2565,8 @@ FindItems(WidgetInfo *wi, * the given priority. */ if (ZnTagSearchScan(wi, (argc == first+3) ? args[first+2] : NULL, - search_var) == ZN_ERROR) { - return ZN_ERROR; + search_var) == TCL_ERROR) { + return TCL_ERROR; } for (item = ZnTagSearchFirst(*search_var); item != ZN_NO_ITEM; item = ZnTagSearchNext(*search_var)) { @@ -2260,15 +2581,15 @@ FindItems(WidgetInfo *wi, */ case ZN_S_BELOW: { - Item next; + ZnItem next; if (argc != first+2) { Tcl_WrongNumArgs(wi->interp, first+1, args, "tagOrId"); - return ZN_ERROR; + return TCL_ERROR; } item = ZN_NO_ITEM; - if (ZnTagSearchScan(wi, args[first+1], search_var) == ZN_ERROR) { - return ZN_ERROR; + if (ZnTagSearchScan(wi, args[first+1], search_var) == TCL_ERROR) { + return TCL_ERROR; } for (next = ZnTagSearchFirst(*search_var); next != ZN_NO_ITEM; next = ZnTagSearchNext(*search_var)) { @@ -2289,17 +2610,17 @@ FindItems(WidgetInfo *wi, if ((argc < first+3) || (argc > first+6)) { Tcl_WrongNumArgs(wi->interp, first+1, args, "x y ?halo? ?start?, ?recursive?"); - return ZN_ERROR; + return TCL_ERROR; } - if (Tcl_GetDoubleFromObj(wi->interp, args[first+1], &p.x) == ZN_ERROR) { - return ZN_ERROR; + if (Tcl_GetDoubleFromObj(wi->interp, args[first+1], &p.x) == TCL_ERROR) { + return TCL_ERROR; } - if (Tcl_GetDoubleFromObj(wi->interp, args[first+2], &p.y) == ZN_ERROR) { - return ZN_ERROR; + if (Tcl_GetDoubleFromObj(wi->interp, args[first+2], &p.y) == TCL_ERROR) { + return TCL_ERROR; } if (argc > first+3) { - if (Tcl_GetIntFromObj(wi->interp, args[first+3], &halo) == ZN_ERROR) { - return ZN_ERROR; + if (Tcl_GetIntFromObj(wi->interp, args[first+3], &halo) == TCL_ERROR) { + return TCL_ERROR; } if (halo < 0) { halo = 0; @@ -2311,7 +2632,7 @@ FindItems(WidgetInfo *wi, item = ZN_NO_ITEM; if (argc > (first+4)) { result = ZnItemWithTagOrId(wi, args[first+4], &item, search_var); - if ((result == ZN_OK) && (item != ZN_NO_ITEM)) { + if ((result == TCL_OK) && (item != ZN_NO_ITEM)) { if ((item->class == ZnGroup) && !ZnGroupAtomic) { ps.in_group = item; } @@ -2322,8 +2643,8 @@ FindItems(WidgetInfo *wi, } } if (argc > first+5) { - if (Tcl_GetBooleanFromObj(wi->interp, args[first+5], &recursive) != ZN_OK) { - return ZN_ERROR; + if (Tcl_GetBooleanFromObj(wi->interp, args[first+5], &recursive) != TCL_OK) { + return TCL_ERROR; } } /* @@ -2351,18 +2672,18 @@ FindItems(WidgetInfo *wi, { if ((argc < first+5) || (argc > first+7)) { Tcl_WrongNumArgs(wi->interp, first+1, args, "x1 y1 x2 y2 ?inGroup? ?recursive?"); - return ZN_ERROR; + return TCL_ERROR; } item = wi->top_group; if (argc > first+5) { result = ZnItemWithTagOrId(wi, args[first+5], &item, search_var); - if ((result != ZN_OK) || (item == ZN_NO_ITEM) || (item->class != ZnGroup)) { - return ZN_ERROR; + if ((result != TCL_OK) || (item == ZN_NO_ITEM) || (item->class != ZnGroup)) { + return TCL_ERROR; } } if (argc > first+6) { - if (Tcl_GetBooleanFromObj(wi->interp, args[first+6], &recursive) != ZN_OK) { - return ZN_ERROR; + if (Tcl_GetBooleanFromObj(wi->interp, args[first+6], &recursive) != TCL_OK) { + return TCL_ERROR; } } return FindArea(wi, args+first+1, tag_uid, True, recursive, item); @@ -2375,18 +2696,18 @@ FindItems(WidgetInfo *wi, { if ((argc < first+5) || (argc > first+7)) { Tcl_WrongNumArgs(wi->interp, first+1, args, "x1 y1 x2 y2 ?inGroup? ?recursive?"); - return ZN_ERROR; + return TCL_ERROR; } item = wi->top_group; if (argc > first+5) { result = ZnItemWithTagOrId(wi, args[first+5], &item, search_var); - if ((result != ZN_OK) || (item == ZN_NO_ITEM) || (item->class != ZnGroup)) { - return ZN_ERROR; + if ((result != TCL_OK) || (item == ZN_NO_ITEM) || (item->class != ZnGroup)) { + return TCL_ERROR; } } if (argc > first+6) { - if (Tcl_GetBooleanFromObj(wi->interp, args[first+6], &recursive) != ZN_OK) { - return ZN_ERROR; + if (Tcl_GetBooleanFromObj(wi->interp, args[first+6], &recursive) != TCL_OK) { + return TCL_ERROR; } } return FindArea(wi, args+first+1, tag_uid, False, recursive, item); @@ -2399,10 +2720,10 @@ FindItems(WidgetInfo *wi, { if (argc != first+2) { Tcl_WrongNumArgs(wi->interp, first+1, args, "tagOrId"); - return ZN_ERROR; + return TCL_ERROR; } - if (ZnTagSearchScan(wi, args[first+1], search_var) == ZN_ERROR) { - return ZN_ERROR; + if (ZnTagSearchScan(wi, args[first+1], search_var) == TCL_ERROR) { + return TCL_ERROR; } for (item = ZnTagSearchFirst(*search_var); item != ZN_NO_ITEM; item = ZnTagSearchNext(*search_var)) { @@ -2415,17 +2736,17 @@ FindItems(WidgetInfo *wi, */ case ZN_S_WITHTYPE: { - ItemClass cls; + ZnItemClass cls; if ((argc != first+2) && (argc != first+3)) { Tcl_WrongNumArgs(wi->interp, first+1, args, "itemType ?tagOrId?"); - return ZN_ERROR; + return TCL_ERROR; } cls = ZnLookupItemClass(Tcl_GetString(args[first+1])); if (!cls) { Tcl_AppendResult(wi->interp, "unknown item type \"", Tcl_GetString(args[first+1]), "\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } /* @@ -2433,8 +2754,8 @@ FindItems(WidgetInfo *wi, * the given item type. */ if (ZnTagSearchScan(wi, (argc == first+3) ? args[first+2] : NULL, - search_var) == ZN_ERROR) { - return ZN_ERROR; + search_var) == TCL_ERROR) { + return TCL_ERROR; } for (item = ZnTagSearchFirst(*search_var); item != ZN_NO_ITEM; item = ZnTagSearchNext(*search_var)) { @@ -2458,11 +2779,11 @@ FindItems(WidgetInfo *wi, *---------------------------------------------------------------------- */ int -ZnParseCoordList(WidgetInfo *wi, +ZnParseCoordList(ZnWInfo *wi, Tcl_Obj *arg, ZnPoint **pts, char **controls, - int *num_pts, + unsigned int *num_pts, ZnBool *old_format) { Tcl_Obj **elems, **selems; @@ -2479,15 +2800,15 @@ ZnParseCoordList(WidgetInfo *wi, *old_format = True; } result = Tcl_ListObjGetElements(wi->interp, arg, &num_elems, &elems); - if (result == ZN_ERROR) { + if (result == TCL_ERROR) { coord_error: Tcl_AppendResult(wi->interp, " malformed coord list", NULL); - return ZN_ERROR; + return TCL_ERROR; } if (num_elems == 0) { *num_pts = 0; *pts = NULL; - return ZN_OK; + return TCL_OK; } /* @@ -2498,7 +2819,7 @@ ZnParseCoordList(WidgetInfo *wi, * with its control flag. */ result = Tcl_GetDoubleFromObj(wi->interp, elems[0], &r); - old_style = (result == ZN_OK); + old_style = (result == TCL_OK); if (old_style) { if ((num_elems%2) == 0) { @@ -2506,10 +2827,10 @@ ZnParseCoordList(WidgetInfo *wi, ZnListAssertSize(wi->work_pts, *num_pts); *pts = p = (ZnPoint *) ZnListArray(wi->work_pts); for (i = 0; i < num_elems; i += 2, p++) { - if (Tcl_GetDoubleFromObj(wi->interp, elems[i], &p->x) == ZN_ERROR) { + if (Tcl_GetDoubleFromObj(wi->interp, elems[i], &p->x) == TCL_ERROR) { goto coord_error; } - if (Tcl_GetDoubleFromObj(wi->interp, elems[i+1], &p->y) == ZN_ERROR) { + if (Tcl_GetDoubleFromObj(wi->interp, elems[i+1], &p->y) == TCL_ERROR) { goto coord_error; } /*printf("Parsed a point: %g@%g, ", p->x, p->y);*/ @@ -2520,10 +2841,10 @@ ZnParseCoordList(WidgetInfo *wi, *num_pts = 1; ZnListAssertSize(wi->work_pts, *num_pts); *pts = p = (ZnPoint *) ZnListArray(wi->work_pts); - if (Tcl_GetDoubleFromObj(wi->interp, elems[0], &p->x) == ZN_ERROR) { + if (Tcl_GetDoubleFromObj(wi->interp, elems[0], &p->x) == TCL_ERROR) { goto coord_error; } - if (Tcl_GetDoubleFromObj(wi->interp, elems[1], &p->y) == ZN_ERROR) { + if (Tcl_GetDoubleFromObj(wi->interp, elems[1], &p->y) == TCL_ERROR) { goto coord_error; } if (controls) { @@ -2548,13 +2869,13 @@ ZnParseCoordList(WidgetInfo *wi, *pts = p = (ZnPoint *) ZnListArray(wi->work_pts); for (i = 0; i < num_elems; i++, p++) { result = Tcl_ListObjGetElements(wi->interp, elems[i], &num_selems, &selems); - if ((result == ZN_ERROR) || (num_selems < 2) || (num_selems > 3)) { + if ((result == TCL_ERROR) || (num_selems < 2) || (num_selems > 3)) { goto coord_error; } - if (Tcl_GetDoubleFromObj(wi->interp, selems[0], &p->x) == ZN_ERROR) { + if (Tcl_GetDoubleFromObj(wi->interp, selems[0], &p->x) == TCL_ERROR) { goto coord_error; } - if (Tcl_GetDoubleFromObj(wi->interp, selems[1], &p->y) == ZN_ERROR) { + if (Tcl_GetDoubleFromObj(wi->interp, selems[1], &p->y) == TCL_ERROR) { goto coord_error; } if (controls) { @@ -2575,7 +2896,7 @@ ZnParseCoordList(WidgetInfo *wi, if (old_format) { *old_format = old_style; } - return ZN_OK; + return TCL_OK; } @@ -2587,14 +2908,15 @@ ZnParseCoordList(WidgetInfo *wi, *---------------------------------------------------------------------- */ static int -Contour(WidgetInfo *wi, +Contour(ZnWInfo *wi, int argc, Tcl_Obj *CONST args[], - TagSearch **search_var) + ZnTagSearch **search_var) { ZnPoint *points; - Item item, shape; - int cmd, num_points, cw, result, i, j, k; + ZnItem item, shape; + unsigned int i, j, k,num_points; + int cmd, cw, result; int winding_flag, revert = False; long index; char *controls; @@ -2604,15 +2926,19 @@ Contour(WidgetInfo *wi, ZnContour *contours; /* Keep this array in sync with ZnContourCmd in Types.h */ +#ifdef PTK + static char *op_strings[] = { +#else static CONST char *op_strings[] = { +#endif "add", "remove", NULL }; result = ZnItemWithTagOrId(wi, args[2], &item, search_var); - if ((result == ZN_ERROR) || (item == ZN_NO_ITEM)){ + if ((result == TCL_ERROR) || (item == ZN_NO_ITEM)){ Tcl_AppendResult(wi->interp, "unknown item \"", Tcl_GetString(args[2]), "\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } if (!item->class->Contour) { if (item->class->GetClipVertices || @@ -2622,38 +2948,38 @@ Contour(WidgetInfo *wi, else { Tcl_SetObjResult(wi->interp, Tcl_NewIntObj(0)); } - return ZN_OK; + return TCL_OK; } if (argc == 3) { /* * Requesting the number of contours. */ Tcl_SetObjResult(wi->interp, Tcl_NewIntObj(item->class->Contour(item, -1, 0, NULL))); - return ZN_OK; + return TCL_OK; } /* * Get the sub-command */ if (Tcl_GetIndexFromObj(wi->interp, args[3], op_strings, - "contour operation", 0, &cmd) != ZN_OK) { - return ZN_ERROR; + "contour operation", 0, &cmd) != TCL_OK) { + return TCL_ERROR; } /* * Get the winding flag. */ - if ((Tcl_GetIntFromObj(wi->interp, args[4], &winding_flag) != ZN_OK) || + if ((Tcl_GetIntFromObj(wi->interp, args[4], &winding_flag) != TCL_OK) || (winding_flag < -1) || (winding_flag > 1)) { Tcl_AppendResult(wi->interp, " incorrect winding flag, should be -1, 0, 1, \"", Tcl_GetString(args[4]), "\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } index = ZnListTail; if (((argc == 6) && (cmd == ZN_CONTOUR_REMOVE)) || (argc == 7)) { /* Look for an index value. */ - if (Tcl_GetLongFromObj(wi->interp, args[5], &index) != ZN_OK) { + if (Tcl_GetLongFromObj(wi->interp, args[5], &index) != TCL_OK) { Tcl_AppendResult(wi->interp, " incorrect contour index \"", Tcl_GetString(args[5]), "\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } argc--; args++; @@ -2664,19 +2990,19 @@ Contour(WidgetInfo *wi, } else { result = ZnItemWithTagOrId(wi, args[5], &shape, search_var); - if ((result == ZN_ERROR) || (shape == ZN_NO_ITEM)) { + if ((result == TCL_ERROR) || (shape == ZN_NO_ITEM)) { Tcl_ResetResult(wi->interp); if (ZnParseCoordList(wi, args[5], &points, - &controls, &num_points, NULL) == ZN_ERROR) { - return ZN_ERROR; + &controls, &num_points, NULL) == TCL_ERROR) { + return TCL_ERROR; } - POLY_CONTOUR1(&poly, NULL, num_points, False); + ZnPolyContour1(&poly, NULL, num_points, False); /* * Allocate a fresh point array, ZnParseCoordList returns a shared * array. The control array is not shared and can be passed along. */ poly.contours[0].points = ZnMalloc(num_points*sizeof(ZnPoint)); - cw = poly.contours[0].cw = !TestCCW(points, num_points); + cw = poly.contours[0].cw = !ZnTestCCW(points, num_points); if (winding_flag != 0) { revert = cw ^ (winding_flag == -1); } @@ -2704,7 +3030,7 @@ Contour(WidgetInfo *wi, Tcl_AppendResult(wi->interp, "Must supply an explicit winding direction (-1, 1)\nwhen adding a contour from an item", NULL); - return ZN_ERROR; + return TCL_ERROR; } /* * If something has changed in the geometry we need to @@ -2716,7 +3042,7 @@ Contour(WidgetInfo *wi, noshape: Tcl_AppendResult(wi->interp, "class: \"", shape->class->name, "\" can't give a polygonal shape", NULL); - return ZN_ERROR; + return TCL_ERROR; } if (!shape->class->GetContours) { ZnTriStrip tristrip; @@ -2730,7 +3056,7 @@ Contour(WidgetInfo *wi, if (!simple) { goto noshape; } - POLY_CONTOUR1(&poly, tristrip.strip1.points, tristrip.strip1.num_points, False); + ZnPolyContour1(&poly, tristrip.strip1.points, tristrip.strip1.num_points, False); poly.contours[0].controls = NULL; } else { @@ -2738,13 +3064,13 @@ Contour(WidgetInfo *wi, simple = shape->class->GetContours(shape, &poly); } if (poly.num_contours == 0) { - return ZN_OK; + return TCL_OK; } /* * Compute the tranform to map the device points * into the coordinate space of item. */ - ITEM.GetItemTransform(item, &t); + ZnITEM.GetItemTransform(item, &t); ZnTransfoInvert(&t, &inv); /* * Make a new transformed poly and unshare @@ -2838,14 +3164,14 @@ Contour(WidgetInfo *wi, if (poly.contours != &poly.contour1) { /* - * Must not use POLY_FREE: the point and controls arrays + * Must not use ZnPolyFree: the point and controls arrays * are passed along to the item and no longer ours. */ ZnFree(poly.contours); } } - return ZN_OK; + return TCL_OK; } @@ -2857,52 +3183,52 @@ Contour(WidgetInfo *wi, *---------------------------------------------------------------------- */ static int -Coords(WidgetInfo *wi, +Coords(ZnWInfo *wi, int argc, Tcl_Obj *CONST args[], - TagSearch **search_var) + ZnTagSearch **search_var) { ZnPoint *points; - Item item; - int num_points, result, i; - int cmd = COORDS_READ; + ZnItem item; + unsigned int num_points, i; + int result, cmd = ZN_COORDS_READ; long index, contour = 0; char *str, *controls = NULL; char c[2] = " "; Tcl_Obj *l, *entries[3]; result = ZnItemWithTagOrId(wi, args[2], &item, search_var); - if ((result == ZN_ERROR) || (item == ZN_NO_ITEM)) { + if ((result == TCL_ERROR) || (item == ZN_NO_ITEM)) { Tcl_AppendResult(wi->interp, " unknown item \"", Tcl_GetString(args[2]), "\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } num_points = 0; /*printf(" coords: argc=%d, item %d class: %s\n", argc, item->id, item->class->name);*/ if (argc == 3) { /* Get all coords of default contour (0). */ - if (item->class->Coords(item, 0, 0, COORDS_READ_ALL, - &points, &controls, &num_points) == ZN_ERROR) { - return ZN_ERROR; + if (item->class->Coords(item, 0, 0, ZN_COORDS_READ_ALL, + &points, &controls, &num_points) == TCL_ERROR) { + return TCL_ERROR; } coords_read: /*printf(" coords: read %d points, first is %g@%g\n", num_points, points->x, points->y);*/ l = Tcl_GetObjResult(wi->interp); for (i = 0; i < num_points; i++, points++) { - entries[0] = NewDoubleObj(points->x); - entries[1] = NewDoubleObj(points->y); + entries[0] = Tcl_NewDoubleObj(points->x); + entries[1] = Tcl_NewDoubleObj(points->y); if (controls && controls[i]) { c[0] = controls[i]; - entries[2] = NewStringObj(c); + entries[2] = Tcl_NewStringObj(c, -1); Tcl_ListObjAppendElement(wi->interp, l, Tcl_NewListObj(3, entries)); } else { Tcl_ListObjAppendElement(wi->interp, l, Tcl_NewListObj(2, entries)); } } - return ZN_OK; + return TCL_OK; } /* @@ -2914,18 +3240,18 @@ Coords(WidgetInfo *wi, if ((argc < 5) || (argc > 7)) { Tcl_WrongNumArgs(wi->interp, 1, args, "coords tagOrId add ?contour? ?index? coordList"); - return ZN_ERROR; + return TCL_ERROR; } - cmd = COORDS_ADD; + cmd = ZN_COORDS_ADD; i++; } else if ((str[0] == 'r') && (strcmp(str, "remove") == 0)) { if ((argc != 5) && (argc != 6)) { Tcl_WrongNumArgs(wi->interp, 1, args, "coords tagOrId remove ?contour? index"); - return ZN_ERROR; + return TCL_ERROR; } - cmd = COORDS_REMOVE; + cmd = ZN_COORDS_REMOVE; i++; } @@ -2934,140 +3260,140 @@ Coords(WidgetInfo *wi, * a contour index or a coord list. */ /* printf(" coords: arg %d is %s\n", i, Tcl_GetString(args[i])); */ - if (Tcl_GetLongFromObj(wi->interp, args[i], &index) != ZN_OK) { + if (Tcl_GetLongFromObj(wi->interp, args[i], &index) != TCL_OK) { Tcl_ResetResult(wi->interp); - if (((argc == 5) && (cmd != COORDS_ADD) && (cmd != COORDS_REMOVE)) || + if (((argc == 5) && (cmd != ZN_COORDS_ADD) && (cmd != ZN_COORDS_REMOVE)) || (argc == 6) || (argc == 7)) { Tcl_AppendResult(wi->interp, " incorrect contour index \"", Tcl_GetString(args[i]), "\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } - else if ((argc == 5) && (cmd != COORDS_ADD)) { + else if ((argc == 5) && (cmd != ZN_COORDS_ADD)) { Tcl_AppendResult(wi->interp, " incorrect coord index \"", Tcl_GetString(args[i]), "\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } else if (ZnParseCoordList(wi, args[argc-1], &points, - &controls, &num_points, NULL) == ZN_ERROR) { - return ZN_ERROR; + &controls, &num_points, NULL) == TCL_ERROR) { + return TCL_ERROR; } - if (cmd == COORDS_ADD) { + if (cmd == ZN_COORDS_ADD) { /* Append coords at end of default contour (0). */ - if (item->class->Coords(item, 0, 0, COORDS_ADD_LAST, - &points, &controls, &num_points) == ZN_ERROR) { - return ZN_ERROR; + if (item->class->Coords(item, 0, 0, ZN_COORDS_ADD_LAST, + &points, &controls, &num_points) == TCL_ERROR) { + return TCL_ERROR; } } else { /* Set all coords of default contour (0). */ - if (item->class->Coords(item, 0, 0, COORDS_REPLACE_ALL, - &points, &controls, &num_points) == ZN_ERROR) { - return ZN_ERROR; + if (item->class->Coords(item, 0, 0, ZN_COORDS_REPLACE_ALL, + &points, &controls, &num_points) == TCL_ERROR) { + return TCL_ERROR; } } if (controls) { ZnFree(controls); } - return ZN_OK; + return TCL_OK; } contour = index; if (argc == 4) { /* Get all coords of contour. */ - if (item->class->Coords(item, contour, 0, COORDS_READ_ALL, - &points, &controls, &num_points) == ZN_ERROR) { - return ZN_ERROR; + if (item->class->Coords(item, contour, 0, ZN_COORDS_READ_ALL, + &points, &controls, &num_points) == TCL_ERROR) { + return TCL_ERROR; } goto coords_read; } - else if ((argc == 5) && (cmd == COORDS_REMOVE)) { + else if ((argc == 5) && (cmd == ZN_COORDS_REMOVE)) { /* Remove coord at index in default contour (0). */ - if (item->class->Coords(item, 0, index, COORDS_REMOVE, - &points, &controls, &num_points) == ZN_ERROR) { - return ZN_ERROR; + if (item->class->Coords(item, 0, index, ZN_COORDS_REMOVE, + &points, &controls, &num_points) == TCL_ERROR) { + return TCL_ERROR; } - return ZN_OK; + return TCL_OK; } /* * Try to see if the next param is a vertex index or a coord list. */ i++; /*printf(" coords: arg %d is %s\n", i, Tcl_GetString(args[i]));*/ - if (Tcl_GetLongFromObj(wi->interp, args[i], &index) != ZN_OK) { + if (Tcl_GetLongFromObj(wi->interp, args[i], &index) != TCL_OK) { Tcl_ResetResult(wi->interp); - if ((argc == 7) || ((argc == 6) && (cmd != COORDS_ADD))) { + if ((argc == 7) || ((argc == 6) && (cmd != ZN_COORDS_ADD))) { Tcl_AppendResult(wi->interp, " incorrect coord index \"", Tcl_GetString(args[i]), "\"", NULL); - return ZN_ERROR; + return TCL_ERROR; } else if (ZnParseCoordList(wi, args[argc-1], &points, - &controls, &num_points, NULL) == ZN_ERROR) { - return ZN_ERROR; + &controls, &num_points, NULL) == TCL_ERROR) { + return TCL_ERROR; } - if (cmd == COORDS_ADD) { + if (cmd == ZN_COORDS_ADD) { /* Append coords at end of contour. */ - if (item->class->Coords(item, contour, 0, COORDS_ADD_LAST, - &points, &controls, &num_points) == ZN_ERROR) { - return ZN_ERROR; + if (item->class->Coords(item, contour, 0, ZN_COORDS_ADD_LAST, + &points, &controls, &num_points) == TCL_ERROR) { + return TCL_ERROR; } } else { /* Set all coords of contour. */ - if (item->class->Coords(item, contour, 0, COORDS_REPLACE_ALL, - &points, &controls, &num_points) == ZN_ERROR) { - return ZN_ERROR; + if (item->class->Coords(item, contour, 0, ZN_COORDS_REPLACE_ALL, + &points, &controls, &num_points) == TCL_ERROR) { + return TCL_ERROR; } } if (controls) { ZnFree(controls); } - return ZN_OK; + return TCL_OK; } if (argc == 5) { /* Get coord of contour at index. */ - if (item->class->Coords(item, contour, index, COORDS_READ, - &points, &controls, &num_points) == ZN_ERROR) { - return ZN_ERROR; + if (item->class->Coords(item, contour, index, ZN_COORDS_READ, + &points, &controls, &num_points) == TCL_ERROR) { + return TCL_ERROR; } if (num_points) { /*printf(" coords: read contour:%d, index:%d, point is %g@%g\n", contour, index, points->x, points->y); */ l = Tcl_GetObjResult(wi->interp); - Tcl_ListObjAppendElement(wi->interp, l, NewDoubleObj(points->x)); - Tcl_ListObjAppendElement(wi->interp, l, NewDoubleObj(points->y)); + Tcl_ListObjAppendElement(wi->interp, l, Tcl_NewDoubleObj(points->x)); + Tcl_ListObjAppendElement(wi->interp, l, Tcl_NewDoubleObj(points->y)); if (controls && controls[0]) { c[0] = controls[0]; - Tcl_ListObjAppendElement(wi->interp, l, NewStringObj(c)); + Tcl_ListObjAppendElement(wi->interp, l, Tcl_NewStringObj(c, -1)); } } - return ZN_OK; + return TCL_OK; } - else if ((argc == 6) && (cmd == COORDS_REMOVE)) { + else if ((argc == 6) && (cmd == ZN_COORDS_REMOVE)) { /* Remove coord of contour at index. */ - if (item->class->Coords(item, contour, index, COORDS_REMOVE, - &points, &controls, &num_points) == ZN_ERROR) { - return ZN_ERROR; + if (item->class->Coords(item, contour, index, ZN_COORDS_REMOVE, + &points, &controls, &num_points) == TCL_ERROR) { + return TCL_ERROR; } - return ZN_OK; + return TCL_OK; } /* Set a single coord or add coords at index in contour. */ if (ZnParseCoordList(wi, args[argc-1], &points, - &controls, &num_points, NULL) == ZN_ERROR) { - return ZN_ERROR; + &controls, &num_points, NULL) == TCL_ERROR) { + return TCL_ERROR; } if (argc == 6) { num_points = 1; - cmd = COORDS_REPLACE; + cmd = ZN_COORDS_REPLACE; } if (item->class->Coords(item, contour, index, cmd, - &points, &controls, &num_points) == ZN_ERROR) { - return ZN_ERROR; + &points, &controls, &num_points) == TCL_ERROR) { + return TCL_ERROR; } if (controls) { ZnFree(controls); } - return ZN_OK; + return TCL_OK; } @@ -3092,25 +3418,29 @@ static int WidgetObjCmd(ClientData client_data, /* Information about the widget. */ Tcl_Interp *interp, /* Current interpreter. */ int argc, /* Number of arguments. */ - Tcl_Obj *CONST args[]) /* Argument strings. */ + Tcl_Obj *CONST args[]) /* Arguments. */ { - WidgetInfo *wi = (WidgetInfo *) client_data; + ZnWInfo *wi = (ZnWInfo *) client_data; int result, cmd_index, index; - Item item, item2; + ZnItem item, item2; int field = ZN_NO_PART; - int num = 0, i, j; + unsigned int num = 0, i, j; char *end, *str; ZnTransfo *t = NULL; Tcl_Obj *l; - TagSearch *search_var = NULL; + ZnTagSearch *search_var = NULL; Tcl_HashEntry *entry; ZnPoint *points; - int num_points; + unsigned int num_points; ZnList to_points; Tcl_Obj *entries[3]; char c[] = "c"; +#ifdef PTK + static char *sub_cmd_strings[] = { +#else static CONST char *sub_cmd_strings[] = { +#endif "add", "addtag", "anchorxy", "bbox", "becomes", "bind", "cget", "chggroup", "clone", "configure", "contour", "coords", "currentpart", "cursor", "dchars", @@ -3120,7 +3450,8 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ "lower", "monitor", "numparts", "postscript", "raise", "remove", "rotate", "scale", "select", "smooth", "tapply", "tdelete", "transform", "translate", "treset", - "trestore", "tsave", "type", "vertexat", NULL + "trestore", "tsave", "type", "vertexat", "xview", "yview", + NULL }; enum sub_cmds { ZN_W_ADD, ZN_W_ADDTAG, ZN_W_ANCHORXY, ZN_W_BBOX, ZN_W_BECOMES, ZN_W_BIND, @@ -3132,9 +3463,13 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ ZN_W_LOWER, ZN_W_MONITOR, ZN_W_NUMPARTS, ZN_W_POSTSCRIPT, ZN_W_RAISE, ZN_W_REMOVE, ZN_W_ROTATE, ZN_W_SCALE, ZN_W_SELECT, ZN_W_SMOOTH, ZN_W_TAPPLY, ZN_W_TDELETE, ZN_W_TRANSFORM, ZN_W_TRANSLATE, ZN_W_TRESET, - ZN_W_TRESTORE, ZN_W_TSAVE, ZN_W_TYPE, ZN_W_VERTEX_AT, + ZN_W_TRESTORE, ZN_W_TSAVE, ZN_W_TYPE, ZN_W_VERTEX_AT, ZN_W_XVIEW, ZN_W_YVIEW }; +#ifdef PTK + static char *sel_cmd_strings[] = { +#else static CONST char *sel_cmd_strings[] = { +#endif "adjust", "clear", "from", "item", "to", NULL }; enum sel_cmds { @@ -3144,16 +3479,16 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ if (argc < 2) { Tcl_WrongNumArgs(interp, 1, args, "subcommand ?args?"); - return ZN_ERROR; + return TCL_ERROR; } Tcl_Preserve((ClientData) wi); if (Tcl_GetIndexFromObj(interp, args[1], sub_cmd_strings, - "subcommand", 0, &cmd_index) != ZN_OK) { + "subcommand", 0, &cmd_index) != TCL_OK) { goto error; } - result = ZN_OK; + result = TCL_OK; /*printf("executing command \"%s\", argc=%d\n", Tcl_GetString(args[1]), argc);*/ @@ -3163,17 +3498,17 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ */ case ZN_W_ADD: { - Item group; - ItemClass cls; + ZnItem group; + ZnItemClass cls; if (argc == 2) { /* create subcommand alone, return the list of known * object types. */ - ItemClass *classes = ZnListArray(ZnItemClassList()); + ZnItemClass *classes = ZnListArray(ZnItemClassList()); num = ZnListSize(ZnItemClassList()); l = Tcl_GetObjResult(interp); for (i = 0; i < num; i++) { - Tcl_ListObjAppendElement(interp, l, NewStringObj(classes[i]->name)); + Tcl_ListObjAppendElement(interp, l, Tcl_NewStringObj(classes[i]->name, -1)); } goto done; } @@ -3192,7 +3527,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ goto error; } result = ZnItemWithTagOrId(wi, args[3], &group, &search_var); - if ((result == ZN_ERROR) || (group == ZN_NO_ITEM) || + if ((result == TCL_ERROR) || (group == ZN_NO_ITEM) || (group->class != ZnGroup)) { Tcl_AppendResult(interp, ", group item expected, got \"", Tcl_GetString(args[3]), "\"", NULL); @@ -3205,13 +3540,13 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ if (item == ZN_NO_ITEM) { goto error; } - ITEM.InsertItem(item, group, ZN_NO_ITEM, True); - if (ITEM.ConfigureItem(item, ZN_NO_PART, argc, args, True) == ZN_ERROR) { + ZnITEM.InsertItem(item, group, ZN_NO_ITEM, True); + if (ZnITEM.ConfigureItem(item, ZN_NO_PART, argc, args, True) == TCL_ERROR) { goto error; } wi->hot_item = item; wi->hot_prev = item->previous; - l = NewLongObj(item->id); + l = Tcl_NewLongObj(item->id); Tcl_SetObjResult(interp, l); } break; @@ -3240,7 +3575,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ goto error; } result = ZnItemWithTagOrId(wi, args[2], &item, &search_var); - if ((result == ZN_ERROR) || (item == ZN_NO_ITEM) || + if ((result == TCL_ERROR) || (item == ZN_NO_ITEM) || !item->class->has_anchors) { Tcl_AppendResult(interp, "unknown item or doesn't support anchors \"", Tcl_GetString(args[2]), NULL); @@ -3256,8 +3591,8 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ Update(wi); item->class->GetAnchor(item, anchor, &p); l = Tcl_GetObjResult(wi->interp); - Tcl_ListObjAppendElement(wi->interp, l, NewDoubleObj(p.x)); - Tcl_ListObjAppendElement(wi->interp, l, NewDoubleObj(p.y)); + Tcl_ListObjAppendElement(wi->interp, l, Tcl_NewDoubleObj(p.x)); + Tcl_ListObjAppendElement(wi->interp, l, Tcl_NewDoubleObj(p.y)); } break; /* @@ -3285,22 +3620,22 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ args += 2; Update(wi); - ResetBBox(&bbox); + ZnResetBBox(&bbox); for (i = 0; i < argc; i++) { - if (ZnTagSearchScan(wi, args[i], &search_var) == ZN_ERROR) { + if (ZnTagSearchScan(wi, args[i], &search_var) == TCL_ERROR) { goto error; } for (item = ZnTagSearchFirst(search_var); item != ZN_NO_ITEM; item = ZnTagSearchNext(search_var)) { - AddBBoxToBBox(&bbox, &item->item_bounding_box); + ZnAddBBoxToBBox(&bbox, &item->item_bounding_box); } } - if (!IsEmptyBBox(&bbox)) { + if (!ZnIsEmptyBBox(&bbox)) { l = Tcl_GetObjResult(interp); - Tcl_ListObjAppendElement(interp, l, NewDoubleObj(bbox.orig.x)); - Tcl_ListObjAppendElement(interp, l, NewDoubleObj(bbox.orig.y)); - Tcl_ListObjAppendElement(interp, l, NewDoubleObj(bbox.corner.x)); - Tcl_ListObjAppendElement(interp, l, NewDoubleObj(bbox.corner.y)); + Tcl_ListObjAppendElement(interp, l, Tcl_NewDoubleObj(bbox.orig.x)); + Tcl_ListObjAppendElement(interp, l, Tcl_NewDoubleObj(bbox.orig.y)); + Tcl_ListObjAppendElement(interp, l, Tcl_NewDoubleObj(bbox.corner.x)); + Tcl_ListObjAppendElement(interp, l, Tcl_NewDoubleObj(bbox.corner.y)); } } break; @@ -3338,8 +3673,8 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ } if (*end == ':') { if (item->class->Part) { - l = NewStringObj(end+1); - if (item->class->Part(item, &l, &part) == ZN_ERROR) { + l = Tcl_NewStringObj(end+1, -1); + if (item->class->Part(item, &l, &part) == TCL_ERROR) { goto error; } elem = EncodeItemPart(item, part); @@ -3431,7 +3766,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ if (command == NULL) { goto error; } - Tcl_SetObjResult(interp, NewStringObj(command)); + Tcl_SetObjResult(interp, Tcl_NewStringObj(command, -1)); #endif } else { @@ -3457,7 +3792,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ */ case ZN_W_CHGGROUP: { - Item grp, scan; + ZnItem grp, scan; int adjust=0; ZnTransfo inv, t, t2, *this_one=NULL; @@ -3466,11 +3801,11 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ goto error; } result = ZnItemWithTagOrId(wi, args[2], &item, &search_var); - if ((result == ZN_ERROR) || (item == ZN_NO_ITEM)) { + if ((result == TCL_ERROR) || (item == ZN_NO_ITEM)) { goto error; } result = ZnItemWithTagOrId(wi, args[3], &grp, &search_var); - if ((result == ZN_ERROR) || (grp == ZN_NO_ITEM)|| (grp->class != ZnGroup)) { + if ((result == TCL_ERROR) || (grp == ZN_NO_ITEM)|| (grp->class != ZnGroup)) { goto error; } if (item->parent == grp) { @@ -3493,7 +3828,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ goto error; } if (argc == 5) { - if (Tcl_GetBooleanFromObj(interp, args[4], &adjust) != ZN_OK) { + if (Tcl_GetBooleanFromObj(interp, args[4], &adjust) != TCL_OK) { goto error; } } @@ -3501,9 +3836,9 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ goto done; } if (adjust) { - ITEM.GetItemTransform(grp, &t); + ZnITEM.GetItemTransform(grp, &t); ZnTransfoInvert(&t, &inv); - ITEM.GetItemTransform(item->parent, &t); + ZnITEM.GetItemTransform(item->parent, &t); ZnTransfoCompose(&t2, &t, &inv); this_one = &t2; if (item->transfo) { @@ -3511,18 +3846,18 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ this_one = &t; } } - ITEM.ExtractItem(item); - ITEM.InsertItem(item, grp, ZN_NO_ITEM, True); + ZnITEM.ExtractItem(item); + ZnITEM.InsertItem(item, grp, ZN_NO_ITEM, True); /* * The item can be a group in which case we must * use the ZN_TRANSFO_FLAG to force an update of * the children. In all other case ZN_COORDS_FLAG * is enough. */ - ITEM.Invalidate(item, + ZnITEM.Invalidate(item, item->class==ZnGroup?ZN_TRANSFO_FLAG:ZN_COORDS_FLAG); if (adjust) { - ITEM.SetTransfo(item, this_one); + ZnITEM.SetTransfo(item, this_one); } } break; @@ -3536,18 +3871,18 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ goto error; } result = ZnItemWithTagOrId(wi, args[2], &item, &search_var); - if ((result == ZN_ERROR) || + if ((result == TCL_ERROR) || (item == ZN_NO_ITEM) || (item == wi->top_group)) { goto error; } argc -= 3; args += 3; - item2 = ITEM.CloneItem(item); - ITEM.InsertItem(item2, item->parent, ZN_NO_ITEM, True); - if (ITEM.ConfigureItem(item2, ZN_NO_PART, argc, args, False) == ZN_ERROR) { + item2 = ZnITEM.CloneItem(item); + ZnITEM.InsertItem(item2, item->parent, ZN_NO_ITEM, True); + if (ZnITEM.ConfigureItem(item2, ZN_NO_PART, argc, args, False) == TCL_ERROR) { goto error; } - l = NewLongObj(item2->id); + l = Tcl_NewLongObj(item2->id); Tcl_SetObjResult(interp, l); } break; @@ -3579,7 +3914,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ "contour tagOrId ?operator windingFlag? ?index? ?coordListOrTagOrId?"); goto error; } - if (Contour(wi, argc, args, &search_var) == ZN_ERROR) { + if (Contour(wi, argc, args, &search_var) == TCL_ERROR) { goto error; } break; @@ -3594,7 +3929,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ "coords tagOrId ?add/remove? ?contour? ?index? ?coordList?"); goto error; } - if (Coords(wi, argc, args, &search_var) == ZN_ERROR) { + if (Coords(wi, argc, args, &search_var) == TCL_ERROR) { goto error; } } @@ -3610,7 +3945,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ goto error; } if (argc == 3) { - if (Tcl_GetBooleanFromObj(interp, args[2], &only_fields) != ZN_OK) { + if (Tcl_GetBooleanFromObj(interp, args[2], &only_fields) != TCL_OK) { goto error; } } @@ -3632,11 +3967,11 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ Tcl_WrongNumArgs(interp, 1, args, "cursor tagOrId ?field? index"); goto error; } - if (ZnTagSearchScan(wi, args[2], &search_var) == ZN_ERROR) { + if (ZnTagSearchScan(wi, args[2], &search_var) == TCL_ERROR) { goto error; } if (argc == 5) { - if (Tcl_GetIntFromObj(interp, args[3], &field) != ZN_OK) { + if (Tcl_GetIntFromObj(interp, args[3], &field) != TCL_OK) { field = ZN_NO_PART; if (Tcl_GetString(args[3])[0] != 0) { Tcl_AppendResult(interp, "invalid field index \"", @@ -3655,14 +3990,14 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ continue; } result = (*item->class->Index)(item, field, args[3], &index); - if (result != ZN_OK) { + if (result != TCL_OK) { goto error; } (*item->class->Cursor)(item, field, index); if ((item == wi->focus_item) && (field == wi->focus_field) && wi->text_info.cursor_on) { - ITEM.Invalidate(item, ZN_DRAW_FLAG); + ZnITEM.Invalidate(item, ZN_DRAW_FLAG); } } } @@ -3672,18 +4007,18 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ */ case ZN_W_DCHARS: { - int first, last; - TextInfo *ti = &wi->text_info; + int first, last; + ZnTextInfo *ti = &wi->text_info; if ((argc < 4) || (argc > 6)) { Tcl_WrongNumArgs(interp, 1, args, "dchars tagOrId ?field? first ?last?"); goto error; } - if (ZnTagSearchScan(wi, args[2], &search_var) == ZN_ERROR) { + if (ZnTagSearchScan(wi, args[2], &search_var) == TCL_ERROR) { goto error; } if (argc == 6) { - if (Tcl_GetIntFromObj(interp, args[3], &field) != ZN_OK) { + if (Tcl_GetIntFromObj(interp, args[3], &field) != TCL_OK) { field = ZN_NO_PART; if (Tcl_GetString(args[3])[0] != 0) { Tcl_AppendResult(interp, "invalid field index \"", @@ -3702,12 +4037,12 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ continue; } result = (*item->class->Index)(item, field, args[3], &first); - if (result != ZN_OK) { + if (result != TCL_OK) { goto error; } if (argc == 5) { result = (*item->class->Index)(item, field, args[4], &last); - if (result != ZN_OK) { + if (result != TCL_OK) { goto error; } } @@ -3766,12 +4101,12 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ else { tag = Tk_GetUid(Tcl_GetString(args[2])); } - if (ZnTagSearchScan(wi, args[2], &search_var) == ZN_ERROR) { + if (ZnTagSearchScan(wi, args[2], &search_var) == TCL_ERROR) { goto error; } for (item = ZnTagSearchFirst(search_var); item != ZN_NO_ITEM; item = ZnTagSearchNext(search_var)) { - ITEM.RemoveTag(item, (char *) tag); + ZnITEM.RemoveTag(item, (char *) tag); } } break; @@ -3799,22 +4134,22 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ goto error; } if (ZnParseCoordList(wi, args[2], &points, - NULL, &num_points, NULL) == ZN_ERROR) { - return ZN_ERROR; + NULL, &num_points, NULL) == TCL_ERROR) { + return TCL_ERROR; } - if (Tcl_GetDoubleFromObj(interp, args[3], &error) == ZN_ERROR) { + if (Tcl_GetDoubleFromObj(interp, args[3], &error) == TCL_ERROR) { goto error; } to_points = ZnListNew(32, sizeof(ZnPoint)); - FitBezier(points, num_points, error, to_points); + ZnFitBezier(points, num_points, error, to_points); points = (ZnPoint *) ZnListArray(to_points); num_points = ZnListSize(to_points); l = Tcl_GetObjResult(interp); for (i = 0; i < num_points; i++, points++) { - entries[0] = NewDoubleObj(points->x); - entries[1] = NewDoubleObj(points->y); + entries[0] = Tcl_NewDoubleObj(points->x); + entries[1] = Tcl_NewDoubleObj(points->y); if (i % 3) { - entries[2] = NewStringObj(c); + entries[2] = Tcl_NewStringObj(c, -1); Tcl_ListObjAppendElement(interp, l, Tcl_NewListObj(3, entries)); } else { @@ -3838,30 +4173,30 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ field = wi->focus_field; if (item != ZN_NO_ITEM) { l = Tcl_GetObjResult(interp); - Tcl_ListObjAppendElement(interp, l, NewLongObj(item->id)); + Tcl_ListObjAppendElement(interp, l, Tcl_NewLongObj(item->id)); if (field != ZN_NO_PART) { Tcl_ListObjAppendElement(interp, l, Tcl_NewIntObj(field)); } else { - Tcl_ListObjAppendElement(interp, l, NewStringObj("")); + Tcl_ListObjAppendElement(interp, l, Tcl_NewStringObj("", -1)); } } break; } if ((item != ZN_NO_ITEM) && (item->class->Cursor != NULL) && - (wi->got_focus)) { - ITEM.Invalidate(item, ZN_COORDS_FLAG); + ISSET(wi->flags, ZN_GOT_FOCUS)) { + ZnITEM.Invalidate(item, ZN_COORDS_FLAG); } if (Tcl_GetString(args[2])[0] == 0) { wi->focus_item = ZN_NO_ITEM; wi->focus_field = ZN_NO_PART; break; } - if (ZnItemWithTagOrId(wi, args[2], &item, &search_var) == ZN_ERROR) { + if (ZnItemWithTagOrId(wi, args[2], &item, &search_var) == TCL_ERROR) { goto error; } if (argc == 4) { - if (Tcl_GetIntFromObj(interp, args[3], &field) != ZN_OK) { + if (Tcl_GetIntFromObj(interp, args[3], &field) != TCL_OK) { field = ZN_NO_PART; if (Tcl_GetString(args[3])[0] != 0) { Tcl_AppendResult(interp, "invalid field index \"", @@ -3873,8 +4208,8 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ } wi->focus_item = item; wi->focus_field = field; - if (wi->got_focus && (item->class->Cursor != NULL)) { - ITEM.Invalidate(wi->focus_item, ZN_COORDS_FLAG); + if (ISSET(wi->flags, ZN_GOT_FOCUS) && (item->class->Cursor != NULL)) { + ZnITEM.Invalidate(wi->focus_item, ZN_COORDS_FLAG); } } break; @@ -3902,7 +4237,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ goto error; } result = ZnItemWithTagOrId(wi, args[2], &item, &search_var); - if ((result == ZN_ERROR) || (item == ZN_NO_ITEM)) { + if ((result == TCL_ERROR) || (item == ZN_NO_ITEM)) { goto error; } if (!item->tags || !ZnListSize(item->tags)) { @@ -3913,7 +4248,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ tags = (Tk_Uid *) ZnListArray(item->tags); l = Tcl_GetObjResult(interp); for (i = 0; i < num; i++) { - Tcl_ListObjAppendElement(interp, l, NewStringObj(tags[i])); + Tcl_ListObjAppendElement(interp, l, Tcl_NewStringObj(tags[i], -1)); } } } @@ -3930,7 +4265,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ goto error; } if (argc == 3) { - l = NewBooleanObj(ZnGradientNameExists(Tcl_GetString(args[2]))); + l = Tcl_NewBooleanObj(ZnGradientNameExists(Tcl_GetString(args[2]))); Tcl_SetObjResult(interp, l); } else { @@ -3952,18 +4287,18 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ goto error; } result = ZnItemWithTagOrId(wi, args[2], &item, &search_var); - if ((result == ZN_ERROR) || (item == ZN_NO_ITEM)) { + if ((result == TCL_ERROR) || (item == ZN_NO_ITEM)) { goto error; } if (item->parent != ZN_NO_ITEM) { - l = NewLongObj(item->parent->id); + l = Tcl_NewLongObj(item->parent->id); Tcl_SetObjResult(interp, l); } else { /* * Top group is its own parent. */ - l = NewLongObj(item->id); + l = Tcl_NewLongObj(item->id); Tcl_SetObjResult(interp, l); } } @@ -3978,10 +4313,10 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ goto error; } result = ZnItemWithTagOrId(wi, args[2], &item, &search_var); - if ((result == ZN_ERROR) || (item == ZN_NO_ITEM)) { + if ((result == TCL_ERROR) || (item == ZN_NO_ITEM)) { goto error; } - l = NewBooleanObj(item->class->has_anchors?1:0); + l = Tcl_NewBooleanObj(item->class->has_anchors?1:0); Tcl_SetObjResult(interp, l); } break; @@ -3995,10 +4330,10 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ goto error; } result = ZnItemWithTagOrId(wi, args[2], &item, &search_var); - if ((result == ZN_ERROR) || (item == ZN_NO_ITEM)) { + if ((result == TCL_ERROR) || (item == ZN_NO_ITEM)) { goto error; } - l = NewBooleanObj(item->class->GetFieldSet?1:0); + l = Tcl_NewBooleanObj(item->class->GetFieldSet?1:0); Tcl_SetObjResult(interp, l); } break; @@ -4012,11 +4347,11 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ goto error; } result = ZnItemWithTagOrId(wi, args[2], &item, &search_var); - if ((result == ZN_ERROR) || (item == ZN_NO_ITEM)) { + if ((result == TCL_ERROR) || (item == ZN_NO_ITEM)) { goto error; } - l = NewBooleanObj(ITEM.HasTag(item, - Tk_GetUid(Tcl_GetString(args[3])))); + l = Tcl_NewBooleanObj(ZnITEM.HasTag(item, + Tk_GetUid(Tcl_GetString(args[3])))); Tcl_SetObjResult(interp, l); } break; @@ -4029,11 +4364,11 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ Tcl_WrongNumArgs(interp, 1, args, "index tagOrId ?field? string"); goto error; } - if (ZnTagSearchScan(wi, args[2], &search_var) == ZN_ERROR) { + if (ZnTagSearchScan(wi, args[2], &search_var) == TCL_ERROR) { goto error; } if (argc == 5) { - if (Tcl_GetIntFromObj(interp, args[3], &field) != ZN_OK) { + if (Tcl_GetIntFromObj(interp, args[3], &field) != TCL_OK) { field = ZN_NO_PART; if (Tcl_GetString(args[3])[0] != 0) { Tcl_AppendResult(interp, "invalid field index \"", @@ -4049,7 +4384,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ item != ZN_NO_ITEM; item = ZnTagSearchNext(search_var)) { if (item->class->Index != NULL) { result = (*item->class->Index)(item, field, args[3], &index); - if (result != ZN_OK) { + if (result != TCL_OK) { goto error; } l = Tcl_NewIntObj(index); @@ -4067,18 +4402,18 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ */ case ZN_W_INSERT: { - TextInfo *ti = &wi->text_info; - char *chars; + ZnTextInfo *ti = &wi->text_info; + char *chars; if ((argc != 5) && (argc != 6)) { Tcl_WrongNumArgs(interp, 1, args, "insert tagOrId ?field? before string"); goto error; } - if (ZnTagSearchScan(wi, args[2], &search_var) == ZN_ERROR) { + if (ZnTagSearchScan(wi, args[2], &search_var) == TCL_ERROR) { goto error; } if (argc == 6) { - if (Tcl_GetIntFromObj(interp, args[3], &field) != ZN_OK) { + if (Tcl_GetIntFromObj(interp, args[3], &field) != TCL_OK) { field = ZN_NO_PART; if (Tcl_GetString(args[3])[0] != 0) { Tcl_AppendResult(interp, "invalid field index \"", @@ -4097,7 +4432,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ continue; } result = (*item->class->Index)(item, field, args[3], &index); - if (result != ZN_OK) { + if (result != TCL_OK) { goto error; } chars = Tcl_GetString(args[4]); @@ -4132,11 +4467,11 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ goto error; } result = ZnItemWithTagOrId(wi, args[2], &item, &search_var); - if ((result == ZN_ERROR) || (item == ZN_NO_ITEM)) { + if ((result == TCL_ERROR) || (item == ZN_NO_ITEM)) { goto error; } if (argc == 5) { - if (Tcl_GetIntFromObj(interp, args[3], &field) != ZN_OK) { + if (Tcl_GetIntFromObj(interp, args[3], &field) != TCL_OK) { field = ZN_NO_PART; if (Tcl_GetString(args[3])[0] != 0) { Tcl_AppendResult(interp, "invalid field index \"", @@ -4151,7 +4486,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ if (argc != 4) { goto itemcget_syntax; } - if (ITEM.QueryItem(item, field, 1, &args[3]) != ZN_OK) { + if (ZnITEM.QueryItem(item, field, 1, &args[3]) != TCL_OK) { goto error; } } @@ -4166,11 +4501,11 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ "itemconfigure tagOrId ?field? option value ?option value? ..."); goto error; } - if (ZnTagSearchScan(wi, args[2], &search_var) == ZN_ERROR) { + if (ZnTagSearchScan(wi, args[2], &search_var) == TCL_ERROR) { goto error; } if ((argc > 3) && (Tcl_GetString(args[3])[0] != '-')) { - if (Tcl_GetIntFromObj(interp, args[3], &field) != ZN_OK) { + if (Tcl_GetIntFromObj(interp, args[3], &field) != TCL_OK) { field = ZN_NO_PART; if (Tcl_GetString(args[3])[0] != 0) { Tcl_AppendResult(interp, "invalid field index \"", @@ -4191,10 +4526,10 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ result = ZnAttributesInfo(wi, item, item->class->attr_desc, argc, args); } else if (item->class->GetFieldSet) { - FieldSet fs = item->class->GetFieldSet(item); - if (field < FIELD.NumFields(fs)) { - result = ZnAttributesInfo(wi, FIELD.GetFieldStruct(fs, field), - FIELD.attr_desc, argc, args); + ZnFieldSet fs = item->class->GetFieldSet(item); + if (field < (int) ZnFIELD.NumFields(fs)) { + result = ZnAttributesInfo(wi, ZnFIELD.GetFieldStruct(fs, field), + ZnFIELD.attr_desc, argc, args); } else { Tcl_AppendResult(interp, "field index out of bound", NULL); @@ -4208,9 +4543,9 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ goto done; } else { - result = ITEM.ConfigureItem(item, field, argc, args, False); + result = ZnITEM.ConfigureItem(item, field, argc, args, False); } - if (result == ZN_ERROR) { + if (result == TCL_ERROR) { goto error; } } @@ -4226,7 +4561,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ "layout operator ?args...? tagOrId ?tagOrId...?"); goto error; } - if (LayoutItems(wi, argc-2, args+2) == ZN_ERROR) { + if (LayoutItems(wi, argc-2, args+2) == TCL_ERROR) { goto error; } } @@ -4236,14 +4571,14 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ */ case ZN_W_LOWER: { - Item first, group, mark = ZN_NO_ITEM; + ZnItem first, group, mark = ZN_NO_ITEM; if (argc < 3) { Tcl_WrongNumArgs(interp, 1, args, "lower tagOrId ?belowThis?"); goto error; } if (argc == 4) { - if (ZnTagSearchScan(wi, args[3], &search_var) == ZN_ERROR) { + if (ZnTagSearchScan(wi, args[3], &search_var) == TCL_ERROR) { goto error; } for (item = ZnTagSearchFirst(search_var); @@ -4256,11 +4591,11 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ goto error; } } - if (ZnTagSearchScan(wi, args[2], &search_var) == ZN_ERROR) { + if (ZnTagSearchScan(wi, args[2], &search_var) == TCL_ERROR) { goto error; } item = ZnTagSearchFirst(search_var); - if (item == ZN_NO_ITEM) { + if ((item == ZN_NO_ITEM) || (item == wi->top_group)) { goto done; } first = item; @@ -4270,7 +4605,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ group = mark->parent; do { if ((item->parent == group) && (item != mark)) { - ITEM.UpdateItemPriority(item, mark, False); + ZnITEM.UpdateItemPriority(item, mark, False); mark = item; } item = ZnTagSearchNext(search_var); @@ -4283,6 +4618,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ */ case ZN_W_MONITOR: { +#ifndef _WIN32 ZnBool on_off; if ((argc != 2) && (argc != 3)) { @@ -4290,20 +4626,20 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ goto error; } if (argc == 3) { - if (Tcl_GetBooleanFromObj(interp, args[2], &on_off) != ZN_OK) { + if (Tcl_GetBooleanFromObj(interp, args[2], &on_off) != TCL_OK) { goto error; } - wi->monitoring = on_off; + ASSIGN(wi->flags, ZN_MONITORING, on_off); if (on_off == True) { - ResetChronos(wi->total_draw_chrono); - ResetChronos(wi->this_draw_chrono); + ZnResetChronos(wi->total_draw_chrono); + ZnResetChronos(wi->this_draw_chrono); } } if ((argc == 2) || (on_off == False)) { long ttime, ltime; int num_actions; - GetChrono(wi->total_draw_chrono, &ttime, &num_actions); - GetChrono(wi->this_draw_chrono, <ime, NULL); + ZnGetChrono(wi->total_draw_chrono, &ttime, &num_actions); + ZnGetChrono(wi->this_draw_chrono, <ime, NULL); l = Tcl_GetObjResult(interp); Tcl_ListObjAppendElement(interp, l, Tcl_NewIntObj(num_actions)); Tcl_ListObjAppendElement(interp, l, Tcl_NewIntObj(ltime)); @@ -4312,6 +4648,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ Tcl_ListObjAppendElement(interp, l, Tcl_NewIntObj(wi->damaged_area_h)); Tcl_ListObjAppendElement(interp, l, Tcl_NewIntObj(ttime));*/ } +#endif } break; /* @@ -4324,10 +4661,10 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ goto error; } result = ZnItemWithTagOrId(wi, args[2], &item, &search_var); - if ((result == ZN_ERROR) || (item == ZN_NO_ITEM)) { + if ((result == TCL_ERROR) || (item == ZN_NO_ITEM)) { goto error; } - l = Tcl_NewIntObj(item->class->num_parts); + l = Tcl_NewIntObj((int) item->class->num_parts); Tcl_SetObjResult(interp, l); } break; @@ -4345,7 +4682,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ */ case ZN_W_RAISE: { - Item group, mark = ZN_NO_ITEM; + ZnItem group, mark = ZN_NO_ITEM; if (argc < 3) { Tcl_WrongNumArgs(interp, 1, args, "raise tagOrId ?aboveThis?"); @@ -4355,7 +4692,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ /* * Find the topmost item with the tag. */ - if (ZnTagSearchScan(wi, args[3], &search_var) == ZN_ERROR) { + if (ZnTagSearchScan(wi, args[3], &search_var) == TCL_ERROR) { goto error; } mark = ZnTagSearchFirst(search_var); @@ -4365,11 +4702,11 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ goto error; } } - if (ZnTagSearchScan(wi, args[2], &search_var) == ZN_ERROR) { + if (ZnTagSearchScan(wi, args[2], &search_var) == TCL_ERROR) { goto error; } item = ZnTagSearchFirst(search_var); - if (item == ZN_NO_ITEM) { + if ((item == ZN_NO_ITEM) || (item == wi->top_group)) { goto done; } if (mark == ZN_NO_ITEM) { @@ -4381,7 +4718,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ continue; } if (item != mark) { - ITEM.UpdateItemPriority(item, mark, True); + ZnITEM.UpdateItemPriority(item, mark, True); } } } @@ -4391,7 +4728,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ */ case ZN_W_REMOVE: { - int num_fields; + unsigned int num_fields; if (argc < 3) { Tcl_WrongNumArgs(interp, 1, args, "remove tagOrId ?tagOrId ...?"); @@ -4399,8 +4736,8 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ } argc -= 2; args += 2; - for (i = 0; i < argc; i++) { - if (ZnTagSearchScan(wi, args[i], &search_var) == ZN_ERROR) { + for (i = 0; i < (unsigned int) argc; i++) { + if (ZnTagSearchScan(wi, args[i], &search_var) == TCL_ERROR) { goto error; } for (item = ZnTagSearchFirst(search_var); @@ -4411,7 +4748,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ if (wi->binding_table != NULL) { Tk_DeleteAllBindings(wi->binding_table, (ClientData) item); if (item->class->GetFieldSet) { - num_fields = FIELD.NumFields(item->class->GetFieldSet(item)); + num_fields = ZnFIELD.NumFields(item->class->GetFieldSet(item)); for (j = 0; j < num_fields; j++) { Tk_DeleteAllBindings(wi->binding_table, (ClientData) EncodeItemPart(item, j)); @@ -4422,7 +4759,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ (ClientData) EncodeItemPart(item, -(j+2))); } } - ITEM.DestroyItem(item); + ZnITEM.DestroyItem(item); } } } @@ -4441,10 +4778,10 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ } if (argc == 6) { - if (Tcl_GetDoubleFromObj(interp, args[4], &p.x) == ZN_ERROR) { + if (Tcl_GetDoubleFromObj(interp, args[4], &p.x) == TCL_ERROR) { goto error; } - if (Tcl_GetDoubleFromObj(interp, args[5], &p.y) == ZN_ERROR) { + if (Tcl_GetDoubleFromObj(interp, args[5], &p.y) == TCL_ERROR) { goto error; } } @@ -4453,11 +4790,11 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ t = (ZnTransfo *) Tcl_GetHashValue(entry); } else { - if (ZnTagSearchScan(wi, args[2], &search_var) == ZN_ERROR) { + if (ZnTagSearchScan(wi, args[2], &search_var) == TCL_ERROR) { goto error; } } - if (Tcl_GetDoubleFromObj(interp, args[3], &angle) == ZN_ERROR) { + if (Tcl_GetDoubleFromObj(interp, args[3], &angle) == TCL_ERROR) { goto error; } @@ -4473,7 +4810,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ else { for (item = ZnTagSearchFirst(search_var); item != ZN_NO_ITEM; item = ZnTagSearchNext(search_var)) { - ITEM.RotateItem(item, angle, (argc == 6) ? &p : NULL); + ZnITEM.RotateItem(item, angle, (argc == 6) ? &p : NULL); } } } @@ -4494,14 +4831,14 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ t = (ZnTransfo *) Tcl_GetHashValue(entry); } else { - if (ZnTagSearchScan(wi, args[2], &search_var) == ZN_ERROR) { + if (ZnTagSearchScan(wi, args[2], &search_var) == TCL_ERROR) { goto error; } } - if (Tcl_GetDoubleFromObj(interp, args[3], &scale.x) == ZN_ERROR) { + if (Tcl_GetDoubleFromObj(interp, args[3], &scale.x) == TCL_ERROR) { goto error; } - if (Tcl_GetDoubleFromObj(interp, args[4], &scale.y) == ZN_ERROR) { + if (Tcl_GetDoubleFromObj(interp, args[4], &scale.y) == TCL_ERROR) { goto error; } @@ -4511,7 +4848,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ else { for (item = ZnTagSearchFirst(search_var); item != ZN_NO_ITEM; item = ZnTagSearchNext(search_var)) { - ITEM.ScaleItem(item, scale.x, scale.y); + ZnITEM.ScaleItem(item, scale.x, scale.y); } } } @@ -4521,14 +4858,14 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ */ case ZN_W_SELECT: { - TextInfo *ti = &wi->text_info; + ZnTextInfo *ti = &wi->text_info; if (argc < 3) { Tcl_WrongNumArgs(interp, 1, args, "select option ?tagOrId? ?arg?"); goto error; } if (argc >= 4) { - if (ZnTagSearchScan(wi, args[3], &search_var) == ZN_ERROR) { + if (ZnTagSearchScan(wi, args[3], &search_var) == TCL_ERROR) { goto error; } for (item = ZnTagSearchFirst(search_var); @@ -4545,12 +4882,12 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ } } if (Tcl_GetIndexFromObj(interp, args[2], sel_cmd_strings, - "selection option", 0, &cmd_index) != ZN_OK) { + "selection option", 0, &cmd_index) != TCL_OK) { goto error; } if ((argc == 5) || (argc == 6)) { if (argc == 6) { - if (Tcl_GetIntFromObj(interp, args[4], &field) != ZN_OK) { + if (Tcl_GetIntFromObj(interp, args[4], &field) != TCL_OK) { field = ZN_NO_PART; if (Tcl_GetString(args[4])[0] != 0) { Tcl_AppendResult(interp, "invalid field index \"", @@ -4563,7 +4900,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ args++; } result = item->class->Index(item, field, args[4], &index); - if (result != ZN_OK) { + if (result != TCL_OK) { goto error; } } @@ -4589,7 +4926,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ goto error; } if (ti->sel_item != ZN_NO_ITEM) { - ITEM.Invalidate(ti->sel_item, ZN_DRAW_FLAG); + ZnITEM.Invalidate(ti->sel_item, ZN_DRAW_FLAG); ti->sel_item = ZN_NO_ITEM; ti->sel_field = ZN_NO_PART; } @@ -4610,12 +4947,12 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ } if (ti->sel_item != ZN_NO_ITEM) { l = Tcl_GetObjResult(interp); - Tcl_ListObjAppendElement(interp, l, NewLongObj(ti->sel_item->id)); + Tcl_ListObjAppendElement(interp, l, Tcl_NewLongObj(ti->sel_item->id)); if (ti->sel_field != ZN_NO_PART) { Tcl_ListObjAppendElement(interp, l, Tcl_NewIntObj(ti->sel_field)); } else { - Tcl_ListObjAppendElement(interp, l, NewStringObj("")); + Tcl_ListObjAppendElement(interp, l, Tcl_NewStringObj("", -1)); } } break; @@ -4639,19 +4976,19 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ goto error; } if (ZnParseCoordList(wi, args[2], &points, - NULL, &num_points, NULL) == ZN_ERROR) { - return ZN_ERROR; + NULL, &num_points, NULL) == TCL_ERROR) { + return TCL_ERROR; } to_points = ZnListNew(32, sizeof(ZnPoint)); - SmoothPathWithBezier(points, num_points, to_points); + ZnSmoothPathWithBezier(points, num_points, to_points); points = (ZnPoint *) ZnListArray(to_points); num_points = ZnListSize(to_points); l = Tcl_GetObjResult(interp); for (i = 0; i < num_points; i++, points++) { - entries[0] = NewDoubleObj(points->x); - entries[1] = NewDoubleObj(points->y); + entries[0] = Tcl_NewDoubleObj(points->x); + entries[1] = Tcl_NewDoubleObj(points->y); if (i % 3) { - entries[2] = NewStringObj(c); + entries[2] = Tcl_NewStringObj(c, -1); Tcl_ListObjAppendElement(interp, l, Tcl_NewListObj(3, entries)); } else { @@ -4699,7 +5036,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ char *controls; ZnPoint *p, xp; ZnTransfo t, t2, inv, *this_one; - Item from, to; + ZnItem from, to; ZnBool old_format; if ((argc != 4) && (argc != 5)) { @@ -4709,12 +5046,12 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ if (argc == 5) { result = ZnItemWithTagOrId(wi, args[2], &from, &search_var); - if ((result == ZN_ERROR) || (from == ZN_NO_ITEM)) { + if ((result == TCL_ERROR) || (from == ZN_NO_ITEM)) { goto error; } } result = ZnItemWithTagOrId(wi, args[argc-2], &to, &search_var); - if ((result == ZN_ERROR) || (to == ZN_NO_ITEM)) { + if ((result == TCL_ERROR) || (to == ZN_NO_ITEM)) { Tcl_HashEntry *e; /* * Try to find a named transform. @@ -4730,12 +5067,12 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ inv = *((ZnTransfo *) Tcl_GetHashValue(e)); } else { - ITEM.GetItemTransform(to, &t); + ZnITEM.GetItemTransform(to, &t); ZnTransfoInvert(&t, &inv); } this_one = &inv; if (argc == 5) { - ITEM.GetItemTransform(from, &t); + ZnITEM.GetItemTransform(from, &t); ZnTransfoCompose(&t2, &t, &inv); this_one = &t2; } @@ -4743,7 +5080,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ ZnPrintTransfo(&inv);*/ if (ZnParseCoordList(wi, args[argc-1], &p, - &controls, &num_points, &old_format) == ZN_ERROR) { + &controls, &num_points, &old_format) == TCL_ERROR) { Tcl_AppendResult(interp, " invalid coord list \"", Tcl_GetString(args[argc-1]), "\"", NULL); goto error; @@ -4753,14 +5090,14 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ for (i = 0; i < num_points; i++, p++) { ZnTransformPoint(this_one, p, &xp); /*printf("p->x=%g, p->y=%g, xp.x=%g, xp.y=%g\n", p->x, p->y, xp.x, xp.y);*/ - Tcl_ListObjAppendElement(interp, l, NewDoubleObj(xp.x)); - Tcl_ListObjAppendElement(interp, l, NewDoubleObj(xp.y)); + Tcl_ListObjAppendElement(interp, l, Tcl_NewDoubleObj(xp.x)); + Tcl_ListObjAppendElement(interp, l, Tcl_NewDoubleObj(xp.y)); /* The next case only applies for a one point * list with a control flag. */ if (controls && controls[i]) { c[0] = controls[i]; - Tcl_ListObjAppendElement(interp, l, NewStringObj(c)); + Tcl_ListObjAppendElement(interp, l, Tcl_NewStringObj(c, -1)); } } } @@ -4768,11 +5105,11 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ for (i = 0; i < num_points; i++, p++) { ZnTransformPoint(this_one, p, &xp); /*printf("p->x=%g, p->y=%g, xp.x=%g, xp.y=%g\n", p->x, p->y, xp.x, xp.y);*/ - entries[0] = NewDoubleObj(xp.x); - entries[1] = NewDoubleObj(xp.y); + entries[0] = Tcl_NewDoubleObj(xp.x); + entries[1] = Tcl_NewDoubleObj(xp.y); if (controls && controls[i]) { c[0] = controls[i]; - entries[2] = NewStringObj(c); + entries[2] = Tcl_NewStringObj(c, -1); Tcl_ListObjAppendElement(interp, l, Tcl_NewListObj(3, entries)); } else { @@ -4798,14 +5135,14 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ t = (ZnTransfo *) Tcl_GetHashValue(entry); } else { - if (ZnTagSearchScan(wi, args[2], &search_var) == ZN_ERROR) { + if (ZnTagSearchScan(wi, args[2], &search_var) == TCL_ERROR) { goto error; } } - if (Tcl_GetDoubleFromObj(interp, args[3], &trans.x) == ZN_ERROR) { + if (Tcl_GetDoubleFromObj(interp, args[3], &trans.x) == TCL_ERROR) { goto error; } - if (Tcl_GetDoubleFromObj(interp, args[4], &trans.y) == ZN_ERROR) { + if (Tcl_GetDoubleFromObj(interp, args[4], &trans.y) == TCL_ERROR) { goto error; } @@ -4815,7 +5152,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ else { for (item = ZnTagSearchFirst(search_var); item != ZN_NO_ITEM; item =ZnTagSearchNext(search_var)) { - ITEM.TranslateItem(item, trans.x, trans.y); + ZnITEM.TranslateItem(item, trans.x, trans.y); } } } @@ -4834,7 +5171,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ t = (ZnTransfo *) Tcl_GetHashValue(entry); } else { - if (ZnTagSearchScan(wi, args[2], &search_var) == ZN_ERROR) { + if (ZnTagSearchScan(wi, args[2], &search_var) == TCL_ERROR) { goto error; } } @@ -4845,7 +5182,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ else { for (item = ZnTagSearchFirst(search_var); item != ZN_NO_ITEM; item = ZnTagSearchNext(search_var)) { - ITEM.ResetTransfo(item); + ZnITEM.ResetTransfo(item); } } } @@ -4866,12 +5203,12 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ goto error; } t = (ZnTransfo *) Tcl_GetHashValue(entry); - if (ZnTagSearchScan(wi, args[2], &search_var) == ZN_ERROR) { + if (ZnTagSearchScan(wi, args[2], &search_var) == TCL_ERROR) { goto error; } for (item = ZnTagSearchFirst(search_var); item != ZN_NO_ITEM; item = ZnTagSearchNext(search_var)) { - ITEM.SetTransfo(item, t); + ZnITEM.SetTransfo(item, t); } } break; @@ -4889,16 +5226,16 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ } if (argc == 3) { entry = Tcl_FindHashEntry(wi->t_table, Tcl_GetString(args[2])); - l = NewBooleanObj(entry != NULL); + l = Tcl_NewBooleanObj(entry != NULL); Tcl_SetObjResult(interp, l); goto done; } result = ZnItemWithTagOrId(wi, args[2], &item, &search_var); - if ((result == ZN_ERROR) || (item == ZN_NO_ITEM)) { + if ((result == TCL_ERROR) || (item == ZN_NO_ITEM)) { goto error; } if (argc == 5) { - if (Tcl_GetBooleanFromObj(interp, args[4], &invert) != ZN_OK) { + if (Tcl_GetBooleanFromObj(interp, args[4], &invert) != TCL_OK) { goto error; } argc--; @@ -4928,11 +5265,11 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ goto error; } result = ZnItemWithTagOrId(wi, args[2], &item, &search_var); - if (result == ZN_ERROR) { + if (result == TCL_ERROR) { goto error; } if (item != ZN_NO_ITEM) { - l = NewStringObj(item->class->name); + l = Tcl_NewStringObj(item->class->name, -1); Tcl_SetObjResult(interp, l); } } @@ -4949,7 +5286,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ Tcl_WrongNumArgs(interp, 1, args, " vertexat tagOrId x y"); goto error; } - if (ZnTagSearchScan(wi, args[2], &search_var) == ZN_ERROR) { + if (ZnTagSearchScan(wi, args[2], &search_var) == TCL_ERROR) { goto error; } for (item = ZnTagSearchFirst(search_var); @@ -4963,10 +5300,10 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ Tcl_GetString(args[2]), "\"", NULL); goto error; } - if (Tcl_GetDoubleFromObj(interp, args[3], &p.x) == ZN_ERROR) { + if (Tcl_GetDoubleFromObj(interp, args[3], &p.x) == TCL_ERROR) { goto error; } - if (Tcl_GetDoubleFromObj(interp, args[4], &p.y) == ZN_ERROR) { + if (Tcl_GetDoubleFromObj(interp, args[4], &p.y) == TCL_ERROR) { goto error; } item->class->PickVertex(item, &p, &contour, &vertex, &o_vertex); @@ -4975,6 +5312,80 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ Tcl_ListObjAppendElement(interp, l, Tcl_NewIntObj(vertex)); Tcl_ListObjAppendElement(interp, l, Tcl_NewIntObj(o_vertex)); } + + /* xview */ + case ZN_W_XVIEW: + { + int count, type; + ZnReal new_x=0.0, fraction; + + if (argc == 2) { + Tcl_SetObjResult(interp, + ScrollFractions(wi->origin.x, wi->origin.x + Tk_Width(wi->win), + wi->scroll_xo, wi->scroll_xc)); + } + else { + type = Tk_GetScrollInfoObj(interp, argc, args, &fraction, &count); + switch (type) { + case TK_SCROLL_ERROR: + result = TCL_ERROR; + goto done; + case TK_SCROLL_MOVETO: + new_x = (wi->scroll_xo + (int) (fraction * (wi->scroll_xc - wi->scroll_xo) + 0.5)); + break; + case TK_SCROLL_PAGES: + new_x = (int) (wi->origin.x + count * 0.9 * Tk_Width(wi->win)); + break; + case TK_SCROLL_UNITS: + if (wi->x_scroll_incr > 0) { + new_x = wi->origin.x + count * wi->x_scroll_incr; + } + else { + new_x = (int) (wi->origin.x + count * 0.1 * Tk_Width(wi->win)); + } + break; + } + SetOrigin(wi, new_x, wi->origin.y); + } + break; + } + + /*yview */ + case ZN_W_YVIEW: + { + int count, type; + ZnReal new_y = 0.0, fraction; + + if (argc == 2) { + Tcl_SetObjResult(interp, + ScrollFractions(wi->origin.y, wi->origin.y + Tk_Height(wi->win), + wi->scroll_yo, wi->scroll_yc)); + } + else { + type = Tk_GetScrollInfoObj(interp, argc, args, &fraction, &count); + switch (type) { + case TK_SCROLL_ERROR: + result = TCL_ERROR; + goto done; + case TK_SCROLL_MOVETO: + new_y = (wi->scroll_yo + (int) (fraction * (wi->scroll_yc - wi->scroll_yo) + 0.5)); + break; + case TK_SCROLL_PAGES: + new_y = (int) (wi->origin.y + count * 0.9 * Tk_Height(wi->win)); + break; + case TK_SCROLL_UNITS: + if (wi->y_scroll_incr > 0) { + new_y = wi->origin.y + count * wi->y_scroll_incr; + } + else { + new_y = (int) (wi->origin.y + count * 0.1 * Tk_Height(wi->win)); + } + break; + } + SetOrigin(wi, wi->origin.x, new_y); + } + break; + } } done: @@ -4993,7 +5404,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ wi->work_item_list = NULL; } Tcl_Release((ClientData) wi); - return ZN_ERROR; + return TCL_ERROR; } @@ -5007,7 +5418,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ * reconfigure) a Zinc widget. * * Results: - * The return value is a standard Tcl result. If ZN_ERROR is + * The return value is a standard Tcl result. If TCL_ERROR is * returned, then interp->result contains an error message. * * Side effects: @@ -5019,7 +5430,7 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */ */ static int Configure(Tcl_Interp *interp,/* Used for error reporting. */ - WidgetInfo *wi, /* Information about widget. */ + ZnWInfo *wi, /* Information about widget. */ int argc, /* Number of valid entries in args. */ Tcl_Obj *CONST args[], /* Arguments. */ int flags) /* Flags to pass to Tk_ConfigureWidget. */ @@ -5047,7 +5458,7 @@ Configure(Tcl_Interp *interp,/* Used for error reporting. */ wi->render = render; } -#ifdef GLX +#ifdef GL if (CONFIG_PROBE(FONT_SPEC) || !wi->font_tfi) { if (wi->font_tfi) { ZnFreeTexFont(wi->font_tfi); @@ -5075,16 +5486,18 @@ Configure(Tcl_Interp *interp,/* Used for error reporting. */ wi->pick_aperture = 0; } if (CONFIG_PROBE(BACK_COLOR_SPEC) || !wi->relief_grad) { - XColor *color; - int alpha; - color = ZnGetGradientColor(wi->back_color, 0, &alpha); + XColor *color; + unsigned short alpha; + + color = ZnGetGradientColor(wi->back_color, 0.0, &alpha); Tk_SetWindowBackground(wi->win, ZnPixel(color)); if (wi->relief_grad) { ZnFreeGradient(wi->relief_grad); + wi->relief_grad = NULL; } - if (wi->relief != RELIEF_FLAT) { + if (wi->relief != ZN_RELIEF_FLAT) { wi->relief_grad = ZnGetReliefGradient(interp, wi->win, - ZnNameOfColor(color), alpha); + Tk_NameOfColor(color), alpha); } } if (CONFIG_PROBE(BACK_COLOR_SPEC) || CONFIG_PROBE(LIGHT_ANGLE_SPEC)) { @@ -5108,10 +5521,10 @@ Configure(Tcl_Interp *interp,/* Used for error reporting. */ if (CONFIG_PROBE(SPEED_VECTOR_LENGTH_SPEC) || CONFIG_PROBE(MANAGE_HISTORY_SPEC) || CONFIG_PROBE(MANAGED_HISTORY_SIZE_SPEC)) { - ITEM.InvalidateItems(wi->top_group, ZnTrack); + ZnITEM.InvalidateItems(wi->top_group, ZnTrack); } if (CONFIG_PROBE(MAP_DISTANCE_SYMBOL_SPEC)) { - ITEM.InvalidateItems(wi->top_group, ZnMap); + ZnITEM.InvalidateItems(wi->top_group, ZnMap); } /* @@ -5119,7 +5532,7 @@ Configure(Tcl_Interp *interp,/* Used for error reporting. */ */ if (CONFIG_PROBE(WIDTH_SPEC) || CONFIG_PROBE(HEIGHT_SPEC) || CONFIG_PROBE(BORDER_WIDTH_SPEC) || - CONFIG_PROBE(HIGHLIGHT_THICKNESS_SPEC) || !wi->realized) { + CONFIG_PROBE(HIGHLIGHT_THICKNESS_SPEC) || ISCLEAR(wi->flags, ZN_REALIZED)) { Tk_GeometryRequest(wi->win, wi->opt_width, wi->opt_height); } @@ -5136,7 +5549,7 @@ Configure(Tcl_Interp *interp,/* Used for error reporting. */ #ifdef OM if (CONFIG_PROBE(OVERLAP_MANAGER_SPEC)) { Tcl_HashEntry *entry; - Item grp; + ZnItem grp; if (wi->om_group != ZN_NO_ITEM) { OmUnregister((void *) wi); @@ -5145,10 +5558,10 @@ Configure(Tcl_Interp *interp,/* Used for error reporting. */ if (wi->om_group_id != 0) { entry = Tcl_FindHashEntry(wi->id_table, (char *) wi->om_group_id); if (entry != NULL) { - grp = (Item) Tcl_GetHashValue(entry); + grp = (ZnItem) Tcl_GetHashValue(entry); if (grp->class == ZnGroup) { - OmRegister((void *) wi, SendTrackToOm, - SetLabelAngleFromOm, QueryLabelPosition); + OmRegister((void *) wi, ZnSendTrackToOm, + ZnSetLabelAngleFromOm, ZnQueryLabelPosition); wi->om_group = grp; } } @@ -5157,17 +5570,59 @@ Configure(Tcl_Interp *interp,/* Used for error reporting. */ #endif if (CONFIG_PROBE(INSERT_WIDTH_SPEC) && wi->focus_item) { - ITEM.Invalidate(wi->focus_item, ZN_COORDS_FLAG); + ZnITEM.Invalidate(wi->focus_item, ZN_COORDS_FLAG); } /* * Update the blinking cursor timing if on/off time has changed. */ - if (wi->got_focus && + if (ISSET(wi->flags, ZN_GOT_FOCUS) && (CONFIG_PROBE(INSERT_ON_TIME_SPEC) || CONFIG_PROBE(INSERT_OFF_TIME_SPEC))) { Focus(wi, True); } - + + if (CONFIG_PROBE(SCROLL_REGION_SPEC)) { + /* + * Compute the scroll region + */ + wi->scroll_xo = wi->scroll_yo = 0; + wi->scroll_xc = wi->scroll_yc = 0; + if (wi->region != NULL) { + int argc2; +#ifdef PTK + char **args2; +#else + CONST char **args2; +#endif + + if (Tcl_SplitList(interp, wi->region, &argc2, &args2) != TCL_OK) { + return TCL_ERROR; + } + if (argc2 != 4) { + Tcl_AppendResult(interp, "bad scrollRegion \"", + wi->region, "\"", (char *) NULL); + badRegion: + ZnFree(wi->region); + ZnFree(args2); + wi->region = NULL; + return TCL_ERROR; + } + if ((Tk_GetPixels(interp, wi->win, args2[0], &wi->scroll_xo) != TCL_OK) || + (Tk_GetPixels(interp, wi->win, args2[1], &wi->scroll_yo) != TCL_OK) || + (Tk_GetPixels(interp, wi->win, args2[2], &wi->scroll_xc) != TCL_OK) || + (Tk_GetPixels(interp, wi->win, args2[3], &wi->scroll_yc) != TCL_OK)) { + goto badRegion; + } + ZnFree(args2); + } + } + + if (CONFIG_PROBE(SCROLL_REGION_SPEC) || + CONFIG_PROBE(CONFINE_SPEC)) { + SetOrigin(wi, wi->origin.x, wi->origin.y); + SET(wi->flags, ZN_UPDATE_SCROLLBARS); + } + return TCL_OK; } @@ -5192,9 +5647,9 @@ Configure(Tcl_Interp *interp,/* Used for error reporting. */ static void Blink(ClientData client_data) { - WidgetInfo *wi = (WidgetInfo *) client_data; + ZnWInfo *wi = (ZnWInfo *) client_data; - if (!wi->got_focus || (wi->insert_off_time == 0)) { + if (ISCLEAR(wi->flags, ZN_GOT_FOCUS) || (wi->insert_off_time == 0)) { return; } if (wi->text_info.cursor_on) { @@ -5209,17 +5664,17 @@ Blink(ClientData client_data) } if ((wi->focus_item != ZN_NO_ITEM) && (wi->focus_item->class->Cursor != NULL)) { - ITEM.Invalidate(wi->focus_item, ZN_DRAW_FLAG); + ZnITEM.Invalidate(wi->focus_item, ZN_DRAW_FLAG); } } static void -Focus(WidgetInfo *wi, +Focus(ZnWInfo *wi, ZnBool got_focus) { Tcl_DeleteTimerHandler(wi->blink_handler); if (got_focus) { - wi->got_focus = 1; + SET(wi->flags, ZN_GOT_FOCUS); wi->text_info.cursor_on = 1; if (wi->insert_off_time != 0) { wi->blink_handler = Tcl_CreateTimerHandler(wi->insert_off_time, @@ -5227,19 +5682,19 @@ Focus(WidgetInfo *wi, } } else { - wi->got_focus = 0; + CLEAR(wi->flags, ZN_GOT_FOCUS); wi->text_info.cursor_on = 0; wi->blink_handler = (Tcl_TimerToken) NULL; } if ((wi->focus_item != ZN_NO_ITEM) && (wi->focus_item->class->Cursor != NULL)){ - ITEM.Invalidate(wi->focus_item, ZN_COORDS_FLAG); + ZnITEM.Invalidate(wi->focus_item, ZN_COORDS_FLAG); } /*printf("focus %s\n", got_focus ? "in" : "out");*/ if (wi->highlight_width > 0) { ZnNeedRedisplay(wi); } -#ifdef GLX_DAMAGE +#ifdef GL_DAMAGE if (wi->render) { ZnBBox bbox; @@ -5273,7 +5728,8 @@ static void Event(ClientData client_data, /* Information about widget. */ XEvent *event) /* Information about event. */ { - WidgetInfo *wi = (WidgetInfo *) client_data; + ZnWInfo *wi = (ZnWInfo *) client_data; + XGCValues values; /*printf("=============== DEBUT %s %d EVENT ==================\n", event->type == MapNotify ? "MAP": @@ -5283,20 +5739,18 @@ Event(ClientData client_data, /* Information about widget. */ "??", event->type);*/ if (event->type == MapNotify) { if (!wi->gc) { - wi->realized = True; + SET(wi->flags, ZN_REALIZED); if (wi->render) { -#ifdef GLX +#ifdef GL GLfloat r[2]; - glXMakeCurrent(wi->dpy, ZnWindowId(wi->win), wi->gl_context); - /*glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, r);*/ - glGetFloatv(GL_SMOOTH_LINE_WIDTH_RANGE, r); + ZnGLMakeCurrent(wi); + glGetFloatv(ZN_GL_LINE_WIDTH_RANGE, r); wi->max_line_width = r[1]; - /*glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, r);*/ - glGetFloatv(GL_SMOOTH_POINT_SIZE_RANGE, r); + glGetFloatv(ZN_GL_POINT_SIZE_RANGE, r); wi->max_point_width = r[1]; -#ifdef GLX_PRINT_CONFIG - if (getenv("ZINC_GLX_INFO")) { + + if (ISSET(wi->flags, ZN_PRINT_CONFIG)) { fprintf(stderr, "OpenGL version %s\n", (char *) glGetString(GL_VERSION)); fprintf(stderr, " Rendering engine: %s, ", @@ -5310,7 +5764,8 @@ Event(ClientData client_data, /* Information about widget. */ fprintf(stderr, "Max antialiased point size: %g\n", wi->max_point_width); } -#endif + + ZnGLRelease(wi); #endif } @@ -5318,8 +5773,10 @@ Event(ClientData client_data, /* Information about widget. */ * Get the work GC and suppress GraphicExpose * and NoExpose events reception. */ - wi->gc = XCreateGC(wi->dpy, ZnWindowId(wi->win), 0, NULL); - XSetGraphicsExposures(wi->dpy, wi->gc, False); + wi->gc = XCreateGC(wi->dpy, Tk_WindowId(wi->win), 0, NULL); + values.graphics_exposures = False; + XChangeGC(wi->dpy, wi->gc, GCGraphicsExposures, &values); + /* * Set the real top window above us. */ @@ -5332,16 +5789,19 @@ Event(ClientData client_data, /* Information about widget. */ while (!Tk_IsTopLevel(top_level)) { top_level = Tk_Parent(top_level); } - XQueryTree(wi->dpy, ZnWindowId(top_level), &root, &parent, + XQueryTree(wi->dpy, Tk_WindowId(top_level), &root, &parent, &children, &num_children); if (root == parent) { - wi->real_top = ZnWindowId(top_level); + wi->real_top = Tk_WindowId(top_level); } else { wi->real_top = parent; } - XFree((char *) children); + if (children) { + XFree(children); + } } + ZnNeedRedisplay(wi); } } else if (event->type == Expose) { @@ -5371,9 +5831,9 @@ Event(ClientData client_data, /* Information about widget. */ * schedule an asynchronous redisplay of the window * if we are done adding exposed parts. */ - AddBBoxToBBox(&wi->exposed_area, &bbox); + ZnAddBBoxToBBox(&wi->exposed_area, &bbox); if (/*(((XExposeEvent*) event)->count == 0) &&*/ - !IsEmptyBBox(&wi->exposed_area)) { + !ZnIsEmptyBBox(&wi->exposed_area)) { ZnNeedRedisplay(wi); } } @@ -5384,7 +5844,7 @@ Event(ClientData client_data, /* Information about widget. */ * need such change, it can bind a handler on . */ else if (event->type == ConfigureNotify) { - ZnDim int_width, int_height; + int int_width, int_height; ZnBBox bbox; int_width = Tk_Width(wi->win); @@ -5398,18 +5858,27 @@ Event(ClientData client_data, /* Information about widget. */ wi->opt_height = wi->height = int_height; ZnResetTransformStack(wi); + + SET(wi->flags, ZN_UPDATE_SCROLLBARS); + /* + * The call below is needed in order to recenter the view if + * it's confined and the scroll region is smaller than the + * window. + */ + SetOrigin(wi, wi->origin.x, wi->origin.y); + ZnDamage(wi, &bbox); - ITEM.Invalidate(wi->top_group, ZN_TRANSFO_FLAG); + ZnITEM.Invalidate(wi->top_group, ZN_TRANSFO_FLAG); /* * Reallocate the double buffer pixmap/image. */ if (!wi->render) { /*printf("reallocating double buffer\n");*/ - XFreePixmap(wi->dpy, wi->draw_buffer); - wi->draw_buffer = XCreatePixmap(wi->dpy, RootWindowOfScreen(wi->screen), - int_width, int_height, - DefaultDepthOfScreen(wi->screen)); + Tk_FreePixmap(wi->dpy, wi->draw_buffer); + wi->draw_buffer = Tk_GetPixmap(wi->dpy, RootWindowOfScreen(wi->screen), + int_width, int_height, + DefaultDepthOfScreen(wi->screen)); } } else { @@ -5421,7 +5890,7 @@ Event(ClientData client_data, /* Information about widget. */ bbox.orig.x = bbox.orig.y = 0; bbox.corner.x = Tk_Width(wi->win); bbox.corner.y = Tk_Height(wi->win); - AddBBoxToBBox(&wi->exposed_area, &bbox); + ZnAddBBoxToBBox(&wi->exposed_area, &bbox); } ZnNeedRedisplay(wi); } @@ -5433,10 +5902,10 @@ Event(ClientData client_data, /* Information about widget. */ else if (event->type == DestroyNotify) { if (wi->win != NULL) { wi->win = NULL; - wi->realized = False; + CLEAR(wi->flags, ZN_REALIZED); Tcl_DeleteCommandFromToken(wi->interp, wi->cmd); } - if (wi->update_pending) { + if (ISSET(wi->flags, ZN_UPDATE_PENDING)) { Tcl_CancelIdleCall(Redisplay, (ClientData) wi); } Tcl_EventuallyFree((ClientData) wi, Destroy); @@ -5471,18 +5940,18 @@ Event(ClientData client_data, /* Information about widget. */ *---------------------------------------------------------------------- */ static void -DoEvent(WidgetInfo *wi, - XEvent *event) +DoEvent(ZnWInfo *wi, + XEvent *event) { #define NUM_STATIC 4 - ClientData items[NUM_STATIC], *its; - static int worksize = 128; - static char *workspace = NULL; - int num, num_tags, i, len, ptr; - ClientData *tag_list = NULL; - Item item; - int part; - ZnBool bind_part, bind_item; + ClientData items[NUM_STATIC], *its; + static unsigned int worksize = 128, len, num, num_tags; + static char *workspace = NULL; + unsigned int i, ptr; + ClientData *tag_list = NULL; + ZnItem item; + int part; + ZnBool bind_part, bind_item; #define BIND_ITEM(test) \ if (bind_item && (test)) { \ @@ -5574,7 +6043,7 @@ DoEvent(WidgetInfo *wi, * Add here a binding for each tag suffixed by :part */ for (i = 0; i < num_tags; i++) { - len = strlen(tag_list[i])+ INTEGER_SPACE; + len = strlen(tag_list[i])+ TCL_INTEGER_SPACE; if (worksize < len) { worksize = len + 10; workspace = ZnRealloc(workspace, len); @@ -5596,7 +6065,7 @@ DoEvent(WidgetInfo *wi, * Invoke the binding system. */ if (wi->win != NULL) { - Tk_BindEvent(wi->binding_table, event, wi->win, num, its); + Tk_BindEvent(wi->binding_table, event, wi->win, (int) num, its); } if (its != items) { ZnFree(its); @@ -5631,7 +6100,7 @@ DoEvent(WidgetInfo *wi, *---------------------------------------------------------------------- */ static void -PickCurrentItem(WidgetInfo *wi, +PickCurrentItem(ZnWInfo *wi, XEvent *event) { int button_down; @@ -5645,7 +6114,7 @@ PickCurrentItem(WidgetInfo *wi, button_down = wi->state & (Button1Mask|Button2Mask|Button3Mask|Button4Mask|Button5Mask); if (!button_down) { - wi->events_flags &= ~LEFT_GRABBED_ITEM; + wi->flags &= ~ZN_LEFT_GRABBED_ITEM; } /* @@ -5690,7 +6159,7 @@ PickCurrentItem(WidgetInfo *wi, * Leave event handler for the old current item) then just return; * the pending call will do everything that's needed. */ - if (wi->events_flags & REPICK_IN_PROGRESS) { + if (wi->flags & ZN_REPICK_IN_PROGRESS) { fprintf(stderr, "PickCurrentItem recursive\n"); return; } @@ -5731,7 +6200,7 @@ PickCurrentItem(WidgetInfo *wi, wi->new_item==ZN_NO_ITEM?0:wi->new_item->id, wi->new_part);*/ if ((wi->new_item == wi->current_item) && (wi->new_part == wi->current_part) && - !(wi->events_flags & LEFT_GRABBED_ITEM)) { + !(wi->flags & ZN_LEFT_GRABBED_ITEM)) { /* * Nothing to do: the current item/part hasn't changed. */ @@ -5743,13 +6212,11 @@ PickCurrentItem(WidgetInfo *wi, * an EnterNotify event on the new current item. Remove the "current" * tag from the previous current item and place it on the new current * item. - * Note that the test for prev_left_grabbed_item is needed to prevent - * calling leave when the grab is released. */ if (((wi->new_item != wi->current_item) || (wi->new_part != wi->current_part)) && - (wi->current_item != ZN_NO_ITEM) && !(wi->events_flags & LEFT_GRABBED_ITEM)) { + (wi->current_item != ZN_NO_ITEM) && !(wi->flags & ZN_LEFT_GRABBED_ITEM)) { XEvent event; - Item item = wi->current_item; + ZnItem item = wi->current_item; event = wi->pick_event; event.type = LeaveNotify; @@ -5761,9 +6228,9 @@ PickCurrentItem(WidgetInfo *wi, * always use NotifyAncestor. */ event.xcrossing.detail = NotifyAncestor; - wi->events_flags |= REPICK_IN_PROGRESS; + wi->flags |= ZN_REPICK_IN_PROGRESS; DoEvent(wi, &event); - wi->events_flags &= ~REPICK_IN_PROGRESS; + wi->flags &= ~ZN_REPICK_IN_PROGRESS; /* * The check on item below is needed because there could be an @@ -5771,7 +6238,7 @@ PickCurrentItem(WidgetInfo *wi, */ if ((item == wi->current_item) && !button_down) { /*printf("^^^ Removing 'current' from %d\n", wi->current_item->id);*/ - ITEM.RemoveTag(item, current_uid); + ZnITEM.RemoveTag(item, current_uid); } /* * Note: during DoEvent above, it's possible that @@ -5781,16 +6248,16 @@ PickCurrentItem(WidgetInfo *wi, } if (((wi->new_item != wi->current_item) || (wi->new_part != wi->current_part)) && button_down) { - wi->events_flags |= LEFT_GRABBED_ITEM; + wi->flags |= ZN_LEFT_GRABBED_ITEM; return; } /* * Special note: it's possible that wi->new_item == wi->current_item - * here. This can happen, for example, if LEFT_GRABBED_ITEM was set or + * here. This can happen, for example, if ZN_LEFT_GRABBED_ITEM was set or * if there is only a change in the part number. */ - wi->events_flags &= ~LEFT_GRABBED_ITEM; + wi->flags &= ~ZN_LEFT_GRABBED_ITEM; /* * Tentative pour éviter d'enlever puis de remettre @@ -5799,18 +6266,18 @@ PickCurrentItem(WidgetInfo *wi, if (wi->current_item != wi->new_item) { if (wi->current_item != ZN_NO_ITEM) { printf("vvv Removing 'current' from %d\n", wi->current_item->id); - ITEM.RemoveTag(wi->current_item, current_uid); + ZnITEM.RemoveTag(wi->current_item, current_uid); } }*/ { - Item it = wi->current_item; + ZnItem it = wi->current_item; wi->current_item = wi->new_item; wi->current_part = wi->new_part; /* * Added to enable DoEvent to make a special case for enter/leaves * between fields in the same item. It may interact with - * LEFT_GRABBED_ITEM. + * ZN_LEFT_GRABBED_ITEM. */ wi->new_item = it; } @@ -5861,7 +6328,7 @@ static void Bind(ClientData client_data, /* Information about widget. */ XEvent *event) /* Information about event. */ { - WidgetInfo *wi = (WidgetInfo *) client_data; + ZnWInfo *wi = (ZnWInfo *) client_data; Tcl_Preserve((ClientData) wi); @@ -5931,7 +6398,7 @@ Bind(ClientData client_data, /* Information about widget. */ } else if ((event->type == EnterNotify) || (event->type == LeaveNotify)) { -#ifdef GLX_DAMAGE +#ifdef GL_DAMAGE /* * Kludge to prevent incorrect redrawing after * a move window when using GL. This code force @@ -5986,11 +6453,11 @@ done: static void LostSelection(ClientData client_data) { - WidgetInfo *wi = (WidgetInfo *) client_data; - TextInfo *ti = &wi->text_info; + ZnWInfo *wi = (ZnWInfo *) client_data; + ZnTextInfo *ti = &wi->text_info; if (ti->sel_item != ZN_NO_ITEM) { - ITEM.Invalidate(ti->sel_item, ZN_DRAW_FLAG); + ZnITEM.Invalidate(ti->sel_item, ZN_DRAW_FLAG); } ti->sel_item = ZN_NO_ITEM; ti->sel_field = ZN_NO_PART; @@ -6014,14 +6481,14 @@ LostSelection(ClientData client_data) *---------------------------------------------------------------------- */ static void -SelectTo(Item item, +SelectTo(ZnItem item, int field, int index) { - WidgetInfo *wi = item->wi; - TextInfo *ti = &wi->text_info; + ZnWInfo *wi = item->wi; + ZnTextInfo *ti = &wi->text_info; int old_first, old_last, old_field; - Item old_sel_item; + ZnItem old_sel_item; old_first = ti->sel_first; old_last = ti->sel_last; @@ -6035,7 +6502,7 @@ SelectTo(Item item, Tk_OwnSelection(wi->win, XA_PRIMARY, LostSelection, (ClientData) wi); } else if ((ti->sel_item != item) || (ti->sel_field != field)) { - ITEM.Invalidate(ti->sel_item, ZN_DRAW_FLAG); + ZnITEM.Invalidate(ti->sel_item, ZN_DRAW_FLAG); } ti->sel_item = item; ti->sel_field = field; @@ -6056,7 +6523,7 @@ SelectTo(Item item, if ((ti->sel_first != old_first) || (ti->sel_last != old_last) || (item != old_sel_item)) { - ITEM.Invalidate(item, ZN_DRAW_FLAG); + ZnITEM.Invalidate(item, ZN_DRAW_FLAG); } } @@ -6091,8 +6558,8 @@ FetchSelection( ClientData client_data, * at buffer, not including terminating * NULL character. */ { - WidgetInfo *wi = (WidgetInfo *) client_data; - TextInfo *ti = &wi->text_info; + ZnWInfo *wi = (ZnWInfo *) client_data; + ZnTextInfo *ti = &wi->text_info; if (ti->sel_item == ZN_NO_ITEM) { return -1; @@ -6125,7 +6592,7 @@ FetchSelection( ClientData client_data, static void CmdDeleted(ClientData client_data) /* Pointer to widget record for widget. */ { - WidgetInfo *wi = (WidgetInfo *) client_data; + ZnWInfo *wi = (ZnWInfo *) client_data; if (wi->win != NULL) { Tk_DestroyWindow(wi->win); @@ -6154,7 +6621,7 @@ CmdDeleted(ClientData client_data) /* Pointer to widget record for widget. */ static void Destroy(char *mem_ptr) /* Info about the widget. */ { - WidgetInfo *wi = (WidgetInfo *) mem_ptr; + ZnWInfo *wi = (ZnWInfo *) mem_ptr; unsigned int num; Tcl_HashSearch search; Tcl_HashEntry *entry; @@ -6180,19 +6647,19 @@ Destroy(char *mem_ptr) /* Info about the widget. */ */ /* Free all items. */ - fprintf(stderr, "Item count before cleanup: %d\n", wi->num_items); - ITEM.DestroyItem(wi->top_group); - fprintf(stderr, "Remaining item count: %d\n", wi->num_items); + /*fprintf(stderr, "Item count before cleanup: %d\n", wi->num_items);*/ + ZnITEM.DestroyItem(wi->top_group); + /*fprintf(stderr, "Remaining item count: %d\n", wi->num_items);*/ /* * Remove the redisplay scheduled by the cleanup. * It will fire when the widget will be gone and * will corrupt memory. */ - if (wi->update_pending) { + if (ISSET(wi->flags, ZN_UPDATE_PENDING)) { Tcl_CancelIdleCall(Redisplay, (ClientData) wi); } -#ifdef GLX +#ifdef GL if (wi->font_tfi) { ZnFreeTexFont(wi->font_tfi); } @@ -6208,7 +6675,7 @@ Destroy(char *mem_ptr) /* Info about the widget. */ Tk_FreeFont(wi->map_text_font); }*/ - for (num = 0; num < NUM_ALPHA_STEPS; num++) { + for (num = 0; num < ZN_NUM_ALPHA_STEPS; num++) { if (wi->alpha_stipples[num] != None) { Tk_FreeBitmap(wi->dpy, wi->alpha_stipples[num]); } @@ -6240,7 +6707,7 @@ Destroy(char *mem_ptr) /* Info about the widget. */ /* Free the double buffer pixmap/image */ if (wi->draw_buffer) { - XFreePixmap(wi->dpy, wi->draw_buffer); + Tk_FreePixmap(wi->dpy, wi->draw_buffer); } if (wi->fore_color) { @@ -6264,28 +6731,30 @@ Destroy(char *mem_ptr) /* Info about the widget. */ ZnFreeClipStack(wi); ZnListFree(wi->work_pts); -#ifdef GLX +#ifdef GL ZnListFree(wi->work_doubles); #endif ZnListFree(wi->work_xpts); ZnListFree(wi->work_strs); - FreeChrono(wi->total_draw_chrono); - FreeChrono(wi->this_draw_chrono); +#ifndef _WIN32 + ZnFreeChrono(wi->total_draw_chrono); + ZnFreeChrono(wi->this_draw_chrono); +#endif -#ifdef GLX - if (wi->render) { - if (wi->gl_context) { - glXDestroyContext(wi->dpy, wi->gl_context); - } - if (wi->gl_visual) { - XFree(wi->gl_visual); - } +#ifdef GL + if (wi->gl_context) { + ZnGLDestroyContext(wi); } +# ifndef _WIN32 + if (wi->gl_visual) { + XFree(wi->gl_visual); + } +# endif +#endif if (wi->tess) { gluDeleteTess(wi->tess); } -#endif ZnFree(wi); /*printf("Destroy ending\n");*/ @@ -6300,17 +6769,17 @@ Destroy(char *mem_ptr) /* Info about the widget. */ ********************************************************************************** */ void -ZnDamage(WidgetInfo *wi, +ZnDamage(ZnWInfo *wi, ZnBBox *damage) { - if ((damage == NULL) || IsEmptyBBox(damage)) { + if ((damage == NULL) || ZnIsEmptyBBox(damage)) { return; } /*printf("damaging area: %g %g %g %g\n", damage->orig.x, damage->orig.y, damage->corner.x, damage->corner.y);*/ - if (IsEmptyBBox(&wi->damaged_area)) { + if (ZnIsEmptyBBox(&wi->damaged_area)) { wi->damaged_area.orig.x = damage->orig.x; wi->damaged_area.orig.y = damage->orig.y; wi->damaged_area.corner.x = damage->corner.x; @@ -6329,7 +6798,7 @@ ZnDamage(WidgetInfo *wi, } static void -ClampDamageArea(WidgetInfo *wi) +ClampDamageArea(ZnWInfo *wi) { int width, height; @@ -6370,7 +6839,7 @@ ClampDamageArea(WidgetInfo *wi) ********************************************************************************** */ static void -Update(WidgetInfo *wi) +Update(ZnWInfo *wi) { /* * Give the overlap manager a chance to do its work. @@ -6402,31 +6871,31 @@ Update(WidgetInfo *wi) ********************************************************************************** */ static void -Repair(WidgetInfo *wi) +Repair(ZnWInfo *wi) { XGCValues values; - ZnPoint pts[2]; + ZnPoint p[5]; ZnTriStrip tristrip; -#ifdef GLX +#ifdef GL XColor *color; #endif - ZnReal int_width = Tk_Width(wi->win); - ZnReal int_height = Tk_Height(wi->win); + int int_width = Tk_Width(wi->win); + int int_height = Tk_Height(wi->win); if (wi->render) { -#ifdef GLX -#ifdef GLX_DAMAGE +#ifdef GL +#ifdef GL_DAMAGE ClampDamageArea(wi); /* * Merge the exposed area. */ - AddBBoxToBBox(&wi->damaged_area, &wi->exposed_area); - if (IsEmptyBBox(&wi->damaged_area)) { + ZnAddBBoxToBBox(&wi->damaged_area, &wi->exposed_area); + if (ZnIsEmptyBBox(&wi->damaged_area)) { return; } #endif - glXMakeCurrent(wi->dpy, ZnWindowId(wi->win), wi->gl_context); + ZnGLMakeCurrent(wi); glEnable(GL_POINT_SMOOTH); glEnable(GL_LINE_SMOOTH); #if 0 @@ -6438,9 +6907,9 @@ Repair(WidgetInfo *wi) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glClearStencil(0); - color = ZnGetGradientColor(wi->back_color, 0, NULL); - glClearColor(color->red/65536.0, color->green/65536.0, - color->blue/65536.0, 0.0); + color = ZnGetGradientColor(wi->back_color, 0.0, NULL); + glClearColor((GLfloat) color->red/65536, (GLfloat) color->green/65536, + (GLfloat) color->blue/65536, 0.0); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); @@ -6452,23 +6921,23 @@ Repair(WidgetInfo *wi) glViewport(0, 0, (GLsizei) int_width, int_height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - glOrtho(0.0, int_width, int_height, 0.0, -1.0, 1.0); + glOrtho(0.0, (GLfloat) int_width, (GLfloat) int_height, 0.0, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); -#ifdef GLX_DAMAGE +#ifdef GL_DAMAGE glEnable(GL_SCISSOR_TEST); /* * Set the damaged area as the scissor area. */ - wi->damaged_area.orig.x = REAL_TO_INT(wi->damaged_area.orig.x); - wi->damaged_area.orig.y = REAL_TO_INT(wi->damaged_area.orig.y); - wi->damaged_area.corner.x = REAL_TO_INT(wi->damaged_area.corner.x); - wi->damaged_area.corner.y = REAL_TO_INT(wi->damaged_area.corner.y); - glScissor(wi->damaged_area.orig.x, - int_height - wi->damaged_area.corner.y, - wi->damaged_area.corner.x - wi->damaged_area.orig.x, - wi->damaged_area.corner.y - wi->damaged_area.orig.y); + wi->damaged_area.orig.x = ZnNearestInt(wi->damaged_area.orig.x); + wi->damaged_area.orig.y = ZnNearestInt(wi->damaged_area.orig.y); + wi->damaged_area.corner.x = ZnNearestInt(wi->damaged_area.corner.x); + wi->damaged_area.corner.y = ZnNearestInt(wi->damaged_area.corner.y); + glScissor((int) wi->damaged_area.orig.x, + int_height - (int) wi->damaged_area.corner.y, + (int) (wi->damaged_area.corner.x - wi->damaged_area.orig.x), + (int) (wi->damaged_area.corner.y - wi->damaged_area.orig.y)); #else /* * We do not use the damaged area for GL rendering, @@ -6500,91 +6969,111 @@ Repair(WidgetInfo *wi) wi->top_group->class->Render(wi->top_group); if ((wi->border_width > 0) || (wi->highlight_width > 0)) { - int alpha; + unsigned short alpha; -#ifdef GLX_DAMAGE +#ifdef GL_DAMAGE glDisable(GL_SCISSOR_TEST); #endif if (wi->highlight_width > 0) { - color = ZnGetGradientColor(wi->got_focus?wi->highlight_color: - wi->highlight_bg_color, 0, &alpha); + color = ZnGetGradientColor(ISSET(wi->flags, ZN_GOT_FOCUS)?wi->highlight_color: + wi->highlight_bg_color, 0.0, &alpha); alpha = ZnComposeAlpha(alpha, 100); glColor4us(color->red, color->green, color->blue, alpha); glBegin(GL_QUAD_STRIP); - glVertex2f(0.0, 0.0); - glVertex2f(wi->highlight_width, wi->highlight_width); - glVertex2f(int_width, 0); - glVertex2f(int_width - wi->highlight_width, wi->highlight_width); - glVertex2f(int_width, int_height); - glVertex2f(int_width - wi->highlight_width, int_height - wi->highlight_width); - glVertex2f(0, int_height); - glVertex2f(wi->highlight_width, int_height - wi->highlight_width); - glVertex2f(0, 0); - glVertex2f(wi->highlight_width, wi->highlight_width); + glVertex2d(0.0, 0.0); + glVertex2i(wi->highlight_width, wi->highlight_width); + glVertex2i(int_width, 0); + glVertex2i(int_width - wi->highlight_width, wi->highlight_width); + glVertex2i(int_width, int_height); + glVertex2i(int_width - wi->highlight_width, int_height - wi->highlight_width); + glVertex2i(0, int_height); + glVertex2i(wi->highlight_width, int_height - wi->highlight_width); + glVertex2i(0, 0); + glVertex2i(wi->highlight_width, wi->highlight_width); glEnd(); } - if ((wi->border_width > 0) && (wi->relief != RELIEF_FLAT)) { - ZnPoint p[5]; - - p[4].x = p[4].y = p[3].y = p[1].x = wi->highlight_width; - p[0] = p[4]; - p[3].x = p[2].x = int_width - wi->highlight_width; - p[2].y = p[1].y = int_height - wi->highlight_width; - ZnRenderPolygonRelief(wi, wi->relief, wi->relief_grad, - False, p, 5, wi->border_width); - } -#ifdef GLX_DAMAGE + if (wi->border_width > 0) { + if (wi->relief != ZN_RELIEF_FLAT) { + p[4].x = p[4].y = p[3].y = p[1].x = wi->highlight_width; + p[0] = p[4]; + p[3].x = p[2].x = int_width - wi->highlight_width; + p[2].y = p[1].y = int_height - wi->highlight_width; + ZnRenderPolygonRelief(wi, wi->relief, wi->relief_grad, + False, p, 5, (ZnReal) wi->border_width); + } + else { + color = ZnGetGradientColor(wi->back_color, 0.0, &alpha); + alpha = ZnComposeAlpha(alpha, 100); + glColor4us(color->red, color->green, color->blue, alpha); + + glBegin(GL_QUAD_STRIP); + glVertex2d(0.0, 0.0); + glVertex2i(wi->highlight_width, wi->highlight_width); + glVertex2i(int_width, 0); + glVertex2i(int_width - wi->highlight_width, wi->highlight_width); + glVertex2i(int_width, int_height); + glVertex2i(int_width - wi->highlight_width, int_height - wi->highlight_width); + glVertex2i(0, int_height); + glVertex2i(wi->highlight_width, int_height - wi->highlight_width); + glVertex2i(0, 0); + glVertex2i(wi->highlight_width, wi->highlight_width); + glEnd(); + } + } +#ifdef GL_DAMAGE glEnable(GL_SCISSOR_TEST); #endif } - /* Switch the GL buffers. */ - glXSwapBuffers(wi->dpy, ZnWindowId(wi->win)); + glFlush(); + /* Switch the GL buffers. */ + ZnGLSwapBuffers(wi); + ZnGLRelease(wi); /* * Wait the end of GL update if we need to synchronize * to monitor perfs. */ - if (wi->monitoring) { - glXWaitGL(); + if (ISSET(wi->flags, ZN_MONITORING)) { + ZnGLWaitGL(); } #endif } else { - XRectangle r; + XRectangle r, rs[4]; ZnBBox merge; ClampDamageArea(wi); /* * Merge the damaged area with the exposed area. */ - ResetBBox(&merge); - CopyBBox(&wi->damaged_area, &merge); - AddBBoxToBBox(&merge, &wi->exposed_area); - if (!IsEmptyBBox(&merge)) { + ZnResetBBox(&merge); + ZnCopyBBox(&wi->damaged_area, &merge); + ZnAddBBoxToBBox(&merge, &wi->exposed_area); + if (!ZnIsEmptyBBox(&merge)) { /* Set the whole damaged area as clip rect. */ - wi->damaged_area.orig.x = r.x = REAL_TO_INT(wi->damaged_area.orig.x); - wi->damaged_area.orig.y = r.y = REAL_TO_INT(wi->damaged_area.orig.y); - wi->damaged_area.corner.x = REAL_TO_INT(wi->damaged_area.corner.x); - wi->damaged_area.corner.y = REAL_TO_INT(wi->damaged_area.corner.y); - r.width = wi->damaged_area.corner.x - wi->damaged_area.orig.x; - r.height = wi->damaged_area.corner.y - wi->damaged_area.orig.y; - pts[0] = wi->damaged_area.orig; - pts[1] = wi->damaged_area.corner; - TRI_STRIP1(&tristrip, pts, 2, False); + wi->damaged_area.orig.x = r.x = ZnNearestInt(wi->damaged_area.orig.x); + wi->damaged_area.orig.y = r.y = ZnNearestInt(wi->damaged_area.orig.y); + wi->damaged_area.corner.x = ZnNearestInt(wi->damaged_area.corner.x); + wi->damaged_area.corner.y = ZnNearestInt(wi->damaged_area.corner.y); + r.width = (unsigned short) (wi->damaged_area.corner.x - wi->damaged_area.orig.x); + r.height = (unsigned short) (wi->damaged_area.corner.y - wi->damaged_area.orig.y); + p[0] = wi->damaged_area.orig; + p[1] = wi->damaged_area.corner; + ZnTriStrip1(&tristrip, p, 2, False); ZnPushClip(wi, &tristrip, True, True); /* Fill the background of the double buffer pixmap. */ if (wi->tile == ZnUnspecifiedImage) { - values.foreground = ZnPixel(ZnGetGradientColor(wi->back_color, 0, NULL)); + values.foreground = ZnPixel(ZnGetGradientColor(wi->back_color, 0.0, NULL)); values.fill_style = FillSolid; XChangeGC(wi->dpy, wi->gc, GCFillStyle|GCForeground, &values); } else { values.fill_style = FillTiled; - values.tile = ZnImagePixmap(wi->tile, NULL); + values.tile = ZnImagePixmap(wi->tile); values.ts_x_origin = values.ts_y_origin = 0; XChangeGC(wi->dpy, wi->gc, GCFillStyle|GCTile|GCTileStipXOrigin|GCTileStipYOrigin, @@ -6606,49 +7095,69 @@ Repair(WidgetInfo *wi) merge.orig.y = MAX(merge.orig.y, wi->inset); merge.corner.x = MIN(merge.corner.x, int_width-wi->inset); merge.corner.y = MIN(merge.corner.y, int_height-wi->inset); - BBox2XRect(&merge, &r); + ZnBBox2XRect(&merge, &r); XCopyArea(wi->dpy, - wi->draw_buffer, ZnWindowId(wi->win), wi->gc, + wi->draw_buffer, Tk_WindowId(wi->win), wi->gc, r.x, r.y, r.width, r.height, r.x, r.y); } /* * Redraw the borders. */ - if ((wi->border_width > 0) && (wi->relief != RELIEF_FLAT)) { + if (wi->border_width > 0) { Pixmap save; - XRectangle r; save = wi->draw_buffer; - wi->draw_buffer = ZnWindowId(wi->win); - r.x = r.y = wi->highlight_width; - r.width = int_width - 2*wi->highlight_width; - r.height = int_height - 2*wi->highlight_width; - ZnDrawRectangleRelief(wi, wi->relief, wi->relief_grad, &r, wi->border_width); + wi->draw_buffer = Tk_WindowId(wi->win); + if (wi->relief_grad != ZN_RELIEF_FLAT) { + r.x = r.y = wi->highlight_width; + r.width = int_width - 2*wi->highlight_width; + r.height = int_height - 2*wi->highlight_width; + ZnDrawRectangleRelief(wi, wi->relief, wi->relief_grad, &r, + (ZnDim) wi->border_width); + } + else { + XSetForeground(wi->dpy, wi->gc, + ZnPixel(ZnGetGradientColor(wi->back_color, 0.0, NULL))); + XSetFillStyle(wi->dpy, wi->gc, FillSolid); + rs[0].x = rs[0].y = wi->highlight_width; + rs[0].width = int_width - 2*wi->highlight_width; + rs[0].height = wi->border_width; + rs[1].x = int_width - wi->highlight_width - wi->border_width; + rs[1].y = 0; + rs[1].width = wi->border_width; + rs[1].height = int_height - 2*wi->highlight_width; + rs[2].x = 0; + rs[2].y = int_height - wi->highlight_width - wi->border_width; + rs[2].width = rs[0].width; + rs[2].height = wi->border_width; + rs[3].x = rs[3].y = wi->highlight_width; + rs[3].width = wi->border_width; + rs[3].height = rs[1].height; + XFillRectangles(wi->dpy, Tk_WindowId(wi->win), wi->gc, rs, 4); + } wi->draw_buffer = save; } if (wi->highlight_width > 0) { - XRectangle r[4]; - XSetForeground(wi->dpy, wi->gc, - ZnPixel(ZnGetGradientColor(wi->got_focus?wi->highlight_color: - wi->highlight_bg_color, 0, NULL))); + ZnPixel(ZnGetGradientColor(ISSET(wi->flags, ZN_GOT_FOCUS)?wi->highlight_color: + wi->highlight_bg_color, 0.0, NULL))); XSetFillStyle(wi->dpy, wi->gc, FillSolid); - r[0].x = r[0].y = 0; - r[0].width = int_width; - r[0].height = wi->highlight_width; - r[1].x = int_width - wi->highlight_width; - r[1].y = 0; - r[1].width = wi->highlight_width; - r[1].height = int_height; - r[2].x = 0; - r[2].y = int_height - wi->highlight_width; - r[2].width = int_width; - r[2].height = wi->highlight_width; - r[3].x = r[3].y = 0; - r[3].width = wi->highlight_width; - r[3].height = int_height; - XFillRectangles(wi->dpy, ZnWindowId(wi->win), wi->gc, r, 4); + rs[0].x = rs[0].y = 0; + rs[0].width = int_width; + rs[0].height = wi->highlight_width; + rs[1].x = int_width - wi->highlight_width; + rs[1].y = 0; + rs[1].width = wi->highlight_width; + rs[1].height = int_height; + rs[2].x = 0; + rs[2].y = int_height - wi->highlight_width; + rs[2].width = int_width; + rs[2].height = wi->highlight_width; + rs[3].x = rs[3].y = 0; + rs[3].width = wi->highlight_width; + rs[3].height = int_height; + XFillRectangles(wi->dpy, Tk_WindowId(wi->win), wi->gc, rs, 4); } } } @@ -6675,17 +7184,19 @@ Repair(WidgetInfo *wi) static void Redisplay(ClientData client_data) /* Information about the widget. */ { - WidgetInfo *wi = (WidgetInfo *) client_data; + ZnWInfo *wi = (ZnWInfo *) client_data; - wi->update_pending = 0; - if (!wi->realized || !Tk_IsMapped(wi->win)) { + CLEAR(wi->flags, ZN_UPDATE_PENDING); + if (ISCLEAR(wi->flags, ZN_REALIZED) || !Tk_IsMapped(wi->win)) { return; } - if (wi->monitoring) { - XStartChrono(wi->total_draw_chrono, wi->dpy, ZnWindowId(wi->win)); - ResetChronos(wi->this_draw_chrono); - XStartChrono(wi->this_draw_chrono, wi->dpy, ZnWindowId(wi->win)); + if (ISSET(wi->flags, ZN_MONITORING)) { +#ifndef _WIN32 + ZnXStartChrono(wi->total_draw_chrono, wi->dpy, Tk_WindowId(wi->win)); + ZnResetChronos(wi->this_draw_chrono); + ZnXStartChrono(wi->this_draw_chrono, wi->dpy, Tk_WindowId(wi->win)); +#endif } do { @@ -6703,11 +7214,11 @@ Redisplay(ClientData client_data) /* Information about the widget. */ * lead to the widget destruction, this is the reason * for Tcl_Preserve/Tcl_Release. */ - if (ISSET(wi->events_flags, INTERNAL_NEED_REPICK)) { + if (ISSET(wi->flags, ZN_INTERNAL_NEED_REPICK)) { Tk_Window tkwin; Tcl_Preserve((ClientData) wi); - CLEAR(wi->events_flags, INTERNAL_NEED_REPICK); + CLEAR(wi->flags, ZN_INTERNAL_NEED_REPICK); PickCurrentItem(wi, &wi->pick_event); tkwin = wi->win; Tcl_Release((ClientData) wi); @@ -6718,7 +7229,7 @@ Redisplay(ClientData client_data) /* Information about the widget. */ } while (ISSET(wi->top_group->inv_flags, ZN_COORDS_FLAG) || ISSET(wi->top_group->inv_flags, ZN_TRANSFO_FLAG) || - ISSET(wi->events_flags, INTERNAL_NEED_REPICK)); + ISSET(wi->flags, ZN_INTERNAL_NEED_REPICK)); /* * Repair the scene where it is no longer up to date, @@ -6729,12 +7240,18 @@ Redisplay(ClientData client_data) /* Information about the widget. */ /* * Reset the exposed & damaged areas. */ - ResetBBox(&wi->exposed_area); - ResetBBox(&wi->damaged_area); + ZnResetBBox(&wi->exposed_area); + ZnResetBBox(&wi->damaged_area); - if (wi->monitoring) { - XStopChrono(wi->total_draw_chrono, wi->dpy, ZnWindowId(wi->win)); - XStopChrono(wi->this_draw_chrono, wi->dpy, ZnWindowId(wi->win)); + if (ISSET(wi->flags, ZN_MONITORING)) { +#ifndef _WIN32 + ZnXStopChrono(wi->total_draw_chrono, wi->dpy, Tk_WindowId(wi->win)); + ZnXStopChrono(wi->this_draw_chrono, wi->dpy, Tk_WindowId(wi->win)); +#endif + } + + if (ISSET(wi->flags, ZN_UPDATE_SCROLLBARS)) { + UpdateScrollbars(wi); } } @@ -6743,7 +7260,7 @@ static void InitZinc(Tcl_Interp *interp) { static ZnBool inited = False; unsigned int i, x, y, bit; - char name[INTEGER_SPACE + 20]; + char name[TCL_INTEGER_SPACE + 20]; if (inited) { return; @@ -6758,7 +7275,7 @@ InitZinc(Tcl_Interp *interp) { SYMBOLS_BITS[i], SYMBOL_WIDTH, SYMBOL_HEIGHT); } - for (i = 0; i < NUM_ALPHA_STEPS; i++) { + for (i = 0; i < ZN_NUM_ALPHA_STEPS; i++) { for (y = 0; y < 4; y++) { bitmaps[i][y][0] = 0; for (x = 0; x < 4; x++) { @@ -6816,6 +7333,10 @@ InitZinc(Tcl_Interp *interp) { inited = True; } +#ifdef BUILD_Tkzinc +# undef TCL_STORAGE_CLASS +# define TCL_STORAGE_CLASS DLLEXPORT +#endif /* *---------------------------------------------------------------------- @@ -6827,41 +7348,39 @@ InitZinc(Tcl_Interp *interp) { * *---------------------------------------------------------------------- */ -int +EXTERN int Tkzinc_Init(Tcl_Interp *interp) /* Used for error reporting. */ { +#ifndef PTK if ( -#ifdef USE_TCL_STUBS - Tcl_InitStubs(interp, "8.2", 0) -#else - Tcl_PkgRequire(interp, "Tcl", "8.2", 0) -#endif - == NULL) { +# ifdef USE_TCL_STUBS + Tcl_InitStubs(interp, "8.4", 0) +# else + Tcl_PkgRequire(interp, "Tcl", "8.4", 0) +# endif + == NULL) { return TCL_ERROR; } + if ( -#ifdef USE_TK_STUBS - Tk_InitStubs(interp, "8.2", 0) -#else - Tcl_PkgRequire(interp, "Tk", "8.2", 0) -#endif - == NULL) { +# ifdef USE_TK_STUBS + Tk_InitStubs(interp, "8.4", 0) +# else + Tcl_PkgRequire(interp, "Tk", "8.4", 0) +# endif + == NULL) { return TCL_ERROR; } - +#endif /* * Create additional commands */ - if (Tcl_PkgProvide(interp, "Tkzinc", "3.2") == ZN_ERROR) { - return ZN_ERROR; - } - Tcl_CreateObjCommand(interp, "zinc", ZincObjCmd, (ClientData) Tk_MainWindow(interp), (Tcl_CmdDeleteProc *) NULL); - Tcl_CreateObjCommand(interp, "mapinfo", MapInfoObjCmd, + Tcl_CreateObjCommand(interp, "mapinfo", ZnMapInfoObjCmd, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); - Tcl_CreateObjCommand(interp, "videomap", VideomapObjCmd, + Tcl_CreateObjCommand(interp, "videomap", ZnVideomapObjCmd, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); /* @@ -6869,11 +7388,45 @@ Tkzinc_Init(Tcl_Interp *interp) /* Used for error reporting. */ */ OmInit(); +#ifndef PTK + if (Tcl_PkgProvide(interp, "Tkzinc", VERSION) == TCL_ERROR) { + return TCL_ERROR; + } +#endif + return TCL_OK; } -int +EXTERN int Tkzinc_debug_Init(Tcl_Interp *interp) /* Used for error reporting. */ { return Tkzinc_Init(interp); } + +#ifdef _WIN32 +/* + *---------------------------------------------------------------------- + * + * DllEntryPoint -- + * + * This wrapper function is used by Windows to invoke the + * initialization code for the DLL. If we are compiling + * with Visual C++, this routine will be renamed to DllMain. + * routine. + * + * Results: + * Returns TRUE; + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ +BOOL APIENTRY +DllEntryPoint(HINSTANCE hInst __unused, /* Library instance handle. */ + DWORD reason __unused, /* Reason this function is being called. */ + LPVOID reserved __unused) /* Not used. */ +{ + return TRUE; +} +#endif diff --git a/generic/tkZinc.h b/generic/tkZinc.h index 1d696dc..d2d7ba1 100644 --- a/generic/tkZinc.h +++ b/generic/tkZinc.h @@ -35,17 +35,17 @@ #include "List.h" #include "MapInfo.h" -typedef struct _TagSearch { - WidgetInfo *wi; - Item current; /* Pointer to last item returned. */ - Item previous; /* The item right before the current +typedef struct _ZnTagSearch { + ZnWInfo *wi; + ZnItem current; /* Pointer to last item returned. */ + ZnItem previous; /* The item right before the current * is tracked so if the current is * deleted we don't have to start from the * beginning. */ ZnBool over; /* Non-zero means NextItem should always * return NULL. */ int type; /* search type */ - int id; /* item id for searches by id */ + long id; /* item id for searches by id */ Tk_Uid tag; /* tag expression string */ int tag_index; /* current position in string scan */ @@ -54,26 +54,21 @@ typedef struct _TagSearch { char *rewrite_buf; /* tag string (after removing escapes) */ unsigned int rewrite_buf_alloc; /* available space for rewrites */ - struct _TagSearchExpr *expr; /* compiled tag expression */ - Item group; + struct _TagSearchExpr *expr; /* compiled tag expression */ + ZnItem group; ZnBool recursive; ZnList item_stack; -} TagSearch; +} ZnTagSearch; -#define NewLongObj Tcl_NewLongObj -#define NewBooleanObj Tcl_NewBooleanObj -#define NewDoubleObj Tcl_NewDoubleObj -Tcl_Obj *NewStringObj(CONST char *val); -void SetStringObj(Tcl_Obj *o, char *val); -int ZnParseCoordList(WidgetInfo *wi, Tcl_Obj *arg, ZnPoint **pts, - char **controls, int *num_pts, ZnBool *old_format); -int ZnItemWithTagOrId(WidgetInfo *wi, Tcl_Obj *tag_or_id, - Item *item, TagSearch **search_var); -void ZnTagSearchDestroy(TagSearch *search); -void ZnDoItem(Tcl_Interp *interp, Item item, int part, Tk_Uid tag_uid); -void ZnNeedRedisplay(WidgetInfo *wi); -void ZnDamage(WidgetInfo *wi, ZnBBox *damage); +int ZnParseCoordList(ZnWInfo *wi, Tcl_Obj *arg, ZnPoint **pts, + char **controls, unsigned int *num_pts, ZnBool *old_format); +int ZnItemWithTagOrId(ZnWInfo *wi, Tcl_Obj *tag_or_id, + ZnItem *item, ZnTagSearch **search_var); +void ZnTagSearchDestroy(ZnTagSearch *search); +void ZnDoItem(Tcl_Interp *interp, ZnItem item, int part, Tk_Uid tag_uid); +void ZnNeedRedisplay(ZnWInfo *wi); +void ZnDamage(ZnWInfo *wi, ZnBBox *damage); #endif /* _tkZinc_h */ diff --git a/generic/version.c b/generic/version.c deleted file mode 100644 index 4821719..0000000 --- a/generic/version.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * version.c -- version string. - * - * Authors : Patrick Lecoanet. - * Creation date : Mon Feb 1 12:13:24 1999 - * - * $Id$ - */ - -/* - * Copyright (c) 1993 - 1999 CENA, Patrick Lecoanet -- - * - * This code is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This code is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this code; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - - -#include "patchlvl.h" - -static const char rcs_id[] = "$PatchLevel: " ZINCVERSION " " __DATE__ " " __TIME__ " $"; -const char * const zinc_version = ZINCVERSION; -- cgit v1.1