[gnome-shell] Add shell_util_get_transformed_allocation()



commit 905c4bb4a547994f9e537f58af10615f49739e25
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Sat Mar 26 16:34:25 2011 -0400

    Add shell_util_get_transformed_allocation()
    
    Add a function that gets the current allocation of an actor
    transformed into stage coordinates. This avoids a misfeature of
    clutter_actor_get_transformed_size() where when a size request is
    queued (even if it won't eventually change the size), the returned
    value is the transformed size request rather than the last allocation.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=645744

 src/shell-util.c |   55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/shell-util.h |    3 ++
 2 files changed, 58 insertions(+), 0 deletions(-)
---
diff --git a/src/shell-util.c b/src/shell-util.c
index d5aec13..0ff9d12 100644
--- a/src/shell-util.c
+++ b/src/shell-util.c
@@ -441,6 +441,61 @@ shell_util_set_hidden_from_pick (ClutterActor *actor,
 }
 
 /**
+ * shell_util_get_transformed_allocation:
+ * @actor: a #ClutterActor
+ * @box: (out): location to store returned box in stage coordinates
+ *
+ * This function is similar to a combination of clutter_actor_get_transformed_position(),
+ * and clutter_actor_get_transformed_size(), but unlike
+ * clutter_actor_get_transformed_size(), it always returns a transform
+ * of the current allocation, while clutter_actor_get_transformed_size() returns
+ * bad values (the transform of the requested size) if a relayout has been
+ * queued.
+ *
+ * This function is more convenient to use than
+ * clutter_actor_get_abs_allocation_vertices() if no transformation is in effect
+ * and also works around limitations in the GJS binding of arrays.
+ */
+void
+shell_util_get_transformed_allocation (ClutterActor    *actor,
+                                       ClutterActorBox *box)
+{
+  /* Code adapted from clutter-actor.c:
+   * Copyright 2006, 2007, 2008 OpenedHand Ltd
+   */
+  ClutterVertex v[4];
+  gfloat x_min, x_max, y_min, y_max;
+  gint i;
+
+  g_return_if_fail (CLUTTER_IS_ACTOR (actor));
+
+  clutter_actor_get_abs_allocation_vertices (actor, v);
+
+  x_min = x_max = v[0].x;
+  y_min = y_max = v[0].y;
+
+  for (i = 1; i < G_N_ELEMENTS (v); ++i)
+    {
+      if (v[i].x < x_min)
+	x_min = v[i].x;
+
+      if (v[i].x > x_max)
+	x_max = v[i].x;
+
+      if (v[i].y < y_min)
+	y_min = v[i].y;
+
+      if (v[i].y > y_max)
+	y_max = v[i].y;
+    }
+
+  box->x1 = x_min;
+  box->y1 = y_min;
+  box->x2 = x_max;
+  box->y2 = y_max;
+}
+
+/**
  * shell_util_format_date:
  * @format: a strftime-style string format, as parsed by
  *   g_date_time_format()
diff --git a/src/shell-util.h b/src/shell-util.h
index e4914c3..7da5476 100644
--- a/src/shell-util.h
+++ b/src/shell-util.h
@@ -13,6 +13,9 @@ GIcon *shell_util_get_icon_for_uri (const char *text_uri);
 GIcon *shell_util_icon_from_string (const char *string, GError **error);
 void   shell_util_set_hidden_from_pick (ClutterActor *actor, gboolean hidden);
 
+void shell_util_get_transformed_allocation (ClutterActor    *actor,
+                                            ClutterActorBox *box);
+
 char *shell_util_format_date (const char *format,
                               gint64      time_ms);
 



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