From 2ef68edad8b9832d55c185d4db948417e74ae8c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 24 Sep 2020 18:22:30 +0200 Subject: Cleanup: animation, deduplicate "can edit action" logic Move "action editable" check from RNA code to Blender kernel `BKE_animdata_action_editable()`. No functional changes. --- source/blender/blenkernel/intern/anim_data.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'source/blender/blenkernel/intern/anim_data.c') diff --git a/source/blender/blenkernel/intern/anim_data.c b/source/blender/blenkernel/intern/anim_data.c index 24908469a77..30b75734e77 100644 --- a/source/blender/blenkernel/intern/anim_data.c +++ b/source/blender/blenkernel/intern/anim_data.c @@ -180,17 +180,14 @@ bool BKE_animdata_set_action(ReportList *reports, ID *id, bAction *act) { AnimData *adt = BKE_animdata_from_id(id); - /* animdata validity check */ + /* Animdata validity check. */ if (adt == NULL) { BKE_report(reports, RPT_WARNING, "No AnimData to set action on"); return false; } - /* active action is only editable when it is not a tweaking strip - * see rna_AnimData_action_editable() in rna_animation.c - */ - if ((adt->flag & ADT_NLA_EDIT_ON) || (adt->actstrip) || (adt->tmpact)) { - /* cannot remove, otherwise things turn to custard */ + if (!BKE_animdata_action_editable(adt)) { + /* Cannot remove, otherwise things turn to custard. */ BKE_report(reports, RPT_ERROR, "Cannot change action, as it is still being edited in NLA"); return false; } @@ -200,8 +197,6 @@ bool BKE_animdata_set_action(ReportList *reports, ID *id, bAction *act) id_us_min((ID *)adt->action); } - /* Assume that AnimData's action can in fact be edited. */ - if (act == NULL) { /* Just clearing the action. */ adt->action = NULL; @@ -227,6 +222,14 @@ bool BKE_animdata_set_action(ReportList *reports, ID *id, bAction *act) return true; } +bool BKE_animdata_action_editable(const AnimData *adt) +{ + /* Active action is only editable when it is not a tweaking strip. */ + const bool is_tweaking_strip = (adt->flag & ADT_NLA_EDIT_ON) || adt->actstrip != NULL || + adt->tmpact != NULL; + return !is_tweaking_strip; +} + /* Freeing -------------------------------------------- */ /* Free AnimData used by the nominated ID-block, and clear ID-block's AnimData pointer */ -- cgit v1.2.3