Bugfix T41525: Button keyframe indicators don't work correctly when editing NLA Strips
authorJoshua Leung <aligorith@gmail.com>
Sun, 16 Nov 2014 07:24:38 +0000 (20:24 +1300)
committerJoshua Leung <aligorith@gmail.com>
Sun, 16 Nov 2014 07:24:38 +0000 (20:24 +1300)
When the active action is a NLA strip, the keyframe indicator colors for buttons
and the 3D view indicator (i.e. the current frame indicator changes color) didn't
work correctly. This was because they were still checking for keyframes in
"global" time space, whereas they needed to be applying NLA corrections to
"look inside" the remapped action.

source/blender/blenkernel/BKE_fcurve.h
source/blender/blenkernel/intern/fcurve.c
source/blender/editors/animation/keyframing.c
source/blender/editors/interface/interface_anim.c
source/blender/editors/space_outliner/outliner_draw.c
source/blender/makesrna/intern/rna_access.c

index c377769b2713883e7add26e29db465c1fec3679e..83783946d4f979ebe2c178114d28af529bf7ff9c 100644 (file)
@@ -44,6 +44,7 @@ struct DriverTarget;
 struct FCM_EnvelopeData;
 
 struct bContext;
+struct AnimData;
 struct bAction;
 struct BezTriple;
 struct StructRNA;
@@ -224,10 +225,10 @@ int list_find_data_fcurves(ListBase *dst, ListBase *src, const char *dataPrefix,
 
 /* find an f-curve based on an rna property. */
 struct FCurve *rna_get_fcurve(struct PointerRNA *ptr, struct PropertyRNA *prop, int rnaindex,
-                              struct bAction **action, bool *r_driven);
+                              struct AnimData **adt, struct bAction **action, bool *r_driven);
 /* Same as above, but takes a context data, temp hack needed for complex paths like texture ones. */
 struct FCurve *rna_get_fcurve_context_ui(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop,
-                                         int rnaindex, struct bAction **action, bool *r_driven);
+                                         int rnaindex, struct AnimData **adt, struct bAction **action, bool *r_driven);
 
 /* Binary search algorithm for finding where to 'insert' BezTriple with given frame number.
  * Returns the index to insert at (data already at that index will be offset if replace is 0)
index e90a08914360855bc6f1c8b5334b95d33fd88d44..325c60566f785b075bd50033f26f57c66b1e807d 100644 (file)
@@ -309,17 +309,18 @@ int list_find_data_fcurves(ListBase *dst, ListBase *src, const char *dataPrefix,
        return matches;
 }
 
-FCurve *rna_get_fcurve(PointerRNA *ptr, PropertyRNA *prop, int rnaindex, bAction **action, bool *r_driven)
+FCurve *rna_get_fcurve(PointerRNA *ptr, PropertyRNA *prop, int rnaindex, AnimData **adt, bAction **action, bool *r_driven)
 {
-       return rna_get_fcurve_context_ui(NULL, ptr, prop, rnaindex, action, r_driven);
+       return rna_get_fcurve_context_ui(NULL, ptr, prop, rnaindex, adt, action, r_driven);
 }
 
 FCurve *rna_get_fcurve_context_ui(bContext *C, PointerRNA *ptr, PropertyRNA *prop, int rnaindex,
-                                  bAction **action, bool *r_driven)
+                                  AnimData **animdata, bAction **action, bool *r_driven)
 {
        FCurve *fcu = NULL;
        PointerRNA tptr = *ptr;
        
+       if (animdata) *animdata = NULL;
        *r_driven = false;
        
        /* there must be some RNA-pointer + property combon */
@@ -350,11 +351,14 @@ FCurve *rna_get_fcurve_context_ui(bContext *C, PointerRNA *ptr, PropertyRNA *pro
                                        if (!fcu && (adt->drivers.first)) {
                                                fcu = list_find_fcurve(&adt->drivers, path, rnaindex);
                                                
-                                               if (fcu)
+                                               if (fcu) {
+                                                       if (animdata) *animdata = adt;
                                                        *r_driven = true;
+                                               }
                                        }
                                        
                                        if (fcu && action) {
+                                               if (animdata) *animdata = adt;
                                                *action = adt->action;
                                                break;
                                        }
index 9a9c987be148b7eaf7c728887efc0189685d06de..2c66d92ab585c36b8d1716bc5c399ce437d85e61 100644 (file)
@@ -2011,7 +2011,13 @@ static bool object_frame_has_keyframe(Object *ob, float frame, short filter)
        
        /* check own animation data - specifically, the action it contains */
        if ((ob->adt) && (ob->adt->action)) {
-               if (action_frame_has_keyframe(ob->adt->action, frame, filter))
+               /* T41525 - When the active action is a NLA strip being edited, 
+                * we need to correct the frame number to "look inside" the
+                * remapped action
+                */
+               float ob_frame = BKE_nla_tweakedit_remap(ob->adt, frame, NLATIME_CONVERT_UNMAP);
+               
+               if (action_frame_has_keyframe(ob->adt->action, ob_frame, filter))
                        return 1;
        }
        
index aa23184727a4e9fc2d3eb9ef0b01c0181674df23..7e7806f6ada70e015eb8b0858e1b67be899ad56e 100644 (file)
@@ -43,6 +43,7 @@
 #include "BKE_animsys.h"
 #include "BKE_fcurve.h"
 #include "BKE_global.h"
+#include "BKE_nla.h"
 
 #include "ED_keyframing.h"
 
 
 #include "interface_intern.h"
 
-static FCurve *ui_but_get_fcurve(uiBut *but, bAction **action, bool *r_driven)
+static FCurve *ui_but_get_fcurve(uiBut *but, AnimData **adt, bAction **action, bool *r_driven)
 {
        /* for entire array buttons we check the first component, it's not perfect
         * but works well enough in typical cases */
        int rnaindex = (but->rnaindex == -1) ? 0 : but->rnaindex;
 
-       return rna_get_fcurve_context_ui(but->block->evil_C, &but->rnapoin, but->rnaprop, rnaindex, action, r_driven);
+       return rna_get_fcurve_context_ui(but->block->evil_C, &but->rnapoin, but->rnaprop, rnaindex, adt, action, r_driven);
 }
 
 void ui_but_anim_flag(uiBut *but, float cfra)
 {
+       AnimData *adt;
+       bAction *act;
        FCurve *fcu;
        bool driven;
 
        but->flag &= ~(UI_BUT_ANIMATED | UI_BUT_ANIMATED_KEY | UI_BUT_DRIVEN);
 
-       fcu = ui_but_get_fcurve(but, NULL, &driven);
+       fcu = ui_but_get_fcurve(but, &adt, &act, &driven);
 
        if (fcu) {
                if (!driven) {
                        but->flag |= UI_BUT_ANIMATED;
                        
+                       /* T41525 - When the active action is a NLA strip being edited, 
+                        * we need to correct the frame number to "look inside" the
+                        * remapped action
+                        */
+                       if (adt)
+                               cfra = BKE_nla_tweakedit_remap(adt, cfra, NLATIME_CONVERT_UNMAP);
+                       
                        if (fcurve_frame_has_keyframe(fcu, cfra, 0))
                                but->flag |= UI_BUT_ANIMATED_KEY;
                }
@@ -92,7 +102,7 @@ bool ui_but_anim_expression_get(uiBut *but, char *str, size_t maxlen)
        ChannelDriver *driver;
        bool driven;
 
-       fcu = ui_but_get_fcurve(but, NULL, &driven);
+       fcu = ui_but_get_fcurve(but, NULL, NULL, &driven);
 
        if (fcu && driven) {
                driver = fcu->driver;
@@ -112,7 +122,7 @@ bool ui_but_anim_expression_set(uiBut *but, const char *str)
        ChannelDriver *driver;
        bool driven;
 
-       fcu = ui_but_get_fcurve(but, NULL, &driven);
+       fcu = ui_but_get_fcurve(but, NULL, NULL, &driven);
 
        if (fcu && driven) {
                driver = fcu->driver;
@@ -208,7 +218,7 @@ void ui_but_anim_autokey(bContext *C, uiBut *but, Scene *scene, float cfra)
        FCurve *fcu;
        bool driven;
 
-       fcu = ui_but_get_fcurve(but, &action, &driven);
+       fcu = ui_but_get_fcurve(but, NULL, &action, &driven);
 
        if (fcu && !driven) {
                id = but->rnapoin.id.data;
index 377bd3ab431404d65793eff256016f3721791d8f..3df6bd51f37dbfd3a1bc85b7dca9d7e1c6c9da65 100644 (file)
@@ -197,7 +197,7 @@ static void restrictbutton_recursive_child(bContext *C, Scene *scene, Object *ob
 
                                RNA_id_pointer_create(&ob->id, &ptr);
                                prop = RNA_struct_find_property(&ptr, rnapropname);
-                               fcu = rna_get_fcurve_context_ui(C, &ptr, prop, 0, &action, &driven);
+                               fcu = rna_get_fcurve_context_ui(C, &ptr, prop, 0, NULL, &action, &driven);
 
                                if (fcu && !driven) {
                                        id = ptr.id.data;
index 806b9d0d5ade1df16559f028d4135e4e6c57641f..9494377e319276539b6f039fa19cb1e8a948502a 100644 (file)
@@ -1630,9 +1630,10 @@ bool RNA_property_animated(PointerRNA *ptr, PropertyRNA *prop)
        if (RNA_property_array_check(prop))
                len = RNA_property_array_length(ptr, prop);
 
-       for (index = 0; index < len; index++)
-               if (rna_get_fcurve(ptr, prop, index, NULL, &driven))
+       for (index = 0; index < len; index++) {
+               if (rna_get_fcurve(ptr, prop, index, NULL, NULL, &driven))
                        return true;
+       }
 
        return false;
 }