[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [17719] branches/blender2.5/blender/source /blender: View2D API: Cleaning up API + New Methods

Joshua Leung aligorith at gmail.com
Fri Dec 5 03:03:43 CET 2008


Revision: 17719
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17719
Author:   aligorith
Date:     2008-12-05 03:03:37 +0100 (Fri, 05 Dec 2008)

Log Message:
-----------
View2D API: Cleaning up API + New Methods

* Cleaned up flags defined for View2D, and added some for defining the alignment of the view's data in the 'tot' rect (i.e. which quadrant(s) the view data is allowed to reside in). 

* These flags are used in the new UI_view2d_totRect_set() function, which sets the new size of the 'tot' rect (i.e. the maximum viewable area). Currently, is only used for Outliner, but channel-lists also require this.

* Added API method to reset 'cur' (current viewing region) to 'default' viewing region - UI_view2d_curRect_reset(). Currently, 'keepzoom' is not respected. I'll check on whether this is needed when I recode UI_view2d_status_enforce(), which is badly in need of a cleanup.

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/space_outliner/space_outliner.c
    branches/blender2.5/blender/source/blender/editors/space_time/space_time.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-04 22:47:26 UTC (rev 17718)
+++ branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c	2008-12-05 02:03:37 UTC (rev 17719)
@@ -5076,6 +5076,7 @@
 				memcpy(&ar->v2d, &soops->v2d, sizeof(View2D));
 				ar->v2d.scroll &= ~V2D_SCROLL_LEFT;
 				ar->v2d.scroll |= V2D_SCROLL_RIGHT;
+				ar->v2d.align = (V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_POS_Y);
 			}
 				break;
 			case SPACE_TIME:
@@ -5084,6 +5085,7 @@
 				memcpy(&ar->v2d, &stime->v2d, sizeof(View2D));
 				
 				ar->v2d.scroll |= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_BOTTOM);
+				ar->v2d.align |= V2D_ALIGN_NO_NEG_Y;
 				ar->v2d.keepofs |= V2D_LOCKOFS_Y;
 			}
 				break;

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-04 22:47:26 UTC (rev 17718)
+++ branches/blender2.5/blender/source/blender/editors/include/UI_view2d.h	2008-12-05 02:03:37 UTC (rev 17719)
@@ -82,14 +82,19 @@
 /* ----------------------------------------- */
 /* Prototypes:						    */
 
-/* setup */
+/* refresh and validation (of view rects) */
+	// XXX rename these...
+void UI_view2d_size_update(struct View2D *v2d, int winx, int winy);
+void UI_view2d_status_enforce(struct View2D *v2d, int winx, int winy);
+
+void UI_view2d_totRect_set(struct View2D *v2d, int width, int height);
+void UI_view2d_curRect_reset(struct View2D *v2d);
+
+/* view matrix operations */
 void UI_view2d_view_ortho(const struct bContext *C, struct View2D *v2d);
-void UI_view2d_view_orthospecial(const struct bContext *C, struct View2D *v2d, short xaxis);
+void UI_view2d_view_orthoSpecial(const struct bContext *C, struct View2D *v2d, short xaxis);
 void UI_view2d_view_restore(const struct bContext *C);
 
-void UI_view2d_update_size(struct View2D *v2d, int winx, int winy);
-void UI_view2d_enforce_status(struct View2D *v2d, int winx, int winy);
-
 /* grid drawing */
 View2DGrid *UI_view2d_calc_grid(const struct bContext *C, struct View2D *v2d, short unit, short clamp, int winx, int winy);
 void UI_view2d_draw_grid(const struct bContext *C, struct View2D *v2d, View2DGrid *grid, int flag);

Modified: branches/blender2.5/blender/source/blender/editors/interface/view2d.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/interface/view2d.c	2008-12-04 22:47:26 UTC (rev 17718)
+++ branches/blender2.5/blender/source/blender/editors/interface/view2d.c	2008-12-05 02:03:37 UTC (rev 17719)
@@ -52,9 +52,12 @@
 /* *********************************************************************** */
 /* Refresh and Validation */
 
-/* Adjust mask size in response to view size changes */
+/* Adjust mask size in response to view size changes 
+ *	- When drawing a region, this should be called before 
+ *	  any other drawing using View2D happens.
+ */
 // XXX pre2.5 -> this used to be called  calc_scrollrcts()
-void UI_view2d_update_size(View2D *v2d, int winx, int winy)
+void UI_view2d_size_update(View2D *v2d, int winx, int winy)
 {
 	/* mask - view frame */
 	v2d->mask.xmin= v2d->mask.ymin= 0;
@@ -99,8 +102,8 @@
  *	- cur is not allowed to be: larger than max, smaller than min, or outside of tot
  */
 // XXX pre2.5 -> this used to be called  test_view2d()
-// XXX FIXME - still need to go through this and figure out what it all parts of it do
-void UI_view2d_enforce_status(View2D *v2d, int winx, int winy)
+// XXX FIXME - this is an old mess function... let's rewrite!
+void UI_view2d_status_enforce(View2D *v2d, int winx, int winy)
 {
 	/* cur is not allowed to be larger than max, smaller than min, or outside of tot */
 	rctf *cur, *tot;
@@ -115,7 +118,7 @@
 	
 	/* get pointers */
 	cur= &v2d->cur;
-	tot= &v2d->tot;
+	tot= &v2d->cur;
 	
 	/* dx, dy are width and height of v2d->cur, respectively */
 	dx= cur->xmax - cur->xmin;
@@ -216,14 +219,14 @@
 		}
 		
 		if (do_x) {
-			if ((v2d->keeptot == 2) && (winx < v2d->oldwinx)) {
+			if ((v2d->keeptot == 2) && (winx != v2d->oldwinx)) {
 				/* This is a special hack for the outliner, to ensure that the 
-				 * outliner contents will not eventually get pushed out of view
-				 * when shrinking the view. 
+				 * outliner contents will stay in their relative place in the view 
+				 * when the view is resized
 				 */
 				cur->xmax -= cur->xmin;
 				cur->xmin= 0.0f;
-			}
+			} 
 			else {
 				/* portrait window: correct for x */
 				dx= cur->ymax - cur->ymin;
@@ -326,6 +329,105 @@
 	}
 }
 
+/* ------------------ */
+
+/* Change the size of the maximum viewable area (i.e. 'tot' rect) 
+ *	- Currently, caller will need to call UI_status_enforce() after this, 
+ *	  with the region width+height to make sure that 'cur' rect is still valid
+ */
+void UI_view2d_totRect_set(View2D *v2d, int width, int height)
+{
+	/* don't do anything if either value is 0 */
+	if (ELEM3(0, v2d, width, height))
+		return;
+		
+	/* handle width - posx and negx flags are mutually exclusive, so watch out */
+	if ((v2d->align & V2D_ALIGN_NO_POS_X) && !(v2d->align & V2D_ALIGN_NO_NEG_X)) {
+		/* width is in negative-x half */
+		v2d->cur.xmin= (float)-width;
+		v2d->cur.xmax= 0.0f;
+	}
+	else if ((v2d->align & V2D_ALIGN_NO_NEG_X) && !(v2d->align & V2D_ALIGN_NO_POS_X)) {
+		/* width is in positive-x half */
+		v2d->cur.xmin= 0.0f;
+		v2d->cur.xmax= (float)width;
+	}
+	else {
+		/* width is centered around x==0 */
+		const float dx= (float)width / 2.0f;
+		
+		v2d->cur.xmin= -dx;
+		v2d->cur.xmax= dx;
+	}
+	
+	/* handle height - posx and negx flags are mutually exclusive, so watch out */
+	if ((v2d->align & V2D_ALIGN_NO_POS_Y) && !(v2d->align & V2D_ALIGN_NO_NEG_Y)) {
+		/* height is in negative-y half */
+		v2d->cur.ymin= (float)-height;
+		v2d->cur.ymax= 0.0f;
+	}
+	else if ((v2d->align & V2D_ALIGN_NO_NEG_Y) && !(v2d->align & V2D_ALIGN_NO_POS_Y)) {
+		/* height is in positive-y half */
+		v2d->cur.ymin= 0.0f;
+		v2d->cur.ymax= (float)height;
+	}
+	else {
+		/* height is centered around y==0 */
+		const float dy= (float)height / 2.0f;
+		
+		v2d->cur.ymin= -dy;
+		v2d->cur.ymax= dy;
+	}
+}
+
+/* Restore 'cur' rect to standard orientation (i.e. optimal maximum view of tot) */
+void UI_view2d_curRect_reset (View2D *v2d)
+{
+	float width, height;
+	
+	/* assume width and height of 'cur' rect by default, should be same size as mask */
+	width= (float)(v2d->mask.xmax - v2d->mask.xmin + 1);
+	height= (float)(v2d->mask.ymax - v2d->mask.ymin + 1);
+	
+	/* handle width - posx and negx flags are mutually exclusive, so watch out */
+	if ((v2d->align & V2D_ALIGN_NO_POS_X) && !(v2d->align & V2D_ALIGN_NO_NEG_X)) {
+		/* width is in negative-x half */
+		v2d->cur.xmin= (float)-width;
+		v2d->cur.xmax= 0.0f;
+	}
+	else if ((v2d->align & V2D_ALIGN_NO_NEG_X) && !(v2d->align & V2D_ALIGN_NO_POS_X)) {
+		/* width is in positive-x half */
+		v2d->cur.xmin= 0.0f;
+		v2d->cur.xmax= (float)width;
+	}
+	else {
+		/* width is centered around x==0 */
+		const float dx= (float)width / 2.0f;
+		
+		v2d->cur.xmin= -dx;
+		v2d->cur.xmax= dx;
+	}
+	
+	/* handle height - posx and negx flags are mutually exclusive, so watch out */
+	if ((v2d->align & V2D_ALIGN_NO_POS_Y) && !(v2d->align & V2D_ALIGN_NO_NEG_Y)) {
+		/* height is in negative-y half */
+		v2d->cur.ymin= (float)-height;
+		v2d->cur.ymax= 0.0f;
+	}
+	else if ((v2d->align & V2D_ALIGN_NO_NEG_Y) && !(v2d->align & V2D_ALIGN_NO_POS_Y)) {
+		/* height is in positive-y half */
+		v2d->cur.ymin= 0.0f;
+		v2d->cur.ymax= (float)height;
+	}
+	else {
+		/* height is centered around y==0 */
+		const float dy= (float)height / 2.0f;
+		
+		v2d->cur.ymin= -dy;
+		v2d->cur.ymax= dy;
+	}
+}
+
 /* *********************************************************************** */
 /* View Matrix Setup */
 
@@ -345,7 +447,7 @@
  *
  *	- xaxis 	= if non-zero, only use cur x-axis, otherwise use cur-yaxis (mostly this will be used for x)
  */
-void UI_view2d_view_orthospecial(const bContext *C, View2D *v2d, short xaxis)
+void UI_view2d_view_orthoSpecial(const bContext *C, View2D *v2d, short xaxis)
 {
 	ARegion *region= C->region;
 	int winx, winy;
@@ -640,14 +742,14 @@
 	/* horizontal scrollers */
 	if (v2d->scroll & (V2D_SCROLL_HORIZONTAL|V2D_SCROLL_HORIZONTAL_O)) {
 		/* slider 'button' extents */
-		totsize= v2d->tot.xmax - v2d->tot.xmin;
+		totsize= v2d->cur.xmax - v2d->cur.xmin;
 		scrollsize= hor.xmax - hor.xmin;
 		
-		fac= (v2d->cur.xmin- v2d->tot.xmin) / totsize;
+		fac= (v2d->cur.xmin- v2d->cur.xmin) / totsize;
 		//if (fac < 0.0f) fac= 0.0f;
 		scrollers->hor_min= hor.xmin + (fac * scrollsize);
 		
-		fac= (v2d->cur.xmax - v2d->tot.xmin) / totsize;
+		fac= (v2d->cur.xmax - v2d->cur.xmin) / totsize;
 		//if (fac > 1.0f) fac= 1.0f;
 		scrollers->hor_max= hor.xmin + (fac * scrollsize);
 		
@@ -658,14 +760,14 @@
 	/* vertical scrollers */
 	if (v2d->scroll & V2D_SCROLL_VERTICAL) {
 		/* slider 'button' extents */
-		totsize= v2d->tot.ymax - v2d->tot.ymin;
+		totsize= v2d->cur.ymax - v2d->cur.ymin;
 		scrollsize= vert.ymax - vert.ymin;
 		
-		fac= (v2d->cur.ymin- v2d->tot.ymin) / totsize;
+		fac= (v2d->cur.ymin- v2d->cur.ymin) / totsize;
 		//if (fac < 0.0f) fac= 0.0f;
 		scrollers->vert_min= vert.ymin + (fac * scrollsize);
 		
-		fac= (v2d->cur.ymax - v2d->tot.ymin) / totsize;
+		fac= (v2d->cur.ymax - v2d->cur.ymin) / totsize;
 		//if (fac > 1.0f) fac= 1.0f;
 		scrollers->vert_max= vert.ymin + (fac * scrollsize);
 		
@@ -752,13 +854,13 @@
 			// FIXME: implement fancy one... but only when we get this working first!
 		{
 			UI_ThemeColorShade(TH_SHADE1, dark);
-			glRecti(scrollers->hor_min,  hor.ymin,  scrollers->hor_max,  hor.ymax);
+			glRecti(scrollers->hor_min,  hor.ymin+2,  scrollers->hor_max,  hor.ymax-2);
 			
 				/* draw lines on either end of 'box' */
 			glLineWidth(2.0);
 				UI_ThemeColorShade(TH_SHADE1, darker);
-				sdrawline(scrollers->hor_min, hor.ymin, scrollers->hor_min, hor.ymax);
-				sdrawline(scrollers->hor_max, hor.ymin, scrollers->hor_max, hor.ymax);
+				sdrawline(scrollers->hor_min, hor.ymin+2, scrollers->hor_min, hor.ymax-2);
+				sdrawline(scrollers->hor_max, hor.ymin+2, scrollers->hor_max, hor.ymax-2);
 			glLineWidth(1.0);
 		}
 		
@@ -844,13 +946,13 @@

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list