forked from bartvdbraak/blender
Fix T39819: Decouple autosnap behaviour from time display
This commit cleans up and fixes some problems related to how the auto-snapping behaviour in the animation editors works, resolving the issues mentioned in T39819. 1) "Nearest Frame" no longer snaps to the nearest second when time is displayed in seconds. Instead, there is now also a "Nearest Second" option, so that either can be used as needed instead of only when a certain time display is used. 2) A similar change has been made for "Time Step" - This is now "Frame Step" and "Second Step" respectively. Notes: * Removed the unneeded getAnimEdit_DrawTime() * Time Step/Frame Step don't work for Graph Editor yet (and seem to not have worked at all) * NLA Editor also seems to be showing some weirdness now. Will be checked on. * Cancelling nearest-second snapping doesn't work nicely, due to another bug with GraphEdit transforms.
This commit is contained in:
parent
1ae3a3fc16
commit
9c28a24153
@ -7201,55 +7201,15 @@ static short getAnimEdit_SnapMode(TransInfo *t)
|
||||
return autosnap;
|
||||
}
|
||||
|
||||
/* This function is used for testing if an Animation Editor is displaying
|
||||
* its data in frames or seconds (and the data needing to be edited as such).
|
||||
* Returns 1 if in seconds, 0 if in frames
|
||||
*/
|
||||
static bool getAnimEdit_DrawTime(TransInfo *t)
|
||||
{
|
||||
bool drawtime;
|
||||
|
||||
if (t->spacetype == SPACE_ACTION) {
|
||||
SpaceAction *saction = (SpaceAction *)t->sa->spacedata.first;
|
||||
|
||||
drawtime = (saction->flag & SACTION_DRAWTIME) != 0;
|
||||
}
|
||||
else if (t->spacetype == SPACE_NLA) {
|
||||
SpaceNla *snla = (SpaceNla *)t->sa->spacedata.first;
|
||||
|
||||
drawtime = (snla->flag & SNLA_DRAWTIME) != 0;
|
||||
}
|
||||
else if (t->spacetype == SPACE_IPO) {
|
||||
SpaceIpo *sipo = (SpaceIpo *)t->sa->spacedata.first;
|
||||
|
||||
drawtime = (sipo->flag & SIPO_DRAWTIME) != 0;
|
||||
}
|
||||
else {
|
||||
drawtime = false;
|
||||
}
|
||||
|
||||
return drawtime;
|
||||
}
|
||||
|
||||
|
||||
/* This function is used by Animation Editor specific transform functions to do
|
||||
* the Snap Keyframe to Nearest Frame/Marker
|
||||
*/
|
||||
static void doAnimEdit_SnapFrame(TransInfo *t, TransData *td, TransData2D *td2d, AnimData *adt, short autosnap)
|
||||
{
|
||||
/* snap key to nearest frame? */
|
||||
if (autosnap == SACTSNAP_FRAME) {
|
||||
|
||||
#if 0 /* 'do_time' disabled for now */
|
||||
|
||||
/* snap key to nearest frame or second? */
|
||||
if (ELEM(autosnap, SACTSNAP_FRAME, SACTSNAP_SECOND)) {
|
||||
const Scene *scene = t->scene;
|
||||
#if 0 /* NOTE: this works, but may be confusing behavior given the option's label, hence disabled */
|
||||
const bool do_time = getAnimEdit_DrawTime(t);
|
||||
#else
|
||||
const bool do_time = false;
|
||||
#endif
|
||||
const double secf = FPS;
|
||||
#endif
|
||||
double val;
|
||||
|
||||
/* convert frame to nla-action time (if needed) */
|
||||
@ -7258,16 +7218,12 @@ static void doAnimEdit_SnapFrame(TransInfo *t, TransData *td, TransData2D *td2d,
|
||||
else
|
||||
val = *(td->val);
|
||||
|
||||
#if 0 /* 'do_time' disabled for now */
|
||||
|
||||
/* do the snapping to nearest frame/second */
|
||||
if (do_time) {
|
||||
val = (float)(floor((val / secf) + 0.5f) * secf);
|
||||
if (autosnap == SACTSNAP_FRAME) {
|
||||
val = floorf(val + 0.5);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
val = floor(val + 0.5);
|
||||
else if (autosnap == SACTSNAP_SECOND) {
|
||||
val = (float)(floor((val / secf) + 0.5f) * secf);
|
||||
}
|
||||
|
||||
/* convert frame out of nla-action time */
|
||||
@ -7355,19 +7311,20 @@ static void headerTimeTranslate(TransInfo *t, char str[MAX_INFO_LEN])
|
||||
else {
|
||||
const Scene *scene = t->scene;
|
||||
const short autosnap = getAnimEdit_SnapMode(t);
|
||||
const bool do_time = getAnimEdit_DrawTime(t);
|
||||
const double secf = FPS;
|
||||
float val = t->values[0];
|
||||
|
||||
/* apply snapping + frame->seconds conversions */
|
||||
if (autosnap == SACTSNAP_STEP) {
|
||||
if (do_time)
|
||||
val = floorf((double)val / secf + 0.5);
|
||||
else
|
||||
/* frame step */
|
||||
val = floorf(val + 0.5f);
|
||||
}
|
||||
else if (autosnap == SACTSNAP_TSTEP) {
|
||||
/* second step */
|
||||
val = floorf((double)val / secf + 0.5);
|
||||
}
|
||||
else {
|
||||
if (do_time)
|
||||
/* nearest frame/second/marker */
|
||||
val = (float)((double)val / secf);
|
||||
}
|
||||
|
||||
@ -7387,10 +7344,8 @@ static void applyTimeTranslateValue(TransInfo *t, float UNUSED(sval))
|
||||
Scene *scene = t->scene;
|
||||
int i;
|
||||
|
||||
const bool do_time = getAnimEdit_DrawTime(t);
|
||||
const double secf = FPS;
|
||||
|
||||
const short autosnap = getAnimEdit_SnapMode(t);
|
||||
const double secf = FPS;
|
||||
|
||||
float deltax, val /* , valprev */;
|
||||
|
||||
@ -7405,13 +7360,13 @@ static void applyTimeTranslateValue(TransInfo *t, float UNUSED(sval))
|
||||
/* valprev = *td->val; */ /* UNUSED */
|
||||
|
||||
/* check if any need to apply nla-mapping */
|
||||
if (adt && t->spacetype != SPACE_SEQ) {
|
||||
if (adt && (t->spacetype != SPACE_SEQ)) {
|
||||
deltax = t->values[0];
|
||||
|
||||
if (autosnap == SACTSNAP_STEP) {
|
||||
if (do_time)
|
||||
if (autosnap == SACTSNAP_TSTEP) {
|
||||
deltax = (float)(floor(((double)deltax / secf) + 0.5) * secf);
|
||||
else
|
||||
}
|
||||
else if (autosnap == SACTSNAP_STEP) {
|
||||
deltax = (float)(floor(deltax + 0.5f));
|
||||
}
|
||||
|
||||
@ -7422,10 +7377,10 @@ static void applyTimeTranslateValue(TransInfo *t, float UNUSED(sval))
|
||||
else {
|
||||
deltax = val = t->values[0];
|
||||
|
||||
if (autosnap == SACTSNAP_STEP) {
|
||||
if (do_time)
|
||||
if (autosnap == SACTSNAP_TSTEP) {
|
||||
val = (float)(floor(((double)deltax / secf) + 0.5) * secf);
|
||||
else
|
||||
}
|
||||
else if (autosnap == SACTSNAP_STEP) {
|
||||
val = (float)(floor(val + 0.5f));
|
||||
}
|
||||
|
||||
@ -7674,7 +7629,6 @@ static void applyTimeScaleValue(TransInfo *t)
|
||||
int i;
|
||||
|
||||
const short autosnap = getAnimEdit_SnapMode(t);
|
||||
const bool do_time = getAnimEdit_DrawTime(t);
|
||||
const double secf = FPS;
|
||||
|
||||
|
||||
@ -7687,10 +7641,10 @@ static void applyTimeScaleValue(TransInfo *t)
|
||||
float startx = CFRA;
|
||||
float fac = t->values[0];
|
||||
|
||||
if (autosnap == SACTSNAP_STEP) {
|
||||
if (do_time)
|
||||
if (autosnap == SACTSNAP_TSTEP) {
|
||||
fac = (float)(floor((double)fac / secf + 0.5) * secf);
|
||||
else
|
||||
}
|
||||
else if (autosnap == SACTSNAP_STEP) {
|
||||
fac = (float)(floor(fac + 0.5f));
|
||||
}
|
||||
|
||||
|
@ -4110,13 +4110,14 @@ void flushTransGraphData(TransInfo *t)
|
||||
*/
|
||||
if ((td->flag & TD_NOTIMESNAP) == 0) {
|
||||
switch (sipo->autosnap) {
|
||||
case SACTSNAP_FRAME: /* snap to nearest frame (or second if drawing seconds) */
|
||||
if (sipo->flag & SIPO_DRAWTIME)
|
||||
td2d->loc[0] = floor(((double)td2d->loc[0] / secf) + 0.5) * secf;
|
||||
else
|
||||
case SACTSNAP_FRAME: /* snap to nearest frame */
|
||||
td2d->loc[0] = floor((double)td2d->loc[0] + 0.5);
|
||||
break;
|
||||
|
||||
case SACTSNAP_SECOND: /* snap to nearest second */
|
||||
td2d->loc[0] = floor(((double)td2d->loc[0] / secf) + 0.5) * secf;
|
||||
break;
|
||||
|
||||
case SACTSNAP_MARKER: /* snap to nearest marker */
|
||||
td2d->loc[0] = (float)ED_markers_find_nearest_marker_time(&t->scene->markers, td2d->loc[0]);
|
||||
break;
|
||||
|
@ -655,7 +655,11 @@ typedef enum eAnimEdit_AutoSnap {
|
||||
/* snap to actual frames/seconds (nla-action time) */
|
||||
SACTSNAP_FRAME = 2,
|
||||
/* snap to nearest marker */
|
||||
SACTSNAP_MARKER = 3
|
||||
SACTSNAP_MARKER = 3,
|
||||
/* snap to actual seconds (nla-action time) */
|
||||
SACTSNAP_SECOND = 4,
|
||||
/* snap to 1.0 second increments */
|
||||
SACTSNAP_TSTEP = 5
|
||||
} eAnimEdit_AutoSnap;
|
||||
|
||||
|
||||
|
@ -112,8 +112,13 @@ static EnumPropertyItem transform_orientation_items[] = {
|
||||
#ifndef RNA_RUNTIME
|
||||
static EnumPropertyItem autosnap_items[] = {
|
||||
{SACTSNAP_OFF, "NONE", 0, "No Auto-Snap", ""},
|
||||
{SACTSNAP_STEP, "STEP", 0, "Time Step", "Snap to 1.0 frame/second intervals"},
|
||||
{SACTSNAP_FRAME, "FRAME", 0, "Nearest Frame", "Snap to actual frames/seconds (nla-action time)"},
|
||||
/* {-1, "", 0, "", ""}, */
|
||||
{SACTSNAP_STEP, "STEP", 0, "Frame Step", "Snap to 1.0 frame intervals"},
|
||||
{SACTSNAP_TSTEP, "TIME_STEP", 0, "Second Step", "Snap to 1.0 second intervals"},
|
||||
/* {-1, "", 0, "", ""}, */
|
||||
{SACTSNAP_FRAME, "FRAME", 0, "Nearest Frame", "Snap to actual frames (nla-action time)"},
|
||||
{SACTSNAP_SECOND, "SECOND", 0, "Nearest Second", "Snap to actual seconds (nla-action time)"},
|
||||
/* {-1, "", 0, "", ""}, */
|
||||
{SACTSNAP_MARKER, "MARKER", 0, "Nearest Marker", "Snap to nearest marker"},
|
||||
{0, NULL, 0, NULL, NULL}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user