UI: Add an outer boundary for edge panning, use in outliner

Currently if you drag and drop an item from the outliner elsewhere in
the Blender window, the outliner will scroll the entire time, even if the
mouse is far away. This commit adds optional behavior for the edge pan
operator that makes it only act if the mouse is close enough to the region.

Differential Revision: https://developer.blender.org/D8193
This commit is contained in:
Hans Goudey 2020-07-21 10:12:35 -04:00
parent 696c23f284
commit c2b0c64843
4 changed files with 54 additions and 14 deletions

View File

@ -63,6 +63,7 @@ void BLI_rcti_translate(struct rcti *rect, int x, int y);
void BLI_rcti_recenter(struct rcti *rect, int x, int y);
void BLI_rctf_recenter(struct rctf *rect, float x, float y);
void BLI_rcti_resize(struct rcti *rect, int x, int y);
void BLI_rcti_pad(struct rcti *rect, int pad_x, int pad_y);
void BLI_rctf_resize(struct rctf *rect, float x, float y);
void BLI_rcti_scale(rcti *rect, const float scale);
void BLI_rctf_scale(rctf *rect, const float scale);

View File

@ -635,6 +635,14 @@ void BLI_rcti_resize(rcti *rect, int x, int y)
rect->ymax = rect->ymin + y;
}
void BLI_rcti_pad(rcti *rect, int pad_x, int pad_y)
{
rect->xmin -= pad_x;
rect->ymin -= pad_y;
rect->xmax += pad_x;
rect->ymax += pad_y;
}
void BLI_rctf_resize(rctf *rect, float x, float y)
{
rect->xmin = BLI_rctf_cent_x(rect) - (x * 0.5f);

View File

@ -475,20 +475,29 @@ static int view_edge_pan_modal(bContext *C, wmOperator *op, const wmEvent *event
* On successful handling, always pass events on to other handlers. */
const int success_retval = OPERATOR_PASS_THROUGH;
/* Find whether the mouse is beyond X and Y edges. */
int outside_padding = RNA_int_get(op->ptr, "outside_padding") * UI_UNIT_X;
rcti padding_rect;
if (outside_padding != 0) {
padding_rect = region->winrct;
BLI_rcti_pad(&padding_rect, outside_padding, outside_padding);
}
int pan_dir_x = 0;
int pan_dir_y = 0;
if (event->x > region->winrct.xmax - EDGE_PAN_REGION_PAD) {
pan_dir_x = 1;
}
else if (event->x < region->winrct.xmin + EDGE_PAN_REGION_PAD) {
pan_dir_x = -1;
}
if (event->y > region->winrct.ymax - EDGE_PAN_REGION_PAD) {
pan_dir_y = 1;
}
else if (event->y < region->winrct.ymin + EDGE_PAN_REGION_PAD) {
pan_dir_y = -1;
if ((outside_padding == 0) || BLI_rcti_isect_pt(&padding_rect, event->x, event->y)) {
/* Find whether the mouse is beyond X and Y edges. */
if (event->x > region->winrct.xmax - EDGE_PAN_REGION_PAD) {
pan_dir_x = 1;
}
else if (event->x < region->winrct.xmin + EDGE_PAN_REGION_PAD) {
pan_dir_x = -1;
}
if (event->y > region->winrct.ymax - EDGE_PAN_REGION_PAD) {
pan_dir_y = 1;
}
else if (event->y < region->winrct.ymin + EDGE_PAN_REGION_PAD) {
pan_dir_y = -1;
}
}
const double current_time = PIL_check_seconds_timer();
@ -532,6 +541,16 @@ static void VIEW2D_OT_edge_pan(wmOperatorType *ot)
/* operator is modal */
ot->flag = OPTYPE_INTERNAL;
RNA_def_int(ot->srna,
"outside_padding",
0,
0,
100,
"Outside Padding",
"Padding around the region in UI units within which panning is activated (0 to "
"disable boundary)",
0,
100);
}
#undef EDGE_PAN_REGION_PAD

View File

@ -858,6 +858,8 @@ void OUTLINER_OT_collection_drop(wmOperatorType *ot)
/* ********************* Outliner Drag Operator ******************** */
#define OUTLINER_DRAG_SCOLL_OUTSIDE_PAD 7 /* In UI units */
static TreeElement *outliner_item_drag_element_find(SpaceOutliner *soops,
ARegion *region,
const wmEvent *event)
@ -892,8 +894,16 @@ static int outliner_item_drag_drop_invoke(bContext *C,
return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH);
}
/* Scroll view when dragging near edges */
WM_operator_name_call(C, "VIEW2D_OT_edge_pan", WM_OP_INVOKE_DEFAULT, NULL);
/* Scroll the view when dragging near edges, but not
* when the drag goes too far outside the region. */
{
wmOperatorType *ot = WM_operatortype_find("VIEW2D_OT_edge_pan", true);
PointerRNA op_ptr;
WM_operator_properties_create_ptr(&op_ptr, ot);
RNA_int_set(&op_ptr, "outside_padding", OUTLINER_DRAG_SCOLL_OUTSIDE_PAD);
WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &op_ptr);
WM_operator_properties_free(&op_ptr);
}
wmDrag *drag = WM_event_start_drag(C, data.icon, WM_DRAG_ID, NULL, 0.0, WM_DRAG_NOP);
@ -993,6 +1003,8 @@ void OUTLINER_OT_item_drag_drop(wmOperatorType *ot)
ot->poll = ED_operator_outliner_active;
}
#undef OUTLINER_DRAG_SCOLL_OUTSIDE_PAD
/* *************************** Drop Boxes ************************** */
/* region dropbox definition */