• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef UI_TEST_TRANSFORM_H
17 #define UI_TEST_TRANSFORM_H
18 
19 #include "components/ui_image_view.h"
20 #include "components/ui_label.h"
21 #include "components/ui_label_button.h"
22 #include "components/ui_scroll_view.h"
23 #include "components/ui_checkbox.h"
24 #include "components/ui_radio_button.h"
25 #include "layout/grid_layout.h"
26 #include "ui_test.h"
27 
28 namespace OHOS {
29 enum ImageScaleMode {
30     AUTO,
31     TILING,
32     COVER,
33     CONTAIN,
34     FILL,
35     CENTER,
36     SCALE_DOWN,
37 };
38 
39 class UITestTransform : public UITest, public UIView::OnClickListener {
40 public:
UITestTransform()41     UITestTransform() {}
~UITestTransform()42     ~UITestTransform() {}
43     void SetUp() override;
44     void TearDown() override;
45     const UIView* GetTestView() override;
46 
47     void SetUpButton(UILabelButton* btn, const char* title);
48 
49     bool OnClick(UIView& view, const ClickEvent& event) override;
50 
51     void UIKit_Transform_Test_Rotate_001();
52     void UIKit_Transform_Test_Scale_002();
53     void UIKit_Transform_Test_Translate_003();
54 
55     void SetScaleMode(ImageScaleMode mode);
56 private:
57     void AddRadioGroup();
58     UILabel* AddLable(int16_t x, int16_t y, const char* data);
59     UIRadioButton* AddRadioButton(Rect rect, const char* name, UICheckBox::OnChangeListener* listener);
GetRect(int16_t x,int16_t y,int16_t w,int16_t h)60     Rect GetRect(int16_t x, int16_t y, int16_t w, int16_t h) const
61     {
62         return Rect(x, y, x + w - 1, y + h - 1);
63     }
64     void SetTransMap(int16_t angle, float scale, int16_t trans, Vector2<float> pivot);
65 
66     UIScrollView* container_ = nullptr;
67     GridLayout* layout_ = nullptr;
68     UIImageView* imageView_ = nullptr;
69     UIViewGroup* uiViewGroupFrame_ = nullptr;
70 
71     UILabelButton* rotateBtn_ = nullptr;
72     UILabelButton* scaleBtn_ = nullptr;
73     UILabelButton* translateBtn_ = nullptr;
74     int16_t angle_ = 0;
75     float scale_ = 1.0;
76     int16_t trans_ = 0;
77 };
78 
79 class StateChangeListener : public UICheckBox::OnChangeListener {
80 public:
81     explicit StateChangeListener(ImageScaleMode mode, UITestTransform* testInstance);
~StateChangeListener()82     ~StateChangeListener() {}
83     bool OnChange(UICheckBox::UICheckBoxState state) override;
84 private:
85     ImageScaleMode mode_ = ImageScaleMode::AUTO;
86     UITestTransform* testInstance_ = nullptr;
87 };
88 
89 class UITestRadioButton : public UIRadioButton {
90 public:
91     explicit UITestRadioButton(const char* name);
92     ~UITestRadioButton();
93     void SetListener(UICheckBox::OnChangeListener* listener);
94 private:
95     UICheckBox::OnChangeListener* listener_ = nullptr;
96 };
97 } // namespace OHOS
98 #endif // UI_TEST_TRANSFORM_H
99