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_COMPONENTS_NG_PROPERTIES_ANIMATABLE_ARITHMETIC_PROXY_H 17 #define FOUNDATION_ACE_FRAMEWORKS_COMPONENTS_NG_PROPERTIES_ANIMATABLE_ARITHMETIC_PROXY_H 18 19 #include "core/components_ng/animation/animatable_arithmetic.h" 20 21 namespace OHOS::Ace::NG { 22 class AnimatableArithmeticProxy : public AnimatableArithmetic<AnimatableArithmeticProxy> { 23 public: 24 AnimatableArithmeticProxy() = default; AnimatableArithmeticProxy(RefPtr<CustomAnimatableArithmetic> object)25 explicit AnimatableArithmeticProxy(RefPtr<CustomAnimatableArithmetic> object) : object_(object) 26 { 27 if (!object_) { 28 LOGD("object provided is null"); 29 } 30 } 31 virtual ~AnimatableArithmeticProxy() = default; 32 Add(const AnimatableArithmeticProxy & val)33 AnimatableArithmeticProxy Add(const AnimatableArithmeticProxy& val) const override 34 { 35 if (!object_) { 36 return {}; 37 } 38 if (!val.object_) { 39 return {}; 40 } 41 42 return AnimatableArithmeticProxy(object_->Add(val.object_)); 43 } 44 Minus(const AnimatableArithmeticProxy & val)45 AnimatableArithmeticProxy Minus(const AnimatableArithmeticProxy& val) const override 46 { 47 if (!object_) { 48 return {}; 49 } 50 if (!val.object_) { 51 return {}; 52 } 53 return AnimatableArithmeticProxy(object_->Minus(val.object_)); 54 } 55 Multiply(const float scale)56 AnimatableArithmeticProxy Multiply(const float scale) const override 57 { 58 if (!object_) { 59 return {}; 60 } 61 return AnimatableArithmeticProxy(object_->Multiply(scale)); 62 } 63 IsEqual(const AnimatableArithmeticProxy & val)64 bool IsEqual(const AnimatableArithmeticProxy& val) const override 65 { 66 if (!object_) { 67 return {}; 68 } 69 if (!val.object_) { 70 return {}; 71 } 72 return object_->IsEqual(val.object_); 73 } 74 GetObject()75 RefPtr<CustomAnimatableArithmetic> GetObject() const 76 { 77 return object_; 78 } 79 80 private: 81 RefPtr<CustomAnimatableArithmetic> object_; 82 }; 83 } // namespace OHOS::Ace::NG 84 85 #endif // FOUNDATION_ACE_FRAMEWORKS_COMPONENTS_NG_PROPERTIES_ANIMATABLE_ARITHMETIC_PROXY_H 86