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_view_scale_rotate.h"
17 #include "common/screen.h"
18 #include "components/ui_label.h"
19 #include "core/render_manager.h"
20 #include "test_resource_config.h"
21 
22 namespace OHOS {
SetUp()23 void UITestViewScaleRotate::SetUp()
24 {
25     if (container_ == nullptr) {
26         container_ = new UIScrollView();
27         container_->Resize(Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight() - BACK_BUTTON_HEIGHT);
28     }
29 
30     if (list_ == nullptr) {
31         list_ = new ListLayout(UISwipeView::VERTICAL);
32         uint16_t width = Screen::GetInstance().GetWidth();
33         uint16_t height = Screen::GetInstance().GetHeight();
34         list_->SetPosition(VIEW_DISTANCE_TO_LEFT_SIDE, 0, width, height + 1);
35         container_->Add(list_);
36     }
37 }
38 
TearDown()39 void UITestViewScaleRotate::TearDown()
40 {
41     animator_.Stop();
42     DeleteChildren(container_);
43     container_ = nullptr;
44     list_ = nullptr;
45 }
46 
GetTestView()47 const UIView* UITestViewScaleRotate::GetTestView()
48 {
49     UIKitViewScaleRotateTestLabel001();
50     UIKitViewScaleRotateTestLabelButton002();
51     UIKitViewScaleRotateTestCanvas003();
52     UIKitViewScaleRotateTestUIBoxProgress004();
53     UIKitViewScaleRotateTestUICircleProgress005();
54     UIKitViewScaleRotateTestUIDigitalClock006();
55     UIKitViewScaleRotateTestGroup007();
56 
57     animator_.Start();
58     return container_;
59 }
60 
Callback(UIView * view)61 void UITestViewScaleRotate::Callback(UIView* view)
62 {
63     angleValue_++;
64 
65     if (scaleValue_.x_ < 0.2f) {
66         scaleStep_ = 0.01f;
67     } else if (scaleValue_.x_ > 1.5f) {
68         scaleStep_ = -0.01f;
69     }
70     scaleValue_.x_ += scaleStep_;
71     scaleValue_.y_ += scaleStep_;
72 
73     button1_->Rotate(angleValue_, VIEW_CENTER);
74     button1_->Scale(scaleValue_, VIEW_CENTER);
75     group1_->Rotate(angleValue_, GROUP_CENTER);
76     group1_->Scale(scaleValue_, GROUP_CENTER);
77     canvas_->Rotate(angleValue_, GROUP_CENTER);
78     canvas_->Scale(scaleValue_, GROUP_CENTER);
79     boxProgress_->Rotate(angleValue_, VIEW_CENTER);
80     boxProgress_->Scale(scaleValue_, VIEW_CENTER);
81     circleProgress_->Rotate(angleValue_, VIEW_CENTER);
82     circleProgress_->Scale(scaleValue_, VIEW_CENTER);
83     dClock_->Rotate(angleValue_, VIEW_CENTER);
84     dClock_->Scale(scaleValue_, VIEW_CENTER);
85     label_->Rotate(angleValue_, VIEW_CENTER);
86     label_->Scale(scaleValue_, VIEW_CENTER);
87 }
88 
SetUpLabel(const char * title) const89 void UITestViewScaleRotate::SetUpLabel(const char* title) const
90 {
91     UILabel* label = new UILabel();
92     label->SetPosition(TEXT_DISTANCE_TO_LEFT_SIDE, TEXT_DISTANCE_TO_TOP_SIDE,
93         Screen::GetInstance().GetWidth(), TITLE_LABEL_DEFAULT_HEIGHT);
94     label->SetText(title);
95     label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
96     list_->Add(label);
97 }
98 
UIKitViewScaleRotateTestLabel001()99 void UITestViewScaleRotate::UIKitViewScaleRotateTestLabel001()
100 {
101     SetUpLabel("UILabel组件旋转 ");
102     UIViewGroup* group = new UIViewGroup();
103     group->SetPosition(0, 0, GROUP_WIDHT, GROUP_HEIGHT);
104     label_ = new UILabel();
105     label_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
106     label_->SetText("Test UILabel");
107     label_->SetPosition(100, 100, 200, 50); // 100: x 100: y 200: width 50: height
108     group->Add(label_);
109     list_->Add(group);
110 }
111 
UIKitViewScaleRotateTestLabelButton002()112 void UITestViewScaleRotate::UIKitViewScaleRotateTestLabelButton002()
113 {
114     SetUpLabel("UILabelButton组件旋转 ");
115     UIViewGroup* group = new UIViewGroup();
116     group->SetPosition(0, 0, GROUP_WIDHT, GROUP_HEIGHT);
117     list_->Add(group);
118     button1_ = new UILabelButton();
119     button1_->SetPosition(100, 100, 200, 50); // 100: x 100: y 200: width 50: height
120     button1_->SetText("Test UILabelButton");
121     group->Add(button1_);
122 }
123 
UIKitViewScaleRotateTestCanvas003()124 void UITestViewScaleRotate::UIKitViewScaleRotateTestCanvas003()
125 {
126     SetUpLabel("UICanvas组件旋转 ");
127     UIViewGroup* group = new UIViewGroup();
128     group->SetPosition(0, 0, GROUP_WIDHT, GROUP_HEIGHT);
129     list_->Add(group);
130     canvas_ = new UICanvas();
131     group->Add(canvas_);
132 
133     canvas_->SetPosition(0, 0, GROUP_WIDHT, GROUP_HEIGHT);
134     canvas_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full);
135 
136     Paint paint;
137     paint.SetStrokeWidth(20); // 20: StrokeWidth
138     canvas_->DrawLine({150, 150}, {300, 300}, paint); // 150: x 150: y 300: x 300: y
139 
140     paint.SetStrokeColor(Color::Red());
141     canvas_->DrawCurve({100, 50}, {150, 50}, {150, 50}, {150, 100}, paint);
142     canvas_->DrawRect({10, 10}, 50, 50, paint); // 10: x 10: y 50: width 50: height
143 }
144 
UIKitViewScaleRotateTestUIBoxProgress004()145 void UITestViewScaleRotate::UIKitViewScaleRotateTestUIBoxProgress004()
146 {
147     SetUpLabel("UIBoxProgress组件旋转 ");
148     UIViewGroup* group = new UIViewGroup();
149     group->SetPosition(0, 0, GROUP_WIDHT, GROUP_HEIGHT);
150     list_->Add(group);
151 
152     boxProgress_ = new UIBoxProgress();
153     boxProgress_->EnableBackground(true);
154     boxProgress_->SetPosition(100, 100, 200, 50); // 100: x 100:y 200:width 50: height
155     boxProgress_->SetValue(80); // 80: value
156     boxProgress_->SetBackgroundStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
157     boxProgress_->SetBackgroundStyle(STYLE_BACKGROUND_COLOR, Color::Red().full);
158     group->Add(boxProgress_);
159 }
160 
UIKitViewScaleRotateTestUICircleProgress005()161 void UITestViewScaleRotate::UIKitViewScaleRotateTestUICircleProgress005()
162 {
163     SetUpLabel("UICircleProgress组件旋转 ");
164     UIViewGroup* group = new UIViewGroup();
165     group->SetPosition(0, 0, GROUP_WIDHT, GROUP_HEIGHT);
166     list_->Add(group);
167     circleProgress_ = new UICircleProgress();
168     circleProgress_->SetPosition(10, 10, 150, 150); // 10: x 10: y 150: width 150: height
169     circleProgress_->SetCenterPosition(75, 75);     // 75: position x 75: position y
170     circleProgress_->SetRadius(50);                 // 50: radius
171     circleProgress_->SetValue(20);                  // 20: value
172     circleProgress_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
173     circleProgress_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Yellow().full);
174     group->Add(circleProgress_);
175 }
UIKitViewScaleRotateTestUIDigitalClock006()176 void UITestViewScaleRotate::UIKitViewScaleRotateTestUIDigitalClock006()
177 {
178     SetUpLabel("UIDigitalClock组件旋转 ");
179     UIViewGroup* group = new UIViewGroup();
180     group->SetPosition(0, 0, GROUP_WIDHT, GROUP_HEIGHT);
181     list_->Add(group);
182     dClock_ = new UIDigitalClock();
183     dClock_->SetPosition(10, 10, 150, 150);             // 10: x 10:y 150: width 150: height
184     dClock_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); // 30: font size
185     dClock_->SetTime24Hour(7, 25, 50);                  // 7: hour, 25: minute, 50: second
186     group->Add(dClock_);
187 }
188 
UIKitViewScaleRotateTestGroup007()189 void UITestViewScaleRotate::UIKitViewScaleRotateTestGroup007()
190 {
191     SetUpLabel("UIViewGroup组件旋转 ");
192     UIViewGroup* group = new UIViewGroup();
193     group->SetPosition(0, 0, GROUP_WIDHT, GROUP_HEIGHT);
194     list_->Add(group);
195 
196     group1_ = new UIViewGroup();
197     group1_->SetPosition(0, 0, GROUP_WIDHT, GROUP_HEIGHT);
198     group1_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
199     group1_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Yellow().full);
200     group->Add(group1_);
201 
202     UISlider* slider = new UISlider();
203     slider->SetPosition(10, 10, 200, 50); // 10: x 10: y 200: width 50: height
204     slider->SetValue(50); // 50: value
205     slider->SetDirection(UISlider::Direction::DIR_LEFT_TO_RIGHT);
206     group1_->Add(slider);
207 
208     UILabelButton* button = new UILabelButton();
209     button->SetPosition(10, 100, 200, 50); // 10: x 100:y 200: width 50: height
210     button->SetText("test ViewGroup");
211     group1_->Add(button);
212 }
213 } // namespace OHOS
214