📄 getcolor.3
字号:
'\"'\" Copyright (c) 1990, 1991 The Regents of the University of California.'\" Copyright (c) 1994-1996 Sun Microsystems, Inc.'\"'\" See the file "license.terms" for information on usage and redistribution'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.'\" '\" SCCS: @(#) GetColor.3 1.22 96/08/27 13:21:26'\" .so man.macros.TH Tk_GetColor 3 4.0 Tk "Tk Library Procedures".BS.SH NAMETk_GetColor, Tk_GetColorByValue, Tk_NameOfColor, Tk_FreeColor \- maintain database of colors.SH SYNOPSIS.nf\fB#include <tk.h>\fR.spXColor *\fBTk_GetColor\fR(\fIinterp, tkwin, nameId\fB)\fR.spXColor *\fBTk_GetColorByValue\fR(\fItkwin, prefPtr\fB)\fR.spchar *\fBTk_NameOfColor(\fIcolorPtr\fB)\fR.spGC\fBTk_GCForColor\fR(\fIcolorPtr, drawable\fR).sp\fBTk_FreeColor(\fIcolorPtr\fB)\fR.SH ARGUMENTS.AS "Tcl_Interp" *colorPtr.AP Tcl_Interp *interp inInterpreter to use for error reporting..AP Tk_Window tkwin inToken for window in which color will be used..AP Tk_Uid nameId inTextual description of desired color..AP XColor *prefPtr inIndicates red, green, and blue intensities of desiredcolor..AP XColor *colorPtr inPointer to X color information. Must have been allocated by previouscall to \fBTk_GetColor\fR or \fBTk_GetColorByValue\fR, except when passedto \fBTk_NameOfColor\fR..AP Drawable drawable inDrawable in which the result graphics context will be used. Must havesame screen and depth as the window for which the color was allocated..BE.SH DESCRIPTION.PPThe \fBTk_GetColor\fR and \fBTk_GetColorByValue\fR procedureslocate pixel values that may be used to render particularcolors in the window given by \fItkwin\fR. In \fBTk_GetColor\fRthe desired color is specified with a Tk_Uid (\fInameId\fR), whichmay have any of the following forms:.TP 20\fIcolorname\fRAny of the valid textual names for a color defined in theserver's color database file, such as \fBred\fR or \fBPeachPuff\fR..TP 20\fB#\fIRGB\fR.TP 20\fB#\fIRRGGBB\fR.TP 20\fB#\fIRRRGGGBBB\fR.TP 20\fB#\fIRRRRGGGGBBBB\fRA numeric specification of the red, green, and blue intensitiesto use to display the color. Each \fIR\fR, \fIG\fR, or \fIB\fRrepresents a single hexadecimal digit. The four forms permitcolors to be specified with 4-bit, 8-bit, 12-bit or 16-bit values.When fewer than 16 bits are provided for each color, they representthe most significant bits of the color. For example, #3a7 is thesame as #3000a0007000..PPIn \fBTk_GetColorByValue\fR, the desired color is indicated withthe \fIred\fR, \fIgreen\fR, and \fIblue\fR fields of the structurepointed to by \fIcolorPtr\fR..PPIf \fBTk_GetColor\fR or \fBTk_GetColorByValue\fR is successfulin allocating the desired color, then it returns a pointer toan XColor structure; the structure indicates the exact intensities ofthe allocated color (which may differ slightly from those requested,depending on the limitations of the screen) and a pixel valuethat may be used to draw in the color.If the colormap for \fItkwin\fR is full, \fBTk_GetColor\fRand \fBTk_GetColorByValue\fR will use the closest existing colorin the colormap.If \fBTk_GetColor\fR encounters an error while allocatingthe color (such as an unknown color name) then NULL is returned andan error message is stored in \fIinterp->result\fR;\fBTk_GetColorByValue\fR never returns an error..PP\fBTk_GetColor\fR and \fBTk_GetColorByValue\fR maintain a databaseof all the colors currently in use.If the same \fInameId\fR is requested multiple times from\fBTk_GetColor\fR (e.g. by different windows), or if thesame intensities are requested multiple times from\fBTk_GetColorByValue\fR, then existing pixel values willbe re-used. Re-using an existing pixel avoids any interactionwith the X server, which makes the allocation much moreefficient. For this reason, you should generally use\fBTk_GetColor\fR or \fBTk_GetColorByValue\fRinstead of Xlib procedures like \fBXAllocColor\fR,\fBXAllocNamedColor\fR, or \fBXParseColor\fR..PPSince different calls to \fBTk_GetColor\fR or \fBTk_GetColorByValue\fRmay return the same sharedpixel value, callers should never change the color of a pixelreturned by the procedures.If you need to change a color value dynamically, you should use\fBXAllocColorCells\fR to allocate the pixel value for the color..PPThe procedure \fBTk_NameOfColor\fR is roughly the inverse of\fBTk_GetColor\fR. If its \fIcolorPtr\fR argument was createdby \fBTk_GetColor\fR, then the return value is the \fInameId\fRstring that was passed to \fBTk_GetColor\fR to create thecolor. If \fIcolorPtr\fR was created by a call to \fBTk_GetColorByValue\fR,or by any other mechanism, then the return value is a stringthat could be passed to \fBTk_GetColor\fR to return the samecolor. Note: the string returned by \fBTk_NameOfColor\fR isonly guaranteed to persist until the next call to \fBTk_NameOfColor\fR..PP\fBTk_GCForColor\fR returns a graphics context whose \fBForeground\fRfield is the pixel allocated for \fIcolorPtr\fR and whose other fieldsall have default values.This provides an easy way to do basic drawing with a color.The graphics context is cached with the color and will exist only aslong as \fIcolorPtr\fR exists; it is freed when the last referenceto \fIcolorPtr\fR is freed by calling \fBTk_FreeColor\fR..PPWhen a pixel value returned by \fBTk_GetColor\fR or\fBTk_GetColorByValue\fR is no longerneeded, \fBTk_FreeColor\fR should be called to release the color.There should be exactly one call to \fBTk_FreeColor\fR foreach call to \fBTk_GetColor\fR or \fBTk_GetColorByValue\fR.When a pixel value is no longer inuse anywhere (i.e. it has been freed as many times as it has been gotten)\fBTk_FreeColor\fR will release it to the X server and delete it fromthe database..SH KEYWORDScolor, intensity, pixel value
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -