UI: Increased Overlay Text Contrast #117351

Merged
Harley Acheson merged 4 commits from Harley/blender:OverlayContrast into main 2024-01-22 21:58:05 +01:00
7 changed files with 43 additions and 61 deletions

View File

@ -334,6 +334,11 @@ 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_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.
*/

View File

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

View File

@ -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_shadowed(xoffset, *yoffset, 0.0f, buf, buf_len);
} while (*buf_step ? ((void)buf_step++, true) : false);
BLF_disable(font_id, BLF_SHADOW);
}
}
}

View File

@ -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(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(
BLF_draw_default_shadowed(
rect->xmin + (1 + u) * U.widget_unit, rect->ymax - (3 + v) * U.widget_unit, 0.0f, txt, size);
}
@ -219,11 +219,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();
/* ------------------------------------------ */
@ -352,5 +347,4 @@ void DRW_stats_draw(const rcti *rect)
}
BLF_batch_draw_end();
BLF_disable(fontid, BLF_SHADOW);
}

View File

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

View File

@ -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_shadowed(x1i,
y1i - (0.7f * U.widget_unit),
0.0f,
v3d->camera->id.name + 2,
sizeof(v3d->camera->id.name) - 2);
}
}
@ -1262,16 +1262,11 @@ 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...) */
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 +1301,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_shadowed(xoffset, *yoffset, 0.0f, name, sizeof(tmpstr));
}
/**
@ -1451,14 +1444,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_shadowed(xoffset, *yoffset, 0.0f, info, sizeof(info));
}
static void draw_grid_unit_name(
@ -1478,11 +1465,8 @@ 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_shadowed(
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_shadowed(xoffset, *yoffset, 0.0f, printable, sizeof(printable));
}
/** \} */

View File

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