Transform: Deduplicate time snap code

This commit is contained in:
Germano Cavalcante 2020-02-15 12:09:23 -03:00
parent f0c991a380
commit de9ea94fc6
Notes: blender-bot 2023-02-14 11:24:03 +01:00
Referenced by commit b0d9e6797f, Fix T87173: wrong Auto-Snap in animation editors
Referenced by issue #87173, Some Auto-Snap options in animation editors don't work correctly
3 changed files with 5 additions and 43 deletions

View File

@ -1063,11 +1063,11 @@ short getAnimEdit_SnapMode(TransInfo *t)
void doAnimEdit_SnapFrame(
TransInfo *t, TransData *td, TransData2D *td2d, AnimData *adt, short autosnap)
{
if (ELEM(autosnap, SACTSNAP_FRAME, SACTSNAP_SECOND, SACTSNAP_MARKER)) {
if (autosnap != SACTSNAP_OFF) {
float val;
/* convert frame to nla-action time (if needed) */
if (adt) {
if (adt && (t->spacetype != SPACE_SEQ)) {
val = BKE_nla_tweakedit_remap(adt, *(td->val), NLATIME_CONVERT_MAP);
}
else {
@ -1077,7 +1077,7 @@ void doAnimEdit_SnapFrame(
snapFrameTransform(t, autosnap, true, val, &val);
/* convert frame out of nla-action time */
if (adt) {
if (adt && (t->spacetype != SPACE_SEQ)) {
*(td->val) = BKE_nla_tweakedit_remap(adt, val, NLATIME_CONVERT_UNMAP);
}
else {

View File

@ -81,13 +81,6 @@ static void applyTimeScaleValue(TransInfo *t, float value)
float startx = CFRA;
float fac = value;
if (autosnap == SACTSNAP_TSTEP) {
fac = (float)(floor((double)fac / secf + 0.5) * secf);
}
else if (autosnap == SACTSNAP_STEP) {
fac = floorf(fac + 0.5f);
}
/* take proportional editing into account */
fac = ((fac - 1.0f) * td->factor) + 1;

View File

@ -87,7 +87,7 @@ static void headerTimeTranslate(TransInfo *t, char str[UI_MAX_DRAW_STR])
}
}
static void applyTimeTranslateValue(TransInfo *t, float value)
static void applyTimeTranslateValue(TransInfo *t, const float deltax)
{
Scene *scene = t->scene;
int i;
@ -95,8 +95,6 @@ static void applyTimeTranslateValue(TransInfo *t, float value)
const short autosnap = getAnimEdit_SnapMode(t);
const double secf = FPS;
float deltax, val /* , valprev */;
FOREACH_TRANS_DATA_CONTAINER (t, tc) {
TransData *td = tc->data;
TransData2D *td2d = tc->data_2d;
@ -110,37 +108,8 @@ static void applyTimeTranslateValue(TransInfo *t, float value)
*/
AnimData *adt = (t->spacetype != SPACE_NLA) ? td->extra : NULL;
/* valprev = *td->val; */ /* UNUSED */
/* check if any need to apply nla-mapping */
if (adt && (t->spacetype != SPACE_SEQ)) {
deltax = value;
if (autosnap == SACTSNAP_TSTEP) {
deltax = (float)(floor(((double)deltax / secf) + 0.5) * secf);
}
else if (autosnap == SACTSNAP_STEP) {
deltax = floorf(deltax + 0.5f);
}
val = BKE_nla_tweakedit_remap(adt, td->ival, NLATIME_CONVERT_MAP);
val += deltax * td->factor;
*(td->val) = BKE_nla_tweakedit_remap(adt, val, NLATIME_CONVERT_UNMAP);
}
else {
deltax = val = t->values_final[0];
if (autosnap == SACTSNAP_TSTEP) {
val = (float)(floor(((double)deltax / secf) + 0.5) * secf);
}
else if (autosnap == SACTSNAP_STEP) {
val = floorf(val + 0.5f);
}
*(td->val) = td->ival + val * td->factor;
}
/* apply nearest snapping */
*(td->val) = td->ival + deltax * td->factor;
doAnimEdit_SnapFrame(t, td, td2d, adt, autosnap);
}
}