2006-11-15 18:37:53 -05:00
|
|
|
/*
|
|
|
|
* Clutter.
|
|
|
|
*
|
|
|
|
* An OpenGL based 'interactive canvas' library.
|
|
|
|
*
|
2010-03-01 07:56:10 -05:00
|
|
|
* Authored By:
|
|
|
|
* Matthew Allum <mallum@openedhand.com>
|
|
|
|
* Neil Roberts <neil@linux.intel.com>
|
2006-11-15 18:37:53 -05:00
|
|
|
*
|
2010-03-01 07:56:10 -05:00
|
|
|
* Copyright (C) 2006, 2007, 2008 OpenedHand Ltd
|
|
|
|
* Copyright (C) 2009, 2010 Intel Corp
|
2006-11-15 18:37:53 -05:00
|
|
|
*
|
|
|
|
* 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
|
2010-03-01 07:56:10 -05:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2006-11-15 18:37:53 -05:00
|
|
|
*/
|
|
|
|
|
2006-11-17 13:24:28 -05:00
|
|
|
/**
|
|
|
|
* SECTION:clutter-behaviour-path
|
2008-12-05 08:13:37 -05:00
|
|
|
* @short_description: A behaviour for moving actors along a #ClutterPath
|
2006-11-17 13:24:28 -05:00
|
|
|
*
|
2006-11-17 14:17:40 -05:00
|
|
|
* #ClutterBehaviourPath interpolates actors along a defined path.
|
2006-11-17 13:24:28 -05:00
|
|
|
*
|
2008-12-05 08:13:37 -05:00
|
|
|
* A path is described by a #ClutterPath object. The path can contain
|
|
|
|
* straight line parts and bezier curves. If the path contains
|
|
|
|
* %CLUTTER_PATH_MOVE_TO parts then the actors will jump to those
|
|
|
|
* coordinates. This can be used make disjoint paths.
|
2006-11-17 14:17:40 -05:00
|
|
|
*
|
2008-12-05 08:13:37 -05:00
|
|
|
* When creating a path behaviour in a #ClutterScript, you can specify
|
|
|
|
* the path property directly as a string. For example:
|
|
|
|
*
|
|
|
|
* |[
|
|
|
|
* {
|
|
|
|
* "id" : "spline-path",
|
|
|
|
* "type" : "ClutterBehaviourPath",
|
|
|
|
* "path" : "M 50 50 L 100 100",
|
|
|
|
* "alpha" : {
|
|
|
|
* "timeline" : "main-timeline",
|
|
|
|
* "function" : "ramp
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* ]|
|
2007-12-17 10:56:35 -05:00
|
|
|
*
|
2008-02-08 09:34:58 -05:00
|
|
|
* <note>If the alpha function is a periodic function, i.e. it returns to
|
2010-08-17 09:54:20 -04:00
|
|
|
* 0.0 after reaching 1.0, then the actors will walk the path back to the
|
|
|
|
* starting #ClutterKnot.</note>
|
2008-02-08 09:34:58 -05:00
|
|
|
*
|
2007-12-17 10:56:35 -05:00
|
|
|
* #ClutterBehaviourPath is available since Clutter 0.2
|
2006-11-17 13:24:28 -05:00
|
|
|
*/
|
|
|
|
|
2006-11-15 18:37:53 -05:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "clutter-actor.h"
|
|
|
|
#include "clutter-behaviour.h"
|
2007-10-25 10:42:15 -04:00
|
|
|
#include "clutter-behaviour-path.h"
|
2008-12-05 08:13:37 -05:00
|
|
|
#include "clutter-bezier.h"
|
2007-10-25 10:42:15 -04:00
|
|
|
#include "clutter-debug.h"
|
2006-11-15 18:37:53 -05:00
|
|
|
#include "clutter-enum-types.h"
|
|
|
|
#include "clutter-main.h"
|
2007-10-25 10:42:15 -04:00
|
|
|
#include "clutter-marshal.h"
|
2006-12-04 11:26:35 -05:00
|
|
|
#include "clutter-private.h"
|
2007-10-25 10:42:15 -04:00
|
|
|
#include "clutter-script-private.h"
|
2008-12-05 08:13:37 -05:00
|
|
|
#include "clutter-scriptable.h"
|
2006-11-15 18:37:53 -05:00
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
2007-10-25 10:42:15 -04:00
|
|
|
static void clutter_scriptable_iface_init (ClutterScriptableIface *iface);
|
|
|
|
|
2007-11-06 10:46:23 -05:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (ClutterBehaviourPath,
|
2007-10-25 10:42:15 -04:00
|
|
|
clutter_behaviour_path,
|
2008-12-05 08:13:37 -05:00
|
|
|
CLUTTER_TYPE_BEHAVIOUR,
|
2007-10-25 10:42:15 -04:00
|
|
|
G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_SCRIPTABLE,
|
|
|
|
clutter_scriptable_iface_init));
|
2006-11-15 18:37:53 -05:00
|
|
|
|
|
|
|
struct _ClutterBehaviourPathPrivate
|
|
|
|
{
|
2008-12-05 08:13:37 -05:00
|
|
|
ClutterPath *path;
|
|
|
|
guint last_knot_passed;
|
2006-11-15 18:37:53 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#define CLUTTER_BEHAVIOUR_PATH_GET_PRIVATE(obj) \
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
|
|
|
|
CLUTTER_TYPE_BEHAVIOUR_PATH, \
|
|
|
|
ClutterBehaviourPathPrivate))
|
|
|
|
|
2006-11-17 13:45:31 -05:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
KNOT_REACHED,
|
|
|
|
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint path_signals[LAST_SIGNAL] = { 0, };
|
|
|
|
|
2006-11-17 14:17:40 -05:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
|
2010-06-21 05:20:32 -04:00
|
|
|
PROP_PATH,
|
|
|
|
|
|
|
|
PROP_LAST
|
2006-11-17 14:17:40 -05:00
|
|
|
};
|
|
|
|
|
2010-06-21 05:20:32 -04:00
|
|
|
static GParamSpec *obj_props[PROP_LAST];
|
|
|
|
|
2006-11-15 18:37:53 -05:00
|
|
|
static void
|
2006-12-08 11:12:52 -05:00
|
|
|
actor_apply_knot_foreach (ClutterBehaviour *behaviour,
|
|
|
|
ClutterActor *actor,
|
|
|
|
gpointer data)
|
2006-11-15 18:37:53 -05:00
|
|
|
{
|
2006-12-08 11:12:52 -05:00
|
|
|
ClutterKnot *knot = data;
|
|
|
|
|
2007-05-14 05:11:23 -04:00
|
|
|
CLUTTER_NOTE (BEHAVIOUR, "Setting actor to %ix%i", knot->x, knot->y);
|
|
|
|
|
2006-11-15 18:37:53 -05:00
|
|
|
clutter_actor_set_position (actor, knot->x, knot->y);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-12-05 08:13:37 -05:00
|
|
|
clutter_behaviour_path_alpha_notify (ClutterBehaviour *behave,
|
2009-01-20 11:42:49 -05:00
|
|
|
gdouble alpha_value)
|
2006-11-15 18:37:53 -05:00
|
|
|
{
|
2008-12-05 08:13:37 -05:00
|
|
|
ClutterBehaviourPath *pathb = CLUTTER_BEHAVIOUR_PATH (behave);
|
|
|
|
ClutterBehaviourPathPrivate *priv = pathb->priv;
|
|
|
|
ClutterKnot position;
|
|
|
|
guint knot_num;
|
2007-11-06 10:46:23 -05:00
|
|
|
|
2008-12-05 08:13:37 -05:00
|
|
|
if (priv->path)
|
2009-01-20 11:42:49 -05:00
|
|
|
knot_num = clutter_path_get_position (priv->path, alpha_value, &position);
|
2008-12-05 08:13:37 -05:00
|
|
|
else
|
2007-05-14 05:11:23 -04:00
|
|
|
{
|
2008-12-05 08:13:37 -05:00
|
|
|
memset (&position, 0, sizeof (position));
|
|
|
|
knot_num = 0;
|
2007-05-14 05:11:23 -04:00
|
|
|
}
|
2006-11-15 18:37:53 -05:00
|
|
|
|
2008-12-05 08:13:37 -05:00
|
|
|
clutter_behaviour_actors_foreach (behave,
|
|
|
|
actor_apply_knot_foreach,
|
|
|
|
&position);
|
2006-11-15 18:37:53 -05:00
|
|
|
|
2008-12-05 08:13:37 -05:00
|
|
|
if (knot_num != priv->last_knot_passed)
|
|
|
|
{
|
|
|
|
g_signal_emit (behave, path_signals[KNOT_REACHED], 0, knot_num);
|
|
|
|
priv->last_knot_passed = knot_num;
|
2006-11-15 18:37:53 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-12-05 08:13:37 -05:00
|
|
|
clutter_behaviour_path_get_property (GObject *gobject,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2006-11-15 18:37:53 -05:00
|
|
|
{
|
2008-12-05 08:13:37 -05:00
|
|
|
ClutterBehaviourPath *pathb = CLUTTER_BEHAVIOUR_PATH (gobject);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_PATH:
|
|
|
|
g_value_set_object (value, clutter_behaviour_path_get_path (pathb));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2006-11-15 18:37:53 -05:00
|
|
|
}
|
|
|
|
|
2006-11-17 14:17:40 -05:00
|
|
|
static void
|
|
|
|
clutter_behaviour_path_set_property (GObject *gobject,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
ClutterBehaviourPath *pathb = CLUTTER_BEHAVIOUR_PATH (gobject);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2008-12-05 08:13:37 -05:00
|
|
|
case PROP_PATH:
|
|
|
|
clutter_behaviour_path_set_path (pathb, g_value_get_object (value));
|
2006-11-17 14:17:40 -05:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-05 08:13:37 -05:00
|
|
|
static void
|
|
|
|
clutter_behaviour_path_dispose (GObject *gobject)
|
|
|
|
{
|
|
|
|
ClutterBehaviourPath *pathb = CLUTTER_BEHAVIOUR_PATH (gobject);
|
|
|
|
|
|
|
|
clutter_behaviour_path_set_path (pathb, NULL);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (clutter_behaviour_path_parent_class)->dispose (gobject);
|
|
|
|
}
|
|
|
|
|
2006-11-15 18:37:53 -05:00
|
|
|
static void
|
|
|
|
clutter_behaviour_path_class_init (ClutterBehaviourPathClass *klass)
|
|
|
|
{
|
2006-11-17 13:45:31 -05:00
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
ClutterBehaviourClass *behave_class = CLUTTER_BEHAVIOUR_CLASS (klass);
|
2008-12-05 08:13:37 -05:00
|
|
|
GParamSpec *pspec;
|
2006-11-17 13:45:31 -05:00
|
|
|
|
2008-12-05 08:13:37 -05:00
|
|
|
gobject_class->get_property = clutter_behaviour_path_get_property;
|
2006-11-17 14:17:40 -05:00
|
|
|
gobject_class->set_property = clutter_behaviour_path_set_property;
|
2008-12-05 08:13:37 -05:00
|
|
|
gobject_class->dispose = clutter_behaviour_path_dispose;
|
2006-11-17 13:45:31 -05:00
|
|
|
|
2008-12-05 08:13:37 -05:00
|
|
|
pspec = g_param_spec_object ("path",
|
2010-06-03 07:57:50 -04:00
|
|
|
P_("Path"),
|
|
|
|
P_("The ClutterPath object representing the path "
|
|
|
|
"to animate along"),
|
2008-12-05 08:13:37 -05:00
|
|
|
CLUTTER_TYPE_PATH,
|
|
|
|
CLUTTER_PARAM_READWRITE);
|
2010-06-21 05:20:32 -04:00
|
|
|
obj_props[PROP_PATH] = pspec;
|
2008-12-05 08:13:37 -05:00
|
|
|
g_object_class_install_property (gobject_class, PROP_PATH, pspec);
|
2006-11-17 14:17:40 -05:00
|
|
|
|
2006-11-17 13:45:31 -05:00
|
|
|
/**
|
|
|
|
* ClutterBehaviourPath::knot-reached:
|
|
|
|
* @pathb: the object which received the signal
|
2010-08-17 09:54:20 -04:00
|
|
|
* @knot_num: the index of the #ClutterKnot reached
|
2006-11-17 13:45:31 -05:00
|
|
|
*
|
|
|
|
* This signal is emitted each time a node defined inside the path
|
|
|
|
* is reached.
|
2006-11-17 14:17:40 -05:00
|
|
|
*
|
|
|
|
* Since: 0.2
|
2006-11-17 13:45:31 -05:00
|
|
|
*/
|
|
|
|
path_signals[KNOT_REACHED] =
|
|
|
|
g_signal_new ("knot-reached",
|
|
|
|
G_TYPE_FROM_CLASS (gobject_class),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (ClutterBehaviourPathClass, knot_reached),
|
|
|
|
NULL, NULL,
|
2010-06-11 10:49:46 -04:00
|
|
|
_clutter_marshal_VOID__UINT,
|
2006-11-17 13:45:31 -05:00
|
|
|
G_TYPE_NONE, 1,
|
2008-12-05 08:13:37 -05:00
|
|
|
G_TYPE_UINT);
|
2006-11-15 18:37:53 -05:00
|
|
|
|
|
|
|
behave_class->alpha_notify = clutter_behaviour_path_alpha_notify;
|
2007-11-06 10:46:23 -05:00
|
|
|
|
2006-11-17 13:45:31 -05:00
|
|
|
g_type_class_add_private (klass, sizeof (ClutterBehaviourPathPrivate));
|
2006-11-15 18:37:53 -05:00
|
|
|
}
|
|
|
|
|
2008-12-05 08:13:37 -05:00
|
|
|
static ClutterScriptableIface *parent_scriptable_iface = NULL;
|
2007-10-25 10:42:15 -04:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
clutter_behaviour_path_parse_custom_node (ClutterScriptable *scriptable,
|
|
|
|
ClutterScript *script,
|
|
|
|
GValue *value,
|
|
|
|
const gchar *name,
|
|
|
|
JsonNode *node)
|
|
|
|
{
|
2008-12-05 08:13:37 -05:00
|
|
|
if (strcmp ("path", name) == 0)
|
2007-10-25 10:42:15 -04:00
|
|
|
{
|
2008-12-05 08:13:37 -05:00
|
|
|
ClutterPath *path;
|
|
|
|
GValue node_value = { 0 };
|
2007-10-25 10:42:15 -04:00
|
|
|
|
2008-12-05 08:13:37 -05:00
|
|
|
path = g_object_ref_sink (clutter_path_new ());
|
2007-11-06 10:46:23 -05:00
|
|
|
|
2008-12-05 08:13:37 -05:00
|
|
|
json_node_get_value (node, &node_value);
|
2007-10-25 10:42:15 -04:00
|
|
|
|
2008-12-05 08:13:37 -05:00
|
|
|
if (!G_VALUE_HOLDS (&node_value, G_TYPE_STRING)
|
|
|
|
|| !clutter_path_set_description (path,
|
|
|
|
g_value_get_string (&node_value)))
|
|
|
|
g_warning ("Invalid path description");
|
2007-10-25 10:42:15 -04:00
|
|
|
|
2008-12-05 08:13:37 -05:00
|
|
|
g_value_unset (&node_value);
|
2007-10-25 10:42:15 -04:00
|
|
|
|
2008-12-05 08:13:37 -05:00
|
|
|
g_value_init (value, G_TYPE_OBJECT);
|
|
|
|
g_value_take_object (value, path);
|
2007-10-25 10:42:15 -04:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2008-12-05 08:13:37 -05:00
|
|
|
/* chain up */
|
|
|
|
else if (parent_scriptable_iface->parse_custom_node)
|
|
|
|
return parent_scriptable_iface->parse_custom_node (scriptable, script,
|
|
|
|
value, name, node);
|
|
|
|
else
|
|
|
|
return FALSE;
|
2007-10-25 10:42:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_scriptable_iface_init (ClutterScriptableIface *iface)
|
|
|
|
{
|
2008-12-05 08:13:37 -05:00
|
|
|
parent_scriptable_iface = g_type_interface_peek_parent (iface);
|
|
|
|
|
|
|
|
if (!parent_scriptable_iface)
|
|
|
|
parent_scriptable_iface
|
|
|
|
= g_type_default_interface_peek (CLUTTER_TYPE_SCRIPTABLE);
|
|
|
|
|
2007-10-25 10:42:15 -04:00
|
|
|
iface->parse_custom_node = clutter_behaviour_path_parse_custom_node;
|
2008-12-05 08:13:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_behaviour_path_init (ClutterBehaviourPath *self)
|
|
|
|
{
|
|
|
|
ClutterBehaviourPathPrivate *priv;
|
|
|
|
|
|
|
|
self->priv = priv = CLUTTER_BEHAVIOUR_PATH_GET_PRIVATE (self);
|
|
|
|
|
|
|
|
priv->path = NULL;
|
|
|
|
priv->last_knot_passed = G_MAXUINT;
|
2007-10-25 10:42:15 -04:00
|
|
|
}
|
|
|
|
|
2006-11-15 18:37:53 -05:00
|
|
|
/**
|
|
|
|
* clutter_behaviour_path_new:
|
2006-11-17 13:45:31 -05:00
|
|
|
* @alpha: a #ClutterAlpha, or %NULL
|
2008-12-05 08:13:37 -05:00
|
|
|
* @path: a #ClutterPath or %NULL for an empty path
|
2006-11-15 18:37:53 -05:00
|
|
|
*
|
2006-11-17 13:45:31 -05:00
|
|
|
* Creates a new path behaviour. You can use this behaviour to drive
|
2008-12-05 08:13:37 -05:00
|
|
|
* actors along the nodes of a path, described by @path.
|
|
|
|
*
|
|
|
|
* This will claim the floating reference on the #ClutterPath so you
|
|
|
|
* do not need to unref if it.
|
2006-11-15 18:37:53 -05:00
|
|
|
*
|
|
|
|
* Return value: a #ClutterBehaviour
|
2006-11-17 13:24:28 -05:00
|
|
|
*
|
|
|
|
* Since: 0.2
|
2006-11-15 18:37:53 -05:00
|
|
|
*/
|
|
|
|
ClutterBehaviour *
|
2008-12-05 08:13:37 -05:00
|
|
|
clutter_behaviour_path_new (ClutterAlpha *alpha,
|
|
|
|
ClutterPath *path)
|
2006-11-15 18:37:53 -05:00
|
|
|
{
|
2008-12-05 08:13:37 -05:00
|
|
|
return g_object_new (CLUTTER_TYPE_BEHAVIOUR_PATH,
|
|
|
|
"alpha", alpha,
|
|
|
|
"path", path,
|
|
|
|
NULL);
|
2006-11-15 18:37:53 -05:00
|
|
|
}
|
|
|
|
|
2006-11-17 13:24:28 -05:00
|
|
|
/**
|
2008-12-05 08:13:37 -05:00
|
|
|
* clutter_behaviour_path_new_with_description:
|
|
|
|
* @alpha: a #ClutterAlpha
|
|
|
|
* @desc: a string description of the path
|
2006-11-17 13:24:28 -05:00
|
|
|
*
|
2008-12-05 08:13:37 -05:00
|
|
|
* Creates a new path behaviour using the path described by @desc. See
|
|
|
|
* clutter_path_add_string() for a description of the format.
|
2006-11-17 13:24:28 -05:00
|
|
|
*
|
2008-12-05 08:13:37 -05:00
|
|
|
* Return value: a #ClutterBehaviour
|
2006-11-17 13:24:28 -05:00
|
|
|
*
|
2008-12-05 08:13:37 -05:00
|
|
|
* Since: 1.0
|
2006-11-17 13:24:28 -05:00
|
|
|
*/
|
2008-12-05 08:13:37 -05:00
|
|
|
ClutterBehaviour *
|
|
|
|
clutter_behaviour_path_new_with_description (ClutterAlpha *alpha,
|
|
|
|
const gchar *desc)
|
2006-11-15 18:37:53 -05:00
|
|
|
{
|
2008-12-05 08:13:37 -05:00
|
|
|
return g_object_new (CLUTTER_TYPE_BEHAVIOUR_PATH,
|
|
|
|
"alpha", alpha,
|
|
|
|
"path", clutter_path_new_with_description (desc),
|
|
|
|
NULL);
|
2006-11-15 18:37:53 -05:00
|
|
|
}
|
|
|
|
|
2006-11-17 13:24:28 -05:00
|
|
|
/**
|
2008-12-05 08:13:37 -05:00
|
|
|
* clutter_behaviour_path_new_with_knots:
|
|
|
|
* @alpha: a #ClutterAlpha
|
|
|
|
* @knots: an array of #ClutterKnot<!-- -->s
|
|
|
|
* @n_knots: number of entries in @knots
|
2007-11-06 10:46:23 -05:00
|
|
|
*
|
2008-12-05 08:13:37 -05:00
|
|
|
* Creates a new path behaviour that will make the actors visit all of
|
|
|
|
* the given knots in order with straight lines in between.
|
2006-11-17 13:24:28 -05:00
|
|
|
*
|
2008-12-05 08:13:37 -05:00
|
|
|
* A path will be created where the first knot is used in a
|
|
|
|
* %CLUTTER_PATH_MOVE_TO and the subsequent knots are used in
|
|
|
|
* %CLUTTER_PATH_LINE_TO<!-- -->s.
|
2007-11-06 10:46:23 -05:00
|
|
|
*
|
2008-12-05 08:13:37 -05:00
|
|
|
* Return value: a #ClutterBehaviour
|
2006-11-17 13:24:28 -05:00
|
|
|
*
|
2008-12-05 08:13:37 -05:00
|
|
|
* Since: 1.0
|
2006-11-17 13:24:28 -05:00
|
|
|
*/
|
2008-12-05 08:13:37 -05:00
|
|
|
ClutterBehaviour *
|
|
|
|
clutter_behaviour_path_new_with_knots (ClutterAlpha *alpha,
|
|
|
|
const ClutterKnot *knots,
|
|
|
|
guint n_knots)
|
2006-11-17 13:24:28 -05:00
|
|
|
{
|
2008-12-05 08:13:37 -05:00
|
|
|
ClutterPath *path = clutter_path_new ();
|
|
|
|
guint i;
|
2006-11-17 13:24:28 -05:00
|
|
|
|
2008-12-05 08:13:37 -05:00
|
|
|
if (n_knots > 0)
|
|
|
|
{
|
|
|
|
clutter_path_add_move_to (path, knots[0].x, knots[0].y);
|
2006-11-17 13:24:28 -05:00
|
|
|
|
2008-12-05 08:13:37 -05:00
|
|
|
for (i = 1; i < n_knots; i++)
|
|
|
|
clutter_path_add_line_to (path, knots[i].x, knots[i].y);
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_object_new (CLUTTER_TYPE_BEHAVIOUR_PATH,
|
|
|
|
"alpha", alpha,
|
|
|
|
"path", path,
|
|
|
|
NULL);
|
2006-11-17 13:24:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-12-05 08:13:37 -05:00
|
|
|
* clutter_behaviour_path_set_path:
|
|
|
|
* @pathb: the path behaviour
|
|
|
|
* @path: the new path to follow
|
2007-11-06 10:46:23 -05:00
|
|
|
*
|
2008-12-05 08:13:37 -05:00
|
|
|
* Change the path that the actors will follow. This will take the
|
|
|
|
* floating reference on the #ClutterPath so you do not need to unref
|
|
|
|
* it.
|
2006-11-17 13:24:28 -05:00
|
|
|
*
|
2008-12-05 08:13:37 -05:00
|
|
|
* Since: 1.0
|
2006-11-17 13:24:28 -05:00
|
|
|
*/
|
|
|
|
void
|
2008-12-05 08:13:37 -05:00
|
|
|
clutter_behaviour_path_set_path (ClutterBehaviourPath *pathb,
|
|
|
|
ClutterPath *path)
|
2006-11-17 13:24:28 -05:00
|
|
|
{
|
|
|
|
ClutterBehaviourPathPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (CLUTTER_IS_BEHAVIOUR_PATH (pathb));
|
|
|
|
|
|
|
|
priv = pathb->priv;
|
|
|
|
|
2008-12-05 08:13:37 -05:00
|
|
|
if (path)
|
|
|
|
g_object_ref_sink (path);
|
2006-11-17 13:24:28 -05:00
|
|
|
|
2008-12-05 08:13:37 -05:00
|
|
|
if (priv->path)
|
|
|
|
g_object_unref (priv->path);
|
2006-11-17 13:24:28 -05:00
|
|
|
|
2008-12-05 08:13:37 -05:00
|
|
|
priv->path = path;
|
2006-11-15 18:37:53 -05:00
|
|
|
|
2010-06-21 05:20:32 -04:00
|
|
|
_clutter_notify_by_pspec (G_OBJECT (pathb), obj_props[PROP_PATH]);
|
2006-11-15 18:37:53 -05:00
|
|
|
}
|
|
|
|
|
2006-11-17 13:24:28 -05:00
|
|
|
/**
|
2008-12-05 08:13:37 -05:00
|
|
|
* clutter_behaviour_path_get_path:
|
|
|
|
* @pathb: a #ClutterBehaviourPath instance
|
2006-11-17 13:24:28 -05:00
|
|
|
*
|
2008-12-05 08:13:37 -05:00
|
|
|
* Get the current path of the behaviour
|
2007-11-06 10:46:23 -05:00
|
|
|
*
|
2009-02-16 19:25:20 -05:00
|
|
|
* Return value: (transfer none): the path
|
2006-11-17 13:24:28 -05:00
|
|
|
*
|
2008-12-05 09:08:06 -05:00
|
|
|
* Since: 1.0
|
2006-11-17 13:24:28 -05:00
|
|
|
*/
|
2008-12-05 08:13:37 -05:00
|
|
|
ClutterPath *
|
|
|
|
clutter_behaviour_path_get_path (ClutterBehaviourPath *pathb)
|
2006-11-15 18:37:53 -05:00
|
|
|
{
|
2008-12-05 08:13:37 -05:00
|
|
|
g_return_val_if_fail (CLUTTER_IS_BEHAVIOUR_PATH (pathb), NULL);
|
2006-11-15 18:37:53 -05:00
|
|
|
|
2008-12-05 08:13:37 -05:00
|
|
|
return pathb->priv->path;
|
2006-11-15 18:37:53 -05:00
|
|
|
}
|