diff --git a/include/tween.h b/include/tween.h index ad64dfd..b96d341 100644 --- a/include/tween.h +++ b/include/tween.h @@ -197,6 +197,24 @@ namespace tweeny { */ template tween & during(Ds... ds); + /** + * @brief Specifies the duration, typically in milliseconds, for the delay at the last point. + * + * You can either specify a single duration for all values or give every value its own duration. Value types + * must be convertible to the uint16_t type. + * + * **Example**: + * + * @code + * // Specify waiting at the first point (0, 0) for 100 milliseconds and then continue to (200, 300). + * auto tween = tweeny::from(0, 0).wait(100).to(200, 300).during(100, 500); + * @endcode + * + * @param ds Duration values + * @returns *this + */ + template tween& wait(Ds... ds); + /** * @brief Steps the animation by the designated delta amount. * @@ -579,6 +597,7 @@ namespace tweeny { void render(float p); void dispatch(std::vector & cbVector); uint16_t pointAt(float progress) const; + void calculateTotal(); }; /** @@ -605,7 +624,8 @@ namespace tweeny { template tween & via(const std::string & easing, Fs... fs); ///< @sa tween::via template tween & via(const char * easing, Fs... fs); ///< @sa tween::via template tween & during(Ds... ds); ///< @sa tween::during - const T & step(int32_t dt, bool suppressCallbacks = false); ///< @sa tween::step(int32_t dt, bool suppressCallbacks) + template tween & wait(Ds... ds); ///< @sa tween::wait + const T & step(int32_t dt, bool suppressCallbacks = false); ///< @sa tween::step(int32_t dt, bool suppressCallbacks) const T & step(uint32_t dt, bool suppressCallbacks = false); ///< @sa tween::step(uint32_t dt, bool suppressCallbacks) const T & step(float dp, bool suppressCallbacks = false); ///< @sa tween::step(float dp, bool suppressCallbacks) const T & seek(float p, bool suppressCallbacks = false); ///< @sa tween::seek(float p, bool suppressCallbacks) @@ -648,7 +668,8 @@ namespace tweeny { void render(float p); void dispatch(std::vector & cbVector); uint16_t pointAt(float progress) const; - }; + void calculateTotal(); + }; } #include "tween.tcc" diff --git a/include/tween.tcc b/include/tween.tcc index dd0e77f..57786eb 100644 --- a/include/tween.tcc +++ b/include/tween.tcc @@ -154,15 +154,20 @@ namespace tweeny { template template inline tween & tween::during(Ds... ds) { - total = 0; points.at(points.size() - 2).during(ds...); - for (detail::tweenpoint & p : points) { - total += p.duration(); - p.stacked = total; - } + calculateTotal(); return *this; } + template + template + inline tween& tween::wait(Ds... ds) { + points.emplace_back(points.back()); + points.at(points.size() - 2).during(ds...); + calculateTotal(); + return *this; + } + template inline const typename detail::tweentraits::valuesType & tween::step(int32_t dt, bool suppress) { return step(static_cast(dt)/static_cast(total), suppress); @@ -212,6 +217,16 @@ namespace tweeny { interpolate(prog, point, values, detail::int2type{ }); } + template + inline void tween::calculateTotal() + { + total = 0; + for(detail::tweenpoint& p : points) { + total += p.duration(); + p.stacked = total; + } + } + template inline void tween::interpolate(float prog, unsigned point, typename traits::valuesType & values, detail::int2type<0>) const { auto & p = points.at(point); diff --git a/include/tweenone.tcc b/include/tweenone.tcc index c2a52ad..112e4dc 100644 --- a/include/tweenone.tcc +++ b/include/tweenone.tcc @@ -146,15 +146,20 @@ namespace tweeny { template template inline tween & tween::during(Ds... ds) { - total = 0; points.at(points.size() - 2).during(ds...); - for (detail::tweenpoint & p : points) { - total += p.duration(); - p.stacked = total; - } - return *this; + calculateTotal(); + return *this; } + template + template + inline tween& tween::wait(Ds... ds) { + points.emplace_back(points.back()); + points.at(points.size() - 2).during(ds...); + calculateTotal(); + return *this; + } + template inline const T & tween::step(int32_t dt, bool suppress) { return step(static_cast(dt)/static_cast(total), suppress); @@ -207,6 +212,16 @@ namespace tweeny { value = easing(pointTotal, std::get<0>(p.values), std::get<0>(points.at(point+1).values)); } + template + inline void tween::calculateTotal() + { + total = 0; + for(detail::tweenpoint& p : points) { + total += p.duration(); + p.stacked = total; + } + } + template inline void tween::render(float p) { currentPoint = pointAt(p);