1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-05 12:10:55 +00:00

[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.
This commit is contained in:
Fabio Alessandrelli
2021-09-10 21:46:22 +02:00
parent e31a10da98
commit b7ac3c1aeb
7 changed files with 233 additions and 168 deletions

View File

@@ -41,6 +41,19 @@
class OS_JavaScript : public OS_Unix {
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;
VideoMode video_mode;
bool window_maximized;
bool entering_fullscreen;
@@ -50,14 +63,13 @@ private:
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE webgl_ctx;
InputDefault *input;
Ref<InputEventKey> deferred_key_event;
CursorShape cursor_shape;
Point2 touches[32];
char canvas_id[256];
bool cursor_inside_canvas;
Point2i last_click_pos;
double last_click_ms;
uint64_t last_click_ms;
int last_click_button_index;
MainLoop *main_loop;
@@ -70,21 +82,14 @@ private:
bool idb_needs_sync;
bool idb_is_syncing;
static Point2 compute_position_in_canvas(int x, int y);
static EM_BOOL fullscreen_change_callback(int p_event_type, const EmscriptenFullscreenChangeEvent *p_event, void *p_user_data);
static EM_BOOL blur_callback(int p_event_type, const EmscriptenFocusEvent *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 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 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 key_callback(int p_pressed, int p_repeat, int p_modifiers);
static void touch_callback(int p_type, int p_count);
static void gamepad_callback(int p_index, int p_connected, const char *p_id, const char *p_guid);
static void input_text_callback(const char *p_text, int p_cursor);