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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TWEEN_TWEEN_COMPONENT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TWEEN_TWEEN_COMPONENT_H
18 
19 #include "base/utils/macros.h"
20 #include "core/animation/animation_pub.h"
21 #include "core/animation/curve.h"
22 #include "core/components/common/properties/tween_option.h"
23 #include "core/components/tween/tween_element.h"
24 #include "core/pipeline/base/composed_component.h"
25 
26 namespace OHOS::Ace {
27 
28 class ACE_EXPORT TweenComponent : public ComposedComponent {
29     DECLARE_ACE_TYPE(TweenComponent, ComposedComponent);
30 
31 public:
TweenComponent(const ComposeId & id,const std::string & name,const RefPtr<Component> & child)32     TweenComponent(const ComposeId& id, const std::string& name, const RefPtr<Component>& child)
33         : ComposedComponent(id, name, child)
34     {}
TweenComponent(const std::string & name,const RefPtr<Component> & child)35     TweenComponent(const std::string& name, const RefPtr<Component>& child)
36         : ComposedComponent(AllocTweenComponentId(), name, child)
37     {}
TweenComponent(const ComposeId & id,const std::string & name)38     TweenComponent(const ComposeId& id, const std::string& name) : ComposedComponent(id, name) {}
TweenComponent(const std::string & name)39     explicit TweenComponent(const std::string& name) : ComposedComponent(AllocTweenComponentId(), name) {}
40     ~TweenComponent() override = default;
41 
42     void SetTweenOption(const TweenOption& option);
43     void SetCustomTweenOption(const TweenOption& option);
44     void SetAnimationOperation(const AnimationOperation& operation);
45     void SetCustomAnimationOperation(const AnimationOperation& operation);
46 
47     const TweenOption& GetTweenOption() const;
48     const TweenOption& GetCustomTweenOption() const;
49     const AnimationOperation& GetAnimationOperation() const;
50     const AnimationOperation& GetCustomAnimationOperation() const;
51 
SetOptionCssChanged(bool change)52     void SetOptionCssChanged(bool change)
53     {
54         optionCssChanged_ = change;
55     }
56 
SetOptionCustomChanged(bool change)57     void SetOptionCustomChanged(bool change)
58     {
59         optionCustomChanged_ = change;
60     }
61 
IsOptionCssChanged()62     bool IsOptionCssChanged() const
63     {
64         return optionCssChanged_;
65     }
66 
IsOptionCustomChanged()67     bool IsOptionCustomChanged() const
68     {
69         return optionCustomChanged_;
70     }
71 
SetOperationCssChanged(bool change)72     void SetOperationCssChanged(bool change)
73     {
74         operationCssChanged_ = change;
75     }
76 
SetOperationCustomChanged(bool change)77     void SetOperationCustomChanged(bool change)
78     {
79         operationCustomChanged_ = change;
80     }
81 
IsOperationCssChanged()82     bool IsOperationCssChanged() const
83     {
84         return operationCssChanged_;
85     }
86 
IsOperationCustomChanged()87     bool IsOperationCustomChanged() const
88     {
89         return operationCustomChanged_;
90     }
91 
92     RefPtr<Element> CreateElement() override;
93 
94     static ComposeId AllocTweenComponentId();
95 
96     void SetIsFirstFrameShow(bool isFirstFrameShow);
97 
98     bool GetIsFirstFrameShow() const;
99 
100     void SetAnimator(const RefPtr<Animator>& animator);
101     RefPtr<Animator> GetAnimator() const;
102 
SetLeafNode(bool isLeaf)103     void SetLeafNode(bool isLeaf)
104     {
105         isLeaf_ = isLeaf;
106     }
107 
IsLeafNode()108     bool IsLeafNode() const
109     {
110         return isLeaf_;
111     }
112 
SetShadow(const Shadow & shadow)113     void SetShadow(const Shadow& shadow)
114     {
115         shadow_ = shadow;
116     }
117 
GetShadow()118     const Shadow& GetShadow() const
119     {
120         return shadow_;
121     }
122 
SetLeft(const Dimension & left)123     void SetLeft(const Dimension& left)
124     {
125         positionParam_.left.first = left;
126         positionParam_.left.second = true;
127     }
128 
SetRight(const Dimension & right)129     void SetRight(const Dimension& right)
130     {
131         positionParam_.right.first = right;
132         positionParam_.right.second = true;
133     }
134 
SetTop(const Dimension & top)135     void SetTop(const Dimension& top)
136     {
137         positionParam_.top.first = top;
138         positionParam_.top.second = true;
139     }
140 
SetBottom(const Dimension & bottom)141     void SetBottom(const Dimension& bottom)
142     {
143         positionParam_.bottom.first = bottom;
144         positionParam_.bottom.second = true;
145     }
146 
SetHasLeft(bool hasLeft)147     void SetHasLeft(bool hasLeft)
148     {
149         positionParam_.left.second = hasLeft;
150     }
151 
SetHasRight(bool hasRight)152     void SetHasRight(bool hasRight)
153     {
154         positionParam_.right.second = hasRight;
155     }
156 
SetHasTop(bool hasTop)157     void SetHasTop(bool hasTop)
158     {
159         positionParam_.top.second = hasTop;
160     }
161 
SetHasBottom(bool hasBottom)162     void SetHasBottom(bool hasBottom)
163     {
164         positionParam_.bottom.second = hasBottom;
165     }
166 
SetPositionType(PositionType positionType)167     void SetPositionType(PositionType positionType)
168     {
169         positionParam_.type = positionType;
170     }
171 
GetPositionParam()172     const PositionParam& GetPositionParam() const
173     {
174         return positionParam_;
175     }
176 
UpdateAnimationName(const std::string & animationName)177     void UpdateAnimationName(const std::string& animationName)
178     {
179         if (animationName_ == animationName) {
180             isAnimationNameUpdated_ = false;
181         } else {
182             animationName_ = animationName;
183             isAnimationNameUpdated_ = true;
184         }
185     }
186 
IsAnimationNameUpdated()187     bool IsAnimationNameUpdated() const
188     {
189         return isAnimationNameUpdated_;
190     }
191 
DisableAnimationNameUpdated()192     void DisableAnimationNameUpdated()
193     {
194         isAnimationNameUpdated_ = false;
195     }
196 
197 private:
198     TweenOption optionCss_;
199     TweenOption optionCustom_;
200     AnimationOperation operationCss_ = AnimationOperation::PLAY;
201     AnimationOperation operationCustom_ = AnimationOperation::PLAY;
202     std::string animationName_;
203     bool isAnimationNameUpdated_ = false;
204     bool isFirstFrameShow_ = true;
205     bool optionCssChanged_ = false;
206     bool optionCustomChanged_ = false;
207     bool operationCssChanged_ = false;
208     bool operationCustomChanged_ = false;
209     bool isLeaf_ = false;
210     RefPtr<Animator> animator_;
211     Shadow shadow_;
212     PositionParam positionParam_;
213 };
214 
215 } // namespace OHOS::Ace
216 
217 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TWEEN_TWEEN_COMPONENT_H
218