-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.d.ts
258 lines (216 loc) · 7.21 KB
/
index.d.ts
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
declare module "qml-raub" {
type TSize = Readonly<{ width: number; height: number }>;
type TEvent = {
type: string;
[key: string]: unknown;
};
type TMouseEventCommon = TEvent & Readonly<{
buttons: number[],
x: number,
y: number,
}>;
type TMouseEventPress = TMouseEventCommon & Readonly<{
button: number,
}>;
type TMouseEventWheel = TMouseEventCommon & Readonly<{
wheelDelta: number,
}>;
type TKeyEvent = TEvent & Readonly<{
which: number,
charCode: number,
}>;
type EventEmitter = import('node:events').EventEmitter;
export type TOptsView = Readonly<Partial<{
/** Texture width. Default is 512. */
width: number;
/** Texture height. Default is 512. */
height: number;
/** Suppress error messages from QML runtime. */
silent: boolean;
/** If passed, this QML file starts loading immediately. */
file: string;
}>>;
export type TOptsLoad = Readonly<{ file: string }> | Readonly<{ source: string }>;
/**
* View
*
* Loads and manages a QML file.
*
* @note Make sure to always switch back to your own OpenGL context before drawing.
*/
export class View implements EventEmitter {
constructor(opts?: TOptsView);
/**
* Width in pixels.
*/
width: number;
/**
* Height in pixels.
*/
height: number;
/** Alias for width. */
w: number;
/** Alias for height. */
h: number;
/** An Array, containing width and height. */
wh: [number, number];
/** An Object, containing width and height. */
size: TSize;
/** Is the requested QML file loaded? */
readonly isLoaded: boolean;
/** OpenGL texture ID for QML scene RTT resource. */
readonly textureId: number;
/** Stringification helper. */
toString(): string;
/** Send "mousedown" event into the QML scene. */
mousedown(e: TMouseEventPress): void;
/** Send "mouseup" event into the QML scene. */
mouseup(e: TMouseEventPress): void;
/** Send "mousemove" event into the QML scene. */
mousemove(e: TMouseEventCommon): void;
/** Send "wheel" event into the QML scene. */
wheel(e: TMouseEventWheel): void;
/** Send "keydown" event into the QML scene. */
keydown(e: TKeyEvent): void;
/** Send "keyup" event into the QML scene. */
keyup(e: TKeyEvent): void;
/**
* Load a new QML scene from file or source text.
*
* @param opts either `{ file: string }` or `{ source: string }`.
*
* @description
*
* Can load QML from `file` (by path), or directly from `source` string.
* The old scene will be discarded, if any. A new texture will be created.
*/
load(opts: TOptsLoad): void;
/** Unload the current QML scene. */
destroy(): void;
/** Invoke a method in QML scene. */
invoke(name: string, key: string, args: unknown[]): unknown;
/** Set property value of an object in QML scene. */
set(name: string, key: string, value: unknown): void;
/** Get property value from an object in QML scene. */
get(name: string, key: string): unknown;
/**
* Initialize the QML engine.
*
* @param cwd base directory for QML file resolution. Usually, `process.cwd()`.
* @param wnd platform window handle (e.g. HWND on Windows).
* @param ctx the OpenGL context to which the QML render texture will be made available.
* @param device optional system display device, used only on Linux.
*
* @see [OpenGL context](https://www.khronos.org/opengl/wiki/OpenGL_Context).
*
* @description
* QML has a dedicated OpenGL context because of the renderer-specific requirements.
* The QML render textures are available to the main application's OpenGL context as well.
*
* With [glfw-raub](https://github.com/node-3d/glfw-raub), `hwnd` and `ctx` can
* be obtained with helpers:
*
* ```
* // window - is returned by glfw.createWindow(...) call
* const hwnd = glfw.platformWindow(window);
* const ctx = glfw.platformContext(window);
* const device = glfw.platformDevice();
* ```
*
* or
*
* ```
* // window - is an instance of glfw.Window
* const hwnd = window.platformWindow;
* const ctx = window.platformContext;
* const device = window.platformDevice;
* ```
*/
static init(cwd: string, wnd: number, ctx: number, device?: number): void;
/**
* Register a QML "library" directory.
*
* Where to look for `*.qml` files for `import` resolution.
*/
static libs(l: string): void;
/**
* Register a QML "plugin" directory.
*
* Where to look for low-level Qt stuff, such as `platforms, iconengines, imageformats`.
*/
static plugins(p: string): void;
/**
* Assign
* [QML style](https://doc.qt.io/qt-5/qtquickcontrols2-styles.html#using-styles-in-qt-quick-controls)
* value.
*/
static style(name: string, fallback: string): void;
/**
* Update the QML scene (similar to "pollEvents" for a window).
*
* Required for async operations, such as signal/slot interaction.
* If this method is not called at all, the QML scene won't ever load. It is preferred
* to call it regularly, e.g. every frame.
*/
static update(): void;
// ------ implements EventEmitter
addListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
on(eventName: string | symbol, listener: (...args: any[]) => void): this;
once(eventName: string | symbol, listener: (...args: any[]) => void): this;
removeListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
off(eventName: string | symbol, listener: (...args: any[]) => void): this;
removeAllListeners(event?: string | symbol): this;
setMaxListeners(n: number): this;
getMaxListeners(): number;
listeners(eventName: string | symbol): Function[];
rawListeners(eventName: string | symbol): Function[];
emit(eventName: string | symbol, ...args: any[]): boolean;
listenerCount(eventName: string | symbol, listener?: Function): number;
prependListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
prependOnceListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
eventNames(): Array<string | symbol>;
}
export type TOptsProperty<T> = Readonly<{
/** QML View instance */
view: View;
/** Target object name. */
name: string;
/** Property key. */
key: string;
/** Optional initial value - will be sent to QML scene ASAP. */
value?: T;
}>;
/**
* QML Property interoperation helper.
*
* Automates reading and writing QML objects. A QML object should
* have `objectName` and the target property. The value must be serializable.
*/
export class Property<T = any> {
constructor(opts: TOptsProperty<T>);
get value(): T | null;
set value(v: T | null);
}
export type TOptsMethod = Readonly<{
/** QML View instance */
view: View;
/** Target object name. */
name: string;
/** Property key. */
key: string;
}>;
type TUnknownFn = (
a0?: any, a1?: any, a2?: any, a3?: any, a4?: any,
a5?: any, a6?: any, a7?: any, a8?: any, a9?: any,
) => unknown;
interface TNewableMethod {
new(opts: TOptsMethod): TUnknownFn;
}
/**
* QML Method interoperation helper.
*
* Automates reading and writing QML objects. A QML object should
* have `objectName` and the target property. The value must be serializable.
*/
export const Method: TNewableMethod;
}