2 * Copyright © 2010 Yuvaraj Pandian T <yuvipanda@yuvi.in>
3 * Copyright © 2010 daniel g. siegel <dgsiegel@gnome.org>
4 * Copyright © 2008 Filippo Argiolas <filippo.argiolas@gmail.com>
6 * Licensed under the GNU General Public License Version 2
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 internal class Cheese
.Countdown
: GLib
.Object
24 public delegate
void CountdownCallback ();
25 private Clutter
.Text countdown_actor
;
26 private unowned CountdownCallback completed_callback
;
27 private Clutter
.PropertyTransition pulse_in
;
28 private Clutter
.PropertyTransition pulse_out
;
29 private int current_value
= 0;
30 private GLib
.Settings settings
;
33 public Countdown (Clutter
.Text countdown_actor
)
35 this
.countdown_actor
= countdown_actor
;
36 settings
= new GLib
.Settings("org.gnome.Cheese");
45 * Fade the countdown text out, over 500 milliseconds.
47 * Once the fade-out is complete, this method calls fade_in().
49 private void fade_out ()
51 pulse_out
= new Clutter
.PropertyTransition ("opacity");
52 pulse_out
.set_duration (500);
53 pulse_out
.set_from_value (255);
54 pulse_out
.set_to_value (0);
55 pulse_out
.completed
.connect (fade_in
);
56 pulse_out
.animatable
= countdown_actor
;
61 * Decrement the countdown text and fade it in, over 500 milliseconds.
63 * Once the fade-in is complete, this method calls fade_out().
65 private void fade_in ()
67 if (this
.current_value
<= 0)
69 this
.completed_callback ();
73 this
.countdown_actor
.text
= this
.current_value
.to_string ();
76 pulse_in
= new Clutter
.PropertyTransition ("opacity");
77 pulse_in
.set_duration (500);
78 pulse_in
.set_from_value (0);
79 pulse_in
.set_to_value (255);
80 pulse_in
.completed
.connect (fade_out
);
81 pulse_in
.animatable
= countdown_actor
;
86 * Start the countdown, using the countdown-duration GSetting for the time.
88 * @param completed_callback the callback to call upon countdown completion
90 public void start (CountdownCallback completed_callback
)
92 this
.completed_callback
= completed_callback
;
93 this
.current_value
= settings
.get_int("countdown-duration");
95 countdown_actor
.show ();
100 * Stop the countdown, for example if it was interrupted by the user.
104 countdown_actor
.hide ();
105 countdown_actor
.remove_all_transitions ();