[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [38520] branches/soc-2011-pepper: View All /Selected tools for NLA Editor

Joshua Leung aligorith at gmail.com
Wed Jul 20 02:36:29 CEST 2011


Revision: 38520
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38520
Author:   aligorith
Date:     2011-07-20 00:36:28 +0000 (Wed, 20 Jul 2011)
Log Message:
-----------
View All/Selected tools for NLA Editor

Modified Paths:
--------------
    branches/soc-2011-pepper/release/scripts/startup/bl_ui/space_nla.py
    branches/soc-2011-pepper/source/blender/editors/space_action/action_edit.c
    branches/soc-2011-pepper/source/blender/editors/space_nla/nla_edit.c
    branches/soc-2011-pepper/source/blender/editors/space_nla/nla_intern.h
    branches/soc-2011-pepper/source/blender/editors/space_nla/nla_ops.c

Modified: branches/soc-2011-pepper/release/scripts/startup/bl_ui/space_nla.py
===================================================================
--- branches/soc-2011-pepper/release/scripts/startup/bl_ui/space_nla.py	2011-07-19 22:40:22 UTC (rev 38519)
+++ branches/soc-2011-pepper/release/scripts/startup/bl_ui/space_nla.py	2011-07-20 00:36:28 UTC (rev 38520)
@@ -72,8 +72,12 @@
         layout.separator()
         layout.operator("anim.previewrange_set")
         layout.operator("anim.previewrange_clear")
-
+        
         layout.separator()
+        layout.operator("nla.view_all")
+        layout.operator("nla.view_selected")
+        
+        layout.separator()
         layout.operator("screen.area_dupli")
         layout.operator("screen.screen_full_area")
 

Modified: branches/soc-2011-pepper/source/blender/editors/space_action/action_edit.c
===================================================================
--- branches/soc-2011-pepper/source/blender/editors/space_action/action_edit.c	2011-07-19 22:40:22 UTC (rev 38519)
+++ branches/soc-2011-pepper/source/blender/editors/space_action/action_edit.c	2011-07-20 00:36:28 UTC (rev 38520)
@@ -234,6 +234,7 @@
 	int filter;
 	
 	/* get data to filter, from Action or Dopesheet */
+	// XXX: what is sel doing here?!
 	filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_SEL /*| ANIMFILTER_CURVESONLY*/ | ANIMFILTER_NODUPLIS);
 	ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
 	

Modified: branches/soc-2011-pepper/source/blender/editors/space_nla/nla_edit.c
===================================================================
--- branches/soc-2011-pepper/source/blender/editors/space_nla/nla_edit.c	2011-07-19 22:40:22 UTC (rev 38519)
+++ branches/soc-2011-pepper/source/blender/editors/space_nla/nla_edit.c	2011-07-20 00:36:28 UTC (rev 38520)
@@ -68,6 +68,7 @@
 
 #include "UI_interface.h"
 #include "UI_resources.h"
+#include "UI_view2d.h"
 
 #include "nla_intern.h"	// own include
 #include "nla_private.h" // FIXME... maybe this shouldn't be included?
@@ -236,6 +237,136 @@
 }
 
 /* *********************************************** */
+/* NLA Strips Range Stuff */
+
+/* *************************** Calculate Range ************************** */
+
+/* Get the min/max strip extents */
+static void get_nlastrip_extents (bAnimContext *ac, float *min, float *max, const short onlySel)
+{
+	ListBase anim_data = {NULL, NULL};
+	bAnimListElem *ale;
+	int filter;
+	
+	/* get data to filter */
+	filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_NODUPLIS);
+	ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
+	
+	/* set large values to try to override */
+	*min= 999999999.0f;
+	*max= -999999999.0f;
+	
+	/* check if any channels to set range with */
+	if (anim_data.first) {
+		/* go through channels, finding max extents */
+		for (ale= anim_data.first; ale; ale= ale->next) {
+			NlaTrack *nlt = (NlaTrack *)ale->data;
+			NlaStrip *strip;
+			
+			for (strip = nlt->strips.first; strip; strip = strip->next) {
+				/* only consider selected strips? */
+				if ((onlySel == 0) || (strip->flag & NLASTRIP_FLAG_SELECT)) {
+					/* extend range if appropriate */
+					*min = MIN2(*min, strip->start);
+					*max = MAX2(*max, strip->end);
+				}
+			}
+		}
+		
+		/* free memory */
+		BLI_freelistN(&anim_data);
+	}
+	else {
+		/* set default range */
+		if (ac->scene) {
+			*min= (float)ac->scene->r.sfra;
+			*max= (float)ac->scene->r.efra;
+		}
+		else {
+			*min= -5;
+			*max= 100;
+		}
+	}
+}
+
+/* ****************** View-All Operator ****************** */
+
+static int nlaedit_viewall(bContext *C, const short onlySel)
+{
+	bAnimContext ac;
+	View2D *v2d;
+	float extra;
+	
+	/* get editor data */
+	if (ANIM_animdata_get_context(C, &ac) == 0)
+		return OPERATOR_CANCELLED;
+	v2d= &ac.ar->v2d;
+	
+	/* set the horizontal range, with an extra offset so that the extreme keys will be in view */
+	get_nlastrip_extents(&ac, &v2d->cur.xmin, &v2d->cur.xmax, onlySel);
+	
+	extra= 0.1f * (v2d->cur.xmax - v2d->cur.xmin);
+	v2d->cur.xmin -= extra;
+	v2d->cur.xmax += extra;
+	
+	/* set vertical range */
+	v2d->cur.ymax= 0.0f;
+	v2d->cur.ymin= (float)-(v2d->mask.ymax - v2d->mask.ymin);
+	
+	/* do View2D syncing */
+	UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
+	
+	/* just redraw this view */
+	ED_area_tag_redraw(CTX_wm_area(C));
+	
+	return OPERATOR_FINISHED;
+}
+
+/* ......... */
+
+static int nlaedit_viewall_exec(bContext *C, wmOperator *UNUSED(op))
+{	
+	/* whole range */
+	return nlaedit_viewall(C, FALSE);
+}
+
+static int nlaedit_viewsel_exec(bContext *C, wmOperator *UNUSED(op))
+{
+	/* only selected */
+	return nlaedit_viewall(C, TRUE);
+}
+ 
+void NLA_OT_view_all (wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name= "View All";
+	ot->idname= "NLA_OT_view_all";
+	ot->description= "Reset viewable area to show full strips range";
+	
+	/* api callbacks */
+	ot->exec= nlaedit_viewall_exec;
+	ot->poll= ED_operator_nla_active;
+	
+	/* flags */
+	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+void NLA_OT_view_selected (wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name= "View Selected";
+	ot->idname= "NLA_OT_view_selected";
+	ot->description= "Reset viewable area to show selected strips range";
+	
+	/* api callbacks */
+	ot->exec= nlaedit_viewsel_exec;
+	ot->poll= ED_operator_nla_active;
+	
+	/* flags */
+	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+/* *********************************************** */
 /* NLA Editing Operations (Constructive/Destructive) */
 
 /* ******************** Add Action-Clip Operator ***************************** */

Modified: branches/soc-2011-pepper/source/blender/editors/space_nla/nla_intern.h
===================================================================
--- branches/soc-2011-pepper/source/blender/editors/space_nla/nla_intern.h	2011-07-19 22:40:22 UTC (rev 38519)
+++ branches/soc-2011-pepper/source/blender/editors/space_nla/nla_intern.h	2011-07-20 00:36:28 UTC (rev 38520)
@@ -94,6 +94,9 @@
 
 /* --- */
 
+void NLA_OT_view_all(wmOperatorType *ot);
+void NLA_OT_view_selected(wmOperatorType *ot);
+
 void NLA_OT_actionclip_add(wmOperatorType *ot);
 void NLA_OT_transition_add(wmOperatorType *ot);
 

Modified: branches/soc-2011-pepper/source/blender/editors/space_nla/nla_ops.c
===================================================================
--- branches/soc-2011-pepper/source/blender/editors/space_nla/nla_ops.c	2011-07-19 22:40:22 UTC (rev 38519)
+++ branches/soc-2011-pepper/source/blender/editors/space_nla/nla_ops.c	2011-07-20 00:36:28 UTC (rev 38520)
@@ -130,6 +130,10 @@
 	WM_operatortype_append(NLA_OT_select_all_toggle);
 	WM_operatortype_append(NLA_OT_select_leftright);
 	
+	/* view */
+	WM_operatortype_append(NLA_OT_view_all);
+	WM_operatortype_append(NLA_OT_view_selected);
+	
 	/* edit */
 	WM_operatortype_append(NLA_OT_tweakmode_enter);
 	WM_operatortype_append(NLA_OT_tweakmode_exit);
@@ -212,6 +216,11 @@
 	WM_keymap_add_item(keymap, "NLA_OT_select_border", BKEY, KM_PRESS, 0, 0);
 	RNA_boolean_set(WM_keymap_add_item(keymap, "NLA_OT_select_border", BKEY, KM_PRESS, KM_ALT, 0)->ptr, "axis_range", 1);
 	
+	/* 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_view_all", HOMEKEY, KM_PRESS, 0, 0);
+	WM_keymap_add_item(keymap, "NLA_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0);
 	
 	/* editing */
 		/* tweakmode 




More information about the Bf-blender-cvs mailing list