[Bf-blender-cvs] [675807e2b6b] master: UI: Add grid-related theme options

Red Mser noreply at git.blender.org
Wed Sep 16 01:42:55 CEST 2020


Commit: 675807e2b6b29558367d49ab7f9f30e90c975fcb
Author: Red Mser
Date:   Tue Sep 15 18:42:38 2020 -0500
Branches: master
https://developer.blender.org/rB675807e2b6b29558367d49ab7f9f30e90c975fcb

UI: Add grid-related theme options

This commit makes grid theming more consistent and capable by adding
some new theme colors related to grid rendering.
 - Add grid theme color for node editor. `UI_view2d_multi_grid_draw`
   is called with TH_GRID instead of a shaded `TH_BACK`.
   Also color-blend `TH_NODE_GROUP`.
 - Make the movie clip editor's clip preview grid respect grid theme
   color (`ED_region_grid_draw` uses color-blended `TH_GRID`).
 - Add versioning code to allow fixing existing themes (the resulting
   themes should visually look the same as before)

These changes did cause some inconsistencies in the movie clip editor,
even after adjusting the themes accordingly:
1. The alpha slider of the grid color affects the background and not
   the grid lines themselves.
2. The grids used by graph and dopesheet mode could already be themed
   in the past. Now that the clip preview's grid can also be themed,
   two different modes share the same theme color.

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

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

M	release/datafiles/userdef/userdef_default_theme.c
M	release/scripts/presets/interface_theme/blender_light.xml
M	source/blender/blenloader/intern/versioning_userdef.c
M	source/blender/editors/interface/resources.c
M	source/blender/editors/interface/view2d.c
M	source/blender/editors/screen/area.c
M	source/blender/editors/space_image/image_draw.c
M	source/blender/editors/space_node/node_draw.c
M	source/blender/makesrna/intern/rna_userdef.c

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

diff --git a/release/datafiles/userdef/userdef_default_theme.c b/release/datafiles/userdef/userdef_default_theme.c
index 8cbb615491d..d3175a6fa56 100644
--- a/release/datafiles/userdef/userdef_default_theme.c
+++ b/release/datafiles/userdef/userdef_default_theme.c
@@ -812,6 +812,7 @@ const bTheme U_theme_default = {
       .sub_back = RGBA(0x0000003e),
     },
     .shade2 = RGBA(0x7f707064),
+    .grid = RGBA(0x23232300),
     .wire = RGBA(0x808080ff),
     .select = RGBA(0xed5700ff),
     .active = RGBA(0xffffffff),
@@ -924,6 +925,7 @@ const bTheme U_theme_default = {
       .back = RGBA(0x333333b3),
       .sub_back = RGBA(0x0000003e),
     },
+    .grid = RGBA(0x424242ff),
     .strip = RGBA(0x0c0a0a80),
     .strip_select = RGBA(0xff8c00ff),
     .cframe = RGBA(0x5680c2ff),
diff --git a/release/scripts/presets/interface_theme/blender_light.xml b/release/scripts/presets/interface_theme/blender_light.xml
index 53e2571ae8c..299bd3e9bdb 100644
--- a/release/scripts/presets/interface_theme/blender_light.xml
+++ b/release/scripts/presets/interface_theme/blender_light.xml
@@ -713,6 +713,7 @@
     </dopesheet_editor>
     <image_editor>
       <ThemeImageEditor
+        grid="#353535ff"
         vertex="#000000"
         vertex_select="#ff8500"
         vertex_size="3"
@@ -929,6 +930,7 @@
     </text_editor>
     <node_editor>
       <ThemeNodeEditor
+        grid="#353535"
         node_selected="#f15800"
         node_active="#f15800"
         wire="#a7a7a7"
@@ -1164,6 +1166,7 @@
     </console>
     <clip_editor>
       <ThemeClipEditor
+        grid="#393939ff"
         marker_outline="#000000"
         marker="#7f7f00"
         active_marker="#ffffff"
diff --git a/source/blender/blenloader/intern/versioning_userdef.c b/source/blender/blenloader/intern/versioning_userdef.c
index d53959a1949..3cc2372a2b0 100644
--- a/source/blender/blenloader/intern/versioning_userdef.c
+++ b/source/blender/blenloader/intern/versioning_userdef.c
@@ -241,6 +241,13 @@ static void do_versions_theme(const UserDef *userdef, bTheme *btheme)
     }
 
     FROM_DEFAULT_V4_UCHAR(space_properties.match);
+
+    /* New grid theme color defaults are the same as the existing background colors,
+     * so they are copied to limit disruption. */
+    copy_v3_v3_uchar(btheme->space_clip.grid, btheme->space_clip.back);
+    btheme->space_clip.grid[3] = 255.0f;
+
+    copy_v3_v3_uchar(btheme->space_node.grid, btheme->space_node.back);
   }
 
 #undef FROM_DEFAULT_V4_UCHAR
diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c
index 87474369e8d..76ad3981586 100644
--- a/source/blender/editors/interface/resources.c
+++ b/source/blender/editors/interface/resources.c
@@ -1246,9 +1246,9 @@ void UI_GetThemeColorBlendShade3ubv(
   CLAMP(fac, 0.0f, 1.0f);
 
   float blend[3];
-  blend[0] = offset + floorf((1.0f - fac) * cp1[0] + fac * cp2[0]);
-  blend[1] = offset + floorf((1.0f - fac) * cp1[1] + fac * cp2[1]);
-  blend[2] = offset + floorf((1.0f - fac) * cp1[2] + fac * cp2[2]);
+  blend[0] = (offset + floorf((1.0f - fac) * cp1[0] + fac * cp2[0])) / 255.0f;
+  blend[1] = (offset + floorf((1.0f - fac) * cp1[1] + fac * cp2[1])) / 255.0f;
+  blend[2] = (offset + floorf((1.0f - fac) * cp1[2] + fac * cp2[2])) / 255.0f;
 
   unit_float_to_uchar_clamp_v3(col, blend);
 }
diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c
index 7651989c2df..9057ccaa762 100644
--- a/source/blender/editors/interface/view2d.c
+++ b/source/blender/editors/interface/view2d.c
@@ -1341,7 +1341,9 @@ void UI_view2d_multi_grid_draw(
   immBeginAtMost(GPU_PRIM_LINES, vertex_count);
 
   for (int level = 0; level < totlevels; level++) {
-    UI_GetThemeColorShade3ubv(colorid, offset, grid_line_color);
+    /* Blend the background color (colorid) with the grid color, to avoid either too low contrast
+     * or high contrast grid lines. This only has an effect if colorid != TH_GRID. */
+    UI_GetThemeColorBlendShade3ubv(colorid, TH_GRID, 0.25f, offset, grid_line_color);
 
     int i = (int)(v2d->cur.xmin / lstep);
     if (v2d->cur.xmin > 0.0f) {
@@ -1382,7 +1384,8 @@ void UI_view2d_multi_grid_draw(
   }
 
   /* X and Y axis */
-  UI_GetThemeColorShade3ubv(colorid, -18 + ((totlevels - 1) * -6), grid_line_color);
+  UI_GetThemeColorBlendShade3ubv(
+      colorid, TH_GRID, 0.5f, -18 + ((totlevels - 1) * -6), grid_line_color);
 
   immAttrSkip(color);
   immVertex2f(pos, 0.0f, v2d->cur.ymin);
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c
index bfd98741ac8..58251bbb6d9 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -3660,8 +3660,12 @@ void ED_region_grid_draw(ARegion *region, float zoomx, float zoomy, float x0, fl
   GPUVertFormat *format = immVertexFormat();
   uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
 
+  float gridcolor[4];
+  UI_GetThemeColor4fv(TH_GRID, gridcolor);
+
   immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
-  immUniformThemeColorShade(TH_BACK, 20);
+  /* To fake alpha-blending, color shading is reduced when alpha is nearing 0. */
+  immUniformThemeColorBlendShade(TH_BACK, TH_GRID, gridcolor[3], 20 * gridcolor[3]);
   immRectf(pos, x1, y1, x2, y2);
   immUnbindProgram();
 
@@ -3699,7 +3703,7 @@ void ED_region_grid_draw(ARegion *region, float zoomx, float zoomy, float x0, fl
     immBegin(GPU_PRIM_LINES, 4 * count_fine + 4 * count_large);
 
     float theme_color[3];
-    UI_GetThemeColorShade3fv(TH_BACK, (int)(20.0f * (1.0f - blendfac)), theme_color);
+    UI_GetThemeColorShade3fv(TH_GRID, (int)(20.0f * (1.0f - blendfac)), theme_color);
     fac = 0.0f;
 
     /* the fine resolution level */
@@ -3716,7 +3720,7 @@ void ED_region_grid_draw(ARegion *region, float zoomx, float zoomy, float x0, fl
     }
 
     if (count_large > 0) {
-      UI_GetThemeColor3fv(TH_BACK, theme_color);
+      UI_GetThemeColor3fv(TH_GRID, theme_color);
       fac = 0.0f;
 
       /* the large resolution level */
diff --git a/source/blender/editors/space_image/image_draw.c b/source/blender/editors/space_image/image_draw.c
index 60dd134646d..7934d600cf1 100644
--- a/source/blender/editors/space_image/image_draw.c
+++ b/source/blender/editors/space_image/image_draw.c
@@ -826,7 +826,7 @@ static void draw_udim_tile_grids(ARegion *region, SpaceImage *sima, Image *ima)
   immBegin(GPU_PRIM_LINES, 8 * num_tiles);
 
   float theme_color[3], selected_color[3];
-  UI_GetThemeColorShade3fv(TH_BACK, 60.0f, theme_color);
+  UI_GetThemeColorShade3fv(TH_GRID, 60.0f, theme_color);
   UI_GetThemeColor3fv(TH_FACE_SELECT, selected_color);
 
   if (ima != NULL) {
diff --git a/source/blender/editors/space_node/node_draw.c b/source/blender/editors/space_node/node_draw.c
index fc4685929d3..0c5ec1bf80e 100644
--- a/source/blender/editors/space_node/node_draw.c
+++ b/source/blender/editors/space_node/node_draw.c
@@ -1803,7 +1803,7 @@ void drawnodespace(const bContext *C, ARegion *region)
 
       /* grid, uses theme color based on node path depth */
       UI_view2d_multi_grid_draw(v2d,
-                                (depth > 0 ? TH_NODE_GROUP : TH_BACK),
+                                (depth > 0 ? TH_NODE_GROUP : TH_GRID),
                                 ED_node_grid_size(),
                                 NODE_GRID_STEPS,
                                 grid_levels);
@@ -1847,7 +1847,7 @@ void drawnodespace(const bContext *C, ARegion *region)
   }
   else {
     /* default grid */
-    UI_view2d_multi_grid_draw(v2d, TH_BACK, ED_node_grid_size(), NODE_GRID_STEPS, grid_levels);
+    UI_view2d_multi_grid_draw(v2d, TH_GRID, ED_node_grid_size(), NODE_GRID_STEPS, grid_levels);
 
     /* backdrop */
     draw_nodespace_back_pix(C, region, snode, NODE_INSTANCE_KEY_NONE);
diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c
index 118a512caf9..7986e129067 100644
--- a/source/blender/makesrna/intern/rna_userdef.c
+++ b/source/blender/makesrna/intern/rna_userdef.c
@@ -2795,6 +2795,11 @@ static void rna_def_userdef_theme_space_node(BlenderRNA *brna)
   rna_def_userdef_theme_spaces_main(srna);
   rna_def_userdef_theme_spaces_list_main(srna);
 
+  prop = RNA_def_property(srna, "grid", PROP_FLOAT, PROP_COLOR_GAMMA);
+  RNA_def_property_array(prop, 3);
+  RNA_def_property_ui_text(prop, "Grid", "");
+  RNA_def_property_update(prop, 0, "rna_userdef_theme_update");
+
   prop = RNA_def_property(srna, "node_selected", PROP_FLOAT, PROP_COLOR_GAMMA);
   RNA_def_property_float_sdna(prop, NULL, "select");
   RNA_def_property_array(prop, 3);
@@ -2982,6 +2987,12 @@ static void rna_def_userdef_theme_space_image(BlenderRNA *brna)
   RNA_def_struct_ui_text(srna, "Theme Image Editor", "Theme settings for the Image Editor");
 
   rna_def_userdef_theme_spaces_main(srna);
+
+  prop = RNA_def_property(srna, "grid", PROP_FLOAT, PROP_COLOR_GAMMA);
+  RNA_def_property_array(prop, 4);
+  RNA_def_property_ui_text(prop, "Grid", "");
+  RNA_def_property_update(prop, 0, "rna_userdef_theme_update");
+
   rna_def_userdef_theme_spaces_vertex(srna);
   rna_def_userdef_theme_spaces_face(srna);
 
@@ -3066,11 +3077,6 @@ static void rna_def_userdef_theme_space_image(BlenderRNA *brna)
   RNA_def_property_ui_text(prop, "Metadata Text", "");
   RNA_def_property_update(prop, 0, "rna_userdef_theme_update");
 
-  prop = RNA_def_property(srna, "grid", PROP_FLOAT, PROP_COLOR_GAMMA);
-  RNA_def_property_array(prop, 4);
-  RNA_def_property_ui_text(prop, "Grid", "");
-  RNA_def_property_update(prop, 0, "rna_userdef_theme_update");
-
   rna_def_userdef_theme_spaces_curves(srna, false, false, false, true);
 
   rna_def_userdef_theme_spaces_paint_curves(srna);
@@ -3656,7 +3662,7 @@ static void rna_def_userdef_theme_space_clip(BlenderRNA *brna)
   rna_def_userdef_theme_spaces_list_main(srna);
 
   prop = RNA_def_property(srna, "grid", PROP_FLOAT, PROP_COLOR_GAMMA);
-  RNA_def_property_array(prop, 3);
+  RNA_def_property_array(prop, 4);
   RNA_def_property_ui_text(prop, "Grid", "");
   RNA_def_property_update(prop, 0, "rna_userdef_theme_update");



More information about the Bf-blender-cvs mailing list