Blender  V2.93
file_utils.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include "BLI_fileops.h"
22 #include "BLI_path_util.h"
23 #include "BLI_rect.h"
24 #include "BLI_string.h"
25 
26 #include "BKE_context.h"
27 #include "BLO_readfile.h"
28 
29 #include "ED_fileselect.h"
30 #include "ED_screen.h"
31 
32 #include "WM_types.h"
33 
34 #include "file_intern.h"
35 
36 void file_tile_boundbox(const ARegion *region, FileLayout *layout, const int file, rcti *r_bounds)
37 {
38  int xmin, ymax;
39 
40  ED_fileselect_layout_tilepos(layout, file, &xmin, &ymax);
41  ymax = (int)region->v2d.tot.ymax - ymax; /* real, view space ymax */
42  BLI_rcti_init(r_bounds,
43  xmin,
44  xmin + layout->tile_w + layout->tile_border_x,
45  ymax - layout->tile_h - layout->tile_border_y,
46  ymax);
47 }
48 
52 void file_path_to_ui_path(const char *path, char *r_path, int max_size)
53 {
54  char tmp_path[PATH_MAX];
55  BLI_strncpy(tmp_path, path, sizeof(tmp_path));
56  BLI_path_slash_rstrip(tmp_path);
57  BLI_strncpy(r_path, BLO_has_bfile_extension(tmp_path) ? tmp_path : path, max_size);
58 }
File and directory operations.
#define PATH_MAX
Definition: BLI_fileops.h:44
void BLI_path_slash_rstrip(char *string) ATTR_NONNULL()
Definition: path_util.c:1995
void BLI_rcti_init(struct rcti *rect, int xmin, int xmax, int ymin, int ymax)
Definition: rct.c:446
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) ATTR_NONNULL()
Definition: string.c:108
external readfile function prototypes.
bool BLO_has_bfile_extension(const char *str)
Definition: readfile.c:1684
void ED_fileselect_layout_tilepos(FileLayout *layout, int tile, int *x, int *y)
Definition: filesel.c:772
FILE * file
void file_tile_boundbox(const ARegion *region, FileLayout *layout, const int file, rcti *r_bounds)
Definition: file_utils.c:36
void file_path_to_ui_path(const char *path, char *r_path, int max_size)
Definition: file_utils.c:52
int tile_border_y
Definition: ED_fileselect.h:78
int tile_border_x
Definition: ED_fileselect.h:77
float ymax
Definition: DNA_vec_types.h:86