1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
/*
* Copyright (C) 2007 Neil J. Patel
* Copyright (C) 2007 OpenedHand Ltd
*
* Author: Neil J. Patel <njp@o-hand.com>
*/
/* This is a utility ClutterBehaviour-derived class, in which you can set the
alphanotify function. It is useful for situations where you do not need the
full capabilities of the ClutterBehvaiour class, you just want a function to
be called for each iteration along the timeline
*/
#include "fluttr-behave.h"
#include "math.h"
G_DEFINE_TYPE (FluttrBehave, fluttr_behave, CLUTTER_TYPE_BEHAVIOUR);
#define FLUTTR_BEHAVE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj),\
FLUTTR_TYPE_BEHAVE, \
FluttrBehavePrivate))
struct _FluttrBehavePrivate
{
FluttrBehaveAlphaFunc func;
gpointer data;
};
guint32
alpha_sine_inc_func (ClutterAlpha *alpha,
gpointer dummy)
{
ClutterTimeline *timeline;
gint current_frame_num, n_frames;
gdouble x, sine;
timeline = clutter_alpha_get_timeline (alpha);
current_frame_num = clutter_timeline_get_current_frame (timeline);
n_frames = clutter_timeline_get_n_frames (timeline);
x = (gdouble) (current_frame_num * 0.5f * M_PI) / n_frames ;
/* sine = (sin (x - (M_PI / 0.5f)) + 1.0f) * 0.5f; */
sine = (sin (x - (M_PI / 0.5f))) ;
return (guint32)(sine * (gdouble) CLUTTER_ALPHA_MAX_ALPHA);
}
guint32
alpha_linear_inc_func (ClutterAlpha *alpha,
gpointer dummy)
{
ClutterTimeline *timeline;
gint current_frame_num, n_frames;
gdouble x;
timeline = clutter_alpha_get_timeline (alpha);
current_frame_num = clutter_timeline_get_current_frame (timeline);
n_frames = clutter_timeline_get_n_frames (timeline);
x = (gdouble) (current_frame_num) / n_frames ;
/* sine = (sin (x - (M_PI / 0.5f)) + 1.0f) * 0.5f; */
return (guint32)(x * (gdouble) CLUTTER_ALPHA_MAX_ALPHA);
}
static void
fluttr_behave_alpha_notify (ClutterBehaviour *behave, guint32 alpha_value)
{
FluttrBehave *fluttr_behave = FLUTTR_BEHAVE(behave);
FluttrBehavePrivate *priv;
priv = FLUTTR_BEHAVE_GET_PRIVATE (fluttr_behave);
if (priv->func != NULL) {
priv->func (behave, alpha_value, priv->data);
}
}
static void
fluttr_behave_class_init (FluttrBehaveClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
ClutterBehaviourClass *behave_class = CLUTTER_BEHAVIOUR_CLASS (klass);
behave_class->alpha_notify = fluttr_behave_alpha_notify;
g_type_class_add_private (gobject_class, sizeof (FluttrBehavePrivate));
}
static void
fluttr_behave_init (FluttrBehave *self)
{
FluttrBehavePrivate *priv;
priv = FLUTTR_BEHAVE_GET_PRIVATE (self);
priv->func = NULL;
priv->data = NULL;
}
ClutterBehaviour*
fluttr_behave_new (ClutterAlpha *alpha,
FluttrBehaveAlphaFunc func,
gpointer data)
{
FluttrBehave *behave;
FluttrBehavePrivate *priv;
behave = g_object_new (FLUTTR_TYPE_BEHAVE,
"alpha", alpha,
NULL);
priv = FLUTTR_BEHAVE_GET_PRIVATE (behave);
priv->func = func;
priv->data = data;
return CLUTTER_BEHAVIOUR(behave);
}
|