diff options
author | Joshua Leung <aligorith@gmail.com> | 2009-02-10 13:42:04 +0300 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2009-02-10 13:42:04 +0300 |
commit | 6f2d5b8e8ac244509b5c4d4a0633d12bfb867b44 (patch) | |
tree | ea63c8276d6cc425737c01c1761a6f8d0db01746 /source/blender/blenkernel | |
parent | c519d69a607ca41863092ab1a61bb84239b93719 (diff) |
Graph Editor: Restoring 'View All' (HomeKey) and Auto-Set Preview Range ('Ctrl Alt P')
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_fcurve.h | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/fcurve.c | 67 |
2 files changed, 70 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_fcurve.h b/source/blender/blenkernel/BKE_fcurve.h index 87c230eec91..dd5e0dd6e21 100644 --- a/source/blender/blenkernel/BKE_fcurve.h +++ b/source/blender/blenkernel/BKE_fcurve.h @@ -89,6 +89,9 @@ struct FCurve *list_find_fcurve(ListBase *list, const char rna_path[], const int /* get the time extents for F-Curve */ 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); + /* -------- Curve Sanity -------- */ void calchandles_fcurve(struct FCurve *fcu); diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c index 72e4932e622..6f8732a35e2 100644 --- a/source/blender/blenkernel/intern/fcurve.c +++ b/source/blender/blenkernel/intern/fcurve.c @@ -170,6 +170,73 @@ FCurve *list_find_fcurve (ListBase *list, const char rna_path[], const int array return NULL; } +/* Calculate the extents of F-Curve's data */ +void calc_fcurve_bounds (FCurve *fcu, float *xmin, float *xmax, float *ymin, float *ymax) +{ + float xminv=999999999.0f, xmaxv=-999999999.0f; + float yminv=999999999.0f, ymaxv=-999999999.0f; + short foundvert=0; + int i; + + if (fcu->totvert) { + if (fcu->bezt) { + /* frame range can be directly calculated from end verts */ + if (xmin || xmax) { + xminv= MIN2(xminv, fcu->bezt[0].vec[1][0]); + xmaxv= MAX2(xmaxv, fcu->bezt[fcu->totvert-1].vec[1][0]); + } + + /* only loop over keyframes to find extents for values if needed */ + if (ymin || ymax) { + BezTriple *bezt; + + for (bezt=fcu->bezt, i=0; i < fcu->totvert; bezt++, i++) { + yminv= MIN2(yminv, bezt->vec[1][1]); + ymaxv= MAX2(ymaxv, bezt->vec[1][1]); + } + } + } + else if (fcu->fpt) { + /* frame range can be directly calculated from end verts */ + if (xmin || xmax) { + xminv= MIN2(xminv, fcu->fpt[0].vec[0]); + xmaxv= MAX2(xmaxv, fcu->fpt[fcu->totvert-1].vec[0]); + } + + /* only loop over keyframes to find extents for values if needed */ + if (ymin || ymax) { + FPoint *fpt; + + for (fpt=fcu->fpt, i=0; i < fcu->totvert; fpt++, i++) { + yminv= MIN2(yminv, fpt->vec[1]); + ymaxv= MAX2(ymaxv, fpt->vec[1]); + } + } + } + + foundvert=1; + } + + /* minimum sizes are 1.0f */ + if (foundvert) { + if (xminv == xmaxv) xmaxv += 1.0f; + if (yminv == ymaxv) ymaxv += 1.0f; + + if (xmin) *xmin= xminv; + if (xmax) *xmax= xmaxv; + + if (ymin) *ymin= yminv; + if (ymax) *ymax= ymaxv; + } + else { + if (xmin) *xmin= 0.0f; + if (xmax) *xmax= 0.0f; + + if (ymin) *ymin= 1.0f; + if (ymax) *ymax= 1.0f; + } +} + /* Calculate the extents of F-Curve's keyframes */ void calc_fcurve_range (FCurve *fcu, float *start, float *end) { |