[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [46970] trunk/blender/source/blender: Graph Editor - View All/ Selected now includes handles for calculating extents of

Joshua Leung aligorith at gmail.com
Thu May 24 15:52:25 CEST 2012


Revision: 46970
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=46970
Author:   aligorith
Date:     2012-05-24 13:52:25 +0000 (Thu, 24 May 2012)
Log Message:
-----------
Graph Editor - View All/Selected now includes handles for calculating extents of
F-Curves

It is possible to get the old behaviour (handles excluded) by bringing up the
Operator Properties (F6) while in the Graph Editor (this doesn't work elsewhere
due to the context requirements of this stuff).

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_fcurve.h
    trunk/blender/source/blender/blenkernel/intern/fcurve.c
    trunk/blender/source/blender/editors/space_graph/graph_edit.c
    trunk/blender/source/blender/editors/space_graph/graph_intern.h
    trunk/blender/source/blender/editors/space_graph/space_graph.c

Modified: trunk/blender/source/blender/blenkernel/BKE_fcurve.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_fcurve.h	2012-05-24 13:31:36 UTC (rev 46969)
+++ trunk/blender/source/blender/blenkernel/BKE_fcurve.h	2012-05-24 13:52:25 UTC (rev 46970)
@@ -218,7 +218,7 @@
 
 /* get the bounding-box extents for F-Curve */
 void calc_fcurve_bounds(struct FCurve *fcu, float *xmin, float *xmax, float *ymin, float *ymax,
-                        const short do_sel_only);
+                        const short do_sel_only, const short include_handles);
 
 /* .............. */
 

Modified: trunk/blender/source/blender/blenkernel/intern/fcurve.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/fcurve.c	2012-05-24 13:31:36 UTC (rev 46969)
+++ trunk/blender/source/blender/blenkernel/intern/fcurve.c	2012-05-24 13:52:25 UTC (rev 46970)
@@ -477,7 +477,7 @@
 
 /* Calculate the extents of F-Curve's data */
 void calc_fcurve_bounds(FCurve *fcu, float *xmin, float *xmax, float *ymin, float *ymax,
-                        const short do_sel_only)
+                        const short do_sel_only, const short include_handles)
 {
 	float xminv = 999999999.0f, xmaxv = -999999999.0f;
 	float yminv = 999999999.0f, ymaxv = -999999999.0f;
@@ -495,8 +495,14 @@
 				if (bezt_first) {
 					BLI_assert(bezt_last != NULL);
 					
-					xminv = MIN2(xminv, bezt_first->vec[1][0]);
-					xmaxv = MAX2(xmaxv, bezt_last->vec[1][0]);
+					if (include_handles) {
+						xminv = MIN3(xminv, bezt_first->vec[0][0], bezt_first->vec[1][0]);
+						xmaxv = MAX3(xmaxv, bezt_last->vec[1][0],  bezt_last->vec[2][0]);
+					}
+					else {
+						xminv = MIN2(xminv, bezt_first->vec[1][0]);
+						xmaxv = MAX2(xmaxv, bezt_last->vec[1][0]);
+					}
 				}
 			}
 			
@@ -506,10 +512,15 @@
 				
 				for (bezt = fcu->bezt, i = 0; i < fcu->totvert; bezt++, i++) {
 					if ((do_sel_only == FALSE) || BEZSELECTED(bezt)) {
-						if (bezt->vec[1][1] < yminv)
-							yminv = bezt->vec[1][1];
-						if (bezt->vec[1][1] > ymaxv)
-							ymaxv = bezt->vec[1][1];
+						if (include_handles) {
+							yminv = MIN4(yminv, bezt->vec[1][1], bezt->vec[0][1], bezt->vec[2][1]);
+							ymaxv = MAX4(ymaxv, bezt->vec[1][1], bezt->vec[0][1], bezt->vec[2][1]);
+						}
+						else {
+							yminv = MIN2(yminv, bezt->vec[1][1]);
+							ymaxv = MAX2(ymaxv, bezt->vec[1][1]);
+						}
+						
 						foundvert = TRUE;
 					}
 				}
@@ -531,7 +542,7 @@
 						yminv = fpt->vec[1];
 					if (fpt->vec[1] > ymaxv)
 						ymaxv = fpt->vec[1];
-
+					
 					foundvert = TRUE;
 				}
 			}
@@ -570,20 +581,20 @@
 			
 			/* get endpoint keyframes */
 			get_fcurve_end_keyframes(fcu, &bezt_first, &bezt_last, do_sel_only);
-
+			
 			if (bezt_first) {
 				BLI_assert(bezt_last != NULL);
-
+				
 				min = MIN2(min, bezt_first->vec[1][0]);
 				max = MAX2(max, bezt_last->vec[1][0]);
-
+				
 				foundvert = TRUE;
 			}
 		}
 		else if (fcu->fpt) {
 			min = MIN2(min, fcu->fpt[0].vec[0]);
 			max = MAX2(max, fcu->fpt[fcu->totvert - 1].vec[0]);
-
+			
 			foundvert = TRUE;
 		}
 		

Modified: trunk/blender/source/blender/editors/space_graph/graph_edit.c
===================================================================
--- trunk/blender/source/blender/editors/space_graph/graph_edit.c	2012-05-24 13:31:36 UTC (rev 46969)
+++ trunk/blender/source/blender/editors/space_graph/graph_edit.c	2012-05-24 13:52:25 UTC (rev 46970)
@@ -83,7 +83,8 @@
 
 /* Get the min/max keyframes*/
 /* note: it should return total boundbox, filter for selection only can be argument... */
-void get_graph_keyframe_extents(bAnimContext *ac, float *xmin, float *xmax, float *ymin, float *ymax, const short selOnly)
+void get_graph_keyframe_extents(bAnimContext *ac, float *xmin, float *xmax, float *ymin, float *ymax, 
+                                const short do_sel_only, const short include_handles)
 {
 	ListBase anim_data = {NULL, NULL};
 	bAnimListElem *ale;
@@ -109,7 +110,7 @@
 			float unitFac;
 			
 			/* get range */
-			calc_fcurve_bounds(fcu, &txmin, &txmax, &tymin, &tymax, selOnly);
+			calc_fcurve_bounds(fcu, &txmin, &txmax, &tymin, &tymax, do_sel_only, include_handles);
 			
 			/* apply NLA scaling */
 			if (adt) {
@@ -169,7 +170,7 @@
 		scene = ac.scene;
 	
 	/* set the range directly */
-	get_graph_keyframe_extents(&ac, &min, &max, NULL, NULL, FALSE);
+	get_graph_keyframe_extents(&ac, &min, &max, NULL, NULL, FALSE, FALSE);
 	scene->r.flag |= SCER_PRV_RANGE;
 	scene->r.psfra = (int)floor(min + 0.5f);
 	scene->r.pefra = (int)floor(max + 0.5f);
@@ -198,7 +199,7 @@
 
 /* ****************** View-All Operator ****************** */
 
-static int graphkeys_viewall(bContext *C, const short selOnly)
+static int graphkeys_viewall(bContext *C, const short do_sel_only, const short include_handles)
 {
 	bAnimContext ac;
 	View2D *v2d;
@@ -210,7 +211,10 @@
 	v2d = &ac.ar->v2d;
 
 	/* set the horizontal range, with an extra offset so that the extreme keys will be in view */
-	get_graph_keyframe_extents(&ac, &v2d->cur.xmin, &v2d->cur.xmax, &v2d->cur.ymin, &v2d->cur.ymax, selOnly);
+	get_graph_keyframe_extents(&ac, 
+	                           &v2d->cur.xmin, &v2d->cur.xmax, 
+							   &v2d->cur.ymin, &v2d->cur.ymax, 
+							   do_sel_only, include_handles);
 
 	extra = 0.1f * (v2d->cur.xmax - v2d->cur.xmin);
 	v2d->cur.xmin -= extra;
@@ -231,16 +235,20 @@
 
 /* ......... */
 
-static int graphkeys_viewall_exec(bContext *C, wmOperator *UNUSED(op))
+static int graphkeys_viewall_exec(bContext *C, wmOperator *op)
 {
+	short include_handles = RNA_boolean_get(op->ptr, "include_handles");
+	
 	/* whole range */
-	return graphkeys_viewall(C, FALSE);
+	return graphkeys_viewall(C, FALSE, include_handles);
 }
  
-static int graphkeys_view_selected_exec(bContext *C, wmOperator *UNUSED(op))
+static int graphkeys_view_selected_exec(bContext *C, wmOperator *op)
 {
+	short include_handles = RNA_boolean_get(op->ptr, "include_handles");
+	
 	/* only selected */
-	return graphkeys_viewall(C, TRUE);
+	return graphkeys_viewall(C, TRUE, include_handles);
 }
 
 void GRAPH_OT_view_all(wmOperatorType *ot)
@@ -256,6 +264,10 @@
 	
 	/* flags */
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+	
+	/* props */
+	ot->prop = RNA_def_boolean(ot->srna, "include_handles", TRUE, "Include Handles", 
+	                           "Include handles of keyframes when calculating extents");
 }
 
 void GRAPH_OT_view_selected(wmOperatorType *ot)
@@ -271,6 +283,10 @@
 
 	/* flags */
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+	
+	/* props */
+	ot->prop = RNA_def_boolean(ot->srna, "include_handles", TRUE, "Include Handles", 
+	                           "Include handles of keyframes when calculating extents");
 }
 
 /* ******************** Create Ghost-Curves Operator *********************** */

Modified: trunk/blender/source/blender/editors/space_graph/graph_intern.h
===================================================================
--- trunk/blender/source/blender/editors/space_graph/graph_intern.h	2012-05-24 13:31:36 UTC (rev 46969)
+++ trunk/blender/source/blender/editors/space_graph/graph_intern.h	2012-05-24 13:52:25 UTC (rev 46970)
@@ -86,7 +86,8 @@
 /* ***************************************** */
 /* graph_edit.c */
 
-void get_graph_keyframe_extents(struct bAnimContext *ac, float *xmin, float *xmax, float *ymin, float *ymax, const short do_selected);
+void get_graph_keyframe_extents(struct bAnimContext *ac, float *xmin, float *xmax, float *ymin, float *ymax, 
+                                const short do_selected, const short include_handles);
 
 void GRAPH_OT_previewrange_set(struct wmOperatorType *ot);
 void GRAPH_OT_view_all(struct wmOperatorType *ot);

Modified: trunk/blender/source/blender/editors/space_graph/space_graph.c
===================================================================
--- trunk/blender/source/blender/editors/space_graph/space_graph.c	2012-05-24 13:31:36 UTC (rev 46969)
+++ trunk/blender/source/blender/editors/space_graph/space_graph.c	2012-05-24 13:52:25 UTC (rev 46970)
@@ -250,7 +250,7 @@
 		graph_draw_curves(&ac, sipo, ar, grid, 1);
 		
 		/* XXX the slow way to set tot rect... but for nice sliders needed (ton) */
-		get_graph_keyframe_extents(&ac, &v2d->tot.xmin, &v2d->tot.xmax, &v2d->tot.ymin, &v2d->tot.ymax, FALSE);
+		get_graph_keyframe_extents(&ac, &v2d->tot.xmin, &v2d->tot.xmax, &v2d->tot.ymin, &v2d->tot.ymax, FALSE, TRUE);
 		/* extra offset so that these items are visible */
 		v2d->tot.xmin -= 10.0f;
 		v2d->tot.xmax += 10.0f;




More information about the Bf-blender-cvs mailing list