diff options
author | Hans Goudey <h.goudey@me.com> | 2022-11-11 04:14:48 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-11-11 04:41:13 +0300 |
commit | 9465b109af0b70244a36f9e68493e316d9f8b56f (patch) | |
tree | c4d933bf09f8313071556063156538ec3356b24c /source/blender/editors/space_graph/graph_edit.c | |
parent | 026d21a225521670c6b5083da9da61227da69e65 (diff) | |
parent | ca1642cd0c5cdf634fe2022c955d93983de95934 (diff) |
Merge branch 'master' into refactor-mesh-position-genericrefactor-mesh-position-generic
Diffstat (limited to 'source/blender/editors/space_graph/graph_edit.c')
-rw-r--r-- | source/blender/editors/space_graph/graph_edit.c | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/source/blender/editors/space_graph/graph_edit.c b/source/blender/editors/space_graph/graph_edit.c index a23b33dde95..cb01b0d9dc8 100644 --- a/source/blender/editors/space_graph/graph_edit.c +++ b/source/blender/editors/space_graph/graph_edit.c @@ -2333,6 +2333,48 @@ static int graphkeys_snap_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } +static bool graph_has_selected_control_points(struct bContext *C) +{ + bAnimContext ac; + ListBase anim_data = {NULL, NULL}; + + /* Get editor data. */ + if (ANIM_animdata_get_context(C, &ac) == 0) { + return OPERATOR_CANCELLED; + } + + /* Filter data. */ + const int filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_FCURVESONLY | + ANIMFILTER_FOREDIT | ANIMFILTER_NODUPLIS); + ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); + + /* Check if any of the visible and editable f-curves have at least one selected control point. */ + bool has_selected_control_points = false; + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { + const FCurve *fcu = ale->key_data; + if (BKE_fcurve_has_selected_control_points(fcu)) { + has_selected_control_points = true; + break; + } + } + + ANIM_animdata_freelist(&anim_data); + + return has_selected_control_points; +} + +static int graphkeys_selected_control_points_invoke(struct bContext *C, + struct wmOperator *op, + const struct wmEvent *event) +{ + if (!graph_has_selected_control_points(C)) { + BKE_report(op->reports, RPT_ERROR, "No control points are selected"); + return OPERATOR_CANCELLED; + } + + return WM_menu_invoke(C, op, event); +} + void GRAPH_OT_snap(wmOperatorType *ot) { /* Identifiers */ @@ -2341,7 +2383,7 @@ void GRAPH_OT_snap(wmOperatorType *ot) ot->description = "Snap selected keyframes to the chosen times/values"; /* API callbacks */ - ot->invoke = WM_menu_invoke; + ot->invoke = graphkeys_selected_control_points_invoke; ot->exec = graphkeys_snap_exec; ot->poll = graphop_editable_keyframes_poll; @@ -2418,7 +2460,7 @@ void GRAPH_OT_equalize_handles(wmOperatorType *ot) "Ensure selected keyframes' handles have equal length, optionally making them horizontal. " "Automatic, Automatic Clamped, or Vector handle types will be converted to Aligned"; /* API callbacks */ - ot->invoke = WM_menu_invoke; + ot->invoke = graphkeys_selected_control_points_invoke; ot->exec = graphkeys_equalize_handles_exec; ot->poll = graphop_editable_keyframes_poll; |