diff options
author | Julian Eisel <eiseljulian@gmail.com> | 2019-08-10 14:24:26 +0300 |
---|---|---|
committer | Julian Eisel <eiseljulian@gmail.com> | 2019-08-10 14:24:26 +0300 |
commit | b9898ebde44d6584ea37a05aaeca8760d31ccc7b (patch) | |
tree | e6dfc796cc82b4b8b8c248c4ff29d2e2047ff84c /source/blender/editors/interface/view2d_ops.c | |
parent | b17380971a144896b34b7863a82bbda3ff68a39f (diff) | |
parent | 553b581f25c1782c4231816965cd3f6ce58a449a (diff) |
Merge branch 'master' into filebrowser_redesign
Diffstat (limited to 'source/blender/editors/interface/view2d_ops.c')
-rw-r--r-- | source/blender/editors/interface/view2d_ops.c | 59 |
1 files changed, 44 insertions, 15 deletions
diff --git a/source/blender/editors/interface/view2d_ops.c b/source/blender/editors/interface/view2d_ops.c index 7d9b722fcc0..f32fcffabd4 100644 --- a/source/blender/editors/interface/view2d_ops.c +++ b/source/blender/editors/interface/view2d_ops.c @@ -31,6 +31,7 @@ #include "BLI_blenlib.h" #include "BLI_utildefines.h" #include "BLI_math_base.h" +#include "BLI_math_vector.h" #include "BKE_context.h" @@ -939,8 +940,8 @@ static void view_zoomdrag_apply(bContext *C, wmOperator *op) const bool zoom_to_pos = use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS); /* get amount to move view by */ - dx = RNA_float_get(op->ptr, "deltax"); - dy = RNA_float_get(op->ptr, "deltay"); + dx = RNA_float_get(op->ptr, "deltax") / U.pixelsize; + dy = RNA_float_get(op->ptr, "deltay") / U.pixelsize; if (U.uiflag & USER_ZOOM_INVERT) { dx *= -1; @@ -1146,33 +1147,49 @@ static int view_zoomdrag_modal(bContext *C, wmOperator *op, const wmEvent *event } else if (event->type == MOUSEMOVE) { float dx, dy; + float zoomfac = 0.01f; + + /* some view2d's (graph) don't have min/max zoom, or extreme ones */ + if (v2d->maxzoom > 0.0f) { + zoomfac = clamp_f(0.001f * v2d->maxzoom, 0.001f, 0.01f); + } /* calculate new delta transform, based on zooming mode */ if (U.viewzoom == USER_ZOOM_SCALE) { /* 'scale' zooming */ float dist; + float len_old[2]; + float len_new[2]; /* x-axis transform */ dist = BLI_rcti_size_x(&v2d->mask) / 2.0f; - dx = 1.0f - (fabsf(vzd->lastx - vzd->ar->winrct.xmin - dist) + 2.0f) / - (fabsf(event->mval[0] - dist) + 2.0f); - dx *= 0.5f * BLI_rctf_size_x(&v2d->cur); + len_old[0] = fabsf(vzd->lastx - vzd->ar->winrct.xmin - dist); + len_new[0] = fabsf(event->x - vzd->ar->winrct.xmin - dist); + + len_old[0] *= zoomfac * BLI_rctf_size_x(&v2d->cur); + len_new[0] *= zoomfac * BLI_rctf_size_x(&v2d->cur); /* y-axis transform */ dist = BLI_rcti_size_y(&v2d->mask) / 2.0f; - dy = 1.0f - (fabsf(vzd->lasty - vzd->ar->winrct.ymin - dist) + 2.0f) / - (fabsf(event->mval[1] - dist) + 2.0f); - dy *= 0.5f * BLI_rctf_size_y(&v2d->cur); + len_old[1] = fabsf(vzd->lasty - vzd->ar->winrct.ymin - dist); + len_new[1] = fabsf(event->y - vzd->ar->winrct.ymin - dist); + + len_old[1] *= zoomfac * BLI_rctf_size_y(&v2d->cur); + len_new[1] *= zoomfac * BLI_rctf_size_y(&v2d->cur); + + /* Calculate distance */ + if (v2d->keepzoom & V2D_KEEPASPECT) { + dist = len_v2(len_new) - len_v2(len_old); + dx = dy = dist; + } + else { + dx = len_new[0] - len_old[0]; + dy = len_new[1] - len_old[1]; + } } else { /* 'continuous' or 'dolly' */ - float fac, zoomfac = 0.01f; - - /* some view2d's (graph) don't have min/max zoom, or extreme ones */ - if (v2d->maxzoom > 0.0f) { - zoomfac = clamp_f(0.001f * v2d->maxzoom, 0.001f, 0.01f); - } - + float fac; /* x-axis transform */ fac = zoomfac * (event->x - vzd->lastx); dx = fac * BLI_rctf_size_x(&v2d->cur); @@ -1180,6 +1197,18 @@ static int view_zoomdrag_modal(bContext *C, wmOperator *op, const wmEvent *event /* y-axis transform */ fac = zoomfac * (event->y - vzd->lasty); dy = fac * BLI_rctf_size_y(&v2d->cur); + + /* Only respect user setting zoom axis if the view does not have any zoom restrictions + * any will be scaled uniformly */ + if ((v2d->keepzoom & V2D_LOCKZOOM_X) == 0 && (v2d->keepzoom & V2D_LOCKZOOM_Y) == 0 && + (v2d->keepzoom & V2D_KEEPASPECT)) { + if (U.uiflag & USER_ZOOM_HORIZ) { + dy = 0; + } + else { + dx = 0; + } + } } /* support zoom to always zoom entirely - the v2d code uses portrait or |