[california/wip/725767-week] Draw red horizontal line in week view for current time



commit 8e9e166ae5cba2886472e635ce4a3086833ae203
Author: Jim Nelson <jim yorba org>
Date:   Mon May 19 18:28:11 2014 -0700

    Draw red horizontal line in week view for current time

 src/toolkit/toolkit-button-connector.vala |    2 +-
 src/view/month/month-cell.vala            |    2 +-
 src/view/view-palette.vala                |   16 ++++++---
 src/view/week/week-controller.vala        |    4 +-
 src/view/week/week-day-pane.vala          |   56 +++++++++++++++++++++++++++-
 src/view/week/week-grid.vala              |    2 +-
 src/view/week/week-pane.vala              |    6 ++--
 7 files changed, 73 insertions(+), 15 deletions(-)
---
diff --git a/src/toolkit/toolkit-button-connector.vala b/src/toolkit/toolkit-button-connector.vala
index 042d977..49d303b 100644
--- a/src/toolkit/toolkit-button-connector.vala
+++ b/src/toolkit/toolkit-button-connector.vala
@@ -23,7 +23,7 @@ public class ButtonConnector : EventConnector {
     // GDK reports 250ms is used to determine if a click is a double-click (and another 250ms for
     // triple-click), so pause just a little more than that to determine if all the clicking is
     // done
-    private const int CLICK_DETERMINATION_DELAY_MSEC = 250;
+    private const int CLICK_DETERMINATION_DELAY_MSEC = 255;
     
     // The actual ButtonEvent, with some useful functionality for release timeouts
     private class InternalButtonEvent : ButtonEvent {
diff --git a/src/view/month/month-cell.vala b/src/view/month/month-cell.vala
index dfe07c3..aa3b391 100644
--- a/src/view/month/month-cell.vala
+++ b/src/view/month/month-cell.vala
@@ -375,7 +375,7 @@ private class Cell : Gtk.EventBox {
         int height = get_allocated_height();
         
         // draw border lines (creates grid effect)
-        Palette.prepare_hairline_border(ctx);
+        Palette.prepare_hairline(ctx, Palette.instance.border);
         
         // only draw top line if on the top row
         if (row == 0) {
diff --git a/src/view/view-palette.vala b/src/view/view-palette.vala
index 977ba91..68a8238 100644
--- a/src/view/view-palette.vala
+++ b/src/view/view-palette.vala
@@ -64,6 +64,11 @@ public class Palette : BaseObject {
     public Gdk.RGBA current_day { get; private set; }
     
     /**
+     * Foreground color representing current time of day.
+     */
+    public Gdk.RGBA current_time { get; private set; }
+    
+    /**
      * Background color to use for selected days/time.
      */
     public Gdk.RGBA selection { get; private set; }
@@ -117,6 +122,7 @@ public class Palette : BaseObject {
         day_in_range = { red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0 };
         day_outside_range = { red: 0.6, green: 0.6, blue: 0.6, alpha: 1.0 };
         current_day = { red: 0.0, green: 0.25, blue: 0.50, alpha: 0.10 };
+        current_time = { red: 1.0, green: 0.0, blue: 0.0, alpha: 0.90 };
         selection = { red: 0.0, green: 0.50, blue: 0.50, alpha: 0.10 };
         
         normal_font = new Pango.FontDescription();
@@ -169,10 +175,10 @@ public class Palette : BaseObject {
     }
     
     /**
-     * Prepare a Cairo.Context for drawing hairline borders.
+     * Prepare a Cairo.Context for drawing hairlines.
      */
-    public static Cairo.Context prepare_hairline_border(Cairo.Context ctx) {
-        Gdk.cairo_set_source_rgba(ctx, instance.border);
+    public static Cairo.Context prepare_hairline(Cairo.Context ctx, Gdk.RGBA rgba) {
+        Gdk.cairo_set_source_rgba(ctx, rgba);
         ctx.set_line_width(HAIRLINE_WIDTH);
         ctx.set_line_cap(Cairo.LineCap.ROUND);
         ctx.set_line_join(Cairo.LineJoin.ROUND);
@@ -184,8 +190,8 @@ public class Palette : BaseObject {
     /**
      * Prepare a Cairo.Context for drawing hairline dashed lines.
      */
-    public static Cairo.Context prepare_hairline_dashed(Cairo.Context ctx) {
-        Gdk.cairo_set_source_rgba(ctx, instance.border);
+    public static Cairo.Context prepare_hairline_dashed(Cairo.Context ctx, Gdk.RGBA rgba) {
+        Gdk.cairo_set_source_rgba(ctx, rgba);
         ctx.set_line_width(HAIRLINE_WIDTH);
         ctx.set_line_cap(Cairo.LineCap.ROUND);
         ctx.set_line_join(Cairo.LineJoin.ROUND);
diff --git a/src/view/week/week-controller.vala b/src/view/week/week-controller.vala
index f16a667..4a4789c 100644
--- a/src/view/week/week-controller.vala
+++ b/src/view/week/week-controller.vala
@@ -85,14 +85,14 @@ public class Controller : BaseObject, View.Controllable {
      * @inheritDoc
      */
     public void next() {
-        week = week.adjust(1);
+        week = week.next();
     }
     
     /**
      * @inheritDoc
      */
     public void previous() {
-        week = week.adjust(-1);
+        week = week.previous();
     }
     
     /**
diff --git a/src/view/week/week-day-pane.vala b/src/view/week/week-day-pane.vala
index 6af8151..4412386 100644
--- a/src/view/week/week-day-pane.vala
+++ b/src/view/week/week-day-pane.vala
@@ -20,6 +20,7 @@ internal class DayPane : Pane {
     public bool selected { get; set; default = false; }
     
     private Gee.TreeSet<Component.Event> days_events = new Gee.TreeSet<Component.Event>();
+    private uint minutes_timeout_id = 0;
     
     public DayPane(Grid owner, Calendar.Date date) {
         base (owner, -1);
@@ -30,17 +31,58 @@ internal class DayPane : Pane {
         notify[PROP_SELECTED].connect(queue_draw);
         Calendar.System.instance.is_24hr_changed.connect(queue_draw);
         Calendar.System.instance.today_changed.connect(on_today_changed);
+        
+        schedule_monitor_minutes();
     }
     
     ~DayPane() {
         Calendar.System.instance.is_24hr_changed.disconnect(queue_draw);
         Calendar.System.instance.today_changed.disconnect(on_today_changed);
+        
+        cancel_monitor_minutes();
     }
     
     private void on_today_changed(Calendar.Date old_today, Calendar.Date new_today) {
         // need to know re: redrawing background color to indicate current day
-        if (date.equal_to(old_today) || date.equal_to(new_today))
+        if (date.equal_to(old_today) || date.equal_to(new_today)) {
+            schedule_monitor_minutes();
             queue_draw();
+        }
+    }
+    
+    // If this pane is showing the current date, need to update once a minute to move the horizontal
+    // minute indicator
+    private void schedule_monitor_minutes() {
+        cancel_monitor_minutes();
+        
+        if (!date.equal_to(Calendar.System.today))
+            return;
+        
+        // find the number of seconds remaining in this minute and schedule an update then
+        int remaining_sec = (Calendar.WallTime.SECONDS_PER_MINUTE - Calendar.System.now.second).clamp(
+            0, Calendar.WallTime.SECONDS_PER_MINUTE);
+        minutes_timeout_id = Timeout.add_seconds(remaining_sec, on_minute_changed);
+    }
+    
+    private bool on_minute_changed() {
+        // done this iteration
+        minutes_timeout_id = 0;
+        
+        // repaint time indicator
+        queue_draw();
+        
+        // reschedule
+        schedule_monitor_minutes();
+        
+        return false;
+    }
+    
+    private void cancel_monitor_minutes() {
+        if (minutes_timeout_id == 0)
+            return;
+        
+        Source.remove(minutes_timeout_id);
+        minutes_timeout_id = 0;
     }
     
     public void add_event(Component.Event event) {
@@ -86,7 +128,7 @@ internal class DayPane : Pane {
         base.on_draw(ctx);
         
         // each event is drawn with a slightly-transparent rectangle with a solid hairline bounding
-        Palette.prepare_hairline_border(ctx);
+        Palette.prepare_hairline(ctx, Palette.instance.border);
         
         foreach (Component.Event event in days_events) {
             // TODO: Show all-day events
@@ -135,6 +177,16 @@ internal class DayPane : Pane {
             print_line(ctx, start_time, 1, event.summary, rgba, rect_width, false);
         }
         
+        // draw horizontal line indicating current time
+        if (date.equal_to(Calendar.System.today)) {
+            int time_of_day_y = get_line_y(new Calendar.WallTime.from_exact_time(Calendar.System.now));
+            
+            Palette.prepare_hairline(ctx, Palette.instance.current_time);
+            ctx.move_to(0, time_of_day_y);
+            ctx.line_to(get_allocated_width(), time_of_day_y);
+            ctx.stroke();
+        }
+        
         return true;
     }
     
diff --git a/src/view/week/week-grid.vala b/src/view/week/week-grid.vala
index eb4f214..4a1ad47 100644
--- a/src/view/week/week-grid.vala
+++ b/src/view/week/week-grid.vala
@@ -133,7 +133,7 @@ internal class Grid : Gtk.Box {
         int width = widget.get_allocated_width();
         int height = widget.get_allocated_height();
         
-        Palette.prepare_hairline_border(ctx);
+        Palette.prepare_hairline(ctx, Palette.instance.border);
         ctx.move_to(0, height);
         ctx.line_to(width, height);
         ctx.stroke();
diff --git a/src/view/week/week-pane.vala b/src/view/week/week-pane.vala
index b9fac89..728b7b5 100644
--- a/src/view/week/week-pane.vala
+++ b/src/view/week/week-pane.vala
@@ -55,7 +55,7 @@ internal abstract class Pane : Gtk.EventBox {
         ctx.save();
         
         // draw right-side border line
-        Palette.prepare_hairline_border(ctx);
+        Palette.prepare_hairline(ctx, Palette.instance.border);
         ctx.move_to(width, 0);
         ctx.line_to(width, height);
         ctx.line_to(0, height);
@@ -73,9 +73,9 @@ internal abstract class Pane : Gtk.EventBox {
             
             // solid line on the hour, dashed on the half-hour
             if (wall_time.minute == 0)
-                Palette.prepare_hairline_border(ctx);
+                Palette.prepare_hairline(ctx, Palette.instance.border);
             else
-                Palette.prepare_hairline_dashed(ctx);
+                Palette.prepare_hairline_dashed(ctx, Palette.instance.border);
             
             ctx.move_to(0, line_y);
             ctx.line_to(width, line_y);


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