forked from bartvdbraak/blender
2.5
- Action Editor: Snap Current Frame to Selected Keyframes - Change time operator - removed old unnecessary code
This commit is contained in:
parent
bb02d1fd4f
commit
452f1d1ea9
@ -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);
|
||||
}
|
||||
|
@ -96,33 +96,63 @@
|
||||
|
||||
/* ***************** 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 */
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user