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 constexpr char* UI_TEST_ROTATE = "rotate"; 40 constexpr char* UI_TEST_ZOOM = "zoom"; 41 constexpr char* UI_TEST_TRANSLATION = "translation"; 42 constexpr char* UI_TEST_AUTO = "auto"; 43 constexpr char* UI_TEST_TILING = "tiling"; 44 constexpr char* UI_TEST_COVER = "cover"; 45 constexpr char* UI_TEST_CONTAIN = "contain"; 46 constexpr char* UI_TEST_FILL = "fill"; 47 constexpr char* UI_TEST_CENTER = "center"; 48 constexpr char* UI_TEST_SCALE_DOWN = "scale_down"; 49 50 class UITestTransform : public UITest, public UIView::OnClickListener { 51 public: UITestTransform()52 UITestTransform() {} ~UITestTransform()53 ~UITestTransform() {} 54 void SetUp() override; 55 void TearDown() override; 56 const UIView* GetTestView() override; 57 58 void SetUpButton(UILabelButton* btn, const char* title, const char* id); 59 60 bool OnClick(UIView& view, const ClickEvent& event) override; 61 62 void UIKitTransformTestRotate001(); 63 void UIKitTransformTestScale002(); 64 void UIKitTransformTestTranslate003(); 65 66 void SetScaleMode(ImageScaleMode mode); 67 68 private: 69 void AddRadioGroup(); 70 UILabel* AddLable(int16_t x, int16_t y, const char* data); 71 UIRadioButton* AddRadioButton(Rect rect, const char* name, 72 UICheckBox::OnChangeListener* listener, const char* id); GetRect(int16_t x,int16_t y,int16_t w,int16_t h)73 Rect GetRect(int16_t x, int16_t y, int16_t w, int16_t h) const 74 { 75 return Rect(x, y, x + w - 1, y + h - 1); 76 } 77 void SetTransMap(int16_t angle, float scale, int16_t trans, Vector2<float> pivot); 78 79 UIScrollView* container_ = nullptr; 80 GridLayout* layout_ = nullptr; 81 UIImageView* imageView_ = nullptr; 82 UIViewGroup* uiViewGroupFrame_ = nullptr; 83 84 UILabelButton* rotateBtn_ = nullptr; 85 UILabelButton* scaleBtn_ = nullptr; 86 UILabelButton* translateBtn_ = nullptr; 87 int16_t angle_ = 0; 88 float scale_ = 1.0; 89 int16_t trans_ = 0; 90 }; 91 92 class StateChangeListener : public UICheckBox::OnChangeListener { 93 public: 94 explicit StateChangeListener(ImageScaleMode mode, UITestTransform* testInstance); ~StateChangeListener()95 ~StateChangeListener() {} 96 bool OnChange(UICheckBox::UICheckBoxState state) override; 97 private: 98 ImageScaleMode mode_ = ImageScaleMode::AUTO; 99 UITestTransform* testInstance_ = nullptr; 100 }; 101 102 class UITestRadioButton : public UIRadioButton { 103 public: 104 explicit UITestRadioButton(const char* name); 105 ~UITestRadioButton(); 106 void SetListener(UICheckBox::OnChangeListener* listener); 107 private: 108 UICheckBox::OnChangeListener* listener_ = nullptr; 109 }; 110 } // namespace OHOS 111 #endif // UI_TEST_TRANSFORM_H 112