1 /*
2 * Copyright (c) 2020-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 "ui_test_anti_aliasing.h"
17 #include "common/screen.h"
18 #include "components/ui_canvas.h"
19 #include "components/ui_circle_progress.h"
20 #include "components/ui_label.h"
21 #include "components/ui_view_group.h"
22
23 namespace OHOS {
SetUp()24 void UITestAntiAliasing::SetUp()
25 {
26 if (container_ == nullptr) {
27 container_ = new UIScrollView();
28 container_->Resize(Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight() - BACK_BUTTON_HEIGHT);
29 container_->SetHorizontalScrollState(false);
30 }
31 }
32
TearDown()33 void UITestAntiAliasing::TearDown()
34 {
35 DeleteChildren(container_);
36 container_ = nullptr;
37 }
38
GetTestView()39 const UIView* UITestAntiAliasing::GetTestView()
40 {
41 UIKitAntiAliasingTestRect001();
42 UIKitAntiAliasingTestCircle001();
43 UIKitAntiAliasingTestLine001();
44 return container_;
45 }
46
CreateTestCaseGroup() const47 UIViewGroup* UITestAntiAliasing::CreateTestCaseGroup() const
48 {
49 UIViewGroup* group = new UIViewGroup();
50 group->Resize(Screen::GetInstance().GetWidth(), 200); // 200: group height
51 return group;
52 }
53
CreateTitleLabel() const54 UILabel* UITestAntiAliasing::CreateTitleLabel() const
55 {
56 UILabel* label = new UILabel();
57 // 2: half of screen width
58 label->SetPosition(TEXT_DISTANCE_TO_LEFT_SIDE, 0, Screen::GetInstance().GetWidth() / 2, TITLE_LABEL_DEFAULT_HEIGHT);
59 label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
60 return label;
61 }
62
UIKitAntiAliasingTestRect001()63 void UITestAntiAliasing::UIKitAntiAliasingTestRect001()
64 {
65 if (container_ == nullptr) {
66 return;
67 }
68
69 UIViewGroup* group = CreateTestCaseGroup();
70 // 2: half of screen width, 110: group height
71 group->Resize(Screen::GetInstance().GetWidth() / 2, 110);
72 group->SetViewId("UIKit_Draw_Rect_Test_Rect_001");
73 group->SetPosition(0, 0);
74
75 UILabel* label = CreateTitleLabel();
76 label->SetText("矩形抗锯齿效果:");
77 label->SetPosition(TEXT_DISTANCE_TO_LEFT_SIDE, TEXT_DISTANCE_TO_TOP_SIDE);
78 group->Add(label);
79
80 UIView* view = new UIView();
81 Style style = view->GetStyleConst();
82 style.bgColor_ = Color::Green();
83 style.bgOpa_ = OPA_OPAQUE;
84 style.borderRadius_ = 5; // 5:border radius
85 style.borderColor_ = Color::Gray();
86 style.borderOpa_ = OPA_OPAQUE;
87 style.borderWidth_ = 3; // 3:border width
88 view->SetStyle(style);
89 view->SetPosition(VIEW_DISTANCE_TO_LEFT_SIDE, VIEW_DISTANCE_TO_TOP_SIDE);
90 view->Resize(120, 50); // 120:new width, 50:new width
91 group->Add(view);
92
93 container_->Add(group);
94 }
95
UIKitAntiAliasingTestCircle001()96 void UITestAntiAliasing::UIKitAntiAliasingTestCircle001()
97 {
98 if (container_ == nullptr) {
99 return;
100 }
101
102 UIViewGroup* group = CreateTestCaseGroup();
103 // 336: x-coordinate
104 group->SetPosition(336, 0);
105 // 2: half of screen width; 180: group height
106 group->Resize(Screen::GetInstance().GetWidth() / 2, 180);
107 group->SetViewId("UIKit_Anti_Aliasing_Test_Circle_001");
108
109 UILabel* label = CreateTitleLabel();
110 label->SetPosition(VIEW_DISTANCE_TO_LEFT_SIDE2, TEXT_DISTANCE_TO_TOP_SIDE);
111 label->SetText("弧形/圆形抗锯齿效果:");
112 group->Add(label);
113
114 UICircleProgress* circleProgress = new UICircleProgress();
115 circleProgress->SetPosition(0, 23, 150, 150); // 23:y-coordinate, 150:new width, 150:new height
116 circleProgress->SetCenterPosition(75, 75); // 75:x-coordinate, 75:y-coordinate
117 circleProgress->SetRadius(50); // 50:outer radius
118 circleProgress->SetValue(20); // 20:current value of progress bar
119 circleProgress->SetLineColor(Color::White());
120 group->Add(circleProgress);
121
122 UICircleProgress* circleProgress1 = new UICircleProgress();
123 circleProgress1->SetPosition(130, 23, 150, 150); // 130:x-coordinate, 23:y-coordinate, 150:new width, 150:new height
124 circleProgress1->SetCenterPosition(75, 75); // 75:x-coordinate, 75:y-coordinate
125 circleProgress1->SetRadius(50); // 50:outer radius
126 circleProgress1->SetValue(100); // 100:current value of progress bar
127 circleProgress1->SetLineColor(Color::White());
128 group->Add(circleProgress1);
129
130 container_->Add(group);
131 }
132
UIKitAntiAliasingTestLine001()133 void UITestAntiAliasing::UIKitAntiAliasingTestLine001()
134 {
135 if (container_ == nullptr) {
136 return;
137 }
138
139 UIViewGroup* group = CreateTestCaseGroup();
140 // 648: x-coordinate
141 group->SetPosition(648, 0);
142 group->Resize(Screen::GetInstance().GetWidth() / 2, 250); // 2: half of screen width; // 250: y-coordinate
143 group->SetViewId("UIKit_Anti_Aliasing_Test_Line_001");
144
145 UILabel* label = CreateTitleLabel();
146 label->SetPosition(VIEW_DISTANCE_TO_LEFT_SIDE2, TEXT_DISTANCE_TO_TOP_SIDE);
147 label->SetText("直线抗锯齿效果:");
148 group->Add(label);
149
150 UICanvas* canvas = new UICanvas();
151 canvas->SetHeight(200); // 200:height
152 canvas->SetWidth(200); // 200:width
153 canvas->SetPosition(VIEW_DISTANCE_TO_LEFT_SIDE2, VIEW_DISTANCE_TO_TOP_SIDE);
154 canvas->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full);
155 Paint paint;
156 // 0:start point x-coordinate, 50:start point y-coordinate, 150:end point x-coordinate, 150:end point y-coordinate
157 canvas->DrawLine({0, 50}, {150, 50}, paint);
158 // 0:start point x-coordinate, 50:start point y-coordinate, 150:end point x-coordinate, 150:end point y-coordinate
159 canvas->DrawLine({0, 50}, {150, 100}, paint);
160 // 0:start point x-coordinate, 50:start point y-coordinate, 150:end point x-coordinate, 150:end point y-coordinate
161 canvas->DrawLine({0, 50}, {150, 200}, paint);
162 // 0:start point x-coordinate, 50:start point y-coordinate, 150:end point x-coordinate, 150:end point y-coordinate
163 canvas->DrawLine({0, 50}, {100, 200}, paint);
164 group->Add(canvas);
165 container_->Add(group);
166 }
167 } // namespace OHOS
168