Revision: 26510
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=26510
Author:   aligorith
Date:     2010-02-01 12:45:24 +0100 (Mon, 01 Feb 2010)

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

Fixed the operators for DopeSheet/Graph Editors responsible for setting the 
"auto-clamped". This option is actually per F-Curve instead of per handle, and 
the code here should function like it did in 2.4x

However, despite this, it still appears to work oddly IMO. Any comments Bassam 
or animators familiar with the intentions of this?

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
    trunk/blender/source/blender/makesdna/DNA_curve_types.h
    trunk/blender/source/blender/makesrna/intern/rna_curve.c

Modified: trunk/blender/source/blender/editors/animation/keyframes_edit.c
===================================================================
--- trunk/blender/source/blender/editors/animation/keyframes_edit.c     
2010-02-01 11:36:22 UTC (rev 26509)
+++ trunk/blender/source/blender/editors/animation/keyframes_edit.c     
2010-02-01 11:45:24 UTC (rev 26510)
@@ -753,8 +753,8 @@
 static short set_bezier_auto(BeztEditData *bed, BezTriple *bezt) 
 {
        if((bezt->f1  & SELECT) || (bezt->f3 & SELECT)) {
-               if (bezt->f1 & SELECT) bezt->h1= 1; /* the secret code for auto 
*/
-               if (bezt->f3 & SELECT) bezt->h2= 1;
+               if (bezt->f1 & SELECT) bezt->h1= HD_AUTO; /* the secret code 
for auto */
+               if (bezt->f3 & SELECT) bezt->h2= HD_AUTO;
                
                /* if the handles are not of the same type, set them
                 * to type free
@@ -809,7 +809,7 @@
        return 0;
 }
 
-/* Set all Bezier Handles to a single type */
+/* Set all selected Bezier Handles to a single type */
 // calchandles_fcurve
 BeztEditFunc ANIM_editkeyframes_handles(short code)
 {

Modified: trunk/blender/source/blender/editors/space_action/action_edit.c
===================================================================
--- trunk/blender/source/blender/editors/space_action/action_edit.c     
2010-02-01 11:36:22 UTC (rev 26509)
+++ trunk/blender/source/blender/editors/space_action/action_edit.c     
2010-02-01 11:45:24 UTC (rev 26510)
@@ -949,6 +949,18 @@
 
 /* ******************** 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, NULL, 0, NULL, NULL}};
+
+/* ------------------- */
+
 /* this function is responsible for setting handle-type of selected keyframes 
*/
 static void sethandles_action_keys(bAnimContext *ac, short mode) 
 {
@@ -964,25 +976,36 @@
        /* 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) {
-               if (mode == -1) {       
-                       BeztEditFunc toggle_cb;
+               FCurve *fcu= ale->data;
+               
+               /* only enable if curve is selected */
+               if (SEL_FCU(fcu))
+                       fcu->flag |= FCURVE_AUTO_HANDLES;
+               else
+                       fcu->flag &= ~FCURVE_AUTO_HANDLES;
                        
-                       /* check which type of handle to set (free or aligned) 
-                        *      - check here checks for handles with free 
alignment already
-                        */
-                       if (ANIM_fcurve_keys_bezier_loop(NULL, ale->key_data, 
NULL, set_cb, NULL))
-                               toggle_cb= ANIM_editkeyframes_handles(HD_FREE);
-                       else
-                               toggle_cb= ANIM_editkeyframes_handles(HD_ALIGN);
-                               
-                       /* set handle-type */
-                       ANIM_fcurve_keys_bezier_loop(NULL, ale->key_data, NULL, 
toggle_cb, calchandles_fcurve);
-               }
-               else {
-                       /* directly set handle-type */
-                       ANIM_fcurve_keys_bezier_loop(NULL, ale->key_data, NULL, 
set_cb, calchandles_fcurve);
-               }
+               /* force handles to be recalculated */
+               calchandles_fcurve(fcu);
        }
        
        /* cleanup */
@@ -1006,7 +1029,10 @@
        mode= RNA_enum_get(op->ptr, "type");
        
        /* set handle type */
-       sethandles_action_keys(&ac, mode);
+       if (mode == HD_AUTO_ANIM)
+               sethandles_clamped_action_keys(&ac);
+       else
+               sethandles_action_keys(&ac, mode);
        
        /* validate keyframes after editing */
        ANIM_editkeyframes_refresh(&ac);
@@ -1033,7 +1059,7 @@
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* id-props */
-       ot->prop= RNA_def_enum(ot->srna, "type", beztriple_handle_type_items, 
0, "Type", "");
+       ot->prop= RNA_def_enum(ot->srna, "type", actkeys_handle_type_items, 0, 
"Type", "");
 }
 
 /* ******************** Set Keyframe-Type Operator *********************** */

Modified: trunk/blender/source/blender/editors/space_graph/graph_edit.c
===================================================================
--- trunk/blender/source/blender/editors/space_graph/graph_edit.c       
2010-02-01 11:36:22 UTC (rev 26509)
+++ trunk/blender/source/blender/editors/space_graph/graph_edit.c       
2010-02-01 11:45:24 UTC (rev 26510)
@@ -1361,6 +1361,18 @@
 
 /* ******************** 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, NULL, 0, NULL, NULL}};
+
+/* ------------------- */
+
 /* this function is responsible for setting handle-type of selected keyframes 
*/
 static void sethandles_graph_keys(bAnimContext *ac, short mode) 
 {
@@ -1370,32 +1382,42 @@
        BeztEditFunc set_cb= ANIM_editkeyframes_handles(mode);
        
        /* filter data */
-       filter= (ANIMFILTER_VISIBLE | ANIMFILTER_CURVEVISIBLE| 
ANIMFILTER_FOREDIT | ANIMFILTER_CURVESONLY);
+       filter= (ANIMFILTER_VISIBLE | ANIMFILTER_CURVEVISIBLE | 
ANIMFILTER_FOREDIT | ANIMFILTER_CURVESONLY);
        ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
        
        /* loop through setting flags for handles 
         * Note: we do not supply BeztEditData to the looper yet. Currently 
that's not necessary here...
         */
-       // XXX we might need to supply BeztEditData to get it to only affect 
selected handles
+       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) {
-               if (mode == -1) {       
-                       BeztEditFunc toggle_cb;
+               FCurve *fcu= ale->data;
+               
+               /* only enable if curve is selected */
+               if (SEL_FCU(fcu))
+                       fcu->flag |= FCURVE_AUTO_HANDLES;
+               else
+                       fcu->flag &= ~FCURVE_AUTO_HANDLES;
                        
-                       /* check which type of handle to set (free or aligned) 
-                        *      - check here checks for handles with free 
alignment already
-                        */
-                       if (ANIM_fcurve_keys_bezier_loop(NULL, ale->key_data, 
NULL, set_cb, NULL))
-                               toggle_cb= ANIM_editkeyframes_handles(HD_FREE);
-                       else
-                               toggle_cb= ANIM_editkeyframes_handles(HD_ALIGN);
-                               
-                       /* set handle-type */
-                       ANIM_fcurve_keys_bezier_loop(NULL, ale->key_data, NULL, 
toggle_cb, calchandles_fcurve);
-               }
-               else {
-                       /* directly set handle-type */
-                       ANIM_fcurve_keys_bezier_loop(NULL, ale->key_data, NULL, 
set_cb, calchandles_fcurve);
-               }
+               /* force handles to be recalculated */
+               calchandles_fcurve(fcu);
        }
        
        /* cleanup */
@@ -1417,18 +1439,21 @@
        mode= RNA_enum_get(op->ptr, "type");
        
        /* set handle type */
-       sethandles_graph_keys(&ac, mode);
+       if (mode == HD_AUTO_ANIM)
+               sethandles_clamped_graph_keys(&ac);
+       else
+               sethandles_graph_keys(&ac, mode);
        
        /* validate keyframes after editing */
        ANIM_editkeyframes_refresh(&ac);
        
-       /* set notifier that things have changed */
+       /* set notifier that keyframe properties have changed */
        WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME_PROP, NULL);
        
        return OPERATOR_FINISHED;
 }
  
-void GRAPH_OT_handle_type (wmOperatorType *ot)
+ void GRAPH_OT_handle_type (wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Set Keyframe Handle Type";
@@ -1444,7 +1469,7 @@
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* id-props */
-       ot->prop= RNA_def_enum(ot->srna, "type", beztriple_handle_type_items, 
0, "Type", "");
+       ot->prop= RNA_def_enum(ot->srna, "type", graphkeys_handle_type_items, 
0, "Type", "");
 }
 
 /* ************************************************************************** 
*/

Modified: trunk/blender/source/blender/makesdna/DNA_curve_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_curve_types.h     2010-02-01 
11:36:22 UTC (rev 26509)
+++ trunk/blender/source/blender/makesdna/DNA_curve_types.h     2010-02-01 
11:45:24 UTC (rev 26510)
@@ -297,7 +297,7 @@
        HD_AUTO,
        HD_VECT,
        HD_ALIGN,
-       HD_AUTO_ANIM
+       HD_AUTO_ANIM,   /* not real handle type, but is just used as dummy item 
for anim code */
 } eBezTriple_Handle;
 
 /* interpolation modes (used only for BezTriple->ipo) */

Modified: trunk/blender/source/blender/makesrna/intern/rna_curve.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_curve.c    2010-02-01 
11:36:22 UTC (rev 26509)
+++ trunk/blender/source/blender/makesrna/intern/rna_curve.c    2010-02-01 
11:45:24 UTC (rev 26510)
@@ -42,7 +42,6 @@
                {HD_AUTO, "AUTO", 0, "Auto", ""},
                {HD_VECT, "VECTOR", 0, "Vector", ""},
                {HD_ALIGN, "ALIGNED", 0, "Aligned", ""},
-               {HD_AUTO_ANIM, "AUTO_CLAMPED", 0, "Auto Clamped", ""},
                {0, NULL, 0, NULL, NULL}};
 
 EnumPropertyItem beztriple_interpolation_mode_items[] = {


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to