GC foreground color.

  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;

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

        gdk_draw_line(widget->window, gc, 10, 10, 100, 10);
        return FALSE;
int main( int argc, char *argv[] )
    GtkWidget *window;
    GtkWidget *drawing_area;
    gtk_init (&argc, &argv);
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title (GTK_WINDOW (window), "Drawing Area");
    gtk_widget_set_usize(GTK_WIDGET(window), 140, 40);
    gtk_signal_connect (GTK_OBJECT (window), "destroy",
                        GTK_SIGNAL_FUNC (gtk_exit), NULL);
    gtk_container_set_border_width (GTK_CONTAINER (window), 10);
    /* Create a drawing area */
    drawing_area = gtk_drawing_area_new();
    gtk_widget_show (drawing_area);
    gtk_container_add (GTK_CONTAINER (window), drawing_area);
    gtk_signal_connect (GTK_OBJECT (drawing_area), "expose_event",
expose_event, NULL);
    gtk_widget_set_events (drawing_area, GDK_EXPOSURE_MASK);
    gtk_widget_show (window);
    gtk_main ();

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