1 /* 2 * Copyright (c) 2021 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 FOUNDATION_ACE_FRAMEWORKS_CORE_ANIMATION_ANIMATABLE_DATA_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_ANIMATION_ANIMATABLE_DATA_H 18 19 #include "base/geometry/dimension.h" 20 #include "core/animation/animatable.h" 21 #include "core/components/common/properties/color.h" 22 #include "core/components/common/properties/decoration.h" 23 #include "core/components/common/properties/shadow.h" 24 25 namespace OHOS::Ace { 26 27 template<typename T> 28 class AnimatableData : public Animatable { 29 DECLARE_ACE_TYPE(AnimatableData, Animatable); 30 31 public: Blend(const T & start,const T & end,float process)32 static T Blend(const T& start, const T& end, float process) 33 { 34 return start + (end - start) * process; 35 } 36 37 // do not add explicit for this constructor. AnimatableData(const T & value)38 explicit AnimatableData(const T& value) : value_(value) {} 39 ~AnimatableData() = default; 40 Animate(const T & start,const T & end,float process)41 virtual T Animate(const T& start, const T& end, float process) 42 { 43 return Blend(start, end, process); 44 } 45 GetValue()46 const T& GetValue() const 47 { 48 return value_; 49 } 50 SetValue(const T & value)51 void SetValue(const T& value) 52 { 53 value_ = value; 54 } 55 56 protected: 57 T value_; 58 }; 59 60 template<> 61 BorderStyle AnimatableData<BorderStyle>::Blend(const BorderStyle& start, const BorderStyle& end, float process); 62 63 template<> 64 Shadow AnimatableData<Shadow>::Blend(const Shadow& start, const Shadow& end, float process); 65 66 template<> 67 BackgroundImageSize AnimatableData<BackgroundImageSize>::Blend( 68 const BackgroundImageSize& start, const BackgroundImageSize& end, float process); 69 70 template<> 71 Dimension AnimatableData<Dimension>::Blend(const Dimension& start, const Dimension& end, float process); 72 73 template<> 74 Color AnimatableData<Color>::Blend(const Color& start, const Color& end, float process); 75 76 } // namespace OHOS::Ace 77 78 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_ANIMATION_ANIMATABLE_DATA_H