From 49451b91f6d0c7d974f0f894a69a5f54dd4576d5 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Mon, 22 Jan 2024 11:26:00 -0800 Subject: [PATCH 1/3] UI: TreeView Hierarchy Line with Region Zoom Minimum changes required to keep hierarchy line width and positions consistent as the region is zoomed. --- source/blender/editors/include/UI_tree_view.hh | 4 +++- .../editors/interface/views/tree_view.cc | 18 +++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/source/blender/editors/include/UI_tree_view.hh b/source/blender/editors/include/UI_tree_view.hh index 440b3d1a8ac..27c91181217 100644 --- a/source/blender/editors/include/UI_tree_view.hh +++ b/source/blender/editors/include/UI_tree_view.hh @@ -150,7 +150,9 @@ class AbstractTreeView : public AbstractView, public TreeViewItemContainer { void draw_hierarchy_lines(const ARegion ®ion) const; void draw_hierarchy_lines_recursive(const ARegion ®ion, const TreeViewOrItem &parent, - uint pos) const; + const uint pos, + const float aspect) const; + AbstractTreeViewItem *find_last_visible_descendant(const AbstractTreeViewItem &parent) const; }; diff --git a/source/blender/editors/interface/views/tree_view.cc b/source/blender/editors/interface/views/tree_view.cc index 7501e47e842..00e90edec40 100644 --- a/source/blender/editors/interface/views/tree_view.cc +++ b/source/blender/editors/interface/views/tree_view.cc @@ -135,14 +135,15 @@ AbstractTreeViewItem *AbstractTreeView::find_last_visible_descendant( void AbstractTreeView::draw_hierarchy_lines_recursive(const ARegion ®ion, const TreeViewOrItem &parent, - const uint pos) const + const uint pos, + const float aspect) const { for (const auto &item : parent.children_) { if (!item->is_collapsible() || item->is_collapsed()) { continue; } - draw_hierarchy_lines_recursive(region, *item, pos); + draw_hierarchy_lines_recursive(region, *item, pos, aspect); const AbstractTreeViewItem *first_descendant = item->children_.first().get(); const AbstractTreeViewItem *last_descendant = find_last_visible_descendant(*item); @@ -162,9 +163,10 @@ void AbstractTreeView::draw_hierarchy_lines_recursive(const ARegion ®ion, ui_but_to_pixelrect(&last_child_rect, ®ion, block, &last_child_but); /* Small vertical padding. */ - const short line_padding = UI_UNIT_Y / 4.0f; - const float x = first_child_rect.xmin + first_descendant->indent_width() - - UI_ICON_SIZE * 0.5f + 2 * UI_SCALE_FAC; + const short line_padding = UI_UNIT_Y / 4.0f / aspect; + const float x = first_child_rect.xmin + + ((first_descendant->indent_width() - (6.0f * UI_SCALE_FAC)) / aspect); + immBegin(GPU_PRIM_LINES, 2); immVertex2f(pos, x, first_child_rect.ymax - line_padding); immVertex2f(pos, x, last_child_rect.ymin + line_padding); @@ -174,6 +176,8 @@ void AbstractTreeView::draw_hierarchy_lines_recursive(const ARegion ®ion, void AbstractTreeView::draw_hierarchy_lines(const ARegion ®ion) const { + const float aspect = BLI_rctf_size_y(®ion.v2d.cur) / (BLI_rcti_size_y(®ion.v2d.mask) + 1); + GPUVertFormat *format = immVertexFormat(); uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); uchar col[4]; @@ -191,9 +195,9 @@ void AbstractTreeView::draw_hierarchy_lines(const ARegion ®ion) const col[3] = 255; immUniformColor4ubv(col); - GPU_line_width(1.0f); + GPU_line_width(1.0f/ aspect); GPU_blend(GPU_BLEND_ALPHA); - draw_hierarchy_lines_recursive(region, *this, pos); + draw_hierarchy_lines_recursive(region, *this, pos, aspect); GPU_blend(GPU_BLEND_NONE); immUnbindProgram(); -- 2.30.2 From 4fdc63f0c379a985c1576ccf66fd43d4bd45964a Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Tue, 23 Jan 2024 09:35:47 -0800 Subject: [PATCH 2/3] Adjust line based on UI_ICON_SIZE --- source/blender/editors/interface/views/tree_view.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/blender/editors/interface/views/tree_view.cc b/source/blender/editors/interface/views/tree_view.cc index 00e90edec40..b57b3c63ace 100644 --- a/source/blender/editors/interface/views/tree_view.cc +++ b/source/blender/editors/interface/views/tree_view.cc @@ -164,9 +164,9 @@ void AbstractTreeView::draw_hierarchy_lines_recursive(const ARegion ®ion, /* Small vertical padding. */ const short line_padding = UI_UNIT_Y / 4.0f / aspect; - const float x = first_child_rect.xmin + - ((first_descendant->indent_width() - (6.0f * UI_SCALE_FAC)) / aspect); - + const float x = first_child_rect.xmin + ((first_descendant->indent_width() - + (0.5f * UI_ICON_SIZE) + U.pixelsize + UI_SCALE_FAC) / + aspect); immBegin(GPU_PRIM_LINES, 2); immVertex2f(pos, x, first_child_rect.ymax - line_padding); immVertex2f(pos, x, last_child_rect.ymin + line_padding); -- 2.30.2 From a67154920bd7e3660513d023f142b0ea4507dea1 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Tue, 23 Jan 2024 11:07:40 -0800 Subject: [PATCH 3/3] formatting change --- source/blender/editors/interface/views/tree_view.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/editors/interface/views/tree_view.cc b/source/blender/editors/interface/views/tree_view.cc index b57b3c63ace..7f6a5f81dea 100644 --- a/source/blender/editors/interface/views/tree_view.cc +++ b/source/blender/editors/interface/views/tree_view.cc @@ -195,7 +195,7 @@ void AbstractTreeView::draw_hierarchy_lines(const ARegion ®ion) const col[3] = 255; immUniformColor4ubv(col); - GPU_line_width(1.0f/ aspect); + GPU_line_width(1.0f / aspect); GPU_blend(GPU_BLEND_ALPHA); draw_hierarchy_lines_recursive(region, *this, pos, aspect); GPU_blend(GPU_BLEND_NONE); -- 2.30.2