• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "core/components/common/properties/border_image.h"
17 
18 namespace OHOS::Ace {
19 
SetEdgeSlice(BorderImageDirection direction,const Dimension & sliceDimension)20 void BorderImage::SetEdgeSlice(BorderImageDirection direction, const Dimension& sliceDimension)
21 {
22     switch (direction) {
23         case BorderImageDirection::TOP:
24             borderImageTop_.SetBorderImageSlice(sliceDimension);
25             break;
26         case BorderImageDirection::BOTTOM:
27             borderImageBottom_.SetBorderImageSlice(sliceDimension);
28             break;
29         case BorderImageDirection::LEFT:
30             borderImageLeft_.SetBorderImageSlice(sliceDimension);
31             break;
32         case BorderImageDirection::RIGHT:
33             borderImageRight_.SetBorderImageSlice(sliceDimension);
34             break;
35         default:
36             LOGE("Unsupported border image direction");
37     }
38 }
39 
SetEdgeOutset(BorderImageDirection direction,const Dimension & outsetDimension)40 void BorderImage::SetEdgeOutset(BorderImageDirection direction, const Dimension& outsetDimension)
41 {
42     switch (direction) {
43         case BorderImageDirection::TOP:
44             borderImageTop_.SetBorderImageOutset(outsetDimension);
45             break;
46         case BorderImageDirection::BOTTOM:
47             borderImageBottom_.SetBorderImageOutset(outsetDimension);
48             break;
49         case BorderImageDirection::LEFT:
50             borderImageLeft_.SetBorderImageOutset(outsetDimension);
51             break;
52         case BorderImageDirection::RIGHT:
53             borderImageRight_.SetBorderImageOutset(outsetDimension);
54             break;
55         default:
56             LOGE("Unsupported border image direction");
57     }
58 }
59 
SetEdgeWidth(BorderImageDirection direction,const Dimension & widthDimension)60 void BorderImage::SetEdgeWidth(BorderImageDirection direction, const Dimension& widthDimension)
61 {
62     switch (direction) {
63         case BorderImageDirection::TOP:
64             borderImageTop_.SetBorderImageWidth(widthDimension);
65             break;
66         case BorderImageDirection::BOTTOM:
67             borderImageBottom_.SetBorderImageWidth(widthDimension);
68             break;
69         case BorderImageDirection::LEFT:
70             borderImageLeft_.SetBorderImageWidth(widthDimension);
71             break;
72         case BorderImageDirection::RIGHT:
73             borderImageRight_.SetBorderImageWidth(widthDimension);
74             break;
75         default:
76             LOGE("Unsupported border image direction");
77     }
78     if (!hasBorderImageWidth_ && GreatNotEqual(widthDimension.Value(), 0.0)) {
79         hasBorderImageWidth_ = true;
80     }
81 }
82 
GetBorderImageEdge(BorderImageDirection direction)83 BorderImageEdge& BorderImage::GetBorderImageEdge(BorderImageDirection direction)
84 {
85     switch (direction) {
86         case BorderImageDirection::TOP:
87             return borderImageTop_;
88         case BorderImageDirection::BOTTOM:
89             return borderImageBottom_;
90         case BorderImageDirection::LEFT:
91             return borderImageLeft_;
92         case BorderImageDirection::RIGHT:
93             return borderImageRight_;
94         default:
95             LOGE("Unsupported border image direction");
96             return borderImageLeft_;
97     }
98 }
99 }