2 * Copyright (C) 2007 Neil J. Patel
3 * Copyright (C) 2007 OpenedHand Ltd
5 * Author: Neil J. Patel <njp@o-hand.com>
9 /* This is a utility ClutterBehaviour-derived class, in which you can set the
10 alphanotify function. It is useful for situations where you do not need the
11 full capabilities of the ClutterBehvaiour class, you just want a function to
12 be called for each iteration along the timeline
15 #include "fluttr-behave.h"
19 G_DEFINE_TYPE (FluttrBehave, fluttr_behave, CLUTTER_TYPE_BEHAVIOUR);
21 #define FLUTTR_BEHAVE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj),\
25 struct _FluttrBehavePrivate
27 FluttrBehaveAlphaFunc func;
32 alpha_sine_inc_func (ClutterAlpha *alpha,
35 ClutterTimeline *timeline;
36 gint current_frame_num, n_frames;
39 timeline = clutter_alpha_get_timeline (alpha);
41 current_frame_num = clutter_timeline_get_current_frame (timeline);
42 n_frames = clutter_timeline_get_n_frames (timeline);
44 x = (gdouble) (current_frame_num * 0.5f * M_PI) / n_frames ;
45 /* sine = (sin (x - (M_PI / 0.5f)) + 1.0f) * 0.5f; */
47 sine = (sin (x - (M_PI / 0.5f))) ;
49 return (guint32)(sine * (gdouble) CLUTTER_ALPHA_MAX_ALPHA);
53 alpha_linear_inc_func (ClutterAlpha *alpha,
56 ClutterTimeline *timeline;
57 gint current_frame_num, n_frames;
60 timeline = clutter_alpha_get_timeline (alpha);
62 current_frame_num = clutter_timeline_get_current_frame (timeline);
63 n_frames = clutter_timeline_get_n_frames (timeline);
65 x = (gdouble) (current_frame_num) / n_frames ;
66 /* sine = (sin (x - (M_PI / 0.5f)) + 1.0f) * 0.5f; */
68 return (guint32)(x * (gdouble) CLUTTER_ALPHA_MAX_ALPHA);
72 fluttr_behave_alpha_notify (ClutterBehaviour *behave, guint32 alpha_value)
74 FluttrBehave *fluttr_behave = FLUTTR_BEHAVE(behave);
75 FluttrBehavePrivate *priv;
77 priv = FLUTTR_BEHAVE_GET_PRIVATE (fluttr_behave);
79 if (priv->func != NULL) {
80 priv->func (behave, alpha_value, priv->data);
85 fluttr_behave_class_init (FluttrBehaveClass *klass)
87 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
88 ClutterBehaviourClass *behave_class = CLUTTER_BEHAVIOUR_CLASS (klass);
90 behave_class->alpha_notify = fluttr_behave_alpha_notify;
92 g_type_class_add_private (gobject_class, sizeof (FluttrBehavePrivate));
96 fluttr_behave_init (FluttrBehave *self)
98 FluttrBehavePrivate *priv;
100 priv = FLUTTR_BEHAVE_GET_PRIVATE (self);
107 fluttr_behave_new (ClutterAlpha *alpha,
108 FluttrBehaveAlphaFunc func,
111 FluttrBehave *behave;
112 FluttrBehavePrivate *priv;
114 behave = g_object_new (FLUTTR_TYPE_BEHAVE,
118 priv = FLUTTR_BEHAVE_GET_PRIVATE (behave);
123 return CLUTTER_BEHAVIOUR(behave);