Parent document is top of "Motif FAQ (Part 9 of 9)"
Previous document is "313) How do I install a private colormap?"
Next document is "315) What color algorithm does Motif use? I am told that Motif uses"

314) How do I get correct shadow colors to match other color

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.

Parent document is top of "Motif FAQ (Part 9 of 9)"
Previous document is "313) How do I install a private colormap?"
Next document is "315) What color algorithm does Motif use? I am told that Motif uses"