[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [18109] branches/blender2.5/blender/source /blender/editors: 2.5

Joshua Leung aligorith at gmail.com
Sun Dec 28 05:13:19 CET 2008


Revision: 18109
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18109
Author:   aligorith
Date:     2008-12-28 05:13:18 +0100 (Sun, 28 Dec 2008)

Log Message:
-----------
2.5 

- Action Editor: Snap Current Frame to Selected Keyframes
- Change time operator - removed old unnecessary code

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/editors/animation/anim_ops.c
    branches/blender2.5/blender/source/blender/editors/space_action/action_edit_keyframes.c
    branches/blender2.5/blender/source/blender/editors/space_action/action_intern.h
    branches/blender2.5/blender/source/blender/editors/space_action/action_ops.c

Modified: branches/blender2.5/blender/source/blender/editors/animation/anim_ops.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/animation/anim_ops.c	2008-12-28 01:49:39 UTC (rev 18108)
+++ branches/blender2.5/blender/source/blender/editors/animation/anim_ops.c	2008-12-28 04:13:18 UTC (rev 18109)
@@ -84,22 +84,9 @@
 	
 	/* 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);
 }

Modified: branches/blender2.5/blender/source/blender/editors/space_action/action_edit_keyframes.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/space_action/action_edit_keyframes.c	2008-12-28 01:49:39 UTC (rev 18108)
+++ branches/blender2.5/blender/source/blender/editors/space_action/action_edit_keyframes.c	2008-12-28 04:13:18 UTC (rev 18109)
@@ -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;
+	BeztEditData bed;
 	
-	//ListBase anim_data= {NULL, NULL};
-	//bAnimListElem *ale;
-	//int filter;
-	
 	/* 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 */

Modified: branches/blender2.5/blender/source/blender/editors/space_action/action_intern.h
===================================================================
--- branches/blender2.5/blender/source/blender/editors/space_action/action_intern.h	2008-12-28 01:49:39 UTC (rev 18108)
+++ branches/blender2.5/blender/source/blender/editors/space_action/action_intern.h	2008-12-28 04:13:18 UTC (rev 18109)
@@ -73,6 +73,7 @@
 /* ***************************************** */
 /* 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);
 

Modified: branches/blender2.5/blender/source/blender/editors/space_action/action_ops.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/space_action/action_ops.c	2008-12-28 01:49:39 UTC (rev 18108)
+++ branches/blender2.5/blender/source/blender/editors/space_action/action_ops.c	2008-12-28 04:13:18 UTC (rev 18109)
@@ -69,6 +69,7 @@
 	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 @@
 	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);





More information about the Bf-blender-cvs mailing list