Fix T89246: No Mnemonic Underlines in Dialogs

When drawing mnemonic underlines for hotkeys, use text output of
underscore character instead of direct drawing a line. Otherwise these
are not visible in dialog buttons.

Introduced in 0fcc063fd9

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

Reviewed by Campbell Barton
This commit is contained in:
Harley Acheson 2021-06-18 08:32:07 -07:00
parent 4c19fe4707
commit aee04d4960
Notes: blender-bot 2023-02-14 02:22:07 +01:00
Referenced by commit f7022fc73f, Fix Build Warning
Referenced by issue #89246, Underline Shortcut Keys no longer appear on Save changes before Closing? menu
1 changed files with 7 additions and 10 deletions

View File

@ -1949,8 +1949,8 @@ static bool widget_draw_text_underline_calc_position(const char *UNUSED(str),
/* Full width of this glyph including both bearings. */
const float width = glyph_bounds->xmin + BLI_rctf_size_x(glyph_bounds) + glyph_bounds->xmin;
ul_data->r_offset_px[0] = glyph_step_bounds->xmin + ((width - ul_data->width_px) * 0.5f);
/* Two line-widths below the lower glyph bounds. */
ul_data->r_offset_px[1] = glyph_bounds->ymin - U.pixelsize - U.pixelsize;
/* One line-width below the lower glyph bounds. */
ul_data->r_offset_px[1] = glyph_bounds->ymin - U.pixelsize;
/* Early exit. */
return false;
}
@ -2221,16 +2221,13 @@ static void widget_draw_text(const uiFontStyle *fstyle,
widget_draw_text_underline_calc_position,
&ul_data);
GPU_blend(GPU_BLEND_ALPHA);
const uint pos = GPU_vertformat_attr_add(
immVertexFormat(), "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT);
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
immUniformColor4ubv(wcol->text);
const int pos_x = rect->xmin + font_xofs + ul_data.r_offset_px[0];
const int pos_y = rect->ymin + font_yofs + ul_data.r_offset_px[1];
immRecti(pos, pos_x, pos_y, pos_x + ul_width, pos_y - ul_height);
immUnbindProgram();
GPU_blend(GPU_BLEND_NONE);
/* Use text output because direct drawing doesn't always work. See T89246. */
BLF_position(fstyle->uifont_id, pos_x, pos_y, 0.0f);
BLF_color4ubv(fstyle->uifont_id, wcol->text);
BLF_draw(fstyle->uifont_id, "_", 2);
if (fstyle->kerning == 1) {
BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT);