From ca00c9aa3ea7f77fd364cb175451b11b413c5d71 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Wed, 30 Aug 2023 18:59:17 +0200 Subject: [PATCH] UI: Header Status Text Changes Draw status text in the Tool Settings bar if visible, rather than Header. Pull Request: https://projects.blender.org/blender/blender/pulls/111676 --- source/blender/editors/screen/area.cc | 92 ++++++++++++++------------- 1 file changed, 48 insertions(+), 44 deletions(-) diff --git a/source/blender/editors/screen/area.cc b/source/blender/editors/screen/area.cc index b480e790e44..b6ef633041b 100644 --- a/source/blender/editors/screen/area.cc +++ b/source/blender/editors/screen/area.cc @@ -343,48 +343,41 @@ static void region_draw_azones(ScrArea *area, ARegion *region) GPU_blend(GPU_BLEND_NONE); } -static void region_draw_status_text(ScrArea *area, ARegion *region) +static void region_draw_status_text(ScrArea * /*area*/, ARegion *region) { - bool overlap = ED_region_is_overlap(area->spacetype, region->regiontype); + float header_color[4]; + UI_GetThemeColor4fv(TH_HEADER_ACTIVE, header_color); - if (overlap) { - GPU_clear_color(0.0f, 0.0f, 0.0f, 0.0f); - } - else { - UI_ThemeClearColor(TH_HEADER); + /* Clear the region from the buffer. */ + GPU_clear_color(0.0f, 0.0f, 0.0f, 0.0f); + + /* Fill with header color. */ + if (header_color[3] > 0.0f) { + const rctf rect = {0.0f, float(region->winx), 0.0f, float(region->winy)}; + UI_draw_roundbox_4fv(&rect, true, 0.0f, header_color); } - int fontid = BLF_set_default(); - - const float width = BLF_width(fontid, region->headerstr, BLF_DRAW_STR_DUMMY_MAX); - const float x = UI_UNIT_X; + const int fontid = BLF_set_default(); + const float x = 12.0f * UI_SCALE_FAC; const float y = 0.4f * UI_UNIT_Y; + GPU_blend(GPU_BLEND_ALPHA); - if (overlap) { - const float pad = 2.0f * UI_SCALE_FAC; - const float x1 = x - (UI_UNIT_X - pad); - const float x2 = x + width + (UI_UNIT_X - pad); - const float y1 = pad; - const float y2 = region->winy - pad; - - GPU_blend(GPU_BLEND_ALPHA); - - float color[4] = {0.0f, 0.0f, 0.0f, 0.5f}; + if (header_color[3] < 0.3f) { + /* Draw a background behind the text for extra contrast. */ + const float width = BLF_width(fontid, region->headerstr, BLF_DRAW_STR_DUMMY_MAX); + const float pad = 5.0f * UI_SCALE_FAC; + const float x1 = x - pad; + const float x2 = x + width + pad; + const float y1 = 3.0f * UI_SCALE_FAC; + const float y2 = region->winy - (4.0f * UI_SCALE_FAC); + float color[4] = {0.0f, 0.0f, 0.0f, 0.3f}; UI_GetThemeColor3fv(TH_BACK, color); UI_draw_roundbox_corner_set(UI_CNR_ALL); - rctf rect{}; - rect.xmin = x1; - rect.xmax = x2; - rect.ymin = y1; - rect.ymax = y2; - UI_draw_roundbox_aa(&rect, true, 4.0f, color); - - UI_FontThemeColor(fontid, TH_TEXT); - } - else { - UI_FontThemeColor(fontid, TH_TEXT); + const rctf rect = {x1, x2, y1, y2}; + UI_draw_roundbox_4fv(&rect, true, 4.0f * UI_SCALE_FAC, color); } + UI_FontThemeColor(fontid, TH_TEXT); BLF_position(fontid, x, y, 0.0f); BLF_draw(fontid, region->headerstr, BLF_DRAW_STR_DUMMY_MAX); } @@ -818,20 +811,31 @@ void ED_area_status_text(ScrArea *area, const char *str) return; } + ARegion *ar = nullptr; + LISTBASE_FOREACH (ARegion *, region, &area->regionbase) { - if (region->regiontype == RGN_TYPE_HEADER) { - if (str) { - if (region->headerstr == nullptr) { - region->headerstr = static_cast(MEM_mallocN(UI_MAX_DRAW_STR, "headerprint")); - } - BLI_strncpy(region->headerstr, str, UI_MAX_DRAW_STR); - BLI_str_rstrip(region->headerstr); - } - else { - MEM_SAFE_FREE(region->headerstr); - } - ED_region_tag_redraw(region); + if (region->regiontype == RGN_TYPE_HEADER && region->visible) { + ar = region; } + else if (region->regiontype == RGN_TYPE_TOOL_HEADER && region->visible) { + /* Prefer tool header when we also have a header. */ + ar = region; + break; + } + } + + if (ar) { + if (str) { + if (ar->headerstr == nullptr) { + ar->headerstr = static_cast(MEM_mallocN(UI_MAX_DRAW_STR, "headerprint")); + } + BLI_strncpy(ar->headerstr, str, UI_MAX_DRAW_STR); + BLI_str_rstrip(ar->headerstr); + } + else { + MEM_SAFE_FREE(ar->headerstr); + } + ED_region_tag_redraw(ar); } }