Fix #126908: 3D view background color affects attribute text outline color #127071

Merged
Harley Acheson merged 2 commits from aras_p/blender:fix_drw_text_outline into main 2024-09-03 22:01:35 +02:00

The change was accidentally done in #121383 which primarily concerned
itself with overlay text colors, but started to use TH_BACK theme color
for the draw manager text (e.g. for geometry nodes value visualization)
outline color. Change behavior to use black or white outline color, based
on lightness of text color.

The change was accidentally done in #121383 which primarily concerned itself with overlay text colors, but started to use TH_BACK theme color for the draw manager text (e.g. for geometry nodes value visualization) outline color. Change behavior to use black or white outline color, based on lightness of text color.
Aras Pranckevicius added 1 commit 2024-09-02 13:28:46 +02:00
The change was accidentally done in #121383 which primarily concerned
itself with overlay text colors, but started to use TH_BACK theme color
for the draw manager text (e.g. for geometry nodes value visualization)
outline color. Restore behavior to use fixed "almost black" outline
color.
Aras Pranckevicius requested review from Harley Acheson 2024-09-02 13:28:58 +02:00
Member

This definitely helps in this case, where we have white text on a white background.

But if the text highlight color is then changed to black then you get a black outline around black text. What do you think of leaving this change for only when the color is light, something like this?

diff --git a/source/blender/draw/intern/draw_manager_text.cc b/source/blender/draw/intern/draw_manager_text.cc
index f0fb6538cc0..0b566ee3c07 100644
--- a/source/blender/draw/intern/draw_manager_text.cc
+++ b/source/blender/draw/intern/draw_manager_text.cc
@@ -143,13 +143,21 @@ static void drw_text_cache_draw_ex(DRWTextStore *dt, ARegion *region)
   const int font_id = BLF_set_default();
 
   float shadow_color[4] = {0, 0, 0, 0.8f};
-  UI_GetThemeColor3fv(TH_BACK, shadow_color);
+  float bg_color[4];
+  UI_GetThemeColor3fv(TH_BACK, bg_color);
 
   BLI_memiter_iter_init(dt->cache_strings, &it);
   while ((vos = static_cast<ViewCachedString *>(BLI_memiter_iter_step(&it)))) {
     if (vos->sco[0] != IS_CLIPPED) {
       if (col_pack_prev != vos->col.pack) {
         BLF_color4ubv(font_id, vos->col.ub);
+        const char lightness = rgb_to_grayscale_byte(vos->col.ub);
+        if (lightness > 153) {
+          copy_v3_fl(shadow_color, 0.0f);
+        }
+        else {
+          copy_v3_v3(shadow_color, bg_color);
+        }
         col_pack_prev = vos->col.pack;
       }

Not sure where the cut off would be to be honest. The above changes it like this:

AttributeTextColor.gif

This definitely helps in this case, where we have white text on a white background. But if the text highlight color is then changed to black then you get a black outline around black text. What do you think of leaving this change for only when the color is light, something like this? ``` diff --git a/source/blender/draw/intern/draw_manager_text.cc b/source/blender/draw/intern/draw_manager_text.cc index f0fb6538cc0..0b566ee3c07 100644 --- a/source/blender/draw/intern/draw_manager_text.cc +++ b/source/blender/draw/intern/draw_manager_text.cc @@ -143,13 +143,21 @@ static void drw_text_cache_draw_ex(DRWTextStore *dt, ARegion *region) const int font_id = BLF_set_default(); float shadow_color[4] = {0, 0, 0, 0.8f}; - UI_GetThemeColor3fv(TH_BACK, shadow_color); + float bg_color[4]; + UI_GetThemeColor3fv(TH_BACK, bg_color); BLI_memiter_iter_init(dt->cache_strings, &it); while ((vos = static_cast<ViewCachedString *>(BLI_memiter_iter_step(&it)))) { if (vos->sco[0] != IS_CLIPPED) { if (col_pack_prev != vos->col.pack) { BLF_color4ubv(font_id, vos->col.ub); + const char lightness = rgb_to_grayscale_byte(vos->col.ub); + if (lightness > 153) { + copy_v3_fl(shadow_color, 0.0f); + } + else { + copy_v3_v3(shadow_color, bg_color); + } col_pack_prev = vos->col.pack; } ``` Not sure where the cut off would be to be honest. The above changes it like this: ![AttributeTextColor.gif](/attachments/3ff72eeb-64c1-4987-b216-8a337602db57)
Author
Member

@Harley should the outline color alternate between "black" (for bright text) and "background" (for dark text), or instead between "black" and "white"? I'm thinking of case of both TH_BACK and the text color being dark enough, that would still not be very legible right?

@Harley should the outline color alternate between "black" (for bright text) and "background" (for dark text), or instead between "black" and "white"? I'm thinking of case of both TH_BACK and the text color being dark enough, that would still not be very legible right?
Member

@Harley should the outline color alternate between "black" (for bright text) and "background" (for dark text), or instead between "black" and "white"? I'm thinking of case of both TH_BACK and the text color being dark enough, that would still not be very legible right?

Oh yeah, you're right! Black on black really needs that light outline.

> @Harley should the outline color alternate between "black" (for bright text) and "background" (for dark text), or instead between "black" and "white"? I'm thinking of case of both TH_BACK and the text color being dark enough, that would still not be very legible right? Oh yeah, you're right! Black on black really needs that light outline.
Aras Pranckevicius added 1 commit 2024-09-03 08:22:08 +02:00
Use white or black outline color in draw manager text
All checks were successful
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
46867eedbd
Member

@blender-bot build

@blender-bot build
Harley Acheson approved these changes 2024-09-03 22:01:02 +02:00
Harley Acheson left a comment
Member

Works great!

Works great!
Harley Acheson merged commit 174387e4d9 into main 2024-09-03 22:01:35 +02:00
Aras Pranckevicius deleted branch fix_drw_text_outline 2024-09-04 11:58:05 +02:00
Harley Acheson added this to the Module: User Interface project 2024-09-05 01:44:24 +02:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Asset System
Module
Asset System
Module
Core
Module
Development Management
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#127071
No description provided.