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_SIMPLE_SPRING_NODE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_ANIMATION_SIMPLE_SPRING_NODE_H 18 19 #include "core/animation/scheduler.h" 20 #include "core/animation/spring_motion.h" 21 #include "core/animation/spring_node.h" 22 #include "core/pipeline/pipeline_context.h" 23 24 namespace OHOS::Ace { 25 26 class SimpleSpringNode : public SpringNode { 27 DECLARE_ACE_TYPE(SimpleSpringNode, SpringNode); 28 29 public: 30 SimpleSpringNode(const WeakPtr<PipelineBase>& context, int32_t index, double value); 31 ~SimpleSpringNode() override = default; 32 33 void EndToValue(double endValue, double velocity) override; 34 35 void TransferParams(double stiffness, double damping) override; 36 GetValue()37 double GetValue() const override 38 { 39 return value_; 40 } 41 42 void SetValue(double value) override; 43 SetDeltaValue(double delta)44 void SetDeltaValue(double delta) override 45 { 46 value_ += delta; 47 } 48 49 void ResetNode(double value, double velocity) override; 50 GetVelocity()51 double GetVelocity() const override 52 { 53 return velocity_; 54 } 55 SetVelocity(double velocity)56 void SetVelocity(double velocity) 57 { 58 velocity_ = velocity; 59 } 60 GetTransferParams()61 const RefPtr<SpringProperty> GetTransferParams() const 62 { 63 return springProperty_; 64 } 65 66 void OnAnimation() override; 67 68 protected: 69 static constexpr double DEFAULT_CHAIN_VALUE_ACCURACY = 1.0; 70 virtual void NotifyNext(double endValue, double initVelocity); 71 RefPtr<SpringMotion> spring_; 72 RefPtr<SpringProperty> springProperty_; 73 RefPtr<Scheduler> scheduler_; 74 const WeakPtr<PipelineBase> context_; 75 double value_ = 0.0; 76 double velocity_ = 0.0; 77 double valueAccuracy_ = DEFAULT_CHAIN_VALUE_ACCURACY; 78 79 void Cancel() override; 80 }; 81 82 } // namespace OHOS::Ace 83 84 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_ANIMATION_SIMPLE_SPRING_NODE_H 85