[Bf-blender-cvs] [83c9b99e760] active-fcurve-keyframe: Add active keyframe to FCurve, draw and mark with clickselect
Hans Goudey
noreply at git.blender.org
Thu Jul 16 20:16:20 CEST 2020
Commit: 83c9b99e760b565a2c5efc5f304094ca500fdf02
Author: Hans Goudey
Date: Thu May 14 16:42:13 2020 -0400
Branches: active-fcurve-keyframe
https://developer.blender.org/rB83c9b99e760b565a2c5efc5f304094ca500fdf02
Add active keyframe to FCurve, draw and mark with clickselect
===================================================================
M source/blender/editors/space_graph/graph_buttons.c
M source/blender/editors/space_graph/graph_draw.c
M source/blender/editors/space_graph/graph_select.c
M source/blender/makesdna/DNA_anim_types.h
===================================================================
diff --git a/source/blender/editors/space_graph/graph_buttons.c b/source/blender/editors/space_graph/graph_buttons.c
index 6c984860efc..e5b8340e0d0 100644
--- a/source/blender/editors/space_graph/graph_buttons.c
+++ b/source/blender/editors/space_graph/graph_buttons.c
@@ -235,38 +235,28 @@ static void graph_panel_properties(const bContext *C, Panel *panel)
/* ******************* active Keyframe ************** */
/* get 'active' keyframe for panel editing */
-static short get_active_fcurve_keyframe_edit(FCurve *fcu, BezTriple **bezt, BezTriple **prevbezt)
+static bool get_active_fcurve_keyframe_edit(FCurve *fcu, BezTriple **bezt, BezTriple **prevbezt)
{
- BezTriple *b;
- int i;
-
/* zero the pointers */
*bezt = *prevbezt = NULL;
+ int active_key = fcu->active_key;
+
/* sanity checks */
- if ((fcu->bezt == NULL) || (fcu->totvert == 0)) {
- return 0;
+ if ((fcu->bezt == NULL) || (fcu->totvert == 0) || (active_key > fcu->totvert) ||
+ (active_key < 0)) {
+ 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
- */
- *prevbezt = (i > 0) ? b - 1 : b;
- *bezt = b;
-
- return 1;
- }
+ if (BEZT_ISSEL_ANY(&fcu->bezt[active_key])) {
+ *bezt = &fcu->bezt[active_key];
+ /* Previous is either one before the active, or the point itself if it's the first. */
+ *prevbezt = &fcu->bezt[(active_key > 0) ? active_key - 1 : active_key];
+ return true;
}
/* not found */
- return 0;
+ return false;
}
/* update callback for active keyframe properties - base updates stuff */
diff --git a/source/blender/editors/space_graph/graph_draw.c b/source/blender/editors/space_graph/graph_draw.c
index eac87caf777..070c752727b 100644
--- a/source/blender/editors/space_graph/graph_draw.c
+++ b/source/blender/editors/space_graph/graph_draw.c
@@ -209,6 +209,17 @@ static void draw_fcurve_keyframe_vertices(FCurve *fcu, View2D *v2d, bool edit, u
draw_fcurve_selected_keyframe_vertices(fcu, v2d, edit, false, pos);
draw_fcurve_selected_keyframe_vertices(fcu, v2d, edit, true, pos);
+ /* One extra point for drawing the active keyframe. */
+ if (fcu->flag & FCURVE_ACTIVE) {
+ BezTriple *bezt = &fcu->bezt[fcu->active_key];
+ if (bezt->f2 & SELECT) {
+ immBegin(GPU_PRIM_POINTS, 1);
+ immUniformThemeColor(TH_VERTEX_ACTIVE);
+ immVertex2fv(pos, bezt->vec[1]);
+ immEnd();
+ }
+ }
+
immUnbindProgram();
}
@@ -271,6 +282,26 @@ static void draw_fcurve_handle_vertices(FCurve *fcu, View2D *v2d, bool sel_handl
draw_fcurve_selected_handle_vertices(fcu, v2d, false, sel_handle_only, pos);
draw_fcurve_selected_handle_vertices(fcu, v2d, true, sel_handle_only, pos);
+ /* Draw the extra handles for active points. */
+ if (fcu->flag & FCURVE_ACTIVE) {
+ BezTriple *bezt = &fcu->bezt[fcu->active_key];
+ if (!sel_handle_only || BEZT_ISSEL_ANY(bezt)) {
+ float active_col[4];
+ UI_GetThemeColor4fv(TH_VERTEX_ACTIVE, active_col);
+ immUniform4fv("outlineColor", active_col);
+ immUniformColor3fvAlpha(active_col, 0.01f); /* almost invisible - only keep for smoothness */
+ immBeginAtMost(GPU_PRIM_POINTS, 2);
+
+ if ((bezt->f1 & SELECT)) {
+ immVertex2fv(pos, bezt->vec[0]);
+ }
+ if ((bezt->f3 & SELECT)) {
+ immVertex2fv(pos, bezt->vec[2]);
+ }
+ immEnd();
+ }
+ }
+
immUnbindProgram();
}
@@ -343,6 +374,10 @@ static void draw_fcurve_handles(SpaceGraph *sipo, FCurve *fcu)
uint color = GPU_vertformat_attr_add(
format, "color", GPU_COMP_U8, 4, GPU_FETCH_INT_TO_FLOAT_UNIT);
immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
+ if ((sipo->flag & SIPO_BEAUTYDRAW_OFF) == 0) {
+ GPU_line_smooth(true);
+ }
+ GPU_blend(true);
immBeginAtMost(GPU_PRIM_LINES, 4 * 2 * fcu->totvert);
diff --git a/source/blender/editors/space_graph/graph_select.c b/source/blender/editors/space_graph/graph_select.c
index ae435b5624a..04d0e2a8092 100644
--- a/source/blender/editors/space_graph/graph_select.c
+++ b/source/blender/editors/space_graph/graph_select.c
@@ -1511,6 +1511,12 @@ static int mouse_graph_keys(bAnimContext *ac,
bezt->f3 |= SELECT;
}
}
+
+ /* Set the curve's active keyframe. */
+ if (BEZT_ISSEL_ANY(bezt)) {
+ BLI_assert(nvi->fcu != NULL);
+ nvi->fcu->active_key = (int)(bezt - nvi->fcu->bezt);
+ }
}
else if (nvi->fpt) {
// TODO: need to handle sample points
diff --git a/source/blender/makesdna/DNA_anim_types.h b/source/blender/makesdna/DNA_anim_types.h
index 6a024ec9e7e..0dadff90198 100644
--- a/source/blender/makesdna/DNA_anim_types.h
+++ b/source/blender/makesdna/DNA_anim_types.h
@@ -588,6 +588,10 @@ typedef struct FCurve {
/** Total number of points which define the curve (i.e. size of arrays in FPoints). */
unsigned int totvert;
+ /** Active keyframe for numerical editing in the interface. */
+ int active_key;
+ char _pad1[4];
+
/* value cache + settings */
/** Value stored from last time curve was evaluated (not threadsafe, debug display only!). */
float curval;
More information about the Bf-blender-cvs
mailing list