[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [49856] trunk/blender/source/blender: 2d smoothview now scales back the time to move for smaller view zoom/ panning.

Campbell Barton ideasman42 at gmail.com
Sun Aug 12 21:35:48 CEST 2012


Revision: 49856
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49856
Author:   campbellbarton
Date:     2012-08-12 19:35:47 +0000 (Sun, 12 Aug 2012)
Log Message:
-----------
2d smoothview now scales back the time to move for smaller view zoom/panning.

also the compositor bounds (used for scroll bars), were only calculated when pressing the home key in 2.63, how this is updated on draw

Modified Paths:
--------------
    trunk/blender/source/blender/editors/interface/view2d_ops.c
    trunk/blender/source/blender/editors/space_node/node_draw.c
    trunk/blender/source/blender/editors/space_node/node_view.c
    trunk/blender/source/blender/makesdna/DNA_node_types.h
    trunk/blender/source/blender/makesdna/DNA_view2d_types.h

Modified: trunk/blender/source/blender/editors/interface/view2d_ops.c
===================================================================
--- trunk/blender/source/blender/editors/interface/view2d_ops.c	2012-08-12 18:39:05 UTC (rev 49855)
+++ trunk/blender/source/blender/editors/interface/view2d_ops.c	2012-08-12 19:35:47 UTC (rev 49856)
@@ -1186,6 +1186,44 @@
 	double time_allowed;
 };
 
+/**
+ * function to get a factor out of a rectangle
+ *
+ * note: this doesn't always work as well as it might because the target size
+ *       may not be reached because of clamping the desired rect, we _could_
+ *       attempt to clamp the rect before working out the zoom factor but its
+ *       not really worthwhile for the few cases this happens.
+ */
+static float smooth_view_rect_to_fac(const rctf *rect_a, const rctf *rect_b)
+{
+	float size_a[2] = {rect_a->xmax - rect_a->xmin,
+					   rect_a->ymax - rect_a->ymin};
+	float size_b[2] = {rect_b->xmax - rect_b->xmin,
+					   rect_b->ymax - rect_b->ymin};
+	float cent_a[2] = {(rect_a->xmax + rect_a->xmin) * 0.5f,
+					   (rect_a->ymax + rect_a->ymin) * 0.5f};
+	float cent_b[2] = {(rect_b->xmax + rect_b->xmin) * 0.5f,
+					   (rect_b->ymax + rect_b->ymin) * 0.5f};
+
+	float fac_max = 0.0f;
+	float tfac;
+
+	int i;
+
+	for (i = 0; i < 2; i++) {
+		/* axis translation normalized to scale */
+		tfac = fabsf(cent_a[i] - cent_b[i]) / fmin(size_a[i], size_b[i]);
+		fac_max = fmax(fac_max, tfac);
+		if (fac_max >= 1.0f) break;
+
+		/* axis scale difference, x2 so doubling or half gives 1.0f */
+		tfac = (1.0f - (fmin(size_a[i], size_b[i]) / fmax(size_a[i], size_b[i]))) * 2.0f;
+		fac_max = fmax(fac_max, tfac);
+		if (fac_max >= 1.0f) break;
+	}
+	return fmin(fac_max, 1.0f);
+}
+
 /* will start timer if appropriate */
 /* the arguments are the desired situation */
 void UI_view2d_smooth_view(bContext *C, ARegion *ar,
@@ -1197,6 +1235,7 @@
 	View2D *v2d = &ar->v2d;
 	struct SmoothView2DStore sms = {{0}};
 	short ok = FALSE;
+	float fac = 1.0f;
 
 	/* initialize sms */
 	sms.new_cur = v2d->cur;
@@ -1204,7 +1243,11 @@
 	/* store the options we want to end with */
 	if (cur) sms.new_cur = *cur;
 
-	if (C && U.smooth_viewtx) {
+	if (cur) {
+		fac = smooth_view_rect_to_fac(&v2d->cur, cur);
+	}
+
+	if (C && U.smooth_viewtx && fac > FLT_EPSILON) {
 		int changed = 0; /* zero means no difference */
 
 		if (BLI_rctf_compare(&sms.new_cur, &v2d->cur, FLT_EPSILON) == FALSE)
@@ -1218,6 +1261,9 @@
 
 			sms.time_allowed = (double)U.smooth_viewtx / 1000.0;
 
+			/* scale the time allowed the change in view */
+			sms.time_allowed *= (double)fac;
+
 			/* keep track of running timer! */
 			if (v2d->sms == NULL)
 				v2d->sms = MEM_mallocN(sizeof(struct SmoothView2DStore), "smoothview v2d");

Modified: trunk/blender/source/blender/editors/space_node/node_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_node/node_draw.c	2012-08-12 18:39:05 UTC (rev 49855)
+++ trunk/blender/source/blender/editors/space_node/node_draw.c	2012-08-12 19:35:47 UTC (rev 49856)
@@ -1039,6 +1039,8 @@
 		node->typeinfo->drawfunc(C, ar, snode, ntree, node);
 }
 
+#define USE_DRAW_TOT_UPDATE
+
 void node_draw_nodetree(const bContext *C, ARegion *ar, SpaceNode *snode, bNodeTree *ntree)
 {
 	bNode *node;
@@ -1046,9 +1048,22 @@
 	int a;
 	
 	if (ntree == NULL) return;      /* groups... */
-	
+
+#ifdef USE_DRAW_TOT_UPDATE
+	if (ntree->nodes.first) {
+		BLI_rctf_init_minmax(&ar->v2d.tot);
+	}
+#endif
+
 	/* draw background nodes, last nodes in front */
 	for (a = 0, node = ntree->nodes.first; node; node = node->next, a++) {
+
+#ifdef USE_DRAW_TOT_UPDATE
+		/* unrelated to background nodes, update the v2d->tot,
+		 * can be anywhere before we draw the scroll bars */
+		BLI_rctf_union(&ar->v2d.tot, &node->totr);
+#endif
+
 		if (!(node->flag & NODE_BACKGROUND))
 			continue;
 		node->nr = a;        /* index of node in list, used for exec event code */

Modified: trunk/blender/source/blender/editors/space_node/node_view.c
===================================================================
--- trunk/blender/source/blender/editors/space_node/node_view.c	2012-08-12 18:39:05 UTC (rev 49855)
+++ trunk/blender/source/blender/editors/space_node/node_view.c	2012-08-12 19:35:47 UTC (rev 49856)
@@ -136,8 +136,6 @@
 	snode->yof = 0;
 
 	if (space_node_view_flag(C, snode, ar, 0)) {
-		ED_region_tag_redraw(ar);
-
 		return OPERATOR_FINISHED;
 	}
 	else {
@@ -166,8 +164,6 @@
 	SpaceNode *snode = CTX_wm_space_node(C);
 
 	if (space_node_view_flag(C, snode, ar, NODE_SELECT)) {
-		ED_region_tag_redraw(ar);
-
 		return OPERATOR_FINISHED;
 	}
 	else {

Modified: trunk/blender/source/blender/makesdna/DNA_node_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_node_types.h	2012-08-12 18:39:05 UTC (rev 49855)
+++ trunk/blender/source/blender/makesdna/DNA_node_types.h	2012-08-12 19:35:47 UTC (rev 49856)
@@ -168,7 +168,7 @@
 	void *storage;			/* custom data, must be struct, for storage in file */
 	struct bNode *original;	/* the original node in the tree (for localized tree) */
 	
-	float locx, locy;		/* root offset for drawing */
+	float locx, locy;		/* root offset for drawing (parent space) */
 	float width, height;	/* node custom width and height */
 	float miniwidth;		/* node width if hidden */
 	float offsetx, offsety;	/* additional offset from loc */
@@ -181,7 +181,7 @@
 
 	short need_exec, exec;	/* need_exec is set as UI execution event, exec is flag during exec */
 	void *threaddata;		/* optional extra storage for use in thread (read only then!) */
-	rctf totr;				/* entire boundbox */
+	rctf totr;				/* entire boundbox (worldspace) */
 	rctf butr;				/* optional buttons area */
 	rctf prvr;				/* optional preview area */
 	bNodePreview *preview;	/* optional preview image */

Modified: trunk/blender/source/blender/makesdna/DNA_view2d_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_view2d_types.h	2012-08-12 18:39:05 UTC (rev 49855)
+++ trunk/blender/source/blender/makesdna/DNA_view2d_types.h	2012-08-12 19:35:47 UTC (rev 49856)
@@ -104,6 +104,7 @@
 
 /* general refresh settings (v2d->flag) */
 	/* global view2d horizontal locking (for showing same time interval) */
+	/* TODO: this flag may be set in old files but is not accessible currently, should be exposed from RNA - Campbell */
 #define V2D_VIEWSYNC_SCREEN_TIME	(1<<0)
 	/* within area (i.e. between regions) view2d vertical locking */
 #define V2D_VIEWSYNC_AREA_VERTICAL	(1<<1)




More information about the Bf-blender-cvs mailing list