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 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_motion_path_option.h" 24 #include "animation/rs_property_animation.h" 25 #include "common/rs_macros.h" 26 27 namespace OHOS { 28 namespace Rosen { 29 class RS_EXPORT RSPathAnimation : public RSPropertyAnimation<Vector2f> { 30 public: 31 RSPathAnimation(const RSAnimatableProperty& property, const std::shared_ptr<RSPath>& animationPath); 32 RSPathAnimation(const RSAnimatableProperty& property, const std::string& path, const Vector2f& startValue, 33 const Vector2f& endValue); 34 35 virtual ~RSPathAnimation() = default; 36 37 void SetTimingCurve(const RSAnimationTimingCurve& timingCurve); 38 39 const RSAnimationTimingCurve& GetTimingCurve() const; 40 41 void SetRotationMode(const RotationMode& rotationMode); 42 43 RotationMode GetRotationMode() const; 44 45 void SetBeginFraction(float fraction); 46 47 float GetBeginFraction() const; 48 49 void SetEndFraction(float fraction); 50 51 float GetEndFraction() const; 52 53 static bool IsAnimatablePathProperty(const RSAnimatableProperty& property); 54 55 protected: 56 void OnStart() override; 57 58 void InitInterpolationValue() override; 59 60 void OnUpdateStagingValue(bool isFirstStart) override; 61 62 private: 63 void ReplaceSubString(std::string& sourceStr, const std::string& subStr, const std::string& newStr) const; 64 65 const std::shared_ptr<RSPath> PreProcessPath( 66 const std::string& path, const Vector2f& startValue, const Vector2f& endValue) const; 67 68 const static std::vector<RSAnimatableProperty> PROP_FOR_PATH_ANIM; 69 70 float beginFraction_ { FRACTION_MIN }; 71 float endFraction_ { FRACTION_MAX }; 72 float startTangent_ { 0.0f }; 73 float endTangent_ { 0.0f }; 74 RotationMode rotationMode_ { RotationMode::ROTATE_NONE }; 75 RSAnimationTimingCurve timingCurve_ { RSAnimationTimingCurve::DEFAULT }; 76 std::shared_ptr<RSPath> animationPath_; 77 }; 78 } // namespace Rosen 79 } // namespace OHOS 80 81 #endif // RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_PATH_ANIMATION_H 82