[planner: 44/61] gantt-background: Port to cairo drawing
- From: Mart Raudsepp <mraudsepp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [planner: 44/61] gantt-background: Port to cairo drawing
- Date: Sat, 12 Jun 2021 17:30:27 +0000 (UTC)
commit fbfb1a0e23d4ce5f721983bfeb0fa4e543da16fa
Author: Mart Raudsepp <leio gentoo org>
Date: Fri Jan 1 18:33:45 2021 +0200
gantt-background: Port to cairo drawing
src/planner-gantt-background.c | 159 +++++++++++++----------------------------
1 file changed, 50 insertions(+), 109 deletions(-)
---
diff --git a/src/planner-gantt-background.c b/src/planner-gantt-background.c
index 02e6103a..47fb5296 100644
--- a/src/planner-gantt-background.c
+++ b/src/planner-gantt-background.c
@@ -43,12 +43,6 @@ enum {
};
struct _PlannerGanttBackgroundPriv {
- GdkGC *border_gc;
- GdkGC *fill_gc;
- GdkGC *timeline_gc;
- GdkGC *start_gc;
- GdkGC *guidelines_gc;
-
PangoLayout *layout;
guint timeout_id;
@@ -365,53 +359,12 @@ gantt_background_realize (GnomeCanvasItem *item)
{
PlannerGanttBackground *background;
PlannerGanttBackgroundPriv *priv;
- GdkColor color;
background = PLANNER_GANTT_BACKGROUND (item);
priv = background->priv;
GNOME_CANVAS_ITEM_CLASS (parent_class)->realize (item);
- priv->fill_gc = gdk_gc_new (item->canvas->layout.bin_window);
- gnome_canvas_get_color (item->canvas, "grey96", &color);
- gdk_gc_set_foreground (priv->fill_gc, &color);
-
- gnome_canvas_get_color (item->canvas, "grey80", &color);
- priv->border_gc = gdk_gc_new (item->canvas->layout.bin_window);
- gdk_gc_set_foreground (priv->border_gc, &color);
- gdk_gc_set_line_attributes (priv->border_gc,
- 1,
- GDK_LINE_SOLID,
- GDK_CAP_BUTT,
- GDK_JOIN_MITER);
-
- gnome_canvas_get_color (item->canvas, "royal blue", &color);
- priv->timeline_gc = gdk_gc_new (item->canvas->layout.bin_window);
- gdk_gc_set_foreground (priv->timeline_gc, &color);
- gdk_gc_set_line_attributes (priv->timeline_gc,
- 1,
- GDK_LINE_ON_OFF_DASH,
- GDK_CAP_BUTT,
- GDK_JOIN_MITER);
-
- gnome_canvas_get_color (item->canvas, "grey", &color);
- priv->start_gc = gdk_gc_new (item->canvas->layout.bin_window);
- gdk_gc_set_foreground (priv->start_gc, &color);
- gdk_gc_set_line_attributes (priv->start_gc,
- 1,
- GDK_LINE_ON_OFF_DASH,
- GDK_CAP_BUTT,
- GDK_JOIN_MITER);
-
- gnome_canvas_get_color (item->canvas, "grey80", &color);
- priv->guidelines_gc = gdk_gc_new (item->canvas->layout.bin_window);
- gdk_gc_set_foreground (priv->guidelines_gc, &color);
- gdk_gc_set_line_attributes (priv->guidelines_gc,
- 1,
- GDK_LINE_SOLID,
- GDK_CAP_BUTT,
- GDK_JOIN_MITER);
-
priv->layout = gtk_widget_create_pango_layout (GTK_WIDGET (item->canvas),
NULL);
@@ -429,21 +382,6 @@ gantt_background_unrealize (GnomeCanvasItem *item)
background = PLANNER_GANTT_BACKGROUND (item);
- g_object_unref (background->priv->border_gc);
- background->priv->border_gc = NULL;
-
- g_object_unref (background->priv->fill_gc);
- background->priv->fill_gc = NULL;
-
- g_object_unref (background->priv->timeline_gc);
- background->priv->timeline_gc = NULL;
-
- g_object_unref (background->priv->start_gc);
- background->priv->start_gc = NULL;
-
- g_object_unref (background->priv->guidelines_gc);
- background->priv->guidelines_gc = NULL;
-
g_object_unref (background->priv->layout);
background->priv->layout = NULL;
@@ -476,6 +414,7 @@ gantt_background_draw (GnomeCanvasItem *item,
{
PlannerGanttBackground *background;
PlannerGanttBackgroundPriv *priv;
+ cairo_t *cr;
gint cx1, cx2; /* Canvas pixel coordinates */
gint cy1, cy2;
gdouble wx1, wx2; /* World coordinates */
@@ -498,6 +437,10 @@ gantt_background_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);
+
calendar = mrp_project_get_calendar (priv->project);
hscale = priv->hscale;
@@ -547,20 +490,16 @@ gantt_background_draw (GnomeCanvasItem *item,
* want at this zoom level.
*/
if (planner_scale_conf[level].nonworking_limit <= ival_start - ival_prev) {
- gdk_draw_rectangle (drawable,
- priv->fill_gc,
- TRUE,
- cx1 - x,
- cy1 - y,
- cx2 - cx1,
- cy2 - cy1);
-
- gdk_draw_line (drawable,
- priv->border_gc,
- cx1 - x,
- cy1 - y,
- cx1 - x,
- cy2 - y);
+ cairo_set_source_rgb (cr, 245/255., 245/255., 245/255.); /* grey96 */
+ cairo_rectangle (cr,
+ cx1 - x, cy1 - y,
+ cx2 - cx1, cy2 - cy1);
+ cairo_fill (cr);
+
+ cairo_set_source_rgb (cr, 204/255., 204/255., 204/255.); /* grey80 */
+ cairo_move_to (cr, cx1 - x + 0.5, cy1 - y + 0.5);
+ cairo_line_to (cr, cx1 - x + 0.5, cy2 - y + 0.5);
+ cairo_stroke (cr);
}
ival_prev = ival_end;
@@ -576,20 +515,16 @@ gantt_background_draw (GnomeCanvasItem *item,
gnome_canvas_w2c (item->canvas, wx1, 0, &cx1, NULL);
gnome_canvas_w2c (item->canvas, wx2, 0, &cx2, NULL);
- gdk_draw_rectangle (drawable,
- priv->fill_gc,
- TRUE,
- cx1 - x,
- cy1 - y,
- cx2 - cx1,
- cy2 - cy1);
-
- gdk_draw_line (drawable,
- priv->border_gc,
- cx1 - x,
- cy1 - y,
- cx1 - x,
- cy2 - y);
+ cairo_set_source_rgb (cr, 245/255., 245/255., 245/255.); /* grey96 */
+ cairo_rectangle (cr,
+ cx1 - x, cy1 - y,
+ cx2 - cx1, cy2 - cy1);
+ cairo_fill (cr);
+
+ cairo_set_source_rgb (cr, 204/255., 204/255., 204/255.); /* grey80 */
+ cairo_move_to (cr, cx1 - x + 0.5, cy1 - y + 0.5);
+ cairo_line_to (cr, cx1 - x + 0.5, cy2 - y + 0.5);
+ cairo_stroke (cr);
}
}
@@ -605,8 +540,12 @@ gantt_background_draw (GnomeCanvasItem *item,
&yy);
while (yy < height+y)
{
- if (yy >= y)
- gdk_draw_line (drawable,priv->guidelines_gc,0,yy-y,width,yy-y);
+ if (yy >= y) {
+ cairo_set_source_rgb (cr, 204/255., 204/255., 204/255.); /* grey80 */
+ cairo_move_to (cr, 0.5, yy - y + 0.5);
+ cairo_line_to (cr, width + 0.5, yy - y + 0.5);
+ cairo_stroke (cr);
+ }
yy += priv->row_height;
}
@@ -620,18 +559,19 @@ gantt_background_draw (GnomeCanvasItem *item,
if (priv->project_start >= t0 && priv->project_start <= t2) {
gint snap;
+ const double dashes[] = { 4.0 };
/* Align the dashed line, which has a dash length of 8. A bit
* ugly :/
*/
snap = cy1 - floor (cy1 / (double)DASH_LENGTH + 0.5) * DASH_LENGTH;
- gdk_draw_line (drawable,
- priv->start_gc,
- cx1 - x,
- cy1 - snap - DASH_LENGTH - y,
- cx1 - x,
- cy2 + DASH_LENGTH - y);
+ cairo_set_source_rgb (cr, 128/255., 128/255., 128/255.); /* grey */
+ cairo_set_dash (cr, dashes, G_N_ELEMENTS (dashes), 0.);
+ cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
+ cairo_move_to (cr, cx1 - x + 0.5, cy1 - snap - DASH_LENGTH - y);
+ cairo_line_to (cr, cx1 - x + 0.5, cy2 + DASH_LENGTH - y);
+ cairo_stroke (cr);
}
if (priv->project_start >= t0) {
@@ -651,29 +591,30 @@ gantt_background_draw (GnomeCanvasItem *item,
pango_layout_get_pixel_size (priv->layout, &label_width, NULL);
- gdk_draw_layout (drawable,
- GTK_WIDGET (item->canvas)->style->text_gc[GTK_STATE_NORMAL],
- cx1 - label_width - 5 - x,
- 5 - y,
- priv->layout);
+ gdk_cairo_set_source_color (cr, >K_WIDGET (item->canvas)->style->text[GTK_STATE_NORMAL]);
+ cairo_move_to (cr, cx1 - label_width - 5 - x, 5 - y);
+ pango_cairo_show_layout (cr, priv->layout);
}
/* Time line for current time .*/
if (priv->timeline >= t0 && priv->timeline <= t2) {
gint snap;
+ const double dashes[] = { 4.0 };
wx1 = priv->timeline * hscale;
gnome_canvas_w2c (item->canvas, wx1, 0, &cx1, NULL);
snap = cy1 - floor (cy1 / (double) DASH_LENGTH + 0.5) * DASH_LENGTH;
- gdk_draw_line (drawable,
- priv->timeline_gc,
- cx1 - x,
- cy1 - snap - DASH_LENGTH - y,
- cx1 - x,
- cy2 + DASH_LENGTH - y);
+ cairo_set_source_rgb (cr, 65/255., 105/255., 225/255.); /* royal blue */
+ cairo_set_dash (cr, dashes, G_N_ELEMENTS (dashes), 0.);
+ cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
+ cairo_move_to (cr, cx1 - x + 0.5, cy1 - snap - DASH_LENGTH - y);
+ cairo_line_to (cr, cx1 - x + 0.5, cy2 + DASH_LENGTH - y);
+ cairo_stroke (cr);
}
+
+ cairo_destroy (cr);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]