summaryrefslogtreecommitdiff
path: root/platform/javascript/os_javascript.cpp
diff options
context:
space:
mode:
authorMikko Mustonen <mustonen.mikko@outlook.com>2018-07-20 19:16:09 +0300
committerMikko Mustonen <mustonen.mikko@outlook.com>2018-08-12 12:41:31 +0300
commit51fa23a52a71fcbae5743587b35b179dcc226b92 (patch)
tree48c1dc6df75e80864e5aa9a0e6a9c040ed5e7215 /platform/javascript/os_javascript.cpp
parent64595f0f6ad2aab38fb14f85c077c6e147326624 (diff)
Added double clicking to all buttons
Diffstat (limited to 'platform/javascript/os_javascript.cpp')
-rw-r--r--platform/javascript/os_javascript.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp
index b9d586e233..bb31cb5ab1 100644
--- a/platform/javascript/os_javascript.cpp
+++ b/platform/javascript/os_javascript.cpp
@@ -302,6 +302,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()) {
@@ -957,6 +981,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;
soft_fullscreen_enabled = false;
canvas_size_adjustment_requested = false;