Fix T65837: "Zoom Axis" is not working on the node editor
We would not take into account the user "Zoom Axis" setting in certain 2D space viewports. In addition to this, the "Scale Zoom" didn't work consistently in these spaces either. Reviewed By: Brecht Differential Revision: http://developer.blender.org/D5132
This commit is contained in:
parent
0516d49d0c
commit
bcda8cc89b
Notes:
blender-bot
2023-02-14 02:11:57 +01:00
Referenced by issue #65837, "Zoom Axis" is not working on the node editor
|
@ -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"
|
||||
|
||||
|
@ -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
|
||||
|
|
|
@ -626,36 +626,35 @@ static void view_zoom_apply(
|
|||
bContext *C, ViewZoomData *vpd, wmOperator *op, const wmEvent *event, const bool zoom_to_pos)
|
||||
{
|
||||
float factor;
|
||||
float delta;
|
||||
|
||||
if (U.viewzoom != USER_ZOOM_SCALE) {
|
||||
if (U.uiflag & USER_ZOOM_HORIZ) {
|
||||
delta = (float)(event->x - vpd->x);
|
||||
}
|
||||
else {
|
||||
delta = (float)(event->y - vpd->y);
|
||||
}
|
||||
}
|
||||
else {
|
||||
delta = event->x - vpd->x + event->y - vpd->y;
|
||||
}
|
||||
|
||||
if (U.uiflag & USER_ZOOM_INVERT) {
|
||||
delta = -delta;
|
||||
}
|
||||
|
||||
if (U.viewzoom == USER_ZOOM_CONT) {
|
||||
SpaceClip *sclip = CTX_wm_space_clip(C);
|
||||
double time = PIL_check_seconds_timer();
|
||||
float time_step = (float)(time - vpd->timer_lastdraw);
|
||||
float fac;
|
||||
float zfac;
|
||||
|
||||
if (U.uiflag & USER_ZOOM_HORIZ) {
|
||||
fac = (float)(event->x - vpd->x);
|
||||
}
|
||||
else {
|
||||
fac = (float)(event->y - vpd->y);
|
||||
}
|
||||
|
||||
if (U.uiflag & USER_ZOOM_INVERT) {
|
||||
fac = -fac;
|
||||
}
|
||||
|
||||
zfac = 1.0f + ((fac / 20.0f) * time_step);
|
||||
zfac = 1.0f + ((delta / 20.0f) * time_step);
|
||||
vpd->timer_lastdraw = time;
|
||||
factor = (sclip->zoom * zfac) / vpd->zoom;
|
||||
}
|
||||
else {
|
||||
float delta = event->x - vpd->x + event->y - vpd->y;
|
||||
|
||||
if (U.uiflag & USER_ZOOM_INVERT) {
|
||||
delta *= -1;
|
||||
}
|
||||
|
||||
factor = 1.0f + delta / 300.0f;
|
||||
}
|
||||
|
||||
|
|
|
@ -556,39 +556,36 @@ static void image_zoom_apply(ViewZoomData *vpd,
|
|||
const bool zoom_to_pos)
|
||||
{
|
||||
float factor;
|
||||
float delta;
|
||||
|
||||
if (viewzoom != USER_ZOOM_SCALE) {
|
||||
if (U.uiflag & USER_ZOOM_HORIZ) {
|
||||
delta = (float)(x - vpd->origx);
|
||||
}
|
||||
else {
|
||||
delta = (float)(y - vpd->origy);
|
||||
}
|
||||
}
|
||||
else {
|
||||
delta = x - vpd->origx + y - vpd->origy;
|
||||
}
|
||||
|
||||
if (zoom_invert) {
|
||||
delta = -delta;
|
||||
}
|
||||
|
||||
if (viewzoom == USER_ZOOM_CONT) {
|
||||
double time = PIL_check_seconds_timer();
|
||||
float time_step = (float)(time - vpd->timer_lastdraw);
|
||||
float fac;
|
||||
float zfac;
|
||||
|
||||
if (U.uiflag & USER_ZOOM_HORIZ) {
|
||||
fac = (float)(x - vpd->origx);
|
||||
}
|
||||
else {
|
||||
fac = (float)(y - vpd->origy);
|
||||
}
|
||||
|
||||
if (zoom_invert) {
|
||||
fac = -fac;
|
||||
}
|
||||
|
||||
/* oldstyle zoom */
|
||||
zfac = 1.0f + ((fac / 20.0f) * time_step);
|
||||
zfac = 1.0f + ((delta / 20.0f) * time_step);
|
||||
vpd->timer_lastdraw = time;
|
||||
/* this is the final zoom, but instead make it into a factor */
|
||||
// zoom = vpd->sima->zoom * zfac;
|
||||
factor = (vpd->sima->zoom * zfac) / vpd->zoom;
|
||||
}
|
||||
else {
|
||||
/* for now do the same things for scale and dolly */
|
||||
float delta = x - vpd->origx + y - vpd->origy;
|
||||
|
||||
if (zoom_invert) {
|
||||
delta *= -1.0f;
|
||||
}
|
||||
|
||||
factor = 1.0f + delta / 300.0f;
|
||||
}
|
||||
|
||||
|
|
|
@ -5112,13 +5112,18 @@ static void rna_def_userdef_input(BlenderRNA *brna)
|
|||
"CONTINUE",
|
||||
0,
|
||||
"Continue",
|
||||
"Old style zoom, continues while moving mouse up or down"},
|
||||
{USER_ZOOM_DOLLY, "DOLLY", 0, "Dolly", "Zoom in and out based on vertical mouse movement"},
|
||||
"Continuous zooming. The zoom direction and speed depends on how far along the set Zoom "
|
||||
"Axis the mouse has moved"},
|
||||
{USER_ZOOM_DOLLY,
|
||||
"DOLLY",
|
||||
0,
|
||||
"Dolly",
|
||||
"Zoom in and out based on mouse movement along the set Zoom Axis"},
|
||||
{USER_ZOOM_SCALE,
|
||||
"SCALE",
|
||||
0,
|
||||
"Scale",
|
||||
"Zoom in and out like scaling the view, mouse movements relative to center"},
|
||||
"Zoom in and out as if you are scaling the view, mouse movements relative to center"},
|
||||
{0, NULL, 0, NULL, NULL},
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue