• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "modifier_ng/geometry/rs_bounds_modifier.h"
17 
18 #include "platform/common/rs_log.h"
19 
20 namespace OHOS::Rosen::ModifierNG {
SetBounds(Vector4f bounds)21 void RSBoundsModifier::SetBounds(Vector4f bounds)
22 {
23     Setter(RSPropertyType::BOUNDS, bounds);
24 }
25 
SetBoundsSize(Vector2f size)26 void RSBoundsModifier::SetBoundsSize(Vector2f size)
27 {
28     Vector4f oldBounds = GetBounds();
29     SetBounds({ oldBounds.x_, oldBounds.y_, size.x_, size.y_ });
30 }
31 
SetBoundsWidth(float width)32 void RSBoundsModifier::SetBoundsWidth(float width)
33 {
34     Vector4f oldBounds = GetBounds();
35     SetBounds({ oldBounds.x_, oldBounds.y_, width, oldBounds.w_ });
36 }
37 
SetBoundsHeight(float height)38 void RSBoundsModifier::SetBoundsHeight(float height)
39 {
40     Vector4f oldBounds = GetBounds();
41     SetBounds({ oldBounds.x_, oldBounds.y_, oldBounds.z_, height });
42 }
43 
SetBoundsPosition(Vector2f position)44 void RSBoundsModifier::SetBoundsPosition(Vector2f position)
45 {
46     Vector4f oldBounds = GetBounds();
47     SetBounds({ position.x_, position.y_, oldBounds.z_, oldBounds.w_ });
48 }
49 
SetBoundsPositionX(float positionX)50 void RSBoundsModifier::SetBoundsPositionX(float positionX)
51 {
52     Vector4f oldBounds = GetBounds();
53     SetBounds({ positionX, oldBounds.y_, oldBounds.z_, oldBounds.w_ });
54 }
55 
SetBoundsPositionY(float positionY)56 void RSBoundsModifier::SetBoundsPositionY(float positionY)
57 {
58     Vector4f oldBounds = GetBounds();
59     SetBounds({ oldBounds.x_, positionY, oldBounds.z_, oldBounds.w_ });
60 }
61 
GetBounds() const62 Vector4f RSBoundsModifier::GetBounds() const
63 {
64     return Getter(RSPropertyType::BOUNDS, Vector4f());
65 }
66 
GetBoundsSize() const67 Vector2f RSBoundsModifier::GetBoundsSize() const
68 {
69     Vector4f bounds = GetBounds();
70     return { bounds.z_, bounds.w_ };
71 }
72 
GetBoundsWidth() const73 float RSBoundsModifier::GetBoundsWidth() const
74 {
75     return GetBounds().z_;
76 }
77 
GetBoundsHeight() const78 float RSBoundsModifier::GetBoundsHeight() const
79 {
80     return GetBounds().w_;
81 }
82 
GetBoundsPosition() const83 Vector2f RSBoundsModifier::GetBoundsPosition() const
84 {
85     Vector4f bounds = GetBounds();
86     return { bounds.x_, bounds.y_ };
87 }
88 
GetBoundsPositionX() const89 float RSBoundsModifier::GetBoundsPositionX() const
90 {
91     return GetBounds().x_;
92 }
93 
GetBoundsPositionY() const94 float RSBoundsModifier::GetBoundsPositionY() const
95 {
96     return GetBounds().y_;
97 }
98 
ApplyGeometry(const std::shared_ptr<RSObjAbsGeometry> & geometry)99 void RSBoundsModifier::ApplyGeometry(const std::shared_ptr<RSObjAbsGeometry>& geometry)
100 {
101     if (geometry == nullptr) {
102         RS_LOGE("RSBoundsModifier::ApplyGeometry, geometry null");
103         return;
104     }
105     if (auto boundsPtr = GetProperty(RSPropertyType::BOUNDS)) {
106         auto bounds = GetterWithoutCheck<Vector4f>(boundsPtr);
107         geometry->SetRect(bounds.x_, bounds.y_, bounds.z_, bounds.w_);
108     }
109 }
110 } // namespace OHOS::Rosen::ModifierNG
111