Re: GC foreground color.



On Wed, 2003-06-25 at 04:48, Deganello Aligi wrote:
  Hi all, I want to draw a red line on a drawing area but it seem not
possible to chage the foreground color. I can't understand why I can modify
the line attributes but not the color. Can someone help me. I'm virgin new
user of GTK.
Here is the code. What's wrong?

static gint expose_event (GtkWidget *widget, GdkEventExpose *event)
{
      GdkGC           *gc;
      GdkColor        *color;

      gc=gdk_gc_new(widget->window);
      color = g_malloc(sizeof(GdkColor));
      color->red = 0xffff; color->green = 0x0; color->blue = 0x0;
      gdk_gc_set_foreground(gc, color);

A) No reason to malloc the color here. Just allocate it on the 
stack:

 GdkColor red = { 0, 0xffff, 0, 0 };

B) gdk_gc_set_foreground() takes an allocated color. You'd need
   to use gdk_colormap_alloc_color() first. But easier, use
   gdk_gc_set_rgb_fg_color() which does the allocation for you.

     gdk_gc_set_rgb_fg_color (gc, &red);

Regards,
                                Owen





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