UI: Improved overlay text contrast with new outline text decoration
Overlay texts were previously drawn with two sets of shadows: - 3px blur, - 5px blur, slightly offset But since the shadow color was always set to black, it was still causing legibility issues when the text itself was dark (set via theme for example). This PR adds a new "outline" BLF text decoration, and uses that for the overlays. And it picks text/outline color depending on the "background" color of the view. Details: - Instead of "shadow level" integer where the only valid options are 0, 3 or 5, have a FontShadowType enum. - Add a new FontShadowType::Outline enum entry, that does a 1px outline by doing a 3x3 dilation in the font shader. - BLF_draw_default_shadowed is changed to do outline, instead of drawing the shadow twice. - In the font shader, instead of encoding shadow type in signs of the glyph_size, pass that as a "flags" vertex attribute. Put font texture channel count into the same flags, so that the vertex size stays the same. - Well actually, vertex size becomes smaller by 4 bytes, since turns out glyph_mode vertex attribute was not used for anything at all. Images in the PR. Co-authored-by: Harley Acheson <harley.acheson@gmail.com> Pull Request: https://projects.blender.org/blender/blender/pulls/121383
This commit is contained in:
committed by
Aras Pranckevicius
parent
b78875c675
commit
3582e52f9c
@@ -342,7 +342,7 @@ PyDoc_STRVAR(
|
||||
" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
|
||||
"font use 0.\n"
|
||||
" :type fontid: int\n"
|
||||
" :arg level: The blur level, can be 3, 5 or 0.\n"
|
||||
" :arg level: The blur level (0, 3, 5) or outline (6).\n"
|
||||
" :type level: int\n"
|
||||
" :arg r: Shadow color (red channel 0.0 - 1.0).\n"
|
||||
" :type r: float\n"
|
||||
@@ -363,12 +363,12 @@ static PyObject *py_blf_shadow(PyObject * /*self*/, PyObject *args)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!ELEM(level, 0, 3, 5)) {
|
||||
PyErr_SetString(PyExc_TypeError, "blf.shadow expected arg to be in (0, 3, 5)");
|
||||
if (!ELEM(level, 0, 3, 5, 6)) {
|
||||
PyErr_SetString(PyExc_TypeError, "blf.shadow expected arg to be in (0, 3, 5, 6)");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
BLF_shadow(fontid, level, rgba);
|
||||
BLF_shadow(fontid, FontShadowType(level), rgba);
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user