diff options
author | Lukas Tönne <lukas.toenne@gmail.com> | 2021-06-16 20:17:07 +0300 |
---|---|---|
committer | Lukas Tönne <lukas.toenne@gmail.com> | 2021-06-16 20:35:52 +0300 |
commit | a1cc7042a745b4bfd882367cf4c4653467c1e430 (patch) | |
tree | bbaf8eaf3d60d9f5630096df67ff2873c7651033 /source/blender/editors/include/UI_view2d.h | |
parent | 247abdbf4148843daf469285a6a63ab9cd0aeef9 (diff) |
Edge-scrolling for node editor
Starts scrolling when dragging a node or node link and going outside the current window.
Largely copied from the VIEW2D_OT_edge_pan operator.
Edge panning operator customdata and supporting functions now in
UI_view2d.h, so they could be used by operators in other editor
libraries. The VIEW2D_OT_edge_pan operator also uses this customdata and
shared functions now. Operators properties can be used to configure
edge panning margins and speed for each use case, rather than using
hardcoded values.
The speed function for edge panning has been tweaked somewhat:
* "Speed per pixel" has been replaced with a "speed ramp" distance.
This is more intuitive and also creates an upper bound for the speed,
which can otherwise become extreme with large cursor distance.
* "Max speed" is reached at the end of the speed ramp.
* Padding the region inside and outside is applied as before, but both
values are operator properties now.
Node transform operator also supports edge panning. This requires
an offset for changes in the view2d rect, otherwise nodes are "stuck"
to the original view.
Transform operator had cursor wrapping categorically enabled, but this
gets quite confusing with the edge scrolling mechanism. A new TransInfo
option T_NO_CURSOR_WRAP has been introduced to disable this behavior.
The double negative is a bit annoying, but want to avoid affecting the
existing transform modes, so by default it should still set the
OP_IS_MODAL_GRAB_CURSOR flag (which then sets the WM_CURSOR_WRAP_XY
flag during modal execution).
Reviewed By: HooglyBoogly, JacquesLucke
Differential Revision: https://developer.blender.org/D11073
Diffstat (limited to 'source/blender/editors/include/UI_view2d.h')
-rw-r--r-- | source/blender/editors/include/UI_view2d.h | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/source/blender/editors/include/UI_view2d.h b/source/blender/editors/include/UI_view2d.h index 64f881052a1..999f42efe65 100644 --- a/source/blender/editors/include/UI_view2d.h +++ b/source/blender/editors/include/UI_view2d.h @@ -105,8 +105,12 @@ struct ScrArea; struct bContext; struct bScreen; struct rctf; +struct rcti; +struct wmEvent; struct wmGizmoGroupType; struct wmKeyConfig; +struct wmOperator; +struct wmOperatorType; typedef struct View2DScrollers View2DScrollers; @@ -287,6 +291,77 @@ void UI_view2d_smooth_view(struct bContext *C, /* Caller passes in own idname. */ void VIEW2D_GGT_navigate_impl(struct wmGizmoGroupType *gzgt, const char *idname); +/* Edge pan */ + +/** + * Custom-data for view panning operators. + */ +typedef struct View2DEdgePanData { + /** Screen where view pan was initiated. */ + struct bScreen *screen; + /** Area where view pan was initiated. */ + struct ScrArea *area; + /** Region where view pan was initiated. */ + struct ARegion *region; + /** View2d we're operating in. */ + struct View2D *v2d; + + /** Inside distance in UI units from the edge of the region within which to start panning. */ + float inside_pad; + /** Outside distance in UI units from the edge of the region at which to stop panning. */ + float outside_pad; + /** + * Width of the zone in UI units where speed increases with distance from the edge. + * At the end of this zone max speed is reached. + */ + float speed_ramp; + /** Maximum speed in UI units per second. */ + float max_speed; + /** Delay in seconds before maximum speed is reached. */ + float delay; + + /** Amount to move view relative to zoom. */ + float facx, facy; + + /* Timers. */ + double edge_pan_last_time; + double edge_pan_start_time_x, edge_pan_start_time_y; +} View2DEdgePanData; + +bool UI_view2d_edge_pan_poll(struct bContext *C); + +void UI_view2d_edge_pan_init(struct bContext *C, + struct View2DEdgePanData *vpd, + float inside_pad, + float outside_pad, + float speed_ramp, + float max_speed, + float delay); + +void UI_view2d_edge_pan_reset(struct View2DEdgePanData *vpd); + +/* Apply transform to view (i.e. adjust 'cur' rect). */ +void UI_view2d_edge_pan_apply(struct bContext *C, struct View2DEdgePanData *vpd, int x, int y); + +/* Apply transform to view using mouse events. */ +void UI_view2d_edge_pan_apply_event(struct bContext *C, + struct View2DEdgePanData *vpd, + const struct wmEvent *event); + +void UI_view2d_edge_pan_operator_properties(struct wmOperatorType *ot); + +void UI_view2d_edge_pan_operator_properties_ex(struct wmOperatorType *ot, + float inside_pad, + float outside_pad, + float speed_ramp, + float max_speed, + float delay); + +/* Initialize panning data with operator settings. */ +void UI_view2d_edge_pan_operator_init(struct bContext *C, + struct View2DEdgePanData *vpd, + struct wmOperator *op); + #ifdef __cplusplus } #endif |