Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Leung <aligorith@gmail.com>2008-12-28 07:13:18 +0300
committerJoshua Leung <aligorith@gmail.com>2008-12-28 07:13:18 +0300
commit452f1d1ea9ecc637103a55ad97564a44371b228a (patch)
tree021c38df06f52ea2af128656bfac34a8c979bc5b
parentbb02d1fd4f86cdb42b1d3dee7b56ec2bde20fbbc (diff)
2.5
- Action Editor: Snap Current Frame to Selected Keyframes - Change time operator - removed old unnecessary code
-rw-r--r--source/blender/editors/animation/anim_ops.c17
-rw-r--r--source/blender/editors/space_action/action_edit_keyframes.c48
-rw-r--r--source/blender/editors/space_action/action_intern.h1
-rw-r--r--source/blender/editors/space_action/action_ops.c4
4 files changed, 46 insertions, 24 deletions
diff --git a/source/blender/editors/animation/anim_ops.c b/source/blender/editors/animation/anim_ops.c
index b47bf3c4611..d31764a2cd3 100644
--- a/source/blender/editors/animation/anim_ops.c
+++ b/source/blender/editors/animation/anim_ops.c
@@ -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);
}
diff --git a/source/blender/editors/space_action/action_edit_keyframes.c b/source/blender/editors/space_action/action_edit_keyframes.c
index 8423aebfafe..d421b2a8b8c 100644
--- a/source/blender/editors/space_action/action_edit_keyframes.c
+++ b/source/blender/editors/space_action/action_edit_keyframes.c
@@ -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 */
diff --git a/source/blender/editors/space_action/action_intern.h b/source/blender/editors/space_action/action_intern.h
index 7719bf4ba34..d95322d80de 100644
--- a/source/blender/editors/space_action/action_intern.h
+++ b/source/blender/editors/space_action/action_intern.h
@@ -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);
diff --git a/source/blender/editors/space_action/action_ops.c b/source/blender/editors/space_action/action_ops.c
index 51b8800c1ea..63de5d147e9 100644
--- a/source/blender/editors/space_action/action_ops.c
+++ b/source/blender/editors/space_action/action_ops.c
@@ -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);