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 45 private: 46 void SetEndPosition(float endPosition, float startVelocity); 47 void InitEstimateDuration(); 48 49 float estimateDuration_ = 1.0f; 50 float startPosition_ = 0.0f; 51 float endPosition_ = 0.0f; 52 float currentVelocity_ = 0.0f; 53 float currentPosition_ = 0.0f; 54 float velocityThreshold_ = 0.001f; 55 float valueThreshold_ = 0.001f; 56 float velocity_ = 0.0f; 57 float mass_ = 0.0f; 58 float stiffness_ = 0.0f; 59 float damping_ = 0.0f; 60 RefPtr<SpringProperty> property_; // Contain: mass & stiffness & damping 61 RefPtr<SpringModel> solution_; // Maybe: CriticalDamped or Overdamped or Underdamped 62 63 friend class NativeCurveHelper; 64 }; 65 66 } // namespace OHOS::Ace 67 68 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_ANIMATION_SPRING_CURVE_H