Planar tracking support for motion tracking
[blender.git] / source / blender / editors / space_clip / clip_buttons.c
index f10529c304f504ee5fd53ca463af497759b4b1f1..ca2ae6e8461f30885f50403fa2d28abf634094bd 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id$
- *
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
@@ -51,6 +49,7 @@
 #include "BKE_tracking.h"
 
 #include "ED_clip.h"
+#include "ED_gpencil.h"
 
 #include "UI_interface.h"
 #include "UI_resources.h"
 
 #include "clip_intern.h"       // own include
 
-#define B_MARKER_POS                   3
-#define B_MARKER_OFFSET                        4
-#define B_MARKER_PAT_DIM               5
-#define B_MARKER_SEARCH_POS            6
-#define B_MARKER_SEARCH_DIM            7
-#define B_MARKER_FLAG                  8
+/* Panels */
 
-static void to_pixel_space(float r[2], float a[2], int width, int height)
+static int clip_grease_pencil_panel_poll(const bContext *C, PanelType *UNUSED(pt))
 {
-       copy_v2_v2(r, a);
-       r[0]*= width;
-       r[1]*= height;
+       SpaceClip *sc = CTX_wm_space_clip(C);
+
+       return sc->view == SC_VIEW_CLIP;
 }
 
-static void trackingMarker_buttons(const bContext *C, uiLayout *layout)
+void ED_clip_buttons_register(ARegionType *art)
 {
-       SpaceClip *sc= CTX_wm_space_clip(C);
-       MovieClip *clip= ED_space_clip(sc);
-       int width, height, step, digits, type;
-       MovieTrackingTrack *track;
-       MovieTrackingMarker *marker;
-       float pat_dim[2], pat_pos[2], search_dim[2], search_pos[2];
-       uiBlock *block;
-       uiLayout *col;
-
-       ED_space_clip_size(sc, &width, &height);
-       BKE_movieclip_last_selection(clip, &type, (void**)&track);
-
-       step= 100;
-       digits= 2;
-
-       marker= BKE_tracking_get_marker(track, sc->user.framenr);
-
-       sub_v2_v2v2(pat_dim, track->pat_max, track->pat_min);
-       sub_v2_v2v2(search_dim, track->search_max, track->search_min);
-
-       add_v2_v2v2(search_pos, track->search_max, track->search_min);
-       mul_v2_fl(search_pos, 0.5);
+       PanelType *pt;
 
-       add_v2_v2v2(pat_pos, track->pat_max, track->pat_min);
-       mul_v2_fl(pat_pos, 0.5);
+       pt = MEM_callocN(sizeof(PanelType), "spacetype clip panel gpencil");
+       strcpy(pt->idname, "CLIP_PT_gpencil");
+       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);
+}
 
-       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_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);
+/********************* MovieClip Template ************************/
 
-       sc->marker_flag= marker->flag;
+void uiTemplateMovieClip(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, int compact)
+{
+       PropertyRNA *prop;
+       PointerRNA clipptr;
+       MovieClip *clip;
+       uiLayout *row, *split;
+       uiBlock *block;
 
-       block= uiLayoutAbsoluteBlock(layout);
+       if (!ptr->data)
+               return;
 
-       uiDefButBitI(block, OPTION, MARKER_DISABLED, B_MARKER_FLAG,  "Disabled", 10, 190, 145, 19, &sc->marker_flag,
-               0, 0, 0, 0, "Marker is disabled for current frame.");
+       prop = RNA_struct_find_property(ptr, propname);
+       if (!prop) {
+               printf("%s: property not found: %s.%s\n",
+                      __func__, RNA_struct_identifier(ptr->type), propname);
+               return;
+       }
 
-       col= uiLayoutColumn(layout, 1);
-       uiLayoutSetActive(col, (sc->marker_flag&MARKER_DISABLED)==0);
+       if (RNA_property_type(prop) != PROP_POINTER) {
+               printf("%s: expected pointer property for %s.%s\n",
+                      __func__, RNA_struct_identifier(ptr->type), propname);
+               return;
+       }
 
-       block= uiLayoutAbsoluteBlock(col);
-       uiBlockBeginAlign(block);
+       clipptr = RNA_property_pointer_get(ptr, prop);
+       clip = clipptr.data;
 
-       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, 171, 145, 19, &sc->marker_pos[1],
-               -10*height, 10.0*height, step, digits, "Y-position of marker at frame in screen coordinates.");
+       uiLayoutSetContextPointer(layout, "edit_movieclip", &clipptr);
 
-       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.");
+       if (!compact)
+               uiTemplateID(layout, C, ptr, propname, NULL, "CLIP_OT_open", NULL);
 
-       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,
-               10.0*height, step, digits, "Height of marker's pattern in screen soordinates.");
+       if (clip) {
+               row = uiLayoutRow(layout, 0);
+               block = uiLayoutGetBlock(row);
+               uiDefBut(block, LABEL, 0, "File Path:", 0, 19, 145, 19, NULL, 0, 0, 0, 0, "");
 
-       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, &sc->track_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, &sc->track_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, &sc->track_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, &sc->track_search[1], 3.0f,
-               10.0*height, step, digits, "Height of marker's search in screen soordinates.");
+               row = uiLayoutRow(layout, 0);
+               split = uiLayoutSplit(row, 0.0, 0);
+               row = uiLayoutRow(split, 1);
 
-       uiBlockEndAlign(block);
+               uiItemR(row, &clipptr, "filepath", 0, "", ICON_NONE);
+               uiItemO(row, "", ICON_FILE_REFRESH, "clip.reload");
+       }
 }
 
-static void do_tracking_marker(bContext *C, void *UNUSED(arg), int event)
-{
-       SpaceClip *sc= CTX_wm_space_clip(C);
-       MovieClip *clip= ED_space_clip(sc);
-       MovieTrackingTrack *track;
-       MovieTrackingMarker *marker;
-       int width, height, type, ok= 0;
-
-       ED_space_clip_size(sc, &width, &height);
+/********************* Track Template ************************/
 
-       BKE_movieclip_last_selection(clip, &type, (void**)&track);
-
-       marker= BKE_tracking_ensure_marker(track, sc->user.framenr);
+void uiTemplateTrack(uiLayout *layout, PointerRNA *ptr, const char *propname)
+{
+       PropertyRNA *prop;
+       PointerRNA scopesptr;
+       uiBlock *block;
+       rctf rect;
+       MovieClipScopes *scopes;
 
-       if(event==B_MARKER_POS) {
-               marker->pos[0]= sc->marker_pos[0]/width;
-               marker->pos[1]= sc->marker_pos[1]/height;
+       if (!ptr->data)
+               return;
 
-               /* to update position of "parented" objects */
-               DAG_id_tag_update(&clip->id, 0);
-               WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, NULL);
+       prop = RNA_struct_find_property(ptr, propname);
+       if (!prop) {
+               printf("%s: property not found: %s.%s\n",
+                      __func__, RNA_struct_identifier(ptr->type), propname);
+               return;
+       }
 
-               ok= 1;
+       if (RNA_property_type(prop) != PROP_POINTER) {
+               printf("%s: expected pointer property for %s.%s\n",
+                      __func__, RNA_struct_identifier(ptr->type), propname);
+               return;
        }
-       else if(event==B_MARKER_PAT_DIM) {
-               float dim[2], pat_dim[2];
 
-               sub_v2_v2v2(pat_dim, track->pat_max, track->pat_min);
+       scopesptr = RNA_property_pointer_get(ptr, prop);
+       scopes = (MovieClipScopes *)scopesptr.data;
 
-               dim[0]= sc->track_pat[0]/width;
-               dim[1]= sc->track_pat[1]/height;
+       rect.xmin = 0; rect.xmax = 200;
+       rect.ymin = 0; rect.ymax = 120;
 
-               sub_v2_v2(dim, pat_dim);
-               mul_v2_fl(dim, 0.5f);
+       block = uiLayoutAbsoluteBlock(layout);
 
-               track->pat_min[0]-= dim[0];
-               track->pat_min[1]-= dim[1];
+       scopes->track_preview_height = (scopes->track_preview_height <= UI_UNIT_Y)?UI_UNIT_Y : scopes->track_preview_height;
 
-               track->pat_max[0]+= dim[0];
-               track->pat_max[1]+= dim[1];
+       uiDefBut(block, TRACKPREVIEW, 0, "", rect.xmin, rect.ymin, rect.xmax - rect.xmin,
+                scopes->track_preview_height, scopes, 0, 0, 0, 0, "");
+}
 
-               BKE_tracking_clamp_track(track, CLAMP_PAT_DIM);
+/********************* Marker Template ************************/
 
-               ok= 1;
-       }
-       else if(event==B_MARKER_SEARCH_POS) {
-               float delta[2], side[2];
+#define B_MARKER_POS                   3
+#define B_MARKER_OFFSET                        4
+#define B_MARKER_PAT_DIM               5
+#define B_MARKER_SEARCH_POS            6
+#define B_MARKER_SEARCH_DIM            7
+#define B_MARKER_FLAG                  8
 
-               sub_v2_v2v2(side, track->search_max, track->search_min);
-               mul_v2_fl(side, 0.5f);
+typedef struct {
+       int compact;                                                            /* compact mode */
 
-               delta[0]= sc->track_search_pos[0]/width;
-               delta[1]= sc->track_search_pos[1]/height;
+       MovieClip *clip;
+       MovieClipUser *user;                                            /* user of clip */
+       MovieTrackingTrack *track;
+       MovieTrackingMarker *marker;
 
-               sub_v2_v2v2(track->search_min, delta, side);
-               add_v2_v2v2(track->search_max, delta, side);
+       int framenr;                                                            /* current frame number */
+       float marker_pos[2];                                            /* position of marker 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 marker_search_pos[2], marker_search[2];   /* position and dimensions of marker search in pixel coords */
+       int marker_flag;                                                        /* marker's flags */
+} MarkerUpdateCb;
 
-               BKE_tracking_clamp_track(track, CLAMP_SEARCH_POS);
+static void to_pixel_space(float r[2], float a[2], int width, int height)
+{
+       copy_v2_v2(r, a);
+       r[0] *= width;
+       r[1] *= height;
+}
 
-               ok= 1;
-       }
-       else if(event==B_MARKER_SEARCH_DIM) {
-               float dim[2], search_dim[2];
+static void marker_update_cb(bContext *C, void *arg_cb, void *UNUSED(arg))
+{
+       MarkerUpdateCb *cb = (MarkerUpdateCb*) arg_cb;
+       MovieTrackingMarker *marker;
 
-               sub_v2_v2v2(search_dim, track->search_max, track->search_min);
+       if (!cb->compact)
+               return;
 
-               dim[0]= sc->track_search[0]/width;
-               dim[1]= sc->track_search[1]/height;
+       marker = BKE_tracking_ensure_marker(cb->track, cb->framenr);
 
-               sub_v2_v2(dim, search_dim);
-               mul_v2_fl(dim, 0.5f);
+       marker->flag = cb->marker_flag;
 
-               track->search_min[0]-= dim[0];
-               track->search_min[1]-= dim[1];
+       WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, NULL);
+}
 
-               track->search_max[0]+= dim[0];
-               track->search_max[1]+= dim[1];
+static void marker_block_handler(bContext *C, void *arg_cb, int event)
+{
+       MarkerUpdateCb *cb = (MarkerUpdateCb*) arg_cb;
+       MovieTrackingMarker *marker;
+       int width, height, ok = FALSE;
 
-               BKE_tracking_clamp_track(track, CLAMP_SEARCH_DIM);
+       BKE_movieclip_get_size(cb->clip, cb->user, &width, &height);
 
-               ok= 1;
-       } else if(event==B_MARKER_FLAG) {
-               marker->flag= sc->marker_flag;
+       marker = BKE_tracking_ensure_marker(cb->track, cb->framenr);
 
-               ok= 1;
-       } else if(event==B_MARKER_OFFSET) {
-               track->offset[0]= sc->track_offset[0]/width;
-               track->offset[1]= sc->track_offset[1]/height;
+       if (event == B_MARKER_POS) {
+               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(&clip->id, 0);
-               WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, NULL);
+               DAG_id_tag_update(&cb->clip->id, 0);
+               WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, NULL);
 
-               ok= 1;
+               ok = TRUE;
        }
+       else if (event == B_MARKER_PAT_DIM) {
+               float dim[2], pat_dim[2], pat_min[2], pat_max[2];
+               float scale_x, scale_y;
+               int a;
 
-       if(ok)
-               WM_event_add_notifier(C, NC_MOVIECLIP|NA_EDITED, clip);
-}
-
-/* Panels */
+               BKE_tracking_marker_pattern_minmax(cb->marker, pat_min, pat_max);
 
-static int clip_panel_marker_poll(const bContext *C, PanelType *UNUSED(pt))
-{
-       SpaceClip *sc= CTX_wm_space_clip(C);
-       MovieClip *clip;
-       int type;
-       MovieTrackingTrack *track;
+               sub_v2_v2v2(pat_dim, pat_max, pat_min);
 
-       if(!sc)
-               return 0;
+               dim[0] = cb->marker_pat[0] / width;
+               dim[1] = cb->marker_pat[1] / height;
 
-       clip= ED_space_clip(sc);
+               scale_x = dim[0] / pat_dim[0];
+               scale_y = dim[1] / pat_dim[1];
 
-       if(!clip || !BKE_movieclip_has_frame(clip, &sc->user))
-               return 0;
+               for (a = 0; a < 4; a++) {
+                       cb->marker->pattern_corners[a][0] *= scale_x;
+                       cb->marker->pattern_corners[a][1] *= scale_y;
+               }
 
-       BKE_movieclip_last_selection(clip, &type, (void**)&track);
+               BKE_tracking_clamp_marker(cb->marker, CLAMP_PAT_DIM);
 
-       if(type!=MCLIP_SEL_TRACK)
-               return 0;
+               ok = TRUE;
+       }
+       else if (event == B_MARKER_SEARCH_POS) {
+               float delta[2], side[2];
 
-       if(track->flag&TRACK_LOCKED)
-               return 0;
+               sub_v2_v2v2(side, cb->marker->search_max, cb->marker->search_min);
+               mul_v2_fl(side, 0.5f);
 
-       return 1;
-}
+               delta[0] = cb->marker_search_pos[0] / width;
+               delta[1] = cb->marker_search_pos[1] / height;
 
-static void clip_panel_marker(const bContext *C, Panel *pa)
-{
-       uiBlock *block;
+               sub_v2_v2v2(cb->marker->search_min, delta, side);
+               add_v2_v2v2(cb->marker->search_max, delta, side);
 
-       block= uiLayoutAbsoluteBlock(pa->layout);
-       uiBlockSetHandleFunc(block, do_tracking_marker, NULL);
+               BKE_tracking_clamp_marker(cb->marker, CLAMP_SEARCH_POS);
 
-       trackingMarker_buttons(C, pa->layout);
-}
+               ok = TRUE;
+       }
+       else if (event == B_MARKER_SEARCH_DIM) {
+               float dim[2], search_dim[2];
 
-void ED_clip_buttons_register(ARegionType *art)
-{
-       PanelType *pt;
+               sub_v2_v2v2(search_dim, cb->marker->search_max, cb->marker->search_min);
 
-       pt= MEM_callocN(sizeof(PanelType), "spacetype clip panel marker");
-       strcpy(pt->idname, "CLIP_PT_marker");
-       strcpy(pt->label, "Marker");
-       pt->draw= clip_panel_marker;
-       pt->poll= clip_panel_marker_poll;
+               dim[0] = cb->marker_search[0] / width;
+               dim[1] = cb->marker_search[1] / height;
 
-       BLI_addtail(&art->paneltypes, pt);
-}
+               sub_v2_v2(dim, search_dim);
+               mul_v2_fl(dim, 0.5f);
 
-/********************* MovieClip Template ************************/
+               cb->marker->search_min[0] -= dim[0];
+               cb->marker->search_min[1] -= dim[1];
 
-void uiTemplateMovieClip(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, PointerRNA *UNUSED(userptr), int compact)
-{
-       PropertyRNA *prop;
-       PointerRNA clipptr;
-       MovieClip *clip;
-       /* MovieClipUser *user; */ /* currently unused */
-       uiLayout *row, *split;
-       uiBlock *block;
+               cb->marker->search_max[0] += dim[0];
+               cb->marker->search_max[1] += dim[1];
 
-       if(!ptr->data)
-               return;
+               BKE_tracking_clamp_marker(cb->marker, CLAMP_SEARCH_DIM);
 
-       prop= RNA_struct_find_property(ptr, propname);
-       if(!prop) {
-               printf("uiTemplateMovieClip: property not found: %s.%s\n", RNA_struct_identifier(ptr->type), propname);
-               return;
+               ok = TRUE;
        }
+       else if (event == B_MARKER_FLAG) {
+               marker->flag = cb->marker_flag;
 
-       if(RNA_property_type(prop) != PROP_POINTER) {
-               printf("uiTemplateMovieClip: expected pointer property for %s.%s\n", RNA_struct_identifier(ptr->type), propname);
-               return;
+               ok = TRUE;
        }
+       else if (event == B_MARKER_OFFSET) {
+               float offset[2], delta[2];
+               int i;
 
-       clipptr= RNA_property_pointer_get(ptr, prop);
-       clip= clipptr.data;
-       /* user= userptr->data; */
+               offset[0] = cb->track_offset[0] / width;
+               offset[1] = cb->track_offset[1] / height;
 
-       uiLayoutSetContextPointer(layout, "edit_movieclip", &clipptr);
+               sub_v2_v2v2(delta, offset, cb->track->offset);
+               copy_v2_v2(cb->track->offset, offset);
 
-       if(!compact)
-               uiTemplateID(layout, C, ptr, propname, NULL, "CLIP_OT_open", NULL);
+               for (i = 0; i < cb->track->markersnr; i++)
+                       sub_v2_v2(cb->track->markers[i].pos, delta);
 
-       if(clip) {
-               row= uiLayoutRow(layout, 0);
-               block= uiLayoutGetBlock(row);
-               uiDefBut(block, LABEL, 0, "File Path:", 0, 19, 145, 19, NULL, 0, 0, 0, 0, "");
-
-               row= uiLayoutRow(layout, 0);
-               split = uiLayoutSplit(row, 0.0, 0);
-               row= uiLayoutRow(split, 1);
+               /* 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);
 
-               uiItemR(row, &clipptr, "filepath", 0, "", ICON_NONE);
-               uiItemO(row, "", ICON_FILE_REFRESH, "clip.reload");
+               ok = TRUE;
        }
-}
 
-/********************* Marker Template ************************/
+       if (ok)
+               WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, cb->clip);
+}
 
-void uiTemplateTrack(uiLayout *layout, PointerRNA *ptr, const char *propname)
+void uiTemplateMarker(uiLayout *layout, PointerRNA *ptr, const char *propname, PointerRNA *userptr,
+                      PointerRNA *trackptr, int compact)
 {
        PropertyRNA *prop;
-       PointerRNA scopesptr;
        uiBlock *block;
-       rctf rect;
-       MovieClipScopes *scopes;
+       uiBut *bt;
+       PointerRNA clipptr;
+       MovieClip *clip;
+       MovieClipUser *user;
+       MovieTrackingTrack *track;
+       MovieTrackingMarker *marker;
+       MarkerUpdateCb *cb;
+       const char *tip;
+       float pat_min[2], pat_max[2];
 
-       if(!ptr->data)
+       if (!ptr->data)
                return;
 
-       prop= RNA_struct_find_property(ptr, propname);
-       if(!prop) {
-               printf("uiTemplateTrack: property not found: %s.%s\n", RNA_struct_identifier(ptr->type), propname);
+       prop = RNA_struct_find_property(ptr, propname);
+       if (!prop) {
+               printf("%s: property not found: %s.%s\n",
+                      __func__, RNA_struct_identifier(ptr->type), propname);
                return;
        }
 
-       if(RNA_property_type(prop) != PROP_POINTER) {
-               printf("uiTemplateTrack: expected pointer property for %s.%s\n", RNA_struct_identifier(ptr->type), propname);
+       if (RNA_property_type(prop) != PROP_POINTER) {
+               printf("%s: expected pointer property for %s.%s\n",
+                      __func__, RNA_struct_identifier(ptr->type), propname);
                return;
        }
 
-       scopesptr= RNA_property_pointer_get(ptr, prop);
-       scopes= (MovieClipScopes *)scopesptr.data;
-
-       rect.xmin= 0; rect.xmax= 200;
-       rect.ymin= 0; rect.ymax= 120;
-
-       block= uiLayoutAbsoluteBlock(layout);
-
-       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, "");
+       clipptr = RNA_property_pointer_get(ptr, prop);
+       clip = (MovieClip *)clipptr.data;
+       user = userptr->data;
+       track = trackptr->data;
+
+       marker = BKE_tracking_get_marker(track, user->framenr);
+
+       cb = MEM_callocN(sizeof(MarkerUpdateCb), "uiTemplateMarker update_cb");
+       cb->compact = compact;
+       cb->clip = clip;
+       cb->user = user;
+       cb->track = track;
+       cb->marker = marker;
+       cb->marker_flag = marker->flag;
+       cb->framenr = user->framenr;
+
+       if (compact) {
+               block = uiLayoutGetBlock(layout);
+
+               if (cb->marker_flag & MARKER_DISABLED)
+                       tip = "Marker is disabled at current frame";
+               else
+                       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);
+               uiButSetNFunc(bt, marker_update_cb, cb, NULL);
+       }
+       else {
+               int width, height, step, digits;
+               float pat_dim[2], search_dim[2], search_pos[2];
+               uiLayout *col;
+
+               BKE_movieclip_get_size(clip, user, &width, &height);
+
+               if (track->flag & TRACK_LOCKED) {
+                       uiLayoutSetActive(layout, 0);
+                       block = uiLayoutAbsoluteBlock(layout);
+                       uiDefBut(block, LABEL, 0, "Track is locked", 0, 0, 300, 19, NULL, 0, 0, 0, 0, "");
+
+                       return;
+               }
+
+               step = 100;
+               digits = 2;
+
+               BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max);
+
+               sub_v2_v2v2(pat_dim, pat_max, pat_min);
+               sub_v2_v2v2(search_dim, marker->search_max, marker->search_min);
+
+               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->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);
+               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";
+               else
+                       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);
+
+               block = uiLayoutAbsoluteBlock(col);
+               uiBlockBeginAlign(block);
+
+               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, &cb->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, 171, 145, 19, &cb->marker_pos[1],
+                       -10*height, 10.0*height, step, digits, "Y-position of marker at frame in screen coordinates");
+
+               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, &cb->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, &cb->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, &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->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->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->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->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->marker_search[1], 3.0f,
+                       10.0*height, step, digits, "Height of marker's search in screen soordinates");
+
+               uiBlockEndAlign(block);
+       }
 }