diff options
Diffstat (limited to 'scene/main')
-rw-r--r-- | scene/main/canvas_item.cpp | 32 | ||||
-rw-r--r-- | scene/main/canvas_item.h | 4 | ||||
-rw-r--r-- | scene/main/http_request.cpp | 8 | ||||
-rw-r--r-- | scene/main/http_request.h | 8 | ||||
-rw-r--r-- | scene/main/node.cpp | 70 | ||||
-rw-r--r-- | scene/main/node.h | 16 | ||||
-rw-r--r-- | scene/main/scene_tree.cpp | 23 | ||||
-rw-r--r-- | scene/main/scene_tree.h | 9 | ||||
-rw-r--r-- | scene/main/shader_globals_override.cpp | 2 | ||||
-rw-r--r-- | scene/main/timer.cpp | 2 | ||||
-rw-r--r-- | scene/main/viewport.cpp | 172 | ||||
-rw-r--r-- | scene/main/viewport.h | 8 | ||||
-rw-r--r-- | scene/main/window.cpp | 17 | ||||
-rw-r--r-- | scene/main/window.h | 2 |
14 files changed, 259 insertions, 114 deletions
diff --git a/scene/main/canvas_item.cpp b/scene/main/canvas_item.cpp index 1d263ba858..f5fe87c808 100644 --- a/scene/main/canvas_item.cpp +++ b/scene/main/canvas_item.cpp @@ -444,6 +444,25 @@ void CanvasItem::item_rect_changed(bool p_size_changed) { emit_signal(SceneStringNames::get_singleton()->item_rect_changed); } +void CanvasItem::draw_dashed_line(const Point2 &p_from, const Point2 &p_to, const Color &p_color, real_t p_width, real_t p_dash) { + ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); + + float length = (p_to - p_from).length(); + if (length < p_dash) { + RenderingServer::get_singleton()->canvas_item_add_line(canvas_item, p_from, p_to, p_color, p_width); + return; + } + + Point2 off = p_from; + Vector2 step = p_dash * (p_to - p_from).normalized(); + int steps = length / p_dash / 2; + for (int i = 0; i < steps; i++) { + RenderingServer::get_singleton()->canvas_item_add_line(canvas_item, off, (off + step), p_color, p_width); + off += 2 * step; + } + RenderingServer::get_singleton()->canvas_item_add_line(canvas_item, off, p_to, p_color, p_width); +} + void CanvasItem::draw_line(const Point2 &p_from, const Point2 &p_to, const Color &p_color, real_t p_width) { ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); @@ -864,10 +883,8 @@ void CanvasItem::_bind_methods() { ClassDB::bind_method(D_METHOD("set_draw_behind_parent", "enable"), &CanvasItem::set_draw_behind_parent); ClassDB::bind_method(D_METHOD("is_draw_behind_parent_enabled"), &CanvasItem::is_draw_behind_parent_enabled); - ClassDB::bind_method(D_METHOD("_set_on_top", "on_top"), &CanvasItem::_set_on_top); - ClassDB::bind_method(D_METHOD("_is_on_top"), &CanvasItem::_is_on_top); - ClassDB::bind_method(D_METHOD("draw_line", "from", "to", "color", "width"), &CanvasItem::draw_line, DEFVAL(1.0)); + ClassDB::bind_method(D_METHOD("draw_dashed_line", "from", "to", "color", "width", "dash"), &CanvasItem::draw_dashed_line, DEFVAL(1.0), DEFVAL(2.0)); ClassDB::bind_method(D_METHOD("draw_polyline", "points", "color", "width", "antialiased"), &CanvasItem::draw_polyline, DEFVAL(1.0), DEFVAL(false)); ClassDB::bind_method(D_METHOD("draw_polyline_colors", "points", "colors", "width", "antialiased"), &CanvasItem::draw_polyline_colors, DEFVAL(1.0), DEFVAL(false)); ClassDB::bind_method(D_METHOD("draw_arc", "center", "radius", "start_angle", "end_angle", "point_count", "color", "width", "antialiased"), &CanvasItem::draw_arc, DEFVAL(1.0), DEFVAL(false)); @@ -939,7 +956,6 @@ void CanvasItem::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::COLOR, "self_modulate"), "set_self_modulate", "get_self_modulate"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_behind_parent"), "set_draw_behind_parent", "is_draw_behind_parent_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "top_level"), "set_as_top_level", "is_set_as_top_level"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_on_top", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "_set_on_top", "_is_on_top"); //compatibility ADD_PROPERTY(PropertyInfo(Variant::BOOL, "clip_children"), "set_clip_children", "is_clipping_children"); ADD_PROPERTY(PropertyInfo(Variant::INT, "light_mask", PROPERTY_HINT_LAYERS_2D_RENDER), "set_light_mask", "get_light_mask"); @@ -958,6 +974,7 @@ void CanvasItem::_bind_methods() { ADD_SIGNAL(MethodInfo("item_rect_changed")); BIND_CONSTANT(NOTIFICATION_TRANSFORM_CHANGED); + BIND_CONSTANT(NOTIFICATION_LOCAL_TRANSFORM_CHANGED); BIND_CONSTANT(NOTIFICATION_DRAW); BIND_CONSTANT(NOTIFICATION_VISIBILITY_CHANGED); BIND_CONSTANT(NOTIFICATION_ENTER_CANVAS); @@ -995,12 +1012,7 @@ Transform2D CanvasItem::get_viewport_transform() const { ERR_FAIL_COND_V(!is_inside_tree(), Transform2D()); if (canvas_layer) { - if (get_viewport()) { - return get_viewport()->get_final_transform() * canvas_layer->get_transform(); - } else { - return canvas_layer->get_transform(); - } - + return get_viewport()->get_final_transform() * canvas_layer->get_transform(); } else { return get_viewport()->get_final_transform() * get_viewport()->get_canvas_transform(); } diff --git a/scene/main/canvas_item.h b/scene/main/canvas_item.h index 1b2c188fc0..95fae0fda7 100644 --- a/scene/main/canvas_item.h +++ b/scene/main/canvas_item.h @@ -120,9 +120,6 @@ private: void _notify_transform(CanvasItem *p_node); - void _set_on_top(bool p_on_top) { set_draw_behind_parent(!p_on_top); } - bool _is_on_top() const { return !is_draw_behind_parent_enabled(); } - static CanvasItem *current_item_drawn; friend class Viewport; void _update_texture_repeat_changed(bool p_propagate); @@ -217,6 +214,7 @@ public: /* DRAWING API */ + void draw_dashed_line(const Point2 &p_from, const Point2 &p_to, const Color &p_color, real_t p_width = 1.0, real_t p_dash = 2.0); void draw_line(const Point2 &p_from, const Point2 &p_to, const Color &p_color, real_t p_width = 1.0); void draw_polyline(const Vector<Point2> &p_points, const Color &p_color, real_t p_width = 1.0, bool p_antialiased = false); void draw_polyline_colors(const Vector<Point2> &p_points, const Vector<Color> &p_colors, real_t p_width = 1.0, bool p_antialiased = false); diff --git a/scene/main/http_request.cpp b/scene/main/http_request.cpp index 700ba761f6..2d5814c954 100644 --- a/scene/main/http_request.cpp +++ b/scene/main/http_request.cpp @@ -164,7 +164,7 @@ Error HTTPRequest::request_raw(const String &p_url, const Vector<String> &p_cust } void HTTPRequest::_thread_func(void *p_userdata) { - HTTPRequest *hr = (HTTPRequest *)p_userdata; + HTTPRequest *hr = static_cast<HTTPRequest *>(p_userdata); Error err = hr->_request(); @@ -558,12 +558,12 @@ void HTTPRequest::set_https_proxy(const String &p_host, int p_port) { client->set_https_proxy(p_host, p_port); } -void HTTPRequest::set_timeout(int p_timeout) { +void HTTPRequest::set_timeout(double p_timeout) { ERR_FAIL_COND(p_timeout < 0); timeout = p_timeout; } -int HTTPRequest::get_timeout() { +double HTTPRequest::get_timeout() { return timeout; } @@ -615,7 +615,7 @@ void HTTPRequest::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "accept_gzip"), "set_accept_gzip", "is_accepting_gzip"); ADD_PROPERTY(PropertyInfo(Variant::INT, "body_size_limit", PROPERTY_HINT_RANGE, "-1,2000000000"), "set_body_size_limit", "get_body_size_limit"); ADD_PROPERTY(PropertyInfo(Variant::INT, "max_redirects", PROPERTY_HINT_RANGE, "-1,64"), "set_max_redirects", "get_max_redirects"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "timeout", PROPERTY_HINT_RANGE, "0,86400"), "set_timeout", "get_timeout"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "timeout", PROPERTY_HINT_RANGE, "0,3600,0.1,or_greater"), "set_timeout", "get_timeout"); ADD_SIGNAL(MethodInfo("request_completed", PropertyInfo(Variant::INT, "result"), PropertyInfo(Variant::INT, "response_code"), PropertyInfo(Variant::PACKED_STRING_ARRAY, "headers"), PropertyInfo(Variant::PACKED_BYTE_ARRAY, "body"))); diff --git a/scene/main/http_request.h b/scene/main/http_request.h index 62880fa282..8b3441f7d7 100644 --- a/scene/main/http_request.h +++ b/scene/main/http_request.h @@ -96,7 +96,7 @@ private: int max_redirects = 8; - int timeout = 0; + double timeout = 0; void _redirect_request(const String &p_new_url); @@ -144,10 +144,10 @@ public: void set_max_redirects(int p_max); int get_max_redirects() const; - Timer *timer; + Timer *timer = nullptr; - void set_timeout(int p_timeout); - int get_timeout(); + void set_timeout(double p_timeout); + double get_timeout(); void _timeout(); diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 208bbe4d72..34bb1cde05 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -79,6 +79,9 @@ void Node::_notification(int p_notification) { if (data.input) { add_to_group("_vp_input" + itos(get_viewport()->get_instance_id())); } + if (data.shortcut_input) { + add_to_group("_vp_shortcut_input" + itos(get_viewport()->get_instance_id())); + } if (data.unhandled_input) { add_to_group("_vp_unhandled_input" + itos(get_viewport()->get_instance_id())); } @@ -100,6 +103,9 @@ void Node::_notification(int p_notification) { if (data.input) { remove_from_group("_vp_input" + itos(get_viewport()->get_instance_id())); } + if (data.shortcut_input) { + remove_from_group("_vp_shortcut_input" + itos(get_viewport()->get_instance_id())); + } if (data.unhandled_input) { remove_from_group("_vp_unhandled_input" + itos(get_viewport()->get_instance_id())); } @@ -126,6 +132,10 @@ void Node::_notification(int p_notification) { set_process_input(true); } + if (GDVIRTUAL_IS_OVERRIDDEN(_shortcut_input)) { + set_process_shortcut_input(true); + } + if (GDVIRTUAL_IS_OVERRIDDEN(_unhandled_input)) { set_process_unhandled_input(true); } @@ -582,11 +592,11 @@ uint16_t Node::rpc_config(const StringName &p_method, Multiplayer::RPCMode p_rpc /***** RPC FUNCTIONS ********/ -Variant Node::_rpc_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { +void Node::_rpc_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { if (p_argcount < 1) { r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; r_error.argument = 1; - return Variant(); + return; } Variant::Type type = p_args[0]->get_type(); @@ -594,7 +604,7 @@ Variant Node::_rpc_bind(const Variant **p_args, int p_argcount, Callable::CallEr r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; r_error.expected = Variant::STRING_NAME; - return Variant(); + return; } StringName method = (*p_args[0]).operator StringName(); @@ -602,21 +612,20 @@ Variant Node::_rpc_bind(const Variant **p_args, int p_argcount, Callable::CallEr rpcp(0, method, &p_args[1], p_argcount - 1); r_error.error = Callable::CallError::CALL_OK; - return Variant(); } -Variant Node::_rpc_id_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { +void Node::_rpc_id_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { if (p_argcount < 2) { r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; r_error.argument = 2; - return Variant(); + return; } if (p_args[0]->get_type() != Variant::INT) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; r_error.expected = Variant::INT; - return Variant(); + return; } Variant::Type type = p_args[1]->get_type(); @@ -624,7 +633,7 @@ Variant Node::_rpc_id_bind(const Variant **p_args, int p_argcount, Callable::Cal r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 1; r_error.expected = Variant::STRING_NAME; - return Variant(); + return; } int peer_id = *p_args[0]; @@ -633,7 +642,6 @@ Variant Node::_rpc_id_bind(const Variant **p_args, int p_argcount, Callable::Cal rpcp(peer_id, method, &p_args[2], p_argcount - 2); r_error.error = Callable::CallError::CALL_OK; - return Variant(); } void Node::rpcp(int p_peer_id, const StringName &p_method, const Variant **p_arg, int p_argcount) { @@ -837,6 +845,26 @@ bool Node::is_processing_input() const { return data.input; } +void Node::set_process_shortcut_input(bool p_enable) { + if (p_enable == data.shortcut_input) { + return; + } + data.shortcut_input = p_enable; + if (!is_inside_tree()) { + return; + } + + if (p_enable) { + add_to_group("_vp_shortcut_input" + itos(get_viewport()->get_instance_id())); + } else { + remove_from_group("_vp_shortcut_input" + itos(get_viewport()->get_instance_id())); + } +} + +bool Node::is_processing_shortcut_input() const { + return data.shortcut_input; +} + void Node::set_process_unhandled_input(bool p_enable) { if (p_enable == data.unhandled_input) { return; @@ -2487,11 +2515,11 @@ static void _Node_debug_sn(Object *p_obj) { } #endif // DEBUG_ENABLED -void Node::_print_stray_nodes() { - print_stray_nodes(); +void Node::_print_orphan_nodes() { + print_orphan_nodes(); } -void Node::print_stray_nodes() { +void Node::print_orphan_nodes() { #ifdef DEBUG_ENABLED ObjectDB::debug_objects(_Node_debug_sn); #endif @@ -2617,6 +2645,15 @@ void Node::_call_input(const Ref<InputEvent> &p_event) { } input(p_event); } + +void Node::_call_shortcut_input(const Ref<InputEvent> &p_event) { + GDVIRTUAL_CALL(_shortcut_input, p_event); + if (!is_inside_tree() || !get_viewport() || get_viewport()->is_input_handled()) { + return; + } + shortcut_input(p_event); +} + void Node::_call_unhandled_input(const Ref<InputEvent> &p_event) { GDVIRTUAL_CALL(_unhandled_input, p_event); if (!is_inside_tree() || !get_viewport() || get_viewport()->is_input_handled()) { @@ -2624,6 +2661,7 @@ void Node::_call_unhandled_input(const Ref<InputEvent> &p_event) { } unhandled_input(p_event); } + void Node::_call_unhandled_key_input(const Ref<InputEvent> &p_event) { GDVIRTUAL_CALL(_unhandled_key_input, p_event); if (!is_inside_tree() || !get_viewport() || get_viewport()->is_input_handled()) { @@ -2635,6 +2673,9 @@ void Node::_call_unhandled_key_input(const Ref<InputEvent> &p_event) { void Node::input(const Ref<InputEvent> &p_event) { } +void Node::shortcut_input(const Ref<InputEvent> &p_key_event) { +} + void Node::unhandled_input(const Ref<InputEvent> &p_event) { } @@ -2696,6 +2737,8 @@ void Node::_bind_methods() { ClassDB::bind_method(D_METHOD("is_processing"), &Node::is_processing); ClassDB::bind_method(D_METHOD("set_process_input", "enable"), &Node::set_process_input); ClassDB::bind_method(D_METHOD("is_processing_input"), &Node::is_processing_input); + ClassDB::bind_method(D_METHOD("set_process_shortcut_input", "enable"), &Node::set_process_shortcut_input); + ClassDB::bind_method(D_METHOD("is_processing_shortcut_input"), &Node::is_processing_shortcut_input); ClassDB::bind_method(D_METHOD("set_process_unhandled_input", "enable"), &Node::set_process_unhandled_input); ClassDB::bind_method(D_METHOD("is_processing_unhandled_input"), &Node::is_processing_unhandled_input); ClassDB::bind_method(D_METHOD("set_process_unhandled_key_input", "enable"), &Node::set_process_unhandled_key_input); @@ -2703,7 +2746,7 @@ void Node::_bind_methods() { ClassDB::bind_method(D_METHOD("set_process_mode", "mode"), &Node::set_process_mode); ClassDB::bind_method(D_METHOD("get_process_mode"), &Node::get_process_mode); ClassDB::bind_method(D_METHOD("can_process"), &Node::can_process); - ClassDB::bind_method(D_METHOD("print_stray_nodes"), &Node::_print_stray_nodes); + ClassDB::bind_method(D_METHOD("print_orphan_nodes"), &Node::_print_orphan_nodes); ClassDB::bind_method(D_METHOD("set_display_folded", "fold"), &Node::set_display_folded); ClassDB::bind_method(D_METHOD("is_displayed_folded"), &Node::is_displayed_folded); @@ -2856,6 +2899,7 @@ void Node::_bind_methods() { GDVIRTUAL_BIND(_ready); GDVIRTUAL_BIND(_get_configuration_warnings); GDVIRTUAL_BIND(_input, "event"); + GDVIRTUAL_BIND(_shortcut_input, "event"); GDVIRTUAL_BIND(_unhandled_input, "event"); GDVIRTUAL_BIND(_unhandled_key_input, "event"); } diff --git a/scene/main/node.h b/scene/main/node.h index f5fbcf6587..57b150e29a 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -43,7 +43,6 @@ class PropertyTweener; class Node : public Object { GDCLASS(Node, Object); - OBJ_CATEGORY("Nodes"); public: enum ProcessMode { @@ -137,6 +136,7 @@ private: bool process_internal = false; bool input = false; + bool shortcut_input = false; bool unhandled_input = false; bool unhandled_key_input = false; @@ -169,7 +169,7 @@ private: void _propagate_ready(); void _propagate_exit_tree(); void _propagate_after_exit_tree(); - void _print_stray_nodes(); + void _print_orphan_nodes(); void _propagate_process_owner(Node *p_owner, int p_pause_notification, int p_enabled_notification); Array _get_node_and_resource(const NodePath &p_path); @@ -179,8 +179,8 @@ private: TypedArray<Node> _get_children(bool p_include_internal = true) const; Array _get_groups() const; - Variant _rpc_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error); - Variant _rpc_id_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error); + void _rpc_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error); + void _rpc_id_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error); _FORCE_INLINE_ bool _is_internal_front() const { return data.parent && data.pos < data.parent->data.internal_children_front; } _FORCE_INLINE_ bool _is_internal_back() const { return data.parent && data.pos >= data.parent->data.children.size() - data.parent->data.internal_children_back; } @@ -216,11 +216,13 @@ protected: //call from SceneTree void _call_input(const Ref<InputEvent> &p_event); + void _call_shortcut_input(const Ref<InputEvent> &p_event); void _call_unhandled_input(const Ref<InputEvent> &p_event); void _call_unhandled_key_input(const Ref<InputEvent> &p_event); protected: virtual void input(const Ref<InputEvent> &p_event); + virtual void shortcut_input(const Ref<InputEvent> &p_key_event); virtual void unhandled_input(const Ref<InputEvent> &p_event); virtual void unhandled_key_input(const Ref<InputEvent> &p_key_event); @@ -232,6 +234,7 @@ protected: GDVIRTUAL0RC(Vector<String>, _get_configuration_warnings) GDVIRTUAL1(_input, Ref<InputEvent>) + GDVIRTUAL1(_shortcut_input, Ref<InputEvent>) GDVIRTUAL1(_unhandled_input, Ref<InputEvent>) GDVIRTUAL1(_unhandled_key_input, Ref<InputEvent>) @@ -396,6 +399,9 @@ public: void set_process_input(bool p_enable); bool is_processing_input() const; + void set_process_shortcut_input(bool p_enable); + bool is_processing_shortcut_input() const; + void set_process_unhandled_input(bool p_enable); bool is_processing_unhandled_input() const; @@ -436,7 +442,7 @@ public: void request_ready(); - static void print_stray_nodes(); + static void print_orphan_nodes(); #ifdef TOOLS_ENABLED String validate_child_name(Node *p_child); diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index 3ddce28b69..d005633bb5 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -897,6 +897,9 @@ void SceneTree::_call_input_pause(const StringName &p_group, CallInputType p_cal case CALL_INPUT_TYPE_INPUT: n->_call_input(p_input); break; + case CALL_INPUT_TYPE_SHORTCUT_INPUT: + n->_call_shortcut_input(p_input); + break; case CALL_INPUT_TYPE_UNHANDLED_INPUT: n->_call_unhandled_input(p_input); break; @@ -912,34 +915,32 @@ void SceneTree::_call_input_pause(const StringName &p_group, CallInputType p_cal } } -Variant SceneTree::_call_group_flags(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { +void SceneTree::_call_group_flags(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { r_error.error = Callable::CallError::CALL_OK; - ERR_FAIL_COND_V(p_argcount < 3, Variant()); - ERR_FAIL_COND_V(!p_args[0]->is_num(), Variant()); - ERR_FAIL_COND_V(p_args[1]->get_type() != Variant::STRING_NAME && p_args[1]->get_type() != Variant::STRING, Variant()); - ERR_FAIL_COND_V(p_args[2]->get_type() != Variant::STRING_NAME && p_args[2]->get_type() != Variant::STRING, Variant()); + ERR_FAIL_COND(p_argcount < 3); + ERR_FAIL_COND(!p_args[0]->is_num()); + ERR_FAIL_COND(p_args[1]->get_type() != Variant::STRING_NAME && p_args[1]->get_type() != Variant::STRING); + ERR_FAIL_COND(p_args[2]->get_type() != Variant::STRING_NAME && p_args[2]->get_type() != Variant::STRING); int flags = *p_args[0]; StringName group = *p_args[1]; StringName method = *p_args[2]; call_group_flagsp(flags, group, method, p_args + 3, p_argcount - 3); - return Variant(); } -Variant SceneTree::_call_group(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { +void SceneTree::_call_group(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { r_error.error = Callable::CallError::CALL_OK; - ERR_FAIL_COND_V(p_argcount < 2, Variant()); - ERR_FAIL_COND_V(p_args[0]->get_type() != Variant::STRING_NAME && p_args[0]->get_type() != Variant::STRING, Variant()); - ERR_FAIL_COND_V(p_args[1]->get_type() != Variant::STRING_NAME && p_args[1]->get_type() != Variant::STRING, Variant()); + ERR_FAIL_COND(p_argcount < 2); + ERR_FAIL_COND(p_args[0]->get_type() != Variant::STRING_NAME && p_args[0]->get_type() != Variant::STRING); + ERR_FAIL_COND(p_args[1]->get_type() != Variant::STRING_NAME && p_args[1]->get_type() != Variant::STRING); StringName group = *p_args[0]; StringName method = *p_args[1]; call_group_flagsp(0, group, method, p_args + 2, p_argcount - 2); - return Variant(); } int64_t SceneTree::get_frame() const { diff --git a/scene/main/scene_tree.h b/scene/main/scene_tree.h index 6197e52fc1..705ca6ebd3 100644 --- a/scene/main/scene_tree.h +++ b/scene/main/scene_tree.h @@ -115,7 +115,7 @@ private: int node_count = 0; #ifdef TOOLS_ENABLED - Node *edited_scene_root; + Node *edited_scene_root = nullptr; #endif struct UGCall { StringName group; @@ -138,7 +138,7 @@ private: Array _get_nodes_in_group(const StringName &p_group); - Node *current_scene; + Node *current_scene = nullptr; Color debug_collisions_color; Color debug_collision_contact_color; @@ -175,8 +175,8 @@ private: void make_group_changed(const StringName &p_group); void _notify_group_pause(const StringName &p_group, int p_notification); - Variant _call_group_flags(const Variant **p_args, int p_argcount, Callable::CallError &r_error); - Variant _call_group(const Variant **p_args, int p_argcount, Callable::CallError &r_error); + void _call_group_flags(const Variant **p_args, int p_argcount, Callable::CallError &r_error); + void _call_group(const Variant **p_args, int p_argcount, Callable::CallError &r_error); void _flush_delete_queue(); // Optimization. @@ -204,6 +204,7 @@ private: enum CallInputType { CALL_INPUT_TYPE_INPUT, + CALL_INPUT_TYPE_SHORTCUT_INPUT, CALL_INPUT_TYPE_UNHANDLED_INPUT, CALL_INPUT_TYPE_UNHANDLED_KEY_INPUT, }; diff --git a/scene/main/shader_globals_override.cpp b/scene/main/shader_globals_override.cpp index 5387dc01e2..9b85e9db38 100644 --- a/scene/main/shader_globals_override.cpp +++ b/scene/main/shader_globals_override.cpp @@ -277,7 +277,7 @@ TypedArray<String> ShaderGlobalsOverride::get_configuration_warnings() const { TypedArray<String> warnings = Node::get_configuration_warnings(); if (!active) { - warnings.push_back(TTR("ShaderGlobalsOverride is not active because another node of the same type is in the scene.")); + warnings.push_back(RTR("ShaderGlobalsOverride is not active because another node of the same type is in the scene.")); } return warnings; diff --git a/scene/main/timer.cpp b/scene/main/timer.cpp index 120b537e4f..5a5747e122 100644 --- a/scene/main/timer.cpp +++ b/scene/main/timer.cpp @@ -184,7 +184,7 @@ TypedArray<String> Timer::get_configuration_warnings() const { TypedArray<String> warnings = Node::get_configuration_warnings(); if (wait_time < 0.05 - CMP_EPSILON) { - warnings.push_back(TTR("Very low timer wait times (< 0.05 seconds) may behave in significantly different ways depending on the rendered or physics frame rate.\nConsider using a script's process loop instead of relying on a Timer for very low wait times.")); + warnings.push_back(RTR("Very low timer wait times (< 0.05 seconds) may behave in significantly different ways depending on the rendered or physics frame rate.\nConsider using a script's process loop instead of relying on a Timer for very low wait times.")); } return warnings; diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index e580e64db6..e20287c875 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -1038,8 +1038,8 @@ Transform2D Viewport::get_final_transform() const { void Viewport::_update_canvas_items(Node *p_node) { if (p_node != this) { - Viewport *vp = Object::cast_to<Viewport>(p_node); - if (vp) { + Window *w = Object::cast_to<Window>(p_node); + if (w && (!w->is_inside_tree() || !w->is_embedded())) { return; } @@ -1124,9 +1124,10 @@ Vector2 Viewport::get_mouse_position() const { return gui.last_mouse_pos; } -void Viewport::warp_mouse(const Vector2 &p_pos) { - Vector2 gpos = (get_final_transform().affine_inverse() * _get_input_pre_xform()).affine_inverse().xform(p_pos); - Input::get_singleton()->warp_mouse_position(gpos); +void Viewport::warp_mouse(const Vector2 &p_position) { + Transform2D xform = get_screen_transform(); + Vector2 gpos = xform.xform(p_position).round(); + Input::get_singleton()->warp_mouse(gpos); } void Viewport::_gui_sort_roots() { @@ -1603,29 +1604,6 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { _gui_call_input(mouse_focus, mb); } - // In case the mouse was released after for example dragging a scrollbar, - // check whether the current control is different from the stored one. If - // it is different, rather than wait for it to be updated the next time the - // mouse is moved, notify the control so that it can e.g. drop the highlight. - // This code is duplicated from the mm.is_valid()-case further below. - Control *over = nullptr; - if (gui.mouse_focus) { - over = gui.mouse_focus; - } else { - over = gui_find_control(mpos); - } - - if (gui.mouse_focus_mask == MouseButton::NONE && over != gui.mouse_over) { - _drop_mouse_over(); - _gui_cancel_tooltip(); - - if (over) { - _gui_call_notification(over, Control::NOTIFICATION_MOUSE_ENTER); - } - } - - gui.mouse_over = over; - set_input_as_handled(); } } @@ -1685,9 +1663,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { } Control *over = nullptr; - if (gui.mouse_focus) { - over = gui.mouse_focus; - } else if (gui.mouse_in_viewport) { + if (gui.mouse_in_viewport) { over = gui_find_control(mpos); } @@ -1701,6 +1677,10 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { } } + if (gui.mouse_focus) { + over = gui.mouse_focus; + } + DisplayServer::CursorShape ds_cursor_shape = (DisplayServer::CursorShape)Input::get_singleton()->get_default_cursor_shape(); if (over) { @@ -1871,8 +1851,10 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { } if (viewport_under) { - Transform2D ai = (viewport_under->get_final_transform().affine_inverse() * viewport_under->_get_input_pre_xform()); - viewport_pos = ai.xform(viewport_pos); + if (viewport_under != this) { + Transform2D ai = (viewport_under->get_final_transform().affine_inverse() * viewport_under->_get_input_pre_xform()); + viewport_pos = ai.xform(viewport_pos); + } // Find control under at position. gui.drag_mouse_over = viewport_under->gui_find_control(viewport_pos); if (gui.drag_mouse_over) { @@ -2001,30 +1983,58 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { if (from && p_event->is_pressed()) { Control *next = nullptr; - if (p_event->is_action_pressed("ui_focus_next", true, true)) { - next = from->find_next_valid_focus(); - } + Ref<InputEventJoypadMotion> joypadmotion_event = p_event; + if (joypadmotion_event.is_valid()) { + Input *input = Input::get_singleton(); - if (p_event->is_action_pressed("ui_focus_prev", true, true)) { - next = from->find_prev_valid_focus(); - } + if (p_event->is_action_pressed("ui_focus_next") && input->is_action_just_pressed("ui_focus_next")) { + next = from->find_next_valid_focus(); + } - if (p_event->is_action_pressed("ui_up", true, true)) { - next = from->_get_focus_neighbor(SIDE_TOP); - } + if (p_event->is_action_pressed("ui_focus_prev") && input->is_action_just_pressed("ui_focus_prev")) { + next = from->find_prev_valid_focus(); + } - if (p_event->is_action_pressed("ui_left", true, true)) { - next = from->_get_focus_neighbor(SIDE_LEFT); - } + if (p_event->is_action_pressed("ui_up") && input->is_action_just_pressed("ui_up")) { + next = from->_get_focus_neighbor(SIDE_TOP); + } - if (p_event->is_action_pressed("ui_right", true, true)) { - next = from->_get_focus_neighbor(SIDE_RIGHT); - } + if (p_event->is_action_pressed("ui_left") && input->is_action_just_pressed("ui_left")) { + next = from->_get_focus_neighbor(SIDE_LEFT); + } - if (p_event->is_action_pressed("ui_down", true, true)) { - next = from->_get_focus_neighbor(SIDE_BOTTOM); - } + if (p_event->is_action_pressed("ui_right") && input->is_action_just_pressed("ui_right")) { + next = from->_get_focus_neighbor(SIDE_RIGHT); + } + + if (p_event->is_action_pressed("ui_down") && input->is_action_just_pressed("ui_down")) { + next = from->_get_focus_neighbor(SIDE_BOTTOM); + } + } else { + if (p_event->is_action_pressed("ui_focus_next", true, true)) { + next = from->find_next_valid_focus(); + } + + if (p_event->is_action_pressed("ui_focus_prev", true, true)) { + next = from->find_prev_valid_focus(); + } + + if (p_event->is_action_pressed("ui_up", true, true)) { + next = from->_get_focus_neighbor(SIDE_TOP); + } + if (p_event->is_action_pressed("ui_left", true, true)) { + next = from->_get_focus_neighbor(SIDE_LEFT); + } + + if (p_event->is_action_pressed("ui_right", true, true)) { + next = from->_get_focus_neighbor(SIDE_RIGHT); + } + + if (p_event->is_action_pressed("ui_down", true, true)) { + next = from->_get_focus_neighbor(SIDE_BOTTOM); + } + } if (next) { next->grab_focus(); set_input_as_handled(); @@ -2033,6 +2043,17 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { } } +void Viewport::_gui_cleanup_internal_state(Ref<InputEvent> p_event) { + ERR_FAIL_COND(p_event.is_null()); + + Ref<InputEventMouseButton> mb = p_event; + if (mb.is_valid()) { + if (!mb->is_pressed()) { + gui.mouse_focus_mask &= ~mouse_button_to_mask(mb->get_button_index()); // Remove from mask. + } + } +} + List<Control *>::Element *Viewport::_gui_add_root_control(Control *p_control) { gui.roots_order_dirty = true; return gui.roots.push_back(p_control); @@ -2680,7 +2701,7 @@ void Viewport::push_input(const Ref<InputEvent> &p_event, bool p_local_coords) { ev = p_event; } - if (is_embedding_subwindows() && _sub_windows_forward_input(p_event)) { + if (is_embedding_subwindows() && _sub_windows_forward_input(ev)) { set_input_as_handled(); return; } @@ -2695,6 +2716,9 @@ void Viewport::push_input(const Ref<InputEvent> &p_event, bool p_local_coords) { if (!is_input_handled()) { _gui_input_event(ev); + } else { + // Cleanup internal GUI state after accepting event during _input(). + _gui_cleanup_internal_state(ev); } event_count++; @@ -2720,11 +2744,18 @@ void Viewport::push_unhandled_input(const Ref<InputEvent> &p_event, bool p_local ev = p_event; } + // Shortcut Input. + if (Object::cast_to<InputEventKey>(*ev) != nullptr || Object::cast_to<InputEventShortcut>(*ev) != nullptr) { + get_tree()->_call_input_pause(shortcut_input_group, SceneTree::CALL_INPUT_TYPE_SHORTCUT_INPUT, ev, this); + } + // Unhandled Input. - get_tree()->_call_input_pause(unhandled_input_group, SceneTree::CALL_INPUT_TYPE_UNHANDLED_INPUT, ev, this); + if (!is_input_handled()) { + get_tree()->_call_input_pause(unhandled_input_group, SceneTree::CALL_INPUT_TYPE_UNHANDLED_INPUT, ev, this); + } - // Unhandled key Input - used for performance reasons - This is called a lot less than _unhandled_input since it ignores MouseMotion, etc. - if (!is_input_handled() && (Object::cast_to<InputEventKey>(*ev) != nullptr || Object::cast_to<InputEventShortcut>(*ev) != nullptr)) { + // Unhandled key Input - Used for performance reasons - This is called a lot less than _unhandled_input since it ignores MouseMotion, and to handle Unicode input with Alt / Ctrl modifiers after handling shortcuts. + if (!is_input_handled() && (Object::cast_to<InputEventKey>(*ev) != nullptr)) { get_tree()->_call_input_pause(unhandled_key_input_group, SceneTree::CALL_INPUT_TYPE_UNHANDLED_KEY_INPUT, ev, this); } @@ -2768,6 +2799,14 @@ Vector2 Viewport::get_camera_rect_size() const { } void Viewport::set_disable_input(bool p_disable) { + if (p_disable == disable_input) { + return; + } + if (p_disable) { + _drop_mouse_focus(); + _drop_mouse_over(); + _gui_cancel_tooltip(); + } disable_input = p_disable; } @@ -2783,7 +2822,7 @@ TypedArray<String> Viewport::get_configuration_warnings() const { TypedArray<String> warnings = Node::get_configuration_warnings(); if (size.x == 0 || size.y == 0) { - warnings.push_back(TTR("Viewport size must be greater than 0 to render anything.")); + warnings.push_back(RTR("Viewport size must be greater than 0 to render anything.")); } return warnings; } @@ -3084,6 +3123,10 @@ Viewport::SDFScale Viewport::get_sdf_scale() const { return sdf_scale; } +Transform2D Viewport::get_screen_transform() const { + return _get_input_pre_xform().affine_inverse() * get_final_transform(); +} + #ifndef _3D_DISABLED AudioListener3D *Viewport::get_audio_listener_3d() const { return audio_listener_3d; @@ -3592,7 +3635,7 @@ void Viewport::_bind_methods() { ClassDB::bind_method(D_METHOD("is_audio_listener_2d"), &Viewport::is_audio_listener_2d); ClassDB::bind_method(D_METHOD("get_mouse_position"), &Viewport::get_mouse_position); - ClassDB::bind_method(D_METHOD("warp_mouse", "to_position"), &Viewport::warp_mouse); + ClassDB::bind_method(D_METHOD("warp_mouse", "position"), &Viewport::warp_mouse); 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); @@ -3843,6 +3886,7 @@ Viewport::Viewport() { input_group = "_vp_input" + id; gui_input_group = "_vp_gui_input" + id; unhandled_input_group = "_vp_unhandled_input" + id; + shortcut_input_group = "_vp_shortcut_input" + id; unhandled_key_input_group = "_vp_unhandled_key_input" + id; // Window tooltip. @@ -3942,6 +3986,20 @@ Transform2D SubViewport::_stretch_transform() { return transform; } +Transform2D SubViewport::get_screen_transform() const { + Transform2D container_transform = Transform2D(); + SubViewportContainer *c = Object::cast_to<SubViewportContainer>(get_parent()); + if (c) { + if (c->is_stretch_enabled()) { + container_transform.scale(Vector2(c->get_stretch_shrink(), c->get_stretch_shrink())); + } + container_transform = c->get_viewport()->get_screen_transform() * c->get_global_transform_with_canvas() * container_transform; + } else { + WARN_PRINT_ONCE("SubViewport is not a child of a SubViewportContainer. get_screen_transform doesn't return the actual screen position."); + } + return container_transform * Viewport::get_screen_transform(); +} + void SubViewport::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { diff --git a/scene/main/viewport.h b/scene/main/viewport.h index 1976b20502..32882fbb68 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -270,6 +270,7 @@ private: Rect2i to_screen_rect; StringName input_group; StringName gui_input_group; + StringName shortcut_input_group; StringName unhandled_input_group; StringName unhandled_key_input_group; @@ -388,6 +389,7 @@ private: Control *_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_global, const Transform2D &p_xform, Transform2D &r_inv_xform); void _gui_input_event(Ref<InputEvent> p_event); + void _gui_cleanup_internal_state(Ref<InputEvent> p_event); _FORCE_INLINE_ Transform2D _get_input_pre_xform() const; @@ -546,7 +548,7 @@ public: bool is_input_disabled() const; Vector2 get_mouse_position() const; - void warp_mouse(const Vector2 &p_pos); + void warp_mouse(const Vector2 &p_position); void set_physics_object_picking(bool p_enable); bool get_physics_object_picking(); @@ -608,6 +610,8 @@ public: void pass_mouse_focus_to(Viewport *p_viewport, Control *p_control); + virtual Transform2D get_screen_transform() const; + #ifndef _3D_DISABLED bool use_xr = false; friend class AudioListener3D; @@ -731,6 +735,8 @@ public: void set_clear_mode(ClearMode p_mode); ClearMode get_clear_mode() const; + virtual Transform2D get_screen_transform() const override; + SubViewport(); ~SubViewport(); }; diff --git a/scene/main/window.cpp b/scene/main/window.cpp index 6837fcae21..2faa107fb4 100644 --- a/scene/main/window.cpp +++ b/scene/main/window.cpp @@ -1101,6 +1101,14 @@ void Window::popup_centered_ratio(float p_ratio) { void Window::popup(const Rect2i &p_screen_rect) { emit_signal(SNAME("about_to_popup")); + if (!_get_embedder() && get_flag(FLAG_POPUP)) { + // Send a focus-out notification when opening a Window Manager Popup. + SceneTree *scene_tree = get_tree(); + if (scene_tree) { + scene_tree->notify_group("_viewports", NOTIFICATION_WM_WINDOW_FOCUS_OUT); + } + } + // Update window size to calculate the actual window size based on contents minimum size and minimum size. _update_window_size(); @@ -1452,6 +1460,15 @@ void Window::_validate_property(PropertyInfo &property) const { } } +Transform2D Window::get_screen_transform() const { + Transform2D embedder_transform = Transform2D(); + if (_get_embedder()) { + embedder_transform.translate(get_position()); + embedder_transform = _get_embedder()->get_screen_transform() * embedder_transform; + } + return embedder_transform * Viewport::get_screen_transform(); +} + 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 3d8e337b4a..f674f6425a 100644 --- a/scene/main/window.h +++ b/scene/main/window.h @@ -291,6 +291,8 @@ public: Ref<Font> get_theme_default_font() const; int get_theme_default_font_size() const; + virtual Transform2D get_screen_transform() const override; + Rect2i get_parent_rect() const; virtual DisplayServer::WindowID get_window_id() const override; |