[Bf-blender-cvs] [2afb5975726] blender-v2.83-release: Fix T76665: Wrong files selected when using box select

Jacques Lucke noreply at git.blender.org
Wed May 13 12:50:50 CEST 2020


Commit: 2afb59757268cc71e7780f683610b2724853cac0
Author: Jacques Lucke
Date:   Wed May 13 12:50:14 2020 +0200
Branches: blender-v2.83-release
https://developer.blender.org/rB2afb59757268cc71e7780f683610b2724853cac0

Fix T76665: Wrong files selected when using box select

Reviewers: Severin

Differential Revision: https://developer.blender.org/D7705

===================================================================

M	source/blender/blenlib/BLI_math_base.h
M	source/blender/blenlib/intern/math_base_inline.c
M	source/blender/editors/space_file/filesel.c

===================================================================

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
@@ -355,6 +355,14 @@ MINLINE int divide_floor_i(int a, int b)
   return r ? d - ((a < 0) ^ (b < 0)) : d;
 }
 
+/**
+ * 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.
  */
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;



More information about the Bf-blender-cvs mailing list