1 /* 2 * Copyright (c) 2021-2022 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_INTERFACE_INNERKITS_ACE_VIEWPORT_CONFIG_H 17 #define FOUNDATION_ACE_INTERFACE_INNERKITS_ACE_VIEWPORT_CONFIG_H 18 19 #include <string> 20 21 namespace OHOS::Ace { 22 23 class ViewportConfig { 24 public: 25 ViewportConfig() = default; ViewportConfig(int32_t width,int32_t height,float density)26 ViewportConfig(int32_t width, int32_t height, float density) 27 : width_(width), height_(height), density_(density) 28 {} 29 ~ViewportConfig() = default; 30 SetSize(int32_t width,int32_t height)31 void SetSize(int32_t width, int32_t height) 32 { 33 width_ = width; 34 height_ = height; 35 } 36 SetPosition(int32_t x,int32_t y)37 void SetPosition(int32_t x, int32_t y) 38 { 39 posX_ = x; 40 posY_ = y; 41 } 42 Width()43 int32_t Width() const 44 { 45 return width_; 46 } 47 Height()48 int32_t Height() const 49 { 50 return height_; 51 } 52 Left()53 int32_t Left() const 54 { 55 return posX_; 56 } 57 Top()58 int32_t Top() const 59 { 60 return posY_; 61 } 62 SetDensity(float density)63 void SetDensity(float density) 64 { 65 density_ = density; 66 } 67 Density()68 float Density() const 69 { 70 return density_; 71 } 72 SetOrientation(int32_t orientation)73 void SetOrientation(int32_t orientation) 74 { 75 orientation_ = orientation; 76 } 77 Orientation()78 int32_t Orientation() const 79 { 80 return orientation_; 81 } 82 SetTransformHint(uint32_t transform)83 void SetTransformHint(uint32_t transform) 84 { 85 transform_ = transform; 86 } 87 TransformHint()88 uint32_t TransformHint() const 89 { 90 return transform_; 91 } 92 93 bool operator==(const ViewportConfig& other) const 94 { 95 return width_ == other.Width() && 96 height_ == other.Height() && 97 posX_ == other.Left() && 98 posY_ == other.Top() && 99 density_ == other.Density() && 100 orientation_ == other.Orientation() && 101 transform_ == other.TransformHint(); 102 } 103 104 bool operator!=(const ViewportConfig& other) const 105 { 106 return !operator==(other); 107 } 108 ToString()109 std::string ToString() const 110 { 111 std::string config = "Viewport config:"; 112 config.append(" size: (" + std::to_string(width_) + ", " + std::to_string(height_) + ")"); 113 config.append(" orientation: " + std::to_string(orientation_)); 114 config.append(" density: " + std::to_string(density_)); 115 config.append(" position: (" + std::to_string(posX_) + ", " + std::to_string(posY_) + ")"); 116 config.append(" transformHint: " + std::to_string(transform_)); 117 return config; 118 } 119 120 private: 121 int32_t width_ = 0; 122 int32_t height_ = 0; 123 int32_t posX_ = 0; 124 int32_t posY_ = 0; 125 int32_t orientation_ = 0; 126 float density_ = 1.0f; 127 uint32_t transform_ = 0; 128 }; 129 130 } // namespace OHOS::Ace 131 132 #endif // FOUNDATION_ACE_INTERFACE_INNERKITS_ACE_VIEWPORT_CONFIG_H 133