• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 FRAMEWORKS_BRIDGE_CJ_FRONTEND_CPP_VIEW_MATRIX2D_H
17 #define FRAMEWORKS_BRIDGE_CJ_FRONTEND_CPP_VIEW_MATRIX2D_H
18 
19 #include "ffi_remote_data.h"
20 
21 #include "base/memory/referenced.h"
22 #include "core/components/common/properties/decoration.h"
23 #include "frameworks/core/components/common/properties/paint_state.h"
24 
25 namespace OHOS::Ace::Framework {
26 
27 class ACE_EXPORT NativeMatrix2d : public OHOS::FFI::FFIData, public Referenced {
28 public:
29     NativeMatrix2d();
30     explicit NativeMatrix2d(const int32_t unit);
31     ~NativeMatrix2d() override;
32     void Identity();
33     void Invert();
34     void Rotate(double degree, double rx, double ry);
35     void Translate(double tx, double ty);
36     void Scale(double sx, double sy);
37 
GetScaleX()38     double GetScaleX() const
39     {
40         return transform_.scaleX;
41     }
42 
GetRotateY()43     double GetRotateY() const
44     {
45         return transform_.skewY;
46     }
47 
GetRotateX()48     double GetRotateX() const
49     {
50         return transform_.skewX;
51     }
52 
GetScaleY()53     double GetScaleY() const
54     {
55         return transform_.scaleY;
56     }
57 
GetTranslateX()58     double GetTranslateX()
59     {
60         double density = Positive(GetDensity()) ? GetDensity() : 1;
61         return transform_.translateX / density;
62     }
63 
GetTranslateY()64     double GetTranslateY()
65     {
66         double density = Positive(GetDensity()) ? GetDensity() : 1;
67         return transform_.translateY / density;
68     }
69 
SetScaleX(double value)70     void SetScaleX(double value)
71     {
72         transform_.scaleX = value;
73     }
74 
SetScaleY(double value)75     void SetScaleY(double value)
76     {
77         transform_.scaleY = value;
78     }
79 
SetRotateX(double value)80     void SetRotateX(double value)
81     {
82         transform_.skewX = value;
83     }
84 
SetRotateY(double value)85     void SetRotateY(double value)
86     {
87         transform_.skewY = value;
88     }
89 
SetTranslateX(double value)90     void SetTranslateX(double value)
91     {
92         double density = GetDensity();
93         transform_.translateX = value * density;
94     }
95 
SetTranslateY(double value)96     void SetTranslateY(double value)
97     {
98         double density = GetDensity();
99         transform_.translateY = value * density;
100     }
101 
GetTransform()102     TransformParam GetTransform() const
103     {
104         return transform_;
105     }
106 
SetTransform(const TransformParam & param)107     void SetTransform(const TransformParam& param)
108     {
109         transform_ = param;
110     }
111 
GetUnit()112     CanvasUnit GetUnit()
113     {
114         return unit_;
115     }
116 
117     double GetDensity();
118 
119 private:
120     TransformParam transform_;
121     CanvasUnit unit_ = CanvasUnit::DEFAULT;
122 };
123 
124 } // namespace OHOS::Ace::Framework
125 #endif // FRAMEWORKS_BRIDGE_CJ_FRONTEND_CPP_VIEW_MATRIX2D_H