From aa019c08a152fc9d3fd124aa780af6c90f7c68ad Mon Sep 17 00:00:00 2001 From: dkf Date: Mon, 11 Mar 2019 09:43:35 +0000 Subject: Basic implementation of TIP 164: [$canvas rotate] --- generic/tk.h | 6 ++- generic/tkCanvas.c | 110 +++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 104 insertions(+), 12 deletions(-) diff --git a/generic/tk.h b/generic/tk.h index f106f1c..b5be2ce 100644 --- a/generic/tk.h +++ b/generic/tk.h @@ -1034,6 +1034,8 @@ typedef int (Tk_ItemAreaProc)(Tk_Canvas canvas, Tk_Item *itemPtr, double *rectPtr); typedef int (Tk_ItemPostscriptProc)(Tcl_Interp *interp, Tk_Canvas canvas, Tk_Item *itemPtr, int prepass); +typedef void (Tk_ItemRotateProc)(Tk_Canvas canvas, Tk_Item *itemPtr, + double originX, double originY, double angleRadians); typedef void (Tk_ItemScaleProc)(Tk_Canvas canvas, Tk_Item *itemPtr, double originX, double originY, double scaleX, double scaleY); @@ -1117,7 +1119,9 @@ typedef struct Tk_ItemType { /* Procedure to delete characters from an * item. */ struct Tk_ItemType *nextPtr;/* Used to link types together into a list. */ - char *reserved1; /* Reserved for future extension. */ + Tk_ItemRotateProc *rotateProc; + /* Procedure to rotate an item's coordinates + * about a point. */ int reserved2; /* Carefully compatible with */ char *reserved3; /* Jan Nijtmans dash patch */ char *reserved4; diff --git a/generic/tkCanvas.c b/generic/tkCanvas.c index f3778a6..8a05c86 100644 --- a/generic/tkCanvas.c +++ b/generic/tkCanvas.c @@ -560,6 +560,71 @@ ItemTranslate( itemPtr->typePtr->translateProc((Tk_Canvas) canvasPtr, itemPtr, xDelta, yDelta); } + +static inline void +ItemRotate( + TkCanvas *canvasPtr, + Tk_Item *itemPtr, + double x, + double y, + double angle) +{ + if (itemPtr->typePtr->rotateProc != NULL) { + itemPtr->typePtr->rotateProc((Tk_Canvas) canvasPtr, + itemPtr, x, y, angle); + } else { + int objc, i, ok = 1; + Tcl_Obj **objv; + double *coordv; + double s = sin(angle); + double c = cos(angle); + Tcl_Interp *interp = canvasPtr->interp; + + if (ItemCoords(canvasPtr, itemPtr, 0, NULL) == TCL_OK && + Tcl_ListObjGetElements(NULL, Tcl_GetObjResult(interp), + &objc, &objv) == TCL_OK) { + coordv = (double *) Tcl_Alloc(sizeof(double) * objc); + for (i=0 ; iflags |= REPICK_NEEDED; + } + break; + } case CANV_SCALE: { double xOrigin, yOrigin, xScale, yScale; -- cgit v0.12