summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/list.h2
-rw-r--r--doc/classes/CanvasItem.xml4
-rw-r--r--doc/classes/Geometry2D.xml7
-rw-r--r--editor/animation_bezier_editor.cpp3
-rw-r--r--editor/editor_inspector.cpp104
-rw-r--r--editor/editor_inspector.h1
-rw-r--r--editor/editor_node.cpp2
-rw-r--r--editor/filesystem_dock.cpp2
-rw-r--r--editor/plugins/animation_tree_editor_plugin.cpp2
-rw-r--r--editor/plugins/animation_tree_editor_plugin.h2
-rw-r--r--editor/scene_tree_dock.cpp14
-rw-r--r--editor/scene_tree_editor.cpp2
-rw-r--r--modules/opensimplex/open_simplex_noise.cpp2
-rw-r--r--platform/javascript/audio_driver_javascript.cpp20
-rw-r--r--platform/javascript/audio_driver_javascript.h7
-rw-r--r--platform/javascript/display_server_javascript.cpp101
-rw-r--r--platform/javascript/display_server_javascript.h20
-rw-r--r--platform/javascript/javascript_main.cpp52
-rw-r--r--platform/javascript/os_javascript.cpp25
-rw-r--r--platform/javascript/os_javascript.h5
-rw-r--r--platform/linuxbsd/display_server_x11.cpp14
-rw-r--r--platform/linuxbsd/display_server_x11.h1
-rw-r--r--scene/animation/animation_player.cpp2
-rw-r--r--scene/gui/dialogs.cpp1
-rw-r--r--scene/gui/line_edit.cpp2
-rw-r--r--scene/gui/tree.cpp8
-rw-r--r--scene/gui/tree.h4
-rw-r--r--scene/main/canvas_item.cpp2
-rw-r--r--scene/main/canvas_item.h2
-rw-r--r--scene/main/scene_tree.cpp5
-rw-r--r--scene/main/scene_tree.h2
-rw-r--r--scene/main/viewport.cpp44
-rw-r--r--scene/main/viewport.h5
-rw-r--r--scene/main/window.cpp8
-rw-r--r--scene/main/window.h5
-rw-r--r--servers/audio_server.cpp1
36 files changed, 357 insertions, 126 deletions
diff --git a/core/list.h b/core/list.h
index 6052a619fb..f850db5241 100644
--- a/core/list.h
+++ b/core/list.h
@@ -348,7 +348,7 @@ public:
* erase an element in the list, by iterator pointing to it. Return true if it was found/erased.
*/
bool erase(const Element *p_I) {
- if (_data) {
+ if (_data && p_I) {
bool ret = _data->erase(p_I);
if (_data->size_cache == 0) {
diff --git a/doc/classes/CanvasItem.xml b/doc/classes/CanvasItem.xml
index b3a3722836..be361f93f3 100644
--- a/doc/classes/CanvasItem.xml
+++ b/doc/classes/CanvasItem.xml
@@ -285,9 +285,9 @@
</return>
<argument index="0" name="position" type="Vector2">
</argument>
- <argument index="1" name="rotation" type="float">
+ <argument index="1" name="rotation" type="float" default="0.0">
</argument>
- <argument index="2" name="scale" type="Vector2">
+ <argument index="2" name="scale" type="Vector2" default="Vector2( 1, 1 )">
</argument>
<description>
Sets a custom transform for drawing via components. Anything drawn afterwards will be transformed by this.
diff --git a/doc/classes/Geometry2D.xml b/doc/classes/Geometry2D.xml
index ffd4bd108d..86dc8e864a 100644
--- a/doc/classes/Geometry2D.xml
+++ b/doc/classes/Geometry2D.xml
@@ -200,6 +200,13 @@
Inflates or deflates [code]polygon[/code] by [code]delta[/code] units (pixels). If [code]delta[/code] is positive, makes the polygon grow outward. If [code]delta[/code] is negative, shrinks the polygon inward. Returns an array of polygons because inflating/deflating may result in multiple discrete polygons. Returns an empty array if [code]delta[/code] is negative and the absolute value of it approximately exceeds the minimum bounding rectangle dimensions of the polygon.
Each polygon's vertices will be rounded as determined by [code]join_type[/code], see [enum PolyJoinType].
The operation may result in an outer polygon (boundary) and inner polygon (hole) produced which could be distinguished by calling [method is_polygon_clockwise].
+ [b]Note:[/b] To translate the polygon's vertices specifically, use the [method Transform2D.xform] method:
+ [codeblock]
+ var polygon = PackedVector2Array([Vector2(0, 0), Vector2(100, 0), Vector2(100, 100), Vector2(0, 100)])
+ var offset = Vector2(50, 50)
+ polygon = Transform2D(0, offset).xform(polygon)
+ print(polygon) # prints [Vector2(50, 50), Vector2(150, 50), Vector2(150, 150), Vector2(50, 150)]
+ [/codeblock]
</description>
</method>
<method name="offset_polyline">
diff --git a/editor/animation_bezier_editor.cpp b/editor/animation_bezier_editor.cpp
index f880ece88b..e52f234218 100644
--- a/editor/animation_bezier_editor.cpp
+++ b/editor/animation_bezier_editor.cpp
@@ -31,6 +31,7 @@
#include "animation_bezier_editor.h"
#include "editor/editor_node.h"
+#include "editor_scale.h"
float AnimationBezierTrackEdit::_bezier_h_to_pixel(float p_h) {
float h = p_h;
@@ -539,7 +540,7 @@ void AnimationBezierTrackEdit::_play_position_draw() {
if (px >= timeline->get_name_limit() && px < (get_size().width - timeline->get_buttons_width())) {
Color color = get_theme_color("accent_color", "Editor");
- play_position->draw_line(Point2(px, 0), Point2(px, h), color);
+ play_position->draw_line(Point2(px, 0), Point2(px, h), color, Math::round(2 * EDSCALE));
}
}
diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp
index a8ded44323..cc58a0d5a0 100644
--- a/editor/editor_inspector.cpp
+++ b/editor/editor_inspector.cpp
@@ -1504,9 +1504,9 @@ void EditorInspector::update_tree() {
String subgroup_base;
VBoxContainer *category_vbox = nullptr;
- List<PropertyInfo>
- plist;
+ List<PropertyInfo> plist;
object->get_property_list(&plist, true);
+ _update_script_class_properties(*object, plist);
HashMap<String, VBoxContainer *> item_path;
Map<VBoxContainer *, EditorInspectorSection *> section_map;
@@ -1572,7 +1572,28 @@ void EditorInspector::update_tree() {
category_vbox = nullptr; //reset
String type = p.name;
- category->icon = EditorNode::get_singleton()->get_class_icon(type, "Object");
+ if (!ClassDB::class_exists(type) && !ScriptServer::is_global_class(type) && p.hint_string.length() && FileAccess::exists(p.hint_string)) {
+ Ref<Script> s = ResourceLoader::load(p.hint_string, "Script");
+ String base_type;
+ if (s.is_valid()) {
+ base_type = s->get_instance_base_type();
+ }
+ while (s.is_valid()) {
+ StringName name = EditorNode::get_editor_data().script_class_get_name(s->get_path());
+ String icon_path = EditorNode::get_editor_data().script_class_get_icon_path(name);
+ if (name != StringName() && icon_path.length()) {
+ category->icon = ResourceLoader::load(icon_path, "Texture");
+ break;
+ }
+ s = s->get_base_script();
+ }
+ if (category->icon.is_null() && has_theme_icon(base_type, "EditorIcons")) {
+ category->icon = get_theme_icon(base_type, "EditorIcons");
+ }
+ }
+ if (category->icon.is_null()) {
+ category->icon = EditorNode::get_singleton()->get_class_icon(type, "Object");
+ }
category->label = type;
category->bg_color = get_theme_color("prop_category", "Editor");
@@ -2370,6 +2391,83 @@ void EditorInspector::_feature_profile_changed() {
update_tree();
}
+void EditorInspector::_update_script_class_properties(const Object &p_object, List<PropertyInfo> &r_list) const {
+ Ref<Script> script = p_object.get_script();
+ if (script.is_null()) {
+ return;
+ }
+
+ List<StringName> classes;
+ Map<StringName, String> paths;
+
+ // NodeC -> NodeB -> NodeA
+ while (script.is_valid()) {
+ String n = EditorNode::get_editor_data().script_class_get_name(script->get_path());
+ if (n.length()) {
+ classes.push_front(n);
+ } else {
+ n = script->get_path().get_file();
+ classes.push_front(n);
+ }
+ paths[n] = script->get_path();
+ script = script->get_base_script();
+ }
+
+ if (classes.empty()) {
+ return;
+ }
+
+ // Script Variables -> to insert: NodeC..B..A -> bottom (insert_here)
+ List<PropertyInfo>::Element *script_variables = NULL;
+ List<PropertyInfo>::Element *bottom = NULL;
+ List<PropertyInfo>::Element *insert_here = NULL;
+ for (List<PropertyInfo>::Element *E = r_list.front(); E; E = E->next()) {
+ PropertyInfo &pi = E->get();
+ if (pi.name != "Script Variables") {
+ continue;
+ }
+ script_variables = E;
+ bottom = r_list.insert_after(script_variables, PropertyInfo());
+ insert_here = bottom;
+ break;
+ }
+
+ Set<StringName> added;
+ for (List<StringName>::Element *E = classes.front(); E; E = E->next()) {
+ StringName name = E->get();
+ String path = paths[name];
+ Ref<Script> s = ResourceLoader::load(path, "Script");
+ List<PropertyInfo> props;
+ s->get_script_property_list(&props);
+
+ // Script Variables -> NodeA -> bottom (insert_here)
+ List<PropertyInfo>::Element *category = r_list.insert_before(insert_here, PropertyInfo(Variant::NIL, name, PROPERTY_HINT_NONE, path, PROPERTY_USAGE_CATEGORY));
+
+ // Script Variables -> NodeA -> A props... -> bottom (insert_here)
+ for (List<PropertyInfo>::Element *P = props.front(); P; P = P->next()) {
+ PropertyInfo &pi = P->get();
+ if (added.has(pi.name)) {
+ continue;
+ }
+ added.insert(pi.name);
+
+ r_list.insert_before(insert_here, pi);
+ }
+
+ // Script Variables -> NodeA (insert_here) -> A props... -> bottom
+ insert_here = category;
+ }
+
+ // NodeC -> C props... -> NodeB..C..
+ r_list.erase(script_variables);
+ List<PropertyInfo>::Element *to_delete = bottom->next();
+ while (to_delete && !(to_delete->get().usage & PROPERTY_USAGE_CATEGORY)) {
+ r_list.erase(to_delete);
+ to_delete = bottom->next();
+ }
+ r_list.erase(bottom);
+}
+
void EditorInspector::_bind_methods() {
ClassDB::bind_method("_edit_request_change", &EditorInspector::_edit_request_change);
diff --git a/editor/editor_inspector.h b/editor/editor_inspector.h
index 90d995e36d..615ad97766 100644
--- a/editor/editor_inspector.h
+++ b/editor/editor_inspector.h
@@ -332,6 +332,7 @@ class EditorInspector : public ScrollContainer {
void _vscroll_changed(double);
void _feature_profile_changed();
+ void _update_script_class_properties(const Object &p_object, List<PropertyInfo> &r_list) const;
bool _is_property_disabled_by_feature_profile(const StringName &p_property);
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index b30d280023..5a298aabe7 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -3780,8 +3780,6 @@ Ref<Texture2D> EditorNode::get_class_icon(const String &p_class, const String &p
if (icon.is_null()) {
icon = gui_base->get_theme_icon(ScriptServer::get_global_class_base(name), "EditorIcons");
}
-
- return icon;
}
const Map<String, Vector<EditorData::CustomType>> &p_map = EditorNode::get_editor_data().get_custom_types();
diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp
index e1f55bd8a8..133aa39cd3 100644
--- a/editor/filesystem_dock.cpp
+++ b/editor/filesystem_dock.cpp
@@ -2313,7 +2313,7 @@ void FileSystemDock::_tree_rmb_select(const Vector2 &p_pos) {
tree_popup->clear();
tree_popup->set_size(Size2(1, 1));
_file_and_folders_fill_popup(tree_popup, paths);
- tree_popup->set_position(tree->get_global_position() + p_pos);
+ tree_popup->set_position(tree->get_screen_position() + p_pos);
tree_popup->popup();
}
}
diff --git a/editor/plugins/animation_tree_editor_plugin.cpp b/editor/plugins/animation_tree_editor_plugin.cpp
index ec3e25f999..dc813896ff 100644
--- a/editor/plugins/animation_tree_editor_plugin.cpp
+++ b/editor/plugins/animation_tree_editor_plugin.cpp
@@ -238,7 +238,7 @@ AnimationTreeEditor::AnimationTreeEditor() {
add_child(memnew(HSeparator));
singleton = this;
- editor_base = memnew(PanelContainer);
+ editor_base = memnew(MarginContainer);
editor_base->set_v_size_flags(SIZE_EXPAND_FILL);
add_child(editor_base);
diff --git a/editor/plugins/animation_tree_editor_plugin.h b/editor/plugins/animation_tree_editor_plugin.h
index 25af81ea9b..79a010b0c0 100644
--- a/editor/plugins/animation_tree_editor_plugin.h
+++ b/editor/plugins/animation_tree_editor_plugin.h
@@ -55,7 +55,7 @@ class AnimationTreeEditor : public VBoxContainer {
HBoxContainer *path_hb;
AnimationTree *tree;
- PanelContainer *editor_base;
+ MarginContainer *editor_base;
Vector<String> button_path;
Vector<String> edited_path;
diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp
index 9831f1bd31..41b8baeb2f 100644
--- a/editor/scene_tree_dock.cpp
+++ b/editor/scene_tree_dock.cpp
@@ -354,11 +354,15 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
// Prefer nodes that inherit from the current scene root.
Node *current_edited_scene_root = EditorNode::get_singleton()->get_edited_scene();
if (current_edited_scene_root) {
- static const String preferred_types[] = { "Node2D", "Node3D", "Control" };
-
- StringName root_class = current_edited_scene_root->get_class_name();
+ String root_class = current_edited_scene_root->get_class_name();
+ static Vector<String> preferred_types;
+ if (preferred_types.empty()) {
+ preferred_types.push_back("Control");
+ preferred_types.push_back("Node2D");
+ preferred_types.push_back("Node3D");
+ }
- for (int i = 0; i < preferred_types->size(); i++) {
+ for (int i = 0; i < preferred_types.size(); i++) {
if (ClassDB::is_parent_class(root_class, preferred_types[i])) {
create_dialog->set_preferred_search_result_type(preferred_types[i]);
break;
@@ -2399,7 +2403,7 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
}
menu->set_size(Size2(1, 1));
- menu->set_position(p_menu_pos);
+ menu->set_position(get_screen_position() + p_menu_pos);
menu->popup();
return;
}
diff --git a/editor/scene_tree_editor.cpp b/editor/scene_tree_editor.cpp
index 1b818036e1..6f29633188 100644
--- a/editor/scene_tree_editor.cpp
+++ b/editor/scene_tree_editor.cpp
@@ -1072,7 +1072,7 @@ void SceneTreeEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data,
}
void SceneTreeEditor::_rmb_select(const Vector2 &p_pos) {
- emit_signal("rmb_pressed", tree->get_global_transform().xform(p_pos));
+ emit_signal("rmb_pressed", tree->get_screen_transform().xform(p_pos));
}
void SceneTreeEditor::_warning_changed(Node *p_for_node) {
diff --git a/modules/opensimplex/open_simplex_noise.cpp b/modules/opensimplex/open_simplex_noise.cpp
index 00b3d47db9..b08219d258 100644
--- a/modules/opensimplex/open_simplex_noise.cpp
+++ b/modules/opensimplex/open_simplex_noise.cpp
@@ -110,7 +110,7 @@ Ref<Image> OpenSimplexNoise::get_image(int p_width, int p_height) {
for (int i = 0; i < p_height; i++) {
for (int j = 0; j < p_width; j++) {
- float v = get_noise_2d(i, j);
+ float v = get_noise_2d(j, i);
v = v * 0.5 + 0.5; // Normalize [0..1]
uint8_t value = uint8_t(CLAMP(v * 255.0, 0, 255));
wd8[(i * p_width + j) * 4 + 0] = value;
diff --git a/platform/javascript/audio_driver_javascript.cpp b/platform/javascript/audio_driver_javascript.cpp
index b8914414e6..9604914b2c 100644
--- a/platform/javascript/audio_driver_javascript.cpp
+++ b/platform/javascript/audio_driver_javascript.cpp
@@ -36,6 +36,15 @@
AudioDriverJavaScript *AudioDriverJavaScript::singleton = nullptr;
+bool AudioDriverJavaScript::is_available() {
+ return EM_ASM_INT({
+ if (!(window.AudioContext || window.webkitAudioContext)) {
+ return 0;
+ }
+ return 1;
+ }) != 0;
+}
+
const char *AudioDriverJavaScript::get_name() const {
return "JavaScript";
}
@@ -207,12 +216,14 @@ void AudioDriverJavaScript::finish_async() {
/* clang-format off */
EM_ASM({
- var ref = Module.IDHandler.get($0);
+ const id = $0;
+ var ref = Module.IDHandler.get(id);
Module.async_finish.push(new Promise(function(accept, reject) {
if (!ref) {
- console.log("Ref not found!", $0, Module.IDHandler);
+ console.log("Ref not found!", id, Module.IDHandler);
setTimeout(accept, 0);
} else {
+ Module.IDHandler.remove(id);
const context = ref['context'];
// Disconnect script and input.
ref['script'].disconnect();
@@ -226,7 +237,6 @@ void AudioDriverJavaScript::finish_async() {
});
}
}));
- Module.IDHandler.remove($0);
}, id);
/* clang-format on */
}
@@ -293,9 +303,5 @@ Error AudioDriverJavaScript::capture_stop() {
}
AudioDriverJavaScript::AudioDriverJavaScript() {
- _driver_id = 0;
- internal_buffer = nullptr;
- buffer_length = 0;
-
singleton = this;
}
diff --git a/platform/javascript/audio_driver_javascript.h b/platform/javascript/audio_driver_javascript.h
index 9b26be001e..f029a91db0 100644
--- a/platform/javascript/audio_driver_javascript.h
+++ b/platform/javascript/audio_driver_javascript.h
@@ -34,12 +34,13 @@
#include "servers/audio_server.h"
class AudioDriverJavaScript : public AudioDriver {
- float *internal_buffer;
+ float *internal_buffer = nullptr;
- int _driver_id;
- int buffer_length;
+ int _driver_id = 0;
+ int buffer_length = 0;
public:
+ static bool is_available();
void mix_to_js();
void process_capture(float sample);
diff --git a/platform/javascript/display_server_javascript.cpp b/platform/javascript/display_server_javascript.cpp
index 0312efb377..2f0a2faa83 100644
--- a/platform/javascript/display_server_javascript.cpp
+++ b/platform/javascript/display_server_javascript.cpp
@@ -44,18 +44,15 @@
#define DOM_BUTTON_XBUTTON1 3
#define DOM_BUTTON_XBUTTON2 4
+char DisplayServerJavaScript::canvas_id[256] = { 0 };
+static bool cursor_inside_canvas = true;
+
DisplayServerJavaScript *DisplayServerJavaScript::get_singleton() {
return static_cast<DisplayServerJavaScript *>(DisplayServer::get_singleton());
}
// Window (canvas)
-extern "C" EMSCRIPTEN_KEEPALIVE void _set_canvas_id(uint8_t *p_data, int p_data_size) {
- DisplayServerJavaScript *display = DisplayServerJavaScript::get_singleton();
- display->canvas_id.parse_utf8((const char *)p_data, p_data_size);
- display->canvas_id = "#" + display->canvas_id;
-}
-
-static void focus_canvas() {
+void DisplayServerJavaScript::focus_canvas() {
/* clang-format off */
EM_ASM(
Module['canvas'].focus();
@@ -63,7 +60,7 @@ static void focus_canvas() {
/* clang-format on */
}
-static bool is_canvas_focused() {
+bool DisplayServerJavaScript::is_canvas_focused() {
/* clang-format off */
return EM_ASM_INT_V(
return document.activeElement == Module['canvas'];
@@ -71,8 +68,21 @@ static bool is_canvas_focused() {
/* clang-format on */
}
-static Point2 compute_position_in_canvas(int x, int y) {
- DisplayServerJavaScript *display = DisplayServerJavaScript::get_singleton();
+bool DisplayServerJavaScript::check_size_force_redraw() {
+ int canvas_width;
+ int canvas_height;
+ emscripten_get_canvas_element_size(DisplayServerJavaScript::canvas_id, &canvas_width, &canvas_height);
+ if (last_width != canvas_width || last_height != canvas_height) {
+ last_width = canvas_width;
+ last_height = canvas_height;
+ // Update the framebuffer size and for redraw.
+ emscripten_set_canvas_element_size(DisplayServerJavaScript::canvas_id, canvas_width, canvas_height);
+ return true;
+ }
+ return false;
+}
+
+Point2 DisplayServerJavaScript::compute_position_in_canvas(int p_x, int p_y) {
int canvas_x = EM_ASM_INT({
return Module['canvas'].getBoundingClientRect().x;
});
@@ -81,23 +91,22 @@ static Point2 compute_position_in_canvas(int x, int y) {
});
int canvas_width;
int canvas_height;
- emscripten_get_canvas_element_size(display->canvas_id.utf8().get_data(), &canvas_width, &canvas_height);
+ emscripten_get_canvas_element_size(canvas_id, &canvas_width, &canvas_height);
double element_width;
double element_height;
- emscripten_get_element_css_size(display->canvas_id.utf8().get_data(), &element_width, &element_height);
+ emscripten_get_element_css_size(canvas_id, &element_width, &element_height);
- return Point2((int)(canvas_width / element_width * (x - canvas_x)),
- (int)(canvas_height / element_height * (y - canvas_y)));
+ return Point2((int)(canvas_width / element_width * (p_x - canvas_x)),
+ (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) {
DisplayServerJavaScript *display = get_singleton();
// Empty ID is canvas.
String target_id = String::utf8(p_event->id);
- if (target_id.empty() || "#" + target_id == display->canvas_id) {
+ String canvas_str_id = String::utf8(canvas_id);
+ if (target_id.empty() || target_id == canvas_str_id) {
// This event property is the only reliable data on
// browser fullscreen state.
if (p_event->isFullscreen) {
@@ -131,14 +140,14 @@ extern "C" EMSCRIPTEN_KEEPALIVE void _drop_files_callback(char *p_filev[], int p
// Keys
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_alt(emscripten_event_ptr->altKey);
godot_event->set_control(emscripten_event_ptr->ctrlKey);
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;
ev.instance();
ev->set_echo(emscripten_event->repeat);
@@ -289,7 +298,7 @@ EM_BOOL DisplayServerJavaScript::mousemove_callback(int p_event_type, const Emsc
}
// Cursor
-static const char *godot2dom_cursor(DisplayServer::CursorShape p_shape) {
+const char *DisplayServerJavaScript::godot2dom_cursor(DisplayServer::CursorShape p_shape) {
switch (p_shape) {
case DisplayServer::CURSOR_ARROW:
return "auto";
@@ -330,7 +339,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 */
EM_ASM_({
Module['canvas'].style.cursor = UTF8ToString($0);
@@ -338,7 +347,7 @@ static void set_css_cursor(const char *p_cursor) {
/* clang-format on */
}
-static bool is_css_cursor_hidden() {
+bool DisplayServerJavaScript::is_css_cursor_hidden() const {
/* clang-format off */
return EM_ASM_INT({
return Module['canvas'].style.cursor === 'none';
@@ -820,23 +829,6 @@ DisplayServer *DisplayServerJavaScript::create_func(const String &p_rendering_dr
}
DisplayServerJavaScript::DisplayServerJavaScript(const String &p_rendering_driver, WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) {
- /* clang-format off */
- EM_ASM({
- const canvas = Module['canvas'];
- var enc = new TextEncoder("utf-8");
- var buffer = new Uint8Array(enc.encode(canvas.id));
- var len = buffer.byteLength;
- var out = _malloc(len);
- HEAPU8.set(buffer, out);
- ccall("_set_canvas_id",
- "void",
- ["number", "number"],
- [out, len]
- );
- _free(out);
- });
- /* clang-format on */
-
RasterizerDummy::make_current(); // TODO GLES2 in Godot 4.0... or webgpu?
#if 0
EmscriptenWebGLContextAttributes attributes;
@@ -859,7 +851,7 @@ DisplayServerJavaScript::DisplayServerJavaScript(const String &p_rendering_drive
gl_initialization_error = true;
}
- EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_create_context(canvas_id.utf8().get_data(), &attributes);
+ EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_create_context(canvas_id, &attributes);
if (emscripten_webgl_make_context_current(ctx) != EMSCRIPTEN_RESULT_SUCCESS) {
gl_initialization_error = true;
}
@@ -881,7 +873,6 @@ DisplayServerJavaScript::DisplayServerJavaScript(const String &p_rendering_drive
}
EMSCRIPTEN_RESULT result;
- CharString id = canvas_id.utf8();
#define EM_CHECK(ev) \
if (result != EMSCRIPTEN_RESULT_SUCCESS) \
ERR_PRINT("Error while setting " #ev " callback: Code " + itos(result));
@@ -895,16 +886,16 @@ DisplayServerJavaScript::DisplayServerJavaScript(const String &p_rendering_drive
// JavaScript APIs. For APIs that are not (sufficiently) exposed, EM_ASM
// is used below.
SET_EM_CALLBACK(EMSCRIPTEN_EVENT_TARGET_WINDOW, mousemove, mousemove_callback)
- SET_EM_CALLBACK(id.get_data(), mousedown, mouse_button_callback)
+ SET_EM_CALLBACK(canvas_id, mousedown, mouse_button_callback)
SET_EM_CALLBACK(EMSCRIPTEN_EVENT_TARGET_WINDOW, mouseup, mouse_button_callback)
- SET_EM_CALLBACK(id.get_data(), wheel, wheel_callback)
- SET_EM_CALLBACK(id.get_data(), touchstart, touch_press_callback)
- SET_EM_CALLBACK(id.get_data(), touchmove, touchmove_callback)
- SET_EM_CALLBACK(id.get_data(), touchend, touch_press_callback)
- SET_EM_CALLBACK(id.get_data(), touchcancel, touch_press_callback)
- SET_EM_CALLBACK(id.get_data(), keydown, keydown_callback)
- SET_EM_CALLBACK(id.get_data(), keypress, keypress_callback)
- SET_EM_CALLBACK(id.get_data(), keyup, keyup_callback)
+ SET_EM_CALLBACK(canvas_id, wheel, wheel_callback)
+ SET_EM_CALLBACK(canvas_id, touchstart, touch_press_callback)
+ SET_EM_CALLBACK(canvas_id, touchmove, touchmove_callback)
+ SET_EM_CALLBACK(canvas_id, touchend, touch_press_callback)
+ SET_EM_CALLBACK(canvas_id, touchcancel, touch_press_callback)
+ SET_EM_CALLBACK(canvas_id, keydown, keydown_callback)
+ SET_EM_CALLBACK(canvas_id, keypress, keypress_callback)
+ SET_EM_CALLBACK(canvas_id, keyup, keyup_callback)
SET_EM_CALLBACK(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, fullscreenchange, fullscreen_change_callback)
SET_EM_CALLBACK_NOTARGET(gamepadconnected, gamepad_change_callback)
SET_EM_CALLBACK_NOTARGET(gamepaddisconnected, gamepad_change_callback)
@@ -1012,7 +1003,7 @@ Size2i DisplayServerJavaScript::screen_get_size(int p_screen) const {
Rect2i DisplayServerJavaScript::screen_get_usable_rect(int p_screen) const {
int canvas[2];
- emscripten_get_canvas_element_size(canvas_id.utf8().get_data(), canvas, canvas + 1);
+ emscripten_get_canvas_element_size(canvas_id, canvas, canvas + 1);
return Rect2i(0, 0, canvas[0], canvas[1]);
}
@@ -1103,12 +1094,14 @@ Size2i DisplayServerJavaScript::window_get_min_size(WindowID p_window) const {
}
void DisplayServerJavaScript::window_set_size(const Size2i p_size, WindowID p_window) {
- emscripten_set_canvas_element_size(canvas_id.utf8().get_data(), p_size.x, p_size.y);
+ last_width = p_size.x;
+ last_height = p_size.y;
+ emscripten_set_canvas_element_size(canvas_id, p_size.x, p_size.y);
}
Size2i DisplayServerJavaScript::window_get_size(WindowID p_window) const {
int canvas[2];
- emscripten_get_canvas_element_size(canvas_id.utf8().get_data(), canvas, canvas + 1);
+ emscripten_get_canvas_element_size(canvas_id, canvas, canvas + 1);
return Size2(canvas[0], canvas[1]);
}
@@ -1134,7 +1127,7 @@ void DisplayServerJavaScript::window_set_mode(WindowMode p_mode, WindowID p_wind
strategy.canvasResolutionScaleMode = EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_STDDEF;
strategy.filteringMode = EMSCRIPTEN_FULLSCREEN_FILTERING_DEFAULT;
strategy.canvasResizedCallback = nullptr;
- EMSCRIPTEN_RESULT result = emscripten_request_fullscreen_strategy(canvas_id.utf8().get_data(), false, &strategy);
+ EMSCRIPTEN_RESULT result = emscripten_request_fullscreen_strategy(canvas_id, false, &strategy);
ERR_FAIL_COND_MSG(result == EMSCRIPTEN_RESULT_FAILED_NOT_DEFERRED, "Enabling fullscreen is only possible from an input callback for the HTML5 platform.");
ERR_FAIL_COND_MSG(result != EMSCRIPTEN_RESULT_SUCCESS, "Enabling fullscreen is only possible from an input callback for the HTML5 platform.");
} break;
diff --git a/platform/javascript/display_server_javascript.h b/platform/javascript/display_server_javascript.h
index 9860ecdf98..b149665d67 100644
--- a/platform/javascript/display_server_javascript.h
+++ b/platform/javascript/display_server_javascript.h
@@ -53,6 +53,21 @@ class DisplayServerJavaScript : public DisplayServer {
double last_click_ms = 0;
int last_click_button_index = -1;
+ int last_width = 0;
+ int last_height = 0;
+
+ // 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 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 keydown_callback(int p_event_type, const EmscriptenKeyboardEvent *p_event, void *p_user_data);
@@ -81,17 +96,20 @@ protected:
public:
// Override return type to make writing static callbacks less tedious.
static DisplayServerJavaScript *get_singleton();
+ static char canvas_id[256];
WindowMode window_mode = WINDOW_MODE_WINDOWED;
String clipboard;
- String canvas_id;
Callable window_event_callback;
Callable input_event_callback;
Callable input_text_callback;
Callable drop_files_callback;
+ // utilities
+ bool check_size_force_redraw();
+
// from DisplayServer
virtual void alert(const String &p_alert, const String &p_title = "ALERT!");
virtual bool has_feature(Feature p_feature) const;
diff --git a/platform/javascript/javascript_main.cpp b/platform/javascript/javascript_main.cpp
index fd61c46e63..99672745e7 100644
--- a/platform/javascript/javascript_main.cpp
+++ b/platform/javascript/javascript_main.cpp
@@ -30,11 +30,13 @@
#include "core/io/resource_loader.h"
#include "main/main.h"
-#include "os_javascript.h"
+#include "platform/javascript/display_server_javascript.h"
+#include "platform/javascript/os_javascript.h"
#include <emscripten/emscripten.h>
static OS_JavaScript *os = nullptr;
+static uint64_t target_ticks = 0;
void exit_callback() {
emscripten_cancel_main_loop(); // After this, we can exit!
@@ -46,12 +48,32 @@ void exit_callback() {
}
void main_loop_callback() {
+ uint64_t current_ticks = os->get_ticks_usec();
+
+ bool force_draw = DisplayServerJavaScript::get_singleton()->check_size_force_redraw();
+ if (force_draw) {
+ Main::force_redraw();
+ } else if (current_ticks < target_ticks) {
+ return; // Skip frame.
+ }
+
+ int target_fps = Engine::get_singleton()->get_target_fps();
+ if (target_fps > 0) {
+ target_ticks += (uint64_t)(1000000 / target_fps);
+ }
if (os->main_loop_iterate()) {
emscripten_cancel_main_loop(); // Cancel current loop and wait for finalize_async.
+ /* clang-format off */
EM_ASM({
// This will contain the list of operations that need to complete before cleanup.
- Module.async_finish = [];
+ Module.async_finish = [
+ // Always contains at least one async promise, to avoid firing immediately if nothing is added.
+ new Promise(function(accept, reject) {
+ setTimeout(accept, 0);
+ })
+ ];
});
+ /* clang-format on */
os->get_main_loop()->finish();
os->finalize_async(); // Will add all the async finish functions.
EM_ASM({
@@ -79,13 +101,35 @@ extern "C" EMSCRIPTEN_KEEPALIVE void main_after_fs_sync(char *p_idbfs_err) {
ResourceLoader::set_abort_on_missing_resources(false);
Main::start();
os->get_main_loop()->init();
- emscripten_resume_main_loop();
// Immediately run the first iteration.
// We are inside an animation frame, we want to immediately draw on the newly setup canvas.
main_loop_callback();
+ emscripten_resume_main_loop();
}
int main(int argc, char *argv[]) {
+ // Create and mount userfs immediately.
+ EM_ASM({
+ FS.mkdir('/userfs');
+ FS.mount(IDBFS, {}, '/userfs');
+ });
+
+ // Configure locale.
+ char locale_ptr[16];
+ /* clang-format off */
+ EM_ASM({
+ stringToUTF8(Module['locale'], $0, 16);
+ }, locale_ptr);
+ /* clang-format on */
+ setenv("LANG", locale_ptr, true);
+
+ // Ensure the canvas ID.
+ /* clang-format off */
+ EM_ASM({
+ stringToUTF8("#" + Module['canvas'].id, $0, 255);
+ }, DisplayServerJavaScript::canvas_id);
+ /* clang-format on */
+
os = new OS_JavaScript();
Main::setup(argv[0], argc - 1, &argv[1], false);
emscripten_set_main_loop(main_loop_callback, -1, false);
@@ -95,8 +139,6 @@ int main(int argc, char *argv[]) {
// run the 'main_after_fs_sync' function.
/* clang-format off */
EM_ASM({
- FS.mkdir('/userfs');
- FS.mount(IDBFS, {}, '/userfs');
FS.syncfs(true, function(err) {
requestAnimationFrame(function() {
ccall('main_after_fs_sync', null, ['string'], [err ? err.message : ""]);
diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp
index ad4b5a5afa..1ff4304bcf 100644
--- a/platform/javascript/os_javascript.cpp
+++ b/platform/javascript/os_javascript.cpp
@@ -74,18 +74,12 @@ void OS_JavaScript::initialize() {
EngineDebugger::register_uri_handler("ws://", RemoteDebuggerPeerWebSocket::create);
EngineDebugger::register_uri_handler("wss://", RemoteDebuggerPeerWebSocket::create);
#endif
-
- char locale_ptr[16];
- /* clang-format off */
- EM_ASM({
- stringToUTF8(Module['locale'], $0, 16);
- }, locale_ptr);
- /* clang-format on */
- setenv("LANG", locale_ptr, true);
}
void OS_JavaScript::resume_audio() {
- audio_driver_javascript.resume();
+ if (audio_driver_javascript) {
+ audio_driver_javascript->resume();
+ }
}
void OS_JavaScript::set_main_loop(MainLoop *p_main_loop) {
@@ -133,11 +127,17 @@ void OS_JavaScript::delete_main_loop() {
void OS_JavaScript::finalize_async() {
finalizing = true;
- audio_driver_javascript.finish_async();
+ if (audio_driver_javascript) {
+ audio_driver_javascript->finish_async();
+ }
}
void OS_JavaScript::finalize() {
delete_main_loop();
+ if (audio_driver_javascript) {
+ memdelete(audio_driver_javascript);
+ audio_driver_javascript = nullptr;
+ }
}
// Miscellaneous
@@ -246,7 +246,10 @@ void OS_JavaScript::initialize_joypads() {
}
OS_JavaScript::OS_JavaScript() {
- AudioDriverManager::add_driver(&audio_driver_javascript);
+ if (AudioDriverJavaScript::is_available()) {
+ audio_driver_javascript = memnew(AudioDriverJavaScript);
+ AudioDriverManager::add_driver(audio_driver_javascript);
+ }
Vector<Logger *> loggers;
loggers.push_back(memnew(StdLogger));
diff --git a/platform/javascript/os_javascript.h b/platform/javascript/os_javascript.h
index f0f18b44f8..22234f9355 100644
--- a/platform/javascript/os_javascript.h
+++ b/platform/javascript/os_javascript.h
@@ -40,7 +40,7 @@
class OS_JavaScript : public OS_Unix {
MainLoop *main_loop = nullptr;
- AudioDriverJavaScript audio_driver_javascript;
+ AudioDriverJavaScript *audio_driver_javascript = nullptr;
bool finalizing = false;
bool idb_available = false;
@@ -83,6 +83,9 @@ public:
String get_executable_path() const;
virtual Error shell_open(String p_uri);
virtual String get_name() const;
+ // Override default OS implementation which would block the main thread with delay_usec.
+ // Implemented in javascript_main.cpp loop callback instead.
+ virtual void add_frame_delay(bool p_can_draw) {}
virtual bool can_draw() const;
virtual String get_cache_path() const;
diff --git a/platform/linuxbsd/display_server_x11.cpp b/platform/linuxbsd/display_server_x11.cpp
index cb4b0d745b..827d0361b9 100644
--- a/platform/linuxbsd/display_server_x11.cpp
+++ b/platform/linuxbsd/display_server_x11.cpp
@@ -2349,11 +2349,17 @@ void DisplayServerX11::process_events() {
}
if (!focus_found) {
- if (OS::get_singleton()->get_main_loop()) {
- OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_APPLICATION_FOCUS_OUT);
- }
+ uint64_t delta = OS::get_singleton()->get_ticks_msec() - time_since_no_focus;
- app_focused = false;
+ if (delta > 250) {
+ //X11 can go between windows and have no focus for a while, when creating them or something else. Use this as safety to avoid unnecesary focus in/outs.
+ if (OS::get_singleton()->get_main_loop()) {
+ OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_APPLICATION_FOCUS_OUT);
+ }
+ app_focused = false;
+ }
+ } else {
+ time_since_no_focus = OS::get_singleton()->get_ticks_msec();
}
}
diff --git a/platform/linuxbsd/display_server_x11.h b/platform/linuxbsd/display_server_x11.h
index 3d0b2c7e8a..b5d2ea1c63 100644
--- a/platform/linuxbsd/display_server_x11.h
+++ b/platform/linuxbsd/display_server_x11.h
@@ -167,6 +167,7 @@ class DisplayServerX11 : public DisplayServer {
int last_click_button_index;
uint32_t last_button_state;
bool app_focused = false;
+ uint64_t time_since_no_focus = 0;
struct {
int opcode;
diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp
index 319d0171b3..2f39c973a0 100644
--- a/scene/animation/animation_player.cpp
+++ b/scene/animation/animation_player.cpp
@@ -1462,7 +1462,7 @@ void AnimationPlayer::get_argument_options(const StringName &p_function, int p_i
#endif
String pf = p_function;
- if (p_function == "play" || p_function == "play_backwards" || p_function == "remove_animation" || p_function == "has_animation" || p_function == "queue") {
+ if (p_idx == 0 && (p_function == "play" || p_function == "play_backwards" || p_function == "remove_animation" || p_function == "has_animation" || p_function == "queue")) {
List<StringName> al;
get_animation_list(&al);
for (List<StringName>::Element *E = al.front(); E; E = E->next()) {
diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp
index bacc65c7bf..faef979090 100644
--- a/scene/gui/dialogs.cpp
+++ b/scene/gui/dialogs.cpp
@@ -298,6 +298,7 @@ AcceptDialog::AcceptDialog() {
set_visible(false);
set_transient(true);
set_exclusive(true);
+ set_clamp_to_embedder(true);
bg = memnew(Panel);
add_child(bg);
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index 251f31ce4e..27c2c70708 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -51,7 +51,7 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
if (b.is_valid()) {
if (b->is_pressed() && b->get_button_index() == BUTTON_RIGHT && context_menu_enabled) {
- menu->set_position(get_global_transform().xform(get_local_mouse_position()));
+ menu->set_position(get_screen_transform().xform(get_local_mouse_position()));
menu->set_size(Vector2(1, 1));
//menu->set_scale(get_global_transform().get_scale());
menu->popup();
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index 34161a9e80..1ed5b9e598 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -1786,7 +1786,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
case TreeItem::CELL_MODE_STRING: {
//nothing in particular
- if (select_mode == SELECT_MULTI && (get_tree()->get_event_count() == focus_in_id || !already_cursor)) {
+ if (select_mode == SELECT_MULTI && (get_viewport()->get_processed_events_count() == focus_in_id || !already_cursor)) {
bring_up_editor = false;
}
@@ -1861,7 +1861,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
} else {
editor_text = String::num(p_item->cells[col].val, Math::range_step_decimals(p_item->cells[col].step));
- if (select_mode == SELECT_MULTI && get_tree()->get_event_count() == focus_in_id) {
+ if (select_mode == SELECT_MULTI && get_viewport()->get_processed_events_count() == focus_in_id) {
bring_up_editor = false;
}
}
@@ -2787,7 +2787,7 @@ int Tree::_get_title_button_height() const {
void Tree::_notification(int p_what) {
if (p_what == NOTIFICATION_FOCUS_ENTER) {
- focus_in_id = get_tree()->get_event_count();
+ focus_in_id = get_viewport()->get_processed_events_count();
}
if (p_what == NOTIFICATION_MOUSE_EXIT) {
if (cache.hover_type != Cache::CLICK_NONE) {
@@ -3839,7 +3839,7 @@ Tree::Tree() {
add_child(popup_menu);
// popup_menu->set_as_toplevel(true);
- popup_editor = memnew(PopupPanel);
+ popup_editor = memnew(Popup);
popup_editor->set_wrap_controls(true);
add_child(popup_editor);
popup_editor_vb = memnew(VBoxContainer);
diff --git a/scene/gui/tree.h b/scene/gui/tree.h
index 46842e78a0..511565619a 100644
--- a/scene/gui/tree.h
+++ b/scene/gui/tree.h
@@ -359,11 +359,11 @@ private:
VBoxContainer *popup_editor_vb;
- PopupPanel *popup_editor;
+ Popup *popup_editor;
LineEdit *text_editor;
HSlider *value_editor;
bool updating_value_editor;
- int64_t focus_in_id;
+ uint64_t focus_in_id;
PopupMenu *popup_menu;
Vector<ColumnInfo> columns;
diff --git a/scene/main/canvas_item.cpp b/scene/main/canvas_item.cpp
index 721f573f39..d1bf038b8d 100644
--- a/scene/main/canvas_item.cpp
+++ b/scene/main/canvas_item.cpp
@@ -1174,7 +1174,7 @@ void CanvasItem::_bind_methods() {
ClassDB::bind_method(D_METHOD("draw_mesh", "mesh", "texture", "normal_map", "specular_map", "specular_shininess", "transform", "modulate", "texture_filter", "texture_repeat"), &CanvasItem::draw_mesh, DEFVAL(Ref<Texture2D>()), DEFVAL(Ref<Texture2D>()), DEFVAL(Color(1, 1, 1, 1)), DEFVAL(Transform2D()), DEFVAL(Color(1, 1, 1, 1)), DEFVAL(TEXTURE_FILTER_PARENT_NODE), DEFVAL(TEXTURE_REPEAT_PARENT_NODE));
ClassDB::bind_method(D_METHOD("draw_multimesh", "multimesh", "texture", "normal_map", "specular_map", "specular_shininess", "texture_filter", "texture_repeat"), &CanvasItem::draw_multimesh, DEFVAL(Ref<Texture2D>()), DEFVAL(Ref<Texture2D>()), DEFVAL(Color(1, 1, 1, 1)), DEFVAL(TEXTURE_FILTER_PARENT_NODE), DEFVAL(TEXTURE_REPEAT_PARENT_NODE));
- ClassDB::bind_method(D_METHOD("draw_set_transform", "position", "rotation", "scale"), &CanvasItem::draw_set_transform);
+ ClassDB::bind_method(D_METHOD("draw_set_transform", "position", "rotation", "scale"), &CanvasItem::draw_set_transform, DEFVAL(0.0), DEFVAL(Size2(1.0, 1.0)));
ClassDB::bind_method(D_METHOD("draw_set_transform_matrix", "xform"), &CanvasItem::draw_set_transform_matrix);
ClassDB::bind_method(D_METHOD("get_transform"), &CanvasItem::get_transform);
ClassDB::bind_method(D_METHOD("get_global_transform"), &CanvasItem::get_global_transform);
diff --git a/scene/main/canvas_item.h b/scene/main/canvas_item.h
index 31edd424a1..918610ac1e 100644
--- a/scene/main/canvas_item.h
+++ b/scene/main/canvas_item.h
@@ -348,7 +348,7 @@ public:
void draw_string(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_text, const Color &p_modulate = Color(1, 1, 1), int p_clip_w = -1);
float draw_char(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_char, const String &p_next = "", const Color &p_modulate = Color(1, 1, 1));
- void draw_set_transform(const Point2 &p_offset, float p_rot, const Size2 &p_scale);
+ void draw_set_transform(const Point2 &p_offset, float p_rot = 0.0, const Size2 &p_scale = Size2(1.0, 1.0));
void draw_set_transform_matrix(const Transform2D &p_matrix);
static CanvasItem *get_current_item_drawn();
diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp
index a418883506..d6159e089b 100644
--- a/scene/main/scene_tree.cpp
+++ b/scene/main/scene_tree.cpp
@@ -939,10 +939,6 @@ int64_t SceneTree::get_frame() const {
return current_frame;
}
-int64_t SceneTree::get_event_count() const {
- return current_event;
-}
-
Array SceneTree::_get_nodes_in_group(const StringName &p_group) {
Array ret;
Map<StringName, Group>::Element *E = group_map.find(p_group);
@@ -1362,7 +1358,6 @@ SceneTree::SceneTree() {
root = nullptr;
pause = false;
current_frame = 0;
- current_event = 0;
tree_changed_name = "tree_changed";
node_added_name = "node_added";
node_removed_name = "node_removed";
diff --git a/scene/main/scene_tree.h b/scene/main/scene_tree.h
index 57b6b4dcfa..bea29c7605 100644
--- a/scene/main/scene_tree.h
+++ b/scene/main/scene_tree.h
@@ -110,7 +110,6 @@ private:
StringName node_renamed_name;
int64_t current_frame;
- int64_t current_event;
int node_count;
#ifdef TOOLS_ENABLED
@@ -300,7 +299,6 @@ public:
int get_collision_debug_contact_count() { return collision_debug_contacts; }
int64_t get_frame() const;
- int64_t get_event_count() const;
int get_node_count() const;
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 0d5d222f5e..65a72267b1 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -2450,6 +2450,22 @@ void Viewport::_gui_remove_control(Control *p_control) {
}
}
+Window *Viewport::get_base_window() const {
+ Viewport *v = const_cast<Viewport *>(this);
+ Window *w = Object::cast_to<Window>(v);
+ while (!w) {
+ v = v->get_parent_viewport();
+ w = Object::cast_to<Window>(v);
+ }
+
+ return w;
+}
+void Viewport::_gui_remove_focus_for_window(Node *p_window) {
+ if (get_base_window() == p_window) {
+ _gui_remove_focus();
+ }
+}
+
void Viewport::_gui_remove_focus() {
if (gui.key_focus) {
Node *f = gui.key_focus;
@@ -2467,7 +2483,7 @@ void Viewport::_gui_control_grab_focus(Control *p_control) {
if (gui.key_focus && gui.key_focus == p_control) {
return;
}
- get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME, "_viewports", "_gui_remove_focus");
+ get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME, "_viewports", "_gui_remove_focus_for_window", (Node *)get_base_window());
gui.key_focus = p_control;
emit_signal("gui_focus_changed", p_control);
p_control->notification(Control::NOTIFICATION_FOCUS_ENTER);
@@ -2685,6 +2701,27 @@ bool Viewport::_sub_windows_forward_input(const Ref<InputEvent> &p_event) {
if (gui.subwindow_drag == SUB_WINDOW_DRAG_MOVE) {
Vector2 diff = mm->get_position() - gui.subwindow_drag_from;
Rect2i new_rect(gui.subwindow_drag_pos + diff, gui.subwindow_focused->get_size());
+
+ if (gui.subwindow_focused->is_clamped_to_embedder()) {
+ Size2i limit = get_visible_rect().size;
+ if (new_rect.position.x + new_rect.size.x > limit.x) {
+ new_rect.position.x = limit.x - new_rect.size.x;
+ }
+ if (new_rect.position.y + new_rect.size.y > limit.y) {
+ new_rect.position.y = limit.y - new_rect.size.y;
+ }
+
+ if (new_rect.position.x < 0) {
+ new_rect.position.x = 0;
+ }
+
+ int title_height = gui.subwindow_focused->get_flag(Window::FLAG_BORDERLESS) ? 0 : gui.subwindow_focused->get_theme_constant("title_height");
+
+ if (new_rect.position.y < title_height) {
+ new_rect.position.y = title_height;
+ }
+ }
+
gui.subwindow_focused->_rect_changed_callback(new_rect);
}
if (gui.subwindow_drag == SUB_WINDOW_DRAG_CLOSE) {
@@ -2924,6 +2961,8 @@ void Viewport::input(const Ref<InputEvent> &p_event, bool p_local_coords) {
if (!is_input_handled()) {
_gui_input_event(ev);
}
+
+ event_count++;
//get_tree()->call_group(SceneTree::GROUP_CALL_REVERSE|SceneTree::GROUP_CALL_REALTIME|SceneTree::GROUP_CALL_MULIILEVEL,gui_input_group,"_gui_input",ev); //special one for GUI, as controls use their own process check
}
@@ -3305,8 +3344,7 @@ void Viewport::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_disable_input", "disable"), &Viewport::set_disable_input);
ClassDB::bind_method(D_METHOD("is_input_disabled"), &Viewport::is_input_disabled);
- ClassDB::bind_method(D_METHOD("_gui_show_tooltip"), &Viewport::_gui_show_tooltip);
- ClassDB::bind_method(D_METHOD("_gui_remove_focus"), &Viewport::_gui_remove_focus);
+ ClassDB::bind_method(D_METHOD("_gui_remove_focus_for_window"), &Viewport::_gui_remove_focus_for_window);
ClassDB::bind_method(D_METHOD("_post_gui_grab_click_focus"), &Viewport::_post_gui_grab_click_focus);
ClassDB::bind_method(D_METHOD("set_shadow_atlas_size", "size"), &Viewport::set_shadow_atlas_size);
diff --git a/scene/main/viewport.h b/scene/main/viewport.h
index d45b321f73..09ef4354c5 100644
--- a/scene/main/viewport.h
+++ b/scene/main/viewport.h
@@ -392,6 +392,7 @@ private:
void _gui_force_drag(Control *p_base, const Variant &p_data, Control *p_control);
void _gui_set_drag_preview(Control *p_base, Control *p_control);
+ void _gui_remove_focus_for_window(Node *p_window);
void _gui_remove_focus();
void _gui_unfocus_control(Control *p_control);
bool _gui_control_has_focus(const Control *p_control);
@@ -442,6 +443,7 @@ private:
SubWindowResize _sub_window_get_resize_margin(Window *p_subwindow, const Point2 &p_point);
virtual bool _can_consume_input_events() const { return true; }
+ uint64_t event_count = 0;
protected:
void _set_size(const Size2i &p_size, const Size2i &p_size_2d_override, const Rect2i &p_to_screen_rect, const Transform2D &p_stretch_transform, bool p_allocated);
@@ -455,6 +457,8 @@ protected:
virtual void _validate_property(PropertyInfo &property) const;
public:
+ uint64_t get_processed_events_count() const { return event_count; }
+
Listener3D *get_listener() const;
Camera3D *get_camera() const;
@@ -572,6 +576,7 @@ public:
bool is_embedding_subwindows() const;
Viewport *get_parent_viewport() const;
+ Window *get_base_window() const;
void pass_mouse_focus_to(Viewport *p_viewport, Control *p_control);
diff --git a/scene/main/window.cpp b/scene/main/window.cpp
index 8604bb78ac..0463615d4d 100644
--- a/scene/main/window.cpp
+++ b/scene/main/window.cpp
@@ -1251,6 +1251,14 @@ Rect2i Window::get_parent_rect() const {
}
}
+void Window::set_clamp_to_embedder(bool p_enable) {
+ clamp_to_embedder = p_enable;
+}
+
+bool Window::is_clamped_to_embedder() const {
+ return clamp_to_embedder;
+}
+
void Window::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_title", "title"), &Window::set_title);
ClassDB::bind_method(D_METHOD("get_title"), &Window::get_title);
diff --git a/scene/main/window.h b/scene/main/window.h
index 89c94753da..5fd59e06f5 100644
--- a/scene/main/window.h
+++ b/scene/main/window.h
@@ -92,6 +92,7 @@ private:
bool exclusive = false;
bool wrap_controls = false;
bool updating_child_controls = false;
+ bool clamp_to_embedder = false;
void _update_child_controls();
@@ -134,7 +135,6 @@ private:
protected:
Viewport *_get_embedder() const;
-
virtual Rect2i _popup_adjust_rect() const { return Rect2i(); }
virtual void _post_popup() {}
@@ -196,6 +196,9 @@ public:
void set_exclusive(bool p_exclusive);
bool is_exclusive() const;
+ void set_clamp_to_embedder(bool p_enable);
+ bool is_clamped_to_embedder() const;
+
bool can_draw() const;
void set_ime_active(bool p_active);
diff --git a/servers/audio_server.cpp b/servers/audio_server.cpp
index 09d2914e05..6b70f41e57 100644
--- a/servers/audio_server.cpp
+++ b/servers/audio_server.cpp
@@ -184,6 +184,7 @@ void AudioDriverManager::initialize(int p_driver) {
GLOBAL_DEF_RST("audio/enable_audio_input", false);
GLOBAL_DEF_RST("audio/mix_rate", DEFAULT_MIX_RATE);
GLOBAL_DEF_RST("audio/output_latency", DEFAULT_OUTPUT_LATENCY);
+ GLOBAL_DEF_RST("audio/output_latency.web", 50); // Safer default output_latency for web.
int failed_driver = -1;