Fix #130402: Improve Tooltip Text Colors for Light Themes

The text colors used on the tooltips are hard-coded and calculated
based on that widget's text color. But this is done in such a way that
the colors lose their saturation when used on light themes. This PR
calculates them in a way that allows the active color (light blue) and
the alert color (red) to work with light theme colors.

Pull Request: https://projects.blender.org/blender/blender/pulls/131515
This commit is contained in:
Harley Acheson
2024-12-08 00:11:08 +01:00
committed by Harley Acheson
parent 033c02557c
commit c5bce9d710

View File

@@ -145,18 +145,13 @@ void UI_tooltip_image_field_add(uiTooltipData &data, const uiTooltipImage &image
/** \name ToolTip Callbacks (Draw & Free)
* \{ */
static void rgb_tint(float col[3], float h, float h_strength, float v, float v_strength)
static void color_blend_f3_f3(float dest[3], const float source[3], const float fac)
{
float col_hsv_from[3];
float col_hsv_to[3];
rgb_to_hsv_v(col, col_hsv_from);
col_hsv_to[0] = h;
col_hsv_to[1] = h_strength;
col_hsv_to[2] = (col_hsv_from[2] * (1.0f - v_strength)) + (v * v_strength);
hsv_to_rgb_v(col_hsv_to, col);
if (fac != 0.0f) {
dest[0] = (1.0f - fac) * dest[0] + (fac * source[0]);
dest[1] = (1.0f - fac) * dest[1] + (fac * source[1]);
dest[2] = (1.0f - fac) * dest[2] + (fac * source[2]);
}
}
static void ui_tooltip_region_draw_cb(const bContext * /*C*/, ARegion *region)
@@ -186,25 +181,29 @@ static void ui_tooltip_region_draw_cb(const bContext * /*C*/, ARegion *region)
/* set background_color */
rgb_uchar_to_float(background_color, theme->inner);
/* Calculate `normal_color`. */
/* `normal_color` is just tooltip text color. */
rgb_uchar_to_float(main_color, theme->text);
copy_v3_v3(active_color, main_color);
copy_v3_v3(normal_color, main_color);
copy_v3_v3(python_color, main_color);
copy_v3_v3(alert_color, main_color);
/* `value_color` mixes with some background for less strength. */
copy_v3_v3(value_color, main_color);
color_blend_f3_f3(value_color, background_color, 0.2f);
/* Find the brightness difference between background and text colors. */
/* `python_color` mixes with more background to be even dimmer. */
copy_v3_v3(python_color, main_color);
color_blend_f3_f3(python_color, background_color, 0.5f);
const float tone_bg = rgb_to_grayscale(background_color);
// tone_fg = rgb_to_grayscale(main_color);
/* `active_color` is a light blue, push a bit toward text color. */
active_color[0] = 0.4f;
active_color[1] = 0.55f;
active_color[2] = 0.75f;
color_blend_f3_f3(active_color, main_color, 0.3f);
/* Mix the colors. */
rgb_tint(value_color, 0.0f, 0.0f, tone_bg, 0.2f); /* Light gray. */
rgb_tint(active_color, 0.6f, 0.2f, tone_bg, 0.2f); /* Light blue. */
rgb_tint(normal_color, 0.0f, 0.0f, tone_bg, 0.4f); /* Gray. */
rgb_tint(python_color, 0.0f, 0.0f, tone_bg, 0.5f); /* Dark gray. */
rgb_tint(alert_color, 0.0f, 0.8f, tone_bg, 0.1f); /* Red. */
/* `alert_color` is red, push a bit toward text color. */
alert_color[0] = 0.7f;
alert_color[1] = 0.0f;
alert_color[2] = 0.0f;
color_blend_f3_f3(alert_color, main_color, 0.3f);
/* Draw text. */
BLF_wordwrap(data->fstyle.uifont_id, data->wrap_width);