summaryrefslogtreecommitdiff
path: root/clutter/clutter-timeline.c
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@linux.intel.com>2012-05-25 19:41:14 -0400
committerEmmanuele Bassi <ebassi@linux.intel.com>2012-05-31 09:54:23 +0100
commitde4d70af69a5e33421c468275a3e0e2dc7aaf624 (patch)
treeb4ba9e48d08e1091b62d0bb9462938fbda5637cb /clutter/clutter-timeline.c
parent4634dde6134507ad6598bf4c0c97a70890aaf9dc (diff)
downloadclutter-de4d70af69a5e33421c468275a3e0e2dc7aaf624.tar.gz
timeline: Add a new "stopped" signal
The ::stopped signal is emitted when the timeline has been completely exhausted or when the timeline has been programmatically stopped by using clutter_timeline_stop(); the notification at the end of the timeline run allows to write handlers without having to check whether the current repeat is the last one, like we are forced to do when using the ::completed signal. Based on the patch by: Jasper St. Pierre <jstpierre@mecheye.net> https://bugzilla.gnome.org/show_bug.cgi?id=676854
Diffstat (limited to 'clutter/clutter-timeline.c')
-rw-r--r--clutter/clutter-timeline.c56
1 files changed, 51 insertions, 5 deletions
diff --git a/clutter/clutter-timeline.c b/clutter/clutter-timeline.c
index 9cc521267..ae1d3e09f 100644
--- a/clutter/clutter-timeline.c
+++ b/clutter/clutter-timeline.c
@@ -187,6 +187,7 @@ enum
PAUSED,
COMPLETED,
MARKER_REACHED,
+ STOPPED,
LAST_SIGNAL
};
@@ -684,6 +685,10 @@ clutter_timeline_class_init (ClutterTimelineClass *klass)
*
* This signal will be emitted even if the #ClutterTimeline is set to be
* repeating.
+ *
+ * If you want to get notification on whether the #ClutterTimeline has
+ * been stopped or has finished its run, including its eventual repeats,
+ * you should use the #ClutterTimeline::stopped signal instead.
*/
timeline_signals[COMPLETED] =
g_signal_new (I_("completed"),
@@ -766,6 +771,33 @@ clutter_timeline_class_init (ClutterTimelineClass *klass)
G_TYPE_NONE, 2,
G_TYPE_STRING,
G_TYPE_INT);
+ /**
+ * ClutterTimeline::stopped:
+ * @timeline: the #ClutterTimeline that emitted the signal
+ * @is_finished: %TRUE if the signal was emitted at the end of the
+ * timeline.
+ *
+ * The #ClutterTimeline::stopped signal is emitted when the timeline
+ * has been stopped, either because clutter_timeline_stop() has been
+ * called, or because it has been exhausted.
+ *
+ * This is different from the #ClutterTimeline::completed signal,
+ * which gets emitted after every repeat finishes.
+ *
+ * If the #ClutterTimeline has is marked as infinitely repeating,
+ * this signal will never be emitted.
+ *
+ * Since: 1.12
+ */
+ timeline_signals[STOPPED] =
+ g_signal_new (I_("stopped"),
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (ClutterTimelineClass, completed),
+ NULL, NULL,
+ _clutter_marshal_VOID__BOOLEAN,
+ G_TYPE_NONE, 1,
+ G_TYPE_BOOLEAN);
}
static void
@@ -897,12 +929,13 @@ set_is_playing (ClutterTimeline *timeline,
ClutterTimelinePrivate *priv = timeline->priv;
ClutterMasterClock *master_clock;
- is_playing = is_playing != FALSE;
+ is_playing = !!is_playing;
if (is_playing == priv->is_playing)
return;
priv->is_playing = is_playing;
+
master_clock = _clutter_master_clock_get_default ();
if (priv->is_playing)
{
@@ -911,9 +944,7 @@ set_is_playing (ClutterTimeline *timeline,
priv->current_repeat = 0;
}
else
- {
- _clutter_master_clock_remove_timeline (master_clock, timeline);
- }
+ _clutter_master_clock_remove_timeline (master_clock, timeline);
}
static gboolean
@@ -1002,7 +1033,8 @@ clutter_timeline_do_frame (ClutterTimeline *timeline)
* priv->repeat_count. Are we limiting the things that could be
* done in the above new-frame signal handler?
*/
- set_is_playing (timeline, FALSE);
+ set_is_playing (timeline, FALSE);
+ g_signal_emit (timeline, timeline_signals[STOPPED], 0, TRUE);
}
g_signal_emit (timeline, timeline_signals[COMPLETED], 0);
@@ -1156,8 +1188,22 @@ clutter_timeline_pause (ClutterTimeline *timeline)
void
clutter_timeline_stop (ClutterTimeline *timeline)
{
+ gboolean was_playing;
+
+ g_return_if_fail (CLUTTER_IS_TIMELINE (timeline));
+
+ /* we check the is_playing here because pause() will return immediately
+ * if the timeline wasn't playing, so we don't know if it was actually
+ * stopped, and yet we still don't want to emit a ::stopped signal if
+ * the timeline was not playing in the first place.
+ */
+ was_playing = timeline->priv->is_playing;
+
clutter_timeline_pause (timeline);
clutter_timeline_rewind (timeline);
+
+ if (was_playing)
+ g_signal_emit (timeline, timeline_signals[STOPPED], 0, FALSE);
}
/**