property-transition: Verify the interval on compute_value()

By checking if the interval is valid inside compute_value() we can catch
the cases where the interval values of a PropertyTransition are set
after the transition has been added to an Animatable instance - i.e. the
following code:

  let transition = new Clutter.PropertyTransition();
  transition.set_property_name('opacity');
  actor.add_transition('opacityAnim', transition);
  transition.set_to_value(0);

should be equivalent to:

  let transition = new Clutter.PropertyTransition();
  transition.set_property_name('opacity');
  transition.set_to_value(0);
  actor.add_transition('opacityAnim', transition);

instead of emitting a warning.
This commit is contained in:
Emmanuele Bassi 2012-06-08 17:33:30 +01:00
parent 762053cd28
commit b21cb29479

View File

@ -62,6 +62,38 @@ static GParamSpec *obj_props[PROP_LAST] = { NULL, };
G_DEFINE_TYPE (ClutterPropertyTransition, clutter_property_transition, CLUTTER_TYPE_TRANSITION) G_DEFINE_TYPE (ClutterPropertyTransition, clutter_property_transition, CLUTTER_TYPE_TRANSITION)
static inline void
clutter_property_transition_ensure_interval (ClutterPropertyTransition *transition,
ClutterAnimatable *animatable,
ClutterInterval *interval)
{
ClutterPropertyTransitionPrivate *priv = transition->priv;
GValue *value_p;
if (clutter_interval_is_valid (interval))
return;
/* if no initial value has been set, use the current value */
value_p = clutter_interval_peek_initial_value (interval);
if (!G_IS_VALUE (value_p))
{
g_value_init (value_p, clutter_interval_get_value_type (interval));
clutter_animatable_get_initial_state (animatable,
priv->property_name,
value_p);
}
/* if no final value has been set, use the current value */
value_p = clutter_interval_peek_final_value (interval);
if (!G_IS_VALUE (value_p))
{
g_value_init (value_p, clutter_interval_get_value_type (interval));
clutter_animatable_get_initial_state (animatable,
priv->property_name,
value_p);
}
}
static void static void
clutter_property_transition_attached (ClutterTransition *transition, clutter_property_transition_attached (ClutterTransition *transition,
ClutterAnimatable *animatable) ClutterAnimatable *animatable)
@ -69,7 +101,6 @@ clutter_property_transition_attached (ClutterTransition *transition,
ClutterPropertyTransition *self = CLUTTER_PROPERTY_TRANSITION (transition); ClutterPropertyTransition *self = CLUTTER_PROPERTY_TRANSITION (transition);
ClutterPropertyTransitionPrivate *priv = self->priv; ClutterPropertyTransitionPrivate *priv = self->priv;
ClutterInterval *interval; ClutterInterval *interval;
GValue *value;
if (priv->property_name == NULL) if (priv->property_name == NULL)
return; return;
@ -84,25 +115,7 @@ clutter_property_transition_attached (ClutterTransition *transition,
if (interval == NULL) if (interval == NULL)
return; return;
/* if no initial value has been set, use the current value */ clutter_property_transition_ensure_interval (self, animatable, interval);
value = clutter_interval_peek_initial_value (interval);
if (!G_IS_VALUE (value))
{
g_value_init (value, clutter_interval_get_value_type (interval));
clutter_animatable_get_initial_state (animatable,
priv->property_name,
value);
}
/* if no final value has been set, use the current value */
value = clutter_interval_peek_final_value (interval);
if (!G_IS_VALUE (value))
{
g_value_init (value, clutter_interval_get_value_type (interval));
clutter_animatable_get_initial_state (animatable,
priv->property_name,
value);
}
} }
static void static void
@ -130,6 +143,8 @@ clutter_property_transition_compute_value (ClutterTransition *transition,
if (priv->pspec == NULL) if (priv->pspec == NULL)
return; return;
clutter_property_transition_ensure_interval (self, animatable, interval);
g_value_init (&value, clutter_interval_get_value_type (interval)); g_value_init (&value, clutter_interval_get_value_type (interval));
res = clutter_animatable_interpolate_value (animatable, res = clutter_animatable_interpolate_value (animatable,