2 * Copyright (C) 2006 John Ellis
3 * Copyright (C) 2008 - 2016 The Geeqie Team
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "pan-folder.h"
28 #include "pan-types.h"
30 #include "pan-view-filter.h"
33 static void pan_flower_size(PanWindow *pw, gint *width, gint *height)
51 pi = static_cast<PanItem *>(work->data);
54 if (x1 > pi->x) x1 = pi->x;
55 if (y1 > pi->y) y1 = pi->y;
56 if (x2 < pi->x + pi->width) x2 = pi->x + pi->width;
57 if (y2 < pi->y + pi->height) y2 = pi->y + pi->height;
70 pi = static_cast<PanItem *>(work->data);
76 if (pi->type == PAN_ITEM_TRIANGLE && pi->data)
80 coord = static_cast<gint *>(pi->data);
90 if (width) *width = x2 - x1;
91 if (height) *height = y2 - y1;
107 static void pan_flower_move(FlowerGroup *group, gint x, gint y)
116 pi = static_cast<PanItem *>(work->data);
127 #define PI 3.14159265
129 static void pan_flower_position(FlowerGroup *group, FlowerGroup *parent,
130 gint *result_x, gint *result_y)
137 radius = parent->circumference / (2*PI);
138 radius = MAX(radius, parent->diameter / 2 + group->diameter / 2);
140 a = 2*PI * group->diameter / parent->circumference;
142 x = static_cast<gint>(static_cast<gdouble>(radius) * cos(parent->angle + a / 2));
143 y = static_cast<gint>(static_cast<gdouble>(radius) * sin(parent->angle + a / 2));
150 x += parent->width / 2;
151 y += parent->height / 2;
153 x -= group->width / 2;
154 y -= group->height / 2;
160 static void pan_flower_build(PanWindow *pw, FlowerGroup *group, FlowerGroup *parent)
168 if (parent && parent->children)
170 pan_flower_position(group, parent, &x, &y);
178 pan_flower_move(group, x, y);
192 px = parent->x + parent->width / 2;
193 py = parent->y + parent->height / 2;
195 gx = group->x + group->width / 2;
196 gy = group->y + group->height / 2;
201 x2 = MAX(px, gx + 5);
202 y2 = MAX(py, gy + 5);
204 pi = pan_item_tri_new(pw, nullptr, x1, y1, x2 - x1, y2 - y1,
205 px, py, gx, gy, gx + 5, gy + 5,
207 pan_item_tri_border(pi, PAN_BORDER_1 | PAN_BORDER_3, {255, 0, 0, 128});
210 pw->list = g_list_concat(group->items, pw->list);
211 group->items = nullptr;
213 group->circumference = 0;
214 work = group->children;
219 child = static_cast<FlowerGroup *>(work->data);
222 group->circumference += child->diameter;
225 work = g_list_last(group->children);
230 child = static_cast<FlowerGroup *>(work->data);
233 pan_flower_build(pw, child, group);
236 g_list_free(group->children);
240 static FlowerGroup *pan_flower_group(PanWindow *pw, FileData *dir_fd, gint x, gint y)
252 if (!filelist_read(dir_fd, &f, &d)) return nullptr;
253 if (!f && !d) return nullptr;
255 f = filelist_sort(f, SORT_NAME, TRUE, TRUE);
256 d = filelist_sort(d, SORT_NAME, TRUE, TRUE);
258 pan_filter_fd_list(&f, pw->filter_ui->filter_elements, pw->filter_ui->filter_classes);
260 pi_box = pan_item_text_new(pw, x, y, dir_fd->path, PAN_TEXT_ATTR_NONE,
262 {PAN_TEXT_COLOR, 255});
266 pi_box = pan_item_box_new(pw, file_data_ref(dir_fd),
268 PAN_BOX_BORDER * 2, PAN_BOX_BORDER * 2,
269 PAN_BOX_OUTLINE_THICKNESS,
270 {PAN_BOX_COLOR, PAN_BOX_ALPHA},
271 {PAN_BOX_OUTLINE_COLOR, PAN_BOX_OUTLINE_ALPHA});
276 grid_size = static_cast<gint>(sqrt(g_list_length(f)) + 0.9);
287 fd = static_cast<FileData *>(work->data);
290 if (pw->size > PAN_IMAGE_SIZE_THUMB_LARGE)
292 pi = pan_item_image_new(pw, fd, x, y, 10, 10);
293 x += pi->width + PAN_THUMB_GAP;
294 if (pi->height > y_height) y_height = pi->height;
298 pi = pan_item_thumb_new(pw, fd, x, y);
299 x += PAN_THUMB_SIZE + PAN_THUMB_GAP;
300 y_height = PAN_THUMB_SIZE;
304 if (grid_count >= grid_size)
308 y += y_height + PAN_THUMB_GAP;
312 pan_item_size_by_item(pi_box, pi, PAN_BOX_BORDER);
315 group = g_new0(FlowerGroup, 1);
316 group->items = pw->list;
319 group->width = pi_box->width;
320 group->height = pi_box->y + pi_box->height;
321 group->diameter = static_cast<gint>(hypot(group->width, group->height));
323 group->children = nullptr;
331 fd = static_cast<FileData *>(work->data);
334 if (!pan_is_ignored(fd->path, pw->ignore_symlinks))
336 child = pan_flower_group(pw, fd, 0, 0);
337 if (child) group->children = g_list_prepend(group->children, child);
341 if (!f && !group->children)
343 g_list_free_full(group->items, reinterpret_cast<GDestroyNotify>(pan_item_free));
354 void pan_flower_compute(PanWindow *pw, FileData *dir_fd,
355 gint *width, gint *height,
356 gint *scroll_x, gint *scroll_y)
361 group = pan_flower_group(pw, dir_fd, 0, 0);
362 pan_flower_build(pw, group, nullptr);
364 pan_flower_size(pw, width, height);
366 list = pan_item_find_by_fd(pw, PAN_ITEM_BOX, dir_fd, FALSE, FALSE);
369 auto pi = static_cast<PanItem *>(list->data);
370 *scroll_x = pi->x + pi->width / 2;
371 *scroll_y = pi->y + pi->height / 2;
376 static void pan_folder_tree_path(PanWindow *pw, FileData *dir_fd,
377 gint *x, gint *y, gint *level,
379 gint *width, gint *height)
387 if (!filelist_read(dir_fd, &f, &d)) return;
388 if (!f && !d) return;
390 f = filelist_sort(f, SORT_NAME, TRUE, TRUE);
391 d = filelist_sort(d, SORT_NAME, TRUE, TRUE);
393 pan_filter_fd_list(&f, pw->filter_ui->filter_elements, pw->filter_ui->filter_classes);
395 *x = PAN_BOX_BORDER + ((*level) * MAX(PAN_BOX_BORDER, PAN_THUMB_GAP));
397 pi_box = pan_item_text_new(pw, *x, *y, dir_fd->path, PAN_TEXT_ATTR_NONE,
399 {PAN_TEXT_COLOR, 255});
401 *y += pi_box->height;
403 pi_box = pan_item_box_new(pw, file_data_ref(dir_fd),
405 PAN_BOX_BORDER, PAN_BOX_BORDER,
406 PAN_BOX_OUTLINE_THICKNESS,
407 {PAN_BOX_COLOR, PAN_BOX_ALPHA},
408 {PAN_BOX_OUTLINE_COLOR, PAN_BOX_OUTLINE_ALPHA});
410 *x += PAN_BOX_BORDER;
411 *y += PAN_BOX_BORDER;
419 fd = static_cast<FileData *>(work->data);
422 if (pw->size > PAN_IMAGE_SIZE_THUMB_LARGE)
424 pi = pan_item_image_new(pw, fd, *x, *y, 10, 10);
425 *x += pi->width + PAN_THUMB_GAP;
426 if (pi->height > y_height) y_height = pi->height;
430 pi = pan_item_thumb_new(pw, fd, *x, *y);
431 *x += PAN_THUMB_SIZE + PAN_THUMB_GAP;
432 y_height = PAN_THUMB_SIZE;
435 pan_item_size_by_item(pi_box, pi, PAN_BOX_BORDER);
438 if (f) *y = pi_box->y + pi_box->height;
447 fd = static_cast<FileData *>(work->data);
450 if (!pan_is_ignored(fd->path, pw->ignore_symlinks))
453 pan_folder_tree_path(pw, fd, x, y, level, pi_box, width, height);
460 pan_item_size_by_item(parent, pi_box, PAN_BOX_BORDER);
462 if (*y < pi_box->y + pi_box->height + PAN_BOX_BORDER)
463 *y = pi_box->y + pi_box->height + PAN_BOX_BORDER;
465 pan_item_size_coordinates(pi_box, PAN_BOX_BORDER, width, height);
468 void pan_folder_tree_compute(PanWindow *pw, FileData *dir_fd, gint *width, gint *height)
479 w = PAN_BOX_BORDER * 2;
480 h = PAN_BOX_BORDER * 2;
482 pan_folder_tree_path(pw, dir_fd, &x, &y, &level, nullptr, &w, &h);
484 if (width) *width = w;
485 if (height) *height = h;
487 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */