[gnome-clocks/wip/analogtimer] Fix pausing the analog timer
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-clocks/wip/analogtimer] Fix pausing the analog timer
- Date: Fri, 2 Aug 2013 07:25:52 +0000 (UTC)
commit d33504dee3535f608de2a43d4c048d72cde41b16
Author: Paolo Borelli <pborelli gnome org>
Date: Fri Aug 2 09:23:35 2013 +0200
Fix pausing the analog timer
src/timer.vala | 19 +++++++++++++++++--
1 files changed, 17 insertions(+), 2 deletions(-)
---
diff --git a/src/timer.vala b/src/timer.vala
index 88258bc..2e84c7d 100644
--- a/src/timer.vala
+++ b/src/timer.vala
@@ -22,10 +22,16 @@ namespace Timer {
public class CountdownFrame : Gtk.Frame {
private const int RADIUS_PAD = 36;
- public double progress { get; set; }
+ public double span { get; set; default = 0; }
+ public double elapsed { get; set; default = 0; }
+ private double elapsed_before_pause;
private Cairo.Pattern cursor_pattern;
+ private double get_progress () {
+ return span != 0 ? (elapsed_before_pause + elapsed) / span : 0;
+ }
+
private int calculate_diameter () {
var child = get_child ();
if (child != null && child.visible) {
@@ -38,6 +44,11 @@ public class CountdownFrame : Gtk.Frame {
}
}
+ public void pause () {
+ elapsed_before_pause += elapsed;
+ elapsed = 0;
+ }
+
public override void get_preferred_width (out int min_w, out int natural_w) {
var d = calculate_diameter ();
min_w = d;
@@ -93,6 +104,7 @@ public class CountdownFrame : Gtk.Frame {
Gdk.cairo_set_source_rgba (cr, color);
cr.stroke ();
+ var progress = get_progress ();
if (progress > 0) {
color = context.get_background_color (Gtk.StateFlags.SELECTED);
cr.arc (center_x, center_y, radius - 4.5, 1.5 * Math.PI, (1.5 + progress * 2 ) * Math.PI);
@@ -267,6 +279,8 @@ public class MainPanel : Gtk.Stack, Clocks.Clock {
settings.set_uint ("timer", (uint) span);
timer.start ();
+
+ countdown_frame.span = span;
visible_child = countdown_frame;
update_countdown_label (h, m, s);
@@ -284,6 +298,7 @@ public class MainPanel : Gtk.Stack, Clocks.Clock {
state = State.PAUSED;
timer.stop ();
span -= timer.elapsed ();
+ countdown_frame.pause ();
remove_timeout ();
}
@@ -327,7 +342,7 @@ public class MainPanel : Gtk.Stack, Clocks.Clock {
double r;
Utils.time_to_hms (t, out h, out m, out s, out r);
update_countdown_label (h, m, s);
- countdown_frame.progress = elapsed / span;
+ countdown_frame.elapsed = elapsed;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]