color how x handles color. widget use of color n widgets that use color have u xmnforeground u...
Post on 22-Dec-2015
221 views
TRANSCRIPT
![Page 1: Color How X handles color. Widget use of color n Widgets that use color have u XmNforeground u XmNbackground u XmNborderColor (since default border width](https://reader036.vdocument.in/reader036/viewer/2022062314/56649d7a5503460f94a5ed9a/html5/thumbnails/1.jpg)
ColorHow X handles color
![Page 2: Color How X handles color. Widget use of color n Widgets that use color have u XmNforeground u XmNbackground u XmNborderColor (since default border width](https://reader036.vdocument.in/reader036/viewer/2022062314/56649d7a5503460f94a5ed9a/html5/thumbnails/2.jpg)
Widget use of color Widgets that use color have
XmNforeground XmNbackground XmNborderColor
(since default border width is 0 this attribute is not often seen)
XmNhighlightColor (widget has focus)
These resources are found in Primitive or Manager and thus inherited by all children.
![Page 3: Color How X handles color. Widget use of color n Widgets that use color have u XmNforeground u XmNbackground u XmNborderColor (since default border width](https://reader036.vdocument.in/reader036/viewer/2022062314/56649d7a5503460f94a5ed9a/html5/thumbnails/3.jpg)
Some widgets have additional color resources ToggleButtons have
XmSelectColor for toggle color, PushButtons have XmNarmColor
which changes background when armed,
ScrollBar has XmNthroughColor for the area behind the slider,
. . .
![Page 4: Color How X handles color. Widget use of color n Widgets that use color have u XmNforeground u XmNbackground u XmNborderColor (since default border width](https://reader036.vdocument.in/reader036/viewer/2022062314/56649d7a5503460f94a5ed9a/html5/thumbnails/4.jpg)
Some resources are specialized and handled automatically XmNtopShadowColor XmNbottomShadowColor
are used to give a 3d effect and are
computed automatically from background to be a shade lighter or a shade darker than the background color.
If the background color is dynamically changed these may not change automatically.
Use XmChangeColor(widget,background) to recalculate and reset shadows
![Page 5: Color How X handles color. Widget use of color n Widgets that use color have u XmNforeground u XmNbackground u XmNborderColor (since default border width](https://reader036.vdocument.in/reader036/viewer/2022062314/56649d7a5503460f94a5ed9a/html5/thumbnails/5.jpg)
The Problem with Color
What you see is not what you get somewhere else.
Color varies from platform to platform since the value of a color is relative to a colormap data structure.
![Page 6: Color How X handles color. Widget use of color n Widgets that use color have u XmNforeground u XmNbackground u XmNborderColor (since default border width](https://reader036.vdocument.in/reader036/viewer/2022062314/56649d7a5503460f94a5ed9a/html5/thumbnails/6.jpg)
Colormaps X assumes the RGB color model.
Each pixel’s color is defined by a percent of each of the colors Red, Green, Blue. All 3 at 100% is white All 3 at 0% is black 50% red, 50% green, 0% blue is
yellow It is not like “paint” which is
subtractive.
![Page 7: Color How X handles color. Widget use of color n Widgets that use color have u XmNforeground u XmNbackground u XmNborderColor (since default border width](https://reader036.vdocument.in/reader036/viewer/2022062314/56649d7a5503460f94a5ed9a/html5/thumbnails/7.jpg)
Each screen pixel has a storage size (8,16,24) bits.The value of this storage is an index into a table of colors called the colormap.
8 bits is 256 values, so this would define a colormap with 256 entries indexed 0..255
Each entry in the colormap is capable of storing one of 256**3 (~16M) colors but a given colormap selects only 256 different colors.
![Page 8: Color How X handles color. Widget use of color n Widgets that use color have u XmNforeground u XmNbackground u XmNborderColor (since default border width](https://reader036.vdocument.in/reader036/viewer/2022062314/56649d7a5503460f94a5ed9a/html5/thumbnails/8.jpg)
Pixels in X The data type Pixel is just an index
into the colormap. Clients using colors are requesting and using colorcells in the colormap.
In general don’t deal directly with these values. They are best manipulated through library routines.
Clients can create and use different colormaps if needed
![Page 9: Color How X handles color. Widget use of color n Widgets that use color have u XmNforeground u XmNbackground u XmNborderColor (since default border width](https://reader036.vdocument.in/reader036/viewer/2022062314/56649d7a5503460f94a5ed9a/html5/thumbnails/9.jpg)
X Color Basics
X Color basics assumes only a few colors are needed there is space in the colormap
(when the server starts it creates a default colormap which it assigns to the root window and is inherited by all applications. There will be some colorcells available for application windows)
![Page 10: Color How X handles color. Widget use of color n Widgets that use color have u XmNforeground u XmNbackground u XmNborderColor (since default border width](https://reader036.vdocument.in/reader036/viewer/2022062314/56649d7a5503460f94a5ed9a/html5/thumbnails/10.jpg)
X startup at least two colors will be in the
colormap, black and white (0 and 1) but they may not appear black and white if the percentages are changed.
Window managers generally install a few (12?) more colors.
Motif adds a few more (5?) for TopShadow, BottomShadow, ..
Remaining color cells are for applications.
![Page 11: Color How X handles color. Widget use of color n Widgets that use color have u XmNforeground u XmNbackground u XmNborderColor (since default border width](https://reader036.vdocument.in/reader036/viewer/2022062314/56649d7a5503460f94a5ed9a/html5/thumbnails/11.jpg)
All active windows have their own small set of colorcells.
Defining colors: Try not to pick rgb percentages.
#70DB93 (assumes 8 bit) Names can be chosen from the file
rgb.txt which is usually found somewhere in X directories. Usage of these names increases the probablility that the rgb percentages these names represent will be shared in the colormap. aquamarine
![Page 12: Color How X handles color. Widget use of color n Widgets that use color have u XmNforeground u XmNbackground u XmNborderColor (since default border width](https://reader036.vdocument.in/reader036/viewer/2022062314/56649d7a5503460f94a5ed9a/html5/thumbnails/12.jpg)
If resource files are usedrc.XmLabel.background: aquamarine
rc.XmLabel.background:#70DB93 In application code use a XColor
data structure defined astypedef struct {
unsigned long pixel;
unsigned short red,green,blue;
char flags;
char pad;
} XColor;\ Named Color examples slide
![Page 13: Color How X handles color. Widget use of color n Widgets that use color have u XmNforeground u XmNbackground u XmNborderColor (since default border width](https://reader036.vdocument.in/reader036/viewer/2022062314/56649d7a5503460f94a5ed9a/html5/thumbnails/13.jpg)
Colorcells continued
There are 2 kinds of color cells in a colormap. shared (readonly) private(read/write)
Application clients can request a private cell to assign a color. If none are available they can choose a shared cell that is “close” to the desired color.
![Page 14: Color How X handles color. Widget use of color n Widgets that use color have u XmNforeground u XmNbackground u XmNborderColor (since default border width](https://reader036.vdocument.in/reader036/viewer/2022062314/56649d7a5503460f94a5ed9a/html5/thumbnails/14.jpg)
private cells may be very limited and used up quickly.
Use shared cells when possible.
![Page 15: Color How X handles color. Widget use of color n Widgets that use color have u XmNforeground u XmNbackground u XmNborderColor (since default border width](https://reader036.vdocument.in/reader036/viewer/2022062314/56649d7a5503460f94a5ed9a/html5/thumbnails/15.jpg)
Using Shared Colorcells First create pointers to two XColor
structures.XColor colorcell;
Initialize with the values you wantcolorcell.red = 65535;
colorcell.green= . . . get the colormap
cmap = DefaultColormap(display,
DefaultScreen(screen));
![Page 16: Color How X handles color. Widget use of color n Widgets that use color have u XmNforeground u XmNbackground u XmNborderColor (since default border width](https://reader036.vdocument.in/reader036/viewer/2022062314/56649d7a5503460f94a5ed9a/html5/thumbnails/16.jpg)
Using Shared Colorcells Make a library call to get the
closest pixel valueif ( XAllocColor( display, cmap,
&colorcell) == 0 ) {/* failure*/} The XAllocColor supports the
shared cell strategy. It returns a pixel value that you can use.
If you prefer named colors (and you should use these to promote sharing) use XAllocNamedColor()
![Page 17: Color How X handles color. Widget use of color n Widgets that use color have u XmNforeground u XmNbackground u XmNborderColor (since default border width](https://reader036.vdocument.in/reader036/viewer/2022062314/56649d7a5503460f94a5ed9a/html5/thumbnails/17.jpg)
ExampleUses XAllocNamedColor()
![Page 18: Color How X handles color. Widget use of color n Widgets that use color have u XmNforeground u XmNbackground u XmNborderColor (since default border width](https://reader036.vdocument.in/reader036/viewer/2022062314/56649d7a5503460f94a5ed9a/html5/thumbnails/18.jpg)
Getting info. Because a “closest” will be chosen for
you, you can use
Colormap cmap;
Xcolor color;
color.red = ...
XQueryColor(display,cmap,&color);
or
XParseColor(display,cmap,65535,&color)
or
XLookupColor(display,cmap,name,&color,&exact)
for information about what will happen
![Page 19: Color How X handles color. Widget use of color n Widgets that use color have u XmNforeground u XmNbackground u XmNborderColor (since default border width](https://reader036.vdocument.in/reader036/viewer/2022062314/56649d7a5503460f94a5ed9a/html5/thumbnails/19.jpg)
Allocating private cells To allocate private color cells use
XAllocColorCells ( ) library routine to allocate the cells. This should be checked for failure.
Then XStoreColor( ) or XStoreNamedColor( ) can be used to fill these cells.
private color cells should be freed when no longer needed with XFreeColors( ). DO NOT CALL with shared cells.
![Page 20: Color How X handles color. Widget use of color n Widgets that use color have u XmNforeground u XmNbackground u XmNborderColor (since default border width](https://reader036.vdocument.in/reader036/viewer/2022062314/56649d7a5503460f94a5ed9a/html5/thumbnails/20.jpg)
Standard ColorMaps To promote maximum sharing X
provides several standard color maps. These maps contain cells with preloaded values.
The root window usually loads a standard colormap at startup
Application using a standard colormap face colormap change effects and must take what they get.
![Page 21: Color How X handles color. Widget use of color n Widgets that use color have u XmNforeground u XmNbackground u XmNborderColor (since default border width](https://reader036.vdocument.in/reader036/viewer/2022062314/56649d7a5503460f94a5ed9a/html5/thumbnails/21.jpg)
Colormaps are resources XCreateColormap( ) XCopyColormap( ) are both ways
to create new colormaps. Colormaps created by applications must be installed in order to be used and are destroyed on exit.
XInstallColormap( ) XUninstallColormap( ) XFreeColormap( )
![Page 22: Color How X handles color. Widget use of color n Widgets that use color have u XmNforeground u XmNbackground u XmNborderColor (since default border width](https://reader036.vdocument.in/reader036/viewer/2022062314/56649d7a5503460f94a5ed9a/html5/thumbnails/22.jpg)
Colormaps are not really private Installed colormaps are a resource
of the screen and if its resource id is discovered by other applications (XListInstalledColormaps( )) it can be used - but not altered if you fill all the cells)
Once installed it must be associated with windows.
![Page 23: Color How X handles color. Widget use of color n Widgets that use color have u XmNforeground u XmNbackground u XmNborderColor (since default border width](https://reader036.vdocument.in/reader036/viewer/2022062314/56649d7a5503460f94a5ed9a/html5/thumbnails/23.jpg)
Events
Applications can arrange to receive ColormapNotify events. These events notify the application of changes to the colormap in your windows.
![Page 24: Color How X handles color. Widget use of color n Widgets that use color have u XmNforeground u XmNbackground u XmNborderColor (since default border width](https://reader036.vdocument.in/reader036/viewer/2022062314/56649d7a5503460f94a5ed9a/html5/thumbnails/24.jpg)
SummaryApplications draw into windows and pixmaps using pixel
values. These values are relative to color cells that are defined in colormaps. Applications cannot assume any meaning about colors on a platform. X calls are used to generate pixel values corresponding to desired colors.
Colors are specified as a combination of red green and blue values. Each color map cell contains a single rgb triplet. Colormap cells are scarse, so choosing the closest color values to the default colormap installed in the root window is a preferred technique. However applications can create and install their own private color maps. Changing colormaps on some platforms can create undesirable effects outside of the application window.
![Page 25: Color How X handles color. Widget use of color n Widgets that use color have u XmNforeground u XmNbackground u XmNborderColor (since default border width](https://reader036.vdocument.in/reader036/viewer/2022062314/56649d7a5503460f94a5ed9a/html5/thumbnails/25.jpg)
SummaryProduction code must do a lot of determination about the
platform on which it is running before using library routines: the number of colormap cells, the default color map, the number of color planes ( not discussed with these slides)
Xlib provides a variety of service functions for color, the most important being the ability to translate named colors into rgb triples.
![Page 26: Color How X handles color. Widget use of color n Widgets that use color have u XmNforeground u XmNbackground u XmNborderColor (since default border width](https://reader036.vdocument.in/reader036/viewer/2022062314/56649d7a5503460f94a5ed9a/html5/thumbnails/26.jpg)
Future studies Students interested in color should
look next into visual techniques and their support in X color planes support in X for applications that
need to interpolate between colors for shading effects.
Production quality color code examples should be investigated.
HAVE A GREEN DAY!