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 #include "bridge/declarative_frontend/jsview/js_matrix2d.h"
17 #include "bridge/declarative_frontend/jsview/js_rendering_context.h"
18 #include "bridge/declarative_frontend/jsview/js_view_common_def.h"
19
20 namespace OHOS::Ace::Framework {
21
JSMatrix2d()22 JSMatrix2d::JSMatrix2d()
23 {
24 }
25
Constructor(const JSCallbackInfo & args)26 void JSMatrix2d::Constructor(const JSCallbackInfo& args)
27 {
28 auto jsCalendarController = Referenced::MakeRefPtr<JSMatrix2d>();
29 jsCalendarController->IncRefCount();
30 args.SetReturnValue(Referenced::RawPtr(jsCalendarController));
31 }
32
Destructor(JSMatrix2d * controller)33 void JSMatrix2d::Destructor(JSMatrix2d* controller)
34 {
35 if (controller != nullptr) {
36 controller->DecRefCount();
37 }
38 }
39
JSBind(BindingTarget globalObj)40 void JSMatrix2d::JSBind(BindingTarget globalObj)
41 {
42 JSClass<JSMatrix2d>::Declare("Matrix2D");
43 JSClass<JSMatrix2d>::CustomMethod("scaleX", &JSMatrix2d::JsSetScaleX);
44 JSClass<JSMatrix2d>::CustomMethod("rotateY", &JSMatrix2d::JsSetRotateY);
45 JSClass<JSMatrix2d>::CustomMethod("rotateX", &JSMatrix2d::JsSetRotateX);
46 JSClass<JSMatrix2d>::CustomMethod("scaleY", &JSMatrix2d::JsSetScaleY);
47 JSClass<JSMatrix2d>::CustomMethod("translateX", &JSMatrix2d::JsSetTranslateX);
48 JSClass<JSMatrix2d>::CustomMethod("translateY", &JSMatrix2d::JsSetTranslateY);
49
50 JSClass<JSMatrix2d>::Bind(globalObj, JSMatrix2d::Constructor, JSMatrix2d::Destructor);
51 }
52
JsSetScaleX(const JSCallbackInfo & info)53 void JSMatrix2d::JsSetScaleX(const JSCallbackInfo& info)
54 {
55 double scaleX;
56 if (info[0]->IsNumber()) {
57 JSViewAbstract::ParseJsDouble(info[0], scaleX);
58 scaleX_ = scaleX;
59 }
60 }
61
JsSetRotateY(const JSCallbackInfo & info)62 void JSMatrix2d::JsSetRotateY(const JSCallbackInfo& info)
63 {
64 double rotateY;
65 if (info[0]->IsNumber()) {
66 JSViewAbstract::ParseJsDouble(info[0], rotateY);
67 rotateY_ = rotateY;
68 }
69 }
70
JsSetRotateX(const JSCallbackInfo & info)71 void JSMatrix2d::JsSetRotateX(const JSCallbackInfo& info)
72 {
73 double rotateX;
74 if (info[0]->IsNumber()) {
75 JSViewAbstract::ParseJsDouble(info[0], rotateX);
76 rotateX_ = rotateX;
77 }
78 }
79
JsSetScaleY(const JSCallbackInfo & info)80 void JSMatrix2d::JsSetScaleY(const JSCallbackInfo& info)
81 {
82 double scaleY;
83 if (info[0]->IsNumber()) {
84 JSViewAbstract::ParseJsDouble(info[0], scaleY);
85 scaleY_ = scaleY;
86 }
87 }
88
JsSetTranslateX(const JSCallbackInfo & info)89 void JSMatrix2d::JsSetTranslateX(const JSCallbackInfo& info)
90 {
91 double translateX;
92 if (info[0]->IsNumber()) {
93 JSViewAbstract::ParseJsDouble(info[0], translateX);
94 translateX = SystemProperties::Vp2Px(translateX);
95 translateX_ = translateX;
96 }
97 }
98
JsSetTranslateY(const JSCallbackInfo & info)99 void JSMatrix2d::JsSetTranslateY(const JSCallbackInfo& info)
100 {
101 double translateY;
102 if (info[0]->IsNumber()) {
103 JSViewAbstract::ParseJsDouble(info[0], translateY);
104 translateY = SystemProperties::Vp2Px(translateY);
105 translateY_ = translateY;
106 }
107 }
108
JsGetScaleX()109 double JSMatrix2d::JsGetScaleX()
110 {
111 return scaleX_;
112 }
113
JsGetRotateY()114 double JSMatrix2d::JsGetRotateY()
115 {
116 return rotateY_;
117 }
118
JsGetRotateX()119 double JSMatrix2d::JsGetRotateX()
120 {
121 return rotateX_;
122 }
123
JsGetScaleY()124 double JSMatrix2d::JsGetScaleY()
125 {
126 return scaleY_;
127 }
128
JsGetTranslateX()129 double JSMatrix2d::JsGetTranslateX()
130 {
131 return translateX_;
132 }
133
JsGetTranslateY()134 double JSMatrix2d::JsGetTranslateY()
135 {
136 return translateY_;
137 }
138
139 } // namespace OHOS::Ace::Framework