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_RENDER_CLIP_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CLIP_RENDER_CLIP_H
18 
19 #include "core/animation/property_animatable.h"
20 #include "core/components/common/properties/radius.h"
21 #include "core/pipeline/base/render_node.h"
22 
23 namespace OHOS::Ace {
24 
25 class RenderClip : public RenderNode {
26     DECLARE_ACE_TYPE(RenderClip, RenderNode);
27 
28 public:
29     static RefPtr<RenderNode> Create();
30 
31     void Update(const RefPtr<Component>& component) override;
32 
33     void PerformLayout() override;
34 
IsFollowChildSize()35     bool IsFollowChildSize() const
36     {
37         return followChildSize_;
38     }
39 
SetOffsetX(double offsetX)40     virtual void SetOffsetX(double offsetX)
41     {
42         if (offsetX < 0.0) {
43             return;
44         }
45         offsetX_ = offsetX;
46         MarkNeedRender();
47     }
48 
SetOffsetY(double offsetY)49     virtual void SetOffsetY(double offsetY)
50     {
51         if (offsetY < 0.0) {
52             return;
53         }
54         offsetY_ = offsetY;
55         MarkNeedRender();
56     }
57 
58     Rect GetClipRect(const Offset& offset) const;
59 
SetWidth(double width)60     virtual void SetWidth(double width)
61     {
62         if (width < 0.0) {
63             return;
64         }
65         width_ = width;
66         MarkNeedRender();
67     }
68 
SetHeight(double height)69     virtual void SetHeight(double height)
70     {
71         if (height < 0.0) {
72             return;
73         }
74         height_ = height;
75         MarkNeedRender();
76     }
77 
GetHeight()78     double GetHeight() const
79     {
80         return height_;
81     }
82 
SetShadowBoxOffset(const Offset & shadowBoxOffset)83     void SetShadowBoxOffset(const Offset& shadowBoxOffset)
84     {
85         shadowBoxOffset_ = shadowBoxOffset;
86     }
87 
88     void Dump() override;
89 
SetClipRadius(const Radius & clipRadius)90     void SetClipRadius(const Radius& clipRadius)
91     {
92         topLeftRadius_ = clipRadius;
93         topRightRadius_ = clipRadius;
94         bottomLeftRadius_ = clipRadius;
95         bottomRightRadius_ = clipRadius;
96         MarkNeedRender();
97     }
98 
99 protected:
100     double width_ = 0.0;
101     double height_ = 0.0;
102     double offsetX_ = 0.0;
103     double offsetY_ = 0.0;
104 
105     Radius topLeftRadius_;
106     Radius topRightRadius_;
107     Radius bottomLeftRadius_;
108     Radius bottomRightRadius_;
109 
110 private:
111     FloatPropertyAnimatable::SetterMap GetFloatPropertySetterMap() override;
112     FloatPropertyAnimatable::GetterMap GetFloatPropertyGetterMap() override;
113     void UpdateBoxForShadowAnimation();
114     bool followChildSize_ = false;
115     bool clipWithShadow_ = false;
116     Offset shadowBoxOffset_;
117 };
118 
119 } // namespace OHOS::Ace
120 
121 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CLIP_RENDER_CLIP_H
122