diff options
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenlib/BLI_math_base.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_base_inline.c | 8 | ||||
-rw-r--r-- | source/blender/editors/space_file/filesel.c | 9 |
3 files changed, 14 insertions, 4 deletions
diff --git a/source/blender/blenlib/BLI_math_base.h b/source/blender/blenlib/BLI_math_base.h index ae9617d2f16..e76c41970c6 100644 --- a/source/blender/blenlib/BLI_math_base.h +++ b/source/blender/blenlib/BLI_math_base.h @@ -33,6 +33,7 @@ #include "BLI_assert.h" #include "BLI_math_inline.h" +#include "BLI_sys_types.h" #include <math.h> #ifndef M_PI diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c index e0cac508d28..6db3ea819a4 100644 --- a/source/blender/blenlib/intern/math_base_inline.c +++ b/source/blender/blenlib/intern/math_base_inline.c @@ -356,6 +356,14 @@ MINLINE int divide_floor_i(int a, int b) } /** + * Integer division that ceils the result, instead of flooring like normal C division. + */ +MINLINE uint divide_ceil_u(uint a, uint b) +{ + return (a + b - 1) / b; +} + +/** * modulo that handles negative numbers, works the same as Python's. */ MINLINE int mod_i(int i, int n) diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c index 6b594c02c15..3b62941af83 100644 --- a/source/blender/editors/space_file/filesel.c +++ b/source/blender/editors/space_file/filesel.c @@ -47,6 +47,7 @@ #include "BLI_blenlib.h" #include "BLI_fnmatch.h" +#include "BLI_math_base.h" #include "BLI_utildefines.h" #include "BLO_readfile.h" @@ -758,11 +759,11 @@ void ED_fileselect_init_layout(struct SpaceFile *sfile, ARegion *region) layout->attribute_column_header_h = 0; layout->offset_top = 0; if (layout->flow_columns > 0) { - layout->rows = numfiles / layout->flow_columns + 1; // XXX dirty, modulo is zero + layout->rows = divide_ceil_u(numfiles, layout->flow_columns); } else { layout->flow_columns = 1; - layout->rows = numfiles + 1; // XXX dirty, modulo is zero + layout->rows = numfiles; } layout->height = sfile->layout->rows * (layout->tile_h + 2 * layout->tile_border_y) + layout->tile_border_y * 2 - layout->offset_top; @@ -807,11 +808,11 @@ void ED_fileselect_init_layout(struct SpaceFile *sfile, ARegion *region) file_attribute_columns_init(params, layout); if (layout->rows > 0) { - layout->flow_columns = numfiles / layout->rows + 1; // XXX dirty, modulo is zero + layout->flow_columns = divide_ceil_u(numfiles, layout->rows); } else { layout->rows = 1; - layout->flow_columns = numfiles + 1; // XXX dirty, modulo is zero + layout->flow_columns = numfiles; } layout->width = sfile->layout->flow_columns * (layout->tile_w + 2 * layout->tile_border_x) + layout->tile_border_x * 2; |