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_CLIP_CLIP_COMPONENT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CLIP_CLIP_COMPONENT_H
18 
19 #include "base/utils/utils.h"
20 #include "core/components/common/properties/radius.h"
21 #include "core/pipeline/base/sole_child_component.h"
22 
23 namespace OHOS::Ace {
24 
25 class ClipComponent : public SoleChildComponent {
26     DECLARE_ACE_TYPE(ClipComponent, SoleChildComponent);
27 
28 public:
ClipComponent(const RefPtr<Component> & child)29     explicit ClipComponent(const RefPtr<Component>& child) : SoleChildComponent(child) {}
30     ~ClipComponent() override = default;
31 
32     RefPtr<Element> CreateElement() override;
33 
34     RefPtr<RenderNode> CreateRenderNode() override;
35 
SetWidth(const Dimension & width)36     void SetWidth(const Dimension& width)
37     {
38         width_ = width;
39     }
40 
GetWidth()41     const Dimension& GetWidth() const
42     {
43         return width_;
44     }
45 
SetHeight(const Dimension & height)46     void SetHeight(const Dimension& height)
47     {
48         height_ = height;
49     }
50 
GetHeight()51     const Dimension& GetHeight() const
52     {
53         return height_;
54     }
55 
GetOffsetX()56     const Dimension& GetOffsetX() const
57     {
58         return offsetX_;
59     }
60 
SetOffsetX(const Dimension & offsetX)61     void SetOffsetX(const Dimension& offsetX)
62     {
63         offsetX_ = offsetX;
64     }
65 
GetOffsetY()66     const Dimension& GetOffsetY() const
67     {
68         return offsetY_;
69     }
70 
SetOffsetY(const Dimension & offsetY)71     void SetOffsetY(const Dimension& offsetY)
72     {
73         offsetY_ = offsetY;
74     }
75 
SetClipRadius(const Radius & clipRadius)76     void SetClipRadius(const Radius& clipRadius)
77     {
78         topLeftRadius_ = clipRadius;
79         topRightRadius_ = clipRadius;
80         bottomLeftRadius_ = clipRadius;
81         bottomRightRadius_ = clipRadius;
82     }
83 
GetTopLeftRadius()84     const Radius& GetTopLeftRadius() const
85     {
86         return topLeftRadius_;
87     }
88 
SetTopLeftRadius(const Radius & topLeftRadius)89     void SetTopLeftRadius(const Radius& topLeftRadius)
90     {
91         topLeftRadius_ = topLeftRadius;
92     }
93 
GetTopRightRadius()94     const Radius& GetTopRightRadius() const
95     {
96         return topRightRadius_;
97     }
98 
SetTopRightRadius(const Radius & topRightRadius)99     void SetTopRightRadius(const Radius& topRightRadius)
100     {
101         topRightRadius_ = topRightRadius;
102     }
103 
GetBottomLeftRadius()104     const Radius& GetBottomLeftRadius() const
105     {
106         return bottomLeftRadius_;
107     }
108 
SetBottomLeftRadius(const Radius & bottomLeftRadius)109     void SetBottomLeftRadius(const Radius& bottomLeftRadius)
110     {
111         bottomLeftRadius_ = bottomLeftRadius;
112     }
113 
GetBottomRightRadius()114     const Radius& GetBottomRightRadius() const
115     {
116         return bottomRightRadius_;
117     }
118 
SetBottomRightRadius(const Radius & bottomRightRadius)119     void SetBottomRightRadius(const Radius& bottomRightRadius)
120     {
121         bottomRightRadius_ = bottomRightRadius;
122     }
123 
IsFollowChild()124     bool IsFollowChild() const
125     {
126         return followChild_;
127     }
128 
SetFollowChild(bool followChild)129     void SetFollowChild(bool followChild)
130     {
131         followChild_ = followChild;
132     }
133 
IsClipWithShadow()134     bool IsClipWithShadow() const
135     {
136         return clipWithShadow_;
137     }
138 
SetClipWithShadow(bool clipWithShadow)139     void SetClipWithShadow(bool clipWithShadow)
140     {
141         clipWithShadow_ = clipWithShadow;
142     }
143 
144 private:
145     Dimension width_ = Dimension(0.0);
146     Dimension height_ = Dimension(0.0);
147     Dimension offsetX_ = Dimension(0.0);
148     Dimension offsetY_ = Dimension(0.0);
149 
150     Radius topLeftRadius_;
151     Radius topRightRadius_;
152     Radius bottomLeftRadius_;
153     Radius bottomRightRadius_;
154     bool followChild_ = true;
155     // Play clip animation with shadow when set true, shadow should set in box outer of tween component.
156     bool clipWithShadow_ = false;
157 };
158 
159 } // namespace OHOS::Ace
160 
161 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CLIP_CLIP_COMPONENT_H
162