diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/space_graph/graph_buttons.c | 1 | ||||
-rw-r--r-- | source/blender/editors/space_graph/graph_edit.c | 40 | ||||
-rw-r--r-- | source/blender/editors/space_graph/graph_intern.h | 1 | ||||
-rw-r--r-- | source/blender/editors/space_graph/graph_ops.c | 1 |
4 files changed, 43 insertions, 0 deletions
diff --git a/source/blender/editors/space_graph/graph_buttons.c b/source/blender/editors/space_graph/graph_buttons.c index be3e49fd810..a491ce29bd4 100644 --- a/source/blender/editors/space_graph/graph_buttons.c +++ b/source/blender/editors/space_graph/graph_buttons.c @@ -161,6 +161,7 @@ static void graph_panel_cursor(const bContext *C, Panel *panel) sub = uiLayoutColumn(col, true); uiItemO(sub, IFACE_("Cursor to Selection"), ICON_NONE, "GRAPH_OT_frame_jump"); + uiItemO(sub, IFACE_("Cursor Value to Selection"), ICON_NONE, "GRAPH_OT_snap_cursor_value"); } /* ******************* active F-Curve ************** */ diff --git a/source/blender/editors/space_graph/graph_edit.c b/source/blender/editors/space_graph/graph_edit.c index 3ec68971dea..c9b26674351 100644 --- a/source/blender/editors/space_graph/graph_edit.c +++ b/source/blender/editors/space_graph/graph_edit.c @@ -2838,6 +2838,46 @@ void GRAPH_OT_frame_jump(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } +/* snap 2D cursor value to the average value of selected keyframe */ +static int graphkeys_snap_cursor_value_exec(bContext *C, wmOperator *UNUSED(op)) +{ + bAnimContext ac; + + if (ANIM_animdata_get_context(C, &ac) == 0) { + return OPERATOR_CANCELLED; + } + + const KeyframeEditData keyframe_sum = sum_selected_keyframes(&ac); + const float sum_value = keyframe_sum.f2; + const int num_keyframes = keyframe_sum.i1; + + if (num_keyframes == 0) { + return OPERATOR_FINISHED; + } + + SpaceGraph *sipo = (SpaceGraph *)ac.sl; + sipo->cursorVal = sum_value / (float)num_keyframes; + // WM_event_add_notifier(C, NC_SCENE | ND_FRAME, ac.scene); + ED_region_tag_redraw(CTX_wm_region(C)); + + return OPERATOR_FINISHED; +} + +void GRAPH_OT_snap_cursor_value(wmOperatorType *ot) +{ + /* Identifiers. */ + ot->name = "Snap Cursor Value to Selected"; + ot->idname = "GRAPH_OT_snap_cursor_value"; + ot->description = "Place the cursor value on the average value of selected keyframes"; + + /* API callbacks. */ + ot->exec = graphkeys_snap_cursor_value_exec; + ot->poll = graphkeys_framejump_poll; + + /* Flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} + /* ******************** Snap Keyframes Operator *********************** */ /* defines for snap keyframes tool */ diff --git a/source/blender/editors/space_graph/graph_intern.h b/source/blender/editors/space_graph/graph_intern.h index c39ffdf42ed..eaa14fedb93 100644 --- a/source/blender/editors/space_graph/graph_intern.h +++ b/source/blender/editors/space_graph/graph_intern.h @@ -113,6 +113,7 @@ void GRAPH_OT_extrapolation_type(struct wmOperatorType *ot); void GRAPH_OT_easing_type(struct wmOperatorType *ot); void GRAPH_OT_frame_jump(struct wmOperatorType *ot); +void GRAPH_OT_snap_cursor_value(struct wmOperatorType *ot); void GRAPH_OT_snap(struct wmOperatorType *ot); void GRAPH_OT_mirror(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_graph/graph_ops.c b/source/blender/editors/space_graph/graph_ops.c index 4d337fdeb5e..fd68303e759 100644 --- a/source/blender/editors/space_graph/graph_ops.c +++ b/source/blender/editors/space_graph/graph_ops.c @@ -452,6 +452,7 @@ void graphedit_operatortypes(void) WM_operatortype_append(GRAPH_OT_snap); WM_operatortype_append(GRAPH_OT_mirror); WM_operatortype_append(GRAPH_OT_frame_jump); + WM_operatortype_append(GRAPH_OT_snap_cursor_value); WM_operatortype_append(GRAPH_OT_handle_type); WM_operatortype_append(GRAPH_OT_interpolation_type); WM_operatortype_append(GRAPH_OT_extrapolation_type); |