4 * An OpenGL based 'interactive canvas' library.
6 * Copyright (C) 2012 Intel Corporation
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
23 * SECTION:clutter-property-transition
24 * @Title: ClutterPropertyTransition
25 * @Short_Description: Property transitions
27 * #ClutterPropertyTransition is a specialized #ClutterTransition that
28 * can be used to tween a property of a #ClutterAnimatable instance.
30 * #ClutterPropertyTransition is available since Clutter 1.10
37 #include "clutter-property-transition.h"
39 #include "clutter-animatable.h"
40 #include "clutter-debug.h"
41 #include "clutter-interval.h"
42 #include "clutter-private.h"
43 #include "clutter-transition.h"
45 struct _ClutterPropertyTransitionPrivate
61 static GParamSpec *obj_props[PROP_LAST] = { NULL, };
63 G_DEFINE_TYPE (ClutterPropertyTransition, clutter_property_transition, CLUTTER_TYPE_TRANSITION)
66 clutter_property_transition_attached (ClutterTransition *transition,
67 ClutterAnimatable *animatable)
69 ClutterPropertyTransition *self = CLUTTER_PROPERTY_TRANSITION (transition);
70 ClutterPropertyTransitionPrivate *priv = self->priv;
72 if (priv->property_name == NULL)
75 priv->pspec = clutter_animatable_find_property (animatable,
80 clutter_property_transition_detached (ClutterTransition *transition,
81 ClutterAnimatable *animatable)
83 ClutterPropertyTransition *self = CLUTTER_PROPERTY_TRANSITION (transition);
84 ClutterPropertyTransitionPrivate *priv = self->priv;
90 clutter_property_transition_compute_value (ClutterTransition *transition,
91 ClutterAnimatable *animatable,
92 ClutterInterval *interval,
95 ClutterPropertyTransition *self = CLUTTER_PROPERTY_TRANSITION (transition);
96 ClutterPropertyTransitionPrivate *priv = self->priv;
97 GValue value = G_VALUE_INIT;
100 /* if we have a GParamSpec we also have an animatable instance */
101 if (priv->pspec == NULL)
104 g_value_init (&value, clutter_interval_get_value_type (interval));
106 res = clutter_animatable_interpolate_value (animatable,
113 clutter_animatable_set_final_state (animatable,
117 g_value_unset (&value);
121 clutter_property_transition_set_property (GObject *gobject,
126 ClutterPropertyTransition *self = CLUTTER_PROPERTY_TRANSITION (gobject);
130 case PROP_PROPERTY_NAME:
131 clutter_property_transition_set_property_name (self,
132 g_value_get_string (value));
136 G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
141 clutter_property_transition_get_property (GObject *gobject,
146 ClutterPropertyTransitionPrivate *priv = CLUTTER_PROPERTY_TRANSITION (gobject)->priv;
150 case PROP_PROPERTY_NAME:
151 g_value_set_string (value, priv->property_name);
155 G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
160 clutter_property_transition_finalize (GObject *gobject)
162 ClutterPropertyTransitionPrivate *priv;
164 priv = CLUTTER_PROPERTY_TRANSITION (gobject)->priv;
166 g_free (priv->property_name);
168 G_OBJECT_CLASS (clutter_property_transition_parent_class)->finalize (gobject);
172 clutter_property_transition_class_init (ClutterPropertyTransitionClass *klass)
174 ClutterTransitionClass *transition_class = CLUTTER_TRANSITION_CLASS (klass);
175 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
177 g_type_class_add_private (klass, sizeof (ClutterPropertyTransitionPrivate));
179 transition_class->attached = clutter_property_transition_attached;
180 transition_class->detached = clutter_property_transition_detached;
181 transition_class->compute_value = clutter_property_transition_compute_value;
183 gobject_class->set_property = clutter_property_transition_set_property;
184 gobject_class->get_property = clutter_property_transition_get_property;
185 gobject_class->finalize = clutter_property_transition_finalize;
188 * ClutterPropertyTransition:property-name:
190 * The name of the property of a #ClutterAnimatable to animate.
194 obj_props[PROP_PROPERTY_NAME] =
195 g_param_spec_string ("property-name",
197 P_("The name of the property to animate"),
199 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
201 g_object_class_install_properties (gobject_class, PROP_LAST, obj_props);
205 clutter_property_transition_init (ClutterPropertyTransition *self)
208 G_TYPE_INSTANCE_GET_PRIVATE (self, CLUTTER_TYPE_PROPERTY_TRANSITION,
209 ClutterPropertyTransitionPrivate);
213 * clutter_property_transition_new:
214 * @property_name: (allow-none): a property of @animatable, or %NULL
216 * Creates a new #ClutterPropertyTransition.
218 * Return value: (transfer full): the newly created #ClutterPropertyTransition.
219 * Use g_object_unref() when done
224 clutter_property_transition_new (const char *property_name)
226 return g_object_new (CLUTTER_TYPE_PROPERTY_TRANSITION,
227 "property-name", property_name,
232 * clutter_property_transition_set_property_name:
233 * @transition: a #ClutterPropertyTransition
234 * @property_name: (allow-none): a property name
236 * Sets the #ClutterPropertyTransition:property-name property of @transition.
241 clutter_property_transition_set_property_name (ClutterPropertyTransition *transition,
242 const char *property_name)
244 ClutterPropertyTransitionPrivate *priv;
245 ClutterAnimatable *animatable;
247 g_return_if_fail (CLUTTER_IS_PROPERTY_TRANSITION (transition));
249 priv = transition->priv;
251 if (g_strcmp0 (priv->property_name, property_name) == 0)
254 g_free (priv->property_name);
255 priv->property_name = g_strdup (property_name);
259 clutter_transition_get_animatable (CLUTTER_TRANSITION (transition));
260 if (animatable != NULL)
262 priv->pspec = clutter_animatable_find_property (animatable,
263 priv->property_name);
266 g_object_notify_by_pspec (G_OBJECT (transition),
267 obj_props[PROP_PROPERTY_NAME]);
271 * clutter_property_transition_get_property_name:
272 * @transition: a #ClutterPropertyTransition
274 * Retrieves the value of the #ClutterPropertyTransition:property-name
277 * Return value: the name of the property being animated, or %NULL if
278 * none is set. The returned string is owned by the @transition and
279 * it should not be freed.
284 clutter_property_transition_get_property_name (ClutterPropertyTransition *transition)
286 g_return_val_if_fail (CLUTTER_IS_PROPERTY_TRANSITION (transition), NULL);
288 return transition->priv->property_name;