diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2021-12-04 19:28:20 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2021-12-04 19:28:20 (GMT) |
commit | 673d172ff18004c4391acdfd660952d372590ecd (patch) | |
tree | 002b43200386d46bbab8b0f3647425735f3a5137 /generic/tkCanvPoly.c | |
parent | a269ff1c77f5929fd61cf8d5554f4f3d25178791 (diff) | |
parent | e47562da179226f06657be6314f662b18cc46e69 (diff) | |
download | tk-673d172ff18004c4391acdfd660952d372590ecd.zip tk-673d172ff18004c4391acdfd660952d372590ecd.tar.gz tk-673d172ff18004c4391acdfd660952d372590ecd.tar.bz2 |
Merge 8.6
Diffstat (limited to 'generic/tkCanvPoly.c')
-rw-r--r-- | generic/tkCanvPoly.c | 92 |
1 files changed, 65 insertions, 27 deletions
diff --git a/generic/tkCanvPoly.c b/generic/tkCanvPoly.c index 90b2896..86e21f0 100644 --- a/generic/tkCanvPoly.c +++ b/generic/tkCanvPoly.c @@ -1021,7 +1021,7 @@ PolygonInsert( Tcl_Obj *obj) /* New coordinates to be inserted. */ { PolygonItem *polyPtr = (PolygonItem *) itemPtr; - int length, objc, i; + int length, oriNumPoints, objc, nbInsPoints, i; Tcl_Obj **objv; double *newCoordPtr; Tk_State state = itemPtr->state; @@ -1034,7 +1034,9 @@ PolygonInsert( || !objc || objc&1) { return; } + oriNumPoints = polyPtr->numPoints - polyPtr->autoClosed; length = 2*(polyPtr->numPoints - polyPtr->autoClosed); + nbInsPoints = objc / 2; while ((int)beforeThis > length) { beforeThis -= length; } @@ -1092,6 +1094,8 @@ PolygonInsert( * 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. + * Rationale for the optimization code can be found in Tk ticket + * [5fb8145997]. */ double width; @@ -1108,42 +1112,76 @@ PolygonInsert( 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; - } + if (!strcmp(polyPtr->smooth->name, "true")) { + /* + * Quadratic Bezier splines. + */ + + beforeThis -= 2; + objc += 4; + + } else if (!strcmp(polyPtr->smooth->name, "raw")) { + /* + * Cubic Bezier splines. + */ + + if ((oriNumPoints % 3) || (nbInsPoints % 3)) { + /* + * No optimization for "degenerate" polygons or when inserting + * something else than a multiple of 3 points. + */ + + itemPtr->redraw_flags &= ~TK_ITEM_DONT_REDRAW; + } else { + beforeThis -= abs((int)beforeThis) % 6; + objc += 4; + } - /* - * Be careful; beforeThis could now be negative - */ + } else { + /* + * Custom smoothing method. No optimization is possible. + */ - for (i=beforeThis; i<(int)beforeThis+objc; i+=2) { - j = i; - if (j < 0) { - j += length; - } else if (j >= length) { - j -= length; + itemPtr->redraw_flags &= ~TK_ITEM_DONT_REDRAW; } - TkIncludePoint(itemPtr, polyPtr->coordPtr+j); } - width = polyPtr->outline.width; - if (Canvas(canvas)->currentItemPtr == itemPtr) { - if (polyPtr->outline.activeWidth > width) { - width = polyPtr->outline.activeWidth; + + if (itemPtr->redraw_flags & TK_ITEM_DONT_REDRAW) { + /* + * Be careful; beforeThis could now be negative + */ + + for (i=(int)beforeThis; i<(int)beforeThis+objc; i+=2) { + j = i; + if (j < 0) { + j += length; + } else if (j >= length) { + j -= length; + } + TkIncludePoint(itemPtr, polyPtr->coordPtr+j); } - } else if (state == TK_STATE_DISABLED) { - if (polyPtr->outline.disabledWidth > 0.0) { - width = polyPtr->outline.disabledWidth; + width = polyPtr->outline.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) { + 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 -= (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); } ComputePolygonBbox(canvas, polyPtr); |