Fix panning with Lock-to-Selection and no selection in Clip Editor

Rather self-explanatory. Never worked since the initial implementation.
It is possible to preserve lock-to-selection option with no selection
nowadays (since the fix for T84850). So now the Lock-to-Selection option
is fully under user control. Surely, the panning and zooming is also
properly supported now in the described scenario.

Differential Revision: https://developer.blender.org/D10226
This commit is contained in:
Sergey Sharybin 2021-01-27 17:07:48 +01:00
parent 3b66f40d40
commit bf721fb679
5 changed files with 85 additions and 21 deletions

View File

@ -178,6 +178,8 @@ void clip_view_center_to_point(SpaceClip *sc, float x, float y);
bool clip_view_calculate_view_selection(
const struct bContext *C, bool fit, float *r_offset_x, float *r_offset_y, float *r_zoom);
bool clip_view_has_locked_selection(const struct bContext *C);
void clip_draw_sfra_efra(struct View2D *v2d, struct Scene *scene);
/* tracking_ops.c */

View File

@ -125,7 +125,7 @@ static void sclip_zoom_set(const bContext *C,
dx = ((location[0] - 0.5f) * w - sc->xof) * (sc->zoom - oldzoom) / sc->zoom;
dy = ((location[1] - 0.5f) * h - sc->yof) * (sc->zoom - oldzoom) / sc->zoom;
if (sc->flag & SC_LOCK_SELECTION) {
if (clip_view_has_locked_selection(C)) {
sc->xlockof += dx;
sc->ylockof += dy;
}
@ -396,7 +396,7 @@ static void view_pan_init(bContext *C, wmOperator *op, const wmEvent *event)
vpd->x = event->x;
vpd->y = event->y;
if (sc->flag & SC_LOCK_SELECTION) {
if (clip_view_has_locked_selection(C)) {
vpd->vec = &sc->xlockof;
}
else {
@ -434,7 +434,7 @@ static int view_pan_exec(bContext *C, wmOperator *op)
RNA_float_get_array(op->ptr, "offset", offset);
if (sc->flag & SC_LOCK_SELECTION) {
if (clip_view_has_locked_selection(C)) {
sc->xlockof += offset[0];
sc->ylockof += offset[1];
}

View File

@ -465,6 +465,68 @@ static bool selected_tracking_boundbox(SpaceClip *sc, float min[2], float max[2]
return ok;
}
static bool tracking_has_selection(SpaceClip *space_clip)
{
MovieClip *clip = ED_space_clip_get_clip(space_clip);
ListBase *tracksbase = BKE_tracking_get_active_tracks(&clip->tracking);
const int framenr = ED_space_clip_get_clip_frame_number(space_clip);
LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) {
if (!TRACK_VIEW_SELECTED(space_clip, track)) {
continue;
}
const MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr);
if (marker != NULL) {
return true;
}
}
return false;
}
static bool mask_has_selection(const bContext *C, bool include_handles)
{
Mask *mask = CTX_data_edit_mask(C);
if (mask == NULL) {
return false;
}
LISTBASE_FOREACH (MaskLayer *, mask_layer, &mask->masklayers) {
if (mask_layer->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) {
continue;
}
LISTBASE_FOREACH (MaskSpline *, spline, &mask_layer->splines) {
for (int i = 0; i < spline->tot_point; i++) {
const MaskSplinePoint *point = &spline->points[i];
const BezTriple *bezt = &point->bezt;
if (!MASKPOINT_ISSEL_ANY(point)) {
continue;
}
if (bezt->f2 & SELECT) {
return true;
}
if (!include_handles) {
/* Ignore handles. */
}
else if (BKE_mask_point_handles_mode_get(point) == MASK_HANDLE_MODE_STICK) {
return true;
}
else {
if ((bezt->f1 & SELECT) && (bezt->h1 != HD_VECT)) {
return true;
}
if ((bezt->f3 & SELECT) && (bezt->h2 != HD_VECT)) {
return true;
}
}
}
}
}
return false;
}
static bool selected_boundbox(const bContext *C, float min[2], float max[2], bool include_handles)
{
SpaceClip *sc = CTX_wm_space_clip(C);
@ -546,6 +608,23 @@ bool clip_view_calculate_view_selection(
return true;
}
/* Returns truth if lock-to-selection is enabled and possible.
* Locking to selection is not possible if there is no selection. */
bool clip_view_has_locked_selection(const bContext *C)
{
SpaceClip *space_clip = CTX_wm_space_clip(C);
if ((space_clip->flag & SC_LOCK_SELECTION) == 0) {
return false;
}
if (space_clip->mode == SC_MODE_TRACKING) {
return tracking_has_selection(space_clip);
}
return mask_has_selection(C, false);
}
void clip_draw_sfra_efra(View2D *v2d, Scene *scene)
{
UI_view2d_view_ortho(v2d);

View File

@ -243,8 +243,6 @@ static int delete_track_exec(bContext *C, wmOperator *UNUSED(op))
changed = true;
}
}
/* Nothing selected now, unlock view so it can be scrolled nice again. */
sc->flag &= ~SC_LOCK_SELECTION;
if (changed) {
WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip);
}
@ -313,11 +311,6 @@ static int delete_marker_exec(bContext *C, wmOperator *UNUSED(op))
}
}
if (!has_selection) {
/* Nothing selected now, unlock view so it can be scrolled nice again. */
sc->flag &= ~SC_LOCK_SELECTION;
}
if (!changed) {
return OPERATOR_CANCELLED;
}
@ -1224,13 +1217,6 @@ static int hide_tracks_exec(bContext *C, wmOperator *op)
clip->tracking.act_plane_track = NULL;
}
if (unselected == 0) {
/* No selection on screen now, unlock view so it can be
* scrolled nice again.
*/
sc->flag &= ~SC_LOCK_SELECTION;
}
BKE_tracking_dopesheet_tag_update(tracking);
WM_event_add_notifier(C, NC_MOVIECLIP | ND_DISPLAY, NULL);

View File

@ -875,10 +875,7 @@ static int select_all_exec(bContext *C, wmOperator *op)
bool has_selection = false;
ED_clip_select_all(sc, action, &has_selection);
if (!has_selection) {
sc->flag &= ~SC_LOCK_SELECTION;
}
else {
if (has_selection) {
ED_clip_view_lock_state_restore_no_jump(C, &lock_state);
}