Fix: VSE snapping with edge panning

Ever since it was added to the VSE in e49fef45ce, edge panning would
break snapping -- edge panning a strip and then bringing it back would
cause snap code to trigger at incorrect locations. This is because the
edge pan system would update the `View2D` in `t->region->v2d.cur`, but
not mouse values, and so `t->values` would end up unchanged even while
the strip was moving.

e6a557952e fixed the issue for the node editor by recalculating mouse
input values when the view changed with `transformViewUpdate()`, but
since the code was separate from VSE, that fix did not get also get
applied here.

Although the code in `view2d_edge_pan_loc_compensate()` is mostly
identical between the two and so one possibility is to move it to
`transform_generics.cc`, adapting it to allow it to be used by both
spaces, custom transform data in the node editor additionally stores and
updates a `viewrect_prev` as mentioned in e040aea7bf, which VSE custom
data does not have. Since the fix is small enough and I don't want to
risk messing with other module code, I've opted to just copy the fix
over to VSE. If further bugs crop up in the future, we can consider
combining the code.

Also fix typo in `tranformViewUpdate()`.

Pull Request: https://projects.blender.org/blender/blender/pulls/126471
This commit is contained in:
John Kiril Swenson
2024-08-20 07:11:45 +02:00
committed by Aras Pranckevicius
parent 9ab9aab3d7
commit 9dd2d7bd75
5 changed files with 14 additions and 12 deletions

View File

@@ -811,7 +811,7 @@ void calculateCenter(TransInfo *t);
* Called every time the view changes due to navigation.
* Adjusts the mouse position relative to the object.
*/
void tranformViewUpdate(TransInfo *t);
void transformViewUpdate(TransInfo *t);
/* API functions for getting center points. */
void calculateCenterBound(TransInfo *t, float r_center[3]);

View File

@@ -208,7 +208,7 @@ static void flushTransNodes(TransInfo *t)
if (!BLI_rctf_compare(&customdata->viewrect_prev, &t->region->v2d.cur, FLT_EPSILON)) {
/* Additional offset due to change in view2D rect. */
BLI_rctf_transform_pt_v(&t->region->v2d.cur, &customdata->viewrect_prev, offset, offset);
tranformViewUpdate(t);
transformViewUpdate(t);
customdata->viewrect_prev = t->region->v2d.cur;
}
}

View File

@@ -524,13 +524,11 @@ static void createTransSeqData(bContext * /*C*/, TransInfo *t)
/** \name UVs Transform Flush
* \{ */
static void view2d_edge_pan_loc_compensate(TransInfo *t, float loc_in[2], float r_loc[2])
static void view2d_edge_pan_loc_compensate(TransInfo *t, float offset[2])
{
TransSeq *ts = (TransSeq *)TRANS_DATA_CONTAINER_FIRST_SINGLE(t)->custom.type.data;
/* Initial and current view2D rects for additional transform due to view panning and zooming. */
const rctf *rect_src = &ts->initial_v2d_cur;
const rctf *rect_dst = &t->region->v2d.cur;
const rctf rect_prev = t->region->v2d.cur;
if (t->options & CTX_VIEW2D_EDGE_PAN) {
if (t->state == TRANS_CANCEL) {
@@ -546,9 +544,13 @@ static void view2d_edge_pan_loc_compensate(TransInfo *t, float loc_in[2], float
}
}
copy_v2_v2(r_loc, loc_in);
/* Additional offset due to change in view2D rect. */
BLI_rctf_transform_pt_v(rect_dst, rect_src, r_loc, r_loc);
if (t->state != TRANS_CANCEL) {
if (!BLI_rctf_compare(&rect_prev, &t->region->v2d.cur, FLT_EPSILON)) {
/* Additional offset due to change in view2D rect. */
BLI_rctf_transform_pt_v(&t->region->v2d.cur, &rect_prev, offset, offset);
transformViewUpdate(t);
}
}
}
static void flushTransSeq(TransInfo *t)
@@ -577,7 +579,7 @@ static void flushTransSeq(TransInfo *t)
int max_offset = 0;
float edge_pan_offset[2] = {0.0f, 0.0f};
view2d_edge_pan_loc_compensate(t, edge_pan_offset, edge_pan_offset);
view2d_edge_pan_loc_compensate(t, edge_pan_offset);
/* Flush to 2D vector from internally used 3D vector. */
for (a = 0, td = tc->data, td2d = tc->data_2d; a < tc->data_len; a++, td++, td2d++) {

View File

@@ -1233,7 +1233,7 @@ void calculateCenter(TransInfo *t)
calculateZfac(t);
}
void tranformViewUpdate(TransInfo *t)
void transformViewUpdate(TransInfo *t)
{
float zoom_prev = t->zfac;
float zoom_new;

View File

@@ -449,7 +449,7 @@ static int transform_modal(bContext *C, wmOperator *op, const wmEvent *event)
/* Navigation has ended. */
/* Call before #applyMouseInput. */
tranformViewUpdate(t);
transformViewUpdate(t);
/* Mouse input is outdated. */
t->mval = float2(event->mval);