diff options
author | Lukas Tönne <lukas.toenne@gmail.com> | 2021-08-24 19:45:40 +0300 |
---|---|---|
committer | Lukas Tönne <lukas.toenne@gmail.com> | 2021-08-24 20:00:05 +0300 |
commit | 19da434e9cc020a88d71d7e8a2e210fd79cab321 (patch) | |
tree | b5e8c3e615564271b86cb7d976345691370cd5f8 /source/blender/editors/transform | |
parent | 38bdde852f1c38a2eaba2b8efc15b49f226baffd (diff) |
Nodes: Improvements to edge panning in the node editor.
- New operator property to toggle edge panning in the keymap:
This is disabled by default to avoid edge-panning in cases where it
gets distracting, such as adding a new node. Only the explicit
translate operator(s) (GKEY or drag) have this enabled now.
- Restore the initial view rect on edge pan cancel:
The initial view rect is now stored in the edge pan operator data.
When an operator with edge panning is cancelled it can now call the
`UI_view2d_edge_pan_cancel` function to restore the original View2D
rect.
- Less delay in node editor scrolling:
Delay is useful when scrolling through long lists, such as in the
outliner, but makes node scrolling feel sluggish and unresponsive.
The lower scroll speed here makes a faster response the better option.
- Zoom influence feature:
Somewhat slower scrolling in UI-space when zoomed out. With the 0.5
zoom influence factor nodes behave as if zoom factor is halved,
otherwise it gets too fast when zoomed out. Previously scrolling would
always be constant-speed in UI space, now it's half-way between UI
space and node (view) space.
Diffstat (limited to 'source/blender/editors/transform')
5 files changed, 37 insertions, 23 deletions
diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 4069a72a8fc..7a83fb71c28 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -1671,6 +1671,13 @@ bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve } } + if ((prop = RNA_struct_find_property(op->ptr, "view2d_edge_pan")) && + RNA_property_is_set(op->ptr, prop)) { + if (RNA_property_boolean_get(op->ptr, prop)) { + options |= CTX_VIEW2D_EDGE_PAN; + } + } + t->options = options; t->mode = mode; diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h index 549ad770ac6..013c5faa54a 100644 --- a/source/blender/editors/transform/transform.h +++ b/source/blender/editors/transform/transform.h @@ -94,6 +94,8 @@ typedef enum { CTX_OBMODE_XFORM_OBDATA = (1 << 12), /** Transform object parents without moving their children. */ CTX_OBMODE_XFORM_SKIP_CHILDREN = (1 << 13), + /** Enable edge scrolling in 2D views */ + CTX_VIEW2D_EDGE_PAN = (1 << 14), } eTContext; /** #TransInfo.flag */ diff --git a/source/blender/editors/transform/transform_convert_node.c b/source/blender/editors/transform/transform_convert_node.c index 9d2d3713bf0..ecc7f01be33 100644 --- a/source/blender/editors/transform/transform_convert_node.c +++ b/source/blender/editors/transform/transform_convert_node.c @@ -46,12 +46,6 @@ /** \name Node Transform Creation * \{ */ -typedef struct NodeTransCustomData { - /* Initial rect of the view2d, used for computing offset during edge panning */ - rctf initial_v2d_cur; - View2DEdgePanData edge_pan; -} NodeTransCustomData; - /* transcribe given node into TransData2D for Transforming */ static void NodeToTransData(TransData *td, TransData2D *td2d, bNode *node, const float dpi_fac) { @@ -115,21 +109,16 @@ void createTransNodeData(TransInfo *t) const float dpi_fac = UI_DPI_FAC; SpaceNode *snode = t->area->spacedata.first; - if (t->mode == TFM_TRANSLATION) { - /* Disable cursor wrapping in the node editor for edge pan */ - t->flag |= T_NO_CURSOR_WRAP; - } - /* Custom data to enable edge panning during the node transform */ - NodeTransCustomData *customdata = MEM_callocN(sizeof(*customdata), __func__); + View2DEdgePanData *customdata = MEM_callocN(sizeof(*customdata), __func__); UI_view2d_edge_pan_init(t->context, - &customdata->edge_pan, + customdata, NODE_EDGE_PAN_INSIDE_PAD, NODE_EDGE_PAN_OUTSIDE_PAD, NODE_EDGE_PAN_SPEED_RAMP, NODE_EDGE_PAN_MAX_SPEED, - NODE_EDGE_PAN_DELAY); - customdata->initial_v2d_cur = t->region->v2d.cur; + NODE_EDGE_PAN_DELAY, + NODE_EDGE_PAN_ZOOM_INFLUENCE); t->custom.type.data = customdata; t->custom.type.use_free = true; @@ -176,17 +165,22 @@ void flushTransNodes(TransInfo *t) { const float dpi_fac = UI_DPI_FAC; - NodeTransCustomData *customdata = (NodeTransCustomData *)t->custom.type.data; + View2DEdgePanData *customdata = (View2DEdgePanData *)t->custom.type.data; - if (t->mode == TFM_TRANSLATION) { - /* Edge panning functions expect window coordinates, mval is relative to region */ - const float x = t->region->winrct.xmin + t->mval[0]; - const float y = t->region->winrct.ymin + t->mval[1]; - UI_view2d_edge_pan_apply(t->context, &customdata->edge_pan, x, y); + if (t->options & CTX_VIEW2D_EDGE_PAN) { + if (t->state == TRANS_CANCEL) { + UI_view2d_edge_pan_cancel(t->context, customdata); + } + else { + /* Edge panning functions expect window coordinates, mval is relative to region */ + const float x = t->region->winrct.xmin + t->mval[0]; + const float y = t->region->winrct.ymin + t->mval[1]; + UI_view2d_edge_pan_apply(t->context, customdata, x, y); + } } /* Initial and current view2D rects for additional transform due to view panning and zooming */ - const rctf *rect_src = &customdata->initial_v2d_cur; + const rctf *rect_src = &customdata->initial_rect; const rctf *rect_dst = &t->region->v2d.cur; FOREACH_TRANS_DATA_CONTAINER (t, tc) { diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c index 81fc1496b1a..9f5e74db501 100644 --- a/source/blender/editors/transform/transform_generics.c +++ b/source/blender/editors/transform/transform_generics.c @@ -625,6 +625,11 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve } #endif + /* Disable cursor wrap when edge panning is enabled. */ + if (t->options & CTX_VIEW2D_EDGE_PAN) { + t->flag |= T_NO_CURSOR_WRAP; + } + setTransformViewAspect(t, t->aspect); if (op && (prop = RNA_struct_find_property(op->ptr, "center_override")) && diff --git a/source/blender/editors/transform/transform_ops.c b/source/blender/editors/transform/transform_ops.c index 45c077b8a07..cbc2adf641f 100644 --- a/source/blender/editors/transform/transform_ops.c +++ b/source/blender/editors/transform/transform_ops.c @@ -709,6 +709,11 @@ void Transform_Properties(struct wmOperatorType *ot, int flags) RNA_def_property_ui_text(prop, "Center Override", "Force using this center value (when set)"); } + if (flags & P_VIEW2D_EDGE_PAN) { + prop = RNA_def_boolean(ot->srna, "view2d_edge_pan", false, "Edge Pan", "Enable edge panning in 2D view"); + RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); + } + if ((flags & P_NO_DEFAULTS) == 0) { prop = RNA_def_boolean(ot->srna, "release_confirm", @@ -754,7 +759,8 @@ static void TRANSFORM_OT_translate(struct wmOperatorType *ot) Transform_Properties(ot, P_ORIENT_MATRIX | P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_ALIGN_SNAP | - P_OPTIONS | P_GPENCIL_EDIT | P_CURSOR_EDIT | P_POST_TRANSFORM); + P_OPTIONS | P_GPENCIL_EDIT | P_CURSOR_EDIT | P_VIEW2D_EDGE_PAN | + P_POST_TRANSFORM); } static void TRANSFORM_OT_resize(struct wmOperatorType *ot) |