[gtk/matthiasc/for-master: 6/8] pick: Take advantage of transform categories



commit 37cd3cf15ba667bcbf5ebf8c5941e5f492f9e6f1
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Jan 19 01:12:19 2020 -0500

    pick: Take advantage of transform categories
    
    Transform categories let us easily avoid doing matrix math
    when we can just do a simple translation.

 gtk/gtkwidget.c | 34 +++++++++++++++++++++++-----------
 1 file changed, 23 insertions(+), 11 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index f0499dc61e..7a36eecde5 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -10507,9 +10507,8 @@ gtk_widget_do_pick (GtkWidget    *widget,
     {
       GtkWidgetPrivate *child_priv = gtk_widget_get_instance_private (child);
       GskTransform *transform;
-      graphene_matrix_t inv;
       GtkWidget *picked;
-      graphene_point3d_t p0, p1, res;
+      graphene_point3d_t res;
 
       if (!gtk_widget_can_be_picked (child, flags))
         continue;
@@ -10527,16 +10526,29 @@ gtk_widget_do_pick (GtkWidget    *widget,
         {
           transform = NULL;
         }
-      gsk_transform_to_matrix (transform, &inv);
-      gsk_transform_unref (transform);
-      graphene_point3d_init (&p0, x, y, 0);
-      graphene_point3d_init (&p1, x, y, 1);
-      graphene_matrix_transform_point3d (&inv, &p0, &p0);
-      graphene_matrix_transform_point3d (&inv, &p1, &p1);
-      if (fabs (p0.z - p1.z) < 1.f / 4096)
-        continue;
+      if (gsk_transform_get_category (transform) >= GSK_TRANSFORM_CATEGORY_2D_TRANSLATE)
+        {
+          float dx, dy;
 
-      graphene_point3d_interpolate (&p0, &p1, p0.z / (p0.z - p1.z), &res);
+          gsk_transform_to_translate (transform, &dx, &dy);
+          graphene_point3d_init (&res, x + dx, y + dy, 0.);
+        }
+      else
+        {
+          graphene_matrix_t inv;
+          graphene_point3d_t p0, p1;
+
+          gsk_transform_to_matrix (transform, &inv);
+          gsk_transform_unref (transform);
+          graphene_point3d_init (&p0, x, y, 0);
+          graphene_point3d_init (&p1, x, y, 1);
+          graphene_matrix_transform_point3d (&inv, &p0, &p0);
+          graphene_matrix_transform_point3d (&inv, &p1, &p1);
+          if (fabs (p0.z - p1.z) < 1.f / 4096)
+            continue;
+
+          graphene_point3d_interpolate (&p0, &p1, p0.z / (p0.z - p1.z), &res);
+        }
 
       picked = gtk_widget_do_pick (child, res.x, res.y, flags);
       if (picked)


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