test_window.h 3.8 KB

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