| 1 | /**************************************************************************/ |
| 2 | /* test_window.h */ |
| 3 | /**************************************************************************/ |
| 4 | /* This file is part of: */ |
| 5 | /* GODOT ENGINE */ |
| 6 | /* https://godotengine.org */ |
| 7 | /**************************************************************************/ |
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
| 10 | /* */ |
| 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
| 12 | /* a copy of this software and associated documentation files (the */ |
| 13 | /* "Software"), to deal in the Software without restriction, including */ |
| 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
| 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
| 16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
| 17 | /* the following conditions: */ |
| 18 | /* */ |
| 19 | /* The above copyright notice and this permission notice shall be */ |
| 20 | /* included in all copies or substantial portions of the Software. */ |
| 21 | /* */ |
| 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
| 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
| 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
| 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
| 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
| 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
| 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 29 | /**************************************************************************/ |
| 30 | |
| 31 | #pragma once |
| 32 | |
| 33 | #include "scene/gui/control.h" |
| 34 | #include "scene/main/window.h" |
| 35 | |
| 36 | #include "tests/test_macros.h" |
| 37 | |
| 38 | namespace TestWindow { |
| 39 | |
| 40 | class NotificationControlWindow : public Control { |
| 41 | GDCLASS(NotificationControlWindow, Control); |
| 42 | |
| 43 | protected: |
| 44 | void _notification(int p_what) { |
| 45 | switch (p_what) { |
| 46 | case NOTIFICATION_MOUSE_ENTER: { |
| 47 | mouse_over = true; |
| 48 | } break; |
| 49 | |
| 50 | case NOTIFICATION_MOUSE_EXIT: { |
| 51 | mouse_over = false; |
| 52 | } break; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | public: |
| 57 | bool mouse_over = false; |
| 58 | }; |
| 59 | |
| 60 | TEST_CASE("[SceneTree][Window]") { |
| 61 | Window *root = SceneTree::get_singleton()->get_root(); |
| 62 | |
| 63 | SUBCASE("Control-mouse-over within Window-black bars should not happen") { |
| 64 | Window *w = memnew(Window); |
| 65 | root->add_child(w); |
| 66 | w->set_size(Size2i(400, 200)); |
| 67 | w->set_position(Size2i(0, 0)); |
| 68 | w->set_content_scale_size(Size2i(200, 200)); |
| 69 | w->set_content_scale_mode(Window::CONTENT_SCALE_MODE_CANVAS_ITEMS); |
| 70 | w->set_content_scale_aspect(Window::CONTENT_SCALE_ASPECT_KEEP); |
| 71 | NotificationControlWindow *c = memnew(NotificationControlWindow); |
| 72 | w->add_child(c); |
| 73 | c->set_size(Size2i(100, 100)); |
| 74 | c->set_position(Size2i(-50, -50)); |
| 75 | |
| 76 | CHECK_FALSE(c->mouse_over); |
| 77 | SEND_GUI_MOUSE_MOTION_EVENT(Point2i(110, 10), MouseButtonMask::NONE, Key::NONE); |
| 78 | CHECK(c->mouse_over); |
| 79 | SEND_GUI_MOUSE_MOTION_EVENT(Point2i(90, 10), MouseButtonMask::NONE, Key::NONE); |
| 80 | CHECK_FALSE(c->mouse_over); // GH-80011 |
| 81 | |
| 82 | /* TODO: |
| 83 | SEND_GUI_MOUSE_BUTTON_EVENT(Point2i(90, 10), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE); |
| 84 | SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(Point2i(90, 10), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE); |
| 85 | CHECK(Control was not pressed); |
| 86 | */ |
| 87 | |
| 88 | memdelete(c); |
| 89 | memdelete(w); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | } // namespace TestWindow |