diff options
Diffstat (limited to 'scene/main')
-rw-r--r-- | scene/main/SCsub | 2 | ||||
-rw-r--r-- | scene/main/canvas_layer.cpp | 17 | ||||
-rw-r--r-- | scene/main/http_request.cpp | 17 | ||||
-rw-r--r-- | scene/main/http_request.h | 6 | ||||
-rw-r--r-- | scene/main/instance_placeholder.cpp | 2 | ||||
-rw-r--r-- | scene/main/node.cpp | 121 | ||||
-rw-r--r-- | scene/main/node.h | 17 | ||||
-rw-r--r-- | scene/main/scene_tree.cpp | 38 | ||||
-rw-r--r-- | scene/main/scene_tree.h | 8 | ||||
-rwxr-xr-x | scene/main/timer.cpp | 2 | ||||
-rw-r--r-- | scene/main/viewport.cpp | 272 | ||||
-rw-r--r-- | scene/main/viewport.h | 33 |
12 files changed, 400 insertions, 135 deletions
diff --git a/scene/main/SCsub b/scene/main/SCsub index bf9125be7f..b01e2fd54d 100644 --- a/scene/main/SCsub +++ b/scene/main/SCsub @@ -3,5 +3,3 @@ Import('env') env.add_source_files(env.scene_sources, "*.cpp") - -Export('env') diff --git a/scene/main/canvas_layer.cpp b/scene/main/canvas_layer.cpp index a2e890e7a7..89bc8c1226 100644 --- a/scene/main/canvas_layer.cpp +++ b/scene/main/canvas_layer.cpp @@ -35,7 +35,7 @@ void CanvasLayer::set_layer(int p_xform) { layer = p_xform; if (viewport.is_valid()) - VisualServer::get_singleton()->viewport_set_canvas_layer(viewport, canvas, layer); + VisualServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_position_in_parent()); } int CanvasLayer::get_layer() const { @@ -146,19 +146,28 @@ void CanvasLayer::_notification(int p_what) { vp = Node::get_viewport(); } ERR_FAIL_COND(!vp); + + vp->_canvas_layer_add(this); viewport = vp->get_viewport_rid(); VisualServer::get_singleton()->viewport_attach_canvas(viewport, canvas); - VisualServer::get_singleton()->viewport_set_canvas_layer(viewport, canvas, layer); + VisualServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_position_in_parent()); VisualServer::get_singleton()->viewport_set_canvas_transform(viewport, canvas, transform); } break; case NOTIFICATION_EXIT_TREE: { + vp->_canvas_layer_remove(this); VisualServer::get_singleton()->viewport_remove_canvas(viewport, canvas); viewport = RID(); } break; + case NOTIFICATION_MOVED_IN_PARENT: { + + if (is_inside_tree()) + VisualServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_position_in_parent()); + + } break; } } @@ -179,6 +188,7 @@ RID CanvasLayer::get_viewport() const { void CanvasLayer::set_custom_viewport(Node *p_viewport) { ERR_FAIL_NULL(p_viewport); if (is_inside_tree()) { + vp->_canvas_layer_remove(this); VisualServer::get_singleton()->viewport_remove_canvas(viewport, canvas); viewport = RID(); } @@ -198,10 +208,11 @@ void CanvasLayer::set_custom_viewport(Node *p_viewport) { else vp = Node::get_viewport(); + vp->_canvas_layer_add(this); viewport = vp->get_viewport_rid(); VisualServer::get_singleton()->viewport_attach_canvas(viewport, canvas); - VisualServer::get_singleton()->viewport_set_canvas_layer(viewport, canvas, layer); + VisualServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_position_in_parent()); VisualServer::get_singleton()->viewport_set_canvas_transform(viewport, canvas, transform); } } diff --git a/scene/main/http_request.cpp b/scene/main/http_request.cpp index 4750e05633..a9b7fba9c7 100644 --- a/scene/main/http_request.cpp +++ b/scene/main/http_request.cpp @@ -330,15 +330,13 @@ bool HTTPRequest::_update_connection() { return true; } - if (client->is_response_chunked()) { - body_len = -1; // No body len because chunked, change your webserver configuration if you want body len - } else { - body_len = client->get_response_body_length(); + // No body len (-1) if chunked or no content-length header was provided. + // Change your webserver configuration if you want body len. + body_len = client->get_response_body_length(); - if (body_size_limit >= 0 && body_len > body_size_limit) { - call_deferred("_request_done", RESULT_BODY_SIZE_LIMIT_EXCEEDED, response_code, response_headers, PoolByteArray()); - return true; - } + if (body_size_limit >= 0 && body_len > body_size_limit) { + call_deferred("_request_done", RESULT_BODY_SIZE_LIMIT_EXCEEDED, response_code, response_headers, PoolByteArray()); + return true; } if (download_to_file != String()) { @@ -378,6 +376,9 @@ bool HTTPRequest::_update_connection() { call_deferred("_request_done", RESULT_SUCCESS, response_code, response_headers, body); return true; } + } else if (client->get_status() == HTTPClient::STATUS_DISCONNECTED) { + // We read till EOF, with no errors. Request is done. + call_deferred("_request_done", RESULT_SUCCESS, response_code, response_headers, body); } return false; diff --git a/scene/main/http_request.h b/scene/main/http_request.h index eb5d020bc5..de09d2afda 100644 --- a/scene/main/http_request.h +++ b/scene/main/http_request.h @@ -31,10 +31,10 @@ #ifndef HTTPREQUEST_H #define HTTPREQUEST_H -#include "io/http_client.h" +#include "core/io/http_client.h" +#include "core/os/file_access.h" +#include "core/os/thread.h" #include "node.h" -#include "os/file_access.h" -#include "os/thread.h" class HTTPRequest : public Node { diff --git a/scene/main/instance_placeholder.cpp b/scene/main/instance_placeholder.cpp index 1443d5efbf..0ee5648de2 100644 --- a/scene/main/instance_placeholder.cpp +++ b/scene/main/instance_placeholder.cpp @@ -30,7 +30,7 @@ #include "instance_placeholder.h" -#include "io/resource_loader.h" +#include "core/io/resource_loader.h" #include "scene/resources/packed_scene.h" bool InstancePlaceholder::_set(const StringName &p_name, const Variant &p_value) { diff --git a/scene/main/node.cpp b/scene/main/node.cpp index e30f58e012..ae2ab2af80 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -31,10 +31,10 @@ #include "node.h" #include "core/core_string_names.h" +#include "core/io/resource_loader.h" +#include "core/message_queue.h" +#include "core/print_string.h" #include "instance_placeholder.h" -#include "io/resource_loader.h" -#include "message_queue.h" -#include "print_string.h" #include "scene/resources/packed_scene.h" #include "scene/scene_string_names.h" #include "viewport.h" @@ -157,7 +157,7 @@ void Node::_notification(int p_notification) { // kill children as cleanly as possible while (data.children.size()) { - Node *child = data.children[0]; + Node *child = data.children[data.children.size() - 1]; //begin from the end because its faster and more consistent with creation remove_child(child); memdelete(child); } @@ -238,6 +238,16 @@ void Node::_propagate_enter_tree() { // enter groups } +void Node::_propagate_after_exit_tree() { + + data.blocked++; + for (int i = 0; i < data.children.size(); i++) { + data.children[i]->_propagate_after_exit_tree(); + } + data.blocked--; + emit_signal(SceneStringNames::get_singleton()->tree_exited); +} + void Node::_propagate_exit_tree() { //block while removing children @@ -299,8 +309,6 @@ void Node::_propagate_exit_tree() { data.ready_notified = false; data.tree = NULL; data.depth = -1; - - emit_signal(SceneStringNames::get_singleton()->tree_exited); } void Node::move_child(Node *p_child, int p_pos) { @@ -1174,13 +1182,24 @@ void Node::remove_child(Node *p_child) { ERR_FAIL_COND(data.blocked > 0); } + int child_count = data.children.size(); + Node **children = data.children.ptrw(); int idx = -1; - for (int i = 0; i < data.children.size(); i++) { - if (data.children[i] == p_child) { + if (p_child->data.pos >= 0 && p_child->data.pos < child_count) { + if (children[p_child->data.pos] == p_child) { + idx = p_child->data.pos; + } + } - idx = i; - break; + if (idx == -1) { //maybe removed while unparenting or something and index was not updated, so just in case the above fails, try this. + for (int i = 0; i < child_count; i++) { + + if (children[i] == p_child) { + + idx = i; + break; + } } } @@ -1197,9 +1216,14 @@ void Node::remove_child(Node *p_child) { data.children.remove(idx); - for (int i = idx; i < data.children.size(); i++) { + //update pointer and size + child_count = data.children.size(); + children = data.children.ptrw(); - data.children[i]->data.pos = i; + for (int i = idx; i < child_count; i++) { + + children[i]->data.pos = i; + children[i]->notification(NOTIFICATION_MOVED_IN_PARENT); } p_child->data.parent = NULL; @@ -1207,6 +1231,10 @@ void Node::remove_child(Node *p_child) { // validate owner p_child->_propagate_validate_owner(); + + if (data.inside_tree) { + p_child->_propagate_after_exit_tree(); + } } int Node::get_child_count() const { @@ -1336,6 +1364,19 @@ Node *Node::get_parent() const { return data.parent; } +Node *Node::find_parent(const String &p_mask) const { + + Node *p = data.parent; + while (p) { + + if (p->data.name.operator String().match(p_mask)) + return p; + p = p->data.parent; + } + + return NULL; +} + bool Node::is_a_parent_of(const Node *p_node) const { ERR_FAIL_NULL_V(p_node, false); @@ -1810,7 +1851,7 @@ void Node::set_editable_instance(Node *p_node, bool p_editable) { } } -bool Node::is_editable_instance(Node *p_node) const { +bool Node::is_editable_instance(const Node *p_node) const { if (!p_node) return false; //easier, null is never editable :) @@ -2104,6 +2145,12 @@ void Node::_duplicate_and_reown(Node *p_new_parent, const Map<Node *, Node *> &p node->set(name, value); } + List<GroupInfo> groups; + get_groups(&groups); + + for (List<GroupInfo>::Element *E = groups.front(); E; E = E->next()) + node->add_to_group(E->get().name, E->get().persistent); + node->set_name(get_name()); p_new_parent->add_child(node); @@ -2151,15 +2198,17 @@ void Node::_duplicate_signals(const Node *p_original, Node *p_copy) const { continue; } NodePath ptarget = p_original->get_path_to(target); - Node *copytarget = p_copy->get_node(ptarget); - // Cannot find a path to the duplicate target, so it seems it's not part - // of the duplicated and not yet parented hierarchy, so at least try to connect + Node *copytarget = target; + + // Atempt to find a path to the duplicate target, if it seems it's not part + // of the duplicated and not yet parented hierarchy then at least try to connect // to the same target as the original - if (!copytarget) - copytarget = target; - if (copy && copytarget) { + if (p_copy->has_node(ptarget)) + copytarget = p_copy->get_node(ptarget); + + if (copy && copytarget && !copy->is_connected(E->get().signal, copytarget, E->get().method)) { copy->connect(E->get().signal, copytarget, E->get().method, E->get().binds, E->get().flags); } } @@ -2198,6 +2247,12 @@ Node *Node::duplicate_and_reown(const Map<Node *, Node *> &p_reown_map) const { node->set(name, get(name)); } + List<GroupInfo> groups; + get_groups(&groups); + + for (List<GroupInfo>::Element *E = groups.front(); E; E = E->next()) + node->add_to_group(E->get().name, E->get().persistent); + for (int i = 0; i < get_child_count(); i++) { get_child(i)->_duplicate_and_reown(node, p_reown_map); @@ -2449,6 +2504,7 @@ void Node::_set_tree(SceneTree *p_tree) { tree_changed_b->tree_changed(); } +#ifdef DEBUG_ENABLED static void _Node_debug_sn(Object *p_obj) { Node *n = Object::cast_to<Node>(p_obj); @@ -2470,6 +2526,7 @@ static void _Node_debug_sn(Object *p_obj) { path = String(p->get_name()) + "/" + p->get_path_to(n); print_line(itos(p_obj->get_instance_id()) + " - Stray Node: " + path + " (Type: " + n->get_class() + ")"); } +#endif // DEBUG_ENABLED void Node::_print_stray_nodes() { @@ -2479,7 +2536,6 @@ void Node::_print_stray_nodes() { void Node::print_stray_nodes() { #ifdef DEBUG_ENABLED - ObjectDB::debug_objects(_Node_debug_sn); #endif } @@ -2605,6 +2661,7 @@ void Node::_bind_methods() { ClassDB::bind_method(D_METHOD("get_node", "path"), &Node::get_node); ClassDB::bind_method(D_METHOD("get_parent"), &Node::get_parent); ClassDB::bind_method(D_METHOD("find_node", "mask", "recursive", "owned"), &Node::find_node, DEFVAL(true), DEFVAL(true)); + ClassDB::bind_method(D_METHOD("find_parent", "mask"), &Node::find_parent); ClassDB::bind_method(D_METHOD("has_node_and_resource", "path"), &Node::has_node_and_resource); ClassDB::bind_method(D_METHOD("get_node_and_resource", "path"), &Node::_get_node_and_resource); @@ -2683,7 +2740,7 @@ void Node::_bind_methods() { ClassDB::bind_method(D_METHOD("_set_import_path", "import_path"), &Node::set_import_path); ClassDB::bind_method(D_METHOD("_get_import_path"), &Node::get_import_path); - ADD_PROPERTYNZ(PropertyInfo(Variant::NODE_PATH, "_import_path", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_import_path", "_get_import_path"); + ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "_import_path", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_import_path", "_get_import_path"); { MethodInfo mi; @@ -2741,18 +2798,18 @@ void Node::_bind_methods() { ADD_SIGNAL(MethodInfo("tree_exiting")); ADD_SIGNAL(MethodInfo("tree_exited")); - //ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "process/process" ),"set_process","is_processing") ; - //ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "process/physics_process" ), "set_physics_process","is_physics_processing") ; - //ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "process/input" ), "set_process_input","is_processing_input" ) ; - //ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "process/unhandled_input" ), "set_process_unhandled_input","is_processing_unhandled_input" ) ; + //ADD_PROPERTY( PropertyInfo( Variant::BOOL, "process/process" ),"set_process","is_processing") ; + //ADD_PROPERTY( PropertyInfo( Variant::BOOL, "process/physics_process" ), "set_physics_process","is_physics_processing") ; + //ADD_PROPERTY( PropertyInfo( Variant::BOOL, "process/input" ), "set_process_input","is_processing_input" ) ; + //ADD_PROPERTY( PropertyInfo( Variant::BOOL, "process/unhandled_input" ), "set_process_unhandled_input","is_processing_unhandled_input" ) ; ADD_GROUP("Pause", "pause_"); - ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "pause_mode", PROPERTY_HINT_ENUM, "Inherit,Stop,Process"), "set_pause_mode", "get_pause_mode"); - ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "editor/display_folded", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "set_display_folded", "is_displayed_folded"); - ADD_PROPERTYNZ(PropertyInfo(Variant::STRING, "name", PROPERTY_HINT_NONE, "", 0), "set_name", "get_name"); - ADD_PROPERTYNZ(PropertyInfo(Variant::STRING, "filename", PROPERTY_HINT_NONE, "", 0), "set_filename", "get_filename"); - ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "owner", PROPERTY_HINT_RESOURCE_TYPE, "Node", 0), "set_owner", "get_owner"); - ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "multiplayer", PROPERTY_HINT_RESOURCE_TYPE, "MultiplayerAPI", 0), "", "get_multiplayer"); - ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "custom_multiplayer", PROPERTY_HINT_RESOURCE_TYPE, "MultiplayerAPI", 0), "set_custom_multiplayer", "get_custom_multiplayer"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "pause_mode", PROPERTY_HINT_ENUM, "Inherit,Stop,Process"), "set_pause_mode", "get_pause_mode"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editor/display_folded", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "set_display_folded", "is_displayed_folded"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "name", PROPERTY_HINT_NONE, "", 0), "set_name", "get_name"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "filename", PROPERTY_HINT_NONE, "", 0), "set_filename", "get_filename"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "owner", PROPERTY_HINT_RESOURCE_TYPE, "Node", 0), "set_owner", "get_owner"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "multiplayer", PROPERTY_HINT_RESOURCE_TYPE, "MultiplayerAPI", 0), "", "get_multiplayer"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "custom_multiplayer", PROPERTY_HINT_RESOURCE_TYPE, "MultiplayerAPI", 0), "set_custom_multiplayer", "get_custom_multiplayer"); BIND_VMETHOD(MethodInfo("_process", PropertyInfo(Variant::REAL, "delta"))); BIND_VMETHOD(MethodInfo("_physics_process", PropertyInfo(Variant::REAL, "delta"))); diff --git a/scene/main/node.h b/scene/main/node.h index f3422618ce..78db12dda9 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -31,13 +31,13 @@ #ifndef NODE_H #define NODE_H -#include "class_db.h" -#include "map.h" -#include "node_path.h" -#include "object.h" -#include "project_settings.h" +#include "core/class_db.h" +#include "core/map.h" +#include "core/node_path.h" +#include "core/object.h" +#include "core/project_settings.h" +#include "core/script_language.h" #include "scene/main/scene_tree.h" -#include "script_language.h" class Viewport; class SceneState; @@ -166,6 +166,7 @@ private: void _propagate_enter_tree(); void _propagate_ready(); void _propagate_exit_tree(); + void _propagate_after_exit_tree(); void _propagate_validate_owner(); void _print_stray_nodes(); void _propagate_pause_owner(Node *p_owner); @@ -256,6 +257,8 @@ public: Node *get_node_and_resource(const NodePath &p_path, RES &r_res, Vector<StringName> &r_leftover_subpath, bool p_last_is_property = true) const; Node *get_parent() const; + Node *find_parent(const String &p_mask) const; + _FORCE_INLINE_ SceneTree *get_tree() const { ERR_FAIL_COND_V(!data.tree, NULL); return data.tree; @@ -300,7 +303,7 @@ public: String get_filename() const; void set_editable_instance(Node *p_node, bool p_editable); - bool is_editable_instance(Node *p_node) const; + bool is_editable_instance(const Node *p_node) const; void set_editable_instances(const HashMap<NodePath, int> &p_editable_instances); HashMap<NodePath, int> get_editable_instances() const; diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index 1d23650a1e..3f664bab10 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -30,16 +30,16 @@ #include "scene_tree.h" +#include "core/io/marshalls.h" +#include "core/io/resource_loader.h" +#include "core/message_queue.h" +#include "core/os/keyboard.h" +#include "core/os/os.h" +#include "core/print_string.h" +#include "core/project_settings.h" #include "editor/editor_node.h" -#include "io/marshalls.h" -#include "io/resource_loader.h" #include "main/input_default.h" -#include "message_queue.h" #include "node.h" -#include "os/keyboard.h" -#include "os/os.h" -#include "print_string.h" -#include "project_settings.h" #include "scene/resources/dynamic_font.h" #include "scene/resources/material.h" #include "scene/resources/mesh.h" @@ -535,10 +535,15 @@ bool SceneTree::idle(float p_time) { //go through timers + List<Ref<SceneTreeTimer> >::Element *L = timers.back(); //last element + for (List<Ref<SceneTreeTimer> >::Element *E = timers.front(); E;) { List<Ref<SceneTreeTimer> >::Element *N = E->next(); if (pause && !E->get()->is_pause_mode_process()) { + if (E == L) { + break; //break on last, so if new timers were added during list traversal, ignore them. + } E = N; continue; } @@ -550,6 +555,9 @@ bool SceneTree::idle(float p_time) { E->get()->emit_signal("timeout"); timers.erase(E); } + if (E == L) { + break; //break on last, so if new timers were added during list traversal, ignore them. + } E = N; } @@ -598,6 +606,7 @@ void SceneTree::finish() { if (root) { root->_set_tree(NULL); + root->_propagate_after_exit_tree(); memdelete(root); //delete root } } @@ -1196,6 +1205,9 @@ void SceneTree::_update_root_rect() { } switch (stretch_mode) { + case STRETCH_MODE_DISABLED: { + // Already handled above + } break; case STRETCH_MODE_2D: { root->set_size((screen_size / stretch_shrink).floor()); @@ -1601,7 +1613,7 @@ void SceneTree::_live_edit_duplicate_node_func(const NodePath &p_at, const Strin continue; Node *n2 = n->get_node(p_at); - Node *dup = n2->duplicate(true); + Node *dup = n2->duplicate(Node::DUPLICATE_SIGNALS | Node::DUPLICATE_GROUPS | Node::DUPLICATE_SCRIPTS); if (!dup) continue; @@ -1862,10 +1874,10 @@ void SceneTree::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "multiplayer_poll"), "set_multiplayer_poll_enabled", "is_multiplayer_poll_enabled"); ADD_SIGNAL(MethodInfo("tree_changed")); - ADD_SIGNAL(MethodInfo("node_added", PropertyInfo(Variant::OBJECT, "node"))); - ADD_SIGNAL(MethodInfo("node_removed", PropertyInfo(Variant::OBJECT, "node"))); + ADD_SIGNAL(MethodInfo("node_added", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node"))); + ADD_SIGNAL(MethodInfo("node_removed", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node"))); ADD_SIGNAL(MethodInfo("screen_resized")); - ADD_SIGNAL(MethodInfo("node_configuration_warning_changed", PropertyInfo(Variant::OBJECT, "node"))); + ADD_SIGNAL(MethodInfo("node_configuration_warning_changed", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node"))); ADD_SIGNAL(MethodInfo("idle_frame")); ADD_SIGNAL(MethodInfo("physics_frame")); @@ -1940,6 +1952,7 @@ SceneTree::SceneTree() { debug_navigation_color = GLOBAL_DEF("debug/shapes/navigation/geometry_color", Color(0.1, 1.0, 0.7, 0.4)); debug_navigation_disabled_color = GLOBAL_DEF("debug/shapes/navigation/disabled_geometry_color", Color(1.0, 0.7, 0.1, 0.4)); collision_debug_contacts = GLOBAL_DEF("debug/shapes/collision/max_contacts_displayed", 10000); + ProjectSettings::get_singleton()->set_custom_property_info("debug/shapes/collision/max_contacts_displayed", PropertyInfo(Variant::INT, "debug/shapes/collision/max_contacts_displayed", PROPERTY_HINT_RANGE, "0,20000,1")); // No negative tree_version = 1; physics_process_time = 1; @@ -1960,6 +1973,7 @@ SceneTree::SceneTree() { root = memnew(Viewport); root->set_name("root"); + root->set_handle_input_locally(false); if (!root->get_world().is_valid()) root->set_world(Ref<World>(memnew(World))); @@ -1973,7 +1987,9 @@ SceneTree::SceneTree() { current_scene = NULL; int ref_atlas_size = GLOBAL_DEF("rendering/quality/reflections/atlas_size", 2048); + ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/reflections/atlas_size", PropertyInfo(Variant::INT, "rendering/quality/reflections/atlas_size", PROPERTY_HINT_RANGE, "0,8192,or_greater")); //next_power_of_2 will return a 0 as min value int ref_atlas_subdiv = GLOBAL_DEF("rendering/quality/reflections/atlas_subdiv", 8); + ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/reflections/atlas_subdiv", PropertyInfo(Variant::INT, "rendering/quality/reflections/atlas_subdiv", PROPERTY_HINT_RANGE, "0,32,or_greater")); //next_power_of_2 will return a 0 as min value int msaa_mode = GLOBAL_DEF("rendering/quality/filters/msaa", 0); ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/filters/msaa", PropertyInfo(Variant::INT, "rendering/quality/filters/msaa", PROPERTY_HINT_ENUM, "Disabled,2x,4x,8x,16x")); root->set_msaa(Viewport::MSAA(msaa_mode)); diff --git a/scene/main/scene_tree.h b/scene/main/scene_tree.h index 11201097d4..d59cbe05fb 100644 --- a/scene/main/scene_tree.h +++ b/scene/main/scene_tree.h @@ -31,13 +31,13 @@ #ifndef SCENE_MAIN_LOOP_H #define SCENE_MAIN_LOOP_H -#include "io/multiplayer_api.h" -#include "os/main_loop.h" -#include "os/thread_safe.h" +#include "core/io/multiplayer_api.h" +#include "core/os/main_loop.h" +#include "core/os/thread_safe.h" +#include "core/self_list.h" #include "scene/resources/mesh.h" #include "scene/resources/world.h" #include "scene/resources/world_2d.h" -#include "self_list.h" /** @author Juan Linietsky <reduzio@gmail.com> diff --git a/scene/main/timer.cpp b/scene/main/timer.cpp index c285694dfa..227840531e 100755 --- a/scene/main/timer.cpp +++ b/scene/main/timer.cpp @@ -30,7 +30,7 @@ #include "timer.h" -#include "engine.h" +#include "core/engine.h" void Timer::_notification(int p_what) { diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index d1b3eb9d9a..8545efb966 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -30,9 +30,9 @@ #include "viewport.h" -#include "os/input.h" -#include "os/os.h" -#include "project_settings.h" +#include "core/os/input.h" +#include "core/os/os.h" +#include "core/project_settings.h" #include "scene/2d/collision_object_2d.h" #include "scene/3d/camera.h" #include "scene/3d/collision_object.h" @@ -45,6 +45,7 @@ #include "scene/gui/panel.h" #include "scene/gui/panel_container.h" #include "scene/gui/popup_menu.h" +#include "scene/main/canvas_layer.h" #include "scene/main/timer.h" #include "scene/resources/mesh.h" #include "scene/scene_string_names.h" @@ -231,6 +232,25 @@ void Viewport::update_worlds() { find_world()->_update(get_tree()->get_frame()); } +void Viewport::_collision_object_input_event(CollisionObject *p_object, Camera *p_camera, const Ref<InputEvent> &p_input_event, const Vector3 &p_pos, const Vector3 &p_normal, int p_shape, bool p_discard_empty_motion) { + + Transform object_transform = p_object->get_global_transform(); + Transform camera_transform = p_camera->get_global_transform(); + ObjectID id = p_object->get_instance_id(); + + if (p_discard_empty_motion) { + //avoid sending the event unnecesarily if nothing really changed in the context + Ref<InputEventMouseMotion> mm = p_input_event; + if (mm.is_valid() && object_transform == physics_last_object_transform && camera_transform == physics_last_camera_transform && physics_last_id == id) { + return; //discarded + } + } + p_object->_input_event(camera, p_input_event, p_pos, p_normal, p_shape); + physics_last_object_transform = object_transform; + physics_last_camera_transform = camera_transform; + physics_last_id = id; +} + void Viewport::_test_new_mouseover(ObjectID new_collider) { #ifndef _3D_DISABLED if (new_collider != physics_object_over) { @@ -402,6 +422,34 @@ void Viewport::_notification(int p_what) { PhysicsDirectSpaceState::RayResult result; Physics2DDirectSpaceState *ss2d = Physics2DServer::get_singleton()->space_get_direct_state(find_world_2d()->get_space()); + bool discard_empty_motion = false; + + { // if no motion event exists, create a new one. This is necessary because objects or camera may have moved. + // while this extra event is sent, it is checked if both camera and last object and last ID did not move. If nothing changed, the event is discarded to avoid flooding with unnecesary motion events every frame + bool has_mouse_motion = false; + for (List<Ref<InputEvent> >::Element *E = physics_picking_events.front(); E; E = E->next()) { + Ref<InputEventMouseMotion> mm = E->get(); + if (mm.is_valid()) { + has_mouse_motion = true; + break; + } + } + + if (!has_mouse_motion) { + Ref<InputEventMouseMotion> mm; + mm.instance(); + mm->set_global_position(physics_last_mousepos); + mm->set_position(physics_last_mousepos); + mm->set_alt(physics_last_mouse_state.alt); + mm->set_shift(physics_last_mouse_state.shift); + mm->set_control(physics_last_mouse_state.control); + mm->set_metakey(physics_last_mouse_state.meta); + mm->set_button_mask(physics_last_mouse_state.mouse_mask); + physics_picking_events.push_back(mm); + discard_empty_motion = true; + } + } + bool motion_tested = false; while (physics_picking_events.size()) { @@ -418,12 +466,37 @@ void Viewport::_notification(int p_what) { pos = mm->get_position(); motion_tested = true; physics_last_mousepos = pos; + physics_last_mouse_state.alt = mm->get_alt(); + physics_last_mouse_state.shift = mm->get_shift(); + physics_last_mouse_state.control = mm->get_control(); + physics_last_mouse_state.meta = mm->get_metakey(); + physics_last_mouse_state.mouse_mask = mm->get_button_mask(); } Ref<InputEventMouseButton> mb = ev; if (mb.is_valid()) { pos = mb->get_position(); + physics_last_mouse_state.alt = mb->get_alt(); + physics_last_mouse_state.shift = mb->get_shift(); + physics_last_mouse_state.control = mb->get_control(); + physics_last_mouse_state.meta = mb->get_metakey(); + + if (mb->is_pressed()) { + physics_last_mouse_state.mouse_mask |= (1 << (mb->get_button_index() - 1)); + } else { + physics_last_mouse_state.mouse_mask &= ~(1 << (mb->get_button_index() - 1)); + } + } + + Ref<InputEventKey> k = ev; + if (k.is_valid()) { + //only for mask + physics_last_mouse_state.alt = k->get_alt(); + physics_last_mouse_state.shift = k->get_shift(); + physics_last_mouse_state.control = k->get_control(); + physics_last_mouse_state.meta = k->get_metakey(); + continue; } Ref<InputEventScreenDrag> sd = ev; @@ -443,24 +516,39 @@ void Viewport::_notification(int p_what) { uint64_t frame = get_tree()->get_frame(); - Vector2 point = get_canvas_transform().affine_inverse().xform(pos); Physics2DDirectSpaceState::ShapeResult res[64]; - int rc = ss2d->intersect_point(point, res, 64, Set<RID>(), 0xFFFFFFFF, true, true, true); - for (int i = 0; i < rc; i++) { - - if (res[i].collider_id && res[i].collider) { - CollisionObject2D *co = Object::cast_to<CollisionObject2D>(res[i].collider); - if (co) { - - Map<ObjectID, uint64_t>::Element *E = physics_2d_mouseover.find(res[i].collider_id); - if (!E) { - E = physics_2d_mouseover.insert(res[i].collider_id, frame); - co->_mouse_enter(); - } else { - E->get() = frame; - } + for (Set<CanvasLayer *>::Element *E = canvas_layers.front(); E; E = E->next()) { + Transform2D canvas_transform; + ObjectID canvas_layer_id; + if (E->get()) { + // A descendant CanvasLayer + canvas_transform = E->get()->get_transform(); + canvas_layer_id = E->get()->get_instance_id(); + } else { + // This Viewport's builtin canvas + canvas_transform = get_canvas_transform(); + canvas_layer_id = 0; + } + + Vector2 point = canvas_transform.affine_inverse().xform(pos); + + int rc = ss2d->intersect_point_on_canvas(point, canvas_layer_id, res, 64, Set<RID>(), 0xFFFFFFFF, true, true, true); + for (int i = 0; i < rc; i++) { + + if (res[i].collider_id && res[i].collider) { + CollisionObject2D *co = Object::cast_to<CollisionObject2D>(res[i].collider); + if (co) { + + Map<ObjectID, uint64_t>::Element *E = physics_2d_mouseover.find(res[i].collider_id); + if (!E) { + E = physics_2d_mouseover.insert(res[i].collider_id, frame); + co->_mouse_enter(); + } else { + E->get() = frame; + } - co->_input_event(this, ev, res[i].shape); + co->_input_event(this, ev, res[i].shape); + } } } } @@ -494,7 +582,7 @@ void Viewport::_notification(int p_what) { CollisionObject *co = Object::cast_to<CollisionObject>(ObjectDB::get_instance(physics_object_capture)); if (co) { - co->_input_event(camera, ev, Vector3(), Vector3(), 0); + _collision_object_input_event(co, camera, ev, Vector3(), Vector3(), 0, discard_empty_motion); captured = true; if (mb.is_valid() && mb->get_button_index() == 1 && !mb->is_pressed()) { physics_object_capture = 0; @@ -512,7 +600,7 @@ void Viewport::_notification(int p_what) { if (last_id) { if (ObjectDB::get_instance(last_id) && last_object) { //good, exists - last_object->_input_event(camera, ev, result.position, result.normal, result.shape); + _collision_object_input_event(last_object, camera, ev, result.position, result.normal, result.shape, discard_empty_motion); if (last_object->get_capture_input_on_drag() && mb.is_valid() && mb->get_button_index() == 1 && mb->is_pressed()) { physics_object_capture = last_id; } @@ -535,7 +623,7 @@ void Viewport::_notification(int p_what) { CollisionObject *co = Object::cast_to<CollisionObject>(result.collider); if (co) { - co->_input_event(camera, ev, result.position, result.normal, result.shape); + _collision_object_input_event(co, camera, ev, result.position, result.normal, result.shape, discard_empty_motion); last_object = co; last_id = result.collider_id; new_collider = last_id; @@ -629,10 +717,8 @@ Rect2 Viewport::get_visible_rect() const { Rect2 r; if (size == Size2()) { - - r = Rect2(Point2(), Size2(OS::get_singleton()->get_window_size().width, OS::get_singleton()->get_window_size().height)); + r = Rect2(Point2(), OS::get_singleton()->get_window_size()); } else { - r = Rect2(Point2(), size); } @@ -701,15 +787,6 @@ void Viewport::set_canvas_transform(const Transform2D &p_transform) { canvas_transform = p_transform; VisualServer::get_singleton()->viewport_set_canvas_transform(viewport, find_world_2d()->get_canvas(), canvas_transform); - - Transform2D xform = (global_canvas_transform * canvas_transform).affine_inverse(); - Size2 ss = get_visible_rect().size; - /*SpatialSound2DServer::get_singleton()->listener_set_transform(internal_listener_2d, Transform2D(0, xform.xform(ss*0.5))); - Vector2 ss2 = ss*xform.get_scale(); - float panrange = MAX(ss2.x,ss2.y); - - SpatialSound2DServer::get_singleton()->listener_set_param(internal_listener_2d, SpatialSound2DServer::LISTENER_PARAM_PAN_RANGE, panrange); -*/ } Transform2D Viewport::get_canvas_transform() const { @@ -722,15 +799,6 @@ void Viewport::_update_global_transform() { Transform2D sxform = stretch_transform * global_canvas_transform; VisualServer::get_singleton()->viewport_set_global_canvas_transform(viewport, sxform); - - Transform2D xform = (sxform * canvas_transform).affine_inverse(); - Size2 ss = get_visible_rect().size; - /*SpatialSound2DServer::get_singleton()->listener_set_transform(internal_listener_2d, Transform2D(0, xform.xform(ss*0.5))); - Vector2 ss2 = ss*xform.get_scale(); - float panrange = MAX(ss2.x,ss2.y); - - SpatialSound2DServer::get_singleton()->listener_set_param(internal_listener_2d, SpatialSound2DServer::LISTENER_PARAM_PAN_RANGE, panrange); -*/ } void Viewport::set_global_canvas_transform(const Transform2D &p_transform) { @@ -874,6 +942,16 @@ void Viewport::_camera_make_next_current(Camera *p_exclude) { } #endif +void Viewport::_canvas_layer_add(CanvasLayer *p_canvas_layer) { + + canvas_layers.insert(p_canvas_layer); +} + +void Viewport::_canvas_layer_remove(CanvasLayer *p_canvas_layer) { + + canvas_layers.erase(p_canvas_layer); +} + void Viewport::set_transparent_background(bool p_enable) { transparent_bg = p_enable; @@ -1432,12 +1510,17 @@ void Viewport::_gui_call_input(Control *p_control, const Ref<InputEvent> &p_inpu Control *control = Object::cast_to<Control>(ci); if (control) { - control->emit_signal(SceneStringNames::get_singleton()->gui_input, ev); //signal should be first, so it's possible to override an event (and then accept it) + if (control->data.mouse_filter != Control::MOUSE_FILTER_IGNORE) { + control->emit_signal(SceneStringNames::get_singleton()->gui_input, ev); //signal should be first, so it's possible to override an event (and then accept it) + } if (gui.key_event_accepted) break; if (!control->is_inside_tree()) break; - control->call_multilevel(SceneStringNames::get_singleton()->_gui_input, ev); + + if (control->data.mouse_filter != Control::MOUSE_FILTER_IGNORE) { + control->call_multilevel(SceneStringNames::get_singleton()->_gui_input, ev); + } if (!control->is_inside_tree() || control->is_set_as_toplevel()) break; @@ -1621,7 +1704,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { if (top->data.modal_exclusive || top->data.modal_frame == Engine::get_singleton()->get_frames_drawn()) { //cancel event, sorry, modal exclusive EATS UP ALL //alternative, you can't pop out a window the same frame it was made modal (fixes many issues) - get_tree()->set_input_as_handled(); + set_input_as_handled(); return; // no one gets the event if exclusive NO ONE } @@ -1639,7 +1722,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { } if (is_handled) { - get_tree()->set_input_as_handled(); + set_input_as_handled(); return; } @@ -1709,7 +1792,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { _gui_call_input(gui.mouse_focus, mb); } - get_tree()->set_input_as_handled(); + set_input_as_handled(); if (gui.drag_data.get_type() != Variant::NIL && mb->get_button_index() == BUTTON_LEFT) { @@ -1783,7 +1866,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { gui.drag_data=Variant(); //always clear }*/ - get_tree()->set_input_as_handled(); + set_input_as_handled(); } } @@ -1817,7 +1900,13 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { if (gui.drag_data.get_type() != Variant::NIL) { gui.mouse_focus = NULL; + break; } else { + if (gui.drag_preview != NULL) { + ERR_PRINT("Don't set a drag preview and return null data. Preview was deleted and drag request ignored."); + memdelete(gui.drag_preview); + gui.drag_preview = NULL; + } gui.dragging = false; } @@ -1859,8 +1948,16 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { MenuButton *popup_menu_parent = NULL; MenuButton *menu_button = Object::cast_to<MenuButton>(over); - if (popup_menu) + if (popup_menu) { popup_menu_parent = Object::cast_to<MenuButton>(popup_menu->get_parent()); + if (!popup_menu_parent) { + // Go through the parents to see if there's a MenuButton at the end. + while (Object::cast_to<PopupMenu>(popup_menu->get_parent())) { + popup_menu = Object::cast_to<PopupMenu>(popup_menu->get_parent()); + } + popup_menu_parent = Object::cast_to<MenuButton>(popup_menu->get_parent()); + } + } // If the mouse is over a menu button, this menu will open automatically // if there is already a pop-up menu open at the same hierarchical level. @@ -1978,7 +2075,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { _gui_call_input(over, mm); } - get_tree()->set_input_as_handled(); + set_input_as_handled(); if (gui.drag_data.get_type() != Variant::NIL && mm->get_button_mask() & BUTTON_MASK_LEFT) { @@ -2021,7 +2118,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { touch_event->set_position(pos); _gui_call_input(over, touch_event); } - get_tree()->set_input_as_handled(); + set_input_as_handled(); return; } } else if (gui.mouse_focus) { @@ -2033,7 +2130,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { _gui_call_input(gui.mouse_focus, touch_event); } - get_tree()->set_input_as_handled(); + set_input_as_handled(); return; } } @@ -2061,7 +2158,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { gesture_event->set_position(pos); _gui_call_input(over, gesture_event); } - get_tree()->set_input_as_handled(); + set_input_as_handled(); return; } } @@ -2099,7 +2196,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { _gui_call_input(over, drag_event); } - get_tree()->set_input_as_handled(); + set_input_as_handled(); return; } } @@ -2121,7 +2218,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { if (gui.key_event_accepted) { - get_tree()->set_input_as_handled(); + set_input_as_handled(); return; } } @@ -2136,7 +2233,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { top->_modal_stack_remove(); top->hide(); // Close modal, set input as handled - get_tree()->set_input_as_handled(); + set_input_as_handled(); return; } } @@ -2185,7 +2282,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { if (next) { next->grab_focus(); - get_tree()->set_input_as_handled(); + set_input_as_handled(); } } } @@ -2389,7 +2486,7 @@ void Viewport::_gui_accept_event() { gui.key_event_accepted = true; if (is_inside_tree()) - get_tree()->set_input_as_handled(); + set_input_as_handled(); } List<Control *>::Element *Viewport::_gui_show_modal(Control *p_control) { @@ -2466,11 +2563,13 @@ void Viewport::input(const Ref<InputEvent> &p_event) { ERR_FAIL_COND(!is_inside_tree()); - if (!get_tree()->is_input_handled()) { + local_input_handled = false; + + if (!is_input_handled()) { get_tree()->_call_input_pause(input_group, "_input", p_event); //not a bug, must happen before GUI, order is _input -> gui input -> _unhandled input } - if (!get_tree()->is_input_handled()) { + if (!is_input_handled()) { _gui_input_event(p_event); } //get_tree()->call_group(SceneTree::GROUP_CALL_REVERSE|SceneTree::GROUP_CALL_REALTIME|SceneTree::GROUP_CALL_MULIILEVEL,gui_input_group,"_gui_input",p_event); //special one for GUI, as controls use their own process check @@ -2493,7 +2592,10 @@ void Viewport::unhandled_input(const Ref<InputEvent> &p_event) { (Object::cast_to<InputEventMouseButton>(*p_event) || Object::cast_to<InputEventMouseMotion>(*p_event) || Object::cast_to<InputEventScreenDrag>(*p_event) || - Object::cast_to<InputEventScreenTouch>(*p_event))) { + Object::cast_to<InputEventScreenTouch>(*p_event) || + Object::cast_to<InputEventKey>(*p_event) //to remember state + + )) { physics_picking_events.push_back(p_event); } } @@ -2701,6 +2803,33 @@ bool Viewport::is_snap_controls_to_pixels_enabled() const { bool Viewport::gui_is_dragging() const { return gui.dragging; } + +void Viewport::set_input_as_handled() { + if (handle_input_locally) { + local_input_handled = true; + } else { + ERR_FAIL_COND(!is_inside_tree()); + get_tree()->set_input_as_handled(); + } +} + +bool Viewport::is_input_handled() const { + if (handle_input_locally) { + return local_input_handled; + } else { + ERR_FAIL_COND_V(!is_inside_tree(), false); + return get_tree()->is_input_handled(); + } +} + +void Viewport::set_handle_input_locally(bool p_enable) { + handle_input_locally = p_enable; +} + +bool Viewport::is_handling_input_locally() const { + return handle_input_locally; +} + void Viewport::_bind_methods() { ClassDB::bind_method(D_METHOD("set_use_arvr", "use"), &Viewport::set_use_arvr); @@ -2789,6 +2918,8 @@ void Viewport::_bind_methods() { ClassDB::bind_method(D_METHOD("gui_get_drag_data"), &Viewport::gui_get_drag_data); ClassDB::bind_method(D_METHOD("gui_is_dragging"), &Viewport::gui_is_dragging); + ClassDB::bind_method(D_METHOD("get_modal_stack_top"), &Viewport::get_modal_stack_top); + 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); @@ -2811,6 +2942,12 @@ void Viewport::_bind_methods() { ClassDB::bind_method(D_METHOD("set_shadow_atlas_quadrant_subdiv", "quadrant", "subdiv"), &Viewport::set_shadow_atlas_quadrant_subdiv); ClassDB::bind_method(D_METHOD("get_shadow_atlas_quadrant_subdiv", "quadrant"), &Viewport::get_shadow_atlas_quadrant_subdiv); + ClassDB::bind_method(D_METHOD("set_input_as_handled"), &Viewport::set_input_as_handled); + ClassDB::bind_method(D_METHOD("is_input_handled"), &Viewport::is_input_handled); + + ClassDB::bind_method(D_METHOD("set_handle_input_locally", "enable"), &Viewport::set_handle_input_locally); + ClassDB::bind_method(D_METHOD("is_handling_input_locally"), &Viewport::is_handling_input_locally); + ClassDB::bind_method(D_METHOD("_subwindow_visibility_changed"), &Viewport::_subwindow_visibility_changed); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "arvr"), "set_use_arvr", "use_arvr"); @@ -2820,6 +2957,7 @@ void Viewport::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "world", PROPERTY_HINT_RESOURCE_TYPE, "World"), "set_world", "get_world"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "world_2d", PROPERTY_HINT_RESOURCE_TYPE, "World2D", 0), "set_world_2d", "get_world_2d"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "transparent_bg"), "set_transparent_background", "has_transparent_background"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "handle_input_locally"), "set_handle_input_locally", "is_handling_input_locally"); ADD_GROUP("Rendering", ""); ADD_PROPERTY(PropertyInfo(Variant::INT, "msaa", PROPERTY_HINT_ENUM, "Disabled,2x,4x,8x,16x"), "set_msaa", "get_msaa"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "hdr"), "set_hdr", "get_hdr"); @@ -2921,6 +3059,7 @@ Viewport::Viewport() { parent = NULL; listener = NULL; camera = NULL; + canvas_layers.insert(NULL); // This eases picking code (interpreted as the canvas of the Viewport) arvr = false; size_override = false; size_override_stretch = false; @@ -2961,6 +3100,7 @@ Viewport::Viewport() { //gui.tooltip_timer->force_parent_owned(); gui.tooltip_delay = GLOBAL_DEF("gui/timers/tooltip_delay_sec", 0.7); + ProjectSettings::get_singleton()->set_custom_property_info("gui/timers/tooltip_delay_sec", PropertyInfo(Variant::REAL, "gui/timers/tooltip_delay_sec", PROPERTY_HINT_RANGE, "0,5,0.01,or_greater")); // No negative numbers gui.tooltip = NULL; gui.tooltip_label = NULL; @@ -2977,6 +3117,14 @@ Viewport::Viewport() { clear_mode = CLEAR_MODE_ALWAYS; snap_controls_to_pixels = true; + physics_last_mouse_state.alt = false; + physics_last_mouse_state.control = false; + physics_last_mouse_state.shift = false; + physics_last_mouse_state.meta = false; + physics_last_mouse_state.mouse_mask = 0; + local_input_handled = false; + handle_input_locally = true; + physics_last_id = 0; //ensures first time there will be a check } Viewport::~Viewport() { diff --git a/scene/main/viewport.h b/scene/main/viewport.h index 450f235b79..44fb322ae2 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -31,11 +31,11 @@ #ifndef VIEWPORT_H #define VIEWPORT_H +#include "core/math/transform_2d.h" #include "scene/main/node.h" #include "scene/resources/texture.h" #include "scene/resources/world_2d.h" #include "servers/visual_server.h" -#include "transform_2d.h" /** @author Juan Linietsky <reduzio@gmail.com> */ @@ -45,10 +45,12 @@ class Camera2D; class Listener; class Control; class CanvasItem; +class CanvasLayer; class Panel; class Label; class Timer; class Viewport; +class CollisionObject; class ViewportTexture : public Texture { @@ -163,6 +165,7 @@ private: Camera *camera; Set<Camera *> cameras; + Set<CanvasLayer *> canvas_layers; RID viewport; RID current_canvas; @@ -203,7 +206,25 @@ private: List<Ref<InputEvent> > physics_picking_events; ObjectID physics_object_capture; ObjectID physics_object_over; + Transform physics_last_object_transform; + Transform physics_last_camera_transform; + ObjectID physics_last_id; Vector2 physics_last_mousepos; + struct { + + bool alt; + bool control; + bool shift; + bool meta; + int mouse_mask; + + } physics_last_mouse_state; + + void _collision_object_input_event(CollisionObject *p_object, Camera *p_camera, const Ref<InputEvent> &p_input_event, const Vector3 &p_pos, const Vector3 &p_normal, int p_shape, bool p_discard_empty_motion); + + bool handle_input_locally; + bool local_input_handled; + void _test_new_mouseover(ObjectID new_collider); Map<ObjectID, uint64_t> physics_2d_mouseover; @@ -354,6 +375,10 @@ private: void _camera_remove(Camera *p_camera); void _camera_make_next_current(Camera *p_exclude); + friend class CanvasLayer; + void _canvas_layer_add(CanvasLayer *p_canvas_layer); + void _canvas_layer_remove(CanvasLayer *p_canvas_layer); + protected: void _notification(int p_what); static void _bind_methods(); @@ -475,6 +500,12 @@ public: void _subwindow_visibility_changed(); + void set_input_as_handled(); + bool is_input_handled() const; + + void set_handle_input_locally(bool p_enable); + bool is_handling_input_locally() const; + bool gui_is_dragging() const; Viewport(); |