Revision: 18902 http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18902 Author: aligorith Date: 2009-02-10 11:42:04 +0100 (Tue, 10 Feb 2009)
Log Message: ----------- Graph Editor: Restoring 'View All' (HomeKey) and Auto-Set Preview Range ('Ctrl Alt P') Modified Paths: -------------- branches/blender2.5/blender/source/blender/blenkernel/BKE_fcurve.h branches/blender2.5/blender/source/blender/blenkernel/intern/fcurve.c branches/blender2.5/blender/source/blender/editors/space_graph/graph_edit.c branches/blender2.5/blender/source/blender/editors/space_graph/graph_ops.c Modified: branches/blender2.5/blender/source/blender/blenkernel/BKE_fcurve.h =================================================================== --- branches/blender2.5/blender/source/blender/blenkernel/BKE_fcurve.h 2009-02-10 09:55:46 UTC (rev 18901) +++ branches/blender2.5/blender/source/blender/blenkernel/BKE_fcurve.h 2009-02-10 10:42:04 UTC (rev 18902) @@ -89,6 +89,9 @@ /* 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); Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/fcurve.c =================================================================== --- branches/blender2.5/blender/source/blender/blenkernel/intern/fcurve.c 2009-02-10 09:55:46 UTC (rev 18901) +++ branches/blender2.5/blender/source/blender/blenkernel/intern/fcurve.c 2009-02-10 10:42:04 UTC (rev 18902) @@ -170,6 +170,73 @@ 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) { Modified: branches/blender2.5/blender/source/blender/editors/space_graph/graph_edit.c =================================================================== --- branches/blender2.5/blender/source/blender/editors/space_graph/graph_edit.c 2009-02-10 09:55:46 UTC (rev 18901) +++ branches/blender2.5/blender/source/blender/editors/space_graph/graph_edit.c 2009-02-10 10:42:04 UTC (rev 18902) @@ -84,15 +84,13 @@ #include "graph_intern.h" -#if 0 // XXX code to be sanitied for new system - /* ************************************************************************** */ /* KEYFRAME-RANGE STUFF */ /* *************************** Calculate Range ************************** */ /* Get the min/max keyframes*/ -static void get_keyframe_extents (bAnimContext *ac, float *xmin, float *xmax, float *ymin, float *ymax) +static void get_graph_keyframe_extents (bAnimContext *ac, float *xmin, float *xmax, float *ymin, float *ymax) { ListBase anim_data = {NULL, NULL}; bAnimListElem *ale; @@ -105,23 +103,19 @@ /* set large values to try to override */ if (xmin) *xmin= 999999999.0f; if (xmax) *xmax= -999999999.0f; - //if (ymin) *ymin= 999999999.0f; - //if (ymax) *ymax= -999999999.0f; + if (ymin) *ymin= 999999999.0f; + if (ymax) *ymax= -999999999.0f; - // XXX - if (ymin) *ymin= -10; - if (ymax) *ymax= 10; - /* check if any channels to set range with */ if (anim_data.first) { /* go through channels, finding max extents */ for (ale= anim_data.first; ale; ale= ale->next) { - Object *nob= ANIM_nla_mapping_get(ac, ale); + Object *nob= NULL; //ANIM_nla_mapping_get(ac, ale); FCurve *fcu= (FCurve *)ale->key_data; float tmin, tmax; /* get range and apply necessary scaling before */ - calc_fcurve_range(fcu, &tmin, &tmax); + calc_fcurve_bounds(fcu, &tmin, &tmax, ymin, ymax); if (nob) { tmin= get_action_frame_inv(nob, tmin); @@ -146,6 +140,9 @@ if (xmin) *xmin= -5; if (xmax) *xmax= 100; } + + if (ymin) *ymin= -5; + if (ymax) *ymax= 5; } } @@ -166,7 +163,7 @@ scene= ac.scene; /* set the range directly */ - get_keyframe_extents(&ac, &min, &max); + get_graph_keyframe_extents(&ac, &min, &max, NULL, NULL); scene->r.psfra= (int)floor(min + 0.5f); scene->r.pefra= (int)floor(max + 0.5f); @@ -205,13 +202,13 @@ v2d= &ac.ar->v2d; /* set the horizontal range, with an extra offset so that the extreme keys will be in view */ - get_keyframe_extents(&ac, &v2d->cur.xmin, &v2d->cur.xmax, &v2d->cur.ymin, &v2d->cur.ymax); + get_graph_keyframe_extents(&ac, &v2d->cur.xmin, &v2d->cur.xmax, &v2d->cur.ymin, &v2d->cur.ymax); - extra= 0.05f * (v2d->cur.xmax - v2d->cur.xmin); + extra= 0.1f * (v2d->cur.xmax - v2d->cur.xmin); v2d->cur.xmin -= extra; v2d->cur.xmax += extra; - extra= 0.05f * (v2d->cur.ymax - v2d->cur.ymin); + extra= 0.1f * (v2d->cur.ymax - v2d->cur.ymin); v2d->cur.ymin -= extra; v2d->cur.ymax += extra; @@ -238,17 +235,17 @@ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } + /* ************************************************************************** */ /* GENERAL STUFF */ +#if 0 // XXX stuff to be sanitised for the new anim system + // TODO: // - insert key /* ******************** Copy/Paste Keyframes Operator ************************* */ -/* - The copy/paste buffer currently stores a set of Action Channels, with temporary - * IPO-blocks, and also temporary IpoCurves which only contain the selected keyframes. - * - Only pastes between compatable data is possible (i.e. same achan->name, ipo-curve type, etc.) - * Unless there is only one element in the buffer, names are also tested to check for compatability. +/* - xxx... * - All pasted frames are offset by the same amount. This is calculated as the difference in the times of * the current frame and the 'first keyframe' (i.e. the earliest one in all channels). * - The earliest frame is calculated per copy operation. Modified: branches/blender2.5/blender/source/blender/editors/space_graph/graph_ops.c =================================================================== --- branches/blender2.5/blender/source/blender/editors/space_graph/graph_ops.c 2009-02-10 09:55:46 UTC (rev 18901) +++ branches/blender2.5/blender/source/blender/editors/space_graph/graph_ops.c 2009-02-10 10:42:04 UTC (rev 18902) @@ -97,8 +97,8 @@ { /* view */ WM_operatortype_append(GRAPHEDIT_OT_view_togglehandles); - //WM_operatortype_append(GRAPHEDIT_OT_set_previewrange); - //WM_operatortype_append(GRAPHEDIT_OT_view_all); + WM_operatortype_append(GRAPHEDIT_OT_set_previewrange); + WM_operatortype_append(GRAPHEDIT_OT_view_all); /* keyframes */ /* selection */ @@ -183,8 +183,8 @@ #endif // XXX code to be sanitied for new system /* auto-set range */ - //WM_keymap_add_item(keymap, "GRAPHEDIT_OT_set_previewrange", PKEY, KM_PRESS, KM_CTRL|KM_ALT, 0); - //WM_keymap_add_item(keymap, "GRAPHEDIT_OT_view_all", HOMEKEY, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "GRAPHEDIT_OT_set_previewrange", PKEY, KM_PRESS, KM_CTRL|KM_ALT, 0); + WM_keymap_add_item(keymap, "GRAPHEDIT_OT_view_all", HOMEKEY, KM_PRESS, 0, 0); /* transform system */ transform_keymap_for_space(wm, keymap, SPACE_IPO); _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs