|
@@ -1,5 +1,5 @@
|
|
|
/*************************************************************************/
|
|
|
-/* display_server_javascript.cpp */
|
|
|
+/* display_server_web.cpp */
|
|
|
/*************************************************************************/
|
|
|
/* This file is part of: */
|
|
|
/* GODOT ENGINE */
|
|
@@ -28,12 +28,12 @@
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
/*************************************************************************/
|
|
|
|
|
|
-#include "display_server_javascript.h"
|
|
|
+#include "display_server_web.h"
|
|
|
|
|
|
#ifdef GLES3_ENABLED
|
|
|
#include "drivers/gles3/rasterizer_gles3.h"
|
|
|
#endif
|
|
|
-#include "platform/javascript/os_javascript.h"
|
|
|
+#include "platform/web/os_web.h"
|
|
|
#include "servers/rendering/dummy/rasterizer_dummy.h"
|
|
|
|
|
|
#include <emscripten.h>
|
|
@@ -48,17 +48,17 @@
|
|
|
#define DOM_BUTTON_XBUTTON1 3
|
|
|
#define DOM_BUTTON_XBUTTON2 4
|
|
|
|
|
|
-DisplayServerJavaScript *DisplayServerJavaScript::get_singleton() {
|
|
|
- return static_cast<DisplayServerJavaScript *>(DisplayServer::get_singleton());
|
|
|
+DisplayServerWeb *DisplayServerWeb::get_singleton() {
|
|
|
+ return static_cast<DisplayServerWeb *>(DisplayServer::get_singleton());
|
|
|
}
|
|
|
|
|
|
// Window (canvas)
|
|
|
-bool DisplayServerJavaScript::check_size_force_redraw() {
|
|
|
+bool DisplayServerWeb::check_size_force_redraw() {
|
|
|
return godot_js_display_size_update() != 0;
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::fullscreen_change_callback(int p_fullscreen) {
|
|
|
- DisplayServerJavaScript *display = get_singleton();
|
|
|
+void DisplayServerWeb::fullscreen_change_callback(int p_fullscreen) {
|
|
|
+ DisplayServerWeb *display = get_singleton();
|
|
|
if (p_fullscreen) {
|
|
|
display->window_mode = WINDOW_MODE_FULLSCREEN;
|
|
|
} else {
|
|
@@ -67,8 +67,8 @@ void DisplayServerJavaScript::fullscreen_change_callback(int p_fullscreen) {
|
|
|
}
|
|
|
|
|
|
// Drag and drop callback.
|
|
|
-void DisplayServerJavaScript::drop_files_js_callback(char **p_filev, int p_filec) {
|
|
|
- DisplayServerJavaScript *ds = get_singleton();
|
|
|
+void DisplayServerWeb::drop_files_js_callback(char **p_filev, int p_filec) {
|
|
|
+ DisplayServerWeb *ds = get_singleton();
|
|
|
if (!ds) {
|
|
|
ERR_FAIL_MSG("Unable to drop files because the DisplayServer is not active");
|
|
|
}
|
|
@@ -86,9 +86,9 @@ void DisplayServerJavaScript::drop_files_js_callback(char **p_filev, int p_filec
|
|
|
ds->drop_files_callback.callp((const Variant **)&vp, 1, ret, ce);
|
|
|
}
|
|
|
|
|
|
-// JavaScript quit request callback.
|
|
|
-void DisplayServerJavaScript::request_quit_callback() {
|
|
|
- DisplayServerJavaScript *ds = get_singleton();
|
|
|
+// Web quit request callback.
|
|
|
+void DisplayServerWeb::request_quit_callback() {
|
|
|
+ DisplayServerWeb *ds = get_singleton();
|
|
|
if (ds && !ds->window_event_callback.is_null()) {
|
|
|
Variant event = int(DisplayServer::WINDOW_EVENT_CLOSE_REQUEST);
|
|
|
Variant *eventp = &event;
|
|
@@ -100,18 +100,18 @@ void DisplayServerJavaScript::request_quit_callback() {
|
|
|
|
|
|
// Keys
|
|
|
|
|
|
-void DisplayServerJavaScript::dom2godot_mod(Ref<InputEventWithModifiers> ev, int p_mod) {
|
|
|
+void DisplayServerWeb::dom2godot_mod(Ref<InputEventWithModifiers> ev, int p_mod) {
|
|
|
ev->set_shift_pressed(p_mod & 1);
|
|
|
ev->set_alt_pressed(p_mod & 2);
|
|
|
ev->set_ctrl_pressed(p_mod & 4);
|
|
|
ev->set_meta_pressed(p_mod & 8);
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::key_callback(int p_pressed, int p_repeat, int p_modifiers) {
|
|
|
- DisplayServerJavaScript *ds = get_singleton();
|
|
|
+void DisplayServerWeb::key_callback(int p_pressed, int p_repeat, int p_modifiers) {
|
|
|
+ DisplayServerWeb *ds = get_singleton();
|
|
|
JSKeyEvent &key_event = ds->key_event;
|
|
|
// Resume audio context after input in case autoplay was denied.
|
|
|
- OS_JavaScript::get_singleton()->resume_audio();
|
|
|
+ OS_Web::get_singleton()->resume_audio();
|
|
|
|
|
|
Ref<InputEventKey> ev;
|
|
|
ev.instantiate();
|
|
@@ -133,8 +133,8 @@ void DisplayServerJavaScript::key_callback(int p_pressed, int p_repeat, int p_mo
|
|
|
|
|
|
// Mouse
|
|
|
|
|
|
-int DisplayServerJavaScript::mouse_button_callback(int p_pressed, int p_button, double p_x, double p_y, int p_modifiers) {
|
|
|
- DisplayServerJavaScript *ds = get_singleton();
|
|
|
+int DisplayServerWeb::mouse_button_callback(int p_pressed, int p_button, double p_x, double p_y, int p_modifiers) {
|
|
|
+ DisplayServerWeb *ds = get_singleton();
|
|
|
|
|
|
Point2 pos(p_x, p_y);
|
|
|
Ref<InputEventMouseButton> ev;
|
|
@@ -199,7 +199,7 @@ int DisplayServerJavaScript::mouse_button_callback(int p_pressed, int p_button,
|
|
|
|
|
|
Input::get_singleton()->parse_input_event(ev);
|
|
|
// Resume audio context after input in case autoplay was denied.
|
|
|
- OS_JavaScript::get_singleton()->resume_audio();
|
|
|
+ OS_Web::get_singleton()->resume_audio();
|
|
|
|
|
|
// Make sure to flush all events so we can call restricted APIs inside the event.
|
|
|
Input::get_singleton()->flush_buffered_events();
|
|
@@ -209,7 +209,7 @@ int DisplayServerJavaScript::mouse_button_callback(int p_pressed, int p_button,
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::mouse_move_callback(double p_x, double p_y, double p_rel_x, double p_rel_y, int p_modifiers) {
|
|
|
+void DisplayServerWeb::mouse_move_callback(double p_x, double p_y, double p_rel_x, double p_rel_y, int p_modifiers) {
|
|
|
MouseButton input_mask = Input::get_singleton()->get_mouse_button_mask();
|
|
|
// For motion outside the canvas, only read mouse movement if dragging
|
|
|
// started inside the canvas; imitating desktop app behaviour.
|
|
@@ -233,7 +233,7 @@ void DisplayServerJavaScript::mouse_move_callback(double p_x, double p_y, double
|
|
|
}
|
|
|
|
|
|
// Cursor
|
|
|
-const char *DisplayServerJavaScript::godot2dom_cursor(DisplayServer::CursorShape p_shape) {
|
|
|
+const char *DisplayServerWeb::godot2dom_cursor(DisplayServer::CursorShape p_shape) {
|
|
|
switch (p_shape) {
|
|
|
case DisplayServer::CURSOR_ARROW:
|
|
|
return "default";
|
|
@@ -274,15 +274,15 @@ const char *DisplayServerJavaScript::godot2dom_cursor(DisplayServer::CursorShape
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-bool DisplayServerJavaScript::tts_is_speaking() const {
|
|
|
+bool DisplayServerWeb::tts_is_speaking() const {
|
|
|
return godot_js_tts_is_speaking();
|
|
|
}
|
|
|
|
|
|
-bool DisplayServerJavaScript::tts_is_paused() const {
|
|
|
+bool DisplayServerWeb::tts_is_paused() const {
|
|
|
return godot_js_tts_is_paused();
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::update_voices_callback(int p_size, const char **p_voice) {
|
|
|
+void DisplayServerWeb::update_voices_callback(int p_size, const char **p_voice) {
|
|
|
get_singleton()->voices.clear();
|
|
|
for (int i = 0; i < p_size; i++) {
|
|
|
Vector<String> tokens = String::utf8(p_voice[i]).split(";", true, 2);
|
|
@@ -296,12 +296,12 @@ void DisplayServerJavaScript::update_voices_callback(int p_size, const char **p_
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-TypedArray<Dictionary> DisplayServerJavaScript::tts_get_voices() const {
|
|
|
+TypedArray<Dictionary> DisplayServerWeb::tts_get_voices() const {
|
|
|
godot_js_tts_get_voices(update_voices_callback);
|
|
|
return voices;
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::tts_speak(const String &p_text, const String &p_voice, int p_volume, float p_pitch, float p_rate, int p_utterance_id, bool p_interrupt) {
|
|
|
+void DisplayServerWeb::tts_speak(const String &p_text, const String &p_voice, int p_volume, float p_pitch, float p_rate, int p_utterance_id, bool p_interrupt) {
|
|
|
if (p_interrupt) {
|
|
|
tts_stop();
|
|
|
}
|
|
@@ -314,18 +314,18 @@ void DisplayServerJavaScript::tts_speak(const String &p_text, const String &p_vo
|
|
|
CharString string = p_text.utf8();
|
|
|
utterance_ids[p_utterance_id] = string;
|
|
|
|
|
|
- godot_js_tts_speak(string.get_data(), p_voice.utf8().get_data(), CLAMP(p_volume, 0, 100), CLAMP(p_pitch, 0.f, 2.f), CLAMP(p_rate, 0.1f, 10.f), p_utterance_id, DisplayServerJavaScript::_js_utterance_callback);
|
|
|
+ godot_js_tts_speak(string.get_data(), p_voice.utf8().get_data(), CLAMP(p_volume, 0, 100), CLAMP(p_pitch, 0.f, 2.f), CLAMP(p_rate, 0.1f, 10.f), p_utterance_id, DisplayServerWeb::_js_utterance_callback);
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::tts_pause() {
|
|
|
+void DisplayServerWeb::tts_pause() {
|
|
|
godot_js_tts_pause();
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::tts_resume() {
|
|
|
+void DisplayServerWeb::tts_resume() {
|
|
|
godot_js_tts_resume();
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::tts_stop() {
|
|
|
+void DisplayServerWeb::tts_stop() {
|
|
|
for (const KeyValue<int, CharString> &E : utterance_ids) {
|
|
|
tts_post_utterance_event(DisplayServer::TTS_UTTERANCE_CANCELED, E.key);
|
|
|
}
|
|
@@ -333,8 +333,8 @@ void DisplayServerJavaScript::tts_stop() {
|
|
|
godot_js_tts_stop();
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::_js_utterance_callback(int p_event, int p_id, int p_pos) {
|
|
|
- DisplayServerJavaScript *ds = (DisplayServerJavaScript *)DisplayServer::get_singleton();
|
|
|
+void DisplayServerWeb::_js_utterance_callback(int p_event, int p_id, int p_pos) {
|
|
|
+ DisplayServerWeb *ds = (DisplayServerWeb *)DisplayServer::get_singleton();
|
|
|
if (ds->utterance_ids.has(p_id)) {
|
|
|
int pos = 0;
|
|
|
if ((TTSUtteranceEvent)p_event == DisplayServer::TTS_UTTERANCE_BOUNDARY) {
|
|
@@ -358,7 +358,7 @@ void DisplayServerJavaScript::_js_utterance_callback(int p_event, int p_id, int
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::cursor_set_shape(CursorShape p_shape) {
|
|
|
+void DisplayServerWeb::cursor_set_shape(CursorShape p_shape) {
|
|
|
ERR_FAIL_INDEX(p_shape, CURSOR_MAX);
|
|
|
if (cursor_shape == p_shape) {
|
|
|
return;
|
|
@@ -367,11 +367,11 @@ void DisplayServerJavaScript::cursor_set_shape(CursorShape p_shape) {
|
|
|
godot_js_display_cursor_set_shape(godot2dom_cursor(cursor_shape));
|
|
|
}
|
|
|
|
|
|
-DisplayServer::CursorShape DisplayServerJavaScript::cursor_get_shape() const {
|
|
|
+DisplayServer::CursorShape DisplayServerWeb::cursor_get_shape() const {
|
|
|
return cursor_shape;
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::cursor_set_custom_image(const Ref<Resource> &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) {
|
|
|
+void DisplayServerWeb::cursor_set_custom_image(const Ref<Resource> &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) {
|
|
|
if (p_cursor.is_valid()) {
|
|
|
Ref<Texture2D> texture = p_cursor;
|
|
|
Ref<AtlasTexture> atlas_texture = p_cursor;
|
|
@@ -446,8 +446,8 @@ void DisplayServerJavaScript::cursor_set_custom_image(const Ref<Resource> &p_cur
|
|
|
}
|
|
|
|
|
|
// Mouse mode
|
|
|
-void DisplayServerJavaScript::mouse_set_mode(MouseMode p_mode) {
|
|
|
- ERR_FAIL_COND_MSG(p_mode == MOUSE_MODE_CONFINED || p_mode == MOUSE_MODE_CONFINED_HIDDEN, "MOUSE_MODE_CONFINED is not supported for the HTML5 platform.");
|
|
|
+void DisplayServerWeb::mouse_set_mode(MouseMode p_mode) {
|
|
|
+ ERR_FAIL_COND_MSG(p_mode == MOUSE_MODE_CONFINED || p_mode == MOUSE_MODE_CONFINED_HIDDEN, "MOUSE_MODE_CONFINED is not supported for the Web platform.");
|
|
|
if (p_mode == mouse_get_mode()) {
|
|
|
return;
|
|
|
}
|
|
@@ -466,7 +466,7 @@ void DisplayServerJavaScript::mouse_set_mode(MouseMode p_mode) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-DisplayServer::MouseMode DisplayServerJavaScript::mouse_get_mode() const {
|
|
|
+DisplayServer::MouseMode DisplayServerWeb::mouse_get_mode() const {
|
|
|
if (godot_js_display_cursor_is_hidden()) {
|
|
|
return MOUSE_MODE_HIDDEN;
|
|
|
}
|
|
@@ -477,12 +477,12 @@ DisplayServer::MouseMode DisplayServerJavaScript::mouse_get_mode() const {
|
|
|
return MOUSE_MODE_VISIBLE;
|
|
|
}
|
|
|
|
|
|
-Point2i DisplayServerJavaScript::mouse_get_position() const {
|
|
|
+Point2i DisplayServerWeb::mouse_get_position() const {
|
|
|
return Input::get_singleton()->get_mouse_position();
|
|
|
}
|
|
|
|
|
|
// Wheel
|
|
|
-int DisplayServerJavaScript::mouse_wheel_callback(double p_delta_x, double p_delta_y) {
|
|
|
+int DisplayServerWeb::mouse_wheel_callback(double p_delta_x, double p_delta_y) {
|
|
|
if (!godot_js_display_canvas_is_focused()) {
|
|
|
if (get_singleton()->cursor_inside_canvas) {
|
|
|
godot_js_display_canvas_focus();
|
|
@@ -532,8 +532,8 @@ int DisplayServerJavaScript::mouse_wheel_callback(double p_delta_x, double p_del
|
|
|
}
|
|
|
|
|
|
// Touch
|
|
|
-void DisplayServerJavaScript::touch_callback(int p_type, int p_count) {
|
|
|
- DisplayServerJavaScript *ds = get_singleton();
|
|
|
+void DisplayServerWeb::touch_callback(int p_type, int p_count) {
|
|
|
+ DisplayServerWeb *ds = get_singleton();
|
|
|
|
|
|
const JSTouchEvent &touch_event = ds->touch_event;
|
|
|
for (int i = 0; i < p_count; i++) {
|
|
@@ -555,7 +555,7 @@ void DisplayServerJavaScript::touch_callback(int p_type, int p_count) {
|
|
|
Ref<InputEventScreenTouch> ev;
|
|
|
|
|
|
// Resume audio context after input in case autoplay was denied.
|
|
|
- OS_JavaScript::get_singleton()->resume_audio();
|
|
|
+ OS_Web::get_singleton()->resume_audio();
|
|
|
|
|
|
ev.instantiate();
|
|
|
ev->set_index(touch_event.identifier[i]);
|
|
@@ -571,13 +571,13 @@ void DisplayServerJavaScript::touch_callback(int p_type, int p_count) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-bool DisplayServerJavaScript::screen_is_touchscreen(int p_screen) const {
|
|
|
+bool DisplayServerWeb::screen_is_touchscreen(int p_screen) const {
|
|
|
return godot_js_display_touchscreen_is_available();
|
|
|
}
|
|
|
|
|
|
// Virtual Keyboard
|
|
|
-void DisplayServerJavaScript::vk_input_text_callback(const char *p_text, int p_cursor) {
|
|
|
- DisplayServerJavaScript *ds = DisplayServerJavaScript::get_singleton();
|
|
|
+void DisplayServerWeb::vk_input_text_callback(const char *p_text, int p_cursor) {
|
|
|
+ DisplayServerWeb *ds = DisplayServerWeb::get_singleton();
|
|
|
if (!ds || ds->input_text_callback.is_null()) {
|
|
|
return;
|
|
|
}
|
|
@@ -604,20 +604,20 @@ void DisplayServerJavaScript::vk_input_text_callback(const char *p_text, int p_c
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::virtual_keyboard_show(const String &p_existing_text, const Rect2 &p_screen_rect, VirtualKeyboardType p_type, int p_max_input_length, int p_cursor_start, int p_cursor_end) {
|
|
|
+void DisplayServerWeb::virtual_keyboard_show(const String &p_existing_text, const Rect2 &p_screen_rect, VirtualKeyboardType p_type, int p_max_input_length, int p_cursor_start, int p_cursor_end) {
|
|
|
godot_js_display_vk_show(p_existing_text.utf8().get_data(), p_type, p_cursor_start, p_cursor_end);
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::virtual_keyboard_hide() {
|
|
|
+void DisplayServerWeb::virtual_keyboard_hide() {
|
|
|
godot_js_display_vk_hide();
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::window_blur_callback() {
|
|
|
+void DisplayServerWeb::window_blur_callback() {
|
|
|
Input::get_singleton()->release_pressed_events();
|
|
|
}
|
|
|
|
|
|
// Gamepad
|
|
|
-void DisplayServerJavaScript::gamepad_callback(int p_index, int p_connected, const char *p_id, const char *p_guid) {
|
|
|
+void DisplayServerWeb::gamepad_callback(int p_index, int p_connected, const char *p_id, const char *p_guid) {
|
|
|
Input *input = Input::get_singleton();
|
|
|
if (p_connected) {
|
|
|
input->joy_connection_changed(p_index, true, String::utf8(p_id), String::utf8(p_guid));
|
|
@@ -626,7 +626,7 @@ void DisplayServerJavaScript::gamepad_callback(int p_index, int p_connected, con
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::process_joypads() {
|
|
|
+void DisplayServerWeb::process_joypads() {
|
|
|
Input *input = Input::get_singleton();
|
|
|
int32_t pads = godot_js_input_gamepad_sample_count();
|
|
|
int32_t s_btns_num = 0;
|
|
@@ -654,7 +654,7 @@ void DisplayServerJavaScript::process_joypads() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-Vector<String> DisplayServerJavaScript::get_rendering_drivers_func() {
|
|
|
+Vector<String> DisplayServerWeb::get_rendering_drivers_func() {
|
|
|
Vector<String> drivers;
|
|
|
#ifdef GLES3_ENABLED
|
|
|
drivers.push_back("opengl3");
|
|
@@ -663,23 +663,23 @@ Vector<String> DisplayServerJavaScript::get_rendering_drivers_func() {
|
|
|
}
|
|
|
|
|
|
// Clipboard
|
|
|
-void DisplayServerJavaScript::update_clipboard_callback(const char *p_text) {
|
|
|
+void DisplayServerWeb::update_clipboard_callback(const char *p_text) {
|
|
|
get_singleton()->clipboard = String::utf8(p_text);
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::clipboard_set(const String &p_text) {
|
|
|
+void DisplayServerWeb::clipboard_set(const String &p_text) {
|
|
|
clipboard = p_text;
|
|
|
int err = godot_js_display_clipboard_set(p_text.utf8().get_data());
|
|
|
ERR_FAIL_COND_MSG(err, "Clipboard API is not supported.");
|
|
|
}
|
|
|
|
|
|
-String DisplayServerJavaScript::clipboard_get() const {
|
|
|
+String DisplayServerWeb::clipboard_get() const {
|
|
|
godot_js_display_clipboard_get(update_clipboard_callback);
|
|
|
return clipboard;
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::send_window_event_callback(int p_notification) {
|
|
|
- DisplayServerJavaScript *ds = get_singleton();
|
|
|
+void DisplayServerWeb::send_window_event_callback(int p_notification) {
|
|
|
+ DisplayServerWeb *ds = get_singleton();
|
|
|
if (!ds) {
|
|
|
return;
|
|
|
}
|
|
@@ -695,7 +695,7 @@ void DisplayServerJavaScript::send_window_event_callback(int p_notification) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::set_icon(const Ref<Image> &p_icon) {
|
|
|
+void DisplayServerWeb::set_icon(const Ref<Image> &p_icon) {
|
|
|
ERR_FAIL_COND(p_icon.is_null());
|
|
|
Ref<Image> icon = p_icon;
|
|
|
if (icon->is_compressed()) {
|
|
@@ -727,7 +727,7 @@ void DisplayServerJavaScript::set_icon(const Ref<Image> &p_icon) {
|
|
|
godot_js_display_window_icon_set(png.ptr(), len);
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::_dispatch_input_event(const Ref<InputEvent> &p_event) {
|
|
|
+void DisplayServerWeb::_dispatch_input_event(const Ref<InputEvent> &p_event) {
|
|
|
Callable cb = get_singleton()->input_event_callback;
|
|
|
if (!cb.is_null()) {
|
|
|
Variant ev = p_event;
|
|
@@ -738,11 +738,11 @@ void DisplayServerJavaScript::_dispatch_input_event(const Ref<InputEvent> &p_eve
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-DisplayServer *DisplayServerJavaScript::create_func(const String &p_rendering_driver, WindowMode p_window_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Size2i &p_resolution, Error &r_error) {
|
|
|
- return memnew(DisplayServerJavaScript(p_rendering_driver, p_window_mode, p_vsync_mode, p_flags, p_resolution, r_error));
|
|
|
+DisplayServer *DisplayServerWeb::create_func(const String &p_rendering_driver, WindowMode p_window_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Size2i &p_resolution, Error &r_error) {
|
|
|
+ return memnew(DisplayServerWeb(p_rendering_driver, p_window_mode, p_vsync_mode, p_flags, p_resolution, r_error));
|
|
|
}
|
|
|
|
|
|
-DisplayServerJavaScript::DisplayServerJavaScript(const String &p_rendering_driver, WindowMode p_window_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Size2i &p_resolution, Error &r_error) {
|
|
|
+DisplayServerWeb::DisplayServerWeb(const String &p_rendering_driver, WindowMode p_window_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Size2i &p_resolution, Error &r_error) {
|
|
|
r_error = OK; // Always succeeds for now.
|
|
|
|
|
|
// Ensure the canvas ID.
|
|
@@ -788,17 +788,17 @@ DisplayServerJavaScript::DisplayServerJavaScript(const String &p_rendering_drive
|
|
|
#endif
|
|
|
|
|
|
// JS Input interface (js/libs/library_godot_input.js)
|
|
|
- godot_js_input_mouse_button_cb(&DisplayServerJavaScript::mouse_button_callback);
|
|
|
- godot_js_input_mouse_move_cb(&DisplayServerJavaScript::mouse_move_callback);
|
|
|
- godot_js_input_mouse_wheel_cb(&DisplayServerJavaScript::mouse_wheel_callback);
|
|
|
- godot_js_input_touch_cb(&DisplayServerJavaScript::touch_callback, touch_event.identifier, touch_event.coords);
|
|
|
- godot_js_input_key_cb(&DisplayServerJavaScript::key_callback, key_event.code, key_event.key);
|
|
|
+ godot_js_input_mouse_button_cb(&DisplayServerWeb::mouse_button_callback);
|
|
|
+ godot_js_input_mouse_move_cb(&DisplayServerWeb::mouse_move_callback);
|
|
|
+ godot_js_input_mouse_wheel_cb(&DisplayServerWeb::mouse_wheel_callback);
|
|
|
+ godot_js_input_touch_cb(&DisplayServerWeb::touch_callback, touch_event.identifier, touch_event.coords);
|
|
|
+ godot_js_input_key_cb(&DisplayServerWeb::key_callback, key_event.code, key_event.key);
|
|
|
godot_js_input_paste_cb(update_clipboard_callback);
|
|
|
godot_js_input_drop_files_cb(drop_files_js_callback);
|
|
|
- godot_js_input_gamepad_cb(&DisplayServerJavaScript::gamepad_callback);
|
|
|
+ godot_js_input_gamepad_cb(&DisplayServerWeb::gamepad_callback);
|
|
|
|
|
|
// JS Display interface (js/libs/library_godot_display.js)
|
|
|
- godot_js_display_fullscreen_cb(&DisplayServerJavaScript::fullscreen_change_callback);
|
|
|
+ godot_js_display_fullscreen_cb(&DisplayServerWeb::fullscreen_change_callback);
|
|
|
godot_js_display_window_blur_cb(&window_blur_callback);
|
|
|
godot_js_display_notification_cb(&send_window_event_callback,
|
|
|
WINDOW_EVENT_MOUSE_ENTER,
|
|
@@ -810,7 +810,7 @@ DisplayServerJavaScript::DisplayServerJavaScript(const String &p_rendering_drive
|
|
|
Input::get_singleton()->set_event_dispatch_function(_dispatch_input_event);
|
|
|
}
|
|
|
|
|
|
-DisplayServerJavaScript::~DisplayServerJavaScript() {
|
|
|
+DisplayServerWeb::~DisplayServerWeb() {
|
|
|
#ifdef GLES3_ENABLED
|
|
|
if (webgl_ctx) {
|
|
|
emscripten_webgl_commit_frame();
|
|
@@ -819,7 +819,7 @@ DisplayServerJavaScript::~DisplayServerJavaScript() {
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
-bool DisplayServerJavaScript::has_feature(Feature p_feature) const {
|
|
|
+bool DisplayServerWeb::has_feature(Feature p_feature) const {
|
|
|
switch (p_feature) {
|
|
|
//case FEATURE_GLOBAL_MENU:
|
|
|
//case FEATURE_HIDPI:
|
|
@@ -846,139 +846,139 @@ bool DisplayServerJavaScript::has_feature(Feature p_feature) const {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::register_javascript_driver() {
|
|
|
- register_create_function("javascript", create_func, get_rendering_drivers_func);
|
|
|
+void DisplayServerWeb::register_web_driver() {
|
|
|
+ register_create_function("web", create_func, get_rendering_drivers_func);
|
|
|
}
|
|
|
|
|
|
-String DisplayServerJavaScript::get_name() const {
|
|
|
- return "javascript";
|
|
|
+String DisplayServerWeb::get_name() const {
|
|
|
+ return "web";
|
|
|
}
|
|
|
|
|
|
-int DisplayServerJavaScript::get_screen_count() const {
|
|
|
+int DisplayServerWeb::get_screen_count() const {
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
-Point2i DisplayServerJavaScript::screen_get_position(int p_screen) const {
|
|
|
+Point2i DisplayServerWeb::screen_get_position(int p_screen) const {
|
|
|
return Point2i(); // TODO offsetX/Y?
|
|
|
}
|
|
|
|
|
|
-Size2i DisplayServerJavaScript::screen_get_size(int p_screen) const {
|
|
|
+Size2i DisplayServerWeb::screen_get_size(int p_screen) const {
|
|
|
int size[2];
|
|
|
godot_js_display_screen_size_get(size, size + 1);
|
|
|
return Size2(size[0], size[1]);
|
|
|
}
|
|
|
|
|
|
-Rect2i DisplayServerJavaScript::screen_get_usable_rect(int p_screen) const {
|
|
|
+Rect2i DisplayServerWeb::screen_get_usable_rect(int p_screen) const {
|
|
|
int size[2];
|
|
|
godot_js_display_window_size_get(size, size + 1);
|
|
|
return Rect2i(0, 0, size[0], size[1]);
|
|
|
}
|
|
|
|
|
|
-int DisplayServerJavaScript::screen_get_dpi(int p_screen) const {
|
|
|
+int DisplayServerWeb::screen_get_dpi(int p_screen) const {
|
|
|
return godot_js_display_screen_dpi_get();
|
|
|
}
|
|
|
|
|
|
-float DisplayServerJavaScript::screen_get_scale(int p_screen) const {
|
|
|
+float DisplayServerWeb::screen_get_scale(int p_screen) const {
|
|
|
return godot_js_display_pixel_ratio_get();
|
|
|
}
|
|
|
|
|
|
-float DisplayServerJavaScript::screen_get_refresh_rate(int p_screen) const {
|
|
|
- return SCREEN_REFRESH_RATE_FALLBACK; // Javascript doesn't have much of a need for the screen refresh rate, and there's no native way to do so.
|
|
|
+float DisplayServerWeb::screen_get_refresh_rate(int p_screen) const {
|
|
|
+ return SCREEN_REFRESH_RATE_FALLBACK; // Web doesn't have much of a need for the screen refresh rate, and there's no native way to do so.
|
|
|
}
|
|
|
|
|
|
-Vector<DisplayServer::WindowID> DisplayServerJavaScript::get_window_list() const {
|
|
|
+Vector<DisplayServer::WindowID> DisplayServerWeb::get_window_list() const {
|
|
|
Vector<WindowID> ret;
|
|
|
ret.push_back(MAIN_WINDOW_ID);
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-DisplayServerJavaScript::WindowID DisplayServerJavaScript::get_window_at_screen_position(const Point2i &p_position) const {
|
|
|
+DisplayServerWeb::WindowID DisplayServerWeb::get_window_at_screen_position(const Point2i &p_position) const {
|
|
|
return MAIN_WINDOW_ID;
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::window_attach_instance_id(ObjectID p_instance, WindowID p_window) {
|
|
|
+void DisplayServerWeb::window_attach_instance_id(ObjectID p_instance, WindowID p_window) {
|
|
|
window_attached_instance_id = p_instance;
|
|
|
}
|
|
|
|
|
|
-ObjectID DisplayServerJavaScript::window_get_attached_instance_id(WindowID p_window) const {
|
|
|
+ObjectID DisplayServerWeb::window_get_attached_instance_id(WindowID p_window) const {
|
|
|
return window_attached_instance_id;
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::window_set_rect_changed_callback(const Callable &p_callable, WindowID p_window) {
|
|
|
+void DisplayServerWeb::window_set_rect_changed_callback(const Callable &p_callable, WindowID p_window) {
|
|
|
// Not supported.
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::window_set_window_event_callback(const Callable &p_callable, WindowID p_window) {
|
|
|
+void DisplayServerWeb::window_set_window_event_callback(const Callable &p_callable, WindowID p_window) {
|
|
|
window_event_callback = p_callable;
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::window_set_input_event_callback(const Callable &p_callable, WindowID p_window) {
|
|
|
+void DisplayServerWeb::window_set_input_event_callback(const Callable &p_callable, WindowID p_window) {
|
|
|
input_event_callback = p_callable;
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::window_set_input_text_callback(const Callable &p_callable, WindowID p_window) {
|
|
|
+void DisplayServerWeb::window_set_input_text_callback(const Callable &p_callable, WindowID p_window) {
|
|
|
input_text_callback = p_callable;
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::window_set_drop_files_callback(const Callable &p_callable, WindowID p_window) {
|
|
|
+void DisplayServerWeb::window_set_drop_files_callback(const Callable &p_callable, WindowID p_window) {
|
|
|
drop_files_callback = p_callable;
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::window_set_title(const String &p_title, WindowID p_window) {
|
|
|
+void DisplayServerWeb::window_set_title(const String &p_title, WindowID p_window) {
|
|
|
godot_js_display_window_title_set(p_title.utf8().get_data());
|
|
|
}
|
|
|
|
|
|
-int DisplayServerJavaScript::window_get_current_screen(WindowID p_window) const {
|
|
|
+int DisplayServerWeb::window_get_current_screen(WindowID p_window) const {
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::window_set_current_screen(int p_screen, WindowID p_window) {
|
|
|
+void DisplayServerWeb::window_set_current_screen(int p_screen, WindowID p_window) {
|
|
|
// Not implemented.
|
|
|
}
|
|
|
|
|
|
-Point2i DisplayServerJavaScript::window_get_position(WindowID p_window) const {
|
|
|
+Point2i DisplayServerWeb::window_get_position(WindowID p_window) const {
|
|
|
return Point2i(); // TODO Does this need implementation?
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::window_set_position(const Point2i &p_position, WindowID p_window) {
|
|
|
+void DisplayServerWeb::window_set_position(const Point2i &p_position, WindowID p_window) {
|
|
|
// Not supported.
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::window_set_transient(WindowID p_window, WindowID p_parent) {
|
|
|
+void DisplayServerWeb::window_set_transient(WindowID p_window, WindowID p_parent) {
|
|
|
// Not supported.
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::window_set_max_size(const Size2i p_size, WindowID p_window) {
|
|
|
+void DisplayServerWeb::window_set_max_size(const Size2i p_size, WindowID p_window) {
|
|
|
// Not supported.
|
|
|
}
|
|
|
|
|
|
-Size2i DisplayServerJavaScript::window_get_max_size(WindowID p_window) const {
|
|
|
+Size2i DisplayServerWeb::window_get_max_size(WindowID p_window) const {
|
|
|
return Size2i();
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::window_set_min_size(const Size2i p_size, WindowID p_window) {
|
|
|
+void DisplayServerWeb::window_set_min_size(const Size2i p_size, WindowID p_window) {
|
|
|
// Not supported.
|
|
|
}
|
|
|
|
|
|
-Size2i DisplayServerJavaScript::window_get_min_size(WindowID p_window) const {
|
|
|
+Size2i DisplayServerWeb::window_get_min_size(WindowID p_window) const {
|
|
|
return Size2i();
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::window_set_size(const Size2i p_size, WindowID p_window) {
|
|
|
+void DisplayServerWeb::window_set_size(const Size2i p_size, WindowID p_window) {
|
|
|
godot_js_display_desired_size_set(p_size.x, p_size.y);
|
|
|
}
|
|
|
|
|
|
-Size2i DisplayServerJavaScript::window_get_size(WindowID p_window) const {
|
|
|
+Size2i DisplayServerWeb::window_get_size(WindowID p_window) const {
|
|
|
int size[2];
|
|
|
godot_js_display_window_size_get(size, size + 1);
|
|
|
return Size2i(size[0], size[1]);
|
|
|
}
|
|
|
|
|
|
-Size2i DisplayServerJavaScript::window_get_real_size(WindowID p_window) const {
|
|
|
+Size2i DisplayServerWeb::window_get_real_size(WindowID p_window) const {
|
|
|
return window_get_size(p_window);
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::window_set_mode(WindowMode p_mode, WindowID p_window) {
|
|
|
+void DisplayServerWeb::window_set_mode(WindowMode p_mode, WindowID p_window) {
|
|
|
if (window_mode == p_mode) {
|
|
|
return;
|
|
|
}
|
|
@@ -993,65 +993,65 @@ void DisplayServerJavaScript::window_set_mode(WindowMode p_mode, WindowID p_wind
|
|
|
case WINDOW_MODE_EXCLUSIVE_FULLSCREEN:
|
|
|
case WINDOW_MODE_FULLSCREEN: {
|
|
|
int result = godot_js_display_fullscreen_request();
|
|
|
- ERR_FAIL_COND_MSG(result, "The request was denied. Remember that enabling fullscreen is only possible from an input callback for the HTML5 platform.");
|
|
|
+ ERR_FAIL_COND_MSG(result, "The request was denied. Remember that enabling fullscreen is only possible from an input callback for the Web platform.");
|
|
|
} break;
|
|
|
case WINDOW_MODE_MAXIMIZED:
|
|
|
case WINDOW_MODE_MINIMIZED:
|
|
|
- WARN_PRINT("WindowMode MAXIMIZED and MINIMIZED are not supported in HTML5 platform.");
|
|
|
+ WARN_PRINT("WindowMode MAXIMIZED and MINIMIZED are not supported in Web platform.");
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-DisplayServerJavaScript::WindowMode DisplayServerJavaScript::window_get_mode(WindowID p_window) const {
|
|
|
+DisplayServerWeb::WindowMode DisplayServerWeb::window_get_mode(WindowID p_window) const {
|
|
|
return window_mode;
|
|
|
}
|
|
|
|
|
|
-bool DisplayServerJavaScript::window_is_maximize_allowed(WindowID p_window) const {
|
|
|
+bool DisplayServerWeb::window_is_maximize_allowed(WindowID p_window) const {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::window_set_flag(WindowFlags p_flag, bool p_enabled, WindowID p_window) {
|
|
|
+void DisplayServerWeb::window_set_flag(WindowFlags p_flag, bool p_enabled, WindowID p_window) {
|
|
|
// Not supported.
|
|
|
}
|
|
|
|
|
|
-bool DisplayServerJavaScript::window_get_flag(WindowFlags p_flag, WindowID p_window) const {
|
|
|
+bool DisplayServerWeb::window_get_flag(WindowFlags p_flag, WindowID p_window) const {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::window_request_attention(WindowID p_window) {
|
|
|
+void DisplayServerWeb::window_request_attention(WindowID p_window) {
|
|
|
// Not supported.
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::window_move_to_foreground(WindowID p_window) {
|
|
|
+void DisplayServerWeb::window_move_to_foreground(WindowID p_window) {
|
|
|
// Not supported.
|
|
|
}
|
|
|
|
|
|
-bool DisplayServerJavaScript::window_can_draw(WindowID p_window) const {
|
|
|
+bool DisplayServerWeb::window_can_draw(WindowID p_window) const {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-bool DisplayServerJavaScript::can_any_window_draw() const {
|
|
|
+bool DisplayServerWeb::can_any_window_draw() const {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::process_events() {
|
|
|
+void DisplayServerWeb::process_events() {
|
|
|
Input::get_singleton()->flush_buffered_events();
|
|
|
if (godot_js_input_gamepad_sample() == OK) {
|
|
|
process_joypads();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-int DisplayServerJavaScript::get_current_video_driver() const {
|
|
|
+int DisplayServerWeb::get_current_video_driver() const {
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
-bool DisplayServerJavaScript::get_swap_cancel_ok() {
|
|
|
+bool DisplayServerWeb::get_swap_cancel_ok() {
|
|
|
return swap_cancel_ok;
|
|
|
}
|
|
|
|
|
|
-void DisplayServerJavaScript::swap_buffers() {
|
|
|
+void DisplayServerWeb::swap_buffers() {
|
|
|
#ifdef GLES3_ENABLED
|
|
|
if (webgl_ctx) {
|
|
|
emscripten_webgl_commit_frame();
|