[planner: 47/61] gantt-row: Port to cairo drawing




commit 4627befbd929dff34ac133cb2fef498622a275d9
Author: Mart Raudsepp <leio gentoo org>
Date:   Sat Jan 2 18:40:45 2021 +0200

    gantt-row: Port to cairo drawing

 src/planner-gantt-row.c | 615 +++++++++++++++++-------------------------------
 1 file changed, 213 insertions(+), 402 deletions(-)
---
diff --git a/src/planner-gantt-row.c b/src/planner-gantt-row.c
index a66f51f9..cc3a2acb 100644
--- a/src/planner-gantt-row.c
+++ b/src/planner-gantt-row.c
@@ -50,9 +50,8 @@
 #define SNAP (60.0*15.0)
 
 /* Constants for the summary bracket. */
-#define HEIGHT 5
 #define THICKNESS 2
-#define SLOPE 4
+#define SLOPE 5
 
 #define MILESTONE_SIZE 5
 
@@ -61,21 +60,6 @@
 /* Minimum width for a task to keep it visible. */
 #define MIN_WIDTH 2
 
-/* Trim the value to short int work space. */
-#define TRSH(a) ((int)((a) < SHRT_MIN ? (short int)SHRT_MIN : ((a) > SHRT_MAX ? (short int)SHRT_MAX : (a))))
-
-/* Same gdk_draw_rectangle but with trimmed x,y,w,h args. */
-#define draw_cut_rectangle(a,b,c,d,e,f,g)              \
-               gdk_draw_rectangle ((a), (b), (c), TRSH (d), TRSH (e), TRSH (f), TRSH (g))
-
-/* Same gdk_draw_line but with trimmed x1,y1,x2,y2 args. */
-#define draw_cut_line(a,b,c,d,e,f)              \
-               gdk_draw_line ((a), (b), TRSH (c), TRSH (d), TRSH (e), TRSH (f))
-
-/* Same gdk_draw_layout but with trimmed x,y args. */
-#define draw_cut_layout(a,b,c,d,e)                      \
-               gdk_draw_layout ((a), (b), TRSH (c), TRSH (d), (e))
-
 enum {
        PROP_0,
        PROP_X,
@@ -114,13 +98,6 @@ typedef enum
 } DragSpot;
 
 struct _PlannerGanttRowPriv {
-       /* FIXME: Don't need those per gantt row. */
-       GdkGC       *complete_gc;
-       GdkGC       *fill_gc;
-       GdkGC       *frame_gc;
-       GdkGC       *ttask_gc;
-
-
        /* FIXME: Don't need those per gantt row. */
        GdkColor     color_normal;
        GdkColor     color_normal_light;
@@ -183,8 +160,6 @@ static void     gantt_row_update                      (GnomeCanvasItem       *it
                                                       double                *affine,
                                                       ArtSVP                *clip_path,
                                                       int                    flags);
-static void     gantt_row_realize                     (GnomeCanvasItem       *item);
-static void     gantt_row_unrealize                   (GnomeCanvasItem       *item);
 static void     gantt_row_draw                        (GnomeCanvasItem       *item,
                                                       GdkDrawable           *drawable,
                                                       gint                   x,
@@ -256,8 +231,7 @@ static MrpInterval *      mop_get_next_mrp_ival       (GList                **cu
                                                        gint                  *is_a_gap,
                                                        GList                 *start,
                                                        MrpInterval           *buf);
-static gboolean gantt_draw_tasktime                   (GdkDrawable           *drawable,
-                                                      GdkGC                 *gc,
+static gboolean gantt_draw_tasktime                   (cairo_t               *cr,
                                                       GnomeCanvas           *canvas,
                                                       gdouble                start_wx,
                                                       gdouble                start_wy,
@@ -273,8 +247,6 @@ static gboolean gantt_draw_tasktime                   (GdkDrawable           *dr
 
 static GnomeCanvasItemClass *parent_class;
 static guint                 signals[LAST_SIGNAL];
-static GdkBitmap            *complete_stipple = NULL;
-static gchar                 complete_stipple_pattern[] = { 0x02, 0x01 };
 
 /* Data related to dragging items */
 static GnomeCanvasItem   *drag_item;
@@ -408,8 +380,6 @@ gantt_row_class_init (PlannerGanttRowClass *class)
        object_class->destroy = gantt_row_destroy;
 
        item_class->update = gantt_row_update;
-       item_class->realize = gantt_row_realize;
-       item_class->unrealize = gantt_row_unrealize;
        item_class->draw = gantt_row_draw;
        item_class->point = gantt_row_point;
        item_class->bounds = gantt_row_bounds;
@@ -434,6 +404,13 @@ gantt_row_init (PlannerGanttRow *row)
        priv->highlight = FALSE;
        priv->mouse_over_index = -1;
        priv->resource_widths = g_array_new (TRUE, FALSE, sizeof (gint));
+
+       gdk_color_parse ("LightSkyBlue3", &priv->color_normal);
+       gdk_color_parse ("#9ac7e0", &priv->color_normal_light);
+       gdk_color_parse ("#7da1b5", &priv->color_normal_dark);
+       gdk_color_parse ("indian red", &priv->color_critical);
+       gdk_color_parse ("#de6464", &priv->color_critical_light);
+       gdk_color_parse ("#ba5454", &priv->color_critical_dark);
 }
 
 static void
@@ -828,94 +805,14 @@ gantt_row_update (GnomeCanvasItem *item,
 }
 
 static void
-gantt_row_realize (GnomeCanvasItem *item)
+gantt_row_setup_frame_dashes (PlannerGanttRow *row, cairo_t *cr, gboolean highlight)
 {
-       PlannerGanttRow     *row;
-       PlannerGanttRowPriv *priv;
-
-       row = PLANNER_GANTT_ROW (item);
-       priv = row->priv;
-
-       GNOME_CANVAS_ITEM_CLASS (parent_class)->realize (item);
-
-       if (complete_stipple == NULL) {
-               complete_stipple = gdk_bitmap_create_from_data (
-                       NULL,
-                       complete_stipple_pattern,
-                       2,
-                       2);
-
-               g_object_add_weak_pointer (G_OBJECT (complete_stipple),
-                                          (gpointer) &complete_stipple);
+       if (highlight) {
+               const double dashes[] = { 3.0, 5.0 }; /* 4 on + 4 off with CAIRO_LINE_CAP_SQUARE */
+               cairo_set_dash (cr, dashes, G_N_ELEMENTS (dashes), 0.0);
        } else {
-               g_object_ref (complete_stipple);
-       }
-
-       priv->complete_gc = gdk_gc_new (item->canvas->layout.bin_window);
-       gdk_gc_set_stipple (priv->complete_gc, complete_stipple);
-       gdk_gc_set_fill (priv->complete_gc, GDK_STIPPLED);
-
-       priv->fill_gc = gdk_gc_new (item->canvas->layout.bin_window);
-
-       priv->frame_gc = gdk_gc_new (item->canvas->layout.bin_window);
-
-       priv->ttask_gc = gdk_gc_new (item->canvas->layout.bin_window);
-
-       gnome_canvas_get_color (item->canvas,
-                               "LightSkyBlue3",
-                               &priv->color_normal);
-       gnome_canvas_get_color (item->canvas,
-                               "#9ac7e0",
-                               &priv->color_normal_light);
-       gnome_canvas_get_color (item->canvas,
-                               "#7da1b5",
-                               &priv->color_normal_dark);
-
-       gnome_canvas_get_color (item->canvas,
-                               "indian red",
-                               &priv->color_critical);
-       gnome_canvas_get_color (item->canvas,
-                               "#de6464",
-                               &priv->color_critical_light);
-       gnome_canvas_get_color (item->canvas,
-                               "#ba5454",
-                               &priv->color_critical_dark);
-}
-
-static void
-gantt_row_unrealize (GnomeCanvasItem *item)
-{
-       PlannerGanttRow *row;
-
-       row = PLANNER_GANTT_ROW (item);
-
-       g_object_unref (row->priv->complete_gc);
-       row->priv->complete_gc = NULL;
-
-       g_object_unref (row->priv->fill_gc);
-       row->priv->fill_gc = NULL;
-
-       g_object_unref (row->priv->frame_gc);
-       row->priv->frame_gc = NULL;
-
-       g_object_unref (row->priv->ttask_gc);
-       row->priv->ttask_gc = NULL;
-
-       if (complete_stipple) {
-               g_object_unref (complete_stipple);
+               cairo_set_dash (cr, NULL, 0, 0.0);
        }
-
-       GNOME_CANVAS_ITEM_CLASS (parent_class)->unrealize (item);
-}
-
-static void
-gantt_row_setup_frame_gc (PlannerGanttRow *row, gboolean highlight)
-{
-       gdk_gc_set_line_attributes (row->priv->frame_gc,
-                                   1,
-                                   highlight ? GDK_LINE_ON_OFF_DASH : GDK_LINE_SOLID,
-                                   GDK_CAP_BUTT,
-                                   GDK_JOIN_MITER);
 }
 
 
@@ -1070,17 +967,15 @@ static MrpInterval *mop_get_next_mrp_ival(GList **cur, gint *is_a_gap, GList *st
 }
 
 
-static gboolean gantt_draw_tasktime(GdkDrawable *drawable,
-                                                        GdkGC *gc,
-                                                        GnomeCanvas *canvas,
-                                                        gdouble start_wx, gdouble start_wy,
-                                                        gdouble end_wx, gdouble end_wy,
-                                                        gint cy1, gint cy2,
-                                                        gint x, gint y,
-                                                        gboolean is_up,
-                                                        gchar *colorname)
+static gboolean gantt_draw_tasktime(cairo_t *cr,
+                                   GnomeCanvas *canvas,
+                                   gdouble start_wx, gdouble start_wy,
+                                   gdouble end_wx, gdouble end_wy,
+                                   gint cy1, gint cy2,
+                                   gint x, gint y,
+                                   gboolean is_up,
+                                   gchar *colorname)
 {
-       GdkColor color;
        gint ttime_x1, ttime_y1, ttime_x2, ttime_y2;
 
        gnome_canvas_w2c (canvas, start_wx,  start_wy, &ttime_x1, &ttime_y1);
@@ -1089,47 +984,46 @@ static gboolean gantt_draw_tasktime(GdkDrawable *drawable,
        ttime_x2 -= x;  ttime_y2 -= y;
 
        if (ttime_x2 > ttime_x1) {
-               gnome_canvas_get_color (canvas, colorname, &color);
-               gdk_gc_set_foreground (gc, &color);
+               GdkColor color;
+
+               gdk_color_parse (colorname, &color);
+               gdk_cairo_set_source_color (cr, &color);
 
                if (is_up) {
-                       draw_cut_rectangle (drawable,
-                                                               gc,
-                                                               TRUE,
-                                                               ttime_x1,
-                                                               ttime_y1,
-                                                               ttime_x2 - ttime_x1,
-                                                               cy1 - ttime_y1);
-
-                       gnome_canvas_get_color (canvas, "gray40", &color);
-                       gdk_gc_set_foreground (gc, &color);
-
-               draw_cut_line (drawable, gc, ttime_x1, ttime_y1,
-                                          ttime_x2-1, ttime_y1);
-               draw_cut_line (drawable, gc, ttime_x1, ttime_y1,
-                                          ttime_x1, cy1-1);
+                       cairo_rectangle (cr,
+                                        ttime_x1, ttime_y1,
+                                        ttime_x2 - ttime_x1, cy1 - ttime_y1);
+                       cairo_fill (cr);
+
+                       gdk_color_parse ("gray40", &color);
+                       gdk_cairo_set_source_color (cr, &color);
+
+                       cairo_move_to (cr, ttime_x1 + 0.5, ttime_y1 + 0.5);
+                       cairo_line_to (cr, ttime_x2 - 1 + 0.5, ttime_y1 + 0.5);
+                       cairo_move_to (cr, ttime_x1 + 0.5, ttime_y1 + 0.5);
+                       cairo_line_to (cr, ttime_x1 + 0.5, cy1 - 1 + 0.5);
+                       cairo_stroke (cr);
                }
                else {
-                       draw_cut_rectangle (drawable,
-                                                               gc,
-                                                               TRUE,
-                                                               ttime_x1, cy2+1,
-                                                               ttime_x2 - ttime_x1,
-                                                               ttime_y2 - cy2 - 1);
-
-                       gnome_canvas_get_color (canvas, "gray40", &color);
-                       gdk_gc_set_foreground (gc, &color);
-
-                       draw_cut_line (drawable, gc, ttime_x1, ttime_y2,
-                                                  ttime_x2-1, ttime_y2);
-                       draw_cut_line (drawable, gc, ttime_x1, cy2+1,
-                                                  ttime_x1, ttime_y2);
+                       cairo_rectangle (cr,
+                                        ttime_x1, cy2+1,
+                                        ttime_x2 - ttime_x1, ttime_y2 - cy2 - 1);
+                       cairo_fill (cr);
+
+                       gdk_color_parse ("gray40", &color);
+                       gdk_cairo_set_source_color (cr, &color);
+
+                       cairo_move_to (cr, ttime_x1 + 0.5, ttime_y2 + 0.5);
+                       cairo_line_to (cr, ttime_x2 - 1 + 0.5, ttime_y2 + 0.5);
+                       cairo_move_to (cr, ttime_x1 + 0.5, cy2 + 1 + 0.5);
+                       cairo_line_to (cr, ttime_x1 + 0.5, ttime_y2 + 0.5);
+                       cairo_stroke (cr);
                }
 
-               return (TRUE);
+               return TRUE;
        }
        else {
-               return (FALSE);
+               return FALSE;
        }
 }
 
@@ -1144,6 +1038,7 @@ gantt_row_draw (GnomeCanvasItem *item,
        PlannerGanttRow     *row;
        PlannerGanttRowPriv *priv;
        PlannerGanttChart   *chart;
+       cairo_t             *cr;
        gdouble              i2w_dx;
        gdouble              i2w_dy;
        gdouble              dx1, dy1, dx2, dy2, dshay1, dshay2;
@@ -1151,7 +1046,6 @@ gantt_row_draw (GnomeCanvasItem *item,
        MrpTaskType          type;
        gboolean             summary;
        gint                 summary_y;
-       GdkPoint             points[4];
        gint                 percent_complete;
        gint                 complete_x2, complete_width;
        gboolean             highlight_critical;
@@ -1275,9 +1169,14 @@ gantt_row_draw (GnomeCanvasItem *item,
                return;
        }
 
+       cr = gdk_cairo_create (drawable);
+       cairo_set_line_width (cr, 1.0);
+       cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
+
        summary_y = floor (priv->y + 2 * priv->bar_top + 0.5) - y;
 
        /* "Clip" the expose area. */
+       /* TODO: Use cairo_clip instead of complicated manual handling via rx/ry vs cx/cy */
        rx1 = MAX (cx1, 0);
        rx2 = MIN (cx2, width);
 
@@ -1299,26 +1198,14 @@ gantt_row_draw (GnomeCanvasItem *item,
                complete_x2 = MIN (cx1 + complete_width, rx2);
        }
 
-       gantt_row_setup_frame_gc (row, !summary && priv->highlight);
-
        if (type == MRP_TASK_TYPE_NORMAL && !summary && rx1 <= rx2) {
-               if (complete_width > 0) {
-                       gnome_canvas_set_stipple_origin (item->canvas,
-                                                        priv->complete_gc);
-               }
-
                if (assignments) {
                        /* #define DRAW_BACKGROUND_CHECK 1 */
 #ifdef DRAW_BACKGROUND_CHECK
-                       gnome_canvas_get_color (item->canvas, "indian red", &color);
-                       gdk_gc_set_foreground (priv->fill_gc, &color);
-                       draw_cut_rectangle (drawable,
-                                                               priv->fill_gc,
-                                                               TRUE,
-                                                               rx1,
-                                                               cy1,
-                                                               rx2 - rx1,
-                                                               cy2 - cy1);
+                       gdk_color_parse ("indian red", &color);
+                       gdk_cairo_set_source_color (cr, &color);
+                       cairo_rectangle (cr, rx1, cy1, rx2 - rx1, cy2 - cy1);
+                       cairo_fill (cr);
 #endif
 
                        /* Start slices drawer */
@@ -1477,12 +1364,12 @@ gantt_row_draw (GnomeCanvasItem *item,
                                                if (planner_scale_conf[level].nonworking_limit <=
                                                        shadup_end - shadup_start) {
 
-                                                       gantt_draw_tasktime (drawable, priv->ttask_gc, 
item->canvas,
-                                                                               (shadup_start * priv->scale) 
+ i2w_dx,
-                                                                               dshay1 + i2w_dy,
-                                                                               (shadup_end * priv->scale) + 
i2w_dx,
-                                                                               dshay2 + i2w_dy,
-                                                                               cy1, cy2, x, y,  TRUE, 
"grey96");
+                                                       gantt_draw_tasktime (cr, item->canvas,
+                                                                            (shadup_start * priv->scale) + 
i2w_dx,
+                                                                            dshay1 + i2w_dy,
+                                                                            (shadup_end * priv->scale) + 
i2w_dx,
+                                                                            dshay2 + i2w_dy,
+                                                                            cy1, cy2, x, y,  TRUE, "grey96");
                                                }
                                                shadup_draw_it = FALSE;
                                                shadup_is_cached = FALSE;
@@ -1498,7 +1385,7 @@ gantt_row_draw (GnomeCanvasItem *item,
                                                if (planner_scale_conf[level].nonworking_limit <=
                                                        shaddo_end - shaddo_start) {
 
-                                                       gantt_draw_tasktime (drawable, priv->ttask_gc, 
item->canvas,
+                                                       gantt_draw_tasktime (cr, item->canvas,
                                                                             (shaddo_start * priv->scale) + 
i2w_dx,
                                                                             dshay1 + i2w_dy,
                                                                             (shaddo_end * priv->scale) + 
i2w_dx,
@@ -1519,7 +1406,7 @@ gantt_row_draw (GnomeCanvasItem *item,
                                                if (planner_scale_conf[level].nonworking_limit <=
                                                        workup_end - workup_start) {
 
-                                                       gantt_draw_tasktime (drawable, priv->ttask_gc, 
item->canvas,
+                                                       gantt_draw_tasktime (cr, item->canvas,
                                                                             (workup_start * priv->scale) + 
i2w_dx,
                                                                             dshay1 + i2w_dy,
                                                                             (workup_end * priv->scale) + 
i2w_dx,
@@ -1540,7 +1427,7 @@ gantt_row_draw (GnomeCanvasItem *item,
                                                if (planner_scale_conf[level].nonworking_limit <=
                                                        workdo_end - workdo_start) {
 
-                                                       gantt_draw_tasktime (drawable, priv->ttask_gc, 
item->canvas,
+                                                       gantt_draw_tasktime (cr, item->canvas,
                                                                             (workdo_start * priv->scale) + 
i2w_dx,
                                                                             dshay1 + i2w_dy,
                                                                             (workdo_end * priv->scale) + 
i2w_dx,
@@ -1580,9 +1467,9 @@ gantt_row_draw (GnomeCanvasItem *item,
 
                                topy = floor ((cy1 + ((1.0 - (double)delta) * (double)(cy2 - cy1 - 3))) + 
0.5);
                                if (!highlight_critical || !critical) {
-                                       gdk_gc_set_foreground (priv->fill_gc, &priv->color_normal);
+                                       gdk_cairo_set_source_color (cr, &priv->color_normal);
                                } else {
-                                       gdk_gc_set_foreground (priv->fill_gc, &priv->color_critical);
+                                       gdk_cairo_set_source_color (cr, &priv->color_critical);
                                }
 
                                if (wunits_draw_it) {
@@ -1594,24 +1481,21 @@ gantt_row_draw (GnomeCanvasItem *item,
                                        }
 
                                        if ((cy2 - topy - 3) > 0) {
-                                               draw_cut_rectangle (drawable,
-                                                                       priv->fill_gc,
-                                                                       TRUE,
-                                                                       wunits_x_start,
-                                                                       topy + 2,
-                                                                       x_end - wunits_x_start,
-                                                                       cy2 - topy - 3);
+                                               cairo_rectangle (cr,
+                                                                wunits_x_start,
+                                                                topy + 2,
+                                                                x_end - wunits_x_start,
+                                                                cy2 - topy - 3);
+                                               cairo_fill (cr);
                                        }
                                        if (topy  - cy1 > 0) {
-                                               gnome_canvas_get_color (item->canvas, "white", &color);
-                                               gdk_gc_set_foreground (priv->fill_gc, &color);
-                                               draw_cut_rectangle (drawable,
-                                                                       priv->fill_gc,
-                                                                       TRUE,
-                                                                       wunits_x_start,
-                                                                       cy1+2,
-                                                                       x_end - wunits_x_start,
-                                                                       topy - cy1);
+                                               gdk_color_parse ("white", &color);
+                                               gdk_cairo_set_source_color (cr, &color);
+                                               cairo_rectangle (cr, wunits_x_start,
+                                                                cy1+2,
+                                                                x_end - wunits_x_start,
+                                                                topy - cy1);
+                                               cairo_fill (cr);
                                        }
                                }
 
@@ -1663,24 +1547,24 @@ gantt_row_draw (GnomeCanvasItem *item,
                                if (shadup_is_cached) {
                                        shadup_end = last_end;
 
-                                       gantt_draw_tasktime (drawable, priv->ttask_gc, item->canvas,
-                                                               (shadup_start * priv->scale) + i2w_dx,
-                                                               dshay1 + i2w_dy,
-                                                               (shadup_end * priv->scale) + i2w_dx,
-                                                               dshay2 + i2w_dy,
-                                                               cy1, cy2, x, y,  TRUE, "grey96");
+                                       gantt_draw_tasktime (cr, item->canvas,
+                                                            (shadup_start * priv->scale) + i2w_dx,
+                                                            dshay1 + i2w_dy,
+                                                            (shadup_end * priv->scale) + i2w_dx,
+                                                            dshay2 + i2w_dy,
+                                                            cy1, cy2, x, y,  TRUE, "grey96");
                                }
 
                                /* Show shad down. */
                                if (shaddo_is_cached) {
                                        shaddo_end = last_end;
 
-                                       gantt_draw_tasktime (drawable, priv->ttask_gc, item->canvas,
-                                                               (shaddo_start * priv->scale) + i2w_dx,
-                                                               dshay1 + i2w_dy,
-                                                               (shaddo_end * priv->scale) + i2w_dx,
-                                                               dshay2 + i2w_dy,
-                                                               cy1, cy2, x, y,  FALSE, "grey96");
+                                       gantt_draw_tasktime (cr, item->canvas,
+                                                            (shaddo_start * priv->scale) + i2w_dx,
+                                                            dshay1 + i2w_dy,
+                                                            (shaddo_end * priv->scale) + i2w_dx,
+                                                            dshay2 + i2w_dy,
+                                                            cy1, cy2, x, y,  FALSE, "grey96");
                                }
 
                                /*
@@ -1691,238 +1575,165 @@ gantt_row_draw (GnomeCanvasItem *item,
                                if (workup_is_cached) {
                                        workup_end = last_end;
 
-                                       gantt_draw_tasktime (drawable, priv->ttask_gc, item->canvas,
-                                                               (workup_start * priv->scale) + i2w_dx,
-                                                               dshay1 + i2w_dy,
-                                                               (workup_end * priv->scale) + i2w_dx,
-                                                               dshay2 + i2w_dy,
-                                                               cy1, cy2, x, y,  TRUE, "white");
+                                       gantt_draw_tasktime (cr, item->canvas,
+                                                            (workup_start * priv->scale) + i2w_dx,
+                                                            dshay1 + i2w_dy,
+                                                            (workup_end * priv->scale) + i2w_dx,
+                                                            dshay2 + i2w_dy,
+                                                            cy1, cy2, x, y,     TRUE, "white");
                                }
 
                                /* Show work down. */
                                if (workdo_is_cached) {
                                        workdo_end = last_end;
 
-                                       gantt_draw_tasktime (drawable, priv->ttask_gc, item->canvas,
-                                                               (workdo_start * priv->scale) + i2w_dx,
-                                                               dshay1 + i2w_dy,
-                                                               (workdo_end * priv->scale) + i2w_dx,
-                                                               dshay2 + i2w_dy,
-                                                               cy1, cy2, x, y,  FALSE, "white");
+                                       gantt_draw_tasktime (cr, item->canvas,
+                                                            (workdo_start * priv->scale) + i2w_dx,
+                                                            dshay1 + i2w_dy,
+                                                            (workdo_end * priv->scale) + i2w_dx,
+                                                            dshay2 + i2w_dy,
+                                                            cy1, cy2, x, y,  FALSE, "white");
                                }
                        }
                }
                else { /* if (assignments) ... */
                        if (!highlight_critical || !critical) {
-                               gdk_gc_set_foreground (priv->fill_gc, &priv->color_normal);
+                               gdk_cairo_set_source_color (cr, &priv->color_normal);
                        } else {
-                               gdk_gc_set_foreground (priv->fill_gc, &priv->color_critical);
+                               gdk_cairo_set_source_color (cr, &priv->color_critical);
                        }
-                       draw_cut_rectangle (drawable,
-                                               priv->fill_gc,
-                                               TRUE,
-                                               rx1,
-                                               cy1,
-                                               rx2 - rx1,
-                                               cy2 - cy1);
+                       cairo_rectangle (cr,
+                                        rx1,
+                                        cy1,
+                                        rx2 - rx1,
+                                        cy2 - cy1);
+                       cairo_fill (cr);
                }
 
 
-               gnome_canvas_get_color (item->canvas, "black", &color);
-               gdk_gc_set_foreground (priv->frame_gc, &color);
-
                if (ival_subbuf) {
                        mrp_interval_unref (ival_subbuf);
                }
 
-               if (!highlight_critical || !critical) {
-                       gdk_gc_set_foreground (priv->fill_gc, &priv->color_normal);
-               } else {
-                       gdk_gc_set_foreground (priv->fill_gc, &priv->color_critical);
-               }
-
                if (rx1 <= complete_x2) {
-                       draw_cut_rectangle (drawable,
-                                           priv->complete_gc,
-                                           TRUE,
-                                           rx1,
-                                           cy1 + 4,
-                                           complete_x2 - rx1,
-                                           cy2 - cy1 - 7);
+                       /* TODO: This and many other things code duplicated in planner-usage-row.c */
+                       /* TODO: Improve design of completed percentage bar; perhaps add borders? */
+                       gdk_color_parse ("LightSkyBlue1", &color);
+                       gdk_cairo_set_source_color (cr, &color);
+                       cairo_rectangle (cr, rx1, cy1 + 5,
+                                        complete_x2 - rx1, cy2 - cy1 - 9);
+                       cairo_fill (cr);
                }
 
+               /* Horizontal borders */
 #ifdef WITH_SIMPLE_PRIORITY_SCHEDULING
-               for (i = 0 ; i < (is_dominant && !(!summary && priv->highlight) ? 2 : 1) ; ++i) {
-                       if (i == 1) {
-                               gnome_canvas_get_color (item->canvas, "indian red", &color);
-                               gdk_gc_set_foreground (priv->frame_gc, &color);
-
-                               gdk_gc_set_line_attributes (priv->frame_gc,
-                                                               1,
-                                                               GDK_LINE_ON_OFF_DASH,
-                                                               GDK_CAP_BUTT,
-                                                               GDK_JOIN_MITER);
-                               draw_cut_line (drawable, priv->frame_gc, cx1, cy1, cx2, cy1);
-                               draw_cut_line (drawable, priv->frame_gc, cx1, cy2, cx2, cy2);
-                               gantt_row_setup_frame_gc (row, !summary && priv->highlight);
-                               gnome_canvas_get_color (item->canvas, "black", &color);
-                               gdk_gc_set_foreground (priv->frame_gc, &color);
-                       }
-                       else {
+               for (i = 0 ; i < (is_dominant && !(!summary && priv->highlight) ? 2 : 1) ; ++i) {
+                       if (i == 1) {
+                               gdk_cairo_set_source_color (cr, &priv->color_critical);
+                               gantt_row_setup_frame_dashes (row, cr, TRUE);
+                               cairo_move_to (cr, rx1 + 0.5, cy1 + 0.5);
+                               cairo_line_to (cr, rx2 + 0.5, cy1 + 0.5);
+                               cairo_move_to (cr, cx1 + 0.5, cy2 + 0.5);
+                               cairo_line_to (cr, cx2 + 0.5, cy2 + 0.5);
+                               cairo_stroke (cr);
+                       } else {
 #endif
-                               draw_cut_line (drawable, priv->frame_gc, rx1, cy1, rx2, cy1);
-                               draw_cut_line (drawable, priv->frame_gc, rx1, cy2, rx2, cy2);
+                               gdk_color_parse ("black", &color);
+                               gdk_cairo_set_source_color (cr, &color);
+                               gantt_row_setup_frame_dashes (row, cr, priv->highlight);
+                               cairo_move_to (cr, rx1 + 0.5, cy1 + 0.5);
+                               cairo_line_to (cr, rx2 + 0.5, cy1 + 0.5);
+                               cairo_move_to (cr, rx1 + 0.5, cy2 + 0.5);
+                               cairo_line_to (cr, rx2 + 0.5, cy2 + 0.5);
+                               cairo_stroke (cr);
 #ifdef WITH_SIMPLE_PRIORITY_SCHEDULING
-                       }
-               }
+                       }
+               }
 #endif
 
+               gantt_row_setup_frame_dashes (row, cr, FALSE);
+
                if (!highlight_critical || !critical) {
-                       gdk_gc_set_foreground (priv->fill_gc, &priv->color_normal_light);
+                       gdk_cairo_set_source_color (cr, &priv->color_normal_light);
                } else {
-                       gdk_gc_set_foreground (priv->fill_gc, &priv->color_critical_light);
+                       gdk_cairo_set_source_color (cr, &priv->color_critical_light);
                }
 
-               draw_cut_line (drawable,
-                              priv->fill_gc,
-                              rx1 + 0,
-                              cy1 + 1,
-                              rx2 - 0,
-                              cy1 + 1);
+               cairo_move_to (cr, rx1 + 0 + 0.5, cy1 + 1 + 0.5);
+               cairo_line_to (cr, rx2 - 0 + 0.5, cy1 + 1 + 0.5);
 
                if (cx1 == rx1) {
-                       draw_cut_line (drawable,
-                                      priv->fill_gc,
-                                      rx1 + 1,
-                                      cy1 + 1,
-                                      rx1 + 1,
-                                      cy2 - 1);
+                       cairo_move_to (cr, rx1 + 1 + 0.5, cy1 + 1 + 0.5);
+                       cairo_line_to (cr, rx1 + 1 + 0.5, cy2 - 1 + 0.5);
                }
 
+               cairo_stroke (cr);
+
                if (!highlight_critical || !critical) {
-                       gdk_gc_set_foreground (priv->fill_gc, &priv->color_normal_dark);
+                       gdk_cairo_set_source_color (cr, &priv->color_normal_dark);
                } else {
-                       gdk_gc_set_foreground (priv->fill_gc, &priv->color_critical_dark);
+                       gdk_cairo_set_source_color (cr, &priv->color_critical_dark);
                }
 
-               draw_cut_line (drawable,
-                              priv->fill_gc,
-                              rx1 + 0,
-                              cy2 - 1,
-                              rx2 - 0,
-                              cy2 - 1);
+               cairo_move_to (cr, rx1 + 0 + 0.5, cy2 - 1 + 0.5);
+               cairo_line_to (cr, rx2 - 0 + 0.5, cy2 - 1 + 0.5);
 
                if (cx2 == rx2) {
-                       draw_cut_line (drawable,
-                                      priv->fill_gc,
-                                      rx2 - 1,
-                                      cy1 + 1,
-                                      rx2 - 1,
-                                      cy2 - 1);
+                       cairo_move_to (cr, rx2 - 1 + 0.5, cy1 + 1 + 0.5);
+                       cairo_line_to (cr, rx2 - 1 + 0.5, cy2 - 1 + 0.5);
                }
+
+               cairo_stroke (cr);
+
 #ifdef WITH_SIMPLE_PRIORITY_SCHEDULING
                for (i = 0 ; i < (is_dominant && !(!summary && priv->highlight) ? 2 : 1) ; ++i) {
                        if (i == 1) {
-                               gnome_canvas_get_color (item->canvas, "red", &color);
-                               gdk_gc_set_foreground (priv->frame_gc, &color);
-
-                               gdk_gc_set_line_attributes (priv->frame_gc,
-                                                               1,
-                                                               GDK_LINE_ON_OFF_DASH,
-                                                               GDK_CAP_BUTT,
-                                                               GDK_JOIN_MITER);
+                               gdk_cairo_set_source_color (cr, &priv->color_critical);
+                               gantt_row_setup_frame_dashes (row, cr, TRUE);
+                       } else {
+#endif
+                               gdk_color_parse ("black", &color);
+                               gdk_cairo_set_source_color (cr, &color);
+                               gantt_row_setup_frame_dashes (row, cr, priv->highlight);
+#ifdef WITH_SIMPLE_PRIORITY_SCHEDULING
                        }
 #endif
+                       /* Vertical borders */
                        if (cx1 == rx1) {
-                               draw_cut_line (drawable, priv->frame_gc,
-                                               cx1, cy1, cx1, cy2);
+                               cairo_move_to (cr, cx1 + 0.5, cy1 + 0.5);
+                               cairo_line_to (cr, cx1 + 0.5, cy2 + 0.5);
                        }
                        if (cx2 == rx2) {
-                               draw_cut_line (drawable, priv->frame_gc,
-                                               cx2, cy1, cx2, cy2);
+                               cairo_move_to (cr, cx2 + 0.5, cy1 + 0.5);
+                               cairo_line_to (cr, cx2 + 0.5, cy2 + 0.5);
                        }
 
+                       cairo_stroke (cr);
 #ifdef WITH_SIMPLE_PRIORITY_SCHEDULING
-                       if (i == 1) {
-                               gantt_row_setup_frame_gc (row, !summary && priv->highlight);
-                               gnome_canvas_get_color (item->canvas, "black", &color);
-                               gdk_gc_set_foreground (priv->frame_gc, &color);
-                       }
                }
 #endif
+               gantt_row_setup_frame_dashes (row, cr, FALSE);
        }
-       else if (type == MRP_TASK_TYPE_MILESTONE && !summary && rx1 <= rx2) {
-               points[0].x = cx1;
-               points[0].y = cy1;
-
-               points[1].x = cx1 + MILESTONE_SIZE + 1;
-               points[1].y = cy1 + MILESTONE_SIZE + 1;
-
-               points[2].x = cx1;
-               points[2].y = cy1 + (MILESTONE_SIZE + 1) * 2;
-
-               points[3].x = cx1 - MILESTONE_SIZE;
-               points[3].y = cy1 + MILESTONE_SIZE + 1;
-
-               gdk_draw_polygon (drawable,
-                                 priv->frame_gc,
-                                 TRUE,
-                                 (GdkPoint *) &points,
-                                 4);
+       else if (type == MRP_TASK_TYPE_MILESTONE && !summary) {
+               cairo_move_to (cr, cx1 + 0.5, cy1 + 1);
+               cairo_rel_line_to (cr, MILESTONE_SIZE + 0.5, MILESTONE_SIZE + 0.5);
+               cairo_rel_line_to (cr, -(MILESTONE_SIZE + 0.5), MILESTONE_SIZE + 0.5);
+               cairo_rel_line_to (cr, -(MILESTONE_SIZE + 0.5), -(MILESTONE_SIZE + 0.5));
+               cairo_close_path (cr);
+               cairo_fill (cr);
        }
-       else if (summary && rx1 <= rx2) {
+       else if (summary) {
                /* FIXME: Maybe we should try and make the summary be thicker
                 * for larger heights and always centered vertically?
                 */
-               draw_cut_rectangle (drawable,
-                                   priv->frame_gc,
-                                   TRUE,
-                                   rx1,
-                                   summary_y,
-                                   rx2 - rx1 + 1,
-                                   THICKNESS);
-
-               if ((rx1 >= cx1 && rx1 <= cx1 + SLOPE) ||
-                   (rx2 >= cx1 && rx2 <= cx1 + SLOPE)) {
-                       points[0].x = cx1;
-                       points[0].y = summary_y + THICKNESS;
-
-                       points[1].x = cx1;
-                       points[1].y = summary_y + THICKNESS + HEIGHT - 1;
-
-                       points[2].x = cx1 + SLOPE;
-                       points[2].y = summary_y + THICKNESS;
-
-                       points[3].x = cx1;
-                       points[3].y = summary_y + THICKNESS;
-
-                       gdk_draw_polygon (drawable,
-                                         priv->frame_gc,
-                                         TRUE,
-                                         (GdkPoint *) &points,
-                                         4);
-               }
-
-               if ((rx1 >= cx2 - SLOPE && rx1 <= cx2) ||
-                   (rx2 >= cx2 - SLOPE && rx2 <= cx2)) {
-                       points[0].x = cx2 + 1;
-                       points[0].y = summary_y + THICKNESS;
-
-                       points[1].x = cx2 + 1 - SLOPE;
-                       points[1].y = summary_y + THICKNESS;
-
-                       points[2].x = cx2 + 1;
-                       points[2].y = summary_y + THICKNESS + HEIGHT;
-
-                       points[3].x = cx2 + 1;
-                       points[3].y = summary_y + THICKNESS;
-
-                       gdk_draw_polygon (drawable,
-                                         priv->frame_gc,
-                                         TRUE,
-                                         (GdkPoint *) &points,
-                                         4);
-               }
+               cairo_move_to (cr, cx1, summary_y);
+               cairo_rel_line_to (cr, cx2 - cx1 + 1, 0.0);
+               cairo_rel_line_to (cr, 0.0, THICKNESS + SLOPE);
+               cairo_rel_line_to (cr, -SLOPE, -SLOPE);
+               cairo_rel_line_to (cr, -(cx2 - cx1 + 1 - 2*SLOPE), 0.0);
+               cairo_rel_line_to (cr, -SLOPE, SLOPE);
+               cairo_close_path (cr);
+               cairo_fill (cr);
        }
 
        /* FIXME: the padding is already included in text_width. */
@@ -1935,11 +1746,11 @@ gantt_row_draw (GnomeCanvasItem *item,
                         add priv->height / 2 to get to the center of the row
                         subtract priv->text_height / 2 to get to the top of the text */
 
-               draw_cut_layout (drawable,
-                                GTK_WIDGET (item->canvas)->style->text_gc[GTK_STATE_NORMAL],
-                                cx2 + TEXT_PADDING,
-                                cy1 - (gint)(priv->bar_top + 0.5) + (priv->height - priv->text_height) / 2,
-                                priv->layout);
+               gdk_cairo_set_source_color (cr, &GTK_WIDGET (item->canvas)->style->text[GTK_STATE_NORMAL]);
+               cairo_move_to (cr,
+                              cx2 + TEXT_PADDING,
+                              cy1 - (gint)(priv->bar_top + 0.5) + (priv->height - priv->text_height) / 2);
+               pango_cairo_show_layout (cr, priv->layout);
 
                if (priv->mouse_over_index != -1) {
                        gint x1, x2;
@@ -1954,14 +1765,14 @@ gantt_row_draw (GnomeCanvasItem *item,
                        x1 += cx2 + TEXT_PADDING;
                        x2 += cx2 + TEXT_PADDING;
 
-                       draw_cut_line (drawable,
-                                      GTK_WIDGET (item->canvas)->style->text_gc[GTK_STATE_NORMAL],
-                                      x1,
-                                      cy2 + 2,
-                                      x2,
-                                      cy2 + 2);
+                       gdk_cairo_set_source_color (cr, &GTK_WIDGET 
(item->canvas)->style->text[GTK_STATE_NORMAL]);
+                       cairo_move_to (cr, x1 + 0.5, cy2 + 2 + 0.5);
+                       cairo_line_to (cr, x2 + 0.5, cy2 + 2 + 0.5);
+                       cairo_stroke (cr);
                }
        }
+
+       cairo_destroy (cr);
 }
 
 static double
@@ -3244,7 +3055,7 @@ gantt_row_get_resource_by_index (PlannerGanttRow *row,
                                        tx2 = MIN (tx2, rx2);
 
                                        if (tx1 < tx2) {
-                                               draw_cut_rectangle (drawable,
+                                               gdk_draw_rectangle (drawable,
                                                                    priv->fill_gc,
                                                                    TRUE,
                                                                    tx1,
@@ -3254,14 +3065,14 @@ gantt_row_get_resource_by_index (PlannerGanttRow *row,
                                        }
 
                                        /*gdk_gc_set_foreground (priv->fill_gc, &color_high);
-                                       draw_cut_line (drawable,
+                                       gdk_draw_line (drawable,
                                                       priv->fill_gc,
                                                       tx1,
                                                       cy1 + 1,
                                                       tx1,
                                                       cy2 - 1);
 
-                                       draw_cut_line (drawable,
+                                       gdk_draw_line (drawable,
                                                       priv->fill_gc,
                                                       tx2 - 1,
                                                       cy1 + 1,
@@ -3301,7 +3112,7 @@ gantt_row_get_resource_by_index (PlannerGanttRow *row,
                                tx2 = MIN (tx2, rx2);
 
                                if (tx1 < tx2) {
-                                       draw_cut_rectangle (drawable,
+                                       gdk_draw_rectangle (drawable,
                                                            priv->fill_gc,
                                                            TRUE,
                                                            tx1,


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