37#ifndef TWEENY_TWEENY_H
38#define TWEENY_TWEENY_H
44#include "detail/tuple-utilities.h"
68 template <
bool WasToCalled,
typename FirstValue,
typename... RemainingValues>
71 template <
typename FirstValue,
typename... RemainingValues>
82 class tweeny_builder<false, FirstValue, RemainingValues...> {
83 typedef std::vector<
detail::key_frame<FirstValue, RemainingValues...>> key_frames_t;
84 typedef tween<FirstValue, RemainingValues...> tween_t;
85 static size_t constexpr value_count = 1 +
sizeof...(RemainingValues);
88 explicit tweeny_builder(FirstValue firstComponent, RemainingValues... remainingComponents) {
89 key_frames.emplace_back(firstComponent, remainingComponents...);
92 explicit tweeny_builder(key_frames_t && frames) : key_frames(std::move(frames)) {}
93 explicit tweeny_builder(
const key_frames_t & frames) : key_frames(frames) {}
109 tweeny_builder<
true, FirstValue, RemainingValues...>
to(
const FirstValue & firstComponent,
const RemainingValues &... remainingComponents) & {
110 key_frames.emplace_back(firstComponent, remainingComponents...);
111 return tweeny_builder<
true, FirstValue, RemainingValues...>(key_frames);
115 tweeny_builder<
true, FirstValue, RemainingValues...>
to(
const FirstValue & firstComponent,
const RemainingValues &... remainingComponents) && {
116 key_frames.emplace_back(firstComponent, remainingComponents...);
117 return tweeny_builder<
true, FirstValue, RemainingValues...>(std::move(key_frames));
121 key_frames_t key_frames;
134 template <
typename FirstValue,
typename... RemainingValues>
135 class tweeny_builder<true, FirstValue, RemainingValues...> {
136 typedef std::vector<
detail::key_frame<FirstValue, RemainingValues...>> key_frames_t;
137 typedef tween<FirstValue, RemainingValues...> tween_t;
138 static size_t constexpr value_count = 1 +
sizeof...(RemainingValues);
141 explicit tweeny_builder(FirstValue firstComponent, RemainingValues... remainingComponents) {
142 key_frames.emplace_back(firstComponent, remainingComponents...);
145 explicit tweeny_builder(key_frames_t && frames) : key_frames(std::move(frames)) {}
146 explicit tweeny_builder(
const key_frames_t & frames) : key_frames(frames) {}
168 tweeny_builder
to(
const FirstValue & firstComponent,
const RemainingValues &... remainingComponents) & {
169 key_frames.emplace_back(firstComponent, remainingComponents...);
170 return tweeny_builder(key_frames);
174 tweeny_builder
to(
const FirstValue & firstComponent,
const RemainingValues &... remainingComponents) && {
175 key_frames.emplace_back(firstComponent, remainingComponents...);
176 return tweeny_builder(std::move(key_frames));
197 template<
typename... EasingFunctionTypes>
198 tweeny_builder &
via(EasingFunctionTypes... easing_functions) {
199 static_assert(
sizeof...(EasingFunctionTypes) == value_count,
200 "via() must have one easing function per tween component");
201 auto & key_frame = key_frames.at(key_frames.size() - 2);
202 key_frame.easing_functions = std::make_tuple(easing_functions...);
220 template<
typename EasingFunctionType>
221 tweeny_builder &
via(EasingFunctionType easing_function) {
222 auto & key_frame = key_frames.at(key_frames.size() - 2);
223 key_frame.easing_functions = detail::make_repeated_tuple<EasingFunctionType, value_count>(easing_function);
244 template<
typename... FrameCountsType>
245 tweeny_builder &
during(FrameCountsType... frame_counts) {
246 static_assert(
sizeof...(FrameCountsType) == value_count,
247 "during() must have one frame count per tween component");
248 static_assert((std::is_same_v<std::decay_t<FrameCountsType>, uint32_t> && ...),
249 "during() parameters must be of type uint32_t");
250 auto & key_frame = key_frames.at(key_frames.size() - 2);
251 std::array<uint32_t,
sizeof...(FrameCountsType)> frame_counts_array = { frame_counts... };
253 std::begin(frame_counts_array),
254 std::end(frame_counts_array),
255 std::begin(key_frame.tween_frame_counts));
256 fix_frame_positions();
274 tweeny_builder &
during(uint32_t frame_count) {
275 auto & key_frame = key_frames.at(key_frames.size() - 2);
277 std::begin(key_frame.tween_frame_counts),
278 std::end(key_frame.tween_frame_counts),
281 fix_frame_positions();
315 key_frames_t key_frames;
316 void fix_frame_positions() {
317 uint32_t key_frame_position = 0;
318 for (
auto & key_frame : key_frames) {
319 key_frame.position = key_frame_position;
320 key_frame_position += key_frame.highest_frame_count();
346 template <
typename FirstValue,
typename... RemainingValues>
347 tweeny_builder<
false, FirstValue, RemainingValues...>
from(FirstValue firstComponent, RemainingValues... remainingComponents) {
348 return tweeny_builder<
false, FirstValue, RemainingValues...>(firstComponent, remainingComponents...);
A tween represents an animation between keyframes.
Definition tween.h:68
tweeny_builder< true, FirstValue, RemainingValues... > to(const FirstValue &firstComponent, const RemainingValues &... remainingComponents) &
Adds a target keyframe to the tween.
Definition tweeny.h:109
tweeny_builder< true, FirstValue, RemainingValues... > to(const FirstValue &firstComponent, const RemainingValues &... remainingComponents) &&
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition tweeny.h:115
tweeny_builder & during(FrameCountsType... frame_counts)
Specifies per-component frame durations for the last keyframe segment.
Definition tweeny.h:245
tweeny_builder & via(EasingFunctionType easing_function)
Specifies a single easing function for all components.
Definition tweeny.h:221
tweeny_builder to(const FirstValue &firstComponent, const RemainingValues &... remainingComponents) &
Adds another keyframe to create multipoint animations.
Definition tweeny.h:168
tweeny_builder & during(uint32_t frame_count)
Specifies a uniform frame duration for all components.
Definition tweeny.h:274
tween_t build() const &
Constructs a tween object from the configured keyframes.
Definition tweeny.h:309
tweeny_builder & via(EasingFunctionTypes... easing_functions)
Specifies per-component easing functions for the last keyframe segment.
Definition tweeny.h:198
tweeny_builder to(const FirstValue &firstComponent, const RemainingValues &... remainingComponents) &&
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition tweeny.h:174
tween_t build() &&
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition tweeny.h:312
Primary template for the tween builder type.
Definition tweeny.h:69
tweeny_builder< false, FirstValue, RemainingValues... > from(FirstValue firstComponent, RemainingValues... remainingComponents)
Creates a new tween builder starting from the specified value(s).
Definition tweeny.h:347
Contains all public API types and functions for creating and managing tweens.
Definition manual.dox:1
Represents a key frame in a tween.
Definition key-frame.h:48