xbintsc 0.7.0 → 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/ast/common.d.ts +10 -0
- package/dist/src/binder/references.js +13 -7
- package/dist/src/binder/references.js.map +1 -1
- package/dist/src/checker/source.js +4 -0
- package/dist/src/checker/source.js.map +1 -1
- package/dist/src/cli/help.d.ts +1 -1
- package/dist/src/cli/main.js +15 -3
- package/dist/src/cli/main.js.map +1 -1
- package/dist/src/codegen/generator/calls/access.js +4 -11
- package/dist/src/codegen/generator/calls/access.js.map +1 -1
- package/dist/src/codegen/generator/calls/element-inline.d.ts +42 -0
- package/dist/src/codegen/generator/calls/element-inline.js +388 -0
- package/dist/src/codegen/generator/calls/element-inline.js.map +1 -0
- package/dist/src/codegen/generator/calls/invocation.js +82 -1
- package/dist/src/codegen/generator/calls/invocation.js.map +1 -1
- package/dist/src/codegen/generator/calls.d.ts +3 -1
- package/dist/src/codegen/generator/calls.js +3 -1
- package/dist/src/codegen/generator/calls.js.map +1 -1
- package/dist/src/codegen/generator/debug.js +20 -3
- package/dist/src/codegen/generator/debug.js.map +1 -1
- package/dist/src/codegen/generator/expressions/assignment.js +10 -2
- package/dist/src/codegen/generator/expressions/assignment.js.map +1 -1
- package/dist/src/codegen/generator/expressions/global-values.d.ts +19 -0
- package/dist/src/codegen/generator/expressions/global-values.js +49 -0
- package/dist/src/codegen/generator/expressions/global-values.js.map +1 -0
- package/dist/src/codegen/generator/expressions/primary.d.ts +0 -2
- package/dist/src/codegen/generator/expressions/primary.js +4 -24
- package/dist/src/codegen/generator/expressions/primary.js.map +1 -1
- package/dist/src/codegen/generator/expressions.d.ts +2 -1
- package/dist/src/codegen/generator/expressions.js +2 -1
- package/dist/src/codegen/generator/expressions.js.map +1 -1
- package/dist/src/codegen/generator/layout.d.ts +65 -0
- package/dist/src/codegen/generator/layout.js +50 -0
- package/dist/src/codegen/generator/layout.js.map +1 -0
- package/dist/src/codegen/generator/state.js +4 -0
- package/dist/src/codegen/generator/state.js.map +1 -1
- package/dist/src/diagnostics/diagnostic.js +1 -1
- package/dist/src/diagnostics/diagnostic.js.map +1 -1
- package/dist/src/diagnostics/source-text.d.ts +37 -9
- package/dist/src/diagnostics/source-text.js +124 -23
- package/dist/src/diagnostics/source-text.js.map +1 -1
- package/dist/src/diagnostics/source.d.ts +16 -6
- package/dist/src/diagnostics/source.js +25 -4
- package/dist/src/diagnostics/source.js.map +1 -1
- package/dist/src/driver/build-key.d.ts +14 -0
- package/dist/src/driver/build-key.js +6 -1
- package/dist/src/driver/build-key.js.map +1 -1
- package/dist/src/driver/bundler/concatenate.js +11 -4
- package/dist/src/driver/bundler/concatenate.js.map +1 -1
- package/dist/src/driver/bundler/graph.js +2 -2
- package/dist/src/driver/bundler/graph.js.map +1 -1
- package/dist/src/driver/bundler/merge.js +11 -5
- package/dist/src/driver/bundler/merge.js.map +1 -1
- package/dist/src/driver/bundler/reexport-resolution.js +3 -0
- package/dist/src/driver/bundler/reexport-resolution.js.map +1 -1
- package/dist/src/driver/compiler.js +13 -3
- package/dist/src/driver/compiler.js.map +1 -1
- package/dist/src/driver/frontend.js +3 -4
- package/dist/src/driver/frontend.js.map +1 -1
- package/dist/src/driver/runtime-objects.d.ts +1 -1
- package/dist/src/driver/runtime-objects.js +4 -0
- package/dist/src/driver/runtime-objects.js.map +1 -1
- package/dist/src/driver/toolchain.js +28 -5
- package/dist/src/driver/toolchain.js.map +1 -1
- package/dist/src/driver/version.d.ts +1 -1
- package/dist/src/driver/version.js +1 -1
- package/dist/src/extensions/gui/html.js +42 -10
- package/dist/src/extensions/gui/html.js.map +1 -1
- package/dist/src/extensions/gui/index.js +53 -0
- package/dist/src/extensions/gui/index.js.map +1 -1
- package/dist/src/extensions/registry.d.ts +20 -0
- package/dist/src/extensions/registry.js.map +1 -1
- package/dist/src/parser/expressions.js +2 -2
- package/dist/src/parser/expressions.js.map +1 -1
- package/dist/src/parser/helpers.d.ts +8 -0
- package/dist/src/parser/helpers.js +21 -0
- package/dist/src/parser/helpers.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/cli/main.test.js +9 -0
- package/dist/tests/cli/main.test.js.map +1 -1
- package/dist/tests/codegen/element-layout.test.d.ts +19 -0
- package/dist/tests/codegen/element-layout.test.js +80 -0
- package/dist/tests/codegen/element-layout.test.js.map +1 -0
- package/dist/tests/codegen/expressions.test.js +25 -0
- package/dist/tests/codegen/expressions.test.js.map +1 -1
- package/dist/tests/codegen/llvm.test.js +13 -0
- package/dist/tests/codegen/llvm.test.js.map +1 -1
- package/dist/tests/diagnostics/diagnostic.test.js +9 -0
- package/dist/tests/diagnostics/diagnostic.test.js.map +1 -1
- package/dist/tests/diagnostics/source-text.test.d.ts +1 -0
- package/dist/tests/diagnostics/source-text.test.js +50 -0
- package/dist/tests/diagnostics/source-text.test.js.map +1 -0
- package/dist/tests/diagnostics/source.test.js +17 -0
- package/dist/tests/diagnostics/source.test.js.map +1 -1
- package/dist/tests/driver/build-key.test.d.ts +1 -0
- package/dist/tests/driver/build-key.test.js +49 -0
- package/dist/tests/driver/build-key.test.js.map +1 -0
- package/dist/tests/driver/toolchain.test.js +8 -1
- package/dist/tests/driver/toolchain.test.js.map +1 -1
- package/dist/tests/driver/usage.test.js +2 -1
- package/dist/tests/driver/usage.test.js.map +1 -1
- package/dist/tests/e2e/async-await.test.js +16 -0
- package/dist/tests/e2e/async-await.test.js.map +1 -1
- package/dist/tests/e2e/compile-builtins.test.js +29 -0
- package/dist/tests/e2e/compile-builtins.test.js.map +1 -1
- package/dist/tests/e2e/compile-modules.test.js +13 -0
- package/dist/tests/e2e/compile-modules.test.js.map +1 -1
- package/dist/tests/e2e/compile-objects-classes.test.js.map +1 -1
- package/dist/tests/e2e/compile-prototype-chain.test.d.ts +8 -0
- package/dist/tests/e2e/compile-prototype-chain.test.js +24 -0
- package/dist/tests/e2e/compile-prototype-chain.test.js.map +1 -0
- package/dist/tests/e2e/differential-language.test.js +25 -0
- package/dist/tests/e2e/differential-language.test.js.map +1 -1
- package/dist/tests/e2e/differential-values.test.js +59 -0
- package/dist/tests/e2e/differential-values.test.js.map +1 -1
- package/dist/tests/e2e/gc.test.js +22 -0
- package/dist/tests/e2e/gc.test.js.map +1 -1
- package/dist/tests/e2e/gui-audio-extra.test.d.ts +12 -0
- package/dist/tests/e2e/gui-audio-extra.test.js +185 -0
- package/dist/tests/e2e/gui-audio-extra.test.js.map +1 -0
- package/dist/tests/e2e/gui-browser.test.js +66 -2
- package/dist/tests/e2e/gui-browser.test.js.map +1 -1
- package/dist/tests/e2e/gui-dom.test.js +88 -0
- package/dist/tests/e2e/gui-dom.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-webgl-declarations.test.d.ts +13 -0
- package/dist/tests/e2e/gui-webgl-declarations.test.js +136 -0
- package/dist/tests/e2e/gui-webgl-declarations.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl-texture-units.test.d.ts +12 -0
- package/dist/tests/e2e/gui-webgl-texture-units.test.js +86 -0
- package/dist/tests/e2e/gui-webgl-texture-units.test.js.map +1 -0
- 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-blit.test.js +6 -2
- package/dist/tests/e2e/gui-webgl2-blit.test.js.map +1 -1
- package/dist/tests/e2e/gui-webgl2-msaa-float.test.d.ts +12 -0
- package/dist/tests/e2e/gui-webgl2-msaa-float.test.js +157 -0
- package/dist/tests/e2e/gui-webgl2-msaa-float.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-msaa.test.d.ts +10 -0
- package/dist/tests/e2e/gui-webgl2-msaa.test.js +344 -0
- package/dist/tests/e2e/gui-webgl2-msaa.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/dist/tests/e2e/gui-webgl2-target-orientation.test.d.ts +15 -0
- package/dist/tests/e2e/gui-webgl2-target-orientation.test.js +287 -0
- package/dist/tests/e2e/gui-webgl2-target-orientation.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2.test.js +59 -1
- package/dist/tests/e2e/gui-webgl2.test.js.map +1 -1
- package/dist/tests/e2e/hang-watchdog.test.d.ts +10 -0
- package/dist/tests/e2e/hang-watchdog.test.js +50 -0
- package/dist/tests/e2e/hang-watchdog.test.js.map +1 -0
- package/dist/tests/e2e/method-call-cache.test.d.ts +5 -0
- package/dist/tests/e2e/method-call-cache.test.js +65 -0
- package/dist/tests/e2e/method-call-cache.test.js.map +1 -0
- package/dist/tests/e2e/performance-now.test.d.ts +9 -0
- package/dist/tests/e2e/performance-now.test.js +36 -0
- package/dist/tests/e2e/performance-now.test.js.map +1 -0
- package/dist/tests/e2e/property-ic.test.js +33 -0
- package/dist/tests/e2e/property-ic.test.js.map +1 -1
- package/dist/tests/e2e/shape-interning.test.d.ts +16 -0
- package/dist/tests/e2e/shape-interning.test.js +55 -0
- package/dist/tests/e2e/shape-interning.test.js.map +1 -0
- package/dist/tests/e2e/string-utf16.test.js +9 -0
- package/dist/tests/e2e/string-utf16.test.js.map +1 -1
- package/dist/tests/e2e/typed-array-views.test.js +26 -0
- package/dist/tests/e2e/typed-array-views.test.js.map +1 -1
- package/dist/tests/e2e/url-search-params.test.js +19 -0
- package/dist/tests/e2e/url-search-params.test.js.map +1 -1
- package/dist/tests/extensions/gui.test.js +16 -1
- package/dist/tests/extensions/gui.test.js.map +1 -1
- package/dist/tests/helpers.js +1 -0
- package/dist/tests/helpers.js.map +1 -1
- package/dist/tests/parser/expressions.test.js +36 -0
- package/dist/tests/parser/expressions.test.js.map +1 -1
- package/doc/ai/contributing.md +8 -5
- package/doc/ai/extensions.md +12 -3
- package/doc/ai/language-support.md +2 -1
- package/doc/ai/troubleshooting.md +14 -0
- package/doc/ai/zh-CN/contributing.md +6 -3
- package/doc/ai/zh-CN/extensions.md +10 -2
- package/doc/ai/zh-CN/language-support.md +2 -1
- package/doc/ai/zh-CN/troubleshooting.md +12 -0
- package/doc/gui/api.md +35 -4
- package/doc/gui/dom.md +8 -0
- package/doc/gui/input.md +8 -0
- package/doc/gui/known-issues.md +43 -6
- package/doc/gui/runtime.md +16 -1
- package/doc/gui/webgl.md +97 -26
- package/doc/gui-scripts.md +2 -1
- package/doc/gui.md +8 -5
- package/doc/implemented/binder.md +1 -1
- package/doc/implemented/checker.md +9 -0
- package/doc/implemented/codegen.md +7 -0
- package/doc/implemented/parser.md +2 -1
- package/doc/implemented/runtime-core.md +9 -2
- package/doc/implemented/stdlib.md +10 -2
- package/doc/implemented/typed-arrays.md +18 -2
- package/doc/zh-CN/gui/api.md +27 -5
- package/doc/zh-CN/gui/dom.md +6 -0
- package/doc/zh-CN/gui/input.md +7 -0
- package/doc/zh-CN/gui/known-issues.md +30 -5
- package/doc/zh-CN/gui/runtime.md +13 -1
- package/doc/zh-CN/gui/webgl.md +20 -7
- package/doc/zh-CN/gui-scripts.md +2 -1
- package/doc/zh-CN/gui.md +4 -1
- package/doc/zh-CN/implemented/binder.md +1 -1
- package/doc/zh-CN/implemented/checker.md +7 -0
- package/doc/zh-CN/implemented/codegen.md +7 -0
- package/doc/zh-CN/implemented/parser.md +2 -1
- package/doc/zh-CN/implemented/runtime-core.md +9 -2
- package/doc/zh-CN/implemented/stdlib.md +6 -2
- package/doc/zh-CN/implemented/typed-arrays.md +14 -2
- package/package.json +7 -7
- package/runtime/ext_gui/audio.cpp +39 -3
- package/runtime/ext_gui/audio_extra.cpp +353 -0
- package/runtime/ext_gui/audio_extra.h +47 -0
- package/runtime/ext_gui/audio_fft.h +76 -0
- package/runtime/ext_gui/audio_internal.h +21 -0
- package/runtime/ext_gui/audio_mixer.cpp +46 -1
- package/runtime/ext_gui/audio_mixer.h +89 -1
- package/runtime/ext_gui/audio_mixer_extra.cpp +126 -0
- package/runtime/ext_gui/audio_nodes.cpp +242 -0
- package/runtime/ext_gui/audio_nodes_internal.h +81 -0
- package/runtime/ext_gui/audio_nodes_spatial.cpp +375 -0
- package/runtime/ext_gui/browser.cpp +11 -0
- package/runtime/ext_gui/browser_screen.cpp +73 -0
- package/runtime/ext_gui/dom_api.cpp +4 -0
- package/runtime/ext_gui/dom_api_canvas.cpp +9 -1
- package/runtime/ext_gui/dom_api_events.cpp +2 -1
- package/runtime/ext_gui/dom_api_internal.h +11 -0
- package/runtime/ext_gui/dom_api_mutation.cpp +49 -0
- package/runtime/ext_gui/dom_api_node.cpp +21 -0
- package/runtime/ext_gui/dom_api_node_read.cpp +29 -0
- package/runtime/ext_gui/dom_api_proto.cpp +6 -0
- package/runtime/ext_gui/dom_api_webgl2.cpp +16 -11
- package/runtime/ext_gui/dom_api_webgl2_msaa.cpp +64 -0
- package/runtime/ext_gui/dom_api_webgl_compressed.cpp +2 -2
- package/runtime/ext_gui/dom_api_webgl_framebuffer.cpp +68 -11
- package/runtime/ext_gui/dom_api_webgl_methods.h +3 -0
- package/runtime/ext_gui/dom_api_webgl_state.cpp +11 -2
- package/runtime/ext_gui/dom_api_webgl_texture.cpp +6 -6
- package/runtime/ext_gui/gui.cpp +8 -1
- package/runtime/ext_gui/gui_engine.h +20 -2
- package/runtime/ext_gui/gui_events.cpp +31 -126
- package/runtime/ext_gui/gui_input.cpp +148 -0
- package/runtime/ext_gui/gui_webgl.cpp +3 -2
- package/runtime/ext_gui/pointer_lock.cpp +137 -0
- package/runtime/ext_gui/style_ua.cpp +4 -0
- package/runtime/ext_gui/warnings.cpp +1 -1
- package/runtime/ext_gui/webgl.h +102 -7
- package/runtime/ext_gui/webgl_api.h +3 -2
- package/runtime/ext_gui/webgl_blit.cpp +109 -15
- package/runtime/ext_gui/webgl_blit_color.cpp +264 -0
- package/runtime/ext_gui/webgl_blit_depth.cpp +26 -8
- package/runtime/ext_gui/webgl_buffer.cpp +26 -170
- package/runtime/ext_gui/webgl_context.cpp +119 -169
- package/runtime/ext_gui/webgl_draw.cpp +116 -5
- package/runtime/ext_gui/webgl_draw_buffers.cpp +21 -6
- package/runtime/ext_gui/webgl_draw_setup.cpp +1 -0
- package/runtime/ext_gui/webgl_draw_state.h +2 -0
- package/runtime/ext_gui/webgl_feature.cpp +2 -2
- package/runtime/ext_gui/webgl_feature.h +4 -3
- package/runtime/ext_gui/webgl_framebuffer.cpp +346 -0
- package/runtime/ext_gui/webgl_glsl.h +4 -0
- package/runtime/ext_gui/webgl_glsl_rewrite.cpp +78 -47
- package/runtime/ext_gui/webgl_glsl_scan.cpp +14 -0
- package/runtime/ext_gui/webgl_objects.h +18 -2
- package/runtime/ext_gui/webgl_pipeline.cpp +1 -1
- package/runtime/ext_gui/webgl_shader.cpp +1 -1
- package/runtime/ext_gui/webgl_state.cpp +45 -36
- package/runtime/ext_gui/webgl_targets.cpp +440 -0
- package/runtime/ext_gui/webgl_texture.cpp +81 -25
- package/runtime/ext_gui/window.cpp +11 -83
- package/runtime/ext_gui/window_diagnostics.cpp +94 -1
- package/runtime/rt.h +27 -27
- package/runtime/rt_binary.h +44 -0
- package/runtime/rt_internal.h +52 -60
- package/runtime/rt_object.h +83 -0
- package/runtime/rt_profile.h +45 -0
- package/runtime/xt_alloc.c +88 -133
- package/runtime/xt_array_buffer.c +99 -71
- package/runtime/xt_builtins.c +3 -1
- package/runtime/xt_constructors.c +1 -0
- package/runtime/xt_containers/access.inc +96 -11
- package/runtime/xt_containers/arrays.inc +2 -1
- package/runtime/xt_containers/cstr_cache.inc +56 -0
- package/runtime/xt_containers/method_cache.inc +121 -0
- package/runtime/xt_containers/object_keys.inc +58 -0
- package/runtime/xt_containers/objects.inc +47 -79
- package/runtime/xt_containers/shapes.inc +153 -8
- package/runtime/xt_containers.c +4 -0
- package/runtime/xt_gc_release.c +70 -0
- package/runtime/xt_gc_stack.c +83 -0
- package/runtime/xt_gc_verify.c +1 -0
- package/runtime/xt_io/console.inc +66 -0
- package/runtime/xt_io/exception.inc +32 -6
- package/runtime/xt_io/watchdog.inc +101 -0
- package/runtime/xt_io.c +1 -0
- package/runtime/xt_loop.c +23 -3
- package/runtime/xt_pool.c +151 -0
- package/runtime/xt_profile.c +126 -0
- package/runtime/xt_stdlib/dispatch.inc +7 -1
- package/runtime/xt_stdlib/math.inc +272 -57
- package/runtime/xt_stdlib2/json_stringify.inc +1 -2
- package/runtime/xt_stdlib2/regexp-match.inc +17 -0
- package/runtime/xt_storage/indexed_db.c +4 -1
- package/runtime/xt_structured_clone.c +2 -1
- package/runtime/xt_typed_array/construction.inc +10 -0
- package/runtime/xt_typed_array/elements.inc +43 -23
- package/runtime/xt_url.c +50 -0
- package/runtime/xt_values/constructors.inc +4 -1
- package/runtime/xt_values/strings.inc +3 -1
- package/src/ast/common.ts +10 -0
- package/src/binder/references.ts +13 -7
- package/src/checker/source.ts +3 -0
- package/src/cli/main.ts +14 -3
- package/src/codegen/generator/calls/access.ts +5 -10
- package/src/codegen/generator/calls/element-inline.ts +433 -0
- package/src/codegen/generator/calls/invocation.ts +87 -1
- package/src/codegen/generator/calls.ts +5 -0
- package/src/codegen/generator/debug.ts +21 -3
- package/src/codegen/generator/expressions/assignment.ts +11 -2
- package/src/codegen/generator/expressions/global-values.ts +57 -0
- package/src/codegen/generator/expressions/primary.ts +4 -27
- package/src/codegen/generator/expressions.ts +3 -0
- package/src/codegen/generator/layout.ts +54 -0
- package/src/codegen/generator/state.ts +5 -0
- package/src/diagnostics/diagnostic.ts +1 -1
- package/src/diagnostics/source-text.ts +118 -22
- package/src/diagnostics/source.ts +29 -7
- package/src/driver/build-key.ts +21 -1
- package/src/driver/bundler/concatenate.ts +12 -5
- package/src/driver/bundler/graph.ts +2 -2
- package/src/driver/bundler/merge.ts +11 -4
- package/src/driver/bundler/reexport-resolution.ts +2 -0
- package/src/driver/compiler.ts +14 -3
- package/src/driver/frontend.ts +3 -4
- package/src/driver/runtime-objects.ts +4 -0
- package/src/driver/toolchain.ts +28 -5
- package/src/driver/version.ts +1 -1
- package/src/extensions/gui/html.ts +41 -11
- package/src/extensions/gui/index.ts +55 -1
- package/src/extensions/registry.ts +20 -0
- package/src/parser/expressions.ts +2 -2
- package/src/parser/helpers.ts +22 -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) {
|
|
@@ -430,7 +330,9 @@ void xt_gui_render_window(XtGuiWindow *win) {
|
|
|
430
330
|
* is picked up by this same frame. A page that asked for a frame expects it
|
|
431
331
|
* to be presented even when its callback changed nothing visible. */
|
|
432
332
|
if (!win->animation_frames.empty()) win->present_dirty = 1;
|
|
433
|
-
|
|
333
|
+
/* The timestamp is a DOMHighResTimeStamp: the same clock as
|
|
334
|
+
* `performance.now()`, not SDL's machine-uptime tick. */
|
|
335
|
+
xt_gui_run_animation_frames(win, xt_monotonic_ms());
|
|
434
336
|
/* A callback may have closed the window (directly or through the
|
|
435
337
|
* auto-close guard): `xt_gui_quit_window` released the document and the GPU
|
|
436
338
|
* geometry, so there is nothing left to lay out or paint. */
|
|
@@ -532,6 +434,7 @@ void xt_gui_render_window(XtGuiWindow *win) {
|
|
|
532
434
|
SDL_GPUCommandBuffer *cmd = SDL_AcquireGPUCommandBuffer(g_device);
|
|
533
435
|
if (cmd != NULL) {
|
|
534
436
|
SDL_GPUTexture *swapchain = NULL;
|
|
437
|
+
SDL_ClearError();
|
|
535
438
|
SDL_AcquireGPUSwapchainTexture(cmd, win->window, &swapchain, NULL, NULL);
|
|
536
439
|
if (swapchain != NULL) {
|
|
537
440
|
/* Attribute the present: a redraw the window system asked for, one a
|
|
@@ -567,13 +470,15 @@ void xt_gui_render_window(XtGuiWindow *win) {
|
|
|
567
470
|
firstFrame = !win->ready;
|
|
568
471
|
win->ready = 1;
|
|
569
472
|
} else {
|
|
570
|
-
/* No
|
|
571
|
-
*
|
|
572
|
-
*
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
473
|
+
/* No image this frame: SDL's non-blocking acquire skips when the GPU
|
|
474
|
+
* still holds it or the window is hidden. Keep the invalidation pending
|
|
475
|
+
* so the retained paint/upload work presents on the next frame. */
|
|
476
|
+
static int acquire_failure_reported = 0;
|
|
477
|
+
if (!acquire_failure_reported) {
|
|
478
|
+
const char *why = SDL_GetError();
|
|
479
|
+
fprintf(stderr, "xt_gui: swapchain acquire returned no image%s%s\n",
|
|
480
|
+
why != NULL && why[0] != '\0' ? ": " : " (starved)", why ? why : "");
|
|
481
|
+
} acquire_failure_reported = 1;
|
|
577
482
|
win->present_dirty = 1;
|
|
578
483
|
win->present_deferred = 1;
|
|
579
484
|
xtgui::g_perf_frame.starvedFrames += 1;
|
|
@@ -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
|
|
@@ -44,7 +44,8 @@ xtgui::WebGLContext *xt_gui_webgl_find(XtGuiWindow *win, const xtgui::Node *node
|
|
|
44
44
|
return entry == found->second.end() ? nullptr : entry->second.get();
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
xtgui::WebGLContext *xt_gui_webgl_get(XtGuiWindow *win, const xtgui::Node *node, bool webgl2
|
|
47
|
+
xtgui::WebGLContext *xt_gui_webgl_get(XtGuiWindow *win, const xtgui::Node *node, bool webgl2,
|
|
48
|
+
bool antialias) {
|
|
48
49
|
if (win == nullptr || !isCanvasElement(node)) return nullptr;
|
|
49
50
|
xtgui::WebGLContext *existing = xt_gui_webgl_find(win, node);
|
|
50
51
|
if (existing != nullptr) return existing->is_webgl2() == webgl2 ? existing : nullptr;
|
|
@@ -66,7 +67,7 @@ xtgui::WebGLContext *xt_gui_webgl_get(XtGuiWindow *win, const xtgui::Node *node,
|
|
|
66
67
|
if (width_attr != nullptr) xtgui::xt_css_parse_number(*width_attr, &width);
|
|
67
68
|
if (height_attr != nullptr) xtgui::xt_css_parse_number(*height_attr, &height);
|
|
68
69
|
auto context = std::make_unique<xtgui::WebGLContext>(
|
|
69
|
-
next_webgl_id(), (int)(width + 0.5f), (int)(height + 0.5f), webgl2);
|
|
70
|
+
next_webgl_id(), (int)(width + 0.5f), (int)(height + 0.5f), webgl2, antialias);
|
|
70
71
|
xtgui::WebGLContext *raw = context.get();
|
|
71
72
|
g_webgl[win][node] = std::move(context);
|
|
72
73
|
if (win->document != nullptr) {
|
|
@@ -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
|
|
@@ -145,6 +145,10 @@ void xt_style_apply_user_agent(const Node *node, XtStyle *style) {
|
|
|
145
145
|
style->has_border_color = true;
|
|
146
146
|
style->margin.top = style->margin.bottom = {8.0f, Unit::Px};
|
|
147
147
|
}
|
|
148
|
+
/* The HTML UA sheet's `[hidden] { display: none }`, applied last so it wins
|
|
149
|
+
* over the tag defaults above. An author rule still overrides it, and
|
|
150
|
+
* `element.hidden = true` is what most pages use to take a node away. */
|
|
151
|
+
if (node->attr("hidden") != nullptr) style->display = Display::None;
|
|
148
152
|
}
|
|
149
153
|
|
|
150
154
|
} // namespace xtgui
|
|
@@ -115,7 +115,7 @@ const std::unordered_set<std::string> &unsupportedSvgElements() {
|
|
|
115
115
|
const std::unordered_set<std::string> &unsupportedAttributes() {
|
|
116
116
|
static const std::unordered_set<std::string> names = {
|
|
117
117
|
"autofocus", "clip-path", "contenteditable", "controls", "draggable",
|
|
118
|
-
"filter", "
|
|
118
|
+
"filter", "href", "marker-end", "marker-mid",
|
|
119
119
|
"marker-start", "mask", "poster", "sizes", "srcset",
|
|
120
120
|
};
|
|
121
121
|
return names;
|