[mutter/gbsneto/animatable-content] clutter/actor: Allow animating content properties



commit 268336c21a62d5dd43154e2ce7f910a74a160626
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Tue Jun 9 15:06:53 2020 -0300

    clutter/actor: Allow animating content properties
    
    ClutterActor allows animating effects, constraints, actions,
    and the layout manager for property transitions. Extend this
    functionality to the content as well.
    
    https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1301

 clutter/clutter/clutter-actor.c | 62 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 61 insertions(+), 1 deletion(-)
---
diff --git a/clutter/clutter/clutter-actor.c b/clutter/clutter/clutter-actor.c
index fe02d3abdd..1195316f8c 100644
--- a/clutter/clutter/clutter-actor.c
+++ b/clutter/clutter/clutter-actor.c
@@ -446,7 +446,8 @@
  * ]|
  *
  *  - the initial `@` is mandatory
- *  - the `section` fragment can be one between "actions", "constraints" and "effects"
+ *  - the `section` fragment can be one between "actions", "constraints", "content",
+ *    and "effects"
  *  - the `meta-name` fragment is the name of the action, effect, or constraint, as
  *    specified by the #ClutterActorMeta:name property of #ClutterActorMeta
  *  - the `property-name` fragment is the name of the action, effect, or constraint
@@ -14622,6 +14623,37 @@ get_layout_from_animation_property (ClutterActor  *actor,
   return TRUE;
 }
 
+static gboolean
+get_content_from_animation_property (ClutterActor  *actor,
+                                     const gchar   *name,
+                                     gchar        **name_p)
+{
+  g_auto (GStrv) tokens = NULL;
+
+  if (!g_str_has_prefix (name, "@content"))
+    return FALSE;
+
+  if (!actor->priv->content)
+    {
+      CLUTTER_NOTE (ANIMATION, "No ClutterContent available for '%s'",
+                    name + 1);
+      return FALSE;
+    }
+
+  tokens = g_strsplit (name, ".", -1);
+  if (tokens == NULL || g_strv_length (tokens) != 2)
+    {
+      CLUTTER_NOTE (ANIMATION, "Invalid property name '%s'",
+                    name + 1);
+      return FALSE;
+    }
+
+  if (name_p != NULL)
+    *name_p = g_strdup (tokens[1]);
+
+  return TRUE;
+}
+
 static ClutterActorMeta *
 get_meta_from_animation_property (ClutterActor  *actor,
                                   const gchar   *name,
@@ -14689,6 +14721,7 @@ clutter_actor_find_property (ClutterAnimatable *animatable,
   GObjectClass *klass = NULL;
   GParamSpec *pspec = NULL;
   gchar *p_name = NULL;
+  gboolean use_content = FALSE;
   gboolean use_layout;
 
   use_layout = get_layout_from_animation_property (actor,
@@ -14696,6 +14729,11 @@ clutter_actor_find_property (ClutterAnimatable *animatable,
                                                    &p_name);
 
   if (!use_layout)
+    use_content = get_content_from_animation_property (actor,
+                                                       property_name,
+                                                       &p_name);
+
+  if (!use_layout && !use_content)
     meta = get_meta_from_animation_property (actor,
                                              property_name,
                                              &p_name);
@@ -14710,6 +14748,12 @@ clutter_actor_find_property (ClutterAnimatable *animatable,
     {
       klass = G_OBJECT_GET_CLASS (actor->priv->layout_manager);
 
+      pspec = g_object_class_find_property (klass, p_name);
+    }
+  else if (use_content)
+    {
+      klass = G_OBJECT_GET_CLASS (actor->priv->content);
+
       pspec = g_object_class_find_property (klass, p_name);
     }
   else
@@ -14732,6 +14776,7 @@ clutter_actor_get_initial_state (ClutterAnimatable *animatable,
   ClutterActor *actor = CLUTTER_ACTOR (animatable);
   ClutterActorMeta *meta = NULL;
   gchar *p_name = NULL;
+  gboolean use_content = FALSE;
   gboolean use_layout;
 
   use_layout = get_layout_from_animation_property (actor,
@@ -14739,6 +14784,11 @@ clutter_actor_get_initial_state (ClutterAnimatable *animatable,
                                                    &p_name);
 
   if (!use_layout)
+    use_content = get_content_from_animation_property (actor,
+                                                       property_name,
+                                                       &p_name);
+
+  if (!use_layout && !use_content)
     meta = get_meta_from_animation_property (actor,
                                              property_name,
                                              &p_name);
@@ -14747,6 +14797,8 @@ clutter_actor_get_initial_state (ClutterAnimatable *animatable,
     g_object_get_property (G_OBJECT (meta), p_name, initial);
   else if (use_layout)
     g_object_get_property (G_OBJECT (actor->priv->layout_manager), p_name, initial);
+  else if (use_content)
+    g_object_get_property (G_OBJECT (actor->priv->content), p_name, initial);
   else
     g_object_get_property (G_OBJECT (animatable), property_name, initial);
 
@@ -14897,6 +14949,7 @@ clutter_actor_set_final_state (ClutterAnimatable *animatable,
   ClutterActor *actor = CLUTTER_ACTOR (animatable);
   ClutterActorMeta *meta = NULL;
   gchar *p_name = NULL;
+  gboolean use_content = FALSE;
   gboolean use_layout;
 
   use_layout = get_layout_from_animation_property (actor,
@@ -14904,6 +14957,11 @@ clutter_actor_set_final_state (ClutterAnimatable *animatable,
                                                    &p_name);
 
   if (!use_layout)
+    use_content = get_content_from_animation_property (actor,
+                                                       property_name,
+                                                       &p_name);
+
+  if (!use_layout && !use_content)
     meta = get_meta_from_animation_property (actor,
                                              property_name,
                                              &p_name);
@@ -14912,6 +14970,8 @@ clutter_actor_set_final_state (ClutterAnimatable *animatable,
     g_object_set_property (G_OBJECT (meta), p_name, final);
   else if (use_layout)
     g_object_set_property (G_OBJECT (actor->priv->layout_manager), p_name, final);
+  else if (use_content)
+    g_object_set_property (G_OBJECT (actor->priv->content), p_name, final);
   else
     {
       GObjectClass *obj_class = G_OBJECT_GET_CLASS (animatable);


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