Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent SubViewportContainer overriding Subviewport's cursor with its own cursor #79805

Merged
merged 1 commit into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions scene/gui/subviewport_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ PackedStringArray SubViewportContainer::get_configuration_warnings() const {
warnings.push_back(RTR("This node doesn't have a SubViewport as child, so it can't display its intended content.\nConsider adding a SubViewport as a child to provide something displayable."));
}

if (get_default_cursor_shape() != Control::CURSOR_ARROW) {
warnings.push_back(RTR("The default mouse cursor shape of SubViewportContainer has no effect.\nConsider leaving it at its initial value `CURSOR_ARROW`."));
}

return warnings;
}

Expand Down
2 changes: 1 addition & 1 deletion scene/main/viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2075,7 +2075,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
}
}

if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_CURSOR_SHAPE)) {
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_CURSOR_SHAPE) && !Object::cast_to<SubViewportContainer>(over)) {
DisplayServer::get_singleton()->cursor_set_shape(ds_cursor_shape);
}
}
Expand Down
41 changes: 41 additions & 0 deletions tests/scene/test_viewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#include "scene/2d/node_2d.h"
#include "scene/gui/control.h"
#include "scene/gui/subviewport_container.h"
Sauermann marked this conversation as resolved.
Show resolved Hide resolved
#include "scene/main/window.h"

#include "tests/test_macros.h"
Expand Down Expand Up @@ -715,6 +716,46 @@ TEST_CASE("[SceneTree][Viewport] Controls and InputEvent handling") {
memdelete(node_a);
}

TEST_CASE("[SceneTree][Viewport] Control mouse cursor shape") {
SUBCASE("[Viewport][CursorShape] Mouse cursor is not overridden by SubViewportContainer") {
SubViewportContainer *node_a = memnew(SubViewportContainer);
SubViewport *node_b = memnew(SubViewport);
Control *node_c = memnew(Control);

node_a->set_name("SubViewportContainer");
node_b->set_name("SubViewport");
node_c->set_name("Control");
node_a->set_position(Point2i(0, 0));
node_c->set_position(Point2i(0, 0));
node_a->set_size(Point2i(100, 100));
node_b->set_size(Point2i(100, 100));
node_c->set_size(Point2i(100, 100));
node_a->set_default_cursor_shape(Control::CURSOR_ARROW);
node_c->set_default_cursor_shape(Control::CURSOR_FORBIDDEN);
Window *root = SceneTree::get_singleton()->get_root();
DisplayServerMock *DS = (DisplayServerMock *)(DisplayServer::get_singleton());

// Scene tree:
// - root
// - node_a (SubViewportContainer)
// - node_b (SubViewport)
// - node_c (Control)

root->add_child(node_a);
node_a->add_child(node_b);
node_b->add_child(node_c);

Point2i on_c = Point2i(5, 5);

SEND_GUI_MOUSE_MOTION_EVENT(on_c, MouseButtonMask::NONE, Key::NONE);
CHECK(DS->get_cursor_shape() == DisplayServer::CURSOR_FORBIDDEN); // GH-74805

memdelete(node_c);
memdelete(node_b);
memdelete(node_a);
}
}

} // namespace TestViewport

#endif // TEST_VIEWPORT_H
Loading