[gtk/wip/otte/boxes: 12/20] widget: Store the render node in the widget's coordinate system



commit b4d2d13f01923a682a5ab969e3f217e623b0ed21
Author: Benjamin Otte <otte redhat com>
Date:   Sun Feb 10 06:26:41 2019 +0100

    widget: Store the render node in the widget's coordinate system
    
    Also require gtk_widget_snapshot() to be in the widget's coordinate
    system.

 gtk/gtkwidget.c          | 18 +++++++++---------
 gtk/gtkwidgetpaintable.c | 10 ++++++----
 gtk/gtkwindow.c          | 13 +++++++++++--
 3 files changed, 26 insertions(+), 15 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 518a3b8c14..67e0e19fbd 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -13121,7 +13121,7 @@ gtk_widget_create_render_node (GtkWidget   *widget,
 
   if (!GTK_IS_WINDOW (widget))
     {
-      gtk_snapshot_offset (snapshot, margin.left, margin.top);
+      gtk_snapshot_offset (snapshot, - padding.left - border.left, - border.top - padding.top);
       gtk_css_style_snapshot_background (style,
                                          snapshot,
                                          allocation.width - margin.left - margin.right,
@@ -13130,12 +13130,9 @@ gtk_widget_create_render_node (GtkWidget   *widget,
                                      snapshot,
                                      allocation.width - margin.left - margin.right,
                                      allocation.height - margin.top - margin.bottom);
-      gtk_snapshot_offset (snapshot, - margin.left, - margin.top);
+      gtk_snapshot_offset (snapshot, padding.left + border.left, border.top + padding.top);
     }
 
-  /* Offset to content allocation */
-  gtk_snapshot_offset (snapshot, margin.left + padding.left + border.left, margin.top + border.top + 
padding.top);
-
   if (priv->overflow == GTK_OVERFLOW_HIDDEN)
     {
       gtk_snapshot_push_clip (snapshot,
@@ -13156,7 +13153,8 @@ gtk_widget_create_render_node (GtkWidget   *widget,
                                   snapshot,
                                   allocation.width - margin.left - margin.right,
                                   allocation.height - margin.top - margin.bottom);
-  gtk_snapshot_offset (snapshot, - margin.left, - margin.top);
+
+  gtk_snapshot_offset (snapshot, padding.left + border.left, border.top + padding.top);
 
   if (opacity < 1.0)
     gtk_snapshot_pop (snapshot);
@@ -13217,6 +13215,7 @@ gtk_widget_render (GtkWidget            *widget,
   GtkSnapshot *snapshot;
   GskRenderer *renderer;
   GskRenderNode *root;
+  int x, y;
 
   if (!GTK_IS_ROOT (widget))
     return;
@@ -13230,7 +13229,10 @@ gtk_widget_render (GtkWidget            *widget,
     return;
 
   snapshot = gtk_snapshot_new ();
+  gtk_root_get_surface_transform (GTK_ROOT (widget), &x, &y);
+  gtk_snapshot_offset (snapshot, x, y);
   gtk_widget_snapshot (widget, snapshot);
+  gtk_snapshot_offset (snapshot, -x, -y);
   root = gtk_snapshot_free_to_node (snapshot);
 
   if (root != NULL)
@@ -13542,14 +13544,12 @@ gtk_widget_snapshot_child (GtkWidget   *widget,
                            GtkWidget   *child,
                            GtkSnapshot *snapshot)
 {
-  GtkWidgetPrivate *priv = gtk_widget_get_instance_private (child);
   int x, y;
 
   g_return_if_fail (_gtk_widget_get_parent (child) == widget);
   g_return_if_fail (snapshot != NULL);
 
-  x = priv->transform.x;
-  y = priv->transform.y;
+  gtk_widget_get_origin_relative_to_parent (child, &x, &y);
 
   gtk_snapshot_offset (snapshot, x, y);
   gtk_widget_snapshot (child, snapshot);
diff --git a/gtk/gtkwidgetpaintable.c b/gtk/gtkwidgetpaintable.c
index 976b29d2c7..531b1332fc 100644
--- a/gtk/gtkwidgetpaintable.c
+++ b/gtk/gtkwidgetpaintable.c
@@ -92,13 +92,15 @@ gtk_widget_paintable_paintable_snapshot (GdkPaintable *paintable,
   else if (self->snapshot_count > 0)
     {
       graphene_matrix_t transform;
+      graphene_rect_t bounds;
 
       gtk_snapshot_push_clip (snapshot,
                               &GRAPHENE_RECT_INIT(0, 0, width, height));
-      graphene_matrix_init_scale (&transform,
-                                  width / gtk_widget_get_allocated_width (self->widget),
-                                  height / gtk_widget_get_allocated_height (self->widget),
-                                  1.0);
+      gtk_widget_compute_bounds (self->widget, self->widget, &bounds);
+      graphene_matrix_init_from_2d (&transform,
+                                    width / bounds.size.width, 0.0,
+                                    0.0, height / bounds.size.height,
+                                    bounds.origin.x, bounds.origin.y);
       gtk_snapshot_push_transform (snapshot, &transform);
 
       gtk_widget_snapshot (self->widget, snapshot);
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 5f98605f22..77bdc43472 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -2521,8 +2521,17 @@ gtk_window_root_get_surface_transform (GtkRoot *root,
                                        int     *x,
                                        int     *y)
 {
-  *x = 0;
-  *y = 0;
+  GtkWindow *self = GTK_WINDOW (root);
+  GtkStyleContext *context;
+  GtkBorder margin, border, padding;
+
+  context = gtk_widget_get_style_context (GTK_WIDGET (self));
+  gtk_style_context_get_margin (context, &margin);
+  gtk_style_context_get_border (context, &border);
+  gtk_style_context_get_padding (context, &padding);
+
+  *x = margin.left + border.left + padding.left;
+  *y = margin.top + border.top + padding.top;
 }
 
 static void


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