diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-08-12 23:35:47 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-08-12 23:35:47 +0400 |
commit | c140ccb9fd3bdf4659ab9159705e868f36817566 (patch) | |
tree | ee08bc73e984592a235b496d6733f0594355f565 /source/blender/editors | |
parent | 38541284c5eb48eea7530f01e0a111fc80c2c078 (diff) |
2d smoothview now scales back the time to move for smaller view zoom/panning.
also the compositor bounds (used for scroll bars), were only calculated when pressing the home key in 2.63, how this is updated on draw
Diffstat (limited to 'source/blender/editors')
-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 |
3 files changed, 63 insertions, 6 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 { |