From 649fdc793851a214f54c9ecdaae4c120c4bd11c9 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Thu, 12 Mar 2020 19:34:59 +0100 Subject: Fix T73049: Drag & drop on overlapping panels behaves incorrectly Reviewers: brecht, Severin Differential Revision: https://developer.blender.org/D7024 --- source/blender/editors/include/ED_screen.h | 1 + source/blender/editors/screen/area_query.c | 12 +++++++ source/blender/editors/space_image/space_image.c | 12 ++++--- source/blender/editors/space_view3d/space_view3d.c | 37 +++++++++++++++------- 4 files changed, 47 insertions(+), 15 deletions(-) diff --git a/source/blender/editors/include/ED_screen.h b/source/blender/editors/include/ED_screen.h index 1dd40f27fbb..0785b0e97f7 100644 --- a/source/blender/editors/include/ED_screen.h +++ b/source/blender/editors/include/ED_screen.h @@ -431,6 +431,7 @@ int ED_region_generic_tools_region_snap_size(const struct ARegion *region, int s bool ED_region_overlap_isect_x(const ARegion *region, const int event_x); bool ED_region_overlap_isect_y(const ARegion *region, const int event_y); bool ED_region_overlap_isect_xy(const ARegion *region, const int event_xy[2]); +bool ED_region_overlap_isect_any_xy(const ScrArea *area, const int event_xy[2]); bool ED_region_overlap_isect_x_with_margin(const ARegion *region, const int event_x, const int margin); diff --git a/source/blender/editors/screen/area_query.c b/source/blender/editors/screen/area_query.c index f8a6b301911..2cccd9a2ba5 100644 --- a/source/blender/editors/screen/area_query.c +++ b/source/blender/editors/screen/area_query.c @@ -61,6 +61,18 @@ bool ED_region_overlap_isect_xy(const ARegion *region, const int event_xy[2]) ED_region_overlap_isect_y(region, event_xy[1])); } +bool ED_region_overlap_isect_any_xy(const ScrArea *area, const int event_xy[2]) +{ + LISTBASE_FOREACH (ARegion *, region, &area->regionbase) { + if (ED_region_is_overlap(area->spacetype, region->regiontype)) { + if (ED_region_overlap_isect_xy(region, event_xy)) { + return true; + } + } + } + return false; +} + bool ED_region_panel_category_gutter_calc_rect(const ARegion *region, rcti *r_ar_gutter) { *r_ar_gutter = region->winrct; diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c index dc546e5baf5..42a8a746eef 100644 --- a/source/blender/editors/space_image/space_image.c +++ b/source/blender/editors/space_image/space_image.c @@ -262,18 +262,22 @@ static void image_keymap(struct wmKeyConfig *keyconf) } /* dropboxes */ -static bool image_drop_poll(bContext *UNUSED(C), +static bool image_drop_poll(bContext *C, wmDrag *drag, - const wmEvent *UNUSED(event), + const wmEvent *event, const char **UNUSED(tooltip)) { + ScrArea *area = CTX_wm_area(C); + if (ED_region_overlap_isect_any_xy(area, &event->x)) { + return false; + } if (drag->type == WM_DRAG_PATH) { /* rule might not work? */ if (ELEM(drag->icon, 0, ICON_FILE_IMAGE, ICON_FILE_MOVIE, ICON_FILE_BLANK)) { - return 1; + return true; } } - return 0; + return false; } static void image_drop_copy(wmDrag *drag, wmDropBox *drop) diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c index 8ec7d5a166b..020c58270fc 100644 --- a/source/blender/editors/space_view3d/space_view3d.c +++ b/source/blender/editors/space_view3d/space_view3d.c @@ -436,35 +436,50 @@ static void view3d_main_region_exit(wmWindowManager *wm, ARegion *region) ED_view3d_stop_render_preview(wm, region); } -static bool view3d_ob_drop_poll(bContext *UNUSED(C), +static bool view3d_drop_id_in_main_region_poll(bContext *C, + wmDrag *drag, + const wmEvent *event, + ID_Type id_type) +{ + ScrArea *area = CTX_wm_area(C); + if (ED_region_overlap_isect_any_xy(area, &event->x)) { + return false; + } + return WM_drag_ID(drag, id_type) != NULL; +} + +static bool view3d_ob_drop_poll(bContext *C, wmDrag *drag, - const wmEvent *UNUSED(event), + const wmEvent *event, const char **UNUSED(tooltip)) { - return WM_drag_ID(drag, ID_OB) != NULL; + return view3d_drop_id_in_main_region_poll(C, drag, event, ID_OB); } -static bool view3d_collection_drop_poll(bContext *UNUSED(C), +static bool view3d_collection_drop_poll(bContext *C, wmDrag *drag, - const wmEvent *UNUSED(event), + const wmEvent *event, const char **UNUSED(tooltip)) { - return WM_drag_ID(drag, ID_GR) != NULL; + return view3d_drop_id_in_main_region_poll(C, drag, event, ID_GR); } -static bool view3d_mat_drop_poll(bContext *UNUSED(C), +static bool view3d_mat_drop_poll(bContext *C, wmDrag *drag, - const wmEvent *UNUSED(event), + const wmEvent *event, const char **UNUSED(tooltip)) { - return WM_drag_ID(drag, ID_MA) != NULL; + return view3d_drop_id_in_main_region_poll(C, drag, event, ID_MA); } -static bool view3d_ima_drop_poll(bContext *UNUSED(C), +static bool view3d_ima_drop_poll(bContext *C, wmDrag *drag, - const wmEvent *UNUSED(event), + const wmEvent *event, const char **UNUSED(tooltip)) { + if (ED_region_overlap_isect_any_xy(CTX_wm_area(C), &event->x)) { + return false; + } if (drag->type == WM_DRAG_PATH) { /* rule might not work? */ return (ELEM(drag->icon, 0, ICON_FILE_IMAGE, ICON_FILE_MOVIE)); -- cgit v1.2.3