diff options
Diffstat (limited to 'generic/tkCanvPoly.c')
-rw-r--r-- | generic/tkCanvPoly.c | 512 |
1 files changed, 259 insertions, 253 deletions
diff --git a/generic/tkCanvPoly.c b/generic/tkCanvPoly.c index b86bc63..943ef0b 100644 --- a/generic/tkCanvPoly.c +++ b/generic/tkCanvPoly.c @@ -11,7 +11,6 @@ * this file, and for a DISCLAIMER OF ALL WARRANTIES. */ -#include <stdio.h> #include "tkInt.h" #include "tkCanvas.h" @@ -44,7 +43,7 @@ typedef struct PolygonItem { 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. + const Tk_SmoothMethod *smooth; /* Non-zero means draw shape smoothed (i.e. * with Bezier splines). */ int splineSteps; /* Number of steps in each spline segment. */ int autoClosed; /* Zero means the given polygon was closed, @@ -55,45 +54,39 @@ typedef struct PolygonItem { * Information used for parsing configuration specs: */ -static Tk_CustomOption smoothOption = { - (Tk_OptionParseProc *) TkSmoothParseProc, - TkSmoothPrintProc, (ClientData) NULL +static const Tk_CustomOption smoothOption = { + TkSmoothParseProc, TkSmoothPrintProc, NULL }; -static Tk_CustomOption stateOption = { - (Tk_OptionParseProc *) TkStateParseProc, - TkStatePrintProc, (ClientData) 2 +static const Tk_CustomOption stateOption = { + TkStateParseProc, TkStatePrintProc, INT2PTR(2) }; -static Tk_CustomOption tagsOption = { - (Tk_OptionParseProc *) Tk_CanvasTagsParseProc, - Tk_CanvasTagsPrintProc, (ClientData) NULL +static const Tk_CustomOption tagsOption = { + Tk_CanvasTagsParseProc, Tk_CanvasTagsPrintProc, NULL }; -static Tk_CustomOption dashOption = { - (Tk_OptionParseProc *) TkCanvasDashParseProc, - TkCanvasDashPrintProc, (ClientData) NULL +static const Tk_CustomOption dashOption = { + TkCanvasDashParseProc, TkCanvasDashPrintProc, NULL }; -static Tk_CustomOption offsetOption = { - (Tk_OptionParseProc *) TkOffsetParseProc, - TkOffsetPrintProc, - (ClientData) (TK_OFFSET_RELATIVE|TK_OFFSET_INDEX) +static const Tk_CustomOption offsetOption = { + TkOffsetParseProc, TkOffsetPrintProc, + INT2PTR(TK_OFFSET_RELATIVE|TK_OFFSET_INDEX) }; -static Tk_CustomOption pixelOption = { - (Tk_OptionParseProc *) TkPixelParseProc, - TkPixelPrintProc, (ClientData) NULL +static const Tk_CustomOption pixelOption = { + TkPixelParseProc, TkPixelPrintProc, NULL }; -static Tk_ConfigSpec configSpecs[] = { +static const Tk_ConfigSpec configSpecs[] = { {TK_CONFIG_CUSTOM, "-activedash", NULL, NULL, NULL, Tk_Offset(PolygonItem, outline.activeDash), TK_CONFIG_NULL_OK, &dashOption}, {TK_CONFIG_COLOR, "-activefill", NULL, NULL, - NULL, Tk_Offset(PolygonItem, activeFillColor), TK_CONFIG_NULL_OK}, + NULL, Tk_Offset(PolygonItem, activeFillColor), TK_CONFIG_NULL_OK, NULL}, {TK_CONFIG_COLOR, "-activeoutline", NULL, NULL, - NULL, Tk_Offset(PolygonItem, outline.activeColor), TK_CONFIG_NULL_OK}, + NULL, Tk_Offset(PolygonItem, outline.activeColor), TK_CONFIG_NULL_OK, NULL}, {TK_CONFIG_BITMAP, "-activeoutlinestipple", NULL, NULL, NULL, Tk_Offset(PolygonItem, outline.activeStipple), - TK_CONFIG_NULL_OK}, + TK_CONFIG_NULL_OK, NULL}, {TK_CONFIG_BITMAP, "-activestipple", NULL, NULL, - NULL, Tk_Offset(PolygonItem, activeFillStipple), TK_CONFIG_NULL_OK}, + NULL, Tk_Offset(PolygonItem, activeFillStipple), TK_CONFIG_NULL_OK, NULL}, {TK_CONFIG_CUSTOM, "-activewidth", NULL, NULL, "0.0", Tk_Offset(PolygonItem, outline.activeWidth), TK_CONFIG_DONT_SET_DEFAULT, &pixelOption}, @@ -102,52 +95,52 @@ static Tk_ConfigSpec configSpecs[] = { TK_CONFIG_NULL_OK, &dashOption}, {TK_CONFIG_PIXELS, "-dashoffset", NULL, NULL, "0", Tk_Offset(PolygonItem, outline.offset), - TK_CONFIG_DONT_SET_DEFAULT}, + TK_CONFIG_DONT_SET_DEFAULT, NULL}, {TK_CONFIG_CUSTOM, "-disableddash", NULL, NULL, NULL, Tk_Offset(PolygonItem, outline.disabledDash), TK_CONFIG_NULL_OK, &dashOption}, {TK_CONFIG_COLOR, "-disabledfill", NULL, NULL, - NULL, Tk_Offset(PolygonItem, disabledFillColor), TK_CONFIG_NULL_OK}, + NULL, Tk_Offset(PolygonItem, disabledFillColor), TK_CONFIG_NULL_OK, NULL}, {TK_CONFIG_COLOR, "-disabledoutline", NULL, NULL, NULL, Tk_Offset(PolygonItem, outline.disabledColor), - TK_CONFIG_NULL_OK}, + TK_CONFIG_NULL_OK, NULL}, {TK_CONFIG_BITMAP, "-disabledoutlinestipple", NULL, NULL, NULL, Tk_Offset(PolygonItem, outline.disabledStipple), - TK_CONFIG_NULL_OK}, + TK_CONFIG_NULL_OK, NULL}, {TK_CONFIG_BITMAP, "-disabledstipple", NULL, NULL, - NULL, Tk_Offset(PolygonItem, disabledFillStipple), TK_CONFIG_NULL_OK}, + NULL, Tk_Offset(PolygonItem, disabledFillStipple), TK_CONFIG_NULL_OK, NULL}, {TK_CONFIG_CUSTOM, "-disabledwidth", NULL, NULL, "0.0", Tk_Offset(PolygonItem, outline.disabledWidth), TK_CONFIG_DONT_SET_DEFAULT, &pixelOption}, {TK_CONFIG_COLOR, "-fill", NULL, NULL, - "black", Tk_Offset(PolygonItem, fillColor), TK_CONFIG_NULL_OK}, + "black", Tk_Offset(PolygonItem, fillColor), TK_CONFIG_NULL_OK, NULL}, {TK_CONFIG_JOIN_STYLE, "-joinstyle", NULL, NULL, - "round", Tk_Offset(PolygonItem, joinStyle), TK_CONFIG_DONT_SET_DEFAULT}, + "round", Tk_Offset(PolygonItem, joinStyle), TK_CONFIG_DONT_SET_DEFAULT, NULL}, {TK_CONFIG_CUSTOM, "-offset", NULL, NULL, "0,0", Tk_Offset(PolygonItem, tsoffset), TK_CONFIG_NULL_OK, &offsetOption}, {TK_CONFIG_COLOR, "-outline", NULL, NULL, - NULL, Tk_Offset(PolygonItem, outline.color), TK_CONFIG_NULL_OK}, + NULL, Tk_Offset(PolygonItem, outline.color), TK_CONFIG_NULL_OK, NULL}, {TK_CONFIG_CUSTOM, "-outlineoffset", NULL, NULL, "0,0", Tk_Offset(PolygonItem, outline.tsoffset), TK_CONFIG_NULL_OK, &offsetOption}, {TK_CONFIG_BITMAP, "-outlinestipple", NULL, NULL, - NULL, Tk_Offset(PolygonItem, outline.stipple), TK_CONFIG_NULL_OK}, + NULL, Tk_Offset(PolygonItem, outline.stipple), TK_CONFIG_NULL_OK, NULL}, {TK_CONFIG_CUSTOM, "-smooth", NULL, NULL, "0", Tk_Offset(PolygonItem, smooth), TK_CONFIG_DONT_SET_DEFAULT, &smoothOption}, {TK_CONFIG_INT, "-splinesteps", NULL, NULL, - "12", Tk_Offset(PolygonItem, splineSteps), TK_CONFIG_DONT_SET_DEFAULT}, + "12", Tk_Offset(PolygonItem, splineSteps), TK_CONFIG_DONT_SET_DEFAULT, 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}, + NULL, Tk_Offset(PolygonItem, fillStipple), TK_CONFIG_NULL_OK, NULL}, {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, NULL, NULL, NULL, NULL, 0, 0} + {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0, NULL} }; /* @@ -158,10 +151,10 @@ 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); + 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[]); + int objc, Tcl_Obj *const objv[]); static void DeletePolygon(Tk_Canvas canvas, Tk_Item *itemPtr, Display *display); static void DisplayPolygon(Tk_Canvas canvas, @@ -172,7 +165,7 @@ static int GetPolygonIndex(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[]); + 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, @@ -203,18 +196,19 @@ Tk_ItemType tkPolygonType = { PolygonCoords, /* coordProc */ DeletePolygon, /* deleteProc */ DisplayPolygon, /* displayProc */ - TK_CONFIG_OBJS, /* flags */ + TK_CONFIG_OBJS | TK_MOVABLE_POINTS, /* flags */ PolygonToPoint, /* pointProc */ PolygonToArea, /* areaProc */ PolygonToPostscript, /* postscriptProc */ ScalePolygon, /* scaleProc */ TranslatePolygon, /* translateProc */ - (Tk_ItemIndexProc *) GetPolygonIndex,/* indexProc */ + GetPolygonIndex, /* indexProc */ NULL, /* icursorProc */ NULL, /* selectionProc */ - (Tk_ItemInsertProc *) PolygonInsert,/* insertProc */ + PolygonInsert, /* insertProc */ PolygonDeleteCoords, /* dTextProc */ NULL, /* nextPtr */ + NULL, 0, NULL, NULL }; /* @@ -251,13 +245,13 @@ CreatePolygon( 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. */ + Tcl_Obj *const objv[]) /* Arguments describing polygon. */ { PolygonItem *polyPtr = (PolygonItem *) itemPtr; int i; if (objc == 0) { - Tcl_Panic("canvas did not pass any coords\n"); + Tcl_Panic("canvas did not pass any coords"); } /* @@ -265,7 +259,7 @@ CreatePolygon( * errors during the the remainder of this function. */ - Tk_CreateOutline(&(polyPtr->outline)); + Tk_CreateOutline(&polyPtr->outline); polyPtr->numPoints = 0; polyPtr->pointsAllocated = 0; polyPtr->coordPtr = NULL; @@ -291,7 +285,8 @@ CreatePolygon( */ for (i = 0; i < objc; i++) { - char *arg = Tcl_GetString(objv[i]); + const char *arg = Tcl_GetString(objv[i]); + if ((arg[0] == '-') && (arg[1] >= 'a') && (arg[1] <= 'z')) { break; } @@ -334,7 +329,7 @@ PolygonCoords( 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, ... */ + Tcl_Obj *const objv[]) /* Array of coordinates: x1, y1, x2, y2, ... */ { PolygonItem *polyPtr = (PolygonItem *) itemPtr; int i, numPoints; @@ -361,50 +356,48 @@ PolygonCoords( } } 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); + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "wrong # coordinates: expected an even number, got %d", + objc)); return TCL_ERROR; - } else { - numPoints = objc/2; - if (polyPtr->pointsAllocated <= numPoints) { - if (polyPtr->coordPtr != NULL) { - ckfree((char *) polyPtr->coordPtr); - } - - /* - * One extra point gets allocated here, because we always add - * another point to close the polygon. - */ + } - polyPtr->coordPtr = (double *) ckalloc((unsigned) - (sizeof(double) * (objc+2))); - polyPtr->pointsAllocated = numPoints+1; - } - for (i = objc-1; i >= 0; i--) { - if (Tk_CanvasGetCoordFromObj(interp, canvas, objv[i], - &polyPtr->coordPtr[i]) != TCL_OK) { - return TCL_ERROR; - } + numPoints = objc/2; + if (polyPtr->pointsAllocated <= numPoints) { + if (polyPtr->coordPtr != NULL) { + ckfree(polyPtr->coordPtr); } - polyPtr->numPoints = numPoints; - polyPtr->autoClosed = 0; /* - * Close the polygon if it isn't already closed. + * One extra point gets allocated here, because we always add + * another point to close the polygon. */ - if (objc>2 && ((polyPtr->coordPtr[objc-2] != polyPtr->coordPtr[0]) - || (polyPtr->coordPtr[objc-1] != polyPtr->coordPtr[1]))) { - polyPtr->autoClosed = 1; - polyPtr->numPoints++; - polyPtr->coordPtr[objc] = polyPtr->coordPtr[0]; - polyPtr->coordPtr[objc+1] = polyPtr->coordPtr[1]; + polyPtr->coordPtr = ckalloc(sizeof(double) * (objc+2)); + polyPtr->pointsAllocated = numPoints+1; + } + for (i = objc-1; i >= 0; i--) { + if (Tk_CanvasGetCoordFromObj(interp, canvas, objv[i], + &polyPtr->coordPtr[i]) != TCL_OK) { + return TCL_ERROR; } - ComputePolygonBbox(canvas, polyPtr); } + polyPtr->numPoints = numPoints; + polyPtr->autoClosed = 0; + + /* + * 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; + polyPtr->numPoints++; + polyPtr->coordPtr[objc] = polyPtr->coordPtr[0]; + polyPtr->coordPtr[objc+1] = polyPtr->coordPtr[1]; + } + + ComputePolygonBbox(canvas, polyPtr); return TCL_OK; } @@ -433,7 +426,7 @@ ConfigurePolygon( 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. */ + Tcl_Obj *const objv[], /* Arguments describing things to configure. */ int flags) /* Flags to pass to Tk_ConfigureWidget. */ { PolygonItem *polyPtr = (PolygonItem *) itemPtr; @@ -447,7 +440,7 @@ ConfigurePolygon( tkwin = Tk_CanvasTkwin(canvas); if (TCL_OK != Tk_ConfigureWidget(interp, tkwin, configSpecs, objc, - (CONST char **) objv, (char *) polyPtr, flags|TK_CONFIG_OBJS)) { + (const char **) objv, (char *) polyPtr, flags|TK_CONFIG_OBJS)) { return TCL_ERROR; } @@ -469,15 +462,15 @@ ConfigurePolygon( itemPtr->redraw_flags &= ~TK_ITEM_STATE_DEPENDANT; } - if(state == TK_STATE_NULL) { - state = ((TkCanvas *)canvas)->canvas_state; + if (state == TK_STATE_NULL) { + state = Canvas(canvas)->canvas_state; } - if (state==TK_STATE_HIDDEN) { + if (state == TK_STATE_HIDDEN) { ComputePolygonBbox(canvas, polyPtr); return TCL_OK; } - mask = Tk_ConfigOutlineGC(&gcValues, canvas, itemPtr, &(polyPtr->outline)); + mask = Tk_ConfigOutlineGC(&gcValues, canvas, itemPtr, &polyPtr->outline); if (mask) { gcValues.cap_style = CapRound; gcValues.join_style = polyPtr->joinStyle; @@ -493,18 +486,18 @@ ConfigurePolygon( color = polyPtr->fillColor; stipple = polyPtr->fillStipple; - if (((TkCanvas *)canvas)->currentItemPtr == itemPtr) { - if (polyPtr->activeFillColor!=NULL) { + if (Canvas(canvas)->currentItemPtr == itemPtr) { + if (polyPtr->activeFillColor != NULL) { color = polyPtr->activeFillColor; } - if (polyPtr->activeFillStipple!=None) { + if (polyPtr->activeFillStipple != None) { stipple = polyPtr->activeFillStipple; } - } else if (state==TK_STATE_DISABLED) { - if (polyPtr->disabledFillColor!=NULL) { + } else if (state == TK_STATE_DISABLED) { + if (polyPtr->disabledFillColor != NULL) { color = polyPtr->disabledFillColor; } - if (polyPtr->disabledFillStipple!=None) { + if (polyPtr->disabledFillStipple != None) { stipple = polyPtr->disabledFillStipple; } } @@ -524,7 +517,7 @@ ConfigurePolygon( * Mac OS X CG drawing needs access to the outline linewidth * even for fills (as linewidth controls antialiasing). */ - gcValues.line_width = polyPtr->outline.gc != None ? + gcValues.line_width = polyPtr->outline.gc != None ? polyPtr->outline.gc->line_width : 0; mask |= GCLineWidth; #endif @@ -574,9 +567,9 @@ DeletePolygon( { PolygonItem *polyPtr = (PolygonItem *) itemPtr; - Tk_DeleteOutline(display,&(polyPtr->outline)); + Tk_DeleteOutline(display, &polyPtr->outline); if (polyPtr->coordPtr != NULL) { - ckfree((char *) polyPtr->coordPtr); + ckfree(polyPtr->coordPtr); } if (polyPtr->fillColor != NULL) { Tk_FreeColor(polyPtr->fillColor); @@ -629,21 +622,22 @@ ComputePolygonBbox( Tk_State state = polyPtr->header.state; Tk_TSOffset *tsoffset; - if(state == TK_STATE_NULL) { - state = ((TkCanvas *)canvas)->canvas_state; + if (state == TK_STATE_NULL) { + state = Canvas(canvas)->canvas_state; } width = polyPtr->outline.width; - if (polyPtr->coordPtr == NULL || (polyPtr->numPoints < 1) || (state==TK_STATE_HIDDEN)) { + if (polyPtr->coordPtr == NULL || (polyPtr->numPoints < 1) + || (state == TK_STATE_HIDDEN)) { polyPtr->header.x1 = polyPtr->header.x2 = - polyPtr->header.y1 = polyPtr->header.y2 = -1; + polyPtr->header.y1 = polyPtr->header.y2 = -1; return; } - if (((TkCanvas *)canvas)->currentItemPtr == (Tk_Item *)polyPtr) { - if (polyPtr->outline.activeWidth>width) { + if (Canvas(canvas)->currentItemPtr == (Tk_Item *) polyPtr) { + if (polyPtr->outline.activeWidth > width) { width = polyPtr->outline.activeWidth; } - } else if (state==TK_STATE_DISABLED) { - if (polyPtr->outline.disabledWidth>0.0) { + } else if (state == TK_STATE_DISABLED) { + if (polyPtr->outline.disabledWidth > 0.0) { width = polyPtr->outline.disabledWidth; } } @@ -669,6 +663,7 @@ ComputePolygonBbox( tsoffset = &polyPtr->tsoffset; if (tsoffset->flags & TK_OFFSET_INDEX) { int index = tsoffset->flags & ~TK_OFFSET_INDEX; + if (tsoffset->flags == INT_MAX) { index = (polyPtr->numPoints - polyPtr->autoClosed) * 2; if (index < 0) { @@ -676,7 +671,7 @@ ComputePolygonBbox( } } index %= (polyPtr->numPoints - polyPtr->autoClosed) * 2; - if (index <0) { + if (index < 0) { index += (polyPtr->numPoints - polyPtr->autoClosed) * 2; } tsoffset->xoffset = (int) (polyPtr->coordPtr[index] + 0.5); @@ -708,7 +703,7 @@ ComputePolygonBbox( index = (polyPtr->numPoints - 1) * 2; } index %= (polyPtr->numPoints - 1) * 2; - if (index <0) { + if (index < 0) { index += (polyPtr->numPoints - 1) * 2; } tsoffset->xoffset = (int) (polyPtr->coordPtr[index] + 0.5); @@ -717,21 +712,23 @@ ComputePolygonBbox( if (tsoffset->flags & TK_OFFSET_LEFT) { tsoffset->xoffset = polyPtr->header.x1; } else if (tsoffset->flags & TK_OFFSET_CENTER) { - tsoffset->xoffset = (polyPtr->header.x1 + polyPtr->header.x2)/2; + tsoffset->xoffset = + (polyPtr->header.x1 + polyPtr->header.x2) / 2; } else if (tsoffset->flags & TK_OFFSET_RIGHT) { tsoffset->xoffset = polyPtr->header.x2; } if (tsoffset->flags & TK_OFFSET_TOP) { tsoffset->yoffset = polyPtr->header.y1; } else if (tsoffset->flags & TK_OFFSET_MIDDLE) { - tsoffset->yoffset = (polyPtr->header.y1 + polyPtr->header.y2)/2; + tsoffset->yoffset = + (polyPtr->header.y1 + polyPtr->header.y2) / 2; } else if (tsoffset->flags & TK_OFFSET_BOTTOM) { tsoffset->yoffset = polyPtr->header.y2; } } } - i = (int) ((width+1.5)/2.0); + i = (int) ((width+1.5) / 2.0); polyPtr->header.x1 -= i; polyPtr->header.x2 += i; polyPtr->header.y1 -= i; @@ -748,19 +745,17 @@ ComputePolygonBbox( int j; coordPtr = polyPtr->coordPtr; - if (polyPtr->numPoints>3) { + if (polyPtr->numPoints > 3) { if (TkGetMiterPoints(coordPtr+2*(polyPtr->numPoints-2), - coordPtr, coordPtr+2, width, - miter, miter+2)) { + coordPtr, coordPtr+2, width, miter, miter+2)) { for (j = 0; j < 4; j += 2) { TkIncludePoint((Tk_Item *) polyPtr, miter+j); } } - } + } for (i = polyPtr->numPoints ; i >= 3; i--, coordPtr += 2) { - - if (TkGetMiterPoints(coordPtr, coordPtr+2, coordPtr+4, - width, miter, miter+2)) { + if (TkGetMiterPoints(coordPtr, coordPtr+2, coordPtr+4, width, + miter, miter+2)) { for (j = 0; j < 4; j += 2) { TkIncludePoint((Tk_Item *) polyPtr, miter+j); } @@ -827,7 +822,7 @@ TkFillPolygon( if (numPoints <= MAX_STATIC_POINTS) { pointPtr = staticPoints; } else { - pointPtr = (XPoint *) ckalloc((unsigned) (numPoints * sizeof(XPoint))); + pointPtr = ckalloc(numPoints * sizeof(XPoint)); } for (i=0, pPtr=pointPtr ; i<numPoints; i+=1, coordPtr+=2, pPtr++) { @@ -840,16 +835,16 @@ TkFillPolygon( * allocated. */ - if (gc != None && numPoints>3) { + if (gc != None && numPoints > 3) { XFillPolygon(display, drawable, gc, pointPtr, numPoints, Complex, CoordModeOrigin); } if (outlineGC != None) { - XDrawLines(display, drawable, outlineGC, pointPtr, - numPoints, CoordModeOrigin); + XDrawLines(display, drawable, outlineGC, pointPtr, numPoints, + CoordModeOrigin); } if (pointPtr != staticPoints) { - ckfree((char *) pointPtr); + ckfree(pointPtr); } } @@ -892,17 +887,17 @@ DisplayPolygon( } if (state == TK_STATE_NULL) { - state = ((TkCanvas *)canvas)->canvas_state; + state = Canvas(canvas)->canvas_state; } - if (((TkCanvas *)canvas)->currentItemPtr == itemPtr) { - if (polyPtr->outline.activeWidth>linewidth) { + if (Canvas(canvas)->currentItemPtr == itemPtr) { + if (polyPtr->outline.activeWidth > linewidth) { linewidth = polyPtr->outline.activeWidth; } if (polyPtr->activeFillStipple != None) { stipple = polyPtr->activeFillStipple; } - } else if (state==TK_STATE_DISABLED) { - if (polyPtr->outline.disabledWidth>0.0) { + } else if (state == TK_STATE_DISABLED) { + if (polyPtr->outline.disabledWidth > 0.0) { linewidth = polyPtr->outline.disabledWidth; } if (polyPtr->disabledFillStipple != None) { @@ -917,10 +912,11 @@ DisplayPolygon( if ((stipple != None) && (polyPtr->fillGC != None)) { Tk_TSOffset *tsoffset = &polyPtr->tsoffset; - int w=0; int h=0; + int w = 0, h = 0; int flags = tsoffset->flags; - if (!(flags & TK_OFFSET_INDEX) && (flags & (TK_OFFSET_CENTER|TK_OFFSET_MIDDLE))) { + if (!(flags & TK_OFFSET_INDEX) + && (flags & (TK_OFFSET_CENTER|TK_OFFSET_MIDDLE))) { Tk_SizeOfBitmap(display, stipple, &w, &h); if (flags & TK_OFFSET_CENTER) { w /= 2; @@ -939,20 +935,20 @@ DisplayPolygon( tsoffset->xoffset += w; tsoffset->yoffset += h; } - Tk_ChangeOutlineGC(canvas, itemPtr, &(polyPtr->outline)); + Tk_ChangeOutlineGC(canvas, itemPtr, &polyPtr->outline); - if(polyPtr->numPoints < 3) { - short x,y; + if (polyPtr->numPoints < 3) { + short x, y; int intLineWidth = (int) (linewidth + 0.5); if (intLineWidth < 1) { intLineWidth = 1; } Tk_CanvasDrawableCoords(canvas, polyPtr->coordPtr[0], - polyPtr->coordPtr[1], &x,&y); + polyPtr->coordPtr[1], &x, &y); XFillArc(display, drawable, polyPtr->outline.gc, x - intLineWidth/2, y - intLineWidth/2, - (unsigned int)intLineWidth+1, (unsigned int)intLineWidth+1, + (unsigned) intLineWidth+1, (unsigned) intLineWidth+1, 0, 64*360); } else if (!polyPtr->smooth || polyPtr->numPoints < 4) { TkFillPolygon(canvas, polyPtr->coordPtr, polyPtr->numPoints, @@ -972,8 +968,7 @@ DisplayPolygon( if (numPoints <= MAX_STATIC_POINTS) { pointPtr = staticPoints; } else { - pointPtr = (XPoint *) ckalloc((unsigned) - (numPoints * sizeof(XPoint))); + pointPtr = ckalloc(numPoints * sizeof(XPoint)); } numPoints = polyPtr->smooth->coordProc(canvas, polyPtr->coordPtr, polyPtr->numPoints, polyPtr->splineSteps, pointPtr, NULL); @@ -986,10 +981,10 @@ DisplayPolygon( numPoints, CoordModeOrigin); } if (pointPtr != staticPoints) { - ckfree((char *) pointPtr); + ckfree(pointPtr); } } - Tk_ResetOutlineGC(canvas, itemPtr, &(polyPtr->outline)); + Tk_ResetOutlineGC(canvas, itemPtr, &polyPtr->outline); if ((stipple != None) && (polyPtr->fillGC != None)) { XSetTSOrigin(display, polyPtr->fillGC, 0, 0); } @@ -1026,7 +1021,7 @@ PolygonInsert( Tk_State state = itemPtr->state; if (state == TK_STATE_NULL) { - state = ((TkCanvas *)canvas)->canvas_state; + state = Canvas(canvas)->canvas_state; } if (!obj || (Tcl_ListObjGetElements(NULL, obj, &objc, &objv) != TCL_OK) @@ -1034,21 +1029,20 @@ PolygonInsert( return; } length = 2*(polyPtr->numPoints - polyPtr->autoClosed); - while (beforeThis>length) { + while (beforeThis > length) { beforeThis -= length; } - while (beforeThis<0) { + while (beforeThis < 0) { beforeThis += length; } - newCoordPtr = (double *) - ckalloc(sizeof(double) * (unsigned)(length + 2 + objc)); + newCoordPtr = ckalloc(sizeof(double) * (length + 2 + objc)); for (i=0; i<beforeThis; i++) { newCoordPtr[i] = polyPtr->coordPtr[i]; } for (i=0; i<objc; i++) { if (Tcl_GetDoubleFromObj(NULL, objv[i], &newCoordPtr[i+beforeThis]) != TCL_OK){ - ckfree((char *) newCoordPtr); + ckfree(newCoordPtr); return; } } @@ -1057,7 +1051,7 @@ PolygonInsert( newCoordPtr[i+objc] = polyPtr->coordPtr[i]; } if (polyPtr->coordPtr) { - ckfree((char *) polyPtr->coordPtr); + ckfree(polyPtr->coordPtr); } length += objc; polyPtr->coordPtr = newCoordPtr; @@ -1084,7 +1078,7 @@ PolygonInsert( newCoordPtr[length] = newCoordPtr[0]; newCoordPtr[length+1] = newCoordPtr[1]; - if (((length-objc)>3) && (state != TK_STATE_HIDDEN)) { + 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 @@ -1096,6 +1090,7 @@ PolygonInsert( double width; int j; + itemPtr->redraw_flags |= TK_ITEM_DONT_REDRAW; /* @@ -1107,10 +1102,11 @@ PolygonInsert( itemPtr->x1 = itemPtr->x2 = (int) polyPtr->coordPtr[beforeThis]; itemPtr->y1 = itemPtr->y2 = (int) polyPtr->coordPtr[beforeThis+1]; - beforeThis-=2; objc+=4; + beforeThis -= 2; + objc += 4; if (polyPtr->smooth) { - beforeThis-=2; - objc+=4; + beforeThis -= 2; + objc += 4; } /* @@ -1119,25 +1115,27 @@ PolygonInsert( for (i=beforeThis; i<beforeThis+objc; i+=2) { j = i; - if (j<0) { + if (j < 0) { j += length; - } else if (j>=length) { + } else if (j >= length) { j -= length; } TkIncludePoint(itemPtr, polyPtr->coordPtr+j); } width = polyPtr->outline.width; - if (((TkCanvas *)canvas)->currentItemPtr == itemPtr) { + if (Canvas(canvas)->currentItemPtr == itemPtr) { if (polyPtr->outline.activeWidth > width) { width = polyPtr->outline.activeWidth; } - } else if (state==TK_STATE_DISABLED) { + } else if (state == TK_STATE_DISABLED) { 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; + 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); } @@ -1173,16 +1171,16 @@ PolygonDeleteCoords( int count, i; int length = 2*(polyPtr->numPoints - polyPtr->autoClosed); - while (first>=length) { + while (first >= length) { first -= length; } - while (first<0) { + while (first < 0) { first += length; } - while (last>=length) { + while (last >= length) { last -= length; } - while (last<0) { + while (last < 0) { last += length; } @@ -1190,26 +1188,26 @@ PolygonDeleteCoords( last &= -2; count = last + 2 - first; - if (count<=0) { + if (count <= 0) { count += length; } if (count >= length) { polyPtr->numPoints = 0; if (polyPtr->coordPtr != NULL) { - ckfree((char *) polyPtr->coordPtr); + ckfree(polyPtr->coordPtr); polyPtr->coordPtr = NULL; } ComputePolygonBbox(canvas, polyPtr); return; } - if (last>=first) { - for(i=last+2; i<length; i++) { + if (last >= first) { + for (i=last+2; i<length; i++) { polyPtr->coordPtr[i-count] = polyPtr->coordPtr[i]; } } else { - for(i=last; i<=first; i++) { + for (i=last; i<=first; i++) { polyPtr->coordPtr[i-last] = polyPtr->coordPtr[i]; } } @@ -1262,15 +1260,15 @@ PolygonToPoint( bestDist = 1.0e36; if (state == TK_STATE_NULL) { - state = ((TkCanvas *)canvas)->canvas_state; + state = Canvas(canvas)->canvas_state; } width = polyPtr->outline.width; - if (((TkCanvas *)canvas)->currentItemPtr == itemPtr) { - if (polyPtr->outline.activeWidth>width) { + if (Canvas(canvas)->currentItemPtr == itemPtr) { + if (polyPtr->outline.activeWidth > width) { width = polyPtr->outline.activeWidth; } - } else if (state==TK_STATE_DISABLED) { - if (polyPtr->outline.disabledWidth>0.0) { + } else if (state == TK_STATE_DISABLED) { + if (polyPtr->outline.disabledWidth > 0.0) { width = polyPtr->outline.disabledWidth; } } @@ -1281,26 +1279,23 @@ PolygonToPoint( * against which to do the check. */ - if ((polyPtr->smooth) && (polyPtr->numPoints>2)) { + if ((polyPtr->smooth) && (polyPtr->numPoints > 2)) { numPoints = polyPtr->smooth->coordProc(canvas, NULL, - polyPtr->numPoints, polyPtr->splineSteps, NULL, - NULL); + polyPtr->numPoints, polyPtr->splineSteps, NULL, NULL); if (numPoints <= MAX_STATIC_POINTS) { polyPoints = staticSpace; } else { - polyPoints = (double *) ckalloc((unsigned) - (2*numPoints*sizeof(double))); + polyPoints = ckalloc(2 * numPoints * sizeof(double)); } numPoints = polyPtr->smooth->coordProc(canvas, polyPtr->coordPtr, - polyPtr->numPoints, polyPtr->splineSteps, NULL, - polyPoints); + polyPtr->numPoints, polyPtr->splineSteps, NULL, polyPoints); } else { numPoints = polyPtr->numPoints; polyPoints = polyPtr->coordPtr; } bestDist = TkPolygonToPoint(polyPoints, numPoints, pointPtr); - if (bestDist<=0.0) { + if (bestDist <= 0.0) { goto donepoint; } if ((polyPtr->outline.gc != None) && (polyPtr->joinStyle == JoinRound)) { @@ -1350,16 +1345,16 @@ PolygonToPoint( */ if (count == numPoints) { - TkGetButtPoints(coordPtr+2, coordPtr, (double) width, - 0, poly, poly+2); + TkGetButtPoints(coordPtr+2, coordPtr, (double) 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, (double) width, 0, - poly, poly+2); + TkGetButtPoints(coordPtr+2, coordPtr, (double) width, 0, poly, + poly+2); /* * If this line uses beveled joints, then check the distance to a @@ -1382,8 +1377,8 @@ PolygonToPoint( } } if (count == 2) { - TkGetButtPoints(coordPtr, coordPtr+2, (double) width, - 0, poly+4, poly+6); + TkGetButtPoints(coordPtr, coordPtr+2, (double) width, 0, poly+4, + poly+6); } else if (polyPtr->joinStyle == JoinMiter) { if (TkGetMiterPoints(coordPtr, coordPtr+2, coordPtr+4, (double) width, poly+4, poly+6) == 0) { @@ -1392,8 +1387,8 @@ PolygonToPoint( poly+4, poly+6); } } else { - TkGetButtPoints(coordPtr, coordPtr+2, (double) width, 0, - poly+4, poly+6); + TkGetButtPoints(coordPtr, coordPtr+2, (double) width, 0, poly+4, + poly+6); } poly[8] = poly[0]; poly[9] = poly[1]; @@ -1407,8 +1402,8 @@ PolygonToPoint( } donepoint: - if ((polyPoints != staticSpace) && polyPoints != polyPtr->coordPtr) { - ckfree((char *) polyPoints); + if (polyPoints != staticSpace && polyPoints != polyPtr->coordPtr) { + ckfree(polyPoints); } return bestDist; } @@ -1459,16 +1454,16 @@ PolygonToArea( Tk_State state = itemPtr->state; if (state == TK_STATE_NULL) { - state = ((TkCanvas *)canvas)->canvas_state; + state = Canvas(canvas)->canvas_state; } width = polyPtr->outline.width; - if (((TkCanvas *)canvas)->currentItemPtr == itemPtr) { - if (polyPtr->outline.activeWidth>width) { + if (Canvas(canvas)->currentItemPtr == itemPtr) { + if (polyPtr->outline.activeWidth > width) { width = polyPtr->outline.activeWidth; } - } else if (state==TK_STATE_DISABLED) { - if (polyPtr->outline.disabledWidth>0.0) { + } else if (state == TK_STATE_DISABLED) { + if (polyPtr->outline.disabledWidth > 0.0) { width = polyPtr->outline.disabledWidth; } } @@ -1476,9 +1471,9 @@ PolygonToArea( radius = width/2.0; inside = -1; - if ((state==TK_STATE_HIDDEN) || polyPtr->numPoints<2) { + if ((state == TK_STATE_HIDDEN) || polyPtr->numPoints < 2) { return -1; - } else if (polyPtr->numPoints <3) { + } else if (polyPtr->numPoints < 3) { double oval[4]; oval[0] = polyPtr->coordPtr[0]-radius; @@ -1499,8 +1494,7 @@ PolygonToArea( if (numPoints <= MAX_STATIC_POINTS) { polyPoints = staticSpace; } else { - polyPoints = (double *) - ckalloc((unsigned) (2*numPoints*sizeof(double))); + polyPoints = ckalloc(2 * numPoints * sizeof(double)); } numPoints = polyPtr->smooth->coordProc(canvas, polyPtr->coordPtr, polyPtr->numPoints, polyPtr->splineSteps, NULL, polyPoints); @@ -1516,7 +1510,7 @@ PolygonToArea( */ inside = TkPolygonToArea(polyPoints, numPoints, rectPtr); - if (inside==0) { + if (inside == 0) { goto donearea; } @@ -1585,8 +1579,8 @@ PolygonToArea( if (count == 2) { 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) { + 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); } @@ -1603,7 +1597,7 @@ PolygonToArea( donearea: if ((polyPoints != staticSpace) && (polyPoints != polyPtr->coordPtr)) { - ckfree((char *) polyPoints); + ckfree(polyPoints); } return inside; } @@ -1679,26 +1673,18 @@ GetPolygonIndex( { PolygonItem *polyPtr = (PolygonItem *) itemPtr; int length; - char *string = Tcl_GetStringFromObj(obj, &length); + const char *string = Tcl_GetStringFromObj(obj, &length); if (string[0] == 'e') { - if (strncmp(string, "end", (unsigned)length) == 0) { - *indexPtr = 2*(polyPtr->numPoints - polyPtr->autoClosed); - } else { - /* - * Some of the paths here leave messages in interp->result, so we - * have to clear it out before storing our own message. - */ - - badIndex: - Tcl_SetResult(interp, NULL, TCL_STATIC); - Tcl_AppendResult(interp, "bad index \"", string, "\"", NULL); - return TCL_ERROR; + if (strncmp(string, "end", (unsigned)length) != 0) { + goto badIndex; } + *indexPtr = 2*(polyPtr->numPoints - polyPtr->autoClosed); } else if (string[0] == '@') { int i; - double x ,y, bestDist, dist, *coordPtr; - char *end, *p; + double x, y, bestDist, dist, *coordPtr; + char *end; + const char *p; p = string+1; x = strtod(p, &end); @@ -1713,9 +1699,9 @@ GetPolygonIndex( bestDist = 1.0e36; coordPtr = polyPtr->coordPtr; *indexPtr = 0; - for(i=0; i<(polyPtr->numPoints-1); i++) { + for (i=0; i<polyPtr->numPoints-1; i++) { dist = hypot(coordPtr[0] - x, coordPtr[1] - y); - if (dist<bestDist) { + if (dist < bestDist) { bestDist = dist; *indexPtr = 2*i; } @@ -1728,17 +1714,24 @@ GetPolygonIndex( goto badIndex; } *indexPtr &= -2; /* if odd, make it even */ - if (count) { - if (*indexPtr > 0) { - *indexPtr = ((*indexPtr - 2) % count) + 2; - } else { - *indexPtr = -((-(*indexPtr)) % count); - } - } else { + if (!count) { *indexPtr = 0; + } else if (*indexPtr > 0) { + *indexPtr = ((*indexPtr - 2) % count) + 2; + } else { + *indexPtr = -((-(*indexPtr)) % count); } } return TCL_OK; + + /* + * Some of the paths here leave messages in interp->result, so we have to + * clear it out before storing our own message. + */ + + badIndex: + Tcl_SetObjResult(interp, Tcl_ObjPrintf("bad index \"%s\"", string)); + return TCL_ERROR; } /* @@ -1806,7 +1799,7 @@ PolygonToPostscript( * being created. */ { PolygonItem *polyPtr = (PolygonItem *) itemPtr; - char *style; + const char *style; XColor *color; XColor *fillColor; Pixmap stipple; @@ -1814,62 +1807,76 @@ PolygonToPostscript( Tk_State state = itemPtr->state; double width; - if (polyPtr->numPoints<2 || polyPtr->coordPtr==NULL) { + if (polyPtr->numPoints < 2 || polyPtr->coordPtr == NULL) { return TCL_OK; } - if(state == TK_STATE_NULL) { - state = ((TkCanvas *)canvas)->canvas_state; + if (state == TK_STATE_NULL) { + state = Canvas(canvas)->canvas_state; } width = polyPtr->outline.width; color = polyPtr->outline.color; stipple = polyPtr->fillStipple; fillColor = polyPtr->fillColor; fillStipple = polyPtr->fillStipple; - if (((TkCanvas *)canvas)->currentItemPtr == itemPtr) { - if (polyPtr->outline.activeWidth>width) { + if (Canvas(canvas)->currentItemPtr == itemPtr) { + if (polyPtr->outline.activeWidth > width) { width = polyPtr->outline.activeWidth; } - if (polyPtr->outline.activeColor!=NULL) { + if (polyPtr->outline.activeColor != NULL) { color = polyPtr->outline.activeColor; } - if (polyPtr->outline.activeStipple!=None) { + if (polyPtr->outline.activeStipple != None) { stipple = polyPtr->outline.activeStipple; } - if (polyPtr->activeFillColor!=NULL) { + if (polyPtr->activeFillColor != NULL) { fillColor = polyPtr->activeFillColor; } - if (polyPtr->activeFillStipple!=None) { + if (polyPtr->activeFillStipple != None) { fillStipple = polyPtr->activeFillStipple; } - } else if (state==TK_STATE_DISABLED) { - if (polyPtr->outline.disabledWidth>0.0) { + } else if (state == TK_STATE_DISABLED) { + if (polyPtr->outline.disabledWidth > 0.0) { width = polyPtr->outline.disabledWidth; } - if (polyPtr->outline.disabledColor!=NULL) { + if (polyPtr->outline.disabledColor != NULL) { color = polyPtr->outline.disabledColor; } - if (polyPtr->outline.disabledStipple!=None) { + if (polyPtr->outline.disabledStipple != None) { stipple = polyPtr->outline.disabledStipple; } - if (polyPtr->disabledFillColor!=NULL) { + if (polyPtr->disabledFillColor != NULL) { fillColor = polyPtr->disabledFillColor; } - if (polyPtr->disabledFillStipple!=None) { + if (polyPtr->disabledFillStipple != None) { fillStipple = polyPtr->disabledFillStipple; } } - if (polyPtr->numPoints==2) { - char string[128]; + if (polyPtr->numPoints == 2) { if (color == NULL) { return TCL_OK; } - sprintf(string, "%.15g %.15g translate %.15g %.15g", - 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", NULL); + /* + * Create a point by using a small circle. (Printer pixels are too + * tiny to be used directly...) + */ + + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "matrix currentmatrix\n" /* save state */ + "%.15g %.15g translate " /* go to drawing location */ + "%.15g %.15g scale " /* scale the drawing */ + "1 0 moveto " /* correct for origin */ + "0 0 1 0 360 arc\n" /* make the circle */ + "setmatrix\n", /* restore state */ + polyPtr->coordPtr[0], + Tk_CanvasPsY(canvas, polyPtr->coordPtr[1]), + width/2.0, width/2.0)); + + /* + * Color it in. + */ + if (Tk_CanvasPsColor(interp, canvas, color) != TCL_OK) { return TCL_ERROR; } @@ -1888,7 +1895,7 @@ PolygonToPostscript( * Fill the area of the polygon. */ - if (fillColor != NULL && polyPtr->numPoints>3) { + if (fillColor != NULL && polyPtr->numPoints > 3) { if (!polyPtr->smooth || !polyPtr->smooth->postscriptProc) { Tk_CanvasPsPath(interp, canvas, polyPtr->coordPtr, polyPtr->numPoints); @@ -1932,9 +1939,8 @@ PolygonToPostscript( } else { style = "0"; } - Tcl_AppendResult(interp, style," setlinejoin 1 setlinecap\n", NULL); - if (Tk_CanvasPsOutline(canvas, itemPtr, - &(polyPtr->outline)) != TCL_OK) { + Tcl_AppendResult(interp, style, " setlinejoin 1 setlinecap\n", NULL); + if (Tk_CanvasPsOutline(canvas, itemPtr, &polyPtr->outline) != TCL_OK){ return TCL_ERROR; } } |