[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [26564] trunk/blender/source/blender/ editors: Bugfix #19970: auto-clamped / auto working strangly in f-curve editor

Joshua Leung aligorith at gmail.com
Tue Feb 2 22:16:28 CET 2010


Revision: 26564
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=26564
Author:   aligorith
Date:     2010-02-02 22:16:28 +0100 (Tue, 02 Feb 2010)

Log Message:
-----------
Bugfix #19970: auto-clamped / auto working strangly in f-curve editor

Thanks to a great doc from Bassam (slikdigit) on the different types of handles (which should probably become/be part of future 2.5 docs), I've revised the code again so that this works well again.

The doc:
http://docs.google.com/View?id=dvgkxj6_1d8cpfw79

Modified Paths:
--------------
    trunk/blender/source/blender/editors/animation/keyframes_edit.c
    trunk/blender/source/blender/editors/space_action/action_edit.c
    trunk/blender/source/blender/editors/space_graph/graph_edit.c

Modified: trunk/blender/source/blender/editors/animation/keyframes_edit.c
===================================================================
--- trunk/blender/source/blender/editors/animation/keyframes_edit.c	2010-02-02 19:51:56 UTC (rev 26563)
+++ trunk/blender/source/blender/editors/animation/keyframes_edit.c	2010-02-02 21:16:28 UTC (rev 26564)
@@ -815,7 +815,9 @@
 {
 	switch (code) {
 		case HD_AUTO: /* auto */
+		case HD_AUTO_ANIM: /* auto clamped */
 			return set_bezier_auto;
+			
 		case HD_VECT: /* vector */
 			return set_bezier_vector;
 		case HD_FREE: /* free */
@@ -823,7 +825,7 @@
 		case HD_ALIGN: /* align */
 			return set_bezier_align;
 		
-		default: /* free or align? */
+		default: /* check for toggle free or align? */
 			return bezier_isfree;
 	}
 }

Modified: trunk/blender/source/blender/editors/space_action/action_edit.c
===================================================================
--- trunk/blender/source/blender/editors/space_action/action_edit.c	2010-02-02 19:51:56 UTC (rev 26563)
+++ trunk/blender/source/blender/editors/space_action/action_edit.c	2010-02-02 21:16:28 UTC (rev 26564)
@@ -950,13 +950,12 @@
 /* ******************** Set Handle-Type Operator *********************** */
 
 EnumPropertyItem actkeys_handle_type_items[] = {
-	{0, "", 0, "For Selected Handles", ""},
 	{HD_FREE, "FREE", 0, "Free", ""},
-	{HD_AUTO, "AUTO", 0, "Auto", ""},
 	{HD_VECT, "VECTOR", 0, "Vector", ""},
 	{HD_ALIGN, "ALIGNED", 0, "Aligned", ""},
-	{0, "", 0, "For Selected F-Curves", ""},
-	{HD_AUTO_ANIM, "ANIM_CLAMPED", 0, "Auto Clamped", "Handles stay horizontal"},
+	{0, "", 0, "", ""},
+	{HD_AUTO, "AUTO", 0, "Auto", "Handles that are automatically adjusted upon moving the keyframe"},
+	{HD_AUTO_ANIM, "ANIM_CLAMPED", 0, "Auto Clamped", "Auto handles clamped to not overshoot"},
 	{0, NULL, 0, NULL, NULL}};
 
 /* ------------------- */
@@ -967,8 +966,10 @@
 	ListBase anim_data = {NULL, NULL};
 	bAnimListElem *ale;
 	int filter;
-	BeztEditFunc set_cb= ANIM_editkeyframes_handles(mode);
 	
+	BeztEditFunc edit_cb= ANIM_editkeyframes_handles(mode);
+	BeztEditFunc sel_cb= ANIM_editkeyframes_ok(BEZT_OK_SELECTED);
+	
 	/* filter data */
 	filter= (ANIMFILTER_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_CURVESONLY);
 	ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
@@ -976,36 +977,20 @@
 	/* loop through setting flags for handles 
 	 * Note: we do not supply BeztEditData to the looper yet. Currently that's not necessary here...
 	 */
-	for (ale= anim_data.first; ale; ale= ale->next)
-		ANIM_fcurve_keys_bezier_loop(NULL, ale->key_data, NULL, set_cb, calchandles_fcurve);
-	
-	/* cleanup */
-	BLI_freelistN(&anim_data);
-}
-
-/* this function is responsible for toggling clamped-handles  */
-static void sethandles_clamped_action_keys(bAnimContext *ac) 
-{
-	ListBase anim_data = {NULL, NULL};
-	bAnimListElem *ale;
-	int filter;
-	
-	/* filter data */
-	filter= (ANIMFILTER_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_CURVESONLY);
-	ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
-	
-	/* toggle auto-handles on the F-Curves, which forces handles to stay horizontal */
 	for (ale= anim_data.first; ale; ale= ale->next) {
-		FCurve *fcu= ale->data;
+		FCurve *fcu= (FCurve *)ale->key_data;
 		
-		/* only enable if curve is selected */
-		if (SEL_FCU(fcu))
-			fcu->flag |= FCURVE_AUTO_HANDLES;
-		else
-			fcu->flag &= ~FCURVE_AUTO_HANDLES;
+		/* any selected keyframes for editing? */
+		if (ANIM_fcurve_keys_bezier_loop(NULL, fcu, NULL, sel_cb, NULL)) {
+			/* for auto/auto-clamped, toggle the auto-handles flag on the F-Curve */
+			if (mode == HD_AUTO_ANIM)
+				fcu->flag |= FCURVE_AUTO_HANDLES;
+			else if (mode == HD_AUTO)
+				fcu->flag &= ~FCURVE_AUTO_HANDLES;
 			
-		/* force handles to be recalculated */
-		calchandles_fcurve(fcu);
+			/* change type of selected handles */
+			ANIM_fcurve_keys_bezier_loop(NULL, fcu, NULL, edit_cb, calchandles_fcurve);
+		}
 	}
 	
 	/* cleanup */
@@ -1029,10 +1014,7 @@
 	mode= RNA_enum_get(op->ptr, "type");
 	
 	/* set handle type */
-	if (mode == HD_AUTO_ANIM)
-		sethandles_clamped_action_keys(&ac);
-	else
-		sethandles_action_keys(&ac, mode);
+	sethandles_action_keys(&ac, mode);
 	
 	/* validate keyframes after editing */
 	ANIM_editkeyframes_refresh(&ac);

Modified: trunk/blender/source/blender/editors/space_graph/graph_edit.c
===================================================================
--- trunk/blender/source/blender/editors/space_graph/graph_edit.c	2010-02-02 19:51:56 UTC (rev 26563)
+++ trunk/blender/source/blender/editors/space_graph/graph_edit.c	2010-02-02 21:16:28 UTC (rev 26564)
@@ -1362,13 +1362,12 @@
 /* ******************** Set Handle-Type Operator *********************** */
 
 EnumPropertyItem graphkeys_handle_type_items[] = {
-	{0, "", 0, "For Selected Handles", ""},
 	{HD_FREE, "FREE", 0, "Free", ""},
-	{HD_AUTO, "AUTO", 0, "Auto", ""},
 	{HD_VECT, "VECTOR", 0, "Vector", ""},
 	{HD_ALIGN, "ALIGNED", 0, "Aligned", ""},
-	{0, "", 0, "For Selected F-Curves", ""},
-	{HD_AUTO_ANIM, "ANIM_CLAMPED", 0, "Auto Clamped", "Handles stay horizontal"},
+	{0, "", 0, "", ""},
+	{HD_AUTO, "AUTO", 0, "Auto", "Handles that are automatically adjusted upon moving the keyframe. Whole curve."},
+	{HD_AUTO_ANIM, "ANIM_CLAMPED", 0, "Auto Clamped", "Auto handles clamped to not overshoot. Whole curve."},
 	{0, NULL, 0, NULL, NULL}};
 
 /* ------------------- */
@@ -1379,8 +1378,10 @@
 	ListBase anim_data = {NULL, NULL};
 	bAnimListElem *ale;
 	int filter;
-	BeztEditFunc set_cb= ANIM_editkeyframes_handles(mode);
 	
+	BeztEditFunc edit_cb= ANIM_editkeyframes_handles(mode);
+	BeztEditFunc sel_cb= ANIM_editkeyframes_ok(BEZT_OK_SELECTED);
+	
 	/* filter data */
 	filter= (ANIMFILTER_VISIBLE | ANIMFILTER_CURVEVISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_CURVESONLY);
 	ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
@@ -1388,42 +1389,25 @@
 	/* loop through setting flags for handles 
 	 * Note: we do not supply BeztEditData to the looper yet. Currently that's not necessary here...
 	 */
-	for (ale= anim_data.first; ale; ale= ale->next)
-		ANIM_fcurve_keys_bezier_loop(NULL, ale->key_data, NULL, set_cb, calchandles_fcurve);
-	
-	/* cleanup */
-	BLI_freelistN(&anim_data);
-}
-
-/* this function is responsible for toggling clamped-handles  */
-static void sethandles_clamped_graph_keys(bAnimContext *ac) 
-{
-	ListBase anim_data = {NULL, NULL};
-	bAnimListElem *ale;
-	int filter;
-	
-	/* filter data */
-	filter= (ANIMFILTER_VISIBLE | ANIMFILTER_CURVEVISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_CURVESONLY);
-	ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
-	
-	/* toggle auto-handles on the F-Curves, which forces handles to stay horizontal */
 	for (ale= anim_data.first; ale; ale= ale->next) {
-		FCurve *fcu= ale->data;
+		FCurve *fcu= (FCurve *)ale->key_data;
 		
-		/* only enable if curve is selected */
-		if (SEL_FCU(fcu))
-			fcu->flag |= FCURVE_AUTO_HANDLES;
-		else
-			fcu->flag &= ~FCURVE_AUTO_HANDLES;
+		/* any selected keyframes for editing? */
+		if (ANIM_fcurve_keys_bezier_loop(NULL, fcu, NULL, sel_cb, NULL)) {
+			/* for auto/auto-clamped, toggle the auto-handles flag on the F-Curve */
+			if (mode == HD_AUTO_ANIM)
+				fcu->flag |= FCURVE_AUTO_HANDLES;
+			else if (mode == HD_AUTO)
+				fcu->flag &= ~FCURVE_AUTO_HANDLES;
 			
-		/* force handles to be recalculated */
-		calchandles_fcurve(fcu);
+			/* change type of selected handles */
+			ANIM_fcurve_keys_bezier_loop(NULL, fcu, NULL, edit_cb, calchandles_fcurve);
+		}
 	}
 	
 	/* cleanup */
 	BLI_freelistN(&anim_data);
 }
-
 /* ------------------- */
 
 static int graphkeys_handletype_exec(bContext *C, wmOperator *op)
@@ -1439,10 +1423,7 @@
 	mode= RNA_enum_get(op->ptr, "type");
 	
 	/* set handle type */
-	if (mode == HD_AUTO_ANIM)
-		sethandles_clamped_graph_keys(&ac);
-	else
-		sethandles_graph_keys(&ac, mode);
+	sethandles_graph_keys(&ac, mode);
 	
 	/* validate keyframes after editing */
 	ANIM_editkeyframes_refresh(&ac);





More information about the Bf-blender-cvs mailing list