Bugfix T41525: Button keyframe indicators don't work correctly when editing NLA Strips

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.
This commit is contained in:
Joshua Leung 2014-11-16 20:24:38 +13:00
parent 65d771dcaf
commit 2625dc5348
Notes: blender-bot 2023-02-14 10:11:45 +01:00
Referenced by issue #41525, Wrong keyframe color indicators when editing NLA strips
6 changed files with 38 additions and 16 deletions

View 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)

View 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;
}

View 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;
}

View 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"
@ -55,28 +56,37 @@
#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;

View 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;

View 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;
}