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 62 protected: 63 void OnStart() override; 64 65 void InitInterpolationValue() override; 66 67 void OnUpdateStagingValue(bool isFirstStart) override; 68 69 void InitRotationId(const std::shared_ptr<RSNode>& node); 70 71 PropertyId GetRotationPropertyId(const std::shared_ptr<RSNode>& node); 72 73 void SetRotation(const std::shared_ptr<RSNode>& node, const float rotation); 74 75 void OnCallFinishCallback() override; 76 SetPropertyOnAllAnimationFinish()77 void SetPropertyOnAllAnimationFinish() override {} 78 79 private: 80 void ReplaceSubString(std::string& sourceStr, const std::string& subStr, const std::string& newStr) const; 81 82 const std::shared_ptr<RSPath> ProcessPath(const std::string& path, const float startX, const float startY, 83 const float endX, const float endY) const; 84 85 const std::shared_ptr<RSPath> PreProcessPath(const std::string& path, 86 const std::shared_ptr<RSPropertyBase>& startValue, 87 const std::shared_ptr<RSPropertyBase>& endValue) const; 88 89 void InitNeedPath(const std::shared_ptr<RSPropertyBase>& startValue, 90 const std::shared_ptr<RSPropertyBase>& endValue); 91 92 bool InitInterpolationVector2f(const std::shared_ptr<RSPropertyBase>& startValue, 93 const std::shared_ptr<RSPropertyBase>& endValue); 94 95 bool InitInterpolationVector4f(const std::shared_ptr<RSPropertyBase>& startValue, 96 const std::shared_ptr<RSPropertyBase>& endValue); 97 98 void UpdateVector2fValueAddOrigin(Vector2f& startValue, Vector2f& endValue, Vector2f& deltaValue); 99 100 void UpdateVector4fValueAddOrigin(Vector4f& startValue, Vector4f& endValue, Vector4f& deltaValue); 101 102 float beginFraction_ { FRACTION_MIN }; 103 float endFraction_ { FRACTION_MAX }; 104 float startTangent_ { 0.0f }; 105 float endTangent_ { 0.0f }; 106 bool isNeedPath_ { true }; 107 bool needAddOrigin_ { true }; 108 PropertyId rotationId_; 109 RotationMode rotationMode_ { RotationMode::ROTATE_NONE }; 110 RSAnimationTimingCurve timingCurve_ { RSAnimationTimingCurve::DEFAULT }; 111 std::shared_ptr<RSPath> animationPath_; 112 }; 113 } // namespace Rosen 114 } // namespace OHOS 115 116 #endif // RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_PATH_ANIMATION_H 117