• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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_RENDER_BORDER_IMAGE_PAINT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_BORDER_IMAGE_PAINT_H
18 
19 #include <cmath>
20 
21 #include "base/geometry/ng/size_t.h"
22 #include "base/memory/ace_type.h"
23 #include "core/components/common/properties/border_image.h"
24 #include "core/components_ng/property/gradient_property.h"
25 #include "core/components_ng/render/drawing.h"
26 #include "core/components_ng/render/render_property.h"
27 
28 namespace OHOS::Ace::NG {
29 class BorderImagePainter : public virtual AceType {
30     DECLARE_ACE_TYPE(BorderImagePainter, AceType);
31 
32 public:
33     BorderImagePainter(BorderImageProperty bdImageProps, const std::unique_ptr<BorderWidthProperty>& widthProp,
34         const SizeF& paintSize, const RSImage& image, double dipScale);
35     ~BorderImagePainter() override = default;
36     void PaintBorderImage(const OffsetF& offset, RSCanvas& canvas) const;
37 
38 private:
39     void InitPainter();
40     void PaintBorderImageCorners(const OffsetF& offset, RSCanvas& canvas) const;
41     void PaintBorderImageStretch(const OffsetF& offset, RSCanvas& canvas) const;
42     void PaintBorderImageRound(const OffsetF& offset, RSCanvas& canvas) const;
43     void PaintBorderImageSpace(const OffsetF& offset, RSCanvas& canvas) const;
44     void PaintBorderImageRepeat(const OffsetF& offset, RSCanvas& canvas) const;
45     void FillBorderImageCenter(const OffsetF& offset, RSCanvas& canvas) const;
46 
47     void InitBorderImageSlice();
48     void InitBorderImageWidth();
49     void InitBorderImageOutset();
50     void ParseNegativeNumberToZeroOrCeil(double& value);
51 
52     bool hasWidthProp_  = false;
53     BorderImageProperty borderImageProperty_;
54     BorderWidthProperty widthProp_;
55     SizeF paintSize_;
56     RSImage image_;
57 
58     double imageWidth_ = 0.0;
59     double imageHeight_ = 0.0;
60     double imageCenterWidth_ = 0.0;
61     double imageCenterHeight_ = 0.0;
62     double borderCenterWidth_ = 0.0;
63     double borderCenterHeight_ = 0.0;
64 
65     double dipScale_ = 0.0;
66     double leftWidth_ = 0.0;
67     double topWidth_ = 0.0;
68     double rightWidth_ = 0.0;
69     double bottomWidth_ = 0.0;
70 
71     double leftSlice_ = 0.0;
72     double topSlice_ = 0.0;
73     double rightSlice_ = 0.0;
74     double bottomSlice_ = 0.0;
75 
76     double leftOutset_ = 0.0;
77     double topOutset_ = 0.0;
78     double rightOutset_ = 0.0;
79     double bottomOutset_ = 0.0;
80 
81     RSRect srcRectLeft_;
82     RSRect srcRectRight_;
83     RSRect srcRectTop_;
84     RSRect srcRectBottom_;
85 
86     bool paintCornersOnly_ = false;
87 };
88 } // namespace OHOS::Ace::NG
89 
90 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_BORDER_IMAGE_PAINT_H
91