diff options
Diffstat (limited to 'generic/tkCanvPoly.c')
-rw-r--r-- | generic/tkCanvPoly.c | 907 |
1 files changed, 455 insertions, 452 deletions
diff --git a/generic/tkCanvPoly.c b/generic/tkCanvPoly.c index 060044e..031b0a3 100644 --- a/generic/tkCanvPoly.c +++ b/generic/tkCanvPoly.c @@ -1,4 +1,4 @@ -/* +/* * tkCanvPoly.c -- * * This file implements polygon items for canvas widgets. @@ -7,10 +7,10 @@ * Copyright (c) 1994-1997 Sun Microsystems, Inc. * Copyright (c) 1998-2000 Ajuba Solutions. * - * See the file "license.terms" for information on usage and redistribution - * of this file, and for a DISCLAIMER OF ALL WARRANTIES. + * See the file "license.terms" for information on usage and redistribution of + * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkCanvPoly.c,v 1.13 2005/08/10 22:02:22 dkf Exp $ + * RCS: @(#) $Id: tkCanvPoly.c,v 1.14 2005/11/04 15:23:05 dkf Exp $ */ #include <stdio.h> @@ -24,24 +24,28 @@ typedef struct PolygonItem { Tk_Item header; /* Generic stuff that's the same for all - * types. MUST BE FIRST IN STRUCTURE. */ + * types. MUST BE FIRST IN STRUCTURE. */ Tk_Outline outline; /* Outline structure */ - int numPoints; /* Number of points in polygon. - * Polygon is always closed. */ + int numPoints; /* Number of points in polygon. Polygon is + * always closed. */ int pointsAllocated; /* Number of points for which space is * allocated at *coordPtr. */ - double *coordPtr; /* Pointer to malloc-ed array containing - * x- and y-coords of all points in polygon. + double *coordPtr; /* Pointer to malloc-ed array containing x- + * and y-coords of all points in polygon. * X-coords are even-valued indices, y-coords * are corresponding odd-valued indices. */ int joinStyle; /* Join style for outline */ Tk_TSOffset tsoffset; XColor *fillColor; /* Foreground color for polygon. */ - XColor *activeFillColor; /* Foreground color for polygon if state is active. */ - XColor *disabledFillColor; /* Foreground color for polygon if state is disabled. */ + XColor *activeFillColor; /* Foreground color for polygon if state is + * active. */ + XColor *disabledFillColor; /* Foreground color for polygon if state is + * disabled. */ Pixmap fillStipple; /* Stipple bitmap for filling polygon. */ - Pixmap activeFillStipple; /* Stipple bitmap for filling polygon if state is active. */ - Pixmap disabledFillStipple; /* Stipple bitmap for filling polygon if state is disabled. */ + Pixmap activeFillStipple; /* Stipple bitmap for filling polygon if state + * is active. */ + Pixmap disabledFillStipple; /* Stipple bitmap for filling polygon if state + * is disabled. */ GC fillGC; /* Graphics context for filling polygon. */ Tk_SmoothMethod *smooth; /* Non-zero means draw shape smoothed (i.e. * with Bezier splines). */ @@ -81,125 +85,116 @@ static Tk_CustomOption pixelOption = { }; static Tk_ConfigSpec configSpecs[] = { - {TK_CONFIG_CUSTOM, "-activedash", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(PolygonItem, outline.activeDash), + {TK_CONFIG_CUSTOM, "-activedash", NULL, NULL, + NULL, Tk_Offset(PolygonItem, outline.activeDash), TK_CONFIG_NULL_OK, &dashOption}, - {TK_CONFIG_COLOR, "-activefill", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(PolygonItem, activeFillColor), - TK_CONFIG_NULL_OK}, - {TK_CONFIG_COLOR, "-activeoutline", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(PolygonItem, outline.activeColor), - TK_CONFIG_NULL_OK}, - {TK_CONFIG_BITMAP, "-activeoutlinestipple", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(PolygonItem, outline.activeStipple), + {TK_CONFIG_COLOR, "-activefill", NULL, NULL, + NULL, Tk_Offset(PolygonItem, activeFillColor), TK_CONFIG_NULL_OK}, + {TK_CONFIG_COLOR, "-activeoutline", NULL, NULL, + NULL, Tk_Offset(PolygonItem, outline.activeColor), TK_CONFIG_NULL_OK}, + {TK_CONFIG_BITMAP, "-activeoutlinestipple", NULL, NULL, + NULL, Tk_Offset(PolygonItem, outline.activeStipple), TK_CONFIG_NULL_OK}, - {TK_CONFIG_BITMAP, "-activestipple", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(PolygonItem, activeFillStipple), - TK_CONFIG_NULL_OK}, - {TK_CONFIG_CUSTOM, "-activewidth", (char *) NULL, (char *) NULL, + {TK_CONFIG_BITMAP, "-activestipple", NULL, NULL, + NULL, Tk_Offset(PolygonItem, activeFillStipple), TK_CONFIG_NULL_OK}, + {TK_CONFIG_CUSTOM, "-activewidth", NULL, NULL, "0.0", Tk_Offset(PolygonItem, outline.activeWidth), TK_CONFIG_DONT_SET_DEFAULT, &pixelOption}, - {TK_CONFIG_CUSTOM, "-dash", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(PolygonItem, outline.dash), + {TK_CONFIG_CUSTOM, "-dash", NULL, NULL, + NULL, Tk_Offset(PolygonItem, outline.dash), TK_CONFIG_NULL_OK, &dashOption}, - {TK_CONFIG_PIXELS, "-dashoffset", (char *) NULL, (char *) NULL, + {TK_CONFIG_PIXELS, "-dashoffset", NULL, NULL, "0", Tk_Offset(PolygonItem, outline.offset), TK_CONFIG_DONT_SET_DEFAULT}, - {TK_CONFIG_CUSTOM, "-disableddash", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(PolygonItem, outline.disabledDash), + {TK_CONFIG_CUSTOM, "-disableddash", NULL, NULL, + NULL, Tk_Offset(PolygonItem, outline.disabledDash), TK_CONFIG_NULL_OK, &dashOption}, - {TK_CONFIG_COLOR, "-disabledfill", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(PolygonItem, disabledFillColor), - TK_CONFIG_NULL_OK}, - {TK_CONFIG_COLOR, "-disabledoutline", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(PolygonItem, outline.disabledColor), + {TK_CONFIG_COLOR, "-disabledfill", NULL, NULL, + NULL, Tk_Offset(PolygonItem, disabledFillColor), TK_CONFIG_NULL_OK}, + {TK_CONFIG_COLOR, "-disabledoutline", NULL, NULL, + NULL, Tk_Offset(PolygonItem, outline.disabledColor), TK_CONFIG_NULL_OK}, - {TK_CONFIG_BITMAP, "-disabledoutlinestipple", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(PolygonItem, outline.disabledStipple), + {TK_CONFIG_BITMAP, "-disabledoutlinestipple", NULL, NULL, + NULL, Tk_Offset(PolygonItem, outline.disabledStipple), TK_CONFIG_NULL_OK}, - {TK_CONFIG_BITMAP, "-disabledstipple", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(PolygonItem, disabledFillStipple), - TK_CONFIG_NULL_OK}, - {TK_CONFIG_CUSTOM, "-disabledwidth", (char *) NULL, (char *) NULL, + {TK_CONFIG_BITMAP, "-disabledstipple", NULL, NULL, + NULL, Tk_Offset(PolygonItem, disabledFillStipple), TK_CONFIG_NULL_OK}, + {TK_CONFIG_CUSTOM, "-disabledwidth", NULL, NULL, "0.0", Tk_Offset(PolygonItem, outline.disabledWidth), TK_CONFIG_DONT_SET_DEFAULT, &pixelOption}, - {TK_CONFIG_COLOR, "-fill", (char *) NULL, (char *) NULL, + {TK_CONFIG_COLOR, "-fill", NULL, NULL, "black", Tk_Offset(PolygonItem, fillColor), TK_CONFIG_NULL_OK}, - {TK_CONFIG_JOIN_STYLE, "-joinstyle", (char *) NULL, (char *) NULL, + {TK_CONFIG_JOIN_STYLE, "-joinstyle", NULL, NULL, "round", Tk_Offset(PolygonItem, joinStyle), TK_CONFIG_DONT_SET_DEFAULT}, - {TK_CONFIG_CUSTOM, "-offset", (char *) NULL, (char *) NULL, + {TK_CONFIG_CUSTOM, "-offset", NULL, NULL, "0,0", Tk_Offset(PolygonItem, tsoffset), TK_CONFIG_NULL_OK, &offsetOption}, - {TK_CONFIG_COLOR, "-outline", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(PolygonItem, outline.color), - TK_CONFIG_NULL_OK}, - {TK_CONFIG_CUSTOM, "-outlineoffset", (char *) NULL, (char *) NULL, + {TK_CONFIG_COLOR, "-outline", NULL, NULL, + NULL, Tk_Offset(PolygonItem, outline.color), TK_CONFIG_NULL_OK}, + {TK_CONFIG_CUSTOM, "-outlineoffset", NULL, NULL, "0,0", Tk_Offset(PolygonItem, outline.tsoffset), TK_CONFIG_NULL_OK, &offsetOption}, - {TK_CONFIG_BITMAP, "-outlinestipple", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(PolygonItem, outline.stipple), - TK_CONFIG_NULL_OK}, - {TK_CONFIG_CUSTOM, "-smooth", (char *) NULL, (char *) NULL, + {TK_CONFIG_BITMAP, "-outlinestipple", NULL, NULL, + NULL, Tk_Offset(PolygonItem, outline.stipple), TK_CONFIG_NULL_OK}, + {TK_CONFIG_CUSTOM, "-smooth", NULL, NULL, "0", Tk_Offset(PolygonItem, smooth), TK_CONFIG_DONT_SET_DEFAULT, &smoothOption}, - {TK_CONFIG_INT, "-splinesteps", (char *) NULL, (char *) NULL, + {TK_CONFIG_INT, "-splinesteps", NULL, NULL, "12", Tk_Offset(PolygonItem, splineSteps), TK_CONFIG_DONT_SET_DEFAULT}, - {TK_CONFIG_CUSTOM, "-state", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(Tk_Item, state), TK_CONFIG_NULL_OK, - &stateOption}, - {TK_CONFIG_BITMAP, "-stipple", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(PolygonItem, fillStipple), TK_CONFIG_NULL_OK}, - {TK_CONFIG_CUSTOM, "-tags", (char *) NULL, (char *) NULL, - (char *) NULL, 0, TK_CONFIG_NULL_OK, &tagsOption}, - {TK_CONFIG_CUSTOM, "-width", (char *) NULL, (char *) NULL, + {TK_CONFIG_CUSTOM, "-state", NULL, NULL, + NULL, Tk_Offset(Tk_Item, state), TK_CONFIG_NULL_OK, &stateOption}, + {TK_CONFIG_BITMAP, "-stipple", NULL, NULL, + NULL, Tk_Offset(PolygonItem, fillStipple), TK_CONFIG_NULL_OK}, + {TK_CONFIG_CUSTOM, "-tags", NULL, NULL, + NULL, 0, TK_CONFIG_NULL_OK, &tagsOption}, + {TK_CONFIG_CUSTOM, "-width", NULL, NULL, "1.0", Tk_Offset(PolygonItem, outline.width), TK_CONFIG_DONT_SET_DEFAULT, &pixelOption}, - {TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL, - (char *) NULL, 0, 0} + {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0} }; /* - * Prototypes for procedures defined in this file: + * Prototypes for functions defined in this file: */ -static void ComputePolygonBbox _ANSI_ARGS_((Tk_Canvas canvas, - PolygonItem *polyPtr)); -static int ConfigurePolygon _ANSI_ARGS_((Tcl_Interp *interp, +static void ComputePolygonBbox(Tk_Canvas canvas, + PolygonItem *polyPtr); +static int ConfigurePolygon(Tcl_Interp *interp, Tk_Canvas canvas, Tk_Item *itemPtr, int objc, - Tcl_Obj *CONST objv[], int flags)); -static int CreatePolygon _ANSI_ARGS_((Tcl_Interp *interp, + Tcl_Obj *CONST objv[], int flags); +static int CreatePolygon(Tcl_Interp *interp, Tk_Canvas canvas, struct Tk_Item *itemPtr, - int objc, Tcl_Obj *CONST objv[])); -static void DeletePolygon _ANSI_ARGS_((Tk_Canvas canvas, - Tk_Item *itemPtr, Display *display)); -static void DisplayPolygon _ANSI_ARGS_((Tk_Canvas canvas, + int objc, Tcl_Obj *CONST objv[]); +static void DeletePolygon(Tk_Canvas canvas, + Tk_Item *itemPtr, Display *display); +static void DisplayPolygon(Tk_Canvas canvas, Tk_Item *itemPtr, Display *display, Drawable dst, - int x, int y, int width, int height)); -static int GetPolygonIndex _ANSI_ARGS_((Tcl_Interp *interp, + int x, int y, int width, int height); +static int GetPolygonIndex(Tcl_Interp *interp, Tk_Canvas canvas, Tk_Item *itemPtr, - Tcl_Obj *obj, int *indexPtr)); -static int PolygonCoords _ANSI_ARGS_((Tcl_Interp *interp, + Tcl_Obj *obj, int *indexPtr); +static int PolygonCoords(Tcl_Interp *interp, Tk_Canvas canvas, Tk_Item *itemPtr, - int objc, Tcl_Obj *CONST objv[])); -static void PolygonDeleteCoords _ANSI_ARGS_((Tk_Canvas canvas, - Tk_Item *itemPtr, int first, int last)); -static void PolygonInsert _ANSI_ARGS_((Tk_Canvas canvas, - Tk_Item *itemPtr, int beforeThis, Tcl_Obj *obj)); -static int PolygonToArea _ANSI_ARGS_((Tk_Canvas canvas, - Tk_Item *itemPtr, double *rectPtr)); -static double PolygonToPoint _ANSI_ARGS_((Tk_Canvas canvas, - Tk_Item *itemPtr, double *pointPtr)); -static int PolygonToPostscript _ANSI_ARGS_((Tcl_Interp *interp, - Tk_Canvas canvas, Tk_Item *itemPtr, int prepass)); -static void ScalePolygon _ANSI_ARGS_((Tk_Canvas canvas, + int objc, Tcl_Obj *CONST objv[]); +static void PolygonDeleteCoords(Tk_Canvas canvas, + Tk_Item *itemPtr, int first, int last); +static void PolygonInsert(Tk_Canvas canvas, + Tk_Item *itemPtr, int beforeThis, Tcl_Obj *obj); +static int PolygonToArea(Tk_Canvas canvas, + Tk_Item *itemPtr, double *rectPtr); +static double PolygonToPoint(Tk_Canvas canvas, + Tk_Item *itemPtr, double *pointPtr); +static int PolygonToPostscript(Tcl_Interp *interp, + Tk_Canvas canvas, Tk_Item *itemPtr, int prepass); +static void ScalePolygon(Tk_Canvas canvas, Tk_Item *itemPtr, double originX, double originY, - double scaleX, double scaleY)); -static void TranslatePolygon _ANSI_ARGS_((Tk_Canvas canvas, - Tk_Item *itemPtr, double deltaX, double deltaY)); + double scaleX, double scaleY); +static void TranslatePolygon(Tk_Canvas canvas, + Tk_Item *itemPtr, double deltaX, double deltaY); /* - * The structures below defines the polygon item type by means - * of procedures that can be invoked by generic item code. + * The structures below defines the polygon item type by means of functions + * that can be invoked by generic item code. */ Tk_ItemType tkPolygonType = { @@ -218,17 +213,17 @@ Tk_ItemType tkPolygonType = { ScalePolygon, /* scaleProc */ TranslatePolygon, /* translateProc */ (Tk_ItemIndexProc *) GetPolygonIndex,/* indexProc */ - (Tk_ItemCursorProc *) NULL, /* icursorProc */ - (Tk_ItemSelectionProc *) NULL, /* selectionProc */ + NULL, /* icursorProc */ + NULL, /* selectionProc */ (Tk_ItemInsertProc *) PolygonInsert,/* insertProc */ PolygonDeleteCoords, /* dTextProc */ - (Tk_ItemType *) NULL, /* nextPtr */ + NULL, /* nextPtr */ }; /* - * The definition below determines how large are static arrays - * used to hold spline points (splines larger than this have to - * have their arrays malloc-ed). + * The definition below determines how large are static arrays used to hold + * spline points (splines larger than this have to have their arrays + * malloc-ed). */ #define MAX_STATIC_POINTS 200 @@ -238,14 +233,12 @@ Tk_ItemType tkPolygonType = { * * CreatePolygon -- * - * This procedure is invoked to create a new polygon item in - * a canvas. + * This function is invoked to create a new polygon item in a canvas. * * Results: - * A standard Tcl return value. If an error occurred in - * creating the item, then an error message is left in - * the interp's result; in this case itemPtr is - * left uninitialized, so it can be safely freed by the + * A standard Tcl return value. If an error occurred in creating the + * item, then an error message is left in the interp's result; in this + * case itemPtr is left uninitialized, so it can be safely freed by the * caller. * * Side effects: @@ -255,13 +248,13 @@ Tk_ItemType tkPolygonType = { */ static int -CreatePolygon(interp, canvas, itemPtr, objc, objv) - Tcl_Interp *interp; /* Interpreter for error reporting. */ - Tk_Canvas canvas; /* Canvas to hold new item. */ - Tk_Item *itemPtr; /* Record to hold new item; header - * has been initialized by caller. */ - int objc; /* Number of arguments in objv. */ - Tcl_Obj *CONST objv[]; /* Arguments describing polygon. */ +CreatePolygon( + Tcl_Interp *interp, /* Interpreter for error reporting. */ + Tk_Canvas canvas, /* Canvas to hold new item. */ + Tk_Item *itemPtr, /* Record to hold new item; header has been + * initialized by caller. */ + int objc, /* Number of arguments in objv. */ + Tcl_Obj *CONST objv[]) /* Arguments describing polygon. */ { PolygonItem *polyPtr = (PolygonItem *) itemPtr; int i; @@ -271,8 +264,8 @@ CreatePolygon(interp, canvas, itemPtr, objc, objv) } /* - * Carry out initialization that is needed in order to clean - * up after errors during the the remainder of this procedure. + * Carry out initialization that is needed in order to clean up after + * errors during the the remainder of this function. */ Tk_CreateOutline(&(polyPtr->outline)); @@ -290,14 +283,14 @@ CreatePolygon(interp, canvas, itemPtr, objc, objv) polyPtr->activeFillStipple = None; polyPtr->disabledFillStipple = None; polyPtr->fillGC = None; - polyPtr->smooth = (Tk_SmoothMethod *) NULL; + polyPtr->smooth = NULL; polyPtr->splineSteps = 12; polyPtr->autoClosed = 0; /* - * Count the number of points and then parse them into a point - * array. Leading arguments are assumed to be points if they - * start with a digit or a minus sign followed by a digit. + * Count the number of points and then parse them into a point array. + * Leading arguments are assumed to be points if they start with a digit + * or a minus sign followed by a digit. */ for (i = 0; i < objc; i++) { @@ -315,7 +308,7 @@ CreatePolygon(interp, canvas, itemPtr, objc, objv) return TCL_OK; } - error: + error: DeletePolygon(canvas, itemPtr, Tk_Display(Tk_CanvasTkwin(canvas))); return TCL_ERROR; } @@ -325,9 +318,8 @@ CreatePolygon(interp, canvas, itemPtr, objc, objv) * * PolygonCoords -- * - * This procedure is invoked to process the "coords" widget - * command on polygons. See the user documentation for details - * on what it does. + * This function is invoked to process the "coords" widget command on + * polygons. See the user documentation for details on what it does. * * Results: * Returns TCL_OK or TCL_ERROR, and sets the interp's result. @@ -339,25 +331,25 @@ CreatePolygon(interp, canvas, itemPtr, objc, objv) */ static int -PolygonCoords(interp, canvas, itemPtr, objc, objv) - Tcl_Interp *interp; /* Used for error reporting. */ - Tk_Canvas canvas; /* Canvas containing item. */ - Tk_Item *itemPtr; /* Item whose coordinates are to be - * read or modified. */ - int objc; /* Number of coordinates supplied in - * objv. */ - Tcl_Obj *CONST objv[]; /* Array of coordinates: x1, y1, - * x2, y2, ... */ +PolygonCoords( + Tcl_Interp *interp, /* Used for error reporting. */ + Tk_Canvas canvas, /* Canvas containing item. */ + Tk_Item *itemPtr, /* Item whose coordinates are to be read or + * modified. */ + int objc, /* Number of coordinates supplied in objv. */ + Tcl_Obj *CONST objv[]) /* Array of coordinates: x1, y1, x2, y2, ... */ { PolygonItem *polyPtr = (PolygonItem *) itemPtr; int i, numPoints; if (objc == 0) { /* - * Print the coords used to create the polygon. If we auto - * closed the polygon then we don't report the last point. + * Print the coords used to create the polygon. If we auto closed the + * polygon then we don't report the last point. */ + Tcl_Obj *subobj, *obj = Tcl_NewObj(); + for (i = 0; i < 2*(polyPtr->numPoints - polyPtr->autoClosed); i++) { subobj = Tcl_NewDoubleObj(polyPtr->coordPtr[i]); Tcl_ListObjAppendElement(interp, obj, subobj); @@ -373,6 +365,7 @@ PolygonCoords(interp, canvas, itemPtr, objc, objv) } if (objc & 1) { char buf[64 + TCL_INTEGER_SPACE]; + sprintf(buf, "wrong # coordinates: expected an even number, got %d", objc); Tcl_SetResult(interp, buf, TCL_VOLATILE); @@ -385,8 +378,8 @@ PolygonCoords(interp, canvas, itemPtr, objc, objv) } /* - * One extra point gets allocated here, because we always - * add another point to close the polygon. + * One extra point gets allocated here, because we always add + * another point to close the polygon. */ polyPtr->coordPtr = (double *) ckalloc((unsigned) @@ -405,7 +398,7 @@ PolygonCoords(interp, canvas, itemPtr, objc, objv) /* * Close the polygon if it isn't already closed. */ - + if (objc>2 && ((polyPtr->coordPtr[objc-2] != polyPtr->coordPtr[0]) || (polyPtr->coordPtr[objc-1] != polyPtr->coordPtr[1]))) { polyPtr->autoClosed = 1; @@ -423,28 +416,28 @@ PolygonCoords(interp, canvas, itemPtr, objc, objv) * * ConfigurePolygon -- * - * This procedure is invoked to configure various aspects - * of a polygon item such as its background color. + * This function is invoked to configure various aspects of a polygon + * item such as its background color. * * Results: - * A standard Tcl result code. If an error occurs, then - * an error message is left in the interp's result. + * A standard Tcl result code. If an error occurs, then an error message + * is left in the interp's result. * * Side effects: - * Configuration information, such as colors and stipple - * patterns, may be set for itemPtr. + * Configuration information, such as colors and stipple patterns, may be + * set for itemPtr. * *-------------------------------------------------------------- */ static int -ConfigurePolygon(interp, canvas, itemPtr, objc, objv, flags) - Tcl_Interp *interp; /* Interpreter for error reporting. */ - Tk_Canvas canvas; /* Canvas containing itemPtr. */ - Tk_Item *itemPtr; /* Polygon item to reconfigure. */ - int objc; /* Number of elements in objv. */ - Tcl_Obj *CONST objv[]; /* Arguments describing things to configure. */ - int flags; /* Flags to pass to Tk_ConfigureWidget. */ +ConfigurePolygon( + Tcl_Interp *interp, /* Interpreter for error reporting. */ + Tk_Canvas canvas, /* Canvas containing itemPtr. */ + Tk_Item *itemPtr, /* Polygon item to reconfigure. */ + int objc, /* Number of elements in objv. */ + Tcl_Obj *CONST objv[], /* Arguments describing things to configure. */ + int flags) /* Flags to pass to Tk_ConfigureWidget. */ { PolygonItem *polyPtr = (PolygonItem *) itemPtr; XGCValues gcValues; @@ -462,8 +455,8 @@ ConfigurePolygon(interp, canvas, itemPtr, objc, objv, flags) } /* - * A few of the options require additional processing, such as - * graphics contexts. + * A few of the options require additional processing, such as graphics + * contexts. */ state = itemPtr->state; @@ -555,8 +548,8 @@ ConfigurePolygon(interp, canvas, itemPtr, objc, objv, flags) * * DeletePolygon -- * - * This procedure is called to clean up the data structure - * associated with a polygon item. + * This function is called to clean up the data structure associated with + * a polygon item. * * Results: * None. @@ -568,11 +561,10 @@ ConfigurePolygon(interp, canvas, itemPtr, objc, objv, flags) */ static void -DeletePolygon(canvas, itemPtr, display) - Tk_Canvas canvas; /* Info about overall canvas widget. */ - Tk_Item *itemPtr; /* Item that is being deleted. */ - Display *display; /* Display containing window for - * canvas. */ +DeletePolygon( + Tk_Canvas canvas, /* Info about overall canvas widget. */ + Tk_Item *itemPtr, /* Item that is being deleted. */ + Display *display) /* Display containing window for canvas. */ { PolygonItem *polyPtr = (PolygonItem *) itemPtr; @@ -608,24 +600,22 @@ DeletePolygon(canvas, itemPtr, display) * * ComputePolygonBbox -- * - * This procedure is invoked to compute the bounding box of - * all the pixels that may be drawn as part of a polygon. + * This function is invoked to compute the bounding box of all the pixels + * that may be drawn as part of a polygon. * * Results: * None. * * Side effects: - * The fields x1, y1, x2, and y2 are updated in the header - * for itemPtr. + * The fields x1, y1, x2, and y2 are updated in the header for itemPtr. * *-------------------------------------------------------------- */ static void -ComputePolygonBbox(canvas, polyPtr) - Tk_Canvas canvas; /* Canvas that contains item. */ - PolygonItem *polyPtr; /* Item whose bbox is to be - * recomputed. */ +ComputePolygonBbox( + Tk_Canvas canvas, /* Canvas that contains item. */ + PolygonItem *polyPtr) /* Item whose bbox is to be recomputed. */ { double *coordPtr; int i; @@ -657,12 +647,11 @@ ComputePolygonBbox(canvas, polyPtr) polyPtr->header.y1 = polyPtr->header.y2 = (int) coordPtr[1]; /* - * Compute the bounding box of all the points in the polygon, - * then expand in all directions by the outline's width to take - * care of butting or rounded corners and projecting or - * rounded caps. This expansion is an overestimate (worst-case - * is square root of two over two) but it's simple. Don't do - * anything special for curves. This causes an additional + * Compute the bounding box of all the points in the polygon, then expand + * in all directions by the outline's width to take care of butting or + * rounded corners and projecting or rounded caps. This expansion is an + * overestimate (worst-case is square root of two over two) but it's + * simple. Don't do anything special for curves. This causes an additional * overestimate in the bounding box, but is faster. */ @@ -708,6 +697,7 @@ ComputePolygonBbox(canvas, polyPtr) if (tsoffset) { if (tsoffset->flags & TK_OFFSET_INDEX) { int index = tsoffset->flags & ~TK_OFFSET_INDEX; + if (tsoffset->flags == INT_MAX) { index = (polyPtr->numPoints - 1) * 2; } @@ -743,13 +733,14 @@ ComputePolygonBbox(canvas, polyPtr) /* * For mitered lines, make a second pass through all the points. - * Compute the locations of the two miter vertex points and add - * those into the bounding box. + * Compute the locations of the two miter vertex points and add those + * into the bounding box. */ if (polyPtr->joinStyle == JoinMiter) { double miter[4]; int j; + coordPtr = polyPtr->coordPtr; if (polyPtr->numPoints>3) { if (TkGetMiterPoints(coordPtr+2*(polyPtr->numPoints-2), @@ -760,9 +751,8 @@ ComputePolygonBbox(canvas, polyPtr) } } } - for (i = polyPtr->numPoints ; i >= 3; - i--, coordPtr += 2) { - + for (i = polyPtr->numPoints ; i >= 3; i--, coordPtr += 2) { + if (TkGetMiterPoints(coordPtr, coordPtr+2, coordPtr+4, width, miter, miter+2)) { for (j = 0; j < 4; j += 2) { @@ -774,8 +764,8 @@ ComputePolygonBbox(canvas, polyPtr) } /* - * Add one more pixel of fudge factor just to be safe (e.g. - * X may round differently than we do). + * Add one more pixel of fudge factor just to be safe (e.g. X may round + * differently than we do). */ polyPtr->header.x1 -= 1; @@ -789,34 +779,33 @@ ComputePolygonBbox(canvas, polyPtr) * * TkFillPolygon -- * - * This procedure is invoked to convert a polygon to screen - * coordinates and display it using a particular GC. + * This function is invoked to convert a polygon to screen coordinates + * and display it using a particular GC. * * Results: * None. * * Side effects: - * ItemPtr is drawn in drawable using the transformation - * information in canvas. + * ItemPtr is drawn in drawable using the transformation information in + * canvas. * *-------------------------------------------------------------- */ void -TkFillPolygon(canvas, coordPtr, numPoints, display, drawable, gc, outlineGC) - Tk_Canvas canvas; /* Canvas whose coordinate system - * is to be used for drawing. */ - double *coordPtr; /* Array of coordinates for polygon: - * x1, y1, x2, y2, .... */ - int numPoints; /* Twice this many coordinates are - * present at *coordPtr. */ - Display *display; /* Display on which to draw polygon. */ - Drawable drawable; /* Pixmap or window in which to draw - * polygon. */ - GC gc; /* Graphics context for drawing. */ - GC outlineGC; /* If not None, use this to draw an - * outline around the polygon after - * filling it. */ +TkFillPolygon( + Tk_Canvas canvas, /* Canvas whose coordinate system is to be + * used for drawing. */ + double *coordPtr, /* Array of coordinates for polygon: x1, y1, + * x2, y2, .... */ + int numPoints, /* Twice this many coordinates are present at + * *coordPtr. */ + Display *display, /* Display on which to draw polygon. */ + Drawable drawable, /* Pixmap or window in which to draw + * polygon. */ + GC gc, /* Graphics context for drawing. */ + GC outlineGC) /* If not None, use this to draw an outline + * around the polygon after filling it. */ { XPoint staticPoints[MAX_STATIC_POINTS]; XPoint *pointPtr; @@ -824,9 +813,9 @@ TkFillPolygon(canvas, coordPtr, numPoints, display, drawable, gc, outlineGC) int i; /* - * Build up an array of points in screen coordinates. Use a - * static array unless the polygon has an enormous number of points; - * in this case, dynamically allocate an array. + * Build up an array of points in screen coordinates. Use a static array + * unless the polygon has an enormous number of points; in this case, + * dynamically allocate an array. */ if (numPoints <= MAX_STATIC_POINTS) { @@ -835,7 +824,7 @@ TkFillPolygon(canvas, coordPtr, numPoints, display, drawable, gc, outlineGC) pointPtr = (XPoint *) ckalloc((unsigned) (numPoints * sizeof(XPoint))); } - for (i = 0, pPtr = pointPtr; i < numPoints; i += 1, coordPtr += 2, pPtr++) { + for (i=0, pPtr=pointPtr ; i<numPoints; i+=1, coordPtr+=2, pPtr++) { Tk_CanvasDrawableCoords(canvas, coordPtr[0], coordPtr[1], &pPtr->x, &pPtr->y); } @@ -863,28 +852,27 @@ TkFillPolygon(canvas, coordPtr, numPoints, display, drawable, gc, outlineGC) * * DisplayPolygon -- * - * This procedure is invoked to draw a polygon item in a given - * drawable. + * This function is invoked to draw a polygon item in a given drawable. * * Results: * None. * * Side effects: - * ItemPtr is drawn in drawable using the transformation - * information in canvas. + * ItemPtr is drawn in drawable using the transformation information in + * canvas. * *-------------------------------------------------------------- */ static void -DisplayPolygon(canvas, itemPtr, display, drawable, x, y, width, height) - Tk_Canvas canvas; /* Canvas that contains item. */ - Tk_Item *itemPtr; /* Item to be displayed. */ - Display *display; /* Display on which to draw item. */ - Drawable drawable; /* Pixmap or window in which to draw - * item. */ - int x, y, width, height; /* Describes region of canvas that - * must be redisplayed (not used). */ +DisplayPolygon( + Tk_Canvas canvas, /* Canvas that contains item. */ + Tk_Item *itemPtr, /* Item to be displayed. */ + Display *display, /* Display on which to draw item. */ + Drawable drawable, /* Pixmap or window in which to draw item. */ + int x, int y, int width, int height) + /* Describes region of canvas that must be + * redisplayed (not used). */ { PolygonItem *polyPtr = (PolygonItem *) itemPtr; Tk_State state = itemPtr->state; @@ -897,7 +885,7 @@ DisplayPolygon(canvas, itemPtr, display, drawable, x, y, width, height) return; } - if(state == TK_STATE_NULL) { + if (state == TK_STATE_NULL) { state = ((TkCanvas *)canvas)->canvas_state; } if (((TkCanvas *)canvas)->currentItemPtr == itemPtr) { @@ -915,16 +903,17 @@ DisplayPolygon(canvas, itemPtr, display, drawable, x, y, width, height) stipple = polyPtr->disabledFillStipple; } } + /* - * If we're stippling then modify the stipple offset in the GC. Be - * sure to reset the offset when done, since the GC is supposed to be - * read-only. + * If we're stippling then modify the stipple offset in the GC. Be sure to + * reset the offset when done, since the GC is supposed to be read-only. */ if ((stipple != None) && (polyPtr->fillGC != None)) { Tk_TSOffset *tsoffset = &polyPtr->tsoffset; int w=0; int h=0; int flags = tsoffset->flags; + if (!(flags & TK_OFFSET_INDEX) && (flags & (TK_OFFSET_CENTER|TK_OFFSET_MIDDLE))) { Tk_SizeOfBitmap(display, stipple, &w, &h); if (flags & TK_OFFSET_CENTER) { @@ -949,6 +938,7 @@ DisplayPolygon(canvas, itemPtr, display, drawable, x, y, width, height) if(polyPtr->numPoints < 3) { short x,y; int intLineWidth = (int) (linewidth + 0.5); + if (intLineWidth < 1) { intLineWidth = 1; } @@ -967,13 +957,12 @@ DisplayPolygon(canvas, itemPtr, display, drawable, x, y, width, height) XPoint *pointPtr; /* - * This is a smoothed polygon. Display using a set of generated - * spline points rather than the original points. + * This is a smoothed polygon. Display using a set of generated spline + * points rather than the original points. */ - numPoints = polyPtr->smooth->coordProc(canvas, (double *) NULL, - polyPtr->numPoints, polyPtr->splineSteps, (XPoint *) NULL, - (double *) NULL); + numPoints = polyPtr->smooth->coordProc(canvas, NULL, + polyPtr->numPoints, polyPtr->splineSteps, NULL, NULL); if (numPoints <= MAX_STATIC_POINTS) { pointPtr = staticPoints; } else { @@ -981,8 +970,7 @@ DisplayPolygon(canvas, itemPtr, display, drawable, x, y, width, height) (numPoints * sizeof(XPoint))); } numPoints = polyPtr->smooth->coordProc(canvas, polyPtr->coordPtr, - polyPtr->numPoints, polyPtr->splineSteps, pointPtr, - (double *) NULL); + polyPtr->numPoints, polyPtr->splineSteps, pointPtr, NULL); if (polyPtr->fillGC != None) { XFillPolygon(display, drawable, polyPtr->fillGC, pointPtr, numPoints, Complex, CoordModeOrigin); @@ -1018,12 +1006,12 @@ DisplayPolygon(canvas, itemPtr, display, drawable, x, y, width, height) */ static void -PolygonInsert(canvas, itemPtr, beforeThis, obj) - Tk_Canvas canvas; /* Canvas containing text item. */ - Tk_Item *itemPtr; /* Line item to be modified. */ - int beforeThis; /* Index before which new coordinates - * are to be inserted. */ - Tcl_Obj *obj; /* New coordinates to be inserted. */ +PolygonInsert( + Tk_Canvas canvas, /* Canvas containing text item. */ + Tk_Item *itemPtr, /* Line item to be modified. */ + int beforeThis, /* Index before which new coordinates are to + * be inserted. */ + Tcl_Obj *obj) /* New coordinates to be inserted. */ { PolygonItem *polyPtr = (PolygonItem *) itemPtr; int length, objc, i; @@ -1035,36 +1023,41 @@ PolygonInsert(canvas, itemPtr, beforeThis, obj) state = ((TkCanvas *)canvas)->canvas_state; } - if (!obj || (Tcl_ListObjGetElements((Tcl_Interp *) NULL, obj, &objc, &objv) != TCL_OK) + if (!obj || (Tcl_ListObjGetElements(NULL, obj, &objc, &objv) != TCL_OK) || !objc || objc&1) { return; } length = 2*(polyPtr->numPoints - polyPtr->autoClosed); - while(beforeThis>length) beforeThis-=length; - while(beforeThis<0) beforeThis+=length; + while (beforeThis>length) { + beforeThis -= length; + } + while (beforeThis<0) { + beforeThis += length; + } new = (double *) ckalloc((unsigned)(sizeof(double) * (length + 2 + objc))); for (i=0; i<beforeThis; i++) { new[i] = polyPtr->coordPtr[i]; } for (i=0; i<objc; i++) { - if (Tcl_GetDoubleFromObj((Tcl_Interp *) NULL,objv[i], - new+(i+beforeThis))!=TCL_OK) { + if (Tcl_GetDoubleFromObj(NULL, objv[i], new+(i+beforeThis)) != TCL_OK){ ckfree((char *) new); return; } } - for(i=beforeThis; i<length; i++) { + for (i=beforeThis; i<length; i++) { new[i+objc] = polyPtr->coordPtr[i]; } - if(polyPtr->coordPtr) ckfree((char *) polyPtr->coordPtr); - length+=objc; + if (polyPtr->coordPtr) { + ckfree((char *) polyPtr->coordPtr); + } + length += objc; polyPtr->coordPtr = new; polyPtr->numPoints = (length/2) + polyPtr->autoClosed; /* - * Close the polygon if it isn't already closed, or remove autoclosing - * if the user's coordinates are now closed. + * Close the polygon if it isn't already closed, or remove autoclosing if + * the user's coordinates are now closed. */ if (polyPtr->autoClosed) { @@ -1072,8 +1065,7 @@ PolygonInsert(canvas, itemPtr, beforeThis, obj) polyPtr->autoClosed = 0; polyPtr->numPoints--; } - } - else { + } else { if ((new[length-2] != new[0]) || (new[length-1] != new[1])) { polyPtr->autoClosed = 1; polyPtr->numPoints++; @@ -1084,52 +1076,60 @@ PolygonInsert(canvas, itemPtr, beforeThis, obj) new[length+1] = new[1]; if (((length-objc)>3) && (state != TK_STATE_HIDDEN)) { /* - * This is some optimizing code that will result that only the part - * of the polygon that changed (and the objects that are overlapping - * with that part) need to be redrawn. A special flag is set that - * instructs the general canvas code not to redraw the whole - * object. If this flag is not set, the canvas will do the redrawing, - * otherwise I have to do it here. + * This is some optimizing code that will result that only the part of + * the polygon that changed (and the objects that are overlapping with + * that part) need to be redrawn. A special flag is set that instructs + * the general canvas code not to redraw the whole object. If this + * flag is not set, the canvas will do the redrawing, otherwise I have + * to do it here. */ + double width; int j; itemPtr->redraw_flags |= TK_ITEM_DONT_REDRAW; /* - * The header elements that normally are used for the - * bounding box, are now used to calculate the bounding - * box for only the part that has to be redrawn. That - * doesn't matter, because afterwards the bounding - * box has to be re-calculated anyway. + * The header elements that normally are used for the bounding box, + * are now used to calculate the bounding box for only the part that + * has to be redrawn. That doesn't matter, because afterwards the + * bounding box has to be re-calculated anyway. */ itemPtr->x1 = itemPtr->x2 = (int) polyPtr->coordPtr[beforeThis]; itemPtr->y1 = itemPtr->y2 = (int) polyPtr->coordPtr[beforeThis+1]; beforeThis-=2; objc+=4; - if(polyPtr->smooth) { - beforeThis-=2; objc+=4; - } /* be carefull; beforeThis could now be negative */ - for(i=beforeThis; i<beforeThis+objc; i+=2) { - j=i; - if(j<0) j+=length; - if(j>=length) j-=length; - TkIncludePoint(itemPtr, polyPtr->coordPtr+j); + if (polyPtr->smooth) { + beforeThis-=2; + objc+=4; + } + + /* + * Be careful; beforeThis could now be negative + */ + + for (i=beforeThis; i<beforeThis+objc; i+=2) { + j = i; + if (j<0) { + j += length; + } else if (j>=length) { + j -= length; + } + TkIncludePoint(itemPtr, polyPtr->coordPtr+j); } width = polyPtr->outline.width; if (((TkCanvas *)canvas)->currentItemPtr == itemPtr) { - if (polyPtr->outline.activeWidth>width) { - width = polyPtr->outline.activeWidth; - } + if (polyPtr->outline.activeWidth > width) { + width = polyPtr->outline.activeWidth; + } } else if (state==TK_STATE_DISABLED) { - if (polyPtr->outline.disabledWidth>0.0) { - width = polyPtr->outline.disabledWidth; - } + if (polyPtr->outline.disabledWidth > 0.0) { + width = polyPtr->outline.disabledWidth; + } } itemPtr->x1 -= (int) width; itemPtr->y1 -= (int) width; itemPtr->x2 += (int) width; itemPtr->y2 += (int) width; Tk_CanvasEventuallyRedraw(canvas, - itemPtr->x1, itemPtr->y1, - itemPtr->x2, itemPtr->y2); + itemPtr->x1, itemPtr->y1, itemPtr->x2, itemPtr->y2); } ComputePolygonBbox(canvas, polyPtr); @@ -1146,44 +1146,54 @@ PolygonInsert(canvas, itemPtr, beforeThis, obj) * None. * * Side effects: - * Characters between "first" and "last", inclusive, get - * deleted from itemPtr. + * Characters between "first" and "last", inclusive, get deleted from + * itemPtr. * *-------------------------------------------------------------- */ static void -PolygonDeleteCoords(canvas, itemPtr, first, last) - Tk_Canvas canvas; /* Canvas containing itemPtr. */ - Tk_Item *itemPtr; /* Item in which to delete characters. */ - int first; /* Index of first character to delete. */ - int last; /* Index of last character to delete. */ +PolygonDeleteCoords( + Tk_Canvas canvas, /* Canvas containing itemPtr. */ + Tk_Item *itemPtr, /* Item in which to delete characters. */ + int first, /* Index of first character to delete. */ + int last) /* Index of last character to delete. */ { PolygonItem *polyPtr = (PolygonItem *) itemPtr; int count, i; int length = 2*(polyPtr->numPoints - polyPtr->autoClosed); - while(first>=length) first-=length; - while(first<0) first+=length; - while(last>=length) last-=length; - while(last<0) last+=length; + while (first>=length) { + first -= length; + } + while (first<0) { + first += length; + } + while (last>=length) { + last -= length; + } + while (last<0) { + last += length; + } first &= -2; last &= -2; count = last + 2 - first; - if(count<=0) count +=length; + if (count<=0) { + count += length; + } - if(count >= length) { + if (count >= length) { polyPtr->numPoints = 0; - if(polyPtr->coordPtr != NULL) { + if (polyPtr->coordPtr != NULL) { ckfree((char *) polyPtr->coordPtr); } ComputePolygonBbox(canvas, polyPtr); return; } - if(last>=first) { + if (last>=first) { for(i=last+2; i<length; i++) { polyPtr->coordPtr[i-count] = polyPtr->coordPtr[i]; } @@ -1203,14 +1213,14 @@ PolygonDeleteCoords(canvas, itemPtr, first, last) * * PolygonToPoint -- * - * Computes the distance from a given point to a given - * polygon, in canvas units. + * Computes the distance from a given point to a given polygon, in canvas + * units. * * Results: - * The return value is 0 if the point whose x and y coordinates - * are pointPtr[0] and pointPtr[1] is inside the polygon. If the - * point isn't inside the polygon then the return value is the - * distance from the point to the polygon. + * The return value is 0 if the point whose x and y coordinates are + * pointPtr[0] and pointPtr[1] is inside the polygon. If the point isn't + * inside the polygon then the return value is the distance from the + * point to the polygon. * * Side effects: * None. @@ -1220,10 +1230,10 @@ PolygonDeleteCoords(canvas, itemPtr, first, last) /* ARGSUSED */ static double -PolygonToPoint(canvas, itemPtr, pointPtr) - Tk_Canvas canvas; /* Canvas containing item. */ - Tk_Item *itemPtr; /* Item to check against point. */ - double *pointPtr; /* Pointer to x and y coordinates. */ +PolygonToPoint( + Tk_Canvas canvas, /* Canvas containing item. */ + Tk_Item *itemPtr, /* Item to check against point. */ + double *pointPtr) /* Pointer to x and y coordinates. */ { PolygonItem *polyPtr = (PolygonItem *) itemPtr; double *coordPtr, *polyPoints; @@ -1232,15 +1242,15 @@ PolygonToPoint(canvas, itemPtr, pointPtr) double radius; double bestDist, dist; int numPoints, count; - int changedMiterToBevel; /* Non-zero means that a mitered corner - * had to be treated as beveled after all - * because the angle was < 11 degrees. */ + int changedMiterToBevel; /* Non-zero means that a mitered corner had to + * be treated as beveled after all because the + * angle was < 11 degrees. */ double width; Tk_State state = itemPtr->state; bestDist = 1.0e36; - if(state == TK_STATE_NULL) { + if (state == TK_STATE_NULL) { state = ((TkCanvas *)canvas)->canvas_state; } width = polyPtr->outline.width; @@ -1261,9 +1271,9 @@ PolygonToPoint(canvas, itemPtr, pointPtr) */ if ((polyPtr->smooth) && (polyPtr->numPoints>2)) { - numPoints = polyPtr->smooth->coordProc(canvas, (double *) NULL, - polyPtr->numPoints, polyPtr->splineSteps, (XPoint *) NULL, - (double *) NULL); + numPoints = polyPtr->smooth->coordProc(canvas, NULL, + polyPtr->numPoints, polyPtr->splineSteps, NULL, + NULL); if (numPoints <= MAX_STATIC_POINTS) { polyPoints = staticSpace; } else { @@ -1271,7 +1281,7 @@ PolygonToPoint(canvas, itemPtr, pointPtr) (2*numPoints*sizeof(double))); } numPoints = polyPtr->smooth->coordProc(canvas, polyPtr->coordPtr, - polyPtr->numPoints, polyPtr->splineSteps, (XPoint *) NULL, + polyPtr->numPoints, polyPtr->splineSteps, NULL, polyPoints); } else { numPoints = polyPtr->numPoints; @@ -1292,22 +1302,23 @@ PolygonToPoint(canvas, itemPtr, pointPtr) } } - if ((polyPtr->outline.gc == None) || (width <= 1)) goto donepoint; + if ((polyPtr->outline.gc == None) || (width <= 1)) { + goto donepoint; + } /* - * The overall idea is to iterate through all of the edges of - * the line, computing a polygon for each edge and testing the - * point against that polygon. In addition, there are additional - * tests to deal with rounded joints and caps. + * The overall idea is to iterate through all of the edges of the line, + * computing a polygon for each edge and testing the point against that + * polygon. In addition, there are additional tests to deal with rounded + * joints and caps. */ changedMiterToBevel = 0; for (count = numPoints, coordPtr = polyPoints; count >= 2; count--, coordPtr += 2) { - /* - * If rounding is done around the first point then compute - * the distance between the point and the point. + * If rounding is done around the first point then compute the + * distance between the point and the point. */ if (polyPtr->joinStyle == JoinRound) { @@ -1322,9 +1333,9 @@ PolygonToPoint(canvas, itemPtr, pointPtr) } /* - * Compute the polygonal shape corresponding to this edge, - * consisting of two points for the first point of the edge - * and two points for the last point of the edge. + * Compute the polygonal shape corresponding to this edge, consisting + * of two points for the first point of the edge and two points for + * the last point of the edge. */ if (count == numPoints) { @@ -1340,10 +1351,10 @@ PolygonToPoint(canvas, itemPtr, pointPtr) poly, poly+2); /* - * If this line uses beveled joints, then check the distance - * to a polygon comprising the last two points of the previous - * polygon and the first two from this polygon; this checks - * the wedges that fill the mitered joint. + * If this line uses beveled joints, then check the distance to a + * polygon comprising the last two points of the previous polygon + * and the first two from this polygon; this checks the wedges + * that fill the mitered joint. */ if ((polyPtr->joinStyle == JoinBevel) || changedMiterToBevel) { @@ -1366,8 +1377,8 @@ PolygonToPoint(canvas, itemPtr, pointPtr) if (TkGetMiterPoints(coordPtr, coordPtr+2, coordPtr+4, (double) width, poly+4, poly+6) == 0) { changedMiterToBevel = 1; - TkGetButtPoints(coordPtr, coordPtr+2, (double) width, - 0, poly+4, poly+6); + TkGetButtPoints(coordPtr, coordPtr+2, (double) width, 0, + poly+4, poly+6); } } else { TkGetButtPoints(coordPtr, coordPtr+2, (double) width, 0, @@ -1384,7 +1395,7 @@ PolygonToPoint(canvas, itemPtr, pointPtr) } } - donepoint: + donepoint: if ((polyPoints != staticSpace) && polyPoints != polyPtr->coordPtr) { ckfree((char *) polyPoints); } @@ -1396,14 +1407,13 @@ PolygonToPoint(canvas, itemPtr, pointPtr) * * PolygonToArea -- * - * This procedure is called to determine whether an item - * lies entirely inside, entirely outside, or overlapping - * a given rectangular area. + * This function is called to determine whether an item lies entirely + * inside, entirely outside, or overlapping a given rectangular area. * * Results: - * -1 is returned if the item is entirely outside the area - * given by rectPtr, 0 if it overlaps, and 1 if it is entirely - * inside the given area. + * -1 is returned if the item is entirely outside the area given by + * rectPtr, 0 if it overlaps, and 1 if it is entirely inside the given + * area. * * Side effects: * None. @@ -1413,12 +1423,12 @@ PolygonToPoint(canvas, itemPtr, pointPtr) /* ARGSUSED */ static int -PolygonToArea(canvas, itemPtr, rectPtr) - Tk_Canvas canvas; /* Canvas containing item. */ - Tk_Item *itemPtr; /* Item to check against polygon. */ - double *rectPtr; /* Pointer to array of four coordinates - * (x1, y1, x2, y2) describing rectangular - * area. */ +PolygonToArea( + Tk_Canvas canvas, /* Canvas containing item. */ + Tk_Item *itemPtr, /* Item to check against polygon. */ + double *rectPtr) /* Pointer to array of four coordinates + * (x1,y1,x2,y2) describing rectangular + * area. */ { PolygonItem *polyPtr = (PolygonItem *) itemPtr; double *coordPtr; @@ -1426,19 +1436,18 @@ PolygonToArea(canvas, itemPtr, rectPtr) double *polyPoints, poly[10]; double radius; int numPoints, count; - int changedMiterToBevel; /* Non-zero means that a mitered corner - * had to be treated as beveled after all - * because the angle was < 11 degrees. */ - int inside; /* Tentative guess about what to return, - * based on all points seen so far: one - * means everything seen so far was - * inside the area; -1 means everything - * was outside the area. 0 means overlap - * has been found. */ + int changedMiterToBevel; /* Non-zero means that a mitered corner had to + * be treated as beveled after all because the + * angle was < 11 degrees. */ + int inside; /* Tentative guess about what to return, based + * on all points seen so far: one means + * everything seen so far was inside the area; + * -1 means everything was outside the area. 0 + * means overlap has been found. */ double width; Tk_State state = itemPtr->state; - if(state == TK_STATE_NULL) { + if (state == TK_STATE_NULL) { state = ((TkCanvas *)canvas)->canvas_state; } @@ -1460,60 +1469,62 @@ PolygonToArea(canvas, itemPtr, rectPtr) return -1; } else if (polyPtr->numPoints <3) { double oval[4]; + oval[0] = polyPtr->coordPtr[0]-radius; oval[1] = polyPtr->coordPtr[1]-radius; oval[2] = polyPtr->coordPtr[0]+radius; oval[3] = polyPtr->coordPtr[1]+radius; return TkOvalToArea(oval, rectPtr); } + /* * Handle smoothed polygons by generating an expanded set of points * against which to do the check. */ if (polyPtr->smooth) { - numPoints = polyPtr->smooth->coordProc(canvas, (double *) NULL, - polyPtr->numPoints, polyPtr->splineSteps, (XPoint *) NULL, - (double *) NULL); + numPoints = polyPtr->smooth->coordProc(canvas, NULL, + polyPtr->numPoints, polyPtr->splineSteps, NULL, NULL); if (numPoints <= MAX_STATIC_POINTS) { polyPoints = staticSpace; } else { - polyPoints = (double *) ckalloc((unsigned) - (2*numPoints*sizeof(double))); + polyPoints = (double *) + ckalloc((unsigned) (2*numPoints*sizeof(double))); } numPoints = polyPtr->smooth->coordProc(canvas, polyPtr->coordPtr, - polyPtr->numPoints, polyPtr->splineSteps, (XPoint *) NULL, - polyPoints); + polyPtr->numPoints, polyPtr->splineSteps, NULL, polyPoints); } else { numPoints = polyPtr->numPoints; polyPoints = polyPtr->coordPtr; } /* - * Simple test to see if we are in the polygon. Polygons are - * different from othe canvas items in that they register points - * being inside even if it isn't filled. + * Simple test to see if we are in the polygon. Polygons are different + * from othe canvas items in that they register points being inside even + * if it isn't filled. */ + inside = TkPolygonToArea(polyPoints, numPoints, rectPtr); - if (inside==0) goto donearea; + if (inside==0) { + goto donearea; + } - if (polyPtr->outline.gc == None) goto donearea ; + if (polyPtr->outline.gc == None) { + goto donearea; + } /* - * Iterate through all of the edges of the line, computing a polygon - * for each edge and testing the area against that polygon. In - * addition, there are additional tests to deal with rounded joints - * and caps. + * Iterate through all of the edges of the line, computing a polygon for + * each edge and testing the area against that polygon. In addition, there + * are additional tests to deal with rounded joints and caps. */ changedMiterToBevel = 0; for (count = numPoints, coordPtr = polyPoints; count >= 2; count--, coordPtr += 2) { - /* - * If rounding is done around the first point of the edge - * then test a circular region around the point with the - * area. + * If rounding is done around the first point of the edge then test a + * circular region around the point with the area. */ if (polyPtr->joinStyle == JoinRound) { @@ -1528,28 +1539,26 @@ PolygonToArea(canvas, itemPtr, rectPtr) } /* - * Compute the polygonal shape corresponding to this edge, - * consisting of two points for the first point of the edge - * and two points for the last point of the edge. + * Compute the polygonal shape corresponding to this edge, consisting + * of two points for the first point of the edge and two points for + * the last point of the edge. */ if (count == numPoints) { - TkGetButtPoints(coordPtr+2, coordPtr, width, - 0, poly, poly+2); + TkGetButtPoints(coordPtr+2, coordPtr, width, 0, poly, poly+2); } else if ((polyPtr->joinStyle == JoinMiter) && !changedMiterToBevel) { poly[0] = poly[6]; poly[1] = poly[7]; poly[2] = poly[4]; poly[3] = poly[5]; } else { - TkGetButtPoints(coordPtr+2, coordPtr, width, 0, - poly, poly+2); + TkGetButtPoints(coordPtr+2, coordPtr, width, 0, poly, poly+2); /* - * If the last joint was beveled, then also check a - * polygon comprising the last two points of the previous - * polygon and the first two from this polygon; this checks - * the wedges that fill the beveled joint. + * If the last joint was beveled, then also check a polygon + * comprising the last two points of the previous polygon and the + * first two from this polygon; this checks the wedges that fill + * the beveled joint. */ if ((polyPtr->joinStyle == JoinBevel) || changedMiterToBevel) { @@ -1563,18 +1572,15 @@ PolygonToArea(canvas, itemPtr, rectPtr) } } if (count == 2) { - TkGetButtPoints(coordPtr, coordPtr+2, width, - 0, poly+4, poly+6); + TkGetButtPoints(coordPtr, coordPtr+2, width, 0, poly+4, poly+6); } else if (polyPtr->joinStyle == JoinMiter) { if (TkGetMiterPoints(coordPtr, coordPtr+2, coordPtr+4, width, poly+4, poly+6) == 0) { changedMiterToBevel = 1; - TkGetButtPoints(coordPtr, coordPtr+2, width, - 0, poly+4, poly+6); + TkGetButtPoints(coordPtr, coordPtr+2, width,0, poly+4, poly+6); } } else { - TkGetButtPoints(coordPtr, coordPtr+2, width, 0, - poly+4, poly+6); + TkGetButtPoints(coordPtr, coordPtr+2, width, 0, poly+4, poly+6); } poly[8] = poly[0]; poly[9] = poly[1]; @@ -1584,7 +1590,7 @@ PolygonToArea(canvas, itemPtr, rectPtr) } } - donearea: + donearea: if ((polyPoints != staticSpace) && (polyPoints != polyPtr->coordPtr)) { ckfree((char *) polyPoints); } @@ -1596,15 +1602,14 @@ PolygonToArea(canvas, itemPtr, rectPtr) * * ScalePolygon -- * - * This procedure is invoked to rescale a polygon item. + * This function is invoked to rescale a polygon item. * * Results: * None. * * Side effects: - * The polygon referred to by itemPtr is rescaled so that the - * following transformation is applied to all point - * coordinates: + * The polygon referred to by itemPtr is rescaled so that the following + * transformation is applied to all point coordinates: * x' = originX + scaleX*(x-originX) * y' = originY + scaleY*(y-originY) * @@ -1612,12 +1617,13 @@ PolygonToArea(canvas, itemPtr, rectPtr) */ static void -ScalePolygon(canvas, itemPtr, originX, originY, scaleX, scaleY) - Tk_Canvas canvas; /* Canvas containing polygon. */ - Tk_Item *itemPtr; /* Polygon to be scaled. */ - double originX, originY; /* Origin about which to scale rect. */ - double scaleX; /* Amount to scale in X direction. */ - double scaleY; /* Amount to scale in Y direction. */ +ScalePolygon( + Tk_Canvas canvas, /* Canvas containing polygon. */ + Tk_Item *itemPtr, /* Polygon to be scaled. */ + double originX, double originY, + /* Origin about which to scale rect. */ + double scaleX, /* Amount to scale in X direction. */ + double scaleY) /* Amount to scale in Y direction. */ { PolygonItem *polyPtr = (PolygonItem *) itemPtr; double *coordPtr; @@ -1636,14 +1642,13 @@ ScalePolygon(canvas, itemPtr, originX, originY, scaleX, scaleY) * * GetPolygonIndex -- * - * Parse an index into a polygon item and return either its value - * or an error. + * Parse an index into a polygon item and return either its value or an + * error. * * Results: - * A standard Tcl result. If all went well, then *indexPtr is - * filled in with the index (into itemPtr) corresponding to - * string. Otherwise an error message is left in - * interp->result. + * A standard Tcl result. If all went well, then *indexPtr is filled in + * with the index (into itemPtr) corresponding to string. Otherwise an + * error message is left in interp->result. * * Side effects: * None. @@ -1652,14 +1657,14 @@ ScalePolygon(canvas, itemPtr, originX, originY, scaleX, scaleY) */ static int -GetPolygonIndex(interp, canvas, itemPtr, obj, indexPtr) - Tcl_Interp *interp; /* Used for error reporting. */ - Tk_Canvas canvas; /* Canvas containing item. */ - Tk_Item *itemPtr; /* Item for which the index is being +GetPolygonIndex( + Tcl_Interp *interp, /* Used for error reporting. */ + Tk_Canvas canvas, /* Canvas containing item. */ + Tk_Item *itemPtr, /* Item for which the index is being * specified. */ - Tcl_Obj *obj; /* Specification of a particular coord - * in itemPtr's line. */ - int *indexPtr; /* Where to store converted index. */ + Tcl_Obj *obj, /* Specification of a particular coord in + * itemPtr's line. */ + int *indexPtr) /* Where to store converted index. */ { PolygonItem *polyPtr = (PolygonItem *) itemPtr; int length; @@ -1669,16 +1674,14 @@ GetPolygonIndex(interp, canvas, itemPtr, obj, indexPtr) if (strncmp(string, "end", (unsigned)length) == 0) { *indexPtr = 2*(polyPtr->numPoints - polyPtr->autoClosed); } else { - badIndex: - /* - * Some of the paths here leave messages in interp->result, - * so we have to clear it out before storing our own message. + * Some of the paths here leave messages in interp->result, so we + * have to clear it out before storing our own message. */ - Tcl_SetResult(interp, (char *) NULL, TCL_STATIC); - Tcl_AppendResult(interp, "bad index \"", string, "\"", - (char *) NULL); + badIndex: + Tcl_SetResult(interp, NULL, TCL_STATIC); + Tcl_AppendResult(interp, "bad index \"", string, "\"", NULL); return TCL_ERROR; } } else if (string[0] == '@') { @@ -1709,6 +1712,7 @@ GetPolygonIndex(interp, canvas, itemPtr, obj, indexPtr) } } else { int count = 2*(polyPtr->numPoints - polyPtr->autoClosed); + if (Tcl_GetIntFromObj(interp, obj, indexPtr) != TCL_OK) { goto badIndex; } @@ -1731,26 +1735,24 @@ GetPolygonIndex(interp, canvas, itemPtr, obj, indexPtr) * * TranslatePolygon -- * - * This procedure is called to move a polygon by a given - * amount. + * This function is called to move a polygon by a given amount. * * Results: * None. * * Side effects: - * The position of the polygon is offset by (xDelta, yDelta), - * and the bounding box is updated in the generic part of the - * item structure. + * The position of the polygon is offset by (xDelta, yDelta), and the + * bounding box is updated in the generic part of the item structure. * *-------------------------------------------------------------- */ static void -TranslatePolygon(canvas, itemPtr, deltaX, deltaY) - Tk_Canvas canvas; /* Canvas containing item. */ - Tk_Item *itemPtr; /* Item that is being moved. */ - double deltaX, deltaY; /* Amount by which item is to be - * moved. */ +TranslatePolygon( + Tk_Canvas canvas, /* Canvas containing item. */ + Tk_Item *itemPtr, /* Item that is being moved. */ + double deltaX, double deltaY) + /* Amount by which item is to be moved. */ { PolygonItem *polyPtr = (PolygonItem *) itemPtr; double *coordPtr; @@ -1769,15 +1771,13 @@ TranslatePolygon(canvas, itemPtr, deltaX, deltaY) * * PolygonToPostscript -- * - * This procedure is called to generate Postscript for - * polygon items. + * This function is called to generate Postscript for polygon items. * * Results: - * The return value is a standard Tcl result. If an error - * occurs in generating Postscript then an error message is - * left in the interp's result, replacing whatever used - * to be there. If no error occurs, then Postscript for the - * item is appended to the result. + * The return value is a standard Tcl result. If an error occurs in + * generating Postscript then an error message is left in the interp's + * result, replacing whatever used to be there. If no error occurs, then + * Postscript for the item is appended to the result. * * Side effects: * None. @@ -1786,15 +1786,13 @@ TranslatePolygon(canvas, itemPtr, deltaX, deltaY) */ static int -PolygonToPostscript(interp, canvas, itemPtr, prepass) - Tcl_Interp *interp; /* Leave Postscript or error message - * here. */ - Tk_Canvas canvas; /* Information about overall canvas. */ - Tk_Item *itemPtr; /* Item for which Postscript is - * wanted. */ - int prepass; /* 1 means this is a prepass to - * collect font information; 0 means - * final Postscript is being created. */ +PolygonToPostscript( + Tcl_Interp *interp, /* Leave Postscript or error message here. */ + Tk_Canvas canvas, /* Information about overall canvas. */ + Tk_Item *itemPtr, /* Item for which Postscript is wanted. */ + int prepass) /* 1 means this is a prepass to collect font + * information; 0 means final Postscript is + * being created. */ { PolygonItem *polyPtr = (PolygonItem *) itemPtr; char *style; @@ -1860,17 +1858,17 @@ PolygonToPostscript(interp, canvas, itemPtr, prepass) polyPtr->coordPtr[0], Tk_CanvasPsY(canvas, polyPtr->coordPtr[1]), width/2.0, width/2.0); Tcl_AppendResult(interp, "matrix currentmatrix\n",string, - " scale 1 0 moveto 0 0 1 0 360 arc\nsetmatrix\n", (char *) NULL); + " scale 1 0 moveto 0 0 1 0 360 arc\nsetmatrix\n", NULL); if (Tk_CanvasPsColor(interp, canvas, color) != TCL_OK) { return TCL_ERROR; } if (stipple != None) { - Tcl_AppendResult(interp, "clip ", (char *) NULL); + Tcl_AppendResult(interp, "clip ", NULL); if (Tk_CanvasPsStipple(interp, canvas, stipple) != TCL_OK) { return TCL_ERROR; } } else { - Tcl_AppendResult(interp, "fill\n", (char *) NULL); + Tcl_AppendResult(interp, "fill\n", NULL); } return TCL_OK; } @@ -1891,16 +1889,15 @@ PolygonToPostscript(interp, canvas, itemPtr, prepass) return TCL_ERROR; } if (fillStipple != None) { - Tcl_AppendResult(interp, "eoclip ", (char *) NULL); - if (Tk_CanvasPsStipple(interp, canvas, fillStipple) - != TCL_OK) { + Tcl_AppendResult(interp, "eoclip ", NULL); + if (Tk_CanvasPsStipple(interp, canvas, fillStipple) != TCL_OK) { return TCL_ERROR; } if (color != NULL) { - Tcl_AppendResult(interp, "grestore gsave\n", (char *) NULL); + Tcl_AppendResult(interp, "grestore gsave\n", NULL); } } else { - Tcl_AppendResult(interp, "eofill\n", (char *) NULL); + Tcl_AppendResult(interp, "eofill\n", NULL); } } @@ -1909,13 +1906,12 @@ PolygonToPostscript(interp, canvas, itemPtr, prepass) */ if (color != NULL) { - if (!polyPtr->smooth || !polyPtr->smooth->postscriptProc) { Tk_CanvasPsPath(interp, canvas, polyPtr->coordPtr, - polyPtr->numPoints); + polyPtr->numPoints); } else { polyPtr->smooth->postscriptProc(interp, canvas, polyPtr->coordPtr, - polyPtr->numPoints, polyPtr->splineSteps); + polyPtr->numPoints, polyPtr->splineSteps); } if (polyPtr->joinStyle == JoinRound) { @@ -1925,8 +1921,7 @@ PolygonToPostscript(interp, canvas, itemPtr, prepass) } else { style = "0"; } - Tcl_AppendResult(interp, style," setlinejoin 1 setlinecap\n", - (char *) NULL); + Tcl_AppendResult(interp, style," setlinejoin 1 setlinecap\n", NULL); if (Tk_CanvasPsOutline(canvas, itemPtr, &(polyPtr->outline)) != TCL_OK) { return TCL_ERROR; @@ -1934,3 +1929,11 @@ PolygonToPostscript(interp, canvas, itemPtr, prepass) } return TCL_OK; } + +/* + * Local Variables: + * mode: c + * c-basic-offset: 4 + * fill-column: 78 + * End: + */ |