[gnome-clocks/wip/analogtimer] Experiment with a circular progress for timer



commit 63924d2340939a6d058625b556d59c8a8f6b5a4b
Author: Paolo Borelli <pborelli gnome org>
Date:   Mon Jul 29 13:08:23 2013 +0200

    Experiment with a circular progress for timer
    
    This is an experiment to play with the idea of showing some kind of
    progress to spice up the timer panel.
    This is far from working: the idea of subclassing GtkFrame is just a
    quick hack and for now it breaks when resizing. The progress also resets
    when the timer is paused.

 src/timer.vala |   62 +++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 55 insertions(+), 7 deletions(-)
---
diff --git a/src/timer.vala b/src/timer.vala
index 0b1b36e..dd9a84e 100644
--- a/src/timer.vala
+++ b/src/timer.vala
@@ -19,6 +19,48 @@
 namespace Clocks {
 namespace Timer {
 
+public class CountdownFrame : Gtk.Frame {
+    public double progress { get; set; }
+
+    public override bool draw (Cairo.Context cr) {
+        base.draw(cr);
+
+        var context = get_style_context ();
+
+        Gtk.Allocation allocation;
+        get_allocation (out allocation);
+        var center_x = allocation.width / 2;
+        var center_y = allocation.height / 2;
+
+        var radius = int.min (allocation.width, allocation.height) / 3;
+        cr.move_to (center_x + radius, center_y);
+
+        cr.set_line_width (1);
+        var color = context.get_border_color (Gtk.StateFlags.SELECTED);
+        Gdk.cairo_set_source_rgba (cr, color);
+        cr.arc (center_x, center_y, radius, 0, 2 * Math.PI);
+        cr.arc (center_x, center_y, radius + 9, 0, 2 * Math.PI);
+        cr.stroke ();
+
+        cr.set_line_width (8);
+
+        color = context.get_color (Gtk.StateFlags.SELECTED);
+        cr.arc (center_x, center_y, radius + 4.5, 0, 2 * Math.PI);
+        Gdk.cairo_set_source_rgba (cr, color);
+        cr.stroke ();
+
+        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);
+            Gdk.cairo_set_source_rgba (cr, color);
+            cr.stroke ();
+        }
+
+        return false;
+    }
+
+}
+
 public class MainPanel : Gtk.Stack, Clocks.Clock {
     enum State {
         STOPPED,
@@ -39,7 +81,7 @@ public class MainPanel : Gtk.Stack, Clocks.Clock {
     private Gtk.SpinButton m_spinbutton;
     private Gtk.SpinButton s_spinbutton;
     private Gtk.Button start_button;
-    private Gtk.Widget countdown_panel;
+    private CountdownFrame countdown_frame;
     private Gtk.Label time_label;
     private Gtk.Button left_button;
     private Gtk.Button right_button;
@@ -77,7 +119,12 @@ public class MainPanel : Gtk.Stack, Clocks.Clock {
             start ();
         });
 
-        countdown_panel = builder.get_object ("countdown_panel") as Gtk.Widget;
+        countdown_frame = new CountdownFrame ();
+        countdown_frame.show();
+
+        var countdown_widgets = builder.get_object ("countdown_panel") as Gtk.Widget;
+        countdown_frame.add (countdown_widgets);
+
         time_label = builder.get_object ("time_label") as Gtk.Label;
         left_button = builder.get_object ("left_button") as Gtk.Button;
         right_button = builder.get_object ("right_button") as Gtk.Button;
@@ -105,7 +152,7 @@ public class MainPanel : Gtk.Stack, Clocks.Clock {
         });
 
         add (setup_panel);
-        add (countdown_panel);
+        add (countdown_frame);
 
         reset ();
 
@@ -160,7 +207,7 @@ public class MainPanel : Gtk.Stack, Clocks.Clock {
             settings.set_uint ("timer", (uint) span);
 
             timer.start ();
-            visible_child = countdown_panel;
+            visible_child = countdown_frame;
 
             update_countdown_label (h, m, s);
             add_timeout ();
@@ -204,22 +251,23 @@ public class MainPanel : Gtk.Stack, Clocks.Clock {
             return false;
         }
 
-        update_countdown (span - e);
+        update_countdown (e);
         return true;
     }
 
-    private void update_countdown (double t) {
+    private void update_countdown (double elapsed) {
         if (time_label.get_mapped ()) {
             // Math.ceil() because we count backwards:
             // with 0.3 seconds we want to show 1 second remaining,
             // with 59.2 seconds we want to show 1 minute, etc
-            t = Math.ceil (t);
+            double t = Math.ceil (span - elapsed);
             int h;
             int m;
             int s;
             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;
         }
     }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]