Colors in GTK+

Programming, for all ages and all languages.
Post Reply
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Colors in GTK+

Post 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?
User avatar
Alboin
Member
Member
Posts: 1466
Joined: Thu Jan 04, 2007 3:29 pm
Location: Noricum and Pannonia

Re: Colors in GTK+

Post 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.
C8H10N4O2 | #446691 | Trust the nodes.
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Re: Colors in GTK+

Post 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!
Post Reply