From bff2dcc6d87e6fac87c787979faff82aa5546648 Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Fri, 12 Jan 2007 02:34:47 +0000 Subject: [PATCH] == NLA Editor == Minor workflow tweak - Add New Empty Action as New Action Strip. Hotkey: Shift N. Menu Entry: 'Strip' menu Creates a new action, and adds it as an action strip at the bottom of the list nla-strips for an object. Useful for creating additional strips to correct poses of prior strips. --- source/blender/include/BIF_editnla.h | 1 + source/blender/src/editnla.c | 131 ++++++++++++++++----------- source/blender/src/header_nla.c | 7 +- 3 files changed, 84 insertions(+), 55 deletions(-) diff --git a/source/blender/include/BIF_editnla.h b/source/blender/include/BIF_editnla.h index bc6ea8b9752..f12a313b903 100644 --- a/source/blender/include/BIF_editnla.h +++ b/source/blender/include/BIF_editnla.h @@ -54,6 +54,7 @@ void reset_action_strips(int val); void synchronize_action_strips(void); void snap_action_strips(int snap_mode); void add_nlablock(void); +void add_empty_nlablock(void); void convert_nla(void); void copy_action_modifiers(void); diff --git a/source/blender/src/editnla.c b/source/blender/src/editnla.c index eeb9436a21b..1684cbf6883 100644 --- a/source/blender/src/editnla.c +++ b/source/blender/src/editnla.c @@ -382,6 +382,60 @@ static void add_nla_block(short event) BIF_undo_push("Add NLA strip"); } +static void add_nla_block_by_name(char name[32], Object *ob, short hold, short add, float repeat) +{ + bAction *act=NULL; + bActionStrip *strip; + int cur; + + if (name){ + for (cur = 1, act=G.main->action.first; act; act=act->id.next, cur++){ + if (strcmp(name,act->id.name)==0) { + break; + } + } + } + + /* Bail out if no action was chosen */ + if (!act){ + return; + } + + /* Initialize the new action block */ + strip = MEM_callocN(sizeof(bActionStrip), "bActionStrip"); + + deselect_nlachannel_keys(0); + + /* Link the action to the strip */ + strip->act = act; + calc_action_range(strip->act, &strip->actstart, &strip->actend, 1); + strip->start = G.scene->r.cfra; /* could be mval[0] another time... */ + strip->end = strip->start + (strip->actend-strip->actstart); + /* simple prevention of zero strips */ + if(strip->start>strip->end-2) + strip->end= strip->start+100; + + strip->flag = ACTSTRIP_SELECT|ACTSTRIP_LOCK_ACTION; //|ACTSTRIP_USEMATCH; + + if (hold==1) + strip->flag = strip->flag|ACTSTRIP_HOLDLASTFRAME; + + if (add==1) + strip->mode = ACTSTRIPMODE_ADD; + + find_stridechannel(ob, strip); + + set_active_strip(ob, strip); + + strip->repeat = repeat; + + act->id.us++; + + BLI_addtail(&ob->nlastrips, strip); + + BIF_undo_push("Add NLA strip"); +} + static void add_nla_databrowse_callback(unsigned short val) { /* val is not used, databrowse needs it to optional pass an event */ @@ -427,6 +481,26 @@ void add_nlablock(void) } } +/* Creates a new action, and makes a new actionstrip of that */ +void add_empty_nlablock(void) +{ + Object *ob= OBACT; + bAction *act= NULL; + + /* check for active object first - will add strip to active object */ + if (ob == NULL) + return; + + /* make new action */ + if ((ob->type == OB_ARMATURE) && (ob->flag & OB_POSEMODE)) + act= add_empty_action(ID_AR); + else + act= add_empty_action(ID_OB); + + /* make a new strip for it */ + add_nla_block_by_name(act->id.name, ob, 0, 1, 1.0f); +} + /* Adds strip to to active Object */ static void relink_active_strip(void) { @@ -1811,6 +1885,9 @@ void winqreadnlaspace(ScrArea *sa, void *spacedata, BWinEvent *evt) toggle_blockhandler(curarea, NLA_HANDLER_PROPERTIES, UI_PNL_TO_MOUSE); scrarea_queue_winredraw(curarea); } + else if (G.qual & LR_SHIFTKEY) { + add_empty_nlablock(); + } break; case LKEY: relink_active_strip(); @@ -1916,60 +1993,6 @@ void winqreadnlaspace(ScrArea *sa, void *spacedata, BWinEvent *evt) if(doredraw) scrarea_queue_winredraw(curarea); } -static void add_nla_block_by_name(char name[32], Object *ob, short hold, short add, float repeat) -{ - bAction *act=NULL; - bActionStrip *strip; - int cur; - - if (name){ - for (cur = 1, act=G.main->action.first; act; act=act->id.next, cur++){ - if (strcmp(name,act->id.name)==0) { - break; - } - } - } - - /* Bail out if no action was chosen */ - if (!act){ - return; - } - - /* Initialize the new action block */ - strip = MEM_callocN(sizeof(bActionStrip), "bActionStrip"); - - deselect_nlachannel_keys(0); - - /* Link the action to the strip */ - strip->act = act; - calc_action_range(strip->act, &strip->actstart, &strip->actend, 1); - strip->start = G.scene->r.cfra; /* could be mval[0] another time... */ - strip->end = strip->start + (strip->actend-strip->actstart); - /* simple prevention of zero strips */ - if(strip->start>strip->end-2) - strip->end= strip->start+100; - - strip->flag = ACTSTRIP_SELECT|ACTSTRIP_LOCK_ACTION; //|ACTSTRIP_USEMATCH; - - if (hold==1) - strip->flag = strip->flag|ACTSTRIP_HOLDLASTFRAME; - - if (add==1) - strip->mode = ACTSTRIPMODE_ADD; - - find_stridechannel(ob, strip); - - set_active_strip(ob, strip); - - strip->repeat = repeat; - - act->id.us++; - - BLI_addtail(&ob->nlastrips, strip); - - BIF_undo_push("Add NLA strip"); -} - void bake_all_to_action(void) { Object *ob; diff --git a/source/blender/src/header_nla.c b/source/blender/src/header_nla.c index c14fea48dc6..2d33ee098de 100644 --- a/source/blender/src/header_nla.c +++ b/source/blender/src/header_nla.c @@ -318,6 +318,9 @@ static void do_nla_stripmenu(void *arg, int event) case 9: /* reset start/end of action */ reset_action_strips(2); break; + case 10: /* add new action as new action strip */ + add_empty_nlablock(); + break; } } @@ -331,13 +334,15 @@ static uiBlock *nla_stripmenu(void *arg_unused) uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Strip Properties...|N", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, ""); uiDefIconTextBlockBut(block, nla_strip_transformmenu, NULL, ICON_RIGHTARROW_THIN, "Transform", 0, yco-=20, 120, 20, ""); + uiDefIconTextBlockBut(block, nla_strip_snapmenu, NULL, ICON_RIGHTARROW_THIN, "Snap To Frame", 0, yco-=20, 120, 20, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Reset Strip Size|Alt S", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 8, ""); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Reset Action Start/End|Alt S", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 9, ""); - uiDefIconTextBlockBut(block, nla_strip_snapmenu, NULL, ICON_RIGHTARROW_THIN, "Snap To Frame", 0, yco-=20, 120, 20, ""); uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Add Action Strip|Shift A", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Add Blank Action Strip|Shift N", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 10, ""); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Convert Action to NLA Strip|C", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 5, ""); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Duplicate|Shift D", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, "");