Re: How to get Colors?



Hi;

On 4 May 2015 at 01:01, The Devils Jester <thedevilsjester gmail com> wrote:
I am trying to get general GTK system colors for use in custom rendering
operations.  In MSW, I would get these colors through a function like
GetSysColor, but GTK does not appear to have such a function.

That is not wholly correct, but to a first approximation, yes: there
is no such thing as "system color".

GTK+ uses CSS, which does support more than just colors for rendering
operations: you can also have gradients with multiple stops, or
images.

The only way that comes to mind, to get a bunch of common system colors, is
to create a bunch of widgets (one of each type that has a color I need),
parent said widget, and make sure its realized, using
gtk_style_context_get_color.  This seems like an awful lot of overhead (and
a bit overkill) just to get some colors.  Am I missing some more direct
method?

The actual question would be: what are you drawing? If you're drawing
bits and pieces of the UI in your custom rendering, then you should be
using the gtk_render_* class of functions. For instance, if you want
to render the same background, using the same style, of a widget you
should use gtk_render_background(); if you want to render text using
the same style as entries or labels, you should use
gtk_render_layout(); if you want to render images, you should use
gtk_render_icon(). This is what widgets do internally.

If you're rending custom things then you can either combine all of the
above, or you can use custom rendering code. If you opt for the
latter, then you should not be using the theme anyway, because you're
clearly creating something that does not fit into the style of the
overall platform. You can still use the CSS machinery, though, through
CSS style classes, and the GtkStyleContext API.

Ciao,
 Emmanuele.

-- 
https://www.bassi.io
[ ] ebassi [ gmail com]


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