Re: Changing the background color of a window



  Sven Neumann wrote:

> 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.
> If you really want to play with colors,
> you should read...

  In fact, for gtk_widget_modify_bg the color
  "does not need to" (must not?) "be allocated",
  as the reference says.
  But indeed it must have been parsed by 
  gdk_color_parse before feeding it to
  gtk_widget_modify_bg. That's what I found.

  static int
  configure_event_cb(GtkWidget * w, GdkEvent * e,
     gpointer p) {

     char * rgb;
     GdkColor color;
     int red, green, blue;
     GdkEventConfigure * cfg = (GdkEventConfigure*)e;
    
     red = g_rand_int_range(my_rand,0,65536);
     green = g_rand_int_range(my_rand,0,65536);
     blue = g_rand_int_range(my_rand,0,65536);
     rgb=g_strdup_printf("#%02X%02X%02X",
        red,green,blue);

     gdk_color_parse(rgb,&color);
     gtk_widget_modify_bg(w,GTK_STATE_NORMAL,&color);

     gtk_widget_queue_draw_area(w,0,0,
        cfg->width,cfg->height);
 
     g_free(rgb);

     return FALSE;

     }
 
  Now it runs fine. (No expose_event callback.)

  (Posting prom webmail, don't know how this
  will look).
-- 
__________________________________________________________
Sign-up for your own FREE Personalized E-mail at Mail.com
http://www.mail.com/?sr=signup




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