Camera tracking integration
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 25 Jul 2011 18:11:22 +0000 (18:11 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 25 Jul 2011 18:11:22 +0000 (18:11 +0000)
===========================

- Split clip hotkeys into two categories:
  * Global
  * Editing
  This allows to re-use such hotkeys as track markers
  from properties region without worrying about conflicts.
- Anchor point could now be offseted from marker position.
- Pattern can now be symmetrical relative to marker position only.
- Changes to mouse sliding:
  * Left top rectangle used for marker position and now
    it's half inside and half outside of marker.
  * Right bottom corners are for size.
  * Anchor point can be slided with mouse to adjust offset.
- Resolved conflict caused by left-mouse selection option.
  Now it works perfectly with sliding -- no more "sticky" keys or so.
- Fixed some typos.

release/scripts/startup/bl_ui/space_userpref_keymap.py
source/blender/blenkernel/intern/constraint.c
source/blender/blenkernel/intern/tracking.c
source/blender/editors/space_clip/clip_buttons.c
source/blender/editors/space_clip/clip_draw.c
source/blender/editors/space_clip/space_clip.c
source/blender/editors/space_clip/tracking_ops.c
source/blender/editors/space_view3d/drawobject.c
source/blender/makesdna/DNA_space_types.h
source/blender/makesdna/DNA_tracking_types.h

index 12cef0f5e6b69e7f9ea8071ac6a1b697693dfb7d..71a0ecb60304c9b5aa73d8985fdc5afa17c8832e 100644 (file)
@@ -95,7 +95,9 @@ KM_HIERARCHY = [
     ('Script', 'SCRIPTS_WINDOW', 'WINDOW', []),
     ('Text', 'TEXT_EDITOR', 'WINDOW', []),
     ('Console', 'CONSOLE', 'WINDOW', []),
-    ('Clip', 'CLIP_EDITOR', 'WINDOW', []),
+    ('Console', 'CONSOLE', 'WINDOW', []),
+    ('Clip Editor', 'CLIP_EDITOR', 'WINDOW', []),
+    ('Clip Globals', 'CLIP_EDITOR', 'WINDOW', []),
 
     ('View3D Gesture Circle', 'EMPTY', 'WINDOW', []),
     ('Gesture Border', 'EMPTY', 'WINDOW', []),
index 961b42d903f4efeb918ab395d0c083661e03dc1d..2fa0110fd14739667af458b4284fe4a495954563 100644 (file)
@@ -4010,9 +4010,14 @@ static void followtrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase
                        len= len_v3(disp);
 
                        if(len>FLT_EPSILON) {
-                               float rmat[4][4];
+                               float pos[2], rmat[4][4];
                                int is_ortho= 0;
 
+                               user.framenr= scene->r.cfra;
+                               marker= BKE_tracking_get_marker(track, user.framenr);
+
+                               add_v2_v2v2(pos, marker->pos, track->offset);
+
                                /* calculate lens and sensor size depends on object type */
                                if(camob->type==OB_CAMERA) {
                                        Camera *camera= (Camera *)camob->data;
@@ -4035,12 +4040,9 @@ static void followtrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase
                                        ortho_scale= 0.f;
                                }
 
-                               user.framenr= scene->r.cfra;
-                               marker= BKE_tracking_get_marker(track, user.framenr);
-
                                if(is_ortho) {
-                                       vec[0]= ortho_scale * (marker->pos[0]-0.5f);
-                                       vec[1]= ortho_scale * (marker->pos[1]-0.5f);
+                                       vec[0]= ortho_scale * (pos[0]-0.5f);
+                                       vec[1]= ortho_scale * (pos[1]-0.5f);
                                        vec[2]= -len;
 
                                        if(aspect>1.f) vec[1]/= aspect;
@@ -4057,8 +4059,8 @@ static void followtrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase
                                else {
                                        d= (len*sensor_x) / (2.f*lens);
 
-                                       vec[0]= d*(2.f*marker->pos[0]-1.f);
-                                       vec[1]= d*(2.f*marker->pos[1]-1.f);
+                                       vec[0]= d*(2.f*pos[0]-1.f);
+                                       vec[1]= d*(2.f*pos[1]-1.f);
                                        vec[2]= -len;
 
                                        if(aspect>1.f) vec[1]/= aspect;
index 763a60e822c69420f7d185a0f68b68a3ed68340b..542049d70f4ed6377a998a6faeaa91f4d2bcd6f5 100644 (file)
@@ -120,20 +120,14 @@ void BKE_tracking_clamp_track(MovieTrackingTrack *track, int event)
                }
        }
 
-       /* marker's center should be inside pattern */
+       /* marker's center should be in center of pattern */
        if(event==CLAMP_PAT_DIM || event==CLAMP_PAT_POS) {
                float dim[2];
                sub_v2_v2v2(dim, track->pat_max, track->pat_min);
 
                for(a= 0; a<2; a++) {
-                       if(track->pat_min[a] > 0.0f) {
-                               track->pat_min[a]= 0.0f;
-                               track->pat_max[a]= dim[a];
-                       }
-                       if(track->pat_max[a] < 0.0f) {
-                               track->pat_max[a]= 0.0f;
-                               track->pat_min[a]= -dim[a];
-                       }
+                       track->pat_min[a]= -dim[a]/2.f;
+                       track->pat_max[a]= dim[a]/2.f;
                }
        }
 }
index 1640bbff09b7d7e7f52d510889f24484e09a8cc4..abc07b52308784685ed9cbedb3a34bea7d3b0ec6 100644 (file)
@@ -62,7 +62,7 @@
 #include "clip_intern.h"       // own include
 
 #define B_MARKER_POS                   3
-#define B_MARKER_PAT_POS               4
+#define B_MARKER_OFFSET                        4
 #define B_MARKER_PAT_DIM               5
 #define B_MARKER_SEARCH_POS            6
 #define B_MARKER_SEARCH_DIM            7
@@ -105,9 +105,9 @@ static void trackingMarker_buttons(const bContext *C, uiLayout *layout)
 
        to_pixel_space(sc->marker_pos, marker->pos, width, height);
        to_pixel_space(sc->track_pat, pat_dim, width, height);
-       to_pixel_space(sc->track_pat_pos, pat_pos, width, height);
        to_pixel_space(sc->track_search, search_dim, width, height);
        to_pixel_space(sc->track_search_pos, search_pos, width, height);
+       to_pixel_space(sc->track_offset, track->offset, width, height);
 
        sc->marker_flag= marker->flag;
 
@@ -122,17 +122,19 @@ static void trackingMarker_buttons(const bContext *C, uiLayout *layout)
        block= uiLayoutAbsoluteBlock(col);
        uiBlockBeginAlign(block);
 
-       uiDefBut(block, LABEL, 0, "Position:", 0, 171, 300, 19, NULL, 0, 0, 0, 0, "");
-       uiDefButF(block, NUM, B_MARKER_POS, "X:", 10, 152, 145, 19, &sc->marker_pos[0],
+       uiDefBut(block, LABEL, 0, "Position:", 0, 190, 300, 19, NULL, 0, 0, 0, 0, "");
+       uiDefButF(block, NUM, B_MARKER_POS, "X:", 10, 171, 145, 19, &sc->marker_pos[0],
                -10*width, 10.0*width, step, digits, "X-position of marker at frame in screen coordinates.");
-       uiDefButF(block, NUM, B_MARKER_POS, "Y:", 165, 152, 145, 19, &sc->marker_pos[1],
+       uiDefButF(block, NUM, B_MARKER_POS, "Y:", 165, 171, 145, 19, &sc->marker_pos[1],
                -10*height, 10.0*height, step, digits, "Y-position of marker at frame in screen coordinates.");
 
-       uiDefBut(block, LABEL, 0, "Pattern Area:", 0, 133, 300, 19, NULL, 0, 0, 0, 0, "");
-       uiDefButF(block, NUM, B_MARKER_PAT_POS, "X:", 10, 114, 145, 19, &sc->track_pat_pos[0],
-               -width, width, step, digits, "X-position of pattern at frame in screen coordinates relative to marker's position.");
-       uiDefButF(block, NUM, B_MARKER_PAT_POS, "Y:", 165, 114, 145, 19, &sc->track_pat_pos[1],
-               -height, height, step, digits, "Y-position of pattern at frame in screen coordinates relative to marker's position.");
+       uiDefBut(block, LABEL, 0, "Offset:", 0, 152, 300, 19, NULL, 0, 0, 0, 0, "");
+       uiDefButF(block, NUM, B_MARKER_OFFSET, "X:", 10, 133, 145, 19, &sc->track_offset[0],
+               -10*width, 10.0*width, step, digits, "X-offset to parenting point.");
+       uiDefButF(block, NUM, B_MARKER_OFFSET, "Y:", 165, 133, 145, 19, &sc->track_offset[1],
+               -10*height, 10.0*height, step, digits, "Y-offset to parenting point.");
+
+       uiDefBut(block, LABEL, 0, "Pattern Area:", 0, 114, 300, 19, NULL, 0, 0, 0, 0, "");
        uiDefButF(block, NUM, B_MARKER_PAT_DIM, "Width:", 10, 95, 300, 19, &sc->track_pat[0], 3.0f,
                10.0*width, step, digits, "Width of marker's pattern in screen soordinates.");
        uiDefButF(block, NUM, B_MARKER_PAT_DIM, "Height:", 10, 76, 300, 19, &sc->track_pat[1], 3.0f,
@@ -171,30 +173,22 @@ static void do_tracking_marker(bContext *C, void *UNUSED(arg), int event)
 
                ok= 1;
        }
-       else if(event==B_MARKER_PAT_POS) {
-               float delta[2], side[2];
-
-               sub_v2_v2v2(side, track->pat_max, track->pat_min);
-               mul_v2_fl(side, 0.5f);
-
-               delta[0]= sc->track_pat_pos[0]/width;
-               delta[1]= sc->track_pat_pos[1]/height;
-
-               sub_v2_v2v2(track->pat_min, delta, side);
-               add_v2_v2v2(track->pat_max, delta, side);
-
-               BKE_tracking_clamp_track(track, CLAMP_PAT_POS);
-
-               ok= 1;
-       }
        else if(event==B_MARKER_PAT_DIM) {
-               float dim[2];
+               float dim[2], pat_dim[2];
+
+               sub_v2_v2v2(pat_dim, track->pat_max, track->pat_min);
 
                dim[0]= sc->track_pat[0]/width;
                dim[1]= sc->track_pat[1]/height;
 
-               mul_v2_v2fl(track->pat_min, dim, -0.5);
-               mul_v2_v2fl(track->pat_max, dim, 0.5);
+               sub_v2_v2(dim, pat_dim);
+               mul_v2_fl(dim, 0.5f);
+
+               track->pat_min[0]-= dim[0];
+               track->pat_min[1]-= dim[1];
+
+               track->pat_max[0]+= dim[0];
+               track->pat_max[1]+= dim[1];
 
                BKE_tracking_clamp_track(track, CLAMP_PAT_DIM);
 
@@ -217,13 +211,21 @@ static void do_tracking_marker(bContext *C, void *UNUSED(arg), int event)
                ok= 1;
        }
        else if(event==B_MARKER_SEARCH_DIM) {
-               float dim[2];
+               float dim[2], search_dim[2];
+
+               sub_v2_v2v2(search_dim, track->search_max, track->search_min);
 
                dim[0]= sc->track_search[0]/width;
                dim[1]= sc->track_search[1]/height;
 
-               mul_v2_v2fl(track->search_min, dim, -0.5);
-               mul_v2_v2fl(track->search_max, dim, 0.5);
+               sub_v2_v2(dim, search_dim);
+               mul_v2_fl(dim, 0.5f);
+
+               track->search_min[0]-= dim[0];
+               track->search_min[1]-= dim[1];
+
+               track->search_max[0]+= dim[0];
+               track->search_max[1]+= dim[1];
 
                BKE_tracking_clamp_track(track, CLAMP_SEARCH_DIM);
 
@@ -231,6 +233,11 @@ static void do_tracking_marker(bContext *C, void *UNUSED(arg), int event)
        } else if(event==B_MARKER_FLAG) {
                marker->flag= sc->marker_flag;
 
+               ok= 1;
+       } else if(event==B_MARKER_OFFSET) {
+               track->offset[0]= sc->track_offset[0]/width;
+               track->offset[1]= sc->track_offset[1]/height;
+
                ok= 1;
        }
 
index 92ecde363e3957817b5328f1182cc94089e59e09..62877a8b67e0f544e72ecb0d2249650d47eab8ae 100644 (file)
@@ -47,6 +47,7 @@
 #include "BLI_utildefines.h"
 #include "BLI_math.h"
 #include "BLI_string.h"
+#include "BLI_rect.h"
 
 #include "ED_screen.h"
 #include "ED_clip.h"
@@ -275,20 +276,48 @@ static void draw_track_path(SpaceClip *sc, MovieClip *clip, MovieTrackingTrack *
        glPointSize(1.0f);
 }
 
-static void draw_marker_outline(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker)
+static void draw_marker_outline(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker, int width, int height)
 {
        int tiny= sc->flag&SC_SHOW_TINY_MARKER;
        int show_pat= 0;
+       float px[2];
 
        UI_ThemeColor(TH_MARKER_OUTLINE);
 
+       px[0]= 1.0f/width/sc->zoom;
+       px[1]= 1.0f/height/sc->zoom;
+
        if((marker->flag&MARKER_DISABLED)==0) {
-               if(tiny) glPointSize(3.0f);
-               else glPointSize(4.0f);
-               glBegin(GL_POINTS);
-                       glVertex2f(marker->pos[0], marker->pos[1]);
-               glEnd();
-               glPointSize(1.0f);
+               float pos[2];
+               rctf r;
+
+               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);
+
+               if(BLI_in_rctf(&r, pos[0]-marker->pos[0], pos[1]-marker->pos[1])) {
+                       if(tiny) glPointSize(3.0f);
+                       else glPointSize(4.0f);
+                       glBegin(GL_POINTS);
+                               glVertex2f(pos[0], pos[1]);
+                       glEnd();
+                       glPointSize(1.0f);
+               } else {
+                       if(!tiny) glLineWidth(3.0f);
+                       glBegin(GL_LINES);
+                               glVertex2f(pos[0] + px[0]*2, pos[1]);
+                               glVertex2f(pos[0] + px[0]*8, pos[1]);
+
+                               glVertex2f(pos[0] - px[0]*2, pos[1]);
+                               glVertex2f(pos[0] - px[0]*8, pos[1]);
+
+                               glVertex2f(pos[0], pos[1] - px[1]*2);
+                               glVertex2f(pos[0], pos[1] - px[1]*8);
+
+                               glVertex2f(pos[0], pos[1] + px[1]*2);
+                               glVertex2f(pos[0], pos[1] + px[1]*8);
+                       glEnd();
+                       if(!tiny) glLineWidth(1.0f);
+               }
        }
 
        /* pattern and search outline */
@@ -335,29 +364,57 @@ static void track_colors(MovieTrackingTrack *track, int act, float col[3], float
        }
 }
 
-static void draw_marker_areas(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker, int act, int sel)
+static void draw_marker_areas(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker, int width, int height, int act, int sel)
 {
        int tiny= sc->flag&SC_SHOW_TINY_MARKER;
        int show_pat= 0;
-       float col[3], scol[3];
+       float col[3], scol[3], px[2];
 
        track_colors(track, act, col, scol);
 
-       /* marker position */
+       px[0]= 1.0f/width/sc->zoom;
+       px[1]= 1.0f/height/sc->zoom;
+
+       /* marker position and offset position */
        if((track->flag&SELECT)==sel && (marker->flag&MARKER_DISABLED)==0) {
+               float pos[2];
+               rctf r;
+
                if(track->flag&TRACK_LOCKED) {
                        if(act) UI_ThemeColor(TH_ACT_MARKER);
                        else if(track->flag&SELECT) UI_ThemeColorShade(TH_LOCK_MARKER, 64);
                        else UI_ThemeColor(TH_LOCK_MARKER);
-               } else
-               if(track->flag&SELECT) glColor3fv(scol);
-               else glColor3fv(col);
+               } else {
+                       if(track->flag&SELECT) glColor3fv(scol);
+                       else glColor3fv(col);
+               }
 
-               if(!tiny) glPointSize(2.0f);
-               glBegin(GL_POINTS);
-                       glVertex2f(marker->pos[0], marker->pos[1]);
-               glEnd();
-               if(!tiny) glPointSize(1.0f);
+               add_v2_v2v2(pos, marker->pos, track->offset);
+
+               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);
+
+               if(BLI_in_rctf(&r, pos[0]-marker->pos[0], pos[1]-marker->pos[1])) {
+                       if(!tiny) glPointSize(2.0f);
+                       glBegin(GL_POINTS);
+                               glVertex2f(pos[0], pos[1]);
+                       glEnd();
+                       if(!tiny) glPointSize(1.0f);
+               } else {
+                       glBegin(GL_LINES);
+                               glVertex2f(pos[0] + px[0]*3, pos[1]);
+                               glVertex2f(pos[0] + px[0]*7, pos[1]);
+
+                               glVertex2f(pos[0] - px[0]*3, pos[1]);
+                               glVertex2f(pos[0] - px[0]*7, pos[1]);
+
+                               glVertex2f(pos[0], pos[1] - px[1]*3);
+                               glVertex2f(pos[0], pos[1] - px[1]*7);
+
+                               glVertex2f(pos[0], pos[1] + px[1]*3);
+                               glVertex2f(pos[0], pos[1] + px[1]*7);
+                       glEnd();
+               }
        }
 
        /* pattern */
@@ -429,7 +486,7 @@ static void draw_marker_areas(SpaceClip *sc, MovieTrackingTrack *track, MovieTra
 
 static void draw_marker_slide_zones(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker, int outline, int act, int width, int height)
 {
-       float x, y, dx, dy, tdx, tdy;
+       float x, y, dx, dy, patdx, patdy, searchdx, searchdy, tdx, tdy;
        int tiny= sc->flag&SC_SHOW_TINY_MARKER;
        float col[3], scol[3];
 
@@ -444,23 +501,45 @@ static void draw_marker_slide_zones(SpaceClip *sc, MovieTrackingTrack *track, Mo
        if(outline) {
                glLineWidth(3.0f);
                UI_ThemeColor(TH_MARKER_OUTLINE);
-       } else {
-               if(track->search_flag&SELECT) glColor3fv(scol);
-               else glColor3fv(col);
        }
 
        glPushMatrix();
        glTranslatef(marker->pos[0], marker->pos[1], 0);
 
-       x= track->search_min[0];
-       y= track->search_max[1];
+       dx= 6.0f/width/sc->zoom;
+       dy= 6.0f/height/sc->zoom;
 
-       dx= 12.0f/width/sc->zoom;
-       dy= 12.0f/height/sc->zoom;
+       patdx= MIN2(dx, (track->pat_max[0]-track->pat_min[0])/6.f);
+       patdy= MIN2(dy, (track->pat_max[1]-track->pat_min[1])/6.f);
 
-       if(sc->flag&SC_SHOW_MARKER_SEARCH) {
-               tdx=MIN2(dx, (track->search_max[0]-track->search_min[0])/3);
-               tdy=MIN2(dy, (track->search_max[1]-track->search_min[1])/3);
+       searchdx= MIN2(dx, (track->search_max[0]-track->search_min[0])/6.f);
+       searchdy= MIN2(dy, (track->search_max[1]-track->search_min[1])/6.f);
+
+       /* position square */
+       if(sc->flag&SC_SHOW_MARKER_SEARCH || sc->flag&SC_SHOW_MARKER_PATTERN) {
+               if(sc->flag&SC_SHOW_MARKER_SEARCH) {
+                       if(!outline) {
+                               if(track->search_flag&SELECT) glColor3fv(scol);
+                               else glColor3fv(col);
+                       }
+
+                       x= track->search_min[0];
+                       y= track->search_max[1];
+
+                       tdx= searchdx;
+                       tdy= searchdy;
+               } else {
+                       if(!outline) {
+                               if(track->pat_flag&SELECT) glColor3fv(scol);
+                               else glColor3fv(col);
+                       }
+
+                       x= track->pat_min[0];
+                       y= track->pat_max[1];
+
+                       tdx= patdx;
+                       tdy= patdy;
+               }
 
                if(outline) {
                        tdx+= 1.0f/sc->zoom/width;
@@ -468,18 +547,29 @@ static void draw_marker_slide_zones(SpaceClip *sc, MovieTrackingTrack *track, Mo
                }
 
                glBegin(GL_QUADS);
-                       glVertex3f(xy, 0);
-                       glVertex3f(x+tdx, y, 0);
+                       glVertex3f(x-tdx, y+tdy, 0);
+                       glVertex3f(x+tdx, y+tdy, 0);
                        glVertex3f(x+tdx, y-tdy, 0);
-                       glVertex3f(x, y-tdy, 0);
+                       glVertex3f(x-tdx, y-tdy, 0);
                glEnd();
+       }
+
+       /* search resizing triangle */
+       if(sc->flag&SC_SHOW_MARKER_SEARCH) {
+               if(!outline) {
+                       if(track->search_flag&SELECT) glColor3fv(scol);
+                       else glColor3fv(col);
+               }
 
                x= track->search_max[0];
                y= track->search_min[1];
 
+               tdx= searchdx*2.f;
+               tdy= searchdy*2.f;
+
                if(outline) {
-                       tdx+= 1.0f/sc->zoom/width;
-                       tdy+= 1.0f/sc->zoom/height;
+                       tdx+= 2.0f/sc->zoom/width;
+                       tdy+= 2.0f/sc->zoom/height;
                }
 
                glBegin(GL_TRIANGLES);
@@ -489,44 +579,22 @@ static void draw_marker_slide_zones(SpaceClip *sc, MovieTrackingTrack *track, Mo
                glEnd();
        }
 
+       /* pattern resizing triangle */
        if(sc->flag&SC_SHOW_MARKER_PATTERN) {
-               float tdx2= 0, tdy2= 0;
-               /* use smaller slider for pattern area */
-               dx= 12.0f/width/sc->zoom;
-               dy= 12.0f/height/sc->zoom;
-
                if(!outline) {
                        if(track->pat_flag&SELECT) glColor3fv(scol);
                        else glColor3fv(col);
                }
 
-               tdx=MIN2(dx, (track->pat_max[0]-track->pat_min[0])/3);
-               tdy=MIN2(dy, (track->pat_max[1]-track->pat_min[1])/3);
-
-               if(outline) {
-                       tdx+= 1.0f/sc->zoom/width;
-                       tdy+= 1.0f/sc->zoom/height;
-
-                       tdx2+= 1.0f/sc->zoom/width;
-                       tdy2+= 1.0f/sc->zoom/height;
-               }
-
-               x= track->pat_min[0];
-               y= track->pat_max[1];
-
-               glBegin(GL_QUADS);
-                       glVertex3f(x+tdx2, y-tdy2, 0);
-                       glVertex3f(x-tdx, y-tdy2, 0);
-                       glVertex3f(x-tdx, y+tdy, 0);
-                       glVertex3f(x+tdx2, y+tdy, 0);
-               glEnd();
-
                x= track->pat_max[0];
                y= track->pat_min[1];
 
+               tdx= patdx*2.f;
+               tdy= patdy*2.f;
+
                if(outline) {
-                       tdx+= 1.0f/sc->zoom/width;
-                       tdy+= 1.0f/sc->zoom/height;
+                       tdx+= 2.0f/sc->zoom/width;
+                       tdy+= 2.0f/sc->zoom/height;
                }
 
                glBegin(GL_TRIANGLES);
@@ -688,9 +756,9 @@ static void draw_tracking_tracks(SpaceClip *sc, ARegion *ar, MovieClip *clip,
                        marker= BKE_tracking_get_marker(track, framenr);
 
                        if(MARKER_VISIBLE(sc, marker)) {
-                               draw_marker_outline(sc, track, marker);
+                               draw_marker_outline(sc, track, marker, width, height);
+                               draw_marker_areas(sc, track, marker, width, height, 0, 0);
                                draw_marker_slide_zones(sc, track, marker, 1, 0, width, height);
-                               draw_marker_areas(sc, track, marker, 0, 0);
                        }
                }
 
@@ -708,7 +776,7 @@ static void draw_tracking_tracks(SpaceClip *sc, ARegion *ar, MovieClip *clip,
                                marker= BKE_tracking_get_marker(track, framenr);
 
                                if(MARKER_VISIBLE(sc, marker)) {
-                                       draw_marker_areas(sc, track, marker, 0, 1);
+                                       draw_marker_areas(sc, track, marker, width, height, 0, 1);
                                        draw_marker_slide_zones(sc, track, marker, 0, 0, width, height);
                                }
                        }
@@ -723,7 +791,7 @@ static void draw_tracking_tracks(SpaceClip *sc, ARegion *ar, MovieClip *clip,
                        marker= BKE_tracking_get_marker(sel, framenr);
 
                        if(MARKER_VISIBLE(sc, marker)) {
-                               draw_marker_areas(sc, sel, marker, 1, 1);
+                               draw_marker_areas(sc, sel, marker, width, height, 1, 1);
                                draw_marker_slide_zones(sc, sel, marker, 0, 1, width, height);
                        }
                }
index 1e066102cdaaa01e2a423e4c97a95e1abd5a8199..a82d46896f13418281d3352cf281a575eff5ca14 100644 (file)
@@ -77,11 +77,11 @@ static void clip_scopes_tag_refresh(ScrArea *sa)
 
        /* only while proeprties are visible */
        for (ar=sa->regionbase.first; ar; ar=ar->next) {
-               if (ar->regiontype == RGN_TYPE_PREVIEW && ar->flag & RGN_FLAG_HIDDEN)
+               if (ar->regiontype == RGN_TYPE_UI && ar->flag & RGN_FLAG_HIDDEN)
                        return;
        }
 
-       sc->scopes.ok=0;
+       sc->scopes.ok= 0;
 }
 
 /* ******************** default callbacks for clip space ***************** */
@@ -268,14 +268,29 @@ static void clip_keymap(struct wmKeyConfig *keyconf)
        wmKeyMap *keymap;
        wmKeyMapItem *kmi;
 
-       keymap= WM_keymap_find(keyconf, "Clip", SPACE_CLIP, 0);
+       /* ******** Global hotkeys avalaible for all regions ******** */
+
+       keymap= WM_keymap_find(keyconf, "Clip Globals", SPACE_CLIP, 0);
 
        WM_keymap_add_item(keymap, "CLIP_OT_open", OKEY, KM_PRESS, KM_ALT, 0);
 
        WM_keymap_add_item(keymap, "CLIP_OT_tools", TKEY, KM_PRESS, 0, 0);
-        WM_keymap_add_item(keymap, "CLIP_OT_properties", NKEY, KM_PRESS, 0, 0);
+       WM_keymap_add_item(keymap, "CLIP_OT_properties", NKEY, KM_PRESS, 0, 0);
 
-       /* ********* View/navigation ******** */
+       kmi= WM_keymap_add_item(keymap, "CLIP_OT_track_markers", LEFTARROWKEY, KM_PRESS, KM_ALT, 0);
+       RNA_boolean_set(kmi->ptr, "backwards", 1);
+       WM_keymap_add_item(keymap, "CLIP_OT_track_markers", RIGHTARROWKEY, KM_PRESS, KM_ALT, 0);
+       kmi= WM_keymap_add_item(keymap, "CLIP_OT_track_markers", TKEY, KM_PRESS, KM_CTRL, 0);
+       RNA_boolean_set(kmi->ptr, "sequence", 1);
+       kmi= WM_keymap_add_item(keymap, "CLIP_OT_track_markers", TKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
+       RNA_boolean_set(kmi->ptr, "backwards", 1);
+       RNA_boolean_set(kmi->ptr, "sequence", 1);
+
+       /* ******** Hotkeys avalaible for main region only ******** */
+
+       keymap= WM_keymap_find(keyconf, "Clip Editor", SPACE_CLIP, 0);
+
+       /* View/navigation */
 
        WM_keymap_add_item(keymap, "CLIP_OT_view_pan", MIDDLEMOUSE, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "CLIP_OT_view_pan", MIDDLEMOUSE, KM_PRESS, KM_SHIFT, 0);
@@ -310,15 +325,6 @@ static void clip_keymap(struct wmKeyConfig *keyconf)
 
        WM_keymap_add_item(keymap, "CLIP_OT_add_marker_slide", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
 
-       kmi= WM_keymap_add_item(keymap, "CLIP_OT_track_markers", LEFTARROWKEY, KM_PRESS, KM_ALT, 0);
-       RNA_boolean_set(kmi->ptr, "backwards", 1);
-       WM_keymap_add_item(keymap, "CLIP_OT_track_markers", RIGHTARROWKEY, KM_PRESS, KM_ALT, 0);
-       kmi= WM_keymap_add_item(keymap, "CLIP_OT_track_markers", TKEY, KM_PRESS, KM_CTRL, 0);
-       RNA_boolean_set(kmi->ptr, "sequence", 1);
-       kmi= WM_keymap_add_item(keymap, "CLIP_OT_track_markers", TKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
-       RNA_boolean_set(kmi->ptr, "backwards", 1);
-       RNA_boolean_set(kmi->ptr, "sequence", 1);
-
        kmi= WM_keymap_add_item(keymap, "CLIP_OT_clear_track_path", TKEY, KM_PRESS, KM_ALT, 0);
        RNA_enum_set(kmi->ptr, "action", TRACK_CLEAR_REMAINED);
        kmi= WM_keymap_add_item(keymap, "CLIP_OT_clear_track_path", TKEY, KM_PRESS, KM_SHIFT, 0);
@@ -445,7 +451,10 @@ static void clip_main_area_init(wmWindowManager *wm, ARegion *ar)
        UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_STANDARD, ar->winx, ar->winy);
 
        /* own keymap */
-       keymap= WM_keymap_find(wm->defaultconf, "Clip", SPACE_CLIP, 0);
+       keymap= WM_keymap_find(wm->defaultconf, "Clip Globals", SPACE_CLIP, 0);
+       WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+
+       keymap= WM_keymap_find(wm->defaultconf, "Clip Editor", SPACE_CLIP, 0);
        WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
 }
 
@@ -507,7 +516,12 @@ static void clip_tools_area_draw(const bContext *C, ARegion *ar)
 /* add handlers, stuff you only do once or on area/region changes */
 static void clip_properties_area_init(wmWindowManager *wm, ARegion *ar)
 {
+       wmKeyMap *keymap;
+
        ED_region_panels_init(wm, ar);
+
+       keymap= WM_keymap_find(wm->defaultconf, "Clip Globals", SPACE_CLIP, 0);
+       WM_event_add_keymap_handler(&ar->handlers, keymap);
 }
 
 static void clip_properties_area_draw(const bContext *C, ARegion *ar)
index f328222b6717fa97226854a24a5eadba379ad8a4..416e911bd8ea988c753739ab9cc8455207aa35fe 100644 (file)
@@ -319,6 +319,342 @@ void CLIP_OT_delete_marker(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
+/********************** slide marker operator *********************/
+
+#define SLIDE_ACTION_POS       0
+#define SLIDE_ACTION_SIZE      1
+#define SLIDE_ACTION_OFFSET    2
+
+typedef struct {
+       int area, action;
+       MovieTrackingTrack *track;
+       MovieTrackingMarker *marker;
+
+       int mval[2];
+       int width, height;
+       float *min, *max, *pos, *offset;
+       float smin[2], smax[2], spos[2], soff[2];
+
+       int lock, accurate;
+} SlideMarkerData;
+
+static SlideMarkerData *create_slide_marker_data(SpaceClip *sc, MovieTrackingTrack *track,
+                       MovieTrackingMarker *marker, wmEvent *event, int area, int action, int width, int height)
+{
+       SlideMarkerData *data= MEM_callocN(sizeof(SlideMarkerData), "slide marker data");
+
+       marker= BKE_tracking_ensure_marker(track, sc->user.framenr);
+
+       data->area= area;
+       data->action= action;
+       data->track= track;
+       data->marker= marker;
+
+       if(area==TRACK_AREA_POINT) {
+               data->pos= marker->pos;
+               data->offset= track->offset;
+               copy_v2_v2(data->spos, marker->pos);
+               copy_v2_v2(data->soff, track->offset);
+       } else if(area==TRACK_AREA_PAT) {
+               data->min= track->pat_min;
+               data->max= track->pat_max;
+       } else if(area==TRACK_AREA_SEARCH) {
+               data->min= track->search_min;
+               data->max= track->search_max;
+       }
+
+       if(ELEM(area, TRACK_AREA_PAT, TRACK_AREA_SEARCH)) {
+               copy_v2_v2(data->smin, data->min);
+               copy_v2_v2(data->smax, data->max);
+       }
+
+       data->mval[0]= event->mval[0];
+       data->mval[1]= event->mval[1];
+
+       data->width= width;
+       data->height= height;
+
+       if(area!=TRACK_AREA_POINT)
+               data->lock= 1;
+
+       return data;
+}
+
+/* corner = 0: right-bottom corner,
+   corner = 1: left-top corner */
+static int mouse_on_corner(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker,
+                       int area, float co[2], int corner, int width, int height)
+{
+       int inside= 0;
+       float size= 12.f;
+       float min[2], max[2];
+       float nco[2], 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);
+       } else {
+               copy_v2_v2(min, track->pat_min);
+               copy_v2_v2(max, track->pat_max);
+       }
+
+       nco[0]= co[0]/width;
+       nco[1]= co[1]/height;
+
+       dx= size/width/sc->zoom;
+       dy= size/height/sc->zoom;
+
+       tdx= 5.0f/width/sc->zoom;
+       tdy= 5.0f/height/sc->zoom;
+
+       dx= MIN2(dx, (max[0]-min[0])/6.f) + tdx;
+       dy= MIN2(dy, (max[1]-min[1])/6.f) + tdy;
+
+       if(corner==0) {
+               crn[0]= marker->pos[0]+max[0];
+               crn[1]= marker->pos[1]+min[1];
+
+               inside= nco[0]>=crn[0]-dx && nco[0]<=crn[0]+tdx && nco[1]>=crn[1]-tdy && nco[1]<=crn[1]+dy;
+       } else {
+               crn[0]= marker->pos[0]+min[0];
+               crn[1]= marker->pos[1]+max[1];
+
+               inside= nco[0]>=crn[0]-dx && nco[0]<=crn[0]+dx && nco[1]>=crn[1]-dy && nco[1]<=crn[1]+dy;
+       }
+
+       return inside;
+}
+
+static int mouse_on_offset(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker,
+                       float co[2], int width, int height)
+{
+       float pos[2], nco[2], dx, dy;
+
+       add_v2_v2v2(pos, marker->pos, track->offset);
+
+       nco[0]= co[0]/width;
+       nco[1]= co[1]/height;
+
+       dx= 12.f/width/sc->zoom;
+       dy= 12.f/height/sc->zoom;
+
+       dx=MIN2(dx, (track->pat_max[0]-track->pat_min[0])/3);
+       dy=MIN2(dy, (track->pat_max[1]-track->pat_min[1])/3);
+
+       return nco[0]>=pos[0]-dx && nco[0]<=pos[0]+dx && nco[1]>=pos[1]-dy && nco[1]<=pos[1]+dy;
+}
+
+static void hide_cursor(bContext *C)
+{
+       wmWindow *win= CTX_wm_window(C);
+
+       WM_cursor_set(win, CURSOR_NONE);
+}
+
+static void show_cursor(bContext *C)
+{
+       wmWindow *win= CTX_wm_window(C);
+
+       WM_cursor_set(win, CURSOR_STD);
+}
+
+static void *slide_marker_customdata(bContext *C, wmEvent *event)
+{
+       SpaceClip *sc= CTX_wm_space_clip(C);
+       MovieClip *clip= ED_space_clip(sc);
+       MovieTrackingTrack *track;
+       int width, height;
+       float co[2];
+       void *customdata= NULL;
+
+       ED_space_clip_size(sc, &width, &height);
+
+       if(width==0 || height==0)
+               return NULL;
+
+       mouse_pos(C, event, co);
+
+       track= clip->tracking.tracks.first;
+       while(track) {
+               if(TRACK_SELECTED(track) && (track->flag&TRACK_LOCKED)==0) {
+                       MovieTrackingMarker *marker= BKE_tracking_get_marker(track, sc->user.framenr);
+
+                       if((marker->flag&MARKER_DISABLED)==0) {
+                               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_POINT, SLIDE_ACTION_POS, 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, SLIDE_ACTION_SIZE, width, height);
+                               }
+
+                               if(!customdata && sc->flag&SC_SHOW_MARKER_PATTERN) {
+                                       if((sc->flag&SC_SHOW_MARKER_SEARCH)==0)
+                                               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_POINT, SLIDE_ACTION_POS, 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);
+                               }
+
+                               if(!customdata)
+                                       if(mouse_on_offset(sc, track, marker, co, width, height))
+                                               customdata= create_slide_marker_data(sc, track, marker, event, TRACK_AREA_POINT, SLIDE_ACTION_OFFSET, width, height);
+
+                               if(customdata)
+                                       break;
+                       }
+               }
+
+               track= track->next;
+       }
+
+       return customdata;
+}
+
+static int slide_marker_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+       op->customdata= slide_marker_customdata(C, event);
+
+       if(op->customdata) {
+               hide_cursor(C);
+               WM_event_add_modal_handler(C, op);
+
+               return OPERATOR_RUNNING_MODAL;
+       }
+
+       return OPERATOR_CANCELLED;
+}
+
+static void cancel_mouse_slide(SlideMarkerData *data)
+{
+       /* cancel sliding */
+       if(data->area == TRACK_AREA_POINT) {
+               if(data->action==SLIDE_ACTION_OFFSET) {
+                       data->offset[0]= data->soff[0];
+                       data->offset[1]= data->soff[1];
+               } else {
+                       data->pos[0]= data->spos[0];
+                       data->pos[1]= data->spos[1];
+               }
+       } else {
+               data->min[0]= data->smin[0];
+               data->max[0]= data->smax[0];
+
+               data->min[1]= data->smin[1];
+               data->max[1]= data->smax[1];
+       }
+
+}
+
+static int slide_marker_modal(bContext *C, wmOperator *op, wmEvent *event)
+{
+       SpaceClip *sc= CTX_wm_space_clip(C);
+       SlideMarkerData *data= (SlideMarkerData *)op->customdata;
+       float dx, dy, mdelta[2];
+
+       switch(event->type) {
+               case LEFTCTRLKEY:
+               case RIGHTCTRLKEY:
+               case LEFTSHIFTKEY:
+               case RIGHTSHIFTKEY:
+                       if(data->area!=TRACK_AREA_POINT)
+                               if(ELEM(event->type, LEFTCTRLKEY, RIGHTCTRLKEY))
+                                       data->lock= event->val==KM_RELEASE;
+
+                       if(ELEM(event->type, LEFTSHIFTKEY, RIGHTSHIFTKEY))
+                               data->accurate= event->val==KM_PRESS;
+
+                       /* no break! update area size */
+
+               case MOUSEMOVE:
+                       mdelta[0]= event->mval[0]-data->mval[0];
+                       mdelta[1]= event->mval[1]-data->mval[1];
+
+                       dx= mdelta[0]/data->width/sc->zoom;
+
+                       if(data->lock) dy= -dx/data->height*data->width;
+                       else dy= mdelta[1]/data->height/sc->zoom;
+
+                       if(data->accurate) {
+                               dx/= 5;
+                               dy/= 5;
+                       }
+
+                       if(data->area==TRACK_AREA_POINT) {
+                               if(data->action==SLIDE_ACTION_OFFSET) {
+                                       data->offset[0]= data->soff[0]+dx;
+                                       data->offset[1]= data->soff[1]+dy;
+                               } 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);
+                               DAG_id_tag_update(&sc->clip->id, 0);
+                       } 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);
+                               else BKE_tracking_clamp_track(data->track, CLAMP_PAT_DIM);
+                       }
+
+                       WM_event_add_notifier(C, NC_MOVIECLIP|NA_EDITED, NULL);
+
+                       break;
+
+               case LEFTMOUSE:
+                       if(event->val==KM_RELEASE) {
+                               MEM_freeN(op->customdata);
+
+                               show_cursor(C);
+
+                               return OPERATOR_FINISHED;
+                       }
+
+                       break;
+
+               case ESCKEY:
+                       cancel_mouse_slide(op->customdata);
+
+                       MEM_freeN(op->customdata);
+
+                       show_cursor(C);
+
+                       WM_event_add_notifier(C, NC_MOVIECLIP|NA_EDITED, NULL);
+
+                       return OPERATOR_CANCELLED;
+       }
+
+       return OPERATOR_RUNNING_MODAL;
+}
+
+void CLIP_OT_slide_marker(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Slide Marker";
+       ot->description= "Slide marker areas";
+       ot->idname= "CLIP_OT_slide_marker";
+
+       /* api callbacks */
+       //ot->exec= slide_marker_exec;
+       ot->poll= space_clip_frame_poll;
+       ot->invoke= slide_marker_invoke;
+       ot->modal= slide_marker_modal;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+       /* properties */
+       RNA_def_float_vector(ot->srna, "offset", 2, NULL, -FLT_MAX, FLT_MAX,
+               "Offset", "Offset in floating point units, 1.0 is the width and height of the image.", -FLT_MAX, FLT_MAX);
+}
+
 /********************** mouse select operator *********************/
 
 static int mouse_on_side(float co[2], float x1, float y1, float x2, float y2, float epsx, float epsy)
@@ -470,8 +806,15 @@ static int select_exec(bContext *C, wmOperator *op)
 static int select_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
        ARegion *ar= CTX_wm_region(C);
+       void *customdata;
        float co[2];
 
+       customdata= slide_marker_customdata(C, event);
+       if(customdata) {
+               MEM_freeN(customdata);
+               return OPERATOR_PASS_THROUGH;
+       }
+
        UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &co[0], &co[1]);
        RNA_float_set_array(op->ptr, "location", co);
 
@@ -744,7 +1087,7 @@ void CLIP_OT_select_all(wmOperatorType *ot)
        WM_operator_properties_select_all(ot);
 }
 
-/********************** select grouped opertaotr *********************/
+/********************** select grouped operator *********************/
 
 static int select_groped_exec(bContext *C, wmOperator *op)
 {
@@ -1715,314 +2058,8 @@ void CLIP_OT_set_center_principal(wmOperatorType *ot)
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
-/********************** slide marker opertaotr *********************/
-
-#define SLIDE_ACTION_POS       0
-#define SLIDE_ACTION_SIZE      1
-
-typedef struct {
-       int area, action;
-       MovieTrackingTrack *track;
-       MovieTrackingMarker *marker;
-
-       int mval[2];
-       int width, height;
-       float *min, *max, *pos;
-       float smin[2], smax[2], spos[2];
-
-       int lock, accurate;
-} SlideMarkerData;
-
-static SlideMarkerData *create_slide_marker_data(SpaceClip *sc, MovieTrackingTrack *track,
-                       MovieTrackingMarker *marker, wmEvent *event, int area, int act, int width, int height)
-{
-       SlideMarkerData *data= MEM_callocN(sizeof(SlideMarkerData), "slide marker data");
-
-       marker= BKE_tracking_ensure_marker(track, sc->user.framenr);
-
-       data->area= area;
-       data->action= act;
-       data->track= track;
-       data->marker= marker;
-
-       if(area==TRACK_AREA_POINT) {
-               data->pos= marker->pos;
-               copy_v2_v2(data->spos, marker->pos);
-       } else if(area==TRACK_AREA_PAT) {
-               data->min= track->pat_min;
-               data->max= track->pat_max;
-       } else if(area==TRACK_AREA_SEARCH) {
-               data->min= track->search_min;
-               data->max= track->search_max;
-       }
-
-       if(ELEM(area, TRACK_AREA_PAT, TRACK_AREA_SEARCH)) {
-               copy_v2_v2(data->smin, data->min);
-               copy_v2_v2(data->smax, data->max);
-       }
-
-       data->mval[0]= event->mval[0];
-       data->mval[1]= event->mval[1];
-
-       data->width= width;
-       data->height= height;
-
-       if(act==SLIDE_ACTION_SIZE)
-               data->lock= 1;
-
-       return data;
-}
-
-/* corner = 0: right-bottom corner,
-   corner = 1: left-top inside corner
-   corner = 2: left top outside corder*/
-static int mouse_on_corner(SpaceClip *sc, MovieTrackingTrack *track, float size, float co[2], int corner,
-                       float *pos, float *min, float *max, int width, int height)
-{
-       int inside= 0;
-       float nco[2], crn[2], dx, dy;
-       float odx, ody;
-
-       nco[0]= co[0]/width;
-       nco[1]= co[1]/height;
-
-       dx= size/width/sc->zoom;
-       dy= size/height/sc->zoom;
-
-       odx= 5.0f/width/sc->zoom;
-       ody= 5.0f/height/sc->zoom;
-
-       dx=MIN2(dx, (track->search_max[0]-track->search_min[0])/3);
-       dy=MIN2(dy, (track->search_max[1]-track->search_min[1])/3);
-
-       if(corner==0) {
-               crn[0]= pos[0]+max[0];
-               crn[1]= pos[1]+min[1];
-
-               inside= nco[0]>=crn[0]-dx && nco[0]<=crn[0]+odx && nco[1]>=crn[1]-ody && nco[1]<=crn[1]+dy;
-       } else if(corner==1) {
-               crn[0]= pos[0]+min[0];
-               crn[1]= pos[1]+max[1];
-
-               inside= nco[0]>=crn[0]-odx && nco[0]<=crn[0]+dx && nco[1]>=crn[1]-dy && nco[1]<=crn[1]+ody;
-       } else {
-               crn[0]= pos[0]+min[0];
-               crn[1]= pos[1]+max[1];
-
-               inside= nco[0]>=crn[0]-dx && nco[0]<=crn[0]+odx && nco[1]>=crn[1]-ody && nco[1]<=crn[1]+dy;
-       }
-
-       return inside;
-}
-
-static int mouse_on_center(SpaceClip *sc, MovieTrackingTrack *track, float size,
-                           float co[2], float *pos, int width, int height)
-{
-       float nco[2], dx, dy;
-
-       nco[0]= co[0]/width;
-       nco[1]= co[1]/height;
-
-       dx= size/width/sc->zoom;
-       dy= size/height/sc->zoom;
-
-       dx=MIN2(dx, (track->pat_max[0]-track->pat_min[0])/3);
-       dy=MIN2(dy, (track->pat_max[1]-track->pat_min[1])/3);
-
-       return nco[0]>=pos[0]-dx && nco[0]<=pos[0]+dx && nco[1]>=pos[1]-dy && nco[1]<=pos[1]+dy;
-}
-
-static void hide_cursor(bContext *C)
-{
-       wmWindow *win= CTX_wm_window(C);
-
-       WM_cursor_set(win, CURSOR_NONE);
-}
-
-static void show_cursor(bContext *C)
-{
-       wmWindow *win= CTX_wm_window(C);
-
-       WM_cursor_set(win, CURSOR_STD);
-}
-
-static int slide_marker_invoke(bContext *C, wmOperator *op, wmEvent *event)
-{
-       SpaceClip *sc= CTX_wm_space_clip(C);
-       MovieClip *clip= ED_space_clip(sc);
-       MovieTrackingTrack *track;
-       int width, height;
-       float co[2];
-
-       ED_space_clip_size(sc, &width, &height);
-
-       if(width==0 || height==0)
-               return OPERATOR_PASS_THROUGH;
-
-       mouse_pos(C, event, co);
-
-       track= clip->tracking.tracks.first;
-       while(track) {
-               if(TRACK_SELECTED(track) && (track->flag&TRACK_LOCKED)==0) {
-                       MovieTrackingMarker *marker= BKE_tracking_get_marker(track, sc->user.framenr);
-
-                       if(marker && (marker->flag&MARKER_DISABLED)==0) {
-                               if(mouse_on_center(sc, track, 15.0f, co, marker->pos, width, height))
-                                       op->customdata= create_slide_marker_data(sc, track, marker, event, TRACK_AREA_POINT, SLIDE_ACTION_POS, width, height);
-
-                               if(!op->customdata && sc->flag&SC_SHOW_MARKER_SEARCH) {
-                                       if(mouse_on_corner(sc, track, 15.0f, co, 1, marker->pos, track->search_min, track->search_max, width, height))
-                                               op->customdata= create_slide_marker_data(sc, track, marker, event, TRACK_AREA_SEARCH, SLIDE_ACTION_POS, width, height);
-                                       else if(mouse_on_corner(sc, track, 15.0f, co, 0, marker->pos, track->search_min, track->search_max, width, height))
-                                               op->customdata= create_slide_marker_data(sc, track, marker, event, TRACK_AREA_SEARCH, SLIDE_ACTION_SIZE, width, height);
-                               }
-
-                               if(!op->customdata && sc->flag&SC_SHOW_MARKER_PATTERN) {
-                                       if(mouse_on_corner(sc, track, 15.0f, co, 2, marker->pos, track->pat_min, track->pat_max, width, height))
-                                               op->customdata= create_slide_marker_data(sc, track, marker, event, TRACK_AREA_PAT, SLIDE_ACTION_POS, width, height);
-                                       else if(mouse_on_corner(sc, track, 15.0f, co, 0, marker->pos, track->pat_min, track->pat_max, width, height))
-                                               op->customdata= create_slide_marker_data(sc, track, marker, event, TRACK_AREA_PAT, SLIDE_ACTION_SIZE, width, height);
-                               }
-
-                               if(op->customdata) {
-                                       hide_cursor(C);
-                                       WM_event_add_modal_handler(C, op);
-
-                                       return OPERATOR_RUNNING_MODAL;
-                               }
-                       }
-               }
-
-               track= track->next;
-       }
-
-       return OPERATOR_CANCELLED;
-}
-
-static int slide_marker_modal(bContext *C, wmOperator *op, wmEvent *event)
-{
-       SpaceClip *sc= CTX_wm_space_clip(C);
-       SlideMarkerData *data= (SlideMarkerData *)op->customdata;
-       float dx, dy, mdelta[2];
-
-       switch(event->type) {
-               case LEFTCTRLKEY:
-               case RIGHTCTRLKEY:
-               case LEFTSHIFTKEY:
-               case RIGHTSHIFTKEY:
-                       if(data->action == SLIDE_ACTION_SIZE)
-                               if(ELEM(event->type, LEFTCTRLKEY, RIGHTCTRLKEY))
-                                       data->lock= event->val==KM_RELEASE;
-
-                       if(ELEM(event->type, LEFTSHIFTKEY, RIGHTSHIFTKEY))
-                               data->accurate= event->val==KM_PRESS;
-
-                       /* no break! update area size */
-
-               case MOUSEMOVE:
-                       mdelta[0]= event->mval[0]-data->mval[0];
-                       mdelta[1]= event->mval[1]-data->mval[1];
-
-                       dx= mdelta[0]/data->width/sc->zoom;
-
-                       if(data->lock) dy= -dx/data->height*data->width;
-                       else dy= mdelta[1]/data->height/sc->zoom;
-
-                       if(data->accurate) {
-                               dx/= 5;
-                               dy/= 5;
-                       }
-
-                       if(data->area == TRACK_AREA_POINT) {
-                               data->pos[0]= data->spos[0]+dx;
-                               data->pos[1]= data->spos[1]+dy;
-
-                               data->marker->flag&= ~MARKER_TRACKED;
-                       } else {
-                               if(data->action==SLIDE_ACTION_SIZE) {
-                                       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);
-                                       else BKE_tracking_clamp_track(data->track, CLAMP_PAT_DIM);
-                               } 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_POS);
-                                       else BKE_tracking_clamp_track(data->track, CLAMP_PAT_POS);
-                               }
-                       }
-
-                       WM_event_add_notifier(C, NC_MOVIECLIP|NA_EDITED, NULL);
-
-                       break;
-
-               case LEFTMOUSE:
-                       if(event->val==KM_RELEASE) {
-                               MEM_freeN(op->customdata);
-
-                               show_cursor(C);
-
-                               return OPERATOR_FINISHED;
-                       }
-
-                       break;
-
-               case ESCKEY:
-                       /* cancel sliding */
-                       if(data->area == TRACK_AREA_POINT) {
-                               data->pos[0]= data->spos[0];
-                               data->pos[1]= data->spos[1];
-                       } else {
-                               data->min[0]= data->smin[0];
-                               data->max[0]= data->smax[0];
-
-                               data->min[1]= data->smin[1];
-                               data->max[1]= data->smax[1];
-                       }
-
-                       MEM_freeN(op->customdata);
-
-                       show_cursor(C);
-
-                       WM_event_add_notifier(C, NC_MOVIECLIP|NA_EDITED, NULL);
-
-                       return OPERATOR_CANCELLED;
-       }
-
-       return OPERATOR_PASS_THROUGH;
-}
-
-void CLIP_OT_slide_marker(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Slide Marker";
-       ot->description= "Slide marker areas";
-       ot->idname= "CLIP_OT_slide_marker";
-
-       /* api callbacks */
-       //ot->exec= slide_marker_exec;
-       ot->poll= space_clip_frame_poll;
-       ot->invoke= slide_marker_invoke;
-       ot->modal= slide_marker_modal;
-
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-
-       /* properties */
-       RNA_def_float_vector(ot->srna, "offset", 2, NULL, -FLT_MAX, FLT_MAX,
-               "Offset", "Offset in floating point units, 1.0 is the width and height of the image.", -FLT_MAX, FLT_MAX);
-}
 
-/********************** hide tracks opertaotr *********************/
+/********************** hide tracks operator *********************/
 
 static int hide_tracks_exec(bContext *C, wmOperator *op)
 {
@@ -2077,7 +2114,7 @@ void CLIP_OT_hide_tracks(wmOperatorType *ot)
        RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Hide unselected tracks");
 }
 
-/********************** hide tracks clear opertaotr *********************/
+/********************** hide tracks clear operator *********************/
 
 static int hide_tracks_clear_exec(bContext *C, wmOperator *UNUSED(op))
 {
@@ -2112,7 +2149,7 @@ void CLIP_OT_hide_tracks_clear(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
-/********************** detect features opertaotr *********************/
+/********************** detect features operator *********************/
 
 static int detect_features_exec(bContext *C, wmOperator *UNUSED(op))
 {
@@ -2155,7 +2192,7 @@ void CLIP_OT_detect_features(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
-/********************** frame jump opertaotr *********************/
+/********************** frame jump operator *********************/
 
 static int frame_jump_exec(bContext *C, wmOperator *op)
 {
@@ -2205,7 +2242,7 @@ void CLIP_OT_frame_jump(wmOperatorType *ot)
        RNA_def_boolean(ot->srna, "end", 0, "Last Frame", "Jump to the last frame of current track.");
 }
 
-/********************** join tracks opertaotr *********************/
+/********************** join tracks operator *********************/
 
 static int join_tracks_exec(bContext *C, wmOperator *op)
 {
index 3f13f04c09570381bcd874977203bf4ab9308d01..2dc9c0f9356143849309bcd027b642b07eb541ec 100644 (file)
@@ -1437,6 +1437,7 @@ static void draw_viewport_reconstruction(Scene *scene, Base *base, View3D *v3d,
        glMultMatrixf(mat);
 
        for ( track= tracking->tracks.first; track; track= track->next) {
+               int selected= track->flag&SELECT || track->pat_flag&SELECT || track->search_flag&SELECT;
                if((track->flag&TRACK_HAS_BUNDLE)==0)
                        continue;
 
@@ -1451,7 +1452,7 @@ static void draw_viewport_reconstruction(Scene *scene, Base *base, View3D *v3d,
                                glDisable(GL_LIGHTING);
                                glDepthMask(0);
 
-                               if(TRACK_SELECTED(track)) {
+                               if(selected) {
                                        if(base==BASACT) UI_ThemeColor(TH_ACTIVE);
                                        else UI_ThemeColor(TH_SELECT);
                                } else UI_ThemeColor(TH_WIRE);
@@ -1463,7 +1464,7 @@ static void draw_viewport_reconstruction(Scene *scene, Base *base, View3D *v3d,
                        } else if(v3d->drawtype>OB_WIRE) {
                                if(v3d->bundle_drawtype==OB_EMPTY_SPHERE) {
                                        /* selection outline */
-                                       if(TRACK_SELECTED(track)) {
+                                       if(selected) {
                                                if(base==BASACT) UI_ThemeColor(TH_ACTIVE);
                                                else UI_ThemeColor(TH_SELECT);
 
@@ -1486,7 +1487,7 @@ static void draw_viewport_reconstruction(Scene *scene, Base *base, View3D *v3d,
                                        glDisable(GL_LIGHTING);
                                        glDepthMask(0);
 
-                                       if(TRACK_SELECTED(track)) {
+                                       if(selected) {
                                                if(base==BASACT) UI_ThemeColor(TH_ACTIVE);
                                                else UI_ThemeColor(TH_SELECT);
                                        } else UI_ThemeColor(TH_WIRE);
@@ -1504,7 +1505,7 @@ static void draw_viewport_reconstruction(Scene *scene, Base *base, View3D *v3d,
                        float pos[3];
                        unsigned char tcol[4];
 
-                       if(TRACK_SELECTED(track)) memcpy(tcol, scol, sizeof(tcol));
+                       if(selected) memcpy(tcol, scol, sizeof(tcol));
                        else memcpy(tcol, col, sizeof(tcol));
 
                        mul_v3_m4v3(pos, mat, track->bundle_pos);
index 4d861327011b5d9ca055aa7f4ad6d2a3d6e728e1..c9920d1edd2fffc87d4c522c1bfaa94901bf36f2 100644 (file)
@@ -585,7 +585,8 @@ typedef struct SpaceClip {
        /* ** some runtime vars which aren't really in file ** */
        /* marker data displayed in panel */
        float marker_pos[2];                                            /* position of marker in pixel coords */
-       float track_pat_pos[2], track_pat[2];           /* position and dimensions of marker pattern in pixel coords */
+       float track_pat[2];                                                     /* position and dimensions of marker pattern in pixel coords */
+       float track_offset[2];                                          /* offset of "parenting" point */
        float track_search_pos[2], track_search[2];     /* position and dimensions of marker search in pixel coords */
        int marker_flag;                                                        /* marker's flags */
 } SpaceClip;
index 11fe9ceedcc2781446782fc89deeb823a8a4289e..da479db257dfcf84effafbdca1826b2caa4d1cd3 100644 (file)
@@ -81,6 +81,7 @@ typedef struct MovieTrackingTrack {
        /* ** setings ** */
        float pat_min[2], pat_max[2];           /* positions of left-bottom and right-top corners of pattern (in unified 0..1 space) */
        float search_min[2], search_max[2];     /* positions of left-bottom and right-top corners of search area (in unified 0..1 space) */
+       float offset[2];                                        /* offset to "parenting" point */
 
        int pad;