From 158657026122d3b169f1bea12a69ff8eb16bbe04 Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Mon, 6 Jul 2009 11:06:34 +0000 Subject: NLA SoC: More work on Meta-Strips * Added several API functions for Meta-Strips editing. One of these (flush transform) still needs a few tweaks before it does its job well enough for all cases. * Meta strips are now drawn with a purple-ish colour. The start/end points of the strips they encompass are shown with lines along the length of the strips, with lines starting from the top indicating start-points and lines starting from the bottom indicating end-points. * Meta strips can be made (i.e. strips can be assigned to meta-strips) by selecting some strips and pressing Shift-G. Meta strips can be removed by selecting some meta-strips and pressing Alt-G. * Strips can now be 'snapped' to start from: the current frame, the nearest frame, the nearest second, or the nearest marker; using the Shift-S hotkey. 'Islands' of adjacent selected strips occurring in the same track are moved together as a single strip so that the start-point of the first strip is on the sepcified time, but all the relative lengths of strips stay the same. Internally, temporary meta-strips are created to facilitate this. --- source/blender/editors/space_nla/nla_draw.c | 39 ++++++- source/blender/editors/space_nla/nla_edit.c | 148 ++++++++++++++++++++++++-- source/blender/editors/space_nla/nla_header.c | 16 +++ source/blender/editors/space_nla/nla_intern.h | 5 + source/blender/editors/space_nla/nla_ops.c | 12 +++ 5 files changed, 213 insertions(+), 7 deletions(-) (limited to 'source/blender/editors') diff --git a/source/blender/editors/space_nla/nla_draw.c b/source/blender/editors/space_nla/nla_draw.c index ab33434077e..e31aebf0155 100644 --- a/source/blender/editors/space_nla/nla_draw.c +++ b/source/blender/editors/space_nla/nla_draw.c @@ -176,6 +176,23 @@ static void nla_strip_get_color_inside (AnimData *adt, NlaStrip *strip, float co color[2]= 0.19f; } } + else if (strip->type == NLASTRIP_TYPE_META) { + /* Meta Clip */ + if (strip->flag & NLASTRIP_FLAG_SELECT) { + /* selected - use a bold purple color */ + // FIXME: hardcoded temp-hack colors + color[0]= 0.41f; + color[1]= 0.13f; + color[2]= 0.59f; + } + else { + /* normal, unselected strip - use (hardly noticable) dark purple tinge */ + // FIXME: hardcoded temp-hack colors + color[0]= 0.20f; + color[1]= 0.15f; + color[2]= 0.26f; + } + } else { /* Action Clip (default/normal type of strip) */ if ((strip->flag & NLASTRIP_FLAG_ACTIVE) && (adt && (adt->flag & ADT_NLA_EDIT_ON))) { @@ -293,7 +310,7 @@ static void nla_draw_strip (AnimData *adt, NlaTrack *nlt, NlaStrip *strip, View2 /* draw outline */ gl_round_box_shade(GL_LINE_LOOP, strip->start, yminc, strip->end, ymaxc, 0.0, 0.0, 0.1); - /* if action-clip strip, draw lines delimiting repeats too (in the same colour */ + /* if action-clip strip, draw lines delimiting repeats too (in the same color as outline) */ if ((strip->type == NLASTRIP_TYPE_CLIP) && IS_EQ(strip->repeat, 1.0f)==0) { float repeatLen = (strip->actend - strip->actstart) * strip->scale; int i; @@ -309,6 +326,26 @@ static void nla_draw_strip (AnimData *adt, NlaTrack *nlt, NlaStrip *strip, View2 fdrawline(repeatPos, yminc, repeatPos, ymaxc); } } + /* or if meta-strip, draw lines delimiting extents of sub-strips (in same color as outline, if more than 1 exists) */ + else if ((strip->type == NLASTRIP_TYPE_META) && (strip->strips.first != strip->strips.last)) { + NlaStrip *cs; + float y= (ymaxc-yminc)/2.0f + yminc; + + /* only draw first-level of child-strips, but don't draw any lines on the endpoints */ + for (cs= strip->strips.first; cs; cs= cs->next) { + /* draw start-line if not same as end of previous (and only if not the first strip) + * - on upper half of strip + */ + if ((cs->prev) && IS_EQ(cs->prev->end, cs->start)==0) + fdrawline(cs->start, y, cs->start, ymaxc); + + /* draw end-line if not the last strip + * - on lower half of strip + */ + if (cs->next) + fdrawline(cs->end, yminc, cs->end, y); + } + } /* reset linestyle */ setlinestyle(0); diff --git a/source/blender/editors/space_nla/nla_edit.c b/source/blender/editors/space_nla/nla_edit.c index e95d0b1a50a..f7d4db17e2c 100644 --- a/source/blender/editors/space_nla/nla_edit.c +++ b/source/blender/editors/space_nla/nla_edit.c @@ -346,7 +346,6 @@ void NLA_OT_add_actionclip (wmOperatorType *ot) /* ******************** Add Transition Operator ***************************** */ /* Add a new transition strip between selected strips */ -/* add the specified action as new strip */ static int nlaedit_add_transition_exec (bContext *C, wmOperator *op) { bAnimContext ac; @@ -453,6 +452,113 @@ void NLA_OT_add_transition (wmOperatorType *ot) ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } +/* ******************** Add Meta-Strip Operator ***************************** */ +/* Add new meta-strips incorporating the selected strips */ + +/* add the specified action as new strip */ +static int nlaedit_add_meta_exec (bContext *C, wmOperator *op) +{ + bAnimContext ac; + + ListBase anim_data = {NULL, NULL}; + bAnimListElem *ale; + int filter; + + /* get editor data */ + if (ANIM_animdata_get_context(C, &ac) == 0) + return OPERATOR_CANCELLED; + + /* get a list of the editable tracks being shown in the NLA */ + filter= (ANIMFILTER_VISIBLE | ANIMFILTER_NLATRACKS | ANIMFILTER_FOREDIT); + ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); + + /* for each track, find pairs of strips to add transitions to */ + for (ale= anim_data.first; ale; ale= ale->next) { + NlaTrack *nlt= (NlaTrack *)ale->data; + + /* create meta-strips from the continuous chains of selected strips */ + BKE_nlastrips_make_metas(&nlt->strips, 0); + } + + /* free temp data */ + BLI_freelistN(&anim_data); + + /* set notifier that things have changed */ + ANIM_animdata_send_notifiers(C, &ac, ANIM_CHANGED_BOTH); + WM_event_add_notifier(C, NC_SCENE, NULL); + + /* done */ + return OPERATOR_FINISHED; +} + +void NLA_OT_add_meta (wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Add Meta-Strips"; + ot->idname= "NLA_OT_add_meta"; + ot->description= "Add new meta-strips incorporating the selected strips."; + + /* api callbacks */ + ot->exec= nlaedit_add_meta_exec; + ot->poll= nlaop_poll_tweakmode_off; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +/* ******************** Remove Meta-Strip Operator ***************************** */ +/* Separate out the strips held by the selected meta-strips */ + +static int nlaedit_remove_meta_exec (bContext *C, wmOperator *op) +{ + bAnimContext ac; + + ListBase anim_data = {NULL, NULL}; + bAnimListElem *ale; + int filter; + + /* get editor data */ + if (ANIM_animdata_get_context(C, &ac) == 0) + return OPERATOR_CANCELLED; + + /* get a list of the editable tracks being shown in the NLA */ + filter= (ANIMFILTER_VISIBLE | ANIMFILTER_NLATRACKS | ANIMFILTER_FOREDIT); + ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); + + /* for each track, find pairs of strips to add transitions to */ + for (ale= anim_data.first; ale; ale= ale->next) { + NlaTrack *nlt= (NlaTrack *)ale->data; + + /* clear all selected meta-strips, regardless of whether they are temporary or not */ + BKE_nlastrips_clear_metas(&nlt->strips, 1, 0); + } + + /* free temp data */ + BLI_freelistN(&anim_data); + + /* set notifier that things have changed */ + ANIM_animdata_send_notifiers(C, &ac, ANIM_CHANGED_BOTH); + WM_event_add_notifier(C, NC_SCENE, NULL); + + /* done */ + return OPERATOR_FINISHED; +} + +void NLA_OT_remove_meta (wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Remove Meta-Strips"; + ot->idname= "NLA_OT_remove_meta"; + ot->description= "Separate out the strips held by the selected meta-strips."; + + /* api callbacks */ + ot->exec= nlaedit_remove_meta_exec; + ot->poll= nlaop_poll_tweakmode_off; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + /* ******************** Duplicate Strips Operator ************************** */ /* Duplicates the selected NLA-Strips, putting them on new tracks above the one * the originals were housed in. @@ -1047,9 +1153,9 @@ static int nlaedit_snap_exec (bContext *C, wmOperator *op) bAnimListElem *ale; int filter; - Scene *scene= ac.scene; + Scene *scene; int mode = RNA_enum_get(op->ptr, "type"); - const float secf = (float)FPS; + float secf; /* get editor data */ if (ANIM_animdata_get_context(C, &ac) == 0) @@ -1059,17 +1165,28 @@ static int nlaedit_snap_exec (bContext *C, wmOperator *op) filter= (ANIMFILTER_VISIBLE | ANIMFILTER_NLATRACKS | ANIMFILTER_FOREDIT); ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); + /* get some necessary vars */ + scene= ac.scene; + secf= (float)FPS; + /* since we may add tracks, perform this in reverse order */ for (ale= anim_data.last; ale; ale= ale->prev) { ListBase tmp_strips = {NULL, NULL}; + AnimData *adt= BKE_animdata_from_id(ale->id); NlaTrack *nlt= (NlaTrack *)ale->data; NlaStrip *strip, *stripn; + NlaTrack *track; - /* first pass: move all selected strips to a separate buffer, and apply snapping to them */ + /* create meta-strips from the continuous chains of selected strips */ + BKE_nlastrips_make_metas(&nlt->strips, 1); + + /* apply the snapping to all the temp meta-strips, then put them in a separate list to be added + * back to the original only if they still fit + */ for (strip= nlt->strips.first; strip; strip= stripn) { stripn= strip->next; - if (strip->flag & NLASTRIP_FLAG_SELECT) { + if (strip->flag & NLASTRIP_FLAG_TEMP_META) { float start, end; /* get the existing end-points */ @@ -1098,13 +1215,32 @@ static int nlaedit_snap_exec (bContext *C, wmOperator *op) /* get new endpoint based on start-point (and old length) */ strip->end= strip->start + (end - start); + /* apply transforms to meta-strip to its children */ + BKE_nlameta_flush_transforms(strip); + /* remove strip from track, and add to the temp buffer */ BLI_remlink(&nlt->strips, strip); BLI_addtail(&tmp_strips, strip); } } - // TODO: finish this... + /* try adding each meta-strip back to the track one at a time, to make sure they'll fit */ + for (strip= tmp_strips.first; strip; strip= stripn) { + stripn= strip->next; + + /* remove from temp-strips list */ + BLI_remlink(&tmp_strips, strip); + + /* in case there's no space in the current track, try adding */ + if (BKE_nlatrack_add_strip(nlt, strip) == 0) { + /* need to add a new track above the current one */ + track= add_nlatrack(adt, nlt); + BKE_nlatrack_add_strip(track, strip); + } + } + + /* remove the meta-strips now that we're done */ + BKE_nlastrips_clear_metas(&nlt->strips, 0, 1); } /* free temp data */ diff --git a/source/blender/editors/space_nla/nla_header.c b/source/blender/editors/space_nla/nla_header.c index fc6db76ba65..9b9b21629cc 100644 --- a/source/blender/editors/space_nla/nla_header.c +++ b/source/blender/editors/space_nla/nla_header.c @@ -70,6 +70,8 @@ #include "ED_markers.h" +#include "nla_intern.h" + /* button events */ enum { B_REDR = 0, @@ -142,9 +144,18 @@ static void nla_edit_transformmenu(bContext *C, uiLayout *layout, void *arg_unus uiItemEnumO(layout, "Scale", 0, "TFM_OT_transform", "mode", TFM_TIME_SCALE); } +static void nla_edit_snapmenu(bContext *C, uiLayout *layout, void *arg_unused) +{ + uiItemEnumO(layout, NULL, 0, "NLA_OT_snap", "type", NLAEDIT_SNAP_CFRA); + uiItemEnumO(layout, NULL, 0, "NLA_OT_snap", "type", NLAEDIT_SNAP_NEAREST_FRAME); + uiItemEnumO(layout, NULL, 0, "NLA_OT_snap", "type", NLAEDIT_SNAP_NEAREST_SECOND); + uiItemEnumO(layout, NULL, 0, "NLA_OT_snap", "type", NLAEDIT_SNAP_NEAREST_MARKER); +} + static void nla_editmenu(bContext *C, uiLayout *layout, void *arg_unused) { uiItemMenuF(layout, "Transform", 0, nla_edit_transformmenu); + uiItemMenuF(layout, "Snap", 0, nla_edit_snapmenu); uiItemS(layout); @@ -173,6 +184,11 @@ static void nla_addmenu(bContext *C, uiLayout *layout, void *arg_unused) uiItemS(layout); + uiItemO(layout, NULL, 0, "NLA_OT_add_meta"); + uiItemO(layout, NULL, 0, "NLA_OT_remove_meta"); + + uiItemS(layout); + uiItemO(layout, NULL, 0, "NLA_OT_add_tracks"); uiItemBooleanO(layout, "Add Tracks Above Selected", 0, "NLA_OT_add_tracks", "above_selected", 1); } diff --git a/source/blender/editors/space_nla/nla_intern.h b/source/blender/editors/space_nla/nla_intern.h index 422686bb424..4391a019207 100644 --- a/source/blender/editors/space_nla/nla_intern.h +++ b/source/blender/editors/space_nla/nla_intern.h @@ -106,6 +106,9 @@ void NLA_OT_tweakmode_exit(wmOperatorType *ot); void NLA_OT_add_actionclip(wmOperatorType *ot); void NLA_OT_add_transition(wmOperatorType *ot); +void NLA_OT_add_meta(wmOperatorType *ot); +void NLA_OT_remove_meta(wmOperatorType *ot); + void NLA_OT_duplicate(wmOperatorType *ot); void NLA_OT_delete(wmOperatorType *ot); void NLA_OT_split(wmOperatorType *ot); @@ -116,6 +119,8 @@ void NLA_OT_move_down(wmOperatorType *ot); void NLA_OT_apply_scale(wmOperatorType *ot); void NLA_OT_clear_scale(wmOperatorType *ot); +void NLA_OT_snap(wmOperatorType *ot); + void NLA_OT_fmodifier_add(wmOperatorType *ot); diff --git a/source/blender/editors/space_nla/nla_ops.c b/source/blender/editors/space_nla/nla_ops.c index 7caab02d6a0..25fd8db668c 100644 --- a/source/blender/editors/space_nla/nla_ops.c +++ b/source/blender/editors/space_nla/nla_ops.c @@ -146,6 +146,9 @@ void nla_operatortypes(void) WM_operatortype_append(NLA_OT_add_actionclip); WM_operatortype_append(NLA_OT_add_transition); + WM_operatortype_append(NLA_OT_add_meta); + WM_operatortype_append(NLA_OT_remove_meta); + WM_operatortype_append(NLA_OT_duplicate); WM_operatortype_append(NLA_OT_delete); WM_operatortype_append(NLA_OT_split); @@ -156,6 +159,8 @@ void nla_operatortypes(void) WM_operatortype_append(NLA_OT_apply_scale); WM_operatortype_append(NLA_OT_clear_scale); + WM_operatortype_append(NLA_OT_snap); + WM_operatortype_append(NLA_OT_fmodifier_add); } @@ -236,6 +241,10 @@ static void nla_keymap_main (wmWindowManager *wm, ListBase *keymap) /* add strips */ WM_keymap_add_item(keymap, "NLA_OT_add_actionclip", AKEY, KM_PRESS, KM_SHIFT, 0); WM_keymap_add_item(keymap, "NLA_OT_add_transition", TKEY, KM_PRESS, KM_SHIFT, 0); + + /* meta-strips */ + WM_keymap_add_item(keymap, "NLA_OT_add_meta", GKEY, KM_PRESS, KM_SHIFT, 0); + WM_keymap_add_item(keymap, "NLA_OT_remove_meta", GKEY, KM_PRESS, KM_ALT, 0); /* duplicate */ WM_keymap_add_item(keymap, "NLA_OT_duplicate", DKEY, KM_PRESS, KM_SHIFT, 0); @@ -257,6 +266,9 @@ static void nla_keymap_main (wmWindowManager *wm, ListBase *keymap) /* clear scale */ WM_keymap_add_item(keymap, "NLA_OT_clear_scale", SKEY, KM_PRESS, KM_ALT, 0); + /* snap */ + WM_keymap_add_item(keymap, "NLA_OT_snap", SKEY, KM_PRESS, KM_SHIFT, 0); + /* add f-modifier */ WM_keymap_add_item(keymap, "NLA_OT_fmodifier_add", MKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0); -- cgit v1.2.3