Since most of the gdk_gc_*
methods are deprecated in GTK+ 3, how does one paint on sub-windows using Cairo only? Below is a simple example of what I would like to achieve:
GdkWindow *tl_window = parent_widget->window;
GdkGC *gc = gdk_gc_new(tl_window1->window);
gdk_gc_set_subwindow(gc, GDK_INCLUDE_INFERIORS);
gdk_gc_set_exposures(gc, FALSE);
do_my_painting(tl_window, gc);
gdk_gc_unref(gc);
http://developer.gnome.org/gdk/stable/gdk-Graphics-Contexts.html#gdk-gc-set开发者_如何学JAVA-subwindow says GDK_INCLUDE_INFERIORS
will be used on sources. So I assume the trick is to create a source of the window and then ... well then ... I'm stuck.
Found a solution myself
GtkWidget *tl_window = gtk_widget_get_toplevel(widget);
cairo_t *cairo = gdk_cairo_create(gtk_widget_get_window(tl_window));
cairo_surface_t *source_surface = cairo_get_target(cairo);
cairo_t *cairo_new = cairo_create(source_surface);
cairo_set_source_surface(cairo, cairo_get_target(cairo_new), 0, 0);
do_my_painting(cairo_new);
cairo_paint(cairo);
cairo_destroy(cairo);
(do I mis a destroy of cairo_new here ?)
I also found the next link (did not test it) http://mail.gnome.org/archives/commits-list/2010-August/msg03385.html where they seem to use a pixmap instead of a surface.
精彩评论