Update copyright in all files
[geeqie.git] / src / pan-grid.c
1 /*
2  * Copyright (C) 2006 John Ellis
3  * Copyright (C) 2008 - 2016 The Geeqie Team
4  *
5  * Author: John Ellis
6  *
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.
11  *
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.
16  *
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.
20  */
21
22 #include "main.h"
23 #include "pan-types.h"
24
25 #include <math.h>
26
27
28 void pan_grid_compute(PanWindow *pw, FileData *dir_fd, gint *width, gint *height)
29 {
30         GList *list;
31         GList *work;
32         gint x, y;
33         gint grid_size;
34         gint next_y;
35
36         list = pan_list_tree(dir_fd, SORT_NAME, TRUE, pw->ignore_symlinks);
37
38         grid_size = (gint)sqrt((gdouble)g_list_length(list));
39         if (pw->size > PAN_IMAGE_SIZE_THUMB_LARGE)
40                 {
41                 grid_size = grid_size * (512 + PAN_THUMB_GAP) * pw->image_size / 100;
42                 }
43         else
44                 {
45                 grid_size = grid_size * (PAN_THUMB_SIZE + PAN_THUMB_GAP);
46                 }
47
48         next_y = 0;
49
50         *width = PAN_BOX_BORDER * 2;
51         *height = PAN_BOX_BORDER * 2;
52
53         x = PAN_THUMB_GAP;
54         y = PAN_THUMB_GAP;
55         work = list;
56         while (work)
57                 {
58                 FileData *fd;
59                 PanItem *pi;
60
61                 fd = work->data;
62                 work = work->next;
63
64                 if (pw->size > PAN_IMAGE_SIZE_THUMB_LARGE)
65                         {
66                         pi = pan_item_image_new(pw, fd, x, y, 10, 10);
67
68                         x += pi->width + PAN_THUMB_GAP;
69                         if (y + pi->height + PAN_THUMB_GAP > next_y) next_y = y + pi->height + PAN_THUMB_GAP;
70                         if (x > grid_size)
71                                 {
72                                 x = PAN_THUMB_GAP;
73                                 y = next_y;
74                                 }
75                         }
76                 else
77                         {
78                         pi = pan_item_thumb_new(pw, fd, x, y);
79
80                         x += PAN_THUMB_SIZE + PAN_THUMB_GAP;
81                         if (x > grid_size)
82                                 {
83                                 x = PAN_THUMB_GAP;
84                                 y += PAN_THUMB_SIZE + PAN_THUMB_GAP;
85                                 }
86                         }
87                 pan_item_size_coordinates(pi, PAN_THUMB_GAP, width, height);
88                 }
89
90         g_list_free(list);
91 }
92 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */