OSSIA
Open Scenario System for Interactive Application
Loading...
Searching...
No Matches
easing_helpers.hpp
1#pragma once
2#include <ossia/detail/typelist.hpp>
4
5#include <boost/mp11/algorithm.hpp>
6#include <boost/mp11/list.hpp>
7namespace ossia
8{
9// clang-format off
10namespace easing {
11using list = ossia::tl<
12 linear,
13 quadraticIn, quadraticOut, quadraticInOut,
14 cubicIn, cubicOut, cubicInOut,
15 quarticIn, quarticOut, quarticInOut,
16 quinticIn, quinticOut, quinticInOut,
17 sineIn, sineOut, sineInOut,
18 circularIn, circularOut, circularInOut,
19 exponentialIn, exponentialOut, exponentialInOut,
20 elasticIn, elasticOut, elasticInOut,
21 backIn, backOut, backInOut,
22 bounceIn, bounceOut, bounceInOut,
23 perlinInOut
24>;
25
26constexpr void for_each(auto&& func) {
27 func.template operator()<
28 linear,
29 quadraticIn, quadraticOut, quadraticInOut,
30 cubicIn, cubicOut, cubicInOut,
31 quarticIn, quarticOut, quarticInOut,
32 quinticIn, quinticOut, quinticInOut,
33 sineIn, sineOut, sineInOut,
34 circularIn, circularOut, circularInOut,
35 exponentialIn, exponentialOut, exponentialInOut,
36 elasticIn, elasticOut, elasticInOut,
37 backIn, backOut, backInOut,
38 bounceIn, bounceOut, bounceInOut,
39 perlinInOut
40 >();
41}
42}
43// clang-format on
44
45template <typename Easing, typename Y>
46constexpr auto make_easing(Y start, Y end) noexcept
47{
48 return [start, end](Y ratio) constexpr noexcept {
49 return easing::ease{}(start, end, Easing{}(ratio));
50 };
51}
52
53template <typename Y>
54constexpr void make_easing(auto& res, std::string_view easing, Y start, Y end) noexcept
55{
56 auto apply_if_easing = [&res, easing, start, end]<typename Easing>() noexcept {
57 constexpr auto name = Easing::name();
58 if(name == easing)
59 {
60 res = make_easing<Easing, Y>(start, end);
61 return true;
62 }
63 return false;
64 };
65 easing::for_each([apply_if_easing]<typename... Easings>() {
66 (apply_if_easing.template operator()<Easings>() || ...);
67 });
68}
69
70template <typename Y>
71constexpr void make_easing(auto& res, std::string_view easing) noexcept
72{
73 auto apply_if_easing = [&res, easing]<typename Easing>() noexcept {
74 constexpr auto name = Easing::name();
75 if(name == easing)
76 {
77 res = Easing{};
78 return true;
79 }
80 return false;
81 };
82 easing::for_each([apply_if_easing]<typename... Easings>() {
83 (apply_if_easing.template operator()<Easings>() || ...);
84 });
85}
86}
Definition git_info.h:7