-
-
Notifications
You must be signed in to change notification settings - Fork 311
Expand file tree
/
Copy pathqpointf_wrap.cpp
More file actions
118 lines (101 loc) · 4.13 KB
/
qpointf_wrap.cpp
File metadata and controls
118 lines (101 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "QtCore/QPointF/qpointf_wrap.h"
#include "Extras/Utils/nutils.h"
#include "QtCore/QPoint/qpoint_wrap.h"
Napi::FunctionReference QPointFWrap::constructor;
Napi::Object QPointFWrap::init(Napi::Env env, Napi::Object exports) {
Napi::HandleScope scope(env);
char CLASSNAME[] = "QPointF";
Napi::Function func = DefineClass(
env, CLASSNAME,
{// Methods inherited from QDropEvent
InstanceMethod("isNull", &QPointFWrap::isNull),
InstanceMethod("manhattanLength", &QPointFWrap::manhattanLength),
InstanceMethod("setX", &QPointFWrap::setX),
InstanceMethod("setY", &QPointFWrap::setY),
InstanceMethod("toPoint", &QPointFWrap::toPoint),
InstanceMethod("transposed", &QPointFWrap::transposed),
InstanceMethod("x", &QPointFWrap::x),
InstanceMethod("y", &QPointFWrap::y),
StaticMethod("dotProduct", &StaticQPointFWrapMethods::dotProduct),
COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE(QPointFWrap)});
constructor = Napi::Persistent(func);
exports.Set(CLASSNAME, func);
return exports;
}
QPointFWrap::~QPointFWrap() { this->instance.reset(); }
QPointF* QPointFWrap::getInternalInstance() { return this->instance.get(); }
QPointFWrap::QPointFWrap(const Napi::CallbackInfo& info)
: Napi::ObjectWrap<QPointFWrap>(info) {
Napi::Env env = info.Env();
if (info.Length() == 2) {
qreal xpos = info[0].As<Napi::Number>().DoubleValue();
qreal ypos = info[1].As<Napi::Number>().DoubleValue();
this->instance = std::make_unique<QPointF>(xpos, ypos);
} else if (info.Length() == 1) {
this->instance =
std::unique_ptr<QPointF>(info[0].As<Napi::External<QPointF>>().Data());
} else if (info.Length() == 0) {
this->instance = std::make_unique<QPointF>();
} else {
Napi::TypeError::New(env, "Wrong number of arguments")
.ThrowAsJavaScriptException();
}
this->rawData = extrautils::configureComponent(this->getInternalInstance());
}
// Instance Methods Here
Napi::Value StaticQPointFWrapMethods::dotProduct(
const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::Object wrap0_0 = info[0].As<Napi::Object>();
QPointFWrap* wrap0_1 = Napi::ObjectWrap<QPointFWrap>::Unwrap(wrap0_0);
QPointF* input0 = wrap0_1->getInternalInstance();
Napi::Object wrap1_0 = info[1].As<Napi::Object>();
QPointFWrap* wrap1_1 = Napi::ObjectWrap<QPointFWrap>::Unwrap(wrap1_0);
QPointF* input1 = wrap1_1->getInternalInstance();
return Napi::Number::New(env, QPointF::dotProduct(*input0, *input1));
}
Napi::Value QPointFWrap::isNull(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
return Napi::Boolean::New(env, this->instance->isNull());
}
Napi::Value QPointFWrap::manhattanLength(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
return Napi::Number::New(env, this->instance->manhattanLength());
}
Napi::Value QPointFWrap::setX(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
qreal input0 = info[0].As<Napi::Number>().DoubleValue();
this->instance->setX(input0);
return env.Null();
}
Napi::Value QPointFWrap::setY(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
qreal input0 = info[0].As<Napi::Number>().DoubleValue();
this->instance->setY(input0);
return env.Null();
}
Napi::Value QPointFWrap::toPoint(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
QPoint ret = this->instance->toPoint();
auto instance = QPointWrap::constructor.New(
{Napi::External<QPoint>::New(env, new QPoint(ret))});
return instance;
}
Napi::Value QPointFWrap::transposed(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
QPointF ret = this->instance->transposed();
auto instance = QPointFWrap::constructor.New(
{Napi::External<QPointF>::New(env, new QPointF(ret))});
return instance;
}
Napi::Value QPointFWrap::x(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
return Napi::Number::New(env, this->instance->x());
}
Napi::Value QPointFWrap::y(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
return Napi::Number::New(env, this->instance->y());
}