1 /* 2 * Copyright (c) 2021-2022 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_SPRING_CURVE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_ANIMATION_SPRING_CURVE_H 18 19 #include "core/animation/curve.h" 20 #include "core/animation/spring_motion.h" 21 22 namespace OHOS::Ace { 23 24 class ACE_EXPORT SpringCurve : public Curve { 25 DECLARE_ACE_TYPE(SpringCurve, Curve); 26 27 public: 28 SpringCurve(float velocity, float mass, float stiffness, float damping); 29 ~SpringCurve() override = default; 30 31 float MoveInternal(float time) override; 32 const std::string ToString() override; 33 UpdateVelocity(float velocity)34 void UpdateVelocity(float velocity) 35 { 36 velocity_ = velocity; 37 SetEndPosition(1.0f, velocity_); 38 } 39 GetCurrentVelocity()40 float GetCurrentVelocity() const 41 { 42 return velocity_; 43 } 44 GetMass()45 float GetMass() const 46 { 47 return mass_; 48 } 49 GetStiffness()50 float GetStiffness() const 51 { 52 return stiffness_; 53 } 54 GetDamping()55 float GetDamping() const 56 { 57 return damping_; 58 } 59 60 private: 61 void SetEndPosition(float endPosition, float startVelocity); 62 void InitEstimateDuration(); 63 64 float estimateDuration_ = 1.0f; 65 float startPosition_ = 0.0f; 66 float endPosition_ = 0.0f; 67 float currentVelocity_ = 0.0f; 68 float currentPosition_ = 0.0f; 69 float velocityThreshold_ = 0.001f; 70 float valueThreshold_ = 0.001f; 71 float velocity_ = 0.0f; 72 float mass_ = 0.0f; 73 float stiffness_ = 0.0f; 74 float damping_ = 0.0f; 75 RefPtr<SpringProperty> property_; // Contain: mass & stiffness & damping 76 RefPtr<SpringModel> solution_; // Maybe: CriticalDamped or Overdamped or Underdamped 77 78 friend class NativeCurveHelper; 79 }; 80 81 } // namespace OHOS::Ace 82 83 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_ANIMATION_SPRING_CURVE_H