From: Andrea Zagli Date: Sat, 4 Dec 2010 12:27:29 +0000 (+0100) Subject: Implemented working week drawing. X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=86bdb147e3725e852356cff4a34b1acc046f0923;p=libgtkcalendarex Implemented working week drawing. --- diff --git a/src/gtkcalexviewday.c b/src/gtkcalexviewday.c index ac473ae..86546b5 100644 --- a/src/gtkcalexviewday.c +++ b/src/gtkcalexviewday.c @@ -218,6 +218,12 @@ gtk_calex_view_day_draw (GtkCalExViewDay *gtk_calex_view_day) { GtkAllocation allocation; + GDateWeekday wday; + GDate *day; + + guint i; + guint days; + gchar *str_day; guint hour; @@ -225,7 +231,10 @@ gtk_calex_view_day_draw (GtkCalExViewDay *gtk_calex_view_day) guint division; guint divisions; + gdouble width; + gdouble x; gdouble y; + gdouble y_division; g_return_if_fail (IS_GTK_CALEX_VIEW_DAY (gtk_calex_view_day)); @@ -235,61 +244,92 @@ gtk_calex_view_day_draw (GtkCalExViewDay *gtk_calex_view_day) gtk_widget_get_allocation (priv->goo_canvas, &allocation); - str_day = g_malloc0 (100); - g_date_strftime (str_day, 100, "%A %d %B", priv->date); - - goo_canvas_text_new (priv->goo_canvas_root, str_day, - 0, 0, allocation.width, - GTK_ANCHOR_NORTH_WEST, - "font", "Sans 10", - NULL); - g_free (str_day); + day = g_date_new_dmy ((GDateDay)priv->date->day, + (GDateMonth)priv->date->month, + (GDateYear)priv->date->year); + if (priv->working_week) + { + days = 5; + wday = g_date_get_weekday (day); + g_date_subtract_days (day, wday); + width = (allocation.width - 55) / 5 - 5; + } + else + { + days = 1; + g_date_subtract_days (day, 1); + width = allocation.width - 55; + } divisions = 60 / priv->division; + y = 0; for (hour = 0; hour < 24; hour++) { y += 20; + goo_canvas_polyline_new_line (priv->goo_canvas_root, 0, y, 50, y, "stroke-color", "black", NULL); - goo_canvas_rect_new (priv->goo_canvas_root, - 55, y, allocation.width - 55, 20, - "line-width", 1.0, - "stroke-color", "black", - "fill-color", "yellow", - NULL); goo_canvas_text_new (priv->goo_canvas_root, g_strdup_printf ("%d", hour), 0, y, 50, GTK_ANCHOR_NORTH_WEST, "font", "Sans 24", NULL); - goo_canvas_text_new (priv->goo_canvas_root, "00", - 25, y, 25, - GTK_ANCHOR_NORTH_WEST, - "font", "Sans 12", - NULL); - for (division = 1; division < divisions; division++) + x = 55; + for (i = 0; i < days; i++) { - y += 20; - goo_canvas_polyline_new_line (priv->goo_canvas_root, - 25, y, 50, y, - "stroke-color", "black", - NULL); - goo_canvas_text_new (priv->goo_canvas_root, g_strdup_printf ("%02d", 60 / divisions * division), - 25, y, 25, - GTK_ANCHOR_NORTH_WEST, - "font", "Sans 12", - NULL); - goo_canvas_rect_new (priv->goo_canvas_root, - 55, y, allocation.width - 55, 20, - "line-width", 1.0, - "stroke-color", "black", - "fill-color", "yellow", - NULL); + if (i > 0) x += (width + 5); + + if (hour == 0) + { + g_date_add_days (day, 1); + str_day = g_malloc0 (100); + g_date_strftime (str_day, 100, "%A %d %B", day); + + goo_canvas_text_new (priv->goo_canvas_root, str_day, + x, 0, width, + GTK_ANCHOR_NORTH_WEST, + "font", "Sans 10", + NULL); + g_free (str_day); + } + + y_division = y; + for (division = 0; division < divisions; division++) + { + if (division > 0) + { + y_division += 20; + } + + if (i == 0) + { + if (division > 0) + { + goo_canvas_polyline_new_line (priv->goo_canvas_root, + 25, y_division, 50, y_division, + "stroke-color", "black", + NULL); + } + goo_canvas_text_new (priv->goo_canvas_root, g_strdup_printf ("%02d", 60 / divisions * division), + 25, y_division, 25, + GTK_ANCHOR_NORTH_WEST, + "font", "Sans 12", + NULL); + } + + goo_canvas_rect_new (priv->goo_canvas_root, + x, y_division, width, 20, + "line-width", 1.0, + "stroke-color", "black", + "fill-color", "yellow", + NULL); + } } + y = y_division; } goo_canvas_set_bounds (GOO_CANVAS (priv->goo_canvas), 0, 0, allocation.width, y + 20); diff --git a/src/gtkcalexviewweek.c b/src/gtkcalexviewweek.c index 7c8791e..09fd38d 100644 --- a/src/gtkcalexviewweek.c +++ b/src/gtkcalexviewweek.c @@ -207,8 +207,6 @@ gtk_calex_view_week_draw (GtkCalExViewWeek *gtk_calex_view_week) "stroke-color", "black", NULL); - str_day = g_malloc0 (100); - day = g_date_new_dmy ((GDateDay)priv->date->day, (GDateMonth)priv->date->month, (GDateYear)priv->date->year); @@ -229,6 +227,7 @@ gtk_calex_view_week_draw (GtkCalExViewWeek *gtk_calex_view_week) } g_date_add_days (day, 1); + str_day = g_malloc0 (100); g_date_strftime (str_day, 100, "%A %d %B", day); goo_canvas_text_new (priv->goo_canvas_root, str_day, @@ -240,10 +239,12 @@ gtk_calex_view_week_draw (GtkCalExViewWeek *gtk_calex_view_week) (i % 2 == 0 ? 0 : width), y + 20, (i % 2 == 0 ? width : allocation.width), y + 20, "stroke-color", "black", NULL); + g_free (str_day); } /* saturday */ g_date_add_days (day, 1); + str_day = g_malloc0 (100); g_date_strftime (str_day, 100, "%A %d %B", day); goo_canvas_text_new (priv->goo_canvas_root, str_day, @@ -255,11 +256,13 @@ gtk_calex_view_week_draw (GtkCalExViewWeek *gtk_calex_view_week) width, y + 20, allocation.width, y + 20, "stroke-color", "black", NULL); + g_free (str_day); /* sunday */ y += (height / 2); g_date_add_days (day, 1); + str_day = g_malloc0 (100); g_date_strftime (str_day, 100, "%A %d %B", day); goo_canvas_polyline_new_line (priv->goo_canvas_root, @@ -275,10 +278,9 @@ gtk_calex_view_week_draw (GtkCalExViewWeek *gtk_calex_view_week) width, y + 20, allocation.width, y + 20, "stroke-color", "black", NULL); + g_free (str_day); goo_canvas_set_bounds (GOO_CANVAS (priv->goo_canvas), 0, 0, allocation.width, allocation.height); - - g_free (str_day); } static void