mirror of
https://github.com/godotengine/godot.git
synced 2025-10-22 09:23:40 +00:00
[HTML5] Opt-in virtual keyboard support.
Added as an export option "Experimental Virtual Keyboard". There is no zoom, so text/line edit must be in the top part of the screen, or it will get hidden by the virtual keyboard. UTF8/Latin-1 only (I think regular UTF-8 should work out of the box in 4.0 but I can't test it). It uses an hidden textarea or input, based on the multiline variable, and only gets activated if the device has a touchscreen. This could cause problems on devices with both touchscreen and a real keyboard (although input should still work in general with some minor focus issues). I'm thinking of a system to detect the first physical keystroke and disable it in case, but it might do more harm then good, so it must be well thought.
This commit is contained in:
parent
9952a5039a
commit
4b38aefd33
7 changed files with 195 additions and 8 deletions
|
@ -897,12 +897,46 @@ Error OS_JavaScript::initialize(const VideoMode &p_desired, int p_video_driver,
|
|||
godot_js_display_paste_cb(&OS_JavaScript::update_clipboard_callback);
|
||||
godot_js_display_drop_files_cb(&OS_JavaScript::drop_files_callback);
|
||||
godot_js_display_gamepad_cb(&OS_JavaScript::gamepad_callback);
|
||||
godot_js_display_vk_cb(&input_text_callback);
|
||||
|
||||
visual_server->init();
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
void OS_JavaScript::input_text_callback(const char *p_text, int p_cursor) {
|
||||
OS_JavaScript *os = OS_JavaScript::get_singleton();
|
||||
if (!os || !os->get_main_loop()) {
|
||||
return;
|
||||
}
|
||||
os->get_main_loop()->input_text(String::utf8(p_text));
|
||||
Ref<InputEventKey> k;
|
||||
for (int i = 0; i < p_cursor; i++) {
|
||||
k.instance();
|
||||
k->set_pressed(true);
|
||||
k->set_echo(false);
|
||||
k->set_scancode(KEY_RIGHT);
|
||||
os->input->parse_input_event(k);
|
||||
k.instance();
|
||||
k->set_pressed(false);
|
||||
k->set_echo(false);
|
||||
k->set_scancode(KEY_RIGHT);
|
||||
os->input->parse_input_event(k);
|
||||
}
|
||||
}
|
||||
|
||||
bool OS_JavaScript::has_virtual_keyboard() const {
|
||||
return godot_js_display_vk_available() != 0;
|
||||
}
|
||||
|
||||
void OS_JavaScript::show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect, bool p_multiline, int p_max_input_length, int p_cursor_start, int p_cursor_end) {
|
||||
godot_js_display_vk_show(p_existing_text.utf8().get_data(), p_multiline, p_cursor_start, p_cursor_end);
|
||||
}
|
||||
|
||||
void OS_JavaScript::hide_virtual_keyboard() {
|
||||
godot_js_display_vk_hide();
|
||||
}
|
||||
|
||||
bool OS_JavaScript::get_swap_ok_cancel() {
|
||||
return swap_ok_cancel;
|
||||
}
|
||||
|
@ -1192,9 +1226,6 @@ OS_JavaScript::OS_JavaScript() {
|
|||
last_click_ms = 0;
|
||||
last_click_pos = Point2(-100, -100);
|
||||
|
||||
last_width = 0;
|
||||
last_height = 0;
|
||||
|
||||
window_maximized = false;
|
||||
entering_fullscreen = false;
|
||||
just_exited_fullscreen = false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue