diff options
author | Joshua Leung <aligorith@gmail.com> | 2015-10-26 09:29:23 +0300 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2015-10-26 10:18:11 +0300 |
commit | b3edd7bdcdbb67abef6436244bb23ec3ef890869 (patch) | |
tree | 9829b62e24bf145cafc1740606aabb79bb8bc9f7 /source/blender | |
parent | 0860fdc53cca53441ca9d9d55a30878d9cdda725 (diff) |
Graph Editor: Adjusting Change Frame and Jump to Keyframes operators to work with Drivers Cursor
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/space_graph/graph_edit.c | 16 | ||||
-rw-r--r-- | source/blender/editors/space_graph/graph_ops.c | 49 |
2 files changed, 41 insertions, 24 deletions
diff --git a/source/blender/editors/space_graph/graph_edit.c b/source/blender/editors/space_graph/graph_edit.c index ca5d2db80e7..e423f564be2 100644 --- a/source/blender/editors/space_graph/graph_edit.c +++ b/source/blender/editors/space_graph/graph_edit.c @@ -1934,10 +1934,18 @@ static int graphkeys_framejump_exec(bContext *C, wmOperator *UNUSED(op)) SpaceIpo *sipo = (SpaceIpo *)ac.sl; Scene *scene = ac.scene; - /* take the average values, rounding to the nearest int for the current frame */ - CFRA = iroundf(ked.f1 / ked.i1); - SUBFRA = 0.f; - sipo->cursorVal = ked.f2 / (float)ked.i1; + /* take the average values, rounding to the nearest int as necessary for int results */ + if (sipo->mode == SIPO_MODE_DRIVERS) { + /* Drivers Mode - Affects cursor (float) */ + sipo->cursorTime = ked.f1 / (float)ked.i1; + sipo->cursorVal = ked.f2 / (float)ked.i1; + } + else { + /* Animation Mode - Affects current frame (int) */ + CFRA = iroundf(ked.f1 / ked.i1); + SUBFRA = 0.f; + sipo->cursorVal = ked.f2 / (float)ked.i1; + } } /* set notifier that things have changed */ diff --git a/source/blender/editors/space_graph/graph_ops.c b/source/blender/editors/space_graph/graph_ops.c index 0f0a329f87a..397a884e20a 100644 --- a/source/blender/editors/space_graph/graph_ops.c +++ b/source/blender/editors/space_graph/graph_ops.c @@ -82,19 +82,33 @@ static void graphview_cursor_apply(bContext *C, wmOperator *op) Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); SpaceIpo *sipo = CTX_wm_space_graph(C); + float frame = RNA_float_get(op->ptr, "frame"); /* this isn't technically "frame", but it'll do... */ /* adjust the frame or the cursor x-value */ if (sipo->mode == SIPO_MODE_DRIVERS) { /* adjust cursor x-value */ - sipo->cursorTime = (float)RNA_int_get(op->ptr, "frame"); // XXX: need new prop + sipo->cursorTime = frame; } else { /* adjust the frame * NOTE: sync this part of the code with ANIM_OT_change_frame */ - CFRA = RNA_int_get(op->ptr, "frame"); - FRAMENUMBER_MIN_CLAMP(CFRA); - SUBFRA = 0.f; + /* 1) frame is rounded to the nearest int, since frames are ints */ + CFRA = iroundf(frame); + + if (scene->r.flag & SCER_LOCK_FRAME_SELECTION) { + /* Clip to preview range + * NOTE: Preview range won't go into negative values, + * so only clamping once should be fine. + */ + CLAMP(CFRA, PSFRA, PEFRA); + } + else { + /* Prevent negative frames */ + FRAMENUMBER_MIN_CLAMP(CFRA); + } + + SUBFRA = 0.0f; BKE_sound_seek_scene(bmain, scene); } @@ -122,7 +136,6 @@ static void graphview_cursor_setprops(bContext *C, wmOperator *op, const wmEvent Scene *scene = CTX_data_scene(C); ARegion *ar = CTX_wm_region(C); float viewx, viewy; - int frame; /* abort if not active region (should not really be possible) */ if (ar == NULL) @@ -131,15 +144,9 @@ static void graphview_cursor_setprops(bContext *C, wmOperator *op, const wmEvent /* convert from region coordinates to View2D 'tot' space */ UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &viewx, &viewy); - /* frame is rounded to the nearest int, since frames are ints */ - frame = iroundf(viewx); - - if (scene->r.flag & SCER_LOCK_FRAME_SELECTION) { - CLAMP(frame, PSFRA, PEFRA); - } - /* store the values in the operator properties */ - RNA_int_set(op->ptr, "frame", frame); + /* NOTE: we don't clamp frame here, as it might be used for the drivers cursor */ + RNA_float_set(op->ptr, "frame", viewx); RNA_float_set(op->ptr, "value", viewy); } @@ -147,18 +154,18 @@ static void graphview_cursor_setprops(bContext *C, wmOperator *op, const wmEvent static int graphview_cursor_invoke(bContext *C, wmOperator *op, const wmEvent *event) { bScreen *screen = CTX_wm_screen(C); + /* Change to frame that mouse is over before adding modal handler, * as user could click on a single frame (jump to frame) as well as - * click-dragging over a range (modal scrubbing). + * click-dragging over a range (modal scrubbing). Apply this change. */ graphview_cursor_setprops(C, op, event); - - /* apply these changes first */ graphview_cursor_apply(C, op); + /* Signal that a scrubbing operating is starting */ if (screen) screen->scrubbing = true; - + /* add temp handler */ WM_event_add_modal_handler(C, op); return OPERATOR_RUNNING_MODAL; @@ -168,13 +175,15 @@ static int graphview_cursor_invoke(bContext *C, wmOperator *op, const wmEvent *e static int graphview_cursor_modal(bContext *C, wmOperator *op, const wmEvent *event) { bScreen *screen = CTX_wm_screen(C); + Scene *scene = CTX_data_scene(C); + /* execute the events */ switch (event->type) { case ESCKEY: if (screen) screen->scrubbing = false; - WM_event_add_notifier(C, NC_SCENE | ND_FRAME, CTX_data_scene(C)); + WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene); return OPERATOR_FINISHED; case MOUSEMOVE: @@ -193,7 +202,7 @@ static int graphview_cursor_modal(bContext *C, wmOperator *op, const wmEvent *ev if (screen) screen->scrubbing = false; - WM_event_add_notifier(C, NC_SCENE | ND_FRAME, CTX_data_scene(C)); + WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene); return OPERATOR_FINISHED; } break; @@ -219,7 +228,7 @@ static void GRAPH_OT_cursor_set(wmOperatorType *ot) ot->flag = OPTYPE_BLOCKING | OPTYPE_UNDO; /* rna */ - RNA_def_int(ot->srna, "frame", 0, MINAFRAME, MAXFRAME, "Frame", "", MINAFRAME, MAXFRAME); + RNA_def_float(ot->srna, "frame", 0, MINAFRAMEF, MAXFRAMEF, "Frame", "", MINAFRAMEF, MAXFRAMEF); RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Value", "", -100.0f, 100.0f); } |