📄 tkrectoval.c
字号:
* distance from the point to the oval. If itemPtr is filled, * then anywhere in the interior is considered "inside"; if * itemPtr isn't filled, then "inside" means only the area * occupied by the outline. * * Side effects: * None. * *-------------------------------------------------------------- */ /* ARGSUSED */static doubleOvalToPoint(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. */{ RectOvalItem *ovalPtr = (RectOvalItem *) itemPtr; double width; int filled; width = ovalPtr->width; filled = ovalPtr->fillGC != None; if (ovalPtr->outlineGC == None) { width = 0.0; filled = 1; } return TkOvalToPoint(ovalPtr->bbox, width, filled, pointPtr);}/* *-------------------------------------------------------------- * * RectToArea -- * * This procedure is called to determine whether an item * lies entirely inside, entirely outside, or overlapping * a given rectangle. * * 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. * * Side effects: * None. * *-------------------------------------------------------------- */ /* ARGSUSED */static intRectToArea(canvas, itemPtr, areaPtr) Tk_Canvas canvas; /* Canvas containing item. */ Tk_Item *itemPtr; /* Item to check against rectangle. */ double *areaPtr; /* Pointer to array of four coordinates * (x1, y1, x2, y2) describing rectangular * area. */{ RectOvalItem *rectPtr = (RectOvalItem *) itemPtr; double halfWidth; halfWidth = rectPtr->width/2.0; if (rectPtr->outlineGC == None) { halfWidth = 0.0; } if ((areaPtr[2] <= (rectPtr->bbox[0] - halfWidth)) || (areaPtr[0] >= (rectPtr->bbox[2] + halfWidth)) || (areaPtr[3] <= (rectPtr->bbox[1] - halfWidth)) || (areaPtr[1] >= (rectPtr->bbox[3] + halfWidth))) { return -1; } if ((rectPtr->fillGC == None) && (rectPtr->outlineGC != None) && (areaPtr[0] >= (rectPtr->bbox[0] + halfWidth)) && (areaPtr[1] >= (rectPtr->bbox[1] + halfWidth)) && (areaPtr[2] <= (rectPtr->bbox[2] - halfWidth)) && (areaPtr[3] <= (rectPtr->bbox[3] - halfWidth))) { return -1; } if ((areaPtr[0] <= (rectPtr->bbox[0] - halfWidth)) && (areaPtr[1] <= (rectPtr->bbox[1] - halfWidth)) && (areaPtr[2] >= (rectPtr->bbox[2] + halfWidth)) && (areaPtr[3] >= (rectPtr->bbox[3] + halfWidth))) { return 1; } return 0;}/* *-------------------------------------------------------------- * * OvalToArea -- * * This procedure 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. * * Side effects: * None. * *-------------------------------------------------------------- */ /* ARGSUSED */static intOvalToArea(canvas, itemPtr, areaPtr) Tk_Canvas canvas; /* Canvas containing item. */ Tk_Item *itemPtr; /* Item to check against oval. */ double *areaPtr; /* Pointer to array of four coordinates * (x1, y1, x2, y2) describing rectangular * area. */{ RectOvalItem *ovalPtr = (RectOvalItem *) itemPtr; double oval[4], halfWidth; int result; /* * Expand the oval to include the width of the outline, if any. */ halfWidth = ovalPtr->width/2.0; if (ovalPtr->outlineGC == None) { halfWidth = 0.0; } oval[0] = ovalPtr->bbox[0] - halfWidth; oval[1] = ovalPtr->bbox[1] - halfWidth; oval[2] = ovalPtr->bbox[2] + halfWidth; oval[3] = ovalPtr->bbox[3] + halfWidth; result = TkOvalToArea(oval, areaPtr); /* * If the rectangle appears to overlap the oval and the oval * isn't filled, do one more check to see if perhaps all four * of the rectangle's corners are totally inside the oval's * unfilled center, in which case we should return "outside". */ if ((result == 0) && (ovalPtr->outlineGC != None) && (ovalPtr->fillGC == None)) { double centerX, centerY, width, height; double xDelta1, yDelta1, xDelta2, yDelta2; centerX = (ovalPtr->bbox[0] + ovalPtr->bbox[2])/2.0; centerY = (ovalPtr->bbox[1] + ovalPtr->bbox[3])/2.0; width = (ovalPtr->bbox[2] - ovalPtr->bbox[0])/2.0 - halfWidth; height = (ovalPtr->bbox[3] - ovalPtr->bbox[1])/2.0 - halfWidth; xDelta1 = (areaPtr[0] - centerX)/width; xDelta1 *= xDelta1; yDelta1 = (areaPtr[1] - centerY)/height; yDelta1 *= yDelta1; xDelta2 = (areaPtr[2] - centerX)/width; xDelta2 *= xDelta2; yDelta2 = (areaPtr[3] - centerY)/height; yDelta2 *= yDelta2; if (((xDelta1 + yDelta1) < 1.0) && ((xDelta1 + yDelta2) < 1.0) && ((xDelta2 + yDelta1) < 1.0) && ((xDelta2 + yDelta2) < 1.0)) { return -1; } } return result;}/* *-------------------------------------------------------------- * * ScaleRectOval -- * * This procedure is invoked to rescale a rectangle or oval * item. * * Results: * None. * * Side effects: * The rectangle or oval 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) * *-------------------------------------------------------------- */static voidScaleRectOval(canvas, itemPtr, originX, originY, scaleX, scaleY) Tk_Canvas canvas; /* Canvas containing rectangle. */ Tk_Item *itemPtr; /* Rectangle 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. */{ RectOvalItem *rectOvalPtr = (RectOvalItem *) itemPtr; rectOvalPtr->bbox[0] = originX + scaleX*(rectOvalPtr->bbox[0] - originX); rectOvalPtr->bbox[1] = originY + scaleY*(rectOvalPtr->bbox[1] - originY); rectOvalPtr->bbox[2] = originX + scaleX*(rectOvalPtr->bbox[2] - originX); rectOvalPtr->bbox[3] = originY + scaleY*(rectOvalPtr->bbox[3] - originY); ComputeRectOvalBbox(canvas, rectOvalPtr);}/* *-------------------------------------------------------------- * * TranslateRectOval -- * * This procedure is called to move a rectangle or oval by a * given amount. * * Results: * None. * * Side effects: * The position of the rectangle or oval is offset by * (xDelta, yDelta), and the bounding box is updated in the * generic part of the item structure. * *-------------------------------------------------------------- */static voidTranslateRectOval(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. */{ RectOvalItem *rectOvalPtr = (RectOvalItem *) itemPtr; rectOvalPtr->bbox[0] += deltaX; rectOvalPtr->bbox[1] += deltaY; rectOvalPtr->bbox[2] += deltaX; rectOvalPtr->bbox[3] += deltaY; ComputeRectOvalBbox(canvas, rectOvalPtr);}/* *-------------------------------------------------------------- * * RectOvalToPostscript -- * * This procedure is called to generate Postscript for * rectangle and oval items. * * Results: * The return value is a standard Tcl result. If an error * occurs in generating Postscript then an error message is * left in interp->result, replacing whatever used to be there. * If no error occurs, then Postscript for the rectangle is * appended to the result. * * Side effects: * None. * *-------------------------------------------------------------- */static intRectOvalToPostscript(interp, canvas, itemPtr, prepass) Tcl_Interp *interp; /* Interpreter for error reporting. */ 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. */{ char pathCmd[500], string[100]; RectOvalItem *rectOvalPtr = (RectOvalItem *) itemPtr; double y1, y2; y1 = Tk_CanvasPsY(canvas, rectOvalPtr->bbox[1]); y2 = Tk_CanvasPsY(canvas, rectOvalPtr->bbox[3]); /* * Generate a string that creates a path for the rectangle or oval. * This is the only part of the procedure's code that is type- * specific. */ if (rectOvalPtr->header.typePtr == &tkRectangleType) { sprintf(pathCmd, "%.15g %.15g moveto %.15g 0 rlineto 0 %.15g rlineto %.15g 0 rlineto closepath\n", rectOvalPtr->bbox[0], y1, rectOvalPtr->bbox[2]-rectOvalPtr->bbox[0], y2-y1, rectOvalPtr->bbox[0]-rectOvalPtr->bbox[2]); } else { sprintf(pathCmd, "matrix currentmatrix\n%.15g %.15g translate %.15g %.15g scale 1 0 moveto 0 0 1 0 360 arc\nsetmatrix\n", (rectOvalPtr->bbox[0] + rectOvalPtr->bbox[2])/2, (y1 + y2)/2, (rectOvalPtr->bbox[2] - rectOvalPtr->bbox[0])/2, (y1 - y2)/2); } /* * First draw the filled area of the rectangle. */ if (rectOvalPtr->fillColor != NULL) { Tcl_AppendResult(interp, pathCmd, (char *) NULL); if (Tk_CanvasPsColor(interp, canvas, rectOvalPtr->fillColor) != TCL_OK) { return TCL_ERROR; } if (rectOvalPtr->fillStipple != None) { Tcl_AppendResult(interp, "clip ", (char *) NULL); if (Tk_CanvasPsStipple(interp, canvas, rectOvalPtr->fillStipple) != TCL_OK) { return TCL_ERROR; } if (rectOvalPtr->outlineColor != NULL) { Tcl_AppendResult(interp, "grestore gsave\n", (char *) NULL); } } else { Tcl_AppendResult(interp, "fill\n", (char *) NULL); } } /* * Now draw the outline, if there is one. */ if (rectOvalPtr->outlineColor != NULL) { Tcl_AppendResult(interp, pathCmd, (char *) NULL); sprintf(string, "%d setlinewidth", rectOvalPtr->width); Tcl_AppendResult(interp, string, " 0 setlinejoin 2 setlinecap\n", (char *) NULL); if (Tk_CanvasPsColor(interp, canvas, rectOvalPtr->outlineColor) != TCL_OK) { return TCL_ERROR; } Tcl_AppendResult(interp, "stroke\n", (char *) NULL); } return TCL_OK;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -