diff options
author | Hans Goudey <h.goudey@me.com> | 2020-10-07 16:27:58 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2020-10-07 16:27:58 +0300 |
commit | 983ad4210b9e3dc6fe98553e686b213423e00fa1 (patch) | |
tree | 06361a54c87221515d112e94892078eced25e01f /source/blender/editors/space_graph/graph_buttons.c | |
parent | ef235b0f172832403c5eaa2b2d510dd6f0dd8a14 (diff) |
Fix T76595: Indicate the Active Keyframe in Graph Editor
In the graph editor there is a panel that says "Active Keyframe" for
numerically editing a keyframe's values, but in the code there is no
concept of the "active keyframe." Since this is a useful concept to
have for some other features anyway, this commit adds an active
keyframe index value to FCurves. It also displays it with a theme
color for the active vertex (which didn't exist before) if the
FCurve is active.
The active keyframe in the graph editor is treated similarly to the
active vertex in the 3D view. It is the keyframe most recently selected
with a single click, and it is always selected.
For now, the only real functional change is that the active keyframe
appears in white and it should be more predictable which keyframe is
being edited in the sidebar panel.
Differential Revision: https://developer.blender.org/D7737
Diffstat (limited to 'source/blender/editors/space_graph/graph_buttons.c')
-rw-r--r-- | source/blender/editors/space_graph/graph_buttons.c | 35 |
1 files changed, 11 insertions, 24 deletions
diff --git a/source/blender/editors/space_graph/graph_buttons.c b/source/blender/editors/space_graph/graph_buttons.c index 45c43a5853d..bbdca5280d4 100644 --- a/source/blender/editors/space_graph/graph_buttons.c +++ b/source/blender/editors/space_graph/graph_buttons.c @@ -235,40 +235,27 @@ static void graph_panel_properties(const bContext *C, Panel *panel) /* ******************* active Keyframe ************** */ /* get 'active' keyframe for panel editing */ -static bool get_active_fcurve_keyframe_edit(FCurve *fcu, +static bool get_active_fcurve_keyframe_edit(const FCurve *fcu, BezTriple **r_bezt, BezTriple **r_prevbezt) { - BezTriple *b; - int i; - /* zero the pointers */ *r_bezt = *r_prevbezt = NULL; - /* sanity checks */ - if ((fcu->bezt == NULL) || (fcu->totvert == 0)) { + const int active_keyframe_index = BKE_fcurve_active_keyframe_index(fcu); + if (active_keyframe_index == FCURVE_ACTIVE_KEYFRAME_NONE) { return false; } - /* find first selected keyframe for now, and call it the active one - * - this is a reasonable assumption, given that whenever anyone - * wants to edit numerically, there is likely to only be 1 vert selected - */ - for (i = 0, b = fcu->bezt; i < fcu->totvert; i++, b++) { - if (BEZT_ISSEL_ANY(b)) { - /* found - * - 'previous' is either the one before, of the keyframe itself (which is still fine) - * XXX: we can just make this null instead if needed - */ - *r_prevbezt = (i > 0) ? b - 1 : b; - *r_bezt = b; - - return true; - } - } + /* The active keyframe should be selected. */ + BLI_assert(BEZT_ISSEL_ANY(&fcu->bezt[active_keyframe_index])); + + *r_bezt = &fcu->bezt[active_keyframe_index]; + /* Previous is either one before the active, or the point itself if it's the first. */ + const int prev_index = max_ii(active_keyframe_index - 1, 0); + *r_prevbezt = &fcu->bezt[prev_index]; - /* not found */ - return false; + return true; } /* update callback for active keyframe properties - base updates stuff */ |