Graph Editor - View All/Selected now includes handles for calculating extents of
authorJoshua Leung <aligorith@gmail.com>
Thu, 24 May 2012 13:52:25 +0000 (13:52 +0000)
committerJoshua Leung <aligorith@gmail.com>
Thu, 24 May 2012 13:52:25 +0000 (13:52 +0000)
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).

source/blender/blenkernel/BKE_fcurve.h
source/blender/blenkernel/intern/fcurve.c
source/blender/editors/space_graph/graph_edit.c
source/blender/editors/space_graph/graph_intern.h
source/blender/editors/space_graph/space_graph.c

index 9dae38d0a659909a21c8bd9e66888a327e6bf0c4..f7aa4470c1973ae66e1d89080a43e6a29484bbb8 100644 (file)
@@ -218,7 +218,7 @@ void calc_fcurve_range(struct FCurve *fcu, float *min, float *max,
 
 /* 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);
 
 /* .............. */
 
index 2a0f49262bc8dfecc24cf054965389fa71a26aee..e20a74e713cb6987839cbf61837d4ab16129ba8a 100644 (file)
@@ -477,7 +477,7 @@ static void get_fcurve_end_keyframes(FCurve *fcu, BezTriple **first, BezTriple *
 
 /* 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 @@ void calc_fcurve_bounds(FCurve *fcu, float *xmin, float *xmax, float *ymin, floa
                                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 @@ void calc_fcurve_bounds(FCurve *fcu, float *xmin, float *xmax, float *ymin, floa
                                
                                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 @@ void calc_fcurve_bounds(FCurve *fcu, float *xmin, float *xmax, float *ymin, floa
                                                yminv = fpt->vec[1];
                                        if (fpt->vec[1] > ymaxv)
                                                ymaxv = fpt->vec[1];
-
+                                       
                                        foundvert = TRUE;
                                }
                        }
@@ -570,20 +581,20 @@ void calc_fcurve_range(FCurve *fcu, float *start, float *end,
                        
                        /* 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;
                }
                
index 2d9a7baa21357a59affccc18ae8abae1b79001d3..4b5f4f5cc2e20de4be7508c76407e2e5a577bb87 100644 (file)
@@ -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 @@ void get_graph_keyframe_extents(bAnimContext *ac, float *xmin, float *xmax, floa
                        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 @@ static int graphkeys_previewrange_exec(bContext *C, wmOperator *UNUSED(op))
                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 @@ void GRAPH_OT_previewrange_set(wmOperatorType *ot)
 
 /* ****************** 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 @@ static int graphkeys_viewall(bContext *C, const short selOnly)
        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(bContext *C, const short selOnly)
 
 /* ......... */
 
-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 @@ void GRAPH_OT_view_all(wmOperatorType *ot)
        
        /* 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 @@ void GRAPH_OT_view_selected(wmOperatorType *ot)
 
        /* 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 *********************** */
index 47b55ae90ab3266e9ce193337009f6f329e72577..eb657169970e0b74047d8c29c3661d4732b9b5b0 100644 (file)
@@ -86,7 +86,8 @@ enum {
 /* ***************************************** */
 /* 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);
index ffff86df4eb560c2a3be8261076b0ea60a5c6d80..756e6997fc817e48ad23b5ebcd7a75adf56e83f1 100644 (file)
@@ -250,7 +250,7 @@ static void graph_main_area_draw(const bContext *C, ARegion *ar)
                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;