1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-06 12:20:30 +00:00

[HTML5] Implement Pointer Lock API in JS library.

Removes more emscripten HTML5 library dependencies.
This commit is contained in:
Fabio Alessandrelli
2021-09-12 18:13:54 +02:00
parent 89c6aaa96d
commit c54f5b90e6
3 changed files with 39 additions and 10 deletions

View File

@@ -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
*/