diff options
author | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2021-09-10 21:46:22 +0200 |
---|---|---|
committer | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2021-10-05 14:15:07 +0200 |
commit | b2d30c725df3cb04f8a5b93455da13f5945d8b4d (patch) | |
tree | dcf7c205548864913406afd43dc67c5abe158640 /platform/javascript/display_server_javascript.h | |
parent | b1c6826b9f84ad564c41a6d1b1e76b09354b8945 (diff) | |
download | redot-engine-b2d30c725df3cb04f8a5b93455da13f5945d8b4d.tar.gz |
[HTML5] Implement mouse/touch/key events in JS library.
This makes us more independent from emscripten libraries, giving us more
control on the application lifecycle.
Diffstat (limited to 'platform/javascript/display_server_javascript.h')
-rw-r--r-- | platform/javascript/display_server_javascript.h | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/platform/javascript/display_server_javascript.h b/platform/javascript/display_server_javascript.h index 1863ddefeb..4e2da4e96d 100644 --- a/platform/javascript/display_server_javascript.h +++ b/platform/javascript/display_server_javascript.h @@ -38,6 +38,19 @@ class DisplayServerJavaScript : public DisplayServer { private: + struct JSTouchEvent { + uint32_t identifier[32] = { 0 }; + double coords[64] = { 0 }; + }; + JSTouchEvent touch_event; + + struct JSKeyEvent { + char code[32] = { 0 }; + char key[32] = { 0 }; + uint8_t modifiers[4] = { 0 }; + }; + JSKeyEvent key_event; + WindowMode window_mode = WINDOW_MODE_WINDOWED; ObjectID window_attached_instance_id = {}; @@ -47,44 +60,33 @@ private: Callable drop_files_callback; String clipboard; - Ref<InputEventKey> deferred_key_event; Point2 touches[32]; char canvas_id[256] = { 0 }; bool cursor_inside_canvas = true; CursorShape cursor_shape = CURSOR_ARROW; Point2i last_click_pos = Point2(-100, -100); // TODO check this again. - double last_click_ms = 0; + uint64_t last_click_ms = 0; int last_click_button_index = -1; bool swap_cancel_ok = false; // utilities - static Point2 compute_position_in_canvas(int p_x, int p_y); static void focus_canvas(); static bool is_canvas_focused(); - template <typename T> - static void dom2godot_mod(T *emscripten_event_ptr, Ref<InputEventWithModifiers> godot_event); - static Ref<InputEventKey> setup_key_event(const EmscriptenKeyboardEvent *emscripten_event); + static void dom2godot_mod(Ref<InputEventWithModifiers> ev, int p_mod); static const char *godot2dom_cursor(DisplayServer::CursorShape p_shape); // events static EM_BOOL fullscreen_change_callback(int p_event_type, const EmscriptenFullscreenChangeEvent *p_event, void *p_user_data); - static EM_BOOL keydown_callback(int p_event_type, const EmscriptenKeyboardEvent *p_event, void *p_user_data); - static EM_BOOL keypress_callback(int p_event_type, const EmscriptenKeyboardEvent *p_event, void *p_user_data); - static EM_BOOL keyup_callback(int p_event_type, const EmscriptenKeyboardEvent *p_event, void *p_user_data); - + static int mouse_button_callback(int p_pressed, int p_button, double p_x, double p_y, int p_modifiers); + static void mouse_move_callback(double p_x, double p_y, double p_rel_x, double p_rel_y, int p_modifiers); + static int mouse_wheel_callback(double p_delta_x, double p_delta_y); + static void touch_callback(int p_type, int p_count); + static void key_callback(int p_pressed, int p_repeat, int p_modifiers); static void vk_input_text_callback(const char *p_text, int p_cursor); - static EM_BOOL mousemove_callback(int p_event_type, const EmscriptenMouseEvent *p_event, void *p_user_data); - static EM_BOOL mouse_button_callback(int p_event_type, const EmscriptenMouseEvent *p_event, void *p_user_data); - - static EM_BOOL wheel_callback(int p_event_type, const EmscriptenWheelEvent *p_event, void *p_user_data); - - static EM_BOOL touch_press_callback(int p_event_type, const EmscriptenTouchEvent *p_event, void *p_user_data); - static EM_BOOL touchmove_callback(int p_event_type, const EmscriptenTouchEvent *p_event, void *p_user_data); - static EM_BOOL blur_callback(int p_event_type, const EmscriptenFocusEvent *p_event, void *p_user_data); static void gamepad_callback(int p_index, int p_connected, const char *p_id, const char *p_guid); |