summaryrefslogtreecommitdiff
path: root/platform/javascript/js/libs
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2021-09-12 18:13:54 +0200
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2021-10-05 14:15:07 +0200
commit204822ed452036f7be8e51d67f624720874abb87 (patch)
treeb163de6177300e49e1207af3551cb4554d8307e8 /platform/javascript/js/libs
parent7d6c1fdb32d277d1986be60e34b92dbca4e30939 (diff)
[HTML5] Implement Pointer Lock API in JS library.
Removes more emscripten HTML5 library dependencies.
Diffstat (limited to 'platform/javascript/js/libs')
-rw-r--r--platform/javascript/js/libs/library_godot_display.js28
1 files changed, 28 insertions, 0 deletions
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
*/