diff options
author | Joshua Leung <aligorith@gmail.com> | 2012-05-24 17:52:25 +0400 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2012-05-24 17:52:25 +0400 |
commit | 240babf07423d5efcb85edbe8e8d2571e8e163b8 (patch) | |
tree | 79b4a5c932b9eb3e9f3ebf34267f377310bacf82 /source | |
parent | 9abd6e76515006214c0bd8d0d412c89baf88a8b1 (diff) |
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).
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_fcurve.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/fcurve.c | 35 | ||||
-rw-r--r-- | source/blender/editors/space_graph/graph_edit.c | 34 | ||||
-rw-r--r-- | source/blender/editors/space_graph/graph_intern.h | 3 | ||||
-rw-r--r-- | source/blender/editors/space_graph/space_graph.c | 2 |
5 files changed, 52 insertions, 24 deletions
diff --git a/source/blender/blenkernel/BKE_fcurve.h b/source/blender/blenkernel/BKE_fcurve.h index 9dae38d0a65..f7aa4470c19 100644 --- a/source/blender/blenkernel/BKE_fcurve.h +++ b/source/blender/blenkernel/BKE_fcurve.h @@ -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); /* .............. */ diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c index 2a0f49262bc..e20a74e713c 100644 --- a/source/blender/blenkernel/intern/fcurve.c +++ b/source/blender/blenkernel/intern/fcurve.c @@ -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; } diff --git a/source/blender/editors/space_graph/graph_edit.c b/source/blender/editors/space_graph/graph_edit.c index 2d9a7baa213..4b5f4f5cc2e 100644 --- a/source/blender/editors/space_graph/graph_edit.c +++ b/source/blender/editors/space_graph/graph_edit.c @@ -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 *********************** */ diff --git a/source/blender/editors/space_graph/graph_intern.h b/source/blender/editors/space_graph/graph_intern.h index 47b55ae90ab..eb657169970 100644 --- a/source/blender/editors/space_graph/graph_intern.h +++ b/source/blender/editors/space_graph/graph_intern.h @@ -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); diff --git a/source/blender/editors/space_graph/space_graph.c b/source/blender/editors/space_graph/space_graph.c index ffff86df4eb..756e6997fc8 100644 --- a/source/blender/editors/space_graph/space_graph.c +++ b/source/blender/editors/space_graph/space_graph.c @@ -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; |