Fix: Node Editor: Improve info panel drawing

Fix papercuts with the info panel:
1. Make the panel extend behind hidden nodes
2. Don't let it become smaller than the node itself, when resizing

Pull Request: https://projects.blender.org/blender/blender/pulls/113411
This commit is contained in:
Leon Schittek
2023-10-14 09:37:03 +02:00
committed by Leon Schittek
parent c634a15e85
commit b93dbaba1d

View File

@@ -2650,6 +2650,35 @@ static void node_draw_extra_info_row(const bNode &node,
}
}
static void node_draw_extra_info_panel_back(const bNode &node, const rctf &extra_info_rect)
{
const rctf &node_rect = node.runtime->totr;
rctf panel_back_rect = extra_info_rect;
/* Extend the panel behind hidden nodes to accomodate the large rounded corners. */
if (node.flag & NODE_HIDDEN) {
panel_back_rect.ymin = BLI_rctf_cent_y(&node_rect);
}
ColorTheme4f color;
if (node.flag & NODE_MUTED) {
UI_GetThemeColorBlend4f(TH_BACK, TH_NODE, 0.2f, color);
}
else {
UI_GetThemeColorBlend4f(TH_BACK, TH_NODE, 0.75f, color);
}
color.a -= 0.35f;
ColorTheme4f color_outline;
UI_GetThemeColorBlendShade4fv(TH_BACK, TH_NODE, 0.4f, -20, color_outline);
const float outline_width = U.pixelsize;
BLI_rctf_pad(&panel_back_rect, outline_width, outline_width);
UI_draw_roundbox_corner_set(UI_CNR_TOP_LEFT | UI_CNR_TOP_RIGHT);
UI_draw_roundbox_4fv_ex(
&panel_back_rect, color, nullptr, 0.0f, color_outline, outline_width, BASIS_RAD);
}
static void node_draw_extra_info_panel(const Scene *scene,
TreeDrawContext &tree_draw_ctx,
const SpaceNode &snode,
@@ -2670,11 +2699,8 @@ static void node_draw_extra_info_panel(const Scene *scene,
}
const rctf &rct = node.runtime->totr;
float color[4];
rctf extra_info_rect;
const float width = (node.width - 6.0f) * UI_SCALE_FAC;
if (node.is_frame()) {
extra_info_rect.xmin = rct.xmin;
extra_info_rect.xmax = rct.xmin + 95.0f * UI_SCALE_FAC;
@@ -2682,62 +2708,40 @@ static void node_draw_extra_info_panel(const Scene *scene,
extra_info_rect.ymax = rct.ymin + 2.0f * UI_SCALE_FAC;
}
else {
float preview_height = 0;
rctf preview_rect;
const float padding = 3.0f * UI_SCALE_FAC;
extra_info_rect.xmin = rct.xmin + 3.0f * UI_SCALE_FAC;
extra_info_rect.xmax = extra_info_rect.xmin + width;
extra_info_rect.xmin = rct.xmin + padding;
extra_info_rect.xmax = rct.xmax - padding;
extra_info_rect.ymin = rct.ymax;
extra_info_rect.ymax = rct.ymax + extra_info_rows.size() * (20.0f * UI_SCALE_FAC);
float preview_height = 0.0f;
rctf preview_rect;
if (preview) {
const float width = BLI_rctf_size_x(&extra_info_rect);
if (preview->x > preview->y) {
const float preview_padding = 3.0f * UI_SCALE_FAC;
preview_height = (width - 2.0 * preview_padding) * float(preview->y) / float(preview->x) +
2.0 * preview_padding;
preview_rect.ymin = extra_info_rect.ymin + preview_padding;
preview_rect.ymax = extra_info_rect.ymin + preview_height - preview_padding;
preview_rect.xmin = extra_info_rect.xmin + preview_padding;
preview_rect.xmax = extra_info_rect.xmax - preview_padding;
preview_height = (width - 2.0f * padding) * float(preview->y) / float(preview->x) +
2.0f * padding;
preview_rect.ymin = extra_info_rect.ymin + padding;
preview_rect.ymax = extra_info_rect.ymin + preview_height - padding;
preview_rect.xmin = extra_info_rect.xmin + padding;
preview_rect.xmax = extra_info_rect.xmax - padding;
extra_info_rect.ymax += preview_height;
}
else {
const float preview_padding = 3.0f * UI_SCALE_FAC;
preview_height = width;
const float preview_width = (width - 2.0 * preview_padding) * float(preview->x) /
const float preview_width = (width - 2.0f * padding) * float(preview->x) /
float(preview->y) +
2.0 * preview_padding;
preview_rect.ymin = extra_info_rect.ymin + preview_padding;
preview_rect.ymax = extra_info_rect.ymin + preview_height - preview_padding;
preview_rect.xmin = extra_info_rect.xmin + preview_padding + (width - preview_width) / 2;
preview_rect.xmax = extra_info_rect.xmax - preview_padding - (width - preview_width) / 2;
2.0f * padding;
preview_rect.ymin = extra_info_rect.ymin + padding;
preview_rect.ymax = extra_info_rect.ymin + preview_height - padding;
preview_rect.xmin = extra_info_rect.xmin + padding + (width - preview_width) / 2;
preview_rect.xmax = extra_info_rect.xmax - padding - (width - preview_width) / 2;
extra_info_rect.ymax += preview_height;
}
}
if (node.flag & NODE_MUTED) {
UI_GetThemeColorBlend4f(TH_BACK, TH_NODE, 0.2f, color);
}
else {
UI_GetThemeColorBlend4f(TH_BACK, TH_NODE, 0.75f, color);
}
color[3] -= 0.35f;
UI_draw_roundbox_corner_set(
UI_CNR_ALL & ~UI_CNR_BOTTOM_LEFT &
((rct.xmax) > extra_info_rect.xmax ? ~UI_CNR_BOTTOM_RIGHT : UI_CNR_ALL));
UI_draw_roundbox_4fv(&extra_info_rect, true, BASIS_RAD, color);
/* Draw outline. */
const float outline_width = 1.0f;
extra_info_rect.xmin -= outline_width;
extra_info_rect.xmax += outline_width;
extra_info_rect.ymin -= outline_width;
extra_info_rect.ymax += outline_width;
UI_GetThemeColorBlendShade4fv(TH_BACK, TH_NODE, 0.4f, -20, color);
UI_draw_roundbox_corner_set(
UI_CNR_ALL & ~UI_CNR_BOTTOM_LEFT &
((rct.xmax) > extra_info_rect.xmax ? ~UI_CNR_BOTTOM_RIGHT : UI_CNR_ALL));
UI_draw_roundbox_4fv(&extra_info_rect, false, BASIS_RAD, color);
node_draw_extra_info_panel_back(node, extra_info_rect);
if (preview) {
node_draw_preview(scene, preview, &preview_rect);