Refactor: move keyframe-adding function from RNA to editors/animation
The RNA function `fcurve.keyframe_points.add(N)` was purely implemented in the RNA wrapper. It now sits in `ED_keyframes_add(fcu, N)` where it can be used by other C code as well. It's in the editors code, as regular keyframe insertion is there as well. No functional changes.
This commit is contained in:
@@ -1659,6 +1659,29 @@ int insert_keyframe(Main *bmain,
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ED_keyframes_add(FCurve *fcu, int num_keys_to_add)
|
||||
{
|
||||
BLI_assert_msg(num_keys_to_add >= 0, "cannot remove keyframes with this function");
|
||||
|
||||
if (num_keys_to_add == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
fcu->bezt = MEM_recallocN(fcu->bezt, sizeof(BezTriple) * (fcu->totvert + num_keys_to_add));
|
||||
BezTriple *bezt = fcu->bezt + fcu->totvert; /* Pointer to the first new one. '*/
|
||||
|
||||
fcu->totvert += num_keys_to_add;
|
||||
|
||||
/* Iterate over the new keys to update their settings. */
|
||||
while (num_keys_to_add--) {
|
||||
/* Defaults, ignoring user-preference gives predictable results for API. */
|
||||
bezt->f1 = bezt->f2 = bezt->f3 = SELECT;
|
||||
bezt->ipo = BEZT_IPO_BEZ;
|
||||
bezt->h1 = bezt->h2 = HD_AUTO_ANIM;
|
||||
bezt++;
|
||||
}
|
||||
}
|
||||
|
||||
/* ************************************************** */
|
||||
/* KEYFRAME DELETION */
|
||||
|
||||
|
||||
@@ -123,6 +123,17 @@ int insert_vert_fcurve(struct FCurve *fcu,
|
||||
eBezTriple_KeyframeType keyframe_type,
|
||||
eInsertKeyFlags flag);
|
||||
|
||||
/**
|
||||
* Add the given number of keyframes to the FCurve. Their coordinates are
|
||||
* uninitialized, so the curve should not be used without further attention.
|
||||
*
|
||||
* The newly created keys are selected, existing keys are not touched.
|
||||
*
|
||||
* This can be used to allocate all the keys at once, and then update them
|
||||
* afterwards.
|
||||
*/
|
||||
void ED_keyframes_add(struct FCurve *fcu, int num_keys_to_add);
|
||||
|
||||
/* -------- */
|
||||
|
||||
/**
|
||||
|
||||
@@ -1071,24 +1071,12 @@ static BezTriple *rna_FKeyframe_points_insert(
|
||||
|
||||
static void rna_FKeyframe_points_add(ID *id, FCurve *fcu, Main *bmain, int tot)
|
||||
{
|
||||
if (tot > 0) {
|
||||
BezTriple *bezt;
|
||||
|
||||
fcu->bezt = MEM_recallocN(fcu->bezt, sizeof(BezTriple) * (fcu->totvert + tot));
|
||||
|
||||
bezt = fcu->bezt + fcu->totvert;
|
||||
fcu->totvert += tot;
|
||||
|
||||
while (tot--) {
|
||||
/* Defaults, ignoring user-preference gives predictable results for API. */
|
||||
bezt->f1 = bezt->f2 = bezt->f3 = SELECT;
|
||||
bezt->ipo = BEZT_IPO_BEZ;
|
||||
bezt->h1 = bezt->h2 = HD_AUTO_ANIM;
|
||||
bezt++;
|
||||
}
|
||||
|
||||
rna_tag_animation_update(bmain, id);
|
||||
if (tot <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
ED_keyframes_add(fcu, tot);
|
||||
rna_tag_animation_update(bmain, id);
|
||||
}
|
||||
|
||||
static void rna_FKeyframe_points_remove(
|
||||
|
||||
Reference in New Issue
Block a user