mirror of
https://github.com/godotengine/godot.git
synced 2025-10-20 00:13:30 +00:00
[HTML5] Implement Pointer Lock API in JS library.
Removes more emscripten HTML5 library dependencies.
This commit is contained in:
parent
7d6c1fdb32
commit
204822ed45
3 changed files with 37 additions and 8 deletions
|
@ -373,17 +373,15 @@ void DisplayServerJavaScript::mouse_set_mode(MouseMode p_mode) {
|
|||
|
||||
if (p_mode == MOUSE_MODE_VISIBLE) {
|
||||
godot_js_display_cursor_set_visible(1);
|
||||
emscripten_exit_pointerlock();
|
||||
godot_js_display_cursor_lock_set(0);
|
||||
|
||||
} else if (p_mode == MOUSE_MODE_HIDDEN) {
|
||||
godot_js_display_cursor_set_visible(0);
|
||||
emscripten_exit_pointerlock();
|
||||
godot_js_display_cursor_lock_set(0);
|
||||
|
||||
} else if (p_mode == MOUSE_MODE_CAPTURED) {
|
||||
godot_js_display_cursor_set_visible(1);
|
||||
EMSCRIPTEN_RESULT result = emscripten_request_pointerlock(canvas_id, false);
|
||||
ERR_FAIL_COND_MSG(result == EMSCRIPTEN_RESULT_FAILED_NOT_DEFERRED, "MOUSE_MODE_CAPTURED can only be entered from within an appropriate input callback.");
|
||||
ERR_FAIL_COND_MSG(result != EMSCRIPTEN_RESULT_SUCCESS, "MOUSE_MODE_CAPTURED can only be entered from within an appropriate input callback.");
|
||||
godot_js_display_cursor_lock_set(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -392,9 +390,10 @@ DisplayServer::MouseMode DisplayServerJavaScript::mouse_get_mode() const {
|
|||
return MOUSE_MODE_HIDDEN;
|
||||
}
|
||||
|
||||
EmscriptenPointerlockChangeEvent ev;
|
||||
emscripten_get_pointerlock_status(&ev);
|
||||
return (ev.isActive && String::utf8(ev.id) == String::utf8(&canvas_id[1])) ? MOUSE_MODE_CAPTURED : MOUSE_MODE_VISIBLE;
|
||||
if (godot_js_display_cursor_is_locked()) {
|
||||
return MOUSE_MODE_CAPTURED;
|
||||
}
|
||||
return MOUSE_MODE_VISIBLE;
|
||||
}
|
||||
|
||||
// Wheel
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue