Small refactor of mask sliding operator
[blender.git] / source / blender / editors / transform / transform_conversions.c
index 859ae1e1b1bb282521fb0c329f78e1ccfcd6d870..8a7caeb30601325de16a37cd325c9666415a7940 100644 (file)
@@ -53,6 +53,7 @@
 #include "DNA_meshdata_types.h"
 #include "DNA_gpencil_types.h"
 #include "DNA_movieclip_types.h"
+#include "DNA_mask_types.h"
 
 #include "MEM_guardedalloc.h"
 
@@ -87,6 +88,7 @@
 #include "BKE_sequencer.h"
 #include "BKE_tessmesh.h"
 #include "BKE_tracking.h"
+#include "BKE_mask.h"
 
 
 #include "ED_anim_api.h"
 #include "ED_types.h"
 #include "ED_uvedit.h"
 #include "ED_clip.h"
+#include "ED_mask.h"
 #include "ED_util.h"  /* for crazyspace correction */
 
 #include "WM_api.h"            /* for WM_event_add_notifier to deal with stabilization nodes */
@@ -266,7 +269,7 @@ static void createTransTexspace(TransInfo *t)
        }
 
        id = ob->data;
-       if (id == NULL || !ELEM3( GS(id->name), ID_ME, ID_CU, ID_MB )) {
+       if (id == NULL || !ELEM3(GS(id->name), ID_ME, ID_CU, ID_MB )) {
                t->total = 0;
                return;
        }
@@ -284,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;
        }
@@ -418,58 +421,13 @@ static short apply_targetless_ik(Object *ob)
                                /* pose_mat(b) = pose_mat(b-1) * offs_bone * channel * constraint * IK  */
                                /* we put in channel the entire result of rmat= (channel * constraint * IK) */
                                /* pose_mat(b) = pose_mat(b-1) * offs_bone * rmat  */
-                               /* rmat = pose_mat(b) * inv( pose_mat(b-1) * offs_bone ) */
+                               /* rmat = pose_mat(b) * inv(pose_mat(b-1) * offs_bone ) */
 
                                parchan= chanlist[segcount-1];
                                bone= parchan->bone;
                                bone->flag |= BONE_TRANSFORM;   /* ensures it gets an auto key inserted */
 
-       /* XXX Old code. Will remove it later. */
-#if 0
-                               if (parchan->parent) {
-                                       Bone *parbone= parchan->parent->bone;
-                                       float offs_bone[4][4];
-
-                                       /* offs_bone =  yoffs(b-1) + root(b) + bonemat(b) */
-                                       copy_m4_m3(offs_bone, bone->bone_mat);
-
-                                       /* The bone's root offset (is in the parent's coordinate system) */
-                                       copy_v3_v3(offs_bone[3], bone->head);
-
-                                       /* Get the length translation of parent (length along y axis) */
-                                       offs_bone[3][1]+= parbone->length;
-
-                                       /* pose_mat(b-1) * offs_bone */
-                                       if (parchan->bone->flag & BONE_HINGE) {
-                                               /* the rotation of the parent restposition */
-                                               copy_m4_m4(rmat, parbone->arm_mat);     /* rmat used as temp */
-
-                                               /* the location of actual parent transform */
-                                               copy_v3_v3(rmat[3], offs_bone[3]);
-                                               offs_bone[3][0]= offs_bone[3][1]= offs_bone[3][2]= 0.0f;
-                                               mul_m4_v3(parchan->parent->pose_mat, rmat[3]);
-
-                                               mult_m4_m4m4(tmat, rmat, offs_bone);
-                                       }
-                                       else if (parchan->bone->flag & BONE_NO_SCALE) {
-                                               mult_m4_m4m4(tmat, parchan->parent->pose_mat, offs_bone);
-                                               normalize_m4(tmat);
-                                       }
-                                       else
-                                               mult_m4_m4m4(tmat, parchan->parent->pose_mat, offs_bone);
-
-                                       invert_m4_m4(imat, tmat);
-                               }
-                               else {
-                                       copy_m4_m3(tmat, bone->bone_mat);
-
-                                       copy_v3_v3(tmat[3], bone->head);
-                                       invert_m4_m4(imat, tmat);
-                               }
-                               /* result matrix */
-                               mult_m4_m4m4(rmat, imat, parchan->pose_mat);
-#endif
-                               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 */
                                {
@@ -484,25 +442,25 @@ static short apply_targetless_ik(Object *ob)
                                                 * and applied poses.
                                                 */
                                        if (parchan->rotmode > 0)
-                                               mat3_to_eulO(parchan->eul, parchan->rotmode,rmat3);
+                                               mat3_to_eulO(parchan->eul, parchan->rotmode, rmat3);
                                        else if (parchan->rotmode == ROT_MODE_AXISANGLE)
-                                               mat3_to_axis_angle(parchan->rotAxis, &parchan->rotAngle,rmat3);
+                                               mat3_to_axis_angle(parchan->rotAxis, &parchan->rotAngle, rmat3);
                                        else
-                                               mat3_to_quat(parchan->quat,rmat3);
+                                               mat3_to_quat(parchan->quat, rmat3);
                                        
                                        /* for size, remove rotation */
                                        /* causes problems with some constraints (so apply only if needed) */
                                        if (data->flag & CONSTRAINT_IK_STRETCH) {
                                                if (parchan->rotmode > 0)
-                                                       eulO_to_mat3( qrmat,parchan->eul, parchan->rotmode);
+                                                       eulO_to_mat3(qrmat, parchan->eul, parchan->rotmode);
                                                else if (parchan->rotmode == ROT_MODE_AXISANGLE)
-                                                       axis_angle_to_mat3( qrmat,parchan->rotAxis, parchan->rotAngle);
+                                                       axis_angle_to_mat3(qrmat, parchan->rotAxis, parchan->rotAngle);
                                                else
-                                                       quat_to_mat3( qrmat,parchan->quat);
+                                                       quat_to_mat3(qrmat, parchan->quat);
                                                
                                                invert_m3_m3(imat3, qrmat);
                                                mul_m3_m3m3(smat, rmat3, imat3);
-                                               mat3_to_size( parchan->size,smat);
+                                               mat3_to_size(parchan->size, smat);
                                        }
                                        
                                        /* causes problems with some constraints (e.g. childof), so disable this */
@@ -580,66 +538,35 @@ 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);
 
-               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);
-               }
-               else
-                       mul_serie_m3(td->mtx, pmat, omat, NULL, NULL,NULL,NULL,NULL,NULL);
-       }
-
-       /* XXX Old code. Will remove it later. */
-#if 0
-       if (ELEM(t->mode, TFM_TRANSLATION, TFM_RESIZE) && (pchan->bone->flag & BONE_NO_LOCAL_LOCATION))
-               unit_m3(bmat);
-       else
-               copy_m3_m3(bmat, pchan->bone->bone_mat);
-
-       if (pchan->parent) {
-               if (pchan->bone->flag & BONE_HINGE) {
-                       copy_m3_m4(pmat, pchan->parent->bone->arm_mat);
-                       if (!(pchan->bone->flag & BONE_NO_SCALE)) {
-                               float tsize[3], tsmat[3][3];
-                               mat4_to_size(tsize, pchan->parent->pose_mat);
-                               size_to_mat3(tsmat, tsize);
-                               mul_m3_m3m3(pmat, tsmat, pmat);
-                       }
-               }
-               else {
-                       copy_m3_m4(pmat, pchan->parent->pose_mat);
-                       if (pchan->bone->flag & BONE_NO_SCALE)
-                               normalize_m3(pmat);
-               }
+               /* 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, bmat, pmat, omat, cmat, NULL,NULL,NULL,NULL);
+                       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, bmat, pmat, omat, NULL,NULL,NULL,NULL,NULL);
-       }
-       else {
-               if (constraints_list_needinv(t, &pchan->constraints)) {
-                       copy_m3_m4(tmat, pchan->constinv);
-                       invert_m3_m3(cmat, tmat);
-                       mul_serie_m3(td->mtx, bmat, omat, cmat, 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);
                }
-               else
-                       mul_m3_m3m3(td->mtx, omat, bmat);
+               invert_m3_m3(td->ext->r_smtx, td->ext->r_mtx);
        }
-# endif
 
        invert_m3_m3(td->smtx, td->mtx);
 
@@ -705,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) &&
@@ -768,7 +694,7 @@ int count_set_pose_transflags(int *out_mode, short around, Object *ob)
                        total++;
                        
                        if (mode == TFM_TRANSLATION) {
-                               if ( has_targetless_ik(pchan)==NULL ) {
+                               if (has_targetless_ik(pchan) == NULL) {
                                        if (pchan->parent && (pchan->bone->flag & BONE_CONNECTED)) {
                                                if (pchan->bone->flag & BONE_HINGE_CHILD_TRANSFORM)
                                                        hastranslation = 1;
@@ -783,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;
        }
 
@@ -821,7 +746,7 @@ static void pchan_autoik_adjust (bPoseChannel *pchan, short chainlen)
 }
 
 /* change the chain-length of auto-ik */
-void transform_autoik_update (TransInfo *t, short mode)
+void transform_autoik_update(TransInfo *t, short mode)
 {
        short *chainlen= &t->settings->autoik_chainlen;
        bPoseChannel *pchan;
@@ -973,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);
        }
@@ -1042,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) {
@@ -1112,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++;
                        }
@@ -1141,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;
 
@@ -1166,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);
@@ -1186,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;
@@ -1217,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;
@@ -1233,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;
@@ -1248,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;
                                        }
 
@@ -1259,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;
@@ -1484,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]);
@@ -1546,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]);
@@ -1703,7 +1615,7 @@ static void createTransParticleVerts(bContext *C, TransInfo *t)
        PTCacheEditPoint *point;
        PTCacheEditKey *key;
        float mat[4][4];
-       int i,k, transformparticle;
+       int i, k, transformparticle;
        int count = 0, hasselected = 0;
        int propmode = t->flag & T_PROP_EDIT;
 
@@ -1712,7 +1624,7 @@ static void createTransParticleVerts(bContext *C, TransInfo *t)
        psys = edit->psys;
 
        if (psys)
-               psmd = psys_get_modifier(ob,psys);
+               psmd = psys_get_modifier(ob, psys);
 
        base->flag |= BA_HAS_RECALC_DATA;
 
@@ -1752,7 +1664,7 @@ static void createTransParticleVerts(bContext *C, TransInfo *t)
 
        unit_m4(mat);
 
-       invert_m4_m4(ob->imat,ob->obmat);
+       invert_m4_m4(ob->imat, ob->obmat);
 
        for (i=0, point=edit->points; i<edit->totpoint; i++, point++) {
                TransData *head, *tail;
@@ -1835,7 +1747,7 @@ void flushTransParticles(TransInfo *t)
 
                if (psys && !(psys->flag & PSYS_GLOBAL_HAIR)) {
                        psys_mat_hair_to_global(ob, psmd->dm, psys->part->from, psys->particles + i, mat);
-                       invert_m4_m4(imat,mat);
+                       invert_m4_m4(imat, mat);
 
                        for (k=0, key=point->keys; k<point->totkey; k++, key++) {
                                copy_v3_v3(co, key->world_co);
@@ -1976,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)
@@ -2010,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;
@@ -2030,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;
        }
@@ -2122,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);
@@ -2142,7 +2069,7 @@ static void createTransEditVerts(bContext *C, TransInfo *t)
                         * the modifiers that support deform matrices (defcos) */
                        if (totleft > 0) {
                                mappedcos= crazyspace_get_mapped_editverts(t->scene, t->obedit);
-                               quats= MEM_mallocN( (t->total)*sizeof(float)*4, "crazy quats");
+                               quats= MEM_mallocN((t->total)*sizeof(float)*4, "crazy quats");
                                crazyspace_set_quats_editmesh(em, (float*)defcos, mappedcos, quats); /* BMESH_TODO, abuses vertex index, should use an int array */
                                if (mappedcos)
                                        MEM_freeN(mappedcos);
@@ -2158,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;
                                }
@@ -2174,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;
@@ -2220,7 +2148,7 @@ static void createTransEditVerts(bContext *C, TransInfo *t)
                                }
 
                                /* Mirror? */
-                               if ( (mirror>0 && tob->iloc[0]>0.0f) || (mirror<0 && tob->iloc[0]<0.0f)) {
+                               if ((mirror>0 && tob->iloc[0]>0.0f) || (mirror<0 && tob->iloc[0]<0.0f)) {
                                        BMVert *vmir= EDBM_verts_mirror_get(em, eve); //t->obedit, em, eve, tob->iloc, a);
                                        if (vmir && vmir != eve) {
                                                tob->extra = vmir;
@@ -2231,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;
                        }
                }
@@ -2276,7 +2201,6 @@ void flushTransNodes(TransInfo *t)
        if (t->total==1) {
                ED_node_link_intersect_test(t->sa, 1);
        }
-       
 }
 
 /* *** SEQUENCE EDITOR *** */
@@ -2288,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;
@@ -2381,7 +2305,7 @@ void flushTransSeq(TransInfo *t)
                        if (seq->depth==0) {
                                /* test overlap, displayes red outline */
                                seq->flag &= ~SEQ_OVERLAP;
-                               if ( seq_test_overlap(seqbasep, seq) ) {
+                               if (seq_test_overlap(seqbasep, seq)) {
                                        seq->flag |= SEQ_OVERLAP;
                                }
                        }
@@ -3074,14 +2998,14 @@ typedef struct tGPFtransdata {
 } tGPFtransdata;
 
 /* This function helps flush transdata written to tempdata into the gp-frames  */
-void flushTransGPactionData (TransInfo *t)
+void flushTransGPactionData(TransInfo *t)
 {
        tGPFtransdata *tfd;
        int i;
 
        /* find the first one to start from */
        if (t->mode == TFM_TIME_SLIDE)
-               tfd= (tGPFtransdata *)( (float *)(t->customData) + 2 );
+               tfd= (tGPFtransdata *)((float *)(t->customData) + 2);
        else
                tfd= (tGPFtransdata *)(t->customData);
 
@@ -3200,7 +3124,7 @@ static void createTransActionData(bContext *C, TransInfo *t)
        if (ac.datatype == ANIMCONT_GPENCIL) {
                if (t->mode == TFM_TIME_SLIDE) {
                        t->customData= MEM_callocN((sizeof(float)*2)+(sizeof(tGPFtransdata)*count), "TimeSlide + tGPFtransdata");
-                       tfd= (tGPFtransdata *)( (float *)(t->customData) + 2 );
+                       tfd= (tGPFtransdata *)((float *)(t->customData) + 2);
                }
                else {
                        t->customData= MEM_callocN(sizeof(tGPFtransdata)*count, "tGPFtransdata");
@@ -3555,9 +3479,9 @@ static void createTransGraphEditData(bContext *C, TransInfo *t)
                                 *        then check if we're using auto-handles.
                                 *      - If so, change them auto-handles to aligned handles so that handles get affected too
                                 */
-                               if ( ELEM(bezt->h1, HD_AUTO, HD_AUTO_ANIM) &&
-                                    ELEM(bezt->h2, HD_AUTO, HD_AUTO_ANIM) &&
-                                    ELEM(t->mode, TFM_ROTATION, TFM_RESIZE))
+                               if (ELEM(bezt->h1, HD_AUTO, HD_AUTO_ANIM) &&
+                                   ELEM(bezt->h2, HD_AUTO, HD_AUTO_ANIM) &&
+                                   ELEM(t->mode, TFM_ROTATION, TFM_RESIZE))
                                {
                                        if (hdata && (sel1) && (sel3)) {
                                                bezt->h1= HD_ALIGN;
@@ -3646,8 +3570,8 @@ static void sort_time_beztmaps (BeztMap *bezms, int totvert, const short UNUSED(
                         * optimization: this only needs to be performed in the first loop
                         */
                        if (bezm->swapHs == 0) {
-                               if ( (bezm->bezt->vec[0][0] > bezm->bezt->vec[1][0]) &&
-                                        (bezm->bezt->vec[2][0] < bezm->bezt->vec[1][0]) )
+                               if ((bezm->bezt->vec[0][0] > bezm->bezt->vec[1][0]) &&
+                                   (bezm->bezt->vec[2][0] < bezm->bezt->vec[1][0]) )
                                {
                                        /* handles need to be swapped */
                                        bezm->swapHs = 1;
@@ -3746,7 +3670,7 @@ static void beztmap_to_data (TransInfo *t, FCurve *fcu, BeztMap *bezms, int totv
  * anim_data is the list of channels (F-Curves) retrieved already containing the
  * channels to work on. It should not be freed here as it may still need to be used.
  */
-void remake_graph_transdata (TransInfo *t, ListBase *anim_data)
+void remake_graph_transdata(TransInfo *t, ListBase *anim_data)
 {
        SpaceIpo *sipo = (SpaceIpo *)t->sa->spacedata.first;
        bAnimListElem *ale;
@@ -3801,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 */
@@ -3811,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);
@@ -3853,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;
                        }
                }
        }
@@ -3904,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)) {
@@ -3922,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;
                                }
                        }
                }
@@ -3933,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
                }
@@ -3966,7 +3890,7 @@ static int SeqTransCount(TransInfo *t, Sequence *parent, ListBase *seqbase, int
        for (seq= seqbase->first; seq; seq= seq->next) {
                seq->depth= depth;
 
-               /* seq->tmp is used by seq_tx_get_final_{left,right} to check sequence's range and clamp to it if needed.
+               /* seq->tmp is used by seq_tx_get_final_{left, right} to check sequence's range and clamp to it if needed.
                 * it's first place where digging into sequences tree, so store link to parent here */
                seq->tmp = parent;
 
@@ -4087,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;
@@ -4150,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 */
@@ -4187,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 */
@@ -4223,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;
@@ -4260,9 +4224,9 @@ static void createTransSeqData(bContext *C, TransInfo *t)
                                int i;
                                for (i=0; i<3; i++) {
                                        seq_user= *((&seq->seq1) + i);
-                                       if ( seq_user && (seq_user->flag & SELECT) &&
-                                            !(seq_user->flag & SEQ_LOCK) &&
-                                            !(seq_user->flag & (SEQ_LEFTSEL|SEQ_RIGHTSEL)))
+                                       if (seq_user && (seq_user->flag & SELECT) &&
+                                           !(seq_user->flag & SEQ_LOCK) &&
+                                           !(seq_user->flag & (SEQ_LEFTSEL|SEQ_RIGHTSEL)))
                                        {
                                                seq->flag |= SELECT;
                                        }
@@ -4365,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;
 
@@ -4427,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);
@@ -4464,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) {
@@ -4482,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;
@@ -4494,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 {
@@ -4543,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)) {
@@ -4560,8 +4524,8 @@ static int count_proportional_objects(TransInfo *t)
                /* mark all children */
                for (base= scene->base.first; base; base= base->next) {
                        /* all base not already selected or marked that is editable */
-                       if ( (base->object->flag & (SELECT|BA_TRANSFORM_CHILD|BA_TRANSFORM_PARENT)) == 0 &&
-                            (BASE_EDITABLE_BGMODE(v3d, scene, base)))
+                       if ((base->object->flag & (SELECT|BA_TRANSFORM_CHILD|BA_TRANSFORM_PARENT)) == 0 &&
+                           (BASE_EDITABLE_BGMODE(v3d, scene, base)))
                        {
                                mark_children(base->object);
                        }
@@ -4572,8 +4536,8 @@ static int count_proportional_objects(TransInfo *t)
                Object *ob= base->object;
 
                /* if base is not selected, not a parent of selection or not a child of selection and it is editable */
-               if ( (ob->flag & (SELECT|BA_TRANSFORM_CHILD|BA_TRANSFORM_PARENT)) == 0 &&
-                    (BASE_EDITABLE_BGMODE(v3d, scene, base)))
+               if ((ob->flag & (SELECT|BA_TRANSFORM_CHILD|BA_TRANSFORM_PARENT)) == 0 &&
+                   (BASE_EDITABLE_BGMODE(v3d, scene, base)))
                {
 
                        /* used for flush, depgraph will change recalcs if needed :) */
@@ -4655,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);
                        }
@@ -4776,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);
                                        }
@@ -4900,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) {
@@ -4915,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);
@@ -4935,6 +4900,24 @@ void special_aftertrans_update(bContext *C, TransInfo *t)
                                WM_event_add_notifier(C, NC_SCENE|ND_NODES, NULL);
                        }
                }
+               else if (t->options & CTX_MASK) {
+                       SpaceClip *sc = t->sa->spacedata.first;
+                       Mask *mask = ED_space_clip_mask(sc);
+
+                       if (t->scene->nodetree) {
+                               /* tracks can be used for stabilization nodes,
+                                * flush update for such nodes */
+                               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) {
                SpaceAction *saction= (SpaceAction *)t->sa->spacedata.first;
@@ -4964,8 +4947,8 @@ void special_aftertrans_update(bContext *C, TransInfo *t)
                                 * 2) canceled == 0        -> user confirmed the transform, so duplicates should be removed
                                 * 3) canceled + duplicate -> user canceled the transform, but we made duplicates, so get rid of these
                                 */
-                               if ( (saction->flag & SACTION_NOTRANSKEYCULL)==0 &&
-                                        ((canceled == 0) || (duplicate)) )
+                               if ((saction->flag & SACTION_NOTRANSKEYCULL)==0 &&
+                                   ((canceled == 0) || (duplicate)) )
                                {
                                        if (adt) {
                                                ANIM_nla_mapping_apply_fcurve(adt, fcu, 0, 1);
@@ -4995,8 +4978,8 @@ void special_aftertrans_update(bContext *C, TransInfo *t)
                         * 2) canceled == 0        -> user confirmed the transform, so duplicates should be removed
                         * 3) canceled + duplicate -> user canceled the transform, but we made duplicates, so get rid of these
                         */
-                       if ( (saction->flag & SACTION_NOTRANSKEYCULL)==0 &&
-                                ((canceled == 0) || (duplicate)) )
+                       if ((saction->flag & SACTION_NOTRANSKEYCULL)==0 &&
+                           ((canceled == 0) || (duplicate)))
                        {
                                posttrans_action_clean(&ac, (bAction *)ac.data);
                        }
@@ -5008,8 +4991,8 @@ void special_aftertrans_update(bContext *C, TransInfo *t)
                                 * 2) canceled == 0        -> user confirmed the transform, so duplicates should be removed
                                 * 3) canceled + duplicate -> user canceled the transform, but we made duplicates, so get rid of these
                                 */
-                       if ( (saction->flag & SACTION_NOTRANSKEYCULL)==0 &&
-                                ((canceled == 0) || (duplicate)) )
+                       if ((saction->flag & SACTION_NOTRANSKEYCULL)==0 &&
+                               ((canceled == 0) || (duplicate)))
                        {
                                bGPdata *gpd;
                                
@@ -5076,8 +5059,8 @@ void special_aftertrans_update(bContext *C, TransInfo *t)
                                 * 2) canceled == 0        -> user confirmed the transform, so duplicates should be removed
                                 * 3) canceled + duplicate -> user canceled the transform, but we made duplicates, so get rid of these
                                 */
-                               if ( (sipo->flag & SIPO_NOTRANSKEYCULL)==0 &&
-                                        ((canceled == 0) || (duplicate)) )
+                               if ((sipo->flag & SIPO_NOTRANSKEYCULL)==0 &&
+                                   ((canceled == 0) || (duplicate)))
                                {
                                        if (adt) {
                                                ANIM_nla_mapping_apply_fcurve(adt, fcu, 0, 0);
@@ -5153,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 */
@@ -5188,10 +5171,10 @@ void special_aftertrans_update(bContext *C, TransInfo *t)
                        DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
 
        }
-       else if ( (t->scene->basact) &&
-                 (ob = t->scene->basact->object) &&
-                 (ob->mode & OB_MODE_PARTICLE_EDIT) &&
-                 PE_get_current(t->scene, ob))
+       else if ((t->scene->basact) &&
+                (ob = t->scene->basact->object) &&
+                (ob->mode & OB_MODE_PARTICLE_EDIT) &&
+                PE_get_current(t->scene, ob))
        {
                /* do nothing */
        }
@@ -5248,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)
@@ -5291,7 +5274,8 @@ static void createTransObject(bContext *C, TransInfo *t)
        td = t->data = MEM_callocN(t->total*sizeof(TransData), "TransOb");
        tx = t->ext = MEM_callocN(t->total*sizeof(TransDataExtension), "TransObExtension");
 
-       CTX_DATA_BEGIN (C, Base*, base, selected_bases) {
+       CTX_DATA_BEGIN (C, Base*, base, selected_bases)
+       {
                Object *ob= base->object;
                
                td->flag = TD_SELECTED;
@@ -5429,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 */
        }
@@ -5459,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);
@@ -5471,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;
 
@@ -5488,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);
        }
 }
 
@@ -5534,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;
@@ -5549,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;
@@ -5561,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");
@@ -5573,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) {
@@ -5743,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);
@@ -5813,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);
@@ -5824,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;
+
+                       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, td2d->loc, tdt->soffset);
-                                       sub_v2_v2(d, tdt->srelative);
+                                               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);
@@ -5860,6 +5875,206 @@ void flushTransTracking(TransInfo *t)
        }
 }
 
+/* * masking * */
+
+typedef struct TransDataMasking{
+       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, 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 (propmode || is_sel_point) {
+               int i;
+               for (i = 0; i < 3; i++) {
+                       /* CV coords are scaled by aspects. this is needed for rotations and
+                        * proportional editing to be consistent with the stretched CV coords
+                        * that are displayed. this also means that for display and numinput,
+                        * and when the the CV coords are flushed, these are converted each time */
+                       td2d->loc[0] = bezt->vec[i][0]*aspx;
+                       td2d->loc[1] = bezt->vec[i][1]*aspy;
+                       td2d->loc[2] = 0.0f;
+                       td2d->loc2d = bezt->vec[i];
+
+                       td->flag = 0;
+                       td->loc = td2d->loc;
+                       copy_v3_v3(td->center, td->loc);
+                       copy_v3_v3(td->iloc, td->loc);
+
+                       memset(td->axismtx, 0, sizeof(td->axismtx));
+                       td->axismtx[2][2] = 1.0f;
+
+                       td->ext= NULL;
+                       td->val= NULL;
+
+                       if (is_sel_any) {
+                               td->flag |= TD_SELECTED;
+                       }
+                       td->dist= 0.0;
+
+                       unit_m3(td->mtx);
+                       unit_m3(td->smtx);
+
+                       td++;
+                       td2d++;
+               }
+       }
+       else {
+               tdm->is_handle = TRUE;
+
+               BKE_mask_point_handle(point, tdm->handle);
+
+               copy_v2_v2(tdm->orig_handle, tdm->handle);
+
+               td2d->loc[0] = tdm->handle[0]*aspx;
+               td2d->loc[1] = tdm->handle[1]*aspy;
+               td2d->loc[2] = 0.0f;
+               td2d->loc2d = tdm->handle;
+
+               td->flag = 0;
+               td->loc = td2d->loc;
+               copy_v3_v3(td->center, td->loc);
+               copy_v3_v3(td->iloc, td->loc);
+
+               memset(td->axismtx, 0, sizeof(td->axismtx));
+               td->axismtx[2][2] = 1.0f;
+
+               td->ext= NULL;
+               td->val= NULL;
+
+               if (is_sel_any) {
+                       td->flag |= TD_SELECTED;
+               }
+
+               td->dist= 0.0;
+
+               unit_m3(td->mtx);
+               unit_m3(td->smtx);
+
+               td++;
+               td2d++;
+       }
+}
+
+static void createTransMaskingData(bContext *C, TransInfo *t)
+{
+       SpaceClip *sc = CTX_wm_space_clip(C);
+       Mask *mask = CTX_data_edit_mask(C);
+       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 (masklay = mask->masklayers.first; masklay; masklay = masklay->next) {
+               MaskSpline *spline = masklay->splines.first;
+
+               if (masklay->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) {
+                       continue;
+               }
+
+               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_ANY(point)) {
+                                       if (MASKPOINT_ISSEL_KNOT(point))
+                                               countsel += 3;
+                                       else
+                                               countsel += 1;
+                               }
+
+                               if (propmode)
+                                       count += 3;
+                       }
+               }
+       }
+
+       /* 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 */
+       td2d = t->data2d = MEM_callocN(t->total*sizeof(TransData2D), "TransObData2D(Mask Editing)");
+       tdm = t->customData = MEM_callocN(t->total*sizeof(TransDataMasking), "TransDataMasking(Mask Editing)");
+
+       t->flag |= T_FREE_CUSTOMDATA;
+
+       /* create data */
+       for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) {
+               MaskSpline *spline = masklay->splines.first;
+
+               if (masklay->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) {
+                       continue;
+               }
+
+               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 (propmode || MASKPOINT_ISSEL_ANY(point)) {
+                                       MaskPointToTransData(sc, point, td, td2d, tdm, propmode);
+
+                                       if (propmode || MASKPOINT_ISSEL_KNOT(point)) {
+                                               td += 3;
+                                               td2d += 3;
+                                               tdm += 3;
+                                       }
+                                       else {
+                                               td++;
+                                               td2d++;
+                                               tdm++;
+                                       }
+                               }
+                       }
+               }
+       }
+}
+
+void flushTransMasking(TransInfo *t)
+{
+       SpaceClip *sc = t->sa->spacedata.first;
+       TransData2D *td;
+       TransDataMasking *tdm;
+       int a;
+       float aspx, aspy, invx, invy;
+
+       ED_space_clip_mask_aspect(sc, &aspx, &aspy);
+       invx = 1.0f/aspx;
+       invy = 1.0f/aspy;
+
+       /* flush to 2d vector from internally used 3d vector */
+       for(a=0, td = t->data2d, tdm = t->customData; a<t->total; a++, td++, tdm++) {
+               td->loc2d[0]= td->loc[0]*invx;
+               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, tdm->orig_handle, tdm->vec);
+       }
+}
+
 void createTransData(bContext *C, TransInfo *t)
 {
        Scene *scene = t->scene;
@@ -5929,6 +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) {
+                       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;
@@ -5984,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)) {