⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tkcanvimg.c

📁 linux系统下的音频通信
💻 C
📖 第 1 页 / 共 2 页
字号:
 *	None. * * Side effects: *	The fields x1, y1, x2, and y2 are updated in the header *	for itemPtr. * *-------------------------------------------------------------- */	/* ARGSUSED */static voidComputeImageBbox(canvas, imgPtr)    Tk_Canvas canvas;			/* Canvas that contains item. */    ImageItem *imgPtr;			/* Item whose bbox is to be					 * recomputed. */{    int width, height;    int x, y;    x = (int) (imgPtr->x + ((imgPtr->x >= 0) ? 0.5 : - 0.5));    y = (int) (imgPtr->y + ((imgPtr->y >= 0) ? 0.5 : - 0.5));    if (imgPtr->image == None) {	imgPtr->header.x1 = imgPtr->header.x2 = x;	imgPtr->header.y1 = imgPtr->header.y2 = y;	return;    }    /*     * Compute location and size of image, using anchor information.     */    Tk_SizeOfImage(imgPtr->image, &width, &height);    switch (imgPtr->anchor) {	case TK_ANCHOR_N:	    x -= width/2;	    break;	case TK_ANCHOR_NE:	    x -= width;	    break;	case TK_ANCHOR_E:	    x -= width;	    y -= height/2;	    break;	case TK_ANCHOR_SE:	    x -= width;	    y -= height;	    break;	case TK_ANCHOR_S:	    x -= width/2;	    y -= height;	    break;	case TK_ANCHOR_SW:	    y -= height;	    break;	case TK_ANCHOR_W:	    y -= height/2;	    break;	case TK_ANCHOR_NW:	    break;	case TK_ANCHOR_CENTER:	    x -= width/2;	    y -= height/2;	    break;    }    /*     * Store the information in the item header.     */    imgPtr->header.x1 = x;    imgPtr->header.y1 = y;    imgPtr->header.x2 = x + width;    imgPtr->header.y2 = y + height;}/* *-------------------------------------------------------------- * * DisplayImage -- * *	This procedure is invoked to draw a image item in a given *	drawable. * * Results: *	None. * * Side effects: *	ItemPtr is drawn in drawable using the transformation *	information in canvas. * *-------------------------------------------------------------- */static voidDisplayImage(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). */{    ImageItem *imgPtr = (ImageItem *) itemPtr;    short drawableX, drawableY;    if (imgPtr->image == NULL) {	return;    }    /*     * Translate the coordinates to those of the image, then redisplay it.     */    Tk_CanvasDrawableCoords(canvas, (double) x, (double) y,	    &drawableX, &drawableY);    Tk_RedrawImage(imgPtr->image, x - imgPtr->header.x1, y - imgPtr->header.y1,	    width, height, drawable, drawableX, drawableY);}/* *-------------------------------------------------------------- * * ImageToPoint -- * *	Computes the distance from a given point to a given *	rectangle, in canvas units. * * Results: *	The return value is 0 if the point whose x and y coordinates *	are coordPtr[0] and coordPtr[1] is inside the image.  If the *	point isn't inside the image then the return value is the *	distance from the point to the image. * * Side effects: *	None. * *-------------------------------------------------------------- */static doubleImageToPoint(canvas, itemPtr, coordPtr)    Tk_Canvas canvas;		/* Canvas containing item. */    Tk_Item *itemPtr;		/* Item to check against point. */    double *coordPtr;		/* Pointer to x and y coordinates. */{    ImageItem *imgPtr = (ImageItem *) itemPtr;    double x1, x2, y1, y2, xDiff, yDiff;    x1 = imgPtr->header.x1;    y1 = imgPtr->header.y1;    x2 = imgPtr->header.x2;    y2 = imgPtr->header.y2;    /*     * Point is outside rectangle.     */    if (coordPtr[0] < x1) {	xDiff = x1 - coordPtr[0];    } else if (coordPtr[0] > x2)  {	xDiff = coordPtr[0] - x2;    } else {	xDiff = 0;    }    if (coordPtr[1] < y1) {	yDiff = y1 - coordPtr[1];    } else if (coordPtr[1] > y2)  {	yDiff = coordPtr[1] - y2;    } else {	yDiff = 0;    }    return hypot(xDiff, yDiff);}/* *-------------------------------------------------------------- * * ImageToArea -- * *	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. * *-------------------------------------------------------------- */static intImageToArea(canvas, itemPtr, rectPtr)    Tk_Canvas canvas;		/* Canvas containing item. */    Tk_Item *itemPtr;		/* Item to check against rectangle. */    double *rectPtr;		/* Pointer to array of four coordinates				 * (x1, y1, x2, y2) describing rectangular				 * area.  */{    ImageItem *imgPtr = (ImageItem *) itemPtr;    if ((rectPtr[2] <= imgPtr->header.x1)	    || (rectPtr[0] >= imgPtr->header.x2)	    || (rectPtr[3] <= imgPtr->header.y1)	    || (rectPtr[1] >= imgPtr->header.y2)) {	return -1;    }    if ((rectPtr[0] <= imgPtr->header.x1)	    && (rectPtr[1] <= imgPtr->header.y1)	    && (rectPtr[2] >= imgPtr->header.x2)	    && (rectPtr[3] >= imgPtr->header.y2)) {	return 1;    }    return 0;}/* *-------------------------------------------------------------- * * ScaleImage -- * *	This procedure is invoked to rescale an item. * * Results: *	None. * * Side effects: *	The item 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 voidScaleImage(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. */{    ImageItem *imgPtr = (ImageItem *) itemPtr;    imgPtr->x = originX + scaleX*(imgPtr->x - originX);    imgPtr->y = originY + scaleY*(imgPtr->y - originY);    ComputeImageBbox(canvas, imgPtr);}/* *-------------------------------------------------------------- * * TranslateImage -- * *	This procedure is called to move an item by a given amount. * * Results: *	None. * * Side effects: *	The position of the item is offset by (xDelta, yDelta), and *	the bounding box is updated in the generic part of the item *	structure. * *-------------------------------------------------------------- */static voidTranslateImage(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. */{    ImageItem *imgPtr = (ImageItem *) itemPtr;    imgPtr->x += deltaX;    imgPtr->y += deltaY;    ComputeImageBbox(canvas, imgPtr);}/* *---------------------------------------------------------------------- * * ImageChangedProc -- * *	This procedure is invoked by the image code whenever the manager *	for an image does something that affects the image's size or *	how it is displayed. * * Results: *	None. * * Side effects: *	Arranges for the canvas to get redisplayed. * *---------------------------------------------------------------------- */static voidImageChangedProc(clientData, x, y, width, height, imgWidth, imgHeight)    ClientData clientData;		/* Pointer to canvas item for image. */    int x, y;				/* Upper left pixel (within image)					 * that must be redisplayed. */    int width, height;			/* Dimensions of area to redisplay					 * (may be <= 0). */    int imgWidth, imgHeight;		/* New dimensions of image. */{    ImageItem *imgPtr = (ImageItem *) clientData;    /*     * If the image's size changed and it's not anchored at its     * northwest corner then just redisplay the entire area of the     * image.  This is a bit over-conservative, but we need to do     * something because a size change also means a position change.     */    if (((imgPtr->header.x2 - imgPtr->header.x1) != imgWidth)	    || ((imgPtr->header.y2 - imgPtr->header.y1) != imgHeight)) {	x = y = 0;	width = imgWidth;	height = imgHeight;	Tk_CanvasEventuallyRedraw(imgPtr->canvas, imgPtr->header.x1,		imgPtr->header.y1, imgPtr->header.x2, imgPtr->header.y2);    }     ComputeImageBbox(imgPtr->canvas, imgPtr);    Tk_CanvasEventuallyRedraw(imgPtr->canvas, imgPtr->header.x1 + x,	    imgPtr->header.y1 + y, (int) (imgPtr->header.x1 + x + width),	    (int) (imgPtr->header.y1 + y + height));}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -