From 204822ed452036f7be8e51d67f624720874abb87 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Sun, 12 Sep 2021 18:13:54 +0200 Subject: [HTML5] Implement Pointer Lock API in JS library. Removes more emscripten HTML5 library dependencies. --- .../javascript/js/libs/library_godot_display.js | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'platform/javascript/js') diff --git a/platform/javascript/js/libs/library_godot_display.js b/platform/javascript/js/libs/library_godot_display.js index a254c92d4d..fa129f0e56 100644 --- a/platform/javascript/js/libs/library_godot_display.js +++ b/platform/javascript/js/libs/library_godot_display.js @@ -376,6 +376,20 @@ const GodotDisplayCursor = { delete GodotDisplayCursor.cursors[key]; }); }, + lockPointer: function () { + const canvas = GodotConfig.canvas; + if (canvas.requestPointerLock) { + canvas.requestPointerLock(); + } + }, + releasePointer: function () { + if (document.exitPointerLock) { + document.exitPointerLock(); + } + }, + isPointerLocked: function () { + return document.pointerLockElement === GodotConfig.canvas; + }, }, }; mergeInto(LibraryManager.library, GodotDisplayCursor); @@ -850,6 +864,20 @@ const GodotDisplay = { } }, + godot_js_display_cursor_lock_set__sig: 'vi', + godot_js_display_cursor_lock_set: function (p_lock) { + if (p_lock) { + GodotDisplayCursor.lockPointer(); + } else { + GodotDisplayCursor.releasePointer(); + } + }, + + godot_js_display_cursor_is_locked__sig: 'i', + godot_js_display_cursor_is_locked: function () { + return GodotDisplayCursor.isPointerLocked() ? 1 : 0; + }, + /* * Listeners */ -- cgit v1.2.3