• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2024 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_TEXT_PICKER_TEXT_PICKER_PAINT_METHOD_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_PICKER_TEXT_PICKER_PAINT_METHOD_H
18 
19 #include "base/geometry/ng/size_t.h"
20 #include "base/memory/ace_type.h"
21 #include "base/memory/referenced.h"
22 #include "base/utils/macros.h"
23 #include "base/utils/utils.h"
24 #include "core/components/common/properties/color.h"
25 #include "core/components_ng/pattern/pattern.h"
26 #include "core/components_ng/pattern/text_picker/textpicker_properties.h"
27 #include "core/components_ng/render/divider_painter.h"
28 #include "core/components_ng/render/node_paint_method.h"
29 
30 namespace OHOS::Ace::NG {
31 
32 class ACE_EXPORT TextPickerPaintMethod : public NodePaintMethod {
33     DECLARE_ACE_TYPE(TextPickerPaintMethod, NodePaintMethod);
34 public:
35     TextPickerPaintMethod() = default;
~TextPickerPaintMethod()36     ~TextPickerPaintMethod() override {}
37 
TextPickerPaintMethod(const WeakPtr<Pattern> & pattern)38     TextPickerPaintMethod(const WeakPtr<Pattern>& pattern)
39     {
40         pattern_ = pattern;
41     }
42 
GetDefaultPickerItemHeight()43     double GetDefaultPickerItemHeight() const
44     {
45         return defaultPickerItemHeight_;
46     }
47 
SetDefaultPickerItemHeight(double defaultPickerItemHeight)48     void SetDefaultPickerItemHeight(double defaultPickerItemHeight)
49     {
50         defaultPickerItemHeight_ = defaultPickerItemHeight;
51     }
52 
SetEnabled(bool enabled)53     void SetEnabled(bool enabled)
54     {
55         enabled_ = enabled;
56     }
57 
58     CanvasDrawFunction GetContentDrawFunction(PaintWrapper* paintWrapper) override;
59     CanvasDrawFunction GetForegroundDrawFunction(PaintWrapper* paintWrapper) override;
60     void PaintDividerLines(RSCanvas& canvas, const RectF& contentRect, const DividerInfo &info,
61         bool isDefaultLine = true);
62 
63 private:
64     double defaultPickerItemHeight_ = 0.0;
65     bool enabled_ = true;
66 
67     WeakPtr<Pattern> pattern_;
68 
69     bool NeedPaintDividerLines(const RectF &contentRect, const ItemDivider &divider, double dividerHeight,
70         DividerInfo& info);
71     void PaintDefaultDividerLines(RSCanvas& canvas, const RectF &contentRect, double dividerHeight);
72     void PaintCustomDividerLines(RSCanvas& canvas, const RectF &contentRect, const RectF &frameRect,
73         const ItemDivider &divider, double dividerHeight);
74     void PaintLine(const OffsetF& offset, const DividerInfo &info, RSCanvas& canvas);
75     bool SetStrokeWidth(const ItemDivider &divider, double dividerHeight, DividerInfo& info);
76     void PaintSelectedBackgroundColor(RSCanvas& canvas, std::list<RefPtr<UINode>> children, Color color,
77         NG::BorderRadiusProperty borderRadius);
78 };
79 } // namespace OHOS::Ace::NG
80 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_PICKER_TEXT_PICKER_PAINT_METHOD_H
81