Fix T73049: Drag & drop on overlapping panels behaves incorrectly

Reviewers: brecht, Severin

Differential Revision: https://developer.blender.org/D7024
This commit is contained in:
Jacques Lucke 2020-03-12 19:34:59 +01:00
parent 11e4827738
commit 649fdc7938
Notes: blender-bot 2023-02-14 09:19:09 +01:00
Referenced by issue #73049, Drag&drop of an object into a panel in the 3D view duplicates the object
4 changed files with 47 additions and 15 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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)

View File

@ -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));