Re: Changing the background color of a window



On Tue, Feb 25, 2003 at 06:42:20PM +0100, Sven Neumann wrote:
> Hi,
> 
> "j. santana" <jvgs osite com br> writes:
> 
> > I'm trying to change the background color of a window
> > randomly, but I always get a black filled window,
> > even though I get random values from g_rand.
> > 
> > (I'm trying this as an exercise in learning GTK.)
> 
> Colors are especially hard to get right so this is probably a bad
> exercise to start with.
> 
> > What would be the best way to achieve this effect ?
> > 
> >      color.red = g_rand_int_range(rand,0,256);
> >      color.green = g_rand_int_range(rand,0,256);
> >      color.blue = g_rand_int_range(rand,0,256);
> 
> The red, green, blue fields of the GdkColor struct use 16 bit, so you
> will want to use a range from 0 to 1<<16. This will however not
> suffice since you need to allocate the color before it can be used.

I don't think gtk_widget_modify_bg() requires allocating the color...

In general with GTK 2 allocating/freeing colors should never be
necessary, gdk_rgb_find_color() and
gdk_gc_set_fg_color()/gdk_gc_set_bg_color() should be used instead.

Havoc



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