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 #include "animation/rs_implicit_animation_param.h"
17
18 #include "animation/rs_transition.h"
19 #include "platform/common/rs_log.h"
20
21 namespace OHOS {
22 namespace Rosen {
RSImplicitAnimationParam(const RSAnimationTimingProtocol & timingProtocol)23 RSImplicitAnimationParam::RSImplicitAnimationParam(const RSAnimationTimingProtocol& timingProtocol)
24 : timingProtocol_(timingProtocol)
25 {}
26
GetType() const27 ImplicitAnimationParamType RSImplicitAnimationParam::GetType() const
28 {
29 return animationType_;
30 }
31
ApplyTimingProtocol(const std::shared_ptr<RSAnimation> & animation) const32 void RSImplicitAnimationParam::ApplyTimingProtocol(const std::shared_ptr<RSAnimation>& animation) const
33 {
34 animation->SetDuration(timingProtocol_.GetDuration());
35 animation->SetStartDelay(timingProtocol_.GetStartDelay());
36 animation->SetSpeed(timingProtocol_.GetSpeed());
37 animation->SetDirection(timingProtocol_.GetDirection());
38 animation->SetAutoReverse(timingProtocol_.GetAutoReverse());
39 animation->SetRepeatCount(timingProtocol_.GetRepeatCount());
40 animation->SetFillMode(timingProtocol_.GetFillMode());
41 }
42
RSImplicitCurveAnimationParam(const RSAnimationTimingProtocol & timingProtocol,const RSAnimationTimingCurve & timingCurve)43 RSImplicitCurveAnimationParam::RSImplicitCurveAnimationParam(
44 const RSAnimationTimingProtocol& timingProtocol, const RSAnimationTimingCurve& timingCurve)
45 : RSImplicitAnimationParam(timingProtocol), timingCurve_(timingCurve)
46 {
47 animationType_ = ImplicitAnimationParamType::CURVE;
48 }
49
RSImplicitKeyframeAnimationParam(const RSAnimationTimingProtocol & timingProtocol,const RSAnimationTimingCurve & timingCurve,float fraction)50 RSImplicitKeyframeAnimationParam::RSImplicitKeyframeAnimationParam(
51 const RSAnimationTimingProtocol& timingProtocol, const RSAnimationTimingCurve& timingCurve, float fraction)
52 : RSImplicitAnimationParam(timingProtocol), timingCurve_(timingCurve), fraction_(fraction)
53 {
54 animationType_ = ImplicitAnimationParamType::KEYFRAME;
55 }
56
RSImplicitPathAnimationParam(const RSAnimationTimingProtocol & timingProtocol,const RSAnimationTimingCurve & timingCurve,const std::shared_ptr<RSMotionPathOption> & motionPathOption)57 RSImplicitPathAnimationParam::RSImplicitPathAnimationParam(const RSAnimationTimingProtocol& timingProtocol,
58 const RSAnimationTimingCurve& timingCurve, const std::shared_ptr<RSMotionPathOption>& motionPathOption)
59 : RSImplicitAnimationParam(timingProtocol), timingCurve_(timingCurve), motionPathOption_(motionPathOption)
60 {
61 animationType_ = ImplicitAnimationParamType::PATH;
62 }
63
CreateAnimation(const RSAnimatableProperty & property,const Vector2f & startValue,const Vector2f & endValue) const64 std::shared_ptr<RSAnimation> RSImplicitPathAnimationParam::CreateAnimation(
65 const RSAnimatableProperty& property, const Vector2f& startValue, const Vector2f& endValue) const
66 {
67 if (motionPathOption_ == nullptr) {
68 ROSEN_LOGE("Failed to create path animation, motion path option is null!");
69 return nullptr;
70 }
71
72 auto pathAnimation =
73 std::make_shared<RSPathAnimation>(property, motionPathOption_->GetPath(), startValue, endValue);
74 pathAnimation->SetBeginFraction(motionPathOption_->GetBeginFraction());
75 pathAnimation->SetEndFraction(motionPathOption_->GetEndFraction());
76 pathAnimation->SetRotationMode(motionPathOption_->GetRotationMode());
77 pathAnimation->SetTimingCurve(timingCurve_);
78 ApplyTimingProtocol(pathAnimation);
79 return pathAnimation;
80 }
81
RSImplicitTransitionParam(const RSAnimationTimingProtocol & timingProtocol,const RSAnimationTimingCurve & timingCurve,const std::shared_ptr<const RSTransitionEffect> & effect)82 RSImplicitTransitionParam::RSImplicitTransitionParam(const RSAnimationTimingProtocol& timingProtocol,
83 const RSAnimationTimingCurve& timingCurve, const std::shared_ptr<const RSTransitionEffect>& effect)
84 : RSImplicitAnimationParam(timingProtocol), timingCurve_(timingCurve), effect_(effect)
85 {
86 animationType_ = ImplicitAnimationParamType::TRANSITION;
87 }
88
CreateAnimation(bool appearing)89 std::shared_ptr<RSAnimation> RSImplicitTransitionParam::CreateAnimation(bool appearing)
90 {
91 auto transition = std::make_shared<RSTransition>(effect_, appearing);
92 transition->SetTimingCurve(timingCurve_);
93 ApplyTimingProtocol(transition);
94 return transition;
95 }
96 } // namespace Rosen
97 } // namespace OHOS
98