[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [17785] branches/blender2.5/blender/source /blender: View2D: Various Fixes + Header Support

Joshua Leung aligorith at gmail.com
Thu Dec 11 04:50:51 CET 2008


Revision: 17785
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17785
Author:   aligorith
Date:     2008-12-11 04:50:50 +0100 (Thu, 11 Dec 2008)

Log Message:
-----------
View2D: Various Fixes + Header Support

Added support for panning headers using View2D of the header regions (only done for TimeLine, as only that one has buttons on it). 
Currently, this uses some do_versions magic to initialise the View2D rects required, however, I'm not sure if all the information was safely ported over yet (notably height and position of rects due to alignment issues).

In the process, I noticed a few bugs with the current View2D code:
* UI_view2d_curRect_validate() is now called after UI_view2d_size_update(), as the size of the 'mask' rect is closely related to the size of the 'cur' rect (especially when zooming is locked).
* Fixed a bug in UI_view2d_curRect_validate() which meant that if the 'cur' rect was slightly larger than the 'tot' rect, and keeptot was set, the view would flicker between the two closely related positions.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c
    branches/blender2.5/blender/source/blender/editors/interface/view2d.c
    branches/blender2.5/blender/source/blender/editors/space_time/space_time.c

Modified: branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c	2008-12-10 22:13:23 UTC (rev 17784)
+++ branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c	2008-12-11 03:50:50 UTC (rev 17785)
@@ -5054,7 +5054,36 @@
 				ar->alignment= RGN_ALIGN_BOTTOM;
 			else
 				ar->alignment= RGN_ALIGN_TOP;
-			// TODO: add conversion stuff for header scrolling to v2d of header region
+			
+			/* initialise view2d data for header region, to allow panning */
+			ar->v2d.keepaspect= 1;
+			ar->v2d.keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_KEEPZOOM);
+			ar->v2d.keepofs = V2D_LOCKOFS_Y;
+			ar->v2d.keeptot = 2; // this keeps the view in place when region size changes...
+			ar->v2d.align = V2D_ALIGN_NO_NEG_X;
+			
+			ar->v2d.minzoom= ar->v2d.maxzoom= 1.0f;
+			
+			ar->v2d.mask.xmin= ar->v2d.mask.ymin= 0;
+			ar->v2d.mask.xmax= sa->winx;
+			ar->v2d.mask.ymax= HEADERY;
+			
+			ar->v2d.cur.xmin= sa->headbutofs;
+			ar->v2d.cur.xmax= sa->winx + sa->headbutofs;
+			ar->v2d.tot.xmin= 0.0f;
+			ar->v2d.tot.xmax= sa->headbutlen;
+			
+			if (ar->alignment == RGN_ALIGN_BOTTOM) {
+				ar->v2d.align = V2D_ALIGN_NO_NEG_Y;
+				ar->v2d.tot.ymin= ar->v2d.cur.ymin= 0.0f; // what was area->headrct.ymin?
+				ar->v2d.tot.ymax= ar->v2d.cur.ymax= HEADERY;
+			}
+			else {
+				// XXX what were the extents of the old headers?
+				ar->v2d.align = V2D_ALIGN_NO_NEG_Y;
+				ar->v2d.tot.ymin= ar->v2d.cur.ymin= 0.0f; // what was area->headrct.ymin?
+				ar->v2d.tot.ymax= ar->v2d.cur.ymax= HEADERY;
+			}
 		}
 		
 		ar= MEM_callocN(sizeof(ARegion), "area region from do_versions");

Modified: branches/blender2.5/blender/source/blender/editors/interface/view2d.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/interface/view2d.c	2008-12-10 22:13:23 UTC (rev 17784)
+++ branches/blender2.5/blender/source/blender/editors/interface/view2d.c	2008-12-11 03:50:50 UTC (rev 17785)
@@ -53,8 +53,8 @@
 /* Refresh and Validation */
 
 /* Adjust mask size in response to view size changes 
- *	- When drawing a region, this should be called before 
- *	  any other drawing using View2D happens.
+ *	- 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)
@@ -96,6 +96,9 @@
 			v2d->mask.ymax= v2d->hor.ymin;
 		}
 	}
+	
+	/* make sure that 'cur' rect is in a valid state as a result of these changes */
+	UI_view2d_curRect_validate(v2d);
 }
 
 /* Ensure View2D rects remain in a viable configuration 
@@ -104,7 +107,6 @@
 // XXX pre2.5 -> this used to be called  test_view2d()
 void UI_view2d_curRect_validate(View2D *v2d)
 {
-	/* cur is not allowed to be larger than max, smaller than min, or outside of tot */
 	float totwidth, totheight, curwidth, curheight, width, height;
 	float winx, winy;
 	rctf *cur, *tot;
@@ -146,17 +148,21 @@
 		float zoom, fac;
 		
 		/* check if excessive zoom on x-axis */
-		zoom= winx / width;
-		if ((zoom < v2d->minzoom) || (zoom > v2d->maxzoom)) {
-			fac= (zoom < v2d->minzoom) ? (zoom / v2d->minzoom) : (zoom / v2d->maxzoom);
-			width *= fac;
+		if ((v2d->keepzoom & V2D_LOCKZOOM_X)==0) {
+			zoom= winx / width;
+			if ((zoom < v2d->minzoom) || (zoom > v2d->maxzoom)) {
+				fac= (zoom < v2d->minzoom) ? (zoom / v2d->minzoom) : (zoom / v2d->maxzoom);
+				width *= fac;
+			}
 		}
 		
 		/* check if excessive zoom on y-axis */
-		zoom= winy / height;
-		if ((zoom < v2d->minzoom) || (zoom > v2d->maxzoom)) {
-			fac= (zoom < v2d->minzoom) ? (zoom / v2d->minzoom) : (zoom / v2d->maxzoom);
-			height *= fac;
+		if ((v2d->keepzoom & V2D_LOCKZOOM_Y)==0) {
+			zoom= winy / height;
+			if ((zoom < v2d->minzoom) || (zoom > v2d->maxzoom)) {
+				fac= (zoom < v2d->minzoom) ? (zoom / v2d->minzoom) : (zoom / v2d->maxzoom);
+				height *= fac;
+			}
 		}
 	}
 	else {
@@ -248,14 +254,14 @@
 	
 	/* Step 3: adjust so that it doesn't fall outside of bounds of tot */
 	if (v2d->keeptot) {
-		float temp;
+		float temp, diff;
 		
 		/* recalculate extents of cur */
 		curwidth= cur->xmax - cur->xmin;
 		curheight= cur->ymax - cur->ymin;
 		
 		/* width */
-		if ((curwidth > totwidth) && (v2d->keepzoom == 0)) {
+		if ( (curwidth > totwidth) && !(v2d->keepzoom & (V2D_KEEPZOOM|V2D_LOCKZOOM_X)) ) {
 			/* if zoom doesn't have to be maintained, just clamp edges */
 			if (cur->xmin < tot->xmin) cur->xmin= tot->xmin;
 			if (cur->xmax > tot->xmax) cur->xmax= tot->xmax;
@@ -301,7 +307,15 @@
 			 * We favour moving the 'minimum' across, as that's origin for most things
 			 * (XXX - in the past, max was favoured... if there are bugs, swap!)
 			 */
-			if (cur->xmin > tot->xmin) {
+			if ((cur->ymin < tot->ymin) && (cur->ymax > tot->ymax)) {
+				/* outside boundaries on both sides, so take middle-point of tot, and place in balanced way */
+				temp= (tot->ymax + tot->ymin) * 0.5f;
+				diff= curheight * 0.5f;
+				
+				cur->ymin= temp - diff;
+				cur->ymax= temp + diff;
+			}
+			else if (cur->xmin > tot->xmin) {
 				/* there's still space remaining, so shift left */
 				temp= cur->xmin - tot->xmin;
 				
@@ -318,7 +332,7 @@
 		}
 		
 		/* height */
-		if ((curheight > totheight) && (v2d->keepzoom == 0)) {
+		if ( (curheight > totheight) && !(v2d->keepzoom & (V2D_KEEPZOOM|V2D_LOCKZOOM_Y)) ) {
 			/* if zoom doesn't have to be maintained, just clamp edges */
 			if (cur->ymin < tot->ymin) cur->ymin= tot->ymin;
 			if (cur->ymax > tot->ymax) cur->ymax= tot->ymax;
@@ -331,7 +345,15 @@
 			 * So, resolution is to just shift view by the gap between the extremities.
 			 * We favour moving the 'minimum' across, as that's origin for most things
 			 */
-			if (cur->ymin < tot->ymin) {
+			if ((cur->ymin < tot->ymin) && (cur->ymax > tot->ymax)) {
+				/* outside boundaries on both sides, so take middle-point of tot, and place in balanced way */
+				temp= (tot->ymax + tot->ymin) * 0.5f;
+				diff= curheight * 0.5f;
+				
+				cur->ymin= temp - diff;
+				cur->ymax= temp + diff;
+			}
+			else if (cur->ymin < tot->ymin) {
 				/* there's still space remaining, so shift up */
 				temp= tot->ymin - cur->ymin;
 				
@@ -460,6 +482,9 @@
 	 * as they were causing some unwanted offsets when drawing 
 	 */
 	wmOrtho2(C->window, v2d->cur.xmin, v2d->cur.xmax, v2d->cur.ymin, v2d->cur.ymax);
+	
+	/* XXX is this necessary? */
+	wmLoadIdentity(C->window);
 }
 
 /* Set view matrices to only use one axis of 'cur' only
@@ -469,20 +494,18 @@
  */
 void UI_view2d_view_orthoSpecial(const bContext *C, View2D *v2d, short xaxis)
 {
-	ARegion *region= C->region;
-	int winx, winy;
+	ARegion *ar= C->region;
 	
-	/* calculate extents of region */
-	winx= region->winrct.xmax - region->winrct.xmin + 1;
-	winy= region->winrct.ymax - region->winrct.ymin + 1;
-	
 	/* set the matrix - pixel offsets (-0.375) for 1:1 correspondance are not applied, 
 	 * as they were causing some unwanted offsets when drawing 
 	 */
 	if (xaxis)
-		wmOrtho2(C->window, v2d->cur.xmin, v2d->cur.xmax, 0, winy);
+		wmOrtho2(C->window, v2d->cur.xmin, v2d->cur.xmax, 0, ar->winy);
 	else
-		wmOrtho2(C->window, 0, winx, v2d->cur.ymin, v2d->cur.ymax);
+		wmOrtho2(C->window, 0, ar->winx, v2d->cur.ymin, v2d->cur.ymax);
+		
+	/* XXX is this necessary? */
+	wmLoadIdentity(C->window);
 } 
 
 

Modified: branches/blender2.5/blender/source/blender/editors/space_time/space_time.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/space_time/space_time.c	2008-12-10 22:13:23 UTC (rev 17784)
+++ branches/blender2.5/blender/source/blender/editors/space_time/space_time.c	2008-12-11 03:50:50 UTC (rev 17785)
@@ -166,6 +166,12 @@
 
 /* ************************ header time area region *********************** */
 
+/* add handlers, stuff you only do once or on area/region changes */
+static void time_header_area_init(wmWindowManager *wm, ARegion *ar)
+{
+	UI_view2d_size_update(&ar->v2d, ar->winx, ar->winy);
+}
+
 static void time_header_area_draw(const bContext *C, ARegion *ar)
 {
 	float col[3];
@@ -178,8 +184,14 @@
 		
 	glClearColor(col[0], col[1], col[2], 0.0);
 	glClear(GL_COLOR_BUFFER_BIT);
-
+	
+	/* set view2d view matrix for scrolling (without scrollers) */
+	UI_view2d_view_ortho(C, &ar->v2d);
+	
 	time_header_buttons(C, ar);
+	
+	/* restore view matrix? */
+	UI_view2d_view_restore(C);
 }
 
 static void time_header_area_free(ARegion *ar)
@@ -279,8 +291,9 @@
 	art= MEM_callocN(sizeof(ARegionType), "spacetype time region");
 	art->regionid = RGN_TYPE_HEADER;
 	art->minsizey= HEADERY;
-	art->keymapflag= ED_KEYMAP_UI;
+	art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
 	
+	art->init= time_header_area_init;
 	art->draw= time_header_area_draw;
 	art->free= time_header_area_free;
 	BLI_addhead(&st->regiontypes, art);





More information about the Bf-blender-cvs mailing list