Tk_AllocColorFromObj


HOME

Tk_AllocColorFromObj

NAME
SYNOPSIS
ARGUMENTS
DESCRIPTION
KEYWORDS

___________________________

NAME

Tk_AllocColorFromObj, Tk_GetColor, Tk_GetColorFromObj, Tk_GetColorByValue, Tk_NameOfColor, Tk_FreeColorFromObj, Tk_FreeColor − maintain database of colors

SYNOPSIS

#include <tk.h>

XColor *
Tk_AllocColorFromObj(
interp, tkwin, objPtr)

XColor *
Tk_GetColor(
interp, tkwin, name)

XColor *
Tk_GetColorFromObj(
tkwin, objPtr)

XColor *
Tk_GetColorByValue(
tkwin, prefPtr)

const char *
Tk_NameOfColor(
colorPtr)

GC
Tk_GCForColor(
colorPtr, drawable)

Tk_FreeColorFromObj(tkwin, objPtr)

Tk_FreeColor(colorPtr)

ARGUMENTS

Tcl_Interp *interp (in)

Interpreter to use for error reporting.

Tk_Window tkwin (in)

Token for window in which color will be used.

Tcl_Obj *objPtr (in/out)

String value describes desired color; internal rep will be modified to cache pointer to corresponding (XColor *).

char *name (in)

Same as objPtr except description of color is passed as a string and resulting (XColor *) is not cached.

XColor *prefPtr (in)

Indicates red, green, and blue intensities of desired color.

XColor *colorPtr (in)

Pointer to X color information. Must have been allocated by previous call to Tk_AllocColorFromObj, Tk_GetColor or Tk_GetColorByValue, except when passed to Tk_NameOfColor.

Drawable drawable (in)

Drawable in which the result graphics context will be used. Must have same screen and depth as the window for which the color was allocated.

______________

DESCRIPTION

These procedures manage the colors being used by a Tk application. They allow colors to be shared whenever possible, so that colormap space is preserved, and they pick closest available colors when colormap space is exhausted.

Given a textual description of a color, Tk_AllocColorFromObj locates a pixel value that may be used to render the color in a particular window. The desired color is specified with an object whose string value must have one of the following forms:

colorname

Any of the valid textual names for a color defined in the server’s color database file, such as red or PeachPuff.

#RGB

#RRGGBB

#RRRGGGBBB

#RRRRGGGGBBBB

A numeric specification of the red, green, and blue intensities to use to display the color. Each R, G, or B represents a single hexadecimal digit. The four forms permit colors 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 represent the most significant bits of the color. For example, #3a7 is the same as #3000a0007000.

Tk_AllocColorFromObj returns a pointer to an XColor structure; the structure indicates the exact intensities of the allocated color (which may differ slightly from those requested, depending on the limitations of the screen) and a pixel value that may be used to draw with the color in tkwin. If an error occurs in Tk_AllocColorFromObj (such as an unknown color name) then NULL is returned and an error message is stored in interp’s result if interp is not NULL. If the colormap for tkwin is full, Tk_AllocColorFromObj will use the closest existing color in the colormap. Tk_AllocColorFromObj caches information about the return value in objPtr, which speeds up future calls to procedures such as Tk_AllocColorFromObj and Tk_GetColorFromObj.

Tk_GetColor is identical to Tk_AllocColorFromObj except that the description of the color is specified with a string instead of an object. This prevents Tk_GetColor from caching the return value, so Tk_GetColor is less efficient than Tk_AllocColorFromObj.

Tk_GetColorFromObj returns the token for an existing color, given the window and description used to create the color. Tk_GetColorFromObj does not actually create the color; the color must already have been created with a previous call to Tk_AllocColorFromObj or Tk_GetColor. The return value is cached in objPtr, which speeds up future calls to Tk_GetColorFromObj with the same objPtr and tkwin.

Tk_GetColorByValue is similar to Tk_GetColor except that the desired color is indicated with the red, green, and blue fields of the structure pointed to by colorPtr.

This package maintains a database of all the colors currently in use. If the same color is requested multiple times from Tk_GetColor or Tk_AllocColorFromObj (e.g. by different windows), or if the same intensities are requested multiple times from Tk_GetColorByValue, then existing pixel values will be re-used. Re-using an existing pixel avoids any interaction with the window server, which makes the allocation much more efficient. These procedures also provide a portable interface that works across all platforms. For this reason, you should generally use Tk_AllocColorFromObj, Tk_GetColor, or Tk_GetColorByValue instead of lower level procedures like XAllocColor.

Since different calls to this package may return the same shared pixel value, callers should never change the color of a pixel returned by the procedures. If you need to change a color value dynamically, you should use XAllocColorCells to allocate the pixel value for the color.

The procedure Tk_NameOfColor is roughly the inverse of Tk_GetColor. If its colorPtr argument was created by Tk_AllocColorFromObj or Tk_GetColor then the return value is the string that was used to create the color. If colorPtr was created by a call to Tk_GetColorByValue, or by any other mechanism, then the return value is a string that could be passed to Tk_GetColor to return the same color. Note: the string returned by Tk_NameOfColor is only guaranteed to persist until the next call to Tk_NameOfColor.

Tk_GCForColor returns a graphics context whose foreground field is the pixel allocated for colorPtr and whose other fields all 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 as long as colorPtr exists; it is freed when the last reference to colorPtr is freed by calling Tk_FreeColor.

When a color is no longer needed Tk_FreeColorFromObj or Tk_FreeColor should be called to release it. For Tk_FreeColorFromObj the color to release is specified with the same information used to create it; for Tk_FreeColor the color to release is specified with a pointer to its XColor structure. There should be exactly one call to Tk_FreeColorFromObj or Tk_FreeColor for each call to Tk_AllocColorFromObj, Tk_GetColor, or Tk_GetColorByValue.

KEYWORDS

color, intensity, object, pixel value



More Linux Commands

manpages/wall.1.html
wall(1) - write a message to users - Linux manual page......
wall displays a message, or the contents of a file, or otherwise its standard input, on the terminals of all currently logged in users. The command will wrap li

manpages/chacl.1.html
chacl(1) - change the access control list of a file or direc
chacl is an IRIX-compatibility command, and is maintained for those users who are familiar with its use from either XFS or IRIX. Refer to the SEE ALSO section b

manpages/mq_send.3.html
mq_send(3) - send a message to a message queue (Man Page)...
mq_send() adds the message pointed to by msg_ptr to the message queue referred to by the descriptor mqdes. The msg_len argument specifies the length of the mess

manpages/perl561delta.1.html
perl561delta(1) - what's new for perl v5.6.x (Man Page).....
This document describes differences between the 5.005 release and the 5.6.1 release. Summary of changes between 5.6.0 and 5.6.1 This section contains a summary

manpages/XkbKeyGroupInfo.3.html
XkbKeyGroupInfo(3) - Returns the number of groups of symbols
The group_info field of an XkbSymMapRec is an encoded value containing the number of groups of symbols bound to the key as well as the specification of the trea

manpages/pam_verror.3.html
pam_verror(3) - display error messages to the user (ManPage)
The pam_error function prints error messages through the conversation function to the user. The pam_verror function performs the same task as pam_error() with t

manpages/ntfsfix.8.html
ntfsfix(8) - fix common errors and force Windows to check NT
ntfsfix is a utility that fixes some common NTFS problems. ntfsfix is NOT a Linux version of chkdsk. It only repairs some fundamental NTFS inconsistencies, rese

manpages/systemd-activate.8.html
systemd-activate(8) Test socket activation of daemons.......
systemd-activate can be used to launch a socket activated daemon from the command-line for testing purposes. It can also be used to launch single instances of t

manpages/gnutls_certificate_set_x509_trust_file.3.html
gnutls_certificate_set_x509_trust_file(3) - API function....
gnutls_certificate_set_x509_trust_file.3 - This function adds the trusted CAs in order to verify client or server certificates. In case of a client this is not

manpages/perl584delta.1.html
perl584delta(1) - what is new for perl v5.8.4 (Man Page)....
This document describes differences between the 5.8.3 release and the 5.8.4 release. Incompatible Changes Many minor bugs have been fixed. Scripts which happen

manpages/mzip.1.html
mzip(1) - change protection mode and eject disk on Zip/Jaz d
The mzip command is used to issue ZIP disk specific commands on Linux, Solaris or HP-UX. Its syntax is: mzip [-epqrwx] Mzip allows the following command line op

manpages/fcntl64.2.html
fcntl64(2) - manipulate file descriptor - Linux manual page
fcntl() performs one of the operations described below on the open file descriptor fd. The operation is determined by cmd. fcntl() can take an optional third ar





We can't live, work or learn in freedom unless the software we use is free.