4 #define CSW() CLUTTER_STAGE_WIDTH()
5 #define CSH() CLUTTER_STAGE_HEIGHT()
7 #define WOOHAA_TYPE_BEHAVIOUR_BUSY (clutter_behaviour_busy_get_type ())
9 #define WOOHAA_BEHAVIOUR_BUSY(obj) \
10 (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
11 WOOHAA_TYPE_BEHAVIOUR_BUSY, WoohaaBehaviourBusy))
13 #define WOOHAA_BEHAVIOUR_BUSY_CLASS(klass) \
14 (G_TYPE_CHECK_CLASS_CAST ((klass), \
15 WOOHAA_TYPE_BEHAVIOUR_BUSY, WoohaaBehaviourBusyClass))
17 #define CLUTTER_IS_BEHAVIOUR_BUSY(obj) \
18 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
19 WOOHAA_TYPE_BEHAVIOUR_BUSY))
21 #define CLUTTER_IS_BEHAVIOUR_BUSY_CLASS(klass) \
22 (G_TYPE_CHECK_CLASS_TYPE ((klass), \
23 WOOHAA_TYPE_BEHAVIOUR_BUSY))
25 #define WOOHAA_BEHAVIOUR_BUSY_GET_CLASS(obj) \
26 (G_TYPE_INSTANCE_GET_CLASS ((obj), \
27 WOOHAA_TYPE_BEHAVIOUR_BUSY, WoohaaBehaviourBusyClass))
29 typedef struct _WoohaaBehaviourBusy WoohaaBehaviourBusy;
30 typedef struct _WoohaaBehaviourBusyClass WoohaaBehaviourBusyClass;
32 struct _WoohaaBehaviourBusy
34 ClutterBehaviour parent;
38 struct _WoohaaBehaviourBusyClass
40 ClutterBehaviourClass parent_class;
43 GType clutter_behaviour_busy_get_type (void) G_GNUC_CONST;
45 G_DEFINE_TYPE (WoohaaBehaviourBusy, clutter_behaviour_busy, CLUTTER_TYPE_BEHAVIOUR);
47 static ClutterBehaviour*
48 clutter_behaviour_busy_new (WoohaaBusy *menu, ClutterAlpha *alpha);
51 clutter_behaviour_alpha_notify (ClutterBehaviour *behave,
60 struct _WoohaaBusyPrivate
62 ClutterActor *spinner;
65 ClutterTimeline *timeline;
69 G_DEFINE_TYPE (WoohaaBusy, woohaa_busy, CLUTTER_TYPE_ACTOR);
72 woohaa_busy_dispose (GObject *object)
75 WoohaaBusyPrivate *priv;
77 self = WOOHAA_BUSY(object);
80 G_OBJECT_CLASS (woohaa_busy_parent_class)->dispose (object);
84 woohaa_busy_finalize (GObject *object)
87 WoohaaBusyPrivate *priv;
89 self = WOOHAA_BUSY(object);
92 G_OBJECT_CLASS (woohaa_busy_parent_class)->finalize (object);
96 woohaa_busy_show_cb (ClutterActor *actor, ClutterTimeline *timeline)
98 clutter_timeline_start (timeline);
102 woohaa_busy_hide_cb (ClutterActor *actor, ClutterTimeline *timeline)
104 clutter_timeline_stop (timeline);
105 clutter_actor_set_opacity (CLUTTER_ACTOR (actor), 0xFF);
109 newframe_cb (ClutterTimeline *timeline,
111 ClutterActor *spinner)
115 clutter_actor_get_position (spinner, &x, &y);
116 clutter_actor_set_position (spinner, x + 10 , y + 10);
118 clutter_actor_set_rotation (spinner,
120 (float)frame_num * 4.0,
121 clutter_actor_get_width (spinner) / 2,
122 clutter_actor_get_height (spinner) / 2,
127 woohaa_busy_paint (ClutterActor *actor)
129 WoohaaBusyPrivate *priv = (WOOHAA_BUSY (actor))->priv;
131 clutter_actor_paint (priv->spinner);
132 clutter_actor_paint (priv->label);
136 woohaa_busy_get_preferred_width (ClutterActor *actor,
137 ClutterUnit for_height,
138 ClutterUnit *min_width_p,
139 ClutterUnit *natural_width_p)
141 *min_width_p = CLUTTER_UNITS_FROM_INT (100);
142 *natural_width_p = CLUTTER_UNITS_FROM_INT (500);
146 woohaa_busy_get_preferred_height (ClutterActor *actor,
147 ClutterUnit for_width,
148 ClutterUnit *min_height_p,
149 ClutterUnit *natural_height_p)
151 *min_height_p = CLUTTER_UNITS_FROM_INT (100);
152 *natural_height_p = CLUTTER_UNITS_FROM_INT (500);
156 woohaa_busy_allocate (ClutterActor *actor,
157 const ClutterActorBox *box,
158 gboolean absolute_origin_changed)
160 WoohaaBusyPrivate *priv = (WOOHAA_BUSY (actor))->priv;
161 ClutterUnit min_width, spinner_natural_width, label_natural_width;
162 ClutterUnit min_height, spinner_natural_height, label_natural_height;
163 ClutterActorBox spinner_box, label_box;
165 /* query spinner width and height */
166 clutter_actor_get_preferred_width (priv->spinner,
169 &spinner_natural_width);
170 clutter_actor_get_preferred_height (priv->spinner,
173 &spinner_natural_height);
175 /* query label width and height */
176 clutter_actor_get_preferred_width (priv->label,
179 &label_natural_width);
180 clutter_actor_get_preferred_height (priv->label,
183 &label_natural_height);
185 spinner_box.x1 = CLUTTER_UNITS_FROM_INT (CSW()/2) - spinner_natural_width/2;
186 spinner_box.y1 = CLUTTER_UNITS_FROM_INT (CSH()/2)
187 - spinner_natural_height/2
188 - label_natural_height/2
189 + (priv->spinner_alpha * 100);
190 spinner_box.x2 = spinner_box.x1 + spinner_natural_width;
191 spinner_box.y2 = spinner_box.y1 + spinner_natural_height;
193 label_box.x1 = CLUTTER_UNITS_FROM_INT (CSW()/2) - label_natural_width/2;
194 label_box.y1 = CLUTTER_UNITS_FROM_INT (CSH()/2)
195 - spinner_natural_height/2
196 - label_natural_height/2
197 + spinner_natural_height;
198 label_box.x2 = label_box.x1 + label_natural_width;
199 label_box.y2 = label_box.y1 + label_natural_height;
201 clutter_actor_allocate (priv->spinner,
203 absolute_origin_changed);
205 clutter_actor_allocate (priv->label,
207 absolute_origin_changed);
209 CLUTTER_ACTOR_CLASS (woohaa_busy_parent_class)->
210 allocate (actor, box, absolute_origin_changed);
214 woohaa_busy_set_property (GObject *object,
220 WoohaaBusyPrivate *priv;
222 busy = WOOHAA_BUSY(object);
228 if (priv->label_text)
229 g_free (priv->label_text);
230 priv->label_text = g_strdup(g_value_get_string (value));
231 clutter_label_set_text (CLUTTER_LABEL (priv->label), priv->label_text);
234 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
240 woohaa_busy_get_property (GObject *object,
246 WoohaaBusyPrivate *priv;
248 busy = WOOHAA_BUSY(object);
254 g_value_set_string (value, priv->label_text);
257 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
263 woohaa_busy_class_init (WoohaaBusyClass *klass)
265 GObjectClass *object_class = G_OBJECT_CLASS (klass);
266 ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
268 g_type_class_add_private (klass, sizeof (WoohaaBusyPrivate));
270 object_class->dispose = woohaa_busy_dispose;
271 object_class->finalize = woohaa_busy_finalize;
272 object_class->set_property = woohaa_busy_set_property;
273 object_class->get_property = woohaa_busy_get_property;
275 actor_class->get_preferred_width = woohaa_busy_get_preferred_width;
276 actor_class->get_preferred_height = woohaa_busy_get_preferred_height;
277 actor_class->allocate = woohaa_busy_allocate;
278 actor_class->paint = woohaa_busy_paint;
280 g_object_class_install_property
281 (object_class, PROP_LABEL,
282 g_param_spec_string ("label",
291 woohaa_busy_init (WoohaaBusy *woohaa_busy)
293 WoohaaBusyPrivate *priv;
295 ClutterColor grey = { 0x72, 0x9f, 0xcf, 0xff};
297 woohaa_busy->priv = priv =
298 G_TYPE_INSTANCE_GET_PRIVATE (woohaa_busy,
302 priv->timeline = clutter_timeline_new (90, 20);
303 clutter_timeline_set_loop (priv->timeline, TRUE);
305 priv->spinner = clutter_texture_new_from_file (PKGDATADIR "/spinner.svg",
307 clutter_actor_set_position
309 (CSW() - clutter_actor_get_width (priv->spinner))/2,
310 (CSH() - clutter_actor_get_height (priv->spinner))/2);
311 clutter_actor_show (priv->spinner);
313 priv->label_text = g_strdup("One moment please...");
314 font = g_strdup_printf("Sans %ipx", (CSH()/6)/2);
315 priv->label = clutter_label_new_full (font, priv->label_text, &grey);
316 clutter_actor_set_position (priv->label,
317 (CSW() - clutter_actor_get_width (priv->label))/2,
318 CSH() - (3*clutter_actor_get_height (priv->label)));
319 clutter_actor_show (priv->label);
321 clutter_actor_set_parent (priv->spinner, CLUTTER_ACTOR (woohaa_busy));
322 clutter_actor_set_parent (priv->label, CLUTTER_ACTOR (woohaa_busy));
324 g_signal_connect (priv->timeline,
326 G_CALLBACK (newframe_cb),
329 g_signal_connect (woohaa_busy,
331 G_CALLBACK (woohaa_busy_show_cb),
333 g_signal_connect (woohaa_busy,
335 G_CALLBACK (woohaa_busy_hide_cb),
340 fade_complete_cb (ClutterActor *actor, gpointer data)
342 clutter_actor_hide(actor);
346 woohaa_busy_fade_out (WoohaaBusy *busy, gint timeout)
348 ClutterEffectTemplate *template;
349 ClutterTimeline *timeline;
351 timeline = clutter_timeline_new_for_duration (timeout);
352 template = clutter_effect_template_new (timeline, CLUTTER_ALPHA_SINE_INC);
354 clutter_effect_fade (template,
355 CLUTTER_ACTOR (busy),
362 woohaa_busy_fade_in (WoohaaBusy *busy, gint timeout)
364 ClutterEffectTemplate *template;
365 ClutterTimeline *timeline;
367 timeline = clutter_timeline_new_for_duration (timeout);
368 template = clutter_effect_template_new (timeline, CLUTTER_ALPHA_SINE_INC);
370 clutter_actor_set_opacity (CLUTTER_ACTOR (busy), 0);
371 clutter_actor_show (CLUTTER_ACTOR (busy));
373 clutter_effect_fade (template,
374 CLUTTER_ACTOR (busy),
381 woohaa_busy_bounce (WoohaaBusy *busy)
383 WoohaaBusyPrivate *priv;
384 ClutterTimeline *timeline;
387 ClutterBehaviour *behave;
390 timeline = clutter_timeline_new_for_duration (500);
391 alpha = clutter_alpha_new_full (timeline, CLUTTER_ALPHA_SINE, NULL, NULL);
393 behave = clutter_behaviour_busy_new (busy, alpha);
395 clutter_timeline_start (timeline);
397 clutter_actor_get_geometry (CLUTTER_ACTOR (busy), &geo);
401 woohaa_busy_new (void)
403 return g_object_new (WOOHAA_TYPE_BUSY, NULL);
406 /* Custom Behavior */
409 clutter_behaviour_alpha_notify (ClutterBehaviour *behave,
414 busy = (WOOHAA_BEHAVIOUR_BUSY (behave))->busy;
416 busy->priv->spinner_alpha = alpha_value;
417 clutter_actor_queue_relayout (CLUTTER_ACTOR (busy));
421 clutter_behaviour_busy_class_init (WoohaaBehaviourBusyClass *klass)
423 ClutterBehaviourClass *behave_class = CLUTTER_BEHAVIOUR_CLASS (klass);
425 behave_class->alpha_notify = clutter_behaviour_alpha_notify;
429 clutter_behaviour_busy_init (WoohaaBehaviourBusy *self)
433 static ClutterBehaviour*
434 clutter_behaviour_busy_new (WoohaaBusy *busy, ClutterAlpha *alpha)
436 WoohaaBehaviourBusy *busy_behave;
438 busy_behave = g_object_new (WOOHAA_TYPE_BEHAVIOUR_BUSY,
439 "alpha", alpha, NULL);
440 busy_behave->busy = busy;
442 return CLUTTER_BEHAVIOUR(busy_behave);