[Bf-blender-cvs] [5caeb054ee] uiTable: Support drawing some background color alternating per row

Julian Eisel noreply at git.blender.org
Thu Feb 9 03:03:29 CET 2017


Commit: 5caeb054eef4ff1fd5453f372ee7613536099188
Author: Julian Eisel
Date:   Thu Feb 9 02:56:27 2017 +0100
Branches: uiTable
https://developer.blender.org/rB5caeb054eef4ff1fd5453f372ee7613536099188

Support drawing some background color alternating per row

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

M	source/blender/editors/include/UI_table.h
M	source/blender/editors/interface/table.c

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

diff --git a/source/blender/editors/include/UI_table.h b/source/blender/editors/include/UI_table.h
index 9524616aa3..992cb388d3 100644
--- a/source/blender/editors/include/UI_table.h
+++ b/source/blender/editors/include/UI_table.h
@@ -53,6 +53,7 @@ void UI_table_free(uiTable *table) ATTR_NONNULL();
 
 void UI_table_max_width_set(uiTable *table, const unsigned int max_width) ATTR_NONNULL();
 void UI_table_horizontal_flow_max_height_set(uiTable *table, const unsigned int max_height) ATTR_NONNULL();
+void UI_table_background_colors_set(uiTable *table, const unsigned char rgb1[3], const unsigned char rgb2[3]);
 void UI_table_draw(uiTable *table) ATTR_NONNULL();
 
 /* *** Columns *** */
diff --git a/source/blender/editors/interface/table.c b/source/blender/editors/interface/table.c
index 241013c813..cb66f6d593 100644
--- a/source/blender/editors/interface/table.c
+++ b/source/blender/editors/interface/table.c
@@ -33,6 +33,8 @@
 
 #include "DNA_userdef_types.h"
 
+#include "GPU_immediate.h"
+
 #include "MEM_guardedalloc.h"
 
 #include "UI_interface.h"
@@ -50,6 +52,8 @@ typedef struct uiTable {
 	} flow_direction;
 	unsigned int max_width;
 
+	unsigned char rgb1[3];
+	unsigned char rgb2[3];
 	char flag;
 } uiTable;
 
@@ -57,6 +61,7 @@ enum eTableFlags {
 	/* All rows have the same height. In this case we can avoid iterating
 	 * over rows for calculations like intersection checks. */
 	TABLE_ROWS_CONSTANT_HEIGHT = (1 << 0),
+	TABLE_DRAW_BACKGROUND      = (1 << 1),
 };
 
 typedef struct TableHorizontalFlow {
@@ -247,6 +252,21 @@ static void table_row_calc_y_coords(uiTable *table, uiTableRow *row,
 	*r_ymin = *r_ymax - height;
 }
 
+static void table_row_draw_background(const uiTable *table, const int column_index, const unsigned int height,
+                                      const unsigned int ofs_x, const unsigned int ofs_y)
+{
+	if (table->flag & TABLE_DRAW_BACKGROUND) {
+		unsigned int pos = add_attrib(immVertexFormat(), "pos", GL_INT, 2, CONVERT_INT_TO_FLOAT);
+
+		immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+		immUniformColor3ubv((column_index % 2) ? table->rgb1 : table->rgb2);
+		immRecti(pos, ofs_x, ofs_x + table->max_width, ofs_y, ofs_y + height);
+
+		immUnbindProgram();
+	}
+}
+
 
 /* -------------------------------------------------------------------- */
 /** \name UI Table API
@@ -304,6 +324,13 @@ void UI_table_horizontal_flow_max_height_set(uiTable *table, const unsigned int
 	horizontal_table->max_height = max_height;
 }
 
+void UI_table_background_colors_set(uiTable *table, const unsigned char rgb1[3], const unsigned char rgb2[3])
+{
+	copy_v3_v3_uchar(table->rgb1, rgb1);
+	copy_v3_v3_uchar(table->rgb2, rgb2);
+	table->flag |= TABLE_DRAW_BACKGROUND;
+}
+
 /**
  * Insert a new column into \a table with default parameters (100% available width, 0px min width, aligned to left).
  *
@@ -405,7 +432,7 @@ void UI_table_draw(uiTable *table)
 
 	BLI_mempool_iternew(table->row_pool, &iter);
 	for (uiTableRow *row = BLI_mempool_iterstep(&iter); row; row = BLI_mempool_iterstep(&iter)) {
-		rcti drawrect = {};
+		rcti drawrect;
 		unsigned int draw_height;
 		int column_index = 0;
 
@@ -417,6 +444,8 @@ void UI_table_draw(uiTable *table)
 			consistent_row_height = false;
 		}
 
+		table_row_draw_background(table, column_index, draw_height, xofs, yofs);
+
 		TABLE_COLUMNS_ITER_BEGIN(table, column)
 		{
 			if (is_first_row) {




More information about the Bf-blender-cvs mailing list