1 /*
2  * Copyright (c) 2024 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 OHOS_ACE_FRAMEWORK_CJ_TRANSITIONEFFECT_H
17 #define OHOS_ACE_FRAMEWORK_CJ_TRANSITIONEFFECT_H
18 
19 #include <cstdint>
20 #include <string>
21 
22 #include "ffi_remote_data.h"
23 #include "bridge/cj_frontend/interfaces/cj_ffi/cj_macro.h"
24 #include "core/components_ng/property/transition_property.h"
25 #include "cj_animate_param_ffi.h"
26 
27 namespace OHOS::Ace::Framework {
28 
29 struct CTranslateOptions {
30     double x;
31     uint32_t xType;
32     double y;
33     uint32_t yType;
34     double z;
35     uint32_t zType;
36 };
37 
38 struct CScaleOptions {
39     float x;
40     float y;
41     float z;
42     double centerX;
43     uint32_t centerXType;
44     double centerY;
45     uint32_t centerYType;
46 };
47 
48 struct CRotateOptions {
49     float angle;
50     float x;
51     float y;
52     float z;
53     double centerX;
54     uint32_t centerXType;
55     double centerY;
56     uint32_t centerYType;
57     double centerZ;
58     uint32_t centerZType;
59     float perspective;
60 };
61 
62 class ACE_EXPORT NativeTransitionEffect: public OHOS::FFI::FFIData {
63     DECL_TYPE(NativeTransitionEffect, OHOS::FFI::FFIData)
64 
65 public:
66     explicit NativeTransitionEffect(RefPtr<NG::ChainedTransitionEffect> effect);
67 
Opacity(double number)68     static RefPtr<NG::ChainedTransitionEffect> Opacity(double number)
69     {
70         double opacity = number;
71         if ((LessNotEqual(opacity, 0.0)) || opacity > 1.0) {
72             opacity = 1.0;
73         }
74         return AceType::MakeRefPtr<NG::ChainedOpacityEffect>(opacity);
75     }
76 
Translate(CTranslateOptions options)77     static RefPtr<NG::ChainedTransitionEffect> Translate(CTranslateOptions options)
78     {
79         // default: x, y, z (0.0, 0.0, 0.0)
80         NG::TranslateOptions translate;
81         translate.x = CalcDimension(options.x, DimensionUnit(options.xType));
82         translate.y = CalcDimension(options.y, DimensionUnit(options.yType));
83         translate.z = CalcDimension(options.z, DimensionUnit(options.zType));
84         return AceType::MakeRefPtr<NG::ChainedTranslateEffect>(translate);
85     }
86 
Scale(CScaleOptions options)87     static RefPtr<NG::ChainedTransitionEffect> Scale(CScaleOptions options)
88     {
89         // default: x, y, z (1.0, 1.0, 1.0), centerX, centerY 50% 50%;
90         NG::ScaleOptions scale(options.x, options.y, options.z,
91             CalcDimension(options.centerX, DimensionUnit(options.centerXType)),
92             CalcDimension(options.centerY, DimensionUnit(options.centerYType)));
93         return AceType::MakeRefPtr<NG::ChainedScaleEffect>(scale);
94     }
95 
Rotate(CRotateOptions options)96     static RefPtr<NG::ChainedTransitionEffect> Rotate(CRotateOptions options)
97     {
98         NG::RotateOptions rotate(options.x, options.y, options.z, options.angle,
99             CalcDimension(options.centerX, DimensionUnit(options.centerXType)),
100             CalcDimension(options.centerY, DimensionUnit(options.centerYType)),
101             CalcDimension(options.centerZ, DimensionUnit(options.centerZType)),
102             options.perspective);
103         return AceType::MakeRefPtr<NG::ChainedRotateEffect>(rotate);
104     }
105 
Move(int32_t edge)106     static RefPtr<NG::ChainedTransitionEffect> Move(int32_t edge)
107     {
108         return AceType::MakeRefPtr<NG::ChainedMoveEffect>(static_cast<NG::TransitionEdge>(edge));
109     }
110 
111 
Asymmetric(int64_t appearId,int64_t disappearId)112     static RefPtr<NG::ChainedTransitionEffect> Asymmetric(int64_t appearId, int64_t disappearId)
113     {
114         auto appear = FFIData::GetData<NativeTransitionEffect>(appearId);
115         if (appear == nullptr) {
116             return nullptr;
117         }
118         auto disappear = FFIData::GetData<NativeTransitionEffect>(disappearId);
119         if (disappear == nullptr) {
120             return nullptr;
121         }
122         auto appearEffect = appear->effect;
123         auto disappearEffect = disappear->effect;
124         return AceType::MakeRefPtr<NG::ChainedAsymmetricEffect>(appearEffect, disappearEffect);
125     }
126 
Identity()127     static RefPtr<NG::ChainedTransitionEffect> Identity()
128     {
129         return AceType::MakeRefPtr<NG::ChainedIdentityEffect>();
130     }
131 
SlideSwitch()132     static RefPtr<NG::ChainedTransitionEffect> SlideSwitch()
133     {
134         return AceType::MakeRefPtr<NG::ChainedSlideSwitchEffect>();
135     }
136 
137     void Combine(sptr<OHOS::Ace::Framework::NativeTransitionEffect> tagEffect);
138 
139     void Animation(const std::shared_ptr<AnimationOption> option);
140 
141     RefPtr<NG::ChainedTransitionEffect> effect;
142 };
143 } // namespace OHOS::Ace::Framework
144 
145 #endif // OHOS_ACE_FRAMEWORK_CJ_TRANSITIONEFFECT_H