2.5
authorJoshua Leung <aligorith@gmail.com>
Sun, 28 Dec 2008 04:13:18 +0000 (04:13 +0000)
committerJoshua Leung <aligorith@gmail.com>
Sun, 28 Dec 2008 04:13:18 +0000 (04:13 +0000)
- Action Editor: Snap Current Frame to Selected Keyframes
- Change time operator - removed old unnecessary code

source/blender/editors/animation/anim_ops.c
source/blender/editors/space_action/action_edit_keyframes.c
source/blender/editors/space_action/action_intern.h
source/blender/editors/space_action/action_ops.c

index b47bf3c4611cc7687ec7921d76bad40ac939cf77..d31764a2cd310b07cb2129cff82e36287ee8ddbe 100644 (file)
@@ -84,22 +84,9 @@ static void change_frame_apply(bContext *C, wmOperator *op)
        
        /* get frame, and clamp to MINFRAME */
        cfra= RNA_int_get(op->ptr, "frame");
-       if (cfra < MINFRAME)
-               cfra= MINFRAME;
-
-#if 0
-       if( cfra!=CFRA || first )
-       {
-               first= 0;
-               CFRA= cfra;
-               update_for_newframe_nodraw(0);  // 1= nosound
-               timeline_force_draw(stime->redraws);
-       }
-#endif
        
-       /* XXX why don't we directly set this? */
-       if (cfra != scene->r.cfra)
-               scene->r.cfra= cfra;
+       if (cfra < MINFRAME) cfra= MINFRAME;
+       CFRA= cfra;
        
        WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene);
 }
index 8423aebfafe38ad09367c26c8aedde7a4e46dc52..d421b2a8b8c95980e2fab019e16b3c49a3af810b 100644 (file)
 
 /* ***************** Snap Current Frame Operator *********************** */
 
+/* helper callback for actkeys_cfrasnap_exec() -> used to help get the average time of all selected beztriples */
+// TODO: if some other code somewhere needs this, it'll be time to port this over to keyframes_edit.c!!!
+static short bezt_calc_average(BeztEditData *bed, BezTriple *bezt)
+{
+       /* only if selected */
+       if (bezt->f2 & SELECT) {
+               /* store average time in float (only do rounding at last step */
+               bed->f1 += bezt->vec[1][0];
+               
+               /* increment number of items */
+               bed->i1++;
+       }
+       
+       return 0;
+}
+
 /* snap current-frame indicator to 'average time' of selected keyframe */
 static int actkeys_cfrasnap_exec(bContext *C, wmOperator *op)
 {
        bAnimContext ac;
-       
-       //ListBase anim_data= {NULL, NULL};
-       //bAnimListElem *ale;
-       //int filter;
+       ListBase anim_data= {NULL, NULL};
+       bAnimListElem *ale;
+       int filter;
+       BeztEditData bed;
        
        /* get editor data */
        if (ANIM_animdata_get_context(C, &ac) == 0)
                return OPERATOR_CANCELLED;
        
-       // FIXME... to be coded
+       /* init edit data */
+       memset(&bed, 0, sizeof(BeztEditData));
+       
+       /* loop over action data, averaging values */
+       filter= (ANIMFILTER_VISIBLE | ANIMFILTER_IPOKEYS);
+       ANIM_animdata_filter(&anim_data, filter, ac.data, ac.datatype);
+       
+       for (ale= anim_data.first; ale; ale= ale->next)
+               ipo_keys_bezier_loop(&bed, ale->key_data, NULL, bezt_calc_average, NULL);
+       
+       BLI_freelistN(&anim_data);
+       
+       /* set the new current frame value, based on the average time */
+       if (bed.i1) {
+               Scene *scene= ac.scene;
+               CFRA= (int)floor((bed.f1 / bed.i1) + 0.5f);
+       }
        
        /* set notifier tha things have changed */
-       ED_area_tag_redraw(CTX_wm_area(C)); // FIXME... should be updating 'keyframes' data context or so instead!
+       WM_event_add_notifier(C, NC_SCENE|ND_FRAME, ac.scene);
        
        return OPERATOR_FINISHED;
 }
 
 void ACT_OT_keyframes_cfrasnap (wmOperatorType *ot)
 {
-       PropertyRNA *prop;
-       
        /* identifiers */
-       ot->name= "Current Frame Snap to Keys";
+       ot->name= "Snap Current Frame to Keys";
        ot->idname= "ACT_OT_keyframes_cfrasnap";
        
        /* api callbacks */
index 7719bf4ba34ef254697665484b617dd7fdec6da4..d95322d80de9db908b3604ca1ab1b1f2dd5ba605 100644 (file)
@@ -73,6 +73,7 @@ enum {
 /* ***************************************** */
 /* action_edit_keyframes.c */
 
+void ACT_OT_keyframes_cfrasnap(struct wmOperatorType *ot);
 void ACT_OT_keyframes_snap(struct wmOperatorType *ot);
 void ACT_OT_keyframes_mirror(struct wmOperatorType *ot);
 
index 51b8800c1ea2a2de9d6a49e4cb79355291feb4a1..63de5d147e91e77c7f03597aaa767aa35395620e 100644 (file)
@@ -69,6 +69,7 @@ void action_operatortypes(void)
        WM_operatortype_append(ACT_OT_keyframes_columnselect);
        
                /* editing */
+       WM_operatortype_append(ACT_OT_keyframes_cfrasnap);
        WM_operatortype_append(ACT_OT_keyframes_snap);
        WM_operatortype_append(ACT_OT_keyframes_mirror);
 }
@@ -99,6 +100,9 @@ static void action_keymap_keyframes (ListBase *keymap)
        RNA_enum_set(WM_keymap_add_item(keymap, "ACT_OT_keyframes_columnselect", KKEY, KM_PRESS, KM_ALT, 0)->ptr, "mode", ACTKEYS_COLUMNSEL_MARKERS_BETWEEN);
        
        /* action_edit_keyframes.c */
+               /* snap - current frame to selected keys */
+       WM_keymap_add_item(keymap, "ACT_OT_keyframes_cfrasnap", SKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
+               
                /* menu+1-step transform */
        WM_keymap_add_item(keymap, "ACT_OT_keyframes_snap", SKEY, KM_PRESS, KM_SHIFT, 0);
        WM_keymap_add_item(keymap, "ACT_OT_keyframes_mirror", MKEY, KM_PRESS, KM_SHIFT, 0);