1 /* 2 * Copyright (c) 2023 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_COMPONENTS_NG_PATTERNS_PARTICLE_PROPERTY_ANIMATION_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_PARTICLE_PROPERTY_ANIMATION_H 18 #include <string> 19 20 #include "core/animation/curve.h" 21 namespace OHOS::Ace::NG { 22 template<typename T> 23 struct ParticlePropertyAnimation { 24 public: GetFromParticlePropertyAnimation25 T GetFrom() const 26 { 27 return from_; 28 } 29 SetFromParticlePropertyAnimation30 void SetFrom(T& from) 31 { 32 from_ = from; 33 } 34 GetToParticlePropertyAnimation35 T GetTo() const 36 { 37 return to_; 38 } 39 SetToParticlePropertyAnimation40 void SetTo(T& to) 41 { 42 to_ = to; 43 } 44 GetStartMillsParticlePropertyAnimation45 int32_t GetStartMills() const 46 { 47 return startMills_; 48 } 49 SetStartMillsParticlePropertyAnimation50 void SetStartMills(int32_t startMills) 51 { 52 startMills_ = startMills; 53 } 54 GetEndMillsParticlePropertyAnimation55 int32_t GetEndMills() const 56 { 57 return endMills_; 58 } 59 SetEndMillsParticlePropertyAnimation60 void SetEndMills(int32_t endMills) 61 { 62 endMills_ = endMills; 63 } 64 GetCurveParticlePropertyAnimation65 RefPtr<Curve> GetCurve() const 66 { 67 return curve_; 68 } 69 SetCurveParticlePropertyAnimation70 void SetCurve(RefPtr<Curve> curve) 71 { 72 curve_ = curve; 73 } 74 75 bool operator==(const ParticlePropertyAnimation<T>& other) const 76 { 77 bool isCurveEqual = (curve_ && curve_->IsEqual(other.GetCurve())) || (!curve_ && !other.GetCurve()); 78 return NearEqual(from_, other.GetFrom()) && NearEqual(to_, other.GetTo()) && 79 (startMills_ == other.GetStartMills()) && (endMills_ == other.GetEndMills()) && 80 isCurveEqual; 81 } 82 ToStringParticlePropertyAnimation83 std::string ToString() const 84 { 85 std::string str; 86 str.append("startMills: [").append(std::to_string(startMills_)).append("]"); 87 str.append("endMills: [").append(std::to_string(endMills_)).append("]"); 88 str.append("curve: [").append(curve_ ? curve_->ToString() : "NA").append("]"); 89 return str; 90 } 91 92 private: 93 T from_; 94 T to_; 95 int32_t startMills_ = 0; 96 int32_t endMills_ = 0; 97 RefPtr<Curve> curve_; 98 }; 99 } // namespace OHOS::Ace::NG 100 #endif