Small refactor of mask sliding operator
[blender.git] / source / blender / editors / transform / transform_conversions.c
index 1390d832296b3763a5b8954520002edc01572264..8a7caeb30601325de16a37cd325c9666415a7940 100644 (file)
@@ -287,7 +287,7 @@ static void createTransTexspace(TransInfo *t)
        normalize_m3(td->axismtx);
        invert_m3_m3(td->smtx, td->mtx);
 
-       if (give_obdata_texspace(ob, &texflag, &td->loc, &td->ext->size, &td->ext->rot)) {
+       if (BKE_object_obdata_texspace_get(ob, &texflag, &td->loc, &td->ext->size, &td->ext->rot)) {
                ob->dtx |= OB_TEXSPACE;
                *texflag &= ~ME_AUTOSPACE;
        }
@@ -427,7 +427,7 @@ static short apply_targetless_ik(Object *ob)
                                bone= parchan->bone;
                                bone->flag |= BONE_TRANSFORM;   /* ensures it gets an auto key inserted */
 
-                               armature_mat_pose_to_bone(parchan, parchan->pose_mat, rmat);
+                               BKE_armature_mat_pose_to_bone(parchan, parchan->pose_mat, rmat);
 
                                /* apply and decompose, doesn't work for constraints or non-uniform scale well */
                                {
@@ -538,23 +538,34 @@ static void add_pose_transdata(TransInfo *t, bPoseChannel *pchan, Object *ob, Tr
        /* proper way to get parent transform + own transform + constraints transform */
        copy_m3_m4(omat, ob->obmat);
 
-       /* New code, using "generic" pchan_to_pose_mat(). */
+       /* New code, using "generic" BKE_pchan_to_pose_mat(). */
        {
                float rotscale_mat[4][4], loc_mat[4][4];
+               float rpmat[3][3];
 
-               pchan_to_pose_mat(pchan, rotscale_mat, loc_mat);
+               BKE_pchan_to_pose_mat(pchan, rotscale_mat, loc_mat);
                if (t->mode == TFM_TRANSLATION)
                        copy_m3_m4(pmat, loc_mat);
                else
                        copy_m3_m4(pmat, rotscale_mat);
 
+               /* Grrr! Exceptional case: When translating pose bones that are either Hinge or NoLocal,
+                * and want align snapping, we just need both loc_mat and rotscale_mat.
+                * So simply always store rotscale mat in td->ext, and always use it to apply rotations...
+                * Ugly to need such hacks! :/ */
+               copy_m3_m4(rpmat, rotscale_mat);
+
                if (constraints_list_needinv(t, &pchan->constraints)) {
                        copy_m3_m4(tmat, pchan->constinv);
                        invert_m3_m3(cmat, tmat);
                        mul_serie_m3(td->mtx, pmat, omat, cmat, NULL, NULL, NULL, NULL, NULL);
+                       mul_serie_m3(td->ext->r_mtx, rpmat, omat, cmat, NULL,NULL,NULL,NULL,NULL);
                }
-               else
-                       mul_serie_m3(td->mtx, pmat, omat, NULL, NULL, NULL, NULL, NULL, NULL);
+               else {
+                       mul_serie_m3(td->mtx, pmat, omat, NULL, NULL,NULL,NULL,NULL,NULL);
+                       mul_serie_m3(td->ext->r_mtx, rpmat, omat, NULL, NULL,NULL,NULL,NULL,NULL);
+               }
+               invert_m3_m3(td->ext->r_smtx, td->ext->r_mtx);
        }
 
        invert_m3_m3(td->smtx, td->mtx);
@@ -621,9 +632,8 @@ static void bone_children_clear_transflag(int mode, short around, ListBase *lb)
 {
        Bone *bone= lb->first;
 
-       for (;bone;bone= bone->next) {
-               if ((bone->flag & BONE_HINGE) && (bone->flag & BONE_CONNECTED))
-               {
+       for ( ; bone;bone= bone->next) {
+               if ((bone->flag & BONE_HINGE) && (bone->flag & BONE_CONNECTED)) {
                        bone->flag |= BONE_HINGE_CHILD_TRANSFORM;
                }
                else if ((bone->flag & BONE_TRANSFORM) &&
@@ -699,8 +709,7 @@ int count_set_pose_transflags(int *out_mode, short around, Object *ob)
        }
 
        /* if there are no translatable bones, do rotation */
-       if (mode == TFM_TRANSLATION && !hastranslation)
-       {
+       if (mode == TFM_TRANSLATION && !hastranslation) {
                *out_mode = TFM_ROTATION;
        }
 
@@ -889,7 +898,7 @@ static short pose_grab_with_ik_children(bPose *pose, Bone *bone)
                }
        }
        if (wentdeeper==0) {
-               bPoseChannel *pchan= get_pose_channel(pose, bone->name);
+               bPoseChannel *pchan= BKE_pose_channel_find_name(pose, bone->name);
                if (pchan)
                        added+= pose_grab_with_ik_add(pchan);
        }
@@ -958,7 +967,7 @@ static void createTransPose(TransInfo *t, Object *ob)
        t->total= 0;
 
        /* check validity of state */
-       arm= get_armature(ob);
+       arm= BKE_armature_from_object(ob);
        if ((arm==NULL) || (ob->pose==NULL)) return;
 
        if (arm->flag & ARM_RESTPOS) {
@@ -1028,16 +1037,13 @@ static void createTransArmatureVerts(TransInfo *t)
                t->mode= TFM_BONE_ENVELOPE;
        
        t->total = 0;
-       for (ebo = edbo->first; ebo; ebo = ebo->next)
-       {
-               if (EBONE_VISIBLE(arm, ebo) && !(ebo->flag & BONE_EDITMODE_LOCKED)) 
-               {
-                       if (t->mode==TFM_BONESIZE)
-                       {
+       for (ebo = edbo->first; ebo; ebo = ebo->next) {
+               if (EBONE_VISIBLE(arm, ebo) && !(ebo->flag & BONE_EDITMODE_LOCKED)) {
+                       if (t->mode == TFM_BONESIZE) {
                                if (ebo->flag & BONE_SELECTED)
                                        t->total++;
                        }
-                       else if (t->mode==TFM_BONE_ROLL) {
+                       else if (t->mode == TFM_BONE_ROLL) {
                                if (ebo->flag & BONE_SELECTED)
                                        t->total++;
                        }
@@ -1057,16 +1063,12 @@ static void createTransArmatureVerts(TransInfo *t)
 
        td = t->data = MEM_callocN(t->total*sizeof(TransData), "TransEditBone");
 
-       for (ebo = edbo->first; ebo; ebo = ebo->next)
-       {
+       for (ebo = edbo->first; ebo; ebo = ebo->next) {
                ebo->oldlength = ebo->length;   // length==0.0 on extrude, used for scaling radius of bone points
 
-               if (EBONE_VISIBLE(arm, ebo) && !(ebo->flag & BONE_EDITMODE_LOCKED)) 
-               {
-                       if (t->mode==TFM_BONE_ENVELOPE)
-                       {
-                               if (ebo->flag & BONE_ROOTSEL)
-                               {
+               if (EBONE_VISIBLE(arm, ebo) && !(ebo->flag & BONE_EDITMODE_LOCKED)) {
+                       if (t->mode==TFM_BONE_ENVELOPE) {
+                               if (ebo->flag & BONE_ROOTSEL) {
                                        td->val= &ebo->rad_head;
                                        td->ival= *td->val;
 
@@ -1082,8 +1084,7 @@ static void createTransArmatureVerts(TransInfo *t)
 
                                        td++;
                                }
-                               if (ebo->flag & BONE_TIPSEL)
-                               {
+                               if (ebo->flag & BONE_TIPSEL) {
                                        td->val= &ebo->rad_tail;
                                        td->ival= *td->val;
                                        copy_v3_v3(td->center, ebo->tail);
@@ -1102,8 +1103,7 @@ static void createTransArmatureVerts(TransInfo *t)
                        }
                        else if (t->mode==TFM_BONESIZE) {
                                if (ebo->flag & BONE_SELECTED) {
-                                       if (arm->drawtype==ARM_ENVELOPE)
-                                       {
+                                       if (arm->drawtype==ARM_ENVELOPE) {
                                                td->loc= NULL;
                                                td->val= &ebo->dist;
                                                td->ival= ebo->dist;
@@ -1133,8 +1133,7 @@ static void createTransArmatureVerts(TransInfo *t)
                                }
                        }
                        else if (t->mode==TFM_BONE_ROLL) {
-                               if (ebo->flag & BONE_SELECTED)
-                               {
+                               if (ebo->flag & BONE_SELECTED) {
                                        td->loc= NULL;
                                        td->val= &(ebo->roll);
                                        td->ival= ebo->roll;
@@ -1149,8 +1148,7 @@ static void createTransArmatureVerts(TransInfo *t)
                                }
                        }
                        else {
-                               if (ebo->flag & BONE_TIPSEL)
-                               {
+                               if (ebo->flag & BONE_TIPSEL) {
                                        copy_v3_v3(td->iloc, ebo->tail);
                                        copy_v3_v3(td->center, (t->around==V3D_LOCAL) ? ebo->head : td->iloc);
                                        td->loc= ebo->tail;
@@ -1164,8 +1162,7 @@ static void createTransArmatureVerts(TransInfo *t)
                                        sub_v3_v3v3(delta, ebo->tail, ebo->head);
                                        vec_roll_to_mat3(delta, ebo->roll, td->axismtx);
 
-                                       if ((ebo->flag & BONE_ROOTSEL) == 0)
-                                       {
+                                       if ((ebo->flag & BONE_ROOTSEL) == 0) {
                                                td->extra = ebo;
                                        }
 
@@ -1175,8 +1172,7 @@ static void createTransArmatureVerts(TransInfo *t)
 
                                        td++;
                                }
-                               if (ebo->flag & BONE_ROOTSEL)
-                               {
+                               if (ebo->flag & BONE_ROOTSEL) {
                                        copy_v3_v3(td->iloc, ebo->head);
                                        copy_v3_v3(td->center, td->iloc);
                                        td->loc= ebo->head;
@@ -1400,10 +1396,10 @@ static void createTransCurveVerts(bContext *C, TransInfo *t)
                                if (bezt->hide==0) {
                                        TransDataCurveHandleFlags *hdata = NULL;
 
-                                       if (            propmode ||
-                                                       ((bezt->f2 & SELECT) && hide_handles) ||
-                                                       ((bezt->f1 & SELECT) && hide_handles == 0)
-                                         ) {
+                                       if (propmode ||
+                                           ((bezt->f2 & SELECT) && hide_handles) ||
+                                           ((bezt->f1 & SELECT) && hide_handles == 0))
+                                       {
                                                copy_v3_v3(td->iloc, bezt->vec[0]);
                                                td->loc= bezt->vec[0];
                                                copy_v3_v3(td->center, bezt->vec[(hide_handles || bezt->f2 & SELECT) ? 1:0]);
@@ -1462,10 +1458,10 @@ static void createTransCurveVerts(bContext *C, TransInfo *t)
                                                count++;
                                                tail++;
                                        }
-                                       if (            propmode ||
-                                                       ((bezt->f2 & SELECT) && hide_handles) ||
-                                                       ((bezt->f3 & SELECT) && hide_handles == 0)
-                                         ) {
+                                       if (propmode ||
+                                           ((bezt->f2 & SELECT) && hide_handles) ||
+                                           ((bezt->f3 & SELECT) && hide_handles == 0))
+                                       {
                                                copy_v3_v3(td->iloc, bezt->vec[2]);
                                                td->loc= bezt->vec[2];
                                                copy_v3_v3(td->center, bezt->vec[(hide_handles || bezt->f2 & SELECT) ? 1:2]);
@@ -1892,7 +1888,8 @@ static void get_edge_center(float cent_r[3], BMVert *eve)
 }
 
 /* way to overwrite what data is edited with transform */
-static void VertsToTransData(TransInfo *t, TransData *td, BMEditMesh *em, BMVert *eve, float *bweight)
+static void VertsToTransData(TransInfo *t, TransData *td, TransDataExtension *tx,
+                                                        BMEditMesh *em, BMVert *eve, float *bweight)
 {
        td->flag = 0;
        //if (key)
@@ -1926,12 +1923,23 @@ static void VertsToTransData(TransInfo *t, TransData *td, BMEditMesh *em, BMVert
                td->val = bweight;
                td->ival = bweight ? *(bweight) : 1.0f;
        }
+       else if (t->mode == TFM_SKIN_RESIZE) {
+               MVertSkin *vs = CustomData_bmesh_get(&em->bm->vdata,
+                                                    eve->head.data,
+                                                    CD_MVERT_SKIN);
+               /* skin node size */
+               td->ext = tx;
+               copy_v3_v3(tx->isize, vs->radius);
+               tx->size = vs->radius;
+               td->val = vs->radius;
+       }
 }
 
 static void createTransEditVerts(bContext *C, TransInfo *t)
 {
        ToolSettings *ts = CTX_data_tool_settings(C);
        TransData *tob = NULL;
+       TransDataExtension *tx = NULL;
        BMEditMesh *em = BMEdit_FromObject(t->obedit);
        BMesh *bm = em->bm;
        BMVert *eve;
@@ -1946,8 +1954,7 @@ static void createTransEditVerts(bContext *C, TransInfo *t)
        char *selstate = NULL;
        short selectmode = ts->selectmode;
 
-       if (t->flag & T_MIRROR)
-       {
+       if (t->flag & T_MIRROR) {
                EDBM_verts_mirror_cache_begin(em, TRUE);
                mirror = 1;
        }
@@ -2038,6 +2045,10 @@ static void createTransEditVerts(bContext *C, TransInfo *t)
        else t->total = countsel;
 
        tob= t->data= MEM_callocN(t->total*sizeof(TransData), "TransObData(Mesh EditMode)");
+       if (t->mode == TFM_SKIN_RESIZE) {
+               tx = t->ext = MEM_callocN(t->total * sizeof(TransDataExtension),
+                                                                 "TransObData ext");
+       }
 
        copy_m3_m4(mtx, t->obedit->obmat);
        invert_m3_m3(smtx, mtx);
@@ -2074,8 +2085,7 @@ static void createTransEditVerts(bContext *C, TransInfo *t)
                eve = BM_iter_new(&iter, bm, BM_VERTS_OF_MESH, NULL);
                for (a=0; eve; eve=BM_iter_step(&iter), a++) {
                        if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN) && selstate[a] && eve->co[0]!=0.0f) {
-                               if (eve->co[0]<0.0f)
-                               {
+                               if (eve->co[0] < 0.0f) {
                                        t->mirror = -1;
                                        mirror = -1;
                                }
@@ -2090,7 +2100,9 @@ static void createTransEditVerts(bContext *C, TransInfo *t)
                        if (propmode || selstate[a]) {
                                float *bweight = CustomData_bmesh_get(&bm->vdata, eve->head.data, CD_BWEIGHT);
                                
-                               VertsToTransData(t, tob, em, eve, bweight);
+                               VertsToTransData(t, tob, tx, em, eve, bweight);
+                               if (tx)
+                                       tx++;
 
                                /* selected */
                                if (selstate[a]) tob->flag |= TD_SELECTED;
@@ -2147,13 +2159,10 @@ static void createTransEditVerts(bContext *C, TransInfo *t)
                }
        }
        
-       if (mirror != 0)
-       {
+       if (mirror != 0) {
                tob = t->data;
-               for (a = 0; a < t->total; a++, tob++ )
-               {
-                       if (ABS(tob->loc[0]) <= 0.00001f)
-                       {
+               for (a = 0; a < t->total; a++, tob++ ) {
+                       if (ABS(tob->loc[0]) <= 0.00001f) {
                                tob->flag |= TD_MIRROR_EDGE;
                        }
                }
@@ -2192,7 +2201,6 @@ void flushTransNodes(TransInfo *t)
        if (t->total==1) {
                ED_node_link_intersect_test(t->sa, 1);
        }
-       
 }
 
 /* *** SEQUENCE EDITOR *** */
@@ -2204,7 +2212,7 @@ void flushTransNodes(TransInfo *t)
 
 void flushTransSeq(TransInfo *t)
 {
-       ListBase *seqbasep= seq_give_editing(t->scene, FALSE)->seqbasep; /* Editing null check already done */
+       ListBase *seqbasep= BKE_sequencer_editing_get(t->scene, FALSE)->seqbasep; /* Editing null check already done */
        int a, new_frame, old_start;
        TransData *td= NULL;
        TransData2D *td2d= NULL;
@@ -3717,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]= (float)(floor((td2d->loc[0]/secf) + 0.5f) * secf);
+                                               td2d->loc[0] = floor(((double)td2d->loc[0] / secf) + 0.5) * secf;
                                        else
-                                               td2d->loc[0]= (float)(floor(td2d->loc[0]+0.5f));
+                                               td2d->loc[0] = floor((double)td2d->loc[0] + 0.5);
                                        break;
                                
                                case SACTSNAP_MARKER: /* snap to nearest marker */
@@ -3727,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);
@@ -3769,42 +3777,42 @@ static void SeqTransInfo(TransInfo *t, Sequence *seq, int *recursive, int *count
 
                /* *** Extend Transform *** */
 
-               Scene * scene= t->scene;
+               Scene *scene = t->scene;
                int cfra= CFRA;
                int left= seq_tx_get_final_left(seq, 1);
                int right= seq_tx_get_final_right(seq, 1);
 
                if (seq->depth == 0 && ((seq->flag & SELECT) == 0 || (seq->flag & SEQ_LOCK))) {
-                       *recursive= 0;
-                       *count= 0;
-                       *flag= 0;
+                       *recursive = FALSE;
+                       *count = 0;
+                       *flag = 0;
                }
-               else if (seq->type ==SEQ_META) {
+               else if (seq->type == SEQ_META) {
 
                        /* for meta's we only ever need to extend their children, no matter what depth
                         * just check the meta's are in the bounds */
-                       if (t->frame_side=='R' && right <= cfra)                *recursive= 0;
-                       else if (t->frame_side=='L' && left >= cfra)    *recursive= 0;
-                       else                                                                                    *recursive= 1;
+                       if      (t->frame_side=='R' && right <= cfra)  *recursive = FALSE;
+                       else if (t->frame_side=='L' && left  >= cfra)  *recursive = FALSE;
+                       else                                           *recursive = TRUE;
 
                        *count= 1;
                        *flag= (seq->flag | SELECT) & ~(SEQ_LEFTSEL|SEQ_RIGHTSEL);
                }
                else {
 
-                       *recursive= 0;  /* not a meta, so no thinking here */
-                       *count= 1;              /* unless its set to 0, extend will never set 2 handles at once */
-                       *flag= (seq->flag | SELECT) & ~(SEQ_LEFTSEL|SEQ_RIGHTSEL);
+                       *recursive = FALSE;  /* not a meta, so no thinking here */
+                       *count = 1;          /* unless its set to 0, extend will never set 2 handles at once */
+                       *flag = (seq->flag | SELECT) & ~(SEQ_LEFTSEL|SEQ_RIGHTSEL);
 
                        if (t->frame_side=='R') {
-                               if (right <= cfra)              *count= *flag= 0;       /* ignore */
-                               else if (left > cfra)   ;       /* keep the selection */
-                               else                                    *flag |= SEQ_RIGHTSEL;
+                               if      (right <= cfra) *count = *flag= 0;  /* ignore */
+                               else if (left   > cfra) ;                  /* keep the selection */
+                               else                    *flag |= SEQ_RIGHTSEL;
                        }
                        else {
-                               if (left >= cfra)               *count= *flag= 0;       /* ignore */
-                               else if (right < cfra)  ;       /* keep the selection */
-                               else                                    *flag |= SEQ_LEFTSEL;
+                               if      (left >= cfra)  *count = *flag= 0;  /* ignore */
+                               else if (right < cfra)  ;                  /* keep the selection */
+                               else                    *flag |= SEQ_LEFTSEL;
                        }
                }
        }
@@ -3820,9 +3828,9 @@ static void SeqTransInfo(TransInfo *t, Sequence *seq, int *recursive, int *count
 
                        /* Non nested strips (resect selection and handles) */
                        if ((seq->flag & SELECT) == 0 || (seq->flag & SEQ_LOCK)) {
-                               *recursive= 0;
-                               *count= 0;
-                               *flag= 0;
+                               *recursive = FALSE;
+                               *count = 0;
+                               *flag = 0;
                        }
                        else {
                                if ((seq->flag & (SEQ_LEFTSEL|SEQ_RIGHTSEL)) == (SEQ_LEFTSEL|SEQ_RIGHTSEL)) {
@@ -3838,10 +3846,10 @@ static void SeqTransInfo(TransInfo *t, Sequence *seq, int *recursive, int *count
 
                                if ((seq->type == SEQ_META) && ((seq->flag & (SEQ_LEFTSEL|SEQ_RIGHTSEL)) == 0)) {
                                        /* if any handles are selected, don't recurse */
-                                       *recursive = 1;
+                                       *recursive = TRUE;
                                }
                                else {
-                                       *recursive = 0;
+                                       *recursive = FALSE;
                                }
                        }
                }
@@ -3849,23 +3857,23 @@ static void SeqTransInfo(TransInfo *t, Sequence *seq, int *recursive, int *count
                        /* Nested, different rules apply */
 
 #ifdef SEQ_TX_NESTED_METAS
-                       *flag= (seq->flag | SELECT) & ~(SEQ_LEFTSEL|SEQ_RIGHTSEL);
-                       *count= 1; /* ignore the selection for nested */
-                       *recursive = (seq->type == SEQ_META     );
+                       *flag = (seq->flag | SELECT) & ~(SEQ_LEFTSEL|SEQ_RIGHTSEL);
+                       *count = 1; /* ignore the selection for nested */
+                       *recursive = (seq->type == SEQ_META);
 #else
                        if (seq->type == SEQ_META) {
                                /* Meta's can only directly be moved between channels since they
                                 * don't have their start and length set directly (children affect that)
-                                * since this Meta is nested we don't need any of its data infact.
+                                * since this Meta is nested we don't need any of its data in fact.
                                 * calc_sequence() will update its settings when run on the toplevel meta */
                                *flag= 0;
                                *count= 0;
-                               *recursive = 1;
+                               *recursive = TRUE;
                        }
                        else {
                                *flag= (seq->flag | SELECT) & ~(SEQ_LEFTSEL|SEQ_RIGHTSEL);
                                *count= 1; /* ignore the selection for nested */
-                               *recursive = 0;
+                               *recursive = FALSE;
                        }
 #endif
                }
@@ -4003,7 +4011,7 @@ static int SeqToTransData_Recursive(TransInfo *t, ListBase *seqbase, TransData *
 
 static void freeSeqData(TransInfo *t)
 {
-       Editing *ed= seq_give_editing(t->scene, FALSE);
+       Editing *ed= BKE_sequencer_editing_get(t->scene, FALSE);
 
        if (ed != NULL) {
                ListBase *seqbasep= ed->seqbasep;
@@ -4066,7 +4074,47 @@ static void freeSeqData(TransInfo *t)
                                                }
                                        }
 
+#if 1                          /* (mango hack! - for Ian) this is truely bad - should _never_ be in a release :| */
+                                       if (CTX_wm_window(t->context)->eventstate->alt) {
+                                               int minframe = MAXFRAME;
+                                               td= t->data;
+                                               seq_prev= NULL;
+                                               for (a=0; a<t->total; a++, td++) {
+                                                       seq= ((TransDataSeq *)td->extra)->seq;
+                                                       if ((seq != seq_prev)) {
+                                                               minframe = MIN2(minframe, seq->startdisp);
+                                                       }
+                                               }
+
+
+                                               for (seq= seqbasep->first; seq; seq= seq->next) {
+                                                       if (!(seq->flag & SELECT)) {
+                                                               if (seq->startdisp >= minframe) {
+                                                                       seq->machine += MAXSEQ * 2;
+                                                               }
+                                                       }
+                                               }
+
+                                               shuffle_seq_time(seqbasep, t->scene);
+
+                                               for (seq= seqbasep->first; seq; seq= seq->next) {
+                                                       if (seq->machine >= MAXSEQ * 2) {
+                                                               seq->machine -= MAXSEQ * 2;
+                                                               seq->tmp= (void*)1;
+                                                       }
+                                                       else {
+                                                               seq->tmp= NULL;
+                                                       }
+                                               }
+
+                                               shuffle_seq_time(seqbasep, t->scene);
+                                       }
+                                       else {
+                                               shuffle_seq_time(seqbasep, t->scene);
+                                       }
+#else
                                        shuffle_seq_time(seqbasep, t->scene);
+#endif
 
                                        if (has_effect) {
                                                /* update effects strips based on strips just moved in time */
@@ -4103,13 +4151,13 @@ static void freeSeqData(TransInfo *t)
                        for (seq= seqbasep->first; seq; seq= seq->next) {
                                /* We might want to build a list of effects that need to be updated during transform */
                                if (seq->type & SEQ_EFFECT) {
-                                       if              (seq->seq1 && seq->seq1->flag & SELECT) calc_sequence(t->scene, seq);
-                                       else if (seq->seq2 && seq->seq2->flag & SELECT) calc_sequence(t->scene, seq);
-                                       else if (seq->seq3 && seq->seq3->flag & SELECT) calc_sequence(t->scene, seq);
+                                       if      (seq->seq1 && seq->seq1->flag & SELECT) calc_sequence(t->scene, seq);
+                                       else if (seq->seq2 && seq->seq2->flag & SELECT) calc_sequence(t->scene, seq);
+                                       else if (seq->seq3 && seq->seq3->flag & SELECT) calc_sequence(t->scene, seq);
                                }
                        }
 
-                       sort_seq(t->scene);
+                       BKE_sequencer_sort(t->scene);
                }
                else {
                        /* Cancelled, need to update the strips display */
@@ -4139,7 +4187,7 @@ static void createTransSeqData(bContext *C, TransInfo *t)
 
        View2D *v2d= UI_view2d_fromcontext(C);
        Scene *scene= t->scene;
-       Editing *ed= seq_give_editing(t->scene, FALSE);
+       Editing *ed= BKE_sequencer_editing_get(t->scene, FALSE);
        TransData *td = NULL;
        TransData2D *td2d= NULL;
        TransDataSeq *tdsq= NULL;
@@ -4281,15 +4329,15 @@ static void ObjectToTransData(TransInfo *t, TransData *td, Object *ob)
 
        if (skip_invert == 0 && constinv == 0) {
                if (constinv == 0)
-                       ob->transflag |= OB_NO_CONSTRAINTS; /* where_is_object_time checks this */
+                       ob->transflag |= OB_NO_CONSTRAINTS; /* BKE_object_where_is_calc_time checks this */
                
-               where_is_object(t->scene, ob);
+               BKE_object_where_is_calc(t->scene, ob);
                
                if (constinv == 0)
                        ob->transflag &= ~OB_NO_CONSTRAINTS;
        }
        else
-               where_is_object(t->scene, ob);
+               BKE_object_where_is_calc(t->scene, ob);
 
        td->ob = ob;
 
@@ -4343,7 +4391,7 @@ static void ObjectToTransData(TransInfo *t, TransData *td, Object *ob)
                 * NOTE: some Constraints, and also Tracking should never get this
                 *              done, as it doesn't work well.
                 */
-               object_to_mat3(ob, obmtx);
+               BKE_object_to_mat3(ob, obmtx);
                copy_m3_m4(totmat, ob->obmat);
                invert_m3_m3(obinv, totmat);
                mul_m3_m3m3(td->smtx, obmtx, obinv);
@@ -4380,12 +4428,12 @@ static void set_trans_object_base_flags(TransInfo *t)
                return;
 
        /* makes sure base flags and object flags are identical */
-       copy_baseflags(t->scene);
+       BKE_scene_base_flag_to_objects(t->scene);
 
        /* handle pending update events, otherwise they got copied below */
        for (base= scene->base.first; base; base= base->next) {
                if (base->object->recalc)
-                       object_handle_update(t->scene, base->object);
+                       BKE_object_handle_update(t->scene, base->object);
        }
 
        for (base= scene->base.first; base; base= base->next) {
@@ -4398,7 +4446,7 @@ static void set_trans_object_base_flags(TransInfo *t)
                        /* if parent selected, deselect */
                        while (parsel) {
                                if (parsel->flag & SELECT) {
-                                       Base *parbase = object_in_scene(parsel, scene);
+                                       Base *parbase = BKE_scene_base_find(scene, parsel);
                                        if (parbase) { /* in rare cases this can fail */
                                                if (TESTBASELIB_BGMODE(v3d, scene, parbase)) {
                                                        break;
@@ -4410,7 +4458,7 @@ static void set_trans_object_base_flags(TransInfo *t)
 
                        if (parsel) {
                                /* rotation around local centers are allowed to propagate */
-                               if ((t->mode == TFM_ROTATION || t->mode == TFM_TRACKBALL)  && t->around == V3D_LOCAL) {
+                               if ((t->mode == TFM_ROTATION || t->mode == TFM_TRACKBALL) && t->around == V3D_LOCAL) {
                                        base->flag |= BA_TRANSFORM_CHILD;
                                }
                                else {
@@ -4459,7 +4507,7 @@ static int count_proportional_objects(TransInfo *t)
        Base *base;
 
        /* rotations around local centers are allowed to propagate, so we take all objects */
-       if (!((t->mode == TFM_ROTATION || t->mode == TFM_TRACKBALL)  && t->around == V3D_LOCAL)) {
+       if (!((t->mode == TFM_ROTATION || t->mode == TFM_TRACKBALL) && t->around == V3D_LOCAL)) {
                /* mark all parents */
                for (base= scene->base.first; base; base= base->next) {
                        if (TESTBASELIB_BGMODE(v3d, scene, base)) {
@@ -4571,45 +4619,45 @@ void autokeyframe_ob_cb_func(bContext *C, Scene *scene, View3D *v3d, Object *ob,
                        }
                }
                else if (IS_AUTOKEY_FLAG(scene, INSERTNEEDED)) {
-                       short doLoc=0, doRot=0, doScale=0;
+                       short do_loc = FALSE, do_rot = FALSE, do_scale = FALSE;
                        
                        /* filter the conditions when this happens (assume that curarea->spacetype==SPACE_VIE3D) */
                        if (tmode == TFM_TRANSLATION) {
-                               doLoc = 1;
+                               do_loc = TRUE;
                        }
                        else if (tmode == TFM_ROTATION) {
                                if (v3d->around == V3D_ACTIVE) {
                                        if (ob != OBACT)
-                                               doLoc = 1;
+                                               do_loc = TRUE;
                                }
                                else if (v3d->around == V3D_CURSOR)
-                                       doLoc = 1;
+                                       do_loc = TRUE;
                                
                                if ((v3d->flag & V3D_ALIGN)==0)
-                                       doRot = 1;
+                                       do_rot = TRUE;
                        }
                        else if (tmode == TFM_RESIZE) {
                                if (v3d->around == V3D_ACTIVE) {
                                        if (ob != OBACT)
-                                               doLoc = 1;
+                                               do_loc = TRUE;
                                }
                                else if (v3d->around == V3D_CURSOR)
-                                       doLoc = 1;
+                                       do_loc = TRUE;
                                
                                if ((v3d->flag & V3D_ALIGN)==0)
-                                       doScale = 1;
+                                       do_scale = TRUE;
                        }
                        
                        /* insert keyframes for the affected sets of channels using the builtin KeyingSets found */
-                       if (doLoc) {
+                       if (do_loc) {
                                KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_LOCATION_ID);
                                ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra);
                        }
-                       if (doRot) {
+                       if (do_rot) {
                                KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_ROTATION_ID);
                                ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra);
                        }
-                       if (doScale) {
+                       if (do_scale) {
                                KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_SCALING_ID);
                                ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra);
                        }
@@ -4692,39 +4740,39 @@ void autokeyframe_pose_cb_func(bContext *C, Scene *scene, View3D *v3d, Object *o
                                }
                                /* only insert keyframe if needed? */
                                else if (IS_AUTOKEY_FLAG(scene, INSERTNEEDED)) {
-                                       short doLoc=0, doRot=0, doScale=0;
+                                       short do_loc = FALSE, do_rot = FALSE, do_scale = FALSE;
                                        
                                        /* filter the conditions when this happens (assume that curarea->spacetype==SPACE_VIE3D) */
                                        if (tmode == TFM_TRANSLATION) {
                                                if (targetless_ik)
-                                                       doRot= 1;
+                                                       do_rot = TRUE;
                                                else
-                                                       doLoc = 1;
+                                                       do_loc = TRUE;
                                        }
                                        else if (tmode == TFM_ROTATION) {
                                                if (ELEM(v3d->around, V3D_CURSOR, V3D_ACTIVE))
-                                                       doLoc = 1;
+                                                       do_loc = TRUE;
                                                        
                                                if ((v3d->flag & V3D_ALIGN)==0)
-                                                       doRot = 1;
+                                                       do_rot = TRUE;
                                        }
                                        else if (tmode == TFM_RESIZE) {
                                                if (ELEM(v3d->around, V3D_CURSOR, V3D_ACTIVE))
-                                                       doLoc = 1;
+                                                       do_loc = TRUE;
                                                        
                                                if ((v3d->flag & V3D_ALIGN)==0)
-                                                       doScale = 1;
+                                                       do_scale = TRUE;
                                        }
                                        
-                                       if (doLoc) {
+                                       if (do_loc) {
                                                KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_LOCATION_ID);
                                                ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra);
                                        }
-                                       if (doRot) {
+                                       if (do_rot) {
                                                KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_ROTATION_ID);
                                                ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra);
                                        }
-                                       if (doScale) {
+                                       if (do_scale) {
                                                KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_SCALING_ID);
                                                ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra);
                                        }
@@ -4816,7 +4864,7 @@ void special_aftertrans_update(bContext *C, TransInfo *t)
                /* marker transform, not especially nice but we may want to move markers
                 * at the same time as keyframes in the dope sheet. */
                if ((sseq->flag & SEQ_MARKER_TRANS) && (canceled == 0)) {
-                       /* cant use TFM_TIME_EXTEND
+                       /* cant use TFM_TIME_EXTEND
                         * for some reason EXTEND is changed into TRANSLATE, so use frame_side instead */
 
                        if (t->mode == TFM_SEQ_SLIDE) {
@@ -4831,10 +4879,11 @@ void special_aftertrans_update(bContext *C, TransInfo *t)
        }
        else if (t->spacetype == SPACE_NODE) {
                SpaceNode *snode= (SpaceNode *)t->sa->spacedata.first;
-               ED_node_update_hierarchy(C, snode->edittree);
-               
-               if (canceled == 0)
+               if (canceled == 0) {
+                       ED_node_post_apply_transform(C, snode->edittree);
+                       
                        ED_node_link_insert(t->sa);
+               }
                
                /* clear link line */
                ED_node_link_intersect_test(t->sa, 0);
@@ -4861,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) {
@@ -5080,7 +5136,7 @@ void special_aftertrans_update(bContext *C, TransInfo *t)
                         * we need to update the pose otherwise no updates get called during
                         * transform and the auto-ik is not applied. see [#26164] */
                        struct Object *pose_ob=t->poseobj;
-                       where_is_pose(t->scene, pose_ob);
+                       BKE_pose_where_is(t->scene, pose_ob);
                }
 
                /* set BONE_TRANSFORM flags for autokey, manipulator draw might have changed them */
@@ -5175,7 +5231,7 @@ void special_aftertrans_update(bContext *C, TransInfo *t)
                        /* recalculating the frame positions means we loose our original transform if its not auto-keyed [#24451]
                         * this hack re-applies it, which is annoying, only alternatives are...
                         * - don't recalc paths.
-                        * - have an object_handle_update() which gives is the new transform without touching the objects.
+                        * - have an BKE_object_handle_update() which gives is the new transform without touching the objects.
                         * - only recalc paths on auto-keying.
                         * - ED_objects_recalculate_paths could backup/restore transforms.
                         * - re-apply the transform which is simplest in this case. (2 lines below)
@@ -5357,23 +5413,24 @@ typedef struct TransDataTracking {
        short coord;
 } TransDataTracking;
 
-static void markerToTransDataInit(TransData *td, TransData2D *td2d, TransDataTracking *tdt, MovieTrackingTrack *track,
-                                  int area, float *loc, float *rel, float *off)
+static void markerToTransDataInit(TransData *td, TransData2D *td2d, TransDataTracking *tdt,
+                                  MovieTrackingTrack *track, MovieTrackingMarker *marker,
+                                  int area, float loc[2], float rel[2], const float off[2], float aspx, float aspy)
 {
        int anchor = area == TRACK_AREA_POINT && off;
 
        tdt->mode = transDataTracking_ModeTracks;
 
        if (anchor) {
-               td2d->loc[0] = rel[0]; /* hold original location */
-               td2d->loc[1] = rel[1];
+               td2d->loc[0] = rel[0] * aspx; /* hold original location */
+               td2d->loc[1] = rel[1] * aspy;
 
                tdt->loc= loc;
                td2d->loc2d = loc; /* current location */
        }
        else {
-               td2d->loc[0] = loc[0]; /* hold original location */
-               td2d->loc[1] = loc[1];
+               td2d->loc[0] = loc[0] * aspx; /* hold original location */
+               td2d->loc[1] = loc[1] * aspy;
 
                td2d->loc2d = loc; /* current location */
        }
@@ -5387,8 +5444,8 @@ static void markerToTransDataInit(TransData *td, TransData2D *td2d, TransDataTra
 
        if (rel) {
                if (!anchor) {
-                       td2d->loc[0] += rel[0];
-                       td2d->loc[1] += rel[1];
+                       td2d->loc[0] += rel[0] * aspx;
+                       td2d->loc[1] += rel[1] * aspy;
                }
 
                copy_v2_v2(tdt->srelative, rel);
@@ -5399,9 +5456,12 @@ static void markerToTransDataInit(TransData *td, TransData2D *td2d, TransDataTra
 
        td->flag = 0;
        td->loc = td2d->loc;
-       copy_v3_v3(td->center, td->loc);
        copy_v3_v3(td->iloc, td->loc);
 
+       //copy_v3_v3(td->center, td->loc);
+       td->center[0] = marker->pos[0] * aspx;
+       td->center[1] = marker->pos[1] * aspy;
+
        memset(td->axismtx, 0, sizeof(td->axismtx));
        td->axismtx[2][2] = 1.0f;
 
@@ -5416,26 +5476,36 @@ static void markerToTransDataInit(TransData *td, TransData2D *td2d, TransDataTra
 }
 
 static void trackToTransData(SpaceClip *sc, TransData *td, TransData2D *td2d,
-                             TransDataTracking *tdt, MovieTrackingTrack *track)
+                             TransDataTracking *tdt, MovieTrackingTrack *track, float aspx, float aspy)
 {
        MovieTrackingMarker *marker = BKE_tracking_ensure_marker(track, sc->user.framenr);
 
        tdt->flag = marker->flag;
-       marker->flag &= ~(MARKER_DISABLED|MARKER_TRACKED);
+       marker->flag &= ~(MARKER_DISABLED | MARKER_TRACKED);
 
-       markerToTransDataInit(td++, td2d++, tdt++, track, TRACK_AREA_POINT, track->offset, marker->pos, track->offset);
+       markerToTransDataInit(td++, td2d++, tdt++, track, marker, TRACK_AREA_POINT,
+                             track->offset, marker->pos, track->offset, aspx, aspy);
 
-       if (track->flag & SELECT)
-               markerToTransDataInit(td++, td2d++, tdt++, track, TRACK_AREA_POINT, marker->pos, NULL, NULL);
+       if (track->flag & SELECT) {
+               markerToTransDataInit(td++, td2d++, tdt++, track, marker, TRACK_AREA_POINT,
+                                     marker->pos, NULL, NULL, aspx, aspy);
+       }
 
        if (track->pat_flag & SELECT) {
-               markerToTransDataInit(td++, td2d++, tdt++, track, TRACK_AREA_PAT, track->pat_min, marker->pos, NULL);
-               markerToTransDataInit(td++, td2d++, tdt++, track, TRACK_AREA_PAT, track->pat_max, marker->pos, NULL);
+               int a;
+
+               for (a = 0; a < 4; a++) {
+                       markerToTransDataInit(td++, td2d++, tdt++, track, marker, TRACK_AREA_PAT,
+                                             marker->pattern_corners[a], marker->pos, NULL, aspx, aspy);
+               }
        }
 
        if (track->search_flag & SELECT) {
-               markerToTransDataInit(td++, td2d++, tdt++, track, TRACK_AREA_SEARCH, track->search_min, marker->pos, NULL);
-               markerToTransDataInit(td++, td2d++, tdt++, track, TRACK_AREA_SEARCH, track->search_max, marker->pos, NULL);
+               markerToTransDataInit(td++, td2d++, tdt++, track, marker, TRACK_AREA_SEARCH,
+                                     marker->search_min, marker->pos, NULL, aspx, aspy);
+
+               markerToTransDataInit(td++, td2d++, tdt++, track, marker, TRACK_AREA_SEARCH,
+                                     marker->search_max, marker->pos, NULL, aspx, aspy);
        }
 }
 
@@ -5462,6 +5532,7 @@ static void createTransTrackingTracksData(bContext *C, TransInfo *t)
        MovieTrackingMarker *marker;
        TransDataTracking *tdt;
        int framenr = sc->user.framenr;
+       float aspx, aspy;
 
        /* count */
        t->total = 0;
@@ -5477,7 +5548,7 @@ static void createTransTrackingTracksData(bContext *C, TransInfo *t)
                                t->total++;
 
                        if (track->pat_flag & SELECT)
-                               t->total+= 2;
+                               t->total+= 4;
 
                        if (track->search_flag & SELECT)
                                t->total+= 2;
@@ -5489,6 +5560,8 @@ static void createTransTrackingTracksData(bContext *C, TransInfo *t)
        if (t->total == 0)
                return;
 
+       ED_space_clip_aspect_dimension_aware(sc, &aspx, &aspy);
+
        td = t->data = MEM_callocN(t->total*sizeof(TransData), "TransTracking TransData");
        td2d = t->data2d = MEM_callocN(t->total*sizeof(TransData2D), "TransTracking TransData2D");
        tdt = t->customData = MEM_callocN(t->total*sizeof(TransDataTracking), "TransTracking TransDataTracking");
@@ -5501,25 +5574,23 @@ static void createTransTrackingTracksData(bContext *C, TransInfo *t)
                if (TRACK_VIEW_SELECTED(sc, track) && (track->flag & TRACK_LOCKED) == 0) {
                        marker = BKE_tracking_get_marker(track, framenr);
 
-                       trackToTransData(sc, td, td2d, tdt, track);
+                       trackToTransData(sc, td, td2d, tdt, track, aspx, aspy);
 
                        /* offset */
                        td++;
                        td2d++;
                        tdt++;
 
-                       if ((marker->flag & MARKER_DISABLED) == 0) {
-                               if (track->flag & SELECT) {
-                                       td++;
-                                       td2d++;
-                                       tdt++;
-                               }
+                       if (track->flag & SELECT) {
+                               td++;
+                               td2d++;
+                               tdt++;
+                       }
 
-                               if (track->pat_flag & SELECT) {
-                                       td += 2;
-                                       td2d += 2;
-                                       tdt +=2;
-                               }
+                       if (track->pat_flag & SELECT) {
+                               td += 4;
+                               td2d += 4;
+                               tdt += 4;
                        }
 
                        if (track->search_flag & SELECT) {
@@ -5671,9 +5742,6 @@ static void createTransTrackingData(bContext *C, TransInfo *t)
        if (!clip || width == 0 || height == 0)
                return;
 
-       if (!ELEM(t->mode, TFM_RESIZE, TFM_TRANSLATION))
-               return;
-
        if (ar->regiontype == RGN_TYPE_PREVIEW) {
                /* transformation was called from graph editor */
                createTransTrackingCurvesData(C, t);
@@ -5741,10 +5809,14 @@ static void cancelTransTracking(TransInfo *t)
 
 void flushTransTracking(TransInfo *t)
 {
+       SpaceClip *sc = t->sa->spacedata.first;
        TransData *td;
        TransData2D *td2d;
        TransDataTracking *tdt;
        int a;
+       float aspx, aspy;
+
+       ED_space_clip_aspect_dimension_aware(sc, &aspx, &aspy);
 
        if (t->state == TRANS_CANCEL)
                cancelTransTracking(t);
@@ -5752,31 +5824,46 @@ void flushTransTracking(TransInfo *t)
        /* flush to 2d vector from internally used 3d vector */
        for (a=0, td= t->data, td2d= t->data2d, tdt= t->customData; a<t->total; a++, td2d++, td++, tdt++) {
                if (tdt->mode == transDataTracking_ModeTracks) {
-                       if (t->flag & T_ALT_TRANSFORM) {
-                               if (tdt->area == TRACK_AREA_POINT && tdt->relative) {
-                                       float d[2], d2[2];
+                       float loc2d[2];
 
-                                       if (!tdt->smarkers) {
-                                               tdt->smarkers = MEM_callocN(sizeof(*tdt->smarkers)*tdt->markersnr, "flushTransTracking markers");
-                                               for (a = 0; a < tdt->markersnr; a++)
-                                                       copy_v2_v2(tdt->smarkers[a], tdt->markers[a].pos);
-                                       }
+                       if (t->mode == TFM_ROTATION && tdt->area == TRACK_AREA_SEARCH) {
+                               continue;
+                       }
+
+                       loc2d[0] = td2d->loc[0] / aspx;
+                       loc2d[1] = td2d->loc[1] / aspy;
 
-                                       sub_v2_v2v2(d, td2d->loc, tdt->soffset);
-                                       sub_v2_v2(d, tdt->srelative);
+                       if (t->flag & T_ALT_TRANSFORM) {
+                               if (t->mode == TFM_RESIZE) {
+                                       if (tdt->area != TRACK_AREA_PAT)
+                                               continue;
+                               }
+                               else if (t->mode == TFM_TRANSLATION) {
+                                       if (tdt->area == TRACK_AREA_POINT && tdt->relative) {
+                                               float d[2], d2[2];
+
+                                               if (!tdt->smarkers) {
+                                                       tdt->smarkers = MEM_callocN(sizeof(*tdt->smarkers)*tdt->markersnr, "flushTransTracking markers");
+                                                       for (a = 0; a < tdt->markersnr; a++)
+                                                               copy_v2_v2(tdt->smarkers[a], tdt->markers[a].pos);
+                                               }
+
+                                               sub_v2_v2v2(d, loc2d, tdt->soffset);
+                                               sub_v2_v2(d, tdt->srelative);
 
-                                       sub_v2_v2v2(d2, td2d->loc, tdt->srelative);
+                                               sub_v2_v2v2(d2, loc2d, tdt->srelative);
 
-                                       for (a= 0; a<tdt->markersnr; a++)
-                                               add_v2_v2v2(tdt->markers[a].pos, tdt->smarkers[a], d2);
+                                               for (a= 0; a<tdt->markersnr; a++)
+                                                       add_v2_v2v2(tdt->markers[a].pos, tdt->smarkers[a], d2);
 
-                                       negate_v2_v2(td2d->loc2d, d);
+                                               negate_v2_v2(td2d->loc2d, d);
+                                       }
                                }
                        }
 
                        if (tdt->area!=TRACK_AREA_POINT || tdt->relative==0) {
-                               td2d->loc2d[0] = td2d->loc[0];
-                               td2d->loc2d[1] = td2d->loc[1];
+                               td2d->loc2d[0] = loc2d[0];
+                               td2d->loc2d[1] = loc2d[1];
 
                                if (tdt->relative)
                                        sub_v2_v2(td2d->loc2d, tdt->relative);
@@ -5791,24 +5878,27 @@ void flushTransTracking(TransInfo *t)
 /* * masking * */
 
 typedef struct TransDataMasking{
-       float is_handle;
+       int   is_handle;
 
        float handle[2], orig_handle[2];
        float vec[3][3];
        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
@@ -5831,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);
@@ -5842,12 +5934,9 @@ static void MaskPointToTransData(SpaceClip *sc, MaskSplinePoint *point, TransDat
                }
        }
        else {
-               int width, height;
-
                tdm->is_handle = TRUE;
 
-               ED_space_clip_mask_size(sc, &width, &height);
-               BKE_mask_point_handle(point, width, height, tdm->handle);
+               BKE_mask_point_handle(point, tdm->handle);
 
                copy_v2_v2(tdm->orig_handle, tdm->handle);
 
@@ -5867,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);
@@ -5882,39 +5974,44 @@ static void createTransMaskingData(bContext *C, TransInfo *t)
 {
        SpaceClip *sc = CTX_wm_space_clip(C);
        Mask *mask = CTX_data_edit_mask(C);
-       MaskShape *shape;
+       MaskLayer *masklay;
        TransData *td = NULL;
        TransData2D *td2d = NULL;
        TransDataMasking *tdm = NULL;
+       int count = 0, countsel = 0;
+       int propmode = t->flag & T_PROP_EDIT;
 
        /* count */
-       shape = mask->shapes.first;
-       while (shape) {
-               MaskSpline *spline = shape->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;
+                       }
                }
-
-               shape = shape->next;
        }
 
-       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 */
@@ -5924,20 +6021,23 @@ static void createTransMaskingData(bContext *C, TransInfo *t)
        t->flag |= T_FREE_CUSTOMDATA;
 
        /* create data */
-       shape = mask->shapes.first;
-       while (shape) {
-               MaskSpline *spline = shape->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;
@@ -5949,11 +6049,7 @@ static void createTransMaskingData(bContext *C, TransInfo *t)
                                        }
                                }
                        }
-
-                       spline = spline->next;
                }
-
-               shape = shape->next;
        }
 }
 
@@ -5975,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);
        }
 }
 
@@ -6048,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;
@@ -6105,7 +6208,7 @@ void createTransData(bContext *C, TransInfo *t)
                 * lines below just check is also visible */
                Object *ob_armature= modifiers_isDeformedByArmature(ob);
                if (ob_armature && ob_armature->mode & OB_MODE_POSE) {
-                       Base *base_arm= object_in_scene(ob_armature, t->scene);
+                       Base *base_arm= BKE_scene_base_find(t->scene, ob_armature);
                        if (base_arm) {
                                View3D *v3d = t->view;
                                if (BASE_VISIBLE(v3d, base_arm)) {