-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80334 from Sauermann/fix-window-out-of-viewport-e…
…vents Fix nodes receiving mouse events in black bars of `Window`
- Loading branch information
Showing
7 changed files
with
146 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/**************************************************************************/ | ||
/* test_window.h */ | ||
/**************************************************************************/ | ||
/* This file is part of: */ | ||
/* GODOT ENGINE */ | ||
/* https://godotengine.org */ | ||
/**************************************************************************/ | ||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ | ||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ | ||
/* */ | ||
/* Permission is hereby granted, free of charge, to any person obtaining */ | ||
/* a copy of this software and associated documentation files (the */ | ||
/* "Software"), to deal in the Software without restriction, including */ | ||
/* without limitation the rights to use, copy, modify, merge, publish, */ | ||
/* distribute, sublicense, and/or sell copies of the Software, and to */ | ||
/* permit persons to whom the Software is furnished to do so, subject to */ | ||
/* the following conditions: */ | ||
/* */ | ||
/* The above copyright notice and this permission notice shall be */ | ||
/* included in all copies or substantial portions of the Software. */ | ||
/* */ | ||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ | ||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ | ||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ | ||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ | ||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ | ||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ | ||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ | ||
/**************************************************************************/ | ||
|
||
#ifndef TEST_WINDOW_H | ||
#define TEST_WINDOW_H | ||
|
||
#include "scene/gui/control.h" | ||
#include "scene/main/window.h" | ||
|
||
#include "tests/test_macros.h" | ||
|
||
namespace TestWindow { | ||
|
||
class NotificationControl : public Control { | ||
GDCLASS(NotificationControl, Control); | ||
|
||
protected: | ||
void _notification(int p_what) { | ||
switch (p_what) { | ||
case NOTIFICATION_MOUSE_ENTER: { | ||
mouse_over = true; | ||
} break; | ||
|
||
case NOTIFICATION_MOUSE_EXIT: { | ||
mouse_over = false; | ||
} break; | ||
} | ||
} | ||
|
||
public: | ||
bool mouse_over = false; | ||
}; | ||
|
||
TEST_CASE("[SceneTree][Window]") { | ||
Window *root = SceneTree::get_singleton()->get_root(); | ||
|
||
SUBCASE("Control-mouse-over within Window-black bars should not happen") { | ||
Window *w = memnew(Window); | ||
root->add_child(w); | ||
w->set_size(Size2i(400, 200)); | ||
w->set_position(Size2i(0, 0)); | ||
w->set_content_scale_size(Size2i(200, 200)); | ||
w->set_content_scale_mode(Window::CONTENT_SCALE_MODE_CANVAS_ITEMS); | ||
w->set_content_scale_aspect(Window::CONTENT_SCALE_ASPECT_KEEP); | ||
NotificationControl *c = memnew(NotificationControl); | ||
w->add_child(c); | ||
c->set_size(Size2i(100, 100)); | ||
c->set_position(Size2i(-50, -50)); | ||
|
||
CHECK_FALSE(c->mouse_over); | ||
SEND_GUI_MOUSE_MOTION_EVENT(Point2i(110, 10), MouseButtonMask::NONE, Key::NONE); | ||
CHECK(c->mouse_over); | ||
SEND_GUI_MOUSE_MOTION_EVENT(Point2i(90, 10), MouseButtonMask::NONE, Key::NONE); | ||
CHECK_FALSE(c->mouse_over); // GH-80011 | ||
|
||
/* TODO: | ||
SEND_GUI_MOUSE_BUTTON_EVENT(Point2i(90, 10), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE); | ||
SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(Point2i(90, 10), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE); | ||
CHECK(Control was not pressed); | ||
*/ | ||
|
||
memdelete(c); | ||
memdelete(w); | ||
} | ||
} | ||
|
||
} // namespace TestWindow | ||
|
||
#endif // TEST_WINDOW_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters