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()22RSShadow::RSShadow() {} 23 ~RSShadow()24RSShadow::~RSShadow() {} 25 SetColor(Color color)26void RSShadow::SetColor(Color color) 27 { 28 color_ = color; 29 } 30 SetOffsetX(float offsetX)31void RSShadow::SetOffsetX(float offsetX) 32 { 33 offsetX_ = offsetX; 34 } 35 SetOffsetY(float offsetY)36void RSShadow::SetOffsetY(float offsetY) 37 { 38 offsetY_ = offsetY; 39 } 40 SetAlpha(float alpha)41void RSShadow::SetAlpha(float alpha) 42 { 43 color_.SetAlpha(std::clamp(alpha, 0.0f, 1.0f) * UINT8_MAX); 44 } 45 SetElevation(float elevation)46void RSShadow::SetElevation(float elevation) 47 { 48 isHardwareAcceleration_ = true; 49 elevation_ = elevation; 50 } 51 SetRadius(float radius)52void RSShadow::SetRadius(float radius) 53 { 54 isHardwareAcceleration_ = false; 55 radius_ = radius; 56 } 57 SetPath(std::shared_ptr<RSPath> path)58void RSShadow::SetPath(std::shared_ptr<RSPath> path) 59 { 60 path_ = path; 61 } 62 GetColor() const63Color RSShadow::GetColor() const 64 { 65 return color_; 66 } 67 GetOffsetX() const68float RSShadow::GetOffsetX() const 69 { 70 return offsetX_; 71 } 72 GetOffsetY() const73float RSShadow::GetOffsetY() const 74 { 75 return offsetY_; 76 } 77 GetAlpha() const78float RSShadow::GetAlpha() const 79 { 80 return static_cast<float>(color_.GetAlpha()) / UINT8_MAX; 81 } 82 GetElevation() const83float RSShadow::GetElevation() const 84 { 85 return elevation_; 86 } 87 GetRadius() const88float RSShadow::GetRadius() const 89 { 90 return radius_; 91 } 92 GetPath() const93std::shared_ptr<RSPath> RSShadow::GetPath() const 94 { 95 return path_; 96 } 97 IsValid() const98bool RSShadow::IsValid() const 99 { 100 if (isHardwareAcceleration_) { 101 return GetAlpha() > 0.f; 102 } else { 103 return radius_ > 0.f; 104 } 105 } 106 } // namespace Rosen 107 } // namespace OHOS 108