test_window.h 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. #ifndef TEST_WINDOW_H
  31. #define TEST_WINDOW_H
  32. #include "scene/gui/control.h"
  33. #include "scene/main/window.h"
  34. #include "tests/test_macros.h"
  35. namespace TestWindow {
  36. class NotificationControlWindow : public Control {
  37. GDCLASS(NotificationControlWindow, Control);
  38. protected:
  39. void _notification(int p_what) {
  40. switch (p_what) {
  41. case NOTIFICATION_MOUSE_ENTER: {
  42. mouse_over = true;
  43. } break;
  44. case NOTIFICATION_MOUSE_EXIT: {
  45. mouse_over = false;
  46. } break;
  47. }
  48. }
  49. public:
  50. bool mouse_over = false;
  51. };
  52. TEST_CASE("[SceneTree][Window]") {
  53. Window *root = SceneTree::get_singleton()->get_root();
  54. SUBCASE("Control-mouse-over within Window-black bars should not happen") {
  55. Window *w = memnew(Window);
  56. root->add_child(w);
  57. w->set_size(Size2i(400, 200));
  58. w->set_position(Size2i(0, 0));
  59. w->set_content_scale_size(Size2i(200, 200));
  60. w->set_content_scale_mode(Window::CONTENT_SCALE_MODE_CANVAS_ITEMS);
  61. w->set_content_scale_aspect(Window::CONTENT_SCALE_ASPECT_KEEP);
  62. NotificationControlWindow *c = memnew(NotificationControlWindow);
  63. w->add_child(c);
  64. c->set_size(Size2i(100, 100));
  65. c->set_position(Size2i(-50, -50));
  66. CHECK_FALSE(c->mouse_over);
  67. SEND_GUI_MOUSE_MOTION_EVENT(Point2i(110, 10), MouseButtonMask::NONE, Key::NONE);
  68. CHECK(c->mouse_over);
  69. SEND_GUI_MOUSE_MOTION_EVENT(Point2i(90, 10), MouseButtonMask::NONE, Key::NONE);
  70. CHECK_FALSE(c->mouse_over); // GH-80011
  71. /* TODO:
  72. SEND_GUI_MOUSE_BUTTON_EVENT(Point2i(90, 10), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
  73. SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(Point2i(90, 10), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
  74. CHECK(Control was not pressed);
  75. */
  76. memdelete(c);
  77. memdelete(w);
  78. }
  79. }
  80. } // namespace TestWindow
  81. #endif // TEST_WINDOW_H