Tweeny 3.2.0
A Tweening library for modern C++
Loading...
Searching...
No Matches
easingresolve.h
1/*
2 This file is part of the Tweeny library.
3
4 Copyright (c) 2016-2021 Leonardo Guilherme Lucena de Freitas
5 Copyright (c) 2016 Guilherme R. Costa
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy of
8 this software and associated documentation files (the "Software"), to deal in
9 the Software without restriction, including without limitation the rights to
10 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 the Software, and to permit persons to whom the Software is furnished to do so,
12 subject to the following conditions:
13
14 The above copyright notice and this permission notice shall be included in all
15 copies or substantial portions of the Software.
16
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23*/
24
25/*
26 * This file provides the easing resolution mechanism so that the library user can mix lambdas and the bundled
27 * pre-defined easing functions. It shall not be used directly.
28 * This file is private.
29 */
30
31#ifndef TWEENY_EASINGRESOLVE_H
32#define TWEENY_EASINGRESOLVE_H
33
34#include <tuple>
35#include "easing.h"
36
37namespace tweeny {
38 namespace detail {
39 using std::get;
40
41 template<int I, typename TypeTuple, typename FunctionTuple, typename... Fs>
42 struct easingresolve {
43 static void impl(FunctionTuple &b, Fs... fs) {
44 if (sizeof...(Fs) == 0) return;
45 easingresolve<I, TypeTuple, FunctionTuple, Fs...>::impl(b, fs...);
46 }
47 };
48
49 template<int I, typename TypeTuple, typename FunctionTuple, typename F1, typename... Fs>
50 struct easingresolve<I, TypeTuple, FunctionTuple, F1, Fs...> {
51 static void impl(FunctionTuple &b, F1 f1, Fs... fs) {
52 get<I>(b) = f1;
53 easingresolve<I + 1, TypeTuple, FunctionTuple, Fs...>::impl(b, fs...);
54 }
55 };
56
57 template<int I, typename TypeTuple, typename FunctionTuple, typename... Fs>
58 struct easingresolve<I, TypeTuple, FunctionTuple, easing::steppedEasing, Fs...> {
59 typedef typename std::tuple_element<I, TypeTuple>::type ArgType;
60
61 static void impl(FunctionTuple &b, easing::steppedEasing, Fs... fs) {
62 get<I>(b) = easing::stepped.run<ArgType>;
63 easingresolve<I + 1, TypeTuple, FunctionTuple, Fs...>::impl(b, fs...);
64 }
65 };
66
67 template<int I, typename TypeTuple, typename FunctionTuple, typename... Fs>
68 struct easingresolve<I, TypeTuple, FunctionTuple, easing::linearEasing, Fs...> {
69 typedef typename std::tuple_element<I, TypeTuple>::type ArgType;
70
71 static void impl(FunctionTuple &b, easing::linearEasing, Fs... fs) {
72 get<I>(b) = easing::linear.run<ArgType>;
73 easingresolve<I + 1, TypeTuple, FunctionTuple, Fs...>::impl(b, fs...);
74 }
75 };
76 template<int I, typename TypeTuple, typename FunctionTuple, typename... Fs>
77 struct easingresolve<I, TypeTuple, FunctionTuple, easing::defaultEasing, Fs...> {
78 typedef typename std::tuple_element<I, TypeTuple>::type ArgType;
79
80 static void impl(FunctionTuple &b, easing::defaultEasing, Fs... fs) {
81 get<I>(b) = easing::def.run<ArgType>;
82 easingresolve<I + 1, TypeTuple, FunctionTuple, Fs...>::impl(b, fs...);
83 }
84 };
85
86 #define DECLARE_EASING_RESOLVE(__EASING_TYPE__) \
87 template <int I, typename TypeTuple, typename FunctionTuple, typename... Fs> \
88 struct easingresolve<I, TypeTuple, FunctionTuple, easing::__EASING_TYPE__ ## InEasing, Fs...> { \
89 typedef typename std::tuple_element<I, TypeTuple>::type ArgType; \
90 static void impl(FunctionTuple & b, decltype(easing::__EASING_TYPE__ ## In), Fs... fs) { \
91 get<I>(b) = easing::__EASING_TYPE__ ## In.run<ArgType>; \
92 easingresolve<I+1, TypeTuple, FunctionTuple, Fs...>::impl(b, fs...); \
93 } \
94 }; \
95 \
96 template <int I, typename TypeTuple, typename FunctionTuple, typename... Fs> \
97 struct easingresolve<I, TypeTuple, FunctionTuple, easing::__EASING_TYPE__ ## OutEasing, Fs...> { \
98 typedef typename std::tuple_element<I, TypeTuple>::type ArgType; \
99 static void impl(FunctionTuple & b, decltype(easing::__EASING_TYPE__ ## Out), Fs... fs) { \
100 get<I>(b) = easing::__EASING_TYPE__ ## Out.run<ArgType>; \
101 easingresolve<I+1, TypeTuple, FunctionTuple, Fs...>::impl(b, fs...); \
102 } \
103 }; \
104 \
105 template <int I, typename TypeTuple, typename FunctionTuple, typename... Fs> \
106 struct easingresolve<I, TypeTuple, FunctionTuple, easing::__EASING_TYPE__ ## InOutEasing, Fs...> { \
107 typedef typename std::tuple_element<I, TypeTuple>::type ArgType; \
108 static void impl(FunctionTuple & b, decltype(easing::__EASING_TYPE__ ## InOut), Fs... fs) { \
109 get<I>(b) = easing::__EASING_TYPE__ ## InOut.run<ArgType>; \
110 easingresolve<I+1, TypeTuple, FunctionTuple, Fs...>::impl(b, fs...); \
111 } \
112 }
113
114 DECLARE_EASING_RESOLVE(quadratic);
115 DECLARE_EASING_RESOLVE(cubic);
116 DECLARE_EASING_RESOLVE(quartic);
117 DECLARE_EASING_RESOLVE(quintic);
118 DECLARE_EASING_RESOLVE(sinusoidal);
119 DECLARE_EASING_RESOLVE(exponential);
120 DECLARE_EASING_RESOLVE(circular);
121 DECLARE_EASING_RESOLVE(bounce);
122 DECLARE_EASING_RESOLVE(elastic);
123 DECLARE_EASING_RESOLVE(back);
124 }
125}
126
127#endif //TWEENY_EASINGRESOLVE_H
The tweeny namespace contains all symbols and names for the Tweeny library.
Definition: MANUAL.dox:1