UI: tweak drawing of header status text for transparent headers.
This commit is contained in:
@@ -102,6 +102,9 @@ void BLF_batch_draw_end(void);
|
||||
void BLF_draw_default(float x, float y, float z, const char *str, size_t len) ATTR_NONNULL();
|
||||
void BLF_draw_default_ascii(float x, float y, float z, const char *str, size_t len) ATTR_NONNULL();
|
||||
|
||||
/* Set size and DPI, and return default font ID. */
|
||||
int BLF_set_default(void);
|
||||
|
||||
/* Draw the string using the current font. */
|
||||
void BLF_draw_ex(int fontid, const char *str, size_t len, struct ResultBLF *r_info) ATTR_NONNULL(2);
|
||||
void BLF_draw(int fontid, const char *str, size_t len) ATTR_NONNULL(2);
|
||||
|
||||
@@ -570,6 +570,15 @@ void BLF_draw_default_ascii(float x, float y, float z, const char *str, size_t l
|
||||
BLF_draw_ascii(global_font_default, str, len); /* XXX, use real length */
|
||||
}
|
||||
|
||||
int BLF_set_default(void)
|
||||
{
|
||||
ASSERT_DEFAULT_SET;
|
||||
|
||||
BLF_size(global_font_default, global_font_points, global_font_dpi);
|
||||
|
||||
return global_font_default;
|
||||
}
|
||||
|
||||
static void blf_draw_gl__start(FontBLF *font)
|
||||
{
|
||||
/*
|
||||
|
||||
@@ -85,6 +85,7 @@ size_t BLI_strnlen(const char *str, const size_t maxlen) ATTR_WARN_UNUSED_RESULT
|
||||
|
||||
void BLI_str_tolower_ascii(char *str, const size_t len) ATTR_NONNULL();
|
||||
void BLI_str_toupper_ascii(char *str, const size_t len) ATTR_NONNULL();
|
||||
void BLI_str_rstrip(char *str) ATTR_NONNULL();
|
||||
int BLI_str_rstrip_float_zero(char *str, const char pad) ATTR_NONNULL();
|
||||
|
||||
int BLI_str_index_in_array_n(const char *__restrict str, const char **__restrict str_array, const int str_array_len) ATTR_NONNULL();
|
||||
|
||||
@@ -778,6 +778,21 @@ void BLI_str_toupper_ascii(char *str, const size_t len)
|
||||
str[i] -= 'a' - 'A';
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip whitespace from end of the string.
|
||||
*/
|
||||
void BLI_str_rstrip(char *str)
|
||||
{
|
||||
for (int i = strlen(str) - 1; i > 0; i--) {
|
||||
if (isspace(str[i])) {
|
||||
str[i] = '\0';
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip trailing zeros from a float, eg:
|
||||
* 0.0000 -> 0.0
|
||||
|
||||
@@ -393,6 +393,49 @@ static void region_draw_azones(ScrArea *sa, ARegion *ar)
|
||||
GPU_blend(false);
|
||||
}
|
||||
|
||||
static void region_draw_status_text(ScrArea *sa, ARegion *ar)
|
||||
{
|
||||
bool overlap = ED_region_is_overlap(sa->spacetype, ar->regiontype);
|
||||
|
||||
if (overlap) {
|
||||
GPU_clear_color(0.0, 0.0, 0.0, 0.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
else {
|
||||
UI_ThemeClearColor(TH_HEADER);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
|
||||
int fontid = BLF_set_default();
|
||||
|
||||
const float width = BLF_width(fontid, ar->headerstr, BLF_DRAW_STR_DUMMY_MAX);
|
||||
const float x = UI_UNIT_X;
|
||||
const float y = 0.4f * UI_UNIT_Y;
|
||||
|
||||
if (overlap) {
|
||||
const float pad = 2.0f * UI_DPI_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 = ar->winy - pad;
|
||||
|
||||
GPU_blend_set_func_separate(GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
float color[4] = {0.0f, 0.0f, 0.0f, 0.5f};
|
||||
UI_GetThemeColor3fv(TH_BACK, color);
|
||||
UI_draw_roundbox_corner_set(UI_CNR_ALL);
|
||||
UI_draw_roundbox_aa(true, x1, y1, x2, y2, 4.0f, color);
|
||||
|
||||
UI_FontThemeColor(fontid, TH_TEXT);
|
||||
}
|
||||
else {
|
||||
UI_FontThemeColor(fontid, TH_TEXT);
|
||||
}
|
||||
|
||||
BLF_position(fontid, x, y, 0.0f);
|
||||
BLF_draw(fontid, ar->headerstr, BLF_DRAW_STR_DUMMY_MAX);
|
||||
}
|
||||
|
||||
/* Follow wmMsgNotifyFn spec */
|
||||
void ED_region_do_msg_notify_tag_redraw(
|
||||
bContext *UNUSED(C), wmMsgSubscribeKey *UNUSED(msg_key), wmMsgSubscribeValue *msg_val)
|
||||
@@ -480,11 +523,7 @@ void ED_region_do_draw(bContext *C, ARegion *ar)
|
||||
}
|
||||
/* optional header info instead? */
|
||||
else if (ar->headerstr) {
|
||||
UI_ThemeClearColor(TH_HEADER);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
UI_FontThemeColor(BLF_default(), TH_TEXT);
|
||||
BLF_draw_default(UI_UNIT_X, 0.4f * UI_UNIT_Y, 0.0f, ar->headerstr, BLF_DRAW_STR_DUMMY_MAX);
|
||||
region_draw_status_text(sa, ar);
|
||||
}
|
||||
else if (at->draw) {
|
||||
at->draw(C, ar);
|
||||
@@ -671,6 +710,7 @@ void ED_area_status_text(ScrArea *sa, const char *str)
|
||||
if (ar->headerstr == NULL)
|
||||
ar->headerstr = MEM_mallocN(UI_MAX_DRAW_STR, "headerprint");
|
||||
BLI_strncpy(ar->headerstr, str, UI_MAX_DRAW_STR);
|
||||
BLI_str_rstrip(ar->headerstr);
|
||||
}
|
||||
else if (ar->headerstr) {
|
||||
MEM_freeN(ar->headerstr);
|
||||
|
||||
Reference in New Issue
Block a user