1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-24 15:26:15 +00:00

More static methods in DisplayServerJavaScript.

Were static functions in cpp file, polluting global namespace.
This commit is contained in:
Fabio Alessandrelli
2020-07-01 02:23:22 +02:00
parent fd92270b0a
commit a1c4c1d318
2 changed files with 19 additions and 9 deletions

View File

@@ -45,13 +45,14 @@
#define DOM_BUTTON_XBUTTON2 4 #define DOM_BUTTON_XBUTTON2 4
char DisplayServerJavaScript::canvas_id[256] = { 0 }; char DisplayServerJavaScript::canvas_id[256] = { 0 };
static bool cursor_inside_canvas = true;
DisplayServerJavaScript *DisplayServerJavaScript::get_singleton() { DisplayServerJavaScript *DisplayServerJavaScript::get_singleton() {
return static_cast<DisplayServerJavaScript *>(DisplayServer::get_singleton()); return static_cast<DisplayServerJavaScript *>(DisplayServer::get_singleton());
} }
// Window (canvas) // Window (canvas)
static void focus_canvas() { void DisplayServerJavaScript::focus_canvas() {
/* clang-format off */ /* clang-format off */
EM_ASM( EM_ASM(
Module['canvas'].focus(); Module['canvas'].focus();
@@ -59,7 +60,7 @@ static void focus_canvas() {
/* clang-format on */ /* clang-format on */
} }
static bool is_canvas_focused() { bool DisplayServerJavaScript::is_canvas_focused() {
/* clang-format off */ /* clang-format off */
return EM_ASM_INT_V( return EM_ASM_INT_V(
return document.activeElement == Module['canvas']; return document.activeElement == Module['canvas'];
@@ -86,8 +87,6 @@ Point2 DisplayServerJavaScript::compute_position_in_canvas(int p_x, int p_y) {
(int)(canvas_height / element_height * (p_y - canvas_y))); (int)(canvas_height / element_height * (p_y - canvas_y)));
} }
static bool cursor_inside_canvas = true;
EM_BOOL DisplayServerJavaScript::fullscreen_change_callback(int p_event_type, const EmscriptenFullscreenChangeEvent *p_event, void *p_user_data) { EM_BOOL DisplayServerJavaScript::fullscreen_change_callback(int p_event_type, const EmscriptenFullscreenChangeEvent *p_event, void *p_user_data) {
DisplayServerJavaScript *display = get_singleton(); DisplayServerJavaScript *display = get_singleton();
// Empty ID is canvas. // Empty ID is canvas.
@@ -127,14 +126,14 @@ extern "C" EMSCRIPTEN_KEEPALIVE void _drop_files_callback(char *p_filev[], int p
// Keys // Keys
template <typename T> template <typename T>
static void dom2godot_mod(T *emscripten_event_ptr, Ref<InputEventWithModifiers> godot_event) { void DisplayServerJavaScript::dom2godot_mod(T *emscripten_event_ptr, Ref<InputEventWithModifiers> godot_event) {
godot_event->set_shift(emscripten_event_ptr->shiftKey); godot_event->set_shift(emscripten_event_ptr->shiftKey);
godot_event->set_alt(emscripten_event_ptr->altKey); godot_event->set_alt(emscripten_event_ptr->altKey);
godot_event->set_control(emscripten_event_ptr->ctrlKey); godot_event->set_control(emscripten_event_ptr->ctrlKey);
godot_event->set_metakey(emscripten_event_ptr->metaKey); godot_event->set_metakey(emscripten_event_ptr->metaKey);
} }
static Ref<InputEventKey> setup_key_event(const EmscriptenKeyboardEvent *emscripten_event) { Ref<InputEventKey> DisplayServerJavaScript::setup_key_event(const EmscriptenKeyboardEvent *emscripten_event) {
Ref<InputEventKey> ev; Ref<InputEventKey> ev;
ev.instance(); ev.instance();
ev->set_echo(emscripten_event->repeat); ev->set_echo(emscripten_event->repeat);
@@ -285,7 +284,7 @@ EM_BOOL DisplayServerJavaScript::mousemove_callback(int p_event_type, const Emsc
} }
// Cursor // Cursor
static const char *godot2dom_cursor(DisplayServer::CursorShape p_shape) { const char *DisplayServerJavaScript::godot2dom_cursor(DisplayServer::CursorShape p_shape) {
switch (p_shape) { switch (p_shape) {
case DisplayServer::CURSOR_ARROW: case DisplayServer::CURSOR_ARROW:
return "auto"; return "auto";
@@ -326,7 +325,7 @@ static const char *godot2dom_cursor(DisplayServer::CursorShape p_shape) {
} }
} }
static void set_css_cursor(const char *p_cursor) { void DisplayServerJavaScript::set_css_cursor(const char *p_cursor) {
/* clang-format off */ /* clang-format off */
EM_ASM_({ EM_ASM_({
Module['canvas'].style.cursor = UTF8ToString($0); Module['canvas'].style.cursor = UTF8ToString($0);
@@ -334,7 +333,7 @@ static void set_css_cursor(const char *p_cursor) {
/* clang-format on */ /* clang-format on */
} }
static bool is_css_cursor_hidden() { bool DisplayServerJavaScript::is_css_cursor_hidden() const {
/* clang-format off */ /* clang-format off */
return EM_ASM_INT({ return EM_ASM_INT({
return Module['canvas'].style.cursor === 'none'; return Module['canvas'].style.cursor === 'none';

View File

@@ -53,7 +53,18 @@ class DisplayServerJavaScript : public DisplayServer {
double last_click_ms = 0; double last_click_ms = 0;
int last_click_button_index = -1; int last_click_button_index = -1;
// utilities
static Point2 compute_position_in_canvas(int p_x, int p_y); 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 const char *godot2dom_cursor(DisplayServer::CursorShape p_shape);
static void set_css_cursor(const char *p_cursor);
bool is_css_cursor_hidden() const;
// events
static EM_BOOL fullscreen_change_callback(int p_event_type, const EmscriptenFullscreenChangeEvent *p_event, void *p_user_data); 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 keydown_callback(int p_event_type, const EmscriptenKeyboardEvent *p_event, void *p_user_data);