diff options
author | Julian Eisel <julian@blender.org> | 2021-11-04 16:50:48 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2021-11-04 16:50:48 +0300 |
commit | 8eff1eca52f2be8df077811a4c16e49b5e799a1e (patch) | |
tree | 9765f189364988ce63d497763134e8f53f709363 /source/blender/editors | |
parent | c641107c9580d684d78898bb676ec5dddcad17f5 (diff) | |
parent | be4478d1f8b6c75b50c951f02cf0116f78e68d6d (diff) |
Merge remote-tracking branch 'origin/blender-v3.0-release'
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/include/ED_screen.h | 1 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_dropboxes.cc | 8 | ||||
-rw-r--r-- | source/blender/editors/screen/area_query.c | 45 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_relationships.cc | 32 |
4 files changed, 78 insertions, 8 deletions
diff --git a/source/blender/editors/include/ED_screen.h b/source/blender/editors/include/ED_screen.h index 08b6c02a8d0..ef3ff7874df 100644 --- a/source/blender/editors/include/ED_screen.h +++ b/source/blender/editors/include/ED_screen.h @@ -439,6 +439,7 @@ bool ED_region_panel_category_gutter_calc_rect(const ARegion *region, rcti *r_re bool ED_region_panel_category_gutter_isect_xy(const ARegion *region, const int event_xy[2]); bool ED_region_contains_xy(const struct ARegion *region, const int event_xy[2]); +ARegion *ED_area_find_region_xy_visual(const ScrArea *area, int regiontype, const int event_xy[2]); /* interface_region_hud.c */ struct ARegionType *ED_area_type_hud(int space_type); diff --git a/source/blender/editors/interface/interface_dropboxes.cc b/source/blender/editors/interface/interface_dropboxes.cc index 81a1354cbe7..369efa7c52e 100644 --- a/source/blender/editors/interface/interface_dropboxes.cc +++ b/source/blender/editors/interface/interface_dropboxes.cc @@ -39,12 +39,12 @@ static bool ui_tree_view_drop_poll(bContext *C, wmDrag *drag, const wmEvent *eve return false; } - if (drag->free_disabled_info) { - MEM_SAFE_FREE(drag->disabled_info); + if (drag->drop_state.free_disabled_info) { + MEM_SAFE_FREE(drag->drop_state.disabled_info); } - drag->free_disabled_info = false; - return UI_tree_view_item_can_drop(hovered_tree_item, drag, &drag->disabled_info); + drag->drop_state.free_disabled_info = false; + return UI_tree_view_item_can_drop(hovered_tree_item, drag, &drag->drop_state.disabled_info); } static char *ui_tree_view_drop_tooltip(bContext *C, diff --git a/source/blender/editors/screen/area_query.c b/source/blender/editors/screen/area_query.c index fd4f3964398..30e744ca174 100644 --- a/source/blender/editors/screen/area_query.c +++ b/source/blender/editors/screen/area_query.c @@ -140,6 +140,10 @@ bool ED_region_overlap_isect_xy_with_margin(const ARegion *region, ED_region_overlap_isect_y_with_margin(region, event_xy[1], margin)); } +/** + * \note: This may return true for multiple overlapping regions. If it matters, check overlapped + * regions first (#ARegion.overlap). + */ bool ED_region_contains_xy(const ARegion *region, const int event_xy[2]) { /* Only use the margin when inside the region. */ @@ -188,3 +192,44 @@ bool ED_region_contains_xy(const ARegion *region, const int event_xy[2]) } return false; } + +/** + * Similar to #BKE_area_find_region_xy() but when \a event_xy intersects an overlapping region, + * this returns the region that is visually under the cursor. E.g. when over the + * transparent part of the region, it returns the region underneath. + * + * The overlapping region is determined using the #ED_region_contains_xy() query. + */ +ARegion *ED_area_find_region_xy_visual(const ScrArea *area, + const int regiontype, + const int event_xy[2]) +{ + if (!area) { + return NULL; + } + + /* Check overlapped regions first. */ + LISTBASE_FOREACH (ARegion *, region, &area->regionbase) { + if (!region->overlap) { + continue; + } + if (ELEM(regiontype, RGN_TYPE_ANY, region->regiontype)) { + if (ED_region_contains_xy(region, event_xy)) { + return region; + } + } + } + /* Now non-overlapping ones. */ + LISTBASE_FOREACH (ARegion *, region, &area->regionbase) { + if (region->overlap) { + continue; + } + if (ELEM(regiontype, RGN_TYPE_ANY, region->regiontype)) { + if (ED_region_contains_xy(region, event_xy)) { + return region; + } + } + } + + return NULL; +} diff --git a/source/blender/editors/space_node/node_relationships.cc b/source/blender/editors/space_node/node_relationships.cc index 76aad684b4c..55b547d3195 100644 --- a/source/blender/editors/space_node/node_relationships.cc +++ b/source/blender/editors/space_node/node_relationships.cc @@ -57,6 +57,7 @@ #include "BLT_translation.h" +#include "NOD_node_declaration.hh" #include "NOD_node_tree_ref.hh" #include "node_intern.h" /* own include */ @@ -2182,9 +2183,32 @@ static int get_main_socket_priority(const bNodeSocket *socket) return -1; } -/** Get the "main" socket of a socket list using a heuristic based on socket types. */ -static bNodeSocket *get_main_socket(ListBase *sockets) +/** Get the "main" socket based on the node declaration or an heuristic. */ +static bNodeSocket *get_main_socket(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) { + using namespace blender; + using namespace blender::nodes; + + ListBase *sockets = (in_out == SOCK_IN) ? &node.inputs : &node.outputs; + + /* Try to get the main socket based on the socket declaration. */ + nodeDeclarationEnsure(&ntree, &node); + const NodeDeclaration *node_decl = node.declaration; + if (node_decl != nullptr) { + Span<SocketDeclarationPtr> socket_decls = (in_out == SOCK_IN) ? node_decl->inputs() : + node_decl->outputs(); + int index; + LISTBASE_FOREACH_INDEX (bNodeSocket *, socket, sockets, index) { + const SocketDeclaration &socket_decl = *socket_decls[index]; + if (nodeSocketIsHidden(socket)) { + continue; + } + if (socket_decl.is_default_link_socket()) { + return socket; + } + } + } + /* find priority range */ int maxpriority = -1; LISTBASE_FOREACH (bNodeSocket *, sock, sockets) { @@ -2561,8 +2585,8 @@ void ED_node_link_insert(Main *bmain, ScrArea *area) } if (link) { - bNodeSocket *best_input = get_main_socket(&select->inputs); - bNodeSocket *best_output = get_main_socket(&select->outputs); + bNodeSocket *best_input = get_main_socket(*snode->edittree, *select, SOCK_IN); + bNodeSocket *best_output = get_main_socket(*snode->edittree, *select, SOCK_OUT); if (best_input && best_output) { bNode *node = link->tonode; |