Camera tracking integration
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 17 Oct 2011 15:57:20 +0000 (15:57 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 17 Oct 2011 15:57:20 +0000 (15:57 +0000)
===========================

Allow offset from locked position.

source/blender/editors/space_clip/clip_ops.c
source/blender/editors/space_clip/space_clip.c
source/blender/makesdna/DNA_space_types.h
source/blender/makesrna/intern/rna_space.c

index d7209a5612bcf4c9ea6652d245fad7d39ee77db0..8842608994668d0a7e78931d517324a8346c1447 100644 (file)
@@ -300,8 +300,9 @@ void CLIP_OT_unlink(wmOperatorType *ot)
 
 typedef struct ViewPanData {
        float x, y;
-       float xof, yof;
+       float xof, yof, xorig, yorig;
        int event_type;
+       float *vec;
 } ViewPanData;
 
 static void view_pan_init(bContext *C, wmOperator *op, wmEvent *event)
@@ -314,8 +315,13 @@ static void view_pan_init(bContext *C, wmOperator *op, wmEvent *event)
 
        vpd->x= event->x;
        vpd->y= event->y;
-       vpd->xof= sc->xof;
-       vpd->yof= sc->yof;
+
+       if(sc->flag&SC_LOCK_SELECTION) vpd->vec= &sc->xlockof;
+       else vpd->vec= &sc->xof;
+
+       copy_v2_v2(&vpd->xof, vpd->vec);
+       copy_v2_v2(&vpd->xorig, &vpd->xof);
+
        vpd->event_type= event->type;
 
        WM_event_add_modal_handler(C, op);
@@ -327,8 +333,8 @@ static void view_pan_exit(bContext *C, wmOperator *op, int cancel)
        ViewPanData *vpd= op->customdata;
 
        if(cancel) {
-               sc->xof= vpd->xof;
-               sc->yof= vpd->yof;
+               copy_v2_v2(vpd->vec, &vpd->xorig);
+
                ED_region_tag_redraw(CTX_wm_region(C));
        }
 
@@ -342,8 +348,14 @@ static int view_pan_exec(bContext *C, wmOperator *op)
        float offset[2];
 
        RNA_float_get_array(op->ptr, "offset", offset);
-       sc->xof += offset[0];
-       sc->yof += offset[1];
+
+       if(sc->flag&SC_LOCK_SELECTION) {
+               sc->xlockof+= offset[0];
+               sc->ylockof+= offset[1];
+       } else {
+               sc->xof+= offset[0];
+               sc->yof+= offset[1];
+       }
 
        ED_region_tag_redraw(CTX_wm_region(C));
 
@@ -358,6 +370,7 @@ static int view_pan_invoke(bContext *C, wmOperator *op, wmEvent *event)
 
                offset[0]= (event->x - event->prevx)/sc->zoom;
                offset[1]= (event->y - event->prevy)/sc->zoom;
+
                RNA_float_set_array(op->ptr, "offset", offset);
 
                view_pan_exec(C, op);
@@ -377,8 +390,7 @@ static int view_pan_modal(bContext *C, wmOperator *op, wmEvent *event)
 
        switch(event->type) {
                case MOUSEMOVE:
-                       sc->xof= vpd->xof;
-                       sc->yof= vpd->yof;
+                       copy_v2_v2(vpd->vec, &vpd->xorig);
                        offset[0]= (vpd->x - event->x)/sc->zoom;
                        offset[1]= (vpd->y - event->y)/sc->zoom;
                        RNA_float_set_array(op->ptr, "offset", offset);
@@ -727,6 +739,9 @@ static int view_selected_exec(bContext *C, wmOperator *UNUSED(op))
        SpaceClip *sc= CTX_wm_space_clip(C);
        ARegion *ar= CTX_wm_region(C);
 
+       sc->xlockof= 0.f;
+       sc->ylockof= 0.f;
+
        ED_clip_view_selection(sc, ar, 1);
        ED_region_tag_redraw(CTX_wm_region(C));
 
index 4a17d5a7dc05699a235b6ef218012e533c57e4d7..b4d851cb72d5f235dc01691409bcc1c15d21f80c 100644 (file)
@@ -564,6 +564,9 @@ static void clip_main_area_draw(const bContext *C, ARegion *ar)
 
                ED_clip_view_selection(sc, ar, 0);
 
+               sc->xof+= sc->xlockof;
+               sc->yof+= sc->ylockof;
+
                if(tmpibuf)
                        IMB_freeImBuf(tmpibuf);
        }
index d5e0951c119473e54dfdc2e288848b6347e36d1b..585ebde2c9a40adb109104888bf1068299bcc027 100644 (file)
@@ -571,6 +571,7 @@ typedef struct SpaceClip {
        int spacetype;
 
        float xof, yof;                         /* user defined offset, image is centered */
+       float xlockof, ylockof;         /* user defined offset from locked position */
        float zoom;                                     /* user defined zoom level */
 
        struct MovieClipUser user;              /* user of clip */
index 247b1153a59e9b963239cadc577856651105a391..3cd201948768c5fdf5c62a5a1e042df0da124e78 100644 (file)
@@ -956,6 +956,14 @@ static void rna_SpaceClipEditor_clip_mode_update(Main *UNUSED(bmain), Scene *UNU
        sc->scopes.ok= 0;
 }
 
+static void rna_SpaceClipEditor_lock_selection_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
+{
+       SpaceClip *sc= (SpaceClip*)(ptr->data);
+
+       sc->xlockof= 0.f;
+       sc->ylockof= 0.f;
+}
+
 #else
 
 static void rna_def_space(BlenderRNA *brna)
@@ -2786,7 +2794,7 @@ static void rna_def_space_clip(BlenderRNA *brna)
        prop= RNA_def_property(srna, "lock_selection", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_ui_text(prop, "Lock to Selection", "Lock viewport to selected markers during playback");
        RNA_def_property_boolean_sdna(prop, NULL, "flag", SC_LOCK_SELECTION);
-       RNA_def_property_update(prop, NC_SPACE|ND_SPACE_CLIP, NULL);
+       RNA_def_property_update(prop, NC_SPACE|ND_SPACE_CLIP, "rna_SpaceClipEditor_lock_selection_update");
 
        /* show markers pathes */
        prop= RNA_def_property(srna, "show_track_path", PROP_BOOLEAN, PROP_NONE);