void pan_calendar_compute(PanWindow *pw, const gchar *path, gint *width, gint *height) { GList *list; GList *work; gint x, y; time_t tc; gint count; gint day_max; gint day_width; gint day_height; gint grid; gint year = 0; gint month = 0; gint end_year = 0; gint end_month = 0; list = pan_list_tree(path, SORT_NONE, TRUE, pw->ignore_symlinks); if (pw->cache_list && pw->exif_date_enable) { pw->cache_list = filelist_sort(pw->cache_list, SORT_NAME, TRUE); list = filelist_sort(list, SORT_NAME, TRUE); pan_cache_sync_date(pw, list); } pw->cache_list = filelist_sort(pw->cache_list, SORT_TIME, TRUE); list = filelist_sort(list, SORT_TIME, TRUE); day_max = 0; count = 0; tc = 0; work = list; while (work) { FileData *fd; fd = work->data; work = work->next; if (!pan_date_compare(fd->date, tc, PAN_DATE_LENGTH_DAY)) { count = 0; tc = fd->date; } else { count++; if (day_max < count) day_max = count; } } if (debug) printf("biggest day contains %d images\n", day_max); grid = (gint)(sqrt((double)day_max) + 0.5) * (PAN_THUMB_SIZE + PAN_SHADOW_OFFSET * 2 + PAN_THUMB_GAP); day_width = MAX(PAN_CAL_DAY_WIDTH, grid); day_height = MAX(PAN_CAL_DAY_HEIGHT, grid); if (list) { FileData *fd = list->data; year = pan_date_value(fd->date, PAN_DATE_LENGTH_YEAR); month = pan_date_value(fd->date, PAN_DATE_LENGTH_MONTH); } work = g_list_last(list); if (work) { FileData *fd = work->data; end_year = pan_date_value(fd->date, PAN_DATE_LENGTH_YEAR); end_month = pan_date_value(fd->date, PAN_DATE_LENGTH_MONTH); } *width = PAN_BOX_BORDER * 2; *height = PAN_BOX_BORDER * 2; x = PAN_BOX_BORDER; y = PAN_BOX_BORDER; work = list; while (work && (year < end_year || (year == end_year && month <= end_month))) { PanItem *pi_month; PanItem *pi_text; gint day; gint days; gint col; gint row; time_t dt; gchar *buf; /* figure last second of this month */ dt = pan_date_to_time((month == 12) ? year + 1 : year, (month == 12) ? 1 : month + 1, 1); dt -= 60 * 60 * 24; /* anything to show this month? */ if (!pan_date_compare(((FileData *)(work->data))->date, dt, PAN_DATE_LENGTH_MONTH)) { month ++; if (month > 12) { year++; month = 1; } continue; } days = pan_date_value(dt, PAN_DATE_LENGTH_DAY); dt = pan_date_to_time(year, month, 1); col = pan_date_value(dt, PAN_DATE_LENGTH_WEEK); row = 1; x = PAN_BOX_BORDER; pi_month = pan_item_box_new(pw, NULL, x, y, PAN_CAL_DAY_WIDTH * 7, PAN_CAL_DAY_HEIGHT / 4, PAN_CAL_MONTH_BORDER, PAN_CAL_MONTH_COLOR, PAN_CAL_MONTH_ALPHA, PAN_CAL_MONTH_BORDER_COLOR, PAN_CAL_MONTH_ALPHA); buf = pan_date_value_string(dt, PAN_DATE_LENGTH_MONTH); pi_text = pan_item_text_new(pw, x, y, buf, PAN_TEXT_ATTR_BOLD | PAN_TEXT_ATTR_HEADING, PAN_TEXT_BORDER_SIZE, PAN_CAL_MONTH_TEXT_COLOR, 255); g_free(buf); pi_text->x = pi_month->x + (pi_month->width - pi_text->width) / 2; pi_month->height = pi_text->y + pi_text->height - pi_month->y; x = PAN_BOX_BORDER + col * PAN_CAL_DAY_WIDTH; y = pi_month->y + pi_month->height + PAN_BOX_BORDER; for (day = 1; day <= days; day++) { FileData *fd; PanItem *pi_day; gint dx, dy; gint n = 0; dt = pan_date_to_time(year, month, day); fd = g_new0(FileData, 1); /* path and name must be non NULL, so make them an invalid filename */ fd->path = g_strdup("//"); fd->name = path; fd->date = dt; pi_day = pan_item_box_new(pw, fd, x, y, PAN_CAL_DAY_WIDTH, PAN_CAL_DAY_HEIGHT, PAN_CAL_DAY_BORDER, PAN_CAL_DAY_COLOR, PAN_CAL_DAY_ALPHA, PAN_CAL_DAY_BORDER_COLOR, PAN_CAL_DAY_ALPHA); pan_item_set_key(pi_day, "day"); dx = x + PAN_CAL_DOT_GAP * 2; dy = y + PAN_CAL_DOT_GAP * 2; fd = (work) ? work->data : NULL; while (fd && pan_date_compare(fd->date, dt, PAN_DATE_LENGTH_DAY)) { PanItem *pi; pi = pan_item_box_new(pw, fd, dx, dy, PAN_CAL_DOT_SIZE, PAN_CAL_DOT_SIZE, 0, PAN_CAL_DOT_COLOR, PAN_CAL_DOT_ALPHA, 0, 0, 0, 0); pan_item_set_key(pi, "dot"); dx += PAN_CAL_DOT_SIZE + PAN_CAL_DOT_GAP; if (dx + PAN_CAL_DOT_SIZE > pi_day->x + pi_day->width - PAN_CAL_DOT_GAP * 2) { dx = x + PAN_CAL_DOT_GAP * 2; dy += PAN_CAL_DOT_SIZE + PAN_CAL_DOT_GAP; } if (dy + PAN_CAL_DOT_SIZE > pi_day->y + pi_day->height - PAN_CAL_DOT_GAP * 2) { /* must keep all dots within respective day even if it gets ugly */ dy = y + PAN_CAL_DOT_GAP * 2; } n++; work = work->next; fd = (work) ? work->data : NULL; } if (n > 0) { PanItem *pi; pi_day->color_r = MAX(pi_day->color_r - 61 - n * 3, 80); pi_day->color_g = pi_day->color_r; buf = g_strdup_printf("( %d )", n); pi = pan_item_text_new(pw, x, y, buf, PAN_TEXT_ATTR_NONE, PAN_TEXT_BORDER_SIZE, PAN_CAL_DAY_TEXT_COLOR, 255); g_free(buf); pi->x = pi_day->x + (pi_day->width - pi->width) / 2; pi->y = pi_day->y + (pi_day->height - pi->height) / 2; } buf = g_strdup_printf("%d", day); pan_item_text_new(pw, x + 4, y + 4, buf, PAN_TEXT_ATTR_BOLD | PAN_TEXT_ATTR_HEADING, PAN_TEXT_BORDER_SIZE, PAN_CAL_DAY_TEXT_COLOR, 255); g_free(buf); pan_item_size_coordinates(pi_day, PAN_BOX_BORDER, width, height); col++; if (col > 6) { col = 0; row++; x = PAN_BOX_BORDER; y += PAN_CAL_DAY_HEIGHT; } else { x += PAN_CAL_DAY_WIDTH; } } if (col > 0) y += PAN_CAL_DAY_HEIGHT; y += PAN_BOX_BORDER * 2; month ++; if (month > 12) { year++; month = 1; } } *width += grid; *height = MAX(*height, grid + PAN_BOX_BORDER * 2 * 2); g_list_free(list); }
void pan_grid_compute(PanWindow *pw, FileData *dir_fd, gint *width, gint *height) { GList *list; GList *work; gint x, y; gint grid_size; gint next_y; list = pan_list_tree(dir_fd, SORT_NAME, TRUE, pw->ignore_symlinks); grid_size = (gint)sqrt((gdouble)g_list_length(list)); if (pw->size > PAN_IMAGE_SIZE_THUMB_LARGE) { grid_size = grid_size * (512 + PAN_THUMB_GAP) * pw->image_size / 100; } else { grid_size = grid_size * (PAN_THUMB_SIZE + PAN_THUMB_GAP); } next_y = 0; *width = PAN_BOX_BORDER * 2; *height = PAN_BOX_BORDER * 2; x = PAN_THUMB_GAP; y = PAN_THUMB_GAP; work = list; while (work) { FileData *fd; PanItem *pi; fd = work->data; work = work->next; if (pw->size > PAN_IMAGE_SIZE_THUMB_LARGE) { pi = pan_item_image_new(pw, fd, x, y, 10, 10); x += pi->width + PAN_THUMB_GAP; if (y + pi->height + PAN_THUMB_GAP > next_y) next_y = y + pi->height + PAN_THUMB_GAP; if (x > grid_size) { x = PAN_THUMB_GAP; y = next_y; } } else { pi = pan_item_thumb_new(pw, fd, x, y); x += PAN_THUMB_SIZE + PAN_THUMB_GAP; if (x > grid_size) { x = PAN_THUMB_GAP; y += PAN_THUMB_SIZE + PAN_THUMB_GAP; } } pan_item_size_coordinates(pi, PAN_THUMB_GAP, width, height); } g_list_free(list); }
void pan_timeline_compute(PanWindow *pw, const gchar *path, gint *width, gint *height) { GList *list; GList *work; gint x, y; time_t tc; gint total; gint count; PanItem *pi_month = NULL; PanItem *pi_day = NULL; gint month_start; gint day_start; gint x_width; gint y_height; list = pan_list_tree(path, SORT_NONE, TRUE, pw->ignore_symlinks); if (pw->cache_list && pw->exif_date_enable) { pw->cache_list = filelist_sort(pw->cache_list, SORT_NAME, TRUE); list = filelist_sort(list, SORT_NAME, TRUE); pan_cache_sync_date(pw, list); } pw->cache_list = filelist_sort(pw->cache_list, SORT_TIME, TRUE); list = filelist_sort(list, SORT_TIME, TRUE); *width = PAN_BOX_BORDER * 2; *height = PAN_BOX_BORDER * 2; x = 0; y = 0; month_start = y; day_start = month_start; x_width = 0; y_height = 0; tc = 0; total = 0; count = 0; work = list; while (work) { FileData *fd; PanItem *pi; fd = work->data; work = work->next; if (!pan_date_compare(fd->date, tc, PAN_DATE_LENGTH_DAY)) { GList *needle; gchar *buf; if (!pan_date_compare(fd->date, tc, PAN_DATE_LENGTH_MONTH)) { pi_day = NULL; if (pi_month) { x = pi_month->x + pi_month->width + PAN_BOX_BORDER; } else { x = PAN_BOX_BORDER; } y = PAN_BOX_BORDER; buf = pan_date_value_string(fd->date, PAN_DATE_LENGTH_MONTH); pi = pan_item_text_new(pw, x, y, buf, PAN_TEXT_ATTR_BOLD | PAN_TEXT_ATTR_HEADING, PAN_TEXT_BORDER_SIZE, PAN_TEXT_COLOR, 255); g_free(buf); y += pi->height; pi_month = pan_item_box_new(pw, file_data_new_simple(fd->path), x, y, 0, 0, PAN_BOX_OUTLINE_THICKNESS, PAN_BOX_COLOR, PAN_BOX_ALPHA, PAN_BOX_OUTLINE_COLOR, PAN_BOX_OUTLINE_ALPHA); x += PAN_BOX_BORDER; y += PAN_BOX_BORDER; month_start = y; } if (pi_day) x = pi_day->x + pi_day->width + PAN_BOX_BORDER; tc = fd->date; total = 1; count = 0; needle = work; while (needle) { FileData *nfd; nfd = needle->data; if (pan_date_compare(nfd->date, tc, PAN_DATE_LENGTH_DAY)) { needle = needle->next; total++; } else { needle = NULL; } } buf = pan_date_value_string(fd->date, PAN_DATE_LENGTH_WEEK); pi = pan_item_text_new(pw, x, y, buf, PAN_TEXT_ATTR_NONE, PAN_TEXT_BORDER_SIZE, PAN_TEXT_COLOR, 255); g_free(buf); y += pi->height; pi_day = pan_item_box_new(pw, file_data_new_simple(fd->path), x, y, 0, 0, PAN_BOX_OUTLINE_THICKNESS, PAN_BOX_COLOR, PAN_BOX_ALPHA, PAN_BOX_OUTLINE_COLOR, PAN_BOX_OUTLINE_ALPHA); x += PAN_BOX_BORDER; y += PAN_BOX_BORDER; day_start = y; } if (pw->size > PAN_IMAGE_SIZE_THUMB_LARGE) { pi = pan_item_image_new(pw, fd, x, y, 10, 10); if (pi->width > x_width) x_width = pi->width; y_height = pi->height; } else { pi = pan_item_thumb_new(pw, fd, x, y); x_width = PAN_THUMB_SIZE; y_height = PAN_THUMB_SIZE; } pan_item_size_by_item(pi_day, pi, PAN_BOX_BORDER); pan_item_size_by_item(pi_month, pi_day, PAN_BOX_BORDER); total--; count++; if (total > 0 && count < PAN_GROUP_MAX) { y += y_height + PAN_THUMB_GAP; } else { x += x_width + PAN_THUMB_GAP; x_width = 0; count = 0; if (total > 0) y = day_start; else y = month_start; } pan_item_size_coordinates(pi_month, PAN_BOX_BORDER, width, height); } g_list_free(list); }