[california/wip/725767-week] Print event information, get borders right



commit 3f2f9e4bf848269ce5ad82d2c6a5fa94e9c151ff
Author: Jim Nelson <jim yorba org>
Date:   Thu May 15 16:17:36 2014 -0700

    Print event information, get borders right

 src/util/util-gfx.vala              |    4 ++-
 src/view/view-palette.vala          |    4 ++
 src/view/week/week-day-pane.vala    |   55 ++++++++++++++++++++++++++++-------
 src/view/week/week-hour-runner.vala |    3 ++
 src/view/week/week-pane.vala        |    5 +++
 5 files changed, 59 insertions(+), 12 deletions(-)
---
diff --git a/src/util/util-gfx.vala b/src/util/util-gfx.vala
index e9c83a5..72bab00 100644
--- a/src/util/util-gfx.vala
+++ b/src/util/util-gfx.vala
@@ -7,8 +7,10 @@
 namespace California.Gfx {
 
 public const Gdk.Color RGB_BLACK = { 0, 0, 0 };
+public const Gdk.Color RGB_WHITE = { 255, 255, 255 };
 
-public const Gdk.RGBA RGBA_BLACK = { 0.0, 0.0, 0.0, 0.0 };
+public const Gdk.RGBA RGBA_BLACK = { 0.0, 0.0, 0.0, 1.0 };
+public const Gdk.RGBA RGBA_WHITE = { 1.0, 1.0, 1.0, 1.0 };
 
 /**
  * Convert an RGB string into an RGB structure.
diff --git a/src/view/view-palette.vala b/src/view/view-palette.vala
index ebdbf6e..977ba91 100644
--- a/src/view/view-palette.vala
+++ b/src/view/view-palette.vala
@@ -174,6 +174,8 @@ public class Palette : BaseObject {
     public static Cairo.Context prepare_hairline_border(Cairo.Context ctx) {
         Gdk.cairo_set_source_rgba(ctx, instance.border);
         ctx.set_line_width(HAIRLINE_WIDTH);
+        ctx.set_line_cap(Cairo.LineCap.ROUND);
+        ctx.set_line_join(Cairo.LineJoin.ROUND);
         ctx.set_dash(null, 0);
         
         return ctx;
@@ -185,6 +187,8 @@ public class Palette : BaseObject {
     public static Cairo.Context prepare_hairline_dashed(Cairo.Context ctx) {
         Gdk.cairo_set_source_rgba(ctx, instance.border);
         ctx.set_line_width(HAIRLINE_WIDTH);
+        ctx.set_line_cap(Cairo.LineCap.ROUND);
+        ctx.set_line_join(Cairo.LineJoin.ROUND);
         ctx.set_dash(DASHES, 0);
         
         return ctx;
diff --git a/src/view/week/week-day-pane.vala b/src/view/week/week-day-pane.vala
index 5fe9f13..0ab732e 100644
--- a/src/view/week/week-day-pane.vala
+++ b/src/view/week/week-day-pane.vala
@@ -67,12 +67,15 @@ internal class DayPane : Pane {
         
         base.on_draw(ctx);
         
-        int width = get_allocated_width();
+        // each event is drawn with a slightly-transparent rectangle with a solid hairline bounding
+        Palette.prepare_hairline_border(ctx);
         
         foreach (Component.Event event in days_events) {
+            // TODO: Show all-day events
             if (event.is_all_day)
                 continue;
             
+            // TODO: Show events that spans days
             Calendar.DateSpan date_span = event.get_event_date_span(Calendar.Timezone.local);
             if (!date_span.is_same_day || !(date in date_span))
                 continue;
@@ -85,25 +88,55 @@ internal class DayPane : Pane {
             int start_y = get_line_y(start_time);
             int end_y = get_line_y(end_time);
             
-            Gdk.RGBA bg = event.calendar_source.color_as_rgba();
+            Gdk.RGBA rgba = event.calendar_source.color_as_rgba();
             
-            ctx.move_to(0, start_y);
-            ctx.line_to(width, start_y);
-            ctx.line_to(width, end_y);
-            ctx.line_to(0, end_y);
-            ctx.close_path();
+            // event rectangle
+            ctx.rectangle(0, start_y, get_allocated_width(), end_y - start_y);
             
-            bg.alpha = 0.25;
-            Gdk.cairo_set_source_rgba(ctx, bg);
+            // background rectangle (to prevent hour lines from showing when using alpha, below)
+            Gdk.cairo_set_source_rgba(ctx, Gfx.RGBA_WHITE);
             ctx.fill_preserve();
             
-            bg.alpha = 0.0;
-            Gdk.cairo_set_source_rgba(ctx, bg);
+            // interior rectangle (use alpha to mute colors)
+            rgba.alpha = 0.25;
+            Gdk.cairo_set_source_rgba(ctx, rgba);
+            ctx.fill_preserve();
+            
+            // bounding border line and text color
+            rgba.alpha = 1.0;
+            Gdk.cairo_set_source_rgba(ctx, rgba);
             ctx.stroke();
+            
+            // time range on first line, summary on second ... note that separator character is an
+            // endash
+            string timespan = "%s &#x2013; %s".printf(
+                start_time.to_pretty_string(Calendar.WallTime.PrettyFlag.NONE),
+                end_time.to_pretty_string(Calendar.WallTime.PrettyFlag.NONE));
+            print_line(ctx, start_time, 0, timespan, rgba, true);
+            print_line(ctx, start_time, 1, event.summary, rgba, false);
         }
         
         return true;
     }
+    
+    private void print_line(Cairo.Context ctx, Calendar.WallTime start_time, int lineno, string text,
+        Gdk.RGBA rgba, bool is_markup) {
+        Pango.Layout layout = create_pango_layout(null);
+        if (is_markup)
+            layout.set_markup(text, -1);
+        else
+            layout.set_text(text, -1);
+        layout.set_font_description(Palette.instance.small_font);
+        layout.set_width((get_allocated_width() - (Palette.TEXT_MARGIN_PX * 2)) * Pango.SCALE);
+        layout.set_ellipsize(Pango.EllipsizeMode.END);
+        
+        int y = get_line_y(start_time) + Palette.LINE_PADDING_PX
+            + (Palette.instance.small_font_height_px * lineno);
+        
+        ctx.move_to(Palette.TEXT_MARGIN_PX, y);
+        Gdk.cairo_set_source_rgba(ctx, rgba);
+        Pango.cairo_show_layout(ctx, layout);
+    }
 }
 
 }
diff --git a/src/view/week/week-hour-runner.vala b/src/view/week/week-hour-runner.vala
index 1bcbcf1..9a843c3 100644
--- a/src/view/week/week-hour-runner.vala
+++ b/src/view/week/week-hour-runner.vala
@@ -30,6 +30,9 @@ internal class HourRunner : Pane {
         
         int right_justify_px = get_allocated_width() - Palette.TEXT_MARGIN_PX;
         
+        // draw hours in the border color
+        Gdk.cairo_set_source_rgba(ctx, Palette.instance.border);
+        
         // draw time-of-day down right-hand side of HourRunner pane, which acts as tick marks for
         // the rest of the week view
         Calendar.WallTime wall_time = Calendar.WallTime.earliest;
diff --git a/src/view/week/week-pane.vala b/src/view/week/week-pane.vala
index 5dc53a1..3a03826 100644
--- a/src/view/week/week-pane.vala
+++ b/src/view/week/week-pane.vala
@@ -51,6 +51,9 @@ internal abstract class Pane : Gtk.EventBox {
         int width = get_allocated_width();
         int height = get_allocated_height();
         
+        // save and restore so child override doesn't have to deal with context state issues
+        ctx.save();
+        
         // draw right-side border line
         Palette.prepare_hairline_border(ctx);
         ctx.move_to(width, 0);
@@ -79,6 +82,8 @@ internal abstract class Pane : Gtk.EventBox {
             ctx.stroke();
         }
         
+        ctx.restore();
+        
         return true;
     }
     


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