4 * Copyright (C) 2008 - 2012 The Geeqie Team
8 * This software is released under the GNU General Public License (GNU GPL).
9 * Please read the included file COPYING for more information.
10 * This software comes with no warranty of any kind, use at your own risk!
15 #include "pan-types.h"
20 static void pan_flower_size(PanWindow *pw, gint *width, gint *height)
38 if (x1 > pi->x) x1 = pi->x;
39 if (y1 > pi->y) y1 = pi->y;
40 if (x2 < pi->x + pi->width) x2 = pi->x + pi->width;
41 if (y2 < pi->y + pi->height) y2 = pi->y + pi->height;
60 if (pi->type == PAN_ITEM_TRIANGLE && pi->data)
74 if (width) *width = x2 - x1;
75 if (height) *height = y2 - y1;
78 typedef struct _FlowerGroup FlowerGroup;
92 static void pan_flower_move(FlowerGroup *group, gint x, gint y)
112 #define PI 3.14159265
114 static void pan_flower_position(FlowerGroup *group, FlowerGroup *parent,
115 gint *result_x, gint *result_y)
121 radius = parent->circumference / (2*PI);
122 radius = MAX(radius, parent->diameter / 2 + group->diameter / 2);
124 a = 2*PI * group->diameter / parent->circumference;
126 x = (gint)((gdouble)radius * cos(parent->angle + a / 2));
127 y = (gint)((gdouble)radius * sin(parent->angle + a / 2));
134 x += parent->width / 2;
135 y += parent->height / 2;
137 x -= group->width / 2;
138 y -= group->height / 2;
144 static void pan_flower_build(PanWindow *pw, FlowerGroup *group, FlowerGroup *parent)
151 if (parent && parent->children)
153 pan_flower_position(group, parent, &x, &y);
161 pan_flower_move(group, x, y);
169 px = parent->x + parent->width / 2;
170 py = parent->y + parent->height / 2;
172 gx = group->x + group->width / 2;
173 gy = group->y + group->height / 2;
178 x2 = MAX(px, gx + 5);
179 y2 = MAX(py, gy + 5);
181 pi = pan_item_tri_new(pw, NULL, x1, y1, x2 - x1, y2 - y1,
182 px, py, gx, gy, gx + 5, gy + 5,
184 pan_item_tri_border(pi, PAN_BORDER_1 | PAN_BORDER_3,
188 pw->list = g_list_concat(group->items, pw->list);
191 group->circumference = 0;
192 work = group->children;
200 group->circumference += child->diameter;
203 work = g_list_last(group->children);
211 pan_flower_build(pw, child, group);
214 g_list_free(group->children);
218 static FlowerGroup *pan_flower_group(PanWindow *pw, FileData *dir_fd, gint x, gint y)
230 if (!filelist_read(dir_fd, &f, &d)) return NULL;
231 if (!f && !d) return NULL;
233 f = filelist_sort(f, SORT_NAME, TRUE);
234 d = filelist_sort(d, SORT_NAME, TRUE);
236 pi_box = pan_item_text_new(pw, x, y, dir_fd->path, PAN_TEXT_ATTR_NONE,
237 PAN_TEXT_BORDER_SIZE,
238 PAN_TEXT_COLOR, 255);
242 pi_box = pan_item_box_new(pw, file_data_ref(dir_fd),
244 PAN_BOX_BORDER * 2, PAN_BOX_BORDER * 2,
245 PAN_BOX_OUTLINE_THICKNESS,
246 PAN_BOX_COLOR, PAN_BOX_ALPHA,
247 PAN_BOX_OUTLINE_COLOR, PAN_BOX_OUTLINE_ALPHA);
252 grid_size = (gint)(sqrt(g_list_length(f)) + 0.9);
266 if (pw->size > PAN_IMAGE_SIZE_THUMB_LARGE)
268 pi = pan_item_image_new(pw, fd, x, y, 10, 10);
269 x += pi->width + PAN_THUMB_GAP;
270 if (pi->height > y_height) y_height = pi->height;
274 pi = pan_item_thumb_new(pw, fd, x, y);
275 x += PAN_THUMB_SIZE + PAN_THUMB_GAP;
276 y_height = PAN_THUMB_SIZE;
280 if (grid_count >= grid_size)
284 y += y_height + PAN_THUMB_GAP;
288 pan_item_size_by_item(pi_box, pi, PAN_BOX_BORDER);
291 group = g_new0(FlowerGroup, 1);
292 group->items = pw->list;
295 group->width = pi_box->width;
296 group->height = pi_box->y + pi_box->height;
297 group->diameter = (gint)sqrt(group->width * group->width + group->height * group->height);
299 group->children = NULL;
310 if (!pan_is_ignored(fd->path, pw->ignore_symlinks))
312 child = pan_flower_group(pw, fd, 0, 0);
313 if (child) group->children = g_list_prepend(group->children, child);
317 if (!f && !group->children)
330 g_list_free(group->items);
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, NULL);
351 pan_flower_size(pw, width, height);
353 list = pan_item_find_by_fd(pw, PAN_ITEM_BOX, dir_fd, FALSE, FALSE);
356 PanItem *pi = 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);
378 d = filelist_sort(d, SORT_NAME, TRUE);
380 *x = PAN_BOX_BORDER + ((*level) * MAX(PAN_BOX_BORDER, PAN_THUMB_GAP));
382 pi_box = pan_item_text_new(pw, *x, *y, dir_fd->path, PAN_TEXT_ATTR_NONE,
383 PAN_TEXT_BORDER_SIZE,
384 PAN_TEXT_COLOR, 255);
386 *y += pi_box->height;
388 pi_box = pan_item_box_new(pw, file_data_ref(dir_fd),
390 PAN_BOX_BORDER, PAN_BOX_BORDER,
391 PAN_BOX_OUTLINE_THICKNESS,
392 PAN_BOX_COLOR, PAN_BOX_ALPHA,
393 PAN_BOX_OUTLINE_COLOR, PAN_BOX_OUTLINE_ALPHA);
395 *x += PAN_BOX_BORDER;
396 *y += PAN_BOX_BORDER;
407 if (pw->size > PAN_IMAGE_SIZE_THUMB_LARGE)
409 pi = pan_item_image_new(pw, fd, *x, *y, 10, 10);
410 *x += pi->width + PAN_THUMB_GAP;
411 if (pi->height > y_height) y_height = pi->height;
415 pi = pan_item_thumb_new(pw, fd, *x, *y);
416 *x += PAN_THUMB_SIZE + PAN_THUMB_GAP;
417 y_height = PAN_THUMB_SIZE;
420 pan_item_size_by_item(pi_box, pi, PAN_BOX_BORDER);
423 if (f) *y = pi_box->y + pi_box->height;
435 if (!pan_is_ignored(fd->path, pw->ignore_symlinks))
438 pan_folder_tree_path(pw, fd, x, y, level, pi_box, width, height);
445 pan_item_size_by_item(parent, pi_box, PAN_BOX_BORDER);
447 if (*y < pi_box->y + pi_box->height + PAN_BOX_BORDER)
448 *y = pi_box->y + pi_box->height + PAN_BOX_BORDER;
450 pan_item_size_coordinates(pi_box, PAN_BOX_BORDER, width, height);
453 void pan_folder_tree_compute(PanWindow *pw, FileData *dir_fd, gint *width, gint *height)
462 w = PAN_BOX_BORDER * 2;
463 h = PAN_BOX_BORDER * 2;
465 pan_folder_tree_path(pw, dir_fd, &x, &y, &level, NULL, &w, &h);
467 if (width) *width = w;
468 if (height) *height = h;
470 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */