Re: [gtk-list] Re: Setting Widget Attributes (Half Solution)



Johannes Keukelaar wrote:
> You'll probably want to do gdk_color_alloc, as well. (You may have to
> initialize the pixel value before calling gdk_color_alloc, I'm kind of vague
> about that.) I quote the following from the FAQ:
> 
> /* the color we want to use */
> color = (GdkColor *)malloc(sizeof(GdkColor));
> 
> /* red, green, and blue are passed values, indicating the RGB triple
>  * of the color we want to draw. Note that the values of the RGB components
>  * within the GdkColor are taken from 0 to 65535, not 0 to 255.
>  */
> color->red = red * (65535/255);
> color->green = green * (65535/255);
> color->blue = blue * (65535/255);
> 
> /* the pixel value indicates the index in the colormap of the color.
>  * it is simply a combination of the RGB values we set earlier
>  */
> color->pixel = (gulong)(red*65536 + green*256 + blue);
> 
> /* However, the pixel valule is only truly valid on 24-bit (TrueColor)
>  * displays. Therefore, this call is required so that GDK and X can
>  * give us the closest color available in the colormap
>  */
> gdk_color_alloc(gtk_widget_get_colormap(widget), color);

If the color is a standard X one, instead of setting directly the pixel,
R, G and B values it may be preferable to call gdk_color_parse, btw
gdk_color_parse("slate gray", &color).



Saludos



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]