Animation: Graph Editor Handle Selection #108142

Closed
Denys Hsu wants to merge 3 commits from cgtinker/blender:select_handles_patch into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
3 changed files with 33 additions and 33 deletions
Showing only changes of commit fdc17a70db - Show all commits

View File

@ -194,8 +194,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'
cgtinker marked this conversation as resolved Outdated

I think we should add separate entries for "select left handles" and "select right handles"
this makes it a lot more discoverable for artists and they can easily assign a hotkey by right clicking the menu entry

I think we should add separate entries for "select left handles" and "select right handles" this makes it a lot more discoverable for artists and they can easily assign a hotkey by right clicking the menu entry
layout.operator("graph.select_handles", text="Select Handles Right").mode = 'RIGHT'
layout.separator()
layout.operator("graph.select_more")

View File

@ -74,7 +74,7 @@ enum eGraphKeys_LeftRightSelect_Mode {
GRAPHKEYS_LRSEL_RIGHT,
};
/* Defines for handle selection */
/* Defines for handle selection. */
cgtinker marked this conversation as resolved Outdated

comments end with a "."

comments end with a "."
enum eGraphKey_HandleSelect_Mode {
cgtinker marked this conversation as resolved Outdated

I think 'side' would be a better noun than 'mode' here. IMO the 'mode' should also include whether the keys themselves are selected/deselected or not, which is not part of this enum.

I think 'side' would be a better noun than 'mode' here. IMO the 'mode' should also include whether the keys themselves are selected/deselected or not, which is not part of this enum.
GRAPHKEYS_HANDLESEL_LR = 0,
GRAPHKEYS_HANDLESEL_L,

View File

@ -214,8 +214,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,
cgtinker marked this conversation as resolved Outdated

when running make format this gets undone
check that you have your clang-format pointed to the binary that comes with blender. that should be in "blender-git/lib//llvm/bin"

when running `make format` this gets undone check that you have your clang-format pointed to the binary that comes with blender. that should be in "blender-git/lib/<platform-name>/llvm/bin"

thanks for the hint, pointed llvm to the wrong binary

thanks for the hint, pointed llvm to the wrong binary
v2d,
fcu,
@ -2038,15 +2037,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", ""},
cgtinker marked this conversation as resolved Outdated

Just for consistency, rename GRAPHKEYS_HANDLESEL_LR to GRAPHKEYS_HANDLESEL_BOTH.

Just for consistency, rename `GRAPHKEYS_HANDLESEL_LR` to `GRAPHKEYS_HANDLESEL_BOTH`.
{GRAPHKEYS_HANDLESEL_L, "LEFT", 0, "Select Left Handles", ""},
cgtinker marked this conversation as resolved Outdated

why is the option to select both handles called "CHECK"
"BOTH" would make more sense to me but maybe I am missing something

Also check the code style for the comment above. Comments should start with a capital letter and end with a "."

why is the option to select both handles called "CHECK" "BOTH" would make more sense to me but maybe I am missing something Also check the code style for the comment above. Comments should start with a capital letter and end with a "."

I think I copied an existing enum and modified it back then, there is no checking. In the 'C' scripts are lots of comments that don't follow this convention which is misleading, probably it would be good to create a small formatter to fix them?

I think I copied an existing enum and modified it back then, there is no checking. In the 'C' scripts are lots of comments that don't follow this convention which is misleading, probably it would be good to create a small formatter to fix them?

yeah there is quite a bit of old comments floating around that need cleaning up

yeah there is quite a bit of old comments floating around that need cleaning up
{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)
{
cgtinker marked this conversation as resolved

make that KeyframeEditData *UNUSED(ked) for all those functions
This removes the warning you get when compiling

make that `KeyframeEditData *UNUSED(ked)` for all those functions This removes the warning you get when compiling
if (BEZT_ISSEL_ANY(bezt)) {
BEZT_SEL_IDX(bezt, 0);
@ -2055,7 +2054,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);
@ -2064,7 +2063,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);
@ -2073,7 +2072,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);
@ -2081,19 +2080,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(
cgtinker marked this conversation as resolved Outdated

Remove the _de_, there are many more functions that are called 'select' but also allow deselecting.

Remove the `_de_`, there are many more functions that are called 'select' but also allow deselecting.
bAnimContext *ac,
cgtinker marked this conversation as resolved Outdated

leave a comment on what kind of enum short mode is
also can be const

leave a comment on what kind of enum `short mode` is also can be const
const short mode, // prop_graphkeys_leftright_handle_select_types
cgtinker marked this conversation as resolved Outdated

I meant add a comment that this is an enum and which it is.
e.g. enum eGraphKey_HandleSelect_Mode

also I am not sure we are supposed to use comments with //
sybren can elaborate on that

I meant add a comment that this is an enum and which it is. e.g. `enum eGraphKey_HandleSelect_Mode` also I am not sure we are supposed to use comments with // sybren can elaborate on that

Nope, see https://wiki.blender.org/wiki/Style_Guide/C_Cpp#Comments

Also, why use short here at all? IMO it should just be enum eGraphKey_HandleSelect_Mode mode.

Nope, see https://wiki.blender.org/wiki/Style_Guide/C_Cpp#Comments Also, why use `short` here at all? IMO it should just be `enum eGraphKey_HandleSelect_Mode mode`.

Also, why use short here at all? IMO it should just be enum eGraphKey_HandleSelect_Mode mode.

Yeah it should be eGraphKey_HandleSelect_Mode, will change that. Within the file all functions use a short instead of the enum prop, thought that had a reason and followed the "convention".

> Also, why use `short` here at all? IMO it should just be `enum eGraphKey_HandleSelect_Mode mode`. Yeah it should be `eGraphKey_HandleSelect_Mode`, will change that. Within the file all functions use a `short` instead of the enum prop, thought that had a reason and followed the "convention".
const bool deselect_keyframe)
cgtinker marked this conversation as resolved Outdated

It's not a good idea to have negated booleans (i.e. 'enable to disable' style ones). Just use const bool select.

Having said that, looking at the code this does something else than I expected, so definitely add a comment above the function that explains what the parameters do.

It's not a good idea to have negated booleans (i.e. 'enable to disable' style ones). Just use `const bool select`. Having said that, looking at the code this does something else than I expected, so definitely add a comment above the function that explains what the parameters do.
{
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);
cgtinker marked this conversation as resolved

can be const int filter = ...

can be `const int filter = ...`
for (ale = anim_data.first; ale; ale = ale->next) {
LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) {
FCurve *fcu = (FCurve *)ale->key_data;
cgtinker marked this conversation as resolved

Add BLI_assert(ale->type, ANIMTYPE_FCURVE) before the cast, just to have a little extra check that the cast is actually valid.

Add `BLI_assert(ale->type, ANIMTYPE_FCURVE)` before the cast, just to have a little extra check that the cast is actually valid.
cgtinker marked this conversation as resolved

this can be LISTBASE_FOREACH(bAnimListElem *, ale, &anim_data)
you then also don't need to have bAnimListElem *ale; before

this can be `LISTBASE_FOREACH(bAnimListElem *, ale, &anim_data)` you then also don't need to have `bAnimListElem *ale;` before
/* Only continue if F-Curve has keyframes. */
@ -2102,17 +2100,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;
}
cgtinker marked this conversation as resolved Outdated

I did a test and you can just pass NULL instead of &ked since you are not doing anything with ked afterwards

I did a test and you can just pass `NULL` instead of `&ked` since you are not doing anything with `ked` afterwards
case GRAPHKEYS_HANDLESEL_R: {
cgtinker marked this conversation as resolved Outdated

so far i've only seen break within the curly bracket block
but I am not sure if this is convention or not. Something to check with sybren

so far i've only seen `break` within the curly bracket block but I am not sure if this is convention or not. Something to check with sybren

Afaik it does not change anything, I just put them inside

Afaik it does not change anything, I just put them inside
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);
}
}
@ -2130,9 +2131,9 @@ static int graphkeys_select_handles_exec(bContext *C, wmOperator *op)
}
cgtinker marked this conversation as resolved Outdated

i think calling the variable also mode would be clearer
and desel_kf should be deselect_keyframe. in general we try to avoid abbreviations these days to make the code more readable.

i think calling the variable also `mode` would be clearer and `desel_kf` should be `deselect_keyframe`. in general we try to avoid abbreviations these days to make the code more readable.
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");
cgtinker marked this conversation as resolved Outdated

These variables can be const.

These variables can be `const`.
/* 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);
@ -2142,8 +2143,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";
@ -2159,8 +2158,8 @@ void GRAPH_OT_select_handles(wmOperatorType *ot)
ot->prop = RNA_def_enum(ot->srna,
cgtinker marked this conversation as resolved

you don't need to assign the RNA_def to anything
so it can just be RNA_def... instead of ot->prop = RNA_def

now I didn't know the operator type had a prop. And I am not sure what it is used for.
Maybe also something for sybren to clear up

you don't need to assign the RNA_def to anything so it can just be `RNA_def...` instead of `ot->prop = RNA_def` now I didn't know the operator type had a prop. And I am not sure what it is used for. Maybe also something for sybren to clear up

It's documented as:

  /**
   * Default rna property to use for generic invoke functions.
   * menus, enum search... etc. Example: Enum 'type' for a Delete menu.
   *
   * When assigned a string/number property,
   * immediately edit the value when used in a popup. see: #UI_BUT_ACTIVATE_ON_INIT.
   */
  PropertyRNA *prop;

So this means that it can be used for certain interactions as a special property.

@ChrisLend is right in that here the assignment is unnecessary. And if there is a property that should be marked as that special one property, it should only be assigned once, and not assigned and then immediately be overwritten again.

It's documented as: ```c /** * Default rna property to use for generic invoke functions. * menus, enum search... etc. Example: Enum 'type' for a Delete menu. * * When assigned a string/number property, * immediately edit the value when used in a popup. see: #UI_BUT_ACTIVATE_ON_INIT. */ PropertyRNA *prop; ``` So this means that it can be used for certain interactions as a special property. @ChrisLend is right in that here the assignment is unnecessary. And if there is a property that should be marked as that special one property, it should only be assigned once, and not assigned and then immediately be overwritten again.
"mode",
cgtinker marked this conversation as resolved Outdated

you don't need to assign the RNA_def functions to anything
that way you can also remove PropertyRNA *prop; for which I get an unused warning anyway

you don't need to assign the `RNA_def` functions to anything that way you can also remove `PropertyRNA *prop;` for which I get an unused warning anyway
prop_graphkeys_leftright_handle_select_types,
GRAPHKEYS_LRSEL_TEST,
GRAPHKEYS_HANDLESEL_LR,
"Mode",
"(De)Select handles based on selection");
cgtinker marked this conversation as resolved

"Select handles based on selection" is too vague.

"Select handles based on selection" is too vague.
prop = RNA_def_boolean(ot->srna, "desel_kf", 1, "Deselect Keyframes", "");
ot->prop = RNA_def_boolean(ot->srna, "deselect_keyframe", 1, "Deselect Keyframes", "");
cgtinker marked this conversation as resolved Outdated

This should have a tooltip that explains what it does.

This should have a tooltip that explains what it does.
}