Small refactor of mask sliding operator
[blender.git] / source / blender / editors / transform / transform_conversions.c
index 74afdfee7c9a48f35c81b847bda5542fa86504c7..8a7caeb30601325de16a37cd325c9666415a7940 100644 (file)
@@ -3725,9 +3725,9 @@ void flushTransGraphData(TransInfo *t)
                        switch (sipo->autosnap) {
                                case SACTSNAP_FRAME: /* snap to nearest frame (or second if drawing seconds) */
                                        if (sipo->flag & SIPO_DRAWTIME)
-                                               td2d->loc[0] = floorf((td2d->loc[0] / secf) + 0.5) * secf;
+                                               td2d->loc[0] = floor(((double)td2d->loc[0] / secf) + 0.5) * secf;
                                        else
-                                               td2d->loc[0] = floorf(td2d->loc[0] + 0.5);
+                                               td2d->loc[0] = floor((double)td2d->loc[0] + 0.5);
                                        break;
                                
                                case SACTSNAP_MARKER: /* snap to nearest marker */
@@ -3735,7 +3735,7 @@ void flushTransGraphData(TransInfo *t)
                                        break;
                        }
                }
-               
+
                /* we need to unapply the nla-mapping from the time in some situations */
                if (adt)
                        td2d->loc2d[0]= BKE_nla_tweakedit_remap(adt, td2d->loc[0], NLATIME_CONVERT_UNMAP);
@@ -4910,6 +4910,13 @@ void special_aftertrans_update(bContext *C, TransInfo *t)
                                nodeUpdateID(t->scene->nodetree, &mask->id);
                                WM_event_add_notifier(C, NC_SCENE|ND_NODES, NULL);
                        }
+
+                       /* TODO - dont key all masks... */
+                       if (IS_AUTOKEY_ON(t->scene)) {
+                               Scene *scene = t->scene;
+
+                               ED_mask_layer_shape_auto_key_all(mask, CFRA);
+                       }
                }
        }
        else if (t->spacetype == SPACE_ACTION) {
@@ -5408,7 +5415,7 @@ typedef struct TransDataTracking {
 
 static void markerToTransDataInit(TransData *td, TransData2D *td2d, TransDataTracking *tdt,
                                   MovieTrackingTrack *track, MovieTrackingMarker *marker,
-                                  int area, float *loc, float *rel, float *off, float aspx, float aspy)
+                                  int area, float loc[2], float rel[2], const float off[2], float aspx, float aspy)
 {
        int anchor = area == TRACK_AREA_POINT && off;
 
@@ -5878,17 +5885,20 @@ typedef struct TransDataMasking{
        MaskSplinePoint *point;
 } TransDataMasking;
 
-static void MaskPointToTransData(SpaceClip *sc, MaskSplinePoint *point, TransData *td, TransData2D *td2d, TransDataMasking *tdm)
+static void MaskPointToTransData(SpaceClip *sc, MaskSplinePoint *point,
+                                 TransData *td, TransData2D *td2d, TransDataMasking *tdm, int propmode)
 {
        BezTriple *bezt = &point->bezt;
        float aspx, aspy;
+       short is_sel_point = MASKPOINT_ISSEL_KNOT(point);
+       short is_sel_any = MASKPOINT_ISSEL_ANY(point);
 
        tdm->point = point;
        copy_m3_m3(tdm->vec, bezt->vec);
 
        ED_space_clip_mask_aspect(sc, &aspx, &aspy);
 
-       if (MASKPOINT_CV_ISSEL(point)) {
+       if (propmode || is_sel_point) {
                int i;
                for (i = 0; i < 3; i++) {
                        /* CV coords are scaled by aspects. this is needed for rotations and
@@ -5911,7 +5921,9 @@ static void MaskPointToTransData(SpaceClip *sc, MaskSplinePoint *point, TransDat
                        td->ext= NULL;
                        td->val= NULL;
 
-                       td->flag |= TD_SELECTED;
+                       if (is_sel_any) {
+                               td->flag |= TD_SELECTED;
+                       }
                        td->dist= 0.0;
 
                        unit_m3(td->mtx);
@@ -5944,7 +5956,10 @@ static void MaskPointToTransData(SpaceClip *sc, MaskSplinePoint *point, TransDat
                td->ext= NULL;
                td->val= NULL;
 
-               td->flag |= TD_SELECTED;
+               if (is_sel_any) {
+                       td->flag |= TD_SELECTED;
+               }
+
                td->dist= 0.0;
 
                unit_m3(td->mtx);
@@ -5959,36 +5974,44 @@ static void createTransMaskingData(bContext *C, TransInfo *t)
 {
        SpaceClip *sc = CTX_wm_space_clip(C);
        Mask *mask = CTX_data_edit_mask(C);
-       MaskObject *maskobj;
+       MaskLayer *masklay;
        TransData *td = NULL;
        TransData2D *td2d = NULL;
        TransDataMasking *tdm = NULL;
+       int count = 0, countsel = 0;
+       int propmode = t->flag & T_PROP_EDIT;
 
        /* count */
-       for (maskobj = mask->maskobjs.first; maskobj; maskobj = maskobj->next) {
-               MaskSpline *spline = maskobj->splines.first;
+       for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) {
+               MaskSpline *spline = masklay->splines.first;
+
+               if (masklay->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) {
+                       continue;
+               }
 
-               while (spline) {
+               for (spline = masklay->splines.first; spline; spline = spline->next) {
                        int i;
 
                        for (i = 0; i < spline->tot_point; i++) {
                                MaskSplinePoint *point = &spline->points[i];
 
-                               if (MASKPOINT_ISSEL(point)) {
-                                       if (MASKPOINT_CV_ISSEL(point))
-                                               t->total += 3;
+                               if (MASKPOINT_ISSEL_ANY(point)) {
+                                       if (MASKPOINT_ISSEL_KNOT(point))
+                                               countsel += 3;
                                        else
-                                               t->total += 1;
+                                               countsel += 1;
                                }
-                       }
 
-                       spline = spline->next;
+                               if (propmode)
+                                       count += 3;
+                       }
                }
        }
 
-       if (t->total == 0)
-               return;
+       /* note: in prop mode we need at least 1 selected */
+       if (countsel == 0) return;
 
+       t->total = (propmode) ? count: countsel;
        td = t->data = MEM_callocN(t->total*sizeof(TransData), "TransObData(Mask Editing)");
        /* for each 2d uv coord a 3d vector is allocated, so that they can be
         * treated just as if they were 3d verts */
@@ -5998,19 +6021,23 @@ static void createTransMaskingData(bContext *C, TransInfo *t)
        t->flag |= T_FREE_CUSTOMDATA;
 
        /* create data */
-       for (maskobj = mask->maskobjs.first; maskobj; maskobj = maskobj->next) {
-               MaskSpline *spline = maskobj->splines.first;
+       for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) {
+               MaskSpline *spline = masklay->splines.first;
+
+               if (masklay->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) {
+                       continue;
+               }
 
-               while (spline) {
+               for (spline = masklay->splines.first; spline; spline = spline->next) {
                        int i;
 
                        for (i = 0; i < spline->tot_point; i++) {
                                MaskSplinePoint *point = &spline->points[i];
 
-                               if (MASKPOINT_ISSEL(point)) {
-                                       MaskPointToTransData(sc, point, td, td2d, tdm);
+                               if (propmode || MASKPOINT_ISSEL_ANY(point)) {
+                                       MaskPointToTransData(sc, point, td, td2d, tdm, propmode);
 
-                                       if (MASKPOINT_CV_ISSEL(point)) {
+                                       if (propmode || MASKPOINT_ISSEL_KNOT(point)) {
                                                td += 3;
                                                td2d += 3;
                                                tdm += 3;
@@ -6022,8 +6049,6 @@ static void createTransMaskingData(bContext *C, TransInfo *t)
                                        }
                                }
                        }
-
-                       spline = spline->next;
                }
        }
 }
@@ -6046,7 +6071,7 @@ void flushTransMasking(TransInfo *t)
                td->loc2d[1]= td->loc[1]*invy;
 
                if (tdm->is_handle)
-                       BKE_mask_point_set_handle(tdm->point, td->loc2d, t->flag & T_ALT_TRANSFORM, aspx, aspy, tdm->orig_handle, tdm->vec);
+                       BKE_mask_point_set_handle(tdm->point, td->loc2d, t->flag & T_ALT_TRANSFORM, tdm->orig_handle, tdm->vec);
        }
 }
 
@@ -6119,8 +6144,15 @@ void createTransData(bContext *C, TransInfo *t)
                t->flag |= T_POINTS|T_2D_EDIT;
                if (t->options & CTX_MOVIECLIP)
                        createTransTrackingData(C, t);
-               else if (t->options & CTX_MASK)
+               else if (t->options & CTX_MASK) {
                        createTransMaskingData(C, t);
+
+                       if (t->data && (t->flag & T_PROP_EDIT)) {
+                               sort_trans_data(t);     // makes selected become first in array
+                               set_prop_dist(t, TRUE);
+                               sort_trans_data_dist(t);
+                       }
+               }
        }
        else if (t->obedit) {
                t->ext = NULL;