diff options
author | Julian Eisel <julian@blender.org> | 2020-10-15 21:23:13 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2020-10-15 21:31:36 +0300 |
commit | d4f94d8a31044af489d4821966854a7bc8975d23 (patch) | |
tree | a4531b783c122238f983936b6175d149f5cbc48c /source | |
parent | 5129e2e042a057a28ea75e4342a664277c74ca34 (diff) |
Cleanup: Refactor lookup for hovered Outliner element for renaming
* Use existing and optimized lookup function, rather than own duplicated logic.
* Move low-level coordinate check into general function, alongside similar
ones.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/space_outliner/outliner_edit.c | 26 | ||||
-rw-r--r-- | source/blender/editors/space_outliner/outliner_intern.h | 1 | ||||
-rw-r--r-- | source/blender/editors/space_outliner/outliner_utils.c | 6 |
3 files changed, 12 insertions, 21 deletions
diff --git a/source/blender/editors/space_outliner/outliner_edit.c b/source/blender/editors/space_outliner/outliner_edit.c index abfec4fc2aa..85e841538d6 100644 --- a/source/blender/editors/space_outliner/outliner_edit.c +++ b/source/blender/editors/space_outliner/outliner_edit.c @@ -363,25 +363,6 @@ void item_rename_fn(bContext *C, do_item_rename(region, te, tselem, reports); } -static void do_outliner_item_rename(ReportList *reports, - ARegion *region, - TreeElement *te, - const float mval[2]) -{ - if (mval[1] > te->ys && mval[1] < te->ys + UI_UNIT_Y) { - TreeStoreElem *tselem = TREESTORE(te); - - /* click on name */ - if (mval[0] > te->xs + UI_UNIT_X * 2 && mval[0] < te->xend) { - do_item_rename(region, te, tselem, reports); - } - } - - LISTBASE_FOREACH (TreeElement *, te_child, &te->subtree) { - do_outliner_item_rename(reports, region, te_child, mval); - } -} - static int outliner_item_rename(bContext *C, wmOperator *op, const wmEvent *event) { ARegion *region = CTX_wm_region(C); @@ -403,8 +384,11 @@ static int outliner_item_rename(bContext *C, wmOperator *op, const wmEvent *even else { UI_view2d_region_to_view(®ion->v2d, event->mval[0], event->mval[1], &fmval[0], &fmval[1]); - LISTBASE_FOREACH (TreeElement *, te, &space_outliner->tree) { - do_outliner_item_rename(op->reports, region, te, fmval); + TreeElement *hovered = outliner_find_item_at_y( + space_outliner, &space_outliner->tree, fmval[1]); + + if (outliner_item_is_co_over_name(hovered, fmval[0])) { + do_item_rename(region, hovered, TREESTORE(hovered), op->reports); } } diff --git a/source/blender/editors/space_outliner/outliner_intern.h b/source/blender/editors/space_outliner/outliner_intern.h index 2e0ea7a481a..382078f006b 100644 --- a/source/blender/editors/space_outliner/outliner_intern.h +++ b/source/blender/editors/space_outliner/outliner_intern.h @@ -286,6 +286,7 @@ void outliner_item_select(struct bContext *C, const short select_flag); bool outliner_item_is_co_over_name_icons(const TreeElement *te, float view_co_x); +bool outliner_item_is_co_over_name(const TreeElement *te, float view_co_x); bool outliner_item_is_co_within_close_toggle(const TreeElement *te, float view_co_x); bool outliner_is_co_within_mode_column(SpaceOutliner *space_outliner, const float view_mval[2]); diff --git a/source/blender/editors/space_outliner/outliner_utils.c b/source/blender/editors/space_outliner/outliner_utils.c index 907b9d372af..c1551b5c584 100644 --- a/source/blender/editors/space_outliner/outliner_utils.c +++ b/source/blender/editors/space_outliner/outliner_utils.c @@ -429,6 +429,12 @@ bool outliner_item_is_co_over_name_icons(const TreeElement *te, float view_co_x) return outside_left && (view_co_x < te->xend); } +/* Find if x coordinate is over element name. */ +bool outliner_item_is_co_over_name(const TreeElement *te, float view_co_x) +{ + return (view_co_x > (te->xs + UI_UNIT_X * 2)) && (view_co_x < te->xend); +} + /* Find if x coordinate is over element disclosure toggle */ bool outliner_item_is_co_within_close_toggle(const TreeElement *te, float view_co_x) { |