2006-05-29 08:59:36 +00:00
|
|
|
/*
|
|
|
|
* Clutter.
|
|
|
|
*
|
|
|
|
* An OpenGL based 'interactive canvas' library.
|
|
|
|
*
|
|
|
|
* Authored By Matthew Allum <mallum@openedhand.com>
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 OpenedHand
|
|
|
|
*
|
|
|
|
* 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, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2006-06-21 22:34:25 +00:00
|
|
|
/**
|
|
|
|
* SECTION:clutter-timeline
|
2007-06-21 14:19:56 +00:00
|
|
|
* @short_description: A class for based events
|
|
|
|
*
|
|
|
|
* #ClutterTimeline is a base class for managing time based events such
|
2006-06-21 22:34:25 +00:00
|
|
|
* as animations.
|
|
|
|
*
|
2007-06-21 14:19:56 +00:00
|
|
|
* Every timeline shares the same #ClutterTimeoutPool to decrease the
|
|
|
|
* possibility of starvating the main loop when using many timelines
|
|
|
|
* at the same time; this might cause problems if you are also using
|
|
|
|
* a library making heavy use of threads with no GLib main loop integration.
|
|
|
|
* In that case you might disable the common timeline pool by setting
|
|
|
|
* the %CLUTTER_TIMELINE=no-pool environment variable prior to launching
|
|
|
|
* your application.
|
2008-02-02 23:39:53 +00:00
|
|
|
*
|
2006-06-21 22:34:25 +00:00
|
|
|
*/
|
|
|
|
|
2007-10-12 08:17:00 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2006-11-15 23:37:53 +00:00
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2006-06-21 22:34:25 +00:00
|
|
|
|
2007-06-09 13:20:00 +00:00
|
|
|
#include "clutter-timeout-pool.h"
|
2006-05-29 08:59:36 +00:00
|
|
|
#include "clutter-timeline.h"
|
|
|
|
#include "clutter-main.h"
|
2006-06-22 12:05:51 +00:00
|
|
|
#include "clutter-marshal.h"
|
2006-11-21 Emmanuele Bassi <ebassi@openedhand.com>
* configure.ac: Enable debug messages also when
--enable-debug is set to "minimum".
* clutter/Makefile.am:
* clutter/clutter-debug.h: Move all debugging macros inside
this private header; make all debug macros depend on the
CLUTTER_ENABLE_DEBUG compile time define, controlled by
the --enable-debug configure switch; add G_LOG_DOMAIN define.
* clutter/clutter-main.c: Clean up the debug stuff; add
command line argument parsing using GOption; the debug
messages now are triggered like this:
CLUTTER_DEBUG=section:section:... clutter-app
or like this:
clutter-app --clutter-debug=section:section:...
where "section" is one of the sections listed in clutter-main.c,
or "all", for all sections; each section is bound to a flag,
which can be used to define a domain when adding a debug note
using the CLUTTER_NOTE() macro; the old CLUTTER_DBG() macro is
just a wrapper around that, under the CLUTTER_DEBUG_MISC domain;
CLUTTER_NOTE() is used like this:
CLUTTER_NOTE (DOMAIN, log-function);
where log function is g_printerr(), g_message(), g_warning(),
g_critical() or directly g_log() - for instance:
CLUTTER_NOTE (PANGO, g_warning ("Cache miss: %d", glyph));
will print the warning only if the "pango" flag has been
set to the CLUTTER_DEBUG envvar or passed to the --clutter-debug
command line argument.
similar to CLUTTER_SHOW_FPS, there's also the --clutter-show-fps
command line switch; also, the --display and --screen command
line switches have been added: the first overrides the DISPLAY
envvar and the second controls the X screen used by Clutter to
get the root window on the display.
* clutter/clutter-main.h:
* clutter/clutter-main.c: Add extended support for GOption
in Clutter; use clutter_init_with_args() to let Clutter
parse your own command line arguments; use instead
clutter_get_option_group() to get the GOptionGroup used by
Clutter if you want to do the parsing yourself with
g_option_context_parse(). The init sequence has been verified,
updated and moved into common functions where possible.
* clutter/pango/pangoclutter-render.c:
* clutter/*.c: Include "clutter-debug.h" where needed; use
CLUTTER_NOTE() instead of CLUTTER_DBG().
* examples/super-oh.c: Use the new clutter_init_with_args()
function, and add a --num-hands command line switch to
the SuperOH example code controlling the number of hands at
runtime.
2006-11-21 21:27:53 +00:00
|
|
|
#include "clutter-private.h"
|
|
|
|
#include "clutter-debug.h"
|
2007-11-15 17:03:55 +00:00
|
|
|
#include "clutter-enum-types.h"
|
2006-05-29 08:59:36 +00:00
|
|
|
|
|
|
|
G_DEFINE_TYPE (ClutterTimeline, clutter_timeline, G_TYPE_OBJECT);
|
|
|
|
|
2006-11-21 Emmanuele Bassi <ebassi@openedhand.com>
* configure.ac: Enable debug messages also when
--enable-debug is set to "minimum".
* clutter/Makefile.am:
* clutter/clutter-debug.h: Move all debugging macros inside
this private header; make all debug macros depend on the
CLUTTER_ENABLE_DEBUG compile time define, controlled by
the --enable-debug configure switch; add G_LOG_DOMAIN define.
* clutter/clutter-main.c: Clean up the debug stuff; add
command line argument parsing using GOption; the debug
messages now are triggered like this:
CLUTTER_DEBUG=section:section:... clutter-app
or like this:
clutter-app --clutter-debug=section:section:...
where "section" is one of the sections listed in clutter-main.c,
or "all", for all sections; each section is bound to a flag,
which can be used to define a domain when adding a debug note
using the CLUTTER_NOTE() macro; the old CLUTTER_DBG() macro is
just a wrapper around that, under the CLUTTER_DEBUG_MISC domain;
CLUTTER_NOTE() is used like this:
CLUTTER_NOTE (DOMAIN, log-function);
where log function is g_printerr(), g_message(), g_warning(),
g_critical() or directly g_log() - for instance:
CLUTTER_NOTE (PANGO, g_warning ("Cache miss: %d", glyph));
will print the warning only if the "pango" flag has been
set to the CLUTTER_DEBUG envvar or passed to the --clutter-debug
command line argument.
similar to CLUTTER_SHOW_FPS, there's also the --clutter-show-fps
command line switch; also, the --display and --screen command
line switches have been added: the first overrides the DISPLAY
envvar and the second controls the X screen used by Clutter to
get the root window on the display.
* clutter/clutter-main.h:
* clutter/clutter-main.c: Add extended support for GOption
in Clutter; use clutter_init_with_args() to let Clutter
parse your own command line arguments; use instead
clutter_get_option_group() to get the GOptionGroup used by
Clutter if you want to do the parsing yourself with
g_option_context_parse(). The init sequence has been verified,
updated and moved into common functions where possible.
* clutter/pango/pangoclutter-render.c:
* clutter/*.c: Include "clutter-debug.h" where needed; use
CLUTTER_NOTE() instead of CLUTTER_DBG().
* examples/super-oh.c: Use the new clutter_init_with_args()
function, and add a --num-hands command line switch to
the SuperOH example code controlling the number of hands at
runtime.
2006-11-21 21:27:53 +00:00
|
|
|
#define FPS_TO_INTERVAL(f) (1000 / (f))
|
2007-06-21 14:19:56 +00:00
|
|
|
#define CLUTTER_TIMELINE_PRIORITY (G_PRIORITY_DEFAULT + 30)
|
2007-06-09 13:20:00 +00:00
|
|
|
|
2006-11-15 23:37:53 +00:00
|
|
|
struct _ClutterTimelinePrivate
|
2006-05-29 08:59:36 +00:00
|
|
|
{
|
2007-11-15 17:03:55 +00:00
|
|
|
ClutterTimelineDirection direction;
|
|
|
|
|
2006-11-15 23:37:53 +00:00
|
|
|
guint timeout_id;
|
2007-06-07 10:26:18 +00:00
|
|
|
guint delay_id;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-11-15 17:03:55 +00:00
|
|
|
gint current_frame_num;
|
|
|
|
|
2006-11-15 23:37:53 +00:00
|
|
|
guint fps;
|
|
|
|
guint n_frames;
|
2007-06-07 10:26:18 +00:00
|
|
|
guint delay;
|
2007-10-16 13:41:34 +00:00
|
|
|
guint duration;
|
2006-11-15 23:37:53 +00:00
|
|
|
|
2007-11-30 13:20:15 +00:00
|
|
|
gint skipped_frames;
|
|
|
|
|
2008-03-07 01:00:00 +00:00
|
|
|
GTimeVal prev_frame_timeval;
|
2007-11-30 17:07:08 +00:00
|
|
|
guint msecs_delta;
|
2006-11-15 23:37:53 +00:00
|
|
|
|
2008-03-18 17:50:45 +00:00
|
|
|
GHashTable *markers_by_frame;
|
|
|
|
GHashTable *markers_by_name;
|
|
|
|
|
2006-11-15 23:37:53 +00:00
|
|
|
guint loop : 1;
|
2006-05-29 08:59:36 +00:00
|
|
|
};
|
|
|
|
|
2008-03-18 17:50:45 +00:00
|
|
|
typedef struct {
|
|
|
|
gchar *name;
|
|
|
|
guint frame_num;
|
|
|
|
GQuark quark;
|
|
|
|
} TimelineMarker;
|
|
|
|
|
2006-05-29 08:59:36 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2006-05-29 08:59:36 +00:00
|
|
|
PROP_FPS,
|
2006-11-15 23:37:53 +00:00
|
|
|
PROP_NUM_FRAMES,
|
2007-06-07 10:26:18 +00:00
|
|
|
PROP_LOOP,
|
2007-10-16 13:41:34 +00:00
|
|
|
PROP_DELAY,
|
2007-11-15 17:03:55 +00:00
|
|
|
PROP_DURATION,
|
|
|
|
PROP_DIRECTION
|
2006-05-29 08:59:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2006-11-15 23:37:53 +00:00
|
|
|
NEW_FRAME,
|
|
|
|
STARTED,
|
|
|
|
PAUSED,
|
|
|
|
COMPLETED,
|
2008-03-18 17:50:45 +00:00
|
|
|
MARKER_REACHED,
|
2006-11-15 23:37:53 +00:00
|
|
|
|
2006-05-29 08:59:36 +00:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2007-06-21 14:19:56 +00:00
|
|
|
static guint timeline_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
static gint timeline_use_pool = -1;
|
|
|
|
static ClutterTimeoutPool *timeline_pool = NULL;
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
timeline_pool_init (void)
|
|
|
|
{
|
|
|
|
if (timeline_use_pool == -1)
|
|
|
|
{
|
|
|
|
const gchar *timeline_env;
|
|
|
|
|
|
|
|
timeline_env = g_getenv ("CLUTTER_TIMELINE");
|
|
|
|
if (timeline_env && timeline_env[0] != '\0' &&
|
|
|
|
strcmp (timeline_env, "no-pool") == 0)
|
|
|
|
{
|
|
|
|
timeline_use_pool = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
timeline_pool = clutter_timeout_pool_new (CLUTTER_TIMELINE_PRIORITY);
|
|
|
|
timeline_use_pool = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static guint
|
|
|
|
timeout_add (guint interval,
|
|
|
|
GSourceFunc func,
|
|
|
|
gpointer data,
|
|
|
|
GDestroyNotify notify)
|
|
|
|
{
|
|
|
|
guint res;
|
|
|
|
|
2007-10-16 13:41:34 +00:00
|
|
|
if (G_LIKELY (timeline_use_pool))
|
2007-06-21 14:19:56 +00:00
|
|
|
{
|
|
|
|
g_assert (timeline_pool != NULL);
|
|
|
|
res = clutter_timeout_pool_add (timeline_pool,
|
|
|
|
interval,
|
|
|
|
func, data, notify);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-08-08 10:20:14 +00:00
|
|
|
res = clutter_threads_add_timeout_full (CLUTTER_TIMELINE_PRIORITY,
|
|
|
|
interval,
|
|
|
|
func, data, notify);
|
2007-06-21 14:19:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
timeout_remove (guint tag)
|
|
|
|
{
|
2007-10-16 13:41:34 +00:00
|
|
|
if (G_LIKELY (timeline_use_pool))
|
2007-06-21 14:19:56 +00:00
|
|
|
{
|
|
|
|
g_assert (timeline_pool != NULL);
|
|
|
|
clutter_timeout_pool_remove (timeline_pool, tag);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
g_source_remove (tag);
|
|
|
|
}
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2008-03-18 17:50:45 +00:00
|
|
|
static TimelineMarker *
|
|
|
|
timeline_marker_new (const gchar *name,
|
|
|
|
guint frame_num)
|
|
|
|
{
|
|
|
|
TimelineMarker *marker = g_slice_new0 (TimelineMarker);
|
|
|
|
|
|
|
|
marker->name = g_strdup (name);
|
|
|
|
marker->quark = g_quark_from_string (marker->name);
|
|
|
|
marker->frame_num = frame_num;
|
|
|
|
|
|
|
|
return marker;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
timeline_marker_free (gpointer data)
|
|
|
|
{
|
|
|
|
if (G_LIKELY (data))
|
|
|
|
{
|
|
|
|
TimelineMarker *marker = data;
|
|
|
|
|
|
|
|
g_free (marker->name);
|
|
|
|
g_slice_free (TimelineMarker, marker);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-13 23:55:52 +00:00
|
|
|
/* Object */
|
|
|
|
|
2007-10-12 08:17:00 +00:00
|
|
|
static void
|
|
|
|
clutter_timeline_set_property (GObject *object,
|
2006-05-29 08:59:36 +00:00
|
|
|
guint prop_id,
|
2007-10-12 08:17:00 +00:00
|
|
|
const GValue *value,
|
2006-05-29 08:59:36 +00:00
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
ClutterTimeline *timeline;
|
|
|
|
ClutterTimelinePrivate *priv;
|
|
|
|
|
|
|
|
timeline = CLUTTER_TIMELINE(object);
|
|
|
|
priv = timeline->priv;
|
|
|
|
|
2007-10-12 08:17:00 +00:00
|
|
|
switch (prop_id)
|
2006-05-29 08:59:36 +00:00
|
|
|
{
|
|
|
|
case PROP_FPS:
|
2007-06-07 10:26:18 +00:00
|
|
|
clutter_timeline_set_speed (timeline, g_value_get_uint (value));
|
2006-05-29 08:59:36 +00:00
|
|
|
break;
|
2006-11-15 23:37:53 +00:00
|
|
|
case PROP_NUM_FRAMES:
|
2007-06-07 10:26:18 +00:00
|
|
|
priv->n_frames = g_value_get_uint (value);
|
2006-05-29 08:59:36 +00:00
|
|
|
break;
|
|
|
|
case PROP_LOOP:
|
|
|
|
priv->loop = g_value_get_boolean (value);
|
|
|
|
break;
|
2007-06-07 10:26:18 +00:00
|
|
|
case PROP_DELAY:
|
|
|
|
priv->delay = g_value_get_uint (value);
|
|
|
|
break;
|
2007-10-16 13:41:34 +00:00
|
|
|
case PROP_DURATION:
|
|
|
|
clutter_timeline_set_duration (timeline, g_value_get_uint (value));
|
|
|
|
break;
|
2007-11-15 17:03:55 +00:00
|
|
|
case PROP_DIRECTION:
|
|
|
|
clutter_timeline_set_direction (timeline, g_value_get_enum (value));
|
|
|
|
break;
|
2006-05-29 08:59:36 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
2008-03-18 17:50:45 +00:00
|
|
|
}
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
|
|
|
|
2007-10-12 08:17:00 +00:00
|
|
|
static void
|
|
|
|
clutter_timeline_get_property (GObject *object,
|
2006-05-29 08:59:36 +00:00
|
|
|
guint prop_id,
|
2007-10-12 08:17:00 +00:00
|
|
|
GValue *value,
|
2006-05-29 08:59:36 +00:00
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
ClutterTimeline *timeline;
|
|
|
|
ClutterTimelinePrivate *priv;
|
|
|
|
|
|
|
|
timeline = CLUTTER_TIMELINE(object);
|
|
|
|
priv = timeline->priv;
|
|
|
|
|
2007-10-12 08:17:00 +00:00
|
|
|
switch (prop_id)
|
2006-05-29 08:59:36 +00:00
|
|
|
{
|
|
|
|
case PROP_FPS:
|
2007-06-07 10:26:18 +00:00
|
|
|
g_value_set_uint (value, priv->fps);
|
2006-05-29 08:59:36 +00:00
|
|
|
break;
|
2006-11-15 23:37:53 +00:00
|
|
|
case PROP_NUM_FRAMES:
|
2007-06-07 10:26:18 +00:00
|
|
|
g_value_set_uint (value, priv->n_frames);
|
2006-05-29 08:59:36 +00:00
|
|
|
break;
|
|
|
|
case PROP_LOOP:
|
|
|
|
g_value_set_boolean (value, priv->loop);
|
|
|
|
break;
|
2007-06-07 10:26:18 +00:00
|
|
|
case PROP_DELAY:
|
|
|
|
g_value_set_uint (value, priv->delay);
|
|
|
|
break;
|
2007-10-16 13:41:34 +00:00
|
|
|
case PROP_DURATION:
|
|
|
|
g_value_set_uint (value, priv->duration);
|
|
|
|
break;
|
2007-11-15 17:03:55 +00:00
|
|
|
case PROP_DIRECTION:
|
|
|
|
g_value_set_enum (value, priv->direction);
|
|
|
|
break;
|
2006-05-29 08:59:36 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-12 08:17:00 +00:00
|
|
|
static void
|
2006-05-29 08:59:36 +00:00
|
|
|
clutter_timeline_finalize (GObject *object)
|
|
|
|
{
|
2008-03-18 17:50:45 +00:00
|
|
|
ClutterTimelinePrivate *priv = CLUTTER_TIMELINE (object)->priv;
|
|
|
|
|
|
|
|
g_hash_table_destroy (priv->markers_by_frame);
|
|
|
|
g_hash_table_destroy (priv->markers_by_name);
|
|
|
|
|
2006-05-29 08:59:36 +00:00
|
|
|
G_OBJECT_CLASS (clutter_timeline_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2007-10-12 08:17:00 +00:00
|
|
|
static void
|
2006-05-29 08:59:36 +00:00
|
|
|
clutter_timeline_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
ClutterTimeline *self = CLUTTER_TIMELINE(object);
|
|
|
|
ClutterTimelinePrivate *priv;
|
|
|
|
|
|
|
|
priv = self->priv;
|
|
|
|
|
2007-06-07 10:26:18 +00:00
|
|
|
if (priv->delay_id)
|
2006-05-29 08:59:36 +00:00
|
|
|
{
|
2007-06-21 14:19:56 +00:00
|
|
|
timeout_remove (priv->delay_id);
|
2007-06-07 10:26:18 +00:00
|
|
|
priv->delay_id = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->timeout_id)
|
|
|
|
{
|
2007-06-21 14:19:56 +00:00
|
|
|
timeout_remove (priv->timeout_id);
|
2007-06-07 10:26:18 +00:00
|
|
|
priv->timeout_id = 0;
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (clutter_timeline_parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_timeline_class_init (ClutterTimelineClass *klass)
|
|
|
|
{
|
2007-06-09 13:20:00 +00:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2007-06-21 14:19:56 +00:00
|
|
|
timeline_pool_init ();
|
2006-05-29 08:59:36 +00:00
|
|
|
|
|
|
|
object_class->set_property = clutter_timeline_set_property;
|
|
|
|
object_class->get_property = clutter_timeline_get_property;
|
|
|
|
object_class->finalize = clutter_timeline_finalize;
|
|
|
|
object_class->dispose = clutter_timeline_dispose;
|
|
|
|
|
|
|
|
g_type_class_add_private (klass, sizeof (ClutterTimelinePrivate));
|
|
|
|
|
2007-06-07 10:26:18 +00:00
|
|
|
/**
|
|
|
|
* ClutterTimeline:fps:
|
|
|
|
*
|
|
|
|
* Timeline frames per second. Because of the nature of the main
|
|
|
|
* loop used by Clutter this is to be considered a best approximation.
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_FPS,
|
|
|
|
g_param_spec_uint ("fps",
|
|
|
|
"Frames Per Second",
|
|
|
|
"Timeline frames per second",
|
2007-07-26 11:28:25 +00:00
|
|
|
1, 1000,
|
2007-10-16 13:41:34 +00:00
|
|
|
60,
|
|
|
|
CLUTTER_PARAM_READWRITE));
|
2007-06-07 10:26:18 +00:00
|
|
|
/**
|
|
|
|
* ClutterTimeline:num-frames:
|
|
|
|
*
|
|
|
|
* Total number of frames for the timeline.
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_NUM_FRAMES,
|
|
|
|
g_param_spec_uint ("num-frames",
|
|
|
|
"Total number of frames",
|
|
|
|
"Timelines total number of frames",
|
2007-07-26 11:28:25 +00:00
|
|
|
1, G_MAXUINT,
|
|
|
|
1,
|
2007-10-16 13:41:34 +00:00
|
|
|
CLUTTER_PARAM_READWRITE));
|
2007-06-07 10:26:18 +00:00
|
|
|
/**
|
|
|
|
* ClutterTimeline:loop:
|
|
|
|
*
|
|
|
|
* Whether the timeline should automatically rewind and restart.
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_LOOP,
|
|
|
|
g_param_spec_boolean ("loop",
|
|
|
|
"Loop",
|
|
|
|
"Should the timeline automatically restart",
|
|
|
|
FALSE,
|
2007-10-16 13:41:34 +00:00
|
|
|
CLUTTER_PARAM_READWRITE));
|
2007-06-07 10:26:18 +00:00
|
|
|
/**
|
|
|
|
* ClutterTimeline:delay:
|
|
|
|
*
|
|
|
|
* A delay, in milliseconds, that should be observed by the
|
|
|
|
* timeline before actually starting.
|
|
|
|
*
|
|
|
|
* Since: 0.4
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_DELAY,
|
|
|
|
g_param_spec_uint ("delay",
|
|
|
|
"Delay",
|
|
|
|
"Delay before start",
|
|
|
|
0, G_MAXUINT,
|
|
|
|
0,
|
2007-10-16 13:41:34 +00:00
|
|
|
CLUTTER_PARAM_READWRITE));
|
|
|
|
/**
|
|
|
|
* ClutterTimeline:duration:
|
|
|
|
*
|
|
|
|
* Duration of the timeline in milliseconds, depending on the
|
|
|
|
* ClutterTimeline:fps value.
|
|
|
|
*
|
|
|
|
* Since: 0.6
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_DURATION,
|
|
|
|
g_param_spec_uint ("duration",
|
|
|
|
"Duration",
|
|
|
|
"Duration of the timeline in milliseconds",
|
|
|
|
0, G_MAXUINT,
|
|
|
|
1000,
|
|
|
|
CLUTTER_PARAM_READWRITE));
|
2007-11-15 17:03:55 +00:00
|
|
|
/**
|
|
|
|
* ClutterTimeline:direction:
|
|
|
|
*
|
|
|
|
* The direction of the timeline, either %CLUTTER_TIMELINE_FORWARD or
|
|
|
|
* %CLUTTER_TIMELINE_BACKWARD.
|
|
|
|
*
|
|
|
|
* Since: 0.6
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_DIRECTION,
|
|
|
|
g_param_spec_enum ("direction",
|
|
|
|
"Direction",
|
|
|
|
"Direction of the timeline",
|
|
|
|
CLUTTER_TYPE_TIMELINE_DIRECTION,
|
|
|
|
CLUTTER_TIMELINE_FORWARD,
|
|
|
|
CLUTTER_PARAM_READWRITE));
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2006-12-13 18:12:09 +00:00
|
|
|
/**
|
|
|
|
* ClutterTimeline::new-frame:
|
|
|
|
* @timeline: the timeline which received the signal
|
2008-02-02 23:39:53 +00:00
|
|
|
* @frame_num: the number of the new frame between 0 and
|
|
|
|
* ClutterTimeline:num-frames
|
2006-12-13 18:12:09 +00:00
|
|
|
*
|
|
|
|
* The ::new-frame signal is emitted each time a new frame in the
|
|
|
|
* timeline is reached.
|
|
|
|
*/
|
2006-11-15 23:37:53 +00:00
|
|
|
timeline_signals[NEW_FRAME] =
|
2006-05-29 08:59:36 +00:00
|
|
|
g_signal_new ("new-frame",
|
|
|
|
G_TYPE_FROM_CLASS (object_class),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (ClutterTimelineClass, new_frame),
|
|
|
|
NULL, NULL,
|
2006-06-22 12:05:51 +00:00
|
|
|
clutter_marshal_VOID__INT,
|
2007-10-12 08:17:00 +00:00
|
|
|
G_TYPE_NONE,
|
2006-05-29 08:59:36 +00:00
|
|
|
1, G_TYPE_INT);
|
2007-07-01 16:44:24 +00:00
|
|
|
/**
|
|
|
|
* ClutterTimeline::completed:
|
|
|
|
* @timeline: the #ClutterTimeline which received the signal
|
|
|
|
*
|
|
|
|
* The ::completed signal is emitted when the timeline reaches the
|
|
|
|
* number of frames specified by the ClutterTimeline:num-frames property.
|
|
|
|
*/
|
2006-11-15 23:37:53 +00:00
|
|
|
timeline_signals[COMPLETED] =
|
2006-05-29 08:59:36 +00:00
|
|
|
g_signal_new ("completed",
|
|
|
|
G_TYPE_FROM_CLASS (object_class),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (ClutterTimelineClass, completed),
|
|
|
|
NULL, NULL,
|
2006-06-22 12:05:51 +00:00
|
|
|
clutter_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
2007-07-01 16:44:24 +00:00
|
|
|
/**
|
|
|
|
* ClutterTimeline::started:
|
|
|
|
* @timeline: the #ClutterTimeline which received the signal
|
|
|
|
*
|
|
|
|
* The ::started signal is emitted when the timeline starts its run.
|
|
|
|
* This might be as soon as clutter_timeline_start() is invoked or
|
|
|
|
* after the delay set in the ClutterTimeline:delay property has
|
|
|
|
* expired.
|
|
|
|
*/
|
2006-11-15 23:37:53 +00:00
|
|
|
timeline_signals[STARTED] =
|
2006-06-22 12:05:51 +00:00
|
|
|
g_signal_new ("started",
|
|
|
|
G_TYPE_FROM_CLASS (object_class),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (ClutterTimelineClass, started),
|
|
|
|
NULL, NULL,
|
|
|
|
clutter_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
2007-07-01 16:44:24 +00:00
|
|
|
/**
|
|
|
|
* ClutterTimeline::paused:
|
|
|
|
* @timeline: the #ClutterTimeline which received the signal
|
|
|
|
*
|
|
|
|
* The ::paused signal is emitted when clutter_timeline_pause() is invoked.
|
|
|
|
*/
|
2006-11-15 23:37:53 +00:00
|
|
|
timeline_signals[PAUSED] =
|
2006-06-22 12:05:51 +00:00
|
|
|
g_signal_new ("paused",
|
|
|
|
G_TYPE_FROM_CLASS (object_class),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (ClutterTimelineClass, paused),
|
|
|
|
NULL, NULL,
|
|
|
|
clutter_marshal_VOID__VOID,
|
2006-05-29 08:59:36 +00:00
|
|
|
G_TYPE_NONE, 0);
|
2008-03-18 17:50:45 +00:00
|
|
|
/**
|
|
|
|
* ClutterTimeline::marker-reached:
|
|
|
|
* @timeline: the #ClutterTimeline which received the signal
|
|
|
|
* @marker_name: the name of the marker reached
|
|
|
|
* @frame_num: the frame number
|
|
|
|
*
|
|
|
|
* The ::marker-reached signal is emitted each time a timeline
|
|
|
|
* reaches a marker set with clutter_timeline_add_marker_at_frame()
|
|
|
|
* or clutter_timeline_add_marker_at_time(). This signal is
|
|
|
|
* detailed with the name of the marker as well, so it is
|
|
|
|
* possible to connect a callback to the ::marker-reached signal
|
|
|
|
* for a specific marker with:
|
|
|
|
*
|
|
|
|
* <informalexample><programlisting>
|
|
|
|
* clutter_timeline_add_marker_at_frame (timeline, "foo", 24);
|
|
|
|
* clutter_timeline_add_marker_at_frame (timeline, "bar", 48);
|
|
|
|
*
|
|
|
|
* g_signal_connect (timeline, "marker-reached",
|
|
|
|
* G_CALLBACK (each_marker_reached), NULL);
|
|
|
|
* g_signal_connect (timeline, "marker-reached::foo",
|
|
|
|
* G_CALLBACK (foo_marker_reached), NULL);
|
|
|
|
* g_signal_connect (timeline, "marker-reached::bar",
|
|
|
|
* G_CALLBACK (bar_marker_reached), NULL);
|
|
|
|
* </programlisting></informalexample>
|
|
|
|
*
|
|
|
|
* In the example, the first callback will be invoked for both
|
|
|
|
* the "foo" and "bar" marker, while the second and third callbacks
|
|
|
|
* will be invoked for the "foo" or "bar" markers, respectively.
|
|
|
|
*
|
|
|
|
* Since: 0.8
|
|
|
|
*/
|
|
|
|
timeline_signals[MARKER_REACHED] =
|
|
|
|
g_signal_new ("marker-reached",
|
|
|
|
G_TYPE_FROM_CLASS (object_class),
|
|
|
|
G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
|
|
|
|
G_STRUCT_OFFSET (ClutterTimelineClass, marker_reached),
|
|
|
|
NULL, NULL,
|
|
|
|
clutter_marshal_VOID__STRING_UINT,
|
|
|
|
G_TYPE_NONE, 2,
|
|
|
|
G_TYPE_STRING,
|
|
|
|
G_TYPE_UINT);
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_timeline_init (ClutterTimeline *self)
|
|
|
|
{
|
2008-03-18 17:50:45 +00:00
|
|
|
ClutterTimelinePrivate *priv;
|
2007-10-16 13:41:34 +00:00
|
|
|
|
2008-03-18 17:50:45 +00:00
|
|
|
self->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
|
|
|
|
CLUTTER_TYPE_TIMELINE,
|
|
|
|
ClutterTimelinePrivate);
|
|
|
|
|
|
|
|
priv->fps = clutter_get_default_frame_rate ();
|
|
|
|
priv->n_frames = 0;
|
|
|
|
priv->msecs_delta = 0;
|
|
|
|
|
|
|
|
priv->markers_by_frame = g_hash_table_new (NULL, NULL);
|
|
|
|
priv->markers_by_name = g_hash_table_new_full (g_str_hash, g_str_equal,
|
|
|
|
NULL,
|
|
|
|
timeline_marker_free);
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
timeline_timeout_func (gpointer data)
|
|
|
|
{
|
2007-06-07 10:26:18 +00:00
|
|
|
ClutterTimeline *timeline = data;
|
2006-05-29 08:59:36 +00:00
|
|
|
ClutterTimelinePrivate *priv;
|
|
|
|
GTimeVal timeval;
|
2008-03-07 01:00:00 +00:00
|
|
|
guint n_frames;
|
2006-05-29 08:59:36 +00:00
|
|
|
gulong msecs;
|
|
|
|
|
|
|
|
priv = timeline->priv;
|
|
|
|
|
2007-08-19 19:09:20 +00:00
|
|
|
g_object_ref (timeline);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2006-05-29 08:59:36 +00:00
|
|
|
/* Figure out potential frame skips */
|
|
|
|
g_get_current_time (&timeval);
|
|
|
|
|
2007-08-19 19:09:20 +00:00
|
|
|
CLUTTER_TIMESTAMP (SCHEDULER, "Timeline [%p] activated (cur: %d)\n",
|
|
|
|
timeline,
|
|
|
|
priv->current_frame_num);
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2008-03-07 01:00:00 +00:00
|
|
|
if (!priv->prev_frame_timeval.tv_sec)
|
2006-05-29 08:59:36 +00:00
|
|
|
{
|
2008-03-07 01:00:00 +00:00
|
|
|
CLUTTER_NOTE (SCHEDULER,
|
|
|
|
"Timeline [%p] recieved timeout before being initialised!",
|
|
|
|
timeline);
|
|
|
|
priv->prev_frame_timeval = timeval;
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2008-03-07 01:00:00 +00:00
|
|
|
/* Interpolate the current frame based on the timeval of the
|
|
|
|
* previous frame */
|
|
|
|
msecs = (timeval.tv_sec - priv->prev_frame_timeval.tv_sec) * 1000;
|
2008-03-18 17:50:45 +00:00
|
|
|
msecs += (timeval.tv_usec - priv->prev_frame_timeval.tv_usec) / 1000;
|
2008-03-07 01:00:00 +00:00
|
|
|
priv->msecs_delta = msecs;
|
|
|
|
n_frames = msecs / (1000 / priv->fps);
|
|
|
|
if (n_frames == 0)
|
2008-03-18 17:50:45 +00:00
|
|
|
n_frames = 1;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2008-03-07 01:00:00 +00:00
|
|
|
priv->skipped_frames = n_frames - 1;
|
|
|
|
|
|
|
|
if (priv->skipped_frames)
|
2008-03-18 17:50:45 +00:00
|
|
|
CLUTTER_TIMESTAMP (SCHEDULER,
|
|
|
|
"Timeline [%p], skipping %d frames\n",
|
|
|
|
timeline,
|
|
|
|
priv->skipped_frames);
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2008-03-07 01:00:00 +00:00
|
|
|
priv->prev_frame_timeval = timeval;
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2006-08-15 20:28:41 +00:00
|
|
|
/* Advance frames */
|
2007-11-15 17:03:55 +00:00
|
|
|
if (priv->direction == CLUTTER_TIMELINE_FORWARD)
|
|
|
|
priv->current_frame_num += n_frames;
|
|
|
|
else
|
|
|
|
priv->current_frame_num -= n_frames;
|
2006-08-15 20:28:41 +00:00
|
|
|
|
2008-03-07 01:00:00 +00:00
|
|
|
/* If we have not reached the end of the timeline: */
|
|
|
|
if (!(
|
|
|
|
((priv->direction == CLUTTER_TIMELINE_FORWARD) &&
|
|
|
|
(priv->current_frame_num >= priv->n_frames)) ||
|
2007-11-15 17:03:55 +00:00
|
|
|
((priv->direction == CLUTTER_TIMELINE_BACKWARD) &&
|
2008-03-07 01:00:00 +00:00
|
|
|
(priv->current_frame_num <= 0))
|
|
|
|
))
|
2006-05-29 08:59:36 +00:00
|
|
|
{
|
2008-03-18 17:50:45 +00:00
|
|
|
gint i;
|
|
|
|
|
2008-03-07 01:00:00 +00:00
|
|
|
/* Fire off signal */
|
2008-03-18 17:50:45 +00:00
|
|
|
g_signal_emit (timeline, timeline_signals[NEW_FRAME], 0,
|
|
|
|
priv->current_frame_num);
|
|
|
|
|
|
|
|
for (i = priv->skipped_frames; i >= 0; i--)
|
|
|
|
{
|
|
|
|
gint frame_num = priv->current_frame_num - i;
|
|
|
|
GSList *markers, *l;
|
|
|
|
|
|
|
|
markers = g_hash_table_lookup (priv->markers_by_frame,
|
|
|
|
GUINT_TO_POINTER (frame_num));
|
|
|
|
for (l = markers; l; l = l->next)
|
|
|
|
{
|
|
|
|
TimelineMarker *marker = l->data;
|
|
|
|
|
|
|
|
CLUTTER_NOTE (SCHEDULER, "Marker `%s' reached", marker->name);
|
|
|
|
|
|
|
|
g_signal_emit (timeline, timeline_signals[MARKER_REACHED],
|
|
|
|
marker->quark,
|
|
|
|
marker->name,
|
|
|
|
marker->frame_num);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-07 01:00:00 +00:00
|
|
|
/* Signal pauses timeline ? */
|
|
|
|
if (!priv->timeout_id)
|
|
|
|
{
|
|
|
|
g_object_unref (timeline);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (timeline);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2008-03-18 17:50:45 +00:00
|
|
|
else
|
2008-03-07 01:00:00 +00:00
|
|
|
{
|
2008-03-18 17:50:45 +00:00
|
|
|
/* Handle loop or stop */
|
2008-03-07 01:00:00 +00:00
|
|
|
ClutterTimelineDirection saved_direction = priv->direction;
|
|
|
|
guint overflow_frame_num = priv->current_frame_num;
|
|
|
|
gint end_frame;
|
|
|
|
|
|
|
|
/* In case the signal handlers want to take a peek... */
|
2007-11-15 17:03:55 +00:00
|
|
|
if (priv->direction == CLUTTER_TIMELINE_FORWARD)
|
2008-03-18 17:50:45 +00:00
|
|
|
priv->current_frame_num = priv->n_frames;
|
2007-11-19 15:25:56 +00:00
|
|
|
else if (priv->direction == CLUTTER_TIMELINE_BACKWARD)
|
2008-03-18 17:50:45 +00:00
|
|
|
priv->current_frame_num = 0;
|
|
|
|
|
2008-03-07 01:00:00 +00:00
|
|
|
end_frame = priv->current_frame_num;
|
|
|
|
|
|
|
|
/* Fire off signal */
|
2008-03-18 17:50:45 +00:00
|
|
|
g_signal_emit (timeline, timeline_signals[NEW_FRAME], 0,
|
|
|
|
priv->current_frame_num);
|
2008-03-07 01:00:00 +00:00
|
|
|
|
|
|
|
/* Did the signal handler modify the current_frame_num */
|
|
|
|
if (priv->current_frame_num != end_frame)
|
|
|
|
{
|
|
|
|
g_object_unref (timeline);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Note: If the new-frame signal handler paused the timeline
|
|
|
|
* on the last frame we will still go ahead and send the
|
|
|
|
* completed signal */
|
2007-11-19 15:25:56 +00:00
|
|
|
CLUTTER_NOTE (SCHEDULER,
|
2008-01-14 12:02:28 +00:00
|
|
|
"Timeline [%p] completed (cur: %d, tot: %d, drop: %d)",
|
2007-11-19 15:25:56 +00:00
|
|
|
timeline,
|
|
|
|
priv->current_frame_num,
|
|
|
|
priv->n_frames,
|
2008-01-14 12:02:28 +00:00
|
|
|
n_frames - 1);
|
2007-11-19 15:25:56 +00:00
|
|
|
|
2008-03-07 01:00:00 +00:00
|
|
|
if (!priv->loop && priv->timeout_id)
|
|
|
|
{
|
|
|
|
/* We remove the timeout now, so that the completed signal handler
|
|
|
|
* may choose to re-start the timeline
|
|
|
|
*
|
|
|
|
* ** Perhaps we should remove this earlier, and regardless
|
|
|
|
* of priv->loop. Are we limiting the things that could be done in
|
|
|
|
* the above new-frame signal handler */
|
|
|
|
timeout_remove (priv->timeout_id);
|
|
|
|
priv->timeout_id = 0;
|
|
|
|
}
|
2008-03-18 17:50:45 +00:00
|
|
|
|
2008-03-07 01:00:00 +00:00
|
|
|
g_signal_emit (timeline, timeline_signals[COMPLETED], 0);
|
|
|
|
|
|
|
|
/* Again check to see if the user has manually played with
|
|
|
|
* current_frame_num, before we finally stop or loop the timeline */
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2008-03-07 01:00:00 +00:00
|
|
|
if (priv->current_frame_num != end_frame &&
|
|
|
|
!(/* Except allow moving from frame 0 -> n_frame (or vica-versa)
|
|
|
|
since these are considered equivalent */
|
|
|
|
(priv->current_frame_num == 0 && end_frame == priv->n_frames) ||
|
|
|
|
(priv->current_frame_num == priv->n_frames && end_frame == 0)
|
|
|
|
))
|
|
|
|
{
|
|
|
|
g_object_unref (timeline);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2007-08-19 19:09:20 +00:00
|
|
|
|
2008-03-07 01:00:00 +00:00
|
|
|
if (priv->loop)
|
|
|
|
{
|
|
|
|
/* We try and interpolate smoothly around a loop */
|
|
|
|
if (saved_direction == CLUTTER_TIMELINE_FORWARD)
|
|
|
|
priv->current_frame_num = overflow_frame_num - priv->n_frames;
|
|
|
|
else
|
|
|
|
priv->current_frame_num = priv->n_frames + overflow_frame_num;
|
|
|
|
|
|
|
|
/* Or if the direction changed, we try and bounce */
|
|
|
|
if (priv->direction != saved_direction)
|
2008-03-18 17:50:45 +00:00
|
|
|
{
|
|
|
|
priv->current_frame_num = priv->n_frames
|
|
|
|
- priv->current_frame_num;
|
|
|
|
}
|
2008-03-07 01:00:00 +00:00
|
|
|
|
|
|
|
g_object_unref (timeline);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2006-05-29 08:59:36 +00:00
|
|
|
else
|
2008-03-07 01:00:00 +00:00
|
|
|
{
|
|
|
|
clutter_timeline_rewind (timeline);
|
2008-03-18 17:50:45 +00:00
|
|
|
|
2008-03-07 01:00:00 +00:00
|
|
|
priv->prev_frame_timeval.tv_sec = 0;
|
|
|
|
priv->prev_frame_timeval.tv_usec = 0;
|
2008-03-18 17:50:45 +00:00
|
|
|
|
2008-03-07 01:00:00 +00:00
|
|
|
g_object_unref (timeline);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-08-19 19:09:20 +00:00
|
|
|
|
2008-03-07 01:00:00 +00:00
|
|
|
static guint
|
|
|
|
timeline_timeout_add (ClutterTimeline *timeline,
|
|
|
|
guint interval,
|
|
|
|
GSourceFunc func,
|
|
|
|
gpointer data,
|
|
|
|
GDestroyNotify notify)
|
|
|
|
{
|
|
|
|
ClutterTimelinePrivate *priv;
|
|
|
|
GTimeVal timeval;
|
2007-08-19 19:09:20 +00:00
|
|
|
|
2008-03-07 01:00:00 +00:00
|
|
|
priv = timeline->priv;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2008-03-07 01:00:00 +00:00
|
|
|
if (priv->prev_frame_timeval.tv_sec == 0)
|
|
|
|
{
|
|
|
|
g_get_current_time (&timeval);
|
|
|
|
priv->prev_frame_timeval = timeval;
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
2008-03-07 01:00:00 +00:00
|
|
|
priv->skipped_frames = 0;
|
|
|
|
priv->msecs_delta = 0;
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2008-03-07 01:00:00 +00:00
|
|
|
return timeout_add (interval, func, data, notify);
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
|
|
|
|
2007-06-07 10:26:18 +00:00
|
|
|
static gboolean
|
|
|
|
delay_timeout_func (gpointer data)
|
|
|
|
{
|
|
|
|
ClutterTimeline *timeline = data;
|
|
|
|
ClutterTimelinePrivate *priv = timeline->priv;
|
|
|
|
|
|
|
|
priv->delay_id = 0;
|
|
|
|
|
2008-03-07 01:00:00 +00:00
|
|
|
priv->timeout_id = timeline_timeout_add (timeline,
|
|
|
|
FPS_TO_INTERVAL (priv->fps),
|
|
|
|
timeline_timeout_func,
|
|
|
|
timeline, NULL);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-06-07 10:26:18 +00:00
|
|
|
g_signal_emit (timeline, timeline_signals[STARTED], 0);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2006-05-29 08:59:36 +00:00
|
|
|
/**
|
|
|
|
* clutter_timeline_start:
|
|
|
|
* @timeline: A #ClutterTimeline
|
|
|
|
*
|
|
|
|
* Starts the #ClutterTimeline playing.
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
clutter_timeline_start (ClutterTimeline *timeline)
|
|
|
|
{
|
|
|
|
ClutterTimelinePrivate *priv;
|
|
|
|
|
2006-06-22 12:05:51 +00:00
|
|
|
g_return_if_fail (CLUTTER_IS_TIMELINE (timeline));
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2006-05-29 08:59:36 +00:00
|
|
|
priv = timeline->priv;
|
|
|
|
|
2007-06-07 10:26:18 +00:00
|
|
|
if (priv->delay_id || priv->timeout_id)
|
|
|
|
return;
|
|
|
|
|
2007-10-16 13:41:34 +00:00
|
|
|
if (priv->n_frames == 0)
|
|
|
|
return;
|
|
|
|
|
2007-06-07 10:26:18 +00:00
|
|
|
if (priv->delay)
|
|
|
|
{
|
2007-06-21 14:19:56 +00:00
|
|
|
priv->delay_id = timeout_add (priv->delay,
|
|
|
|
delay_timeout_func,
|
|
|
|
timeline, NULL);
|
2007-06-07 10:26:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-03-07 01:00:00 +00:00
|
|
|
priv->timeout_id = timeline_timeout_add (timeline,
|
|
|
|
FPS_TO_INTERVAL (priv->fps),
|
|
|
|
timeline_timeout_func,
|
|
|
|
timeline, NULL);
|
2007-06-09 13:20:00 +00:00
|
|
|
|
2007-06-07 10:26:18 +00:00
|
|
|
g_signal_emit (timeline, timeline_signals[STARTED], 0);
|
|
|
|
}
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_timeline_pause:
|
|
|
|
* @timeline: A #ClutterTimeline
|
|
|
|
*
|
|
|
|
* Pauses the #ClutterTimeline on current frame
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
clutter_timeline_pause (ClutterTimeline *timeline)
|
|
|
|
{
|
2007-06-07 10:26:18 +00:00
|
|
|
ClutterTimelinePrivate *priv;
|
|
|
|
|
2006-05-29 08:59:36 +00:00
|
|
|
g_return_if_fail (CLUTTER_IS_TIMELINE (timeline));
|
|
|
|
|
2007-06-07 10:26:18 +00:00
|
|
|
priv = timeline->priv;
|
|
|
|
|
|
|
|
if (priv->delay_id)
|
|
|
|
{
|
2007-06-21 14:19:56 +00:00
|
|
|
timeout_remove (priv->delay_id);
|
2007-06-07 10:26:18 +00:00
|
|
|
priv->delay_id = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->timeout_id)
|
|
|
|
{
|
2007-06-21 14:19:56 +00:00
|
|
|
timeout_remove (priv->timeout_id);
|
2007-06-07 10:26:18 +00:00
|
|
|
priv->timeout_id = 0;
|
|
|
|
}
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2008-03-07 01:00:00 +00:00
|
|
|
priv->prev_frame_timeval.tv_sec = 0;
|
|
|
|
priv->prev_frame_timeval.tv_usec = 0;
|
2006-06-22 12:05:51 +00:00
|
|
|
|
2006-11-15 23:37:53 +00:00
|
|
|
g_signal_emit (timeline, timeline_signals[PAUSED], 0);
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_timeline_stop:
|
|
|
|
* @timeline: A #ClutterTimeline
|
|
|
|
*
|
|
|
|
* Stops the #ClutterTimeline and moves to frame 0
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
clutter_timeline_stop (ClutterTimeline *timeline)
|
|
|
|
{
|
|
|
|
clutter_timeline_pause (timeline);
|
|
|
|
clutter_timeline_rewind (timeline);
|
|
|
|
}
|
|
|
|
|
2006-06-22 12:05:51 +00:00
|
|
|
/**
|
|
|
|
* clutter_timeline_set_loop:
|
|
|
|
* @timeline: a #ClutterTimeline
|
|
|
|
* @loop: %TRUE for enable looping
|
|
|
|
*
|
|
|
|
* Sets whether @timeline should loop.
|
|
|
|
*/
|
2006-05-29 08:59:36 +00:00
|
|
|
void
|
2006-06-22 12:05:51 +00:00
|
|
|
clutter_timeline_set_loop (ClutterTimeline *timeline,
|
|
|
|
gboolean loop)
|
2006-05-29 08:59:36 +00:00
|
|
|
{
|
2006-06-22 12:05:51 +00:00
|
|
|
g_return_if_fail (CLUTTER_IS_TIMELINE (timeline));
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2006-06-22 12:05:51 +00:00
|
|
|
if (timeline->priv->loop != loop)
|
|
|
|
{
|
|
|
|
timeline->priv->loop = loop;
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (timeline), "loop");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_timeline_get_loop:
|
|
|
|
* @timeline: a #ClutterTimeline
|
|
|
|
*
|
|
|
|
* Gets whether @timeline is looping
|
|
|
|
*
|
|
|
|
* Return value: %TRUE if the timeline is looping
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
clutter_timeline_get_loop (ClutterTimeline *timeline)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (CLUTTER_IS_TIMELINE (timeline), FALSE);
|
|
|
|
|
|
|
|
return timeline->priv->loop;
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_timeline_rewind:
|
|
|
|
* @timeline: A #ClutterTimeline
|
|
|
|
*
|
2008-02-04 14:35:47 +00:00
|
|
|
* Rewinds #ClutterTimeline to the first frame if its direction is
|
|
|
|
* CLUTTER_TIMELINE_FORWARD and the last frame if it is
|
|
|
|
* CLUTTER_TIMELINE_BACKWARD.
|
2006-05-29 08:59:36 +00:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
clutter_timeline_rewind (ClutterTimeline *timeline)
|
|
|
|
{
|
2007-11-15 17:03:55 +00:00
|
|
|
ClutterTimelinePrivate *priv;
|
|
|
|
|
2006-06-22 12:05:51 +00:00
|
|
|
g_return_if_fail (CLUTTER_IS_TIMELINE (timeline));
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-11-15 17:03:55 +00:00
|
|
|
priv = timeline->priv;
|
|
|
|
|
|
|
|
if (priv->direction == CLUTTER_TIMELINE_FORWARD)
|
|
|
|
clutter_timeline_advance (timeline, 0);
|
|
|
|
else if (priv->direction == CLUTTER_TIMELINE_BACKWARD)
|
|
|
|
clutter_timeline_advance (timeline, priv->n_frames);
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-06-22 13:56:04 +00:00
|
|
|
* clutter_timeline_skip:
|
2006-05-29 08:59:36 +00:00
|
|
|
* @timeline: A #ClutterTimeline
|
2006-11-15 23:37:53 +00:00
|
|
|
* @n_frames: Number of frames to skip
|
2006-05-29 08:59:36 +00:00
|
|
|
*
|
|
|
|
* Advance timeline by requested number of frames.
|
|
|
|
**/
|
|
|
|
void
|
2006-11-15 23:37:53 +00:00
|
|
|
clutter_timeline_skip (ClutterTimeline *timeline,
|
|
|
|
guint n_frames)
|
2006-05-29 08:59:36 +00:00
|
|
|
{
|
|
|
|
ClutterTimelinePrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (CLUTTER_IS_TIMELINE (timeline));
|
|
|
|
|
|
|
|
priv = timeline->priv;
|
|
|
|
|
2007-11-15 17:03:55 +00:00
|
|
|
if (priv->direction == CLUTTER_TIMELINE_FORWARD)
|
|
|
|
{
|
|
|
|
priv->current_frame_num += n_frames;
|
|
|
|
|
|
|
|
if (priv->current_frame_num > priv->n_frames)
|
|
|
|
priv->current_frame_num = 1;
|
|
|
|
}
|
|
|
|
else if (priv->direction == CLUTTER_TIMELINE_BACKWARD)
|
|
|
|
{
|
|
|
|
priv->current_frame_num -= n_frames;
|
|
|
|
|
|
|
|
if (priv->current_frame_num < 1)
|
|
|
|
priv->current_frame_num = priv->n_frames - 1;
|
|
|
|
}
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_timeline_advance:
|
|
|
|
* @timeline: A #ClutterTimeline
|
|
|
|
* @frame_num: Frame number to advance to
|
|
|
|
*
|
|
|
|
* Advance timeline to requested frame number
|
|
|
|
**/
|
|
|
|
void
|
2006-11-15 23:37:53 +00:00
|
|
|
clutter_timeline_advance (ClutterTimeline *timeline,
|
|
|
|
guint frame_num)
|
2006-05-29 08:59:36 +00:00
|
|
|
{
|
|
|
|
ClutterTimelinePrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (CLUTTER_IS_TIMELINE (timeline));
|
|
|
|
|
|
|
|
priv = timeline->priv;
|
|
|
|
|
2007-11-15 17:03:55 +00:00
|
|
|
priv->current_frame_num = CLAMP (frame_num, 0, priv->n_frames);
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_timeline_get_current_frame:
|
|
|
|
* @timeline: A #ClutterTimeline
|
|
|
|
*
|
|
|
|
* Request the current frame number of the timeline.
|
|
|
|
*
|
|
|
|
* Return Value: current frame number
|
|
|
|
**/
|
|
|
|
gint
|
|
|
|
clutter_timeline_get_current_frame (ClutterTimeline *timeline)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (CLUTTER_IS_TIMELINE (timeline), 0);
|
|
|
|
|
|
|
|
return timeline->priv->current_frame_num;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_timeline_get_n_frames:
|
|
|
|
* @timeline: A #ClutterTimeline
|
|
|
|
*
|
2006-11-15 23:37:53 +00:00
|
|
|
* Request the total number of frames for the #ClutterTimeline.
|
2006-05-29 08:59:36 +00:00
|
|
|
*
|
|
|
|
* Return Value: Number of frames for this #ClutterTimeline.
|
|
|
|
**/
|
|
|
|
guint
|
|
|
|
clutter_timeline_get_n_frames (ClutterTimeline *timeline)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (CLUTTER_IS_TIMELINE (timeline), 0);
|
|
|
|
|
2006-11-15 23:37:53 +00:00
|
|
|
return timeline->priv->n_frames;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_timeline_set_n_frames:
|
|
|
|
* @timeline: a #ClutterTimeline
|
|
|
|
* @n_frames: the number of frames
|
|
|
|
*
|
|
|
|
* Sets the total number of frames for @timeline
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
clutter_timeline_set_n_frames (ClutterTimeline *timeline,
|
|
|
|
guint n_frames)
|
|
|
|
{
|
|
|
|
ClutterTimelinePrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (CLUTTER_IS_TIMELINE (timeline));
|
2007-07-26 11:28:30 +00:00
|
|
|
g_return_if_fail (n_frames > 0);
|
2006-11-15 23:37:53 +00:00
|
|
|
|
|
|
|
priv = timeline->priv;
|
|
|
|
|
|
|
|
if (priv->n_frames != n_frames)
|
|
|
|
{
|
|
|
|
priv->n_frames = n_frames;
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (timeline), "num-frames");
|
|
|
|
}
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-06-22 09:14:35 +00:00
|
|
|
* clutter_timeline_set_speed:
|
2006-05-29 08:59:36 +00:00
|
|
|
* @timeline: A #ClutterTimeline
|
|
|
|
* @fps: New speed of timeline as frames per second
|
|
|
|
*
|
|
|
|
* Set the speed in frames per second of the timeline.
|
|
|
|
**/
|
|
|
|
void
|
2006-11-15 23:37:53 +00:00
|
|
|
clutter_timeline_set_speed (ClutterTimeline *timeline,
|
|
|
|
guint fps)
|
2006-05-29 08:59:36 +00:00
|
|
|
{
|
|
|
|
ClutterTimelinePrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (CLUTTER_IS_TIMELINE (timeline));
|
2007-07-26 11:28:30 +00:00
|
|
|
g_return_if_fail (fps > 0);
|
2006-05-29 08:59:36 +00:00
|
|
|
|
|
|
|
priv = timeline->priv;
|
|
|
|
|
2006-11-15 23:37:53 +00:00
|
|
|
if (priv->fps != fps)
|
2006-05-29 08:59:36 +00:00
|
|
|
{
|
2006-11-15 23:37:53 +00:00
|
|
|
g_object_ref (timeline);
|
|
|
|
|
|
|
|
priv->fps = fps;
|
|
|
|
|
|
|
|
/* if the timeline is playing restart */
|
|
|
|
if (priv->timeout_id)
|
|
|
|
{
|
2007-06-21 14:19:56 +00:00
|
|
|
timeout_remove (priv->timeout_id);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2008-03-07 01:00:00 +00:00
|
|
|
priv->timeout_id = timeline_timeout_add (timeline,
|
|
|
|
FPS_TO_INTERVAL (priv->fps),
|
|
|
|
timeline_timeout_func,
|
|
|
|
timeline, NULL);
|
2006-11-15 23:37:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (timeline), "fps");
|
|
|
|
g_object_unref (timeline);
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-15 23:37:53 +00:00
|
|
|
/**
|
|
|
|
* clutter_timeline_get_speed:
|
|
|
|
* @timeline: a #ClutterTimeline
|
|
|
|
*
|
|
|
|
* Gets the frames per second played by @timeline
|
|
|
|
*
|
|
|
|
* Return value: the number of frames per second.
|
|
|
|
*/
|
|
|
|
guint
|
|
|
|
clutter_timeline_get_speed (ClutterTimeline *timeline)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (CLUTTER_IS_TIMELINE (timeline), 0);
|
|
|
|
|
|
|
|
return timeline->priv->fps;
|
|
|
|
}
|
|
|
|
|
2006-06-01 21:37:28 +00:00
|
|
|
/**
|
|
|
|
* clutter_timeline_is_playing:
|
|
|
|
* @timeline: A #ClutterTimeline
|
|
|
|
*
|
|
|
|
* Query state of a #ClutterTimeline instance.
|
|
|
|
*
|
|
|
|
* Return Value: TRUE if timeline is currently playing, FALSE if not.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
clutter_timeline_is_playing (ClutterTimeline *timeline)
|
|
|
|
{
|
2006-06-22 12:05:51 +00:00
|
|
|
g_return_val_if_fail (CLUTTER_IS_TIMELINE (timeline), FALSE);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2006-06-01 21:37:28 +00:00
|
|
|
return (timeline->priv->timeout_id != 0);
|
|
|
|
}
|
|
|
|
|
2007-05-14 09:11:23 +00:00
|
|
|
/**
|
2007-06-07 10:26:07 +00:00
|
|
|
* clutter_timeline_clone:
|
2007-05-14 09:11:23 +00:00
|
|
|
* @timeline: #ClutterTimeline to duplicate.
|
|
|
|
*
|
|
|
|
* Create a new #ClutterTimeline instance which has property values
|
2007-06-07 10:26:07 +00:00
|
|
|
* matching that of supplied timeline. The cloned timeline will not
|
|
|
|
* be started and will not be positioned to the current position of
|
|
|
|
* @timeline: you will have to start it with clutter_timeline_start().
|
2007-05-14 09:11:23 +00:00
|
|
|
*
|
2007-06-07 10:26:07 +00:00
|
|
|
* Return Value: a new #ClutterTimeline, cloned from @timeline
|
2007-05-14 09:11:23 +00:00
|
|
|
*
|
|
|
|
* Since 0.4
|
|
|
|
*/
|
2007-06-07 10:26:07 +00:00
|
|
|
ClutterTimeline *
|
|
|
|
clutter_timeline_clone (ClutterTimeline *timeline)
|
2007-05-14 09:11:23 +00:00
|
|
|
{
|
|
|
|
ClutterTimeline *copy;
|
|
|
|
|
|
|
|
g_return_val_if_fail (CLUTTER_IS_TIMELINE (timeline), NULL);
|
|
|
|
|
2007-06-07 10:26:07 +00:00
|
|
|
copy = g_object_new (CLUTTER_TYPE_TIMELINE,
|
|
|
|
"fps", clutter_timeline_get_speed (timeline),
|
|
|
|
"num-frames", clutter_timeline_get_n_frames (timeline),
|
|
|
|
"loop", clutter_timeline_get_loop (timeline),
|
2007-06-07 10:26:18 +00:00
|
|
|
"delay", clutter_timeline_get_delay (timeline),
|
2007-11-15 17:03:55 +00:00
|
|
|
"direction", clutter_timeline_get_direction (timeline),
|
2007-06-07 10:26:07 +00:00
|
|
|
NULL);
|
2007-05-14 09:11:23 +00:00
|
|
|
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
2007-10-16 13:41:34 +00:00
|
|
|
/**
|
|
|
|
* clutter_timeline_new_for_duration:
|
|
|
|
* @msecs: Duration of the timeline in milliseconds
|
|
|
|
*
|
|
|
|
* Creates a new #ClutterTimeline with a duration of @msecs using
|
|
|
|
* the value of the ClutterTimeline:fps property to compute the
|
2008-02-02 23:39:53 +00:00
|
|
|
* equivalent number of frames.
|
2007-10-16 13:41:34 +00:00
|
|
|
*
|
|
|
|
* Return value: the newly created #ClutterTimeline
|
|
|
|
*
|
|
|
|
* Since: 0.6
|
|
|
|
*/
|
|
|
|
ClutterTimeline *
|
|
|
|
clutter_timeline_new_for_duration (guint msecs)
|
|
|
|
{
|
|
|
|
return g_object_new (CLUTTER_TYPE_TIMELINE,
|
|
|
|
"duration", msecs,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2006-05-29 08:59:36 +00:00
|
|
|
/**
|
|
|
|
* clutter_timeline_new:
|
2006-11-15 23:37:53 +00:00
|
|
|
* @n_frames: the number of frames
|
|
|
|
* @fps: the number of frames per second
|
2006-05-29 08:59:36 +00:00
|
|
|
*
|
|
|
|
* Create a new #ClutterTimeline instance.
|
|
|
|
*
|
|
|
|
* Return Value: a new #ClutterTimeline
|
|
|
|
*/
|
2006-06-06 20:40:40 +00:00
|
|
|
ClutterTimeline*
|
2006-11-15 23:37:53 +00:00
|
|
|
clutter_timeline_new (guint n_frames,
|
2006-05-29 08:59:36 +00:00
|
|
|
guint fps)
|
|
|
|
{
|
2007-07-26 11:28:25 +00:00
|
|
|
g_return_val_if_fail (n_frames > 0, NULL);
|
|
|
|
g_return_val_if_fail (fps > 0, NULL);
|
|
|
|
|
2007-10-12 08:17:00 +00:00
|
|
|
return g_object_new (CLUTTER_TYPE_TIMELINE,
|
|
|
|
"fps", fps,
|
|
|
|
"num-frames", n_frames,
|
2006-05-29 08:59:36 +00:00
|
|
|
NULL);
|
|
|
|
}
|
2007-06-07 10:26:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_timeline_get_delay:
|
|
|
|
* @timeline: a #ClutterTimeline
|
|
|
|
*
|
|
|
|
* Retrieves the delay set using clutter_timeline_set_delay().
|
|
|
|
*
|
|
|
|
* Return value: the delay in milliseconds.
|
|
|
|
*
|
|
|
|
* Since: 0.4
|
|
|
|
*/
|
|
|
|
guint
|
|
|
|
clutter_timeline_get_delay (ClutterTimeline *timeline)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (CLUTTER_IS_TIMELINE (timeline), 0);
|
|
|
|
|
|
|
|
return timeline->priv->delay;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_timeline_set_delay:
|
|
|
|
* @timeline: a #ClutterTimeline
|
|
|
|
* @msecs: delay in milliseconds
|
|
|
|
*
|
|
|
|
* Sets the delay, in milliseconds, before @timeline should start.
|
|
|
|
*
|
|
|
|
* Since: 0.4
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
clutter_timeline_set_delay (ClutterTimeline *timeline,
|
|
|
|
guint msecs)
|
|
|
|
{
|
|
|
|
ClutterTimelinePrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (CLUTTER_IS_TIMELINE (timeline));
|
|
|
|
|
|
|
|
priv = timeline->priv;
|
|
|
|
|
|
|
|
if (priv->delay != msecs)
|
|
|
|
{
|
|
|
|
priv->delay = msecs;
|
|
|
|
g_object_notify (G_OBJECT (timeline), "delay");
|
|
|
|
}
|
|
|
|
}
|
2007-10-16 13:41:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_timeline_get_duration:
|
|
|
|
* @timeline: a #ClutterTimeline
|
|
|
|
*
|
|
|
|
* Retrieves the duration of a #ClutterTimeline in milliseconds.
|
|
|
|
* See clutter_timeline_set_duration().
|
|
|
|
*
|
|
|
|
* Return value: the duration of the timeline, in milliseconds.
|
|
|
|
*
|
|
|
|
* Since: 0.6
|
|
|
|
*/
|
|
|
|
guint
|
|
|
|
clutter_timeline_get_duration (ClutterTimeline *timeline)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (CLUTTER_IS_TIMELINE (timeline), 0);
|
|
|
|
|
|
|
|
return timeline->priv->duration;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_timeline_set_duration:
|
|
|
|
* @timeline: a #ClutterTimeline
|
|
|
|
* @msecs: duration of the timeline in milliseconds
|
|
|
|
*
|
|
|
|
* Sets the duration of the timeline, in milliseconds. The speed
|
|
|
|
* of the timeline depends on the ClutterTimeline:fps setting.
|
|
|
|
*
|
|
|
|
* Since: 0.6
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
clutter_timeline_set_duration (ClutterTimeline *timeline,
|
|
|
|
guint msecs)
|
|
|
|
{
|
|
|
|
ClutterTimelinePrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (CLUTTER_IS_TIMELINE (timeline));
|
|
|
|
|
|
|
|
priv = timeline->priv;
|
|
|
|
|
|
|
|
if (priv->duration != msecs)
|
|
|
|
{
|
|
|
|
g_object_ref (timeline);
|
|
|
|
|
|
|
|
g_object_freeze_notify (G_OBJECT (timeline));
|
|
|
|
|
|
|
|
priv->duration = msecs;
|
|
|
|
|
2007-10-18 13:47:21 +00:00
|
|
|
priv->n_frames = priv->duration * priv->fps / 1000;
|
2007-10-16 13:41:34 +00:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (timeline), "num-frames");
|
|
|
|
g_object_notify (G_OBJECT (timeline), "duration");
|
|
|
|
|
|
|
|
g_object_thaw_notify (G_OBJECT (timeline));
|
|
|
|
g_object_unref (timeline);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_timeline_get_progress:
|
|
|
|
* @timeline: a #ClutterTimeline
|
|
|
|
*
|
|
|
|
* The position of the timeline in a [0, 1] interval.
|
|
|
|
*
|
|
|
|
* Return value: the position of the timeline.
|
|
|
|
*
|
|
|
|
* Since: 0.6
|
|
|
|
*/
|
|
|
|
gdouble
|
|
|
|
clutter_timeline_get_progress (ClutterTimeline *timeline)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (CLUTTER_IS_TIMELINE (timeline), 0.);
|
|
|
|
|
|
|
|
return CLUTTER_FIXED_TO_DOUBLE (clutter_timeline_get_progressx (timeline));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_timeline_get_progressx:
|
|
|
|
* @timeline: a #ClutterTimeline
|
|
|
|
*
|
|
|
|
* Fixed point version of clutter_timeline_get_progress().
|
|
|
|
*
|
|
|
|
* Return value: the position of the timeline as a fixed point value
|
|
|
|
*
|
|
|
|
* Since: 0.6
|
|
|
|
*/
|
|
|
|
ClutterFixed
|
|
|
|
clutter_timeline_get_progressx (ClutterTimeline *timeline)
|
|
|
|
{
|
|
|
|
ClutterTimelinePrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (CLUTTER_IS_TIMELINE (timeline), 0);
|
|
|
|
|
|
|
|
priv = timeline->priv;
|
|
|
|
|
2007-11-15 17:03:55 +00:00
|
|
|
if (priv->direction == CLUTTER_TIMELINE_FORWARD)
|
|
|
|
return CLUTTER_FIXED_DIV (CLUTTER_INT_TO_FIXED (priv->current_frame_num),
|
|
|
|
CLUTTER_INT_TO_FIXED (priv->n_frames));
|
|
|
|
else
|
|
|
|
return CLUTTER_FIXED_DIV (CLUTTER_INT_TO_FIXED (priv->n_frames),
|
|
|
|
CLUTTER_INT_TO_FIXED (priv->current_frame_num));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_timeline_get_direction:
|
|
|
|
* @timeline: a #ClutterTimeline
|
|
|
|
*
|
|
|
|
* Retrieves the direction of the timeline set with
|
|
|
|
* clutter_timeline_set_direction().
|
|
|
|
*
|
|
|
|
* Return value: the direction of the timeline
|
|
|
|
*
|
|
|
|
* Since: 0.6
|
|
|
|
*/
|
|
|
|
ClutterTimelineDirection
|
|
|
|
clutter_timeline_get_direction (ClutterTimeline *timeline)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (CLUTTER_IS_TIMELINE (timeline), CLUTTER_TIMELINE_FORWARD);
|
|
|
|
|
|
|
|
return timeline->priv->direction;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_timeline_set_direction:
|
|
|
|
* @timeline: a #ClutterTimeline
|
|
|
|
* @direction: the direction of the timeline
|
|
|
|
*
|
|
|
|
* Sets the direction of @timeline, either %CLUTTER_TIMELINE_FORWARD or
|
|
|
|
* %CLUTTER_TIMELINE_BACKWARD.
|
|
|
|
*
|
|
|
|
* Since: 0.6
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
clutter_timeline_set_direction (ClutterTimeline *timeline,
|
|
|
|
ClutterTimelineDirection direction)
|
|
|
|
{
|
|
|
|
ClutterTimelinePrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (CLUTTER_IS_TIMELINE (timeline));
|
|
|
|
|
|
|
|
priv = timeline->priv;
|
|
|
|
|
|
|
|
if (priv->direction != direction)
|
|
|
|
{
|
|
|
|
priv->direction = direction;
|
|
|
|
|
|
|
|
if (priv->current_frame_num == 0)
|
|
|
|
priv->current_frame_num = priv->n_frames;
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (timeline), "direction");
|
|
|
|
}
|
2007-10-16 13:41:34 +00:00
|
|
|
}
|
2007-11-30 13:20:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_timeline_get_delta:
|
|
|
|
* @timeline: a #ClutterTimeline
|
|
|
|
* @msecs: return location for the milliseconds elapsed since the last
|
|
|
|
* frame, or %NULL
|
|
|
|
*
|
|
|
|
* Retrieves the number of frames and the amount of time elapsed since
|
|
|
|
* the last ClutterTimeline::new-frame signal.
|
|
|
|
*
|
|
|
|
* This function is only useful inside handlers for the ::new-frame
|
|
|
|
* signal, and its behaviour is undefined if the timeline is not
|
|
|
|
* playing.
|
|
|
|
*
|
|
|
|
* Return value: the amount of frames elapsed since the last one
|
|
|
|
*
|
|
|
|
* Since: 0.6
|
|
|
|
*/
|
|
|
|
guint
|
|
|
|
clutter_timeline_get_delta (ClutterTimeline *timeline,
|
|
|
|
guint *msecs)
|
|
|
|
{
|
|
|
|
ClutterTimelinePrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (CLUTTER_IS_TIMELINE (timeline), 0);
|
|
|
|
|
|
|
|
if (!clutter_timeline_is_playing (timeline))
|
|
|
|
{
|
|
|
|
if (msecs)
|
|
|
|
*msecs = 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv = timeline->priv;
|
|
|
|
|
|
|
|
if (msecs)
|
2008-02-01 11:22:59 +00:00
|
|
|
*msecs = timeline->priv->msecs_delta;
|
2007-11-30 13:20:15 +00:00
|
|
|
|
|
|
|
return priv->skipped_frames + 1;
|
|
|
|
}
|
2008-03-18 17:50:45 +00:00
|
|
|
|
|
|
|
static inline void
|
|
|
|
clutter_timeline_add_marker_internal (ClutterTimeline *timeline,
|
|
|
|
const gchar *marker_name,
|
|
|
|
guint frame_num)
|
|
|
|
{
|
|
|
|
ClutterTimelinePrivate *priv = timeline->priv;
|
|
|
|
TimelineMarker *marker;
|
|
|
|
GSList *markers;
|
|
|
|
|
|
|
|
marker = g_hash_table_lookup (priv->markers_by_name, marker_name);
|
|
|
|
if (G_UNLIKELY (marker))
|
|
|
|
{
|
|
|
|
g_warning ("A marker named `%s' already exists on frame %d",
|
|
|
|
marker->name,
|
|
|
|
marker->frame_num);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
marker = timeline_marker_new (marker_name, frame_num);
|
|
|
|
g_hash_table_insert (priv->markers_by_name, marker->name, marker);
|
|
|
|
|
|
|
|
markers = g_hash_table_lookup (priv->markers_by_frame,
|
|
|
|
GUINT_TO_POINTER (frame_num));
|
|
|
|
if (!markers)
|
|
|
|
{
|
|
|
|
markers = g_slist_prepend (NULL, marker);
|
|
|
|
g_hash_table_insert (priv->markers_by_frame,
|
|
|
|
GUINT_TO_POINTER (frame_num),
|
|
|
|
markers);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
markers = g_slist_prepend (markers, marker);
|
|
|
|
g_hash_table_replace (priv->markers_by_frame,
|
|
|
|
GUINT_TO_POINTER (frame_num),
|
|
|
|
markers);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_timeline_add_marker_at_frame:
|
|
|
|
* @timeline: a #ClutterTimeline
|
|
|
|
* @marker_name: the unique name for this marker
|
|
|
|
* @frame_num: the marker's frame
|
|
|
|
*
|
|
|
|
* Adds a named marker at @frame_num. Markers are unique string identifiers
|
|
|
|
* for a specific frame. Once @timeline reaches @frame_num, it will emit
|
|
|
|
* a ::marker-reached signal for each marker attached to that frame.
|
|
|
|
*
|
|
|
|
* A marker can be removed with clutter_timeline_remove_marker(). The
|
|
|
|
* timeline can be advanced to a marker using
|
|
|
|
* clutter_timeline_advance_to_marker().
|
|
|
|
*
|
|
|
|
* Since: 0.8
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
clutter_timeline_add_marker_at_frame (ClutterTimeline *timeline,
|
|
|
|
const gchar *marker_name,
|
|
|
|
guint frame_num)
|
|
|
|
{
|
|
|
|
g_return_if_fail (CLUTTER_IS_TIMELINE (timeline));
|
|
|
|
g_return_if_fail (marker_name != NULL);
|
|
|
|
g_return_if_fail (frame_num <= clutter_timeline_get_n_frames (timeline));
|
|
|
|
|
|
|
|
clutter_timeline_add_marker_internal (timeline, marker_name, frame_num);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_timeline_add_marker_at_time:
|
|
|
|
* @timeline: a #ClutterTimeline
|
|
|
|
* @marker_name: the unique name for this marker
|
|
|
|
* @msecs: position of the marker in milliseconds
|
|
|
|
*
|
|
|
|
* Time-based variant of clutter_timeline_add_marker_at_frame().
|
|
|
|
*
|
|
|
|
* Adds a named marker at @msecs.
|
|
|
|
*
|
|
|
|
* Since: 0.8
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
clutter_timeline_add_marker_at_time (ClutterTimeline *timeline,
|
|
|
|
const gchar *marker_name,
|
|
|
|
guint msecs)
|
|
|
|
{
|
|
|
|
guint frame_num;
|
|
|
|
|
|
|
|
g_return_if_fail (CLUTTER_IS_TIMELINE (timeline));
|
|
|
|
g_return_if_fail (marker_name != NULL);
|
|
|
|
g_return_if_fail (msecs <= clutter_timeline_get_duration (timeline));
|
|
|
|
|
|
|
|
frame_num = msecs * timeline->priv->fps / 1000;
|
|
|
|
|
|
|
|
clutter_timeline_add_marker_internal (timeline, marker_name, frame_num);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_timeline_list_markers:
|
|
|
|
* @timeline: a #ClutterTimeline
|
|
|
|
* @frame_num: the frame number to check, or -1
|
|
|
|
* @n_markers: the number of markers returned
|
|
|
|
*
|
|
|
|
* Retrieves the list of markers at @frame_num. If @frame_num is a
|
|
|
|
* negative integer, all the markers attached to @timeline will be
|
|
|
|
* returned.
|
|
|
|
*
|
|
|
|
* Return value: a newly allocated, %NULL terminated string array
|
|
|
|
* containing the names of the markers. Use g_strfreev() when
|
|
|
|
* done.
|
|
|
|
*
|
|
|
|
* Since: 0.8
|
|
|
|
*/
|
|
|
|
gchar **
|
|
|
|
clutter_timeline_list_markers (ClutterTimeline *timeline,
|
|
|
|
gint frame_num,
|
|
|
|
guint *n_markers)
|
|
|
|
{
|
|
|
|
ClutterTimelinePrivate *priv;
|
|
|
|
gchar **retval = NULL;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
g_return_val_if_fail (CLUTTER_IS_TIMELINE (timeline), NULL);
|
|
|
|
|
|
|
|
priv = timeline->priv;
|
|
|
|
|
|
|
|
if (frame_num < 0)
|
|
|
|
{
|
|
|
|
GList *markers, *l;
|
|
|
|
|
|
|
|
markers = g_hash_table_get_keys (priv->markers_by_name);
|
|
|
|
retval = g_new0 (gchar*, g_list_length (markers) + 1);
|
|
|
|
|
|
|
|
for (i = 0, l = markers; l != NULL; i++, l = l->next)
|
|
|
|
retval[i] = g_strdup (l->data);
|
|
|
|
|
|
|
|
g_list_free (markers);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GSList *markers, *l;
|
|
|
|
|
|
|
|
markers = g_hash_table_lookup (priv->markers_by_frame,
|
|
|
|
GUINT_TO_POINTER (frame_num));
|
|
|
|
retval = g_new0 (gchar*, g_slist_length (markers) + 1);
|
|
|
|
|
|
|
|
for (i = 0, l = markers; l != NULL; i++, l = l->next)
|
|
|
|
retval[i] = g_strdup (l->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n_markers)
|
|
|
|
*n_markers = i;
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_timeline_advance_to_marker:
|
|
|
|
* @timeline: a #ClutterTimeline
|
|
|
|
* @marker_name: the name of the marker
|
|
|
|
*
|
|
|
|
* Advances @timeline to the frame of the given @marker_name.
|
|
|
|
*
|
|
|
|
* Since: 0.8
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
clutter_timeline_advance_to_marker (ClutterTimeline *timeline,
|
|
|
|
const gchar *marker_name)
|
|
|
|
{
|
|
|
|
ClutterTimelinePrivate *priv;
|
|
|
|
TimelineMarker *marker;
|
|
|
|
|
|
|
|
g_return_if_fail (CLUTTER_IS_TIMELINE (timeline));
|
|
|
|
g_return_if_fail (marker_name != NULL);
|
|
|
|
|
|
|
|
priv = timeline->priv;
|
|
|
|
|
|
|
|
marker = g_hash_table_lookup (priv->markers_by_name, marker_name);
|
|
|
|
if (!marker)
|
|
|
|
{
|
|
|
|
g_warning ("No marker named `%s' found.", marker_name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
clutter_timeline_advance (timeline, marker->frame_num);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_timeline_remove_marker:
|
|
|
|
* @timeline: a #ClutterTimeline
|
|
|
|
* @marker_name: the name of the marker to remove
|
|
|
|
*
|
|
|
|
* Removes @marker_name, if found, from @timeline.
|
|
|
|
*
|
|
|
|
* Since: 0.8
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
clutter_timeline_remove_marker (ClutterTimeline *timeline,
|
|
|
|
const gchar *marker_name)
|
|
|
|
{
|
|
|
|
ClutterTimelinePrivate *priv;
|
|
|
|
TimelineMarker *marker;
|
|
|
|
GSList *markers;
|
|
|
|
|
|
|
|
g_return_if_fail (CLUTTER_IS_TIMELINE (timeline));
|
|
|
|
g_return_if_fail (marker_name != NULL);
|
|
|
|
|
|
|
|
priv = timeline->priv;
|
|
|
|
|
|
|
|
marker = g_hash_table_lookup (priv->markers_by_name, marker_name);
|
|
|
|
if (!marker)
|
|
|
|
{
|
|
|
|
g_warning ("No marker named `%s' found.", marker_name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remove from the list of markers at the same frame */
|
|
|
|
markers = g_hash_table_lookup (priv->markers_by_frame,
|
|
|
|
GUINT_TO_POINTER (marker->frame_num));
|
|
|
|
if (G_LIKELY (markers))
|
|
|
|
{
|
|
|
|
markers = g_slist_remove (markers, marker);
|
|
|
|
if (!markers)
|
|
|
|
{
|
|
|
|
/* no markers left, remove the slot */
|
|
|
|
g_hash_table_remove (priv->markers_by_frame,
|
|
|
|
GUINT_TO_POINTER (marker->frame_num));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
g_hash_table_replace (priv->markers_by_frame,
|
|
|
|
GUINT_TO_POINTER (marker->frame_num),
|
|
|
|
markers);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* uh-oh, dangling marker; this should never happen */
|
|
|
|
g_warning ("Dangling marker %s at frame %d",
|
|
|
|
marker->name,
|
|
|
|
marker->frame_num);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this will take care of freeing the marker as well */
|
|
|
|
g_hash_table_remove (priv->markers_by_name, marker_name);
|
|
|
|
}
|
2008-03-18 22:07:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_timeline_has_marker:
|
|
|
|
* @timeline: a #ClutterTimeline
|
|
|
|
* @marker_name: the name of the marker
|
|
|
|
*
|
|
|
|
* Checks whether @timeline has a marker set with the given name.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE if the marker was found
|
|
|
|
*
|
|
|
|
* Since: 0.8
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
clutter_timeline_has_marker (ClutterTimeline *timeline,
|
|
|
|
const gchar *marker_name)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (CLUTTER_IS_TIMELINE (timeline), FALSE);
|
|
|
|
g_return_val_if_fail (marker_name != NULL, FALSE);
|
|
|
|
|
|
|
|
return NULL != g_hash_table_lookup (timeline->priv->markers_by_name,
|
|
|
|
marker_name);
|
|
|
|
}
|