diff options
author | Joshua Leung <aligorith@gmail.com> | 2009-06-27 17:00:22 +0400 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2009-06-27 17:00:22 +0400 |
commit | bc0cd9607e1e2d25f92216332d73c23ef1e7c786 (patch) | |
tree | 0e31f3bbd0c1e3099c372ff2935d14bcdeeec863 /source/blender/editors | |
parent | d3557fc487bc5e5c02c9758b6a05200575e82e84 (diff) |
NLA SoC: Move Strips Up/Down Operators
These operators may be temporary only, depending on if a workable solution via transform is found.
* PageUp moves strips into the track above if there's space
* PageDown moves strips into the track below if there's space
* Also fixed a button-alignment bug in the DopeSheet header
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/space_action/action_header.c | 3 | ||||
-rw-r--r-- | source/blender/editors/space_nla/nla_edit.c | 154 | ||||
-rw-r--r-- | source/blender/editors/space_nla/nla_header.c | 5 | ||||
-rw-r--r-- | source/blender/editors/space_nla/nla_intern.h | 3 | ||||
-rw-r--r-- | source/blender/editors/space_nla/nla_ops.c | 9 |
5 files changed, 173 insertions, 1 deletions
diff --git a/source/blender/editors/space_action/action_header.c b/source/blender/editors/space_action/action_header.c index a9ce145088d..62e7a2d8e3f 100644 --- a/source/blender/editors/space_action/action_header.c +++ b/source/blender/editors/space_action/action_header.c @@ -398,7 +398,8 @@ void action_header_buttons(const bContext *C, ARegion *ar) /* COPY PASTE */ uiBlockBeginAlign(block); uiDefIconButO(block, BUT, "ACT_OT_copy", WM_OP_INVOKE_REGION_WIN, ICON_COPYDOWN, xco,yco,XIC,YIC, "Copies the selected keyframes to the buffer."); - uiDefIconButO(block, BUT, "ACT_OT_paste", WM_OP_INVOKE_REGION_WIN, ICON_COPYDOWN, xco,yco,XIC,YIC, "Pastes the keyframes from the buffer into the selected channels."); + xco += XIC; + uiDefIconButO(block, BUT, "ACT_OT_paste", WM_OP_INVOKE_REGION_WIN, ICON_PASTEDOWN, xco,yco,XIC,YIC, "Pastes the keyframes from the buffer into the selected channels."); uiBlockEndAlign(block); xco += (XIC + 8); diff --git a/source/blender/editors/space_nla/nla_edit.c b/source/blender/editors/space_nla/nla_edit.c index 44528714732..efde2d0b537 100644 --- a/source/blender/editors/space_nla/nla_edit.c +++ b/source/blender/editors/space_nla/nla_edit.c @@ -706,6 +706,160 @@ void NLAEDIT_OT_split (wmOperatorType *ot) /* *********************************************** */ /* NLA Editing Operations (Modifying) */ +/* ******************** Move Strips Up Operator ************************** */ +/* Tries to move the selected strips into the track above if possible. */ + +static int nlaedit_move_up_exec (bContext *C, wmOperator *op) +{ + bAnimContext ac; + + ListBase anim_data = {NULL, NULL}; + bAnimListElem *ale; + int filter; + + BeztEditData bed; + + /* 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); + + /* init the editing data */ + memset(&bed, 0, sizeof(BeztEditData)); + + /* since we're potentially moving strips from lower tracks to higher tracks, we should + * loop over the tracks in reverse order to avoid moving earlier strips up multiple tracks + */ + for (ale= anim_data.last; ale; ale= ale->prev) { + NlaTrack *nlt= (NlaTrack *)ale->data; + NlaTrack *nltn= nlt->next; + NlaStrip *strip, *stripn; + + /* if this track has no tracks after it, skip for now... */ + if (nltn == NULL) + continue; + + /* for every selected strip, try to move */ + for (strip= nlt->strips.first; strip; strip= stripn) { + stripn= strip->next; + + if (strip->flag & NLASTRIP_FLAG_SELECT) { + /* check if the track above has room for this strip */ + if (BKE_nlatrack_has_space(nltn, strip->start, strip->end)) { + /* remove from its current track, and add to the one above (it 'should' work, so no need to worry) */ + BLI_remlink(&nlt->strips, strip); + BKE_nlatrack_add_strip(nltn, strip); + } + } + } + } + + /* 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 NLAEDIT_OT_move_up (wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Move Strips Up"; + ot->idname= "NLAEDIT_OT_move_up"; + ot->description= "Move selected strips up a track if there's room."; + + /* api callbacks */ + ot->exec= nlaedit_move_up_exec; + ot->poll= nlaop_poll_tweakmode_off; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +/* ******************** Move Strips Down Operator ************************** */ +/* Tries to move the selected strips into the track above if possible. */ + +static int nlaedit_move_down_exec (bContext *C, wmOperator *op) +{ + bAnimContext ac; + + ListBase anim_data = {NULL, NULL}; + bAnimListElem *ale; + int filter; + + BeztEditData bed; + + /* 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); + + /* init the editing data */ + memset(&bed, 0, sizeof(BeztEditData)); + + /* loop through the tracks in normal order, since we're pushing strips down, + * strips won't get operated on twice + */ + for (ale= anim_data.first; ale; ale= ale->next) { + NlaTrack *nlt= (NlaTrack *)ale->data; + NlaTrack *nltp= nlt->prev; + NlaStrip *strip, *stripn; + + /* if this track has no tracks before it, skip for now... */ + if (nltp == NULL) + continue; + + /* for every selected strip, try to move */ + for (strip= nlt->strips.first; strip; strip= stripn) { + stripn= strip->next; + + if (strip->flag & NLASTRIP_FLAG_SELECT) { + /* check if the track below has room for this strip */ + if (BKE_nlatrack_has_space(nltp, strip->start, strip->end)) { + /* remove from its current track, and add to the one above (it 'should' work, so no need to worry) */ + BLI_remlink(&nlt->strips, strip); + BKE_nlatrack_add_strip(nltp, strip); + } + } + } + } + + /* 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 NLAEDIT_OT_move_down (wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Move Strips Down"; + ot->idname= "NLAEDIT_OT_move_down"; + ot->description= "Move selected strips down a track if there's room."; + + /* api callbacks */ + ot->exec= nlaedit_move_down_exec; + ot->poll= nlaop_poll_tweakmode_off; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + /* ******************** Apply Scale Operator ***************************** */ /* Reset the scaling of the selected strips to 1.0f */ diff --git a/source/blender/editors/space_nla/nla_header.c b/source/blender/editors/space_nla/nla_header.c index 11dfc5575b1..939e886abeb 100644 --- a/source/blender/editors/space_nla/nla_header.c +++ b/source/blender/editors/space_nla/nla_header.c @@ -159,6 +159,11 @@ static void nla_editmenu(bContext *C, uiLayout *layout, void *arg_unused) uiItemO(layout, NULL, 0, "NLAEDIT_OT_apply_scale"); uiItemO(layout, NULL, 0, "NLAEDIT_OT_clear_scale"); + + uiItemS(layout); + + uiItemO(layout, NULL, 0, "NLAEDIT_OT_move_up"); + uiItemO(layout, NULL, 0, "NLAEDIT_OT_move_down"); } static void nla_addmenu(bContext *C, uiLayout *layout, void *arg_unused) diff --git a/source/blender/editors/space_nla/nla_intern.h b/source/blender/editors/space_nla/nla_intern.h index 17fad5db47f..7056139d734 100644 --- a/source/blender/editors/space_nla/nla_intern.h +++ b/source/blender/editors/space_nla/nla_intern.h @@ -99,6 +99,9 @@ void NLAEDIT_OT_duplicate(wmOperatorType *ot); void NLAEDIT_OT_delete(wmOperatorType *ot); void NLAEDIT_OT_split(wmOperatorType *ot); +void NLAEDIT_OT_move_up(wmOperatorType *ot); +void NLAEDIT_OT_move_down(wmOperatorType *ot); + void NLAEDIT_OT_apply_scale(wmOperatorType *ot); void NLAEDIT_OT_clear_scale(wmOperatorType *ot); diff --git a/source/blender/editors/space_nla/nla_ops.c b/source/blender/editors/space_nla/nla_ops.c index 531e049d29a..35db79a0b38 100644 --- a/source/blender/editors/space_nla/nla_ops.c +++ b/source/blender/editors/space_nla/nla_ops.c @@ -150,6 +150,9 @@ void nla_operatortypes(void) WM_operatortype_append(NLAEDIT_OT_delete); WM_operatortype_append(NLAEDIT_OT_split); + WM_operatortype_append(NLAEDIT_OT_move_up); + WM_operatortype_append(NLAEDIT_OT_move_down); + WM_operatortype_append(NLAEDIT_OT_apply_scale); WM_operatortype_append(NLAEDIT_OT_clear_scale); } @@ -242,8 +245,14 @@ static void nla_keymap_main (wmWindowManager *wm, ListBase *keymap) /* split */ WM_keymap_add_item(keymap, "NLAEDIT_OT_split", YKEY, KM_PRESS, 0, 0); + /* move up */ + WM_keymap_add_item(keymap, "NLAEDIT_OT_move_up", PAGEUPKEY, KM_PRESS, 0, 0); + /* move down */ + WM_keymap_add_item(keymap, "NLAEDIT_OT_move_down", PAGEDOWNKEY, KM_PRESS, 0, 0); + /* apply scale */ WM_keymap_add_item(keymap, "NLAEDIT_OT_apply_scale", AKEY, KM_PRESS, KM_CTRL, 0); + /* clear scale */ WM_keymap_add_item(keymap, "NLAEDIT_OT_clear_scale", SKEY, KM_PRESS, KM_ALT, 0); /* transform system */ |