1 /*
2  * Copyright (c) 2022-2023 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MOCK_ROSEN_TEST_TESTING_ROUND_RECT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MOCK_ROSEN_TEST_TESTING_ROUND_RECT_H
18 
19 #include <vector>
20 
21 #include "testing_point.h"
22 #include "testing_rect.h"
23 
24 namespace OHOS::Ace::Testing {
25 class TestingRoundRect {
26 public:
27     enum CornerPos {
28         TOP_LEFT_POS,
29         TOP_RIGHT_POS,
30         BOTTOM_RIGHT_POS,
31         BOTTOM_LEFT_POS,
32         CORNER_NUMBER,
33     };
34 
TestingRoundRect()35     TestingRoundRect()
36         : radiusXY_(CORNER_NUMBER, TestingPoint(0, 0)) {};
37     virtual ~TestingRoundRect() = default;
38 
TestingRoundRect(const TestingRoundRect & testingRoundRect)39     TestingRoundRect(const TestingRoundRect& testingRoundRect) : TestingRoundRect()
40     {
41         rect_ = testingRoundRect.rect_;
42     }
43 
TestingRoundRect(const TestingRect & rect,float xRad,float yRad)44     TestingRoundRect(const TestingRect& rect, float xRad, float yRad) : TestingRoundRect()
45     {
46         rect_ = rect;
47         for (size_t i = 0; i < radiusXY_.size(); ++i) {
48             radiusXY_[i].SetX(xRad);
49             radiusXY_[i].SetY(yRad);
50         }
51     }
52 
TestingRoundRect(const TestingRect & rect,std::vector<TestingPoint> & radiusXY)53     TestingRoundRect(const TestingRect& rect, std::vector<TestingPoint>& radiusXY) : TestingRoundRect()
54     {
55         rect_ = rect;
56         for (size_t i = 0; i < radiusXY_.size(); ++i) {
57             radiusXY_[i] = radiusXY[i];
58         }
59     }
60 
SetCornerRadius(CornerPos pos,float radiusX,float radiusY)61     virtual void SetCornerRadius(CornerPos pos, float radiusX, float radiusY)
62     {
63         radiusXY_[pos].SetX(radiusX);
64         radiusXY_[pos].SetY(radiusY);
65     }
66 
GetCornerRadius(CornerPos pos)67     virtual TestingPoint GetCornerRadius(CornerPos pos) const
68     {
69         return radiusXY_[pos];
70     }
71 
SetRect(const TestingRect & rect)72     virtual void SetRect(const TestingRect& rect)
73     {
74         rect_ = rect;
75     }
76 
GetRect()77     virtual TestingRect GetRect() const
78     {
79         return rect_;
80     }
81 
Offset(float dx,float dy)82     virtual void Offset(float dx, float dy)
83     {
84         rect_.Offset(dx, dy);
85     }
86 
87 private:
88     TestingRect rect_;
89     std::vector<TestingPoint> radiusXY_;
90 };
91 } // namespace OHOS::Ace::Testing
92 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MOCK_ROSEN_TEST_TESTING_ROUND_RECT_H
93