GTK 绘图相关函数

1.回调函数configure_event,创建窗口时调用该函数,创建一块新的PIXMAP。
gboolean configure_event(GtkWidget *widget, GdkEventConfigure *event, gpointer data)
{
    if(pixmap)
        g_object_unref(pixmap);    //Create the new pixmap
    pixmap = gdk_pixmap_new(widget->window,

                                                 widget->allocation.width,

                                                 widget->allocation.height,
                                                 -1);
    //initialize the pixmap  --- no need, default with black
/*--------------------------------------------------------------------------
    gdk_draw_rectangle(pixmap,
               widget->style->white_gc,
               TRUE,
               0, 0,
               widget->allocation.width,
               widget->allocation.height);
-----------------------------------------------------------------------------*/
    return TRUE;
}

 

2.回调函数expose_event,这个函数比较重要,它实现区域的重绘。每次当drawing_area的窗口的某块区域被挡住或者最小化后再重现都会自动调用该函数,对失效区域重画。另外,我们也可以自己调用gdk_window_invalidate_rect()或是gtk_widget_queue_draw_area()等函数来发送一条重绘消息。
gboolean expose_event(GtkWidget *widget,GdkEventExpose *event,gpointer data)
{
    //draw the pixmap onto the drawable
    gdk_draw_drawable(widget->window,
                                      widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
                                      pixmap,
                                      event->area.x, event->area.y,
                                      event->area.x, event->area.y,
                                      event->area.width, event->area.height);
    return FALSE;
}

你可能感兴趣的:(object,gtk)