From 0a25f5d0560c54c8973d6a62561813de23177410 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Fri, 19 Jan 2024 15:25:44 -0800 Subject: [PATCH 1/3] UI: Increased Overlay Text Contrast Increased contrast of light text on any background by increasing the effectiveness of the dark shadow. --- source/blender/blenfont/BLF_api.h | 4 ++ source/blender/blenfont/intern/blf_default.cc | 18 +++++++++ source/blender/draw/intern/draw_manager_c.cc | 9 +---- .../draw/intern/draw_manager_profiling.cc | 18 +++------ .../blender/editors/space_info/info_stats.cc | 10 +---- .../editors/space_view3d/view3d_draw.cc | 40 +++++-------------- source/blender/editors/transform/transform.cc | 2 +- 7 files changed, 41 insertions(+), 60 deletions(-) diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h index 6824e63fc00..fa02a25b7ff 100644 --- a/source/blender/blenfont/BLF_api.h +++ b/source/blender/blenfont/BLF_api.h @@ -334,6 +334,10 @@ int BLF_default(void); * Draw the string using the default font, size and DPI. */ void BLF_draw_default(float x, float y, float z, const char *str, size_t str_len) ATTR_NONNULL(); +/** + * As above but with a very contrasting dark shadow. + */ +void BLF_draw_default_shadow(float x, float y, float z, const char *str, size_t str_len) ATTR_NONNULL(); /** * Set size and DPI, and return default font ID. */ diff --git a/source/blender/blenfont/intern/blf_default.cc b/source/blender/blenfont/intern/blf_default.cc index 4a168fe7af0..7e7df2e5ced 100644 --- a/source/blender/blenfont/intern/blf_default.cc +++ b/source/blender/blenfont/intern/blf_default.cc @@ -11,6 +11,7 @@ #include "DNA_userdef_types.h" #include "BLI_assert.h" +#include "BLI_math_vector_types.hh" #include "BLF_api.h" @@ -58,3 +59,20 @@ void BLF_draw_default(float x, float y, float z, const char *str, const size_t s BLF_position(global_font_default, x, y, z); BLF_draw(global_font_default, str, str_len); } + +void BLF_draw_default_shadow(float x, float y, float z, const char *str, const size_t str_len) +{ + ASSERT_DEFAULT_SET; + BLF_size(global_font_default, global_font_size * UI_SCALE_FAC); + + BLF_enable(global_font_default, BLF_SHADOW); + BLF_shadow(global_font_default, 5, blender::float4{0.0f, 0.0f, 0.0f, 1.0f}); + BLF_shadow_offset(global_font_default, 0, 0); + BLF_position(global_font_default, x, y, z); + BLF_draw(global_font_default, str, str_len); + + BLF_shadow(global_font_default, 3, blender::float4{0.0f, 0.0f, 0.0f, 1.0f}); + BLF_shadow_offset(global_font_default, 1, -1); + BLF_draw(global_font_default, str, str_len); + BLF_disable(global_font_default, BLF_SHADOW); +} diff --git a/source/blender/draw/intern/draw_manager_c.cc b/source/blender/draw/intern/draw_manager_c.cc index da44dc82a3a..a8201c38854 100644 --- a/source/blender/draw/intern/draw_manager_c.cc +++ b/source/blender/draw/intern/draw_manager_c.cc @@ -1145,21 +1145,14 @@ void DRW_draw_region_engine_info(int xoffset, int *yoffset, int line_height) if (data->info[0] != '\0') { const int font_id = BLF_default(); UI_FontThemeColor(font_id, TH_TEXT_HI); - - BLF_enable(font_id, BLF_SHADOW); - BLF_shadow(font_id, 5, blender::float4{0.0f, 0.0f, 0.0f, 1.0f}); - BLF_shadow_offset(font_id, 1, -1); - const char *buf_step = IFACE_(data->info); do { const char *buf = buf_step; buf_step = BLI_strchr_or_end(buf, '\n'); const int buf_len = buf_step - buf; *yoffset -= line_height; - BLF_draw_default(xoffset, *yoffset, 0.0f, buf, buf_len); + BLF_draw_default_shadow(xoffset, *yoffset, 0.0f, buf, buf_len); } while (*buf_step ? ((void)buf_step++, true) : false); - - BLF_disable(font_id, BLF_SHADOW); } } } diff --git a/source/blender/draw/intern/draw_manager_profiling.cc b/source/blender/draw/intern/draw_manager_profiling.cc index 94ce41a9bec..50ede5e4034 100644 --- a/source/blender/draw/intern/draw_manager_profiling.cc +++ b/source/blender/draw/intern/draw_manager_profiling.cc @@ -194,16 +194,16 @@ void DRW_stats_reset() static void draw_stat_5row(const rcti *rect, int u, int v, const char *txt, const int size) { - BLF_draw_default(rect->xmin + (1 + u * 5) * U.widget_unit, - rect->ymax - (3 + v) * U.widget_unit, - 0.0f, - txt, - size); + BLF_draw_default_shadow(rect->xmin + (1 + u * 5) * U.widget_unit, + rect->ymax - (3 + v) * U.widget_unit, + 0.0f, + txt, + size); } static void draw_stat(const rcti *rect, int u, int v, const char *txt, const int size) { - BLF_draw_default( + BLF_draw_default_shadow( rect->xmin + (1 + u) * U.widget_unit, rect->ymax - (3 + v) * U.widget_unit, 0.0f, txt, size); } @@ -217,11 +217,6 @@ void DRW_stats_draw(const rcti *rect) int fontid = BLF_default(); UI_FontThemeColor(fontid, TH_TEXT_HI); - BLF_enable(fontid, BLF_SHADOW); - const float rgba[] = {0.0f, 0.0f, 0.0f, 0.75f}; - BLF_shadow(fontid, 5, rgba); - BLF_shadow_offset(fontid, 0, -1); - BLF_batch_draw_begin(); /* ------------------------------------------ */ @@ -350,5 +345,4 @@ void DRW_stats_draw(const rcti *rect) } BLF_batch_draw_end(); - BLF_disable(fontid, BLF_SHADOW); } diff --git a/source/blender/editors/space_info/info_stats.cc b/source/blender/editors/space_info/info_stats.cc index f6d7d2b0e0a..ab6635e23d6 100644 --- a/source/blender/editors/space_info/info_stats.cc +++ b/source/blender/editors/space_info/info_stats.cc @@ -749,10 +749,10 @@ static void stats_row(int col1, int height) { *y -= height; - BLF_draw_default(col1, *y, 0.0f, key, 128); + BLF_draw_default_shadow(col1, *y, 0.0f, key, 128); char values[128]; SNPRINTF(values, (value2) ? "%s / %s" : "%s", value1, value2); - BLF_draw_default(col2, *y, 0.0f, values, sizeof(values)); + BLF_draw_default_shadow(col2, *y, 0.0f, values, sizeof(values)); } void ED_info_draw_stats( @@ -771,10 +771,6 @@ void ED_info_draw_stats( const int font_id = BLF_default(); UI_FontThemeColor(font_id, TH_TEXT_HI); - BLF_enable(font_id, BLF_SHADOW); - const float shadow_color[4] = {0.0f, 0.0f, 0.0f, 1.0f}; - BLF_shadow(font_id, 5, shadow_color); - BLF_shadow_offset(font_id, 1, -1); /* Translated labels for each stat row. */ enum { @@ -885,6 +881,4 @@ void ED_info_draw_stats( stats_row(col1, labels[FACES], col2, stats_fmt.totfacesel, stats_fmt.totface, y, height); stats_row(col1, labels[TRIS], col2, stats_fmt.tottrisel, stats_fmt.tottri, y, height); } - - BLF_disable(font_id, BLF_SHADOW); } diff --git a/source/blender/editors/space_view3d/view3d_draw.cc b/source/blender/editors/space_view3d/view3d_draw.cc index 8210a08ec75..d87231fe609 100644 --- a/source/blender/editors/space_view3d/view3d_draw.cc +++ b/source/blender/editors/space_view3d/view3d_draw.cc @@ -795,11 +795,11 @@ static void drawviewborder(Scene *scene, Depsgraph *depsgraph, ARegion *region, /* camera name - draw in highlighted text color */ if (ca && ((v3d->overlay.flag & V3D_OVERLAY_HIDE_TEXT) == 0) && (ca->flag & CAM_SHOWNAME)) { UI_FontThemeColor(BLF_default(), TH_TEXT_HI); - BLF_draw_default(x1i, - y1i - (0.7f * U.widget_unit), - 0.0f, - v3d->camera->id.name + 2, - sizeof(v3d->camera->id.name) - 2); + BLF_draw_default_shadow(x1i, + y1i - (0.7f * U.widget_unit), + 0.0f, + v3d->camera->id.name + 2, + sizeof(v3d->camera->id.name) - 2); } } @@ -1268,10 +1268,6 @@ static void draw_viewport_name(ARegion *region, View3D *v3d, int xoffset, int *y /* increase size for unicode languages (Chinese in utf-8...) */ char tmpstr[96 + 6]; - BLF_enable(font_id, BLF_SHADOW); - BLF_shadow(font_id, 5, float4{0.0f, 0.0f, 0.0f, 1.0f}); - BLF_shadow_offset(font_id, 1, -1); - if (RV3D_VIEW_IS_AXIS(rv3d->view) && (rv3d->view_axis_roll != RV3D_VIEW_AXIS_ROLL_0)) { const char *axis_roll; switch (rv3d->view_axis_roll) { @@ -1306,9 +1302,7 @@ static void draw_viewport_name(ARegion *region, View3D *v3d, int xoffset, int *y *yoffset -= VIEW3D_OVERLAY_LINEHEIGHT; - BLF_draw_default(xoffset, *yoffset, 0.0f, name, sizeof(tmpstr)); - - BLF_disable(font_id, BLF_SHADOW); + BLF_draw_default_shadow(xoffset, *yoffset, 0.0f, name, sizeof(tmpstr)); } /** @@ -1451,14 +1445,8 @@ static void draw_selected_name( BLI_assert(BLI_string_len_array(info_array, i) < sizeof(info)); BLI_string_join_array(info, sizeof(info), info_array, i); - BLF_enable(font_id, BLF_SHADOW); - BLF_shadow(font_id, 5, float4{0.0f, 0.0f, 0.0f, 1.0f}); - BLF_shadow_offset(font_id, 1, -1); - *yoffset -= VIEW3D_OVERLAY_LINEHEIGHT; - BLF_draw_default(xoffset, *yoffset, 0.0f, info, sizeof(info)); - - BLF_disable(font_id, BLF_SHADOW); + BLF_draw_default_shadow(xoffset, *yoffset, 0.0f, info, sizeof(info)); } static void draw_grid_unit_name( @@ -1478,11 +1466,7 @@ static void draw_grid_unit_name( } *yoffset -= VIEW3D_OVERLAY_LINEHEIGHT; - BLF_enable(font_id, BLF_SHADOW); - BLF_shadow(font_id, 5, float4{0.0f, 0.0f, 0.0f, 1.0f}); - BLF_shadow_offset(font_id, 1, -1); - BLF_draw_default(xoffset, *yoffset, 0.0f, numstr[0] ? numstr : grid_unit, sizeof(numstr)); - BLF_disable(font_id, BLF_SHADOW); + BLF_draw_default_shadow(xoffset, *yoffset, 0.0f, numstr[0] ? numstr : grid_unit, sizeof(numstr)); } } } @@ -2612,15 +2596,9 @@ void ED_scene_draw_fps(const Scene *scene, int xoffset, int *yoffset) SNPRINTF(printable, IFACE_("fps: %i"), int(state.fps_average + 0.5f)); } - BLF_enable(font_id, BLF_SHADOW); - BLF_shadow(font_id, 5, float4{0.0f, 0.0f, 0.0f, 1.0f}); - BLF_shadow_offset(font_id, 1, -1); - *yoffset -= VIEW3D_OVERLAY_LINEHEIGHT; - BLF_draw_default(xoffset, *yoffset, 0.0f, printable, sizeof(printable)); - - BLF_disable(font_id, BLF_SHADOW); + BLF_draw_default_shadow(xoffset, *yoffset, 0.0f, printable, sizeof(printable)); } /** \} */ diff --git a/source/blender/editors/transform/transform.cc b/source/blender/editors/transform/transform.cc index 593771f8f7e..96990c2b819 100644 --- a/source/blender/editors/transform/transform.cc +++ b/source/blender/editors/transform/transform.cc @@ -1557,7 +1557,7 @@ static void drawAutoKeyWarning(TransInfo *t, ARegion *region) uchar color[3]; UI_GetThemeColorShade3ubv(TH_TEXT_HI, -50, color); BLF_color3ubv(font_id, color); - BLF_draw_default(xco, yco, 0.0f, printable, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_default_shadow(xco, yco, 0.0f, printable, BLF_DRAW_STR_DUMMY_MAX); /* autokey recording icon... */ GPU_blend(GPU_BLEND_ALPHA); -- 2.30.2 From 5a9363a238bb19df7158bc1d28f40a6f3edacf3c Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Mon, 22 Jan 2024 12:06:48 -0800 Subject: [PATCH 2/3] BLF_draw_default_shadow -> BLF_draw_default_shadowed --- source/blender/blenfont/BLF_api.h | 3 ++- source/blender/blenfont/intern/blf_default.cc | 2 +- source/blender/draw/intern/draw_manager_c.cc | 2 +- .../draw/intern/draw_manager_profiling.cc | 12 ++++++------ .../blender/editors/space_info/info_stats.cc | 4 ++-- .../editors/space_view3d/view3d_draw.cc | 19 ++++++++++--------- source/blender/editors/transform/transform.cc | 2 +- 7 files changed, 23 insertions(+), 21 deletions(-) diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h index fa02a25b7ff..2736ca6dd0e 100644 --- a/source/blender/blenfont/BLF_api.h +++ b/source/blender/blenfont/BLF_api.h @@ -337,7 +337,8 @@ void BLF_draw_default(float x, float y, float z, const char *str, size_t str_len /** * As above but with a very contrasting dark shadow. */ -void BLF_draw_default_shadow(float x, float y, float z, const char *str, size_t str_len) ATTR_NONNULL(); +void BLF_draw_default_shadowed(float x, float y, float z, const char *str, size_t str_len) + ATTR_NONNULL(); /** * Set size and DPI, and return default font ID. */ diff --git a/source/blender/blenfont/intern/blf_default.cc b/source/blender/blenfont/intern/blf_default.cc index 7e7df2e5ced..9c2db851b09 100644 --- a/source/blender/blenfont/intern/blf_default.cc +++ b/source/blender/blenfont/intern/blf_default.cc @@ -60,7 +60,7 @@ void BLF_draw_default(float x, float y, float z, const char *str, const size_t s BLF_draw(global_font_default, str, str_len); } -void BLF_draw_default_shadow(float x, float y, float z, const char *str, const size_t str_len) +void BLF_draw_default_shadowed(float x, float y, float z, const char *str, const size_t str_len) { ASSERT_DEFAULT_SET; BLF_size(global_font_default, global_font_size * UI_SCALE_FAC); diff --git a/source/blender/draw/intern/draw_manager_c.cc b/source/blender/draw/intern/draw_manager_c.cc index a8201c38854..d9a24a352e2 100644 --- a/source/blender/draw/intern/draw_manager_c.cc +++ b/source/blender/draw/intern/draw_manager_c.cc @@ -1151,7 +1151,7 @@ void DRW_draw_region_engine_info(int xoffset, int *yoffset, int line_height) buf_step = BLI_strchr_or_end(buf, '\n'); const int buf_len = buf_step - buf; *yoffset -= line_height; - BLF_draw_default_shadow(xoffset, *yoffset, 0.0f, buf, buf_len); + BLF_draw_default_shadowed(xoffset, *yoffset, 0.0f, buf, buf_len); } while (*buf_step ? ((void)buf_step++, true) : false); } } diff --git a/source/blender/draw/intern/draw_manager_profiling.cc b/source/blender/draw/intern/draw_manager_profiling.cc index abd0b875eef..30bdf68aa61 100644 --- a/source/blender/draw/intern/draw_manager_profiling.cc +++ b/source/blender/draw/intern/draw_manager_profiling.cc @@ -196,16 +196,16 @@ void DRW_stats_reset() static void draw_stat_5row(const rcti *rect, int u, int v, const char *txt, const int size) { - BLF_draw_default_shadow(rect->xmin + (1 + u * 5) * U.widget_unit, - rect->ymax - (3 + v) * U.widget_unit, - 0.0f, - txt, - size); + BLF_draw_default_shadowed(rect->xmin + (1 + u * 5) * U.widget_unit, + rect->ymax - (3 + v) * U.widget_unit, + 0.0f, + txt, + size); } static void draw_stat(const rcti *rect, int u, int v, const char *txt, const int size) { - BLF_draw_default_shadow( + BLF_draw_default_shadowed( rect->xmin + (1 + u) * U.widget_unit, rect->ymax - (3 + v) * U.widget_unit, 0.0f, txt, size); } diff --git a/source/blender/editors/space_info/info_stats.cc b/source/blender/editors/space_info/info_stats.cc index ab6635e23d6..34af2d6cfcd 100644 --- a/source/blender/editors/space_info/info_stats.cc +++ b/source/blender/editors/space_info/info_stats.cc @@ -749,10 +749,10 @@ static void stats_row(int col1, int height) { *y -= height; - BLF_draw_default_shadow(col1, *y, 0.0f, key, 128); + BLF_draw_default_shadowed(col1, *y, 0.0f, key, 128); char values[128]; SNPRINTF(values, (value2) ? "%s / %s" : "%s", value1, value2); - BLF_draw_default_shadow(col2, *y, 0.0f, values, sizeof(values)); + BLF_draw_default_shadowed(col2, *y, 0.0f, values, sizeof(values)); } void ED_info_draw_stats( diff --git a/source/blender/editors/space_view3d/view3d_draw.cc b/source/blender/editors/space_view3d/view3d_draw.cc index d87231fe609..4e852163650 100644 --- a/source/blender/editors/space_view3d/view3d_draw.cc +++ b/source/blender/editors/space_view3d/view3d_draw.cc @@ -795,11 +795,11 @@ static void drawviewborder(Scene *scene, Depsgraph *depsgraph, ARegion *region, /* camera name - draw in highlighted text color */ if (ca && ((v3d->overlay.flag & V3D_OVERLAY_HIDE_TEXT) == 0) && (ca->flag & CAM_SHOWNAME)) { UI_FontThemeColor(BLF_default(), TH_TEXT_HI); - BLF_draw_default_shadow(x1i, - y1i - (0.7f * U.widget_unit), - 0.0f, - v3d->camera->id.name + 2, - sizeof(v3d->camera->id.name) - 2); + BLF_draw_default_shadowed(x1i, + y1i - (0.7f * U.widget_unit), + 0.0f, + v3d->camera->id.name + 2, + sizeof(v3d->camera->id.name) - 2); } } @@ -1302,7 +1302,7 @@ static void draw_viewport_name(ARegion *region, View3D *v3d, int xoffset, int *y *yoffset -= VIEW3D_OVERLAY_LINEHEIGHT; - BLF_draw_default_shadow(xoffset, *yoffset, 0.0f, name, sizeof(tmpstr)); + BLF_draw_default_shadowed(xoffset, *yoffset, 0.0f, name, sizeof(tmpstr)); } /** @@ -1446,7 +1446,7 @@ static void draw_selected_name( BLI_string_join_array(info, sizeof(info), info_array, i); *yoffset -= VIEW3D_OVERLAY_LINEHEIGHT; - BLF_draw_default_shadow(xoffset, *yoffset, 0.0f, info, sizeof(info)); + BLF_draw_default_shadowed(xoffset, *yoffset, 0.0f, info, sizeof(info)); } static void draw_grid_unit_name( @@ -1466,7 +1466,8 @@ static void draw_grid_unit_name( } *yoffset -= VIEW3D_OVERLAY_LINEHEIGHT; - BLF_draw_default_shadow(xoffset, *yoffset, 0.0f, numstr[0] ? numstr : grid_unit, sizeof(numstr)); + BLF_draw_default_shadowed( + xoffset, *yoffset, 0.0f, numstr[0] ? numstr : grid_unit, sizeof(numstr)); } } } @@ -2598,7 +2599,7 @@ void ED_scene_draw_fps(const Scene *scene, int xoffset, int *yoffset) *yoffset -= VIEW3D_OVERLAY_LINEHEIGHT; - BLF_draw_default_shadow(xoffset, *yoffset, 0.0f, printable, sizeof(printable)); + BLF_draw_default_shadowed(xoffset, *yoffset, 0.0f, printable, sizeof(printable)); } /** \} */ diff --git a/source/blender/editors/transform/transform.cc b/source/blender/editors/transform/transform.cc index 6eb70cb302d..68f83ce21ed 100644 --- a/source/blender/editors/transform/transform.cc +++ b/source/blender/editors/transform/transform.cc @@ -1559,7 +1559,7 @@ static void drawAutoKeyWarning(TransInfo *t, ARegion *region) uchar color[3]; UI_GetThemeColorShade3ubv(TH_TEXT_HI, -50, color); BLF_color3ubv(font_id, color); - BLF_draw_default_shadow(xco, yco, 0.0f, printable, BLF_DRAW_STR_DUMMY_MAX); + BLF_draw_default_shadowed(xco, yco, 0.0f, printable, BLF_DRAW_STR_DUMMY_MAX); /* autokey recording icon... */ GPU_blend(GPU_BLEND_ALPHA); -- 2.30.2 From 5394d2a27f61a35f62593a2e1b4a22933347f7ec Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Mon, 22 Jan 2024 12:52:26 -0800 Subject: [PATCH 3/3] unused variable --- source/blender/editors/space_view3d/view3d_draw.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/source/blender/editors/space_view3d/view3d_draw.cc b/source/blender/editors/space_view3d/view3d_draw.cc index 4e852163650..b0b4f873325 100644 --- a/source/blender/editors/space_view3d/view3d_draw.cc +++ b/source/blender/editors/space_view3d/view3d_draw.cc @@ -1262,7 +1262,6 @@ static void draw_viewport_name(ARegion *region, View3D *v3d, int xoffset, int *y const char *name = view3d_get_name(v3d, rv3d); const char *name_array[3] = {name, nullptr, nullptr}; int name_array_len = 1; - const int font_id = BLF_default(); /* 6 is the maximum size of the axis roll text. */ /* increase size for unicode languages (Chinese in utf-8...) */ -- 2.30.2