2006-05-29 04:59:36 -04: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 18:34:25 -04:00
|
|
|
/**
|
|
|
|
* SECTION:clutter-timeline
|
2007-06-21 10:19:56 -04:00
|
|
|
* @short_description: A class for based events
|
|
|
|
*
|
|
|
|
* #ClutterTimeline is a base class for managing time based events such
|
2006-06-21 18:34:25 -04:00
|
|
|
* as animations.
|
|
|
|
*
|
2007-06-21 10:19:56 -04: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.
|
2006-06-21 18:34:25 -04:00
|
|
|
*/
|
|
|
|
|
2007-10-12 04:17:00 -04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2006-11-15 18:37:53 -05:00
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2006-06-21 18:34:25 -04:00
|
|
|
|
2007-06-09 09:20:00 -04:00
|
|
|
#include "clutter-timeout-pool.h"
|
2006-05-29 04:59:36 -04:00
|
|
|
#include "clutter-timeline.h"
|
|
|
|
#include "clutter-main.h"
|
2006-06-22 08:05:51 -04: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 16:27:53 -05:00
|
|
|
#include "clutter-private.h"
|
|
|
|
#include "clutter-debug.h"
|
2006-05-29 04:59:36 -04: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 16:27:53 -05:00
|
|
|
#define FPS_TO_INTERVAL(f) (1000 / (f))
|
2007-06-21 10:19:56 -04:00
|
|
|
#define CLUTTER_TIMELINE_PRIORITY (G_PRIORITY_DEFAULT + 30)
|
2007-06-09 09:20:00 -04:00
|
|
|
|
2006-11-15 18:37:53 -05:00
|
|
|
struct _ClutterTimelinePrivate
|
2006-05-29 04:59:36 -04:00
|
|
|
{
|
2006-11-15 18:37:53 -05:00
|
|
|
guint timeout_id;
|
2007-06-07 06:26:18 -04:00
|
|
|
guint delay_id;
|
2007-10-12 04:17:00 -04:00
|
|
|
|
2006-11-15 18:37:53 -05:00
|
|
|
guint fps;
|
|
|
|
guint n_frames;
|
|
|
|
guint current_frame_num;
|
2007-06-07 06:26:18 -04:00
|
|
|
guint delay;
|
2006-11-15 18:37:53 -05:00
|
|
|
|
|
|
|
gulong last_frame_msecs;
|
|
|
|
gulong start_frame_secs;
|
|
|
|
|
|
|
|
guint loop : 1;
|
2006-05-29 04:59:36 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2007-10-12 04:17:00 -04:00
|
|
|
|
2006-05-29 04:59:36 -04:00
|
|
|
PROP_FPS,
|
2006-11-15 18:37:53 -05:00
|
|
|
PROP_NUM_FRAMES,
|
2007-06-07 06:26:18 -04:00
|
|
|
PROP_LOOP,
|
|
|
|
PROP_DELAY
|
2006-05-29 04:59:36 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2006-11-15 18:37:53 -05:00
|
|
|
NEW_FRAME,
|
|
|
|
STARTED,
|
|
|
|
PAUSED,
|
|
|
|
COMPLETED,
|
|
|
|
|
2006-05-29 04:59:36 -04:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2007-06-21 10:19:56 -04: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;
|
|
|
|
|
|
|
|
if (timeline_use_pool)
|
|
|
|
{
|
|
|
|
g_assert (timeline_pool != NULL);
|
|
|
|
res = clutter_timeout_pool_add (timeline_pool,
|
|
|
|
interval,
|
|
|
|
func, data, notify);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-08-08 06:20:14 -04:00
|
|
|
res = clutter_threads_add_timeout_full (CLUTTER_TIMELINE_PRIORITY,
|
|
|
|
interval,
|
|
|
|
func, data, notify);
|
2007-06-21 10:19:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
timeout_remove (guint tag)
|
|
|
|
{
|
|
|
|
if (timeline_use_pool)
|
|
|
|
{
|
|
|
|
g_assert (timeline_pool != NULL);
|
|
|
|
clutter_timeout_pool_remove (timeline_pool, tag);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
g_source_remove (tag);
|
|
|
|
}
|
2006-05-29 04:59:36 -04:00
|
|
|
|
2006-08-13 19:55:52 -04:00
|
|
|
/* Object */
|
|
|
|
|
2007-10-12 04:17:00 -04:00
|
|
|
static void
|
|
|
|
clutter_timeline_set_property (GObject *object,
|
2006-05-29 04:59:36 -04:00
|
|
|
guint prop_id,
|
2007-10-12 04:17:00 -04:00
|
|
|
const GValue *value,
|
2006-05-29 04:59:36 -04:00
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
ClutterTimeline *timeline;
|
|
|
|
ClutterTimelinePrivate *priv;
|
|
|
|
|
|
|
|
timeline = CLUTTER_TIMELINE(object);
|
|
|
|
priv = timeline->priv;
|
|
|
|
|
2007-10-12 04:17:00 -04:00
|
|
|
switch (prop_id)
|
2006-05-29 04:59:36 -04:00
|
|
|
{
|
|
|
|
case PROP_FPS:
|
2007-06-07 06:26:18 -04:00
|
|
|
clutter_timeline_set_speed (timeline, g_value_get_uint (value));
|
2006-05-29 04:59:36 -04:00
|
|
|
break;
|
2006-11-15 18:37:53 -05:00
|
|
|
case PROP_NUM_FRAMES:
|
2007-06-07 06:26:18 -04:00
|
|
|
priv->n_frames = g_value_get_uint (value);
|
2006-05-29 04:59:36 -04:00
|
|
|
break;
|
|
|
|
case PROP_LOOP:
|
|
|
|
priv->loop = g_value_get_boolean (value);
|
|
|
|
break;
|
2007-06-07 06:26:18 -04:00
|
|
|
case PROP_DELAY:
|
|
|
|
priv->delay = g_value_get_uint (value);
|
|
|
|
break;
|
2006-05-29 04:59:36 -04:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-12 04:17:00 -04:00
|
|
|
static void
|
|
|
|
clutter_timeline_get_property (GObject *object,
|
2006-05-29 04:59:36 -04:00
|
|
|
guint prop_id,
|
2007-10-12 04:17:00 -04:00
|
|
|
GValue *value,
|
2006-05-29 04:59:36 -04:00
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
ClutterTimeline *timeline;
|
|
|
|
ClutterTimelinePrivate *priv;
|
|
|
|
|
|
|
|
timeline = CLUTTER_TIMELINE(object);
|
|
|
|
priv = timeline->priv;
|
|
|
|
|
2007-10-12 04:17:00 -04:00
|
|
|
switch (prop_id)
|
2006-05-29 04:59:36 -04:00
|
|
|
{
|
|
|
|
case PROP_FPS:
|
2007-06-07 06:26:18 -04:00
|
|
|
g_value_set_uint (value, priv->fps);
|
2006-05-29 04:59:36 -04:00
|
|
|
break;
|
2006-11-15 18:37:53 -05:00
|
|
|
case PROP_NUM_FRAMES:
|
2007-06-07 06:26:18 -04:00
|
|
|
g_value_set_uint (value, priv->n_frames);
|
2006-05-29 04:59:36 -04:00
|
|
|
break;
|
|
|
|
case PROP_LOOP:
|
|
|
|
g_value_set_boolean (value, priv->loop);
|
|
|
|
break;
|
2007-06-07 06:26:18 -04:00
|
|
|
case PROP_DELAY:
|
|
|
|
g_value_set_uint (value, priv->delay);
|
|
|
|
break;
|
2006-05-29 04:59:36 -04:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-12 04:17:00 -04:00
|
|
|
static void
|
2006-05-29 04:59:36 -04:00
|
|
|
clutter_timeline_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
G_OBJECT_CLASS (clutter_timeline_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2007-10-12 04:17:00 -04:00
|
|
|
static void
|
2006-05-29 04:59:36 -04:00
|
|
|
clutter_timeline_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
ClutterTimeline *self = CLUTTER_TIMELINE(object);
|
|
|
|
ClutterTimelinePrivate *priv;
|
|
|
|
|
|
|
|
priv = self->priv;
|
|
|
|
|
2007-06-07 06:26:18 -04:00
|
|
|
if (priv->delay_id)
|
2006-05-29 04:59:36 -04:00
|
|
|
{
|
2007-06-21 10:19:56 -04:00
|
|
|
timeout_remove (priv->delay_id);
|
2007-06-07 06:26:18 -04:00
|
|
|
priv->delay_id = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->timeout_id)
|
|
|
|
{
|
2007-06-21 10:19:56 -04:00
|
|
|
timeout_remove (priv->timeout_id);
|
2007-06-07 06:26:18 -04:00
|
|
|
priv->timeout_id = 0;
|
2006-05-29 04:59:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (clutter_timeline_parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_timeline_class_init (ClutterTimelineClass *klass)
|
|
|
|
{
|
2007-06-09 09:20:00 -04:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2006-05-29 04:59:36 -04:00
|
|
|
|
2007-06-21 10:19:56 -04:00
|
|
|
timeline_pool_init ();
|
2006-05-29 04:59:36 -04: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 06:26:18 -04: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 07:28:25 -04:00
|
|
|
1, 1000,
|
2007-06-07 06:26:18 -04:00
|
|
|
50,
|
|
|
|
G_PARAM_CONSTRUCT | CLUTTER_PARAM_READWRITE));
|
|
|
|
/**
|
|
|
|
* 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 07:28:25 -04:00
|
|
|
1, G_MAXUINT,
|
|
|
|
1,
|
2007-06-07 06:26:18 -04:00
|
|
|
G_PARAM_CONSTRUCT | CLUTTER_PARAM_READWRITE));
|
|
|
|
/**
|
|
|
|
* 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,
|
|
|
|
G_PARAM_CONSTRUCT | CLUTTER_PARAM_READWRITE));
|
|
|
|
/**
|
|
|
|
* 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,
|
|
|
|
G_PARAM_CONSTRUCT | CLUTTER_PARAM_READWRITE));
|
2006-05-29 04:59:36 -04:00
|
|
|
|
2006-12-13 13:12:09 -05:00
|
|
|
/**
|
|
|
|
* ClutterTimeline::new-frame:
|
|
|
|
* @timeline: the timeline which received the signal
|
|
|
|
* @frame_num: the number of the new frame
|
|
|
|
*
|
|
|
|
* The ::new-frame signal is emitted each time a new frame in the
|
|
|
|
* timeline is reached.
|
|
|
|
*/
|
2006-11-15 18:37:53 -05:00
|
|
|
timeline_signals[NEW_FRAME] =
|
2006-05-29 04:59:36 -04: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 08:05:51 -04:00
|
|
|
clutter_marshal_VOID__INT,
|
2007-10-12 04:17:00 -04:00
|
|
|
G_TYPE_NONE,
|
2006-05-29 04:59:36 -04:00
|
|
|
1, G_TYPE_INT);
|
2007-07-01 12:44:24 -04: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 18:37:53 -05:00
|
|
|
timeline_signals[COMPLETED] =
|
2006-05-29 04:59:36 -04: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 08:05:51 -04:00
|
|
|
clutter_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
2007-07-01 12:44:24 -04: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 18:37:53 -05:00
|
|
|
timeline_signals[STARTED] =
|
2006-06-22 08:05:51 -04: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 12:44:24 -04:00
|
|
|
/**
|
|
|
|
* ClutterTimeline::paused:
|
|
|
|
* @timeline: the #ClutterTimeline which received the signal
|
|
|
|
*
|
|
|
|
* The ::paused signal is emitted when clutter_timeline_pause() is invoked.
|
|
|
|
*/
|
2006-11-15 18:37:53 -05:00
|
|
|
timeline_signals[PAUSED] =
|
2006-06-22 08:05:51 -04: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 04:59:36 -04:00
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_timeline_init (ClutterTimeline *self)
|
|
|
|
{
|
2007-06-07 06:26:18 -04:00
|
|
|
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
|
|
|
|
CLUTTER_TYPE_TIMELINE,
|
|
|
|
ClutterTimelinePrivate);
|
2006-05-29 04:59:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
timeline_timeout_func (gpointer data)
|
|
|
|
{
|
2007-06-07 06:26:18 -04:00
|
|
|
ClutterTimeline *timeline = data;
|
2006-05-29 04:59:36 -04:00
|
|
|
ClutterTimelinePrivate *priv;
|
|
|
|
GTimeVal timeval;
|
2006-11-15 18:37:53 -05:00
|
|
|
gint n_frames;
|
2006-05-29 04:59:36 -04:00
|
|
|
gulong msecs;
|
2007-08-19 15:09:20 -04:00
|
|
|
gboolean retval = TRUE;
|
2006-05-29 04:59:36 -04:00
|
|
|
|
|
|
|
priv = timeline->priv;
|
|
|
|
|
2007-08-19 15:09:20 -04:00
|
|
|
if (!timeline)
|
|
|
|
{
|
|
|
|
CLUTTER_NOTE (SCHEDULER,
|
|
|
|
"The timeline [%p] has been disposed",
|
|
|
|
timeline);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!priv->timeout_id)
|
|
|
|
{
|
|
|
|
CLUTTER_NOTE (SCHEDULER,
|
|
|
|
"The timeline [%p] has been removed",
|
|
|
|
timeline);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
2007-06-07 19:51:53 -04:00
|
|
|
|
2007-08-19 15:09:20 -04:00
|
|
|
g_object_ref (timeline);
|
2007-10-12 04:17:00 -04:00
|
|
|
|
2006-05-29 04:59:36 -04:00
|
|
|
/* Figure out potential frame skips */
|
|
|
|
g_get_current_time (&timeval);
|
|
|
|
|
2007-08-19 15:09:20 -04:00
|
|
|
CLUTTER_TIMESTAMP (SCHEDULER, "Timeline [%p] activated (cur: %d)\n",
|
|
|
|
timeline,
|
|
|
|
priv->current_frame_num);
|
2006-05-29 04:59:36 -04:00
|
|
|
|
2007-08-19 15:09:20 -04:00
|
|
|
/* Fire off signal */
|
|
|
|
g_signal_emit (timeline, timeline_signals[NEW_FRAME], 0,
|
|
|
|
priv->current_frame_num);
|
2006-05-29 04:59:36 -04:00
|
|
|
|
|
|
|
/* Signal removes source ? */
|
|
|
|
if (!priv->timeout_id)
|
|
|
|
{
|
2007-08-19 15:09:20 -04:00
|
|
|
g_object_unref (timeline);
|
2006-05-29 04:59:36 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
2007-10-12 04:17:00 -04:00
|
|
|
|
2006-05-29 04:59:36 -04:00
|
|
|
if (priv->last_frame_msecs)
|
|
|
|
{
|
2007-10-12 04:17:00 -04:00
|
|
|
/* Check time diff from out last call and adjust number
|
|
|
|
* of frames to advance accordingly.
|
2006-05-29 04:59:36 -04:00
|
|
|
*/
|
2007-10-12 04:17:00 -04:00
|
|
|
msecs = ((timeval.tv_sec - priv->start_frame_secs) * 1000)
|
2007-08-19 15:09:20 -04:00
|
|
|
+ (timeval.tv_usec / 1000);
|
|
|
|
n_frames = (msecs - priv->last_frame_msecs)
|
|
|
|
/ (1000 / priv->fps);
|
2007-10-12 04:17:00 -04:00
|
|
|
|
2007-08-19 15:09:20 -04:00
|
|
|
if (n_frames <= 0)
|
2006-11-15 18:37:53 -05:00
|
|
|
n_frames = 1;
|
2007-08-19 15:09:20 -04:00
|
|
|
else if (n_frames > 1)
|
2007-06-07 19:51:53 -04:00
|
|
|
{
|
2007-10-12 04:17:00 -04:00
|
|
|
CLUTTER_TIMESTAMP (SCHEDULER,
|
|
|
|
"Timeline [%p], skipping %d frames\n",
|
2007-08-19 15:09:20 -04:00
|
|
|
timeline,
|
|
|
|
n_frames);
|
2007-06-07 19:51:53 -04:00
|
|
|
}
|
2006-05-29 04:59:36 -04:00
|
|
|
}
|
2007-10-12 04:17:00 -04:00
|
|
|
else
|
2006-05-29 04:59:36 -04:00
|
|
|
{
|
|
|
|
/* First frame, set up timings.*/
|
|
|
|
priv->start_frame_secs = timeval.tv_sec;
|
2007-10-12 04:17:00 -04:00
|
|
|
|
2006-05-29 04:59:36 -04:00
|
|
|
msecs = timeval.tv_usec / 1000;
|
2006-11-15 18:37:53 -05:00
|
|
|
n_frames = 1;
|
2006-05-29 04:59:36 -04:00
|
|
|
}
|
|
|
|
|
2007-10-12 04:17:00 -04:00
|
|
|
priv->last_frame_msecs = msecs;
|
2006-05-29 04:59:36 -04:00
|
|
|
|
2006-08-15 16:28:41 -04:00
|
|
|
/* Advance frames */
|
2006-11-15 18:37:53 -05:00
|
|
|
priv->current_frame_num += n_frames;;
|
2006-08-15 16:28:41 -04:00
|
|
|
|
2006-05-29 04:59:36 -04:00
|
|
|
/* Handle loop or stop */
|
2006-11-15 18:37:53 -05:00
|
|
|
if (priv->current_frame_num > priv->n_frames)
|
2006-05-29 04:59:36 -04:00
|
|
|
{
|
2007-08-19 15:09:20 -04:00
|
|
|
guint frame_diff;
|
|
|
|
|
|
|
|
CLUTTER_NOTE (SCHEDULER,
|
|
|
|
"Timeline [%p] completed (cur: %d, tot: %d, drop: %d)",
|
|
|
|
timeline,
|
|
|
|
priv->current_frame_num,
|
|
|
|
priv->n_frames,
|
|
|
|
n_frames - 1);
|
|
|
|
|
|
|
|
frame_diff = priv->current_frame_num - priv->n_frames;
|
2006-11-15 18:37:53 -05:00
|
|
|
priv->current_frame_num = priv->n_frames;
|
2006-05-29 04:59:36 -04:00
|
|
|
|
2007-08-19 15:09:20 -04:00
|
|
|
/* if we skipped some frame to get here let's see whether we still need
|
|
|
|
* to emit the last new-frame signal with the last frame
|
|
|
|
*/
|
|
|
|
if (frame_diff)
|
2006-08-15 16:28:41 -04:00
|
|
|
{
|
2007-08-19 15:09:20 -04:00
|
|
|
g_signal_emit (timeline, timeline_signals[NEW_FRAME], 0,
|
|
|
|
priv->current_frame_num);
|
2006-08-15 16:28:41 -04:00
|
|
|
}
|
2006-05-29 04:59:36 -04:00
|
|
|
|
|
|
|
if (priv->loop)
|
2007-05-25 06:56:09 -04:00
|
|
|
{
|
2007-08-19 15:09:20 -04:00
|
|
|
g_signal_emit (timeline, timeline_signals[COMPLETED], 0);
|
2007-05-25 06:56:09 -04:00
|
|
|
clutter_timeline_rewind (timeline);
|
2007-08-19 15:09:20 -04:00
|
|
|
|
|
|
|
retval = TRUE;
|
2007-05-25 06:56:09 -04:00
|
|
|
}
|
2006-05-29 04:59:36 -04:00
|
|
|
else
|
|
|
|
{
|
2007-08-19 15:09:20 -04:00
|
|
|
if (priv->timeout_id)
|
|
|
|
{
|
|
|
|
timeout_remove (priv->timeout_id);
|
|
|
|
priv->timeout_id = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->last_frame_msecs = 0;
|
|
|
|
|
|
|
|
g_signal_emit (timeline, timeline_signals[COMPLETED], 0);
|
|
|
|
clutter_timeline_rewind (timeline);
|
2007-10-12 04:17:00 -04:00
|
|
|
|
2007-08-19 15:09:20 -04:00
|
|
|
retval = FALSE;
|
2006-05-29 04:59:36 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-19 15:09:20 -04:00
|
|
|
g_object_unref (timeline);
|
|
|
|
|
|
|
|
return retval;
|
2006-05-29 04:59:36 -04:00
|
|
|
}
|
|
|
|
|
2007-06-07 06:26:18 -04:00
|
|
|
static gboolean
|
|
|
|
delay_timeout_func (gpointer data)
|
|
|
|
{
|
|
|
|
ClutterTimeline *timeline = data;
|
|
|
|
ClutterTimelinePrivate *priv = timeline->priv;
|
|
|
|
|
|
|
|
priv->delay_id = 0;
|
|
|
|
|
2007-06-21 10:19:56 -04:00
|
|
|
priv->timeout_id = timeout_add (FPS_TO_INTERVAL (priv->fps),
|
|
|
|
timeline_timeout_func,
|
|
|
|
timeline, NULL);
|
2007-10-12 04:17:00 -04:00
|
|
|
|
2007-06-07 06:26:18 -04:00
|
|
|
g_signal_emit (timeline, timeline_signals[STARTED], 0);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2006-05-29 04:59:36 -04:00
|
|
|
/**
|
|
|
|
* clutter_timeline_start:
|
|
|
|
* @timeline: A #ClutterTimeline
|
|
|
|
*
|
|
|
|
* Starts the #ClutterTimeline playing.
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
clutter_timeline_start (ClutterTimeline *timeline)
|
|
|
|
{
|
|
|
|
ClutterTimelinePrivate *priv;
|
|
|
|
|
2006-06-22 08:05:51 -04:00
|
|
|
g_return_if_fail (CLUTTER_IS_TIMELINE (timeline));
|
2007-10-12 04:17:00 -04:00
|
|
|
|
2006-05-29 04:59:36 -04:00
|
|
|
priv = timeline->priv;
|
|
|
|
|
2007-06-07 06:26:18 -04:00
|
|
|
if (priv->delay_id || priv->timeout_id)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (priv->delay)
|
|
|
|
{
|
2007-06-21 10:19:56 -04:00
|
|
|
priv->delay_id = timeout_add (priv->delay,
|
|
|
|
delay_timeout_func,
|
|
|
|
timeline, NULL);
|
2007-06-07 06:26:18 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-06-21 10:19:56 -04:00
|
|
|
priv->timeout_id = timeout_add (FPS_TO_INTERVAL (priv->fps),
|
|
|
|
timeline_timeout_func,
|
|
|
|
timeline, NULL);
|
2007-06-09 09:20:00 -04:00
|
|
|
|
2007-06-07 06:26:18 -04:00
|
|
|
g_signal_emit (timeline, timeline_signals[STARTED], 0);
|
|
|
|
}
|
2006-05-29 04:59:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_timeline_pause:
|
|
|
|
* @timeline: A #ClutterTimeline
|
|
|
|
*
|
|
|
|
* Pauses the #ClutterTimeline on current frame
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
clutter_timeline_pause (ClutterTimeline *timeline)
|
|
|
|
{
|
2007-06-07 06:26:18 -04:00
|
|
|
ClutterTimelinePrivate *priv;
|
|
|
|
|
2006-05-29 04:59:36 -04:00
|
|
|
g_return_if_fail (CLUTTER_IS_TIMELINE (timeline));
|
|
|
|
|
2007-06-07 06:26:18 -04:00
|
|
|
priv = timeline->priv;
|
|
|
|
|
|
|
|
if (priv->delay_id)
|
|
|
|
{
|
2007-06-21 10:19:56 -04:00
|
|
|
timeout_remove (priv->delay_id);
|
2007-06-07 06:26:18 -04:00
|
|
|
priv->delay_id = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->timeout_id)
|
|
|
|
{
|
2007-06-21 10:19:56 -04:00
|
|
|
timeout_remove (priv->timeout_id);
|
2007-06-07 06:26:18 -04:00
|
|
|
priv->timeout_id = 0;
|
|
|
|
}
|
2006-05-29 04:59:36 -04:00
|
|
|
|
2007-06-07 06:26:18 -04:00
|
|
|
priv->last_frame_msecs = 0;
|
2006-06-22 08:05:51 -04:00
|
|
|
|
2006-11-15 18:37:53 -05:00
|
|
|
g_signal_emit (timeline, timeline_signals[PAUSED], 0);
|
2006-05-29 04:59:36 -04: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 08:05:51 -04:00
|
|
|
/**
|
|
|
|
* clutter_timeline_set_loop:
|
|
|
|
* @timeline: a #ClutterTimeline
|
|
|
|
* @loop: %TRUE for enable looping
|
|
|
|
*
|
|
|
|
* Sets whether @timeline should loop.
|
|
|
|
*/
|
2006-05-29 04:59:36 -04:00
|
|
|
void
|
2006-06-22 08:05:51 -04:00
|
|
|
clutter_timeline_set_loop (ClutterTimeline *timeline,
|
|
|
|
gboolean loop)
|
2006-05-29 04:59:36 -04:00
|
|
|
{
|
2006-06-22 08:05:51 -04:00
|
|
|
g_return_if_fail (CLUTTER_IS_TIMELINE (timeline));
|
2007-10-12 04:17:00 -04:00
|
|
|
|
2006-06-22 08:05:51 -04: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 04:59:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_timeline_rewind:
|
|
|
|
* @timeline: A #ClutterTimeline
|
|
|
|
*
|
|
|
|
* Rewinds #ClutterTimeline to frame 0.
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
clutter_timeline_rewind (ClutterTimeline *timeline)
|
|
|
|
{
|
2006-06-22 08:05:51 -04:00
|
|
|
g_return_if_fail (CLUTTER_IS_TIMELINE (timeline));
|
2007-10-12 04:17:00 -04:00
|
|
|
|
2006-05-29 04:59:36 -04:00
|
|
|
clutter_timeline_advance (timeline, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-06-22 09:56:04 -04:00
|
|
|
* clutter_timeline_skip:
|
2006-05-29 04:59:36 -04:00
|
|
|
* @timeline: A #ClutterTimeline
|
2006-11-15 18:37:53 -05:00
|
|
|
* @n_frames: Number of frames to skip
|
2006-05-29 04:59:36 -04:00
|
|
|
*
|
|
|
|
* Advance timeline by requested number of frames.
|
|
|
|
**/
|
|
|
|
void
|
2006-11-15 18:37:53 -05:00
|
|
|
clutter_timeline_skip (ClutterTimeline *timeline,
|
|
|
|
guint n_frames)
|
2006-05-29 04:59:36 -04:00
|
|
|
{
|
|
|
|
ClutterTimelinePrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (CLUTTER_IS_TIMELINE (timeline));
|
|
|
|
|
|
|
|
priv = timeline->priv;
|
|
|
|
|
2006-11-15 18:37:53 -05:00
|
|
|
priv->current_frame_num += n_frames;
|
2006-05-29 04:59:36 -04:00
|
|
|
|
2006-11-15 18:37:53 -05:00
|
|
|
if (priv->current_frame_num > priv->n_frames)
|
2006-05-29 04:59:36 -04:00
|
|
|
priv->current_frame_num = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_timeline_advance:
|
|
|
|
* @timeline: A #ClutterTimeline
|
|
|
|
* @frame_num: Frame number to advance to
|
|
|
|
*
|
|
|
|
* Advance timeline to requested frame number
|
|
|
|
**/
|
|
|
|
void
|
2006-11-15 18:37:53 -05:00
|
|
|
clutter_timeline_advance (ClutterTimeline *timeline,
|
|
|
|
guint frame_num)
|
2006-05-29 04:59:36 -04:00
|
|
|
{
|
|
|
|
ClutterTimelinePrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (CLUTTER_IS_TIMELINE (timeline));
|
|
|
|
|
|
|
|
priv = timeline->priv;
|
|
|
|
|
2006-11-15 18:37:53 -05:00
|
|
|
if (frame_num < priv->n_frames)
|
2006-05-29 04:59:36 -04:00
|
|
|
priv->current_frame_num = frame_num;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 18:37:53 -05:00
|
|
|
* Request the total number of frames for the #ClutterTimeline.
|
2006-05-29 04:59:36 -04: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 18:37:53 -05: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 07:28:30 -04:00
|
|
|
g_return_if_fail (n_frames > 0);
|
2006-11-15 18:37:53 -05:00
|
|
|
|
|
|
|
priv = timeline->priv;
|
|
|
|
|
|
|
|
if (priv->n_frames != n_frames)
|
|
|
|
{
|
|
|
|
g_object_ref (timeline);
|
|
|
|
|
|
|
|
priv->n_frames = n_frames;
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (timeline), "num-frames");
|
|
|
|
g_object_unref (timeline);
|
|
|
|
}
|
2006-05-29 04:59:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-06-22 05:14:35 -04:00
|
|
|
* clutter_timeline_set_speed:
|
2006-05-29 04:59:36 -04: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 18:37:53 -05:00
|
|
|
clutter_timeline_set_speed (ClutterTimeline *timeline,
|
|
|
|
guint fps)
|
2006-05-29 04:59:36 -04:00
|
|
|
{
|
|
|
|
ClutterTimelinePrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (CLUTTER_IS_TIMELINE (timeline));
|
2007-07-26 07:28:30 -04:00
|
|
|
g_return_if_fail (fps > 0);
|
2006-05-29 04:59:36 -04:00
|
|
|
|
|
|
|
priv = timeline->priv;
|
|
|
|
|
2006-11-15 18:37:53 -05:00
|
|
|
if (priv->fps != fps)
|
2006-05-29 04:59:36 -04:00
|
|
|
{
|
2006-11-15 18:37:53 -05:00
|
|
|
g_object_ref (timeline);
|
|
|
|
|
|
|
|
priv->fps = fps;
|
|
|
|
|
|
|
|
/* if the timeline is playing restart */
|
|
|
|
if (priv->timeout_id)
|
|
|
|
{
|
2007-06-21 10:19:56 -04:00
|
|
|
timeout_remove (priv->timeout_id);
|
2007-10-12 04:17:00 -04:00
|
|
|
|
2007-06-21 10:19:56 -04:00
|
|
|
priv->timeout_id = timeout_add (FPS_TO_INTERVAL (priv->fps),
|
|
|
|
timeline_timeout_func,
|
|
|
|
timeline, NULL);
|
2006-11-15 18:37:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (timeline), "fps");
|
|
|
|
g_object_unref (timeline);
|
2006-05-29 04:59:36 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-15 18:37:53 -05: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 17:37:28 -04: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 08:05:51 -04:00
|
|
|
g_return_val_if_fail (CLUTTER_IS_TIMELINE (timeline), FALSE);
|
2007-10-12 04:17:00 -04:00
|
|
|
|
2006-06-01 17:37:28 -04:00
|
|
|
return (timeline->priv->timeout_id != 0);
|
|
|
|
}
|
|
|
|
|
2007-05-14 05:11:23 -04:00
|
|
|
/**
|
2007-06-07 06:26:07 -04:00
|
|
|
* clutter_timeline_clone:
|
2007-05-14 05:11:23 -04:00
|
|
|
* @timeline: #ClutterTimeline to duplicate.
|
|
|
|
*
|
|
|
|
* Create a new #ClutterTimeline instance which has property values
|
2007-06-07 06:26:07 -04: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 05:11:23 -04:00
|
|
|
*
|
2007-06-07 06:26:07 -04:00
|
|
|
* Return Value: a new #ClutterTimeline, cloned from @timeline
|
2007-05-14 05:11:23 -04:00
|
|
|
*
|
|
|
|
* Since 0.4
|
|
|
|
*/
|
2007-06-07 06:26:07 -04:00
|
|
|
ClutterTimeline *
|
|
|
|
clutter_timeline_clone (ClutterTimeline *timeline)
|
2007-05-14 05:11:23 -04:00
|
|
|
{
|
|
|
|
ClutterTimeline *copy;
|
|
|
|
|
|
|
|
g_return_val_if_fail (CLUTTER_IS_TIMELINE (timeline), NULL);
|
|
|
|
|
2007-06-07 06:26:07 -04: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 06:26:18 -04:00
|
|
|
"delay", clutter_timeline_get_delay (timeline),
|
2007-06-07 06:26:07 -04:00
|
|
|
NULL);
|
2007-05-14 05:11:23 -04:00
|
|
|
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
2006-05-29 04:59:36 -04:00
|
|
|
/**
|
|
|
|
* clutter_timeline_new:
|
2006-11-15 18:37:53 -05:00
|
|
|
* @n_frames: the number of frames
|
|
|
|
* @fps: the number of frames per second
|
2006-05-29 04:59:36 -04:00
|
|
|
*
|
|
|
|
* Create a new #ClutterTimeline instance.
|
|
|
|
*
|
|
|
|
* Return Value: a new #ClutterTimeline
|
|
|
|
*/
|
2006-06-06 16:40:40 -04:00
|
|
|
ClutterTimeline*
|
2006-11-15 18:37:53 -05:00
|
|
|
clutter_timeline_new (guint n_frames,
|
2006-05-29 04:59:36 -04:00
|
|
|
guint fps)
|
|
|
|
{
|
2007-07-26 07:28:25 -04:00
|
|
|
g_return_val_if_fail (n_frames > 0, NULL);
|
|
|
|
g_return_val_if_fail (fps > 0, NULL);
|
|
|
|
|
2007-10-12 04:17:00 -04:00
|
|
|
return g_object_new (CLUTTER_TYPE_TIMELINE,
|
|
|
|
"fps", fps,
|
|
|
|
"num-frames", n_frames,
|
2006-05-29 04:59:36 -04:00
|
|
|
NULL);
|
|
|
|
}
|
2007-06-07 06:26:18 -04: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));
|
|
|
|
g_return_if_fail (msecs > 0);
|
|
|
|
|
|
|
|
priv = timeline->priv;
|
|
|
|
|
|
|
|
if (priv->delay != msecs)
|
|
|
|
{
|
|
|
|
priv->delay = msecs;
|
|
|
|
g_object_notify (G_OBJECT (timeline), "delay");
|
|
|
|
}
|
|
|
|
}
|