summaryrefslogtreecommitdiffstats
path: root/scene/main/viewport.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/main/viewport.cpp')
-rw-r--r--scene/main/viewport.cpp261
1 files changed, 86 insertions, 175 deletions
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index de2332125f..a4e27a3d16 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -1235,14 +1235,16 @@ Ref<World2D> Viewport::find_world_2d() const {
}
}
-void Viewport::_propagate_viewport_notification(Node *p_node, int p_what) {
+void Viewport::_propagate_drag_notification(Node *p_node, int p_what) {
+ // Send notification to p_node and all children and descendant nodes of p_node, except to SubViewports which are not children of a SubViewportContainer.
p_node->notification(p_what);
+ bool is_svc = Object::cast_to<SubViewportContainer>(p_node);
for (int i = 0; i < p_node->get_child_count(); i++) {
Node *c = p_node->get_child(i);
- if (Object::cast_to<Viewport>(c)) {
+ if (!is_svc && Object::cast_to<SubViewport>(c)) {
continue;
}
- _propagate_viewport_notification(c, p_what);
+ Viewport::_propagate_drag_notification(c, p_what);
}
}
@@ -1345,7 +1347,7 @@ Ref<InputEvent> Viewport::_make_input_local(const Ref<InputEvent> &ev) {
Vector2 Viewport::get_mouse_position() const {
ERR_READ_THREAD_GUARD_V(Vector2());
- if (!is_directly_attached_to_screen()) {
+ if (get_section_root_viewport() != SceneTree::get_singleton()->get_root()) {
// Rely on the most recent mouse coordinate from an InputEventMouse in push_input.
// In this case get_screen_transform is not applicable, because it is ambiguous.
return gui.last_mouse_pos;
@@ -1548,8 +1550,7 @@ void Viewport::_gui_show_tooltip() {
gui.tooltip_popup->child_controls_changed();
}
-bool Viewport::_gui_call_input(Control *p_control, const Ref<InputEvent> &p_input) {
- bool stopped = false;
+void Viewport::_gui_call_input(Control *p_control, const Ref<InputEvent> &p_input) {
Ref<InputEvent> ev = p_input;
// Returns true if an event should be impacted by a control's mouse filter.
@@ -1573,19 +1574,15 @@ bool Viewport::_gui_call_input(Control *p_control, const Ref<InputEvent> &p_inpu
if (!control->is_inside_tree() || control->is_set_as_top_level()) {
break;
}
- if (gui.key_event_accepted) {
- stopped = true;
- break;
- }
if (control->data.mouse_filter == Control::MOUSE_FILTER_STOP && is_pointer_event && !(is_scroll_event && control->data.force_pass_scroll_events)) {
// Mouse, ScreenDrag and ScreenTouch events are stopped by default with MOUSE_FILTER_STOP, unless we have a scroll event and force_pass_scroll_events set to true
- stopped = true;
+ set_input_as_handled();
break;
}
}
if (is_input_handled()) {
- // Break after Physics Picking in SubViewport.
+ // Break when the event is set to handled in a child Control node or after physics picking in SubViewport.
break;
}
@@ -1596,7 +1593,6 @@ bool Viewport::_gui_call_input(Control *p_control, const Ref<InputEvent> &p_inpu
ev = ev->xformed_by(ci->get_transform()); // Transform event upwards.
ci = ci->get_parent_item();
}
- return stopped;
}
void Viewport::_gui_call_notification(Control *p_control, int p_what) {
@@ -1701,14 +1697,15 @@ Control *Viewport::_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_
}
bool Viewport::_gui_drop(Control *p_at_control, Point2 p_at_pos, bool p_just_check) {
- // Attempt grab, try parent controls too.
+ // Attempt drop, try parent controls too.
CanvasItem *ci = p_at_control;
+ Viewport *section_root = get_section_root_viewport();
while (ci) {
Control *control = Object::cast_to<Control>(ci);
if (control) {
- if (control->can_drop_data(p_at_pos, gui.drag_data)) {
+ if (control->can_drop_data(p_at_pos, section_root->gui.drag_data)) {
if (!p_just_check) {
- control->drop_data(p_at_pos, gui.drag_data);
+ control->drop_data(p_at_pos, section_root->gui.drag_data);
}
return true;
@@ -1736,8 +1733,6 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
Ref<InputEventMouseButton> mb = p_event;
if (mb.is_valid()) {
- gui.key_event_accepted = false;
-
Point2 mpos = mb->get_position();
if (mb->is_pressed()) {
MouseButtonMask button_mask = mouse_button_to_mask(mb->get_button_index());
@@ -1780,7 +1775,9 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
Control *control = Object::cast_to<Control>(ci);
if (control) {
if (control->get_focus_mode() != Control::FOCUS_NONE) {
- if (control != gui.key_focus) {
+ // Grabbing unhovered focus can cause issues when mouse is dragged
+ // with another button held down.
+ if (control != gui.key_focus && gui.mouse_over_hierarchy.has(control)) {
control->grab_focus();
}
break;
@@ -1799,20 +1796,19 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
}
}
- bool stopped = gui.mouse_focus && gui.mouse_focus->can_process() && _gui_call_input(gui.mouse_focus, mb);
- if (stopped) {
- set_input_as_handled();
+ if (gui.mouse_focus && gui.mouse_focus->can_process()) {
+ _gui_call_input(gui.mouse_focus, mb);
}
if (gui.dragging && mb->get_button_index() == MouseButton::LEFT) {
// Alternate drop use (when using force_drag(), as proposed by #5342).
- _perform_drop(gui.mouse_focus, pos);
+ _perform_drop(gui.mouse_focus);
}
_gui_cancel_tooltip();
} else {
if (gui.dragging && mb->get_button_index() == MouseButton::LEFT) {
- _perform_drop(gui.drag_mouse_over, gui.drag_mouse_over_pos);
+ _perform_drop(gui.drag_mouse_over);
}
gui.mouse_focus_mask.clear_flag(mouse_button_to_mask(mb->get_button_index())); // Remove from mask.
@@ -1835,20 +1831,19 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
gui.mouse_focus = nullptr;
}
- bool stopped = mouse_focus && mouse_focus->can_process() && _gui_call_input(mouse_focus, mb);
- if (stopped) {
- set_input_as_handled();
+ if (mouse_focus && mouse_focus->can_process()) {
+ _gui_call_input(mouse_focus, mb);
}
}
}
Ref<InputEventMouseMotion> mm = p_event;
if (mm.is_valid()) {
- gui.key_event_accepted = false;
Point2 mpos = mm->get_position();
// Drag & drop.
- if (!gui.drag_attempted && gui.mouse_focus && (mm->get_button_mask().has_flag(MouseButtonMask::LEFT))) {
+ Viewport *section_root = get_section_root_viewport();
+ if (!gui.drag_attempted && gui.mouse_focus && section_root && !section_root->gui.global_dragging && (mm->get_button_mask().has_flag(MouseButtonMask::LEFT))) {
gui.drag_accum += mm->get_relative();
float len = gui.drag_accum.length();
if (len > 10) {
@@ -1857,11 +1852,12 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
while (ci) {
Control *control = Object::cast_to<Control>(ci);
if (control) {
- gui.dragging = true;
- gui.drag_data = control->get_drag_data(control->get_global_transform_with_canvas().affine_inverse().xform(mpos - gui.drag_accum));
- if (gui.drag_data.get_type() != Variant::NIL) {
+ section_root->gui.global_dragging = true;
+ section_root->gui.drag_data = control->get_drag_data(control->get_global_transform_with_canvas().affine_inverse().xform(mpos - gui.drag_accum));
+ if (section_root->gui.drag_data.get_type() != Variant::NIL) {
gui.mouse_focus = nullptr;
gui.mouse_focus_mask.clear();
+ gui.dragging = true;
break;
} else {
Control *drag_preview = _gui_get_drag_preview();
@@ -1870,7 +1866,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
memdelete(drag_preview);
gui.drag_preview_id = ObjectID();
}
- gui.dragging = false;
+ section_root->gui.global_dragging = false;
}
if (control->data.mouse_filter == Control::MOUSE_FILTER_STOP) {
@@ -1888,7 +1884,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
gui.drag_attempted = true;
if (gui.dragging) {
- _propagate_viewport_notification(this, NOTIFICATION_DRAG_BEGIN);
+ Viewport::_propagate_drag_notification(section_root, NOTIFICATION_DRAG_BEGIN);
}
}
}
@@ -1979,112 +1975,35 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
ds_cursor_shape = (DisplayServer::CursorShape)cursor_shape;
- bool stopped = over->can_process() && _gui_call_input(over, mm);
- if (stopped) {
- set_input_as_handled();
+ if (over->can_process()) {
+ _gui_call_input(over, mm);
}
}
if (gui.dragging) {
- // Handle drag & drop.
+ // Handle drag & drop. This happens in the viewport where dragging started.
Control *drag_preview = _gui_get_drag_preview();
if (drag_preview) {
drag_preview->set_position(mpos);
}
- gui.drag_mouse_over = over;
- gui.drag_mouse_over_pos = Vector2();
-
- // Find the window this is above of.
- // See if there is an embedder.
- Viewport *embedder = nullptr;
- Vector2 viewport_pos;
-
- if (is_embedding_subwindows()) {
- embedder = this;
- viewport_pos = mpos;
- } else {
- // Not an embedder, but may be a subwindow of an embedder.
- Window *w = Object::cast_to<Window>(this);
- if (w) {
- if (w->is_embedded()) {
- embedder = w->get_embedder();
-
- viewport_pos = get_final_transform().xform(mpos) + w->get_position(); // To parent coords.
- }
- }
- }
-
- Viewport *viewport_under = nullptr;
-
- if (embedder) {
- // Use embedder logic.
-
- for (int i = embedder->gui.sub_windows.size() - 1; i >= 0; i--) {
- Window *sw = embedder->gui.sub_windows[i].window;
- Rect2 swrect = Rect2i(sw->get_position(), sw->get_size());
- if (!sw->get_flag(Window::FLAG_BORDERLESS)) {
- int title_height = sw->theme_cache.title_height;
- swrect.position.y -= title_height;
- swrect.size.y += title_height;
- }
-
- if (swrect.has_point(viewport_pos)) {
- viewport_under = sw;
- viewport_pos -= sw->get_position();
- }
- }
-
- if (!viewport_under) {
- // Not in a subwindow, likely in embedder.
- viewport_under = embedder;
+ gui.drag_mouse_over = section_root->gui.target_control;
+ if (gui.drag_mouse_over) {
+ if (!_gui_drop(gui.drag_mouse_over, gui.drag_mouse_over->get_local_mouse_position(), true)) {
+ gui.drag_mouse_over = nullptr;
}
- } else {
- // Use DisplayServer logic.
- Vector2i screen_mouse_pos = DisplayServer::get_singleton()->mouse_get_position();
-
- DisplayServer::WindowID window_id = DisplayServer::get_singleton()->get_window_at_screen_position(screen_mouse_pos);
-
- if (window_id != DisplayServer::INVALID_WINDOW_ID) {
- ObjectID object_under = DisplayServer::get_singleton()->window_get_attached_instance_id(window_id);
-
- if (object_under != ObjectID()) { // Fetch window.
- Window *w = Object::cast_to<Window>(ObjectDB::get_instance(object_under));
- if (w) {
- viewport_under = w;
- viewport_pos = w->get_final_transform().affine_inverse().xform(screen_mouse_pos - w->get_position());
- }
- }
- }
- }
-
- if (viewport_under) {
- if (viewport_under != this) {
- Transform2D ai = viewport_under->get_final_transform().affine_inverse();
- 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) {
- Transform2D localizer = gui.drag_mouse_over->get_global_transform_with_canvas().affine_inverse();
- gui.drag_mouse_over_pos = localizer.xform(viewport_pos);
-
- bool can_drop = _gui_drop(gui.drag_mouse_over, gui.drag_mouse_over_pos, true);
-
- if (!can_drop) {
- ds_cursor_shape = DisplayServer::CURSOR_FORBIDDEN;
- } else {
- ds_cursor_shape = DisplayServer::CURSOR_CAN_DROP;
- }
+ ds_cursor_shape = DisplayServer::CURSOR_CAN_DROP;
+ } else {
+ ds_cursor_shape = DisplayServer::CURSOR_FORBIDDEN;
}
-
- } else {
- gui.drag_mouse_over = nullptr;
}
}
- if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_CURSOR_SHAPE) && !Object::cast_to<SubViewportContainer>(over)) {
+ if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_CURSOR_SHAPE) && (gui.dragging || (!section_root->gui.global_dragging && !Object::cast_to<SubViewportContainer>(over)))) {
+ // If dragging is active, then set the cursor shape only from the Viewport where dragging started.
+ // If dragging is inactive, then set the cursor shape only when not over a SubViewportContainer.
DisplayServer::get_singleton()->cursor_set_shape(ds_cursor_shape);
}
}
@@ -2097,20 +2016,15 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
Control *over = gui_find_control(pos);
if (over) {
gui.touch_focus[touch_index] = over->get_instance_id();
- bool stopped = false;
if (over->can_process()) {
touch_event = touch_event->xformed_by(Transform2D()); // Make a copy.
pos = over->get_global_transform_with_canvas().affine_inverse().xform(pos);
touch_event->set_position(pos);
- stopped = _gui_call_input(over, touch_event);
- }
- if (stopped) {
- set_input_as_handled();
+ _gui_call_input(over, touch_event);
}
return;
}
} else {
- bool stopped = false;
ObjectID control_id = gui.touch_focus[touch_index];
Control *over = control_id.is_valid() ? Object::cast_to<Control>(ObjectDB::get_instance(control_id)) : nullptr;
if (over && over->can_process()) {
@@ -2118,10 +2032,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
pos = over->get_global_transform_with_canvas().affine_inverse().xform(pos);
touch_event->set_position(pos);
- stopped = _gui_call_input(over, touch_event);
- }
- if (stopped) {
- set_input_as_handled();
+ _gui_call_input(over, touch_event);
}
gui.touch_focus.erase(touch_index);
return;
@@ -2130,23 +2041,17 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
Ref<InputEventGesture> gesture_event = p_event;
if (gesture_event.is_valid()) {
- gui.key_event_accepted = false;
-
_gui_cancel_tooltip();
Size2 pos = gesture_event->get_position();
Control *over = gui_find_control(pos);
if (over) {
- bool stopped = false;
if (over->can_process()) {
gesture_event = gesture_event->xformed_by(Transform2D()); // Make a copy.
pos = over->get_global_transform_with_canvas().affine_inverse().xform(pos);
gesture_event->set_position(pos);
- stopped = _gui_call_input(over, gesture_event);
- }
- if (stopped) {
- set_input_as_handled();
+ _gui_call_input(over, gesture_event);
}
return;
}
@@ -2161,7 +2066,6 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
over = gui_find_control(drag_event->get_position());
}
if (over) {
- bool stopped = false;
if (over->can_process()) {
Transform2D localizer = over->get_global_transform_with_canvas().affine_inverse();
Size2 pos = localizer.xform(drag_event->get_position());
@@ -2174,24 +2078,21 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
drag_event->set_relative(rel);
drag_event->set_position(pos);
- stopped = _gui_call_input(over, drag_event);
+ _gui_call_input(over, drag_event);
}
- if (stopped) {
- set_input_as_handled();
- }
return;
}
}
if (mm.is_null() && mb.is_null() && p_event->is_action_type()) {
- if (gui.dragging && p_event->is_action_pressed("ui_cancel") && Input::get_singleton()->is_action_just_pressed("ui_cancel")) {
+ if (gui.dragging && p_event->is_action_pressed(SNAME("ui_cancel")) && Input::get_singleton()->is_action_just_pressed(SNAME("ui_cancel"))) {
_perform_drop();
set_input_as_handled();
return;
}
- if (p_event->is_action_pressed("ui_cancel")) {
+ if (p_event->is_action_pressed(SNAME("ui_cancel"))) {
// Cancel tooltip timer or hide tooltip when pressing Escape (this is standard behavior in most applications).
_gui_cancel_tooltip();
if (gui.tooltip_popup) {
@@ -2208,13 +2109,11 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
}
if (gui.key_focus) {
- gui.key_event_accepted = false;
if (gui.key_focus->can_process()) {
gui.key_focus->_call_gui_input(p_event);
}
- if (gui.key_event_accepted) {
- set_input_as_handled();
+ if (is_input_handled()) {
return;
}
}
@@ -2228,51 +2127,51 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
if (joypadmotion_event.is_valid()) {
Input *input = Input::get_singleton();
- if (p_event->is_action_pressed("ui_focus_next") && input->is_action_just_pressed("ui_focus_next")) {
+ if (p_event->is_action_pressed(SNAME("ui_focus_next")) && input->is_action_just_pressed(SNAME("ui_focus_next"))) {
next = from->find_next_valid_focus();
}
- if (p_event->is_action_pressed("ui_focus_prev") && input->is_action_just_pressed("ui_focus_prev")) {
+ if (p_event->is_action_pressed(SNAME("ui_focus_prev")) && input->is_action_just_pressed(SNAME("ui_focus_prev"))) {
next = from->find_prev_valid_focus();
}
- if (p_event->is_action_pressed("ui_up") && input->is_action_just_pressed("ui_up")) {
+ if (p_event->is_action_pressed(SNAME("ui_up")) && input->is_action_just_pressed(SNAME("ui_up"))) {
next = from->_get_focus_neighbor(SIDE_TOP);
}
- if (p_event->is_action_pressed("ui_left") && input->is_action_just_pressed("ui_left")) {
+ if (p_event->is_action_pressed(SNAME("ui_left")) && input->is_action_just_pressed(SNAME("ui_left"))) {
next = from->_get_focus_neighbor(SIDE_LEFT);
}
- if (p_event->is_action_pressed("ui_right") && input->is_action_just_pressed("ui_right")) {
+ if (p_event->is_action_pressed(SNAME("ui_right")) && input->is_action_just_pressed(SNAME("ui_right"))) {
next = from->_get_focus_neighbor(SIDE_RIGHT);
}
- if (p_event->is_action_pressed("ui_down") && input->is_action_just_pressed("ui_down")) {
+ if (p_event->is_action_pressed(SNAME("ui_down")) && input->is_action_just_pressed(SNAME("ui_down"))) {
next = from->_get_focus_neighbor(SIDE_BOTTOM);
}
} else {
- if (p_event->is_action_pressed("ui_focus_next", true, true)) {
+ if (p_event->is_action_pressed(SNAME("ui_focus_next"), true, true)) {
next = from->find_next_valid_focus();
}
- if (p_event->is_action_pressed("ui_focus_prev", true, true)) {
+ if (p_event->is_action_pressed(SNAME("ui_focus_prev"), true, true)) {
next = from->find_prev_valid_focus();
}
- if (p_event->is_action_pressed("ui_up", true, true)) {
+ if (p_event->is_action_pressed(SNAME("ui_up"), true, true)) {
next = from->_get_focus_neighbor(SIDE_TOP);
}
- if (p_event->is_action_pressed("ui_left", true, true)) {
+ if (p_event->is_action_pressed(SNAME("ui_left"), true, true)) {
next = from->_get_focus_neighbor(SIDE_LEFT);
}
- if (p_event->is_action_pressed("ui_right", true, true)) {
+ if (p_event->is_action_pressed(SNAME("ui_right"), true, true)) {
next = from->_get_focus_neighbor(SIDE_RIGHT);
}
- if (p_event->is_action_pressed("ui_down", true, true)) {
+ if (p_event->is_action_pressed(SNAME("ui_down"), true, true)) {
next = from->_get_focus_neighbor(SIDE_BOTTOM);
}
}
@@ -2284,10 +2183,10 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
}
}
-void Viewport::_perform_drop(Control *p_control, Point2 p_pos) {
+void Viewport::_perform_drop(Control *p_control) {
// Without any arguments, simply cancel Drag and Drop.
if (p_control) {
- gui.drag_successful = _gui_drop(p_control, p_pos, false);
+ gui.drag_successful = _gui_drop(p_control, p_control->get_local_mouse_position(), false);
} else {
gui.drag_successful = false;
}
@@ -2298,10 +2197,12 @@ void Viewport::_perform_drop(Control *p_control, Point2 p_pos) {
gui.drag_preview_id = ObjectID();
}
- gui.drag_data = Variant();
+ Viewport *section_root = get_section_root_viewport();
+ section_root->gui.drag_data = Variant();
gui.dragging = false;
+ section_root->gui.global_dragging = false;
gui.drag_mouse_over = nullptr;
- _propagate_viewport_notification(this, NOTIFICATION_DRAG_END);
+ Viewport::_propagate_drag_notification(section_root, NOTIFICATION_DRAG_END);
// Display the new cursor shape instantly.
update_mouse_cursor_state();
}
@@ -2331,14 +2232,16 @@ void Viewport::_gui_force_drag(Control *p_base, const Variant &p_data, Control *
ERR_FAIL_COND_MSG(p_data.get_type() == Variant::NIL, "Drag data must be a value.");
gui.dragging = true;
- gui.drag_data = p_data;
+ Viewport *section_root = get_section_root_viewport();
+ section_root->gui.global_dragging = true;
+ section_root->gui.drag_data = p_data;
gui.mouse_focus = nullptr;
gui.mouse_focus_mask.clear();
if (p_control) {
_gui_set_drag_preview(p_base, p_control);
}
- _propagate_viewport_notification(this, NOTIFICATION_DRAG_BEGIN);
+ Viewport::_propagate_drag_notification(section_root, NOTIFICATION_DRAG_BEGIN);
}
void Viewport::_gui_set_drag_preview(Control *p_base, Control *p_control) {
@@ -2558,7 +2461,6 @@ void Viewport::_gui_control_grab_focus(Control *p_control) {
}
void Viewport::_gui_accept_event() {
- gui.key_event_accepted = true;
if (is_inside_tree()) {
set_input_as_handled();
}
@@ -3022,6 +2924,7 @@ void Viewport::_update_mouse_over() {
}
void Viewport::_update_mouse_over(Vector2 p_pos) {
+ gui.last_mouse_pos = p_pos; // Necessary, because mouse cursor can be over Viewports that are not reached by the InputEvent.
// Look for embedded windows at mouse position.
if (is_embedding_subwindows()) {
for (int i = gui.sub_windows.size() - 1; i >= 0; i--) {
@@ -3073,6 +2976,7 @@ void Viewport::_update_mouse_over(Vector2 p_pos) {
// Look for Controls at mouse position.
Control *over = gui_find_control(p_pos);
+ get_section_root_viewport()->gui.target_control = over;
bool notify_embedded_viewports = false;
if (over != gui.mouse_over || (!over && !gui.mouse_over_hierarchy.is_empty())) {
// Find the common ancestor of `gui.mouse_over` and `over`.
@@ -3195,6 +3099,10 @@ void Viewport::_drop_mouse_over(Control *p_until_control) {
if (gui.mouse_over && gui.mouse_over->is_inside_tree()) {
gui.mouse_over->notification(Control::NOTIFICATION_MOUSE_EXIT_SELF);
}
+ Viewport *section_root = get_section_root_viewport();
+ if (section_root && section_root->gui.target_control == gui.mouse_over) {
+ section_root->gui.target_control = nullptr;
+ }
gui.mouse_over = nullptr;
// Send Mouse Exit notifications to children first. Don't send to p_until_control or above.
@@ -3403,7 +3311,7 @@ bool Viewport::is_input_disabled() const {
Variant Viewport::gui_get_drag_data() const {
ERR_READ_THREAD_GUARD_V(Variant());
- return gui.drag_data;
+ return get_section_root_viewport()->gui.drag_data;
}
PackedStringArray Viewport::get_configuration_warnings() const {
@@ -3597,7 +3505,7 @@ bool Viewport::is_snap_2d_vertices_to_pixel_enabled() const {
bool Viewport::gui_is_dragging() const {
ERR_READ_THREAD_GUARD_V(false);
- return gui.dragging;
+ return get_section_root_viewport()->gui.global_dragging;
}
bool Viewport::gui_is_drag_successful() const {
@@ -5156,9 +5064,12 @@ Transform2D SubViewport::get_popup_base_transform() const {
return c->get_screen_transform() * container_transform * get_final_transform();
}
-bool SubViewport::is_directly_attached_to_screen() const {
- // SubViewports, that are used as Textures are not considered to be directly attached to screen.
- return Object::cast_to<SubViewportContainer>(get_parent()) && get_parent()->get_viewport() && get_parent()->get_viewport()->is_directly_attached_to_screen();
+Viewport *SubViewport::get_section_root_viewport() const {
+ if (Object::cast_to<SubViewportContainer>(get_parent()) && get_parent()->get_viewport()) {
+ return get_parent()->get_viewport()->get_section_root_viewport();
+ }
+ SubViewport *vp = const_cast<SubViewport *>(this);
+ return vp;
}
bool SubViewport::is_attached_in_viewport() const {