updated timeline tools to allow rounding as well as flooring to find the frame

at the mouse cursor point
This commit is contained in:
itsmattkc
2020-01-02 04:11:50 +11:00
parent e8fddc2d5b
commit ae71b206cd
11 changed files with 101 additions and 54 deletions
@@ -18,18 +18,31 @@ const double &TimelineScaledObject::timebase_dbl()
return timebase_dbl_;
}
rational TimelineScaledObject::SceneToTime(const double &x, const double &x_scale, const rational &timebase, bool round)
{
double unscaled_time = x / x_scale / timebase.toDouble();
// Adjust screen point by scale and timebase
qint64 rounded_x_mvmt;
if (round) {
rounded_x_mvmt = qRound64(unscaled_time);
} else {
rounded_x_mvmt = qFloor(unscaled_time);
}
// Return a time in the timebase
return rational(rounded_x_mvmt * timebase.numerator(), timebase.denominator());
}
double TimelineScaledObject::TimeToScene(const rational &time)
{
return time.toDouble() * scale_;
}
rational TimelineScaledObject::SceneToTime(const double &x)
rational TimelineScaledObject::SceneToTime(const double &x, bool round)
{
// Adjust screen point by scale and timebase
qint64 scaled_x_mvmt = qFloor(x / scale_ / timebase_dbl_);
// Return a time in the timebase
return rational(scaled_x_mvmt * timebase_.numerator(), timebase_.denominator());
return SceneToTime(x, scale_, timebase_, round);
}
void TimelineScaledObject::SetTimebaseInternal(const rational &timebase)