📄 tkimgbmap.c
字号:
* A standard Tcl result. * * Side effects: * See the user documentation. * *-------------------------------------------------------------- */static intImgBmapCmd(clientData, interp, argc, argv) ClientData clientData; /* Information about the image master. */ Tcl_Interp *interp; /* Current interpreter. */ int argc; /* Number of arguments. */ char **argv; /* Argument strings. */{ BitmapMaster *masterPtr = (BitmapMaster *) clientData; int c, code; size_t length; if (argc < 2) { sprintf(interp->result, "wrong # args: should be \"%.50s option ?arg arg ...?\"", argv[0]); return TCL_ERROR; } c = argv[1][0]; length = strlen(argv[1]); if ((c == 'c') && (strncmp(argv[1], "cget", length) == 0) && (length >= 2)) { if (argc != 3) { Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " cget option\"", (char *) NULL); return TCL_ERROR; } return Tk_ConfigureValue(interp, Tk_MainWindow(interp), configSpecs, (char *) masterPtr, argv[2], 0); } else if ((c == 'c') && (strncmp(argv[1], "configure", length) == 0) && (length >= 2)) { if (argc == 2) { code = Tk_ConfigureInfo(interp, Tk_MainWindow(interp), configSpecs, (char *) masterPtr, (char *) NULL, 0); } else if (argc == 3) { code = Tk_ConfigureInfo(interp, Tk_MainWindow(interp), configSpecs, (char *) masterPtr, argv[2], 0); } else { code = ImgBmapConfigureMaster(masterPtr, argc-2, argv+2, TK_CONFIG_ARGV_ONLY); } return code; } else { Tcl_AppendResult(interp, "bad option \"", argv[1], "\": must be cget or configure", (char *) NULL); return TCL_ERROR; }}/* *---------------------------------------------------------------------- * * ImgBmapGet -- * * This procedure is called for each use of a bitmap image in a * widget. * * Results: * The return value is a token for the instance, which is passed * back to us in calls to ImgBmapDisplay and ImgBmapFree. * * Side effects: * A data structure is set up for the instance (or, an existing * instance is re-used for the new one). * *---------------------------------------------------------------------- */static ClientDataImgBmapGet(tkwin, masterData) Tk_Window tkwin; /* Window in which the instance will be * used. */ ClientData masterData; /* Pointer to our master structure for the * image. */{ BitmapMaster *masterPtr = (BitmapMaster *) masterData; BitmapInstance *instancePtr; /* * See if there is already an instance for this window. If so * then just re-use it. */ for (instancePtr = masterPtr->instancePtr; instancePtr != NULL; instancePtr = instancePtr->nextPtr) { if (instancePtr->tkwin == tkwin) { instancePtr->refCount++; return (ClientData) instancePtr; } } /* * The image isn't already in use in this window. Make a new * instance of the image. */ instancePtr = (BitmapInstance *) ckalloc(sizeof(BitmapInstance)); instancePtr->refCount = 1; instancePtr->masterPtr = masterPtr; instancePtr->tkwin = tkwin; instancePtr->fg = NULL; instancePtr->bg = NULL; instancePtr->bitmap = None; instancePtr->mask = None; instancePtr->gc = None; instancePtr->nextPtr = masterPtr->instancePtr; masterPtr->instancePtr = instancePtr; ImgBmapConfigureInstance(instancePtr); /* * If this is the first instance, must set the size of the image. */ if (instancePtr->nextPtr == NULL) { Tk_ImageChanged(masterPtr->tkMaster, 0, 0, 0, 0, masterPtr->width, masterPtr->height); } return (ClientData) instancePtr;}/* *---------------------------------------------------------------------- * * ImgBmapDisplay -- * * This procedure is invoked to draw a bitmap image. * * Results: * None. * * Side effects: * A portion of the image gets rendered in a pixmap or window. * *---------------------------------------------------------------------- */static voidImgBmapDisplay(clientData, display, drawable, imageX, imageY, width, height, drawableX, drawableY) ClientData clientData; /* Pointer to BitmapInstance structure for * for instance to be displayed. */ Display *display; /* Display on which to draw image. */ Drawable drawable; /* Pixmap or window in which to draw image. */ int imageX, imageY; /* Upper-left corner of region within image * to draw. */ int width, height; /* Dimensions of region within image to draw. */ int drawableX, drawableY; /* Coordinates within drawable that * correspond to imageX and imageY. */{ BitmapInstance *instancePtr = (BitmapInstance *) clientData; int masking; /* * If there's no graphics context, it means that an error occurred * while creating the image instance so it can't be displayed. */ if (instancePtr->gc == None) { return; } /* * If masking is in effect, must modify the mask origin within * the graphics context to line up with the image's origin. * Then draw the image and reset the clip origin, if there's * a mask. */ masking = (instancePtr->mask != None) || (instancePtr->bg == NULL); if (masking) { XSetClipOrigin(display, instancePtr->gc, drawableX - imageX, drawableY - imageY); } XCopyPlane(display, instancePtr->bitmap, drawable, instancePtr->gc, imageX, imageY, (unsigned) width, (unsigned) height, drawableX, drawableY, 1); if (masking) { XSetClipOrigin(display, instancePtr->gc, 0, 0); }}/* *---------------------------------------------------------------------- * * ImgBmapFree -- * * This procedure is called when a widget ceases to use a * particular instance of an image. * * Results: * None. * * Side effects: * Internal data structures get cleaned up. * *---------------------------------------------------------------------- */static voidImgBmapFree(clientData, display) ClientData clientData; /* Pointer to BitmapInstance structure for * for instance to be displayed. */ Display *display; /* Display containing window that used image. */{ BitmapInstance *instancePtr = (BitmapInstance *) clientData; BitmapInstance *prevPtr; instancePtr->refCount--; if (instancePtr->refCount > 0) { return; } /* * There are no more uses of the image within this widget. Free * the instance structure. */ if (instancePtr->fg != NULL) { Tk_FreeColor(instancePtr->fg); } if (instancePtr->bg != NULL) { Tk_FreeColor(instancePtr->bg); } if (instancePtr->bitmap != None) { Tk_FreePixmap(display, instancePtr->bitmap); } if (instancePtr->mask != None) { Tk_FreePixmap(display, instancePtr->mask); } if (instancePtr->gc != None) { Tk_FreeGC(display, instancePtr->gc); } if (instancePtr->masterPtr->instancePtr == instancePtr) { instancePtr->masterPtr->instancePtr = instancePtr->nextPtr; } else { for (prevPtr = instancePtr->masterPtr->instancePtr; prevPtr->nextPtr != instancePtr; prevPtr = prevPtr->nextPtr) { /* Empty loop body */ } prevPtr->nextPtr = instancePtr->nextPtr; } ckfree((char *) instancePtr);}/* *---------------------------------------------------------------------- * * ImgBmapDelete -- * * This procedure is called by the image code to delete the * master structure for an image. * * Results: * None. * * Side effects: * Resources associated with the image get freed. * *---------------------------------------------------------------------- */static voidImgBmapDelete(masterData) ClientData masterData; /* Pointer to BitmapMaster structure for * image. Must not have any more instances. */{ BitmapMaster *masterPtr = (BitmapMaster *) masterData; if (masterPtr->instancePtr != NULL) { panic("tried to delete bitmap image when instances still exist"); } masterPtr->tkMaster = NULL; if (masterPtr->imageCmd != NULL) { Tcl_DeleteCommandFromToken(masterPtr->interp, masterPtr->imageCmd); } if (masterPtr->data != NULL) { ckfree(masterPtr->data); } if (masterPtr->maskData != NULL) { ckfree(masterPtr->maskData); } Tk_FreeOptions(configSpecs, (char *) masterPtr, (Display *) NULL, 0); ckfree((char *) masterPtr);}/* *---------------------------------------------------------------------- * * ImgBmapCmdDeletedProc -- * * This procedure is invoked when the image command for an image * is deleted. It deletes the image. * * Results: * None. * * Side effects: * The image is deleted. * *---------------------------------------------------------------------- */static voidImgBmapCmdDeletedProc(clientData) ClientData clientData; /* Pointer to BitmapMaster structure for * image. */{ BitmapMaster *masterPtr = (BitmapMaster *) clientData; masterPtr->imageCmd = NULL; if (masterPtr->tkMaster != NULL) { Tk_DeleteImage(masterPtr->interp, Tk_NameOfImage(masterPtr->tkMaster)); }}/* *---------------------------------------------------------------------- * * GetByte -- * * Get the next byte from the open channel. * * Results: * The next byte or EOF. * * Side effects: * We read from the channel. * *---------------------------------------------------------------------- */static intGetByte(chan) Tcl_Channel chan; /* The channel we read from. */{ char buffer; int size; size = Tcl_Read(chan, &buffer, 1); if (size <= 0) { return EOF; } else { return buffer; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -