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)
45 pi = static_cast<PanItem *>(work->data);
48 if (x1 > pi->x) x1 = pi->x;
49 if (y1 > pi->y) y1 = pi->y;
50 if (x2 < pi->x + pi->width) x2 = pi->x + pi->width;
51 if (y2 < pi->y + pi->height) y2 = pi->y + pi->height;
64 pi = static_cast<PanItem *>(work->data);
70 if (pi->type == PAN_ITEM_TRIANGLE && pi->data)
74 coord = static_cast<gint *>(pi->data);
84 if (width) *width = x2 - x1;
85 if (height) *height = y2 - y1;
101 static void pan_flower_move(FlowerGroup *group, gint x, gint y)
110 pi = static_cast<PanItem *>(work->data);
121 #define PI 3.14159265
123 static void pan_flower_position(FlowerGroup *group, FlowerGroup *parent,
124 gint *result_x, gint *result_y)
130 radius = parent->circumference / (2*PI);
131 radius = MAX(radius, parent->diameter / 2 + group->diameter / 2);
133 a = 2*PI * group->diameter / parent->circumference;
135 x = static_cast<gint>(static_cast<gdouble>(radius) * cos(parent->angle + a / 2));
136 y = static_cast<gint>(static_cast<gdouble>(radius) * sin(parent->angle + a / 2));
143 x += parent->width / 2;
144 y += parent->height / 2;
146 x -= group->width / 2;
147 y -= group->height / 2;
153 static void pan_flower_build(PanWindow *pw, FlowerGroup *group, FlowerGroup *parent)
160 if (parent && parent->children)
162 pan_flower_position(group, parent, &x, &y);
170 pan_flower_move(group, x, y);
178 px = parent->x + parent->width / 2;
179 py = parent->y + parent->height / 2;
181 gx = group->x + group->width / 2;
182 gy = group->y + group->height / 2;
187 x2 = MAX(px, gx + 5);
188 y2 = MAX(py, gy + 5);
190 pi = pan_item_tri_new(pw, nullptr, x1, y1, x2 - x1, y2 - y1,
191 px, py, gx, gy, gx + 5, gy + 5,
193 pan_item_tri_border(pi, PAN_BORDER_1 | PAN_BORDER_3,
197 pw->list = g_list_concat(group->items, pw->list);
198 group->items = nullptr;
200 group->circumference = 0;
201 work = group->children;
206 child = static_cast<FlowerGroup *>(work->data);
209 group->circumference += child->diameter;
212 work = g_list_last(group->children);
217 child = static_cast<FlowerGroup *>(work->data);
220 pan_flower_build(pw, child, group);
223 g_list_free(group->children);
227 static FlowerGroup *pan_flower_group(PanWindow *pw, FileData *dir_fd, gint x, gint y)
239 if (!filelist_read(dir_fd, &f, &d)) return nullptr;
240 if (!f && !d) return nullptr;
242 f = filelist_sort(f, SORT_NAME, TRUE, TRUE);
243 d = filelist_sort(d, SORT_NAME, TRUE, TRUE);
245 pan_filter_fd_list(&f, pw->filter_ui->filter_elements, pw->filter_ui->filter_classes);
247 pi_box = pan_item_text_new(pw, x, y, dir_fd->path, PAN_TEXT_ATTR_NONE,
249 PAN_TEXT_COLOR, 255);
253 pi_box = pan_item_box_new(pw, file_data_ref(dir_fd),
255 PAN_BOX_BORDER * 2, PAN_BOX_BORDER * 2,
256 PAN_BOX_OUTLINE_THICKNESS,
257 PAN_BOX_COLOR, PAN_BOX_ALPHA,
258 PAN_BOX_OUTLINE_COLOR, PAN_BOX_OUTLINE_ALPHA);
263 grid_size = static_cast<gint>(sqrt(g_list_length(f)) + 0.9);
274 fd = static_cast<FileData *>(work->data);
277 if (pw->size > PAN_IMAGE_SIZE_THUMB_LARGE)
279 pi = pan_item_image_new(pw, fd, x, y, 10, 10);
280 x += pi->width + PAN_THUMB_GAP;
281 if (pi->height > y_height) y_height = pi->height;
285 pi = pan_item_thumb_new(pw, fd, x, y);
286 x += PAN_THUMB_SIZE + PAN_THUMB_GAP;
287 y_height = PAN_THUMB_SIZE;
291 if (grid_count >= grid_size)
295 y += y_height + PAN_THUMB_GAP;
299 pan_item_size_by_item(pi_box, pi, PAN_BOX_BORDER);
302 group = g_new0(FlowerGroup, 1);
303 group->items = pw->list;
306 group->width = pi_box->width;
307 group->height = pi_box->y + pi_box->height;
308 group->diameter = static_cast<gint>(hypot(group->width, group->height));
310 group->children = nullptr;
318 fd = static_cast<FileData *>(work->data);
321 if (!pan_is_ignored(fd->path, pw->ignore_symlinks))
323 child = pan_flower_group(pw, fd, 0, 0);
324 if (child) group->children = g_list_prepend(group->children, child);
328 if (!f && !group->children)
330 g_list_free_full(group->items, reinterpret_cast<GDestroyNotify>(pan_item_free));
341 void pan_flower_compute(PanWindow *pw, FileData *dir_fd,
342 gint *width, gint *height,
343 gint *scroll_x, gint *scroll_y)
348 group = pan_flower_group(pw, dir_fd, 0, 0);
349 pan_flower_build(pw, group, nullptr);
351 pan_flower_size(pw, width, height);
353 list = pan_item_find_by_fd(pw, PAN_ITEM_BOX, dir_fd, FALSE, FALSE);
356 auto pi = static_cast<PanItem *>(list->data);
357 *scroll_x = pi->x + pi->width / 2;
358 *scroll_y = pi->y + pi->height / 2;
363 static void pan_folder_tree_path(PanWindow *pw, FileData *dir_fd,
364 gint *x, gint *y, gint *level,
366 gint *width, gint *height)
374 if (!filelist_read(dir_fd, &f, &d)) return;
375 if (!f && !d) return;
377 f = filelist_sort(f, SORT_NAME, TRUE, TRUE);
378 d = filelist_sort(d, SORT_NAME, TRUE, TRUE);
380 pan_filter_fd_list(&f, pw->filter_ui->filter_elements, pw->filter_ui->filter_classes);
382 *x = PAN_BOX_BORDER + ((*level) * MAX(PAN_BOX_BORDER, PAN_THUMB_GAP));
384 pi_box = pan_item_text_new(pw, *x, *y, dir_fd->path, PAN_TEXT_ATTR_NONE,
386 PAN_TEXT_COLOR, 255);
388 *y += pi_box->height;
390 pi_box = pan_item_box_new(pw, file_data_ref(dir_fd),
392 PAN_BOX_BORDER, PAN_BOX_BORDER,
393 PAN_BOX_OUTLINE_THICKNESS,
394 PAN_BOX_COLOR, PAN_BOX_ALPHA,
395 PAN_BOX_OUTLINE_COLOR, PAN_BOX_OUTLINE_ALPHA);
397 *x += PAN_BOX_BORDER;
398 *y += PAN_BOX_BORDER;
406 fd = static_cast<FileData *>(work->data);
409 if (pw->size > PAN_IMAGE_SIZE_THUMB_LARGE)
411 pi = pan_item_image_new(pw, fd, *x, *y, 10, 10);
412 *x += pi->width + PAN_THUMB_GAP;
413 if (pi->height > y_height) y_height = pi->height;
417 pi = pan_item_thumb_new(pw, fd, *x, *y);
418 *x += PAN_THUMB_SIZE + PAN_THUMB_GAP;
419 y_height = PAN_THUMB_SIZE;
422 pan_item_size_by_item(pi_box, pi, PAN_BOX_BORDER);
425 if (f) *y = pi_box->y + pi_box->height;
434 fd = static_cast<FileData *>(work->data);
437 if (!pan_is_ignored(fd->path, pw->ignore_symlinks))
440 pan_folder_tree_path(pw, fd, x, y, level, pi_box, width, height);
447 pan_item_size_by_item(parent, pi_box, PAN_BOX_BORDER);
449 if (*y < pi_box->y + pi_box->height + PAN_BOX_BORDER)
450 *y = pi_box->y + pi_box->height + PAN_BOX_BORDER;
452 pan_item_size_coordinates(pi_box, PAN_BOX_BORDER, width, height);
455 void pan_folder_tree_compute(PanWindow *pw, FileData *dir_fd, gint *width, gint *height)
464 w = PAN_BOX_BORDER * 2;
465 h = PAN_BOX_BORDER * 2;
467 pan_folder_tree_path(pw, dir_fd, &x, &y, &level, nullptr, &w, &h);
469 if (width) *width = w;
470 if (height) *height = h;
472 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */