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