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/curves.h"
17 
18 #include <map>
19 
20 namespace OHOS::Ace {
21 
22 const RefPtr<DecelerationCurve> Curves::DECELE = AceType::MakeRefPtr<DecelerationCurve>();
23 const RefPtr<LinearCurve> Curves::LINEAR = AceType::MakeRefPtr<LinearCurve>();
24 const RefPtr<SineCurve> Curves::SINE = AceType::MakeRefPtr<SineCurve>();
25 const RefPtr<CubicCurve> Curves::EASE = AceType::MakeRefPtr<CubicCurve>(0.25f, 0.1f, 0.25f, 1.0f);
26 const RefPtr<CubicCurve> Curves::EASE_IN = AceType::MakeRefPtr<CubicCurve>(0.42f, 0.0f, 1.0f, 1.0f);
27 const RefPtr<CubicCurve> Curves::EASE_OUT = AceType::MakeRefPtr<CubicCurve>(0.0f, 0.0f, 0.58f, 1.0f);
28 const RefPtr<CubicCurve> Curves::EASE_IN_OUT = AceType::MakeRefPtr<CubicCurve>(0.42f, 0.0f, 0.58f, 1.0f);
29 const RefPtr<CubicCurve> Curves::FAST_OUT_SLOW_IN = AceType::MakeRefPtr<CubicCurve>(0.4f, 0.0f, 0.2f, 1.0f);
30 const RefPtr<CubicCurve> Curves::LINEAR_OUT_SLOW_IN = AceType::MakeRefPtr<CubicCurve>(0.0f, 0.0f, 0.2f, 1.0f);
31 const RefPtr<CubicCurve> Curves::FAST_OUT_LINEAR_IN = AceType::MakeRefPtr<CubicCurve>(0.4f, 0.0f, 1.0f, 1.0f);
32 const RefPtr<CubicCurve> Curves::FRICTION = AceType::MakeRefPtr<CubicCurve>(0.2f, 0.0f, 0.2f, 1.0f);
33 const RefPtr<CubicCurve> Curves::EXTREME_DECELERATION = AceType::MakeRefPtr<CubicCurve>(0.0f, 0.0f, 0.0f, 1.0f);
34 const RefPtr<CubicCurve> Curves::SHARP = AceType::MakeRefPtr<CubicCurve>(0.33f, 0.0f, 0.67f, 1.0f);
35 const RefPtr<CubicCurve> Curves::RHYTHM = AceType::MakeRefPtr<CubicCurve>(0.7f, 0.0f, 0.2f, 1.0f);
36 const RefPtr<CubicCurve> Curves::SMOOTH = AceType::MakeRefPtr<CubicCurve>(0.4f, 0.0f, 0.4f, 1.0f);
37 const RefPtr<AnticipateCurve> Curves::ANTICIPATE = AceType::MakeRefPtr<AnticipateCurve>(2.0f);
38 const RefPtr<CubicCurve> Curves::MAGNETIC = AceType::MakeRefPtr<CubicCurve>(0.8f, 0.0f, 1.0f, 0.6f);
39 const RefPtr<ElasticsCurve> Curves::ELASTICS = AceType::MakeRefPtr<ElasticsCurve>(2.0f);
40 const std::string Curves::DEFAULT_CURVE_NAME = "Curves.Ease";
41 
ToString(const RefPtr<Curve> & curve)42 std::string Curves::ToString(const RefPtr<Curve>& curve)
43 {
44     static const std::map<RefPtr<Curve>, std::string> curveNames = { { Curves::EASE, Curves::DEFAULT_CURVE_NAME },
45         { Curves::EASE_IN, "Curves.EaseIn" }, { Curves::EASE_OUT, "Curves.EaseOut" },
46         { Curves::EASE_IN_OUT, "Curves.EaseInOut" }, { Curves::FAST_OUT_SLOW_IN, "Curves.FastOutSlowIn" },
47         { Curves::LINEAR_OUT_SLOW_IN, "Curves.LinearOutSlowIn" },
48         { Curves::FAST_OUT_LINEAR_IN, "Curves.FastOutLinearIn" }, { Curves::FRICTION, "Curves.Friction" },
49         { Curves::EXTREME_DECELERATION, "Curves.ExtremeDeceleration" }, { Curves::SHARP, "Curves.Sharp" },
50         { Curves::SMOOTH, "Curves.Smooth" }, { Curves::LINEAR, "Curves.Linear" } };
51     auto iter = curveNames.find(curve);
52     if (iter != curveNames.end()) {
53         return iter->second;
54     }
55     return Curves::DEFAULT_CURVE_NAME;
56 }
57 
58 } // namespace OHOS::Ace
59