xbintsc 0.7.6 → 0.7.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/binder/references.js +13 -7
- package/dist/src/binder/references.js.map +1 -1
- package/dist/src/cli/help.d.ts +1 -1
- package/dist/src/driver/version.d.ts +1 -1
- package/dist/src/driver/version.js +1 -1
- package/dist/src/extensions/gui/index.js +5 -0
- package/dist/src/extensions/gui/index.js.map +1 -1
- package/dist/tests/binder/binder.test.js +26 -4
- package/dist/tests/binder/binder.test.js.map +1 -1
- package/dist/tests/checker/checker.test.js +16 -0
- package/dist/tests/checker/checker.test.js.map +1 -1
- package/dist/tests/e2e/gui-browser.test.js +31 -0
- package/dist/tests/e2e/gui-browser.test.js.map +1 -1
- package/dist/tests/e2e/gui-events.test.js +89 -0
- package/dist/tests/e2e/gui-events.test.js.map +1 -1
- package/dist/tests/e2e/gui-webgl2-anisotropy.test.d.ts +10 -0
- package/dist/tests/e2e/gui-webgl2-anisotropy.test.js +105 -0
- package/dist/tests/e2e/gui-webgl2-anisotropy.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-sampler-array.test.d.ts +11 -0
- package/dist/tests/e2e/gui-webgl2-sampler-array.test.js +117 -0
- package/dist/tests/e2e/gui-webgl2-sampler-array.test.js.map +1 -0
- package/doc/gui/api.md +9 -0
- package/doc/gui/input.md +8 -0
- package/doc/gui/known-issues.md +8 -0
- package/doc/implemented/binder.md +1 -1
- package/doc/zh-CN/gui/api.md +8 -0
- package/doc/zh-CN/gui/input.md +7 -0
- package/doc/zh-CN/gui/known-issues.md +6 -0
- package/doc/zh-CN/implemented/binder.md +1 -1
- package/package.json +7 -7
- package/runtime/ext_gui/browser.cpp +2 -0
- package/runtime/ext_gui/dom_api.cpp +4 -0
- package/runtime/ext_gui/dom_api_events.cpp +2 -1
- package/runtime/ext_gui/dom_api_internal.h +8 -0
- package/runtime/ext_gui/dom_api_mutation.cpp +49 -0
- package/runtime/ext_gui/dom_api_proto.cpp +3 -0
- package/runtime/ext_gui/dom_api_webgl_state.cpp +7 -0
- package/runtime/ext_gui/gui.cpp +2 -0
- package/runtime/ext_gui/gui_engine.h +18 -2
- package/runtime/ext_gui/gui_events.cpp +18 -118
- package/runtime/ext_gui/gui_input.cpp +148 -0
- package/runtime/ext_gui/pointer_lock.cpp +137 -0
- package/runtime/ext_gui/webgl_buffer.cpp +6 -0
- package/runtime/ext_gui/webgl_context.cpp +2 -0
- package/runtime/ext_gui/webgl_glsl.h +4 -0
- package/runtime/ext_gui/webgl_glsl_scan.cpp +14 -0
- package/runtime/ext_gui/webgl_objects.h +2 -0
- package/runtime/ext_gui/webgl_shader.cpp +1 -1
- package/runtime/ext_gui/window.cpp +3 -83
- package/runtime/ext_gui/window_diagnostics.cpp +94 -1
- package/src/binder/references.ts +13 -7
- package/src/driver/version.ts +1 -1
- package/src/extensions/gui/index.ts +5 -0
|
@@ -81,15 +81,6 @@ void xt_gui_scroll_to(XtGuiWindow *win, float x, float y) {
|
|
|
81
81
|
xt_gui_emit(win, "scroll");
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
static XtGuiWindow *xt_gui_find_by_window_id(SDL_WindowID id) {
|
|
85
|
-
SDL_Window *window = SDL_GetWindowFromID(id);
|
|
86
|
-
if (window == NULL) return NULL;
|
|
87
|
-
for (int i = 0; i < g_window_count; i++) {
|
|
88
|
-
if (g_windows[i].window == window) return &g_windows[i];
|
|
89
|
-
}
|
|
90
|
-
return NULL;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
84
|
/* -- input events --------------------------------------------------------- */
|
|
94
85
|
|
|
95
86
|
/** Deepest element under (x, y), or NULL. */
|
|
@@ -120,9 +111,12 @@ static void xt_gui_update_hover(XtGuiWindow *win, const xtgui::Node *node) {
|
|
|
120
111
|
}
|
|
121
112
|
|
|
122
113
|
/** Pointer payload. `node` is the hit-test result the caller already resolved,
|
|
123
|
-
* so one event does not walk the layout tree three times.
|
|
114
|
+
* so one event does not walk the layout tree three times. `movement_x`/
|
|
115
|
+
* `movement_y` are the raw deltas (`movementX`/`movementY`): zero for button
|
|
116
|
+
* events, SDL's `xrel`/`yrel` for motion. */
|
|
124
117
|
static xt_value xt_gui_pointer_payload(const char *type, XtGuiWindow *win, float x, float y,
|
|
125
|
-
int button, int clicks, const xtgui::Node *node
|
|
118
|
+
int button, int clicks, const xtgui::Node *node,
|
|
119
|
+
float movement_x, float movement_y) {
|
|
126
120
|
(void)win;
|
|
127
121
|
xt_value payload = xt_object_new();
|
|
128
122
|
xt_object_set(payload, xt_string_from_cstr("type"), xt_string_from_cstr(type));
|
|
@@ -130,6 +124,8 @@ static xt_value xt_gui_pointer_payload(const char *type, XtGuiWindow *win, float
|
|
|
130
124
|
xt_object_set(payload, xt_string_from_cstr("y"), xt_number(y));
|
|
131
125
|
xt_object_set(payload, xt_string_from_cstr("clientX"), xt_number(x));
|
|
132
126
|
xt_object_set(payload, xt_string_from_cstr("clientY"), xt_number(y));
|
|
127
|
+
xt_object_set(payload, xt_string_from_cstr("movementX"), xt_number(movement_x));
|
|
128
|
+
xt_object_set(payload, xt_string_from_cstr("movementY"), xt_number(movement_y));
|
|
133
129
|
xt_object_set(payload, xt_string_from_cstr("button"), xt_number(button));
|
|
134
130
|
xt_object_set(payload, xt_string_from_cstr("clicks"), xt_number(clicks));
|
|
135
131
|
if (node != nullptr) {
|
|
@@ -143,11 +139,16 @@ static xt_value xt_gui_pointer_payload(const char *type, XtGuiWindow *win, float
|
|
|
143
139
|
}
|
|
144
140
|
|
|
145
141
|
void xt_gui_dispatch_pointer(XtGuiWindow *win, const char *type, float x, float y, int button,
|
|
146
|
-
int clicks) {
|
|
142
|
+
int clicks, float movement_x, float movement_y) {
|
|
147
143
|
if (win == NULL || !win->open) return;
|
|
148
|
-
|
|
144
|
+
/* While the pointer is locked every pointer event targets the locked element
|
|
145
|
+
* and the cursor no longer hits new elements: the only thing that moves is
|
|
146
|
+
* the raw delta. Hovering is frozen too, so the page does not restyle under a
|
|
147
|
+
* hidden cursor. */
|
|
148
|
+
const bool locked = win->pointer_lock_node != nullptr;
|
|
149
|
+
const xtgui::Node *node = locked ? win->pointer_lock_node : xt_gui_hit_node(win, x, y);
|
|
149
150
|
xtgui::Node *target = const_cast<xtgui::Node *>(node);
|
|
150
|
-
xt_gui_update_hover(win, node);
|
|
151
|
+
if (!locked) xt_gui_update_hover(win, node);
|
|
151
152
|
bool prevented = false;
|
|
152
153
|
if (win->document != nullptr) {
|
|
153
154
|
if (strcmp(type, "mousedown") == 0) {
|
|
@@ -179,7 +180,8 @@ void xt_gui_dispatch_pointer(XtGuiWindow *win, const char *type, float x, float
|
|
|
179
180
|
}
|
|
180
181
|
}
|
|
181
182
|
}
|
|
182
|
-
xt_value payload = xt_gui_pointer_payload(type, win, x, y, button, clicks, node
|
|
183
|
+
xt_value payload = xt_gui_pointer_payload(type, win, x, y, button, clicks, node, movement_x,
|
|
184
|
+
movement_y);
|
|
183
185
|
if (node != nullptr) prevented = xt_gui_emit_dom_event(win, type, node, payload);
|
|
184
186
|
xt_gui_emit_payload(win, type, payload);
|
|
185
187
|
if (!prevented && node != nullptr && strcmp(type, "click") == 0) {
|
|
@@ -190,7 +192,7 @@ void xt_gui_dispatch_pointer(XtGuiWindow *win, const char *type, float x, float
|
|
|
190
192
|
void xt_gui_dispatch_wheel(XtGuiWindow *win, float x, float y, float delta_x, float delta_y) {
|
|
191
193
|
if (win == NULL || !win->open) return;
|
|
192
194
|
const xtgui::Node *node = xt_gui_hit_node(win, x, y);
|
|
193
|
-
xt_value payload = xt_gui_pointer_payload("wheel", win, x, y, -1, 0, node);
|
|
195
|
+
xt_value payload = xt_gui_pointer_payload("wheel", win, x, y, -1, 0, node, 0.0f, 0.0f);
|
|
194
196
|
xt_object_set(payload, xt_string_from_cstr("deltaX"), xt_number(delta_x));
|
|
195
197
|
xt_object_set(payload, xt_string_from_cstr("deltaY"), xt_number(delta_y));
|
|
196
198
|
if (node != nullptr) xt_gui_emit_dom_event(win, "wheel", node, payload);
|
|
@@ -289,108 +291,6 @@ void xt_gui_dispatch_physical_key(XtGuiWindow *win, const char *type, int scanco
|
|
|
289
291
|
xt_gui_dispatch_key_payload(win, type, payload);
|
|
290
292
|
}
|
|
291
293
|
|
|
292
|
-
namespace guidev {
|
|
293
|
-
|
|
294
|
-
void handle_event(const SDL_Event *event) {
|
|
295
|
-
if (event->type == SDL_EVENT_QUIT) {
|
|
296
|
-
g_quit = 1;
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
299
|
-
if (event->type == SDL_EVENT_WINDOW_CLOSE_REQUESTED) {
|
|
300
|
-
XtGuiWindow *win = xt_gui_find_by_window_id(event->window.windowID);
|
|
301
|
-
if (win != NULL && win->open) xt_gui_quit_window(win);
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
if (event->type == SDL_EVENT_WINDOW_RESIZED) {
|
|
305
|
-
XtGuiWindow *win = xt_gui_find_by_window_id(event->window.windowID);
|
|
306
|
-
if (win == NULL || !win->open) return;
|
|
307
|
-
/* `setSize` already applied and emitted the change synchronously; the
|
|
308
|
-
* queued backend event must not deliver the same resize twice. */
|
|
309
|
-
if (win->width == event->window.data1 && win->height == event->window.data2) return;
|
|
310
|
-
win->width = event->window.data1;
|
|
311
|
-
win->height = event->window.data2;
|
|
312
|
-
if (win->document != NULL) win->document->restyle((float)win->width, (float)win->height);
|
|
313
|
-
win->geometry.dirty = 1;
|
|
314
|
-
win->present_dirty = 1;
|
|
315
|
-
/* Web 'resize', so a document can re-measure on a window change in every
|
|
316
|
-
* host (a browser already fires one). */
|
|
317
|
-
xt_gui_emit(win, "resize");
|
|
318
|
-
xt_gui_media_lists_notify(win);
|
|
319
|
-
return;
|
|
320
|
-
}
|
|
321
|
-
/* A window the compositor revealed (uncovered, restored, shown) must be
|
|
322
|
-
* redrawn even though nothing in the document changed: the frame loop only
|
|
323
|
-
* presents on demand. The request is charged to `exposes` (below) so
|
|
324
|
-
* `stats()` can separate it from a present the page caused. */
|
|
325
|
-
if (event->type == SDL_EVENT_WINDOW_EXPOSED || event->type == SDL_EVENT_WINDOW_SHOWN ||
|
|
326
|
-
event->type == SDL_EVENT_WINDOW_RESTORED) {
|
|
327
|
-
XtGuiWindow *win = xt_gui_find_by_window_id(event->window.windowID);
|
|
328
|
-
if (win != NULL) {
|
|
329
|
-
win->present_dirty = 1;
|
|
330
|
-
win->expose_pending = 1;
|
|
331
|
-
}
|
|
332
|
-
return;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
if (event->type == SDL_EVENT_TEXT_INPUT) {
|
|
336
|
-
XtGuiWindow *win = xt_gui_find_by_window_id(event->text.windowID);
|
|
337
|
-
if (win == NULL || !win->open) return;
|
|
338
|
-
xt_gui_text_input(win, event->text.text);
|
|
339
|
-
return;
|
|
340
|
-
}
|
|
341
|
-
if (event->type == SDL_EVENT_TEXT_EDITING) {
|
|
342
|
-
XtGuiWindow *win = xt_gui_find_by_window_id(event->edit.windowID);
|
|
343
|
-
if (win == NULL || !win->open) return;
|
|
344
|
-
xt_gui_text_editing(win, event->edit.text, event->edit.start, event->edit.length);
|
|
345
|
-
return;
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
if (event->type == SDL_EVENT_MOUSE_MOTION) {
|
|
349
|
-
XtGuiWindow *win = xt_gui_find_by_window_id(event->motion.windowID);
|
|
350
|
-
xt_gui_dispatch_pointer(win, "mousemove", event->motion.x, event->motion.y, -1, 0);
|
|
351
|
-
return;
|
|
352
|
-
}
|
|
353
|
-
if (event->type == SDL_EVENT_MOUSE_BUTTON_DOWN) {
|
|
354
|
-
XtGuiWindow *win = xt_gui_find_by_window_id(event->button.windowID);
|
|
355
|
-
/* SDL numbers buttons 1/2/3 (left/middle/right); DOM uses 0/1/2. */
|
|
356
|
-
xt_gui_dispatch_pointer(win, "mousedown", event->button.x, event->button.y,
|
|
357
|
-
(int)event->button.button - 1, event->button.clicks);
|
|
358
|
-
return;
|
|
359
|
-
}
|
|
360
|
-
if (event->type == SDL_EVENT_MOUSE_BUTTON_UP) {
|
|
361
|
-
XtGuiWindow *win = xt_gui_find_by_window_id(event->button.windowID);
|
|
362
|
-
if (win == NULL || !win->open) return;
|
|
363
|
-
int button = (int)event->button.button - 1;
|
|
364
|
-
xt_gui_dispatch_pointer(win, "mouseup", event->button.x, event->button.y, button,
|
|
365
|
-
event->button.clicks);
|
|
366
|
-
if (button == 0) {
|
|
367
|
-
xt_gui_dispatch_pointer(win, "click", event->button.x, event->button.y, button,
|
|
368
|
-
event->button.clicks);
|
|
369
|
-
}
|
|
370
|
-
return;
|
|
371
|
-
}
|
|
372
|
-
if (event->type == SDL_EVENT_MOUSE_WHEEL) {
|
|
373
|
-
XtGuiWindow *win = xt_gui_find_by_window_id(event->wheel.windowID);
|
|
374
|
-
/* DOM `deltaY` grows downwards; SDL's grows away from the user. */
|
|
375
|
-
xt_gui_dispatch_wheel(win, event->wheel.mouse_x, event->wheel.mouse_y, event->wheel.x,
|
|
376
|
-
-event->wheel.y);
|
|
377
|
-
return;
|
|
378
|
-
}
|
|
379
|
-
if (event->type == SDL_EVENT_KEY_DOWN || event->type == SDL_EVENT_KEY_UP) {
|
|
380
|
-
XtGuiWindow *win = xt_gui_find_by_window_id(event->key.windowID);
|
|
381
|
-
if (win == NULL || !win->open) return;
|
|
382
|
-
const char *type = event->type == SDL_EVENT_KEY_DOWN ? "keydown" : "keyup";
|
|
383
|
-
xt_gui_dispatch_physical_key(
|
|
384
|
-
win, type, static_cast<int>(event->key.scancode), static_cast<int>(event->key.key),
|
|
385
|
-
event->key.repeat, (event->key.mod & SDL_KMOD_CTRL) != 0,
|
|
386
|
-
(event->key.mod & SDL_KMOD_SHIFT) != 0, (event->key.mod & SDL_KMOD_ALT) != 0,
|
|
387
|
-
(event->key.mod & SDL_KMOD_GUI) != 0, (event->key.mod & SDL_KMOD_CAPS) != 0);
|
|
388
|
-
return;
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
} // namespace guidev
|
|
393
|
-
|
|
394
294
|
/* -- rendering ------------------------------------------------------------ */
|
|
395
295
|
|
|
396
296
|
void xt_gui_run_animation_frames(XtGuiWindow *win, double timestamp_ms) {
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* xbintsc GUI engine — SDL event translation.
|
|
3
|
+
*
|
|
4
|
+
* The frame loop polls SDL and hands every event to `handle_event`, which finds
|
|
5
|
+
* the owning window and turns the event into the engine's DOM-shaped callback.
|
|
6
|
+
* Hit testing, pointer payloads and rendering stay in `gui_events.cpp`; keeping
|
|
7
|
+
* the SDL switch here leaves that unit under the repository's size budget and
|
|
8
|
+
* focused on delivery.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
#include "gui_internal.h"
|
|
12
|
+
|
|
13
|
+
#include <string.h>
|
|
14
|
+
|
|
15
|
+
namespace guidev {
|
|
16
|
+
|
|
17
|
+
namespace {
|
|
18
|
+
|
|
19
|
+
/** The live window record that owns an SDL window id, or null. */
|
|
20
|
+
XtGuiWindow *find_by_window_id(SDL_WindowID id) {
|
|
21
|
+
SDL_Window *window = SDL_GetWindowFromID(id);
|
|
22
|
+
if (window == NULL) return NULL;
|
|
23
|
+
for (int i = 0; i < g_window_count; i++) {
|
|
24
|
+
if (g_windows[i].window == window) return &g_windows[i];
|
|
25
|
+
}
|
|
26
|
+
return NULL;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
} // namespace
|
|
30
|
+
|
|
31
|
+
void handle_event(const SDL_Event *event) {
|
|
32
|
+
if (event->type == SDL_EVENT_QUIT) {
|
|
33
|
+
g_quit = 1;
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (event->type == SDL_EVENT_WINDOW_CLOSE_REQUESTED) {
|
|
37
|
+
XtGuiWindow *win = find_by_window_id(event->window.windowID);
|
|
38
|
+
if (win != NULL && win->open) xt_gui_quit_window(win);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
/* Losing focus releases the pointer lock, as the browser does when the user
|
|
42
|
+
* switches away: leaving the cursor hidden in another window would trap the
|
|
43
|
+
* pointer with no way back except Escape. */
|
|
44
|
+
if (event->type == SDL_EVENT_WINDOW_FOCUS_LOST) {
|
|
45
|
+
XtGuiWindow *win = find_by_window_id(event->window.windowID);
|
|
46
|
+
if (win != NULL && win->pointer_lock_node != nullptr) {
|
|
47
|
+
xt_gui_set_pointer_lock(win, nullptr);
|
|
48
|
+
}
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (event->type == SDL_EVENT_WINDOW_RESIZED) {
|
|
52
|
+
XtGuiWindow *win = find_by_window_id(event->window.windowID);
|
|
53
|
+
if (win == NULL || !win->open) return;
|
|
54
|
+
/* `setSize` already applied and emitted the change synchronously; the
|
|
55
|
+
* queued backend event must not deliver the same resize twice. */
|
|
56
|
+
if (win->width == event->window.data1 && win->height == event->window.data2) return;
|
|
57
|
+
win->width = event->window.data1;
|
|
58
|
+
win->height = event->window.data2;
|
|
59
|
+
if (win->document != NULL) win->document->restyle((float)win->width, (float)win->height);
|
|
60
|
+
win->geometry.dirty = 1;
|
|
61
|
+
win->present_dirty = 1;
|
|
62
|
+
/* Web 'resize', so a document can re-measure on a window change in every
|
|
63
|
+
* host (a browser already fires one). */
|
|
64
|
+
xt_gui_emit(win, "resize");
|
|
65
|
+
xt_gui_media_lists_notify(win);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
/* A window the compositor revealed (uncovered, restored, shown) must be
|
|
69
|
+
* redrawn even though nothing in the document changed: the frame loop only
|
|
70
|
+
* presents on demand. The request is charged to `exposes` (below) so
|
|
71
|
+
* `stats()` can separate it from a present the page caused. */
|
|
72
|
+
if (event->type == SDL_EVENT_WINDOW_EXPOSED || event->type == SDL_EVENT_WINDOW_SHOWN ||
|
|
73
|
+
event->type == SDL_EVENT_WINDOW_RESTORED) {
|
|
74
|
+
XtGuiWindow *win = find_by_window_id(event->window.windowID);
|
|
75
|
+
if (win != NULL) {
|
|
76
|
+
win->present_dirty = 1;
|
|
77
|
+
win->expose_pending = 1;
|
|
78
|
+
}
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (event->type == SDL_EVENT_TEXT_INPUT) {
|
|
83
|
+
XtGuiWindow *win = find_by_window_id(event->text.windowID);
|
|
84
|
+
if (win == NULL || !win->open) return;
|
|
85
|
+
xt_gui_text_input(win, event->text.text);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (event->type == SDL_EVENT_TEXT_EDITING) {
|
|
89
|
+
XtGuiWindow *win = find_by_window_id(event->edit.windowID);
|
|
90
|
+
if (win == NULL || !win->open) return;
|
|
91
|
+
xt_gui_text_editing(win, event->edit.text, event->edit.start, event->edit.length);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (event->type == SDL_EVENT_MOUSE_MOTION) {
|
|
96
|
+
XtGuiWindow *win = find_by_window_id(event->motion.windowID);
|
|
97
|
+
/* SDL's `xrel`/`yrel` are the raw delta and stay meaningful in relative
|
|
98
|
+
* (pointer-lock) mode, where `x`/`y` stop tracking a visible cursor. */
|
|
99
|
+
xt_gui_dispatch_pointer(win, "mousemove", event->motion.x, event->motion.y, -1, 0,
|
|
100
|
+
event->motion.xrel, event->motion.yrel);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (event->type == SDL_EVENT_MOUSE_BUTTON_DOWN) {
|
|
104
|
+
XtGuiWindow *win = find_by_window_id(event->button.windowID);
|
|
105
|
+
/* SDL numbers buttons 1/2/3 (left/middle/right); DOM uses 0/1/2. */
|
|
106
|
+
xt_gui_dispatch_pointer(win, "mousedown", event->button.x, event->button.y,
|
|
107
|
+
(int)event->button.button - 1, event->button.clicks);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (event->type == SDL_EVENT_MOUSE_BUTTON_UP) {
|
|
111
|
+
XtGuiWindow *win = find_by_window_id(event->button.windowID);
|
|
112
|
+
if (win == NULL || !win->open) return;
|
|
113
|
+
int button = (int)event->button.button - 1;
|
|
114
|
+
xt_gui_dispatch_pointer(win, "mouseup", event->button.x, event->button.y, button,
|
|
115
|
+
event->button.clicks);
|
|
116
|
+
if (button == 0) {
|
|
117
|
+
xt_gui_dispatch_pointer(win, "click", event->button.x, event->button.y, button,
|
|
118
|
+
event->button.clicks);
|
|
119
|
+
}
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (event->type == SDL_EVENT_MOUSE_WHEEL) {
|
|
123
|
+
XtGuiWindow *win = find_by_window_id(event->wheel.windowID);
|
|
124
|
+
/* DOM `deltaY` grows downwards; SDL's grows away from the user. */
|
|
125
|
+
xt_gui_dispatch_wheel(win, event->wheel.mouse_x, event->wheel.mouse_y, event->wheel.x,
|
|
126
|
+
-event->wheel.y);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (event->type == SDL_EVENT_KEY_DOWN || event->type == SDL_EVENT_KEY_UP) {
|
|
130
|
+
XtGuiWindow *win = find_by_window_id(event->key.windowID);
|
|
131
|
+
if (win == NULL || !win->open) return;
|
|
132
|
+
/* Escape is the browser's universal exit from pointer lock; release before
|
|
133
|
+
* the page sees the key, so its handler observes the unlocked state. */
|
|
134
|
+
if (event->type == SDL_EVENT_KEY_DOWN && event->key.key == SDLK_ESCAPE &&
|
|
135
|
+
win->pointer_lock_node != nullptr) {
|
|
136
|
+
xt_gui_set_pointer_lock(win, nullptr);
|
|
137
|
+
}
|
|
138
|
+
const char *type = event->type == SDL_EVENT_KEY_DOWN ? "keydown" : "keyup";
|
|
139
|
+
xt_gui_dispatch_physical_key(
|
|
140
|
+
win, type, static_cast<int>(event->key.scancode), static_cast<int>(event->key.key),
|
|
141
|
+
event->key.repeat, (event->key.mod & SDL_KMOD_CTRL) != 0,
|
|
142
|
+
(event->key.mod & SDL_KMOD_SHIFT) != 0, (event->key.mod & SDL_KMOD_ALT) != 0,
|
|
143
|
+
(event->key.mod & SDL_KMOD_GUI) != 0, (event->key.mod & SDL_KMOD_CAPS) != 0);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
} // namespace guidev
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* xbintsc GUI engine — the Pointer Lock API.
|
|
3
|
+
*
|
|
4
|
+
* First-person games aim with raw relative motion instead of the cursor: a
|
|
5
|
+
* click calls `element.requestPointerLock()`, the host hides and captures the
|
|
6
|
+
* pointer, and every `mousemove` carries `movementX`/`movementY`. SDL3 calls
|
|
7
|
+
* that mode "relative mouse", so the two states map one-to-one:
|
|
8
|
+
*
|
|
9
|
+
* requestPointerLock() -> SDL_SetWindowRelativeMouseMode(window, true)
|
|
10
|
+
* exitPointerLock() -> SDL_SetWindowRelativeMouseMode(window, false)
|
|
11
|
+
* document.pointerLockElement
|
|
12
|
+
* pointerlockchange / pointerlockerror
|
|
13
|
+
*
|
|
14
|
+
* Without it a game silently falls back to drag-to-look and receives
|
|
15
|
+
* `movementX === 0`, which reads as "the mouse does nothing".
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
#include "dom_api_internal.h"
|
|
19
|
+
#include "gui_engine.h"
|
|
20
|
+
#include "gui_internal.h"
|
|
21
|
+
|
|
22
|
+
namespace {
|
|
23
|
+
|
|
24
|
+
/** Deliver `pointerlockchange` / `pointerlockerror` to `document` listeners
|
|
25
|
+
* (the document handle resolves to the root node) and then to `window`
|
|
26
|
+
* listeners, like an ordinary DOM event. */
|
|
27
|
+
void emit_pointer_lock_event(XtGuiWindow *win, const char *type) {
|
|
28
|
+
if (win == nullptr) return;
|
|
29
|
+
xt_value payload = xt_object_new();
|
|
30
|
+
xt_object_set(payload, xt_string_from_cstr("type"), xt_string_from_cstr(type));
|
|
31
|
+
if (win->document != nullptr) {
|
|
32
|
+
const xtgui::Node *root = win->document->root();
|
|
33
|
+
if (root != nullptr) {
|
|
34
|
+
xt_value legacy = xt_object_new();
|
|
35
|
+
xt_object_set(legacy, xt_string_from_cstr("type"), xt_string_from_cstr(type));
|
|
36
|
+
/* In a browser the target is `document`; the engine's document handle
|
|
37
|
+
* resolves to this root node, so the listener path is the same. */
|
|
38
|
+
xt_object_set(legacy, xt_string_from_cstr("target"), xt_string_from_cstr("#document"));
|
|
39
|
+
xt_gui_emit_dom_event(win, type, root, legacy);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
xt_gui_emit_payload(win, type, payload);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
} // namespace
|
|
46
|
+
|
|
47
|
+
bool xt_gui_set_pointer_lock(XtGuiWindow *win, const xtgui::Node *node) {
|
|
48
|
+
if (win == nullptr || win->window == nullptr) return false;
|
|
49
|
+
if (win->pointer_lock_node == node) return true;
|
|
50
|
+
if (node == nullptr) {
|
|
51
|
+
if (win->pointer_lock_node == nullptr) return true;
|
|
52
|
+
win->pointer_lock_node = nullptr;
|
|
53
|
+
SDL_SetWindowRelativeMouseMode(win->window, false);
|
|
54
|
+
emit_pointer_lock_event(win, "pointerlockchange");
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
if (win->document == nullptr || win->document->root() == nullptr ||
|
|
58
|
+
!win->document->root()->contains(node)) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
if (!SDL_SetWindowRelativeMouseMode(win->window, true)) return false;
|
|
62
|
+
win->pointer_lock_node = node;
|
|
63
|
+
emit_pointer_lock_event(win, "pointerlockchange");
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
void xt_gui_pointer_lock_release(XtGuiWindow *win) {
|
|
68
|
+
if (win == nullptr) return;
|
|
69
|
+
if (win->window != nullptr && win->pointer_lock_node != nullptr) {
|
|
70
|
+
SDL_SetWindowRelativeMouseMode(win->window, false);
|
|
71
|
+
}
|
|
72
|
+
win->pointer_lock_node = nullptr;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
void xt_gui_pointer_lock_error(XtGuiWindow *win) {
|
|
76
|
+
emit_pointer_lock_event(win, "pointerlockerror");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
namespace domapi {
|
|
80
|
+
|
|
81
|
+
namespace {
|
|
82
|
+
|
|
83
|
+
xt_value pointer_lock_error(const char *message) {
|
|
84
|
+
xt_value text = xt_string_from_cstr(message);
|
|
85
|
+
return xt_error_ctor_by_name(xt_string_from_cstr("Error"), 1, &text);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const char *pointer_lock_failure(void) {
|
|
89
|
+
const char *error = SDL_GetError();
|
|
90
|
+
return error != nullptr && error[0] != '\0' ? error : "pointer lock is not available";
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
} // namespace
|
|
94
|
+
|
|
95
|
+
/** `element.requestPointerLock()`: enter relative mouse mode and resolve once
|
|
96
|
+
* the lock is active. A failed request fires `pointerlockerror` and rejects. */
|
|
97
|
+
xt_value node_request_pointer_lock(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
|
|
98
|
+
(void)env;
|
|
99
|
+
(void)argc;
|
|
100
|
+
(void)argv;
|
|
101
|
+
XtGuiWindow *win = nullptr;
|
|
102
|
+
xtgui::Node *node = resolve_node(self, &win);
|
|
103
|
+
if (win == nullptr || node == nullptr || win->window == nullptr) {
|
|
104
|
+
return xt_promise_reject(pointer_lock_error("the element is not in a document"));
|
|
105
|
+
}
|
|
106
|
+
if (!xt_gui_set_pointer_lock(win, node)) {
|
|
107
|
+
xt_gui_pointer_lock_error(win);
|
|
108
|
+
return xt_promise_reject(pointer_lock_error(pointer_lock_failure()));
|
|
109
|
+
}
|
|
110
|
+
return xt_promise_resolve(XT_UNDEFINED);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** `document.exitPointerLock()`: leave relative mouse mode. A no-op when no
|
|
114
|
+
* element holds the lock. */
|
|
115
|
+
xt_value doc_exit_pointer_lock(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
|
|
116
|
+
(void)env;
|
|
117
|
+
(void)argc;
|
|
118
|
+
(void)argv;
|
|
119
|
+
xt_gui_set_pointer_lock(resolve_window(self), nullptr);
|
|
120
|
+
return XT_UNDEFINED;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** `document.pointerLockElement`: the locked element, or null. */
|
|
124
|
+
xt_value doc_pointer_lock_element_get(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
|
|
125
|
+
(void)env;
|
|
126
|
+
(void)argc;
|
|
127
|
+
(void)argv;
|
|
128
|
+
XtGuiWindow *win = resolve_window(self);
|
|
129
|
+
if (win == nullptr || win->document == nullptr || win->pointer_lock_node == nullptr) {
|
|
130
|
+
return XT_NULL;
|
|
131
|
+
}
|
|
132
|
+
const xtgui::Node *root = win->document->root();
|
|
133
|
+
if (root == nullptr || !root->contains(win->pointer_lock_node)) return XT_NULL;
|
|
134
|
+
return xt_gui_node_handle(win, win->pointer_lock_node);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
} // namespace domapi
|
|
@@ -186,6 +186,9 @@ bool WebGLContext::tex_parameter(uint32_t id, int pname, int value) {
|
|
|
186
186
|
if (record == nullptr) return false;
|
|
187
187
|
if (pname == GL_TEXTURE_MIN_FILTER) record->min_filter = value;
|
|
188
188
|
else if (pname == GL_TEXTURE_MAG_FILTER) record->mag_filter = value;
|
|
189
|
+
else if (pname == 0x84FE) { // TEXTURE_MAX_ANISOTROPY_EXT
|
|
190
|
+
record->anisotropy = value < 1 ? 1 : (value > 16 ? 16 : value);
|
|
191
|
+
}
|
|
189
192
|
else if (pname == GL_TEXTURE_WRAP_S) record->wrap_s = value;
|
|
190
193
|
else if (pname == GL_TEXTURE_WRAP_T) record->wrap_t = value;
|
|
191
194
|
else if (pname == GL_TEXTURE_COMPARE_MODE) {
|
|
@@ -213,6 +216,7 @@ int WebGLContext::tex_parameter_value(uint32_t id, int pname) {
|
|
|
213
216
|
if (pname == GL_TEXTURE_COMPARE_FUNC) return record->compare_func;
|
|
214
217
|
if (pname == GL_TEXTURE_MIN_FILTER) return record->min_filter;
|
|
215
218
|
if (pname == GL_TEXTURE_MAG_FILTER) return record->mag_filter;
|
|
219
|
+
if (pname == 0x84FE) return record->anisotropy; // TEXTURE_MAX_ANISOTROPY_EXT
|
|
216
220
|
if (pname == GL_TEXTURE_WRAP_S) return record->wrap_s;
|
|
217
221
|
if (pname == GL_TEXTURE_WRAP_T) return record->wrap_t;
|
|
218
222
|
return 0;
|
|
@@ -307,6 +311,8 @@ SDL_GPUSampler *WebGLContext::sampler_for(WebGLTexture *record) {
|
|
|
307
311
|
info.address_mode_w = address_of(record->wrap_t);
|
|
308
312
|
info.min_lod = 0.0f;
|
|
309
313
|
info.max_lod = record->has_mipmaps ? 1000.0f : 0.0f;
|
|
314
|
+
info.max_anisotropy = (float)record->anisotropy;
|
|
315
|
+
info.enable_anisotropy = record->anisotropy > 1;
|
|
310
316
|
if (record->depth) {
|
|
311
317
|
/* Depth formats are sampled unfiltered; a depth value has no meaning once
|
|
312
318
|
* interpolated across a texel boundary. */
|
|
@@ -386,6 +386,8 @@ double WebGLContext::parameter(int pname) {
|
|
|
386
386
|
return 8192;
|
|
387
387
|
case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
|
|
388
388
|
return 8192;
|
|
389
|
+
case 0x84FF: // MAX_TEXTURE_MAX_ANISOTROPY_EXT
|
|
390
|
+
return 16;
|
|
389
391
|
case GL_SAMPLES: {
|
|
390
392
|
const int samples = bound_framebuffer_ == 0 ? default_samples_
|
|
391
393
|
: framebuffer_samples(bound_framebuffer_);
|
|
@@ -132,6 +132,10 @@ std::string unroll_glsl_pragmas(const std::string &source);
|
|
|
132
132
|
/** Scan `source` for the declarations WebGL needs to know about. */
|
|
133
133
|
void scan_glsl(const std::string &source, bool fragment, GlslShaderInfo *info);
|
|
134
134
|
|
|
135
|
+
/** Element count of a declaration's array suffix (`"[4]"`, `"[N]"`); arrays
|
|
136
|
+
* whose size is a macro cannot be counted here, so they report one. */
|
|
137
|
+
int glsl_array_size(const std::string &array);
|
|
138
|
+
|
|
135
139
|
/** Rewrite `source` into Vulkan GLSL ES 3.10 (`layout` added everywhere). */
|
|
136
140
|
std::string rewrite_glsl(const std::string &source, bool fragment, const GlslLinkLayout &layout,
|
|
137
141
|
const GlslShaderInfo &info);
|
|
@@ -359,6 +359,20 @@ ConditionValue evaluate_condition(const std::string &directive,
|
|
|
359
359
|
|
|
360
360
|
} // namespace
|
|
361
361
|
|
|
362
|
+
int glsl_array_size(const std::string &array) {
|
|
363
|
+
int size = 0;
|
|
364
|
+
bool numeric = true;
|
|
365
|
+
for (char ch : array) {
|
|
366
|
+
if (ch == ' ' || ch == '\t' || ch == '[' || ch == ']') continue;
|
|
367
|
+
if (ch < '0' || ch > '9') {
|
|
368
|
+
numeric = false;
|
|
369
|
+
break;
|
|
370
|
+
}
|
|
371
|
+
size = size * 10 + (ch - '0');
|
|
372
|
+
}
|
|
373
|
+
return numeric && size > 0 ? size : 1;
|
|
374
|
+
}
|
|
375
|
+
|
|
362
376
|
void scan_glsl(const std::string &source, bool fragment, GlslShaderInfo *info) {
|
|
363
377
|
*info = GlslShaderInfo();
|
|
364
378
|
const std::vector<Token> tokens = tokenize(source);
|
|
@@ -64,6 +64,8 @@ struct WebGLTexture {
|
|
|
64
64
|
bool has_mipmaps = false;
|
|
65
65
|
int min_filter = 0;
|
|
66
66
|
int mag_filter = 0;
|
|
67
|
+
/** `TEXTURE_MAX_ANISOTROPY_EXT`; 1 disables anisotropic filtering. */
|
|
68
|
+
int anisotropy = 1;
|
|
67
69
|
int wrap_s = 0;
|
|
68
70
|
int wrap_t = 0;
|
|
69
71
|
SDL_GPUSampler *sampler = nullptr;
|
|
@@ -452,6 +452,7 @@ bool WebGLContext::link_program(uint32_t id) {
|
|
|
452
452
|
uniform.compare = compare;
|
|
453
453
|
uniform.unit = 0;
|
|
454
454
|
uniform.layout.gl_type = gl_type_of(decl.type);
|
|
455
|
+
if (!decl.array.empty()) { uniform.layout.is_array = true; uniform.layout.array_size = glsl_array_size(decl.array); }
|
|
455
456
|
index = (int)program->uniforms.size();
|
|
456
457
|
program->uniform_index[decl.name] = index;
|
|
457
458
|
program->uniforms.push_back(uniform);
|
|
@@ -460,7 +461,6 @@ bool WebGLContext::link_program(uint32_t id) {
|
|
|
460
461
|
};
|
|
461
462
|
for (const GlslUniformDecl &decl : vs_info.samplers) add_sampler(record, &record->vs_sampler_uniforms, decl);
|
|
462
463
|
for (const GlslUniformDecl &decl : fs_info.samplers) add_sampler(record, &record->fs_sampler_uniforms, decl);
|
|
463
|
-
|
|
464
464
|
webgl_detail::build_uniform_blocks(record, vs_info.blocks, fs_info.blocks, members);
|
|
465
465
|
|
|
466
466
|
/* (Re)create the SDL shaders. */
|