diff options
-rw-r--r-- | source/blender/editors/interface/view2d_ops.c | 48 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_draw.c | 17 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_view.c | 4 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_node_types.h | 4 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_view2d_types.h | 1 |
5 files changed, 66 insertions, 8 deletions
diff --git a/source/blender/editors/interface/view2d_ops.c b/source/blender/editors/interface/view2d_ops.c index 5b5ccc0582c..71367bb7df4 100644 --- a/source/blender/editors/interface/view2d_ops.c +++ b/source/blender/editors/interface/view2d_ops.c @@ -1186,6 +1186,44 @@ struct SmoothView2DStore { double time_allowed; }; +/** + * function to get a factor out of a rectangle + * + * note: this doesn't always work as well as it might because the target size + * may not be reached because of clamping the desired rect, we _could_ + * attempt to clamp the rect before working out the zoom factor but its + * not really worthwhile for the few cases this happens. + */ +static float smooth_view_rect_to_fac(const rctf *rect_a, const rctf *rect_b) +{ + float size_a[2] = {rect_a->xmax - rect_a->xmin, + rect_a->ymax - rect_a->ymin}; + float size_b[2] = {rect_b->xmax - rect_b->xmin, + rect_b->ymax - rect_b->ymin}; + float cent_a[2] = {(rect_a->xmax + rect_a->xmin) * 0.5f, + (rect_a->ymax + rect_a->ymin) * 0.5f}; + float cent_b[2] = {(rect_b->xmax + rect_b->xmin) * 0.5f, + (rect_b->ymax + rect_b->ymin) * 0.5f}; + + float fac_max = 0.0f; + float tfac; + + int i; + + for (i = 0; i < 2; i++) { + /* axis translation normalized to scale */ + tfac = fabsf(cent_a[i] - cent_b[i]) / fmin(size_a[i], size_b[i]); + fac_max = fmax(fac_max, tfac); + if (fac_max >= 1.0f) break; + + /* axis scale difference, x2 so doubling or half gives 1.0f */ + tfac = (1.0f - (fmin(size_a[i], size_b[i]) / fmax(size_a[i], size_b[i]))) * 2.0f; + fac_max = fmax(fac_max, tfac); + if (fac_max >= 1.0f) break; + } + return fmin(fac_max, 1.0f); +} + /* will start timer if appropriate */ /* the arguments are the desired situation */ void UI_view2d_smooth_view(bContext *C, ARegion *ar, @@ -1197,6 +1235,7 @@ void UI_view2d_smooth_view(bContext *C, ARegion *ar, View2D *v2d = &ar->v2d; struct SmoothView2DStore sms = {{0}}; short ok = FALSE; + float fac = 1.0f; /* initialize sms */ sms.new_cur = v2d->cur; @@ -1204,7 +1243,11 @@ void UI_view2d_smooth_view(bContext *C, ARegion *ar, /* store the options we want to end with */ if (cur) sms.new_cur = *cur; - if (C && U.smooth_viewtx) { + if (cur) { + fac = smooth_view_rect_to_fac(&v2d->cur, cur); + } + + if (C && U.smooth_viewtx && fac > FLT_EPSILON) { int changed = 0; /* zero means no difference */ if (BLI_rctf_compare(&sms.new_cur, &v2d->cur, FLT_EPSILON) == FALSE) @@ -1218,6 +1261,9 @@ void UI_view2d_smooth_view(bContext *C, ARegion *ar, sms.time_allowed = (double)U.smooth_viewtx / 1000.0; + /* scale the time allowed the change in view */ + sms.time_allowed *= (double)fac; + /* keep track of running timer! */ if (v2d->sms == NULL) v2d->sms = MEM_mallocN(sizeof(struct SmoothView2DStore), "smoothview v2d"); diff --git a/source/blender/editors/space_node/node_draw.c b/source/blender/editors/space_node/node_draw.c index 07b1faecaef..1a4c302124f 100644 --- a/source/blender/editors/space_node/node_draw.c +++ b/source/blender/editors/space_node/node_draw.c @@ -1039,6 +1039,8 @@ static void node_draw(const bContext *C, ARegion *ar, SpaceNode *snode, bNodeTre node->typeinfo->drawfunc(C, ar, snode, ntree, node); } +#define USE_DRAW_TOT_UPDATE + void node_draw_nodetree(const bContext *C, ARegion *ar, SpaceNode *snode, bNodeTree *ntree) { bNode *node; @@ -1046,9 +1048,22 @@ void node_draw_nodetree(const bContext *C, ARegion *ar, SpaceNode *snode, bNodeT int a; if (ntree == NULL) return; /* groups... */ - + +#ifdef USE_DRAW_TOT_UPDATE + if (ntree->nodes.first) { + BLI_rctf_init_minmax(&ar->v2d.tot); + } +#endif + /* draw background nodes, last nodes in front */ for (a = 0, node = ntree->nodes.first; node; node = node->next, a++) { + +#ifdef USE_DRAW_TOT_UPDATE + /* unrelated to background nodes, update the v2d->tot, + * can be anywhere before we draw the scroll bars */ + BLI_rctf_union(&ar->v2d.tot, &node->totr); +#endif + if (!(node->flag & NODE_BACKGROUND)) continue; node->nr = a; /* index of node in list, used for exec event code */ diff --git a/source/blender/editors/space_node/node_view.c b/source/blender/editors/space_node/node_view.c index 0566611dc0e..4be51a02137 100644 --- a/source/blender/editors/space_node/node_view.c +++ b/source/blender/editors/space_node/node_view.c @@ -136,8 +136,6 @@ static int node_view_all_exec(bContext *C, wmOperator *UNUSED(op)) snode->yof = 0; if (space_node_view_flag(C, snode, ar, 0)) { - ED_region_tag_redraw(ar); - return OPERATOR_FINISHED; } else { @@ -166,8 +164,6 @@ static int node_view_selected_exec(bContext *C, wmOperator *UNUSED(op)) SpaceNode *snode = CTX_wm_space_node(C); if (space_node_view_flag(C, snode, ar, NODE_SELECT)) { - ED_region_tag_redraw(ar); - return OPERATOR_FINISHED; } else { diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h index d0c2a5c9925..3f439454a97 100644 --- a/source/blender/makesdna/DNA_node_types.h +++ b/source/blender/makesdna/DNA_node_types.h @@ -168,7 +168,7 @@ typedef struct bNode { void *storage; /* custom data, must be struct, for storage in file */ struct bNode *original; /* the original node in the tree (for localized tree) */ - float locx, locy; /* root offset for drawing */ + float locx, locy; /* root offset for drawing (parent space) */ float width, height; /* node custom width and height */ float miniwidth; /* node width if hidden */ float offsetx, offsety; /* additional offset from loc */ @@ -181,7 +181,7 @@ typedef struct bNode { short need_exec, exec; /* need_exec is set as UI execution event, exec is flag during exec */ void *threaddata; /* optional extra storage for use in thread (read only then!) */ - rctf totr; /* entire boundbox */ + rctf totr; /* entire boundbox (worldspace) */ rctf butr; /* optional buttons area */ rctf prvr; /* optional preview area */ bNodePreview *preview; /* optional preview image */ diff --git a/source/blender/makesdna/DNA_view2d_types.h b/source/blender/makesdna/DNA_view2d_types.h index ab533b2859b..a3f4b362672 100644 --- a/source/blender/makesdna/DNA_view2d_types.h +++ b/source/blender/makesdna/DNA_view2d_types.h @@ -104,6 +104,7 @@ typedef struct View2D { /* general refresh settings (v2d->flag) */ /* global view2d horizontal locking (for showing same time interval) */ + /* TODO: this flag may be set in old files but is not accessible currently, should be exposed from RNA - Campbell */ #define V2D_VIEWSYNC_SCREEN_TIME (1<<0) /* within area (i.e. between regions) view2d vertical locking */ #define V2D_VIEWSYNC_AREA_VERTICAL (1<<1) |