Search the FAQ Archives

3 - A - B - C - D - E - F - G - H - I - J - K - L - M
N - O - P - Q - R - S - T - U - V - W - X - Y - Z
faqs.org - Internet FAQ Archives

Motif FAQ (Part 9 of 9)
Section - 309) How do I get correct shadow colors to match other color

( Part1 - Part2 - Part3 - Part4 - Part5 - Part6 - Part7 - Part8 - Part9 - Single Page )
[ Usenet FAQs | Web FAQs | Documents | RFC Index | Schools ]


Top Document: Motif FAQ (Part 9 of 9)
Previous Document: 308) How do I install a private colormap?
Next Document: 310) What color algorithm does Motif use? I am told that Motif uses
See reader questions & answers on this topic! - Help others by sharing your knowledge
changes?
[Last modified: Sept 95]

Answer: Thanks to Craig MacFarlane (craigm@chateau-rouge.ICS.UCI.EDU) for the
following explanation and code:

You have to make a call to calculate the new shadow colors.  The trick is
actually getting a value of type Pixel when all you have is the string "Blue".
I use the XtConvertAndStore() function to convert from a char * to a Pixel.
For example:


char *color = "blue";
XrmValue color_value, pixel_value;
Pixel background;

color_value.size = strlen(color);
color_value.addr = (XtPointer) color;
pixel_value.size = sizeof(Pixel);
pixel_value.addr = (XtPointer) 0;

result = XtConvertAndStore(widget,
                     XtRString, &color_value,
                     XtRPixel, &pixel_value);

background = (*(Pixel *)pixel_value.addr);


You can then use the pixel value obtained by XtConvertAndStore() in the
XmGetColors call.  XmGetColors calculates appropriate foreground, topshadow,
bottomshadow, and select colors for the given background. e.g.


XmGetColors(screen,
      DefaultColormap(display_id, DefaultScreen(display_id)),
      background,
      &foreground, &topshadow, &bottomshadow, &select);


Then it's trivial to set the shadow colors at the same time you set the
foreground and background colors.  For example:


XtVaSetValues(widget,
    XmNforeground, foreground,
    XmNbackground, background,
    XmNarmColor, select,
    XmNtopShadowColor, topshadow,
    XmNbottomShadowColor, bottomshadow,
    NULL);


You'll get asthetically pleasing colors every time. :)

Wolfram Gries <1gries@informatik.uni-hamburg.de> adds:

The function XmChangeColor() takes a Widget and a Pixel-value for the new
background-color and does the calculation of the new shadow-colors on its own.
But it seems to me that this function is rather slow, so if you often change
the color of your widgets, the XmGetColors()/XmSetColors() approach might be
better.

User Contributions:

Comment about this article, ask questions, or add new information about this topic:




Top Document: Motif FAQ (Part 9 of 9)
Previous Document: 308) How do I install a private colormap?
Next Document: 310) What color algorithm does Motif use? I am told that Motif uses

Part1 - Part2 - Part3 - Part4 - Part5 - Part6 - Part7 - Part8 - Part9 - Single Page

[ Usenet FAQs | Web FAQs | Documents | RFC Index ]

Send corrections/additions to the FAQ Maintainer:
kenton@rahul.net (Ken Lee)





Last Update March 27 2014 @ 02:11 PM