From d5b57d41110c09e41ad648b90d248c08ce306849 Mon Sep 17 00:00:00 2001 From: cgtinker Date: Mon, 22 May 2023 11:47:42 +0200 Subject: [PATCH 01/11] handle selection --- scripts/startup/bl_ui/space_graph.py | 4 + .../editors/space_graph/graph_intern.h | 8 ++ .../blender/editors/space_graph/graph_ops.cc | 2 + .../editors/space_graph/graph_select.cc | 131 +++++++++++++++++- 4 files changed, 144 insertions(+), 1 deletion(-) diff --git a/scripts/startup/bl_ui/space_graph.py b/scripts/startup/bl_ui/space_graph.py index 73acde0b5fc..170fc32a7aa 100644 --- a/scripts/startup/bl_ui/space_graph.py +++ b/scripts/startup/bl_ui/space_graph.py @@ -217,6 +217,10 @@ class GRAPH_MT_select(Menu): props.extend = False props.mode = 'RIGHT' + layout.separator() + # layout.operator("graph.select_handles", text="All").action = 'SELECT' + layout.operator("graph.select_handles") + layout.separator() layout.operator("graph.select_more") layout.operator("graph.select_less") diff --git a/source/blender/editors/space_graph/graph_intern.h b/source/blender/editors/space_graph/graph_intern.h index e744a46346e..6a5c76815b1 100644 --- a/source/blender/editors/space_graph/graph_intern.h +++ b/source/blender/editors/space_graph/graph_intern.h @@ -79,6 +79,13 @@ enum eGraphKeys_LeftRightSelect_Mode { GRAPHKEYS_LRSEL_RIGHT, }; +/* Defines for handle selection */ +enum eGraphKey_HandleSelect_Mode { + GRAPHKEYS_HANDLESEL_LR = 0, + GRAPHKEYS_HANDLESEL_L, + GRAPHKEYS_HANDLESEL_R, +}; + /* defines for column-select mode */ enum eGraphKeys_ColumnSelect_Mode { GRAPHKEYS_COLUMNSEL_KEYS = 0, @@ -135,6 +142,7 @@ void GRAPH_OT_sound_to_samples(struct wmOperatorType *ot); void GRAPH_OT_smooth(struct wmOperatorType *ot); void GRAPH_OT_euler_filter(struct wmOperatorType *ot); +void GRAPH_OT_select_handles(struct wmOperatorType *ot); void GRAPH_OT_handle_type(struct wmOperatorType *ot); void GRAPH_OT_interpolation_type(struct wmOperatorType *ot); void GRAPH_OT_extrapolation_type(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_graph/graph_ops.cc b/source/blender/editors/space_graph/graph_ops.cc index 3df2f1c3496..b9d7a0c598c 100644 --- a/source/blender/editors/space_graph/graph_ops.cc +++ b/source/blender/editors/space_graph/graph_ops.cc @@ -448,6 +448,8 @@ void graphedit_operatortypes() WM_operatortype_append(GRAPH_OT_select_less); WM_operatortype_append(GRAPH_OT_select_leftright); + WM_operatortype_append(GRAPH_OT_select_handles); + /* editing */ WM_operatortype_append(GRAPH_OT_snap); WM_operatortype_append(GRAPH_OT_equalize_handles); diff --git a/source/blender/editors/space_graph/graph_select.cc b/source/blender/editors/space_graph/graph_select.cc index dd42688066a..151dc906645 100644 --- a/source/blender/editors/space_graph/graph_select.cc +++ b/source/blender/editors/space_graph/graph_select.cc @@ -216,7 +216,8 @@ static void get_nearest_fcurve_verts_list(bAnimContext *ac, const int mval[2], L if (fcurve_handle_sel_check(sipo, bezt1)) { /* first handle only visible if previous segment had handles */ if ((!prevbezt && (bezt1->ipo == BEZT_IPO_BEZ)) || - (prevbezt && (prevbezt->ipo == BEZT_IPO_BEZ))) { + (prevbezt && (prevbezt->ipo == BEZT_IPO_BEZ))) + { nearest_fcurve_vert_store(matches, v2d, fcu, @@ -2064,3 +2065,131 @@ void GRAPH_OT_clickselect(wmOperatorType *ot) } /** \} */ +/* Handle selection */ + +/* defines for left-right select tool */ +static const EnumPropertyItem prop_graphkeys_leftright_handle_select_types[] = { + {GRAPHKEYS_HANDLESEL_LR, "CHECK", 0, "Select Both Handles", ""}, + {GRAPHKEYS_HANDLESEL_L, "LEFT", 0, "Select Left Handles", ""}, + {GRAPHKEYS_HANDLESEL_R, "RIGHT", 0, "Select Right Handles", ""}, + {0, NULL, 0, NULL, NULL}, +}; + +short bezt_sel_left_handles(KeyframeEditData *ked, BezTriple *bezt) +{ + if (BEZT_ISSEL_ANY(bezt)) { + BEZT_SEL_IDX(bezt, 0); + BEZT_DESEL_IDX(bezt, 2); + } + return 0; +} + +short bezt_sel_right_handles(KeyframeEditData *ked, BezTriple *bezt) +{ + if (BEZT_ISSEL_ANY(bezt)) { + BEZT_DESEL_IDX(bezt, 0); + BEZT_SEL_IDX(bezt, 2); + } + return 0; +} + +short bezt_sel_both_handles(KeyframeEditData *ked, BezTriple *bezt) +{ + if (BEZT_ISSEL_ANY(bezt)) { + BEZT_SEL_IDX(bezt, 0); + BEZT_SEL_IDX(bezt, 2); + } + return 0; +} + +short bezt_desel_keys(KeyframeEditData *ked, BezTriple *bezt) +{ + if (BEZT_ISSEL_ANY(bezt)) { + BEZT_DESEL_IDX(bezt, 1); + } + return 0; +} + +static void graphkeys_de_select_handles(bAnimContext *ac, short mode, const bool desel_kf) +{ + ListBase anim_data = {NULL, NULL}; + bAnimListElem *ale; + int filter; + + KeyframeEditData ked; + + filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_FCURVESONLY | + ANIMFILTER_NODUPLIS); + ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); + + for (ale = anim_data.first; ale; ale = ale->next) { + FCurve *fcu = (FCurve *)ale->key_data; + + /* Only continue if F-Curve has keyframes. */ + if (fcu->bezt == NULL) { + continue; + } + switch (mode) { + case GRAPHKEYS_HANDLESEL_LR: { + ANIM_fcurve_keyframes_loop(&ked, fcu, NULL, bezt_sel_both_handles, NULL); + } break; + case GRAPHKEYS_HANDLESEL_R: { + ANIM_fcurve_keyframes_loop(&ked, fcu, NULL, bezt_sel_right_handles, NULL); + } break; + case GRAPHKEYS_HANDLESEL_L: { + ANIM_fcurve_keyframes_loop(&ked, fcu, NULL, bezt_sel_left_handles, NULL); + } break; + } + if (desel_kf) { + ANIM_fcurve_keyframes_loop(&ked, fcu, NULL, bezt_desel_keys, NULL); + } + } + + /* Cleanup */ + ANIM_animdata_freelist(&anim_data); +} + +static int graphkeys_select_handles_exec(bContext *C, wmOperator *op) +{ + bAnimContext ac; + + /* Get editor data. */ + if (ANIM_animdata_get_context(C, &ac) == 0) { + return OPERATOR_CANCELLED; + } + + short leftright = RNA_enum_get(op->ptr, "mode"); + bool desel_kf = RNA_boolean_get(op->ptr, "desel_kf"); + /* Perform selection changes. */ + graphkeys_de_select_handles(&ac, leftright, desel_kf); + + /* Set notifier that keyframe selection has changed. */ + WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_SELECTED, NULL); + + return OPERATOR_FINISHED; +} + +void GRAPH_OT_select_handles(wmOperatorType *ot) +{ + PropertyRNA *prop; + + /* identifiers */ + ot->name = "Select Handles"; + ot->idname = "GRAPH_OT_select_handles"; + ot->description = "(De)Select handles of based on the active selection"; + + /* callbacks */ + ot->poll = graphop_visible_keyframes_poll; + ot->exec = graphkeys_select_handles_exec; + + /* flags */ + ot->flag = OPTYPE_UNDO | OPTYPE_REGISTER; + + ot->prop = RNA_def_enum(ot->srna, + "mode", + prop_graphkeys_leftright_handle_select_types, + GRAPHKEYS_LRSEL_TEST, + "Mode", + "(De)Select handles based on selection"); + prop = RNA_def_boolean(ot->srna, "desel_kf", 1, "Deselect Keyframes", ""); +} \ No newline at end of file -- 2.30.2 From edbc4d57f5358248fce10b4b39b504f74af9bd16 Mon Sep 17 00:00:00 2001 From: cgtinker Date: Fri, 16 Jun 2023 11:19:52 +0200 Subject: [PATCH 02/11] improve pr --- scripts/startup/bl_ui/space_graph.py | 5 +- .../editors/space_graph/graph_intern.h | 2 +- .../editors/space_graph/graph_select.cc | 59 +++++++++---------- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/scripts/startup/bl_ui/space_graph.py b/scripts/startup/bl_ui/space_graph.py index 170fc32a7aa..e31fe2dcffa 100644 --- a/scripts/startup/bl_ui/space_graph.py +++ b/scripts/startup/bl_ui/space_graph.py @@ -218,8 +218,9 @@ class GRAPH_MT_select(Menu): props.mode = 'RIGHT' layout.separator() - # layout.operator("graph.select_handles", text="All").action = 'SELECT' - layout.operator("graph.select_handles") + layout.operator("graph.select_handles", text="Select Handles").mode = 'BOTH' + layout.operator("graph.select_handles", text="Select Handles Left").mode = 'LEFT' + layout.operator("graph.select_handles", text="Select Handles Right").mode = 'RIGHT' layout.separator() layout.operator("graph.select_more") diff --git a/source/blender/editors/space_graph/graph_intern.h b/source/blender/editors/space_graph/graph_intern.h index 6a5c76815b1..45c772a32c5 100644 --- a/source/blender/editors/space_graph/graph_intern.h +++ b/source/blender/editors/space_graph/graph_intern.h @@ -79,7 +79,7 @@ enum eGraphKeys_LeftRightSelect_Mode { GRAPHKEYS_LRSEL_RIGHT, }; -/* Defines for handle selection */ +/* Defines for handle selection. */ enum eGraphKey_HandleSelect_Mode { GRAPHKEYS_HANDLESEL_LR = 0, GRAPHKEYS_HANDLESEL_L, diff --git a/source/blender/editors/space_graph/graph_select.cc b/source/blender/editors/space_graph/graph_select.cc index 151dc906645..e489fe719e9 100644 --- a/source/blender/editors/space_graph/graph_select.cc +++ b/source/blender/editors/space_graph/graph_select.cc @@ -216,8 +216,7 @@ static void get_nearest_fcurve_verts_list(bAnimContext *ac, const int mval[2], L if (fcurve_handle_sel_check(sipo, bezt1)) { /* first handle only visible if previous segment had handles */ if ((!prevbezt && (bezt1->ipo == BEZT_IPO_BEZ)) || - (prevbezt && (prevbezt->ipo == BEZT_IPO_BEZ))) - { + (prevbezt && (prevbezt->ipo == BEZT_IPO_BEZ))) { nearest_fcurve_vert_store(matches, v2d, fcu, @@ -2067,15 +2066,15 @@ void GRAPH_OT_clickselect(wmOperatorType *ot) /** \} */ /* Handle selection */ -/* defines for left-right select tool */ +/* Defines for handle select tool. */ static const EnumPropertyItem prop_graphkeys_leftright_handle_select_types[] = { - {GRAPHKEYS_HANDLESEL_LR, "CHECK", 0, "Select Both Handles", ""}, + {GRAPHKEYS_HANDLESEL_LR, "BOTH", 0, "Select Both Handles", ""}, {GRAPHKEYS_HANDLESEL_L, "LEFT", 0, "Select Left Handles", ""}, {GRAPHKEYS_HANDLESEL_R, "RIGHT", 0, "Select Right Handles", ""}, {0, NULL, 0, NULL, NULL}, }; -short bezt_sel_left_handles(KeyframeEditData *ked, BezTriple *bezt) +static short bezt_sel_left_handles(KeyframeEditData *UNUSED(ked), BezTriple *bezt) { if (BEZT_ISSEL_ANY(bezt)) { BEZT_SEL_IDX(bezt, 0); @@ -2084,7 +2083,7 @@ short bezt_sel_left_handles(KeyframeEditData *ked, BezTriple *bezt) return 0; } -short bezt_sel_right_handles(KeyframeEditData *ked, BezTriple *bezt) +static short bezt_sel_right_handles(KeyframeEditData *UNUSED(ked), BezTriple *bezt) { if (BEZT_ISSEL_ANY(bezt)) { BEZT_DESEL_IDX(bezt, 0); @@ -2093,7 +2092,7 @@ short bezt_sel_right_handles(KeyframeEditData *ked, BezTriple *bezt) return 0; } -short bezt_sel_both_handles(KeyframeEditData *ked, BezTriple *bezt) +static short bezt_sel_both_handles(KeyframeEditData *UNUSED(ked), BezTriple *bezt) { if (BEZT_ISSEL_ANY(bezt)) { BEZT_SEL_IDX(bezt, 0); @@ -2102,7 +2101,7 @@ short bezt_sel_both_handles(KeyframeEditData *ked, BezTriple *bezt) return 0; } -short bezt_desel_keys(KeyframeEditData *ked, BezTriple *bezt) +static short bezt_desel_keys(KeyframeEditData *UNUSED(ked), BezTriple *bezt) { if (BEZT_ISSEL_ANY(bezt)) { BEZT_DESEL_IDX(bezt, 1); @@ -2110,19 +2109,18 @@ short bezt_desel_keys(KeyframeEditData *ked, BezTriple *bezt) return 0; } -static void graphkeys_de_select_handles(bAnimContext *ac, short mode, const bool desel_kf) +static void graphkeys_de_select_handles( + bAnimContext *ac, + const short mode, // prop_graphkeys_leftright_handle_select_types + const bool deselect_keyframe) { ListBase anim_data = {NULL, NULL}; - bAnimListElem *ale; - int filter; - KeyframeEditData ked; - - filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_FCURVESONLY | - ANIMFILTER_NODUPLIS); + const int filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_FCURVESONLY | + ANIMFILTER_NODUPLIS); ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); - for (ale = anim_data.first; ale; ale = ale->next) { + LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { FCurve *fcu = (FCurve *)ale->key_data; /* Only continue if F-Curve has keyframes. */ @@ -2131,17 +2129,20 @@ static void graphkeys_de_select_handles(bAnimContext *ac, short mode, const bool } switch (mode) { case GRAPHKEYS_HANDLESEL_LR: { - ANIM_fcurve_keyframes_loop(&ked, fcu, NULL, bezt_sel_both_handles, NULL); - } break; + ANIM_fcurve_keyframes_loop(NULL, fcu, NULL, bezt_sel_both_handles, NULL); + break; + } case GRAPHKEYS_HANDLESEL_R: { - ANIM_fcurve_keyframes_loop(&ked, fcu, NULL, bezt_sel_right_handles, NULL); - } break; + ANIM_fcurve_keyframes_loop(NULL, fcu, NULL, bezt_sel_right_handles, NULL); + break; + } case GRAPHKEYS_HANDLESEL_L: { - ANIM_fcurve_keyframes_loop(&ked, fcu, NULL, bezt_sel_left_handles, NULL); - } break; + ANIM_fcurve_keyframes_loop(NULL, fcu, NULL, bezt_sel_left_handles, NULL); + break; + } } - if (desel_kf) { - ANIM_fcurve_keyframes_loop(&ked, fcu, NULL, bezt_desel_keys, NULL); + if (deselect_keyframe) { + ANIM_fcurve_keyframes_loop(NULL, fcu, NULL, bezt_desel_keys, NULL); } } @@ -2159,9 +2160,9 @@ static int graphkeys_select_handles_exec(bContext *C, wmOperator *op) } short leftright = RNA_enum_get(op->ptr, "mode"); - bool desel_kf = RNA_boolean_get(op->ptr, "desel_kf"); + bool deselect_keyframe = RNA_boolean_get(op->ptr, "deselect_keyframe"); /* Perform selection changes. */ - graphkeys_de_select_handles(&ac, leftright, desel_kf); + graphkeys_de_select_handles(&ac, leftright, deselect_keyframe); /* Set notifier that keyframe selection has changed. */ WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_SELECTED, NULL); @@ -2171,8 +2172,6 @@ static int graphkeys_select_handles_exec(bContext *C, wmOperator *op) void GRAPH_OT_select_handles(wmOperatorType *ot) { - PropertyRNA *prop; - /* identifiers */ ot->name = "Select Handles"; ot->idname = "GRAPH_OT_select_handles"; @@ -2188,8 +2187,8 @@ void GRAPH_OT_select_handles(wmOperatorType *ot) ot->prop = RNA_def_enum(ot->srna, "mode", prop_graphkeys_leftright_handle_select_types, - GRAPHKEYS_LRSEL_TEST, + GRAPHKEYS_HANDLESEL_LR, "Mode", "(De)Select handles based on selection"); - prop = RNA_def_boolean(ot->srna, "desel_kf", 1, "Deselect Keyframes", ""); + ot->prop = RNA_def_boolean(ot->srna, "deselect_keyframe", 1, "Deselect Keyframes", ""); } \ No newline at end of file -- 2.30.2 From 8bb64f00838f41dd6f72dace379fc08dea20fe46 Mon Sep 17 00:00:00 2001 From: cgtinker Date: Mon, 26 Jun 2023 12:58:15 +0200 Subject: [PATCH 03/11] improved descriptions and keyframe selection --- scripts/startup/bl_ui/space_graph.py | 1 + .../editors/space_graph/graph_intern.h | 5 +- .../editors/space_graph/graph_select.cc | 97 ++++++++++++++----- 3 files changed, 75 insertions(+), 28 deletions(-) diff --git a/scripts/startup/bl_ui/space_graph.py b/scripts/startup/bl_ui/space_graph.py index e31fe2dcffa..e5c2585a8e8 100644 --- a/scripts/startup/bl_ui/space_graph.py +++ b/scripts/startup/bl_ui/space_graph.py @@ -221,6 +221,7 @@ class GRAPH_MT_select(Menu): layout.operator("graph.select_handles", text="Select Handles").mode = 'BOTH' layout.operator("graph.select_handles", text="Select Handles Left").mode = 'LEFT' layout.operator("graph.select_handles", text="Select Handles Right").mode = 'RIGHT' + layout.operator("graph.select_handles", text="Select Keyframes").mode = 'KEY' layout.separator() layout.operator("graph.select_more") diff --git a/source/blender/editors/space_graph/graph_intern.h b/source/blender/editors/space_graph/graph_intern.h index 45c772a32c5..298d607f5d8 100644 --- a/source/blender/editors/space_graph/graph_intern.h +++ b/source/blender/editors/space_graph/graph_intern.h @@ -80,10 +80,11 @@ enum eGraphKeys_LeftRightSelect_Mode { }; /* Defines for handle selection. */ -enum eGraphKey_HandleSelect_Mode { - GRAPHKEYS_HANDLESEL_LR = 0, +enum eGraphKey_HandleSelect_Side { + GRAPHKEYS_HANDLESEL_BOTH = 0, GRAPHKEYS_HANDLESEL_L, GRAPHKEYS_HANDLESEL_R, + GRAPHKEYS_HANDLESEL_KEY, }; /* defines for column-select mode */ diff --git a/source/blender/editors/space_graph/graph_select.cc b/source/blender/editors/space_graph/graph_select.cc index e489fe719e9..0126cf13259 100644 --- a/source/blender/editors/space_graph/graph_select.cc +++ b/source/blender/editors/space_graph/graph_select.cc @@ -30,6 +30,8 @@ #include "BKE_fcurve.h" #include "BKE_nla.h" +#include "UI_interface_c.hh" +#include "UI_resources.hh" #include "UI_view2d.hh" #include "ED_anim_api.hh" @@ -2068,13 +2070,14 @@ void GRAPH_OT_clickselect(wmOperatorType *ot) /* Defines for handle select tool. */ static const EnumPropertyItem prop_graphkeys_leftright_handle_select_types[] = { - {GRAPHKEYS_HANDLESEL_LR, "BOTH", 0, "Select Both Handles", ""}, + {GRAPHKEYS_HANDLESEL_BOTH, "BOTH", 0, "Select Both Handles", ""}, {GRAPHKEYS_HANDLESEL_L, "LEFT", 0, "Select Left Handles", ""}, {GRAPHKEYS_HANDLESEL_R, "RIGHT", 0, "Select Right Handles", ""}, + {GRAPHKEYS_HANDLESEL_KEY, "KEY", 0, "Select Keyframes", ""}, {0, NULL, 0, NULL, NULL}, }; -static short bezt_sel_left_handles(KeyframeEditData *UNUSED(ked), BezTriple *bezt) +static short bezt_sel_left_handles(KeyframeEditData * /* ked */, BezTriple *bezt) { if (BEZT_ISSEL_ANY(bezt)) { BEZT_SEL_IDX(bezt, 0); @@ -2083,7 +2086,7 @@ static short bezt_sel_left_handles(KeyframeEditData *UNUSED(ked), BezTriple *bez return 0; } -static short bezt_sel_right_handles(KeyframeEditData *UNUSED(ked), BezTriple *bezt) +static short bezt_sel_right_handles(KeyframeEditData * /* ked */, BezTriple *bezt) { if (BEZT_ISSEL_ANY(bezt)) { BEZT_DESEL_IDX(bezt, 0); @@ -2092,7 +2095,7 @@ static short bezt_sel_right_handles(KeyframeEditData *UNUSED(ked), BezTriple *be return 0; } -static short bezt_sel_both_handles(KeyframeEditData *UNUSED(ked), BezTriple *bezt) +static short bezt_sel_both_handles(KeyframeEditData * /* ked */, BezTriple *bezt) { if (BEZT_ISSEL_ANY(bezt)) { BEZT_SEL_IDX(bezt, 0); @@ -2101,7 +2104,17 @@ static short bezt_sel_both_handles(KeyframeEditData *UNUSED(ked), BezTriple *bez return 0; } -static short bezt_desel_keys(KeyframeEditData *UNUSED(ked), BezTriple *bezt) +static short bezt_sel_keys(KeyframeEditData * /* ked */, BezTriple *bezt) +{ + if (BEZT_ISSEL_ANY(bezt)) { + BEZT_DESEL_IDX(bezt, 0); + BEZT_SEL_IDX(bezt, 1); + BEZT_DESEL_IDX(bezt, 2); + } + return 0; +} + +static short bezt_desel_keys(KeyframeEditData * /*ked */, BezTriple *bezt) { if (BEZT_ISSEL_ANY(bezt)) { BEZT_DESEL_IDX(bezt, 1); @@ -2109,18 +2122,25 @@ static short bezt_desel_keys(KeyframeEditData *UNUSED(ked), BezTriple *bezt) return 0; } -static void graphkeys_de_select_handles( - bAnimContext *ac, - const short mode, // prop_graphkeys_leftright_handle_select_types - const bool deselect_keyframe) +/* + * Select keyframe handles left/right/both or keys based on the given selection. + * + * mode: Determines which handles to select - left, right, or both. + * deselect_keyframe: Specifies whether keyframes should be deselected (true) or if the current + * selection should be preserved (false). + */ +static void graph_keys_select_handles(bAnimContext *ac, + const enum eGraphKey_HandleSelect_Side mode, + const bool deselect_keyframe) { ListBase anim_data = {NULL, NULL}; - const int filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_FCURVESONLY | - ANIMFILTER_NODUPLIS); - ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); - + const eAnimFilter_Flags filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | + ANIMFILTER_FCURVESONLY | ANIMFILTER_NODUPLIS); + ANIM_animdata_filter( + ac, &anim_data, filter, ac->data, static_cast(ac->datatype)); LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) { + BLI_assert(ale->type & ANIMTYPE_FCURVE); FCurve *fcu = (FCurve *)ale->key_data; /* Only continue if F-Curve has keyframes. */ @@ -2128,7 +2148,7 @@ static void graphkeys_de_select_handles( continue; } switch (mode) { - case GRAPHKEYS_HANDLESEL_LR: { + case GRAPHKEYS_HANDLESEL_BOTH: { ANIM_fcurve_keyframes_loop(NULL, fcu, NULL, bezt_sel_both_handles, NULL); break; } @@ -2140,8 +2160,11 @@ static void graphkeys_de_select_handles( ANIM_fcurve_keyframes_loop(NULL, fcu, NULL, bezt_sel_left_handles, NULL); break; } + case GRAPHKEYS_HANDLESEL_KEY: { + ANIM_fcurve_keyframes_loop(NULL, fcu, NULL, bezt_sel_keys, NULL); + } } - if (deselect_keyframe) { + if (deselect_keyframe && (mode != GRAPHKEYS_HANDLESEL_KEY)) { ANIM_fcurve_keyframes_loop(NULL, fcu, NULL, bezt_desel_keys, NULL); } } @@ -2159,10 +2182,11 @@ static int graphkeys_select_handles_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - short leftright = RNA_enum_get(op->ptr, "mode"); - bool deselect_keyframe = RNA_boolean_get(op->ptr, "deselect_keyframe"); + const eGraphKey_HandleSelect_Side leftright = static_cast( + RNA_enum_get(op->ptr, "mode")); + const bool deselect_keyframe = RNA_boolean_get(op->ptr, "deselect_keyframe"); /* Perform selection changes. */ - graphkeys_de_select_handles(&ac, leftright, deselect_keyframe); + graph_keys_select_handles(&ac, leftright, deselect_keyframe); /* Set notifier that keyframe selection has changed. */ WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_SELECTED, NULL); @@ -2170,25 +2194,46 @@ static int graphkeys_select_handles_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } +static void graphkeys_select_handles_ui(bContext * /* C */, wmOperator *op) +{ + uiLayout *layout = op->layout; + uiLayout *row; + + bool keyframe_selection = RNA_enum_get(op->ptr, "mode") == GRAPHKEYS_HANDLESEL_KEY; + row = uiLayoutRow(layout, false); + uiItemR(row, op->ptr, "mode", UI_ITEM_NONE, NULL, ICON_NONE); + + if (!keyframe_selection) { + uiItemR(layout, op->ptr, "deselect_keyframe", UI_ITEM_NONE, NULL, ICON_NONE); + } +} + void GRAPH_OT_select_handles(wmOperatorType *ot) { /* identifiers */ ot->name = "Select Handles"; ot->idname = "GRAPH_OT_select_handles"; - ot->description = "(De)Select handles of based on the active selection"; + ot->description = "Select keyframe handles left/right/both or keys based on the given selection"; /* callbacks */ ot->poll = graphop_visible_keyframes_poll; ot->exec = graphkeys_select_handles_exec; + ot->ui = graphkeys_select_handles_ui; /* flags */ ot->flag = OPTYPE_UNDO | OPTYPE_REGISTER; - ot->prop = RNA_def_enum(ot->srna, - "mode", - prop_graphkeys_leftright_handle_select_types, - GRAPHKEYS_HANDLESEL_LR, - "Mode", - "(De)Select handles based on selection"); - ot->prop = RNA_def_boolean(ot->srna, "deselect_keyframe", 1, "Deselect Keyframes", ""); + RNA_def_enum( + ot->srna, + "mode", + prop_graphkeys_leftright_handle_select_types, + GRAPHKEYS_HANDLESEL_BOTH, + "Mode", + "Selects corresponding keyframe handles (left, right, both or keys) based on the given " + "selection"); + RNA_def_boolean(ot->srna, + "deselect_keyframe", + 1, + "Deselect Keyframes", + "Deselect keyframes or preserve the given keyframe selection"); } \ No newline at end of file -- 2.30.2 From 47e50a8383eaa7aac536e2e732983880cbc418ed Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Mon, 18 Sep 2023 17:00:21 +0200 Subject: [PATCH 04/11] Change SelectHandles parameters to be per-part of the key --- scripts/startup/bl_ui/space_graph.py | 20 +- .../editors/space_graph/graph_intern.h | 10 +- .../editors/space_graph/graph_select.cc | 185 ++++++++---------- 3 files changed, 108 insertions(+), 107 deletions(-) diff --git a/scripts/startup/bl_ui/space_graph.py b/scripts/startup/bl_ui/space_graph.py index e5c2585a8e8..b1c095a20f4 100644 --- a/scripts/startup/bl_ui/space_graph.py +++ b/scripts/startup/bl_ui/space_graph.py @@ -218,10 +218,22 @@ class GRAPH_MT_select(Menu): props.mode = 'RIGHT' layout.separator() - layout.operator("graph.select_handles", text="Select Handles").mode = 'BOTH' - layout.operator("graph.select_handles", text="Select Handles Left").mode = 'LEFT' - layout.operator("graph.select_handles", text="Select Handles Right").mode = 'RIGHT' - layout.operator("graph.select_handles", text="Select Keyframes").mode = 'KEY' + props = layout.operator("graph.select_handles", text="Select Handles") + props.left_handle_action = 'SELECT' + props.right_handle_action = 'SELECT' + props.k_actioney = 'KEEP' + props = layout.operator("graph.select_handles", text="Select Handles Left") + props.left_handle_action = 'SELECT' + props.right_handle_action = 'DESELECT' + props.key_action = 'KEEP' + props = layout.operator("graph.select_handles", text="Select Handles Right") + props.left_handle_action = 'DESELECT' + props.right_handle_action = 'SELECT' + props.key_action = 'KEEP' + props = layout.operator("graph.select_handles", text="Select Keyframes") + props.left_handle_action = 'DESELECT' + props.right_handle_action = 'DESELECT' + props.key_action = 'SELECT' layout.separator() layout.operator("graph.select_more") diff --git a/source/blender/editors/space_graph/graph_intern.h b/source/blender/editors/space_graph/graph_intern.h index 298d607f5d8..b243a6bf93f 100644 --- a/source/blender/editors/space_graph/graph_intern.h +++ b/source/blender/editors/space_graph/graph_intern.h @@ -80,11 +80,11 @@ enum eGraphKeys_LeftRightSelect_Mode { }; /* Defines for handle selection. */ -enum eGraphKey_HandleSelect_Side { - GRAPHKEYS_HANDLESEL_BOTH = 0, - GRAPHKEYS_HANDLESEL_L, - GRAPHKEYS_HANDLESEL_R, - GRAPHKEYS_HANDLESEL_KEY, +enum eGraphKey_HandleSelect_Action { + GRAPHKEYS_HANDLESEL_SELECT = 0, + GRAPHKEYS_HANDLESEL_DESELECT, + /* Leave the selection status as-is. */ + GRAPHKEYS_HANDLESEL_KEEP, }; /* defines for column-select mode */ diff --git a/source/blender/editors/space_graph/graph_select.cc b/source/blender/editors/space_graph/graph_select.cc index 0126cf13259..3f7df5bd2fa 100644 --- a/source/blender/editors/space_graph/graph_select.cc +++ b/source/blender/editors/space_graph/graph_select.cc @@ -2069,69 +2069,27 @@ void GRAPH_OT_clickselect(wmOperatorType *ot) /* Handle selection */ /* Defines for handle select tool. */ -static const EnumPropertyItem prop_graphkeys_leftright_handle_select_types[] = { - {GRAPHKEYS_HANDLESEL_BOTH, "BOTH", 0, "Select Both Handles", ""}, - {GRAPHKEYS_HANDLESEL_L, "LEFT", 0, "Select Left Handles", ""}, - {GRAPHKEYS_HANDLESEL_R, "RIGHT", 0, "Select Right Handles", ""}, - {GRAPHKEYS_HANDLESEL_KEY, "KEY", 0, "Select Keyframes", ""}, +static const EnumPropertyItem prop_graphkeys_handle_select_actions[] = { + {GRAPHKEYS_HANDLESEL_SELECT, "SELECT", 0, "Select", ""}, + {GRAPHKEYS_HANDLESEL_DESELECT, "DESELECT", 0, "Deselect", ""}, + {GRAPHKEYS_HANDLESEL_KEEP, "KEEP", 0, "Keep", "Leave as-is"}, {0, NULL, 0, NULL, NULL}, }; -static short bezt_sel_left_handles(KeyframeEditData * /* ked */, BezTriple *bezt) -{ - if (BEZT_ISSEL_ANY(bezt)) { - BEZT_SEL_IDX(bezt, 0); - BEZT_DESEL_IDX(bezt, 2); - } - return 0; -} - -static short bezt_sel_right_handles(KeyframeEditData * /* ked */, BezTriple *bezt) -{ - if (BEZT_ISSEL_ANY(bezt)) { - BEZT_DESEL_IDX(bezt, 0); - BEZT_SEL_IDX(bezt, 2); - } - return 0; -} - -static short bezt_sel_both_handles(KeyframeEditData * /* ked */, BezTriple *bezt) -{ - if (BEZT_ISSEL_ANY(bezt)) { - BEZT_SEL_IDX(bezt, 0); - BEZT_SEL_IDX(bezt, 2); - } - return 0; -} - -static short bezt_sel_keys(KeyframeEditData * /* ked */, BezTriple *bezt) -{ - if (BEZT_ISSEL_ANY(bezt)) { - BEZT_DESEL_IDX(bezt, 0); - BEZT_SEL_IDX(bezt, 1); - BEZT_DESEL_IDX(bezt, 2); - } - return 0; -} - -static short bezt_desel_keys(KeyframeEditData * /*ked */, BezTriple *bezt) -{ - if (BEZT_ISSEL_ANY(bezt)) { - BEZT_DESEL_IDX(bezt, 1); - } - return 0; -} - -/* - * Select keyframe handles left/right/both or keys based on the given selection. +/** + * Select/deselect different parts (e.g. left/right handles) of already-selected keys. * - * mode: Determines which handles to select - left, right, or both. - * deselect_keyframe: Specifies whether keyframes should be deselected (true) or if the current - * selection should be preserved (false). + * The *_action parameters determine what action to take on each part of + * a key: select, deselect, or keep (do nothing). + * + * \param left_handle_action: selection action to perform on left handles. + * \param key_action: selection action to perform on the keys themselves. + * \param right_handle_action: selection action to perform on right handles. */ static void graph_keys_select_handles(bAnimContext *ac, - const enum eGraphKey_HandleSelect_Side mode, - const bool deselect_keyframe) + const enum eGraphKey_HandleSelect_Action left_handle_action, + const enum eGraphKey_HandleSelect_Action key_action, + const enum eGraphKey_HandleSelect_Action right_handle_action) { ListBase anim_data = {NULL, NULL}; @@ -2147,26 +2105,50 @@ static void graph_keys_select_handles(bAnimContext *ac, if (fcu->bezt == NULL) { continue; } - switch (mode) { - case GRAPHKEYS_HANDLESEL_BOTH: { - ANIM_fcurve_keyframes_loop(NULL, fcu, NULL, bezt_sel_both_handles, NULL); - break; + + int i = 0; + BezTriple *bezt = fcu->bezt; + for (; i < fcu->totvert; bezt++, i++) { + if (!BEZT_ISSEL_ANY(bezt)) { + continue; } - case GRAPHKEYS_HANDLESEL_R: { - ANIM_fcurve_keyframes_loop(NULL, fcu, NULL, bezt_sel_right_handles, NULL); - break; + + switch (left_handle_action) { + case GRAPHKEYS_HANDLESEL_SELECT: + BEZT_SEL_IDX(bezt, 0); + break; + case GRAPHKEYS_HANDLESEL_DESELECT: + BEZT_DESEL_IDX(bezt, 0); + break; + case GRAPHKEYS_HANDLESEL_KEEP: + /* Do nothing. */ + break; } - case GRAPHKEYS_HANDLESEL_L: { - ANIM_fcurve_keyframes_loop(NULL, fcu, NULL, bezt_sel_left_handles, NULL); - break; + + switch (key_action) { + case GRAPHKEYS_HANDLESEL_SELECT: + BEZT_SEL_IDX(bezt, 1); + break; + case GRAPHKEYS_HANDLESEL_DESELECT: + BEZT_DESEL_IDX(bezt, 1); + break; + case GRAPHKEYS_HANDLESEL_KEEP: + /* Do nothing. */ + break; } - case GRAPHKEYS_HANDLESEL_KEY: { - ANIM_fcurve_keyframes_loop(NULL, fcu, NULL, bezt_sel_keys, NULL); + + switch (right_handle_action) { + case GRAPHKEYS_HANDLESEL_SELECT: + BEZT_SEL_IDX(bezt, 2); + break; + case GRAPHKEYS_HANDLESEL_DESELECT: + BEZT_DESEL_IDX(bezt, 2); + break; + case GRAPHKEYS_HANDLESEL_KEEP: + /* Do nothing. */ + break; } } - if (deselect_keyframe && (mode != GRAPHKEYS_HANDLESEL_KEY)) { - ANIM_fcurve_keyframes_loop(NULL, fcu, NULL, bezt_desel_keys, NULL); - } } /* Cleanup */ @@ -2182,13 +2164,15 @@ static int graphkeys_select_handles_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - const eGraphKey_HandleSelect_Side leftright = static_cast( - RNA_enum_get(op->ptr, "mode")); - const bool deselect_keyframe = RNA_boolean_get(op->ptr, "deselect_keyframe"); - /* Perform selection changes. */ - graph_keys_select_handles(&ac, leftright, deselect_keyframe); + const eGraphKey_HandleSelect_Action left_handle_action = + static_cast(RNA_enum_get(op->ptr, "left_handle_action")); + const eGraphKey_HandleSelect_Action key_action = static_cast( + RNA_enum_get(op->ptr, "key_action")); + const eGraphKey_HandleSelect_Action right_handle_action = + static_cast(RNA_enum_get(op->ptr, "right_handle_action")); + + graph_keys_select_handles(&ac, left_handle_action, key_action, right_handle_action); - /* Set notifier that keyframe selection has changed. */ WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_SELECTED, NULL); return OPERATOR_FINISHED; @@ -2199,13 +2183,12 @@ static void graphkeys_select_handles_ui(bContext * /* C */, wmOperator *op) uiLayout *layout = op->layout; uiLayout *row; - bool keyframe_selection = RNA_enum_get(op->ptr, "mode") == GRAPHKEYS_HANDLESEL_KEY; row = uiLayoutRow(layout, false); - uiItemR(row, op->ptr, "mode", UI_ITEM_NONE, NULL, ICON_NONE); - - if (!keyframe_selection) { - uiItemR(layout, op->ptr, "deselect_keyframe", UI_ITEM_NONE, NULL, ICON_NONE); - } + uiItemR(row, op->ptr, "left_handle_action", UI_ITEM_NONE, NULL, ICON_NONE); + row = uiLayoutRow(layout, false); + uiItemR(row, op->ptr, "right_handle_action", UI_ITEM_NONE, NULL, ICON_NONE); + row = uiLayoutRow(layout, false); + uiItemR(row, op->ptr, "key_action", UI_ITEM_NONE, NULL, ICON_NONE); } void GRAPH_OT_select_handles(wmOperatorType *ot) @@ -2213,7 +2196,8 @@ void GRAPH_OT_select_handles(wmOperatorType *ot) /* identifiers */ ot->name = "Select Handles"; ot->idname = "GRAPH_OT_select_handles"; - ot->description = "Select keyframe handles left/right/both or keys based on the given selection"; + ot->description = + "Select/deselect the different parts of keys that have at least one part already selected"; /* callbacks */ ot->poll = graphop_visible_keyframes_poll; @@ -2223,17 +2207,22 @@ void GRAPH_OT_select_handles(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_UNDO | OPTYPE_REGISTER; - RNA_def_enum( - ot->srna, - "mode", - prop_graphkeys_leftright_handle_select_types, - GRAPHKEYS_HANDLESEL_BOTH, - "Mode", - "Selects corresponding keyframe handles (left, right, both or keys) based on the given " - "selection"); - RNA_def_boolean(ot->srna, - "deselect_keyframe", - 1, - "Deselect Keyframes", - "Deselect keyframes or preserve the given keyframe selection"); + RNA_def_enum(ot->srna, + "left_handle_action", + prop_graphkeys_handle_select_actions, + GRAPHKEYS_HANDLESEL_SELECT, + "Left Handle", + "How to affect the selection of the left handle"); + RNA_def_enum(ot->srna, + "right_handle_action", + prop_graphkeys_handle_select_actions, + GRAPHKEYS_HANDLESEL_SELECT, + "Right Handle", + "How to affect the selection of the right handle"); + RNA_def_enum(ot->srna, + "key_action", + prop_graphkeys_handle_select_actions, + GRAPHKEYS_HANDLESEL_KEEP, + "Key", + "How to affect the selection of the key itself"); } \ No newline at end of file -- 2.30.2 From 5c5be1b8b5d673d91b6fa0b8156228b29bb9310e Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Tue, 19 Sep 2023 14:10:41 +0200 Subject: [PATCH 05/11] Change operator name to "Select Key / Handles". --- scripts/startup/bl_ui/space_graph.py | 10 +-- .../editors/space_graph/graph_intern.h | 12 +-- .../blender/editors/space_graph/graph_ops.cc | 3 +- .../editors/space_graph/graph_select.cc | 79 ++++++++++--------- 4 files changed, 52 insertions(+), 52 deletions(-) diff --git a/scripts/startup/bl_ui/space_graph.py b/scripts/startup/bl_ui/space_graph.py index b1c095a20f4..864e7e45412 100644 --- a/scripts/startup/bl_ui/space_graph.py +++ b/scripts/startup/bl_ui/space_graph.py @@ -218,19 +218,19 @@ class GRAPH_MT_select(Menu): props.mode = 'RIGHT' layout.separator() - props = layout.operator("graph.select_handles", text="Select Handles") + props = layout.operator("graph.select_key_handles", text="Select Handles") props.left_handle_action = 'SELECT' props.right_handle_action = 'SELECT' - props.k_actioney = 'KEEP' - props = layout.operator("graph.select_handles", text="Select Handles Left") + props.key_action = 'KEEP' + props = layout.operator("graph.select_key_handles", text="Select Handles Left") props.left_handle_action = 'SELECT' props.right_handle_action = 'DESELECT' props.key_action = 'KEEP' - props = layout.operator("graph.select_handles", text="Select Handles Right") + props = layout.operator("graph.select_key_handles", text="Select Handles Right") props.left_handle_action = 'DESELECT' props.right_handle_action = 'SELECT' props.key_action = 'KEEP' - props = layout.operator("graph.select_handles", text="Select Keyframes") + props = layout.operator("graph.select_key_handles", text="Select Keyframes") props.left_handle_action = 'DESELECT' props.right_handle_action = 'DESELECT' props.key_action = 'SELECT' diff --git a/source/blender/editors/space_graph/graph_intern.h b/source/blender/editors/space_graph/graph_intern.h index b243a6bf93f..9cdb97ed23e 100644 --- a/source/blender/editors/space_graph/graph_intern.h +++ b/source/blender/editors/space_graph/graph_intern.h @@ -70,6 +70,7 @@ void GRAPH_OT_select_linked(struct wmOperatorType *ot); void GRAPH_OT_select_more(struct wmOperatorType *ot); void GRAPH_OT_select_less(struct wmOperatorType *ot); void GRAPH_OT_select_leftright(struct wmOperatorType *ot); +void GRAPH_OT_select_key_handles(struct wmOperatorType *ot); void GRAPH_OT_clickselect(struct wmOperatorType *ot); /* defines for left-right select tool */ @@ -79,12 +80,12 @@ enum eGraphKeys_LeftRightSelect_Mode { GRAPHKEYS_LRSEL_RIGHT, }; -/* Defines for handle selection. */ -enum eGraphKey_HandleSelect_Action { - GRAPHKEYS_HANDLESEL_SELECT = 0, - GRAPHKEYS_HANDLESEL_DESELECT, +/* Defines for key/handles selection. */ +enum eGraphKey_SelectKeyHandles_Action { + GRAPHKEYS_KEYHANDLESSEL_SELECT = 0, + GRAPHKEYS_KEYHANDLESSEL_DESELECT, /* Leave the selection status as-is. */ - GRAPHKEYS_HANDLESEL_KEEP, + GRAPHKEYS_KEYHANDLESSEL_KEEP, }; /* defines for column-select mode */ @@ -143,7 +144,6 @@ void GRAPH_OT_sound_to_samples(struct wmOperatorType *ot); void GRAPH_OT_smooth(struct wmOperatorType *ot); void GRAPH_OT_euler_filter(struct wmOperatorType *ot); -void GRAPH_OT_select_handles(struct wmOperatorType *ot); void GRAPH_OT_handle_type(struct wmOperatorType *ot); void GRAPH_OT_interpolation_type(struct wmOperatorType *ot); void GRAPH_OT_extrapolation_type(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_graph/graph_ops.cc b/source/blender/editors/space_graph/graph_ops.cc index b9d7a0c598c..5bd307face3 100644 --- a/source/blender/editors/space_graph/graph_ops.cc +++ b/source/blender/editors/space_graph/graph_ops.cc @@ -447,8 +447,7 @@ void graphedit_operatortypes() WM_operatortype_append(GRAPH_OT_select_more); WM_operatortype_append(GRAPH_OT_select_less); WM_operatortype_append(GRAPH_OT_select_leftright); - - WM_operatortype_append(GRAPH_OT_select_handles); + WM_operatortype_append(GRAPH_OT_select_key_handles); /* editing */ WM_operatortype_append(GRAPH_OT_snap); diff --git a/source/blender/editors/space_graph/graph_select.cc b/source/blender/editors/space_graph/graph_select.cc index 3f7df5bd2fa..79b84f1464a 100644 --- a/source/blender/editors/space_graph/graph_select.cc +++ b/source/blender/editors/space_graph/graph_select.cc @@ -2066,13 +2066,13 @@ void GRAPH_OT_clickselect(wmOperatorType *ot) } /** \} */ -/* Handle selection */ +/* Key/handles selection */ -/* Defines for handle select tool. */ -static const EnumPropertyItem prop_graphkeys_handle_select_actions[] = { - {GRAPHKEYS_HANDLESEL_SELECT, "SELECT", 0, "Select", ""}, - {GRAPHKEYS_HANDLESEL_DESELECT, "DESELECT", 0, "Deselect", ""}, - {GRAPHKEYS_HANDLESEL_KEEP, "KEEP", 0, "Keep", "Leave as-is"}, +/* Defines for key/handles select tool. */ +static const EnumPropertyItem prop_graphkeys_select_key_handles_actions[] = { + {GRAPHKEYS_KEYHANDLESSEL_SELECT, "SELECT", 0, "Select", ""}, + {GRAPHKEYS_KEYHANDLESSEL_DESELECT, "DESELECT", 0, "Deselect", ""}, + {GRAPHKEYS_KEYHANDLESSEL_KEEP, "KEEP", 0, "Keep", "Leave as-is"}, {0, NULL, 0, NULL, NULL}, }; @@ -2086,10 +2086,11 @@ static const EnumPropertyItem prop_graphkeys_handle_select_actions[] = { * \param key_action: selection action to perform on the keys themselves. * \param right_handle_action: selection action to perform on right handles. */ -static void graph_keys_select_handles(bAnimContext *ac, - const enum eGraphKey_HandleSelect_Action left_handle_action, - const enum eGraphKey_HandleSelect_Action key_action, - const enum eGraphKey_HandleSelect_Action right_handle_action) +static void graphkeys_select_key_handles( + bAnimContext *ac, + const enum eGraphKey_SelectKeyHandles_Action left_handle_action, + const enum eGraphKey_SelectKeyHandles_Action key_action, + const enum eGraphKey_SelectKeyHandles_Action right_handle_action) { ListBase anim_data = {NULL, NULL}; @@ -2114,37 +2115,37 @@ static void graph_keys_select_handles(bAnimContext *ac, } switch (left_handle_action) { - case GRAPHKEYS_HANDLESEL_SELECT: + case GRAPHKEYS_KEYHANDLESSEL_SELECT: BEZT_SEL_IDX(bezt, 0); break; - case GRAPHKEYS_HANDLESEL_DESELECT: + case GRAPHKEYS_KEYHANDLESSEL_DESELECT: BEZT_DESEL_IDX(bezt, 0); break; - case GRAPHKEYS_HANDLESEL_KEEP: + case GRAPHKEYS_KEYHANDLESSEL_KEEP: /* Do nothing. */ break; } switch (key_action) { - case GRAPHKEYS_HANDLESEL_SELECT: + case GRAPHKEYS_KEYHANDLESSEL_SELECT: BEZT_SEL_IDX(bezt, 1); break; - case GRAPHKEYS_HANDLESEL_DESELECT: + case GRAPHKEYS_KEYHANDLESSEL_DESELECT: BEZT_DESEL_IDX(bezt, 1); break; - case GRAPHKEYS_HANDLESEL_KEEP: + case GRAPHKEYS_KEYHANDLESSEL_KEEP: /* Do nothing. */ break; } switch (right_handle_action) { - case GRAPHKEYS_HANDLESEL_SELECT: + case GRAPHKEYS_KEYHANDLESSEL_SELECT: BEZT_SEL_IDX(bezt, 2); break; - case GRAPHKEYS_HANDLESEL_DESELECT: + case GRAPHKEYS_KEYHANDLESSEL_DESELECT: BEZT_DESEL_IDX(bezt, 2); break; - case GRAPHKEYS_HANDLESEL_KEEP: + case GRAPHKEYS_KEYHANDLESSEL_KEEP: /* Do nothing. */ break; } @@ -2155,7 +2156,7 @@ static void graph_keys_select_handles(bAnimContext *ac, ANIM_animdata_freelist(&anim_data); } -static int graphkeys_select_handles_exec(bContext *C, wmOperator *op) +static int graphkeys_select_key_handles_exec(bContext *C, wmOperator *op) { bAnimContext ac; @@ -2164,21 +2165,21 @@ static int graphkeys_select_handles_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - const eGraphKey_HandleSelect_Action left_handle_action = - static_cast(RNA_enum_get(op->ptr, "left_handle_action")); - const eGraphKey_HandleSelect_Action key_action = static_cast( - RNA_enum_get(op->ptr, "key_action")); - const eGraphKey_HandleSelect_Action right_handle_action = - static_cast(RNA_enum_get(op->ptr, "right_handle_action")); + const eGraphKey_SelectKeyHandles_Action left_handle_action = + static_cast(RNA_enum_get(op->ptr, "left_handle_action")); + const eGraphKey_SelectKeyHandles_Action key_action = + static_cast(RNA_enum_get(op->ptr, "key_action")); + const eGraphKey_SelectKeyHandles_Action right_handle_action = + static_cast(RNA_enum_get(op->ptr, "right_handle_action")); - graph_keys_select_handles(&ac, left_handle_action, key_action, right_handle_action); + graphkeys_select_key_handles(&ac, left_handle_action, key_action, right_handle_action); WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_SELECTED, NULL); return OPERATOR_FINISHED; } -static void graphkeys_select_handles_ui(bContext * /* C */, wmOperator *op) +static void graphkeys_select_key_handles_ui(bContext * /* C */, wmOperator *op) { uiLayout *layout = op->layout; uiLayout *row; @@ -2191,38 +2192,38 @@ static void graphkeys_select_handles_ui(bContext * /* C */, wmOperator *op) uiItemR(row, op->ptr, "key_action", UI_ITEM_NONE, NULL, ICON_NONE); } -void GRAPH_OT_select_handles(wmOperatorType *ot) +void GRAPH_OT_select_key_handles(wmOperatorType *ot) { /* identifiers */ - ot->name = "Select Handles"; - ot->idname = "GRAPH_OT_select_handles"; + ot->name = "Select Key / Handles"; + ot->idname = "GRAPH_OT_select_key_handles"; ot->description = "Select/deselect the different parts of keys that have at least one part already selected"; /* callbacks */ ot->poll = graphop_visible_keyframes_poll; - ot->exec = graphkeys_select_handles_exec; - ot->ui = graphkeys_select_handles_ui; + ot->exec = graphkeys_select_key_handles_exec; + ot->ui = graphkeys_select_key_handles_ui; /* flags */ ot->flag = OPTYPE_UNDO | OPTYPE_REGISTER; RNA_def_enum(ot->srna, "left_handle_action", - prop_graphkeys_handle_select_actions, - GRAPHKEYS_HANDLESEL_SELECT, + prop_graphkeys_select_key_handles_actions, + GRAPHKEYS_KEYHANDLESSEL_SELECT, "Left Handle", "How to affect the selection of the left handle"); RNA_def_enum(ot->srna, "right_handle_action", - prop_graphkeys_handle_select_actions, - GRAPHKEYS_HANDLESEL_SELECT, + prop_graphkeys_select_key_handles_actions, + GRAPHKEYS_KEYHANDLESSEL_SELECT, "Right Handle", "How to affect the selection of the right handle"); RNA_def_enum(ot->srna, "key_action", - prop_graphkeys_handle_select_actions, - GRAPHKEYS_HANDLESEL_KEEP, + prop_graphkeys_select_key_handles_actions, + GRAPHKEYS_KEYHANDLESSEL_KEEP, "Key", "How to affect the selection of the key itself"); } \ No newline at end of file -- 2.30.2 From 9a26d0e27544376a6eef0f99d4e5135826943a81 Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Thu, 21 Sep 2023 11:27:30 +0200 Subject: [PATCH 06/11] Better tooltips. --- source/blender/editors/space_graph/graph_select.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/blender/editors/space_graph/graph_select.cc b/source/blender/editors/space_graph/graph_select.cc index 79b84f1464a..ac3f9572b82 100644 --- a/source/blender/editors/space_graph/graph_select.cc +++ b/source/blender/editors/space_graph/graph_select.cc @@ -2072,7 +2072,7 @@ void GRAPH_OT_clickselect(wmOperatorType *ot) static const EnumPropertyItem prop_graphkeys_select_key_handles_actions[] = { {GRAPHKEYS_KEYHANDLESSEL_SELECT, "SELECT", 0, "Select", ""}, {GRAPHKEYS_KEYHANDLESSEL_DESELECT, "DESELECT", 0, "Deselect", ""}, - {GRAPHKEYS_KEYHANDLESSEL_KEEP, "KEEP", 0, "Keep", "Leave as-is"}, + {GRAPHKEYS_KEYHANDLESSEL_KEEP, "KEEP", 0, "Keep", "Leave as is"}, {0, NULL, 0, NULL, NULL}, }; @@ -2198,7 +2198,7 @@ void GRAPH_OT_select_key_handles(wmOperatorType *ot) ot->name = "Select Key / Handles"; ot->idname = "GRAPH_OT_select_key_handles"; ot->description = - "Select/deselect the different parts of keys that have at least one part already selected"; + "Select/deselect any combination of the key and handles of selected keyframes"; /* callbacks */ ot->poll = graphop_visible_keyframes_poll; -- 2.30.2 From ccfa647f35829b3a508a77a08f35831f645503cf Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Thu, 21 Sep 2023 14:19:15 +0200 Subject: [PATCH 07/11] Remove left/right handle menu presets. --- scripts/startup/bl_ui/space_graph.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/scripts/startup/bl_ui/space_graph.py b/scripts/startup/bl_ui/space_graph.py index 864e7e45412..cb227a44e9f 100644 --- a/scripts/startup/bl_ui/space_graph.py +++ b/scripts/startup/bl_ui/space_graph.py @@ -222,15 +222,7 @@ class GRAPH_MT_select(Menu): props.left_handle_action = 'SELECT' props.right_handle_action = 'SELECT' props.key_action = 'KEEP' - props = layout.operator("graph.select_key_handles", text="Select Handles Left") - props.left_handle_action = 'SELECT' - props.right_handle_action = 'DESELECT' - props.key_action = 'KEEP' - props = layout.operator("graph.select_key_handles", text="Select Handles Right") - props.left_handle_action = 'DESELECT' - props.right_handle_action = 'SELECT' - props.key_action = 'KEEP' - props = layout.operator("graph.select_key_handles", text="Select Keyframes") + props = layout.operator("graph.select_key_handles", text="Select Key") props.left_handle_action = 'DESELECT' props.right_handle_action = 'DESELECT' props.key_action = 'SELECT' -- 2.30.2 From 70c1d1e9bb550bca9e9cc645f5e82b626ce8b43d Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Thu, 21 Sep 2023 14:19:41 +0200 Subject: [PATCH 08/11] Clang format --- source/blender/editors/space_graph/graph_select.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/blender/editors/space_graph/graph_select.cc b/source/blender/editors/space_graph/graph_select.cc index ac3f9572b82..f06a9735d27 100644 --- a/source/blender/editors/space_graph/graph_select.cc +++ b/source/blender/editors/space_graph/graph_select.cc @@ -2197,8 +2197,7 @@ void GRAPH_OT_select_key_handles(wmOperatorType *ot) /* identifiers */ ot->name = "Select Key / Handles"; ot->idname = "GRAPH_OT_select_key_handles"; - ot->description = - "Select/deselect any combination of the key and handles of selected keyframes"; + ot->description = "Select/deselect any combination of the key and handles of selected keyframes"; /* callbacks */ ot->poll = graphop_visible_keyframes_poll; -- 2.30.2 From 6fbcaf16c87ff54c013a7f619b2d3bcf5123c777 Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Thu, 21 Sep 2023 14:30:48 +0200 Subject: [PATCH 09/11] Improve operator description --- source/blender/editors/space_graph/graph_select.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/blender/editors/space_graph/graph_select.cc b/source/blender/editors/space_graph/graph_select.cc index f06a9735d27..6f49ca35dd9 100644 --- a/source/blender/editors/space_graph/graph_select.cc +++ b/source/blender/editors/space_graph/graph_select.cc @@ -2197,7 +2197,8 @@ void GRAPH_OT_select_key_handles(wmOperatorType *ot) /* identifiers */ ot->name = "Select Key / Handles"; ot->idname = "GRAPH_OT_select_key_handles"; - ot->description = "Select/deselect any combination of the key and handles of selected keyframes"; + ot->description = + "For selected keyframes, select/deselect any combination of the key itself and its handles"; /* callbacks */ ot->poll = graphop_visible_keyframes_poll; -- 2.30.2 From 9aa3372069e78113653c914dfdd64972b2c8d667 Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Thu, 21 Sep 2023 14:43:18 +0200 Subject: [PATCH 10/11] More succinct tooltips --- source/blender/editors/space_graph/graph_select.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/blender/editors/space_graph/graph_select.cc b/source/blender/editors/space_graph/graph_select.cc index 6f49ca35dd9..c1fddcad09e 100644 --- a/source/blender/editors/space_graph/graph_select.cc +++ b/source/blender/editors/space_graph/graph_select.cc @@ -2213,17 +2213,17 @@ void GRAPH_OT_select_key_handles(wmOperatorType *ot) prop_graphkeys_select_key_handles_actions, GRAPHKEYS_KEYHANDLESSEL_SELECT, "Left Handle", - "How to affect the selection of the left handle"); + "Effect on the left handle"); RNA_def_enum(ot->srna, "right_handle_action", prop_graphkeys_select_key_handles_actions, GRAPHKEYS_KEYHANDLESSEL_SELECT, "Right Handle", - "How to affect the selection of the right handle"); + "Effect on the right handle"); RNA_def_enum(ot->srna, "key_action", prop_graphkeys_select_key_handles_actions, GRAPHKEYS_KEYHANDLESSEL_KEEP, "Key", - "How to affect the selection of the key itself"); + "Effect on the key itself"); } \ No newline at end of file -- 2.30.2 From 645d9ac29db665822075c169b645ec530cd8c853 Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Thu, 21 Sep 2023 14:56:30 +0200 Subject: [PATCH 11/11] Use indexing instead of pointer incrementing --- source/blender/editors/space_graph/graph_select.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/blender/editors/space_graph/graph_select.cc b/source/blender/editors/space_graph/graph_select.cc index c1fddcad09e..a199f3321d9 100644 --- a/source/blender/editors/space_graph/graph_select.cc +++ b/source/blender/editors/space_graph/graph_select.cc @@ -2107,9 +2107,9 @@ static void graphkeys_select_key_handles( continue; } - int i = 0; - BezTriple *bezt = fcu->bezt; - for (; i < fcu->totvert; bezt++, i++) { + for (int i = 0; i < fcu->totvert; i++) { + BezTriple *bezt = &fcu->bezt[i]; + if (!BEZT_ISSEL_ANY(bezt)) { continue; } -- 2.30.2