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-view-filter.h"
30 static void pan_flower_size(PanWindow *pw, gint *width, gint *height)
48 pi = static_cast<PanItem *>(work->data);
51 if (x1 > pi->x) x1 = pi->x;
52 if (y1 > pi->y) y1 = pi->y;
53 if (x2 < pi->x + pi->width) x2 = pi->x + pi->width;
54 if (y2 < pi->y + pi->height) y2 = pi->y + pi->height;
67 pi = static_cast<PanItem *>(work->data);
73 if (pi->type == PAN_ITEM_TRIANGLE && pi->data)
77 coord = static_cast<gint *>(pi->data);
87 if (width) *width = x2 - x1;
88 if (height) *height = y2 - y1;
104 static void pan_flower_move(FlowerGroup *group, gint x, gint y)
113 pi = static_cast<PanItem *>(work->data);
124 #define PI 3.14159265
126 static void pan_flower_position(FlowerGroup *group, FlowerGroup *parent,
127 gint *result_x, gint *result_y)
134 radius = parent->circumference / (2*PI);
135 radius = MAX(radius, parent->diameter / 2 + group->diameter / 2);
137 a = 2*PI * group->diameter / parent->circumference;
139 x = static_cast<gint>(static_cast<gdouble>(radius) * cos(parent->angle + a / 2));
140 y = static_cast<gint>(static_cast<gdouble>(radius) * sin(parent->angle + a / 2));
147 x += parent->width / 2;
148 y += parent->height / 2;
150 x -= group->width / 2;
151 y -= group->height / 2;
157 static void pan_flower_build(PanWindow *pw, FlowerGroup *group, FlowerGroup *parent)
165 if (parent && parent->children)
167 pan_flower_position(group, parent, &x, &y);
175 pan_flower_move(group, x, y);
189 px = parent->x + parent->width / 2;
190 py = parent->y + parent->height / 2;
192 gx = group->x + group->width / 2;
193 gy = group->y + group->height / 2;
198 x2 = MAX(px, gx + 5);
199 y2 = MAX(py, gy + 5);
201 pi = pan_item_tri_new(pw, nullptr, x1, y1, x2 - x1, y2 - y1,
202 px, py, gx, gy, gx + 5, gy + 5,
204 pan_item_tri_border(pi, PAN_BORDER_1 | PAN_BORDER_3,
208 pw->list = g_list_concat(group->items, pw->list);
209 group->items = nullptr;
211 group->circumference = 0;
212 work = group->children;
217 child = static_cast<FlowerGroup *>(work->data);
220 group->circumference += child->diameter;
223 work = g_list_last(group->children);
228 child = static_cast<FlowerGroup *>(work->data);
231 pan_flower_build(pw, child, group);
234 g_list_free(group->children);
238 static FlowerGroup *pan_flower_group(PanWindow *pw, FileData *dir_fd, gint x, gint y)
250 if (!filelist_read(dir_fd, &f, &d)) return nullptr;
251 if (!f && !d) return nullptr;
253 f = filelist_sort(f, SORT_NAME, TRUE, TRUE);
254 d = filelist_sort(d, SORT_NAME, TRUE, TRUE);
256 pan_filter_fd_list(&f, pw->filter_ui->filter_elements, pw->filter_ui->filter_classes);
258 pi_box = pan_item_text_new(pw, x, y, dir_fd->path, PAN_TEXT_ATTR_NONE,
260 PAN_TEXT_COLOR, 255);
264 pi_box = pan_item_box_new(pw, file_data_ref(dir_fd),
266 PAN_BOX_BORDER * 2, PAN_BOX_BORDER * 2,
267 PAN_BOX_OUTLINE_THICKNESS,
268 PAN_BOX_COLOR, PAN_BOX_ALPHA,
269 PAN_BOX_OUTLINE_COLOR, PAN_BOX_OUTLINE_ALPHA);
274 grid_size = static_cast<gint>(sqrt(g_list_length(f)) + 0.9);
285 fd = static_cast<FileData *>(work->data);
288 if (pw->size > PAN_IMAGE_SIZE_THUMB_LARGE)
290 pi = pan_item_image_new(pw, fd, x, y, 10, 10);
291 x += pi->width + PAN_THUMB_GAP;
292 if (pi->height > y_height) y_height = pi->height;
296 pi = pan_item_thumb_new(pw, fd, x, y);
297 x += PAN_THUMB_SIZE + PAN_THUMB_GAP;
298 y_height = PAN_THUMB_SIZE;
302 if (grid_count >= grid_size)
306 y += y_height + PAN_THUMB_GAP;
310 pan_item_size_by_item(pi_box, pi, PAN_BOX_BORDER);
313 group = g_new0(FlowerGroup, 1);
314 group->items = pw->list;
317 group->width = pi_box->width;
318 group->height = pi_box->y + pi_box->height;
319 group->diameter = static_cast<gint>(hypot(group->width, group->height));
321 group->children = nullptr;
329 fd = static_cast<FileData *>(work->data);
332 if (!pan_is_ignored(fd->path, pw->ignore_symlinks))
334 child = pan_flower_group(pw, fd, 0, 0);
335 if (child) group->children = g_list_prepend(group->children, child);
339 if (!f && !group->children)
341 g_list_free_full(group->items, reinterpret_cast<GDestroyNotify>(pan_item_free));
352 void pan_flower_compute(PanWindow *pw, FileData *dir_fd,
353 gint *width, gint *height,
354 gint *scroll_x, gint *scroll_y)
359 group = pan_flower_group(pw, dir_fd, 0, 0);
360 pan_flower_build(pw, group, nullptr);
362 pan_flower_size(pw, width, height);
364 list = pan_item_find_by_fd(pw, PAN_ITEM_BOX, dir_fd, FALSE, FALSE);
367 auto pi = static_cast<PanItem *>(list->data);
368 *scroll_x = pi->x + pi->width / 2;
369 *scroll_y = pi->y + pi->height / 2;
374 static void pan_folder_tree_path(PanWindow *pw, FileData *dir_fd,
375 gint *x, gint *y, gint *level,
377 gint *width, gint *height)
385 if (!filelist_read(dir_fd, &f, &d)) return;
386 if (!f && !d) return;
388 f = filelist_sort(f, SORT_NAME, TRUE, TRUE);
389 d = filelist_sort(d, SORT_NAME, TRUE, TRUE);
391 pan_filter_fd_list(&f, pw->filter_ui->filter_elements, pw->filter_ui->filter_classes);
393 *x = PAN_BOX_BORDER + ((*level) * MAX(PAN_BOX_BORDER, PAN_THUMB_GAP));
395 pi_box = pan_item_text_new(pw, *x, *y, dir_fd->path, PAN_TEXT_ATTR_NONE,
397 PAN_TEXT_COLOR, 255);
399 *y += pi_box->height;
401 pi_box = pan_item_box_new(pw, file_data_ref(dir_fd),
403 PAN_BOX_BORDER, PAN_BOX_BORDER,
404 PAN_BOX_OUTLINE_THICKNESS,
405 PAN_BOX_COLOR, PAN_BOX_ALPHA,
406 PAN_BOX_OUTLINE_COLOR, PAN_BOX_OUTLINE_ALPHA);
408 *x += PAN_BOX_BORDER;
409 *y += PAN_BOX_BORDER;
417 fd = static_cast<FileData *>(work->data);
420 if (pw->size > PAN_IMAGE_SIZE_THUMB_LARGE)
422 pi = pan_item_image_new(pw, fd, *x, *y, 10, 10);
423 *x += pi->width + PAN_THUMB_GAP;
424 if (pi->height > y_height) y_height = pi->height;
428 pi = pan_item_thumb_new(pw, fd, *x, *y);
429 *x += PAN_THUMB_SIZE + PAN_THUMB_GAP;
430 y_height = PAN_THUMB_SIZE;
433 pan_item_size_by_item(pi_box, pi, PAN_BOX_BORDER);
436 if (f) *y = pi_box->y + pi_box->height;
445 fd = static_cast<FileData *>(work->data);
448 if (!pan_is_ignored(fd->path, pw->ignore_symlinks))
451 pan_folder_tree_path(pw, fd, x, y, level, pi_box, width, height);
458 pan_item_size_by_item(parent, pi_box, PAN_BOX_BORDER);
460 if (*y < pi_box->y + pi_box->height + PAN_BOX_BORDER)
461 *y = pi_box->y + pi_box->height + PAN_BOX_BORDER;
463 pan_item_size_coordinates(pi_box, PAN_BOX_BORDER, width, height);
466 void pan_folder_tree_compute(PanWindow *pw, FileData *dir_fd, gint *width, gint *height)
477 w = PAN_BOX_BORDER * 2;
478 h = PAN_BOX_BORDER * 2;
480 pan_folder_tree_path(pw, dir_fd, &x, &y, &level, nullptr, &w, &h);
482 if (width) *width = w;
483 if (height) *height = h;
485 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */