[mutter] clutter/actor-box: Allow marking boxes as uninitialized
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter] clutter/actor-box: Allow marking boxes as uninitialized
- Date: Wed, 10 Jun 2020 17:10:10 +0000 (UTC)
commit 0bfb995bffeb846cb574d1f6762b1440fad7272d
Author: Jonas Dreßler <verdre v0yd nl>
Date: Sat Jun 6 12:55:07 2020 +0200
clutter/actor-box: Allow marking boxes as uninitialized
Add support for an artificial UNINITIALIZED marking for ClutterActorBox,
done by setting the boxes origin to Infinity and its size to -Infinity.
That is a value that's considered an invalid allocation by Clutter and
which can never be set by sane code.
This will allow setting the allocation of ClutterActors to an
UNINITIALIZED box when creating actors or when removing them from the
scenegraph and makes it possible to explicitely detect uninitialized
allocations, which is useful in a few cases.
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1290
clutter/clutter/clutter-actor-box.c | 26 ++++++++++++++++++++++++++
clutter/clutter/clutter-types.h | 17 +++++++++++++++++
2 files changed, 43 insertions(+)
---
diff --git a/clutter/clutter/clutter-actor-box.c b/clutter/clutter/clutter-actor-box.c
index a2308ac314..9e30c62bd7 100644
--- a/clutter/clutter/clutter-actor-box.c
+++ b/clutter/clutter/clutter-actor-box.c
@@ -615,6 +615,32 @@ clutter_actor_box_scale (ClutterActorBox *box,
box->y2 *= scale;
}
+/**
+ * clutter_actor_box_is_initialized:
+ * @box: a #ClutterActorBox
+ *
+ * Checks if @box has been initialized, a #ClutterActorBox is uninitialized
+ * if it has a size of -1 at an origin of 0, 0.
+ *
+ * Returns: %TRUE if the box is uninitialized, %FALSE if it isn't
+ */
+gboolean
+clutter_actor_box_is_initialized (ClutterActorBox *box)
+{
+ gboolean x1_uninitialized, x2_uninitialized;
+ gboolean y1_uninitialized, y2_uninitialized;
+
+ g_return_val_if_fail (box != NULL, TRUE);
+
+ x1_uninitialized = isinf (box->x1);
+ x2_uninitialized = isinf (box->x2) && signbit (box->x2);
+ y1_uninitialized = isinf (box->y1);
+ y2_uninitialized = isinf (box->y2) && signbit (box->y2);
+
+ return !x1_uninitialized || !x2_uninitialized ||
+ !y1_uninitialized || !y2_uninitialized;
+}
+
G_DEFINE_BOXED_TYPE_WITH_CODE (ClutterActorBox, clutter_actor_box,
clutter_actor_box_copy,
clutter_actor_box_free,
diff --git a/clutter/clutter/clutter-types.h b/clutter/clutter/clutter-types.h
index 1b65573a3c..0c6400d93e 100644
--- a/clutter/clutter/clutter-types.h
+++ b/clutter/clutter/clutter-types.h
@@ -174,6 +174,20 @@ struct _ClutterActorBox
*/
#define CLUTTER_ACTOR_BOX_INIT_ZERO CLUTTER_ACTOR_BOX_INIT (0.f, 0.f, 0.f, 0.f)
+/**
+ * CLUTTER_ACTOR_BOX_UNINITIALIZED:
+ *
+ * A simple macro for creating a #ClutterActorBox with a size of -1 when
+ * declaring it, e.g.:
+ *
+ * |[
+ * ClutterActorBox box = CLUTTER_ACTOR_BOX_UNINITIALIZED;
+ * ]|
+ */
+
+
+#define CLUTTER_ACTOR_BOX_UNINITIALIZED { .x1 = INFINITY, .y1 = INFINITY, .x2 = -INFINITY, .y2 = -INFINITY }
+
CLUTTER_EXPORT
GType clutter_actor_box_get_type (void) G_GNUC_CONST;
CLUTTER_EXPORT
@@ -252,6 +266,9 @@ CLUTTER_EXPORT
void clutter_actor_box_scale (ClutterActorBox *box,
gfloat scale);
+CLUTTER_EXPORT
+gboolean clutter_actor_box_is_initialized (ClutterActorBox *box);
+
/**
* ClutterKnot:
* @x: X coordinate of the knot
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]