📄 tkimage.c
字号:
*---------------------------------------------------------------------- */char *Tk_NameOfImage(imageMaster) Tk_ImageMaster imageMaster; /* Token for image. */{ ImageMaster *masterPtr = (ImageMaster *) imageMaster; return Tcl_GetHashKey(masterPtr->tablePtr, masterPtr->hPtr);}/* *---------------------------------------------------------------------- * * Tk_GetImage -- * * This procedure is invoked by a widget when it wants to use * a particular image in a particular window. * * Results: * The return value is a token for the image. If there is no image * by the given name, then NULL is returned and an error message is * left in interp->result. * * Side effects: * Tk records the fact that the widget is using the image, and * it will invoke changeProc later if the widget needs redisplay * (i.e. its size changes or some of its pixels change). The * caller must eventually invoke Tk_FreeImage when it no longer * needs the image. * *---------------------------------------------------------------------- */Tk_ImageTk_GetImage(interp, tkwin, name, changeProc, clientData) Tcl_Interp *interp; /* Place to leave error message if image * can't be found. */ Tk_Window tkwin; /* Token for window in which image will * be used. */ char *name; /* Name of desired image. */ Tk_ImageChangedProc *changeProc; /* Procedure to invoke when redisplay is * needed because image's pixels or size * changed. */ ClientData clientData; /* One-word argument to pass to damageProc. */{ Tcl_HashEntry *hPtr; ImageMaster *masterPtr; Image *imagePtr; hPtr = Tcl_FindHashEntry(&((TkWindow *) tkwin)->mainPtr->imageTable, name); if (hPtr == NULL) { goto noSuchImage; } masterPtr = (ImageMaster *) Tcl_GetHashValue(hPtr); if (masterPtr->typePtr == NULL) { goto noSuchImage; } imagePtr = (Image *) ckalloc(sizeof(Image)); imagePtr->tkwin = tkwin; imagePtr->display = Tk_Display(tkwin); imagePtr->masterPtr = masterPtr; imagePtr->instanceData = (*masterPtr->typePtr->getProc)(tkwin, masterPtr->masterData); imagePtr->changeProc = changeProc; imagePtr->widgetClientData = clientData; imagePtr->nextPtr = masterPtr->instancePtr; masterPtr->instancePtr = imagePtr; return (Tk_Image) imagePtr; noSuchImage: Tcl_AppendResult(interp, "image \"", name, "\" doesn't exist", (char *) NULL); return NULL;}/* *---------------------------------------------------------------------- * * Tk_FreeImage -- * * This procedure is invoked by a widget when it no longer needs * an image acquired by a previous call to Tk_GetImage. For each * call to Tk_GetImage there must be exactly one call to Tk_FreeImage. * * Results: * None. * * Side effects: * The association between the image and the widget is removed. * *---------------------------------------------------------------------- */voidTk_FreeImage(image) Tk_Image image; /* Token for image that is no longer * needed by a widget. */{ Image *imagePtr = (Image *) image; ImageMaster *masterPtr = imagePtr->masterPtr; Image *prevPtr; /* * Clean up the particular instance. */ if (masterPtr->typePtr != NULL) { (*masterPtr->typePtr->freeProc)(imagePtr->instanceData, imagePtr->display); } prevPtr = masterPtr->instancePtr; if (prevPtr == imagePtr) { masterPtr->instancePtr = imagePtr->nextPtr; } else { while (prevPtr->nextPtr != imagePtr) { prevPtr = prevPtr->nextPtr; } prevPtr->nextPtr = imagePtr->nextPtr; } ckfree((char *) imagePtr); /* * If there are no more instances left for the master, and if the * master image has been deleted, then delete the master too. */ if ((masterPtr->typePtr == NULL) && (masterPtr->instancePtr == NULL)) { Tcl_DeleteHashEntry(masterPtr->hPtr); ckfree((char *) masterPtr); }}/* *---------------------------------------------------------------------- * * Tk_RedrawImage -- * * This procedure is called by widgets that contain images in order * to redisplay an image on the screen or an off-screen pixmap. * * Results: * None. * * Side effects: * The image's manager is notified, and it redraws the desired * portion of the image before returning. * *---------------------------------------------------------------------- */voidTk_RedrawImage(image, imageX, imageY, width, height, drawable, drawableX, drawableY) Tk_Image image; /* Token for image to redisplay. */ int imageX, imageY; /* Upper-left pixel of region in image that * needs to be redisplayed. */ int width, height; /* Dimensions of region to redraw. */ Drawable drawable; /* Drawable in which to display image * (window or pixmap). If this is a pixmap, * it must have the same depth as the window * used in the Tk_GetImage call for the * image. */ int drawableX, drawableY; /* Coordinates in drawable that correspond * to imageX and imageY. */{ Image *imagePtr = (Image *) image; if (imagePtr->masterPtr->typePtr == NULL) { /* * No master for image, so nothing to display. */ return; } /* * Clip the redraw area to the area of the image. */ if (imageX < 0) { width += imageX; drawableX -= imageX; imageX = 0; } if (imageY < 0) { height += imageY; drawableY -= imageY; imageY = 0; } if ((imageX + width) > imagePtr->masterPtr->width) { width = imagePtr->masterPtr->width - imageX; } if ((imageY + height) > imagePtr->masterPtr->height) { height = imagePtr->masterPtr->height - imageY; } (*imagePtr->masterPtr->typePtr->displayProc)( imagePtr->instanceData, imagePtr->display, drawable, imageX, imageY, width, height, drawableX, drawableY);}/* *---------------------------------------------------------------------- * * Tk_SizeOfImage -- * * This procedure returns the current dimensions of an image. * * Results: * The width and height of the image are returned in *widthPtr * and *heightPtr. * * Side effects: * None. * *---------------------------------------------------------------------- */voidTk_SizeOfImage(image, widthPtr, heightPtr) Tk_Image image; /* Token for image whose size is wanted. */ int *widthPtr; /* Return width of image here. */ int *heightPtr; /* Return height of image here. */{ Image *imagePtr = (Image *) image; *widthPtr = imagePtr->masterPtr->width; *heightPtr = imagePtr->masterPtr->height;}/* *---------------------------------------------------------------------- * * Tk_DeleteImage -- * * Given the name of an image, this procedure destroys the * image. * * Results: * None. * * Side effects: * The image is destroyed; existing instances will display as * blank areas. If no such image exists then the procedure does * nothing. * *---------------------------------------------------------------------- */voidTk_DeleteImage(interp, name) Tcl_Interp *interp; /* Interpreter in which the image was * created. */ char *name; /* Name of image. */{ Tcl_HashEntry *hPtr; TkWindow *winPtr; winPtr = (TkWindow *) Tk_MainWindow(interp); if (winPtr == NULL) { return; } hPtr = Tcl_FindHashEntry(&winPtr->mainPtr->imageTable, name); if (hPtr == NULL) { return; } DeleteImage((ImageMaster *) Tcl_GetHashValue(hPtr));}/* *---------------------------------------------------------------------- * * DeleteImage -- * * This procedure is responsible for deleting an image. * * Results: * None. * * Side effects: * The connection is dropped between instances of this image and * an image master. Image instances will redisplay themselves * as empty areas, but existing instances will not be deleted. * *---------------------------------------------------------------------- */static voidDeleteImage(masterPtr) ImageMaster *masterPtr; /* Pointer to main data structure for image. */{ Image *imagePtr; Tk_ImageType *typePtr; typePtr = masterPtr->typePtr; masterPtr->typePtr = NULL; if (typePtr != NULL) { for (imagePtr = masterPtr->instancePtr; imagePtr != NULL; imagePtr = imagePtr->nextPtr) { (*typePtr->freeProc)(imagePtr->instanceData, imagePtr->display); (*imagePtr->changeProc)(imagePtr->widgetClientData, 0, 0, masterPtr->width, masterPtr->height, masterPtr->width, masterPtr->height); } (*typePtr->deleteProc)(masterPtr->masterData); } if (masterPtr->instancePtr == NULL) { Tcl_DeleteHashEntry(masterPtr->hPtr); ckfree((char *) masterPtr); }}/* *---------------------------------------------------------------------- * * TkDeleteAllImages -- * * This procedure is called when an application is deleted. It * calls back all of the managers for all images so that they * can cleanup, then it deletes all of Tk's internal information * about images. * * Results: * None. * * Side effects: * All information for all images gets deleted. * *---------------------------------------------------------------------- */voidTkDeleteAllImages(mainPtr) TkMainInfo *mainPtr; /* Structure describing application that is * going away. */{ Tcl_HashSearch search; Tcl_HashEntry *hPtr; ImageMaster *masterPtr; for (hPtr = Tcl_FirstHashEntry(&mainPtr->imageTable, &search); hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) { masterPtr = (ImageMaster *) Tcl_GetHashValue(hPtr); DeleteImage(masterPtr); } Tcl_DeleteHashTable(&mainPtr->imageTable);}/* *---------------------------------------------------------------------- * * Tk_GetImageMasterData -- * * Given the name of an image, this procedure returns the type * of the image and the clientData associated with its master. * * Results: * If there is no image by the given name, then NULL is returned * and a NULL value is stored at *typePtrPtr. Otherwise the return * value is the clientData returned by the createProc when the * image was created and a pointer to the type structure for the * image is stored at *typePtrPtr. * * Side effects: * None. * *---------------------------------------------------------------------- */ClientDataTk_GetImageMasterData(interp, name, typePtrPtr) Tcl_Interp *interp; /* Interpreter in which the image was * created. */ char *name; /* Name of image. */ Tk_ImageType **typePtrPtr; /* Points to location to fill in with * pointer to type information for image. */{ Tcl_HashEntry *hPtr; TkWindow *winPtr; ImageMaster *masterPtr; winPtr = (TkWindow *) Tk_MainWindow(interp); hPtr = Tcl_FindHashEntry(&winPtr->mainPtr->imageTable, name); if (hPtr == NULL) { *typePtrPtr = NULL; return NULL; } masterPtr = (ImageMaster *) Tcl_GetHashValue(hPtr); *typePtrPtr = masterPtr->typePtr; return masterPtr->masterData;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -