2009-01-08 08:18:00 -05:00
|
|
|
/*
|
|
|
|
* Clutter.
|
|
|
|
*
|
|
|
|
* An OpenGL based 'interactive canvas' library.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Intel Corporation.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Author:
|
|
|
|
* Emmanuele Bassi <ebassi@linux.intel.com>
|
|
|
|
*/
|
|
|
|
|
2009-01-08 07:56:46 -05:00
|
|
|
/**
|
2022-05-25 12:41:48 -04:00
|
|
|
* ClutterAnimatable:
|
|
|
|
*
|
|
|
|
* Interface for animatable classes
|
2009-01-08 07:56:46 -05:00
|
|
|
*
|
2022-05-25 12:41:48 -04:00
|
|
|
* #ClutterAnimatable is an interface that allows a [class@GObject.Object] class
|
2020-04-09 11:54:45 -04:00
|
|
|
* to control how an actor will animate a property.
|
2009-01-08 07:56:46 -05:00
|
|
|
*
|
2011-09-12 08:12:14 -04:00
|
|
|
* Each #ClutterAnimatable should implement the
|
2022-05-25 12:41:48 -04:00
|
|
|
* [vfunc@Animatable.interpolate_value] virtual function of the
|
2012-04-19 11:00:23 -04:00
|
|
|
* interface to compute the animation state between two values of an interval
|
|
|
|
* depending on a progress factor, expressed as a floating point value.
|
2009-01-08 07:56:46 -05:00
|
|
|
*/
|
|
|
|
|
2023-11-07 05:56:00 -05:00
|
|
|
#include "config.h"
|
2009-01-08 07:56:46 -05:00
|
|
|
|
2023-08-07 09:38:12 -04:00
|
|
|
#include "clutter/clutter-animatable.h"
|
|
|
|
#include "clutter/clutter-interval.h"
|
|
|
|
#include "clutter/clutter-debug.h"
|
|
|
|
#include "clutter/clutter-private.h"
|
2015-01-03 15:34:20 -05:00
|
|
|
|
2010-10-08 09:47:46 -04:00
|
|
|
G_DEFINE_INTERFACE (ClutterAnimatable, clutter_animatable, G_TYPE_OBJECT);
|
2009-01-08 07:56:46 -05:00
|
|
|
|
2010-10-08 09:47:46 -04:00
|
|
|
static void
|
|
|
|
clutter_animatable_default_init (ClutterAnimatableInterface *iface)
|
|
|
|
{
|
2009-01-08 07:56:46 -05:00
|
|
|
}
|
|
|
|
|
2010-05-19 11:10:05 -04:00
|
|
|
/**
|
|
|
|
* clutter_animatable_find_property:
|
|
|
|
* @animatable: a #ClutterAnimatable
|
|
|
|
* @property_name: the name of the animatable property to find
|
|
|
|
*
|
2022-05-25 12:41:48 -04:00
|
|
|
* Finds the [class@GObject.ParamSpec] for @property_name
|
2010-05-19 11:10:05 -04:00
|
|
|
*
|
|
|
|
* Return value: (transfer none): The #GParamSpec for the given property
|
|
|
|
* or %NULL
|
|
|
|
*/
|
2010-05-19 07:21:54 -04:00
|
|
|
GParamSpec *
|
|
|
|
clutter_animatable_find_property (ClutterAnimatable *animatable,
|
|
|
|
const gchar *property_name)
|
|
|
|
{
|
2019-01-10 10:42:08 -05:00
|
|
|
ClutterAnimatableInterface *iface;
|
2010-05-19 07:21:54 -04:00
|
|
|
|
|
|
|
g_return_val_if_fail (CLUTTER_IS_ANIMATABLE (animatable), NULL);
|
|
|
|
g_return_val_if_fail (property_name != NULL, NULL);
|
|
|
|
|
|
|
|
CLUTTER_NOTE (ANIMATION, "Looking for property '%s'", property_name);
|
|
|
|
|
|
|
|
iface = CLUTTER_ANIMATABLE_GET_IFACE (animatable);
|
|
|
|
if (iface->find_property != NULL)
|
2010-07-31 05:40:21 -04:00
|
|
|
return iface->find_property (animatable, property_name);
|
2010-05-19 07:21:54 -04:00
|
|
|
|
|
|
|
return g_object_class_find_property (G_OBJECT_GET_CLASS (animatable),
|
|
|
|
property_name);
|
|
|
|
}
|
|
|
|
|
2010-05-19 11:10:05 -04:00
|
|
|
/**
|
|
|
|
* clutter_animatable_get_initial_state:
|
|
|
|
* @animatable: a #ClutterAnimatable
|
|
|
|
* @property_name: the name of the animatable property to retrieve
|
|
|
|
* @value: a #GValue initialized to the type of the property to retrieve
|
|
|
|
*
|
|
|
|
* Retrieves the current state of @property_name and sets @value with it
|
|
|
|
*/
|
2010-05-19 07:21:54 -04:00
|
|
|
void
|
|
|
|
clutter_animatable_get_initial_state (ClutterAnimatable *animatable,
|
|
|
|
const gchar *property_name,
|
|
|
|
GValue *value)
|
|
|
|
{
|
2019-01-10 10:42:08 -05:00
|
|
|
ClutterAnimatableInterface *iface;
|
2010-05-19 07:21:54 -04:00
|
|
|
|
|
|
|
g_return_if_fail (CLUTTER_IS_ANIMATABLE (animatable));
|
|
|
|
g_return_if_fail (property_name != NULL);
|
|
|
|
|
|
|
|
CLUTTER_NOTE (ANIMATION, "Getting initial state of '%s'", property_name);
|
|
|
|
|
|
|
|
iface = CLUTTER_ANIMATABLE_GET_IFACE (animatable);
|
|
|
|
if (iface->get_initial_state != NULL)
|
2010-07-31 05:40:21 -04:00
|
|
|
iface->get_initial_state (animatable, property_name, value);
|
2010-05-19 07:21:54 -04:00
|
|
|
else
|
|
|
|
g_object_get_property (G_OBJECT (animatable), property_name, value);
|
|
|
|
}
|
|
|
|
|
2010-05-19 11:10:05 -04:00
|
|
|
/**
|
|
|
|
* clutter_animatable_set_final_state:
|
|
|
|
* @animatable: a #ClutterAnimatable
|
|
|
|
* @property_name: the name of the animatable property to set
|
|
|
|
* @value: the value of the animatable property to set
|
|
|
|
*
|
|
|
|
* Sets the current state of @property_name to @value
|
|
|
|
*/
|
2010-05-19 07:21:54 -04:00
|
|
|
void
|
|
|
|
clutter_animatable_set_final_state (ClutterAnimatable *animatable,
|
|
|
|
const gchar *property_name,
|
|
|
|
const GValue *value)
|
|
|
|
{
|
2019-01-10 10:42:08 -05:00
|
|
|
ClutterAnimatableInterface *iface;
|
2010-05-19 07:21:54 -04:00
|
|
|
|
|
|
|
g_return_if_fail (CLUTTER_IS_ANIMATABLE (animatable));
|
|
|
|
g_return_if_fail (property_name != NULL);
|
|
|
|
|
|
|
|
CLUTTER_NOTE (ANIMATION, "Setting state of property '%s'", property_name);
|
|
|
|
|
|
|
|
iface = CLUTTER_ANIMATABLE_GET_IFACE (animatable);
|
|
|
|
if (iface->set_final_state != NULL)
|
2010-07-31 05:40:21 -04:00
|
|
|
iface->set_final_state (animatable, property_name, value);
|
2010-05-19 07:21:54 -04:00
|
|
|
else
|
|
|
|
g_object_set_property (G_OBJECT (animatable), property_name, value);
|
|
|
|
}
|
2011-07-15 09:27:26 -04:00
|
|
|
|
2011-07-29 06:48:13 -04:00
|
|
|
/**
|
|
|
|
* clutter_animatable_interpolate_value:
|
|
|
|
* @animatable: a #ClutterAnimatable
|
|
|
|
* @property_name: the name of the property to interpolate
|
|
|
|
* @interval: a #ClutterInterval with the animation range
|
|
|
|
* @progress: the progress to use to interpolate between the
|
|
|
|
* initial and final values of the @interval
|
|
|
|
* @value: (out): return location for an initialized #GValue
|
|
|
|
* using the same type of the @interval
|
|
|
|
*
|
|
|
|
* Asks a #ClutterAnimatable implementation to interpolate a
|
|
|
|
* a named property between the initial and final values of
|
|
|
|
* a #ClutterInterval, using @progress as the interpolation
|
|
|
|
* value, and store the result inside @value.
|
|
|
|
*
|
|
|
|
* This function should be used for every property animation
|
2022-05-25 12:41:48 -04:00
|
|
|
* involving `ClutterAnimatable`s.
|
2011-07-29 06:48:13 -04:00
|
|
|
*
|
|
|
|
* Return value: %TRUE if the interpolation was successful,
|
|
|
|
* and %FALSE otherwise
|
|
|
|
*/
|
2011-07-15 09:27:26 -04:00
|
|
|
gboolean
|
|
|
|
clutter_animatable_interpolate_value (ClutterAnimatable *animatable,
|
|
|
|
const gchar *property_name,
|
|
|
|
ClutterInterval *interval,
|
|
|
|
gdouble progress,
|
|
|
|
GValue *value)
|
|
|
|
{
|
2019-01-10 10:42:08 -05:00
|
|
|
ClutterAnimatableInterface *iface;
|
2011-07-15 09:27:26 -04:00
|
|
|
|
|
|
|
g_return_val_if_fail (CLUTTER_IS_ANIMATABLE (animatable), FALSE);
|
|
|
|
g_return_val_if_fail (property_name != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (CLUTTER_IS_INTERVAL (interval), FALSE);
|
|
|
|
g_return_val_if_fail (value != NULL, FALSE);
|
|
|
|
|
|
|
|
CLUTTER_NOTE (ANIMATION, "Interpolating '%s' (progress: %.3f)",
|
|
|
|
property_name,
|
|
|
|
progress);
|
|
|
|
|
|
|
|
iface = CLUTTER_ANIMATABLE_GET_IFACE (animatable);
|
|
|
|
if (iface->interpolate_value != NULL)
|
|
|
|
{
|
|
|
|
return iface->interpolate_value (animatable, property_name,
|
|
|
|
interval,
|
|
|
|
progress,
|
|
|
|
value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return clutter_interval_compute_value (interval, progress, value);
|
|
|
|
}
|
2020-06-23 14:23:37 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_animatable_get_actor:
|
|
|
|
* @animatable: a #ClutterAnimatable
|
|
|
|
*
|
|
|
|
* Get animated actor.
|
|
|
|
*
|
|
|
|
* Return value: (transfer none): a #ClutterActor
|
|
|
|
*/
|
|
|
|
ClutterActor *
|
|
|
|
clutter_animatable_get_actor (ClutterAnimatable *animatable)
|
|
|
|
{
|
|
|
|
ClutterAnimatableInterface *iface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (CLUTTER_IS_ANIMATABLE (animatable), NULL);
|
|
|
|
|
|
|
|
iface = CLUTTER_ANIMATABLE_GET_IFACE (animatable);
|
|
|
|
|
|
|
|
g_return_val_if_fail (iface->get_actor, NULL);
|
|
|
|
|
|
|
|
return iface->get_actor (animatable);
|
|
|
|
}
|