• 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_SHAPE_RECT_PAINT_METHOD_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_SHAPE_RECT_PAINT_METHOD_H
18 
19 #include "base/geometry/ng/radius.h"
20 #include "core/components_ng/pattern/shape/shape_paint_method.h"
21 #include "core/components_ng/pattern/shape/shape_overlay_modifier.h"
22 #include "core/components_ng/pattern/shape/rect_paint_property.h"
23 #include "core/components_ng/render/node_paint_method.h"
24 #include "core/components_ng/render/rect_painter.h"
25 namespace OHOS::Ace::NG {
26 
27 class ACE_EXPORT RectPaintMethod : public ShapePaintMethod {
28     DECLARE_ACE_TYPE(RectPaintMethod, ShapePaintMethod);
29 public:
30     RectPaintMethod() = default;
RectPaintMethod(const RefPtr<ShapePaintProperty> & shapePaintProperty,const RefPtr<ShapeOverlayModifier> & shapeOverlayModifier)31     RectPaintMethod(
32         const RefPtr<ShapePaintProperty>& shapePaintProperty,
33         const RefPtr<ShapeOverlayModifier>& shapeOverlayModifier)
34         : ShapePaintMethod(shapePaintProperty, shapeOverlayModifier)
35     {}
36     ~RectPaintMethod() override = default;
GetContentDrawFunction(PaintWrapper * paintWrapper)37     CanvasDrawFunction GetContentDrawFunction(PaintWrapper* paintWrapper) override
38     {
39         CHECK_NULL_RETURN(paintWrapper, nullptr);
40         auto rectPaintProperty = DynamicCast<RectPaintProperty>(paintWrapper->GetPaintProperty()->Clone());
41         CHECK_NULL_RETURN(rectPaintProperty, nullptr);
42 
43         if (propertiesFromAncestor_) {
44             if (!rectPaintProperty->HasFill() && propertiesFromAncestor_->HasFill()) {
45                 auto renderContext = paintWrapper->GetRenderContext();
46                 renderContext->UpdateForegroundColor(propertiesFromAncestor_->GetFillValue());
47                 renderContext->ResetForegroundColorStrategy();
48             }
49             rectPaintProperty->UpdateShapeProperty(propertiesFromAncestor_);
50         }
51         if (paintWrapper->HasForegroundColor()) {
52             rectPaintProperty->UpdateFill(paintWrapper->GetForegroundColor());
53         } else if (paintWrapper->HasForegroundColorStrategy()) {
54             rectPaintProperty->UpdateFill(Color::FOREGROUND);
55             rectPaintProperty->ResetFillOpacity();
56         }
57         rect_.SetSize(rectPaintProperty->GetContentSize());
58         rect_.SetOffset(rectPaintProperty->GetContentOffset());
59 
60         return [rect = rect_, rectPaintProperty, paintWrapper](RSCanvas& canvas) {
61                     RectPainter::DrawRect(canvas, rect, *rectPaintProperty);
62                     if (paintWrapper) {
63                         paintWrapper->FlushOverlayModifier();
64                     }
65                 };
66     }
67 
68 private:
69     RectF rect_;
70     Radius topLeftRadius_;
71     Radius topRightRadius_;
72     Radius bottomLeftRadius_;
73     Radius bottomRightRadius_;
74     ACE_DISALLOW_COPY_AND_MOVE(RectPaintMethod);
75 };
76 
77 } // namespace OHOS::Ace::NG
78 
79 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_SHAPE_RECT_PAINT_METHOD_H
80