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 #include "draw/brush.h"
17
18 namespace OHOS {
19 namespace Rosen {
20 namespace Drawing {
Brush()21 Brush::Brush() noexcept
22 : color_(),
23 blendMode_(BlendMode::SRC_OVER),
24 filter_(),
25 colorSpace_(nullptr),
26 shaderEffect_(nullptr),
27 antiAlias_(false)
28 {}
29
Brush(const Color & c)30 Brush::Brush(const Color& c) noexcept
31 : color_(c),
32 blendMode_(BlendMode::SRC_OVER),
33 filter_(),
34 colorSpace_(nullptr),
35 shaderEffect_(nullptr),
36 antiAlias_(false)
37 {}
38
Brush(int rgba)39 Brush::Brush(int rgba) noexcept
40 : color_(rgba),
41 blendMode_(BlendMode::SRC_OVER),
42 filter_(),
43 colorSpace_(nullptr),
44 shaderEffect_(nullptr),
45 antiAlias_(false)
46 {}
47
Brush(std::shared_ptr<ShaderEffect> e)48 Brush::Brush(std::shared_ptr<ShaderEffect> e) noexcept
49 : color_(), blendMode_(BlendMode::SRC_OVER), filter_(), colorSpace_(nullptr), shaderEffect_(e), antiAlias_(false)
50 {}
51
GetColor() const52 Color Brush::GetColor() const
53 {
54 return color_;
55 }
56
SetColor(const Color & c)57 void Brush::SetColor(const Color& c)
58 {
59 color_ = c;
60 }
61
SetColor(int c)62 void Brush::SetColor(int c)
63 {
64 color_.SetColorQuad(c);
65 }
66
SetARGB(int r,int g,int b,int a)67 void Brush::SetARGB(int r, int g, int b, int a)
68 {
69 color_.SetRgb(r, g, b, a);
70 }
71
GetColor4f()72 Color4f Brush::GetColor4f()
73 {
74 return color_.GetColor4f();
75 }
76
GetColorSpace() const77 std::shared_ptr<ColorSpace> Brush::GetColorSpace() const
78 {
79 return colorSpace_;
80 }
81
SetColor(const Color4f & cf,std::shared_ptr<ColorSpace> s)82 void Brush::SetColor(const Color4f& cf, std::shared_ptr<ColorSpace> s)
83 {
84 color_.SetRgbF(cf.redF_, cf.greenF_, cf.blueF_, cf.alphaF_);
85 colorSpace_ = s;
86 }
87
GetAlpha() const88 uint32_t Brush::GetAlpha() const
89 {
90 return color_.GetAlpha();
91 }
92
SetAlpha(uint32_t a)93 void Brush::SetAlpha(uint32_t a)
94 {
95 color_.SetAlpha(a);
96 }
97
SetAlphaF(scalar a)98 void Brush::SetAlphaF(scalar a)
99 {
100 color_.SetAlphaF(a);
101 }
102
GetBlendMode() const103 BlendMode Brush::GetBlendMode() const
104 {
105 return blendMode_;
106 }
107
SetBlendMode(BlendMode mode)108 void Brush::SetBlendMode(BlendMode mode)
109 {
110 blendMode_ = mode;
111 }
112
SetFilter(const Filter & filter)113 void Brush::SetFilter(const Filter& filter)
114 {
115 filter_ = filter;
116 }
117
GetFilter() const118 Filter Brush::GetFilter() const
119 {
120 return filter_;
121 }
122
SetShaderEffect(std::shared_ptr<ShaderEffect> e)123 void Brush::SetShaderEffect(std::shared_ptr<ShaderEffect> e)
124 {
125 shaderEffect_ = e;
126 }
127
GetShaderEffect() const128 std::shared_ptr<ShaderEffect> Brush::GetShaderEffect() const
129 {
130 return shaderEffect_;
131 }
132
IsAntiAlias() const133 bool Brush::IsAntiAlias() const
134 {
135 return antiAlias_;
136 }
137
SetAntiAlias(bool aa)138 void Brush::SetAntiAlias(bool aa)
139 {
140 antiAlias_ = aa;
141 }
142
Reset()143 void Brush::Reset()
144 {
145 *this = Brush();
146 }
147
operator ==(const Brush & b1,const Brush & b2)148 bool operator==(const Brush& b1, const Brush& b2)
149 {
150 return b1.color_ == b2.color_ && b1.blendMode_ == b2.blendMode_ && b1.shaderEffect_ == b2.shaderEffect_ &&
151 b1.colorSpace_ == b2.colorSpace_ && b1.filter_ == b2.filter_ && b1.antiAlias_ == b2.antiAlias_;
152 }
153
operator !=(const Brush & b1,const Brush & b2)154 bool operator!=(const Brush& b1, const Brush& b2)
155 {
156 return b1.color_ != b2.color_ || b1.blendMode_ == b2.blendMode_ || b1.shaderEffect_ != b2.shaderEffect_ ||
157 b1.colorSpace_ == b2.colorSpace_ || b1.filter_ != b2.filter_ || b1.antiAlias_ == b2.antiAlias_;
158 }
159 } // namespace Drawing
160 } // namespace Rosen
161 } // namespace OHOS
162