• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "core/animation/native_curve_helper.h"
17 
18 #include "core/animation/cubic_curve.h"
19 #include "core/animation/spring_curve.h"
20 
21 namespace OHOS::Ace {
22 
ToNativeCurve(const RefPtr<Curve> & curve)23 Rosen::RSAnimationTimingCurve NativeCurveHelper::ToNativeCurve(const RefPtr<Curve>& curve)
24 {
25     if (AceType::InstanceOf<LinearCurve>(curve)) {
26         return Rosen::RSAnimationTimingCurve::LINEAR;
27     } else if (auto cubicCurve = AceType::DynamicCast<CubicCurve>(curve)) {
28         return Rosen::RSAnimationTimingCurve::CreateCubicCurve(
29             cubicCurve->x0_, cubicCurve->y0_, cubicCurve->x1_, cubicCurve->y1_);
30     } else if (auto springCurve = AceType::DynamicCast<SpringCurve>(curve)) {
31         return Rosen::RSAnimationTimingCurve::CreateSpringCurve(springCurve->velocity_, springCurve->mass_,
32             springCurve->stiffness_, springCurve->damping_);
33     } else if (auto customCurve = AceType::DynamicCast<CustomCurve>(curve)) {
34         return Rosen::RSAnimationTimingCurve::CreateCustomCurve(customCurve->interpolateFunc_);
35     } else {
36         return Rosen::RSAnimationTimingCurve::CreateCustomCurve(
37             [weak = WeakPtr<Curve>(curve)](float fraction) -> float {
38                 auto curve = weak.Upgrade();
39                 if (curve == nullptr) {
40                     LOGE("transform to native curve failed, curve is null!");
41                     return 1.0f;
42                 }
43 
44                 return curve->MoveInternal(fraction);
45             });
46     }
47 }
48 
ToNativeMotionPathOption(const MotionPathOption & option)49 Rosen::RSMotionPathOption NativeCurveHelper::ToNativeMotionPathOption(const MotionPathOption& option)
50 {
51     auto motionOption = Rosen::RSMotionPathOption(option.GetPath());
52     motionOption.SetBeginFraction(option.GetBegin());
53     motionOption.SetEndFraction(option.GetEnd());
54     motionOption.SetRotationMode(
55         option.GetRotate() ? Rosen::RotationMode::ROTATE_AUTO : Rosen::RotationMode::ROTATE_NONE);
56     return motionOption;
57 }
58 
59 } // namespace OHOS::Ace
60