clang-tidy: readability-isolate-declaration
[geeqie.git] / src / pan-view / pan-grid.cc
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 "pan-grid.h"
23
24 #include <cmath>
25
26 #include "pan-item.h"
27 #include "pan-util.h"
28 #include "pan-view-filter.h"
29
30 void pan_grid_compute(PanWindow *pw, FileData *dir_fd, gint *width, gint *height)
31 {
32         GList *list;
33         GList *work;
34         gint x;
35         gint y;
36         gint grid_size;
37         gint next_y;
38
39         list = pan_list_tree(dir_fd, SORT_NAME, TRUE, TRUE, pw->ignore_symlinks);
40         pan_filter_fd_list(&list, pw->filter_ui->filter_elements, pw->filter_ui->filter_classes);
41
42         grid_size = static_cast<gint>(sqrt(static_cast<gdouble>(g_list_length(list))));
43         if (pw->size > PAN_IMAGE_SIZE_THUMB_LARGE)
44                 {
45                 grid_size = grid_size * (512 + PAN_THUMB_GAP) * pw->image_size / 100;
46                 }
47         else
48                 {
49                 grid_size = grid_size * (PAN_THUMB_SIZE + PAN_THUMB_GAP);
50                 }
51
52         next_y = 0;
53
54         *width = PAN_BOX_BORDER * 2;
55         *height = PAN_BOX_BORDER * 2;
56
57         x = PAN_THUMB_GAP;
58         y = PAN_THUMB_GAP;
59         work = list;
60         while (work)
61                 {
62                 FileData *fd;
63                 PanItem *pi;
64
65                 fd = static_cast<FileData *>(work->data);
66                 work = work->next;
67
68                 if (pw->size > PAN_IMAGE_SIZE_THUMB_LARGE)
69                         {
70                         pi = pan_item_image_new(pw, fd, x, y, 10, 10);
71
72                         x += pi->width + PAN_THUMB_GAP;
73                         if (y + pi->height + PAN_THUMB_GAP > next_y) next_y = y + pi->height + PAN_THUMB_GAP;
74                         if (x > grid_size)
75                                 {
76                                 x = PAN_THUMB_GAP;
77                                 y = next_y;
78                                 }
79                         }
80                 else
81                         {
82                         pi = pan_item_thumb_new(pw, fd, x, y);
83
84                         x += PAN_THUMB_SIZE + PAN_THUMB_GAP;
85                         if (x > grid_size)
86                                 {
87                                 x = PAN_THUMB_GAP;
88                                 y += PAN_THUMB_SIZE + PAN_THUMB_GAP;
89                                 }
90                         }
91                 pan_item_size_coordinates(pi, PAN_THUMB_GAP, width, height);
92                 }
93
94         g_list_free(list);
95 }
96 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */