• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 #ifndef META_EXT_INTERPOLATOR_H
18 #define META_EXT_INTERPOLATOR_H
19 
20 #include <meta/api/util.h>
21 #include <meta/base/namespace.h>
22 #include <meta/ext/base_object.h>
23 #include <meta/interface/animation/intf_interpolator.h>
24 
META_BEGIN_NAMESPACE()25 META_BEGIN_NAMESPACE()
26 
27 /**
28  * @brief A default implementation template for an interpolator for a given type.
29  */
30 template<class Type>
31 class Interpolator : public IntroduceInterfaces<BaseObject, IInterpolator> {
32 public:
33     AnyReturnValue Interpolate(IAny& output, const IAny& from, const IAny& to, float t) const override
34     {
35         if (IsGetCompatibleWith<Type>(output) && IsGetCompatibleWith<Type>(from) && IsGetCompatibleWith<Type>(to)) {
36             Type value0 = GetValue<Type>(from);
37             Type value1 = GetValue<Type>(to);
38             return output.SetValue<Type>(value0 + (value1 - value0) * t);
39         }
40         return AnyReturn::INCOMPATIBLE_TYPE;
41     }
42     bool IsCompatibleWith(TypeId id) const noexcept override
43     {
44         return id == UidFromType<Type>();
45     }
46 };
47 
48 META_END_NAMESPACE()
49 
50 #endif
51