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