diff options
author | Joshua Leung <aligorith@gmail.com> | 2014-04-28 16:07:15 +0400 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2014-04-28 17:59:41 +0400 |
commit | 68c3b6350ad702195a86adfcde65687269820afd (patch) | |
tree | 468a0b3537cde7a18f7526b0ceed7ff0ae99d36e | |
parent | 27db75363e67f1da272fc9e4ca340e4eb8bf77d1 (diff) |
NLA Editor: Duplicate/Duplicate Linked
This commit changes the default strip duplication behaviour (Shift-D) so that it will
create a copy of whatever action it uses. Previously, it was very hard, if not impossible
in some cases to create a new copy of an action to start working on in the NLA.
If you want the old behaviour, you'll need to use ALt-D (Linked Duplicates).
(Note: Although the new Shift-D may not be so optimal in all cases, I've decided to go
with this version since it aligns better with the way this works for objects. Doing the
opposite for NLA would just have added to the confusion)
-rw-r--r-- | release/scripts/startup/bl_ui/space_nla.py | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_nla.h | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/nla.c | 29 | ||||
-rw-r--r-- | source/blender/editors/space_nla/nla_edit.c | 10 | ||||
-rw-r--r-- | source/blender/editors/space_nla/nla_ops.c | 6 |
5 files changed, 36 insertions, 16 deletions
diff --git a/release/scripts/startup/bl_ui/space_nla.py b/release/scripts/startup/bl_ui/space_nla.py index a07d2021243..ae5d308b0d3 100644 --- a/release/scripts/startup/bl_ui/space_nla.py +++ b/release/scripts/startup/bl_ui/space_nla.py @@ -133,7 +133,8 @@ class NLA_MT_edit(Menu): layout.operator_menu_enum("nla.snap", "type", text="Snap") layout.separator() - layout.operator("nla.duplicate") + layout.operator("nla.duplicate", text="Duplicate") + layout.operator("nla.duplicate", text="Linked Duplicate").linked = True layout.operator("nla.split") layout.operator("nla.delete") diff --git a/source/blender/blenkernel/BKE_nla.h b/source/blender/blenkernel/BKE_nla.h index 7823efc3bae..0c29179aa1c 100644 --- a/source/blender/blenkernel/BKE_nla.h +++ b/source/blender/blenkernel/BKE_nla.h @@ -47,8 +47,8 @@ void free_nlastrip(ListBase *strips, struct NlaStrip *strip); void free_nlatrack(ListBase *tracks, struct NlaTrack *nlt); void free_nladata(ListBase *tracks); -struct NlaStrip *copy_nlastrip(struct NlaStrip *strip); -struct NlaTrack *copy_nlatrack(struct NlaTrack *nlt); +struct NlaStrip *copy_nlastrip(struct NlaStrip *strip, const bool use_same_action); +struct NlaTrack *copy_nlatrack(struct NlaTrack *nlt, const bool use_same_actions); void copy_nladata(ListBase *dst, ListBase *src); struct NlaTrack *add_nlatrack(struct AnimData *adt, struct NlaTrack *prev); diff --git a/source/blender/blenkernel/intern/nla.c b/source/blender/blenkernel/intern/nla.c index d251a8599b1..0c244e8a40b 100644 --- a/source/blender/blenkernel/intern/nla.c +++ b/source/blender/blenkernel/intern/nla.c @@ -157,8 +157,10 @@ void free_nladata(ListBase *tracks) /* Copying ------------------------------------------- */ -/* Copy NLA strip */ -NlaStrip *copy_nlastrip(NlaStrip *strip) +/* Copy NLA strip + * < use_same_action: if true, the existing action is used (instead of being duplicated) + */ +NlaStrip *copy_nlastrip(NlaStrip *strip, const bool use_same_action) { NlaStrip *strip_d; NlaStrip *cs, *cs_d; @@ -171,9 +173,17 @@ NlaStrip *copy_nlastrip(NlaStrip *strip) strip_d = MEM_dupallocN(strip); strip_d->next = strip_d->prev = NULL; - /* increase user-count of action */ - if (strip_d->act) - id_us_plus(&strip_d->act->id); + /* handle action */ + if (strip_d->act) { + if (use_same_action) { + /* increase user-count of action */ + id_us_plus(&strip_d->act->id); + } + else { + /* use a copy of the action instead (user count shouldn't have changed yet) */ + strip_d->act = BKE_action_copy(strip_d->act); + } + } /* copy F-Curves and modifiers */ copy_fcurves(&strip_d->fcurves, &strip->fcurves); @@ -183,7 +193,7 @@ NlaStrip *copy_nlastrip(NlaStrip *strip) BLI_listbase_clear(&strip_d->strips); for (cs = strip->strips.first; cs; cs = cs->next) { - cs_d = copy_nlastrip(cs); + cs_d = copy_nlastrip(cs, use_same_action); BLI_addtail(&strip_d->strips, cs_d); } @@ -192,7 +202,7 @@ NlaStrip *copy_nlastrip(NlaStrip *strip) } /* Copy NLA Track */ -NlaTrack *copy_nlatrack(NlaTrack *nlt) +NlaTrack *copy_nlatrack(NlaTrack *nlt, const bool use_same_actions) { NlaStrip *strip, *strip_d; NlaTrack *nlt_d; @@ -209,7 +219,7 @@ NlaTrack *copy_nlatrack(NlaTrack *nlt) BLI_listbase_clear(&nlt_d->strips); for (strip = nlt->strips.first; strip; strip = strip->next) { - strip_d = copy_nlastrip(strip); + strip_d = copy_nlastrip(strip, use_same_actions); BLI_addtail(&nlt_d->strips, strip_d); } @@ -232,7 +242,8 @@ void copy_nladata(ListBase *dst, ListBase *src) /* copy each NLA-track, one at a time */ for (nlt = src->first; nlt; nlt = nlt->next) { /* make a copy, and add the copy to the destination list */ - nlt_d = copy_nlatrack(nlt); + // XXX: we need to fix this sometime + nlt_d = copy_nlatrack(nlt, true); BLI_addtail(dst, nlt_d); } } diff --git a/source/blender/editors/space_nla/nla_edit.c b/source/blender/editors/space_nla/nla_edit.c index 8221fb0199b..bb1e0e4245f 100644 --- a/source/blender/editors/space_nla/nla_edit.c +++ b/source/blender/editors/space_nla/nla_edit.c @@ -887,7 +887,7 @@ void NLA_OT_meta_remove(wmOperatorType *ot) * the originals were housed in. */ -static int nlaedit_duplicate_exec(bContext *C, wmOperator *UNUSED(op)) +static int nlaedit_duplicate_exec(bContext *C, wmOperator *op) { bAnimContext ac; @@ -895,6 +895,7 @@ static int nlaedit_duplicate_exec(bContext *C, wmOperator *UNUSED(op)) bAnimListElem *ale; int filter; + bool linked = RNA_boolean_get(op->ptr, "linked"); bool done = false; /* get editor data */ @@ -920,7 +921,7 @@ static int nlaedit_duplicate_exec(bContext *C, wmOperator *UNUSED(op)) /* if selected, split the strip at its midpoint */ if (strip->flag & NLASTRIP_FLAG_SELECT) { /* make a copy (assume that this is possible) */ - nstrip = copy_nlastrip(strip); + nstrip = copy_nlastrip(strip, linked); /* in case there's no space in the track above, or we haven't got a reference to it yet, try adding */ if (BKE_nlatrack_add_strip(nlt->next, nstrip) == 0) { @@ -985,6 +986,9 @@ void NLA_OT_duplicate(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* own properties */ + ot->prop = RNA_def_boolean(ot->srna, "linked", false, "Linked", "When duplicating strips, assign new copies of the actions they use"); + /* to give to transform */ RNA_def_enum(ot->srna, "mode", transform_mode_types, TFM_TRANSLATION, "Mode", ""); } @@ -1102,7 +1106,7 @@ static void nlaedit_split_strip_actclip(AnimData *adt, NlaTrack *nlt, NlaStrip * /* make a copy (assume that this is possible) and append * it immediately after the current strip */ - nstrip = copy_nlastrip(strip); + nstrip = copy_nlastrip(strip, true); BLI_insertlinkafter(&nlt->strips, strip, nstrip); /* set the endpoint of the first strip and the start of the new strip diff --git a/source/blender/editors/space_nla/nla_ops.c b/source/blender/editors/space_nla/nla_ops.c index 373879a278b..9dc598bc382 100644 --- a/source/blender/editors/space_nla/nla_ops.c +++ b/source/blender/editors/space_nla/nla_ops.c @@ -256,7 +256,11 @@ static void nla_keymap_main(wmKeyConfig *keyconf, wmKeyMap *keymap) WM_keymap_add_item(keymap, "NLA_OT_meta_remove", GKEY, KM_PRESS, KM_ALT, 0); /* duplicate */ - WM_keymap_add_item(keymap, "NLA_OT_duplicate", DKEY, KM_PRESS, KM_SHIFT, 0); + kmi = WM_keymap_add_item(keymap, "NLA_OT_duplicate", DKEY, KM_PRESS, KM_SHIFT, 0); + RNA_boolean_set(kmi->ptr, "linked", false); + + kmi = WM_keymap_add_item(keymap, "NLA_OT_duplicate", DKEY, KM_PRESS, KM_ALT, 0); + RNA_boolean_set(kmi->ptr, "linked", true); /* delete */ WM_keymap_add_item(keymap, "NLA_OT_delete", XKEY, KM_PRESS, 0, 0); |