1 /* 2 * Copyright (c) 2021-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 RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_PATH_ANIMATION_H 17 #define RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_PATH_ANIMATION_H 18 19 #include <string> 20 #include <vector> 21 22 #include "animation/rs_animation_common.h" 23 #include "animation/rs_property_animation.h" 24 #include "animation/rs_animation_timing_curve.h" 25 #include "common/rs_macros.h" 26 #include "common/rs_vector2.h" 27 #include "common/rs_vector4.h" 28 29 namespace OHOS { 30 namespace Rosen { 31 class RSPath; 32 33 class RSC_EXPORT RSPathAnimation : public RSPropertyAnimation { 34 public: 35 RSPathAnimation(std::shared_ptr<RSPropertyBase> property, const std::shared_ptr<RSPath>& animationPath); 36 RSPathAnimation(std::shared_ptr<RSPropertyBase> property, const std::string& path, 37 const std::shared_ptr<RSPropertyBase>& startValue, 38 const std::shared_ptr<RSPropertyBase>& endValue); 39 40 virtual ~RSPathAnimation() = default; 41 42 void SetTimingCurve(const RSAnimationTimingCurve& timingCurve); 43 44 const RSAnimationTimingCurve& GetTimingCurve() const; 45 46 void SetRotationMode(const RotationMode& rotationMode); 47 48 RotationMode GetRotationMode() const; 49 50 void SetBeginFraction(float fraction); 51 52 float GetBeginFraction() const; 53 54 void SetEndFraction(float fraction); 55 56 float GetEndFraction() const; 57 58 void SetPathNeedAddOrigin(bool needAddOrigin); 59 60 bool GetPathNeedAddOrigin() const; 61 IsSupportInteractiveAnimator()62 bool IsSupportInteractiveAnimator() override { return false; } 63 64 protected: 65 void OnStart() override; 66 67 void InitInterpolationValue() override; 68 69 void OnUpdateStagingValue(bool isFirstStart) override; 70 71 void InitRotationId(const std::shared_ptr<RSNode>& node); 72 73 PropertyId GetRotationPropertyId(const std::shared_ptr<RSNode>& node); 74 75 void SetRotation(const std::shared_ptr<RSNode>& node, const float rotation); 76 77 void OnCallFinishCallback() override; 78 SetPropertyOnAllAnimationFinish()79 void SetPropertyOnAllAnimationFinish() override {} 80 81 private: 82 void ReplaceSubString(std::string& sourceStr, const std::string& subStr, const std::string& newStr) const; 83 84 const std::shared_ptr<RSPath> ProcessPath(const std::string& path, const float startX, const float startY, 85 const float endX, const float endY) const; 86 87 const std::shared_ptr<RSPath> PreProcessPath(const std::string& path, 88 const std::shared_ptr<RSPropertyBase>& startValue, 89 const std::shared_ptr<RSPropertyBase>& endValue) const; 90 91 void InitNeedPath(const std::shared_ptr<RSPropertyBase>& startValue, 92 const std::shared_ptr<RSPropertyBase>& endValue); 93 94 bool InitInterpolationVector2f(const std::shared_ptr<RSPropertyBase>& startValue, 95 const std::shared_ptr<RSPropertyBase>& endValue); 96 97 bool InitInterpolationVector4f(const std::shared_ptr<RSPropertyBase>& startValue, 98 const std::shared_ptr<RSPropertyBase>& endValue); 99 100 void UpdateVector2fValueAddOrigin(Vector2f& startValue, Vector2f& endValue, Vector2f& deltaValue); 101 102 void UpdateVector4fValueAddOrigin(Vector4f& startValue, Vector4f& endValue, Vector4f& deltaValue); 103 104 float beginFraction_ { FRACTION_MIN }; 105 float endFraction_ { FRACTION_MAX }; 106 float startTangent_ { 0.0f }; 107 float endTangent_ { 0.0f }; 108 bool isNeedPath_ { true }; 109 bool needAddOrigin_ { true }; 110 PropertyId rotationId_ {}; 111 RotationMode rotationMode_ { RotationMode::ROTATE_NONE }; 112 RSAnimationTimingCurve timingCurve_ { RSAnimationTimingCurve::DEFAULT }; 113 std::shared_ptr<RSPath> animationPath_; 114 }; 115 } // namespace Rosen 116 } // namespace OHOS 117 118 #endif // RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_PATH_ANIMATION_H 119