diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2018-12-14 23:47:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-14 23:47:03 +0100 |
commit | 5f32fc82087404ac2c803770dc9d1e3711fc14fd (patch) | |
tree | 8648290c5456f219de0b2315badc52e017a3fa08 /platform/javascript | |
parent | 57c3f6a94ba547cfb4c3bcfd7a3e2e784239fd4e (diff) | |
parent | 51fa23a52a71fcbae5743587b35b179dcc226b92 (diff) |
Merge pull request #20385 from moiman100/unify-double-clicking
Added double clicking to all buttons on Linux and Javascript
Diffstat (limited to 'platform/javascript')
-rw-r--r-- | platform/javascript/os_javascript.cpp | 28 | ||||
-rw-r--r-- | platform/javascript/os_javascript.h | 4 |
2 files changed, 32 insertions, 0 deletions
diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp index 2068fee9e0..1a40f6a979 100644 --- a/platform/javascript/os_javascript.cpp +++ b/platform/javascript/os_javascript.cpp @@ -295,6 +295,30 @@ EM_BOOL OS_JavaScript::mouse_button_callback(int p_event_type, const EmscriptenM default: return false; } + if (ev->is_pressed()) { + + uint64_t diff = p_event->timestamp - os->last_click_ms; + + if (ev->get_button_index() == os->last_click_button_index) { + + if (diff < 400 && Point2(os->last_click_pos).distance_to(ev->get_position()) < 5) { + + os->last_click_ms = 0; + os->last_click_pos = Point2(-100, -100); + os->last_click_button_index = -1; + ev->set_doubleclick(true); + } + + } else { + os->last_click_button_index = ev->get_button_index(); + } + + if (!ev->is_doubleclick()) { + os->last_click_ms += diff; + os->last_click_pos = ev->get_position(); + } + } + int mask = os->input->get_mouse_button_mask(); int button_flag = 1 << (ev->get_button_index() - 1); if (ev->is_pressed()) { @@ -1070,6 +1094,10 @@ OS_JavaScript::OS_JavaScript(int p_argc, char *p_argv[]) { } set_cmdline(p_argv[0], arguments); + last_click_button_index = -1; + last_click_ms = 0; + last_click_pos = Point2(-100, -100); + window_maximized = false; entering_fullscreen = false; just_exited_fullscreen = false; diff --git a/platform/javascript/os_javascript.h b/platform/javascript/os_javascript.h index 79dac5940f..45c1a9d32d 100644 --- a/platform/javascript/os_javascript.h +++ b/platform/javascript/os_javascript.h @@ -52,6 +52,10 @@ class OS_JavaScript : public OS_Unix { CursorShape cursor_shape; Point2 touches[32]; + Point2i last_click_pos; + uint64_t last_click_ms; + int last_click_button_index; + MainLoop *main_loop; AudioDriverJavaScript audio_driver_javascript; |