4 * Copyright (C) 2008 - 2012 The Geeqie Team
8 * This software is released under the GNU General Public License (GNU GPL).
9 * Please read the included file COPYING for more information.
10 * This software comes with no warranty of any kind, use at your own risk!
15 #include "pan-types.h"
17 #include <glib/gprintf.h>
21 #define PAN_CAL_POPUP_COLOR 220, 220, 220
22 #define PAN_CAL_POPUP_ALPHA 255
23 #define PAN_CAL_POPUP_BORDER 1
24 #define PAN_CAL_POPUP_BORDER_COLOR 0, 0, 0
25 #define PAN_CAL_POPUP_TEXT_COLOR 0, 0, 0
27 #define PAN_CAL_DAY_WIDTH 100
28 #define PAN_CAL_DAY_HEIGHT 80
30 #define PAN_CAL_DAY_COLOR 255, 255, 255
31 #define PAN_CAL_DAY_ALPHA 220
32 #define PAN_CAL_DAY_BORDER 2
33 #define PAN_CAL_DAY_BORDER_COLOR 0, 0, 0
34 #define PAN_CAL_DAY_TEXT_COLOR 0, 0, 0
36 #define PAN_CAL_MONTH_COLOR 255, 255, 255
37 #define PAN_CAL_MONTH_ALPHA 200
38 #define PAN_CAL_MONTH_BORDER 4
39 #define PAN_CAL_MONTH_BORDER_COLOR 0, 0, 0
40 #define PAN_CAL_MONTH_TEXT_COLOR 0, 0, 0
42 #define PAN_CAL_DOT_SIZE 3
43 #define PAN_CAL_DOT_GAP 2
44 #define PAN_CAL_DOT_COLOR 128, 128, 128
45 #define PAN_CAL_DOT_ALPHA 128
49 *-----------------------------------------------------------------------------
51 *-----------------------------------------------------------------------------
54 void pan_calendar_update(PanWindow *pw, PanItem *pi_day)
60 gint x1, y1, x2, y2, x3, y3;
65 while ((pi = pan_item_find_by_key(pw, PAN_ITEM_NONE, "day_bubble"))) pan_item_remove(pw, pi);
67 if (!pi_day || pi_day->type != PAN_ITEM_BOX ||
68 !pi_day->key || strcmp(pi_day->key, "day") != 0) return;
70 list = pan_layout_intersect(pw, pi_day->x, pi_day->y, pi_day->width, pi_day->height);
82 if (dot->type != PAN_ITEM_BOX || !dot->fd ||
83 !dot->key || strcmp(dot->key, "dot") != 0)
85 list = g_list_delete_link(list, node);
89 grid = (gint)(sqrt(g_list_length(list)) + 0.5);
91 x = pi_day->x + pi_day->width + 4;
94 pbox = pan_item_box_new(pw, NULL, x, y, PAN_BOX_BORDER, PAN_BOX_BORDER,
96 PAN_CAL_POPUP_COLOR, PAN_CAL_POPUP_ALPHA,
97 PAN_CAL_POPUP_BORDER_COLOR, PAN_CAL_POPUP_ALPHA);
98 pan_item_set_key(pbox, "day_bubble");
105 buf = pan_date_value_string(pi_day->fd->date, PAN_DATE_LENGTH_WEEK);
106 plabel = pan_item_text_new(pw, x, y, buf, PAN_TEXT_ATTR_BOLD | PAN_TEXT_ATTR_HEADING,
107 PAN_TEXT_BORDER_SIZE,
108 PAN_CAL_POPUP_TEXT_COLOR, 255);
109 pan_item_set_key(plabel, "day_bubble");
112 pan_item_size_by_item(pbox, plabel, 0);
136 pimg = pan_item_thumb_new(pw, file_data_ref(dot->fd), x, y);
137 pan_item_set_key(pimg, "day_bubble");
139 pan_item_size_by_item(pbox, pimg, PAN_BOX_BORDER);
144 x += PAN_THUMB_SIZE + PAN_THUMB_GAP;
149 x = pbox->x + PAN_BOX_BORDER;
150 y += PAN_THUMB_SIZE + PAN_THUMB_GAP;
156 x1 = pi_day->x + pi_day->width - 8;
159 y2 = pbox->y + MIN(42, pbox->height);
161 y3 = MAX(pbox->y, y2 - 30);
162 util_clip_triangle(x1, y1, x2, y2, x3, y3,
165 pi = pan_item_tri_new(pw, NULL, x, y, w, h,
166 x1, y1, x2, y2, x3, y3,
167 PAN_CAL_POPUP_COLOR, PAN_CAL_POPUP_ALPHA);
168 pan_item_tri_border(pi, PAN_BORDER_1 | PAN_BORDER_3, PAN_CAL_POPUP_BORDER_COLOR, PAN_CAL_POPUP_ALPHA);
169 pan_item_set_key(pi, "day_bubble");
170 pan_item_added(pw, pi);
172 pan_item_box_shadow(pbox, PAN_SHADOW_OFFSET * 2, PAN_SHADOW_FADE * 2);
173 pan_item_added(pw, pbox);
175 pan_layout_resize(pw);
178 void pan_calendar_compute(PanWindow *pw, FileData *dir_fd, gint *width, gint *height)
192 list = pan_list_tree(dir_fd, SORT_NONE, TRUE, pw->ignore_symlinks);
194 if (pw->cache_list && pw->exif_date_enable)
196 pw->cache_list = pan_cache_sort(pw->cache_list, SORT_NAME, TRUE);
197 list = filelist_sort(list, SORT_NAME, TRUE);
198 pan_cache_sync_date(pw, list);
201 pw->cache_list = pan_cache_sort(pw->cache_list, SORT_TIME, TRUE);
202 list = filelist_sort(list, SORT_TIME, TRUE);
215 if (!pan_date_compare(fd->date, tc, PAN_DATE_LENGTH_DAY))
223 if (day_max < count) day_max = count;
227 DEBUG_1("biggest day contains %d images", day_max);
229 grid = (gint)(sqrt((gdouble)day_max) + 0.5) * (PAN_THUMB_SIZE + PAN_SHADOW_OFFSET * 2 + PAN_THUMB_GAP);
233 FileData *fd = list->data;
235 year = pan_date_value(fd->date, PAN_DATE_LENGTH_YEAR);
236 month = pan_date_value(fd->date, PAN_DATE_LENGTH_MONTH);
239 work = g_list_last(list);
242 FileData *fd = work->data;
243 end_year = pan_date_value(fd->date, PAN_DATE_LENGTH_YEAR);
244 end_month = pan_date_value(fd->date, PAN_DATE_LENGTH_MONTH);
247 *width = PAN_BOX_BORDER * 2;
248 *height = PAN_BOX_BORDER * 2;
254 while (work && (year < end_year || (year == end_year && month <= end_month)))
265 /* figure last second of this month */
266 dt = pan_date_to_time((month == 12) ? year + 1 : year, (month == 12) ? 1 : month + 1, 1);
269 /* anything to show this month? */
270 if (!pan_date_compare(((FileData *)(work->data))->date, dt, PAN_DATE_LENGTH_MONTH))
281 days = pan_date_value(dt, PAN_DATE_LENGTH_DAY);
282 dt = pan_date_to_time(year, month, 1);
283 col = pan_date_value(dt, PAN_DATE_LENGTH_WEEK);
288 pi_month = pan_item_box_new(pw, NULL, x, y, PAN_CAL_DAY_WIDTH * 7, PAN_CAL_DAY_HEIGHT / 4,
289 PAN_CAL_MONTH_BORDER,
290 PAN_CAL_MONTH_COLOR, PAN_CAL_MONTH_ALPHA,
291 PAN_CAL_MONTH_BORDER_COLOR, PAN_CAL_MONTH_ALPHA);
292 buf = pan_date_value_string(dt, PAN_DATE_LENGTH_MONTH);
293 pi_text = pan_item_text_new(pw, x, y, buf,
294 PAN_TEXT_ATTR_BOLD | PAN_TEXT_ATTR_HEADING,
295 PAN_TEXT_BORDER_SIZE,
296 PAN_CAL_MONTH_TEXT_COLOR, 255);
298 pi_text->x = pi_month->x + (pi_month->width - pi_text->width) / 2;
300 pi_month->height = pi_text->y + pi_text->height - pi_month->y;
302 x = PAN_BOX_BORDER + col * PAN_CAL_DAY_WIDTH;
303 y = pi_month->y + pi_month->height + PAN_BOX_BORDER;
305 for (day = 1; day <= days; day++)
313 dt = pan_date_to_time(year, month, day);
316 * Create a FileData entry that represents the given day.
317 * It does not correspond to any real file
320 g_snprintf(fake_path, sizeof(fake_path), "//%04d-%02d-%02d", year, month, day);
321 fd = file_data_new_no_grouping(fake_path);
323 pi_day = pan_item_box_new(pw, fd, x, y, PAN_CAL_DAY_WIDTH, PAN_CAL_DAY_HEIGHT,
325 PAN_CAL_DAY_COLOR, PAN_CAL_DAY_ALPHA,
326 PAN_CAL_DAY_BORDER_COLOR, PAN_CAL_DAY_ALPHA);
327 pan_item_set_key(pi_day, "day");
329 dx = x + PAN_CAL_DOT_GAP * 2;
330 dy = y + PAN_CAL_DOT_GAP * 2;
332 fd = (work) ? work->data : NULL;
333 while (fd && pan_date_compare(fd->date, dt, PAN_DATE_LENGTH_DAY))
337 pi = pan_item_box_new(pw, fd, dx, dy, PAN_CAL_DOT_SIZE, PAN_CAL_DOT_SIZE,
339 PAN_CAL_DOT_COLOR, PAN_CAL_DOT_ALPHA,
341 pan_item_set_key(pi, "dot");
343 dx += PAN_CAL_DOT_SIZE + PAN_CAL_DOT_GAP;
344 if (dx + PAN_CAL_DOT_SIZE > pi_day->x + pi_day->width - PAN_CAL_DOT_GAP * 2)
346 dx = x + PAN_CAL_DOT_GAP * 2;
347 dy += PAN_CAL_DOT_SIZE + PAN_CAL_DOT_GAP;
349 if (dy + PAN_CAL_DOT_SIZE > pi_day->y + pi_day->height - PAN_CAL_DOT_GAP * 2)
351 /* must keep all dots within respective day even if it gets ugly */
352 dy = y + PAN_CAL_DOT_GAP * 2;
358 fd = (work) ? work->data : NULL;
365 pi_day->color_r = MAX(pi_day->color_r - 61 - n * 3, 80);
366 pi_day->color_g = pi_day->color_r;
368 buf = g_strdup_printf("( %d )", n);
369 pi = pan_item_text_new(pw, x, y, buf, PAN_TEXT_ATTR_NONE,
370 PAN_TEXT_BORDER_SIZE,
371 PAN_CAL_DAY_TEXT_COLOR, 255);
374 pi->x = pi_day->x + (pi_day->width - pi->width) / 2;
375 pi->y = pi_day->y + (pi_day->height - pi->height) / 2;
378 buf = g_strdup_printf("%d", day);
379 pan_item_text_new(pw, x + 4, y + 4, buf, PAN_TEXT_ATTR_BOLD | PAN_TEXT_ATTR_HEADING,
380 PAN_TEXT_BORDER_SIZE,
381 PAN_CAL_DAY_TEXT_COLOR, 255);
385 pan_item_size_coordinates(pi_day, PAN_BOX_BORDER, width, height);
393 y += PAN_CAL_DAY_HEIGHT;
397 x += PAN_CAL_DAY_WIDTH;
401 if (col > 0) y += PAN_CAL_DAY_HEIGHT;
402 y += PAN_BOX_BORDER * 2;
413 *height = MAX(*height, grid + PAN_BOX_BORDER * 2 * 2);
417 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */