• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 PEN_H
17 #define PEN_H
18 
19 #include "draw/brush.h"
20 #include "draw/color.h"
21 #include "effect/filter.h"
22 #include "effect/path_effect.h"
23 #include "utils/rect.h"
24 
25 namespace OHOS {
26 namespace Rosen {
27 namespace Drawing {
28 class Pen {
29 public:
30     enum class JoinStyle {
31         MITER_JOIN,
32         ROUND_JOIN,
33         BEVEL_JOIN,
34     };
35 
36     enum class CapStyle {
37         FLAT_CAP,
38         SQUARE_CAP,
39         ROUND_CAP,
40     };
41 
42     Pen() noexcept;
43     Pen(const Pen& p) noexcept = default;
44     Pen(const Color& c) noexcept;
45     Pen(int rgba) noexcept;
~Pen()46     ~Pen() {};
47 
48     Color GetColor() const;
49     void SetColor(const Color& c);
50     void SetColor(int c);
51     void SetARGB(int r, int g, int b, int a);
52 
53     Color4f GetColor4f();
54     std::shared_ptr<ColorSpace> GetColorSpace() const;
55     void SetColor(const Color4f& cf, std::shared_ptr<ColorSpace> s);
56 
57     uint32_t GetAlpha() const;
58     void SetAlpha(uint32_t a);
59     void SetAlphaF(scalar a);
60 
61     scalar GetWidth() const;
62     void SetWidth(scalar width);
63 
64     scalar GetMiterLimit() const;
65     void SetMiterLimit(scalar limit);
66 
67     CapStyle GetCapStyle() const;
68     void SetCapStyle(CapStyle cs);
69 
70     JoinStyle GetJoinStyle() const;
71     void SetJoinStyle(JoinStyle js);
72 
73     BlendMode GetBlendMode() const;
74     void SetBlendMode(BlendMode mode);
75 
76     bool IsAntiAlias() const;
77     void SetAntiAlias(bool aa);
78 
79     void SetPathEffect(std::shared_ptr<PathEffect> e);
80     std::shared_ptr<PathEffect> GetPathEffect() const;
81 
82     void SetFilter(const Filter& filter);
83     Filter GetFilter() const;
84 
85     void SetShaderEffect(std::shared_ptr<ShaderEffect> e);
86     std::shared_ptr<ShaderEffect> GetShaderEffect() const;
87 
88     void Reset();
89 
90     friend bool operator==(const Pen& p1, const Pen& p2);
91     friend bool operator!=(const Pen& p1, const Pen& p2);
92 
93 private:
94     scalar width_;
95     scalar miterLimit_;
96     JoinStyle join_;
97     CapStyle cap_;
98     std::shared_ptr<PathEffect> pathEffect_;
99 
100     Brush brush_;
101 };
102 } // namespace Drawing
103 } // namespace Rosen
104 } // namespace OHOS
105 #endif