From 1ee7b2fae4c61ac45ae6a7e53e51bea78a7ae306 Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Tue, 2 Feb 2010 21:16:28 +0000 Subject: 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 --- source/blender/editors/animation/keyframes_edit.c | 4 +- source/blender/editors/space_action/action_edit.c | 54 ++++++++-------------- source/blender/editors/space_graph/graph_edit.c | 55 ++++++++--------------- 3 files changed, 39 insertions(+), 74 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/animation/keyframes_edit.c b/source/blender/editors/animation/keyframes_edit.c index 81845598162..912b51a0b4d 100644 --- a/source/blender/editors/animation/keyframes_edit.c +++ b/source/blender/editors/animation/keyframes_edit.c @@ -815,7 +815,9 @@ BeztEditFunc ANIM_editkeyframes_handles(short code) { 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 @@ BeztEditFunc ANIM_editkeyframes_handles(short code) case HD_ALIGN: /* align */ return set_bezier_align; - default: /* free or align? */ + default: /* check for toggle free or align? */ return bezier_isfree; } } diff --git a/source/blender/editors/space_action/action_edit.c b/source/blender/editors/space_action/action_edit.c index bb77ad40671..22f5989f3aa 100644 --- a/source/blender/editors/space_action/action_edit.c +++ b/source/blender/editors/space_action/action_edit.c @@ -950,13 +950,12 @@ void ACTION_OT_interpolation_type (wmOperatorType *ot) /* ******************** 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,7 +966,9 @@ static void sethandles_action_keys(bAnimContext *ac, short mode) 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); @@ -976,36 +977,20 @@ static void sethandles_action_keys(bAnimContext *ac, short mode) /* 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 @@ static int actkeys_handletype_exec(bContext *C, wmOperator *op) 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); diff --git a/source/blender/editors/space_graph/graph_edit.c b/source/blender/editors/space_graph/graph_edit.c index 5e2e56abcc5..dca2b2f3b98 100644 --- a/source/blender/editors/space_graph/graph_edit.c +++ b/source/blender/editors/space_graph/graph_edit.c @@ -1362,13 +1362,12 @@ void GRAPH_OT_interpolation_type (wmOperatorType *ot) /* ******************** 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,7 +1378,9 @@ static void sethandles_graph_keys(bAnimContext *ac, short mode) 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); @@ -1388,42 +1389,25 @@ static void sethandles_graph_keys(bAnimContext *ac, short mode) /* 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 @@ static int graphkeys_handletype_exec(bContext *C, wmOperator *op) 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); -- cgit v1.2.3