• 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 RENDER_SERVICE_CLIENT_CORE_RENDER_RS_BORDER_H
17 #define RENDER_SERVICE_CLIENT_CORE_RENDER_RS_BORDER_H
18 
19 #include <iostream>
20 #include <sstream>
21 #include <vector>
22 
23 #include "common/rs_color_palette.h"
24 #include "common/rs_vector4.h"
25 #include "platform/common/rs_log.h"
26 #include "property/rs_properties_def.h"
27 
28 #ifndef USE_ROSEN_DRAWING
29 class SkCanvas;
30 class SkPaint;
31 class SkRRect;
32 #else
33 #include "draw/canvas.h"
34 #include "draw/brush.h"
35 #include "draw/pen.h"
36 #include "utils/rect.h"
37 #include "utils/round_rect.h"
38 #endif
39 
40 namespace OHOS {
41 namespace Rosen {
42 enum class BorderStyle : uint32_t {
43     SOLID = 0,
44     DASHED,
45     DOTTED,
46     NONE
47 };
48 
49 class RSBorder final {
50 public:
51     RSBorder() = default;
~RSBorder()52     ~RSBorder() {}
53 
54     enum BorderType : int {
55         LEFT = 0,
56         TOP,
57         RIGHT,
58         BOTTOM,
59     };
60 
61     void SetColor(Color color);
62     void SetWidth(float width);
63     void SetStyle(BorderStyle style);
64     Color GetColor(int idx = RSBorder::LEFT) const;
65     float GetWidth(int idx = RSBorder::LEFT) const;
66     BorderStyle GetStyle(int idx = RSBorder::LEFT) const;
67 
68     void SetColorFour(Vector4<Color> color);
69     void SetWidthFour(Vector4f width);
70     void SetStyleFour(Vector4<uint32_t> style);
71     Vector4<Color> GetColorFour() const;
72     Vector4f GetWidthFour() const;
73     Vector4<uint32_t> GetStyleFour() const;
74 
75     bool HasBorder() const;
76 
77     std::string ToString() const;
78 
79 protected:
80 #ifndef USE_ROSEN_DRAWING
81     bool ApplyFillStyle(SkPaint& paint) const;
82     bool ApplyPathStyle(SkPaint& paint) const;
83     bool ApplyFourLine(SkPaint& paint) const;
84     bool ApplyLineStyle(SkPaint& paint, int borderIdx, float length) const;
85     void PaintFourLine(SkCanvas& canvas, SkPaint& paint, RectF rect) const;
86     void PaintTopPath(SkCanvas& canvas, SkPaint& paint, SkRRect& rrect) const;
87     void PaintRightPath(SkCanvas& canvas, SkPaint& paint, SkRRect& rrect) const;
88     void PaintBottomPath(SkCanvas& canvas, SkPaint& paint, SkRRect& rrect) const;
89     void PaintLeftPath(SkCanvas& canvas, SkPaint& paint, SkRRect& rrect) const;
90 #else
91     bool ApplyFillStyle(Drawing::Brush& brush) const;
92     bool ApplyPathStyle(Drawing::Pen& pen) const;
93     bool ApplyFourLine(Drawing::Pen& pen) const;
94     bool ApplyLineStyle(Drawing::Pen& pen, int borderIdx, float length) const;
95 
96     void PaintFourLine(Drawing::Canvas& canvas, Drawing::Pen& pen, RectF rect) const;
97     void PaintTopPath(Drawing::Canvas& canvas, Drawing::Pen& pen, Drawing::RoundRect& rrect) const;
98     void PaintRightPath(Drawing::Canvas& canvas, Drawing::Pen& pen, Drawing::RoundRect& rrect) const;
99     void PaintBottomPath(Drawing::Canvas& canvas, Drawing::Pen& pen, Drawing::RoundRect& rrect) const;
100     void PaintLeftPath(Drawing::Canvas& canvas, Drawing::Pen& pen, Drawing::RoundRect& rrect) const;
101 #endif
102 
103 private:
104     // Vectors containing uniform or four-sided border attributes.
105     // If four-sided, the order of contents is left, top, right, bottom.
106     std::vector<Color> colors_;
107     std::vector<float> widths_;
108     std::vector<BorderStyle> styles_;
109 
110     friend class RSPropertiesPainter;
111 };
112 } // namespace Rosen
113 } // namespace OHOS
114 
115 #endif // RENDER_SERVICE_CLIENT_CORE_RENDER_RS_BORDER_H
116