[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [17888] branches/blender2.5/blender/source /blender: View2D: Presets for Initialising Views

Joshua Leung aligorith at gmail.com
Tue Dec 16 12:24:26 CET 2008


Revision: 17888
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17888
Author:   aligorith
Date:     2008-12-16 12:24:24 +0100 (Tue, 16 Dec 2008)

Log Message:
-----------
View2D: Presets for Initialising Views

Improved the View2D API so that initialising View2D data in init() callbacks (called on new regions and also on resizing regions) for regions is easier. 

Added a few preset view configurations for use when initialising new views. Views with the V2D_IS_INITIALISED flag set will not be reinitialised in the init() callbacks. Currently, some of these configurations will set/override all settings (like V2D_COMMONVIEW_LIST and V2D_COMMONVIEW_HEADER), while other ones serve a more supplimentary role (i.e. V2D_COMMONVIEW_TIMELINE only sets the x-axis settings, relying on the region to have already set the relevant y-axis settings). 
The future of such supplimentary configurations is yet to be seen, as I'm currently not sure whether they will cause the code to become too confusing, as you'd have to keep track of which settings belong/are set where. So far, only a few areas have been ported to use this. Tomorrow I'll check on a few more.

As this commit touches a lot of files, hopefully there aren't any critical bugs I've missed here. 

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c
    branches/blender2.5/blender/source/blender/editors/include/UI_view2d.h
    branches/blender2.5/blender/source/blender/editors/interface/view2d.c
    branches/blender2.5/blender/source/blender/editors/interface/view2d_ops.c
    branches/blender2.5/blender/source/blender/editors/space_action/space_action.c
    branches/blender2.5/blender/source/blender/editors/space_buttons/space_buttons.c
    branches/blender2.5/blender/source/blender/editors/space_file/space_file.c
    branches/blender2.5/blender/source/blender/editors/space_image/space_image.c
    branches/blender2.5/blender/source/blender/editors/space_info/space_info.c
    branches/blender2.5/blender/source/blender/editors/space_ipo/space_ipo.c
    branches/blender2.5/blender/source/blender/editors/space_nla/space_nla.c
    branches/blender2.5/blender/source/blender/editors/space_node/space_node.c
    branches/blender2.5/blender/source/blender/editors/space_outliner/space_outliner.c
    branches/blender2.5/blender/source/blender/editors/space_script/space_script.c
    branches/blender2.5/blender/source/blender/editors/space_sequencer/space_sequencer.c
    branches/blender2.5/blender/source/blender/editors/space_sound/space_sound.c
    branches/blender2.5/blender/source/blender/editors/space_text/space_text.c
    branches/blender2.5/blender/source/blender/editors/space_time/space_time.c
    branches/blender2.5/blender/source/blender/editors/space_view3d/space_view3d.c
    branches/blender2.5/blender/source/blender/makesdna/DNA_view2d_types.h

Modified: branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c	2008-12-16 07:55:43 UTC (rev 17887)
+++ branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c	2008-12-16 11:24:24 UTC (rev 17888)
@@ -5061,7 +5061,7 @@
 	/* is copy from ui_view2d.c */
 	ar->v2d.keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_KEEPZOOM|V2D_KEEPASPECT);
 	ar->v2d.keepofs = V2D_LOCKOFS_Y;
-	ar->v2d.keeptot = 2; // this keeps the view in place when region size changes...
+	ar->v2d.keeptot = V2D_KEEPTOT_STRICT; 
 	ar->v2d.align = V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_NEG_Y;
 	
 }
@@ -5116,7 +5116,8 @@
 				ar->v2d.scroll |= (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM_O);
 				ar->v2d.align = (V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_POS_Y);
 				ar->v2d.keepzoom |= (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_KEEPASPECT);
-				ar->v2d.keeptot = 2;
+				ar->v2d.keeptot = V2D_KEEPTOT_STRICT;
+				ar->v2d.flag |= V2D_IS_INITIALISED;
 			}
 				break;
 			case SPACE_TIME:
@@ -5130,6 +5131,7 @@
 				ar->v2d.keepzoom |= V2D_LOCKZOOM_Y;
 				ar->v2d.tot.ymin= ar->v2d.cur.ymin= -10.0;
 				ar->v2d.min[1]= ar->v2d.max[1]= 20.0;
+				ar->v2d.flag |= V2D_IS_INITIALISED;
 			}
 				break;
 			case SPACE_IPO:
@@ -5139,6 +5141,7 @@
 				
 				ar->v2d.scroll |= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
 				ar->v2d.scroll |= (V2D_SCROLL_LEFT|V2D_SCROLL_SCALE_VERTICAL);
+				ar->v2d.flag |= V2D_IS_INITIALISED;
 				break;
 			}
 			case SPACE_SOUND:
@@ -5148,6 +5151,7 @@
 				
 				ar->v2d.scroll |= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
 				ar->v2d.scroll |= (V2D_SCROLL_LEFT);
+				ar->v2d.flag |= V2D_IS_INITIALISED;
 				break;
 			}
 			case SPACE_NLA:
@@ -5157,6 +5161,7 @@
 				
 				ar->v2d.scroll |= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
 				ar->v2d.scroll |= (V2D_SCROLL_RIGHT);
+				ar->v2d.flag |= V2D_IS_INITIALISED;
 				break;
 			}
 			case SPACE_ACTION:
@@ -5166,6 +5171,7 @@
 				
 				ar->v2d.scroll |= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
 				ar->v2d.scroll |= (V2D_SCROLL_RIGHT);
+				ar->v2d.flag |= V2D_IS_INITIALISED;
 				break;
 			}
 			case SPACE_SEQ:
@@ -5175,12 +5181,14 @@
 				
 				ar->v2d.scroll |= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
 				ar->v2d.scroll |= (V2D_SCROLL_LEFT|V2D_SCROLL_SCALE_VERTICAL);
+				ar->v2d.flag |= V2D_IS_INITIALISED;
 				break;
 			}
 			case SPACE_NODE:
 			{
 				SpaceNode *snode= (SpaceNode *)sl;
 				memcpy(&ar->v2d, &snode->v2d, sizeof(View2D));
+				ar->v2d.flag |= V2D_IS_INITIALISED;
 				break;
 			}
 			case SPACE_BUTS:
@@ -5188,6 +5196,7 @@
 				SpaceButs *sbuts= (SpaceButs *)sl;
 				memcpy(&ar->v2d, &sbuts->v2d, sizeof(View2D));
 				ar->v2d.keepzoom |= V2D_KEEPASPECT;
+				ar->v2d.flag |= V2D_IS_INITIALISED;
 				break;
 			}
 				//case SPACE_XXX: // FIXME... add other ones

Modified: branches/blender2.5/blender/source/blender/editors/include/UI_view2d.h
===================================================================
--- branches/blender2.5/blender/source/blender/editors/include/UI_view2d.h	2008-12-16 07:55:43 UTC (rev 17887)
+++ branches/blender2.5/blender/source/blender/editors/include/UI_view2d.h	2008-12-16 11:24:24 UTC (rev 17888)
@@ -44,10 +44,14 @@
 enum {
 		/* custom view type (region has defined all necessary flags already) */
 	V2D_COMMONVIEW_CUSTOM = 0,
+		/* view canvas ('standard' view, view limits/restrictions still need to be set first!) */
+	V2D_COMMONVIEW_VIEWCANVAS,
 		/* listview (i.e. Outliner) */
 	V2D_COMMONVIEW_LIST,
 		/* headers (this is basically the same as listview, but no y-panning) */
 	V2D_COMMONVIEW_HEADER,
+		/* timegrid (this sets the settings for x/horizontal, but y/vertical settings still need to be set first!) */
+	V2D_COMMONVIEW_TIMELINE,
 } eView2D_CommonViewTypes;
 
 /* ---- Defines for Scroller/Grid Arguments ----- */
@@ -125,11 +129,8 @@
 /* Prototypes:						    */
 
 /* refresh and validation (of view rects) */
-void UI_view2d_regiondata_init(struct View2D *v2d, short type, int winx, int winy);
-void UI_view2d_header_default(struct View2D *v2d);
+void UI_view2d_region_reinit(struct View2D *v2d, short type, int winx, int winy);
 
-void UI_view2d_size_update(struct View2D *v2d, int winx, int winy);
-
 void UI_view2d_curRect_validate(struct View2D *v2d);
 void UI_view2d_curRect_reset(struct View2D *v2d);
 

Modified: branches/blender2.5/blender/source/blender/editors/interface/view2d.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/interface/view2d.c	2008-12-16 07:55:43 UTC (rev 17887)
+++ branches/blender2.5/blender/source/blender/editors/interface/view2d.c	2008-12-16 11:24:24 UTC (rev 17888)
@@ -57,32 +57,18 @@
 /* *********************************************************************** */
 /* Refresh and Validation */
 
-/* Initialise all View2D data for a given region */
+/* Initialise all relevant View2D data (including view rects if first time) and/or refresh mask sizes after view resize
+ *	- for some of these presets, it is expected that the region will have defined some
+ * 	  additional settings necessary for the customisation of the 2D viewport to its requirements
+ *	- this function should only be called from region init() callbacks, where it is expected that
+ *	  this is called before UI_view2d_size_update(), as this one checks that the rects are properly initialised. 
+ */
 // eView2D_CommonViewTypes <--- only check handle these types...
-void UI_view2d_regiondata_init(View2D *v2d, short type, int winx, int winy)
+void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy)
 {
+	short tot_changed= 0;
 	
-}
-
-
-/* allowing horizontal pan */
-// XXX this should become one of 'standard' setups...
-void UI_view2d_header_default(View2D *v2d)
-{
-	v2d->keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_KEEPZOOM|V2D_KEEPASPECT);
-	v2d->keepofs = V2D_LOCKOFS_Y;
-	v2d->keeptot = 2; // this keeps the view in place when region size changes...
-	v2d->align = V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_NEG_Y;
-	
-}
-
-/* Adjust mask size in response to view size changes 
- *	- This should only be called in region init() callbacks, which are
- * 	  called when the region is resized or area changes...
- */
-// XXX pre2.5 -> this used to be called  calc_scrollrcts()
-void UI_view2d_size_update(View2D *v2d, int winx, int winy)
-{
+	/* store view size */
 	v2d->winx= winx;
 	v2d->winy= winy;
 	
@@ -138,22 +124,96 @@
 		}
 	}
 	
-	/* cope with unitialized veriables for simple cases, like header or outliner */
-	// XXX er... this shouldn't be here??? or at least some extra checks are needed for some things...
-	if ((v2d->tot.xmin==v2d->tot.xmax) || (v2d->cur.xmin==v2d->cur.xmax)) {
-		if (v2d->keepzoom & (V2D_KEEPZOOM|V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y)) {
-			BLI_init_rctf(&v2d->tot, v2d->mask.xmin, v2d->mask.xmax, v2d->mask.ymin, v2d->mask.ymax);
-			BLI_init_rctf(&v2d->cur, v2d->mask.xmin, v2d->mask.xmax, v2d->mask.ymin, v2d->mask.ymax);
+	/* initialise data if there is a need for such */
+	if ((v2d->flag & V2D_IS_INITIALISED) == 0) {
+		v2d->flag |= V2D_IS_INITIALISED;
+		
+		/* see eView2D_CommonViewTypes in UI_view2d.h for available view presets */
+		switch (type) {
+			/* 'standard view' - from (0,0) to (winx,winy), with other restrictions defined by region already */
+			case V2D_COMMONVIEW_VIEWCANVAS: 
+			{
+				/* just set 'tot' rect alignment restictions for now */
+				v2d->align= V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_NEG_Y;
+				tot_changed= 1;
+				
+				// XXX... should we set min/max here too? probably not essential yet
+			}
+				break;
 			
-			v2d->min[0]= v2d->max[0]= winx;
-			v2d->min[1]= v2d->max[1]= winy;
-			v2d->minzoom= 1.0f;
-			v2d->maxzoom= 1.0f;
+			/* 'list/channel view' - zoom, aspect ratio, and alignment restrictions are set here */
+			case V2D_COMMONVIEW_LIST:
+			{
+				/* zoom + aspect ratio are locked */
+				v2d->keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_KEEPZOOM|V2D_KEEPASPECT);
+				v2d->minzoom= v2d->maxzoom= 1.0f;
+				
+				/* tot rect has strictly regulated placement, and must only occur in +/- quadrant */
+				v2d->align = (V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_POS_Y);
+				v2d->keeptot = V2D_KEEPTOT_STRICT;
+				tot_changed= 1;
+				
+				/* scroller settings are currently not set here... that is left for regions... */
+			}
+				break;
+				
+			/* 'header' regions - zoom, aspect ratio, alignment, and panning restrictions are set here */
+			case V2D_COMMONVIEW_HEADER:
+			{
+				/* zoom + aspect ratio are locked */
+				v2d->keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_KEEPZOOM|V2D_KEEPASPECT);
+				v2d->minzoom= v2d->maxzoom= 1.0f;
+				v2d->min[0]= v2d->max[0]= winx;
+				v2d->min[1]= v2d->max[1]= winy;
+				
+				/* tot rect has strictly regulated placement, and must only occur in +/+ quadrant */
+				v2d->align = (V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_NEG_Y);
+				v2d->keeptot = V2D_KEEPTOT_STRICT;
+				tot_changed= 1;
+				
+				/* panning in y-axis is prohibited */
+				v2d->keepofs= V2D_LOCKOFS_Y;
+				
+				/* absolutely no scrollers allowed */
+				v2d->scroll= 0;
+			}
+				break;
+				
+			/* 'timeline/animeditors' - only set x-axis settings (y axis settings have already been set by regions, so don't overwrite! */
+			case V2D_COMMONVIEW_TIMELINE:
+			{
+				/* zoom on x-axis is free, but zoom factors are usually standard */
+				v2d->minzoom= 0.5f;
+				v2d->maxzoom= 10.0f;
+				
+				/* size limits on x-axis are also standard */
+				v2d->min[0]= 0.0f; // XXX... would 1.0f be better?
+				v2d->max[0]= MAXFRAMEF;
+				
+				/* scrollers for x-axis must be shown, and with scales */
+				v2d->scroll |= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
+				
+				/* 'tot' rect x-axis size */
+				v2d->tot.xmin= (float)(SFRA - 10);
+				v2d->tot.xmax= (float)(EFRA + 10);
+				v2d->cur.xmin= v2d->mask.xmin;
+				v2d->cur.xmax= v2d->mask.xmax;
+				tot_changed= 0; // er..
+			}
+				break;
+				
+			/* other view types are completely defined using their own settings already */
+			default:
+				/* we don't do anything here, as settings should be fine, but just make sure that rect */
+				break;	
 		}
 	}
 	
-	/* make sure that 'cur' rect is in a valid state as a result of these changes */
-	UI_view2d_curRect_validate(v2d);
+	/* set 'tot' rect before setting cur? */
+	if (tot_changed) 
+		UI_view2d_totRect_set(v2d, winx, winy);
+	else

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list