UI: Allow Discretionary Use of Icon Outline

Icons can have contrasting outlines, but currently this can only happen
for some icons and when the theme setting "Icon Border" is greater than
zero. This change shows them in the same situations but also allows
them to be shown when needed. For special situations like having an
icon overlay on an icon, or for the icons in the corners of File
Browser preview items, etc.  In a nutshell this allows UI_icon_draw_ex
to honor its outline argument, rather than ignoring it unless the theme
setting was also set.

Pull Request: https://projects.blender.org/blender/blender/pulls/123863
This commit is contained in:
Harley Acheson
2024-06-27 23:00:53 +02:00
committed by Harley Acheson
parent 5c7821fd79
commit 9ae237d0b4
3 changed files with 37 additions and 23 deletions

View File

@@ -439,7 +439,7 @@ static void vicon_collection_color_draw(
1.0f,
0.0f,
collection_color->color,
true,
btheme->tui.icon_border_intensity > 0.0f,
UI_NO_ICON_OVERLAY_TEXT);
}
@@ -468,8 +468,15 @@ static void vicon_strip_color_draw(
const float aspect = float(ICON_DEFAULT_WIDTH) / float(w);
UI_icon_draw_ex(
x, y, ICON_SNAP_FACE, aspect, 1.0f, 0.0f, strip_color->color, true, UI_NO_ICON_OVERLAY_TEXT);
UI_icon_draw_ex(x,
y,
ICON_SNAP_FACE,
aspect,
1.0f,
0.0f,
strip_color->color,
btheme->tui.icon_border_intensity > 0.0f,
UI_NO_ICON_OVERLAY_TEXT);
}
# define DEF_ICON_STRIP_COLOR_DRAW(index, color) \
@@ -539,7 +546,7 @@ static void vicon_layergroup_color_draw(
1.0f,
0.0f,
layergroup_color->color,
true,
btheme->tui.icon_border_intensity > 0.0f,
UI_NO_ICON_OVERLAY_TEXT);
}
@@ -1948,7 +1955,10 @@ static void icon_draw_size(float x,
}
else if (di->type == ICON_TYPE_MONO_TEXTURE) {
/* Monochrome icon that uses text or theme color. */
const bool with_border = mono_border && (btheme->tui.icon_border_intensity > 0.0f);
float outline_intensity = mono_border ? (btheme->tui.icon_border_intensity > 0.0f ?
btheme->tui.icon_border_intensity :
0.5f) :
0.0f;
float color[4];
if (mono_rgba) {
rgba_uchar_to_float(color, (const uchar *)mono_rgba);
@@ -1957,12 +1967,7 @@ static void icon_draw_size(float x,
UI_GetThemeColor4fv(TH_TEXT, color);
}
color[3] = alpha;
BLF_draw_svg_icon(uint(icon_id),
x,
y,
float(draw_size) / aspect,
color,
with_border ? btheme->tui.icon_border_intensity : 0.0f);
BLF_draw_svg_icon(uint(icon_id), x, y, float(draw_size) / aspect, color, outline_intensity);
if (text_overlay && text_overlay->text[0] != '\0') {
/* Handle the little numbers on top of the icon. */

View File

@@ -1264,9 +1264,10 @@ static void widget_draw_icon_centered(const BIFIconID icon,
const float desaturate = 1.0 - btheme->tui.icon_saturation;
uchar color[4] = {mono_color[0], mono_color[1], mono_color[2], mono_color[3]};
const bool has_theme = UI_icon_get_theme_color(int(icon), color);
const bool outline = btheme->tui.icon_border_intensity > 0.0f && has_theme;
UI_icon_draw_ex(
x, y, icon, aspect * UI_INV_SCALE_FAC, alpha, desaturate, color, has_theme, nullptr);
x, y, icon, aspect * UI_INV_SCALE_FAC, alpha, desaturate, color, outline, nullptr);
}
}
@@ -1352,19 +1353,19 @@ static void widget_draw_icon(
/* Get theme color. */
uchar color[4] = {mono_color[0], mono_color[1], mono_color[2], mono_color[3]};
const bool has_theme = UI_icon_get_theme_color(icon, color);
bTheme *btheme = UI_GetTheme();
const bool has_theme = UI_icon_get_theme_color(int(icon), color);
const bool outline = btheme->tui.icon_border_intensity > 0.0f && has_theme;
/* to indicate draggable */
if (ui_but_drag_is_draggable(but) && (but->flag & UI_HOVER)) {
UI_icon_draw_ex(
xs, ys, icon, aspect, 1.25f, 0.0f, color, has_theme, &but->icon_overlay_text);
UI_icon_draw_ex(xs, ys, icon, aspect, 1.25f, 0.0f, color, outline, &but->icon_overlay_text);
}
else if (but->flag & (UI_HOVER | UI_SELECT | UI_SELECT_DRAW)) {
UI_icon_draw_ex(
xs, ys, icon, aspect, alpha, 0.0f, color, has_theme, &but->icon_overlay_text);
UI_icon_draw_ex(xs, ys, icon, aspect, alpha, 0.0f, color, outline, &but->icon_overlay_text);
}
else if (!((but->icon != ICON_NONE) && UI_but_is_tool(but))) {
if (has_theme) {
if (outline) {
alpha *= 0.8f;
}
UI_icon_draw_ex(xs,
@@ -1374,7 +1375,7 @@ static void widget_draw_icon(
alpha,
0.0f,
color,
has_theme,
outline,
&but->icon_overlay_text,
but->drawflag & UI_BUT_ICON_INVERT);
}
@@ -1382,7 +1383,7 @@ static void widget_draw_icon(
const bTheme *btheme = UI_GetTheme();
const float desaturate = 1.0 - btheme->tui.icon_saturation;
UI_icon_draw_ex(
xs, ys, icon, aspect, alpha, desaturate, color, has_theme, &but->icon_overlay_text);
xs, ys, icon, aspect, alpha, desaturate, color, outline, &but->icon_overlay_text);
}
}

View File

@@ -2971,11 +2971,11 @@ static bool tselem_draw_icon(uiBlock *block,
float aspect = (0.8f * UI_UNIT_Y) / ICON_DEFAULT_HEIGHT;
x += 2.0f * aspect;
y += 2.0f * aspect;
bTheme *btheme = UI_GetTheme();
if (is_collection) {
Collection *collection = outliner_collection_from_tree_element(te);
if (collection->color_tag != COLLECTION_COLOR_NONE) {
bTheme *btheme = UI_GetTheme();
UI_icon_draw_ex(x,
y,
data.icon,
@@ -2983,7 +2983,7 @@ static bool tselem_draw_icon(uiBlock *block,
alpha,
0.0f,
btheme->collection_color[collection->color_tag].color,
true,
btheme->tui.icon_border_intensity > 0.0f,
&text_overlay);
return true;
}
@@ -2995,7 +2995,15 @@ static bool tselem_draw_icon(uiBlock *block,
/* Restrict column clip. it has been coded by simply overdrawing, doesn't work for buttons. */
uchar color[4];
if (UI_icon_get_theme_color(data.icon, color)) {
UI_icon_draw_ex(x, y, data.icon, UI_INV_SCALE_FAC, alpha, 0.0f, color, true, &text_overlay);
UI_icon_draw_ex(x,
y,
data.icon,
UI_INV_SCALE_FAC,
alpha,
0.0f,
color,
btheme->tui.icon_border_intensity > 0.0f,
&text_overlay);
}
else {
UI_icon_draw_ex(