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