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"
29 #include "pan-types.h"
31 #include "pan-view-filter.h"
34 static void pan_flower_size(PanWindow *pw, gint &width, gint &height)
52 pi = static_cast<PanItem *>(work->data);
55 if (x1 > pi->x) x1 = pi->x;
56 if (y1 > pi->y) y1 = pi->y;
57 if (x2 < pi->x + pi->width) x2 = pi->x + pi->width;
58 if (y2 < pi->y + pi->height) y2 = pi->y + pi->height;
71 pi = static_cast<PanItem *>(work->data);
77 if (pi->type == PAN_ITEM_TRIANGLE && pi->data)
81 coord = static_cast<gint *>(pi->data);
108 static void pan_flower_move(FlowerGroup *group, gint x, gint y)
117 pi = static_cast<PanItem *>(work->data);
128 static void pan_flower_position(FlowerGroup *group, FlowerGroup *parent,
129 gint *result_x, gint *result_y)
136 radius = parent->circumference / (2*G_PI);
137 radius = MAX(radius, parent->diameter / 2 + group->diameter / 2);
139 a = 2*G_PI * group->diameter / parent->circumference;
141 x = static_cast<gint>(static_cast<gdouble>(radius) * cos(parent->angle + a / 2));
142 y = static_cast<gint>(static_cast<gdouble>(radius) * sin(parent->angle + a / 2));
149 x += parent->width / 2;
150 y += parent->height / 2;
152 x -= group->width / 2;
153 y -= group->height / 2;
159 static void pan_flower_build(PanWindow *pw, FlowerGroup *group, FlowerGroup *parent)
167 if (parent && parent->children)
169 pan_flower_position(group, parent, &x, &y);
177 pan_flower_move(group, x, y);
191 px = parent->x + parent->width / 2;
192 py = parent->y + parent->height / 2;
194 gx = group->x + group->width / 2;
195 gy = group->y + group->height / 2;
200 x2 = MAX(px, gx + 5);
201 y2 = MAX(py, gy + 5);
203 pi = pan_item_tri_new(pw, nullptr, x1, y1, x2 - x1, y2 - y1,
204 px, py, gx, gy, gx + 5, gy + 5,
206 pan_item_tri_border(pi, PAN_BORDER_1 | PAN_BORDER_3, {255, 0, 0, 128});
209 pw->list = g_list_concat(group->items, pw->list);
210 group->items = nullptr;
212 group->circumference = 0;
213 work = group->children;
218 child = static_cast<FlowerGroup *>(work->data);
221 group->circumference += child->diameter;
224 work = g_list_last(group->children);
229 child = static_cast<FlowerGroup *>(work->data);
232 pan_flower_build(pw, child, group);
235 g_list_free(group->children);
239 static FlowerGroup *pan_flower_group(PanWindow *pw, FileData *dir_fd, gint x, gint y)
251 if (!filelist_read(dir_fd, &f, &d)) return nullptr;
252 if (!f && !d) return nullptr;
254 f = filelist_sort(f, SORT_NAME, TRUE, TRUE);
255 d = filelist_sort(d, SORT_NAME, TRUE, TRUE);
257 pan_filter_fd_list(&f, pw->filter_ui->filter_elements, pw->filter_ui->filter_classes);
259 pi_box = pan_item_text_new(pw, x, y, dir_fd->path, PAN_TEXT_ATTR_NONE,
261 {PAN_TEXT_COLOR, 255});
265 pi_box = pan_item_box_new(pw, file_data_ref(dir_fd),
267 PAN_BOX_BORDER * 2, PAN_BOX_BORDER * 2,
268 PAN_BOX_OUTLINE_THICKNESS,
269 {PAN_BOX_COLOR, PAN_BOX_ALPHA},
270 {PAN_BOX_OUTLINE_COLOR, PAN_BOX_OUTLINE_ALPHA});
275 grid_size = static_cast<gint>(sqrt(g_list_length(f)) + 0.9);
286 fd = static_cast<FileData *>(work->data);
289 if (pw->size > PAN_IMAGE_SIZE_THUMB_LARGE)
291 pi = pan_item_image_new(pw, fd, x, y, 10, 10);
292 x += pi->width + PAN_THUMB_GAP;
293 if (pi->height > y_height) y_height = pi->height;
297 pi = pan_item_thumb_new(pw, fd, x, y);
298 x += PAN_THUMB_SIZE + PAN_THUMB_GAP;
299 y_height = PAN_THUMB_SIZE;
303 if (grid_count >= grid_size)
307 y += y_height + PAN_THUMB_GAP;
311 pan_item_size_by_item(pi_box, pi, PAN_BOX_BORDER);
314 group = g_new0(FlowerGroup, 1);
315 group->items = pw->list;
318 group->width = pi_box->width;
319 group->height = pi_box->y + pi_box->height;
320 group->diameter = static_cast<gint>(hypot(group->width, group->height));
322 group->children = nullptr;
330 fd = static_cast<FileData *>(work->data);
333 if (!pan_is_ignored(fd->path, pw->ignore_symlinks))
335 child = pan_flower_group(pw, fd, 0, 0);
336 if (child) group->children = g_list_prepend(group->children, child);
340 if (!f && !group->children)
342 g_list_free_full(group->items, reinterpret_cast<GDestroyNotify>(pan_item_free));
353 void pan_flower_compute(PanWindow *pw, FileData *dir_fd,
354 gint &width, gint &height,
355 gint &scroll_x, gint &scroll_y)
360 group = pan_flower_group(pw, dir_fd, 0, 0);
361 pan_flower_build(pw, group, nullptr);
363 pan_flower_size(pw, width, height);
365 list = pan_item_find_by_fd(pw, PAN_ITEM_BOX, dir_fd, FALSE, FALSE);
368 auto pi = static_cast<PanItem *>(list->data);
369 scroll_x = pi->x + pi->width / 2;
370 scroll_y = pi->y + pi->height / 2;
375 static void pan_folder_tree_path(PanWindow *pw, FileData *dir_fd,
376 gint &x, gint &y, gint level,
378 gint &width, gint &height)
386 if (!filelist_read(dir_fd, &f, &d)) return;
387 if (!f && !d) return;
389 f = filelist_sort(f, SORT_NAME, TRUE, TRUE);
390 d = filelist_sort(d, SORT_NAME, TRUE, TRUE);
392 pan_filter_fd_list(&f, pw->filter_ui->filter_elements, pw->filter_ui->filter_classes);
394 x = PAN_BOX_BORDER + (level * MAX(PAN_BOX_BORDER, PAN_THUMB_GAP));
396 pi_box = pan_item_text_new(pw, x, y, dir_fd->path, PAN_TEXT_ATTR_NONE,
398 {PAN_TEXT_COLOR, 255});
402 pi_box = pan_item_box_new(pw, file_data_ref(dir_fd),
404 PAN_BOX_BORDER, PAN_BOX_BORDER,
405 PAN_BOX_OUTLINE_THICKNESS,
406 {PAN_BOX_COLOR, PAN_BOX_ALPHA},
407 {PAN_BOX_OUTLINE_COLOR, PAN_BOX_OUTLINE_ALPHA});
418 fd = static_cast<FileData *>(work->data);
421 if (pw->size > PAN_IMAGE_SIZE_THUMB_LARGE)
423 pi = pan_item_image_new(pw, fd, x, y, 10, 10);
424 x += pi->width + PAN_THUMB_GAP;
425 if (pi->height > y_height) y_height = pi->height;
429 pi = pan_item_thumb_new(pw, fd, x, y);
430 x += PAN_THUMB_SIZE + PAN_THUMB_GAP;
431 y_height = PAN_THUMB_SIZE;
434 pan_item_size_by_item(pi_box, pi, PAN_BOX_BORDER);
437 if (f) y = pi_box->y + pi_box->height;
446 fd = static_cast<FileData *>(work->data);
449 if (!pan_is_ignored(fd->path, pw->ignore_symlinks))
451 pan_folder_tree_path(pw, fd, x, y, level + 1, pi_box, width, height);
457 pan_item_size_by_item(parent, pi_box, PAN_BOX_BORDER);
459 y = std::max(y, pi_box->y + pi_box->height + PAN_BOX_BORDER);
461 pan_item_size_coordinates(pi_box, PAN_BOX_BORDER, width, height);
464 void pan_folder_tree_compute(PanWindow *pw, FileData *dir_fd, gint &width, gint &height)
471 width = PAN_BOX_BORDER * 2;
472 height = PAN_BOX_BORDER * 2;
474 pan_folder_tree_path(pw, dir_fd, x, y, 0, nullptr, width, height);
476 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */