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
This commit is contained in:
Red Mser 2020-09-15 18:42:38 -05:00 committed by Hans Goudey
parent 1858535a10
commit 675807e2b6
9 changed files with 42 additions and 17 deletions

View File

@ -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),

View File

@ -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"

View File

@ -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

View File

@ -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);
}

View File

@ -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);

View File

@ -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 */

View File

@ -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) {

View File

@ -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);

View File

@ -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");