Re: [gtk-list] Re: How do I get r,g,b from gdk_gc_get_values?




Rob Browning <rlb@cs.utexas.edu> writes:

> I think I figured out the answer (at least it seems to work).  Please
> let me know if this is wrong.  Also, do I need any other
> "free/unref's" here?
> 
>   GdkGCValues gcv;
>   GdkVisual *visual = gtk_widget_get_visual(GTK_WIDGET(w));
>   GdkColormap *cmap = gtk_widget_get_colormap(GTK_WIDGET(w)); 
>   GdkColorContext *cc = gdk_color_context_new(visual, cmap);
>   GdkColor fg;
> 
>   gdk_gc_get_values(gc, &gcv);
> 
>   fg.pixel = gc.foreground.pixel;
>   gdk_color_context_query_color(cc, &fg);
> 
>   gdk_color_context_free(cc);
>   cc = NULL:

It should work, but is a pretty expensive way of doing it.
ColorContext's are heavyweight objects. (Eventually, you
should be doing all color allocation through a CC, so 
you would typically allocate one at the start of your program
and just use it throughout)

But I might wonder why you want to do this ...

Either you created the GC yourself, in which case know what
you set the foreground color is.

Or you got the GC out of widget->style, in which case there
is a corresponding color entry (style->white_gc <=> style->white)
which will have it's R,G,B filled in.

(The reason that they aren't filled in for gdk_gc_get_values, 
is that the server just return sthe pixel for XGCGetValues,
and it would be expensive to all XQueryColor to fill in the
remainder, when it usually isn't needed. Or so I assume.)

Regards,
                                        Owen



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