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