1
0
mirror of https://github.com/brl/mutter.git synced 2025-06-14 09:19:31 +00:00
Files
build
clutter
cally
cex100
cogl
deprecated
clutter-actor-deprecated.c
clutter-actor.h
clutter-alpha.c
clutter-alpha.h
clutter-animatable.h
clutter-animation.c
clutter-animation.h
clutter-animator.c
clutter-animator.h
clutter-backend.h
clutter-behaviour-depth.c
clutter-behaviour-depth.h
clutter-behaviour-ellipse.c
clutter-behaviour-ellipse.h
clutter-behaviour-opacity.c
clutter-behaviour-opacity.h
clutter-behaviour-path.c
clutter-behaviour-path.h
clutter-behaviour-rotate.c
clutter-behaviour-rotate.h
clutter-behaviour-scale.c
clutter-behaviour-scale.h
clutter-behaviour.c
clutter-behaviour.h
clutter-bin-layout.h
clutter-box.c
clutter-box.h
clutter-cairo-texture.c
clutter-cairo-texture.h
clutter-container.h
clutter-fixed.c
clutter-fixed.h
clutter-frame-source.c
clutter-frame-source.h
clutter-group.c
clutter-group.h
clutter-input-device-deprecated.c
clutter-input-device.h
clutter-keysyms.h
clutter-layout-manager-deprecated.c
clutter-main.h
clutter-media.c
clutter-media.h
clutter-rectangle.c
clutter-rectangle.h
clutter-score.c
clutter-score.h
clutter-shader.c
clutter-shader.h
clutter-stage-manager.h
clutter-stage.h
clutter-state.c
clutter-state.h
clutter-table-layout.c
clutter-table-layout.h
clutter-texture.c
clutter-texture.h
clutter-timeline.h
clutter-timeout-interval.c
clutter-timeout-interval.h
clutter-timeout-pool.c
clutter-timeout-pool.h
clutter-util.h
egl
evdev
gdk
osx
tslib
wayland
win32
x11
Makefile.am
abicheck.sh
clutter-action.c
clutter-action.h
clutter-actor-box.c
clutter-actor-meta-private.h
clutter-actor-meta.c
clutter-actor-meta.h
clutter-actor-private.h
clutter-actor.c
clutter-actor.h
clutter-align-constraint.c
clutter-align-constraint.h
clutter-animatable.c
clutter-animatable.h
clutter-backend-private.h
clutter-backend.c
clutter-backend.h
clutter-base-types.c
clutter-bezier.c
clutter-bezier.h
clutter-bin-layout.c
clutter-bin-layout.h
clutter-bind-constraint.c
clutter-bind-constraint.h
clutter-binding-pool.c
clutter-binding-pool.h
clutter-blur-effect.c
clutter-blur-effect.h
clutter-box-layout.c
clutter-box-layout.h
clutter-brightness-contrast-effect.c
clutter-brightness-contrast-effect.h
clutter-cairo.c
clutter-cairo.h
clutter-canvas.c
clutter-canvas.h
clutter-child-meta.c
clutter-child-meta.h
clutter-click-action.c
clutter-click-action.h
clutter-clone.c
clutter-clone.h
clutter-cogl-compat.h
clutter-color-static.h
clutter-color.c
clutter-color.h
clutter-colorize-effect.c
clutter-colorize-effect.h
clutter-config.h.in
clutter-config.h.win32
clutter-config.h.win32_GDK
clutter-constraint.c
clutter-constraint.h
clutter-container.c
clutter-container.h
clutter-content-private.h
clutter-content.c
clutter-content.h
clutter-debug.h
clutter-deform-effect.c
clutter-deform-effect.h
clutter-deprecated.h
clutter-desaturate-effect.c
clutter-desaturate-effect.h
clutter-device-manager-private.h
clutter-device-manager.c
clutter-device-manager.h
clutter-drag-action.c
clutter-drag-action.h
clutter-drop-action.c
clutter-drop-action.h
clutter-easing.c
clutter-easing.h
clutter-effect-private.h
clutter-effect.c
clutter-effect.h
clutter-enum-types.c.in
clutter-enum-types.h.in
clutter-enums.h
clutter-event-private.h
clutter-event-translator.c
clutter-event-translator.h
clutter-event.c
clutter-event.h
clutter-feature.c
clutter-feature.h
clutter-fixed-layout.c
clutter-fixed-layout.h
clutter-flatten-effect.c
clutter-flatten-effect.h
clutter-flow-layout.c
clutter-flow-layout.h
clutter-gesture-action-private.h
clutter-gesture-action.c
clutter-gesture-action.h
clutter-grid-layout.c
clutter-grid-layout.h
clutter-group.h
clutter-id-pool.c
clutter-id-pool.h
clutter-image.c
clutter-image.h
clutter-input-device.c
clutter-input-device.h
clutter-interval.c
clutter-interval.h
clutter-keyframe-transition.c
clutter-keyframe-transition.h
clutter-keysyms-table.c
clutter-keysyms-update.pl
clutter-keysyms.h
clutter-layout-manager.c
clutter-layout-manager.h
clutter-layout-meta.c
clutter-layout-meta.h
clutter-list-model.c
clutter-list-model.h
clutter-macros.h
clutter-main.c
clutter-main.h
clutter-marshal.list
clutter-master-clock.c
clutter-master-clock.h
clutter-model-private.h
clutter-model.c
clutter-model.h
clutter-offscreen-effect-private.h
clutter-offscreen-effect.c
clutter-offscreen-effect.h
clutter-page-turn-effect.c
clutter-page-turn-effect.h
clutter-paint-node-private.h
clutter-paint-node.c
clutter-paint-node.h
clutter-paint-nodes.c
clutter-paint-nodes.h
clutter-paint-volume-private.h
clutter-paint-volume.c
clutter-pan-action.c
clutter-pan-action.h
clutter-path-constraint.c
clutter-path-constraint.h
clutter-path.c
clutter-path.h
clutter-private.h
clutter-profile.c
clutter-profile.h
clutter-property-transition.c
clutter-property-transition.h
clutter-rotate-action.c
clutter-rotate-action.h
clutter-script-parser.c
clutter-script-private.h
clutter-script.c
clutter-script.h
clutter-scriptable.c
clutter-scriptable.h
clutter-scroll-actor.c
clutter-scroll-actor.h
clutter-settings-private.h
clutter-settings.c
clutter-settings.h
clutter-shader-effect.c
clutter-shader-effect.h
clutter-shader-types.c
clutter-shader-types.h
clutter-snap-constraint.c
clutter-snap-constraint.h
clutter-stage-manager-private.h
clutter-stage-manager.c
clutter-stage-manager.h
clutter-stage-private.h
clutter-stage-window.c
clutter-stage-window.h
clutter-stage.c
clutter-stage.h
clutter-swipe-action.c
clutter-swipe-action.h
clutter-tap-action.c
clutter-tap-action.h
clutter-test-utils.c
clutter-test-utils.h
clutter-text-buffer.c
clutter-text-buffer.h
clutter-text.c
clutter-text.h
clutter-texture.h
clutter-timeline.c
clutter-timeline.h
clutter-transition-group.c
clutter-transition-group.h
clutter-transition.c
clutter-transition.h
clutter-types.h
clutter-units.c
clutter-units.h
clutter-util.c
clutter-version.h.in
clutter-zoom-action.c
clutter-zoom-action.h
clutter.h
clutter.pc.in
clutter.symbols
config.h.win32.in
doc
examples
po
tests
.gitignore
COPYING
ChangeLog.pre-git-import
Makefile.am
NEWS
README.in
README.md
autogen.sh
clutter.doap
configure.ac
mutter/clutter/deprecated/clutter-behaviour-path.c
2013-07-03 18:12:47 +01:00

468 lines
14 KiB
C

/*
* Clutter.
*
* An OpenGL based 'interactive canvas' library.
*
* Authored By:
* Matthew Allum <mallum@openedhand.com>
* Neil Roberts <neil@linux.intel.com>
*
* Copyright (C) 2006, 2007, 2008 OpenedHand Ltd
* Copyright (C) 2009, 2010 Intel Corp
*
* 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/>.
*/
/**
* SECTION:clutter-behaviour-path
* @Title: ClutterBehaviourPath
* @short_description: A behaviour for moving actors along a #ClutterPath
* @Deprecated: 1.6: Use #ClutterPathConstraint and clutter_actor_animate()
* with the #ClutterPathConstraint:offset property instead.
*
* #ClutterBehaviourPath interpolates actors along a defined path.
*
* 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.
*
* 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
* }
* }
* ]|
*
* <note>If the alpha function is a periodic function, i.e. it returns to
* 0.0 after reaching 1.0, then the actors will walk the path back to the
* starting #ClutterKnot.</note>
*
* #ClutterBehaviourPath is available since Clutter 0.2
*
* Deprecated: 1.6: Use #ClutterPath and #ClutterPathConstraint with
* clutter_actor_animate() instead.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#define CLUTTER_DISABLE_DEPRECATION_WARNINGS
#include "clutter-alpha.h"
#include "clutter-behaviour.h"
#include "clutter-behaviour-path.h"
#include "clutter-bezier.h"
#include "clutter-debug.h"
#include "clutter-enum-types.h"
#include "clutter-main.h"
#include "clutter-marshal.h"
#include "clutter-private.h"
#include "clutter-script-private.h"
#include "clutter-scriptable.h"
#include <math.h>
struct _ClutterBehaviourPathPrivate
{
ClutterPath *path;
guint last_knot_passed;
};
enum
{
KNOT_REACHED,
LAST_SIGNAL
};
static guint path_signals[LAST_SIGNAL] = { 0, };
enum
{
PROP_0,
PROP_PATH,
PROP_LAST
};
static GParamSpec *obj_props[PROP_LAST];
static void clutter_scriptable_iface_init (ClutterScriptableIface *iface);
G_DEFINE_TYPE_WITH_CODE (ClutterBehaviourPath,
clutter_behaviour_path,
CLUTTER_TYPE_BEHAVIOUR,
G_ADD_PRIVATE (ClutterBehaviourPath)
G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_SCRIPTABLE,
clutter_scriptable_iface_init))
static void
actor_apply_knot_foreach (ClutterBehaviour *behaviour,
ClutterActor *actor,
gpointer data)
{
ClutterKnot *knot = data;
CLUTTER_NOTE (ANIMATION, "Setting actor to %ix%i", knot->x, knot->y);
clutter_actor_set_position (actor, knot->x, knot->y);
}
static void
clutter_behaviour_path_alpha_notify (ClutterBehaviour *behave,
gdouble alpha_value)
{
ClutterBehaviourPath *pathb = CLUTTER_BEHAVIOUR_PATH (behave);
ClutterBehaviourPathPrivate *priv = pathb->priv;
ClutterKnot position;
guint knot_num;
if (priv->path)
knot_num = clutter_path_get_position (priv->path, alpha_value, &position);
else
{
memset (&position, 0, sizeof (position));
knot_num = 0;
}
clutter_behaviour_actors_foreach (behave,
actor_apply_knot_foreach,
&position);
if (knot_num != priv->last_knot_passed)
{
g_signal_emit (behave, path_signals[KNOT_REACHED], 0, knot_num);
priv->last_knot_passed = knot_num;
}
}
static void
clutter_behaviour_path_get_property (GObject *gobject,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
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;
}
}
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)
{
case PROP_PATH:
clutter_behaviour_path_set_path (pathb, g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
break;
}
}
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);
}
static void
clutter_behaviour_path_class_init (ClutterBehaviourPathClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
ClutterBehaviourClass *behave_class = CLUTTER_BEHAVIOUR_CLASS (klass);
GParamSpec *pspec;
gobject_class->get_property = clutter_behaviour_path_get_property;
gobject_class->set_property = clutter_behaviour_path_set_property;
gobject_class->dispose = clutter_behaviour_path_dispose;
pspec = g_param_spec_object ("path",
P_("Path"),
P_("The ClutterPath object representing the path "
"to animate along"),
CLUTTER_TYPE_PATH,
CLUTTER_PARAM_READWRITE);
obj_props[PROP_PATH] = pspec;
g_object_class_install_property (gobject_class, PROP_PATH, pspec);
/**
* ClutterBehaviourPath::knot-reached:
* @pathb: the object which received the signal
* @knot_num: the index of the #ClutterKnot reached
*
* This signal is emitted each time a node defined inside the path
* is reached.
*
* Since: 0.2
*
* Deprecated: 1.6
*/
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,
_clutter_marshal_VOID__UINT,
G_TYPE_NONE, 1,
G_TYPE_UINT);
behave_class->alpha_notify = clutter_behaviour_path_alpha_notify;
}
static ClutterScriptableIface *parent_scriptable_iface = NULL;
static gboolean
clutter_behaviour_path_parse_custom_node (ClutterScriptable *scriptable,
ClutterScript *script,
GValue *value,
const gchar *name,
JsonNode *node)
{
if (strcmp ("path", name) == 0)
{
ClutterPath *path;
GValue node_value = { 0 };
path = g_object_ref_sink (clutter_path_new ());
json_node_get_value (node, &node_value);
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");
g_value_unset (&node_value);
g_value_init (value, G_TYPE_OBJECT);
g_value_take_object (value, path);
return TRUE;
}
/* 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;
}
static void
clutter_scriptable_iface_init (ClutterScriptableIface *iface)
{
parent_scriptable_iface = g_type_interface_peek_parent (iface);
if (!parent_scriptable_iface)
parent_scriptable_iface
= g_type_default_interface_peek (CLUTTER_TYPE_SCRIPTABLE);
iface->parse_custom_node = clutter_behaviour_path_parse_custom_node;
}
static void
clutter_behaviour_path_init (ClutterBehaviourPath *self)
{
self->priv = clutter_behaviour_path_get_instance_private (self);
self->priv->last_knot_passed = G_MAXUINT;
}
/**
* clutter_behaviour_path_new:
* @alpha: (allow-none): a #ClutterAlpha instance, or %NULL
* @path: a #ClutterPath or %NULL for an empty path
*
* Creates a new path behaviour. You can use this behaviour to drive
* 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.
*
* If @alpha is not %NULL, the #ClutterBehaviour will take ownership
* of the #ClutterAlpha instance. In the case when @alpha is %NULL,
* it can be set later with clutter_behaviour_set_alpha().
*
* Return value: (transfer full): a #ClutterBehaviour
*
* Since: 0.2
*
* Deprecated: 1.6
*/
ClutterBehaviour *
clutter_behaviour_path_new (ClutterAlpha *alpha,
ClutterPath *path)
{
return g_object_new (CLUTTER_TYPE_BEHAVIOUR_PATH,
"alpha", alpha,
"path", path,
NULL);
}
/**
* clutter_behaviour_path_new_with_description:
* @alpha: (allow-none): a #ClutterAlpha instance, or %NULL
* @desc: a string description of the path
*
* Creates a new path behaviour using the path described by @desc. See
* clutter_path_add_string() for a description of the format.
*
* If @alpha is not %NULL, the #ClutterBehaviour will take ownership
* of the #ClutterAlpha instance. In the case when @alpha is %NULL,
* it can be set later with clutter_behaviour_set_alpha().
*
* Return value: (transfer full): a #ClutterBehaviour
*
* Since: 1.0
*
* Deprecated: 1.6
*/
ClutterBehaviour *
clutter_behaviour_path_new_with_description (ClutterAlpha *alpha,
const gchar *desc)
{
return g_object_new (CLUTTER_TYPE_BEHAVIOUR_PATH,
"alpha", alpha,
"path", clutter_path_new_with_description (desc),
NULL);
}
/**
* clutter_behaviour_path_new_with_knots:
* @alpha: (allow-none): a #ClutterAlpha instance, or %NULL
* @knots: (array length=n_knots): an array of #ClutterKnot<!-- -->s
* @n_knots: number of entries in @knots
*
* Creates a new path behaviour that will make the actors visit all of
* the given knots in order with straight lines in between.
*
* 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.
*
* If @alpha is not %NULL, the #ClutterBehaviour will take ownership
* of the #ClutterAlpha instance. In the case when @alpha is %NULL,
* it can be set later with clutter_behaviour_set_alpha().
*
* Return value: (transfer full): a #ClutterBehaviour
*
* Since: 1.0
*
* Deprecated: 1.6
*/
ClutterBehaviour *
clutter_behaviour_path_new_with_knots (ClutterAlpha *alpha,
const ClutterKnot *knots,
guint n_knots)
{
ClutterPath *path = clutter_path_new ();
guint i;
if (n_knots > 0)
{
clutter_path_add_move_to (path, knots[0].x, knots[0].y);
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);
}
/**
* clutter_behaviour_path_set_path:
* @pathb: the path behaviour
* @path: the new path to follow
*
* 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.
*
* Since: 1.0
*
* Deprecated: 1.6
*/
void
clutter_behaviour_path_set_path (ClutterBehaviourPath *pathb,
ClutterPath *path)
{
ClutterBehaviourPathPrivate *priv;
g_return_if_fail (CLUTTER_IS_BEHAVIOUR_PATH (pathb));
priv = pathb->priv;
if (path)
g_object_ref_sink (path);
if (priv->path)
g_object_unref (priv->path);
priv->path = path;
g_object_notify_by_pspec (G_OBJECT (pathb), obj_props[PROP_PATH]);
}
/**
* clutter_behaviour_path_get_path:
* @pathb: a #ClutterBehaviourPath instance
*
* Get the current path of the behaviour
*
* Return value: (transfer none): the path
*
* Since: 1.0
*
* Deprecated: 1.6
*/
ClutterPath *
clutter_behaviour_path_get_path (ClutterBehaviourPath *pathb)
{
g_return_val_if_fail (CLUTTER_IS_BEHAVIOUR_PATH (pathb), NULL);
return pathb->priv->path;
}