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 "render/rs_shadow.h"
17 
18 #include <algorithm>
19 
20 namespace OHOS {
21 namespace Rosen {
RSShadow()22 RSShadow::RSShadow() {}
23 
~RSShadow()24 RSShadow::~RSShadow() {}
25 
SetColor(Color color)26 void RSShadow::SetColor(Color color)
27 {
28     color_ = color;
29 }
30 
SetOffsetX(float offsetX)31 void RSShadow::SetOffsetX(float offsetX)
32 {
33     offsetX_ = offsetX;
34 }
35 
SetOffsetY(float offsetY)36 void RSShadow::SetOffsetY(float offsetY)
37 {
38     offsetY_ = offsetY;
39 }
40 
SetAlpha(float alpha)41 void RSShadow::SetAlpha(float alpha)
42 {
43     color_.SetAlpha(std::clamp(alpha, 0.0f, 1.0f) * UINT8_MAX);
44 }
45 
SetElevation(float elevation)46 void RSShadow::SetElevation(float elevation)
47 {
48     elevation_ = elevation;
49 }
50 
SetRadius(float radius)51 void RSShadow::SetRadius(float radius)
52 {
53     radius_ = radius;
54 }
55 
SetPath(const std::shared_ptr<RSPath> & path)56 void RSShadow::SetPath(const std::shared_ptr<RSPath>& path)
57 {
58     path_ = path;
59 }
60 
SetMask(bool mask)61 void RSShadow::SetMask(bool mask)
62 {
63     imageMask_ = mask;
64 }
65 
SetIsFilled(bool isFilled)66 void RSShadow::SetIsFilled(bool isFilled)
67 {
68     isFilled_ = isFilled;
69 }
70 
SetColorStrategy(int colorStrategy)71 void RSShadow::SetColorStrategy(int colorStrategy)
72 {
73     colorStrategy_ = colorStrategy;
74 }
75 
GetColor() const76 const Color& RSShadow::GetColor() const
77 {
78     return color_;
79 }
80 
GetOffsetX() const81 float RSShadow::GetOffsetX() const
82 {
83     return offsetX_;
84 }
85 
GetOffsetY() const86 float RSShadow::GetOffsetY() const
87 {
88     return offsetY_;
89 }
90 
GetAlpha() const91 float RSShadow::GetAlpha() const
92 {
93     return static_cast<float>(color_.GetAlpha()) / UINT8_MAX;
94 }
95 
GetElevation() const96 float RSShadow::GetElevation() const
97 {
98     return elevation_;
99 }
100 
GetRadius() const101 float RSShadow::GetRadius() const
102 {
103     return radius_;
104 }
105 
GetPath() const106 const std::shared_ptr<RSPath>& RSShadow::GetPath() const
107 {
108     return path_;
109 }
110 
GetMask() const111 bool RSShadow::GetMask() const
112 {
113     return imageMask_;
114 }
115 
GetIsFilled() const116 bool RSShadow::GetIsFilled() const
117 {
118     return isFilled_;
119 }
120 
GetColorStrategy() const121 int RSShadow::GetColorStrategy() const
122 {
123     return colorStrategy_;
124 }
125 
IsValid() const126 bool RSShadow::IsValid() const
127 {
128     return (ROSEN_GNE(GetElevation(), 0.f) && ROSEN_GNE(GetAlpha(), 0.f)) || (ROSEN_GNE(GetRadius(), 0.f));
129 }
130 
131 } // namespace Rosen
132 } // namespace OHOS
133