Re: setting background color to drawing area
- From: Paul Barton-Davis <pbd Op Net>
- To: Gtk users <gtk-list gnome org>
- Subject: Re: setting background color to drawing area
- Date: Wed, 06 Dec 2000 17:03:34 -0500
In message <14894 45509 293328 823890 helion crl nmsu edu>you write:
>
> Billy> I've been looking throught the archived mail but havent found
> Billy> anything but discussions about doing this. I'm just on my 2nd day
> Billy> with gtk and need some assistance.
>
>Setting it is easy. Changing it a lot seems to be trickier. Anyway:
>
> GdkColor newbg;
> GtkStyle *style;
>
> style = gtk_style_copy(gtk_widget_get_style(widget));
> style->bg[GTK_STATE_NORMAL] = newbg;
> gtk_widget_set_style(widget, style);
>
>You have get the color you want by using the GDK color routines first.
just to be persnickety again, doing this directly in the code is a
generally bad idea. instead do this:
gtk_widget_set_name (area_widget, "MyArea");
then load an RC file with
style "my_area" {
bg[NORMAL] = { N1, N2, N3 }
bg[SELECTED] = { N4, N5, N6 }
}
widget "*MyArea" style "my_area"
where N1..N6 are suitable values between 0.0 and 1.0, and define the
RGB levels for the desired colors.
then to change colors:
gtk_widget_set_state (area_widget, GTK_STATE_SELECTED);
you save yourself typing a bunch of code, and more importantly, the
colors can be changed without recompilation.
this only works if you have a limited number of colors, of course. if
you really want to change to one of more than about 4 colors, you'll
have to use mark's suggested method, except that you should really be
using the rc_style, as indicated in a message from Havoc:
GdkColor red = { 0, 65535, 0, 0 };
GtkRcStyle *rc_style = gtk_rc_style_new ();
rc_style->bg[GTK_STATE_NORMAL] = red;
rc_style->color_flags[GTK_STATE_NORMAL] |= GTK_RC_BG;
gtk_widget_modify_style (widget, rc_style);
gtk_rc_style_unref (rc_style);
--p
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]