Page 1 of 1

Colors in GTK+

Posted: Sun Nov 16, 2008 4:52 pm
by bewing
I know this is a pretty specific topic -- but I know a few of you have programmed GTK, and it's a pretty simple question.

I am trying to code in some widget background colors in RGB. My display is 8x3=24bit truecolor. My version of GTK/GDK is processing my colors through what looks like a 256 color palette -- so they come out looking utterly ridiculous.

Q: does GTK/GDK always use a palette, and play the "closest match to requested color" game? Or is it a fluke that it's using a palette on my truecolor display?

Re: Colors in GTK+

Posted: Sun Nov 16, 2008 5:34 pm
by Alboin
What code are you using? I have a 24bit true color display (At least that is what Gdk seems to think.), and I have no problems making an orange button with:

Code: Select all

GdkColor color;
color.red = 60000;
color.blue = 0;
color.green = 30000;
gtk_widget_modify_bg(button, GTK_STATE_NORMAL, &color);
You can check what your GTK is using by getting your GdkVisual:

Code: Select all

GdkColormap *map = gdk_colormap_get_system();
GdkVisual *visual = gdk_colormap_get_visual(map);

printf("%i\n", visual->depth); 
...
Hope that helps, if only a little.
-Alboin

Note: With a truecolor, the visual->colormap_size is always 256. Don't be alarmed. In a sense, this means the answer to your question is "no", in that GTK somewhat 'ignores' the palette, setting it to 256, when it has a truecolor display.

Re: Colors in GTK+

Posted: Sun Nov 16, 2008 7:35 pm
by bewing
Thank you. It prints a depth of 24, and your code works.

I had created a macro to make the "transition" from Win32 to GTK easier. But the first reference that I saw had the GdkColor elements in the wrong order, so my macro creates the elements wrong. It was easy to fix, once your code showed me what to check!