diff options
author | Hans Goudey <h.goudey@me.com> | 2020-07-21 17:12:35 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2020-07-21 17:12:35 +0300 |
commit | c2b0c64843084b6e4189d289fd2d201257fd9448 (patch) | |
tree | dec8ce388fe4afeae9735fe5824e0ad12dcbfe0a /source/blender | |
parent | 696c23f284b8af2164d8d239e680301523badec1 (diff) |
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
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenlib/BLI_rect.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/intern/rct.c | 8 | ||||
-rw-r--r-- | source/blender/editors/interface/view2d_ops.c | 43 | ||||
-rw-r--r-- | source/blender/editors/space_outliner/outliner_dragdrop.c | 16 |
4 files changed, 54 insertions, 14 deletions
diff --git a/source/blender/blenlib/BLI_rect.h b/source/blender/blenlib/BLI_rect.h index b1faae03583..14d18308ed6 100644 --- a/source/blender/blenlib/BLI_rect.h +++ b/source/blender/blenlib/BLI_rect.h @@ -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); diff --git a/source/blender/blenlib/intern/rct.c b/source/blender/blenlib/intern/rct.c index ad8443683f8..bf3c8730b01 100644 --- a/source/blender/blenlib/intern/rct.c +++ b/source/blender/blenlib/intern/rct.c @@ -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); diff --git a/source/blender/editors/interface/view2d_ops.c b/source/blender/editors/interface/view2d_ops.c index c37a7279773..64cacd44e3d 100644 --- a/source/blender/editors/interface/view2d_ops.c +++ b/source/blender/editors/interface/view2d_ops.c @@ -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 diff --git a/source/blender/editors/space_outliner/outliner_dragdrop.c b/source/blender/editors/space_outliner/outliner_dragdrop.c index 09d7f889bde..5baaef958fa 100644 --- a/source/blender/editors/space_outliner/outliner_dragdrop.c +++ b/source/blender/editors/space_outliner/outliner_dragdrop.c @@ -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 */ |