diff options
author | Benjamin Otte <otte@redhat.com> | 2016-11-08 01:42:06 +0100 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2016-11-15 17:48:45 +0100 |
commit | bb9626dc292edbd7a624c9b0ce921c2767612ba9 (patch) | |
tree | 841e2f3d3e14e6897268ec5e753e5a66b12a4c98 /gtk/gtkcontainer.c | |
parent | b1154be1c4210c095760555af9f4f3f0058f4903 (diff) | |
download | gtk+-bb9626dc292edbd7a624c9b0ce921c2767612ba9.tar.gz |
window: Implement snapshot()
Diffstat (limited to 'gtk/gtkcontainer.c')
-rw-r--r-- | gtk/gtkcontainer.c | 117 |
1 files changed, 81 insertions, 36 deletions
diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c index a68fa8708c..893b1e43c0 100644 --- a/gtk/gtkcontainer.c +++ b/gtk/gtkcontainer.c @@ -42,6 +42,7 @@ #include "gtkmarshalers.h" #include "gtksizerequest.h" #include "gtksizerequestcacheprivate.h" +#include "gtksnapshotprivate.h" #include "gtkwidgetprivate.h" #include "gtkwindow.h" #include "gtkassistant.h" @@ -3158,47 +3159,16 @@ gtk_container_get_children_clip (GtkContainer *container, gtk_container_forall (container, union_with_clip, out_clip); } -/** - * gtk_container_propagate_draw: - * @container: a #GtkContainer - * @child: a child of @container - * @cr: Cairo context as passed to the container. If you want to use @cr - * in container’s draw function, consider using cairo_save() and - * cairo_restore() before calling this function. - * - * When a container receives a call to the draw function, it must send - * synthetic #GtkWidget::draw calls to all children that don’t have their - * own #GdkWindows. This function provides a convenient way of doing this. - * A container, when it receives a call to its #GtkWidget::draw function, - * calls gtk_container_propagate_draw() once for each child, passing in - * the @cr the container received. - * - * gtk_container_propagate_draw() takes care of translating the origin of @cr, - * and deciding whether the draw needs to be sent to the child. It is a - * convenient and optimized way of getting the same effect as calling - * gtk_widget_draw() on the child directly. - * - * In most cases, a container can simply either inherit the - * #GtkWidget::draw implementation from #GtkContainer, or do some drawing - * and then chain to the ::draw implementation from #GtkContainer. - **/ -void -gtk_container_propagate_draw (GtkContainer *container, - GtkWidget *child, - cairo_t *cr) +static void +gtk_container_get_translation_to_child (GtkContainer *container, + GtkWidget *child, + int *x_out, + int *y_out) { GtkAllocation allocation; GdkWindow *window, *w; int x, y; - g_return_if_fail (GTK_IS_CONTAINER (container)); - g_return_if_fail (GTK_IS_WIDGET (child)); - g_return_if_fail (cr != NULL); - g_return_if_fail (_gtk_widget_get_parent (child) == GTK_WIDGET (container)); - - if (!gtk_container_should_propagate_draw (container, child, cr)) - return; - /* translate coordinates. Ugly business, that. */ if (!_gtk_widget_get_has_window (GTK_WIDGET (container))) { @@ -3235,6 +3205,51 @@ gtk_container_propagate_draw (GtkContainer *container, y += allocation.y; } + *x_out = x; + *y_out = y; +} + +/** + * gtk_container_propagate_draw: + * @container: a #GtkContainer + * @child: a child of @container + * @cr: Cairo context as passed to the container. If you want to use @cr + * in container’s draw function, consider using cairo_save() and + * cairo_restore() before calling this function. + * + * When a container receives a call to the draw function, it must send + * synthetic #GtkWidget::draw calls to all children that don’t have their + * own #GdkWindows. This function provides a convenient way of doing this. + * A container, when it receives a call to its #GtkWidget::draw function, + * calls gtk_container_propagate_draw() once for each child, passing in + * the @cr the container received. + * + * gtk_container_propagate_draw() takes care of translating the origin of @cr, + * and deciding whether the draw needs to be sent to the child. It is a + * convenient and optimized way of getting the same effect as calling + * gtk_widget_draw() on the child directly. + * + * In most cases, a container can simply either inherit the + * #GtkWidget::draw implementation from #GtkContainer, or do some drawing + * and then chain to the ::draw implementation from #GtkContainer. + **/ +void +gtk_container_propagate_draw (GtkContainer *container, + GtkWidget *child, + cairo_t *cr) +{ + int x, y; + + g_return_if_fail (GTK_IS_CONTAINER (container)); + g_return_if_fail (GTK_IS_WIDGET (child)); + g_return_if_fail (cr != NULL); + g_return_if_fail (_gtk_widget_get_parent (child) == GTK_WIDGET (container)); + + if (!gtk_container_should_propagate_draw (container, child, cr)) + return; + + gtk_container_get_translation_to_child (container, child, &x, &y); + cairo_save (cr); cairo_translate (cr, x, y); @@ -3243,6 +3258,36 @@ gtk_container_propagate_draw (GtkContainer *container, cairo_restore (cr); } +void +gtk_container_snapshot_child (GtkContainer *container, + GskRenderNode *container_node, + GtkWidget *child, + const GtkSnapshot *snapshot) +{ + GtkSnapshot child_snapshot; + GskRenderNode *child_node; + int x, y; + + g_return_if_fail (GTK_IS_CONTAINER (container)); + g_return_if_fail (GTK_IS_WIDGET (child)); + g_return_if_fail (_gtk_widget_get_parent (child) == GTK_WIDGET (container)); + g_return_if_fail (GSK_IS_RENDER_NODE (container_node)); + g_return_if_fail (snapshot != NULL); + + gtk_container_get_translation_to_child (container, child, &x, &y); + + gtk_snapshot_init_translate (&child_snapshot, snapshot, x, y); + child_node = gtk_widget_snapshot (child, &child_snapshot); + + if (child_node) + { + gsk_render_node_append_child (container_node, child_node); + gsk_render_node_unref (child_node); + } + + gtk_snapshot_finish (&child_snapshot); +} + /** * gtk_container_get_path_for_child: * @container: a #GtkContainer |