Simplest way to use a named colour ? - Motif

This is a discussion on Simplest way to use a named colour ? - Motif ; Ok, in a UIL file, I can have something very simple such as: XmNbackground = color('Light Steel Blue', background) ; Somewhere in there, the colour gets translated to the right stuff and applied to the background of the widget and ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: Simplest way to use a named colour ?

  1. Simplest way to use a named colour ?

    Ok, in a UIL file, I can have something very simple such as:

    XmNbackground = color('Light Steel Blue', background) ;

    Somewhere in there, the colour gets translated to the right stuff and applied
    to the background of the widget and I don't have to lift a finger.

    Now, I want to dynamically set a colour inside a C program to either red ,
    yellow or green.

    I've looked through example programs and couldn't find a single simple way of
    doing this.

    What is the simplest way to convert a standard named colour into a "Pixel"
    which I can then use as an argument to XtSetValues on the Widget ?

  2. Re: Simplest way to use a named colour ?

    JF Mezei wrote in
    news:41B9C63B.466F7A06@teksavvy.com:
    > What is the simplest way to convert a standard named colour into a
    > "Pixel" which I can then use as an argument to XtSetValues on the Widget


    Subject 155 in the Motif FAQ. My web site has a copy of the FAQ.

    Ken Lee, http://www.rahul.net/kenton/


  3. Re: Simplest way to use a named colour ?

    Ken Lee wrote:
    > Subject 155 in the Motif FAQ. My web site has a copy of the FAQ.


    Many thanks. Don't think I would have ever found it on my own as I was looking
    for something to convert from colour to a pixel,. What 155 shows is a far
    simpler than I expected it.

  4. Re: Simplest way to use a named colour ?

    JF Mezei wrote:

    > Ken Lee wrote:
    > > Subject 155 in the Motif FAQ. My web site has a copy of the FAQ.

    >
    > Many thanks. Don't think I would have ever found it on my own as I was looking
    > for something to convert from colour to a pixel,. What 155 shows is a far
    > simpler than I expected it.


    Yes, it really is that simple. To make it as short and sweet as
    possible, you can define a macro like this:

    #define TArg(name,value) XtVaTypedArg, name, XmRString, value,
    strlen(value)+1

    Then you can just do

    XtVaSetValues(w, TArg(XmNbackground, "yellow"), NULL);

    This also works for things like converting strings to XmStrings:

    XtVaSetValues(w, TArg(XmNlabelString, "Push me"), NULL);

    but there is a caveat: This causes a memory leak. If the conversion
    allocates memory for the result, this memory is never freed.

    --
    Per Espen Hagen, Principal Scientist
    Norwegian Defence Research Establishment

  5. Re: Simplest way to use a named colour ?

    In article <41BEF7E3.14768201@ffi.no> Per Espen Hagen writes:

    > XtVaSetValues(w, TArg(XmNbackground, "yellow"), NULL);


    Note that the color name needs to be in the RGB database. You can look at the
    text version to see what names are there. The file is usually
    /usr/lib/X11/rgb.txt, but on Sun Solaris it is /usr/openwin/lib/X11/rgb.txt.
    All the standard colors should always be there ("white", "black", "magenta",
    etc.), but some colors like "papaya whip" or "blanched almond" may not be on
    all systems (they should be, though).

    I'm pretty sure you can use the hex-encoded RGB syntax as well, such as
    "#FFFFFF" for white or "#FFEFD5" for papaya whip. X also supports syntaxes
    that specify colors using the various CIE specifications or RGBi, etc.

    -Pete Zakel
    (phz@seeheader.nospam)

    "gy-ro-scope: A wheel or disk mounted to spin rapidly about an axis and also
    free to rotate about one or both of two axes perpendicular to each other and
    the axis of spin so that a rotation of one of the two mutually perpindicular
    axes results from application of torque to the other when the wheel is
    spinning and so that the entire apparatus offers considerable opposition
    depending on the angular momentum to any torque that would change the
    direction of the axis of spin."

    -Webster's Seventh New Collegiate Dictionary

+ Reply to Thread