diff options
author | Joshua Leung <aligorith@gmail.com> | 2014-04-28 11:33:28 +0400 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2014-04-28 11:34:02 +0400 |
commit | b40b6bd48d5c7f8cc4057b7355462e0bb198e987 (patch) | |
tree | 841b87d71014556f87f3395b4cacafee8745e7d0 | |
parent | 1cd4a884233a38cecfe6e2aa42d87842ab008a93 (diff) |
NLA Editor: Added an operator to set preview range based on the extents of selected strips
This brings it more in line with the other anim editors, and makes like a little
bit easier for animators working on games or looping anims.
-rw-r--r-- | release/scripts/startup/bl_ui/space_nla.py | 1 | ||||
-rw-r--r-- | source/blender/editors/space_nla/nla_edit.c | 57 | ||||
-rw-r--r-- | source/blender/editors/space_nla/nla_intern.h | 2 | ||||
-rw-r--r-- | source/blender/editors/space_nla/nla_ops.c | 5 |
4 files changed, 60 insertions, 5 deletions
diff --git a/release/scripts/startup/bl_ui/space_nla.py b/release/scripts/startup/bl_ui/space_nla.py index e41086f6da1..2a32e7b064c 100644 --- a/release/scripts/startup/bl_ui/space_nla.py +++ b/release/scripts/startup/bl_ui/space_nla.py @@ -80,6 +80,7 @@ class NLA_MT_view(Menu): layout.separator() layout.operator("anim.previewrange_set") layout.operator("anim.previewrange_clear") + layout.operator("nla.previewrange_clear") layout.separator() layout.operator("nla.view_all") diff --git a/source/blender/editors/space_nla/nla_edit.c b/source/blender/editors/space_nla/nla_edit.c index 10fc8e507af..8221fb0199b 100644 --- a/source/blender/editors/space_nla/nla_edit.c +++ b/source/blender/editors/space_nla/nla_edit.c @@ -257,11 +257,12 @@ void NLA_OT_tweakmode_exit(wmOperatorType *ot) /* *************************** Calculate Range ************************** */ /* Get the min/max strip extents */ -static void get_nlastrip_extents(bAnimContext *ac, float *min, float *max, const bool onlySel) +static void get_nlastrip_extents(bAnimContext *ac, float *min, float *max, const bool only_sel) { ListBase anim_data = {NULL, NULL}; bAnimListElem *ale; int filter; + bool found_bounds = false; /* get data to filter */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_NODUPLIS); @@ -280,10 +281,12 @@ static void get_nlastrip_extents(bAnimContext *ac, float *min, float *max, const for (strip = nlt->strips.first; strip; strip = strip->next) { /* only consider selected strips? */ - if ((onlySel == false) || (strip->flag & NLASTRIP_FLAG_SELECT)) { + if ((only_sel == false) || (strip->flag & NLASTRIP_FLAG_SELECT)) { /* extend range if appropriate */ *min = min_ff(*min, strip->start); *max = max_ff(*max, strip->end); + + found_bounds = true; } } } @@ -291,8 +294,9 @@ static void get_nlastrip_extents(bAnimContext *ac, float *min, float *max, const /* free memory */ BLI_freelistN(&anim_data); } - else { - /* set default range */ + + /* set default range if nothing happened */ + if (found_bounds == false) { if (ac->scene) { *min = (float)ac->scene->r.sfra; *max = (float)ac->scene->r.efra; @@ -304,6 +308,51 @@ static void get_nlastrip_extents(bAnimContext *ac, float *min, float *max, const } } +/* ****************** Automatic Preview-Range Operator ****************** */ + +static int nlaedit_previewrange_exec(bContext *C, wmOperator *UNUSED(op)) +{ + bAnimContext ac; + Scene *scene; + float min, max; + + /* get editor data */ + if (ANIM_animdata_get_context(C, &ac) == 0) + return OPERATOR_CANCELLED; + + if (ac.scene == NULL) + return OPERATOR_CANCELLED; + else + scene = ac.scene; + + /* set the range directly */ + get_nlastrip_extents(&ac, &min, &max, true); + scene->r.flag |= SCER_PRV_RANGE; + scene->r.psfra = iroundf(min); + scene->r.pefra = iroundf(max); + + /* set notifier that things have changed */ + // XXX err... there's nothing for frame ranges yet, but this should do fine too + WM_event_add_notifier(C, NC_SCENE | ND_FRAME, ac.scene); + + return OPERATOR_FINISHED; +} + +void NLA_OT_previewrange_set(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Auto-Set Preview Range"; + ot->idname = "NLA_OT_previewrange_set"; + ot->description = "Automatically set Preview Range based on range of keyframes"; + + /* api callbacks */ + ot->exec = nlaedit_previewrange_exec; + ot->poll = ED_operator_nla_active; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} + /* ****************** View-All Operator ****************** */ static int nlaedit_viewall(bContext *C, const bool onlySel) diff --git a/source/blender/editors/space_nla/nla_intern.h b/source/blender/editors/space_nla/nla_intern.h index dedd6404a2c..8d49d54375a 100644 --- a/source/blender/editors/space_nla/nla_intern.h +++ b/source/blender/editors/space_nla/nla_intern.h @@ -88,6 +88,8 @@ void NLA_OT_tweakmode_exit(wmOperatorType *ot); /* --- */ +void NLA_OT_previewrange_set(wmOperatorType *ot); + void NLA_OT_view_all(wmOperatorType *ot); void NLA_OT_view_selected(wmOperatorType *ot); diff --git a/source/blender/editors/space_nla/nla_ops.c b/source/blender/editors/space_nla/nla_ops.c index 0a010ffb819..373879a278b 100644 --- a/source/blender/editors/space_nla/nla_ops.c +++ b/source/blender/editors/space_nla/nla_ops.c @@ -133,6 +133,8 @@ void nla_operatortypes(void) WM_operatortype_append(NLA_OT_view_all); WM_operatortype_append(NLA_OT_view_selected); + WM_operatortype_append(NLA_OT_previewrange_set); + /* edit */ WM_operatortype_append(NLA_OT_tweakmode_enter); WM_operatortype_append(NLA_OT_tweakmode_exit); @@ -236,7 +238,8 @@ static void nla_keymap_main(wmKeyConfig *keyconf, wmKeyMap *keymap) /* view ---------------------------------------------------- */ /* auto-set range */ - //WM_keymap_add_item(keymap, "NLA_OT_previewrange_set", PKEY, KM_PRESS, KM_CTRL|KM_ALT, 0); + WM_keymap_add_item(keymap, "NLA_OT_previewrange_set", PKEY, KM_PRESS, KM_CTRL | KM_ALT, 0); + WM_keymap_add_item(keymap, "NLA_OT_view_all", HOMEKEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "NLA_OT_view_all", NDOF_BUTTON_FIT, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "NLA_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0); |