[gtk+/wip/baedert/children: 55/57] widget: Add widget version of gtk_container_snapshot_child



commit d0df2db7a69c1fb11f74d32f07207d13006878d1
Author: Timm Bäder <mail baedert org>
Date:   Wed Nov 16 14:32:50 2016 +0100

    widget: Add widget version of gtk_container_snapshot_child

 gtk/gtkwidget.c        |   69 ++++++++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkwidgetprivate.h |    4 +++
 2 files changed, 73 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 9dcea00..123520f 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -15812,3 +15812,72 @@ gtk_widget_forall (GtkWidget *widget, GtkCallback cb, gpointer user_data)
       cb (p, user_data);
     }
 }
+
+static void
+gtk_widget_get_translation_to_child (GtkWidget    *widget,
+                                        GtkWidget    *child,
+                                        int          *x_out,
+                                        int          *y_out)
+{
+  GtkAllocation allocation;
+  GdkWindow *window, *w;
+  int x, y;
+
+  /* translate coordinates. Ugly business, that. */
+  if (!_gtk_widget_get_has_window (widget))
+    {
+      _gtk_widget_get_allocation (widget, &allocation);
+      x = -allocation.x;
+      y = -allocation.y;
+    }
+  else
+    {
+      x = 0;
+      y = 0;
+    }
+
+  window = _gtk_widget_get_window (widget);
+
+  for (w = _gtk_widget_get_window (child); w && w != window; w = gdk_window_get_parent (w))
+    {
+      int wx, wy;
+      gdk_window_get_position (w, &wx, &wy);
+      x += wx;
+      y += wy;
+    }
+
+  if (w == NULL)
+    {
+      x = 0;
+      y = 0;
+    }
+
+  if (!_gtk_widget_get_has_window (child))
+    {
+      _gtk_widget_get_allocation (child, &allocation);
+      x += allocation.x;
+      y += allocation.y;
+    }
+
+  *x_out = x;
+  *y_out = y;
+}
+
+void
+gtk_widget_snapshot_child (GtkWidget      *widget,
+                           GtkWidget      *child,
+                           GtkSnapshot    *snapshot)
+{
+  int x, y;
+
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+  g_return_if_fail (GTK_IS_WIDGET (child));
+  g_return_if_fail (_gtk_widget_get_parent (child) == widget);
+  g_return_if_fail (snapshot != NULL);
+
+  gtk_widget_get_translation_to_child (widget, child, &x, &y);
+
+  gtk_snapshot_translate_2d (snapshot, x, y);
+  gtk_widget_snapshot (child, snapshot);
+  gtk_snapshot_translate_2d (snapshot, -x, -y);
+}
diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h
index 2445e9d..999ab64 100644
--- a/gtk/gtkwidgetprivate.h
+++ b/gtk/gtkwidgetprivate.h
@@ -290,6 +290,10 @@ void              gtk_widget_render                        (GtkWidget
 
 void              gtk_widget_snapshot                      (GtkWidget            *widget,
                                                             GtkSnapshot          *snapshot);
+void              gtk_widget_snapshot_child                (GtkWidget            *widget,
+                                                            GtkWidget            *child,
+                                                            GtkSnapshot          *snapshot);
+
 
 /* inline getters */
 


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