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 #include "core/components_ng/render/polygon_painter.h"
17
18 #include "core/components_ng/render/shape_painter.h"
19
20 namespace OHOS::Ace::NG {
DrawPolygon(RSCanvas & canvas,const PolygonPaintProperty & polygonPaintProperty,bool isClose)21 void PolygonPainter::DrawPolygon(RSCanvas& canvas, const PolygonPaintProperty& polygonPaintProperty, bool isClose)
22 {
23 if (!polygonPaintProperty.HasPoints()) {
24 return;
25 }
26 RSPen pen;
27 RSBrush brush;
28 if (ShapePainter::SetPen(pen, polygonPaintProperty)) {
29 canvas.AttachPen(pen);
30 }
31 ShapePainter::SetBrush(brush, polygonPaintProperty);
32 canvas.AttachBrush(brush);
33 #ifndef USE_ROSEN_DRAWING
34 RSPath path;
35 #else
36 RSRecordingPath path;
37 #endif
38 std::vector<RSPoint> points;
39 for (auto point : polygonPaintProperty.GetPointsValue()) {
40 points.emplace_back(RSPoint(
41 static_cast<RSScalar>(point.first.ConvertToPx()), static_cast<RSScalar>(point.second.ConvertToPx())));
42 }
43 if (points.empty()) {
44 return;
45 }
46 path.AddPoly(points, static_cast<int>(points.size()), isClose);
47 canvas.DrawPath(path);
48 canvas.DetachBrush();
49 canvas.DetachPen();
50 }
51 } // namespace OHOS::Ace::NG