1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #ifndef META_API_CURVES_H
17 #define META_API_CURVES_H
18
19 #include <meta/api/object.h>
20 #include <meta/interface/animation/builtin_animations.h>
21 #include <meta/interface/curves/intf_bezier.h>
22 #include <meta/interface/curves/intf_easing_curve.h>
23
META_BEGIN_NAMESPACE()24 META_BEGIN_NAMESPACE()
25
26 /**
27 * @brief Wrapper class for objects which implement IEasingCurve.
28 */
29 class EasingCurve : public Object {
30 public:
31 META_INTERFACE_OBJECT(EasingCurve, Object, IEasingCurve)
32 operator ICurve1D::Ptr() const noexcept
33 {
34 return GetPtr<ICurve1D>();
35 }
36 /// @see IEasingCurve::Transform
37 auto Transform(float t) const
38 {
39 return META_INTERFACE_OBJECT_CALL_PTR(Transform(t));
40 }
41 };
42
43 namespace Curves {
44
45 #define META_EASING_CURVE_INTERFACE_OBJECT(Class) \
46 class Class : public EasingCurve { \
47 public: \
48 Class(const IInterfacePtr& ptr) : EasingCurve(ptr) \
49 {} \
50 Class(const ::META_NS::InitializationType& t) \
51 : EasingCurve(::META_NS::CreateObjectInstance(ClassId::Class##EasingCurve)) \
52 {} \
53 };
54
55 /// Linear easing curve
56 META_EASING_CURVE_INTERFACE_OBJECT(Linear)
57 /// InQuad easing curve
META_EASING_CURVE_INTERFACE_OBJECT(InQuad)58 META_EASING_CURVE_INTERFACE_OBJECT(InQuad)
59 /// OutQuad easing curve
60 META_EASING_CURVE_INTERFACE_OBJECT(OutQuad)
61 /// InOutQuad easing curve
62 META_EASING_CURVE_INTERFACE_OBJECT(InOutQuad)
63 /// InCubic easing curve
64 META_EASING_CURVE_INTERFACE_OBJECT(InCubic)
65 /// OutCubic easing curve
66 META_EASING_CURVE_INTERFACE_OBJECT(OutCubic)
67 /// InOutCubic easing curve
68 META_EASING_CURVE_INTERFACE_OBJECT(InOutCubic)
69 /// InSine easing curve
70 META_EASING_CURVE_INTERFACE_OBJECT(InSine)
71 /// OutSine easing curve
72 META_EASING_CURVE_INTERFACE_OBJECT(OutSine)
73 /// InOutSine easing curve
74 META_EASING_CURVE_INTERFACE_OBJECT(InOutSine)
75 /// InQuart easing curve
76 META_EASING_CURVE_INTERFACE_OBJECT(InQuart)
77 /// OutQuart easing curve
78 META_EASING_CURVE_INTERFACE_OBJECT(OutQuart)
79 /// InOutQuart easing curve
80 META_EASING_CURVE_INTERFACE_OBJECT(InOutQuart)
81 /// InQuint easing curve
82 META_EASING_CURVE_INTERFACE_OBJECT(InQuint)
83 /// OutQuint easing curve
84 META_EASING_CURVE_INTERFACE_OBJECT(OutQuint)
85 /// InOutQuint easing curve
86 META_EASING_CURVE_INTERFACE_OBJECT(InOutQuint)
87 /// InExpo easing curve
88 META_EASING_CURVE_INTERFACE_OBJECT(InExpo)
89 /// OutExpo easing curve
90 META_EASING_CURVE_INTERFACE_OBJECT(OutExpo)
91 /// InOutExpo easing curve
92 META_EASING_CURVE_INTERFACE_OBJECT(InOutExpo)
93 /// InCirc easing curve
94 META_EASING_CURVE_INTERFACE_OBJECT(InCirc)
95 /// OutCirc easing curve
96 META_EASING_CURVE_INTERFACE_OBJECT(OutCirc)
97 /// InOutCirc easing curve
98 META_EASING_CURVE_INTERFACE_OBJECT(InOutCirc)
99 /// InBack easing curve
100 META_EASING_CURVE_INTERFACE_OBJECT(InBack)
101 /// OutBack easing curve
102 META_EASING_CURVE_INTERFACE_OBJECT(OutBack)
103 /// InOutBack easing curve
104 META_EASING_CURVE_INTERFACE_OBJECT(InOutBack)
105 /// InElastic easing curve
106 META_EASING_CURVE_INTERFACE_OBJECT(InElastic)
107 /// OutElastic easing curve
108 META_EASING_CURVE_INTERFACE_OBJECT(OutElastic)
109 /// InOutElastic easing curve
110 META_EASING_CURVE_INTERFACE_OBJECT(InOutElastic)
111 /// InBounce easing curve
112 META_EASING_CURVE_INTERFACE_OBJECT(InBounce)
113 /// OutBounce easing curve
114 META_EASING_CURVE_INTERFACE_OBJECT(OutBounce)
115 /// InOutBounce easing curve
116 META_EASING_CURVE_INTERFACE_OBJECT(InOutBounce)
117 /// StepStart easing curve
118 META_EASING_CURVE_INTERFACE_OBJECT(StepStart)
119 /// StepEnd easing curve
120 META_EASING_CURVE_INTERFACE_OBJECT(StepEnd)
121
122 /**
123 * @brief Wrapper class for objects which implement ICubicBezier.
124 */
125 class CubicBezier : public EasingCurve {
126 public:
127 META_INTERFACE_OBJECT(CubicBezier, EasingCurve, ICubicBezier)
128 META_INTERFACE_OBJECT_INSTANTIATE(CubicBezier, ClassId::CubicBezierEasingCurve)
129 /// @see ICubicBezier::ControlPoint1
130 META_INTERFACE_OBJECT_PROPERTY(BASE_NS::Math::Vec2, ControlPoint1)
131 /// @see ICubicBezier::ControlPoint1
132 META_INTERFACE_OBJECT_PROPERTY(BASE_NS::Math::Vec2, ControlPoint2)
133 };
134
135 } // namespace Curves
136
137 /// Return a default object which implements ICubicBezier
138 template<>
139 inline auto CreateObjectInstance<ICubicBezier>()
140 {
141 return Curves::CubicBezier(CreateNew);
142 }
143
144 /// Return a default object which implements ICubicBezier.
145 template<>
146 inline auto CreateObjectInstance<IEasingCurve>()
147 {
148 // By default return an InOutCubic easing curve for IEasingCurve
149 return Curves::InOutCubic(CreateNew);
150 }
151
152 META_END_NAMESPACE()
153
154 #endif // META_API_CURVES_H
155