[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [17737] branches/blender2.5/blender/source /blender: View2D: Scroller Manipulations

Joshua Leung aligorith at gmail.com
Sun Dec 7 13:15:05 CET 2008


Revision: 17737
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17737
Author:   aligorith
Date:     2008-12-07 13:15:04 +0100 (Sun, 07 Dec 2008)

Log Message:
-----------
View2D: Scroller Manipulations

Implemented operator to work with scrollers. This should work reasonably well, but as always, more testing is needed.
* LMB-drag can now be used to initiate manipulations of scrollbars (so they can be dragged as per normal)
* By clicking on the 'dark regions' on the ends of the scroll bubble, it is possible to zoom the view (in a way similar to Sony Vegas scrollbars)

Tidied up code of other operators
* Re-labelled the current zoom operators, as there is still a modal click-drag zoom tool to be ported still
* Marked all of the existing view manipulation operators as redoable. Scrollers manipulator is not allowed to be redoable. 

Assorted changes:
* Added more flags for Outliner on reading old files, to prevent more weird things happening as code expects certain flags these days

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/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-07 10:55:33 UTC (rev 17736)
+++ branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c	2008-12-07 12:15:04 UTC (rev 17737)
@@ -5078,6 +5078,7 @@
 				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);
+				ar->v2d.keepzoom |= (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y);
 			}
 				break;
 			case SPACE_TIME:

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-07 10:55:33 UTC (rev 17736)
+++ branches/blender2.5/blender/source/blender/editors/include/UI_view2d.h	2008-12-07 12:15:04 UTC (rev 17737)
@@ -33,7 +33,7 @@
 #define UI_VIEW2D_H
 
 /* ------------------------------------------ */
-/* Settings: 								*/
+/* Settings and Defines: 					*/
 
 /* generic value to use when coordinate lies out of view when converting */
 #define V2D_IS_CLIPPED	12000
@@ -41,6 +41,7 @@
 /* 'dummy' argument to pass when argument is irrelevant */
 #define V2D_ARG_DUMMY		-1
 
+
 /* grid-units (for drawing time) */
 #define V2D_UNIT_SECONDS	0
 #define V2D_UNIT_FRAMES		1

Modified: branches/blender2.5/blender/source/blender/editors/interface/view2d.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/interface/view2d.c	2008-12-07 10:55:33 UTC (rev 17736)
+++ branches/blender2.5/blender/source/blender/editors/interface/view2d.c	2008-12-07 12:15:04 UTC (rev 17737)
@@ -732,7 +732,10 @@
 /* *********************************************************************** */
 /* Scrollbars */
 
-/* View2DScrollers is typedef'd in UI_view2d.h */
+/* View2DScrollers is typedef'd in UI_view2d.h 
+ * WARNING: the start of this struct must not change, as view2d_ops.c uses this too. 
+ * 		   For now, we don't need to have a separate (internal) header for structs like this...
+ */
 struct View2DScrollers {	
 		/* focus bubbles */
 	int vert_min, vert_max;	/* vertical scrollbar */
@@ -769,11 +772,11 @@
 		scrollsize= hor.xmax - hor.xmin;
 		
 		fac= (v2d->cur.xmin- v2d->tot.xmin) / totsize;
-		//if (fac < 0.0f) fac= 0.0f;
+		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;
+		if (fac > 1.0f) fac= 1.0f;
 		scrollers->hor_max= hor.xmin + (fac * scrollsize);
 		
 		if (scrollers->hor_min > scrollers->hor_max) 
@@ -787,11 +790,11 @@
 		scrollsize= vert.ymax - vert.ymin;
 		
 		fac= (v2d->cur.ymin- v2d->tot.ymin) / totsize;
-		//if (fac < 0.0f) fac= 0.0f;
+		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;
+		if (fac > 1.0f) fac= 1.0f;
 		scrollers->vert_max= vert.ymin + (fac * scrollsize);
 		
 		if (scrollers->vert_min > scrollers->vert_max) 
@@ -806,11 +809,15 @@
 		scrollers->yclamp= yclamp;
 		scrollers->yunits= yunits;
 		
-		/* calculate grid */
-		if (v2d->scroll & V2D_SCROLL_SCALE_HORIZONTAL)
-			scrollers->grid= UI_view2d_grid_calc(C, v2d, xunits, xclamp, (hor.xmax - hor.xmin), (vert.ymax - vert.ymin));
-		else if (v2d->scroll & V2D_SCROLL_SCALE_VERTICAL)
-			scrollers->grid= UI_view2d_grid_calc(C, v2d, yunits, yclamp, (hor.xmax - hor.xmin), (vert.ymax - vert.ymin));
+		/* calculate grid only if clamping + units are valid arguments */
+		if ( !((xclamp == V2D_ARG_DUMMY) && (xunits == V2D_ARG_DUMMY) && (yclamp == V2D_ARG_DUMMY) && (yunits == V2D_ARG_DUMMY)) ) { 
+			/* if both axes show scale, give priority to horizontal.. */
+			// FIXME: this doesn't do justice to the vertical scroller calculations...
+			if (v2d->scroll & V2D_SCROLL_SCALE_HORIZONTAL)
+				scrollers->grid= UI_view2d_grid_calc(C, v2d, xunits, xclamp, (hor.xmax - hor.xmin), (vert.ymax - vert.ymin));
+			else if (v2d->scroll & V2D_SCROLL_SCALE_VERTICAL)
+				scrollers->grid= UI_view2d_grid_calc(C, v2d, yunits, yclamp, (hor.xmax - hor.xmin), (vert.ymax - vert.ymin));
+		}
 	}
 	
 	/* return scrollers */

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-07 10:55:33 UTC (rev 17736)
+++ branches/blender2.5/blender/source/blender/editors/interface/view2d_ops.c	2008-12-07 12:15:04 UTC (rev 17737)
@@ -98,7 +98,6 @@
  
 /* temp customdata for operator */
 typedef struct v2dViewPanData {
-	ARegion *region;		/* region we're operating in */
 	View2D *v2d;			/* view2d we're operating in */
 	
 	float facx, facy;		/* amount to move view relative to zoom */
@@ -107,7 +106,7 @@
 	int startx, starty;		/* mouse x/y values in window when operator was initiated */
 	int lastx, lasty;		/* previous x/y values of mouse in window */
 	
-	short in_scroller;		/* activated in scrollbar */
+	short in_scroller;		/* for MMB in scrollers (old feature in past, but now not that useful) */
 } v2dViewPanData;
  
 /* initialise panning customdata */
@@ -121,13 +120,13 @@
 	/* regions now have v2d-data by default, so check for region */
 	if (C->region == NULL)
 		return 0;
+	ar= C->region;
 	
 	/* set custom-data for operator */
 	vpd= MEM_callocN(sizeof(v2dViewPanData), "v2dViewPanData");
 	op->customdata= vpd;
 	
 	/* set pointers to owners */
-	vpd->region= ar= C->region;
 	vpd->v2d= v2d= &ar->v2d;
 	
 	/* calculate translation factor - based on size of view */
@@ -160,6 +159,9 @@
 		v2d->cur.ymax += dy;
 	}
 	
+	/* validate that view is in valid configuration after this operation */
+	UI_view2d_status_enforce(v2d);
+	
 	/* request updates to be done... */
 	WM_event_add_notifier(C, WM_NOTE_AREA_REDRAW, 0, NULL);
 	/* XXX: add WM_NOTE_TIME_CHANGED? */
@@ -299,6 +301,9 @@
 	ot->invoke= view_pan_invoke;
 	ot->modal= view_pan_modal;
 	
+	/* operator is repeatable */
+	ot->flag= OPTYPE_REGISTER;
+	
 	/* rna - must keep these in sync with the other operators */
 	prop= RNA_def_property(ot->srna, "deltax", PROP_INT, PROP_NONE);
 	prop= RNA_def_property(ot->srna, "deltay", PROP_INT, PROP_NONE);
@@ -335,6 +340,9 @@
 	/* api callbacks */
 	ot->exec= view_scrollright_exec;
 	
+	/* operator is repeatable */
+	ot->flag= OPTYPE_REGISTER;
+	
 	/* rna - must keep these in sync with the other operators */
 	prop= RNA_def_property(ot->srna, "deltax", PROP_INT, PROP_NONE);
 	prop= RNA_def_property(ot->srna, "deltay", PROP_INT, PROP_NONE);
@@ -371,6 +379,9 @@
 	/* api callbacks */
 	ot->exec= view_scrollleft_exec;
 	
+	/* operator is repeatable */
+	ot->flag= OPTYPE_REGISTER;
+	
 	/* rna - must keep these in sync with the other operators */
 	prop= RNA_def_property(ot->srna, "deltax", PROP_INT, PROP_NONE);
 	prop= RNA_def_property(ot->srna, "deltay", PROP_INT, PROP_NONE);
@@ -405,6 +416,9 @@
 	/* api callbacks */
 	ot->exec= view_scrolldown_exec;
 	
+	/* operator is repeatable */
+	ot->flag= OPTYPE_REGISTER;
+	
 	/* rna - must keep these in sync with the other operators */
 	prop= RNA_def_property(ot->srna, "deltax", PROP_INT, PROP_NONE);
 	prop= RNA_def_property(ot->srna, "deltay", PROP_INT, PROP_NONE);
@@ -441,60 +455,34 @@
 	/* api callbacks */
 	ot->exec= view_scrollup_exec;
 	
+	/* operator is repeatable */
+	ot->flag= OPTYPE_REGISTER;
+	
 	/* rna - must keep these in sync with the other operators */
 	prop= RNA_def_property(ot->srna, "deltax", PROP_INT, PROP_NONE);
 	prop= RNA_def_property(ot->srna, "deltay", PROP_INT, PROP_NONE);
 }
 
 /* ********************************************************* */
-/* VIEW ZOOMING OPERATOR								 */
+/* SINGLE-STEP VIEW ZOOMING OPERATOR						 */
 
 /* 	This group of operators come in several forms:
- *		1) Modal 'dragging' with MMB - where movement of mouse dictates amount to zoom view by
- *		2) Scrollwheel 'steps' - rolling mousewheel by one step moves view by predefined amount
+ *		1) Scrollwheel 'steps' - rolling mousewheel by one step zooms view by predefined amount
+ *		2) Scrollwheel 'steps' + alt + ctrl/shift - zooms view on one axis only (ctrl=x, shift=y)  // XXX this could be implemented...
  *		3) Pad +/- Keys - pressing each key moves the zooms the view by a predefined amount
  *
  *	In order to make sure this works, each operator must define the following RNA-Operator Props:
- *		zoomfacx, zoomfacy	- sometimes it's still useful to have non-uniform scaling  
+ *		zoomfacx, zoomfacy	- These two zoom factors allow for non-uniform scaling.
+ *							  It is safe to scale by 0, as these factors are used to determine
+ *							  amount to enlarge 'cur' by
  */
 
-/* ------------------ Shared 'core' stuff ---------------------- */
-
-/* temp customdata for operator */
-typedef struct v2dViewZoomData {
-	ARegion *region;		/* region we're operating in */
-	View2D *v2d;			/* view2d we're operating in */
-	
-	int startx, starty;		/* mouse x/y values in window when operator was initiated */
-	int lastx, lasty;		/* previous x/y values of mouse in window */
-} v2dViewZoomData;
+/* ------------------ 'Shared' stuff ------------------------ */
  
-/* initialise zooming customdata */
-static int view_zoom_init(bContext *C, wmOperator *op)
-{
-	v2dViewZoomData *vzd;
-	ARegion *ar;
-	
-	/* regions now have v2d-data by default, so check for region */
-	if (C->region == NULL)
-		return 0;
-	
-	/* set custom-data for operator */
-	vzd= MEM_callocN(sizeof(v2dViewZoomData), "v2dViewZoomData");
-	op->customdata= vzd;
-	
-	/* set pointers to owners */
-	vzd->region= ar= C->region;
-	vzd->v2d= &ar->v2d;
-	
-	return 1;
-}
-
 /* apply transform to view (i.e. adjust 'cur' rect) */
 static void view_zoom_apply(bContext *C, wmOperator *op)
 {
-	v2dViewZoomData *vzd= op->customdata;
-	View2D *v2d= vzd->v2d;
+	View2D *v2d= &C->region->v2d;
 	float dx, dy;
 	
 	/* calculate amount to move view by */
@@ -502,7 +490,6 @@
 	dy= (v2d->cur.ymax - v2d->cur.ymin) * (float)RNA_float_get(op->ptr, "zoomfacy");
 	
 	/* only move view on an axis if change is allowed */
-	// FIXME: this still only allows for zooming around 'center' of view... userdefined center is more useful!
 	if ((v2d->keepofs & V2D_LOCKOFS_X)==0) {

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list