• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 struct KeyFrameConfig {
24     bool enableKeyFrame_ = false;
25     int32_t animationDuration_ = 0;
26     int32_t animationDelay_ = 0;
27 };
28 
29 class ViewportConfig {
30 public:
31     ViewportConfig() = default;
ViewportConfig(int32_t width,int32_t height,float density)32     ViewportConfig(int32_t width, int32_t height, float density)
33         : width_(width), height_(height), density_(density)
34     {}
35     ~ViewportConfig() = default;
36 
SetSize(int32_t width,int32_t height)37     void SetSize(int32_t width, int32_t height)
38     {
39         width_ = width;
40         height_ = height;
41     }
42 
SetPosition(int32_t x,int32_t y)43     void SetPosition(int32_t x, int32_t y)
44     {
45         posX_ = x;
46         posY_ = y;
47     }
48 
Width()49     int32_t Width() const
50     {
51         return width_;
52     }
53 
Height()54     int32_t Height() const
55     {
56         return height_;
57     }
58 
Left()59     int32_t Left() const
60     {
61         return posX_;
62     }
63 
Top()64     int32_t Top() const
65     {
66         return posY_;
67     }
68 
SetDensity(float density)69     void SetDensity(float density)
70     {
71         density_ = density;
72     }
73 
Density()74     float Density() const
75     {
76         return density_;
77     }
78 
SetOrientation(int32_t orientation)79     void SetOrientation(int32_t orientation)
80     {
81         orientation_ = orientation;
82     }
83 
Orientation()84     int32_t Orientation() const
85     {
86         return orientation_;
87     }
88 
SetTransformHint(uint32_t transform)89     void SetTransformHint(uint32_t transform)
90     {
91         transform_ = transform;
92     }
93 
TransformHint()94     uint32_t TransformHint() const
95     {
96         return transform_;
97     }
98 
SetDisplayId(uint64_t displayId)99     void SetDisplayId(uint64_t displayId)
100     {
101         displayId_ = displayId;
102     }
103 
DisplayId()104     uint64_t DisplayId() const
105     {
106         return displayId_;
107     }
108 
109     bool operator==(const ViewportConfig& other) const
110     {
111         return width_ == other.Width() &&
112             height_ == other.Height() &&
113             posX_ == other.Left() &&
114             posY_ == other.Top() &&
115             density_ == other.Density() &&
116             orientation_ == other.Orientation() &&
117             transform_ == other.TransformHint() &&
118             displayId_ == other.DisplayId();
119     }
120 
121     bool operator!=(const ViewportConfig& other) const
122     {
123         return !operator==(other);
124     }
125 
ToString()126     std::string ToString() const
127     {
128         std::string config = "Viewport config:";
129         config.append(" size: (" + std::to_string(width_) + ", " + std::to_string(height_) + ")");
130         config.append(" orientation: " + std::to_string(orientation_));
131         config.append(" density: " + std::to_string(density_));
132         config.append(" position: (" + std::to_string(posX_) + ", " + std::to_string(posY_) + ")");
133         config.append(" transformHint: " + std::to_string(transform_));
134         config.append(" displayId: " + std::to_string(displayId_));
135         return config;
136     }
137 
SetKeyFrameConfig(bool enableKeyFrame,int32_t animationDuration,int32_t animationDelay)138     void SetKeyFrameConfig(bool enableKeyFrame, int32_t animationDuration, int32_t animationDelay)
139     {
140         keyFrameConfig_.enableKeyFrame_ = enableKeyFrame;
141         keyFrameConfig_.animationDuration_ = animationDuration;
142         keyFrameConfig_.animationDelay_ = animationDelay;
143     }
144 
GetKeyFrameConfig()145     KeyFrameConfig GetKeyFrameConfig() const
146     {
147         return keyFrameConfig_;
148     }
149 
150 private:
151     int32_t width_ = 0;
152     int32_t height_ = 0;
153     int32_t posX_ = 0;
154     int32_t posY_ = 0;
155     int32_t orientation_ = 0;
156     float density_ = 1.0f;
157     uint32_t transform_ = 0;
158     uint64_t displayId_ = 0;
159     KeyFrameConfig keyFrameConfig_;
160 };
161 
162 } // namespace OHOS::Ace
163 
164 #endif // FOUNDATION_ACE_INTERFACE_INNERKITS_ACE_VIEWPORT_CONFIG_H
165