From e3842d1ca4dd2fdc58b8d7819a8a02a688753146 Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Thu, 17 Mar 2011 10:02:37 +0000 Subject: Bugfix [#26505] zoom in selected keys on graph editor Not really a "bug", but it was on my todo anyways. Based on patch [#26508] by Campbell, with a few modifications including extending this to the Action/DopeSheet editor too. --- source/blender/editors/space_graph/graph_edit.c | 53 ++++++++++++++++++----- source/blender/editors/space_graph/graph_intern.h | 3 +- source/blender/editors/space_graph/graph_ops.c | 2 + source/blender/editors/space_graph/space_graph.c | 2 +- 4 files changed, 46 insertions(+), 14 deletions(-) (limited to 'source/blender/editors/space_graph') diff --git a/source/blender/editors/space_graph/graph_edit.c b/source/blender/editors/space_graph/graph_edit.c index d3e53a11c10..fdd43aa0566 100644 --- a/source/blender/editors/space_graph/graph_edit.c +++ b/source/blender/editors/space_graph/graph_edit.c @@ -81,7 +81,7 @@ /* 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) +void get_graph_keyframe_extents (bAnimContext *ac, float *xmin, float *xmax, float *ymin, float *ymax, const short selOnly) { ListBase anim_data = {NULL, NULL}; bAnimListElem *ale; @@ -107,7 +107,7 @@ void get_graph_keyframe_extents (bAnimContext *ac, float *xmin, float *xmax, flo float unitFac; /* get range */ - calc_fcurve_bounds(fcu, &txmin, &txmax, &tymin, &tymax); + calc_fcurve_bounds(fcu, &txmin, &txmax, &tymin, &tymax, selOnly); /* apply NLA scaling */ if (adt) { @@ -167,7 +167,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); + get_graph_keyframe_extents(&ac, &min, &max, NULL, NULL, FALSE); scene->r.flag |= SCER_PRV_RANGE; scene->r.psfra= (int)floor(min + 0.5f); scene->r.pefra= (int)floor(max + 0.5f); @@ -196,37 +196,51 @@ void GRAPH_OT_previewrange_set (wmOperatorType *ot) /* ****************** View-All Operator ****************** */ -static int graphkeys_viewall_exec(bContext *C, wmOperator *UNUSED(op)) +static int graphkeys_viewall(bContext *C, const short selOnly) { bAnimContext ac; View2D *v2d; float extra; - + /* get editor data */ if (ANIM_animdata_get_context(C, &ac) == 0) return OPERATOR_CANCELLED; 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); - + get_graph_keyframe_extents(&ac, &v2d->cur.xmin, &v2d->cur.xmax, &v2d->cur.ymin, &v2d->cur.ymax, selOnly); + extra= 0.1f * (v2d->cur.xmax - v2d->cur.xmin); v2d->cur.xmin -= extra; v2d->cur.xmax += extra; - + extra= 0.1f * (v2d->cur.ymax - v2d->cur.ymin); v2d->cur.ymin -= extra; v2d->cur.ymax += extra; - + /* do View2D syncing */ UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY); - + /* set notifier that things have changed */ ED_area_tag_redraw(CTX_wm_area(C)); - + return OPERATOR_FINISHED; } + +/* ......... */ + +static int graphkeys_viewall_exec(bContext *C, wmOperator *UNUSED(op)) +{ + /* whole range */ + return graphkeys_viewall(C, FALSE); +} +static int graphkeys_view_selected_exec(bContext *C, wmOperator *UNUSED(op)) +{ + /* only selected */ + return graphkeys_viewall(C, TRUE); +} + void GRAPH_OT_view_all (wmOperatorType *ot) { /* identifiers */ @@ -242,6 +256,21 @@ void GRAPH_OT_view_all (wmOperatorType *ot) ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } +void GRAPH_OT_view_selected (wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "View Selected"; + ot->idname= "GRAPH_OT_view_selected"; + ot->description= "Reset viewable area to show selected keyframe range"; + + /* api callbacks */ + ot->exec= graphkeys_view_selected_exec; + ot->poll= ED_operator_graphedit_active; // XXX: unchecked poll to get fsamples working too, but makes modifier damage trickier... + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + /* ******************** Create Ghost-Curves Operator *********************** */ /* This operator samples the data of the selected F-Curves to F-Points, storing them * as 'ghost curves' in the active Graph Editor diff --git a/source/blender/editors/space_graph/graph_intern.h b/source/blender/editors/space_graph/graph_intern.h index f0a3f797a2b..feb17827db7 100644 --- a/source/blender/editors/space_graph/graph_intern.h +++ b/source/blender/editors/space_graph/graph_intern.h @@ -92,10 +92,11 @@ enum { /* ***************************************** */ /* graph_edit.c */ -void get_graph_keyframe_extents (struct bAnimContext *ac, float *xmin, float *xmax, float *ymin, float *ymax); +void get_graph_keyframe_extents (struct bAnimContext *ac, float *xmin, float *xmax, float *ymin, float *ymax, const short do_selected); void GRAPH_OT_previewrange_set(struct wmOperatorType *ot); void GRAPH_OT_view_all(struct wmOperatorType *ot); +void GRAPH_OT_view_selected(struct wmOperatorType *ot); void GRAPH_OT_click_insert(struct wmOperatorType *ot); void GRAPH_OT_keyframe_insert(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_graph/graph_ops.c b/source/blender/editors/space_graph/graph_ops.c index b1dae57b574..da7de7ca003 100644 --- a/source/blender/editors/space_graph/graph_ops.c +++ b/source/blender/editors/space_graph/graph_ops.c @@ -226,6 +226,7 @@ void graphedit_operatortypes(void) WM_operatortype_append(GRAPH_OT_previewrange_set); WM_operatortype_append(GRAPH_OT_view_all); + WM_operatortype_append(GRAPH_OT_view_selected); WM_operatortype_append(GRAPH_OT_properties); WM_operatortype_append(GRAPH_OT_ghost_curves_create); @@ -387,6 +388,7 @@ static void graphedit_keymap_keyframes (wmKeyConfig *keyconf, wmKeyMap *keymap) /* auto-set range */ WM_keymap_add_item(keymap, "GRAPH_OT_previewrange_set", PKEY, KM_PRESS, KM_CTRL|KM_ALT, 0); WM_keymap_add_item(keymap, "GRAPH_OT_view_all", HOMEKEY, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "GRAPH_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0); /* F-Modifiers */ RNA_boolean_set(WM_keymap_add_item(keymap, "GRAPH_OT_fmodifier_add", MKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0)->ptr, "only_active", 0); diff --git a/source/blender/editors/space_graph/space_graph.c b/source/blender/editors/space_graph/space_graph.c index e5c605c0a83..554d2e36ccf 100644 --- a/source/blender/editors/space_graph/space_graph.c +++ b/source/blender/editors/space_graph/space_graph.c @@ -253,7 +253,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); + get_graph_keyframe_extents(&ac, &v2d->tot.xmin, &v2d->tot.xmax, &v2d->tot.ymin, &v2d->tot.ymax, FALSE); /* extra offset so that these items are visible */ v2d->tot.xmin -= 10.0f; v2d->tot.xmax += 10.0f; -- cgit v1.2.3