[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [17662] branches/blender2.5/blender/source /blender: View2D - Zoom + More Scrollbar work

Joshua Leung aligorith at gmail.com
Mon Dec 1 12:37:07 CET 2008


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

Log Message:
-----------
View2D - Zoom + More Scrollbar work

* Added basic (non-modal) zoom operators that use a uniform scale factor, with zoom centered using the view center as scaling point. Use Scrollwheel up/down and Pad +/- to use this.

* Added back the 'button'/bubble for the scrollbars. I've added dark lines on either end of it for some later work on zooming widgets.
This is not the final form they'll take. I still need to decide how to handle those scrollbars which act as grid-markers too (showing timescale, etc.), before trying to integrate that with some fancy scrollbar drawing (rounded, etc.)

Assorted changes:
* Moved vertical scrollbar for Outliner to right hand side
* Made Timeline use standard scrollbars, and turned on various clamping options
* Fixed ortho-matrix corrections for scrollbars, and added pixel offsets
* Made Timeline markers sit more snugly on the scrollbar. They were a bit far out...
* Fixed memory leak with view2d keymaps not being freed when Blender exited

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_outliner/space_outliner.c
    branches/blender2.5/blender/source/blender/editors/space_time/ed_markers.c
    branches/blender2.5/blender/source/blender/editors/space_time/space_time.c
    branches/blender2.5/blender/source/blender/makesdna/DNA_screen_types.h
    branches/blender2.5/blender/source/blender/makesdna/DNA_view2d_types.h
    branches/blender2.5/blender/source/blender/windowmanager/intern/wm.c

Modified: branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c	2008-12-01 11:14:33 UTC (rev 17661)
+++ branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c	2008-12-01 11:37:05 UTC (rev 17662)
@@ -5073,12 +5073,26 @@
 		/* if active spacetype has view2d data, copy that over to main region */
 		switch(sa->spacetype) {
 			case SPACE_OOPS:
-				memcpy(&ar->v2d, &((SpaceOops *)sa->spacedata.first)->v2d, sizeof(View2D));
+			{
+				SpaceOops *soops= sa->spacedata.first;
+				
+				memcpy(&ar->v2d, &soops->v2d, sizeof(View2D));
+				ar->v2d.scroll &= ~L_SCROLL;
+				ar->v2d.scroll |= R_SCROLL;
+			}
 				break;
 			case SPACE_TIME:
-				memcpy(&ar->v2d, &((SpaceTime *)sa->spacedata.first)->v2d, sizeof(View2D));
+			{
+				SpaceTime *stime= sa->spacedata.first;
+				memcpy(&ar->v2d, &stime->v2d, sizeof(View2D));
+				
+				ar->v2d.scroll |= (B_SCROLL|BGRID_SCROLL);
+				ar->v2d.keepofs |= V2D_LOCKOFS_Y;
+			}
 				break;
 			//case SPACE_XXX: // FIXME... add other ones
+			//	memcpy(&ar->v2d, &((SpaceXxx *)sa->spacedata.first)->v2d, sizeof(View2D));
+			//	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-01 11:14:33 UTC (rev 17661)
+++ branches/blender2.5/blender/source/blender/editors/include/UI_view2d.h	2008-12-01 11:37:05 UTC (rev 17662)
@@ -93,7 +93,7 @@
 /* scrollbar drawing */
 View2DScrollers *UI_view2d_calc_scrollers(const struct bContext *C, struct View2D *v2d, short units, short clamp);
 void UI_view2d_draw_scrollers(const struct bContext *C, struct View2D *v2d, View2DScrollers *scrollers, int flag);
-void UI_view2d_free_scrollbars(View2DScrollers *scrollers);
+void UI_view2d_free_scrollers(View2DScrollers *scrollers);
 
 /* coordinate conversion */
 void UI_view2d_region_to_view(struct View2D *v2d, short x, short y, float *viewx, float *viewy);

Modified: branches/blender2.5/blender/source/blender/editors/interface/view2d.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/interface/view2d.c	2008-12-01 11:14:33 UTC (rev 17661)
+++ branches/blender2.5/blender/source/blender/editors/interface/view2d.c	2008-12-01 11:37:05 UTC (rev 17662)
@@ -48,33 +48,33 @@
 /* *********************************************************************** */
 /* Setup and Refresh Code */
 
-
-/* ---------------------- */
-
 /* Set view matrices to ortho for View2D drawing */
 void UI_view2d_view_ortho(const bContext *C, View2D *v2d)
 {
 	ARegion *region= C->region;
 	int winx, winy;
-	float ofsx, ofsy;
+	float ofsx1, ofsy1, ofsx2, ofsy2;
 	
 	/* calculate extents of region */
 	winx= region->winrct.xmax - region->winrct.xmin;
 	winy= region->winrct.ymax - region->winrct.ymin;
-	ofsx= ofsy= 0.0f;
+	ofsx1= ofsy1= ofsx2= ofsy2= 0.0f;
 	
 	/* these checks here make sure that the region is large-enough to show scrollers */
 	if ((winx > SCROLLB+10) && (winy > SCROLLH+10)) {
-		if (v2d->scroll) {
-			if (v2d->scroll & (HOR_SCROLL|HOR_SCROLLO))
-				ofsy= (float)-SCROLLB;
-			if (v2d->scroll & VERT_SCROLL)
-				ofsx= (float)-SCROLLH;
-		}
+		/* calculate offset factor required on each axis */
+		if (v2d->scroll & L_SCROLL)
+			ofsy1= (float)SCROLLB;
+		if (v2d->scroll & R_SCROLL)
+			ofsy2= (float)SCROLLB;
+		if (v2d->scroll & T_SCROLL)
+			ofsx1= (float)SCROLLH;
+		if (v2d->scroll & B_SCROLL)
+			ofsx2= (float)SCROLLH;
 	}
 	
 	/* note: 0.375 is constant factor to get 1:1 correspondance with pixels */
-	wmOrtho2(C->window, v2d->cur.xmin+ofsx-0.375f, v2d->cur.xmax-0.375f, v2d->cur.ymin+ofsy-0.375f, v2d->cur.ymax-0.375f);
+	wmOrtho2(C->window, v2d->cur.xmin-ofsx1-0.375f, v2d->cur.xmax-ofsx2-0.375f, v2d->cur.ymin-ofsy1-0.375f, v2d->cur.ymax-ofsx2-0.375f);
 }
 
 /* Restore view matrices after drawing */
@@ -590,19 +590,61 @@
 struct View2DScrollers {
 	View2DGrid *grid;		/* grid for coordinate drawing */
 	
-	int vertmin, vertmax;	/* vertical scrollbar - current 'focus' button */
-	int hormin, hormax;		/* horizontal scrollbar - current 'focus' button */
+	int vert_min, vert_max;	/* vertical scrollbar - current 'focus' button */
+	int hor_min, hor_max;		/* horizontal scrollbar - current 'focus' button */
 };
 
+/* Calculate relevant scroller properties */
 View2DScrollers *UI_view2d_calc_scrollers(const bContext *C, View2D *v2d, short units, short clamp)
 {
 	View2DScrollers *scrollers;
+	rcti vert, hor;
+	float fac, totsize, scrollsize;
 	
+	vert= v2d->vert;
+	hor= v2d->hor;
+	
 	/* scrollers is allocated here... */
 	scrollers= MEM_callocN(sizeof(View2DScrollers), "View2DScrollers");
 	
-	// ... add some stuff here...
+	/* slider 'buttons':
+	 *	- These should always remain within the visible region of the scrollbar
+	 *	- They represent the region of 'tot' that is visible in 'cur'
+	 */
+	/* slider 'button' extents - horizontal */
+	if (v2d->scroll & (HOR_SCROLL|HOR_SCROLLO)) {
+		totsize= v2d->tot.xmax - v2d->tot.xmin;
+		scrollsize= hor.xmax - hor.xmin;
+		
+		fac= (v2d->cur.xmin- v2d->tot.xmin) / totsize;
+		//if (fac < 0.0f) fac= 0.0f;
+		scrollers->hor_min= hor.xmin + (fac * scrollsize);
+		
+		fac= (v2d->cur.xmax - v2d->tot.xmin) / totsize;
+		//if (fac > 1.0f) fac= 1.0f;
+		scrollers->hor_max= hor.xmin + (fac * scrollsize);
+		
+		if (scrollers->hor_min > scrollers->hor_max) 
+			scrollers->hor_min= scrollers->hor_max;
+	}
 	
+	/* slider 'button' extents - vertical */
+	if (v2d->scroll & VERT_SCROLL) {
+		totsize= v2d->tot.ymax - v2d->tot.ymin;
+		scrollsize= vert.ymax - vert.ymin;
+		
+		fac= (v2d->cur.ymin- v2d->tot.ymin) / totsize;
+		//if (fac < 0.0f) fac= 0.0f;
+		scrollers->vert_min= vert.ymin + (fac * scrollsize);
+		
+		fac= (v2d->cur.ymax - v2d->tot.ymin) / totsize;
+		//if (fac > 1.0f) fac= 1.0f;
+		scrollers->vert_max= vert.ymin + (fac * scrollsize);
+		
+		if (scrollers->vert_min > scrollers->vert_max) 
+			scrollers->vert_min= scrollers->vert_max;
+	}
+	
 	return scrollers;
 }
 
@@ -611,20 +653,29 @@
 void UI_view2d_draw_scrollers(const bContext *C, View2D *v2d, View2DScrollers *scrollers, int flag)
 {
 	const int darker= -40, dark= 0, light= 20, lighter= 50;
-	float fac, dfac, val, fac2, tim;
 	rcti vert, hor;
 	
 	vert= v2d->vert;
 	hor= v2d->hor;
 	
 	/* horizontal scrollbar */
-	if ((v2d->scroll & HOR_SCROLL) || (v2d->scroll & HOR_SCROLLO)) {
+	if (v2d->scroll & (HOR_SCROLL|HOR_SCROLLO)) {
 		/* scroller backdrop */
 		UI_ThemeColorShade(TH_SHADE1, light);
 		glRecti(hor.xmin,  hor.ymin,  hor.xmax,  hor.ymax);
 		
-		// FIXME: add slider bar
+		/* slider 'button' */
+			// 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);
 		
+			/* 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);
+		glLineWidth(1.0);
+		
 		/* decoration bright line */
 		UI_ThemeColorShade(TH_SHADE1, lighter);
 		sdrawline(hor.xmin, hor.ymax, hor.xmax, hor.ymax);
@@ -636,6 +687,18 @@
 		UI_ThemeColorShade(TH_SHADE1, light);
 		glRecti(vert.xmin,  vert.ymin,  vert.xmax,  vert.ymax);
 		
+		/* slider 'button' */
+			// FIXME: implement fancy one... but only when we get this working first!
+		UI_ThemeColorShade(TH_SHADE1, dark);
+		glRecti(vert.xmin,  scrollers->vert_min,  vert.xmax,  scrollers->vert_max);
+		
+			/* draw lines on either end of 'box' */
+		glLineWidth(2.0);
+			UI_ThemeColorShade(TH_SHADE1, darker);
+			sdrawline(vert.xmin, scrollers->vert_min, vert.xmax, scrollers->vert_min);
+			sdrawline(vert.xmin, scrollers->vert_max, vert.xmax, scrollers->vert_max);
+		glLineWidth(1.0);
+		
 		/* decoration black line */
 		UI_ThemeColorShade(TH_SHADE1, darker);
 		if (v2d->scroll & HOR_SCROLL) 

Modified: branches/blender2.5/blender/source/blender/editors/interface/view2d_ops.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/interface/view2d_ops.c	2008-12-01 11:14:33 UTC (rev 17661)
+++ branches/blender2.5/blender/source/blender/editors/interface/view2d_ops.c	2008-12-01 11:37:05 UTC (rev 17662)
@@ -54,13 +54,12 @@
 /* 	This group of operators come in several forms:
  *		1) Modal 'dragging' with MMB - where movement of mouse dictates amount to pan view by
  *		2) Scrollwheel 'steps' - rolling mousewheel by one step moves view by predefined amount
- *		3) Scroller drag - similar to 1), but only while mouse is still in view
  *
  *	In order to make sure this works, each operator must define the following RNA-Operator Props:
  *		deltax, deltay 	- define how much to move view by (relative to zoom-correction factor)
  */
 
- /* ------------------ Shared 'core' stuff ---------------------- */
+/* ------------------ Shared 'core' stuff ---------------------- */
  
 /* temp customdata for operator */
 typedef struct v2dViewPanData {
@@ -92,7 +91,7 @@
 	
 	/* set pointers to owners */
 	vpd->region= ar= C->region;
-	vpd->v2d= v2d= &C->region->v2d;
+	vpd->v2d= v2d= &ar->v2d;
 	
 	/* calculate translation factor - based on size of view */
 	winx= (float)(ar->winrct.xmax - ar->winrct.xmin);
@@ -241,8 +240,8 @@
 }
 
 /* ------------------ Scrollwheel Versions (2) ---------------------- */
-// XXX should these be unified a bit?
 
+// XXX scroll down operator not working yet! (doesn't get called on wheeldownmouse for some reason)
 /* this operator only needs this single callback, where it callsthe view_pan_*() methods */
 static int view_scrollright_exec(bContext *C, wmOperator *op)
 {
@@ -313,7 +312,7 @@
 	prop= RNA_def_property(ot->srna, "deltay", PROP_INT, PROP_NONE);
 }
 
-
+// XXX scroll down operator not working yet! (doesn't get called on wheeldownmouse for some reason)
 /* this operator only needs this single callback, where it callsthe view_pan_*() methods */
 static int view_scrolldown_exec(bContext *C, wmOperator *op)
 {
@@ -385,6 +384,161 @@
 }
 
 /* ********************************************************* */
+/* VIEW ZOOMING OPERATOR								 */
+

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list