Evince
Evince is a document viewer capable of displaying multiple and single page document formats like PDF and Postscript.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ev-timeline.c File Reference
#include <glib.h>
#include <math.h>
#include <gdk/gdk.h>
#include "ev-timeline.h"
+ Include dependency graph for ev-timeline.c:

Go to the source code of this file.

Data Structures

struct  EvTimelinePriv
 

Macros

#define EV_TIMELINE_GET_PRIV(obj)   (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EV_TYPE_TIMELINE, EvTimelinePriv))
 
#define MSECS_PER_SEC   1000
 
#define FRAME_INTERVAL(nframes)   (MSECS_PER_SEC / nframes)
 
#define DEFAULT_FPS   30
 

Typedefs

typedef struct EvTimelinePriv EvTimelinePriv
 

Enumerations

enum  { PROP_0, PROP_FPS, PROP_DURATION, PROP_LOOP }
 
enum  {
  STARTED, PAUSED, FINISHED, FRAME,
  LAST_SIGNAL
}
 

Functions

static void ev_timeline_init (EvTimeline *timeline)
 
static void ev_timeline_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
 
static void ev_timeline_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
 
static void ev_timeline_finalize (GObject *object)
 
static gboolean ev_timeline_run_frame (EvTimeline *timeline)
 
static void ev_timeline_real_start (EvTimeline *timeline)
 
static void ev_timeline_class_init (EvTimelineClass *class)
 
EvTimelineev_timeline_new (guint duration)
 
void ev_timeline_start (EvTimeline *timeline)
 
void ev_timeline_pause (EvTimeline *timeline)
 
void ev_timeline_rewind (EvTimeline *timeline)
 
gboolean ev_timeline_is_running (EvTimeline *timeline)
 
guint ev_timeline_get_fps (EvTimeline *timeline)
 
void ev_timeline_set_fps (EvTimeline *timeline, guint fps)
 
gboolean ev_timeline_get_loop (EvTimeline *timeline)
 
void ev_timeline_set_loop (EvTimeline *timeline, gboolean loop)
 
void ev_timeline_set_duration (EvTimeline *timeline, guint duration)
 
guint ev_timeline_get_duration (EvTimeline *timeline)
 
gdouble ev_timeline_get_progress (EvTimeline *timeline)
 

Variables

static guint signals [LAST_SIGNAL] = { 0, }
 

Macro Definition Documentation

#define DEFAULT_FPS   30

Definition at line 30 of file ev-timeline.c.

#define EV_TIMELINE_GET_PRIV (   obj)    (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EV_TYPE_TIMELINE, EvTimelinePriv))

Definition at line 27 of file ev-timeline.c.

#define FRAME_INTERVAL (   nframes)    (MSECS_PER_SEC / nframes)

Definition at line 29 of file ev-timeline.c.

#define MSECS_PER_SEC   1000

Definition at line 28 of file ev-timeline.c.

Typedef Documentation

Definition at line 32 of file ev-timeline.c.

Enumeration Type Documentation

anonymous enum
Enumerator
PROP_0 
PROP_FPS 
PROP_DURATION 
PROP_LOOP 

Definition at line 44 of file ev-timeline.c.

44  {
45  PROP_0,
46  PROP_FPS,
48  PROP_LOOP
49 };
anonymous enum
Enumerator
STARTED 
PAUSED 
FINISHED 
FRAME 
LAST_SIGNAL 

Definition at line 51 of file ev-timeline.c.

51  {
52  STARTED,
53  PAUSED,
54  FINISHED,
55  FRAME,
57 };

Function Documentation

static void ev_timeline_class_init ( EvTimelineClass class)
static

Definition at line 207 of file ev-timeline.c.

208 {
209  GObjectClass *object_class = G_OBJECT_CLASS (class);
210 
211  object_class->set_property = ev_timeline_set_property;
212  object_class->get_property = ev_timeline_get_property;
213  object_class->finalize = ev_timeline_finalize;
214 
215  class->start = ev_timeline_real_start;
216 
217  g_object_class_install_property (object_class,
218  PROP_FPS,
219  g_param_spec_uint ("fps",
220  "FPS",
221  "Frames per second for the timeline",
222  1,
223  G_MAXUINT,
224  DEFAULT_FPS,
225  G_PARAM_READWRITE |
226  G_PARAM_STATIC_STRINGS));
227  g_object_class_install_property (object_class,
229  g_param_spec_uint ("duration",
230  "Animation Duration",
231  "Animation Duration",
232  0,
233  G_MAXUINT,
234  0,
235  G_PARAM_READWRITE |
236  G_PARAM_STATIC_STRINGS));
237  g_object_class_install_property (object_class,
238  PROP_LOOP,
239  g_param_spec_boolean ("loop",
240  "Loop",
241  "Whether the timeline loops or not",
242  FALSE,
243  G_PARAM_READWRITE |
244  G_PARAM_STATIC_STRINGS));
245  signals[STARTED] =
246  g_signal_new ("started",
247  G_TYPE_FROM_CLASS (object_class),
248  G_SIGNAL_RUN_LAST,
249  G_STRUCT_OFFSET (EvTimelineClass, started),
250  NULL, NULL,
251  g_cclosure_marshal_VOID__VOID,
252  G_TYPE_NONE, 0);
253 
254  signals[PAUSED] =
255  g_signal_new ("paused",
256  G_TYPE_FROM_CLASS (object_class),
257  G_SIGNAL_RUN_LAST,
258  G_STRUCT_OFFSET (EvTimelineClass, paused),
259  NULL, NULL,
260  g_cclosure_marshal_VOID__VOID,
261  G_TYPE_NONE, 0);
262 
263  signals[FINISHED] =
264  g_signal_new ("finished",
265  G_TYPE_FROM_CLASS (object_class),
266  G_SIGNAL_RUN_LAST,
267  G_STRUCT_OFFSET (EvTimelineClass, finished),
268  NULL, NULL,
269  g_cclosure_marshal_VOID__VOID,
270  G_TYPE_NONE, 0);
271 
272  signals[FRAME] =
273  g_signal_new ("frame",
274  G_TYPE_FROM_CLASS (object_class),
275  G_SIGNAL_RUN_LAST,
276  G_STRUCT_OFFSET (EvTimelineClass, frame),
277  NULL, NULL,
278  g_cclosure_marshal_VOID__DOUBLE,
279  G_TYPE_NONE, 1,
280  G_TYPE_DOUBLE);
281 
282  g_type_class_add_private (class, sizeof (EvTimelinePriv));
283 }
static void ev_timeline_finalize ( GObject *  object)
static

Definition at line 129 of file ev-timeline.c.

130 {
131  EvTimelinePriv *priv;
132 
133  priv = EV_TIMELINE_GET_PRIV (object);
134 
135  if (priv->source_id) {
136  g_source_remove (priv->source_id);
137  priv->source_id = 0;
138  }
139 
140  if (priv->timer)
141  g_timer_destroy (priv->timer);
142 
143  G_OBJECT_CLASS (ev_timeline_parent_class)->finalize (object);
144 }

+ Here is the caller graph for this function:

guint ev_timeline_get_duration ( EvTimeline timeline)

Definition at line 424 of file ev-timeline.c.

425 {
426  EvTimelinePriv *priv;
427 
428  g_return_val_if_fail (EV_IS_TIMELINE (timeline), 0);
429 
430  priv = EV_TIMELINE_GET_PRIV (timeline);
431 
432  return priv->duration;
433 }
guint ev_timeline_get_fps ( EvTimeline timeline)

Definition at line 351 of file ev-timeline.c.

352 {
353  EvTimelinePriv *priv;
354 
355  g_return_val_if_fail (EV_IS_TIMELINE (timeline), 1);
356 
357  priv = EV_TIMELINE_GET_PRIV (timeline);
358  return priv->fps;
359 }
gboolean ev_timeline_get_loop ( EvTimeline timeline)

Definition at line 384 of file ev-timeline.c.

385 {
386  EvTimelinePriv *priv;
387 
388  g_return_val_if_fail (EV_IS_TIMELINE (timeline), FALSE);
389 
390  priv = EV_TIMELINE_GET_PRIV (timeline);
391  return priv->loop;
392 }
gdouble ev_timeline_get_progress ( EvTimeline timeline)

Definition at line 436 of file ev-timeline.c.

437 {
438  EvTimelinePriv *priv;
439  gdouble progress;
440  guint elapsed_time;
441 
442  g_return_val_if_fail (EV_IS_TIMELINE (timeline), 0.0);
443 
444  priv = EV_TIMELINE_GET_PRIV (timeline);
445 
446  if (!priv->timer)
447  return 0.;
448 
449  elapsed_time = (guint) (g_timer_elapsed (priv->timer, NULL) * 1000);
450  progress = (gdouble) elapsed_time / priv->duration;
451 
452  return CLAMP (progress, 0., 1.);
453 }

+ Here is the caller graph for this function:

static void ev_timeline_get_property ( GObject *  object,
guint  prop_id,
GValue *  value,
GParamSpec *  pspec 
)
static

Definition at line 102 of file ev-timeline.c.

106 {
107  EvTimeline *timeline;
108  EvTimelinePriv *priv;
109 
110  timeline = EV_TIMELINE (object);
111  priv = EV_TIMELINE_GET_PRIV (timeline);
112 
113  switch (prop_id) {
114  case PROP_FPS:
115  g_value_set_uint (value, priv->fps);
116  break;
117  case PROP_DURATION:
118  g_value_set_uint (value, priv->duration);
119  break;
120  case PROP_LOOP:
121  g_value_set_boolean (value, priv->loop);
122  break;
123  default:
124  G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
125  }
126 }

+ Here is the caller graph for this function:

static void ev_timeline_init ( EvTimeline timeline)
static

Definition at line 66 of file ev-timeline.c.

67 {
68  EvTimelinePriv *priv;
69 
70  priv = EV_TIMELINE_GET_PRIV (timeline);
71 
72  priv->fps = DEFAULT_FPS;
73  priv->duration = 0;
74 }
gboolean ev_timeline_is_running ( EvTimeline timeline)

Definition at line 339 of file ev-timeline.c.

340 {
341  EvTimelinePriv *priv;
342 
343  g_return_val_if_fail (EV_IS_TIMELINE (timeline), FALSE);
344 
345  priv = EV_TIMELINE_GET_PRIV (timeline);
346 
347  return (priv->source_id != 0);
348 }

+ Here is the caller graph for this function:

EvTimeline* ev_timeline_new ( guint  duration)

Definition at line 286 of file ev-timeline.c.

287 {
288  return g_object_new (EV_TYPE_TIMELINE,
289  "duration", duration,
290  NULL);
291 }
void ev_timeline_pause ( EvTimeline timeline)

Definition at line 302 of file ev-timeline.c.

303 {
304  EvTimelinePriv *priv;
305 
306  g_return_if_fail (EV_IS_TIMELINE (timeline));
307 
308  priv = EV_TIMELINE_GET_PRIV (timeline);
309 
310  if (priv->source_id) {
311  g_source_remove (priv->source_id);
312  priv->source_id = 0;
313  g_timer_stop (priv->timer);
314  g_signal_emit (timeline, signals [PAUSED], 0);
315  }
316 }
static void ev_timeline_real_start ( EvTimeline timeline)
static

Definition at line 183 of file ev-timeline.c.

184 {
185  EvTimelinePriv *priv;
186 
187  priv = EV_TIMELINE_GET_PRIV (timeline);
188 
189  if (!priv->source_id) {
190  if (priv->timer)
191  g_timer_continue (priv->timer);
192  else
193  priv->timer = g_timer_new ();
194 
195  /* sanity check */
196  g_assert (priv->fps > 0);
197 
198  g_signal_emit (timeline, signals [STARTED], 0);
199 
200  priv->source_id = g_timeout_add (FRAME_INTERVAL (priv->fps),
201  (GSourceFunc) ev_timeline_run_frame,
202  timeline);
203  }
204 }

+ Here is the caller graph for this function:

void ev_timeline_rewind ( EvTimeline timeline)

Definition at line 319 of file ev-timeline.c.

320 {
321  EvTimelinePriv *priv;
322 
323  g_return_if_fail (EV_IS_TIMELINE (timeline));
324 
325  priv = EV_TIMELINE_GET_PRIV (timeline);
326 
327  /* destroy and re-create timer if neccesary */
328  if (priv->timer) {
329  g_timer_destroy (priv->timer);
330 
331  if (ev_timeline_is_running (timeline))
332  priv->timer = g_timer_new ();
333  else
334  priv->timer = NULL;
335  }
336 }

+ Here is the caller graph for this function:

static gboolean ev_timeline_run_frame ( EvTimeline timeline)
static

Definition at line 147 of file ev-timeline.c.

148 {
149  EvTimelinePriv *priv;
150  gdouble progress;
151  guint elapsed_time;
152 
153  gdk_threads_enter ();
154 
155  priv = EV_TIMELINE_GET_PRIV (timeline);
156 
157  elapsed_time = (guint) (g_timer_elapsed (priv->timer, NULL) * 1000);
158  progress = (gdouble) elapsed_time / priv->duration;
159  progress = CLAMP (progress, 0., 1.);
160 
161  g_signal_emit (timeline, signals [FRAME], 0, progress);
162 
163  if (progress >= 1.0) {
164  if (!priv->loop) {
165  if (priv->source_id) {
166  g_source_remove (priv->source_id);
167  priv->source_id = 0;
168  }
169 
170  g_signal_emit (timeline, signals [FINISHED], 0);
171  return FALSE;
172  } else {
173  ev_timeline_rewind (timeline);
174  }
175  }
176 
177  gdk_threads_leave ();
178 
179  return TRUE;
180 }

+ Here is the caller graph for this function:

void ev_timeline_set_duration ( EvTimeline timeline,
guint  duration 
)

Definition at line 409 of file ev-timeline.c.

411 {
412  EvTimelinePriv *priv;
413 
414  g_return_if_fail (EV_IS_TIMELINE (timeline));
415 
416  priv = EV_TIMELINE_GET_PRIV (timeline);
417 
418  priv->duration = duration;
419 
420  g_object_notify (G_OBJECT (timeline), "duration");
421 }

+ Here is the caller graph for this function:

void ev_timeline_set_fps ( EvTimeline timeline,
guint  fps 
)

Definition at line 362 of file ev-timeline.c.

364 {
365  EvTimelinePriv *priv;
366 
367  g_return_if_fail (EV_IS_TIMELINE (timeline));
368 
369  priv = EV_TIMELINE_GET_PRIV (timeline);
370 
371  priv->fps = fps;
372 
373  if (ev_timeline_is_running (timeline)) {
374  g_source_remove (priv->source_id);
375  priv->source_id = g_timeout_add (FRAME_INTERVAL (priv->fps),
376  (GSourceFunc) ev_timeline_run_frame,
377  timeline);
378  }
379 
380  g_object_notify (G_OBJECT (timeline), "fps");
381 }

+ Here is the caller graph for this function:

void ev_timeline_set_loop ( EvTimeline timeline,
gboolean  loop 
)

Definition at line 395 of file ev-timeline.c.

397 {
398  EvTimelinePriv *priv;
399 
400  g_return_if_fail (EV_IS_TIMELINE (timeline));
401 
402  priv = EV_TIMELINE_GET_PRIV (timeline);
403  priv->loop = loop;
404 
405  g_object_notify (G_OBJECT (timeline), "loop");
406 }

+ Here is the caller graph for this function:

static void ev_timeline_set_property ( GObject *  object,
guint  prop_id,
const GValue *  value,
GParamSpec *  pspec 
)
static

Definition at line 77 of file ev-timeline.c.

81 {
82  EvTimeline *timeline;
83 
84  timeline = EV_TIMELINE (object);
85 
86  switch (prop_id) {
87  case PROP_FPS:
88  ev_timeline_set_fps (timeline, g_value_get_uint (value));
89  break;
90  case PROP_DURATION:
91  ev_timeline_set_duration (timeline, g_value_get_uint (value));
92  break;
93  case PROP_LOOP:
94  ev_timeline_set_loop (timeline, g_value_get_boolean (value));
95  break;
96  default:
97  G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
98  }
99 }

+ Here is the caller graph for this function:

void ev_timeline_start ( EvTimeline timeline)

Definition at line 294 of file ev-timeline.c.

295 {
296  g_return_if_fail (EV_IS_TIMELINE (timeline));
297 
298  EV_TIMELINE_GET_CLASS (timeline)->start (timeline);
299 }

+ Here is the caller graph for this function:

Variable Documentation

guint signals[LAST_SIGNAL] = { 0, }
static

Definition at line 59 of file ev-timeline.c.