[Bf-blender-cvs] [c080702e73f] blender2.8: fix drawing file column dividers (T51189)

Mike Erwin noreply at git.blender.org
Wed Apr 12 20:22:15 CEST 2017


Commit: c080702e73f1729897033343d44198488b6fed9f
Author: Mike Erwin
Date:   Wed Apr 12 14:16:43 2017 -0400
Branches: blender2.8
https://developer.blender.org/rBc080702e73f1729897033343d44198488b6fed9f

fix drawing file column dividers (T51189)

Problem was an edge case where vertex_ct logic and draw logic disagreed on how many dividers to draw.

Fix: copy draw logic to earlier vertex_ct

I also skip any drawing or setup if vertex_ct = 0, and set color attribute only for each line's provoking vertex. Small optimizations but these things add up.

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

M	source/blender/editors/space_file/file_draw.c

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

diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c
index 329b3f7f525..61f33d72b71 100644
--- a/source/blender/editors/space_file/file_draw.c
+++ b/source/blender/editors/space_file/file_draw.c
@@ -477,46 +477,54 @@ static void draw_background(FileLayout *layout, View2D *v2d)
 
 static void draw_dividers(FileLayout *layout, View2D *v2d)
 {
-	const int step = (layout->tile_w + 2 * layout->tile_border_x);
-	int v1[2], v2[2];
-	int sx;
-	unsigned int vertex_ct = 0;
-	unsigned char col_hi[3], col_lo[3];
+	/* vertical column dividers */
 
-	VertexFormat *format = immVertexFormat();
-	unsigned int pos = VertexFormat_add_attrib(format, "pos", COMP_I32, 2, CONVERT_INT_TO_FLOAT);
-	unsigned int color = VertexFormat_add_attrib(format, "color", COMP_U8, 3, NORMALIZE_INT_TO_FLOAT);
+	const int step = (layout->tile_w + 2 * layout->tile_border_x);
 
-	vertex_ct = (v2d->cur.xmax - v2d->tot.xmin) / step + 1; /* paint at least 1 divider */
-	vertex_ct *= 4; /* vertex_count = 2 points per divider * 2 lines per divider */
+	unsigned int vertex_ct = 0;
+	int sx = (int)v2d->tot.xmin;
+	while (sx < v2d->cur.xmax) {
+		sx += step;
+		vertex_ct += 4; /* vertex_count = 2 points per line * 2 lines per divider */
+	}
 
-	UI_GetThemeColorShade3ubv(TH_BACK,  30, col_hi);
-	UI_GetThemeColorShade3ubv(TH_BACK, -30, col_lo);
+	if (vertex_ct > 0) {
+		int v1[2], v2[2];
+		unsigned char col_hi[3], col_lo[3];
 
-	v1[1] = v2d->cur.ymax - layout->tile_border_y;
-	v2[1] = v2d->cur.ymin;
+		UI_GetThemeColorShade3ubv(TH_BACK,  30, col_hi);
+		UI_GetThemeColorShade3ubv(TH_BACK, -30, col_lo);
 
-	immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
-	immBegin(PRIM_LINES, vertex_ct);
+		v1[1] = v2d->cur.ymax - layout->tile_border_y;
+		v2[1] = v2d->cur.ymin;
 
-	/* vertical column dividers */
-	sx = (int)v2d->tot.xmin;
-	while (sx < v2d->cur.xmax) {
-		sx += step;
-
-		v1[0] = v2[0] = sx;
-		immAttrib3ubv(color, col_lo);
-		immVertex2iv(pos, v1);
-		immVertex2iv(pos, v2);
+		VertexFormat *format = immVertexFormat();
+		unsigned int pos = VertexFormat_add_attrib(format, "pos", COMP_I32, 2, CONVERT_INT_TO_FLOAT);
+		unsigned int color = VertexFormat_add_attrib(format, "color", COMP_U8, 3, NORMALIZE_INT_TO_FLOAT);
+
+		immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
+		immBegin(PRIM_LINES, vertex_ct);
+
+		sx = (int)v2d->tot.xmin;
+		while (sx < v2d->cur.xmax) {
+			sx += step;
+
+			v1[0] = v2[0] = sx;
+			immSkipAttrib(color);
+			immVertex2iv(pos, v1);
+			immAttrib3ubv(color, col_lo);
+			immVertex2iv(pos, v2);
+
+			v1[0] = v2[0] = sx + 1;
+			immSkipAttrib(color);
+			immVertex2iv(pos, v1);
+			immAttrib3ubv(color, col_hi);
+			immVertex2iv(pos, v2);
+		}
 
-		v1[0] = v2[0] = sx + 1;
-		immAttrib3ubv(color, col_hi);
-		immVertex2iv(pos, v1);
-		immVertex2iv(pos, v2);
+		immEnd();
+		immUnbindProgram();
 	}
-
-	immEnd();
-	immUnbindProgram();
 }
 
 void file_draw_list(const bContext *C, ARegion *ar)




More information about the Bf-blender-cvs mailing list