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.
23 #include "pan-types.h"
28 static void pan_flower_size(PanWindow *pw, gint *width, gint *height)
46 if (x1 > pi->x) x1 = pi->x;
47 if (y1 > pi->y) y1 = pi->y;
48 if (x2 < pi->x + pi->width) x2 = pi->x + pi->width;
49 if (y2 < pi->y + pi->height) y2 = pi->y + pi->height;
68 if (pi->type == PAN_ITEM_TRIANGLE && pi->data)
82 if (width) *width = x2 - x1;
83 if (height) *height = y2 - y1;
86 typedef struct _FlowerGroup FlowerGroup;
100 static void pan_flower_move(FlowerGroup *group, gint x, gint y)
120 #define PI 3.14159265
122 static void pan_flower_position(FlowerGroup *group, FlowerGroup *parent,
123 gint *result_x, gint *result_y)
129 radius = parent->circumference / (2*PI);
130 radius = MAX(radius, parent->diameter / 2 + group->diameter / 2);
132 a = 2*PI * group->diameter / parent->circumference;
134 x = (gint)((gdouble)radius * cos(parent->angle + a / 2));
135 y = (gint)((gdouble)radius * sin(parent->angle + a / 2));
142 x += parent->width / 2;
143 y += parent->height / 2;
145 x -= group->width / 2;
146 y -= group->height / 2;
152 static void pan_flower_build(PanWindow *pw, FlowerGroup *group, FlowerGroup *parent)
159 if (parent && parent->children)
161 pan_flower_position(group, parent, &x, &y);
169 pan_flower_move(group, x, y);
177 px = parent->x + parent->width / 2;
178 py = parent->y + parent->height / 2;
180 gx = group->x + group->width / 2;
181 gy = group->y + group->height / 2;
186 x2 = MAX(px, gx + 5);
187 y2 = MAX(py, gy + 5);
189 pi = pan_item_tri_new(pw, NULL, x1, y1, x2 - x1, y2 - y1,
190 px, py, gx, gy, gx + 5, gy + 5,
192 pan_item_tri_border(pi, PAN_BORDER_1 | PAN_BORDER_3,
196 pw->list = g_list_concat(group->items, pw->list);
199 group->circumference = 0;
200 work = group->children;
208 group->circumference += child->diameter;
211 work = g_list_last(group->children);
219 pan_flower_build(pw, child, group);
222 g_list_free(group->children);
226 static FlowerGroup *pan_flower_group(PanWindow *pw, FileData *dir_fd, gint x, gint y)
238 if (!filelist_read(dir_fd, &f, &d)) return NULL;
239 if (!f && !d) return NULL;
241 f = filelist_sort(f, SORT_NAME, TRUE);
242 d = filelist_sort(d, SORT_NAME, TRUE);
244 pi_box = pan_item_text_new(pw, x, y, dir_fd->path, PAN_TEXT_ATTR_NONE,
245 PAN_TEXT_BORDER_SIZE,
246 PAN_TEXT_COLOR, 255);
250 pi_box = pan_item_box_new(pw, file_data_ref(dir_fd),
252 PAN_BOX_BORDER * 2, PAN_BOX_BORDER * 2,
253 PAN_BOX_OUTLINE_THICKNESS,
254 PAN_BOX_COLOR, PAN_BOX_ALPHA,
255 PAN_BOX_OUTLINE_COLOR, PAN_BOX_OUTLINE_ALPHA);
260 grid_size = (gint)(sqrt(g_list_length(f)) + 0.9);
274 if (pw->size > PAN_IMAGE_SIZE_THUMB_LARGE)
276 pi = pan_item_image_new(pw, fd, x, y, 10, 10);
277 x += pi->width + PAN_THUMB_GAP;
278 if (pi->height > y_height) y_height = pi->height;
282 pi = pan_item_thumb_new(pw, fd, x, y);
283 x += PAN_THUMB_SIZE + PAN_THUMB_GAP;
284 y_height = PAN_THUMB_SIZE;
288 if (grid_count >= grid_size)
292 y += y_height + PAN_THUMB_GAP;
296 pan_item_size_by_item(pi_box, pi, PAN_BOX_BORDER);
299 group = g_new0(FlowerGroup, 1);
300 group->items = pw->list;
303 group->width = pi_box->width;
304 group->height = pi_box->y + pi_box->height;
305 group->diameter = (gint)sqrt(group->width * group->width + group->height * group->height);
307 group->children = NULL;
318 if (!pan_is_ignored(fd->path, pw->ignore_symlinks))
320 child = pan_flower_group(pw, fd, 0, 0);
321 if (child) group->children = g_list_prepend(group->children, child);
325 if (!f && !group->children)
338 g_list_free(group->items);
349 void pan_flower_compute(PanWindow *pw, FileData *dir_fd,
350 gint *width, gint *height,
351 gint *scroll_x, gint *scroll_y)
356 group = pan_flower_group(pw, dir_fd, 0, 0);
357 pan_flower_build(pw, group, NULL);
359 pan_flower_size(pw, width, height);
361 list = pan_item_find_by_fd(pw, PAN_ITEM_BOX, dir_fd, FALSE, FALSE);
364 PanItem *pi = list->data;
365 *scroll_x = pi->x + pi->width / 2;
366 *scroll_y = pi->y + pi->height / 2;
371 static void pan_folder_tree_path(PanWindow *pw, FileData *dir_fd,
372 gint *x, gint *y, gint *level,
374 gint *width, gint *height)
382 if (!filelist_read(dir_fd, &f, &d)) return;
383 if (!f && !d) return;
385 f = filelist_sort(f, SORT_NAME, TRUE);
386 d = filelist_sort(d, SORT_NAME, TRUE);
388 *x = PAN_BOX_BORDER + ((*level) * MAX(PAN_BOX_BORDER, PAN_THUMB_GAP));
390 pi_box = pan_item_text_new(pw, *x, *y, dir_fd->path, PAN_TEXT_ATTR_NONE,
391 PAN_TEXT_BORDER_SIZE,
392 PAN_TEXT_COLOR, 255);
394 *y += pi_box->height;
396 pi_box = pan_item_box_new(pw, file_data_ref(dir_fd),
398 PAN_BOX_BORDER, PAN_BOX_BORDER,
399 PAN_BOX_OUTLINE_THICKNESS,
400 PAN_BOX_COLOR, PAN_BOX_ALPHA,
401 PAN_BOX_OUTLINE_COLOR, PAN_BOX_OUTLINE_ALPHA);
403 *x += PAN_BOX_BORDER;
404 *y += PAN_BOX_BORDER;
415 if (pw->size > PAN_IMAGE_SIZE_THUMB_LARGE)
417 pi = pan_item_image_new(pw, fd, *x, *y, 10, 10);
418 *x += pi->width + PAN_THUMB_GAP;
419 if (pi->height > y_height) y_height = pi->height;
423 pi = pan_item_thumb_new(pw, fd, *x, *y);
424 *x += PAN_THUMB_SIZE + PAN_THUMB_GAP;
425 y_height = PAN_THUMB_SIZE;
428 pan_item_size_by_item(pi_box, pi, PAN_BOX_BORDER);
431 if (f) *y = pi_box->y + pi_box->height;
443 if (!pan_is_ignored(fd->path, pw->ignore_symlinks))
446 pan_folder_tree_path(pw, fd, x, y, level, pi_box, width, height);
453 pan_item_size_by_item(parent, pi_box, PAN_BOX_BORDER);
455 if (*y < pi_box->y + pi_box->height + PAN_BOX_BORDER)
456 *y = pi_box->y + pi_box->height + PAN_BOX_BORDER;
458 pan_item_size_coordinates(pi_box, PAN_BOX_BORDER, width, height);
461 void pan_folder_tree_compute(PanWindow *pw, FileData *dir_fd, gint *width, gint *height)
470 w = PAN_BOX_BORDER * 2;
471 h = PAN_BOX_BORDER * 2;
473 pan_folder_tree_path(pw, dir_fd, &x, &y, &level, NULL, &w, &h);
475 if (width) *width = w;
476 if (height) *height = h;
478 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */