Planar tracking support for motion tracking
[blender.git] / source / blender / editors / space_clip / clip_buttons.c
index eabd64bdc4f29573633fdb8508a7bf22c086f5f0..ca2ae6e8461f30885f50403fa2d28abf634094bd 100644 (file)
 
 /* Panels */
 
+static int clip_grease_pencil_panel_poll(const bContext *C, PanelType *UNUSED(pt))
+{
+       SpaceClip *sc = CTX_wm_space_clip(C);
+
+       return sc->view == SC_VIEW_CLIP;
+}
+
 void ED_clip_buttons_register(ARegionType *art)
 {
        PanelType *pt;
@@ -72,6 +79,7 @@ void ED_clip_buttons_register(ARegionType *art)
        strcpy(pt->label, "Grease Pencil");
        pt->draw = gpencil_panel_standard;
        pt->flag |= PNL_DEFAULT_CLOSED;
+       pt->poll = clip_grease_pencil_panel_poll;
        BLI_addtail(&art->paneltypes, pt);
 }
 
@@ -157,9 +165,10 @@ void uiTemplateTrack(uiLayout *layout, PointerRNA *ptr, const char *propname)
 
        block = uiLayoutAbsoluteBlock(layout);
 
-       scopes->track_preview_height = (scopes->track_preview_height<=UI_UNIT_Y)?UI_UNIT_Y:scopes->track_preview_height;
+       scopes->track_preview_height = (scopes->track_preview_height <= UI_UNIT_Y)?UI_UNIT_Y : scopes->track_preview_height;
 
-       uiDefBut(block, TRACKPREVIEW, 0, "", rect.xmin, rect.ymin, rect.xmax-rect.xmin, scopes->track_preview_height, scopes, 0, 0, 0, 0, "");
+       uiDefBut(block, TRACKPREVIEW, 0, "", rect.xmin, rect.ymin, rect.xmax - rect.xmin,
+                scopes->track_preview_height, scopes, 0, 0, 0, 0, "");
 }
 
 /********************* Marker Template ************************/
@@ -177,12 +186,13 @@ typedef struct {
        MovieClip *clip;
        MovieClipUser *user;                                            /* user of clip */
        MovieTrackingTrack *track;
+       MovieTrackingMarker *marker;
 
        int framenr;                                                            /* current frame number */
        float marker_pos[2];                                            /* position of marker in pixel coords */
-       float track_pat[2];                                                     /* position and dimensions of marker pattern in pixel coords */
+       float marker_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 */
+       float marker_search_pos[2], marker_search[2];   /* position and dimensions of marker search in pixel coords */
        int marker_flag;                                                        /* marker's flags */
 } MarkerUpdateCb;
 
@@ -205,7 +215,7 @@ static void marker_update_cb(bContext *C, void *arg_cb, void *UNUSED(arg))
 
        marker->flag = cb->marker_flag;
 
-       WM_event_add_notifier(C, NC_MOVIECLIP|NA_EDITED, NULL);
+       WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, NULL);
 }
 
 static void marker_block_handler(bContext *C, void *arg_cb, int event)
@@ -219,70 +229,73 @@ static void marker_block_handler(bContext *C, void *arg_cb, int event)
        marker = BKE_tracking_ensure_marker(cb->track, cb->framenr);
 
        if (event == B_MARKER_POS) {
-               marker->pos[0] = cb->marker_pos[0]/width;
-               marker->pos[1] = cb->marker_pos[1]/height;
+               marker->pos[0] = cb->marker_pos[0] / width;
+               marker->pos[1] = cb->marker_pos[1] / height;
 
                /* to update position of "parented" objects */
                DAG_id_tag_update(&cb->clip->id, 0);
-               WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, NULL);
+               WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, NULL);
 
                ok = TRUE;
        }
        else if (event == B_MARKER_PAT_DIM) {
-               float dim[2], pat_dim[2];
+               float dim[2], pat_dim[2], pat_min[2], pat_max[2];
+               float scale_x, scale_y;
+               int a;
 
-               sub_v2_v2v2(pat_dim, cb->track->pat_max, cb->track->pat_min);
+               BKE_tracking_marker_pattern_minmax(cb->marker, pat_min, pat_max);
 
-               dim[0] = cb->track_pat[0] / width;
-               dim[1] = cb->track_pat[1] / height;
+               sub_v2_v2v2(pat_dim, pat_max, pat_min);
 
-               sub_v2_v2(dim, pat_dim);
-               mul_v2_fl(dim, 0.5f);
+               dim[0] = cb->marker_pat[0] / width;
+               dim[1] = cb->marker_pat[1] / height;
 
-               cb->track->pat_min[0] -= dim[0];
-               cb->track->pat_min[1] -= dim[1];
+               scale_x = dim[0] / pat_dim[0];
+               scale_y = dim[1] / pat_dim[1];
 
-               cb->track->pat_max[0] += dim[0];
-               cb->track->pat_max[1] += dim[1];
+               for (a = 0; a < 4; a++) {
+                       cb->marker->pattern_corners[a][0] *= scale_x;
+                       cb->marker->pattern_corners[a][1] *= scale_y;
+               }
 
-               BKE_tracking_clamp_track(cb->track, CLAMP_PAT_DIM);
+               BKE_tracking_clamp_marker(cb->marker, CLAMP_PAT_DIM);
 
                ok = TRUE;
        }
        else if (event == B_MARKER_SEARCH_POS) {
                float delta[2], side[2];
 
-               sub_v2_v2v2(side, cb->track->search_max, cb->track->search_min);
+               sub_v2_v2v2(side, cb->marker->search_max, cb->marker->search_min);
                mul_v2_fl(side, 0.5f);
 
-               delta[0] = cb->track_search_pos[0] / width;
-               delta[1] = cb->track_search_pos[1] / height;
+               delta[0] = cb->marker_search_pos[0] / width;
+               delta[1] = cb->marker_search_pos[1] / height;
 
-               sub_v2_v2v2(cb->track->search_min, delta, side);
-               add_v2_v2v2(cb->track->search_max, delta, side);
+               sub_v2_v2v2(cb->marker->search_min, delta, side);
+               add_v2_v2v2(cb->marker->search_max, delta, side);
 
-               BKE_tracking_clamp_track(cb->track, CLAMP_SEARCH_POS);
+               BKE_tracking_clamp_marker(cb->marker, CLAMP_SEARCH_POS);
 
                ok = TRUE;
        }
        else if (event == B_MARKER_SEARCH_DIM) {
                float dim[2], search_dim[2];
 
-               sub_v2_v2v2(search_dim, cb->track->search_max, cb->track->search_min);
+               sub_v2_v2v2(search_dim, cb->marker->search_max, cb->marker->search_min);
 
-               dim[0] = cb->track_search[0]/width;
-               dim[1] = cb->track_search[1]/height;
+               dim[0] = cb->marker_search[0] / width;
+               dim[1] = cb->marker_search[1] / height;
 
                sub_v2_v2(dim, search_dim);
                mul_v2_fl(dim, 0.5f);
 
-               cb->track->search_min[0]-= dim[0];
-               cb->track->search_min[1]-= dim[1];
+               cb->marker->search_min[0] -= dim[0];
+               cb->marker->search_min[1] -= dim[1];
 
-               cb->track->search_max[0]+= dim[0];
-               cb->track->search_max[1]+= dim[1];
+               cb->marker->search_max[0] += dim[0];
+               cb->marker->search_max[1] += dim[1];
 
-               BKE_tracking_clamp_track(cb->track, CLAMP_SEARCH_DIM);
+               BKE_tracking_clamp_marker(cb->marker, CLAMP_SEARCH_DIM);
 
                ok = TRUE;
        }
@@ -306,16 +319,17 @@ static void marker_block_handler(bContext *C, void *arg_cb, int event)
 
                /* to update position of "parented" objects */
                DAG_id_tag_update(&cb->clip->id, 0);
-               WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, NULL);
+               WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, NULL);
 
                ok = TRUE;
        }
 
        if (ok)
-               WM_event_add_notifier(C, NC_MOVIECLIP|NA_EDITED, cb->clip);
+               WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, cb->clip);
 }
 
-void uiTemplateMarker(uiLayout *layout, PointerRNA *ptr, const char *propname, PointerRNA *userptr, PointerRNA *trackptr, int compact)
+void uiTemplateMarker(uiLayout *layout, PointerRNA *ptr, const char *propname, PointerRNA *userptr,
+                      PointerRNA *trackptr, int compact)
 {
        PropertyRNA *prop;
        uiBlock *block;
@@ -327,6 +341,7 @@ void uiTemplateMarker(uiLayout *layout, PointerRNA *ptr, const char *propname, P
        MovieTrackingMarker *marker;
        MarkerUpdateCb *cb;
        const char *tip;
+       float pat_min[2], pat_max[2];
 
        if (!ptr->data)
                return;
@@ -356,6 +371,7 @@ void uiTemplateMarker(uiLayout *layout, PointerRNA *ptr, const char *propname, P
        cb->clip = clip;
        cb->user = user;
        cb->track = track;
+       cb->marker = marker;
        cb->marker_flag = marker->flag;
        cb->framenr = user->framenr;
 
@@ -363,16 +379,17 @@ void uiTemplateMarker(uiLayout *layout, PointerRNA *ptr, const char *propname, P
                block = uiLayoutGetBlock(layout);
 
                if (cb->marker_flag & MARKER_DISABLED)
-                       tip= "Marker is disabled at current frame";
+                       tip = "Marker is disabled at current frame";
                else
-                       tip= "Marker is enabled at current frame";
+                       tip = "Marker is enabled at current frame";
 
-               bt = uiDefIconButBitI(block, TOGN, MARKER_DISABLED, 0, ICON_RESTRICT_VIEW_OFF, 0, 0, 20, 20, &cb->marker_flag, 0, 0, 1, 0, tip);
+               bt = uiDefIconButBitI(block, TOGN, MARKER_DISABLED, 0, ICON_RESTRICT_VIEW_OFF, 0, 0, 20, 20,
+                                     &cb->marker_flag, 0, 0, 1, 0, tip);
                uiButSetNFunc(bt, marker_update_cb, cb, NULL);
        }
        else {
                int width, height, step, digits;
-               float pat_dim[2], pat_pos[2], search_dim[2], search_pos[2];
+               float pat_dim[2], search_dim[2], search_pos[2];
                uiLayout *col;
 
                BKE_movieclip_get_size(clip, user, &width, &height);
@@ -385,40 +402,39 @@ void uiTemplateMarker(uiLayout *layout, PointerRNA *ptr, const char *propname, P
                        return;
                }
 
-               step= 100;
+               step = 100;
                digits = 2;
 
-               sub_v2_v2v2(pat_dim, track->pat_max, track->pat_min);
-               sub_v2_v2v2(search_dim, track->search_max, track->search_min);
+               BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max);
 
-               add_v2_v2v2(search_pos, track->search_max, track->search_min);
-               mul_v2_fl(search_pos, 0.5);
+               sub_v2_v2v2(pat_dim, pat_max, pat_min);
+               sub_v2_v2v2(search_dim, marker->search_max, marker->search_min);
 
-               add_v2_v2v2(pat_pos, track->pat_max, track->pat_min);
-               mul_v2_fl(pat_pos, 0.5);
+               add_v2_v2v2(search_pos, marker->search_max, marker->search_min);
+               mul_v2_fl(search_pos, 0.5);
 
                to_pixel_space(cb->marker_pos, marker->pos, width, height);
-               to_pixel_space(cb->track_pat, pat_dim, width, height);
-               to_pixel_space(cb->track_search, search_dim, width, height);
-               to_pixel_space(cb->track_search_pos, search_pos, width, height);
+               to_pixel_space(cb->marker_pat, pat_dim, width, height);
+               to_pixel_space(cb->marker_search, search_dim, width, height);
+               to_pixel_space(cb->marker_search_pos, search_pos, width, height);
                to_pixel_space(cb->track_offset, track->offset, width, height);
 
                cb->marker_flag = marker->flag;
 
-               block= uiLayoutAbsoluteBlock(layout);
+               block = uiLayoutAbsoluteBlock(layout);
                uiBlockSetHandleFunc(block, marker_block_handler, cb);
                uiBlockSetNFunc(block, marker_update_cb, cb, NULL);
 
                if (cb->marker_flag & MARKER_DISABLED)
-                       tip= "Marker is disabled at current frame";
+                       tip = "Marker is disabled at current frame";
                else
-                       tip= "Marker is enabled at current frame";
+                       tip = "Marker is enabled at current frame";
 
                uiDefButBitI(block, OPTIONN, MARKER_DISABLED, B_MARKER_FLAG,  "Enabled", 10, 190, 145, 19, &cb->marker_flag,
                        0, 0, 0, 0, tip);
 
                col = uiLayoutColumn(layout, 1);
-               uiLayoutSetActive(col, (cb->marker_flag&MARKER_DISABLED)==0);
+               uiLayoutSetActive(col, (cb->marker_flag & MARKER_DISABLED) == 0);
 
                block = uiLayoutAbsoluteBlock(col);
                uiBlockBeginAlign(block);
@@ -436,19 +452,19 @@ void uiTemplateMarker(uiLayout *layout, PointerRNA *ptr, const char *propname, P
                        -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, &cb->track_pat[0], 3.0f,
+               uiDefButF(block, NUM, B_MARKER_PAT_DIM, "Width:", 10, 95, 300, 19, &cb->marker_pat[0], 3.0f,
                        10.0*width, step, digits, "Width of marker's pattern in screen coordinates");
-               uiDefButF(block, NUM, B_MARKER_PAT_DIM, "Height:", 10, 76, 300, 19, &cb->track_pat[1], 3.0f,
+               uiDefButF(block, NUM, B_MARKER_PAT_DIM, "Height:", 10, 76, 300, 19, &cb->marker_pat[1], 3.0f,
                        10.0*height, step, digits, "Height of marker's pattern in screen coordinates");
 
                uiDefBut(block, LABEL, 0, "Search Area:", 0, 57, 300, 19, NULL, 0, 0, 0, 0, "");
-               uiDefButF(block, NUM, B_MARKER_SEARCH_POS, "X:", 10, 38, 145, 19, &cb->track_search_pos[0],
+               uiDefButF(block, NUM, B_MARKER_SEARCH_POS, "X:", 10, 38, 145, 19, &cb->marker_search_pos[0],
                        -width, width, step, digits, "X-position of search at frame relative to marker's position");
-               uiDefButF(block, NUM, B_MARKER_SEARCH_POS, "Y:", 165, 38, 145, 19, &cb->track_search_pos[1],
+               uiDefButF(block, NUM, B_MARKER_SEARCH_POS, "Y:", 165, 38, 145, 19, &cb->marker_search_pos[1],
                        -height, height, step, digits, "X-position of search at frame relative to marker's position");
-               uiDefButF(block, NUM, B_MARKER_SEARCH_DIM, "Width:", 10, 19, 300, 19, &cb->track_search[0], 3.0f,
+               uiDefButF(block, NUM, B_MARKER_SEARCH_DIM, "Width:", 10, 19, 300, 19, &cb->marker_search[0], 3.0f,
                        10.0*width, step, digits, "Width of marker's search in screen soordinates");
-               uiDefButF(block, NUM, B_MARKER_SEARCH_DIM, "Height:", 10, 0, 300, 19, &cb->track_search[1], 3.0f,
+               uiDefButF(block, NUM, B_MARKER_SEARCH_DIM, "Height:", 10, 0, 300, 19, &cb->marker_search[1], 3.0f,
                        10.0*height, step, digits, "Height of marker's search in screen soordinates");
 
                uiBlockEndAlign(block);