Re: Changing the background color of a window



  Havoc Pennington wrote:

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

  I eventually got my test program running fine,
  see my reply to Sven.

> 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.

  With these functions things didn't go too well.

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

     GdkColor color = {-1,-1,-1,-1};
     GdkEventConfigure * cfg = (GdkEventConfigure*)e;

     color.red = g_rand_int_range(my_rand,0,256);
     color.green = g_rand_int_range(my_rand,0,256);
     color.blue = g_rand_int_range(my_rand,0,256);

     gdk_rgb_find_color(gtk_widget_get_colormap(w),
        &color);

     g_print("color: pixel=%08X red=%02X green=%02X"
        "blue=%02X\n",color.pixel,color.red,
        color.green,color.blue);

     gdk_gc_set_foreground(
         w->style->bg_gc[GTK_STATE_NORMAL],&color);

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

     return TRUE; // FALSE ?

     }

  Pixel.color always gets zero after
     gdk_rgb_find_color.

  I tried reading the sources to find some clue, but
  they are, well, a little difficult.

  FWIW I'm using 16-bit color.

  (Posting from 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]