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 static void pan_flower_size(PanWindow *pw, gint *width, gint *height)
47 if (x1 > pi->x) x1 = pi->x;
48 if (y1 > pi->y) y1 = pi->y;
49 if (x2 < pi->x + pi->width) x2 = pi->x + pi->width;
50 if (y2 < pi->y + pi->height) y2 = pi->y + pi->height;
69 if (pi->type == PAN_ITEM_TRIANGLE && pi->data)
83 if (width) *width = x2 - x1;
84 if (height) *height = y2 - y1;
87 typedef struct _FlowerGroup FlowerGroup;
101 static void pan_flower_move(FlowerGroup *group, gint x, gint y)
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 = (gint)((gdouble)radius * cos(parent->angle + a / 2));
136 y = (gint)((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, NULL, 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);
200 group->circumference = 0;
201 work = group->children;
209 group->circumference += child->diameter;
212 work = g_list_last(group->children);
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 NULL;
240 if (!f && !d) return NULL;
242 f = filelist_sort(f, SORT_NAME, TRUE);
243 d = filelist_sort(d, SORT_NAME, TRUE);
245 pi_box = pan_item_text_new(pw, x, y, dir_fd->path, PAN_TEXT_ATTR_NONE,
246 PAN_TEXT_BORDER_SIZE,
247 PAN_TEXT_COLOR, 255);
251 pi_box = pan_item_box_new(pw, file_data_ref(dir_fd),
253 PAN_BOX_BORDER * 2, PAN_BOX_BORDER * 2,
254 PAN_BOX_OUTLINE_THICKNESS,
255 PAN_BOX_COLOR, PAN_BOX_ALPHA,
256 PAN_BOX_OUTLINE_COLOR, PAN_BOX_OUTLINE_ALPHA);
261 grid_size = (gint)(sqrt(g_list_length(f)) + 0.9);
275 if (pw->size > PAN_IMAGE_SIZE_THUMB_LARGE)
277 pi = pan_item_image_new(pw, fd, x, y, 10, 10);
278 x += pi->width + PAN_THUMB_GAP;
279 if (pi->height > y_height) y_height = pi->height;
283 pi = pan_item_thumb_new(pw, fd, x, y);
284 x += PAN_THUMB_SIZE + PAN_THUMB_GAP;
285 y_height = PAN_THUMB_SIZE;
289 if (grid_count >= grid_size)
293 y += y_height + PAN_THUMB_GAP;
297 pan_item_size_by_item(pi_box, pi, PAN_BOX_BORDER);
300 group = g_new0(FlowerGroup, 1);
301 group->items = pw->list;
304 group->width = pi_box->width;
305 group->height = pi_box->y + pi_box->height;
306 group->diameter = (gint)sqrt(group->width * group->width + group->height * group->height);
308 group->children = NULL;
319 if (!pan_is_ignored(fd->path, pw->ignore_symlinks))
321 child = pan_flower_group(pw, fd, 0, 0);
322 if (child) group->children = g_list_prepend(group->children, child);
326 if (!f && !group->children)
339 g_list_free(group->items);
350 void pan_flower_compute(PanWindow *pw, FileData *dir_fd,
351 gint *width, gint *height,
352 gint *scroll_x, gint *scroll_y)
357 group = pan_flower_group(pw, dir_fd, 0, 0);
358 pan_flower_build(pw, group, NULL);
360 pan_flower_size(pw, width, height);
362 list = pan_item_find_by_fd(pw, PAN_ITEM_BOX, dir_fd, FALSE, FALSE);
365 PanItem *pi = list->data;
366 *scroll_x = pi->x + pi->width / 2;
367 *scroll_y = pi->y + pi->height / 2;
372 static void pan_folder_tree_path(PanWindow *pw, FileData *dir_fd,
373 gint *x, gint *y, gint *level,
375 gint *width, gint *height)
383 if (!filelist_read(dir_fd, &f, &d)) return;
384 if (!f && !d) return;
386 f = filelist_sort(f, SORT_NAME, TRUE);
387 d = filelist_sort(d, SORT_NAME, TRUE);
389 *x = PAN_BOX_BORDER + ((*level) * MAX(PAN_BOX_BORDER, PAN_THUMB_GAP));
391 pi_box = pan_item_text_new(pw, *x, *y, dir_fd->path, PAN_TEXT_ATTR_NONE,
392 PAN_TEXT_BORDER_SIZE,
393 PAN_TEXT_COLOR, 255);
395 *y += pi_box->height;
397 pi_box = pan_item_box_new(pw, file_data_ref(dir_fd),
399 PAN_BOX_BORDER, PAN_BOX_BORDER,
400 PAN_BOX_OUTLINE_THICKNESS,
401 PAN_BOX_COLOR, PAN_BOX_ALPHA,
402 PAN_BOX_OUTLINE_COLOR, PAN_BOX_OUTLINE_ALPHA);
404 *x += PAN_BOX_BORDER;
405 *y += PAN_BOX_BORDER;
416 if (pw->size > PAN_IMAGE_SIZE_THUMB_LARGE)
418 pi = pan_item_image_new(pw, fd, *x, *y, 10, 10);
419 *x += pi->width + PAN_THUMB_GAP;
420 if (pi->height > y_height) y_height = pi->height;
424 pi = pan_item_thumb_new(pw, fd, *x, *y);
425 *x += PAN_THUMB_SIZE + PAN_THUMB_GAP;
426 y_height = PAN_THUMB_SIZE;
429 pan_item_size_by_item(pi_box, pi, PAN_BOX_BORDER);
432 if (f) *y = pi_box->y + pi_box->height;
444 if (!pan_is_ignored(fd->path, pw->ignore_symlinks))
447 pan_folder_tree_path(pw, fd, x, y, level, pi_box, width, height);
454 pan_item_size_by_item(parent, pi_box, PAN_BOX_BORDER);
456 if (*y < pi_box->y + pi_box->height + PAN_BOX_BORDER)
457 *y = pi_box->y + pi_box->height + PAN_BOX_BORDER;
459 pan_item_size_coordinates(pi_box, PAN_BOX_BORDER, width, height);
462 void pan_folder_tree_compute(PanWindow *pw, FileData *dir_fd, gint *width, gint *height)
471 w = PAN_BOX_BORDER * 2;
472 h = PAN_BOX_BORDER * 2;
474 pan_folder_tree_path(pw, dir_fd, &x, &y, &level, NULL, &w, &h);
476 if (width) *width = w;
477 if (height) *height = h;
479 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */