#include static gboolean expose_event (GtkWidget *widget, GdkEventExpose *ev) { cairo_t *context; cairo_t *pcontext; cairo_surface_t *surface; context = gdk_cairo_create (widget->window); surface = cairo_surface_create_similar (cairo_get_group_target (context), CAIRO_CONTENT_COLOR_ALPHA, 4, 4); pcontext = cairo_create (surface); cairo_surface_destroy (surface); cairo_set_source_rgba (pcontext, 1.0, 0.0, 0.0, 0.8); cairo_rectangle (pcontext, 1, 1, 2, 2); cairo_fill (pcontext); cairo_set_source_surface (context, cairo_get_target (pcontext), 0, 0); cairo_destroy (pcontext); cairo_pattern_set_extend (cairo_get_source (context), CAIRO_EXTEND_REPEAT); cairo_move_to (context, 100.5, 100.5); cairo_line_to (context, 100.5, 600.5); cairo_line_to (context, 600.5, 600.5); cairo_line_to (context, 600.5, 550.5); cairo_line_to (context, 150.5, 550.5); cairo_line_to (context, 150.5, 100.5); cairo_line_to (context, 100.5, 100.5); cairo_fill (context); cairo_destroy (context); return FALSE; } int main (int argc, char **argv) { GtkWidget *window, *draw; gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_widget_set_size_request (window, 800, 800); g_signal_connect (window, "delete-event", G_CALLBACK (gtk_main_quit), NULL); draw = gtk_drawing_area_new (); g_signal_connect (draw, "expose-event", G_CALLBACK (expose_event), NULL); gtk_container_add (GTK_CONTAINER (window), draw); gtk_widget_show_all (window); gtk_main (); return 0; }