[Bf-blender-cvs] [b40b6bd] master: NLA Editor: Added an operator to set preview range based on the extents of selected strips

Joshua Leung noreply at git.blender.org
Mon Apr 28 09:34:40 CEST 2014


Commit: b40b6bd48d5c7f8cc4057b7355462e0bb198e987
Author: Joshua Leung
Date:   Mon Apr 28 19:33:28 2014 +1200
https://developer.blender.org/rBb40b6bd48d5c7f8cc4057b7355462e0bb198e987

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.

===================================================================

M	release/scripts/startup/bl_ui/space_nla.py
M	source/blender/editors/space_nla/nla_edit.c
M	source/blender/editors/space_nla/nla_intern.h
M	source/blender/editors/space_nla/nla_ops.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_nla.py b/release/scripts/startup/bl_ui/space_nla.py
index e41086f..2a32e7b 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 10fc8e5..8221fb0 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 dedd640..8d49d54 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 0a010ff..373879a 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);




More information about the Bf-blender-cvs mailing list