• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_NG_PATTERN_BUBBLE_BUBBLE_PAINT_METHOD_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_BUBBLE_BUBBLE_PAINT_METHOD_H
18 
19 #include "base/geometry/dimension.h"
20 #include "base/geometry/ng/offset_t.h"
21 #include "base/geometry/ng/size_t.h"
22 #include "core/components/common/properties/alignment.h"
23 #include "core/components/common/properties/border.h"
24 #include "core/components/common/properties/placement.h"
25 #include "core/components/common/properties/shadow.h"
26 #include "core/components/common/properties/shadow_config.h"
27 #include "core/components_ng/render/canvas_image.h"
28 #include "core/components_ng/render/drawing.h"
29 #include "core/components_ng/render/drawing_prop_convertor.h"
30 #include "core/components_ng/render/node_paint_method.h"
31 #include "core/components_ng/render/paint_wrapper.h"
32 
33 namespace OHOS::Ace::NG {
34 
35 class ACE_EXPORT BubblePaintMethod : public NodePaintMethod {
36     DECLARE_ACE_TYPE(BubblePaintMethod, NodePaintMethod)
37 public:
38     BubblePaintMethod() = default;
39     ~BubblePaintMethod() override = default;
40 
GetContentDrawFunction(PaintWrapper * paintWrapper)41     CanvasDrawFunction GetContentDrawFunction(PaintWrapper* paintWrapper) override
42     {
43         return [weak = WeakClaim(this), paintWrapper](RSCanvas& canvas) {
44             auto bubble = weak.Upgrade();
45             if (bubble) {
46                 bubble->PaintMask(canvas, paintWrapper);
47                 bubble->ClipBubble(paintWrapper);
48                 bubble->PaintBorder(canvas, paintWrapper);
49             }
50         };
51     }
52 
GetOverlayDrawFunction(PaintWrapper * paintWrapper)53     CanvasDrawFunction GetOverlayDrawFunction(PaintWrapper* paintWrapper) override
54     {
55         return [weak = WeakClaim(this), paintWrapper](RSCanvas& canvas) {
56             auto bubble = weak.Upgrade();
57             if (bubble) {
58                 bubble->PaintInnerBorder(canvas, paintWrapper);
59                 bubble->PaintOuterBorder(canvas, paintWrapper);
60             }
61         };
62     }
63 
SetShowArrow(bool flag)64     void SetShowArrow(bool flag)
65     {
66         showArrow_ = flag;
67     }
68 
SetChildOffset(const OffsetF & offset)69     void SetChildOffset(const OffsetF& offset)
70     {
71         childOffset_ = offset;
72     }
73 
SetChildSize(const SizeF & size)74     void SetChildSize(const SizeF& size)
75     {
76         childSize_ = size;
77     }
78 
SetArrowPosition(const OffsetF & offset)79     void SetArrowPosition(const OffsetF& offset)
80     {
81         arrowPosition_ = offset;
82     }
83 
SetClipPath(const std::string & clipPath)84     void SetClipPath(const std::string& clipPath)
85     {
86         clipPath_ = clipPath;
87     }
88 
SetClipFrameNode(RefPtr<FrameNode> & clipFrameNode)89     void SetClipFrameNode(RefPtr<FrameNode>& clipFrameNode)
90     {
91         clipFrameNode_ = clipFrameNode;
92     }
93 
SetArrowOffsetsFromClip(const std::vector<std::vector<float>> & arrowOffsetsFromClip)94     void SetArrowOffsetsFromClip(const std::vector<std::vector<float>>& arrowOffsetsFromClip)
95     {
96         arrowOffsetsFromClip_ = arrowOffsetsFromClip;
97     }
98 
SetArrowWidth(const float arrowWidth)99     void SetArrowWidth(const float arrowWidth)
100     {
101         arrowWidth_ = arrowWidth;
102     }
103 
SetArrowHeight(const float arrowHeight)104     void SetArrowHeight(const float arrowHeight)
105     {
106         arrowHeight_ = arrowHeight;
107     }
108 
109     void PaintBubble(RSCanvas& canvas, PaintWrapper* paintWrapper);
110     void PaintMask(RSCanvas& canvas, PaintWrapper* paintWrapper);
111     void PaintBorder(RSCanvas& canvas, PaintWrapper* paintWrapper);
112     void ClipBubble(PaintWrapper* paintWrapper);
113     void PaintDoubleBorder(RSCanvas& canvas, PaintWrapper* paintWrapper);
114     void PaintOuterBorder(RSCanvas& canvas, PaintWrapper* paintWrapper);
115     void PaintInnerBorder(RSCanvas& canvas, PaintWrapper* paintWrapper);
116     bool IsPaintDoubleBorder(PaintWrapper* paintWrapper);
117     void DrawDashedBorder(RSCanvas& canvas, RSPen& paint);
118 
119 private:
120     void PaintBubbleWithArrow(RSCanvas& canvas, PaintWrapper* paintWrapper);
121     void PaintDoubleBorderWithArrow(RSCanvas& canvas, PaintWrapper* paintWrapper);
122     void PaintNonCustomPopup(RSCanvas& canvas, PaintWrapper* wrapper);
123 
124     void PaintTopBubble(RSCanvas& canvas);
125     void PaintBottomBubble(RSCanvas& canvas);
126     void PaintDefaultBubble(RSCanvas& canvas);
127 
128     void UpdateArrowOffset(const std::optional<Dimension>& offset, const Placement& placement);
129 
130     RSRoundRect MakeRRect();
131     float GetArrowOffset(const Placement& placement);
132     void InitEdgeSize(Edge& edge);
133 
134     void BuildCompletePath(RSPath& path);
135     void BuildCornerPath(RSPath& path, const Placement& placement, float radius);
136     void BuildTopLinePath(RSPath& path, float arrowOffset, float radius);
137     void BuildRightLinePath(RSPath& path, float arrowOffset, float radius);
138     void BuildBottomLinePath(RSPath& path, float arrowOffset, float radius);
139     void BuildLeftLinePath(RSPath& path, float arrowOffset, float radius);
140     void PaintShadow(const RSPath& path, const Shadow& shadow, RSCanvas& canvas);
141     void ClipBubbleWithPath(const RefPtr<FrameNode>& frameNode);
142 
143     void BuildDoubleBorderPath(RSPath& path);
144     void BuildTopDoubleBorderPath(RSPath& path, float radius);
145     void BuildRightDoubleBorderPath(RSPath& path, float radius);
146     void BuildBottomDoubleBorderPath(RSPath& path, float radius);
147     void BuildLeftDoubleBorderPath(RSPath& path, float radius);
148 
149     float GetInnerBorderOffset();
150     float GetBorderOffset();
151     float outerBorderWidth_ = Dimension(0.8_vp).ConvertToPx();
152     float innerBorderWidth_ = Dimension(0.6_vp).ConvertToPx();
153     bool needPaintOuterBorder_ = false;
154     bool isPaintBubble_ = false;
155     std::vector<std::vector<float>> arrowOffsetsFromClip_
156         = { {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f} };
157     float arrowWidth_ = Dimension(16.0_vp).ConvertToPx();
158     float arrowHeight_ = Dimension(8.0_vp).ConvertToPx();
159 
160     // Get from RenderProp
161     bool useCustom_ = false;
162     Placement arrowPlacement_ = Placement::BOTTOM;
163     bool enableArrow_ = false;
164     Dimension arrowOffset_;
165     Color maskColor_;
166     Color backgroundColor_;
167 
168     // Get from pattern
169     OffsetF childOffset_;
170     OffsetF arrowPosition_;
171     SizeF childSize_;
172     bool showArrow_ = false;
173     std::string clipPath_;
174     RefPtr<FrameNode> clipFrameNode_;
175     // Get from theme
176     Border border_;
177     Edge padding_;
178 
179 #ifndef USE_ROSEN_DRAWING
180     RSPath path_;
181 #else
182     RSRecordingPath path_;
183 #endif
184 
185     ACE_DISALLOW_COPY_AND_MOVE(BubblePaintMethod);
186 };
187 } // namespace OHOS::Ace::NG
188 
189 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_BUBBLE_BUBBLE_PAINT_METHOD_H