[Bf-blender-cvs] [1b28635] master: Graph Editor: Snap and Mirror keyframes now respect Cursor X in Drivers mode

Joshua Leung noreply at git.blender.org
Mon Oct 26 08:19:42 CET 2015


Commit: 1b286352a31c5a1320c5b481a2edc694b9b80338
Author: Joshua Leung
Date:   Mon Oct 26 20:13:29 2015 +1300
Branches: master
https://developer.blender.org/rB1b286352a31c5a1320c5b481a2edc694b9b80338

Graph Editor: Snap and Mirror keyframes now respect Cursor X in Drivers mode

When using the "Current Frame" options for these operators, the Cursor X value
will now be used instead of the current frame. Perhaps the labels could be changed
too, but for now, I guess this will be good enough.

===================================================================

M	source/blender/editors/animation/keyframes_edit.c
M	source/blender/editors/include/ED_keyframes_edit.h
M	source/blender/editors/space_graph/graph_edit.c

===================================================================

diff --git a/source/blender/editors/animation/keyframes_edit.c b/source/blender/editors/animation/keyframes_edit.c
index bd34f32..dd01e53 100644
--- a/source/blender/editors/animation/keyframes_edit.c
+++ b/source/blender/editors/animation/keyframes_edit.c
@@ -714,6 +714,14 @@ static short snap_bezier_horizontal(KeyframeEditData *UNUSED(ked), BezTriple *be
 	return 0;
 }
 
+/* frame to snap to is stored in the custom data -> first float value slot */
+static short snap_bezier_time(KeyframeEditData *ked, BezTriple *bezt)
+{
+	if (bezt->f2 & SELECT)
+		bezt->vec[1][0] = ked->f1;
+	return 0;
+}
+
 /* value to snap to is stored in the custom data -> first float value slot */
 static short snap_bezier_value(KeyframeEditData *ked, BezTriple *bezt)
 {
@@ -736,6 +744,8 @@ KeyframeEditFunc ANIM_editkeyframes_snap(short type)
 			return snap_bezier_nearestsec;
 		case SNAP_KEYS_HORIZONTAL: /* snap handles to same value */
 			return snap_bezier_horizontal;
+		case SNAP_KEYS_TIME: /* snap to given frame/time */
+			return snap_bezier_time;
 		case SNAP_KEYS_VALUE: /* snap to given value */
 			return snap_bezier_value;
 		default: /* just in case */
@@ -812,6 +822,16 @@ static short mirror_bezier_marker(KeyframeEditData *ked, BezTriple *bezt)
 	return 0;
 }
 
+static short mirror_bezier_time(KeyframeEditData *ked, BezTriple *bezt)
+{
+	/* value to mirror over is strored in f1 */
+	if (bezt->f2 & SELECT) {
+		mirror_bezier_xaxis_ex(bezt, ked->f1);
+	}
+	
+	return 0;
+}
+
 static short mirror_bezier_value(KeyframeEditData *ked, BezTriple *bezt)
 {
 	/* value to mirror over is stored in the custom data -> first float value slot */
@@ -835,6 +855,8 @@ KeyframeEditFunc ANIM_editkeyframes_mirror(short type)
 			return mirror_bezier_xaxis;
 		case MIRROR_KEYS_MARKER: /* mirror over marker */
 			return mirror_bezier_marker; 
+		case MIRROR_KEYS_TIME: /* mirror over frame/time */
+			return mirror_bezier_time;
 		case MIRROR_KEYS_VALUE: /* mirror over given value */
 			return mirror_bezier_value;
 		default: /* just in case */
diff --git a/source/blender/editors/include/ED_keyframes_edit.h b/source/blender/editors/include/ED_keyframes_edit.h
index c6ef303..910b647 100644
--- a/source/blender/editors/include/ED_keyframes_edit.h
+++ b/source/blender/editors/include/ED_keyframes_edit.h
@@ -82,7 +82,8 @@ typedef enum eEditKeyframes_Snap {
 	SNAP_KEYS_NEARSEC,
 	SNAP_KEYS_NEARMARKER,
 	SNAP_KEYS_HORIZONTAL,
-	SNAP_KEYS_VALUE
+	SNAP_KEYS_VALUE,
+	SNAP_KEYS_TIME,
 } eEditKeyframes_Snap;
 
 /* mirroring tools */
@@ -91,7 +92,8 @@ typedef enum eEditKeyframes_Mirror {
 	MIRROR_KEYS_YAXIS,
 	MIRROR_KEYS_XAXIS,
 	MIRROR_KEYS_MARKER,
-	MIRROR_KEYS_VALUE
+	MIRROR_KEYS_VALUE,
+	MIRROR_KEYS_TIME,
 } eEditKeyframes_Mirror;
 
 /* use with BEZT_OK_REGION_LASSO */
diff --git a/source/blender/editors/space_graph/graph_edit.c b/source/blender/editors/space_graph/graph_edit.c
index e423f56..78eb173 100644
--- a/source/blender/editors/space_graph/graph_edit.c
+++ b/source/blender/editors/space_graph/graph_edit.c
@@ -1995,6 +1995,7 @@ static void snap_graph_keys(bAnimContext *ac, short mode)
 	bAnimListElem *ale;
 	int filter;
 	
+	SpaceIpo *sipo = (SpaceIpo *)ac->sl;
 	KeyframeEditData ked;
 	KeyframeEditFunc edit_cb;
 	float cursor_value = 0.0f;
@@ -2003,9 +2004,7 @@ static void snap_graph_keys(bAnimContext *ac, short mode)
 	filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_NODUPLIS);
 	ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
 	
-	/* get beztriple editing callbacks */
-	edit_cb = ANIM_editkeyframes_snap(mode);
-	
+	/* init custom data for iterating over keyframes */
 	memset(&ked, 0, sizeof(KeyframeEditData)); 
 	ked.scene = ac->scene;
 	if (mode == GRAPHKEYS_SNAP_NEAREST_MARKER) {
@@ -2013,9 +2012,20 @@ static void snap_graph_keys(bAnimContext *ac, short mode)
 		ked.list.last = (ac->markers) ? ac->markers->last : NULL;
 	}
 	else if (mode == GRAPHKEYS_SNAP_VALUE) {
-		SpaceIpo *sipo = (SpaceIpo *)ac->sl;
 		cursor_value = (sipo) ? sipo->cursorVal : 0.0f;
 	}
+	else if (mode == GRAPHKEYS_SNAP_CFRA) {
+		/* In drivers mode, use the cursor value instead
+		 * (We need to use a different callback for that though)
+		 */
+		if (sipo->mode == SIPO_MODE_DRIVERS) {
+			ked.f1 = sipo->cursorTime;
+			mode = SNAP_KEYS_TIME;
+		}
+	}
+	
+	/* get beztriple editing callbacks */
+	edit_cb = ANIM_editkeyframes_snap(mode);
 	
 	/* snap keyframes */
 	for (ale = anim_data.first; ale; ale = ale->next) {
@@ -2038,7 +2048,7 @@ static void snap_graph_keys(bAnimContext *ac, short mode)
 		}
 		else 
 			ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, edit_cb, calchandles_fcurve);
-
+		
 		ale->update |= ANIM_UPDATE_DEFAULT;
 	}
 
@@ -2112,18 +2122,16 @@ static void mirror_graph_keys(bAnimContext *ac, short mode)
 	bAnimListElem *ale;
 	int filter;
 	
+	SpaceIpo *sipo = (SpaceIpo *)ac->sl;
 	KeyframeEditData ked;
 	KeyframeEditFunc edit_cb;
 	float cursor_value = 0.0f;
 
-	/* get beztriple editing callbacks */
-	edit_cb = ANIM_editkeyframes_mirror(mode);
-	
+	/* init custom data for looping over keyframes */
 	memset(&ked, 0, sizeof(KeyframeEditData)); 
 	ked.scene = ac->scene;
 	
-	/* for 'first selected marker' mode, need to find first selected marker first! */
-	// XXX should this be made into a helper func in the API?
+	/* store mode-specific custom data... */
 	if (mode == GRAPHKEYS_MIRROR_MARKER) {
 		TimeMarker *marker = NULL;
 		
@@ -2137,9 +2145,20 @@ static void mirror_graph_keys(bAnimContext *ac, short mode)
 			return;
 	}
 	else if (mode == GRAPHKEYS_MIRROR_VALUE) {
-		SpaceIpo *sipo = (SpaceIpo *)ac->sl;
 		cursor_value = (sipo) ? sipo->cursorVal : 0.0f;
 	}
+	else if (mode == GRAPHKEYS_MIRROR_CFRA) {
+		/* In drivers mode, use the cursor value instead
+		 * (We need to use a different callback for that though)
+		 */
+		if (sipo->mode == SIPO_MODE_DRIVERS) {
+			ked.f1 = sipo->cursorTime;
+			mode = MIRROR_KEYS_TIME;
+		}
+	}
+	
+	/* get beztriple editing callbacks */
+	edit_cb = ANIM_editkeyframes_mirror(mode);
 	
 	/* filter data */
 	filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_NODUPLIS);
@@ -2166,7 +2185,7 @@ static void mirror_graph_keys(bAnimContext *ac, short mode)
 		}
 		else 
 			ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, edit_cb, calchandles_fcurve);
-
+		
 		ale->update |= ANIM_UPDATE_DEFAULT;
 	}




More information about the Bf-blender-cvs mailing list