[gtk/wip/baedert/transforms6: 22/52] widget: Consider widget transformations in translate_coordinatesf



commit edd8183a2cfe691dc185032de19ad49992ded741
Author: Timm Bäder <mail baedert org>
Date:   Sat Aug 11 22:14:33 2018 +0200

    widget: Consider widget transformations in translate_coordinatesf

 gtk/gtkwidget.c | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 36b959f8be..97a00280b8 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -4475,7 +4475,7 @@ gtk_widget_translate_coordinatesf (GtkWidget  *src_widget,
   int dest_depth;
   GtkWidget **dest_path;
   int i;
-  graphene_point_t src_point;
+  graphene_vec4_t src_point;
 
   g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
   g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
@@ -4508,22 +4508,19 @@ gtk_widget_translate_coordinatesf (GtkWidget  *src_widget,
       i ++;
     }
 
-  src_point.x = src_x;
-  src_point.y = src_y;
+  graphene_vec4_init (&src_point, src_x, src_y, 0, 1);
 
   parent = src_widget;
   while (parent != ancestor)
     {
-      graphene_matrix_t inv_transform;
+      graphene_vec4_t offset;
       int origin_x, origin_y;
 
       gtk_widget_get_origin_relative_to_parent (parent, &origin_x, &origin_y);
 
-      src_point.x += origin_x;
-      src_point.y += origin_y;
-
-      g_assert (graphene_matrix_inverse (&parent->priv->transform, &inv_transform));
-      graphene_matrix_transform_point (&inv_transform, &src_point, &src_point);
+      graphene_matrix_transform_vec4 (&parent->priv->transform, &src_point, &src_point);
+      graphene_vec4_init (&offset, origin_x, origin_y, 0, 0);
+      graphene_vec4_add (&src_point, &offset, &src_point);
 
       parent = _gtk_widget_get_parent (parent);
     }
@@ -4533,20 +4530,26 @@ gtk_widget_translate_coordinatesf (GtkWidget  *src_widget,
   for (i = 0; i < dest_depth; i ++)
     {
       int origin_x, origin_y;
+      graphene_vec4_t offset;
+      graphene_matrix_t inv_transform;
 
       parent = dest_path[i];
 
       gtk_widget_get_origin_relative_to_parent (parent, &origin_x, &origin_y);
 
-      src_point.x -= origin_x;
-      src_point.y -= origin_y;
+      graphene_vec4_init (&offset, -origin_x, -origin_y, 0, 0);
+      graphene_vec4_add (&src_point, &offset, &src_point);
+
+      /* TODO: inversion can fail */
+      graphene_matrix_inverse (&parent->priv->transform, &inv_transform);
+      graphene_matrix_transform_vec4 (&inv_transform, &src_point, &src_point);
     }
 
   if (dest_x)
-    *dest_x = src_point.x;
+    *dest_x = graphene_vec4_get_x (&src_point);
 
   if (dest_y)
-    *dest_y = src_point.y;
+    *dest_y = graphene_vec4_get_y (&src_point);
 
   return TRUE;
 }


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