Merging r47572 through r47580 form trunk into soc-2011-tomato
authorSergey Sharybin <sergey.vfx@gmail.com>
Thu, 7 Jun 2012 18:08:57 +0000 (18:08 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Thu, 7 Jun 2012 18:08:57 +0000 (18:08 +0000)
1  2 
source/blender/blenkernel/intern/movieclip.c
source/blender/blenloader/intern/readfile.c
source/blender/blenloader/intern/writefile.c
source/blender/editors/space_clip/clip_draw.c
source/blender/editors/space_clip/tracking_ops.c
source/blender/editors/transform/transform_conversions.c

index 8d67d3bd02dd074bd9bcb20335f77c76f58f4ff7,985fc433c13ffbde18c913daddb3373be5b8f1e4..84d6141b470316d532afda712bcf7e5ba2dee4ec
@@@ -916,7 -916,17 +916,17 @@@ int BKE_movieclip_has_frame(MovieClip *
  
  void BKE_movieclip_get_size(MovieClip *clip, MovieClipUser *user, int *width, int *height)
  {
+ #if 0
+       /* originally was needed to support image sequences with different image dimensions,
+        * which might be useful for such things as reconstruction of unordered image sequence,
+        * or painting/rotoscoping of non-equal-sized images, but this ended up in unneeded
+        * cache lookups and even unwanted non-proxied files loading when doing mask parenting,
+        * so let's disable this for now and assume image sequence consists of images with
+        * equal sizes (sergey)
+        */
        if (user->framenr == clip->lastframe) {
+ #endif
+       if (clip->lastsize[0] != 0 && clip->lastsize[1] != 0) {
                *width = clip->lastsize[0];
                *height = clip->lastsize[1];
        }
@@@ -1077,18 -1087,10 +1087,18 @@@ void BKE_movieclip_update_scopes(MovieC
                        }
  
                        if ((track->flag & TRACK_LOCKED) == 0) {
 +                              float pat_min[2], pat_max[2];
 +
                                scopes->marker = marker;
                                scopes->track = track;
 -                              scopes->slide_scale[0] = track->pat_max[0] - track->pat_min[0];
 -                              scopes->slide_scale[1] = track->pat_max[1] - track->pat_min[1];
 +
 +                              /* XXX: would work fine with non-transformed patterns, but would likely fail
 +                               *      with transformed patterns, but that would be easier to debug when
 +                               *      we'll have real pattern sampling (at least to test) */
 +                              BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max);
 +
 +                              scopes->slide_scale[0] = pat_max[0] - pat_min[0];
 +                              scopes->slide_scale[1] = pat_max[1] - pat_min[1];
                        }
                }
        }
index cc5abce64f3c886735b81ce65c60c64a79f0081e,cce38ff1d90b7fc61fdbb989be4e8141763a117f..b1a3150ff249d1da564e54c3b62080abf8e02059
@@@ -4831,8 -4831,8 +4831,8 @@@ static void lib_link_scene(FileData *fd
                                if (seq->scene_camera) seq->scene_camera = newlibadr(fd, sce->id.lib, seq->scene_camera);
                                if (seq->sound) {
                                        seq->scene_sound = NULL;
-                                       if (seq->type == SEQ_HD_SOUND)
-                                               seq->type = SEQ_SOUND;
+                                       if (seq->type == SEQ_TYPE_SOUND_HD)
+                                               seq->type = SEQ_TYPE_SOUND_RAM;
                                        else
                                                seq->sound = newlibadr(fd, sce->id.lib, seq->sound);
                                        if (seq->sound) {
@@@ -4957,10 -4957,10 +4957,10 @@@ static void direct_link_scene(FileData 
                        
                        seq->effectdata = newdataadr(fd, seq->effectdata);
                        
-                       if (seq->type & SEQ_EFFECT)
+                       if (seq->type & SEQ_TYPE_EFFECT)
                                seq->flag |= SEQ_EFFECT_NOT_LOADED;
                        
-                       if (seq->type == SEQ_SPEED) {
+                       if (seq->type == SEQ_TYPE_SPEED) {
                                SpeedControlVars *s = seq->effectdata;
                                s->frameMap = NULL;
                        }
                        if (seq->strip && seq->strip->done==0) {
                                seq->strip->done = TRUE;
                                
-                               if (ELEM4(seq->type, SEQ_IMAGE, SEQ_MOVIE, SEQ_RAM_SOUND, SEQ_HD_SOUND)) {
+                               if (ELEM4(seq->type, SEQ_TYPE_IMAGE, SEQ_TYPE_MOVIE, SEQ_TYPE_SOUND_RAM, SEQ_TYPE_SOUND_HD)) {
                                        seq->strip->stripdata = newdataadr(fd, seq->strip->stripdata);
                                }
                                else {
@@@ -6112,15 -6112,14 +6112,15 @@@ static void direct_link_movieReconstruc
        reconstruction->cameras = newdataadr(fd, reconstruction->cameras);
  }
  
 -static void direct_link_movieTracks(FileData *fd, ListBase *tracksbase)
 +static void direct_link_movieTracks(FileData *fd, MovieClip *clip, ListBase *tracksbase)
  {
        MovieTrackingTrack *track;
        
        link_list(fd, tracksbase);
 -      
 +
        for (track = tracksbase->first; track; track = track->next) {
                track->markers = newdataadr(fd, track->markers);
 +              track->gpd = newlibadr_us(fd, clip->id.lib, track->gpd);
        }
  }
  
@@@ -6137,7 -6136,7 +6137,7 @@@ static void direct_link_movieclip(FileD
        if (fd->movieclipmap) clip->tracking.camera.intrinsics = newmclipadr(fd, clip->tracking.camera.intrinsics);
        else clip->tracking.camera.intrinsics = NULL;
  
 -      direct_link_movieTracks(fd, &tracking->tracks);
 +      direct_link_movieTracks(fd, clip, &tracking->tracks);
        direct_link_movieReconstruction(fd, &tracking->reconstruction);
  
        clip->tracking.act_track = newdataadr(fd, clip->tracking.act_track);
        link_list(fd, &tracking->objects);
        
        for (object = tracking->objects.first; object; object = object->next) {
 -              direct_link_movieTracks(fd, &object->tracks);
 +              direct_link_movieTracks(fd, clip, &object->tracks);
                direct_link_movieReconstruction(fd, &object->reconstruction);
        }
  }
@@@ -7063,9 -7062,12 +7063,9 @@@ static void do_versions(FileData *fd, L
                                        
                                track = clip->tracking.tracks.first;
                                while (track) {
 -                                      if (track->pyramid_levels == 0)
 -                                              track->pyramid_levels = 2;
 -                                      
                                        if (track->minimum_correlation == 0.0f)
                                                track->minimum_correlation = 0.75f;
 -                                      
 +
                                        track = track->next;
                                }
                        }
                
                for (clip= main->movieclip.first; clip; clip= clip->id.next) {
                        MovieTrackingSettings *settings= &clip->tracking.settings;
 -                      
 -                      if (settings->default_pyramid_levels == 0) {
 -                              settings->default_tracker= TRACKER_KLT;
 -                              settings->default_pyramid_levels = 2;
 +
 +                      if (settings->default_pattern_size == 0.0f) {
 +                              settings->default_motion_model = TRACK_MOTION_MODEL_TRANSLATION;
                                settings->default_minimum_correlation = 0.75;
                                settings->default_pattern_size = 11;
                                settings->default_search_size = 51;
                }
        }
  
 +
        if (main->versionfile < 263 || (main->versionfile == 263 && main->subversionfile < 8))
        {
                /* set new deactivation values for game settings */
                }
        }
  
 +      {
 +              MovieClip *clip;
 +
 +              for (clip = main->movieclip.first; clip; clip = clip->id.next) {
 +                      MovieTrackingTrack *track;
 +
 +                      track = clip->tracking.tracks.first;
 +                      while (track) {
 +                              int i;
 +
 +                              for (i = 0; i < track->markersnr; i++) {
 +                                      MovieTrackingMarker *marker = &track->markers[i];
 +
 +                                      if (is_zero_v2(marker->pattern_corners[0]) && is_zero_v2(marker->pattern_corners[1]) &&
 +                                          is_zero_v2(marker->pattern_corners[3]) && is_zero_v2(marker->pattern_corners[3]))
 +                                      {
 +                                              marker->pattern_corners[0][0] = track->pat_min[0];
 +                                              marker->pattern_corners[0][1] = track->pat_min[1];
 +
 +                                              marker->pattern_corners[1][0] = track->pat_max[0];
 +                                              marker->pattern_corners[1][1] = track->pat_min[1];
 +
 +                                              marker->pattern_corners[2][0] = track->pat_max[0];
 +                                              marker->pattern_corners[2][1] = track->pat_max[1];
 +
 +                                              marker->pattern_corners[3][0] = track->pat_min[0];
 +                                              marker->pattern_corners[3][1] = track->pat_max[1];
 +                                      }
 +
 +                                      if (is_zero_v2(marker->search_min) && is_zero_v2(marker->search_max)) {
 +                                              copy_v2_v2(marker->search_min, track->search_min);
 +                                              copy_v2_v2(marker->search_max, track->search_max);
 +                                      }
 +                              }
 +
 +                              track = track->next;
 +                      }
 +              }
 +      }
 +
        /* WATCH IT!!!: pointers from libdata have not been converted yet here! */
        /* WATCH IT 2!: Userdef struct init has to be in editors/interface/resources.c! */
  
index 74287f0e6935e697c53e29097600aea98e474bd4,f257994bc1c92ffad3886e504bf2e923117cfe38..e54ae41286da0b2b0f767742b1c0e678d4abadcb
@@@ -2153,19 -2153,19 +2153,19 @@@ static void write_scenes(WriteData *wd
                                        
                                        if (seq->effectdata) {
                                                switch (seq->type) {
-                                               case SEQ_COLOR:
+                                               case SEQ_TYPE_COLOR:
                                                        writestruct(wd, DATA, "SolidColorVars", 1, seq->effectdata);
                                                        break;
-                                               case SEQ_SPEED:
+                                               case SEQ_TYPE_SPEED:
                                                        writestruct(wd, DATA, "SpeedControlVars", 1, seq->effectdata);
                                                        break;
-                                               case SEQ_WIPE:
+                                               case SEQ_TYPE_WIPE:
                                                        writestruct(wd, DATA, "WipeVars", 1, seq->effectdata);
                                                        break;
-                                               case SEQ_GLOW:
+                                               case SEQ_TYPE_GLOW:
                                                        writestruct(wd, DATA, "GlowVars", 1, seq->effectdata);
                                                        break;
-                                               case SEQ_TRANSFORM:
+                                               case SEQ_TYPE_TRANSFORM:
                                                        writestruct(wd, DATA, "TransformVars", 1, seq->effectdata);
                                                        break;
                                                }
                                        if (seq->flag & SEQ_USE_COLOR_BALANCE && strip->color_balance) {
                                                writestruct(wd, DATA, "StripColorBalance", 1, strip->color_balance);
                                        }
-                                       if (seq->type==SEQ_IMAGE)
+                                       if (seq->type==SEQ_TYPE_IMAGE)
                                                writestruct(wd, DATA, "StripElem", MEM_allocN_len(strip->stripdata) / sizeof(struct StripElem), strip->stripdata);
-                                       else if (seq->type==SEQ_MOVIE || seq->type==SEQ_RAM_SOUND || seq->type == SEQ_HD_SOUND)
+                                       else if (seq->type==SEQ_TYPE_MOVIE || seq->type==SEQ_TYPE_SOUND_RAM || seq->type == SEQ_TYPE_SOUND_HD)
                                                writestruct(wd, DATA, "StripElem", 1, strip->stripdata);
                                        
                                        strip->done = TRUE;
@@@ -2889,7 -2889,6 +2889,7 @@@ static int write_file_handle(Main *main
                write_windowmanagers(wd, &mainvar->wm);
                write_screens  (wd, &mainvar->screen);
        }
 +      write_gpencils (wd, &mainvar->gpencil);
        write_movieclips (wd, &mainvar->movieclip);
        write_masks    (wd, &mainvar->mask);
        write_scenes   (wd, &mainvar->scene);
        write_nodetrees(wd, &mainvar->nodetree);
        write_brushes  (wd, &mainvar->brush);
        write_scripts  (wd, &mainvar->script);
 -      write_gpencils (wd, &mainvar->gpencil);
        write_libraries(wd,  mainvar->next);
  
        if (write_user_block) {
index 3f3bacfabdf18db0ba6a7a79307dc0a86c57f733,cca72e7469a0f059891592d85e4c3fd2a233a628..9332413b33bca7910918ca7af3dcfc8f25d053fd
@@@ -456,17 -456,14 +456,17 @@@ static void draw_marker_outline(SpaceCl
  
        if ((marker->flag & MARKER_DISABLED) == 0) {
                float pos[2];
 -              rctf r;
 +              float p[2];
  
 -              BLI_init_rctf(&r, track->pat_min[0], track->pat_max[0], track->pat_min[1], track->pat_max[1]);
                add_v2_v2v2(pos, marker->pos, track->offset);
  
                ED_clip_point_undistorted_pos(sc, pos, pos);
  
 -              if (BLI_in_rctf(&r, pos[0] - marker_pos[0], pos[1] - marker_pos[1])) {
 +              sub_v2_v2v2(p, pos, marker_pos);
 +
 +              if (isect_point_quad_v2(p, marker->pattern_corners[0], marker->pattern_corners[1],
 +                                      marker->pattern_corners[2], marker->pattern_corners[3]))
 +              {
                        if (tiny) glPointSize(3.0f);
                        else glPointSize(4.0f);
                        glBegin(GL_POINTS);
  
        if (sc->flag & SC_SHOW_MARKER_PATTERN) {
                glBegin(GL_LINE_LOOP);
 -                      glVertex2f(track->pat_min[0], track->pat_min[1]);
 -                      glVertex2f(track->pat_max[0], track->pat_min[1]);
 -                      glVertex2f(track->pat_max[0], track->pat_max[1]);
 -                      glVertex2f(track->pat_min[0], track->pat_max[1]);
 +                      glVertex2fv(marker->pattern_corners[0]);
 +                      glVertex2fv(marker->pattern_corners[1]);
 +                      glVertex2fv(marker->pattern_corners[2]);
 +                      glVertex2fv(marker->pattern_corners[3]);
                glEnd();
        }
  
                      ((marker->flag & MARKER_DISABLED) == 0 || (sc->flag & SC_SHOW_MARKER_PATTERN) == 0);
        if (sc->flag & SC_SHOW_MARKER_SEARCH && show_search) {
                glBegin(GL_LINE_LOOP);
 -                      glVertex2f(track->search_min[0], track->search_min[1]);
 -                      glVertex2f(track->search_max[0], track->search_min[1]);
 -                      glVertex2f(track->search_max[0], track->search_max[1]);
 -                      glVertex2f(track->search_min[0], track->search_max[1]);
 +                      glVertex2f(marker->search_min[0], marker->search_min[1]);
 +                      glVertex2f(marker->search_max[0], marker->search_min[1]);
 +                      glVertex2f(marker->search_max[0], marker->search_max[1]);
 +                      glVertex2f(marker->search_min[0], marker->search_max[1]);
                glEnd();
        }
        glPopMatrix();
@@@ -559,7 -556,8 +559,7 @@@ static void draw_marker_areas(SpaceCli
  
        /* marker position and offset position */
        if ((track->flag & SELECT) == sel && (marker->flag & MARKER_DISABLED) == 0) {
 -              float pos[2];
 -              rctf r;
 +              float pos[2], p[2];
  
                if (track->flag & TRACK_LOCKED) {
                        if (act)
                                glColor3fv(col);
                }
  
 -              BLI_init_rctf(&r, track->pat_min[0], track->pat_max[0], track->pat_min[1], track->pat_max[1]);
                add_v2_v2v2(pos, marker->pos, track->offset);
                ED_clip_point_undistorted_pos(sc, pos, pos);
  
 -              if (BLI_in_rctf(&r, pos[0] - marker_pos[0], pos[1] - marker_pos[1])) {
 +              sub_v2_v2v2(p, pos, marker_pos);
 +
 +              if (isect_point_quad_v2(p, marker->pattern_corners[0], marker->pattern_corners[1],
 +                                      marker->pattern_corners[2], marker->pattern_corners[3]))
 +              {
                        if (!tiny)
                                glPointSize(2.0f);
  
                }
  
                glBegin(GL_LINE_LOOP);
 -                      glVertex2f(track->pat_min[0], track->pat_min[1]);
 -                      glVertex2f(track->pat_max[0], track->pat_min[1]);
 -                      glVertex2f(track->pat_max[0], track->pat_max[1]);
 -                      glVertex2f(track->pat_min[0], track->pat_max[1]);
 +                      glVertex2fv(marker->pattern_corners[0]);
 +                      glVertex2fv(marker->pattern_corners[1]);
 +                      glVertex2fv(marker->pattern_corners[2]);
 +                      glVertex2fv(marker->pattern_corners[3]);
                glEnd();
        }
  
                }
  
                glBegin(GL_LINE_LOOP);
 -                      glVertex2f(track->search_min[0], track->search_min[1]);
 -                      glVertex2f(track->search_max[0], track->search_min[1]);
 -                      glVertex2f(track->search_max[0], track->search_max[1]);
 -                      glVertex2f(track->search_min[0], track->search_max[1]);
 +                      glVertex2f(marker->search_min[0], marker->search_min[1]);
 +                      glVertex2f(marker->search_max[0], marker->search_min[1]);
 +                      glVertex2f(marker->search_max[0], marker->search_max[1]);
 +                      glVertex2f(marker->search_min[0], marker->search_max[1]);
                glEnd();
        }
  
 -      /* pyramid */
 -      if (sel && TRACK_VIEW_SELECTED(sc, track) &&
 -          (track->tracker == TRACKER_KLT) &&
 -              (marker->flag & MARKER_DISABLED) == 0)
 -      {
 -              if (track->flag & TRACK_LOCKED) {
 -                      if (act)
 -                              UI_ThemeColor(TH_ACT_MARKER);
 -                      else if (track->pat_flag & SELECT)
 -                              UI_ThemeColorShade(TH_LOCK_MARKER, 64);
 -                      else UI_ThemeColor(TH_LOCK_MARKER);
 -              }
 -              else if (marker->flag & MARKER_DISABLED) {
 -                      if (act)
 -                              UI_ThemeColor(TH_ACT_MARKER);
 -                      else if (track->pat_flag & SELECT)
 -                              UI_ThemeColorShade(TH_DIS_MARKER, 128);
 -                      else UI_ThemeColor(TH_DIS_MARKER);
 -              }
 -              else {
 -                      if (track->pat_flag & SELECT)
 -                              glColor3fv(scol);
 -                      else
 -                              glColor3fv(col);
 -              }
 -
 -              {
 -                      int i = 0;
 -                      glPushMatrix();
 -                      glEnable(GL_LINE_STIPPLE);
 -                      for (i = 1; i < track->pyramid_levels; ++i) {
 -                              glScalef(2.0f, 2.0f, 1.0);
 -                      }
 -                      /* only draw a pattern for the coarsest level */
 -                      glBegin(GL_LINE_LOOP);
 -                              glVertex2f(track->pat_min[0], track->pat_min[1]);
 -                              glVertex2f(track->pat_max[0], track->pat_min[1]);
 -                              glVertex2f(track->pat_max[0], track->pat_max[1]);
 -                              glVertex2f(track->pat_min[0], track->pat_max[1]);
 -                      glEnd();
 -                      glDisable(GL_LINE_STIPPLE);
 -                      glPopMatrix();
 -              }
 -      }
 -
        if (tiny)
                glDisable(GL_LINE_STIPPLE);
  
        glPopMatrix();
  }
  
 +static float get_shortest_pattern_side(MovieTrackingMarker *marker)
 +{
 +      int i, next;
 +      float len = FLT_MAX;
 +
 +      for (i = 0; i < 4; i++) {
 +              float cur_len;
 +
 +              next = (i + 1) % 4;
 +
 +              cur_len = len_v2v2(marker->pattern_corners[i], marker->pattern_corners[next]);
 +
 +              len = MIN2(cur_len, len);
 +      }
 +
 +      return len;
 +}
 +
 +static void draw_marker_slide_square(float x, float y, float dx, float dy, int outline, float px[2])
 +{
 +      float tdx, tdy;
 +
 +      tdx = dx;
 +      tdy = dy;
 +
 +      if (outline) {
 +              tdx += px[0];
 +              tdy += px[1];
 +      }
 +
 +      glBegin(GL_QUADS);
 +              glVertex3f(x - tdx, y + tdy, 0.0f);
 +              glVertex3f(x + tdx, y + tdy, 0.0f);
 +              glVertex3f(x + tdx, y - tdy, 0.0f);
 +              glVertex3f(x - tdx, y - tdy, 0.0f);
 +      glEnd();
 +}
 +
 +static void draw_marker_slide_triangle(float x, float y, float dx, float dy, int outline, float px[2])
 +{
 +      float tdx, tdy;
 +
 +      tdx = dx * 2.0f;
 +      tdy = dy * 2.0f;
 +
 +      if (outline) {
 +              tdx += px[0];
 +              tdy += px[1];
 +      }
 +
 +      glBegin(GL_TRIANGLES);
 +              glVertex3f(x,       y,       0.0f);
 +              glVertex3f(x - tdx, y,       0.0f);
 +              glVertex3f(x,       y + tdy, 0.0f);
 +      glEnd();
 +}
 +
  static void draw_marker_slide_zones(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker,
                                      float marker_pos[2], int outline, int sel, int act, int width, int height)
  {
 -      float x, y, dx, dy, patdx, patdy, searchdx, searchdy, tdx, tdy;
 +      float dx, dy, patdx, patdy, searchdx, searchdy;
        int tiny = sc->flag & SC_SHOW_TINY_MARKER;
 -      float col[3], scol[3], px[2];
 +      float col[3], scol[3], px[2], side;
  
        if ((tiny && outline) || (marker->flag & MARKER_DISABLED))
                return;
        dx = 6.0f / width / sc->zoom;
        dy = 6.0f / height / sc->zoom;
  
 -      patdx = MIN2(dx * 2.0f / 3.0f, (track->pat_max[0] - track->pat_min[0]) / 6.0f);
 -      patdy = MIN2(dy * 2.0f / 3.0f, (track->pat_max[1] - track->pat_min[1]) / 6.0f);
 +      side = get_shortest_pattern_side(marker);
 +      patdx = MIN2(dx * 2.0f / 3.0f, side / 6.0f);
 +      patdy = MIN2(dy * 2.0f / 3.0f, side * width / height / 6.0f);
  
 -      searchdx = MIN2(dx, (track->search_max[0] - track->search_min[0]) / 6.0f);
 -      searchdy = MIN2(dy, (track->search_max[1] - track->search_min[1]) / 6.0f);
 +      searchdx = MIN2(dx, (marker->search_max[0] - marker->search_min[0]) / 6.0f);
 +      searchdy = MIN2(dy, (marker->search_max[1] - marker->search_min[1]) / 6.0f);
  
        px[0] = 1.0f / sc->zoom / width / sc->scale;
        px[1] = 1.0f / sc->zoom / height / sc->scale;
                }
  
                /* search offset square */
 -              x = track->search_min[0];
 -              y = track->search_max[1];
 -
 -              tdx = searchdx;
 -              tdy = searchdy;
 -
 -              if (outline) {
 -                      tdx += px[0];
 -                      tdy += px[1];
 -              }
 -
 -              glBegin(GL_QUADS);
 -                      glVertex3f(x - tdx, y + tdy, 0);
 -                      glVertex3f(x + tdx, y + tdy, 0);
 -                      glVertex3f(x + tdx, y - tdy, 0);
 -                      glVertex3f(x - tdx, y - tdy, 0);
 -              glEnd();
 +              draw_marker_slide_square(marker->search_min[0], marker->search_max[1], searchdx, searchdy, outline, px);
  
                /* search re-sizing triangle */
 -              x = track->search_max[0];
 -              y = track->search_min[1];
 -
 -              tdx = searchdx * 2.0f;
 -              tdy = searchdy * 2.0f;
 -
 -              if (outline) {
 -                      tdx += px[0];
 -                      tdy += px[1];
 -              }
 -
 -              glBegin(GL_TRIANGLES);
 -                      glVertex3f(x, y, 0);
 -                      glVertex3f(x - tdx, y, 0);
 -                      glVertex3f(x, y + tdy, 0);
 -              glEnd();
 +              draw_marker_slide_triangle(marker->search_max[0], marker->search_min[1], searchdx, searchdy, outline, px);
        }
  
        if ((sc->flag & SC_SHOW_MARKER_PATTERN) && ((track->pat_flag & SELECT) == sel || outline)) {
                                glColor3fv(col);
                }
  
 -              /* pattern offset square */
 -              x = track->pat_min[0];
 -              y = track->pat_max[1];
 +              /* XXX: need to be real check if affine tracking is enabled, but for now not
 +               *      sure how to do this, so assume affine tracker is always enabled */
 +              if (TRUE) {
 +                      int i;
  
 -              tdx = patdx;
 -              tdy = patdy;
 -
 -              if (outline) {
 -                      tdx += px[0];
 -                      tdy += px[1];
 +                      /* pattern's corners sliding squares */
 +                      for (i = 0; i < 4; i++) {
 +                              draw_marker_slide_square(marker->pattern_corners[i][0], marker->pattern_corners[i][1],
 +                                                       patdx / 1.5f, patdy / 1.5f, outline, px);
 +                      }
                }
 +              else {
 +                      /* pattern offset square */
 +                      draw_marker_slide_square(marker->pattern_corners[3][0], marker->pattern_corners[3][1],
 +                                               patdx, patdy, outline, px);
  
 -              glBegin(GL_QUADS);
 -                      glVertex3f(x - tdx, y + tdy, 0);
 -                      glVertex3f(x + tdx, y + tdy, 0);
 -                      glVertex3f(x + tdx, y - tdy, 0);
 -                      glVertex3f(x - tdx, y - tdy, 0);
 -              glEnd();
 -
 -              /* pattern re-sizing triangle */
 -              x = track->pat_max[0];
 -              y = track->pat_min[1];
 -
 -              tdx = patdx*2.0f;
 -              tdy = patdy*2.0f;
 -
 -              if (outline) {
 -                      tdx += px[0];
 -                      tdy += px[1];
 +                      /* pattern re-sizing triangle */
 +                      draw_marker_slide_triangle(marker->pattern_corners[1][0], marker->pattern_corners[1][1],
 +                                                 patdx, patdy, outline, px);
                }
 -
 -              glBegin(GL_TRIANGLES);
 -                      glVertex3f(x, y, 0);
 -                      glVertex3f(x - tdx, y, 0);
 -                      glVertex3f(x, y + tdy, 0);
 -              glEnd();
        }
  
        glPopMatrix();
@@@ -876,15 -905,12 +876,15 @@@ static void draw_marker_texts(SpaceCli
        if ((sc->flag & SC_SHOW_MARKER_SEARCH) &&
           ((marker->flag & MARKER_DISABLED) == 0 || (sc->flag & SC_SHOW_MARKER_PATTERN) == 0))
        {
 -              dx = track->search_min[0];
 -              dy = track->search_min[1];
 +              dx = marker->search_min[0];
 +              dy = marker->search_min[1];
        }
        else if (sc->flag & SC_SHOW_MARKER_PATTERN) {
 -              dx = track->pat_min[0];
 -              dy = track->pat_min[1];
 +              float pat_min[2], pat_max[2];
 +
 +              BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max);
 +              dx = pat_min[0];
 +              dy = pat_min[1];
        }
  
        pos[0] = (marker_pos[0] + dx) * width;
@@@ -1177,10 -1203,8 +1177,10 @@@ static void draw_distortion(SpaceClip *
        int i, j, a;
        float pos[2], tpos[2], grid[11][11][2];
        MovieTracking *tracking = &clip->tracking;
 +      bGPdata *gpd = NULL;
        float aspy = 1.0f / tracking->camera.pixel_aspect;
        float dx = (float)width / n, dy = (float)height / n * aspy;
 +      float offsx = 0.0f, offsy = 0.0f;
  
        if (sc->mode != SC_MODE_DISTORTION)
                return;
                }
        }
  
 -      if (sc->flag & SC_MANUAL_CALIBRATION && clip->gpd) {
 -              bGPDlayer *layer = clip->gpd->layers.first;
 +      if (sc->gpencil_src == SC_GPENCIL_SRC_TRACK) {
 +              MovieTrackingTrack *track = BKE_tracking_active_track(&sc->clip->tracking);
 +
 +              if (track) {
 +                      int framenr = sc->user.framenr;
 +                      MovieTrackingMarker *marker = BKE_tracking_exact_marker(track, framenr);
 +
 +                      offsx = marker->pos[0];
 +                      offsy = marker->pos[1];
 +
 +                      gpd = track->gpd;
 +              }
 +
 +      }
 +      else {
 +              gpd = clip->gpd;
 +      }
 +
 +      if (sc->flag & SC_MANUAL_CALIBRATION && gpd) {
 +              bGPDlayer *layer = gpd->layers.first;
  
                while (layer) {
                        bGPDframe *frame = layer->frames.first;
                                                                        float npos[2], dpos[2], len;
                                                                        int steps;
  
 -                                                                      pos[0] = stroke->points[i].x * width;
 -                                                                      pos[1] = stroke->points[i].y * height * aspy;
 +                                                                      pos[0] = (stroke->points[i].x + offsx) * width;
 +                                                                      pos[1] = (stroke->points[i].y + offsy) * height * aspy;
  
 -                                                                      npos[0] = stroke->points[i + 1].x * width;
 -                                                                      npos[1] = stroke->points[i + 1].y * height * aspy;
 +                                                                      npos[0] = (stroke->points[i + 1].x + offsx) * width;
 +                                                                      npos[1] = (stroke->points[i + 1].y + offsy) * height * aspy;
  
                                                                        len = len_v2v2(pos, npos);
                                                                        steps = ceil(len / 5.0f);
                                                }
                                                else if (stroke->totpoints == 1) {
                                                        glBegin(GL_POINTS);
 -                                                              glVertex2f(stroke->points[0].x, stroke->points[0].y);
 +                                                              glVertex2f(stroke->points[0].x + offsx, stroke->points[0].y + offsy);
                                                        glEnd();
                                                }
                                        }
@@@ -1451,7 -1457,6 +1451,6 @@@ void clip_draw_grease_pencil(bContext *
  {
        SpaceClip *sc = CTX_wm_space_clip(C);
        MovieClip *clip = ED_space_clip(sc);
-       ImBuf *ibuf;
  
        if (!clip)
                return;
                /* if manual calibration is used then grease pencil data is already
                 * drawed in draw_distortion */
                if ((sc->flag & SC_MANUAL_CALIBRATION) == 0 || sc->mode != SC_MODE_DISTORTION) {
-                       ibuf = ED_space_clip_get_buffer(sc);
-                       if (ibuf) {
-                               glPushMatrix();
-                               glMultMatrixf(sc->unistabmat);
+                       glPushMatrix();
+                       glMultMatrixf(sc->unistabmat);
 +
-                               if (sc->gpencil_src == SC_GPENCIL_SRC_TRACK) {
-                                       MovieTrackingTrack *track = BKE_tracking_active_track(&sc->clip->tracking);
++                      if (sc->gpencil_src == SC_GPENCIL_SRC_TRACK) {
++                              MovieTrackingTrack *track = BKE_tracking_active_track(&sc->clip->tracking);
 +
-                                       if (track) {
-                                               int framenr = sc->user.framenr;
-                                               MovieTrackingMarker *marker = BKE_tracking_exact_marker(track, framenr);
++                              if (track) {
++                                      int framenr = sc->user.framenr;
++                                      MovieTrackingMarker *marker = BKE_tracking_exact_marker(track, framenr);
 +
-                                               glTranslatef(marker->pos[0], marker->pos[1], 0.0f);
-                                       }
++                                      glTranslatef(marker->pos[0], marker->pos[1], 0.0f);
 +                              }
++                      }
 +
-                               draw_gpencil_2dimage(C, ibuf);
+                       draw_gpencil_2dimage(C);
  
-                               IMB_freeImBuf(ibuf);
-                               glPopMatrix();
-                       }
+                       glPopMatrix();
                }
        }
        else {
index 298dfca8bc71e5a2e1694d68e20fcfd150cb5d59,fdd4dfc57d082680dde84867a1a6965f4c777eff..4884171364e2bed13eb055d3d24a4a1dd9f52f59
@@@ -79,8 -79,6 +79,8 @@@
  
  #include "clip_intern.h"      // own include
  
 +static float dist_to_crns(float co[2], float pos[2], float crns[4][2]);
 +
  /********************** add marker operator *********************/
  
  static void add_marker(SpaceClip *sc, float x, float y)
@@@ -109,6 -107,7 +109,7 @@@ static int add_marker_exec(bContext *C
        int width, height;
  
        ED_space_clip_size(sc, &width, &height);
        if (!width || !height)
                return OPERATOR_CANCELLED;
  
@@@ -146,7 -145,7 +147,7 @@@ void CLIP_OT_add_marker(wmOperatorType 
        /* api callbacks */
        ot->invoke = add_marker_invoke;
        ot->exec = add_marker_exec;
-       ot->poll = ED_space_clip_tracking_size_poll;
+       ot->poll = ED_space_clip_tracking_poll;
  
        /* flags */
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@@@ -261,16 -260,15 +262,16 @@@ typedef struct 
  
        int mval[2];
        int width, height;
 -      float *min, *max, *pos, *offset;
 -      float smin[2], smax[2], spos[2], soff[2];
 +      float *min, *max, *pos, *offset, (*corners)[2];
 +      float smin[2], smax[2], spos[2], soff[2], scorners[4][2];
        float (*smarkers)[2];
  
 -      int lock, accurate;
 +      int lock, accurate, scale;
  } SlideMarkerData;
  
  static SlideMarkerData *create_slide_marker_data(SpaceClip *sc, MovieTrackingTrack *track,
 -                      MovieTrackingMarker *marker, wmEvent *event, int area, int action, int width, int height)
 +                                                 MovieTrackingMarker *marker, wmEvent *event,
 +                                                                                               int area, int corner, int action, int width, int height)
  {
        SlideMarkerData *data = MEM_callocN(sizeof(SlideMarkerData), "slide marker data");
        int framenr = ED_space_clip_clip_framenr(sc);
        }
        else if (area == TRACK_AREA_PAT) {
                if (action == SLIDE_ACTION_SIZE) {
 -                      data->min = track->pat_min;
 -                      data->max = track->pat_max;
 +                      data->corners = marker->pattern_corners;
                }
 -              else {
 +              else if (action == SLIDE_ACTION_OFFSET) {
                        int a;
  
                        data->pos = marker->pos;
                        for (a = 0; a < track->markersnr; a++)
                                copy_v2_v2(data->smarkers[a], track->markers[a].pos);
                }
 +              else if (action == SLIDE_ACTION_POS) {
 +                      data->corners = marker->pattern_corners;
 +                      data->pos = marker->pattern_corners[corner];
 +
 +                      copy_v2_v2(data->spos, data->pos);
 +              }
        }
        else if (area == TRACK_AREA_SEARCH) {
 -              data->min = track->search_min;
 -              data->max = track->search_max;
 +              data->min = marker->search_min;
 +              data->max = marker->search_max;
        }
  
 -      if (area == TRACK_AREA_SEARCH || (area == TRACK_AREA_PAT && action != SLIDE_ACTION_OFFSET)) {
 -              copy_v2_v2(data->smin, data->min);
 -              copy_v2_v2(data->smax, data->max);
 +      if ((area == TRACK_AREA_SEARCH) ||
 +              (area == TRACK_AREA_PAT && action != SLIDE_ACTION_OFFSET))
 +      {
 +              if (data->corners) {
 +                      memcpy(data->scorners, data->corners, sizeof(data->scorners));
 +              }
 +              else {
 +                      copy_v2_v2(data->smin, data->min);
 +                      copy_v2_v2(data->smax, data->max);
 +              }
        }
  
        data->mval[0] = event->mval[0];
        return data;
  }
  
 -/* corner = 0: right-bottom corner,
 - * corner = 1: left-top corner */
 -static int mouse_on_corner(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker,
 +static int mouse_on_corner(SpaceClip *sc, MovieTrackingMarker *marker,
                             int area, float co[2], int corner, int width, int height)
  {
        int inside = 0;
        float crn[2], dx, dy, tdx, tdy;
  
        if (area == TRACK_AREA_SEARCH) {
 -              copy_v2_v2(min, track->search_min);
 -              copy_v2_v2(max, track->search_max);
 +              copy_v2_v2(min, marker->search_min);
 +              copy_v2_v2(max, marker->search_max);
        }
        else {
 -              copy_v2_v2(min, track->pat_min);
 -              copy_v2_v2(max, track->pat_max);
 +              BKE_tracking_marker_pattern_minmax(marker, min, max);
        }
  
        dx = size / width / sc->zoom;
        return inside;
  }
  
 +static int get_mouse_pattern_corner(SpaceClip *sc, MovieTrackingMarker *marker, float co[2], int width, int height)
 +{
 +      int i, next;
 +      float len = FLT_MAX, dx, dy;
 +
 +      for (i = 0; i < 4; i++) {
 +              float cur_len;
 +
 +              next = (i + 1) % 4;
 +
 +              cur_len = len_v2v2(marker->pattern_corners[i], marker->pattern_corners[next]);
 +
 +              len = MIN2(cur_len, len);
 +      }
 +
 +      dx = 6.0f / width / sc->zoom;
 +      dy = 6.0f / height / sc->zoom;
 +
 +      dx = MIN2(dx * 2.0f / 3.0f, len / 6.0f);
 +      dy = MIN2(dy * 2.0f / 3.0f, len * width / height / 6.0f);
 +
 +      for (i = 0; i < 4; i++) {
 +              float crn[2];
 +              int inside;
 +
 +              add_v2_v2v2(crn, marker->pattern_corners[i], marker->pos);
 +
 +              inside = IN_RANGE_INCL(co[0], crn[0] - dx, crn[0] + dx) &&
 +                       IN_RANGE_INCL(co[1], crn[1] - dy, crn[1] + dy);
 +
 +              if (inside)
 +                      return i;
 +      }
 +
 +      return -1;
 +}
 +
  static int mouse_on_offset(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker,
 -                      float co[2], int width, int height)
 +                           float co[2], int width, int height)
  {
        float pos[2], dx, dy;
 +      float pat_min[2], pat_max[2];
 +
 +      BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max);
  
        add_v2_v2v2(pos, marker->pos, track->offset);
  
        dx = 12.0f / width / sc->zoom;
        dy = 12.0f / height / sc->zoom;
  
 -      dx = MIN2(dx, (track->pat_max[0] - track->pat_min[0]) / 2.0f);
 -      dy = MIN2(dy, (track->pat_max[1] - track->pat_min[1]) / 2.0f);
 +      dx = MIN2(dx, (pat_max[0] - pat_min[0]) / 2.0f);
 +      dy = MIN2(dy, (pat_max[1] - pat_min[1]) / 2.0f);
  
        return co[0] >= pos[0] - dx && co[0] <= pos[0] + dx && co[1] >= pos[1] - dy && co[1] <= pos[1] + dy;
  }
  
 +static int slide_check_corners(float (*corners)[2])
 +{
 +      int i, next, prev;
 +      float cross = 0.0f;
 +      float p[2] = {0.0f, 0.0f};
 +
 +      if (!isect_point_quad_v2(p, corners[0], corners[1], corners[2], corners[3]))
 +              return FALSE;
 +
 +      for (i = 0; i < 4; i++) {
 +              float v1[2], v2[2], cur_cross;
 +
 +              next = (i + 1) % 4;
 +              prev = (4 + i - 1) % 4;
 +
 +              sub_v2_v2v2(v1, corners[i], corners[prev]);
 +              sub_v2_v2v2(v2, corners[next], corners[i]);
 +
 +              cur_cross = cross_v2v2(v1, v2);
 +
 +              if (fabsf(cur_cross) > FLT_EPSILON) {
 +                      if (cross == 0.0f) {
 +                              cross = cur_cross;
 +                      }
 +                      else if (cross * cur_cross < 0.0f) {
 +                              return FALSE;
 +                      }
 +              }
 +      }
 +
 +      return TRUE;
 +}
 +
  static void hide_cursor(bContext *C)
  {
        wmWindow *win = CTX_wm_window(C);
@@@ -508,45 -424,28 +509,45 @@@ static void *slide_marker_customdata(bC
                        MovieTrackingMarker *marker = BKE_tracking_get_marker(track, framenr);
  
                        if ((marker->flag & MARKER_DISABLED) == 0) {
 -                              if (!customdata)
 +                              if (!customdata) {
                                        if (mouse_on_offset(sc, track, marker, co, width, height))
 -                                              customdata = create_slide_marker_data(sc, track, marker, event, TRACK_AREA_POINT,
 +                                              customdata = create_slide_marker_data(sc, track, marker, event, TRACK_AREA_POINT, 0,
                                                                                      SLIDE_ACTION_POS, width, height);
 +                              }
  
                                if (sc->flag & SC_SHOW_MARKER_SEARCH) {
 -                                      if (mouse_on_corner(sc, track, marker, TRACK_AREA_SEARCH, co, 1, width, height))
 -                                              customdata = create_slide_marker_data(sc, track, marker, event, TRACK_AREA_SEARCH,
 +                                      if (mouse_on_corner(sc, marker, TRACK_AREA_SEARCH, co, 1, width, height)) {
 +                                              customdata = create_slide_marker_data(sc, track, marker, event, TRACK_AREA_SEARCH, 0,
                                                                                      SLIDE_ACTION_OFFSET, width, height);
 -                                      else if (mouse_on_corner(sc, track, marker, TRACK_AREA_SEARCH, co, 0, width, height))
 -                                              customdata = create_slide_marker_data(sc, track, marker, event, TRACK_AREA_SEARCH,
 +                                      }
 +                                      else if (mouse_on_corner(sc, marker, TRACK_AREA_SEARCH, co, 0, width, height)) {
 +                                              customdata = create_slide_marker_data(sc, track, marker, event, TRACK_AREA_SEARCH, 0,
                                                                                      SLIDE_ACTION_SIZE, width, height);
 +                                      }
                                }
  
                                if (!customdata && (sc->flag & SC_SHOW_MARKER_PATTERN)) {
 -                                      if (mouse_on_corner(sc, track, marker, TRACK_AREA_PAT, co, 1,  width, height))
 -                                              customdata = create_slide_marker_data(sc, track, marker, event, TRACK_AREA_PAT,
 -                                                              SLIDE_ACTION_OFFSET, width, height);
 -
 -                                      if (!customdata && mouse_on_corner(sc, track, marker, TRACK_AREA_PAT, co, 0, width, height))
 -                                              customdata = create_slide_marker_data(sc, track, marker, event, TRACK_AREA_PAT,
 -                                                                                    SLIDE_ACTION_SIZE, width, height);
 +                                      /* XXX: need to be real check if affine tracking is enabled, but for now not
 +                                       *      sure how to do this, so assume affine tracker is always enabled */
 +                                      if (TRUE) {
 +                                              int corner = get_mouse_pattern_corner(sc, marker, co, width, height);
 +
 +                                              if (corner != -1) {
 +                                                      customdata = create_slide_marker_data(sc, track, marker, event, TRACK_AREA_PAT, corner,
 +                                                                                            SLIDE_ACTION_POS, width, height);
 +                                              }
 +                                      }
 +                                      else {
 +                                              if (mouse_on_corner(sc, marker, TRACK_AREA_PAT, co, 1,  width, height)) {
 +                                                      customdata = create_slide_marker_data(sc, track, marker, event, TRACK_AREA_PAT, 0,
 +                                                                                            SLIDE_ACTION_OFFSET, width, height);
 +                                              }
 +
 +                                              if (!customdata && mouse_on_corner(sc, marker, TRACK_AREA_PAT, co, 0, width, height)) {
 +                                                      customdata = create_slide_marker_data(sc, track, marker, event, TRACK_AREA_PAT, 0,
 +                                                                                            SLIDE_ACTION_SIZE, width, height);
 +                                              }
 +                                      }
                                }
  
                                if (customdata)
@@@ -594,16 -493,9 +595,16 @@@ static void cancel_mouse_slide(SlideMar
                        copy_v2_v2(data->pos, data->spos);
        }
        else {
 -              if (data->action == SLIDE_ACTION_SIZE) {
 -                      copy_v2_v2(data->min, data->smin);
 -                      copy_v2_v2(data->max, data->smax);
 +              if ((data->action == SLIDE_ACTION_SIZE) ||
 +                  (data->action == SLIDE_ACTION_POS && data->area == TRACK_AREA_PAT))
 +              {
 +                      if (data->corners) {
 +                              memcpy(data->corners, data->scorners, sizeof(data->scorners));
 +                      }
 +                      else {
 +                              copy_v2_v2(data->min, data->smin);
 +                              copy_v2_v2(data->max, data->smax);
 +                      }
                }
                else {
                        int a;
@@@ -639,10 -531,6 +640,10 @@@ static int slide_marker_modal(bContext 
                                if (ELEM(event->type, LEFTCTRLKEY, RIGHTCTRLKEY))
                                        data->lock = event->val == KM_RELEASE;
  
 +                      if (data->action == SLIDE_ACTION_POS)
 +                              if (ELEM(event->type, LEFTCTRLKEY, RIGHTCTRLKEY))
 +                                      data->scale = event->val == KM_PRESS;
 +
                        if (ELEM(event->type, LEFTSHIFTKEY, RIGHTSHIFTKEY))
                                data->accurate = event->val == KM_PRESS;
  
                                else {
                                        data->pos[0] = data->spos[0] + dx;
                                        data->pos[1] = data->spos[1] + dy;
 -
 -                                      data->marker->flag &= ~MARKER_TRACKED;
                                }
  
                                WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
                        }
                        else {
                                if (data->action == SLIDE_ACTION_SIZE) {
 -                                      data->min[0] = data->smin[0] - dx;
 -                                      data->max[0] = data->smax[0] + dx;
 +                                      if (data->corners) {
 +                                              data->corners[0][0] = data->scorners[0][0] - dx;
 +                                              data->corners[0][1] = data->scorners[0][1] + dy;
 +
 +                                              data->corners[1][0] = data->scorners[1][0] + dx;
 +                                              data->corners[1][1] = data->scorners[1][1] + dy;
  
 -                                      data->min[1] = data->smin[1] + dy;
 -                                      data->max[1] = data->smax[1] - dy;
 +                                              data->corners[2][0] = data->scorners[2][0] + dx;
 +                                              data->corners[2][1] = data->scorners[2][1] - dy;
 +
 +                                              data->corners[3][0] = data->scorners[3][0] - dx;
 +                                              data->corners[3][1] = data->scorners[3][1] - dy;
 +                                      }
 +                                      else {
 +                                              data->min[0] = data->smin[0] - dx;
 +                                              data->max[0] = data->smax[0] + dx;
 +
 +                                              data->min[1] = data->smin[1] + dy;
 +                                              data->max[1] = data->smax[1] - dy;
 +                                      }
  
                                        if (data->area == TRACK_AREA_SEARCH)
 -                                              BKE_tracking_clamp_track(data->track, CLAMP_SEARCH_DIM);
 +                                              BKE_tracking_clamp_marker(data->marker, CLAMP_SEARCH_DIM);
                                        else
 -                                              BKE_tracking_clamp_track(data->track, CLAMP_PAT_DIM);
 +                                              BKE_tracking_clamp_marker(data->marker, CLAMP_PAT_DIM);
                                }
 -                              else {
 +                              else if (data->action == SLIDE_ACTION_OFFSET) {
                                        float d[2] = {dx, dy};
  
                                        if (data->area == TRACK_AREA_SEARCH) {
                                        }
  
                                        if (data->area == TRACK_AREA_SEARCH)
 -                                              BKE_tracking_clamp_track(data->track, CLAMP_SEARCH_POS);
 +                                              BKE_tracking_clamp_marker(data->marker, CLAMP_SEARCH_POS);
 +                              }
 +                              else if (data->action == SLIDE_ACTION_POS) {
 +                                      if (data->scale) {
 +                                              float scale = 1.0f + 10.0f * (dx - dy);
 +
 +                                              if (scale > 0.0f) {
 +                                                      int a;
 +
 +                                                      for (a = 0; a < 4; a++) {
 +                                                              mul_v2_v2fl(data->corners[a], data->scorners[a], scale);
 +                                                      }
 +                                              }
 +                                      }
 +                                      else {
 +                                              float spos[2];
 +
 +                                              copy_v2_v2(spos, data->pos);
 +
 +                                              /* corners might've been scaled before, restore their original position */
 +                                              memcpy(data->corners, data->scorners, sizeof(data->scorners));
 +
 +                                              data->pos[0] = data->spos[0] + dx;
 +                                              data->pos[1] = data->spos[1] + dy;
 +
 +                                              if (!slide_check_corners(data->corners)) {
 +                                                      copy_v2_v2(data->pos, spos);
 +                                              }
 +                                      }
 +
 +                                      /* currently only patterns are allowed to have such combination of event and data */
 +                                      BKE_tracking_clamp_marker(data->marker, CLAMP_PAT_DIM);
                                }
                        }
  
 +                      data->marker->flag &= ~MARKER_TRACKED;
 +
                        WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, NULL);
  
                        break;
@@@ -797,7 -639,7 +798,7 @@@ void CLIP_OT_slide_marker(wmOperatorTyp
        ot->idname = "CLIP_OT_slide_marker";
  
        /* api callbacks */
-       ot->poll = ED_space_clip_tracking_size_poll;
+       ot->poll = ED_space_clip_tracking_poll;
        ot->invoke = slide_marker_invoke;
        ot->modal = slide_marker_modal;
  
@@@ -831,41 -673,31 +832,41 @@@ static int mouse_on_rect(float co[2], f
               mouse_on_side(co, pos[0] + max[0], pos[1] + min[1], pos[0] + max[0], pos[1] + max[1], epsx, epsy);
  }
  
 +static int mouse_on_crns(float co[2], float pos[2], float crns[4][2], float epsx, float epsy)
 +{
 +      float dist = dist_to_crns(co, pos, crns);
 +
 +      return dist < MAX2(epsx, epsy);
 +}
 +
  static int track_mouse_area(SpaceClip *sc, float co[2], MovieTrackingTrack *track)
  {
        int framenr = ED_space_clip_clip_framenr(sc);
        MovieTrackingMarker *marker = BKE_tracking_get_marker(track, framenr);
 +      float pat_min[2], pat_max[2];
        float epsx, epsy;
        int width, height;
  
        ED_space_clip_size(sc, &width, &height);
  
 -      epsx = MIN4(track->pat_min[0] - track->search_min[0], track->search_max[0] - track->pat_max[0],
 -                 fabsf(track->pat_min[0]), fabsf(track->pat_max[0])) / 2;
 -      epsy = MIN4(track->pat_min[1] - track->search_min[1], track->search_max[1] - track->pat_max[1],
 -                 fabsf(track->pat_min[1]), fabsf(track->pat_max[1])) / 2;
 +      BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max);
 +
 +      epsx = MIN4(pat_min[0] - marker->search_min[0], marker->search_max[0] - pat_max[0],
 +                  fabsf(pat_min[0]), fabsf(pat_max[0])) / 2;
 +      epsy = MIN4(pat_min[1] - marker->search_min[1], marker->search_max[1] - pat_max[1],
 +                  fabsf(pat_min[1]), fabsf(pat_max[1])) / 2;
  
        epsx = MAX2(epsx, 2.0f / width);
        epsy = MAX2(epsy, 2.0f / height);
  
        if (sc->flag & SC_SHOW_MARKER_SEARCH) {
 -              if (mouse_on_rect(co, marker->pos, track->search_min, track->search_max, epsx, epsy))
 +              if (mouse_on_rect(co, marker->pos, marker->search_min, marker->search_max, epsx, epsy))
                        return TRACK_AREA_SEARCH;
        }
  
        if ((marker->flag & MARKER_DISABLED) == 0) {
                if (sc->flag & SC_SHOW_MARKER_PATTERN)
 -                      if (mouse_on_rect(co, marker->pos, track->pat_min, track->pat_max, epsx, epsy))
 +                      if (mouse_on_crns(co, marker->pos, marker->pattern_corners, epsx, epsy))
                                return TRACK_AREA_PAT;
  
                epsx = 12.0f / width;
@@@ -896,21 -728,6 +897,21 @@@ static float dist_to_rect(float co[2], 
        return MIN4(d1, d2, d3, d4);
  }
  
 +static float dist_to_crns(float co[2], float pos[2], float crns[4][2])
 +{
 +      float d1, d2, d3, d4;
 +      float p[2] = {co[0] - pos[0], co[1] - pos[1]};
 +      float *v1 = crns[0], *v2 = crns[1],
 +            *v3 = crns[2], *v4 = crns[3];
 +
 +      d1 = dist_to_line_segment_v2(p, v1, v2);
 +      d2 = dist_to_line_segment_v2(p, v2, v3);
 +      d3 = dist_to_line_segment_v2(p, v3, v4);
 +      d4 = dist_to_line_segment_v2(p, v4, v1);
 +
 +      return MIN4(d1, d2, d3, d4);
 +}
 +
  static MovieTrackingTrack *find_nearest_track(SpaceClip *sc, ListBase *tracksbase, float co[2])
  {
        MovieTrackingTrack *track = NULL, *cur;
  
                        /* distance to marker point */
                        d1 = sqrtf((co[0] - marker->pos[0] - cur->offset[0]) * (co[0] - marker->pos[0] - cur->offset[0]) +
 -                                        (co[1] - marker->pos[1] - cur->offset[1]) * (co[1] - marker->pos[1] - cur->offset[1]));
 +                                         (co[1] - marker->pos[1] - cur->offset[1]) * (co[1] - marker->pos[1] - cur->offset[1]));
  
                        /* distance to pattern boundbox */
                        if (sc->flag & SC_SHOW_MARKER_PATTERN)
 -                              d2 = dist_to_rect(co, marker->pos, cur->pat_min, cur->pat_max);
 +                              d2 = dist_to_crns(co, marker->pos, marker->pattern_corners);
  
                        /* distance to search boundbox */
                        if (sc->flag & SC_SHOW_MARKER_SEARCH && TRACK_VIEW_SELECTED(sc, cur))
 -                              d3 = dist_to_rect(co, marker->pos, cur->search_min, cur->search_max);
 +                              d3 = dist_to_rect(co, marker->pos, marker->search_min, marker->search_max);
  
                        /* choose minimal distance. useful for cases of overlapped markers. */
                        dist = MIN3(d1, d2, d3);
@@@ -1044,8 -861,7 +1045,8 @@@ void CLIP_OT_select(wmOperatorType *ot
        /* api callbacks */
        ot->exec = select_exec;
        ot->invoke = select_invoke;
 -      ot->poll = ED_space_clip_tracking_poll;
 +      //ot->poll = ED_space_clip_tracking_poll; // so mask view can Ctrl+RMB markers
 +      ot->poll = ED_space_clip_view_clip_poll;
  
        /* flags */
        ot->flag = OPTYPE_UNDO;
@@@ -1493,7 -1309,7 +1494,7 @@@ void CLIP_OT_select_grouped(wmOperatorT
  
        /* api callbacks */
        ot->exec = select_groped_exec;
-       ot->poll = ED_space_clip_tracking_size_poll;
+       ot->poll = ED_space_clip_tracking_poll;
  
        /* flags */
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@@@ -1878,7 -1694,7 +1879,7 @@@ void CLIP_OT_track_markers(wmOperatorTy
        /* api callbacks */
        ot->exec = track_markers_exec;
        ot->invoke = track_markers_invoke;
-       ot->poll = ED_space_clip_tracking_frame_poll;
+       ot->poll = ED_space_clip_tracking_poll;
        ot->modal = track_markers_modal;
  
        /* flags */
@@@ -2319,19 -2135,17 +2320,17 @@@ static Object *get_orientation_object(b
  
  static int set_orientation_poll(bContext *C)
  {
-       if (ED_space_clip_tracking_size_poll(C)) {
-               Scene *scene = CTX_data_scene(C);
-               SpaceClip *sc = CTX_wm_space_clip(C);
-               MovieClip *clip = ED_space_clip(sc);
-               MovieTracking *tracking = &clip->tracking;
-               MovieTrackingObject *tracking_object = BKE_tracking_active_object(tracking);
+       Scene *scene = CTX_data_scene(C);
+       SpaceClip *sc = CTX_wm_space_clip(C);
+       MovieClip *clip = ED_space_clip(sc);
+       MovieTracking *tracking = &clip->tracking;
+       MovieTrackingObject *tracking_object = BKE_tracking_active_object(tracking);
  
-               if (tracking_object->flag & TRACKING_OBJECT_CAMERA) {
-                       return TRUE;
-               }
-               else {
-                       return OBACT != NULL;
-               }
+       if (tracking_object->flag & TRACKING_OBJECT_CAMERA) {
+               return TRUE;
+       }
+       else {
+               return OBACT != NULL;
        }
  
        return FALSE;
@@@ -2929,16 -2743,12 +2928,12 @@@ void CLIP_OT_set_scale(wmOperatorType *
  
  static int set_solution_scale_poll(bContext *C)
  {
-       if (ED_space_clip_tracking_size_poll(C)) {
-               SpaceClip *sc = CTX_wm_space_clip(C);
-               MovieClip *clip = ED_space_clip(sc);
-               MovieTracking *tracking = &clip->tracking;
-               MovieTrackingObject *tracking_object = BKE_tracking_active_object(tracking);
-               return (tracking_object->flag & TRACKING_OBJECT_CAMERA) == 0;
-       }
+       SpaceClip *sc = CTX_wm_space_clip(C);
+       MovieClip *clip = ED_space_clip(sc);
+       MovieTracking *tracking = &clip->tracking;
+       MovieTrackingObject *tracking_object = BKE_tracking_active_object(tracking);
  
-       return 0;
+       return (tracking_object->flag & TRACKING_OBJECT_CAMERA) == 0;
  }
  
  static int set_solution_scale_exec(bContext *C, wmOperator *op)
@@@ -3148,6 -2958,11 +3143,11 @@@ static int detect_features_exec(bContex
        int framenr = ED_space_clip_clip_framenr(sc);
        bGPDlayer *layer = NULL;
  
+       if (!ibuf) {
+               BKE_report(op->reports, RPT_ERROR, "Feature detection requires valid clip frame");
+               return OPERATOR_CANCELLED;
+       }
        if (placement != 0) {
                layer = detect_get_layer(clip);
                place_outside_layer = placement == 2;
@@@ -3188,7 -3003,7 +3188,7 @@@ void CLIP_OT_detect_features(wmOperator
  
        /* api callbacks */
        ot->exec = detect_features_exec;
-       ot->poll = ED_space_clip_tracking_frame_poll;
+       ot->poll = ED_space_clip_tracking_poll;
  
        /* flags */
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@@@ -3341,7 -3156,7 +3341,7 @@@ void CLIP_OT_join_tracks(wmOperatorTyp
  
        /* api callbacks */
        ot->exec = join_tracks_exec;
-       ot->poll = ED_space_clip_tracking_size_poll;
+       ot->poll = ED_space_clip_tracking_poll;
  
        /* flags */
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
index 38ac8c2999c30f1830df3301ada3614bbc32b4ae,1d4257ea3d3924cf8cb63993a1218d9d1e1c6acd..429a3b3d86ac47291463f2285ddbbb462ebd7ef7
@@@ -2239,7 -2239,7 +2239,7 @@@ void flushTransSeq(TransInfo *t
                        if ((seq->depth != 0 || seq_tx_test(seq))) /* for meta's, their children move */
                                seq->start= new_frame - tdsq->start_offset;
  #else
-                       if (seq->type != SEQ_META && (seq->depth != 0 || seq_tx_test(seq))) /* for meta's, their children move */
+                       if (seq->type != SEQ_TYPE_META && (seq->depth != 0 || seq_tx_test(seq))) /* for meta's, their children move */
                                seq->start= new_frame - tdsq->start_offset;
  #endif
                        if (seq->depth==0) {
  
                /* calc all meta's then effects [#27953] */
                for (seq = seqbasep->first; seq; seq = seq->next) {
-                       if (seq->type == SEQ_META && seq->flag & SELECT) {
+                       if (seq->type == SEQ_TYPE_META && seq->flag & SELECT) {
                                calc_sequence(t->scene, seq);
                        }
                }
@@@ -3787,7 -3787,7 +3787,7 @@@ static void SeqTransInfo(TransInfo *t, 
                        *count = 0;
                        *flag = 0;
                }
-               else if (seq->type == SEQ_META) {
+               else if (seq->type == SEQ_TYPE_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 */
  
                                /* Recursive */
  
-                               if ((seq->type == SEQ_META) && ((seq->flag & (SEQ_LEFTSEL|SEQ_RIGHTSEL)) == 0)) {
+                               if ((seq->type == SEQ_TYPE_META) && ((seq->flag & (SEQ_LEFTSEL|SEQ_RIGHTSEL)) == 0)) {
                                        /* if any handles are selected, don't recurse */
                                        *recursive = TRUE;
                                }
  #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);
+                       *recursive = (seq->type == SEQ_TYPE_META);
  #else
-                       if (seq->type == SEQ_META) {
+                       if (seq->type == SEQ_TYPE_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 in fact.
@@@ -4064,7 -4064,7 +4064,7 @@@ static void freeSeqData(TransInfo *t
                                                seq= ((TransDataSeq *)td->extra)->seq;
                                                if ((seq != seq_prev)) {
                                                        /* check effects strips, we cant change their time */
-                                                       if ((seq->type & SEQ_EFFECT) && seq->seq1) {
+                                                       if ((seq->type & SEQ_TYPE_EFFECT) && seq->seq1) {
                                                                has_effect= TRUE;
                                                        }
                                                        else {
                                                for (a=0; a<t->total; a++, td++) {
                                                        seq= ((TransDataSeq *)td->extra)->seq;
                                                        if ((seq != seq_prev)) {
-                                                               if ((seq->type & SEQ_EFFECT) && seq->seq1) {
+                                                               if ((seq->type & SEQ_TYPE_EFFECT) && seq->seq1) {
                                                                        calc_sequence(t->scene, seq);
                                                                }
                                                        }
                                                for (a=0; a<t->total; a++, td++) {
                                                        seq= ((TransDataSeq *)td->extra)->seq;
                                                        if ((seq != seq_prev)) {
-                                                               if ((seq->type & SEQ_EFFECT) && seq->seq1) {
+                                                               if ((seq->type & SEQ_TYPE_EFFECT) && seq->seq1) {
                                                                        if (seq_test_overlap(seqbasep, seq)) {
                                                                                shuffle_seq(seqbasep, seq, t->scene);
                                                                        }
  
                        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->type & SEQ_TYPE_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);
@@@ -4219,7 -4219,7 +4219,7 @@@ static void createTransSeqData(bContex
                Sequence *seq;
                for (seq= ed->seqbasep->first; seq; seq= seq->next) {
                        /* hack */
-                       if ((seq->flag & SELECT)==0 && seq->type & SEQ_EFFECT) {
+                       if ((seq->flag & SELECT)==0 && seq->type & SEQ_TYPE_EFFECT) {
                                Sequence *seq_user;
                                int i;
                                for (i=0; i<3; i++) {
@@@ -5413,24 -5413,23 +5413,24 @@@ typedef struct TransDataTracking 
        short coord;
  } TransDataTracking;
  
 -static void markerToTransDataInit(TransData *td, TransData2D *td2d, TransDataTracking *tdt, MovieTrackingTrack *track,
 -                                  int area, float loc[2], float rel[2], const float off[2])
 +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 */
        }
  
        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);
  
        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;
  
  }
  
  static void trackToTransData(SpaceClip *sc, TransData *td, TransData2D *td2d,
 -                             TransDataTracking *tdt, MovieTrackingTrack *track)
 +                             TransDataTracking *tdt, MovieTrackingTrack *track, float aspx, float aspy)
  {
        int framenr = ED_space_clip_clip_framenr(sc);
        MovieTrackingMarker *marker = BKE_tracking_ensure_marker(track, 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);
        }
  }
  
@@@ -5533,7 -5519,6 +5533,7 @@@ static void createTransTrackingTracksDa
        MovieTrackingMarker *marker;
        TransDataTracking *tdt;
        int framenr = ED_space_clip_clip_framenr(sc);
 +      float aspx, aspy;
  
        /* count */
        t->total = 0;
                                t->total++;
  
                        if (track->pat_flag & SELECT)
 -                              t->total+= 2;
 +                              t->total+= 4;
  
                        if (track->search_flag & SELECT)
                                t->total+= 2;
        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");
                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,6 -5728,9 +5743,6 @@@ static void createTransTrackingData(bCo
        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);
@@@ -5810,14 -5798,10 +5810,14 @@@ static void cancelTransTracking(TransIn
  
  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);
        /* 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);